@powerlines/schema 0.11.27 → 0.11.37

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 (82) hide show
  1. package/dist/bundle.cjs +34 -20
  2. package/dist/bundle.d.cts +3 -3
  3. package/dist/bundle.d.cts.map +1 -1
  4. package/dist/bundle.d.mts +3 -3
  5. package/dist/bundle.d.mts.map +1 -1
  6. package/dist/bundle.mjs +35 -21
  7. package/dist/bundle.mjs.map +1 -1
  8. package/dist/codegen.cjs +40 -36
  9. package/dist/codegen.d.cts +10 -22
  10. package/dist/codegen.d.cts.map +1 -1
  11. package/dist/codegen.d.mts +10 -22
  12. package/dist/codegen.d.mts.map +1 -1
  13. package/dist/codegen.mjs +39 -36
  14. package/dist/codegen.mjs.map +1 -1
  15. package/dist/constants.cjs +34 -11
  16. package/dist/constants.d.cts +9 -11
  17. package/dist/constants.d.cts.map +1 -1
  18. package/dist/constants.d.mts +9 -11
  19. package/dist/constants.d.mts.map +1 -1
  20. package/dist/constants.mjs +32 -11
  21. package/dist/constants.mjs.map +1 -1
  22. package/dist/extract.cjs +122 -92
  23. package/dist/extract.d.cts +34 -69
  24. package/dist/extract.d.cts.map +1 -1
  25. package/dist/extract.d.mts +34 -69
  26. package/dist/extract.d.mts.map +1 -1
  27. package/dist/extract.mjs +123 -93
  28. package/dist/extract.mjs.map +1 -1
  29. package/dist/helpers.cjs +45 -52
  30. package/dist/helpers.d.cts +28 -24
  31. package/dist/helpers.d.cts.map +1 -1
  32. package/dist/helpers.d.mts +28 -24
  33. package/dist/helpers.d.mts.map +1 -1
  34. package/dist/helpers.mjs +46 -52
  35. package/dist/helpers.mjs.map +1 -1
  36. package/dist/index.cjs +14 -7
  37. package/dist/index.d.cts +6 -6
  38. package/dist/index.d.mts +6 -6
  39. package/dist/index.mjs +5 -5
  40. package/dist/metadata.cjs +80 -0
  41. package/dist/metadata.d.cts +52 -0
  42. package/dist/metadata.d.cts.map +1 -0
  43. package/dist/metadata.d.mts +52 -0
  44. package/dist/metadata.d.mts.map +1 -0
  45. package/dist/metadata.mjs +76 -0
  46. package/dist/metadata.mjs.map +1 -0
  47. package/dist/persistence.cjs +1 -2
  48. package/dist/persistence.d.cts +5 -5
  49. package/dist/persistence.d.cts.map +1 -1
  50. package/dist/persistence.d.mts +5 -5
  51. package/dist/persistence.d.mts.map +1 -1
  52. package/dist/persistence.mjs +1 -1
  53. package/dist/persistence.mjs.map +1 -1
  54. package/dist/reflection.cjs +289 -303
  55. package/dist/reflection.d.cts +3 -16
  56. package/dist/reflection.d.cts.map +1 -1
  57. package/dist/reflection.d.mts +3 -16
  58. package/dist/reflection.d.mts.map +1 -1
  59. package/dist/reflection.mjs +290 -304
  60. package/dist/reflection.mjs.map +1 -1
  61. package/dist/resolve.cjs +7 -7
  62. package/dist/resolve.mjs +7 -7
  63. package/dist/resolve.mjs.map +1 -1
  64. package/dist/type-checks.cjs +122 -40
  65. package/dist/type-checks.d.cts +41 -33
  66. package/dist/type-checks.d.cts.map +1 -1
  67. package/dist/type-checks.d.mts +41 -33
  68. package/dist/type-checks.d.mts.map +1 -1
  69. package/dist/type-checks.mjs +120 -37
  70. package/dist/type-checks.mjs.map +1 -1
  71. package/dist/types.d.cts +225 -113
  72. package/dist/types.d.cts.map +1 -1
  73. package/dist/types.d.mts +225 -113
  74. package/dist/types.d.mts.map +1 -1
  75. package/package.json +11 -7
  76. package/dist/jtd.cjs +0 -385
  77. package/dist/jtd.d.cts +0 -15
  78. package/dist/jtd.d.cts.map +0 -1
  79. package/dist/jtd.d.mts +0 -15
  80. package/dist/jtd.d.mts.map +0 -1
  81. package/dist/jtd.mjs +0 -384
  82. package/dist/jtd.mjs.map +0 -1
@@ -1,57 +1,65 @@
1
- import { ExtractedSchema, JTDSchemaObjectType, ObjectSchema, Schema as Schema$1, SchemaMetadata } from "./types.mjs";
1
+ import { ExtractedSchema, JsonSchema, JsonSchemaObject, Schema as Schema$1 } from "./types.mjs";
2
2
  import { InputObject, Schema } from "untyped";
