@workglow/storage 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -16
- package/dist/browser.js +89 -19
- package/dist/browser.js.map +11 -10
- package/dist/bun.js +61 -15
- package/dist/bun.js.map +14 -13
- package/dist/common.d.ts +1 -0
- package/dist/common.d.ts.map +1 -1
- package/dist/credentials/LazyEncryptedCredentialStore.d.ts +63 -0
- package/dist/credentials/LazyEncryptedCredentialStore.d.ts.map +1 -0
- package/dist/kv/IKvStorage.d.ts.map +1 -1
- package/dist/node.js +61 -15
- package/dist/node.js.map +14 -13
- package/dist/postgres/browser.d.ts.map +1 -1
- package/dist/postgres/node-bun.d.ts.map +1 -1
- package/dist/queue/IQueueStorage.d.ts.map +1 -1
- package/dist/queue/InMemoryQueueStorage.d.ts.map +1 -1
- package/dist/queue/SqliteQueueStorage.d.ts.map +1 -1
- package/dist/sqlite/browser.d.ts.map +1 -1
- package/dist/sqlite/bun.d.ts.map +1 -1
- package/dist/sqlite/node.d.ts.map +1 -1
- package/dist/tabular/BaseSqlTabularStorage.d.ts.map +1 -1
- package/dist/tabular/BaseTabularStorage.d.ts +2 -2
- package/dist/tabular/BaseTabularStorage.d.ts.map +1 -1
- package/dist/tabular/IndexedDbTabularStorage.d.ts.map +1 -1
- package/dist/tabular/PostgresTabularStorage.d.ts.map +1 -1
- package/dist/tabular/SharedInMemoryTabularStorage.d.ts +2 -0
- package/dist/tabular/SharedInMemoryTabularStorage.d.ts.map +1 -1
- package/dist/tabular/SqliteTabularStorage.d.ts.map +1 -1
- package/dist/tabular/StorageError.d.ts +0 -2
- package/dist/tabular/StorageError.d.ts.map +1 -1
- package/dist/tabular/SupabaseTabularStorage.d.ts.map +1 -1
- package/dist/tabular/TabularStorageRegistry.d.ts.map +1 -1
- package/dist/vector/InMemoryVectorStorage.d.ts +2 -2
- package/dist/vector/InMemoryVectorStorage.d.ts.map +1 -1
- package/dist/vector/IndexedDbVectorStorage.d.ts +2 -2
- package/dist/vector/IndexedDbVectorStorage.d.ts.map +1 -1
- package/dist/vector/PostgresVectorStorage.d.ts +2 -2
- package/dist/vector/PostgresVectorStorage.d.ts.map +1 -1
- package/dist/vector/SqliteAiVectorStorage.d.ts +2 -2
- package/dist/vector/SqliteAiVectorStorage.d.ts.map +1 -1
- package/dist/vector/SqliteVectorStorage.d.ts +2 -2
- package/dist/vector/SqliteVectorStorage.d.ts.map +1 -1
- package/package.json +12 -15
package/README.md
CHANGED
|
@@ -641,11 +641,7 @@ await task.run({ dataSource: userRepoInstance }); // Direct instance
|
|
|
641
641
|
The package provides schema helper functions for defining repository inputs with proper format annotations:
|
|
642
642
|
|
|
643
643
|
```typescript
|
|
644
|
-
import {
|
|
645
|
-
TypeTabularStorage,
|
|
646
|
-
TypeVectorRepository,
|
|
647
|
-
TypeDocumentRepository,
|
|
648
|
-
} from "@workglow/storage";
|
|
644
|
+
import { TypeTabularStorage } from "@workglow/storage";
|
|
649
645
|
|
|
650
646
|
// Tabular repository (format: "storage:tabular")
|
|
651
647
|
const tabularSchema = TypeTabularStorage({
|
|
@@ -653,17 +649,6 @@ const tabularSchema = TypeTabularStorage({
|
|
|
653
649
|
description: "Tabular data repository",
|
|
654
650
|
});
|
|
655
651
|
|
|
656
|
-
// Vector repository (format: "repository:document-node-vector")
|
|
657
|
-
const vectorSchema = TypeVectorRepository({
|
|
658
|
-
title: "Embeddings Store",
|
|
659
|
-
description: "Vector embeddings repository",
|
|
660
|
-
});
|
|
661
|
-
|
|
662
|
-
// Document repository (format: "repository:document")
|
|
663
|
-
const docSchema = TypeDocumentRepository({
|
|
664
|
-
title: "Document Store",
|
|
665
|
-
description: "Document storage repository",
|
|
666
|
-
});
|
|
667
652
|
```
|
|
668
653
|
|
|
669
654
|
### Event-Driven Architecture
|
package/dist/browser.js
CHANGED
|
@@ -11,16 +11,10 @@ import { BaseError } from "@workglow/util";
|
|
|
11
11
|
|
|
12
12
|
class StorageError extends BaseError {
|
|
13
13
|
static type = "StorageError";
|
|
14
|
-
constructor(message) {
|
|
15
|
-
super(message);
|
|
16
|
-
}
|
|
17
14
|
}
|
|
18
15
|
|
|
19
16
|
class StorageValidationError extends StorageError {
|
|
20
17
|
static type = "StorageValidationError";
|
|
21
|
-
constructor(message) {
|
|
22
|
-
super(message);
|
|
23
|
-
}
|
|
24
18
|
}
|
|
25
19
|
|
|
26
20
|
class StorageEmptyCriteriaError extends StorageValidationError {
|
|
@@ -121,14 +115,10 @@ class BaseTabularStorage {
|
|
|
121
115
|
}
|
|
122
116
|
}
|
|
123
117
|
if (autoGeneratedKeys.length > 1) {
|
|
124
|
-
throw new Error(`Multiple auto-generated keys detected: ${autoGeneratedKeys.join(", ")}. ` + `
|
|
118
|
+
throw new Error(`Multiple auto-generated keys detected: ${autoGeneratedKeys.join(", ")}. ` + `At most one primary key column can be auto-generated.`);
|
|
125
119
|
}
|
|
126
120
|
if (autoGeneratedKeys.length > 0) {
|
|
127
121
|
const autoGenKeyName = autoGeneratedKeys[0];
|
|
128
|
-
const firstPrimaryKey = String(primaryKeyNames[0]);
|
|
129
|
-
if (autoGenKeyName !== firstPrimaryKey) {
|
|
130
|
-
throw new Error(`Auto-generated key "${autoGenKeyName}" must be the first primary key column. ` + `Current first primary key is "${firstPrimaryKey}".`);
|
|
131
|
-
}
|
|
132
122
|
this.autoGeneratedKeyName = autoGenKeyName;
|
|
133
123
|
this.autoGeneratedKeyStrategy = this.determineGenerationStrategy(autoGenKeyName, schema.properties[autoGenKeyName]);
|
|
134
124
|
}
|
|
@@ -1110,12 +1100,11 @@ function hfFeatureToJsonSchema(feature) {
|
|
|
1110
1100
|
import {
|
|
1111
1101
|
createServiceToken as createServiceToken5,
|
|
1112
1102
|
globalServiceRegistry,
|
|
1103
|
+
registerInputCompactor,
|
|
1113
1104
|
registerInputResolver
|
|
1114
1105
|
} from "@workglow/util";
|
|
1115
1106
|
var TABULAR_REPOSITORIES = createServiceToken5("storage.tabular.repositories");
|
|
1116
|
-
|
|
1117
|
-
globalServiceRegistry.register(TABULAR_REPOSITORIES, () => new Map, true);
|
|
1118
|
-
}
|
|
1107
|
+
globalServiceRegistry.registerIfAbsent(TABULAR_REPOSITORIES, () => new Map, true);
|
|
1119
1108
|
function getGlobalTabularRepositories() {
|
|
1120
1109
|
return globalServiceRegistry.get(TABULAR_REPOSITORIES);
|
|
1121
1110
|
}
|
|
@@ -1135,6 +1124,14 @@ function resolveRepositoryFromRegistry(id, format, registry) {
|
|
|
1135
1124
|
return repo;
|
|
1136
1125
|
}
|
|
1137
1126
|
registerInputResolver("storage:tabular", resolveRepositoryFromRegistry);
|
|
1127
|
+
registerInputCompactor("storage:tabular", (value, _format, registry) => {
|
|
1128
|
+
const repos = registry.has(TABULAR_REPOSITORIES) ? registry.get(TABULAR_REPOSITORIES) : getGlobalTabularRepositories();
|
|
1129
|
+
for (const [id, repo] of repos) {
|
|
1130
|
+
if (repo === value)
|
|
1131
|
+
return id;
|
|
1132
|
+
}
|
|
1133
|
+
return;
|
|
1134
|
+
});
|
|
1138
1135
|
// src/util/traced.ts
|
|
1139
1136
|
import { getTelemetryProvider, SpanStatusCode } from "@workglow/util";
|
|
1140
1137
|
async function traced(spanName, storageName, fn) {
|
|
@@ -2234,6 +2231,54 @@ class EncryptedKvCredentialStore {
|
|
|
2234
2231
|
await this.kv.deleteAll();
|
|
2235
2232
|
}
|
|
2236
2233
|
}
|
|
2234
|
+
// src/credentials/LazyEncryptedCredentialStore.ts
|
|
2235
|
+
class LazyEncryptedCredentialStore {
|
|
2236
|
+
kv;
|
|
2237
|
+
inner;
|
|
2238
|
+
constructor(kv) {
|
|
2239
|
+
this.kv = kv;
|
|
2240
|
+
}
|
|
2241
|
+
get isUnlocked() {
|
|
2242
|
+
return this.inner !== undefined;
|
|
2243
|
+
}
|
|
2244
|
+
unlock(passphrase) {
|
|
2245
|
+
this.inner = new EncryptedKvCredentialStore(this.kv, passphrase);
|
|
2246
|
+
}
|
|
2247
|
+
lock() {
|
|
2248
|
+
this.inner = undefined;
|
|
2249
|
+
}
|
|
2250
|
+
async get(key) {
|
|
2251
|
+
if (!this.inner)
|
|
2252
|
+
return;
|
|
2253
|
+
return this.inner.get(key);
|
|
2254
|
+
}
|
|
2255
|
+
async put(key, value, options) {
|
|
2256
|
+
if (!this.inner) {
|
|
2257
|
+
throw new Error("Credential store is locked. Call unlock() before storing credentials.");
|
|
2258
|
+
}
|
|
2259
|
+
return this.inner.put(key, value, options);
|
|
2260
|
+
}
|
|
2261
|
+
async delete(key) {
|
|
2262
|
+
if (!this.inner)
|
|
2263
|
+
return false;
|
|
2264
|
+
return this.inner.delete(key);
|
|
2265
|
+
}
|
|
2266
|
+
async has(key) {
|
|
2267
|
+
if (!this.inner)
|
|
2268
|
+
return false;
|
|
2269
|
+
return this.inner.has(key);
|
|
2270
|
+
}
|
|
2271
|
+
async keys() {
|
|
2272
|
+
if (!this.inner)
|
|
2273
|
+
return [];
|
|
2274
|
+
return this.inner.keys();
|
|
2275
|
+
}
|
|
2276
|
+
async deleteAll() {
|
|
2277
|
+
if (!this.inner)
|
|
2278
|
+
return;
|
|
2279
|
+
return this.inner.deleteAll();
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2237
2282
|
// src/tabular/IndexedDbTabularStorage.ts
|
|
2238
2283
|
import { createServiceToken as createServiceToken12, makeFingerprint as makeFingerprint5, uuid4 as uuid43 } from "@workglow/util";
|
|
2239
2284
|
|
|
@@ -3014,6 +3059,8 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
|
|
|
3014
3059
|
// src/tabular/SharedInMemoryTabularStorage.ts
|
|
3015
3060
|
import { createServiceToken as createServiceToken13 } from "@workglow/util";
|
|
3016
3061
|
var SHARED_IN_MEMORY_TABULAR_REPOSITORY = createServiceToken13("storage.tabularRepository.sharedInMemory");
|
|
3062
|
+
var SYNC_TIMEOUT = 1000;
|
|
3063
|
+
var MAX_PENDING_MESSAGES = 1000;
|
|
3017
3064
|
|
|
3018
3065
|
class SharedInMemoryTabularStorage extends BaseTabularStorage {
|
|
3019
3066
|
channel = null;
|
|
@@ -3021,6 +3068,7 @@ class SharedInMemoryTabularStorage extends BaseTabularStorage {
|
|
|
3021
3068
|
inMemoryRepo;
|
|
3022
3069
|
isInitialized = false;
|
|
3023
3070
|
syncInProgress = false;
|
|
3071
|
+
pendingMessages = [];
|
|
3024
3072
|
constructor(channelName = "tabular_store", schema, primaryKeyNames, indexes = [], clientProvidedKeys = "if-missing") {
|
|
3025
3073
|
super(schema, primaryKeyNames, indexes, clientProvidedKeys);
|
|
3026
3074
|
this.channelName = channelName;
|
|
@@ -3065,6 +3113,9 @@ class SharedInMemoryTabularStorage extends BaseTabularStorage {
|
|
|
3065
3113
|
}
|
|
3066
3114
|
async handleBroadcastMessage(message) {
|
|
3067
3115
|
if (this.syncInProgress && message.type !== "SYNC_RESPONSE") {
|
|
3116
|
+
if (this.pendingMessages.length < MAX_PENDING_MESSAGES) {
|
|
3117
|
+
this.pendingMessages.push(message);
|
|
3118
|
+
}
|
|
3068
3119
|
return;
|
|
3069
3120
|
}
|
|
3070
3121
|
switch (message.type) {
|
|
@@ -3082,6 +3133,7 @@ class SharedInMemoryTabularStorage extends BaseTabularStorage {
|
|
|
3082
3133
|
await this.copyDataFromArray(message.data);
|
|
3083
3134
|
}
|
|
3084
3135
|
this.syncInProgress = false;
|
|
3136
|
+
await this.drainPendingMessages();
|
|
3085
3137
|
break;
|
|
3086
3138
|
case "PUT":
|
|
3087
3139
|
await this.inMemoryRepo.put(message.entity);
|
|
@@ -3100,14 +3152,31 @@ class SharedInMemoryTabularStorage extends BaseTabularStorage {
|
|
|
3100
3152
|
break;
|
|
3101
3153
|
}
|
|
3102
3154
|
}
|
|
3155
|
+
async drainPendingMessages() {
|
|
3156
|
+
while (!this.syncInProgress && this.pendingMessages.length > 0) {
|
|
3157
|
+
const messages = this.pendingMessages;
|
|
3158
|
+
this.pendingMessages = [];
|
|
3159
|
+
for (const message of messages) {
|
|
3160
|
+
await this.handleBroadcastMessage(message);
|
|
3161
|
+
if (this.syncInProgress) {
|
|
3162
|
+
break;
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3103
3167
|
syncFromOtherTabs() {
|
|
3104
3168
|
if (!this.channel)
|
|
3105
3169
|
return;
|
|
3106
3170
|
this.syncInProgress = true;
|
|
3107
3171
|
this.channel.postMessage({ type: "SYNC_REQUEST" });
|
|
3108
3172
|
setTimeout(() => {
|
|
3109
|
-
this.syncInProgress
|
|
3110
|
-
|
|
3173
|
+
if (this.syncInProgress) {
|
|
3174
|
+
this.syncInProgress = false;
|
|
3175
|
+
this.drainPendingMessages().catch((error) => {
|
|
3176
|
+
console.error("Failed to drain pending messages after sync timeout", error);
|
|
3177
|
+
});
|
|
3178
|
+
}
|
|
3179
|
+
}, SYNC_TIMEOUT);
|
|
3111
3180
|
}
|
|
3112
3181
|
async copyDataFromArray(entities) {
|
|
3113
3182
|
if (entities.length === 0)
|
|
@@ -3128,12 +3197,12 @@ class SharedInMemoryTabularStorage extends BaseTabularStorage {
|
|
|
3128
3197
|
}
|
|
3129
3198
|
async put(value) {
|
|
3130
3199
|
const result = await this.inMemoryRepo.put(value);
|
|
3131
|
-
this.broadcast({ type: "PUT", entity:
|
|
3200
|
+
this.broadcast({ type: "PUT", entity: result });
|
|
3132
3201
|
return result;
|
|
3133
3202
|
}
|
|
3134
3203
|
async putBulk(values) {
|
|
3135
3204
|
const result = await this.inMemoryRepo.putBulk(values);
|
|
3136
|
-
this.broadcast({ type: "PUT_BULK", entities:
|
|
3205
|
+
this.broadcast({ type: "PUT_BULK", entities: result });
|
|
3137
3206
|
return result;
|
|
3138
3207
|
}
|
|
3139
3208
|
async get(key) {
|
|
@@ -5472,6 +5541,7 @@ export {
|
|
|
5472
5541
|
PollingSubscriptionManager,
|
|
5473
5542
|
MEMORY_TABULAR_REPOSITORY,
|
|
5474
5543
|
MEMORY_KV_REPOSITORY,
|
|
5544
|
+
LazyEncryptedCredentialStore,
|
|
5475
5545
|
KvViaTabularStorage,
|
|
5476
5546
|
KvStorage,
|
|
5477
5547
|
KV_REPOSITORY,
|
|
@@ -5504,4 +5574,4 @@ export {
|
|
|
5504
5574
|
BaseTabularStorage
|
|
5505
5575
|
};
|
|
5506
5576
|
|
|
5507
|
-
//# debugId=
|
|
5577
|
+
//# debugId=5DBA415CCD0F79AA64756E2164756E21
|