@workglow/storage 0.0.96 → 0.0.98

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 +396 -33
  2. package/dist/browser.js.map +11 -10
  3. package/dist/bun.js +470 -53
  4. package/dist/bun.js.map +15 -14
  5. package/dist/common.d.ts +1 -0
  6. package/dist/common.d.ts.map +1 -1
  7. package/dist/node.js +470 -53
  8. package/dist/node.js.map +15 -14
  9. package/dist/queue/PostgresQueueStorage.d.ts +1 -1
  10. package/dist/queue/PostgresQueueStorage.d.ts.map +1 -1
  11. package/dist/queue-limiter/PostgresRateLimiterStorage.d.ts +1 -1
  12. package/dist/queue-limiter/PostgresRateLimiterStorage.d.ts.map +1 -1
  13. package/dist/tabular/BaseTabularStorage.d.ts +21 -0
  14. package/dist/tabular/BaseTabularStorage.d.ts.map +1 -1
  15. package/dist/tabular/CachedTabularStorage.d.ts +7 -0
  16. package/dist/tabular/CachedTabularStorage.d.ts.map +1 -1
  17. package/dist/tabular/FsFolderTabularStorage.d.ts +7 -0
  18. package/dist/tabular/FsFolderTabularStorage.d.ts.map +1 -1
  19. package/dist/tabular/HuggingFaceTabularStorage.d.ts +119 -0
  20. package/dist/tabular/HuggingFaceTabularStorage.d.ts.map +1 -0
  21. package/dist/tabular/ITabularStorage.d.ts +19 -3
  22. package/dist/tabular/ITabularStorage.d.ts.map +1 -1
  23. package/dist/tabular/InMemoryTabularStorage.d.ts +7 -0
  24. package/dist/tabular/InMemoryTabularStorage.d.ts.map +1 -1
  25. package/dist/tabular/IndexedDbTabularStorage.d.ts +7 -0
  26. package/dist/tabular/IndexedDbTabularStorage.d.ts.map +1 -1
  27. package/dist/tabular/PostgresTabularStorage.d.ts +7 -0
  28. package/dist/tabular/PostgresTabularStorage.d.ts.map +1 -1
  29. package/dist/tabular/SharedInMemoryTabularStorage.d.ts +7 -0
  30. package/dist/tabular/SharedInMemoryTabularStorage.d.ts.map +1 -1
  31. package/dist/tabular/SqliteTabularStorage.d.ts +7 -0
  32. package/dist/tabular/SqliteTabularStorage.d.ts.map +1 -1
  33. package/dist/tabular/SupabaseTabularStorage.d.ts +7 -0
  34. package/dist/tabular/SupabaseTabularStorage.d.ts.map +1 -1
  35. package/package.json +13 -13
