@asaidimu/anansi 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +1 -1
- package/index.d.cts +53 -12
- package/index.d.ts +53 -12
- package/index.js +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -64,4 +64,4 @@ ${n.description}
|
|
|
64
64
|
## Migrations
|
|
65
65
|
`),t.push("| ID | Description | Status | Changes |"),t.push("|----|-------------|--------|---------|");for(let a of n.migrations||[])t.push([a.id,a.description,a.status,a.changes.length].join("|"));if(n.mock&&e?.faker)try{let a=n.mock(e.faker).next().value;t.push("\n## Example Data\n```json\n"+JSON.stringify(a,null,2)+"\n```")}catch{t.push(`
|
|
66
66
|
<!-- Error generating mock data -->`)}return t.join(`
|
|
67
|
-
`)}function Et(n){let e={},t={};n.hint?.groups&&n.hint.groups.forEach(s=>{t[s.name]={label:s.label,description:s.description}}),Ge(n.fields,"",n.nestedSchemas||{},e);let i=[];for(let[s,r]of Object.entries(e)){let a=s!=="ungrouped"?t[s]:void 0;i.push({name:s!=="ungrouped"?s:"ungrouped",label:a?.label||"Ungrouped",description:a?.description,fields:r})}return i}function Ge(n,e,t,i){for(let[s,r]of Object.entries(n)){
|
|
67
|
+
`)}function Et(n){let e={},t={};n.hint?.groups&&n.hint.groups.forEach(s=>{t[s.name]={label:s.label,description:s.description}}),Ge(n.fields,"",n.nestedSchemas||{},e);let i=[];for(let[s,r]of Object.entries(e)){let a=s!=="ungrouped"?t[s]:void 0;i.push({name:s!=="ungrouped"?s:"ungrouped",label:a?.label||"Ungrouped",description:a?.description,fields:r})}return i}function Ge(n,e,t,i){for(let[s,r]of Object.entries(n)){let a=e?`${e}.${r.name}`:r.name,o={...r,name:a};if(!r.hint?.input?.ignore){if(r.type!=="object"){let c=r.hint?.input?.group||"ungrouped";i[c]||(i[c]=[]),i[c].push(o)}if(r.nestedSchema?.id&&t[r.nestedSchema.id]){let c=t[r.nestedSchema.id];Ge(c.fields,a,t,i)}}}}0&&(module.exports={JsonPatchError,MigrationEngine,MigrationError,MigrationErrorCode,SchemaRegistry,applyPatch,calculateNextVersion,compareSemanticVersions,createGitSchemaRegistry,createPatch,createSchemaMigrationHelper,createStandardSchemaValidator,deepMerge,docgen,extractInputFieldGroups,generateSHA256Hash,generateValidationInterface,normalizePath,schemaChangeToPatch,schemaToTypes,serializeParams,sortSemanticVars,validate,validateMigration,validateSchemaChange,validateSchemaDefinition});
|
package/index.d.cts
CHANGED
|
@@ -155,7 +155,7 @@ type LogicalOperator = "and" | "or" | "not" | "nor" | "xor";
|
|
|
155
155
|
/**
|
|
156
156
|
* Basic field types supported by the schema system.
|
|
157
157
|
*/
|
|
158
|
-
type FieldType = "string" | "number" | "boolean" | "array" | "set" | "enum" | "object" | "record" | "dynamic";
|
|
158
|
+
type FieldType = "string" | "number" | "boolean" | "array" | "set" | "enum" | "object" | "record" | "union" | "dynamic";
|
|
159
159
|
/**
|
|
160
160
|
* Index types for optimizing different query patterns.
|
|
161
161
|
*/
|
|
@@ -226,6 +226,12 @@ interface ConstraintGroup<T extends FieldType> {
|
|
|
226
226
|
* Collection of constraints or groups applied at the schema or nested level.
|
|
227
227
|
*/
|
|
228
228
|
type SchemaConstraint<T extends FieldType> = Array<Constraint<T> | ConstraintGroup<T>>;
|
|
229
|
+
/** Reference to a nested schema (mini-SchemaDefinition) with optional overrides. */
|
|
230
|
+
interface FieldSchema {
|
|
231
|
+
id: string;
|
|
232
|
+
constraints?: SchemaConstraint<any>;
|
|
233
|
+
indexes?: IndexDefinition[];
|
|
234
|
+
}
|
|
229
235
|
/**
|
|
230
236
|
* Defines a field within a schema, including its type, constraints, and nesting.
|
|
231
237
|
*/
|
|
@@ -235,14 +241,14 @@ interface FieldDefinition<T> {
|
|
|
235
241
|
required?: boolean;
|
|
236
242
|
constraints?: Constraint<any>[];
|
|
237
243
|
default?: T;
|
|
238
|
-
values
|
|
244
|
+
/** For type 'enum', specifies the allowed values. */
|
|
245
|
+
values?: Array<string | number>;
|
|
246
|
+
/** For type 'union', specifies the array of allowed schemas.
|
|
247
|
+
* For type 'object' specifies the schema of the object
|
|
248
|
+
* */
|
|
249
|
+
schema?: FieldSchema | Array<FieldSchema>;
|
|
239
250
|
itemsType?: FieldType;
|
|
240
|
-
|
|
241
|
-
nestedSchema?: {
|
|
242
|
-
id: string;
|
|
243
|
-
constraints?: SchemaConstraint<any>;
|
|
244
|
-
indexes?: IndexDefinition[];
|
|
245
|
-
};
|
|
251
|
+
nestedSchema?: FieldSchema;
|
|
246
252
|
deprecated?: boolean;
|
|
247
253
|
reference?: {
|
|
248
254
|
schema: string;
|
|
@@ -276,15 +282,50 @@ interface IndexDefinition {
|
|
|
276
282
|
name: string;
|
|
277
283
|
}
|
|
278
284
|
/**
|
|
279
|
-
*
|
|
280
|
-
*
|
|
285
|
+
* Represents a nested schema definition embedded within a parent schema.
|
|
286
|
+
* Unlike SchemaDefinition, this can use a discriminated array of field sets for variant-specific fields,
|
|
287
|
+
* but only when concrete is false. This restriction avoids complexity in RDBMS implementations,
|
|
288
|
+
* where concrete schemas map directly to tables with fixed columns. Non-concrete schemas, as embedded
|
|
289
|
+
* structures, can leverage this flexibility without affecting physical table design.
|
|
281
290
|
*/
|
|
282
291
|
interface NestedSchemaDefinition {
|
|
292
|
+
/**
|
|
293
|
+
* The name of the nested schema, unique within the parent schema's nestedSchemas.
|
|
294
|
+
*/
|
|
283
295
|
name: string;
|
|
296
|
+
/**
|
|
297
|
+
* A description of the nested schema's purpose.
|
|
298
|
+
*/
|
|
284
299
|
description?: string;
|
|
285
|
-
|
|
286
|
-
|
|
300
|
+
/**
|
|
301
|
+
* Indicates whether this schema represents a standalone entity (true) or is embedded (false).
|
|
302
|
+
* When true, fields must be a Record<string, FieldDefinition<any>> to ensure a fixed structure
|
|
303
|
+
* suitable for RDBMS table mapping. When false, fields can be an array of discriminated field sets.
|
|
304
|
+
* @default false
|
|
305
|
+
*/
|
|
306
|
+
concrete?: boolean;
|
|
307
|
+
/**
|
|
308
|
+
* Defines the fields of the nested schema.
|
|
309
|
+
* - If concrete is true, must be a Record<string, FieldDefinition<any>> for a fixed field set.
|
|
310
|
+
* - If concrete is false, can be either a Record<string, FieldDefinition<any>> or an
|
|
311
|
+
* Array<{ fields: Record<string, FieldDefinition<any>>; when?: { field: string; value: any } }>,
|
|
312
|
+
* allowing discriminated field sets based on a field value (e.g., 'type').
|
|
313
|
+
* The array form enables variant-specific fields without constraints, but is not supported for
|
|
314
|
+
* concrete schemas to maintain simplicity in RDBMS table mappings.
|
|
315
|
+
*/
|
|
316
|
+
fields: Record<string, FieldDefinition<any>> | Array<{
|
|
317
|
+
fields: Record<string, FieldDefinition<any>>;
|
|
318
|
+
when?: {
|
|
319
|
+
field: string;
|
|
320
|
+
value: any;
|
|
321
|
+
};
|
|
322
|
+
}>;
|
|
323
|
+
/**
|
|
324
|
+
* Optional constraints for additional validation rules.
|
|
325
|
+
* Less necessary when using discriminated field sets, as variant logic can be structural.
|
|
326
|
+
*/
|
|
287
327
|
constraints?: SchemaConstraint<any>;
|
|
328
|
+
indexes?: IndexDefinition[];
|
|
288
329
|
metadata?: Record<string, any>;
|
|
289
330
|
}
|
|
290
331
|
/**
|
package/index.d.ts
CHANGED
|
@@ -155,7 +155,7 @@ type LogicalOperator = "and" | "or" | "not" | "nor" | "xor";
|
|
|
155
155
|
/**
|
|
156
156
|
* Basic field types supported by the schema system.
|
|
157
157
|
*/
|
|
158
|
-
type FieldType = "string" | "number" | "boolean" | "array" | "set" | "enum" | "object" | "record" | "dynamic";
|
|
158
|
+
type FieldType = "string" | "number" | "boolean" | "array" | "set" | "enum" | "object" | "record" | "union" | "dynamic";
|
|
159
159
|
/**
|
|
160
160
|
* Index types for optimizing different query patterns.
|
|
161
161
|
*/
|
|
@@ -226,6 +226,12 @@ interface ConstraintGroup<T extends FieldType> {
|
|
|
226
226
|
* Collection of constraints or groups applied at the schema or nested level.
|
|
227
227
|
*/
|
|
228
228
|
type SchemaConstraint<T extends FieldType> = Array<Constraint<T> | ConstraintGroup<T>>;
|
|
229
|
+
/** Reference to a nested schema (mini-SchemaDefinition) with optional overrides. */
|
|
230
|
+
interface FieldSchema {
|
|
231
|
+
id: string;
|
|
232
|
+
constraints?: SchemaConstraint<any>;
|
|
233
|
+
indexes?: IndexDefinition[];
|
|
234
|
+
}
|
|
229
235
|
/**
|
|
230
236
|
* Defines a field within a schema, including its type, constraints, and nesting.
|
|
231
237
|
*/
|
|
@@ -235,14 +241,14 @@ interface FieldDefinition<T> {
|
|
|
235
241
|
required?: boolean;
|
|
236
242
|
constraints?: Constraint<any>[];
|
|
237
243
|
default?: T;
|
|
238
|
-
values
|
|
244
|
+
/** For type 'enum', specifies the allowed values. */
|
|
245
|
+
values?: Array<string | number>;
|
|
246
|
+
/** For type 'union', specifies the array of allowed schemas.
|
|
247
|
+
* For type 'object' specifies the schema of the object
|
|
248
|
+
* */
|
|
249
|
+
schema?: FieldSchema | Array<FieldSchema>;
|
|
239
250
|
itemsType?: FieldType;
|
|
240
|
-
|
|
241
|
-
nestedSchema?: {
|
|
242
|
-
id: string;
|
|
243
|
-
constraints?: SchemaConstraint<any>;
|
|
244
|
-
indexes?: IndexDefinition[];
|
|
245
|
-
};
|
|
251
|
+
nestedSchema?: FieldSchema;
|
|
246
252
|
deprecated?: boolean;
|
|
247
253
|
reference?: {
|
|
248
254
|
schema: string;
|
|
@@ -276,15 +282,50 @@ interface IndexDefinition {
|
|
|
276
282
|
name: string;
|
|
277
283
|
}
|
|
278
284
|
/**
|
|
279
|
-
*
|
|
280
|
-
*
|
|
285
|
+
* Represents a nested schema definition embedded within a parent schema.
|
|
286
|
+
* Unlike SchemaDefinition, this can use a discriminated array of field sets for variant-specific fields,
|
|
287
|
+
* but only when concrete is false. This restriction avoids complexity in RDBMS implementations,
|
|
288
|
+
* where concrete schemas map directly to tables with fixed columns. Non-concrete schemas, as embedded
|
|
289
|
+
* structures, can leverage this flexibility without affecting physical table design.
|
|
281
290
|
*/
|
|
282
291
|
interface NestedSchemaDefinition {
|
|
292
|
+
/**
|
|
293
|
+
* The name of the nested schema, unique within the parent schema's nestedSchemas.
|
|
294
|
+
*/
|
|
283
295
|
name: string;
|
|
296
|
+
/**
|
|
297
|
+
* A description of the nested schema's purpose.
|
|
298
|
+
*/
|
|
284
299
|
description?: string;
|
|
285
|
-
|
|
286
|
-
|
|
300
|
+
/**
|
|
301
|
+
* Indicates whether this schema represents a standalone entity (true) or is embedded (false).
|
|
302
|
+
* When true, fields must be a Record<string, FieldDefinition<any>> to ensure a fixed structure
|
|
303
|
+
* suitable for RDBMS table mapping. When false, fields can be an array of discriminated field sets.
|
|
304
|
+
* @default false
|
|
305
|
+
*/
|
|
306
|
+
concrete?: boolean;
|
|
307
|
+
/**
|
|
308
|
+
* Defines the fields of the nested schema.
|
|
309
|
+
* - If concrete is true, must be a Record<string, FieldDefinition<any>> for a fixed field set.
|
|
310
|
+
* - If concrete is false, can be either a Record<string, FieldDefinition<any>> or an
|
|
311
|
+
* Array<{ fields: Record<string, FieldDefinition<any>>; when?: { field: string; value: any } }>,
|
|
312
|
+
* allowing discriminated field sets based on a field value (e.g., 'type').
|
|
313
|
+
* The array form enables variant-specific fields without constraints, but is not supported for
|
|
314
|
+
* concrete schemas to maintain simplicity in RDBMS table mappings.
|
|
315
|
+
*/
|
|
316
|
+
fields: Record<string, FieldDefinition<any>> | Array<{
|
|
317
|
+
fields: Record<string, FieldDefinition<any>>;
|
|
318
|
+
when?: {
|
|
319
|
+
field: string;
|
|
320
|
+
value: any;
|
|
321
|
+
};
|
|
322
|
+
}>;
|
|
323
|
+
/**
|
|
324
|
+
* Optional constraints for additional validation rules.
|
|
325
|
+
* Less necessary when using discriminated field sets, as variant logic can be structural.
|
|
326
|
+
*/
|
|
287
327
|
constraints?: SchemaConstraint<any>;
|
|
328
|
+
indexes?: IndexDefinition[];
|
|
288
329
|
metadata?: Record<string, any>;
|
|
289
330
|
}
|
|
290
331
|
/**
|
package/index.js
CHANGED
|
@@ -64,4 +64,4 @@ ${n.description}
|
|
|
64
64
|
## Migrations
|
|
65
65
|
`),t.push("| ID | Description | Status | Changes |"),t.push("|----|-------------|--------|---------|");for(let a of n.migrations||[])t.push([a.id,a.description,a.status,a.changes.length].join("|"));if(n.mock&&e?.faker)try{let a=n.mock(e.faker).next().value;t.push("\n## Example Data\n```json\n"+JSON.stringify(a,null,2)+"\n```")}catch{t.push(`
|
|
66
66
|
<!-- Error generating mock data -->`)}return t.join(`
|
|
67
|
-
`)}function yn(n){let e={},t={};n.hint?.groups&&n.hint.groups.forEach(s=>{t[s.name]={label:s.label,description:s.description}}),Me(n.fields,"",n.nestedSchemas||{},e);let i=[];for(let[s,r]of Object.entries(e)){let a=s!=="ungrouped"?t[s]:void 0;i.push({name:s!=="ungrouped"?s:"ungrouped",label:a?.label||"Ungrouped",description:a?.description,fields:r})}return i}function Me(n,e,t,i){for(let[s,r]of Object.entries(n)){
|
|
67
|
+
`)}function yn(n){let e={},t={};n.hint?.groups&&n.hint.groups.forEach(s=>{t[s.name]={label:s.label,description:s.description}}),Me(n.fields,"",n.nestedSchemas||{},e);let i=[];for(let[s,r]of Object.entries(e)){let a=s!=="ungrouped"?t[s]:void 0;i.push({name:s!=="ungrouped"?s:"ungrouped",label:a?.label||"Ungrouped",description:a?.description,fields:r})}return i}function Me(n,e,t,i){for(let[s,r]of Object.entries(n)){let a=e?`${e}.${r.name}`:r.name,o={...r,name:a};if(!r.hint?.input?.ignore){if(r.type!=="object"){let c=r.hint?.input?.group||"ungrouped";i[c]||(i[c]=[]),i[c].push(o)}if(r.nestedSchema?.id&&t[r.nestedSchema.id]){let c=t[r.nestedSchema.id];Me(c.fields,a,t,i)}}}}export{P as JsonPatchError,ke as MigrationEngine,x as MigrationError,et as MigrationErrorCode,B as SchemaRegistry,X as applyPatch,De as calculateNextVersion,M as compareSemanticVersions,sn as createGitSchemaRegistry,at as createPatch,tt as createSchemaMigrationHelper,Ue as createStandardSchemaValidator,pe as deepMerge,ln as docgen,yn as extractInputFieldGroups,j as generateSHA256Hash,mn as generateValidationInterface,Oe as normalizePath,me as schemaChangeToPatch,fn as schemaToTypes,J as serializeParams,pt as sortSemanticVars,mt as validate,Ce as validateMigration,Te as validateSchemaChange,q as validateSchemaDefinition};
|