@dxos/echo-protocol 0.5.9-main.bfee100 → 0.5.9-main.c2c4258
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/dist/lib/browser/index.mjs +70 -13
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +68 -14
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/document-structure.d.ts +4 -2
- package/dist/types/src/document-structure.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/legacy.d.ts +13 -0
- package/dist/types/src/legacy.d.ts.map +1 -0
- package/dist/types/src/reference.d.ts +20 -13
- package/dist/types/src/reference.d.ts.map +1 -1
- package/dist/types/src/space-doc-version.d.ts +17 -0
- package/dist/types/src/space-doc-version.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/document-structure.ts +5 -2
- package/src/index.ts +2 -0
- package/src/legacy.ts +20 -0
- package/src/reference.ts +54 -25
- package/src/space-doc-version.ts +20 -0
|
@@ -1,44 +1,101 @@
|
|
|
1
1
|
// packages/core/echo/echo-protocol/src/reference.ts
|
|
2
|
+
import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
|
|
2
3
|
var Reference = class _Reference {
|
|
4
|
+
static {
|
|
5
|
+
/**
|
|
6
|
+
* Protocol references to runtime registered types.
|
|
7
|
+
*/
|
|
8
|
+
this.TYPE_PROTOCOL = "protobuf";
|
|
9
|
+
}
|
|
3
10
|
static fromValue(value) {
|
|
4
|
-
return new _Reference(value.
|
|
11
|
+
return new _Reference(value.objectId, value.protocol, value.host);
|
|
5
12
|
}
|
|
6
13
|
/**
|
|
7
14
|
* @deprecated
|
|
8
15
|
*/
|
|
9
16
|
// TODO(burdon): Document/remove?
|
|
10
17
|
static fromLegacyTypename(type) {
|
|
11
|
-
return new _Reference(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
|
+
}
|
|
12
33
|
}
|
|
13
34
|
// prettier-ignore
|
|
14
|
-
constructor(
|
|
15
|
-
this.
|
|
35
|
+
constructor(objectId, protocol, host) {
|
|
36
|
+
this.objectId = objectId;
|
|
16
37
|
this.protocol = protocol;
|
|
17
38
|
this.host = host;
|
|
18
39
|
}
|
|
19
40
|
encode() {
|
|
20
41
|
return {
|
|
21
|
-
|
|
42
|
+
objectId: this.objectId,
|
|
22
43
|
host: this.host,
|
|
23
44
|
protocol: this.protocol
|
|
24
45
|
};
|
|
25
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
|
+
}
|
|
26
66
|
};
|
|
27
67
|
var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
|
|
28
68
|
var encodeReference = (reference) => ({
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
34
84
|
});
|
|
35
|
-
|
|
36
|
-
|
|
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";
|
|
37
90
|
export {
|
|
91
|
+
LEGACY_REFERENCE_TYPE_TAG,
|
|
92
|
+
LEGACY_TYPE_PROPERTIES,
|
|
38
93
|
REFERENCE_TYPE_TAG,
|
|
39
94
|
Reference,
|
|
95
|
+
SpaceDocVersion,
|
|
40
96
|
decodeReference,
|
|
41
97
|
encodeReference,
|
|
42
|
-
|
|
98
|
+
isEncodedReference,
|
|
99
|
+
isLegacyReference
|
|
43
100
|
};
|
|
44
101
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/reference.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { type
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": ["Reference", "fromValue", "value", "
|
|
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;QAC5D;MACF;AACE,cAAM,IAAII,MAAM,yBAAyBR,IAAIC,IAAI,EAAE;IACvD;EACF;;EAGAQ,YACkBf,UACAC,UACAC,MAChB;SAHgBF,WAAAA;SACAC,WAAAA;SACAC,OAAAA;EACf;EAEHc,SAAyB;AACvB,WAAO;MAAEhB,UAAU,KAAKA;MAAUE,MAAM,KAAKA;MAAMD,UAAU,KAAKA;IAAS;EAC7E;EAEAgB,QAAa;AACX,QAAI,KAAKhB,aAAaL,WAAUC,eAAe;AAC7C,aAAO,IAAIW,IAAIA,IAAID,KAAKE,MAAM;QAAC,KAAKT;OAAS;IAC/C,OAAO;AACL,UAAI,KAAKE,MAAM;AAIb,eAAO,IAAIM,IAAIA,IAAID,KAAKI,MAAM;UAAC,KAAKT;UAAM,KAAKF;SAAS;MAC1D,OAAO;AACL,eAAO,IAAIQ,IAAIA,IAAID,KAAKI,MAAM;UAACC;UAAiB,KAAKZ;SAAS;MAChE;IACF;EACF;AACF;AAEO,IAAMkB,qBAAqB;AAS3B,IAAMC,kBAAkB,CAACC,eAA4C;EAC1E,KAAKA,UAAUH,MAAK,EAAGI,SAAQ;AACjC;AAEO,IAAMC,kBAAkB,CAACvB,UAAeH,UAAUS,QAAQG,IAAIe,MAAMxB,MAAM,GAAA,CAAI,CAAA;AAE9E,IAAMyB,qBAAqB,CAACzB,UACjC,OAAOA,UAAU,YAAYA,UAAU,QAAQ0B,OAAOC,KAAK3B,KAAAA,EAAO4B,WAAW,KAAK,OAAO5B,MAAM,GAAA,MAAS;;;AC9EnG,IAAM6B,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", "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", "SpaceDocVersion", "Object", "freeze", "LEGACY", "CURRENT", "LEGACY_REFERENCE_TYPE_TAG", "isLegacyReference", "value", "LEGACY_TYPE_PROPERTIES"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":
|
|
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/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5988},"packages/core/echo/echo-protocol/dist/lib/browser/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/dist/lib/node/index.cjs
CHANGED
|
@@ -18,54 +18,108 @@ 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,
|
|
21
23
|
REFERENCE_TYPE_TAG: () => REFERENCE_TYPE_TAG,
|
|
22
24
|
Reference: () => Reference,
|
|
25
|
+
SpaceDocVersion: () => SpaceDocVersion,
|
|
23
26
|
decodeReference: () => decodeReference,
|
|
24
27
|
encodeReference: () => encodeReference,
|
|
25
|
-
|
|
28
|
+
isEncodedReference: () => isEncodedReference,
|
|
29
|
+
isLegacyReference: () => isLegacyReference
|
|
26
30
|
});
|
|
27
31
|
module.exports = __toCommonJS(node_exports);
|
|
32
|
+
var import_keys = require("@dxos/keys");
|
|
28
33
|
var Reference = class _Reference {
|
|
34
|
+
static {
|
|
35
|
+
this.TYPE_PROTOCOL = "protobuf";
|
|
36
|
+
}
|
|
29
37
|
static fromValue(value) {
|
|
30
|
-
return new _Reference(value.
|
|
38
|
+
return new _Reference(value.objectId, value.protocol, value.host);
|
|
31
39
|
}
|
|
32
40
|
/**
|
|
33
41
|
* @deprecated
|
|
34
42
|
*/
|
|
35
43
|
// TODO(burdon): Document/remove?
|
|
36
44
|
static fromLegacyTypename(type) {
|
|
37
|
-
return new _Reference(type,
|
|
45
|
+
return new _Reference(type, _Reference.TYPE_PROTOCOL, "dxos.org");
|
|
46
|
+
}
|
|
47
|
+
static fromDXN(dxn) {
|
|
48
|
+
switch (dxn.kind) {
|
|
49
|
+
case import_keys.DXN.kind.TYPE:
|
|
50
|
+
return _Reference.fromLegacyTypename(dxn.parts[0]);
|
|
51
|
+
case import_keys.DXN.kind.ECHO:
|
|
52
|
+
if (dxn.parts[0] === import_keys.LOCAL_SPACE_TAG) {
|
|
53
|
+
return new _Reference(dxn.parts[1]);
|
|
54
|
+
} else {
|
|
55
|
+
return new _Reference(dxn.parts[1], void 0, dxn.parts[0]);
|
|
56
|
+
}
|
|
57
|
+
default:
|
|
58
|
+
throw new Error(`Unsupported DXN kind: ${dxn.kind}`);
|
|
59
|
+
}
|
|
38
60
|
}
|
|
39
61
|
// prettier-ignore
|
|
40
|
-
constructor(
|
|
41
|
-
this.
|
|
62
|
+
constructor(objectId, protocol, host) {
|
|
63
|
+
this.objectId = objectId;
|
|
42
64
|
this.protocol = protocol;
|
|
43
65
|
this.host = host;
|
|
44
66
|
}
|
|
45
67
|
encode() {
|
|
46
68
|
return {
|
|
47
|
-
|
|
69
|
+
objectId: this.objectId,
|
|
48
70
|
host: this.host,
|
|
49
71
|
protocol: this.protocol
|
|
50
72
|
};
|
|
51
73
|
}
|
|
74
|
+
toDXN() {
|
|
75
|
+
if (this.protocol === _Reference.TYPE_PROTOCOL) {
|
|
76
|
+
return new import_keys.DXN(import_keys.DXN.kind.TYPE, [
|
|
77
|
+
this.objectId
|
|
78
|
+
]);
|
|
79
|
+
} else {
|
|
80
|
+
if (this.host) {
|
|
81
|
+
return new import_keys.DXN(import_keys.DXN.kind.ECHO, [
|
|
82
|
+
this.host,
|
|
83
|
+
this.objectId
|
|
84
|
+
]);
|
|
85
|
+
} else {
|
|
86
|
+
return new import_keys.DXN(import_keys.DXN.kind.ECHO, [
|
|
87
|
+
import_keys.LOCAL_SPACE_TAG,
|
|
88
|
+
this.objectId
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
52
93
|
};
|
|
53
94
|
var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
|
|
54
95
|
var encodeReference = (reference) => ({
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
96
|
+
"/": reference.toDXN().toString()
|
|
97
|
+
});
|
|
98
|
+
var decodeReference = (value) => Reference.fromDXN(import_keys.DXN.parse(value["/"]));
|
|
99
|
+
var isEncodedReference = (value) => typeof value === "object" && value !== null && Object.keys(value).length === 1 && typeof value["/"] === "string";
|
|
100
|
+
var SpaceDocVersion = Object.freeze({
|
|
101
|
+
/**
|
|
102
|
+
* For the documents created before the versioning was introduced.
|
|
103
|
+
*/
|
|
104
|
+
LEGACY: 0,
|
|
105
|
+
/**
|
|
106
|
+
* Current version.
|
|
107
|
+
*/
|
|
108
|
+
CURRENT: 1
|
|
60
109
|
});
|
|
61
|
-
var
|
|
62
|
-
var
|
|
110
|
+
var LEGACY_REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
|
|
111
|
+
var isLegacyReference = (value) => typeof value === "object" && value !== null && value["@type"] === LEGACY_REFERENCE_TYPE_TAG;
|
|
112
|
+
var LEGACY_TYPE_PROPERTIES = "dxos.sdk.client.Properties";
|
|
63
113
|
// Annotate the CommonJS export names for ESM import in node:
|
|
64
114
|
0 && (module.exports = {
|
|
115
|
+
LEGACY_REFERENCE_TYPE_TAG,
|
|
116
|
+
LEGACY_TYPE_PROPERTIES,
|
|
65
117
|
REFERENCE_TYPE_TAG,
|
|
66
118
|
Reference,
|
|
119
|
+
SpaceDocVersion,
|
|
67
120
|
decodeReference,
|
|
68
121
|
encodeReference,
|
|
69
|
-
|
|
122
|
+
isEncodedReference,
|
|
123
|
+
isLegacyReference
|
|
70
124
|
});
|
|
71
125
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/reference.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { type
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["Reference", "fromValue", "value", "
|
|
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,kBAAqC;AAO9B,IAAMA,YAAN,MAAMA,WAAAA;EAIX,OAAA;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,gBAAID,KAAKE;AACZ,eAAOb,WAAUO,mBAAmBG,IAAII,MAAM,CAAA,CAAE;MAClD,KAAKF,gBAAID,KAAKI;AACZ,YAAIL,IAAII,MAAM,CAAA,MAAOE,6BAAiB;AACpC,iBAAO,IAAIhB,WAAUU,IAAII,MAAM,CAAA,CAAE;QACnC,OAAO;AACL,iBAAO,IAAId,WAAUU,IAAII,MAAM,CAAA,GAAIG,QAAWP,IAAII,MAAM,CAAA,CAAE;QAC5D;MACF;AACE,cAAM,IAAII,MAAM,yBAAyBR,IAAIC,IAAI,EAAE;IACvD;EACF;;EAGAQ,YACkBf,UACAC,UACAC,MAChB;SAHgBF,WAAAA;SACAC,WAAAA;SACAC,OAAAA;EACf;EAEHc,SAAyB;AACvB,WAAO;MAAEhB,UAAU,KAAKA;MAAUE,MAAM,KAAKA;MAAMD,UAAU,KAAKA;IAAS;EAC7E;EAEAgB,QAAa;AACX,QAAI,KAAKhB,aAAaL,WAAUC,eAAe;AAC7C,aAAO,IAAIW,gBAAIA,gBAAID,KAAKE,MAAM;QAAC,KAAKT;OAAS;IAC/C,OAAO;AACL,UAAI,KAAKE,MAAM;AAIb,eAAO,IAAIM,gBAAIA,gBAAID,KAAKI,MAAM;UAAC,KAAKT;UAAM,KAAKF;SAAS;MAC1D,OAAO;AACL,eAAO,IAAIQ,gBAAIA,gBAAID,KAAKI,MAAM;UAACC;UAAiB,KAAKZ;SAAS;MAChE;IACF;EACF;AACF;AAEO,IAAMkB,qBAAqB;AAS3B,IAAMC,kBAAkB,CAACC,eAA4C;EAC1E,KAAKA,UAAUH,MAAK,EAAGI,SAAQ;AACjC;AAEO,IAAMC,kBAAkB,CAACvB,UAAeH,UAAUS,QAAQG,gBAAIe,MAAMxB,MAAM,GAAA,CAAI,CAAA;AAE9E,IAAMyB,qBAAqB,CAACzB,UACjC,OAAOA,UAAU,YAAYA,UAAU,QAAQ0B,OAAOC,KAAK3B,KAAAA,EAAO4B,WAAW,KAAK,OAAO5B,MAAM,GAAA,MAAS;AC9EnG,IAAM6B,kBAAkBH,OAAOI,OAAO;;;;EAI3CC,QAAQ;;;;EAKRC,SAAS;AACX,CAAA;ACfO,IAAMC,4BAA4B;AAYlC,IAAMC,oBAAoB,CAAClC,UAChC,OAAOA,UAAU,YAAYA,UAAU,QAAQA,MAAM,OAAA,MAAaiC;AAE7D,IAAME,yBAAyB;",
|
|
6
|
+
"names": ["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", "SpaceDocVersion", "freeze", "LEGACY", "CURRENT", "LEGACY_REFERENCE_TYPE_TAG", "isLegacyReference", "LEGACY_TYPE_PROPERTIES"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo-protocol/src/document-structure.ts":{"bytes":
|
|
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/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5988},"packages/core/echo/echo-protocol/dist/lib/node/index.cjs":{"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}}}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type EncodedReference } from './reference';
|
|
2
|
+
import type { SpaceDocVersion } from './space-doc-version';
|
|
2
3
|
export type SpaceState = {
|
|
3
4
|
rootUrl?: string;
|
|
4
5
|
};
|
|
5
6
|
export interface SpaceDoc {
|
|
7
|
+
version?: SpaceDocVersion;
|
|
6
8
|
access?: {
|
|
7
9
|
spaceKey: string;
|
|
8
10
|
};
|
|
@@ -58,7 +60,7 @@ export type ObjectSystem = {
|
|
|
58
60
|
/**
|
|
59
61
|
* Object reference ('protobuf' protocol) type.
|
|
60
62
|
*/
|
|
61
|
-
type?:
|
|
63
|
+
type?: EncodedReference;
|
|
62
64
|
/**
|
|
63
65
|
* Deletion marker.
|
|
64
66
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-structure.d.ts","sourceRoot":"","sources":["../../../src/document-structure.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"document-structure.d.ts","sourceRoot":"","sources":["../../../src/document-structure.ts"],"names":[],"mappings":"AAIA,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,CAAC;KAC1B,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,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,UAAU,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -1,28 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type
|
|
1
|
+
import { DXN } from '@dxos/keys';
|
|
2
|
+
import { type ObjectId } from '@dxos/protocols';
|
|
3
|
+
import { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';
|
|
4
|
+
/**
|
|
5
|
+
* Runtime representation of object reference.
|
|
6
|
+
*/
|
|
3
7
|
export declare class Reference {
|
|
4
|
-
readonly
|
|
8
|
+
readonly objectId: ObjectId;
|
|
5
9
|
readonly protocol?: string | undefined;
|
|
6
10
|
readonly host?: string | undefined;
|
|
7
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Protocol references to runtime registered types.
|
|
13
|
+
*/
|
|
14
|
+
static TYPE_PROTOCOL: string;
|
|
15
|
+
static fromValue(value: ReferenceProto): Reference;
|
|
8
16
|
/**
|
|
9
17
|
* @deprecated
|
|
10
18
|
*/
|
|
11
19
|
static fromLegacyTypename(type: string): Reference;
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
static fromDXN(dxn: DXN): Reference;
|
|
21
|
+
constructor(objectId: ObjectId, protocol?: string | undefined, host?: string | undefined);
|
|
22
|
+
encode(): ReferenceProto;
|
|
23
|
+
toDXN(): DXN;
|
|
14
24
|
}
|
|
15
25
|
export declare const REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
|
|
16
26
|
/**
|
|
17
27
|
* Reference as it is stored in Automerge document.
|
|
18
28
|
*/
|
|
19
|
-
export type
|
|
20
|
-
'
|
|
21
|
-
itemId: string | null;
|
|
22
|
-
protocol: string | null;
|
|
23
|
-
host: string | null;
|
|
29
|
+
export type EncodedReference = {
|
|
30
|
+
'/': string;
|
|
24
31
|
};
|
|
25
|
-
export declare const encodeReference: (reference: Reference) =>
|
|
32
|
+
export declare const encodeReference: (reference: Reference) => EncodedReference;
|
|
26
33
|
export declare const decodeReference: (value: any) => Reference;
|
|
27
|
-
export declare const
|
|
34
|
+
export declare const isEncodedReference: (value: any) => value is EncodedReference;
|
|
28
35
|
//# sourceMappingURL=reference.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/reference.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/reference.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAmB,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,KAAK,SAAS,IAAI,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAElG;;GAEG;AACH,qBAAa,SAAS;aAmCF,QAAQ,EAAE,QAAQ;aAClB,QAAQ,CAAC;aACT,IAAI,CAAC;IApCvB;;OAEG;IACH,MAAM,CAAC,aAAa,SAAc;IAElC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS;IAIlD;;OAEG;IAEH,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAIlD,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,SAAS;gBAiBjB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,CAAC,oBAAQ,EACjB,IAAI,CAAC,oBAAQ;IAG/B,MAAM,IAAI,cAAc;IAIxB,KAAK,IAAI,GAAG;CAcb;AAED,eAAO,MAAM,kBAAkB,uCAAuC,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,SAAS,KAAG,gBAErD,CAAC;AAEH,eAAO,MAAM,eAAe,UAAW,GAAG,cAA6C,CAAC;AAExF,eAAO,MAAM,kBAAkB,UAAW,GAAG,8BACqE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Denotes the data version of the space automerge document as well as the leaf documents for each individual ECHO object.
|
|
3
|
+
*/
|
|
4
|
+
export type SpaceDocVersion = number & {
|
|
5
|
+
__type: 'SpaceDocVersion';
|
|
6
|
+
};
|
|
7
|
+
export declare const SpaceDocVersion: Readonly<{
|
|
8
|
+
/**
|
|
9
|
+
* For the documents created before the versioning was introduced.
|
|
10
|
+
*/
|
|
11
|
+
LEGACY: SpaceDocVersion;
|
|
12
|
+
/**
|
|
13
|
+
* Current version.
|
|
14
|
+
*/
|
|
15
|
+
CURRENT: SpaceDocVersion;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=space-doc-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"space-doc-version.d.ts","sourceRoot":"","sources":["../../../src/space-doc-version.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG;IAAE,MAAM,EAAE,iBAAiB,CAAA;CAAE,CAAC;AAErE,eAAO,MAAM,eAAe;IAC1B;;OAEG;;IAGH;;OAEG;;EAEH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-protocol",
|
|
3
|
-
"version": "0.5.9-main.
|
|
3
|
+
"version": "0.5.9-main.c2c4258",
|
|
4
4
|
"description": "Core ECHO APIs.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"src"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@dxos/
|
|
25
|
+
"@dxos/keys": "0.5.9-main.c2c4258",
|
|
26
|
+
"@dxos/protocols": "0.5.9-main.c2c4258"
|
|
26
27
|
},
|
|
27
28
|
"publishConfig": {
|
|
28
29
|
"access": "public"
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type EncodedReference } from './reference';
|
|
6
|
+
import type { SpaceDocVersion } from './space-doc-version';
|
|
6
7
|
|
|
7
8
|
export type SpaceState = {
|
|
8
9
|
// Url of the root automerge document.
|
|
@@ -11,6 +12,8 @@ export type SpaceState = {
|
|
|
11
12
|
|
|
12
13
|
// TODO(dmaretskyi): Rename DatabaseRootDoc.
|
|
13
14
|
export interface SpaceDoc {
|
|
15
|
+
version?: SpaceDocVersion;
|
|
16
|
+
|
|
14
17
|
access?: {
|
|
15
18
|
spaceKey: string;
|
|
16
19
|
};
|
|
@@ -71,7 +74,7 @@ export type ObjectSystem = {
|
|
|
71
74
|
/**
|
|
72
75
|
* Object reference ('protobuf' protocol) type.
|
|
73
76
|
*/
|
|
74
|
-
type?:
|
|
77
|
+
type?: EncodedReference;
|
|
75
78
|
|
|
76
79
|
/**
|
|
77
80
|
* Deletion marker.
|
package/src/index.ts
CHANGED
package/src/legacy.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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';
|
package/src/reference.ts
CHANGED
|
@@ -2,13 +2,21 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { type
|
|
5
|
+
import { DXN, LOCAL_SPACE_TAG } from '@dxos/keys';
|
|
6
|
+
import { type ObjectId } from '@dxos/protocols';
|
|
7
|
+
import { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Runtime representation of object reference.
|
|
11
|
+
*/
|
|
9
12
|
export class Reference {
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Protocol references to runtime registered types.
|
|
15
|
+
*/
|
|
16
|
+
static TYPE_PROTOCOL = 'protobuf';
|
|
17
|
+
|
|
18
|
+
static fromValue(value: ReferenceProto): Reference {
|
|
19
|
+
return new Reference(value.objectId, value.protocol, value.host);
|
|
12
20
|
}
|
|
13
21
|
|
|
14
22
|
/**
|
|
@@ -16,19 +24,48 @@ export class Reference {
|
|
|
16
24
|
*/
|
|
17
25
|
// TODO(burdon): Document/remove?
|
|
18
26
|
static fromLegacyTypename(type: string): Reference {
|
|
19
|
-
return new Reference(type,
|
|
27
|
+
return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static fromDXN(dxn: DXN): Reference {
|
|
31
|
+
switch (dxn.kind) {
|
|
32
|
+
case DXN.kind.TYPE:
|
|
33
|
+
return Reference.fromLegacyTypename(dxn.parts[0]);
|
|
34
|
+
case DXN.kind.ECHO:
|
|
35
|
+
if (dxn.parts[0] === LOCAL_SPACE_TAG) {
|
|
36
|
+
return new Reference(dxn.parts[1]);
|
|
37
|
+
} else {
|
|
38
|
+
return new Reference(dxn.parts[1], undefined, dxn.parts[0]);
|
|
39
|
+
}
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(`Unsupported DXN kind: ${dxn.kind}`);
|
|
42
|
+
}
|
|
20
43
|
}
|
|
21
44
|
|
|
22
45
|
// prettier-ignore
|
|
23
46
|
constructor(
|
|
24
|
-
|
|
25
|
-
public readonly itemId: ItemID,
|
|
47
|
+
public readonly objectId: ObjectId,
|
|
26
48
|
public readonly protocol?: string,
|
|
27
49
|
public readonly host?: string
|
|
28
50
|
) {}
|
|
29
51
|
|
|
30
|
-
encode():
|
|
31
|
-
return {
|
|
52
|
+
encode(): ReferenceProto {
|
|
53
|
+
return { objectId: this.objectId, host: this.host, protocol: this.protocol };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
toDXN(): DXN {
|
|
57
|
+
if (this.protocol === Reference.TYPE_PROTOCOL) {
|
|
58
|
+
return new DXN(DXN.kind.TYPE, [this.objectId]);
|
|
59
|
+
} else {
|
|
60
|
+
if (this.host) {
|
|
61
|
+
// Host is assumed to be the space key.
|
|
62
|
+
// The DXN should actually have the space ID.
|
|
63
|
+
// TODO(dmaretskyi): Migrate to space id.
|
|
64
|
+
return new DXN(DXN.kind.ECHO, [this.host, this.objectId]);
|
|
65
|
+
} else {
|
|
66
|
+
return new DXN(DXN.kind.ECHO, [LOCAL_SPACE_TAG, this.objectId]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
32
69
|
}
|
|
33
70
|
}
|
|
34
71
|
|
|
@@ -37,23 +74,15 @@ export const REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';
|
|
|
37
74
|
/**
|
|
38
75
|
* Reference as it is stored in Automerge document.
|
|
39
76
|
*/
|
|
40
|
-
export type
|
|
41
|
-
'
|
|
42
|
-
itemId: string | null;
|
|
43
|
-
protocol: string | null;
|
|
44
|
-
host: string | null;
|
|
77
|
+
export type EncodedReference = {
|
|
78
|
+
'/': string;
|
|
45
79
|
};
|
|
46
80
|
|
|
47
|
-
export const encodeReference = (reference: Reference):
|
|
48
|
-
'
|
|
49
|
-
// NOTE: Automerge do not support undefined values, so we need to use null instead.
|
|
50
|
-
itemId: reference.itemId ?? null,
|
|
51
|
-
protocol: reference.protocol ?? null,
|
|
52
|
-
host: reference.host ?? null,
|
|
81
|
+
export const encodeReference = (reference: Reference): EncodedReference => ({
|
|
82
|
+
'/': reference.toDXN().toString(),
|
|
53
83
|
});
|
|
54
84
|
|
|
55
|
-
export const decodeReference = (value: any) =>
|
|
56
|
-
new Reference(value.itemId, value.protocol ?? undefined, value.host ?? undefined);
|
|
85
|
+
export const decodeReference = (value: any) => Reference.fromDXN(DXN.parse(value['/']));
|
|
57
86
|
|
|
58
|
-
export const
|
|
59
|
-
typeof value === 'object' && value !== null && value['
|
|
87
|
+
export const isEncodedReference = (value: any): value is EncodedReference =>
|
|
88
|
+
typeof value === 'object' && value !== null && Object.keys(value).length === 1 && typeof value['/'] === 'string';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Denotes the data version of the space automerge document as well as the leaf documents for each individual ECHO object.
|
|
7
|
+
*/
|
|
8
|
+
export type SpaceDocVersion = number & { __type: 'SpaceDocVersion' };
|
|
9
|
+
|
|
10
|
+
export const SpaceDocVersion = Object.freeze({
|
|
11
|
+
/**
|
|
12
|
+
* For the documents created before the versioning was introduced.
|
|
13
|
+
*/
|
|
14
|
+
LEGACY: 0 as SpaceDocVersion,
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Current version.
|
|
18
|
+
*/
|
|
19
|
+
CURRENT: 1 as SpaceDocVersion,
|
|
20
|
+
});
|