@asaidimu/anansi 2.0.0 → 3.0.0

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 (3) hide show
  1. package/index.d.cts +18 -118
  2. package/index.d.ts +18 -118
  3. package/package.json +1 -1
package/index.d.cts CHANGED
@@ -416,66 +416,6 @@ interface IndexDefinition {
416
416
  * Nested schemas are stored in the `nestedSchemas` map of a `SchemaDefinition` and referenced by their `id`.
417
417
  * They facilitate schema reusability, modularity, and the definition of polymorphic structures.
418
418
  *
419
- * @template T - The TypeScript type this schema represents. When `literal` is `true`, this `T`
420
- * corresponds to the actual primitive type (e.g., `string`, `number`).
421
- * When `literal` is `false`, `T` is typically an object type.
422
- *
423
- * @example
424
- * // Example of a concrete, object-based nested schema (like a fixed address structure)
425
- * ```typescript
426
- * const addressSchema: NestedSchemaDefinition = {
427
- * name: "AddressSchema",
428
- * description: "A concrete schema for geographical addresses.",
429
- * fields: {
430
- * street: { name: "street", type: "string", description: "Street name and number." },
431
- * city: { name: "city", type: "string", description: "City or town." },
432
- * zip: { name: "zip", type: "string", description: "Postal or zip code." }
433
- * },
434
- * concrete: true // Suitable for RDBMS table mapping
435
- * };
436
- * ```
437
- *
438
- * @example
439
- * // Example of a non-concrete, object-based nested schema with discriminated fields (like a contact method)
440
- * ```typescript
441
- * const contactSchema: NestedSchemaDefinition = {
442
- * name: "ContactMethod",
443
- * description: "Represents various contact methods using a discriminated union.",
444
- * fields: [
445
- * {
446
- * fields: {
447
- * type: { name: "type", type: "enum", values: ["email"], required: true },
448
- * email: { name: "email", type: "string", hint: { input: { type: "email" } } }
449
- * },
450
- * when: { field: "type", value: "email" }
451
- * },
452
- * {
453
- * fields: {
454
- * type: { name: "type", type: "enum", values: ["phone"], required: true },
455
- * phone: { name: "phone", type: "string", hint: { input: { type: "tel" } } }
456
- * },
457
- * when: { field: "type", value: "phone" }
458
- * }
459
- * ],
460
- * concrete: false // Allows for discriminated field sets
461
- * };
462
- * ```
463
- *
464
- * @example
465
- * // Example of a literal nested schema (reusable email string definition)
466
- * ```typescript
467
- * const emailStringSchema: NestedSchemaDefinition<string> = {
468
- * name: "EmailAddressString",
469
- * description: "A literal schema for a validated email address string.",
470
- * literal: true,
471
- * type: "string",
472
- * constraints: {
473
- * predicates: {
474
- * matches: "/^[^\s@]+@[^\s@]+\\.[^\s@]+$/" // Regex for email format validation
475
- * }
476
- * }
477
- * };
478
- * ```
479
419
  */
480
420
  type NestedSchemaDefinition<T> = {
481
421
  /**
@@ -489,52 +429,27 @@ type NestedSchemaDefinition<T> = {
489
429
  * This is crucial for documentation and understanding the schema's intent.
490
430
  */
491
431
  description?: string;
492
- } & (
493
- /**
494
- * Defines a literal nested schema.
495
- * When `literal` is `true`, this `NestedSchemaDefinition` represents a direct primitive value
496
- * (string, number, or boolean) rather than an object with fields.
497
- * This is particularly useful for:
498
- * - Defining reusable primitive types with specific constraints (e.g., a regex for an "EmailAddress" string).
499
- * - Enabling direct unions between primitive types and object types within a `FieldDefinition`
500
- * (e.g., `FieldType: "union"`, where one `FieldSchema` references a literal type).
501
- */
502
- {
503
- literal: true;
504
432
  /**
505
- * The basic primitive type that this literal schema represents.
506
- * Must be one of "string", "number", or "boolean".
507
- */
508
- type: "string" | "number" | "boolean";
509
- /**
510
- * An optional default value for this literal schema.
511
- * If provided, the type of `default` must strictly match the `type` specified.
512
- * @example "default@example.com" for type "string"
513
- * @example 0 for type "number"
514
- */
515
- default?: T;
516
- /**
517
- * Optional constraints for additional validation rules specific to this literal type.
518
- * These constraints apply directly to the primitive value.
433
+ * Defines database indexes for the fields within this nested schema.
434
+ * This is primarily applicable when `concrete` is `true`, indicating that the schema
435
+ * maps directly to a persistent data store table. Indexes help optimize data retrieval.
519
436
  */
520
- constraints?: Array<Constraint<any> | ConstraintGroup<any>>;
437
+ indexes?: IndexDefinition[];
521
438
  /**
522
- * Optional generic metadata associated with the literal schema.
523
- * This can store any additional information relevant to tooling or specific domain requirements.
524
- * @example `{ uiComponent: "emailInput", validationMessage: "Invalid email format" }`
439
+ * Optional generic metadata associated with the structured schema.
440
+ * This can store any additional information relevant to tooling, UI generation,
441
+ * or specific domain requirements that are not covered by other properties.
442
+ * @example `{ graphqlType: "Address", apiEndpoint: "/api/addresses" }`
525
443
  */
526
444
  metadata?: Record<string, any>;
527
- } |
528
- /**
529
- * Defines a structured nested schema that represents an object with defined fields.
530
- * This is the traditional way of defining complex data structures within the schema.
531
- */
532
- {
445
+ } & ({
533
446
  /**
534
- * Explicitly indicates that this is a non-literal, structured schema.
535
- * Default value is `false` if omitted.
447
+ * Optional constraints for additional validation rules that apply to the entire structured schema.
448
+ * These constraints provide an extra layer of data integrity beyond basic type checking.
449
+ * They are less strictly necessary when using discriminated field sets (`fields` as an array),
450
+ * as much of the variant logic can be enforced structurally through the `when` clauses.
536
451
  */
537
- literal?: false;
452
+ constraints?: SchemaConstraint<any>;
538
453
  /**
539
454
  * Indicates whether this schema represents a standalone entity (`true`) or is embedded (`false`).
540
455
  * - When `true` (`concrete: true`), the schema is treated as a distinct, fixed-structure entity,
@@ -579,27 +494,12 @@ type NestedSchemaDefinition<T> = {
579
494
  value: any;
580
495
  };
581
496
  }>;
497
+ } | (Pick<FieldDefinition<T>, "name" | "default" | "schema" | "itemsType" | "constraints"> & {
582
498
  /**
583
- * Optional constraints for additional validation rules that apply to the entire structured schema.
584
- * These constraints provide an extra layer of data integrity beyond basic type checking.
585
- * They are less strictly necessary when using discriminated field sets (`fields` as an array),
586
- * as much of the variant logic can be enforced structurally through the `when` clauses.
587
- */
588
- constraints?: SchemaConstraint<any>;
589
- /**
590
- * Defines database indexes for the fields within this nested schema.
591
- * This is primarily applicable when `concrete` is `true`, indicating that the schema
592
- * maps directly to a persistent data store table. Indexes help optimize data retrieval.
593
- */
594
- indexes?: IndexDefinition[];
595
- /**
596
- * Optional generic metadata associated with the structured schema.
597
- * This can store any additional information relevant to tooling, UI generation,
598
- * or specific domain requirements that are not covered by other properties.
599
- * @example `{ graphqlType: "Address", apiEndpoint: "/api/addresses" }`
499
+ * The basic primitive type that this literal schema represents.
600
500
  */
601
- metadata?: Record<string, any>;
602
- });
501
+ type: "string" | "number" | "boolean" | "array" | "set" | "enum" | "record";
502
+ }));
603
503
  /**
604
504
  * Defines a complete schema, intended as an atomic unit within a larger domain model.
605
505
  *
package/index.d.ts CHANGED
@@ -416,66 +416,6 @@ interface IndexDefinition {
416
416
  * Nested schemas are stored in the `nestedSchemas` map of a `SchemaDefinition` and referenced by their `id`.
417
417
  * They facilitate schema reusability, modularity, and the definition of polymorphic structures.
418
418
  *
419
- * @template T - The TypeScript type this schema represents. When `literal` is `true`, this `T`
420
- * corresponds to the actual primitive type (e.g., `string`, `number`).
421
- * When `literal` is `false`, `T` is typically an object type.
422
- *
423
- * @example
424
- * // Example of a concrete, object-based nested schema (like a fixed address structure)
425
- * ```typescript
426
- * const addressSchema: NestedSchemaDefinition = {
427
- * name: "AddressSchema",
428
- * description: "A concrete schema for geographical addresses.",
429
- * fields: {
430
- * street: { name: "street", type: "string", description: "Street name and number." },
431
- * city: { name: "city", type: "string", description: "City or town." },
432
- * zip: { name: "zip", type: "string", description: "Postal or zip code." }
433
- * },
434
- * concrete: true // Suitable for RDBMS table mapping
435
- * };
436
- * ```
437
- *
438
- * @example
439
- * // Example of a non-concrete, object-based nested schema with discriminated fields (like a contact method)
440
- * ```typescript
441
- * const contactSchema: NestedSchemaDefinition = {
442
- * name: "ContactMethod",
443
- * description: "Represents various contact methods using a discriminated union.",
444
- * fields: [
445
- * {
446
- * fields: {
447
- * type: { name: "type", type: "enum", values: ["email"], required: true },
448
- * email: { name: "email", type: "string", hint: { input: { type: "email" } } }
449
- * },
450
- * when: { field: "type", value: "email" }
451
- * },
452
- * {
453
- * fields: {
454
- * type: { name: "type", type: "enum", values: ["phone"], required: true },
455
- * phone: { name: "phone", type: "string", hint: { input: { type: "tel" } } }
456
- * },
457
- * when: { field: "type", value: "phone" }
458
- * }
459
- * ],
460
- * concrete: false // Allows for discriminated field sets
461
- * };
462
- * ```
463
- *
464
- * @example
465
- * // Example of a literal nested schema (reusable email string definition)
466
- * ```typescript
467
- * const emailStringSchema: NestedSchemaDefinition<string> = {
468
- * name: "EmailAddressString",
469
- * description: "A literal schema for a validated email address string.",
470
- * literal: true,
471
- * type: "string",
472
- * constraints: {
473
- * predicates: {
474
- * matches: "/^[^\s@]+@[^\s@]+\\.[^\s@]+$/" // Regex for email format validation
475
- * }
476
- * }
477
- * };
478
- * ```
479
419
  */
