@dxos/echo 0.8.2-main.fbd8ed0 → 0.8.2-staging.7ac8446
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +26 -76
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +25 -77
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +26 -76
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/{experimental/database.d.ts → Database.d.ts} +1 -1
- package/dist/types/src/Database.d.ts.map +1 -0
- package/dist/types/src/{experimental/queue.d.ts → Queue.d.ts} +1 -1
- package/dist/types/src/Queue.d.ts.map +1 -0
- package/dist/types/src/{experimental/space.d.ts → Space.d.ts} +1 -1
- package/dist/types/src/Space.d.ts.map +1 -0
- package/dist/types/src/Type.d.ts +49 -0
- package/dist/types/src/Type.d.ts.map +1 -0
- package/dist/types/src/{type/api.test.d.ts.map → api.test.d.ts.map} +1 -1
- package/dist/types/src/index.d.ts +6 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -14
- package/src/{experimental/database.ts → Database.ts} +1 -1
- package/src/{experimental/queue.ts → Queue.ts} +1 -1
- package/src/Type.ts +99 -0
- package/src/api.test.ts +94 -0
- package/src/index.ts +7 -3
- package/dist/types/src/experimental/database.d.ts.map +0 -1
- package/dist/types/src/experimental/index.d.ts +0 -1
- package/dist/types/src/experimental/index.d.ts.map +0 -1
- package/dist/types/src/experimental/queue.d.ts.map +0 -1
- package/dist/types/src/experimental/space.d.ts.map +0 -1
- package/dist/types/src/type/Obj.d.ts +0 -12
- package/dist/types/src/type/Obj.d.ts.map +0 -1
- package/dist/types/src/type/Ref.d.ts +0 -3
- package/dist/types/src/type/Ref.d.ts.map +0 -1
- package/dist/types/src/type/Relation.d.ts +0 -16
- package/dist/types/src/type/Relation.d.ts.map +0 -1
- package/dist/types/src/type/Type.d.ts +0 -77
- package/dist/types/src/type/Type.d.ts.map +0 -1
- package/dist/types/src/type/index.d.ts +0 -5
- package/dist/types/src/type/index.d.ts.map +0 -1
- package/src/experimental/index.ts +0 -7
- package/src/type/Obj.ts +0 -18
- package/src/type/Ref.ts +0 -7
- package/src/type/Relation.ts +0 -17
- package/src/type/Type.ts +0 -134
- package/src/type/api.test.ts +0 -128
- package/src/type/index.ts +0 -8
- /package/dist/types/src/{type/api.test.d.ts → api.test.d.ts} +0 -0
- /package/src/{experimental/space.ts → Space.ts} +0 -0
package/src/type/Type.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Schema } from 'effect';
|
|
6
|
-
|
|
7
|
-
import { type AnyLiveObject as AnyLiveObject$ } from '@dxos/echo-db';
|
|
8
|
-
import {
|
|
9
|
-
type BaseEchoObject,
|
|
10
|
-
type BaseObject,
|
|
11
|
-
type BaseSchema,
|
|
12
|
-
type EchoSchema,
|
|
13
|
-
EchoObject,
|
|
14
|
-
EntityKind,
|
|
15
|
-
Expando as Expando$,
|
|
16
|
-
type ImmutableSchema,
|
|
17
|
-
type JsonSchemaType,
|
|
18
|
-
ObjectId as ObjectId$,
|
|
19
|
-
Ref as Ref$,
|
|
20
|
-
type StoredSchema,
|
|
21
|
-
type TypeMeta,
|
|
22
|
-
getTypeAnnotation,
|
|
23
|
-
getSchema as getSchema$,
|
|
24
|
-
getSchemaDXN,
|
|
25
|
-
getSchemaTypename,
|
|
26
|
-
getSchemaVersion,
|
|
27
|
-
isInstanceOf,
|
|
28
|
-
isMutable as isMutable$,
|
|
29
|
-
toJsonSchema as toJsonSchema$,
|
|
30
|
-
} from '@dxos/echo-schema';
|
|
31
|
-
import { invariant } from '@dxos/invariant';
|
|
32
|
-
import { SpaceId as SpaceId$ } from '@dxos/keys';
|
|
33
|
-
import { live as live$ } from '@dxos/live-object';
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Type System API.
|
|
37
|
-
*
|
|
38
|
-
* @category api namespace
|
|
39
|
-
* @since 0.9.0
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
//
|
|
43
|
-
// Keys
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
export const SpaceId = SpaceId$;
|
|
47
|
-
export type SpaceId = SpaceId$;
|
|
48
|
-
|
|
49
|
-
export const ObjectId = ObjectId$;
|
|
50
|
-
export type ObjectId = ObjectId$;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Defines a reference to an ECHO object.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* import { Type } from '@dxos/echo';
|
|
58
|
-
* const Person = Schema.Struct({
|
|
59
|
-
* name: Schema.String,
|
|
60
|
-
* organization: Type.Ref(Organization),
|
|
61
|
-
* }).pipe(Type.def({
|
|
62
|
-
* typename: 'example.com/type/Person',
|
|
63
|
-
* version: '0.1.0',
|
|
64
|
-
* }));
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export const Ref = <S extends Schema.Schema.AnyNoContext>(self: S) => Ref$<Schema.Schema.Type<S>>(self);
|
|
68
|
-
|
|
69
|
-
//
|
|
70
|
-
// Objects
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
export const Kind = EntityKind;
|
|
74
|
-
export type AnyObject = BaseEchoObject;
|
|
75
|
-
export type AnyLiveObject<T extends BaseObject> = AnyLiveObject$<T>;
|
|
76
|
-
|
|
77
|
-
//
|
|
78
|
-
// Schema
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
export type JsonSchema = JsonSchemaType;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* A schema that can be extended with arbitrary properties.
|
|
85
|
-
*/
|
|
86
|
-
export const Expando = Expando$;
|
|
87
|
-
export type Expando = Expando$;
|
|
88
|
-
|
|
89
|
-
// TODO(burdon): Review/remove.
|
|
90
|
-
export type Abstract<T = any> = BaseSchema<T>;
|
|
91
|
-
export type ImmutableType<T> = ImmutableSchema<T>;
|
|
92
|
-
export type MutableType<T> = EchoSchema<T>;
|
|
93
|
-
export type StoredType = StoredSchema;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Defines an ECHO type.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```ts
|
|
100
|
-
* import { Type } from '@dxos/echo';
|
|
101
|
-
* const Organization = Schema.Struct({
|
|
102
|
-
* name: Schema.String,
|
|
103
|
-
* }).pipe(Type.def({
|
|
104
|
-
* typename: 'example.com/type/Organization',
|
|
105
|
-
* version: '0.1.0',
|
|
106
|
-
* }));
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
export const def = (meta: TypeMeta) => EchoObject(meta);
|
|
110
|
-
|
|
111
|
-
//
|
|
112
|
-
// Object utils
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
export const create = live$;
|
|
116
|
-
|
|
117
|
-
export const getSchema = getSchema$;
|
|
118
|
-
export const instanceOf = isInstanceOf;
|
|
119
|
-
|
|
120
|
-
//
|
|
121
|
-
// Type utils
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
// TODO(burdon): Reconcile getDXN and getTypename.
|
|
125
|
-
export const getDXN = getSchemaDXN;
|
|
126
|
-
export const getMeta = getTypeAnnotation;
|
|
127
|
-
export const getTypename = (schema: Schema.Schema.AnyNoContext): string => {
|
|
128
|
-
const typename = getSchemaTypename(schema);
|
|
129
|
-
invariant(typename, 'Invalid object');
|
|
130
|
-
return typename;
|
|
131
|
-
};
|
|
132
|
-
export const getVersion = getSchemaVersion;
|
|
133
|
-
export const isMutable = isMutable$;
|
|
134
|
-
export const toJsonSchema = toJsonSchema$;
|
package/src/type/api.test.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
|
-
import { describe, test } from 'vitest';
|
|
7
|
-
|
|
8
|
-
import { raise } from '@dxos/debug';
|
|
9
|
-
import { FormatEnum, FormatAnnotation } from '@dxos/echo-schema';
|
|
10
|
-
|
|
11
|
-
import { Obj, Ref, Type } from '.';
|
|
12
|
-
|
|
13
|
-
namespace Testing {
|
|
14
|
-
export const Organization = Schema.Struct({
|
|
15
|
-
id: Type.ObjectId,
|
|
16
|
-
name: Schema.String,
|
|
17
|
-
}).pipe(
|
|
18
|
-
Type.def({
|
|
19
|
-
typename: 'example.com/type/Organization',
|
|
20
|
-
version: '0.1.0',
|
|
21
|
-
}),
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
export interface Organization extends Schema.Schema.Type<typeof Organization> {}
|
|
25
|
-
|
|
26
|
-
export const Person = Schema.Struct({
|
|
27
|
-
name: Schema.String,
|
|
28
|
-
dob: Schema.optional(Schema.String),
|
|
29
|
-
email: Schema.optional(Schema.String.pipe(FormatAnnotation.set(FormatEnum.Email))),
|
|
30
|
-
organization: Schema.optional(Type.Ref(Organization)),
|
|
31
|
-
}).pipe(
|
|
32
|
-
Type.def({
|
|
33
|
-
typename: 'example.com/type/Person',
|
|
34
|
-
version: '0.1.0',
|
|
35
|
-
}),
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
export interface Person extends Schema.Schema.Type<typeof Person> {}
|
|
39
|
-
|
|
40
|
-
// export const WorksFor = S.Struct({
|
|
41
|
-
// id: Type.ObjectId,
|
|
42
|
-
// since: S.String,
|
|
43
|
-
// jobTitle: S.String,
|
|
44
|
-
// ...Range({ from, to }),
|
|
45
|
-
// ...Provenance({ source: 'duckduckgo.com', confidence: 0.9 }), // keys
|
|
46
|
-
// ...Relation.make({ source: Contact, target: Organization }),
|
|
47
|
-
// }).pipe(
|
|
48
|
-
// Relation.def({
|
|
49
|
-
// typename: 'example.com/relation/WorksFor',
|
|
50
|
-
// version: '0.1.0',
|
|
51
|
-
// }),
|
|
52
|
-
// );
|
|
53
|
-
|
|
54
|
-
// {
|
|
55
|
-
// const contact = db.add(create(Contact, { name: 'Test' }));
|
|
56
|
-
// const organization = db.add(create(Organization, { name: 'DXOS' }));
|
|
57
|
-
// db.add(create(WorksFor, { source: contact, target: organization }));
|
|
58
|
-
// }
|
|
59
|
-
|
|
60
|
-
export const WorksFor = Schema.Struct({
|
|
61
|
-
// id: Type.ObjectId,
|
|
62
|
-
role: Schema.String,
|
|
63
|
-
}).pipe(
|
|
64
|
-
// Relation.def
|
|
65
|
-
Type.def({
|
|
66
|
-
typename: 'example.com/type/WorksFor',
|
|
67
|
-
version: '0.1.0',
|
|
68
|
-
// source: Person,
|
|
69
|
-
// target: Organization,
|
|
70
|
-
}),
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
export interface WorksFor extends Schema.Schema.Type<typeof WorksFor> {}
|
|
74
|
-
|
|
75
|
-
// TODO(burdon): Fix (Type.def currently removes TypeLiteral that implements the `make` function).
|
|
76
|
-
// Property 'make' does not exist on type 'EchoObjectSchema<Struct<{ timestamp: PropertySignature<":", string, never, ":", string, true, never>; }>>'.ts(2339)
|
|
77
|
-
export const MessageStruct = Schema.Struct({
|
|
78
|
-
// TODO(burdon): Support S.Date; Custom Timestamp (with defaults).
|
|
79
|
-
// TODO(burdon): Support defaults (update create and create).
|
|
80
|
-
timestamp: Schema.String.pipe(
|
|
81
|
-
Schema.propertySignature,
|
|
82
|
-
Schema.withConstructorDefault(() => new Date().toISOString()),
|
|
83
|
-
),
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
export const Message = MessageStruct.pipe(
|
|
87
|
-
Type.def({
|
|
88
|
-
typename: 'example.com/type/Message',
|
|
89
|
-
version: '0.1.0',
|
|
90
|
-
}),
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
export interface Message extends Schema.Schema.Type<typeof Message> {}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
describe('Experimental API review', () => {
|
|
97
|
-
test('type checks', ({ expect }) => {
|
|
98
|
-
const contact = Obj.create(Testing.Person, { name: 'Test' });
|
|
99
|
-
const type: Schema.Schema<Testing.Person> = Obj.getSchema(contact) ?? raise(new Error('No schema found'));
|
|
100
|
-
|
|
101
|
-
expect(Type.getDXN(type)?.typename).to.eq(Testing.Person.typename);
|
|
102
|
-
expect(Type.getTypename(type)).to.eq('example.com/type/Person');
|
|
103
|
-
expect(Type.getVersion(type)).to.eq('0.1.0');
|
|
104
|
-
expect(Type.getMeta(type)).to.deep.eq({
|
|
105
|
-
kind: Type.Kind.Object,
|
|
106
|
-
typename: 'example.com/type/Person',
|
|
107
|
-
version: '0.1.0',
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test('instance checks', ({ expect }) => {
|
|
112
|
-
const organization: Obj.Obj.Live<Testing.Organization> = Obj.create(Testing.Organization, { name: 'DXOS' });
|
|
113
|
-
const contact: Obj.Obj.Live<Testing.Person> = Obj.create(Testing.Person, {
|
|
114
|
-
name: 'Test',
|
|
115
|
-
organization: Ref.make(organization),
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
expect(Schema.is(Testing.Person)(contact)).to.be.true;
|
|
119
|
-
expect(Testing.Person.instanceOf(contact)).to.be.true;
|
|
120
|
-
expect(Type.instanceOf(Testing.Person, contact)).to.be.true;
|
|
121
|
-
expect(Type.instanceOf(Testing.Organization, organization)).to.be.true;
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test('default props', ({ expect }) => {
|
|
125
|
-
const message = Obj.create(Testing.Message, Testing.MessageStruct.make({}));
|
|
126
|
-
expect(message.timestamp).to.exist;
|
|
127
|
-
});
|
|
128
|
-
});
|
package/src/type/index.ts
DELETED
|
File without changes
|
|
File without changes
|