@powerlines/schema 0.11.81 → 0.11.82

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.
Files changed (86) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/bundle.cjs +49 -0
  3. package/dist/bundle.d.cts +21 -0
  4. package/dist/bundle.d.cts.map +1 -0
  5. package/dist/bundle.d.mts +21 -0
  6. package/dist/bundle.d.mts.map +1 -0
  7. package/dist/bundle.mjs +48 -0
  8. package/dist/bundle.mjs.map +1 -0
  9. package/dist/codegen.cjs +312 -0
  10. package/dist/codegen.d.cts +67 -0
  11. package/dist/codegen.d.cts.map +1 -0
  12. package/dist/codegen.d.mts +67 -0
  13. package/dist/codegen.d.mts.map +1 -0
  14. package/dist/codegen.mjs +306 -0
  15. package/dist/codegen.mjs.map +1 -0
  16. package/dist/constants.cjs +61 -0
  17. package/dist/constants.d.cts +17 -0
  18. package/dist/constants.d.cts.map +1 -0
  19. package/dist/constants.d.mts +17 -0
  20. package/dist/constants.d.mts.map +1 -0
  21. package/dist/constants.mjs +57 -0
  22. package/dist/constants.mjs.map +1 -0
  23. package/dist/extract.cjs +482 -0
  24. package/dist/extract.d.cts +125 -0
  25. package/dist/extract.d.cts.map +1 -0
  26. package/dist/extract.d.mts +125 -0
  27. package/dist/extract.d.mts.map +1 -0
  28. package/dist/extract.mjs +472 -0
  29. package/dist/extract.mjs.map +1 -0
  30. package/dist/helpers.cjs +241 -0
  31. package/dist/helpers.d.cts +121 -0
  32. package/dist/helpers.d.cts.map +1 -0
  33. package/dist/helpers.d.mts +121 -0
  34. package/dist/helpers.d.mts.map +1 -0
  35. package/dist/helpers.mjs +234 -0
  36. package/dist/helpers.mjs.map +1 -0
  37. package/dist/index.cjs +95 -2434
  38. package/dist/index.d.cts +11 -1892
  39. package/dist/index.d.cts.map +1 -1
  40. package/dist/index.d.mts +11 -1892
  41. package/dist/index.d.mts.map +1 -1
  42. package/dist/index.mjs +12 -2321
  43. package/dist/metadata.cjs +53 -0
  44. package/dist/metadata.d.cts +31 -0
  45. package/dist/metadata.d.cts.map +1 -0
  46. package/dist/metadata.d.mts +31 -0
  47. package/dist/metadata.d.mts.map +1 -0
  48. package/dist/metadata.mjs +52 -0
  49. package/dist/metadata.mjs.map +1 -0
  50. package/dist/persistence.cjs +74 -0
  51. package/dist/persistence.d.cts +47 -0
  52. package/dist/persistence.d.cts.map +1 -0
  53. package/dist/persistence.d.mts +47 -0
  54. package/dist/persistence.d.mts.map +1 -0
  55. package/dist/persistence.mjs +71 -0
  56. package/dist/persistence.mjs.map +1 -0
  57. package/dist/reflection.cjs +426 -0
  58. package/dist/reflection.d.cts +11 -0
  59. package/dist/reflection.d.cts.map +1 -0
  60. package/dist/reflection.d.mts +11 -0
  61. package/dist/reflection.d.mts.map +1 -0
  62. package/dist/reflection.mjs +425 -0
  63. package/dist/reflection.mjs.map +1 -0
  64. package/dist/resolve.cjs +105 -0
  65. package/dist/resolve.d.cts +36 -0
  66. package/dist/resolve.d.cts.map +1 -0
  67. package/dist/resolve.d.mts +36 -0
  68. package/dist/resolve.d.mts.map +1 -0
  69. package/dist/resolve.mjs +102 -0
  70. package/dist/resolve.mjs.map +1 -0
  71. package/dist/type-checks.cjs +633 -0
  72. package/dist/type-checks.d.cts +316 -0
  73. package/dist/type-checks.d.cts.map +1 -0
  74. package/dist/type-checks.d.mts +316 -0
  75. package/dist/type-checks.d.mts.map +1 -0
  76. package/dist/type-checks.mjs +594 -0
  77. package/dist/type-checks.mjs.map +1 -0
  78. package/dist/types.d.cts +1152 -0
  79. package/dist/types.d.cts.map +1 -0
  80. package/dist/types.d.mts +1152 -0
  81. package/dist/types.d.mts.map +1 -0
  82. package/dist/validate.cjs +27 -0
  83. package/dist/validate.mjs +25 -0
  84. package/dist/validate.mjs.map +1 -0
  85. package/package.json +6 -6
  86. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,594 @@
