@asaidimu/anansi 1.6.5 → 2.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 (6) hide show
  1. package/README.md +750 -65
  2. package/index.cjs +13 -13
  3. package/index.d.cts +753 -173
  4. package/index.d.ts +753 -173
  5. package/index.js +14 -14
  6. 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';
@@ -16,9 +16,11 @@ import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
16
16
  */
17
17
  type FileHint = {
18
18
  type: "file";
19
+ subtype: "video" | "audio" | "image" | "pdf" | "doc" | "txt";
19
20
  label?: string;
20
21
  embed?: boolean;
21
22
  mimes?: string | string[];
23
+ preview?: boolean;
22
24
  size?: {
23
25
  max?: number;
24
26
  min?: number;
@@ -122,30 +124,39 @@ type ObjectHint = {
122
124
  ignore?: boolean;
123
125
  };
124
126
  /**
125
- * Hints for generating a dynamic input control.
127
+ * Hints for generating a date input control.
126
128
  */
127
- type DynamicHint = {
128
- type: "text";
129
+ type DateHint = {
130
+ type: "date" | "datetime" | "time";
129
131
  label?: string;
132
+ placeholder?: string;
133
+ min?: string;
134
+ max?: string;
130
135
  group?: string;
131
136
  ignore?: boolean;
132
137
  };
133
138
  /**
134
- * Hints for generating a date input control.
139
+ * Hints for generating a code input control (e.g., for code snippets or scripts).
135
140
  */
136
- type DateHint = {
137
- type: "date" | "datetime" | "time";
141
+ type CodeHint = {
142
+ type: "code";
138
143
  label?: string;
144
+ language?: string;
139
145
  placeholder?: string;
140
- min?: string;
141
- max?: string;
146
+ readonly?: boolean;
147
+ editorOptions?: {
148
+ lineNumbers?: boolean;
149
+ wordWrap?: boolean;
150
+ minimap?: boolean;
151
+ };
142
152
  group?: string;
143
153
  ignore?: boolean;
144
154
  };
145
155
  /**
146
156
  * Union type for all possible input hints.
157
+ * Note: DynamicHint removed to avoid overlap with TextHint; use TextHint for generic text needs.
147
158
  */
148
- type InputHint = FileHint | TextHint | SecretHint | NumberHint | BooleanHint | EnumHint | ArrayHint | SetHint | ObjectHint | DynamicHint | DateHint;
159
+ type InputHint = FileHint | TextHint | SecretHint | NumberHint | BooleanHint | EnumHint | ArrayHint | SetHint | ObjectHint | DateHint | CodeHint;
149
160
  /**
150
161
  * Defines metadata for a group of inputs at the schema level.
151
162
  */
@@ -161,10 +172,6 @@ type SchemaHint = {
161
172
  groups?: GroupDefinition[];
162
173
  };
163
174
 
164
- /**
165
- * Logical operators for combining constraints or index conditions.
166
- */
167
- type LogicalOperator = "and" | "or" | "not" | "nor" | "xor";
168
175
  /**
169
176
  * Basic field types supported by the schema system.
170
177
  */
@@ -404,73 +411,195 @@ interface IndexDefinition {
404
411
  name: string;
405
412
  }
406
413
  /**
407
- * Represents a nested schema definition embedded within a parent schema.
408
- * Unlike SchemaDefinition, this can use a discriminated array of field sets for variant-specific fields,
409
- * but only when concrete is false. This restriction avoids complexity in RDBMS implementations,
410
- * where concrete schemas map directly to tables with fixed columns. Non-concrete schemas, as embedded
411
- * structures, can leverage this flexibility without affecting physical table design.
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.
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.
412
422
  *
413
423
  * @example
424
+ * // Example of a concrete, object-based nested schema (like a fixed address structure)
414
425
  * ```typescript
415
426
  * const addressSchema: NestedSchemaDefinition = {
416
- * name: "address",
417
- * fields: {
418
- * street: { name: "street", type: "string" },
419
- * city: { name: "city", type: "string" },
420
- * zip: { name: "zip", type: "string" }
421
- * },
422
- * concrete: true
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
423
435
  * };
436
+ * ```
424
437
  *
438
+ * @example
439
+ * // Example of a non-concrete, object-based nested schema with discriminated fields (like a contact method)
440
+ * ```typescript
425
441
  * const contactSchema: NestedSchemaDefinition = {
426
- * name: "contact",
427
- * fields: [
428
- * { fields: { email: { name: "email", type: "string" } }, when: { field: "type", value: "email" } },
429
- * { fields: { phone: { name: "phone", type: "string" } }, when: { field: "type", value: "phone" } }
430
- * ]
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
+ * }
431
477
  * };
432
478
  * ```
433
479
  */
434
- interface NestedSchemaDefinition {
480
+ type NestedSchemaDefinition<T> = {
435
481
  /**
436
- * The name of the nested schema, unique within the parent schema's nestedSchemas.
482
+ * The unique name or identifier of the nested schema within the parent schema's `nestedSchemas` map.
483
+ * This `name` is used by `FieldDefinition.schema.id` to reference this nested schema.
484
+ * @example "AddressSchema" or "EmailString"
437
485
  */
438
486
  name: string;
439
487
  /**
440
- * A description of the nested schema's purpose.
488
+ * A clear and concise description of the nested schema's purpose, structure, or expected data.
489
+ * This is crucial for documentation and understanding the schema's intent.
441
490
  */
442
491
  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
+ /**
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";
443
509
  /**
444
- * Indicates whether this schema represents a standalone entity (true) or is embedded (false).
445
- * When true, fields must be a Record<string, FieldDefinition<any>> to ensure a fixed structure
446
- * suitable for RDBMS table mapping. When false, fields can be an array of discriminated field sets.
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.
519
+ */
520
+ constraints?: Array<Constraint<any> | ConstraintGroup<any>>;
521
+ /**
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" }`
525
+ */
526
+ 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
+ {
533
+ /**
534
+ * Explicitly indicates that this is a non-literal, structured schema.
535
+ * Default value is `false` if omitted.
536
+ */
537
+ literal?: false;
538
+ /**
539
+ * Indicates whether this schema represents a standalone entity (`true`) or is embedded (`false`).
540
+ * - When `true` (`concrete: true`), the schema is treated as a distinct, fixed-structure entity,
541
+ * often suitable for direct mapping to RDBMS tables. In this case, `fields` *must* be a
542
+ * `Record<string, FieldDefinition<any>>` to ensure a consistent, non-polymorphic structure.
543
+ * - When `false` (`concrete: false` or omitted), the schema is considered embedded or polymorphic.
544
+ * `fields` can be either a `Record<string, FieldDefinition<any>>` (for a fixed embedded object)
545
+ * or an `Array<{ fields: Record<string, FieldDefinition<any>>; when?: { field: string; value: any } }>`,
546
+ * allowing discriminated field sets based on a specific field's value (e.g., a 'type' field).
547
+ * The array form enables defining variants within a single schema without imposing strict concrete
548
+ * constraints, but is not supported for `concrete: true` schemas to maintain simplicity in RDBMS table mappings.
447
549
  * @default false
448
550
  */
449
551
  concrete?: boolean;
450
552
  /**
451
- * Defines the fields of the nested schema.
452
- * - If concrete is true, must be a Record<string, FieldDefinition<any>> for a fixed field set.
453
- * - If concrete is false, can be either a Record<string, FieldDefinition<any>> or an
454
- * Array<{ fields: Record<string, FieldDefinition<any>>; when?: { field: string; value: any } }>,
455
- * allowing discriminated field sets based on a field value (e.g., 'type').
456
- * The array form enables variant-specific fields without constraints, but is not supported for
457
- * concrete schemas to maintain simplicity in RDBMS table mappings.
553
+ * Defines the fields (properties) that constitute this nested schema.
554
+ * The structure of `fields` depends on the `concrete` property:
555
+ * - If `concrete` is `true`, `fields` must be a `Record<string, FieldDefinition<any>>`
556
+ * to define a fixed set of named fields (e.g., for a database table).
557
+ * - If `concrete` is `false` (or omitted), `fields` can be:
558
+ * - A `Record<string, FieldDefinition<any>>` for a simple, embedded object.
559
+ * - An `Array<{ fields: Record<string, FieldDefinition<any>>; when?: { field: string; value: any } }>`
560
+ * to define a discriminated union or polymorphic structure. Each object in the array defines a
561
+ * set of fields that apply `when` a specified `field` (within this schema's own fields)
562
+ * has a particular `value`. This allows for variant-specific fields.
458
563
  */
459
564
  fields: Record<string, FieldDefinition<any>> | Array<{
565
+ /**
566
+ * A set of field definitions that apply when the `when` condition is met.
567
+ */
460
568
  fields: Record<string, FieldDefinition<any>>;
569
+ /**
570
+ * An optional condition that makes this set of fields active.
571
+ * This object specifies a `field` (its name within this schema) and a `value`.
572
+ * When the specified `field` in the data matches this `value`, these `fields` are considered active.
573
+ * Used for discriminated unions or polymorphic structures (e.g., `when: { field: "type", value: "car" }`).
574
+ * If `when` is omitted for an entry in the array, those fields are always present in the union's base,
575
+ * or it acts as a fallback if no other `when` condition matches.
576
+ */
461
577
  when?: {
462
578
  field: string;
463
579
  value: any;
464
580
  };
465
581
  }>;
466
582
  /**
467
- * Optional constraints for additional validation rules.
468
- * Less necessary when using discriminated field sets, as variant logic can be structural.
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.
469
587
  */
470
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
+ */
471
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" }`
600
+ */
472
601
  metadata?: Record<string, any>;
473
- }
602
+ });
474
603
  /**
475
604
  * Defines a complete schema, intended as an atomic unit within a larger domain model.
476
605
  *
@@ -508,7 +637,7 @@ interface SchemaDefinition {
508
637
  description?: string;
509
638
  fields: Record<string, FieldDefinition<any>>;
510
639
  /** Reusable nested schema definitions, now as mini-SchemaDefinitions. */
511
- nestedSchemas: Record<string, NestedSchemaDefinition>;
640
+ nestedSchemas?: Record<string, NestedSchemaDefinition<any>>;
512
641
  indexes?: IndexDefinition[];
513
642
  constraints?: SchemaConstraint<any>;
514
643
  metadata?: Record<string, any>;
@@ -587,14 +716,14 @@ type SchemaChange<T> = {
587
716
  } | {
588
717
  type: "addNestedSchema";
589
718
  id: string;
590
- definition: NestedSchemaDefinition;
719
+ definition: NestedSchemaDefinition<any>;
591
720
  } | {
592
721
  type: "removeNestedSchema";
593
722
  id: string;
594
723
  } | {
595
724
  type: "modifyNestedSchema";
596
725
  id: string;
597
- changes: Partial<NestedSchemaDefinition>;
726
+ changes: Partial<NestedSchemaDefinition<any>>;
598
727
  };
599
728
  /**
600
729
  * Defines a transform function for data migration between schema versions.
@@ -951,7 +1080,7 @@ interface SchemaMigrationHelper {
951
1080
  * @param {string} schemaId - The ID of the nested schema to add.
952
1081
  * @param {NestedSchemaDefinition} nestedDefinition - The definition of the nested schema to add.
953
1082
  */
954
- addNestedSchema(schemaId: string, nestedDefinition: NestedSchemaDefinition): void;
1083
+ addNestedSchema(schemaId: string, nestedDefinition: NestedSchemaDefinition<any>): void;
955
1084
  /**
956
1085
  * Removes a nested schema from the schema.
957
1086
  * @param {string} schemaId - The ID of the nested schema to remove.
@@ -962,7 +1091,7 @@ interface SchemaMigrationHelper {
962
1091
  * @param {string} schemaId - The ID of the nested schema to modify.
963
1092
  * @param {Partial<NestedSchemaDefinition>} changes - The changes to apply to the nested schema.
964
1093
  */
965
- modifyNestedSchema(schemaId: string, changes: Partial<NestedSchemaDefinition>): void;
1094
+ modifyNestedSchema(schemaId: string, changes: Partial<NestedSchemaDefinition<any>>): void;
966
1095
  /**
967
1096
  * Returns the list of changes made through this helper.
968
1097
  * @returns An array of schema changes.
@@ -973,185 +1102,635 @@ interface SchemaMigrationHelper {
973
1102
  };
974
1103
  }
975
1104
 
1105
+ /**
1106
+ * Defines the possible event types for persistence operations.
1107
+ */
1108
+ 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";
1109
+ /**
1110
+ * Interface representing events emitted during persistence operations.
1111
+ */
1112
+ interface PersistenceEvent<DataType> {
1113
+ /** The type of event (e.g., 'create:start', 'trigger:execute'). */
1114
+ type: PersistenceEventType;
1115
+ /** Timestamp when the event occurred. */
1116
+ timestamp: number;
1117
+ /** The operation being performed (e.g., 'create', 'trigger'). */
1118
+ operation: string;
1119
+ /** Name of the collection affected by the operation (if applicable). */
1120
+ collection?: string;
1121
+ /** Data passed to the operation (if applicable). */
1122
+ input?: any;
1123
+ /** Data returned by the operation (if applicable). */
1124
+ output?: any;
1125
+ /** Error object if the operation failed (if applicable). */
1126
+ error?: Error;
1127
+ /** Issues that caused the operation to fail (if applicable). */
1128
+ issues?: Array<StandardSchemaV1.Issue>;
1129
+ /** Query used in the operation (if applicable). */
1130
+ query?: QueryDSL<DataType, any>;
1131
+ /** Identifier for the transaction (if part of one). */
1132
+ transactionId?: string;
1133
+ /** Duration of the operation in milliseconds. */
1134
+ duration?: number;
1135
+ /** Additional context or metadata specific to the operation. */
1136
+ context?: Record<string, any>;
1137
+ }
1138
+ /**
1139
+ * Describes a subscription configuration.
1140
+ */
1141
+ interface SubscriptionInfo {
1142
+ /** The event subscribed to. */
1143
+ event: PersistenceEventType;
1144
+ /** Unique identifier for the callback. */
1145
+ callbackId: string;
1146
+ /** Optional short identifier (max 50 chars, unique within scope). */
1147
+ label?: string;
1148
+ /** Optional description of the subscription's purpose (max 500 chars). */
1149
+ description?: string;
1150
+ }
1151
+ /**
1152
+ * Describes a trigger configuration.
1153
+ */
1154
+ interface TriggerInfo<T, FunctionMap = Record<string, any>> {
1155
+ /** The event(s) or pattern triggering the callback. */
1156
+ event: PersistenceEventType | PersistenceEventType[] | `${string}:*`;
1157
+ /** Optional condition for the trigger. */
1158
+ condition?: QueryFilter<T, FunctionMap>;
1159
+ /** Unique identifier for the callback. */
1160
+ callbackId: string;
1161
+ /** Whether the trigger executes synchronously. */
1162
+ isSync: boolean;
1163
+ /** Short identifier (max 50 chars, unique within scope). */
1164
+ label: string;
1165
+ /** Description of the trigger's purpose (max 500 chars). */
1166
+ description: string;
1167
+ }
1168
+ /**
1169
+ * Describes a scheduled task configuration.
1170
+ */
1171
+ interface TaskInfo {
1172
+ /** Unique identifier for the task. */
1173
+ id: string;
1174
+ /** Schedule for task execution. */
1175
+ schedule: TaskSchedule;
1176
+ /** Unique identifier for the callback. */
1177
+ callbackId: string;
1178
+ /** Whether the task executes synchronously. */
1179
+ isSync: boolean;
1180
+ /** Optional metadata for logging or telemetry. */
1181
+ metadata?: Record<string, any>;
1182
+ /** Short identifier (max 50 chars, unique within scope). */
1183
+ label: string;
1184
+ /** Description of the task's purpose (max 500 chars). */
1185
+ description: string;
1186
+ }
1187
+ /**
1188
+ * Filter criteria for metadata queries.
1189
+ */
1190
+ interface MetadataFilter {
1191
+ /** Filter for subscriptions. */
1192
+ subscriptions?: {
1193
+ event?: PersistenceEventType | PersistenceEventType[];
1194
+ label?: string;
1195
+ };
1196
+ /** Filter for triggers. */
1197
+ triggers?: {
1198
+ event?: PersistenceEventType | PersistenceEventType[] | `${string}:*`;
1199
+ label?: string;
1200
+ };
1201
+ /** Filter for tasks. */
1202
+ tasks?: {
1203
+ id?: string;
1204
+ metadata?: Record<string, any>;
1205
+ label?: string;
1206
+ };
1207
+ /** Filter for schemas. */
1208
+ schemas?: {
1209
+ id?: string;
1210
+ };
1211
+ }
1212
+ /**
1213
+ * Metadata for a single collection.
1214
+ */
1215
+ interface CollectionMetadata<T, FunctionMap = Record<string, any>> {
1216
+ /** Collection identifier. */
1217
+ id: string;
1218
+ /** Active subscriptions for the collection. */
1219
+ subscriptions: SubscriptionInfo[];
1220
+ /** Active triggers for the collection. */
1221
+ triggers: TriggerInfo<T, FunctionMap>[];
1222
+ /** Scheduled tasks for the collection. */
1223
+ tasks: TaskInfo[];
1224
+ /** Number of records in the collection. */
1225
+ recordCount: number;
1226
+ /** Storage used by the collection in bytes. */
1227
+ dataSizeBytes: number;
1228
+ /** Schema definition for the collection. */
1229
+ schema: SchemaDefinition;
1230
+ /** Timestamp of the last operation on the collection. */
1231
+ lastModified: number;
1232
+ }
1233
+ /**
1234
+ * Metadata for Persistence or PersistenceCollection.
1235
+ */
1236
+ interface Metadata<T, FunctionMap = Record<string, any>> {
1237
+ /** Active subscriptions. */
1238
+ subscriptions: SubscriptionInfo[];
1239
+ /** Active triggers. */
1240
+ triggers: TriggerInfo<T, FunctionMap>[];
1241
+ /** Scheduled tasks. */
1242
+ tasks: TaskInfo[];
1243
+ /** Number of collections (Persistence only). */
1244
+ collectionCount?: number;
1245
+ /** Total storage used by all collections in bytes (Persistence only). */
1246
+ storageUsageBytes?: number;
1247
+ /** Database connection status (Persistence only). */
1248
+ connectionStatus?: "connected" | "disconnected" | "error";
1249
+ /** Database connection error, if any (Persistence only). */
1250
+ connectionError?: string | null;
1251
+ /** Schema definitions for all collections, if requested (Persistence only). */
1252
+ schemas?: SchemaDefinition[];
1253
+ /** Per-collection metadata, if requested (Persistence only). */
1254
+ collections?: CollectionMetadata<any, FunctionMap>[];
1255
+ /** Number of records in the collection (PersistenceCollection only). */
1256
+ recordCount?: number;
1257
+ /** Storage used by the collection in bytes (PersistenceCollection only). */
1258
+ dataSizeBytes?: number;
1259
+ /** Schema definition for the collection (PersistenceCollection only). */
1260
+ schema?: SchemaDefinition;
1261
+ /** Timestamp of the last operation on the collection (PersistenceCollection only). */
1262
+ lastModified?: number;
1263
+ }
1264
+ /**
1265
+ * Interface for querying observability data.
1266
+ */
1267
+ interface ObservabilityInterface<T, FunctionMap = Record<string, any>> {
1268
+ /**
1269
+ * Returns metadata about active subscriptions, triggers, tasks, and system state.
1270
+ * @param filter Optional filter to limit returned data (e.g., by event or label).
1271
+ * @param includeCollections For Persistence, whether to include per-collection metadata.
1272
+ * @param includeSchemas For Persistence, whether to include schema definitions.
1273
+ * @param forceRefresh Whether to force real-time queries for storageUsageBytes and dataSizeBytes.
1274
+ * @returns Metadata object containing observability data.
1275
+ * @example
1276
+ * // Collection metadata with label filter
1277
+ * const metadata = collection.metadata({ triggers: { label: "user-*" } });
1278
+ * console.log(metadata.triggers); // Triggers with label "user-*"
1279
+ * console.log(metadata.dataSizeBytes); // Storage used
1280
+ *
1281
+ * // Persistence metadata
1282
+ * const globalMetadata = persistence.metadata({ includeCollections: true });
1283
+ * console.log(globalMetadata.storageUsageBytes); // Total storage
1284
+ * console.log(globalMetadata.collections); // Per-collection metadata
1285
+ */
1286
+ metadata(filter?: MetadataFilter, includeCollections?: boolean, includeSchemas?: boolean, forceRefresh?: boolean): Metadata<T, FunctionMap>;
1287
+ }
1288
+ /**
1289
+ * Interface for event handling and task scheduling.
1290
+ */
1291
+ interface EventTaskInterface<T, FunctionMap = Record<string, any>> {
1292
+ /**
1293
+ * Subscribes to persistence events.
1294
+ * @param event The event to subscribe to.
1295
+ * @param callback The callback to handle the event.
1296
+ * @param options Optional label and description for the subscription.
1297
+ * @returns A function to unsubscribe from the event.
1298
+ * @example
1299
+ * const unsubscribe = persistence.subscribe("telemetry", (event) => {
1300
+ * console.log(event);
1301
+ * }, { label: "telemetry-log", description: "Logs telemetry events" });
1302
+ * unsubscribe();
1303
+ */
1304
+ subscribe(event: PersistenceEventType, callback: (payload: PersistenceEvent<T>) => void, options?: {
1305
+ label?: string;
1306
+ description?: string;
1307
+ }): () => void;
1308
+ /**
1309
+ * Registers a trigger callback for specific events.
1310
+ * @param config Configuration including event, callback, label, description, and options.
1311
+ * @returns A function to unsubscribe the trigger.
1312
+ * @example
1313
+ * collection.trigger("create:success",
1314
+ * ({ collection, results }) => {
1315
+ * console.log(`Created: ${results.id}`);
1316
+ * },
1317
+ * {
1318
+ * label: "user-create-hook",
1319
+ * description: "Syncs new users with CRM",
1320
+ * sync: true
1321
+ * });
1322
+ */
1323
+ trigger(event: PersistenceEventType | PersistenceEventType[] | `${string}:*`, callback: (context: TriggerContext<T, FunctionMap>) => void | Promise<void>, options: {
1324
+ condition?: QueryFilter<T, FunctionMap>;
1325
+ sync?: boolean;
1326
+ label: string;
1327
+ description: string;
1328
+ }): () => void;
1329
+ /**
1330
+ * Schedules a task to run at specified times or intervals.
1331
+ * @param config Configuration including ID, schedule, callback, label, description, and options.
1332
+ * @returns A function to cancel the scheduled task.
1333
+ * @example
1334
+ * collection.schedule({
1335
+ * id: "cleanup-inactive",
1336
+ * label: "inactive-cleanup",
1337
+ * description: "Deletes inactive records hourly",
1338
+ * schedule: { cron: "0 * * * *" },
1339
+ * callback: ({ collection }) => {
1340
+ * collection.delete({ query: { filter: { status: { $eq: "inactive" } } } });
1341
+ * }
1342
+ * });
1343
+ */
1344
+ schedule(config: {
1345
+ id: string;
1346
+ schedule: TaskSchedule;
1347
+ callback: (context: TaskContext<T, FunctionMap>) => void | Promise<void>;
1348
+ sync?: boolean;
1349
+ metadata?: Record<string, any>;
1350
+ label: string;
1351
+ description: string;
1352
+ }): () => void;
1353
+ }
976
1354
  /**
977
1355
  * Interface defining persistence operations for data management.
978
- * Provides methods for CRUD operations, transactions, validation, and event subscription.
979
- *
980
- * @generic DataType - The type of data being persisted.
981
- * @generic FunctionMap - A map of functions used in the persistence operations (default: Record<string, any>).
982
1356
  */
983
- interface Persistence<FunctionMap> {
1357
+ interface Persistence<FunctionMap = Record<string, any>> extends ObservabilityInterface<any, FunctionMap>, EventTaskInterface<any, FunctionMap> {
984
1358
  /**
985
- * Returns a list of all collections
986
- * @returns A promise that resolves to a list of collection names
1359
+ * Returns a list of all collection names.
1360
+ * @returns A promise that resolves to an array of collection names.
987
1361
  */
988
1362
  collections(): Promise<Array<string>>;
989
1363
  /**
990
1364
  * Creates a new collection with the specified schema.
991
- * @param schema - The schema definition for the new collection.
992
- * @returns A promise that resolves when the collection is created.
1365
+ * @param schema The schema definition for the new collection.
1366
+ * @returns A promise that resolves to the created PersistenceCollection.
993
1367
  */
994
- createCollection<T>(schema: SchemaDefinition): Promise<PersistenceCollection<T, FunctionMap>>;
1368
+ create<T>(schema: SchemaDefinition): Promise<PersistenceCollection<T, FunctionMap>>;
995
1369
  /**
996
1370
  * Deletes the specified collection.
997
- * @param id - The ID of the collection to delete.
998
- * @returns A promise that resolves when the collection is deleted.
1371
+ * @param id The ID of the collection to delete.
1372
+ * @returns A promise that resolves indicating whether the collection was deleted.
999
1373
  */
1000
- deleteCollection(id: string): Promise<void>;
1374
+ delete(id: string): Promise<boolean>;
1001
1375
  /**
1002
1376
  * Retrieves the schema definition for the specified collection.
1003
- * @param id - The ID of the collection.
1004
- * @returns A promise that resolves to the schema definition of the collection.
1377
+ * @param id The ID of the collection.
1378
+ * @returns A promise that resolves to the schema definition.
1005
1379
  */
1006
1380
  schema(id: string): Promise<SchemaDefinition>;
1007
1381
  /**
1008
- * Returns an object that can be used to interact with a collection of data
1009
- *
1382
+ * Returns a PersistenceCollection instance for interacting with a collection.
1383
+ * @param id The ID of the collection.
1384
+ * @returns The PersistenceCollection instance.
1010
1385
  */
1011
1386
  collection<T>(id: string): PersistenceCollection<T, FunctionMap>;
1012
- /**
1013
- * Subscribe to persistence events
1014
- * @param event - The event to subscribe to
1015
- * @param callback - A callback to handle the event
1016
- * @returns A callback that can be used to unsubscribe from the event
1017
- */
1018
- subscribe(event: PersistenceEventType, callback: (payload: PersistenceEvent<any>) => void): () => void;
1019
1387
  /**
1020
1388
  * Executes a transaction with multiple operations.
1021
- * @param callback A function that receives a PersistenceTransaction object to perform multiple operations.
1022
- * @param callback.tx The PersistenceTransaction object used to perform transactional operations.
1023
- * @returns A promise that resolves to the result of the transaction.
1389
+ * @param callback A function that receives a PersistenceTransaction object.
1390
+ * @returns A promise that resolves to the transaction result.
1024
1391
  */
1025
1392
  transact<ReturnType>(callback: (tx: PersistenceTransaction<FunctionMap>) => Promise<ReturnType>): Promise<ReturnType>;
1026
1393
  }
1027
- type PersistenceTransaction<F> = Omit<Persistence<F>, "subscribe" | "transact">;
1028
- interface PersistenceCollection<T, FunctionMap> {
1394
+ /**
1395
+ * Transaction interface, omitting subscribe, trigger, schedule, and transact methods.
1396
+ */
1397
+ type PersistenceTransaction<F> = Omit<Persistence<F>, "subscribe" | "trigger" | "schedule" | "transact">;
1398
+ /**
1399
+ * Interface for managing a single collection's data operations.
1400
+ */
1401
+ interface PersistenceCollection<T, FunctionMap = Record<string, any>> extends ObservabilityInterface<T, FunctionMap>, EventTaskInterface<T, FunctionMap> {
1029
1402
  /**
1030
- * Creates a new record or multiple records in the specified collection.
1031
- * @param params An object containing the data to create and the collection name.
1032
- * @param params.data The data to be inserted; can be a single record or an array of records.
1033
- * @param params.collection The name of the collection to create records in.
1034
- * @returns A promise that resolves to the created record(s) with their generated IDs.
1403
+ * Creates a new record or multiple records in the collection.
1404
+ * @param params The data to create.
1405
+ * @returns A promise that resolves to the created record(s).
1035
1406
  */
1036
1407
  create(params: {
1037
1408
  data: T | T[];
1038
1409
  }): Promise<T | T[]>;
1039
1410
  /**
1040
- * Retrieves one or more records from the specified collection.
1041
- * @param params An object containing the query and collection name.
1042
- * @param params.query The query defining the filter, sort, pagination, and projection options.
1043
- * @returns A promise that resolves to a single record or an array of matching records.
1411
+ * Retrieves one or more records from the collection.
1412
+ * @param params The query defining the filter, sort, pagination, and projection.
1413
+ * @returns A promise that resolves to the matching record or array of records.
1044
1414
  */
1045
1415
  read(params: {
1046
1416
  query: QueryDSL<T, FunctionMap>;
1047
- }): Promise<T | T[]>;
1417
+ }): Promise<T | Array<T>>;
1048
1418
  /**
1049
- * Updates one or more records in the specified collection.
1050
- * @param params An object containing the updated data, query, and collection name.
1051
- * @param params.data The updated data to be applied; can be a single partial record or an array of partial records.
1052
- * @param params.query The query defining which records to update.
1419
+ * Updates one or more records in the collection.
1420
+ * @param params The updated data, patch, or query.
1053
1421
  * @returns A promise that resolves to the updated records.
1054
1422
  */
1055
1423
  update(params: {
1056
1424
  data?: Partial<T>;
1057
1425
  patch?: PatchOperation | Array<PatchOperation>;
1058
- query: QueryFilter<T, any>;
1426
+ query: QueryFilter<T, FunctionMap>;
1059
1427
  }): Promise<Array<T>>;
1060
1428
  /**
1061
- * Deletes one or more records from the specified collection.
1062
- * @param params An object containing either the query or records to delete, and the collection name.
1063
- * @param params.query The query defining which records to delete.
1064
- * @param params.records An array of records to delete.
1065
- * @returns A promise that resolves to the number of deleted records or the deleted records themselves.
1429
+ * Deletes one or more records from the collection.
1430
+ * @param params The query defining which records to delete.
1431
+ * @returns A promise that resolves to the number of deleted records.
1066
1432
  */
1067
1433
  delete(params: {
1068
- query: QueryFilter<T, any>;
1434
+ query: QueryFilter<T, FunctionMap>;
1069
1435
  }): Promise<number>;
1070
1436
  /**
1071
- * Validates an object against a schema.
1072
- * @param params An object containing the data, and collection name.
1073
- * @param params.data The object to validate.
1074
- * @returns An object containing validation results.
1437
+ * Validates an object against the collection's schema.
1438
+ * @param data The object to validate.
1439
+ * @returns Validation results.
1075
1440
  */
1076
1441
  validate(data: any): {
1077
1442
  valid: boolean;
1078
1443
  issues: ReadonlyArray<StandardSchemaV1.Issue> | null;
1079
1444
  };
1080
1445
  /**
1081
- * Subscribe to persistence events
1082
- * @param event - The event to subscribe to
1083
- * @param callback - A callback to handle the event
1084
- * @returns A callback that can be used to unsubscribe from the event
1446
+ * Rolls back the collection to a previous schema version.
1447
+ * @param version The version to roll back to (optional).
1448
+ * @param dryRun Whether to simulate the rollback.
1449
+ * @returns A promise that resolves to the new schema and data preview, or undefined.
1085
1450
  */
1086
- subscribe(event: PersistenceEventType, callback: (payload: PersistenceEvent<T>) => void): () => void;
1087
1451
  rollback(version?: string, dryRun?: boolean): Promise<{
1088
- newSchema: SchemaDefinition;
1089
- dataPreview: ReadableStream<any>;
1452
+ schema: SchemaDefinition;
1453
+ preview: ReadableStream<any>;
1090
1454
  } | undefined>;
1455
+ /**
1456
+ * Applies a schema migration to the collection.
1457
+ * @param description A description of the migration.
1458
+ * @param cb A callback defining the transformation logic.
1459
+ * @param dryRun Whether to simulate the migration.
1460
+ * @returns A promise that resolves to the new schema and data preview, or undefined.
1461
+ */
1091
1462
  migrate(description: string, cb: (h: Omit<SchemaMigrationHelper, "changes">) => DataTransform<any, any> | undefined, dryRun?: boolean): Promise<{
1092
- newSchema: SchemaDefinition;
1093
- dataPreview: ReadableStream<any>;
1463
+ schema: SchemaDefinition;
1464
+ preview: ReadableStream<any>;
1094
1465
  } | undefined>;
1095
1466
  }
1096
1467
  /**
1097
- * Defines the possible event types for persistence operations
1468
+ * Context for collection-specific triggers.
1469
+ */
1470
+ type CollectionTriggerContext<T, FunctionMap = Record<string, any>> = {
1471
+ event: PersistenceEvent<T> & {
1472
+ type: "create:start";
1473
+ operation: "create";
1474
+ };
1475
+ persistence: Persistence<FunctionMap>;
1476
+ collection: PersistenceCollection<T, FunctionMap>;
1477
+ params: {
1478
+ data: T | T[];
1479
+ };
1480
+ results: undefined;
1481
+ } | {
1482
+ event: PersistenceEvent<T> & {
1483
+ type: "create:success";
1484
+ operation: "create";
1485
+ };
1486
+ persistence: Persistence<FunctionMap>;
1487
+ collection: PersistenceCollection<T, FunctionMap>;
1488
+ params: {
1489
+ data: T | T[];
1490
+ };
1491
+ results: T | T[];
1492
+ } | {
1493
+ event: PersistenceEvent<T> & {
1494
+ type: "create:failed";
1495
+ operation: "create";
1496
+ };
1497
+ persistence: Persistence<FunctionMap>;
1498
+ collection: PersistenceCollection<T, FunctionMap>;
1499
+ params: {
1500
+ data: T | T[];
1501
+ };
1502
+ results: undefined;
1503
+ } | {
1504
+ event: PersistenceEvent<T> & {
1505
+ type: "read:start";
1506
+ operation: "read";
1507
+ };
1508
+ persistence: Persistence<FunctionMap>;
1509
+ collection: PersistenceCollection<T, FunctionMap>;
1510
+ params: {
1511
+ query: QueryDSL<T, FunctionMap>;
1512
+ };
1513
+ results: undefined;
1514
+ } | {
1515
+ event: PersistenceEvent<T> & {
1516
+ type: "read:success";
1517
+ operation: "read";
1518
+ };
1519
+ persistence: Persistence<FunctionMap>;
1520
+ collection: PersistenceCollection<T, FunctionMap>;
1521
+ params: {
1522
+ query: QueryDSL<T, FunctionMap>;
1523
+ };
1524
+ results: T | T[];
1525
+ } | {
1526
+ event: PersistenceEvent<T> & {
1527
+ type: "read:failed";
1528
+ operation: "read";
1529
+ };
1530
+ persistence: Persistence<FunctionMap>;
1531
+ collection: PersistenceCollection<T, FunctionMap>;
1532
+ params: {
1533
+ query: QueryDSL<T, FunctionMap>;
1534
+ };
1535
+ results: undefined;
1536
+ } | {
1537
+ event: PersistenceEvent<T> & {
1538
+ type: "update:start";
1539
+ operation: "update";
1540
+ };
1541
+ persistence: Persistence<FunctionMap>;
1542
+ collection: PersistenceCollection<T, FunctionMap>;
1543
+ params: {
1544
+ data?: Partial<T>;
1545
+ patch?: PatchOperation | Array<PatchOperation>;
1546
+ query: QueryFilter<T, FunctionMap>;
1547
+ };
1548
+ results: undefined;
1549
+ } | {
1550
+ event: PersistenceEvent<T> & {
1551
+ type: "update:success";
1552
+ operation: "update";
1553
+ };
1554
+ persistence: Persistence<FunctionMap>;
1555
+ collection: PersistenceCollection<T, FunctionMap>;
1556
+ params: {
1557
+ data?: Partial<T>;
1558
+ patch?: PatchOperation | Array<PatchOperation>;
1559
+ query: QueryFilter<T, FunctionMap>;
1560
+ };
1561
+ results: Array<T>;
1562
+ } | {
1563
+ event: PersistenceEvent<T> & {
1564
+ type: "update:failed";
1565
+ operation: "update";
1566
+ };
1567
+ persistence: Persistence<FunctionMap>;
1568
+ collection: PersistenceCollection<T, FunctionMap>;
1569
+ params: {
1570
+ data?: Partial<T>;
1571
+ patch?: PatchOperation | Array<PatchOperation>;
1572
+ query: QueryFilter<T, FunctionMap>;
1573
+ };
1574
+ results: undefined;
1575
+ } | {
1576
+ event: PersistenceEvent<T> & {
1577
+ type: "delete:start";
1578
+ operation: "delete";
1579
+ };
1580
+ persistence: Persistence<FunctionMap>;
1581
+ collection: PersistenceCollection<T, FunctionMap>;
1582
+ params: {
1583
+ query: QueryFilter<T, FunctionMap>;
1584
+ };
1585
+ results: undefined;
1586
+ } | {
1587
+ event: PersistenceEvent<T> & {
1588
+ type: "delete:success";
1589
+ operation: "delete";
1590
+ };
1591
+ persistence: Persistence<FunctionMap>;
1592
+ collection: PersistenceCollection<T, FunctionMap>;
1593
+ params: {
1594
+ query: QueryFilter<T, FunctionMap>;
1595
+ };
1596
+ results: number;
1597
+ } | {
1598
+ event: PersistenceEvent<T> & {
1599
+ type: "delete:failed";
1600
+ operation: "delete";
1601
+ };
1602
+ persistence: Persistence<FunctionMap>;
1603
+ collection: PersistenceCollection<T, FunctionMap>;
1604
+ params: {
1605
+ query: QueryFilter<T, FunctionMap>;
1606
+ };
1607
+ results: undefined;
1608
+ } | {
1609
+ event: PersistenceEvent<T> & {
1610
+ type: "migrate:start";
1611
+ operation: "migrate";
1612
+ };
1613
+ persistence: Persistence<FunctionMap>;
1614
+ collection: PersistenceCollection<T, FunctionMap>;
1615
+ params: {
1616
+ description: string;
1617
+ dryRun?: boolean;
1618
+ };
1619
+ results: undefined;
1620
+ } | {
1621
+ event: PersistenceEvent<T> & {
1622
+ type: "migrate:success";
1623
+ operation: "migrate";
1624
+ };
1625
+ persistence: Persistence<FunctionMap>;
1626
+ collection: PersistenceCollection<T, FunctionMap>;
1627
+ params: {
1628
+ description: string;
1629
+ dryRun?: boolean;
1630
+ };
1631
+ results: {
1632
+ schema: SchemaDefinition;
1633
+ preview: ReadableStream<any>;
1634
+ } | undefined;
1635
+ } | {
1636
+ event: PersistenceEvent<T> & {
1637
+ type: "migrate:failed";
1638
+ operation: "migrate";
1639
+ };
1640
+ persistence: Persistence<FunctionMap>;
1641
+ collection: PersistenceCollection<T, FunctionMap>;
1642
+ params: {
1643
+ description: string;
1644
+ dryRun?: boolean;
1645
+ };
1646
+ results: undefined;
1647
+ } | {
1648
+ event: PersistenceEvent<T> & {
1649
+ type: "rollback:start";
1650
+ operation: "rollback";
1651
+ };
1652
+ persistence: Persistence<FunctionMap>;
1653
+ collection: PersistenceCollection<T, FunctionMap>;
1654
+ params: {
1655
+ version?: string;
1656
+ dryRun?: boolean;
1657
+ };
1658
+ results: undefined;
1659
+ } | {
1660
+ event: PersistenceEvent<T> & {
1661
+ type: "rollback:success";
1662
+ operation: "rollback";
1663
+ };
1664
+ persistence: Persistence<FunctionMap>;
1665
+ collection: PersistenceCollection<T, FunctionMap>;
1666
+ params: {
1667
+ version?: string;
1668
+ dryRun?: boolean;
1669
+ };
1670
+ results: {
1671
+ schema: SchemaDefinition;
1672
+ preview: ReadableStream<any>;
1673
+ } | undefined;
1674
+ } | {
1675
+ event: PersistenceEvent<T> & {
1676
+ type: "rollback:failed";
1677
+ operation: "rollback";
1678
+ };
1679
+ persistence: Persistence<FunctionMap>;
1680
+ collection: PersistenceCollection<T, FunctionMap>;
1681
+ params: {
1682
+ version?: string;
1683
+ dryRun?: boolean;
1684
+ };
1685
+ results: undefined;
1686
+ };
1687
+ /**
1688
+ * Context for global triggers (Persistence-level, non-collection-specific).
1098
1689
  */
1099
- 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" | "read: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:update:start" | "collection:update:success" | "collection:update:failed" | "collection:delete:start" | "collection:delete:success" | "collection:delete:failed";
1690
+ type GlobalTriggerContext<T, FunctionMap = Record<string, any>> = {
1691
+ event: PersistenceEvent<T> & {
1692
+ 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";
1693
+ operation: "transaction" | "collection:create" | "collection:delete";
1694
+ };
1695
+ persistence: Persistence<FunctionMap>;
1696
+ collection?: undefined;
1697
+ params: any;
1698
+ results: any;
1699
+ };
1100
1700
  /**
1101
- * Interface representing events emitted during persistence operations
1701
+ * Union of trigger contexts.
1102
1702
  */
1103
- interface PersistenceEvent<DataType> {
1104
- /**
1105
- * The type of event (e.g., 'create:start', 'read:success')
1106
- */
1107
- type: PersistenceEventType;
1108
- /**
1109
- * Timestamp when the event occurred
1110
- */
1111
- timestamp: number;
1112
- /**
1113
- * The operation being performed (e.g., 'create', 'read')
1114
- */
1115
- operation: string;
1116
- /**
1117
- * Name of the collection affected by the operation (if applicable)
1118
- */
1119
- collection?: string;
1120
- /**
1121
- * Data passed to the operation (if applicable)
1122
- */
1123
- input?: any;
1124
- /**
1125
- * Data returned by the operation (if applicable)
1126
- */
1127
- output?: any;
1128
- /**
1129
- * Error object if the operation failed (if applicable)
1130
- */
1131
- error?: Error;
1132
- /**
1133
- * issues that caused the operation to fail (if applicable)
1134
- */
1135
- issues?: Array<StandardSchemaV1.Issue>;
1136
- /**
1137
- * Query used in the operation (if applicable)
1138
- */
1139
- query?: QueryDSL<DataType, any>;
1140
- /**
1141
- * Identifier for the transaction (if part of one)
1142
- */
1143
- transactionId?: string;
1144
- /**
1145
- * Duration of the operation in milliseconds.
1146
- * Useful for performance monitoring.
1147
- */
1148
- duration?: number;
1149
- /**
1150
- * Additional context or metadata specific to the operation.
1151
- * This field can be used to include extra debugging or contextual data.
1152
- */
1153
- context?: Record<string, any>;
1154
- }
1703
+ type TriggerContext<T, FunctionMap = Record<string, any>> = CollectionTriggerContext<T, FunctionMap> | GlobalTriggerContext<T, FunctionMap>;
1704
+ /**
1705
+ * Defines a schedule for a task.
1706
+ */
1707
+ type TaskSchedule = {
1708
+ cron: string;
1709
+ } | {
1710
+ at: string;
1711
+ } | {
1712
+ interval: number;
1713
+ };
1714
+ /**
1715
+ * Context provided to task callbacks.
1716
+ */
1717
+ type TaskContext<T, FunctionMap = Record<string, any>> = {
1718
+ persistence: Persistence<FunctionMap>;
1719
+ collection: PersistenceCollection<T, FunctionMap>;
1720
+ taskId: string;
1721
+ executionTime: number;
1722
+ metadata?: Record<string, any>;
1723
+ label: string;
1724
+ description: string;
1725
+ } | {
1726
+ persistence: Persistence<FunctionMap>;
1727
+ collection?: undefined;
1728
+ taskId: string;
1729
+ executionTime: number;
1730
+ metadata?: Record<string, any>;
1731
+ label: string;
1732
+ description: string;
1733
+ };
1155
1734
 
1156
1735
  type SchemaIndex = {
1157
1736
  schema: string;
@@ -1491,9 +2070,10 @@ declare class SchemaRegistry implements SchemaRegistryInterface {
1491
2070
  }
1492
2071
 
1493
2072
  /**
1494
- * @fileoverview Provides a MigrationEngine class that handles schema migrations,
2073
+ * @fileoverview
2074
+ * Provides a MigrationEngine class that handles schema migrations,
1495
2075
  * including validation, checksum generation, and migration application.
1496
- * @author Your Name
2076
+ * @author Saidimu
1497
2077
  */
1498
2078
 
1499
2079
  /**
@@ -1869,4 +2449,4 @@ declare function docgen(schema: SchemaDefinition, options?: {
1869
2449
  faker?: Faker;
1870
2450
  }): string;
1871
2451
 
1872
- export { type ArrayHint, type BooleanHint, type Constraint, type ConstraintGroup, type ConstraintParameters, type ConstraintsMap, type DataTransform, type DateHint, type DynamicHint, type EnumHint, type FieldDefinition, type FieldGroup, type FieldSchema, type FieldType, type FileHint, type FunctionMap, type GroupDefinition, type IndexDefinition, type IndexType, type InputHint, JsonPatchError, type LogicalOperator, type Migration, MigrationEngine, type MigrationEngineInterface, MigrationError, MigrationErrorCode, type MigrationMetadata, type NestedSchemaDefinition, type NumberHint, type ObjectHint, 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 TextHint, type TransformFunction, applyPatch, calculateNextVersion, compareSemanticVersions, createGitSchemaRegistry, createPatch, createSchemaMigrationHelper, createStandardSchemaValidator, deepMerge, docgen, extractInputFieldGroups, formResolver, generateSHA256Hash, normalizePath, schemaChangeToPatch, schemaDefaults, schemaToTypes, serializeParams, sortSemanticVars, validate, validateMigration, validateSchemaChange, validateSchemaDefinition };
2452
+ 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 };