@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/dist/cjs/indexes.d.ts +1 -0
- package/dist/cjs/indexes.js +5 -1
- package/dist/cjs/indexes.js.map +1 -1
- package/dist/cjs/migration.js +19 -9
- package/dist/cjs/migration.js.map +1 -1
- package/dist/cjs/oids.js +1 -1
- package/dist/cjs/oids.js.map +1 -1
- package/dist/cjs/oids.test.js +3 -0
- package/dist/cjs/oids.test.js.map +1 -1
- package/dist/cjs/schema/types/fields.d.ts +6 -0
- package/dist/cjs/timestamp.test.js +11 -0
- package/dist/cjs/timestamp.test.js.map +1 -1
- package/dist/esm/indexes.d.ts +1 -0
- package/dist/esm/indexes.js +4 -0
- package/dist/esm/indexes.js.map +1 -1
- package/dist/esm/migration.js +19 -9
- package/dist/esm/migration.js.map +1 -1
- package/dist/esm/oids.js +1 -1
- package/dist/esm/oids.js.map +1 -1
- package/dist/esm/oids.test.js +4 -1
- package/dist/esm/oids.test.js.map +1 -1
- package/dist/esm/schema/types/fields.d.ts +6 -0
- package/dist/esm/timestamp.test.js +12 -1
- package/dist/esm/timestamp.test.js.map +1 -1
- package/dist/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/indexes.ts +5 -0
- package/src/migration.ts +28 -15
- package/src/oids.test.ts +7 -0
- package/src/oids.ts +1 -1
- package/src/schema/types/fields.ts +6 -1
- package/src/timestamp.test.ts +13 -0
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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
|
@@ -37,7 +37,12 @@ export type StorageMapFieldSchema<V extends NestedStorageFieldSchema> = {
|
|
|
37
37
|
export type StorageFileFieldSchema = {
|
|
38
38
|
type: 'file';
|
|
39
39
|
nullable?: boolean;
|
|
40
|
-
|
|
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 =
|
package/src/timestamp.test.ts
CHANGED
|
@@ -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
|
+
});
|