@kravc/schema 2.8.0-alpha.7 → 2.8.0-alpha.9

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 (118) hide show
  1. package/dist/CredentialFactory.d.ts +5 -318
  2. package/dist/CredentialFactory.d.ts.map +1 -1
  3. package/dist/CredentialFactory.js +5 -317
  4. package/dist/CredentialFactory.js.map +1 -1
  5. package/dist/Schema.d.ts +15 -420
  6. package/dist/Schema.d.ts.map +1 -1
  7. package/dist/Schema.js +13 -384
  8. package/dist/Schema.js.map +1 -1
  9. package/dist/ValidationError.d.ts +3 -49
  10. package/dist/ValidationError.d.ts.map +1 -1
  11. package/dist/ValidationError.js +3 -48
  12. package/dist/ValidationError.js.map +1 -1
  13. package/dist/Validator.d.ts +6 -470
  14. package/dist/Validator.d.ts.map +1 -1
  15. package/dist/Validator.js +51 -479
  16. package/dist/Validator.js.map +1 -1
  17. package/dist/helpers/cleanupAttributes.d.ts +3 -32
  18. package/dist/helpers/cleanupAttributes.d.ts.map +1 -1
  19. package/dist/helpers/cleanupAttributes.js +1 -30
  20. package/dist/helpers/cleanupAttributes.js.map +1 -1
  21. package/dist/helpers/cleanupNulls.d.ts +1 -25
  22. package/dist/helpers/cleanupNulls.d.ts.map +1 -1
  23. package/dist/helpers/cleanupNulls.js +2 -61
  24. package/dist/helpers/cleanupNulls.js.map +1 -1
  25. package/dist/helpers/createSchemasMap.d.ts +2 -93
  26. package/dist/helpers/createSchemasMap.d.ts.map +1 -1
  27. package/dist/helpers/createSchemasMap.js +4 -162
  28. package/dist/helpers/createSchemasMap.js.map +1 -1
  29. package/dist/helpers/getReferenceIds.d.ts +1 -165
  30. package/dist/helpers/getReferenceIds.d.ts.map +1 -1
  31. package/dist/helpers/getReferenceIds.js +2 -166
  32. package/dist/helpers/getReferenceIds.js.map +1 -1
  33. package/dist/helpers/got.d.ts +1 -57
  34. package/dist/helpers/got.d.ts.map +1 -1
  35. package/dist/helpers/got.js +1 -57
  36. package/dist/helpers/got.js.map +1 -1
  37. package/dist/helpers/mapObjectProperties.d.ts +2 -144
  38. package/dist/helpers/mapObjectProperties.d.ts.map +1 -1
  39. package/dist/helpers/mapObjectProperties.js +1 -142
  40. package/dist/helpers/mapObjectProperties.js.map +1 -1
  41. package/dist/helpers/normalizeAttributes.d.ts +3 -211
  42. package/dist/helpers/normalizeAttributes.d.ts.map +1 -1
  43. package/dist/helpers/normalizeAttributes.js +1 -209
  44. package/dist/helpers/normalizeAttributes.js.map +1 -1
  45. package/dist/helpers/normalizeProperties.d.ts +1 -165
  46. package/dist/helpers/normalizeProperties.d.ts.map +1 -1
  47. package/dist/helpers/normalizeProperties.js +1 -164
  48. package/dist/helpers/normalizeProperties.js.map +1 -1
  49. package/dist/helpers/normalizeRequired.d.ts +1 -153
  50. package/dist/helpers/normalizeRequired.d.ts.map +1 -1
  51. package/dist/helpers/normalizeRequired.js +0 -151
  52. package/dist/helpers/normalizeRequired.js.map +1 -1
  53. package/dist/helpers/normalizeType.d.ts +1 -77
  54. package/dist/helpers/normalizeType.d.ts.map +1 -1
  55. package/dist/helpers/normalizeType.js +11 -139
  56. package/dist/helpers/normalizeType.js.map +1 -1
  57. package/dist/helpers/nullifyEmptyValues.d.ts +1 -135
  58. package/dist/helpers/nullifyEmptyValues.d.ts.map +1 -1
  59. package/dist/helpers/nullifyEmptyValues.js +13 -143
  60. package/dist/helpers/nullifyEmptyValues.js.map +1 -1
  61. package/dist/helpers/removeRequiredAndDefault.d.ts +2 -102
  62. package/dist/helpers/removeRequiredAndDefault.d.ts.map +1 -1
  63. package/dist/helpers/removeRequiredAndDefault.js +1 -100
  64. package/dist/helpers/removeRequiredAndDefault.js.map +1 -1
  65. package/dist/helpers/validateId.d.ts +1 -36
  66. package/dist/helpers/validateId.d.ts.map +1 -1
  67. package/dist/helpers/validateId.js +1 -36
  68. package/dist/helpers/validateId.js.map +1 -1
  69. package/dist/ld/documentLoader.d.ts +1 -1
  70. package/dist/ld/documentLoader.d.ts.map +1 -1
  71. package/dist/ld/documentLoader.js +1 -1
  72. package/dist/ld/documentLoader.js.map +1 -1
  73. package/dist/ld/getLinkedDataAttributeType.d.ts +1 -1
  74. package/dist/ld/getLinkedDataAttributeType.d.ts.map +1 -1
  75. package/dist/ld/getLinkedDataAttributeType.js +1 -1
  76. package/dist/ld/getLinkedDataAttributeType.js.map +1 -1
  77. package/dist/ld/getLinkedDataContext.d.ts +1 -1
  78. package/dist/ld/getLinkedDataContext.d.ts.map +1 -1
  79. package/dist/ld/getLinkedDataContext.js +1 -1
  80. package/dist/ld/getLinkedDataContext.js.map +1 -1
  81. package/package.json +5 -5
  82. package/src/CredentialFactory.ts +5 -318
  83. package/src/Schema.ts +17 -427
  84. package/src/ValidationError.ts +5 -52
  85. package/src/Validator.ts +20 -484
  86. package/src/__tests__/CredentialFactory.test.ts +1 -1
  87. package/src/__tests__/Schema.test.ts +3 -8
  88. package/src/__tests__/ValidationError.test.ts +4 -2
  89. package/src/__tests__/Validator.test.ts +21 -4
  90. package/src/helpers/__tests__/cleanupAttributes.test.ts +3 -1
  91. package/src/helpers/__tests__/createSchemasMap.test.ts +1 -1
  92. package/src/helpers/__tests__/mapObjectProperties.test.ts +2 -1
  93. package/src/helpers/__tests__/normalizeAttributes.test.ts +4 -2
  94. package/src/helpers/__tests__/normalizeProperties.test.ts +3 -1
  95. package/src/helpers/__tests__/normalizeRequired.test.ts +4 -9
  96. package/src/helpers/__tests__/nullifyEmptyValues.test.ts +43 -12
  97. package/src/helpers/__tests__/removeRequiredAndDefault.test.ts +3 -10
  98. package/src/helpers/cleanupAttributes.ts +6 -44
  99. package/src/helpers/cleanupNulls.ts +2 -63
  100. package/src/helpers/createSchemasMap.ts +4 -163
  101. package/src/helpers/getReferenceIds.ts +2 -173
  102. package/src/helpers/got.ts +1 -57
  103. package/src/helpers/mapObjectProperties.ts +4 -156
  104. package/src/helpers/normalizeAttributes.ts +7 -211
  105. package/src/helpers/normalizeProperties.ts +1 -172
  106. package/src/helpers/normalizeRequired.ts +1 -161
  107. package/src/helpers/normalizeType.ts +11 -139
  108. package/src/helpers/nullifyEmptyValues.ts +10 -145
  109. package/src/helpers/removeRequiredAndDefault.ts +1 -106
  110. package/src/helpers/validateId.ts +1 -36
  111. package/src/ld/documentLoader.ts +1 -1
  112. package/src/ld/getLinkedDataAttributeType.ts +1 -1
  113. package/src/ld/getLinkedDataContext.ts +1 -1
  114. package/src/{helpers/JsonSchema.ts → types.d.ts} +12 -16
  115. package/dist/helpers/JsonSchema.d.ts +0 -99
  116. package/dist/helpers/JsonSchema.d.ts.map +0 -1
  117. package/dist/helpers/JsonSchema.js +0 -3
  118. package/dist/helpers/JsonSchema.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"CredentialFactory.js","sourceRoot":"","sources":["../src/CredentialFactory.ts"],"names":[],"mappings":";;;;;AAAA,6DAAgD;AAEhD,4DAAoC;AACpC,sEAA8C;AAE9C,sDAAuD;AAEvD,MAAM,EAAE,0BAA0B,EAAE,GAAG,+BAAS,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8GG;AACH,MAAM,iBAAiB;IACb,IAAI,CAAS;IACb,MAAM,CAAW;IACjB,QAAQ,CAAiC;IACzC,UAAU,CAAY;IAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuCG;IACH,YAAY,GAAW,EAAE,OAAiB;QACxC,IAAA,oBAAU,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAEvB,IAAI,CAAC,MAAM,GAAG,OAAO;aAClB,GAAG,CAAC,MAAM,CAAC,EAAE;YACZ,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;gBACf,OAAO,MAAM,CAAC;YAChB,CAAC;YAED,OAAO,IAAI,gBAAM,CAAC,MAAM,EAAE,MAAM,C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D,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,cAAe,CAAC;QACtC,CAAC;IACH,CAAC;IAED,uEAAuE;IACvE,IAAI,cAAc;QAChB,MAAM,CAAE,cAAc,CAAE,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;QAE1D,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,6DAA6D;IAC7D,IAAI,OAAO;QACT,OAAO;YACL,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE;YAC3C,GAAG,IAAI,CAAC,QAAQ;SACjB,CAAC;IACJ,CAAC;IAED,iEAAiE;IACjE,gBAAgB,CAAC,EAAU,EAAE,MAAc,EAAE,UAAwB,EAAE;QACrE,IAAA,oBAAU,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACrB,IAAA,oBAAU,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAE7B,MAAM,IAAI,GAAG;YACX,sBAAsB;YACtB,IAAI,CAAC,cAAc;SACpB,CAAC;QAEF,MAAM,CAAE,QAAQ,CAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QACjC,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;QAEzE,OAAO;YACL,UAAU,EAAE;gBACV,0BAA0B;gBAC1B,IAAI,CAAC,OAAO;aACb;YACD,EAAE;YACF,IAAI;YACJ,MAAM;YACN,iBAAiB;SAClB,CAAC;IACJ,CAAC;CACF;AAED,kBAAe,iBAAiB,CAAC"}
