@asaidimu/anansi 1.5.1 → 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 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)){if(r.hint?.input?.ignore)continue;let a=e?`${e}.${r.name}`:r.name,o={...r,name:a},c=r.hint?.input?.group||"ungrouped";if(i[c]||(i[c]=[]),i[c].push(o),r.nestedSchema?.id&&t[r.nestedSchema.id]){let d=t[r.nestedSchema.id];Ge(d.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});
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
@@ -81,7 +81,10 @@ type EnumHint = {
81
81
  label?: string;
82
82
  group?: string;
83
83
  ignore?: boolean;
84
- options?: Array<string | number>;
84
+ options?: Array<{
85
+ value: string | number;
86
+ label: string;
87
+ }>;
85
88
  };
86
89
  /**
87
90
  * Hints for generating an array input control.
@@ -152,7 +155,7 @@ type LogicalOperator = "and" | "or" | "not" | "nor" | "xor";
152
155
  /**
153
156
  * Basic field types supported by the schema system.
154
157
  */
155
- type FieldType = "string" | "number" | "boolean" | "array" | "set" | "enum" | "object" | "record" | "dynamic";
158
+ type FieldType = "string" | "number" | "boolean" | "array" | "set" | "enum" | "object" | "record" | "union" | "dynamic";
156
159
  /**
157
160
  * Index types for optimizing different query patterns.
158
161
  */
@@ -223,6 +226,12 @@ interface ConstraintGroup<T extends FieldType> {
223
226
  * Collection of constraints or groups applied at the schema or nested level.
224
227
  */
225
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
+ }
226
235
  /**
227
236
  * Defines a field within a schema, including its type, constraints, and nesting.
228
237
  */
@@ -232,14 +241,14 @@ interface FieldDefinition<T> {
232
241
  required?: boolean;
233
242
  constraints?: Constraint<any>[];
234
243
  default?: T;
235
- values?: Array<unknown>;
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>;
236
250
  itemsType?: FieldType;
237
- /** Reference to a nested schema (mini-SchemaDefinition) with optional overrides. */
238
- nestedSchema?: {
239
- id: string;
240
- constraints?: SchemaConstraint<any>;
241
- indexes?: IndexDefinition[];
242
- };
251
+ nestedSchema?: FieldSchema;
243
252
  deprecated?: boolean;
244
253
  reference?: {
245
254
  schema: string;
@@ -273,15 +282,50 @@ interface IndexDefinition {
273
282
  name: string;
274
283
  }
275
284
  /**
276
- * A mini-schema definition for reusable nested structures within a larger schema.
277
- * Mirrors SchemaDefinition but omits top-level-only properties like version and migrations.
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.
278
290
  */
279
291
  interface NestedSchemaDefinition {
292
+ /**
293
+ * The name of the nested schema, unique within the parent schema's nestedSchemas.
294
+ */
280
295
  name: string;
296
+ /**
297
+ * A description of the nested schema's purpose.
298
+ */
281
299
  description?: string;
282
- fields: Record<string, FieldDefinition<any>>;
283
- indexes?: IndexDefinition[];
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
+ */
284
327
  constraints?: SchemaConstraint<any>;
328
+ indexes?: IndexDefinition[];
285
329
  metadata?: Record<string, any>;
286
330
  }
287
331
  /**
package/index.d.ts CHANGED
@@ -81,7 +81,10 @@ type EnumHint = {
81
81
  label?: string;
82
82
  group?: string;
83
83
  ignore?: boolean;
84
- options?: Array<string | number>;
84
+ options?: Array<{
85
+ value: string | number;
86
+ label: string;
87
+ }>;
85
88
  };
86
89
  /**
87
90
  * Hints for generating an array input control.
@@ -152,7 +155,7 @@ type LogicalOperator = "and" | "or" | "not" | "nor" | "xor";
152
155
  /**
153
156
  * Basic field types supported by the schema system.
154
157
  */
155
- type FieldType = "string" | "number" | "boolean" | "array" | "set" | "enum" | "object" | "record" | "dynamic";
158
+ type FieldType = "string" | "number" | "boolean" | "array" | "set" | "enum" | "object" | "record" | "union" | "dynamic";
156
159
  /**
157
160
  * Index types for optimizing different query patterns.
158
161
  */
@@ -223,6 +226,12 @@ interface ConstraintGroup<T extends FieldType> {
223
226
  * Collection of constraints or groups applied at the schema or nested level.
224
227
  */
225
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
+ }
226
235
  /**
227
236
  * Defines a field within a schema, including its type, constraints, and nesting.
228
237
  */
@@ -232,14 +241,14 @@ interface FieldDefinition<T> {
232
241
  required?: boolean;
233
242
  constraints?: Constraint<any>[];
234
243
  default?: T;
235
- values?: Array<unknown>;
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>;
236
250
  itemsType?: FieldType;
237
- /** Reference to a nested schema (mini-SchemaDefinition) with optional overrides. */
238
- nestedSchema?: {
239
- id: string;
240
- constraints?: SchemaConstraint<any>;
241
- indexes?: IndexDefinition[];
242
- };
251
+ nestedSchema?: FieldSchema;
243
252
  deprecated?: boolean;
244
253
  reference?: {
245
254
  schema: string;
@@ -273,15 +282,50 @@ interface IndexDefinition {
273
282
  name: string;
274
283
  }
275
284
  /**
276
- * A mini-schema definition for reusable nested structures within a larger schema.
277
- * Mirrors SchemaDefinition but omits top-level-only properties like version and migrations.
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.
278
290
  */
279
291
  interface NestedSchemaDefinition {
292
+ /**
293
+ * The name of the nested schema, unique within the parent schema's nestedSchemas.
294
+ */
280
295
  name: string;
296
+ /**
297
+ * A description of the nested schema's purpose.
298
+ */
281
299
  description?: string;
282
- fields: Record<string, FieldDefinition<any>>;
283
- indexes?: IndexDefinition[];
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
+ */
284
327
  constraints?: SchemaConstraint<any>;
328
+ indexes?: IndexDefinition[];
285
329
  metadata?: Record<string, any>;
286
330
  }
287
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)){if(r.hint?.input?.ignore)continue;let a=e?`${e}.${r.name}`:r.name,o={...r,name:a},c=r.hint?.input?.group||"ungrouped";if(i[c]||(i[c]=[]),i[c].push(o),r.nestedSchema?.id&&t[r.nestedSchema.id]){let d=t[r.nestedSchema.id];Me(d.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};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asaidimu/anansi",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "A toolkit for advanced data modelling",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",