@dxos/migrations 0.8.4-main.dedc0f3 → 0.8.4-main.ead640a

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.
@@ -1,9 +1,9 @@
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
+ import { requireTypeReference } from "@dxos/echo/internal";
4
5
  import { ObjectCore, migrateDocument } from "@dxos/echo-db";
5
6
  import { Reference, SpaceDocVersion, encodeReference } from "@dxos/echo-protocol";
6
- import { requireTypeReference } from "@dxos/echo-schema";
7
7
  import { invariant } from "@dxos/invariant";
8
8
  function _define_property(obj, key, value) {
9
9
  if (key in obj) {
@@ -64,7 +64,7 @@ var MigrationBuilder = class {
64
64
  }
65
65
  };
66
66
  const migratedDoc = migrateDocument(oldHandle.doc(), newState);
67
- const newHandle = this._repo.import(am.save(migratedDoc));
67
+ const newHandle = this._repo.import(A.save(migratedDoc));
68
68
  this._newLinks[id] = newHandle.url;
69
69
  this._addHandleToFlushList(newHandle);
70
70
  }
@@ -139,7 +139,7 @@ var MigrationBuilder = class {
139
139
  delete links[id];
140
140
  }
141
141
  for (const [id, url] of Object.entries(this._newLinks)) {
142
- links[id] = new am.RawString(url);
142
+ links[id] = new A.RawString(url);
143
143
  }