480
420
  type NestedSchemaDefinition<T> = {
481
421
  /**
@@ -489,52 +429,27 @@ type NestedSchemaDefinition<T> = {
489
429
  * This is crucial for documentation and understanding the schema's intent.
490
430
  */
491
431
  description?: string;
492
- } & (
493
- /**
494
- * Defines a literal nested schema.
495
- * When `literal` is `true`, this `NestedSchemaDefinition` represents a direct primitive value
496
- * (string, number, or boolean) rather than an object with fields.
497
- * This is particularly useful for:
498
- * - Defining reusable primitive types with specific constraints (e.g., a regex for an "EmailAddress" string).
499
- * - Enabling direct unions between primitive types and object types within a `FieldDefinition`
500
- * (e.g., `FieldType: "union"`, where one `FieldSchema` references a literal type).
501
- */
502
- {
503
- literal: true;
504
432
  /**
505
- * The basic primitive type that this literal schema represents.
506
- * Must be one of "string", "number", or "boolean".
507
- */
508
- type: "string" | "number" | "boolean";
509
- /**
510
- * An optional default value for this literal schema.
511
- * If provided, the type of `default` must strictly match the `type` specified.
512
- * @example "default@example.com" for type "string"
513
- * @example 0 for type "number"
514
- */
515
- default?: T;
516
- /**
517
- * Optional constraints for additional validation rules specific to this literal type.
518
- * These constraints apply directly to the primitive value.
433
+ * Defines database indexes for the fields within this nested schema.
434
+ * This is primarily applicable when `concrete` is `true`, indicating that the schema
435
+ * maps directly to a persistent data store table. Indexes help optimize data retrieval.
519
436
  */
520
- constraints?: Array<Constraint<any> | ConstraintGroup<any>>;
437
+ indexes?: IndexDefinition[];
521
438
  /**
522
- * Optional generic metadata associated with the literal schema.
523
- * This can store any additional information relevant to tooling or specific domain requirements.
524
- * @example `{ uiComponent: "emailInput", validationMessage: "Invalid email format" }`
439
+ * Optional generic metadata associated with the structured schema.
440
+ * This can store any additional information relevant to tooling, UI generation,
441
+ * or specific domain requirements that are not covered by other properties.
442
+ * @example `{ graphqlType: "Address", apiEndpoint: "/api/addresses" }`
525
443
  */
526
444
  metadata?: Record<string, any>;
527
- } |
528
- /**
529
- * Defines a structured nested schema that represents an object with defined fields.
530
- * This is the traditional way of defining complex data structures within the schema.
531
- */
532
- {
445
+ } & ({
533
446
  /**
534
- * Explicitly indicates that this is a non-literal, structured schema.
535
- * Default value is `false` if omitted.
447
+ * Optional constraints for additional validation rules that apply to the entire structured schema.
448
+ * These constraints provide an extra layer of data integrity beyond basic type checking.
449
+ * They are less strictly necessary when using discriminated field sets (`fields` as an array),
450
+ * as much of the variant logic can be enforced structurally through the `when` clauses.
536
451
  */
537
- literal?: false;
452
+ constraints?: SchemaConstraint<any>;
538
453
  /**
539
454
  * Indicates whether this schema represents a standalone entity (`true`) or is embedded (`false`).
540
455
  * - When `true` (`concrete: true`), the schema is treated as a distinct, fixed-structure entity,
@@ -579,27 +494,12 @@ type NestedSchemaDefinition<T> = {
579
494
  value: any;
580
495
  };
581
496
  }>;
497
+ } | (Pick<FieldDefinition<T>, "name" | "default" | "schema" | "itemsType" | "constraints"> & {
582
498
  /**
583
- * Optional constraints for additional validation rules that apply to the entire structured schema.
584
- * These constraints provide an extra layer of data integrity beyond basic type checking.
585
- * They are less strictly necessary when using discriminated field sets (`fields` as an array),
586
- * as much of the variant logic can be enforced structurally through the `when` clauses.
587
- */
588
- constraints?: SchemaConstraint<any>;
589
- /**
590
- * Defines database indexes for the fields within this nested schema.
591
- * This is primarily applicable when `concrete` is `true`, indicating that the schema
592
- * maps directly to a persistent data store table. Indexes help optimize data retrieval.
593
- */
594
- indexes?: IndexDefinition[];
595
- /**
596
- * Optional generic metadata associated with the structured schema.
597
- * This can store any additional information relevant to tooling, UI generation,
598
- * or specific domain requirements that are not covered by other properties.
599
- * @example `{ graphqlType: "Address", apiEndpoint: "/api/addresses" }`
499
+ * The basic primitive type that this literal schema represents.
600
500
  */
601
- metadata?: Record<string, any>;
602
- });
501
+ type: "string" | "number" | "boolean" | "array" | "set" | "enum" | "record";
502
+ }));
603
503
  /**
604
504
  * Defines a complete schema, intended as an atomic unit within a larger domain model.
605
505
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asaidimu/anansi",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "A toolkit for advanced data modelling",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",