@workglow/storage 0.0.103 → 0.0.105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/browser.js +570 -219
  2. package/dist/browser.js.map +13 -11
  3. package/dist/bun.js +671 -288
  4. package/dist/bun.js.map +15 -13
  5. package/dist/common.d.ts +2 -0
  6. package/dist/common.d.ts.map +1 -1
  7. package/dist/credentials/EncryptedKvCredentialStore.d.ts +52 -0
  8. package/dist/credentials/EncryptedKvCredentialStore.d.ts.map +1 -0
  9. package/dist/node.js +671 -288
  10. package/dist/node.js.map +15 -13
  11. package/dist/tabular/BaseTabularStorage.d.ts +21 -7
  12. package/dist/tabular/BaseTabularStorage.d.ts.map +1 -1
  13. package/dist/tabular/CachedTabularStorage.d.ts +14 -10
  14. package/dist/tabular/CachedTabularStorage.d.ts.map +1 -1
  15. package/dist/tabular/FsFolderTabularStorage.d.ts +6 -6
  16. package/dist/tabular/FsFolderTabularStorage.d.ts.map +1 -1
  17. package/dist/tabular/HuggingFaceTabularStorage.d.ts +11 -6
  18. package/dist/tabular/HuggingFaceTabularStorage.d.ts.map +1 -1
  19. package/dist/tabular/ITabularStorage.d.ts +22 -3
  20. package/dist/tabular/ITabularStorage.d.ts.map +1 -1
  21. package/dist/tabular/InMemoryTabularStorage.d.ts +12 -10
  22. package/dist/tabular/InMemoryTabularStorage.d.ts.map +1 -1
  23. package/dist/tabular/IndexedDbTabularStorage.d.ts +12 -10
  24. package/dist/tabular/IndexedDbTabularStorage.d.ts.map +1 -1
  25. package/dist/tabular/PostgresTabularStorage.d.ts +12 -11
  26. package/dist/tabular/PostgresTabularStorage.d.ts.map +1 -1
  27. package/dist/tabular/SharedInMemoryTabularStorage.d.ts +12 -10
  28. package/dist/tabular/SharedInMemoryTabularStorage.d.ts.map +1 -1
  29. package/dist/tabular/SqliteTabularStorage.d.ts +12 -11
  30. package/dist/tabular/SqliteTabularStorage.d.ts.map +1 -1
  31. package/dist/tabular/StorageError.d.ts +31 -0
  32. package/dist/tabular/StorageError.d.ts.map +1 -0
  33. package/dist/tabular/SupabaseTabularStorage.d.ts +12 -10
  34. package/dist/tabular/SupabaseTabularStorage.d.ts.map +1 -1
  35. package/package.json +7 -7
package/dist/node.js CHANGED
@@ -4,6 +4,58 @@ import {
4
4
  EventEmitter,
5
5
  makeFingerprint
6
6
  } from "@workglow/util";
7
+
8
+ // src/tabular/ITabularStorage.ts
9
+ function isSearchCondition(value) {
10
+ return typeof value === "object" && value !== null && "value" in value && "operator" in value && typeof value.operator === "string";
11
+ }
12
+
13
+ // src/tabular/StorageError.ts
14
+ import { BaseError } from "@workglow/util";
15
+
16
+ class StorageError extends BaseError {
17
+ static type = "StorageError";
18
+ constructor(message) {
19
+ super(message);
20
+ }
21
+ }
22
+
23
+ class StorageValidationError extends StorageError {
24
+ static type = "StorageValidationError";
25
+ constructor(message) {
26
+ super(message);
27
+ }
28
+ }
29
+
30
+ class StorageEmptyCriteriaError extends StorageValidationError {
31
+ static type = "StorageEmptyCriteriaError";
32
+ constructor() {
33
+ super("Query criteria must not be empty. Use getAll() to retrieve all records.");
34
+ }
35
+ }
36
+
37
+ class StorageInvalidLimitError extends StorageValidationError {
38
+ static type = "StorageInvalidLimitError";
39
+ constructor(limit) {
40
+ super(`Query limit must be greater than 0, got ${limit}`);
41
+ }
42
+ }
43
+
44
+ class StorageInvalidColumnError extends StorageValidationError {
45
+ static type = "StorageInvalidColumnError";
46
+ constructor(column) {
47
+ super(`Column "${column}" does not exist in the schema`);
48
+ }
49
+ }
50
+
51
+ class StorageUnsupportedError extends StorageError {
52
+ static type = "StorageUnsupportedError";
53
+ constructor(operation, backend) {
54
+ super(`${operation} is not supported for ${backend}`);
55
+ }
56
+ }
57
+
58
+ // src/tabular/BaseTabularStorage.ts
7
59
  var TABULAR_REPOSITORY = createServiceToken("storage.tabularRepository");
8
60
 
