@dxos/migrations 0.4.9 → 0.4.10-main.06ef97a
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/lib/browser/index.mjs +2 -2
- package/dist/lib/browser/index.mjs.map +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +2 -2
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/migrations.d.ts +1 -1
- package/dist/types/src/migrations.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/migrations.test.ts +5 -3
- package/src/migrations.ts +3 -1
|
@@ -20,7 +20,7 @@ var Migrations = class {
|
|
|
20
20
|
static async migrate(space, targetVersion) {
|
|
21
21
|
invariant(this.versionProperty, "Migrations namespace not set", {
|
|
22
22
|
F: __dxlog_file,
|
|
23
|
-
L:
|
|
23
|
+
L: 40,
|
|
24
24
|
S: this,
|
|
25
25
|
A: [
|
|
26
26
|
"this.versionProperty",
|
|
@@ -29,7 +29,7 @@ var Migrations = class {
|
|
|
29
29
|
});
|
|
30
30
|
invariant(space.state.get() === SpaceState.READY, "Space not ready", {
|
|
31
31
|
F: __dxlog_file,
|
|
32
|
-
L:
|
|
32
|
+
L: 41,
|
|
33
33
|
S: this,
|
|
34
34
|
A: [
|
|
35
35
|
"space.state.get() === SpaceState.READY",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/migrations.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { invariant } from '@dxos/invariant';\nimport type
|
|
5
|
-
"mappings": ";AAIA,SAAqBA,kBAAkB;AACvC,SAASC,iBAAiB;;
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { invariant } from '@dxos/invariant';\nimport { type MaybePromise } from '@dxos/util';\n\n// TODO(burdon): Merge with successor to serialization mechanism in braneframe/types.\n\nexport type MigrationContext = {\n space: Space;\n};\n\nexport type Migration = {\n version: string | number;\n up: (context: MigrationContext) => MaybePromise<void>;\n down: (context: MigrationContext) => MaybePromise<void>;\n};\n\nexport class Migrations {\n static namespace?: string;\n static migrations: Migration[] = [];\n\n static get versionProperty() {\n return this.namespace && `${this.namespace}.version`;\n }\n\n static get targetVersion() {\n return this.migrations[this.migrations.length - 1].version;\n }\n\n static define(namespace: string, migrations: Migration[]) {\n this.namespace = namespace;\n this.migrations = migrations;\n }\n\n // TODO(wittjosiah): Multi-space migrations.\n static async migrate(space: Space, targetVersion?: string | number) {\n invariant(this.versionProperty, 'Migrations namespace not set');\n invariant(space.state.get() === SpaceState.READY, 'Space not ready');\n const currentVersion = space.properties[this.versionProperty];\n const currentIndex = this.migrations.findIndex((m) => m.version === currentVersion) + 1;\n const i = this.migrations.findIndex((m) => m.version === targetVersion);\n const targetIndex = i === -1 ? this.migrations.length : i + 1;\n if (currentIndex === targetIndex) {\n return false;\n }\n\n if (targetIndex > currentIndex) {\n const migrations = this.migrations.slice(currentIndex, targetIndex);\n for (const migration of migrations) {\n await migration.up({ space });\n space.properties[this.versionProperty] = migration.version;\n }\n } else {\n const migrations = this.migrations.slice(targetIndex, currentIndex);\n migrations.reverse();\n for (const migration of migrations) {\n await migration.down({ space });\n const index = this.migrations.indexOf(migration);\n space.properties[this.versionProperty] = this.migrations[index - 1]?.version;\n }\n }\n\n return true;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,SAAqBA,kBAAkB;AACvC,SAASC,iBAAiB;;AAenB,IAAMC,aAAN,MAAMA;EAEX;SAAOC,aAA0B,CAAA;;EAEjC,WAAWC,kBAAkB;AAC3B,WAAO,KAAKC,aAAa,GAAG,KAAKA,SAAS;EAC5C;EAEA,WAAWC,gBAAgB;AACzB,WAAO,KAAKH,WAAW,KAAKA,WAAWI,SAAS,CAAA,EAAGC;EACrD;EAEA,OAAOC,OAAOJ,WAAmBF,YAAyB;AACxD,SAAKE,YAAYA;AACjB,SAAKF,aAAaA;EACpB;;EAGA,aAAaO,QAAQC,OAAcL,eAAiC;AAClEL,cAAU,KAAKG,iBAAiB,gCAAA;;;;;;;;;AAChCH,cAAUU,MAAMC,MAAMC,IAAG,MAAOb,WAAWc,OAAO,mBAAA;;;;;;;;;AAClD,UAAMC,iBAAiBJ,MAAMK,WAAW,KAAKZ,eAAe;AAC5D,UAAMa,eAAe,KAAKd,WAAWe,UAAU,CAACC,MAAMA,EAAEX,YAAYO,cAAAA,IAAkB;AACtF,UAAMK,IAAI,KAAKjB,WAAWe,UAAU,CAACC,MAAMA,EAAEX,YAAYF,aAAAA;AACzD,UAAMe,cAAcD,MAAM,KAAK,KAAKjB,WAAWI,SAASa,IAAI;AAC5D,QAAIH,iBAAiBI,aAAa;AAChC,aAAO;IACT;AAEA,QAAIA,cAAcJ,cAAc;AAC9B,YAAMd,aAAa,KAAKA,WAAWmB,MAAML,cAAcI,WAAAA;AACvD,iBAAWE,aAAapB,YAAY;AAClC,cAAMoB,UAAUC,GAAG;UAAEb;QAAM,CAAA;AAC3BA,cAAMK,WAAW,KAAKZ,eAAe,IAAImB,UAAUf;MACrD;IACF,OAAO;AACL,YAAML,aAAa,KAAKA,WAAWmB,MAAMD,aAAaJ,YAAAA;AACtDd,iBAAWsB,QAAO;AAClB,iBAAWF,aAAapB,YAAY;AAClC,cAAMoB,UAAUG,KAAK;UAAEf;QAAM,CAAA;AAC7B,cAAMgB,QAAQ,KAAKxB,WAAWyB,QAAQL,SAAAA;AACtCZ,cAAMK,WAAW,KAAKZ,eAAe,IAAI,KAAKD,WAAWwB,QAAQ,CAAA,GAAInB;MACvE;IACF;AAEA,WAAO;EACT;AACF;",
|
|
6
6
|
"names": ["SpaceState", "invariant", "Migrations", "migrations", "versionProperty", "namespace", "targetVersion", "length", "version", "define", "migrate", "space", "state", "get", "READY", "currentVersion", "properties", "currentIndex", "findIndex", "m", "i", "targetIndex", "slice", "migration", "up", "reverse", "down", "index", "indexOf"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/sdk/migrations/src/migrations.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/sdk/migrations/src/migrations.ts":{"bytes":8124,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/migrations/src/index.ts":{"bytes":469,"imports":[{"path":"packages/sdk/migrations/src/migrations.ts","kind":"import-statement","original":"./migrations"}],"format":"esm"}},"outputs":{"packages/sdk/migrations/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":3895},"packages/sdk/migrations/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"exports":["Migrations"],"entryPoint":"packages/sdk/migrations/src/index.ts","inputs":{"packages/sdk/migrations/src/migrations.ts":{"bytesInOutput":2163},"packages/sdk/migrations/src/index.ts":{"bytesInOutput":0}},"bytes":2268}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -42,7 +42,7 @@ var Migrations = class {
|
|
|
42
42
|
static async migrate(space, targetVersion) {
|
|
43
43
|
(0, import_invariant.invariant)(this.versionProperty, "Migrations namespace not set", {
|
|
44
44
|
F: __dxlog_file,
|
|
45
|
-
L:
|
|
45
|
+
L: 40,
|
|
46
46
|
S: this,
|
|
47
47
|
A: [
|
|
48
48
|
"this.versionProperty",
|
|
@@ -51,7 +51,7 @@ var Migrations = class {
|
|
|
51
51
|
});
|
|
52
52
|
(0, import_invariant.invariant)(space.state.get() === import_echo.SpaceState.READY, "Space not ready", {
|
|
53
53
|
F: __dxlog_file,
|
|
54
|
-
L:
|
|
54
|
+
L: 41,
|
|
55
55
|
S: this,
|
|
56
56
|
A: [
|
|
57
57
|
"space.state.get() === SpaceState.READY",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/migrations.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { invariant } from '@dxos/invariant';\nimport type
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAIA,kBAAuC;AACvC,uBAA0B;;
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { invariant } from '@dxos/invariant';\nimport { type MaybePromise } from '@dxos/util';\n\n// TODO(burdon): Merge with successor to serialization mechanism in braneframe/types.\n\nexport type MigrationContext = {\n space: Space;\n};\n\nexport type Migration = {\n version: string | number;\n up: (context: MigrationContext) => MaybePromise<void>;\n down: (context: MigrationContext) => MaybePromise<void>;\n};\n\nexport class Migrations {\n static namespace?: string;\n static migrations: Migration[] = [];\n\n static get versionProperty() {\n return this.namespace && `${this.namespace}.version`;\n }\n\n static get targetVersion() {\n return this.migrations[this.migrations.length - 1].version;\n }\n\n static define(namespace: string, migrations: Migration[]) {\n this.namespace = namespace;\n this.migrations = migrations;\n }\n\n // TODO(wittjosiah): Multi-space migrations.\n static async migrate(space: Space, targetVersion?: string | number) {\n invariant(this.versionProperty, 'Migrations namespace not set');\n invariant(space.state.get() === SpaceState.READY, 'Space not ready');\n const currentVersion = space.properties[this.versionProperty];\n const currentIndex = this.migrations.findIndex((m) => m.version === currentVersion) + 1;\n const i = this.migrations.findIndex((m) => m.version === targetVersion);\n const targetIndex = i === -1 ? this.migrations.length : i + 1;\n if (currentIndex === targetIndex) {\n return false;\n }\n\n if (targetIndex > currentIndex) {\n const migrations = this.migrations.slice(currentIndex, targetIndex);\n for (const migration of migrations) {\n await migration.up({ space });\n space.properties[this.versionProperty] = migration.version;\n }\n } else {\n const migrations = this.migrations.slice(targetIndex, currentIndex);\n migrations.reverse();\n for (const migration of migrations) {\n await migration.down({ space });\n const index = this.migrations.indexOf(migration);\n space.properties[this.versionProperty] = this.migrations[index - 1]?.version;\n }\n }\n\n return true;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAIA,kBAAuC;AACvC,uBAA0B;;AAenB,IAAMA,aAAN,MAAMA;EAEX,OAAA;SAAOC,aAA0B,CAAA;;EAEjC,WAAWC,kBAAkB;AAC3B,WAAO,KAAKC,aAAa,GAAG,KAAKA,SAAS;EAC5C;EAEA,WAAWC,gBAAgB;AACzB,WAAO,KAAKH,WAAW,KAAKA,WAAWI,SAAS,CAAA,EAAGC;EACrD;EAEA,OAAOC,OAAOJ,WAAmBF,YAAyB;AACxD,SAAKE,YAAYA;AACjB,SAAKF,aAAaA;EACpB;;EAGA,aAAaO,QAAQC,OAAcL,eAAiC;AAClEM,oCAAU,KAAKR,iBAAiB,gCAAA;;;;;;;;;AAChCQ,oCAAUD,MAAME,MAAMC,IAAG,MAAOC,uBAAWC,OAAO,mBAAA;;;;;;;;;AAClD,UAAMC,iBAAiBN,MAAMO,WAAW,KAAKd,eAAe;AAC5D,UAAMe,eAAe,KAAKhB,WAAWiB,UAAU,CAACC,MAAMA,EAAEb,YAAYS,cAAAA,IAAkB;AACtF,UAAMK,IAAI,KAAKnB,WAAWiB,UAAU,CAACC,MAAMA,EAAEb,YAAYF,aAAAA;AACzD,UAAMiB,cAAcD,MAAM,KAAK,KAAKnB,WAAWI,SAASe,IAAI;AAC5D,QAAIH,iBAAiBI,aAAa;AAChC,aAAO;IACT;AAEA,QAAIA,cAAcJ,cAAc;AAC9B,YAAMhB,aAAa,KAAKA,WAAWqB,MAAML,cAAcI,WAAAA;AACvD,iBAAWE,aAAatB,YAAY;AAClC,cAAMsB,UAAUC,GAAG;UAAEf;QAAM,CAAA;AAC3BA,cAAMO,WAAW,KAAKd,eAAe,IAAIqB,UAAUjB;MACrD;IACF,OAAO;AACL,YAAML,aAAa,KAAKA,WAAWqB,MAAMD,aAAaJ,YAAAA;AACtDhB,iBAAWwB,QAAO;AAClB,iBAAWF,aAAatB,YAAY;AAClC,cAAMsB,UAAUG,KAAK;UAAEjB;QAAM,CAAA;AAC7B,cAAMkB,QAAQ,KAAK1B,WAAW2B,QAAQL,SAAAA;AACtCd,cAAMO,WAAW,KAAKd,eAAe,IAAI,KAAKD,WAAW0B,QAAQ,CAAA,GAAIrB;MACvE;IACF;AAEA,WAAO;EACT;AACF;",
|
|
6
6
|
"names": ["Migrations", "migrations", "versionProperty", "namespace", "targetVersion", "length", "version", "define", "migrate", "space", "invariant", "state", "get", "SpaceState", "READY", "currentVersion", "properties", "currentIndex", "findIndex", "m", "i", "targetIndex", "slice", "migration", "up", "reverse", "down", "index", "indexOf"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/sdk/migrations/src/migrations.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/sdk/migrations/src/migrations.ts":{"bytes":8124,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/migrations/src/index.ts":{"bytes":469,"imports":[{"path":"packages/sdk/migrations/src/migrations.ts","kind":"import-statement","original":"./migrations"}],"format":"esm"}},"outputs":{"packages/sdk/migrations/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":3895},"packages/sdk/migrations/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"exports":["Migrations"],"entryPoint":"packages/sdk/migrations/src/index.ts","inputs":{"packages/sdk/migrations/src/migrations.ts":{"bytesInOutput":2163},"packages/sdk/migrations/src/index.ts":{"bytesInOutput":0}},"bytes":2268}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../src/migrations.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAc,MAAM,mBAAmB,CAAC;AAE3D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../src/migrations.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAc,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,EAAE,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;IACtD,IAAI,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CACzD,CAAC;AAEF,qBAAa,UAAU;IACrB,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,UAAU,EAAE,SAAS,EAAE,CAAM;IAEpC,MAAM,KAAK,eAAe,uBAEzB;IAED,MAAM,KAAK,aAAa,oBAEvB;IAED,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE;WAM3C,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM;CA6BnE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/migrations",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.10-main.06ef97a",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -20,9 +20,10 @@
|
|
|
20
20
|
"src"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@dxos/
|
|
24
|
-
"@dxos/
|
|
25
|
-
"@dxos/
|
|
23
|
+
"@dxos/client": "0.4.10-main.06ef97a",
|
|
24
|
+
"@dxos/echo-schema": "0.4.10-main.06ef97a",
|
|
25
|
+
"@dxos/invariant": "0.4.10-main.06ef97a",
|
|
26
|
+
"@dxos/util": "0.4.10-main.06ef97a"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {},
|
|
28
29
|
"publishConfig": {
|
package/src/migrations.test.ts
CHANGED
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
import { expect } from 'chai';
|
|
6
6
|
|
|
7
7
|
import { Client } from '@dxos/client';
|
|
8
|
-
import {
|
|
8
|
+
import { type Space } from '@dxos/client/echo';
|
|
9
9
|
import { TestBuilder } from '@dxos/client/testing';
|
|
10
|
+
import * as E from '@dxos/echo-schema';
|
|
11
|
+
import { ExpandoType } from '@dxos/echo-schema';
|
|
10
12
|
import { describe, test, beforeEach, beforeAll, afterAll } from '@dxos/test';
|
|
11
13
|
|
|
12
14
|
import { Migrations } from './migrations';
|
|
@@ -15,7 +17,7 @@ Migrations.define('test', [
|
|
|
15
17
|
{
|
|
16
18
|
version: 1,
|
|
17
19
|
up: async ({ space }) => {
|
|
18
|
-
space.db.add(
|
|
20
|
+
space.db.add(E.object(E.ExpandoType, { namespace: 'test', count: 1 }));
|
|
19
21
|
},
|
|
20
22
|
down: async ({ space }) => {
|
|
21
23
|
const { objects } = space.db.query({ namespace: 'test' });
|
|
@@ -82,7 +84,7 @@ describe('Migrations', () => {
|
|
|
82
84
|
|
|
83
85
|
test('if some migrations have been run before, runs only the remaining migrations', async () => {
|
|
84
86
|
space.properties['test.version'] = 2;
|
|
85
|
-
space.db.add(
|
|
87
|
+
space.db.add(E.object(ExpandoType, { namespace: 'test', count: 5 }));
|
|
86
88
|
await Migrations.migrate(space);
|
|
87
89
|
const { objects } = space.db.query({ namespace: 'test' });
|
|
88
90
|
expect(objects).to.have.length(1);
|
package/src/migrations.ts
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Space, SpaceState } from '@dxos/client/echo';
|
|
6
6
|
import { invariant } from '@dxos/invariant';
|
|
7
|
-
import type
|
|
7
|
+
import { type MaybePromise } from '@dxos/util';
|
|
8
|
+
|
|
9
|
+
// TODO(burdon): Merge with successor to serialization mechanism in braneframe/types.
|
|
8
10
|
|
|
9
11
|
export type MigrationContext = {
|
|
10
12
|
space: Space;
|