@workglow/storage 0.0.85 → 0.0.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +185 -53
- package/dist/browser.js +451 -188
- package/dist/browser.js.map +21 -18
- package/dist/bun.js +1069 -356
- package/dist/bun.js.map +29 -24
- package/dist/common-server.d.ts +17 -15
- package/dist/common-server.d.ts.map +1 -1
- package/dist/common.d.ts +13 -10
- package/dist/common.d.ts.map +1 -1
- package/dist/kv/{FsFolderJsonKvRepository.d.ts → FsFolderJsonKvStorage.d.ts} +8 -8
- package/dist/kv/FsFolderJsonKvStorage.d.ts.map +1 -0
- package/dist/kv/{FsFolderKvRepository.d.ts → FsFolderKvStorage.d.ts} +7 -7
- package/dist/kv/FsFolderKvStorage.d.ts.map +1 -0
- package/dist/kv/{IKvRepository.d.ts → IKvStorage.d.ts} +3 -3
- package/dist/kv/IKvStorage.d.ts.map +1 -0
- package/dist/kv/{InMemoryKvRepository.d.ts → InMemoryKvStorage.d.ts} +8 -8
- package/dist/kv/InMemoryKvStorage.d.ts.map +1 -0
- package/dist/kv/{IndexedDbKvRepository.d.ts → IndexedDbKvStorage.d.ts} +8 -8
- package/dist/kv/IndexedDbKvStorage.d.ts.map +1 -0
- package/dist/kv/{KvRepository.d.ts → KvStorage.d.ts} +7 -7
- package/dist/kv/KvStorage.d.ts.map +1 -0
- package/dist/kv/{KvViaTabularRepository.d.ts → KvViaTabularStorage.d.ts} +7 -7
- package/dist/kv/KvViaTabularStorage.d.ts.map +1 -0
- package/dist/kv/{PostgresKvRepository.d.ts → PostgresKvStorage.d.ts} +8 -8
- package/dist/kv/PostgresKvStorage.d.ts.map +1 -0
- package/dist/kv/{SqliteKvRepository.d.ts → SqliteKvStorage.d.ts} +8 -8
- package/dist/kv/SqliteKvStorage.d.ts.map +1 -0
- package/dist/kv/{SupabaseKvRepository.d.ts → SupabaseKvStorage.d.ts} +9 -9
- package/dist/kv/SupabaseKvStorage.d.ts.map +1 -0
- package/dist/node.js +1069 -356
- package/dist/node.js.map +29 -24
- package/dist/queue-limiter/IRateLimiterStorage.d.ts.map +1 -0
- package/dist/queue-limiter/InMemoryRateLimiterStorage.d.ts.map +1 -0
- package/dist/queue-limiter/IndexedDbRateLimiterStorage.d.ts.map +1 -0
- package/dist/queue-limiter/PostgresRateLimiterStorage.d.ts.map +1 -0
- package/dist/queue-limiter/SqliteRateLimiterStorage.d.ts.map +1 -0
- package/dist/queue-limiter/SupabaseRateLimiterStorage.d.ts.map +1 -0
- package/dist/tabular/{BaseSqlTabularRepository.d.ts → BaseSqlTabularStorage.d.ts} +8 -7
- package/dist/tabular/BaseSqlTabularStorage.d.ts.map +1 -0
- package/dist/tabular/{TabularRepository.d.ts → BaseTabularStorage.d.ts} +52 -10
- package/dist/tabular/BaseTabularStorage.d.ts.map +1 -0
- package/dist/tabular/{CachedTabularRepository.d.ts → CachedTabularStorage.d.ts} +15 -14
- package/dist/tabular/CachedTabularStorage.d.ts.map +1 -0
- package/dist/tabular/{FsFolderTabularRepository.d.ts → FsFolderTabularStorage.d.ts} +22 -12
- package/dist/tabular/FsFolderTabularStorage.d.ts.map +1 -0
- package/dist/tabular/{ITabularRepository.d.ts → ITabularStorage.d.ts} +29 -6
- package/dist/tabular/ITabularStorage.d.ts.map +1 -0
- package/dist/tabular/{InMemoryTabularRepository.d.ts → InMemoryTabularStorage.d.ts} +24 -14
- package/dist/tabular/InMemoryTabularStorage.d.ts.map +1 -0
- package/dist/tabular/{IndexedDbTabularRepository.d.ts → IndexedDbTabularStorage.d.ts} +20 -11
- package/dist/tabular/IndexedDbTabularStorage.d.ts.map +1 -0
- package/dist/tabular/{PostgresTabularRepository.d.ts → PostgresTabularStorage.d.ts} +37 -15
- package/dist/tabular/PostgresTabularStorage.d.ts.map +1 -0
- package/dist/tabular/{SharedInMemoryTabularRepository.d.ts → SharedInMemoryTabularStorage.d.ts} +14 -13
- package/dist/tabular/SharedInMemoryTabularStorage.d.ts.map +1 -0
- package/dist/tabular/{SqliteTabularRepository.d.ts → SqliteTabularStorage.d.ts} +25 -11
- package/dist/tabular/SqliteTabularStorage.d.ts.map +1 -0
- package/dist/tabular/{SupabaseTabularRepository.d.ts → SupabaseTabularStorage.d.ts} +17 -15
- package/dist/tabular/SupabaseTabularStorage.d.ts.map +1 -0
- package/dist/tabular/TabularStorageRegistry.d.ts +29 -0
- package/dist/tabular/TabularStorageRegistry.d.ts.map +1 -0
- package/dist/util/IndexedDbTable.d.ts +1 -1
- package/dist/util/IndexedDbTable.d.ts.map +1 -1
- package/dist/vector/IVectorStorage.d.ts +83 -0
- package/dist/vector/IVectorStorage.d.ts.map +1 -0
- package/dist/vector/InMemoryVectorStorage.d.ts +41 -0
- package/dist/vector/InMemoryVectorStorage.d.ts.map +1 -0
- package/dist/vector/PostgresVectorStorage.d.ts +57 -0
- package/dist/vector/PostgresVectorStorage.d.ts.map +1 -0
- package/dist/vector/SqliteVectorStorage.d.ts +45 -0
- package/dist/vector/SqliteVectorStorage.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/kv/README.md +3 -3
- package/src/tabular/README.md +186 -23
- package/src/vector/README.md +393 -0
- package/dist/kv/FsFolderJsonKvRepository.d.ts.map +0 -1
- package/dist/kv/FsFolderKvRepository.d.ts.map +0 -1
- package/dist/kv/IKvRepository.d.ts.map +0 -1
- package/dist/kv/InMemoryKvRepository.d.ts.map +0 -1
- package/dist/kv/IndexedDbKvRepository.d.ts.map +0 -1
- package/dist/kv/KvRepository.d.ts.map +0 -1
- package/dist/kv/KvViaTabularRepository.d.ts.map +0 -1
- package/dist/kv/PostgresKvRepository.d.ts.map +0 -1
- package/dist/kv/SqliteKvRepository.d.ts.map +0 -1
- package/dist/kv/SupabaseKvRepository.d.ts.map +0 -1
- package/dist/limiter/IRateLimiterStorage.d.ts.map +0 -1
- package/dist/limiter/InMemoryRateLimiterStorage.d.ts.map +0 -1
- package/dist/limiter/IndexedDbRateLimiterStorage.d.ts.map +0 -1
- package/dist/limiter/PostgresRateLimiterStorage.d.ts.map +0 -1
- package/dist/limiter/SqliteRateLimiterStorage.d.ts.map +0 -1
- package/dist/limiter/SupabaseRateLimiterStorage.d.ts.map +0 -1
- package/dist/tabular/BaseSqlTabularRepository.d.ts.map +0 -1
- package/dist/tabular/CachedTabularRepository.d.ts.map +0 -1
- package/dist/tabular/FsFolderTabularRepository.d.ts.map +0 -1
- package/dist/tabular/ITabularRepository.d.ts.map +0 -1
- package/dist/tabular/InMemoryTabularRepository.d.ts.map +0 -1
- package/dist/tabular/IndexedDbTabularRepository.d.ts.map +0 -1
- package/dist/tabular/PostgresTabularRepository.d.ts.map +0 -1
- package/dist/tabular/SharedInMemoryTabularRepository.d.ts.map +0 -1
- package/dist/tabular/SqliteTabularRepository.d.ts.map +0 -1
- package/dist/tabular/SupabaseTabularRepository.d.ts.map +0 -1
- package/dist/tabular/TabularRepository.d.ts.map +0 -1
- /package/dist/{limiter → queue-limiter}/IRateLimiterStorage.d.ts +0 -0
- /package/dist/{limiter → queue-limiter}/InMemoryRateLimiterStorage.d.ts +0 -0
- /package/dist/{limiter → queue-limiter}/IndexedDbRateLimiterStorage.d.ts +0 -0
- /package/dist/{limiter → queue-limiter}/PostgresRateLimiterStorage.d.ts +0 -0
- /package/dist/{limiter → queue-limiter}/SqliteRateLimiterStorage.d.ts +0 -0
- /package/dist/{limiter → queue-limiter}/SupabaseRateLimiterStorage.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndexedDbTabularStorage.d.ts","sourceRoot":"","sources":["../../src/tabular/IndexedDbTabularStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,oBAAoB,EACpB,UAAU,EAEV,uBAAuB,EAExB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAGL,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,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oBAAoB,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAoEzE;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IA0CxB;;;;;;;OAOG;IACH,kBAAkB,CAChB,QAAQ,EAAE,CAAC,MAAM,EAAE,oBAAoB,CAAC,MAAM,CAAC,KAAK,IAAI,EACxD,OAAO,CAAC,EAAE,uBAAuB,GAChC,MAAM,IAAI;IAQb;;OAEG;IACH,OAAO,IAAI,IAAI;CAOhB"}
|
|
@@ -3,23 +3,24 @@
|
|
|
3
3
|
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { DataPortSchemaObject, FromSchema, JsonSchema } from "@workglow/util";
|
|
6
|
+
import { DataPortSchemaObject, FromSchema, JsonSchema, TypedArraySchemaOptions } from "@workglow/util";
|
|
7
7
|
import type { Pool } from "pg";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
8
|
+
import { BaseSqlTabularStorage } from "./BaseSqlTabularStorage";
|
|
9
|
+
import { ClientProvidedKeysOption } from "./BaseTabularStorage";
|
|
10
|
+
import { AnyTabularStorage, AutoGeneratedKeys, DeleteSearchCriteria, InsertEntity, SimplifyPrimaryKey, TabularChangePayload, TabularSubscribeOptions, ValueOptionType } from "./ITabularStorage";
|
|
11
|
+
export declare const POSTGRES_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<AnyTabularStorage>;
|
|
11
12
|
/**
|
|
12
|
-
* A PostgreSQL-based tabular repository implementation that extends
|
|
13
|
+
* A PostgreSQL-based tabular repository implementation that extends BaseSqlTabularStorage.
|
|
13
14
|
* This class provides persistent storage for data in a PostgreSQL database,
|
|
14
15
|
* making it suitable for multi-user scenarios.
|
|
15
16
|
*
|
|
16
17
|
* @template Schema - The schema definition for the entity
|
|
17
18
|
* @template PrimaryKeyNames - Array of property names that form the primary key
|
|
18
19
|
*/
|
|
19
|
-
export declare class
|
|
20
|
-
|
|
20
|
+
export declare class PostgresTabularStorage<Schema extends DataPortSchemaObject, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]>, Entity = FromSchema<Schema, TypedArraySchemaOptions>, PrimaryKey = SimplifyPrimaryKey<Entity, PrimaryKeyNames>, Value = Omit<Entity, PrimaryKeyNames[number] & keyof Entity>, InsertType extends InsertEntity<Entity, AutoGeneratedKeys<Schema>> = InsertEntity<Entity, AutoGeneratedKeys<Schema>>> extends BaseSqlTabularStorage<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value, InsertType> {
|
|
21
|
+
protected db: Pool;
|
|
21
22
|
/**
|
|
22
|
-
* Creates a new
|
|
23
|
+
* Creates a new PostgresTabularStorage instance.
|
|
23
24
|
*
|
|
24
25
|
* @param db - PostgreSQL db
|
|
25
26
|
* @param table - Name of the table to store data (defaults to "tabular_store")
|
|
@@ -27,14 +28,17 @@ export declare class PostgresTabularRepository<Schema extends DataPortSchemaObje
|
|
|
27
28
|
* @param primaryKeyNames - Array of property names that form the primary key
|
|
28
29
|
* @param indexes - Array of columns or column arrays to make searchable. Each string or single column creates a single-column index,
|
|
29
30
|
* while each array creates a compound index with columns in the specified order.
|
|
31
|
+
* @param clientProvidedKeys - How to handle client-provided values for auto-generated keys
|
|
30
32
|
*/
|
|
31
|
-
constructor(db: Pool, table: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: readonly (keyof Entity | readonly (keyof Entity)[])[]);
|
|
33
|
+
constructor(db: Pool, table: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: readonly (keyof Entity | readonly (keyof Entity)[])[], clientProvidedKeys?: ClientProvidedKeysOption);
|
|
32
34
|
/**
|
|
33
35
|
* Initializes the database table with the required schema.
|
|
34
36
|
* Creates the table if it doesn't exist with primary key and value columns.
|
|
35
37
|
* Must be called before using any other methods.
|
|
36
38
|
*/
|
|
37
39
|
setupDatabase(): Promise<void>;
|
|
40
|
+
protected isVectorFormat(format?: string): boolean;
|
|
41
|
+
protected getVectorDimensions(typeDef: JsonSchema): number | undefined;
|
|
38
42
|
/**
|
|
39
43
|
* Maps TypeScript/JavaScript types to corresponding PostgreSQL data types.
|
|
40
44
|
* Uses additional schema information like minimum/maximum values, nullable status,
|
|
@@ -46,6 +50,7 @@ export declare class PostgresTabularRepository<Schema extends DataPortSchemaObje
|
|
|
46
50
|
protected mapTypeToSQL(typeDef: JsonSchema): string;
|
|
47
51
|
/**
|
|
48
52
|
* Generates the SQL column definitions for primary key fields with constraints
|
|
53
|
+
* Handles auto-generated keys using SERIAL for integers and UUID DEFAULT for strings
|
|
49
54
|
* @returns SQL string containing primary key column definitions
|
|
50
55
|
*/
|
|
51
56
|
protected constructPrimaryKeyColumns($delimiter?: string): string;
|
|
@@ -54,6 +59,10 @@ export declare class PostgresTabularRepository<Schema extends DataPortSchemaObje
|
|
|
54
59
|
* @returns SQL string containing value column definitions
|
|
55
60
|
*/
|
|
56
61
|
protected constructValueColumns($delimiter?: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Convert JavaScript values to PostgreSQL values, including TypedArray to vector string
|
|
64
|
+
*/
|
|
65
|
+
protected jsToSqlValue(column: string, value: Entity[keyof Entity]): ValueOptionType;
|
|
57
66
|
/**
|
|
58
67
|
* Convert PostgreSQL values to JS values. Ensures numeric strings become numbers where schema says number.
|
|
59
68
|
*/
|
|
@@ -64,24 +73,37 @@ export declare class PostgresTabularRepository<Schema extends DataPortSchemaObje
|
|
|
64
73
|
* @returns true if the field should be treated as unsigned
|
|
65
74
|
*/
|
|
66
75
|
protected shouldBeUnsigned(typeDef: JsonSchema): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Gets information about vector columns in the schema
|
|
78
|
+
* @returns Array of objects with column name and dimension
|
|
79
|
+
*/
|
|
80
|
+
protected getVectorColumns(): Array<{
|
|
81
|
+
column: string;
|
|
82
|
+
dimension: number;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Creates vector-specific indexes (HNSW for pgvector)
|
|
86
|
+
* Called after table creation if vector columns exist
|
|
87
|
+
*/
|
|
88
|
+
protected createVectorIndexes(): Promise<void>;
|
|
67
89
|
/**
|
|
68
90
|
* Stores or updates a row in the database.
|
|
69
91
|
* Uses UPSERT (INSERT ... ON CONFLICT DO UPDATE) for atomic operations.
|
|
70
92
|
*
|
|
71
|
-
* @param entity - The entity to store
|
|
93
|
+
* @param entity - The entity to store (may be missing auto-generated keys)
|
|
72
94
|
* @returns The entity with any server-generated fields updated
|
|
73
95
|
* @emits "put" event with the updated entity when successful
|
|
74
96
|
*/
|
|
75
|
-
put(entity:
|
|
97
|
+
put(entity: InsertType): Promise<Entity>;
|
|
76
98
|
/**
|
|
77
99
|
* Stores multiple rows in the database in a bulk operation.
|
|
78
|
-
* Uses
|
|
100
|
+
* Uses individual put calls to ensure auto-generated keys are handled correctly.
|
|
79
101
|
*
|
|
80
|
-
* @param entities - Array of entities to store
|
|
102
|
+
* @param entities - Array of entities to store (may be missing auto-generated keys)
|
|
81
103
|
* @returns Array of entities with any server-generated fields updated
|
|
82
104
|
* @emits "put" event for each entity stored
|
|
83
105
|
*/
|
|
84
|
-
putBulk(entities:
|
|
106
|
+
putBulk(entities: InsertType[]): Promise<Entity[]>;
|
|
85
107
|
/**
|
|
86
108
|
* Retrieves a value from the database by its primary key.
|
|
87
109
|
*
|
|
@@ -149,4 +171,4 @@ export declare class PostgresTabularRepository<Schema extends DataPortSchemaObje
|
|
|
149
171
|
*/
|
|
150
172
|
destroy(): void;
|
|
151
173
|
}
|
|
152
|
-
//# sourceMappingURL=
|
|
174
|
+
//# sourceMappingURL=PostgresTabularStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgresTabularStorage.d.ts","sourceRoot":"","sources":["../../src/tabular/PostgresTabularStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,oBAAoB,EACpB,UAAU,EACV,UAAU,EAEV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SAAS,CAAC;IAyBvD;;;;;;OAMG;IACU,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC;IAuDxE;;;;;OAKG;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;IAkB7C;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAMhC;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAM7B;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,CAAC,QAAQ,EAAE,oBAAoB,CAAC,MAAM,CAAC,GAAG;QACxE,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,EAAE,eAAe,EAAE,CAAC;KAC3B;IAgCD;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,oBAAoB,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAYzE;;;;;OAKG;IACH,kBAAkB,CAChB,QAAQ,EAAE,CAAC,MAAM,EAAE,oBAAoB,CAAC,MAAM,CAAC,KAAK,IAAI,EACxD,OAAO,CAAC,EAAE,uBAAuB,GAChC,MAAM,IAAI;IAIb;;OAEG;IACH,OAAO,IAAI,IAAI;CAGhB"}
|
package/dist/tabular/{SharedInMemoryTabularRepository.d.ts → SharedInMemoryTabularStorage.d.ts}
RENAMED
|
@@ -3,33 +3,34 @@
|
|
|
3
3
|
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { DataPortSchemaObject, FromSchema } from "@workglow/util";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
export declare const SHARED_IN_MEMORY_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<
|
|
6
|
+
import { DataPortSchemaObject, FromSchema, TypedArraySchemaOptions } from "@workglow/util";
|
|
7
|
+
import { BaseTabularStorage, ClientProvidedKeysOption } from "./BaseTabularStorage";
|
|
8
|
+
import { AnyTabularStorage, AutoGeneratedKeys, DeleteSearchCriteria, InsertEntity, SimplifyPrimaryKey, TabularSubscribeOptions } from "./ITabularStorage";
|
|
9
|
+
export declare const SHARED_IN_MEMORY_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<AnyTabularStorage>;
|
|
10
10
|
/**
|
|
11
11
|
* A tabular repository implementation that shares data across browser tabs/windows
|
|
12
|
-
* using BroadcastChannel API. Uses
|
|
12
|
+
* using BroadcastChannel API. Uses InMemoryTabularStorage internally and
|
|
13
13
|
* synchronizes changes across all instances.
|
|
14
14
|
*
|
|
15
15
|
* @template Schema - The schema definition for the entity using JSON Schema
|
|
16
16
|
* @template PrimaryKeyNames - Array of property names that form the primary key
|
|
17
17
|
*/
|
|
18
|
-
export declare class
|
|
18
|
+
export declare class SharedInMemoryTabularStorage<Schema extends DataPortSchemaObject, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]>, Entity = FromSchema<Schema, TypedArraySchemaOptions>, PrimaryKey = SimplifyPrimaryKey<Entity, PrimaryKeyNames>, Value = Omit<Entity, PrimaryKeyNames[number] & keyof Entity>, InsertType extends InsertEntity<Entity, AutoGeneratedKeys<Schema>> = InsertEntity<Entity, AutoGeneratedKeys<Schema>>> extends BaseTabularStorage<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value, InsertType> {
|
|
19
19
|
private channel;
|
|
20
20
|
private channelName;
|
|
21
21
|
private inMemoryRepo;
|
|
22
22
|
private isInitialized;
|
|
23
23
|
private syncInProgress;
|
|
24
24
|
/**
|
|
25
|
-
* Creates a new
|
|
25
|
+
* Creates a new SharedInMemoryTabularStorage instance
|
|
26
26
|
* @param channelName - Unique name for the BroadcastChannel (defaults to "tabular_store")
|
|
27
27
|
* @param schema - Schema defining the structure of the entity
|
|
28
28
|
* @param primaryKeyNames - Array of property names that form the primary key
|
|
29
29
|
* @param indexes - Array of columns or column arrays to make searchable. Each string or single column creates a single-column index,
|
|
30
30
|
* while each array creates a compound index with columns in the specified order.
|
|
31
|
+
* @param clientProvidedKeys - How to handle client-provided values for auto-generated keys
|
|
31
32
|
*/
|
|
32
|
-
constructor(channelName: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: readonly (keyof Entity | readonly (keyof Entity)[])[]);
|
|
33
|
+
constructor(channelName: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: readonly (keyof Entity | readonly (keyof Entity)[])[], clientProvidedKeys?: ClientProvidedKeysOption);
|
|
33
34
|
/**
|
|
34
35
|
* Checks if BroadcastChannel is available in the current environment
|
|
35
36
|
*/
|
|
@@ -39,7 +40,7 @@ export declare class SharedInMemoryTabularRepository<Schema extends DataPortSche
|
|
|
39
40
|
*/
|
|
40
41
|
private initializeBroadcastChannel;
|
|
41
42
|
/**
|
|
42
|
-
* Sets up event forwarding from the internal
|
|
43
|
+
* Sets up event forwarding from the internal InMemoryTabularStorage
|
|
43
44
|
*/
|
|
44
45
|
private setupEventForwarding;
|
|
45
46
|
/**
|
|
@@ -68,14 +69,14 @@ export declare class SharedInMemoryTabularRepository<Schema extends DataPortSche
|
|
|
68
69
|
* @returns The stored entity
|
|
69
70
|
* @emits 'put' event with the stored entity when successful
|
|
70
71
|
*/
|
|
71
|
-
put(value:
|
|
72
|
+
put(value: InsertType): Promise<Entity>;
|
|
72
73
|
/**
|
|
73
74
|
* Stores multiple key-value pairs in the repository in a bulk operation
|
|
74
75
|
* @param values - Array of combined objects to store
|
|
75
76
|
* @returns Array of stored entities
|
|
76
77
|
* @emits 'put' event for each value stored
|
|
77
78
|
*/
|
|
78
|
-
putBulk(values:
|
|
79
|
+
putBulk(values: InsertType[]): Promise<Entity[]>;
|
|
79
80
|
/**
|
|
80
81
|
* Retrieves a value by its key
|
|
81
82
|
* @param key - The primary key object to look up
|
|
@@ -120,7 +121,7 @@ export declare class SharedInMemoryTabularRepository<Schema extends DataPortSche
|
|
|
120
121
|
deleteSearch(criteria: DeleteSearchCriteria<Entity>): Promise<void>;
|
|
121
122
|
/**
|
|
122
123
|
* Subscribes to changes in the repository.
|
|
123
|
-
* Delegates to the internal
|
|
124
|
+
* Delegates to the internal InMemoryTabularStorage which monitors local changes.
|
|
124
125
|
* Changes from other tabs/windows are already propagated via BroadcastChannel.
|
|
125
126
|
*
|
|
126
127
|
* @param callback - Function called when a change occurs
|
|
@@ -133,4 +134,4 @@ export declare class SharedInMemoryTabularRepository<Schema extends DataPortSche
|
|
|
133
134
|
*/
|
|
134
135
|
destroy(): void;
|
|
135
136
|
}
|
|
136
|
-
//# sourceMappingURL=
|
|
137
|
+
//# sourceMappingURL=SharedInMemoryTabularStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SharedInMemoryTabularStorage.d.ts","sourceRoot":"","sources":["../../src/tabular/SharedInMemoryTabularStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,oBAAoB,EACpB,UAAU,EACV,uBAAuB,EACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,mBAAmB,CAAC;AAG3B,eAAO,MAAM,mCAAmC,0DAE/C,CAAC;AAcF;;;;;;;GAOG;AACH,qBAAa,4BAA4B,CACvC,MAAM,SAAS,oBAAoB,EACnC,eAAe,SAAS,aAAa,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,EAEjE,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,uBAAuB,CAAC,EACpD,UAAU,GAAG,kBAAkB,CAAC,MAAM,EAAE,eAAe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AG,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAIvD;;;;;OAKG;IACG,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC;IAIjE;;;;OAIG;IACG,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMvD;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAKhC;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC;IAI7C;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAI7B;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,oBAAoB,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAQzE;;;;;;;;OAQG;IACH,kBAAkB,CAChB,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,EAC/B,OAAO,CAAC,EAAE,uBAAuB,GAChC,MAAM,IAAI;IAIb;;OAEG;IACH,OAAO,IAAI,IAAI;CAOhB"}
|
|
@@ -4,16 +4,17 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { Sqlite } from "@workglow/sqlite";
|
|
7
|
-
import { DataPortSchemaObject, FromSchema, JsonSchema } from "@workglow/util";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
7
|
+
import { DataPortSchemaObject, FromSchema, JsonSchema, TypedArraySchemaOptions } from "@workglow/util";
|
|
8
|
+
import { BaseSqlTabularStorage } from "./BaseSqlTabularStorage";
|
|
9
|
+
import { ClientProvidedKeysOption, KeyGenerationStrategy } from "./BaseTabularStorage";
|
|
10
|
+
import { AnyTabularStorage, AutoGeneratedKeys, DeleteSearchCriteria, InsertEntity, SimplifyPrimaryKey, TabularChangePayload, TabularSubscribeOptions, ValueOptionType } from "./ITabularStorage";
|
|
11
|
+
export declare const SQLITE_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<AnyTabularStorage>;
|
|
11
12
|
/**
|
|
12
13
|
* A SQLite-based key-value repository implementation.
|
|
13
14
|
* @template Schema - The schema definition for the entity
|
|
14
15
|
* @template PrimaryKeyNames - Array of property names that form the primary key
|
|
15
16
|
*/
|
|
16
|
-
export declare class
|
|
17
|
+
export declare class SqliteTabularStorage<Schema extends DataPortSchemaObject, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]>, Entity = FromSchema<Schema, TypedArraySchemaOptions>, PrimaryKey = SimplifyPrimaryKey<Entity, PrimaryKeyNames>, Value = Omit<Entity, PrimaryKeyNames[number] & keyof Entity>, InsertType extends InsertEntity<Entity, AutoGeneratedKeys<Schema>> = InsertEntity<Entity, AutoGeneratedKeys<Schema>>> extends BaseSqlTabularStorage<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value, InsertType> {
|
|
17
18
|
/** The SQLite database instance */
|
|
18
19
|
private db;
|
|
19
20
|
/**
|
|
@@ -24,8 +25,13 @@ export declare class SqliteTabularRepository<Schema extends DataPortSchemaObject
|
|
|
24
25
|
* @param primaryKeyNames - Array of property names that form the primary key
|
|
25
26
|
* @param indexes - Array of columns or column arrays to make searchable. Each string or single column creates a single-column index,
|
|
26
27
|
* while each array creates a compound index with columns in the specified order.
|
|
28
|
+
* @param clientProvidedKeys - How to handle client-provided values for auto-generated keys
|
|
27
29
|
*/
|
|
28
|
-
constructor(dbOrPath: string | Sqlite.Database, table: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: readonly (keyof Entity | readonly (keyof Entity)[])[]);
|
|
30
|
+
constructor(dbOrPath: string | Sqlite.Database, table: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: readonly (keyof Entity | readonly (keyof Entity)[])[], clientProvidedKeys?: ClientProvidedKeysOption);
|
|
31
|
+
/**
|
|
32
|
+
* Override to handle SQLite's INTEGER PRIMARY KEY for auto-increment
|
|
33
|
+
*/
|
|
34
|
+
protected constructPrimaryKeyColumns($delimiter?: string): string;
|
|
29
35
|
/**
|
|
30
36
|
* Creates the database table if it doesn't exist with the defined schema.
|
|
31
37
|
* Must be called before using any other methods.
|
|
@@ -48,20 +54,28 @@ export declare class SqliteTabularRepository<Schema extends DataPortSchemaObject
|
|
|
48
54
|
* @returns The corresponding SQLite column type
|
|
49
55
|
*/
|
|
50
56
|
protected mapTypeToSQL(typeDef: JsonSchema): string;
|
|
57
|
+
/**
|
|
58
|
+
* Generates a key value for string UUID keys
|
|
59
|
+
* Integer keys are auto-generated by SQLite's INTEGER PRIMARY KEY
|
|
60
|
+
* @param columnName - Name of the column to generate a key for
|
|
61
|
+
* @param strategy - The generation strategy to use
|
|
62
|
+
* @returns The generated key value
|
|
63
|
+
*/
|
|
64
|
+
protected generateKeyValue(columnName: string, strategy: KeyGenerationStrategy): string | number;
|
|
51
65
|
/**
|
|
52
66
|
* Stores a key-value pair in the database
|
|
53
|
-
* @param entity - The entity to store
|
|
67
|
+
* @param entity - The entity to store (may be missing auto-generated keys)
|
|
54
68
|
* @returns The entity with any server-generated fields updated
|
|
55
69
|
* @emits 'put' event when successful
|
|
56
70
|
*/
|
|
57
|
-
put(entity:
|
|
71
|
+
put(entity: InsertType): Promise<Entity>;
|
|
58
72
|
/**
|
|
59
73
|
* Stores multiple key-value pairs in the database in a bulk operation
|
|
60
|
-
* @param entities - Array of entities to store
|
|
74
|
+
* @param entities - Array of entities to store (may be missing auto-generated keys)
|
|
61
75
|
* @returns Array of entities with any server-generated fields updated
|
|
62
76
|
* @emits 'put' event for each entity stored
|
|
63
77
|
*/
|
|
64
|
-
putBulk(entities:
|
|
78
|
+
putBulk(entities: InsertType[]): Promise<Entity[]>;
|
|
65
79
|
/**
|
|
66
80
|
* Retrieves a value from the database by its key
|
|
67
81
|
* @param key - The primary key object to look up
|
|
@@ -126,4 +140,4 @@ export declare class SqliteTabularRepository<Schema extends DataPortSchemaObject
|
|
|
126
140
|
*/
|
|
127
141
|
destroy(): void;
|
|
128
142
|
}
|
|
129
|
-
//# sourceMappingURL=
|
|
143
|
+
//# sourceMappingURL=SqliteTabularStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqliteTabularStorage.d.ts","sourceRoot":"","sources":["../../src/tabular/SqliteTabularStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAEL,oBAAoB,EACpB,UAAU,EACV,UAAU,EACV,uBAAuB,EAExB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACvF,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EAGZ,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAK3B,eAAO,MAAM,yBAAyB,0DAErC,CAAC;AAOF;;;;GAIG;AACH,qBAAa,oBAAoB,CAC/B,MAAM,SAAS,oBAAoB,EACnC,eAAe,SAAS,aAAa,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,EAEjE,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,uBAAuB,CAAC,EACpD,UAAU,GAAG,kBAAkB,CAAC,MAAM,EAAE,eAAe,CAAC,EACxD,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,EAC5D,UAAU,SAAS,YAAY,CAAC,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC,GAAG,YAAY,CAC/E,MAAM,EACN,iBAAiB,CAAC,MAAM,C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AG,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;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,CAAC,QAAQ,EAAE,oBAAoB,CAAC,MAAM,CAAC,GAAG;QACxE,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,EAAE,eAAe,EAAE,CAAC;KAC3B;IA8BD;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,oBAAoB,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAczE;;;;;OAKG;IACH,kBAAkB,CAChB,QAAQ,EAAE,CAAC,MAAM,EAAE,oBAAoB,CAAC,MAAM,CAAC,KAAK,IAAI,EACxD,OAAO,CAAC,EAAE,uBAAuB,GAChC,MAAM,IAAI;IAIb;;OAEG;IACH,OAAO,IAAI,IAAI;CAGhB"}
|
|
@@ -4,23 +4,24 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import type { SupabaseClient } from "@supabase/supabase-js";
|
|
7
|
-
import { DataPortSchemaObject, FromSchema, JsonSchema } from "@workglow/util";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
7
|
+
import { DataPortSchemaObject, FromSchema, JsonSchema, TypedArraySchemaOptions } from "@workglow/util";
|
|
8
|
+
import { BaseSqlTabularStorage } from "./BaseSqlTabularStorage";
|
|
9
|
+
import { ClientProvidedKeysOption } from "./BaseTabularStorage";
|
|
10
|
+
import { AnyTabularStorage, AutoGeneratedKeys, DeleteSearchCriteria, InsertEntity, SimplifyPrimaryKey, TabularChangePayload, TabularSubscribeOptions, ValueOptionType } from "./ITabularStorage";
|
|
11
|
+
export declare const SUPABASE_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken<AnyTabularStorage>;
|
|
11
12
|
/**
|
|
12
|
-
* A Supabase-based tabular repository implementation that extends
|
|
13
|
+
* A Supabase-based tabular repository implementation that extends BaseSqlTabularStorage.
|
|
13
14
|
* This class provides persistent storage for data in a Supabase database,
|
|
14
15
|
* making it suitable for multi-user scenarios.
|
|
15
16
|
*
|
|
16
17
|
* @template Schema - The schema definition for the entity
|
|
17
18
|
* @template PrimaryKeyNames - Array of property names that form the primary key
|
|
18
19
|
*/
|
|
19
|
-
export declare class
|
|
20
|
+
export declare class SupabaseTabularStorage<Schema extends DataPortSchemaObject, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]>, Entity = FromSchema<Schema, TypedArraySchemaOptions>, PrimaryKey = SimplifyPrimaryKey<Entity, PrimaryKeyNames>, Value = Omit<Entity, PrimaryKeyNames[number] & keyof Entity>, InsertType extends InsertEntity<Entity, AutoGeneratedKeys<Schema>> = InsertEntity<Entity, AutoGeneratedKeys<Schema>>> extends BaseSqlTabularStorage<Schema, PrimaryKeyNames, Entity, PrimaryKey, Value, InsertType> {
|
|
20
21
|
private client;
|
|
21
22
|
private realtimeChannel;
|
|
22
23
|
/**
|
|
23
|
-
* Creates a new
|
|
24
|
+
* Creates a new SupabaseTabularStorage instance.
|
|
24
25
|
*
|
|
25
26
|
* @param client - Supabase client instance
|
|
26
27
|
* @param table - Name of the table to store data (defaults to "tabular_store")
|
|
@@ -28,13 +29,13 @@ export declare class SupabaseTabularRepository<Schema extends DataPortSchemaObje
|
|
|
28
29
|
* @param primaryKeyNames - Array of property names that form the primary key
|
|
29
30
|
* @param indexes - Array of columns or column arrays to make searchable. Each string or single column creates a single-column index,
|
|
30
31
|
* while each array creates a compound index with columns in the specified order.
|
|
32
|
+
* @param clientProvidedKeys - How to handle client-provided values for auto-generated keys
|
|
31
33
|
*/
|
|
32
|
-
constructor(client: SupabaseClient, table: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: readonly (keyof Entity | readonly (keyof Entity)[])[]);
|
|
34
|
+
constructor(client: SupabaseClient, table: string | undefined, schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes?: readonly (keyof Entity | readonly (keyof Entity)[])[], clientProvidedKeys?: ClientProvidedKeysOption);
|
|
33
35
|
/**
|
|
34
36
|
* Initializes the database table with the required schema.
|
|
35
37
|
* Creates the table if it doesn't exist with primary key and value columns.
|
|
36
38
|
* Must be called before using any other methods.
|
|
37
|
-
* Note: By default, assumes the table already exists (set isSetup in tests).
|
|
38
39
|
*/
|
|
39
40
|
setupDatabase(): Promise<void>;
|
|
40
41
|
/**
|
|
@@ -48,6 +49,7 @@ export declare class SupabaseTabularRepository<Schema extends DataPortSchemaObje
|
|
|
48
49
|
protected mapTypeToSQL(typeDef: JsonSchema): string;
|
|
49
50
|
/**
|
|
50
51
|
* Generates the SQL column definitions for primary key fields with constraints
|
|
52
|
+
* Handles auto-generated keys using SERIAL for integers and UUID DEFAULT for strings
|
|
51
53
|
* @returns SQL string containing primary key column definitions
|
|
52
54
|
*/
|
|
53
55
|
protected constructPrimaryKeyColumns($delimiter?: string): string;
|
|
@@ -70,20 +72,20 @@ export declare class SupabaseTabularRepository<Schema extends DataPortSchemaObje
|
|
|
70
72
|
* Stores or updates a row in the database.
|
|
71
73
|
* Uses UPSERT (INSERT ... ON CONFLICT DO UPDATE) for atomic operations.
|
|
72
74
|
*
|
|
73
|
-
* @param entity - The entity to store
|
|
75
|
+
* @param entity - The entity to store (may be missing auto-generated keys)
|
|
74
76
|
* @returns The entity with any server-generated fields updated
|
|
75
77
|
* @emits "put" event with the updated entity when successful
|
|
76
78
|
*/
|
|
77
|
-
put(entity:
|
|
79
|
+
put(entity: InsertType): Promise<Entity>;
|
|
78
80
|
/**
|
|
79
81
|
* Stores multiple rows in the database in a bulk operation.
|
|
80
|
-
* Uses
|
|
82
|
+
* Uses individual put calls to ensure auto-generated keys are handled correctly.
|
|
81
83
|
*
|
|
82
|
-
* @param entities - Array of entities to store
|
|
84
|
+
* @param entities - Array of entities to store (may be missing auto-generated keys)
|
|
83
85
|
* @returns Array of entities with any server-generated fields updated
|
|
84
86
|
* @emits "put" event for each entity stored
|
|
85
87
|
*/
|
|
86
|
-
putBulk(entities:
|
|
88
|
+
putBulk(entities: InsertType[]): Promise<Entity[]>;
|
|
87
89
|
/**
|
|
88
90
|
* Retrieves a value from the database by its primary key.
|
|
89
91
|
*
|
|
@@ -150,4 +152,4 @@ export declare class SupabaseTabularRepository<Schema extends DataPortSchemaObje
|
|
|
150
152
|
*/
|
|
151
153
|
destroy(): void;
|
|
152
154
|
}
|
|
153
|
-
//# sourceMappingURL=
|
|
155
|
+
//# sourceMappingURL=SupabaseTabularStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SupabaseTabularStorage.d.ts","sourceRoot":"","sources":["../../src/tabular/SupabaseTabularStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAmB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAEL,oBAAoB,EACpB,UAAU,EACV,UAAU,EACV,uBAAuB,EACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EAGZ,kBAAkB,EAClB,oBAAoB,EAEpB,uBAAuB,EACvB,eAAe,EAChB,MAAM,mB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AAO,IAAI,IAAI;CAMhB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { AnyTabularStorage } from "./ITabularStorage";
|
|
7
|
+
/**
|
|
8
|
+
* Service token for the tabular repository registry
|
|
9
|
+
* Maps repository IDs to ITabularStorage instances
|
|
10
|
+
*/
|
|
11
|
+
export declare const TABULAR_REPOSITORIES: import("@workglow/util").ServiceToken<Map<string, AnyTabularStorage>>;
|
|
12
|
+
/**
|
|
13
|
+
* Gets the global tabular repository registry
|
|
14
|
+
* @returns Map of tabular repository ID to instance
|
|
15
|
+
*/
|
|
16
|
+
export declare function getGlobalTabularRepositories(): Map<string, AnyTabularStorage>;
|
|
17
|
+
/**
|
|
18
|
+
* Registers a tabular repository globally by ID
|
|
19
|
+
* @param id The unique identifier for this repository
|
|
20
|
+
* @param repository The repository instance to register
|
|
21
|
+
*/
|
|
22
|
+
export declare function registerTabularRepository(id: string, repository: AnyTabularStorage): void;
|
|
23
|
+
/**
|
|
24
|
+
* Gets a tabular repository by ID from the global registry
|
|
25
|
+
* @param id The repository identifier
|
|
26
|
+
* @returns The repository instance or undefined if not found
|
|
27
|
+
*/
|
|
28
|
+
export declare function getTabularRepository(id: string): AnyTabularStorage | undefined;
|
|
29
|
+
//# sourceMappingURL=TabularStorageRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TabularStorageRegistry.d.ts","sourceRoot":"","sources":["../../src/tabular/TabularStorageRegistry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,oBAAoB,uEAEhC,CAAC;AAWF;;;GAGG;AACH,wBAAgB,4BAA4B,IAAI,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAE7E;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,GAAG,IAAI,CAGzF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAE9E"}
|
|
@@ -32,7 +32,7 @@ export interface MigrationOptions {
|
|
|
32
32
|
* Ensures that an IndexedDB table exists with the specified schema.
|
|
33
33
|
* Performs migrations as needed without data loss when possible.
|
|
34
34
|
*/
|
|
35
|
-
export declare function ensureIndexedDbTable(tableName: string, primaryKey: string | string[], expectedIndexes?: ExpectedIndexDefinition[], options?: MigrationOptions): Promise<IDBDatabase>;
|
|
35
|
+
export declare function ensureIndexedDbTable(tableName: string, primaryKey: string | string[], expectedIndexes?: ExpectedIndexDefinition[], options?: MigrationOptions, autoIncrement?: boolean): Promise<IDBDatabase>;
|
|
36
36
|
/**
|
|
37
37
|
* Utility function to delete a database (for testing or cleanup)
|
|
38
38
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IndexedDbTable.d.ts","sourceRoot":"","sources":["../../src/util/IndexedDbTable.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,WAAW,CAAC;IAChB,WAAW,EAAE,cAAc,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,CAAC,OAAO,EAAE,GAAG,GAAG,GAAG,GAAG,OAAO,CAAC,GAAG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AO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;CAC/D;AA2cD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,EAC7B,eAAe,GAAE,uBAAuB,EAAO,EAC/C,OAAO,GAAE,gBAAqB,EAC9B,aAAa,GAAE,OAAe,GAC7B,OAAO,CAAC,WAAW,CAAC,CA6JtB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzE"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { DataPortSchemaObject, EventParameters, FromSchema, TypedArray, TypedArraySchemaOptions } from "@workglow/util";
|
|
7
|
+
import type { ITabularStorage, TabularEventListeners } from "../tabular/ITabularStorage";
|
|
8
|
+
export type AnyVectorStorage = IVectorStorage<any, any, any, any>;
|
|
9
|
+
/**
|
|
10
|
+
* Options for vector search operations
|
|
11
|
+
*/
|
|
12
|
+
export interface VectorSearchOptions<Metadata extends Record<string, unknown> | undefined = Record<string, unknown>> {
|
|
13
|
+
readonly topK?: number;
|
|
14
|
+
readonly filter?: Partial<Metadata>;
|
|
15
|
+
readonly scoreThreshold?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Options for hybrid search (vector + full-text)
|
|
19
|
+
*/
|
|
20
|
+
export interface HybridSearchOptions<Metadata extends Record<string, unknown> | undefined = Record<string, unknown>> extends VectorSearchOptions<Metadata> {
|
|
21
|
+
readonly textQuery: string;
|
|
22
|
+
readonly vectorWeight?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Type definitions for document chunk vector repository events
|
|
26
|
+
*/
|
|
27
|
+
export interface VectorEventListeners<PrimaryKey, Entity> extends TabularEventListeners<PrimaryKey, Entity> {
|
|
28
|
+
similaritySearch: (query: TypedArray, results: (Entity & {
|
|
29
|
+
score: number;
|
|
30
|
+
})[]) => void;
|
|
31
|
+
hybridSearch: (query: TypedArray, results: (Entity & {
|
|
32
|
+
score: number;
|
|
33
|
+
})[]) => void;
|
|
34
|
+
}
|
|
35
|
+
export type VectorEventName = keyof VectorEventListeners<any, any>;
|
|
36
|
+
export type VectorEventListener<Event extends VectorEventName, PrimaryKey, Entity> = VectorEventListeners<PrimaryKey, Entity>[Event];
|
|
37
|
+
export type VectorEventParameters<Event extends VectorEventName, PrimaryKey, Entity> = EventParameters<VectorEventListeners<PrimaryKey, Entity>, Event>;
|
|
38
|
+
/**
|
|
39
|
+
* Interface defining the contract for vector storage repositories.
|
|
40
|
+
* These repositories store vector embeddings with metadata.
|
|
41
|
+
* Extends ITabularStorage to provide standard storage operations,
|
|
42
|
+
* plus vector-specific similarity search capabilities.
|
|
43
|
+
* Supports various vector types including quantized formats.
|
|
44
|
+
*
|
|
45
|
+
* @typeParam Schema - The schema definition for the entity using JSON Schema
|
|
46
|
+
* @typeParam PrimaryKeyNames - Array of property names that form the primary key
|
|
47
|
+
* @typeParam Entity - The entity type
|
|
48
|
+
*/
|
|
49
|
+
export interface IVectorStorage<Metadata extends Record<string, unknown> | undefined, Schema extends DataPortSchemaObject, Entity = FromSchema<Schema, TypedArraySchemaOptions>, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]> = ReadonlyArray<keyof Schema["properties"]>> extends ITabularStorage<Schema, PrimaryKeyNames, Entity> {
|
|
50
|
+
/**
|
|
51
|
+
* Get the vector dimension
|
|
52
|
+
* @returns The vector dimension
|
|
53
|
+
*/
|
|
54
|
+
getVectorDimensions(): number;
|
|
55
|
+
/**
|
|
56
|
+
* Search for similar vectors using similarity scoring
|
|
57
|
+
* @param query - Query vector to compare against
|
|
58
|
+
* @param options - Search options (topK, filter, scoreThreshold)
|
|
59
|
+
* @returns Array of search results sorted by similarity (highest first)
|
|
60
|
+
*/
|
|
61
|
+
similaritySearch(query: TypedArray, options?: VectorSearchOptions<Metadata>): Promise<(Entity & {
|
|
62
|
+
score: number;
|
|
63
|
+
})[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Hybrid search combining vector similarity with full-text search
|
|
66
|
+
* This is optional and may not be supported by all implementations
|
|
67
|
+
* @param query - Query vector to compare against
|
|
68
|
+
* @param options - Hybrid search options including text query
|
|
69
|
+
* @returns Array of search results sorted by combined relevance
|
|
70
|
+
*/
|
|
71
|
+
hybridSearch?(query: TypedArray, options: HybridSearchOptions<Metadata>): Promise<(Entity & {
|
|
72
|
+
score: number;
|
|
73
|
+
})[]>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* TODO: Given a schema, return the vector column by searching for a property with a TypedArray format (or TypedArray:xxx format)
|
|
77
|
+
*/
|
|
78
|
+
export declare function getVectorProperty<Schema extends DataPortSchemaObject>(schema: Schema): keyof Schema["properties"] | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Given a schema, return the property which is an object with format "metadata"
|
|
81
|
+
*/
|
|
82
|
+
export declare function getMetadataProperty<Schema extends DataPortSchemaObject>(schema: Schema): keyof Schema["properties"] | undefined;
|
|
83
|
+
//# sourceMappingURL=IVectorStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IVectorStorage.d.ts","sourceRoot":"","sources":["../../src/vector/IVectorStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,UAAU,EAEV,UAAU,EACV,uBAAuB,EACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEzF,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAC,GAAG,EAAE,GAAG,E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AAoB,EACrE,MAAM,EAAE,MAAM,GACb,MAAM,MAAM,CAAC,YAAY,CAAC,GAAG,SAAS,CAOxC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { DataPortSchemaObject, FromSchema, TypedArray, TypedArraySchemaOptions } from "@workglow/util";
|
|
7
|
+
import { InMemoryTabularStorage } from "../tabular/InMemoryTabularStorage";
|
|
8
|
+
import { type HybridSearchOptions, type IVectorStorage, type VectorSearchOptions } from "./IVectorStorage";
|
|
9
|
+
/**
|
|
10
|
+
* In-memory document chunk vector repository implementation.
|
|
11
|
+
* Extends InMemoryTabularStorage for storage.
|
|
12
|
+
* Suitable for testing and small-scale browser applications.
|
|
13
|
+
* Supports all vector types including quantized formats.
|
|
14
|
+
*
|
|
15
|
+
* @template Metadata - The metadata type for the document chunk
|
|
16
|
+
* @template Vector - The vector type for the document chunk
|
|
17
|
+
*/
|
|
18
|
+
export declare class InMemoryVectorStorage<Schema extends DataPortSchemaObject, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]>, Metadata extends Record<string, unknown> = Record<string, unknown>, Vector extends TypedArray = Float32Array, Entity = FromSchema<Schema, TypedArraySchemaOptions>> extends InMemoryTabularStorage<Schema, PrimaryKeyNames, Entity> implements IVectorStorage<Metadata, Schema, Entity, PrimaryKeyNames> {
|
|
19
|
+
private vectorDimensions;
|
|
20
|
+
private VectorType;
|
|
21
|
+
private vectorPropertyName;
|
|
22
|
+
private metadataPropertyName;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new in-memory document chunk vector repository
|
|
25
|
+
* @param dimensions - The number of dimensions of the vector
|
|
26
|
+
* @param VectorType - The type of vector to use (defaults to Float32Array)
|
|
27
|
+
*/
|
|
28
|
+
constructor(schema: Schema, primaryKeyNames: PrimaryKeyNames, indexes: readonly (keyof Entity | readonly (keyof Entity)[])[] | undefined, dimensions: number, VectorType?: new (array: number[]) => TypedArray);
|
|
29
|
+
/**
|
|
30
|
+
* Get the vector dimensions
|
|
31
|
+
* @returns The vector dimensions
|
|
32
|
+
*/
|
|
33
|
+
getVectorDimensions(): number;
|
|
34
|
+
similaritySearch(query: TypedArray, options?: VectorSearchOptions<Record<string, unknown>>): Promise<(Entity & {
|
|
35
|
+
score: number;
|
|
36
|
+
})[]>;
|
|
37
|
+
hybridSearch(query: TypedArray, options: HybridSearchOptions<Record<string, unknown>>): Promise<(Entity & {
|
|
38
|
+
score: number;
|
|
39
|
+
})[]>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=InMemoryVectorStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryVectorStorage.d.ts","sourceRoot":"","sources":["../../src/vector/InMemoryVectorStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,UAAU,EACV,UAAU,EACV,uBAAuB,EACxB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAiC1B;;;;;;;;GAQG;AACH,qBAAa,qBAAqB,CAChC,MAAM,SAAS,oBAAoB,EACnC,eAAe,SAAS,aAAa,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,EACjE,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,MAAM,SAAS,UAAU,GAAG,YAAY,EACxC,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAEpD,SAAQ,sBAAsB,CAAC,MAAM,EAAE,eAAe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