@dxos/echo-protocol 0.6.11-staging.e6894a4 → 0.6.12-main.5cc132e

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.
@@ -0,0 +1,101 @@
1
+ // packages/core/echo/echo-protocol/src/reference.ts
2
+ import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
3
+ var Reference = class _Reference {
4
+ static {
5
+ /**
6
+ * Protocol references to runtime registered types.
7
+ */
8
+ this.TYPE_PROTOCOL = "protobuf";
9
+ }
10
+ static fromValue(value) {
11
+ return new _Reference(value.objectId, value.protocol, value.host);
12
+ }
13
+ /**
14
+ * @deprecated
15
+ */
16
+ // TODO(burdon): Document/remove?
17
+ static fromLegacyTypename(type) {
18
+ return new _Reference(type, _Reference.TYPE_PROTOCOL, "dxos.org");
19
+ }
20
+ static fromDXN(dxn) {
21
+ switch (dxn.kind) {
22
+ case DXN.kind.TYPE:
23
+ return _Reference.fromLegacyTypename(dxn.parts[0]);
24
+ case DXN.kind.ECHO:
25
+ if (dxn.parts[0] === LOCAL_SPACE_TAG) {
26
+ return new _Reference(dxn.parts[1]);
27
+ } else {
28
+ return new _Reference(dxn.parts[1], void 0, dxn.parts[0]);
29
+ }
30
+ default:
31
+ throw new Error(`Unsupported DXN kind: ${dxn.kind}`);
32
+ }
33
+ }
34
+ // prettier-ignore
35
+ constructor(objectId, protocol, host) {
36
+ this.objectId = objectId;
37
+ this.protocol = protocol;
38
+ this.host = host;
39
+ }
40
+ encode() {
41
+ return {
42
+ objectId: this.objectId,
43
+ host: this.host,
44
+ protocol: this.protocol
45
+ };
46
+ }
47
+ toDXN() {
48
+ if (this.protocol === _Reference.TYPE_PROTOCOL) {
49
+ return new DXN(DXN.kind.TYPE, [
50
+ this.objectId
51
+ ]);
52
+ } else {
53
+ if (this.host) {
54
+ return new DXN(DXN.kind.ECHO, [
55
+ this.host,
56
+ this.objectId
57
+ ]);
58
+ } else {
59
+ return new DXN(DXN.kind.ECHO, [
60
+ LOCAL_SPACE_TAG,
61
+ this.objectId
62
+ ]);
63
+ }
64
+ }
65
+ }
66
+ };
67
+ var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
68
+ var encodeReference = (reference) => ({
69
+ "/": reference.toDXN().toString()
70
+ });
71
+ var decodeReference = (value) => Reference.fromDXN(DXN.parse(value["/"]));
72
+ var isEncodedReference = (value) => typeof value === "object" && value !== null && Object.keys(value).length === 1 && typeof value["/"] === "string";
73
+
74
+ // packages/core/echo/echo-protocol/src/space-doc-version.ts
75
+ var SpaceDocVersion = Object.freeze({
76
+ /**
77
+ * For the documents created before the versioning was introduced.
78
+ */
79
+ LEGACY: 0,
80
+ /**
81
+ * Current version.
82
+ */
83
+ CURRENT: 1
84
+ });
85
+
86
+ // packages/core/echo/echo-protocol/src/legacy.ts
87
+ var LEGACY_REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
88
+ var isLegacyReference = (value) => typeof value === "object" && value !== null && value["@type"] === LEGACY_REFERENCE_TYPE_TAG;
89
+ var LEGACY_TYPE_PROPERTIES = "dxos.sdk.client.Properties";
90
+ export {
91
+ LEGACY_REFERENCE_TYPE_TAG,
92
+ LEGACY_TYPE_PROPERTIES,
93
+ REFERENCE_TYPE_TAG,
94
+ Reference,
95
+ SpaceDocVersion,
96
+ decodeReference,
97
+ encodeReference,
98
+ isEncodedReference,
99
+ isLegacyReference
100
+ };
101
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/reference.ts", "../../../src/space-doc-version.ts", "../../../src/legacy.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 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", "//\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,SAASA,KAAKC,uBAAuB;AAO9B,IAAMC,YAAN,MAAMA,WAAAA;EAIX;;;;SAAOC,gBAAgB;;EAEvB,OAAOC,UAAUC,OAAkC;AACjD,WAAO,IAAIH,WAAUG,MAAMC,UAAUD,MAAME,UAAUF,MAAMG,IAAI;EACjE;;;;;EAMA,OAAOC,mBAAmBC,MAAyB;AACjD,WAAO,IAAIR,WAAUQ,MAAMR,WAAUC,eAAe,UAAA;EACtD;EAEA,OAAOQ,QAAQC,KAAqB;AAClC,YAAQA,IAAIC,MAAI;MACd,KAAKC,IAAID,KAAKE;AACZ,eAAOb,WAAUO,mBAAmBG,IAAII,MAAM,CAAA,CAAE;MAClD,KAAKF,IAAID,KAAKI;AACZ,YAAIL,IAAII,MAAM,CAAA,MAAOE,iBAAiB;AACpC,iBAAO,IAAIhB,WAAUU,IAAII,MAAM,CAAA,CAAE;QACnC,OAAO;AACL,iBAAO,IAAId,WAAUU,IAAII,MAAM,CAAA,GAAIG,QAAWP,IAAII,MAAM,CAAA,CAAE;QAC5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"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", "SpaceDocVersion", "Object", "freeze", "LEGACY", "CURRENT", "LEGACY_REFERENCE_TYPE_TAG", "isLegacyReference", "value", "LEGACY_TYPE_PROPERTIES"]
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":2528,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/reference.ts":{"bytes":9351,"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/legacy.ts":{"bytes":1719,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/index.ts":{"bytes":818,"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"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-protocol/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5988},"packages/core/echo/echo-protocol/dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true}],"exports":["LEGACY_REFERENCE_TYPE_TAG","LEGACY_TYPE_PROPERTIES","REFERENCE_TYPE_TAG","Reference","SpaceDocVersion","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":1969},"packages/core/echo/echo-protocol/src/space-doc-version.ts":{"bytesInOutput":179},"packages/core/echo/echo-protocol/src/legacy.ts":{"bytesInOutput":257}},"bytes":2807}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/echo-protocol",
3
- "version": "0.6.11-staging.e6894a4",
3
+ "version": "0.6.12-main.5cc132e",
4
4
  "description": "Core ECHO APIs.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -11,7 +11,8 @@
11
11
  ".": {
12
12
  "browser": "./dist/lib/browser/index.mjs",
13
13
  "node": {
14
- "default": "./dist/lib/node/index.cjs"
14
+ "require": "./dist/lib/node/index.cjs",
15
+ "default": "./dist/lib/node-esm/index.mjs"
15
16
  },
16
17
  "types": "./dist/types/src/index.d.ts"
17
18
  }
@@ -25,8 +26,8 @@
25
26
  "src"
26
27
  ],
27
28
  "dependencies": {
28
- "@dxos/keys": "0.6.11-staging.e6894a4",
29
- "@dxos/protocols": "0.6.11-staging.e6894a4"
29
+ "@dxos/keys": "0.6.12-main.5cc132e",
30
+ "@dxos/protocols": "0.6.12-main.5cc132e"
30
31
  },
31
32
  "publishConfig": {
32
33
  "access": "public"