9
61
  class BaseTabularStorage {
@@ -162,6 +214,62 @@ class BaseTabularStorage {
162
214
  subscribeToChanges(_callback, _options) {
163
215
  throw new Error(`subscribeToChanges is not implemented for ${this.constructor.name}. ` + `All concrete repository implementations should override this method.`);
164
216
  }
217
+ validateQueryParams(criteria, options) {
218
+ const criteriaKeys = Object.keys(criteria);
219
+ if (criteriaKeys.length === 0) {
220
+ throw new StorageEmptyCriteriaError;
221
+ }
222
+ if (options?.limit !== undefined && options.limit <= 0) {
223
+ throw new StorageInvalidLimitError(options.limit);
224
+ }
225
+ if (options?.offset !== undefined && options.offset < 0) {
226
+ throw new StorageValidationError(`Query offset must be non-negative, got ${options.offset}`);
227
+ }
228
+ for (const column of criteriaKeys) {
229
+ if (!(column in this.schema.properties)) {
230
+ throw new StorageInvalidColumnError(String(column));
231
+ }
232
+ const criterion = criteria[column];
233
+ if (isSearchCondition(criterion)) {
234
+ const validOperators = ["=", "<", "<=", ">", ">="];
235
+ if (!validOperators.includes(criterion.operator)) {
236
+ throw new StorageValidationError(`Invalid operator "${criterion.operator}". Must be one of: ${validOperators.join(", ")}`);
237
+ }
238
+ }
239
+ }
240
+ if (options?.orderBy) {
241
+ const validDirections = ["ASC", "DESC"];
242
+ for (const { column, direction } of options.orderBy) {
243
+ if (!(column in this.schema.properties)) {
244
+ throw new StorageInvalidColumnError(String(column));
245
+ }
246
+ if (!validDirections.includes(direction)) {
247
+ throw new StorageValidationError(`Invalid sort direction "${direction}". Must be "ASC" or "DESC"`);
248
+ }
249
+ }
250
+ }
251
+ }
252
+ validateGetAllOptions(options) {
253
+ if (!options)
254
+ return;
255
+ if (options.limit !== undefined && options.limit <= 0) {
256
+ throw new StorageInvalidLimitError(options.limit);
257
+ }
258
+ if (options.offset !== undefined && options.offset < 0) {
259
+ throw new StorageValidationError(`Query offset must be non-negative, got ${options.offset}`);
260
+ }
261
+ if (options.orderBy) {
262
+ const validDirections = ["ASC", "DESC"];
263
+ for (const { column, direction } of options.orderBy) {
264
+ if (!(column in this.schema.properties)) {
265
+ throw new StorageInvalidColumnError(String(column));
266
+ }
267
+ if (!validDirections.includes(direction)) {
268
+ throw new StorageValidationError(`Invalid sort direction "${direction}". Must be "ASC" or "DESC"`);
269
+ }
270
+ }
271
+ }
272
+ }
165
273
  primaryKeyColumns() {
166
274
  const columns = [];
167
275
  for (const key of Object.keys(this.primaryKeySchema.properties)) {
@@ -279,7 +387,8 @@ class BaseTabularStorage {
279
387
  }
280
388
  // src/tabular/CachedTabularStorage.ts
281
389
  import {
282
- createServiceToken as createServiceToken3
390
+ createServiceToken as createServiceToken3,
391
+ getLogger
283
392
  } from "@workglow/util";
284
393
 
285
394
  // src/tabular/InMemoryTabularStorage.ts
@@ -288,13 +397,6 @@ import {
288
397
  makeFingerprint as makeFingerprint2,
289
398
  uuid4
290
399
  } from "@workglow/util";
291
-
292
- // src/tabular/ITabularStorage.ts
293
- function isSearchCondition(value) {
294
- return typeof value === "object" && value !== null && "value" in value && "operator" in value && typeof value.operator === "string";
295
- }
296
-
297
- // src/tabular/InMemoryTabularStorage.ts
298
400
  var MEMORY_TABULAR_REPOSITORY = createServiceToken2("storage.tabularRepository.inMemory");
299
401
 
300
402
  class InMemoryTabularStorage extends BaseTabularStorage {
@@ -348,24 +450,6 @@ class InMemoryTabularStorage extends BaseTabularStorage {
348
450
  this.events.emit("get", key, out);
349
451
  return out;
350
452
  }
351
- async search(key) {
352
- const searchKeys = Object.keys(key);
353
- if (searchKeys.length === 0) {
354
- return;
355
- }
356
- const bestIndex = this.findBestMatchingIndex(searchKeys);
357
- if (!bestIndex) {
358
- throw new Error(`No suitable index found for the search criteria, searching for ['${searchKeys.join("', '")}'] with pk ['${this.primaryKeyNames.join("', '")}'] and indexes ['${this.indexes.join("', '")}']`);
359
- }
360
- const results = Array.from(this.values.values()).filter((item) => Object.entries(key).every(([k, v]) => item[k] === v));
361
- if (results.length > 0) {
362
- this.events.emit("search", key, results);
363
- return results;
364
- } else {
365
- this.events.emit("search", key, undefined);
366
- return;
367
- }
368
- }
369
453
  async delete(value) {
370
454
  const { key } = this.separateKeyValueFromCombined(value);
371
455
  const id = await makeFingerprint2(key);
@@ -376,8 +460,34 @@ class InMemoryTabularStorage extends BaseTabularStorage {
376
460
  this.values.clear();
377
461
  this.events.emit("clearall");
378
462
  }
379
- async getAll() {
380
- const all = Array.from(this.values.values());
463
+ async getAll(options) {
464
+ this.validateGetAllOptions(options);
465
+ let all = Array.from(this.values.values());
466
+ if (options?.orderBy && options.orderBy.length > 0) {
467
+ all.sort((a, b) => {
468
+ for (const { column, direction } of options.orderBy) {
469
+ const aVal = a[column];
470
+ const bVal = b[column];
471
+ if (aVal == null && bVal == null)
472
+ continue;
473
+ if (aVal == null)
474
+ return direction === "ASC" ? -1 : 1;
475
+ if (bVal == null)
476
+ return direction === "ASC" ? 1 : -1;
477
+ if (aVal < bVal)
478
+ return direction === "ASC" ? -1 : 1;
479
+ if (aVal > bVal)
480
+ return direction === "ASC" ? 1 : -1;
481
+ }
482
+ return 0;
483
+ });
484
+ }
485
+ if (options?.offset !== undefined) {
486
+ all = all.slice(options.offset);
487
+ }
488
+ if (options?.limit !== undefined) {
489
+ all = all.slice(0, options.limit);
490
+ }
381
491
  return all.length > 0 ? all : undefined;
382
492
  }
383
493
  async size() {
@@ -450,6 +560,77 @@ class InMemoryTabularStorage extends BaseTabularStorage {
450
560
  this.events.emit("delete", key);
451
561
  }
452
562
  }
563
+ async query(criteria, options) {
564
+ this.validateQueryParams(criteria, options);
565
+ const criteriaKeys = Object.keys(criteria);
566
+ let results = Array.from(this.values.values()).filter((entity) => {
567
+ for (const column of criteriaKeys) {
568
+ const criterion = criteria[column];
569
+ const columnValue = entity[column];
570
+ if (isSearchCondition(criterion)) {
571
+ const { value, operator } = criterion;
572
+ const v = value;
573
+ const cv = columnValue;
574
+ switch (operator) {
575
+ case "=":
576
+ if (cv !== v)
577
+ return false;
578
+ break;
579
+ case "<":
580
+ if (cv === null || cv === undefined || !(cv < v))
581
+ return false;
582
+ break;
583
+ case "<=":
584
+ if (cv === null || cv === undefined || !(cv <= v))
585
+ return false;
586
+ break;
587
+ case ">":
588
+ if (cv === null || cv === undefined || !(cv > v))
589
+ return false;
590
+ break;
591
+ case ">=":
592
+ if (cv === null || cv === undefined || !(cv >= v))
593
+ return false;
594
+ break;
595
+ default:
596
+ return false;
597
+ }
598
+ } else {
599
+ if (columnValue !== criterion)
600
+ return false;
601
+ }
602
+ }
603
+ return true;
604
+ });
605
+ if (options?.orderBy && options.orderBy.length > 0) {
606
+ results.sort((a, b) => {
607
+ for (const { column, direction } of options.orderBy) {
608
+ const aVal = a[column];
609
+ const bVal = b[column];
610
+ if (aVal == null && bVal == null)
611
+ continue;
612
+ if (aVal == null)
613
+ return direction === "ASC" ? -1 : 1;
614
+ if (bVal == null)
615
+ return direction === "ASC" ? 1 : -1;
616
+ if (aVal < bVal)
617
+ return direction === "ASC" ? -1 : 1;
618
+ if (aVal > bVal)
619
+ return direction === "ASC" ? 1 : -1;
620
+ }
621
+ return 0;
622
+ });
623
+ }
624
+ if (options?.offset !== undefined) {
625
+ results = results.slice(options.offset);
626
+ }
627
+ if (options?.limit !== undefined) {
628
+ results = results.slice(0, options.limit);
629
+ }
630
+ const result = results.length > 0 ? results : undefined;
631
+ this.events.emit("query", criteria, result);
632
+ return result;
633
+ }
453
634
  subscribeToChanges(callback, options) {
454
635
  const handlePut = (entity) => {
455
636
  callback({ type: "UPDATE", new: entity });
@@ -501,8 +682,8 @@ class CachedTabularStorage extends BaseTabularStorage {
501
682
  this.cache.on("get", (key, entity) => {
502
683
  this.events.emit("get", key, entity);
503
684
  });
504
- this.cache.on("search", (key, entities) => {
505
- this.events.emit("search", key, entities);
685
+ this.cache.on("query", (key, entities) => {
686
+ this.events.emit("query", key, entities);
506
687
  });
507
688
  this.cache.on("delete", (key) => {
508
689
  this.events.emit("delete", key);
@@ -521,7 +702,7 @@ class CachedTabularStorage extends BaseTabularStorage {
521
702
  }
522
703
  this.cacheInitialized = true;
523
704
  } catch (error) {
524
- console.warn("Failed to initialize cache from durable repository:", error);
705
+ getLogger().warn("Failed to initialize cache from durable repository:", { error });
525
706
  this.cacheInitialized = true;
526
707
  }
527
708
  }
@@ -548,17 +729,6 @@ class CachedTabularStorage extends BaseTabularStorage {
548
729
  }
549
730
  return result;
550
731
  }
551
- async search(key) {
552
- await this.initializeCache();
553
- let results = await this.cache.search(key);
554
- if (results === undefined) {
555
- results = await this.durable.search(key);
556
- if (results && results.length > 0) {
557
- await this.cache.putBulk(results);
558
- }
559
- }
560
- return results;
561
- }
562
732
  async delete(value) {
563
733
  await this.initializeCache();
564
734
  await this.durable.delete(value);
@@ -569,7 +739,7 @@ class CachedTabularStorage extends BaseTabularStorage {
569
739
  await this.durable.deleteAll();
570
740
  await this.cache.deleteAll();
571
741
  }
572
- async getAll() {
742
+ async getAll(options) {
573
743
  await this.initializeCache();
574
744
  let results = await this.cache.getAll();
575
745
  if (!results || results.length === 0) {
@@ -578,6 +748,9 @@ class CachedTabularStorage extends BaseTabularStorage {
578
748
  await this.cache.putBulk(results);
579
749
  }
580
750
  }
751
+ if (options && results && results.length > 0) {
752
+ return await this.cache.getAll(options);
753
+ }
581
754
  return results;
582
755
  }
583
756
  async size() {
@@ -588,6 +761,10 @@ class CachedTabularStorage extends BaseTabularStorage {
588
761
  await this.initializeCache();
589
762
  return await this.durable.getBulk(offset, limit);
590
763
  }
764
+ async query(criteria, options) {
765
+ await this.initializeCache();
766
+ return await this.cache.query(criteria, options);
767
+ }
591
768
  async deleteSearch(criteria) {
592
769
  await this.initializeCache();
593
770
  await this.durable.deleteSearch(criteria);
@@ -708,7 +885,8 @@ class HuggingFaceTabularStorage extends BaseTabularStorage {
708
885
  this.events.emit("get", key, undefined);
709
886
  return;
710
887
  }
711
- async getAll() {
888
+ async getAll(options) {
889
+ this.validateGetAllOptions(options);
712
890
  const allEntities = [];
713
891
  let offset = 0;
714
892
  const pageSize = 100;
@@ -723,7 +901,36 @@ class HuggingFaceTabularStorage extends BaseTabularStorage {
723
901
  break;
724
902
  }
725
903
  }
726
- return allEntities.length > 0 ? allEntities : undefined;
904
+ if (allEntities.length === 0)
905
+ return;
906
+ let results = allEntities;
907
+ if (options?.orderBy && options.orderBy.length > 0) {
908
+ results = [...results];
909
+ results.sort((a, b) => {
910
+ for (const { column, direction } of options.orderBy) {
911
+ const aVal = a[column];
912
+ const bVal = b[column];
913
+ if (aVal == null && bVal == null)
914
+ continue;
915
+ if (aVal == null)
916
+ return direction === "ASC" ? -1 : 1;
917
+ if (bVal == null)
918
+ return direction === "ASC" ? 1 : -1;
919
+ if (aVal < bVal)
920
+ return direction === "ASC" ? -1 : 1;
921
+ if (aVal > bVal)
922
+ return direction === "ASC" ? 1 : -1;
923
+ }
924
+ return 0;
925
+ });
926
+ }
927
+ if (options?.offset !== undefined) {
928
+ results = results.slice(options.offset);
929
+ }
930
+ if (options?.limit !== undefined) {
931
+ results = results.slice(0, options.limit);
932
+ }
933
+ return results.length > 0 ? results : undefined;
727
934
  }
728
935
  async getBulk(offset, limit) {
729
936
  const data = await this.fetchApi("/rows", {
@@ -739,18 +946,40 @@ class HuggingFaceTabularStorage extends BaseTabularStorage {
739
946
  }
740
947
  return entities;
741
948
  }
742
- async search(key) {
743
- const searchKeys = Object.keys(key);
744
- if (searchKeys.length === 0) {
745
- return;
746
- }
747
- const bestIndex = this.findBestMatchingIndex(searchKeys);
748
- if (!bestIndex) {
749
- throw new Error(`No suitable index found for the search criteria, searching for ['${searchKeys.join("', '")}'] with pk ['${this.primaryKeyNames.join("', '")}'] and indexes ['${this.indexes.map((idx) => idx.join(",")).join("', '")}'`);
750
- }
949
+ async size() {
950
+ const data = await this.fetchApi("/size", {});
951
+ return data.size.num_rows;
952
+ }
953
+ async put(_value) {
954
+ throw new Error("HuggingFaceTabularStorage is readonly");
955
+ }
956
+ async putBulk(_values) {
957
+ throw new Error("HuggingFaceTabularStorage is readonly");
958
+ }
959
+ async delete(_value) {
960
+ throw new Error("HuggingFaceTabularStorage is readonly");
961
+ }
962
+ async deleteAll() {
963
+ throw new Error("HuggingFaceTabularStorage is readonly");
964
+ }
965
+ async query(criteria, options) {
966
+ this.validateQueryParams(criteria, options);
751
967
  const whereConditions = [];
752
- for (const [k, v] of Object.entries(key)) {
753
- if (v !== undefined && v !== null) {
968
+ for (const [k, v] of Object.entries(criteria)) {
969
+ if (v === undefined || v === null)
970
+ continue;
971
+ if (isSearchCondition(v)) {
972
+ if (v.operator !== "=") {
973
+ throw new StorageUnsupportedError(`Operator "${v.operator}" in query`, "HuggingFaceTabularStorage");
974
+ }
975
+ const val = v.value;
976
+ if (typeof val === "string") {
977
+ const escaped = val.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
978
+ whereConditions.push(`${k}='${escaped}'`);
979
+ } else {
980
+ whereConditions.push(`${k}=${val}`);
981
+ }
982
+ } else {
754
983
  if (typeof v === "string") {
755
984
  const escaped = v.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
756
985
  whereConditions.push(`${k}='${escaped}'`);
@@ -760,50 +989,60 @@ class HuggingFaceTabularStorage extends BaseTabularStorage {
760
989
  }
761
990
  }
762
991
  if (whereConditions.length === 0) {
763
- throw new Error("Search criteria must include at least one non-null and non-undefined value to build a valid WHERE clause.");
992
+ return;
764
993
  }
765
994
  const where = whereConditions.join(" AND ");
766
995
  const allEntities = [];
767
- let offset = 0;
768
- const limit = 100;
996
+ let fetchOffset = 0;
997
+ const fetchLimit = 100;
769
998
  while (true) {
770
999
  const data = await this.fetchApi("/filter", {
771
1000
  where,
772
- offset: offset.toString(),
773
- limit: limit.toString()
1001
+ offset: fetchOffset.toString(),
1002
+ limit: fetchLimit.toString()
774
1003
  });
775
1004
  for (const row of data.rows) {
776
1005
  allEntities.push(this.rowToEntity(row));
777
1006
  }
778
- offset += data.rows.length;
779
- if (offset >= data.num_rows_total || data.rows.length < limit) {
1007
+ fetchOffset += data.rows.length;
1008
+ if (fetchOffset >= data.num_rows_total || data.rows.length < fetchLimit) {
780
1009
  break;
781
1010
  }
782
1011
  }
783
- if (allEntities.length > 0) {
784
- this.events.emit("search", key, allEntities);
785
- return allEntities;
1012
+ let results = allEntities;
1013
+ if (options?.orderBy && options.orderBy.length > 0) {
1014
+ results.sort((a, b) => {
1015
+ for (const { column, direction } of options.orderBy) {
1016
+ const aVal = a[column];
1017
+ const bVal = b[column];
1018
+ if (aVal == null && bVal == null)
1019
+ continue;
1020
+ if (aVal == null)
1021
+ return direction === "ASC" ? -1 : 1;
1022
+ if (bVal == null)
1023
+ return direction === "ASC" ? 1 : -1;
1024
+ if (aVal < bVal)
1025
+ return direction === "ASC" ? -1 : 1;
1026
+ if (aVal > bVal)
1027
+ return direction === "ASC" ? 1 : -1;
1028
+ }
1029
+ return 0;
1030
+ });
1031
+ }
1032
+ if (options?.offset !== undefined) {
1033
+ results = results.slice(options.offset);
1034
+ }
1035
+ if (options?.limit !== undefined) {
1036
+ results = results.slice(0, options.limit);
1037
+ }
1038
+ if (results.length > 0) {
1039
+ this.events.emit("query", criteria, results);
1040
+ return results;
786
1041
  } else {
787
- this.events.emit("search", key, undefined);
1042
+ this.events.emit("query", criteria, undefined);
788
1043
  return;
789
1044
  }
790
1045
  }
791
- async size() {
792
- const data = await this.fetchApi("/size", {});
793
- return data.size.num_rows;
794
- }
795
- async put(_value) {
796
- throw new Error("HuggingFaceTabularStorage is readonly");
797
- }
798
- async putBulk(_values) {
799
- throw new Error("HuggingFaceTabularStorage is readonly");
800
- }
801
- async delete(_value) {
802
- throw new Error("HuggingFaceTabularStorage is readonly");
803
- }
804
- async deleteAll() {
805
- throw new Error("HuggingFaceTabularStorage is readonly");
806
- }
807
1046
  async deleteSearch(_criteria) {
808
1047
  throw new Error("HuggingFaceTabularStorage is readonly");
809
1048
  }
@@ -1034,7 +1273,7 @@ class InMemoryKvStorage extends KvViaTabularStorage {
1034
1273
  import {
1035
1274
  createServiceToken as createServiceToken9,
1036
1275
  EventEmitter as EventEmitter3,
1037
- getLogger,
1276
+ getLogger as getLogger2,
1038
1277
  makeFingerprint as makeFingerprint4,
1039
1278
  sleep,
1040
1279
  uuid4 as uuid42
@@ -1133,7 +1372,7 @@ class InMemoryQueueStorage {
1133
1372
  const job = this.jobQueue.find((j) => j.id === id && this.matchesPrefixes(j));
1134
1373
  if (!job) {
1135
1374
  const jobWithAnyPrefix = this.jobQueue.find((j) => j.id === id);
1136
- getLogger().warn("Job not found for progress update", {
1375
+ getLogger2().warn("Job not found for progress update", {
1137
1376
  id,
1138
1377
  reason: jobWithAnyPrefix ? "prefix_mismatch" : "missing",
1139
1378
  existingStatus: jobWithAnyPrefix?.status,
@@ -1143,7 +1382,7 @@ class InMemoryQueueStorage {
1143
1382
  return;
1144
1383
  }
1145
1384
  if (job.status === JobStatus.COMPLETED || job.status === JobStatus.FAILED) {
1146
- getLogger().warn("Job already completed or failed for progress update", {
1385
+ getLogger2().warn("Job already completed or failed for progress update", {
1147
1386
  id,
1148
1387
  status: job.status,
1149
1388
  completedAt: job.completed_at,
@@ -1694,6 +1933,81 @@ class InMemoryVectorStorage extends InMemoryTabularStorage {
1694
1933
  return topResults;
1695
1934
  }
1696
1935
  }
1936
+ // src/credentials/EncryptedKvCredentialStore.ts
1937
+ import { decrypt, encrypt } from "@workglow/util";
1938
+
1939
+ class EncryptedKvCredentialStore {
1940
+ kv;
1941
+ passphrase;
1942
+ keyCache = new Map;
1943
+ constructor(kv, passphrase) {
1944
+ this.kv = kv;
1945
+ this.passphrase = passphrase;
1946
+ if (!passphrase) {
1947
+ throw new Error("EncryptedKvCredentialStore requires a non-empty passphrase.");
1948
+ }
1949
+ }
1950
+ async get(key) {
1951
+ const raw = await this.kv.get(key);
1952
+ if (!raw)
1953
+ return;
1954
+ if (raw.expiresAt && new Date(raw.expiresAt) <= new Date) {
1955
+ await this.kv.delete(key);
1956
+ return;
1957
+ }
1958
+ return decrypt(raw.encrypted, raw.iv, this.passphrase, this.keyCache);
1959
+ }
1960
+ async put(key, value, options) {
1961
+ const now = new Date;
1962
+ const existing = await this.kv.get(key);
1963
+ const { encrypted, iv } = await encrypt(value, this.passphrase, this.keyCache);
1964
+ const stored = {
1965
+ encrypted,
1966
+ iv,
1967
+ label: options?.label ?? existing?.label,
1968
+ provider: options?.provider ?? existing?.provider,
1969
+ createdAt: existing?.createdAt ?? now.toISOString(),
1970
+ updatedAt: now.toISOString(),
1971
+ expiresAt: options?.expiresAt ? options.expiresAt.toISOString() : existing?.expiresAt
1972
+ };
1973
+ await this.kv.put(key, stored);
1974
+ }
1975
+ async delete(key) {
1976
+ const exists = await this.kv.get(key) !== undefined;
1977
+ if (exists) {
1978
+ await this.kv.delete(key);
1979
+ }
1980
+ return exists;
1981
+ }
1982
+ async has(key) {
1983
+ const raw = await this.kv.get(key);
1984
+ if (!raw)
1985
+ return false;
1986
+ if (raw.expiresAt && new Date(raw.expiresAt) <= new Date) {
1987
+ await this.kv.delete(key);
1988
+ return false;
1989
+ }
1990
+ return true;
1991
+ }
1992
+ async keys() {
1993
+ const all = await this.kv.getAll();
1994
+ if (!all)
1995
+ return [];
1996
+ const now = new Date;
1997
+ const result = [];
1998
+ for (const entry of all) {
1999
+ if (entry.value.expiresAt && new Date(entry.value.expiresAt) <= now) {
2000
+ await this.kv.delete(entry.key);
2001
+ continue;
2002
+ }
2003
+ result.push(entry.key);
2004
+ }
2005
+ return result;
2006
+ }
2007
+ async deleteAll() {
2008
+ await this.kv.deleteAll();
2009
+ }
2010
+ }
1697
2011
  // src/tabular/FsFolderTabularStorage.ts
1698
2012
  import {
1699
2013
  createServiceToken as createServiceToken12,
@@ -1854,15 +2168,15 @@ class FsFolderTabularStorage extends BaseTabularStorage {
1854
2168
  const page = allEntities.slice(offset, offset + limit);
1855
2169
  return page.length > 0 ? page : undefined;
1856
2170
  }
1857
- async search(key) {
1858
- throw new Error("Search not supported for FsFolderTabularStorage");
1859
- }
1860
2171
  async getFilePath(value) {
1861
2172
  const { key } = this.separateKeyValueFromCombined(value);
1862
2173
  const filename = await this.getKeyAsIdString(key);
1863
2174
  const fullPath = path.join(this.folderPath, `${filename}.json`);
1864
2175
  return fullPath;
1865
2176
  }
2177
+ async query(_criteria, _options) {
2178
+ throw new StorageUnsupportedError("query", "FsFolderTabularStorage");
2179
+ }
1866
2180
  async deleteSearch(_criteria) {
1867
2181
  throw new Error("deleteSearch is not supported for FsFolderTabularStorage");
1868
2182
  }
@@ -2450,39 +2764,6 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
2450
2764
  this.events.emit("get", key, val);
2451
2765
  return val;
2452
2766
  }
2453
- async search(key) {
2454
- const db = this.db;
2455
- const searchKeys = Object.keys(key);
2456
- if (searchKeys.length === 0) {
2457
- return;
2458
- }
2459
- const bestIndex = this.findBestMatchingIndex(searchKeys);
2460
- if (!bestIndex) {
2461
- throw new Error(`No suitable index found for the search criteria, searching for ['${searchKeys.join("', '")}'] with pk ['${this.primaryKeyNames.join("', '")}'] and indexes ['${this.indexes.join("', '")}']`);
2462
- }
2463
- const validColumns = [...this.primaryKeyColumns(), ...this.valueColumns()];
2464
- const invalidColumns = searchKeys.filter((key2) => !validColumns.includes(key2));
2465
- if (invalidColumns.length > 0) {
2466
- throw new Error(`Invalid columns in search criteria: ${invalidColumns.join(", ")}`);
2467
- }
2468
- const whereClauses = Object.keys(key).map((key2, i) => `"${key2}" = $${i + 1}`).join(" AND ");
2469
- const whereClauseValues = Object.entries(key).map(([k, v]) => this.jsToSqlValue(k, v));
2470
- const sql = `SELECT * FROM "${this.table}" WHERE ${whereClauses}`;
2471
- const result = await db.query(sql, whereClauseValues);
2472
- if (result.rows.length > 0) {
2473
- for (const row of result.rows) {
2474
- const record = row;
2475
- for (const k in this.schema.properties) {
2476
- record[k] = this.sqlToJsValue(k, record[k]);
2477
- }
2478
- }
2479
- this.events.emit("search", key, result.rows);
2480
- return result.rows;
2481
- } else {
2482
- this.events.emit("search", key, undefined);
2483
- return;
2484
- }
2485
- }
2486
2767
  async delete(value) {
2487
2768
  const db = this.db;
2488
2769
  const { key } = this.separateKeyValueFromCombined(value);
@@ -2491,10 +2772,24 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
2491
2772
  await db.query(`DELETE FROM "${this.table}" WHERE ${whereClauses}`, params);
2492
2773
  this.events.emit("delete", key);
2493
2774
  }
2494
- async getAll() {
2775
+ async getAll(options) {
2776
+ this.validateGetAllOptions(options);
2495
2777
  const db = this.db;
2496
- const sql = `SELECT * FROM "${this.table}"`;
2497
- const result = await db.query(sql);
2778
+ let sql = `SELECT * FROM "${this.table}"`;
2779
+ const params = [];
2780
+ if (options?.orderBy && options.orderBy.length > 0) {
2781
+ const orderClauses = options.orderBy.map((o) => `"${String(o.column)}" ${o.direction}`);
2782
+ sql += ` ORDER BY ${orderClauses.join(", ")}`;
2783
+ }
2784
+ if (options?.limit !== undefined) {
2785
+ sql += ` LIMIT $${params.length + 1}`;
2786
+ params.push(options.limit);
2787
+ }
2788
+ if (options?.offset !== undefined) {
2789
+ sql += ` OFFSET $${params.length + 1}`;
2790
+ params.push(options.offset);
2791
+ }
2792
+ const result = params.length > 0 ? await db.query(sql, params) : await db.query(sql);
2498
2793
  if (result.rows.length > 0) {
2499
2794
  for (const row of result.rows) {
2500
2795
  const record = row;
@@ -2567,6 +2862,38 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
2567
2862
  await db.query(`DELETE FROM "${this.table}" WHERE ${whereClause}`, params);
2568
2863
  this.events.emit("delete", criteriaKeys[0]);
2569
2864
  }
2865
+ async query(criteria, options) {
2866
+ this.validateQueryParams(criteria, options);
2867
+ const db = this.db;
2868
+ let sql = `SELECT * FROM "${this.table}"`;
2869
+ const { whereClause, params } = this.buildDeleteSearchWhere(criteria);
2870
+ sql += ` WHERE ${whereClause}`;
2871
+ if (options?.orderBy && options.orderBy.length > 0) {
2872
+ const orderClauses = options.orderBy.map((o) => `"${String(o.column)}" ${o.direction}`);
2873
+ sql += ` ORDER BY ${orderClauses.join(", ")}`;
2874
+ }
2875
+ if (options?.limit !== undefined) {
2876
+ sql += ` LIMIT $${params.length + 1}`;
2877
+ params.push(options.limit);
2878
+ }
2879
+ if (options?.offset !== undefined) {
2880
+ sql += ` OFFSET $${params.length + 1}`;
2881
+ params.push(options.offset);
2882
+ }
2883
+ const result = await db.query(sql, params);
2884
+ if (result.rows.length > 0) {
2885
+ for (const row of result.rows) {
2886
+ const record = row;
2887
+ for (const k in this.schema.properties) {
2888
+ record[k] = this.sqlToJsValue(k, record[k]);
2889
+ }
2890
+ }
2891
+ this.events.emit("query", criteria, result.rows);
2892
+ return result.rows;
2893
+ }
2894
+ this.events.emit("query", criteria, undefined);
2895
+ return;
2896
+ }
2570
2897
  subscribeToChanges(callback, options) {
2571
2898
  throw new Error("subscribeToChanges is not supported for PostgresTabularStorage");
2572
2899
  }
@@ -2899,40 +3226,6 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2899
3226
  return;
2900
3227
  }
2901
3228
  }
2902
- async search(key) {
2903
- const db = this.db;
2904
- const searchKeys = Object.keys(key);
2905
- if (searchKeys.length === 0) {
2906
- return;
2907
- }
2908
- const bestIndex = super.findBestMatchingIndex(searchKeys);
2909
- if (!bestIndex) {
2910
- throw new Error(`No suitable index found for the search criteria, searching for ['${searchKeys.join("', '")}'] with pk ['${this.primaryKeyNames.join("', '")}'] and indexes ['${this.indexes.join("', '")}']`);
2911
- }
2912
- const validColumns = [...this.primaryKeyColumns(), ...this.valueColumns()];
2913
- const invalidColumns = searchKeys.filter((key2) => !validColumns.includes(key2));
2914
- if (invalidColumns.length > 0) {
2915
- throw new Error(`Invalid columns in search criteria: ${invalidColumns.join(", ")}`);
2916
- }
2917
- const whereClauses = Object.keys(key).map((key2, i) => `"${key2}" = ?`).join(" AND ");
2918
- const whereClauseValues = Object.entries(key).map(([k, v]) => this.jsToSqlValue(k, v));
2919
- const sql = `SELECT * FROM \`${this.table}\` WHERE ${whereClauses}`;
2920
- const stmt = db.prepare(sql);
2921
- const result = stmt.all(...whereClauseValues);
2922
- if (result.length > 0) {
2923
- for (const row of result) {
2924
- const record = row;
2925
- for (const k in this.schema.properties) {
2926
- record[k] = this.sqlToJsValue(k, record[k]);
2927
- }
2928
- }
2929
- this.events.emit("search", key, result);
2930
- return result;
2931
- } else {
2932
- this.events.emit("search", key, undefined);
2933
- return;
2934
- }
2935
- }
2936
3229
  async delete(key) {
2937
3230
  const db = this.db;
2938
3231
  const whereClauses = this.primaryKeyColumns().map((key2) => `${key2} = ?`).join(" AND ");
@@ -2941,11 +3234,28 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2941
3234
  stmt.run(...params);
2942
3235
  this.events.emit("delete", key);
2943
3236
  }
2944
- async getAll() {
3237
+ async getAll(options) {
3238
+ this.validateGetAllOptions(options);
2945
3239
  const db = this.db;
2946
- const sql = `SELECT * FROM \`${this.table}\``;
3240
+ let sql = `SELECT * FROM \`${this.table}\``;
3241
+ const params = [];
3242
+ if (options?.orderBy && options.orderBy.length > 0) {
3243
+ const orderClauses = options.orderBy.map((o) => `\`${String(o.column)}\` ${o.direction}`);
3244
+ sql += ` ORDER BY ${orderClauses.join(", ")}`;
3245
+ }
3246
+ if (options?.limit !== undefined) {
3247
+ sql += ` LIMIT ?`;
3248
+ params.push(options.limit);
3249
+ }
3250
+ if (options?.offset !== undefined) {
3251
+ if (options.limit === undefined) {
3252
+ sql += ` LIMIT -1`;
3253
+ }
3254
+ sql += ` OFFSET ?`;
3255
+ params.push(options.offset);
3256
+ }
2947
3257
  const stmt = db.prepare(sql);
2948
- const value = stmt.all();
3258
+ const value = params.length > 0 ? stmt.all(...params) : stmt.all();
2949
3259
  if (!value.length)
2950
3260
  return;
2951
3261
  for (const row of value) {
@@ -3021,6 +3331,42 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
3021
3331
  stmt.run(...params);
3022
3332
  this.events.emit("delete", criteriaKeys[0]);
3023
3333
  }
3334
+ async query(criteria, options) {
3335
+ this.validateQueryParams(criteria, options);
3336
+ const db = this.db;
3337
+ let sql = `SELECT * FROM \`${this.table}\``;
3338
+ const { whereClause, params } = this.buildDeleteSearchWhere(criteria);
3339
+ sql += ` WHERE ${whereClause}`;
3340
+ if (options?.orderBy && options.orderBy.length > 0) {
3341
+ const orderClauses = options.orderBy.map((o) => `\`${String(o.column)}\` ${o.direction}`);
3342
+ sql += ` ORDER BY ${orderClauses.join(", ")}`;
3343
+ }
3344
+ if (options?.limit !== undefined) {
3345
+ sql += ` LIMIT ?`;
3346
+ params.push(options.limit);
3347
+ }
3348
+ if (options?.offset !== undefined) {
3349
+ if (options.limit === undefined) {
3350
+ sql += ` LIMIT -1`;
3351
+ }
3352
+ sql += ` OFFSET ?`;
3353
+ params.push(options.offset);
3354
+ }
3355
+ const stmt = db.prepare(sql);
3356
+ const result = stmt.all(...params);
3357
+ if (result.length > 0) {
3358
+ for (const row of result) {
3359
+ const record = row;
3360
+ for (const k in this.schema.properties) {
3361
+ record[k] = this.sqlToJsValue(k, record[k]);
3362
+ }
3363
+ }
3364
+ this.events.emit("query", criteria, result);
3365
+ return result;
3366
+ }
3367
+ this.events.emit("query", criteria, undefined);
3368
+ return;
3369
+ }
3024
3370
  subscribeToChanges(callback, options) {
3025
3371
  throw new Error("subscribeToChanges is not supported for SqliteTabularStorage");
3026
3372
  }
@@ -3304,41 +3650,6 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3304
3650
  this.events.emit("get", key, val);
3305
3651
  return val;
3306
3652
  }
3307
- async search(searchCriteria) {
3308
- const searchKeys = Object.keys(searchCriteria);
3309
- if (searchKeys.length === 0) {
3310
- return;
3311
- }
3312
- const bestIndex = this.findBestMatchingIndex(searchKeys);
3313
- if (!bestIndex) {
3314
- throw new Error(`No suitable index found for the search criteria, searching for ['${searchKeys.join("', '")}'] with pk ['${this.primaryKeyNames.join("', '")}'] and indexes ['${this.indexes.join("', '")}']`);
3315
- }
3316
- const validColumns = [...this.primaryKeyColumns(), ...this.valueColumns()];
3317
- const invalidColumns = searchKeys.filter((key) => !validColumns.includes(key));
3318
- if (invalidColumns.length > 0) {
3319
- throw new Error(`Invalid columns in search criteria: ${invalidColumns.join(", ")}`);
3320
- }
3321
- let query = this.client.from(this.table).select("*");
3322
- for (const [key, value] of Object.entries(searchCriteria)) {
3323
- query = query.eq(key, value);
3324
- }
3325
- const { data, error } = await query;
3326
- if (error)
3327
- throw error;
3328
- if (data && data.length > 0) {
3329
- for (const row of data) {
3330
- const record = row;
3331
- for (const key in this.schema.properties) {
3332
- record[key] = this.sqlToJsValue(key, record[key]);
3333
- }
3334
- }
3335
- this.events.emit("search", searchCriteria, data);
3336
- return data;
3337
- } else {
3338
- this.events.emit("search", searchCriteria, undefined);
3339
- return;
3340
- }
3341
- }
3342
3653
  async delete(value) {
3343
3654
  const { key } = this.separateKeyValueFromCombined(value);
3344
3655
  let query = this.client.from(this.table).delete();
@@ -3351,8 +3662,23 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3351
3662
  throw error;
3352
3663
  this.events.emit("delete", key);
3353
3664
  }
3354
- async getAll() {
3355
- const { data, error } = await this.client.from(this.table).select("*");
3665
+ async getAll(options) {
3666
+ this.validateGetAllOptions(options);
3667
+ let query = this.client.from(this.table).select("*");
3668
+ if (options?.orderBy) {
3669
+ for (const { column, direction } of options.orderBy) {
3670
+ query = query.order(String(column), { ascending: direction === "ASC" });
3671
+ }
3672
+ }
3673
+ if (options?.offset !== undefined || options?.limit !== undefined) {
3674
+ const start = options?.offset ?? 0;
3675
+ if (options?.limit !== undefined) {
3676
+ query = query.range(start, start + options.limit - 1);
3677
+ } else if (options?.offset !== undefined) {
3678
+ query = query.range(start, start + 999999);
3679
+ }
3680
+ }
3681
+ const { data, error } = await query;
3356
3682
  if (error)
3357
3683
  throw error;
3358
3684
  if (data && data.length) {
@@ -3440,6 +3766,69 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3440
3766
  throw error;
3441
3767
  this.events.emit("delete", criteriaKeys[0]);
3442
3768
  }
3769
+ async query(criteria, options) {
3770
+ this.validateQueryParams(criteria, options);
3771
+ const criteriaKeys = Object.keys(criteria);
3772
+ let query = this.client.from(this.table).select("*");
3773
+ for (const column of criteriaKeys) {
3774
+ const criterion = criteria[column];
3775
+ let operator = "=";
3776
+ let value;
3777
+ if (isSearchCondition(criterion)) {
3778
+ operator = criterion.operator;
3779
+ value = criterion.value;
3780
+ } else {
3781
+ value = criterion;
3782
+ }
3783
+ switch (operator) {
3784
+ case "=":
3785
+ query = query.eq(String(column), value);
3786
+ break;
3787
+ case "<":
3788
+ query = query.lt(String(column), value);
3789
+ break;
3790
+ case "<=":
3791
+ query = query.lte(String(column), value);
3792
+ break;
3793
+ case ">":
3794
+ query = query.gt(String(column), value);
3795
+ break;
3796
+ case ">=":
3797
+ query = query.gte(String(column), value);
3798
+ break;
3799
+ }
3800
+ }
3801
+ if (options?.orderBy) {
3802
+ for (const { column, direction } of options.orderBy) {
3803
+ query = query.order(String(column), { ascending: direction === "ASC" });
3804
+ }
3805
+ }
3806
+ if (options?.offset !== undefined || options?.limit !== undefined) {
3807
+ const start = options?.offset ?? 0;
3808
+ if (options?.limit !== undefined) {
3809
+ query = query.range(start, start + options.limit - 1);
3810
+ } else if (options?.offset !== undefined) {
3811
+ query = query.range(start, start + 999999);
3812
+ }
3813
+ } else if (options?.limit !== undefined) {
3814
+ query = query.limit(options.limit);
3815
+ }
3816
+ const { data, error } = await query;
3817
+ if (error)
3818
+ throw error;
3819
+ if (data && data.length > 0) {
3820
+ for (const row of data) {
3821
+ const record = row;
3822
+ for (const key in this.schema.properties) {
3823
+ record[key] = this.sqlToJsValue(key, record[key]);
3824
+ }
3825
+ }
3826
+ this.events.emit("query", criteria, data);
3827
+ return data;
3828
+ }
3829
+ this.events.emit("query", criteria, undefined);
3830
+ return;
3831
+ }
3443
3832
  convertRealtimeRow(row) {
3444
3833
  const entity = { ...row };
3445
3834
  const record = entity;
@@ -6004,7 +6393,8 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
6004
6393
  };
6005
6394
  });
6006
6395
  }
6007
- async getAll() {
6396
+ async getAll(options) {
6397
+ this.validateGetAllOptions(options);
6008
6398
  const db = await this.getDb();
6009
6399
  const transaction = db.transaction(this.table, "readonly");
6010
6400
  const store = transaction.objectStore(this.table);
@@ -6012,96 +6402,38 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
6012
6402
  return new Promise((resolve, reject) => {
6013
6403
  request.onerror = () => reject(request.error);
6014
6404
  request.onsuccess = () => {
6015
- const values = request.result;
6016
- resolve(values.length > 0 ? values : undefined);
6017
- };
6018
- });
6019
- }
6020
- async search(key) {
6021
- const db = await this.getDb();
6022
- const searchKeys = Object.keys(key);
6023
- if (searchKeys.length === 0) {
6024
- return;
6025
- }
6026
- const bestIndex = this.findBestMatchingIndex(searchKeys);
6027
- if (!bestIndex) {
6028
- throw new Error("No suitable index found for the search criteria");
6029
- }
6030
- return new Promise((resolve, reject) => {
6031
- const transaction = db.transaction(this.table, "readonly");
6032
- const store = transaction.objectStore(this.table);
6033
- const indexName = bestIndex.join("_");
6034
- const primaryKeyName = this.primaryKeyColumns().join("_");
6035
- const isPrimaryKey = indexName === primaryKeyName;
6036
- const indexValues = [];
6037
- for (const col of bestIndex) {
6038
- const val = key[col];
6039
- if (val === undefined)
6040
- break;
6041
- if (typeof val !== "string" && typeof val !== "number") {
6042
- throw new Error(`Invalid value type for indexed column ${String(col)}`);
6405
+ let values = request.result;
6406
+ if (values.length === 0) {
6407
+ resolve(undefined);
6408
+ return;
6043
6409
  }
6044
- indexValues.push(val);
6045
- }
6046
- if (indexValues.length > 0) {
6047
- const index = isPrimaryKey ? store : store.index(indexName);
6048
- const isPartialMatch = indexValues.length < bestIndex.length;
6049
- if (isPartialMatch) {
6050
- const allColumnsRequired = bestIndex.every((col) => {
6051
- const colName = String(col);
6052
- return this.schema.required?.includes(colName);
6410
+ if (options?.orderBy && options.orderBy.length > 0) {
6411
+ values.sort((a, b) => {
6412
+ for (const { column, direction } of options.orderBy) {
6413
+ const aVal = a[column];
6414
+ const bVal = b[column];
6415
+ if (aVal == null && bVal == null)
6416
+ continue;
6417
+ if (aVal == null)
6418
+ return direction === "ASC" ? -1 : 1;
6419
+ if (bVal == null)
6420
+ return direction === "ASC" ? 1 : -1;
6421
+ if (aVal < bVal)
6422
+ return direction === "ASC" ? -1 : 1;
6423
+ if (aVal > bVal)
6424
+ return direction === "ASC" ? 1 : -1;
6425
+ }
6426
+ return 0;
6053
6427
  });
6054
- if (allColumnsRequired) {
6055
- const results = [];
6056
- const keyRange = IDBKeyRange.lowerBound(indexValues);
6057
- const cursorRequest = index.openCursor(keyRange);
6058
- cursorRequest.onsuccess = () => {
6059
- const cursor = cursorRequest.result;
6060
- if (cursor) {
6061
- const item = cursor.value;
6062
- const cursorKey = Array.isArray(cursor.key) ? cursor.key : [cursor.key];
6063
- const prefixMatches = indexValues.every((val, idx) => cursorKey[idx] === val);
6064
- if (!prefixMatches) {
6065
- resolve(results.length > 0 ? results : undefined);
6066
- return;
6067
- }
6068
- const matches = Object.entries(key).every(([k, v]) => item[k] === v);
6069
- if (matches) {
6070
- results.push(item);
6071
- }
6072
- cursor.continue();
6073
- } else {
6074
- resolve(results.length > 0 ? results : undefined);
6075
- }
6076
- };
6077
- cursorRequest.onerror = () => {
6078
- reject(cursorRequest.error);
6079
- };
6080
- } else {
6081
- const getAllRequest = store.getAll();
6082
- getAllRequest.onsuccess = () => {
6083
- const allRecords = getAllRequest.result;
6084
- const results = allRecords.filter((item) => Object.entries(key).every(([k, v]) => item[k] === v));
6085
- resolve(results.length > 0 ? results : undefined);
6086
- };
6087
- getAllRequest.onerror = () => {
6088
- reject(getAllRequest.error);
6089
- };
6090
- }
6091
- } else {
6092
- const request = index.getAll(indexValues.length === 1 ? indexValues[0] : indexValues);
6093
- request.onsuccess = () => {
6094
- const results = request.result.filter((item) => Object.entries(key).every(([k, v]) => item[k] === v));
6095
- resolve(results.length > 0 ? results : undefined);
6096
- };
6097
- request.onerror = () => {
6098
- console.error("Search error:", request.error);
6099
- reject(request.error);
6100
- };
6101
6428
  }
6102
- } else {
6103
- throw new Error(`No valid values provided for indexed columns: ${bestIndex.join(", ")}`);
6104
- }
6429
+ if (options?.offset !== undefined) {
6430
+ values = values.slice(options.offset);
6431
+ }
6432
+ if (options?.limit !== undefined) {
6433
+ values = values.slice(0, options.limit);
6434
+ }
6435
+ resolve(values.length > 0 ? values : undefined);
6436
+ };
6105
6437
  });
6106
6438
  }
6107
6439
  async delete(key) {
@@ -6267,6 +6599,50 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
6267
6599
  }
6268
6600
  });
6269
6601
  }
6602
+ async query(criteria, options) {
6603
+ this.validateQueryParams(criteria, options);
6604
+ const db = await this.getDb();
6605
+ return new Promise((resolve, reject) => {
6606
+ const transaction = db.transaction(this.table, "readonly");
6607
+ const store = transaction.objectStore(this.table);
6608
+ const getAllRequest = store.getAll();
6609
+ getAllRequest.onsuccess = () => {
6610
+ const allRecords = getAllRequest.result;
6611
+ let results = allRecords.filter((record) => this.matchesCriteria(record, criteria));
6612
+ if (options?.orderBy && options.orderBy.length > 0) {
6613
+ results.sort((a, b) => {
6614
+ for (const { column, direction } of options.orderBy) {
6615
+ const aVal = a[column];
6616
+ const bVal = b[column];
6617
+ if (aVal == null && bVal == null)
6618
+ continue;
6619
+ if (aVal == null)
6620
+ return direction === "ASC" ? -1 : 1;
6621
+ if (bVal == null)
6622
+ return direction === "ASC" ? 1 : -1;
6623
+ if (aVal < bVal)
6624
+ return direction === "ASC" ? -1 : 1;
6625
+ if (aVal > bVal)
6626
+ return direction === "ASC" ? 1 : -1;
6627
+ }
6628
+ return 0;
6629
+ });
6630
+ }
6631
+ if (options?.offset !== undefined) {
6632
+ results = results.slice(options.offset);
6633
+ }
6634
+ if (options?.limit !== undefined) {
6635
+ results = results.slice(0, options.limit);
6636
+ }
6637
+ const result = results.length > 0 ? results : undefined;
6638
+ this.events.emit("query", criteria, result);
6639
+ resolve(result);
6640
+ };
6641
+ getAllRequest.onerror = () => {
6642
+ reject(getAllRequest.error);
6643
+ };
6644
+ });
6645
+ }
6270
6646
  getHybridManager() {
6271
6647
  if (!this.hybridManager) {
6272
6648
  const channelName = `indexeddb-tabular-${this.table}`;
@@ -7221,6 +7597,12 @@ export {
7221
7597
  SupabaseRateLimiterStorage,
7222
7598
  SupabaseQueueStorage,
7223
7599
  SupabaseKvStorage,
7600
+ StorageValidationError,
7601
+ StorageUnsupportedError,
7602
+ StorageInvalidLimitError,
7603
+ StorageInvalidColumnError,
7604
+ StorageError,
7605
+ StorageEmptyCriteriaError,
7224
7606
  SqliteVectorStorage,
7225
7607
  SqliteTabularStorage,
7226
7608
  SqliteRateLimiterStorage,
@@ -7278,6 +7660,7 @@ export {
7278
7660
  FS_FOLDER_TABULAR_REPOSITORY,
7279
7661
  FS_FOLDER_KV_REPOSITORY,
7280
7662
  FS_FOLDER_JSON_KV_REPOSITORY,
7663
+ EncryptedKvCredentialStore,
7281
7664
  DefaultKeyValueSchema,
7282
7665
  DefaultKeyValueKey,
7283
7666
  CachedTabularStorage,
@@ -7285,4 +7668,4 @@ export {
7285
7668
  BaseTabularStorage
7286
7669
  };
7287
7670
 
7288
- //# debugId=24D8B8B9BAD9862964756E2164756E21
7671
+ //# debugId=10EEBA1FB4F879DB64756E2164756E21