@verdant-web/store 4.1.6 → 4.3.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 (46) hide show
  1. package/dist/bundle/index.js +9 -7
  2. package/dist/bundle/index.js.map +4 -4
  3. package/dist/esm/UndoHistory.d.ts +2 -0
  4. package/dist/esm/UndoHistory.js +6 -0
  5. package/dist/esm/UndoHistory.js.map +1 -1
  6. package/dist/esm/__tests__/entities.test.js +143 -5
  7. package/dist/esm/__tests__/entities.test.js.map +1 -1
  8. package/dist/esm/__tests__/fixtures/testStorage.d.ts +1 -0
  9. package/dist/esm/__tests__/fixtures/testStorage.js +1 -1
  10. package/dist/esm/__tests__/fixtures/testStorage.js.map +1 -1
  11. package/dist/esm/client/Client.js +1 -0
  12. package/dist/esm/client/Client.js.map +1 -1
  13. package/dist/esm/client/ClientDescriptor.js +4 -1
  14. package/dist/esm/client/ClientDescriptor.js.map +1 -1
  15. package/dist/esm/context/context.d.ts +6 -0
  16. package/dist/esm/entities/Entity.d.ts +22 -2
  17. package/dist/esm/entities/Entity.js +127 -5
  18. package/dist/esm/entities/Entity.js.map +1 -1
  19. package/dist/esm/entities/EntityCache.d.ts +1 -1
  20. package/dist/esm/entities/EntityMetadata.d.ts +2 -2
  21. package/dist/esm/entities/EntityMetadata.js.map +1 -1
  22. package/dist/esm/entities/EntityStore.d.ts +4 -4
  23. package/dist/esm/entities/EntityStore.js +4 -9
  24. package/dist/esm/entities/EntityStore.js.map +1 -1
  25. package/dist/esm/entities/OperationBatcher.d.ts +1 -1
  26. package/dist/esm/entities/OperationBatcher.js +2 -0
  27. package/dist/esm/entities/OperationBatcher.js.map +1 -1
  28. package/dist/esm/index.d.ts +16 -19
  29. package/dist/esm/index.js +10 -12
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/persistence/migration/engine.d.ts +1 -1
  32. package/dist/esm/persistence/migration/engine.js +7 -0
  33. package/dist/esm/persistence/migration/engine.js.map +1 -1
  34. package/package.json +2 -2
  35. package/src/UndoHistory.ts +7 -0
  36. package/src/__tests__/entities.test.ts +160 -5
  37. package/src/__tests__/fixtures/testStorage.ts +1 -1
  38. package/src/client/Client.ts +1 -0
  39. package/src/client/ClientDescriptor.ts +8 -0
  40. package/src/context/context.ts +7 -0
  41. package/src/entities/Entity.ts +151 -5
  42. package/src/entities/EntityMetadata.ts +5 -4
  43. package/src/entities/EntityStore.ts +10 -11
  44. package/src/entities/OperationBatcher.ts +16 -2
  45. package/src/index.ts +39 -39
  46. package/src/persistence/migration/engine.ts +9 -2
