@asaidimu/anansi 1.6.6 → 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/README.md +750 -65
- package/index.cjs +13 -13
- package/index.d.cts +683 -172
- package/index.d.ts +683 -172
- package/index.js +14 -14
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _faker_js_faker from '@faker-js/faker';
|
|
2
2
|
import { Faker } from '@faker-js/faker';
|
|
3
|
-
import { QueryDSL, QueryFilter } from '@asaidimu/query';
|
|
3
|
+
import { LogicalOperator, QueryDSL, QueryFilter } from '@asaidimu/query';
|
|
4
4
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
5
|
import LightningFS from '@isomorphic-git/lightning-fs';
|
|
6
6
|
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
@@ -172,10 +172,6 @@ type SchemaHint = {
|
|
|
172
172
|
groups?: GroupDefinition[];
|
|
173
173
|
};
|
|
174
174
|
|
|
175
|
-
/**
|
|
176
|
-
* Logical operators for combining constraints or index conditions.
|
|
177
|
-
*/
|
|
178
|
-
type LogicalOperator = "and" | "or" | "not" | "nor" | "xor";
|
|
179
175
|
/**
|
|
180
176
|
* Basic field types supported by the schema system.
|
|
181
177
|
*/
|
|
@@ -415,73 +411,137 @@ interface IndexDefinition {
|
|
|
415
411
|
name: string;
|
|
416
412
|
}
|
|
417
413
|
/**
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
* structures, can leverage this flexibility without affecting physical table design.
|
|
423
|
-
*
|
|
424
|
-
* @example
|
|
425
|
-
* ```typescript
|
|
426
|
-
* const addressSchema: NestedSchemaDefinition = {
|
|
427
|
-
* name: "address",
|
|
428
|
-
* fields: {
|
|
429
|
-
* street: { name: "street", type: "string" },
|
|
430
|
-
* city: { name: "city", type: "string" },
|
|
431
|
-
* zip: { name: "zip", type: "string" }
|
|
432
|
-
* },
|
|
433
|
-
* concrete: true
|
|
434
|
-
* };
|
|
414
|
+
* Defines a reusable nested schema structure.
|
|
415
|
+
* This can represent either a complex object with defined fields, or a direct primitive literal (string, number, boolean).
|
|
416
|
+
* Nested schemas are stored in the `nestedSchemas` map of a `SchemaDefinition` and referenced by their `id`.
|
|
417
|
+
* They facilitate schema reusability, modularity, and the definition of polymorphic structures.
|
|
435
418
|
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
* { fields: { email: { name: "email", type: "string" } }, when: { field: "type", value: "email" } },
|
|
440
|
-
* { fields: { phone: { name: "phone", type: "string" } }, when: { field: "type", value: "phone" } }
|
|
441
|
-
* ]
|
|
442
|
-
* };
|
|
443
|
-
* ```
|
|
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.
|
|
444
422
|
*/
|
|
445
|
-
|
|
423
|
+
type NestedSchemaDefinition<T> = {
|
|
446
424
|
/**
|
|
447
|
-
* The name of the nested schema
|
|
425
|
+
* The unique name or identifier of the nested schema within the parent schema's `nestedSchemas` map.
|
|
426
|
+
* This `name` is used by `FieldDefinition.schema.id` to reference this nested schema.
|
|
427
|
+
* @example "AddressSchema" or "EmailString"
|
|
448
428
|
*/
|
|
449
429
|
name: string;
|
|
450
430
|
/**
|
|
451
|
-
* A description of the nested schema's purpose.
|
|
431
|
+
* A clear and concise description of the nested schema's purpose, structure, or expected data.
|
|
432
|
+
* This is crucial for documentation and understanding the schema's intent.
|
|
452
433
|
*/
|
|
453
434
|
description?: string;
|
|
435
|
+
} & /**
|
|
436
|
+
* Defines a literal nested schema.
|
|
437
|
+
* When `literal` is `true`, this `NestedSchemaDefinition` represents a direct primitive value
|
|
438
|
+
* rather than an object with fields.
|
|
439
|
+
* This is particularly useful for:
|
|
440
|
+
* - Defining reusable primitive types with specific constraints (e.g., a regex for an "EmailAddress" string).
|
|
441
|
+
* - Enabling direct unions between primitive types and object types within a `FieldDefinition`
|
|
442
|
+
* (e.g., `FieldType: "union"`, where one `FieldSchema` references a literal type).
|
|
443
|
+
*/ ({
|
|
444
|
+
literal: true;
|
|
445
|
+
/**
|
|
446
|
+
* The basic primitive type that this literal schema represents.
|
|
447
|
+
*/
|
|
448
|
+
type: "string" | "number" | "boolean" | "array" | "set" | "enum" | "record";
|
|
449
|
+
/** For type 'enum', specifies the allowed values. */
|
|
450
|
+
values?: Array<string | number>;
|
|
451
|
+
/**
|
|
452
|
+
* An optional default value for this literal schema.
|
|
453
|
+
* If provided, the type of `default` must strictly match the `type` specified.
|
|
454
|
+
* @example "default@example.com" for type "string"
|
|
455
|
+
* @example 0 for type "number"
|
|
456
|
+
*/
|
|
457
|
+
default?: T;
|
|
454
458
|
/**
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
|
|
459
|
+
* Optional constraints for additional validation rules specific to this literal type.
|
|
460
|
+
* These constraints apply directly to the primitive value.
|
|
461
|
+
*/
|
|
462
|
+
constraints?: Array<Constraint<any> | ConstraintGroup<any>>;
|
|
463
|
+
/**
|
|
464
|
+
* Optional generic metadata associated with the literal schema.
|
|
465
|
+
* This can store any additional information relevant to tooling or specific domain requirements.
|
|
466
|
+
* @example `{ uiComponent: "emailInput", validationMessage: "Invalid email format" }`
|
|
467
|
+
*/
|
|
468
|
+
metadata?: Record<string, any>;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Defines a structured nested schema that represents an object with defined fields.
|
|
472
|
+
* This is the traditional way of defining complex data structures within the schema.
|
|
473
|
+
*/
|
|
474
|
+
| {
|
|
475
|
+
/**
|
|
476
|
+
* Explicitly indicates that this is a non-literal, structured schema.
|
|
477
|
+
* Default value is `false` if omitted.
|
|
478
|
+
*/
|
|
479
|
+
literal?: false;
|
|
480
|
+
/**
|
|
481
|
+
* Indicates whether this schema represents a standalone entity (`true`) or is embedded (`false`).
|
|
482
|
+
* - When `true` (`concrete: true`), the schema is treated as a distinct, fixed-structure entity,
|
|
483
|
+
* often suitable for direct mapping to RDBMS tables. In this case, `fields` *must* be a
|
|
484
|
+
* `Record<string, FieldDefinition<any>>` to ensure a consistent, non-polymorphic structure.
|
|
485
|
+
* - When `false` (`concrete: false` or omitted), the schema is considered embedded or polymorphic.
|
|
486
|
+
* `fields` can be either a `Record<string, FieldDefinition<any>>` (for a fixed embedded object)
|
|
487
|
+
* or an `Array<{ fields: Record<string, FieldDefinition<any>>; when?: { field: string; value: any } }>`,
|
|
488
|
+
* allowing discriminated field sets based on a specific field's value (e.g., a 'type' field).
|
|
489
|
+
* The array form enables defining variants within a single schema without imposing strict concrete
|
|
490
|
+
* constraints, but is not supported for `concrete: true` schemas to maintain simplicity in RDBMS table mappings.
|
|
458
491
|
* @default false
|
|
459
492
|
*/
|
|
460
493
|
concrete?: boolean;
|
|
461
494
|
/**
|
|
462
|
-
* Defines the fields
|
|
463
|
-
*
|
|
464
|
-
* - If concrete is
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
495
|
+
* Defines the fields (properties) that constitute this nested schema.
|
|
496
|
+
* The structure of `fields` depends on the `concrete` property:
|
|
497
|
+
* - If `concrete` is `true`, `fields` must be a `Record<string, FieldDefinition<any>>`
|
|
498
|
+
* to define a fixed set of named fields (e.g., for a database table).
|
|
499
|
+
* - If `concrete` is `false` (or omitted), `fields` can be:
|
|
500
|
+
* - A `Record<string, FieldDefinition<any>>` for a simple, embedded object.
|
|
501
|
+
* - An `Array<{ fields: Record<string, FieldDefinition<any>>; when?: { field: string; value: any } }>`
|
|
502
|
+
* to define a discriminated union or polymorphic structure. Each object in the array defines a
|
|
503
|
+
* set of fields that apply `when` a specified `field` (within this schema's own fields)
|
|
504
|
+
* has a particular `value`. This allows for variant-specific fields.
|
|
469
505
|
*/
|
|
470
506
|
fields: Record<string, FieldDefinition<any>> | Array<{
|
|
507
|
+
/**
|
|
508
|
+
* A set of field definitions that apply when the `when` condition is met.
|
|
509
|
+
*/
|
|
471
510
|
fields: Record<string, FieldDefinition<any>>;
|
|
511
|
+
/**
|
|
512
|
+
* An optional condition that makes this set of fields active.
|
|
513
|
+
* This object specifies a `field` (its name within this schema) and a `value`.
|
|
514
|
+
* When the specified `field` in the data matches this `value`, these `fields` are considered active.
|
|
515
|
+
* Used for discriminated unions or polymorphic structures (e.g., `when: { field: "type", value: "car" }`).
|
|
516
|
+
* If `when` is omitted for an entry in the array, those fields are always present in the union's base,
|
|
517
|
+
* or it acts as a fallback if no other `when` condition matches.
|
|
518
|
+
*/
|
|
472
519
|
when?: {
|
|
473
520
|
field: string;
|
|
474
521
|
value: any;
|
|
475
522
|
};
|
|
476
523
|
}>;
|
|
477
524
|
/**
|
|
478
|
-
* Optional constraints for additional validation rules.
|
|
479
|
-
*
|
|
525
|
+
* Optional constraints for additional validation rules that apply to the entire structured schema.
|
|
526
|
+
* These constraints provide an extra layer of data integrity beyond basic type checking.
|
|
527
|
+
* They are less strictly necessary when using discriminated field sets (`fields` as an array),
|
|
528
|
+
* as much of the variant logic can be enforced structurally through the `when` clauses.
|
|
480
529
|
*/
|
|
481
530
|
constraints?: SchemaConstraint<any>;
|
|
531
|
+
/**
|
|
532
|
+
* Defines database indexes for the fields within this nested schema.
|
|
533
|
+
* This is primarily applicable when `concrete` is `true`, indicating that the schema
|
|
534
|
+
* maps directly to a persistent data store table. Indexes help optimize data retrieval.
|
|
535
|
+
*/
|
|
482
536
|
indexes?: IndexDefinition[];
|
|
537
|
+
/**
|
|
538
|
+
* Optional generic metadata associated with the structured schema.
|
|
539
|
+
* This can store any additional information relevant to tooling, UI generation,
|
|
540
|
+
* or specific domain requirements that are not covered by other properties.
|
|
541
|
+
* @example `{ graphqlType: "Address", apiEndpoint: "/api/addresses" }`
|
|
542
|
+
*/
|
|
483
543
|
metadata?: Record<string, any>;
|
|
484
|
-
}
|
|
544
|
+
});
|
|
485
545
|
/**
|
|
486
546
|
* Defines a complete schema, intended as an atomic unit within a larger domain model.
|
|
487
547
|
*
|
|
@@ -519,7 +579,7 @@ interface SchemaDefinition {
|
|
|
519
579
|
description?: string;
|
|
520
580
|
fields: Record<string, FieldDefinition<any>>;
|
|
521
581
|
/** Reusable nested schema definitions, now as mini-SchemaDefinitions. */
|
|
522
|
-
nestedSchemas
|
|
582
|
+
nestedSchemas?: Record<string, NestedSchemaDefinition<any>>;
|
|
523
583
|
indexes?: IndexDefinition[];
|
|
524
584
|
constraints?: SchemaConstraint<any>;
|
|
525
585
|
metadata?: Record<string, any>;
|
|
@@ -598,14 +658,14 @@ type SchemaChange<T> = {
|
|
|
598
658
|
} | {
|
|
599
659
|
type: "addNestedSchema";
|
|
600
660
|
id: string;
|
|
601
|
-
definition: NestedSchemaDefinition
|
|
661
|
+
definition: NestedSchemaDefinition<any>;
|
|
602
662
|
} | {
|
|
603
663
|
type: "removeNestedSchema";
|
|
604
664
|
id: string;
|
|
605
665
|
} | {
|
|
606
666
|
type: "modifyNestedSchema";
|
|
607
667
|
id: string;
|
|
608
|
-
changes: Partial<NestedSchemaDefinition
|
|
668
|
+
changes: Partial<NestedSchemaDefinition<any>>;
|
|
609
669
|
};
|
|
610
670
|
/**
|
|
611
671
|
* Defines a transform function for data migration between schema versions.
|
|
@@ -962,7 +1022,7 @@ interface SchemaMigrationHelper {
|
|
|
962
1022
|
* @param {string} schemaId - The ID of the nested schema to add.
|
|
963
1023
|
* @param {NestedSchemaDefinition} nestedDefinition - The definition of the nested schema to add.
|
|
964
1024
|
*/
|
|
965
|
-
addNestedSchema(schemaId: string, nestedDefinition: NestedSchemaDefinition): void;
|
|
1025
|
+
addNestedSchema(schemaId: string, nestedDefinition: NestedSchemaDefinition<any>): void;
|
|
966
1026
|
/**
|
|
967
1027
|
* Removes a nested schema from the schema.
|
|
968
1028
|
* @param {string} schemaId - The ID of the nested schema to remove.
|
|
@@ -973,7 +1033,7 @@ interface SchemaMigrationHelper {
|
|
|
973
1033
|
* @param {string} schemaId - The ID of the nested schema to modify.
|
|
974
1034
|
* @param {Partial<NestedSchemaDefinition>} changes - The changes to apply to the nested schema.
|
|
975
1035
|
*/
|
|
976
|
-
modifyNestedSchema(schemaId: string, changes: Partial<NestedSchemaDefinition
|
|
1036
|
+
modifyNestedSchema(schemaId: string, changes: Partial<NestedSchemaDefinition<any>>): void;
|
|
977
1037
|
/**
|
|
978
1038
|
* Returns the list of changes made through this helper.
|
|
979
1039
|
* @returns An array of schema changes.
|
|
@@ -984,185 +1044,635 @@ interface SchemaMigrationHelper {
|
|
|
984
1044
|
};
|
|
985
1045
|
}
|
|
986
1046
|
|
|
1047
|
+
/**
|
|
1048
|
+
* Defines the possible event types for persistence operations.
|
|
1049
|
+
*/
|
|
1050
|
+
type PersistenceEventType = "create:start" | "create:success" | "create:failed" | "read:start" | "read:success" | "read:failed" | "migrate:start" | "migrate:success" | "migrate:failed" | "rollback:start" | "rollback:success" | "rollback:failed" | "update:start" | "update:success" | "update:failed" | "delete:start" | "delete:success" | "delete:failed" | "transaction:start" | "transaction:success" | "transaction:failed" | "telemetry" | "collection:create:start" | "collection:create:success" | "collection:create:failed" | "collection:delete:start" | "collection:delete:success" | "collection:delete:failed" | "subscription:register" | "subscription:unregister" | "trigger:register" | "trigger:unregister" | "trigger:execute" | "trigger:failed" | "task:register" | "task:unregister" | "task:start" | "task:success" | "task:failed" | "metadata:called";
|
|
1051
|
+
/**
|
|
1052
|
+
* Interface representing events emitted during persistence operations.
|
|
1053
|
+
*/
|
|
1054
|
+
interface PersistenceEvent<DataType> {
|
|
1055
|
+
/** The type of event (e.g., 'create:start', 'trigger:execute'). */
|
|
1056
|
+
type: PersistenceEventType;
|
|
1057
|
+
/** Timestamp when the event occurred. */
|
|
1058
|
+
timestamp: number;
|
|
1059
|
+
/** The operation being performed (e.g., 'create', 'trigger'). */
|
|
1060
|
+
operation: string;
|
|
1061
|
+
/** Name of the collection affected by the operation (if applicable). */
|
|
1062
|
+
collection?: string;
|
|
1063
|
+
/** Data passed to the operation (if applicable). */
|
|
1064
|
+
input?: any;
|
|
1065
|
+
/** Data returned by the operation (if applicable). */
|
|
1066
|
+
output?: any;
|
|
1067
|
+
/** Error object if the operation failed (if applicable). */
|
|
1068
|
+
error?: Error;
|
|
1069
|
+
/** Issues that caused the operation to fail (if applicable). */
|
|
1070
|
+
issues?: Array<StandardSchemaV1.Issue>;
|
|
1071
|
+
/** Query used in the operation (if applicable). */
|
|
1072
|
+
query?: QueryDSL<DataType, any>;
|
|
1073
|
+
/** Identifier for the transaction (if part of one). */
|
|
1074
|
+
transactionId?: string;
|
|
1075
|
+
/** Duration of the operation in milliseconds. */
|
|
1076
|
+
duration?: number;
|
|
1077
|
+
/** Additional context or metadata specific to the operation. */
|
|
1078
|
+
context?: Record<string, any>;
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Describes a subscription configuration.
|
|
1082
|
+
*/
|
|
1083
|
+
interface SubscriptionInfo {
|
|
1084
|
+
/** The event subscribed to. */
|
|
1085
|
+
event: PersistenceEventType;
|
|
1086
|
+
/** Unique identifier for the callback. */
|
|
1087
|
+
callbackId: string;
|
|
1088
|
+
/** Optional short identifier (max 50 chars, unique within scope). */
|
|
1089
|
+
label?: string;
|
|
1090
|
+
/** Optional description of the subscription's purpose (max 500 chars). */
|
|
1091
|
+
description?: string;
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* Describes a trigger configuration.
|
|
1095
|
+
*/
|
|
1096
|
+
interface TriggerInfo<T, FunctionMap = Record<string, any>> {
|
|
1097
|
+
/** The event(s) or pattern triggering the callback. */
|
|
1098
|
+
event: PersistenceEventType | PersistenceEventType[] | `${string}:*`;
|
|
1099
|
+
/** Optional condition for the trigger. */
|
|
1100
|
+
condition?: QueryFilter<T, FunctionMap>;
|
|
1101
|
+
/** Unique identifier for the callback. */
|
|
1102
|
+
callbackId: string;
|
|
1103
|
+
/** Whether the trigger executes synchronously. */
|
|
1104
|
+
isSync: boolean;
|
|
1105
|
+
/** Short identifier (max 50 chars, unique within scope). */
|
|
1106
|
+
label: string;
|
|
1107
|
+
/** Description of the trigger's purpose (max 500 chars). */
|
|
1108
|
+
description: string;
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Describes a scheduled task configuration.
|
|
1112
|
+
*/
|
|
1113
|
+
interface TaskInfo {
|
|
1114
|
+
/** Unique identifier for the task. */
|
|
1115
|
+
id: string;
|
|
1116
|
+
/** Schedule for task execution. */
|
|
1117
|
+
schedule: TaskSchedule;
|
|
1118
|
+
/** Unique identifier for the callback. */
|
|
1119
|
+
callbackId: string;
|
|
1120
|
+
/** Whether the task executes synchronously. */
|
|
1121
|
+
isSync: boolean;
|
|
1122
|
+
/** Optional metadata for logging or telemetry. */
|
|
1123
|
+
metadata?: Record<string, any>;
|
|
1124
|
+
/** Short identifier (max 50 chars, unique within scope). */
|
|
1125
|
+
label: string;
|
|
1126
|
+
/** Description of the task's purpose (max 500 chars). */
|
|
1127
|
+
description: string;
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Filter criteria for metadata queries.
|
|
1131
|
+
*/
|
|
1132
|
+
interface MetadataFilter {
|
|
1133
|
+
/** Filter for subscriptions. */
|
|
1134
|
+
subscriptions?: {
|
|
1135
|
+
event?: PersistenceEventType | PersistenceEventType[];
|
|
1136
|
+
label?: string;
|
|
1137
|
+
};
|
|
1138
|
+
/** Filter for triggers. */
|
|
1139
|
+
triggers?: {
|
|
1140
|
+
event?: PersistenceEventType | PersistenceEventType[] | `${string}:*`;
|
|
1141
|
+
label?: string;
|
|
1142
|
+
};
|
|
1143
|
+
/** Filter for tasks. */
|
|
1144
|
+
tasks?: {
|
|
1145
|
+
id?: string;
|
|
1146
|
+
metadata?: Record<string, any>;
|
|
1147
|
+
label?: string;
|
|
1148
|
+
};
|
|
1149
|
+
/** Filter for schemas. */
|
|
1150
|
+
schemas?: {
|
|
1151
|
+
id?: string;
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
/**
|
|
1155
|
+
* Metadata for a single collection.
|
|
1156
|
+
*/
|
|
1157
|
+
interface CollectionMetadata<T, FunctionMap = Record<string, any>> {
|
|
1158
|
+
/** Collection identifier. */
|
|
1159
|
+
id: string;
|
|
1160
|
+
/** Active subscriptions for the collection. */
|
|
1161
|
+
subscriptions: SubscriptionInfo[];
|
|
1162
|
+
/** Active triggers for the collection. */
|
|
1163
|
+
triggers: TriggerInfo<T, FunctionMap>[];
|
|
1164
|
+
/** Scheduled tasks for the collection. */
|
|
1165
|
+
tasks: TaskInfo[];
|
|
1166
|
+
/** Number of records in the collection. */
|
|
1167
|
+
recordCount: number;
|
|
1168
|
+
/** Storage used by the collection in bytes. */
|
|
1169
|
+
dataSizeBytes: number;
|
|
1170
|
+
/** Schema definition for the collection. */
|
|
1171
|
+
schema: SchemaDefinition;
|
|
1172
|
+
/** Timestamp of the last operation on the collection. */
|
|
1173
|
+
lastModified: number;
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Metadata for Persistence or PersistenceCollection.
|
|
1177
|
+
*/
|
|
1178
|
+
interface Metadata<T, FunctionMap = Record<string, any>> {
|
|
1179
|
+
/** Active subscriptions. */
|
|
1180
|
+
subscriptions: SubscriptionInfo[];
|
|
1181
|
+
/** Active triggers. */
|
|
1182
|
+
triggers: TriggerInfo<T, FunctionMap>[];
|
|
1183
|
+
/** Scheduled tasks. */
|
|
1184
|
+
tasks: TaskInfo[];
|
|
1185
|
+
/** Number of collections (Persistence only). */
|
|
1186
|
+
collectionCount?: number;
|
|
1187
|
+
/** Total storage used by all collections in bytes (Persistence only). */
|
|
1188
|
+
storageUsageBytes?: number;
|
|
1189
|
+
/** Database connection status (Persistence only). */
|
|
1190
|
+
connectionStatus?: "connected" | "disconnected" | "error";
|
|
1191
|
+
/** Database connection error, if any (Persistence only). */
|
|
1192
|
+
connectionError?: string | null;
|
|
1193
|
+
/** Schema definitions for all collections, if requested (Persistence only). */
|
|
1194
|
+
schemas?: SchemaDefinition[];
|
|
1195
|
+
/** Per-collection metadata, if requested (Persistence only). */
|
|
1196
|
+
collections?: CollectionMetadata<any, FunctionMap>[];
|
|
1197
|
+
/** Number of records in the collection (PersistenceCollection only). */
|
|
1198
|
+
recordCount?: number;
|
|
1199
|
+
/** Storage used by the collection in bytes (PersistenceCollection only). */
|
|
1200
|
+
dataSizeBytes?: number;
|
|
1201
|
+
/** Schema definition for the collection (PersistenceCollection only). */
|
|
1202
|
+
schema?: SchemaDefinition;
|
|
1203
|
+
/** Timestamp of the last operation on the collection (PersistenceCollection only). */
|
|
1204
|
+
lastModified?: number;
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Interface for querying observability data.
|
|
1208
|
+
*/
|
|
1209
|
+
interface ObservabilityInterface<T, FunctionMap = Record<string, any>> {
|
|
1210
|
+
/**
|
|
1211
|
+
* Returns metadata about active subscriptions, triggers, tasks, and system state.
|
|
1212
|
+
* @param filter Optional filter to limit returned data (e.g., by event or label).
|
|
1213
|
+
* @param includeCollections For Persistence, whether to include per-collection metadata.
|
|
1214
|
+
* @param includeSchemas For Persistence, whether to include schema definitions.
|
|
1215
|
+
* @param forceRefresh Whether to force real-time queries for storageUsageBytes and dataSizeBytes.
|
|
1216
|
+
* @returns Metadata object containing observability data.
|
|
1217
|
+
* @example
|
|
1218
|
+
* // Collection metadata with label filter
|
|
1219
|
+
* const metadata = collection.metadata({ triggers: { label: "user-*" } });
|
|
1220
|
+
* console.log(metadata.triggers); // Triggers with label "user-*"
|
|
1221
|
+
* console.log(metadata.dataSizeBytes); // Storage used
|
|
1222
|
+
*
|
|
1223
|
+
* // Persistence metadata
|
|
1224
|
+
* const globalMetadata = persistence.metadata({ includeCollections: true });
|
|
1225
|
+
* console.log(globalMetadata.storageUsageBytes); // Total storage
|
|
1226
|
+
* console.log(globalMetadata.collections); // Per-collection metadata
|
|
1227
|
+
*/
|
|
1228
|
+
metadata(filter?: MetadataFilter, includeCollections?: boolean, includeSchemas?: boolean, forceRefresh?: boolean): Metadata<T, FunctionMap>;
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* Interface for event handling and task scheduling.
|
|
1232
|
+
*/
|
|
1233
|
+
interface EventTaskInterface<T, FunctionMap = Record<string, any>> {
|
|
1234
|
+
/**
|
|
1235
|
+
* Subscribes to persistence events.
|
|
1236
|
+
* @param event The event to subscribe to.
|
|
1237
|
+
* @param callback The callback to handle the event.
|
|
1238
|
+
* @param options Optional label and description for the subscription.
|
|
1239
|
+
* @returns A function to unsubscribe from the event.
|
|
1240
|
+
* @example
|
|
1241
|
+
* const unsubscribe = persistence.subscribe("telemetry", (event) => {
|
|
1242
|
+
* console.log(event);
|
|
1243
|
+
* }, { label: "telemetry-log", description: "Logs telemetry events" });
|
|
1244
|
+
* unsubscribe();
|
|
1245
|
+
*/
|
|
1246
|
+
subscribe(event: PersistenceEventType, callback: (payload: PersistenceEvent<T>) => void, options?: {
|
|
1247
|
+
label?: string;
|
|
1248
|
+
description?: string;
|
|
1249
|
+
}): () => void;
|
|
1250
|
+
/**
|
|
1251
|
+
* Registers a trigger callback for specific events.
|
|
1252
|
+
* @param config Configuration including event, callback, label, description, and options.
|
|
1253
|
+
* @returns A function to unsubscribe the trigger.
|
|
1254
|
+
* @example
|
|
1255
|
+
* collection.trigger("create:success",
|
|
1256
|
+
* ({ collection, results }) => {
|
|
1257
|
+
* console.log(`Created: ${results.id}`);
|
|
1258
|
+
* },
|
|
1259
|
+
* {
|
|
1260
|
+
* label: "user-create-hook",
|
|
1261
|
+
* description: "Syncs new users with CRM",
|
|
1262
|
+
* sync: true
|
|
1263
|
+
* });
|
|
1264
|
+
*/
|
|
1265
|
+
trigger(event: PersistenceEventType | PersistenceEventType[] | `${string}:*`, callback: (context: TriggerContext<T, FunctionMap>) => void | Promise<void>, options: {
|
|
1266
|
+
condition?: QueryFilter<T, FunctionMap>;
|
|
1267
|
+
sync?: boolean;
|
|
1268
|
+
label: string;
|
|
1269
|
+
description: string;
|
|
1270
|
+
}): () => void;
|
|
1271
|
+
/**
|
|
1272
|
+
* Schedules a task to run at specified times or intervals.
|
|
1273
|
+
* @param config Configuration including ID, schedule, callback, label, description, and options.
|
|
1274
|
+
* @returns A function to cancel the scheduled task.
|
|
1275
|
+
* @example
|
|
1276
|
+
* collection.schedule({
|
|
1277
|
+
* id: "cleanup-inactive",
|
|
1278
|
+
* label: "inactive-cleanup",
|
|
1279
|
+
* description: "Deletes inactive records hourly",
|
|
1280
|
+
* schedule: { cron: "0 * * * *" },
|
|
1281
|
+
* callback: ({ collection }) => {
|
|
1282
|
+
* collection.delete({ query: { filter: { status: { $eq: "inactive" } } } });
|
|
1283
|
+
* }
|
|
1284
|
+
* });
|
|
1285
|
+
*/
|
|
1286
|
+
schedule(config: {
|
|
1287
|
+
id: string;
|
|
1288
|
+
schedule: TaskSchedule;
|
|
1289
|
+
callback: (context: TaskContext<T, FunctionMap>) => void | Promise<void>;
|
|
1290
|
+
sync?: boolean;
|
|
1291
|
+
metadata?: Record<string, any>;
|
|
1292
|
+
label: string;
|
|
1293
|
+
description: string;
|
|
1294
|
+
}): () => void;
|
|
1295
|
+
}
|
|
987
1296
|
/**
|
|
988
1297
|
* Interface defining persistence operations for data management.
|
|
989
|
-
* Provides methods for CRUD operations, transactions, validation, and event subscription.
|
|
990
|
-
*
|
|
991
|
-
* @generic DataType - The type of data being persisted.
|
|
992
|
-
* @generic FunctionMap - A map of functions used in the persistence operations (default: Record<string, any>).
|
|
993
1298
|
*/
|
|
994
|
-
interface Persistence<FunctionMap> {
|
|
1299
|
+
interface Persistence<FunctionMap = Record<string, any>> extends ObservabilityInterface<any, FunctionMap>, EventTaskInterface<any, FunctionMap> {
|
|
995
1300
|
/**
|
|
996
|
-
* Returns a list of all
|
|
997
|
-
* @returns A promise that resolves to
|
|
1301
|
+
* Returns a list of all collection names.
|
|
1302
|
+
* @returns A promise that resolves to an array of collection names.
|
|
998
1303
|
*/
|
|
999
1304
|
collections(): Promise<Array<string>>;
|
|
1000
1305
|
/**
|
|
1001
1306
|
* Creates a new collection with the specified schema.
|
|
1002
|
-
* @param schema
|
|
1003
|
-
* @returns A promise that resolves
|
|
1307
|
+
* @param schema The schema definition for the new collection.
|
|
1308
|
+
* @returns A promise that resolves to the created PersistenceCollection.
|
|
1004
1309
|
*/
|
|
1005
|
-
|
|
1310
|
+
create<T>(schema: SchemaDefinition): Promise<PersistenceCollection<T, FunctionMap>>;
|
|
1006
1311
|
/**
|
|
1007
1312
|
* Deletes the specified collection.
|
|
1008
|
-
* @param id
|
|
1009
|
-
* @returns A promise that resolves
|
|
1313
|
+
* @param id The ID of the collection to delete.
|
|
1314
|
+
* @returns A promise that resolves indicating whether the collection was deleted.
|
|
1010
1315
|
*/
|
|
1011
|
-
|
|
1316
|
+
delete(id: string): Promise<boolean>;
|
|
1012
1317
|
/**
|
|
1013
1318
|
* Retrieves the schema definition for the specified collection.
|
|
1014
|
-
* @param id
|
|
1015
|
-
* @returns A promise that resolves to the schema definition
|
|
1319
|
+
* @param id The ID of the collection.
|
|
1320
|
+
* @returns A promise that resolves to the schema definition.
|
|
1016
1321
|
*/
|
|
1017
1322
|
schema(id: string): Promise<SchemaDefinition>;
|
|
1018
1323
|
/**
|
|
1019
|
-
* Returns
|
|
1020
|
-
*
|
|
1324
|
+
* Returns a PersistenceCollection instance for interacting with a collection.
|
|
1325
|
+
* @param id The ID of the collection.
|
|
1326
|
+
* @returns The PersistenceCollection instance.
|
|
1021
1327
|
*/
|
|
1022
1328
|
collection<T>(id: string): PersistenceCollection<T, FunctionMap>;
|
|
1023
|
-
/**
|
|
1024
|
-
* Subscribe to persistence events
|
|
1025
|
-
* @param event - The event to subscribe to
|
|
1026
|
-
* @param callback - A callback to handle the event
|
|
1027
|
-
* @returns A callback that can be used to unsubscribe from the event
|
|
1028
|
-
*/
|
|
1029
|
-
subscribe(event: PersistenceEventType, callback: (payload: PersistenceEvent<any>) => void): () => void;
|
|
1030
1329
|
/**
|
|
1031
1330
|
* Executes a transaction with multiple operations.
|
|
1032
|
-
* @param callback A function that receives a PersistenceTransaction object
|
|
1033
|
-
* @
|
|
1034
|
-
* @returns A promise that resolves to the result of the transaction.
|
|
1331
|
+
* @param callback A function that receives a PersistenceTransaction object.
|
|
1332
|
+
* @returns A promise that resolves to the transaction result.
|
|
1035
1333
|
*/
|
|
1036
1334
|
transact<ReturnType>(callback: (tx: PersistenceTransaction<FunctionMap>) => Promise<ReturnType>): Promise<ReturnType>;
|
|
1037
1335
|
}
|
|
1038
|
-
|
|
1039
|
-
interface
|
|
1336
|
+
/**
|
|
1337
|
+
* Transaction interface, omitting subscribe, trigger, schedule, and transact methods.
|
|
1338
|
+
*/
|
|
1339
|
+
type PersistenceTransaction<F> = Omit<Persistence<F>, "subscribe" | "trigger" | "schedule" | "transact">;
|
|
1340
|
+
/**
|
|
1341
|
+
* Interface for managing a single collection's data operations.
|
|
1342
|
+
*/
|
|
1343
|
+
interface PersistenceCollection<T, FunctionMap = Record<string, any>> extends ObservabilityInterface<T, FunctionMap>, EventTaskInterface<T, FunctionMap> {
|
|
1040
1344
|
/**
|
|
1041
|
-
* Creates a new record or multiple records in the
|
|
1042
|
-
* @param params
|
|
1043
|
-
* @
|
|
1044
|
-
* @param params.collection The name of the collection to create records in.
|
|
1045
|
-
* @returns A promise that resolves to the created record(s) with their generated IDs.
|
|
1345
|
+
* Creates a new record or multiple records in the collection.
|
|
1346
|
+
* @param params The data to create.
|
|
1347
|
+
* @returns A promise that resolves to the created record(s).
|
|
1046
1348
|
*/
|
|
1047
1349
|
create(params: {
|
|
1048
1350
|
data: T | T[];
|
|
1049
1351
|
}): Promise<T | T[]>;
|
|
1050
1352
|
/**
|
|
1051
|
-
* Retrieves one or more records from the
|
|
1052
|
-
* @param params
|
|
1053
|
-
* @
|
|
1054
|
-
* @returns A promise that resolves to a single record or an array of matching records.
|
|
1353
|
+
* Retrieves one or more records from the collection.
|
|
1354
|
+
* @param params The query defining the filter, sort, pagination, and projection.
|
|
1355
|
+
* @returns A promise that resolves to the matching record or array of records.
|
|
1055
1356
|
*/
|
|
1056
1357
|
read(params: {
|
|
1057
1358
|
query: QueryDSL<T, FunctionMap>;
|
|
1058
|
-
}): Promise<T | T
|
|
1359
|
+
}): Promise<T | Array<T>>;
|
|
1059
1360
|
/**
|
|
1060
|
-
* Updates one or more records in the
|
|
1061
|
-
* @param params
|
|
1062
|
-
* @param params.data The updated data to be applied; can be a single partial record or an array of partial records.
|
|
1063
|
-
* @param params.query The query defining which records to update.
|
|
1361
|
+
* Updates one or more records in the collection.
|
|
1362
|
+
* @param params The updated data, patch, or query.
|
|
1064
1363
|
* @returns A promise that resolves to the updated records.
|
|
1065
1364
|
*/
|
|
1066
1365
|
update(params: {
|
|
1067
1366
|
data?: Partial<T>;
|
|
1068
1367
|
patch?: PatchOperation | Array<PatchOperation>;
|
|
1069
|
-
query: QueryFilter<T,
|
|
1368
|
+
query: QueryFilter<T, FunctionMap>;
|
|
1070
1369
|
}): Promise<Array<T>>;
|
|
1071
1370
|
/**
|
|
1072
|
-
* Deletes one or more records from the
|
|
1073
|
-
* @param params
|
|
1074
|
-
* @
|
|
1075
|
-
* @param params.records An array of records to delete.
|
|
1076
|
-
* @returns A promise that resolves to the number of deleted records or the deleted records themselves.
|
|
1371
|
+
* Deletes one or more records from the collection.
|
|
1372
|
+
* @param params The query defining which records to delete.
|
|
1373
|
+
* @returns A promise that resolves to the number of deleted records.
|
|
1077
1374
|
*/
|
|
1078
1375
|
delete(params: {
|
|
1079
|
-
query: QueryFilter<T,
|
|
1376
|
+
query: QueryFilter<T, FunctionMap>;
|
|
1080
1377
|
}): Promise<number>;
|
|
1081
1378
|
/**
|
|
1082
|
-
* Validates an object against
|
|
1083
|
-
* @param
|
|
1084
|
-
* @
|
|
1085
|
-
* @returns An object containing validation results.
|
|
1379
|
+
* Validates an object against the collection's schema.
|
|
1380
|
+
* @param data The object to validate.
|
|
1381
|
+
* @returns Validation results.
|
|
1086
1382
|
*/
|
|
1087
1383
|
validate(data: any): {
|
|
1088
1384
|
valid: boolean;
|
|
1089
1385
|
issues: ReadonlyArray<StandardSchemaV1.Issue> | null;
|
|
1090
1386
|
};
|
|
1091
1387
|
/**
|
|
1092
|
-
*
|
|
1093
|
-
* @param
|
|
1094
|
-
* @param
|
|
1095
|
-
* @returns A
|
|
1388
|
+
* Rolls back the collection to a previous schema version.
|
|
1389
|
+
* @param version The version to roll back to (optional).
|
|
1390
|
+
* @param dryRun Whether to simulate the rollback.
|
|
1391
|
+
* @returns A promise that resolves to the new schema and data preview, or undefined.
|
|
1096
1392
|
*/
|
|
1097
|
-
subscribe(event: PersistenceEventType, callback: (payload: PersistenceEvent<T>) => void): () => void;
|
|
1098
1393
|
rollback(version?: string, dryRun?: boolean): Promise<{
|
|
1099
|
-
|
|
1100
|
-
|
|
1394
|
+
schema: SchemaDefinition;
|
|
1395
|
+
preview: ReadableStream<any>;
|
|
1101
1396
|
} | undefined>;
|
|
1397
|
+
/**
|
|
1398
|
+
* Applies a schema migration to the collection.
|
|
1399
|
+
* @param description A description of the migration.
|
|
1400
|
+
* @param cb A callback defining the transformation logic.
|
|
1401
|
+
* @param dryRun Whether to simulate the migration.
|
|
1402
|
+
* @returns A promise that resolves to the new schema and data preview, or undefined.
|
|
1403
|
+
*/
|
|
1102
1404
|
migrate(description: string, cb: (h: Omit<SchemaMigrationHelper, "changes">) => DataTransform<any, any> | undefined, dryRun?: boolean): Promise<{
|
|
1103
|
-
|
|
1104
|
-
|
|
1405
|
+
schema: SchemaDefinition;
|
|
1406
|
+
preview: ReadableStream<any>;
|
|
1105
1407
|
} | undefined>;
|
|
1106
1408
|
}
|
|
1107
1409
|
/**
|
|
1108
|
-
*
|
|
1410
|
+
* Context for collection-specific triggers.
|
|
1109
1411
|
*/
|
|
1110
|
-
type
|
|
1412
|
+
type CollectionTriggerContext<T, FunctionMap = Record<string, any>> = {
|
|
1413
|
+
event: PersistenceEvent<T> & {
|
|
1414
|
+
type: "create:start";
|
|
1415
|
+
operation: "create";
|
|
1416
|
+
};
|
|
1417
|
+
persistence: Persistence<FunctionMap>;
|
|
1418
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1419
|
+
params: {
|
|
1420
|
+
data: T | T[];
|
|
1421
|
+
};
|
|
1422
|
+
results: undefined;
|
|
1423
|
+
} | {
|
|
1424
|
+
event: PersistenceEvent<T> & {
|
|
1425
|
+
type: "create:success";
|
|
1426
|
+
operation: "create";
|
|
1427
|
+
};
|
|
1428
|
+
persistence: Persistence<FunctionMap>;
|
|
1429
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1430
|
+
params: {
|
|
1431
|
+
data: T | T[];
|
|
1432
|
+
};
|
|
1433
|
+
results: T | T[];
|
|
1434
|
+
} | {
|
|
1435
|
+
event: PersistenceEvent<T> & {
|
|
1436
|
+
type: "create:failed";
|
|
1437
|
+
operation: "create";
|
|
1438
|
+
};
|
|
1439
|
+
persistence: Persistence<FunctionMap>;
|
|
1440
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1441
|
+
params: {
|
|
1442
|
+
data: T | T[];
|
|
1443
|
+
};
|
|
1444
|
+
results: undefined;
|
|
1445
|
+
} | {
|
|
1446
|
+
event: PersistenceEvent<T> & {
|
|
1447
|
+
type: "read:start";
|
|
1448
|
+
operation: "read";
|
|
1449
|
+
};
|
|
1450
|
+
persistence: Persistence<FunctionMap>;
|
|
1451
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1452
|
+
params: {
|
|
1453
|
+
query: QueryDSL<T, FunctionMap>;
|
|
1454
|
+
};
|
|
1455
|
+
results: undefined;
|
|
1456
|
+
} | {
|
|
1457
|
+
event: PersistenceEvent<T> & {
|
|
1458
|
+
type: "read:success";
|
|
1459
|
+
operation: "read";
|
|
1460
|
+
};
|
|
1461
|
+
persistence: Persistence<FunctionMap>;
|
|
1462
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1463
|
+
params: {
|
|
1464
|
+
query: QueryDSL<T, FunctionMap>;
|
|
1465
|
+
};
|
|
1466
|
+
results: T | T[];
|
|
1467
|
+
} | {
|
|
1468
|
+
event: PersistenceEvent<T> & {
|
|
1469
|
+
type: "read:failed";
|
|
1470
|
+
operation: "read";
|
|
1471
|
+
};
|
|
1472
|
+
persistence: Persistence<FunctionMap>;
|
|
1473
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1474
|
+
params: {
|
|
1475
|
+
query: QueryDSL<T, FunctionMap>;
|
|
1476
|
+
};
|
|
1477
|
+
results: undefined;
|
|
1478
|
+
} | {
|
|
1479
|
+
event: PersistenceEvent<T> & {
|
|
1480
|
+
type: "update:start";
|
|
1481
|
+
operation: "update";
|
|
1482
|
+
};
|
|
1483
|
+
persistence: Persistence<FunctionMap>;
|
|
1484
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1485
|
+
params: {
|
|
1486
|
+
data?: Partial<T>;
|
|
1487
|
+
patch?: PatchOperation | Array<PatchOperation>;
|
|
1488
|
+
query: QueryFilter<T, FunctionMap>;
|
|
1489
|
+
};
|
|
1490
|
+
results: undefined;
|
|
1491
|
+
} | {
|
|
1492
|
+
event: PersistenceEvent<T> & {
|
|
1493
|
+
type: "update:success";
|
|
1494
|
+
operation: "update";
|
|
1495
|
+
};
|
|
1496
|
+
persistence: Persistence<FunctionMap>;
|
|
1497
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1498
|
+
params: {
|
|
1499
|
+
data?: Partial<T>;
|
|
1500
|
+
patch?: PatchOperation | Array<PatchOperation>;
|
|
1501
|
+
query: QueryFilter<T, FunctionMap>;
|
|
1502
|
+
};
|
|
1503
|
+
results: Array<T>;
|
|
1504
|
+
} | {
|
|
1505
|
+
event: PersistenceEvent<T> & {
|
|
1506
|
+
type: "update:failed";
|
|
1507
|
+
operation: "update";
|
|
1508
|
+
};
|
|
1509
|
+
persistence: Persistence<FunctionMap>;
|
|
1510
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1511
|
+
params: {
|
|
1512
|
+
data?: Partial<T>;
|
|
1513
|
+
patch?: PatchOperation | Array<PatchOperation>;
|
|
1514
|
+
query: QueryFilter<T, FunctionMap>;
|
|
1515
|
+
};
|
|
1516
|
+
results: undefined;
|
|
1517
|
+
} | {
|
|
1518
|
+
event: PersistenceEvent<T> & {
|
|
1519
|
+
type: "delete:start";
|
|
1520
|
+
operation: "delete";
|
|
1521
|
+
};
|
|
1522
|
+
persistence: Persistence<FunctionMap>;
|
|
1523
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1524
|
+
params: {
|
|
1525
|
+
query: QueryFilter<T, FunctionMap>;
|
|
1526
|
+
};
|
|
1527
|
+
results: undefined;
|
|
1528
|
+
} | {
|
|
1529
|
+
event: PersistenceEvent<T> & {
|
|
1530
|
+
type: "delete:success";
|
|
1531
|
+
operation: "delete";
|
|
1532
|
+
};
|
|
1533
|
+
persistence: Persistence<FunctionMap>;
|
|
1534
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1535
|
+
params: {
|
|
1536
|
+
query: QueryFilter<T, FunctionMap>;
|
|
1537
|
+
};
|
|
1538
|
+
results: number;
|
|
1539
|
+
} | {
|
|
1540
|
+
event: PersistenceEvent<T> & {
|
|
1541
|
+
type: "delete:failed";
|
|
1542
|
+
operation: "delete";
|
|
1543
|
+
};
|
|
1544
|
+
persistence: Persistence<FunctionMap>;
|
|
1545
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1546
|
+
params: {
|
|
1547
|
+
query: QueryFilter<T, FunctionMap>;
|
|
1548
|
+
};
|
|
1549
|
+
results: undefined;
|
|
1550
|
+
} | {
|
|
1551
|
+
event: PersistenceEvent<T> & {
|
|
1552
|
+
type: "migrate:start";
|
|
1553
|
+
operation: "migrate";
|
|
1554
|
+
};
|
|
1555
|
+
persistence: Persistence<FunctionMap>;
|
|
1556
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1557
|
+
params: {
|
|
1558
|
+
description: string;
|
|
1559
|
+
dryRun?: boolean;
|
|
1560
|
+
};
|
|
1561
|
+
results: undefined;
|
|
1562
|
+
} | {
|
|
1563
|
+
event: PersistenceEvent<T> & {
|
|
1564
|
+
type: "migrate:success";
|
|
1565
|
+
operation: "migrate";
|
|
1566
|
+
};
|
|
1567
|
+
persistence: Persistence<FunctionMap>;
|
|
1568
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1569
|
+
params: {
|
|
1570
|
+
description: string;
|
|
1571
|
+
dryRun?: boolean;
|
|
1572
|
+
};
|
|
1573
|
+
results: {
|
|
1574
|
+
schema: SchemaDefinition;
|
|
1575
|
+
preview: ReadableStream<any>;
|
|
1576
|
+
} | undefined;
|
|
1577
|
+
} | {
|
|
1578
|
+
event: PersistenceEvent<T> & {
|
|
1579
|
+
type: "migrate:failed";
|
|
1580
|
+
operation: "migrate";
|
|
1581
|
+
};
|
|
1582
|
+
persistence: Persistence<FunctionMap>;
|
|
1583
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1584
|
+
params: {
|
|
1585
|
+
description: string;
|
|
1586
|
+
dryRun?: boolean;
|
|
1587
|
+
};
|
|
1588
|
+
results: undefined;
|
|
1589
|
+
} | {
|
|
1590
|
+
event: PersistenceEvent<T> & {
|
|
1591
|
+
type: "rollback:start";
|
|
1592
|
+
operation: "rollback";
|
|
1593
|
+
};
|
|
1594
|
+
persistence: Persistence<FunctionMap>;
|
|
1595
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1596
|
+
params: {
|
|
1597
|
+
version?: string;
|
|
1598
|
+
dryRun?: boolean;
|
|
1599
|
+
};
|
|
1600
|
+
results: undefined;
|
|
1601
|
+
} | {
|
|
1602
|
+
event: PersistenceEvent<T> & {
|
|
1603
|
+
type: "rollback:success";
|
|
1604
|
+
operation: "rollback";
|
|
1605
|
+
};
|
|
1606
|
+
persistence: Persistence<FunctionMap>;
|
|
1607
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1608
|
+
params: {
|
|
1609
|
+
version?: string;
|
|
1610
|
+
dryRun?: boolean;
|
|
1611
|
+
};
|
|
1612
|
+
results: {
|
|
1613
|
+
schema: SchemaDefinition;
|
|
1614
|
+
preview: ReadableStream<any>;
|
|
1615
|
+
} | undefined;
|
|
1616
|
+
} | {
|
|
1617
|
+
event: PersistenceEvent<T> & {
|
|
1618
|
+
type: "rollback:failed";
|
|
1619
|
+
operation: "rollback";
|
|
1620
|
+
};
|
|
1621
|
+
persistence: Persistence<FunctionMap>;
|
|
1622
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1623
|
+
params: {
|
|
1624
|
+
version?: string;
|
|
1625
|
+
dryRun?: boolean;
|
|
1626
|
+
};
|
|
1627
|
+
results: undefined;
|
|
1628
|
+
};
|
|
1111
1629
|
/**
|
|
1112
|
-
*
|
|
1630
|
+
* Context for global triggers (Persistence-level, non-collection-specific).
|
|
1113
1631
|
*/
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
*/
|
|
1159
|
-
duration?: number;
|
|
1160
|
-
/**
|
|
1161
|
-
* Additional context or metadata specific to the operation.
|
|
1162
|
-
* This field can be used to include extra debugging or contextual data.
|
|
1163
|
-
*/
|
|
1164
|
-
context?: Record<string, any>;
|
|
1165
|
-
}
|
|
1632
|
+
type GlobalTriggerContext<T, FunctionMap = Record<string, any>> = {
|
|
1633
|
+
event: PersistenceEvent<T> & {
|
|
1634
|
+
type: "transaction:start" | "transaction:success" | "transaction:failed" | "collection:create:start" | "collection:create:success" | "collection:create:failed" | "collection:delete:start" | "collection:delete:success" | "collection:delete:failed" | "telemetry";
|
|
1635
|
+
operation: "transaction" | "collection:create" | "collection:delete";
|
|
1636
|
+
};
|
|
1637
|
+
persistence: Persistence<FunctionMap>;
|
|
1638
|
+
collection?: undefined;
|
|
1639
|
+
params: any;
|
|
1640
|
+
results: any;
|
|
1641
|
+
};
|
|
1642
|
+
/**
|
|
1643
|
+
* Union of trigger contexts.
|
|
1644
|
+
*/
|
|
1645
|
+
type TriggerContext<T, FunctionMap = Record<string, any>> = CollectionTriggerContext<T, FunctionMap> | GlobalTriggerContext<T, FunctionMap>;
|
|
1646
|
+
/**
|
|
1647
|
+
* Defines a schedule for a task.
|
|
1648
|
+
*/
|
|
1649
|
+
type TaskSchedule = {
|
|
1650
|
+
cron: string;
|
|
1651
|
+
} | {
|
|
1652
|
+
at: string;
|
|
1653
|
+
} | {
|
|
1654
|
+
interval: number;
|
|
1655
|
+
};
|
|
1656
|
+
/**
|
|
1657
|
+
* Context provided to task callbacks.
|
|
1658
|
+
*/
|
|
1659
|
+
type TaskContext<T, FunctionMap = Record<string, any>> = {
|
|
1660
|
+
persistence: Persistence<FunctionMap>;
|
|
1661
|
+
collection: PersistenceCollection<T, FunctionMap>;
|
|
1662
|
+
taskId: string;
|
|
1663
|
+
executionTime: number;
|
|
1664
|
+
metadata?: Record<string, any>;
|
|
1665
|
+
label: string;
|
|
1666
|
+
description: string;
|
|
1667
|
+
} | {
|
|
1668
|
+
persistence: Persistence<FunctionMap>;
|
|
1669
|
+
collection?: undefined;
|
|
1670
|
+
taskId: string;
|
|
1671
|
+
executionTime: number;
|
|
1672
|
+
metadata?: Record<string, any>;
|
|
1673
|
+
label: string;
|
|
1674
|
+
description: string;
|
|
1675
|
+
};
|
|
1166
1676
|
|
|
1167
1677
|
type SchemaIndex = {
|
|
1168
1678
|
schema: string;
|
|
@@ -1502,9 +2012,10 @@ declare class SchemaRegistry implements SchemaRegistryInterface {
|
|
|
1502
2012
|
}
|
|
1503
2013
|
|
|
1504
2014
|
/**
|
|
1505
|
-
* @fileoverview
|
|
2015
|
+
* @fileoverview
|
|
2016
|
+
* Provides a MigrationEngine class that handles schema migrations,
|
|
1506
2017
|
* including validation, checksum generation, and migration application.
|
|
1507
|
-
* @author
|
|
2018
|
+
* @author Saidimu
|
|
1508
2019
|
*/
|
|
1509
2020
|
|
|
1510
2021
|
/**
|
|
@@ -1880,4 +2391,4 @@ declare function docgen(schema: SchemaDefinition, options?: {
|
|
|
1880
2391
|
faker?: Faker;
|
|
1881
2392
|
}): string;
|
|
1882
2393
|
|
|
1883
|
-
export { type ArrayHint, type BooleanHint, type CodeHint, type Constraint, type ConstraintGroup, type ConstraintParameters, type ConstraintsMap, type DataTransform, type DateHint, type EnumHint, type FieldDefinition, type FieldGroup, type FieldSchema, type FieldType, type FileHint, type FunctionMap, type GroupDefinition, type IndexDefinition, type IndexType, type InputHint, JsonPatchError, type
|
|
2394
|
+
export { type ArrayHint, type BooleanHint, type CodeHint, type CollectionMetadata, type CollectionTriggerContext, type Constraint, type ConstraintGroup, type ConstraintParameters, type ConstraintsMap, type DataTransform, type DateHint, type EnumHint, type EventTaskInterface, type FieldDefinition, type FieldGroup, type FieldSchema, type FieldType, type FileHint, type FunctionMap, type GlobalTriggerContext, type GroupDefinition, type IndexDefinition, type IndexType, type InputHint, JsonPatchError, type Metadata, type MetadataFilter, type Migration, MigrationEngine, type MigrationEngineInterface, MigrationError, MigrationErrorCode, type MigrationMetadata, type NestedSchemaDefinition, type NumberHint, type ObjectHint, type ObservabilityInterface, type PartialIndexCondition, type PatchOperation, type Persistence, type PersistenceCollection, type PersistenceEvent, type PersistenceEventType, type PersistenceTransaction, type Predicate, type PredicateMap, type PredicateName, type PredicateParameters, type RegistryLock, type RegistryMetadata, type RemoteRepository, type Schema, type SchemaChange, type SchemaConstraint, type SchemaDefinition, type SchemaEvent, type SchemaEventType, type SchemaHint, type SchemaIndex, type SchemaMetadata, type SchemaMigrationHelper, SchemaRegistry, type SchemaRegistryInterface, type SchemaVersion, type SecretHint, type SetHint, type SubscriptionInfo, type TaskContext, type TaskInfo, type TaskSchedule, type TextHint, type TransformFunction, type TriggerContext, type TriggerInfo, applyPatch, calculateNextVersion, compareSemanticVersions, createGitSchemaRegistry, createPatch, createSchemaMigrationHelper, createStandardSchemaValidator, deepMerge, docgen, extractInputFieldGroups, formResolver, generateSHA256Hash, normalizePath, schemaChangeToPatch, schemaDefaults, schemaToTypes, serializeParams, sortSemanticVars, validate, validateMigration, validateSchemaChange, validateSchemaDefinition };
|