3
- import { JTDSchemaType } from "ajv/dist/types/jtd-schema.js";
4
3
 
5
4
  //#region src/type-checks.d.ts
6
5
  /**
7
- * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
6
+ * Type guard for JSON Schema types.
8
7
  *
9
- * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
10
- * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
11
- */
12
- declare function isJTDSchemaObject<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is JTDSchemaObjectType<TMetadata>;
13
- /**
14
- * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
8
+ * @remarks
9
+ * 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.
15
10
  *
16
- * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
17
- * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
11
+ * @param input - The value to check.
12
+ * @returns True if the input is a JSON Schema type, false otherwise.
18
13
  */
19
- declare function isJTDSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is JTDSchemaType<TMetadata>;
14
+ declare function isJsonSchema<T = unknown>(input: unknown): input is JsonSchema<T>;
20
15
  /**
21
- * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedSchema | Schema} object. This function verifies that the input is a non-null object whose optional metadata properties (`id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`) - when present - match the shapes declared by `untyped`'s [`Schema`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface.
16
+ * Type guard for JSON Schema object forms.
17
+ *
18
+ * @remarks
19
+ * 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.
22
20
  *
23
- * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) schema.
24
- * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) schema, otherwise `false`.
21
+ * @param input - The value to check.
22
+ * @returns True if the input is a JSON Schema object type, false otherwise.
25
23
  */
26
- declare function isUntypedSchema(input: unknown): input is Schema;
24
+ declare function isJsonSchemaObject<T extends Record<string, any> = Record<string, any>>(input: unknown): input is JsonSchemaObject<T>;
27
25
  /**
28
- * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedInputObject | InputObject}. This function verifies that the input is a non-null object and that any `untyped`-reserved `$`-prefixed properties have the expected shape: `$schema` (when present) must satisfy {@link isUntypedSchema} and `$resolve` (when present) must be a function. See `untyped`'s [`InputObject`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface for the canonical definition.
26
+ * Type guard for JSON Schemas that only accept `null`.
27
+ *
28
+ * @remarks
29
+ * 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.
29
30
  *
30
- * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) input object.
31
- * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) input object, otherwise `false`.
31
+ * @param input - The value to check.
32
+ * @returns True if the input is a JSON Schema that only accepts `null`, false otherwise.
32
33
  */
33
- declare function isUntypedInput(input: unknown): input is InputObject;
34
+ declare function isNullOnlyJsonSchema(input: unknown): input is JsonSchema<null>;
34
35
  /**
35
- * Type guard to check if a given input is a {@link Schema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link Schema}; otherwise, it returns `false`.
36
+ * Type guard for untyped schema objects.
37
+ *
38
+ * @remarks
39
+ * 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.
36
40
  *
37
- * @param input - The input to check for being a {@link Schema}.
38
- * @returns `true` if the input is a {@link Schema}, otherwise `false`.
41
+ * @param input - The value to check.
42
+ * @returns True if the input is an untyped schema object, false otherwise.
39
43
  */
40
- declare function isSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is Schema$1<TMetadata>;
44
+ declare function isUntypedSchema(input: unknown): input is Schema;
41
45
  /**
42
- * Type guard to check if a given input is a {@link ExtractedSchema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link ExtractedSchema}; otherwise, it returns `false`.
46
+ * Type guard for untyped input objects.
43
47
  *
44
- * @param input - The input to check for being a {@link ExtractedSchema}.
45
- * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
48
+ * @remarks
49
+ * 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.
50
+ *
51
+ * @param input - The value to check.
52
+ * @returns True if the input is an untyped input object, false otherwise.
46
53
  */
47
- declare function isExtractedSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ExtractedSchema<TMetadata>;
54
+ declare function isUntypedInput(input: unknown): input is InputObject;
48
55
  /**
49
- * Type guard to check if a given input is a {@link ObjectSchema} object. This function verifies that the input is a {@link Schema} object and that its `schema` property has either a `properties` property that is an object or an `optionalProperties` property that is an object (as per the structure of JTD schema objects). If these conditions are met, the function returns `true`, indicating that the input is a valid {@link ObjectSchema}; otherwise, it returns `false`.
56
+ * Type guard for Powerlines Schema objects.
50
57
  *
51
- * @param input - The input to check for being a {@link ObjectSchema}.
52
- * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.
58
+ * @param input - The value to check.
59
+ * @returns True if the input is a Powerlines Schema object, false otherwise.
53
60
  */
54
- declare function isObjectSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ObjectSchema<TMetadata>;
61
+ declare function isSchema<T = unknown>(input: unknown): input is Schema$1<T>;
62
+ declare function isExtractedSchema<T = unknown>(input: unknown): input is ExtractedSchema<T>;
55
63
  //#endregion
