orchid-orm-test-factory 0.7.65 → 1.0.1

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/index.d.ts CHANGED
@@ -1,23 +1,29 @@
1
- import { AnyZodObject, ZodTypeAny, ZodObject } from 'zod';
2
- import { CreateData, Query } from 'pqb';
3
- import { MaybePromise, EmptyObject, RecordUnknown, ColumnShapeOutput } from 'orchid-core';
1
+ import { CreateData, CreateSelf } from 'pqb';
2
+ import { PickQueryShape, MaybePromise, EmptyObject, RecordUnknown, ColumnTypeBase, ColumnShapeOutput } from 'orchid-core';
4
3
 
5
- type UniqueField = {
6
- key: string;
7
- type: 'text';
8
- kind?: 'email' | 'url';
9
- max?: number;
10
- length?: number;
11
- } | {
12
- key: string;
13
- type: 'number';
14
- gt?: number;
15
- gte?: number;
16
- };
17
- interface FactoryOptions {
4
+ type FakeDataFn = (sequence: number) => unknown;
5
+ interface FakeDataDefineFns {
6
+ [K: string]: (column: ColumnTypeBase) => FakeDataFn;
7
+ }
8
+ interface FakeDataFns {
9
+ [K: string]: FakeDataFn;
10
+ }
11
+ interface FactoryConfig {
18
12
  sequence?: number;
19
13
  sequenceDistance?: number;
20
14
  maxTextLength?: number;
15
+ fakeDataForTypes?: FakeDataDefineFns;
16
+ }
17
+ type FactoryExtend<T extends PickQueryShape> = {
18
+ [K in keyof T['shape']]?: (sequence: number) => T['shape'][K]['outputType'];
19
+ };
20
+ interface TableFactoryConfig<T extends PickQueryShape> extends FactoryConfig {
21
+ extend?: FactoryExtend<T>;
22
+ }
23
+ interface OrmFactoryConfig<T> extends FactoryConfig {
24
+ extend?: {
25
+ [K in keyof T]?: T[K] extends PickQueryShape ? FactoryExtend<T[K]> : never;
26
+ };
21
27
  }
22
28
  type metaKey = typeof metaKey;
23
29
  declare const metaKey: unique symbol;
@@ -36,20 +42,19 @@ type CreateArg<T extends TestFactory> = CreateData<{
36
42
  } : T['table'][K];
37
43
  }>;
38
44
  type CreateResult<T extends TestFactory> = Result<T, ColumnShapeOutput<T['table']['shape']>>;
39
- declare class TestFactory<Q extends Query = Query, Schema extends AnyZodObject = AnyZodObject, Type extends EmptyObject = EmptyObject> {
45
+ declare class TestFactory<Q extends CreateSelf = CreateSelf, Type extends EmptyObject = EmptyObject> {
40
46
  table: Q;
41
- schema: Schema;
42
- private uniqueFields;
43
- private readonly data;
47
+ fns: FakeDataFns;
44
48
  sequence: number;
45
49
  private readonly omitValues;
46
50
  private readonly pickValues;
51
+ private readonly data;
47
52
  [metaKey]: {
48
53
  type: Type;
49
54
  omit: EmptyObject;
50
55
  pick: EmptyObject;
51
56
  };
52
- constructor(table: Q, schema: Schema, uniqueFields: UniqueField[], data?: RecordUnknown, options?: FactoryOptions);
57
+ constructor(table: Q, fns: FakeDataFns, options?: TableFactoryConfig<PickQueryShape>);
53
58
  set<T extends this, Meta extends {
54
59
  type: EmptyObject;
55
60
  }, Data extends {
@@ -85,19 +90,13 @@ declare class TestFactory<Q extends Query = Query, Schema extends AnyZodObject =
85
90
  createMany<T extends this, Args extends CreateArg<T>[]>(this: T, ...arr: Args): Promise<{
86
91
  [K in keyof Args]: CreateResult<T>;
87
92
  }>;
88
- extend<T extends this>(this: T): new () => TestFactory<Q, Schema, Type>;
93
+ extend<T extends this>(this: T): new () => TestFactory<Q, Type>;
89
94
  }
90
- type TableFactory<T extends Query> = T['shape'] extends Record<string, {
91
- inputSchema: ZodTypeAny;
92
- }> ? TestFactory<T, ZodObject<{
93
- [K in keyof T['shape']]: T['shape'][K]['inputSchema'];
94
- }, 'strip'>, ColumnShapeOutput<T['shape']>> : never;
95
- declare const tableFactory: <T extends Query>(table: T, options?: FactoryOptions) => TableFactory<T>;
95
+ type TableFactory<T extends CreateSelf> = TestFactory<T, ColumnShapeOutput<T['shape']>>;
96
+ declare const tableFactory: <T extends CreateSelf>(table: T, config?: TableFactoryConfig<T>) => TableFactory<T>;
96
97
  type ORMFactory<T> = {
97
- [K in keyof T]: T[K] extends Query & {
98
- definedAs: string;
99
- } ? TableFactory<T[K]> : never;
98
+ [K in keyof T]: T[K] extends CreateSelf ? TableFactory<T[K]> : never;
100
99
  };
101
- declare const ormFactory: <T>(orm: T, options?: FactoryOptions) => ORMFactory<T>;
100
+ declare const ormFactory: <T>(orm: T, options?: OrmFactoryConfig<T>) => ORMFactory<T>;
102
101
 
103
- export { CreateArg, TestFactory, ormFactory, tableFactory };
102
+ export { type CreateArg, type FactoryConfig, type OrmFactoryConfig, type TableFactoryConfig, TestFactory, ormFactory, tableFactory };