@dxos/migrations 0.8.4-main.f5c0578 → 0.8.4-main.fcc0d83b33

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/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # @dxos/echo-signals
1
+ # @dxos/migrations
2
2
 
3
3
  ## Installation
4
4
 
5
5
  ```bash
6
- pnpm i @dxos/echo-signals
6
+ pnpm i @dxos/migrations
7
7
  ```
8
8
 
9
9
  ## DXOS Resources
@@ -1,28 +1,25 @@
1
1
  // src/migration-builder.ts
2
- import { next as am } from "@automerge/automerge";
2
+ import { next as A } from "@automerge/automerge";
3
3
  import { CreateEpochRequest } from "@dxos/client/halo";
4
4
  import { ObjectCore, migrateDocument } from "@dxos/echo-db";
5
- import { Reference, SpaceDocVersion, encodeReference } from "@dxos/echo-protocol";
6
- import { requireTypeReference } from "@dxos/echo-schema";
5
+ import { EncodedReference, SpaceDocVersion } from "@dxos/echo-protocol";
6
+ import { getSchemaDXN } from "@dxos/echo/internal";
7
7
  import { invariant } from "@dxos/invariant";
8
+ import { DXN } from "@dxos/keys";
8
9
  var __dxlog_file = "/__w/dxos/dxos/packages/sdk/migrations/src/migration-builder.ts";
