massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / table / node_modules / ajv / dist / vocabularies / jtd / type.js
index 47aa69f38bed0d3851a7bc991c1f5099862ec51f..17a0b510792f9429beb3a2bca7d9c77835e1baa1 100644 (file)
@@ -15,37 +15,54 @@ exports.intRange = {
     uint32: [0, 4294967295, 10],
 };
 const error = {
-    message: (cxt) => error_1.typeErrorMessage(cxt, cxt.schema),
-    params: (cxt) => error_1.typeErrorParams(cxt, cxt.schema),
+    message: (cxt) => (0, error_1.typeErrorMessage)(cxt, cxt.schema),
+    params: (cxt) => (0, error_1.typeErrorParams)(cxt, cxt.schema),
 };
+function timestampCode(cxt) {
+    const { gen, data, it } = cxt;
+    const { timestamp, allowDate } = it.opts;
+    if (timestamp === "date")
+        return (0, codegen_1._) `${data} instanceof Date `;
+    const vts = (0, util_1.useFunc)(gen, timestamp_1.default);
+    const allowDateArg = allowDate ? (0, codegen_1._) `, true` : codegen_1.nil;
+    const validString = (0, codegen_1._) `typeof ${data} == "string" && ${vts}(${data}${allowDateArg})`;
+    return timestamp === "string" ? validString : (0, codegen_1.or)((0, codegen_1._) `${data} instanceof Date`, validString);
+}
 const def = {
     keyword: "type",
     schemaType: "string",
     error,
     code(cxt) {
-        metadata_1.checkMetadata(cxt);
-        const { gen, data, schema, parentSchema } = cxt;
+        (0, metadata_1.checkMetadata)(cxt);
+        const { data, schema, parentSchema, it } = cxt;
         let cond;
         switch (schema) {
             case "boolean":
             case "string":
-                cond = codegen_1._ `typeof ${data} == ${schema}`;
+                cond = (0, codegen_1._) `typeof ${data} == ${schema}`;
                 break;
             case "timestamp": {
-                const vts = util_1.useFunc(gen, timestamp_1.default);
-                cond = codegen_1._ `${data} instanceof Date || (typeof ${data} == "string" && ${vts}(${data}))`;
+                cond = timestampCode(cxt);
                 break;
             }
             case "float32":
             case "float64":
-                cond = codegen_1._ `typeof ${data} == "number"`;
+                cond = (0, codegen_1._) `typeof ${data} == "number"`;
                 break;
             default: {
-                const [min, max] = exports.intRange[schema];
-                cond = codegen_1._ `typeof ${data} == "number" && isFinite(${data}) && ${data} >= ${min} && ${data} <= ${max} && !(${data} % 1)`;
+                const sch = schema;
+                cond = (0, codegen_1._) `typeof ${data} == "number" && isFinite(${data}) && !(${data} % 1)`;
+                if (!it.opts.int32range && (sch === "int32" || sch === "uint32")) {
+                    if (sch === "uint32")
+                        cond = (0, codegen_1._) `${cond} && ${data} >= 0`;
+                }
+                else {
+                    const [min, max] = exports.intRange[sch];
+                    cond = (0, codegen_1._) `${cond} && ${data} >= ${min} && ${data} <= ${max}`;
+                }
             }
         }
-        cxt.pass(parentSchema.nullable ? codegen_1.or(codegen_1._ `${data} === null`, cond) : cond);
+        cxt.pass(parentSchema.nullable ? (0, codegen_1.or)((0, codegen_1._) `${data} === null`, cond) : cond);
     },
 };
 exports.default = def;