@verdant-web/store 2.7.9 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/bundle/index.js +13 -13
  2. package/dist/bundle/index.js.map +4 -4
  3. package/dist/cjs/entities/DocumentFamiliyCache.d.ts +7 -1
  4. package/dist/cjs/entities/DocumentFamiliyCache.js +5 -1
  5. package/dist/cjs/entities/DocumentFamiliyCache.js.map +1 -1
  6. package/dist/cjs/entities/Entity.d.ts +9 -2
  7. package/dist/cjs/entities/Entity.js +17 -2
  8. package/dist/cjs/entities/Entity.js.map +1 -1
  9. package/dist/cjs/entities/EntityStore.js +3 -3
  10. package/dist/cjs/entities/EntityStore.js.map +1 -1
  11. package/dist/cjs/metadata/BaselinesStore.d.ts +4 -0
  12. package/dist/cjs/metadata/BaselinesStore.js +7 -0
  13. package/dist/cjs/metadata/BaselinesStore.js.map +1 -1
  14. package/dist/cjs/metadata/Metadata.d.ts +1 -0
  15. package/dist/cjs/metadata/Metadata.js +13 -0
  16. package/dist/cjs/metadata/Metadata.js.map +1 -1
  17. package/dist/cjs/metadata/OperationsStore.d.ts +6 -0
  18. package/dist/cjs/metadata/OperationsStore.js +6 -0
  19. package/dist/cjs/metadata/OperationsStore.js.map +1 -1
  20. package/dist/cjs/migration/openDatabase.js +20 -9
  21. package/dist/cjs/migration/openDatabase.js.map +1 -1
  22. package/dist/esm/entities/DocumentFamiliyCache.d.ts +7 -1
  23. package/dist/esm/entities/DocumentFamiliyCache.js +5 -1
  24. package/dist/esm/entities/DocumentFamiliyCache.js.map +1 -1
  25. package/dist/esm/entities/Entity.d.ts +9 -2
  26. package/dist/esm/entities/Entity.js +18 -3
  27. package/dist/esm/entities/Entity.js.map +1 -1
  28. package/dist/esm/entities/EntityStore.js +3 -3
  29. package/dist/esm/entities/EntityStore.js.map +1 -1
  30. package/dist/esm/metadata/BaselinesStore.d.ts +4 -0
  31. package/dist/esm/metadata/BaselinesStore.js +7 -0
  32. package/dist/esm/metadata/BaselinesStore.js.map +1 -1
  33. package/dist/esm/metadata/Metadata.d.ts +1 -0
  34. package/dist/esm/metadata/Metadata.js +13 -0
  35. package/dist/esm/metadata/Metadata.js.map +1 -1
  36. package/dist/esm/metadata/OperationsStore.d.ts +6 -0
  37. package/dist/esm/metadata/OperationsStore.js +6 -0
  38. package/dist/esm/metadata/OperationsStore.js.map +1 -1
  39. package/dist/esm/migration/openDatabase.js +20 -9
  40. package/dist/esm/migration/openDatabase.js.map +1 -1
  41. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/package.json +2 -2
  44. package/src/entities/DocumentFamiliyCache.ts +16 -6
  45. package/src/entities/Entity.ts +26 -6
  46. package/src/entities/EntityStore.ts +3 -3
  47. package/src/metadata/BaselinesStore.ts +35 -12
  48. package/src/metadata/Metadata.ts +26 -0
  49. package/src/metadata/OperationsStore.ts +31 -0
  50. package/src/migration/openDatabase.ts +23 -6
@@ -136,6 +136,37 @@ export class OperationsStore extends IDBService {
136
136
  });
137
137
  };
138
138
 
139
+ iterateOverAllOperationsForCollection = async (
140
+ collection: string,
141
+ iterator: (patch: StoredClientOperation, store: IDBObjectStore) => void,
142
+ {
143
+ after,
144
+ to,
145
+ mode,
146
+ transaction: providedTx,
147
+ }: {
148
+ after?: string;
149
+ to?: string;
150
+ mode?: 'readwrite' | 'readonly';
151
+ transaction?: IDBTransaction;
152
+ },
153
+ ): Promise<void> => {
154
+ const transaction = providedTx || this.db.transaction('operations', mode);
155
+
156
+ return this.iterate(
157
+ 'operations',
158
+ (store) => {
159
+ return store.openCursor(
160
+ IDBKeyRange.bound(collection, collection + '\uffff', false, false),
161
+ 'next',
162
+ );
163
+ },
164
+ iterator,
165
+ mode,
166
+ transaction,
167
+ );
168
+ };
169
+
139
170
  iterateOverAllLocalOperations = async (
140
171
  iterator: (patch: ClientOperation, store: IDBObjectStore) => void,
141
172
  {
@@ -458,15 +458,16 @@ function getMigrationMutations({
458
458
  );
459
459
  return doc;
460
460
  },
461
- delete: (id: string) => {
462
- const oid = createOid(collectionName, id);
463
- return meta.insertLocalOperation([
464
- {
461
+ delete: async (id: string) => {
462
+ const rootOid = createOid(collectionName, id);
463
+ const allOids = await meta.getAllDocumentRelatedOids(rootOid);
464
+ return meta.insertLocalOperation(
465
+ allOids.map((oid) => ({
465
466
  oid,
466
467
  timestamp: getMigrationNow(),
467
468
  data: { op: 'delete' },
468
- },
469
- ]);
469
+ })),
470
+ );
470
471
  },
471
472
  };
472
473
  return acc;
@@ -553,10 +554,21 @@ function getMigrationEngine({
553
554
  newOids,
554
555
  meta,
555
556
  });
557
+ const deleteCollection = async (collection: string) => {
558
+ const allOids = await meta.getAllCollectionRelatedOids(collection);
559
+ return meta.insertLocalOperation(
560
+ allOids.map((oid) => ({
561
+ oid,
562
+ timestamp: getMigrationNow(),
563
+ data: { op: 'delete' },
564
+ })),
565
+ );
566
+ };
556
567
  const awaitables = new Array<Promise<any>>();
557
568
  const engine: MigrationEngine = {
558
569
  log: context.log,
559
570
  newOids,
571
+ deleteCollection,
560
572
  migrate: async (collection, strategy) => {
561
573
  const docs = await queries[collection].findAll();
562
574
 
@@ -632,6 +644,11 @@ function getInitialMigrationEngine({
632
644
  const engine: MigrationEngine = {
633
645
  log: context.log,
634
646
  newOids,
647
+ deleteCollection: () => {
648
+ throw new Error(
649
+ 'Calling deleteCollection() in initial migrations is not supported! Use initial migrations to seed initial data using mutations.',
650
+ );
651
+ },
635
652
  migrate: () => {
636
653
  throw new Error(
637
654
  'Calling migrate() in initial migrations is not supported! Use initial migrations to seed initial data using mutations.',