package/dist/Schema.d.ts CHANGED
@@ -1,446 +1,41 @@
1
+ import type { JsonSchema } from 'z-schema';
1
2
  import type { LinkedDataContext } from './ld/getLinkedDataContext';
2
- import type { JsonSchema, EnumSchema, PropertiesSchema } from './helpers/JsonSchema';
3
- /**
4
- * JSON-LD linked data type structure for semantic web integration.
5
- *
6
- * **Intent:** Provide a standardized format for representing schemas in the
7
- * semantic web, enabling integration with Linked Data and Verifiable Credentials.
8
- *
9
- * **Use Cases:**
10
- * - Generate Verifiable Credentials with proper semantic context
11
- * - Create JSON-LD documents compatible with schema.org and other vocabularies
12
- * - Enable semantic interoperability between different systems
13
- * - Support decentralized identity and credential systems
14
- *
15
- * **Structure:**
16
- * - `@id`: The unique identifier (URI) for the schema type
17
- * - `@context`: The JSON-LD context mapping properties to semantic types
18
- *
19
- * **Example:**
20
- * ```typescript
21
- * const schema = new Schema(
22
- * { name: { type: 'string' }, email: { type: 'string', format: 'email' } },
23
- * 'Person',
24
- * 'https://schema.org/'
25
- * );
26
- *
27
- * const linkedData = schema.linkedDataType;
28
- * // {
29
- * // '@id': 'https://schema.org/Person',
30
- * // '@context': {
31
- * // '@vocab': 'https://schema.org/',
32
- * // 'name': 'https://schema.org/name',
33
- * // 'email': 'https://schema.org/email'
34
- * // }
35
- * // }
36
- * ```
37
- */
3
+ /** JSON-LD linked data type structure for semantic web integration. */
38
4
  export type LinkedDataType = {
39
5
  '@id': string;
40
6
  '@context': LinkedDataContext;
41
7
  };