9
10
  var MigrationBuilder = class {
10
11
  _space;
11
12
  _repo;
12
13
  _rootDoc;
13
14
  // echoId -> automergeUrl
14
- _newLinks;
15
- _flushIds;
16
- _deleteObjects;
17
- _newRoot;
15
+ _newLinks = {};
16
+ _flushIds = [];
17
+ _deleteObjects = [];
18
+ _newRoot = void 0;
18
19
  constructor(_space) {
19
20
  this._space = _space;
20
- this._newLinks = {};
21
- this._flushIds = [];
22
- this._deleteObjects = [];
23
- this._newRoot = void 0;
24
- this._repo = this._space.db.coreDatabase._repo;
25
- this._rootDoc = this._space.db.coreDatabase._automergeDocLoader.getSpaceRootDocHandle().doc();
21
+ this._repo = this._space.internal.db.coreDatabase._repo;
22
+ this._rootDoc = this._space.internal.db.coreDatabase._automergeDocLoader.getSpaceRootDocHandle().doc();
26
23
  }
27
24
  async findObject(id) {
28
25
  const documentId = (this._rootDoc.links?.[id] || this._newLinks[id])?.toString();
@@ -41,15 +38,7 @@ var MigrationBuilder = class {
41
38
  }
42
39
  const { schema, props } = await migrate(objectStructure);
43
40
  const oldHandle = await this._findObjectContainingHandle(id);
44
- invariant(oldHandle, void 0, {
45
- F: __dxlog_file,
46
- L: 84,
47
- S: this,
48
- A: [
49
- "oldHandle",
50
- ""
51
- ]
52
- });
41
+ invariant(oldHandle, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 59, S: this, A: ["oldHandle", ""] });
53
42
  const newState = {
54
43
  version: SpaceDocVersion.CURRENT,
55
44
  access: {
@@ -58,7 +47,7 @@ var MigrationBuilder = class {
58
47
  objects: {
59
48
  [id]: {
60
49
  system: {
61
- type: encodeReference(requireTypeReference(schema))
50
+ type: EncodedReference.fromDXN(getSchemaDXN(schema))
62
51
  },
63
52
  data: props,
64
53
  meta: {
@@ -68,59 +57,47 @@ var MigrationBuilder = class {
68
57
  }
69
58
  };
70
59
  const migratedDoc = migrateDocument(oldHandle.doc(), newState);
71
- const newHandle = this._repo.import(am.save(migratedDoc));
60
+ const newHandle = this._repo.import(A.save(migratedDoc));
61
+ await newHandle.whenReady();
62
+ invariant(newHandle.url, "Migrated document URL not available after whenReady", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 80, S: this, A: ["newHandle.url", "'Migrated document URL not available after whenReady'"] });
72
63
  this._newLinks[id] = newHandle.url;
73
- this._addHandleToFlushList(newHandle);
64
+ this._addHandleToFlushList(newHandle.documentId);
74
65
  }
75
66
  async addObject(schema, props) {
76
- const core = this._createObject({
67
+ const core = await this._createObject({
77
68
  schema,
78
69
  props
79
70
  });
80
71
  return core.id;
81
72
  }
82
73
  createReference(id) {
83
- return encodeReference(Reference.localObjectReference(id));
74
+ return EncodedReference.fromDXN(DXN.fromLocalObjectId(id));
84
75
  }
85
76
  deleteObject(id) {
86
77
  this._deleteObjects.push(id);
87
78
  }
88
- changeProperties(changeFn) {
79
+ async changeProperties(changeFn) {
89
80
  if (!this._newRoot) {
90
- this._buildNewRoot();
81
+ await this._buildNewRoot();
91
82
  }
92
- invariant(this._newRoot, "New root not created", {
93
- F: __dxlog_file,
94
- L: 126,
95
- S: this,
96
- A: [
97
- "this._newRoot",
98
- "'New root not created'"
99
- ]
100
- });
83
+ invariant(this._newRoot, "New root not created", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 101, S: this, A: ["this._newRoot", "'New root not created'"] });
101
84
  this._newRoot.change((doc) => {
102
85
  const propertiesStructure = doc.objects?.[this._space.properties.id];
103
86
  propertiesStructure && changeFn(propertiesStructure);
104
87
  });
105
- this._addHandleToFlushList(this._newRoot);
88
+ await this._newRoot.whenReady();
89
+ this._addHandleToFlushList(this._newRoot.documentId);
106
90
  }
107
91
  /**
108
92
  * @internal
109
93
  */
110
94
  async _commit() {
111
95
  if (!this._newRoot) {
112
- this._buildNewRoot();
96
+ await this._buildNewRoot();
113
97
  }
114
- invariant(this._newRoot, "New root not created", {
115
- F: __dxlog_file,
116
- L: 142,
117
- S: this,
118
- A: [
119
- "this._newRoot",
120
- "'New root not created'"
121
- ]
122
- });
98
+ invariant(this._newRoot, "New root not created", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 115, S: this, A: ["this._newRoot", "'New root not created'"] });
123
99
  await this._space.db.flush();
100
+ invariant(this._newRoot.url, "New root URL not available", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 118, S: this, A: ["this._newRoot.url", "'New root URL not available'"] });
124
101
  await this._space.internal.createEpoch({
125
102
  migration: CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT,
126
103
  automergeRootUrl: this._newRoot.url
@@ -135,7 +112,7 @@ var MigrationBuilder = class {
135
112
  await docHandle.whenReady();
136
113
  return docHandle;
137
114
  }
138
- _buildNewRoot() {
115
+ async _buildNewRoot() {
139
116
  const links = {
140
117
  ...this._rootDoc.links ?? {}
141
118
  };
@@ -143,7 +120,7 @@ var MigrationBuilder = class {
143
120
  delete links[id];
144
121
  }
145
122
  for (const [id, url] of Object.entries(this._newLinks)) {
146
- links[id] = new am.RawString(url);
123
+ links[id] = new A.RawString(url);
147
124
  }
148
125
  this._newRoot = this._repo.create({
149
126
  version: SpaceDocVersion.CURRENT,
@@ -153,15 +130,16 @@ var MigrationBuilder = class {
153
130
  objects: this._rootDoc.objects,
154
131
  links
155
132
  });
156
- this._addHandleToFlushList(this._newRoot);
133
+ await this._newRoot.whenReady();
134
+ this._addHandleToFlushList(this._newRoot.documentId);
157
135
  }
158
- _createObject({ id, schema, props }) {
136
+ async _createObject({ id, schema, props }) {
159
137
  const core = new ObjectCore();
160
138
  if (id) {
161
139
  core.id = id;
162
140
  }
163
141
  core.initNewObject(props);
164
- core.setType(requireTypeReference(schema));
142
+ core.setType(EncodedReference.fromDXN(getSchemaDXN(schema)));
165
143
  const newHandle = this._repo.create({
166
144
  version: SpaceDocVersion.CURRENT,
167
145
  access: {
@@ -171,25 +149,29 @@ var MigrationBuilder = class {
171
149
  [core.id]: core.getDoc()
172
150
  }
173
151
  });
152
+ await newHandle.whenReady();
174
153
  this._newLinks[core.id] = newHandle.url;
175
- this._addHandleToFlushList(newHandle);
154
+ this._addHandleToFlushList(newHandle.documentId);
176
155
  return core;
177
156
  }
178
- _addHandleToFlushList(handle) {
179
- this._flushIds.push(handle.documentId);
157
+ _addHandleToFlushList(id) {
158
+ this._flushIds.push(id);
180
159
  }
181
160
  };
182
161
 
183
162
  // src/migrations.ts
184
- import { SpaceState, live } from "@dxos/client/echo";
163
+ import { Atom } from "@effect-atom/atom";
164
+ import * as Registry from "@effect-atom/atom/Registry";
165
+ import { SpaceState } from "@dxos/client/echo";
185
166
  import { invariant as invariant2 } from "@dxos/invariant";
186
167
  var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/migrations/src/migrations.ts";
187
168
  var Migrations = class {
188
169
  static namespace;
189
170
  static migrations = [];
190
- static _state = live({
171
+ static _registry = Registry.make();
172
+ static _stateAtom = Atom.make({
191
173
  running: []
192
- });
174
+ }).pipe(Atom.keepAlive);
193
175
  static get versionProperty() {
194
176
  return this.namespace && `${this.namespace}.version`;
195
177
  }
@@ -197,40 +179,17 @@ var Migrations = class {
197
179
  return this.migrations[this.migrations.length - 1]?.version;
198
180
  }
199
181
  static running(space) {
200
- return this._state.running.includes(space.key.toHex());
182
+ const state = this._registry.get(this._stateAtom);
183
+ return state.running.includes(space.key.toHex());
201
184
  }
202
185
  static define(namespace, migrations) {
203
186
  this.namespace = namespace;
204
187
  this.migrations = migrations;
205
188
  }
206
189
  static async migrate(space, targetVersion) {
207
- invariant2(!this.running(space), "Migration already running", {
208
- F: __dxlog_file2,
209
- L: 44,
210
- S: this,
211
- A: [
212
- "!this.running(space)",
213
- "'Migration already running'"
214
- ]
215
- });
216
- invariant2(this.versionProperty, "Migrations namespace not set", {
217
- F: __dxlog_file2,
218
- L: 45,
219
- S: this,
220
- A: [
221
- "this.versionProperty",
222
- "'Migrations namespace not set'"
223
- ]
224
- });
225
- invariant2(space.state.get() === SpaceState.SPACE_READY, "Space not ready", {
226
- F: __dxlog_file2,
227
- L: 46,
228
- S: this,
229
- A: [
230
- "space.state.get() === SpaceState.SPACE_READY",
231
- "'Space not ready'"
232
- ]
233
- });
190
+ invariant2(!this.running(space), "Migration already running", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 31, S: this, A: ["!this.running(space)", "'Migration already running'"] });
191
+ invariant2(this.versionProperty, "Migrations namespace not set", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 32, S: this, A: ["this.versionProperty", "'Migrations namespace not set'"] });
192
+ invariant2(space.state.get() === SpaceState.SPACE_READY, "Space not ready", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 33, S: this, A: ["space.state.get() === SpaceState.SPACE_READY", "'Space not ready'"] });
234
193
  const currentVersion = space.properties[this.versionProperty];
235
194
  const currentIndex = this.migrations.findIndex((m) => m.version === currentVersion) + 1;
236
195
  const i = this.migrations.findIndex((m) => m.version === targetVersion);
@@ -238,7 +197,14 @@ var Migrations = class {
238
197
  if (currentIndex === targetIndex) {
239
198
  return false;
240
199
  }
241
- this._state.running.push(space.key.toHex());
200
+ const spaceKey = space.key.toHex();
201
+ const currentState = this._registry.get(this._stateAtom);
202
+ this._registry.set(this._stateAtom, {
203
+ running: [
204
+ ...currentState.running,
205
+ spaceKey
206
+ ]
207
+ });
242
208
  if (targetIndex > currentIndex) {
243
209
  const migrations = this.migrations.slice(currentIndex, targetIndex);
244
210
  for (const migration of migrations) {
@@ -247,22 +213,17 @@ var Migrations = class {
247
213
  space,
248
214
  builder
249
215
  });
250
- builder.changeProperties((propertiesStructure) => {
251
- invariant2(this.versionProperty, "Migrations namespace not set", {
252
- F: __dxlog_file2,
253
- L: 62,
254
- S: this,
255
- A: [
256
- "this.versionProperty",
257
- "'Migrations namespace not set'"
258
- ]
259
- });
216
+ await builder.changeProperties((propertiesStructure) => {
217
+ invariant2(this.versionProperty, "Migrations namespace not set", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 58, S: this, A: ["this.versionProperty", "'Migrations namespace not set'"] });
260
218
  propertiesStructure.data[this.versionProperty] = migration.version;
261
219
  });
262
220
  await builder._commit();
263
221
  }
264
222
  }
265
- this._state.running.splice(this._state.running.indexOf(space.key.toHex()), 1);
223
+ const finalState = this._registry.get(this._stateAtom);
224
+ this._registry.set(this._stateAtom, {
225
+ running: finalState.running.filter((key) => key !== spaceKey)
226
+ });
266
227
  return true;
267
228
  }
268
229
  };
@@ -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 { type Doc, next as am } from '@automerge/automerge';\nimport { type AnyDocumentId, type DocumentId } from '@automerge/automerge-repo';\nimport { type Schema } from 'effect';\n\nimport { type Space } from '@dxos/client/echo';\nimport { CreateEpochRequest } from '@dxos/client/halo';\nimport { type DocHandleProxy, ObjectCore, type RepoProxy, migrateDocument } from '@dxos/echo-db';\nimport {\n type DatabaseDirectory,\n type ObjectStructure,\n Reference,\n SpaceDocVersion,\n encodeReference,\n} from '@dxos/echo-protocol';\nimport { requireTypeReference } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { type MaybePromise } from '@dxos/util';\n\n/*\n\nConsidering a better API for this:\n\n```ts\nconst migration = space.db.beginMigration(); // all actions are not visible to queries and are only applied once you call `apply`\n\nmigration.applyObjectMigration(defineMigration(From, To, { ... }));\n\nmigration.delete(id);\nmigration.add(obj);\n\nawait migration.apply(); // Will create new epoch.\n```\n\n*/\n\n// TODO(dmaretskyi): We no longer need to hook into ECHO internals, with the changes to echo APIs.\nexport class MigrationBuilder {\n private readonly _repo: RepoProxy;\n private readonly _rootDoc: Doc<DatabaseDirectory>;\n\n // echoId -> automergeUrl\n private readonly _newLinks: Record<string, string> = {};\n private readonly _flushIds: DocumentId[] = [];\n private readonly _deleteObjects: string[] = [];\n\n private _newRoot?: DocHandleProxy<DatabaseDirectory> = undefined;\n\n constructor(private readonly _space: Space) {\n this._repo = this._space.db.coreDatabase._repo;\n // TODO(wittjosiah): Accessing private API.\n this._rootDoc = (this._space.db.coreDatabase as any)._automergeDocLoader\n .getSpaceRootDocHandle()\n .doc() as Doc<DatabaseDirectory>;\n }\n\n async findObject(id: string): Promise<ObjectStructure | undefined> {\n const documentId = (this._rootDoc.links?.[id] || this._newLinks[id])?.toString() 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.doc() as Doc<DatabaseDirectory>;\n return doc.objects?.[id];\n }\n\n async migrateObject(\n id: string,\n migrate: (objectStructure: ObjectStructure) => MaybePromise<{ schema: Schema.Schema.AnyNoContext; props: any }>,\n ): Promise<void> {\n const objectStructure = await this.findObject(id);\n if (!objectStructure) {\n return;\n }\n\n const { schema, props } = await migrate(objectStructure);\n\n const oldHandle = await this._findObjectContainingHandle(id);\n invariant(oldHandle);\n\n const newState: DatabaseDirectory = {\n version: SpaceDocVersion.CURRENT,\n access: {\n spaceKey: this._space.key.toHex(),\n },\n objects: {\n [id]: {\n system: {\n type: encodeReference(requireTypeReference(schema)),\n },\n data: props,\n meta: {\n keys: [],\n },\n },\n },\n };\n const migratedDoc = migrateDocument(oldHandle.doc() as Doc<DatabaseDirectory>, newState);\n const newHandle = this._repo.import<DatabaseDirectory>(am.save(migratedDoc));\n this._newLinks[id] = newHandle.url;\n this._addHandleToFlushList(newHandle);\n }\n\n async addObject(schema: Schema.Schema.AnyNoContext, props: any): Promise<string> {\n const core = this._createObject({ schema, props });\n return core.id;\n }\n\n createReference(id: string) {\n return encodeReference(Reference.localObjectReference(id));\n }\n\n deleteObject(id: string): void {\n this._deleteObjects.push(id);\n }\n\n changeProperties(changeFn: (properties: ObjectStructure) => void): void {\n if (!this._newRoot) {\n this._buildNewRoot();\n }\n invariant(this._newRoot, 'New root not created');\n\n this._newRoot.change((doc: DatabaseDirectory) => {\n const propertiesStructure = doc.objects?.[this._space.properties.id];\n propertiesStructure && changeFn(propertiesStructure);\n });\n this._addHandleToFlushList(this._newRoot);\n }\n\n /**\n * @internal\n */\n async _commit(): Promise<void> {\n if (!this._newRoot) {\n this._buildNewRoot();\n }\n invariant(this._newRoot, 'New root not created');\n\n await this._space.db.flush();\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 async _findObjectContainingHandle(id: string): Promise<DocHandleProxy<DatabaseDirectory> | undefined> {\n const documentId = (this._rootDoc.links?.[id] || this._newLinks[id])?.toString() as AnyDocumentId | undefined;\n const docHandle = documentId && this._repo.find(documentId);\n if (!docHandle) {\n return undefined;\n }\n\n await docHandle.whenReady();\n return docHandle;\n }\n\n private _buildNewRoot(): void {\n const links = { ...(this._rootDoc.links ?? {}) };\n for (const id of this._deleteObjects) {\n delete links[id];\n }\n\n for (const [id, url] of Object.entries(this._newLinks)) {\n links[id] = new am.RawString(url);\n }\n\n this._newRoot = this._repo.create<DatabaseDirectory>({\n version: SpaceDocVersion.CURRENT,\n access: {\n spaceKey: this._space.key.toHex(),\n },\n objects: this._rootDoc.objects,\n links,\n });\n this._addHandleToFlushList(this._newRoot);\n }\n\n private _createObject({\n id,\n schema,\n props,\n }: {\n id?: string;\n schema: Schema.Schema.AnyNoContext;\n props: any;\n }): ObjectCore {\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<DatabaseDirectory>({\n version: SpaceDocVersion.CURRENT,\n access: {\n spaceKey: this._space.key.toHex(),\n },\n objects: {\n [core.id]: core.getDoc() as ObjectStructure,\n },\n });\n this._newLinks[core.id] = newHandle.url;\n this._addHandleToFlushList(newHandle);\n\n return core;\n }\n\n private _addHandleToFlushList(handle: DocHandleProxy<any>): void {\n this._flushIds.push(handle.documentId);\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Space, SpaceState, live } 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 = live<{ 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): boolean {\n return this._state.running.includes(space.key.toHex());\n }\n\n static define(namespace: string, migrations: Migration[]): void {\n this.namespace = namespace;\n this.migrations = migrations;\n }\n\n static async migrate(space: Space, targetVersion?: string | number): Promise<boolean> {\n invariant(!this.running(space), 'Migration already running');\n invariant(this.versionProperty, 'Migrations namespace not set');\n invariant(space.state.get() === SpaceState.SPACE_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,QAAQC,UAAU;AAKrC,SAASC,0BAA0B;AACnC,SAA8BC,YAA4BC,uBAAuB;AACjF,SAGEC,WACAC,iBACAC,uBACK;AACP,SAASC,4BAA4B;AACrC,SAASC,iBAAiB;;AAqBnB,IAAMC,mBAAN,MAAMA;;EACMC;EACAC;;EAGAC;EACAC;EACAC;EAETC;EAER,YAA6BC,QAAe;SAAfA,SAAAA;SANZJ,YAAoC,CAAC;SACrCC,YAA0B,CAAA;SAC1BC,iBAA2B,CAAA;SAEpCC,WAA+CE;AAGrD,SAAKP,QAAQ,KAAKM,OAAOE,GAAGC,aAAaT;AAEzC,SAAKC,WAAY,KAAKK,OAAOE,GAAGC,aAAqBC,oBAClDC,sBAAqB,EACrBC,IAAG;EACR;EAEA,MAAMC,WAAWC,IAAkD;AACjE,UAAMC,cAAc,KAAKd,SAASe,QAAQF,EAAAA,KAAO,KAAKZ,UAAUY,EAAAA,IAAMG,SAAAA;AACtE,UAAMC,YAAYH,cAAc,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,CAAA;AAE3E,WAAO;EACT;AACF;",
6
- "names": ["next", "am", "CreateEpochRequest", "ObjectCore", "migrateDocument", "Reference", "SpaceDocVersion", "encodeReference", "requireTypeReference", "invariant", "MigrationBuilder", "_repo", "_rootDoc", "_newLinks", "_flushIds", "_deleteObjects", "_newRoot", "_space", "undefined", "db", "coreDatabase", "_automergeDocLoader", "getSpaceRootDocHandle", "doc", "findObject", "id", "documentId", "links", "toString", "docHandle", "find", "whenReady", "objects", "migrateObject", "migrate", "objectStructure", "schema", "props", "oldHandle", "_findObjectContainingHandle", "newState", "version", "CURRENT", "access", "spaceKey", "key", "toHex", "system", "type", "data", "meta", "keys", "migratedDoc", "newHandle", "import", "save", "url", "_addHandleToFlushList", "addObject", "core", "_createObject", "createReference", "localObjectReference", "deleteObject", "push", "changeProperties", "changeFn", "_buildNewRoot", "change", "propertiesStructure", "properties", "_commit", "flush", "internal", "createEpoch", "migration", "Migration", "REPLACE_AUTOMERGE_ROOT", "automergeRootUrl", "Object", "entries", "RawString", "create", "initNewObject", "setType", "getDoc", "handle", "SpaceState", "live", "invariant", "Migrations", "namespace", "migrations", "_state", "live", "running", "versionProperty", "targetVersion", "length", "version", "space", "includes", "key", "toHex", "define", "migrate", "invariant", "state", "get", "SpaceState", "SPACE_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 { next as A, type Doc } from '@automerge/automerge';\nimport { type AnyDocumentId, type DocumentId } from '@automerge/automerge-repo';\nimport type * as Schema from 'effect/Schema';\n\nimport { type Space } from '@dxos/client/echo';\nimport { CreateEpochRequest } from '@dxos/client/halo';\nimport { type DocHandleProxy, ObjectCore, type RepoProxy, migrateDocument } from '@dxos/echo-db';\nimport { type DatabaseDirectory, EncodedReference, type ObjectStructure, SpaceDocVersion } from '@dxos/echo-protocol';\nimport { getSchemaDXN } from '@dxos/echo/internal';\nimport { invariant } from '@dxos/invariant';\nimport { DXN } from '@dxos/keys';\nimport { type MaybePromise } from '@dxos/util';\n\n/*\n\nConsidering a better API for this:\n\n```ts\nconst migration = space.db.beginMigration(); // all actions are not visible to queries and are only applied once you call `apply`\n\nmigration.applyObjectMigration(defineMigration(From, To, { ... }));\n\nmigration.delete(id);\nmigration.add(obj);\n\nawait migration.apply(); // Will create new epoch.\n```\n\n*/\n\n// TODO(dmaretskyi): We no longer need to hook into ECHO internals, with the changes to echo APIs.\nexport class MigrationBuilder {\n private readonly _repo: RepoProxy;\n private readonly _rootDoc: Doc<DatabaseDirectory>;\n\n // echoId -> automergeUrl\n private readonly _newLinks: Record<string, string> = {};\n private readonly _flushIds: DocumentId[] = [];\n private readonly _deleteObjects: string[] = [];\n\n private _newRoot?: DocHandleProxy<DatabaseDirectory> = undefined;\n\n constructor(private readonly _space: Space) {\n this._repo = this._space.internal.db.coreDatabase._repo;\n // TODO(wittjosiah): Accessing private API.\n this._rootDoc = (this._space.internal.db.coreDatabase as any)._automergeDocLoader\n .getSpaceRootDocHandle()\n .doc() as Doc<DatabaseDirectory>;\n }\n\n async findObject(id: string): Promise<ObjectStructure | undefined> {\n const documentId = (this._rootDoc.links?.[id] || this._newLinks[id])?.toString() 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.doc() as Doc<DatabaseDirectory>;\n return doc.objects?.[id];\n }\n\n async migrateObject(\n id: string,\n migrate: (objectStructure: ObjectStructure) => MaybePromise<{ schema: Schema.Schema.AnyNoContext; props: any }>,\n ): Promise<void> {\n const objectStructure = await this.findObject(id);\n if (!objectStructure) {\n return;\n }\n\n const { schema, props } = await migrate(objectStructure);\n\n const oldHandle = await this._findObjectContainingHandle(id);\n invariant(oldHandle);\n\n const newState: DatabaseDirectory = {\n version: SpaceDocVersion.CURRENT,\n access: {\n spaceKey: this._space.key.toHex(),\n },\n objects: {\n [id]: {\n system: {\n type: EncodedReference.fromDXN(getSchemaDXN(schema)!),\n },\n data: props,\n meta: {\n keys: [],\n },\n },\n },\n };\n const migratedDoc = migrateDocument(oldHandle.doc() as Doc<DatabaseDirectory>, newState);\n const newHandle = this._repo.import<DatabaseDirectory>(A.save(migratedDoc));\n await newHandle.whenReady();\n invariant(newHandle.url, 'Migrated document URL not available after whenReady');\n this._newLinks[id] = newHandle.url;\n this._addHandleToFlushList(newHandle.documentId!);\n }\n\n async addObject(schema: Schema.Schema.AnyNoContext, props: any): Promise<string> {\n const core = await this._createObject({ schema, props });\n return core.id;\n }\n\n createReference(id: string) {\n return EncodedReference.fromDXN(DXN.fromLocalObjectId(id));\n }\n\n deleteObject(id: string): void {\n this._deleteObjects.push(id);\n }\n\n async changeProperties(changeFn: (properties: ObjectStructure) => void): Promise<void> {\n if (!this._newRoot) {\n await this._buildNewRoot();\n }\n invariant(this._newRoot, 'New root not created');\n\n this._newRoot.change((doc: DatabaseDirectory) => {\n const propertiesStructure = doc.objects?.[this._space.properties.id];\n propertiesStructure && changeFn(propertiesStructure);\n });\n await this._newRoot.whenReady();\n this._addHandleToFlushList(this._newRoot.documentId!);\n }\n\n /**\n * @internal\n */\n async _commit(): Promise<void> {\n if (!this._newRoot) {\n await this._buildNewRoot();\n }\n invariant(this._newRoot, 'New root not created');\n\n await this._space.db.flush();\n\n // Create new epoch.\n invariant(this._newRoot.url, 'New root URL not available');\n await this._space.internal.createEpoch({\n migration: CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT,\n automergeRootUrl: this._newRoot.url,\n });\n }\n\n private async _findObjectContainingHandle(id: string): Promise<DocHandleProxy<DatabaseDirectory> | undefined> {\n const documentId = (this._rootDoc.links?.[id] || this._newLinks[id])?.toString() as AnyDocumentId | undefined;\n const docHandle = documentId && this._repo.find(documentId);\n if (!docHandle) {\n return undefined;\n }\n\n await docHandle.whenReady();\n return docHandle;\n }\n\n private async _buildNewRoot(): Promise<void> {\n const links = { ...(this._rootDoc.links ?? {}) };\n for (const id of this._deleteObjects) {\n delete links[id];\n }\n\n for (const [id, url] of Object.entries(this._newLinks)) {\n links[id] = new A.RawString(url);\n }\n\n this._newRoot = this._repo.create<DatabaseDirectory>({\n version: SpaceDocVersion.CURRENT,\n access: {\n spaceKey: this._space.key.toHex(),\n },\n objects: this._rootDoc.objects,\n links,\n });\n await this._newRoot.whenReady();\n this._addHandleToFlushList(this._newRoot.documentId!);\n }\n\n private async _createObject({\n id,\n schema,\n props,\n }: {\n id?: string;\n schema: Schema.Schema.AnyNoContext;\n props: any;\n }): Promise<ObjectCore> {\n const core = new ObjectCore();\n if (id) {\n core.id = id;\n }\n\n core.initNewObject(props);\n core.setType(EncodedReference.fromDXN(getSchemaDXN(schema)!));\n const newHandle = this._repo.create<DatabaseDirectory>({\n version: SpaceDocVersion.CURRENT,\n access: {\n spaceKey: this._space.key.toHex(),\n },\n objects: {\n [core.id]: core.getDoc() as ObjectStructure,\n },\n });\n await newHandle.whenReady();\n this._newLinks[core.id] = newHandle.url!;\n this._addHandleToFlushList(newHandle.documentId!);\n\n return core;\n }\n\n private _addHandleToFlushList(id: DocumentId): void {\n this._flushIds.push(id);\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { Atom } from '@effect-atom/atom';\nimport * as Registry from '@effect-atom/atom/Registry';\n\nimport { type Space, 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 _registry = Registry.make();\n private static _stateAtom = Atom.make<{ running: string[] }>({ running: [] }).pipe(Atom.keepAlive);\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): boolean {\n const state = this._registry.get(this._stateAtom);\n return state.running.includes(space.key.toHex());\n }\n\n static define(namespace: string, migrations: Migration[]): void {\n this.namespace = namespace;\n this.migrations = migrations;\n }\n\n static async migrate(space: Space, targetVersion?: string | number): Promise<boolean> {\n invariant(!this.running(space), 'Migration already running');\n invariant(this.versionProperty, 'Migrations namespace not set');\n invariant(space.state.get() === SpaceState.SPACE_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 const spaceKey = space.key.toHex();\n const currentState = this._registry.get(this._stateAtom);\n this._registry.set(this._stateAtom, { running: [...currentState.running, spaceKey] });\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 await 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 const finalState = this._registry.get(this._stateAtom);\n this._registry.set(this._stateAtom, { running: finalState.running.filter((key) => key !== spaceKey) });\n\n return true;\n }\n}\n"],
5
+ "mappings": ";AAIA,SAASA,QAAQC,SAAmB;AAKpC,SAASC,0BAA0B;AACnC,SAA8BC,YAA4BC,uBAAuB;AACjF,SAAiCC,kBAAwCC,uBAAuB;AAChG,SAASC,oBAAoB;AAC7B,SAASC,iBAAiB;AAC1B,SAASC,WAAW;AAGpB,IAAA,eAAA;AAmBmBC,IAAiB,mBAAjBA,MAAiB;EACjBC;EAEjB;EACiBC;;EAEAC,YAAAA,CAAAA;EAETC,YAA+CC,CAAAA;EAEvD,iBA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AAUpB,UAAWuB,CAAAA,MAAAA,EAAM,YAAO,cAAA,IAAA;AAC5D,UAAIN,IAAAA,KAAAA,WAAiBK,UAAa,CAAA,MAAA,EAAA,YAAA,aAAA;UAChC,cAAO,MAAA,KAAA,KAAA,WAAA,SAAA,IAAA;AACT,QAAA,iBAAA,aAAA;AAEA,aAAME;IACN;AACA,UAAKvB,WAAUwB,MAAQ,IAACvB,MAAAA;UAAcE,eAAS,KAAA,UAAA,IAAA,KAAA,UAAA;mBAAIsB,IAAAA,KAAatB,YAAO;eAAEoB;QAAS,GAAA,aAAA;QAAC;MAC/EF;;QAEF,cAAWK,cAAa3B;YACtB,aAAM4B,KAAcC,WAAAA,MAAiBpB,cAAAA,WAAAA;iBAC/BkB,aAAc,YAAC;cAAElB,UAAAA,IAAAA,iBAAAA,KAAAA;cAAOmB,UAAAA,KAAAA;UAAQ;UACtC;;cAEEE,QAAAA,iBAAyB,CAAA,wBAAwBH;AACnD,UAAAf,WAAA,KAAA,iBAAA,gCAAA,EAAA,YAAA,YAAA,GAAAd,eAAA,GAAA,IAAA,GAAA,MAAA,GAAA,CAAA,wBAAA,gCAAA,EAAA,CAAA;AACA,8BAAqB,KAAA,KAAA,eAAA,IAAA,UAAA;QACvB,CAAA;AACF,cAAA,QAAA,QAAA;MACA;IACA;UAAsCM,aAAS2B,KAAW3B,UAAQ4B,IAAM,KAAEC,UAAQA;AAAkB,SAAA,UAAA,IAAA,KAAA,YAAA;MAEpG,SAAO,WAAA,QAAA,OAAA,CAAA,QAAA,QAAA,QAAA;IACT,CAAA;AACF,WAAA;;;",
6
+ "names": ["next", "A", "CreateEpochRequest", "ObjectCore", "migrateDocument", "EncodedReference", "SpaceDocVersion", "getSchemaDXN", "invariant", "DXN", "_repo", "_rootDoc", "_newLinks", "_deleteObjects", "_newRoot", "undefined", "_space", "internal", "db", "coreDatabase", "findObject", "docHandle", "objects", "migrateObject", "migrate", "objectStructure", "oldHandle", "newState", "version", "access", "spaceKey", "system", "data", "props", "meta", "keys", "newHandle", "whenReady", "id", "_addHandleToFlushList", "addObject", "schema", "createReference", "deleteObject", "changeProperties", "changeFn", "_buildNewRoot", "propertiesStructure", "properties", "migration", "REPLACE_AUTOMERGE_ROOT", "automergeRootUrl", "documentId", "url", "create", "links", "_createObject", "core", "initNewObject", "CURRENT", "Atom", "Registry", "SpaceState", "invariant", "__dxlog_file", "Migrations", "migrations", "_registry", "_stateAtom", "Atom", "running", "keepAlive", "versionProperty", "namespace", "targetVersion", "space", "state", "define", "invariant", "get", "SpaceState", "currentVersion", "properties", "currentIndex", "findIndex", "version", "i", "m", "targetIndex", "length", "spaceKey", "set", "currentState", "migration", "builder", "MigrationBuilder", "propertiesStructure", "finalState", "filter", "key"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/migration-builder.ts":{"bytes":22168,"imports":[{"path":"@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"},"src/migrations.ts":{"bytes":9709,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"src/migration-builder.ts","kind":"import-statement","original":"./migration-builder"}],"format":"esm"},"src/index.ts":{"bytes":653,"imports":[{"path":"src/migration-builder.ts","kind":"import-statement","original":"./migration-builder"},{"path":"src/migrations.ts","kind":"import-statement","original":"./migrations"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15629},"dist/lib/browser/index.mjs":{"imports":[{"path":"@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":"src/index.ts","inputs":{"src/migration-builder.ts":{"bytesInOutput":4936},"src/index.ts":{"bytesInOutput":0},"src/migrations.ts":{"bytesInOutput":2727}},"bytes":7793}}}
1
+ {"inputs":{"src/migration-builder.ts":{"bytes":23409,"imports":[{"path":"@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/internal","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"src/migrations.ts":{"bytes":10982,"imports":[{"path":"@effect-atom/atom","kind":"import-statement","external":true},{"path":"@effect-atom/atom/Registry","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"src/migration-builder.ts","kind":"import-statement","original":"./migration-builder"}],"format":"esm"},"src/index.ts":{"bytes":575,"imports":[{"path":"src/migration-builder.ts","kind":"import-statement","original":"./migration-builder"},{"path":"src/migrations.ts","kind":"import-statement","original":"./migrations"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":16635},"dist/lib/browser/index.mjs":{"imports":[{"path":"@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/internal","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@effect-atom/atom","kind":"import-statement","external":true},{"path":"@effect-atom/atom/Registry","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":"src/index.ts","inputs":{"src/migration-builder.ts":{"bytesInOutput":5430},"src/index.ts":{"bytesInOutput":0},"src/migrations.ts":{"bytesInOutput":3055}},"bytes":8615}}}