@dxos/echo-protocol 0.8.2-main.f11618f → 0.8.2-staging.7ac8446

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.
@@ -111,12 +111,7 @@ var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
111
111
  var encodeReference = (reference) => ({
112
112
  "/": reference.toDXN().toString()
113
113
  });
114
- var decodeReference = (value) => {
115
- if (value.length % 2 === 0 && value.slice(0, value.length / 2) === value.slice(value.length / 2) && value.includes("dxn:echo")) {
116
- throw new Error("Automerge bug detected!");
117
- }
118
- return Reference.fromDXN(DXN.parse(value["/"]));
119
- };
114
+ var decodeReference = (value) => Reference.fromDXN(DXN.parse(value["/"]));
120
115
  var isEncodedReference = (value) => typeof value === "object" && value !== null && Object.keys(value).length === 1 && typeof value["/"] === "string";
121
116
 
122
117
  // packages/core/echo/echo-protocol/src/space-doc-version.ts
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/reference.ts", "../../../src/space-doc-version.ts", "../../../src/space-id.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { DXN, LOCAL_SPACE_TAG, type PublicKey } from '@dxos/keys';\nimport { type ObjectId } from '@dxos/protocols';\nimport { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';\n\n/**\n * Runtime representation of an reference in ECHO.\n * Implemented as a DXN, but we might extend it to other URIs in the future.\n */\nexport class Reference {\n /**\n * Protocol references to runtime registered types.\n * @deprecated\n */\n static TYPE_PROTOCOL = 'protobuf';\n\n static fromDXN(dxn: DXN): Reference {\n switch (dxn.kind) {\n case DXN.kind.TYPE:\n return new Reference(dxn.parts[0], Reference.TYPE_PROTOCOL, 'dxos.org', dxn);\n case DXN.kind.ECHO:\n if (dxn.parts[0] === LOCAL_SPACE_TAG) {\n return new Reference(dxn.parts[1], undefined, undefined, dxn);\n } else {\n return new Reference(dxn.parts[1], undefined, dxn.parts[0], dxn);\n }\n default:\n return new Reference(dxn.parts[0], undefined, dxn.parts[0], dxn);\n }\n }\n\n static fromValue(value: ReferenceProto): Reference {\n return new Reference(value.objectId, value.protocol, value.host);\n }\n\n /**\n * Reference an object in the local space.\n */\n static localObjectReference(objectId: ObjectId): Reference {\n return new Reference(objectId);\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n static fromLegacyTypename(type: string): Reference {\n return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove\n static fromObjectIdAndSpaceKey(objectId: ObjectId, spaceKey: PublicKey): Reference {\n // TODO(dmaretskyi): FIX ME! This should be a space ID not a space key.\n return new Reference(objectId, undefined, spaceKey.toHex());\n }\n\n // prettier-ignore\n private constructor(\n // TODO(dmaretskyi): Remove and just leave DXN.\n private readonly _objectId: ObjectId,\n private readonly _protocol?: string,\n private readonly _host?: string,\n private readonly _dxn?: DXN,\n ) {}\n\n get dxn(): DXN | undefined {\n return this._dxn;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get objectId(): ObjectId {\n return this._objectId;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get protocol(): string | undefined {\n return this._protocol;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get host(): string | undefined {\n return this._host;\n }\n\n encode(): ReferenceProto {\n return { objectId: this.objectId, host: this.host, protocol: this.protocol };\n }\n\n // TODO(dmaretskyi): Remove in favor of `reference.dxn`.\n toDXN(): DXN {\n if (this._dxn) {\n return this._dxn;\n }\n\n if (this.protocol === Reference.TYPE_PROTOCOL) {\n return new DXN(DXN.kind.TYPE, [this.objectId]);\n } else {\n if (this.host) {\n // Host is assumed to be the space key.\n // The DXN should actually have the space ID.\n // TODO(dmaretskyi): Migrate to space id.\n return new DXN(DXN.kind.ECHO, [this.host, this.objectId]);\n } else {\n return new DXN(DXN.kind.ECHO, [LOCAL_SPACE_TAG, this.objectId]);\n }\n }\n }\n}\n\nexport const REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';\n\n/**\n * Reference as it is stored in Automerge document.\n */\nexport type EncodedReference = {\n '/': string;\n};\n\nexport const encodeReference = (reference: Reference): EncodedReference => ({\n '/': reference.toDXN().toString(),\n});\n\nexport const decodeReference = (value: any) => {\n if (\n value.length % 2 === 0 &&\n value.slice(0, value.length / 2) === value.slice(value.length / 2) &&\n value.includes('dxn:echo')\n ) {\n throw new Error('Automerge bug detected!');\n }\n\n return Reference.fromDXN(DXN.parse(value['/']));\n};\n\nexport const isEncodedReference = (value: any): value is EncodedReference =>\n typeof value === 'object' && value !== null && Object.keys(value).length === 1 && typeof value['/'] === 'string';\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Denotes the data version of the space automerge document as well as the leaf documents for each individual ECHO object.\n */\nexport type SpaceDocVersion = number & { __type: 'SpaceDocVersion' };\n\nexport const SpaceDocVersion = Object.freeze({\n /**\n * For the documents created before the versioning was introduced.\n */\n LEGACY: 0 as SpaceDocVersion,\n\n /**\n * Current version.\n */\n CURRENT: 1 as SpaceDocVersion,\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { PublicKey, SpaceId } from '@dxos/keys';\nimport { ComplexMap } from '@dxos/util';\n\nconst SPACE_IDS_CACHE = new ComplexMap<PublicKey, SpaceId>(PublicKey.hash);\n\n/**\n * Space keys are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).\n * Inspired by how ethereum addresses are derived.\n */\nexport const createIdFromSpaceKey = async (spaceKey: PublicKey): Promise<SpaceId> => {\n const cachedValue = SPACE_IDS_CACHE.get(spaceKey);\n if (cachedValue !== undefined) {\n return cachedValue;\n }\n\n const digest = await subtleCrypto.digest('SHA-256', spaceKey.asUint8Array());\n\n const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);\n const spaceId = SpaceId.encode(bytes);\n SPACE_IDS_CACHE.set(spaceKey, spaceId);\n return spaceId;\n};\n"],
5
- "mappings": ";AAIA,SAASA,KAAKC,uBAAuC;AAQ9C,IAAMC,YAAN,MAAMA,WAAAA;EAKX;;;;;SAAOC,gBAAgB;;EAEvB,OAAOC,QAAQC,KAAqB;AAClC,YAAQA,IAAIC,MAAI;MACd,KAAKC,IAAID,KAAKE;AACZ,eAAO,IAAIN,WAAUG,IAAII,MAAM,CAAA,GAAIP,WAAUC,eAAe,YAAYE,GAAAA;MAC1E,KAAKE,IAAID,KAAKI;AACZ,YAAIL,IAAII,MAAM,CAAA,MAAOE,iBAAiB;AACpC,iBAAO,IAAIT,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWA,QAAWP,GAAAA;QAC3D,OAAO;AACL,iBAAO,IAAIH,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWP,IAAII,MAAM,CAAA,GAAIJ,GAAAA;QAC9D;MACF;AACE,eAAO,IAAIH,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWP,IAAII,MAAM,CAAA,GAAIJ,GAAAA;IAChE;EACF;EAEA,OAAOQ,UAAUC,OAAkC;AACjD,WAAO,IAAIZ,WAAUY,MAAMC,UAAUD,MAAME,UAAUF,MAAMG,IAAI;EACjE;;;;EAKA,OAAOC,qBAAqBH,UAA+B;AACzD,WAAO,IAAIb,WAAUa,QAAAA;EACvB;;;;;EAMA,OAAOI,mBAAmBC,MAAyB;AACjD,WAAO,IAAIlB,WAAUkB,MAAMlB,WAAUC,eAAe,UAAA;EACtD;;;;;EAMA,OAAOkB,wBAAwBN,UAAoBO,UAAgC;AAEjF,WAAO,IAAIpB,WAAUa,UAAUH,QAAWU,SAASC,MAAK,CAAA;EAC1D;;EAGA,YAEmBC,WACAC,WACAC,OACAC,MACjB;SAJiBH,YAAAA;SACAC,YAAAA;SACAC,QAAAA;SACAC,OAAAA;EAChB;EA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AAA,MAAS;;;AC7InG,IAAM6B,kBAAkBC,OAAOC,OAAO;;;;EAI3CC,QAAQ;;;;EAKRC,SAAS;AACX,CAAA;;;ACfA,SAASC,oBAAoB;AAC7B,SAASC,WAAWC,eAAe;AACnC,SAASC,kBAAkB;AAE3B,IAAMC,kBAAkB,IAAIC,WAA+BC,UAAUC,IAAI;AAMlE,IAAMC,uBAAuB,OAAOC,aAAAA;AACzC,QAAMC,cAAcN,gBAAgBO,IAAIF,QAAAA;AACxC,MAAIC,gBAAgBE,QAAW;AAC7B,WAAOF;EACT;AAEA,QAAMG,SAAS,MAAMC,aAAaD,OAAO,WAAWJ,SAASM,aAAY,CAAA;AAEzE,QAAMC,QAAQ,IAAIC,WAAWJ,MAAAA,EAAQK,MAAM,GAAGC,QAAQC,UAAU;AAChE,QAAMC,UAAUF,QAAQG,OAAON,KAAAA;AAC/BZ,kBAAgBmB,IAAId,UAAUY,OAAAA;AAC9B,SAAOA;AACT;",
6
- "names": ["DXN", "LOCAL_SPACE_TAG", "Reference", "TYPE_PROTOCOL", "fromDXN", "dxn", "kind", "DXN", "TYPE", "parts", "ECHO", "LOCAL_SPACE_TAG", "undefined", "fromValue", "value", "objectId", "protocol", "host", "localObjectReference", "fromLegacyTypename", "type", "fromObjectIdAndSpaceKey", "spaceKey", "toHex", "_objectId", "_protocol", "_host", "_dxn", "encode", "toDXN", "REFERENCE_TYPE_TAG", "encodeReference", "reference", "toString", "decodeReference", "length", "slice", "includes", "Error", "parse", "isEncodedReference", "Object", "keys", "SpaceDocVersion", "Object", "freeze", "LEGACY", "CURRENT", "subtleCrypto", "PublicKey", "SpaceId", "ComplexMap", "SPACE_IDS_CACHE", "ComplexMap", "PublicKey", "hash", "createIdFromSpaceKey", "spaceKey", "cachedValue", "get", "undefined", "digest", "subtleCrypto", "asUint8Array", "bytes", "Uint8Array", "slice", "SpaceId", "byteLength", "spaceId", "encode", "set"]
4
+ "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { DXN, LOCAL_SPACE_TAG, type PublicKey } from '@dxos/keys';\nimport { type ObjectId } from '@dxos/protocols';\nimport { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';\n\n/**\n * Runtime representation of an reference in ECHO.\n * Implemented as a DXN, but we might extend it to other URIs in the future.\n */\nexport class Reference {\n /**\n * Protocol references to runtime registered types.\n * @deprecated\n */\n static TYPE_PROTOCOL = 'protobuf';\n\n static fromDXN(dxn: DXN): Reference {\n switch (dxn.kind) {\n case DXN.kind.TYPE:\n return new Reference(dxn.parts[0], Reference.TYPE_PROTOCOL, 'dxos.org', dxn);\n case DXN.kind.ECHO:\n if (dxn.parts[0] === LOCAL_SPACE_TAG) {\n return new Reference(dxn.parts[1], undefined, undefined, dxn);\n } else {\n return new Reference(dxn.parts[1], undefined, dxn.parts[0], dxn);\n }\n default:\n return new Reference(dxn.parts[0], undefined, dxn.parts[0], dxn);\n }\n }\n\n static fromValue(value: ReferenceProto): Reference {\n return new Reference(value.objectId, value.protocol, value.host);\n }\n\n /**\n * Reference an object in the local space.\n */\n static localObjectReference(objectId: ObjectId): Reference {\n return new Reference(objectId);\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n static fromLegacyTypename(type: string): Reference {\n return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove\n static fromObjectIdAndSpaceKey(objectId: ObjectId, spaceKey: PublicKey): Reference {\n // TODO(dmaretskyi): FIX ME! This should be a space ID not a space key.\n return new Reference(objectId, undefined, spaceKey.toHex());\n }\n\n // prettier-ignore\n private constructor(\n // TODO(dmaretskyi): Remove and just leave DXN.\n private readonly _objectId: ObjectId,\n private readonly _protocol?: string,\n private readonly _host?: string,\n private readonly _dxn?: DXN,\n ) {}\n\n get dxn(): DXN | undefined {\n return this._dxn;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get objectId(): ObjectId {\n return this._objectId;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get protocol(): string | undefined {\n return this._protocol;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get host(): string | undefined {\n return this._host;\n }\n\n encode(): ReferenceProto {\n return { objectId: this.objectId, host: this.host, protocol: this.protocol };\n }\n\n // TODO(dmaretskyi): Remove in favor of `reference.dxn`.\n toDXN(): DXN {\n if (this._dxn) {\n return this._dxn;\n }\n\n if (this.protocol === Reference.TYPE_PROTOCOL) {\n return new DXN(DXN.kind.TYPE, [this.objectId]);\n } else {\n if (this.host) {\n // Host is assumed to be the space key.\n // The DXN should actually have the space ID.\n // TODO(dmaretskyi): Migrate to space id.\n return new DXN(DXN.kind.ECHO, [this.host, this.objectId]);\n } else {\n return new DXN(DXN.kind.ECHO, [LOCAL_SPACE_TAG, this.objectId]);\n }\n }\n }\n}\n\nexport const REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';\n\n/**\n * Reference as it is stored in Automerge document.\n */\nexport type EncodedReference = {\n '/': string;\n};\n\nexport const encodeReference = (reference: Reference): EncodedReference => ({\n '/': reference.toDXN().toString(),\n});\n\nexport const decodeReference = (value: any) => Reference.fromDXN(DXN.parse(value['/']));\n\nexport const isEncodedReference = (value: any): value is EncodedReference =>\n typeof value === 'object' && value !== null && Object.keys(value).length === 1 && typeof value['/'] === 'string';\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Denotes the data version of the space automerge document as well as the leaf documents for each individual ECHO object.\n */\nexport type SpaceDocVersion = number & { __type: 'SpaceDocVersion' };\n\nexport const SpaceDocVersion = Object.freeze({\n /**\n * For the documents created before the versioning was introduced.\n */\n LEGACY: 0 as SpaceDocVersion,\n\n /**\n * Current version.\n */\n CURRENT: 1 as SpaceDocVersion,\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { PublicKey, SpaceId } from '@dxos/keys';\nimport { ComplexMap } from '@dxos/util';\n\nconst SPACE_IDS_CACHE = new ComplexMap<PublicKey, SpaceId>(PublicKey.hash);\n\n/**\n * Space keys are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).\n * Inspired by how ethereum addresses are derived.\n */\nexport const createIdFromSpaceKey = async (spaceKey: PublicKey): Promise<SpaceId> => {\n const cachedValue = SPACE_IDS_CACHE.get(spaceKey);\n if (cachedValue !== undefined) {\n return cachedValue;\n }\n\n const digest = await subtleCrypto.digest('SHA-256', spaceKey.asUint8Array());\n\n const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);\n const spaceId = SpaceId.encode(bytes);\n SPACE_IDS_CACHE.set(spaceKey, spaceId);\n return spaceId;\n};\n"],
5
+ "mappings": ";AAIA,SAASA,KAAKC,uBAAuC;AAQ9C,IAAMC,YAAN,MAAMA,WAAAA;EAKX;;;;;SAAOC,gBAAgB;;EAEvB,OAAOC,QAAQC,KAAqB;AAClC,YAAQA,IAAIC,MAAI;MACd,KAAKC,IAAID,KAAKE;AACZ,eAAO,IAAIN,WAAUG,IAAII,MAAM,CAAA,GAAIP,WAAUC,eAAe,YAAYE,GAAAA;MAC1E,KAAKE,IAAID,KAAKI;AACZ,YAAIL,IAAII,MAAM,CAAA,MAAOE,iBAAiB;AACpC,iBAAO,IAAIT,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWA,QAAWP,GAAAA;QAC3D,OAAO;AACL,iBAAO,IAAIH,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWP,IAAII,MAAM,CAAA,GAAIJ,GAAAA;QAC9D;MACF;AACE,eAAO,IAAIH,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWP,IAAII,MAAM,CAAA,GAAIJ,GAAAA;IAChE;EACF;EAEA,OAAOQ,UAAUC,OAAkC;AACjD,WAAO,IAAIZ,WAAUY,MAAMC,UAAUD,MAAME,UAAUF,MAAMG,IAAI;EACjE;;;;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AMrB,MAAM,GAAA,CAAI,CAAA;AAE9E,IAAMsB,qBAAqB,CAACtB,UACjC,OAAOA,UAAU,YAAYA,UAAU,QAAQuB,OAAOC,KAAKxB,KAAAA,EAAOyB,WAAW,KAAK,OAAOzB,MAAM,GAAA,MAAS;;;ACnInG,IAAM0B,kBAAkBC,OAAOC,OAAO;;;;EAI3CC,QAAQ;;;;EAKRC,SAAS;AACX,CAAA;;;ACfA,SAASC,oBAAoB;AAC7B,SAASC,WAAWC,eAAe;AACnC,SAASC,kBAAkB;AAE3B,IAAMC,kBAAkB,IAAIC,WAA+BC,UAAUC,IAAI;AAMlE,IAAMC,uBAAuB,OAAOC,aAAAA;AACzC,QAAMC,cAAcN,gBAAgBO,IAAIF,QAAAA;AACxC,MAAIC,gBAAgBE,QAAW;AAC7B,WAAOF;EACT;AAEA,QAAMG,SAAS,MAAMC,aAAaD,OAAO,WAAWJ,SAASM,aAAY,CAAA;AAEzE,QAAMC,QAAQ,IAAIC,WAAWJ,MAAAA,EAAQK,MAAM,GAAGC,QAAQC,UAAU;AAChE,QAAMC,UAAUF,QAAQG,OAAON,KAAAA;AAC/BZ,kBAAgBmB,IAAId,UAAUY,OAAAA;AAC9B,SAAOA;AACT;",
6
+ "names": ["DXN", "LOCAL_SPACE_TAG", "Reference", "TYPE_PROTOCOL", "fromDXN", "dxn", "kind", "DXN", "TYPE", "parts", "ECHO", "LOCAL_SPACE_TAG", "undefined", "fromValue", "value", "objectId", "protocol", "host", "localObjectReference", "fromLegacyTypename", "type", "fromObjectIdAndSpaceKey", "spaceKey", "toHex", "_objectId", "_protocol", "_host", "_dxn", "encode", "toDXN", "REFERENCE_TYPE_TAG", "encodeReference", "reference", "toString", "decodeReference", "parse", "isEncodedReference", "Object", "keys", "length", "SpaceDocVersion", "Object", "freeze", "LEGACY", "CURRENT", "subtleCrypto", "PublicKey", "SpaceId", "ComplexMap", "SPACE_IDS_CACHE", "ComplexMap", "PublicKey", "hash", "createIdFromSpaceKey", "spaceKey", "cachedValue", "get", "undefined", "digest", "subtleCrypto", "asUint8Array", "bytes", "Uint8Array", "slice", "SpaceId", "byteLength", "spaceId", "encode", "set"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":2912,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/reference.ts":{"bytes":14189,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytes":1591,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/collection-sync.ts":{"bytes":550,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytes":3580,"imports":[{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-protocol/src/index.ts":{"bytes":931,"imports":[{"path":"packages/core/echo/echo-protocol/src/document-structure.ts","kind":"import-statement","original":"./document-structure"},{"path":"packages/core/echo/echo-protocol/src/reference.ts","kind":"import-statement","original":"./reference"},{"path":"packages/core/echo/echo-protocol/src/space-doc-version.ts","kind":"import-statement","original":"./space-doc-version"},{"path":"packages/core/echo/echo-protocol/src/collection-sync.ts","kind":"import-statement","original":"./collection-sync"},{"path":"packages/core/echo/echo-protocol/src/space-id.ts","kind":"import-statement","original":"./space-id"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-protocol/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9297},"packages/core/echo/echo-protocol/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["REFERENCE_TYPE_TAG","Reference","SpaceDocVersion","createIdFromSpaceKey","decodeReference","encodeReference","isEncodedReference"],"entryPoint":"packages/core/echo/echo-protocol/src/index.ts","inputs":{"packages/core/echo/echo-protocol/src/index.ts":{"bytesInOutput":0},"packages/core/echo/echo-protocol/src/reference.ts":{"bytesInOutput":3064},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytesInOutput":179},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytesInOutput":604}},"bytes":4199}}}
1
+ {"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":2912,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/reference.ts":{"bytes":13381,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytes":1591,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/collection-sync.ts":{"bytes":550,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytes":3580,"imports":[{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-protocol/src/index.ts":{"bytes":931,"imports":[{"path":"packages/core/echo/echo-protocol/src/document-structure.ts","kind":"import-statement","original":"./document-structure"},{"path":"packages/core/echo/echo-protocol/src/reference.ts","kind":"import-statement","original":"./reference"},{"path":"packages/core/echo/echo-protocol/src/space-doc-version.ts","kind":"import-statement","original":"./space-doc-version"},{"path":"packages/core/echo/echo-protocol/src/collection-sync.ts","kind":"import-statement","original":"./collection-sync"},{"path":"packages/core/echo/echo-protocol/src/space-id.ts","kind":"import-statement","original":"./space-id"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-protocol/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":8851},"packages/core/echo/echo-protocol/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["REFERENCE_TYPE_TAG","Reference","SpaceDocVersion","createIdFromSpaceKey","decodeReference","encodeReference","isEncodedReference"],"entryPoint":"packages/core/echo/echo-protocol/src/index.ts","inputs":{"packages/core/echo/echo-protocol/src/index.ts":{"bytesInOutput":0},"packages/core/echo/echo-protocol/src/reference.ts":{"bytesInOutput":2866},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytesInOutput":179},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytesInOutput":604}},"bytes":4001}}}
@@ -138,12 +138,7 @@ var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
138
138
  var encodeReference = (reference) => ({
139
139
  "/": reference.toDXN().toString()
140
140
  });
141
- var decodeReference = (value) => {
142
- if (value.length % 2 === 0 && value.slice(0, value.length / 2) === value.slice(value.length / 2) && value.includes("dxn:echo")) {
143
- throw new Error("Automerge bug detected!");
144
- }
145
- return Reference.fromDXN(import_keys.DXN.parse(value["/"]));
146
- };
141
+ var decodeReference = (value) => Reference.fromDXN(import_keys.DXN.parse(value["/"]));
147
142
  var isEncodedReference = (value) => typeof value === "object" && value !== null && Object.keys(value).length === 1 && typeof value["/"] === "string";
148
143
  var SpaceDocVersion = Object.freeze({
149
144
  /**
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/reference.ts", "../../../src/space-doc-version.ts", "../../../src/space-id.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { DXN, LOCAL_SPACE_TAG, type PublicKey } from '@dxos/keys';\nimport { type ObjectId } from '@dxos/protocols';\nimport { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';\n\n/**\n * Runtime representation of an reference in ECHO.\n * Implemented as a DXN, but we might extend it to other URIs in the future.\n */\nexport class Reference {\n /**\n * Protocol references to runtime registered types.\n * @deprecated\n */\n static TYPE_PROTOCOL = 'protobuf';\n\n static fromDXN(dxn: DXN): Reference {\n switch (dxn.kind) {\n case DXN.kind.TYPE:\n return new Reference(dxn.parts[0], Reference.TYPE_PROTOCOL, 'dxos.org', dxn);\n case DXN.kind.ECHO:\n if (dxn.parts[0] === LOCAL_SPACE_TAG) {\n return new Reference(dxn.parts[1], undefined, undefined, dxn);\n } else {\n return new Reference(dxn.parts[1], undefined, dxn.parts[0], dxn);\n }\n default:\n return new Reference(dxn.parts[0], undefined, dxn.parts[0], dxn);\n }\n }\n\n static fromValue(value: ReferenceProto): Reference {\n return new Reference(value.objectId, value.protocol, value.host);\n }\n\n /**\n * Reference an object in the local space.\n */\n static localObjectReference(objectId: ObjectId): Reference {\n return new Reference(objectId);\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n static fromLegacyTypename(type: string): Reference {\n return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove\n static fromObjectIdAndSpaceKey(objectId: ObjectId, spaceKey: PublicKey): Reference {\n // TODO(dmaretskyi): FIX ME! This should be a space ID not a space key.\n return new Reference(objectId, undefined, spaceKey.toHex());\n }\n\n // prettier-ignore\n private constructor(\n // TODO(dmaretskyi): Remove and just leave DXN.\n private readonly _objectId: ObjectId,\n private readonly _protocol?: string,\n private readonly _host?: string,\n private readonly _dxn?: DXN,\n ) {}\n\n get dxn(): DXN | undefined {\n return this._dxn;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get objectId(): ObjectId {\n return this._objectId;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get protocol(): string | undefined {\n return this._protocol;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get host(): string | undefined {\n return this._host;\n }\n\n encode(): ReferenceProto {\n return { objectId: this.objectId, host: this.host, protocol: this.protocol };\n }\n\n // TODO(dmaretskyi): Remove in favor of `reference.dxn`.\n toDXN(): DXN {\n if (this._dxn) {\n return this._dxn;\n }\n\n if (this.protocol === Reference.TYPE_PROTOCOL) {\n return new DXN(DXN.kind.TYPE, [this.objectId]);\n } else {\n if (this.host) {\n // Host is assumed to be the space key.\n // The DXN should actually have the space ID.\n // TODO(dmaretskyi): Migrate to space id.\n return new DXN(DXN.kind.ECHO, [this.host, this.objectId]);\n } else {\n return new DXN(DXN.kind.ECHO, [LOCAL_SPACE_TAG, this.objectId]);\n }\n }\n }\n}\n\nexport const REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';\n\n/**\n * Reference as it is stored in Automerge document.\n */\nexport type EncodedReference = {\n '/': string;\n};\n\nexport const encodeReference = (reference: Reference): EncodedReference => ({\n '/': reference.toDXN().toString(),\n});\n\nexport const decodeReference = (value: any) => {\n if (\n value.length % 2 === 0 &&\n value.slice(0, value.length / 2) === value.slice(value.length / 2) &&\n value.includes('dxn:echo')\n ) {\n throw new Error('Automerge bug detected!');\n }\n\n return Reference.fromDXN(DXN.parse(value['/']));\n};\n\nexport const isEncodedReference = (value: any): value is EncodedReference =>\n typeof value === 'object' && value !== null && Object.keys(value).length === 1 && typeof value['/'] === 'string';\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Denotes the data version of the space automerge document as well as the leaf documents for each individual ECHO object.\n */\nexport type SpaceDocVersion = number & { __type: 'SpaceDocVersion' };\n\nexport const SpaceDocVersion = Object.freeze({\n /**\n * For the documents created before the versioning was introduced.\n */\n LEGACY: 0 as SpaceDocVersion,\n\n /**\n * Current version.\n */\n CURRENT: 1 as SpaceDocVersion,\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { PublicKey, SpaceId } from '@dxos/keys';\nimport { ComplexMap } from '@dxos/util';\n\nconst SPACE_IDS_CACHE = new ComplexMap<PublicKey, SpaceId>(PublicKey.hash);\n\n/**\n * Space keys are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).\n * Inspired by how ethereum addresses are derived.\n */\nexport const createIdFromSpaceKey = async (spaceKey: PublicKey): Promise<SpaceId> => {\n const cachedValue = SPACE_IDS_CACHE.get(spaceKey);\n if (cachedValue !== undefined) {\n return cachedValue;\n }\n\n const digest = await subtleCrypto.digest('SHA-256', spaceKey.asUint8Array());\n\n const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);\n const spaceId = SpaceId.encode(bytes);\n SPACE_IDS_CACHE.set(spaceKey, spaceId);\n return spaceId;\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kBAAqD;AEArD,oBAA6B;AAC7B,IAAAA,eAAmC;AACnC,kBAA2B;AFMpB,IAAMC,YAAN,MAAMA,WAAAA;EAKX,OAAA;SAAOC,gBAAgB;;EAEvB,OAAOC,QAAQC,KAAqB;AAClC,YAAQA,IAAIC,MAAI;MACd,KAAKC,gBAAID,KAAKE;AACZ,eAAO,IAAIN,WAAUG,IAAII,MAAM,CAAA,GAAIP,WAAUC,eAAe,YAAYE,GAAAA;MAC1E,KAAKE,gBAAID,KAAKI;AACZ,YAAIL,IAAII,MAAM,CAAA,MAAOE,6BAAiB;AACpC,iBAAO,IAAIT,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWA,QAAWP,GAAAA;QAC3D,OAAO;AACL,iBAAO,IAAIH,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWP,IAAII,MAAM,CAAA,GAAIJ,GAAAA;QAC9D;MACF;AACE,eAAO,IAAIH,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWP,IAAII,MAAM,CAAA,GAAIJ,GAAAA;IAChE;EACF;EAEA,OAAOQ,UAAUC,OAAkC;AACjD,WAAO,IAAIZ,WAAUY,MAAMC,UAAUD,MAAME,UAAUF,MAAMG,IAAI;EACjE;;;;EAKA,OAAOC,qBAAqBH,UAA+B;AACzD,WAAO,IAAIb,WAAUa,QAAAA;EACvB;;;;;EAMA,O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,MAAMtB,MAAMqB,SAAS,CAAA,KAChErB,MAAMuB,SAAS,UAAA,GACf;AACA,UAAM,IAAIC,MAAM,yBAAA;EAClB;AAEA,SAAOpC,UAAUE,QAAQG,gBAAIgC,MAAMzB,MAAM,GAAA,CAAI,CAAA;AAC/C;AAEO,IAAM0B,qBAAqB,CAAC1B,UACjC,OAAOA,UAAU,YAAYA,UAAU,QAAQ2B,OAAOC,KAAK5B,KAAAA,EAAOqB,WAAW,KAAK,OAAOrB,MAAM,GAAA,MAAS;AC7InG,IAAM6B,kBAAkBF,OAAOG,OAAO;;;;EAI3CC,QAAQ;;;;EAKRC,SAAS;AACX,CAAA;ACXA,IAAMC,kBAAkB,IAAIC,uBAA+BC,uBAAUC,IAAI;AAMlE,IAAMC,uBAAuB,OAAO7B,aAAAA;AACzC,QAAM8B,cAAcL,gBAAgBM,IAAI/B,QAAAA;AACxC,MAAI8B,gBAAgBxC,QAAW;AAC7B,WAAOwC;EACT;AAEA,QAAME,SAAS,MAAMC,2BAAaD,OAAO,WAAWhC,SAASkC,aAAY,CAAA;AAEzE,QAAMC,QAAQ,IAAIC,WAAWJ,MAAAA,EAAQlB,MAAM,GAAGuB,qBAAQC,UAAU;AAChE,QAAMC,UAAUF,qBAAQ/B,OAAO6B,KAAAA;AAC/BV,kBAAgBe,IAAIxC,UAAUuC,OAAAA;AAC9B,SAAOA;AACT;",
6
- "names": ["import_keys", "Reference", "TYPE_PROTOCOL", "fromDXN", "dxn", "kind", "DXN", "TYPE", "parts", "ECHO", "LOCAL_SPACE_TAG", "undefined", "fromValue", "value", "objectId", "protocol", "host", "localObjectReference", "fromLegacyTypename", "type", "fromObjectIdAndSpaceKey", "spaceKey", "toHex", "_objectId", "_protocol", "_host", "_dxn", "encode", "toDXN", "REFERENCE_TYPE_TAG", "encodeReference", "reference", "toString", "decodeReference", "length", "slice", "includes", "Error", "parse", "isEncodedReference", "Object", "keys", "SpaceDocVersion", "freeze", "LEGACY", "CURRENT", "SPACE_IDS_CACHE", "ComplexMap", "PublicKey", "hash", "createIdFromSpaceKey", "cachedValue", "get", "digest", "subtleCrypto", "asUint8Array", "bytes", "Uint8Array", "SpaceId", "byteLength", "spaceId", "set"]
4
+ "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { DXN, LOCAL_SPACE_TAG, type PublicKey } from '@dxos/keys';\nimport { type ObjectId } from '@dxos/protocols';\nimport { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';\n\n/**\n * Runtime representation of an reference in ECHO.\n * Implemented as a DXN, but we might extend it to other URIs in the future.\n */\nexport class Reference {\n /**\n * Protocol references to runtime registered types.\n * @deprecated\n */\n static TYPE_PROTOCOL = 'protobuf';\n\n static fromDXN(dxn: DXN): Reference {\n switch (dxn.kind) {\n case DXN.kind.TYPE:\n return new Reference(dxn.parts[0], Reference.TYPE_PROTOCOL, 'dxos.org', dxn);\n case DXN.kind.ECHO:\n if (dxn.parts[0] === LOCAL_SPACE_TAG) {\n return new Reference(dxn.parts[1], undefined, undefined, dxn);\n } else {\n return new Reference(dxn.parts[1], undefined, dxn.parts[0], dxn);\n }\n default:\n return new Reference(dxn.parts[0], undefined, dxn.parts[0], dxn);\n }\n }\n\n static fromValue(value: ReferenceProto): Reference {\n return new Reference(value.objectId, value.protocol, value.host);\n }\n\n /**\n * Reference an object in the local space.\n */\n static localObjectReference(objectId: ObjectId): Reference {\n return new Reference(objectId);\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n static fromLegacyTypename(type: string): Reference {\n return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove\n static fromObjectIdAndSpaceKey(objectId: ObjectId, spaceKey: PublicKey): Reference {\n // TODO(dmaretskyi): FIX ME! This should be a space ID not a space key.\n return new Reference(objectId, undefined, spaceKey.toHex());\n }\n\n // prettier-ignore\n private constructor(\n // TODO(dmaretskyi): Remove and just leave DXN.\n private readonly _objectId: ObjectId,\n private readonly _protocol?: string,\n private readonly _host?: string,\n private readonly _dxn?: DXN,\n ) {}\n\n get dxn(): DXN | undefined {\n return this._dxn;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get objectId(): ObjectId {\n return this._objectId;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get protocol(): string | undefined {\n return this._protocol;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get host(): string | undefined {\n return this._host;\n }\n\n encode(): ReferenceProto {\n return { objectId: this.objectId, host: this.host, protocol: this.protocol };\n }\n\n // TODO(dmaretskyi): Remove in favor of `reference.dxn`.\n toDXN(): DXN {\n if (this._dxn) {\n return this._dxn;\n }\n\n if (this.protocol === Reference.TYPE_PROTOCOL) {\n return new DXN(DXN.kind.TYPE, [this.objectId]);\n } else {\n if (this.host) {\n // Host is assumed to be the space key.\n // The DXN should actually have the space ID.\n // TODO(dmaretskyi): Migrate to space id.\n return new DXN(DXN.kind.ECHO, [this.host, this.objectId]);\n } else {\n return new DXN(DXN.kind.ECHO, [LOCAL_SPACE_TAG, this.objectId]);\n }\n }\n }\n}\n\nexport const REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';\n\n/**\n * Reference as it is stored in Automerge document.\n */\nexport type EncodedReference = {\n '/': string;\n};\n\nexport const encodeReference = (reference: Reference): EncodedReference => ({\n '/': reference.toDXN().toString(),\n});\n\nexport const decodeReference = (value: any) => Reference.fromDXN(DXN.parse(value['/']));\n\nexport const isEncodedReference = (value: any): value is EncodedReference =>\n typeof value === 'object' && value !== null && Object.keys(value).length === 1 && typeof value['/'] === 'string';\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Denotes the data version of the space automerge document as well as the leaf documents for each individual ECHO object.\n */\nexport type SpaceDocVersion = number & { __type: 'SpaceDocVersion' };\n\nexport const SpaceDocVersion = Object.freeze({\n /**\n * For the documents created before the versioning was introduced.\n */\n LEGACY: 0 as SpaceDocVersion,\n\n /**\n * Current version.\n */\n CURRENT: 1 as SpaceDocVersion,\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { PublicKey, SpaceId } from '@dxos/keys';\nimport { ComplexMap } from '@dxos/util';\n\nconst SPACE_IDS_CACHE = new ComplexMap<PublicKey, SpaceId>(PublicKey.hash);\n\n/**\n * Space keys are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).\n * Inspired by how ethereum addresses are derived.\n */\nexport const createIdFromSpaceKey = async (spaceKey: PublicKey): Promise<SpaceId> => {\n const cachedValue = SPACE_IDS_CACHE.get(spaceKey);\n if (cachedValue !== undefined) {\n return cachedValue;\n }\n\n const digest = await subtleCrypto.digest('SHA-256', spaceKey.asUint8Array());\n\n const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);\n const spaceId = SpaceId.encode(bytes);\n SPACE_IDS_CACHE.set(spaceKey, spaceId);\n return spaceId;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kBAAqD;AEArD,oBAA6B;AAC7B,IAAAA,eAAmC;AACnC,kBAA2B;AFMpB,IAAMC,YAAN,MAAMA,WAAAA;EAKX,OAAA;SAAOC,gBAAgB;;EAEvB,OAAOC,QAAQC,KAAqB;AAClC,YAAQA,IAAIC,MAAI;MACd,KAAKC,gBAAID,KAAKE;AACZ,eAAO,IAAIN,WAAUG,IAAII,MAAM,CAAA,GAAIP,WAAUC,eAAe,YAAYE,GAAAA;MAC1E,KAAKE,gBAAID,KAAKI;AACZ,YAAIL,IAAII,MAAM,CAAA,MAAOE,6BAAiB;AACpC,iBAAO,IAAIT,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWA,QAAWP,GAAAA;QAC3D,OAAO;AACL,iBAAO,IAAIH,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWP,IAAII,M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AO,IAAIR,gBAAIA,gBAAID,KAAKI,MAAM;UAACC;UAAiB,KAAKI;SAAS;MAChE;IACF;EACF;AACF;AAEO,IAAMe,qBAAqB;AAS3B,IAAMC,kBAAkB,CAACC,eAA4C;EAC1E,KAAKA,UAAUH,MAAK,EAAGI,SAAQ;AACjC;AAEO,IAAMC,kBAAkB,CAACpB,UAAeZ,UAAUE,QAAQG,gBAAI4B,MAAMrB,MAAM,GAAA,CAAI,CAAA;AAE9E,IAAMsB,qBAAqB,CAACtB,UACjC,OAAOA,UAAU,YAAYA,UAAU,QAAQuB,OAAOC,KAAKxB,KAAAA,EAAOyB,WAAW,KAAK,OAAOzB,MAAM,GAAA,MAAS;ACnInG,IAAM0B,kBAAkBH,OAAOI,OAAO;;;;EAI3CC,QAAQ;;;;EAKRC,SAAS;AACX,CAAA;ACXA,IAAMC,kBAAkB,IAAIC,uBAA+BC,uBAAUC,IAAI;AAMlE,IAAMC,uBAAuB,OAAO1B,aAAAA;AACzC,QAAM2B,cAAcL,gBAAgBM,IAAI5B,QAAAA;AACxC,MAAI2B,gBAAgBrC,QAAW;AAC7B,WAAOqC;EACT;AAEA,QAAME,SAAS,MAAMC,2BAAaD,OAAO,WAAW7B,SAAS+B,aAAY,CAAA;AAEzE,QAAMC,QAAQ,IAAIC,WAAWJ,MAAAA,EAAQK,MAAM,GAAGC,qBAAQC,UAAU;AAChE,QAAMC,UAAUF,qBAAQ7B,OAAO0B,KAAAA;AAC/BV,kBAAgBgB,IAAItC,UAAUqC,OAAAA;AAC9B,SAAOA;AACT;",
6
+ "names": ["import_keys", "Reference", "TYPE_PROTOCOL", "fromDXN", "dxn", "kind", "DXN", "TYPE", "parts", "ECHO", "LOCAL_SPACE_TAG", "undefined", "fromValue", "value", "objectId", "protocol", "host", "localObjectReference", "fromLegacyTypename", "type", "fromObjectIdAndSpaceKey", "spaceKey", "toHex", "_objectId", "_protocol", "_host", "_dxn", "encode", "toDXN", "REFERENCE_TYPE_TAG", "encodeReference", "reference", "toString", "decodeReference", "parse", "isEncodedReference", "Object", "keys", "length", "SpaceDocVersion", "freeze", "LEGACY", "CURRENT", "SPACE_IDS_CACHE", "ComplexMap", "PublicKey", "hash", "createIdFromSpaceKey", "cachedValue", "get", "digest", "subtleCrypto", "asUint8Array", "bytes", "Uint8Array", "slice", "SpaceId", "byteLength", "spaceId", "set"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":2912,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/reference.ts":{"bytes":14189,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytes":1591,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/collection-sync.ts":{"bytes":550,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytes":3580,"imports":[{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-protocol/src/index.ts":{"bytes":931,"imports":[{"path":"packages/core/echo/echo-protocol/src/document-structure.ts","kind":"import-statement","original":"./document-structure"},{"path":"packages/core/echo/echo-protocol/src/reference.ts","kind":"import-statement","original":"./reference"},{"path":"packages/core/echo/echo-protocol/src/space-doc-version.ts","kind":"import-statement","original":"./space-doc-version"},{"path":"packages/core/echo/echo-protocol/src/collection-sync.ts","kind":"import-statement","original":"./collection-sync"},{"path":"packages/core/echo/echo-protocol/src/space-id.ts","kind":"import-statement","original":"./space-id"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-protocol/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9297},"packages/core/echo/echo-protocol/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["REFERENCE_TYPE_TAG","Reference","SpaceDocVersion","createIdFromSpaceKey","decodeReference","encodeReference","isEncodedReference"],"entryPoint":"packages/core/echo/echo-protocol/src/index.ts","inputs":{"packages/core/echo/echo-protocol/src/index.ts":{"bytesInOutput":0},"packages/core/echo/echo-protocol/src/reference.ts":{"bytesInOutput":3064},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytesInOutput":179},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytesInOutput":604}},"bytes":4199}}}
1
+ {"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":2912,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/reference.ts":{"bytes":13381,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytes":1591,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/collection-sync.ts":{"bytes":550,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytes":3580,"imports":[{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-protocol/src/index.ts":{"bytes":931,"imports":[{"path":"packages/core/echo/echo-protocol/src/document-structure.ts","kind":"import-statement","original":"./document-structure"},{"path":"packages/core/echo/echo-protocol/src/reference.ts","kind":"import-statement","original":"./reference"},{"path":"packages/core/echo/echo-protocol/src/space-doc-version.ts","kind":"import-statement","original":"./space-doc-version"},{"path":"packages/core/echo/echo-protocol/src/collection-sync.ts","kind":"import-statement","original":"./collection-sync"},{"path":"packages/core/echo/echo-protocol/src/space-id.ts","kind":"import-statement","original":"./space-id"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-protocol/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":8851},"packages/core/echo/echo-protocol/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["REFERENCE_TYPE_TAG","Reference","SpaceDocVersion","createIdFromSpaceKey","decodeReference","encodeReference","isEncodedReference"],"entryPoint":"packages/core/echo/echo-protocol/src/index.ts","inputs":{"packages/core/echo/echo-protocol/src/index.ts":{"bytesInOutput":0},"packages/core/echo/echo-protocol/src/reference.ts":{"bytesInOutput":2866},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytesInOutput":179},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytesInOutput":604}},"bytes":4001}}}
@@ -113,12 +113,7 @@ var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
113
113
  var encodeReference = (reference) => ({
114
114
  "/": reference.toDXN().toString()
115
115
  });
116
- var decodeReference = (value) => {
117
- if (value.length % 2 === 0 && value.slice(0, value.length / 2) === value.slice(value.length / 2) && value.includes("dxn:echo")) {
118
- throw new Error("Automerge bug detected!");
119
- }
120
- return Reference.fromDXN(DXN.parse(value["/"]));
121
- };
116
+ var decodeReference = (value) => Reference.fromDXN(DXN.parse(value["/"]));
122
117
  var isEncodedReference = (value) => typeof value === "object" && value !== null && Object.keys(value).length === 1 && typeof value["/"] === "string";
123
118
 
124
119
  // packages/core/echo/echo-protocol/src/space-doc-version.ts
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/reference.ts", "../../../src/space-doc-version.ts", "../../../src/space-id.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { DXN, LOCAL_SPACE_TAG, type PublicKey } from '@dxos/keys';\nimport { type ObjectId } from '@dxos/protocols';\nimport { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';\n\n/**\n * Runtime representation of an reference in ECHO.\n * Implemented as a DXN, but we might extend it to other URIs in the future.\n */\nexport class Reference {\n /**\n * Protocol references to runtime registered types.\n * @deprecated\n */\n static TYPE_PROTOCOL = 'protobuf';\n\n static fromDXN(dxn: DXN): Reference {\n switch (dxn.kind) {\n case DXN.kind.TYPE:\n return new Reference(dxn.parts[0], Reference.TYPE_PROTOCOL, 'dxos.org', dxn);\n case DXN.kind.ECHO:\n if (dxn.parts[0] === LOCAL_SPACE_TAG) {\n return new Reference(dxn.parts[1], undefined, undefined, dxn);\n } else {\n return new Reference(dxn.parts[1], undefined, dxn.parts[0], dxn);\n }\n default:\n return new Reference(dxn.parts[0], undefined, dxn.parts[0], dxn);\n }\n }\n\n static fromValue(value: ReferenceProto): Reference {\n return new Reference(value.objectId, value.protocol, value.host);\n }\n\n /**\n * Reference an object in the local space.\n */\n static localObjectReference(objectId: ObjectId): Reference {\n return new Reference(objectId);\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n static fromLegacyTypename(type: string): Reference {\n return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove\n static fromObjectIdAndSpaceKey(objectId: ObjectId, spaceKey: PublicKey): Reference {\n // TODO(dmaretskyi): FIX ME! This should be a space ID not a space key.\n return new Reference(objectId, undefined, spaceKey.toHex());\n }\n\n // prettier-ignore\n private constructor(\n // TODO(dmaretskyi): Remove and just leave DXN.\n private readonly _objectId: ObjectId,\n private readonly _protocol?: string,\n private readonly _host?: string,\n private readonly _dxn?: DXN,\n ) {}\n\n get dxn(): DXN | undefined {\n return this._dxn;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get objectId(): ObjectId {\n return this._objectId;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get protocol(): string | undefined {\n return this._protocol;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get host(): string | undefined {\n return this._host;\n }\n\n encode(): ReferenceProto {\n return { objectId: this.objectId, host: this.host, protocol: this.protocol };\n }\n\n // TODO(dmaretskyi): Remove in favor of `reference.dxn`.\n toDXN(): DXN {\n if (this._dxn) {\n return this._dxn;\n }\n\n if (this.protocol === Reference.TYPE_PROTOCOL) {\n return new DXN(DXN.kind.TYPE, [this.objectId]);\n } else {\n if (this.host) {\n // Host is assumed to be the space key.\n // The DXN should actually have the space ID.\n // TODO(dmaretskyi): Migrate to space id.\n return new DXN(DXN.kind.ECHO, [this.host, this.objectId]);\n } else {\n return new DXN(DXN.kind.ECHO, [LOCAL_SPACE_TAG, this.objectId]);\n }\n }\n }\n}\n\nexport const REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';\n\n/**\n * Reference as it is stored in Automerge document.\n */\nexport type EncodedReference = {\n '/': string;\n};\n\nexport const encodeReference = (reference: Reference): EncodedReference => ({\n '/': reference.toDXN().toString(),\n});\n\nexport const decodeReference = (value: any) => {\n if (\n value.length % 2 === 0 &&\n value.slice(0, value.length / 2) === value.slice(value.length / 2) &&\n value.includes('dxn:echo')\n ) {\n throw new Error('Automerge bug detected!');\n }\n\n return Reference.fromDXN(DXN.parse(value['/']));\n};\n\nexport const isEncodedReference = (value: any): value is EncodedReference =>\n typeof value === 'object' && value !== null && Object.keys(value).length === 1 && typeof value['/'] === 'string';\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Denotes the data version of the space automerge document as well as the leaf documents for each individual ECHO object.\n */\nexport type SpaceDocVersion = number & { __type: 'SpaceDocVersion' };\n\nexport const SpaceDocVersion = Object.freeze({\n /**\n * For the documents created before the versioning was introduced.\n */\n LEGACY: 0 as SpaceDocVersion,\n\n /**\n * Current version.\n */\n CURRENT: 1 as SpaceDocVersion,\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { PublicKey, SpaceId } from '@dxos/keys';\nimport { ComplexMap } from '@dxos/util';\n\nconst SPACE_IDS_CACHE = new ComplexMap<PublicKey, SpaceId>(PublicKey.hash);\n\n/**\n * Space keys are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).\n * Inspired by how ethereum addresses are derived.\n */\nexport const createIdFromSpaceKey = async (spaceKey: PublicKey): Promise<SpaceId> => {\n const cachedValue = SPACE_IDS_CACHE.get(spaceKey);\n if (cachedValue !== undefined) {\n return cachedValue;\n }\n\n const digest = await subtleCrypto.digest('SHA-256', spaceKey.asUint8Array());\n\n const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);\n const spaceId = SpaceId.encode(bytes);\n SPACE_IDS_CACHE.set(spaceKey, spaceId);\n return spaceId;\n};\n"],
5
- "mappings": ";;;AAIA,SAASA,KAAKC,uBAAuC;AAQ9C,IAAMC,YAAN,MAAMA,WAAAA;EAKX;;;;;SAAOC,gBAAgB;;EAEvB,OAAOC,QAAQC,KAAqB;AAClC,YAAQA,IAAIC,MAAI;MACd,KAAKC,IAAID,KAAKE;AACZ,eAAO,IAAIN,WAAUG,IAAII,MAAM,CAAA,GAAIP,WAAUC,eAAe,YAAYE,GAAAA;MAC1E,KAAKE,IAAID,KAAKI;AACZ,YAAIL,IAAII,MAAM,CAAA,MAAOE,iBAAiB;AACpC,iBAAO,IAAIT,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWA,QAAWP,GAAAA;QAC3D,OAAO;AACL,iBAAO,IAAIH,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWP,IAAII,MAAM,CAAA,GAAIJ,GAAAA;QAC9D;MACF;AACE,eAAO,IAAIH,WAAUG,IAAII,MAAM,CAAA,GAAIG,QAAWP,IAAII,MAAM,CAAA,GAAIJ,GAAAA;IAChE;EACF;EAEA,OAAOQ,UAAUC,OAAkC;AACjD,WAAO,IAAIZ,WAAUY,MAAMC,UAAUD,MAAME,UAAUF,MAAMG,IAAI;EACjE;;;;EAKA,OAAOC,qBAAqBH,UAA+B;AACzD,W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,MAAMqB,SAAS,CAAA,MAAOrB,MAAMsB,MAAMtB,MAAMqB,SAAS,CAAA,KAChErB,MAAMuB,SAAS,UAAA,GACf;AACA,UAAM,IAAIC,MAAM,yBAAA;EAClB;AAEA,SAAOpC,UAAUE,QAAQG,IAAIgC,MAAMzB,MAAM,GAAA,CAAI,CAAA;AAC/C;AAEO,IAAM0B,qBAAqB,CAAC1B,UACjC,OAAOA,UAAU,YAAYA,UAAU,QAAQ2B,OAAOC,KAAK5B,KAAAA,EAAOqB,WAAW,KAAK,OAAOrB,MAAM,GAAA,MAAS;;;AC7InG,IAAM6B,kBAAkBC,OAAOC,OAAO;;;;EAI3CC,QAAQ;;;;EAKRC,SAAS;AACX,CAAA;;;ACfA,SAASC,oBAAoB;AAC7B,SAASC,WAAWC,eAAe;AACnC,SAASC,kBAAkB;AAE3B,IAAMC,kBAAkB,IAAIC,WAA+BC,UAAUC,IAAI;AAMlE,IAAMC,uBAAuB,OAAOC,aAAAA;AACzC,QAAMC,cAAcN,gBAAgBO,IAAIF,QAAAA;AACxC,MAAIC,gBAAgBE,QAAW;AAC7B,WAAOF;EACT;AAEA,QAAMG,SAAS,MAAMC,aAAaD,OAAO,WAAWJ,SAASM,aAAY,CAAA;AAEzE,QAAMC,QAAQ,IAAIC,WAAWJ,MAAAA,EAAQK,MAAM,GAAGC,QAAQC,UAAU;AAChE,QAAMC,UAAUF,QAAQG,OAAON,KAAAA;AAC/BZ,kBAAgBmB,IAAId,UAAUY,OAAAA;AAC9B,SAAOA;AACT;",
6
- "names": ["DXN", "LOCAL_SPACE_TAG", "Reference", "TYPE_PROTOCOL", "fromDXN", "dxn", "kind", "DXN", "TYPE", "parts", "ECHO", "LOCAL_SPACE_TAG", "undefined", "fromValue", "value", "objectId", "protocol", "host", "localObjectReference", "fromLegacyTypename", "type", "fromObjectIdAndSpaceKey", "spaceKey", "toHex", "_objectId", "_protocol", "_host", "_dxn", "encode", "toDXN", "REFERENCE_TYPE_TAG", "encodeReference", "reference", "toString", "decodeReference", "length", "slice", "includes", "Error", "parse", "isEncodedReference", "Object", "keys", "SpaceDocVersion", "Object", "freeze", "LEGACY", "CURRENT", "subtleCrypto", "PublicKey", "SpaceId", "ComplexMap", "SPACE_IDS_CACHE", "ComplexMap", "PublicKey", "hash", "createIdFromSpaceKey", "spaceKey", "cachedValue", "get", "undefined", "digest", "subtleCrypto", "asUint8Array", "bytes", "Uint8Array", "slice", "SpaceId", "byteLength", "spaceId", "encode", "set"]
4
+ "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { DXN, LOCAL_SPACE_TAG, type PublicKey } from '@dxos/keys';\nimport { type ObjectId } from '@dxos/protocols';\nimport { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';\n\n/**\n * Runtime representation of an reference in ECHO.\n * Implemented as a DXN, but we might extend it to other URIs in the future.\n */\nexport class Reference {\n /**\n * Protocol references to runtime registered types.\n * @deprecated\n */\n static TYPE_PROTOCOL = 'protobuf';\n\n static fromDXN(dxn: DXN): Reference {\n switch (dxn.kind) {\n case DXN.kind.TYPE:\n return new Reference(dxn.parts[0], Reference.TYPE_PROTOCOL, 'dxos.org', dxn);\n case DXN.kind.ECHO:\n if (dxn.parts[0] === LOCAL_SPACE_TAG) {\n return new Reference(dxn.parts[1], undefined, undefined, dxn);\n } else {\n return new Reference(dxn.parts[1], undefined, dxn.parts[0], dxn);\n }\n default:\n return new Reference(dxn.parts[0], undefined, dxn.parts[0], dxn);\n }\n }\n\n static fromValue(value: ReferenceProto): Reference {\n return new Reference(value.objectId, value.protocol, value.host);\n }\n\n /**\n * Reference an object in the local space.\n */\n static localObjectReference(objectId: ObjectId): Reference {\n return new Reference(objectId);\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n static fromLegacyTypename(type: string): Reference {\n return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove\n static fromObjectIdAndSpaceKey(objectId: ObjectId, spaceKey: PublicKey): Reference {\n // TODO(dmaretskyi): FIX ME! This should be a space ID not a space key.\n return new Reference(objectId, undefined, spaceKey.toHex());\n }\n\n // prettier-ignore\n private constructor(\n // TODO(dmaretskyi): Remove and just leave DXN.\n private readonly _objectId: ObjectId,\n private readonly _protocol?: string,\n private readonly _host?: string,\n private readonly _dxn?: DXN,\n ) {}\n\n get dxn(): DXN | undefined {\n return this._dxn;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get objectId(): ObjectId {\n return this._objectId;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get protocol(): string | undefined {\n return this._protocol;\n }\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): Remove.\n get host(): string | undefined {\n return this._host;\n }\n\n encode(): ReferenceProto {\n return { objectId: this.objectId, host: this.host, protocol: this.protocol };\n }\n\n // TODO(dmaretskyi): Remove in favor of `reference.dxn`.\n toDXN(): DXN {\n if (this._dxn) {\n return this._dxn;\n }\n\n if (this.protocol === Reference.TYPE_PROTOCOL) {\n return new DXN(DXN.kind.TYPE, [this.objectId]);\n } else {\n if (this.host) {\n // Host is assumed to be the space key.\n // The DXN should actually have the space ID.\n // TODO(dmaretskyi): Migrate to space id.\n return new DXN(DXN.kind.ECHO, [this.host, this.objectId]);\n } else {\n return new DXN(DXN.kind.ECHO, [LOCAL_SPACE_TAG, this.objectId]);\n }\n }\n }\n}\n\nexport const REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';\n\n/**\n * Reference as it is stored in Automerge document.\n */\nexport type EncodedReference = {\n '/': string;\n};\n\nexport const encodeReference = (reference: Reference): EncodedReference => ({\n '/': reference.toDXN().toString(),\n});\n\nexport const decodeReference = (value: any) => Reference.fromDXN(DXN.parse(value['/']));\n\nexport const isEncodedReference = (value: any): value is EncodedReference =>\n typeof value === 'object' && value !== null && Object.keys(value).length === 1 && typeof value['/'] === 'string';\n", "//\n// Copyright 2024 DXOS.org\n//\n\n/**\n * Denotes the data version of the space automerge document as well as the leaf documents for each individual ECHO object.\n */\nexport type SpaceDocVersion = number & { __type: 'SpaceDocVersion' };\n\nexport const SpaceDocVersion = Object.freeze({\n /**\n * For the documents created before the versioning was introduced.\n */\n LEGACY: 0 as SpaceDocVersion,\n\n /**\n * Current version.\n */\n CURRENT: 1 as SpaceDocVersion,\n});\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { PublicKey, SpaceId } from '@dxos/keys';\nimport { ComplexMap } from '@dxos/util';\n\nconst SPACE_IDS_CACHE = new ComplexMap<PublicKey, SpaceId>(PublicKey.hash);\n\n/**\n * Space keys are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).\n * Inspired by how ethereum addresses are derived.\n */\nexport const createIdFromSpaceKey = async (spaceKey: PublicKey): Promise<SpaceId> => {\n const cachedValue = SPACE_IDS_CACHE.get(spaceKey);\n if (cachedValue !== undefined) {\n return cachedValue;\n }\n\n const digest = await subtleCrypto.digest('SHA-256', spaceKey.asUint8Array());\n\n const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);\n const spaceId = SpaceId.encode(bytes);\n SPACE_IDS_CACHE.set(spaceKey, spaceId);\n return spaceId;\n};\n"],
5
+ "mappings": ";;;AAIA,SAASA,KAAKC,uBAAuC;AAQ9C,IAAMC,YAAN,MAAMA,WAAAA;EAKX;;;;;SAAOC,gBAAgB;;EAEvB,OAAOC,QAAQC,KAAqB;AAClC,YAAQA,IAAIC,MAAI;MACd,KAAKC,IAAID,KAAKE;AACZ,eAAO,IAAIN,WAAUG,IAAII,MAAM,CAAA,GAAIP,WAAUC,eAAe,YAAYE,GAAAA;MAC1E,KAAKE,IAAID,KAAKI;AACZ,YAAIL,IAAII,MAAM,CAAA,MAAOE,iBAAiB;AACpC,iBAAO,IAAIT,WAAUG,IAAII,MAAM,CAAA,GAAIG,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efined", "fromValue", "value", "objectId", "protocol", "host", "localObjectReference", "fromLegacyTypename", "type", "fromObjectIdAndSpaceKey", "spaceKey", "toHex", "_objectId", "_protocol", "_host", "_dxn", "encode", "toDXN", "REFERENCE_TYPE_TAG", "encodeReference", "reference", "toString", "decodeReference", "parse", "isEncodedReference", "Object", "keys", "length", "SpaceDocVersion", "Object", "freeze", "LEGACY", "CURRENT", "subtleCrypto", "PublicKey", "SpaceId", "ComplexMap", "SPACE_IDS_CACHE", "ComplexMap", "PublicKey", "hash", "createIdFromSpaceKey", "spaceKey", "cachedValue", "get", "undefined", "digest", "subtleCrypto", "asUint8Array", "bytes", "Uint8Array", "slice", "SpaceId", "byteLength", "spaceId", "encode", "set"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":2912,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/reference.ts":{"bytes":14189,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytes":1591,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/collection-sync.ts":{"bytes":550,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytes":3580,"imports":[{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-protocol/src/index.ts":{"bytes":931,"imports":[{"path":"packages/core/echo/echo-protocol/src/document-structure.ts","kind":"import-statement","original":"./document-structure"},{"path":"packages/core/echo/echo-protocol/src/reference.ts","kind":"import-statement","original":"./reference"},{"path":"packages/core/echo/echo-protocol/src/space-doc-version.ts","kind":"import-statement","original":"./space-doc-version"},{"path":"packages/core/echo/echo-protocol/src/collection-sync.ts","kind":"import-statement","original":"./collection-sync"},{"path":"packages/core/echo/echo-protocol/src/space-id.ts","kind":"import-statement","original":"./space-id"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-protocol/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9299},"packages/core/echo/echo-protocol/dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["REFERENCE_TYPE_TAG","Reference","SpaceDocVersion","createIdFromSpaceKey","decodeReference","encodeReference","isEncodedReference"],"entryPoint":"packages/core/echo/echo-protocol/src/index.ts","inputs":{"packages/core/echo/echo-protocol/src/index.ts":{"bytesInOutput":0},"packages/core/echo/echo-protocol/src/reference.ts":{"bytesInOutput":3064},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytesInOutput":179},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytesInOutput":604}},"bytes":4292}}}
1
+ {"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":2912,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/reference.ts":{"bytes":13381,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytes":1591,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/collection-sync.ts":{"bytes":550,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytes":3580,"imports":[{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-protocol/src/index.ts":{"bytes":931,"imports":[{"path":"packages/core/echo/echo-protocol/src/document-structure.ts","kind":"import-statement","original":"./document-structure"},{"path":"packages/core/echo/echo-protocol/src/reference.ts","kind":"import-statement","original":"./reference"},{"path":"packages/core/echo/echo-protocol/src/space-doc-version.ts","kind":"import-statement","original":"./space-doc-version"},{"path":"packages/core/echo/echo-protocol/src/collection-sync.ts","kind":"import-statement","original":"./collection-sync"},{"path":"packages/core/echo/echo-protocol/src/space-id.ts","kind":"import-statement","original":"./space-id"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-protocol/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":8853},"packages/core/echo/echo-protocol/dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["REFERENCE_TYPE_TAG","Reference","SpaceDocVersion","createIdFromSpaceKey","decodeReference","encodeReference","isEncodedReference"],"entryPoint":"packages/core/echo/echo-protocol/src/index.ts","inputs":{"packages/core/echo/echo-protocol/src/index.ts":{"bytesInOutput":0},"packages/core/echo/echo-protocol/src/reference.ts":{"bytesInOutput":2866},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytesInOutput":179},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytesInOutput":604}},"bytes":4094}}}
@@ -1 +1 @@
1
- {"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/reference.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAmB,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,KAAK,SAAS,IAAI,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAElG;;;GAGG;AACH,qBAAa,SAAS;IAqDlB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IAvDxB;;;OAGG;IACH,MAAM,CAAC,a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,gBACyD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/echo-protocol",
3
- "version": "0.8.2-main.f11618f",
3
+ "version": "0.8.2-staging.7ac8446",
4
4
  "description": "Core ECHO APIs.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -25,10 +25,10 @@
25
25
  "src"
26
26
  ],
27
27
  "dependencies": {
28
- "@dxos/keys": "0.8.2-main.f11618f",
29
- "@dxos/crypto": "0.8.2-main.f11618f",
30
- "@dxos/protocols": "0.8.2-main.f11618f",
31
- "@dxos/util": "0.8.2-main.f11618f"
28
+ "@dxos/crypto": "0.8.2-staging.7ac8446",
29
+ "@dxos/keys": "0.8.2-staging.7ac8446",
30
+ "@dxos/protocols": "0.8.2-staging.7ac8446",
31
+ "@dxos/util": "0.8.2-staging.7ac8446"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
package/src/reference.ts CHANGED
@@ -135,17 +135,7 @@ export const encodeReference = (reference: Reference): EncodedReference => ({
135
135
  '/': reference.toDXN().toString(),
136
136
  });
137
137
 
138
- export const decodeReference = (value: any) => {
139
- if (
140
- value.length % 2 === 0 &&
141
- value.slice(0, value.length / 2) === value.slice(value.length / 2) &&
142
- value.includes('dxn:echo')
143
- ) {
144
- throw new Error('Automerge bug detected!');
145
- }
146
-
147
- return Reference.fromDXN(DXN.parse(value['/']));
148
- };
138
+ export const decodeReference = (value: any) => Reference.fromDXN(DXN.parse(value['/']));
149
139
 
150
140
  export const isEncodedReference = (value: any): value is EncodedReference =>
151
141
  typeof value === 'object' && value !== null && Object.keys(value).length === 1 && typeof value['/'] === 'string';