@workglow/storage 0.0.101 → 0.0.103
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/dist/browser.js +161 -34
- package/dist/browser.js.map +15 -14
- package/dist/bun.js +207 -69
- package/dist/bun.js.map +19 -18
- package/dist/common-server.d.ts +1 -0
- package/dist/common-server.d.ts.map +1 -1
- package/dist/kv/InMemoryKvStorage.d.ts.map +1 -1
- package/dist/kv/KvStorage.d.ts.map +1 -1
- package/dist/node.js +207 -69
- package/dist/node.js.map +19 -18
- package/dist/queue/InMemoryQueueStorage.d.ts.map +1 -1
- package/dist/tabular/BaseSqlTabularStorage.d.ts.map +1 -1
- package/dist/tabular/BaseTabularStorage.d.ts.map +1 -1
- package/dist/tabular/HuggingFaceTabularStorage.d.ts.map +1 -1
- package/dist/tabular/PostgresTabularStorage.d.ts.map +1 -1
- package/dist/tabular/SqliteTabularStorage.d.ts.map +1 -1
- package/dist/tabular/SupabaseTabularStorage.d.ts.map +1 -1
- package/dist/util/IndexedDbTable.d.ts.map +1 -1
- package/dist/vector/IndexedDbVectorStorage.d.ts +55 -0
- package/dist/vector/IndexedDbVectorStorage.d.ts.map +1 -0
- package/dist/vector/PostgresVectorStorage.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/common-server.d.ts
CHANGED
|
@@ -25,5 +25,6 @@ export * from "./kv/IndexedDbKvStorage";
|
|
|
25
25
|
export * from "./queue-limiter/IndexedDbRateLimiterStorage";
|
|
26
26
|
export * from "./queue/IndexedDbQueueStorage";
|
|
27
27
|
export * from "./tabular/IndexedDbTabularStorage";
|
|
28
|
+
export * from "./vector/IndexedDbVectorStorage";
|
|
28
29
|
export * from "./util/IndexedDbTable";
|
|
29
30
|
//# sourceMappingURL=common-server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-server.d.ts","sourceRoot":"","sources":["../src/common-server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,c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cAAc,6CAA6C,CAAC;AAC5D,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InMemoryKvStorage.d.ts","sourceRoot":"","sources":["../../src/kv/InMemoryKvStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAsB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,eAAO,MAAM,oBAAoB,qEAEhC,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,iBAAkB,SAAQ,mBAAmB;IACjD,iBAAiB,EAAE,sBAAsB,CAC9C,OAAO,qBAAqB,EAC5B,OAAO,kBAAkB,CAC1B,CAAC;IAEF;;OAEG;gBACS,SAAS,GAAE,UAA+B,EAAE,WAAW,GAAE,UAAe;
|
|
1
|
+
{"version":3,"file":"InMemoryKvStorage.d.ts","sourceRoot":"","sources":["../../src/kv/InMemoryKvStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAsB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,eAAO,MAAM,oBAAoB,qEAEhC,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,iBAAkB,SAAQ,mBAAmB;IACjD,iBAAiB,EAAE,sBAAsB,CAC9C,OAAO,qBAAqB,EAC5B,OAAO,kBAAkB,CAC1B,CAAC;IAEF;;OAEG;gBACS,SAAS,GAAE,UAA+B,EAAE,WAAW,GAAE,UAAe;CAIrF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KvStorage.d.ts","sourceRoot":"","sources":["../../src/kv/KvStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAsB,YAAY,EAAE,UAAU,EAAmB,MAAM,gBAAgB,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,
|
|
1
|
+
{"version":3,"file":"KvStorage.d.ts","sourceRoot":"","sources":["../../src/kv/KvStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAsB,YAAY,EAAE,UAAU,EAAmB,MAAM,gBAAgB,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EACL,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,aAAa,kEAAwE,CAAC;AAEnG;;;;;;;GAOG;AACH,8BAAsB,SAAS,CAC7B,GAAG,SAAS,MAAM,GAAG,MAAM,EAC3B,KAAK,SAAS,GAAG,GAAG,GAAG,EACvB,QAAQ,GAAG;IAAE,GAAG,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CACrC,YAAW,UAAU,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC;IAQlC,SAAS,EAAE,UAAU;IACrB,WAAW,EAAE,UAAU;IARhC,0CAA0C;IAC1C,SAAS,CAAC,MAAM,uDAA8D;IAE9E;;OAEG;gBAEM,SAAS,GAAE,UAA+B,EAC1C,WAAW,GAAE,UAAe;IAGrC;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK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,SAAS,WAAW,EAC5B,IAAI,EAAE,KAAK,EACX,GAAG,IAAI,EAAE,iBAAiB,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC;IAKzD;;;;OAIG;IACH,MAAM,CAAC,KAAK,SAAS,WAAW,EAC9B,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,iBAAiB,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;CAG3D"}
|
package/dist/node.js
CHANGED
|
@@ -189,11 +189,12 @@ class BaseTabularStorage {
|
|
|
189
189
|
const valueNames = this.valueColumns();
|
|
190
190
|
const value = {};
|
|
191
191
|
const key = {};
|
|
192
|
+
const objRecord = obj;
|
|
192
193
|
for (const k of primaryKeyNames) {
|
|
193
|
-
key[k] =
|
|
194
|
+
key[k] = objRecord[k];
|
|
194
195
|
}
|
|
195
196
|
for (const k of valueNames) {
|
|
196
|
-
value[k] =
|
|
197
|
+
value[k] = objRecord[k];
|
|
197
198
|
}
|
|
198
199
|
return { value, key };
|
|
199
200
|
}
|
|
@@ -1030,7 +1031,14 @@ class InMemoryKvStorage extends KvViaTabularStorage {
|
|
|
1030
1031
|
}
|
|
1031
1032
|
}
|
|
1032
1033
|
// src/queue/InMemoryQueueStorage.ts
|
|
1033
|
-
import {
|
|
1034
|
+
import {
|
|
1035
|
+
createServiceToken as createServiceToken9,
|
|
1036
|
+
EventEmitter as EventEmitter3,
|
|
1037
|
+
getLogger,
|
|
1038
|
+
makeFingerprint as makeFingerprint4,
|
|
1039
|
+
sleep,
|
|
1040
|
+
uuid4 as uuid42
|
|
1041
|
+
} from "@workglow/util";
|
|
1034
1042
|
|
|
1035
1043
|
// src/queue/IQueueStorage.ts
|
|
1036
1044
|
import { createServiceToken as createServiceToken8 } from "@workglow/util";
|
|
@@ -1124,11 +1132,23 @@ class InMemoryQueueStorage {
|
|
|
1124
1132
|
await sleep(0);
|
|
1125
1133
|
const job = this.jobQueue.find((j) => j.id === id && this.matchesPrefixes(j));
|
|
1126
1134
|
if (!job) {
|
|
1127
|
-
|
|
1135
|
+
const jobWithAnyPrefix = this.jobQueue.find((j) => j.id === id);
|
|
1136
|
+
getLogger().warn("Job not found for progress update", {
|
|
1137
|
+
id,
|
|
1138
|
+
reason: jobWithAnyPrefix ? "prefix_mismatch" : "missing",
|
|
1139
|
+
existingStatus: jobWithAnyPrefix?.status,
|
|
1140
|
+
queueName: this.queueName,
|
|
1141
|
+
prefixValues: this.prefixValues
|
|
1142
|
+
});
|
|
1128
1143
|
return;
|
|
1129
1144
|
}
|
|
1130
1145
|
if (job.status === JobStatus.COMPLETED || job.status === JobStatus.FAILED) {
|
|
1131
|
-
|
|
1146
|
+
getLogger().warn("Job already completed or failed for progress update", {
|
|
1147
|
+
id,
|
|
1148
|
+
status: job.status,
|
|
1149
|
+
completedAt: job.completed_at,
|
|
1150
|
+
error: job.error
|
|
1151
|
+
});
|
|
1132
1152
|
return;
|
|
1133
1153
|
}
|
|
1134
1154
|
const oldJob = { ...job };
|
|
@@ -2002,17 +2022,16 @@ class BaseSqlTabularStorage extends BaseTabularStorage {
|
|
|
2002
2022
|
return value;
|
|
2003
2023
|
}
|
|
2004
2024
|
if (actualType.contentEncoding === "blob") {
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
return v;
|
|
2025
|
+
if (value instanceof Uint8Array) {
|
|
2026
|
+
return value;
|
|
2008
2027
|
}
|
|
2009
|
-
if (typeof Buffer !== "undefined" &&
|
|
2010
|
-
return new Uint8Array(
|
|
2028
|
+
if (typeof Buffer !== "undefined" && value instanceof Buffer) {
|
|
2029
|
+
return new Uint8Array(value);
|
|
2011
2030
|
}
|
|
2012
|
-
if (Array.isArray(
|
|
2013
|
-
return new Uint8Array(
|
|
2031
|
+
if (Array.isArray(value)) {
|
|
2032
|
+
return new Uint8Array(value);
|
|
2014
2033
|
}
|
|
2015
|
-
return
|
|
2034
|
+
return value;
|
|
2016
2035
|
} else if (value instanceof Date) {
|
|
2017
2036
|
return value.toISOString();
|
|
2018
2037
|
} else {
|
|
@@ -2032,14 +2051,13 @@ class BaseSqlTabularStorage extends BaseTabularStorage {
|
|
|
2032
2051
|
return value;
|
|
2033
2052
|
}
|
|
2034
2053
|
if (actualType.contentEncoding === "blob") {
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
return new Uint8Array(v);
|
|
2054
|
+
if (typeof Buffer !== "undefined" && value instanceof Buffer) {
|
|
2055
|
+
return new Uint8Array(value);
|
|
2038
2056
|
}
|
|
2039
|
-
if (
|
|
2040
|
-
return
|
|
2057
|
+
if (value instanceof Uint8Array) {
|
|
2058
|
+
return value;
|
|
2041
2059
|
}
|
|
2042
|
-
return
|
|
2060
|
+
return value;
|
|
2043
2061
|
} else {
|
|
2044
2062
|
return value;
|
|
2045
2063
|
}
|
|
@@ -2282,11 +2300,10 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
|
|
|
2282
2300
|
}
|
|
2283
2301
|
}
|
|
2284
2302
|
if (typeof actualType !== "boolean" && (actualType.type === "number" || actualType.type === "integer")) {
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
const parsed = Number(v);
|
|
2303
|
+
if (typeof value === "number")
|
|
2304
|
+
return value;
|
|
2305
|
+
if (typeof value === "string") {
|
|
2306
|
+
const parsed = Number(value);
|
|
2290
2307
|
if (!isNaN(parsed))
|
|
2291
2308
|
return parsed;
|
|
2292
2309
|
}
|
|
@@ -2349,10 +2366,11 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
|
|
|
2349
2366
|
const paramsToInsert = [];
|
|
2350
2367
|
let paramIndex = 1;
|
|
2351
2368
|
const pkColumns = this.primaryKeyColumns();
|
|
2369
|
+
const entityRecord = entity;
|
|
2352
2370
|
for (const col of pkColumns) {
|
|
2353
2371
|
const colStr = String(col);
|
|
2354
2372
|
if (this.isAutoGeneratedKey(colStr)) {
|
|
2355
|
-
const clientProvidedValue =
|
|
2373
|
+
const clientProvidedValue = entityRecord[colStr];
|
|
2356
2374
|
const hasClientValue = clientProvidedValue !== undefined && clientProvidedValue !== null;
|
|
2357
2375
|
let shouldUseClientValue = false;
|
|
2358
2376
|
if (this.clientProvidedKeys === "never") {
|
|
@@ -2372,14 +2390,14 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
|
|
|
2372
2390
|
continue;
|
|
2373
2391
|
}
|
|
2374
2392
|
columnsToInsert.push(colStr);
|
|
2375
|
-
const value =
|
|
2393
|
+
const value = entityRecord[colStr];
|
|
2376
2394
|
paramsToInsert.push(this.jsToSqlValue(colStr, value));
|
|
2377
2395
|
}
|
|
2378
2396
|
const valueColumns = this.valueColumns();
|
|
2379
2397
|
for (const col of valueColumns) {
|
|
2380
2398
|
const colStr = String(col);
|
|
2381
2399
|
columnsToInsert.push(colStr);
|
|
2382
|
-
const value =
|
|
2400
|
+
const value = entityRecord[colStr];
|
|
2383
2401
|
paramsToInsert.push(this.jsToSqlValue(colStr, value));
|
|
2384
2402
|
}
|
|
2385
2403
|
const columnList = columnsToInsert.map((c) => `"${c}"`).join(", ");
|
|
@@ -2401,8 +2419,9 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
|
|
|
2401
2419
|
const params = paramsToInsert;
|
|
2402
2420
|
const result = await db.query(sql, params);
|
|
2403
2421
|
const updatedEntity = result.rows[0];
|
|
2422
|
+
const updatedRecord = updatedEntity;
|
|
2404
2423
|
for (const key in this.schema.properties) {
|
|
2405
|
-
|
|
2424
|
+
updatedRecord[key] = this.sqlToJsValue(key, updatedRecord[key]);
|
|
2406
2425
|
}
|
|
2407
2426
|
this.events.emit("put", updatedEntity);
|
|
2408
2427
|
return updatedEntity;
|
|
@@ -2421,8 +2440,9 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
|
|
|
2421
2440
|
let val;
|
|
2422
2441
|
if (result.rows.length > 0) {
|
|
2423
2442
|
val = result.rows[0];
|
|
2443
|
+
const valRecord = val;
|
|
2424
2444
|
for (const key2 in this.schema.properties) {
|
|
2425
|
-
|
|
2445
|
+
valRecord[key2] = this.sqlToJsValue(key2, valRecord[key2]);
|
|
2426
2446
|
}
|
|
2427
2447
|
} else {
|
|
2428
2448
|
val = undefined;
|
|
@@ -2451,8 +2471,9 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
|
|
|
2451
2471
|
const result = await db.query(sql, whereClauseValues);
|
|
2452
2472
|
if (result.rows.length > 0) {
|
|
2453
2473
|
for (const row of result.rows) {
|
|
2474
|
+
const record = row;
|
|
2454
2475
|
for (const k in this.schema.properties) {
|
|
2455
|
-
|
|
2476
|
+
record[k] = this.sqlToJsValue(k, record[k]);
|
|
2456
2477
|
}
|
|
2457
2478
|
}
|
|
2458
2479
|
this.events.emit("search", key, result.rows);
|
|
@@ -2476,8 +2497,9 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
|
|
|
2476
2497
|
const result = await db.query(sql);
|
|
2477
2498
|
if (result.rows.length > 0) {
|
|
2478
2499
|
for (const row of result.rows) {
|
|
2500
|
+
const record = row;
|
|
2479
2501
|
for (const key in this.schema.properties) {
|
|
2480
|
-
|
|
2502
|
+
record[key] = this.sqlToJsValue(key, record[key]);
|
|
2481
2503
|
}
|
|
2482
2504
|
}
|
|
2483
2505
|
return result.rows;
|
|
@@ -2502,8 +2524,9 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
|
|
|
2502
2524
|
return;
|
|
2503
2525
|
}
|
|
2504
2526
|
for (const row of result.rows) {
|
|
2527
|
+
const record = row;
|
|
2505
2528
|
for (const key in this.schema.properties) {
|
|
2506
|
-
|
|
2529
|
+
record[key] = this.sqlToJsValue(key, record[key]);
|
|
2507
2530
|
}
|
|
2508
2531
|
}
|
|
2509
2532
|
return result.rows;
|
|
@@ -2643,13 +2666,12 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
|
|
|
2643
2666
|
const isArray = typeDef === true || typeof actualType !== "boolean" && actualType.type === "array";
|
|
2644
2667
|
const isBoolean = typeDef === true || typeof actualType !== "boolean" && actualType.type === "boolean";
|
|
2645
2668
|
if (isBoolean) {
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
return v === "1" || v.toLowerCase() === "true" ? 1 : 0;
|
|
2669
|
+
if (typeof value === "boolean")
|
|
2670
|
+
return value ? 1 : 0;
|
|
2671
|
+
if (typeof value === "number")
|
|
2672
|
+
return value ? 1 : 0;
|
|
2673
|
+
if (typeof value === "string")
|
|
2674
|
+
return value === "1" || value.toLowerCase() === "true" ? 1 : 0;
|
|
2653
2675
|
}
|
|
2654
2676
|
if ((isObject || isArray) && value !== null && typeof value === "object") {
|
|
2655
2677
|
if (!(value instanceof Date) && !(value instanceof Uint8Array) && (typeof Buffer === "undefined" || !(value instanceof Buffer))) {
|
|
@@ -2679,13 +2701,12 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
|
|
|
2679
2701
|
const isArray = typeDef === true || typeof actualType !== "boolean" && actualType.type === "array";
|
|
2680
2702
|
const isBoolean = typeDef === true || typeof actualType !== "boolean" && actualType.type === "boolean";
|
|
2681
2703
|
if (isBoolean) {
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
return v === "1" || v.toLowerCase() === "true" ? true : false;
|
|
2704
|
+
if (typeof value === "boolean")
|
|
2705
|
+
return value;
|
|
2706
|
+
if (typeof value === "number")
|
|
2707
|
+
return value !== 0 ? true : false;
|
|
2708
|
+
if (typeof value === "string")
|
|
2709
|
+
return value === "1" || value.toLowerCase() === "true" ? true : false;
|
|
2689
2710
|
}
|
|
2690
2711
|
if (isArray || isObject) {
|
|
2691
2712
|
if (typeof value === "string") {
|
|
@@ -2743,7 +2764,8 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
|
|
|
2743
2764
|
let entityToInsert = entity;
|
|
2744
2765
|
if (this.hasAutoGeneratedKey() && this.autoGeneratedKeyName) {
|
|
2745
2766
|
const keyName = String(this.autoGeneratedKeyName);
|
|
2746
|
-
const
|
|
2767
|
+
const entityRecord = entity;
|
|
2768
|
+
const clientProvidedValue = entityRecord[keyName];
|
|
2747
2769
|
const hasClientValue = clientProvidedValue !== undefined && clientProvidedValue !== null;
|
|
2748
2770
|
let shouldUseClientValue = false;
|
|
2749
2771
|
if (this.clientProvidedKeys === "never") {
|
|
@@ -2769,7 +2791,8 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
|
|
|
2769
2791
|
for (const col of pkColumns) {
|
|
2770
2792
|
const colStr = String(col);
|
|
2771
2793
|
if (this.isAutoGeneratedKey(colStr) && this.autoGeneratedKeyStrategy === "autoincrement" && this.clientProvidedKeys !== "always") {
|
|
2772
|
-
const
|
|
2794
|
+
const insertRecord2 = entityToInsert;
|
|
2795
|
+
const clientProvidedValue = insertRecord2[colStr];
|
|
2773
2796
|
const hasClientValue = clientProvidedValue !== undefined && clientProvidedValue !== null;
|
|
2774
2797
|
if (this.clientProvidedKeys === "if-missing" && hasClientValue) {
|
|
2775
2798
|
columnsToInsert.push(colStr);
|
|
@@ -2782,10 +2805,11 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
|
|
|
2782
2805
|
paramsToInsert.push(this.jsToSqlValue(colStr, value));
|
|
2783
2806
|
}
|
|
2784
2807
|
const valueColumns = this.valueColumns();
|
|
2808
|
+
const insertRecord = entityToInsert;
|
|
2785
2809
|
for (const col of valueColumns) {
|
|
2786
2810
|
const colStr = String(col);
|
|
2787
2811
|
columnsToInsert.push(colStr);
|
|
2788
|
-
const value =
|
|
2812
|
+
const value = insertRecord[colStr];
|
|
2789
2813
|
paramsToInsert.push(this.jsToSqlValue(colStr, value));
|
|
2790
2814
|
}
|
|
2791
2815
|
const columnList = columnsToInsert.map((c) => `\`${c}\``).join(", ");
|
|
@@ -2842,8 +2866,9 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
|
|
|
2842
2866
|
throw new Error(`Invalid SQLite params detected at indices: ${invalidParams.map((p) => p.index).join(", ")}`);
|
|
2843
2867
|
}
|
|
2844
2868
|
const updatedEntity = stmt.get(...params);
|
|
2869
|
+
const updatedRecord = updatedEntity;
|
|
2845
2870
|
for (const k in this.schema.properties) {
|
|
2846
|
-
|
|
2871
|
+
updatedRecord[k] = this.sqlToJsValue(k, updatedRecord[k]);
|
|
2847
2872
|
}
|
|
2848
2873
|
this.events.emit("put", updatedEntity);
|
|
2849
2874
|
return updatedEntity;
|
|
@@ -2863,8 +2888,9 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
|
|
|
2863
2888
|
const params = this.getPrimaryKeyAsOrderedArray(key);
|
|
2864
2889
|
const value = stmt.get(...params);
|
|
2865
2890
|
if (value) {
|
|
2891
|
+
const row = value;
|
|
2866
2892
|
for (const k in this.schema.properties) {
|
|
2867
|
-
|
|
2893
|
+
row[k] = this.sqlToJsValue(k, row[k]);
|
|
2868
2894
|
}
|
|
2869
2895
|
this.events.emit("get", key, value);
|
|
2870
2896
|
return value;
|
|
@@ -2895,8 +2921,9 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
|
|
|
2895
2921
|
const result = stmt.all(...whereClauseValues);
|
|
2896
2922
|
if (result.length > 0) {
|
|
2897
2923
|
for (const row of result) {
|
|
2924
|
+
const record = row;
|
|
2898
2925
|
for (const k in this.schema.properties) {
|
|
2899
|
-
|
|
2926
|
+
record[k] = this.sqlToJsValue(k, record[k]);
|
|
2900
2927
|
}
|
|
2901
2928
|
}
|
|
2902
2929
|
this.events.emit("search", key, result);
|
|
@@ -2922,8 +2949,9 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
|
|
|
2922
2949
|
if (!value.length)
|
|
2923
2950
|
return;
|
|
2924
2951
|
for (const row of value) {
|
|
2952
|
+
const record = row;
|
|
2925
2953
|
for (const k in this.schema.properties) {
|
|
2926
|
-
|
|
2954
|
+
record[k] = this.sqlToJsValue(k, record[k]);
|
|
2927
2955
|
}
|
|
2928
2956
|
}
|
|
2929
2957
|
return value;
|
|
@@ -2951,8 +2979,9 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
|
|
|
2951
2979
|
return;
|
|
2952
2980
|
}
|
|
2953
2981
|
for (const row of rows) {
|
|
2982
|
+
const record = row;
|
|
2954
2983
|
for (const k in this.schema.properties) {
|
|
2955
|
-
|
|
2984
|
+
record[k] = this.sqlToJsValue(k, record[k]);
|
|
2956
2985
|
}
|
|
2957
2986
|
}
|
|
2958
2987
|
return rows;
|
|
@@ -3183,11 +3212,10 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3183
3212
|
}
|
|
3184
3213
|
const actualType = this.getNonNullType(typeDef);
|
|
3185
3214
|
if (typeof actualType !== "boolean" && (actualType.type === "number" || actualType.type === "integer")) {
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
const parsed = Number(v);
|
|
3215
|
+
if (typeof value === "number")
|
|
3216
|
+
return value;
|
|
3217
|
+
if (typeof value === "string") {
|
|
3218
|
+
const parsed = Number(value);
|
|
3191
3219
|
if (!isNaN(parsed))
|
|
3192
3220
|
return parsed;
|
|
3193
3221
|
}
|
|
@@ -3209,7 +3237,8 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3209
3237
|
let entityToInsert = { ...entity };
|
|
3210
3238
|
if (this.hasAutoGeneratedKey() && this.autoGeneratedKeyName) {
|
|
3211
3239
|
const keyName = String(this.autoGeneratedKeyName);
|
|
3212
|
-
const
|
|
3240
|
+
const entityRecord = entity;
|
|
3241
|
+
const clientProvidedValue = entityRecord[keyName];
|
|
3213
3242
|
const hasClientValue = clientProvidedValue !== undefined && clientProvidedValue !== null;
|
|
3214
3243
|
let shouldOmitKey = false;
|
|
3215
3244
|
if (this.clientProvidedKeys === "never") {
|
|
@@ -3239,8 +3268,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3239
3268
|
if (error)
|
|
3240
3269
|
throw error;
|
|
3241
3270
|
const updatedEntity = data;
|
|
3271
|
+
const updatedRecord = updatedEntity;
|
|
3242
3272
|
for (const key in this.schema.properties) {
|
|
3243
|
-
|
|
3273
|
+
updatedRecord[key] = this.sqlToJsValue(key, updatedRecord[key]);
|
|
3244
3274
|
}
|
|
3245
3275
|
this.events.emit("put", updatedEntity);
|
|
3246
3276
|
return updatedEntity;
|
|
@@ -3252,8 +3282,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3252
3282
|
}
|
|
3253
3283
|
async get(key) {
|
|
3254
3284
|
let query = this.client.from(this.table).select("*");
|
|
3285
|
+
const keyRecord = key;
|
|
3255
3286
|
for (const pkName of this.primaryKeyNames) {
|
|
3256
|
-
query = query.eq(String(pkName),
|
|
3287
|
+
query = query.eq(String(pkName), keyRecord[String(pkName)]);
|
|
3257
3288
|
}
|
|
3258
3289
|
const { data, error } = await query.single();
|
|
3259
3290
|
if (error) {
|
|
@@ -3265,8 +3296,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3265
3296
|
}
|
|
3266
3297
|
const val = data;
|
|
3267
3298
|
if (val) {
|
|
3299
|
+
const valRecord = val;
|
|
3268
3300
|
for (const key2 in this.schema.properties) {
|
|
3269
|
-
|
|
3301
|
+
valRecord[key2] = this.sqlToJsValue(key2, valRecord[key2]);
|
|
3270
3302
|
}
|
|
3271
3303
|
}
|
|
3272
3304
|
this.events.emit("get", key, val);
|
|
@@ -3295,8 +3327,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3295
3327
|
throw error;
|
|
3296
3328
|
if (data && data.length > 0) {
|
|
3297
3329
|
for (const row of data) {
|
|
3330
|
+
const record = row;
|
|
3298
3331
|
for (const key in this.schema.properties) {
|
|
3299
|
-
|
|
3332
|
+
record[key] = this.sqlToJsValue(key, record[key]);
|
|
3300
3333
|
}
|
|
3301
3334
|
}
|
|
3302
3335
|
this.events.emit("search", searchCriteria, data);
|
|
@@ -3309,8 +3342,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3309
3342
|
async delete(value) {
|
|
3310
3343
|
const { key } = this.separateKeyValueFromCombined(value);
|
|
3311
3344
|
let query = this.client.from(this.table).delete();
|
|
3345
|
+
const deleteKeyRecord = key;
|
|
3312
3346
|
for (const pkName of this.primaryKeyNames) {
|
|
3313
|
-
query = query.eq(String(pkName),
|
|
3347
|
+
query = query.eq(String(pkName), deleteKeyRecord[String(pkName)]);
|
|
3314
3348
|
}
|
|
3315
3349
|
const { error } = await query;
|
|
3316
3350
|
if (error)
|
|
@@ -3323,8 +3357,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3323
3357
|
throw error;
|
|
3324
3358
|
if (data && data.length) {
|
|
3325
3359
|
for (const row of data) {
|
|
3360
|
+
const record = row;
|
|
3326
3361
|
for (const key in this.schema.properties) {
|
|
3327
|
-
|
|
3362
|
+
record[key] = this.sqlToJsValue(key, record[key]);
|
|
3328
3363
|
}
|
|
3329
3364
|
}
|
|
3330
3365
|
return data;
|
|
@@ -3356,8 +3391,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3356
3391
|
return;
|
|
3357
3392
|
}
|
|
3358
3393
|
for (const row of data) {
|
|
3394
|
+
const record = row;
|
|
3359
3395
|
for (const key in this.schema.properties) {
|
|
3360
|
-
|
|
3396
|
+
record[key] = this.sqlToJsValue(key, record[key]);
|
|
3361
3397
|
}
|
|
3362
3398
|
}
|
|
3363
3399
|
return data;
|
|
@@ -3406,8 +3442,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3406
3442
|
}
|
|
3407
3443
|
convertRealtimeRow(row) {
|
|
3408
3444
|
const entity = { ...row };
|
|
3445
|
+
const record = entity;
|
|
3409
3446
|
for (const key in this.schema.properties) {
|
|
3410
|
-
|
|
3447
|
+
record[key] = this.sqlToJsValue(key, row[key]);
|
|
3411
3448
|
}
|
|
3412
3449
|
return entity;
|
|
3413
3450
|
}
|
|
@@ -7070,6 +7107,105 @@ class IndexedDbQueueStorage {
|
|
|
7070
7107
|
}
|
|
7071
7108
|
}
|
|
7072
7109
|
}
|
|
7110
|
+
// src/vector/IndexedDbVectorStorage.ts
|
|
7111
|
+
import { cosineSimilarity as cosineSimilarity4, createServiceToken as createServiceToken31 } from "@workglow/util";
|
|
7112
|
+
var IDB_VECTOR_REPOSITORY = createServiceToken31("storage.vectorRepository.indexedDb");
|
|
7113
|
+
function matchesFilter3(metadata, filter) {
|
|
7114
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
7115
|
+
if (metadata[key] !== value) {
|
|
7116
|
+
return false;
|
|
7117
|
+
}
|
|
7118
|
+
}
|
|
7119
|
+
return true;
|
|
7120
|
+
}
|
|
7121
|
+
function textRelevance2(text, query) {
|
|
7122
|
+
const textLower = text.toLowerCase();
|
|
7123
|
+
const queryLower = query.toLowerCase();
|
|
7124
|
+
const queryWords = queryLower.split(/\s+/).filter((w) => w.length > 0);
|
|
7125
|
+
if (queryWords.length === 0) {
|
|
7126
|
+
return 0;
|
|
7127
|
+
}
|
|
7128
|
+
let matches = 0;
|
|
7129
|
+
for (const word of queryWords) {
|
|
7130
|
+
if (textLower.includes(word)) {
|
|
7131
|
+
matches++;
|
|
7132
|
+
}
|
|
7133
|
+
}
|
|
7134
|
+
return matches / queryWords.length;
|
|
7135
|
+
}
|
|
7136
|
+
|
|
7137
|
+
class IndexedDbVectorStorage extends IndexedDbTabularStorage {
|
|
7138
|
+
vectorDimensions;
|
|
7139
|
+
VectorType;
|
|
7140
|
+
vectorPropertyName;
|
|
7141
|
+
metadataPropertyName;
|
|
7142
|
+
constructor(table = "vectors", schema, primaryKeyNames, indexes = [], dimensions, VectorType = Float32Array, migrationOptions = {}, clientProvidedKeys = "if-missing") {
|
|
7143
|
+
super(table, schema, primaryKeyNames, indexes, migrationOptions, clientProvidedKeys);
|
|
7144
|
+
this.vectorDimensions = dimensions;
|
|
7145
|
+
this.VectorType = VectorType;
|
|
7146
|
+
const vectorProp = getVectorProperty(schema);
|
|
7147
|
+
if (!vectorProp) {
|
|
7148
|
+
throw new Error("Schema must have a property with type array and format TypedArray");
|
|
7149
|
+
}
|
|
7150
|
+
this.vectorPropertyName = vectorProp;
|
|
7151
|
+
this.metadataPropertyName = getMetadataProperty(schema);
|
|
7152
|
+
}
|
|
7153
|
+
getVectorDimensions() {
|
|
7154
|
+
return this.vectorDimensions;
|
|
7155
|
+
}
|
|
7156
|
+
async similaritySearch(query, options = {}) {
|
|
7157
|
+
const { topK = 10, filter, scoreThreshold = 0 } = options;
|
|
7158
|
+
const results = [];
|
|
7159
|
+
const allEntities = await this.getAll() || [];
|
|
7160
|
+
for (const entity of allEntities) {
|
|
7161
|
+
const vector = entity[this.vectorPropertyName];
|
|
7162
|
+
const metadata = this.metadataPropertyName ? entity[this.metadataPropertyName] : {};
|
|
7163
|
+
if (filter && !matchesFilter3(metadata, filter)) {
|
|
7164
|
+
continue;
|
|
7165
|
+
}
|
|
7166
|
+
const score = cosineSimilarity4(query, vector);
|
|
7167
|
+
if (score < scoreThreshold) {
|
|
7168
|
+
continue;
|
|
7169
|
+
}
|
|
7170
|
+
results.push({
|
|
7171
|
+
...entity,
|
|
7172
|
+
score
|
|
7173
|
+
});
|
|
7174
|
+
}
|
|
7175
|
+
results.sort((a, b) => b.score - a.score);
|
|
7176
|
+
const topResults = results.slice(0, topK);
|
|
7177
|
+
return topResults;
|
|
7178
|
+
}
|
|
7179
|
+
async hybridSearch(query, options) {
|
|
7180
|
+
const { topK = 10, filter, scoreThreshold = 0, textQuery, vectorWeight = 0.7 } = options;
|
|
7181
|
+
if (!textQuery || textQuery.trim().length === 0) {
|
|
7182
|
+
return this.similaritySearch(query, { topK, filter, scoreThreshold });
|
|
7183
|
+
}
|
|
7184
|
+
const results = [];
|
|
7185
|
+
const allEntities = await this.getAll() || [];
|
|
7186
|
+
for (const entity of allEntities) {
|
|
7187
|
+
const vector = entity[this.vectorPropertyName];
|
|
7188
|
+
const metadata = this.metadataPropertyName ? entity[this.metadataPropertyName] : {};
|
|
7189
|
+
if (filter && !matchesFilter3(metadata, filter)) {
|
|
7190
|
+
continue;
|
|
7191
|
+
}
|
|
7192
|
+
const vectorScore = cosineSimilarity4(query, vector);
|
|
7193
|
+
const metadataText = Object.values(metadata).join(" ").toLowerCase();
|
|
7194
|
+
const textScore = textRelevance2(metadataText, textQuery);
|
|
7195
|
+
const combinedScore = vectorWeight * vectorScore + (1 - vectorWeight) * textScore;
|
|
7196
|
+
if (combinedScore < scoreThreshold) {
|
|
7197
|
+
continue;
|
|
7198
|
+
}
|
|
7199
|
+
results.push({
|
|
7200
|
+
...entity,
|
|
7201
|
+
score: combinedScore
|
|
7202
|
+
});
|
|
7203
|
+
}
|
|
7204
|
+
results.sort((a, b) => b.score - a.score);
|
|
7205
|
+
const topResults = results.slice(0, topK);
|
|
7206
|
+
return topResults;
|
|
7207
|
+
}
|
|
7208
|
+
}
|
|
7073
7209
|
export {
|
|
7074
7210
|
registerTabularRepository,
|
|
7075
7211
|
isSearchCondition,
|
|
@@ -7116,6 +7252,7 @@ export {
|
|
|
7116
7252
|
KvStorage,
|
|
7117
7253
|
KV_REPOSITORY,
|
|
7118
7254
|
JobStatus,
|
|
7255
|
+
IndexedDbVectorStorage,
|
|
7119
7256
|
IndexedDbTabularStorage,
|
|
7120
7257
|
IndexedDbRateLimiterStorage,
|
|
7121
7258
|
IndexedDbQueueStorage,
|
|
@@ -7129,6 +7266,7 @@ export {
|
|
|
7129
7266
|
IN_MEMORY_QUEUE_STORAGE,
|
|
7130
7267
|
INDEXED_DB_RATE_LIMITER_STORAGE,
|
|
7131
7268
|
INDEXED_DB_QUEUE_STORAGE,
|
|
7269
|
+
IDB_VECTOR_REPOSITORY,
|
|
7132
7270
|
IDB_TABULAR_REPOSITORY,
|
|
7133
7271
|
IDB_KV_REPOSITORY,
|
|
7134
7272
|
HybridSubscriptionManager,
|
|
@@ -7147,4 +7285,4 @@ export {
|
|
|
7147
7285
|
BaseTabularStorage
|
|
7148
7286
|
};
|
|
7149
7287
|
|
|
7150
|
-
//# debugId=
|
|
7288
|
+
//# debugId=24D8B8B9BAD9862964756E2164756E21
|