1
+ import { JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES } from "./constants.mjs";
2
+ import { isBoolean, isFunction, isSetObject, isSetString, isString } from "@stryke/type-checks";
3
+
4
+ //#region src/type-checks.ts
5
+ const isSetNumber = (value) => typeof value === "number" && Number.isFinite(value);
6
+ const isSchemaLikeValue = (value) => isSetObject(value) || isBoolean(value);
7
+ const isRecordOfSchemaLike = (value) => isSetObject(value) && Object.values(value).every((item) => isSchemaLikeValue(item));
8
+ const isVocabularyMap = (value) => isSetObject(value) && Object.values(value).every((item) => isBoolean(item));
9
+ const isStringArray = (value) => Array.isArray(value) && value.every((item) => isSetString(item));
10
+ const isRecordOfStringArrays = (value) => isSetObject(value) && Object.values(value).every((item) => isStringArray(item));
11
+ const JSON_SCHEMA_PRIMITIVE_TYPE_SET = new Set(JSON_SCHEMA_PRIMITIVE_TYPES);
12
+ const JSON_SCHEMA_TYPE_SET = new Set(JSON_SCHEMA_TYPES);
13
+ /**
14
+ * A helper type guard to check if a value is a JSON Schema primitive type.
15
+ *
16
+ * @param value - The value to check.
17
+ * @returns True if the value is a JSON Schema primitive type, false otherwise.
18
+ */
19
+ function isJsonSchemaPrimitiveType(value) {
20
+ return isSetString(value) && JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(value);
21
+ }
22
+ /**
23
+ * A helper type guard to check if a value is a JSON Schema type.
24
+ *
25
+ * @param value - The value to check.
26
+ * @returns True if the value is a JSON Schema type, false otherwise.
27
+ */
28
+ function isJsonSchemaType(value) {
29
+ return isSetString(value) && JSON_SCHEMA_TYPE_SET.has(value);
30
+ }
31
+ const DATE_FORMAT_SET = new Set([
32
+ "date",
33
+ "time",
34
+ "date-time",
35
+ "iso-time",
36
+ "iso-date-time",
37
+ "unix-time"
38
+ ]);
39
+ const isSetBigint = (value) => typeof value === "bigint";
40
+ const UNTYPED_TYPE_NAME_SET = new Set([
41
+ "string",
42
+ "number",
43
+ "bigint",
44
+ "boolean",
45
+ "symbol",
46
+ "function",
47
+ "object",
48
+ "any",
49
+ "array"
50
+ ]);
51
+ const isUntypedJSType = (value) => isSetString(value) && UNTYPED_TYPE_NAME_SET.has(value);
52
+ const isUntypedTypeDescriptor = (value) => {
53
+ if (!isSetObject(value)) return false;
54
+ const descriptor = value;
55
+ if (descriptor.type !== void 0 && !(isSetString(descriptor.type) && isUntypedJSType(descriptor.type) || Array.isArray(descriptor.type) && descriptor.type.every((item) => isUntypedJSType(item)))) return false;
56
+ if (descriptor.tsType !== void 0 && !isSetString(descriptor.tsType)) return false;
57
+ if (descriptor.markdownType !== void 0 && !isSetString(descriptor.markdownType)) return false;
58
+ if (descriptor.items !== void 0 && !(isUntypedTypeDescriptor(descriptor.items) || Array.isArray(descriptor.items) && descriptor.items.every((item) => isUntypedTypeDescriptor(item)))) return false;
59
+ return true;
60
+ };
61
+ const isUntypedFunctionArg = (value) => {
62
+ if (!isUntypedTypeDescriptor(value)) return false;
63
+ const arg = value;
64
+ if (arg.name !== void 0 && !isSetString(arg.name)) return false;
65
+ return arg.optional === void 0 || typeof arg.optional === "boolean";
66
+ };
67
+ const isRecordOfUntypedSchema = (value) => isSetObject(value) && Object.values(value).every((item) => isUntypedSchema(item));
68
+ const isArrayOf = (value, predicate) => Array.isArray(value) && value.every((item) => predicate(item));
69
+ const isTupleOfTwo = (value, aPredicate, bPredicate) => Array.isArray(value) && value.length === 2 && aPredicate(value[0]) && bPredicate(value[1]);
70
+ const isOptionalString = (value, allowEmpty = false) => value === void 0 || isString(value) && (allowEmpty || value.length > 0);
71
+ const isOptionalBoolean = (value) => value === void 0 || isBoolean(value);
72
+ const isOptionalNumber = (value) => value === void 0 || isSetNumber(value);
73
+ const isOptionalBigint = (value) => value === void 0 || isSetBigint(value);
74
+ const isOptionalJsonSchema = (value) => value === void 0 || isJsonSchema(value);
75
+ const isOptionalJsonSchemaArray = (value) => value === void 0 || isArrayOf(value, isJsonSchema);
76
+ const isOptionalPrimitiveTypeArray = (value) => value === void 0 || Array.isArray(value) && value.every((item) => isSetString(item) && JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(item));
77
+ const isOptionalJsonSchemaTypeArray = (value) => value === void 0 || Array.isArray(value) && value.every((item) => isSetString(item) && JSON_SCHEMA_TYPE_SET.has(item));
78
+ const hasValidJsonSchemaKeywords = (schema) => {
79
+ if (!isOptionalString(schema.$id)) return false;
80
+ if (!isOptionalString(schema.$schema)) return false;
81
+ if (schema.$vocabulary !== void 0 && !isVocabularyMap(schema.$vocabulary)) return false;
82
+ if (!isOptionalString(schema.$comment, true)) return false;
83
+ if (!isOptionalString(schema.$anchor)) return false;
84
+ if (schema.$defs !== void 0 && !isRecordOfSchemaLike(schema.$defs)) return false;
85
+ if (!isOptionalString(schema.$dynamicRef)) return false;
86
+ if (!isOptionalString(schema.$dynamicAnchor)) return false;
87
+ if (!isOptionalString(schema.name)) return false;
88
+ if (!isOptionalString(schema.title, true)) return false;
89
+ if (!isOptionalString(schema.description, true)) return false;
90
+ if (!isOptionalString(schema.docs, true)) return false;
91
+ if (schema.examples !== void 0 && !Array.isArray(schema.examples)) return false;
92
+ if (schema.alias !== void 0 && !isStringArray(schema.alias)) return false;
93
+ if (schema.tags !== void 0 && !isStringArray(schema.tags)) return false;
94
+ if (!isOptionalBoolean(schema.deprecated)) return false;
95
+ if (!isOptionalBoolean(schema.hidden)) return false;
96
+ if (!isOptionalBoolean(schema.ignore)) return false;
97
+ if (!isOptionalBoolean(schema.internal)) return false;
98
+ if (!isOptionalBoolean(schema.runtime)) return false;
99
+ if (!isOptionalBoolean(schema.readOnly)) return false;
100
+ if (!isOptionalBoolean(schema.writeOnly)) return false;
101
+ if (!isOptionalJsonSchemaArray(schema.allOf)) return false;
102
+ if (!isOptionalJsonSchemaArray(schema.anyOf)) return false;
103
+ if (!isOptionalJsonSchemaArray(schema.oneOf)) return false;
104
+ if (!isOptionalJsonSchema(schema.not)) return false;
105
+ if (!isOptionalJsonSchema(schema.if)) return false;
106
+ if (!isOptionalJsonSchema(schema.then)) return false;
107
+ if (!isOptionalJsonSchema(schema.else)) return false;
108
+ return true;
109
+ };
110
+ /**
111
+ * Type guard for shared JSON Schema keyword groups.
112
+ *
113
+ * @param input - The value to check.
114
+ * @returns True if the input is a JSON Schema keyword group, false otherwise.
115
+ */
116
+ function isJsonSchemaKeywords(input) {
117
+ if (!isSetObject(input)) return false;
118
+ return hasValidJsonSchemaKeywords(input);
119
+ }
120
+ /**
121
+ * Type guard for generic JSON Schema objects with optional `$ref`.
122
+ *
123
+ * @param input - The value to check.
124
+ * @returns True if the input is a generic JSON Schema object, false otherwise.
125
+ */
126
+ function isJsonSchemaAny(input) {
127
+ if (!isSetObject(input)) return false;
128
+ const schema = input;
129
+ return hasValidJsonSchemaKeywords(schema) && isOptionalString(schema.$ref);
130
+ }
131
+ /**
132
+ * Type guard for JSON Schema array types.
133
+ *
134
+ * @param input - The value to check.
135
+ * @returns True if the input is a JSON Schema array schema, false otherwise.
136
+ */
137
+ function isJsonSchemaArray(input) {
138
+ if (!isSetObject(input)) return false;
139
+ const schema = input;
140
+ if (!hasValidJsonSchemaKeywords(schema) || schema.type !== "array") return false;
141
+ 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 || isBoolean(schema.unevaluatedItems) || isJsonSchema(schema.unevaluatedItems));
142
+ }
143
+ /**
144
+ * Type guard for bigint-backed integer schemas.
145
+ *
146
+ * @param input - The value to check.
147
+ * @returns True if the input is a bigint-backed integer schema, false otherwise.
148
+ */
149
+ function isJsonSchemaBigint(input) {
150
+ if (!isSetObject(input)) return false;
151
+ const schema = input;
152
+ if (!hasValidJsonSchemaKeywords(schema) || schema.type !== "integer" || schema.format !== "int64") return false;
153
+ 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));
154
+ }
155
+ /**
156
+ * Type guard for boolean schemas.
157
+ *
158
+ * @param input - The value to check.
159
+ * @returns True if the input is a boolean schema, false otherwise.
160
+ */
161
+ function isJsonSchemaBoolean(input) {
162
+ if (!isSetObject(input)) return false;
163
+ const schema = input;
164
+ return hasValidJsonSchemaKeywords(schema) && schema.type === "boolean" && isOptionalBoolean(schema.default);
165
+ }
166
+ /**
167
+ * Type guard for date/time schemas.
168
+ *
169
+ * @param input - The value to check.
170
+ * @returns True if the input is a date or time schema, false otherwise.
171
+ */
172
+ function isJsonSchemaDate(input) {
173
+ if (!isSetObject(input)) return false;
174
+ const schema = input;
175
+ if (!hasValidJsonSchemaKeywords(schema)) return false;
176
+ if (schema.anyOf !== void 0) return isArrayOf(schema.anyOf, isJsonSchemaDate);
177
+ if (schema.type !== "integer" && schema.type !== "string") return false;
178
+ if (!isSetString(schema.format) || !DATE_FORMAT_SET.has(schema.format)) return false;
179
+ return isOptionalNumber(schema.minimum) && isOptionalNumber(schema.maximum) && (schema.default === void 0 || isSetString(schema.default) || isSetNumber(schema.default));
180
+ }
181
+ /**
182
+ * Type guard for enum-constrained schemas.
183
+ *
184
+ * @param input - The value to check.
185
+ * @returns True if the input is an enum-constrained schema, false otherwise.
186
+ */
187
+ function isJsonSchemaEnum(input) {
188
+ if (!isSetObject(input)) return false;
189
+ const schema = input;
190
+ if (!hasValidJsonSchemaKeywords(schema) || !isSetString(schema.type) || !JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(schema.type) || !Array.isArray(schema.enum)) return false;
191
+ const typeName = schema.type;
192
+ const enumValues = schema.enum;
193
+ const defaultValue = schema.default;
194
+ if (typeName === "string") return enumValues.every((value) => isSetString(value)) && (defaultValue === void 0 || isSetString(defaultValue));
195
+ if (typeName === "number" || typeName === "integer") return enumValues.every((value) => isSetNumber(value)) && (defaultValue === void 0 || isSetNumber(defaultValue));
196
+ if (typeName === "boolean") return enumValues.every((value) => isBoolean(value)) && (defaultValue === void 0 || isBoolean(defaultValue));
197
+ return typeName === "null" && enumValues.every((value) => value === null) && (defaultValue === void 0 || defaultValue === null);
198
+ }
199
+ /**
200
+ * Type guard for `allOf` composition schemas.
201
+ *
202
+ * @param input - The value to check.
203
+ * @returns True if the input is an `allOf` schema, false otherwise.
204
+ */
205
+ function isJsonSchemaAllOf(input) {
206
+ if (!isSetObject(input)) return false;
207
+ const schema = input;
208
+ if (!hasValidJsonSchemaKeywords(schema) || !isArrayOf(schema.allOf, isJsonSchema)) return false;
209
+ return schema.unevaluatedProperties === void 0 || isBoolean(schema.unevaluatedProperties) || isJsonSchema(schema.unevaluatedProperties);
210
+ }
211
+ /**
212
+ * Type guard for literal-value schemas.
213
+ *
214
+ * @param input - The value to check.
215
+ * @returns True if the input is a literal-value schema, false otherwise.
216
+ */
217
+ function isJsonSchemaLiteral(input) {
218
+ if (!isSetObject(input)) return false;
219
+ const schema = input;
220
+ if (!hasValidJsonSchemaKeywords(schema) || !("const" in schema)) return false;
221
+ return schema.type === void 0 || isSetString(schema.type) && isJsonSchemaType(schema.type) || isOptionalJsonSchemaTypeArray(schema.type);
222
+ }
223
+ /**
224
+ * Type guard for map tuple-array schemas.
225
+ *
226
+ * @param input - The value to check.
227
+ * @returns True if the input is a map tuple-array schema, false otherwise.
228
+ */
229
+ function isJsonSchemaMap(input) {
230
+ if (!isSetObject(input)) return false;
231
+ const schema = input;
232
+ if (!hasValidJsonSchemaKeywords(schema) || schema.type !== "array" || schema.maxItems !== 125 || !isSetObject(schema.items)) return false;
233
+ const items = schema.items;
234
+ return items.type === "array" && isTupleOfTwo(items.prefixItems, isJsonSchema, isJsonSchema) && (items.items === void 0 || items.items === false) && items.minItems === 2 && items.maxItems === 2;
235
+ }
236
+ /**
237
+ * Type guard for native enum schemas.
238
+ *
239
+ * @param input - The value to check.
240
+ * @returns True if the input is a native enum schema, false otherwise.
241
+ */
242
+ function isJsonSchemaNativeEnum(input) {
243
+ if (!isSetObject(input)) return false;
244
+ const schema = input;
245
+ const isValidType = schema.type === "string" || schema.type === "number" || Array.isArray(schema.type) && schema.type.length === 2 && schema.type[0] === "string" && schema.type[1] === "number";
246
+ return hasValidJsonSchemaKeywords(schema) && isValidType && Array.isArray(schema.enum) && schema.enum.every((value) => isSetString(value) || isSetNumber(value));
247
+ }
248
+ /**
249
+ * Type guard for impossible/never schemas.
250
+ *
251
+ * @param input - The value to check.
252
+ * @returns True if the input is a never schema, false otherwise.
253
+ */
254
+ function isJsonSchemaNever(input) {
255
+ if (!isSetObject(input)) return false;
256
+ const schema = input;
257
+ return hasValidJsonSchemaKeywords(schema) && isJsonSchemaAny(schema.not);
258
+ }
259
+ /**
260
+ * Type guard for `null` schemas.
261
+ *
262
+ * @param input - The value to check.
263
+ * @returns True if the input is a null schema, false otherwise.
264
+ */
265
+ function isJsonSchemaNull(input) {
266
+ if (!isSetObject(input)) return false;
267
+ const schema = input;
268
+ 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);
269
+ }
270
+ /**
271
+ * Type guard for nullable schema unions.
272
+ *
273
+ * @param input - The value to check.
274
+ * @returns True if the input is a nullable schema union, false otherwise.
275
+ */
276
+ function isJsonSchemaNullable(input) {
277
+ if (!isSetObject(input)) return false;
278
+ const schema = input;
279
+ if (!hasValidJsonSchemaKeywords(schema)) return false;
280
+ const anyOfBranch = schema.anyOf !== void 0 && Array.isArray(schema.anyOf) && schema.anyOf.length === 2 && isJsonSchema(schema.anyOf[0]) && isJsonSchemaNull(schema.anyOf[1]);
281
+ const typeBranch = Array.isArray(schema.type) && schema.type.length === 2 && (schema.type[0] === "null" && isSetString(schema.type[1]) && schema.type[1] !== "null" && JSON_SCHEMA_TYPE_SET.has(schema.type[1]) || schema.type[1] === "null" && isSetString(schema.type[0]) && schema.type[0] !== "null" && JSON_SCHEMA_TYPE_SET.has(schema.type[0]));
282
+ return anyOfBranch || typeBranch;
283
+ }
284
+ /**
285
+ * Type guard for numeric schemas.
286
+ *
287
+ * @param input - The value to check.
288
+ * @returns True if the input is a numeric schema, false otherwise.
289
+ */
290
+ function isJsonSchemaNumber(input) {
291
+ if (!isSetObject(input)) return false;
292
+ const schema = input;
293
+ if (!hasValidJsonSchemaKeywords(schema) || schema.type !== "number" && schema.type !== "integer") return false;
294
+ 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));
295
+ }
296
+ /**
297
+ * Type guard for integer schemas.
298
+ *
299
+ * @param input - The value to check.
300
+ * @returns True if the input is an integer schema, false otherwise.
301
+ */
302
+ function isJsonSchemaInteger(input) {
303
+ return isJsonSchemaNumber(input) && input.type === "integer";
304
+ }
305
+ /**
306
+ * Type guard for decimal schemas.
307
+ *
308
+ * @param input - The value to check.
309
+ * @returns True if the input is a decimal schema, false otherwise.
310
+ */
311
+ function isJsonSchemaDecimal(input) {
312
+ return isJsonSchemaNumber(input) && input.type === "number";
313
+ }
314
+ /**
315
+ * Type guard for object schemas.
316
+ *
317
+ * @param input - The value to check.
318
+ * @returns True if the input is an object schema, false otherwise.
319
+ */
320
+ function isJsonSchemaObject(input) {
321
+ if (!isSetObject(input)) return false;
322
+ const schema = input;
323
+ return hasValidJsonSchemaKeywords(schema) && schema.type === "object" && (schema.properties === void 0 || isRecordOfSchemaLike(schema.properties)) && (schema.patternProperties === void 0 || isRecordOfSchemaLike(schema.patternProperties)) && (schema.additionalProperties === void 0 || isBoolean(schema.additionalProperties) || isJsonSchema(schema.additionalProperties)) && (schema.required === void 0 || isStringArray(schema.required)) && (schema.unevaluatedProperties === void 0 || isBoolean(schema.unevaluatedProperties) || isJsonSchema(schema.unevaluatedProperties)) && (schema.dependencies === void 0 || 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);
324
+ }
325
+ /**
326
+ * Type guard for string schemas.
327
+ *
328
+ * @param input - The value to check.
329
+ * @returns True if the input is a string schema, false otherwise.
330
+ */
331
+ function isJsonSchemaString(input) {
332
+ if (!isSetObject(input)) return false;
333
+ const schema = input;
334
+ 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, isSetString)) && isOptionalString(schema.contentMediaType) && isOptionalString(schema.contentEncoding) && isOptionalString(schema.contentSchema);
335
+ }
336
+ /**
337
+ * Type guard for set-like array schemas.
338
+ *
339
+ * @param input - The value to check.
340
+ * @returns True if the input is a set-like array schema, false otherwise.
341
+ */
342
+ function isJsonSchemaSet(input) {
343
+ if (!isSetObject(input)) return false;
344
+ const schema = input;
345
+ 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 || isBoolean(schema.unevaluatedItems) || isJsonSchema(schema.unevaluatedItems));
346
+ }
347
+ /**
348
+ * Type guard for record schemas.
349
+ *
350
+ * @param input - The value to check.
351
+ * @returns True if the input is a record schema, false otherwise.
352
+ */
353
+ function isJsonSchemaRecord(input) {
354
+ if (!isSetObject(input)) return false;
355
+ const schema = input;
356
+ return hasValidJsonSchemaKeywords(schema) && schema.type === "object" && (schema.patternProperties === void 0 || isRecordOfSchemaLike(schema.patternProperties)) && (schema.additionalProperties === void 0 || isBoolean(schema.additionalProperties) || isJsonSchema(schema.additionalProperties)) && isOptionalJsonSchema(schema.propertyNames);
357
+ }
358
+ /**
359
+ * Type guard for tuple schemas.
360
+ *
361
+ * @param input - The value to check.
362
+ * @returns True if the input is a tuple schema, false otherwise.
363
+ */
364
+ function isJsonSchemaTuple(input) {
365
+ if (!isSetObject(input)) return false;
366
+ const schema = input;
367
+ 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 || isBoolean(schema.unevaluatedItems) || isJsonSchema(schema.unevaluatedItems));
368
+ }
369
+ /**
370
+ * Type guard for undefined-representing schemas.
371
+ *
372
+ * @param input - The value to check.
373
+ * @returns True if the input is an undefined-representing schema, false otherwise.
374
+ */
375
+ function isJsonSchemaUndefined(input) {
376
+ if (!isSetObject(input)) return false;
377
+ const schema = input;
378
+ return hasValidJsonSchemaKeywords(schema) && isJsonSchemaAny(schema.not) && (schema.default === void 0 || schema.default === void 0);
379
+ }
380
+ /**
381
+ * Type guard for primitive-union schema variants.
382
+ *
383
+ * @param input - The value to check.
384
+ * @returns True if the input is a primitive-union schema variant, false otherwise.
385
+ */
386
+ function isJsonSchemaPrimitiveUnion(input) {
387
+ if (!isSetObject(input)) return false;
388
+ const schema = input;
389
+ if (!hasValidJsonSchemaKeywords(schema)) return false;
390
+ if (isSetString(schema.type) && JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(schema.type)) {
391
+ if (schema.enum === void 0) return true;
392
+ if (!Array.isArray(schema.enum)) return false;
393
+ if (schema.type === "string") return schema.enum.every((value) => isSetString(value)) && (schema.default === void 0 || isSetString(schema.default));
394
+ if (schema.type === "number") return schema.enum.every((value) => isSetNumber(value)) && (schema.default === void 0 || isSetNumber(schema.default));
395
+ if (schema.type === "boolean") return schema.enum.every((value) => isBoolean(value)) && (schema.default === void 0 || isBoolean(schema.default));
396
+ if (schema.type === "integer") {
397
+ if (schema.format !== "int64") return false;
398
+ return schema.enum.every((value) => isSetBigint(value)) && (schema.default === void 0 || isSetBigint(schema.default));
399
+ }
400
+ return schema.type === "null" && schema.enum.every((value) => value === null) && (schema.default === void 0 || schema.default === null);
401
+ }
402
+ return isOptionalPrimitiveTypeArray(schema.type) && schema.type !== void 0;
403
+ }
404
+ /**
405
+ * Type guard for union schemas.
406
+ *
407
+ * @param input - The value to check.
408
+ * @returns True if the input is a union schema, false otherwise.
409
+ */
410
+ function isJsonSchemaUnion(input) {
411
+ if (!isSetObject(input)) return false;
412
+ const schema = input;
413
+ return hasValidJsonSchemaKeywords(schema) && (isJsonSchemaPrimitiveUnion(schema) || isJsonSchemaAnyOf(schema));
414
+ }
415
+ /**
416
+ * Type guard for permissive unknown schemas.
417
+ *
418
+ * @param input - The value to check.
419
+ * @returns True if the input is a permissive unknown schema, false otherwise.
420
+ */
421
+ function isJsonSchemaUnknown(input) {
422
+ return isJsonSchemaAny(input);
423
+ }
424
+ /**
425
+ * Type guard for `anyOf` composition schemas.
426
+ *
427
+ * @param input - The value to check.
428
+ * @returns True if the input is an `anyOf` schema, false otherwise.
429
+ */
430
+ function isJsonSchemaAnyOf(input) {
431
+ if (!isSetObject(input)) return false;
432
+ const schema = input;
433
+ return hasValidJsonSchemaKeywords(schema) && isArrayOf(schema.anyOf, isJsonSchema);
434
+ }
435
+ /**
436
+ * Type guard for reference schemas.
437
+ *
438
+ * @param input - The value to check.
439
+ * @returns True if the input is a reference schema, false otherwise.
440
+ */
441
+ function isJsonSchemaRef(input) {
442
+ if (!isSetObject(input)) return false;
443
+ const schema = input;
444
+ return hasValidJsonSchemaKeywords(schema) && isSetString(schema.$ref);
445
+ }
446
+ /**
447
+ * Type guard for Standard Schema V1 objects.
448
+ *
449
+ * @param input - The value to check.
450
+ * @returns True if the input is a Standard Schema V1 object, false otherwise.
451
+ */
452
+ function isStandardSchema(input) {
453
+ if (!isSetObject(input)) return false;
454
+ const schema = input;
455
+ if (!isSetObject(schema["~standard"])) return false;
456
+ const standard = schema["~standard"];
457
+ return standard.version === 1 && isFunction(standard.validate);
458
+ }
459
+ /**
460
+ * Type guard for Valibot BaseSchema objects.
461
+ *
462
+ * @param input - The value to check.
463
+ * @returns True if the input is a Valibot BaseSchema, false otherwise.
464
+ */
465
+ function isValibotSchema(input) {
466
+ if (!isSetObject(input) || !isStandardSchema(input)) return false;
467
+ const schema = input;
468
+ return schema.kind === "schema" && isSetString(schema.type) && isBoolean(schema.async) && isFunction(schema.reference) && isSetString(schema.expects) && isFunction(schema["~run"]);
469
+ }
470
+ /**
471
+ * Type guard for JSON Schema types.
472
+ *
473
+ * @remarks
474
+ * This function checks if the input is a JSON Schema type, which is defined as having a `type` property or a `$ref` property. This is used to determine if a given input conforms to the structure of a JSON Schema definition that includes type information.
475
+ *
476
+ * @param input - The value to check.
477
+ * @returns True if the input is a JSON Schema type, false otherwise.
478
+ */
479
+ function isJsonSchema(input) {
480
+ 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);
481
+ }
482
+ /**
483
+ * Type guard for JSON Schemas that only accept `null`.
484
+ *
485
+ * @remarks
486
+ * This function checks if the input is a JSON Schema that exclusively accepts the `null` type. It verifies that the input is a valid JSON Schema and that its `type` property is set to "null". This is useful for identifying schemas that are specifically designed to allow only `null` values.
487
+ *
488
+ * @param input - The value to check.
489
+ * @returns True if the input is a JSON Schema that only accepts `null`, false otherwise.
490
+ */
491
+ function isNullOnlyJsonSchema(input) {
492
+ return isJsonSchemaNull(input);
493
+ }
494
+ /**
495
+ * Type guard for untyped schema objects.
496
+ *
497
+ * @remarks
498
+ * This function checks if the input is an untyped schema object, which is defined as having certain properties that are commonly found in untyped schema definitions. This includes properties such as `id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`. The function verifies that these properties, if present, conform to the expected types (e.g., strings for certain properties, arrays for others). This type guard is used to determine if a given input can be treated as an untyped schema object within the context of the Powerlines schema system.
499
+ *
500
+ * @param input - The value to check.
501
+ * @returns True if the input is an untyped schema object, false otherwise.
502
+ */
503
+ function isUntypedSchema(input) {
504
+ if (!isSetObject(input)) return false;
505
+ const schema = input;
506
+ if (!isUntypedTypeDescriptor(schema)) return false;
507
+ if ("id" in schema && !isSetString(schema.id)) return false;
508
+ if ("resolve" in schema && !isFunction(schema.resolve)) return false;
509
+ if ("properties" in schema && !isRecordOfUntypedSchema(schema.properties)) return false;
510
+ if ("required" in schema && !isStringArray(schema.required)) return false;
511
+ if ("title" in schema && !isSetString(schema.title)) return false;
512
+ if ("description" in schema && !isSetString(schema.description)) return false;
513
+ if ("$schema" in schema && !isSetString(schema.$schema)) return false;
514
+ if ("tags" in schema && !isStringArray(schema.tags)) return false;
515
+ if ("args" in schema && (!Array.isArray(schema.args) || !schema.args.every((item) => isUntypedFunctionArg(item)))) return false;
516
+ if ("returns" in schema && !isUntypedTypeDescriptor(schema.returns)) return false;
517
+ return true;
518
+ }
519
+ /**
520
+ * Strict type guard for untyped schema objects.
521
+ *
522
+ * @remarks
523
+ * This guard narrows values to the Untyped schema model while explicitly
524
+ * rejecting values that are also valid JSON Schema instances.
525
+ *
526
+ * @param input - The value to check.
527
+ * @returns True if the input is an untyped schema and not a JSON Schema.
528
+ */
529
+ function isUntypedSchemaStrict(input) {
530
+ return isUntypedSchema(input) && !isJsonSchema(input);
531
+ }
532
+ /**
533
+ * Type guard for untyped input objects.
534
+ *
535
+ * @remarks
536
+ * This function checks if the input is an untyped input object, which is defined as having certain properties that are commonly found in untyped input definitions. This includes properties such as `$schema` and `$resolve`. The function verifies that these properties, if present, conform to the expected types (e.g., objects for `$schema`, functions for `$resolve`). This type guard is used to determine if a given input can be treated as an untyped input object within the context of the Powerlines schema system.
537
+ *
538
+ * @param input - The value to check.
539
+ * @returns True if the input is an untyped input object, false otherwise.
540
+ */
541
+ function isUntypedInput(input) {
542
+ if (!isSetObject(input)) return false;
543
+ const inputObject = input;
544
+ if ("$schema" in inputObject && !isUntypedSchema(inputObject.$schema)) return false;
545
+ if ("$resolve" in inputObject && !isFunction(inputObject.$resolve)) return false;
546
+ return true;
547
+ }
548
+ /**
549
+ * Strict type guard for untyped input objects.
550
+ *
551
+ * @remarks
552
+ * This guard narrows values to the Untyped input-object model while
553
+ * explicitly rejecting values that are valid JSON Schema objects.
554
+ *
555
+ * @param input - The value to check.
556
+ * @returns True if the input is an untyped input object and not JSON Schema.
557
+ */
558
+ function isUntypedInputStrict(input) {
559
+ if (!isUntypedInput(input) || isJsonSchema(input)) return false;
560
+ const inputObject = input;
561
+ if ("$schema" in inputObject && inputObject.$schema !== void 0 && !isUntypedSchemaStrict(inputObject.$schema)) return false;
562
+ return true;
563
+ }
564
+ /**
565
+ * Type guard for Powerlines Schema objects.
566
+ *
567
+ * @param input - The value to check.
568
+ * @returns True if the input is a Powerlines Schema object, false otherwise.
569
+ */
570
+ function isSchema(input) {
571
+ return isSetObject(input) && "schema" in input && isJsonSchema(input.schema) && "variant" in input && isSetString(input.variant) && "hash" in input && isSetString(input.hash);
572
+ }
573
+ /**
574
+ * Type guard for extracted schema objects that include source information.
575
+ *
576
+ * @param input - The value to check.
577
+ * @returns True if the input is a SchemaWithSource object, false otherwise.
578
+ */
579
+ function isSchemaWithSource(input) {
580
+ return isSchema(input) && "source" in input && isSetObject(input.source) && "schema" in input.source && "variant" in input.source && isSetString(input.source.variant);
581
+ }
582
+ /**
583
+ * Type guard for Powerlines Schemas that are in Object form.
584
+ *
585
+ * @param input - The value to check.
586
+ * @returns True if the input is a Powerlines Schema object in Object form, false otherwise.
587
+ */
588
+ function isSchemaObject(input) {
589
+ return isSchema(input) && isJsonSchemaObject(input.schema);
590
+ }
591
+
592
+ //#endregion
593
+ export { isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isSchema, isSchemaObject, isSchemaWithSource, isStandardSchema, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema };
594
+ //# sourceMappingURL=type-checks.mjs.map