56
- export { isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema };
64
+ export { isExtractedSchema, isJsonSchema, isJsonSchemaObject, isNullOnlyJsonSchema, isSchema, isUntypedInput, isUntypedSchema };
57
65
  //# sourceMappingURL=type-checks.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-checks.d.mts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AA2CA;;;;iBAAgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,mBAAA,CAAoB,SAAA;;;;;;;iBAchC,WAAA,mBAA8B,cAAA,GAAiB,cAAA,CAAA,CAC7D,KAAA,YACC,KAAA,IAAS,aAAA,CAAc,SAAA;;;;;;AAhB+B;iBAsCzC,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAa;;;;;;;iBAwDvD,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAkB;;;;;;;iBAsB3D,QAAA,mBAA2B,cAAA,GAAiB,cAAA,CAAA,CAC1D,KAAA,YACC,KAAA,IAAS,QAAA,CAAO,SAAA;;;AAtGgB;AAsBnC;;;iBAkGgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,SAAA;;;;;AApG2B;AAwDvE;iBA8DgB,cAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,YAAA,CAAa,SAAA"}
1
+ {"version":3,"file":"type-checks.d.mts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;AAyHA;;;;;;;iBAAgB,YAAA,aAAA,CACd,KAAA,YACC,KAAA,IAAS,UAAU,CAAC,CAAA;;;AAAC;AA4FxB;;;;;;iBAAgB,kBAAA,WACJ,MAAA,gBAAsB,MAAA,cAAA,CAChC,KAAA,YAAiB,KAAA,IAAS,gBAAA,CAAiB,CAAA;;;;;;;;;;iBAgB7B,oBAAA,CACd,KAAA,YACC,KAAA,IAAS,UAAU;AAlBwB;AAgB9C;;;;;;;;AAhB8C,iBA+B9B,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAa;AAAvE;;;;;;;;AAAuE;AAAvE,iBA2DgB,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAkB;;;;;;;iBAsB3D,QAAA,aAAA,CAAsB,KAAA,YAAiB,KAAA,IAAS,QAAM,CAAC,CAAA;AAAA,iBAYvD,iBAAA,aAAA,CACd,KAAA,YACC,KAAA,IAAS,eAAe,CAAC,CAAA"}
@@ -1,29 +1,124 @@
1
+ import { JSON_SCHEMA_DATA_TYPES } from "./constants.mjs";
1
2
  import { isFunction, isObject, isSetObject, isSetString } from "@stryke/type-checks";
3
+ import { isJsonSchemaObjectType } from "@stryke/json";
2
4
 
3
5
  //#region src/type-checks.ts
6
+ const JSON_SCHEMA_DATA_TYPE_SET = new Set(JSON_SCHEMA_DATA_TYPES);
7
+ const isSetNumber = (value) => typeof value === "number" && Number.isFinite(value);
8
+ const isSetBoolean = (value) => typeof value === "boolean";
9
+ const isNonNegativeInteger = (value) => Number.isInteger(value) && value >= 0;
10
+ const isSchemaLikeValue = (value) => isSetObject(value) || isSetBoolean(value);
11
+ const isStringArray = (value) => Array.isArray(value) && value.every((item) => isSetString(item));
12
+ const isRecordOfStringArrays = (value) => isSetObject(value) && Object.values(value).every((item) => isStringArray(item));
13
+ const TYPE_KEYWORD_VALIDATORS = {
14
+ string: {
15
+ minLength: isNonNegativeInteger,
16
+ maxLength: isNonNegativeInteger,
17
+ pattern: isSetString,
18
+ format: isSetString,
19
+ contentEncoding: isSetString,
20
+ contentMediaType: isSetString
21
+ },
22
+ number: {
23
+ minimum: isSetNumber,
24
+ maximum: isSetNumber,
25
+ exclusiveMinimum: isSetNumber,
26
+ exclusiveMaximum: isSetNumber,
27
+ multipleOf: isSetNumber
28
+ },
29
+ integer: {
30
+ minimum: isSetNumber,
31
+ maximum: isSetNumber,
32
+ exclusiveMinimum: isSetNumber,
33
+ exclusiveMaximum: isSetNumber,
34
+ multipleOf: isSetNumber
35
+ },
36
+ boolean: {},
37
+ array: {
38
+ items: isSchemaLikeValue,
39
+ prefixItems: Array.isArray,
40
+ contains: isSchemaLikeValue,
41
+ minItems: isNonNegativeInteger,
42
+ maxItems: isNonNegativeInteger,
43
+ uniqueItems: isSetBoolean,
44
+ minContains: isNonNegativeInteger,
45
+ maxContains: isNonNegativeInteger
46
+ },
47
+ object: {
48
+ properties: isSetObject,
49
+ patternProperties: isSetObject,
50
+ additionalProperties: isSchemaLikeValue,
51
+ required: isStringArray,
52
+ minProperties: isNonNegativeInteger,
53
+ maxProperties: isNonNegativeInteger,
54
+ dependentRequired: isRecordOfStringArrays,
55
+ dependentSchemas: isSetObject,
56
+ propertyNames: isSchemaLikeValue,
57
+ unevaluatedProperties: isSchemaLikeValue
58
+ },
59
+ null: {}
60
+ };
4
61
  /**
5
- * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
62
+ * Type guard for JSON Schema types.
6
63
  *
7
- * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
8
- * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
64
+ * @remarks
65
+ * 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.
66
+ *
67
+ * @param input - The value to check.
68
+ * @returns True if the input is a JSON Schema type, false otherwise.
9
69
  */
