@power-plant/schema 0.0.4 → 0.0.5

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 (76) hide show
  1. package/dist/codegen.cjs +6 -6
  2. package/dist/codegen.d.cts +1 -1
  3. package/dist/codegen.d.mts +1 -1
  4. package/dist/codegen.mjs +3 -3
  5. package/dist/constants-CwyhgVEl.cjs +1 -0
  6. package/dist/{constants.mjs → constants-lk1mMbgx.mjs} +2 -2
  7. package/dist/constants-lk1mMbgx.mjs.map +1 -0
  8. package/dist/helpers-B5sr5S3X.cjs +1 -0
  9. package/dist/helpers-Bh_V7xwV.mjs +2 -0
  10. package/dist/helpers-Bh_V7xwV.mjs.map +1 -0
  11. package/dist/index.cjs +1 -1
  12. package/dist/index.d.cts +616 -31
  13. package/dist/index.d.cts.map +1 -1
  14. package/dist/index.d.mts +616 -31
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +2 -1
  17. package/dist/index.mjs.map +1 -0
  18. package/dist/{types.d.cts → types-BawP3FVI.d.mts} +72 -18
  19. package/dist/types-BawP3FVI.d.mts.map +1 -0
  20. package/dist/{types.d.mts → types-BmNamqlM.d.cts} +71 -17
  21. package/dist/types-BmNamqlM.d.cts.map +1 -0
  22. package/dist/valibot.cjs +1 -0
  23. package/dist/valibot.d.cts +14 -0
  24. package/dist/valibot.d.cts.map +1 -0
  25. package/dist/valibot.d.mts +14 -0
  26. package/dist/valibot.d.mts.map +1 -0
  27. package/dist/valibot.mjs +2 -0
  28. package/dist/valibot.mjs.map +1 -0
  29. package/dist/zod.cjs +1 -0
  30. package/dist/zod.d.cts +14 -0
  31. package/dist/zod.d.cts.map +1 -0
  32. package/dist/zod.d.mts +14 -0
  33. package/dist/zod.d.mts.map +1 -0
  34. package/dist/zod.mjs +2 -0
  35. package/dist/zod.mjs.map +1 -0
  36. package/package.json +26 -91
  37. package/dist/constants-lihlIQu7.d.cts +0 -31
  38. package/dist/constants-lihlIQu7.d.cts.map +0 -1
  39. package/dist/constants-lihlIQu7.d.mts +0 -31
  40. package/dist/constants-lihlIQu7.d.mts.map +0 -1
  41. package/dist/constants.cjs +0 -1
  42. package/dist/constants.d.cts +0 -2
  43. package/dist/constants.d.mts +0 -2
  44. package/dist/constants.mjs.map +0 -1
  45. package/dist/extract.cjs +0 -1
  46. package/dist/extract.d.cts +0 -135
  47. package/dist/extract.d.cts.map +0 -1
  48. package/dist/extract.d.mts +0 -135
  49. package/dist/extract.d.mts.map +0 -1
  50. package/dist/extract.mjs +0 -2
  51. package/dist/extract.mjs.map +0 -1
  52. package/dist/helpers.cjs +0 -1
  53. package/dist/helpers.d.cts +0 -134
  54. package/dist/helpers.d.cts.map +0 -1
  55. package/dist/helpers.d.mts +0 -134
  56. package/dist/helpers.d.mts.map +0 -1
  57. package/dist/helpers.mjs +0 -2
  58. package/dist/helpers.mjs.map +0 -1
  59. package/dist/metadata.cjs +0 -1
  60. package/dist/metadata.d.cts +0 -31
  61. package/dist/metadata.d.cts.map +0 -1
  62. package/dist/metadata.d.mts +0 -31
  63. package/dist/metadata.d.mts.map +0 -1
  64. package/dist/metadata.mjs +0 -2
  65. package/dist/metadata.mjs.map +0 -1
  66. package/dist/type-checks.cjs +0 -1
  67. package/dist/type-checks.d.cts +0 -331
  68. package/dist/type-checks.d.cts.map +0 -1
  69. package/dist/type-checks.d.mts +0 -331
  70. package/dist/type-checks.d.mts.map +0 -1
  71. package/dist/type-checks.mjs +0 -2
  72. package/dist/type-checks.mjs.map +0 -1
  73. package/dist/types.cjs +0 -0
  74. package/dist/types.d.cts.map +0 -1
  75. package/dist/types.d.mts.map +0 -1
  76. package/dist/types.mjs +0 -1
