@dxos/echo-generator 0.3.3-main.d66bdd4 → 0.3.3-main.ef9deca
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 +170 -78
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +175 -79
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/data.d.ts +11 -0
- package/dist/types/src/data.d.ts.map +1 -0
- package/dist/types/src/generator.d.ts +25 -36
- package/dist/types/src/generator.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +8 -0
- package/dist/types/src/types.d.ts.map +1 -0
- package/dist/types/src/util.d.ts +2 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/data.ts +130 -0
- package/src/generator.test.ts +31 -4
- package/src/generator.ts +42 -97
- package/src/index.ts +2 -0
- package/src/types.ts +13 -0
- package/src/util.ts +9 -0
|
@@ -1,20 +1,65 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
2
|
|
|
3
|
+
// packages/core/echo/echo-generator/src/data.ts
|
|
4
|
+
import { faker as faker2 } from "@faker-js/faker";
|
|
5
|
+
import { Schema, Text } from "@dxos/client/echo";
|
|
6
|
+
|
|
3
7
|
// packages/core/echo/echo-generator/src/generator.ts
|
|
4
8
|
import { faker } from "@faker-js/faker";
|
|
5
|
-
import { Expando
|
|
9
|
+
import { Expando } from "@dxos/client/echo";
|
|
10
|
+
|
|
11
|
+
// packages/core/echo/echo-generator/src/util.ts
|
|
6
12
|
var range = (fn, length) => Array.from({
|
|
7
13
|
length
|
|
8
14
|
}).map((_, i) => fn(i)).filter(Boolean);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
|
|
16
|
+
// packages/core/echo/echo-generator/src/generator.ts
|
|
17
|
+
var TestObjectGenerator = class {
|
|
18
|
+
// prettier-ignore
|
|
19
|
+
constructor(schema, _generators, _provider) {
|
|
20
|
+
this.schema = schema;
|
|
21
|
+
this._generators = _generators;
|
|
22
|
+
this._provider = _provider;
|
|
23
|
+
}
|
|
24
|
+
get schemas() {
|
|
25
|
+
return Object.values(this.schema);
|
|
26
|
+
}
|
|
27
|
+
createObject({ types } = {}) {
|
|
28
|
+
const type = faker.helpers.arrayElement(types ?? Object.keys(this.schema));
|
|
29
|
+
const factory = this._generators[type];
|
|
30
|
+
const data = factory(this._provider);
|
|
31
|
+
return new Expando(data, {
|
|
32
|
+
schema: this.schema[type]
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
// TODO(burdon): Create batch.
|
|
36
|
+
createObjects({ types, count }) {
|
|
37
|
+
return range(() => this.createObject({
|
|
38
|
+
types
|
|
39
|
+
}), count);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
43
|
+
constructor(_space, schema, generators) {
|
|
44
|
+
super(schema, generators, (type) => {
|
|
45
|
+
const { objects } = this._space.db.query((object) => {
|
|
46
|
+
return object.__schema === schema[type];
|
|
47
|
+
});
|
|
48
|
+
return objects;
|
|
49
|
+
});
|
|
50
|
+
this._space = _space;
|
|
51
|
+
}
|
|
52
|
+
addSchemas() {
|
|
53
|
+
this.schemas.forEach((schema) => this._space.db.add(schema));
|
|
54
|
+
}
|
|
55
|
+
createObject({ types } = {}) {
|
|
56
|
+
return this._space.db.add(super.createObject({
|
|
57
|
+
types
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
17
60
|
};
|
|
61
|
+
|
|
62
|
+
// packages/core/echo/echo-generator/src/data.ts
|
|
18
63
|
var Status = [
|
|
19
64
|
"pending",
|
|
20
65
|
"active",
|
|
@@ -27,83 +72,130 @@ var Priority = [
|
|
|
27
72
|
4,
|
|
28
73
|
5
|
|
29
74
|
];
|
|
30
|
-
var
|
|
31
|
-
document
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
75
|
+
var testSchemas = () => {
|
|
76
|
+
const document = new Schema({
|
|
77
|
+
props: [
|
|
78
|
+
{
|
|
79
|
+
id: "name",
|
|
80
|
+
type: Schema.PropType.STRING
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "content",
|
|
84
|
+
type: Schema.PropType.STRING
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
});
|
|
88
|
+
const organization = new Schema({
|
|
89
|
+
props: [
|
|
90
|
+
// TODO(burdon): Add metadata for default label.
|
|
91
|
+
{
|
|
92
|
+
id: "name",
|
|
93
|
+
type: Schema.PropType.STRING
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "website",
|
|
97
|
+
type: Schema.PropType.STRING
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: "active",
|
|
101
|
+
type: Schema.PropType.BOOLEAN
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
});
|
|
105
|
+
const person = new Schema({
|
|
106
|
+
props: [
|
|
107
|
+
{
|
|
108
|
+
id: "name",
|
|
109
|
+
type: Schema.PropType.STRING
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: "email",
|
|
113
|
+
type: Schema.PropType.STRING
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
id: "org",
|
|
117
|
+
type: Schema.PropType.REF,
|
|
118
|
+
ref: organization
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
});
|
|
122
|
+
const project = new Schema({
|
|
123
|
+
props: [
|
|
124
|
+
{
|
|
125
|
+
id: "title",
|
|
126
|
+
type: Schema.PropType.STRING
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: "repo",
|
|
130
|
+
type: Schema.PropType.STRING
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: "status",
|
|
134
|
+
type: Schema.PropType.STRING
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
id: "priority",
|
|
138
|
+
type: Schema.PropType.NUMBER
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
document,
|
|
144
|
+
organization,
|
|
145
|
+
person,
|
|
146
|
+
project
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
var testObjectGenerators = {
|
|
150
|
+
document: () => ({
|
|
151
|
+
title: faker2.lorem.sentence(3),
|
|
152
|
+
content: faker2.lorem.sentences({
|
|
153
|
+
min: 1,
|
|
154
|
+
max: faker2.number.int({
|
|
35
155
|
min: 1,
|
|
36
|
-
max:
|
|
37
|
-
min: 1,
|
|
38
|
-
max: 3
|
|
39
|
-
})
|
|
156
|
+
max: 3
|
|
40
157
|
})
|
|
41
158
|
})
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
id: "repo",
|
|
59
|
-
type: SchemaType.PropType.STRING
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
id: "status",
|
|
63
|
-
type: SchemaType.PropType.STRING
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
id: "priority",
|
|
67
|
-
type: SchemaType.PropType.NUMBER
|
|
68
|
-
}
|
|
69
|
-
]
|
|
70
|
-
}),
|
|
71
|
-
createData: () => ({
|
|
72
|
-
title: faker.commerce.productName(),
|
|
73
|
-
repo: faker.datatype.boolean({
|
|
159
|
+
}),
|
|
160
|
+
organization: () => ({
|
|
161
|
+
name: faker2.company.name(),
|
|
162
|
+
website: faker2.datatype.boolean({
|
|
163
|
+
probability: 0.3
|
|
164
|
+
}) ? faker2.internet.url() : void 0,
|
|
165
|
+
description: new Text(faker2.lorem.sentences())
|
|
166
|
+
}),
|
|
167
|
+
person: (provider) => {
|
|
168
|
+
const organizations = provider?.("organization");
|
|
169
|
+
return {
|
|
170
|
+
name: faker2.person.fullName(),
|
|
171
|
+
email: faker2.datatype.boolean({
|
|
172
|
+
probability: 0.5
|
|
173
|
+
}) ? faker2.internet.email() : void 0,
|
|
174
|
+
org: organizations?.length && faker2.datatype.boolean({
|
|
74
175
|
probability: 0.3
|
|
75
|
-
}) ?
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}, {});
|
|
87
|
-
}
|
|
88
|
-
get schema() {
|
|
89
|
-
return Object.values(this.factories).map((f) => f.schema);
|
|
90
|
-
}
|
|
91
|
-
createObject({ types } = {}) {
|
|
92
|
-
const type = faker.helpers.arrayElement(types ?? Object.keys(this.factories));
|
|
93
|
-
const factory = this.factories[type];
|
|
94
|
-
return factory?.createObject();
|
|
95
|
-
}
|
|
96
|
-
createObjects({ types, length }) {
|
|
97
|
-
return range(() => this.createObject({
|
|
98
|
-
types
|
|
99
|
-
}), length);
|
|
100
|
-
}
|
|
176
|
+
}) ? faker2.helpers.arrayElement(organizations) : void 0
|
|
177
|
+
};
|
|
178
|
+
},
|
|
179
|
+
project: () => ({
|
|
180
|
+
title: faker2.commerce.productName(),
|
|
181
|
+
repo: faker2.datatype.boolean({
|
|
182
|
+
probability: 0.3
|
|
183
|
+
}) ? faker2.internet.url() : void 0,
|
|
184
|
+
status: faker2.helpers.arrayElement(Status),
|
|
185
|
+
priority: faker2.helpers.arrayElement(Priority)
|
|
186
|
+
})
|
|
101
187
|
};
|
|
188
|
+
var createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);
|
|
189
|
+
var createSpaceObjectGenerator = (space) => new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);
|
|
102
190
|
export {
|
|
103
191
|
Priority,
|
|
192
|
+
SpaceObjectGenerator,
|
|
104
193
|
Status,
|
|
105
194
|
TestObjectGenerator,
|
|
106
|
-
|
|
107
|
-
|
|
195
|
+
createSpaceObjectGenerator,
|
|
196
|
+
createTestObjectGenerator,
|
|
197
|
+
range,
|
|
198
|
+
testObjectGenerators,
|
|
199
|
+
testSchemas
|
|
108
200
|
};
|
|
109
201
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/generator.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 {
|
|
5
|
-
"mappings": ";;;AAOA,SAASA,
|
|
6
|
-
"names": ["faker", "
|
|
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, Text } 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 },\n {\n id: 'content',\n type: Schema.PropType.STRING, // TODO(burdon): Rich text.\n },\n ],\n });\n\n const organization = new Schema({\n props: [\n // TODO(burdon): Add metadata for default label.\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'website',\n type: Schema.PropType.STRING,\n },\n {\n id: 'active',\n type: Schema.PropType.BOOLEAN,\n },\n ],\n });\n\n const person = new Schema({\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 ],\n });\n\n const project = new Schema({\n props: [\n {\n id: 'title',\n type: Schema.PropType.STRING,\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 });\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 Text(faker.lorem.sentences()),\n }),\n\n person: (provider) => {\n const organizations = provider?.('organization');\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 };\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 }),\n};\n\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);\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 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 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 }\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": 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AMC,MAAMC,SAAS,CAAA;IAC5BC,SAASH,OAAMC,MAAMG,UAAU;MAAEC,KAAK;MAAGC,KAAKN,OAAMO,OAAOC,IAAI;QAAEH,KAAK;QAAGC,KAAK;MAAE,CAAA;IAAG,CAAA;EACrF;EAEAf,cAAc,OAAO;IACnBkB,MAAMT,OAAMU,QAAQD,KAAI;IACxBE,SAASX,OAAMY,SAASC,QAAQ;MAAEC,aAAa;IAAI,CAAA,IAAKd,OAAMe,SAASC,IAAG,IAAKC;IAC/EC,aAAa,IAAIC,KAAKnB,OAAMC,MAAMG,UAAS,CAAA;EAC7C;EAEAX,QAAQ,CAAC2B,aAAAA;AACP,UAAMC,gBAAgBD,WAAW,cAAA;AACjC,WAAO;MACLX,MAAMT,OAAMP,OAAO6B,SAAQ;MAC3BC,OAAOvB,OAAMY,SAASC,QAAQ;QAAEC,aAAa;MAAI,CAAA,IAAKd,OAAMe,SAASQ,MAAK,IAAKN;MAC/EO,KACEH,eAAeI,UAAUzB,OAAMY,SAASC,QAAQ;QAAEC,aAAa;MAAI,CAAA,IAC/Dd,OAAM0B,QAAQC,aAAaN,aAAAA,IAC3BJ;IACR;EACF;EAEArB,SAAS,OAAO;IACdG,OAAOC,OAAM4B,SAASC,YAAW;IACjCC,MAAM9B,OAAMY,SAASC,QAAQ;MAAEC,aAAa;IAAI,CAAA,IAAKd,OAAMe,SAASC,IAAG,IAAKC;IAC5Ec,QAAQ/B,OAAM0B,QAAQC,aAAa9C,MAAAA;IACnCmD,UAAUhC,OAAM0B,QAAQC,aAAa7C,QAAAA;EACvC;AACF;AAEO,IAAMmD,4BAA4B,MAAM,IAAIC,oBAAoBnD,YAAAA,GAAee,oBAAAA;AAE/E,IAAMqC,6BAA6B,CAACC,UACzC,IAAIC,qBAAqBD,OAAOrD,YAAAA,GAAee,oBAAAA;",
|
|
6
|
+
"names": ["faker", "Schema", "Text", "faker", "Expando", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "TestObjectGenerator", "constructor", "schema", "_generators", "_provider", "schemas", "Object", "values", "createObject", "types", "type", "faker", "helpers", "arrayElement", "keys", "factory", "data", "Expando", "createObjects", "count", "range", "SpaceObjectGenerator", "_space", "generators", "objects", "db", "query", "object", "__schema", "addSchemas", "forEach", "add", "Status", "Priority", "testSchemas", "document", "Schema", "props", "id", "type", "PropType", "STRING", "organization", "BOOLEAN", "person", "REF", "ref", "project", "NUMBER", "testObjectGenerators", "title", "faker", "lorem", "sentence", "content", "sentences", "min", "max", "number", "int", "name", "company", "website", "datatype", "boolean", "probability", "internet", "url", "undefined", "description", "Text", "provider", "organizations", "fullName", "email", "org", "length", "helpers", "arrayElement", "commerce", "productName", "repo", "status", "priority", "createTestObjectGenerator", "TestObjectGenerator", "createSpaceObjectGenerator", "space", "SpaceObjectGenerator"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/echo/echo-generator/src/util.ts":{"bytes":1057,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/generator.ts":{"bytes":7133,"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":12963,"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":634,"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":10324},"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","createSpaceObjectGenerator","createTestObjectGenerator","range","testObjectGenerators","testSchemas"],"entryPoint":"packages/core/echo/echo-generator/src/index.ts","inputs":{"packages/core/echo/echo-generator/src/data.ts":{"bytesInOutput":2835},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":1297},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":91},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":4738}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -21,28 +21,77 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
Priority: () => Priority,
|
|
24
|
+
SpaceObjectGenerator: () => SpaceObjectGenerator,
|
|
24
25
|
Status: () => Status,
|
|
25
26
|
TestObjectGenerator: () => TestObjectGenerator,
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
createSpaceObjectGenerator: () => createSpaceObjectGenerator,
|
|
28
|
+
createTestObjectGenerator: () => createTestObjectGenerator,
|
|
29
|
+
range: () => range,
|
|
30
|
+
testObjectGenerators: () => testObjectGenerators,
|
|
31
|
+
testSchemas: () => testSchemas
|
|
28
32
|
});
|
|
29
33
|
module.exports = __toCommonJS(src_exports);
|
|
30
34
|
|
|
35
|
+
// packages/core/echo/echo-generator/src/data.ts
|
|
36
|
+
var import_faker2 = require("@faker-js/faker");
|
|
37
|
+
var import_echo2 = require("@dxos/client/echo");
|
|
38
|
+
|
|
31
39
|
// packages/core/echo/echo-generator/src/generator.ts
|
|
32
40
|
var import_faker = require("@faker-js/faker");
|
|
33
41
|
var import_echo = require("@dxos/client/echo");
|
|
42
|
+
|
|
43
|
+
// packages/core/echo/echo-generator/src/util.ts
|
|
34
44
|
var range = (fn, length) => Array.from({
|
|
35
45
|
length
|
|
36
46
|
}).map((_, i) => fn(i)).filter(Boolean);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
|
|
48
|
+
// packages/core/echo/echo-generator/src/generator.ts
|
|
49
|
+
var TestObjectGenerator = class {
|
|
50
|
+
// prettier-ignore
|
|
51
|
+
constructor(schema, _generators, _provider) {
|
|
52
|
+
this.schema = schema;
|
|
53
|
+
this._generators = _generators;
|
|
54
|
+
this._provider = _provider;
|
|
55
|
+
}
|
|
56
|
+
get schemas() {
|
|
57
|
+
return Object.values(this.schema);
|
|
58
|
+
}
|
|
59
|
+
createObject({ types } = {}) {
|
|
60
|
+
const type = import_faker.faker.helpers.arrayElement(types ?? Object.keys(this.schema));
|
|
61
|
+
const factory = this._generators[type];
|
|
62
|
+
const data = factory(this._provider);
|
|
63
|
+
return new import_echo.Expando(data, {
|
|
64
|
+
schema: this.schema[type]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// TODO(burdon): Create batch.
|
|
68
|
+
createObjects({ types, count }) {
|
|
69
|
+
return range(() => this.createObject({
|
|
70
|
+
types
|
|
71
|
+
}), count);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
75
|
+
constructor(_space, schema, generators) {
|
|
76
|
+
super(schema, generators, (type) => {
|
|
77
|
+
const { objects } = this._space.db.query((object) => {
|
|
78
|
+
return object.__schema === schema[type];
|
|
79
|
+
});
|
|
80
|
+
return objects;
|
|
81
|
+
});
|
|
82
|
+
this._space = _space;
|
|
83
|
+
}
|
|
84
|
+
addSchemas() {
|
|
85
|
+
this.schemas.forEach((schema) => this._space.db.add(schema));
|
|
86
|
+
}
|
|
87
|
+
createObject({ types } = {}) {
|
|
88
|
+
return this._space.db.add(super.createObject({
|
|
89
|
+
types
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
45
92
|
};
|
|
93
|
+
|
|
94
|
+
// packages/core/echo/echo-generator/src/data.ts
|
|
46
95
|
var Status = [
|
|
47
96
|
"pending",
|
|
48
97
|
"active",
|
|
@@ -55,84 +104,131 @@ var Priority = [
|
|
|
55
104
|
4,
|
|
56
105
|
5
|
|
57
106
|
];
|
|
58
|
-
var
|
|
59
|
-
document
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
107
|
+
var testSchemas = () => {
|
|
108
|
+
const document = new import_echo2.Schema({
|
|
109
|
+
props: [
|
|
110
|
+
{
|
|
111
|
+
id: "name",
|
|
112
|
+
type: import_echo2.Schema.PropType.STRING
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: "content",
|
|
116
|
+
type: import_echo2.Schema.PropType.STRING
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
});
|
|
120
|
+
const organization = new import_echo2.Schema({
|
|
121
|
+
props: [
|
|
122
|
+
// TODO(burdon): Add metadata for default label.
|
|
123
|
+
{
|
|
124
|
+
id: "name",
|
|
125
|
+
type: import_echo2.Schema.PropType.STRING
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: "website",
|
|
129
|
+
type: import_echo2.Schema.PropType.STRING
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: "active",
|
|
133
|
+
type: import_echo2.Schema.PropType.BOOLEAN
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
});
|
|
137
|
+
const person = new import_echo2.Schema({
|
|
138
|
+
props: [
|
|
139
|
+
{
|
|
140
|
+
id: "name",
|
|
141
|
+
type: import_echo2.Schema.PropType.STRING
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
id: "email",
|
|
145
|
+
type: import_echo2.Schema.PropType.STRING
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: "org",
|
|
149
|
+
type: import_echo2.Schema.PropType.REF,
|
|
150
|
+
ref: organization
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
});
|
|
154
|
+
const project = new import_echo2.Schema({
|
|
155
|
+
props: [
|
|
156
|
+
{
|
|
157
|
+
id: "title",
|
|
158
|
+
type: import_echo2.Schema.PropType.STRING
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
id: "repo",
|
|
162
|
+
type: import_echo2.Schema.PropType.STRING
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: "status",
|
|
166
|
+
type: import_echo2.Schema.PropType.STRING
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
id: "priority",
|
|
170
|
+
type: import_echo2.Schema.PropType.NUMBER
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
document,
|
|
176
|
+
organization,
|
|
177
|
+
person,
|
|
178
|
+
project
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
var testObjectGenerators = {
|
|
182
|
+
document: () => ({
|
|
183
|
+
title: import_faker2.faker.lorem.sentence(3),
|
|
184
|
+
content: import_faker2.faker.lorem.sentences({
|
|
185
|
+
min: 1,
|
|
186
|
+
max: import_faker2.faker.number.int({
|
|
63
187
|
min: 1,
|
|
64
|
-
max:
|
|
65
|
-
min: 1,
|
|
66
|
-
max: 3
|
|
67
|
-
})
|
|
188
|
+
max: 3
|
|
68
189
|
})
|
|
69
190
|
})
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
id: "repo",
|
|
87
|
-
type: import_echo.Schema.PropType.STRING
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
id: "status",
|
|
91
|
-
type: import_echo.Schema.PropType.STRING
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
id: "priority",
|
|
95
|
-
type: import_echo.Schema.PropType.NUMBER
|
|
96
|
-
}
|
|
97
|
-
]
|
|
98
|
-
}),
|
|
99
|
-
createData: () => ({
|
|
100
|
-
title: import_faker.faker.commerce.productName(),
|
|
101
|
-
repo: import_faker.faker.datatype.boolean({
|
|
191
|
+
}),
|
|
192
|
+
organization: () => ({
|
|
193
|
+
name: import_faker2.faker.company.name(),
|
|
194
|
+
website: import_faker2.faker.datatype.boolean({
|
|
195
|
+
probability: 0.3
|
|
196
|
+
}) ? import_faker2.faker.internet.url() : void 0,
|
|
197
|
+
description: new import_echo2.Text(import_faker2.faker.lorem.sentences())
|
|
198
|
+
}),
|
|
199
|
+
person: (provider) => {
|
|
200
|
+
const organizations = provider?.("organization");
|
|
201
|
+
return {
|
|
202
|
+
name: import_faker2.faker.person.fullName(),
|
|
203
|
+
email: import_faker2.faker.datatype.boolean({
|
|
204
|
+
probability: 0.5
|
|
205
|
+
}) ? import_faker2.faker.internet.email() : void 0,
|
|
206
|
+
org: organizations?.length && import_faker2.faker.datatype.boolean({
|
|
102
207
|
probability: 0.3
|
|
103
|
-
}) ?
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}, {});
|
|
115
|
-
}
|
|
116
|
-
get schema() {
|
|
117
|
-
return Object.values(this.factories).map((f) => f.schema);
|
|
118
|
-
}
|
|
119
|
-
createObject({ types } = {}) {
|
|
120
|
-
const type = import_faker.faker.helpers.arrayElement(types ?? Object.keys(this.factories));
|
|
121
|
-
const factory = this.factories[type];
|
|
122
|
-
return factory?.createObject();
|
|
123
|
-
}
|
|
124
|
-
createObjects({ types, length }) {
|
|
125
|
-
return range(() => this.createObject({
|
|
126
|
-
types
|
|
127
|
-
}), length);
|
|
128
|
-
}
|
|
208
|
+
}) ? import_faker2.faker.helpers.arrayElement(organizations) : void 0
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
project: () => ({
|
|
212
|
+
title: import_faker2.faker.commerce.productName(),
|
|
213
|
+
repo: import_faker2.faker.datatype.boolean({
|
|
214
|
+
probability: 0.3
|
|
215
|
+
}) ? import_faker2.faker.internet.url() : void 0,
|
|
216
|
+
status: import_faker2.faker.helpers.arrayElement(Status),
|
|
217
|
+
priority: import_faker2.faker.helpers.arrayElement(Priority)
|
|
218
|
+
})
|
|
129
219
|
};
|
|
220
|
+
var createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);
|
|
221
|
+
var createSpaceObjectGenerator = (space) => new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);
|
|
130
222
|
// Annotate the CommonJS export names for ESM import in node:
|
|
131
223
|
0 && (module.exports = {
|
|
132
224
|
Priority,
|
|
225
|
+
SpaceObjectGenerator,
|
|
133
226
|
Status,
|
|
134
227
|
TestObjectGenerator,
|
|
135
|
-
|
|
136
|
-
|
|
228
|
+
createSpaceObjectGenerator,
|
|
229
|
+
createTestObjectGenerator,
|
|
230
|
+
range,
|
|
231
|
+
testObjectGenerators,
|
|
232
|
+
testSchemas
|
|
137
233
|
});
|
|
138
234
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/index.ts", "../../../src/generator.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport * from './generator';\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 {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA
|
|
6
|
-
"names": ["range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "
|
|
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, Text } 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 },\n {\n id: 'content',\n type: Schema.PropType.STRING, // TODO(burdon): Rich text.\n },\n ],\n });\n\n const organization = new Schema({\n props: [\n // TODO(burdon): Add metadata for default label.\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'website',\n type: Schema.PropType.STRING,\n },\n {\n id: 'active',\n type: Schema.PropType.BOOLEAN,\n },\n ],\n });\n\n const person = new Schema({\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 ],\n });\n\n const project = new Schema({\n props: [\n {\n id: 'title',\n type: Schema.PropType.STRING,\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 });\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 Text(faker.lorem.sentences()),\n }),\n\n person: (provider) => {\n const organizations = provider?.('organization');\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 };\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 }),\n};\n\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);\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 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 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 }\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,eAAyC;;;ACFzC,mBAAsB;AAEtB,kBAAiD;;;ACJ1C,IAAMC,QAAQ,CAAIC,IAAkCC,WACzDC,MAAMC,KAAK;EAAEF;AAAO,CAAA,EACjBG,IAAI,CAACC,GAAGC,MAAMN,GAAGM,CAAAA,CAAAA,EACjBC,OAAOC,OAAAA;;;ADSL,IAAMC,sBAAN,MAAMA;;EAEXC,YACkBC,QACCC,aACAC,WACjB;kBAHgBF;uBACCC;qBACAC;EAChB;EAEH,IAAIC,UAAoB;AACtB,WAAOC,OAAOC,OAAO,K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;EAC7C;EAEAX,QAAQ,CAAC2B,aAAAA;AACP,UAAMC,gBAAgBD,WAAW,cAAA;AACjC,WAAO;MACLX,MAAMT,oBAAMP,OAAO6B,SAAQ;MAC3BC,OAAOvB,oBAAMY,SAASC,QAAQ;QAAEC,aAAa;MAAI,CAAA,IAAKd,oBAAMe,SAASQ,MAAK,IAAKN;MAC/EO,KACEH,eAAeI,UAAUzB,oBAAMY,SAASC,QAAQ;QAAEC,aAAa;MAAI,CAAA,IAC/Dd,oBAAM0B,QAAQC,aAAaN,aAAAA,IAC3BJ;IACR;EACF;EAEArB,SAAS,OAAO;IACdG,OAAOC,oBAAM4B,SAASC,YAAW;IACjCC,MAAM9B,oBAAMY,SAASC,QAAQ;MAAEC,aAAa;IAAI,CAAA,IAAKd,oBAAMe,SAASC,IAAG,IAAKC;IAC5Ec,QAAQ/B,oBAAM0B,QAAQC,aAAa9C,MAAAA;IACnCmD,UAAUhC,oBAAM0B,QAAQC,aAAa7C,QAAAA;EACvC;AACF;AAEO,IAAMmD,4BAA4B,MAAM,IAAIC,oBAAoBnD,YAAAA,GAAee,oBAAAA;AAE/E,IAAMqC,6BAA6B,CAACC,UACzC,IAAIC,qBAAqBD,OAAOrD,YAAAA,GAAee,oBAAAA;",
|
|
6
|
+
"names": ["import_faker", "import_echo", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "TestObjectGenerator", "constructor", "schema", "_generators", "_provider", "schemas", "Object", "values", "createObject", "types", "type", "faker", "helpers", "arrayElement", "keys", "factory", "data", "Expando", "createObjects", "count", "range", "SpaceObjectGenerator", "_space", "generators", "objects", "db", "query", "object", "__schema", "addSchemas", "forEach", "add", "Status", "Priority", "testSchemas", "document", "Schema", "props", "id", "type", "PropType", "STRING", "organization", "BOOLEAN", "person", "REF", "ref", "project", "NUMBER", "testObjectGenerators", "title", "faker", "lorem", "sentence", "content", "sentences", "min", "max", "number", "int", "name", "company", "website", "datatype", "boolean", "probability", "internet", "url", "undefined", "description", "Text", "provider", "organizations", "fullName", "email", "org", "length", "helpers", "arrayElement", "commerce", "productName", "repo", "status", "priority", "createTestObjectGenerator", "TestObjectGenerator", "createSpaceObjectGenerator", "space", "SpaceObjectGenerator"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/echo/echo-generator/src/util.ts":{"bytes":1057,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/generator.ts":{"bytes":7133,"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":12963,"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":634,"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":10508},"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":481},"packages/core/echo/echo-generator/src/data.ts":{"bytesInOutput":3273},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":1331},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":91}},"bytes":6587}}}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Space } from '@dxos/client/echo';
|
|
2
|
+
import { SpaceObjectGenerator, TestObjectGenerator } from './generator';
|
|
3
|
+
import { type TestGeneratorMap, type TestSchemaMap } from './types';
|
|
4
|
+
export declare const Status: string[];
|
|
5
|
+
export declare const Priority: number[];
|
|
6
|
+
export type TestSchemaType = 'document' | 'organization' | 'person' | 'project';
|
|
7
|
+
export declare const testSchemas: () => TestSchemaMap<TestSchemaType>;
|
|
8
|
+
export declare const testObjectGenerators: TestGeneratorMap<TestSchemaType>;
|
|
9
|
+
export declare const createTestObjectGenerator: () => TestObjectGenerator<TestSchemaType>;
|
|
10
|
+
export declare const createSpaceObjectGenerator: (space: Space) => SpaceObjectGenerator<TestSchemaType>;
|
|
11
|
+
//# sourceMappingURL=data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/data.ts"],"names":[],"mappings":"AASA,OAAO,EAAU,KAAK,KAAK,EAAQ,MAAM,mBAAmB,CAAC;AAE7D,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,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,cAAc,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEhF,eAAO,MAAM,WAAW,QAAO,cAAc,cAAc,CAwE1D,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,cAAc,CA8BjE,CAAC;AAEF,eAAO,MAAM,yBAAyB,2CAAqE,CAAC;AAE5G,eAAO,MAAM,0BAA0B,UAAW,KAAK,yCACe,CAAC"}
|
|
@@ -1,42 +1,31 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
3
|
-
export type TestItem = {
|
|
4
|
-
id: string;
|
|
5
|
-
type: string;
|
|
6
|
-
} & Record<string, any>;
|
|
7
|
-
type ObjectDataGenerator = {
|
|
8
|
-
createSchema?: () => SchemaType;
|
|
9
|
-
createData: () => any;
|
|
10
|
-
};
|
|
11
|
-
type ObjectFactory<T extends TypedObject> = {
|
|
12
|
-
schema?: SchemaType;
|
|
13
|
-
createObject: () => T;
|
|
14
|
-
};
|
|
15
|
-
type ObjectFactoryMap = {
|
|
16
|
-
[type: string]: ObjectFactory<any>;
|
|
17
|
-
};
|
|
18
|
-
export declare const Status: string[];
|
|
19
|
-
export declare const Priority: number[];
|
|
20
|
-
export declare const defaultGenerators: {
|
|
21
|
-
[type: string]: ObjectDataGenerator;
|
|
22
|
-
};
|
|
1
|
+
import { Expando, type Schema, type Space } from '@dxos/client/echo';
|
|
2
|
+
import { type TestGeneratorMap, type TestObjectProvider, type TestSchemaMap } from './types';
|
|
23
3
|
/**
|
|
24
4
|
* Typed object generator.
|
|
25
5
|
*/
|
|
26
|
-
export declare class TestObjectGenerator {
|
|
27
|
-
readonly
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
get schema(): SchemaType[];
|
|
6
|
+
export declare class TestObjectGenerator<T extends string> {
|
|
7
|
+
readonly schema: TestSchemaMap<T>;
|
|
8
|
+
private readonly _generators;
|
|
9
|
+
private readonly _provider?;
|
|
10
|
+
constructor(schema: TestSchemaMap<T>, _generators: TestGeneratorMap<T>, _provider?: TestObjectProvider<T> | undefined);
|
|
11
|
+
get schemas(): Schema[];
|
|
33
12
|
createObject({ types }?: {
|
|
34
|
-
types?:
|
|
35
|
-
}):
|
|
36
|
-
createObjects({ types,
|
|
37
|
-
types?:
|
|
38
|
-
|
|
39
|
-
}):
|
|
13
|
+
types?: T[];
|
|
14
|
+
}): Expando;
|
|
15
|
+
createObjects({ types, count }: {
|
|
16
|
+
types?: T[];
|
|
17
|
+
count: number;
|
|
18
|
+
}): Expando[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Typed object generator for a space.
|
|
22
|
+
*/
|
|
23
|
+
export declare class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {
|
|
24
|
+
private readonly _space;
|
|
25
|
+
constructor(_space: Space, schema: TestSchemaMap<T>, generators: TestGeneratorMap<T>);
|
|
26
|
+
addSchemas(): void;
|
|
27
|
+
createObject({ types }?: {
|
|
28
|
+
types?: T[];
|
|
29
|
+
}): Expando;
|
|
40
30
|
}
|
|
41
|
-
export {};
|
|
42
31
|
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generator.ts"],"names":[],"mappings":"AASA,OAAO,
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generator.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7F;;GAEG;AACH,qBAAa,mBAAmB,CAAC,CAAC,SAAS,MAAM;aAG7B,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;IACxC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAFX,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,EACvB,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAChC,SAAS,CAAC,mCAAuB;IAGpD,IAAI,OAAO,IAAI,MAAM,EAAE,CAEtB;IAED,YAAY,CAAC,EAAE,KAAK,EAAE,GAAE;QAAE,KAAK,CAAC,EAAE,CAAC,EAAE,CAAA;KAAO,GAAG,OAAO;IAQtD,aAAa,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,EAAE;CAG3E;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,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAWrG,UAAU;IAID,YAAY,CAAC,EAAE,KAAK,EAAE,GAAE;QAAE,KAAK,CAAC,EAAE,CAAC,EAAE,CAAA;KAAO,GAAG,OAAO;CAGhE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Schema, type Expando } from '@dxos/client/echo';
|
|
2
|
+
export type TestObject = {
|
|
3
|
+
id: string;
|
|
4
|
+
} & Record<string, any>;
|
|
5
|
+
export type TestSchemaMap<T extends string> = Record<T, Schema>;
|
|
6
|
+
export type TestObjectProvider<T extends string> = (type: T) => Expando[];
|
|
7
|
+
export type TestGeneratorMap<T extends string> = Record<T, (provider: TestObjectProvider<T> | undefined) => any>;
|
|
8
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,EAAE,CAAC;AAE1E,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,KAAK,cAAe,MAAM,4BAA4B,MAAM,QAG9C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-generator",
|
|
3
|
-
"version": "0.3.3-main.
|
|
3
|
+
"version": "0.3.3-main.ef9deca",
|
|
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.3-main.
|
|
21
|
-
"@dxos/node-std": "0.3.3-main.
|
|
20
|
+
"@dxos/client": "0.3.3-main.ef9deca",
|
|
21
|
+
"@dxos/node-std": "0.3.3-main.ef9deca"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {},
|
|
24
24
|
"publishConfig": {
|
package/src/data.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
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
|
+
import { faker } from '@faker-js/faker';
|
|
9
|
+
|
|
10
|
+
import { Schema, type Space, Text } from '@dxos/client/echo';
|
|
11
|
+
|
|
12
|
+
import { SpaceObjectGenerator, TestObjectGenerator } from './generator';
|
|
13
|
+
import { type TestGeneratorMap, type TestSchemaMap } from './types';
|
|
14
|
+
|
|
15
|
+
// TODO(burdon): Handle restricted values.
|
|
16
|
+
export const Status = ['pending', 'active', 'done'];
|
|
17
|
+
export const Priority = [1, 2, 3, 4, 5];
|
|
18
|
+
|
|
19
|
+
export type TestSchemaType = 'document' | 'organization' | 'person' | 'project';
|
|
20
|
+
|
|
21
|
+
export const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
22
|
+
const document = new Schema({
|
|
23
|
+
props: [
|
|
24
|
+
{
|
|
25
|
+
id: 'name',
|
|
26
|
+
type: Schema.PropType.STRING,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'content',
|
|
30
|
+
type: Schema.PropType.STRING, // TODO(burdon): Rich text.
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const organization = new Schema({
|
|
36
|
+
props: [
|
|
37
|
+
// TODO(burdon): Add metadata for default label.
|
|
38
|
+
{
|
|
39
|
+
id: 'name',
|
|
40
|
+
type: Schema.PropType.STRING,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: 'website',
|
|
44
|
+
type: Schema.PropType.STRING,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'active',
|
|
48
|
+
type: Schema.PropType.BOOLEAN,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const person = new Schema({
|
|
54
|
+
props: [
|
|
55
|
+
{
|
|
56
|
+
id: 'name',
|
|
57
|
+
type: Schema.PropType.STRING,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 'email',
|
|
61
|
+
type: Schema.PropType.STRING,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 'org',
|
|
65
|
+
type: Schema.PropType.REF,
|
|
66
|
+
ref: organization,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const project = new Schema({
|
|
72
|
+
props: [
|
|
73
|
+
{
|
|
74
|
+
id: 'title',
|
|
75
|
+
type: Schema.PropType.STRING,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: 'repo',
|
|
79
|
+
type: Schema.PropType.STRING,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: 'status',
|
|
83
|
+
type: Schema.PropType.STRING,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: 'priority',
|
|
87
|
+
type: Schema.PropType.NUMBER,
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return { document, organization, person, project };
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {
|
|
96
|
+
document: () => ({
|
|
97
|
+
title: faker.lorem.sentence(3),
|
|
98
|
+
content: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),
|
|
99
|
+
}),
|
|
100
|
+
|
|
101
|
+
organization: () => ({
|
|
102
|
+
name: faker.company.name(),
|
|
103
|
+
website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,
|
|
104
|
+
description: new Text(faker.lorem.sentences()),
|
|
105
|
+
}),
|
|
106
|
+
|
|
107
|
+
person: (provider) => {
|
|
108
|
+
const organizations = provider?.('organization');
|
|
109
|
+
return {
|
|
110
|
+
name: faker.person.fullName(),
|
|
111
|
+
email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,
|
|
112
|
+
org:
|
|
113
|
+
organizations?.length && faker.datatype.boolean({ probability: 0.3 })
|
|
114
|
+
? faker.helpers.arrayElement(organizations)
|
|
115
|
+
: undefined,
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
project: () => ({
|
|
120
|
+
title: faker.commerce.productName(),
|
|
121
|
+
repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,
|
|
122
|
+
status: faker.helpers.arrayElement(Status),
|
|
123
|
+
priority: faker.helpers.arrayElement(Priority),
|
|
124
|
+
}),
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);
|
|
128
|
+
|
|
129
|
+
export const createSpaceObjectGenerator = (space: Space) =>
|
|
130
|
+
new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);
|
package/src/generator.test.ts
CHANGED
|
@@ -2,16 +2,43 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { faker } from '@faker-js/faker';
|
|
5
6
|
import { expect } from 'chai';
|
|
6
7
|
|
|
8
|
+
import { Client } from '@dxos/client';
|
|
7
9
|
import { describe, test } from '@dxos/test';
|
|
8
10
|
|
|
9
|
-
import {
|
|
11
|
+
import { createSpaceObjectGenerator, createTestObjectGenerator } from './data';
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
faker.seed(3);
|
|
14
|
+
|
|
15
|
+
describe('TestObjectGenerator', () => {
|
|
12
16
|
test('basic', () => {
|
|
13
|
-
const generator =
|
|
14
|
-
|
|
17
|
+
const generator = createTestObjectGenerator();
|
|
18
|
+
|
|
19
|
+
// Create raw object.
|
|
20
|
+
const object = generator.createObject({ types: ['person'] });
|
|
15
21
|
expect(object).to.exist;
|
|
16
22
|
});
|
|
23
|
+
|
|
24
|
+
test('with space', async () => {
|
|
25
|
+
const client = new Client();
|
|
26
|
+
await client.initialize();
|
|
27
|
+
await client.halo.createIdentity();
|
|
28
|
+
const space = await client.spaces.create();
|
|
29
|
+
const generator = createSpaceObjectGenerator(space);
|
|
30
|
+
|
|
31
|
+
// Add schemas.
|
|
32
|
+
generator.addSchemas();
|
|
33
|
+
|
|
34
|
+
// Create org object.
|
|
35
|
+
const organization = generator.createObject({ types: ['organization'] });
|
|
36
|
+
expect(organization.__schema).to.exist;
|
|
37
|
+
|
|
38
|
+
// Expect at least one person object with a linked org reference.
|
|
39
|
+
const objects = generator.createObjects({ types: ['person'], count: 10 });
|
|
40
|
+
expect(objects.some((object) => object.org === organization)).to.be.true;
|
|
41
|
+
|
|
42
|
+
await client.destroy();
|
|
43
|
+
});
|
|
17
44
|
});
|
package/src/generator.ts
CHANGED
|
@@ -7,114 +7,59 @@
|
|
|
7
7
|
|
|
8
8
|
import { faker } from '@faker-js/faker';
|
|
9
9
|
|
|
10
|
-
import { Expando, type
|
|
10
|
+
import { Expando, type Schema, type Space } from '@dxos/client/echo';
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Array.from({ length })
|
|
15
|
-
.map((_, i) => fn(i))
|
|
16
|
-
.filter(Boolean) as T[];
|
|
17
|
-
|
|
18
|
-
// TODO(burdon): Commit to using ECHO to generate all test data? Or convert from raw data?
|
|
19
|
-
export type TestItem = { id: string; type: string } & Record<string, any>;
|
|
20
|
-
|
|
21
|
-
type ObjectDataGenerator = {
|
|
22
|
-
createSchema?: () => SchemaType;
|
|
23
|
-
createData: () => any;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
type ObjectFactory<T extends TypedObject> = {
|
|
27
|
-
schema?: SchemaType; // TODO(burdon): Support both typed and expando schema.
|
|
28
|
-
createObject: () => T;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
type ObjectFactoryMap = { [type: string]: ObjectFactory<any> };
|
|
32
|
-
|
|
33
|
-
const createFactory = ({ createSchema, createData }: ObjectDataGenerator) => {
|
|
34
|
-
const schema = createSchema?.();
|
|
35
|
-
return {
|
|
36
|
-
schema,
|
|
37
|
-
createObject: () => new Expando(createData(), { schema }),
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// TODO(burdon): Handle restricted values.
|
|
42
|
-
export const Status = ['pending', 'active', 'done'];
|
|
43
|
-
export const Priority = [1, 2, 3, 4, 5];
|
|
44
|
-
|
|
45
|
-
export const defaultGenerators: { [type: string]: ObjectDataGenerator } = {
|
|
46
|
-
document: {
|
|
47
|
-
createData: () => ({
|
|
48
|
-
title: faker.lorem.sentence(3),
|
|
49
|
-
body: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),
|
|
50
|
-
}),
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
// TODO(burdon): Configure images.
|
|
54
|
-
image: {
|
|
55
|
-
createData: () => ({
|
|
56
|
-
title: faker.lorem.sentence(3),
|
|
57
|
-
body: faker.datatype.boolean() ? faker.lorem.sentences() : undefined,
|
|
58
|
-
}),
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
project: {
|
|
62
|
-
createSchema: () =>
|
|
63
|
-
new SchemaType({
|
|
64
|
-
props: [
|
|
65
|
-
{
|
|
66
|
-
id: 'title',
|
|
67
|
-
type: SchemaType.PropType.STRING,
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
id: 'repo',
|
|
71
|
-
type: SchemaType.PropType.STRING,
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
id: 'status',
|
|
75
|
-
type: SchemaType.PropType.STRING,
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
id: 'priority',
|
|
79
|
-
type: SchemaType.PropType.NUMBER,
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
}),
|
|
83
|
-
createData: () => ({
|
|
84
|
-
title: faker.commerce.productName(),
|
|
85
|
-
repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,
|
|
86
|
-
status: faker.helpers.arrayElement(Status),
|
|
87
|
-
priority: faker.helpers.arrayElement(Priority),
|
|
88
|
-
}),
|
|
89
|
-
},
|
|
90
|
-
};
|
|
12
|
+
import { type TestGeneratorMap, type TestObjectProvider, type TestSchemaMap } from './types';
|
|
13
|
+
import { range } from './util';
|
|
91
14
|
|
|
92
15
|
/**
|
|
93
16
|
* Typed object generator.
|
|
94
17
|
*/
|
|
95
|
-
export class TestObjectGenerator {
|
|
96
|
-
|
|
18
|
+
export class TestObjectGenerator<T extends string> {
|
|
19
|
+
// prettier-ignore
|
|
20
|
+
constructor(
|
|
21
|
+
public readonly schema: TestSchemaMap<T>,
|
|
22
|
+
private readonly _generators: TestGeneratorMap<T>,
|
|
23
|
+
private readonly _provider?: TestObjectProvider<T>
|
|
24
|
+
) {}
|
|
25
|
+
|
|
26
|
+
get schemas(): Schema[] {
|
|
27
|
+
return Object.values(this.schema);
|
|
28
|
+
}
|
|
97
29
|
|
|
98
|
-
|
|
99
|
-
this.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return acc;
|
|
104
|
-
}, {});
|
|
30
|
+
createObject({ types }: { types?: T[] } = {}): Expando {
|
|
31
|
+
const type = faker.helpers.arrayElement(types ?? (Object.keys(this.schema) as T[]));
|
|
32
|
+
const factory = this._generators[type];
|
|
33
|
+
const data = factory(this._provider);
|
|
34
|
+
return new Expando(data, { schema: this.schema[type] });
|
|
105
35
|
}
|
|
106
36
|
|
|
107
|
-
|
|
108
|
-
|
|
37
|
+
// TODO(burdon): Create batch.
|
|
38
|
+
createObjects({ types, count }: { types?: T[]; count: number }): Expando[] {
|
|
39
|
+
return range(() => this.createObject({ types }), count);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Typed object generator for a space.
|
|
45
|
+
*/
|
|
46
|
+
export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {
|
|
47
|
+
constructor(private readonly _space: Space, schema: TestSchemaMap<T>, generators: TestGeneratorMap<T>) {
|
|
48
|
+
super(schema, generators, (type: T) => {
|
|
49
|
+
// TODO(burdon): Query by schema.
|
|
50
|
+
const { objects } = this._space.db.query((object) => {
|
|
51
|
+
return object.__schema === schema[type];
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return objects;
|
|
55
|
+
});
|
|
109
56
|
}
|
|
110
57
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const factory = this.factories[type];
|
|
114
|
-
return factory?.createObject();
|
|
58
|
+
addSchemas() {
|
|
59
|
+
this.schemas.forEach((schema) => this._space.db.add(schema));
|
|
115
60
|
}
|
|
116
61
|
|
|
117
|
-
|
|
118
|
-
return
|
|
62
|
+
override createObject({ types }: { types?: T[] } = {}): Expando {
|
|
63
|
+
return this._space.db.add(super.createObject({ types }));
|
|
119
64
|
}
|
|
120
65
|
}
|
package/src/index.ts
CHANGED
package/src/types.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Schema, type Expando } from '@dxos/client/echo';
|
|
6
|
+
|
|
7
|
+
export type TestObject = { id: string } & Record<string, any>;
|
|
8
|
+
|
|
9
|
+
export type TestSchemaMap<T extends string> = Record<T, Schema>;
|
|
10
|
+
|
|
11
|
+
export type TestObjectProvider<T extends string> = (type: T) => Expando[];
|
|
12
|
+
|
|
13
|
+
export type TestGeneratorMap<T extends string> = Record<T, (provider: TestObjectProvider<T> | undefined) => any>;
|