@powerlines/schema 0.11.44 → 0.11.46
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/bundle.cjs +1 -1
- package/dist/bundle.d.cts +1 -1
- package/dist/bundle.d.mts +1 -1
- package/dist/bundle.mjs +1 -1
- package/dist/bundle.mjs.map +1 -1
- package/dist/codegen.cjs +28 -22
- package/dist/codegen.d.cts +11 -11
- package/dist/codegen.d.cts.map +1 -1
- package/dist/codegen.d.mts +11 -11
- package/dist/codegen.d.mts.map +1 -1
- package/dist/codegen.mjs +36 -30
- package/dist/codegen.mjs.map +1 -1
- package/dist/constants.cjs +15 -11
- package/dist/constants.d.cts +4 -3
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +4 -3
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +13 -10
- package/dist/constants.mjs.map +1 -1
- package/dist/extract.cjs +158 -20
- package/dist/extract.d.cts +55 -16
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts +55 -16
- package/dist/extract.d.mts.map +1 -1
- package/dist/extract.mjs +158 -22
- package/dist/extract.mjs.map +1 -1
- package/dist/helpers.cjs +43 -8
- package/dist/helpers.d.cts +40 -6
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +40 -6
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +43 -10
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +39 -7
- package/dist/index.d.cts +8 -8
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +7 -7
- package/dist/metadata.cjs +9 -35
- package/dist/metadata.d.cts +5 -26
- package/dist/metadata.d.cts.map +1 -1
- package/dist/metadata.d.mts +5 -26
- package/dist/metadata.d.mts.map +1 -1
- package/dist/metadata.mjs +9 -33
- package/dist/metadata.mjs.map +1 -1
- package/dist/persistence.d.cts +4 -4
- package/dist/persistence.d.cts.map +1 -1
- package/dist/persistence.d.mts +4 -4
- package/dist/persistence.d.mts.map +1 -1
- package/dist/persistence.mjs.map +1 -1
- package/dist/reflection.cjs +72 -50
- package/dist/reflection.d.cts +1 -1
- package/dist/reflection.d.cts.map +1 -1
- package/dist/reflection.d.mts +1 -1
- package/dist/reflection.d.mts.map +1 -1
- package/dist/reflection.mjs +74 -52
- package/dist/reflection.mjs.map +1 -1
- package/dist/resolve.cjs +2 -2
- package/dist/resolve.mjs +2 -2
- package/dist/resolve.mjs.map +1 -1
- package/dist/type-checks.cjs +363 -83
- package/dist/type-checks.d.cts +138 -16
- package/dist/type-checks.d.cts.map +1 -1
- package/dist/type-checks.d.mts +138 -16
- package/dist/type-checks.d.mts.map +1 -1
- package/dist/type-checks.mjs +336 -85
- package/dist/type-checks.mjs.map +1 -1
- package/dist/types.d.cts +901 -176
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +901 -176
- package/dist/types.d.mts.map +1 -1
- package/dist/validate.mjs.map +1 -1
- package/package.json +5 -5
package/dist/type-checks.cjs
CHANGED
|
@@ -1,64 +1,338 @@
|
|
|
1
1
|
const require_constants = require('./constants.cjs');
|
|
2
2
|
let _stryke_type_checks = require("@stryke/type-checks");
|
|
3
|
-
let _stryke_json = require("@stryke/json");
|
|
4
3
|
|
|
5
4
|
//#region src/type-checks.ts
|
|
6
|
-
const JSON_SCHEMA_DATA_TYPE_SET = new Set(require_constants.JSON_SCHEMA_DATA_TYPES);
|
|
7
5
|
const isSetNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
8
6
|
const isSetBoolean = (value) => typeof value === "boolean";
|
|
9
|
-
const isNonNegativeInteger = (value) => Number.isInteger(value) && value >= 0;
|
|
10
7
|
const isSchemaLikeValue = (value) => (0, _stryke_type_checks.isSetObject)(value) || isSetBoolean(value);
|
|
8
|
+
const isRecordOfSchemaLike = (value) => (0, _stryke_type_checks.isSetObject)(value) && Object.values(value).every((item) => isSchemaLikeValue(item));
|
|
9
|
+
const isVocabularyMap = (value) => (0, _stryke_type_checks.isSetObject)(value) && Object.values(value).every((item) => isSetBoolean(item));
|
|
11
10
|
const isStringArray = (value) => Array.isArray(value) && value.every((item) => (0, _stryke_type_checks.isSetString)(item));
|
|
12
11
|
const isRecordOfStringArrays = (value) => (0, _stryke_type_checks.isSetObject)(value) && Object.values(value).every((item) => isStringArray(item));
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
12
|
+
const JSON_SCHEMA_PRIMITIVE_TYPE_SET = new Set(require_constants.JSON_SCHEMA_PRIMITIVE_TYPES);
|
|
13
|
+
const JSON_SCHEMA_TYPE_SET = new Set(require_constants.JSON_SCHEMA_TYPES);
|
|
14
|
+
/**
|
|
15
|
+
* A helper type guard to check if a value is a JSON Schema primitive type.
|
|
16
|
+
*
|
|
17
|
+
* @param value - The value to check.
|
|
18
|
+
* @returns True if the value is a JSON Schema primitive type, false otherwise.
|
|
19
|
+
*/
|
|
20
|
+
function isJsonSchemaPrimitiveType(value) {
|
|
21
|
+
return (0, _stryke_type_checks.isSetString)(value) && JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(value);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A helper type guard to check if a value is a JSON Schema type.
|
|
25
|
+
*
|
|
26
|
+
* @param value - The value to check.
|
|
27
|
+
* @returns True if the value is a JSON Schema type, false otherwise.
|
|
28
|
+
*/
|
|
29
|
+
function isJsonSchemaType(value) {
|
|
30
|
+
return (0, _stryke_type_checks.isSetString)(value) && JSON_SCHEMA_TYPE_SET.has(value);
|
|
31
|
+
}
|
|
32
|
+
const DATE_FORMAT_SET = new Set([
|
|
33
|
+
"date",
|
|
34
|
+
"time",
|
|
35
|
+
"date-time",
|
|
36
|
+
"iso-time",
|
|
37
|
+
"iso-date-time",
|
|
38
|
+
"unix-time"
|
|
39
|
+
]);
|
|
40
|
+
const isSetBigint = (value) => typeof value === "bigint";
|
|
41
|
+
const isArrayOf = (value, predicate) => Array.isArray(value) && value.every((item) => predicate(item));
|
|
42
|
+
const isTupleOfTwo = (value, aPredicate, bPredicate) => Array.isArray(value) && value.length === 2 && aPredicate(value[0]) && bPredicate(value[1]);
|
|
43
|
+
const isOptionalString = (value) => value === void 0 || (0, _stryke_type_checks.isSetString)(value);
|
|
44
|
+
const isOptionalBoolean = (value) => value === void 0 || isSetBoolean(value);
|
|
45
|
+
const isOptionalNumber = (value) => value === void 0 || isSetNumber(value);
|
|
46
|
+
const isOptionalBigint = (value) => value === void 0 || isSetBigint(value);
|
|
47
|
+
const isOptionalJsonSchema = (value) => value === void 0 || isJsonSchema(value);
|
|
48
|
+
const isOptionalJsonSchemaArray = (value) => value === void 0 || isArrayOf(value, isJsonSchema);
|
|
49
|
+
const isOptionalPrimitiveTypeArray = (value) => value === void 0 || Array.isArray(value) && value.every((item) => (0, _stryke_type_checks.isSetString)(item) && JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(item));
|
|
50
|
+
const isOptionalJsonSchemaTypeArray = (value) => value === void 0 || Array.isArray(value) && value.every((item) => (0, _stryke_type_checks.isSetString)(item) && JSON_SCHEMA_TYPE_SET.has(item));
|
|
51
|
+
const hasValidJsonSchemaKeywords = (schema) => {
|
|
52
|
+
if (!isOptionalString(schema.$id)) return false;
|
|
53
|
+
if (!isOptionalString(schema.$schema)) return false;
|
|
54
|
+
if (schema.$vocabulary !== void 0 && !isVocabularyMap(schema.$vocabulary)) return false;
|
|
55
|
+
if (!isOptionalString(schema.$comment)) return false;
|
|
56
|
+
if (!isOptionalString(schema.$anchor)) return false;
|
|
57
|
+
if (schema.$defs !== void 0 && !isRecordOfSchemaLike(schema.$defs)) return false;
|
|
58
|
+
if (!isOptionalString(schema.$dynamicRef)) return false;
|
|
59
|
+
if (!isOptionalString(schema.$dynamicAnchor)) return false;
|
|
60
|
+
if (!isOptionalString(schema.name)) return false;
|
|
61
|
+
if (!isOptionalString(schema.title)) return false;
|
|
62
|
+
if (!isOptionalString(schema.description)) return false;
|
|
63
|
+
if (!isOptionalString(schema.docs)) return false;
|
|
64
|
+
if (schema.examples !== void 0 && !Array.isArray(schema.examples)) return false;
|
|
65
|
+
if (schema.alias !== void 0 && !isStringArray(schema.alias)) return false;
|
|
66
|
+
if (schema.tags !== void 0 && !isStringArray(schema.tags)) return false;
|
|
67
|
+
if (!isOptionalBoolean(schema.deprecated)) return false;
|
|
68
|
+
if (!isOptionalBoolean(schema.hidden)) return false;
|
|
69
|
+
if (!isOptionalBoolean(schema.ignore)) return false;
|
|
70
|
+
if (!isOptionalBoolean(schema.internal)) return false;
|
|
71
|
+
if (!isOptionalBoolean(schema.runtime)) return false;
|
|
72
|
+
if (!isOptionalBoolean(schema.readOnly)) return false;
|
|
73
|
+
if (!isOptionalBoolean(schema.writeOnly)) return false;
|
|
74
|
+
if (!isOptionalJsonSchemaArray(schema.allOf)) return false;
|
|
75
|
+
if (!isOptionalJsonSchemaArray(schema.anyOf)) return false;
|
|
76
|
+
if (!isOptionalJsonSchemaArray(schema.oneOf)) return false;
|
|
77
|
+
if (!isOptionalJsonSchema(schema.not)) return false;
|
|
78
|
+
if (!isOptionalJsonSchema(schema.if)) return false;
|
|
79
|
+
if (!isOptionalJsonSchema(schema.then)) return false;
|
|
80
|
+
if (!isOptionalJsonSchema(schema.else)) return false;
|
|
81
|
+
return true;
|
|
60
82
|
};
|
|
61
83
|
/**
|
|
84
|
+
* Type guard for shared JSON Schema keyword groups.
|
|
85
|
+
*/
|
|
86
|
+
function isJsonSchemaKeywords(input) {
|
|
87
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
88
|
+
return hasValidJsonSchemaKeywords(input);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Type guard for generic JSON Schema objects with optional `$ref`.
|
|
92
|
+
*/
|
|
93
|
+
function isJsonSchemaAny(input) {
|
|
94
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
95
|
+
const schema = input;
|
|
96
|
+
return hasValidJsonSchemaKeywords(schema) && isOptionalString(schema.$ref);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Type guard for JSON Schema array types.
|
|
100
|
+
*/
|
|
101
|
+
function isJsonSchemaArray(input) {
|
|
102
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
103
|
+
const schema = input;
|
|
104
|
+
if (!hasValidJsonSchemaKeywords(schema) || schema.type !== "array") return false;
|
|
105
|
+
return isOptionalJsonSchemaArray(schema.prefixItems) && isOptionalJsonSchema(schema.items) && isOptionalJsonSchema(schema.contains) && isOptionalNumber(schema.minItems) && isOptionalNumber(schema.maxItems) && isOptionalBoolean(schema.uniqueItems) && isOptionalNumber(schema.minContains) && isOptionalNumber(schema.maxContains) && (schema.unevaluatedItems === void 0 || isSetBoolean(schema.unevaluatedItems) || isJsonSchema(schema.unevaluatedItems));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Type guard for bigint-backed integer schemas.
|
|
109
|
+
*/
|
|
110
|
+
function isJsonSchemaBigint(input) {
|
|
111
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
112
|
+
const schema = input;
|
|
113
|
+
if (!hasValidJsonSchemaKeywords(schema) || schema.type !== "integer" || schema.format !== "int64") return false;
|
|
114
|
+
return isOptionalBigint(schema.minimum) && isOptionalBigint(schema.exclusiveMinimum) && isOptionalBigint(schema.maximum) && isOptionalBigint(schema.exclusiveMaximum) && isOptionalBigint(schema.multipleOf) && isOptionalBigint(schema.default) && (schema.enum === void 0 || isArrayOf(schema.enum, isSetBigint));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Type guard for boolean schemas.
|
|
118
|
+
*/
|
|
119
|
+
function isJsonSchemaBoolean(input) {
|
|
120
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
121
|
+
const schema = input;
|
|
122
|
+
return hasValidJsonSchemaKeywords(schema) && schema.type === "boolean" && isOptionalBoolean(schema.default);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Type guard for date/time schemas.
|
|
126
|
+
*/
|
|
127
|
+
function isJsonSchemaDate(input) {
|
|
128
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
129
|
+
const schema = input;
|
|
130
|
+
if (!hasValidJsonSchemaKeywords(schema)) return false;
|
|
131
|
+
if (schema.anyOf !== void 0) return isArrayOf(schema.anyOf, isJsonSchemaDate);
|
|
132
|
+
if (schema.type !== "integer" && schema.type !== "string") return false;
|
|
133
|
+
if (!(0, _stryke_type_checks.isSetString)(schema.format) || !DATE_FORMAT_SET.has(schema.format)) return false;
|
|
134
|
+
return isOptionalNumber(schema.minimum) && isOptionalNumber(schema.maximum) && (schema.default === void 0 || (0, _stryke_type_checks.isSetString)(schema.default) || isSetNumber(schema.default));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Type guard for enum-constrained schemas.
|
|
138
|
+
*/
|
|
139
|
+
function isJsonSchemaEnum(input) {
|
|
140
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
141
|
+
const schema = input;
|
|
142
|
+
if (!hasValidJsonSchemaKeywords(schema) || !(0, _stryke_type_checks.isSetString)(schema.type) || !JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(schema.type) || !Array.isArray(schema.enum)) return false;
|
|
143
|
+
const typeName = schema.type;
|
|
144
|
+
const enumValues = schema.enum;
|
|
145
|
+
const defaultValue = schema.default;
|
|
146
|
+
if (typeName === "string") return enumValues.every((value) => (0, _stryke_type_checks.isSetString)(value)) && (defaultValue === void 0 || (0, _stryke_type_checks.isSetString)(defaultValue));
|
|
147
|
+
if (typeName === "number" || typeName === "integer") return enumValues.every((value) => isSetNumber(value)) && (defaultValue === void 0 || isSetNumber(defaultValue));
|
|
148
|
+
if (typeName === "boolean") return enumValues.every((value) => isSetBoolean(value)) && (defaultValue === void 0 || isSetBoolean(defaultValue));
|
|
149
|
+
return typeName === "null" && enumValues.every((value) => value === null) && (defaultValue === void 0 || defaultValue === null);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Type guard for `allOf` composition schemas.
|
|
153
|
+
*/
|
|
154
|
+
function isJsonSchemaAllOf(input) {
|
|
155
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
156
|
+
const schema = input;
|
|
157
|
+
if (!hasValidJsonSchemaKeywords(schema) || !isArrayOf(schema.allOf, isJsonSchema)) return false;
|
|
158
|
+
return schema.unevaluatedProperties === void 0 || isSetBoolean(schema.unevaluatedProperties) || isJsonSchema(schema.unevaluatedProperties);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Type guard for literal-value schemas.
|
|
162
|
+
*/
|
|
163
|
+
function isJsonSchemaLiteral(input) {
|
|
164
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
165
|
+
const schema = input;
|
|
166
|
+
if (!hasValidJsonSchemaKeywords(schema) || !("const" in schema)) return false;
|
|
167
|
+
return schema.type === void 0 || (0, _stryke_type_checks.isSetString)(schema.type) && isJsonSchemaType(schema.type) || isOptionalJsonSchemaTypeArray(schema.type);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Type guard for map tuple-array schemas.
|
|
171
|
+
*/
|
|
172
|
+
function isJsonSchemaMap(input) {
|
|
173
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
174
|
+
const schema = input;
|
|
175
|
+
if (!hasValidJsonSchemaKeywords(schema) || schema.type !== "array" || schema.maxItems !== 125 || !(0, _stryke_type_checks.isSetObject)(schema.items)) return false;
|
|
176
|
+
const items = schema.items;
|
|
177
|
+
return items.type === "array" && isTupleOfTwo(items.prefixItems, isJsonSchema, isJsonSchema) && (items.items === void 0 || items.items === false) && items.minItems === 2 && items.maxItems === 2;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Type guard for native enum schemas.
|
|
181
|
+
*/
|
|
182
|
+
function isJsonSchemaNativeEnum(input) {
|
|
183
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
184
|
+
const schema = input;
|
|
185
|
+
const isValidType = schema.type === "string" || schema.type === "number" || Array.isArray(schema.type) && schema.type.length === 2 && schema.type[0] === "string" && schema.type[1] === "number";
|
|
186
|
+
return hasValidJsonSchemaKeywords(schema) && isValidType && Array.isArray(schema.enum) && schema.enum.every((value) => (0, _stryke_type_checks.isSetString)(value) || isSetNumber(value));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Type guard for impossible/never schemas.
|
|
190
|
+
*/
|
|
191
|
+
function isJsonSchemaNever(input) {
|
|
192
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
193
|
+
const schema = input;
|
|
194
|
+
return hasValidJsonSchemaKeywords(schema) && isJsonSchemaAny(schema.not);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Type guard for `null` schemas.
|
|
198
|
+
*/
|
|
199
|
+
function isJsonSchemaNull(input) {
|
|
200
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
201
|
+
const schema = input;
|
|
202
|
+
return hasValidJsonSchemaKeywords(schema) && schema.type === "null" && (schema.const === void 0 || schema.const === null) && (schema.enum === void 0 || Array.isArray(schema.enum) && schema.enum.every((v) => v === null)) && (schema.default === void 0 || schema.default === null);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Type guard for nullable schema unions.
|
|
206
|
+
*/
|
|
207
|
+
function isJsonSchemaNullable(input) {
|
|
208
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
209
|
+
const schema = input;
|
|
210
|
+
if (!hasValidJsonSchemaKeywords(schema)) return false;
|
|
211
|
+
const anyOfBranch = schema.anyOf !== void 0 && Array.isArray(schema.anyOf) && schema.anyOf.length === 2 && isJsonSchema(schema.anyOf[0]) && isJsonSchemaNull(schema.anyOf[1]);
|
|
212
|
+
const typeBranch = Array.isArray(schema.type) && schema.type.length === 2 && (schema.type[0] === "null" && (0, _stryke_type_checks.isSetString)(schema.type[1]) && schema.type[1] !== "null" && JSON_SCHEMA_TYPE_SET.has(schema.type[1]) || schema.type[1] === "null" && (0, _stryke_type_checks.isSetString)(schema.type[0]) && schema.type[0] !== "null" && JSON_SCHEMA_TYPE_SET.has(schema.type[0]));
|
|
213
|
+
return anyOfBranch || typeBranch;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Type guard for numeric schemas.
|
|
217
|
+
*/
|
|
218
|
+
function isJsonSchemaNumber(input) {
|
|
219
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
220
|
+
const schema = input;
|
|
221
|
+
if (!hasValidJsonSchemaKeywords(schema) || schema.type !== "number" && schema.type !== "integer") return false;
|
|
222
|
+
return isOptionalString(schema.format) && isOptionalNumber(schema.minimum) && isOptionalNumber(schema.exclusiveMinimum) && isOptionalNumber(schema.maximum) && isOptionalNumber(schema.exclusiveMaximum) && isOptionalNumber(schema.multipleOf) && isOptionalNumber(schema.default) && (schema.enum === void 0 || isArrayOf(schema.enum, isSetNumber));
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Type guard for integer schemas.
|
|
226
|
+
*/
|
|
227
|
+
function isJsonSchemaInteger(input) {
|
|
228
|
+
return isJsonSchemaNumber(input) && input.type === "integer";
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Type guard for decimal schemas.
|
|
232
|
+
*/
|
|
233
|
+
function isJsonSchemaDecimal(input) {
|
|
234
|
+
return isJsonSchemaNumber(input) && input.type === "number";
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Type guard for object schemas.
|
|
238
|
+
*/
|
|
239
|
+
function isJsonSchemaObject(input) {
|
|
240
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
241
|
+
const schema = input;
|
|
242
|
+
return hasValidJsonSchemaKeywords(schema) && schema.type === "object" && (schema.properties === void 0 || isRecordOfSchemaLike(schema.properties)) && (schema.patternProperties === void 0 || isRecordOfSchemaLike(schema.patternProperties)) && (schema.additionalProperties === void 0 || isSetBoolean(schema.additionalProperties) || isJsonSchema(schema.additionalProperties)) && (schema.required === void 0 || isStringArray(schema.required)) && (schema.unevaluatedProperties === void 0 || isSetBoolean(schema.unevaluatedProperties) || isJsonSchema(schema.unevaluatedProperties)) && (schema.dependencies === void 0 || (0, _stryke_type_checks.isSetObject)(schema.dependencies) && Object.values(schema.dependencies).every((item) => isStringArray(item) || isJsonSchema(item))) && (schema.dependentRequired === void 0 || isRecordOfStringArrays(schema.dependentRequired)) && (schema.dependentSchemas === void 0 || isRecordOfSchemaLike(schema.dependentSchemas)) && isOptionalNumber(schema.minProperties) && isOptionalNumber(schema.maxProperties) && (schema.primaryKey === void 0 || isStringArray(schema.primaryKey)) && isOptionalString(schema.databaseSchema);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Type guard for string schemas.
|
|
246
|
+
*/
|
|
247
|
+
function isJsonSchemaString(input) {
|
|
248
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
249
|
+
const schema = input;
|
|
250
|
+
return hasValidJsonSchemaKeywords(schema) && schema.type === "string" && isOptionalNumber(schema.minLength) && isOptionalNumber(schema.maxLength) && isOptionalString(schema.pattern) && isOptionalString(schema.format) && isOptionalString(schema.default) && (schema.enum === void 0 || isArrayOf(schema.enum, _stryke_type_checks.isSetString)) && isOptionalString(schema.contentMediaType) && isOptionalString(schema.contentEncoding) && isOptionalString(schema.contentSchema);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Type guard for set-like array schemas.
|
|
254
|
+
*/
|
|
255
|
+
function isJsonSchemaSet(input) {
|
|
256
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
257
|
+
const schema = input;
|
|
258
|
+
return hasValidJsonSchemaKeywords(schema) && schema.type === "array" && schema.uniqueItems === true && isOptionalJsonSchemaArray(schema.prefixItems) && isOptionalJsonSchema(schema.items) && isOptionalJsonSchema(schema.contains) && isOptionalNumber(schema.minItems) && isOptionalNumber(schema.maxItems) && isOptionalNumber(schema.minContains) && isOptionalNumber(schema.maxContains) && (schema.unevaluatedItems === void 0 || isSetBoolean(schema.unevaluatedItems) || isJsonSchema(schema.unevaluatedItems));
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Type guard for record schemas.
|
|
262
|
+
*/
|
|
263
|
+
function isJsonSchemaRecord(input) {
|
|
264
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
265
|
+
const schema = input;
|
|
266
|
+
return hasValidJsonSchemaKeywords(schema) && schema.type === "object" && (schema.patternProperties === void 0 || isRecordOfSchemaLike(schema.patternProperties)) && (schema.additionalProperties === void 0 || isSetBoolean(schema.additionalProperties) || isJsonSchema(schema.additionalProperties)) && isOptionalJsonSchema(schema.propertyNames);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Type guard for tuple schemas.
|
|
270
|
+
*/
|
|
271
|
+
function isJsonSchemaTuple(input) {
|
|
272
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
273
|
+
const schema = input;
|
|
274
|
+
return hasValidJsonSchemaKeywords(schema) && schema.type === "array" && isArrayOf(schema.prefixItems, isJsonSchema) && isOptionalNumber(schema.minItems) && isOptionalNumber(schema.maxItems) && isOptionalJsonSchema(schema.items) && isOptionalJsonSchema(schema.contains) && isOptionalBoolean(schema.uniqueItems) && isOptionalNumber(schema.minContains) && isOptionalNumber(schema.maxContains) && (schema.unevaluatedItems === void 0 || isSetBoolean(schema.unevaluatedItems) || isJsonSchema(schema.unevaluatedItems));
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Type guard for undefined-representing schemas.
|
|
278
|
+
*/
|
|
279
|
+
function isJsonSchemaUndefined(input) {
|
|
280
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
281
|
+
const schema = input;
|
|
282
|
+
return hasValidJsonSchemaKeywords(schema) && isJsonSchemaAny(schema.not) && (schema.default === void 0 || schema.default === void 0);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Type guard for primitive-union schema variants.
|
|
286
|
+
*/
|
|
287
|
+
function isJsonSchemaPrimitiveUnion(input) {
|
|
288
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
289
|
+
const schema = input;
|
|
290
|
+
if (!hasValidJsonSchemaKeywords(schema)) return false;
|
|
291
|
+
if ((0, _stryke_type_checks.isSetString)(schema.type) && JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(schema.type)) {
|
|
292
|
+
if (schema.enum === void 0) return true;
|
|
293
|
+
if (!Array.isArray(schema.enum)) return false;
|
|
294
|
+
if (schema.type === "string") return schema.enum.every((value) => (0, _stryke_type_checks.isSetString)(value)) && (schema.default === void 0 || (0, _stryke_type_checks.isSetString)(schema.default));
|
|
295
|
+
if (schema.type === "number") return schema.enum.every((value) => isSetNumber(value)) && (schema.default === void 0 || isSetNumber(schema.default));
|
|
296
|
+
if (schema.type === "boolean") return schema.enum.every((value) => isSetBoolean(value)) && (schema.default === void 0 || isSetBoolean(schema.default));
|
|
297
|
+
if (schema.type === "integer") {
|
|
298
|
+
if (schema.format !== "int64") return false;
|
|
299
|
+
return schema.enum.every((value) => isSetBigint(value)) && (schema.default === void 0 || isSetBigint(schema.default));
|
|
300
|
+
}
|
|
301
|
+
return schema.type === "null" && schema.enum.every((value) => value === null) && (schema.default === void 0 || schema.default === null);
|
|
302
|
+
}
|
|
303
|
+
return isOptionalPrimitiveTypeArray(schema.type) && schema.type !== void 0;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Type guard for union schemas.
|
|
307
|
+
*/
|
|
308
|
+
function isJsonSchemaUnion(input) {
|
|
309
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
310
|
+
const schema = input;
|
|
311
|
+
return hasValidJsonSchemaKeywords(schema) && (isJsonSchemaPrimitiveUnion(schema) || isJsonSchemaAnyOf(schema));
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Type guard for permissive unknown schemas.
|
|
315
|
+
*/
|
|
316
|
+
function isJsonSchemaUnknown(input) {
|
|
317
|
+
return isJsonSchemaAny(input);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Type guard for `anyOf` composition schemas.
|
|
321
|
+
*/
|
|
322
|
+
function isJsonSchemaAnyOf(input) {
|
|
323
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
324
|
+
const schema = input;
|
|
325
|
+
return hasValidJsonSchemaKeywords(schema) && isArrayOf(schema.anyOf, isJsonSchema);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Type guard for reference schemas.
|
|
329
|
+
*/
|
|
330
|
+
function isJsonSchemaRef(input) {
|
|
331
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
332
|
+
const schema = input;
|
|
333
|
+
return hasValidJsonSchemaKeywords(schema) && (0, _stryke_type_checks.isSetString)(schema.$ref);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
62
336
|
* Type guard for Standard Schema V1 objects.
|
|
63
337
|
*
|
|
64
338
|
* @param input - The value to check.
|
|
@@ -92,36 +366,7 @@ function isValibotSchema(input) {
|
|
|
92
366
|
* @returns True if the input is a JSON Schema type, false otherwise.
|
|
93
367
|
*/
|
|
94
368
|
function isJsonSchema(input) {
|
|
95
|
-
|
|
96
|
-
const schema = input;
|
|
97
|
-
if ("$ref" in schema && (0, _stryke_type_checks.isSetString)(schema.$ref)) return true;
|
|
98
|
-
if (!("type" in schema)) return false;
|
|
99
|
-
const schemaTypes = [];
|
|
100
|
-
if ((0, _stryke_type_checks.isSetString)(schema.type)) {
|
|
101
|
-
if (!JSON_SCHEMA_DATA_TYPE_SET.has(schema.type)) return false;
|
|
102
|
-
schemaTypes.push(schema.type);
|
|
103
|
-
} else if (Array.isArray(schema.type) && schema.type.length > 0) {
|
|
104
|
-
if (!schema.type.every((schemaType) => (0, _stryke_type_checks.isSetString)(schemaType) && JSON_SCHEMA_DATA_TYPE_SET.has(schemaType)) || new Set(schema.type).size !== schema.type.length) return false;
|
|
105
|
-
schemaTypes.push(...schema.type);
|
|
106
|
-
} else return false;
|
|
107
|
-
const typeKeywordValidators = schemaTypes.flatMap((schemaType) => Object.entries(TYPE_KEYWORD_VALIDATORS[schemaType]));
|
|
108
|
-
for (const [keyword, validator] of typeKeywordValidators) if (keyword in schema && !validator(schema[keyword])) return false;
|
|
109
|
-
if ("minItems" in schema && "maxItems" in schema && isNonNegativeInteger(schema.minItems) && isNonNegativeInteger(schema.maxItems) && schema.minItems > schema.maxItems) return false;
|
|
110
|
-
if ("minLength" in schema && "maxLength" in schema && isNonNegativeInteger(schema.minLength) && isNonNegativeInteger(schema.maxLength) && schema.minLength > schema.maxLength) return false;
|
|
111
|
-
if ("minProperties" in schema && "maxProperties" in schema && isNonNegativeInteger(schema.minProperties) && isNonNegativeInteger(schema.maxProperties) && schema.minProperties > schema.maxProperties) return false;
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Type guard for JSON Schema object forms.
|
|
116
|
-
*
|
|
117
|
-
* @remarks
|
|
118
|
-
* This function checks if the input is a JSON Schema object type, which is defined as having a `type` property equal to "object" or having a `properties` object. This is used to determine if a given input conforms to the structure of a JSON Schema object definition.
|
|
119
|
-
*
|
|
120
|
-
* @param input - The value to check.
|
|
121
|
-
* @returns True if the input is a JSON Schema object type, false otherwise.
|
|
122
|
-
*/
|
|
123
|
-
function isJsonSchemaObject(input) {
|
|
124
|
-
return (0, _stryke_json.isJsonSchemaObjectType)(input) && (input.type === "object" || (0, _stryke_type_checks.isObject)(input.properties));
|
|
369
|
+
return isJsonSchemaString(input) || isJsonSchemaInteger(input) || isJsonSchemaDecimal(input) || isJsonSchemaBigint(input) || isJsonSchemaBoolean(input) || isJsonSchemaDate(input) || isJsonSchemaEnum(input) || isJsonSchemaLiteral(input) || isJsonSchemaNativeEnum(input) || isJsonSchemaNull(input) || isJsonSchemaArray(input) || isJsonSchemaObject(input) || isJsonSchemaRecord(input) || isJsonSchemaTuple(input) || isJsonSchemaUnion(input) || isJsonSchemaUndefined(input) || isJsonSchemaRef(input) || isJsonSchemaNever(input) || isJsonSchemaMap(input) || isJsonSchemaAny(input) || isJsonSchemaNullable(input) || isJsonSchemaAllOf(input) || isJsonSchemaUnknown(input) || isJsonSchemaSet(input);
|
|
125
370
|
}
|
|
126
371
|
/**
|
|
127
372
|
* Type guard for JSON Schemas that only accept `null`.
|
|
@@ -133,7 +378,7 @@ function isJsonSchemaObject(input) {
|
|
|
133
378
|
* @returns True if the input is a JSON Schema that only accepts `null`, false otherwise.
|
|
134
379
|
*/
|
|
135
380
|
function isNullOnlyJsonSchema(input) {
|
|
136
|
-
return
|
|
381
|
+
return isJsonSchemaNull(input);
|
|
137
382
|
}
|
|
138
383
|
/**
|
|
139
384
|
* Type guard for untyped schema objects.
|
|
@@ -186,16 +431,51 @@ function isUntypedInput(input) {
|
|
|
186
431
|
function isSchema(input) {
|
|
187
432
|
return (0, _stryke_type_checks.isSetObject)(input) && "schema" in input && isJsonSchema(input.schema) && "variant" in input && (0, _stryke_type_checks.isSetString)(input.variant) && "hash" in input && (0, _stryke_type_checks.isSetString)(input.hash);
|
|
188
433
|
}
|
|
189
|
-
|
|
434
|
+
/**
|
|
435
|
+
* Type guard for extracted schema objects that include source information.
|
|
436
|
+
*
|
|
437
|
+
* @param input - The value to check.
|
|
438
|
+
* @returns True if the input is a SchemaWithSource object, false otherwise.
|
|
439
|
+
*/
|
|
440
|
+
function isSchemaWithSource(input) {
|
|
190
441
|
return isSchema(input) && "source" in input && (0, _stryke_type_checks.isSetObject)(input.source) && "schema" in input.source && "variant" in input.source && (0, _stryke_type_checks.isSetString)(input.source.variant);
|
|
191
442
|
}
|
|
192
443
|
|
|
193
444
|
//#endregion
|
|
194
|
-
exports.isExtractedSchema = isExtractedSchema;
|
|
195
445
|
exports.isJsonSchema = isJsonSchema;
|
|
446
|
+
exports.isJsonSchemaAllOf = isJsonSchemaAllOf;
|
|
447
|
+
exports.isJsonSchemaAny = isJsonSchemaAny;
|
|
448
|
+
exports.isJsonSchemaAnyOf = isJsonSchemaAnyOf;
|
|
449
|
+
exports.isJsonSchemaArray = isJsonSchemaArray;
|
|
450
|
+
exports.isJsonSchemaBigint = isJsonSchemaBigint;
|
|
451
|
+
exports.isJsonSchemaBoolean = isJsonSchemaBoolean;
|
|
452
|
+
exports.isJsonSchemaDate = isJsonSchemaDate;
|
|
453
|
+
exports.isJsonSchemaDecimal = isJsonSchemaDecimal;
|
|
454
|
+
exports.isJsonSchemaEnum = isJsonSchemaEnum;
|
|
455
|
+
exports.isJsonSchemaInteger = isJsonSchemaInteger;
|
|
456
|
+
exports.isJsonSchemaKeywords = isJsonSchemaKeywords;
|
|
457
|
+
exports.isJsonSchemaLiteral = isJsonSchemaLiteral;
|
|
458
|
+
exports.isJsonSchemaMap = isJsonSchemaMap;
|
|
459
|
+
exports.isJsonSchemaNativeEnum = isJsonSchemaNativeEnum;
|
|
460
|
+
exports.isJsonSchemaNever = isJsonSchemaNever;
|
|
461
|
+
exports.isJsonSchemaNull = isJsonSchemaNull;
|
|
462
|
+
exports.isJsonSchemaNullable = isJsonSchemaNullable;
|
|
463
|
+
exports.isJsonSchemaNumber = isJsonSchemaNumber;
|
|
196
464
|
exports.isJsonSchemaObject = isJsonSchemaObject;
|
|
465
|
+
exports.isJsonSchemaPrimitiveType = isJsonSchemaPrimitiveType;
|
|
466
|
+
exports.isJsonSchemaPrimitiveUnion = isJsonSchemaPrimitiveUnion;
|
|
467
|
+
exports.isJsonSchemaRecord = isJsonSchemaRecord;
|
|
468
|
+
exports.isJsonSchemaRef = isJsonSchemaRef;
|
|
469
|
+
exports.isJsonSchemaSet = isJsonSchemaSet;
|
|
470
|
+
exports.isJsonSchemaString = isJsonSchemaString;
|
|
471
|
+
exports.isJsonSchemaTuple = isJsonSchemaTuple;
|
|
472
|
+
exports.isJsonSchemaType = isJsonSchemaType;
|
|
473
|
+
exports.isJsonSchemaUndefined = isJsonSchemaUndefined;
|
|
474
|
+
exports.isJsonSchemaUnion = isJsonSchemaUnion;
|
|
475
|
+
exports.isJsonSchemaUnknown = isJsonSchemaUnknown;
|
|
197
476
|
exports.isNullOnlyJsonSchema = isNullOnlyJsonSchema;
|
|
198
477
|
exports.isSchema = isSchema;
|
|
478
|
+
exports.isSchemaWithSource = isSchemaWithSource;
|
|
199
479
|
exports.isStandardSchema = isStandardSchema;
|
|
200
480
|
exports.isUntypedInput = isUntypedInput;
|
|
201
481
|
exports.isUntypedSchema = isUntypedSchema;
|