@m6d/cortex 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1102 -2760
- package/dist/index.js +145 -24
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14626,48 +14626,151 @@ var schemaTypeSchema = z7.enum([...SCALAR_TYPES, "object", "array"]);
|
|
|
14626
14626
|
var FIELD_LIMITS = { nameLength: 120, descriptionLength: 500, enumValues: 50 };
|
|
14627
14627
|
var propertyNameSchema = z7.string().min(1).max(FIELD_LIMITS.nameLength).refine((name) => name === name.trim(), "no surrounding spaces");
|
|
14628
14628
|
var propertyOrderSchema = z7.array(z7.string()).refine((names) => new Set(names).size === names.length, "a name repeats").optional();
|
|
14629
|
-
var
|
|
14630
|
-
|
|
14631
|
-
|
|
14632
|
-
|
|
14633
|
-
|
|
14629
|
+
var countSchema = z7.number().int().min(0).optional();
|
|
14630
|
+
var valueKeywordsSchema = z7.strictObject({
|
|
14631
|
+
pattern: z7.string().min(1).max(1000).refine((pattern) => linearPattern(pattern) !== undefined, "a pattern Cortex cannot match").optional(),
|
|
14632
|
+
minLength: countSchema,
|
|
14633
|
+
maxLength: countSchema,
|
|
14634
|
+
format: z7.string().trim().min(1).max(100).optional(),
|
|
14635
|
+
minimum: z7.number().optional(),
|
|
14636
|
+
maximum: z7.number().optional(),
|
|
14637
|
+
exclusiveMinimum: z7.number().optional(),
|
|
14638
|
+
exclusiveMaximum: z7.number().optional(),
|
|
14639
|
+
multipleOf: z7.number().positive().optional(),
|
|
14640
|
+
minItems: countSchema,
|
|
14641
|
+
maxItems: countSchema,
|
|
14642
|
+
uniqueItems: z7.boolean().optional(),
|
|
14643
|
+
const: z7.union([z7.string().max(4000), z7.number(), z7.boolean()]).optional()
|
|
14644
|
+
});
|
|
14645
|
+
var NUMERIC_TYPES = ["number", "integer"];
|
|
14646
|
+
var VALUE_KEYWORD_TYPES = {
|
|
14647
|
+
pattern: ["string"],
|
|
14648
|
+
minLength: ["string"],
|
|
14649
|
+
maxLength: ["string"],
|
|
14650
|
+
format: SCALAR_TYPES,
|
|
14651
|
+
minimum: NUMERIC_TYPES,
|
|
14652
|
+
maximum: NUMERIC_TYPES,
|
|
14653
|
+
exclusiveMinimum: NUMERIC_TYPES,
|
|
14654
|
+
exclusiveMaximum: NUMERIC_TYPES,
|
|
14655
|
+
multipleOf: NUMERIC_TYPES,
|
|
14656
|
+
minItems: ["array"],
|
|
14657
|
+
maxItems: ["array"],
|
|
14658
|
+
uniqueItems: ["array"],
|
|
14659
|
+
const: SCALAR_TYPES
|
|
14660
|
+
};
|
|
14661
|
+
var ruleTypeSchema = z7.enum([...SCALAR_TYPES, "object", "array", "null"]);
|
|
14662
|
+
var conditionSchema = z7.lazy(() => z7.strictObject({
|
|
14663
|
+
type: z7.union([ruleTypeSchema, z7.array(ruleTypeSchema).min(1)]).optional(),
|
|
14664
|
+
enum: z7.array(z7.union([z7.string(), z7.number(), z7.boolean(), z7.null()])).min(1).optional(),
|
|
14665
|
+
...valueKeywordsSchema.shape,
|
|
14634
14666
|
required: z7.array(z7.string()).optional(),
|
|
14635
|
-
|
|
14667
|
+
properties: z7.record(z7.string(), conditionSchema).optional(),
|
|
14668
|
+
items: conditionSchema.optional(),
|
|
14669
|
+
...objectRulesSchema.shape
|
|
14670
|
+
})).meta({ id: "SchemaCondition" });
|
|
14671
|
+
var conditionsSchema = z7.array(conditionSchema).min(1).meta({ id: "SchemaConditions" });
|
|
14672
|
+
var objectRulesSchema = z7.strictObject({
|
|
14673
|
+
anyOf: conditionsSchema.optional(),
|
|
14674
|
+
oneOf: conditionsSchema.optional(),
|
|
14675
|
+
allOf: conditionsSchema.optional(),
|
|
14676
|
+
not: conditionSchema.optional(),
|
|
14677
|
+
if: conditionSchema.optional(),
|
|
14678
|
+
then: conditionSchema.optional(),
|
|
14679
|
+
else: conditionSchema.optional(),
|
|
14680
|
+
dependentRequired: z7.record(z7.string(), z7.array(z7.string())).optional(),
|
|
14681
|
+
dependentSchemas: z7.record(z7.string(), conditionSchema).optional(),
|
|
14682
|
+
minProperties: countSchema,
|
|
14683
|
+
maxProperties: countSchema
|
|
14636
14684
|
});
|
|
14637
|
-
var
|
|
14685
|
+
var OBJECT_RULE_KEYWORDS = objectRulesSchema.keyof().options;
|
|
14686
|
+
function listed(value) {
|
|
14687
|
+
return Array.isArray(value) ? value : [];
|
|
14688
|
+
}
|
|
14689
|
+
function keyed(value) {
|
|
14690
|
+
return isRecord(value) ? value : {};
|
|
14691
|
+
}
|
|
14692
|
+
function ruleNodes(rule) {
|
|
14693
|
+
if (!isRecord(rule))
|
|
14694
|
+
return [];
|
|
14695
|
+
return [
|
|
14696
|
+
rule,
|
|
14697
|
+
...[
|
|
14698
|
+
...["anyOf", "oneOf", "allOf"].flatMap((keyword) => listed(rule[keyword])),
|
|
14699
|
+
rule.not,
|
|
14700
|
+
rule.if,
|
|
14701
|
+
rule.then,
|
|
14702
|
+
rule.else,
|
|
14703
|
+
...Object.values(keyed(rule.dependentSchemas))
|
|
14704
|
+
].flatMap(ruleNodes)
|
|
14705
|
+
];
|
|
14706
|
+
}
|
|
14707
|
+
function ruleNames(rule) {
|
|
14708
|
+
return ruleNodes(rule).flatMap((node) => [
|
|
14709
|
+
...listed(node.required),
|
|
14710
|
+
...Object.keys(keyed(node.properties)),
|
|
14711
|
+
...Object.entries(keyed(node.dependentRequired)).flatMap(([name, names]) => [
|
|
14712
|
+
name,
|
|
14713
|
+
...listed(names)
|
|
14714
|
+
]),
|
|
14715
|
+
...Object.keys(keyed(node.dependentSchemas))
|
|
14716
|
+
]).filter((name) => typeof name === "string");
|
|
14717
|
+
}
|
|
14718
|
+
var itemTypeSchema = z7.enum([...SCALAR_TYPES, "object"]);
|
|
14719
|
+
var enumSchema = z7.array(z7.union([z7.string().trim().min(1), z7.null()])).min(1).max(FIELD_LIMITS.enumValues + 1).optional();
|
|
14720
|
+
var itemsSchema = z7.lazy(() => z7.strictObject({
|
|
14721
|
+
type: z7.union([itemTypeSchema, z7.tuple([itemTypeSchema, z7.literal("null")])]),
|
|
14722
|
+
enum: enumSchema,
|
|
14723
|
+
properties: z7.record(propertyNameSchema, schemaPropertySchema).optional(),
|
|
14724
|
+
required: z7.array(z7.string()).optional(),
|
|
14725
|
+
"x-order": propertyOrderSchema,
|
|
14726
|
+
...valueKeywordsSchema.shape,
|
|
14727
|
+
...objectRulesSchema.shape
|
|
14728
|
+
}));
|
|
14729
|
+
var schemaPropertySchema = z7.lazy(() => z7.strictObject({
|
|
14638
14730
|
type: z7.union([schemaTypeSchema, z7.tuple([schemaTypeSchema, z7.literal("null")])]),
|
|
14639
14731
|
description: z7.string().trim().max(FIELD_LIMITS.descriptionLength).optional(),
|
|
14640
|
-
enum:
|
|
14641
|
-
|
|
14642
|
-
return z7.record(propertyNameSchema, schemaPropertySchema).optional();
|
|
14643
|
-
},
|
|
14732
|
+
enum: enumSchema,
|
|
14733
|
+
properties: z7.record(propertyNameSchema, schemaPropertySchema).optional(),
|
|
14644
14734
|
required: z7.array(z7.string()).optional(),
|
|
14645
14735
|
"x-order": propertyOrderSchema,
|
|
14646
|
-
|
|
14647
|
-
return itemsSchema.optional();
|
|
14648
|
-
},
|
|
14736
|
+
items: itemsSchema.optional(),
|
|
14649
14737
|
"x-sensitive": z7.boolean().optional(),
|
|
14650
14738
|
"x-source": fieldSourceSchema.optional(),
|
|
14651
|
-
"x-target": fieldTargetSchema.optional()
|
|
14652
|
-
|
|
14739
|
+
"x-target": fieldTargetSchema.optional(),
|
|
14740
|
+
...valueKeywordsSchema.shape,
|
|
14741
|
+
...objectRulesSchema.shape
|
|
14742
|
+
}));
|
|
14653
14743
|
function typeOf(node) {
|
|
14654
14744
|
return [node.type].flat()[0];
|
|
14655
14745
|
}
|
|
14656
14746
|
function nodeIssues(node) {
|
|
14657
14747
|
const issues = new Array;
|
|
14658
|
-
const
|
|
14659
|
-
|
|
14748
|
+
const type = typeOf(node);
|
|
14749
|
+
const object = type === "object";
|
|
14750
|
+
for (const keyword of ["properties", "required", "x-order", ...OBJECT_RULE_KEYWORDS]) {
|
|
14660
14751
|
if (!object && node[keyword] !== undefined) {
|
|
14661
14752
|
issues.push({ at: [keyword], message: "only an object has it" });
|
|
14662
14753
|
}
|
|
14663
14754
|
}
|
|
14755
|
+
const named = (name) => Object.hasOwn(node.properties ?? {}, name);
|
|
14664
14756
|
for (const keyword of ["required", "x-order"]) {
|
|
14665
14757
|
node[keyword]?.forEach((name, index) => {
|
|
14666
|
-
if (!
|
|
14758
|
+
if (!named(name))
|
|
14667
14759
|
issues.push({ at: [keyword, index], message: "names no property" });
|
|
14668
|
-
}
|
|
14669
14760
|
});
|
|
14670
14761
|
}
|
|
14762
|
+
for (const keyword of OBJECT_RULE_KEYWORDS) {
|
|
14763
|
+
if (object && !ruleNames({ [keyword]: node[keyword] }).every(named)) {
|
|
14764
|
+
issues.push({ at: [keyword], message: "names no property" });
|
|
14765
|
+
}
|
|
14766
|
+
}
|
|
14767
|
+
for (const [keyword, types] of Object.entries(VALUE_KEYWORD_TYPES)) {
|
|
14768
|
+
if (node[keyword] === undefined)
|
|
14769
|
+
continue;
|
|
14770
|
+
if (!types.some((bounded) => bounded === type)) {
|
|
14771
|
+
issues.push({ at: [keyword], message: `only a ${types.join(" or ")} has it` });
|
|
14772
|
+
}
|
|
14773
|
+
}
|
|
14671
14774
|
return issues;
|
|
14672
14775
|
}
|
|
14673
14776
|
function enumIssueOf(property, type) {
|
|
@@ -14730,8 +14833,12 @@ function heldByRows(node, context, path, bindings) {
|
|
|
14730
14833
|
const at = [...path, "properties", name];
|
|
14731
14834
|
report(at, propertyIssues(property, bindings));
|
|
14732
14835
|
heldByRows(property, context, at, undefined);
|
|
14733
|
-
if (property.items)
|
|
14734
|
-
|
|
14836
|
+
if (!property.items)
|
|
14837
|
+
continue;
|
|
14838
|
+
const enumIssue = enumIssueOf(property.items, typeOf(property.items));
|
|
14839
|
+
if (enumIssue)
|
|
14840
|
+
report([...at, "items"], [{ at: ["enum"], message: enumIssue }]);
|
|
14841
|
+
heldByRows(property.items, context, [...at, "items"], undefined);
|
|
14735
14842
|
}
|
|
14736
14843
|
}
|
|
14737
14844
|
function objectJsonSchemaOf(bindings) {
|
|
@@ -14739,8 +14846,22 @@ function objectJsonSchemaOf(bindings) {
|
|
|
14739
14846
|
type: z7.literal("object"),
|
|
14740
14847
|
properties: z7.record(propertyNameSchema, schemaPropertySchema).optional(),
|
|
14741
14848
|
required: z7.array(z7.string()).optional(),
|
|
14742
|
-
"x-order": propertyOrderSchema
|
|
14743
|
-
|
|
14849
|
+
"x-order": propertyOrderSchema,
|
|
14850
|
+
...objectRulesSchema.shape
|
|
14851
|
+
}).superRefine((schema, context) => {
|
|
14852
|
+
heldByRows(schema, context, [], bindings);
|
|
14853
|
+
if (bindings !== undefined)
|
|
14854
|
+
return;
|
|
14855
|
+
for (const keyword of OBJECT_RULE_KEYWORDS) {
|
|
14856
|
+
if (schema[keyword] === undefined)
|
|
14857
|
+
continue;
|
|
14858
|
+
context.addIssue({
|
|
14859
|
+
code: "custom",
|
|
14860
|
+
path: [keyword],
|
|
14861
|
+
message: "only a tool's input has rules at its root"
|
|
14862
|
+
});
|
|
14863
|
+
}
|
|
14864
|
+
});
|
|
14744
14865
|
}
|
|
14745
14866
|
var objectSchema = objectJsonSchemaOf();
|
|
14746
14867
|
var EMPTY_OBJECT = { type: "object" };
|
package/package.json
CHANGED