package/dist/node.js CHANGED
@@ -123,6 +123,42 @@ class BaseTabularStorage {
123
123
  waitOn(name) {
124
124
  return this.events.waitOn(name);
125
125
  }
126
+ async* records(pageSize = 100) {
127
+ if (pageSize <= 0) {
128
+ throw new RangeError(`pageSize must be greater than 0, got ${pageSize}`);
129
+ }
130
+ let offset = 0;
131
+ while (true) {
132
+ const page = await this.getBulk(offset, pageSize);
133
+ if (!page || page.length === 0) {
134
+ break;
135
+ }
136
+ for (const entity of page) {
137
+ yield entity;
138
+ }
139
+ if (page.length < pageSize) {
140
+ break;
141
+ }
142
+ offset += pageSize;
143
+ }
144
+ }
145
+ async* pages(pageSize = 100) {
146
+ if (pageSize <= 0) {
147
+ throw new RangeError(`pageSize must be greater than 0, got ${pageSize}`);
148
+ }
149
+ let offset = 0;
150
+ while (true) {
151
+ const page = await this.getBulk(offset, pageSize);
152
+ if (!page || page.length === 0) {
153
+ break;
154
+ }
155
+ yield page;
156
+ if (page.length < pageSize) {
157
+ break;
158
+ }
159
+ offset += pageSize;
160
+ }
161
+ }
126
162
  subscribeToChanges(_callback, _options) {
127
163
  throw new Error(`subscribeToChanges is not implemented for ${this.constructor.name}. ` + `All concrete repository implementations should override this method.`);
128
164
  }
@@ -346,6 +382,22 @@ class InMemoryTabularStorage extends BaseTabularStorage {
346
382
  async size() {
347
383
  return this.values.size;
348
384
  }
385
+ async getBulk(offset, limit) {
386
+ const all = Array.from(this.values.values());
387
+ all.sort((a, b) => {
388
+ for (const key of this.primaryKeyNames) {
389
+ const aVal = a[key];
390
+ const bVal = b[key];
391
+ if (aVal < bVal)
392
+ return -1;
393
+ if (aVal > bVal)
394
+ return 1;
395
+ }
396
+ return 0;
397
+ });
398
+ const page = all.slice(offset, offset + limit);
399
+ return page.length > 0 ? page : undefined;
400
+ }
349
401
  async deleteSearch(criteria) {
350
402
  const criteriaKeys = Object.keys(criteria);
351
403
  if (criteriaKeys.length === 0) {
@@ -531,6 +583,10 @@ class CachedTabularStorage extends BaseTabularStorage {
531
583
  await this.initializeCache();
532
584
  return await this.durable.size();
533
585
  }
586
+ async getBulk(offset, limit) {
587
+ await this.initializeCache();
588
+ return await this.durable.getBulk(offset, limit);
589
+ }
534
590
  async deleteSearch(criteria) {
535
591
  await this.initializeCache();
536
592
  await this.durable.deleteSearch(criteria);
@@ -564,13 +620,262 @@ class CachedTabularStorage extends BaseTabularStorage {
564
620
  this.cache.destroy();
565
621
  }
566
622
  }
623
+ // src/tabular/HuggingFaceTabularStorage.ts
624
+ import {
625
+ createServiceToken as createServiceToken4
626
+ } from "@workglow/util";
627
+ var HF_TABULAR_REPOSITORY = createServiceToken4("storage.tabularRepository.huggingface");
628
+
629
+ class HuggingFaceTabularStorage extends BaseTabularStorage {
630
+ dataset;
631
+ config;
632
+ split;
633
+ token;
634
+ baseUrl;
635
+ constructor(dataset, config, split, schema, primaryKeyNames, options) {
636
+ super(schema, primaryKeyNames, options?.indexes ?? [], "never");
637
+ this.dataset = dataset;
638
+ this.config = config;
639
+ this.split = split;
640
+ this.token = options?.token;
641
+ this.baseUrl = options?.baseUrl ?? "https://datasets-server.huggingface.co";
642
+ }
643
+ static async fromDataset(dataset, config, split, options) {
644
+ const baseUrl = options?.baseUrl ?? "https://datasets-server.huggingface.co";
645
+ const token = options?.token;
646
+ const url = new URL(`${baseUrl}/first-rows`);
647
+ url.searchParams.set("dataset", dataset);
648
+ url.searchParams.set("config", config);
649
+ url.searchParams.set("split", split);
650
+ const headers = {};
651
+ if (token) {
652
+ headers["Authorization"] = `Bearer ${token}`;
653
+ }
654
+ const response = await fetch(url.toString(), { headers });
655
+ if (!response.ok) {
656
+ throw new Error(`Failed to fetch dataset features: ${response.status} ${response.statusText}`);
657
+ }
658
+ const data = await response.json();
659
+ const properties = {};
660
+ const required = [];
661
+ properties["row_idx"] = { type: "integer", "x-auto-generated": true };
662
+ required.push("row_idx");
663
+ for (const feature of data.features) {
664
+ const jsonSchema = hfFeatureToJsonSchema(feature.type);
665
+ properties[feature.name] = jsonSchema;
666
+ required.push(feature.name);
667
+ }
668
+ const schema = {
669
+ type: "object",
670
+ properties,
671
+ required,
672
+ additionalProperties: false
673
+ };
674
+ return new HuggingFaceTabularStorage(dataset, config, split, schema, ["row_idx"], options);
675
+ }
676
+ async setupDatabase() {
677
+ const data = await this.fetchApi("/first-rows", {});
678
+ const schemaColumns = Object.keys(this.schema.properties);
679
+ const hfColumns = data.features.map((f) => f.name);
680
+ const hasRowIdx = schemaColumns.includes("row_idx");
681
+ if (!hasRowIdx) {
682
+ for (const column of schemaColumns) {
683
+ if (!hfColumns.includes(column) && !this.primaryKeyNames.includes(column)) {
684
+ throw new Error(`Schema column "${column}" not found in HuggingFace dataset features`);
685
+ }
686
+ }
687
+ }
688
+ }
689
+ async get(key) {
690
+ const keyObj = this.separateKeyValueFromCombined({ ...key }).key;
691
+ const whereConditions = [];
692
+ for (const [k, v] of Object.entries(keyObj)) {
693
+ if (typeof v === "string") {
694
+ const escaped = v.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
695
+ whereConditions.push(`${k}='${escaped}'`);
696
+ } else {
697
+ whereConditions.push(`${k}=${v}`);
698
+ }
699
+ }
700
+ const where = whereConditions.join(" AND ");
701
+ const data = await this.fetchApi("/filter", { where, limit: "1" });
702
+ if (data.rows.length > 0) {
703
+ const entity = this.rowToEntity(data.rows[0]);
704
+ this.events.emit("get", key, entity);
705
+ return entity;
706
+ }
707
+ this.events.emit("get", key, undefined);
708
+ return;
709
+ }
710
+ async getAll() {
711
+ const allEntities = [];
712
+ let offset = 0;
713
+ const pageSize = 100;
714
+ while (true) {
715
+ const page = await this.getBulk(offset, pageSize);
716
+ if (!page || page.length === 0) {
717
+ break;
718
+ }
719
+ allEntities.push(...page);
720
+ offset += page.length;
721
+ if (page.length < pageSize) {
722
+ break;
723
+ }
724
+ }
725
+ return allEntities.length > 0 ? allEntities : undefined;
726
+ }
727
+ async getBulk(offset, limit) {
728
+ const data = await this.fetchApi("/rows", {
729
+ offset: offset.toString(),
730
+ length: Math.min(limit, 100).toString()
731
+ });
732
+ if (data.rows.length === 0) {
733
+ return;
734
+ }
735
+ const entities = [];
736
+ for (const row of data.rows) {
737
+ entities.push(this.rowToEntity(row));
738
+ }
739
+ return entities;
740
+ }
741
+ async search(key) {
742
+ const searchKeys = Object.keys(key);
743
+ if (searchKeys.length === 0) {
744
+ return;
745
+ }
746
+ const bestIndex = this.findBestMatchingIndex(searchKeys);
747
+ if (!bestIndex) {
748
+ 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("', '")}'`);
749
+ }
750
+ const whereConditions = [];
751
+ for (const [k, v] of Object.entries(key)) {
752
+ if (v !== undefined && v !== null) {
753
+ if (typeof v === "string") {
754
+ const escaped = v.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
755
+ whereConditions.push(`${k}='${escaped}'`);
756
+ } else {
757
+ whereConditions.push(`${k}=${v}`);
758
+ }
759
+ }
760
+ }
761
+ if (whereConditions.length === 0) {
762
+ throw new Error("Search criteria must include at least one non-null and non-undefined value to build a valid WHERE clause.");
763
+ }
764
+ const where = whereConditions.join(" AND ");
765
+ const allEntities = [];
766
+ let offset = 0;
767
+ const limit = 100;
768
+ while (true) {
769
+ const data = await this.fetchApi("/filter", {
770
+ where,
771
+ offset: offset.toString(),
772
+ limit: limit.toString()
773
+ });
774
+ for (const row of data.rows) {
775
+ allEntities.push(this.rowToEntity(row));
776
+ }
777
+ offset += data.rows.length;
778
+ if (offset >= data.num_rows_total || data.rows.length < limit) {
779
+ break;
780
+ }
781
+ }
782
+ if (allEntities.length > 0) {
783
+ this.events.emit("search", key, allEntities);
784
+ return allEntities;
785
+ } else {
786
+ this.events.emit("search", key, undefined);
787
+ return;
788
+ }
789
+ }
790
+ async size() {
791
+ const data = await this.fetchApi("/size", {});
792
+ return data.size.num_rows;
793
+ }
794
+ async put(_value) {
795
+ throw new Error("HuggingFaceTabularStorage is readonly");
796
+ }
797
+ async putBulk(_values) {
798
+ throw new Error("HuggingFaceTabularStorage is readonly");
799
+ }
800
+ async delete(_value) {
801
+ throw new Error("HuggingFaceTabularStorage is readonly");
802
+ }
803
+ async deleteAll() {
804
+ throw new Error("HuggingFaceTabularStorage is readonly");
805
+ }
806
+ async deleteSearch(_criteria) {
807
+ throw new Error("HuggingFaceTabularStorage is readonly");
808
+ }
809
+ subscribeToChanges(_callback, _options) {
810
+ throw new Error("HuggingFaceTabularStorage does not support subscriptions");
811
+ }
812
+ destroy() {}
813
+ async fetchApi(endpoint, params) {
814
+ const url = new URL(`${this.baseUrl}${endpoint}`);
815
+ url.searchParams.set("dataset", this.dataset);
816
+ url.searchParams.set("config", this.config);
817
+ url.searchParams.set("split", this.split);
818
+ for (const [key, value] of Object.entries(params)) {
819
+ if (value !== undefined) {
820
+ url.searchParams.set(key, value);
821
+ }
822
+ }
823
+ const headers = {};
824
+ if (this.token) {
825
+ headers["Authorization"] = `Bearer ${this.token}`;
826
+ }
827
+ const response = await fetch(url.toString(), { headers });
828
+ if (!response.ok) {
829
+ throw new Error(`HuggingFace API error: ${response.status} ${response.statusText}`);
830
+ }
831
+ return await response.json();
832
+ }
833
+ rowToEntity(row) {
834
+ return { row_idx: row.row_idx, ...row.row };
835
+ }
836
+ }
837
+ function hfFeatureToJsonSchema(feature) {
838
+ if (feature._type === "Value") {
839
+ switch (feature.dtype) {
840
+ case "string":
841
+ return { type: "string" };
842
+ case "int64":
843
+ case "int32":
844
+ case "int16":
845
+ case "int8":
846
+ case "uint64":
847
+ case "uint32":
848
+ case "uint16":
849
+ case "uint8":
850
+ return { type: "integer" };
851
+ case "float64":
852
+ case "float32":
853
+ case "float16":
854
+ return { type: "number" };
855
+ case "bool":
856
+ return { type: "boolean" };
857
+ default:
858
+ return {};
859
+ }
860
+ }
861
+ if (feature._type === "ClassLabel") {
862
+ return { type: "integer" };
863
+ }
864
+ if (feature._type === "Sequence") {
865
+ return {
866
+ type: "array",
867
+ items: hfFeatureToJsonSchema(feature.feature)
868
+ };
869
+ }
870
+ return {};
871
+ }
567
872
  // src/tabular/TabularStorageRegistry.ts
568
873
  import {
569
- createServiceToken as createServiceToken4,
874
+ createServiceToken as createServiceToken5,
570
875
  globalServiceRegistry,
571
876
  registerInputResolver
572
877
  } from "@workglow/util";
573
- var TABULAR_REPOSITORIES = createServiceToken4("storage.tabular.repositories");
878
+ var TABULAR_REPOSITORIES = createServiceToken5("storage.tabular.repositories");
574
879
  if (!globalServiceRegistry.has(TABULAR_REPOSITORIES)) {
575
880
  globalServiceRegistry.register(TABULAR_REPOSITORIES, () => new Map, true);
576
881
  }
@@ -604,11 +909,11 @@ var DefaultKeyValueSchema = {
604
909
  };
605
910
  var DefaultKeyValueKey = ["key"];
606
911
  // src/kv/InMemoryKvStorage.ts
607
- import { createServiceToken as createServiceToken6 } from "@workglow/util";
912
+ import { createServiceToken as createServiceToken7 } from "@workglow/util";
608
913
 
609
914
  // src/kv/KvStorage.ts
610
- import { createServiceToken as createServiceToken5, EventEmitter as EventEmitter2, makeFingerprint as makeFingerprint3 } from "@workglow/util";
611
- var KV_REPOSITORY = createServiceToken5("storage.kvRepository");
915
+ import { createServiceToken as createServiceToken6, EventEmitter as EventEmitter2, makeFingerprint as makeFingerprint3 } from "@workglow/util";
916
+ var KV_REPOSITORY = createServiceToken6("storage.kvRepository");
612
917
 
613
918
  class KvStorage {
614
919
  keySchema;
@@ -715,7 +1020,7 @@ class KvViaTabularStorage extends KvStorage {
715
1020
  }
716
1021
 
717
1022
  // src/kv/InMemoryKvStorage.ts
718
- var MEMORY_KV_REPOSITORY = createServiceToken6("storage.kvRepository.inMemory");
1023
+ var MEMORY_KV_REPOSITORY = createServiceToken7("storage.kvRepository.inMemory");
719
1024
 
720
1025
  class InMemoryKvStorage extends KvViaTabularStorage {
721
1026
  tabularRepository;
@@ -725,11 +1030,11 @@ class InMemoryKvStorage extends KvViaTabularStorage {
725
1030
  }
726
1031
  }
727
1032
  // src/queue/InMemoryQueueStorage.ts
728
- import { createServiceToken as createServiceToken8, EventEmitter as EventEmitter3, makeFingerprint as makeFingerprint4, sleep, uuid4 as uuid42 } from "@workglow/util";
1033
+ import { createServiceToken as createServiceToken9, EventEmitter as EventEmitter3, makeFingerprint as makeFingerprint4, sleep, uuid4 as uuid42 } from "@workglow/util";
729
1034
 
730
1035
  // src/queue/IQueueStorage.ts
731
- import { createServiceToken as createServiceToken7 } from "@workglow/util";
732
- var QUEUE_STORAGE = createServiceToken7("jobqueue.storage");
1036
+ import { createServiceToken as createServiceToken8 } from "@workglow/util";
1037
+ var QUEUE_STORAGE = createServiceToken8("jobqueue.storage");
733
1038
  var JobStatus = {
734
1039
  PENDING: "PENDING",
735
1040
  PROCESSING: "PROCESSING",
@@ -740,7 +1045,7 @@ var JobStatus = {
740
1045
  };
741
1046
 
742
1047
  // src/queue/InMemoryQueueStorage.ts
743
- var IN_MEMORY_QUEUE_STORAGE = createServiceToken8("jobqueue.storage.inMemory");
1048
+ var IN_MEMORY_QUEUE_STORAGE = createServiceToken9("jobqueue.storage.inMemory");
744
1049
 
745
1050
  class InMemoryQueueStorage {
746
1051
  queueName;
@@ -917,8 +1222,8 @@ class InMemoryQueueStorage {
917
1222
  }
918
1223
  }
919
1224
  // src/queue-limiter/InMemoryRateLimiterStorage.ts
920
- import { createServiceToken as createServiceToken9, sleep as sleep2 } from "@workglow/util";
921
- var IN_MEMORY_RATE_LIMITER_STORAGE = createServiceToken9("ratelimiter.storage.inMemory");
1225
+ import { createServiceToken as createServiceToken10, sleep as sleep2 } from "@workglow/util";
1226
+ var IN_MEMORY_RATE_LIMITER_STORAGE = createServiceToken10("ratelimiter.storage.inMemory");
922
1227
 
923
1228
  class InMemoryRateLimiterStorage {
924
1229
  prefixValues;
@@ -976,8 +1281,8 @@ class InMemoryRateLimiterStorage {
976
1281
  }
977
1282
  }
978
1283
  // src/queue-limiter/IRateLimiterStorage.ts
979
- import { createServiceToken as createServiceToken10 } from "@workglow/util";
980
- var RATE_LIMITER_STORAGE = createServiceToken10("ratelimiter.storage");
1284
+ import { createServiceToken as createServiceToken11 } from "@workglow/util";
1285
+ var RATE_LIMITER_STORAGE = createServiceToken11("ratelimiter.storage");
981
1286
  // src/util/HybridSubscriptionManager.ts
982
1287
  class HybridSubscriptionManager {
983
1288
  subscribers = new Set;
@@ -1371,14 +1676,14 @@ class InMemoryVectorStorage extends InMemoryTabularStorage {
1371
1676
  }
1372
1677
  // src/tabular/FsFolderTabularStorage.ts
1373
1678
  import {
1374
- createServiceToken as createServiceToken11,
1679
+ createServiceToken as createServiceToken12,
1375
1680
  makeFingerprint as makeFingerprint5,
1376
1681
  sleep as sleep3,
1377
1682
  uuid4 as uuid43
1378
1683
  } from "@workglow/util";
1379
1684
  import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
1380
1685
  import path from "node:path";
1381
- var FS_FOLDER_TABULAR_REPOSITORY = createServiceToken11("storage.tabularRepository.fsFolder");
1686
+ var FS_FOLDER_TABULAR_REPOSITORY = createServiceToken12("storage.tabularRepository.fsFolder");
1382
1687
 
1383
1688
  class FsFolderTabularStorage extends BaseTabularStorage {
1384
1689
  folderPath;
@@ -1503,6 +1808,32 @@ class FsFolderTabularStorage extends BaseTabularStorage {
1503
1808
  const jsonFiles = files.filter((file) => file.endsWith(".json"));
1504
1809
  return jsonFiles.length;
1505
1810
  }
1811
+ async getBulk(offset, limit) {
1812
+ await this.setupDirectory();
1813
+ const files = await readdir(this.folderPath);
1814
+ const jsonFiles = files.filter((file) => file.endsWith(".json"));
1815
+ if (jsonFiles.length === 0) {
1816
+ return;
1817
+ }
1818
+ const allEntities = await Promise.all(jsonFiles.map(async (file) => {
1819
+ const filePath = path.join(this.folderPath, file);
1820
+ const content = await readFile(filePath, "utf8");
1821
+ return JSON.parse(content);
1822
+ }));
1823
+ allEntities.sort((a, b) => {
1824
+ for (const key of this.primaryKeyNames) {
1825
+ const aVal = a[key];
1826
+ const bVal = b[key];
1827
+ if (aVal < bVal)
1828
+ return -1;
1829
+ if (aVal > bVal)
1830
+ return 1;
1831
+ }
1832
+ return 0;
1833
+ });
1834
+ const page = allEntities.slice(offset, offset + limit);
1835
+ return page.length > 0 ? page : undefined;
1836
+ }
1506
1837
  async search(key) {
1507
1838
  throw new Error("Search not supported for FsFolderTabularStorage");
1508
1839
  }
@@ -1549,7 +1880,7 @@ class FsFolderTabularStorage extends BaseTabularStorage {
1549
1880
  }
1550
1881
  // src/tabular/PostgresTabularStorage.ts
1551
1882
  import {
1552
- createServiceToken as createServiceToken12
1883
+ createServiceToken as createServiceToken13
1553
1884
  } from "@workglow/util";
1554
1885
 
1555
1886
  // src/tabular/BaseSqlTabularStorage.ts
@@ -1736,7 +2067,7 @@ class BaseSqlTabularStorage extends BaseTabularStorage {
1736
2067
  }
1737
2068
 
1738
2069
  // src/tabular/PostgresTabularStorage.ts
1739
- var POSTGRES_TABULAR_REPOSITORY = createServiceToken12("storage.tabularRepository.postgres");
2070
+ var POSTGRES_TABULAR_REPOSITORY = createServiceToken13("storage.tabularRepository.postgres");
1740
2071
 
1741
2072
  class PostgresTabularStorage extends BaseSqlTabularStorage {
1742
2073
  db;
@@ -2163,6 +2494,20 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
2163
2494
  const result = await db.query(`SELECT COUNT(*) FROM "${this.table}"`);
2164
2495
  return parseInt(result.rows[0].count, 10);
2165
2496
  }
2497
+ async getBulk(offset, limit) {
2498
+ const db = this.db;
2499
+ const orderByClause = this.primaryKeyColumns().map((col) => `"${String(col)}"`).join(", ");
2500
+ const result = await db.query(`SELECT * FROM "${this.table}" ORDER BY ${orderByClause} LIMIT $1 OFFSET $2`, [limit, offset]);
2501
+ if (!result.rows || result.rows.length === 0) {
2502
+ return;
2503
+ }
2504
+ for (const row of result.rows) {
2505
+ for (const key in this.schema.properties) {
2506
+ row[key] = this.sqlToJsValue(key, row[key]);
2507
+ }
2508
+ }
2509
+ return result.rows;
2510
+ }
2166
2511
  buildDeleteSearchWhere(criteria) {
2167
2512
  const conditions = [];
2168
2513
  const params = [];
@@ -2209,10 +2554,10 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
2209
2554
  // src/tabular/SqliteTabularStorage.ts
2210
2555
  import { Sqlite } from "@workglow/sqlite";
2211
2556
  import {
2212
- createServiceToken as createServiceToken13,
2557
+ createServiceToken as createServiceToken14,
2213
2558
  uuid4 as uuid44
2214
2559
  } from "@workglow/util";
2215
- var SQLITE_TABULAR_REPOSITORY = createServiceToken13("storage.tabularRepository.sqlite");
2560
+ var SQLITE_TABULAR_REPOSITORY = createServiceToken14("storage.tabularRepository.sqlite");
2216
2561
  var Database = Sqlite.Database;
2217
2562
 
2218
2563
  class SqliteTabularStorage extends BaseSqlTabularStorage {
@@ -2595,6 +2940,23 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2595
2940
  `);
2596
2941
  return stmt.get()?.count || 0;
2597
2942
  }
2943
+ async getBulk(offset, limit) {
2944
+ const db = this.db;
2945
+ const orderByClause = this.primaryKeyColumns().map((col) => `\`${String(col)}\``).join(", ");
2946
+ const stmt = db.prepare(`
2947
+ SELECT * FROM \`${this.table}\` ORDER BY ${orderByClause} LIMIT ? OFFSET ?
2948
+ `);
2949
+ const rows = stmt.all(limit, offset);
2950
+ if (!rows || rows.length === 0) {
2951
+ return;
2952
+ }
2953
+ for (const row of rows) {
2954
+ for (const k in this.schema.properties) {
2955
+ row[k] = this.sqlToJsValue(k, row[k]);
2956
+ }
2957
+ }
2958
+ return rows;
2959
+ }
2598
2960
  buildDeleteSearchWhere(criteria) {
2599
2961
  const conditions = [];
2600
2962
  const params = [];
@@ -2639,9 +3001,9 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2639
3001
  }
2640
3002
  // src/tabular/SupabaseTabularStorage.ts
2641
3003
  import {
2642
- createServiceToken as createServiceToken14
3004
+ createServiceToken as createServiceToken15
2643
3005
  } from "@workglow/util";
2644
- var SUPABASE_TABULAR_REPOSITORY = createServiceToken14("storage.tabularRepository.supabase");
3006
+ var SUPABASE_TABULAR_REPOSITORY = createServiceToken15("storage.tabularRepository.supabase");
2645
3007
 
2646
3008
  class SupabaseTabularStorage extends BaseSqlTabularStorage {
2647
3009
  client;
@@ -2982,6 +3344,24 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
2982
3344
  throw error;
2983
3345
  return count ?? 0;
2984
3346
  }
3347
+ async getBulk(offset, limit) {
3348
+ let query = this.client.from(this.table).select("*");
3349
+ for (const pkName of this.primaryKeyNames) {
3350
+ query = query.order(String(pkName));
3351
+ }
3352
+ const { data, error } = await query.range(offset, offset + limit - 1);
3353
+ if (error)
3354
+ throw error;
3355
+ if (!data || data.length === 0) {
3356
+ return;
3357
+ }
3358
+ for (const row of data) {
3359
+ for (const key in this.schema.properties) {
3360
+ row[key] = this.sqlToJsValue(key, row[key]);
3361
+ }
3362
+ }
3363
+ return data;
3364
+ }
2985
3365
  async deleteSearch(criteria) {
2986
3366
  const criteriaKeys = Object.keys(criteria);
2987
3367
  if (criteriaKeys.length === 0) {
@@ -3060,8 +3440,8 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3060
3440
  }
3061
3441
  }
3062
3442
  // src/kv/FsFolderJsonKvStorage.ts
3063
- import { createServiceToken as createServiceToken15 } from "@workglow/util";
3064
- var FS_FOLDER_JSON_KV_REPOSITORY = createServiceToken15("storage.kvRepository.fsFolderJson");
3443
+ import { createServiceToken as createServiceToken16 } from "@workglow/util";
3444
+ var FS_FOLDER_JSON_KV_REPOSITORY = createServiceToken16("storage.kvRepository.fsFolderJson");
3065
3445
 
3066
3446
  class FsFolderJsonKvStorage extends KvViaTabularStorage {
3067
3447
  folderPath;
@@ -3073,10 +3453,10 @@ class FsFolderJsonKvStorage extends KvViaTabularStorage {
3073
3453
  }
3074
3454
  }
3075
3455
  // src/kv/FsFolderKvStorage.ts
3076
- import { createServiceToken as createServiceToken16 } from "@workglow/util";
3456
+ import { createServiceToken as createServiceToken17 } from "@workglow/util";
3077
3457
  import { mkdir as mkdir2, readFile as readFile2, rm as rm2, unlink, writeFile as writeFile2 } from "fs/promises";
3078
3458
  import path2 from "path";
3079
- var FS_FOLDER_KV_REPOSITORY = createServiceToken16("storage.kvRepository.fsFolder");
3459
+ var FS_FOLDER_KV_REPOSITORY = createServiceToken17("storage.kvRepository.fsFolder");
3080
3460
 
3081
3461
  class FsFolderKvStorage extends KvStorage {
3082
3462
  folderPath;
@@ -3153,8 +3533,8 @@ class FsFolderKvStorage extends KvStorage {
3153
3533
  }
3154
3534
  }
3155
3535
  // src/kv/PostgresKvStorage.ts
3156
- import { createServiceToken as createServiceToken17 } from "@workglow/util";
3157
- var POSTGRES_KV_REPOSITORY = createServiceToken17("storage.kvRepository.postgres");
3536
+ import { createServiceToken as createServiceToken18 } from "@workglow/util";
3537
+ var POSTGRES_KV_REPOSITORY = createServiceToken18("storage.kvRepository.postgres");
3158
3538
 
3159
3539
  class PostgresKvStorage extends KvViaTabularStorage {
3160
3540
  db;
@@ -3168,8 +3548,8 @@ class PostgresKvStorage extends KvViaTabularStorage {
3168
3548
  }
3169
3549
  }
3170
3550
  // src/kv/SqliteKvStorage.ts
3171
- import { createServiceToken as createServiceToken18 } from "@workglow/util";
3172
- var SQLITE_KV_REPOSITORY = createServiceToken18("storage.kvRepository.sqlite");
3551
+ import { createServiceToken as createServiceToken19 } from "@workglow/util";
3552
+ var SQLITE_KV_REPOSITORY = createServiceToken19("storage.kvRepository.sqlite");
3173
3553
 
3174
3554
  class SqliteKvStorage extends KvViaTabularStorage {
3175
3555
  db;
@@ -3183,8 +3563,8 @@ class SqliteKvStorage extends KvViaTabularStorage {
3183
3563
  }
3184
3564
  }
3185
3565
  // src/kv/SupabaseKvStorage.ts
3186
- import { createServiceToken as createServiceToken19 } from "@workglow/util";
3187
- var SUPABASE_KV_REPOSITORY = createServiceToken19("storage.kvRepository.supabase");
3566
+ import { createServiceToken as createServiceToken20 } from "@workglow/util";
3567
+ var SUPABASE_KV_REPOSITORY = createServiceToken20("storage.kvRepository.supabase");
3188
3568
 
3189
3569
  class SupabaseKvStorage extends KvViaTabularStorage {
3190
3570
  client;
@@ -3198,8 +3578,8 @@ class SupabaseKvStorage extends KvViaTabularStorage {
3198
3578
  }
3199
3579
  }
3200
3580
  // src/queue/PostgresQueueStorage.ts
3201
- import { createServiceToken as createServiceToken20, makeFingerprint as makeFingerprint6, uuid4 as uuid45 } from "@workglow/util";
3202
- var POSTGRES_QUEUE_STORAGE = createServiceToken20("jobqueue.storage.postgres");
3581
+ import { createServiceToken as createServiceToken21, makeFingerprint as makeFingerprint6, uuid4 as uuid45 } from "@workglow/util";
3582
+ var POSTGRES_QUEUE_STORAGE = createServiceToken21("jobqueue.storage.postgres");
3203
3583
 
3204
3584
  class PostgresQueueStorage {
3205
3585
  db;
@@ -3528,8 +3908,8 @@ class PostgresQueueStorage {
3528
3908
  }
3529
3909
  }
3530
3910
  // src/queue/SqliteQueueStorage.ts
3531
- import { createServiceToken as createServiceToken21, makeFingerprint as makeFingerprint7, sleep as sleep4, uuid4 as uuid46 } from "@workglow/util";
3532
- var SQLITE_QUEUE_STORAGE = createServiceToken21("jobqueue.storage.sqlite");
3911
+ import { createServiceToken as createServiceToken22, makeFingerprint as makeFingerprint7, sleep as sleep4, uuid4 as uuid46 } from "@workglow/util";
3912
+ var SQLITE_QUEUE_STORAGE = createServiceToken22("jobqueue.storage.sqlite");
3533
3913
 
3534
3914
  class SqliteQueueStorage {
3535
3915
  db;
@@ -3864,8 +4244,8 @@ class SqliteQueueStorage {
3864
4244
  }
3865
4245
  }
3866
4246
  // src/queue/SupabaseQueueStorage.ts
3867
- import { createServiceToken as createServiceToken22, makeFingerprint as makeFingerprint8, uuid4 as uuid47 } from "@workglow/util";
3868
- var SUPABASE_QUEUE_STORAGE = createServiceToken22("jobqueue.storage.supabase");
4247
+ import { createServiceToken as createServiceToken23, makeFingerprint as makeFingerprint8, uuid4 as uuid47 } from "@workglow/util";
4248
+ var SUPABASE_QUEUE_STORAGE = createServiceToken23("jobqueue.storage.supabase");
3869
4249
 
3870
4250
  class SupabaseQueueStorage {
3871
4251
  client;
@@ -4364,8 +4744,8 @@ class SupabaseQueueStorage {
4364
4744
  }
4365
4745
  }
4366
4746
  // src/queue-limiter/PostgresRateLimiterStorage.ts
4367
- import { createServiceToken as createServiceToken23 } from "@workglow/util";
4368
- var POSTGRES_RATE_LIMITER_STORAGE = createServiceToken23("ratelimiter.storage.postgres");
4747
+ import { createServiceToken as createServiceToken24 } from "@workglow/util";
4748
+ var POSTGRES_RATE_LIMITER_STORAGE = createServiceToken24("ratelimiter.storage.postgres");
4369
4749
 
4370
4750
  class PostgresRateLimiterStorage {
4371
4751
  db;
@@ -4502,8 +4882,8 @@ class PostgresRateLimiterStorage {
4502
4882
  }
4503
4883
  }
4504
4884
  // src/queue-limiter/SqliteRateLimiterStorage.ts
4505
- import { createServiceToken as createServiceToken24, sleep as sleep5, toSQLiteTimestamp } from "@workglow/util";
4506
- var SQLITE_RATE_LIMITER_STORAGE = createServiceToken24("ratelimiter.storage.sqlite");
4885
+ import { createServiceToken as createServiceToken25, sleep as sleep5, toSQLiteTimestamp } from "@workglow/util";
4886
+ var SQLITE_RATE_LIMITER_STORAGE = createServiceToken25("ratelimiter.storage.sqlite");
4507
4887
 
4508
4888
  class SqliteRateLimiterStorage {
4509
4889
  db;
@@ -4641,8 +5021,8 @@ class SqliteRateLimiterStorage {
4641
5021
  }
4642
5022
  }
4643
5023
  // src/queue-limiter/SupabaseRateLimiterStorage.ts
4644
- import { createServiceToken as createServiceToken25 } from "@workglow/util";
4645
- var SUPABASE_RATE_LIMITER_STORAGE = createServiceToken25("ratelimiter.storage.supabase");
5024
+ import { createServiceToken as createServiceToken26 } from "@workglow/util";
5025
+ var SUPABASE_RATE_LIMITER_STORAGE = createServiceToken26("ratelimiter.storage.supabase");
4646
5026
 
4647
5027
  class SupabaseRateLimiterStorage {
4648
5028
  client;
@@ -5091,11 +5471,11 @@ class SqliteVectorStorage extends SqliteTabularStorage {
5091
5471
  }
5092
5472
  }
5093
5473
  // src/kv/IndexedDbKvStorage.ts
5094
- import { createServiceToken as createServiceToken27 } from "@workglow/util";
5474
+ import { createServiceToken as createServiceToken28 } from "@workglow/util";
5095
5475
 
5096
5476
  // src/tabular/IndexedDbTabularStorage.ts
5097
5477
  import {
5098
- createServiceToken as createServiceToken26,
5478
+ createServiceToken as createServiceToken27,
5099
5479
  makeFingerprint as makeFingerprint9,
5100
5480
  uuid4 as uuid48
5101
5481
  } from "@workglow/util";
@@ -5438,7 +5818,7 @@ async function dropIndexedDbTable(tableName) {
5438
5818
  }
5439
5819
 
5440
5820
  // src/tabular/IndexedDbTabularStorage.ts
5441
- var IDB_TABULAR_REPOSITORY = createServiceToken26("storage.tabularRepository.indexedDb");
5821
+ var IDB_TABULAR_REPOSITORY = createServiceToken27("storage.tabularRepository.indexedDb");
5442
5822
 
5443
5823
  class IndexedDbTabularStorage extends BaseTabularStorage {
5444
5824
  table;
@@ -5729,6 +6109,41 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
5729
6109
  request.onsuccess = () => resolve(request.result);
5730
6110
  });
5731
6111
  }
6112
+ async getBulk(offset, limit) {
6113
+ if (offset < 0) {
6114
+ throw new RangeError(`offset must be non-negative, got ${offset}`);
6115
+ }
6116
+ if (limit <= 0) {
6117
+ return;
6118
+ }
6119
+ const db = await this.getDb();
6120
+ return new Promise((resolve, reject) => {
6121
+ const transaction = db.transaction(this.table, "readonly");
6122
+ const store = transaction.objectStore(this.table);
6123
+ const request = store.openCursor();
6124
+ const entities = [];
6125
+ let skipped = false;
6126
+ request.onerror = () => reject(request.error);
6127
+ request.onsuccess = () => {
6128
+ const cursor = request.result;
6129
+ if (cursor) {
6130
+ if (!skipped && offset > 0) {
6131
+ skipped = true;
6132
+ cursor.advance(offset);
6133
+ return;
6134
+ }
6135
+ entities.push(cursor.value);
6136
+ if (entities.length === limit) {
6137
+ resolve(entities);
6138
+ return;
6139
+ }
6140
+ cursor.continue();
6141
+ } else {
6142
+ resolve(entities.length > 0 ? entities : undefined);
6143
+ }
6144
+ };
6145
+ });
6146
+ }
5732
6147
  matchesCriteria(record, criteria) {
5733
6148
  for (const column of Object.keys(criteria)) {
5734
6149
  const criterion = criteria[column];
@@ -5854,7 +6269,7 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
5854
6269
  }
5855
6270
 
5856
6271
  // src/kv/IndexedDbKvStorage.ts
5857
- var IDB_KV_REPOSITORY = createServiceToken27("storage.kvRepository.indexedDb");
6272
+ var IDB_KV_REPOSITORY = createServiceToken28("storage.kvRepository.indexedDb");
5858
6273
 
5859
6274
  class IndexedDbKvStorage extends KvViaTabularStorage {
5860
6275
  dbName;
@@ -5866,8 +6281,8 @@ class IndexedDbKvStorage extends KvViaTabularStorage {
5866
6281
  }
5867
6282
  }
5868
6283
  // src/queue-limiter/IndexedDbRateLimiterStorage.ts
5869
- import { createServiceToken as createServiceToken28 } from "@workglow/util";
5870
- var INDEXED_DB_RATE_LIMITER_STORAGE = createServiceToken28("ratelimiter.storage.indexedDb");
6284
+ import { createServiceToken as createServiceToken29 } from "@workglow/util";
6285
+ var INDEXED_DB_RATE_LIMITER_STORAGE = createServiceToken29("ratelimiter.storage.indexedDb");
5871
6286
 
5872
6287
  class IndexedDbRateLimiterStorage {
5873
6288
  executionDb;
@@ -6087,8 +6502,8 @@ class IndexedDbRateLimiterStorage {
6087
6502
  }
6088
6503
  }
6089
6504
  // src/queue/IndexedDbQueueStorage.ts
6090
- import { createServiceToken as createServiceToken29, makeFingerprint as makeFingerprint10, uuid4 as uuid49 } from "@workglow/util";
6091
- var INDEXED_DB_QUEUE_STORAGE = createServiceToken29("jobqueue.storage.indexedDb");
6505
+ import { createServiceToken as createServiceToken30, makeFingerprint as makeFingerprint10, uuid4 as uuid49 } from "@workglow/util";
6506
+ var INDEXED_DB_QUEUE_STORAGE = createServiceToken30("jobqueue.storage.indexedDb");
6092
6507
 
6093
6508
  class IndexedDbQueueStorage {
6094
6509
  queueName;
@@ -6717,6 +7132,8 @@ export {
6717
7132
  IDB_TABULAR_REPOSITORY,
6718
7133
  IDB_KV_REPOSITORY,
6719
7134
  HybridSubscriptionManager,
7135
+ HuggingFaceTabularStorage,
7136
+ HF_TABULAR_REPOSITORY,
6720
7137
  FsFolderTabularStorage,
6721
7138
  FsFolderKvStorage,
6722
7139
  FsFolderJsonKvStorage,
@@ -6730,4 +7147,4 @@ export {
6730
7147
  BaseTabularStorage
6731
7148
  };
6732
7149
 
6733
- //# debugId=CDE752B27E94EEDB64756E2164756E21
7150
+ //# debugId=C74BA1BBB43EDF7664756E2164756E21