@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.548089c",
|
|
4
4
|
"description": "ECHO API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -85,17 +85,17 @@
|
|
|
85
85
|
"dependencies": {
|
|
86
86
|
"@preact/signals-core": "^1.12.1",
|
|
87
87
|
"effect": "3.18.3",
|
|
88
|
-
"@dxos/debug": "0.8.4-main.
|
|
89
|
-
"@dxos/echo-
|
|
90
|
-
"@dxos/
|
|
91
|
-
"@dxos/
|
|
92
|
-
"@dxos/invariant": "0.8.4-main.
|
|
93
|
-
"@dxos/keys": "0.8.4-main.
|
|
94
|
-
"@dxos/
|
|
95
|
-
"@dxos/
|
|
96
|
-
"@dxos/
|
|
97
|
-
"@dxos/
|
|
98
|
-
"@dxos/
|
|
88
|
+
"@dxos/debug": "0.8.4-main.548089c",
|
|
89
|
+
"@dxos/echo-protocol": "0.8.4-main.548089c",
|
|
90
|
+
"@dxos/echo-signals": "0.8.4-main.548089c",
|
|
91
|
+
"@dxos/effect": "0.8.4-main.548089c",
|
|
92
|
+
"@dxos/invariant": "0.8.4-main.548089c",
|
|
93
|
+
"@dxos/keys": "0.8.4-main.548089c",
|
|
94
|
+
"@dxos/errors": "0.8.4-main.548089c",
|
|
95
|
+
"@dxos/live-object": "0.8.4-main.548089c",
|
|
96
|
+
"@dxos/log": "0.8.4-main.548089c",
|
|
97
|
+
"@dxos/node-std": "0.8.4-main.548089c",
|
|
98
|
+
"@dxos/util": "0.8.4-main.548089c"
|
|
99
99
|
},
|
|
100
100
|
"publishConfig": {
|
|
101
101
|
"access": "public"
|
package/src/Obj.ts
CHANGED
|
@@ -139,14 +139,14 @@ export const getDXN = (obj: Any | Relation.Any): DXN => {
|
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
141
|
* @returns The DXN of the object's type.
|
|
142
|
-
* @example dxn:example.com/type/
|
|
142
|
+
* @example dxn:example.com/type/Person:1.0.0
|
|
143
143
|
*/
|
|
144
144
|
// TODO(burdon): Expando does not have a type.
|
|
145
145
|
export const getTypeDXN = EchoSchema.getType;
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
* @returns The typename of the object's type.
|
|
149
|
-
* @example `example.com/type/
|
|
149
|
+
* @example `example.com/type/Person`
|
|
150
150
|
*/
|
|
151
151
|
export const getTypename = (obj: Any | Relation.Any): string | undefined => {
|
|
152
152
|
const schema = getSchema(obj);
|
|
@@ -227,6 +227,25 @@ export const setDescription = (obj: Any | Relation.Any, description: string) =>
|
|
|
227
227
|
}
|
|
228
228
|
};
|
|
229
229
|
|
|
230
|
+
export const addTag = (obj: Any | Relation.Any, tag: string) => {
|
|
231
|
+
const meta = getMeta(obj);
|
|
232
|
+
meta.tags ??= [];
|
|
233
|
+
meta.tags.push(tag);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export const removeTag = (obj: Any | Relation.Any, tag: string) => {
|
|
237
|
+
const meta = getMeta(obj);
|
|
238
|
+
if (!meta.tags) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
for (let i = 0; i < meta.tags.length; i++) {
|
|
242
|
+
if (meta.tags[i] === tag) {
|
|
243
|
+
meta.tags.splice(i, 1);
|
|
244
|
+
i--;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
230
249
|
const compare = (a?: string, b?: string) => {
|
|
231
250
|
if (a == null) {
|
|
232
251
|
return b == null ? 0 : 1;
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { LabelAnnotation } from '
|
|
8
|
-
import * as Obj from '
|
|
9
|
-
import * as Type from '
|
|
7
|
+
import { LabelAnnotation } from './internal';
|
|
8
|
+
import * as Obj from './Obj';
|
|
9
|
+
import * as Type from './Type';
|
|
10
10
|
|
|
11
11
|
export const Tag = Schema.Struct({
|
|
12
12
|
label: Schema.String,
|
|
@@ -18,20 +18,22 @@ export const Tag = Schema.Struct({
|
|
|
18
18
|
}),
|
|
19
19
|
LabelAnnotation.set(['label']),
|
|
20
20
|
);
|
|
21
|
+
|
|
21
22
|
export type Tag = Schema.Schema.Type<typeof Tag>;
|
|
22
23
|
|
|
23
24
|
export const make = (props: Obj.MakeProps<typeof Tag>) => Obj.make(Tag, props);
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
// TODO(burdon): Rename Map.
|
|
27
|
+
export type Map = Record<string, Tag>;
|
|
26
28
|
|
|
27
29
|
export const sortTags = ({ label: a }: Tag, { label: b }: Tag) => a.localeCompare(b);
|
|
28
30
|
|
|
29
|
-
export const createTagList = (tags:
|
|
31
|
+
export const createTagList = (tags: Map): Tag[] =>
|
|
30
32
|
Object.entries(tags)
|
|
31
33
|
.map(([id, tag]) => ({ ...tag, id }))
|
|
32
34
|
.sort(sortTags);
|
|
33
35
|
|
|
34
|
-
export const findTagByLabel = (tags:
|
|
36
|
+
export const findTagByLabel = (tags: Map | undefined, name: string): Tag | undefined => {
|
|
35
37
|
const entry = Object.entries(tags ?? {}).find(([_, tag]) => tag.label.toLowerCase() === name.toLowerCase());
|
|
36
38
|
return entry ? { ...entry[1], id: entry[0] } : undefined;
|
|
37
39
|
};
|
package/src/index.ts
CHANGED
|
@@ -174,6 +174,13 @@ export const LabelAnnotation = createAnnotationHelper<string[]>(LabelAnnotationI
|
|
|
174
174
|
export const DescriptionAnnotationId = Symbol.for('@dxos/schema/annotation/Description');
|
|
175
175
|
export const DescriptionAnnotation = createAnnotationHelper<string>(DescriptionAnnotationId);
|
|
176
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Identifies if a property should be included in a form or not.
|
|
179
|
+
* By default, all properties are included in forms, so this is opt-out.
|
|
180
|
+
*/
|
|
181
|
+
export const FormAnnotationId = Symbol.for('@dxos/schema/annotation/Form');
|
|
182
|
+
export const FormAnnotation = createAnnotationHelper<boolean>(FormAnnotationId);
|
|
183
|
+
|
|
177
184
|
/**
|
|
178
185
|
* Default field to be used on referenced schema to lookup the value.
|
|
179
186
|
*/
|
package/src/internal/index.ts
CHANGED
|
@@ -15,8 +15,8 @@ export * from './json-schema';
|
|
|
15
15
|
export * from './object';
|
|
16
16
|
export * from './types';
|
|
17
17
|
export { defineHiddenProperty } from '@dxos/live-object';
|
|
18
|
-
export * from './ref';
|
|
19
18
|
export * from './projection';
|
|
20
|
-
export * from './schema';
|
|
21
19
|
// TODO(dmaretskyi): Remove
|
|
22
20
|
export { live } from './proxy/reactive-object';
|
|
21
|
+
export * from './ref';
|
|
22
|
+
export * from './schema';
|
|
@@ -12,6 +12,7 @@ import { ObjectId } from '@dxos/keys';
|
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
13
|
|
|
14
14
|
import { Type } from '../..';
|
|
15
|
+
import { Testing, prepareAstForCompare } from '../../testing';
|
|
15
16
|
import {
|
|
16
17
|
EntityKind,
|
|
17
18
|
FieldLookupAnnotationId,
|
|
@@ -26,7 +27,6 @@ import { JsonSchemaType, getNormalizedEchoAnnotations, getSchemaProperty, setSch
|
|
|
26
27
|
import { EchoObject } from '../object';
|
|
27
28
|
import { Ref, createSchemaReference, getReferenceAst, getSchemaReference } from '../ref';
|
|
28
29
|
import { StoredSchema } from '../schema';
|
|
29
|
-
import { Testing, prepareAstForCompare } from '../testing';
|
|
30
30
|
|
|
31
31
|
import { toEffectSchema, toJsonSchema } from './json-schema';
|
|
32
32
|
|
|
@@ -166,17 +166,17 @@ describe('effect-to-json', () => {
|
|
|
166
166
|
}),
|
|
167
167
|
}).pipe(
|
|
168
168
|
Type.Obj({
|
|
169
|
-
typename: 'example.com/type/
|
|
169
|
+
typename: 'example.com/type/Person',
|
|
170
170
|
version: '0.1.0',
|
|
171
171
|
}),
|
|
172
172
|
);
|
|
173
173
|
const jsonSchema = toJsonSchema(TestSchema);
|
|
174
174
|
expect(jsonSchema).to.deep.eq({
|
|
175
175
|
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
176
|
-
$id: 'dxn:type:example.com/type/
|
|
176
|
+
$id: 'dxn:type:example.com/type/Person',
|
|
177
177
|
|
|
178
178
|
entityKind: EntityKind.Object,
|
|
179
|
-
typename: 'example.com/type/
|
|
179
|
+
typename: 'example.com/type/Person',
|
|
180
180
|
version: '0.1.0',
|
|
181
181
|
|
|
182
182
|
type: 'object',
|
|
@@ -197,16 +197,8 @@ describe('effect-to-json', () => {
|
|
|
197
197
|
});
|
|
198
198
|
|
|
199
199
|
test('handles suspend -- Contact schema serialization', () => {
|
|
200
|
-
const schema = toJsonSchema(Testing.
|
|
201
|
-
expect(Object.keys(schema.properties!)).toEqual([
|
|
202
|
-
'id',
|
|
203
|
-
'name',
|
|
204
|
-
'username',
|
|
205
|
-
'email',
|
|
206
|
-
'phoneNumbers',
|
|
207
|
-
'tasks',
|
|
208
|
-
'address',
|
|
209
|
-
]);
|
|
200
|
+
const schema = toJsonSchema(Testing.Person);
|
|
201
|
+
expect(Object.keys(schema.properties!)).toEqual(['id', 'name', 'username', 'email', 'tasks', 'address']);
|
|
210
202
|
});
|
|
211
203
|
|
|
212
204
|
test('reference property by ref', () => {
|
|
@@ -224,7 +216,7 @@ describe('effect-to-json', () => {
|
|
|
224
216
|
organization: Ref(Organization).annotations({ description: 'Contact organization' }),
|
|
225
217
|
}).pipe(
|
|
226
218
|
Type.Obj({
|
|
227
|
-
typename: 'example.com/type/
|
|
219
|
+
typename: 'example.com/type/Person',
|
|
228
220
|
version: '0.1.0',
|
|
229
221
|
}),
|
|
230
222
|
);
|
|
@@ -234,10 +226,10 @@ describe('effect-to-json', () => {
|
|
|
234
226
|
const jsonSchema = toJsonSchema(Contact);
|
|
235
227
|
expect(jsonSchema).toEqual({
|
|
236
228
|
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
237
|
-
$id: 'dxn:type:example.com/type/
|
|
229
|
+
$id: 'dxn:type:example.com/type/Person',
|
|
238
230
|
|
|
239
231
|
entityKind: EntityKind.Object,
|
|
240
|
-
typename: 'example.com/type/
|
|
232
|
+
typename: 'example.com/type/Person',
|
|
241
233
|
version: '0.1.0',
|
|
242
234
|
|
|
243
235
|
type: 'object',
|
|
@@ -286,7 +278,7 @@ describe('effect-to-json', () => {
|
|
|
286
278
|
organization: Ref(Organization).annotations({ description: 'Contact organization' }),
|
|
287
279
|
}).pipe(
|
|
288
280
|
Type.Obj({
|
|
289
|
-
typename: 'example.com/type/
|
|
281
|
+
typename: 'example.com/type/Person',
|
|
290
282
|
version: '0.1.0',
|
|
291
283
|
}),
|
|
292
284
|
);
|
|
@@ -321,7 +313,7 @@ describe('effect-to-json', () => {
|
|
|
321
313
|
|
|
322
314
|
test('reference with title annotation', () => {
|
|
323
315
|
const schema = Schema.Struct({
|
|
324
|
-
contact: Ref(Testing.
|
|
316
|
+
contact: Ref(Testing.Person).annotations({ title: 'Custom Title' }),
|
|
325
317
|
});
|
|
326
318
|
|
|
327
319
|
// log.info('schema before', { ast: schema.ast });
|
|
@@ -354,11 +346,11 @@ describe('effect-to-json', () => {
|
|
|
354
346
|
version: '0.1.0',
|
|
355
347
|
relationSource: {
|
|
356
348
|
// TODO(dmaretskyi): Should those point to specific schema version?
|
|
357
|
-
$ref: 'dxn:type:example.com/type/
|
|
349
|
+
$ref: 'dxn:type:example.com/type/Person',
|
|
358
350
|
},
|
|
359
351
|
relationTarget: {
|
|
360
352
|
// TODO(dmaretskyi): Should those point to specific schema version?
|
|
361
|
-
$ref: 'dxn:type:example.com/type/
|
|
353
|
+
$ref: 'dxn:type:example.com/type/Person',
|
|
362
354
|
},
|
|
363
355
|
type: 'object',
|
|
364
356
|
properties: {
|
|
@@ -698,7 +690,7 @@ describe('json-to-effect', () => {
|
|
|
698
690
|
|
|
699
691
|
test('schema with optional referece', () => {
|
|
700
692
|
const TestSchema = Schema.Struct({
|
|
701
|
-
contact: Schema.optional(Ref(Testing.
|
|
693
|
+
contact: Schema.optional(Ref(Testing.Person)),
|
|
702
694
|
});
|
|
703
695
|
const jsonSchema = toJsonSchema(TestSchema);
|
|
704
696
|
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
@@ -711,7 +703,7 @@ describe('json-to-effect', () => {
|
|
|
711
703
|
"$ref": "/schemas/echo/ref",
|
|
712
704
|
"reference": {
|
|
713
705
|
"schema": {
|
|
714
|
-
"$ref": "dxn:type:example.com/type/
|
|
706
|
+
"$ref": "dxn:type:example.com/type/Person",
|
|
715
707
|
},
|
|
716
708
|
"schemaVersion": "0.1.0",
|
|
717
709
|
},
|
|
@@ -732,7 +724,7 @@ describe('json-to-effect', () => {
|
|
|
732
724
|
test('object nested inside another struct', () => {
|
|
733
725
|
const Contact = Schema.Struct({
|
|
734
726
|
name: Schema.String,
|
|
735
|
-
}).pipe(EchoObject({ typename: 'example.com/type/
|
|
727
|
+
}).pipe(EchoObject({ typename: 'example.com/type/Person', version: '0.1.0' }));
|
|
736
728
|
const input = Schema.Struct({
|
|
737
729
|
contact: Contact,
|
|
738
730
|
});
|
|
@@ -743,7 +735,7 @@ describe('json-to-effect', () => {
|
|
|
743
735
|
"additionalProperties": false,
|
|
744
736
|
"properties": {
|
|
745
737
|
"contact": {
|
|
746
|
-
"$id": "dxn:type:example.com/type/
|
|
738
|
+
"$id": "dxn:type:example.com/type/Person",
|
|
747
739
|
"additionalProperties": false,
|
|
748
740
|
"entityKind": "object",
|
|
749
741
|
"properties": {
|
|
@@ -763,7 +755,7 @@ describe('json-to-effect', () => {
|
|
|
763
755
|
"id",
|
|
764
756
|
],
|
|
765
757
|
"type": "object",
|
|
766
|
-
"typename": "example.com/type/
|
|
758
|
+
"typename": "example.com/type/Person",
|
|
767
759
|
"version": "0.1.0",
|
|
768
760
|
},
|
|
769
761
|
},
|
|
@@ -784,7 +776,7 @@ describe('json-to-effect', () => {
|
|
|
784
776
|
|
|
785
777
|
describe('reference', () => {
|
|
786
778
|
test('reference annotation', () => {
|
|
787
|
-
const schema = Ref(Testing.
|
|
779
|
+
const schema = Ref(Testing.Person);
|
|
788
780
|
const jsonSchema = toJsonSchema(schema);
|
|
789
781
|
expect(jsonSchema).toEqual({
|
|
790
782
|
$id: '/schemas/echo/ref',
|
|
@@ -792,7 +784,7 @@ describe('reference', () => {
|
|
|
792
784
|
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
793
785
|
reference: {
|
|
794
786
|
schema: {
|
|
795
|
-
$ref: 'dxn:type:example.com/type/
|
|
787
|
+
$ref: 'dxn:type:example.com/type/Person',
|
|
796
788
|
},
|
|
797
789
|
schemaVersion: '0.1.0',
|
|
798
790
|
},
|
|
@@ -800,7 +792,7 @@ describe('reference', () => {
|
|
|
800
792
|
});
|
|
801
793
|
|
|
802
794
|
test('title annotation', () => {
|
|
803
|
-
const schema = Ref(Testing.
|
|
795
|
+
const schema = Ref(Testing.Person).annotations({ title: 'My custom title' });
|
|
804
796
|
const jsonSchema = toJsonSchema(schema);
|
|
805
797
|
expect(jsonSchema).toEqual({
|
|
806
798
|
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
@@ -810,7 +802,7 @@ describe('reference', () => {
|
|
|
810
802
|
$ref: '/schemas/echo/ref',
|
|
811
803
|
reference: {
|
|
812
804
|
schema: {
|
|
813
|
-
$ref: 'dxn:type:example.com/type/
|
|
805
|
+
$ref: 'dxn:type:example.com/type/Person',
|
|
814
806
|
},
|
|
815
807
|
schemaVersion: '0.1.0',
|
|
816
808
|
},
|
|
@@ -821,7 +813,7 @@ describe('reference', () => {
|
|
|
821
813
|
});
|
|
822
814
|
|
|
823
815
|
test('description annotation', () => {
|
|
824
|
-
const schema = Ref(Testing.
|
|
816
|
+
const schema = Ref(Testing.Person).annotations({ description: 'My custom description' });
|
|
825
817
|
const jsonSchema = toJsonSchema(schema);
|
|
826
818
|
expect(jsonSchema).toEqual({
|
|
827
819
|
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
@@ -831,7 +823,7 @@ describe('reference', () => {
|
|
|
831
823
|
$ref: '/schemas/echo/ref',
|
|
832
824
|
reference: {
|
|
833
825
|
schema: {
|
|
834
|
-
$ref: 'dxn:type:example.com/type/
|
|
826
|
+
$ref: 'dxn:type:example.com/type/Person',
|
|
835
827
|
},
|
|
836
828
|
schemaVersion: '0.1.0',
|
|
837
829
|
},
|
|
@@ -845,13 +837,13 @@ describe('reference', () => {
|
|
|
845
837
|
});
|
|
846
838
|
|
|
847
839
|
test('serialize and deserialize', () => {
|
|
848
|
-
const schema = Ref(Testing.
|
|
840
|
+
const schema = Ref(Testing.Person);
|
|
849
841
|
const jsonSchema = toJsonSchema(schema);
|
|
850
842
|
const deserializedSchema = toEffectSchema(jsonSchema);
|
|
851
843
|
const refAst = getReferenceAst(deserializedSchema.ast);
|
|
852
844
|
expect(refAst).toEqual({
|
|
853
|
-
typename: Testing.
|
|
854
|
-
version: Testing.
|
|
845
|
+
typename: Testing.Person.typename,
|
|
846
|
+
version: Testing.Person.version,
|
|
855
847
|
});
|
|
856
848
|
});
|
|
857
849
|
});
|
|
@@ -34,7 +34,7 @@ describe('create (static version)', () => {
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test('create static object', () => {
|
|
37
|
-
const contact = create(Testing.
|
|
37
|
+
const contact = create(Testing.Person, {
|
|
38
38
|
name: 'Bot',
|
|
39
39
|
email: 'bot@example.com',
|
|
40
40
|
});
|
|
@@ -43,12 +43,12 @@ describe('create (static version)', () => {
|
|
|
43
43
|
expect(contact.name).toBe('Bot');
|
|
44
44
|
expect(contact.email).toBe('bot@example.com');
|
|
45
45
|
expect((contact as any)['@type']).toBeUndefined();
|
|
46
|
-
expect(getType(contact)?.toString()).toBe(getSchemaDXN(Testing.
|
|
47
|
-
expect(isInstanceOf(Testing.
|
|
46
|
+
expect(getType(contact)?.toString()).toBe(getSchemaDXN(Testing.Person)!.toString());
|
|
47
|
+
expect(isInstanceOf(Testing.Person, contact)).toBe(true);
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
test('JSON encoding', () => {
|
|
51
|
-
const contact = create(Testing.
|
|
51
|
+
const contact = create(Testing.Person, {
|
|
52
52
|
name: 'Bot',
|
|
53
53
|
email: 'bot@example.com',
|
|
54
54
|
});
|
|
@@ -56,7 +56,7 @@ describe('create (static version)', () => {
|
|
|
56
56
|
const json = JSON.parse(JSON.stringify(contact));
|
|
57
57
|
expect(json).toEqual({
|
|
58
58
|
id: contact.id,
|
|
59
|
-
'@type': DXN.fromTypenameAndVersion(Testing.
|
|
59
|
+
'@type': DXN.fromTypenameAndVersion(Testing.Person.typename, Testing.Person.version).toString(),
|
|
60
60
|
'@meta': {
|
|
61
61
|
keys: [],
|
|
62
62
|
},
|
|
@@ -67,11 +67,11 @@ describe('create (static version)', () => {
|
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
test('JSON encoding with relation', () => {
|
|
70
|
-
const contactA = create(Testing.
|
|
70
|
+
const contactA = create(Testing.Person, {
|
|
71
71
|
name: 'Bot',
|
|
72
72
|
email: 'bot@example.com',
|
|
73
73
|
});
|
|
74
|
-
const contactB = create(Testing.
|
|
74
|
+
const contactB = create(Testing.Person, {
|
|
75
75
|
name: 'Bot',
|
|
76
76
|
email: 'bot@example.com',
|
|
77
77
|
});
|
|
@@ -93,16 +93,16 @@ describe('create (static version)', () => {
|
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
test('getSchema', () => {
|
|
96
|
-
const contact = create(Testing.
|
|
96
|
+
const contact = create(Testing.Person, {
|
|
97
97
|
name: 'Bot',
|
|
98
98
|
email: 'bot@example.com',
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
expect(getSchema(contact)).toBe(Testing.
|
|
101
|
+
expect(getSchema(contact)).toBe(Testing.Person);
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
test('inspect', () => {
|
|
105
|
-
const contact = create(Testing.
|
|
105
|
+
const contact = create(Testing.Person, {
|
|
106
106
|
name: 'Bot',
|
|
107
107
|
email: 'bot@example.com',
|
|
108
108
|
});
|
|
@@ -112,7 +112,7 @@ describe('create (static version)', () => {
|
|
|
112
112
|
const text = inspect(contact);
|
|
113
113
|
expect(text).toContain('Bot');
|
|
114
114
|
expect(text).toContain('bot@example.com');
|
|
115
|
-
expect(text).toContain('example.com/type/
|
|
115
|
+
expect(text).toContain('example.com/type/Person');
|
|
116
116
|
expect(text).toContain('0.1.0');
|
|
117
117
|
});
|
|
118
118
|
});
|
|
@@ -45,7 +45,7 @@ type CreateData<T> = T extends { id: string } ? Omit<T, 'id' | typeof EntityKind
|
|
|
45
45
|
* name: Schema.String,
|
|
46
46
|
* email: Schema.String,
|
|
47
47
|
* }).pipe(Type.Obj({
|
|
48
|
-
* typename: 'example.com/type/
|
|
48
|
+
* typename: 'example.com/type/Person',
|
|
49
49
|
* version: '0.1.0',
|
|
50
50
|
* }))
|
|
51
51
|
*
|
|
@@ -19,7 +19,7 @@ import { getType, getTypename } from './typename';
|
|
|
19
19
|
|
|
20
20
|
describe('Object JSON serializer', () => {
|
|
21
21
|
test('should serialize and deserialize object', async () => {
|
|
22
|
-
const contact = create(Testing.
|
|
22
|
+
const contact = create(Testing.Person, {
|
|
23
23
|
name: 'John Doe',
|
|
24
24
|
});
|
|
25
25
|
getMeta(contact).keys.push({ id: '12345', source: 'crm.example.com' });
|
|
@@ -33,7 +33,7 @@ describe('Object JSON serializer', () => {
|
|
|
33
33
|
const taskJson = objectToJSON(task);
|
|
34
34
|
|
|
35
35
|
expect(contactJson.id).toBe(contact.id);
|
|
36
|
-
expect(contactJson[ATTR_TYPE]).toEqual(getSchemaDXN(Testing.
|
|
36
|
+
expect(contactJson[ATTR_TYPE]).toEqual(getSchemaDXN(Testing.Person)!.toString());
|
|
37
37
|
expect(contactJson.name).toEqual('John Doe');
|
|
38
38
|
|
|
39
39
|
expect(taskJson.id).toBe(task.id);
|
|
@@ -42,17 +42,17 @@ describe('Object JSON serializer', () => {
|
|
|
42
42
|
expect(taskJson.assignee).toEqual({ '/': DXN.fromLocalObjectId(contact.id).toString() });
|
|
43
43
|
|
|
44
44
|
const refResolver = new StaticRefResolver()
|
|
45
|
-
.addSchema(Testing.
|
|
45
|
+
.addSchema(Testing.Person)
|
|
46
46
|
.addSchema(Testing.Task)
|
|
47
47
|
.addObject(contact)
|
|
48
48
|
.addObject(task);
|
|
49
49
|
|
|
50
|
-
const contactFromJson = (await objectFromJSON(contactJson, { refResolver })) as Testing.
|
|
50
|
+
const contactFromJson = (await objectFromJSON(contactJson, { refResolver })) as Testing.Person;
|
|
51
51
|
const taskFromJson = (await objectFromJSON(taskJson, { refResolver })) as Testing.Task;
|
|
52
52
|
|
|
53
53
|
expect(contactFromJson.id).toBe(contact.id);
|
|
54
54
|
expect(contactFromJson.name).toBe('John Doe');
|
|
55
|
-
expect((contactFromJson as any)[TypeId]).toEqual(getSchemaDXN(Testing.
|
|
55
|
+
expect((contactFromJson as any)[TypeId]).toEqual(getSchemaDXN(Testing.Person));
|
|
56
56
|
expect((contactFromJson as any)[EntityKindId]).toBe(EntityKind.Object);
|
|
57
57
|
expect((contactFromJson as any)[RelationSourceId]).toBeUndefined();
|
|
58
58
|
expect((contactFromJson as any)[RelationTargetId]).toBeUndefined();
|
|
@@ -64,10 +64,10 @@ describe('Object JSON serializer', () => {
|
|
|
64
64
|
},
|
|
65
65
|
],
|
|
66
66
|
});
|
|
67
|
-
expect(getType(contactFromJson)?.toString()).toBe(getSchemaDXN(Testing.
|
|
68
|
-
expect(getTypename(contactFromJson)).toBe(getSchemaTypename(Testing.
|
|
67
|
+
expect(getType(contactFromJson)?.toString()).toBe(getSchemaDXN(Testing.Person)!.toString());
|
|
68
|
+
expect(getTypename(contactFromJson)).toBe(getSchemaTypename(Testing.Person));
|
|
69
69
|
expect(getObjectDXN(contactFromJson)?.toString()).toEqual(getObjectDXN(contact)?.toString());
|
|
70
|
-
expect(getSchema(contactFromJson)).toEqual(Testing.
|
|
70
|
+
expect(getSchema(contactFromJson)).toEqual(Testing.Person);
|
|
71
71
|
|
|
72
72
|
expect(taskFromJson.id).toBe(task.id);
|
|
73
73
|
expect(taskFromJson.title).toBe('Polish my shoes');
|
|
@@ -83,7 +83,7 @@ describe('Object JSON serializer', () => {
|
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
test('serialize with unresolved schema', async () => {
|
|
86
|
-
const contact = create(Testing.
|
|
86
|
+
const contact = create(Testing.Person, {
|
|
87
87
|
name: 'John Doe',
|
|
88
88
|
});
|
|
89
89
|
const contactJson = objectToJSON(contact);
|
|
@@ -92,8 +92,8 @@ describe('Object JSON serializer', () => {
|
|
|
92
92
|
expect(contactFromJson.id).toBe(contact.id);
|
|
93
93
|
expect(contactFromJson.name).toBe('John Doe');
|
|
94
94
|
expect(getSchema(contactFromJson)).toBeUndefined();
|
|
95
|
-
expect(getTypename(contactFromJson)).toEqual(getSchemaTypename(Testing.
|
|
95
|
+
expect(getTypename(contactFromJson)).toEqual(getSchemaTypename(Testing.Person));
|
|
96
96
|
expect(getObjectDXN(contactFromJson)).toEqual(getObjectDXN(contact));
|
|
97
|
-
expect(getType(contactFromJson)).toEqual(getSchemaDXN(Testing.
|
|
97
|
+
expect(getType(contactFromJson)).toEqual(getSchemaDXN(Testing.Person));
|
|
98
98
|
});
|
|
99
99
|
});
|
|
@@ -44,7 +44,7 @@ export const setTypename = (obj: any, typename: DXN) => {
|
|
|
44
44
|
/**
|
|
45
45
|
* @returns Object type as {@link DXN}.
|
|
46
46
|
* @returns undefined if the object doesn't have a type.
|
|
47
|
-
* @example `dxn:example.com/type/
|
|
47
|
+
* @example `dxn:example.com/type/Person:1.0.0`
|
|
48
48
|
*/
|
|
49
49
|
export const getType = (obj: BaseObject): DXN | undefined => {
|
|
50
50
|
if (!obj) {
|
|
@@ -65,11 +65,11 @@ describe('complex schema validations', () => {
|
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
test('nesting static objects with schema in the live object', () => {
|
|
68
|
-
const contact1 = create(Testing.
|
|
68
|
+
const contact1 = create(Testing.Person, {
|
|
69
69
|
name: 'Robert Smith',
|
|
70
70
|
email: 'robert@example.com',
|
|
71
71
|
} as any);
|
|
72
|
-
const contact2 = create(Testing.
|
|
72
|
+
const contact2 = create(Testing.Person, {
|
|
73
73
|
name: 'Katy Perry',
|
|
74
74
|
email: 'katy@example.com',
|
|
75
75
|
} as any);
|
|
@@ -78,16 +78,16 @@ describe('complex schema validations', () => {
|
|
|
78
78
|
contacts: [contact1],
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
-
expect(isInstanceOf(Testing.
|
|
82
|
-
expect(getSchema(contactBook.contacts[0])).to.eq(Testing.
|
|
81
|
+
expect(isInstanceOf(Testing.Person, contactBook.contacts[0])).to.eq(true);
|
|
82
|
+
expect(getSchema(contactBook.contacts[0])).to.eq(Testing.Person);
|
|
83
83
|
|
|
84
84
|
contactBook.contacts.push(contact2);
|
|
85
|
-
expect(isInstanceOf(Testing.
|
|
86
|
-
expect(getSchema(contactBook.contacts[1])).to.eq(Testing.
|
|
85
|
+
expect(isInstanceOf(Testing.Person, contactBook.contacts[1])).to.eq(true);
|
|
86
|
+
expect(getSchema(contactBook.contacts[1])).to.eq(Testing.Person);
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
test('creating an object with data from another object', () => {
|
|
90
|
-
const contact = live(Testing.
|
|
90
|
+
const contact = live(Testing.Person, {
|
|
91
91
|
name: 'Robert Smith',
|
|
92
92
|
email: 'robert@example.com',
|
|
93
93
|
});
|