@dxos/echo-protocol 0.7.2 → 0.7.3-staging.971cd8d

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,24 +1,5 @@
1
1
  // packages/core/echo/echo-protocol/src/reference.ts
2
- import { DXN, LOCAL_SPACE_TAG, PublicKey as PublicKey2 } from "@dxos/keys";
3
-
4
- // packages/core/echo/echo-protocol/src/space-id.ts
5
- import { subtleCrypto } from "@dxos/crypto";
6
- import { PublicKey, SpaceId } from "@dxos/keys";
7
- import { ComplexMap } from "@dxos/util";
8
- var SPACE_IDS_CACHE = new ComplexMap(PublicKey.hash);
9
- var createIdFromSpaceKey = async (spaceKey) => {
10
- const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
11
- if (cachedValue !== void 0) {
12
- return cachedValue;
13
- }
14
- const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
15
- const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
16
- const spaceId = SpaceId.encode(bytes);
17
- SPACE_IDS_CACHE.set(spaceKey, spaceId);
18
- return spaceId;
19
- };
20
-
21
- // packages/core/echo/echo-protocol/src/reference.ts
2
+ import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
22
3
  var Reference = class _Reference {
23
4
  static {
24
5
  /**
@@ -26,16 +7,6 @@ var Reference = class _Reference {
26
7
  */
27
8
  this.TYPE_PROTOCOL = "protobuf";
28
9
  }
29
- static fromValue(value) {
30
- return new _Reference(value.objectId, value.protocol, value.host);
31
- }
32
- /**
33
- * @deprecated
34
- */
35
- // TODO(burdon): Document/remove?
36
- static fromLegacyTypename(type) {
37
- return new _Reference(type, _Reference.TYPE_PROTOCOL, "dxos.org");
38
- }
39
10
  static fromDXN(dxn) {
40
11
  switch (dxn.kind) {
41
12
  case DXN.kind.TYPE:
@@ -50,6 +21,22 @@ var Reference = class _Reference {
50
21
  throw new Error(`Unsupported DXN kind: ${dxn.kind}`);
51
22
  }
52
23
  }
24
+ static fromValue(value) {
25
+ return new _Reference(value.objectId, value.protocol, value.host);
26
+ }
27
+ /**
28
+ * Reference an object in the local space.
29
+ */
30
+ static localObjectReference(objectId) {
31
+ return new _Reference(objectId);
32
+ }
33
+ /**
34
+ * @deprecated
35
+ */
36
+ // TODO(burdon): Document/remove?
37
+ static fromLegacyTypename(type) {
38
+ return new _Reference(type, _Reference.TYPE_PROTOCOL, "dxos.org");
39
+ }
53
40
  // prettier-ignore
54
41
  constructor(objectId, protocol, host) {
55
42
  this.objectId = objectId;
@@ -89,17 +76,6 @@ var encodeReference = (reference) => ({
89
76
  });
90
77
  var decodeReference = (value) => Reference.fromDXN(DXN.parse(value["/"]));
91
78
  var isEncodedReference = (value) => typeof value === "object" && value !== null && Object.keys(value).length === 1 && typeof value["/"] === "string";
92
- var convertLegacyReference = async (reference) => {
93
- if (reference.protocol === Reference.TYPE_PROTOCOL) {
94
- return encodeReference(Reference.fromLegacyTypename(reference.itemId));
95
- }
96
- if (!reference.itemId) {
97
- throw new Error("Invalid reference");
98
- }
99
- const spaceKey = reference.host;
100
- const spaceId = spaceKey != null ? await createIdFromSpaceKey(PublicKey2.fromHex(spaceKey)) : void 0;
101
- return encodeReference(new Reference(reference.itemId, reference.protocol ?? void 0, spaceId));
102
- };
103
79
 
104
80
  // packages/core/echo/echo-protocol/src/space-doc-version.ts
105
81
  var SpaceDocVersion = Object.freeze({
@@ -113,21 +89,29 @@ var SpaceDocVersion = Object.freeze({
113
89
  CURRENT: 1
114
90
  });
115
91
 
116
- // packages/core/echo/echo-protocol/src/legacy.ts
117
- var LEGACY_REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
118
- var isLegacyReference = (value) => typeof value === "object" && value !== null && value["@type"] === LEGACY_REFERENCE_TYPE_TAG;
119
- var LEGACY_TYPE_PROPERTIES = "dxos.sdk.client.Properties";
92
+ // packages/core/echo/echo-protocol/src/space-id.ts
93
+ import { subtleCrypto } from "@dxos/crypto";
94
+ import { PublicKey, SpaceId } from "@dxos/keys";
95
+ import { ComplexMap } from "@dxos/util";
96
+ var SPACE_IDS_CACHE = new ComplexMap(PublicKey.hash);
97
+ var createIdFromSpaceKey = async (spaceKey) => {
98
+ const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
99
+ if (cachedValue !== void 0) {
100
+ return cachedValue;
101
+ }
102
+ const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
103
+ const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
104
+ const spaceId = SpaceId.encode(bytes);
105
+ SPACE_IDS_CACHE.set(spaceKey, spaceId);
106
+ return spaceId;
107
+ };
120
108
  export {
121
- LEGACY_REFERENCE_TYPE_TAG,
122
- LEGACY_TYPE_PROPERTIES,
123
109
  REFERENCE_TYPE_TAG,
124
110
  Reference,
125
111
  SpaceDocVersion,
126
- convertLegacyReference,
127
112
  createIdFromSpaceKey,
128
113
  decodeReference,
129
114
  encodeReference,
130
- isEncodedReference,
131
- isLegacyReference
115
+ isEncodedReference
132
116
  };
133
117
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/reference.ts", "../../../src/space-id.ts", "../../../src/space-doc-version.ts", "../../../src/legacy.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { DXN, LOCAL_SPACE_TAG, PublicKey } from '@dxos/keys';\nimport { type ObjectId } from '@dxos/protocols';\nimport { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';\n\nimport type { LegacyEncodedReferenceObject } from './legacy';\nimport { createIdFromSpaceKey } from './space-id';\n\n/**\n * Runtime representation of object reference.\n */\nexport class Reference {\n /**\n * Protocol references to runtime registered types.\n */\n static TYPE_PROTOCOL = 'protobuf';\n\n static fromValue(value: ReferenceProto): Reference {\n return new Reference(value.objectId, value.protocol, value.host);\n }\n\n /**\n * @deprecated\n */\n // TODO(burdon): Document/remove?\n static fromLegacyTypename(type: string): Reference {\n return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');\n }\n\n static fromDXN(dxn: DXN): Reference {\n switch (dxn.kind) {\n case DXN.kind.TYPE:\n return Reference.fromLegacyTypename(dxn.parts[0]);\n case DXN.kind.ECHO:\n if (dxn.parts[0] === LOCAL_SPACE_TAG) {\n return new Reference(dxn.parts[1]);\n } else {\n return new Reference(dxn.parts[1], undefined, dxn.parts[0]);\n }\n default:\n throw new Error(`Unsupported DXN kind: ${dxn.kind}`);\n }\n }\n\n // prettier-ignore\n constructor(\n public readonly objectId: ObjectId,\n public readonly protocol?: string,\n public readonly host?: string\n ) {}\n\n encode(): ReferenceProto {\n return { objectId: this.objectId, host: this.host, protocol: this.protocol };\n }\n\n toDXN(): DXN {\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\nexport const convertLegacyReference = async (reference: LegacyEncodedReferenceObject): Promise<EncodedReference> => {\n if (reference.protocol === Reference.TYPE_PROTOCOL) {\n return encodeReference(Reference.fromLegacyTypename(reference.itemId));\n }\n if (!reference.itemId) {\n throw new Error('Invalid reference');\n }\n\n const spaceKey = reference.host;\n const spaceId = spaceKey != null ? await createIdFromSpaceKey(PublicKey.fromHex(spaceKey)) : undefined;\n return encodeReference(new Reference(reference.itemId, reference.protocol ?? undefined, spaceId));\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", "//\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\nexport const LEGACY_REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';\n\n/**\n * Reference as it is stored in Automerge document.\n */\nexport type LegacyEncodedReferenceObject = {\n '@type': typeof LEGACY_REFERENCE_TYPE_TAG;\n itemId: string;\n protocol?: string;\n host?: string;\n};\n\nexport const isLegacyReference = (value: any): boolean =>\n typeof value === 'object' && value !== null && value['@type'] ===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UD,YAAY,OAAO,MAAME,qBAAqBC,WAAUC,QAAQJ,QAAAA,CAAAA,IAAajB;AAC7F,SAAOM,gBAAgB,IAAIvB,UAAUwB,UAAUS,QAAQT,UAAUnB,YAAYY,QAAWkB,OAAAA,CAAAA;AAC1F;;;AE9FO,IAAMI,kBAAkBC,OAAOC,OAAO;;;;EAI3CC,QAAQ;;;;EAKRC,SAAS;AACX,CAAA;;;ACfO,IAAMC,4BAA4B;AAYlC,IAAMC,oBAAoB,CAACC,UAChC,OAAOA,UAAU,YAAYA,UAAU,QAAQA,MAAM,OAAA,MAAaF;AAE7D,IAAMG,yBAAyB;",
6
- "names": ["DXN", "LOCAL_SPACE_TAG", "PublicKey", "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", "Reference", "TYPE_PROTOCOL", "fromValue", "value", "objectId", "protocol", "host", "fromLegacyTypename", "type", "fromDXN", "dxn", "kind", "DXN", "TYPE", "parts", "ECHO", "LOCAL_SPACE_TAG", "undefined", "Error", "constructor", "encode", "toDXN", "REFERENCE_TYPE_TAG", "encodeReference", "reference", "toString", "decodeReference", "parse", "isEncodedReference", "Object", "keys", "length", "convertLegacyReference", "itemId", "spaceKey", "spaceId", "createIdFromSpaceKey", "PublicKey", "fromHex", "SpaceDocVersion", "Object", "freeze", "LEGACY", "CURRENT", "LEGACY_REFERENCE_TYPE_TAG", "isLegacyReference", "value", "LEGACY_TYPE_PROPERTIES"]
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 } 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 object reference.\n */\nexport class Reference {\n /**\n * Protocol references to runtime registered types.\n */\n static TYPE_PROTOCOL = 'protobuf';\n\n static fromDXN(dxn: DXN): Reference {\n switch (dxn.kind) {\n case DXN.kind.TYPE:\n return Reference.fromLegacyTypename(dxn.parts[0]);\n case DXN.kind.ECHO:\n if (dxn.parts[0] === LOCAL_SPACE_TAG) {\n return new Reference(dxn.parts[1]);\n } else {\n return new Reference(dxn.parts[1], undefined, dxn.parts[0]);\n }\n default:\n throw new Error(`Unsupported DXN kind: ${dxn.kind}`);\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(burdon): Document/remove?\n static fromLegacyTypename(type: string): Reference {\n return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');\n }\n\n // prettier-ignore\n constructor(\n public readonly objectId: ObjectId,\n public readonly protocol?: string,\n public readonly host?: string\n ) {}\n\n encode(): ReferenceProto {\n return { objectId: this.objectId, host: this.host, protocol: this.protocol };\n }\n\n toDXN(): DXN {\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,uBAAuB;AAO9B,IAAMC,YAAN,MAAMA,WAAAA;EAIX;;;;SAAOC,gBAAgB;;EAEvB,OAAOC,QAAQC,KAAqB;AAClC,YAAQA,IAAIC,MAAI;MACd,KAAKC,IAAID,KAAKE;AACZ,eAAON,WAAUO,mBAAmBJ,IAAIK,MAAM,CAAA,CAAE;MA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AUE,QAAQG,IAAIuB,MAAMd,MAAM,GAAA,CAAI,CAAA;AAE9E,IAAMe,qBAAqB,CAACf,UACjC,OAAOA,UAAU,YAAYA,UAAU,QAAQgB,OAAOC,KAAKjB,KAAAA,EAAOkB,WAAW,KAAK,OAAOlB,MAAM,GAAA,MAAS;;;ACrFnG,IAAMmB,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", "fromLegacyTypename", "parts", "ECHO", "LOCAL_SPACE_TAG", "undefined", "Error", "fromValue", "value", "objectId", "protocol", "host", "localObjectReference", "type", "constructor", "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":2608,"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/reference.ts":{"bytes":11612,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-protocol/src/space-id.ts","kind":"import-statement","original":"./space-id"}],"format":"esm"},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytes":1591,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/legacy.ts":{"bytes":1719,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/collection-sync.ts":{"bytes":550,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/index.ts":{"bytes":1017,"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/legacy.ts","kind":"import-statement","original":"./legacy"},{"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":8975},"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":["LEGACY_REFERENCE_TYPE_TAG","LEGACY_TYPE_PROPERTIES","REFERENCE_TYPE_TAG","Reference","SpaceDocVersion","convertLegacyReference","createIdFromSpaceKey","decodeReference","encodeReference","isEncodedReference","isLegacyReference"],"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":2495},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytesInOutput":604},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytesInOutput":179},"packages/core/echo/echo-protocol/src/legacy.ts":{"bytesInOutput":257}},"bytes":4094}}}
1
+ {"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":2628,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/reference.ts":{"bytes":9848,"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":7213},"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":2107},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytesInOutput":179},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytesInOutput":604}},"bytes":3242}}}
@@ -18,49 +18,23 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var node_exports = {};
20
20
  __export(node_exports, {
21
- LEGACY_REFERENCE_TYPE_TAG: () => LEGACY_REFERENCE_TYPE_TAG,
22
- LEGACY_TYPE_PROPERTIES: () => LEGACY_TYPE_PROPERTIES,
23
21
  REFERENCE_TYPE_TAG: () => REFERENCE_TYPE_TAG,
24
22
  Reference: () => Reference,
25
23
  SpaceDocVersion: () => SpaceDocVersion,
26
- convertLegacyReference: () => convertLegacyReference,
27
24
  createIdFromSpaceKey: () => createIdFromSpaceKey,
28
25
  decodeReference: () => decodeReference,
29
26
  encodeReference: () => encodeReference,
30
- isEncodedReference: () => isEncodedReference,
31
- isLegacyReference: () => isLegacyReference
27
+ isEncodedReference: () => isEncodedReference
32
28
  });
33
29
  module.exports = __toCommonJS(node_exports);
34
30
  var import_keys = require("@dxos/keys");
35
31
  var import_crypto = require("@dxos/crypto");
36
32
  var import_keys2 = require("@dxos/keys");
37
33
  var import_util = require("@dxos/util");
38
- var SPACE_IDS_CACHE = new import_util.ComplexMap(import_keys2.PublicKey.hash);
39
- var createIdFromSpaceKey = async (spaceKey) => {
40
- const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
41
- if (cachedValue !== void 0) {
42
- return cachedValue;
43
- }
44
- const digest = await import_crypto.subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
45
- const bytes = new Uint8Array(digest).slice(0, import_keys2.SpaceId.byteLength);
46
- const spaceId = import_keys2.SpaceId.encode(bytes);
47
- SPACE_IDS_CACHE.set(spaceKey, spaceId);
48
- return spaceId;
49
- };
50
34
  var Reference = class _Reference {
51
35
  static {
52
36
  this.TYPE_PROTOCOL = "protobuf";
53
37
  }
54
- static fromValue(value) {
55
- return new _Reference(value.objectId, value.protocol, value.host);
56
- }
57
- /**
58
- * @deprecated
59
- */
60
- // TODO(burdon): Document/remove?
61
- static fromLegacyTypename(type) {
62
- return new _Reference(type, _Reference.TYPE_PROTOCOL, "dxos.org");
63
- }
64
38
  static fromDXN(dxn) {
65
39
  switch (dxn.kind) {
66
40
  case import_keys.DXN.kind.TYPE:
@@ -75,6 +49,22 @@ var Reference = class _Reference {
75
49
  throw new Error(`Unsupported DXN kind: ${dxn.kind}`);
76
50
  }
77
51
  }
52
+ static fromValue(value) {
53
+ return new _Reference(value.objectId, value.protocol, value.host);
54
+ }
55
+ /**
56
+ * Reference an object in the local space.
57
+ */
58
+ static localObjectReference(objectId) {
59
+ return new _Reference(objectId);
60
+ }
61
+ /**
62
+ * @deprecated
63
+ */
64
+ // TODO(burdon): Document/remove?
65
+ static fromLegacyTypename(type) {
66
+ return new _Reference(type, _Reference.TYPE_PROTOCOL, "dxos.org");
67
+ }
78
68
  // prettier-ignore
79
69
  constructor(objectId, protocol, host) {
80
70
  this.objectId = objectId;
@@ -114,17 +104,6 @@ var encodeReference = (reference) => ({
114
104
  });
115
105
  var decodeReference = (value) => Reference.fromDXN(import_keys.DXN.parse(value["/"]));
116
106
  var isEncodedReference = (value) => typeof value === "object" && value !== null && Object.keys(value).length === 1 && typeof value["/"] === "string";
117
- var convertLegacyReference = async (reference) => {
118
- if (reference.protocol === Reference.TYPE_PROTOCOL) {
119
- return encodeReference(Reference.fromLegacyTypename(reference.itemId));
120
- }
121
- if (!reference.itemId) {
122
- throw new Error("Invalid reference");
123
- }
124
- const spaceKey = reference.host;
125
- const spaceId = spaceKey != null ? await createIdFromSpaceKey(import_keys.PublicKey.fromHex(spaceKey)) : void 0;
126
- return encodeReference(new Reference(reference.itemId, reference.protocol ?? void 0, spaceId));
127
- };
128
107
  var SpaceDocVersion = Object.freeze({
129
108
  /**
130
109
  * For the documents created before the versioning was introduced.
@@ -135,21 +114,26 @@ var SpaceDocVersion = Object.freeze({
135
114
  */
136
115
  CURRENT: 1
137
116
  });
138
- var LEGACY_REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
139
- var isLegacyReference = (value) => typeof value === "object" && value !== null && value["@type"] === LEGACY_REFERENCE_TYPE_TAG;
140
- var LEGACY_TYPE_PROPERTIES = "dxos.sdk.client.Properties";
117
+ var SPACE_IDS_CACHE = new import_util.ComplexMap(import_keys2.PublicKey.hash);
118
+ var createIdFromSpaceKey = async (spaceKey) => {
119
+ const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
120
+ if (cachedValue !== void 0) {
121
+ return cachedValue;
122
+ }
123
+ const digest = await import_crypto.subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
124
+ const bytes = new Uint8Array(digest).slice(0, import_keys2.SpaceId.byteLength);
125
+ const spaceId = import_keys2.SpaceId.encode(bytes);
126
+ SPACE_IDS_CACHE.set(spaceKey, spaceId);
127
+ return spaceId;
128
+ };
141
129
  // Annotate the CommonJS export names for ESM import in node:
142
130
  0 && (module.exports = {
143
- LEGACY_REFERENCE_TYPE_TAG,
144
- LEGACY_TYPE_PROPERTIES,
145
131
  REFERENCE_TYPE_TAG,
146
132
  Reference,
147
133
  SpaceDocVersion,
148
- convertLegacyReference,
149
134
  createIdFromSpaceKey,
150
135
  decodeReference,
151
136
  encodeReference,
152
- isEncodedReference,
153
- isLegacyReference
137
+ isEncodedReference
154
138
  });
155
139
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/reference.ts", "../../../src/space-id.ts", "../../../src/space-doc-version.ts", "../../../src/legacy.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { DXN, LOCAL_SPACE_TAG, PublicKey } from '@dxos/keys';\nimport { type ObjectId } from '@dxos/protocols';\nimport { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';\n\nimport type { LegacyEncodedReferenceObject } from './legacy';\nimport { createIdFromSpaceKey } from './space-id';\n\n/**\n * Runtime representation of object reference.\n */\nexport class Reference {\n /**\n * Protocol references to runtime registered types.\n */\n static TYPE_PROTOCOL = 'protobuf';\n\n static fromValue(value: ReferenceProto): Reference {\n return new Reference(value.objectId, value.protocol, value.host);\n }\n\n /**\n * @deprecated\n */\n // TODO(burdon): Document/remove?\n static fromLegacyTypename(type: string): Reference {\n return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');\n }\n\n static fromDXN(dxn: DXN): Reference {\n switch (dxn.kind) {\n case DXN.kind.TYPE:\n return Reference.fromLegacyTypename(dxn.parts[0]);\n case DXN.kind.ECHO:\n if (dxn.parts[0] === LOCAL_SPACE_TAG) {\n return new Reference(dxn.parts[1]);\n } else {\n return new Reference(dxn.parts[1], undefined, dxn.parts[0]);\n }\n default:\n throw new Error(`Unsupported DXN kind: ${dxn.kind}`);\n }\n }\n\n // prettier-ignore\n constructor(\n public readonly objectId: ObjectId,\n public readonly protocol?: string,\n public readonly host?: string\n ) {}\n\n encode(): ReferenceProto {\n return { objectId: this.objectId, host: this.host, protocol: this.protocol };\n }\n\n toDXN(): DXN {\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\nexport const convertLegacyReference = async (reference: LegacyEncodedReferenceObject): Promise<EncodedReference> => {\n if (reference.protocol === Reference.TYPE_PROTOCOL) {\n return encodeReference(Reference.fromLegacyTypename(reference.itemId));\n }\n if (!reference.itemId) {\n throw new Error('Invalid reference');\n }\n\n const spaceKey = reference.host;\n const spaceId = spaceKey != null ? await createIdFromSpaceKey(PublicKey.fromHex(spaceKey)) : undefined;\n return encodeReference(new Reference(reference.itemId, reference.protocol ?? undefined, spaceId));\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", "//\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\nexport const LEGACY_REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';\n\n/**\n * Reference as it is stored in Automerge document.\n */\nexport type LegacyEncodedReferenceObject = {\n '@type': typeof LEGACY_REFERENCE_TYPE_TAG;\n itemId: string;\n protocol?: string;\n host?: string;\n};\n\nexport const isLegacyReference = (value: any): boolean =>\n typeof value === 'object' && value !== null && value['@type'] === LEGACY_REFERENCE_TYPE_TAG;\n\nexport const LEGACY_TYPE_PROPERTIES = 'dxos.sdk.client.Properties';\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kBAAgD;ACAhD,oBAA6B;AAC7B,IAAAA,eAAmC;AACnC,kBAA2B;AAE3B,IAAMC,kBAAkB,IAAIC,uBAA+BC,uBAAUC,IAAI;AAMlE,IAAMC,uBAAuB,OAAOC,aAAAA;AACzC,QAAMC,cAAcN,gBAAgBO,IAAIF,QAAAA;AACxC,MAAIC,gBAAgBE,QAAW;AAC7B,WAAOF;EACT;AAEA,QAAMG,SAAS,MAAMC,2BAAaD,OAAO,WAAWJ,SAASM,aAAY,CAAA;AAEzE,QAAMC,QAAQ,I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", "spaceKey", "cachedValue", "get", "undefined", "digest", "subtleCrypto", "asUint8Array", "bytes", "Uint8Array", "slice", "SpaceId", "byteLength", "spaceId", "encode", "set", "Reference", "TYPE_PROTOCOL", "fromValue", "value", "objectId", "protocol", "host", "fromLegacyTypename", "type", "fromDXN", "dxn", "kind", "DXN", "TYPE", "parts", "ECHO", "LOCAL_SPACE_TAG", "Error", "constructor", "toDXN", "REFERENCE_TYPE_TAG", "encodeReference", "reference", "toString", "decodeReference", "parse", "isEncodedReference", "Object", "keys", "length", "convertLegacyReference", "itemId", "fromHex", "SpaceDocVersion", "freeze", "LEGACY", "CURRENT", "LEGACY_REFERENCE_TYPE_TAG", "isLegacyReference", "LEGACY_TYPE_PROPERTIES"]
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 } 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 object reference.\n */\nexport class Reference {\n /**\n * Protocol references to runtime registered types.\n */\n static TYPE_PROTOCOL = 'protobuf';\n\n static fromDXN(dxn: DXN): Reference {\n switch (dxn.kind) {\n case DXN.kind.TYPE:\n return Reference.fromLegacyTypename(dxn.parts[0]);\n case DXN.kind.ECHO:\n if (dxn.parts[0] === LOCAL_SPACE_TAG) {\n return new Reference(dxn.parts[1]);\n } else {\n return new Reference(dxn.parts[1], undefined, dxn.parts[0]);\n }\n default:\n throw new Error(`Unsupported DXN kind: ${dxn.kind}`);\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(burdon): Document/remove?\n static fromLegacyTypename(type: string): Reference {\n return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');\n }\n\n // prettier-ignore\n constructor(\n public readonly objectId: ObjectId,\n public readonly protocol?: string,\n public readonly host?: string\n ) {}\n\n encode(): ReferenceProto {\n return { objectId: this.objectId, host: this.host, protocol: this.protocol };\n }\n\n toDXN(): DXN {\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,kBAAqC;AEArC,oBAA6B;AAC7B,IAAAA,eAAmC;AACnC,kBAA2B;AFKpB,IAAMC,YAAN,MAAMA,WAAAA;EAIX,OAAA;SAAOC,gBAAgB;;EAEvB,OAAOC,QAAQC,KAAqB;AAClC,YAAQA,IAAIC,MAAI;MACd,KAAKC,gBAAID,KAAKE;AACZ,eAAON,WAAUO,mBAAmBJ,IAAIK,MAAM,CAAA,CAAE;MAClD,KAAKH,gBAAID,KAAKK;AACZ,YAAIN,IAAIK,MAAM,CAAA,MAAOE,6BAAiB;AACpC,iBAAO,IAAIV,WAAUG,IAAIK,MAAM,CAAA,CAAE;QACnC,OAAO;AACL,iBAAO,IAAIR,WAAUG,IAAIK,MAAM,CAAA,GAAIG,QAAWR,IAAIK,MAAM,CAAA,CAAE;QAC5D;MACF;AACE,cAAM,IAAII,MAAM,yBAAyBT,IAAIC,IAAI,EAAE;IACvD;EACF;EAEA,OAAOS,UAAUC,OAAkC;AACjD,WAAO,IAAId,WAAUc,MAAMC,UAAUD,MAAME,UAAUF,MAAMG,IAAI;EACjE;;;;EAKA,OAAOC,qBAAqBH,UAA+B;AACzD,WAAO,IAAIf,WAAUe,QAAAA;EACvB;;;;;EAMA,OAAOR,mBAAmBY,MAAyB;AACjD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,WAAWH,SAASK,aAAY,CAAA;AAEzE,QAAMC,QAAQ,IAAIC,WAAWJ,MAAAA,EAAQK,MAAM,GAAGC,qBAAQC,UAAU;AAChE,QAAMC,UAAUF,qBAAQ9B,OAAO2B,KAAAA;AAC/BX,kBAAgBiB,IAAIZ,UAAUW,OAAAA;AAC9B,SAAOA;AACT;",
6
+ "names": ["import_keys", "Reference", "TYPE_PROTOCOL", "fromDXN", "dxn", "kind", "DXN", "TYPE", "fromLegacyTypename", "parts", "ECHO", "LOCAL_SPACE_TAG", "undefined", "Error", "fromValue", "value", "objectId", "protocol", "host", "localObjectReference", "type", "constructor", "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", "spaceKey", "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":2608,"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/reference.ts":{"bytes":11612,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-protocol/src/space-id.ts","kind":"import-statement","original":"./space-id"}],"format":"esm"},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytes":1591,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/legacy.ts":{"bytes":1719,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/collection-sync.ts":{"bytes":550,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/index.ts":{"bytes":1017,"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/legacy.ts","kind":"import-statement","original":"./legacy"},{"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":8975},"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":["LEGACY_REFERENCE_TYPE_TAG","LEGACY_TYPE_PROPERTIES","REFERENCE_TYPE_TAG","Reference","SpaceDocVersion","convertLegacyReference","createIdFromSpaceKey","decodeReference","encodeReference","isEncodedReference","isLegacyReference"],"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":2495},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytesInOutput":604},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytesInOutput":179},"packages/core/echo/echo-protocol/src/legacy.ts":{"bytesInOutput":257}},"bytes":4094}}}
1
+ {"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":2628,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/reference.ts":{"bytes":9848,"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":7213},"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":2107},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytesInOutput":179},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytesInOutput":604}},"bytes":3242}}}
@@ -1,26 +1,7 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // packages/core/echo/echo-protocol/src/reference.ts
4
- import { DXN, LOCAL_SPACE_TAG, PublicKey as PublicKey2 } from "@dxos/keys";
5
-
6
- // packages/core/echo/echo-protocol/src/space-id.ts
7
- import { subtleCrypto } from "@dxos/crypto";
8
- import { PublicKey, SpaceId } from "@dxos/keys";
9
- import { ComplexMap } from "@dxos/util";
10
- var SPACE_IDS_CACHE = new ComplexMap(PublicKey.hash);
11
- var createIdFromSpaceKey = async (spaceKey) => {
12
- const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
13
- if (cachedValue !== void 0) {
14
- return cachedValue;
15
- }
16
- const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
17
- const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
18
- const spaceId = SpaceId.encode(bytes);
19
- SPACE_IDS_CACHE.set(spaceKey, spaceId);
20
- return spaceId;
21
- };
22
-
23
- // packages/core/echo/echo-protocol/src/reference.ts
4
+ import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
24
5
  var Reference = class _Reference {
25
6
  static {
26
7
  /**
@@ -28,16 +9,6 @@ var Reference = class _Reference {
28
9
  */
29
10
  this.TYPE_PROTOCOL = "protobuf";
30
11
  }
31
- static fromValue(value) {
32
- return new _Reference(value.objectId, value.protocol, value.host);
33
- }
34
- /**
35
- * @deprecated
36
- */
37
- // TODO(burdon): Document/remove?
38
- static fromLegacyTypename(type) {
39
- return new _Reference(type, _Reference.TYPE_PROTOCOL, "dxos.org");
40
- }
41
12
  static fromDXN(dxn) {
42
13
  switch (dxn.kind) {
43
14
  case DXN.kind.TYPE:
@@ -52,6 +23,22 @@ var Reference = class _Reference {
52
23
  throw new Error(`Unsupported DXN kind: ${dxn.kind}`);
53
24
  }
54
25
  }
26
+ static fromValue(value) {
27
+ return new _Reference(value.objectId, value.protocol, value.host);
28
+ }
29
+ /**
30
+ * Reference an object in the local space.
31
+ */
32
+ static localObjectReference(objectId) {
33
+ return new _Reference(objectId);
34
+ }
35
+ /**
36
+ * @deprecated
37
+ */
38
+ // TODO(burdon): Document/remove?
39
+ static fromLegacyTypename(type) {
40
+ return new _Reference(type, _Reference.TYPE_PROTOCOL, "dxos.org");
41
+ }
55
42
  // prettier-ignore
56
43
  constructor(objectId, protocol, host) {
57
44
  this.objectId = objectId;
@@ -91,17 +78,6 @@ var encodeReference = (reference) => ({
91
78
  });
92
79
  var decodeReference = (value) => Reference.fromDXN(DXN.parse(value["/"]));
93
80
  var isEncodedReference = (value) => typeof value === "object" && value !== null && Object.keys(value).length === 1 && typeof value["/"] === "string";
94
- var convertLegacyReference = async (reference) => {
95
- if (reference.protocol === Reference.TYPE_PROTOCOL) {
96
- return encodeReference(Reference.fromLegacyTypename(reference.itemId));
97
- }
98
- if (!reference.itemId) {
99
- throw new Error("Invalid reference");
100
- }
101
- const spaceKey = reference.host;
102
- const spaceId = spaceKey != null ? await createIdFromSpaceKey(PublicKey2.fromHex(spaceKey)) : void 0;
103
- return encodeReference(new Reference(reference.itemId, reference.protocol ?? void 0, spaceId));
104
- };
105
81
 
106
82
  // packages/core/echo/echo-protocol/src/space-doc-version.ts
107
83
  var SpaceDocVersion = Object.freeze({
@@ -115,21 +91,29 @@ var SpaceDocVersion = Object.freeze({
115
91
  CURRENT: 1
116
92
  });
117
93
 
118
- // packages/core/echo/echo-protocol/src/legacy.ts
119
- var LEGACY_REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
120
- var isLegacyReference = (value) => typeof value === "object" && value !== null && value["@type"] === LEGACY_REFERENCE_TYPE_TAG;
121
- var LEGACY_TYPE_PROPERTIES = "dxos.sdk.client.Properties";
94
+ // packages/core/echo/echo-protocol/src/space-id.ts
95
+ import { subtleCrypto } from "@dxos/crypto";
96
+ import { PublicKey, SpaceId } from "@dxos/keys";
97
+ import { ComplexMap } from "@dxos/util";
98
+ var SPACE_IDS_CACHE = new ComplexMap(PublicKey.hash);
99
+ var createIdFromSpaceKey = async (spaceKey) => {
100
+ const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
101
+ if (cachedValue !== void 0) {
102
+ return cachedValue;
103
+ }
104
+ const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
105
+ const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
106
+ const spaceId = SpaceId.encode(bytes);
107
+ SPACE_IDS_CACHE.set(spaceKey, spaceId);
108
+ return spaceId;
109
+ };
122
110
  export {
123
- LEGACY_REFERENCE_TYPE_TAG,
124
- LEGACY_TYPE_PROPERTIES,
125
111
  REFERENCE_TYPE_TAG,
126
112
  Reference,
127
113
  SpaceDocVersion,
128
- convertLegacyReference,
129
114
  createIdFromSpaceKey,
130
115
  decodeReference,
131
116
  encodeReference,
132
- isEncodedReference,
133
- isLegacyReference
117
+ isEncodedReference
134
118
  };
135
119
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/reference.ts", "../../../src/space-id.ts", "../../../src/space-doc-version.ts", "../../../src/legacy.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { DXN, LOCAL_SPACE_TAG, PublicKey } from '@dxos/keys';\nimport { type ObjectId } from '@dxos/protocols';\nimport { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';\n\nimport type { LegacyEncodedReferenceObject } from './legacy';\nimport { createIdFromSpaceKey } from './space-id';\n\n/**\n * Runtime representation of object reference.\n */\nexport class Reference {\n /**\n * Protocol references to runtime registered types.\n */\n static TYPE_PROTOCOL = 'protobuf';\n\n static fromValue(value: ReferenceProto): Reference {\n return new Reference(value.objectId, value.protocol, value.host);\n }\n\n /**\n * @deprecated\n */\n // TODO(burdon): Document/remove?\n static fromLegacyTypename(type: string): Reference {\n return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');\n }\n\n static fromDXN(dxn: DXN): Reference {\n switch (dxn.kind) {\n case DXN.kind.TYPE:\n return Reference.fromLegacyTypename(dxn.parts[0]);\n case DXN.kind.ECHO:\n if (dxn.parts[0] === LOCAL_SPACE_TAG) {\n return new Reference(dxn.parts[1]);\n } else {\n return new Reference(dxn.parts[1], undefined, dxn.parts[0]);\n }\n default:\n throw new Error(`Unsupported DXN kind: ${dxn.kind}`);\n }\n }\n\n // prettier-ignore\n constructor(\n public readonly objectId: ObjectId,\n public readonly protocol?: string,\n public readonly host?: string\n ) {}\n\n encode(): ReferenceProto {\n return { objectId: this.objectId, host: this.host, protocol: this.protocol };\n }\n\n toDXN(): DXN {\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\nexport const convertLegacyReference = async (reference: LegacyEncodedReferenceObject): Promise<EncodedReference> => {\n if (reference.protocol === Reference.TYPE_PROTOCOL) {\n return encodeReference(Reference.fromLegacyTypename(reference.itemId));\n }\n if (!reference.itemId) {\n throw new Error('Invalid reference');\n }\n\n const spaceKey = reference.host;\n const spaceId = spaceKey != null ? await createIdFromSpaceKey(PublicKey.fromHex(spaceKey)) : undefined;\n return encodeReference(new Reference(reference.itemId, reference.protocol ?? undefined, spaceId));\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", "//\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\nexport const LEGACY_REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';\n\n/**\n * Reference as it is stored in Automerge document.\n */\nexport type LegacyEncodedReferenceObject = {\n '@type': typeof LEGACY_REFERENCE_TYPE_TAG;\n itemId: string;\n protocol?: string;\n host?: string;\n};\n\nexport const isLegacyReference = (value: any): boolean =>\n typeof value === 'object' && value !== null && value['@type'] === LEGACY_REFERENCE_TYPE_TAG;\n\nexport const LEGACY_TYPE_PROPERTIES = 'dxos.sdk.client.Properties';\n"],
5
- "mappings": ";;;AAI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,UAAUwB,UAAUS,QAAQT,UAAUnB,YAAYY,QAAWkB,OAAAA,CAAAA;AAC1F;;;AE9FO,IAAMI,kBAAkBC,OAAOC,OAAO;;;;EAI3CC,QAAQ;;;;EAKRC,SAAS;AACX,CAAA;;;ACfO,IAAMC,4BAA4B;AAYlC,IAAMC,oBAAoB,CAACC,UAChC,OAAOA,UAAU,YAAYA,UAAU,QAAQA,MAAM,OAAA,MAAaF;AAE7D,IAAMG,yBAAyB;",
6
- "names": ["DXN", "LOCAL_SPACE_TAG", "PublicKey", "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", "Reference", "TYPE_PROTOCOL", "fromValue", "value", "objectId", "protocol", "host", "fromLegacyTypename", "type", "fromDXN", "dxn", "kind", "DXN", "TYPE", "parts", "ECHO", "LOCAL_SPACE_TAG", "undefined", "Error", "constructor", "encode", "toDXN", "REFERENCE_TYPE_TAG", "encodeReference", "reference", "toString", "decodeReference", "parse", "isEncodedReference", "Object", "keys", "length", "convertLegacyReference", "itemId", "spaceKey", "spaceId", "createIdFromSpaceKey", "PublicKey", "fromHex", "SpaceDocVersion", "Object", "freeze", "LEGACY", "CURRENT", "LEGACY_REFERENCE_TYPE_TAG", "isLegacyReference", "value", "LEGACY_TYPE_PROPERTIES"]
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 } 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 object reference.\n */\nexport class Reference {\n /**\n * Protocol references to runtime registered types.\n */\n static TYPE_PROTOCOL = 'protobuf';\n\n static fromDXN(dxn: DXN): Reference {\n switch (dxn.kind) {\n case DXN.kind.TYPE:\n return Reference.fromLegacyTypename(dxn.parts[0]);\n case DXN.kind.ECHO:\n if (dxn.parts[0] === LOCAL_SPACE_TAG) {\n return new Reference(dxn.parts[1]);\n } else {\n return new Reference(dxn.parts[1], undefined, dxn.parts[0]);\n }\n default:\n throw new Error(`Unsupported DXN kind: ${dxn.kind}`);\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(burdon): Document/remove?\n static fromLegacyTypename(type: string): Reference {\n return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');\n }\n\n // prettier-ignore\n constructor(\n public readonly objectId: ObjectId,\n public readonly protocol?: string,\n public readonly host?: string\n ) {}\n\n encode(): ReferenceProto {\n return { objectId: this.objectId, host: this.host, protocol: this.protocol };\n }\n\n toDXN(): DXN {\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,uBAAuB;AAO9B,IAAMC,YAAN,MAAMA,WAAAA;EAIX;;;;SAAOC,gBAAgB;;EAEvB,OAAOC,QAAQC,KAAqB;AAClC,YAAQA,IAAIC,MAAI;MACd,KAAKC,IAAID,KAAKE;AACZ,eAAON,WAAUO,mBAAmBJ,IAAIK,MAAM,CAAA,CAAE;MAClD,KAAKH,IAAID,KAAKK;AACZ,YAAIN,IAAIK,MAAM,CAAA,MAAOE,iBAAiB;AACpC,iBAAO,IAAIV,WAA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AU,YAAYA,UAAU,QAAQgB,OAAOC,KAAKjB,KAAAA,EAAOkB,WAAW,KAAK,OAAOlB,MAAM,GAAA,MAAS;;;ACrFnG,IAAMmB,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", "fromLegacyTypename", "parts", "ECHO", "LOCAL_SPACE_TAG", "undefined", "Error", "fromValue", "value", "objectId", "protocol", "host", "localObjectReference", "type", "constructor", "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":2608,"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/reference.ts":{"bytes":11612,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-protocol/src/space-id.ts","kind":"import-statement","original":"./space-id"}],"format":"esm"},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytes":1591,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/legacy.ts":{"bytes":1719,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/collection-sync.ts":{"bytes":550,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/index.ts":{"bytes":1017,"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/legacy.ts","kind":"import-statement","original":"./legacy"},{"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":8977},"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":["LEGACY_REFERENCE_TYPE_TAG","LEGACY_TYPE_PROPERTIES","REFERENCE_TYPE_TAG","Reference","SpaceDocVersion","convertLegacyReference","createIdFromSpaceKey","decodeReference","encodeReference","isEncodedReference","isLegacyReference"],"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":2495},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytesInOutput":604},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytesInOutput":179},"packages/core/echo/echo-protocol/src/legacy.ts":{"bytesInOutput":257}},"bytes":4187}}}
1
+ {"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":2628,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/reference.ts":{"bytes":9848,"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":7215},"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":2107},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytesInOutput":179},"packages/core/echo/echo-protocol/src/space-id.ts":{"bytesInOutput":604}},"bytes":3335}}}
@@ -1,6 +1,6 @@
1
- import type { RawString } from './automerge';
1
+ import { type RawString } from './automerge';
2
2
  import { type EncodedReference } from './reference';
3
- import type { SpaceDocVersion } from './space-doc-version';
3
+ import { type SpaceDocVersion } from './space-doc-version';
4
4
  export type SpaceState = {
5
5
  rootUrl?: string;
6
6
  };
@@ -47,11 +47,11 @@ export type ForeignKey = {
47
47
  * Name of the foreign database/system.
48
48
  * E.g., `github.com`.
49
49
  */
50
- source?: string;
50
+ readonly source: string;
51
51
  /**
52
52
  * Id within the foreign database.
53
53
  */
54
- id?: string;
54
+ readonly id: string;
55
55
  };
56
56
  /**
57
57
  * Automerge object system properties.
@@ -1 +1 @@
1
- {"version":3,"file":"document-structure.d.ts","sourceRoot":"","sources":["../../../src/document-structure.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,MAAM,MAAM,UAAU,GAAG;IAEvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAGF,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,EAAE,eAAe,CAAC;IAE1B,MAAM,CAAC,EAAE;QACP,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF;;OAEG;IACH,OAAO,CAAC,EAAE;QACR,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,CAAC;KAC/B,CAAC;IACF;;OAEG;IACH,KAAK,CAAC,EAAE;QACN,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;KACtC,CAAC;CACH;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,YAAY,CAAC;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,IAAI,EAAE,UAAU,EAAE,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,IAAI,CAAC,EAAE,gBAAgB,CAAC;IAExB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC"}
1
+ {"version":3,"file":"document-structure.d.ts","sourceRoot":"","sources":["../../../src/document-structure.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,MAAM,MAAM,UAAU,GAAG;IAEvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAGF,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,EAAE,eAAe,CAAC;IAE1B,MAAM,CAAC,EAAE;QACP,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF;;OAEG;IACH,OAAO,CAAC,EAAE;QACR,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,CAAC;KAC/B,CAAC;IACF;;OAEG;IACH,KAAK,CAAC,EAAE;QACN,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;KACtC,CAAC;CACH;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,YAAY,CAAC;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,IAAI,EAAE,UAAU,EAAE,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,IAAI,CAAC,EAAE,gBAAgB,CAAC;IAExB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC"}
@@ -1,7 +1,6 @@
1
1
  export * from './document-structure';
2
2
  export * from './reference';
3
3
  export * from './space-doc-version';
4
- export * from './legacy';
5
4
  export * from './collection-sync';
6
5
  export * from './space-id';
7
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
@@ -1,7 +1,6 @@
1
1
  import { DXN } from '@dxos/keys';
2
2
  import { type ObjectId } from '@dxos/protocols';
3
3
  import { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';
4
- import type { LegacyEncodedReferenceObject } from './legacy';
5
4
  /**
6
5
  * Runtime representation of object reference.
7
6
  */
@@ -13,12 +12,16 @@ export declare class Reference {
13
12
  * Protocol references to runtime registered types.
14
13
  */
15
14
  static TYPE_PROTOCOL: string;
15
+ static fromDXN(dxn: DXN): Reference;
16
16
  static fromValue(value: ReferenceProto): Reference;
17
+ /**
18
+ * Reference an object in the local space.
19
+ */
20
+ static localObjectReference(objectId: ObjectId): Reference;
17
21
  /**
18
22
  * @deprecated
19
23
  */
20
24
  static fromLegacyTypename(type: string): Reference;
21
- static fromDXN(dxn: DXN): Reference;
22
25
  constructor(objectId: ObjectId, protocol?: string | undefined, host?: string | undefined);
23
26
  encode(): ReferenceProto;
24
27
  toDXN(): DXN;
@@ -33,5 +36,4 @@ export type EncodedReference = {
33
36
  export declare const encodeReference: (reference: Reference) => EncodedReference;
34
37
  export declare const decodeReference: (value: any) => Reference;
35
38
  export declare const isEncodedReference: (value: any) => value is EncodedReference;
36
- export declare const convertLegacyReference: (reference: LegacyEncodedReferenceObject) => Promise<EncodedReference>;
37
39
  //# sourceMappingURL=reference.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src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age": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -24,10 +24,10 @@
24
24
  "src"
25
25
  ],
26
26
  "dependencies": {
27
- "@dxos/keys": "0.7.2",
28
- "@dxos/protocols": "0.7.2",
29
- "@dxos/util": "0.7.2",
30
- "@dxos/crypto": "0.7.2"
27
+ "@dxos/crypto": "0.7.3-staging.971cd8d",
28
+ "@dxos/keys": "0.7.3-staging.971cd8d",
29
+ "@dxos/protocols": "0.7.3-staging.971cd8d",
30
+ "@dxos/util": "0.7.3-staging.971cd8d"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"
@@ -2,9 +2,9 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import type { RawString } from './automerge';
5
+ import { type RawString } from './automerge';
6
6
  import { type EncodedReference } from './reference';
7
- import type { SpaceDocVersion } from './space-doc-version';
7
+ import { type SpaceDocVersion } from './space-doc-version';
8
8
 
9
9
  export type SpaceState = {
10
10
  // Url of the root automerge document.
@@ -59,12 +59,12 @@ export type ForeignKey = {
59
59
  * Name of the foreign database/system.
60
60
  * E.g., `github.com`.
61
61
  */
62
- source?: string;
62
+ readonly source: string;
63
63
 
64
64
  /**
65
65
  * Id within the foreign database.
66
66
  */
67
- id?: string;
67
+ readonly id: string;
68
68
  };
69
69
 
70
70
  /**
package/src/index.ts CHANGED
@@ -5,6 +5,5 @@
5
5
  export * from './document-structure';
6
6
  export * from './reference';
7
7
  export * from './space-doc-version';
8
- export * from './legacy';
9
8
  export * from './collection-sync';
10
9
  export * from './space-id';
package/src/reference.ts CHANGED
@@ -2,13 +2,10 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { DXN, LOCAL_SPACE_TAG, PublicKey } from '@dxos/keys';
5
+ import { DXN, LOCAL_SPACE_TAG } from '@dxos/keys';
6
6
  import { type ObjectId } from '@dxos/protocols';
7
7
  import { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';
8
8
 
9
- import type { LegacyEncodedReferenceObject } from './legacy';
10
- import { createIdFromSpaceKey } from './space-id';
11
-
12
9
  /**
13
10
  * Runtime representation of object reference.
14
11
  */
@@ -18,18 +15,6 @@ export class Reference {
18
15
  */
19
16
  static TYPE_PROTOCOL = 'protobuf';
20
17
 
21
- static fromValue(value: ReferenceProto): Reference {
22
- return new Reference(value.objectId, value.protocol, value.host);
23
- }
24
-
25
- /**
26
- * @deprecated
27
- */
28
- // TODO(burdon): Document/remove?
29
- static fromLegacyTypename(type: string): Reference {
30
- return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');
31
- }
32
-
33
18
  static fromDXN(dxn: DXN): Reference {
34
19
  switch (dxn.kind) {
35
20
  case DXN.kind.TYPE:
@@ -45,6 +30,25 @@ export class Reference {
45
30
  }
46
31
  }
47
32
 
33
+ static fromValue(value: ReferenceProto): Reference {
34
+ return new Reference(value.objectId, value.protocol, value.host);
35
+ }
36
+
37
+ /**
38
+ * Reference an object in the local space.
39
+ */
40
+ static localObjectReference(objectId: ObjectId): Reference {
41
+ return new Reference(objectId);
42
+ }
43
+
44
+ /**
45
+ * @deprecated
46
+ */
47
+ // TODO(burdon): Document/remove?
48
+ static fromLegacyTypename(type: string): Reference {
49
+ return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');
50
+ }
51
+
48
52
  // prettier-ignore
49
53
  constructor(
50
54
  public readonly objectId: ObjectId,
@@ -89,16 +93,3 @@ export const decodeReference = (value: any) => Reference.fromDXN(DXN.parse(value
89
93
 
90
94
  export const isEncodedReference = (value: any): value is EncodedReference =>
91
95
  typeof value === 'object' && value !== null && Object.keys(value).length === 1 && typeof value['/'] === 'string';
92
-
93
- export const convertLegacyReference = async (reference: LegacyEncodedReferenceObject): Promise<EncodedReference> => {
94
- if (reference.protocol === Reference.TYPE_PROTOCOL) {
95
- return encodeReference(Reference.fromLegacyTypename(reference.itemId));
96
- }
97
- if (!reference.itemId) {
98
- throw new Error('Invalid reference');
99
- }
100
-
101
- const spaceKey = reference.host;
102
- const spaceId = spaceKey != null ? await createIdFromSpaceKey(PublicKey.fromHex(spaceKey)) : undefined;
103
- return encodeReference(new Reference(reference.itemId, reference.protocol ?? undefined, spaceId));
104
- };
@@ -1,13 +0,0 @@
1
- export declare const LEGACY_REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
2
- /**
3
- * Reference as it is stored in Automerge document.
4
- */
5
- export type LegacyEncodedReferenceObject = {
6
- '@type': typeof LEGACY_REFERENCE_TYPE_TAG;
7
- itemId: string;
8
- protocol?: string;
9
- host?: string;
10
- };
11
- export declare const isLegacyReference: (value: any) => boolean;
12
- export declare const LEGACY_TYPE_PROPERTIES = "dxos.sdk.client.Properties";
13
- //# sourceMappingURL=legacy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../../src/legacy.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,yBAAyB,uCAAuC,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,OAAO,EAAE,OAAO,yBAAyB,CAAC;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAW,GAAG,KAAG,OAC8C,CAAC;AAE9F,eAAO,MAAM,sBAAsB,+BAA+B,CAAC"}
package/src/legacy.ts DELETED
@@ -1,20 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- export const LEGACY_REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';
6
-
7
- /**
8
- * Reference as it is stored in Automerge document.
9
- */
10
- export type LegacyEncodedReferenceObject = {
11
- '@type': typeof LEGACY_REFERENCE_TYPE_TAG;
12
- itemId: string;
13
- protocol?: string;
14
- host?: string;
15
- };
16
-
17
- export const isLegacyReference = (value: any): boolean =>
18
- typeof value === 'object' && value !== null && value['@type'] === LEGACY_REFERENCE_TYPE_TAG;
19
-
20
- export const LEGACY_TYPE_PROPERTIES = 'dxos.sdk.client.Properties';