@dxos/echo 0.8.3-main.672df60 → 0.8.3-main.7f5a14c
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 +25 -23
- package/dist/lib/browser/index.mjs +139 -136
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +134 -132
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +139 -136
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/Key.d.ts +2 -0
- package/dist/types/src/Key.d.ts.map +1 -0
- package/dist/types/src/Obj.d.ts +15 -11
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts +9 -3
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +15 -13
- package/dist/types/src/Type.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/package.json +12 -12
- package/src/Key.ts +5 -0
- package/src/Obj.ts +23 -20
- package/src/Ref.ts +9 -6
- package/src/Type.ts +19 -14
- package/src/index.ts +5 -3
- package/src/test/api.test.ts +17 -2
package/dist/types/src/Type.d.ts
CHANGED
|
@@ -10,6 +10,13 @@ export type Schema = EchoSchema.EchoSchema;
|
|
|
10
10
|
* EchoObject schema.
|
|
11
11
|
*/
|
|
12
12
|
export declare const Obj: (meta: EchoSchema.TypeMeta) => <Self extends Schema.Schema.Any>(self: Self) => EchoSchema.EchoTypeSchema<Self>;
|
|
13
|
+
export declare namespace Obj {
|
|
14
|
+
/**
|
|
15
|
+
* Type that represents an arbitrary schema type of an object.
|
|
16
|
+
* NOTE: This is not an instance type.
|
|
17
|
+
*/
|
|
18
|
+
type Any = Schema.Schema.AnyNoContext;
|
|
19
|
+
}
|
|
13
20
|
/**
|
|
14
21
|
* EchoRelation schema.
|
|
15
22
|
*/
|
|
@@ -19,17 +26,6 @@ export declare const Relation: <Source extends Schema.Schema.AnyNoContext, Targe
|
|
|
19
26
|
source: Source;
|
|
20
27
|
target: Target;
|
|
21
28
|
}) => <Self extends Schema.Schema.Any>(self: Self) => EchoSchema.EchoTypeSchema<Self, EchoSchema.RelationSourceTargetRefs<Schema.Schema.Type<Source>, Schema.Schema.Type<Target>>>;
|
|
22
|
-
/**
|
|
23
|
-
* Ref schema.
|
|
24
|
-
*/
|
|
25
|
-
export declare const Ref: <S extends Obj.Any>(schema: S) => EchoSchema.Ref$<Schema.Schema.Type<S>>;
|
|
26
|
-
export declare namespace Obj {
|
|
27
|
-
/**
|
|
28
|
-
* Type that represents an arbitrary schema type of an object.
|
|
29
|
-
* NOTE: This is not an instance type.
|
|
30
|
-
*/
|
|
31
|
-
type Any = Schema.Schema.AnyNoContext;
|
|
32
|
-
}
|
|
33
29
|
export declare namespace Relation {
|
|
34
30
|
/**
|
|
35
31
|
* Type that represents an arbitrary schema type of a relation.
|
|
@@ -45,6 +41,12 @@ export declare namespace Relation {
|
|
|
45
41
|
*/
|
|
46
42
|
type Source<A> = A extends EchoSchema.RelationSourceTargetRefs<infer _T, infer S> ? S : never;
|
|
47
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Ref schema.
|
|
46
|
+
*/
|
|
47
|
+
export declare const Ref: <S extends Obj.Any>(schema: S) => EchoSchema.Ref$<Schema.Schema.Type<S>>;
|
|
48
|
+
export interface Ref<T> extends Schema.SchemaClass<EchoSchema.Ref<T>, EncodedReference> {
|
|
49
|
+
}
|
|
48
50
|
export declare namespace Ref {
|
|
49
51
|
/**
|
|
50
52
|
* Type that represents an arbitrary schema type of a reference.
|
|
@@ -81,7 +83,7 @@ export { EntityKind as Kind } from '@dxos/echo-schema';
|
|
|
81
83
|
/**
|
|
82
84
|
* @returns True if the schema is mutable.
|
|
83
85
|
*/
|
|
84
|
-
export declare const isMutable: (schema:
|
|
86
|
+
export declare const isMutable: (schema: Schema.Schema.AnyNoContext) => schema is EchoSchema.EchoSchema;
|
|
85
87
|
export { SpaceId, ObjectId, DXN } from '@dxos/keys';
|
|
86
|
-
export { Expando, JsonSchemaType as JsonSchema,
|
|
88
|
+
export { Expando, Format, JsonSchemaType as JsonSchema, toEffectSchema, toJsonSchema, } from '@dxos/echo-schema';
|
|
87
89
|
//# sourceMappingURL=Type.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Type.d.ts","sourceRoot":"","sources":["../../../src/Type.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,KAAK,IAAI,MAAM,YAAY,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,UAAU,CAAC;AAE3C;;GAEG;AACH,eAAO,MAAM,GAAG,gHAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"Type.d.ts","sourceRoot":"","sources":["../../../src/Type.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,KAAK,IAAI,MAAM,YAAY,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,UAAU,CAAC;AAE3C;;GAEG;AACH,eAAO,MAAM,GAAG,gHAAwB,CAAC;AAGzC,yBAAiB,GAAG,CAAC;IACnB;;;OAGG;IAEH,KAAY,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;CAC9C;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;;kLAA0B,CAAC;AAGhD,yBAAiB,QAAQ,CAAC;IACxB;;;OAGG;IAEH,KAAY,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;IAE7C;;OAEG;IACH,KAAY,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,UAAU,CAAC,wBAAwB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAErG;;OAEG;IACH,KAAY,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,UAAU,CAAC,wBAAwB,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CACtG;AAED;;GAEG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAkB,CAAC;AAE5G,MAAM,WAAW,GAAG,CAAC,CAAC,CAAE,SAAQ,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC;CAAG;AAG1F,yBAAiB,GAAG,CAAC;IACnB;;;OAGG;IACH,KAAY,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,gBAAgB,CAAC,CAAC;CACxE;AAED;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,QAAQ,GAAG,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,KAAG,IAAI,CAAC,GAAG,GAAG,SAElE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,GAAG,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,KAAG,MAI5D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,GAAG,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,KAAG,MAI3D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,UAAU,CAAC,cAAc,CAAC;AAE7C;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,QAAQ,GAAG,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,KAAG,IAAI,GAAG,SAE/D,CAAC;AAEF,OAAO,EAAE,UAAU,IAAI,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;GAEG;AACH,eAAO,MAAM,SAAS,yEAAuB,CAAC;AAE9C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EAEL,OAAO,EAEP,MAAM,EACN,cAAc,IAAI,UAAU,EAC5B,cAAc,EACd,YAAY,GACb,MAAM,mBAAmB,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export * as
|
|
1
|
+
export * as Key from './Key';
|
|
2
2
|
export * as Obj from './Obj';
|
|
3
|
-
export * as Relation from './Relation';
|
|
4
3
|
export * as Ref from './Ref';
|
|
5
|
-
export
|
|
4
|
+
export * as Relation from './Relation';
|
|
5
|
+
export * as Type from './Type';
|
|
6
|
+
export { DXN } from '@dxos/keys';
|
|
6
7
|
export { Filter, Query } from '@dxos/echo-schema';
|
|
8
|
+
export { type Live } from '@dxos/live-object';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAE/B,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo",
|
|
3
|
-
"version": "0.8.3-main.
|
|
3
|
+
"version": "0.8.3-main.7f5a14c",
|
|
4
4
|
"description": "ECHO API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -23,17 +23,17 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@preact/signals-core": "^1.9.0",
|
|
25
25
|
"effect": "3.14.21",
|
|
26
|
-
"@dxos/debug": "0.8.3-main.
|
|
27
|
-
"@dxos/echo-protocol": "0.8.3-main.
|
|
28
|
-
"@dxos/echo-schema": "0.8.3-main.
|
|
29
|
-
"@dxos/echo-signals": "0.8.3-main.
|
|
30
|
-
"@dxos/effect": "0.8.3-main.
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/live-object": "0.8.3-main.
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/util": "0.8.3-main.
|
|
26
|
+
"@dxos/debug": "0.8.3-main.7f5a14c",
|
|
27
|
+
"@dxos/echo-protocol": "0.8.3-main.7f5a14c",
|
|
28
|
+
"@dxos/echo-schema": "0.8.3-main.7f5a14c",
|
|
29
|
+
"@dxos/echo-signals": "0.8.3-main.7f5a14c",
|
|
30
|
+
"@dxos/effect": "0.8.3-main.7f5a14c",
|
|
31
|
+
"@dxos/keys": "0.8.3-main.7f5a14c",
|
|
32
|
+
"@dxos/invariant": "0.8.3-main.7f5a14c",
|
|
33
|
+
"@dxos/live-object": "0.8.3-main.7f5a14c",
|
|
34
|
+
"@dxos/log": "0.8.3-main.7f5a14c",
|
|
35
|
+
"@dxos/node-std": "0.8.3-main.7f5a14c",
|
|
36
|
+
"@dxos/util": "0.8.3-main.7f5a14c"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
package/src/Key.ts
ADDED
package/src/Obj.ts
CHANGED
|
@@ -6,34 +6,42 @@ import { Schema } from 'effect';
|
|
|
6
6
|
|
|
7
7
|
import * as EchoSchema from '@dxos/echo-schema';
|
|
8
8
|
import { assertArgument, invariant } from '@dxos/invariant';
|
|
9
|
-
import type
|
|
9
|
+
import { type DXN } from '@dxos/keys';
|
|
10
10
|
import * as LiveObject from '@dxos/live-object';
|
|
11
|
+
import { assumeType } from '@dxos/util';
|
|
11
12
|
|
|
12
13
|
import type * as Ref from './Ref';
|
|
13
14
|
import type * as Type from './Type';
|
|
14
15
|
|
|
16
|
+
export type Obj<T = any> = EchoSchema.AnyEchoObject & T;
|
|
15
17
|
export type Any = EchoSchema.AnyEchoObject;
|
|
16
18
|
|
|
17
19
|
export const make = LiveObject.live;
|
|
18
20
|
|
|
19
|
-
// TODO(dmaretskyi): Currently broken
|
|
20
21
|
export const isObject = (obj: unknown): obj is Any => {
|
|
21
|
-
|
|
22
|
+
assumeType<EchoSchema.InternalObjectProps>(obj);
|
|
23
|
+
return typeof obj === 'object' && obj !== null && obj[EchoSchema.EntityKindId] === EchoSchema.EntityKind.Object;
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
|
-
*
|
|
27
|
+
* Test if object or relation is an instance of a schema.
|
|
26
28
|
* @example
|
|
27
29
|
* ```ts
|
|
28
|
-
* const
|
|
30
|
+
* const john = Obj.make(Person, { name: 'John' });
|
|
31
|
+
* const johnIsPerson = Obj.instanceOf(Person)(john);
|
|
32
|
+
*
|
|
29
33
|
* const isPerson = Obj.instanceOf(Person);
|
|
30
|
-
* isPerson(
|
|
34
|
+
* if(isPerson(john)) {
|
|
35
|
+
* // john is Person
|
|
36
|
+
* }
|
|
31
37
|
* ```
|
|
32
38
|
*/
|
|
33
39
|
export const instanceOf: {
|
|
34
|
-
<S extends Type.Relation.Any | Type.Obj.Any>(schema: S): (value: unknown) => value is S
|
|
35
|
-
<S extends Type.Relation.Any | Type.Obj.Any>(schema: S, value: unknown): value is S
|
|
36
|
-
} = ((
|
|
40
|
+
<S extends Type.Relation.Any | Type.Obj.Any>(schema: S): (value: unknown) => value is Schema.Schema.Type<S>;
|
|
41
|
+
<S extends Type.Relation.Any | Type.Obj.Any>(schema: S, value: unknown): value is Schema.Schema.Type<S>;
|
|
42
|
+
} = ((
|
|
43
|
+
...args: [schema: Type.Relation.Any | Type.Obj.Any, value: unknown] | [schema: Type.Relation.Any | Type.Obj.Any]
|
|
44
|
+
) => {
|
|
37
45
|
if (args.length === 1) {
|
|
38
46
|
return (obj: unknown) => EchoSchema.isInstanceOf(args[0], obj);
|
|
39
47
|
}
|
|
@@ -55,12 +63,8 @@ export const getDXN = (obj: Any): DXN => {
|
|
|
55
63
|
* @returns The DXN of the object's type.
|
|
56
64
|
* @example dxn:example.com/type/Contact:1.0.0
|
|
57
65
|
*/
|
|
58
|
-
// TODO(
|
|
59
|
-
export const
|
|
60
|
-
const type = EchoSchema.getType(obj);
|
|
61
|
-
invariant(type != null, 'Invalid object.');
|
|
62
|
-
return type;
|
|
63
|
-
};
|
|
66
|
+
// TODO(burdon): Expando does not have a type.
|
|
67
|
+
export const getTypeDXN = EchoSchema.getType;
|
|
64
68
|
|
|
65
69
|
/**
|
|
66
70
|
* @returns The typename of the object's type.
|
|
@@ -70,7 +74,7 @@ export const getTypename = (obj: Any): string | undefined => {
|
|
|
70
74
|
const schema = getSchema(obj);
|
|
71
75
|
if (schema == null) {
|
|
72
76
|
// Try to extract typename from DXN.
|
|
73
|
-
return
|
|
77
|
+
return EchoSchema.getType(obj)?.asTypeDXN()?.type;
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
return EchoSchema.getSchemaTypename(schema);
|
|
@@ -103,16 +107,15 @@ export const getLabel = (obj: Any): string | undefined => {
|
|
|
103
107
|
export type JSON = EchoSchema.ObjectJSON;
|
|
104
108
|
|
|
105
109
|
/**
|
|
106
|
-
* Converts object to
|
|
110
|
+
* Converts object to its JSON representation.
|
|
107
111
|
*
|
|
108
112
|
* The same algorithm is used when calling the standard `JSON.stringify(obj)` function.
|
|
109
113
|
*/
|
|
110
114
|
export const toJSON = (obj: Any): JSON => EchoSchema.objectToJSON(obj);
|
|
111
115
|
|
|
112
116
|
/**
|
|
113
|
-
* Creates an object from
|
|
114
|
-
*
|
|
115
|
-
* References and schema will be resolvable if the `refResolver` is provided.
|
|
117
|
+
* Creates an object from its json representation, performing schema validation.
|
|
118
|
+
* References and schemas will be resolvable if the `refResolver` is provided.
|
|
116
119
|
*
|
|
117
120
|
* The function need to be async to support resolving the schema as well as the relation endpoints.
|
|
118
121
|
*/
|
package/src/Ref.ts
CHANGED
|
@@ -6,14 +6,10 @@ import * as EchoSchema from '@dxos/echo-schema';
|
|
|
6
6
|
|
|
7
7
|
import type * as Obj from './Obj';
|
|
8
8
|
|
|
9
|
+
export type Ref<T extends Obj.Any> = EchoSchema.Ref<T>;
|
|
9
10
|
export type Any = EchoSchema.Ref<Obj.Any>;
|
|
10
11
|
|
|
11
|
-
export const
|
|
12
|
-
|
|
13
|
-
export const isRef: (value: unknown) => value is Any = EchoSchema.Ref.isRef;
|
|
14
|
-
|
|
15
|
-
// TODO(dmaretskyi): Consider just allowing `make` to accept DXN.
|
|
16
|
-
export const fromDXN = EchoSchema.Ref.fromDXN;
|
|
12
|
+
export const Array = EchoSchema.RefArray;
|
|
17
13
|
|
|
18
14
|
/**
|
|
19
15
|
* Extract reference target.
|
|
@@ -24,3 +20,10 @@ export type Target<R extends Any> = R extends EchoSchema.Ref<infer T> ? T : neve
|
|
|
24
20
|
* Reference resolver.
|
|
25
21
|
*/
|
|
26
22
|
export type Resolver = EchoSchema.RefResolver;
|
|
23
|
+
|
|
24
|
+
export const isRef: (value: unknown) => value is Any = EchoSchema.Ref.isRef;
|
|
25
|
+
|
|
26
|
+
export const make = EchoSchema.Ref.make;
|
|
27
|
+
|
|
28
|
+
// TODO(dmaretskyi): Consider just allowing `make` to accept DXN.
|
|
29
|
+
export const fromDXN = EchoSchema.Ref.fromDXN;
|
package/src/Type.ts
CHANGED
|
@@ -19,16 +19,7 @@ export type Schema = EchoSchema.EchoSchema;
|
|
|
19
19
|
*/
|
|
20
20
|
export const Obj = EchoSchema.EchoObject;
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
* EchoRelation schema.
|
|
24
|
-
*/
|
|
25
|
-
export const Relation = EchoSchema.EchoRelation;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Ref schema.
|
|
29
|
-
*/
|
|
30
|
-
export const Ref: <S extends Obj.Any>(schema: S) => EchoSchema.Ref$<Schema.Schema.Type<S>> = EchoSchema.Ref;
|
|
31
|
-
|
|
22
|
+
// TODO(buurdon): Move to Obj?
|
|
32
23
|
export namespace Obj {
|
|
33
24
|
/**
|
|
34
25
|
* Type that represents an arbitrary schema type of an object.
|
|
@@ -38,6 +29,12 @@ export namespace Obj {
|
|
|
38
29
|
export type Any = Schema.Schema.AnyNoContext;
|
|
39
30
|
}
|
|
40
31
|
|
|
32
|
+
/**
|
|
33
|
+
* EchoRelation schema.
|
|
34
|
+
*/
|
|
35
|
+
export const Relation = EchoSchema.EchoRelation;
|
|
36
|
+
|
|
37
|
+
// TODO(buurdon): Move to Relation?
|
|
41
38
|
export namespace Relation {
|
|
42
39
|
/**
|
|
43
40
|
* Type that represents an arbitrary schema type of a relation.
|
|
@@ -57,6 +54,14 @@ export namespace Relation {
|
|
|
57
54
|
export type Source<A> = A extends EchoSchema.RelationSourceTargetRefs<infer _T, infer S> ? S : never;
|
|
58
55
|
}
|
|
59
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Ref schema.
|
|
59
|
+
*/
|
|
60
|
+
export const Ref: <S extends Obj.Any>(schema: S) => EchoSchema.Ref$<Schema.Schema.Type<S>> = EchoSchema.Ref;
|
|
61
|
+
|
|
62
|
+
export interface Ref<T> extends Schema.SchemaClass<EchoSchema.Ref<T>, EncodedReference> {}
|
|
63
|
+
|
|
64
|
+
// TODO(buurdon): Move to Ref?
|
|
60
65
|
export namespace Ref {
|
|
61
66
|
/**
|
|
62
67
|
* Type that represents an arbitrary schema type of a reference.
|
|
@@ -112,16 +117,16 @@ export { EntityKind as Kind } from '@dxos/echo-schema';
|
|
|
112
117
|
/**
|
|
113
118
|
* @returns True if the schema is mutable.
|
|
114
119
|
*/
|
|
115
|
-
export const isMutable =
|
|
116
|
-
return EchoSchema.isMutable(schema);
|
|
117
|
-
};
|
|
120
|
+
export const isMutable = EchoSchema.isMutable;
|
|
118
121
|
|
|
119
122
|
export { SpaceId, ObjectId, DXN } from '@dxos/keys';
|
|
120
123
|
|
|
121
124
|
export {
|
|
122
125
|
//
|
|
123
126
|
Expando,
|
|
127
|
+
// TODO(burdon): Standardize.
|
|
128
|
+
Format,
|
|
124
129
|
JsonSchemaType as JsonSchema,
|
|
130
|
+
toEffectSchema,
|
|
125
131
|
toJsonSchema,
|
|
126
|
-
Format,
|
|
127
132
|
} from '@dxos/echo-schema';
|
package/src/index.ts
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * as
|
|
5
|
+
export * as Key from './Key';
|
|
6
6
|
export * as Obj from './Obj';
|
|
7
|
-
export * as Relation from './Relation';
|
|
8
7
|
export * as Ref from './Ref';
|
|
8
|
+
export * as Relation from './Relation';
|
|
9
|
+
export * as Type from './Type';
|
|
9
10
|
|
|
10
|
-
export {
|
|
11
|
+
export { DXN } from '@dxos/keys';
|
|
11
12
|
export { Filter, Query } from '@dxos/echo-schema';
|
|
13
|
+
export { type Live } from '@dxos/live-object';
|
package/src/test/api.test.ts
CHANGED
|
@@ -117,12 +117,27 @@ describe('Experimental API review', () => {
|
|
|
117
117
|
|
|
118
118
|
expect(Schema.is(Testing.Person)(contact)).to.be.true;
|
|
119
119
|
expect(Testing.Person.instanceOf(contact)).to.be.true;
|
|
120
|
-
expect(Obj.instanceOf(Testing.Person
|
|
121
|
-
expect(Obj.instanceOf(Testing.Organization
|
|
120
|
+
expect(Obj.instanceOf(Testing.Person, contact)).to.be.true;
|
|
121
|
+
expect(Obj.instanceOf(Testing.Organization, organization)).to.be.true;
|
|
122
|
+
|
|
123
|
+
const isPerson = Obj.instanceOf(Testing.Person);
|
|
124
|
+
const x: any = {};
|
|
125
|
+
if (isPerson(x)) {
|
|
126
|
+
x.name;
|
|
127
|
+
}
|
|
122
128
|
});
|
|
123
129
|
|
|
124
130
|
test('default props', ({ expect }) => {
|
|
125
131
|
const message = Obj.make(Testing.Message, Testing.MessageStruct.make({}));
|
|
126
132
|
expect(message.timestamp).to.exist;
|
|
127
133
|
});
|
|
134
|
+
|
|
135
|
+
test('Obj.isObject', ({ expect }) => {
|
|
136
|
+
const guy = Obj.make(Testing.Person, { name: 'Test' });
|
|
137
|
+
expect(Obj.isObject(guy)).to.be.true;
|
|
138
|
+
expect(Obj.isObject(null)).to.be.false;
|
|
139
|
+
expect(Obj.isObject(undefined)).to.be.false;
|
|
140
|
+
expect(Obj.isObject(1)).to.be.false;
|
|
141
|
+
expect(Obj.isObject('string')).to.be.false;
|
|
142
|
+
});
|
|
128
143
|
});
|