@workglow/storage 0.0.52

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 (74) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1015 -0
  3. package/dist/browser.js +2635 -0
  4. package/dist/browser.js.map +27 -0
  5. package/dist/bun.js +3880 -0
  6. package/dist/bun.js.map +35 -0
  7. package/dist/common-server.d.ts +23 -0
  8. package/dist/common-server.d.ts.map +1 -0
  9. package/dist/common.d.ts +16 -0
  10. package/dist/common.d.ts.map +1 -0
  11. package/dist/kv/FsFolderJsonKvRepository.d.ts +27 -0
  12. package/dist/kv/FsFolderJsonKvRepository.d.ts.map +1 -0
  13. package/dist/kv/FsFolderKvRepository.d.ts +74 -0
  14. package/dist/kv/FsFolderKvRepository.d.ts.map +1 -0
  15. package/dist/kv/IKvRepository.d.ts +65 -0
  16. package/dist/kv/IKvRepository.d.ts.map +1 -0
  17. package/dist/kv/InMemoryKvRepository.d.ts +26 -0
  18. package/dist/kv/InMemoryKvRepository.d.ts.map +1 -0
  19. package/dist/kv/IndexedDbKvRepository.d.ts +27 -0
  20. package/dist/kv/IndexedDbKvRepository.d.ts.map +1 -0
  21. package/dist/kv/KvRepository.d.ts +109 -0
  22. package/dist/kv/KvRepository.d.ts.map +1 -0
  23. package/dist/kv/KvViaTabularRepository.d.ts +64 -0
  24. package/dist/kv/KvViaTabularRepository.d.ts.map +1 -0
  25. package/dist/kv/PostgresKvRepository.d.ts +28 -0
  26. package/dist/kv/PostgresKvRepository.d.ts.map +1 -0
  27. package/dist/kv/SqliteKvRepository.d.ts +28 -0
  28. package/dist/kv/SqliteKvRepository.d.ts.map +1 -0
  29. package/dist/kv/SupabaseKvRepository.d.ts +34 -0
  30. package/dist/kv/SupabaseKvRepository.d.ts.map +1 -0
  31. package/dist/node.js +3879 -0
  32. package/dist/node.js.map +35 -0
  33. package/dist/queue/IQueueStorage.d.ts +125 -0
  34. package/dist/queue/IQueueStorage.d.ts.map +1 -0
  35. package/dist/queue/InMemoryQueueStorage.d.ts +109 -0
  36. package/dist/queue/InMemoryQueueStorage.d.ts.map +1 -0
  37. package/dist/queue/IndexedDbQueueStorage.d.ts +89 -0
  38. package/dist/queue/IndexedDbQueueStorage.d.ts.map +1 -0
  39. package/dist/queue/PostgresQueueStorage.d.ts +92 -0
  40. package/dist/queue/PostgresQueueStorage.d.ts.map +1 -0
  41. package/dist/queue/SqliteQueueStorage.d.ts +116 -0
  42. package/dist/queue/SqliteQueueStorage.d.ts.map +1 -0
  43. package/dist/queue/SupabaseQueueStorage.d.ts +93 -0
  44. package/dist/queue/SupabaseQueueStorage.d.ts.map +1 -0
  45. package/dist/tabular/BaseSqlTabularRepository.d.ts +94 -0
  46. package/dist/tabular/BaseSqlTabularRepository.d.ts.map +1 -0
  47. package/dist/tabular/CachedTabularRepository.d.ts +110 -0
  48. package/dist/tabular/CachedTabularRepository.d.ts.map +1 -0
  49. package/dist/tabular/FsFolderTabularRepository.d.ts +92 -0
  50. package/dist/tabular/FsFolderTabularRepository.d.ts.map +1 -0
  51. package/dist/tabular/ITabularRepository.d.ts +52 -0
  52. package/dist/tabular/ITabularRepository.d.ts.map +1 -0
  53. package/dist/tabular/InMemoryTabularRepository.d.ts +93 -0
  54. package/dist/tabular/InMemoryTabularRepository.d.ts.map +1 -0
  55. package/dist/tabular/IndexedDbTabularRepository.d.ts +100 -0
  56. package/dist/tabular/IndexedDbTabularRepository.d.ts.map +1 -0
  57. package/dist/tabular/PostgresTabularRepository.d.ts +133 -0
  58. package/dist/tabular/PostgresTabularRepository.d.ts.map +1 -0
  59. package/dist/tabular/SharedInMemoryTabularRepository.d.ts +126 -0
  60. package/dist/tabular/SharedInMemoryTabularRepository.d.ts.map +1 -0
  61. package/dist/tabular/SqliteTabularRepository.d.ts +110 -0
  62. package/dist/tabular/SqliteTabularRepository.d.ts.map +1 -0
  63. package/dist/tabular/SupabaseTabularRepository.d.ts +132 -0
  64. package/dist/tabular/SupabaseTabularRepository.d.ts.map +1 -0
  65. package/dist/tabular/TabularRepository.d.ts +123 -0
  66. package/dist/tabular/TabularRepository.d.ts.map +1 -0
  67. package/dist/types.d.ts +7 -0
  68. package/dist/types.d.ts.map +1 -0
  69. package/dist/util/IndexedDbTable.d.ts +40 -0
  70. package/dist/util/IndexedDbTable.d.ts.map +1 -0
  71. package/package.json +60 -0
  72. package/src/kv/README.md +159 -0
  73. package/src/queue/README.md +41 -0
  74. package/src/tabular/README.md +298 -0
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { DataPortSchemaObject, FromSchema, JsonSchema } from "@workglow/util";
7
+ import { ValueOptionType } from "./ITabularRepository";
8
+ import { TabularRepository } from "./TabularRepository";
9
+ /**
10
+ * Base class for SQL-based tabular repositories that implements common functionality
11
+ * for both SQLite and PostgreSQL database implementations.
12
+ *
13
+ * @template Schema - The schema definition for the entity using JSON Schema
14
+ * @template PrimaryKeyNames - Array of property names that form the primary key
15
+ */
16
+ export declare abstract class BaseSqlTabularRepository<Schema extends DataPortSchemaObject, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]>, Entity = FromSchema<Schema>, PrimaryKey = Pick<Entity, PrimaryKeyNames[number] & keyof Entity>, Value = Omit<Entity, PrimaryKeyNames[number] & keyof Entity>> extends TabularRepository<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value> {
17
+ protected readonly table: string;
18
+ /**
19
+ * Creates a new instance of BaseSqlTabularRepository
20
+ * @param table - The name of the database table to use for storage
21
+ * @param schema - Schema defining the structure of the entity
22
+ * @param primaryKeyNames - Array of property names that form the primary key
23
+ * @param indexes - Array of columns or column arrays to make searchable. Each string or single column creates a single-column index,
24
+ * while each array creates a compound index with columns in the specified order.
25
+ */
26
+ constructor(table: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: Array<keyof Entity | Array<keyof Entity>>);
27
+ /**
28
+ * Maps JavaScript/TypeScript types to their corresponding SQL type
29
+ * Must be implemented by derived classes for specific SQL dialects
30
+ */
31
+ protected abstract mapTypeToSQL(typeDef: JsonSchema): string;
32
+ /**
33
+ * Generates the SQL column definitions for primary key fields
34
+ * @returns SQL string containing primary key column definitions
35
+ */
36
+ protected constructPrimaryKeyColumns($delimiter?: string): string;
37
+ /**
38
+ * Generates the SQL column definitions for value fields
39
+ * @returns SQL string containing value column definitions
40
+ */
41
+ protected constructValueColumns($delimiter?: string): string;
42
+ /**
43
+ * Determines if a schema type allows null values
44
+ * @param typeDef - The schema type definition
45
+ * @returns true if the type allows null values
46
+ */
47
+ protected isNullable(typeDef: JsonSchema): boolean;
48
+ /**
49
+ * Returns a comma-separated list of primary key column names
50
+ * @returns Formatted string of primary key column names
51
+ */
52
+ protected primaryKeyColumnList($delimiter?: string): string;
53
+ /**
54
+ * Returns a comma-separated list of value column names
55
+ * @returns Formatted string of value column names
56
+ */
57
+ protected valueColumnList($delimiter?: string): string;
58
+ /**
59
+ * Gets the real underlying type from possibly union types
60
+ * For example, for a union with null, this extracts the non-null type
61
+ * @param typeDef - The schema to extract from
62
+ * @returns The non-null type from the schema
63
+ */
64
+ protected getNonNullType(typeDef: JsonSchema): JsonSchema;
65
+ /**
66
+ * Converts a value object into an ordered array based on the valueSchema
67
+ * This ensures consistent parameter ordering for SQL queries
68
+ * @param value - The value object to convert
69
+ * @returns Array of values ordered according to the schema
70
+ * @throws Error if a required field is missing
71
+ */
72
+ protected getValueAsOrderedArray(value: Value): ValueOptionType[];
73
+ /**
74
+ * Converts a primary key object into an ordered array based on the schema
75
+ * This ensures consistent parameter ordering for storage operations
76
+ * @param key - The primary key object to convert
77
+ * @returns Array of key values ordered according to the schema
78
+ */
79
+ protected getPrimaryKeyAsOrderedArray(key: PrimaryKey): ValueOptionType[];
80
+ protected jsToSqlValue(column: string, value: Entity[keyof Entity]): ValueOptionType;
81
+ protected sqlToJsValue(column: string, value: ValueOptionType): Entity[keyof Entity];
82
+ /**
83
+ * Validates table name and schema configurations
84
+ * Checks for:
85
+ * 1. Valid table name format
86
+ * 2. Valid schema key names
87
+ * 3. No duplicate keys between primary key and value schemas
88
+ * This is a sanity check to make sure the table and schema are valid,
89
+ * and to prevent dumb mistakes and mischevious behavior.
90
+ * @throws Error if validation fails
91
+ */
92
+ protected validateTableAndSchema(): void;
93
+ }
94
+ //# sourceMappingURL=BaseSqlTabularRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseSqlTabularRepository.d.ts","sourceRoot":"","sources":["../../src/tabular/BaseSqlTabularRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIxD;;;;;;GAMG;AACH,8BAAsB,wBAAwB,CAC5C,MAAM,SAAS,oBAAoB,EACnC,eAAe,SAAS,aAAa,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,EAEjE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,EAC3B,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,EACjE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,CAC5D,SAAQ,iBAAiB,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC;IAU3E,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;IATlC;;;;;;;OAOG;gBAEkB,KAAK,EAAE,MAAM,YAAkB,EAClD,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,eAAe,EAChC,OAAO,GAAE,KAAK,CAAC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,MAAM,CAAC,CAAM;IAMzD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM;IAE5D;;;OAGG;IACH,SAAS,CAAC,0BAA0B,CAAC,UAAU,GAAE,MAAW,GAAG,MAAM;IAUrE;;;OAGG;IACH,SAAS,CAAC,qBAAqB,CAAC,UAAU,GAAE,MAAW,GAAG,MAAM;IAkBhE;;;;OAIG;IACH,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO;IA0BlD;;;OAGG;IACH,SAAS,CAAC,oBAAoB,CAAC,UAAU,GAAE,MAAW,GAAG,MAAM;IAI/D;;;OAGG;IACH,SAAS,CAAC,eAAe,CAAC,UAAU,GAAE,MAAW,GAAG,MAAM;IAI1D;;;;;OAKG;IACH,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU;IAkBzD;;;;;;OAMG;IACH,SAAS,CAAC,sBAAsB,CAAC,KAAK,EAAE,KAAK,GAAG,eAAe,EAAE;IAyBjE;;;;;OAKG;IACH,SAAS,CAAC,2BAA2B,CAAC,GAAG,EAAE,UAAU,GAAG,eAAe,EAAE;IAiBzE,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,MAAM,CAAC,GAAG,eAAe;IAqCpF,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,MAAM,CAAC;IAgCpF;;;;;;;;;OASG;IACH,SAAS,CAAC,sBAAsB,IAAI,IAAI;CAgCzC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { DataPortSchemaObject, FromSchema } from "@workglow/util";
7
+ import { ITabularRepository } from "./ITabularRepository";
8
+ import { TabularRepository } from "./TabularRepository";
9
+ export declare const CACHED_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<ITabularRepository<any, any, any, any, any>>;
10
+ /**
11
+ * A tabular repository wrapper that adds caching layer to a durable repository.
12
+ * Uses InMemoryTabularRepository or SharedInMemoryTabularRepository as a cache
13
+ * for faster access to frequently used data.
14
+ *
15
+ * @template Schema - The schema definition for the entity using JSON Schema
16
+ * @template PrimaryKeyNames - Array of property names that form the primary key
17
+ */
18
+ export declare class CachedTabularRepository<Schema extends DataPortSchemaObject, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]>, Entity = FromSchema<Schema>, PrimaryKey = Pick<Entity, PrimaryKeyNames[number] & keyof Entity>, Value = Omit<Entity, PrimaryKeyNames[number] & keyof Entity>> extends TabularRepository<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value> {
19
+ readonly cache: ITabularRepository<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value>;
20
+ private durable;
21
+ private cacheInitialized;
22
+ /**
23
+ * Creates a new CachedTabularRepository instance
24
+ * @param durable - The durable repository to use as the source of truth
25
+ * @param cache - Optional cache repository (InMemoryTabularRepository or SharedInMemoryTabularRepository).
26
+ * If not provided, a new InMemoryTabularRepository will be created.
27
+ * @param schema - Schema defining the structure of the entity
28
+ * @param primaryKeyNames - Array of property names that form the primary key
29
+ * @param indexes - Array of columns or column arrays to make searchable. Each string or single column creates a single-column index,
30
+ * while each array creates a compound index with columns in the specified order.
31
+ */
32
+ constructor(durable: ITabularRepository<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value>, cache?: ITabularRepository<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value>, schema?: Schema, primaryKeyNames?: PrimaryKeyNames, indexes?: Array<keyof Entity | Array<keyof Entity>>);
33
+ /**
34
+ * Sets up event forwarding from cache and durable repositories
35
+ */
36
+ private setupEventForwarding;
37
+ /**
38
+ * Initializes the cache by loading all data from the durable repository
39
+ */
40
+ private initializeCache;
41
+ /**
42
+ * Stores a key-value pair in both cache and durable repository
43
+ * @param value - The combined object to store
44
+ * @returns The stored entity
45
+ * @emits 'put' event with the stored entity when successful
46
+ */
47
+ put(value: Entity): Promise<Entity>;
48
+ /**
49
+ * Stores multiple key-value pairs in both cache and durable repository
50
+ * @param values - Array of combined objects to store
51
+ * @returns Array of stored entities
52
+ * @emits 'put' event for each value stored
53
+ */
54
+ putBulk(values: Entity[]): Promise<Entity[]>;
55
+ /**
56
+ * Retrieves a value by its key, checking cache first, then durable repository
57
+ * @param key - The primary key object to look up
58
+ * @returns The value object if found, undefined otherwise
59
+ * @emits 'get' event with the fingerprint ID and value when found
60
+ */
61
+ get(key: PrimaryKey): Promise<Entity | undefined>;
62
+ /**
63
+ * Searches for entries matching a partial key
64
+ * @param key - Partial key object to search for
65
+ * @returns Array of matching combined objects
66
+ * @throws Error if search criteria outside of searchable fields
67
+ */
68
+ search(key: Partial<Entity>): Promise<Entity[] | undefined>;
69
+ /**
70
+ * Deletes an entry from both cache and durable repository
71
+ * @param value - The primary key object or entity of the entry to delete
72
+ * @emits 'delete' event with the fingerprint ID when successful
73
+ */
74
+ delete(value: PrimaryKey | Entity): Promise<void>;
75
+ /**
76
+ * Removes all entries from both cache and durable repository
77
+ * @emits 'clearall' event when successful
78
+ */
79
+ deleteAll(): Promise<void>;
80
+ /**
81
+ * Returns an array of all entries in the repository
82
+ * @returns Array of all entries in the repository
83
+ */
84
+ getAll(): Promise<Entity[] | undefined>;
85
+ /**
86
+ * Returns the number of entries in the repository
87
+ * @returns The total count of stored entries
88
+ */
89
+ size(): Promise<number>;
90
+ /**
91
+ * Deletes all entries with a date column value matching the provided criteria
92
+ * @param column - The name of the date column to compare against
93
+ * @param value - The value to compare against
94
+ * @param operator - The operator to use for comparison
95
+ */
96
+ deleteSearch(column: keyof Entity, value: Entity[keyof Entity], operator?: "=" | "<" | "<=" | ">" | ">="): Promise<void>;
97
+ /**
98
+ * Invalidates the cache by clearing it and resetting initialization flag
99
+ */
100
+ invalidateCache(): Promise<void>;
101
+ /**
102
+ * Refreshes the cache by reloading all data from the durable repository
103
+ */
104
+ refreshCache(): Promise<void>;
105
+ /**
106
+ * Destroys the durable and cache repositories.
107
+ */
108
+ destroy(): void;
109
+ }
110
+ //# sourceMappingURL=CachedTabularRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CachedTabularRepository.d.ts","sourceRoot":"","sources":["../../src/tabular/CachedTabularRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAsB,oBAAoB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,eAAO,MAAM,yBAAyB,oFAED,CAAC;AAEtC;;;;;;;GAOG;AACH,qBAAa,uBAAuB,CAClC,MAAM,SAAS,oBAAoB,EACnC,eAAe,SAAS,aAAa,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,EAEjE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,EAC3B,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,EACjE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,CAC5D,SAAQ,iBAAiB,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC;IAC7E,SAAgB,KAAK,EAAE,kBAAkB,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IAC9F,OAAO,CAAC,OAAO,CAAyE;IACxF,OAAO,CAAC,gBAAgB,CAAS;IAEjC;;;;;;;;;OASG;gBAED,OAAO,EAAE,kBAAkB,CAAC,MAAM,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AC5C,OAAO,CAAC,IAAI,CAAC;IAUhB;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtC;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAMnC;;OAEG;IACH,OAAO,IAAI,IAAI;CAIhB"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { DataPortSchemaObject, FromSchema } from "@workglow/util";
7
+ import { ITabularRepository } from "./ITabularRepository";
8
+ import { TabularRepository } from "./TabularRepository";
9
+ export declare const FS_FOLDER_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<ITabularRepository<any, any, any, any, any>>;
10
+ /**
11
+ * A tabular repository implementation that uses the filesystem for storage.
12
+ * Each row is stored as a separate JSON file in the specified directory.
13
+ *
14
+ * @template Schema - The schema definition for the entity
15
+ * @template PrimaryKeyNames - Array of property names that form the primary key
16
+ */
17
+ export declare class FsFolderTabularRepository<Schema extends DataPortSchemaObject, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]>, Entity = FromSchema<Schema>, PrimaryKey = Pick<Entity, PrimaryKeyNames[number] & keyof Entity>, Value = Omit<Entity, PrimaryKeyNames[number] & keyof Entity>> extends TabularRepository<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value> {
18
+ private folderPath;
19
+ /**
20
+ * Creates a new FsFolderTabularRepository instance.
21
+ *
22
+ * @param folderPath - The directory path where the JSON files will be stored
23
+ * @param schema - Schema defining the structure of the entity
24
+ * @param primaryKeyNames - Array of property names that form the primary key
25
+ * @param indexes - Note: indexes are not supported in this implementation.
26
+ */
27
+ constructor(folderPath: string, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: Array<keyof Entity | Array<keyof Entity>>);
28
+ /**
29
+ * Sets up the directory for the repository (creates directory)
30
+ */
31
+ setupDirectory(): Promise<void>;
32
+ /**
33
+ * Stores a row in the repository
34
+ * @param entity - The entity to store
35
+ * @returns The stored entity
36
+ * @emits 'put' event when successful
37
+ */
38
+ put(entity: Entity): Promise<Entity>;
39
+ /**
40
+ * Stores multiple rows in the repository in a bulk operation
41
+ * @param entities - Array of entities to store
42
+ * @returns Array of stored entities
43
+ * @emits 'put' event for each entity stored
44
+ */
45
+ putBulk(entities: Entity[]): Promise<Entity[]>;
46
+ /**
47
+ * Retrieves a value by its key
48
+ * @param key - The primary key object to look up
49
+ * @returns The value object if found, undefined otherwise
50
+ * @emits 'get' event with the fingerprint ID and value when found
51
+ */
52
+ get(key: PrimaryKey): Promise<Entity | undefined>;
53
+ /**
54
+ * Deletes an entry by its key
55
+ * @param key - The primary key object of the entry to delete
56
+ * @emits 'delete' event with the fingerprint ID when successful
57
+ */
58
+ delete(value: PrimaryKey | Entity): Promise<void>;
59
+ /**
60
+ * Retrieves all rows stored in the repository
61
+ * @returns Array of combined objects (rows) if found, undefined otherwise
62
+ */
63
+ getAll(): Promise<Entity[] | undefined>;
64
+ /**
65
+ * Removes all entries from the repository
66
+ * @emits 'clearall' event when successful
67
+ */
68
+ deleteAll(): Promise<void>;
69
+ /**
70
+ * Returns the total number of stored rows
71
+ * @returns Promise resolving to the count of stored items
72
+ */
73
+ size(): Promise<number>;
74
+ /**
75
+ * Search is not supported in the filesystem implementation.
76
+ * @throws {Error} Always throws an error indicating search is not supported
77
+ */
78
+ search(key: Partial<Entity>): Promise<Entity[] | undefined>;
79
+ /**
80
+ * Generates the full filesystem path for a given key.
81
+ * @private
82
+ */
83
+ private getFilePath;
84
+ /**
85
+ * Deletes all entries with a date column value older than the provided date
86
+ * @param column - The name of the date column to compare against
87
+ * @param value - The value to compare against
88
+ * @param operator - The operator to use for comparison
89
+ */
90
+ deleteSearch(column: keyof Entity, value: Entity[keyof Entity], operator?: "=" | "<" | "<=" | ">" | ">="): Promise<void>;
91
+ }
92
+ //# sourceMappingURL=FsFolderTabularRepository.d.ts.map
@@ -0,0 +1 @@
1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G,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAevD;;;;OAIG;IACG,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYvD;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC;IA4B7C;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAOhC;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAQ7B;;;OAGG;IACG,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC;IAIjE;;;OAGG;YACW,WAAW;IAOzB;;;;;OAKG;IACG,YAAY,CAChB,MAAM,EAAE,MAAM,MAAM,EACpB,KAAK,EAAE,MAAM,CAAC,MAAM,MAAM,CAAC,EAC3B,QAAQ,GAAE,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAU,GAC5C,OAAO,CAAC,IAAI,CAAC;CAGjB"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { DataPortSchemaObject, EventParameters, FromSchema } from "@workglow/util";
7
+ export type ValueOptionType = string | number | bigint | boolean | null | Uint8Array;
8
+ /**
9
+ * Type definitions for tabular repository events
10
+ */
11
+ export type TabularEventListeners<PrimaryKey, Entity> = {
12
+ put: (entity: Entity) => void;
13
+ get: (key: PrimaryKey, entity: Entity | undefined) => void;
14
+ search: (key: Partial<Entity>, entities: Entity[] | undefined) => void;
15
+ delete: (key: keyof Entity) => void;
16
+ clearall: () => void;
17
+ };
18
+ export type TabularEventName = keyof TabularEventListeners<any, any>;
19
+ export type TabularEventListener<Event extends TabularEventName, PrimaryKey, Entity> = TabularEventListeners<PrimaryKey, Entity>[Event];
20
+ export type TabularEventParameters<Event extends TabularEventName, PrimaryKey, Entity> = EventParameters<TabularEventListeners<PrimaryKey, Entity>, Event>;
21
+ export type uuid4 = string;
22
+ export type JSONValue = string | number | boolean | null | JSONValue[] | {
23
+ [key: string]: JSONValue;
24
+ };
25
+ /**
26
+ * Interface defining the contract for tabular storage repositories.
27
+ * Provides a flexible interface for storing and retrieving data with typed
28
+ * primary keys and values, and supports compound keys and partial key lookup.
29
+ *
30
+ * @typeParam Schema - The schema definition for the entity using JSON Schema
31
+ * @typeParam PrimaryKeyNames - Array of property names that form the primary key
32
+ */
33
+ export interface ITabularRepository<Schema extends DataPortSchemaObject, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]>, Entity = FromSchema<Schema>, PrimaryKey = Pick<Entity, PrimaryKeyNames[number] & keyof Entity>, Value = Omit<Entity, PrimaryKeyNames[number] & keyof Entity>> {
34
+ put(value: Entity): Promise<Entity>;
35
+ putBulk(values: Entity[]): Promise<Entity[]>;
36
+ get(key: PrimaryKey): Promise<Entity | undefined>;
37
+ delete(key: PrimaryKey | Entity): Promise<void>;
38
+ getAll(): Promise<Entity[] | undefined>;
39
+ deleteAll(): Promise<void>;
40
+ size(): Promise<number>;
41
+ deleteSearch(column: keyof Entity, value: Entity[keyof Entity], operator: "=" | "<" | "<=" | ">" | ">="): Promise<void>;
42
+ on<Event extends TabularEventName>(name: Event, fn: TabularEventListener<Event, PrimaryKey, Entity>): void;
43
+ off<Event extends TabularEventName>(name: Event, fn: TabularEventListener<Event, PrimaryKey, Entity>): void;
44
+ emit<Event extends TabularEventName>(name: Event, ...args: TabularEventParameters<Event, PrimaryKey, Entity>): void;
45
+ once<Event extends TabularEventName>(name: Event, fn: TabularEventListener<Event, PrimaryKey, Entity>): void;
46
+ waitOn<Event extends TabularEventName>(name: Event): Promise<TabularEventParameters<Event, PrimaryKey, Entity>>;
47
+ search(key: Partial<Entity>): Promise<Entity[] | undefined>;
48
+ destroy(): void;
49
+ [Symbol.dispose](): void;
50
+ [Symbol.asyncDispose](): Promise<void>;
51
+ }
52
+ //# sourceMappingURL=ITabularRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ITabularRepository.d.ts","sourceRoot":"","sources":["../../src/tabular/ITabularRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGnF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,UAAU,CAAC;AAErF;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,UAAU,EAAE,MAAM,IAAI;IACtD,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,GAAG,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IAC3D,MAAM,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,KAAK,IAAI,CAAC;IACvE,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;IACpC,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,MAAM,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACrE,MAAM,MAAM,oBAAoB,CAC9B,KAAK,SAAS,gBAAgB,EAC9B,UAAU,EACV,MAAM,IACJ,qBAAqB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;AAErD,MAAM,MAAM,sBAAsB,CAChC,KAAK,SAAS,gBAAgB,EAC9B,UAAU,EACV,MAAM,IACJ,eAAe,CAAC,qBAAqB,CAAC,UAAU,EAAE,MAAM,C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AAG,IAAI,GACtC,OAAO,CAAC,IAAI,CAAC,CAAC;IAGjB,EAAE,CAAC,KAAK,SAAS,gBAAgB,EAC/B,IAAI,EAAE,KAAK,EACX,EAAE,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,GAClD,IAAI,CAAC;IACR,GAAG,CAAC,KAAK,SAAS,gBAAgB,EAChC,IAAI,EAAE,KAAK,EACX,EAAE,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,GAClD,IAAI,CAAC;IACR,IAAI,CAAC,KAAK,SAAS,gBAAgB,EACjC,IAAI,EAAE,KAAK,EACX,GAAG,IAAI,EAAE,sBAAsB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,GACzD,IAAI,CAAC;IACR,IAAI,CAAC,KAAK,SAAS,gBAAgB,EACjC,IAAI,EAAE,KAAK,EACX,EAAE,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,GAClD,IAAI,CAAC;IACR,MAAM,CAAC,KAAK,SAAS,gBAAgB,EACnC,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,sBAAsB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;IAG9D,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IAG5D,OAAO,IAAI,IAAI,CAAC;IAChB,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;IACzB,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { DataPortSchemaObject, FromSchema } from "@workglow/util";
7
+ import { ITabularRepository } from "./ITabularRepository";
8
+ import { TabularRepository } from "./TabularRepository";
9
+ export declare const MEMORY_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<ITabularRepository<any, any, any, any, any>>;
10
+ /**
11
+ * A generic in-memory key-value repository implementation.
12
+ * Provides a simple, non-persistent storage solution suitable for testing and caching scenarios.
13
+ *
14
+ * @template Schema - The schema definition for the entity using JSON Schema
15
+ * @template PrimaryKeyNames - Array of property names that form the primary key
16
+ */
17
+ export declare class InMemoryTabularRepository<Schema extends DataPortSchemaObject, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]>, Entity = FromSchema<Schema>, PrimaryKey = Pick<Entity, PrimaryKeyNames[number] & keyof Entity>, Value = Omit<Entity, PrimaryKeyNames[number] & keyof Entity>> extends TabularRepository<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value> {
18
+ /** Internal storage using a Map with fingerprint strings as keys */
19
+ values: Map<string, Entity>;
20
+ /**
21
+ * Creates a new InMemoryTabularRepository instance
22
+ * @param schema - Schema defining the structure of the entity
23
+ * @param primaryKeyNames - Array of property names that form the primary key
24
+ * @param indexes - Array of columns or column arrays to make searchable. Each string or single column creates a single-column index,
25
+ * while each array creates a compound index with columns in the specified order.
26
+ */
27
+ constructor(schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: Array<keyof Entity | Array<keyof Entity>>);
28
+ /**
29
+ * Sets up the database for the repository (no-op for in-memory)
30
+ */
31
+ setupDatabase(): Promise<void>;
32
+ /**
33
+ * Stores a key-value pair in the repository
34
+ * @param value - The combined object to store
35
+ * @returns The stored entity
36
+ * @emits 'put' event with the stored entity when successful
37
+ */
38
+ put(value: Entity): Promise<Entity>;
39
+ /**
40
+ * Stores multiple key-value pairs in the repository in a bulk operation
41
+ * @param values - Array of combined objects to store
42
+ * @returns Array of stored entities
43
+ * @emits 'put' event for each value stored
44
+ */
45
+ putBulk(values: Entity[]): Promise<Entity[]>;
46
+ /**
47
+ * Retrieves a value by its key
48
+ * @param key - The primary key object to look up
49
+ * @returns The value object if found, undefined otherwise
50
+ * @emits 'get' event with the fingerprint ID and value when found
51
+ */
52
+ get(key: PrimaryKey): Promise<Entity | undefined>;
53
+ /**
54
+ * Searches for entries matching a partial key
55
+ * @param key - Partial key object to search for
56
+ * @returns Array of matching combined objects
57
+ * @throws Error if search criteria outside of searchable fields
58
+ */
59
+ search(key: Partial<Entity>): Promise<Entity[] | undefined>;
60
+ /**
61
+ * Deletes an entry by its key
62
+ * @param key - The primary key object of the entry to delete
63
+ * @emits 'delete' event with the fingerprint ID when successful
64
+ */
65
+ delete(value: PrimaryKey | Entity): Promise<void>;
66
+ /**
67
+ * Removes all entries from the repository
68
+ * @emits 'clearall' event when successful
69
+ */
70
+ deleteAll(): Promise<void>;
71
+ /**
72
+ * Returns an array of all entries in the repository
73
+ * @returns Array of all entries in the repository
74
+ */
75
+ getAll(): Promise<Entity[] | undefined>;
76
+ /**
77
+ * Returns the number of entries in the repository
78
+ * @returns The total count of stored entries
79
+ */
80
+ size(): Promise<number>;
81
+ /**
82
+ * Deletes all entries with a date column value older than the provided date
83
+ * @param column - The name of the date column to compare against
84
+ * @param value - The value to compare against
85
+ * @param operator - The operator to use for comparison
86
+ */
87
+ deleteSearch(column: keyof Entity, value: Entity[keyof Entity], operator?: "=" | "<" | "<=" | ">" | ">="): Promise<void>;
88
+ /**
89
+ * Destroys the repository and frees up resources.
90
+ */
91
+ destroy(): void;
92
+ }
93
+ //# sourceMappingURL=InMemoryTabularRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryTabularRepository.d.ts","sourceRoot":"","sources":["../../src/tabular/InMemoryTabularRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEH,oBAAoB,EACpB,UAAU,EAEb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,eA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IAAI,OAAO,CAAC,IAAI,CAAC;IAKhC;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC;IAK7C;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAI7B;;;;;OAKG;IACG,YAAY,CAChB,MAAM,EAAE,MAAM,MAAM,EACpB,KAAK,EAAE,MAAM,CAAC,MAAM,MAAM,CAAC,EAC3B,QAAQ,GAAE,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAU,GAC5C,OAAO,CAAC,IAAI,CAAC;IA8BhB;;OAEG;IACH,OAAO,IAAI,IAAI;CAGhB"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { DataPortSchemaObject, FromSchema } from "@workglow/util";
7
+ import { MigrationOptions } from "../util/IndexedDbTable";
8
+ import { ITabularRepository } from "./ITabularRepository";
9
+ import { TabularRepository } from "./TabularRepository";
10
+ export declare const IDB_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<ITabularRepository<any, any, any, any, any>>;
11
+ /**
12
+ * A tabular repository implementation using IndexedDB for browser-based storage.
13
+ *
14
+ * @template Schema - The schema definition for the entity
15
+ * @template PrimaryKeyNames - Array of property names that form the primary key
16
+ */
17
+ export declare class IndexedDbTabularRepository<Schema extends DataPortSchemaObject, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]>, Entity = FromSchema<Schema>, PrimaryKey = Pick<Entity, PrimaryKeyNames[number] & keyof Entity>, Value = Omit<Entity, PrimaryKeyNames[number] & keyof Entity>> extends TabularRepository<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value> {
18
+ table: string;
19
+ /** Promise that resolves to the IndexedDB database instance */
20
+ private db;
21
+ /** Migration options for database schema changes */
22
+ private migrationOptions;
23
+ /**
24
+ * Creates a new IndexedDB-based tabular repository.
25
+ * @param table - Name of the IndexedDB store to use.
26
+ * @param schema - Schema defining the structure of the entity
27
+ * @param primaryKeyNames - Array of property names that form the primary key
28
+ * @param indexes - Array of columns or column arrays to make searchable. Each string or single column creates a single-column index,
29
+ * while each array creates a compound index with columns in the specified order.
30
+ * @param migrationOptions - Options for handling database schema migrations
31
+ */
32
+ constructor(table: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: Array<keyof Entity | Array<keyof Entity>>, migrationOptions?: MigrationOptions);
33
+ /**
34
+ * Sets up the IndexedDB database table with the required schema and indexes.
35
+ * Must be called before using any other methods.
36
+ */
37
+ setupDatabase(): Promise<IDBDatabase>;
38
+ /**
39
+ * Stores a row in the repository.
40
+ * @param record - The entity to store.
41
+ * @returns The stored entity
42
+ * @emits put - Emitted when the value is successfully stored
43
+ */
44
+ put(record: Entity): Promise<Entity>;
45
+ /**
46
+ * Stores multiple rows in the repository in a bulk operation.
47
+ * @param records - Array of entities to store.
48
+ * @returns Array of stored entities
49
+ * @emits put - Emitted for each record successfully stored
50
+ */
51
+ putBulk(records: Entity[]): Promise<Entity[]>;
52
+ protected getPrimaryKeyAsOrderedArray(key: PrimaryKey): (string | number | boolean | Uint8Array<ArrayBufferLike> | null)[];
53
+ private getIndexedKey;
54
+ /**
55
+ * Retrieves a value from the repository by its key.
56
+ * @param key - The key object.
57
+ * @returns The value object or undefined if not found.
58
+ * @emits get - Emitted when the value is successfully retrieved
59
+ */
60
+ get(key: PrimaryKey): Promise<Entity | undefined>;
61
+ /**
62
+ * Returns an array of all entries in the repository.
63
+ * @returns Array of all entries in the repository.
64
+ */
65
+ getAll(): Promise<Entity[] | undefined>;
66
+ /**
67
+ * Searches for records matching the specified partial query.
68
+ * It uses an appropriate index if one exists, or scans all records.
69
+ * @param key - Partial query object.
70
+ * @returns Array of matching records or undefined.
71
+ */
72
+ search(key: Partial<Entity>): Promise<Entity[] | undefined>;
73
+ /**
74
+ * Deletes a row from the repository.
75
+ * @param key - The key object to delete.
76
+ */
77
+ delete(key: PrimaryKey): Promise<void>;
78
+ /**
79
+ * Deletes all records from the repository.
80
+ * @emits clearall - Emitted when all values are deleted
81
+ */
82
+ deleteAll(): Promise<void>;
83
+ /**
84
+ * Returns the total number of rows in the repository.
85
+ * @returns Count of stored items.
86
+ */
87
+ size(): Promise<number>;
88
+ /**
89
+ * Deletes all entries with a date column value older than the provided date
90
+ * @param column - The name of the date column to compare against
91
+ * @param value - The value to compare against
92
+ * @param operator - The operator to use for comparison
93
+ */
94
+ deleteSearch(column: keyof Entity, value: Entity[keyof Entity], operator?: "=" | "<" | "<=" | ">" | ">="): Promise<void>;
95
+ /**
96
+ * Destroys this repository and frees up resources.
97
+ */
98
+ destroy(): void;
99
+ }
100
+ //# sourceMappingURL=IndexedDbTabularRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IndexedDbTabularRepository.d.ts","sourceRoot":"","sources":["../../src/tabular/IndexedDbTabularRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAsB,oBAAoB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAGH,gBAAgB,EACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,eAAO,MAAM,sBAAsB,oFAEK,CAAC;AAEzC;;;;;GAKG;AACH,qBAAa,0BAA0B,CACrC,MAAM,SAAS,oBAAoB,EACnC,eAAe,SAAS,aAAa,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,EAEjE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,EAC3B,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,EACjE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,GAA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