@dxos/echo-generator 0.3.7-main.fcec8cd → 0.3.7
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 +89 -57
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +69 -36
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/data.d.ts +6 -1
- package/dist/types/src/data.d.ts.map +1 -1
- package/dist/types/src/generator.d.ts +8 -10
- package/dist/types/src/generator.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +1 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/data.ts +23 -13
- package/src/generator.test.ts +37 -6
- package/src/generator.ts +43 -21
- package/src/types.ts +2 -2
|
@@ -2,11 +2,11 @@ import "@dxos/node-std/globals";
|
|
|
2
2
|
|
|
3
3
|
// packages/core/echo/echo-generator/src/data.ts
|
|
4
4
|
import { faker as faker2 } from "@faker-js/faker";
|
|
5
|
-
import { Schema, TextObject } from "@dxos/client/echo";
|
|
5
|
+
import { Schema as Schema2, TextObject } from "@dxos/client/echo";
|
|
6
6
|
|
|
7
7
|
// packages/core/echo/echo-generator/src/generator.ts
|
|
8
8
|
import { faker } from "@faker-js/faker";
|
|
9
|
-
import { Expando } from "@dxos/client/echo";
|
|
9
|
+
import { Expando, Schema } from "@dxos/client/echo";
|
|
10
10
|
|
|
11
11
|
// packages/core/echo/echo-generator/src/util.ts
|
|
12
12
|
var range = (fn, length) => Array.from({
|
|
@@ -16,44 +16,67 @@ var range = (fn, length) => Array.from({
|
|
|
16
16
|
// packages/core/echo/echo-generator/src/generator.ts
|
|
17
17
|
var TestObjectGenerator = class {
|
|
18
18
|
// prettier-ignore
|
|
19
|
-
constructor(
|
|
20
|
-
this.
|
|
19
|
+
constructor(_schemas, _generators, _provider) {
|
|
20
|
+
this._schemas = _schemas;
|
|
21
21
|
this._generators = _generators;
|
|
22
22
|
this._provider = _provider;
|
|
23
23
|
}
|
|
24
24
|
get schemas() {
|
|
25
|
-
return Object.values(this.
|
|
25
|
+
return Object.values(this._schemas);
|
|
26
26
|
}
|
|
27
|
-
getSchema(
|
|
28
|
-
return this.schemas.find((schema) => schema.typename ===
|
|
27
|
+
getSchema(type) {
|
|
28
|
+
return this.schemas.find((schema) => schema.typename === type);
|
|
29
29
|
}
|
|
30
|
+
setSchema(type, schema) {
|
|
31
|
+
this._schemas[type] = schema;
|
|
32
|
+
}
|
|
33
|
+
// TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).
|
|
30
34
|
createObject({ types } = {}) {
|
|
31
|
-
const type = faker.helpers.arrayElement(types ?? Object.keys(this.
|
|
32
|
-
const
|
|
33
|
-
const
|
|
35
|
+
const type = faker.helpers.arrayElement(types ?? Object.keys(this._schemas));
|
|
36
|
+
const data = this._generators[type](this._provider);
|
|
37
|
+
const schema = this.getSchema(type);
|
|
34
38
|
return new Expando(data, {
|
|
35
|
-
schema
|
|
39
|
+
schema
|
|
36
40
|
});
|
|
37
41
|
}
|
|
38
42
|
// TODO(burdon): Create batch.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
// TODO(burdon): Based on dependencies (e.g., organization before contact).
|
|
44
|
+
createObjects(map) {
|
|
45
|
+
const objects = [];
|
|
46
|
+
Object.entries(map).forEach(([type, count]) => {
|
|
47
|
+
range(() => objects.push(this.createObject({
|
|
48
|
+
types: [
|
|
49
|
+
type
|
|
50
|
+
]
|
|
51
|
+
})), count);
|
|
52
|
+
});
|
|
53
|
+
return objects;
|
|
43
54
|
}
|
|
44
55
|
};
|
|
45
56
|
var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
46
|
-
constructor(_space,
|
|
47
|
-
super(
|
|
48
|
-
const { objects } = this._space.db.query((object) => {
|
|
49
|
-
return object.__schema ===
|
|
57
|
+
constructor(_space, schemaMap, generators) {
|
|
58
|
+
super(schemaMap, generators, (type) => {
|
|
59
|
+
const { objects: objects2 } = this._space.db.query((object) => {
|
|
60
|
+
return object.__schema?.id === this.getSchema(type)?.id;
|
|
50
61
|
});
|
|
51
|
-
return
|
|
62
|
+
return objects2;
|
|
52
63
|
});
|
|
53
64
|
this._space = _space;
|
|
65
|
+
const { objects } = this._space.db.query(Schema.filter());
|
|
66
|
+
Object.keys(schemaMap).forEach((type) => {
|
|
67
|
+
const schema = objects.find((object) => object.typename === type);
|
|
68
|
+
if (schema) {
|
|
69
|
+
this.setSchema(type, schema);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
54
72
|
}
|
|
55
73
|
addSchemas() {
|
|
56
|
-
|
|
74
|
+
const { objects } = this._space.db.query(Schema.filter());
|
|
75
|
+
this.schemas.forEach((schema) => {
|
|
76
|
+
if (!objects.find((object) => object.typename === schema.typename)) {
|
|
77
|
+
this._space.db.add(schema);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
57
80
|
return this.schemas;
|
|
58
81
|
}
|
|
59
82
|
createObject({ types } = {}) {
|
|
@@ -76,101 +99,109 @@ var Priority = [
|
|
|
76
99
|
4,
|
|
77
100
|
5
|
|
78
101
|
];
|
|
102
|
+
var TestSchemaType;
|
|
103
|
+
(function(TestSchemaType2) {
|
|
104
|
+
TestSchemaType2["document"] = "example.com/schema/document";
|
|
105
|
+
TestSchemaType2["organization"] = "example.com/schema/organization";
|
|
106
|
+
TestSchemaType2["contact"] = "example.com/schema/contact";
|
|
107
|
+
TestSchemaType2["project"] = "example.com/schema/project";
|
|
108
|
+
})(TestSchemaType || (TestSchemaType = {}));
|
|
79
109
|
var testSchemas = () => {
|
|
80
|
-
const document = new
|
|
110
|
+
const document = new Schema2({
|
|
111
|
+
typename: TestSchemaType.document,
|
|
81
112
|
props: [
|
|
82
113
|
{
|
|
83
114
|
id: "name",
|
|
84
|
-
type:
|
|
115
|
+
type: Schema2.PropType.STRING
|
|
85
116
|
},
|
|
86
117
|
{
|
|
87
118
|
id: "content",
|
|
88
|
-
type:
|
|
119
|
+
type: Schema2.PropType.STRING
|
|
89
120
|
}
|
|
90
121
|
]
|
|
91
122
|
});
|
|
92
|
-
const organization = new
|
|
93
|
-
typename:
|
|
123
|
+
const organization = new Schema2({
|
|
124
|
+
typename: TestSchemaType.organization,
|
|
94
125
|
props: [
|
|
95
126
|
{
|
|
96
127
|
id: "name",
|
|
97
|
-
type:
|
|
128
|
+
type: Schema2.PropType.STRING
|
|
98
129
|
},
|
|
99
130
|
{
|
|
100
131
|
id: "website",
|
|
101
|
-
type:
|
|
132
|
+
type: Schema2.PropType.STRING
|
|
102
133
|
},
|
|
103
134
|
{
|
|
104
135
|
id: "description",
|
|
105
|
-
type:
|
|
136
|
+
type: Schema2.PropType.STRING
|
|
106
137
|
}
|
|
107
138
|
]
|
|
108
139
|
});
|
|
109
|
-
const
|
|
110
|
-
typename:
|
|
140
|
+
const contact = new Schema2({
|
|
141
|
+
typename: TestSchemaType.contact,
|
|
111
142
|
props: [
|
|
112
143
|
{
|
|
113
144
|
id: "name",
|
|
114
|
-
type:
|
|
145
|
+
type: Schema2.PropType.STRING
|
|
115
146
|
},
|
|
116
147
|
{
|
|
117
148
|
id: "email",
|
|
118
|
-
type:
|
|
149
|
+
type: Schema2.PropType.STRING
|
|
119
150
|
},
|
|
120
151
|
{
|
|
121
152
|
id: "org",
|
|
122
|
-
type:
|
|
153
|
+
type: Schema2.PropType.REF,
|
|
123
154
|
ref: organization
|
|
124
155
|
},
|
|
125
156
|
// TODO(burdon): Convert to object with nested props.
|
|
126
157
|
{
|
|
127
158
|
id: "lat",
|
|
128
|
-
type:
|
|
159
|
+
type: Schema2.PropType.NUMBER
|
|
129
160
|
},
|
|
130
161
|
{
|
|
131
162
|
id: "lng",
|
|
132
|
-
type:
|
|
163
|
+
type: Schema2.PropType.NUMBER
|
|
133
164
|
}
|
|
134
165
|
]
|
|
135
166
|
});
|
|
136
|
-
const project = new
|
|
137
|
-
typename:
|
|
167
|
+
const project = new Schema2({
|
|
168
|
+
typename: TestSchemaType.project,
|
|
138
169
|
props: [
|
|
139
170
|
{
|
|
140
171
|
id: "title",
|
|
141
|
-
type:
|
|
172
|
+
type: Schema2.PropType.STRING
|
|
142
173
|
},
|
|
143
174
|
{
|
|
144
175
|
id: "description",
|
|
145
|
-
type:
|
|
176
|
+
type: Schema2.PropType.STRING
|
|
146
177
|
},
|
|
147
178
|
{
|
|
148
179
|
id: "repo",
|
|
149
|
-
type:
|
|
180
|
+
type: Schema2.PropType.STRING
|
|
150
181
|
},
|
|
151
182
|
{
|
|
152
183
|
id: "status",
|
|
153
|
-
type:
|
|
184
|
+
type: Schema2.PropType.STRING
|
|
154
185
|
},
|
|
155
186
|
{
|
|
156
187
|
id: "priority",
|
|
157
|
-
type:
|
|
188
|
+
type: Schema2.PropType.NUMBER
|
|
158
189
|
},
|
|
159
190
|
{
|
|
160
191
|
id: "active",
|
|
161
|
-
type:
|
|
192
|
+
type: Schema2.PropType.BOOLEAN
|
|
162
193
|
}
|
|
163
194
|
]
|
|
164
195
|
});
|
|
165
196
|
return {
|
|
166
|
-
document,
|
|
167
|
-
organization,
|
|
168
|
-
|
|
169
|
-
project
|
|
197
|
+
[TestSchemaType.document]: document,
|
|
198
|
+
[TestSchemaType.organization]: organization,
|
|
199
|
+
[TestSchemaType.contact]: contact,
|
|
200
|
+
[TestSchemaType.project]: project
|
|
170
201
|
};
|
|
171
202
|
};
|
|
172
203
|
var testObjectGenerators = {
|
|
173
|
-
document: () => ({
|
|
204
|
+
[TestSchemaType.document]: () => ({
|
|
174
205
|
title: faker2.lorem.sentence(3),
|
|
175
206
|
content: faker2.lorem.sentences({
|
|
176
207
|
min: 1,
|
|
@@ -180,15 +211,15 @@ var testObjectGenerators = {
|
|
|
180
211
|
})
|
|
181
212
|
})
|
|
182
213
|
}),
|
|
183
|
-
organization: () => ({
|
|
214
|
+
[TestSchemaType.organization]: () => ({
|
|
184
215
|
name: faker2.company.name(),
|
|
185
216
|
website: faker2.datatype.boolean({
|
|
186
217
|
probability: 0.3
|
|
187
218
|
}) ? faker2.internet.url() : void 0,
|
|
188
219
|
description: new TextObject(faker2.lorem.sentences())
|
|
189
220
|
}),
|
|
190
|
-
|
|
191
|
-
const organizations = provider?.(
|
|
221
|
+
[TestSchemaType.contact]: (provider) => {
|
|
222
|
+
const organizations = provider?.(TestSchemaType.organization);
|
|
192
223
|
const location = faker2.datatype.boolean() ? faker2.helpers.arrayElement(locations) : void 0;
|
|
193
224
|
return {
|
|
194
225
|
name: faker2.person.fullName(),
|
|
@@ -201,7 +232,7 @@ var testObjectGenerators = {
|
|
|
201
232
|
...location
|
|
202
233
|
};
|
|
203
234
|
},
|
|
204
|
-
project: () => ({
|
|
235
|
+
[TestSchemaType.project]: () => ({
|
|
205
236
|
title: faker2.commerce.productName(),
|
|
206
237
|
repo: faker2.datatype.boolean({
|
|
207
238
|
probability: 0.3
|
|
@@ -606,13 +637,13 @@ var locations = [
|
|
|
606
637
|
lat: 3.048606670909237,
|
|
607
638
|
lng: 36.765010656628135
|
|
608
639
|
},
|
|
609
|
-
{
|
|
610
|
-
lat: 12.481312562873995,
|
|
611
|
-
lng: 41.89790148509894
|
|
612
|
-
},
|
|
613
640
|
{
|
|
614
641
|
lat: 125.75274485499392,
|
|
615
642
|
lng: 39.02138455800434
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
lat: 12.481312562873995,
|
|
646
|
+
lng: 41.89790148509894
|
|
616
647
|
}
|
|
617
648
|
];
|
|
618
649
|
export {
|
|
@@ -620,6 +651,7 @@ export {
|
|
|
620
651
|
SpaceObjectGenerator,
|
|
621
652
|
Status,
|
|
622
653
|
TestObjectGenerator,
|
|
654
|
+
TestSchemaType,
|
|
623
655
|
createSpaceObjectGenerator,
|
|
624
656
|
createTestObjectGenerator,
|
|
625
657
|
range,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/data.ts", "../../../src/generator.ts", "../../../src/util.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.\n// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).\n\nimport { faker } from '@faker-js/faker';\n\nimport { Schema, type Space, TextObject } from '@dxos/client/echo';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestSchemaMap } from './types';\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport type TestSchemaType = 'document' | 'organization' | 'person' | 'project';\n\nexport const testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = new Schema({\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n // TODO(burdon): primary: true,\n },\n {\n id: 'content',\n type: Schema.PropType.STRING, // TODO(burdon): Rich text.\n },\n ],\n });\n\n const organization = new Schema({\n typename: 'example.com/schema/organization',\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'website',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING,\n },\n ],\n });\n\n const person = new Schema({\n typename: 'example.com/schema/person',\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'email',\n type: Schema.PropType.STRING,\n },\n {\n id: 'org',\n type: Schema.PropType.REF,\n ref: organization,\n },\n // TODO(burdon): Convert to object with nested props.\n {\n id: 'lat',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'lng',\n type: Schema.PropType.NUMBER,\n },\n ],\n });\n\n const project = new Schema({\n typename: 'example.com/schema/project',\n props: [\n {\n id: 'title',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING, // TODO(burdon): Text.\n },\n {\n id: 'repo',\n type: Schema.PropType.STRING,\n },\n {\n id: 'status',\n type: Schema.PropType.STRING,\n },\n {\n id: 'priority',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'active',\n type: Schema.PropType.BOOLEAN,\n },\n ],\n });\n\n return { document, organization, person, project };\n};\n\nexport const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n document: () => ({\n title: faker.lorem.sentence(3),\n content: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n\n organization: () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: new TextObject(faker.lorem.sentences()),\n }),\n\n person: (provider) => {\n const organizations = provider?.('organization');\n const location = faker.datatype.boolean() ? faker.helpers.arrayElement(locations) : undefined;\n return {\n name: faker.person.fullName(),\n email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,\n org:\n organizations?.length && faker.datatype.boolean({ probability: 0.3 })\n ? faker.helpers.arrayElement(organizations)\n : undefined,\n ...location,\n };\n },\n\n project: () => ({\n title: faker.commerce.productName(),\n repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n status: faker.helpers.arrayElement(Status),\n priority: faker.helpers.arrayElement(Priority),\n active: faker.datatype.boolean(),\n }),\n};\n\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);\n\nconst locations = [\n { lat: 139.74946157054467, lng: 35.686962764371174 },\n { lat: -73.98196278740681, lng: 40.75192492259464 },\n { lat: -99.1329340602939, lng: 19.444388301415472 },\n { lat: 72.85504343876647, lng: 19.0189362343566 },\n { lat: -46.62696583905523, lng: -23.55673372837896 },\n { lat: 77.22805816860182, lng: 28.671938757181522 },\n { lat: 121.43455881982015, lng: 31.218398311228327 },\n { lat: 88.32272979950551, lng: 22.49691515689642 },\n { lat: 90.40663360810754, lng: 23.725005570312817 },\n { lat: -58.399477232331435, lng: -34.600555749907414 },\n { lat: -118.18192636994041, lng: 33.99192410876543 },\n { lat: 66.98806305137339, lng: 24.87193814681484 },\n { lat: 31.248022361126118, lng: 30.051906205103705 },\n { lat: -43.22696665284366, lng: -22.923077315615956 },\n { lat: 135.4581989565952, lng: 34.75198107491417 },\n { lat: 116.38633982565943, lng: 39.93083808990906 },\n { lat: 120.9802713035424, lng: 14.606104813440538 },\n { lat: 37.6135769672714, lng: 55.75410998124818 },\n { lat: 29.008055727002613, lng: 41.10694201243979 },\n { lat: 2.33138946713035, lng: 48.86863878981461 },\n { lat: 126.99778513820195, lng: 37.56829495838895 },\n { lat: 3.3895852125984334, lng: 6.445207512093191 },\n { lat: 106.82749176247012, lng: -6.172471846798885 },\n { lat: -87.75200083270931, lng: 41.83193651927843 },\n { lat: 113.32306427226172, lng: 23.14692716047989 },\n { lat: -0.11866770247593195, lng: 51.5019405883275 },\n { lat: -77.05200795343472, lng: -12.04606681752557 },\n { lat: 51.42239817500899, lng: 35.673888627001304 },\n { lat: 15.313026023171744, lng: -4.327778243275986 },\n { lat: -74.08528981377441, lng: 4.598369421147822 },\n { lat: 114.1201772298325, lng: 22.554316369677963 },\n { lat: 114.26807118958311, lng: 30.581977209337822 },\n { lat: 114.18306345846304, lng: 22.30692675357551 },\n { lat: 117.19807322410043, lng: 39.13197212310894 },\n { lat: 80.27805287890033, lng: 13.091933670856292 },\n { lat: 121.568333333333, lng: 25.0358333333333 },\n { lat: 77.55806386521755, lng: 12.97194099507442 },\n { lat: 100.51469879369489, lng: 13.751945064087977 },\n { lat: 74.34807892054346, lng: 31.56191739488844 },\n { lat: 106.59303578916195, lng: 29.566922888044644 },\n { lat: 78.47800771287751, lng: 17.401928991511454 },\n { lat: -70.66898671317483, lng: -33.448067956934096 },\n { lat: -80.22605193945003, lng: 25.789556555021534 },\n { lat: -43.916950376804834, lng: -19.91308016391116 },\n { lat: -3.6852975446125242, lng: 40.40197212311381 },\n { lat: -75.17194183200792, lng: 40.001919022526465 },\n { lat: 72.57805776168215, lng: 23.031998775062675 },\n { lat: 106.69308136207889, lng: 10.781971309193409 },\n { lat: -79.42196665298843, lng: 43.70192573640844 },\n { lat: 103.85387481909902, lng: 1.2949793251059418 },\n { lat: 13.23248118266855, lng: -8.836340255012658 },\n { lat: 44.391922914564134, lng: 33.34059435615865 },\n { lat: 2.181424460619155, lng: 41.385245438547486 },\n { lat: 88.32994665421205, lng: 22.580390440861947 },\n { lat: -96.84196278749818, lng: 32.82196968167733 },\n { lat: 123.44802765120869, lng: 41.80692512604918 },\n { lat: 32.532233380011576, lng: 15.590024084277673 },\n { lat: 73.84805776168719, lng: 18.531963374654026 },\n { lat: 151.1832339501475, lng: -33.91806510862875 },\n { lat: 30.314074200315076, lng: 59.94096036375191 },\n { lat: 91.79802154756635, lng: 22.33193814680459 },\n { lat: 113.74277634138707, lng: 23.050834758613007 },\n { lat: -84.40189524187565, lng: 33.83195971260585 },\n { lat: -71.07195953218684, lng: 42.33190600170229 },\n { lat: 46.770795798688255, lng: 24.642779007816443 },\n { lat: -95.341925149146, lng: 29.821920243188856 },\n { lat: 105.8480683412422, lng: 21.035273107737055 },\n { lat: -77.01136443943716, lng: 38.901495235087054 },\n { lat: -103.33198008081848, lng: 20.671961950508944 },\n { lat: 144.97307037590406, lng: -37.81808545369631 },\n { lat: 29.948050030391755, lng: 31.201965205759393 },\n { lat: 104.06807363094873, lng: 30.671945877957796 },\n { lat: -83.0820016464927, lng: 42.33190600170229 },\n { lat: 96.16473175266185, lng: 16.785299963188777 },\n { lat: 108.89305043760862, lng: 34.27697130928732 },\n { lat: -51.20195790450316, lng: -30.048068770722466 },\n { lat: 121.465, lng: 25.0127777777778 },\n { lat: 72.83809356897484, lng: 21.20192960187819 },\n { lat: 109.60911291406296, lng: 23.09653464659317 },\n { lat: -4.041994118507091, lng: 5.321942826098564 },\n { lat: -47.91799814700306, lng: -15.781394372878992 },\n { lat: 32.862445782356644, lng: 39.929184444075474 },\n { lat: -100.33193064232995, lng: 25.671940995125283 },\n { lat: 139.60202098994017, lng: 35.43065615270891 },\n { lat: 118.77802846499208, lng: 32.05196500231233 },\n { lat: -73.58524281670213, lng: 45.50194506421502 },\n { lat: 106.7180927553083, lng: 26.581988806001448 },\n { lat: -34.91755136960728, lng: -8.073699467249241 },\n { lat: 126.64803904445057, lng: 45.75192980542715 },\n { lat: -38.58192718342411, lng: -3.7480720258257634 },\n { lat: -112.07193755969467, lng: 33.5419257363676 },\n { lat: 117.67001623440774, lng: 24.520375385531167 },\n { lat: -38.48193328693924, lng: -12.968026046044827 },\n { lat: 129.00810170722048, lng: 35.09699877511093 },\n { lat: -122.41716877355225, lng: 37.76919562968743 },\n { lat: 28.028063865019476, lng: -26.16809888138414 },\n { lat: 13.399602764700546, lng: 52.523764522251156 },\n { lat: 3.048606670909237, lng: 36.765010656628135 },\n { lat: 12.481312562873995, lng: 41.89790148509894 },\n { lat: 125.75274485499392, lng: 39.02138455800434 },\n];\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.\n// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).\n\nimport { faker } from '@faker-js/faker';\n\nimport { Expando, type Schema, type Space } from '@dxos/client/echo';\n\nimport { type TestGeneratorMap, type TestObjectProvider, type TestSchemaMap } from './types';\nimport { range } from './util';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string> {\n // prettier-ignore\n constructor(\n public readonly schema: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>\n ) {}\n\n get schemas(): Schema[] {\n return Object.values(this.schema);\n }\n\n getSchema(typename: string) {\n return this.schemas.find((schema) => schema.typename === typename);\n }\n\n createObject({ types }: { types?: T[] } = {}): Expando {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this.schema) as T[]));\n const factory = this._generators[type];\n const data = factory(this._provider);\n // TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).\n return new Expando(data, { schema: this.schema[type] });\n }\n\n // TODO(burdon): Create batch.\n createObjects({ types, count }: { types?: T[]; count: number }): Expando[] {\n return range(() => this.createObject({ types }), count);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(private readonly _space: Space, schema: TestSchemaMap<T>, generators: TestGeneratorMap<T>) {\n super(schema, generators, (type: T) => {\n // TODO(burdon): Query by schema.\n const { objects } = this._space.db.query((object) => {\n return object.__schema === schema[type];\n });\n\n return objects;\n });\n }\n\n addSchemas() {\n this.schemas.forEach((schema) => this._space.db.add(schema));\n return this.schemas;\n }\n\n override createObject({ types }: { types?: T[] } = {}): Expando {\n return this._space.db.add(super.createObject({ types }));\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Util.\nexport const range = <T>(fn: (i: number) => T | undefined, length: number): T[] =>\n Array.from({ length })\n .map((_, i) => fn(i))\n .filter(Boolean) as T[];\n"],
|
|
5
|
-
"mappings": ";;;AAOA,SAASA,SAAAA,cAAa;AAEtB,SAASC,
|
|
6
|
-
"names": ["faker", "Schema", "TextObject", "faker", "Expando", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "TestObjectGenerator", "constructor", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.\n// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).\n\nimport { faker } from '@faker-js/faker';\n\nimport { Schema, type Space, TextObject } from '@dxos/client/echo';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestSchemaMap } from './types';\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport enum TestSchemaType {\n document = 'example.com/schema/document',\n organization = 'example.com/schema/organization',\n contact = 'example.com/schema/contact',\n project = 'example.com/schema/project',\n}\n\nexport const testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = new Schema({\n typename: TestSchemaType.document,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'content',\n type: Schema.PropType.STRING, // TODO(burdon): Rich text.\n },\n ],\n });\n\n const organization = new Schema({\n typename: TestSchemaType.organization,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'website',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING,\n },\n ],\n });\n\n const contact = new Schema({\n typename: TestSchemaType.contact,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'email',\n type: Schema.PropType.STRING,\n },\n {\n id: 'org',\n type: Schema.PropType.REF,\n ref: organization,\n },\n // TODO(burdon): Convert to object with nested props.\n {\n id: 'lat',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'lng',\n type: Schema.PropType.NUMBER,\n },\n ],\n });\n\n const project = new Schema({\n typename: TestSchemaType.project,\n props: [\n {\n id: 'title',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING, // TODO(burdon): Text.\n },\n {\n id: 'repo',\n type: Schema.PropType.STRING,\n },\n {\n id: 'status',\n type: Schema.PropType.STRING,\n },\n {\n id: 'priority',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'active',\n type: Schema.PropType.BOOLEAN,\n },\n ],\n });\n\n return {\n [TestSchemaType.document]: document,\n [TestSchemaType.organization]: organization,\n [TestSchemaType.contact]: contact,\n [TestSchemaType.project]: project,\n };\n};\n\nexport const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n [TestSchemaType.document]: () => ({\n title: faker.lorem.sentence(3),\n content: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n\n [TestSchemaType.organization]: () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: new TextObject(faker.lorem.sentences()),\n }),\n\n [TestSchemaType.contact]: (provider) => {\n const organizations = provider?.(TestSchemaType.organization);\n const location = faker.datatype.boolean() ? faker.helpers.arrayElement(locations) : undefined;\n return {\n name: faker.person.fullName(),\n email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,\n org:\n organizations?.length && faker.datatype.boolean({ probability: 0.3 })\n ? faker.helpers.arrayElement(organizations)\n : undefined,\n ...location,\n };\n },\n\n [TestSchemaType.project]: () => ({\n title: faker.commerce.productName(),\n repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n status: faker.helpers.arrayElement(Status),\n priority: faker.helpers.arrayElement(Priority),\n active: faker.datatype.boolean(),\n }),\n};\n\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);\n\nconst locations = [\n { lat: 139.74946157054467, lng: 35.686962764371174 },\n { lat: -73.98196278740681, lng: 40.75192492259464 },\n { lat: -99.1329340602939, lng: 19.444388301415472 },\n { lat: 72.85504343876647, lng: 19.0189362343566 },\n { lat: -46.62696583905523, lng: -23.55673372837896 },\n { lat: 77.22805816860182, lng: 28.671938757181522 },\n { lat: 121.43455881982015, lng: 31.218398311228327 },\n { lat: 88.32272979950551, lng: 22.49691515689642 },\n { lat: 90.40663360810754, lng: 23.725005570312817 },\n { lat: -58.399477232331435, lng: -34.600555749907414 },\n { lat: -118.18192636994041, lng: 33.99192410876543 },\n { lat: 66.98806305137339, lng: 24.87193814681484 },\n { lat: 31.248022361126118, lng: 30.051906205103705 },\n { lat: -43.22696665284366, lng: -22.923077315615956 },\n { lat: 135.4581989565952, lng: 34.75198107491417 },\n { lat: 116.38633982565943, lng: 39.93083808990906 },\n { lat: 120.9802713035424, lng: 14.606104813440538 },\n { lat: 37.6135769672714, lng: 55.75410998124818 },\n { lat: 29.008055727002613, lng: 41.10694201243979 },\n { lat: 2.33138946713035, lng: 48.86863878981461 },\n { lat: 126.99778513820195, lng: 37.56829495838895 },\n { lat: 3.3895852125984334, lng: 6.445207512093191 },\n { lat: 106.82749176247012, lng: -6.172471846798885 },\n { lat: -87.75200083270931, lng: 41.83193651927843 },\n { lat: 113.32306427226172, lng: 23.14692716047989 },\n { lat: -0.11866770247593195, lng: 51.5019405883275 },\n { lat: -77.05200795343472, lng: -12.04606681752557 },\n { lat: 51.42239817500899, lng: 35.673888627001304 },\n { lat: 15.313026023171744, lng: -4.327778243275986 },\n { lat: -74.08528981377441, lng: 4.598369421147822 },\n { lat: 114.1201772298325, lng: 22.554316369677963 },\n { lat: 114.26807118958311, lng: 30.581977209337822 },\n { lat: 114.18306345846304, lng: 22.30692675357551 },\n { lat: 117.19807322410043, lng: 39.13197212310894 },\n { lat: 80.27805287890033, lng: 13.091933670856292 },\n { lat: 121.568333333333, lng: 25.0358333333333 },\n { lat: 77.55806386521755, lng: 12.97194099507442 },\n { lat: 100.51469879369489, lng: 13.751945064087977 },\n { lat: 74.34807892054346, lng: 31.56191739488844 },\n { lat: 106.59303578916195, lng: 29.566922888044644 },\n { lat: 78.47800771287751, lng: 17.401928991511454 },\n { lat: -70.66898671317483, lng: -33.448067956934096 },\n { lat: -80.22605193945003, lng: 25.789556555021534 },\n { lat: -43.916950376804834, lng: -19.91308016391116 },\n { lat: -3.6852975446125242, lng: 40.40197212311381 },\n { lat: -75.17194183200792, lng: 40.001919022526465 },\n { lat: 72.57805776168215, lng: 23.031998775062675 },\n { lat: 106.69308136207889, lng: 10.781971309193409 },\n { lat: -79.42196665298843, lng: 43.70192573640844 },\n { lat: 103.85387481909902, lng: 1.2949793251059418 },\n { lat: 13.23248118266855, lng: -8.836340255012658 },\n { lat: 44.391922914564134, lng: 33.34059435615865 },\n { lat: 2.181424460619155, lng: 41.385245438547486 },\n { lat: 88.32994665421205, lng: 22.580390440861947 },\n { lat: -96.84196278749818, lng: 32.82196968167733 },\n { lat: 123.44802765120869, lng: 41.80692512604918 },\n { lat: 32.532233380011576, lng: 15.590024084277673 },\n { lat: 73.84805776168719, lng: 18.531963374654026 },\n { lat: 151.1832339501475, lng: -33.91806510862875 },\n { lat: 30.314074200315076, lng: 59.94096036375191 },\n { lat: 91.79802154756635, lng: 22.33193814680459 },\n { lat: 113.74277634138707, lng: 23.050834758613007 },\n { lat: -84.40189524187565, lng: 33.83195971260585 },\n { lat: -71.07195953218684, lng: 42.33190600170229 },\n { lat: 46.770795798688255, lng: 24.642779007816443 },\n { lat: -95.341925149146, lng: 29.821920243188856 },\n { lat: 105.8480683412422, lng: 21.035273107737055 },\n { lat: -77.01136443943716, lng: 38.901495235087054 },\n { lat: -103.33198008081848, lng: 20.671961950508944 },\n { lat: 144.97307037590406, lng: -37.81808545369631 },\n { lat: 29.948050030391755, lng: 31.201965205759393 },\n { lat: 104.06807363094873, lng: 30.671945877957796 },\n { lat: -83.0820016464927, lng: 42.33190600170229 },\n { lat: 96.16473175266185, lng: 16.785299963188777 },\n { lat: 108.89305043760862, lng: 34.27697130928732 },\n { lat: -51.20195790450316, lng: -30.048068770722466 },\n { lat: 121.465, lng: 25.0127777777778 },\n { lat: 72.83809356897484, lng: 21.20192960187819 },\n { lat: 109.60911291406296, lng: 23.09653464659317 },\n { lat: -4.041994118507091, lng: 5.321942826098564 },\n { lat: -47.91799814700306, lng: -15.781394372878992 },\n { lat: 32.862445782356644, lng: 39.929184444075474 },\n { lat: -100.33193064232995, lng: 25.671940995125283 },\n { lat: 139.60202098994017, lng: 35.43065615270891 },\n { lat: 118.77802846499208, lng: 32.05196500231233 },\n { lat: -73.58524281670213, lng: 45.50194506421502 },\n { lat: 106.7180927553083, lng: 26.581988806001448 },\n { lat: -34.91755136960728, lng: -8.073699467249241 },\n { lat: 126.64803904445057, lng: 45.75192980542715 },\n { lat: -38.58192718342411, lng: -3.7480720258257634 },\n { lat: -112.07193755969467, lng: 33.5419257363676 },\n { lat: 117.67001623440774, lng: 24.520375385531167 },\n { lat: -38.48193328693924, lng: -12.968026046044827 },\n { lat: 129.00810170722048, lng: 35.09699877511093 },\n { lat: -122.41716877355225, lng: 37.76919562968743 },\n { lat: 28.028063865019476, lng: -26.16809888138414 },\n { lat: 13.399602764700546, lng: 52.523764522251156 },\n { lat: 3.048606670909237, lng: 36.765010656628135 },\n { lat: 125.75274485499392, lng: 39.02138455800434 },\n { lat: 12.481312562873995, lng: 41.89790148509894 },\n];\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { faker } from '@faker-js/faker';\n\nimport { Expando, type TypedObject, Schema, type Space } from '@dxos/client/echo';\n\nimport { type TestGeneratorMap, type TestObjectProvider, type TestSchemaMap } from './types';\nimport { range } from './util';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string> {\n // prettier-ignore\n constructor(\n private readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>\n ) {}\n\n get schemas(): Schema[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T) {\n return this.schemas.find((schema) => schema.typename === type);\n }\n\n protected setSchema(type: T, schema: Schema) {\n this._schemas[type] = schema;\n }\n\n // TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).\n createObject({ types }: { types?: T[] } = {}): TypedObject {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = this._generators[type](this._provider);\n const schema = this.getSchema(type);\n return new Expando(data, { schema });\n }\n\n // TODO(burdon): Create batch.\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n createObjects(map: Partial<Record<T, number>>): Expando[] {\n const objects: Expando[] = [];\n Object.entries<number>(map as any).forEach(([type, count]) => {\n range(() => objects.push(this.createObject({ types: [type as T] })), count);\n });\n\n return objects;\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(private readonly _space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>) {\n super(schemaMap, generators, (type: T) => {\n const { objects } = this._space.db.query((object) => {\n return object.__schema?.id === this.getSchema(type)?.id;\n });\n\n return objects;\n });\n\n // TODO(burdon): Map initially are objects that have not been added to the space.\n // Merge existing schema in space with defaults.\n const { objects } = this._space.db.query(Schema.filter());\n Object.keys(schemaMap).forEach((type) => {\n const schema = objects.find((object) => object.typename === type);\n if (schema) {\n this.setSchema(type as T, schema);\n }\n });\n }\n\n addSchemas() {\n const { objects } = this._space.db.query(Schema.filter());\n this.schemas.forEach((schema) => {\n if (!objects.find((object) => object.typename === schema.typename)) {\n this._space.db.add(schema);\n }\n });\n\n return this.schemas;\n }\n\n override createObject({ types }: { types?: T[] } = {}): Expando {\n return this._space.db.add(super.createObject({ types }));\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Util.\nexport const range = <T>(fn: (i: number) => T | undefined, length: number): T[] =>\n Array.from({ length })\n .map((_, i) => fn(i))\n .filter(Boolean) as T[];\n"],
|
|
5
|
+
"mappings": ";;;AAOA,SAASA,SAAAA,cAAa;AAEtB,SAASC,UAAAA,SAAoBC,kBAAkB;;;ACL/C,SAASC,aAAa;AAEtB,SAASC,SAA2BC,cAA0B;;;ACDvD,IAAMC,QAAQ,CAAIC,IAAkCC,WACzDC,MAAMC,KAAK;EAAEF;AAAO,CAAA,EACjBG,IAAI,CAACC,GAAGC,MAAMN,GAAGM,CAAAA,CAAAA,EACjBC,OAAOC,OAAAA;;;ADML,IAAMC,sBAAN,MAAMA;;EAEXC,YACmBC,UACAC,aACAC,WACjB;oBAHiBF;uBACAC;qBACAC;EAChB;EAEH,IAAIC,UAAoB;AACtB,WAAOC,OAAOC,OAAO,KAAKL,QAAQ;EACpC;EAEAM,UAAUC,MAAS;AACjB,WAAO,KAAKJ,QAAQK,KAAK,CAACC,WAAWA,OAAOC,aAAaH,IAAAA;E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AK;IAAmBC,KAAK;EAAmB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;;",
|
|
6
|
+
"names": ["faker", "Schema", "TextObject", "faker", "Expando", "Schema", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "TestObjectGenerator", "constructor", "_schemas", "_generators", "_provider", "schemas", "Object", "values", "getSchema", "type", "find", "schema", "typename", "setSchema", "createObject", "types", "faker", "helpers", "arrayElement", "keys", "data", "Expando", "createObjects", "map", "objects", "entries", "forEach", "count", "range", "push", "SpaceObjectGenerator", "_space", "schemaMap", "generators", "db", "query", "object", "__schema", "id", "Schema", "filter", "addSchemas", "add", "Status", "Priority", "TestSchemaType", "document", "organization", "contact", "project", "testSchemas", "Schema", "typename", "props", "id", "type", "PropType", "STRING", "REF", "ref", "NUMBER", "BOOLEAN", "testObjectGenerators", "title", "faker", "lorem", "sentence", "content", "sentences", "min", "max", "number", "int", "name", "company", "website", "datatype", "boolean", "probability", "internet", "url", "undefined", "description", "TextObject", "provider", "organizations", "location", "helpers", "arrayElement", "locations", "person", "fullName", "email", "org", "length", "commerce", "productName", "repo", "status", "priority", "active", "createTestObjectGenerator", "TestObjectGenerator", "createSpaceObjectGenerator", "space", "SpaceObjectGenerator", "lat", "lng"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo-generator/src/util.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/echo/echo-generator/src/util.ts":{"bytes":1052,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/generator.ts":{"bytes":10511,"imports":[{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-generator/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"packages/core/echo/echo-generator/src/data.ts":{"bytes":37168,"imports":[{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"}],"format":"esm"},"packages/core/echo/echo-generator/src/index.ts":{"bytes":629,"imports":[{"path":"packages/core/echo/echo-generator/src/data.ts","kind":"import-statement","original":"./data"},{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"},{"path":"packages/core/echo/echo-generator/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-generator/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":23093},"packages/core/echo/echo-generator/dist/lib/browser/index.mjs":{"imports":[{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true}],"exports":["Priority","SpaceObjectGenerator","Status","TestObjectGenerator","TestSchemaType","createSpaceObjectGenerator","createTestObjectGenerator","range","testObjectGenerators","testSchemas"],"entryPoint":"packages/core/echo/echo-generator/src/index.ts","inputs":{"packages/core/echo/echo-generator/src/data.ts":{"bytesInOutput":10590},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":2245},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":91},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":13459}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -24,6 +24,7 @@ __export(src_exports, {
|
|
|
24
24
|
SpaceObjectGenerator: () => SpaceObjectGenerator,
|
|
25
25
|
Status: () => Status,
|
|
26
26
|
TestObjectGenerator: () => TestObjectGenerator,
|
|
27
|
+
TestSchemaType: () => TestSchemaType,
|
|
27
28
|
createSpaceObjectGenerator: () => createSpaceObjectGenerator,
|
|
28
29
|
createTestObjectGenerator: () => createTestObjectGenerator,
|
|
29
30
|
range: () => range,
|
|
@@ -48,44 +49,67 @@ var range = (fn, length) => Array.from({
|
|
|
48
49
|
// packages/core/echo/echo-generator/src/generator.ts
|
|
49
50
|
var TestObjectGenerator = class {
|
|
50
51
|
// prettier-ignore
|
|
51
|
-
constructor(
|
|
52
|
-
this.
|
|
52
|
+
constructor(_schemas, _generators, _provider) {
|
|
53
|
+
this._schemas = _schemas;
|
|
53
54
|
this._generators = _generators;
|
|
54
55
|
this._provider = _provider;
|
|
55
56
|
}
|
|
56
57
|
get schemas() {
|
|
57
|
-
return Object.values(this.
|
|
58
|
+
return Object.values(this._schemas);
|
|
58
59
|
}
|
|
59
|
-
getSchema(
|
|
60
|
-
return this.schemas.find((schema) => schema.typename ===
|
|
60
|
+
getSchema(type) {
|
|
61
|
+
return this.schemas.find((schema) => schema.typename === type);
|
|
61
62
|
}
|
|
63
|
+
setSchema(type, schema) {
|
|
64
|
+
this._schemas[type] = schema;
|
|
65
|
+
}
|
|
66
|
+
// TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).
|
|
62
67
|
createObject({ types } = {}) {
|
|
63
|
-
const type = import_faker.faker.helpers.arrayElement(types ?? Object.keys(this.
|
|
64
|
-
const
|
|
65
|
-
const
|
|
68
|
+
const type = import_faker.faker.helpers.arrayElement(types ?? Object.keys(this._schemas));
|
|
69
|
+
const data = this._generators[type](this._provider);
|
|
70
|
+
const schema = this.getSchema(type);
|
|
66
71
|
return new import_echo.Expando(data, {
|
|
67
|
-
schema
|
|
72
|
+
schema
|
|
68
73
|
});
|
|
69
74
|
}
|
|
70
75
|
// TODO(burdon): Create batch.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
// TODO(burdon): Based on dependencies (e.g., organization before contact).
|
|
77
|
+
createObjects(map) {
|
|
78
|
+
const objects = [];
|
|
79
|
+
Object.entries(map).forEach(([type, count]) => {
|
|
80
|
+
range(() => objects.push(this.createObject({
|
|
81
|
+
types: [
|
|
82
|
+
type
|
|
83
|
+
]
|
|
84
|
+
})), count);
|
|
85
|
+
});
|
|
86
|
+
return objects;
|
|
75
87
|
}
|
|
76
88
|
};
|
|
77
89
|
var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
78
|
-
constructor(_space,
|
|
79
|
-
super(
|
|
80
|
-
const { objects } = this._space.db.query((object) => {
|
|
81
|
-
return object.__schema ===
|
|
90
|
+
constructor(_space, schemaMap, generators) {
|
|
91
|
+
super(schemaMap, generators, (type) => {
|
|
92
|
+
const { objects: objects2 } = this._space.db.query((object) => {
|
|
93
|
+
return object.__schema?.id === this.getSchema(type)?.id;
|
|
82
94
|
});
|
|
83
|
-
return
|
|
95
|
+
return objects2;
|
|
84
96
|
});
|
|
85
97
|
this._space = _space;
|
|
98
|
+
const { objects } = this._space.db.query(import_echo.Schema.filter());
|
|
99
|
+
Object.keys(schemaMap).forEach((type) => {
|
|
100
|
+
const schema = objects.find((object) => object.typename === type);
|
|
101
|
+
if (schema) {
|
|
102
|
+
this.setSchema(type, schema);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
86
105
|
}
|
|
87
106
|
addSchemas() {
|
|
88
|
-
|
|
107
|
+
const { objects } = this._space.db.query(import_echo.Schema.filter());
|
|
108
|
+
this.schemas.forEach((schema) => {
|
|
109
|
+
if (!objects.find((object) => object.typename === schema.typename)) {
|
|
110
|
+
this._space.db.add(schema);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
89
113
|
return this.schemas;
|
|
90
114
|
}
|
|
91
115
|
createObject({ types } = {}) {
|
|
@@ -108,8 +132,16 @@ var Priority = [
|
|
|
108
132
|
4,
|
|
109
133
|
5
|
|
110
134
|
];
|
|
135
|
+
var TestSchemaType;
|
|
136
|
+
(function(TestSchemaType2) {
|
|
137
|
+
TestSchemaType2["document"] = "example.com/schema/document";
|
|
138
|
+
TestSchemaType2["organization"] = "example.com/schema/organization";
|
|
139
|
+
TestSchemaType2["contact"] = "example.com/schema/contact";
|
|
140
|
+
TestSchemaType2["project"] = "example.com/schema/project";
|
|
141
|
+
})(TestSchemaType || (TestSchemaType = {}));
|
|
111
142
|
var testSchemas = () => {
|
|
112
143
|
const document = new import_echo2.Schema({
|
|
144
|
+
typename: TestSchemaType.document,
|
|
113
145
|
props: [
|
|
114
146
|
{
|
|
115
147
|
id: "name",
|
|
@@ -122,7 +154,7 @@ var testSchemas = () => {
|
|
|
122
154
|
]
|
|
123
155
|
});
|
|
124
156
|
const organization = new import_echo2.Schema({
|
|
125
|
-
typename:
|
|
157
|
+
typename: TestSchemaType.organization,
|
|
126
158
|
props: [
|
|
127
159
|
{
|
|
128
160
|
id: "name",
|
|
@@ -138,8 +170,8 @@ var testSchemas = () => {
|
|
|
138
170
|
}
|
|
139
171
|
]
|
|
140
172
|
});
|
|
141
|
-
const
|
|
142
|
-
typename:
|
|
173
|
+
const contact = new import_echo2.Schema({
|
|
174
|
+
typename: TestSchemaType.contact,
|
|
143
175
|
props: [
|
|
144
176
|
{
|
|
145
177
|
id: "name",
|
|
@@ -166,7 +198,7 @@ var testSchemas = () => {
|
|
|
166
198
|
]
|
|
167
199
|
});
|
|
168
200
|
const project = new import_echo2.Schema({
|
|
169
|
-
typename:
|
|
201
|
+
typename: TestSchemaType.project,
|
|
170
202
|
props: [
|
|
171
203
|
{
|
|
172
204
|
id: "title",
|
|
@@ -195,14 +227,14 @@ var testSchemas = () => {
|
|
|
195
227
|
]
|
|
196
228
|
});
|
|
197
229
|
return {
|
|
198
|
-
document,
|
|
199
|
-
organization,
|
|
200
|
-
|
|
201
|
-
project
|
|
230
|
+
[TestSchemaType.document]: document,
|
|
231
|
+
[TestSchemaType.organization]: organization,
|
|
232
|
+
[TestSchemaType.contact]: contact,
|
|
233
|
+
[TestSchemaType.project]: project
|
|
202
234
|
};
|
|
203
235
|
};
|
|
204
236
|
var testObjectGenerators = {
|
|
205
|
-
document: () => ({
|
|
237
|
+
[TestSchemaType.document]: () => ({
|
|
206
238
|
title: import_faker2.faker.lorem.sentence(3),
|
|
207
239
|
content: import_faker2.faker.lorem.sentences({
|
|
208
240
|
min: 1,
|
|
@@ -212,15 +244,15 @@ var testObjectGenerators = {
|
|
|
212
244
|
})
|
|
213
245
|
})
|
|
214
246
|
}),
|
|
215
|
-
organization: () => ({
|
|
247
|
+
[TestSchemaType.organization]: () => ({
|
|
216
248
|
name: import_faker2.faker.company.name(),
|
|
217
249
|
website: import_faker2.faker.datatype.boolean({
|
|
218
250
|
probability: 0.3
|
|
219
251
|
}) ? import_faker2.faker.internet.url() : void 0,
|
|
220
252
|
description: new import_echo2.TextObject(import_faker2.faker.lorem.sentences())
|
|
221
253
|
}),
|
|
222
|
-
|
|
223
|
-
const organizations = provider?.(
|
|
254
|
+
[TestSchemaType.contact]: (provider) => {
|
|
255
|
+
const organizations = provider?.(TestSchemaType.organization);
|
|
224
256
|
const location = import_faker2.faker.datatype.boolean() ? import_faker2.faker.helpers.arrayElement(locations) : void 0;
|
|
225
257
|
return {
|
|
226
258
|
name: import_faker2.faker.person.fullName(),
|
|
@@ -233,7 +265,7 @@ var testObjectGenerators = {
|
|
|
233
265
|
...location
|
|
234
266
|
};
|
|
235
267
|
},
|
|
236
|
-
project: () => ({
|
|
268
|
+
[TestSchemaType.project]: () => ({
|
|
237
269
|
title: import_faker2.faker.commerce.productName(),
|
|
238
270
|
repo: import_faker2.faker.datatype.boolean({
|
|
239
271
|
probability: 0.3
|
|
@@ -638,13 +670,13 @@ var locations = [
|
|
|
638
670
|
lat: 3.048606670909237,
|
|
639
671
|
lng: 36.765010656628135
|
|
640
672
|
},
|
|
641
|
-
{
|
|
642
|
-
lat: 12.481312562873995,
|
|
643
|
-
lng: 41.89790148509894
|
|
644
|
-
},
|
|
645
673
|
{
|
|
646
674
|
lat: 125.75274485499392,
|
|
647
675
|
lng: 39.02138455800434
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
lat: 12.481312562873995,
|
|
679
|
+
lng: 41.89790148509894
|
|
648
680
|
}
|
|
649
681
|
];
|
|
650
682
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -653,6 +685,7 @@ var locations = [
|
|
|
653
685
|
SpaceObjectGenerator,
|
|
654
686
|
Status,
|
|
655
687
|
TestObjectGenerator,
|
|
688
|
+
TestSchemaType,
|
|
656
689
|
createSpaceObjectGenerator,
|
|
657
690
|
createTestObjectGenerator,
|
|
658
691
|
range,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/data.ts", "../../../src/generator.ts", "../../../src/util.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport * from './data';\nexport * from './generator';\nexport * from './util';\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.\n// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).\n\nimport { faker } from '@faker-js/faker';\n\nimport { Schema, type Space, TextObject } from '@dxos/client/echo';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestSchemaMap } from './types';\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport type TestSchemaType = 'document' | 'organization' | 'person' | 'project';\n\nexport const testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = new Schema({\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n // TODO(burdon): primary: true,\n },\n {\n id: 'content',\n type: Schema.PropType.STRING, // TODO(burdon): Rich text.\n },\n ],\n });\n\n const organization = new Schema({\n typename: 'example.com/schema/organization',\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'website',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING,\n },\n ],\n });\n\n const person = new Schema({\n typename: 'example.com/schema/person',\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'email',\n type: Schema.PropType.STRING,\n },\n {\n id: 'org',\n type: Schema.PropType.REF,\n ref: organization,\n },\n // TODO(burdon): Convert to object with nested props.\n {\n id: 'lat',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'lng',\n type: Schema.PropType.NUMBER,\n },\n ],\n });\n\n const project = new Schema({\n typename: 'example.com/schema/project',\n props: [\n {\n id: 'title',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING, // TODO(burdon): Text.\n },\n {\n id: 'repo',\n type: Schema.PropType.STRING,\n },\n {\n id: 'status',\n type: Schema.PropType.STRING,\n },\n {\n id: 'priority',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'active',\n type: Schema.PropType.BOOLEAN,\n },\n ],\n });\n\n return { document, organization, person, project };\n};\n\nexport const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n document: () => ({\n title: faker.lorem.sentence(3),\n content: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n\n organization: () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: new TextObject(faker.lorem.sentences()),\n }),\n\n person: (provider) => {\n const organizations = provider?.('organization');\n const location = faker.datatype.boolean() ? faker.helpers.arrayElement(locations) : undefined;\n return {\n name: faker.person.fullName(),\n email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,\n org:\n organizations?.length && faker.datatype.boolean({ probability: 0.3 })\n ? faker.helpers.arrayElement(organizations)\n : undefined,\n ...location,\n };\n },\n\n project: () => ({\n title: faker.commerce.productName(),\n repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n status: faker.helpers.arrayElement(Status),\n priority: faker.helpers.arrayElement(Priority),\n active: faker.datatype.boolean(),\n }),\n};\n\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);\n\nconst locations = [\n { lat: 139.74946157054467, lng: 35.686962764371174 },\n { lat: -73.98196278740681, lng: 40.75192492259464 },\n { lat: -99.1329340602939, lng: 19.444388301415472 },\n { lat: 72.85504343876647, lng: 19.0189362343566 },\n { lat: -46.62696583905523, lng: -23.55673372837896 },\n { lat: 77.22805816860182, lng: 28.671938757181522 },\n { lat: 121.43455881982015, lng: 31.218398311228327 },\n { lat: 88.32272979950551, lng: 22.49691515689642 },\n { lat: 90.40663360810754, lng: 23.725005570312817 },\n { lat: -58.399477232331435, lng: -34.600555749907414 },\n { lat: -118.18192636994041, lng: 33.99192410876543 },\n { lat: 66.98806305137339, lng: 24.87193814681484 },\n { lat: 31.248022361126118, lng: 30.051906205103705 },\n { lat: -43.22696665284366, lng: -22.923077315615956 },\n { lat: 135.4581989565952, lng: 34.75198107491417 },\n { lat: 116.38633982565943, lng: 39.93083808990906 },\n { lat: 120.9802713035424, lng: 14.606104813440538 },\n { lat: 37.6135769672714, lng: 55.75410998124818 },\n { lat: 29.008055727002613, lng: 41.10694201243979 },\n { lat: 2.33138946713035, lng: 48.86863878981461 },\n { lat: 126.99778513820195, lng: 37.56829495838895 },\n { lat: 3.3895852125984334, lng: 6.445207512093191 },\n { lat: 106.82749176247012, lng: -6.172471846798885 },\n { lat: -87.75200083270931, lng: 41.83193651927843 },\n { lat: 113.32306427226172, lng: 23.14692716047989 },\n { lat: -0.11866770247593195, lng: 51.5019405883275 },\n { lat: -77.05200795343472, lng: -12.04606681752557 },\n { lat: 51.42239817500899, lng: 35.673888627001304 },\n { lat: 15.313026023171744, lng: -4.327778243275986 },\n { lat: -74.08528981377441, lng: 4.598369421147822 },\n { lat: 114.1201772298325, lng: 22.554316369677963 },\n { lat: 114.26807118958311, lng: 30.581977209337822 },\n { lat: 114.18306345846304, lng: 22.30692675357551 },\n { lat: 117.19807322410043, lng: 39.13197212310894 },\n { lat: 80.27805287890033, lng: 13.091933670856292 },\n { lat: 121.568333333333, lng: 25.0358333333333 },\n { lat: 77.55806386521755, lng: 12.97194099507442 },\n { lat: 100.51469879369489, lng: 13.751945064087977 },\n { lat: 74.34807892054346, lng: 31.56191739488844 },\n { lat: 106.59303578916195, lng: 29.566922888044644 },\n { lat: 78.47800771287751, lng: 17.401928991511454 },\n { lat: -70.66898671317483, lng: -33.448067956934096 },\n { lat: -80.22605193945003, lng: 25.789556555021534 },\n { lat: -43.916950376804834, lng: -19.91308016391116 },\n { lat: -3.6852975446125242, lng: 40.40197212311381 },\n { lat: -75.17194183200792, lng: 40.001919022526465 },\n { lat: 72.57805776168215, lng: 23.031998775062675 },\n { lat: 106.69308136207889, lng: 10.781971309193409 },\n { lat: -79.42196665298843, lng: 43.70192573640844 },\n { lat: 103.85387481909902, lng: 1.2949793251059418 },\n { lat: 13.23248118266855, lng: -8.836340255012658 },\n { lat: 44.391922914564134, lng: 33.34059435615865 },\n { lat: 2.181424460619155, lng: 41.385245438547486 },\n { lat: 88.32994665421205, lng: 22.580390440861947 },\n { lat: -96.84196278749818, lng: 32.82196968167733 },\n { lat: 123.44802765120869, lng: 41.80692512604918 },\n { lat: 32.532233380011576, lng: 15.590024084277673 },\n { lat: 73.84805776168719, lng: 18.531963374654026 },\n { lat: 151.1832339501475, lng: -33.91806510862875 },\n { lat: 30.314074200315076, lng: 59.94096036375191 },\n { lat: 91.79802154756635, lng: 22.33193814680459 },\n { lat: 113.74277634138707, lng: 23.050834758613007 },\n { lat: -84.40189524187565, lng: 33.83195971260585 },\n { lat: -71.07195953218684, lng: 42.33190600170229 },\n { lat: 46.770795798688255, lng: 24.642779007816443 },\n { lat: -95.341925149146, lng: 29.821920243188856 },\n { lat: 105.8480683412422, lng: 21.035273107737055 },\n { lat: -77.01136443943716, lng: 38.901495235087054 },\n { lat: -103.33198008081848, lng: 20.671961950508944 },\n { lat: 144.97307037590406, lng: -37.81808545369631 },\n { lat: 29.948050030391755, lng: 31.201965205759393 },\n { lat: 104.06807363094873, lng: 30.671945877957796 },\n { lat: -83.0820016464927, lng: 42.33190600170229 },\n { lat: 96.16473175266185, lng: 16.785299963188777 },\n { lat: 108.89305043760862, lng: 34.27697130928732 },\n { lat: -51.20195790450316, lng: -30.048068770722466 },\n { lat: 121.465, lng: 25.0127777777778 },\n { lat: 72.83809356897484, lng: 21.20192960187819 },\n { lat: 109.60911291406296, lng: 23.09653464659317 },\n { lat: -4.041994118507091, lng: 5.321942826098564 },\n { lat: -47.91799814700306, lng: -15.781394372878992 },\n { lat: 32.862445782356644, lng: 39.929184444075474 },\n { lat: -100.33193064232995, lng: 25.671940995125283 },\n { lat: 139.60202098994017, lng: 35.43065615270891 },\n { lat: 118.77802846499208, lng: 32.05196500231233 },\n { lat: -73.58524281670213, lng: 45.50194506421502 },\n { lat: 106.7180927553083, lng: 26.581988806001448 },\n { lat: -34.91755136960728, lng: -8.073699467249241 },\n { lat: 126.64803904445057, lng: 45.75192980542715 },\n { lat: -38.58192718342411, lng: -3.7480720258257634 },\n { lat: -112.07193755969467, lng: 33.5419257363676 },\n { lat: 117.67001623440774, lng: 24.520375385531167 },\n { lat: -38.48193328693924, lng: -12.968026046044827 },\n { lat: 129.00810170722048, lng: 35.09699877511093 },\n { lat: -122.41716877355225, lng: 37.76919562968743 },\n { lat: 28.028063865019476, lng: -26.16809888138414 },\n { lat: 13.399602764700546, lng: 52.523764522251156 },\n { lat: 3.048606670909237, lng: 36.765010656628135 },\n { lat: 12.481312562873995, lng: 41.89790148509894 },\n { lat: 125.75274485499392, lng: 39.02138455800434 },\n];\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.\n// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).\n\nimport { faker } from '@faker-js/faker';\n\nimport { Expando, type Schema, type Space } from '@dxos/client/echo';\n\nimport { type TestGeneratorMap, type TestObjectProvider, type TestSchemaMap } from './types';\nimport { range } from './util';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string> {\n // prettier-ignore\n constructor(\n public readonly schema: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>\n ) {}\n\n get schemas(): Schema[] {\n return Object.values(this.schema);\n }\n\n getSchema(typename: string) {\n return this.schemas.find((schema) => schema.typename === typename);\n }\n\n createObject({ types }: { types?: T[] } = {}): Expando {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this.schema) as T[]));\n const factory = this._generators[type];\n const data = factory(this._provider);\n // TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).\n return new Expando(data, { schema: this.schema[type] });\n }\n\n // TODO(burdon): Create batch.\n createObjects({ types, count }: { types?: T[]; count: number }): Expando[] {\n return range(() => this.createObject({ types }), count);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(private readonly _space: Space, schema: TestSchemaMap<T>, generators: TestGeneratorMap<T>) {\n super(schema, generators, (type: T) => {\n // TODO(burdon): Query by schema.\n const { objects } = this._space.db.query((object) => {\n return object.__schema === schema[type];\n });\n\n return objects;\n });\n }\n\n addSchemas() {\n this.schemas.forEach((schema) => this._space.db.add(schema));\n return this.schemas;\n }\n\n override createObject({ types }: { types?: T[] } = {}): Expando {\n return this._space.db.add(super.createObject({ types }));\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Util.\nexport const range = <T>(fn: (i: number) => T | undefined, length: number): T[] =>\n Array.from({ length })\n .map((_, i) => fn(i))\n .filter(Boolean) as T[];\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA
|
|
6
|
-
"names": ["import_faker", "import_echo", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "TestObjectGenerator", "constructor", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport * from './data';\nexport * from './generator';\nexport * from './util';\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.\n// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).\n\nimport { faker } from '@faker-js/faker';\n\nimport { Schema, type Space, TextObject } from '@dxos/client/echo';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestSchemaMap } from './types';\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport enum TestSchemaType {\n document = 'example.com/schema/document',\n organization = 'example.com/schema/organization',\n contact = 'example.com/schema/contact',\n project = 'example.com/schema/project',\n}\n\nexport const testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = new Schema({\n typename: TestSchemaType.document,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'content',\n type: Schema.PropType.STRING, // TODO(burdon): Rich text.\n },\n ],\n });\n\n const organization = new Schema({\n typename: TestSchemaType.organization,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'website',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING,\n },\n ],\n });\n\n const contact = new Schema({\n typename: TestSchemaType.contact,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'email',\n type: Schema.PropType.STRING,\n },\n {\n id: 'org',\n type: Schema.PropType.REF,\n ref: organization,\n },\n // TODO(burdon): Convert to object with nested props.\n {\n id: 'lat',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'lng',\n type: Schema.PropType.NUMBER,\n },\n ],\n });\n\n const project = new Schema({\n typename: TestSchemaType.project,\n props: [\n {\n id: 'title',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING, // TODO(burdon): Text.\n },\n {\n id: 'repo',\n type: Schema.PropType.STRING,\n },\n {\n id: 'status',\n type: Schema.PropType.STRING,\n },\n {\n id: 'priority',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'active',\n type: Schema.PropType.BOOLEAN,\n },\n ],\n });\n\n return {\n [TestSchemaType.document]: document,\n [TestSchemaType.organization]: organization,\n [TestSchemaType.contact]: contact,\n [TestSchemaType.project]: project,\n };\n};\n\nexport const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n [TestSchemaType.document]: () => ({\n title: faker.lorem.sentence(3),\n content: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n\n [TestSchemaType.organization]: () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: new TextObject(faker.lorem.sentences()),\n }),\n\n [TestSchemaType.contact]: (provider) => {\n const organizations = provider?.(TestSchemaType.organization);\n const location = faker.datatype.boolean() ? faker.helpers.arrayElement(locations) : undefined;\n return {\n name: faker.person.fullName(),\n email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,\n org:\n organizations?.length && faker.datatype.boolean({ probability: 0.3 })\n ? faker.helpers.arrayElement(organizations)\n : undefined,\n ...location,\n };\n },\n\n [TestSchemaType.project]: () => ({\n title: faker.commerce.productName(),\n repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n status: faker.helpers.arrayElement(Status),\n priority: faker.helpers.arrayElement(Priority),\n active: faker.datatype.boolean(),\n }),\n};\n\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);\n\nconst locations = [\n { lat: 139.74946157054467, lng: 35.686962764371174 },\n { lat: -73.98196278740681, lng: 40.75192492259464 },\n { lat: -99.1329340602939, lng: 19.444388301415472 },\n { lat: 72.85504343876647, lng: 19.0189362343566 },\n { lat: -46.62696583905523, lng: -23.55673372837896 },\n { lat: 77.22805816860182, lng: 28.671938757181522 },\n { lat: 121.43455881982015, lng: 31.218398311228327 },\n { lat: 88.32272979950551, lng: 22.49691515689642 },\n { lat: 90.40663360810754, lng: 23.725005570312817 },\n { lat: -58.399477232331435, lng: -34.600555749907414 },\n { lat: -118.18192636994041, lng: 33.99192410876543 },\n { lat: 66.98806305137339, lng: 24.87193814681484 },\n { lat: 31.248022361126118, lng: 30.051906205103705 },\n { lat: -43.22696665284366, lng: -22.923077315615956 },\n { lat: 135.4581989565952, lng: 34.75198107491417 },\n { lat: 116.38633982565943, lng: 39.93083808990906 },\n { lat: 120.9802713035424, lng: 14.606104813440538 },\n { lat: 37.6135769672714, lng: 55.75410998124818 },\n { lat: 29.008055727002613, lng: 41.10694201243979 },\n { lat: 2.33138946713035, lng: 48.86863878981461 },\n { lat: 126.99778513820195, lng: 37.56829495838895 },\n { lat: 3.3895852125984334, lng: 6.445207512093191 },\n { lat: 106.82749176247012, lng: -6.172471846798885 },\n { lat: -87.75200083270931, lng: 41.83193651927843 },\n { lat: 113.32306427226172, lng: 23.14692716047989 },\n { lat: -0.11866770247593195, lng: 51.5019405883275 },\n { lat: -77.05200795343472, lng: -12.04606681752557 },\n { lat: 51.42239817500899, lng: 35.673888627001304 },\n { lat: 15.313026023171744, lng: -4.327778243275986 },\n { lat: -74.08528981377441, lng: 4.598369421147822 },\n { lat: 114.1201772298325, lng: 22.554316369677963 },\n { lat: 114.26807118958311, lng: 30.581977209337822 },\n { lat: 114.18306345846304, lng: 22.30692675357551 },\n { lat: 117.19807322410043, lng: 39.13197212310894 },\n { lat: 80.27805287890033, lng: 13.091933670856292 },\n { lat: 121.568333333333, lng: 25.0358333333333 },\n { lat: 77.55806386521755, lng: 12.97194099507442 },\n { lat: 100.51469879369489, lng: 13.751945064087977 },\n { lat: 74.34807892054346, lng: 31.56191739488844 },\n { lat: 106.59303578916195, lng: 29.566922888044644 },\n { lat: 78.47800771287751, lng: 17.401928991511454 },\n { lat: -70.66898671317483, lng: -33.448067956934096 },\n { lat: -80.22605193945003, lng: 25.789556555021534 },\n { lat: -43.916950376804834, lng: -19.91308016391116 },\n { lat: -3.6852975446125242, lng: 40.40197212311381 },\n { lat: -75.17194183200792, lng: 40.001919022526465 },\n { lat: 72.57805776168215, lng: 23.031998775062675 },\n { lat: 106.69308136207889, lng: 10.781971309193409 },\n { lat: -79.42196665298843, lng: 43.70192573640844 },\n { lat: 103.85387481909902, lng: 1.2949793251059418 },\n { lat: 13.23248118266855, lng: -8.836340255012658 },\n { lat: 44.391922914564134, lng: 33.34059435615865 },\n { lat: 2.181424460619155, lng: 41.385245438547486 },\n { lat: 88.32994665421205, lng: 22.580390440861947 },\n { lat: -96.84196278749818, lng: 32.82196968167733 },\n { lat: 123.44802765120869, lng: 41.80692512604918 },\n { lat: 32.532233380011576, lng: 15.590024084277673 },\n { lat: 73.84805776168719, lng: 18.531963374654026 },\n { lat: 151.1832339501475, lng: -33.91806510862875 },\n { lat: 30.314074200315076, lng: 59.94096036375191 },\n { lat: 91.79802154756635, lng: 22.33193814680459 },\n { lat: 113.74277634138707, lng: 23.050834758613007 },\n { lat: -84.40189524187565, lng: 33.83195971260585 },\n { lat: -71.07195953218684, lng: 42.33190600170229 },\n { lat: 46.770795798688255, lng: 24.642779007816443 },\n { lat: -95.341925149146, lng: 29.821920243188856 },\n { lat: 105.8480683412422, lng: 21.035273107737055 },\n { lat: -77.01136443943716, lng: 38.901495235087054 },\n { lat: -103.33198008081848, lng: 20.671961950508944 },\n { lat: 144.97307037590406, lng: -37.81808545369631 },\n { lat: 29.948050030391755, lng: 31.201965205759393 },\n { lat: 104.06807363094873, lng: 30.671945877957796 },\n { lat: -83.0820016464927, lng: 42.33190600170229 },\n { lat: 96.16473175266185, lng: 16.785299963188777 },\n { lat: 108.89305043760862, lng: 34.27697130928732 },\n { lat: -51.20195790450316, lng: -30.048068770722466 },\n { lat: 121.465, lng: 25.0127777777778 },\n { lat: 72.83809356897484, lng: 21.20192960187819 },\n { lat: 109.60911291406296, lng: 23.09653464659317 },\n { lat: -4.041994118507091, lng: 5.321942826098564 },\n { lat: -47.91799814700306, lng: -15.781394372878992 },\n { lat: 32.862445782356644, lng: 39.929184444075474 },\n { lat: -100.33193064232995, lng: 25.671940995125283 },\n { lat: 139.60202098994017, lng: 35.43065615270891 },\n { lat: 118.77802846499208, lng: 32.05196500231233 },\n { lat: -73.58524281670213, lng: 45.50194506421502 },\n { lat: 106.7180927553083, lng: 26.581988806001448 },\n { lat: -34.91755136960728, lng: -8.073699467249241 },\n { lat: 126.64803904445057, lng: 45.75192980542715 },\n { lat: -38.58192718342411, lng: -3.7480720258257634 },\n { lat: -112.07193755969467, lng: 33.5419257363676 },\n { lat: 117.67001623440774, lng: 24.520375385531167 },\n { lat: -38.48193328693924, lng: -12.968026046044827 },\n { lat: 129.00810170722048, lng: 35.09699877511093 },\n { lat: -122.41716877355225, lng: 37.76919562968743 },\n { lat: 28.028063865019476, lng: -26.16809888138414 },\n { lat: 13.399602764700546, lng: 52.523764522251156 },\n { lat: 3.048606670909237, lng: 36.765010656628135 },\n { lat: 125.75274485499392, lng: 39.02138455800434 },\n { lat: 12.481312562873995, lng: 41.89790148509894 },\n];\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { faker } from '@faker-js/faker';\n\nimport { Expando, type TypedObject, Schema, type Space } from '@dxos/client/echo';\n\nimport { type TestGeneratorMap, type TestObjectProvider, type TestSchemaMap } from './types';\nimport { range } from './util';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string> {\n // prettier-ignore\n constructor(\n private readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>\n ) {}\n\n get schemas(): Schema[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T) {\n return this.schemas.find((schema) => schema.typename === type);\n }\n\n protected setSchema(type: T, schema: Schema) {\n this._schemas[type] = schema;\n }\n\n // TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).\n createObject({ types }: { types?: T[] } = {}): TypedObject {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = this._generators[type](this._provider);\n const schema = this.getSchema(type);\n return new Expando(data, { schema });\n }\n\n // TODO(burdon): Create batch.\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n createObjects(map: Partial<Record<T, number>>): Expando[] {\n const objects: Expando[] = [];\n Object.entries<number>(map as any).forEach(([type, count]) => {\n range(() => objects.push(this.createObject({ types: [type as T] })), count);\n });\n\n return objects;\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(private readonly _space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>) {\n super(schemaMap, generators, (type: T) => {\n const { objects } = this._space.db.query((object) => {\n return object.__schema?.id === this.getSchema(type)?.id;\n });\n\n return objects;\n });\n\n // TODO(burdon): Map initially are objects that have not been added to the space.\n // Merge existing schema in space with defaults.\n const { objects } = this._space.db.query(Schema.filter());\n Object.keys(schemaMap).forEach((type) => {\n const schema = objects.find((object) => object.typename === type);\n if (schema) {\n this.setSchema(type as T, schema);\n }\n });\n }\n\n addSchemas() {\n const { objects } = this._space.db.query(Schema.filter());\n this.schemas.forEach((schema) => {\n if (!objects.find((object) => object.typename === schema.typename)) {\n this._space.db.add(schema);\n }\n });\n\n return this.schemas;\n }\n\n override createObject({ types }: { types?: T[] } = {}): Expando {\n return this._space.db.add(super.createObject({ types }));\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Util.\nexport const range = <T>(fn: (i: number) => T | undefined, length: number): T[] =>\n Array.from({ length })\n .map((_, i) => fn(i))\n .filter(Boolean) as T[];\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;ACOA,IAAAA,gBAAsB;AAEtB,IAAAC,eAA+C;;;ACL/C,mBAAsB;AAEtB,kBAA8D;;;ACDvD,IAAMC,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AAED,KAAK;IAAmBC,KAAK;EAAmB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAmB;EACnD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAoB;EACpD;IAAED,KAAK;IAAqBC,KAAK;EAAiB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAmB;EACnD;IAAED,KAAK;IAAoBC,KAAK;EAAoB;EACpD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;EAClD;IAAED,KAAK;IAAqBC,KAAK;EAAkB;EACnD;IAAED,KAAK;IAAoBC,KAAK;EAAmB;EACnD;IAAED,KAAK;IAAoBC,KAAK;EAAmB;EACnD;IAAED,KAAK;IAAmBC,KAAK;EAAmB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;;",
|
|
6
|
+
"names": ["import_faker", "import_echo", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "TestObjectGenerator", "constructor", "_schemas", "_generators", "_provider", "schemas", "Object", "values", "getSchema", "type", "find", "schema", "typename", "setSchema", "createObject", "types", "faker", "helpers", "arrayElement", "keys", "data", "Expando", "createObjects", "map", "objects", "entries", "forEach", "count", "range", "push", "SpaceObjectGenerator", "_space", "schemaMap", "generators", "db", "query", "object", "__schema", "id", "Schema", "filter", "addSchemas", "add", "Status", "Priority", "TestSchemaType", "document", "organization", "contact", "project", "testSchemas", "Schema", "typename", "props", "id", "type", "PropType", "STRING", "REF", "ref", "NUMBER", "BOOLEAN", "testObjectGenerators", "title", "faker", "lorem", "sentence", "content", "sentences", "min", "max", "number", "int", "name", "company", "website", "datatype", "boolean", "probability", "internet", "url", "undefined", "description", "TextObject", "provider", "organizations", "location", "helpers", "arrayElement", "locations", "person", "fullName", "email", "org", "length", "commerce", "productName", "repo", "status", "priority", "active", "createTestObjectGenerator", "TestObjectGenerator", "createSpaceObjectGenerator", "space", "SpaceObjectGenerator", "lat", "lng"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo-generator/src/util.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/echo/echo-generator/src/util.ts":{"bytes":1052,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/generator.ts":{"bytes":10511,"imports":[{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-generator/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"packages/core/echo/echo-generator/src/data.ts":{"bytes":37168,"imports":[{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"}],"format":"esm"},"packages/core/echo/echo-generator/src/index.ts":{"bytes":629,"imports":[{"path":"packages/core/echo/echo-generator/src/data.ts","kind":"import-statement","original":"./data"},{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"},{"path":"packages/core/echo/echo-generator/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-generator/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":23256},"packages/core/echo/echo-generator/dist/lib/node/index.cjs":{"imports":[{"path":"@faker-js/faker","kind":"require-call","external":true},{"path":"@dxos/client/echo","kind":"require-call","external":true},{"path":"@faker-js/faker","kind":"require-call","external":true},{"path":"@dxos/client/echo","kind":"require-call","external":true}],"exports":[],"entryPoint":"packages/core/echo/echo-generator/src/index.ts","inputs":{"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":521},"packages/core/echo/echo-generator/src/data.ts":{"bytesInOutput":11082},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":2295},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":91}},"bytes":15418}}}
|
package/dist/types/src/data.d.ts
CHANGED
|
@@ -3,7 +3,12 @@ import { SpaceObjectGenerator, TestObjectGenerator } from './generator';
|
|
|
3
3
|
import { type TestGeneratorMap, type TestSchemaMap } from './types';
|
|
4
4
|
export declare const Status: string[];
|
|
5
5
|
export declare const Priority: number[];
|
|
6
|
-
export
|
|
6
|
+
export declare enum TestSchemaType {
|
|
7
|
+
document = "example.com/schema/document",
|
|
8
|
+
organization = "example.com/schema/organization",
|
|
9
|
+
contact = "example.com/schema/contact",
|
|
10
|
+
project = "example.com/schema/project"
|
|
11
|
+
}
|
|
7
12
|
export declare const testSchemas: () => TestSchemaMap<TestSchemaType>;
|
|
8
13
|
export declare const testObjectGenerators: TestGeneratorMap<TestSchemaType>;
|
|
9
14
|
export declare const createTestObjectGenerator: () => TestObjectGenerator<TestSchemaType>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/data.ts"],"names":[],"mappings":"AASA,OAAO,EAAU,KAAK,KAAK,EAAc,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAGpE,eAAO,MAAM,MAAM,UAAgC,CAAC;AACpD,eAAO,MAAM,QAAQ,UAAkB,CAAC;AAExC,
|
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/data.ts"],"names":[],"mappings":"AASA,OAAO,EAAU,KAAK,KAAK,EAAc,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAGpE,eAAO,MAAM,MAAM,UAAgC,CAAC;AACpD,eAAO,MAAM,QAAQ,UAAkB,CAAC;AAExC,oBAAY,cAAc;IACxB,QAAQ,gCAAgC;IACxC,YAAY,oCAAoC;IAChD,OAAO,+BAA+B;IACtC,OAAO,+BAA+B;CACvC;AAED,eAAO,MAAM,WAAW,QAAO,cAAc,cAAc,CAiG1D,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,cAAc,CAiCjE,CAAC;AAEF,eAAO,MAAM,yBAAyB,2CAAqE,CAAC;AAE5G,eAAO,MAAM,0BAA0B,UAAW,KAAK,yCACe,CAAC"}
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
import { Expando, type Schema, type Space } from '@dxos/client/echo';
|
|
1
|
+
import { Expando, type TypedObject, Schema, type Space } from '@dxos/client/echo';
|
|
2
2
|
import { type TestGeneratorMap, type TestObjectProvider, type TestSchemaMap } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Typed object generator.
|
|
5
5
|
*/
|
|
6
6
|
export declare class TestObjectGenerator<T extends string> {
|
|
7
|
-
readonly
|
|
7
|
+
private readonly _schemas;
|
|
8
8
|
private readonly _generators;
|
|
9
9
|
private readonly _provider?;
|
|
10
|
-
constructor(
|
|
10
|
+
constructor(_schemas: TestSchemaMap<T>, _generators: TestGeneratorMap<T>, _provider?: TestObjectProvider<T> | undefined);
|
|
11
11
|
get schemas(): Schema[];
|
|
12
|
-
getSchema(
|
|
12
|
+
getSchema(type: T): Schema | undefined;
|
|
13
|
+
protected setSchema(type: T, schema: Schema): void;
|
|
13
14
|
createObject({ types }?: {
|
|
14
15
|
types?: T[];
|
|
15
|
-
}):
|
|
16
|
-
createObjects(
|
|
17
|
-
types?: T[];
|
|
18
|
-
count: number;
|
|
19
|
-
}): Expando[];
|
|
16
|
+
}): TypedObject;
|
|
17
|
+
createObjects(map: Partial<Record<T, number>>): Expando[];
|
|
20
18
|
}
|
|
21
19
|
/**
|
|
22
20
|
* Typed object generator for a space.
|
|
23
21
|
*/
|
|
24
22
|
export declare class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {
|
|
25
23
|
private readonly _space;
|
|
26
|
-
constructor(_space: Space,
|
|
24
|
+
constructor(_space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>);
|
|
27
25
|
addSchemas(): Schema[];
|
|
28
26
|
createObject({ types }?: {
|
|
29
27
|
types?: T[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generator.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAElF,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7F;;GAEG;AACH,qBAAa,mBAAmB,CAAC,CAAC,SAAS,MAAM;IAG7C,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAFV,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAChC,SAAS,CAAC,mCAAuB;IAGpD,IAAI,OAAO,IAAI,MAAM,EAAE,CAEtB;IAED,SAAS,CAAC,IAAI,EAAE,CAAC;IAIjB,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM;IAK3C,YAAY,CAAC,EAAE,KAAK,EAAE,GAAE;QAAE,KAAK,CAAC,EAAE,CAAC,EAAE,CAAA;KAAO,GAAG,WAAW;IAS1D,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE;CAQ1D;AAED;;GAEG;AACH,qBAAa,oBAAoB,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IACpE,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAoBxG,UAAU;IAWD,YAAY,CAAC,EAAE,KAAK,EAAE,GAAE;QAAE,KAAK,CAAC,EAAE,CAAC,EAAE,CAAA;KAAO,GAAG,OAAO;CAGhE"}
|
|
@@ -3,6 +3,6 @@ export type TestObject = {
|
|
|
3
3
|
id: string;
|
|
4
4
|
} & Record<string, any>;
|
|
5
5
|
export type TestSchemaMap<T extends string> = Record<T, Schema>;
|
|
6
|
-
export type TestObjectProvider<T extends string> = (type: T) => Expando[];
|
|
7
6
|
export type TestGeneratorMap<T extends string> = Record<T, (provider: TestObjectProvider<T> | undefined) => any>;
|
|
7
|
+
export type TestObjectProvider<T extends string> = (type: T) => Expando[];
|
|
8
8
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE9D,MAAM,MAAM,UAAU,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE9D,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAEhE,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE9D,MAAM,MAAM,UAAU,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE9D,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAEhE,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,SAAS,KAAK,GAAG,CAAC,CAAC;AAEjH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-generator",
|
|
3
|
-
"version": "0.3.7
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "ECHO data generator for testing.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@faker-js/faker": "^8.0.2",
|
|
20
|
-
"@dxos/client": "0.3.7
|
|
21
|
-
"@dxos/node-std": "0.3.7
|
|
20
|
+
"@dxos/client": "0.3.7",
|
|
21
|
+
"@dxos/node-std": "0.3.7"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {},
|
|
24
24
|
"publishConfig": {
|
package/src/data.ts
CHANGED
|
@@ -16,15 +16,20 @@ import { type TestGeneratorMap, type TestSchemaMap } from './types';
|
|
|
16
16
|
export const Status = ['pending', 'active', 'done'];
|
|
17
17
|
export const Priority = [1, 2, 3, 4, 5];
|
|
18
18
|
|
|
19
|
-
export
|
|
19
|
+
export enum TestSchemaType {
|
|
20
|
+
document = 'example.com/schema/document',
|
|
21
|
+
organization = 'example.com/schema/organization',
|
|
22
|
+
contact = 'example.com/schema/contact',
|
|
23
|
+
project = 'example.com/schema/project',
|
|
24
|
+
}
|
|
20
25
|
|
|
21
26
|
export const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
22
27
|
const document = new Schema({
|
|
28
|
+
typename: TestSchemaType.document,
|
|
23
29
|
props: [
|
|
24
30
|
{
|
|
25
31
|
id: 'name',
|
|
26
32
|
type: Schema.PropType.STRING,
|
|
27
|
-
// TODO(burdon): primary: true,
|
|
28
33
|
},
|
|
29
34
|
{
|
|
30
35
|
id: 'content',
|
|
@@ -34,7 +39,7 @@ export const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
34
39
|
});
|
|
35
40
|
|
|
36
41
|
const organization = new Schema({
|
|
37
|
-
typename:
|
|
42
|
+
typename: TestSchemaType.organization,
|
|
38
43
|
props: [
|
|
39
44
|
{
|
|
40
45
|
id: 'name',
|
|
@@ -51,8 +56,8 @@ export const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
51
56
|
],
|
|
52
57
|
});
|
|
53
58
|
|
|
54
|
-
const
|
|
55
|
-
typename:
|
|
59
|
+
const contact = new Schema({
|
|
60
|
+
typename: TestSchemaType.contact,
|
|
56
61
|
props: [
|
|
57
62
|
{
|
|
58
63
|
id: 'name',
|
|
@@ -80,7 +85,7 @@ export const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
80
85
|
});
|
|
81
86
|
|
|
82
87
|
const project = new Schema({
|
|
83
|
-
typename:
|
|
88
|
+
typename: TestSchemaType.project,
|
|
84
89
|
props: [
|
|
85
90
|
{
|
|
86
91
|
id: 'title',
|
|
@@ -109,23 +114,28 @@ export const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
109
114
|
],
|
|
110
115
|
});
|
|
111
116
|
|
|
112
|
-
return {
|
|
117
|
+
return {
|
|
118
|
+
[TestSchemaType.document]: document,
|
|
119
|
+
[TestSchemaType.organization]: organization,
|
|
120
|
+
[TestSchemaType.contact]: contact,
|
|
121
|
+
[TestSchemaType.project]: project,
|
|
122
|
+
};
|
|
113
123
|
};
|
|
114
124
|
|
|
115
125
|
export const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {
|
|
116
|
-
document: () => ({
|
|
126
|
+
[TestSchemaType.document]: () => ({
|
|
117
127
|
title: faker.lorem.sentence(3),
|
|
118
128
|
content: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),
|
|
119
129
|
}),
|
|
120
130
|
|
|
121
|
-
organization: () => ({
|
|
131
|
+
[TestSchemaType.organization]: () => ({
|
|
122
132
|
name: faker.company.name(),
|
|
123
133
|
website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,
|
|
124
134
|
description: new TextObject(faker.lorem.sentences()),
|
|
125
135
|
}),
|
|
126
136
|
|
|
127
|
-
|
|
128
|
-
const organizations = provider?.(
|
|
137
|
+
[TestSchemaType.contact]: (provider) => {
|
|
138
|
+
const organizations = provider?.(TestSchemaType.organization);
|
|
129
139
|
const location = faker.datatype.boolean() ? faker.helpers.arrayElement(locations) : undefined;
|
|
130
140
|
return {
|
|
131
141
|
name: faker.person.fullName(),
|
|
@@ -138,7 +148,7 @@ export const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {
|
|
|
138
148
|
};
|
|
139
149
|
},
|
|
140
150
|
|
|
141
|
-
project: () => ({
|
|
151
|
+
[TestSchemaType.project]: () => ({
|
|
142
152
|
title: faker.commerce.productName(),
|
|
143
153
|
repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,
|
|
144
154
|
status: faker.helpers.arrayElement(Status),
|
|
@@ -251,6 +261,6 @@ const locations = [
|
|
|
251
261
|
{ lat: 28.028063865019476, lng: -26.16809888138414 },
|
|
252
262
|
{ lat: 13.399602764700546, lng: 52.523764522251156 },
|
|
253
263
|
{ lat: 3.048606670909237, lng: 36.765010656628135 },
|
|
254
|
-
{ lat: 12.481312562873995, lng: 41.89790148509894 },
|
|
255
264
|
{ lat: 125.75274485499392, lng: 39.02138455800434 },
|
|
265
|
+
{ lat: 12.481312562873995, lng: 41.89790148509894 },
|
|
256
266
|
];
|
package/src/generator.test.ts
CHANGED
|
@@ -6,9 +6,10 @@ import { faker } from '@faker-js/faker';
|
|
|
6
6
|
import { expect } from 'chai';
|
|
7
7
|
|
|
8
8
|
import { Client } from '@dxos/client';
|
|
9
|
+
import { debug } from '@dxos/client/echo';
|
|
9
10
|
import { describe, test } from '@dxos/test';
|
|
10
11
|
|
|
11
|
-
import { createSpaceObjectGenerator, createTestObjectGenerator } from './data';
|
|
12
|
+
import { createSpaceObjectGenerator, createTestObjectGenerator, TestSchemaType } from './data';
|
|
12
13
|
|
|
13
14
|
faker.seed(3);
|
|
14
15
|
|
|
@@ -17,7 +18,7 @@ describe('TestObjectGenerator', () => {
|
|
|
17
18
|
const generator = createTestObjectGenerator();
|
|
18
19
|
|
|
19
20
|
// Create raw object.
|
|
20
|
-
const object = generator.createObject({ types: [
|
|
21
|
+
const object = generator.createObject({ types: [TestSchemaType.contact] });
|
|
21
22
|
expect(object).to.exist;
|
|
22
23
|
});
|
|
23
24
|
|
|
@@ -26,19 +27,49 @@ describe('TestObjectGenerator', () => {
|
|
|
26
27
|
await client.initialize();
|
|
27
28
|
await client.halo.createIdentity();
|
|
28
29
|
const space = await client.spaces.create();
|
|
29
|
-
const generator = createSpaceObjectGenerator(space);
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
const generator = createSpaceObjectGenerator(space);
|
|
32
32
|
generator.addSchemas();
|
|
33
33
|
|
|
34
34
|
// Create org object.
|
|
35
|
-
const organization = generator.createObject({ types: [
|
|
35
|
+
const organization = generator.createObject({ types: [TestSchemaType.organization] });
|
|
36
36
|
expect(organization.__schema).to.exist;
|
|
37
37
|
|
|
38
38
|
// Expect at least one person object with a linked org reference.
|
|
39
|
-
const objects = generator.createObjects({
|
|
39
|
+
const objects = generator.createObjects({ [TestSchemaType.contact]: 10 });
|
|
40
40
|
expect(objects.some((object) => object.org === organization)).to.be.true;
|
|
41
41
|
|
|
42
42
|
await client.destroy();
|
|
43
43
|
});
|
|
44
|
+
|
|
45
|
+
test.only('idempotence', async () => {
|
|
46
|
+
const client = new Client();
|
|
47
|
+
await client.initialize();
|
|
48
|
+
await client.halo.createIdentity();
|
|
49
|
+
const space = await client.spaces.create();
|
|
50
|
+
|
|
51
|
+
const schemaId: string[] = [];
|
|
52
|
+
|
|
53
|
+
{
|
|
54
|
+
const generator = createSpaceObjectGenerator(space);
|
|
55
|
+
generator.addSchemas();
|
|
56
|
+
const organization = generator.createObject({ types: [TestSchemaType.organization] });
|
|
57
|
+
schemaId.push(organization.__schema!.id);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
{
|
|
61
|
+
const generator = createSpaceObjectGenerator(space);
|
|
62
|
+
generator.addSchemas();
|
|
63
|
+
const organization = generator.createObject({ types: [TestSchemaType.organization] });
|
|
64
|
+
schemaId.push(organization.__schema!.id);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
expect(schemaId[0]).to.eq(schemaId[1]);
|
|
68
|
+
|
|
69
|
+
{
|
|
70
|
+
console.log(space.db.objects.map((object) => object[debug]));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
await client.destroy();
|
|
74
|
+
});
|
|
44
75
|
});
|
package/src/generator.ts
CHANGED
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.
|
|
6
|
-
// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).
|
|
7
|
-
|
|
8
5
|
import { faker } from '@faker-js/faker';
|
|
9
6
|
|
|
10
|
-
import { Expando, type Schema, type Space } from '@dxos/client/echo';
|
|
7
|
+
import { Expando, type TypedObject, Schema, type Space } from '@dxos/client/echo';
|
|
11
8
|
|
|
12
9
|
import { type TestGeneratorMap, type TestObjectProvider, type TestSchemaMap } from './types';
|
|
13
10
|
import { range } from './util';
|
|
@@ -18,30 +15,40 @@ import { range } from './util';
|
|
|
18
15
|
export class TestObjectGenerator<T extends string> {
|
|
19
16
|
// prettier-ignore
|
|
20
17
|
constructor(
|
|
21
|
-
|
|
18
|
+
private readonly _schemas: TestSchemaMap<T>,
|
|
22
19
|
private readonly _generators: TestGeneratorMap<T>,
|
|
23
20
|
private readonly _provider?: TestObjectProvider<T>
|
|
24
21
|
) {}
|
|
25
22
|
|
|
26
23
|
get schemas(): Schema[] {
|
|
27
|
-
return Object.values(this.
|
|
24
|
+
return Object.values(this._schemas);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getSchema(type: T) {
|
|
28
|
+
return this.schemas.find((schema) => schema.typename === type);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
protected setSchema(type: T, schema: Schema) {
|
|
32
|
+
this._schemas[type] = schema;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const data =
|
|
38
|
-
|
|
39
|
-
return new Expando(data, { schema
|
|
35
|
+
// TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).
|
|
36
|
+
createObject({ types }: { types?: T[] } = {}): TypedObject {
|
|
37
|
+
const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));
|
|
38
|
+
const data = this._generators[type](this._provider);
|
|
39
|
+
const schema = this.getSchema(type);
|
|
40
|
+
return new Expando(data, { schema });
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
// TODO(burdon): Create batch.
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
// TODO(burdon): Based on dependencies (e.g., organization before contact).
|
|
45
|
+
createObjects(map: Partial<Record<T, number>>): Expando[] {
|
|
46
|
+
const objects: Expando[] = [];
|
|
47
|
+
Object.entries<number>(map as any).forEach(([type, count]) => {
|
|
48
|
+
range(() => objects.push(this.createObject({ types: [type as T] })), count);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return objects;
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
|
|
@@ -49,19 +56,34 @@ export class TestObjectGenerator<T extends string> {
|
|
|
49
56
|
* Typed object generator for a space.
|
|
50
57
|
*/
|
|
51
58
|
export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {
|
|
52
|
-
constructor(private readonly _space: Space,
|
|
53
|
-
super(
|
|
54
|
-
// TODO(burdon): Query by schema.
|
|
59
|
+
constructor(private readonly _space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>) {
|
|
60
|
+
super(schemaMap, generators, (type: T) => {
|
|
55
61
|
const { objects } = this._space.db.query((object) => {
|
|
56
|
-
return object.__schema ===
|
|
62
|
+
return object.__schema?.id === this.getSchema(type)?.id;
|
|
57
63
|
});
|
|
58
64
|
|
|
59
65
|
return objects;
|
|
60
66
|
});
|
|
67
|
+
|
|
68
|
+
// TODO(burdon): Map initially are objects that have not been added to the space.
|
|
69
|
+
// Merge existing schema in space with defaults.
|
|
70
|
+
const { objects } = this._space.db.query(Schema.filter());
|
|
71
|
+
Object.keys(schemaMap).forEach((type) => {
|
|
72
|
+
const schema = objects.find((object) => object.typename === type);
|
|
73
|
+
if (schema) {
|
|
74
|
+
this.setSchema(type as T, schema);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
61
77
|
}
|
|
62
78
|
|
|
63
79
|
addSchemas() {
|
|
64
|
-
|
|
80
|
+
const { objects } = this._space.db.query(Schema.filter());
|
|
81
|
+
this.schemas.forEach((schema) => {
|
|
82
|
+
if (!objects.find((object) => object.typename === schema.typename)) {
|
|
83
|
+
this._space.db.add(schema);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
65
87
|
return this.schemas;
|
|
66
88
|
}
|
|
67
89
|
|
package/src/types.ts
CHANGED
|
@@ -8,6 +8,6 @@ export type TestObject = { id: string } & Record<string, any>;
|
|
|
8
8
|
|
|
9
9
|
export type TestSchemaMap<T extends string> = Record<T, Schema>;
|
|
10
10
|
|
|
11
|
-
export type TestObjectProvider<T extends string> = (type: T) => Expando[];
|
|
12
|
-
|
|
13
11
|
export type TestGeneratorMap<T extends string> = Record<T, (provider: TestObjectProvider<T> | undefined) => any>;
|
|
12
|
+
|
|
13
|
+
export type TestObjectProvider<T extends string> = (type: T) => Expando[];
|