@dxos/echo-protocol 0.8.4-main.fd6878d → 0.8.4-staging.60fe92afc8
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 +102 -5
- package/README.md +1 -1
- package/dist/lib/neutral/index.mjs +721 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/document-structure.d.ts +85 -30
- package/dist/types/src/document-structure.d.ts.map +1 -1
- package/dist/types/src/echo-feed-codec.d.ts +17 -0
- package/dist/types/src/echo-feed-codec.d.ts.map +1 -0
- package/dist/types/src/edge-peer.d.ts +11 -0
- package/dist/types/src/edge-peer.d.ts.map +1 -0
- package/dist/types/src/foreign-key.d.ts +1 -1
- package/dist/types/src/foreign-key.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +5 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/query/ast.d.ts +290 -28
- package/dist/types/src/query/ast.d.ts.map +1 -1
- package/dist/types/src/reference.d.ts +11 -64
- package/dist/types/src/reference.d.ts.map +1 -1
- package/dist/types/src/space-id.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -15
- package/src/document-structure.ts +106 -33
- package/src/echo-feed-codec.ts +67 -0
- package/src/edge-peer.ts +27 -0
- package/src/foreign-key.ts +4 -3
- package/src/index.ts +5 -3
- package/src/query/ast.ts +353 -38
- package/src/reference.ts +13 -158
- package/dist/lib/browser/index.mjs +0 -526
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -527
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
package/src/reference.ts
CHANGED
|
@@ -3,126 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { assertArgument } from '@dxos/invariant';
|
|
6
|
-
import {
|
|
7
|
-
import { type ObjectId } from '@dxos/protocols';
|
|
8
|
-
import { type Reference as ReferenceProto } from '@dxos/protocols/proto/dxos/echo/model/document';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Runtime representation of an reference in ECHO.
|
|
12
|
-
* Implemented as a DXN, but we might extend it to other URIs in the future.
|
|
13
|
-
* @deprecated Use `EncodedReference` instead.
|
|
14
|
-
*/
|
|
15
|
-
export class Reference {
|
|
16
|
-
/**
|
|
17
|
-
* Protocol references to runtime registered types.
|
|
18
|
-
* @deprecated
|
|
19
|
-
*/
|
|
20
|
-
static TYPE_PROTOCOL = 'protobuf';
|
|
21
|
-
|
|
22
|
-
static fromDXN(dxn: DXN): Reference {
|
|
23
|
-
switch (dxn.kind) {
|
|
24
|
-
case DXN.kind.TYPE:
|
|
25
|
-
return new Reference(dxn.parts[0], Reference.TYPE_PROTOCOL, 'dxos.org', dxn);
|
|
26
|
-
case DXN.kind.ECHO:
|
|
27
|
-
if (dxn.parts[0] === LOCAL_SPACE_TAG) {
|
|
28
|
-
return new Reference(dxn.parts[1], undefined, undefined, dxn);
|
|
29
|
-
} else {
|
|
30
|
-
return new Reference(dxn.parts[1], undefined, dxn.parts[0], dxn);
|
|
31
|
-
}
|
|
32
|
-
default:
|
|
33
|
-
return new Reference(dxn.parts[0], undefined, dxn.parts[0], dxn);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
static fromValue(value: ReferenceProto): Reference {
|
|
38
|
-
return new Reference(value.objectId, value.protocol, value.host);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Reference an object in the local space.
|
|
43
|
-
*/
|
|
44
|
-
static localObjectReference(objectId: ObjectId): Reference {
|
|
45
|
-
return new Reference(objectId);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @deprecated
|
|
50
|
-
*/
|
|
51
|
-
// TODO(dmaretskyi): Remove.
|
|
52
|
-
static fromLegacyTypename(type: string): Reference {
|
|
53
|
-
return new Reference(type, Reference.TYPE_PROTOCOL, 'dxos.org');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @deprecated
|
|
58
|
-
*/
|
|
59
|
-
// TODO(dmaretskyi): Remove
|
|
60
|
-
static fromObjectIdAndSpaceKey(objectId: ObjectId, spaceKey: PublicKey): Reference {
|
|
61
|
-
// TODO(dmaretskyi): FIX ME! This should be a space ID not a space key.
|
|
62
|
-
return new Reference(objectId, undefined, spaceKey.toHex());
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// prettier-ignore
|
|
66
|
-
private constructor(
|
|
67
|
-
// TODO(dmaretskyi): Remove and just leave DXN.
|
|
68
|
-
private readonly _objectId: ObjectId,
|
|
69
|
-
private readonly _protocol?: string,
|
|
70
|
-
private readonly _host?: string,
|
|
71
|
-
private readonly _dxn?: DXN,
|
|
72
|
-
) {}
|
|
73
|
-
|
|
74
|
-
get dxn(): DXN | undefined {
|
|
75
|
-
return this._dxn;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @deprecated
|
|
80
|
-
*/
|
|
81
|
-
// TODO(dmaretskyi): Remove.
|
|
82
|
-
get objectId(): ObjectId {
|
|
83
|
-
return this._objectId;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @deprecated
|
|
88
|
-
*/
|
|
89
|
-
// TODO(dmaretskyi): Remove.
|
|
90
|
-
get protocol(): string | undefined {
|
|
91
|
-
return this._protocol;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @deprecated
|
|
96
|
-
*/
|
|
97
|
-
// TODO(dmaretskyi): Remove.
|
|
98
|
-
get host(): string | undefined {
|
|
99
|
-
return this._host;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
encode(): ReferenceProto {
|
|
103
|
-
return { objectId: this.objectId, host: this.host, protocol: this.protocol };
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// TODO(dmaretskyi): Remove in favor of `reference.dxn`.
|
|
107
|
-
toDXN(): DXN {
|
|
108
|
-
if (this._dxn) {
|
|
109
|
-
return this._dxn;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (this.protocol === Reference.TYPE_PROTOCOL) {
|
|
113
|
-
return new DXN(DXN.kind.TYPE, [this.objectId]);
|
|
114
|
-
} else {
|
|
115
|
-
if (this.host) {
|
|
116
|
-
// Host is assumed to be the space key.
|
|
117
|
-
// The DXN should actually have the space ID.
|
|
118
|
-
// TODO(dmaretskyi): Migrate to space id.
|
|
119
|
-
return new DXN(DXN.kind.ECHO, [this.host, this.objectId]);
|
|
120
|
-
} else {
|
|
121
|
-
return new DXN(DXN.kind.ECHO, [LOCAL_SPACE_TAG, this.objectId]);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
6
|
+
import { URI } from '@dxos/keys';
|
|
126
7
|
|
|
127
8
|
// TODO(dmaretskyi): Is this used anywhere?
|
|
128
9
|
export const REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';
|
|
@@ -131,52 +12,26 @@ export const REFERENCE_TYPE_TAG = 'dxos.echo.model.document.Reference';
|
|
|
131
12
|
* Reference as it is stored in Automerge document.
|
|
132
13
|
*/
|
|
133
14
|
export type EncodedReference = {
|
|
134
|
-
'/':
|
|
15
|
+
'/': URI.URI;
|
|
135
16
|
};
|
|
136
17
|
|
|
137
|
-
/**
|
|
138
|
-
* @deprecated Use `EncodedReference.fromDXN` instead.
|
|
139
|
-
*/
|
|
140
|
-
export const encodeReference = (reference: Reference): EncodedReference => ({
|
|
141
|
-
'/': reference.toDXN().toString(),
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* @deprecated Use `EncodedReference.toDXN` instead.
|
|
146
|
-
*/
|
|
147
|
-
export const decodeReference = (value: any) => {
|
|
148
|
-
if (typeof value !== 'object' || value === null || typeof value['/'] !== 'string') {
|
|
149
|
-
throw new Error('Invalid reference');
|
|
150
|
-
}
|
|
151
|
-
const dxnString = value['/'];
|
|
152
|
-
|
|
153
|
-
if (
|
|
154
|
-
dxnString.length % 2 === 0 &&
|
|
155
|
-
dxnString.slice(0, dxnString.length / 2) === dxnString.slice(dxnString.length / 2) &&
|
|
156
|
-
dxnString.includes('dxn:echo')
|
|
157
|
-
) {
|
|
158
|
-
throw new Error('Automerge bug detected!');
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return Reference.fromDXN(DXN.parse(dxnString));
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* @deprecated Use `EncodedReference.isEncodedReference` instead.
|
|
166
|
-
*/
|
|
167
18
|
export const isEncodedReference = (value: any): value is EncodedReference =>
|
|
168
19
|
typeof value === 'object' && value !== null && Object.keys(value).length === 1 && typeof value['/'] === 'string';
|
|
169
20
|
|
|
170
21
|
export const EncodedReference = Object.freeze({
|
|
171
22
|
isEncodedReference,
|
|
172
|
-
|
|
173
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Returns the opaque URI stored in the encoded reference (any scheme: `echo:` or `dxn:`).
|
|
25
|
+
* Consumers can narrow with `EID.isEID(uri)` / `DXN.isDXN(uri)`.
|
|
26
|
+
*/
|
|
27
|
+
toURI: (value: EncodedReference): URI.URI => {
|
|
28
|
+
assertArgument(isEncodedReference(value), 'value', 'invalid reference');
|
|
174
29
|
return value['/'];
|
|
175
30
|
},
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return
|
|
31
|
+
/**
|
|
32
|
+
* Creates an encoded reference from an opaque URI.
|
|
33
|
+
*/
|
|
34
|
+
fromURI: (uri: URI.URI): EncodedReference => {
|
|
35
|
+
return { '/': uri };
|
|
181
36
|
},
|
|
182
37
|
});
|
|
@@ -1,526 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
// src/document-structure.ts
|
|
8
|
-
import { invariant } from "@dxos/invariant";
|
|
9
|
-
import { visitValues } from "@dxos/util";
|
|
10
|
-
|
|
11
|
-
// src/reference.ts
|
|
12
|
-
import { assertArgument } from "@dxos/invariant";
|
|
13
|
-
import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
|
|
14
|
-
var Reference = class _Reference {
|
|
15
|
-
_objectId;
|
|
16
|
-
_protocol;
|
|
17
|
-
_host;
|
|
18
|
-
_dxn;
|
|
19
|
-
/**
|
|
20
|
-
* Protocol references to runtime registered types.
|
|
21
|
-
* @deprecated
|
|
22
|
-
*/
|
|
23
|
-
static TYPE_PROTOCOL = "protobuf";
|
|
24
|
-
static fromDXN(dxn) {
|
|
25
|
-
switch (dxn.kind) {
|
|
26
|
-
case DXN.kind.TYPE:
|
|
27
|
-
return new _Reference(dxn.parts[0], _Reference.TYPE_PROTOCOL, "dxos.org", dxn);
|
|
28
|
-
case DXN.kind.ECHO:
|
|
29
|
-
if (dxn.parts[0] === LOCAL_SPACE_TAG) {
|
|
30
|
-
return new _Reference(dxn.parts[1], void 0, void 0, dxn);
|
|
31
|
-
} else {
|
|
32
|
-
return new _Reference(dxn.parts[1], void 0, dxn.parts[0], dxn);
|
|
33
|
-
}
|
|
34
|
-
default:
|
|
35
|
-
return new _Reference(dxn.parts[0], void 0, dxn.parts[0], dxn);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
static fromValue(value) {
|
|
39
|
-
return new _Reference(value.objectId, value.protocol, value.host);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Reference an object in the local space.
|
|
43
|
-
*/
|
|
44
|
-
static localObjectReference(objectId) {
|
|
45
|
-
return new _Reference(objectId);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* @deprecated
|
|
49
|
-
*/
|
|
50
|
-
// TODO(dmaretskyi): Remove.
|
|
51
|
-
static fromLegacyTypename(type) {
|
|
52
|
-
return new _Reference(type, _Reference.TYPE_PROTOCOL, "dxos.org");
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* @deprecated
|
|
56
|
-
*/
|
|
57
|
-
// TODO(dmaretskyi): Remove
|
|
58
|
-
static fromObjectIdAndSpaceKey(objectId, spaceKey) {
|
|
59
|
-
return new _Reference(objectId, void 0, spaceKey.toHex());
|
|
60
|
-
}
|
|
61
|
-
// prettier-ignore
|
|
62
|
-
constructor(_objectId, _protocol, _host, _dxn) {
|
|
63
|
-
this._objectId = _objectId;
|
|
64
|
-
this._protocol = _protocol;
|
|
65
|
-
this._host = _host;
|
|
66
|
-
this._dxn = _dxn;
|
|
67
|
-
}
|
|
68
|
-
get dxn() {
|
|
69
|
-
return this._dxn;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* @deprecated
|
|
73
|
-
*/
|
|
74
|
-
// TODO(dmaretskyi): Remove.
|
|
75
|
-
get objectId() {
|
|
76
|
-
return this._objectId;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* @deprecated
|
|
80
|
-
*/
|
|
81
|
-
// TODO(dmaretskyi): Remove.
|
|
82
|
-
get protocol() {
|
|
83
|
-
return this._protocol;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* @deprecated
|
|
87
|
-
*/
|
|
88
|
-
// TODO(dmaretskyi): Remove.
|
|
89
|
-
get host() {
|
|
90
|
-
return this._host;
|
|
91
|
-
}
|
|
92
|
-
encode() {
|
|
93
|
-
return {
|
|
94
|
-
objectId: this.objectId,
|
|
95
|
-
host: this.host,
|
|
96
|
-
protocol: this.protocol
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
// TODO(dmaretskyi): Remove in favor of `reference.dxn`.
|
|
100
|
-
toDXN() {
|
|
101
|
-
if (this._dxn) {
|
|
102
|
-
return this._dxn;
|
|
103
|
-
}
|
|
104
|
-
if (this.protocol === _Reference.TYPE_PROTOCOL) {
|
|
105
|
-
return new DXN(DXN.kind.TYPE, [
|
|
106
|
-
this.objectId
|
|
107
|
-
]);
|
|
108
|
-
} else {
|
|
109
|
-
if (this.host) {
|
|
110
|
-
return new DXN(DXN.kind.ECHO, [
|
|
111
|
-
this.host,
|
|
112
|
-
this.objectId
|
|
113
|
-
]);
|
|
114
|
-
} else {
|
|
115
|
-
return new DXN(DXN.kind.ECHO, [
|
|
116
|
-
LOCAL_SPACE_TAG,
|
|
117
|
-
this.objectId
|
|
118
|
-
]);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
|
|
124
|
-
var encodeReference = (reference) => ({
|
|
125
|
-
"/": reference.toDXN().toString()
|
|
126
|
-
});
|
|
127
|
-
var decodeReference = (value) => {
|
|
128
|
-
if (typeof value !== "object" || value === null || typeof value["/"] !== "string") {
|
|
129
|
-
throw new Error("Invalid reference");
|
|
130
|
-
}
|
|
131
|
-
const dxnString = value["/"];
|
|
132
|
-
if (dxnString.length % 2 === 0 && dxnString.slice(0, dxnString.length / 2) === dxnString.slice(dxnString.length / 2) && dxnString.includes("dxn:echo")) {
|
|
133
|
-
throw new Error("Automerge bug detected!");
|
|
134
|
-
}
|
|
135
|
-
return Reference.fromDXN(DXN.parse(dxnString));
|
|
136
|
-
};
|
|
137
|
-
var isEncodedReference = (value) => typeof value === "object" && value !== null && Object.keys(value).length === 1 && typeof value["/"] === "string";
|
|
138
|
-
var EncodedReference = Object.freeze({
|
|
139
|
-
isEncodedReference,
|
|
140
|
-
getReferenceString: (value) => {
|
|
141
|
-
assertArgument(isEncodedReference(value), "invalid reference");
|
|
142
|
-
return value["/"];
|
|
143
|
-
},
|
|
144
|
-
toDXN: (value) => {
|
|
145
|
-
return DXN.parse(EncodedReference.getReferenceString(value));
|
|
146
|
-
},
|
|
147
|
-
fromDXN: (dxn) => {
|
|
148
|
-
return encodeReference(Reference.fromDXN(dxn));
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
// src/document-structure.ts
|
|
153
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo-protocol/src/document-structure.ts";
|
|
154
|
-
var DatabaseDirectory = Object.freeze({
|
|
155
|
-
/**
|
|
156
|
-
* @returns Space key in hex of the space that owns the document. In hex format. Without 0x prefix.
|
|
157
|
-
*/
|
|
158
|
-
getSpaceKey: (doc) => {
|
|
159
|
-
const rawSpaceKey = doc.access?.spaceKey ?? doc.experimental_spaceKey;
|
|
160
|
-
if (rawSpaceKey == null) {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
const rawKey = String(rawSpaceKey);
|
|
164
|
-
invariant(!rawKey.startsWith("0x"), "Space key must not start with 0x", {
|
|
165
|
-
F: __dxlog_file,
|
|
166
|
-
L: 66,
|
|
167
|
-
S: void 0,
|
|
168
|
-
A: [
|
|
169
|
-
"!rawKey.startsWith('0x')",
|
|
170
|
-
"'Space key must not start with 0x'"
|
|
171
|
-
]
|
|
172
|
-
});
|
|
173
|
-
return rawKey;
|
|
174
|
-
},
|
|
175
|
-
getInlineObject: (doc, id) => {
|
|
176
|
-
return doc.objects?.[id];
|
|
177
|
-
},
|
|
178
|
-
getLink: (doc, id) => {
|
|
179
|
-
return doc.links?.[id]?.toString();
|
|
180
|
-
},
|
|
181
|
-
make: ({ spaceKey, objects, links }) => ({
|
|
182
|
-
access: {
|
|
183
|
-
spaceKey
|
|
184
|
-
},
|
|
185
|
-
objects: objects ?? {},
|
|
186
|
-
links: links ?? {}
|
|
187
|
-
})
|
|
188
|
-
});
|
|
189
|
-
var ObjectStructure = Object.freeze({
|
|
190
|
-
/**
|
|
191
|
-
* @throws On invalid object structure.
|
|
192
|
-
*/
|
|
193
|
-
getTypeReference: (object) => {
|
|
194
|
-
return object.system?.type;
|
|
195
|
-
},
|
|
196
|
-
/**
|
|
197
|
-
* @throws On invalid object structure.
|
|
198
|
-
*/
|
|
199
|
-
getEntityKind: (object) => {
|
|
200
|
-
const kind = object.system?.kind ?? "object";
|
|
201
|
-
invariant(kind === "object" || kind === "relation", "Invalid kind", {
|
|
202
|
-
F: __dxlog_file,
|
|
203
|
-
L: 124,
|
|
204
|
-
S: void 0,
|
|
205
|
-
A: [
|
|
206
|
-
"kind === 'object' || kind === 'relation'",
|
|
207
|
-
"'Invalid kind'"
|
|
208
|
-
]
|
|
209
|
-
});
|
|
210
|
-
return kind;
|
|
211
|
-
},
|
|
212
|
-
isDeleted: (object) => {
|
|
213
|
-
return object.system?.deleted ?? false;
|
|
214
|
-
},
|
|
215
|
-
getRelationSource: (object) => {
|
|
216
|
-
return object.system?.source;
|
|
217
|
-
},
|
|
218
|
-
getRelationTarget: (object) => {
|
|
219
|
-
return object.system?.target;
|
|
220
|
-
},
|
|
221
|
-
/**
|
|
222
|
-
* @returns All references in the data section of the object.
|
|
223
|
-
*/
|
|
224
|
-
getAllOutgoingReferences: (object) => {
|
|
225
|
-
const references = [];
|
|
226
|
-
const visit2 = (path, value) => {
|
|
227
|
-
if (isEncodedReference(value)) {
|
|
228
|
-
references.push({
|
|
229
|
-
path,
|
|
230
|
-
reference: value
|
|
231
|
-
});
|
|
232
|
-
} else {
|
|
233
|
-
visitValues(value, (value2, key) => visit2([
|
|
234
|
-
...path,
|
|
235
|
-
String(key)
|
|
236
|
-
], value2));
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
visitValues(object.data, (value, key) => visit2([
|
|
240
|
-
String(key)
|
|
241
|
-
], value));
|
|
242
|
-
return references;
|
|
243
|
-
},
|
|
244
|
-
makeObject: ({ type, data, keys }) => {
|
|
245
|
-
return {
|
|
246
|
-
system: {
|
|
247
|
-
kind: "object",
|
|
248
|
-
type: {
|
|
249
|
-
"/": type
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
meta: {
|
|
253
|
-
keys: keys ?? []
|
|
254
|
-
},
|
|
255
|
-
data: data ?? {}
|
|
256
|
-
};
|
|
257
|
-
},
|
|
258
|
-
makeRelation: ({ type, source, target, deleted, keys, data }) => {
|
|
259
|
-
return {
|
|
260
|
-
system: {
|
|
261
|
-
kind: "relation",
|
|
262
|
-
type: {
|
|
263
|
-
"/": type
|
|
264
|
-
},
|
|
265
|
-
source,
|
|
266
|
-
target,
|
|
267
|
-
deleted: deleted ?? false
|
|
268
|
-
},
|
|
269
|
-
meta: {
|
|
270
|
-
keys: keys ?? []
|
|
271
|
-
},
|
|
272
|
-
data: data ?? {}
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
var PROPERTY_ID = "id";
|
|
277
|
-
var DATA_NAMESPACE = "data";
|
|
278
|
-
|
|
279
|
-
// src/space-doc-version.ts
|
|
280
|
-
var SpaceDocVersion = Object.freeze({
|
|
281
|
-
/**
|
|
282
|
-
* For the documents created before the versioning was introduced.
|
|
283
|
-
*/
|
|
284
|
-
LEGACY: 0,
|
|
285
|
-
/**
|
|
286
|
-
* Current version.
|
|
287
|
-
*/
|
|
288
|
-
CURRENT: 1
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
// src/space-id.ts
|
|
292
|
-
import { subtleCrypto } from "@dxos/crypto";
|
|
293
|
-
import { PublicKey, SpaceId } from "@dxos/keys";
|
|
294
|
-
import { ComplexMap } from "@dxos/util";
|
|
295
|
-
var SPACE_IDS_CACHE = new ComplexMap(PublicKey.hash);
|
|
296
|
-
var createIdFromSpaceKey = async (spaceKey) => {
|
|
297
|
-
const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
|
|
298
|
-
if (cachedValue !== void 0) {
|
|
299
|
-
return cachedValue;
|
|
300
|
-
}
|
|
301
|
-
const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
|
|
302
|
-
const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
|
|
303
|
-
const spaceId = SpaceId.encode(bytes);
|
|
304
|
-
SPACE_IDS_CACHE.set(spaceKey, spaceId);
|
|
305
|
-
return spaceId;
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
// src/foreign-key.ts
|
|
309
|
-
import { Schema, SchemaAST } from "effect";
|
|
310
|
-
var ForeignKey_ = Schema.Struct({
|
|
311
|
-
/**
|
|
312
|
-
* Name of the foreign database/system.
|
|
313
|
-
* E.g., `github.com`.
|
|
314
|
-
*/
|
|
315
|
-
source: Schema.String,
|
|
316
|
-
/**
|
|
317
|
-
* Id within the foreign database.
|
|
318
|
-
*/
|
|
319
|
-
// TODO(wittjosiah): This annotation is currently used to ensure id field shows up in forms.
|
|
320
|
-
// TODO(dmaretskyi): `false` is not a valid value for the annotation.
|
|
321
|
-
id: Schema.String.annotations({
|
|
322
|
-
[SchemaAST.IdentifierAnnotationId]: false
|
|
323
|
-
})
|
|
324
|
-
});
|
|
325
|
-
var ForeignKey = ForeignKey_;
|
|
326
|
-
|
|
327
|
-
// src/query/ast.ts
|
|
328
|
-
var ast_exports = {};
|
|
329
|
-
__export(ast_exports, {
|
|
330
|
-
Filter: () => Filter,
|
|
331
|
-
FilterAnd: () => FilterAnd,
|
|
332
|
-
FilterCompare: () => FilterCompare,
|
|
333
|
-
FilterIn: () => FilterIn,
|
|
334
|
-
FilterNot: () => FilterNot,
|
|
335
|
-
FilterObject: () => FilterObject,
|
|
336
|
-
FilterOr: () => FilterOr,
|
|
337
|
-
FilterRange: () => FilterRange,
|
|
338
|
-
FilterTextSearch: () => FilterTextSearch,
|
|
339
|
-
Query: () => Query,
|
|
340
|
-
QueryFilterClause: () => QueryFilterClause,
|
|
341
|
-
QueryIncomingReferencesClause: () => QueryIncomingReferencesClause,
|
|
342
|
-
QueryOptions: () => QueryOptions,
|
|
343
|
-
QueryOptionsClause: () => QueryOptionsClause,
|
|
344
|
-
QueryReferenceTraversalClause: () => QueryReferenceTraversalClause,
|
|
345
|
-
QueryRelationClause: () => QueryRelationClause,
|
|
346
|
-
QueryRelationTraversalClause: () => QueryRelationTraversalClause,
|
|
347
|
-
QuerySelectClause: () => QuerySelectClause,
|
|
348
|
-
QuerySetDifferenceClause: () => QuerySetDifferenceClause,
|
|
349
|
-
QueryUnionClause: () => QueryUnionClause,
|
|
350
|
-
visit: () => visit
|
|
351
|
-
});
|
|
352
|
-
import { Schema as Schema2 } from "effect";
|
|
353
|
-
import { DXN as DXN2, ObjectId } from "@dxos/keys";
|
|
354
|
-
var TypenameSpecifier = Schema2.Union(DXN2.Schema, Schema2.Null).annotations({
|
|
355
|
-
description: "DXN or null. Null means any type will match"
|
|
356
|
-
});
|
|
357
|
-
var FilterObject_ = Schema2.Struct({
|
|
358
|
-
type: Schema2.Literal("object"),
|
|
359
|
-
typename: TypenameSpecifier,
|
|
360
|
-
id: Schema2.optional(Schema2.Array(ObjectId)),
|
|
361
|
-
/**
|
|
362
|
-
* Filter by property.
|
|
363
|
-
* Must not include object ID.
|
|
364
|
-
*/
|
|
365
|
-
props: Schema2.Record({
|
|
366
|
-
key: Schema2.String.annotations({
|
|
367
|
-
description: "Property name"
|
|
368
|
-
}),
|
|
369
|
-
value: Schema2.suspend(() => Filter)
|
|
370
|
-
}),
|
|
371
|
-
/**
|
|
372
|
-
* Objects that have any of the given foreign keys.
|
|
373
|
-
*/
|
|
374
|
-
foreignKeys: Schema2.optional(Schema2.Array(ForeignKey))
|
|
375
|
-
});
|
|
376
|
-
var FilterObject = FilterObject_;
|
|
377
|
-
var FilterCompare_ = Schema2.Struct({
|
|
378
|
-
type: Schema2.Literal("compare"),
|
|
379
|
-
operator: Schema2.Literal("eq", "neq", "gt", "gte", "lt", "lte"),
|
|
380
|
-
value: Schema2.Unknown
|
|
381
|
-
});
|
|
382
|
-
var FilterCompare = FilterCompare_;
|
|
383
|
-
var FilterIn_ = Schema2.Struct({
|
|
384
|
-
type: Schema2.Literal("in"),
|
|
385
|
-
values: Schema2.Array(Schema2.Any)
|
|
386
|
-
});
|
|
387
|
-
var FilterIn = FilterIn_;
|
|
388
|
-
var FilterRange_ = Schema2.Struct({
|
|
389
|
-
type: Schema2.Literal("range"),
|
|
390
|
-
from: Schema2.Any,
|
|
391
|
-
to: Schema2.Any
|
|
392
|
-
});
|
|
393
|
-
var FilterRange = FilterRange_;
|
|
394
|
-
var FilterTextSearch_ = Schema2.Struct({
|
|
395
|
-
type: Schema2.Literal("text-search"),
|
|
396
|
-
text: Schema2.String,
|
|
397
|
-
searchKind: Schema2.optional(Schema2.Literal("full-text", "vector"))
|
|
398
|
-
});
|
|
399
|
-
var FilterTextSearch = FilterTextSearch_;
|
|
400
|
-
var FilterNot_ = Schema2.Struct({
|
|
401
|
-
type: Schema2.Literal("not"),
|
|
402
|
-
filter: Schema2.suspend(() => Filter)
|
|
403
|
-
});
|
|
404
|
-
var FilterNot = FilterNot_;
|
|
405
|
-
var FilterAnd_ = Schema2.Struct({
|
|
406
|
-
type: Schema2.Literal("and"),
|
|
407
|
-
filters: Schema2.Array(Schema2.suspend(() => Filter))
|
|
408
|
-
});
|
|
409
|
-
var FilterAnd = FilterAnd_;
|
|
410
|
-
var FilterOr_ = Schema2.Struct({
|
|
411
|
-
type: Schema2.Literal("or"),
|
|
412
|
-
filters: Schema2.Array(Schema2.suspend(() => Filter))
|
|
413
|
-
});
|
|
414
|
-
var FilterOr = FilterOr_;
|
|
415
|
-
var Filter = Schema2.Union(FilterObject, FilterTextSearch, FilterCompare, FilterIn, FilterRange, FilterNot, FilterAnd, FilterOr);
|
|
416
|
-
var QuerySelectClause_ = Schema2.Struct({
|
|
417
|
-
type: Schema2.Literal("select"),
|
|
418
|
-
filter: Schema2.suspend(() => Filter)
|
|
419
|
-
});
|
|
420
|
-
var QuerySelectClause = QuerySelectClause_;
|
|
421
|
-
var QueryFilterClause_ = Schema2.Struct({
|
|
422
|
-
type: Schema2.Literal("filter"),
|
|
423
|
-
selection: Schema2.suspend(() => Query),
|
|
424
|
-
filter: Schema2.suspend(() => Filter)
|
|
425
|
-
});
|
|
426
|
-
var QueryFilterClause = QueryFilterClause_;
|
|
427
|
-
var QueryReferenceTraversalClause_ = Schema2.Struct({
|
|
428
|
-
type: Schema2.Literal("reference-traversal"),
|
|
429
|
-
anchor: Schema2.suspend(() => Query),
|
|
430
|
-
property: Schema2.String
|
|
431
|
-
});
|
|
432
|
-
var QueryReferenceTraversalClause = QueryReferenceTraversalClause_;
|
|
433
|
-
var QueryIncomingReferencesClause_ = Schema2.Struct({
|
|
434
|
-
type: Schema2.Literal("incoming-references"),
|
|
435
|
-
anchor: Schema2.suspend(() => Query),
|
|
436
|
-
property: Schema2.String,
|
|
437
|
-
typename: TypenameSpecifier
|
|
438
|
-
});
|
|
439
|
-
var QueryIncomingReferencesClause = QueryIncomingReferencesClause_;
|
|
440
|
-
var QueryRelationClause_ = Schema2.Struct({
|
|
441
|
-
type: Schema2.Literal("relation"),
|
|
442
|
-
anchor: Schema2.suspend(() => Query),
|
|
443
|
-
/**
|
|
444
|
-
* outgoing: anchor is the source of the relation.
|
|
445
|
-
* incoming: anchor is the target of the relation.
|
|
446
|
-
* both: anchor is either the source or target of the relation.
|
|
447
|
-
*/
|
|
448
|
-
direction: Schema2.Literal("outgoing", "incoming", "both"),
|
|
449
|
-
filter: Schema2.optional(Schema2.suspend(() => Filter))
|
|
450
|
-
});
|
|
451
|
-
var QueryRelationClause = QueryRelationClause_;
|
|
452
|
-
var QueryRelationTraversalClause_ = Schema2.Struct({
|
|
453
|
-
type: Schema2.Literal("relation-traversal"),
|
|
454
|
-
anchor: Schema2.suspend(() => Query),
|
|
455
|
-
direction: Schema2.Literal("source", "target", "both")
|
|
456
|
-
});
|
|
457
|
-
var QueryRelationTraversalClause = QueryRelationTraversalClause_;
|
|
458
|
-
var QueryUnionClause_ = Schema2.Struct({
|
|
459
|
-
type: Schema2.Literal("union"),
|
|
460
|
-
queries: Schema2.Array(Schema2.suspend(() => Query))
|
|
461
|
-
});
|
|
462
|
-
var QueryUnionClause = QueryUnionClause_;
|
|
463
|
-
var QuerySetDifferenceClause_ = Schema2.Struct({
|
|
464
|
-
type: Schema2.Literal("set-difference"),
|
|
465
|
-
source: Schema2.suspend(() => Query),
|
|
466
|
-
exclude: Schema2.suspend(() => Query)
|
|
467
|
-
});
|
|
468
|
-
var QuerySetDifferenceClause = QuerySetDifferenceClause_;
|
|
469
|
-
var QueryOptionsClause_ = Schema2.Struct({
|
|
470
|
-
type: Schema2.Literal("options"),
|
|
471
|
-
query: Schema2.suspend(() => Query),
|
|
472
|
-
options: Schema2.suspend(() => QueryOptions)
|
|
473
|
-
});
|
|
474
|
-
var QueryOptionsClause = QueryOptionsClause_;
|
|
475
|
-
var Query_ = Schema2.Union(QuerySelectClause, QueryFilterClause, QueryReferenceTraversalClause, QueryIncomingReferencesClause, QueryRelationClause, QueryRelationTraversalClause, QueryUnionClause, QuerySetDifferenceClause, QueryOptionsClause);
|
|
476
|
-
var Query = Query_;
|
|
477
|
-
var QueryOptions = Schema2.Struct({
|
|
478
|
-
spaceIds: Schema2.optional(Schema2.Array(Schema2.String)),
|
|
479
|
-
deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only"))
|
|
480
|
-
});
|
|
481
|
-
var visit = (query, visitor) => {
|
|
482
|
-
switch (query.type) {
|
|
483
|
-
case "filter":
|
|
484
|
-
visit(query.selection, visitor);
|
|
485
|
-
break;
|
|
486
|
-
case "reference-traversal":
|
|
487
|
-
visit(query.anchor, visitor);
|
|
488
|
-
break;
|
|
489
|
-
case "incoming-references":
|
|
490
|
-
visit(query.anchor, visitor);
|
|
491
|
-
break;
|
|
492
|
-
case "relation":
|
|
493
|
-
visit(query.anchor, visitor);
|
|
494
|
-
break;
|
|
495
|
-
case "options":
|
|
496
|
-
visit(query.query, visitor);
|
|
497
|
-
break;
|
|
498
|
-
case "relation-traversal":
|
|
499
|
-
visit(query.anchor, visitor);
|
|
500
|
-
break;
|
|
501
|
-
case "union":
|
|
502
|
-
query.queries.forEach((q) => visit(q, visitor));
|
|
503
|
-
break;
|
|
504
|
-
case "set-difference":
|
|
505
|
-
visit(query.source, visitor);
|
|
506
|
-
visit(query.exclude, visitor);
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
};
|
|
510
|
-
export {
|
|
511
|
-
DATA_NAMESPACE,
|
|
512
|
-
DatabaseDirectory,
|
|
513
|
-
EncodedReference,
|
|
514
|
-
ForeignKey,
|
|
515
|
-
ObjectStructure,
|
|
516
|
-
PROPERTY_ID,
|
|
517
|
-
ast_exports as QueryAST,
|
|
518
|
-
REFERENCE_TYPE_TAG,
|
|
519
|
-
Reference,
|
|
520
|
-
SpaceDocVersion,
|
|
521
|
-
createIdFromSpaceKey,
|
|
522
|
-
decodeReference,
|
|
523
|
-
encodeReference,
|
|
524
|
-
isEncodedReference
|
|
525
|
-
};
|
|
526
|
-
//# sourceMappingURL=index.mjs.map
|