@dxos/echo-generator 0.7.1 → 0.7.2-main.f1adc9f
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 +36 -448
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +33 -444
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +36 -448
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/data.d.ts.map +1 -1
- package/dist/types/src/generator.d.ts +4 -4
- package/dist/types/src/generator.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +6 -6
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +0 -1
- package/dist/types/src/util.d.ts.map +1 -1
- package/package.json +11 -9
- package/src/data.ts +55 -155
- package/src/generator.test.ts +18 -18
- package/src/generator.ts +8 -9
- package/src/types.ts +10 -6
- package/src/util.ts +1 -6
package/src/generator.ts
CHANGED
|
@@ -3,18 +3,19 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Space, Filter } from '@dxos/client/echo';
|
|
6
|
-
import { type
|
|
6
|
+
import { type ReactiveEchoObject } from '@dxos/echo-db';
|
|
7
7
|
import {
|
|
8
8
|
create,
|
|
9
|
-
MutableSchema,
|
|
10
|
-
type ReactiveObject,
|
|
11
9
|
getObjectAnnotation,
|
|
12
10
|
getSchema,
|
|
13
11
|
isReactiveObject,
|
|
12
|
+
MutableSchema,
|
|
13
|
+
type ReactiveObject,
|
|
14
14
|
type S,
|
|
15
15
|
} from '@dxos/echo-schema';
|
|
16
16
|
import { invariant } from '@dxos/invariant';
|
|
17
17
|
import { faker } from '@dxos/random';
|
|
18
|
+
import { range } from '@dxos/util';
|
|
18
19
|
|
|
19
20
|
import { type TestSchemaType } from './data';
|
|
20
21
|
import {
|
|
@@ -24,7 +25,6 @@ import {
|
|
|
24
25
|
type TestObjectProvider,
|
|
25
26
|
type TestSchemaMap,
|
|
26
27
|
} from './types';
|
|
27
|
-
import { range } from './util';
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Typed object generator.
|
|
@@ -60,12 +60,11 @@ export class TestObjectGenerator<T extends string = TestSchemaType> {
|
|
|
60
60
|
return schema ? create(schema, data) : create(data);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
// TODO(burdon): Create batch.
|
|
64
63
|
// TODO(burdon): Based on dependencies (e.g., organization before contact).
|
|
65
64
|
async createObjects(map: Partial<Record<T, number>>) {
|
|
66
65
|
const tasks = Object.entries<number>(map as any)
|
|
67
66
|
.map(([type, count]) => {
|
|
68
|
-
return range(() => this.createObject({ types: [type as T] })
|
|
67
|
+
return range(count, () => this.createObject({ types: [type as T] }));
|
|
69
68
|
})
|
|
70
69
|
.flatMap((t) => t);
|
|
71
70
|
|
|
@@ -105,7 +104,7 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
105
104
|
return result;
|
|
106
105
|
}
|
|
107
106
|
|
|
108
|
-
override async createObject({ types }: { types?: T[] } = {}): Promise<
|
|
107
|
+
override async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveEchoObject<any>> {
|
|
109
108
|
return this._space.db.add(await super.createObject({ types }));
|
|
110
109
|
}
|
|
111
110
|
|
|
@@ -127,7 +126,7 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
128
|
|
|
130
|
-
async mutateObject(object:
|
|
129
|
+
async mutateObject(object: ReactiveEchoObject<any>, params: MutationsProviderParams) {
|
|
131
130
|
invariant(this._mutations, 'Mutations not defined.');
|
|
132
131
|
const type = getObjectAnnotation(getSchema(object)!)!.typename as T;
|
|
133
132
|
invariant(type && this._mutations?.[type], 'Invalid object type.');
|
|
@@ -135,7 +134,7 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
135
134
|
await this._mutations;
|
|
136
135
|
}
|
|
137
136
|
|
|
138
|
-
async mutateObjects(objects:
|
|
137
|
+
async mutateObjects(objects: ReactiveEchoObject<any>[], params: MutationsProviderParams) {
|
|
139
138
|
for (const object of objects) {
|
|
140
139
|
await this.mutateObject(object, params);
|
|
141
140
|
}
|
package/src/types.ts
CHANGED
|
@@ -2,18 +2,22 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type ReactiveEchoObject } from '@dxos/echo-db';
|
|
6
6
|
import { type MutableSchema, type ReactiveObject, type S } from '@dxos/echo-schema';
|
|
7
7
|
|
|
8
|
+
// TODO(burdon): Use echo-schema types.
|
|
8
9
|
export type TestObject = { id: string } & Record<string, any>;
|
|
9
10
|
|
|
10
|
-
export type TestSchemaMap<T extends string> = Record<T, MutableSchema | S.Schema<any>>;
|
|
11
|
+
export type TestSchemaMap<T extends string = string> = Record<T, MutableSchema | S.Schema<any>>;
|
|
11
12
|
|
|
12
|
-
export type
|
|
13
|
+
export type TestObjectProvider<T extends string = string> = (type: T) => Promise<ReactiveObject<any>[]>;
|
|
13
14
|
|
|
14
|
-
export type
|
|
15
|
+
export type TestGeneratorMap<T extends string = string> = Record<
|
|
16
|
+
T,
|
|
17
|
+
(provider: TestObjectProvider<T> | undefined) => any
|
|
18
|
+
>;
|
|
15
19
|
|
|
16
|
-
export type TestMutationsMap<T extends string> = Record<T, TestObjectMutators>;
|
|
20
|
+
export type TestMutationsMap<T extends string = string> = Record<T, TestObjectMutators>;
|
|
17
21
|
|
|
18
22
|
export type MutationsProviderParams = {
|
|
19
23
|
count: number;
|
|
@@ -21,4 +25,4 @@ export type MutationsProviderParams = {
|
|
|
21
25
|
maxContentLength: number;
|
|
22
26
|
};
|
|
23
27
|
|
|
24
|
-
export type TestObjectMutators = (object:
|
|
28
|
+
export type TestObjectMutators = (object: ReactiveEchoObject<any>, params: MutationsProviderParams) => Promise<void>;
|
package/src/util.ts
CHANGED
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
// TODO(burdon): Util.
|
|
6
|
-
export const range = <T>(fn: (i: number) => T | undefined, length: number): T[] =>
|
|
7
|
-
Array.from({ length })
|
|
8
|
-
.map((_, i) => fn(i))
|
|
9
|
-
.filter(Boolean) as T[];
|
|
10
|
-
|
|
11
5
|
export const randomText = (length: number) => {
|
|
12
6
|
let result = '';
|
|
13
7
|
const characters = 'abcdefghijklmnopqrstuvwxyz';
|
|
@@ -15,5 +9,6 @@ export const randomText = (length: number) => {
|
|
|
15
9
|
for (let index = 0; index < length; index++) {
|
|
16
10
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
17
11
|
}
|
|
12
|
+
|
|
18
13
|
return result;
|
|
19
14
|
};
|