@dxos/echo-generator 0.3.3-main.10234ef → 0.3.3-main.1817c8a
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 +24 -0
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +24 -0
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/generator.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/generator.ts +26 -0
|
@@ -29,6 +29,18 @@ var Priority = [
|
|
|
29
29
|
];
|
|
30
30
|
var defaultGenerators = {
|
|
31
31
|
document: {
|
|
32
|
+
createSchema: () => new SchemaType({
|
|
33
|
+
props: [
|
|
34
|
+
{
|
|
35
|
+
id: "title",
|
|
36
|
+
type: SchemaType.PropType.STRING
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "body",
|
|
40
|
+
type: SchemaType.PropType.STRING
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}),
|
|
32
44
|
createData: () => ({
|
|
33
45
|
title: faker.lorem.sentence(3),
|
|
34
46
|
body: faker.lorem.sentences({
|
|
@@ -42,6 +54,18 @@ var defaultGenerators = {
|
|
|
42
54
|
},
|
|
43
55
|
// TODO(burdon): Configure images.
|
|
44
56
|
image: {
|
|
57
|
+
createSchema: () => new SchemaType({
|
|
58
|
+
props: [
|
|
59
|
+
{
|
|
60
|
+
id: "title",
|
|
61
|
+
type: SchemaType.PropType.STRING
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "body",
|
|
65
|
+
type: SchemaType.PropType.STRING
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}),
|
|
45
69
|
createData: () => ({
|
|
46
70
|
title: faker.lorem.sentence(3),
|
|
47
71
|
body: faker.datatype.boolean() ? faker.lorem.sentences() : void 0
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 { Expando, type TypedObject, Schema as SchemaType } from '@dxos/client/echo';\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\n// TODO(burdon): Commit to using ECHO to generate all test data? Or convert from raw data?\nexport type TestItem = { id: string; type: string } & Record<string, any>;\n\ntype ObjectDataGenerator = {\n createSchema?: () => SchemaType;\n createData: () => any;\n};\n\ntype ObjectFactory<T extends TypedObject> = {\n schema?: SchemaType; // TODO(burdon): Support both typed and expando schema.\n createObject: () => T;\n};\n\ntype ObjectFactoryMap = { [type: string]: ObjectFactory<any> };\n\nconst createFactory = ({ createSchema, createData }: ObjectDataGenerator) => {\n const schema = createSchema?.();\n return {\n schema,\n createObject: () => new Expando(createData(), { schema }),\n };\n};\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport const defaultGenerators: { [type: string]: ObjectDataGenerator } = {\n document: {\n createData: () => ({\n title: faker.lorem.sentence(3),\n body: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n },\n\n // TODO(burdon): Configure images.\n image: {\n createData: () => ({\n title: faker.lorem.sentence(3),\n body: faker.datatype.boolean() ? faker.lorem.sentences() : undefined,\n }),\n },\n\n project: {\n createSchema: () =>\n new SchemaType({\n props: [\n {\n id: 'title',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'repo',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'status',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'priority',\n type: SchemaType.PropType.NUMBER,\n },\n ],\n }),\n createData: () => ({\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};\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator {\n public readonly factories: ObjectFactoryMap;\n\n constructor({ types, factories }: { types?: string[]; factories?: ObjectFactoryMap } = {}) {\n this.factories =\n factories ??\n (types ?? Object.keys(defaultGenerators)).reduce<ObjectFactoryMap>((acc, type) => {\n acc[type] = createFactory(defaultGenerators[type]);\n return acc;\n }, {});\n }\n\n get schema(): SchemaType[] {\n return Object.values(this.factories).map((f) => f.schema!);\n }\n\n createObject({ types }: { types?: string[] } = {}) {\n const type = faker.helpers.arrayElement(types ?? Object.keys(this.factories));\n const factory = this.factories[type];\n return factory?.createObject();\n }\n\n createObjects({ types, length }: { types?: string[]; length: number }) {\n return range(() => this.createObject({ types }), length);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;AAOA,SAASA,aAAa;AAEtB,SAASC,SAA2BC,UAAUC,kBAAkB;AAGzD,IAAMC,QAAQ,CAAIC,IAAkCC,WACzDC,MAAMC,KAAK;EAAEF;AAAO,CAAA,EACjBG,IAAI,CAACC,GAAGC,MAAMN,GAAGM,CAAAA,CAAAA,EACjBC,OAAOC,OAAAA;AAiBZ,IAAMC,gBAAgB,CAAC,EAAEC,cAAcC,WAAU,MAAuB;AACtE,QAAMC,SAASF,eAAAA;AACf,SAAO;IACLE;IACAC,cAAc,MAAM,IAAIC,QAAQH,WAAAA,GAAc;MAAEC;IAAO,CAAA;EACzD;AACF;AAGO,IAAMG,SAAS;EAAC;EAAW;EAAU;;AACrC,IAAMC,WAAW;EAAC;EAAG;EAAG;EAAG;EAAG;;AAE9B,IAAMC,oBAA6D;EACxEC,UAAU;
|
|
6
|
-
"names": ["faker", "Expando", "Schema", "SchemaType", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "createFactory", "createSchema", "createData", "schema", "createObject", "Expando", "Status", "Priority", "defaultGenerators", "document", "
|
|
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 { Expando, type TypedObject, Schema as SchemaType } from '@dxos/client/echo';\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\n// TODO(burdon): Commit to using ECHO to generate all test data? Or convert from raw data?\nexport type TestItem = { id: string; type: string } & Record<string, any>;\n\ntype ObjectDataGenerator = {\n createSchema?: () => SchemaType;\n createData: () => any;\n};\n\ntype ObjectFactory<T extends TypedObject> = {\n schema?: SchemaType; // TODO(burdon): Support both typed and expando schema.\n createObject: () => T;\n};\n\ntype ObjectFactoryMap = { [type: string]: ObjectFactory<any> };\n\nconst createFactory = ({ createSchema, createData }: ObjectDataGenerator) => {\n const schema = createSchema?.();\n return {\n schema,\n createObject: () => new Expando(createData(), { schema }),\n };\n};\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport const defaultGenerators: { [type: string]: ObjectDataGenerator } = {\n document: {\n createSchema: () =>\n new SchemaType({\n props: [\n {\n id: 'title',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'body',\n type: SchemaType.PropType.STRING,\n },\n ],\n }),\n createData: () => ({\n title: faker.lorem.sentence(3),\n body: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n },\n\n // TODO(burdon): Configure images.\n image: {\n createSchema: () =>\n new SchemaType({\n props: [\n {\n id: 'title',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'body',\n type: SchemaType.PropType.STRING,\n },\n ],\n }),\n createData: () => ({\n title: faker.lorem.sentence(3),\n body: faker.datatype.boolean() ? faker.lorem.sentences() : undefined,\n }),\n },\n\n project: {\n createSchema: () =>\n new SchemaType({\n props: [\n {\n id: 'title',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'repo',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'status',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'priority',\n type: SchemaType.PropType.NUMBER,\n },\n ],\n }),\n createData: () => ({\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};\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator {\n public readonly factories: ObjectFactoryMap;\n\n constructor({ types, factories }: { types?: string[]; factories?: ObjectFactoryMap } = {}) {\n this.factories =\n factories ??\n (types ?? Object.keys(defaultGenerators)).reduce<ObjectFactoryMap>((acc, type) => {\n acc[type] = createFactory(defaultGenerators[type]);\n return acc;\n }, {});\n }\n\n get schema(): SchemaType[] {\n return Object.values(this.factories).map((f) => f.schema!);\n }\n\n createObject({ types }: { types?: string[] } = {}) {\n const type = faker.helpers.arrayElement(types ?? Object.keys(this.factories));\n const factory = this.factories[type];\n return factory?.createObject();\n }\n\n createObjects({ types, length }: { types?: string[]; length: number }) {\n return range(() => this.createObject({ types }), length);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;AAOA,SAASA,aAAa;AAEtB,SAASC,SAA2BC,UAAUC,kBAAkB;AAGzD,IAAMC,QAAQ,CAAIC,IAAkCC,WACzDC,MAAMC,KAAK;EAAEF;AAAO,CAAA,EACjBG,IAAI,CAACC,GAAGC,MAAMN,GAAGM,CAAAA,CAAAA,EACjBC,OAAOC,OAAAA;AAiBZ,IAAMC,gBAAgB,CAAC,EAAEC,cAAc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O;MACjBc,OAAOC,MAAMe,SAASC,YAAW;MACjCC,MAAMjB,MAAMU,SAASC,QAAQ;QAAEO,aAAa;MAAI,CAAA,IAAKlB,MAAMmB,SAASC,IAAG,IAAKR;MAC5ES,QAAQrB,MAAMsB,QAAQC,aAAalC,MAAAA;MACnCmC,UAAUxB,MAAMsB,QAAQC,aAAajC,QAAAA;IACvC;EACF;AACF;AAKO,IAAMmC,sBAAN,MAAMA;EAGXC,YAAY,EAAEC,OAAOC,UAAS,IAAyD,CAAC,GAAG;AACzF,SAAKA,YACHA,cACCD,SAASE,OAAOC,KAAKvC,iBAAAA,GAAoBwC,OAAyB,CAACC,KAAKpC,SAAAA;AACvEoC,UAAIpC,IAAAA,IAAQb,cAAcQ,kBAAkBK,IAAAA,CAAK;AACjD,aAAOoC;IACT,GAAG,CAAC,CAAA;EACR;EAEA,IAAI9C,SAAuB;AACzB,WAAO2C,OAAOI,OAAO,KAAKL,SAAS,EAAElD,IAAI,CAACwD,MAAMA,EAAEhD,MAAM;EAC1D;EAEAC,aAAa,EAAEwC,MAAK,IAA2B,CAAC,GAAG;AACjD,UAAM/B,OAAOI,MAAMsB,QAAQC,aAAaI,SAASE,OAAOC,KAAK,KAAKF,SAAS,CAAA;AAC3E,UAAMO,UAAU,KAAKP,UAAUhC,IAAAA;AAC/B,WAAOuC,SAAShD,aAAAA;EAClB;EAEAiD,cAAc,EAAET,OAAOpD,OAAM,GAA0C;AACrE,WAAOF,MAAM,MAAM,KAAKc,aAAa;MAAEwC;IAAM,CAAA,GAAIpD,MAAAA;EACnD;AACF;",
|
|
6
|
+
"names": ["faker", "Expando", "Schema", "SchemaType", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "createFactory", "createSchema", "createData", "schema", "createObject", "Expando", "Status", "Priority", "defaultGenerators", "document", "SchemaType", "props", "id", "type", "PropType", "STRING", "title", "faker", "lorem", "sentence", "body", "sentences", "min", "max", "number", "int", "image", "datatype", "boolean", "undefined", "project", "NUMBER", "commerce", "productName", "repo", "probability", "internet", "url", "status", "helpers", "arrayElement", "priority", "TestObjectGenerator", "constructor", "types", "factories", "Object", "keys", "reduce", "acc", "values", "f", "factory", "createObjects"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":14286,"imports":[{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-generator/src/index.ts":{"bytes":478,"imports":[{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-generator/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7186},"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}],"exports":["Priority","Status","TestObjectGenerator","defaultGenerators","range"],"entryPoint":"packages/core/echo/echo-generator/src/index.ts","inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":2817},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":3026}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -57,6 +57,18 @@ var Priority = [
|
|
|
57
57
|
];
|
|
58
58
|
var defaultGenerators = {
|
|
59
59
|
document: {
|
|
60
|
+
createSchema: () => new import_echo.Schema({
|
|
61
|
+
props: [
|
|
62
|
+
{
|
|
63
|
+
id: "title",
|
|
64
|
+
type: import_echo.Schema.PropType.STRING
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: "body",
|
|
68
|
+
type: import_echo.Schema.PropType.STRING
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}),
|
|
60
72
|
createData: () => ({
|
|
61
73
|
title: import_faker.faker.lorem.sentence(3),
|
|
62
74
|
body: import_faker.faker.lorem.sentences({
|
|
@@ -70,6 +82,18 @@ var defaultGenerators = {
|
|
|
70
82
|
},
|
|
71
83
|
// TODO(burdon): Configure images.
|
|
72
84
|
image: {
|
|
85
|
+
createSchema: () => new import_echo.Schema({
|
|
86
|
+
props: [
|
|
87
|
+
{
|
|
88
|
+
id: "title",
|
|
89
|
+
type: import_echo.Schema.PropType.STRING
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: "body",
|
|
93
|
+
type: import_echo.Schema.PropType.STRING
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}),
|
|
73
97
|
createData: () => ({
|
|
74
98
|
title: import_faker.faker.lorem.sentence(3),
|
|
75
99
|
body: import_faker.faker.datatype.boolean() ? import_faker.faker.lorem.sentences() : void 0
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 { Expando, type TypedObject, Schema as SchemaType } from '@dxos/client/echo';\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\n// TODO(burdon): Commit to using ECHO to generate all test data? Or convert from raw data?\nexport type TestItem = { id: string; type: string } & Record<string, any>;\n\ntype ObjectDataGenerator = {\n createSchema?: () => SchemaType;\n createData: () => any;\n};\n\ntype ObjectFactory<T extends TypedObject> = {\n schema?: SchemaType; // TODO(burdon): Support both typed and expando schema.\n createObject: () => T;\n};\n\ntype ObjectFactoryMap = { [type: string]: ObjectFactory<any> };\n\nconst createFactory = ({ createSchema, createData }: ObjectDataGenerator) => {\n const schema = createSchema?.();\n return {\n schema,\n createObject: () => new Expando(createData(), { schema }),\n };\n};\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport const defaultGenerators: { [type: string]: ObjectDataGenerator } = {\n document: {\n createData: () => ({\n title: faker.lorem.sentence(3),\n body: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n },\n\n // TODO(burdon): Configure images.\n image: {\n createData: () => ({\n title: faker.lorem.sentence(3),\n body: faker.datatype.boolean() ? faker.lorem.sentences() : undefined,\n }),\n },\n\n project: {\n createSchema: () =>\n new SchemaType({\n props: [\n {\n id: 'title',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'repo',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'status',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'priority',\n type: SchemaType.PropType.NUMBER,\n },\n ],\n }),\n createData: () => ({\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};\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator {\n public readonly factories: ObjectFactoryMap;\n\n constructor({ types, factories }: { types?: string[]; factories?: ObjectFactoryMap } = {}) {\n this.factories =\n factories ??\n (types ?? Object.keys(defaultGenerators)).reduce<ObjectFactoryMap>((acc, type) => {\n acc[type] = createFactory(defaultGenerators[type]);\n return acc;\n }, {});\n }\n\n get schema(): SchemaType[] {\n return Object.values(this.factories).map((f) => f.schema!);\n }\n\n createObject({ types }: { types?: string[] } = {}) {\n const type = faker.helpers.arrayElement(types ?? Object.keys(this.factories));\n const factory = this.factories[type];\n return factory?.createObject();\n }\n\n createObjects({ types, length }: { types?: string[]; length: number }) {\n return range(() => this.createObject({ types }), length);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;ACOA,mBAAsB;AAEtB,kBAAgE;AAGzD,IAAMA,QAAQ,CAAIC,IAAkCC,WACzDC,MAAMC,KAAK;EAAEF;AAAO,CAAA,EACjBG,IAAI,CAACC,GAAGC,MAAMN,GAAGM,CAAAA,CAAAA,EACjBC,OAAOC,OAAAA;AAiBZ,IAAMC,gBAAgB,CAAC,EAAEC,cAAcC,WAAU,MAAuB;AACtE,QAAMC,SAASF,eAAAA;AACf,SAAO;IACLE;IACAC,cAAc,MAAM,IAAIC,oBAAQH,WAAAA,GAAc;MAAEC;IAAO,CAAA;EACzD;AACF;AAGO,IAAMG,SAAS;EAAC;EAAW;EAAU;;AACrC,IAAMC,WAAW;EAAC;EAAG;EAAG;EAAG;EAAG;;AAE9B,IAAMC,oBAA6D;EACxEC,UAAU;
|
|
6
|
-
"names": ["range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "createFactory", "createSchema", "createData", "schema", "createObject", "Expando", "Status", "Priority", "defaultGenerators", "document", "
|
|
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 { Expando, type TypedObject, Schema as SchemaType } from '@dxos/client/echo';\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\n// TODO(burdon): Commit to using ECHO to generate all test data? Or convert from raw data?\nexport type TestItem = { id: string; type: string } & Record<string, any>;\n\ntype ObjectDataGenerator = {\n createSchema?: () => SchemaType;\n createData: () => any;\n};\n\ntype ObjectFactory<T extends TypedObject> = {\n schema?: SchemaType; // TODO(burdon): Support both typed and expando schema.\n createObject: () => T;\n};\n\ntype ObjectFactoryMap = { [type: string]: ObjectFactory<any> };\n\nconst createFactory = ({ createSchema, createData }: ObjectDataGenerator) => {\n const schema = createSchema?.();\n return {\n schema,\n createObject: () => new Expando(createData(), { schema }),\n };\n};\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport const defaultGenerators: { [type: string]: ObjectDataGenerator } = {\n document: {\n createSchema: () =>\n new SchemaType({\n props: [\n {\n id: 'title',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'body',\n type: SchemaType.PropType.STRING,\n },\n ],\n }),\n createData: () => ({\n title: faker.lorem.sentence(3),\n body: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n },\n\n // TODO(burdon): Configure images.\n image: {\n createSchema: () =>\n new SchemaType({\n props: [\n {\n id: 'title',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'body',\n type: SchemaType.PropType.STRING,\n },\n ],\n }),\n createData: () => ({\n title: faker.lorem.sentence(3),\n body: faker.datatype.boolean() ? faker.lorem.sentences() : undefined,\n }),\n },\n\n project: {\n createSchema: () =>\n new SchemaType({\n props: [\n {\n id: 'title',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'repo',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'status',\n type: SchemaType.PropType.STRING,\n },\n {\n id: 'priority',\n type: SchemaType.PropType.NUMBER,\n },\n ],\n }),\n createData: () => ({\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};\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator {\n public readonly factories: ObjectFactoryMap;\n\n constructor({ types, factories }: { types?: string[]; factories?: ObjectFactoryMap } = {}) {\n this.factories =\n factories ??\n (types ?? Object.keys(defaultGenerators)).reduce<ObjectFactoryMap>((acc, type) => {\n acc[type] = createFactory(defaultGenerators[type]);\n return acc;\n }, {});\n }\n\n get schema(): SchemaType[] {\n return Object.values(this.factories).map((f) => f.schema!);\n }\n\n createObject({ types }: { types?: string[] } = {}) {\n const type = faker.helpers.arrayElement(types ?? Object.keys(this.factories));\n const factory = this.factories[type];\n return factory?.createObject();\n }\n\n createObjects({ types, length }: { types?: string[]; length: number }) {\n return range(() => this.createObject({ types }), length);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;ACOA,mBAAsB;AAEtB,kBAAgE;AAGzD,IAAMA,QAAQ,CAAIC,IAAkCC,WACzDC,MAAMC,KAAK;EAAEF;AAAO,CAAA,EACjBG,IAAI,CAACC,GAAGC,MAAMN,GAAGM,CAAAA,CAAAA,EACjBC,OAAOC,OAAAA;AAiBZ,IAAMC,gBAAgB,CAAC,EAAEC,cAAcC,WAAU,MAAuB;AACtE,QAAMC,SAASF,eAAAA;AACf,SAAO;IACLE;IACAC,cAAc,MAAM,IAAIC,oBAAQH,WAAAA,GAAc;MAAEC;IAAO,CAAA;EACzD;AACF;AAGO,IAAMG,SAAS;EAAC;EAAW;EAAU;;AACrC,IAAMC,WAAW;EAAC;EAAG;EAAG;EAAG;EAAG;;AAE9B,IAAMC,oBAA6D;EACxEC,UAAU;IACRR,cAAc,MACZ,IAAIS,YAAAA,OAAW;MACbC,OAAO;QACL;UACEC,IAAI;UACJC,MAAMH,YAAAA,OAAWI,SAASC;QAC5B;QACA;UACEH,IAAI;UACJC,MAAMH,YAAAA,OAAWI,SAASC;QAC5B;;IAEJ,CAAA;IACFb,YAAY,OAAO;MACjBc,OAAOC,mBAAMC,MAAMC,SAAS,CAAA;MAC5BC,MAAMH,mBAAMC,MAAMG,UAAU;QAAEC,KAAK;QAAGC,KAAKN,mBAAMO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;AACjD,aAAOoC;IACT,GAAG,CAAC,CAAA;EACR;EAEA,IAAI9C,SAAuB;AACzB,WAAO2C,OAAOI,OAAO,KAAKL,SAAS,EAAElD,IAAI,CAACwD,MAAMA,EAAEhD,MAAM;EAC1D;EAEAC,aAAa,EAAEwC,MAAK,IAA2B,CAAC,GAAG;AACjD,UAAM/B,OAAOI,mBAAMsB,QAAQC,aAAaI,SAASE,OAAOC,KAAK,KAAKF,SAAS,CAAA;AAC3E,UAAMO,UAAU,KAAKP,UAAUhC,IAAAA;AAC/B,WAAOuC,SAAShD,aAAAA;EAClB;EAEAiD,cAAc,EAAET,OAAOpD,OAAM,GAA0C;AACrE,WAAOF,MAAM,MAAM,KAAKc,aAAa;MAAEwC;IAAM,CAAA,GAAIpD,MAAAA;EACnD;AACF;",
|
|
6
|
+
"names": ["range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "createFactory", "createSchema", "createData", "schema", "createObject", "Expando", "Status", "Priority", "defaultGenerators", "document", "SchemaType", "props", "id", "type", "PropType", "STRING", "title", "faker", "lorem", "sentence", "body", "sentences", "min", "max", "number", "int", "image", "datatype", "boolean", "undefined", "project", "NUMBER", "commerce", "productName", "repo", "probability", "internet", "url", "status", "helpers", "arrayElement", "priority", "TestObjectGenerator", "constructor", "types", "factories", "Object", "keys", "reduce", "acc", "values", "f", "factory", "createObjects"]
|
|
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/generator.ts":{"bytes":14286,"imports":[{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-generator/src/index.ts":{"bytes":478,"imports":[{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-generator/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7327},"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}],"exports":[],"entryPoint":"packages/core/echo/echo-generator/src/index.ts","inputs":{"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":263},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":3060}},"bytes":4428}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generator.ts"],"names":[],"mappings":"AASA,OAAO,EAAW,KAAK,WAAW,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpF,eAAO,MAAM,KAAK,cAAe,MAAM,4BAA4B,MAAM,QAG9C,CAAC;AAG5B,MAAM,MAAM,QAAQ,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE1E,KAAK,mBAAmB,GAAG;IACzB,YAAY,CAAC,EAAE,MAAM,UAAU,CAAC;IAChC,UAAU,EAAE,MAAM,GAAG,CAAC;CACvB,CAAC;AAEF,KAAK,aAAa,CAAC,CAAC,SAAS,WAAW,IAAI;IAC1C,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC,CAAC;CACvB,CAAC;AAEF,KAAK,gBAAgB,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;CAAE,CAAC;AAW/D,eAAO,MAAM,MAAM,UAAgC,CAAC;AACpD,eAAO,MAAM,QAAQ,UAAkB,CAAC;AAExC,eAAO,MAAM,iBAAiB,EAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAAA;
|
|
1
|
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D,aAAa,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;CAGtE"}
|
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.1817c8a",
|
|
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.1817c8a",
|
|
21
|
+
"@dxos/node-std": "0.3.3-main.1817c8a"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {},
|
|
24
24
|
"publishConfig": {
|
package/src/generator.ts
CHANGED
|
@@ -44,6 +44,19 @@ export const Priority = [1, 2, 3, 4, 5];
|
|
|
44
44
|
|
|
45
45
|
export const defaultGenerators: { [type: string]: ObjectDataGenerator } = {
|
|
46
46
|
document: {
|
|
47
|
+
createSchema: () =>
|
|
48
|
+
new SchemaType({
|
|
49
|
+
props: [
|
|
50
|
+
{
|
|
51
|
+
id: 'title',
|
|
52
|
+
type: SchemaType.PropType.STRING,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'body',
|
|
56
|
+
type: SchemaType.PropType.STRING,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
}),
|
|
47
60
|
createData: () => ({
|
|
48
61
|
title: faker.lorem.sentence(3),
|
|
49
62
|
body: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),
|
|
@@ -52,6 +65,19 @@ export const defaultGenerators: { [type: string]: ObjectDataGenerator } = {
|
|
|
52
65
|
|
|
53
66
|
// TODO(burdon): Configure images.
|
|
54
67
|
image: {
|
|
68
|
+
createSchema: () =>
|
|
69
|
+
new SchemaType({
|
|
70
|
+
props: [
|
|
71
|
+
{
|
|
72
|
+
id: 'title',
|
|
73
|
+
type: SchemaType.PropType.STRING,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: 'body',
|
|
77
|
+
type: SchemaType.PropType.STRING,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
}),
|
|
55
81
|
createData: () => ({
|
|
56
82
|
title: faker.lorem.sentence(3),
|
|
57
83
|
body: faker.datatype.boolean() ? faker.lorem.sentences() : undefined,
|