42
8
  export type SchemaSource = EnumSchema | PropertiesSchema;
43
9
  export type PropertiesSchemaSource = PropertiesSchema;
44
- /**
45
- * Schema class for defining and manipulating JSON schemas for object validation.
46
- *
47
- * This class provides a flexible API for creating, transforming, and composing JSON schemas.
48
- * It supports both property-based schemas (for objects) and enum schemas (for value sets).
49
- *
50
- * **Use Cases:**
51
- * - Define validation schemas for API request/response objects
52
- * - Create reusable schema components that can be extended or composed
53
- * - Generate JSON-LD linked data types for semantic web applications
54
- * - Transform schemas for different use cases (e.g., create update schemas from create schemas)
55
- *
56
- * **Example - Basic Usage:**
57
- * ```typescript
58
- * const userSchema = new Schema({
59
- * firstName: { type: 'string', required: true },
60
- * lastName: { type: 'string', required: true },
61
- * email: { type: 'string', format: 'email', required: true }
62
- * }, 'User');
63
- * ```
64
- *
65
- * **Example - Schema Composition:**
66
- * ```typescript
67
- * const baseSchema = new Schema({ name: { required: true } }, 'Base');
68
- * const extendedSchema = baseSchema.extend({ status: { enum: ['Active', 'Inactive'] } }, 'Extended');
69
- * ```
70
- *
71
- * **Example - Linked Data Types:**
72
- * ```typescript
73
- * const schema = new Schema(
74
- * { id: { type: 'string' }, name: { type: 'string' } },
75
- * 'Person',
76
- * 'https://schema.org/'
77
- * );
78
- * // schema.linkedDataType will contain JSON-LD context
79
- * ```
80
- */
10
+ /** Schema class for defining and manipulating JSON schemas for object validation. */
81
11
  declare class Schema {
82
12
  private _id;
83
13
  private _url?;
84
14
  private _source;
85
15
  private _linkedDataType?;
86
- /**
87
- * Creates a new Schema instance.
88
- *
89
- * **Intent:** Initialize a schema with properties, enum values, or clone from another schema.
90
- * Automatically normalizes properties, infers types, and optionally creates JSON-LD linked data types.
91
- *
92
- * **Use Cases:**
93
- * - Create a new schema from scratch with property definitions
94
- * - Create an enum schema for value validation
95
- * - Clone an existing schema with a new ID
96
- * - Create a schema with JSON-LD context for semantic web applications
97
- *
98
- * @param propertiesOrSchema - Property definitions, enum schema, or existing Schema instance to clone
99
- * @param id - Unique identifier for the schema (defaults to 'UNDEFINED_SCHEMA_ID' if not provided)
100
- * @param url - Optional URL for generating JSON-LD linked data types (only for property schemas, not enums)
101
- *
102
- * **Example - Property Schema:**
103
- * ```typescript
104
- * const schema = new Schema({
105
- * name: { type: 'string', required: true },
106
- * age: { type: 'number', minimum: 0 }
107
- * }, 'Person');
108
- * ```
109
- *
110
- * **Example - Enum Schema:**
111
- * ```typescript
112
- * const sizeSchema = new Schema({ enum: ['S', 'M', 'L'], type: 'string' }, 'Size');
113
- * ```
114
- *
115
- * **Example - Clone Schema:**
116
- * ```typescript
117
- * const original = new Schema({ name: { type: 'string' } }, 'Original');
118
- * const cloned = new Schema(original, 'Cloned');
119
- * ```
120
- *
121
- * **Example - With Linked Data URL:**
122
- * ```typescript
123
- * const schema = new Schema(
124
- * { name: { type: 'string' } },
125
- * 'Person',
126
- * 'https://schema.org/'
127
- * );
128
- * // Automatically creates linkedDataType with @id and @context
129
- * ```
130
- */
16
+ /** Creates a new Schema instance. */
131
17
  constructor(propertiesOrSchema: Schema | SchemaSource, id?: string, url?: string);
132
- /**
133
- * Returns the unique identifier for this schema.
134
- *
135
- * **Intent:** Provide a way to reference and identify schemas in collections or validators.
136
- *
137
- * **Use Cases:**
138
- * - Reference schemas in Validator instances
139
- * - Track schema lineage when cloning/extending
140
- * - Generate schema identifiers for JSON Schema output
141
- *
142
- * @returns The schema ID, or 'UNDEFINED_SCHEMA_ID' if not specified during construction
143
- *
144
- * **Example:**
145
- * ```typescript
146
- * const schema = new Schema({ name: { type: 'string' } }, 'User');
147
- * console.log(schema.id); // 'User'
148
- * ```
149
- */
18
+ /** Returns the unique identifier for this schema. */
150
19
  get id(): string;
151
- /**
152
- * Returns the URL associated with this schema for JSON-LD linked data generation.
153
- *
154
- * **Intent:** Provide access to the base URL used for generating semantic web identifiers.
155
- *
156
- * **Use Cases:**
157
- * - Check if a schema has linked data support
158
- * - Access the base URL for constructing related URIs
159
- * - Debug linked data type generation
160
- *
161
- * @returns The schema URL if provided during construction, undefined otherwise
162
- *
163
- * **Example:**
164
- * ```typescript
165
- * const schema = new Schema({ name: { type: 'string' } }, 'Person', 'https://schema.org/');
166
- * console.log(schema.url); // 'https://schema.org/'
167
- * ```
168
- */
20
+ /** Returns the URL associated with this schema for JSON-LD linked data generation. */
169
21
  get url(): string | undefined;
170
- /**
171
- * Returns a deep clone of the schema's source properties or enum definition.
172
- *
173
- * **Intent:** Provide immutable access to schema definitions to prevent accidental mutations.
174
- *
175
- * **Use Cases:**
176
- * - Inspect schema structure without modifying the original
177
- * - Clone schemas manually for custom transformations
178
- * - Debug schema definitions
179
- * - Pass schema definitions to other functions safely
180
- *
181
- * @returns A deep copy of the schema source (PropertiesSchema or EnumSchema)
182
- *
183
- * **Example:**
184
- * ```typescript
185
- * const schema = new Schema({ name: { type: 'string', required: true } }, 'User');
186
- * const source = schema.source;
187
- * // source is a clone, modifying it won't affect the original schema
188
- * ```
189
- */
22
+ /** Returns a deep clone of the schema's source properties or enum definition. */
190
23
  get source(): EnumSchema | PropertiesSchema;
191
- /**
192
- * Checks if this schema is an enum schema (defines a set of allowed values).
193
- *
194
- * **Intent:** Enable type-safe branching logic based on schema type.
195
- *
196
- * **Use Cases:**
197
- * - Conditionally apply methods that only work on property schemas
198
- * - Validate schema type before operations
199
- * - Implement different serialization logic for enums vs objects
200
- *
201
- * @returns true if the schema is an enum schema, false if it's a properties schema
202
- *
203
- * **Example:**
204
- * ```typescript
205
- * const enumSchema = new Schema({ enum: ['A', 'B', 'C'] }, 'Letters');
206
- * const propSchema = new Schema({ name: { type: 'string' } }, 'Person');
207
- *
208
- * console.log(enumSchema.isEnum); // true
209
- * console.log(propSchema.isEnum); // false
210
- * ```
211
- */
24
+ /** Checks if this schema is an enum schema (defines a set of allowed values). */
212
25
  get isEnum(): boolean;
213
- /**
214
- * Returns a normalized JSON Schema representation of this schema.
215
- *
216
- * **Intent:** Convert the internal schema representation to standard JSON Schema format
217
- * with normalized required arrays and proper structure for validation libraries.
218
- *
219
- * **Use Cases:**
220
- * - Export schemas for use with JSON Schema validators (e.g., z-schema)
221
- * - Generate API documentation from schemas
222
- * - Serialize schemas to JSON for storage or transmission
223
- * - Integrate with tools that expect standard JSON Schema format
224
- *
225
- * @returns A JsonSchema object (ObjectSchema for property schemas, EnumSchema for enum schemas)
226
- *
227
- * **Example - Property Schema:**
228
- * ```typescript
229
- * const schema = new Schema({
230
- * name: { type: 'string', required: true },
231
- * age: { type: 'number' }
232
- * }, 'Person');
233
- *
234
- * const jsonSchema = schema.jsonSchema;
235
- * // {
236
- * // id: 'Person',
237
- * // type: 'object',
238
- * // properties: { name: {...}, age: {...} },
239
- * // required: ['name']
240
- * // }
241
- * ```
242
- *
243
- * **Example - Enum Schema:**
244
- * ```typescript
245
- * const enumSchema = new Schema({ enum: ['S', 'M', 'L'], type: 'string' }, 'Size');
246
- * const jsonSchema = enumSchema.jsonSchema;
247
- * // { id: 'Size', enum: ['S', 'M', 'L'], type: 'string' }
248
- * ```
249
- */
26
+ /** Returns a normalized JSON Schema representation of this schema. */
250
27
  get jsonSchema(): JsonSchema;
251
- /**
252
- * Returns the JSON-LD linked data type if a URL was provided during construction.
253
- *
254
- * **Intent:** Provide semantic web identifiers and context for schemas, enabling
255
- * integration with Linked Data and Verifiable Credentials standards.
256
- *
257
- * **Use Cases:**
258
- * - Generate Verifiable Credentials with proper semantic context
259
- * - Create JSON-LD documents with schema.org or custom vocabularies
260
- * - Enable semantic interoperability between systems
261
- * - Support decentralized identity and credential systems
262
- *
263
- * @returns LinkedDataType object with @id and @context, or undefined if no URL was provided
264
- *
265
- * **Example:**
266
- * ```typescript
267
- * const schema = new Schema(
268
- * { name: { type: 'string' }, email: { type: 'string', format: 'email' } },
269
- * 'Person',
270
- * 'https://schema.org/'
271
- * );
272
- *
273
- * const linkedData = schema.linkedDataType;
274
- * // {
275
- * // '@id': 'https://schema.org/Person',
276
- * // '@context': { ... } // Generated context mapping types to schema.org
277
- * // }
278
- * ```
279
- *
280
- * **Note:** Linked data types are only generated for property schemas, not enum schemas.
281
- */
28
+ /** Returns the JSON-LD linked data type if a URL was provided during construction. */
282
29
  get linkedDataType(): LinkedDataType | undefined;
283
- /**
284
- * Creates a complete clone of the schema with a new identifier.
285
- *
286
- * **Intent:** Duplicate a schema while maintaining all properties and structure,
287
- * useful for creating variations or versioning schemas.
288
- *
289
- * **Use Cases:**
290
- * - Create schema versions (e.g., 'UserV1', 'UserV2')
291
- * - Duplicate schemas for different contexts
292
- * - Create base schemas that can be independently extended
293
- * - Maintain schema history or branching
294
- *
295
- * @param id - The new unique identifier for the cloned schema
296
- * @returns A new Schema instance with identical structure but different ID
297
- *
298
- * **Example:**
299
- * ```typescript
300
- * const userSchema = new Schema({ name: { type: 'string' } }, 'User');
301
- * const userV2Schema = userSchema.clone('UserV2');
302
- * // Both schemas have identical properties but different IDs
303
- * ```
304
- */
30
+ /** Creates a complete clone of the schema with a new identifier. */
305
31
  clone(id?: string): Schema;
306
- /**
307
- * Creates a schema clone without required constraints and default values.
308
- *
309
- * **Intent:** Generate update/patch schemas from create schemas by removing
310
- * validation constraints that make sense for creation but not for updates.
311
- *
312
- * **Use Cases:**
313
- * - Create update schemas where all fields are optional
314
- * - Generate PATCH endpoint schemas from POST endpoint schemas
315
- * - Allow partial updates without requiring all original fields
316
- * - Create flexible input schemas for editing operations
317
- *
318
- * @param id - The new unique identifier for the pure schema
319
- * @returns A new Schema instance with all required flags and defaults removed
320
- * @throws Error if called on an enum schema
321
- *
322
- * **Example:**
323
- * ```typescript
324
- * const createSchema = new Schema({
325
- * name: { type: 'string', required: true },
326
- * email: { type: 'string', required: true, default: 'user@example.com' }
327
- * }, 'CreateUser');
328
- *
329
- * const updateSchema = createSchema.pure('UpdateUser');
330
- * // updateSchema has no required fields and no defaults
331
- * // All fields are optional for updates
332
- * ```
333
- */
32
+ /** Creates a schema clone without required constraints and default values. */
334
33
  pure(id?: string): Schema;
335
- /**
336
- * Creates a schema clone containing only the specified properties.
337
- *
338
- * **Intent:** Create focused schemas that expose only a subset of properties,
339
- * useful for different API views or security contexts.
340
- *
341
- * **Use Cases:**
342
- * - Create public-facing schemas that hide sensitive fields
343
- * - Generate response schemas with only necessary fields
344
- * - Create view-specific schemas (e.g., 'UserSummary', 'UserDetail')
345
- * - Implement field-level access control in schemas
346
- * - Create lightweight schemas for list views
347
- *
348
- * @param propertyNames - Array of property names to include in the new schema
349
- * @param id - The new unique identifier for the filtered schema
350
- * @returns A new Schema instance containing only the specified properties
351
- * @throws Error if called on an enum schema
352
- *
353
- * **Example:**
354
- * ```typescript
355
- * const fullSchema = new Schema({
356
- * name: { type: 'string' },
357
- * email: { type: 'string' },
358
- * password: { type: 'string' },
359
- * ssn: { type: 'string' }
360
- * }, 'User');
361
- *
362
- * const publicSchema = fullSchema.only(['name', 'email'], 'PublicUser');
363
- * // publicSchema only contains name and email, hiding sensitive fields
364
- * ```
365
- */
34
+ /** Creates a schema clone containing only the specified properties. */
366
35
  only(propertyNames: string[], id?: string): Schema;
367
- /**
368
- * Creates a schema clone extended with additional properties.
369
- *
370
- * **Intent:** Build complex schemas incrementally by composing base schemas
371
- * with additional fields, enabling schema inheritance and composition patterns.
372
- *
373
- * **Use Cases:**
374
- * - Extend base schemas with domain-specific fields
375
- * - Create schema hierarchies (e.g., BaseEntity -> User -> AdminUser)
376
- * - Add computed or derived fields to existing schemas
377
- * - Compose schemas from multiple sources
378
- * - Build versioned schemas that add new fields
379
- *
380
- * @param properties - Additional properties to merge into the schema
381
- * @param id - The new unique identifier for the extended schema
382
- * @returns A new Schema instance with merged properties (new properties override existing ones)
383
- * @throws Error if called on an enum schema
384
- *
385
- * **Example:**
386
- * ```typescript
387
- * const baseSchema = new Schema({
388
- * id: { type: 'string', required: true },
389
- * createdAt: { type: 'string', format: 'date-time', required: true }
390
- * }, 'BaseEntity');
391
- *
392
- * const userSchema = baseSchema.extend({
393
- * name: { type: 'string', required: true },
394
- * email: { type: 'string', format: 'email', required: true }
395
- * }, 'User');
396
- *
397
- * // userSchema contains id, createdAt, name, and email
398
- * ```
399
- */
36
+ /** Creates a schema clone extended with additional properties. */
400
37
  extend(properties: PropertiesSchema, id?: string): Schema;
401
- /**
402
- * Creates a new schema that wraps the current schema as a nested property.
403
- *
404
- * **Intent:** Transform a flat schema into a nested structure, useful for
405
- * API response formatting or when data needs to be wrapped in a container object.
406
- *
407
- * **Use Cases:**
408
- * - Wrap schemas for API responses (e.g., { data: { ...schema } })
409
- * - Create nested data structures from flat schemas
410
- * - Format schemas for specific API conventions
411
- * - Generate wrapper schemas for pagination or metadata containers
412
- * - Transform schemas for different API versions or formats
413
- *
414
- * @param propertyName - The name of the property that will contain the wrapped schema
415
- * @param attributes - Optional attributes for the wrapper property (default: { required: true })
416
- * @param id - The new unique identifier for the wrapped schema
417
- * @returns A new Schema instance where the original schema is nested under the specified property
418
- * @throws Error if called on an enum schema
419
- *
420
- * **Example:**
421
- * ```typescript
422
- * const userSchema = new Schema({
423
- * name: { type: 'string', required: true },
424
- * email: { type: 'string', required: true }
425
- * }, 'User');
426
- *
427
- * const wrappedSchema = userSchema.wrap('data', { required: true }, 'UserResponse');
428
- * // Resulting schema structure:
429
- * // {
430
- * // data: {
431
- * // type: 'object',
432
- * // properties: { name: {...}, email: {...} },
433
- * // required: true
434
- * // }
435
- * // }
436
- * ```
437
- *
438
- * **Example - With Default Value:**
439
- * ```typescript
440
- * const wrappedSchema = userSchema.wrap('data', { default: '{}' }, 'OptionalUserResponse');
441
- * // The 'data' property has a default value and is not required
442
- * ```
443
- */
38
+ /** Creates a new schema that wraps the current schema as a nested property. */
444
39
  wrap(propertyName: string, attributes: {
445
40
  default?: string;
446
41
  required?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,gBAAgB,EAEjB,MAAM,sBAAsB,CAAC;AAI9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,iBAAiB,CAAC;CAC/B,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,gBAAgB,CAAC;AAEzD,MAAM,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,cAAM,MAAM;IACV,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,IAAI,CAAC,CAAS;IACtB,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,eAAe,CAAC,CAAiB;IAEzC;;;;;;;;;;;;;;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