@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,133 @@
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 type { Pool } from "pg";
8
+ import { BaseSqlTabularRepository } from "./BaseSqlTabularRepository";
9
+ import { ITabularRepository, ValueOptionType } from "./ITabularRepository";
10
+ export declare const POSTGRES_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<ITabularRepository<any, any, any, any, any>>;
11
+ /**
12
+ * A PostgreSQL-based tabular repository implementation that extends BaseSqlTabularRepository.
13
+ * This class provides persistent storage for data in a PostgreSQL database,
14
+ * making it suitable for multi-user scenarios.
15
+ *
16
+ * @template Schema - The schema definition for the entity
17
+ * @template PrimaryKeyNames - Array of property names that form the primary key
18
+ */
19
+ export declare class PostgresTabularRepository<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 BaseSqlTabularRepository<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value> {
20
+ #private;
21
+ private db;
22
+ /**
23
+ * Creates a new PostgresTabularRepository instance.
24
+ *
25
+ * @param db - PostgreSQL db
26
+ * @param table - Name of the table to store data (defaults to "tabular_store")
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(db: Pool, table: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: Array<keyof Entity | Array<keyof Entity>>);
33
+ /**
34
+ * Initializes the database table with the required schema.
35
+ * Creates the table if it doesn't exist with primary key and value columns.
36
+ */
37
+ setupDatabase(): Promise<Pool>;
38
+ /**
39
+ * Maps TypeScript/JavaScript types to corresponding PostgreSQL data types.
40
+ * Uses additional schema information like minimum/maximum values, nullable status,
41
+ * and string lengths to create more optimized column types.
42
+ *
43
+ * @param typeDef - The TypeScript/JavaScript type to map
44
+ * @returns The corresponding PostgreSQL data type
45
+ */
46
+ protected mapTypeToSQL(typeDef: JsonSchema): string;
47
+ /**
48
+ * Generates the SQL column definitions for primary key fields with constraints
49
+ * @returns SQL string containing primary key column definitions
50
+ */
51
+ protected constructPrimaryKeyColumns($delimiter?: string): string;
52
+ /**
53
+ * Generates the SQL column definitions for value fields with constraints
54
+ * @returns SQL string containing value column definitions
55
+ */
56
+ protected constructValueColumns($delimiter?: string): string;
57
+ /**
58
+ * Convert PostgreSQL values to JS values. Ensures numeric strings become numbers where schema says number.
59
+ */
60
+ protected sqlToJsValue(column: string, value: ValueOptionType): Entity[keyof Entity];
61
+ /**
62
+ * Determines if a field should be treated as unsigned based on schema properties
63
+ * @param typeDef - The schema type definition
64
+ * @returns true if the field should be treated as unsigned
65
+ */
66
+ protected shouldBeUnsigned(typeDef: JsonSchema): boolean;
67
+ /**
68
+ * Stores or updates a row in the database.
69
+ * Uses UPSERT (INSERT ... ON CONFLICT DO UPDATE) for atomic operations.
70
+ *
71
+ * @param entity - The entity to store
72
+ * @returns The entity with any server-generated fields updated
73
+ * @emits "put" event with the updated entity when successful
74
+ */
75
+ put(entity: Entity): Promise<Entity>;
76
+ /**
77
+ * Stores multiple rows in the database in a bulk operation.
78
+ * Uses batch INSERT with ON CONFLICT for better performance.
79
+ *
80
+ * @param entities - Array of entities to store
81
+ * @returns Array of entities with any server-generated fields updated
82
+ * @emits "put" event for each entity stored
83
+ */
84
+ putBulk(entities: Entity[]): Promise<Entity[]>;
85
+ /**
86
+ * Retrieves a value from the database by its primary key.
87
+ *
88
+ * @param key - The primary key object to look up
89
+ * @returns The stored value or undefined if not found
90
+ * @emits "get" event with the key when successful
91
+ */
92
+ get(key: PrimaryKey): Promise<Entity | undefined>;
93
+ /**
94
+ * Method to be implemented by concrete repositories to search for rows
95
+ * based on a partial key.
96
+ *
97
+ * @param key - Partial key to search for
98
+ * @returns Promise resolving to an array of combined row objects or undefined if not found
99
+ */
100
+ search(key: Partial<Entity>): Promise<Entity[] | undefined>;
101
+ /**
102
+ * Deletes a row from the database.
103
+ *
104
+ * @param key - The primary key object to delete
105
+ * @emits "delete" event with the key when successful
106
+ */
107
+ delete(value: PrimaryKey | Entity): Promise<void>;
108
+ /**
109
+ * Retrieves all entries from the database table
110
+ * @returns Promise resolving to an array of entries or undefined if not found
111
+ */
112
+ getAll(): Promise<Entity[] | undefined>;
113
+ /**
114
+ * Deletes all rows from the database table.
115
+ * @emits "clearall" event when successful
116
+ */
117
+ deleteAll(): Promise<void>;
118
+ /**
119
+ * Returns the total number of rows in the database.
120
+ *
121
+ * @returns Promise resolving to the count of stored items
122
+ */
123
+ size(): Promise<number>;
124
+ protected generateWhereClause(column: keyof Entity, operator?: "=" | "<" | "<=" | ">" | ">="): string;
125
+ /**
126
+ * Deletes all entries with a date column value older than the provided date
127
+ * @param column - The name of the date column to compare against
128
+ * @param value - The value to compare against
129
+ * @param operator - The operator to use for comparison
130
+ */
131
+ deleteSearch(column: keyof Entity, value: Entity[keyof Entity], operator?: "=" | "<" | "<=" | ">" | ">="): Promise<void>;
132
+ }
133
+ //# sourceMappingURL=PostgresTabularRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresTabularRepository.d.ts","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CAAC,MAAM,MAAM,CAAC,EAC3B,QAAQ,GAAE,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAU,GAC5C,OAAO,CAAC,IAAI,CAAC;CASjB"}
@@ -0,0 +1,126 @@
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 SHARED_IN_MEMORY_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<ITabularRepository<any, any, any, any, any>>;
10
+ /**
11
+ * A tabular repository implementation that shares data across browser tabs/windows
12
+ * using BroadcastChannel API. Uses InMemoryTabularRepository internally and
13
+ * synchronizes changes across all instances.
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 SharedInMemoryTabularRepository<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
+ private channel;
20
+ private channelName;
21
+ private inMemoryRepo;
22
+ private isInitialized;
23
+ private syncInProgress;
24
+ /**
25
+ * Creates a new SharedInMemoryTabularRepository instance
26
+ * @param channelName - Unique name for the BroadcastChannel (defaults to "tabular_store")
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(channelName: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: Array<keyof Entity | Array<keyof Entity>>);
33
+ /**
34
+ * Checks if BroadcastChannel is available in the current environment
35
+ */
36
+ private isBroadcastChannelAvailable;
37
+ /**
38
+ * Initializes the BroadcastChannel and sets up message handlers
39
+ */
40
+ private initializeBroadcastChannel;
41
+ /**
42
+ * Sets up event forwarding from the internal InMemoryTabularRepository
43
+ */
44
+ private setupEventForwarding;
45
+ /**
46
+ * Handles incoming BroadcastChannel messages
47
+ */
48
+ private handleBroadcastMessage;
49
+ /**
50
+ * Requests synchronization from other tabs
51
+ */
52
+ private syncFromOtherTabs;
53
+ /**
54
+ * Copies data from an array of entities into the repository
55
+ */
56
+ private copyDataFromArray;
57
+ /**
58
+ * Broadcasts a message to other tabs
59
+ */
60
+ private broadcast;
61
+ /**
62
+ * Sets up the database for the repository (syncs from other tabs)
63
+ */
64
+ setupDatabase(): Promise<void>;
65
+ /**
66
+ * Stores a key-value pair in the repository
67
+ * @param value - The combined object to store
68
+ * @returns The stored entity
69
+ * @emits 'put' event with the stored entity when successful
70
+ */
71
+ put(value: Entity): Promise<Entity>;
72
+ /**
73
+ * Stores multiple key-value pairs in the repository in a bulk operation
74
+ * @param values - Array of combined objects to store
75
+ * @returns Array of stored entities
76
+ * @emits 'put' event for each value stored
77
+ */
78
+ putBulk(values: Entity[]): Promise<Entity[]>;
79
+ /**
80
+ * Retrieves a value by its key
81
+ * @param key - The primary key object to look up
82
+ * @returns The value object if found, undefined otherwise
83
+ * @emits 'get' event with the fingerprint ID and value when found
84
+ */
85
+ get(key: PrimaryKey): Promise<Entity | undefined>;
86
+ /**
87
+ * Searches for entries matching a partial key
88
+ * @param key - Partial key object to search for
89
+ * @returns Array of matching combined objects
90
+ * @throws Error if search criteria outside of searchable fields
91
+ */
92
+ search(key: Partial<Entity>): Promise<Entity[] | undefined>;
93
+ /**
94
+ * Deletes an entry by its key
95
+ * @param value - The primary key object or entity of the entry to delete
96
+ * @emits 'delete' event with the fingerprint ID when successful
97
+ */
98
+ delete(value: PrimaryKey | Entity): Promise<void>;
99
+ /**
100
+ * Removes all entries from the repository
101
+ * @emits 'clearall' event when successful
102
+ */
103
+ deleteAll(): Promise<void>;
104
+ /**
105
+ * Returns an array of all entries in the repository
106
+ * @returns Array of all entries in the repository
107
+ */
108
+ getAll(): Promise<Entity[] | undefined>;
109
+ /**
110
+ * Returns the number of entries in the repository
111
+ * @returns The total count of stored entries
112
+ */
113
+ size(): Promise<number>;
114
+ /**
115
+ * Deletes all entries with a date column value matching the provided criteria
116
+ * @param column - The name of the date column to compare against
117
+ * @param value - The value to compare against
118
+ * @param operator - The operator to use for comparison
119
+ */
120
+ deleteSearch(column: keyof Entity, value: Entity[keyof Entity], operator?: "=" | "<" | "<=" | ">" | ">="): Promise<void>;
121
+ /**
122
+ * Cleanup method to close the BroadcastChannel
123
+ */
124
+ destroy(): void;
125
+ }
126
+ //# sourceMappingURL=SharedInMemoryTabularRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SharedInMemoryTabularRepository.d.ts","sourceRoot":"","sources":["../../src/tabular/SharedInMemoryTabularRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAsB,oBAAoB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,eAAO,MAAM,mCAAmC,oFAEH,CAAC;AAc9C;;;;;;;GAOG;AACH,qBAAa,+BAA+B,CAC1C,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,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AG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOvD;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAMhC;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC;IAK7C;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAK7B;;;;;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;IAWhB;;OAEG;IACH,OAAO,IAAI,IAAI;CAMhB"}
@@ -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 { Sqlite } from "@workglow/sqlite";
7
+ import { DataPortSchemaObject, FromSchema, JsonSchema } from "@workglow/util";
8
+ import { BaseSqlTabularRepository } from "./BaseSqlTabularRepository";
9
+ import { ITabularRepository, ValueOptionType } from "./ITabularRepository";
10
+ export declare const SQLITE_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<ITabularRepository<any, any, any, any, any>>;
11
+ /**
12
+ * A SQLite-based key-value repository implementation.
13
+ * @template Schema - The schema definition for the entity
14
+ * @template PrimaryKeyNames - Array of property names that form the primary key
15
+ */
16
+ export declare class SqliteTabularRepository<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 BaseSqlTabularRepository<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value> {
17
+ #private;
18
+ /** The SQLite database instance */
19
+ private db;
20
+ /**
21
+ * Creates a new SQLite key-value repository
22
+ * @param dbOrPath - Either a Database instance or a path to the SQLite database file
23
+ * @param table - The name of the table to use for storage (defaults to 'tabular_store')
24
+ * @param schema - Schema defining the structure of the entity
25
+ * @param primaryKeyNames - Array of property names that form the primary key
26
+ * @param indexes - Array of columns or column arrays to make searchable. Each string or single column creates a single-column index,
27
+ * while each array creates a compound index with columns in the specified order.
28
+ */
29
+ constructor(dbOrPath: string | Sqlite.Database, table: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: Array<keyof Entity | Array<keyof Entity>>);
30
+ /**
31
+ * Creates the database table if it doesn't exist with the defined schema
32
+ */
33
+ setupDatabase(): Promise<Sqlite.Database>;
34
+ /**
35
+ * Convert JS values to SQLite-compatible values. Ensures booleans are stored as 0/1.
36
+ */
37
+ protected jsToSqlValue(column: string, value: Entity[keyof Entity]): ValueOptionType;
38
+ /**
39
+ * Convert SQLite values to JS values. Ensures 0/1 become booleans where schema says boolean.
40
+ */
41
+ protected sqlToJsValue(column: string, value: ValueOptionType): Entity[keyof Entity];
42
+ /**
43
+ * Maps TypeScript/JavaScript types to their SQLite column type equivalents
44
+ * Uses additional schema information like minimum/maximum values, nullable status,
45
+ * and string lengths to create more optimized column types.
46
+ *
47
+ * @param typeDef - The TypeScript/JavaScript type definition
48
+ * @returns The corresponding SQLite column type
49
+ */
50
+ protected mapTypeToSQL(typeDef: JsonSchema): string;
51
+ /**
52
+ * Stores a key-value pair in the database
53
+ * @param entity - The entity to store
54
+ * @returns The entity with any server-generated fields updated
55
+ * @emits 'put' event when successful
56
+ */
57
+ put(entity: Entity): Promise<Entity>;
58
+ /**
59
+ * Stores multiple key-value pairs in the database in a bulk operation
60
+ * @param entities - Array of entities to store
61
+ * @returns Array of entities with any server-generated fields updated
62
+ * @emits 'put' event for each entity stored
63
+ */
64
+ putBulk(entities: Entity[]): Promise<Entity[]>;
65
+ /**
66
+ * Retrieves a value from the database by its key
67
+ * @param key - The primary key object to look up
68
+ * @returns The stored value or undefined if not found
69
+ * @emits 'get' event when successful
70
+ */
71
+ get(key: PrimaryKey): Promise<Entity | undefined>;
72
+ /**
73
+ * Method to be implemented by concrete repositories to search for key-value pairs
74
+ * based on a partial key.
75
+ *
76
+ * @param key - Partial key to search for
77
+ * @returns Promise resolving to an array of combined key-value objects or undefined if not found
78
+ */
79
+ search(key: Partial<Entity>): Promise<Entity[] | undefined>;
80
+ /**
81
+ * Deletes a key-value pair from the database
82
+ * @param key - The primary key object to delete
83
+ * @emits 'delete' event when successful
84
+ */
85
+ delete(key: PrimaryKey): Promise<void>;
86
+ /**
87
+ * Retrieves all entries from the database table
88
+ * @returns Promise resolving to an array of entries or undefined if not found
89
+ */
90
+ getAll(): Promise<Entity[] | undefined>;
91
+ /**
92
+ * Deletes all entries from the database table
93
+ * @emits 'clearall' event when successful
94
+ */
95
+ deleteAll(): Promise<void>;
96
+ /**
97
+ * Gets the total number of entries in the database table
98
+ * @returns The count of entries
99
+ */
100
+ size(): Promise<number>;
101
+ protected generateWhereClause(column: keyof Entity, operator?: "=" | "<" | "<=" | ">" | ">="): string;
102
+ /**
103
+ * Deletes all entries with a date column value older than the provided date
104
+ * @param column - The name of the date column to compare against
105
+ * @param value - The value to compare against
106
+ * @param operator - The operator to use for comparison
107
+ */
108
+ deleteSearch(column: keyof Entity, value: Entity[keyof Entity], operator?: "=" | "<" | "<=" | ">" | ">="): Promise<void>;
109
+ }
110
+ //# sourceMappingURL=SqliteTabularRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteTabularRepository.d.ts","sourceRoot":"","sources":["../../src/tabular/SqliteTabularRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAsB,oBAAoB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC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nD;;;;;OAKG;IACG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAgC1C;;;;;OAKG;IACG,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA2DpD;;;;;OAKG;IACG,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IA0BvD;;;;;;OAMG;IACU,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC;IAuDxE;;;;OAIG;IACG,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5C;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC;IAe7C;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAMhC;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAQ7B,SAAS,CAAC,mBAAmB,CAC3B,MAAM,EAAE,MAAM,MAAM,EACpB,QAAQ,GAAE,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAU,GAC5C,MAAM;IAOT;;;;;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;CAQjB"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { SupabaseClient } from "@supabase/supabase-js";
7
+ import { DataPortSchemaObject, FromSchema, JsonSchema } from "@workglow/util";
8
+ import { BaseSqlTabularRepository } from "./BaseSqlTabularRepository";
9
+ import { ITabularRepository, ValueOptionType } from "./ITabularRepository";
10
+ export declare const SUPABASE_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<ITabularRepository<any, any, any, any, any>>;
11
+ /**
12
+ * A Supabase-based tabular repository implementation that extends BaseSqlTabularRepository.
13
+ * This class provides persistent storage for data in a Supabase database,
14
+ * making it suitable for multi-user scenarios.
15
+ *
16
+ * @template Schema - The schema definition for the entity
17
+ * @template PrimaryKeyNames - Array of property names that form the primary key
18
+ */
19
+ export declare class SupabaseTabularRepository<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 BaseSqlTabularRepository<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value> {
20
+ private client;
21
+ /**
22
+ * Creates a new SupabaseTabularRepository instance.
23
+ *
24
+ * @param client - Supabase client instance
25
+ * @param table - Name of the table to store data (defaults to "tabular_store")
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
+ */
31
+ constructor(client: SupabaseClient, table: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: Array<keyof Entity | Array<keyof Entity>>);
32
+ protected isSetup: boolean;
33
+ /**
34
+ * Initializes the database table with the required schema.
35
+ * Creates the table if it doesn't exist with primary key and value columns.
36
+ */
37
+ setupDatabase(): Promise<SupabaseClient>;
38
+ /**
39
+ * Maps TypeScript/JavaScript types to corresponding PostgreSQL data types.
40
+ * Uses additional schema information like minimum/maximum values, nullable status,
41
+ * and string lengths to create more optimized column types.
42
+ *
43
+ * @param typeDef - The TypeScript/JavaScript type to map
44
+ * @returns The corresponding PostgreSQL data type
45
+ */
46
+ protected mapTypeToSQL(typeDef: JsonSchema): string;
47
+ /**
48
+ * Generates the SQL column definitions for primary key fields with constraints
49
+ * @returns SQL string containing primary key column definitions
50
+ */
51
+ protected constructPrimaryKeyColumns($delimiter?: string): string;
52
+ /**
53
+ * Generates the SQL column definitions for value fields with constraints
54
+ * @returns SQL string containing value column definitions
55
+ */
56
+ protected constructValueColumns($delimiter?: string): string;
57
+ /**
58
+ * Convert Supabase values to JS values. Ensures numeric strings become numbers where schema says number.
59
+ */
60
+ protected sqlToJsValue(column: string, value: ValueOptionType): Entity[keyof Entity];
61
+ /**
62
+ * Determines if a field should be treated as unsigned based on schema properties
63
+ * @param typeDef - The schema type definition
64
+ * @returns true if the field should be treated as unsigned
65
+ */
66
+ protected shouldBeUnsigned(typeDef: JsonSchema): boolean;
67
+ /**
68
+ * Stores or updates a row in the database.
69
+ * Uses UPSERT (INSERT ... ON CONFLICT DO UPDATE) for atomic operations.
70
+ *
71
+ * @param entity - The entity to store
72
+ * @returns The entity with any server-generated fields updated
73
+ * @emits "put" event with the updated entity when successful
74
+ */
75
+ put(entity: Entity): Promise<Entity>;
76
+ /**
77
+ * Stores multiple rows in the database in a bulk operation.
78
+ * Uses batch INSERT with ON CONFLICT for better performance.
79
+ *
80
+ * @param entities - Array of entities to store
81
+ * @returns Array of entities with any server-generated fields updated
82
+ * @emits "put" event for each entity stored
83
+ */
84
+ putBulk(entities: Entity[]): Promise<Entity[]>;
85
+ /**
86
+ * Retrieves a value from the database by its primary key.
87
+ *
88
+ * @param key - The primary key object to look up
89
+ * @returns The stored entity or undefined if not found
90
+ * @emits "get" event with the key when successful
91
+ */
92
+ get(key: PrimaryKey): Promise<Entity | undefined>;
93
+ /**
94
+ * Method to search for rows based on a partial key.
95
+ *
96
+ * @param searchCriteria - Partial entity to search for
97
+ * @returns Promise resolving to an array of entities or undefined if not found
98
+ */
99
+ search(searchCriteria: Partial<Entity>): Promise<Entity[] | undefined>;
100
+ /**
101
+ * Deletes a row from the database.
102
+ *
103
+ * @param value - The primary key object or entity to delete
104
+ * @emits "delete" event with the key when successful
105
+ */
106
+ delete(value: PrimaryKey | Entity): Promise<void>;
107
+ /**
108
+ * Retrieves all entries from the database table
109
+ * @returns Promise resolving to an array of entries or undefined if not found
110
+ */
111
+ getAll(): Promise<Entity[] | undefined>;
112
+ /**
113
+ * Deletes all rows from the database table.
114
+ * @emits "clearall" event when successful
115
+ */
116
+ deleteAll(): Promise<void>;
117
+ /**
118
+ * Returns the total number of rows in the database.
119
+ *
120
+ * @returns Promise resolving to the count of stored items
121
+ */
122
+ size(): Promise<number>;
123
+ protected generateWhereClause(column: keyof Entity, operator?: "=" | "<" | "<=" | ">" | ">="): string;
124
+ /**
125
+ * Deletes all entries matching a search criteria
126
+ * @param column - The column name to compare against
127
+ * @param value - The value to compare against
128
+ * @param operator - The operator to use for comparison
129
+ */
130
+ deleteSearch(column: keyof Entity, value: Entity[keyof Entity], operator?: "=" | "<" | "<=" | ">" | ">="): Promise<void>;
131
+ }
132
+ //# sourceMappingURL=SupabaseTabularRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SupabaseTabularRepository.d.ts","sourceRoot":"","sources":["../../src/tabular/SupabaseTabularRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAsB,oBAAoB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE3E,eAAO,MAAM,2BAA2B,oFAED,CAAC;AAExC;;;;;;;GAOG;AACH,qBAAa,yBAAyB,CACpC,MAAM,SAAS,oBAAoB,EACnC,eAAe,SAAS,aAAa,CAAC,MAAM,MAAM,CAAC,YAAY,CAA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AM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAqCpD;;;;;;OAMG;IACG,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAiCvD;;;;;OAKG;IACU,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC;IAsDnF;;;;;OAKG;IACG,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBvD;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC;IAmB7C;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAWhC;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAU7B,SAAS,CAAC,mBAAmB,CAC3B,MAAM,EAAE,MAAM,MAAM,EACpB,QAAQ,GAAE,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAU,GAC5C,MAAM;IAOT;;;;;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;CA4BjB"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { DataPortSchemaObject, EventEmitter, FromSchema } from "@workglow/util";
7
+ import { ITabularRepository, TabularEventListener, TabularEventListeners, TabularEventName, TabularEventParameters, ValueOptionType } from "./ITabularRepository";
8
+ export declare const TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<ITabularRepository<any, any, any, any, any>>;
9
+ /**
10
+ * Abstract base class for tabular storage repositories.
11
+ * Provides functionality for storing and retrieving data with typed
12
+ * primary keys and values, and supports compound keys and partial key lookup.
13
+ * Has a basic event emitter for listening to repository events.
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 abstract class TabularRepository<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>> implements ITabularRepository<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value> {
19
+ protected schema: Schema;
20
+ protected primaryKeyNames: PrimaryKeyNames;
21
+ /** Event emitter for repository events */
22
+ protected events: EventEmitter<TabularEventListeners<PrimaryKey, Entity>>;
23
+ protected indexes: Array<keyof Entity>[];
24
+ protected primaryKeySchema: DataPortSchemaObject;
25
+ protected valueSchema: DataPortSchemaObject;
26
+ /**
27
+ * Creates a new TabularRepository instance
28
+ * @param schema - Schema defining the structure of the entity
29
+ * @param primaryKeyNames - Array of property names that form the primary key
30
+ * @param indexes - Array of columns or column arrays to make searchable. Each string or single column creates a single-column index,
31
+ * while each array creates a compound index with columns in the specified order.
32
+ */
33
+ constructor(schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: Array<keyof Entity | Array<keyof Entity>>);
34
+ protected filterCompoundKeys(primaryKey: Array<keyof Entity>, potentialKeys: Array<keyof Entity>[]): Array<keyof Entity>[];
35
+ /**
36
+ * Adds an event listener for a specific event
37
+ * @param name The name of the event to listen for
38
+ * @param fn The callback function to execute when the event occurs
39
+ */
40
+ on<Event extends TabularEventName>(name: Event, fn: TabularEventListener<Event, PrimaryKey, Entity>): void;
41
+ /**
42
+ * Removes an event listener for a specific event
43
+ * @param name The name of the event to remove the listener from
44
+ * @param fn The callback function to remove
45
+ */
46
+ off<Event extends TabularEventName>(name: Event, fn: TabularEventListener<Event, PrimaryKey, Entity>): void;
47
+ /**
48
+ * Adds an event listener that will only be called once
49
+ * @param name The name of the event to listen for
50
+ * @param fn The callback function to execute when the event occurs
51
+ */
52
+ once<Event extends TabularEventName>(name: Event, fn: TabularEventListener<Event, PrimaryKey, Entity>): void;
53
+ /**
54
+ * Emits an event with the specified name and arguments
55
+ * @param name The name of the event to emit
56
+ * @param args The arguments to pass to the event listeners
57
+ */
58
+ emit<Event extends TabularEventName>(name: Event, ...args: TabularEventParameters<Event, PrimaryKey, Entity>): void;
59
+ /**
60
+ * Returns when the event was emitted (promise form of once)
61
+ * @param name The name of the event to check
62
+ * @returns true if the event has listeners, false otherwise
63
+ */
64
+ waitOn<Event extends TabularEventName>(name: Event): Promise<TabularEventParameters<Event, PrimaryKey, Entity>>;
65
+ /**
66
+ * Core abstract methods that must be implemented by concrete repositories
67
+ */
68
+ abstract put(value: Entity): Promise<Entity>;
69
+ abstract putBulk(values: Entity[]): Promise<Entity[]>;
70
+ abstract get(key: PrimaryKey): Promise<Entity | undefined>;
71
+ abstract delete(key: PrimaryKey | Entity): Promise<void>;
72
+ abstract getAll(): Promise<Entity[] | undefined>;
73
+ abstract deleteAll(): Promise<void>;
74
+ abstract size(): Promise<number>;
75
+ abstract deleteSearch(column: keyof Entity, value: Entity[keyof Entity], operator: "=" | "<" | "<=" | ">" | ">="): Promise<void>;
76
+ /**
77
+ * Abstract method to be implemented by concrete repositories to search for rows
78
+ * based on a partial key.
79
+ *
80
+ * @param key - Partial key to search for
81
+ * @returns Promise resolving to an array of combined row objects or undefined if not found
82
+ */
83
+ abstract search(key: Partial<Entity>): Promise<Entity[] | undefined>;
84
+ protected primaryKeyColumns(): Array<keyof PrimaryKey>;
85
+ protected valueColumns(): Array<keyof Value>;
86
+ /**
87
+ * Utility method to separate a combined object into its key and value components
88
+ * for storage.
89
+ * @param obj - Entity row object
90
+ * @returns Separated key and value objects
91
+ */
92
+ protected separateKeyValueFromCombined(obj: Entity): {
93
+ value: Value;
94
+ key: PrimaryKey;
95
+ };
96
+ /**
97
+ * Generates a consistent string identifier for a given key.
98
+ *
99
+ * @param key - Primary key to convert
100
+ * @returns Promise resolving to a string fingerprint of the key
101
+ */
102
+ protected getKeyAsIdString(key: PrimaryKey): Promise<string>;
103
+ /**
104
+ * Converts a primary key object into an ordered array based on the schema
105
+ * This ensures consistent parameter ordering for storage operations
106
+ * @param key - The primary key object to convert
107
+ * @returns Array of key values ordered according to the schema
108
+ */
109
+ protected getPrimaryKeyAsOrderedArray(key: PrimaryKey): ValueOptionType[];
110
+ /**
111
+ * Finds the best matching index for a set of search keys.
112
+ * @param unorderedSearchKey - Unordered array of keys being searched, can be reordered
113
+ * @returns Array of column names representing the best matching index, or undefined if no suitable index is found
114
+ */
115
+ findBestMatchingIndex(unorderedSearchKey: Array<keyof Entity>): Array<keyof Entity> | undefined;
116
+ /**
117
+ * Destroys the repository and frees up resources.
118
+ */
119
+ destroy(): void;
120
+ [Symbol.asyncDispose](): Promise<void>;
121
+ [Symbol.dispose](): void;
122
+ }
123
+ //# sourceMappingURL=TabularRepository.d.ts.map