@workglow/storage 0.1.2 → 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 +80 -19
- package/dist/browser.js.map +11 -10
- package/dist/bun.js +52 -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/node.js +52 -15
- package/dist/node.js.map +14 -13
- package/dist/queue/InMemoryQueueStorage.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/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/StorageError.d.ts +0 -2
- package/dist/tabular/StorageError.d.ts.map +1 -1
- package/dist/tabular/TabularStorageRegistry.d.ts.map +1 -1
- package/dist/vector/InMemoryVectorStorage.d.ts +1 -1
- package/dist/vector/InMemoryVectorStorage.d.ts.map +1 -1
- package/dist/vector/IndexedDbVectorStorage.d.ts +1 -1
- package/dist/vector/IndexedDbVectorStorage.d.ts.map +1 -1
- package/dist/vector/PostgresVectorStorage.d.ts +1 -1
- package/dist/vector/PostgresVectorStorage.d.ts.map +1 -1
- package/dist/vector/SqliteAiVectorStorage.d.ts +1 -1
- package/dist/vector/SqliteAiVectorStorage.d.ts.map +1 -1
- package/dist/vector/SqliteVectorStorage.d.ts +1 -1
- 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
|
}
|
|
@@ -1114,9 +1104,7 @@ import {
|
|
|
1114
1104
|
registerInputResolver
|
|
1115
1105
|
} from "@workglow/util";
|
|
1116
1106
|
var TABULAR_REPOSITORIES = createServiceToken5("storage.tabular.repositories");
|
|
1117
|
-
|
|
1118
|
-
globalServiceRegistry.register(TABULAR_REPOSITORIES, () => new Map, true);
|
|
1119
|
-
}
|
|
1107
|
+
globalServiceRegistry.registerIfAbsent(TABULAR_REPOSITORIES, () => new Map, true);
|
|
1120
1108
|
function getGlobalTabularRepositories() {
|
|
1121
1109
|
return globalServiceRegistry.get(TABULAR_REPOSITORIES);
|
|
1122
1110
|
}
|
|
@@ -2243,6 +2231,54 @@ class EncryptedKvCredentialStore {
|
|
|
2243
2231
|
await this.kv.deleteAll();
|
|
2244
2232
|
}
|
|
2245
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
|
+
}
|
|
2246
2282
|
// src/tabular/IndexedDbTabularStorage.ts
|
|
2247
2283
|
import { createServiceToken as createServiceToken12, makeFingerprint as makeFingerprint5, uuid4 as uuid43 } from "@workglow/util";
|
|
2248
2284
|
|
|
@@ -3023,6 +3059,8 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
|
|
|
3023
3059
|
// src/tabular/SharedInMemoryTabularStorage.ts
|
|
3024
3060
|
import { createServiceToken as createServiceToken13 } from "@workglow/util";
|
|
3025
3061
|
var SHARED_IN_MEMORY_TABULAR_REPOSITORY = createServiceToken13("storage.tabularRepository.sharedInMemory");
|
|
3062
|
+
var SYNC_TIMEOUT = 1000;
|
|
3063
|
+
var MAX_PENDING_MESSAGES = 1000;
|
|
3026
3064
|
|
|
3027
3065
|
class SharedInMemoryTabularStorage extends BaseTabularStorage {
|
|
3028
3066
|
channel = null;
|
|
@@ -3030,6 +3068,7 @@ class SharedInMemoryTabularStorage extends BaseTabularStorage {
|
|
|
3030
3068
|
inMemoryRepo;
|
|
3031
3069
|
isInitialized = false;
|
|
3032
3070
|
syncInProgress = false;
|
|
3071
|
+
pendingMessages = [];
|
|
3033
3072
|
constructor(channelName = "tabular_store", schema, primaryKeyNames, indexes = [], clientProvidedKeys = "if-missing") {
|
|
3034
3073
|
super(schema, primaryKeyNames, indexes, clientProvidedKeys);
|
|
3035
3074
|
this.channelName = channelName;
|
|
@@ -3074,6 +3113,9 @@ class SharedInMemoryTabularStorage extends BaseTabularStorage {
|
|
|
3074
3113
|
}
|
|
3075
3114
|
async handleBroadcastMessage(message) {
|
|
3076
3115
|
if (this.syncInProgress && message.type !== "SYNC_RESPONSE") {
|
|
3116
|
+
if (this.pendingMessages.length < MAX_PENDING_MESSAGES) {
|
|
3117
|
+
this.pendingMessages.push(message);
|
|
3118
|
+
}
|
|
3077
3119
|
return;
|
|
3078
3120
|
}
|
|
3079
3121
|
switch (message.type) {
|
|
@@ -3091,6 +3133,7 @@ class SharedInMemoryTabularStorage extends BaseTabularStorage {
|
|
|
3091
3133
|
await this.copyDataFromArray(message.data);
|
|
3092
3134
|
}
|
|
3093
3135
|
this.syncInProgress = false;
|
|
3136
|
+
await this.drainPendingMessages();
|
|
3094
3137
|
break;
|
|
3095
3138
|
case "PUT":
|
|
3096
3139
|
await this.inMemoryRepo.put(message.entity);
|
|
@@ -3109,14 +3152,31 @@ class SharedInMemoryTabularStorage extends BaseTabularStorage {
|
|
|
3109
3152
|
break;
|
|
3110
3153
|
}
|
|
3111
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
|
+
}
|
|
3112
3167
|
syncFromOtherTabs() {
|
|
3113
3168
|
if (!this.channel)
|
|
3114
3169
|
return;
|
|
3115
3170
|
this.syncInProgress = true;
|
|
3116
3171
|
this.channel.postMessage({ type: "SYNC_REQUEST" });
|
|
3117
3172
|
setTimeout(() => {
|
|
3118
|
-
this.syncInProgress
|
|
3119
|
-
|
|
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);
|
|
3120
3180
|
}
|
|
3121
3181
|
async copyDataFromArray(entities) {
|
|
3122
3182
|
if (entities.length === 0)
|
|
@@ -3137,12 +3197,12 @@ class SharedInMemoryTabularStorage extends BaseTabularStorage {
|
|
|
3137
3197
|
}
|
|
3138
3198
|
async put(value) {
|
|
3139
3199
|
const result = await this.inMemoryRepo.put(value);
|
|
3140
|
-
this.broadcast({ type: "PUT", entity:
|
|
3200
|
+
this.broadcast({ type: "PUT", entity: result });
|
|
3141
3201
|
return result;
|
|
3142
3202
|
}
|
|
3143
3203
|
async putBulk(values) {
|
|
3144
3204
|
const result = await this.inMemoryRepo.putBulk(values);
|
|
3145
|
-
this.broadcast({ type: "PUT_BULK", entities:
|
|
3205
|
+
this.broadcast({ type: "PUT_BULK", entities: result });
|
|
3146
3206
|
return result;
|
|
3147
3207
|
}
|
|
3148
3208
|
async get(key) {
|
|
@@ -5481,6 +5541,7 @@ export {
|
|
|
5481
5541
|
PollingSubscriptionManager,
|
|
5482
5542
|
MEMORY_TABULAR_REPOSITORY,
|
|
5483
5543
|
MEMORY_KV_REPOSITORY,
|
|
5544
|
+
LazyEncryptedCredentialStore,
|
|
5484
5545
|
KvViaTabularStorage,
|
|
5485
5546
|
KvStorage,
|
|
5486
5547
|
KV_REPOSITORY,
|
|
@@ -5513,4 +5574,4 @@ export {
|
|
|
5513
5574
|
BaseTabularStorage
|
|
5514
5575
|
};
|
|
5515
5576
|
|
|
5516
|
-
//# debugId=
|
|
5577
|
+
//# debugId=5DBA415CCD0F79AA64756E2164756E21
|