144
144
  this._newRoot = this._repo.create({
145
145
  version: SpaceDocVersion.CURRENT,
@@ -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;EAmBX,MAAMC,WAAWC,IAAkD;AACjE,UAAMC,cAAc,KAAKC,SAASC,QAAQH,EAAAA,KAAO,KAAKI,UAAUJ,EAAAA,IAAMK,SAAAA;AACtE,UAAMC,YAAYL,cAAc,KAAKM,MAAMC,KAAKP,UAAAA;AAChD,QAAI,CAACK,WAAW;AACd,aAAOG;IACT;AAEA,UAAMH,UAAUI,UAAS;AACzB,UAAMC,MAAML,UAAUK,IAAG;AACzB,WAAOA,IAAIC,UAAUZ,EAAAA;EACvB;EAEA,MAAMa,cACJb,IACAc,SACe;AACf,UAAMC,kBAAkB,MAAM,KAAKhB,WAAWC,EAAAA;AAC9C,QAAI,CAACe,iBAAiB;AACpB;IACF;AAEA,UAAM,EAAEC,QAAQC,MAAK,IAAK,MA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,QAAQ+B,QAAQ9B,MAAMG,IAAIC,MAAK,CAAA,GAAK,CAAA;AAE3E,WAAO;EACT;AACF;AAlDE2B,kBADWvC,YACJE,aAAP,MAAA;AACAqC,kBAFWvC,YAEJI,cAA0B,CAAA,CAAE;AACnCmC,kBAHWvC,YAGIS,UAAS+B,KAA4B;EAAEjC,SAAS,CAAA;AAAG,CAAA,CAAA;",
6
- "names": ["next", "am", "CreateEpochRequest", "ObjectCore", "migrateDocument", "Reference", "SpaceDocVersion", "encodeReference", "requireTypeReference", "invariant", "MigrationBuilder", "findObject", "id", "documentId", "_rootDoc", "links", "_newLinks", "toString", "docHandle", "_repo", "find", "undefined", "whenReady", "doc", "objects", "migrateObject", "migrate", "objectStructure", "schema", "props", "oldHandle", "_findObjectContainingHandle", "newState", "version", "CURRENT", "access", "spaceKey", "_space", "key", "toHex", "system", "type", "data", "meta", "keys", "migratedDoc", "newHandle", "import", "save", "url", "_addHandleToFlushList", "addObject", "core", "_createObject", "createReference", "localObjectReference", "deleteObject", "_deleteObjects", "push", "changeProperties", "changeFn", "_newRoot", "_buildNewRoot", "change", "propertiesStructure", "properties", "_commit", "db", "flush", "internal", "createEpoch", "migration", "Migration", "REPLACE_AUTOMERGE_ROOT", "automergeRootUrl", "Object", "entries", "RawString", "create", "initNewObject", "setType", "getDoc", "handle", "_flushIds", "coreDatabase", "_automergeDocLoader", "getSpaceRootDocHandle", "SpaceState", "live", "invariant", "Migrations", "versionProperty", "namespace", "targetVersion", "migrations", "length", "version", "running", "space", "_state", "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", "_define_property", "live"]
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 { requireTypeReference } from '@dxos/echo/internal';\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 { 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>(A.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 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 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,SAASA,QAAQC,SAAmB;AAKpC,SAASC,0BAA0B;AACnC,SAASC,4BAA4B;AACrC,SAA8BC,YAA4BC,uBAAuB;AACjF,SAGEC,WACAC,iBACAC,uBACK;AACP,SAASC,iBAAiB;;;;;;;;;;;;;;;AAqBnB,IAAMC,mBAAN,MAAMA;EAmBX,MAAMC,WAAWC,IAAkD;AACjE,UAAMC,cAAc,KAAKC,SAASC,QAAQH,EAAAA,KAAO,KAAKI,UAAUJ,EAAAA,IAAMK,SAAAA;AACtE,UAAMC,YAAYL,cAAc,KAAKM,MAAMC,KAAKP,UAAAA;AAChD,QAAI,CAACK,WAAW;AACd,aAAOG;IACT;AAEA,UAAMH,UAAUI,UAAS;AACzB,UAAMC,MAAML,UAAUK,IAAG;AACzB,WAAOA,IAAIC,UAAUZ,EAAAA;EACvB;EAEA,MAAMa,cACJb,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C,KAAK,KAAKlC,eAAe,IAAI4B,UAAUvB;QAC7D,CAAA;AACA,cAAMwB,QAAQM,QAAO;MACvB;IACF;AACA,SAAK3B,OAAOF,QAAQ8B,OAAO,KAAK5B,OAAOF,QAAQ+B,QAAQ9B,MAAMG,IAAIC,MAAK,CAAA,GAAK,CAAA;AAE3E,WAAO;EACT;AACF;AAlDE2B,kBADWvC,YACJE,aAAP,MAAA;AACAqC,kBAFWvC,YAEJI,cAA0B,CAAA,CAAE;AACnCmC,kBAHWvC,YAGIS,UAAS+B,KAA4B;EAAEjC,SAAS,CAAA;AAAG,CAAA,CAAA;",
6
+ "names": ["next", "A", "CreateEpochRequest", "requireTypeReference", "ObjectCore", "migrateDocument", "Reference", "SpaceDocVersion", "encodeReference", "invariant", "MigrationBuilder", "findObject", "id", "documentId", "_rootDoc", "links", "_newLinks", "toString", "docHandle", "_repo", "find", "undefined", "whenReady", "doc", "objects", "migrateObject", "migrate", "objectStructure", "schema", "props", "oldHandle", "_findObjectContainingHandle", "newState", "version", "CURRENT", "access", "spaceKey", "_space", "key", "toHex", "system", "type", "data", "meta", "keys", "migratedDoc", "newHandle", "import", "save", "url", "_addHandleToFlushList", "addObject", "core", "_createObject", "createReference", "localObjectReference", "deleteObject", "_deleteObjects", "push", "changeProperties", "changeFn", "_newRoot", "_buildNewRoot", "change", "propertiesStructure", "properties", "_commit", "db", "flush", "internal", "createEpoch", "migration", "Migration", "REPLACE_AUTOMERGE_ROOT", "automergeRootUrl", "Object", "entries", "RawString", "create", "initNewObject", "setType", "getDoc", "handle", "_flushIds", "coreDatabase", "_automergeDocLoader", "getSpaceRootDocHandle", "SpaceState", "live", "invariant", "Migrations", "versionProperty", "namespace", "targetVersion", "migrations", "length", "version", "running", "space", "_state", "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", "_define_property", "live"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/migration-builder.ts":{"bytes":22849,"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":10109,"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":15867},"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":5408},"src/index.ts":{"bytesInOutput":0},"src/migrations.ts":{"bytesInOutput":3050}},"bytes":8588}}}
1
+ {"inputs":{"src/migration-builder.ts":{"bytes":22856,"imports":[{"path":"@automerge/automerge","kind":"import-statement","external":true},{"path":"@dxos/client/halo","kind":"import-statement","external":true},{"path":"@dxos/echo/internal","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/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/migrations.ts":{"bytes":10109,"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":15873},"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/internal","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/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":5407},"src/index.ts":{"bytesInOutput":0},"src/migrations.ts":{"bytesInOutput":3050}},"bytes":8587}}}
@@ -1,11 +1,11 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // src/migration-builder.ts
4
- import { next as am } from "@automerge/automerge";
4
+ import { next as A } from "@automerge/automerge";
5
5
  import { CreateEpochRequest } from "@dxos/client/halo";
6
+ import { requireTypeReference } from "@dxos/echo/internal";
6
7
  import { ObjectCore, migrateDocument } from "@dxos/echo-db";
7
8
  import { Reference, SpaceDocVersion, encodeReference } from "@dxos/echo-protocol";
8
- import { requireTypeReference } from "@dxos/echo-schema";
9
9
  import { invariant } from "@dxos/invariant";
10
10
  function _define_property(obj, key, value) {
11
11
  if (key in obj) {
@@ -66,7 +66,7 @@ var MigrationBuilder = class {
66
66
  }
67
67
  };
68
68
  const migratedDoc = migrateDocument(oldHandle.doc(), newState);
69
- const newHandle = this._repo.import(am.save(migratedDoc));
69
+ const newHandle = this._repo.import(A.save(migratedDoc));
70
70
  this._newLinks[id] = newHandle.url;
71
71
  this._addHandleToFlushList(newHandle);
72
72
  }
@@ -141,7 +141,7 @@ var MigrationBuilder = class {
141
141
  delete links[id];
142
142
  }
143
143
  for (const [id, url] of Object.entries(this._newLinks)) {
144
- links[id] = new am.RawString(url);
144
+ links[id] = new A.RawString(url);
145
145
  }
146
146
  this._newRoot = this._repo.create({
147
147
  version: SpaceDocVersion.CURRENT,
@@ -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;EAmBX,MAAMC,WAAWC,IAAkD;AACjE,UAAMC,cAAc,KAAKC,SAASC,QAAQH,EAAAA,KAAO,KAAKI,UAAUJ,EAAAA,IAAMK,SAAAA;AACtE,UAAMC,YAAYL,cAAc,KAAKM,MAAMC,KAAKP,UAAAA;AAChD,QAAI,CAACK,WAAW;AACd,aAAOG;IACT;AAEA,UAAMH,UAAUI,UAAS;AACzB,UAAMC,MAAML,UAAUK,IAAG;AACzB,WAAOA,IAAIC,UAAUZ,EAAAA;EACvB;EAEA,MAAMa,cACJb,IACAc,SACe;AACf,UAAMC,kBAAkB,MAAM,KAAKhB,WAAWC,EAAAA;AAC9C,QAAI,CAACe,iBAAiB;AACpB;IACF;AAEA,UAAM,EAAEC,QAAQC,MAAK,IAAK,MAAMH,QAAQC,eAAAA;AAExC,UAAMG,YAAY,MAAM,KAAKC,4BAA4BnB,EAAAA;AACzDH,cAAUqB,WAAAA,QAAAA;;;;;;;;;AAEV,UAAME,WAA8B;MAClCC,SAAS3B,gBAAgB4B;MACzBC,QAAQ;QACNC,UAAU,KAAKC,OAAOC,IAAIC,MAAK;MACjC;MACAf,SAAS;QACP,CAACZ,EAAAA,GAAK;UACJ4B,QAAQ;YACNC,MAAMlC,gBAAgBC,qBAAqBoB,MAAAA,CAAAA;UAC7C;UACAc,MAAMb;UACNc,MAAM;YACJC,MAAM,CAAA;UACR;QACF;MACF;IACF;AACA,UAAMC,cAAczC,gBAAgB0B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AKpB,eAAe;AAC5D,UAAMqB,eAAe,KAAKlB,WAAWmB,UAAU,CAACC,MAAMA,EAAElB,YAAYc,cAAAA,IAAkB;AACtF,UAAMK,IAAI,KAAKrB,WAAWmB,UAAU,CAACC,MAAMA,EAAElB,YAAYH,aAAAA;AACzD,UAAMuB,cAAcD,MAAM,KAAK,KAAKrB,WAAWC,SAASoB,IAAI;AAC5D,QAAIH,iBAAiBI,aAAa;AAChC,aAAO;IACT;AAEA,SAAKjB,OAAOF,QAAQoB,KAAKnB,MAAMG,IAAIC,MAAK,CAAA;AACxC,QAAIc,cAAcJ,cAAc;AAC9B,YAAMlB,aAAa,KAAKA,WAAWwB,MAAMN,cAAcI,WAAAA;AACvD,iBAAWG,aAAazB,YAAY;AAClC,cAAM0B,UAAU,IAAIC,iBAAiBvB,KAAAA;AACrC,cAAMqB,UAAUG,KAAK;UAAExB;UAAOsB;QAAQ,CAAA;AACtCA,gBAAQG,iBAAiB,CAACC,wBAAAA;AACxBnB,UAAAA,WAAU,KAAKd,iBAAiB,gCAAA;;;;;;;;;AAChCiC,8BAAoBC,KAAK,KAAKlC,eAAe,IAAI4B,UAAUvB;QAC7D,CAAA;AACA,cAAMwB,QAAQM,QAAO;MACvB;IACF;AACA,SAAK3B,OAAOF,QAAQ8B,OAAO,KAAK5B,OAAOF,QAAQ+B,QAAQ9B,MAAMG,IAAIC,MAAK,CAAA,GAAK,CAAA;AAE3E,WAAO;EACT;AACF;AAlDE2B,kBADWvC,YACJE,aAAP,MAAA;AACAqC,kBAFWvC,YAEJI,cAA0B,CAAA,CAAE;AACnCmC,kBAHWvC,YAGIS,UAAS+B,KAA4B;EAAEjC,SAAS,CAAA;AAAG,CAAA,CAAA;",
6
- "names": ["next", "am", "CreateEpochRequest", "ObjectCore", "migrateDocument", "Reference", "SpaceDocVersion", "encodeReference", "requireTypeReference", "invariant", "MigrationBuilder", "findObject", "id", "documentId", "_rootDoc", "links", "_newLinks", "toString", "docHandle", "_repo", "find", "undefined", "whenReady", "doc", "objects", "migrateObject", "migrate", "objectStructure", "schema", "props", "oldHandle", "_findObjectContainingHandle", "newState", "version", "CURRENT", "access", "spaceKey", "_space", "key", "toHex", "system", "type", "data", "meta", "keys", "migratedDoc", "newHandle", "import", "save", "url", "_addHandleToFlushList", "addObject", "core", "_createObject", "createReference", "localObjectReference", "deleteObject", "_deleteObjects", "push", "changeProperties", "changeFn", "_newRoot", "_buildNewRoot", "change", "propertiesStructure", "properties", "_commit", "db", "flush", "internal", "createEpoch", "migration", "Migration", "REPLACE_AUTOMERGE_ROOT", "automergeRootUrl", "Object", "entries", "RawString", "create", "initNewObject", "setType", "getDoc", "handle", "_flushIds", "coreDatabase", "_automergeDocLoader", "getSpaceRootDocHandle", "SpaceState", "live", "invariant", "Migrations", "versionProperty", "namespace", "targetVersion", "migrations", "length", "version", "running", "space", "_state", "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", "_define_property", "live"]
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 { requireTypeReference } from '@dxos/echo/internal';\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 { 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>(A.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 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 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,SAASA,QAAQC,SAAmB;AAKpC,SAASC,0BAA0B;AACnC,SAASC,4BAA4B;AACrC,SAA8BC,YAA4BC,uBAAuB;AACjF,SAGEC,WACAC,iBACAC,uBACK;AACP,SAASC,iBAAiB;;;;;;;;;;;;;;;AAqBnB,IAAMC,mBAAN,MAAMA;EAmBX,MAAMC,WAAWC,IAAkD;AACjE,UAAMC,cAAc,KAAKC,SAASC,QAAQH,EAAAA,KAAO,KAAKI,UAAUJ,EAAAA,IAAMK,SAAAA;AACtE,UAAMC,YAAYL,cAAc,KAAKM,MAAMC,KAAKP,UAAAA;AAChD,QAAI,CAACK,WAAW;AACd,aAAOG;IACT;AAEA,UAAMH,UAAUI,UAAS;AACzB,UAAMC,MAAML,UAAUK,IAAG;AACzB,WAAOA,IAAIC,UAAUZ,EAAAA;EACvB;EAEA,MAAMa,cACJb,IACAc,SACe;AACf,UAAMC,kBAAkB,MAAM,KAAKhB,WAAWC,EAAAA;AAC9C,QAAI,CAACe,iBAAiB;AACpB;IACF;AAEA,UAAM,EAAEC,QAAQC,MAAK,IAAK,MAAMH,QAAQC,eAAAA;AAExC,UAAMG,YAAY,MAAM,KAAKC,4BAA4BnB,EAAAA;AACzDH,cAAUqB,WAAAA,QAAAA;;;;;;;;;AAEV,UAAME,WAA8B;MAClCC,SAAS1B,gBAAgB2B;MACzBC,QAAQ;QACNC,UAAU,KAAKC,OAAOC,IAAIC,MAAK;MACjC;MACAf,SAAS;QACP,CAACZ,EAAAA,GAAK;UACJ4B,QAAQ;YACNC,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"requireTypeReference", "ObjectCore", "migrateDocument", "Reference", "SpaceDocVersion", "encodeReference", "invariant", "MigrationBuilder", "findObject", "id", "documentId", "_rootDoc", "links", "_newLinks", "toString", "docHandle", "_repo", "find", "undefined", "whenReady", "doc", "objects", "migrateObject", "migrate", "objectStructure", "schema", "props", "oldHandle", "_findObjectContainingHandle", "newState", "version", "CURRENT", "access", "spaceKey", "_space", "key", "toHex", "system", "type", "data", "meta", "keys", "migratedDoc", "newHandle", "import", "save", "url", "_addHandleToFlushList", "addObject", "core", "_createObject", "createReference", "localObjectReference", "deleteObject", "_deleteObjects", "push", "changeProperties", "changeFn", "_newRoot", "_buildNewRoot", "change", "propertiesStructure", "properties", "_commit", "db", "flush", "internal", "createEpoch", "migration", "Migration", "REPLACE_AUTOMERGE_ROOT", "automergeRootUrl", "Object", "entries", "RawString", "create", "initNewObject", "setType", "getDoc", "handle", "_flushIds", "coreDatabase", "_automergeDocLoader", "getSpaceRootDocHandle", "SpaceState", "live", "invariant", "Migrations", "versionProperty", "namespace", "targetVersion", "migrations", "length", "version", "running", "space", "_state", "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", "_define_property", "live"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/migration-builder.ts":{"bytes":22849,"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":10109,"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/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15869},"dist/lib/node-esm/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":5408},"src/index.ts":{"bytesInOutput":0},"src/migrations.ts":{"bytesInOutput":3050}},"bytes":8681}}}
1
+ {"inputs":{"src/migration-builder.ts":{"bytes":22856,"imports":[{"path":"@automerge/automerge","kind":"import-statement","external":true},{"path":"@dxos/client/halo","kind":"import-statement","external":true},{"path":"@dxos/echo/internal","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/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/migrations.ts":{"bytes":10109,"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/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15875},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"@automerge/automerge","kind":"import-statement","external":true},{"path":"@dxos/client/halo","kind":"import-statement","external":true},{"path":"@dxos/echo/internal","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/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":5407},"src/index.ts":{"bytesInOutput":0},"src/migrations.ts":{"bytesInOutput":3050}},"bytes":8680}}}
@@ -1,4 +1,4 @@
1
- import { type Schema } from 'effect';
1
+ import type * as Schema from 'effect/Schema';
2
2
  import { type Space } from '@dxos/client/echo';
3
3
  import { type ObjectStructure } from '@dxos/echo-protocol';
4
4
  import { type MaybePromise } from '@dxos/util';
@@ -1 +1 @@
1
- {"version":3,"file":"migration-builder.d.ts","sourceRoot":"","sources":["../../../src/migration-builder.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG/C,OAAO,EAEL,KAAK,eAAe,EAIrB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAoB/C,qBAAa,gBAAgB;IAWf,OAAO,CAAC,QAAQ,CAAC,MAAM;IAVnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAY;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAGlD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IACxD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoB;IAC9C,OAAO,CAAC,QA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