@@ -1,134 +0,0 @@
1
- import { JsonSchema, JsonSchemaMetadataKeywords, JsonSchemaObject, JsonSchemaOf, SchemaEnvelope } from "./types.cjs";
2
-
3
- //#region src/helpers.d.ts
4
- type GetPropertyResult = JsonSchema & {
5
- name: string;
6
- required: boolean;
7
- default?: unknown;
8
- };
9
- /**
10
- * Retrieves the JSON Schema from a Schema wrapper or returns the input if it's already a JSON Schema.
11
- *
12
- * @remarks
13
- * This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.
14
- *
15
- * @param input - The input which can be either a Schema wrapper or a JSON Schema object.
16
- * @returns The JSON Schema object.
17
- * @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.
18
- */
19
- declare function getJsonSchema(input: SchemaEnvelope | JsonSchema): JsonSchema;
20
- /**
21
- * Retrieves the JSON Schema in Object form from a Schema wrapper or returns the input if it's already a JSON Schema.
22
- *
23
- * @remarks
24
- * This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema object, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.
25
- *
26
- * @param input - The input which can be either a Schema wrapper or a JSON Schema object.
27
- * @returns The JSON Schema object.
28
- * @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.
29
- */
30
- declare function getJsonSchemaObject(input: SchemaEnvelope | JsonSchema): JsonSchemaObject;
31
- /**
32
- * Extracts object properties from a JSON Schema object form.
33
- *
34
- * @remarks
35
- * This function returns an empty object if the schema is not an object form or if it has no properties.
36
- *
37
- * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.
38
- * @returns An object mapping property names to their corresponding JSON Schema fragments, including metadata.
39
- */
40
- declare function getProperties(obj: SchemaEnvelope | JsonSchemaObject): Record<string, GetPropertyResult>;
41
- /**
42
- * Returns object properties as an array.
43
- *
44
- * @remarks
45
- * This is a convenience function that extracts properties using `getProperties` and returns them as an array.
46
- *
47
- * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.
48
- * @returns An array of JSON Schema fragments representing the properties, each including metadata.
49
- */
50
- declare function getPropertiesList(obj: SchemaEnvelope | JsonSchemaObject): GetPropertyResult[];
51
- /**
52
- * Extracts object properties from a JSON Schema object form.
53
- *
54
- * @remarks
55
- * This function returns an empty object if the schema is not an object form or if it has no properties.
56
- *
57
- * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.
58
- * @returns An object mapping property names to their corresponding JSON Schema fragments, including metadata.
59
- */
60
- declare function getProperty<TSchema extends JsonSchemaObject>(obj: SchemaEnvelope<TSchema> | TSchema, name: keyof TSchema["properties"] & string): GetPropertyResult;
61
- /**
62
- * Adds a property to a JSON Schema object form.
63
- *
64
- * @remarks
65
- * This function modifies the provided schema in place by adding a new property with the specified name and schema. It also updates the `required` array based on the `optional` flag of the property. If the property is marked as optional, it will be removed from the `required` array; otherwise, it will be added to it.
66
- *
67
- * @param obj - The JSON Schema object form or a Schema wrapper to which the property should be added.
68
- * @param name - The name of the property to add.
69
- * @param property - The JSON Schema fragment representing the property's schema, including metadata.
70
- * @throws Will throw an error if the provided schema is not an object form.
71
- */
72
- declare function addProperty(obj: SchemaEnvelope | JsonSchemaObject, name: string, property: JsonSchema): void;
73
- /**
74
- * Merges multiple JSON Schemas into one.
75
- *
76
- * @remarks
77
- * This function takes multiple JSON Schemas or Schema wrappers and merges them
78
- * into a single JSON Schema object. Later schemas in the argument list take
79
- * precedence over earlier ones for scalar conflicts.
80
- *
81
- * Structured keywords are merged recursively:
82
- * - Named child schemas (`properties`, `$defs`, etc.) are merged
83
- * per-property via recursive calls to `merge`.
84
- * - Composition arrays (`allOf`, `anyOf`, `oneOf`) are concatenated.
85
- * - Single-schema keywords (`if`, `then`, `else`, `not`, `items`, etc.)
86
- * are merged recursively when both sides define them.
87
- * - `required` arrays are union'ed and deduplicated.
88
- *
89
- * @param schemas - An array of JSON Schemas or Schema wrappers to merge.
90
- * @returns A new JSON Schema that is the result of merging all input schemas.
91
- */
92
- declare function merge(...schemas: (JsonSchema | SchemaEnvelope)[]): JsonSchema;
93
- /**
94
- * Merges metadata into a JSON Schema fragment.
95
- *
96
- * @remarks
97
- * This function takes a JSON Schema fragment and a metadata object, and merges the metadata into the schema. Only the keys defined in {@link JSON_SCHEMA_METADATA_KEYS} are considered for merging. The resulting schema will include the original schema properties along with the provided metadata.
98
- *
99
- * @param schema - The JSON Schema fragment to merge metadata into.
100
- * @param metadata - The metadata to merge into the schema.
101
- * @returns A new JSON Schema fragment that includes the merged metadata.
102
- */
103
- declare function mergeMetadata<TSpec>(schema: JsonSchemaOf<TSpec>, metadata: JsonSchemaMetadataKeywords): JsonSchemaOf<TSpec>;
104
- /**
105
- * Returns whether a JSON Schema fragment accepts `null`.
106
- *
107
- * @remarks
108
- * This is true if the schema has `nullable: true` or if its `type` includes `"null"`.
109
- *
110
- * @param schema - The JSON Schema fragment to check.
111
- * @returns `true` if the schema accepts `null`, otherwise `false`.
112
- */
113
- declare function isSchemaNullable(schema?: JsonSchema): boolean;
114
- /**
115
- * Returns whether an object property is optional (not listed in `required`).
116
- *
117
- * @remarks
118
- * In JSON Schema, object properties are optional by default unless they are listed in the `required` array of the parent schema. This function checks whether a given property name is not included in the `required` array of its parent schema, indicating that it is optional.
119
- *
120
- * @param parent - The parent JSON Schema object containing the property.
121
- * @param propertyName - The name of the property to check for optionality.
122
- * @returns `true` if the property is optional, otherwise `false`.
123
- */
124
- declare function isPropertyOptional(parent: JsonSchemaObject, propertyName: string): boolean;
125
- /**
126
- * Checks if a given file name has a valid schema input file extension.
127
- *
128
- * @param fileName - The file name to check for a valid schema input extension.
129
- * @returns `true` if the file name has a valid schema input extension, otherwise `false`.
130
- */
131
- declare function isValidSchemaInputFile(fileName: string): boolean;
132
- //#endregion
133
- export { GetPropertyResult, addProperty, getJsonSchema, getJsonSchemaObject, getProperties, getPropertiesList, getProperty, isPropertyOptional, isSchemaNullable, isValidSchemaInputFile, merge, mergeMetadata };
134
- //# sourceMappingURL=helpers.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.d.cts","names":[],"sources":["../src/helpers.ts"],"mappings":";;;KAwCY,iBAAA,GAAoB,UAAU;EACxC,IAAA;EACA,QAAA;EACA,OAAA;AAAA;;;;;;;AAAO;AAaT;;;iBAAgB,aAAA,CAAc,KAAA,EAAO,cAAA,GAAiB,UAAA,GAAa,UAAA;;;;;;;;;;AAAU;iBAmB7D,mBAAA,CACd,KAAA,EAAO,cAAA,GAAiB,UAAA,GACvB,gBAAA;;;;;;;;;;iBAkBa,aAAA,CACd,GAAA,EAAK,cAAA,GAAiB,gBAAA,GACrB,MAAA,SAAe,iBAAA;;;AApBC;AAkBnB;;;;;;iBA+BgB,iBAAA,CAAkB,GAAA,EAAK,cAAA,GAAiB,gBAAA,GAAgB,iBAAA;;;;;;;;;AA7BrC;iBA0CnB,WAAA,iBAA4B,gBAAA,EAC1C,GAAA,EAAK,cAAA,CAAe,OAAA,IAAW,OAAA,EAC/B,IAAA,QAAY,OAAA,0BACX,iBAAA;;;;;;;;;;;;iBAgCa,WAAA,CACd,GAAA,EAAK,cAAA,GAAiB,gBAAA,EACtB,IAAA,UACA,QAAA,EAAU,UAAA;AAnD4D;AAaxE;;;;;;;;;;;;;;;;;;AAbwE,iBA4JxD,KAAA,IAAS,OAAA,GAAU,UAAA,GAAa,cAAA,MAAoB,UAAA;;;AA5IhD;AAgCpB;;;;;;;iBAyIgB,aAAA,QACd,MAAA,EAAQ,YAAA,CAAa,KAAA,GACrB,QAAA,EAAU,0BAAA,GACT,YAAA,CAAa,KAAA;;;;;;;;AAzIM;AAyGtB;iBAoDgB,gBAAA,CAAiB,MAAmB,GAAV,UAAU;;;;;;;;;;;iBAsBpC,kBAAA,CACd,MAAA,EAAQ,gBAAgB,EACxB,YAAA;AA5E4E;AA6B9E;;;;;AA7B8E,iBA6F9D,sBAAA,CAAuB,QAAgB"}
@@ -1,134 +0,0 @@
1
- import { JsonSchema, JsonSchemaMetadataKeywords, JsonSchemaObject, JsonSchemaOf, SchemaEnvelope } from "./types.mjs";
2
-
3
- //#region src/helpers.d.ts
4
- type GetPropertyResult = JsonSchema & {
5
- name: string;
6
- required: boolean;
7
- default?: unknown;
8
- };
9
- /**
10
- * Retrieves the JSON Schema from a Schema wrapper or returns the input if it's already a JSON Schema.
11
- *
12
- * @remarks
13
- * This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.
14
- *
15
- * @param input - The input which can be either a Schema wrapper or a JSON Schema object.
16
- * @returns The JSON Schema object.
17
- * @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.
18
- */
19
- declare function getJsonSchema(input: SchemaEnvelope | JsonSchema): JsonSchema;
20
- /**
21
- * Retrieves the JSON Schema in Object form from a Schema wrapper or returns the input if it's already a JSON Schema.
22
- *
23
- * @remarks
24
- * This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema object, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.
25
- *
26
- * @param input - The input which can be either a Schema wrapper or a JSON Schema object.
27
- * @returns The JSON Schema object.
28
- * @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.
29
- */
30
- declare function getJsonSchemaObject(input: SchemaEnvelope | JsonSchema): JsonSchemaObject;
31
- /**
32
- * Extracts object properties from a JSON Schema object form.
33
- *
34
- * @remarks
35
- * This function returns an empty object if the schema is not an object form or if it has no properties.
36
- *
37
- * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.
38
- * @returns An object mapping property names to their corresponding JSON Schema fragments, including metadata.
39
- */
40
- declare function getProperties(obj: SchemaEnvelope | JsonSchemaObject): Record<string, GetPropertyResult>;
41
- /**
42
- * Returns object properties as an array.
43
- *
44
- * @remarks
45
- * This is a convenience function that extracts properties using `getProperties` and returns them as an array.
46
- *
47
- * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.
48
- * @returns An array of JSON Schema fragments representing the properties, each including metadata.
49
- */
50
- declare function getPropertiesList(obj: SchemaEnvelope | JsonSchemaObject): GetPropertyResult[];
51
- /**
52
- * Extracts object properties from a JSON Schema object form.
53
- *
54
- * @remarks
55
- * This function returns an empty object if the schema is not an object form or if it has no properties.
56
- *
57
- * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.
58
- * @returns An object mapping property names to their corresponding JSON Schema fragments, including metadata.
59
- */
60
- declare function getProperty<TSchema extends JsonSchemaObject>(obj: SchemaEnvelope<TSchema> | TSchema, name: keyof TSchema["properties"] & string): GetPropertyResult;
61
- /**
62
- * Adds a property to a JSON Schema object form.
63
- *
64
- * @remarks
65
- * This function modifies the provided schema in place by adding a new property with the specified name and schema. It also updates the `required` array based on the `optional` flag of the property. If the property is marked as optional, it will be removed from the `required` array; otherwise, it will be added to it.
66
- *
67
- * @param obj - The JSON Schema object form or a Schema wrapper to which the property should be added.
68
- * @param name - The name of the property to add.
69
- * @param property - The JSON Schema fragment representing the property's schema, including metadata.
70
- * @throws Will throw an error if the provided schema is not an object form.
71
- */
72
- declare function addProperty(obj: SchemaEnvelope | JsonSchemaObject, name: string, property: JsonSchema): void;
73
- /**
74
- * Merges multiple JSON Schemas into one.
75
- *
76
- * @remarks
77
- * This function takes multiple JSON Schemas or Schema wrappers and merges them
78
- * into a single JSON Schema object. Later schemas in the argument list take
79
- * precedence over earlier ones for scalar conflicts.
80
- *
81
- * Structured keywords are merged recursively:
82
- * - Named child schemas (`properties`, `$defs`, etc.) are merged
83
- * per-property via recursive calls to `merge`.
84
- * - Composition arrays (`allOf`, `anyOf`, `oneOf`) are concatenated.
85
- * - Single-schema keywords (`if`, `then`, `else`, `not`, `items`, etc.)
86
- * are merged recursively when both sides define them.
87
- * - `required` arrays are union'ed and deduplicated.
88
- *
89
- * @param schemas - An array of JSON Schemas or Schema wrappers to merge.
90
- * @returns A new JSON Schema that is the result of merging all input schemas.
91
- */
92
- declare function merge(...schemas: (JsonSchema | SchemaEnvelope)[]): JsonSchema;
93
- /**
94
- * Merges metadata into a JSON Schema fragment.
95
- *
96
- * @remarks
97
- * This function takes a JSON Schema fragment and a metadata object, and merges the metadata into the schema. Only the keys defined in {@link JSON_SCHEMA_METADATA_KEYS} are considered for merging. The resulting schema will include the original schema properties along with the provided metadata.
98
- *
99
- * @param schema - The JSON Schema fragment to merge metadata into.
100
- * @param metadata - The metadata to merge into the schema.
101
- * @returns A new JSON Schema fragment that includes the merged metadata.
102
- */
103
- declare function mergeMetadata<TSpec>(schema: JsonSchemaOf<TSpec>, metadata: JsonSchemaMetadataKeywords): JsonSchemaOf<TSpec>;
104
- /**
105
- * Returns whether a JSON Schema fragment accepts `null`.
106
- *
107
- * @remarks
108
- * This is true if the schema has `nullable: true` or if its `type` includes `"null"`.
109
- *
110
- * @param schema - The JSON Schema fragment to check.
111
- * @returns `true` if the schema accepts `null`, otherwise `false`.
112
- */
113
- declare function isSchemaNullable(schema?: JsonSchema): boolean;
114
- /**
115
- * Returns whether an object property is optional (not listed in `required`).
116
- *
117
- * @remarks
118
- * In JSON Schema, object properties are optional by default unless they are listed in the `required` array of the parent schema. This function checks whether a given property name is not included in the `required` array of its parent schema, indicating that it is optional.
119
- *
120
- * @param parent - The parent JSON Schema object containing the property.
121
- * @param propertyName - The name of the property to check for optionality.
122
- * @returns `true` if the property is optional, otherwise `false`.
123
- */
124
- declare function isPropertyOptional(parent: JsonSchemaObject, propertyName: string): boolean;
125
- /**
126
- * Checks if a given file name has a valid schema input file extension.
127
- *
128
- * @param fileName - The file name to check for a valid schema input extension.
129
- * @returns `true` if the file name has a valid schema input extension, otherwise `false`.
130
- */
131
- declare function isValidSchemaInputFile(fileName: string): boolean;
132
- //#endregion
133
- export { GetPropertyResult, addProperty, getJsonSchema, getJsonSchemaObject, getProperties, getPropertiesList, getProperty, isPropertyOptional, isSchemaNullable, isValidSchemaInputFile, merge, mergeMetadata };
134
- //# sourceMappingURL=helpers.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.d.mts","names":[],"sources":["../src/helpers.ts"],"mappings":""}
package/dist/helpers.mjs DELETED
@@ -1,2 +0,0 @@
1
- import{JSON_SCHEMA_METADATA_KEYS as e,SCHEMA_ARRAY_CONCAT_KEYWORDS as t,SCHEMA_RECORD_KEYWORDS as n,SCHEMA_SINGLE_KEYWORDS as r}from"./constants.mjs";import{isJsonSchema as i,isJsonSchemaObject as a,isSchema as o}from"./type-checks.mjs";import{readSchemaTypes as s}from"./metadata.mjs";import{isSetObject as c}from"@stryke/type-checks";import{getUnique as l}from"@stryke/helpers/get-unique";import{findFileExtensionSafe as u}from"@stryke/path/find";import{VALID_OBJECT_SOURCE_EXTENSIONS as d}from"@stryke/resolve/constants";import f from"defu";function p(e){let t=o(e)?e.schema:e;if(!i(t))throw TypeError(`The provided input is not a valid JSON Schema`);return t}function m(e){let t=p(e);if(!a(t))throw TypeError(`The provided input is not a valid JSON Schema object`);return t}function h(e){let t=m(e);return c(t.properties)?Object.entries(t.properties).reduce((e,[n,r])=>(r.name=n,r.required=!C(t,n),r.default=t.default?.[n]??r.default,e[n]=r,e),{}):{}}function g(e){return Object.values(h(e))}function _(e,t){let n=m(e);if(!c(n.properties))throw TypeError(`The provided schema does not have any properties`);let r=n.properties[t];if(!r)throw TypeError(`The provided schema does not have a property named "${t}"`);return{...r,name:t,required:!C(n,t),default:n.default?.[t]??r?.default}}function v(e,t,n){let r=m(e);r.properties??={},r.required??=[],n.name=t,r.properties[t]=n,r.required.includes(t)||r.required.push(t),r.required.length===0&&delete r.required}function y(e,a){let o={...e};for(let[e,s]of Object.entries(a)){let a=o[e];if(e===`required`)o[e]=l([...Array.isArray(a)?a:[],...Array.isArray(s)?s:[]]);else if(n.has(e)&&c(a)&&c(s)){let t={...a};for(let[e,n]of Object.entries(s)){let r=t[e];t[e]=i(r)&&i(n)?y(r,n):n}o[e]=t}else t.has(e)&&Array.isArray(a)&&Array.isArray(s)?o[e]=[...a,...s]:r.has(e)&&i(a)&&i(s)?o[e]=y(a,s):o[e]=s}return o}function b(...e){let t=e.map(e=>p(e));return t.length===0?{}:t.reduce((e,t)=>{let n=e.type,r=t.type;return n&&r&&n!==r?t:y(e,t)})}function x(t,n){return f(t,Object.fromEntries(e.filter(e=>n[e]!==void 0).map(e=>[e,n[e]])))}function S(e){return c(e)?e.nullable===!0?!0:s(e).includes(`null`):!1}function C(e,t){if(!e.properties?.[t])throw Error(`The property "${t}" does not exist in the parent schema.`);return!(e.required??[]).includes(t)}function w(e){return d.includes(u(e))}export{v as addProperty,p as getJsonSchema,m as getJsonSchemaObject,h as getProperties,g as getPropertiesList,_ as getProperty,C as isPropertyOptional,S as isSchemaNullable,w as isValidSchemaInputFile,b as merge,x as mergeMetadata};
2
- //# sourceMappingURL=helpers.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.mjs","names":[],"sources":[],"mappings":""}
package/dist/metadata.cjs DELETED
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./constants.cjs");let t=require("@stryke/type-checks/is-set-object"),n=require("@stryke/type-checks/is-set-string");function r(n,r){if(!r||!(0,t.isSetObject)(n))return n;let i={...n},a=i;for(let t of e.JSON_SCHEMA_METADATA_KEYS){let e=r[t];e!=null&&(a[t]=e)}return i}function i(e){if(!(0,t.isSetObject)(e))return[];let r=e;return Array.isArray(r.type)?r.type.filter(e=>(0,n.isSetString)(e)):(0,n.isSetString)(r.type)&&r.type!==`object`&&r.type!==`array`?[r.type]:[]}function a(e){if((0,t.isSetObject)(e))return i(e).find(e=>e!==`null`)}exports.applyJsonSchemaMetadata=r,exports.getPrimarySchemaType=a,exports.readSchemaTypes=i;
@@ -1,31 +0,0 @@
1
- import { JsonSchema, JsonSchemaMetadataKeywords, JsonSchemaPrimitiveType } from "./types.cjs";
2
-
3
- //#region src/metadata.d.ts
4
- /**
5
- * Applies Powerlines schema metadata onto a JSON Schema fragment.
6
- *
7
- * @param schema - The JSON Schema fragment to apply metadata to.
8
- * @param metadata - The Powerlines schema metadata to apply.
9
- * @returns A new JSON Schema fragment with the metadata applied.
10
- */
11
- declare function applyJsonSchemaMetadata(schema: JsonSchema, metadata: JsonSchemaMetadataKeywords | undefined): JsonSchema;
12
- /**
13
- * Normalizes the JSON Schema `type` keyword to a string array.
14
- *
15
- * @remarks
16
- * This function ensures that the `type` keyword of a JSON Schema fragment is always represented as an array of strings, even if it was originally defined as a single string. This normalization simplifies type checking and processing of JSON Schemas by providing a consistent format for the `type` information.
17
- *
18
- * @param schema - The JSON Schema fragment to read types from.
19
- * @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.
20
- */
21
- declare function readSchemaTypes(schema?: JsonSchema): JsonSchemaPrimitiveType[];
22
- /**
23
- * Returns the primary non-null JSON Schema type name for a fragment.
24
- *
25
- * @param schema - The JSON Schema fragment to check.
26
- * @returns The primary non-null JSON Schema type name, or `undefined` if none is found.
27
- */
28
- declare function getPrimarySchemaType(schema?: JsonSchema): JsonSchemaPrimitiveType | undefined;
29
- //#endregion
30
- export { applyJsonSchemaMetadata, getPrimarySchemaType, readSchemaTypes };
31
- //# sourceMappingURL=metadata.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"metadata.d.cts","names":[],"sources":["../src/metadata.ts"],"mappings":";;;;;AAuCA;;;;;iBAAgB,uBAAA,CACd,MAAA,EAAQ,UAAA,EACR,QAAA,EAAU,0BAAA,eACT,UAAA;;;;;;;;;AAAU;iBA0BG,eAAA,CACd,MAAA,GAAS,UAAA,GACR,uBAAuB;;;;;;;iBA6BV,oBAAA,CACd,MAAA,GAAS,UAAA,GACR,uBAAuB"}
@@ -1,31 +0,0 @@
1
- import { JsonSchema, JsonSchemaMetadataKeywords, JsonSchemaPrimitiveType } from "./types.mjs";
2
-
3
- //#region src/metadata.d.ts
4
- /**
5
- * Applies Powerlines schema metadata onto a JSON Schema fragment.
6
- *
7
- * @param schema - The JSON Schema fragment to apply metadata to.
8
- * @param metadata - The Powerlines schema metadata to apply.
9
- * @returns A new JSON Schema fragment with the metadata applied.
10
- */
11
- declare function applyJsonSchemaMetadata(schema: JsonSchema, metadata: JsonSchemaMetadataKeywords | undefined): JsonSchema;
12
- /**
13
- * Normalizes the JSON Schema `type` keyword to a string array.
14
- *
15
- * @remarks
16
- * This function ensures that the `type` keyword of a JSON Schema fragment is always represented as an array of strings, even if it was originally defined as a single string. This normalization simplifies type checking and processing of JSON Schemas by providing a consistent format for the `type` information.
17
- *
18
- * @param schema - The JSON Schema fragment to read types from.
19
- * @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.
20
- */
21
- declare function readSchemaTypes(schema?: JsonSchema): JsonSchemaPrimitiveType[];
22
- /**
23
- * Returns the primary non-null JSON Schema type name for a fragment.
24
- *
25
- * @param schema - The JSON Schema fragment to check.
26
- * @returns The primary non-null JSON Schema type name, or `undefined` if none is found.
27
- */
28
- declare function getPrimarySchemaType(schema?: JsonSchema): JsonSchemaPrimitiveType | undefined;
29
- //#endregion
30
- export { applyJsonSchemaMetadata, getPrimarySchemaType, readSchemaTypes };
31
- //# sourceMappingURL=metadata.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"metadata.d.mts","names":[],"sources":["../src/metadata.ts"],"mappings":""}
package/dist/metadata.mjs DELETED
@@ -1,2 +0,0 @@
1
- import{JSON_SCHEMA_METADATA_KEYS as e}from"./constants.mjs";import{isSetObject as t}from"@stryke/type-checks/is-set-object";import{isSetString as n}from"@stryke/type-checks/is-set-string";function r(n,r){if(!r||!t(n))return n;let i={...n},a=i;for(let t of e){let e=r[t];e!=null&&(a[t]=e)}return i}function i(e){if(!t(e))return[];let r=e;return Array.isArray(r.type)?r.type.filter(e=>n(e)):n(r.type)&&r.type!==`object`&&r.type!==`array`?[r.type]:[]}function a(e){if(t(e))return i(e).find(e=>e!==`null`)}export{r as applyJsonSchemaMetadata,a as getPrimarySchemaType,i as readSchemaTypes};
2
- //# sourceMappingURL=metadata.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"metadata.mjs","names":[],"sources":[],"mappings":""}
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./constants.cjs");let t=require("@stryke/type-checks");function n(e){return!(0,t.isString)(e)&&e.file!==void 0}const r=e=>typeof e==`number`&&Number.isFinite(e),i=e=>(0,t.isSetObject)(e)||(0,t.isBoolean)(e),a=e=>(0,t.isSetObject)(e)&&Object.values(e).every(e=>i(e)),o=e=>(0,t.isSetObject)(e)&&Object.values(e).every(e=>(0,t.isBoolean)(e)),s=e=>Array.isArray(e)&&e.every(e=>(0,t.isSetString)(e)),ee=e=>(0,t.isSetObject)(e)&&Object.values(e).every(e=>s(e)),c=new Set(e.JSON_SCHEMA_PRIMITIVE_TYPES),l=new Set(e.JSON_SCHEMA_TYPES);function te(e){return(0,t.isSetString)(e)&&c.has(e)}function u(e){return(0,t.isSetString)(e)&&l.has(e)}const ne=new Set([`date`,`time`,`date-time`,`iso-time`,`iso-date-time`,`unix-time`]),d=e=>typeof e==`bigint`,re=new Set([`string`,`number`,`bigint`,`boolean`,`symbol`,`function`,`object`,`any`,`array`]),f=e=>(0,t.isSetString)(e)&&re.has(e),p=e=>{if(!(0,t.isSetObject)(e))return!1;let n=e;return!(n.type!==void 0&&!((0,t.isSetString)(n.type)&&f(n.type)||Array.isArray(n.type)&&n.type.every(e=>f(e)))||n.tsType!==void 0&&!(0,t.isSetString)(n.tsType)||n.markdownType!==void 0&&!(0,t.isSetString)(n.markdownType)||n.items!==void 0&&!(p(n.items)||Array.isArray(n.items)&&n.items.every(e=>p(e))))},ie=e=>{if(!p(e))return!1;let n=e;return n.name!==void 0&&!(0,t.isSetString)(n.name)?!1:n.optional===void 0||typeof n.optional==`boolean`},ae=e=>(0,t.isSetObject)(e)&&Object.values(e).every(e=>Z(e)),m=(e,t)=>Array.isArray(e)&&e.every(e=>t(e)),oe=(e,t,n)=>Array.isArray(e)&&e.length===2&&t(e[0])&&n(e[1]),h=(e,n=!1)=>e===void 0||(0,t.isString)(e)&&(n||e.length>0),g=e=>e===void 0||(0,t.isBoolean)(e),_=e=>e===void 0||r(e),v=e=>e===void 0||d(e),y=e=>e===void 0||X(e),b=e=>e===void 0||m(e,X),se=e=>e===void 0||Array.isArray(e)&&e.every(e=>(0,t.isSetString)(e)&&c.has(e)),ce=e=>e===void 0||Array.isArray(e)&&e.every(e=>(0,t.isSetString)(e)&&l.has(e)),x=e=>!(!h(e.$id)||!h(e.$schema)||e.$vocabulary!==void 0&&!o(e.$vocabulary)||!h(e.$comment,!0)||!h(e.$anchor)||e.$defs!==void 0&&!a(e.$defs)||!h(e.$dynamicRef)||!h(e.$dynamicAnchor)||!h(e.name)||!h(e.title,!0)||!h(e.description,!0)||!h(e.docs,!0)||e.examples!==void 0&&!Array.isArray(e.examples)||e.alias!==void 0&&!s(e.alias)||e.tags!==void 0&&!s(e.tags)||!g(e.deprecated)||!g(e.hidden)||!g(e.ignore)||!g(e.internal)||!g(e.runtime)||!g(e.readOnly)||!g(e.writeOnly)||!b(e.allOf)||!b(e.anyOf)||!b(e.oneOf)||!y(e.not)||!y(e.if)||!y(e.then)||!y(e.else));function le(e){return(0,t.isSetObject)(e)?x(e):!1}function S(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)&&h(n.$ref)}function C(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return!x(n)||n.type!==`array`?!1:b(n.prefixItems)&&y(n.items)&&y(n.contains)&&_(n.minItems)&&_(n.maxItems)&&g(n.uniqueItems)&&_(n.minContains)&&_(n.maxContains)&&(n.unevaluatedItems===void 0||(0,t.isBoolean)(n.unevaluatedItems)||X(n.unevaluatedItems))}function w(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return!x(n)||n.type!==`integer`||n.format!==`int64`?!1:v(n.minimum)&&v(n.exclusiveMinimum)&&v(n.maximum)&&v(n.exclusiveMaximum)&&v(n.multipleOf)&&v(n.default)&&(n.enum===void 0||m(n.enum,d))}function T(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)&&n.type===`boolean`&&g(n.default)}function E(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)?n.anyOf===void 0?n.type!==`integer`&&n.type!==`string`||!(0,t.isSetString)(n.format)||!ne.has(n.format)?!1:_(n.minimum)&&_(n.maximum)&&(n.default===void 0||(0,t.isSetString)(n.default)||r(n.default)):m(n.anyOf,E):!1}function D(e){if(!(0,t.isSetObject)(e))return!1;let n=e;if(!x(n)||!(0,t.isSetString)(n.type)||!c.has(n.type)||!Array.isArray(n.enum))return!1;let i=n.type,a=n.enum,o=n.default;return i===`string`?a.every(e=>(0,t.isSetString)(e))&&(o===void 0||(0,t.isSetString)(o)):i===`number`||i===`integer`?a.every(e=>r(e))&&(o===void 0||r(o)):i===`boolean`?a.every(e=>(0,t.isBoolean)(e))&&(o===void 0||(0,t.isBoolean)(o)):i===`null`&&a.every(e=>e===null)&&o==null}function O(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return!x(n)||!m(n.allOf,X)?!1:n.unevaluatedProperties===void 0||(0,t.isBoolean)(n.unevaluatedProperties)||X(n.unevaluatedProperties)}function k(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return!x(n)||!(`const`in n)?!1:n.type===void 0||(0,t.isSetString)(n.type)&&u(n.type)||ce(n.type)}function A(e){if(!(0,t.isSetObject)(e))return!1;let n=e;if(!x(n)||n.type!==`array`||n.maxItems!==125||!(0,t.isSetObject)(n.items))return!1;let r=n.items;return r.type===`array`&&oe(r.prefixItems,X,X)&&(r.items===void 0||r.items===!1)&&r.minItems===2&&r.maxItems===2}function j(e){if(!(0,t.isSetObject)(e))return!1;let n=e,i=n.type===`string`||n.type===`number`||Array.isArray(n.type)&&n.type.length===2&&n.type[0]===`string`&&n.type[1]===`number`;return x(n)&&i&&Array.isArray(n.enum)&&n.enum.every(e=>(0,t.isSetString)(e)||r(e))}function M(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)&&S(n.not)}function N(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)&&n.type===`null`&&(n.const===void 0||n.const===null)&&(n.enum===void 0||Array.isArray(n.enum)&&n.enum.every(e=>e===null))&&(n.default===void 0||n.default===null)}function P(e){if(!(0,t.isSetObject)(e))return!1;let n=e;if(!x(n))return!1;let r=n.anyOf!==void 0&&Array.isArray(n.anyOf)&&n.anyOf.length===2&&X(n.anyOf[0])&&N(n.anyOf[1]),i=Array.isArray(n.type)&&n.type.length===2&&(n.type[0]===`null`&&(0,t.isSetString)(n.type[1])&&n.type[1]!==`null`&&l.has(n.type[1])||n.type[1]===`null`&&(0,t.isSetString)(n.type[0])&&n.type[0]!==`null`&&l.has(n.type[0]));return r||i}function F(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return!x(n)||n.type!==`number`&&n.type!==`integer`?!1:h(n.format)&&_(n.minimum)&&_(n.exclusiveMinimum)&&_(n.maximum)&&_(n.exclusiveMaximum)&&_(n.multipleOf)&&_(n.default)&&(n.enum===void 0||m(n.enum,r))}function I(e){return F(e)&&e.type===`integer`}function L(e){return F(e)&&e.type===`number`}function R(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)&&n.type===`object`&&(n.properties===void 0||a(n.properties))&&(n.patternProperties===void 0||a(n.patternProperties))&&(n.additionalProperties===void 0||(0,t.isBoolean)(n.additionalProperties)||X(n.additionalProperties))&&(n.required===void 0||s(n.required))&&(n.unevaluatedProperties===void 0||(0,t.isBoolean)(n.unevaluatedProperties)||X(n.unevaluatedProperties))&&(n.dependencies===void 0||(0,t.isSetObject)(n.dependencies)&&Object.values(n.dependencies).every(e=>s(e)||X(e)))&&(n.dependentRequired===void 0||ee(n.dependentRequired))&&(n.dependentSchemas===void 0||a(n.dependentSchemas))&&_(n.minProperties)&&_(n.maxProperties)&&(n.primaryKey===void 0||s(n.primaryKey))&&h(n.databaseSchema)}function z(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)&&n.type===`string`&&_(n.minLength)&&_(n.maxLength)&&h(n.pattern)&&h(n.format)&&h(n.default)&&(n.enum===void 0||m(n.enum,t.isSetString))&&h(n.contentMediaType)&&h(n.contentEncoding)&&h(n.contentSchema)}function B(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)&&n.type===`array`&&n.uniqueItems===!0&&b(n.prefixItems)&&y(n.items)&&y(n.contains)&&_(n.minItems)&&_(n.maxItems)&&_(n.minContains)&&_(n.maxContains)&&(n.unevaluatedItems===void 0||(0,t.isBoolean)(n.unevaluatedItems)||X(n.unevaluatedItems))}function V(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)&&n.type===`object`&&(n.patternProperties===void 0||a(n.patternProperties))&&(n.additionalProperties===void 0||(0,t.isBoolean)(n.additionalProperties)||X(n.additionalProperties))&&y(n.propertyNames)}function H(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)&&n.type===`array`&&m(n.prefixItems,X)&&_(n.minItems)&&_(n.maxItems)&&y(n.items)&&y(n.contains)&&g(n.uniqueItems)&&_(n.minContains)&&_(n.maxContains)&&(n.unevaluatedItems===void 0||(0,t.isBoolean)(n.unevaluatedItems)||X(n.unevaluatedItems))}function U(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)&&S(n.not)&&(n.default===void 0||n.default===void 0)}function W(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)?(0,t.isSetString)(n.type)&&c.has(n.type)?n.enum===void 0?!0:Array.isArray(n.enum)?n.type===`string`?n.enum.every(e=>(0,t.isSetString)(e))&&(n.default===void 0||(0,t.isSetString)(n.default)):n.type===`number`?n.enum.every(e=>r(e))&&(n.default===void 0||r(n.default)):n.type===`boolean`?n.enum.every(e=>(0,t.isBoolean)(e))&&(n.default===void 0||(0,t.isBoolean)(n.default)):n.type===`integer`?n.format===`int64`?n.enum.every(e=>d(e))&&(n.default===void 0||d(n.default)):!1:n.type===`null`&&n.enum.every(e=>e===null)&&(n.default===void 0||n.default===null):!1:se(n.type)&&n.type!==void 0:!1}function G(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)&&(W(n)||q(n))}function K(e){return S(e)}function q(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)&&m(n.anyOf,X)}function J(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return x(n)&&(0,t.isSetString)(n.$ref)}function Y(e){if(!(0,t.isSetObject)(e))return!1;let n=e;if(!(0,t.isSetObject)(n[`~standard`]))return!1;let r=n[`~standard`];return r.version===1&&(0,t.isFunction)(r.validate)}function ue(e){if(!(0,t.isSetObject)(e)||!Y(e))return!1;let n=e;return n.kind===`schema`&&(0,t.isSetString)(n.type)&&(0,t.isBoolean)(n.async)&&(0,t.isFunction)(n.reference)&&(0,t.isSetString)(n.expects)&&(0,t.isFunction)(n[`~run`])}function X(e){return z(e)||I(e)||L(e)||w(e)||T(e)||E(e)||D(e)||k(e)||j(e)||N(e)||C(e)||R(e)||V(e)||H(e)||G(e)||U(e)||J(e)||M(e)||A(e)||S(e)||P(e)||O(e)||K(e)||B(e)}function de(e){return N(e)}function Z(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return!(!p(n)||`id`in n&&!(0,t.isSetString)(n.id)||`resolve`in n&&!(0,t.isFunction)(n.resolve)||`properties`in n&&!ae(n.properties)||`required`in n&&!s(n.required)||`title`in n&&!(0,t.isSetString)(n.title)||`description`in n&&!(0,t.isSetString)(n.description)||`$schema`in n&&!(0,t.isSetString)(n.$schema)||`tags`in n&&!s(n.tags)||`args`in n&&(!Array.isArray(n.args)||!n.args.every(e=>ie(e)))||`returns`in n&&!p(n.returns))}function Q(e){return Z(e)&&!X(e)}function fe(e){if(!(0,t.isSetObject)(e))return!1;let n=e;return!(`$schema`in n&&!Z(n.$schema)||`$resolve`in n&&!(0,t.isFunction)(n.$resolve))}function pe(e){if(!fe(e)||X(e))return!1;let t=e;return!(`$schema`in t&&t.$schema!==void 0&&!Q(t.$schema))}function $(e){return(0,t.isSetObject)(e)&&`schema`in e&&X(e.schema)&&`variant`in e&&(0,t.isSetString)(e.variant)&&`hash`in e&&(0,t.isSetString)(e.hash)}function me(e){return $(e)}function he(e){return $(e)&&`source`in e&&(0,t.isSetObject)(e.source)&&`schema`in e.source&&`variant`in e.source&&(0,t.isSetString)(e.source.variant)}function ge(e){return $(e)&&R(e.schema)}exports.isFileReference=n,exports.isJsonSchema=X,exports.isJsonSchemaAllOf=O,exports.isJsonSchemaAny=S,exports.isJsonSchemaAnyOf=q,exports.isJsonSchemaArray=C,exports.isJsonSchemaBigint=w,exports.isJsonSchemaBoolean=T,exports.isJsonSchemaDate=E,exports.isJsonSchemaDecimal=L,exports.isJsonSchemaEnum=D,exports.isJsonSchemaInteger=I,exports.isJsonSchemaKeywords=le,exports.isJsonSchemaLiteral=k,exports.isJsonSchemaMap=A,exports.isJsonSchemaNativeEnum=j,exports.isJsonSchemaNever=M,exports.isJsonSchemaNull=N,exports.isJsonSchemaNullable=P,exports.isJsonSchemaNumber=F,exports.isJsonSchemaObject=R,exports.isJsonSchemaPrimitiveType=te,exports.isJsonSchemaPrimitiveUnion=W,exports.isJsonSchemaRecord=V,exports.isJsonSchemaRef=J,exports.isJsonSchemaSet=B,exports.isJsonSchemaString=z,exports.isJsonSchemaTuple=H,exports.isJsonSchemaType=u,exports.isJsonSchemaUndefined=U,exports.isJsonSchemaUnion=G,exports.isJsonSchemaUnknown=K,exports.isNullOnlyJsonSchema=de,exports.isSchema=$,exports.isSchemaObject=ge,exports.isSchemaOf=me,exports.isSchemaWithSource=he,exports.isStandardSchema=Y,exports.isUntypedInput=fe,exports.isUntypedInputStrict=pe,exports.isUntypedSchema=Z,exports.isUntypedSchemaStrict=Q,exports.isValibotSchema=ue;