@dxos/echo-protocol 0.5.1-main.1670c35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ MIT License
2
+ Copyright (c) 2022 DXOS
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @dxos/echo-protocol
2
+
3
+ ECHO database.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm i @dxos/echo-protocol
9
+ ```
10
+
11
+ ## DXOS Resources
12
+
13
+ - [Website](https://dxos.org)
14
+ - [Developer Documentation](https://docs.dxos.org)
15
+ - Talk to us on [Discord](https://discord.gg/eXVfryv3sW)
16
+
17
+ ## Contributions
18
+
19
+ Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
20
+
21
+ License: [MIT](./LICENSE) Copyright 2022 © DXOS
@@ -0,0 +1,44 @@
1
+ // packages/core/echo/echo-protocol/src/reference.ts
2
+ var Reference = class _Reference {
3
+ static fromValue(value) {
4
+ return new _Reference(value.itemId, value.protocol, value.host);
5
+ }
6
+ /**
7
+ * @deprecated
8
+ */
9
+ // TODO(burdon): Document/remove?
10
+ static fromLegacyTypename(type) {
11
+ return new _Reference(type, "protobuf", "dxos.org");
12
+ }
13
+ // prettier-ignore
14
+ constructor(itemId, protocol, host) {
15
+ this.itemId = itemId;
16
+ this.protocol = protocol;
17
+ this.host = host;
18
+ }
19
+ encode() {
20
+ return {
21
+ itemId: this.itemId,
22
+ host: this.host,
23
+ protocol: this.protocol
24
+ };
25
+ }
26
+ };
27
+ var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
28
+ var encodeReference = (reference) => ({
29
+ "@type": REFERENCE_TYPE_TAG,
30
+ // NOTE: Automerge do not support undefined values, so we need to use null instead.
31
+ itemId: reference.itemId ?? null,
32
+ protocol: reference.protocol ?? null,
33
+ host: reference.host ?? null
34
+ });
35
+ var decodeReference = (value) => new Reference(value.itemId, value.protocol ?? void 0, value.host ?? void 0);
36
+ var isEncodedReferenceObject = (value) => typeof value === "object" && value !== null && value["@type"] === REFERENCE_TYPE_TAG;
37
+ export {
38
+ REFERENCE_TYPE_TAG,
39
+ Reference,
40
+ decodeReference,
41
+ encodeReference,
42
+ isEncodedReferenceObject
43
+ };
44
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/reference.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { type ItemID } from '@dxos/protocols';\nimport { type Reference as ReferenceValue } from '@dxos/protocols/proto/dxos/echo/model/document';\n\n// TODO(burdon): Comment.\nexport class Reference {\n static fromValue(value: ReferenceValue): Reference {\n return new Reference(value.itemId, 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, 'protobuf', 'dxos.org');\n }\n\n // prettier-ignore\n constructor(\n public readonly itemId: ItemID,\n public readonly protocol?: string,\n public readonly host?: string\n ) {}\n\n encode(): ReferenceValue {\n return { itemId: this.itemId, host: this.host, protocol: this.protocol };\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 EncodedReferenceObject = {\n '@type': typeof REFERENCE_TYPE_TAG;\n itemId: string | null;\n protocol: string | null;\n host: string | null;\n};\n\nexport const encodeReference = (reference: Reference): EncodedReferenceObject => ({\n '@type': REFERENCE_TYPE_TAG,\n // NOTE: Automerge do not support undefined values, so we need to use null instead.\n itemId: reference.itemId ?? null,\n protocol: reference.protocol ?? null,\n host: reference.host ?? null,\n});\n\nexport const decodeReference = (value: any) =>\n new Reference(value.itemId, value.protocol ?? undefined, value.host ?? undefined);\n\nexport const isEncodedReferenceObject = (value: any): value is EncodedReferenceObject =>\n typeof value === 'object' && value !== null && value['@type'] === REFERENCE_TYPE_TAG;\n"],
5
+ "mappings": ";AAQO,IAAMA,YAAN,MAAMA,WAAAA;EACX,OAAOC,UAAUC,OAAkC;AACjD,WAAO,IAAIF,WAAUE,MAAMC,QAAQD,MAAME,UAAUF,MAAMG,IAAI;EAC/D;;;;;EAMA,OAAOC,mBAAmBC,MAAyB;AACjD,WAAO,IAAIP,WAAUO,MAAM,YAAY,UAAA;EACzC;;EAGAC,YACkBL,QACAC,UACAC,MAChB;SAHgBF,SAAAA;SACAC,WAAAA;SACAC,OAAAA;EACf;EAEHI,SAAyB;AACvB,WAAO;MAAEN,QAAQ,KAAKA;MAAQE,MAAM,KAAKA;MAAMD,UAAU,KAAKA;IAAS;EACzE;AACF;AAEO,IAAMM,qBAAqB;AAY3B,IAAMC,kBAAkB,CAACC,eAAkD;EAChF,SAASF;;EAETP,QAAQS,UAAUT,UAAU;EAC5BC,UAAUQ,UAAUR,YAAY;EAChCC,MAAMO,UAAUP,QAAQ;AAC1B;AAEO,IAAMQ,kBAAkB,CAACX,UAC9B,IAAIF,UAAUE,MAAMC,QAAQD,MAAME,YAAYU,QAAWZ,MAAMG,QAAQS,MAAAA;AAElE,IAAMC,2BAA2B,CAACb,UACvC,OAAOA,UAAU,YAAYA,UAAU,QAAQA,MAAM,OAAA,MAAaQ;",
6
+ "names": ["Reference", "fromValue", "value", "itemId", "protocol", "host", "fromLegacyTypename", "type", "constructor", "encode", "REFERENCE_TYPE_TAG", "encodeReference", "reference", "decodeReference", "undefined", "isEncodedReferenceObject"]
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":2324,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/reference.ts":{"bytes":5472,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/index.ts":{"bytes":591,"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"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-protocol/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":2790},"packages/core/echo/echo-protocol/dist/lib/browser/index.mjs":{"imports":[],"exports":["REFERENCE_TYPE_TAG","Reference","decodeReference","encodeReference","isEncodedReferenceObject"],"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":1128}},"bytes":1328}}}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var node_exports = {};
20
+ __export(node_exports, {
21
+ REFERENCE_TYPE_TAG: () => REFERENCE_TYPE_TAG,
22
+ Reference: () => Reference,
23
+ decodeReference: () => decodeReference,
24
+ encodeReference: () => encodeReference,
25
+ isEncodedReferenceObject: () => isEncodedReferenceObject
26
+ });
27
+ module.exports = __toCommonJS(node_exports);
28
+ var Reference = class _Reference {
29
+ static fromValue(value) {
30
+ return new _Reference(value.itemId, value.protocol, value.host);
31
+ }
32
+ /**
33
+ * @deprecated
34
+ */
35
+ // TODO(burdon): Document/remove?
36
+ static fromLegacyTypename(type) {
37
+ return new _Reference(type, "protobuf", "dxos.org");
38
+ }
39
+ // prettier-ignore
40
+ constructor(itemId, protocol, host) {
41
+ this.itemId = itemId;
42
+ this.protocol = protocol;
43
+ this.host = host;
44
+ }
45
+ encode() {
46
+ return {
47
+ itemId: this.itemId,
48
+ host: this.host,
49
+ protocol: this.protocol
50
+ };
51
+ }
52
+ };
53
+ var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
54
+ var encodeReference = (reference) => ({
55
+ "@type": REFERENCE_TYPE_TAG,
56
+ // NOTE: Automerge do not support undefined values, so we need to use null instead.
57
+ itemId: reference.itemId ?? null,
58
+ protocol: reference.protocol ?? null,
59
+ host: reference.host ?? null
60
+ });
61
+ var decodeReference = (value) => new Reference(value.itemId, value.protocol ?? void 0, value.host ?? void 0);
62
+ var isEncodedReferenceObject = (value) => typeof value === "object" && value !== null && value["@type"] === REFERENCE_TYPE_TAG;
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ REFERENCE_TYPE_TAG,
66
+ Reference,
67
+ decodeReference,
68
+ encodeReference,
69
+ isEncodedReferenceObject
70
+ });
71
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/reference.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { type ItemID } from '@dxos/protocols';\nimport { type Reference as ReferenceValue } from '@dxos/protocols/proto/dxos/echo/model/document';\n\n// TODO(burdon): Comment.\nexport class Reference {\n static fromValue(value: ReferenceValue): Reference {\n return new Reference(value.itemId, 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, 'protobuf', 'dxos.org');\n }\n\n // prettier-ignore\n constructor(\n public readonly itemId: ItemID,\n public readonly protocol?: string,\n public readonly host?: string\n ) {}\n\n encode(): ReferenceValue {\n return { itemId: this.itemId, host: this.host, protocol: this.protocol };\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 EncodedReferenceObject = {\n '@type': typeof REFERENCE_TYPE_TAG;\n itemId: string | null;\n protocol: string | null;\n host: string | null;\n};\n\nexport const encodeReference = (reference: Reference): EncodedReferenceObject => ({\n '@type': REFERENCE_TYPE_TAG,\n // NOTE: Automerge do not support undefined values, so we need to use null instead.\n itemId: reference.itemId ?? null,\n protocol: reference.protocol ?? null,\n host: reference.host ?? null,\n});\n\nexport const decodeReference = (value: any) =>\n new Reference(value.itemId, value.protocol ?? undefined, value.host ?? undefined);\n\nexport const isEncodedReferenceObject = (value: any): value is EncodedReferenceObject =>\n typeof value === 'object' && value !== null && value['@type'] === REFERENCE_TYPE_TAG;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAQO,IAAMA,YAAN,MAAMA,WAAAA;EACX,OAAOC,UAAUC,OAAkC;AACjD,WAAO,IAAIF,WAAUE,MAAMC,QAAQD,MAAME,UAAUF,MAAMG,IAAI;EAC/D;;;;;EAMA,OAAOC,mBAAmBC,MAAyB;AACjD,WAAO,IAAIP,WAAUO,MAAM,YAAY,UAAA;EACzC;;EAGAC,YACkBL,QACAC,UACAC,MAChB;SAHgBF,SAAAA;SACAC,WAAAA;SACAC,OAAAA;EACf;EAEHI,SAAyB;AACvB,WAAO;MAAEN,QAAQ,KAAKA;MAAQE,MAAM,KAAKA;MAAMD,UAAU,KAAKA;IAAS;EACzE;AACF;AAEO,IAAMM,qBAAqB;AAY3B,IAAMC,kBAAkB,CAACC,eAAkD;EAChF,SAASF;;EAETP,QAAQS,UAAUT,UAAU;EAC5BC,UAAUQ,UAAUR,YAAY;EAChCC,MAAMO,UAAUP,QAAQ;AAC1B;AAEO,IAAMQ,kBAAkB,CAACX,UAC9B,IAAIF,UAAUE,MAAMC,QAAQD,MAAME,YAAYU,QAAWZ,MAAMG,QAAQS,MAAAA;AAElE,IAAMC,2BAA2B,CAACb,UACvC,OAAOA,UAAU,YAAYA,UAAU,QAAQA,MAAM,OAAA,MAAaQ;",
6
+ "names": ["Reference", "fromValue", "value", "itemId", "protocol", "host", "fromLegacyTypename", "type", "constructor", "encode", "REFERENCE_TYPE_TAG", "encodeReference", "reference", "decodeReference", "undefined", "isEncodedReferenceObject"]
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":2324,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/reference.ts":{"bytes":5472,"imports":[],"format":"esm"},"packages/core/echo/echo-protocol/src/index.ts":{"bytes":591,"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"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-protocol/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":2790},"packages/core/echo/echo-protocol/dist/lib/node/index.cjs":{"imports":[],"exports":["REFERENCE_TYPE_TAG","Reference","decodeReference","encodeReference","isEncodedReferenceObject"],"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":1128}},"bytes":1328}}}
@@ -0,0 +1,67 @@
1
+ import { type EncodedReferenceObject } from './reference';
2
+ export type SpaceState = {
3
+ rootUrl?: string;
4
+ };
5
+ export interface SpaceDoc {
6
+ access?: {
7
+ spaceKey: string;
8
+ };
9
+ /**
10
+ * Objects inlined in the current document.
11
+ */
12
+ objects?: {
13
+ [key: string]: ObjectStructure;
14
+ };
15
+ /**
16
+ * Object id points to an automerge doc url where the object is embedded.
17
+ */
18
+ links?: {
19
+ [echoId: string]: string;
20
+ };
21
+ }
22
+ /**
23
+ * Representation of an ECHO object in an AM document.
24
+ */
25
+ export type ObjectStructure = {
26
+ data: Record<string, any>;
27
+ meta: ObjectMeta;
28
+ system: ObjectSystem;
29
+ };
30
+ /**
31
+ * Echo object metadata.
32
+ */
33
+ export type ObjectMeta = {
34
+ /**
35
+ * Foreign keys.
36
+ */
37
+ keys: ForeignKey[];
38
+ };
39
+ /**
40
+ * Reference to an object in a foreign database.
41
+ */
42
+ export type ForeignKey = {
43
+ /**
44
+ * Name of the foreign database/system.
45
+ * E.g. `github.com`.
46
+ */
47
+ source?: string;
48
+ /**
49
+ * Id within the foreign database.
50
+ */
51
+ id?: string;
52
+ };
53
+ /**
54
+ * Automerge object system properties.
55
+ * (Is automerge specific.)
56
+ */
57
+ export type ObjectSystem = {
58
+ /**
59
+ * Deletion marker.
60
+ */
61
+ deleted?: boolean;
62
+ /**
63
+ * Object reference ('protobuf' protocol) type.
64
+ */
65
+ type?: EncodedReferenceObject;
66
+ };
67
+ //# sourceMappingURL=document-structure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-structure.d.ts","sourceRoot":"","sources":["../../../src/document-structure.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,MAAM,UAAU,GAAG;IAEvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,EAAE;QACP,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF;;OAEG;IACH,OAAO,CAAC,EAAE;QACR,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC;KAChC,CAAC;IACF;;OAEG;IACH,KAAK,CAAC,EAAE;QACN,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;KAC1B,CAAC;CACH;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,YAAY,CAAC;CACtB,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,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,IAAI,CAAC,EAAE,sBAAsB,CAAC;CAC/B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './document-structure';
2
+ export * from './reference';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { type ItemID } from '@dxos/protocols';
2
+ import { type Reference as ReferenceValue } from '@dxos/protocols/proto/dxos/echo/model/document';
3
+ export declare class Reference {
4
+ readonly itemId: ItemID;
5
+ readonly protocol?: string | undefined;
6
+ readonly host?: string | undefined;
7
+ static fromValue(value: ReferenceValue): Reference;
8
+ /**
9
+ * @deprecated
10
+ */
11
+ static fromLegacyTypename(type: string): Reference;
12
+ constructor(itemId: ItemID, protocol?: string | undefined, host?: string | undefined);
13
+ encode(): ReferenceValue;
14
+ }
15
+ export declare const REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
16
+ /**
17
+ * Reference as it is stored in Automerge document.
18
+ */
19
+ export type EncodedReferenceObject = {
20
+ '@type': typeof REFERENCE_TYPE_TAG;
21
+ itemId: string | null;
22
+ protocol: string | null;
23
+ host: string | null;
24
+ };
25
+ export declare const encodeReference: (reference: Reference) => EncodedReferenceObject;
26
+ export declare const decodeReference: (value: any) => Reference;
27
+ export declare const isEncodedReferenceObject: (value: any) => value is EncodedReferenceObject;
28
+ //# sourceMappingURL=reference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/reference.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,KAAK,SAAS,IAAI,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAGlG,qBAAa,SAAS;aAeF,MAAM,EAAE,MAAM;aACd,QAAQ,CAAC;aACT,IAAI,CAAC;IAhBvB,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS;IAIlD;;OAEG;IAEH,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;gBAMhC,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,oBAAQ,EACjB,IAAI,CAAC,oBAAQ;IAG/B,MAAM,IAAI,cAAc;CAGzB;AAED,eAAO,MAAM,kBAAkB,uCAAuC,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,OAAO,kBAAkB,CAAC;IACnC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,SAAS,KAAG,sBAMrD,CAAC;AAEH,eAAO,MAAM,eAAe,UAAW,GAAG,cACyC,CAAC;AAEpF,eAAO,MAAM,wBAAwB,UAAW,GAAG,oCACmC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@dxos/echo-protocol",
3
+ "version": "0.5.1-main.1670c35",
4
+ "description": "Core ECHO APIs.",
5
+ "homepage": "https://dxos.org",
6
+ "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": "github:dxos/dxos",
8
+ "license": "MIT",
9
+ "author": "DXOS.org",
10
+ "exports": {
11
+ ".": {
12
+ "browser": "./dist/lib/browser/index.mjs",
13
+ "import": "./dist/lib/browser/index.mjs",
14
+ "require": "./dist/lib/node/index.cjs",
15
+ "node": "./dist/lib/node/index.cjs"
16
+ }
17
+ },
18
+ "main": "dist/lib/node/index.cjs",
19
+ "types": "dist/types/src/index.d.ts",
20
+ "files": [
21
+ "dist",
22
+ "src"
23
+ ],
24
+ "dependencies": {
25
+ "@dxos/protocols": "0.5.1-main.1670c35"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ }
30
+ }
@@ -0,0 +1,79 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type EncodedReferenceObject } from './reference';
6
+
7
+ export type SpaceState = {
8
+ // Url of the root automerge document.
9
+ rootUrl?: string;
10
+ };
11
+
12
+ export interface SpaceDoc {
13
+ access?: {
14
+ spaceKey: string;
15
+ };
16
+ /**
17
+ * Objects inlined in the current document.
18
+ */
19
+ objects?: {
20
+ [key: string]: ObjectStructure;
21
+ };
22
+ /**
23
+ * Object id points to an automerge doc url where the object is embedded.
24
+ */
25
+ links?: {
26
+ [echoId: string]: string;
27
+ };
28
+ }
29
+
30
+ /**
31
+ * Representation of an ECHO object in an AM document.
32
+ */
33
+ export type ObjectStructure = {
34
+ data: Record<string, any>;
35
+ meta: ObjectMeta;
36
+ system: ObjectSystem;
37
+ };
38
+
39
+ /**
40
+ * Echo object metadata.
41
+ */
42
+ export type ObjectMeta = {
43
+ /**
44
+ * Foreign keys.
45
+ */
46
+ keys: ForeignKey[];
47
+ };
48
+
49
+ /**
50
+ * Reference to an object in a foreign database.
51
+ */
52
+ export type ForeignKey = {
53
+ /**
54
+ * Name of the foreign database/system.
55
+ * E.g. `github.com`.
56
+ */
57
+ source?: string;
58
+
59
+ /**
60
+ * Id within the foreign database.
61
+ */
62
+ id?: string;
63
+ };
64
+
65
+ /**
66
+ * Automerge object system properties.
67
+ * (Is automerge specific.)
68
+ */
69
+ export type ObjectSystem = {
70
+ /**
71
+ * Deletion marker.
72
+ */
73
+ deleted?: boolean;
74
+
75
+ /**
76
+ * Object reference ('protobuf' protocol) type.
77
+ */
78
+ type?: EncodedReferenceObject;
79
+ };
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './document-structure';
6
+ export * from './reference';
@@ -0,0 +1,58 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import { type ItemID } from '@dxos/protocols';
6
+ import { type Reference as ReferenceValue } from '@dxos/protocols/proto/dxos/echo/model/document';
7
+
8
+ // TODO(burdon): Comment.
9
+ export class Reference {
10
+ static fromValue(value: ReferenceValue): Reference {
11
+ return new Reference(value.itemId, value.protocol, value.host);
12
+ }
13
+
14
+ /**
15
+ * @deprecated
16
+ */
17
+ // TODO(burdon): Document/remove?
18
+ static fromLegacyTypename(type: string): Reference {
19
+ return new Reference(type, 'protobuf', 'dxos.org');
20
+ }
21
+
22
+ // prettier-ignore
23
+ constructor(
24
+ public readonly itemId: ItemID,
25
+ public readonly protocol?: string,
26
+ public readonly host?: string
27
+ ) {}
28
+
29
+ encode(): ReferenceValue {
30
+ return { itemId: this.itemId, host: this.host, protocol: this.protocol };
31
+ }
32
+ }
33
+
34
+ export const REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';
35
+
36
+ /**
37
+ * Reference as it is stored in Automerge document.
38
+ */
39
+ export type EncodedReferenceObject = {
40
+ '@type': typeof REFERENCE_TYPE_TAG;
41
+ itemId: string | null;
42
+ protocol: string | null;
43
+ host: string | null;
44
+ };
45
+
46
+ export const encodeReference = (reference: Reference): EncodedReferenceObject => ({
47
+ '@type': REFERENCE_TYPE_TAG,
48
+ // NOTE: Automerge do not support undefined values, so we need to use null instead.
49
+ itemId: reference.itemId ?? null,
50
+ protocol: reference.protocol ?? null,
51
+ host: reference.host ?? null,
52
+ });
53
+
54
+ export const decodeReference = (value: any) =>
55
+ new Reference(value.itemId, value.protocol ?? undefined, value.host ?? undefined);
56
+
57
+ export const isEncodedReferenceObject = (value: any): value is EncodedReferenceObject =>
58
+ typeof value === 'object' && value !== null && value['@type'] === REFERENCE_TYPE_TAG;