@asaidimu/anansi 2.0.0 → 2.1.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.
- package/index.d.cts +8 -66
- package/index.d.ts +8 -66
- package/package.json +1 -1
package/index.d.cts
CHANGED
|
@@ -419,63 +419,6 @@ interface IndexDefinition {
|
|
|
419
419
|
* @template T - The TypeScript type this schema represents. When `literal` is `true`, this `T`
|
|
420
420
|
* corresponds to the actual primitive type (e.g., `string`, `number`).
|
|
421
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
422
|
*/
|
|
480
423
|
type NestedSchemaDefinition<T> = {
|
|
481
424
|
/**
|
|
@@ -489,23 +432,22 @@ type NestedSchemaDefinition<T> = {
|
|
|
489
432
|
* This is crucial for documentation and understanding the schema's intent.
|
|
490
433
|
*/
|
|
491
434
|
description?: string;
|
|
492
|
-
} &
|
|
493
|
-
/**
|
|
435
|
+
} & /**
|
|
494
436
|
* Defines a literal nested schema.
|
|
495
437
|
* When `literal` is `true`, this `NestedSchemaDefinition` represents a direct primitive value
|
|
496
|
-
*
|
|
438
|
+
* rather than an object with fields.
|
|
497
439
|
* This is particularly useful for:
|
|
498
440
|
* - Defining reusable primitive types with specific constraints (e.g., a regex for an "EmailAddress" string).
|
|
499
441
|
* - Enabling direct unions between primitive types and object types within a `FieldDefinition`
|
|
500
442
|
* (e.g., `FieldType: "union"`, where one `FieldSchema` references a literal type).
|
|
501
|
-
*/
|
|
502
|
-
{
|
|
443
|
+
*/ ({
|
|
503
444
|
literal: true;
|
|
504
445
|
/**
|
|
505
446
|
* The basic primitive type that this literal schema represents.
|
|
506
|
-
* Must be one of "string", "number", or "boolean".
|
|
507
447
|
*/
|
|
508
|
-
type: "string" | "number" | "boolean";
|
|
448
|
+
type: "string" | "number" | "boolean" | "array" | "set" | "enum" | "record";
|
|
449
|
+
/** For type 'enum', specifies the allowed values. */
|
|
450
|
+
values?: Array<string | number>;
|
|
509
451
|
/**
|
|
510
452
|
* An optional default value for this literal schema.
|
|
511
453
|
* If provided, the type of `default` must strictly match the `type` specified.
|
|
@@ -524,12 +466,12 @@ type NestedSchemaDefinition<T> = {
|
|
|
524
466
|
* @example `{ uiComponent: "emailInput", validationMessage: "Invalid email format" }`
|
|
525
467
|
*/
|
|
526
468
|
metadata?: Record<string, any>;
|
|
527
|
-
}
|
|
469
|
+
}
|
|
528
470
|
/**
|
|
529
471
|
* Defines a structured nested schema that represents an object with defined fields.
|
|
530
472
|
* This is the traditional way of defining complex data structures within the schema.
|
|
531
473
|
*/
|
|
532
|
-
{
|
|
474
|
+
| {
|
|
533
475
|
/**
|
|
534
476
|
* Explicitly indicates that this is a non-literal, structured schema.
|
|
535
477
|
* Default value is `false` if omitted.
|
package/index.d.ts
CHANGED
|
@@ -419,63 +419,6 @@ interface IndexDefinition {
|
|
|
419
419
|
* @template T - The TypeScript type this schema represents. When `literal` is `true`, this `T`
|
|
420
420
|
* corresponds to the actual primitive type (e.g., `string`, `number`).
|
|
421
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
422
|
*/
|
|
480
423
|
type NestedSchemaDefinition<T> = {
|
|
481
424
|
/**
|
|
@@ -489,23 +432,22 @@ type NestedSchemaDefinition<T> = {
|
|
|
489
432
|
* This is crucial for documentation and understanding the schema's intent.
|
|
490
433
|
*/
|
|
491
434
|
description?: string;
|
|
492
|
-
} &
|
|
493
|
-
/**
|
|
435
|
+
} & /**
|
|
494
436
|
* Defines a literal nested schema.
|
|
495
437
|
* When `literal` is `true`, this `NestedSchemaDefinition` represents a direct primitive value
|
|
496
|
-
*
|
|
438
|
+
* rather than an object with fields.
|
|
497
439
|
* This is particularly useful for:
|
|
498
440
|
* - Defining reusable primitive types with specific constraints (e.g., a regex for an "EmailAddress" string).
|
|
499
441
|
* - Enabling direct unions between primitive types and object types within a `FieldDefinition`
|
|
500
442
|
* (e.g., `FieldType: "union"`, where one `FieldSchema` references a literal type).
|
|
501
|
-
*/
|
|
502
|
-
{
|
|
443
|
+
*/ ({
|
|
503
444
|
literal: true;
|
|
504
445
|
/**
|
|
505
446
|
* The basic primitive type that this literal schema represents.
|
|
506
|
-
* Must be one of "string", "number", or "boolean".
|
|
507
447
|
*/
|
|
508
|
-
type: "string" | "number" | "boolean";
|
|
448
|
+
type: "string" | "number" | "boolean" | "array" | "set" | "enum" | "record";
|
|
449
|
+
/** For type 'enum', specifies the allowed values. */
|
|
450
|
+
values?: Array<string | number>;
|
|
509
451
|
/**
|
|
510
452
|
* An optional default value for this literal schema.
|
|
511
453
|
* If provided, the type of `default` must strictly match the `type` specified.
|
|
@@ -524,12 +466,12 @@ type NestedSchemaDefinition<T> = {
|
|
|
524
466
|
* @example `{ uiComponent: "emailInput", validationMessage: "Invalid email format" }`
|
|
525
467
|
*/
|
|
526
468
|
metadata?: Record<string, any>;
|
|
527
|
-
}
|
|
469
|
+
}
|
|
528
470
|
/**
|
|
529
471
|
* Defines a structured nested schema that represents an object with defined fields.
|
|
530
472
|
* This is the traditional way of defining complex data structures within the schema.
|
|
531
473
|
*/
|
|
532
|
-
{
|
|
474
|
+
| {
|
|
533
475
|
/**
|
|
534
476
|
* Explicitly indicates that this is a non-literal, structured schema.
|
|
535
477
|
* Default value is `false` if omitted.
|