@dxos/echo 0.8.4-main.406dc2a → 0.8.4-main.548089c
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/chunk-3FCPYTWA.mjs +585 -0
- package/dist/lib/browser/chunk-3FCPYTWA.mjs.map +7 -0
- package/dist/lib/browser/{chunk-MB6MMNFP.mjs → chunk-5BNXQE6S.mjs} +106 -236
- package/dist/lib/browser/chunk-5BNXQE6S.mjs.map +7 -0
- package/dist/lib/browser/chunk-U43CXUCL.mjs +410 -0
- package/dist/lib/browser/chunk-U43CXUCL.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +9 -9
- package/dist/lib/browser/internal/index.mjs +5 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/query/index.mjs +4 -6
- package/dist/lib/browser/testing/index.mjs +32 -63
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-BQRA4VLX.mjs → chunk-3FGSPSYN.mjs} +106 -236
- package/dist/lib/node-esm/chunk-3FGSPSYN.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-C7LTTWRL.mjs +585 -0
- package/dist/lib/node-esm/chunk-C7LTTWRL.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-OHJ5WBB6.mjs +410 -0
- package/dist/lib/node-esm/chunk-OHJ5WBB6.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +9 -9
- package/dist/lib/node-esm/internal/index.mjs +5 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/query/index.mjs +4 -6
- package/dist/lib/node-esm/testing/index.mjs +32 -63
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/Obj.d.ts +4 -2
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/{query/tag.d.ts → Tag.d.ts} +7 -7
- package/dist/types/src/Tag.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts +8 -16
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/ast/annotations.d.ts +6 -0
- package/dist/types/src/internal/ast/annotations.d.ts.map +1 -1
- package/dist/types/src/internal/index.d.ts +2 -2
- package/dist/types/src/internal/index.d.ts.map +1 -1
- package/dist/types/src/internal/object/create.d.ts +1 -1
- package/dist/types/src/internal/object/typename.d.ts +1 -1
- package/dist/types/src/internal/testing/types.d.ts +5 -79
- package/dist/types/src/internal/testing/types.d.ts.map +1 -1
- package/dist/types/src/query/index.d.ts +0 -1
- package/dist/types/src/query/index.d.ts.map +1 -1
- package/dist/types/src/testing/types.d.ts +161 -46
- package/dist/types/src/testing/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/src/Obj.ts +21 -2
- package/src/{query/tag.ts → Tag.ts} +8 -6
- package/src/index.ts +1 -0
- package/src/internal/ast/annotations.ts +7 -0
- package/src/internal/index.ts +2 -2
- package/src/internal/json/json-schema.test.ts +27 -35
- package/src/internal/object/create.test.ts +11 -11
- package/src/internal/object/create.ts +1 -1
- package/src/internal/object/json-serializer.test.ts +11 -11
- package/src/internal/object/typename.ts +1 -1
- package/src/internal/proxy/typed-handler.test.ts +7 -7
- package/src/internal/proxy/typed-object.test.ts +1 -1
- package/src/internal/ref/ref.test.ts +1 -1
- package/src/internal/testing/types.ts +10 -77
- package/src/internal/testing/utils.ts +1 -1
- package/src/query/index.ts +1 -1
- package/src/testing/types.ts +39 -22
- package/dist/lib/browser/chunk-HKFCK2GL.mjs +0 -175
- package/dist/lib/browser/chunk-HKFCK2GL.mjs.map +0 -7
- package/dist/lib/browser/chunk-MAAYELT7.mjs +0 -830
- package/dist/lib/browser/chunk-MAAYELT7.mjs.map +0 -7
- package/dist/lib/browser/chunk-MB6MMNFP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-5NWDGIBT.mjs +0 -830
- package/dist/lib/node-esm/chunk-5NWDGIBT.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AUAH4E2J.mjs +0 -175
- package/dist/lib/node-esm/chunk-AUAH4E2J.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BQRA4VLX.mjs.map +0 -7
- package/dist/types/src/query/tag.d.ts.map +0 -1
|
@@ -4,10 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { EchoObject, EchoRelation,
|
|
7
|
+
import { EchoObject, EchoRelation, TypedObject } from '../object';
|
|
8
8
|
import { Ref, type Ref$ } from '../ref';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated
|
|
12
|
+
*/
|
|
13
|
+
// TOOD(burdon): Reconcile with ../testing (remove this).
|
|
11
14
|
export namespace Testing {
|
|
12
15
|
//
|
|
13
16
|
// Primitives
|
|
@@ -89,8 +92,8 @@ export namespace Testing {
|
|
|
89
92
|
|
|
90
93
|
export type TestSchemaWithClass = Schema.Schema.Type<typeof TestSchemaWithClass>;
|
|
91
94
|
|
|
92
|
-
export class
|
|
93
|
-
typename: 'example.com/type/
|
|
95
|
+
export class Person extends TypedObject({
|
|
96
|
+
typename: 'example.com/type/Person',
|
|
94
97
|
version: '0.1.0',
|
|
95
98
|
})(
|
|
96
99
|
{
|
|
@@ -119,7 +122,7 @@ export namespace Testing {
|
|
|
119
122
|
{
|
|
120
123
|
title: Schema.optional(Schema.String),
|
|
121
124
|
completed: Schema.optional(Schema.Boolean),
|
|
122
|
-
assignee: Schema.optional(Ref(
|
|
125
|
+
assignee: Schema.optional(Ref(Person)),
|
|
123
126
|
previous: Schema.optional(Schema.suspend((): Ref$<Task> => Ref(Task))),
|
|
124
127
|
subTasks: Schema.optional(Schema.mutable(Schema.Array(Schema.suspend((): Ref$<Task> => Ref(Task))))),
|
|
125
128
|
description: Schema.optional(Schema.String),
|
|
@@ -127,84 +130,14 @@ export namespace Testing {
|
|
|
127
130
|
{ partial: true },
|
|
128
131
|
) {}
|
|
129
132
|
|
|
130
|
-
// TOOD(burdon): Ref$ breaks if using new syntax (since ID is not declared).
|
|
131
|
-
|
|
132
|
-
// export const Task = Schema.Struct({
|
|
133
|
-
// title: Schema.String,
|
|
134
|
-
// completed: Schema.Boolean,
|
|
135
|
-
// assignee: Schema.optional(Ref(Schema.suspend((): Ref$<Contact> => Ref(Contact)))),
|
|
136
|
-
// previous: Schema.optional(Ref(Schema.suspend((): Ref$<Task> => Ref(Task)))),
|
|
137
|
-
// subTasks: Schema.optional(Schema.Array(Ref(Schema.suspend((): Ref$<Task> => Ref(Task))))),
|
|
138
|
-
// description: Schema.optional(Schema.String),
|
|
139
|
-
// }).pipe(
|
|
140
|
-
// EchoObject({
|
|
141
|
-
// typename: 'example.com/type/Task',
|
|
142
|
-
// version: '0.1.0',
|
|
143
|
-
// }),
|
|
144
|
-
// );
|
|
145
|
-
|
|
146
|
-
// export type Task = Schema.Schema.Type<typeof Task>;
|
|
147
|
-
|
|
148
|
-
// export const Contact = Schema.Struct({
|
|
149
|
-
// name: Schema.String,
|
|
150
|
-
// username: Schema.String,
|
|
151
|
-
// email: Schema.String,
|
|
152
|
-
// // TOOD(burdon): Should model via relations?
|
|
153
|
-
// // tasks: Schema.mutable(Schema.Array(Ref(Task))),
|
|
154
|
-
// address: Schema.Struct({
|
|
155
|
-
// city: Schema.optional(Schema.String),
|
|
156
|
-
// state: Schema.optional(Schema.String),
|
|
157
|
-
// zip: Schema.optional(Schema.String),
|
|
158
|
-
// coordinates: Schema.Struct({
|
|
159
|
-
// lat: Schema.optional(Schema.Number),
|
|
160
|
-
// lng: Schema.optional(Schema.Number),
|
|
161
|
-
// }),
|
|
162
|
-
// }),
|
|
163
|
-
// }).pipe(
|
|
164
|
-
// EchoObject({
|
|
165
|
-
// typename: 'example.com/type/Contact',
|
|
166
|
-
// version: '0.1.0',
|
|
167
|
-
// }),
|
|
168
|
-
// );
|
|
169
|
-
|
|
170
|
-
// export type Contact = Schema.Schema.Type<typeof Contact>;
|
|
171
|
-
|
|
172
|
-
export enum RecordType {
|
|
173
|
-
UNDEFINED = 0,
|
|
174
|
-
PERSONAL = 1,
|
|
175
|
-
WORK = 2,
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export class Container extends TypedObject({
|
|
179
|
-
typename: 'example.com/type/Container',
|
|
180
|
-
version: '0.1.0',
|
|
181
|
-
})(
|
|
182
|
-
{
|
|
183
|
-
objects: Schema.mutable(Schema.Array(Ref(Expando))),
|
|
184
|
-
records: Schema.mutable(
|
|
185
|
-
Schema.Array(
|
|
186
|
-
Schema.partial(
|
|
187
|
-
Schema.Struct({
|
|
188
|
-
title: Schema.String,
|
|
189
|
-
description: Schema.String,
|
|
190
|
-
contacts: Schema.mutable(Schema.Array(Ref(Contact))),
|
|
191
|
-
type: Schema.Enums(RecordType),
|
|
192
|
-
}),
|
|
193
|
-
),
|
|
194
|
-
),
|
|
195
|
-
),
|
|
196
|
-
},
|
|
197
|
-
{ partial: true },
|
|
198
|
-
) {}
|
|
199
|
-
|
|
200
133
|
export const HasManager = Schema.Struct({
|
|
201
134
|
since: Schema.optional(Schema.String),
|
|
202
135
|
}).pipe(
|
|
203
136
|
EchoRelation({
|
|
204
137
|
typename: 'example.com/type/HasManager',
|
|
205
138
|
version: '0.1.0',
|
|
206
|
-
source:
|
|
207
|
-
target:
|
|
139
|
+
source: Person,
|
|
140
|
+
target: Person,
|
|
208
141
|
}),
|
|
209
142
|
);
|
|
210
143
|
export interface HasManager extends Schema.Schema.Type<typeof HasManager> {}
|
|
@@ -31,7 +31,7 @@ export const updateCounter = (touch: () => void) => {
|
|
|
31
31
|
* Converts AST to a format that can be compared with test matchers.
|
|
32
32
|
*/
|
|
33
33
|
export const prepareAstForCompare = (obj: SchemaAST.AST): any =>
|
|
34
|
-
deepMapValues(obj, (value: any, recurse
|
|
34
|
+
deepMapValues(obj, (value: any, recurse) => {
|
|
35
35
|
if (typeof value === 'function') {
|
|
36
36
|
return null;
|
|
37
37
|
}
|
package/src/query/index.ts
CHANGED
package/src/testing/types.ts
CHANGED
|
@@ -6,9 +6,12 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
|
|
7
7
|
import { Type } from '..';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated
|
|
11
|
+
*/
|
|
12
|
+
// TOOD(burdon): Reconcile with @dxos/schema.
|
|
10
13
|
export namespace Testing {
|
|
11
|
-
const
|
|
14
|
+
export const Person = Schema.Struct({
|
|
12
15
|
name: Schema.String,
|
|
13
16
|
username: Schema.String,
|
|
14
17
|
email: Schema.String,
|
|
@@ -25,17 +28,17 @@ export namespace Testing {
|
|
|
25
28
|
}).pipe(
|
|
26
29
|
Schema.partial,
|
|
27
30
|
Type.Obj({
|
|
28
|
-
typename: 'example.com/type/
|
|
31
|
+
typename: 'example.com/type/Person',
|
|
29
32
|
version: '0.1.0',
|
|
30
33
|
}),
|
|
31
34
|
);
|
|
32
|
-
export interface Contact extends Schema.Schema.Type<typeof _Contact> {}
|
|
33
|
-
export const Contact: Schema.Schema<Contact, Schema.Schema.Encoded<typeof _Contact>, never> = _Contact;
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
export interface Person extends Schema.Schema.Type<typeof Person> {}
|
|
37
|
+
|
|
38
|
+
export const Task = Schema.Struct({
|
|
36
39
|
title: Schema.optional(Schema.String),
|
|
37
40
|
completed: Schema.optional(Schema.Boolean),
|
|
38
|
-
assignee: Schema.optional(Type.Ref(
|
|
41
|
+
assignee: Schema.optional(Type.Ref(Person)),
|
|
39
42
|
previous: Schema.optional(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task))),
|
|
40
43
|
subTasks: Schema.optional(Schema.mutable(Schema.Array(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task))))),
|
|
41
44
|
description: Schema.optional(Schema.String),
|
|
@@ -46,8 +49,34 @@ export namespace Testing {
|
|
|
46
49
|
version: '0.1.0',
|
|
47
50
|
}),
|
|
48
51
|
);
|
|
49
|
-
|
|
50
|
-
export
|
|
52
|
+
|
|
53
|
+
export interface Task extends Schema.Schema.Type<typeof Task> {}
|
|
54
|
+
|
|
55
|
+
export const WorksFor = Schema.Struct({
|
|
56
|
+
since: Schema.optional(Schema.String),
|
|
57
|
+
}).pipe(
|
|
58
|
+
Type.Relation({
|
|
59
|
+
typename: 'example.com/type/WorksFor',
|
|
60
|
+
version: '0.1.0',
|
|
61
|
+
source: Person,
|
|
62
|
+
target: Person,
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
export interface WorksFor extends Schema.Schema.Type<typeof WorksFor> {}
|
|
67
|
+
|
|
68
|
+
export const HasManager = Schema.Struct({
|
|
69
|
+
since: Schema.optional(Schema.String),
|
|
70
|
+
}).pipe(
|
|
71
|
+
Type.Relation({
|
|
72
|
+
typename: 'example.com/type/HasManager',
|
|
73
|
+
version: '0.1.0',
|
|
74
|
+
source: Person,
|
|
75
|
+
target: Person,
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export interface HasManager extends Schema.Schema.Type<typeof HasManager> {}
|
|
51
80
|
|
|
52
81
|
export enum RecordType {
|
|
53
82
|
UNDEFINED = 0,
|
|
@@ -63,7 +92,7 @@ export namespace Testing {
|
|
|
63
92
|
Schema.Struct({
|
|
64
93
|
title: Schema.String,
|
|
65
94
|
description: Schema.String,
|
|
66
|
-
contacts: Schema.mutable(Schema.Array(Type.Ref(
|
|
95
|
+
contacts: Schema.mutable(Schema.Array(Type.Ref(Person))),
|
|
67
96
|
type: Schema.Enums(RecordType),
|
|
68
97
|
}),
|
|
69
98
|
),
|
|
@@ -76,16 +105,4 @@ export namespace Testing {
|
|
|
76
105
|
version: '0.1.0',
|
|
77
106
|
}),
|
|
78
107
|
);
|
|
79
|
-
|
|
80
|
-
export const WorksFor = Schema.Struct({
|
|
81
|
-
since: Schema.optional(Schema.String),
|
|
82
|
-
}).pipe(
|
|
83
|
-
Type.Relation({
|
|
84
|
-
typename: 'example.com/type/WorksFor',
|
|
85
|
-
version: '0.1.0',
|
|
86
|
-
source: Contact,
|
|
87
|
-
target: Contact,
|
|
88
|
-
}),
|
|
89
|
-
);
|
|
90
|
-
export interface WorksFor extends Schema.Schema.Type<typeof WorksFor> {}
|
|
91
108
|
}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import "@dxos/node-std/globals";
|
|
2
|
-
import {
|
|
3
|
-
Any,
|
|
4
|
-
Relation
|
|
5
|
-
} from "./chunk-MAAYELT7.mjs";
|
|
6
|
-
import {
|
|
7
|
-
ATTR_RELATION_SOURCE,
|
|
8
|
-
ATTR_RELATION_TARGET,
|
|
9
|
-
EntityKind,
|
|
10
|
-
EntityKindId,
|
|
11
|
-
MetaId,
|
|
12
|
-
RelationSourceDXNId,
|
|
13
|
-
RelationSourceId,
|
|
14
|
-
RelationTargetDXNId,
|
|
15
|
-
RelationTargetId,
|
|
16
|
-
__export,
|
|
17
|
-
getObjectDXN,
|
|
18
|
-
getTypeAnnotation,
|
|
19
|
-
live
|
|
20
|
-
} from "./chunk-MB6MMNFP.mjs";
|
|
21
|
-
|
|
22
|
-
// src/errors.ts
|
|
23
|
-
import { BaseError } from "@dxos/errors";
|
|
24
|
-
var SchemaNotFoundError = class extends BaseError.extend("SCHEMA_NOT_FOUND", "Schema not found") {
|
|
25
|
-
constructor(schema, options) {
|
|
26
|
-
super({
|
|
27
|
-
context: {
|
|
28
|
-
schema
|
|
29
|
-
},
|
|
30
|
-
...options
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var ObjectNotFoundError = class extends BaseError.extend("OBJECT_NOT_FOUND", "Object not found") {
|
|
35
|
-
constructor(dxn, options) {
|
|
36
|
-
super({
|
|
37
|
-
context: {
|
|
38
|
-
dxn
|
|
39
|
-
},
|
|
40
|
-
...options
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// src/Key.ts
|
|
46
|
-
var Key_exports = {};
|
|
47
|
-
__export(Key_exports, {
|
|
48
|
-
ObjectId: () => ObjectId,
|
|
49
|
-
SpaceId: () => SpaceId
|
|
50
|
-
});
|
|
51
|
-
import { SpaceId, ObjectId } from "@dxos/keys";
|
|
52
|
-
|
|
53
|
-
// src/Relation.ts
|
|
54
|
-
var Relation_exports = {};
|
|
55
|
-
__export(Relation_exports, {
|
|
56
|
-
Any: () => Any2,
|
|
57
|
-
Source: () => Source,
|
|
58
|
-
Target: () => Target,
|
|
59
|
-
getSource: () => getSource,
|
|
60
|
-
getSourceDXN: () => getSourceDXN,
|
|
61
|
-
getTarget: () => getTarget,
|
|
62
|
-
getTargetDXN: () => getTargetDXN,
|
|
63
|
-
isRelation: () => isRelation,
|
|
64
|
-
make: () => make
|
|
65
|
-
});
|
|
66
|
-
import * as Schema from "effect/Schema";
|
|
67
|
-
import { raise } from "@dxos/debug";
|
|
68
|
-
import { assertArgument, invariant } from "@dxos/invariant";
|
|
69
|
-
import { DXN } from "@dxos/keys";
|
|
70
|
-
import { assumeType } from "@dxos/util";
|
|
71
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/Relation.ts";
|
|
72
|
-
var Any2 = Schema.Struct({}).pipe(Relation({
|
|
73
|
-
typename: "dxos.org/types/Any",
|
|
74
|
-
version: "0.1.0",
|
|
75
|
-
source: Any,
|
|
76
|
-
target: Any
|
|
77
|
-
}));
|
|
78
|
-
var Source = RelationSourceId;
|
|
79
|
-
var Target = RelationTargetId;
|
|
80
|
-
var make = (schema, props, meta) => {
|
|
81
|
-
assertArgument(getTypeAnnotation(schema)?.kind === EntityKind.Relation, "schema", "Expected a relation schema");
|
|
82
|
-
if (props[MetaId] != null) {
|
|
83
|
-
meta = props[MetaId];
|
|
84
|
-
delete props[MetaId];
|
|
85
|
-
}
|
|
86
|
-
const sourceDXN = getObjectDXN(props[Source]) ?? raise(new Error("Unresolved relation source"));
|
|
87
|
-
const targetDXN = getObjectDXN(props[Target]) ?? raise(new Error("Unresolved relation target"));
|
|
88
|
-
props[RelationSourceDXNId] = sourceDXN;
|
|
89
|
-
props[RelationTargetDXNId] = targetDXN;
|
|
90
|
-
return live(schema, props, meta);
|
|
91
|
-
};
|
|
92
|
-
var isRelation = (value) => {
|
|
93
|
-
if (typeof value !== "object" || value === null) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
if (ATTR_RELATION_SOURCE in value || ATTR_RELATION_TARGET in value) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
const kind = value[EntityKindId];
|
|
100
|
-
return kind === EntityKind.Relation;
|
|
101
|
-
};
|
|
102
|
-
var getSourceDXN = (value) => {
|
|
103
|
-
assertArgument(isRelation(value), "Expected a relation");
|
|
104
|
-
assumeType(value);
|
|
105
|
-
const dxn = value[RelationSourceDXNId];
|
|
106
|
-
invariant(dxn instanceof DXN, void 0, {
|
|
107
|
-
F: __dxlog_file,
|
|
108
|
-
L: 110,
|
|
109
|
-
S: void 0,
|
|
110
|
-
A: [
|
|
111
|
-
"dxn instanceof DXN",
|
|
112
|
-
""
|
|
113
|
-
]
|
|
114
|
-
});
|
|
115
|
-
return dxn;
|
|
116
|
-
};
|
|
117
|
-
var getTargetDXN = (value) => {
|
|
118
|
-
assertArgument(isRelation(value), "Expected a relation");
|
|
119
|
-
assumeType(value);
|
|
120
|
-
const dxn = value[RelationTargetDXNId];
|
|
121
|
-
invariant(dxn instanceof DXN, void 0, {
|
|
122
|
-
F: __dxlog_file,
|
|
123
|
-
L: 122,
|
|
124
|
-
S: void 0,
|
|
125
|
-
A: [
|
|
126
|
-
"dxn instanceof DXN",
|
|
127
|
-
""
|
|
128
|
-
]
|
|
129
|
-
});
|
|
130
|
-
return dxn;
|
|
131
|
-
};
|
|
132
|
-
var getSource = (relation) => {
|
|
133
|
-
assertArgument(isRelation(relation), "Expected a relation");
|
|
134
|
-
assumeType(relation);
|
|
135
|
-
const obj = relation[RelationSourceId];
|
|
136
|
-
invariant(obj !== void 0, `Invalid source: ${relation.id}`, {
|
|
137
|
-
F: __dxlog_file,
|
|
138
|
-
L: 134,
|
|
139
|
-
S: void 0,
|
|
140
|
-
A: [
|
|
141
|
-
"obj !== undefined",
|
|
142
|
-
"`Invalid source: ${relation.id}`"
|
|
143
|
-
]
|
|
144
|
-
});
|
|
145
|
-
return obj;
|
|
146
|
-
};
|
|
147
|
-
var getTarget = (relation) => {
|
|
148
|
-
assertArgument(isRelation(relation), "Expected a relation");
|
|
149
|
-
assumeType(relation);
|
|
150
|
-
const obj = relation[RelationTargetId];
|
|
151
|
-
invariant(obj !== void 0, `Invalid target: ${relation.id}`, {
|
|
152
|
-
F: __dxlog_file,
|
|
153
|
-
L: 146,
|
|
154
|
-
S: void 0,
|
|
155
|
-
A: [
|
|
156
|
-
"obj !== undefined",
|
|
157
|
-
"`Invalid target: ${relation.id}`"
|
|
158
|
-
]
|
|
159
|
-
});
|
|
160
|
-
return obj;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
// src/index.ts
|
|
164
|
-
import { QueryAST } from "@dxos/echo-protocol";
|
|
165
|
-
import { DXN as DXN2 } from "@dxos/keys";
|
|
166
|
-
|
|
167
|
-
export {
|
|
168
|
-
SchemaNotFoundError,
|
|
169
|
-
ObjectNotFoundError,
|
|
170
|
-
Key_exports,
|
|
171
|
-
Relation_exports,
|
|
172
|
-
QueryAST,
|
|
173
|
-
DXN2 as DXN
|
|
174
|
-
};
|
|
175
|
-
//# sourceMappingURL=chunk-HKFCK2GL.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/errors.ts", "../../../src/Key.ts", "../../../src/Relation.ts", "../../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { BaseError, type BaseErrorOptions } from '@dxos/errors';\nimport { type DXN } from '@dxos/keys';\n\nexport class SchemaNotFoundError extends BaseError.extend('SCHEMA_NOT_FOUND', 'Schema not found') {\n constructor(schema: string, options?: BaseErrorOptions) {\n super({ context: { schema }, ...options });\n }\n}\n\nexport class ObjectNotFoundError extends BaseError.extend('OBJECT_NOT_FOUND', 'Object not found') {\n constructor(dxn: DXN, options?: BaseErrorOptions) {\n super({ context: { dxn }, ...options });\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nexport { SpaceId, ObjectId } from '@dxos/keys';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { raise } from '@dxos/debug';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN } from '@dxos/keys';\nimport { type Live } from '@dxos/live-object';\nimport { assumeType } from '@dxos/util';\n\nimport { live } from './internal';\nimport * as EchoSchema from './internal';\nimport * as Obj from './Obj';\nimport * as Type from './Type';\n\n/**\n * NOTE: Don't export: Relation.Relation and Relation.Any form the public API.\n */\ninterface BaseRelation<Source, Target>\n extends EchoSchema.HasId,\n Type.Relation.Endpoints<Source, Target>,\n Type.OfKind<EchoSchema.EntityKind.Relation> {}\n\n/**\n * Relation type with specific properties.\n */\nexport type Relation<Source extends Obj.Any, Target extends Obj.Any, Props> = BaseRelation<Source, Target> & Props;\n\n/**\n * Base type for all ECHO relations.\n */\nexport interface Any extends BaseRelation<Obj.Any, Obj.Any> {}\n\nexport const Any = Schema.Struct({}).pipe(\n Type.Relation({\n typename: 'dxos.org/types/Any',\n version: '0.1.0',\n source: Obj.Any,\n target: Obj.Any,\n }),\n);\n\n// TODO(dmaretskyi): Has to be `unique symbol`.\nexport const Source: unique symbol = EchoSchema.RelationSourceId as any;\nexport type Source = typeof Source;\nexport const Target: unique symbol = EchoSchema.RelationTargetId as any;\nexport type Target = typeof Target;\n\ntype MakeProps<T extends Any> = {\n id?: EchoSchema.ObjectId;\n [Source]: T[Source];\n [Target]: T[Target];\n} & Type.Properties<T>;\n\n/**\n * Creates new relation.\n * @param schema - Relation schema.\n * @param props - Relation properties. Endpoints are passed as [Relation.Source] and [Relation.Target] keys.\n * @param meta - Relation metadata.\n * @returns\n */\n// NOTE: Writing the definition this way (with generic over schema) makes typescript perfer to infer the type from the first param (this schema) rather than the second param (the props).\n// TODO(dmaretskyi): Move meta into props.\nexport const make = <S extends Type.Relation.Any>(\n schema: S,\n props: NoInfer<MakeProps<Schema.Schema.Type<S>>>,\n meta?: EchoSchema.ObjectMeta,\n): Live<Schema.Schema.Type<S> & Type.OfKind<EchoSchema.EntityKind.Relation>> => {\n assertArgument(\n EchoSchema.getTypeAnnotation(schema)?.kind === EchoSchema.EntityKind.Relation,\n 'schema',\n 'Expected a relation schema',\n );\n\n if (props[EchoSchema.MetaId] != null) {\n meta = props[EchoSchema.MetaId] as any;\n delete props[EchoSchema.MetaId];\n }\n\n const sourceDXN = EchoSchema.getObjectDXN(props[Source]) ?? raise(new Error('Unresolved relation source'));\n const targetDXN = EchoSchema.getObjectDXN(props[Target]) ?? raise(new Error('Unresolved relation target'));\n (props as any)[EchoSchema.RelationSourceDXNId] = sourceDXN;\n (props as any)[EchoSchema.RelationTargetDXNId] = targetDXN;\n\n return live<Schema.Schema.Type<S>>(schema, props as any, meta);\n};\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.EntityKindId];\n return kind === EchoSchema.EntityKind.Relation;\n};\n\n/**\n * @returns Relation source DXN.\n * @throws If the object is not a relation.\n */\nexport const getSourceDXN = (value: Any): DXN => {\n assertArgument(isRelation(value), 'Expected a relation');\n assumeType<EchoSchema.InternalObjectProps>(value);\n const dxn = (value as EchoSchema.InternalObjectProps)[EchoSchema.RelationSourceDXNId];\n invariant(dxn instanceof DXN);\n return dxn;\n};\n\n/**\n * @returns Relation target DXN.\n * @throws If the object is not a relation.\n */\nexport const getTargetDXN = (value: Any): DXN => {\n assertArgument(isRelation(value), 'Expected a relation');\n assumeType<EchoSchema.InternalObjectProps>(value);\n const dxn = (value as EchoSchema.InternalObjectProps)[EchoSchema.RelationTargetDXNId];\n invariant(dxn instanceof DXN);\n return dxn;\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): Type.Relation.Source<T> => {\n assertArgument(isRelation(relation), 'Expected a relation');\n assumeType<EchoSchema.InternalObjectProps>(relation);\n const obj = (relation as EchoSchema.InternalObjectProps)[EchoSchema.RelationSourceId];\n invariant(obj !== undefined, `Invalid source: ${relation.id}`);\n return obj as Type.Relation.Source<T>;\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): Type.Relation.Target<T> => {\n assertArgument(isRelation(relation), 'Expected a relation');\n assumeType<EchoSchema.InternalObjectProps>(relation);\n const obj = (relation as EchoSchema.InternalObjectProps)[EchoSchema.RelationTargetId];\n invariant(obj !== undefined, `Invalid target: ${relation.id}`);\n return obj as Type.Relation.Target<T>;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nexport * from './errors';\nexport * from './query';\n\nexport * as Key from './Key';\nexport * as Obj from './Obj';\nexport * as Ref from './Ref';\nexport * as Relation from './Relation';\nexport * as Type from './Type';\n\nexport { QueryAST } from '@dxos/echo-protocol';\nexport { DXN } from '@dxos/keys';\nexport { type Live } from '@dxos/live-object';\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": ["BaseError", "SchemaNotFoundError", "BaseError", "extend", "schema", "options", "context", "ObjectNotFoundError", "dxn", "SpaceId", "ObjectId", "Any", "Schema", "raise", "assertArgument", "invariant", "DXN", "assumeType", "Any", "Struct", "pipe", "Relation", "typename", "version", "source", "target", "Source", "RelationSourceId", "Target", "RelationTargetId", "make", "schema", "props", "meta", "assertArgument", "getTypeAnnotation", "kind", "EntityKind", "MetaId", "sourceDXN", "getObjectDXN", "raise", "Error", "targetDXN", "RelationSourceDXNId", "RelationTargetDXNId", "live", "isRelation", "value", "ATTR_RELATION_SOURCE", "ATTR_RELATION_TARGET", "EntityKindId", "getSourceDXN", "assumeType", "dxn", "invariant", "DXN", "getTargetDXN", "getSource", "relation", "obj", "undefined", "id", "getTarget", "QueryAST", "DXN"]
|
|
7
|
-
}
|