@@ -1,4 +1,5 @@
1
1
  import {
2
+ AuthorizationKey,
2
3
  DocumentBaseline,
3
4
  ObjectIdentifier,
4
5
  Operation,
@@ -12,16 +13,15 @@ import {
12
13
  groupPatchesByRootOid,
13
14
  isRootOid,
14
15
  removeOidsFromAllSubObjects,
15
- AuthorizationKey,
16
16
  } from '@verdant-web/common';
17
+ import { WeakEvent } from 'weak-event';
17
18
  import { Context } from '../context/context.js';
18
- import { Entity } from './Entity.js';
19
+ import { FileManager } from '../files/FileManager.js';
20
+ import { processValueFiles } from '../files/utils.js';
19
21
  import { Disposable } from '../utils/Disposable.js';
22
+ import { Entity } from './Entity.js';
20
23
  import { EntityFamilyMetadata } from './EntityMetadata.js';
21
- import { FileManager } from '../files/FileManager.js';
22
24
  import { OperationBatcher } from './OperationBatcher.js';
23
- import { WeakEvent } from 'weak-event';
24
- import { processValueFiles } from '../files/utils.js';
25
25
 
26
26
  enum AbortReason {
27
27
  Reset,
@@ -347,12 +347,11 @@ export class EntityStore extends Disposable {
347
347
  );
348
348
  }
349
349
 
350
- const operations = this.ctx.patchCreator.createInitialize(processed, oid);
351
- if (access) {
352
- operations.forEach((op) => {
353
- op.authz = access;
354
- });
355
- }
350
+ const operations = this.ctx.patchCreator.createInitialize(
351
+ processed,
352
+ oid,
353
+ access,
354
+ );
356
355
  await this.batcher.commitOperations(operations, {
357
356
  undoable: !!undoable,
358
357
  source: entity,
@@ -11,8 +11,8 @@ import {
11
11
  operationSupersedes,
12
12
  } from '@verdant-web/common';
13
13
  import { Context } from '../context/context.js';
14
- import type { EntityStore } from './EntityStore.js';
15
14
  import { Entity } from './Entity.js';
15
+ import type { EntityStore } from './EntityStore.js';
16
16
 
17
17
  const DEFAULT_BATCH_KEY = '@@default';
18
18
 
@@ -257,7 +257,11 @@ export class OperationBatcher {
257
257
  return Promise.all(this.batcher.flushAll());
258
258
  };
259
259
 
260
- private createUndo = async (data: { ops: Operation[]; source?: Entity }) => {
260
+ private createUndo = async (data: {
261
+ ops: Operation[];
262
+ source?: Entity;
263
+ isRedo?: boolean;
264
+ }) => {
261
265
  // this can't be done on-demand because we rely on the current
262
266
  // state of the entities to calculate the inverse operations.
263
267
  const inverseOps = await this.getInverseOperations(data);
@@ -268,11 +272,21 @@ export class OperationBatcher {
268
272
  const redo = await this.createUndo({
269
273
  ops: inverseOps,
270
274
  source: data.source,
275
+ isRedo: true,
271
276
  });
272
277
  // set time to now for all undo operations, they're happening now.
273
278
  for (const op of inverseOps) {
274
279
  op.timestamp = this.ctx.time.now;
275
280
  }
281
+
282
+ this.ctx.log(
283
+ 'debug',
284
+ data.isRedo ? 'Redo' : 'Undo',
285
+ inverseOps,
286
+ '\n was \n',
287
+ data.ops,
288
+ );
289
+
276
290
  await this.commitOperations(
277
291
  inverseOps,
278
292
  // undos should not generate their own undo operations
package/src/index.ts CHANGED
@@ -1,60 +1,60 @@
1
+ import { Client } from './client/Client.js';
1
2
  import {
2
3
  ClientDescriptor,
3
4
  ClientDescriptorOptions,
4
5
  } from './client/ClientDescriptor.js';
5
- import { Client } from './client/Client.js';
6
6
  export type { ClientWithCollections } from './client/Client.js';
7
- export { ClientDescriptor };
8
- export { Client };
7
+ export { Client, ClientDescriptor };
9
8
  // backward compat
10
- export { ClientDescriptor as StorageDescriptor };
11
- export { Client as Storage };
12
- export type { ClientDescriptorOptions };
13
- export type { ClientDescriptorOptions as StorageInitOptions };
14
- export { Entity } from './entities/Entity.js';
15
- export type {
16
- ObjectEntity,
17
- ListEntity,
18
- EntityShape,
19
- AccessibleEntityProperty,
20
- AnyEntity,
21
- EntityDestructured,
22
- EntityInit,
23
- } from './entities/types.js';
24
- export { ServerSync } from './sync/Sync.js';
25
- export type { SyncTransportMode } from './sync/Sync.js';
26
- export { EntityFile, type EntityFileSnapshot } from './files/EntityFile.js';
27
- export { schema, createMigration } from '@verdant-web/common';
9
+ export { createMigration, schema } from '@verdant-web/common';
28
10
  export type {
29
- StorageDocument,
30
- StorageSchema,
31
- StorageCollectionSchema,
11
+ CollectionFilter,
12
+ DocumentBaseline,
13
+ FileData,
14
+ IndexValueTag,
15
+ Migration,
16
+ ObjectIdentifier,
32
17
  StorageAnyFieldSchema,
33
18
  StorageArrayFieldSchema,
34
- StorageObjectFieldSchema,
35
19
  StorageBooleanFieldSchema,
20
+ StorageCollectionSchema,
21
+ StorageDocument,
36
22
  StorageFieldSchema,
23
+ StorageFieldsSchema,
37
24
  StorageFileFieldSchema,
38
25
  StorageMapFieldSchema,
39
26
  StorageNumberFieldSchema,
27
+ StorageObjectFieldSchema,
28
+ StorageSchema,
40
29
  StorageStringFieldSchema,
41
- StorageFieldsSchema,
42
- IndexValueTag,
43
- Migration,
30
+ UserInfo,
44
31
  VerdantError,
45
32
  VerdantErrorCode,
46
- ObjectIdentifier,
47
- CollectionFilter,
48
- FileData,
49
- DocumentBaseline,
50
- UserInfo,
51
33
  } from '@verdant-web/common';
52
- export type { Query } from './queries/types.js';
34
+ export * from './authorization.js';
35
+ export { Entity, getEntityClient } from './entities/Entity.js';
36
+ export type {
37
+ AccessibleEntityProperty,
38
+ AnyEntity,
39
+ EntityDestructured,
40
+ EntityInit,
41
+ EntityShape,
42
+ ListEntity,
43
+ ObjectEntity,
44
+ } from './entities/types.js';
45
+ export { EntityFile, type EntityFileSnapshot } from './files/EntityFile.js';
46
+ export { IdbPersistence } from './persistence/idb/idbPersistence.js';
47
+ export type * from './persistence/interfaces.js';
53
48
  export type { QueryStatus } from './queries/BaseQuery.js';
54
49
  export type { CollectionQueries } from './queries/CollectionQueries.js';
55
- export * from './utils/id.js';
56
- export { UndoHistory } from './UndoHistory.js';
57
- export * from './authorization.js';
50
+ export type { Query } from './queries/types.js';
58
51
  export * from './sync/cliSync.js';
59
- export type * from './persistence/interfaces.js';
60
- export { IdbPersistence } from './persistence/idb/idbPersistence.js';
52
+ export { ServerSync } from './sync/Sync.js';
53
+ export type { SyncTransportMode } from './sync/Sync.js';
54
+ export { UndoHistory } from './UndoHistory.js';
55
+ export * from './utils/id.js';
56
+ export { Client as Storage, ClientDescriptor as StorageDescriptor };
57
+ export type {
58
+ ClientDescriptorOptions,
59
+ ClientDescriptorOptions as StorageInitOptions,
60
+ };
@@ -1,4 +1,5 @@
1
1
  import {
2
+ AuthorizationKey,
2
3
  CollectionFilter,
3
4
  Migration,
4
5
  MigrationEngine,
@@ -11,10 +12,9 @@ import {
11
12
  diffToPatches,
12
13
  getOid,
13
14
  removeOidPropertiesFromAllSubObjects,
14
- AuthorizationKey,
15
15
  } from '@verdant-web/common';
16
- import { OpenDocumentDbContext } from './types.js';
17
16
  import { PersistenceDocumentDb, PersistenceNamespace } from '../interfaces.js';
17
+ import { OpenDocumentDbContext } from './types.js';
18
18
 
19
19
  function getMigrationMutations({
20
20
  migration,
@@ -184,7 +184,14 @@ export async function getMigrationEngine({
184
184
  undefined,
185
185
  [],
186
186
  {
187
+ // incoming unknown objects are assumed to be the same
188
+ // as any pre-existing object.
187
189
  mergeUnknownObjects: true,
190
+ // if a field is undefined in the new value, it should be
191
+ // erased. this is the only way to allow users to remove
192
+ // entries in maps during migrations. it is a little
193
+ // dangerous for other types, though.
194
+ defaultUndefined: false,
188
195
  authz,
189
196
  },
190
197
  );