10
- function isJTDSchemaObject(input) {
11
- return isSetObject(input) && ("properties" in input && isObject(input.properties) || "optionalProperties" in input && isObject(input.optionalProperties));
70
+ function isJsonSchema(input) {
71
+ if (!isSetObject(input)) return false;
72
+ const schema = input;
73
+ if ("$ref" in schema && isSetString(schema.$ref)) return true;
74
+ if (!("type" in schema)) return false;
75
+ const schemaTypes = [];
76
+ if (isSetString(schema.type)) {
77
+ if (!JSON_SCHEMA_DATA_TYPE_SET.has(schema.type)) return false;
78
+ schemaTypes.push(schema.type);
79
+ } else if (Array.isArray(schema.type) && schema.type.length > 0) {
80
+ if (!schema.type.every((schemaType) => isSetString(schemaType) && JSON_SCHEMA_DATA_TYPE_SET.has(schemaType)) || new Set(schema.type).size !== schema.type.length) return false;
81
+ schemaTypes.push(...schema.type);
82
+ } else return false;
83
+ const typeKeywordValidators = schemaTypes.flatMap((schemaType) => Object.entries(TYPE_KEYWORD_VALIDATORS[schemaType]));
84
+ for (const [keyword, validator] of typeKeywordValidators) if (keyword in schema && !validator(schema[keyword])) return false;
85
+ if ("minItems" in schema && "maxItems" in schema && isNonNegativeInteger(schema.minItems) && isNonNegativeInteger(schema.maxItems) && schema.minItems > schema.maxItems) return false;
86
+ if ("minLength" in schema && "maxLength" in schema && isNonNegativeInteger(schema.minLength) && isNonNegativeInteger(schema.maxLength) && schema.minLength > schema.maxLength) return false;
87
+ if ("minProperties" in schema && "maxProperties" in schema && isNonNegativeInteger(schema.minProperties) && isNonNegativeInteger(schema.maxProperties) && schema.minProperties > schema.maxProperties) return false;
88
+ return true;
12
89
  }
13
90
  /**
14
- * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
91
+ * Type guard for JSON Schema object forms.
92
+ *
93
+ * @remarks
94
+ * 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.
15
95
  *
16
- * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
17
- * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
96
+ * @param input - The value to check.
97
+ * @returns True if the input is a JSON Schema object type, false otherwise.
18
98
  */
19
- function isJTDSchema(input) {
20
- return isSetObject(input) && (isJTDSchemaObject(input) || "elements" in input || "values" in input || "ref" in input || "type" in input || "enum" in input || "discriminator" in input && isSetString(input.discriminator) && "mapping" in input && isObject(input.mapping));
99
+ function isJsonSchemaObject(input) {
100
+ return isJsonSchemaObjectType(input) && (input.type === "object" || isObject(input.properties));
21
101
  }
22
102
  /**
23
- * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedSchema | Schema} object. This function verifies that the input is a non-null object whose optional metadata properties (`id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`) - when present - match the shapes declared by `untyped`'s [`Schema`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface.
103
+ * Type guard for JSON Schemas that only accept `null`.
24
104
  *
25
- * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) schema.
26
- * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) schema, otherwise `false`.
105
+ * @remarks
106
+ * 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.
107
+ *
108
+ * @param input - The value to check.
109
+ * @returns True if the input is a JSON Schema that only accepts `null`, false otherwise.
110
+ */
111
+ function isNullOnlyJsonSchema(input) {
112
+ return isJsonSchema(input) && input.type === "null";
113
+ }
114
+ /**
115
+ * Type guard for untyped schema objects.
116
+ *
117
+ * @remarks
118
+ * 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.
119
+ *
120
+ * @param input - The value to check.
121
+ * @returns True if the input is an untyped schema object, false otherwise.
27
122
  */
28
123
  function isUntypedSchema(input) {
29
124
  if (!isSetObject(input)) return false;
@@ -43,10 +138,13 @@ function isUntypedSchema(input) {
43
138
  return true;
44
139
  }
45
140
  /**
46
- * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedInputObject | InputObject}. This function verifies that the input is a non-null object and that any `untyped`-reserved `$`-prefixed properties have the expected shape: `$schema` (when present) must satisfy {@link isUntypedSchema} and `$resolve` (when present) must be a function. See `untyped`'s [`InputObject`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface for the canonical definition.
141
+ * Type guard for untyped input objects.
142
+ *
143
+ * @remarks
144
+ * 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.
47
145
  *
48
- * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) input object.
49
- * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) input object, otherwise `false`.
146
+ * @param input - The value to check.
147
+ * @returns True if the input is an untyped input object, false otherwise.
50
148
  */
51
149
  function isUntypedInput(input) {
52
150
  if (!isSetObject(input)) return false;
@@ -56,33 +154,18 @@ function isUntypedInput(input) {
56
154
  return true;
57
155
  }
58
156
  /**
59
- * Type guard to check if a given input is a {@link Schema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link Schema}; otherwise, it returns `false`.
157
+ * Type guard for Powerlines Schema objects.
60
158
  *
61
- * @param input - The input to check for being a {@link Schema}.
62
- * @returns `true` if the input is a {@link Schema}, otherwise `false`.
159
+ * @param input - The value to check.
160
+ * @returns True if the input is a Powerlines Schema object, false otherwise.
63
161
  */
64
162
  function isSchema(input) {
65
- return isSetObject(input) && "schema" in input && isJTDSchema(input.schema) && "input" in input && isSetObject(input.input) && "variant" in input && isSetString(input.variant);
163
+ return isSetObject(input) && "schema" in input && isJsonSchema(input.schema) && "variant" in input && isSetString(input.variant) && "hash" in input && isSetString(input.hash);
66
164
  }
67
- /**
68
- * Type guard to check if a given input is a {@link ExtractedSchema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link ExtractedSchema}; otherwise, it returns `false`.
69
- *
70
- * @param input - The input to check for being a {@link ExtractedSchema}.
71
- * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
72
- */
73
165
  function isExtractedSchema(input) {
74
- return isSchema(input) && "source" in input && isSetObject(input.source) && "schema" in input.source && isJTDSchema(input.source.schema) && "variant" in input.source && isSetString(input.source.variant);
75
- }
76
- /**
77
- * Type guard to check if a given input is a {@link ObjectSchema} object. This function verifies that the input is a {@link Schema} object and that its `schema` property has either a `properties` property that is an object or an `optionalProperties` property that is an object (as per the structure of JTD schema objects). If these conditions are met, the function returns `true`, indicating that the input is a valid {@link ObjectSchema}; otherwise, it returns `false`.
78
- *
79
- * @param input - The input to check for being a {@link ObjectSchema}.
80
- * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.
81
- */
82
- function isObjectSchema(input) {
83
- return isSchema(input) && isJTDSchemaObject(input.schema);
166
+ return isSchema(input) && "source" in input && isSetObject(input.source) && "schema" in input.source && "variant" in input.source && isSetString(input.source.variant);
84
167
  }
85
168
 
86
169
  //#endregion
87
- export { isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema };
170
+ export { isExtractedSchema, isJsonSchema, isJsonSchemaObject, isNullOnlyJsonSchema, isSchema, isUntypedInput, isUntypedSchema };
88
171
  //# sourceMappingURL=type-checks.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-checks.mjs","names":[],"sources":["../src/type-checks.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport {\n isFunction,\n isObject,\n isSetObject,\n isSetString\n} from \"@stryke/type-checks\";\nimport { JTDSchemaType } from \"ajv/dist/types/jtd-schema\";\nimport {\n InputObject as UntypedInputObject,\n Schema as UntypedSchema\n} from \"untyped\";\nimport {\n ExtractedSchema,\n JTDSchemaObjectType,\n ObjectSchema,\n Schema,\n SchemaMetadata\n} from \"./types\";\n\n/**\n * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).\n * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.\n */\nexport function isJTDSchemaObject<\n TMetadata extends SchemaMetadata = SchemaMetadata\n>(input: unknown): input is JTDSchemaObjectType<TMetadata> {\n return (\n isSetObject(input) &&\n ((\"properties\" in input && isObject(input.properties)) ||\n (\"optionalProperties\" in input && isObject(input.optionalProperties)))\n );\n}\n\n/**\n * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).\n * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.\n */\nexport function isJTDSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(\n input: unknown\n): input is JTDSchemaType<TMetadata> {\n return (\n isSetObject(input) &&\n (isJTDSchemaObject<TMetadata>(input) ||\n \"elements\" in input ||\n \"values\" in input ||\n \"ref\" in input ||\n \"type\" in input ||\n \"enum\" in input ||\n (\"discriminator\" in input &&\n isSetString(input.discriminator) &&\n \"mapping\" in input &&\n isObject(input.mapping)))\n );\n}\n\n/**\n * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedSchema | Schema} object. This function verifies that the input is a non-null object whose optional metadata properties (`id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`) - when present - match the shapes declared by `untyped`'s [`Schema`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface.\n *\n * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) schema.\n * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) schema, otherwise `false`.\n */\nexport function isUntypedSchema(input: unknown): input is UntypedSchema {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\"id\" in schema && !isSetString(schema.id)) {\n return false;\n }\n if (\"title\" in schema && !isSetString(schema.title)) {\n return false;\n }\n if (\"description\" in schema && !isSetString(schema.description)) {\n return false;\n }\n if (\"$schema\" in schema && !isSetString(schema.$schema)) {\n return false;\n }\n if (\"tsType\" in schema && !isSetString(schema.tsType)) {\n return false;\n }\n if (\"markdownType\" in schema && !isSetString(schema.markdownType)) {\n return false;\n }\n if (\n \"type\" in schema &&\n !isSetString(schema.type) &&\n !Array.isArray(schema.type)\n ) {\n return false;\n }\n if (\"required\" in schema && !Array.isArray(schema.required)) {\n return false;\n }\n if (\"tags\" in schema && !Array.isArray(schema.tags)) {\n return false;\n }\n if (\"args\" in schema && !Array.isArray(schema.args)) {\n return false;\n }\n if (\"properties\" in schema && !isSetObject(schema.properties)) {\n return false;\n }\n if (\"resolve\" in schema && !isFunction(schema.resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedInputObject | InputObject}. This function verifies that the input is a non-null object and that any `untyped`-reserved `$`-prefixed properties have the expected shape: `$schema` (when present) must satisfy {@link isUntypedSchema} and `$resolve` (when present) must be a function. See `untyped`'s [`InputObject`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface for the canonical definition.\n *\n * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) input object.\n * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) input object, otherwise `false`.\n */\nexport function isUntypedInput(input: unknown): input is UntypedInputObject {\n if (!isSetObject(input)) {\n return false;\n }\n\n const inputObject = input as Record<string, unknown>;\n if (\"$schema\" in inputObject && !isUntypedSchema(inputObject.$schema)) {\n return false;\n }\n if (\"$resolve\" in inputObject && !isFunction(inputObject.$resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard to check if a given input is a {@link Schema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants (\"json-schema\", \"standard-schema\", \"zod3\", or \"reflection\"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link Schema}; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a {@link Schema}.\n * @returns `true` if the input is a {@link Schema}, otherwise `false`.\n */\nexport function isSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(\n input: unknown\n): input is Schema<TMetadata> {\n return (\n isSetObject(input) &&\n \"schema\" in input &&\n isJTDSchema(input.schema) &&\n \"input\" in input &&\n isSetObject(input.input) &&\n \"variant\" in input &&\n isSetString(input.variant)\n );\n}\n\n/**\n * Type guard to check if a given input is a {@link ExtractedSchema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants (\"json-schema\", \"standard-schema\", \"zod3\", or \"reflection\"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link ExtractedSchema}; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a {@link ExtractedSchema}.\n * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.\n */\nexport function isExtractedSchema<\n TMetadata extends SchemaMetadata = SchemaMetadata\n>(input: unknown): input is ExtractedSchema<TMetadata> {\n return (\n isSchema<TMetadata>(input) &&\n \"source\" in input &&\n isSetObject(input.source) &&\n \"schema\" in input.source &&\n isJTDSchema(input.source.schema) &&\n \"variant\" in input.source &&\n isSetString(input.source.variant)\n );\n}\n\n/**\n * Type guard to check if a given input is a {@link ObjectSchema} object. This function verifies that the input is a {@link Schema} object and that its `schema` property has either a `properties` property that is an object or an `optionalProperties` property that is an object (as per the structure of JTD schema objects). If these conditions are met, the function returns `true`, indicating that the input is a valid {@link ObjectSchema}; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a {@link ObjectSchema}.\n * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.\n */\nexport function isObjectSchema<\n TMetadata extends SchemaMetadata = SchemaMetadata\n>(input: unknown): input is ObjectSchema<TMetadata> {\n return (\n isSchema<TMetadata>(input) && isJTDSchemaObject<TMetadata>(input.schema)\n );\n}\n"],"mappings":";;;;;;;;;AA2CA,SAAgB,kBAEd,OAAyD;CACzD,OACE,YAAY,KAAK,MACf,gBAAgB,SAAS,SAAS,MAAM,UAAU,KACjD,wBAAwB,SAAS,SAAS,MAAM,kBAAkB;AAEzE;;;;;;;AAQA,SAAgB,YACd,OACmC;CACnC,OACE,YAAY,KAAK,MAChB,kBAA6B,KAAK,KACjC,cAAc,SACd,YAAY,SACZ,SAAS,SACT,UAAU,SACV,UAAU,SACT,mBAAmB,SAClB,YAAY,MAAM,aAAa,KAC/B,aAAa,SACb,SAAS,MAAM,OAAO;AAE9B;;;;;;;AAQA,SAAgB,gBAAgB,OAAwC;CACtE,IAAI,CAAC,YAAY,KAAK,GACpB,OAAO;CAGT,MAAM,SAAS;CACf,IAAI,QAAQ,UAAU,CAAC,YAAY,OAAO,EAAE,GAC1C,OAAO;CAET,IAAI,WAAW,UAAU,CAAC,YAAY,OAAO,KAAK,GAChD,OAAO;CAET,IAAI,iBAAiB,UAAU,CAAC,YA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O,OAAO;AAEpC;;;;;;;AAQA,SAAgB,eAEd,OAAkD;CAClD,OACE,SAAoB,KAAK,KAAK,kBAA6B,MAAM,MAAM;AAE3E"}
1
+ {"version":3,"file":"type-checks.mjs","names":[],"sources":["../src/type-checks.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isJsonSchemaObjectType } from \"@stryke/json\";\nimport {\n isFunction,\n isObject,\n isSetObject,\n isSetString\n} from \"@stryke/type-checks\";\nimport {\n InputObject as UntypedInputObject,\n Schema as UntypedSchema\n} from \"untyped\";\nimport { JSON_SCHEMA_DATA_TYPES } from \"./constants\";\nimport { ExtractedSchema, JsonSchema, JsonSchemaObject, Schema } from \"./types\";\n\ntype JsonSchemaDataType = (typeof JSON_SCHEMA_DATA_TYPES)[number];\n\nconst JSON_SCHEMA_DATA_TYPE_SET = new Set<JsonSchemaDataType>(\n JSON_SCHEMA_DATA_TYPES\n);\n\ntype SchemaKeywordValidator = (value: unknown) => boolean;\n\nconst isSetNumber = (value: unknown): value is number =>\n typeof value === \"number\" && Number.isFinite(value);\n\nconst isSetBoolean = (value: unknown): value is boolean =>\n typeof value === \"boolean\";\n\nconst isNonNegativeInteger = (value: unknown): value is number =>\n Number.isInteger(value) && (value as number) >= 0;\n\nconst isSchemaLikeValue = (value: unknown): boolean =>\n isSetObject(value) || isSetBoolean(value);\n\nconst isStringArray = (value: unknown): value is string[] =>\n Array.isArray(value) && value.every(item => isSetString(item));\n\nconst isRecordOfStringArrays = (\n value: unknown\n): value is Record<string, string[]> =>\n isSetObject(value) && Object.values(value).every(item => isStringArray(item));\n\nconst TYPE_KEYWORD_VALIDATORS: Record<\n JsonSchemaDataType,\n Record<string, SchemaKeywordValidator>\n> = {\n string: {\n minLength: isNonNegativeInteger,\n maxLength: isNonNegativeInteger,\n pattern: isSetString,\n format: isSetString,\n contentEncoding: isSetString,\n contentMediaType: isSetString\n },\n number: {\n minimum: isSetNumber,\n maximum: isSetNumber,\n exclusiveMinimum: isSetNumber,\n exclusiveMaximum: isSetNumber,\n multipleOf: isSetNumber\n },\n integer: {\n minimum: isSetNumber,\n maximum: isSetNumber,\n exclusiveMinimum: isSetNumber,\n exclusiveMaximum: isSetNumber,\n multipleOf: isSetNumber\n },\n boolean: {},\n array: {\n items: isSchemaLikeValue,\n prefixItems: Array.isArray,\n contains: isSchemaLikeValue,\n minItems: isNonNegativeInteger,\n maxItems: isNonNegativeInteger,\n uniqueItems: isSetBoolean,\n minContains: isNonNegativeInteger,\n maxContains: isNonNegativeInteger\n },\n object: {\n properties: isSetObject,\n patternProperties: isSetObject,\n additionalProperties: isSchemaLikeValue,\n required: isStringArray,\n minProperties: isNonNegativeInteger,\n maxProperties: isNonNegativeInteger,\n dependentRequired: isRecordOfStringArrays,\n dependentSchemas: isSetObject,\n propertyNames: isSchemaLikeValue,\n unevaluatedProperties: isSchemaLikeValue\n },\n null: {}\n};\n\n/**\n * Type guard for JSON Schema types.\n *\n * @remarks\n * 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.\n *\n * @param input - The value to check.\n * @returns True if the input is a JSON Schema type, false otherwise.\n */\nexport function isJsonSchema<T = unknown>(\n input: unknown\n): input is JsonSchema<T> {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n if (\"$ref\" in schema && isSetString(schema.$ref)) {\n return true;\n }\n\n if (!(\"type\" in schema)) {\n return false;\n }\n\n const schemaTypes: JsonSchemaDataType[] = [];\n\n if (isSetString(schema.type)) {\n if (!JSON_SCHEMA_DATA_TYPE_SET.has(schema.type as JsonSchemaDataType)) {\n return false;\n }\n\n schemaTypes.push(schema.type as JsonSchemaDataType);\n } else if (Array.isArray(schema.type) && schema.type.length > 0) {\n if (\n !schema.type.every(\n schemaType =>\n isSetString(schemaType) &&\n JSON_SCHEMA_DATA_TYPE_SET.has(schemaType as JsonSchemaDataType)\n ) ||\n new Set(schema.type).size !== schema.type.length\n ) {\n return false;\n }\n\n schemaTypes.push(...(schema.type as JsonSchemaDataType[]));\n } else {\n return false;\n }\n\n const typeKeywordValidators = schemaTypes.flatMap(schemaType =>\n Object.entries(TYPE_KEYWORD_VALIDATORS[schemaType])\n );\n\n for (const [keyword, validator] of typeKeywordValidators) {\n if (keyword in schema && !validator(schema[keyword])) {\n return false;\n }\n }\n\n if (\n \"minItems\" in schema &&\n \"maxItems\" in schema &&\n isNonNegativeInteger(schema.minItems) &&\n isNonNegativeInteger(schema.maxItems) &&\n schema.minItems > schema.maxItems\n ) {\n return false;\n }\n\n if (\n \"minLength\" in schema &&\n \"maxLength\" in schema &&\n isNonNegativeInteger(schema.minLength) &&\n isNonNegativeInteger(schema.maxLength) &&\n schema.minLength > schema.maxLength\n ) {\n return false;\n }\n\n if (\n \"minProperties\" in schema &&\n \"maxProperties\" in schema &&\n isNonNegativeInteger(schema.minProperties) &&\n isNonNegativeInteger(schema.maxProperties) &&\n schema.minProperties > schema.maxProperties\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard for JSON Schema object forms.\n *\n * @remarks\n * 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.\n *\n * @param input - The value to check.\n * @returns True if the input is a JSON Schema object type, false otherwise.\n */\nexport function isJsonSchemaObject<\n T extends Record<string, any> = Record<string, any>\n>(input: unknown): input is JsonSchemaObject<T> {\n return (\n isJsonSchemaObjectType(input) &&\n (input.type === \"object\" || isObject(input.properties))\n );\n}\n\n/**\n * Type guard for JSON Schemas that only accept `null`.\n *\n * @remarks\n * 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.\n *\n * @param input - The value to check.\n * @returns True if the input is a JSON Schema that only accepts `null`, false otherwise.\n */\nexport function isNullOnlyJsonSchema(\n input: unknown\n): input is JsonSchema<null> {\n return isJsonSchema(input) && input.type === \"null\";\n}\n\n/**\n * Type guard for untyped schema objects.\n *\n * @remarks\n * 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.\n *\n * @param input - The value to check.\n * @returns True if the input is an untyped schema object, false otherwise.\n */\nexport function isUntypedSchema(input: unknown): input is UntypedSchema {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\"id\" in schema && !isSetString(schema.id)) {\n return false;\n }\n if (\"title\" in schema && !isSetString(schema.title)) {\n return false;\n }\n if (\"description\" in schema && !isSetString(schema.description)) {\n return false;\n }\n if (\"$schema\" in schema && !isSetString(schema.$schema)) {\n return false;\n }\n if (\"tsType\" in schema && !isSetString(schema.tsType)) {\n return false;\n }\n if (\"markdownType\" in schema && !isSetString(schema.markdownType)) {\n return false;\n }\n if (\n \"type\" in schema &&\n !isSetString(schema.type) &&\n !Array.isArray(schema.type)\n ) {\n return false;\n }\n if (\"required\" in schema && !Array.isArray(schema.required)) {\n return false;\n }\n if (\"tags\" in schema && !Array.isArray(schema.tags)) {\n return false;\n }\n if (\"args\" in schema && !Array.isArray(schema.args)) {\n return false;\n }\n if (\"properties\" in schema && !isSetObject(schema.properties)) {\n return false;\n }\n if (\"resolve\" in schema && !isFunction(schema.resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard for untyped input objects.\n *\n * @remarks\n * 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.\n *\n * @param input - The value to check.\n * @returns True if the input is an untyped input object, false otherwise.\n */\nexport function isUntypedInput(input: unknown): input is UntypedInputObject {\n if (!isSetObject(input)) {\n return false;\n }\n\n const inputObject = input as Record<string, unknown>;\n if (\"$schema\" in inputObject && !isUntypedSchema(inputObject.$schema)) {\n return false;\n }\n if (\"$resolve\" in inputObject && !isFunction(inputObject.$resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard for Powerlines Schema objects.\n *\n * @param input - The value to check.\n * @returns True if the input is a Powerlines Schema object, false otherwise.\n */\nexport function isSchema<T = unknown>(input: unknown): input is Schema<T> {\n return (\n isSetObject(input) &&\n \"schema\" in input &&\n isJsonSchema(input.schema) &&\n \"variant\" in input &&\n isSetString(input.variant) &&\n \"hash\" in input &&\n isSetString(input.hash)\n );\n}\n\nexport function isExtractedSchema<T = unknown>(\n input: unknown\n): input is ExtractedSchema<T> {\n return (\n isSchema<T>(input) &&\n \"source\" in input &&\n isSetObject(input.source) &&\n \"schema\" in input.source &&\n \"variant\" in input.source &&\n isSetString(input.source.variant)\n );\n}\n"],"mappings":";;;;;AAkCA,MAAM,4BAA4B,IAAI,IACpC,sBACF;AAIA,MAAM,eAAe,UACnB,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK;AAEpD,MAAM,gBAAgB,UACpB,OAAO,UAAU;AAEnB,MAAM,wBAAwB,UAC5B,OAAO,UAAU,KAAK,KAAM,SAAoB;AAElD,MAAM,qBAAqB,UACzB,YAAY,KAAK,KAAK,aAAa,KAAK;AAE1C,MA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