@dxos/echo 0.8.1 → 0.8.2-main.10c050d
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/README.md +116 -0
- package/dist/lib/browser/index.mjs +241 -32
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +243 -28
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +241 -32
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/Obj.d.ts +39 -0
- package/dist/types/src/Obj.d.ts.map +1 -0
- package/dist/types/src/Ref.d.ts +11 -0
- package/dist/types/src/Ref.d.ts.map +1 -0
- package/dist/types/src/Relation.d.ts +19 -0
- package/dist/types/src/Relation.d.ts.map +1 -0
- package/dist/types/src/Type.d.ts +80 -42
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/{Database.d.ts → experimental/database.d.ts} +1 -1
- package/dist/types/src/experimental/database.d.ts.map +1 -0
- package/dist/types/src/experimental/index.d.ts +1 -0
- package/dist/types/src/experimental/index.d.ts.map +1 -0
- package/dist/types/src/{Queue.d.ts → experimental/queue.d.ts} +1 -1
- package/dist/types/src/experimental/queue.d.ts.map +1 -0
- package/dist/types/src/{Space.d.ts → experimental/space.d.ts} +1 -1
- package/dist/types/src/experimental/space.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +5 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/{api.test.d.ts.map → test/api.test.d.ts.map} +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -15
- package/src/Obj.ts +86 -0
- package/src/Ref.ts +21 -0
- package/src/Relation.ts +45 -0
- package/src/Type.ts +103 -75
- package/src/{Database.ts → experimental/database.ts} +1 -1
- package/src/experimental/index.ts +7 -0
- package/src/{Queue.ts → experimental/queue.ts} +1 -1
- package/src/index.ts +6 -7
- package/src/test/api.test.ts +128 -0
- package/dist/types/src/Database.d.ts.map +0 -1
- package/dist/types/src/Queue.d.ts.map +0 -1
- package/dist/types/src/Space.d.ts.map +0 -1
- package/src/api.test.ts +0 -94
- /package/dist/types/src/{api.test.d.ts → test/api.test.d.ts} +0 -0
- /package/src/{Space.ts → experimental/space.ts} +0 -0
package/dist/lib/node/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,52 +17,265 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var node_exports = {};
|
|
20
30
|
__export(node_exports, {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
Filter: () => import_echo_schema3.Filter,
|
|
32
|
+
Obj: () => Obj_exports,
|
|
33
|
+
Query: () => import_echo_schema3.Query,
|
|
34
|
+
Ref: () => Ref_exports,
|
|
35
|
+
Relation: () => Relation_exports,
|
|
25
36
|
Type: () => Type_exports
|
|
26
37
|
});
|
|
27
38
|
module.exports = __toCommonJS(node_exports);
|
|
28
|
-
var
|
|
39
|
+
var EchoSchema = __toESM(require("@dxos/echo-schema"));
|
|
40
|
+
var import_invariant = require("@dxos/invariant");
|
|
29
41
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
30
|
-
var
|
|
42
|
+
var import_keys = require("@dxos/keys");
|
|
43
|
+
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
44
|
+
var import_effect = require("effect");
|
|
45
|
+
var EchoSchema2 = __toESM(require("@dxos/echo-schema"));
|
|
46
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
47
|
+
var LiveObject = __toESM(require("@dxos/live-object"));
|
|
48
|
+
var EchoSchema3 = __toESM(require("@dxos/echo-schema"));
|
|
49
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
50
|
+
var LiveObject2 = __toESM(require("@dxos/live-object"));
|
|
51
|
+
var EchoSchema4 = __toESM(require("@dxos/echo-schema"));
|
|
52
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
31
53
|
var __defProp2 = Object.defineProperty;
|
|
32
54
|
var __export2 = (target, all) => {
|
|
33
55
|
for (var name in all)
|
|
34
56
|
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
35
57
|
};
|
|
36
|
-
var Database_exports = {};
|
|
37
|
-
var Queue_exports = {};
|
|
38
|
-
var Space_exports = {};
|
|
39
58
|
var Type_exports = {};
|
|
40
59
|
__export2(Type_exports, {
|
|
60
|
+
DXN: () => import_keys.DXN,
|
|
61
|
+
Expando: () => import_echo_schema2.Expando,
|
|
62
|
+
Format: () => import_echo_schema2.Format,
|
|
63
|
+
JsonSchema: () => import_echo_schema2.JsonSchemaType,
|
|
41
64
|
Kind: () => import_echo_schema.EntityKind,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
getTypename: () =>
|
|
50
|
-
getVersion: () =>
|
|
51
|
-
|
|
52
|
-
|
|
65
|
+
Obj: () => Obj,
|
|
66
|
+
ObjectId: () => import_keys.ObjectId,
|
|
67
|
+
Ref: () => Ref2,
|
|
68
|
+
Relation: () => Relation,
|
|
69
|
+
SpaceId: () => import_keys.SpaceId,
|
|
70
|
+
getDXN: () => getDXN,
|
|
71
|
+
getMeta: () => getMeta,
|
|
72
|
+
getTypename: () => getTypename,
|
|
73
|
+
getVersion: () => getVersion,
|
|
74
|
+
isMutable: () => isMutable2,
|
|
75
|
+
toJsonSchema: () => import_echo_schema2.toJsonSchema
|
|
76
|
+
});
|
|
77
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo/src/Type.ts";
|
|
78
|
+
var Obj = EchoSchema.EchoObject;
|
|
79
|
+
var Relation = EchoSchema.EchoRelation;
|
|
80
|
+
var Ref2 = EchoSchema.Ref;
|
|
81
|
+
var getDXN = (schema) => {
|
|
82
|
+
return EchoSchema.getSchemaDXN(schema);
|
|
83
|
+
};
|
|
84
|
+
var getTypename = (schema) => {
|
|
85
|
+
const typename = EchoSchema.getSchemaTypename(schema);
|
|
86
|
+
(0, import_invariant.invariant)(typeof typename === "string" && !typename.startsWith("dxn:"), "Invalid typename", {
|
|
87
|
+
F: __dxlog_file,
|
|
88
|
+
L: 84,
|
|
89
|
+
S: void 0,
|
|
90
|
+
A: [
|
|
91
|
+
"typeof typename === 'string' && !typename.startsWith('dxn:')",
|
|
92
|
+
"'Invalid typename'"
|
|
93
|
+
]
|
|
94
|
+
});
|
|
95
|
+
return typename;
|
|
96
|
+
};
|
|
97
|
+
var getVersion = (schema) => {
|
|
98
|
+
const version = EchoSchema.getSchemaVersion(schema);
|
|
99
|
+
(0, import_invariant.invariant)(typeof version === "string" && version.match(/^\d+\.\d+\.\d+$/), "Invalid version", {
|
|
100
|
+
F: __dxlog_file,
|
|
101
|
+
L: 94,
|
|
102
|
+
S: void 0,
|
|
103
|
+
A: [
|
|
104
|
+
"typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/)",
|
|
105
|
+
"'Invalid version'"
|
|
106
|
+
]
|
|
107
|
+
});
|
|
108
|
+
return version;
|
|
109
|
+
};
|
|
110
|
+
var getMeta = (schema) => {
|
|
111
|
+
return EchoSchema.getTypeAnnotation(schema);
|
|
112
|
+
};
|
|
113
|
+
var isMutable2 = (schema) => {
|
|
114
|
+
return EchoSchema.isMutable(schema);
|
|
115
|
+
};
|
|
116
|
+
var Obj_exports = {};
|
|
117
|
+
__export2(Obj_exports, {
|
|
118
|
+
getDXN: () => getDXN3,
|
|
119
|
+
getMeta: () => getMeta3,
|
|
120
|
+
getSchema: () => getSchema2,
|
|
121
|
+
getSchemaDXN: () => getSchemaDXN2,
|
|
122
|
+
getTypename: () => getTypename3,
|
|
123
|
+
instanceOf: () => instanceOf,
|
|
124
|
+
isDeleted: () => isDeleted2,
|
|
125
|
+
isObject: () => isObject,
|
|
126
|
+
make: () => make
|
|
127
|
+
});
|
|
128
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo/src/Obj.ts";
|
|
129
|
+
var make = LiveObject.live;
|
|
130
|
+
var isObject = (obj) => {
|
|
131
|
+
return LiveObject.isLiveObject(obj);
|
|
132
|
+
};
|
|
133
|
+
var instanceOf = (...args) => {
|
|
134
|
+
if (args.length === 1) {
|
|
135
|
+
return (obj) => EchoSchema2.isInstanceOf(args[0], obj);
|
|
136
|
+
}
|
|
137
|
+
return EchoSchema2.isInstanceOf(args[0], args[1]);
|
|
138
|
+
};
|
|
139
|
+
var getSchema2 = EchoSchema2.getSchema;
|
|
140
|
+
var getDXN3 = (obj) => {
|
|
141
|
+
(0, import_invariant2.assertArgument)(!import_effect.Schema.isSchema(obj), "Object should not be a schema.");
|
|
142
|
+
const dxn = EchoSchema2.getDXN(obj);
|
|
143
|
+
(0, import_invariant2.invariant)(dxn != null, "Invalid object.", {
|
|
144
|
+
F: __dxlog_file2,
|
|
145
|
+
L: 48,
|
|
146
|
+
S: void 0,
|
|
147
|
+
A: [
|
|
148
|
+
"dxn != null",
|
|
149
|
+
"'Invalid object.'"
|
|
150
|
+
]
|
|
151
|
+
});
|
|
152
|
+
return dxn;
|
|
153
|
+
};
|
|
154
|
+
var getSchemaDXN2 = (obj) => {
|
|
155
|
+
const type = EchoSchema2.getType(obj);
|
|
156
|
+
(0, import_invariant2.invariant)(type != null, "Invalid object.", {
|
|
157
|
+
F: __dxlog_file2,
|
|
158
|
+
L: 58,
|
|
159
|
+
S: void 0,
|
|
160
|
+
A: [
|
|
161
|
+
"type != null",
|
|
162
|
+
"'Invalid object.'"
|
|
163
|
+
]
|
|
164
|
+
});
|
|
165
|
+
return type;
|
|
166
|
+
};
|
|
167
|
+
var getTypename3 = (obj) => {
|
|
168
|
+
const schema = getSchema2(obj);
|
|
169
|
+
if (schema == null) {
|
|
170
|
+
return getSchemaDXN2(obj)?.asTypeDXN()?.type;
|
|
171
|
+
}
|
|
172
|
+
return EchoSchema2.getTypename(schema);
|
|
173
|
+
};
|
|
174
|
+
var getMeta3 = (obj) => {
|
|
175
|
+
const meta = EchoSchema2.getMeta(obj);
|
|
176
|
+
(0, import_invariant2.invariant)(meta != null, "Invalid object.", {
|
|
177
|
+
F: __dxlog_file2,
|
|
178
|
+
L: 78,
|
|
179
|
+
S: void 0,
|
|
180
|
+
A: [
|
|
181
|
+
"meta != null",
|
|
182
|
+
"'Invalid object.'"
|
|
183
|
+
]
|
|
184
|
+
});
|
|
185
|
+
return meta;
|
|
186
|
+
};
|
|
187
|
+
var isDeleted2 = (obj) => {
|
|
188
|
+
const deleted = EchoSchema2.isDeleted(obj);
|
|
189
|
+
(0, import_invariant2.invariant)(typeof deleted === "boolean", "Invalid object.", {
|
|
190
|
+
F: __dxlog_file2,
|
|
191
|
+
L: 84,
|
|
192
|
+
S: void 0,
|
|
193
|
+
A: [
|
|
194
|
+
"typeof deleted === 'boolean'",
|
|
195
|
+
"'Invalid object.'"
|
|
196
|
+
]
|
|
197
|
+
});
|
|
198
|
+
return deleted;
|
|
199
|
+
};
|
|
200
|
+
var Relation_exports = {};
|
|
201
|
+
__export2(Relation_exports, {
|
|
202
|
+
getSource: () => getSource,
|
|
203
|
+
getTarget: () => getTarget,
|
|
204
|
+
isRelation: () => isRelation,
|
|
205
|
+
make: () => make2
|
|
206
|
+
});
|
|
207
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo/src/Relation.ts";
|
|
208
|
+
var make2 = LiveObject2.live;
|
|
209
|
+
var isRelation = (value) => {
|
|
210
|
+
if (typeof value !== "object" || value === null) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
if (EchoSchema3.ATTR_RELATION_SOURCE in value || EchoSchema3.ATTR_RELATION_TARGET in value) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
const kind = value[EchoSchema3.EntityKindPropertyId];
|
|
217
|
+
return kind === EchoSchema3.EntityKind.Relation;
|
|
218
|
+
};
|
|
219
|
+
var getSource = (relation) => {
|
|
220
|
+
(0, import_invariant3.invariant)(isRelation(relation), void 0, {
|
|
221
|
+
F: __dxlog_file3,
|
|
222
|
+
L: 30,
|
|
223
|
+
S: void 0,
|
|
224
|
+
A: [
|
|
225
|
+
"isRelation(relation)",
|
|
226
|
+
""
|
|
227
|
+
]
|
|
228
|
+
});
|
|
229
|
+
const obj = relation[EchoSchema3.RelationSourceId];
|
|
230
|
+
(0, import_invariant3.invariant)(obj !== void 0, `Invalid source: ${relation.id}`, {
|
|
231
|
+
F: __dxlog_file3,
|
|
232
|
+
L: 32,
|
|
233
|
+
S: void 0,
|
|
234
|
+
A: [
|
|
235
|
+
"obj !== undefined",
|
|
236
|
+
"`Invalid source: ${relation.id}`"
|
|
237
|
+
]
|
|
238
|
+
});
|
|
239
|
+
return obj;
|
|
240
|
+
};
|
|
241
|
+
var getTarget = (relation) => {
|
|
242
|
+
(0, import_invariant3.invariant)(isRelation(relation), void 0, {
|
|
243
|
+
F: __dxlog_file3,
|
|
244
|
+
L: 41,
|
|
245
|
+
S: void 0,
|
|
246
|
+
A: [
|
|
247
|
+
"isRelation(relation)",
|
|
248
|
+
""
|
|
249
|
+
]
|
|
250
|
+
});
|
|
251
|
+
const obj = relation[EchoSchema3.RelationTargetId];
|
|
252
|
+
(0, import_invariant3.invariant)(obj !== void 0, `Invalid target: ${relation.id}`, {
|
|
253
|
+
F: __dxlog_file3,
|
|
254
|
+
L: 43,
|
|
255
|
+
S: void 0,
|
|
256
|
+
A: [
|
|
257
|
+
"obj !== undefined",
|
|
258
|
+
"`Invalid target: ${relation.id}`"
|
|
259
|
+
]
|
|
260
|
+
});
|
|
261
|
+
return obj;
|
|
262
|
+
};
|
|
263
|
+
var Ref_exports = {};
|
|
264
|
+
__export2(Ref_exports, {
|
|
265
|
+
fromDXN: () => fromDXN,
|
|
266
|
+
isRef: () => isRef,
|
|
267
|
+
make: () => make3
|
|
53
268
|
});
|
|
54
|
-
var
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
var Ref = (self) => (0, import_echo_schema.Ref)(self);
|
|
269
|
+
var make3 = EchoSchema4.Ref.make;
|
|
270
|
+
var isRef = EchoSchema4.Ref.isRef;
|
|
271
|
+
var fromDXN = EchoSchema4.Ref.fromDXN;
|
|
58
272
|
// Annotate the CommonJS export names for ESM import in node:
|
|
59
273
|
0 && (module.exports = {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
274
|
+
Filter,
|
|
275
|
+
Obj,
|
|
276
|
+
Query,
|
|
277
|
+
Ref,
|
|
278
|
+
Relation,
|
|
64
279
|
Type
|
|
65
280
|
});
|
|
66
281
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport {
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../src/Type.ts", "../../../src/Obj.ts", "../../../src/Relation.ts", "../../../src/Ref.ts", "../../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\n\nimport type { EncodedReference } from '@dxos/echo-protocol';\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport type * as Keys from '@dxos/keys';\n\n/**\n * ECHO schema.\n */\nexport type Schema = EchoSchema.EchoSchema;\n\n/**\n * EchoObject schema.\n */\nexport const Obj = EchoSchema.EchoObject;\n\n/**\n * EchoRelation schema.\n */\nexport const Relation = EchoSchema.EchoRelation;\n\n/**\n * Ref schema.\n */\nexport const Ref: <S extends Obj.Any>(schema: S) => EchoSchema.Ref$<Schema.Schema.Type<S>> = EchoSchema.Ref;\n\nexport namespace Obj {\n /**\n * Type that represents an arbitrary schema type of an object.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n}\n\nexport namespace Relation {\n /**\n * Type that represents an arbitrary schema type of a relation.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n\n /**\n * Get relation target type.\n */\n export type Target<A> = A extends EchoSchema.RelationSourceTargetRefs<infer T, infer _S> ? T : never;\n\n /**\n * Get relation source type.\n */\n export type Source<A> = A extends EchoSchema.RelationSourceTargetRefs<infer _T, infer S> ? S : never;\n}\n\nexport namespace Ref {\n /**\n * Type that represents an arbitrary schema type of a reference.\n * NOTE: This is not an instance type.\n */\n export type Any = Schema.Schema<EchoSchema.Ref<any>, EncodedReference>;\n}\n\n/**\n * Gets the full DXN of the schema.\n * Will include the version if it's a `type` DXN.\n * @example \"dxn:example.com/type/Person:0.1.0\"\n * @example \"dxn:echo:SSSSSSSSSS:XXXXXXXXXXXXX\"\n */\nexport const getDXN = (schema: Obj.Any | Relation.Any): Keys.DXN | undefined => {\n return EchoSchema.getSchemaDXN(schema);\n};\n\n/**\n * @param schema - Schema to get the typename from.\n * @returns The typename of the schema. Example: `example.com/type/Person`.\n */\nexport const getTypename = (schema: Obj.Any | Relation.Any): string => {\n const typename = EchoSchema.getSchemaTypename(schema);\n invariant(typeof typename === 'string' && !typename.startsWith('dxn:'), 'Invalid typename');\n return typename;\n};\n\n/**\n * Gets the version of the schema.\n * @example 0.1.0\n */\nexport const getVersion = (schema: Obj.Any | Relation.Any): string => {\n const version = EchoSchema.getSchemaVersion(schema);\n invariant(typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/), 'Invalid version');\n return version;\n};\n\n/**\n * ECHO type metadata.\n */\nexport type Meta = EchoSchema.TypeAnnotation;\n\n/**\n * Gets the meta data of the schema.\n */\nexport const getMeta = (schema: Obj.Any | Relation.Any): Meta | undefined => {\n return EchoSchema.getTypeAnnotation(schema);\n};\n\nexport { EntityKind as Kind } from '@dxos/echo-schema';\n\n/**\n * @returns True if the schema is mutable.\n */\nexport const isMutable = (schema: Obj.Any | Relation.Any): boolean => {\n return EchoSchema.isMutable(schema);\n};\n\nexport { SpaceId, ObjectId, DXN } from '@dxos/keys';\n\nexport {\n //\n Expando,\n JsonSchemaType as JsonSchema,\n toJsonSchema,\n Format,\n} from '@dxos/echo-schema';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport type { DXN } from '@dxos/keys';\nimport * as LiveObject from '@dxos/live-object';\n\nimport type * as Type from './Type';\n\nexport type Any = EchoSchema.AnyEchoObject;\n\nexport const make = LiveObject.live;\n\n// TODO(dmaretskyi): Currently broken\nexport const isObject = (obj: unknown): obj is Any => {\n return LiveObject.isLiveObject(obj);\n};\n\n/**\n * Check that object or relation is an instance of a schema.\n * @example\n * ```ts\n * const person = Obj.make(Person, { name: 'John' });\n * const isPerson = Obj.instanceOf(Person);\n * isPerson(person); // true\n * ```\n */\nexport const instanceOf: {\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S): (value: unknown) => value is S;\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S, value: unknown): value is S;\n} = ((...args: any[]) => {\n if (args.length === 1) {\n return (obj: unknown) => EchoSchema.isInstanceOf(args[0], obj);\n }\n\n return EchoSchema.isInstanceOf(args[0], args[1]);\n}) as any;\n\nexport const getSchema = EchoSchema.getSchema;\n\nexport const getDXN = (obj: Any): DXN => {\n assertArgument(!Schema.isSchema(obj), 'Object should not be a schema.');\n const dxn = EchoSchema.getDXN(obj);\n invariant(dxn != null, 'Invalid object.');\n return dxn;\n};\n\n/**\n * @returns The DXN of the object's type.\n * @example dxn:example.com/type/Contact:1.0.0\n */\nexport const getSchemaDXN = (obj: Any): DXN => {\n const type = EchoSchema.getType(obj);\n invariant(type != null, 'Invalid object.');\n return type;\n};\n\n/**\n * @returns The typename of the object's type.\n * @example `example.com/type/Contact`\n */\nexport const getTypename = (obj: Any): string | undefined => {\n const schema = getSchema(obj);\n if (schema == null) {\n // Try to extract typename from DXN.\n return getSchemaDXN(obj)?.asTypeDXN()?.type;\n }\n\n return EchoSchema.getTypename(schema);\n};\n\nexport const getMeta = (obj: Any): EchoSchema.ObjectMeta => {\n const meta = EchoSchema.getMeta(obj);\n invariant(meta != null, 'Invalid object.');\n return meta;\n};\n\nexport const isDeleted = (obj: Any): boolean => {\n const deleted = EchoSchema.isDeleted(obj);\n invariant(typeof deleted === 'boolean', 'Invalid object.');\n return deleted;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport * as LiveObject from '@dxos/live-object';\n\nexport type Any = EchoSchema.AnyEchoObject & EchoSchema.RelationSourceTargetRefs;\n\nexport const make = LiveObject.live;\n\nexport const isRelation = (value: unknown): value is Any => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n if (EchoSchema.ATTR_RELATION_SOURCE in value || EchoSchema.ATTR_RELATION_TARGET in value) {\n return true;\n }\n\n const kind = (value as any)[EchoSchema.EntityKindPropertyId];\n return kind === EchoSchema.EntityKind.Relation;\n};\n\n/**\n * @returns Relation source.\n * @throws If the object is not a relation.\n */\nexport const getSource = <T extends Any>(relation: T): EchoSchema.RelationSource<T> => {\n invariant(isRelation(relation));\n const obj = relation[EchoSchema.RelationSourceId];\n invariant(obj !== undefined, `Invalid source: ${relation.id}`);\n return obj;\n};\n\n/**\n * @returns Relation target.\n * @throws If the object is not a relation.\n */\nexport const getTarget = <T extends Any>(relation: T): EchoSchema.RelationTarget<T> => {\n invariant(isRelation(relation));\n const obj = relation[EchoSchema.RelationTargetId];\n invariant(obj !== undefined, `Invalid target: ${relation.id}`);\n return obj;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\n\nimport type * as Obj from './Obj';\n\nexport type Any = EchoSchema.Ref<Obj.Any>;\n\nexport const make = EchoSchema.Ref.make;\n\nexport const isRef: (value: unknown) => value is Any = EchoSchema.Ref.isRef;\n\n// TODO(dmaretskyi): Consider just allowing `make` to accept DXN.\nexport const fromDXN = EchoSchema.Ref.fromDXN;\n\n/**\n * Extract reference target.\n */\nexport type Target<R extends Any> = R extends EchoSchema.Ref<infer T> ? T : never;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nexport * as Type from './Type';\nexport * as Obj from './Obj';\nexport * as Relation from './Relation';\nexport * as Ref from './Ref';\n\nexport { type Live } from '@dxos/live-object';\nexport { Filter, Query } from '@dxos/echo-schema';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;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AUO,IAAMA,QAAkBC,YAAAA;AAExB,IAAMiB,aAAa,CAACC,UAAAA;AACzB,MAAI,OAAOA,UAAU,YAAYA,UAAU,MAAM;AAC/C,WAAO;EACT;AACA,MAAeC,YAAAA,wBAAwBD,SAAoBE,YAAAA,wBAAwBF,OAAO;AACxF,WAAO;EACT;AAEA,QAAMG,OAAQH,MAAyBI,YAAAA,oBAAoB;AAC3D,SAAOD,SAAoBE,YAAAA,WAAW1C;AACxC;AAMO,IAAM2C,YAAY,CAAgBC,aAAAA;AACvCpC,wBAAAA,WAAU4B,WAAWQ,QAAAA,GAAAA,QAAAA;;;;;;;;;AACrB,QAAMvB,MAAMuB,SAAoBC,YAAAA,gBAAgB;AAChDrC,wBAAAA,WAAUa,QAAQyB,QAAW,mBAAmBF,SAASG,EAAE,IAAE;;;;;;;;;AAC7D,SAAO1B;AACT;AAMO,IAAM2B,YAAY,CAAgBJ,aAAAA;AACvCpC,wBAAAA,WAAU4B,WAAWQ,QAAAA,GAAAA,QAAAA;;;;;;;;;AACrB,QAAMvB,MAAMuB,SAAoBK,YAAAA,gBAAgB;AAChDzC,wBAAAA,WAAUa,QAAQyB,QAAW,mBAAmBF,SAASG,EAAE,IAAE;;;;;;;;;AAC7D,SAAO1B;AACT;AC5CA,IAAA,cAAA,CAAA;;;;cAAAH;;AAUO,IAAMA,QAAkBtB,YAAAA,IAAIsB;AAE5B,IAAMgC,QAAqDtD,YAAAA,IAAIsD;AAG/D,IAAMC,UAAqBvD,YAAAA,IAAIuD;",
|
|
6
|
+
"names": ["import_echo_schema", "import_invariant", "Ref", "isMutable", "Obj", "EchoObject", "Relation", "EchoRelation", "getDXN", "schema", "getSchemaDXN", "getTypename", "typename", "getSchemaTypename", "invariant", "startsWith", "getVersion", "version", "getSchemaVersion", "match", "getMeta", "getTypeAnnotation", "getSchema", "isDeleted", "make", "live", "isObject", "obj", "isLiveObject", "instanceOf", "args", "length", "isInstanceOf", "assertArgument", "Schema", "isSchema", "dxn", "type", "getType", "asTypeDXN", "meta", "deleted", "isRelation", "value", "ATTR_RELATION_SOURCE", "ATTR_RELATION_TARGET", "kind", "EntityKindPropertyId", "EntityKind", "getSource", "relation", "RelationSourceId", "undefined", "id", "getTarget", "RelationTargetId", "isRef", "fromDXN"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo/src/
|
|
1
|
+
{"inputs":{"packages/core/echo/echo/src/Type.ts":{"bytes":8839,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Obj.ts":{"bytes":8124,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Relation.ts":{"bytes":5369,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Ref.ts":{"bytes":1595,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/index.ts":{"bytes":1162,"imports":[{"path":"packages/core/echo/echo/src/Type.ts","kind":"import-statement","original":"./Type"},{"path":"packages/core/echo/echo/src/Obj.ts","kind":"import-statement","original":"./Obj"},{"path":"packages/core/echo/echo/src/Relation.ts","kind":"import-statement","original":"./Relation"},{"path":"packages/core/echo/echo/src/Ref.ts","kind":"import-statement","original":"./Ref"},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"packages/core/echo/echo/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12153},"packages/core/echo/echo/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["Filter","Obj","Query","Ref","Relation","Type"],"entryPoint":"packages/core/echo/echo/src/index.ts","inputs":{"packages/core/echo/echo/src/Type.ts":{"bytesInOutput":1927},"packages/core/echo/echo/src/index.ts":{"bytesInOutput":51},"packages/core/echo/echo/src/Obj.ts":{"bytesInOutput":2226},"packages/core/echo/echo/src/Relation.ts":{"bytesInOutput":1700},"packages/core/echo/echo/src/Ref.ts":{"bytesInOutput":276}},"bytes":6715}}}
|