@dxos/echo-generator 0.8.2-main.fbd8ed0 → 0.8.2-staging.4d6ad0f
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 +64 -58
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +65 -59
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +64 -58
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/data.d.ts +13 -4
- package/dist/types/src/data.d.ts.map +1 -1
- package/dist/types/src/generator.d.ts +1 -0
- package/dist/types/src/generator.d.ts.map +1 -1
- package/package.json +13 -12
- package/src/data.ts +52 -62
- package/src/generator.test.ts +29 -2
- package/src/generator.ts +12 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-generator",
|
|
3
|
-
"version": "0.8.2-
|
|
3
|
+
"version": "0.8.2-staging.4d6ad0f",
|
|
4
4
|
"description": "ECHO data generator for testing.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -24,23 +24,24 @@
|
|
|
24
24
|
"src"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@automerge/automerge": "3.0.0-beta.
|
|
27
|
+
"@automerge/automerge": "3.0.0-beta.4",
|
|
28
28
|
"effect": "3.14.21",
|
|
29
|
-
"@dxos/client": "0.8.2-
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/live-object": "0.8.2-
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/
|
|
29
|
+
"@dxos/client": "0.8.2-staging.4d6ad0f",
|
|
30
|
+
"@dxos/echo-schema": "0.8.2-staging.4d6ad0f",
|
|
31
|
+
"@dxos/invariant": "0.8.2-staging.4d6ad0f",
|
|
32
|
+
"@dxos/live-object": "0.8.2-staging.4d6ad0f",
|
|
33
|
+
"@dxos/log": "0.8.2-staging.4d6ad0f",
|
|
34
|
+
"@dxos/echo-db": "0.8.2-staging.4d6ad0f",
|
|
35
|
+
"@dxos/node-std": "0.8.2-staging.4d6ad0f",
|
|
36
|
+
"@dxos/schema": "0.8.2-staging.4d6ad0f",
|
|
37
|
+
"@dxos/util": "0.8.2-staging.4d6ad0f"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@dxos/random": "0.8.2-
|
|
40
|
+
"@dxos/random": "0.8.2-staging.4d6ad0f"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
43
|
"effect": "^3.13.3",
|
|
43
|
-
"@dxos/random": "0.8.2-
|
|
44
|
+
"@dxos/random": "0.8.2-staging.4d6ad0f"
|
|
44
45
|
},
|
|
45
46
|
"publishConfig": {
|
|
46
47
|
"access": "public"
|
package/src/data.ts
CHANGED
|
@@ -6,8 +6,7 @@ import { next as A } from '@automerge/automerge';
|
|
|
6
6
|
import { Schema } from 'effect';
|
|
7
7
|
|
|
8
8
|
import { createDocAccessor, type Space } from '@dxos/client/echo';
|
|
9
|
-
import { Ref } from '@dxos/echo-schema';
|
|
10
|
-
import { createEchoSchema } from '@dxos/live-object';
|
|
9
|
+
import { EchoObject, Ref } from '@dxos/echo-schema';
|
|
11
10
|
import { faker } from '@dxos/random';
|
|
12
11
|
|
|
13
12
|
import { SpaceObjectGenerator, TestObjectGenerator } from './generator';
|
|
@@ -21,67 +20,49 @@ import { randomText } from './util';
|
|
|
21
20
|
export const Status = ['pending', 'active', 'done'];
|
|
22
21
|
export const Priority = [1, 2, 3, 4, 5];
|
|
23
22
|
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated
|
|
25
|
+
*/
|
|
24
26
|
export enum TestSchemaType {
|
|
25
|
-
document = 'example.com/type/
|
|
26
|
-
organization = 'example.com/type/
|
|
27
|
-
contact = 'example.com/type/
|
|
28
|
-
project = 'example.com/type/
|
|
27
|
+
document = 'example.com/type/Document',
|
|
28
|
+
organization = 'example.com/type/Organization',
|
|
29
|
+
contact = 'example.com/type/Contact',
|
|
30
|
+
project = 'example.com/type/Project',
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated
|
|
35
|
+
*/
|
|
31
36
|
const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
32
|
-
const document =
|
|
33
|
-
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
name: Schema.String.annotations({ description: 'name of the person' }),
|
|
62
|
-
email: Schema.String,
|
|
63
|
-
org: Ref(organization),
|
|
64
|
-
lat: Schema.Number,
|
|
65
|
-
lng: Schema.Number,
|
|
66
|
-
},
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const project = createEchoSchema(
|
|
70
|
-
{
|
|
71
|
-
typename: TestSchemaType.project,
|
|
72
|
-
version: '0.1.0',
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
name: Schema.String.annotations({ description: 'name of the project' }),
|
|
76
|
-
description: Schema.String,
|
|
77
|
-
website: Schema.String,
|
|
78
|
-
repo: Schema.String,
|
|
79
|
-
status: Schema.String,
|
|
80
|
-
priority: Schema.Number,
|
|
81
|
-
active: Schema.Boolean,
|
|
82
|
-
org: Ref(organization),
|
|
83
|
-
},
|
|
84
|
-
);
|
|
37
|
+
const document = Schema.Struct({
|
|
38
|
+
title: Schema.String.annotations({ description: 'title of the document' }),
|
|
39
|
+
content: Schema.String,
|
|
40
|
+
}).pipe(EchoObject({ typename: TestSchemaType.document, version: '0.1.0' }));
|
|
41
|
+
|
|
42
|
+
const organization = Schema.Struct({
|
|
43
|
+
name: Schema.String.annotations({ description: 'name of the company or organization' }),
|
|
44
|
+
website: Schema.optional(Schema.String.annotations({ description: 'public website URL' })),
|
|
45
|
+
description: Schema.String.annotations({ description: 'short summary of the company' }),
|
|
46
|
+
}).pipe(EchoObject({ typename: TestSchemaType.organization, version: '0.1.0' }));
|
|
47
|
+
|
|
48
|
+
const contact = Schema.Struct({
|
|
49
|
+
name: Schema.String.annotations({ description: 'name of the person' }),
|
|
50
|
+
email: Schema.optional(Schema.String),
|
|
51
|
+
org: Schema.optional(Ref(organization)),
|
|
52
|
+
lat: Schema.optional(Schema.Number),
|
|
53
|
+
lng: Schema.optional(Schema.Number),
|
|
54
|
+
}).pipe(EchoObject({ typename: TestSchemaType.contact, version: '0.1.0' }));
|
|
55
|
+
|
|
56
|
+
const project = Schema.Struct({
|
|
57
|
+
name: Schema.String.annotations({ description: 'name of the project' }),
|
|
58
|
+
description: Schema.String,
|
|
59
|
+
website: Schema.String,
|
|
60
|
+
repo: Schema.String,
|
|
61
|
+
status: Schema.String,
|
|
62
|
+
priority: Schema.Number,
|
|
63
|
+
active: Schema.Boolean,
|
|
64
|
+
org: Schema.optional(Ref(organization)),
|
|
65
|
+
}).pipe(EchoObject({ typename: TestSchemaType.project, version: '0.1.0' }));
|
|
85
66
|
|
|
86
67
|
return {
|
|
87
68
|
[TestSchemaType.document]: document,
|
|
@@ -105,12 +86,13 @@ const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {
|
|
|
105
86
|
|
|
106
87
|
[TestSchemaType.contact]: async (provider) => {
|
|
107
88
|
const organizations = await provider?.(TestSchemaType.organization);
|
|
108
|
-
const
|
|
89
|
+
const location = faker.datatype.boolean() ? faker.geo.airport() : {};
|
|
90
|
+
|
|
109
91
|
return {
|
|
110
92
|
name: faker.person.fullName(),
|
|
111
93
|
email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,
|
|
112
94
|
org:
|
|
113
|
-
organizations?.length && faker.datatype.boolean({ probability: 0.
|
|
95
|
+
organizations?.length && faker.datatype.boolean({ probability: 0.8 })
|
|
114
96
|
? Ref.make(faker.helpers.arrayElement(organizations))
|
|
115
97
|
: undefined,
|
|
116
98
|
...location,
|
|
@@ -119,8 +101,10 @@ const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {
|
|
|
119
101
|
|
|
120
102
|
[TestSchemaType.project]: async () => ({
|
|
121
103
|
name: faker.commerce.productName(),
|
|
122
|
-
repo: faker.
|
|
104
|
+
repo: faker.internet.url(),
|
|
123
105
|
status: faker.helpers.arrayElement(Status),
|
|
106
|
+
description: faker.lorem.sentences(),
|
|
107
|
+
website: faker.internet.url(),
|
|
124
108
|
priority: faker.helpers.arrayElement(Priority),
|
|
125
109
|
active: faker.datatype.boolean(),
|
|
126
110
|
}),
|
|
@@ -153,7 +137,13 @@ const testObjectMutators: TestMutationsMap<TestSchemaType> = {
|
|
|
153
137
|
},
|
|
154
138
|
};
|
|
155
139
|
|
|
140
|
+
/**
|
|
141
|
+
* @deprecated Use generators in schema package.
|
|
142
|
+
*/
|
|
156
143
|
export const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);
|
|
157
144
|
|
|
145
|
+
/**
|
|
146
|
+
* @deprecated Use generators in schema package.
|
|
147
|
+
*/
|
|
158
148
|
export const createSpaceObjectGenerator = (space: Space) =>
|
|
159
149
|
new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators, testObjectMutators);
|
package/src/generator.test.ts
CHANGED
|
@@ -60,14 +60,14 @@ describe('TestObjectGenerator', () => {
|
|
|
60
60
|
const generator = createSpaceObjectGenerator(space);
|
|
61
61
|
await generator.addSchemas();
|
|
62
62
|
const organization = await generator.createObject({ types: [TestSchemaType.organization] });
|
|
63
|
-
schemaId.push(getType(organization)!.
|
|
63
|
+
schemaId.push(getType(organization)!.toString());
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
{
|
|
67
67
|
const generator = createSpaceObjectGenerator(space);
|
|
68
68
|
await generator.addSchemas();
|
|
69
69
|
const organization = await generator.createObject({ types: [TestSchemaType.organization] });
|
|
70
|
-
schemaId.push(getType(organization)!.
|
|
70
|
+
schemaId.push(getType(organization)!.toString());
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
expect(schemaId[0]).not.to.be.undefined;
|
|
@@ -124,4 +124,31 @@ describe('TestObjectGenerator', () => {
|
|
|
124
124
|
const todo = await generator.createObject({ types: [Types.task] });
|
|
125
125
|
expect(getType(todo)).to.exist;
|
|
126
126
|
});
|
|
127
|
+
|
|
128
|
+
test('references', async () => {
|
|
129
|
+
const { space } = await setupTest();
|
|
130
|
+
const generator = createSpaceObjectGenerator(space);
|
|
131
|
+
await generator.addSchemas();
|
|
132
|
+
|
|
133
|
+
// Create raw object.
|
|
134
|
+
const objects = await generator.createObjects({
|
|
135
|
+
[TestSchemaType.organization]: 1,
|
|
136
|
+
[TestSchemaType.contact]: 1,
|
|
137
|
+
});
|
|
138
|
+
expect(objects).to.exist;
|
|
139
|
+
expect(objects.length).to.be.eq(2);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('create project', async () => {
|
|
143
|
+
const generator = createTestObjectGenerator();
|
|
144
|
+
const project = await generator.createObject({ types: [TestSchemaType.project] });
|
|
145
|
+
expect(getType(project)).to.exist;
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('create object with not type', async () => {
|
|
149
|
+
// TODO(burdon): Create Client/spaces.
|
|
150
|
+
const generator = createTestObjectGenerator();
|
|
151
|
+
|
|
152
|
+
await generator.createObject();
|
|
153
|
+
});
|
|
127
154
|
});
|
package/src/generator.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { getTypeAnnotation, EchoSchema, getSchema } from '@dxos/echo-schema';
|
|
|
10
10
|
import { invariant } from '@dxos/invariant';
|
|
11
11
|
import { live, isLiveObject, type Live } from '@dxos/live-object';
|
|
12
12
|
import { faker } from '@dxos/random';
|
|
13
|
-
import { range } from '@dxos/util';
|
|
13
|
+
import { entries, range } from '@dxos/util';
|
|
14
14
|
|
|
15
15
|
import { type TestSchemaType } from './data';
|
|
16
16
|
import {
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Typed object generator.
|
|
26
|
+
* @deprecated
|
|
26
27
|
*/
|
|
27
28
|
export class TestObjectGenerator<T extends string = TestSchemaType> {
|
|
28
29
|
// prettier-ignore
|
|
@@ -40,7 +41,7 @@ export class TestObjectGenerator<T extends string = TestSchemaType> {
|
|
|
40
41
|
return this.schemas.find((schema) => getTypeAnnotation(schema)!.typename === type);
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
protected setSchema(type: T, schema: EchoSchema | Schema.Schema.AnyNoContext) {
|
|
44
|
+
protected setSchema(type: T, schema: EchoSchema | Schema.Schema.AnyNoContext): void {
|
|
44
45
|
this._schemas[type] = schema;
|
|
45
46
|
}
|
|
46
47
|
|
|
@@ -57,6 +58,11 @@ export class TestObjectGenerator<T extends string = TestSchemaType> {
|
|
|
57
58
|
|
|
58
59
|
// TODO(burdon): Based on dependencies (e.g., organization before contact).
|
|
59
60
|
async createObjects(map: Partial<Record<T, number>>) {
|
|
61
|
+
const results: Live<any>[] = [];
|
|
62
|
+
for (const [type, count] of entries(map)) {
|
|
63
|
+
results.push(...(await Promise.all(range(count ?? 0, () => this.createObject({ types: [type as T] })))));
|
|
64
|
+
}
|
|
65
|
+
|
|
60
66
|
const tasks = Object.entries<number>(map as any)
|
|
61
67
|
.map(([type, count]) => {
|
|
62
68
|
return range(count, () => this.createObject({ types: [type as T] }));
|
|
@@ -79,7 +85,8 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
79
85
|
) {
|
|
80
86
|
super(schemaMap, generators, async (type: T) => {
|
|
81
87
|
const schema = this.getSchema(type);
|
|
82
|
-
|
|
88
|
+
const { objects } = await this._space.db.query(schema ? Filter.type(schema) : Filter.nothing()).run();
|
|
89
|
+
return objects;
|
|
83
90
|
});
|
|
84
91
|
}
|
|
85
92
|
|
|
@@ -119,7 +126,7 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
119
126
|
}
|
|
120
127
|
}
|
|
121
128
|
|
|
122
|
-
async mutateObject(object: AnyLiveObject<any>, params: MutationsProviderParams) {
|
|
129
|
+
async mutateObject(object: AnyLiveObject<any>, params: MutationsProviderParams): Promise<void> {
|
|
123
130
|
invariant(this._mutations, 'Mutations not defined.');
|
|
124
131
|
const type = getTypeAnnotation(getSchema(object)!)!.typename as T;
|
|
125
132
|
invariant(type && this._mutations?.[type], 'Invalid object type.');
|
|
@@ -127,7 +134,7 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
127
134
|
await this._mutations;
|
|
128
135
|
}
|
|
129
136
|
|
|
130
|
-
async mutateObjects(objects: AnyLiveObject<any>[], params: MutationsProviderParams) {
|
|
137
|
+
async mutateObjects(objects: AnyLiveObject<any>[], params: MutationsProviderParams): Promise<void> {
|
|
131
138
|
for (const object of objects) {
|
|
132
139
|
await this.mutateObject(object, params);
|
|
133
140
|
}
|