@verdant-web/common 1.13.0 → 1.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/migration.ts CHANGED
@@ -270,9 +270,17 @@ export function migrate(
270
270
  );
271
271
  if (added.length > 0) {
272
272
  addedIndexes[changed] = added;
273
+ // FIXME: don't o(n^2) this
274
+ if (changedCollections.includes(changed)) {
275
+ autoMigratedCollections.add(changed);
276
+ }
273
277
  }
274
278
  if (removed.length > 0) {
275
279
  removedIndexes[changed] = removed;
280
+ // FIXME: don't o(n^2) this
281
+ if (changedCollections.includes(changed)) {
282
+ autoMigratedCollections.add(changed);
283
+ }
276
284
  }
277
285
  }
278
286
 
@@ -321,22 +329,27 @@ export function migrate(
321
329
  // mandatory migration of fields which had defaults added or
322
330
  // fields removed but weren't migrated by the user
323
331
 
324
- engine.log(
325
- 'debug',
326
- 'auto-migrating collections with new defaults',
327
- autoMigratedCollections,
328
- );
329
- for (const name of autoMigratedCollections) {
330
- await engine.migrate(name, autoMigration(name));
331
- migratedCollections.push(name);
332
- }
332
+ if (newSchema.version > 1) {
333
+ engine.log(
334
+ 'debug',
335
+ 'auto-migrating collections with new defaults',
336
+ autoMigratedCollections,
337
+ );
338
+ for (const name of autoMigratedCollections) {
339
+ await engine.migrate(name, autoMigration(name));
340
+ migratedCollections.push(name);
341
+ }
333
342
 
334
- const unmigrated = changedCollections.filter(
335
- (collection) => !migratedCollections.includes(collection),
336
- );
337
- if (unmigrated.length > 0) {
338
- // TODO: does this deserve a full-on error?
339
- console.error('Unmigrated changed collections:', unmigrated);
343
+ const unmigrated = changedCollections.filter(
344
+ (collection) => !migratedCollections.includes(collection),
345
+ );
346
+ if (unmigrated.length > 0) {
347
+ // TODO: does this deserve a full-on error?
348
+ console.error(
349
+ `Unmigrated changed collections from version ${oldSchema.version} to version ${newSchema.version}:`,
350
+ unmigrated,
351
+ );
352
+ }
340
353
  }
341
354
  },
342
355
  removedCollections,
package/src/oids.test.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  decomposeOid,
10
10
  getOid,
11
11
  getOidRange,
12
+ getOidRoot,
12
13
  hasOid,
13
14
  maybeGetOidProperty,
14
15
  normalize,
@@ -404,3 +405,9 @@ describe('assigning OIDs to sub-objects', () => {
404
405
  expect(hasOid(obj.bar[0])).toBe(false);
405
406
  });
406
407
  });
408
+
409
+ it('should get the root OID for a legacy OID', () => [
410
+ expect(getOidRoot('items/clabgyjfh00003968qycsq3ld.inputs.#')).toEqual(
411
+ 'items/clabgyjfh00003968qycsq3ld',
412
+ ),
413
+ ]);
package/src/oids.ts CHANGED
@@ -426,7 +426,7 @@ export function normalizeFirstLevel(obj: any) {
426
426
  }
427
427
 
428
428
  export function getOidRoot(oid: ObjectIdentifier) {
429
- return oid.split(RANDOM_SEPARATOR)[0];
429
+ return oid.split('.')[0].split(RANDOM_SEPARATOR)[0];
430
430
  }
431
431
 
432
432
  /**
@@ -37,7 +37,12 @@ export type StorageMapFieldSchema<V extends NestedStorageFieldSchema> = {
37
37
  export type StorageFileFieldSchema = {
38
38
  type: 'file';
39
39
  nullable?: boolean;
40
- // downloadRemote?: boolean; TODO: is this a good feature? maybe later.
40
+ /**
41
+ * Instructs the client to download synced files to local storage on first request for offline use.
42
+ * Leave this false to save storage space on the client, at the cost of requiring a network
43
+ * connection to use files created by other devices.
44
+ */
45
+ downloadRemote?: boolean;
41
46
  };
42
47
 
43
48
  export type StorageFieldSchema =
@@ -2,6 +2,7 @@ import { describe, expect, it, vitest } from 'vitest';
2
2
  import {
3
3
  convertOldHlcTimestamp,
4
4
  deserializeHlcTimestamp,
5
+ encodeVersion,
5
6
  HybridLogicalClockTimestampProvider,
6
7
  OLD_encodeVersion,
7
8
  OLD_serializeHlcTimestamp,
@@ -111,3 +112,15 @@ describe('the hybrid logical clock', () => {
111
112
  expect(clock.getWallClockTime(now)).toEqual(time.getTime());
112
113
  });
113
114
  });
115
+
116
+ describe('version encoding', () => {
117
+ it('orders 1 before 2', () => {
118
+ expect(encodeVersion(1) < encodeVersion(2)).toBe(true);
119
+ });
120
+ it('orders 32 before 33', () => {
121
+ expect(encodeVersion(32) < encodeVersion(33)).toBe(true);
122
+ });
123
+ it('orders 34 before 35', () => {
124
+ expect(encodeVersion(34) < encodeVersion(35)).toBe(true);
125
+ });
126
+ });