@dxos/migrations 0.4.9 → 0.4.10-main.05b9ab6

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.
@@ -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: 38,
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: 39,
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 { MaybePromise } from '@dxos/util';\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;;AAanB,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;",
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":8004,"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":3806},"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}}}
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}}}
@@ -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: 38,
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: 39,
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 { MaybePromise } from '@dxos/util';\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;;AAanB,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;",
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
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/sdk/migrations/src/migrations.ts":{"bytes":8004,"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":3806},"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
+ {"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,5 +1,5 @@
1
1
  import { type Space } from '@dxos/client/echo';
2
- import type { MaybePromise } from '@dxos/util';
2
+ import { type MaybePromise } from '@dxos/util';
3
3
  export type MigrationContext = {
4
4
  space: Space;
5
5
  };
@@ -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,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/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"}
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.9",
3
+ "version": "0.4.10-main.05b9ab6",
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/invariant": "0.4.9",
24
- "@dxos/client": "0.4.9",
25
- "@dxos/util": "0.4.9"
23
+ "@dxos/client": "0.4.10-main.05b9ab6",
24
+ "@dxos/invariant": "0.4.10-main.05b9ab6",
25
+ "@dxos/util": "0.4.10-main.05b9ab6",
26
+ "@dxos/echo-schema": "0.4.10-main.05b9ab6"
26
27
  },
27
28
  "devDependencies": {},
28
29
  "publishConfig": {
@@ -5,8 +5,9 @@
5
5
  import { expect } from 'chai';
6
6
 
7
7
  import { Client } from '@dxos/client';
8
- import { Expando, type Space } from '@dxos/client/echo';
8
+ import { type Space } from '@dxos/client/echo';
9
9
  import { TestBuilder } from '@dxos/client/testing';
10
+ import { Expando, create } from '@dxos/echo-schema';
10
11
  import { describe, test, beforeEach, beforeAll, afterAll } from '@dxos/test';
11
12
 
12
13
  import { Migrations } from './migrations';
@@ -15,10 +16,10 @@ Migrations.define('test', [
15
16
  {
16
17
  version: 1,
17
18
  up: async ({ space }) => {
18
- space.db.add(new Expando({ namespace: 'test', count: 1 }));
19
+ space.db.add(create(Expando, { namespace: 'test', count: 1 }));
19
20
  },
20
21
  down: async ({ space }) => {
21
- const { objects } = space.db.query({ namespace: 'test' });
22
+ const { objects } = await space.db.query({ namespace: 'test' }).run();
22
23
  for (const object of objects) {
23
24
  space.db.remove(object);
24
25
  }
@@ -27,7 +28,7 @@ Migrations.define('test', [
27
28
  {
28
29
  version: 2,
29
30
  up: async ({ space }) => {
30
- const { objects } = space.db.query({ namespace: 'test' });
31
+ const { objects } = await space.db.query({ namespace: 'test' }).run();
31
32
  for (const object of objects) {
32
33
  object.count = 2;
33
34
  }
@@ -39,13 +40,13 @@ Migrations.define('test', [
39
40
  {
40
41
  version: 3,
41
42
  up: async ({ space }) => {
42
- const { objects } = space.db.query({ namespace: 'test' });
43
+ const { objects } = await space.db.query({ namespace: 'test' }).run();
43
44
  for (const object of objects) {
44
45
  object.count *= 3;
45
46
  }
46
47
  },
47
48
  down: async ({ space }) => {
48
- const { objects } = space.db.query({ namespace: 'test' });
49
+ const { objects } = await space.db.query({ namespace: 'test' }).run();
49
50
  for (const object of objects) {
50
51
  object.count /= 3;
51
52
  }
@@ -74,7 +75,7 @@ describe('Migrations', () => {
74
75
 
75
76
  test('if no migrations have been run before, runs all migrations', async () => {
76
77
  await Migrations.migrate(space);
77
- const { objects } = space.db.query({ namespace: 'test' });
78
+ const { objects } = await space.db.query({ namespace: 'test' }).run();
78
79
  expect(objects).to.have.length(1);
79
80
  expect(objects[0].count).to.equal(6);
80
81
  expect(space.properties['test.version']).to.equal(3);
@@ -82,9 +83,9 @@ describe('Migrations', () => {
82
83
 
83
84
  test('if some migrations have been run before, runs only the remaining migrations', async () => {
84
85
  space.properties['test.version'] = 2;
85
- space.db.add(new Expando({ namespace: 'test', count: 5 }));
86
+ space.db.add(create(Expando, { namespace: 'test', count: 5 }));
86
87
  await Migrations.migrate(space);
87
- const { objects } = space.db.query({ namespace: 'test' });
88
+ const { objects } = await space.db.query({ namespace: 'test' }).run();
88
89
  expect(objects).to.have.length(1);
89
90
  expect(objects[0].count).to.equal(15);
90
91
  expect(space.properties['test.version']).to.equal(3);
@@ -93,27 +94,28 @@ describe('Migrations', () => {
93
94
  test('if all migrations have been run before, does nothing', async () => {
94
95
  space.properties['test.version'] = 3;
95
96
  await Migrations.migrate(space);
96
- const { objects } = space.db.query({ namespace: 'test' });
97
+ const { objects } = await space.db.query({ namespace: 'test' }).run();
97
98
  expect(objects).to.have.length(0);
98
99
  });
99
100
 
100
101
  test('if target version is specified, runs only the migrations up to that version', async () => {
101
102
  await Migrations.migrate(space, 2);
102
- const { objects } = space.db.query({ namespace: 'test' });
103
+ const { objects } = await space.db.query({ namespace: 'test' }).run();
103
104
  expect(objects).to.have.length(1);
104
105
  expect(objects[0].count).to.equal(2);
105
106
  expect(space.properties['test.version']).to.equal(2);
106
107
  });
107
108
 
108
109
  test('if target version is specified and is lower than current version, runs the down migrations', async () => {
109
- const query = space.db.query({ namespace: 'test' });
110
110
  await Migrations.migrate(space);
111
- expect(query.objects).to.have.length(1);
112
- expect(query.objects[0].count).to.equal(6);
111
+ const beforeDowngrade = await space.db.query({ namespace: 'test' }).run();
112
+ expect(beforeDowngrade.objects).to.have.length(1);
113
+ expect(beforeDowngrade.objects[0].count).to.equal(6);
113
114
  expect(space.properties['test.version']).to.equal(3);
114
115
  await Migrations.migrate(space, 1);
115
- expect(query.objects).to.have.length(1);
116
- expect(query.objects[0].count).to.equal(2);
116
+ const afterDowngrade = await space.db.query({ namespace: 'test' }).run();
117
+ expect(afterDowngrade.objects).to.have.length(1);
118
+ expect(afterDowngrade.objects[0].count).to.equal(2);
117
119
  expect(space.properties['test.version']).to.equal(1);
118
120
  });
119
121
  });
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 { MaybePromise } from '@dxos/util';
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;