@dxos/echo-generator 0.8.4-main.c85a9c8dae → 0.8.4-main.d05539e30a
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/neutral/index.mjs +48 -73
- package/dist/lib/neutral/index.mjs.map +3 -3
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/types/src/data.d.ts +4 -4
- package/dist/types/src/data.d.ts.map +1 -1
- package/dist/types/src/generator.d.ts +1 -1
- package/dist/types/src/generator.d.ts.map +1 -1
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -17
- package/src/data.ts +22 -22
- package/src/generator.test.ts +7 -6
- package/src/generator.ts +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-generator",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.d05539e30a",
|
|
4
4
|
"description": "ECHO data generator for testing.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/dxos/dxos"
|
|
10
10
|
},
|
|
11
|
-
"license": "
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
12
12
|
"author": "info@dxos.org",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"type": "module",
|
|
@@ -20,30 +20,28 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"types": "dist/types/src/index.d.ts",
|
|
23
|
-
"typesVersions": {
|
|
24
|
-
"*": {}
|
|
25
|
-
},
|
|
26
23
|
"files": [
|
|
27
24
|
"dist",
|
|
28
25
|
"src"
|
|
29
26
|
],
|
|
30
27
|
"dependencies": {
|
|
31
|
-
"@automerge/automerge": "3.2.
|
|
32
|
-
"effect": "3.
|
|
33
|
-
"@dxos/client": "0.8.4-main.
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/echo": "0.8.4-main.
|
|
37
|
-
"@dxos/log": "0.8.4-main.
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/node-std": "0.8.4-main.
|
|
28
|
+
"@automerge/automerge": "3.2.6",
|
|
29
|
+
"effect": "3.20.0",
|
|
30
|
+
"@dxos/client": "0.8.4-main.d05539e30a",
|
|
31
|
+
"@dxos/context": "0.8.4-main.d05539e30a",
|
|
32
|
+
"@dxos/echo": "0.8.4-main.d05539e30a",
|
|
33
|
+
"@dxos/echo-db": "0.8.4-main.d05539e30a",
|
|
34
|
+
"@dxos/log": "0.8.4-main.d05539e30a",
|
|
35
|
+
"@dxos/invariant": "0.8.4-main.d05539e30a",
|
|
36
|
+
"@dxos/node-std": "0.8.4-main.d05539e30a",
|
|
37
|
+
"@dxos/util": "0.8.4-main.d05539e30a"
|
|
40
38
|
},
|
|
41
39
|
"devDependencies": {
|
|
42
|
-
"@dxos/random": "0.8.4-main.
|
|
40
|
+
"@dxos/random": "0.8.4-main.d05539e30a"
|
|
43
41
|
},
|
|
44
42
|
"peerDependencies": {
|
|
45
|
-
"effect": "3.
|
|
46
|
-
"@dxos/random": "0.8.4-main.
|
|
43
|
+
"effect": "3.20.0",
|
|
44
|
+
"@dxos/random": "0.8.4-main.d05539e30a"
|
|
47
45
|
},
|
|
48
46
|
"publishConfig": {
|
|
49
47
|
"access": "public"
|
package/src/data.ts
CHANGED
|
@@ -8,7 +8,7 @@ import * as Schema from 'effect/Schema';
|
|
|
8
8
|
import { type Space } from '@dxos/client/echo';
|
|
9
9
|
import { Ref, Type } from '@dxos/echo';
|
|
10
10
|
import { createDocAccessor } from '@dxos/echo-db';
|
|
11
|
-
import {
|
|
11
|
+
import { random } from '@dxos/random';
|
|
12
12
|
|
|
13
13
|
import { SpaceObjectGenerator, TestObjectGenerator } from './generator';
|
|
14
14
|
import { type TestGeneratorMap, type TestMutationsMap, type TestSchemaMap } from './types';
|
|
@@ -25,10 +25,10 @@ export const Priority = [1, 2, 3, 4, 5];
|
|
|
25
25
|
* @deprecated
|
|
26
26
|
*/
|
|
27
27
|
export enum TestSchemaType {
|
|
28
|
-
document = 'example.
|
|
29
|
-
organization = 'example.
|
|
30
|
-
contact = 'example.
|
|
31
|
-
project = 'example.
|
|
28
|
+
document = 'com.example.type.document',
|
|
29
|
+
organization = 'com.example.type.organization',
|
|
30
|
+
contact = 'com.example.type.person',
|
|
31
|
+
project = 'com.example.type.project',
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -75,39 +75,39 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
75
75
|
|
|
76
76
|
const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {
|
|
77
77
|
[TestSchemaType.document]: async () => ({
|
|
78
|
-
title:
|
|
79
|
-
content:
|
|
78
|
+
title: random.lorem.sentence(3),
|
|
79
|
+
content: random.lorem.sentences({ min: 1, max: random.number.int({ min: 1, max: 3 }) }),
|
|
80
80
|
}),
|
|
81
81
|
|
|
82
82
|
[TestSchemaType.organization]: async () => ({
|
|
83
|
-
name:
|
|
84
|
-
website:
|
|
85
|
-
description:
|
|
83
|
+
name: random.company.name(),
|
|
84
|
+
website: random.datatype.boolean({ probability: 0.3 }) ? random.internet.url() : undefined,
|
|
85
|
+
description: random.lorem.sentences(),
|
|
86
86
|
}),
|
|
87
87
|
|
|
88
88
|
[TestSchemaType.contact]: async (provider) => {
|
|
89
89
|
const organizations = await provider?.(TestSchemaType.organization);
|
|
90
|
-
const location =
|
|
90
|
+
const location = random.datatype.boolean() ? random.geo.airport() : {};
|
|
91
91
|
|
|
92
92
|
return {
|
|
93
|
-
name:
|
|
94
|
-
email:
|
|
93
|
+
name: random.person.fullName(),
|
|
94
|
+
email: random.datatype.boolean({ probability: 0.5 }) ? random.internet.email() : undefined,
|
|
95
95
|
org:
|
|
96
|
-
organizations?.length &&
|
|
97
|
-
? Ref.make(
|
|
96
|
+
organizations?.length && random.datatype.boolean({ probability: 0.8 })
|
|
97
|
+
? Ref.make(random.helpers.arrayElement(organizations))
|
|
98
98
|
: undefined,
|
|
99
99
|
...location,
|
|
100
100
|
};
|
|
101
101
|
},
|
|
102
102
|
|
|
103
103
|
[TestSchemaType.project]: async () => ({
|
|
104
|
-
name:
|
|
105
|
-
repo:
|
|
106
|
-
status:
|
|
107
|
-
description:
|
|
108
|
-
website:
|
|
109
|
-
priority:
|
|
110
|
-
active:
|
|
104
|
+
name: random.commerce.productName(),
|
|
105
|
+
repo: random.internet.url(),
|
|
106
|
+
status: random.helpers.arrayElement(Status),
|
|
107
|
+
description: random.lorem.sentences(),
|
|
108
|
+
website: random.internet.url(),
|
|
109
|
+
priority: random.helpers.arrayElement(Priority),
|
|
110
|
+
active: random.datatype.boolean(),
|
|
111
111
|
}),
|
|
112
112
|
};
|
|
113
113
|
|
package/src/generator.test.ts
CHANGED
|
@@ -9,12 +9,12 @@ import { describe, expect, onTestFinished, test } from 'vitest';
|
|
|
9
9
|
import { Client } from '@dxos/client';
|
|
10
10
|
import { Obj, Type } from '@dxos/echo';
|
|
11
11
|
import { getObjectCore } from '@dxos/echo-db';
|
|
12
|
-
import {
|
|
12
|
+
import { random } from '@dxos/random';
|
|
13
13
|
|
|
14
14
|
import { TestSchemaType, createSpaceObjectGenerator, createTestObjectGenerator } from './data';
|
|
15
15
|
import { SpaceObjectGenerator } from './generator';
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
random.seed(3);
|
|
18
18
|
|
|
19
19
|
describe('TestObjectGenerator', () => {
|
|
20
20
|
// TODO(burdon): Use TestBuilder.
|
|
@@ -73,7 +73,8 @@ describe('TestObjectGenerator', () => {
|
|
|
73
73
|
expect(schemaId[0]).to.eq(schemaId[1]);
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
// flaky
|
|
77
|
+
test.skip('mutations', async () => {
|
|
77
78
|
const { space } = await setupTest();
|
|
78
79
|
const generator = createSpaceObjectGenerator(space);
|
|
79
80
|
await generator.addSchemas();
|
|
@@ -96,13 +97,13 @@ describe('TestObjectGenerator', () => {
|
|
|
96
97
|
name: Schema.optional(Schema.String),
|
|
97
98
|
}).pipe(
|
|
98
99
|
Type.object({
|
|
99
|
-
typename: 'example.
|
|
100
|
+
typename: 'com.example.type.task',
|
|
100
101
|
version: '0.1.0',
|
|
101
102
|
}),
|
|
102
103
|
);
|
|
103
104
|
|
|
104
105
|
enum Types {
|
|
105
|
-
task = 'example.
|
|
106
|
+
task = 'com.example.type.task',
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
const { space } = await setupTest();
|
|
@@ -117,7 +118,7 @@ describe('TestObjectGenerator', () => {
|
|
|
117
118
|
{
|
|
118
119
|
[Types.task]: async (task, params) => {
|
|
119
120
|
for (const _ in Array.from({ length: params.count })) {
|
|
120
|
-
task.name =
|
|
121
|
+
task.name = random.lorem.sentence();
|
|
121
122
|
}
|
|
122
123
|
},
|
|
123
124
|
},
|
package/src/generator.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { Obj, type Type } from '@dxos/echo';
|
|
5
|
+
import { type Space } from '@dxos/client/echo';
|
|
6
|
+
import { Filter, Obj, type Type } from '@dxos/echo';
|
|
7
7
|
import { EchoSchema, getTypeAnnotation } from '@dxos/echo/internal';
|
|
8
8
|
import { isProxy } from '@dxos/echo/internal';
|
|
9
9
|
import { invariant } from '@dxos/invariant';
|
|
10
|
-
import {
|
|
10
|
+
import { random } from '@dxos/random';
|
|
11
11
|
import { entries, range } from '@dxos/util';
|
|
12
12
|
|
|
13
13
|
import { type TestSchemaType } from './data';
|
|
@@ -44,7 +44,7 @@ export class TestObjectGenerator<T extends string = TestSchemaType> {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
async createObject({ types }: { types?: T[] } = {}): Promise<any> {
|
|
47
|
-
const type =
|
|
47
|
+
const type = random.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));
|
|
48
48
|
const data = await this._generators[type](this._provider);
|
|
49
49
|
if (isProxy(data)) {
|
|
50
50
|
return data;
|