@dxos/migrations 0.5.9-main.845f659 → 0.5.9-main.89d55b2
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 +8 -4
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +8 -4
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/migration-builder.d.ts +5 -3
- package/dist/types/src/migration-builder.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/migration-builder.ts +10 -5
- package/src/migrations.test.ts +1 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { getHeads } from "@dxos/automerge/automerge";
|
|
3
3
|
import { CreateEpochRequest } from "@dxos/client/halo";
|
|
4
4
|
import { ObjectCore } from "@dxos/echo-db";
|
|
5
|
+
import { encodeReference, Reference } from "@dxos/echo-protocol";
|
|
5
6
|
import { requireTypeReference } from "@dxos/echo-schema";
|
|
6
7
|
import { invariant } from "@dxos/invariant";
|
|
7
8
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/migrations/src/migration-builder.ts";
|
|
@@ -31,20 +32,23 @@ var MigrationBuilder = class {
|
|
|
31
32
|
if (!objectStructure) {
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
|
-
const { schema, props } = migrate(objectStructure);
|
|
35
|
+
const { schema, props } = await migrate(objectStructure);
|
|
35
36
|
this._createObject({
|
|
36
37
|
id,
|
|
37
38
|
schema,
|
|
38
39
|
props
|
|
39
40
|
});
|
|
40
41
|
}
|
|
41
|
-
addObject(schema, props) {
|
|
42
|
+
async addObject(schema, props) {
|
|
42
43
|
const core = this._createObject({
|
|
43
44
|
schema,
|
|
44
45
|
props
|
|
45
46
|
});
|
|
46
47
|
return core.id;
|
|
47
48
|
}
|
|
49
|
+
createReference(id) {
|
|
50
|
+
return encodeReference(new Reference(id));
|
|
51
|
+
}
|
|
48
52
|
deleteObject(id) {
|
|
49
53
|
this._deleteObjects.push(id);
|
|
50
54
|
}
|
|
@@ -54,7 +58,7 @@ var MigrationBuilder = class {
|
|
|
54
58
|
}
|
|
55
59
|
invariant(this._newRoot, "New root not created", {
|
|
56
60
|
F: __dxlog_file,
|
|
57
|
-
L:
|
|
61
|
+
L: 79,
|
|
58
62
|
S: this,
|
|
59
63
|
A: [
|
|
60
64
|
"this._newRoot",
|
|
@@ -79,7 +83,7 @@ var MigrationBuilder = class {
|
|
|
79
83
|
}
|
|
80
84
|
invariant(this._newRoot, "New root not created", {
|
|
81
85
|
F: __dxlog_file,
|
|
82
|
-
L:
|
|
86
|
+
L: 98,
|
|
83
87
|
S: this,
|
|
84
88
|
A: [
|
|
85
89
|
"this._newRoot",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/migration-builder.ts", "../../../src/migrations.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport {
|
|
5
|
-
"mappings": ";AAIA,
|
|
6
|
-
"names": ["getHeads", "CreateEpochRequest", "ObjectCore", "requireTypeReference", "invariant", "MigrationBuilder", "constructor", "_space", "_newLinks", "_flushStates", "_deleteObjects", "_newRoot", "undefined", "_repo", "db", "coreDatabase", "automerge", "repo", "_automergeContext", "_rootDoc", "_automergeDocLoader", "getSpaceRootDocHandle", "docSync", "findObject", "id", "documentId", "links", "docHandle", "find", "whenReady", "doc", "objects", "migrateObject", "migrate", "objectStructure", "schema", "props", "_createObject", "addObject", "core", "deleteObject", "push", "changeProperties", "changeFn", "_buildNewRoot", "change", "propertiesStructure", "properties", "heads", "_commit", "flush", "states", "internal", "createEpoch", "migration", "Migration", "REPLACE_AUTOMERGE_ROOT", "automergeRootUrl", "url", "previousLinks", "create", "access", "spaceKey", "key", "toHex", "initNewObject", "setType", "newHandle", "getDoc", "create", "SpaceState", "invariant", "Migrations", "migrations", "_state", "create", "running", "versionProperty", "namespace", "targetVersion", "length", "version", "space", "includes", "key", "toHex", "define", "migrate", "invariant", "state", "get", "SpaceState", "READY", "currentVersion", "properties", "currentIndex", "findIndex", "m", "i", "targetIndex", "push", "slice", "migration", "builder", "MigrationBuilder", "next", "changeProperties", "propertiesStructure", "data", "_commit", "splice", "indexOf"]
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Doc, getHeads } from '@dxos/automerge/automerge';\nimport { type AnyDocumentId, type DocHandle, type Repo } from '@dxos/automerge/automerge-repo';\nimport { type Space } from '@dxos/client/echo';\nimport { CreateEpochRequest } from '@dxos/client/halo';\nimport { type AutomergeContext, ObjectCore } from '@dxos/echo-db';\nimport { encodeReference, type ObjectStructure, Reference, type SpaceDoc } from '@dxos/echo-protocol';\nimport { requireTypeReference, type S } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { type FlushRequest } from '@dxos/protocols/proto/dxos/echo/service';\nimport { type MaybePromise } from '@dxos/util';\n\nexport class MigrationBuilder {\n private readonly _repo: Repo;\n private readonly _automergeContext: AutomergeContext;\n private readonly _rootDoc: Doc<SpaceDoc>;\n\n // echoId -> automergeUrl\n private readonly _newLinks: Record<string, string> = {};\n private readonly _flushStates: FlushRequest.DocState[] = [];\n private readonly _deleteObjects: string[] = [];\n\n private _newRoot?: DocHandle<SpaceDoc> = undefined;\n\n constructor(private readonly _space: Space) {\n this._repo = this._space.db.coreDatabase.automerge.repo;\n this._automergeContext = this._space.db.coreDatabase.automerge;\n // TODO(wittjosiah): Accessing private API.\n this._rootDoc = (this._space.db.coreDatabase as any)._automergeDocLoader\n .getSpaceRootDocHandle()\n .docSync() as Doc<SpaceDoc>;\n }\n\n async findObject(id: string): Promise<ObjectStructure | undefined> {\n const documentId = (this._rootDoc.links?.[id] || this._newLinks[id]) as AnyDocumentId | undefined;\n const docHandle = documentId && this._repo.find(documentId);\n if (!docHandle) {\n return undefined;\n }\n\n await docHandle.whenReady();\n const doc = docHandle.docSync() as Doc<SpaceDoc>;\n return doc.objects?.[id];\n }\n\n async migrateObject(\n id: string,\n migrate: (objectStructure: ObjectStructure) => MaybePromise<{ schema: S.Schema<any>; props: any }>,\n ) {\n const objectStructure = await this.findObject(id);\n if (!objectStructure) {\n return;\n }\n\n const { schema, props } = await migrate(objectStructure);\n this._createObject({ id, schema, props });\n }\n\n async addObject(schema: S.Schema<any>, props: any) {\n const core = this._createObject({ schema, props });\n return core.id;\n }\n\n createReference(id: string) {\n return encodeReference(new Reference(id));\n }\n\n deleteObject(id: string) {\n this._deleteObjects.push(id);\n }\n\n changeProperties(changeFn: (properties: ObjectStructure) => void) {\n if (!this._newRoot) {\n this._buildNewRoot();\n }\n invariant(this._newRoot, 'New root not created');\n\n this._newRoot.change((doc: SpaceDoc) => {\n const propertiesStructure = doc.objects?.[this._space.properties.id];\n propertiesStructure && changeFn(propertiesStructure);\n });\n this._flushStates.push({\n documentId: this._newRoot.documentId,\n heads: getHeads(this._newRoot.docSync()),\n });\n }\n\n /**\n * @internal\n */\n async _commit() {\n if (!this._newRoot) {\n this._buildNewRoot();\n }\n invariant(this._newRoot, 'New root not created');\n\n await this._automergeContext.flush({\n states: this._flushStates,\n });\n\n // Create new epoch.\n await this._space.internal.createEpoch({\n migration: CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT,\n automergeRootUrl: this._newRoot.url,\n });\n }\n\n private _buildNewRoot() {\n const previousLinks = { ...(this._rootDoc.links ?? {}) };\n for (const id of this._deleteObjects) {\n delete previousLinks[id];\n }\n\n this._newRoot = this._repo.create<SpaceDoc>({\n access: {\n spaceKey: this._space.key.toHex(),\n },\n objects: this._rootDoc.objects,\n links: {\n ...previousLinks,\n ...this._newLinks,\n },\n });\n this._flushStates.push({\n documentId: this._newRoot.documentId,\n heads: getHeads(this._newRoot.docSync()),\n });\n }\n\n private _createObject({ id, schema, props }: { id?: string; schema: S.Schema<any>; props: any }) {\n const core = new ObjectCore();\n if (id) {\n core.id = id;\n }\n\n core.initNewObject(props);\n core.setType(requireTypeReference(schema));\n const newHandle = this._repo.create<SpaceDoc>({\n access: {\n spaceKey: this._space.key.toHex(),\n },\n objects: {\n [core.id]: core.getDoc(),\n },\n });\n this._newLinks[core.id] = newHandle.url;\n this._flushStates.push({\n documentId: newHandle.documentId,\n heads: getHeads(newHandle.docSync()),\n });\n\n return core;\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Space, create, SpaceState } from '@dxos/client/echo';\nimport { invariant } from '@dxos/invariant';\nimport { type MaybePromise } from '@dxos/util';\n\nimport { MigrationBuilder } from './migration-builder';\n\nexport type MigrationContext = {\n space: Space;\n builder: MigrationBuilder;\n};\n\nexport type Migration = {\n version: string;\n next: (context: MigrationContext) => MaybePromise<void>;\n};\n\nexport class Migrations {\n static namespace?: string;\n static migrations: Migration[] = [];\n private static _state = create<{ running: string[] }>({ running: [] });\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 running(space: Space) {\n return this._state.running.includes(space.key.toHex());\n }\n\n static define(namespace: string, migrations: Migration[]) {\n this.namespace = namespace;\n this.migrations = migrations;\n }\n\n static async migrate(space: Space, targetVersion?: string | number) {\n invariant(!this.running(space), 'Migration already running');\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 this._state.running.push(space.key.toHex());\n if (targetIndex > currentIndex) {\n const migrations = this.migrations.slice(currentIndex, targetIndex);\n for (const migration of migrations) {\n const builder = new MigrationBuilder(space);\n await migration.next({ space, builder });\n builder.changeProperties((propertiesStructure) => {\n invariant(this.versionProperty, 'Migrations namespace not set');\n propertiesStructure.data[this.versionProperty] = migration.version;\n });\n await builder._commit();\n }\n }\n this._state.running.splice(this._state.running.indexOf(space.key.toHex()), 1);\n\n return true;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,SAAmBA,gBAAgB;AAGnC,SAASC,0BAA0B;AACnC,SAAgCC,kBAAkB;AAClD,SAASC,iBAAuCC,iBAAgC;AAChF,SAASC,4BAAoC;AAC7C,SAASC,iBAAiB;;AAInB,IAAMC,mBAAN,MAAMA;EAYXC,YAA6BC,QAAe;SAAfA,SAAAA;SANZC,YAAoC,CAAC;SACrCC,eAAwC,CAAA;SACxCC,iBAA2B,CAAA;SAEpCC,WAAiCC;AAGvC,SAAKC,QAAQ,KAAKN,OAAOO,GAAGC,aAAaC,UAAUC;AACnD,SAAKC,oBAAoB,KAAKX,OAAOO,GAAGC,aAAaC;AAErD,SAAKG,WAAY,KAAKZ,OAAOO,GAAGC,aAAqBK,oBAClDC,sBAAqB,EACrBC,QAAO;EACZ;EAEA,MAAMC,WAAWC,IAAkD;AACjE,UAAMC,aAAc,KAAKN,SAASO,QAAQF,EAAAA,KAAO,KAAKhB,UAAUgB,EAAAA;AAChE,UAAMG,YAAYF,cAAc,KAAKZ,MAAMe,KAAKH,UAAAA;AAChD,QAAI,CAACE,WAAW;AACd,aAAOf;IACT;AAEA,UAAMe,UAAUE,UAAS;AACzB,UAAMC,MAAMH,UAAUL,QAAO;AAC7B,WAAOQ,IAAIC,UAAUP,EAAAA;EACvB;EAEA,MAAMQ,cACJR,IACAS,SACA;AACA,UAAMC,kBAAkB,MAAM,KAAKX,WAAWC,EAAAA;AAC9C,QAAI,CAACU,iBAAiB;AACpB;IACF;AAEA,UAAM,EAAEC,QAAQC,MAAK,IAAK,MAAMH,QAAQC,eAAAA;AACxC,SAAKG,cAAc;MAAEb;MAAIW;MAAQC;IAAM,CAAA;EACzC;EAEA,MAAME,UAAUH,QAAuBC,OAAY;AACjD,UAAMG,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
6
|
+
"names": ["getHeads", "CreateEpochRequest", "ObjectCore", "encodeReference", "Reference", "requireTypeReference", "invariant", "MigrationBuilder", "constructor", "_space", "_newLinks", "_flushStates", "_deleteObjects", "_newRoot", "undefined", "_repo", "db", "coreDatabase", "automerge", "repo", "_automergeContext", "_rootDoc", "_automergeDocLoader", "getSpaceRootDocHandle", "docSync", "findObject", "id", "documentId", "links", "docHandle", "find", "whenReady", "doc", "objects", "migrateObject", "migrate", "objectStructure", "schema", "props", "_createObject", "addObject", "core", "createReference", "deleteObject", "push", "changeProperties", "changeFn", "_buildNewRoot", "change", "propertiesStructure", "properties", "heads", "_commit", "flush", "states", "internal", "createEpoch", "migration", "Migration", "REPLACE_AUTOMERGE_ROOT", "automergeRootUrl", "url", "previousLinks", "create", "access", "spaceKey", "key", "toHex", "initNewObject", "setType", "newHandle", "getDoc", "create", "SpaceState", "invariant", "Migrations", "migrations", "_state", "create", "running", "versionProperty", "namespace", "targetVersion", "length", "version", "space", "includes", "key", "toHex", "define", "migrate", "invariant", "state", "get", "SpaceState", "READY", "currentVersion", "properties", "currentIndex", "findIndex", "m", "i", "targetIndex", "push", "slice", "migration", "builder", "MigrationBuilder", "next", "changeProperties", "propertiesStructure", "data", "_commit", "splice", "indexOf"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/sdk/migrations/src/migration-builder.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/sdk/migrations/src/migration-builder.ts":{"bytes":17544,"imports":[{"path":"@dxos/automerge/automerge","kind":"import-statement","external":true},{"path":"@dxos/client/halo","kind":"import-statement","external":true},{"path":"@dxos/echo-db","kind":"import-statement","external":true},{"path":"@dxos/echo-protocol","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/migrations/src/migrations.ts":{"bytes":9817,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"packages/sdk/migrations/src/migration-builder.ts","kind":"import-statement","original":"./migration-builder"}],"format":"esm"},"packages/sdk/migrations/src/index.ts":{"bytes":698,"imports":[{"path":"packages/sdk/migrations/src/migration-builder.ts","kind":"import-statement","original":"./migration-builder"},{"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":13051},"packages/sdk/migrations/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/automerge/automerge","kind":"import-statement","external":true},{"path":"@dxos/client/halo","kind":"import-statement","external":true},{"path":"@dxos/echo-db","kind":"import-statement","external":true},{"path":"@dxos/echo-protocol","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"exports":["MigrationBuilder","Migrations"],"entryPoint":"packages/sdk/migrations/src/index.ts","inputs":{"packages/sdk/migrations/src/migration-builder.ts":{"bytesInOutput":3936},"packages/sdk/migrations/src/index.ts":{"bytesInOutput":0},"packages/sdk/migrations/src/migrations.ts":{"bytesInOutput":2745}},"bytes":6859}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -25,6 +25,7 @@ module.exports = __toCommonJS(node_exports);
|
|
|
25
25
|
var import_automerge = require("@dxos/automerge/automerge");
|
|
26
26
|
var import_halo = require("@dxos/client/halo");
|
|
27
27
|
var import_echo_db = require("@dxos/echo-db");
|
|
28
|
+
var import_echo_protocol = require("@dxos/echo-protocol");
|
|
28
29
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
29
30
|
var import_invariant = require("@dxos/invariant");
|
|
30
31
|
var import_echo = require("@dxos/client/echo");
|
|
@@ -56,20 +57,23 @@ var MigrationBuilder = class {
|
|
|
56
57
|
if (!objectStructure) {
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
59
|
-
const { schema, props } = migrate(objectStructure);
|
|
60
|
+
const { schema, props } = await migrate(objectStructure);
|
|
60
61
|
this._createObject({
|
|
61
62
|
id,
|
|
62
63
|
schema,
|
|
63
64
|
props
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
|
-
addObject(schema, props) {
|
|
67
|
+
async addObject(schema, props) {
|
|
67
68
|
const core = this._createObject({
|
|
68
69
|
schema,
|
|
69
70
|
props
|
|
70
71
|
});
|
|
71
72
|
return core.id;
|
|
72
73
|
}
|
|
74
|
+
createReference(id) {
|
|
75
|
+
return (0, import_echo_protocol.encodeReference)(new import_echo_protocol.Reference(id));
|
|
76
|
+
}
|
|
73
77
|
deleteObject(id) {
|
|
74
78
|
this._deleteObjects.push(id);
|
|
75
79
|
}
|
|
@@ -79,7 +83,7 @@ var MigrationBuilder = class {
|
|
|
79
83
|
}
|
|
80
84
|
(0, import_invariant.invariant)(this._newRoot, "New root not created", {
|
|
81
85
|
F: __dxlog_file,
|
|
82
|
-
L:
|
|
86
|
+
L: 79,
|
|
83
87
|
S: this,
|
|
84
88
|
A: [
|
|
85
89
|
"this._newRoot",
|
|
@@ -104,7 +108,7 @@ var MigrationBuilder = class {
|
|
|
104
108
|
}
|
|
105
109
|
(0, import_invariant.invariant)(this._newRoot, "New root not created", {
|
|
106
110
|
F: __dxlog_file,
|
|
107
|
-
L:
|
|
111
|
+
L: 98,
|
|
108
112
|
S: this,
|
|
109
113
|
A: [
|
|
110
114
|
"this._newRoot",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/migration-builder.ts", "../../../src/migrations.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAIA,uBAAmC;AAGnC,kBAAmC;AACnC,qBAAkD;
|
|
6
|
-
"names": ["import_invariant", "MigrationBuilder", "constructor", "_space", "_newLinks", "_flushStates", "_deleteObjects", "_newRoot", "undefined", "_repo", "db", "coreDatabase", "automerge", "repo", "_automergeContext", "_rootDoc", "_automergeDocLoader", "getSpaceRootDocHandle", "docSync", "findObject", "id", "documentId", "links", "docHandle", "find", "whenReady", "doc", "objects", "migrateObject", "migrate", "objectStructure", "schema", "props", "_createObject", "addObject", "core", "deleteObject", "push", "changeProperties", "changeFn", "_buildNewRoot", "invariant", "change", "propertiesStructure", "properties", "heads", "getHeads", "_commit", "flush", "states", "internal", "createEpoch", "migration", "CreateEpochRequest", "Migration", "REPLACE_AUTOMERGE_ROOT", "automergeRootUrl", "url", "previousLinks", "create", "access", "spaceKey", "key", "toHex", "ObjectCore", "initNewObject", "setType", "requireTypeReference", "newHandle", "getDoc", "Migrations", "migrations", "_state", "running", "versionProperty", "namespace", "targetVersion", "length", "version", "space", "includes", "define", "state", "get", "SpaceState", "READY", "currentVersion", "currentIndex", "findIndex", "m", "i", "targetIndex", "slice", "builder", "next", "data", "splice", "indexOf"]
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Doc, getHeads } from '@dxos/automerge/automerge';\nimport { type AnyDocumentId, type DocHandle, type Repo } from '@dxos/automerge/automerge-repo';\nimport { type Space } from '@dxos/client/echo';\nimport { CreateEpochRequest } from '@dxos/client/halo';\nimport { type AutomergeContext, ObjectCore } from '@dxos/echo-db';\nimport { encodeReference, type ObjectStructure, Reference, type SpaceDoc } from '@dxos/echo-protocol';\nimport { requireTypeReference, type S } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { type FlushRequest } from '@dxos/protocols/proto/dxos/echo/service';\nimport { type MaybePromise } from '@dxos/util';\n\nexport class MigrationBuilder {\n private readonly _repo: Repo;\n private readonly _automergeContext: AutomergeContext;\n private readonly _rootDoc: Doc<SpaceDoc>;\n\n // echoId -> automergeUrl\n private readonly _newLinks: Record<string, string> = {};\n private readonly _flushStates: FlushRequest.DocState[] = [];\n private readonly _deleteObjects: string[] = [];\n\n private _newRoot?: DocHandle<SpaceDoc> = undefined;\n\n constructor(private readonly _space: Space) {\n this._repo = this._space.db.coreDatabase.automerge.repo;\n this._automergeContext = this._space.db.coreDatabase.automerge;\n // TODO(wittjosiah): Accessing private API.\n this._rootDoc = (this._space.db.coreDatabase as any)._automergeDocLoader\n .getSpaceRootDocHandle()\n .docSync() as Doc<SpaceDoc>;\n }\n\n async findObject(id: string): Promise<ObjectStructure | undefined> {\n const documentId = (this._rootDoc.links?.[id] || this._newLinks[id]) as AnyDocumentId | undefined;\n const docHandle = documentId && this._repo.find(documentId);\n if (!docHandle) {\n return undefined;\n }\n\n await docHandle.whenReady();\n const doc = docHandle.docSync() as Doc<SpaceDoc>;\n return doc.objects?.[id];\n }\n\n async migrateObject(\n id: string,\n migrate: (objectStructure: ObjectStructure) => MaybePromise<{ schema: S.Schema<any>; props: any }>,\n ) {\n const objectStructure = await this.findObject(id);\n if (!objectStructure) {\n return;\n }\n\n const { schema, props } = await migrate(objectStructure);\n this._createObject({ id, schema, props });\n }\n\n async addObject(schema: S.Schema<any>, props: any) {\n const core = this._createObject({ schema, props });\n return core.id;\n }\n\n createReference(id: string) {\n return encodeReference(new Reference(id));\n }\n\n deleteObject(id: string) {\n this._deleteObjects.push(id);\n }\n\n changeProperties(changeFn: (properties: ObjectStructure) => void) {\n if (!this._newRoot) {\n this._buildNewRoot();\n }\n invariant(this._newRoot, 'New root not created');\n\n this._newRoot.change((doc: SpaceDoc) => {\n const propertiesStructure = doc.objects?.[this._space.properties.id];\n propertiesStructure && changeFn(propertiesStructure);\n });\n this._flushStates.push({\n documentId: this._newRoot.documentId,\n heads: getHeads(this._newRoot.docSync()),\n });\n }\n\n /**\n * @internal\n */\n async _commit() {\n if (!this._newRoot) {\n this._buildNewRoot();\n }\n invariant(this._newRoot, 'New root not created');\n\n await this._automergeContext.flush({\n states: this._flushStates,\n });\n\n // Create new epoch.\n await this._space.internal.createEpoch({\n migration: CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT,\n automergeRootUrl: this._newRoot.url,\n });\n }\n\n private _buildNewRoot() {\n const previousLinks = { ...(this._rootDoc.links ?? {}) };\n for (const id of this._deleteObjects) {\n delete previousLinks[id];\n }\n\n this._newRoot = this._repo.create<SpaceDoc>({\n access: {\n spaceKey: this._space.key.toHex(),\n },\n objects: this._rootDoc.objects,\n links: {\n ...previousLinks,\n ...this._newLinks,\n },\n });\n this._flushStates.push({\n documentId: this._newRoot.documentId,\n heads: getHeads(this._newRoot.docSync()),\n });\n }\n\n private _createObject({ id, schema, props }: { id?: string; schema: S.Schema<any>; props: any }) {\n const core = new ObjectCore();\n if (id) {\n core.id = id;\n }\n\n core.initNewObject(props);\n core.setType(requireTypeReference(schema));\n const newHandle = this._repo.create<SpaceDoc>({\n access: {\n spaceKey: this._space.key.toHex(),\n },\n objects: {\n [core.id]: core.getDoc(),\n },\n });\n this._newLinks[core.id] = newHandle.url;\n this._flushStates.push({\n documentId: newHandle.documentId,\n heads: getHeads(newHandle.docSync()),\n });\n\n return core;\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Space, create, SpaceState } from '@dxos/client/echo';\nimport { invariant } from '@dxos/invariant';\nimport { type MaybePromise } from '@dxos/util';\n\nimport { MigrationBuilder } from './migration-builder';\n\nexport type MigrationContext = {\n space: Space;\n builder: MigrationBuilder;\n};\n\nexport type Migration = {\n version: string;\n next: (context: MigrationContext) => MaybePromise<void>;\n};\n\nexport class Migrations {\n static namespace?: string;\n static migrations: Migration[] = [];\n private static _state = create<{ running: string[] }>({ running: [] });\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 running(space: Space) {\n return this._state.running.includes(space.key.toHex());\n }\n\n static define(namespace: string, migrations: Migration[]) {\n this.namespace = namespace;\n this.migrations = migrations;\n }\n\n static async migrate(space: Space, targetVersion?: string | number) {\n invariant(!this.running(space), 'Migration already running');\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 this._state.running.push(space.key.toHex());\n if (targetIndex > currentIndex) {\n const migrations = this.migrations.slice(currentIndex, targetIndex);\n for (const migration of migrations) {\n const builder = new MigrationBuilder(space);\n await migration.next({ space, builder });\n builder.changeProperties((propertiesStructure) => {\n invariant(this.versionProperty, 'Migrations namespace not set');\n propertiesStructure.data[this.versionProperty] = migration.version;\n });\n await builder._commit();\n }\n }\n this._state.running.splice(this._state.running.indexOf(space.key.toHex()), 1);\n\n return true;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAIA,uBAAmC;AAGnC,kBAAmC;AACnC,qBAAkD;AAClD,2BAAgF;AAChF,yBAA6C;AAC7C,uBAA0B;ACP1B,kBAA+C;AAC/C,IAAAA,oBAA0B;;ADUnB,IAAMC,mBAAN,MAAMA;EAYXC,YAA6BC,QAAe;SAAfA,SAAAA;SANZC,YAAoC,CAAC;SACrCC,eAAwC,CAAA;SACxCC,iBAA2B,CAAA;SAEpCC,WAAiCC;AAGvC,SAAKC,QAAQ,KAAKN,OAAOO,GAAGC,aAAaC,UAAUC;AACnD,SAAKC,oBAAoB,KAAKX,OAAOO,GAAGC,aAAaC;AAErD,SAAKG,WAAY,KAAKZ,OAAOO,GAAGC,aAAqBK,oBAClDC,sBAAqB,EACrBC,QAAO;EACZ;EAEA,MAAMC,WAAWC,IAAkD;AACjE,UAAMC,aAAc,KAAKN,SAASO,QAAQF,EAAAA,KAAO,KAAKhB,UAAUgB,EAAAA;AA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AWvC,aAAamB,YAAY;AAClC,cAAMsB,UAAU,IAAI/F,iBAAiBiF,KAAAA;AACrC,cAAM3B,UAAU0C,KAAK;UAAEf;UAAOc;QAAQ,CAAA;AACtCA,gBAAQvD,iBAAiB,CAACK,wBAAAA;AACxBF,gCAAAA,WAAU,KAAKiC,iBAAiB,gCAAA;;;;;;;;;AAChC/B,8BAAoBoD,KAAK,KAAKrB,eAAe,IAAItB,UAAU0B;QAC7D,CAAA;AACA,cAAMe,QAAQ9C,QAAO;MACvB;IACF;AACA,SAAKyB,OAAOC,QAAQuB,OAAO,KAAKxB,OAAOC,QAAQwB,QAAQlB,MAAMjB,IAAIC,MAAK,CAAA,GAAK,CAAA;AAE3E,WAAO;EACT;AACF;",
|
|
6
|
+
"names": ["import_invariant", "MigrationBuilder", "constructor", "_space", "_newLinks", "_flushStates", "_deleteObjects", "_newRoot", "undefined", "_repo", "db", "coreDatabase", "automerge", "repo", "_automergeContext", "_rootDoc", "_automergeDocLoader", "getSpaceRootDocHandle", "docSync", "findObject", "id", "documentId", "links", "docHandle", "find", "whenReady", "doc", "objects", "migrateObject", "migrate", "objectStructure", "schema", "props", "_createObject", "addObject", "core", "createReference", "encodeReference", "Reference", "deleteObject", "push", "changeProperties", "changeFn", "_buildNewRoot", "invariant", "change", "propertiesStructure", "properties", "heads", "getHeads", "_commit", "flush", "states", "internal", "createEpoch", "migration", "CreateEpochRequest", "Migration", "REPLACE_AUTOMERGE_ROOT", "automergeRootUrl", "url", "previousLinks", "create", "access", "spaceKey", "key", "toHex", "ObjectCore", "initNewObject", "setType", "requireTypeReference", "newHandle", "getDoc", "Migrations", "migrations", "_state", "running", "versionProperty", "namespace", "targetVersion", "length", "version", "space", "includes", "define", "state", "get", "SpaceState", "READY", "currentVersion", "currentIndex", "findIndex", "m", "i", "targetIndex", "slice", "builder", "next", "data", "splice", "indexOf"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/sdk/migrations/src/migration-builder.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/sdk/migrations/src/migration-builder.ts":{"bytes":17544,"imports":[{"path":"@dxos/automerge/automerge","kind":"import-statement","external":true},{"path":"@dxos/client/halo","kind":"import-statement","external":true},{"path":"@dxos/echo-db","kind":"import-statement","external":true},{"path":"@dxos/echo-protocol","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/migrations/src/migrations.ts":{"bytes":9817,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"packages/sdk/migrations/src/migration-builder.ts","kind":"import-statement","original":"./migration-builder"}],"format":"esm"},"packages/sdk/migrations/src/index.ts":{"bytes":698,"imports":[{"path":"packages/sdk/migrations/src/migration-builder.ts","kind":"import-statement","original":"./migration-builder"},{"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":13051},"packages/sdk/migrations/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/automerge/automerge","kind":"import-statement","external":true},{"path":"@dxos/client/halo","kind":"import-statement","external":true},{"path":"@dxos/echo-db","kind":"import-statement","external":true},{"path":"@dxos/echo-protocol","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"exports":["MigrationBuilder","Migrations"],"entryPoint":"packages/sdk/migrations/src/index.ts","inputs":{"packages/sdk/migrations/src/migration-builder.ts":{"bytesInOutput":3936},"packages/sdk/migrations/src/index.ts":{"bytesInOutput":0},"packages/sdk/migrations/src/migrations.ts":{"bytesInOutput":2745}},"bytes":6859}}}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Space } from '@dxos/client/echo';
|
|
2
2
|
import { type ObjectStructure } from '@dxos/echo-protocol';
|
|
3
3
|
import { type S } from '@dxos/echo-schema';
|
|
4
|
+
import { type MaybePromise } from '@dxos/util';
|
|
4
5
|
export declare class MigrationBuilder {
|
|
5
6
|
private readonly _space;
|
|
6
7
|
private readonly _repo;
|
|
@@ -12,11 +13,12 @@ export declare class MigrationBuilder {
|
|
|
12
13
|
private _newRoot?;
|
|
13
14
|
constructor(_space: Space);
|
|
14
15
|
findObject(id: string): Promise<ObjectStructure | undefined>;
|
|
15
|
-
migrateObject(id: string, migrate: (objectStructure: ObjectStructure) => {
|
|
16
|
+
migrateObject(id: string, migrate: (objectStructure: ObjectStructure) => MaybePromise<{
|
|
16
17
|
schema: S.Schema<any>;
|
|
17
18
|
props: any;
|
|
18
|
-
}): Promise<void>;
|
|
19
|
-
addObject(schema: S.Schema<any>, props: any): string
|
|
19
|
+
}>): Promise<void>;
|
|
20
|
+
addObject(schema: S.Schema<any>, props: any): Promise<string>;
|
|
21
|
+
createReference(id: string): import("@dxos/echo-protocol").EncodedReferenceObject;
|
|
20
22
|
deleteObject(id: string): void;
|
|
21
23
|
changeProperties(changeFn: (properties: ObjectStructure) => void): void;
|
|
22
24
|
private _buildNewRoot;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-builder.d.ts","sourceRoot":"","sources":["../../../src/migration-builder.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG/C,OAAO,
|
|
1
|
+
{"version":3,"file":"migration-builder.d.ts","sourceRoot":"","sources":["../../../src/migration-builder.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG/C,OAAO,EAAmB,KAAK,eAAe,EAA4B,MAAM,qBAAqB,CAAC;AACtG,OAAO,EAA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
"description": "",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"src"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@dxos/client": "0.5.9-main.
|
|
24
|
-
"@dxos/
|
|
25
|
-
"@dxos/echo-
|
|
26
|
-
"@dxos/echo-schema": "0.5.9-main.
|
|
27
|
-
"@dxos/
|
|
28
|
-
"@dxos/
|
|
29
|
-
"@dxos/protocols": "0.5.9-main.
|
|
30
|
-
"@dxos/log": "0.5.9-main.
|
|
31
|
-
"@dxos/util": "0.5.9-main.
|
|
23
|
+
"@dxos/client": "0.5.9-main.89d55b2",
|
|
24
|
+
"@dxos/echo-db": "0.5.9-main.89d55b2",
|
|
25
|
+
"@dxos/echo-protocol": "0.5.9-main.89d55b2",
|
|
26
|
+
"@dxos/echo-schema": "0.5.9-main.89d55b2",
|
|
27
|
+
"@dxos/invariant": "0.5.9-main.89d55b2",
|
|
28
|
+
"@dxos/automerge": "0.5.9-main.89d55b2",
|
|
29
|
+
"@dxos/protocols": "0.5.9-main.89d55b2",
|
|
30
|
+
"@dxos/log": "0.5.9-main.89d55b2",
|
|
31
|
+
"@dxos/util": "0.5.9-main.89d55b2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {},
|
|
34
34
|
"publishConfig": {
|
package/src/migration-builder.ts
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { type Doc, getHeads } from '@dxos/automerge/automerge';
|
|
6
6
|
import { type AnyDocumentId, type DocHandle, type Repo } from '@dxos/automerge/automerge-repo';
|
|
7
7
|
import { type Space } from '@dxos/client/echo';
|
|
8
8
|
import { CreateEpochRequest } from '@dxos/client/halo';
|
|
9
9
|
import { type AutomergeContext, ObjectCore } from '@dxos/echo-db';
|
|
10
|
-
import { type ObjectStructure, type SpaceDoc } from '@dxos/echo-protocol';
|
|
10
|
+
import { encodeReference, type ObjectStructure, Reference, type SpaceDoc } from '@dxos/echo-protocol';
|
|
11
11
|
import { requireTypeReference, type S } from '@dxos/echo-schema';
|
|
12
12
|
import { invariant } from '@dxos/invariant';
|
|
13
13
|
import { type FlushRequest } from '@dxos/protocols/proto/dxos/echo/service';
|
|
14
|
+
import { type MaybePromise } from '@dxos/util';
|
|
14
15
|
|
|
15
16
|
export class MigrationBuilder {
|
|
16
17
|
private readonly _repo: Repo;
|
|
@@ -47,22 +48,26 @@ export class MigrationBuilder {
|
|
|
47
48
|
|
|
48
49
|
async migrateObject(
|
|
49
50
|
id: string,
|
|
50
|
-
migrate: (objectStructure: ObjectStructure) => { schema: S.Schema<any>; props: any }
|
|
51
|
+
migrate: (objectStructure: ObjectStructure) => MaybePromise<{ schema: S.Schema<any>; props: any }>,
|
|
51
52
|
) {
|
|
52
53
|
const objectStructure = await this.findObject(id);
|
|
53
54
|
if (!objectStructure) {
|
|
54
55
|
return;
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
const { schema, props } = migrate(objectStructure);
|
|
58
|
+
const { schema, props } = await migrate(objectStructure);
|
|
58
59
|
this._createObject({ id, schema, props });
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
addObject(schema: S.Schema<any>, props: any) {
|
|
62
|
+
async addObject(schema: S.Schema<any>, props: any) {
|
|
62
63
|
const core = this._createObject({ schema, props });
|
|
63
64
|
return core.id;
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
createReference(id: string) {
|
|
68
|
+
return encodeReference(new Reference(id));
|
|
69
|
+
}
|
|
70
|
+
|
|
66
71
|
deleteObject(id: string) {
|
|
67
72
|
this._deleteObjects.push(id);
|
|
68
73
|
}
|
package/src/migrations.test.ts
CHANGED