typion 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +4 -2
- package/bin/typion.js +7 -0
- package/dist/auth/better-auth.d.ts +15 -0
- package/dist/auth/better-auth.js +11 -0
- package/dist/auth/better-auth.js.map +1 -0
- package/dist/cli/index.d.ts +14 -0
- package/dist/cli/index.js +827 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/column-kinds-Bkm4NJI2.js +47 -0
- package/dist/column-kinds-Bkm4NJI2.js.map +1 -0
- package/dist/context-CpLQy7OI.d.ts +2098 -0
- package/dist/contract/index.d.ts +137 -0
- package/dist/contract/index.js +42 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/db/pglite.d.ts +12 -0
- package/dist/db/pglite.js +27 -0
- package/dist/db/pglite.js.map +1 -0
- package/dist/descriptor-Cc3mGp73.js +12 -0
- package/dist/descriptor-Cc3mGp73.js.map +1 -0
- package/dist/errors-ChDBxeS-.js +17 -0
- package/dist/errors-ChDBxeS-.js.map +1 -0
- package/dist/errors-D-CKO-px.js +114 -0
- package/dist/errors-D-CKO-px.js.map +1 -0
- package/dist/handler-D03-rJ-t.d.ts +23 -0
- package/dist/handler-_87bFkbP.js +565 -0
- package/dist/handler-_87bFkbP.js.map +1 -0
- package/dist/hono/index.d.ts +17 -0
- package/dist/hono/index.js +26 -0
- package/dist/hono/index.js.map +1 -0
- package/dist/http/index.d.ts +13 -0
- package/dist/http/index.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1324 -0
- package/dist/index.js.map +1 -0
- package/dist/issues-DLqCBQT1.js +42 -0
- package/dist/issues-DLqCBQT1.js.map +1 -0
- package/dist/next/index.d.ts +8 -0
- package/dist/next/index.js +18 -0
- package/dist/next/index.js.map +1 -0
- package/dist/operations-D3rOacLX.js +1811 -0
- package/dist/operations-D3rOacLX.js.map +1 -0
- package/dist/schema/index.d.ts +18 -0
- package/dist/schema/index.js +3 -0
- package/dist/schema-Rzzq97cK.js +68 -0
- package/dist/schema-Rzzq97cK.js.map +1 -0
- package/dist/seed/index.d.ts +19 -0
- package/dist/seed/index.js +85 -0
- package/dist/seed/index.js.map +1 -0
- package/dist/structural-BZnjFmCs.js +247 -0
- package/dist/structural-BZnjFmCs.js.map +1 -0
- package/dist/testing/index.d.ts +28 -0
- package/dist/testing/index.js +92 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/typion-TJWDkHGh.js +1186 -0
- package/dist/typion-TJWDkHGh.js.map +1 -0
- package/dist/validation/zod.d.ts +21 -0
- package/dist/validation/zod.js +84 -0
- package/dist/validation/zod.js.map +1 -0
- package/docs/README.md +145 -0
- package/docs/access.md +112 -0
- package/docs/auth.md +140 -0
- package/docs/collections.md +168 -0
- package/docs/database.md +74 -0
- package/docs/features/localization.md +112 -0
- package/docs/features/multi-tenant.md +165 -0
- package/docs/features/soft-delete.md +85 -0
- package/docs/features/versions.md +106 -0
- package/docs/hooks.md +106 -0
- package/docs/http.md +184 -0
- package/docs/queries.md +197 -0
- package/docs/testing.md +85 -0
- package/package.json +125 -3
|
@@ -0,0 +1,2098 @@
|
|
|
1
|
+
import { AnyPgColumn, AnyPgColumnBuilder, ExtraConfigColumn, IndexBuilder, PgAsyncDatabase, PgAsyncTransaction, PgBuildColumns, PgColumn, PgEnum, PgIntegerBuilder, PgJsonbBuilder, PgQueryResultHKT, PgSchema, PgTable, PgTableExtraConfigValue, PgTableWithColumns, PgTextBuilder, PgTransactionConfig, PgUUIDBuilder, SetNotNull } from "drizzle-orm/pg-core";
|
|
2
|
+
import { $Type, AnyRelations, AnyRelationsBuilderConfig, Assume, BuildQueryResult, DBQueryConfig, DBQueryConfigOrderByObject, ExtractTablesFromSchema, ExtractTablesWithRelations, GetTableViewFieldSelection, KnownKeysOnly, Many, One, RelationsBuilder, RelationsBuilderConfig, RelationsFilter, RelationsRecord, SQL } from "drizzle-orm";
|
|
3
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
|
+
//#region src/contract/descriptor.d.ts
|
|
5
|
+
declare const RESULT: unique symbol;
|
|
6
|
+
type ReadOp = 'find' | 'findOne' | 'findById' | 'count' | 'page';
|
|
7
|
+
type WriteOp = 'create' | 'update' | 'updateMany' | 'delete' | 'deleteMany';
|
|
8
|
+
type Op = ReadOp | WriteOp | (string & {});
|
|
9
|
+
interface Descriptor<TEntity extends string, TOp extends Op, TInput, TResult> {
|
|
10
|
+
readonly entity: TEntity;
|
|
11
|
+
readonly op: TOp;
|
|
12
|
+
readonly input: TInput;
|
|
13
|
+
readonly [RESULT]?: TResult;
|
|
14
|
+
}
|
|
15
|
+
type AnyDescriptor = Descriptor<string, Op, unknown, unknown>;
|
|
16
|
+
type InferResult<Q> = Q extends {
|
|
17
|
+
readonly [RESULT]?: infer T;
|
|
18
|
+
} ? T : never;
|
|
19
|
+
type InferItem<Q> = InferResult<Q> extends readonly (infer El)[] ? El : InferResult<Q> extends {
|
|
20
|
+
items: readonly (infer El)[];
|
|
21
|
+
} ? El : NonNullable<InferResult<Q>>;
|
|
22
|
+
declare function descriptor<E extends string, O extends Op, I>(entity: E, op: O, input: I): Descriptor<E, O, I, unknown>;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/errors.d.ts
|
|
25
|
+
type TypionErrorCode = 'NOT_FOUND' | 'FORBIDDEN' | 'VALIDATION' | 'CONFLICT' | 'INVALID_STATE' | 'BAD_REQUEST' | 'UNSUPPORTED' | 'PLUGIN' | 'CONFIG' | 'INTERNAL';
|
|
26
|
+
type TypionErrorOptions = {
|
|
27
|
+
entity?: string;
|
|
28
|
+
details?: Record<string, unknown>;
|
|
29
|
+
cause?: unknown;
|
|
30
|
+
};
|
|
31
|
+
declare abstract class TypionError extends Error {
|
|
32
|
+
abstract readonly code: TypionErrorCode;
|
|
33
|
+
abstract readonly status: number;
|
|
34
|
+
readonly entity: string | undefined;
|
|
35
|
+
readonly details: Record<string, unknown> | undefined;
|
|
36
|
+
constructor(message: string, opts?: TypionErrorOptions);
|
|
37
|
+
}
|
|
38
|
+
declare class NotFoundError extends TypionError {
|
|
39
|
+
readonly code: 'NOT_FOUND';
|
|
40
|
+
readonly status: 404;
|
|
41
|
+
}
|
|
42
|
+
type ForbiddenErrorOptions = TypionErrorOptions & {
|
|
43
|
+
operation?: string;
|
|
44
|
+
rule?: string;
|
|
45
|
+
};
|
|
46
|
+
declare class ForbiddenError extends TypionError {
|
|
47
|
+
readonly code: 'FORBIDDEN';
|
|
48
|
+
readonly status: 403;
|
|
49
|
+
readonly operation: string | undefined;
|
|
50
|
+
readonly rule: string | undefined;
|
|
51
|
+
constructor(message: string, opts?: ForbiddenErrorOptions);
|
|
52
|
+
}
|
|
53
|
+
type ValidationIssue = {
|
|
54
|
+
readonly path: readonly PropertyKey[];
|
|
55
|
+
readonly message: string;
|
|
56
|
+
};
|
|
57
|
+
declare class ValidationError extends TypionError {
|
|
58
|
+
readonly code: 'VALIDATION';
|
|
59
|
+
readonly status: 422;
|
|
60
|
+
readonly issues: readonly ValidationIssue[];
|
|
61
|
+
constructor(message: string, issues: readonly ValidationIssue[], opts?: TypionErrorOptions);
|
|
62
|
+
}
|
|
63
|
+
type ConflictKind = 'unique' | 'foreign_key' | 'check' | 'serialization' | 'deadlock';
|
|
64
|
+
type ConflictErrorOptions = TypionErrorOptions & {
|
|
65
|
+
constraint?: string;
|
|
66
|
+
retryable?: boolean;
|
|
67
|
+
issues?: readonly ValidationIssue[];
|
|
68
|
+
};
|
|
69
|
+
declare class ConflictError extends TypionError {
|
|
70
|
+
readonly code: 'CONFLICT';
|
|
71
|
+
readonly status: 409;
|
|
72
|
+
readonly kind: ConflictKind;
|
|
73
|
+
readonly constraint: string | undefined;
|
|
74
|
+
readonly retryable: boolean;
|
|
75
|
+
readonly issues?: readonly ValidationIssue[];
|
|
76
|
+
constructor(message: string, kind: ConflictKind, opts?: ConflictErrorOptions);
|
|
77
|
+
}
|
|
78
|
+
declare class InvalidStateError extends TypionError {
|
|
79
|
+
readonly code: 'INVALID_STATE';
|
|
80
|
+
readonly status: 409;
|
|
81
|
+
}
|
|
82
|
+
declare class BadRequestError extends TypionError {
|
|
83
|
+
readonly code: 'BAD_REQUEST';
|
|
84
|
+
readonly status: 400;
|
|
85
|
+
}
|
|
86
|
+
declare class UnsupportedError extends TypionError {
|
|
87
|
+
readonly code: 'UNSUPPORTED';
|
|
88
|
+
readonly status: 400;
|
|
89
|
+
}
|
|
90
|
+
type PluginErrorOptions = TypionErrorOptions & {
|
|
91
|
+
status?: number;
|
|
92
|
+
};
|
|
93
|
+
declare class PluginError extends TypionError {
|
|
94
|
+
readonly code: 'PLUGIN';
|
|
95
|
+
readonly status: number;
|
|
96
|
+
readonly pluginId: string;
|
|
97
|
+
readonly pluginCode: string;
|
|
98
|
+
constructor(message: string, pluginId: string, pluginCode: string, opts?: PluginErrorOptions);
|
|
99
|
+
}
|
|
100
|
+
type ConfigErrorKind = 'config' | 'schema_drift' | 'relations_mismatch';
|
|
101
|
+
declare class ConfigError extends TypionError {
|
|
102
|
+
readonly code: 'CONFIG';
|
|
103
|
+
readonly status: 500;
|
|
104
|
+
readonly kind: ConfigErrorKind;
|
|
105
|
+
constructor(message: string, kind?: ConfigErrorKind, opts?: TypionErrorOptions);
|
|
106
|
+
}
|
|
107
|
+
declare class InternalError extends TypionError {
|
|
108
|
+
readonly code: 'INTERNAL';
|
|
109
|
+
readonly status: 500;
|
|
110
|
+
}
|
|
111
|
+
declare function isTypionError(e: unknown, code?: TypionErrorCode): e is TypionError;
|
|
112
|
+
type Attempt<T> = {
|
|
113
|
+
ok: true;
|
|
114
|
+
data: T;
|
|
115
|
+
} | {
|
|
116
|
+
ok: false;
|
|
117
|
+
error: TypionError;
|
|
118
|
+
};
|
|
119
|
+
declare function attempt<T>(fn: () => Promise<T>): Promise<Attempt<T>>;
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/types/kinds.d.ts
|
|
122
|
+
declare const COLUMN_KIND: unique symbol;
|
|
123
|
+
type ColumnKindTypes = {
|
|
124
|
+
readonly plugin: string;
|
|
125
|
+
readonly read: object;
|
|
126
|
+
readonly write?: object;
|
|
127
|
+
};
|
|
128
|
+
type Kinded<K extends ColumnKindTypes> = {
|
|
129
|
+
readonly [COLUMN_KIND]?: K;
|
|
130
|
+
};
|
|
131
|
+
type KindOf<D> = D extends {
|
|
132
|
+
readonly [COLUMN_KIND]?: infer K;
|
|
133
|
+
} ? K extends ColumnKindTypes ? K : never : never;
|
|
134
|
+
interface ReadModeFn {
|
|
135
|
+
readonly config: unknown;
|
|
136
|
+
readonly mode: string;
|
|
137
|
+
}
|
|
138
|
+
interface WriteModeFn {
|
|
139
|
+
readonly config: unknown;
|
|
140
|
+
readonly mode: string;
|
|
141
|
+
}
|
|
142
|
+
type KindTypesOf<H> = H extends {
|
|
143
|
+
readonly columnKinds?: infer S;
|
|
144
|
+
} ? NonNullable<S> extends {
|
|
145
|
+
readonly $types?: infer T;
|
|
146
|
+
} ? NonNullable<T> : never : never;
|
|
147
|
+
type IdOf$1<H> = H extends {
|
|
148
|
+
readonly id: infer Id extends string;
|
|
149
|
+
} ? Id : never;
|
|
150
|
+
type ReadModeFnOf<H> = [KindTypesOf<H>] extends [never] ? never : KindTypesOf<H> extends {
|
|
151
|
+
readonly readMode: infer F extends ReadModeFn;
|
|
152
|
+
} ? F : never;
|
|
153
|
+
type WriteModeFnOf<H> = [KindTypesOf<H>] extends [never] ? never : KindTypesOf<H> extends {
|
|
154
|
+
readonly writeMode: infer F extends WriteModeFn;
|
|
155
|
+
} ? F : never;
|
|
156
|
+
type FilterModeOf<H> = [KindTypesOf<H>] extends [never] ? never : KindTypesOf<H> extends {
|
|
157
|
+
readonly filterMode: infer M extends string;
|
|
158
|
+
} ? M : never;
|
|
159
|
+
type ReadModeOf<C, P extends readonly unknown[], Acc extends string = ''> = P extends readonly [infer H, ...infer R] ? [ReadModeFnOf<H>] extends [never] ? ReadModeOf<C, R, Acc> : ReadModeOf<C, R, `${Acc}|${IdOf$1<H>}=${(ReadModeFnOf<H> & {
|
|
160
|
+
readonly config: C;
|
|
161
|
+
})['mode']}|`> : Acc;
|
|
162
|
+
type WriteModeOf<O, P extends readonly unknown[], Acc extends string = ''> = P extends readonly [infer H, ...infer R] ? [WriteModeFnOf<H>] extends [never] ? WriteModeOf<O, R, Acc> : WriteModeOf<O, R, `${Acc}|${IdOf$1<H>}=${(WriteModeFnOf<H> & {
|
|
163
|
+
readonly config: O;
|
|
164
|
+
})['mode']}|`> : Acc;
|
|
165
|
+
type InputModeOf<P extends readonly unknown[], Acc extends string = ''> = P extends readonly [infer H, ...infer R] ? [FilterModeOf<H>] extends [never] ? InputModeOf<R, Acc> : InputModeOf<R, `${Acc}|${IdOf$1<H>}=${FilterModeOf<H>}|`> : Acc;
|
|
166
|
+
type SegmentOf<M extends string, G extends string> = M extends `${string}|${G}=${infer S}|${string}` ? S : never;
|
|
167
|
+
type KindRead<K extends ColumnKindTypes, M extends string, Storage> = [SegmentOf<M, K['plugin']>] extends [never] ? Storage : K['read'][SegmentOf<M, K['plugin']> & keyof K['read']];
|
|
168
|
+
type KindedData<D, M extends string> = [KindOf<D>] extends [never] ? D : KindRead<KindOf<D>, M, D>;
|
|
169
|
+
type PluginsOfColumns<T extends PgTable> = { [K in keyof T['_']['columns']]: KindOf<Assume<T['_']['columns'][K], AnyPgColumn>['_']['data']>['plugin']; }[keyof T['_']['columns']];
|
|
170
|
+
type PickSegments<M extends string, G extends string, Acc extends string = ''> = M extends `|${infer Id}=${infer S}|${infer Rest}` ? PickSegments<Rest, G, Id extends G ? `${Acc}|${Id}=${S}|` : Acc> : Acc;
|
|
171
|
+
type TableMode<T extends PgTable, M extends string> = [PluginsOfColumns<T>] extends [never] ? '' : PickSegments<M, PluginsOfColumns<T>>;
|
|
172
|
+
type KindWrite<D, M extends string> = [KindOf<NonNullable<D>>] extends [never] ? D : KindOf<NonNullable<D>> extends {
|
|
173
|
+
readonly write: infer W;
|
|
174
|
+
readonly plugin: infer G extends string;
|
|
175
|
+
} ? [SegmentOf<M, G>] extends [never] ? D : W[SegmentOf<M, G> & keyof W] | Extract<D, null | undefined> : D;
|
|
176
|
+
type UnionToIntersection$1<U> = (U extends unknown ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
|
|
177
|
+
type Flatten$2<T> = { [K in keyof T]: T[K]; } & {};
|
|
178
|
+
type CarrierOf<H, K extends string> = [KindTypesOf<H>] extends [never] ? {} : KindTypesOf<H> extends { readonly [P in K]: infer O extends object; } ? O : {};
|
|
179
|
+
type PluginReadOptions<P extends readonly unknown[]> = [P[number]] extends [never] ? {} : Flatten$2<UnionToIntersection$1<CarrierOf<P[number], 'readOptions'>>>;
|
|
180
|
+
type KindWriteOptions<P extends readonly unknown[], T extends PgTable> = [PluginsOfColumns<T>] extends [never] ? {} : Flatten$2<UnionToIntersection$1<CarrierOf<Extract<P[number], {
|
|
181
|
+
readonly id: PluginsOfColumns<T>;
|
|
182
|
+
}>, 'writeOptions'>>>;
|
|
183
|
+
type ContextOptionsOf<H> = H extends {
|
|
184
|
+
readonly contextOptions?: infer C;
|
|
185
|
+
} ? NonNullable<C> extends {
|
|
186
|
+
$type: infer T extends object;
|
|
187
|
+
} ? T : {} : {};
|
|
188
|
+
type PluginContextOptions<P extends readonly unknown[]> = [P[number]] extends [never] ? {} : Flatten$2<UnionToIntersection$1<ContextOptionsOf<P[number]>>>;
|
|
189
|
+
type SystemOptionsOf<H> = H extends {
|
|
190
|
+
readonly systemOptions?: infer C;
|
|
191
|
+
} ? NonNullable<C> extends {
|
|
192
|
+
$type: infer T extends object;
|
|
193
|
+
} ? T : {} : {};
|
|
194
|
+
type PluginSystemOptions<P extends readonly unknown[]> = [P[number]] extends [never] ? {} : Flatten$2<UnionToIntersection$1<SystemOptionsOf<P[number]>>>;
|
|
195
|
+
type KeyedShape = {
|
|
196
|
+
readonly type: 'keyed';
|
|
197
|
+
readonly keyName: string;
|
|
198
|
+
readonly keys: readonly string[];
|
|
199
|
+
readonly required: readonly string[];
|
|
200
|
+
readonly nonNull: readonly string[];
|
|
201
|
+
readonly value?: AnyPgColumn;
|
|
202
|
+
};
|
|
203
|
+
type ValidationMode = 'insert' | 'update' | 'select';
|
|
204
|
+
type ColumnKindSpec<TState = any, TWriteState = any> = {
|
|
205
|
+
readonly project?: (values: unknown[], state: TState) => unknown[] | Promise<unknown[]>;
|
|
206
|
+
readonly expression?: (input: {
|
|
207
|
+
readonly column: AnyPgColumn | SQL;
|
|
208
|
+
readonly state: TState;
|
|
209
|
+
readonly sample: unknown;
|
|
210
|
+
readonly dialect: Dialect;
|
|
211
|
+
}) => SQL;
|
|
212
|
+
readonly write?: (input: {
|
|
213
|
+
readonly value: unknown;
|
|
214
|
+
readonly stored: unknown;
|
|
215
|
+
readonly state: TWriteState;
|
|
216
|
+
}) => unknown;
|
|
217
|
+
readonly validation?: (column: ColumnMeta, mode: ValidationMode) => KeyedShape;
|
|
218
|
+
readonly diff?: (before: unknown, after: unknown) => {
|
|
219
|
+
before: unknown;
|
|
220
|
+
after: unknown;
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
type OptionType = 'string' | 'boolean' | 'number';
|
|
224
|
+
type ColumnKindsTypes = {
|
|
225
|
+
readonly readMode?: ReadModeFn;
|
|
226
|
+
readonly filterMode?: string;
|
|
227
|
+
readonly writeMode?: WriteModeFn;
|
|
228
|
+
readonly readOptions?: object;
|
|
229
|
+
readonly writeOptions?: object;
|
|
230
|
+
};
|
|
231
|
+
type ColumnKindsSpec<TTypes extends ColumnKindsTypes = ColumnKindsTypes> = {
|
|
232
|
+
readonly $types?: TTypes;
|
|
233
|
+
readonly readOptions?: Readonly<Record<string, OptionType>>;
|
|
234
|
+
readonly writeOptions?: Readonly<Record<string, OptionType>>;
|
|
235
|
+
readonly read?: (input: {
|
|
236
|
+
readonly options: Readonly<Record<string, unknown>>;
|
|
237
|
+
readonly ctx: BaseContext & Readonly<Record<string, unknown>>;
|
|
238
|
+
}) => unknown;
|
|
239
|
+
readonly write?: (input: {
|
|
240
|
+
readonly options: Readonly<Record<string, unknown>>;
|
|
241
|
+
readonly ctx: BaseContext & Readonly<Record<string, unknown>>;
|
|
242
|
+
}) => unknown;
|
|
243
|
+
readonly kinds: Readonly<Record<string, ColumnKindSpec>>;
|
|
244
|
+
};
|
|
245
|
+
type ColumnKindRuntime = ColumnKindSpec & {
|
|
246
|
+
readonly id: string;
|
|
247
|
+
readonly plugin: string;
|
|
248
|
+
};
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/types/plugin.d.ts
|
|
251
|
+
type TableShape<TColumns extends Record<string, AnyPgColumn>> = PgTableWithColumns<{
|
|
252
|
+
name: string;
|
|
253
|
+
schema: string | undefined;
|
|
254
|
+
dialect: 'pg';
|
|
255
|
+
columns: TColumns;
|
|
256
|
+
}>;
|
|
257
|
+
type PluginErrorDef = {
|
|
258
|
+
status: number;
|
|
259
|
+
message: string;
|
|
260
|
+
};
|
|
261
|
+
type PluginRoute = {
|
|
262
|
+
method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
263
|
+
path: string;
|
|
264
|
+
handler: (c: {
|
|
265
|
+
request: Request;
|
|
266
|
+
params: Record<string, string>;
|
|
267
|
+
engine: AnyTypion;
|
|
268
|
+
app: AnyTypionApp;
|
|
269
|
+
}) => MaybePromise<Response>;
|
|
270
|
+
};
|
|
271
|
+
interface ColumnKind<TId extends string, TMeta> {
|
|
272
|
+
readonly id: TId;
|
|
273
|
+
mark<B extends AnyPgColumnBuilder>(builder: B, meta?: TMeta): B;
|
|
274
|
+
markColumns<T extends PgTable>(table: T, columns: readonly (keyof T['_']['columns'])[]): void;
|
|
275
|
+
is(column: AnyPgColumn): boolean;
|
|
276
|
+
metaOf(column: AnyPgColumn): TMeta | undefined;
|
|
277
|
+
}
|
|
278
|
+
type PluginEntityDefiner<TTables extends Record<string, PgTable>> = <N extends keyof TTables & string, const O>(name: N, options: O) => EntityDef<N, O>;
|
|
279
|
+
interface CollectionKinds {
|
|
280
|
+
readonly options: unknown;
|
|
281
|
+
readonly columns: {};
|
|
282
|
+
readonly entity: {};
|
|
283
|
+
}
|
|
284
|
+
type SeedGenerators = {
|
|
285
|
+
default(params: {
|
|
286
|
+
defaultValue: unknown;
|
|
287
|
+
arraySize?: number;
|
|
288
|
+
}): unknown;
|
|
289
|
+
valuesFromArray(params: {
|
|
290
|
+
values: readonly unknown[];
|
|
291
|
+
isUnique?: boolean;
|
|
292
|
+
}): unknown;
|
|
293
|
+
} & Record<string, (params?: any) => unknown>;
|
|
294
|
+
type SeedColumnsInput = {
|
|
295
|
+
readonly generators: SeedGenerators;
|
|
296
|
+
readonly values: Readonly<Record<string, unknown>>;
|
|
297
|
+
readonly count: number;
|
|
298
|
+
};
|
|
299
|
+
type SeedSpec = {
|
|
300
|
+
columns?: (entity: EntityMeta, input: SeedColumnsInput) => Record<string, unknown>;
|
|
301
|
+
};
|
|
302
|
+
type CollectionSpec<TKinds extends CollectionKinds = CollectionKinds, TOptions extends object = {}> = {
|
|
303
|
+
$options?: TOptions;
|
|
304
|
+
$kinds?: TKinds;
|
|
305
|
+
consumes?: readonly string[];
|
|
306
|
+
columns?: (options: Readonly<Record<string, unknown>>) => Record<string, AnyPgColumnBuilder>;
|
|
307
|
+
entity?: (options: Readonly<Record<string, unknown>>) => Record<string, unknown>;
|
|
308
|
+
};
|
|
309
|
+
interface PluginSpec<TId extends string = string, TTables extends Record<string, PgTable> = {}, TRequires extends Record<string, PgTable> = {}, TCtx extends object = {}, TApi = {}, TEntityOptions extends object = {}, TErrors extends Record<string, PluginErrorDef> = {}, TKinds extends CollectionKinds = CollectionKinds, TCollectionOptions extends object = {}, TSystemOptions extends object = {}, TNeedsCtx extends object = {}, TColumnKinds extends ColumnKindsTypes = ColumnKindsTypes, TContextOptions extends object = {}, TTraits extends EntityTraits = never, TDependsOn extends string = never, TFeatureTables extends AnyFeatureTables = {}> {
|
|
310
|
+
id: TId;
|
|
311
|
+
dependsOn?: readonly TDependsOn[];
|
|
312
|
+
tables?: TTables;
|
|
313
|
+
featureTables?: TFeatureTables;
|
|
314
|
+
requires?: TRequires;
|
|
315
|
+
needsContext?: {
|
|
316
|
+
$type: TNeedsCtx;
|
|
317
|
+
};
|
|
318
|
+
relations?: (r: RelationsBuilder<TTables & TRequires>) => RelationsBuilderConfig<TTables & TRequires>;
|
|
319
|
+
entities?: (define: PluginEntityDefiner<TTables>) => Record<string, EntityDef<string, unknown>>;
|
|
320
|
+
entityOptions?: {
|
|
321
|
+
$type: TEntityOptions;
|
|
322
|
+
schema?: StandardSchemaV1;
|
|
323
|
+
};
|
|
324
|
+
collection?: CollectionSpec<TKinds, TCollectionOptions>;
|
|
325
|
+
seed?: SeedSpec;
|
|
326
|
+
columnKinds?: ColumnKindsSpec<TColumnKinds>;
|
|
327
|
+
contextOptions?: {
|
|
328
|
+
$type: TContextOptions;
|
|
329
|
+
};
|
|
330
|
+
systemOptions?: {
|
|
331
|
+
$type: TSystemOptions;
|
|
332
|
+
};
|
|
333
|
+
requestHeaders?: readonly string[];
|
|
334
|
+
traits?: TraitsSpec<TTraits>;
|
|
335
|
+
init?: (engine: AnyTypion) => MaybePromise<void>;
|
|
336
|
+
context?: (base: BaseContext, input: ContextInput) => MaybePromise<TCtx>;
|
|
337
|
+
hooks?: GlobalHooks;
|
|
338
|
+
api?: (engine: AnyTypion, app?: AnyTypionApp) => TApi;
|
|
339
|
+
routes?: readonly PluginRoute[];
|
|
340
|
+
errors?: TErrors;
|
|
341
|
+
}
|
|
342
|
+
type AnyPluginSpec = {
|
|
343
|
+
readonly id: string;
|
|
344
|
+
readonly dependsOn?: readonly string[] | undefined;
|
|
345
|
+
readonly tables?: Record<string, PgTable> | undefined;
|
|
346
|
+
readonly featureTables?: { readonly [F in FeatureId]?: {
|
|
347
|
+
readonly [key: string]: PgTable | undefined;
|
|
348
|
+
}; } | undefined;
|
|
349
|
+
readonly requires?: Record<string, PgTable> | undefined;
|
|
350
|
+
readonly relations?: ((r: never) => AnyRelationsBuilderConfig) | undefined;
|
|
351
|
+
readonly entities?: ((define: never) => Record<string, EntityDef<string, unknown>>) | undefined;
|
|
352
|
+
readonly entityOptions?: {
|
|
353
|
+
$type: object;
|
|
354
|
+
schema?: StandardSchemaV1;
|
|
355
|
+
} | undefined;
|
|
356
|
+
readonly needsContext?: {
|
|
357
|
+
$type: object;
|
|
358
|
+
} | undefined;
|
|
359
|
+
readonly collection?: CollectionSpec | undefined;
|
|
360
|
+
readonly seed?: SeedSpec | undefined;
|
|
361
|
+
readonly columnKinds?: ColumnKindsSpec | undefined;
|
|
362
|
+
readonly contextOptions?: {
|
|
363
|
+
$type: object;
|
|
364
|
+
} | undefined;
|
|
365
|
+
readonly systemOptions?: {
|
|
366
|
+
$type: object;
|
|
367
|
+
} | undefined;
|
|
368
|
+
readonly requestHeaders?: readonly string[] | undefined;
|
|
369
|
+
readonly traits?: TraitsSpec | undefined;
|
|
370
|
+
readonly init?: ((engine: AnyTypion) => MaybePromise<void>) | undefined;
|
|
371
|
+
readonly context?: ((base: BaseContext, input: ContextInput) => MaybePromise<object>) | undefined;
|
|
372
|
+
readonly hooks?: GlobalHooks | undefined;
|
|
373
|
+
readonly api?: ((engine: AnyTypion, app?: AnyTypionApp) => unknown) | undefined;
|
|
374
|
+
readonly routes?: readonly PluginRoute[] | undefined;
|
|
375
|
+
readonly errors?: Record<string, PluginErrorDef> | undefined;
|
|
376
|
+
};
|
|
377
|
+
type CallbackReturn<P, K extends PropertyKey> = P extends { [Key in K]?: infer F; } ? NonNullable<F> extends ((...a: never[]) => infer R) ? R : {} : {};
|
|
378
|
+
type Plugin<P extends AnyPluginSpec> = P & {
|
|
379
|
+
readonly $api: CallbackReturn<P, 'api'>;
|
|
380
|
+
readonly $context: Awaited<CallbackReturn<P, 'context'>>;
|
|
381
|
+
readonly $entityOptions: P extends {
|
|
382
|
+
entityOptions?: infer EO;
|
|
383
|
+
} ? NonNullable<EO> extends {
|
|
384
|
+
$type: infer T;
|
|
385
|
+
} ? T : {} : {};
|
|
386
|
+
readonly $entities: CallbackReturn<P, 'entities'> extends (infer E) ? E extends AnyEntities ? E : {} : {};
|
|
387
|
+
};
|
|
388
|
+
type AnyPlugin = Plugin<AnyPluginSpec>;
|
|
389
|
+
type UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
|
|
390
|
+
type FeatureId = 'localization' | 'multiTenant';
|
|
391
|
+
type FeatureTables<TTables> = { readonly [F in FeatureId]?: { readonly [K in keyof TTables]?: PgTable; }; };
|
|
392
|
+
type AnyFeatureTables = { readonly [F in FeatureId]?: {
|
|
393
|
+
readonly [key: string]: PgTable | undefined;
|
|
394
|
+
}; };
|
|
395
|
+
type VariantOf<Q, F> = Q extends {
|
|
396
|
+
readonly featureTables?: infer V;
|
|
397
|
+
} ? UnionToIntersection<{ [K in keyof NonNullable<V> & F]: NonNullable<NonNullable<V>[K]>; }[keyof NonNullable<V> & F]> extends (infer T) ? [T] extends [never] ? {} : T : {} : {};
|
|
398
|
+
type TablesOf$1<Q, F> = Q extends {
|
|
399
|
+
readonly tables?: infer T;
|
|
400
|
+
} ? VariantOf<Q, F> extends (infer V) ? Omit<NonNullable<T>, keyof V> & V : never : {};
|
|
401
|
+
type PluginTables<P extends readonly AnyPlugin[]> = [P[number]] extends [never] ? {} : UnionToIntersection<TablesOf$1<P[number], P[number]['id']>>;
|
|
402
|
+
type PluginEntities<P extends readonly AnyPlugin[]> = [P[number]] extends [never] ? {} : UnionToIntersection<P[number]['$entities']>;
|
|
403
|
+
type PluginContext<P extends readonly AnyPlugin[]> = [P[number]] extends [never] ? {} : UnionToIntersection<P[number]['$context']>;
|
|
404
|
+
type PluginEntityOptions<P extends readonly AnyPlugin[]> = [P[number]] extends [never] ? {} : UnionToIntersection<P[number]['$entityOptions']>;
|
|
405
|
+
type NeedsCtxOf<P> = P extends {
|
|
406
|
+
needsContext?: infer NC;
|
|
407
|
+
} ? NonNullable<NC> extends {
|
|
408
|
+
$type: infer T;
|
|
409
|
+
} ? T : {} : {};
|
|
410
|
+
type PluginNeedsContext<P extends readonly AnyPlugin[]> = [P[number]] extends [never] ? {} : UnionToIntersection<NeedsCtxOf<P[number]>>;
|
|
411
|
+
type CollectionOptionsOf<P> = P extends {
|
|
412
|
+
collection?: infer C;
|
|
413
|
+
} ? NonNullable<C> extends {
|
|
414
|
+
$options?: infer O;
|
|
415
|
+
} ? NonNullable<O> : {} : {};
|
|
416
|
+
type PluginCollectionOptions<P extends readonly AnyPlugin[]> = [P[number]] extends [never] ? {} : UnionToIntersection<CollectionOptionsOf<P[number]>>;
|
|
417
|
+
type PluginKinds<P> = P extends {
|
|
418
|
+
collection?: infer C;
|
|
419
|
+
} ? NonNullable<C> extends {
|
|
420
|
+
$kinds?: infer K;
|
|
421
|
+
} ? NonNullable<K> extends CollectionKinds ? NonNullable<K> : CollectionKinds : CollectionKinds : CollectionKinds;
|
|
422
|
+
type PluginErrorInput = {
|
|
423
|
+
message?: string;
|
|
424
|
+
details?: Record<string, unknown>;
|
|
425
|
+
cause?: unknown;
|
|
426
|
+
};
|
|
427
|
+
type PluginErrorFactories<P> = P extends {
|
|
428
|
+
errors?: infer E;
|
|
429
|
+
} ? { [K in keyof NonNullable<E>]: (input?: PluginErrorInput) => PluginError; } : {};
|
|
430
|
+
type PluginApis<P extends readonly AnyPlugin[]> = [P[number]] extends [never] ? {} : { [K in P[number]['id']]: Extract<P[number], {
|
|
431
|
+
id: K;
|
|
432
|
+
}>['$api'] & {
|
|
433
|
+
errors: PluginErrorFactories<Extract<P[number], {
|
|
434
|
+
id: K;
|
|
435
|
+
}>>;
|
|
436
|
+
}; };
|
|
437
|
+
type RelsAt<T, K> = K extends keyof T ? (T[K] extends RelationsRecord ? T[K] : {}) : {};
|
|
438
|
+
type MergeConfigs<A, B> = { [K in keyof A | keyof B]: RelsAt<A, K> & RelsAt<B, K>; };
|
|
439
|
+
type PluginConfig<P> = P extends {
|
|
440
|
+
relations?: (r: never) => infer C;
|
|
441
|
+
} ? C extends AnyRelationsBuilderConfig ? C : {} : {};
|
|
442
|
+
type MergeAll<T extends readonly unknown[], Acc = {}> = T extends readonly [infer H, ...infer R] ? MergeAll<R, MergeConfigs<Acc, PluginConfig<H>>> : Acc;
|
|
443
|
+
type RequirementsError<TUser, TPlugins extends readonly unknown[]> = TUser extends UnionToIntersection<NonNullable<Extract<TPlugins[number], {
|
|
444
|
+
requires?: unknown;
|
|
445
|
+
}>['requires']>> ? unknown : {
|
|
446
|
+
plugins: 'Plugin requirements not met by `tables`';
|
|
447
|
+
};
|
|
448
|
+
type IdOf<H> = H extends {
|
|
449
|
+
readonly id: infer I extends string;
|
|
450
|
+
} ? I : never;
|
|
451
|
+
type DependsOnOf<H> = H extends {
|
|
452
|
+
readonly dependsOn?: readonly (infer D extends string)[] | undefined;
|
|
453
|
+
} ? D : never;
|
|
454
|
+
type DependencyMessage<TId extends string, TMissing extends string, TInstalled> = [TMissing & TInstalled] extends [never] ? `plugin '${TId}' needs plugin '${TMissing}', which is not installed` : `plugin '${TId}' needs plugin '${TMissing & TInstalled & string}' installed before it`;
|
|
455
|
+
type DependenciesError<P extends readonly unknown[], TInstalled = IdOf<P[number]>, TBefore = never> = P extends readonly [infer H, ...infer R] ? [Exclude<DependsOnOf<H>, TBefore>] extends [never] ? DependenciesError<R, TInstalled, TBefore | IdOf<H>> : {
|
|
456
|
+
'~error': DependencyMessage<IdOf<H>, Exclude<DependsOnOf<H>, TBefore>, TInstalled>;
|
|
457
|
+
} : unknown;
|
|
458
|
+
interface PluginRuntime {
|
|
459
|
+
readonly id: string;
|
|
460
|
+
readonly spec: AnyPluginSpec;
|
|
461
|
+
readonly columnKinds: ColumnKindsSpec | null;
|
|
462
|
+
readonly traits: TraitsSpec | null;
|
|
463
|
+
readonly tables: Readonly<Record<string, PgTable>>;
|
|
464
|
+
readonly entities: Readonly<Record<string, EntityDef<string, unknown>>>;
|
|
465
|
+
readonly hooks: GlobalHooks | null;
|
|
466
|
+
readonly routes: readonly PluginRoute[];
|
|
467
|
+
readonly errors: Readonly<Record<string, PluginErrorDef>>;
|
|
468
|
+
}
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/types/schema.d.ts
|
|
471
|
+
type RemapData<C extends AnyPgColumn, D> = PgColumn<C['_']['dataType'], Omit<C['_'], 'data'> & {
|
|
472
|
+
data: D;
|
|
473
|
+
}>;
|
|
474
|
+
type VirtualColumn<C extends AnyPgColumn, M extends string, Dyn extends boolean> = Dyn extends true ? RemapData<C, KindedData<C['_']['data'], M> | null> : [KindOf<C['_']['data']>] extends [never] ? C : RemapData<C, KindedData<C['_']['data'], M>>;
|
|
475
|
+
type VirtualTable<T extends PgTable, M extends string, Hidden extends PropertyKey, Dyn extends PropertyKey> = PgTableWithColumns<{
|
|
476
|
+
name: T['_']['name'];
|
|
477
|
+
schema: T['_']['schema'];
|
|
478
|
+
dialect: 'pg';
|
|
479
|
+
columns: { [K in keyof T['_']['columns'] as K extends Hidden ? never : K]: VirtualColumn<Assume<T['_']['columns'][K], AnyPgColumn>, M, K extends Dyn ? true : false>; };
|
|
480
|
+
}>;
|
|
481
|
+
type ReadRuleOf<O> = O extends {
|
|
482
|
+
access: {
|
|
483
|
+
read: infer Rd;
|
|
484
|
+
};
|
|
485
|
+
} ? Rd : undefined;
|
|
486
|
+
type AclGoverned<O> = ReadRuleOf<O> extends true ? false : ReadRuleOf<O> extends undefined ? false : true;
|
|
487
|
+
type Governed<E extends AnyEntities, P extends readonly unknown[], N, TMode extends TypionMode> = N extends keyof E ? TraitGoverned<P, E[N]['options']> extends true ? true : TMode extends 'system' ? false : AclGoverned<E[N]['options']> : false;
|
|
488
|
+
type HiddenReadKeys<E extends AnyEntities, N> = N extends keyof E ? E[N]['options'] extends {
|
|
489
|
+
fields: infer F;
|
|
490
|
+
} ? { [K in keyof F]: F[K] extends {
|
|
491
|
+
read: false;
|
|
492
|
+
} ? K : never; }[keyof F] : never : never;
|
|
493
|
+
type DynamicReadKeys<E extends AnyEntities, N> = N extends keyof E ? E[N]['options'] extends {
|
|
494
|
+
fields: infer F;
|
|
495
|
+
} ? { [K in keyof F]: F[K] extends {
|
|
496
|
+
read: (...a: never[]) => unknown;
|
|
497
|
+
} ? K : never; }[keyof F] : never : never;
|
|
498
|
+
type VirtualRelation<Rel, E extends AnyEntities, P extends readonly unknown[], TMode extends TypionMode> = Rel extends One<infer T, boolean> ? Governed<E, P, T, TMode> extends true ? One<T, true> : Rel : Rel;
|
|
499
|
+
type VS<TE extends TypionTypes, M extends string, TMode extends TypionMode> = { [K in keyof TE['relations']]: {
|
|
500
|
+
table: VirtualTable<Assume<TE['relations'][K]['table'], PgTable>, TableMode<Assume<TE['relations'][K]['table'], PgTable>, M>, HiddenReadKeys<TE['entities'], K>, DynamicReadKeys<TE['entities'], K>>;
|
|
501
|
+
name: TE['relations'][K]['name'];
|
|
502
|
+
relations: { [F in keyof TE['relations'][K]['relations']]: VirtualRelation<TE['relations'][K]['relations'][F], TE['entities'], TE['plugins'], TMode>; };
|
|
503
|
+
}; };
|
|
504
|
+
//#endregion
|
|
505
|
+
//#region src/types/query.d.ts
|
|
506
|
+
type ReadOptions<TE extends TypionTypes, N extends EntityName<TE>> = PluginReadOptions<TE['plugins']> & TraitOptions<TE['plugins'], TE['entities'][N]['options'], 'read'>;
|
|
507
|
+
type InputSchema<TE extends TypionTypes, TMode extends TypionMode> = VS<TE, InputModeOf<TE['plugins']>, TMode>;
|
|
508
|
+
type FindConfig<TE extends TypionTypes, N extends EntityName<TE>, TMode extends TypionMode> = DBQueryConfig<'many', InputSchema<TE, TMode>, InputSchema<TE, TMode>[N]> & ReadOptions<TE, N>;
|
|
509
|
+
type FirstConfig<TE extends TypionTypes, N extends EntityName<TE>, TMode extends TypionMode> = DBQueryConfig<'one', InputSchema<TE, TMode>, InputSchema<TE, TMode>[N]> & ReadOptions<TE, N>;
|
|
510
|
+
type ByIdConfig<TE extends TypionTypes, N extends EntityName<TE>, TMode extends TypionMode> = Omit<FirstConfig<TE, N, TMode>, 'where' | 'offset'>;
|
|
511
|
+
type Where<TE extends TypionTypes, N extends EntityName<TE>, TMode extends TypionMode = 'user'> = NonNullable<DBQueryConfig<'many', InputSchema<TE, TMode>, InputSchema<TE, TMode>[N]>['where']>;
|
|
512
|
+
type OrderBy<TE extends TypionTypes, N extends EntityName<TE>> = DBQueryConfigOrderByObject<GetTableViewFieldSelection<InputSchema<TE, 'user'>[N]['table']>>;
|
|
513
|
+
type CountConfig<TE extends TypionTypes, N extends EntityName<TE>> = {
|
|
514
|
+
where?: Where<TE, N>;
|
|
515
|
+
} & ReadOptions<TE, N>;
|
|
516
|
+
type Page<T> = {
|
|
517
|
+
items: T[];
|
|
518
|
+
total: number;
|
|
519
|
+
limit: number;
|
|
520
|
+
offset: number;
|
|
521
|
+
hasMore: boolean;
|
|
522
|
+
};
|
|
523
|
+
type Extend<TE extends TypionTypes, N extends EntityName<TE>> = {
|
|
524
|
+
where?: Where<TE, N>;
|
|
525
|
+
orderBy?: OrderBy<TE, N>;
|
|
526
|
+
limit?: number;
|
|
527
|
+
offset?: number;
|
|
528
|
+
};
|
|
529
|
+
type Result<TE extends TypionTypes, N extends EntityName<TE>, C extends Record<string, unknown>, TMode extends TypionMode> = ReadModeOf<C, TE['plugins']> extends (infer M) ? M extends string ? BuildQueryResult<VS<TE, M, TMode>, VS<TE, M, TMode>[N], C> : never : never;
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/types/entity.d.ts
|
|
532
|
+
interface EntityDef<N extends string, O> {
|
|
533
|
+
readonly name: N;
|
|
534
|
+
readonly options: O;
|
|
535
|
+
}
|
|
536
|
+
type AnyEntities = Record<string, EntityDef<string, unknown>>;
|
|
537
|
+
type EntitiesOf$1<R extends AnyRelations> = { [N in keyof R & string]?: EntityDef<N, unknown>; };
|
|
538
|
+
type Select<TE extends TypionTypes, N extends EntityName<TE>> = Assume<TE['relations'][N]['table'], {
|
|
539
|
+
$inferSelect: Record<string, unknown>;
|
|
540
|
+
}>['$inferSelect'];
|
|
541
|
+
type Insert<TE extends TypionTypes, N extends EntityName<TE>> = Assume<TE['relations'][N]['table'], {
|
|
542
|
+
$inferInsert: Record<string, unknown>;
|
|
543
|
+
}>['$inferInsert'];
|
|
544
|
+
type IdKey<TE extends TypionTypes, N extends EntityName<TE>> = TE['entities'][N]['options'] extends {
|
|
545
|
+
idColumn: infer K extends string;
|
|
546
|
+
} ? K : 'id';
|
|
547
|
+
type Id$1<TE extends TypionTypes, N extends EntityName<TE>> = Select<TE, N>[IdKey<TE, N> & keyof Select<TE, N>];
|
|
548
|
+
type FieldsOf<TE extends TypionTypes, N extends keyof TE['entities']> = TE['entities'][N]['options'] extends {
|
|
549
|
+
fields: infer F;
|
|
550
|
+
} ? F : {};
|
|
551
|
+
type HiddenWriteKeys<TE extends TypionTypes, N extends keyof TE['entities'], TMode extends TypionMode = 'user'> = { [K in keyof FieldsOf<TE, N>]: FieldsOf<TE, N>[K] extends {
|
|
552
|
+
write: false;
|
|
553
|
+
} ? K : FieldsOf<TE, N>[K] extends {
|
|
554
|
+
write: 'system';
|
|
555
|
+
} ? TMode extends 'user' ? K : never : never; }[keyof FieldsOf<TE, N>];
|
|
556
|
+
type ManagedKeys<TE extends TypionTypes, N extends keyof TE['entities']> = TraitManaged<TE['plugins'], TE['entities'][N]['options']>;
|
|
557
|
+
type Flatten$1<T> = { [K in keyof T]: T[K]; } & {};
|
|
558
|
+
type TableOfEntity<TE extends TypionTypes, N extends EntityName<TE>> = Assume<TE['relations'][N]['table'], PgTable>;
|
|
559
|
+
type ReadRow<TE extends TypionTypes, N extends EntityName<TE>, C, TMode extends TypionMode = 'user'> = ReadModeOf<C, TE['plugins']> extends (infer M) ? M extends string ? BuildQueryResult<VS<TE, M, TMode>, VS<TE, M, TMode>[N], true> : never : never;
|
|
560
|
+
type Row<TE extends TypionTypes, N extends EntityName<TE>, TMode extends TypionMode = 'user'> = ReadRow<TE, N, {}, TMode>;
|
|
561
|
+
type KindShape<T, M extends string> = M extends '' ? T : { [K in keyof T]: KindWrite<T[K], M>; };
|
|
562
|
+
type WriteModeFor<TE extends TypionTypes, N extends EntityName<TE>, O> = TableMode<TableOfEntity<TE, N>, WriteModeOf<O, TE['plugins']>>;
|
|
563
|
+
type WriteShape<TE extends TypionTypes, N extends EntityName<TE>, TMode extends TypionMode> = TMode extends 'user' ? Omit<Insert<TE, N>, HiddenWriteKeys<TE, N, 'user'> | ManagedKeys<TE, N>> : Omit<Insert<TE, N>, HiddenWriteKeys<TE, N, 'system'> | ManagedKeys<TE, N>> & Partial<Pick<Insert<TE, N>, ManagedKeys<TE, N> & keyof Insert<TE, N>>>;
|
|
564
|
+
type CreateInput<TE extends TypionTypes, N extends EntityName<TE>, O, TMode extends TypionMode = 'user'> = Flatten$1<KindShape<WriteShape<TE, N, TMode>, WriteModeFor<TE, N, O>>>;
|
|
565
|
+
type UpdateInput<TE extends TypionTypes, N extends EntityName<TE>, O, TMode extends TypionMode = 'user'> = Flatten$1<Partial<CreateInput<TE, N, O, TMode>>>;
|
|
566
|
+
type NoExtraKeys<O, TAllowed> = { [K in Exclude<keyof O, keyof TAllowed>]: never; };
|
|
567
|
+
type WriteOptions<TE extends TypionTypes, N extends EntityName<TE>> = KindWriteOptions<TE['plugins'], TableOfEntity<TE, N>>;
|
|
568
|
+
type DeletableTarget<TE extends TypionTypes, N extends EntityName<TE>> = { [K in keyof TE['relations'][N]['relations']]: TE['relations'][N]['relations'][K] extends {
|
|
569
|
+
readonly relationType: 'one';
|
|
570
|
+
readonly targetTableName: infer T extends EntityName<TE>;
|
|
571
|
+
} ? TE['entities'][T]['options'] extends {
|
|
572
|
+
softDelete: true;
|
|
573
|
+
} ? true : never : never; }[keyof TE['relations'][N]['relations']];
|
|
574
|
+
type ReferenceOptions<TE extends TypionTypes, N extends EntityName<TE>> = [DeletableTarget<TE, N>] extends [never] ? {} : {
|
|
575
|
+
withDeleted?: boolean;
|
|
576
|
+
};
|
|
577
|
+
type CreateOptions<TE extends TypionTypes, N extends EntityName<TE>> = TraitOptions<TE['plugins'], TE['entities'][N]['options'], 'create'> & WriteOptions<TE, N> & ReferenceOptions<TE, N>;
|
|
578
|
+
type UpdateOptions<TE extends TypionTypes, N extends EntityName<TE>> = TraitOptions<TE['plugins'], TE['entities'][N]['options'], 'update'> & WriteOptions<TE, N> & ReferenceOptions<TE, N>;
|
|
579
|
+
type UpdateManyOptions<TE extends TypionTypes, N extends EntityName<TE>> = {
|
|
580
|
+
max?: number;
|
|
581
|
+
} & WriteOptions<TE, N> & ReferenceOptions<TE, N>;
|
|
582
|
+
type DeleteOptions<TE extends TypionTypes, N extends EntityName<TE>> = TraitOptions<TE['plugins'], TE['entities'][N]['options'], 'delete'>;
|
|
583
|
+
type NoneIfEmpty<T> = [keyof T] extends [never] ? Record<string, never> : T;
|
|
584
|
+
type EntitySchemas<TE extends TypionTypes, N extends EntityName<TE>> = {
|
|
585
|
+
readonly insert: StandardSchemaV1<unknown, CreateInput<TE, N, {}>>;
|
|
586
|
+
readonly update: StandardSchemaV1<unknown, UpdateInput<TE, N, {}>>;
|
|
587
|
+
readonly select: StandardSchemaV1<unknown, Select<TE, N>>;
|
|
588
|
+
};
|
|
589
|
+
interface EntityApi<TE extends TypionTypes, N extends EntityName<TE>, TMode extends TypionMode> {
|
|
590
|
+
find<const C extends FindConfig<TE, N, TMode>>(config?: KnownKeysOnly<C, FindConfig<TE, N, TMode>>): Promise<Result<TE, N, C, TMode>[]>;
|
|
591
|
+
findOne<const C extends FirstConfig<TE, N, TMode>>(config?: KnownKeysOnly<C, FirstConfig<TE, N, TMode>>): Promise<Result<TE, N, C, TMode> | null>;
|
|
592
|
+
findById<const C extends ByIdConfig<TE, N, TMode>>(id: Id$1<TE, N>, config?: KnownKeysOnly<C, ByIdConfig<TE, N, TMode>>): Promise<Result<TE, N, C, TMode>>;
|
|
593
|
+
count(config?: CountConfig<TE, N>): Promise<number>;
|
|
594
|
+
page<const C extends FindConfig<TE, N, TMode>>(config: KnownKeysOnly<C, FindConfig<TE, N, TMode>>): Promise<Page<Result<TE, N, C, TMode>>>;
|
|
595
|
+
query<const C extends FindConfig<TE, N, 'user'>>(config: KnownKeysOnly<C, FindConfig<TE, N, 'user'>>): Descriptor<N, 'find', C, Result<TE, N, C, 'user'>[]>;
|
|
596
|
+
queryOne<const C extends FirstConfig<TE, N, 'user'>>(config: KnownKeysOnly<C, FirstConfig<TE, N, 'user'>>): Descriptor<N, 'findOne', C, Result<TE, N, C, 'user'> | null>;
|
|
597
|
+
run<D extends Descriptor<N, Op, unknown, unknown>>(descriptor: D, extend?: Extend<TE, N>): Promise<InferResult<D>>;
|
|
598
|
+
create<const O extends CreateOptions<TE, N>>(data: CreateInput<TE, N, O, TMode>, options?: O & NoExtraKeys<O, CreateOptions<TE, N>>): Promise<ReadRow<TE, N, O, TMode>>;
|
|
599
|
+
update<const O extends UpdateOptions<TE, N>>(id: Id$1<TE, N>, data: UpdateInput<TE, N, O, TMode>, options?: O & NoExtraKeys<O, UpdateOptions<TE, N>>): Promise<ReadRow<TE, N, O, TMode>>;
|
|
600
|
+
updateMany<const O extends UpdateManyOptions<TE, N>>(where: Where<TE, N, TMode>, data: UpdateInput<TE, N, O, TMode>, options?: O & NoExtraKeys<O, UpdateManyOptions<TE, N>>): Promise<{
|
|
601
|
+
count: number;
|
|
602
|
+
}>;
|
|
603
|
+
delete(id: Id$1<TE, N>, options?: NoneIfEmpty<DeleteOptions<TE, N>>): Promise<Row<TE, N, TMode>>;
|
|
604
|
+
deleteMany(where: Where<TE, N, TMode>, options?: {
|
|
605
|
+
max?: number;
|
|
606
|
+
} & DeleteOptions<TE, N>): Promise<{
|
|
607
|
+
count: number;
|
|
608
|
+
}>;
|
|
609
|
+
readonly schemas: EntitySchemas<TE, N>;
|
|
610
|
+
}
|
|
611
|
+
type LinkedRelations<TE extends TypionTypes, N extends EntityName<TE>> = TE['entities'][N]['options'] extends {
|
|
612
|
+
links: readonly (infer L extends string)[];
|
|
613
|
+
} ? L : never;
|
|
614
|
+
type LinkTarget<TE extends TypionTypes, N extends EntityName<TE>, R> = TE['relations'][N]['relations'][R & keyof TE['relations'][N]['relations']] extends {
|
|
615
|
+
targetTableName: infer T extends EntityName<TE>;
|
|
616
|
+
} ? T : never;
|
|
617
|
+
type LinkApi<TE extends TypionTypes, N extends EntityName<TE>> = [LinkedRelations<TE, N>] extends [never] ? {} : LinkMethods<TE, N, LinkedRelations<TE, N>>;
|
|
618
|
+
interface LinkMethods<TE extends TypionTypes, N extends EntityName<TE>, L extends string> {
|
|
619
|
+
link<const R extends L>(id: Id$1<TE, N>, relation: R, ids: Id$1<TE, LinkTarget<TE, N, R>> | readonly Id$1<TE, LinkTarget<TE, N, R>>[]): Promise<{
|
|
620
|
+
count: number;
|
|
621
|
+
}>;
|
|
622
|
+
unlink<const R extends L>(id: Id$1<TE, N>, relation: R, ids: Id$1<TE, LinkTarget<TE, N, R>> | readonly Id$1<TE, LinkTarget<TE, N, R>>[]): Promise<{
|
|
623
|
+
count: number;
|
|
624
|
+
}>;
|
|
625
|
+
}
|
|
626
|
+
type LinkInput<TE extends TypionTypes, N extends EntityName<TE>, R> = {
|
|
627
|
+
id: Id$1<TE, N>;
|
|
628
|
+
relation: R;
|
|
629
|
+
ids: readonly Id$1<TE, LinkTarget<TE, N, R>>[];
|
|
630
|
+
};
|
|
631
|
+
type LinkQueries<TE extends TypionTypes, N extends EntityName<TE>> = [LinkedRelations<TE, N>] extends [never] ? {} : LinkQueryMethods<TE, N, LinkedRelations<TE, N>>;
|
|
632
|
+
interface LinkQueryMethods<TE extends TypionTypes, N extends EntityName<TE>, L extends string> {
|
|
633
|
+
link<const R extends L>(input: LinkInput<TE, N, R>): Descriptor<N, 'link', LinkInput<TE, N, R>, {
|
|
634
|
+
count: number;
|
|
635
|
+
}>;
|
|
636
|
+
unlink<const R extends L>(input: LinkInput<TE, N, R>): Descriptor<N, 'unlink', LinkInput<TE, N, R>, {
|
|
637
|
+
count: number;
|
|
638
|
+
}>;
|
|
639
|
+
}
|
|
640
|
+
type FieldRuleArgs<Ctx> = {
|
|
641
|
+
ctx: Ctx;
|
|
642
|
+
meta: OperationMeta;
|
|
643
|
+
};
|
|
644
|
+
type TableOf$1<R extends AnyRelations, N extends keyof R> = Assume<R[N]['table'], PgTable>;
|
|
645
|
+
type ColumnKeys<R extends AnyRelations, N extends keyof R> = keyof TableOf$1<R, N>['_']['columns'] & string;
|
|
646
|
+
type NullableTimestampKeys<T extends PgTable> = { [K in keyof T['_']['columns']]: Assume<T['_']['columns'][K], AnyPgColumn>['_'] extends {
|
|
647
|
+
dataType: 'object date';
|
|
648
|
+
notNull: false;
|
|
649
|
+
} ? K : never; }[keyof T['_']['columns']];
|
|
650
|
+
type FieldOptions<Ctx> = {
|
|
651
|
+
read?: false | ((a: FieldRuleArgs<Ctx>) => boolean);
|
|
652
|
+
write?: false | 'system' | ((a: FieldRuleArgs<Ctx>) => boolean);
|
|
653
|
+
kind?: string;
|
|
654
|
+
};
|
|
655
|
+
type FieldRefinements<R extends AnyRelations, N extends keyof R> = { [K in ColumnKeys<R, N>]?: unknown; };
|
|
656
|
+
type EntityValidation<R extends AnyRelations, N extends keyof R> = {
|
|
657
|
+
insert?: StandardSchemaV1;
|
|
658
|
+
update?: StandardSchemaV1;
|
|
659
|
+
fields?: FieldRefinements<R, N>;
|
|
660
|
+
};
|
|
661
|
+
type EntityOptions<R extends AnyRelations, N extends keyof R & string, Ctx, P extends readonly AnyPlugin[]> = {
|
|
662
|
+
idColumn?: ColumnKeys<R, N>;
|
|
663
|
+
fields?: { [K in ColumnKeys<R, N>]?: FieldOptions<Ctx>; };
|
|
664
|
+
access?: AccessRules<R, N, Ctx, P>;
|
|
665
|
+
hooks?: EntityHooks<R, N, Ctx, P>;
|
|
666
|
+
validate?: EntityValidation<R, N>;
|
|
667
|
+
defaultOrder?: DBQueryConfigOrderByObject<GetTableViewFieldSelection<TableOf$1<R, N>>>;
|
|
668
|
+
maxLimit?: number;
|
|
669
|
+
links?: readonly (keyof R[N]['relations'] & string)[];
|
|
670
|
+
} & PluginEntityOptions<P> & TraitEntityOptions<P, TableOf$1<R, N>>;
|
|
671
|
+
//#endregion
|
|
672
|
+
//#region src/types/traits.d.ts
|
|
673
|
+
type OptionGroup = 'read' | 'create' | 'update' | 'delete';
|
|
674
|
+
type RuleKind = 'filter' | 'boolean';
|
|
675
|
+
type HookArgGroup = 'change' | 'afterChange' | 'afterDelete';
|
|
676
|
+
interface EntityTraits {
|
|
677
|
+
readonly table: unknown;
|
|
678
|
+
readonly given: unknown;
|
|
679
|
+
readonly te: unknown;
|
|
680
|
+
readonly name: unknown;
|
|
681
|
+
readonly mode: unknown;
|
|
682
|
+
readonly row: unknown;
|
|
683
|
+
readonly entityOptions: object;
|
|
684
|
+
readonly governs: unknown;
|
|
685
|
+
readonly managed: string;
|
|
686
|
+
readonly optionsOn: OptionGroup;
|
|
687
|
+
readonly optionTypes: object;
|
|
688
|
+
readonly operations: string;
|
|
689
|
+
readonly rules: {
|
|
690
|
+
readonly [name: string]: RuleKind;
|
|
691
|
+
};
|
|
692
|
+
readonly rulesOn: string;
|
|
693
|
+
readonly hookArgs: { readonly [G in HookArgGroup]?: object; };
|
|
694
|
+
readonly api: object;
|
|
695
|
+
readonly queries: object;
|
|
696
|
+
}
|
|
697
|
+
type EntityTableOf<T extends EntityTraits> = T['table'] extends (infer X extends PgTable) ? X : never;
|
|
698
|
+
type EntityIdOf<T extends EntityTraits> = T['te'] extends (infer TE extends TypionTypes) ? Id$1<TE, T['name'] & EntityName<TE>> : never;
|
|
699
|
+
type EntitySelectOf<T extends EntityTraits> = T['te'] extends (infer TE extends TypionTypes) ? Select<TE, T['name'] & EntityName<TE>> : never;
|
|
700
|
+
type EntityRowOf<T extends EntityTraits> = T['te'] extends (infer TE extends TypionTypes) ? Row<TE, T['name'] & EntityName<TE>, T['mode'] & TypionMode> : never;
|
|
701
|
+
type Declared<T, Base> = Base extends T ? never : T;
|
|
702
|
+
type TraitsOf<H> = H extends {
|
|
703
|
+
readonly traits?: infer S;
|
|
704
|
+
} ? NonNullable<S> extends {
|
|
705
|
+
readonly $types?: infer T;
|
|
706
|
+
} ? NonNullable<T> extends EntityTraits ? NonNullable<T> : never : never : never;
|
|
707
|
+
type PatternOf<P extends readonly unknown[], Acc = never> = P extends readonly [infer H, ...infer R] ? PatternOf<R, Acc | Declared<TraitsOf<H>['governs'], unknown>> : Acc;
|
|
708
|
+
type TraitGoverned<P extends readonly unknown[], O> = [PatternOf<P>] extends [never] ? false : O extends PatternOf<P> ? true : false;
|
|
709
|
+
type TraitManaged<P extends readonly unknown[], O, Acc = never> = P extends readonly [infer H, ...infer R] ? [TraitsOf<H>] extends [never] ? TraitManaged<R, O, Acc> : TraitManaged<R, O, Acc | Declared<(TraitsOf<H> & {
|
|
710
|
+
readonly given: O;
|
|
711
|
+
})['managed'], string>> : Acc;
|
|
712
|
+
type TraitOperationNames<P extends readonly unknown[], Acc = never> = P extends readonly [infer H, ...infer R] ? TraitOperationNames<R, Acc | Declared<TraitsOf<H>['operations'], string>> : Acc;
|
|
713
|
+
type RulesOf<H> = [TraitsOf<H>] extends [never] ? {} : TraitsOf<H>['rules'] extends (infer T) ? string extends keyof T ? {} : T : {};
|
|
714
|
+
type AllTraitRules<P extends readonly unknown[], Acc = {}> = P extends readonly [infer H, ...infer R] ? AllTraitRules<R, Acc & RulesOf<H>> : Acc;
|
|
715
|
+
type RulesOnOf<H, O> = (TraitsOf<H> & {
|
|
716
|
+
readonly given: O;
|
|
717
|
+
})['rulesOn'];
|
|
718
|
+
type TraitRules<P extends readonly unknown[], O, Acc = {}> = P extends readonly [infer H, ...infer R] ? TraitRules<R, O, Acc & Pick<RulesOf<H>, RulesOnOf<H, O> & keyof RulesOf<H>>> : Acc;
|
|
719
|
+
type HookArgsOf<H, S, G extends HookArgGroup> = [TraitsOf<H>] extends [never] ? {} : (TraitsOf<H> & {
|
|
720
|
+
readonly row: S;
|
|
721
|
+
})['hookArgs'] extends { readonly [K in G]?: infer A; } ? object extends NonNullable<A> ? {} : NonNullable<A> : {};
|
|
722
|
+
type TraitHookArgs<P extends readonly unknown[], S, G extends HookArgGroup, Acc = {}> = P extends readonly [infer H, ...infer R] ? TraitHookArgs<R, S, G, Acc & HookArgsOf<H, S, G>> : Acc;
|
|
723
|
+
type GroupOf<H, G extends OptionGroup> = [TraitsOf<H>] extends [never] ? {} : TraitsOf<H>['optionTypes'] extends { readonly [K in G]: infer T; } ? T : {};
|
|
724
|
+
type AppliesOn<H, O> = (TraitsOf<H> & {
|
|
725
|
+
readonly given: O;
|
|
726
|
+
})['optionsOn'];
|
|
727
|
+
type TraitOptions<P extends readonly unknown[], O, G extends OptionGroup, Acc = {}> = P extends readonly [infer H, ...infer R] ? [TraitsOf<H>] extends [never] ? TraitOptions<R, O, G, Acc> : TraitOptions<R, O, G, G extends AppliesOn<H, O> ? Acc & GroupOf<H, G> : Acc> : Acc;
|
|
728
|
+
type AllTraitOptions<P extends readonly unknown[], G extends OptionGroup, Acc = {}> = P extends readonly [infer H, ...infer R] ? AllTraitOptions<R, G, Acc & GroupOf<H, G>> : Acc;
|
|
729
|
+
type TraitEntityOptions<P extends readonly unknown[], T, Acc = {}> = P extends readonly [infer H, ...infer R] ? [TraitsOf<H>] extends [never] ? TraitEntityOptions<R, T, Acc> : TraitEntityOptions<R, T, Acc & (TraitsOf<H> & {
|
|
730
|
+
readonly table: T;
|
|
731
|
+
})['entityOptions']> : Acc;
|
|
732
|
+
type MethodsFold<P extends readonly unknown[], In, K extends 'api' | 'queries', Acc = {}> = P extends readonly [infer H, ...infer R] ? [TraitsOf<H>] extends [never] ? MethodsFold<R, In, K, Acc> : MethodsFold<R, In, K, Acc & (TraitsOf<H> & In)[K]> : Acc;
|
|
733
|
+
type TraitApi<TE extends TypionTypes, N extends EntityName<TE>, TMode extends TypionMode> = MethodsFold<TE['plugins'], {
|
|
734
|
+
readonly given: TE['entities'][N]['options'];
|
|
735
|
+
readonly te: TE;
|
|
736
|
+
readonly name: N;
|
|
737
|
+
readonly mode: TMode;
|
|
738
|
+
}, 'api'>;
|
|
739
|
+
type TraitQueries<TE extends TypionTypes, N extends EntityName<TE>> = MethodsFold<TE['plugins'], {
|
|
740
|
+
readonly given: TE['entities'][N]['options'];
|
|
741
|
+
readonly te: TE;
|
|
742
|
+
readonly name: N;
|
|
743
|
+
readonly mode: 'user';
|
|
744
|
+
}, 'queries'>;
|
|
745
|
+
type Values = Readonly<Record<string, unknown>>;
|
|
746
|
+
type TraitContext = BaseContext & Values;
|
|
747
|
+
type TraitFilter = Values;
|
|
748
|
+
type HookArgValues = { readonly [G in HookArgGroup]?: Values; };
|
|
749
|
+
type DerivedTable = {
|
|
750
|
+
readonly table: PgTable;
|
|
751
|
+
readonly mirror?: boolean;
|
|
752
|
+
};
|
|
753
|
+
type TraitDeriveInput = {
|
|
754
|
+
readonly entity: string;
|
|
755
|
+
readonly table: PgTable;
|
|
756
|
+
readonly options: Values;
|
|
757
|
+
readonly schema: PgSchema<string>;
|
|
758
|
+
};
|
|
759
|
+
type TraitResolveInput = {
|
|
760
|
+
readonly entity: string;
|
|
761
|
+
readonly table: PgTable;
|
|
762
|
+
readonly columns: Readonly<Record<string, AnyPgColumn>>;
|
|
763
|
+
readonly options: Values;
|
|
764
|
+
readonly derived: Readonly<Record<string, PgTable>>;
|
|
765
|
+
};
|
|
766
|
+
type TraitResolved = {
|
|
767
|
+
readonly state?: unknown;
|
|
768
|
+
readonly managed?: readonly string[];
|
|
769
|
+
readonly options?: readonly OptionGroup[];
|
|
770
|
+
readonly rules?: readonly string[];
|
|
771
|
+
};
|
|
772
|
+
type TraitFilterInput = {
|
|
773
|
+
readonly entity: EntityMeta;
|
|
774
|
+
readonly state: unknown;
|
|
775
|
+
readonly operation: Operation;
|
|
776
|
+
readonly writing: boolean;
|
|
777
|
+
readonly options: Values;
|
|
778
|
+
readonly ctx: TraitContext;
|
|
779
|
+
};
|
|
780
|
+
type TraitPartitionInput = {
|
|
781
|
+
readonly entity: EntityMeta;
|
|
782
|
+
readonly state: unknown;
|
|
783
|
+
readonly operation: Operation;
|
|
784
|
+
readonly ctx: TraitContext;
|
|
785
|
+
};
|
|
786
|
+
type TraitSourceInput = {
|
|
787
|
+
readonly entity: EntityMeta;
|
|
788
|
+
readonly state: unknown;
|
|
789
|
+
readonly operation: Operation;
|
|
790
|
+
readonly options: Values;
|
|
791
|
+
readonly ctx: TraitContext;
|
|
792
|
+
};
|
|
793
|
+
type TraitSource = {
|
|
794
|
+
readonly table: string;
|
|
795
|
+
readonly filter?: TraitFilter;
|
|
796
|
+
readonly rule?: string;
|
|
797
|
+
};
|
|
798
|
+
type TraitCreateInput = {
|
|
799
|
+
readonly entity: EntityMeta;
|
|
800
|
+
readonly state: unknown;
|
|
801
|
+
readonly options: Values;
|
|
802
|
+
readonly row: Values;
|
|
803
|
+
readonly now: Date;
|
|
804
|
+
readonly ctx: TraitContext;
|
|
805
|
+
};
|
|
806
|
+
type TraitCreatePlan = {
|
|
807
|
+
readonly set?: Values;
|
|
808
|
+
readonly rules?: readonly string[];
|
|
809
|
+
readonly args?: HookArgValues;
|
|
810
|
+
};
|
|
811
|
+
type TraitUpdateInput = {
|
|
812
|
+
readonly entity: EntityMeta;
|
|
813
|
+
readonly state: unknown;
|
|
814
|
+
readonly operation: Operation;
|
|
815
|
+
readonly options: Values;
|
|
816
|
+
readonly row: AnyRow;
|
|
817
|
+
readonly tx: AnyTx;
|
|
818
|
+
readonly ctx: TraitContext;
|
|
819
|
+
};
|
|
820
|
+
type TraitUpdatePlan = {
|
|
821
|
+
readonly base?: AnyRow;
|
|
822
|
+
readonly keep?: boolean;
|
|
823
|
+
readonly args?: HookArgValues;
|
|
824
|
+
};
|
|
825
|
+
type TraitRecordInput = {
|
|
826
|
+
readonly entity: EntityMeta;
|
|
827
|
+
readonly state: unknown;
|
|
828
|
+
readonly operation: Operation;
|
|
829
|
+
readonly step: 'create' | 'update' | 'delete';
|
|
830
|
+
readonly row: AnyRow;
|
|
831
|
+
readonly previous: AnyRow | null;
|
|
832
|
+
readonly written: boolean;
|
|
833
|
+
readonly options: Values;
|
|
834
|
+
readonly now: Date;
|
|
835
|
+
readonly tx: AnyTx;
|
|
836
|
+
readonly ctx: TraitContext;
|
|
837
|
+
};
|
|
838
|
+
type TraitRemoveInput = {
|
|
839
|
+
readonly entity: EntityMeta;
|
|
840
|
+
readonly state: unknown;
|
|
841
|
+
readonly options: Values;
|
|
842
|
+
readonly row: AnyRow;
|
|
843
|
+
readonly now: Date;
|
|
844
|
+
readonly update: (patch: Values) => Promise<AnyRow>;
|
|
845
|
+
};
|
|
846
|
+
type KitPatchInput = {
|
|
847
|
+
readonly row: AnyRow;
|
|
848
|
+
readonly tx: AnyTx;
|
|
849
|
+
readonly now: Date;
|
|
850
|
+
readonly ctx: TraitContext;
|
|
851
|
+
};
|
|
852
|
+
type KitReadInput = {
|
|
853
|
+
readonly executor: AnyDb | AnyTx;
|
|
854
|
+
readonly partition: Values;
|
|
855
|
+
readonly now: Date;
|
|
856
|
+
readonly ctx: TraitContext;
|
|
857
|
+
};
|
|
858
|
+
type OperationKit = {
|
|
859
|
+
update(id: unknown, patch: Values | ((input: KitPatchInput) => Values | undefined | Promise<Values | undefined>), options?: {
|
|
860
|
+
readonly rule?: string;
|
|
861
|
+
readonly options?: Values;
|
|
862
|
+
}): Promise<AnyRow>;
|
|
863
|
+
read<T>(fn: (input: KitReadInput) => Promise<T>, options?: {
|
|
864
|
+
readonly rule?: string;
|
|
865
|
+
}): Promise<T>;
|
|
866
|
+
};
|
|
867
|
+
type TraitOperationInput = {
|
|
868
|
+
readonly entity: EntityMeta;
|
|
869
|
+
readonly state: unknown;
|
|
870
|
+
readonly input: Values;
|
|
871
|
+
readonly kit: OperationKit;
|
|
872
|
+
};
|
|
873
|
+
type TraitOperation = {
|
|
874
|
+
readonly args: readonly string[];
|
|
875
|
+
readonly options?: Readonly<Record<string, OptionType>>;
|
|
876
|
+
readonly route?: {
|
|
877
|
+
readonly method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
878
|
+
readonly path: string;
|
|
879
|
+
};
|
|
880
|
+
readonly run: (input: TraitOperationInput) => Promise<unknown>;
|
|
881
|
+
};
|
|
882
|
+
type TraitsSpec<TTraits extends EntityTraits = EntityTraits> = {
|
|
883
|
+
readonly $types?: TTraits;
|
|
884
|
+
readonly options?: { readonly [G in OptionGroup]?: Readonly<Record<string, OptionType>>; };
|
|
885
|
+
readonly rules?: Readonly<Record<string, RuleKind>>;
|
|
886
|
+
readonly hookArgs?: HookArgValues;
|
|
887
|
+
readonly derive?: (input: TraitDeriveInput) => Readonly<Record<string, DerivedTable>> | null;
|
|
888
|
+
readonly resolve?: (input: TraitResolveInput) => TraitResolved | null;
|
|
889
|
+
readonly filter?: (input: TraitFilterInput) => TraitFilter | undefined;
|
|
890
|
+
readonly partition?: (input: TraitPartitionInput) => Values | undefined;
|
|
891
|
+
readonly source?: (input: TraitSourceInput) => TraitSource | undefined;
|
|
892
|
+
readonly create?: (input: TraitCreateInput) => TraitCreatePlan | undefined;
|
|
893
|
+
readonly update?: (input: TraitUpdateInput) => TraitUpdatePlan | undefined | Promise<TraitUpdatePlan | undefined>;
|
|
894
|
+
readonly remove?: (input: TraitRemoveInput) => Promise<AnyRow> | undefined;
|
|
895
|
+
readonly record?: (input: TraitRecordInput) => Promise<Values | undefined | void>;
|
|
896
|
+
readonly operations?: Readonly<Record<string, TraitOperation>>;
|
|
897
|
+
};
|
|
898
|
+
type EntityTrait = {
|
|
899
|
+
readonly plugin: string;
|
|
900
|
+
readonly state: unknown;
|
|
901
|
+
readonly options: readonly OptionGroup[];
|
|
902
|
+
readonly rules: readonly string[];
|
|
903
|
+
};
|
|
904
|
+
//#endregion
|
|
905
|
+
//#region src/schema/columns.d.ts
|
|
906
|
+
declare function defaultIdColumn(): import("drizzle-orm/pg-core").SetHasDefault<import("drizzle-orm/pg-core").SetIsPrimaryKey<import("drizzle-orm/pg-core").PgUUIDBuilder>>;
|
|
907
|
+
declare function timestamps(): {
|
|
908
|
+
createdAt: import("drizzle-orm/pg-core").SetHasDefault<import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTimestampBuilder>>;
|
|
909
|
+
updatedAt: import("drizzle-orm/pg-core").SetHasDefault<import("drizzle-orm/pg-core").SetHasDefault<import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTimestampBuilder>>>;
|
|
910
|
+
};
|
|
911
|
+
//#endregion
|
|
912
|
+
//#region src/define/engine.d.ts
|
|
913
|
+
type UserTables = Record<string, PgTable | PgEnum<any>>;
|
|
914
|
+
type AllTables<T extends UserTables, P extends readonly AnyPlugin[]> = ExtractTablesFromSchema<T & PluginTables<P>>;
|
|
915
|
+
type MergedRelations<C, P extends readonly AnyPlugin[], T extends UserTables> = ExtractTablesWithRelations<[P[number]] extends [never] ? C & {} : MergeConfigs<MergeAll<P>, C>, AllTables<T, P>>;
|
|
916
|
+
//#endregion
|
|
917
|
+
//#region src/contract/jsonified.d.ts
|
|
918
|
+
type Jsonified<T> = T extends Date | bigint ? string : T extends ((...args: never[]) => unknown) ? never : T extends readonly (infer E)[] ? Jsonified<E>[] : T extends object ? { [K in keyof T]: Jsonified<T[K]>; } : T;
|
|
919
|
+
//#endregion
|
|
920
|
+
//#region src/define/collection.d.ts
|
|
921
|
+
declare function collection<const N extends string, const C extends Record<string, AnyPgColumnBuilder>, const S extends StructureInput<RegisteredPlugins, C, S>>(name: N, structure: S & {
|
|
922
|
+
columns: C;
|
|
923
|
+
} & NoUnknownKeys<S, StructureInput<RegisteredPlugins, C, S>>): CollectionDraft<N, TableOf<N, S, FoldKinds<RegisteredPlugins, S, 'columns'>>, S>;
|
|
924
|
+
//#endregion
|
|
925
|
+
//#region src/define/plugin.d.ts
|
|
926
|
+
type PluginSpecInput<TId extends string, TTables extends Record<string, PgTable>, TRequires extends Record<string, PgTable>, TCtx extends object, TApi, TEntityOptions extends object, TErrors extends Record<string, PluginErrorDef>, TEntities extends Record<string, EntityDef<string, unknown>>, TRelations extends RelationsBuilderConfig<TTables & TRequires>, TKinds extends CollectionKinds = CollectionKinds, TCollectionOptions extends object = {}, TSystemOptions extends object = {}, TNeedsCtx extends object = {}, TColumnKinds extends ColumnKindsTypes = never, TContextOptions extends object = {}, TTraits extends EntityTraits = never, TDependsOn extends string = never, TFeatureTables extends AnyFeatureTables = {}> = Omit<PluginSpec<TId, TTables, TRequires, TCtx, TApi, TEntityOptions, TErrors, TKinds, TCollectionOptions, TSystemOptions, TNeedsCtx, TColumnKinds, TContextOptions, TTraits, TDependsOn, TFeatureTables>, 'entities' | 'relations'> & {
|
|
927
|
+
relations?: (r: RelationsBuilder<TTables & TRequires>) => TRelations;
|
|
928
|
+
entities?: (define: PluginEntityDefiner<TTables>) => TEntities;
|
|
929
|
+
};
|
|
930
|
+
interface DefinedPlugin<TId extends string, TTables extends Record<string, PgTable>, TRequires extends Record<string, PgTable>, TCtx extends object, TApi, TEntityOptions extends object, TErrors extends Record<string, PluginErrorDef>, TEntities extends Record<string, EntityDef<string, unknown>>, TRelations extends RelationsBuilderConfig<TTables & TRequires>, TKinds extends CollectionKinds, TCollectionOptions extends object, TSystemOptions extends object, TNeedsCtx extends object, TColumnKinds extends ColumnKindsTypes, TContextOptions extends object, TTraits extends EntityTraits, TDependsOn extends string, TFeatureTables extends AnyFeatureTables = {}> extends Plugin<PluginSpecInput<TId, TTables, TRequires, TCtx, TApi, TEntityOptions, TErrors, TEntities, TRelations, TKinds, TCollectionOptions, TSystemOptions, TNeedsCtx, TColumnKinds, TContextOptions, TTraits, TDependsOn, TFeatureTables>> {}
|
|
931
|
+
type Guard<T> = [T] extends [infer X extends T] ? X : never;
|
|
932
|
+
declare function definePlugin<const TId extends string, TTables extends Record<string, PgTable> = {}, TRequires extends Record<string, PgTable> = {}, TCtx extends object = {}, TApi = {}, TEntityOptions extends object = {}, const TErrors extends Record<string, PluginErrorDef> = {}, TEntities extends Record<string, EntityDef<string, unknown>> = {}, TRelations extends RelationsBuilderConfig<TTables & TRequires> = {}, TKinds extends CollectionKinds = CollectionKinds, TCollectionOptions extends object = {}, TSystemOptions extends object = {}, TNeedsCtx extends object = {}, TColumnKinds extends ColumnKindsTypes = never, TContextOptions extends object = {}, TDependsOn extends string = never, TFeatureTables extends FeatureTables<TTables> = {}>(spec: PluginSpecInput<TId, TTables, TRequires, TCtx, TApi, TEntityOptions, TErrors, TEntities, TRelations, TKinds, TCollectionOptions, TSystemOptions, TNeedsCtx, TColumnKinds, TContextOptions, never, TDependsOn, TFeatureTables> & {
|
|
933
|
+
traits?: never;
|
|
934
|
+
}): DefinedPlugin<Guard<TId>, Guard<TTables>, Guard<TRequires>, Guard<TCtx>, Guard<TApi>, Guard<TEntityOptions>, Guard<TErrors>, Guard<TEntities>, Guard<TRelations>, Guard<TKinds>, Guard<TCollectionOptions>, Guard<TSystemOptions>, Guard<TNeedsCtx>, Guard<TColumnKinds>, Guard<TContextOptions>, never, Guard<TDependsOn>, Guard<TFeatureTables>>;
|
|
935
|
+
//#endregion
|
|
936
|
+
//#region src/features/localization.d.ts
|
|
937
|
+
type Localized<T, L extends string, D extends L> = { [K in D]: T; } & { [K in Exclude<L, D>]?: T; } & Kinded<{
|
|
938
|
+
readonly plugin: 'localization';
|
|
939
|
+
readonly read: {
|
|
940
|
+
readonly resolved: T;
|
|
941
|
+
readonly strict: T | null;
|
|
942
|
+
readonly all: Localized<T, L, D>;
|
|
943
|
+
};
|
|
944
|
+
readonly write: {
|
|
945
|
+
readonly value: T;
|
|
946
|
+
readonly all: Localized<T, L, D>;
|
|
947
|
+
};
|
|
948
|
+
}>;
|
|
949
|
+
type LocaleReadMode = 'resolved' | 'strict' | 'all';
|
|
950
|
+
type StrictOf<C> = C extends {
|
|
951
|
+
fallback: infer F;
|
|
952
|
+
} ? F extends false ? 'strict' : 'resolved' : 'resolved';
|
|
953
|
+
interface LocalizationReadMode extends ReadModeFn {
|
|
954
|
+
readonly mode: this['config'] extends {
|
|
955
|
+
locale: infer L;
|
|
956
|
+
} ? L extends 'all' ? 'all' : StrictOf<this['config']> : StrictOf<this['config']>;
|
|
957
|
+
}
|
|
958
|
+
interface LocalizationWriteMode extends WriteModeFn {
|
|
959
|
+
readonly mode: this['config'] extends {
|
|
960
|
+
locale: infer L;
|
|
961
|
+
} ? L extends 'all' ? 'all' : 'value' : 'value';
|
|
962
|
+
}
|
|
963
|
+
type LocalizationOptions<L extends readonly [string, ...string[]], D extends L[number]> = {
|
|
964
|
+
locales: L;
|
|
965
|
+
defaultLocale: D;
|
|
966
|
+
fallback?: boolean;
|
|
967
|
+
locale?: (input: ContextInput) => string | undefined;
|
|
968
|
+
};
|
|
969
|
+
type LocalizationColumnKinds<L extends readonly [string, ...string[]]> = {
|
|
970
|
+
readMode: LocalizationReadMode;
|
|
971
|
+
filterMode: 'resolved';
|
|
972
|
+
writeMode: LocalizationWriteMode;
|
|
973
|
+
readOptions: {
|
|
974
|
+
locale?: L[number] | 'all' | undefined;
|
|
975
|
+
fallback?: boolean | undefined;
|
|
976
|
+
};
|
|
977
|
+
writeOptions: {
|
|
978
|
+
locale?: L[number] | 'all';
|
|
979
|
+
};
|
|
980
|
+
};
|
|
981
|
+
interface LocalizationPlugin<L extends readonly [string, ...string[]], D extends L[number]> extends DefinedPlugin<'localization', {}, {}, {
|
|
982
|
+
locale: L[number];
|
|
983
|
+
}, {}, {}, {}, {}, {}, CollectionKinds, {}, {}, {}, LocalizationColumnKinds<L>, {
|
|
984
|
+
locale?: L[number];
|
|
985
|
+
}, never, never> {
|
|
986
|
+
readonly locales: L;
|
|
987
|
+
readonly defaultLocale: D;
|
|
988
|
+
}
|
|
989
|
+
type RegisteredLocalization = Extract<RegisteredPlugins[number], {
|
|
990
|
+
readonly id: 'localization';
|
|
991
|
+
}>;
|
|
992
|
+
type LocalesOf<P> = P extends {
|
|
993
|
+
readonly locales: readonly (infer L extends string)[];
|
|
994
|
+
readonly defaultLocale: infer D extends string;
|
|
995
|
+
} ? {
|
|
996
|
+
locale: L;
|
|
997
|
+
default: D;
|
|
998
|
+
} : {
|
|
999
|
+
locale: string;
|
|
1000
|
+
default: string;
|
|
1001
|
+
};
|
|
1002
|
+
type LocalizationConfigured = [RegisteredLocalization] extends [never] ? {
|
|
1003
|
+
readonly '~error': 'localized() needs defineSetup({ localization })';
|
|
1004
|
+
} : unknown;
|
|
1005
|
+
type RegisteredLocale = LocalesOf<RegisteredLocalization>['locale'];
|
|
1006
|
+
type RegisteredDefault = LocalesOf<RegisteredLocalization>['default'] & RegisteredLocale;
|
|
1007
|
+
type BuilderData<B extends AnyPgColumnBuilder> = B['_'] extends {
|
|
1008
|
+
$type: infer T;
|
|
1009
|
+
} ? T : B['_']['data'];
|
|
1010
|
+
type JsonSafe<B extends AnyPgColumnBuilder> = BuilderData<B> extends Date | bigint | Uint8Array ? {
|
|
1011
|
+
readonly '~error': 'a localized value is stored as JSON: use text, numbers, booleans, enums or json';
|
|
1012
|
+
} : unknown;
|
|
1013
|
+
declare function localized<B extends AnyPgColumnBuilder>(builder: B & JsonSafe<B> & LocalizationConfigured): $Type<PgJsonbBuilder, Localized<BuilderData<B>, RegisteredLocale, RegisteredDefault>>;
|
|
1014
|
+
declare function localizedValue(column: AnyPgColumn, locale: RegisteredLocale): SQL;
|
|
1015
|
+
declare function localizedIndex(name: string, column: AnyPgColumn, locale: RegisteredLocale): IndexBuilder;
|
|
1016
|
+
declare function localizedUnique(name: string, column: AnyPgColumn, locale: RegisteredLocale): IndexBuilder;
|
|
1017
|
+
//#endregion
|
|
1018
|
+
//#region src/features/multi-tenant.d.ts
|
|
1019
|
+
declare const COLUMN = "tenantId";
|
|
1020
|
+
type TenantIdOf<B> = B extends {
|
|
1021
|
+
readonly _: {
|
|
1022
|
+
readonly $type: infer T;
|
|
1023
|
+
};
|
|
1024
|
+
} ? T : B extends {
|
|
1025
|
+
readonly _: {
|
|
1026
|
+
readonly data: infer T;
|
|
1027
|
+
};
|
|
1028
|
+
} ? T : unknown;
|
|
1029
|
+
type UuidBuilder = SetNotNull<PgUUIDBuilder>;
|
|
1030
|
+
type TextBuilder = SetNotNull<PgTextBuilder<[string, ...string[]]>>;
|
|
1031
|
+
type IntegerBuilder = SetNotNull<PgIntegerBuilder>;
|
|
1032
|
+
interface UuidTenantColumn extends UuidBuilder {}
|
|
1033
|
+
interface TextTenantColumn extends TextBuilder {}
|
|
1034
|
+
interface IntegerTenantColumn extends IntegerBuilder {}
|
|
1035
|
+
type Same<A, B> = [A] extends [B] ? ([B] extends [A] ? true : false) : false;
|
|
1036
|
+
type TenantColumnOf<B> = Same<B, UuidBuilder> extends true ? UuidTenantColumn : Same<B, TextBuilder> extends true ? TextTenantColumn : Same<B, IntegerBuilder> extends true ? IntegerTenantColumn : B;
|
|
1037
|
+
type TenantContext<T = string> = {
|
|
1038
|
+
tenantId: T | null;
|
|
1039
|
+
};
|
|
1040
|
+
type MultiTenantCollectionOptions = {
|
|
1041
|
+
tenant?: boolean;
|
|
1042
|
+
};
|
|
1043
|
+
interface MultiTenantKinds<B> extends CollectionKinds {
|
|
1044
|
+
readonly columns: this['options'] extends {
|
|
1045
|
+
tenant: true;
|
|
1046
|
+
} ? {
|
|
1047
|
+
tenantId: B;
|
|
1048
|
+
} : {};
|
|
1049
|
+
readonly entity: this['options'] extends {
|
|
1050
|
+
tenant: true;
|
|
1051
|
+
} ? {
|
|
1052
|
+
tenant: true;
|
|
1053
|
+
} : {};
|
|
1054
|
+
}
|
|
1055
|
+
type MultiTenantEntityOptions = {
|
|
1056
|
+
tenant?: true;
|
|
1057
|
+
};
|
|
1058
|
+
type MultiTenantSystemOptions = {
|
|
1059
|
+
unscoped?: boolean;
|
|
1060
|
+
};
|
|
1061
|
+
type MultiTenantContext = {
|
|
1062
|
+
readonly unscoped: boolean;
|
|
1063
|
+
};
|
|
1064
|
+
type Enabled$1 = {
|
|
1065
|
+
tenant: true;
|
|
1066
|
+
};
|
|
1067
|
+
interface MultiTenantTraits extends EntityTraits {
|
|
1068
|
+
readonly entityOptions: MultiTenantEntityOptions;
|
|
1069
|
+
readonly governs: Enabled$1;
|
|
1070
|
+
readonly managed: this['given'] extends Enabled$1 ? typeof COLUMN : never;
|
|
1071
|
+
}
|
|
1072
|
+
declare function tenantColumn(entity: EntityMeta): string | null;
|
|
1073
|
+
type MultiTenantOptions<B extends AnyPgColumnBuilder> = {
|
|
1074
|
+
column: () => B;
|
|
1075
|
+
seedTenant?: TenantIdOf<B>;
|
|
1076
|
+
};
|
|
1077
|
+
interface MultiTenantPlugin<C, T> extends DefinedPlugin<'multiTenant', {}, {}, MultiTenantContext, {}, {}, {}, {}, {}, MultiTenantKinds<C>, MultiTenantCollectionOptions, MultiTenantSystemOptions, TenantContext<T>, never, {}, MultiTenantTraits, never> {}
|
|
1078
|
+
//#endregion
|
|
1079
|
+
//#region src/features/soft-delete.d.ts
|
|
1080
|
+
declare function softDeleteColumns(): {
|
|
1081
|
+
deletedAt: import("drizzle-orm/pg-core").PgTimestampBuilder;
|
|
1082
|
+
};
|
|
1083
|
+
declare function softUnique(name: string, deletedAt: AnyPgColumn): {
|
|
1084
|
+
on(...cols: [AnyPgColumn, ...AnyPgColumn[]]): IndexBuilder;
|
|
1085
|
+
};
|
|
1086
|
+
type SoftDeleteCollectionOptions = {
|
|
1087
|
+
softDelete?: boolean;
|
|
1088
|
+
};
|
|
1089
|
+
interface SoftDeleteKinds extends CollectionKinds {
|
|
1090
|
+
readonly columns: this['options'] extends {
|
|
1091
|
+
softDelete: true;
|
|
1092
|
+
} ? ReturnType<typeof softDeleteColumns> : {};
|
|
1093
|
+
readonly entity: this['options'] extends {
|
|
1094
|
+
softDelete: true;
|
|
1095
|
+
} ? {
|
|
1096
|
+
softDelete: true;
|
|
1097
|
+
} : {};
|
|
1098
|
+
}
|
|
1099
|
+
type SoftDeleteEntityOptions = {
|
|
1100
|
+
softDelete?: true;
|
|
1101
|
+
};
|
|
1102
|
+
type SoftDeleteReadOptions = {
|
|
1103
|
+
withDeleted?: boolean | undefined;
|
|
1104
|
+
};
|
|
1105
|
+
type SoftDeleteDeleteOptions = {
|
|
1106
|
+
hard?: boolean;
|
|
1107
|
+
};
|
|
1108
|
+
type Enabled = {
|
|
1109
|
+
softDelete: true;
|
|
1110
|
+
};
|
|
1111
|
+
type SoftDeleteApi<T extends EntityTraits> = {
|
|
1112
|
+
restore(id: EntityIdOf<T>): Promise<EntityRowOf<T>>;
|
|
1113
|
+
};
|
|
1114
|
+
type SoftDeleteQueries<T extends EntityTraits> = {
|
|
1115
|
+
restore(input: {
|
|
1116
|
+
id: EntityIdOf<T>;
|
|
1117
|
+
}): Descriptor<T['name'] & string, 'restore', {
|
|
1118
|
+
id: EntityIdOf<T>;
|
|
1119
|
+
}, EntityRowOf<T>>;
|
|
1120
|
+
};
|
|
1121
|
+
interface SoftDeleteTraits extends EntityTraits {
|
|
1122
|
+
readonly entityOptions: SoftDeleteEntityOptions;
|
|
1123
|
+
readonly governs: Enabled;
|
|
1124
|
+
readonly managed: this['given'] extends Enabled ? 'deletedAt' : never;
|
|
1125
|
+
readonly optionsOn: this['given'] extends Enabled ? 'read' | 'delete' : never;
|
|
1126
|
+
readonly optionTypes: {
|
|
1127
|
+
read: SoftDeleteReadOptions;
|
|
1128
|
+
delete: SoftDeleteDeleteOptions;
|
|
1129
|
+
};
|
|
1130
|
+
readonly operations: 'restore';
|
|
1131
|
+
readonly api: this['given'] extends Enabled ? SoftDeleteApi<this> : {};
|
|
1132
|
+
readonly queries: this['given'] extends Enabled ? SoftDeleteQueries<this> : {};
|
|
1133
|
+
}
|
|
1134
|
+
declare function softDeleteColumn(entity: EntityMeta): string | null;
|
|
1135
|
+
type SoftDeletePlugin = DefinedPlugin<'softDelete', {}, {}, {}, {}, {}, {}, {}, {}, SoftDeleteKinds, SoftDeleteCollectionOptions, {}, {}, never, {}, SoftDeleteTraits, never>;
|
|
1136
|
+
//#endregion
|
|
1137
|
+
//#region src/features/versions/table.d.ts
|
|
1138
|
+
declare function draftColumns(): {
|
|
1139
|
+
status: import("drizzle-orm/pg-core").SetHasDefault<import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTextBuilder<["draft", "published"]>>>;
|
|
1140
|
+
publishedAt: import("drizzle-orm/pg-core").PgTimestampBuilder;
|
|
1141
|
+
};
|
|
1142
|
+
//#endregion
|
|
1143
|
+
//#region src/features/versions/index.d.ts
|
|
1144
|
+
declare function versionsTable(entity: EntityMeta): PgTable | null;
|
|
1145
|
+
type VersionsPlugin = DefinedPlugin<'versions', {}, {}, {}, {}, {}, {}, {}, {}, VersionsKinds, VersionsCollectionOptions, {}, {}, never, {}, VersionsTraits, never>;
|
|
1146
|
+
//#endregion
|
|
1147
|
+
//#region src/features/index.d.ts
|
|
1148
|
+
type Locales = readonly [string, ...string[]];
|
|
1149
|
+
type DefaultFeaturePlugins = readonly [VersionsPlugin, SoftDeletePlugin];
|
|
1150
|
+
type FeaturePlugins<L, D, B> = readonly [...([L] extends [never] ? [] : [LocalizationPlugin<Assume<L, Locales>, Assume<D, Assume<L, Locales>[number]>>]), VersionsPlugin, SoftDeletePlugin, ...([B] extends [never] ? [] : [MultiTenantPlugin<TenantColumnOf<B>, TenantIdOf<B>>])];
|
|
1151
|
+
type FeaturesOptions<L extends Locales, D extends L[number], B extends AnyPgColumnBuilder> = {
|
|
1152
|
+
localization?: LocalizationOptions<L, D>;
|
|
1153
|
+
multiTenant?: MultiTenantOptions<B>;
|
|
1154
|
+
};
|
|
1155
|
+
//#endregion
|
|
1156
|
+
//#region src/define/setup.d.ts
|
|
1157
|
+
interface TypionSetup<TPlugins extends readonly AnyPlugin[]> {
|
|
1158
|
+
readonly '~plugins': TPlugins;
|
|
1159
|
+
}
|
|
1160
|
+
type AnySetup = TypionSetup<readonly AnyPlugin[]>;
|
|
1161
|
+
type DefaultSetup = TypionSetup<DefaultFeaturePlugins>;
|
|
1162
|
+
interface SetupLocalization<L extends Locales, D extends L[number]> {
|
|
1163
|
+
readonly locales: L;
|
|
1164
|
+
readonly defaultLocale: D;
|
|
1165
|
+
}
|
|
1166
|
+
type SetupPlugins<L, D, B, P extends readonly AnyPlugin[]> = readonly [...FeaturePlugins<L, D, B>, ...P];
|
|
1167
|
+
type Setup<L, D, B, P extends readonly AnyPlugin[]> = TypionSetup<SetupPlugins<L, D, B, P>> & ([L] extends [never] ? {} : {
|
|
1168
|
+
readonly localization: SetupLocalization<Assume<L, Locales>, Assume<D, Assume<L, Locales>[number]>>;
|
|
1169
|
+
});
|
|
1170
|
+
type SetupOptions<L extends Locales, D extends L[number], B extends AnyPgColumnBuilder, P extends readonly AnyPlugin[]> = FeaturesOptions<L, D, B> & {
|
|
1171
|
+
plugins?: P & DependenciesError<P>;
|
|
1172
|
+
};
|
|
1173
|
+
declare function defineSetup<const L extends Locales = never, const D extends L[number] = never, B extends AnyPgColumnBuilder = never, const P extends readonly AnyPlugin[] = readonly []>(options: SetupOptions<L, D, B, P>): Setup<L, D, B, P>;
|
|
1174
|
+
//#endregion
|
|
1175
|
+
//#region src/define/config.d.ts
|
|
1176
|
+
declare function defineConfig<S extends AnySetup = DefaultSetup, const Cs extends readonly AnyCollection[] = readonly [], TCtx extends object = {}, const Tb extends ConfigTables = {}>(options: ConfigOptions<S, Cs, TCtx, Tb>): TypionConfig<ConfigTypes<TCtx, S['~plugins'], ByName<Cs>, Tb>>;
|
|
1177
|
+
//#endregion
|
|
1178
|
+
//#region src/db/adapter.d.ts
|
|
1179
|
+
declare function dbAdapter(connect: (relations: AnyRelations) => PgAsyncDatabase<PgQueryResultHKT, any>, options?: {
|
|
1180
|
+
close?: () => Promise<void>;
|
|
1181
|
+
url?: string;
|
|
1182
|
+
}): DbAdapter;
|
|
1183
|
+
//#endregion
|
|
1184
|
+
//#region src/define/entity.d.ts
|
|
1185
|
+
declare function allowAll(): AllowAll;
|
|
1186
|
+
//#endregion
|
|
1187
|
+
//#region src/runtime/internals.d.ts
|
|
1188
|
+
type AfterCommitErrorInfo = {
|
|
1189
|
+
readonly entity: string;
|
|
1190
|
+
readonly operation: Operation | 'transaction';
|
|
1191
|
+
readonly requestId: string;
|
|
1192
|
+
};
|
|
1193
|
+
//#endregion
|
|
1194
|
+
//#region src/runtime/typion.d.ts
|
|
1195
|
+
type GetTypionOptions = {
|
|
1196
|
+
db?: DbAdapter;
|
|
1197
|
+
fresh?: boolean;
|
|
1198
|
+
};
|
|
1199
|
+
declare function getTypion<const C extends TypionConfig<any>>(config: C, options?: GetTypionOptions): Promise<Typion<C>>;
|
|
1200
|
+
//#endregion
|
|
1201
|
+
//#region src/validation/structural.d.ts
|
|
1202
|
+
interface StructuralFieldSchema extends StandardSchemaV1 {
|
|
1203
|
+
readonly key: string;
|
|
1204
|
+
readonly required: boolean;
|
|
1205
|
+
readonly nullable: boolean;
|
|
1206
|
+
readonly keyed: boolean;
|
|
1207
|
+
}
|
|
1208
|
+
interface StructuralSchema extends StandardSchemaV1<Record<string, unknown>, Record<string, unknown>> {
|
|
1209
|
+
readonly entity: string;
|
|
1210
|
+
readonly mode: ValidationMode;
|
|
1211
|
+
readonly fields: Readonly<Record<string, StructuralFieldSchema>>;
|
|
1212
|
+
}
|
|
1213
|
+
interface StructuralValidationAdapter extends ValidationAdapter {
|
|
1214
|
+
readonly id: 'structural';
|
|
1215
|
+
base(entity: EntityMeta, mode: ValidationMode, refinements: Record<string, unknown> | undefined): StructuralSchema;
|
|
1216
|
+
}
|
|
1217
|
+
declare function structuralValidation(): StructuralValidationAdapter;
|
|
1218
|
+
//#endregion
|
|
1219
|
+
//#region src/index.d.ts
|
|
1220
|
+
interface Register {}
|
|
1221
|
+
//#endregion
|
|
1222
|
+
//#region src/types/collection.d.ts
|
|
1223
|
+
type RegisteredSetup = Register extends {
|
|
1224
|
+
setup: infer S extends AnySetup;
|
|
1225
|
+
} ? S : DefaultSetup;
|
|
1226
|
+
type RegisteredPlugins = RegisteredSetup['~plugins'];
|
|
1227
|
+
type RegisteredContext = Register extends {
|
|
1228
|
+
context: infer C extends object;
|
|
1229
|
+
} ? C : {};
|
|
1230
|
+
type RegisteredConfig = Register extends {
|
|
1231
|
+
config: infer C;
|
|
1232
|
+
} ? C : never;
|
|
1233
|
+
type Registered = ConfigTypesOf<RegisteredConfig>;
|
|
1234
|
+
interface RegisteredTypes extends RegisteredTypesBase {}
|
|
1235
|
+
type RegisteredTypesBase = [Registered] extends [never] ? TypionTypes : Assume<Registered, TypionTypes>;
|
|
1236
|
+
type TypesOf<C> = [C] extends [RegisteredConfig] ? [RegisteredConfig] extends [C] ? RegisteredTypes : OwnTypesOf<C> : OwnTypesOf<C>;
|
|
1237
|
+
type OwnTypesOf<C> = C extends {
|
|
1238
|
+
readonly '~types'?: infer TE;
|
|
1239
|
+
} ? Assume<NonNullable<TE>, TypionTypes> : never;
|
|
1240
|
+
type ConfigTypesOf<C> = C extends {
|
|
1241
|
+
readonly '~types'?: infer TE;
|
|
1242
|
+
} ? NonNullable<TE> : never;
|
|
1243
|
+
type Flatten<T> = { [K in keyof T]: T[K]; } & {};
|
|
1244
|
+
type ApplyKinds<K, O, Key extends 'columns' | 'entity'> = K extends CollectionKinds ? (K & {
|
|
1245
|
+
readonly options: O;
|
|
1246
|
+
})[Key] : {};
|
|
1247
|
+
type FoldKinds<P extends readonly unknown[], O, Key extends 'columns' | 'entity', Acc = {}> = P extends readonly [infer H, ...infer Rest] ? FoldKinds<Rest, O, Key, Acc & ApplyKinds<PluginKinds<H>, O, Key>> : Acc;
|
|
1248
|
+
type IdColumn<S> = S extends {
|
|
1249
|
+
columns: {
|
|
1250
|
+
id: unknown;
|
|
1251
|
+
};
|
|
1252
|
+
} ? {} : S extends {
|
|
1253
|
+
idColumn: string;
|
|
1254
|
+
} ? {} : {
|
|
1255
|
+
id: ReturnType<typeof defaultIdColumn>;
|
|
1256
|
+
};
|
|
1257
|
+
type TimestampColumns<S> = S extends {
|
|
1258
|
+
timestamps: false;
|
|
1259
|
+
} ? {} : ReturnType<typeof timestamps>;
|
|
1260
|
+
type ColumnsOf<S, K> = Flatten<IdColumn<S> & (S extends {
|
|
1261
|
+
columns: infer C;
|
|
1262
|
+
} ? C : {}) & TimestampColumns<S> & K>;
|
|
1263
|
+
type DbNameOf<N extends string, S> = S extends {
|
|
1264
|
+
dbName: infer D extends string;
|
|
1265
|
+
} ? D : N;
|
|
1266
|
+
type TableOf<N extends string, S, K> = PgTableWithColumns<{
|
|
1267
|
+
name: DbNameOf<N, S>;
|
|
1268
|
+
schema: undefined;
|
|
1269
|
+
columns: PgBuildColumns<N, Assume<ColumnsOf<S, K>, Record<string, AnyPgColumnBuilder>>>;
|
|
1270
|
+
dialect: 'pg';
|
|
1271
|
+
}>;
|
|
1272
|
+
type OneSpec<T extends string = string, Opt extends boolean = boolean> = {
|
|
1273
|
+
readonly kind: 'one';
|
|
1274
|
+
readonly target: T;
|
|
1275
|
+
readonly from: string;
|
|
1276
|
+
readonly to: string;
|
|
1277
|
+
readonly optional: Opt;
|
|
1278
|
+
};
|
|
1279
|
+
type ThroughSpec = {
|
|
1280
|
+
readonly table: string;
|
|
1281
|
+
readonly from: string;
|
|
1282
|
+
readonly to: string;
|
|
1283
|
+
};
|
|
1284
|
+
type ManySpec<T extends string = string, W extends boolean = boolean> = {
|
|
1285
|
+
readonly kind: 'many';
|
|
1286
|
+
readonly target: T;
|
|
1287
|
+
readonly from: string;
|
|
1288
|
+
readonly to: string;
|
|
1289
|
+
readonly through?: ThroughSpec | undefined;
|
|
1290
|
+
readonly writable: W;
|
|
1291
|
+
};
|
|
1292
|
+
type RelationSpec = OneSpec | ManySpec;
|
|
1293
|
+
type RelationHelpers<TKeys extends string> = {
|
|
1294
|
+
one<const T extends string, const Opt extends boolean = true>(target: T, config: {
|
|
1295
|
+
from: TKeys;
|
|
1296
|
+
to: string;
|
|
1297
|
+
optional?: Opt;
|
|
1298
|
+
}): OneSpec<T, Opt>;
|
|
1299
|
+
many<const T extends string, const W extends boolean = false>(target: T, config: {
|
|
1300
|
+
from: TKeys;
|
|
1301
|
+
to: string;
|
|
1302
|
+
through?: ThroughSpec;
|
|
1303
|
+
writable?: W;
|
|
1304
|
+
}): ManySpec<T, W>;
|
|
1305
|
+
};
|
|
1306
|
+
type StructureInput<P extends readonly AnyPlugin[], C, S> = {
|
|
1307
|
+
columns: Record<string, AnyPgColumnBuilder>;
|
|
1308
|
+
relations?: (r: RelationHelpers<keyof ColumnsOf<S & {
|
|
1309
|
+
columns: C;
|
|
1310
|
+
}, FoldKinds<P, S & {
|
|
1311
|
+
columns: C;
|
|
1312
|
+
}, 'columns'>> & string>) => Record<string, RelationSpec>;
|
|
1313
|
+
dbName?: string;
|
|
1314
|
+
timestamps?: boolean;
|
|
1315
|
+
public?: boolean;
|
|
1316
|
+
idColumn?: keyof ColumnsOf<S, FoldKinds<P, S, 'columns'>> & string;
|
|
1317
|
+
fields?: { [K in keyof ColumnsOf<S & {
|
|
1318
|
+
columns: C;
|
|
1319
|
+
}, FoldKinds<P, S & {
|
|
1320
|
+
columns: C;
|
|
1321
|
+
}, 'columns'>>]?: FieldOptions<BaseContext & RegisteredContext & PluginNeedsContext<P> & PluginContext<P>>; };
|
|
1322
|
+
} & PluginCollectionOptions<P> & PluginEntityOptions<P>;
|
|
1323
|
+
type NoUnknownKeys<S, TAllowed> = { [K in Exclude<keyof S, keyof TAllowed>]: never; };
|
|
1324
|
+
type RegisteredCtx = [Registered] extends [never] ? BaseContext : Ctx<RegisteredTypes>;
|
|
1325
|
+
type OwnRelations<N extends string, T> = ExtractTablesWithRelations<{}, { [K in N]: Assume<T, PgTable>; }>;
|
|
1326
|
+
interface RegisteredRelations extends RegisteredRelationsBase {}
|
|
1327
|
+
type RegisteredRelationsBase = [Registered] extends [never] ? {} : RegisteredTypes['relations'];
|
|
1328
|
+
type RulesRelations<N extends string, T> = [Registered] extends [never] ? OwnRelations<N, T> : N extends keyof RegisteredRelations ? RegisteredRelations : OwnRelations<N, T>;
|
|
1329
|
+
type AccessOf<N extends string, T, S, TCtx> = RulesRelations<N, T> extends (infer R extends AnyRelations) ? N extends keyof R & string ? S extends {
|
|
1330
|
+
public: true;
|
|
1331
|
+
} ? Omit<AccessRules<R, N, TCtx, RegisteredPlugins, SystemTypion, CollectionRules<S>>, 'read'> : AccessRules<R, N, TCtx, RegisteredPlugins, SystemTypion, CollectionRules<S>> : never : never;
|
|
1332
|
+
type CollectionRules<S> = TraitRules<RegisteredPlugins, FoldKinds<RegisteredPlugins, S, 'entity'>>;
|
|
1333
|
+
type HooksOf<N extends string, T, TCtx> = RulesRelations<N, T> extends (infer R extends AnyRelations) ? N extends keyof R & string ? EntityHooks<R, N, TCtx, RegisteredPlugins, HookTypion> : never : never;
|
|
1334
|
+
type ValidationOf<N extends string, T> = RulesRelations<N, T> extends (infer R extends AnyRelations) ? N extends keyof R & string ? EntityValidation<R, N> : never : never;
|
|
1335
|
+
type Behaviour<N extends string, T, S> = {
|
|
1336
|
+
access?: AccessOf<N, T, S, RegisteredCtx>;
|
|
1337
|
+
hooks?: HooksOf<N, T, RegisteredCtx>;
|
|
1338
|
+
validate?: ValidationOf<N, T>;
|
|
1339
|
+
indexes?: (t: { [K in keyof Assume<T, PgTable>['_']['columns']]: ExtraConfigColumn; }) => PgTableExtraConfigValue[];
|
|
1340
|
+
seed?: (generators: SeedGenerators) => Record<string, unknown>;
|
|
1341
|
+
defaultOrder?: Record<string, 'asc' | 'desc'>;
|
|
1342
|
+
maxLimit?: number;
|
|
1343
|
+
};
|
|
1344
|
+
type CollectionRuntime = {
|
|
1345
|
+
readonly structure: Readonly<Record<string, unknown>>;
|
|
1346
|
+
readonly relations: Readonly<Record<string, RelationSpec>>;
|
|
1347
|
+
readonly behaviour: Readonly<Record<string, unknown>>;
|
|
1348
|
+
readonly state: {
|
|
1349
|
+
table: PgTable | undefined;
|
|
1350
|
+
};
|
|
1351
|
+
};
|
|
1352
|
+
interface Collection<N extends string, T extends PgTable, S> {
|
|
1353
|
+
readonly name: N;
|
|
1354
|
+
readonly table: T;
|
|
1355
|
+
readonly '~structure': S;
|
|
1356
|
+
readonly '~runtime': CollectionRuntime;
|
|
1357
|
+
}
|
|
1358
|
+
interface CollectionDraft<N extends string, T extends PgTable, S> extends Collection<N, T, S> {
|
|
1359
|
+
define(behaviour: Behaviour<N, T, S>): Collection<N, T, S>;
|
|
1360
|
+
}
|
|
1361
|
+
type AnyCollection = {
|
|
1362
|
+
readonly name: string;
|
|
1363
|
+
readonly table: PgTable;
|
|
1364
|
+
readonly '~structure': object;
|
|
1365
|
+
readonly '~runtime': CollectionRuntime;
|
|
1366
|
+
};
|
|
1367
|
+
type RelationOf<Spec> = Spec extends OneSpec<infer T, infer Opt> ? One<T, Opt> : Spec extends ManySpec<infer T> ? Many<T> : never;
|
|
1368
|
+
type RelationsOfStructure<S> = S extends {
|
|
1369
|
+
relations: (r: never) => infer Specs;
|
|
1370
|
+
} ? { [K in keyof Specs]: RelationOf<Specs[K]>; } : {};
|
|
1371
|
+
type StructureOf<C> = C extends {
|
|
1372
|
+
readonly '~structure': infer S;
|
|
1373
|
+
} ? S : never;
|
|
1374
|
+
type RelationConfigOf<Cs> = { [K in keyof Cs]: RelationsOfStructure<StructureOf<Cs[K]>>; };
|
|
1375
|
+
type TablesOf<Cs> = { [K in keyof Cs]: Cs[K] extends {
|
|
1376
|
+
readonly table: infer T;
|
|
1377
|
+
} ? T : never; };
|
|
1378
|
+
type ReadOptionOf<S> = S extends {
|
|
1379
|
+
public: true;
|
|
1380
|
+
} ? {
|
|
1381
|
+
access: {
|
|
1382
|
+
read: true;
|
|
1383
|
+
};
|
|
1384
|
+
} : {
|
|
1385
|
+
access: {
|
|
1386
|
+
read: (a: never) => boolean;
|
|
1387
|
+
};
|
|
1388
|
+
};
|
|
1389
|
+
type StructureOptionsOf<S> = (S extends {
|
|
1390
|
+
fields: infer Fd;
|
|
1391
|
+
} ? {
|
|
1392
|
+
fields: Fd;
|
|
1393
|
+
} : {}) & (S extends {
|
|
1394
|
+
idColumn: infer I;
|
|
1395
|
+
} ? {
|
|
1396
|
+
idColumn: I;
|
|
1397
|
+
} : {}) & LinksOf<S>;
|
|
1398
|
+
type LinksOf<S> = S extends {
|
|
1399
|
+
relations: (r: never) => infer Specs;
|
|
1400
|
+
} ? WritableOf<Specs> extends (infer L extends string) ? [L] extends [never] ? {} : {
|
|
1401
|
+
links: readonly L[];
|
|
1402
|
+
} : {} : {};
|
|
1403
|
+
type WritableOf<Specs> = { [K in keyof Specs]: Specs[K] extends {
|
|
1404
|
+
readonly writable: true;
|
|
1405
|
+
} ? K : never; }[keyof Specs];
|
|
1406
|
+
type EntityOptionsOf<S, K> = Flatten<ReadOptionOf<S> & StructureOptionsOf<S> & K>;
|
|
1407
|
+
type EntitiesOf<Cs, P extends readonly unknown[]> = { [K in keyof Cs & string]: EntityDef<K, EntityOptionsOf<StructureOf<Cs[K]>, FoldKinds<P, StructureOf<Cs[K]>, 'entity'>>>; };
|
|
1408
|
+
type ConfigTypes<TCtx extends object, P extends readonly AnyPlugin[], Cs, Tb extends ConfigTables = {}> = MergedRelations<RelationConfigOf<Cs>, P, Assume<TablesOf<Cs> & Tb, UserTables>> extends (infer R extends AnyRelations) ? {
|
|
1409
|
+
ctx: TCtx & PluginNeedsContext<P>;
|
|
1410
|
+
tables: TablesOf<Cs> & Tb & Record<string, PgTable | PgEnum<any>>;
|
|
1411
|
+
plugins: P;
|
|
1412
|
+
entities: EntitiesOf<Cs, P> & PluginEntities<P>;
|
|
1413
|
+
relations: R;
|
|
1414
|
+
} : never;
|
|
1415
|
+
type DbAdapter = {
|
|
1416
|
+
connect(relations: AnyRelations): PgAsyncDatabase<PgQueryResultHKT, any>;
|
|
1417
|
+
check?(): void;
|
|
1418
|
+
close?(): Promise<void>;
|
|
1419
|
+
credentials?(): unknown;
|
|
1420
|
+
};
|
|
1421
|
+
type ConfigSeedOptions = {
|
|
1422
|
+
count?: number;
|
|
1423
|
+
seed?: number;
|
|
1424
|
+
collections?: readonly string[];
|
|
1425
|
+
values?: Readonly<Record<string, unknown>>;
|
|
1426
|
+
refine?: (generators: SeedGenerators) => Record<string, unknown>;
|
|
1427
|
+
};
|
|
1428
|
+
type MigrationsOptions = {
|
|
1429
|
+
dir?: string;
|
|
1430
|
+
table?: string;
|
|
1431
|
+
schema?: string;
|
|
1432
|
+
};
|
|
1433
|
+
interface SystemTypion extends RegisteredSystem {}
|
|
1434
|
+
type RegisteredSystem = [Registered] extends [never] ? {} : TypionApp<RegisteredTypes, 'system'>;
|
|
1435
|
+
interface HookTypion extends RegisteredHook {}
|
|
1436
|
+
type RegisteredHook = [Registered] extends [never] ? {} : Omit<TypionApp<RegisteredTypes, 'user'>, '$mode'> & {
|
|
1437
|
+
readonly $mode: TypionMode;
|
|
1438
|
+
};
|
|
1439
|
+
type ContextFactory<TCtx> = (input: ContextInput & {
|
|
1440
|
+
system: SystemTypion;
|
|
1441
|
+
}) => MaybePromise<TCtx>;
|
|
1442
|
+
type TypionConfig<TE extends TypionTypes> = {
|
|
1443
|
+
readonly '~types'?: TE;
|
|
1444
|
+
readonly definition: TypionDefinition<TE>;
|
|
1445
|
+
readonly schema: TypionDefinition<TE>['schema'];
|
|
1446
|
+
readonly db: DbAdapter | undefined;
|
|
1447
|
+
readonly context: ContextFactory<object> | undefined;
|
|
1448
|
+
readonly migrations: MigrationsOptions | undefined;
|
|
1449
|
+
readonly seed: ConfigSeedOptions | undefined;
|
|
1450
|
+
readonly onAfterCommitError: AfterCommitErrorHandler | undefined;
|
|
1451
|
+
readonly checkSchema: boolean | undefined;
|
|
1452
|
+
};
|
|
1453
|
+
type AfterCommitErrorHandler = (error: unknown, info: AfterCommitErrorInfo) => void;
|
|
1454
|
+
type ConfigTables = Record<string, PgTable | PgEnum<any>>;
|
|
1455
|
+
type ByName<Cs extends readonly AnyCollection[]> = { [C in Cs[number] as C['name']]: C; };
|
|
1456
|
+
type SameSetup<S> = [S] extends [RegisteredSetup] ? [RegisteredSetup] extends [S] ? unknown : SetupMismatch : SetupMismatch;
|
|
1457
|
+
type SetupMismatch = {
|
|
1458
|
+
'~error': 'setup must be the one in `interface Register { setup }`';
|
|
1459
|
+
};
|
|
1460
|
+
type ConfigOptions<S extends AnySetup, Cs extends readonly AnyCollection[], TCtx, Tb extends ConfigTables = {}> = {
|
|
1461
|
+
setup?: S & SameSetup<S>;
|
|
1462
|
+
collections: Cs;
|
|
1463
|
+
tables?: Tb;
|
|
1464
|
+
db?: DbAdapter;
|
|
1465
|
+
context?: ContextFactory<TCtx> & ContextFactory<PluginNeedsContext<S['~plugins']>> & ContextFactory<RegisteredContext>;
|
|
1466
|
+
migrations?: MigrationsOptions;
|
|
1467
|
+
seed?: ConfigSeedOptions;
|
|
1468
|
+
maxLimit?: number;
|
|
1469
|
+
validation?: ValidationAdapter;
|
|
1470
|
+
onAfterCommitError?: AfterCommitErrorHandler;
|
|
1471
|
+
checkSchema?: boolean;
|
|
1472
|
+
};
|
|
1473
|
+
type Typion<C> = TypionEngine<TypesOf<C>>;
|
|
1474
|
+
type TypionAppOf<C> = TypionApp<TypesOf<C>, 'user'>;
|
|
1475
|
+
type HandlerOptionsOf<C> = HandlerOptions<TypesOf<C>>;
|
|
1476
|
+
//#endregion
|
|
1477
|
+
//#region src/features/versions/types.d.ts
|
|
1478
|
+
type VersionState = 'draft' | 'published';
|
|
1479
|
+
type VersionOperation = 'create' | 'update' | 'draft' | 'publish' | 'unpublish' | 'discard' | 'restoreVersion' | 'delete' | (string & {});
|
|
1480
|
+
type VersionRef = {
|
|
1481
|
+
versionId: string;
|
|
1482
|
+
versionNumber: number;
|
|
1483
|
+
state: VersionState;
|
|
1484
|
+
};
|
|
1485
|
+
type Version<TRow> = {
|
|
1486
|
+
versionId: string;
|
|
1487
|
+
versionNumber: number;
|
|
1488
|
+
state: VersionState;
|
|
1489
|
+
operation: VersionOperation;
|
|
1490
|
+
isLatest: boolean;
|
|
1491
|
+
createdAt: Date;
|
|
1492
|
+
createdBy: string | null;
|
|
1493
|
+
mode: TypionMode;
|
|
1494
|
+
systemReason: string | null;
|
|
1495
|
+
requestId: string | null;
|
|
1496
|
+
data: TRow;
|
|
1497
|
+
};
|
|
1498
|
+
type FieldDiff<TRow> = { [K in keyof TRow]: {
|
|
1499
|
+
field: K;
|
|
1500
|
+
before: TRow[K];
|
|
1501
|
+
after: TRow[K];
|
|
1502
|
+
}; }[keyof TRow];
|
|
1503
|
+
type HasDraftColumns<T> = T extends {
|
|
1504
|
+
_: {
|
|
1505
|
+
columns: {
|
|
1506
|
+
status: AnyPgColumn;
|
|
1507
|
+
publishedAt: AnyPgColumn;
|
|
1508
|
+
};
|
|
1509
|
+
};
|
|
1510
|
+
} ? true : false;
|
|
1511
|
+
type PendingDraftPolicy = 'supersede' | 'reject';
|
|
1512
|
+
type VersionsEntityOptions<T> = {
|
|
1513
|
+
versions?: true | {
|
|
1514
|
+
drafts?: HasDraftColumns<T> extends true ? boolean : never;
|
|
1515
|
+
max?: number;
|
|
1516
|
+
onPendingDraft?: PendingDraftPolicy;
|
|
1517
|
+
table?: PgTable;
|
|
1518
|
+
};
|
|
1519
|
+
};
|
|
1520
|
+
type VersionsOption = true | {
|
|
1521
|
+
drafts?: boolean;
|
|
1522
|
+
max?: number;
|
|
1523
|
+
onPendingDraft?: PendingDraftPolicy;
|
|
1524
|
+
};
|
|
1525
|
+
type VersionsCollectionOptions = {
|
|
1526
|
+
versions?: VersionsOption;
|
|
1527
|
+
};
|
|
1528
|
+
interface VersionsKinds extends CollectionKinds {
|
|
1529
|
+
readonly columns: this['options'] extends {
|
|
1530
|
+
versions: {
|
|
1531
|
+
drafts: true;
|
|
1532
|
+
};
|
|
1533
|
+
} ? ReturnType<typeof draftColumns> : {};
|
|
1534
|
+
readonly entity: this['options'] extends {
|
|
1535
|
+
versions: infer V;
|
|
1536
|
+
} ? {
|
|
1537
|
+
versions: V;
|
|
1538
|
+
} : {};
|
|
1539
|
+
}
|
|
1540
|
+
type Versioned = {
|
|
1541
|
+
versions: true | object;
|
|
1542
|
+
};
|
|
1543
|
+
type Drafts = {
|
|
1544
|
+
versions: {
|
|
1545
|
+
drafts: true;
|
|
1546
|
+
};
|
|
1547
|
+
};
|
|
1548
|
+
type VersionsReadOptions = {
|
|
1549
|
+
draft?: boolean | undefined;
|
|
1550
|
+
};
|
|
1551
|
+
type VersionsCreateOptions = {
|
|
1552
|
+
draft?: boolean;
|
|
1553
|
+
publish?: boolean;
|
|
1554
|
+
};
|
|
1555
|
+
type VersionsUpdateOptions = {
|
|
1556
|
+
draft?: boolean;
|
|
1557
|
+
};
|
|
1558
|
+
type VersionsListOptions = {
|
|
1559
|
+
limit?: number;
|
|
1560
|
+
offset?: number;
|
|
1561
|
+
state?: VersionState;
|
|
1562
|
+
};
|
|
1563
|
+
type VersionsRestoreOptions = {
|
|
1564
|
+
draft?: boolean;
|
|
1565
|
+
};
|
|
1566
|
+
type VersionsHookArgs<TRow> = {
|
|
1567
|
+
change: {
|
|
1568
|
+
draft: boolean;
|
|
1569
|
+
};
|
|
1570
|
+
afterChange: {
|
|
1571
|
+
previousDraft: TRow | null;
|
|
1572
|
+
version: VersionRef | null;
|
|
1573
|
+
};
|
|
1574
|
+
afterDelete: {
|
|
1575
|
+
version: VersionRef | null;
|
|
1576
|
+
};
|
|
1577
|
+
};
|
|
1578
|
+
type DraftsApi<T extends EntityTraits> = {
|
|
1579
|
+
publish(id: EntityIdOf<T>): Promise<EntityRowOf<T>>;
|
|
1580
|
+
unpublish(id: EntityIdOf<T>): Promise<EntityRowOf<T>>;
|
|
1581
|
+
discardDraft(id: EntityIdOf<T>): Promise<EntityRowOf<T>>;
|
|
1582
|
+
};
|
|
1583
|
+
type HistoryApi<T extends EntityTraits> = {
|
|
1584
|
+
versions: {
|
|
1585
|
+
list(id: EntityIdOf<T>, options?: VersionsListOptions): Promise<Version<EntitySelectOf<T>>[]>;
|
|
1586
|
+
get(id: EntityIdOf<T>, versionId: string): Promise<Version<EntitySelectOf<T>>>;
|
|
1587
|
+
restore(id: EntityIdOf<T>, versionId: string, options?: VersionsRestoreOptions): Promise<EntityRowOf<T>>;
|
|
1588
|
+
diff(id: EntityIdOf<T>, from: string, to: string): Promise<FieldDiff<EntitySelectOf<T>>[]>;
|
|
1589
|
+
};
|
|
1590
|
+
};
|
|
1591
|
+
type IdInput<T extends EntityTraits> = {
|
|
1592
|
+
id: EntityIdOf<T>;
|
|
1593
|
+
};
|
|
1594
|
+
type Named<T extends EntityTraits> = T['name'] & string;
|
|
1595
|
+
type ListInput<T extends EntityTraits> = IdInput<T> & VersionsListOptions;
|
|
1596
|
+
type GetInput<T extends EntityTraits> = IdInput<T> & {
|
|
1597
|
+
versionId: string;
|
|
1598
|
+
};
|
|
1599
|
+
type RestoreInput<T extends EntityTraits> = GetInput<T> & VersionsRestoreOptions;
|
|
1600
|
+
type DiffInput<T extends EntityTraits> = IdInput<T> & {
|
|
1601
|
+
from: string;
|
|
1602
|
+
to: string;
|
|
1603
|
+
};
|
|
1604
|
+
type DraftsQueries<T extends EntityTraits> = {
|
|
1605
|
+
publish(input: IdInput<T>): Descriptor<Named<T>, 'publish', IdInput<T>, EntityRowOf<T>>;
|
|
1606
|
+
unpublish(input: IdInput<T>): Descriptor<Named<T>, 'unpublish', IdInput<T>, EntityRowOf<T>>;
|
|
1607
|
+
discardDraft(input: IdInput<T>): Descriptor<Named<T>, 'discardDraft', IdInput<T>, EntityRowOf<T>>;
|
|
1608
|
+
};
|
|
1609
|
+
type HistoryQueries<T extends EntityTraits> = {
|
|
1610
|
+
versions: {
|
|
1611
|
+
list(input: ListInput<T>): Descriptor<Named<T>, 'versions.list', ListInput<T>, Version<EntitySelectOf<T>>[]>;
|
|
1612
|
+
get(input: GetInput<T>): Descriptor<Named<T>, 'versions.get', GetInput<T>, Version<EntitySelectOf<T>>>;
|
|
1613
|
+
restore(input: RestoreInput<T>): Descriptor<Named<T>, 'versions.restore', RestoreInput<T>, EntityRowOf<T>>;
|
|
1614
|
+
diff(input: DiffInput<T>): Descriptor<Named<T>, 'versions.diff', DiffInput<T>, FieldDiff<EntitySelectOf<T>>[]>;
|
|
1615
|
+
};
|
|
1616
|
+
};
|
|
1617
|
+
interface VersionsTraits extends EntityTraits {
|
|
1618
|
+
readonly entityOptions: VersionsEntityOptions<EntityTableOf<this>>;
|
|
1619
|
+
readonly governs: Drafts;
|
|
1620
|
+
readonly managed: this['given'] extends Drafts ? 'status' | 'publishedAt' : never;
|
|
1621
|
+
readonly optionsOn: this['given'] extends Drafts ? 'read' | 'create' | 'update' : never;
|
|
1622
|
+
readonly optionTypes: {
|
|
1623
|
+
read: VersionsReadOptions;
|
|
1624
|
+
create: VersionsCreateOptions;
|
|
1625
|
+
update: VersionsUpdateOptions;
|
|
1626
|
+
};
|
|
1627
|
+
readonly operations: 'publish' | 'unpublish' | 'discardDraft' | 'versions.restore';
|
|
1628
|
+
readonly rules: {
|
|
1629
|
+
readDrafts: 'filter';
|
|
1630
|
+
readVersions: 'boolean';
|
|
1631
|
+
publish: 'filter';
|
|
1632
|
+
};
|
|
1633
|
+
readonly rulesOn: this['given'] extends Drafts ? 'readDrafts' | 'readVersions' | 'publish' : this['given'] extends Versioned ? 'readVersions' : never;
|
|
1634
|
+
readonly hookArgs: VersionsHookArgs<this['row']>;
|
|
1635
|
+
readonly api: this['given'] extends Drafts ? DraftsApi<this> & HistoryApi<this> : this['given'] extends Versioned ? HistoryApi<this> : {};
|
|
1636
|
+
readonly queries: this['given'] extends Drafts ? DraftsQueries<this> & HistoryQueries<this> : this['given'] extends Versioned ? HistoryQueries<this> : {};
|
|
1637
|
+
}
|
|
1638
|
+
//#endregion
|
|
1639
|
+
//#region src/types/hooks.d.ts
|
|
1640
|
+
type ChangeOp = 'create' | 'update';
|
|
1641
|
+
type Select_<R extends AnyRelations, N extends keyof R> = Assume<R[N]['table'], {
|
|
1642
|
+
$inferSelect: Record<string, unknown>;
|
|
1643
|
+
}>['$inferSelect'];
|
|
1644
|
+
type Insert_<R extends AnyRelations, N extends keyof R> = Assume<R[N]['table'], {
|
|
1645
|
+
$inferInsert: Record<string, unknown>;
|
|
1646
|
+
}>['$inferInsert'];
|
|
1647
|
+
type CreateInput_<R extends AnyRelations, N extends keyof R> = Insert_<R, N>;
|
|
1648
|
+
type UpdateInput_<R extends AnyRelations, N extends keyof R> = Partial<Insert_<R, N>>;
|
|
1649
|
+
type HookBase<R extends AnyRelations, Ctx, TApp = TypionHookApp<R, Ctx>> = {
|
|
1650
|
+
ctx: Ctx;
|
|
1651
|
+
meta: OperationMeta;
|
|
1652
|
+
typion: TApp;
|
|
1653
|
+
tx: PgAsyncTransaction<PgQueryResultHKT, any>;
|
|
1654
|
+
bag: Map<string, unknown>;
|
|
1655
|
+
};
|
|
1656
|
+
interface TypionHookEntityApi<R extends AnyRelations, N extends keyof R & string> {
|
|
1657
|
+
find<const C extends DBQueryConfig<'many', R, R[N]>>(config?: KnownKeysOnly<C, DBQueryConfig<'many', R, R[N]>>): Promise<BuildQueryResult<R, R[N], C>[]>;
|
|
1658
|
+
findOne<const C extends DBQueryConfig<'one', R, R[N]>>(config?: KnownKeysOnly<C, DBQueryConfig<'one', R, R[N]>>): Promise<BuildQueryResult<R, R[N], C> | null>;
|
|
1659
|
+
findById<const C extends Omit<DBQueryConfig<'one', R, R[N]>, 'where' | 'offset'>>(id: unknown, config?: C): Promise<BuildQueryResult<R, R[N], C>>;
|
|
1660
|
+
count(config?: {
|
|
1661
|
+
where?: RawWhere<R, N>;
|
|
1662
|
+
}): Promise<number>;
|
|
1663
|
+
create(data: Insert_<R, N>): Promise<Select_<R, N>>;
|
|
1664
|
+
update(id: unknown, data: Partial<Insert_<R, N>>): Promise<Select_<R, N>>;
|
|
1665
|
+
updateMany(where: RawWhere<R, N>, data: Partial<Insert_<R, N>>, options?: {
|
|
1666
|
+
max?: number;
|
|
1667
|
+
}): Promise<{
|
|
1668
|
+
count: number;
|
|
1669
|
+
}>;
|
|
1670
|
+
delete(id: unknown, options?: Readonly<Record<string, unknown>>): Promise<Select_<R, N>>;
|
|
1671
|
+
deleteMany(where: RawWhere<R, N>, options?: {
|
|
1672
|
+
max?: number;
|
|
1673
|
+
} & Readonly<Record<string, unknown>>): Promise<{
|
|
1674
|
+
count: number;
|
|
1675
|
+
}>;
|
|
1676
|
+
}
|
|
1677
|
+
type TypionHookApp<R extends AnyRelations, Ctx> = { [N in keyof R & string]: TypionHookEntityApi<R, N>; } & {
|
|
1678
|
+
readonly $ctx: Ctx;
|
|
1679
|
+
readonly $mode: TypionMode;
|
|
1680
|
+
$transaction<T>(fn: (e: TypionHookApp<R, Ctx>) => Promise<T>): Promise<T>;
|
|
1681
|
+
};
|
|
1682
|
+
type ChangeArgs<S, CI, UI, TOps extends string = never, TArgs = {}> = ({
|
|
1683
|
+
op: 'create';
|
|
1684
|
+
data: CI;
|
|
1685
|
+
original: null;
|
|
1686
|
+
} | {
|
|
1687
|
+
op: 'update' | TOps;
|
|
1688
|
+
data: UI;
|
|
1689
|
+
original: S;
|
|
1690
|
+
}) & TArgs;
|
|
1691
|
+
type AfterChangeArgs<S, TOps extends string = never, TArgs = {}> = {
|
|
1692
|
+
op: ChangeOp | TOps;
|
|
1693
|
+
doc: S;
|
|
1694
|
+
previous: S | null;
|
|
1695
|
+
changes: readonly (keyof S & string)[];
|
|
1696
|
+
} & TArgs;
|
|
1697
|
+
type EntityHooks<R extends AnyRelations, N extends keyof R & string, Ctx, P extends readonly unknown[] = readonly [], TApp = TypionHookApp<R, Ctx>, S = Select_<R, N>, CI = CreateInput_<R, N>, UI = UpdateInput_<R, N>, TOps extends string = TraitOperationNames<P>, TDelete = AllTraitOptions<P, 'delete'>, TChange = TraitHookArgs<P, S, 'change'>, TAfterChange = TraitHookArgs<P, S, 'afterChange'>, TAfterDelete = TraitHookArgs<P, S, 'afterDelete'>> = {
|
|
1698
|
+
beforeValidate?: (a: ChangeArgs<S, CI, UI, TOps, TChange> & HookBase<R, Ctx, TApp>) => MaybePromise<CI | UI | void>;
|
|
1699
|
+
beforeChange?: (a: ChangeArgs<S, CI, UI, TOps, TChange> & HookBase<R, Ctx, TApp>) => MaybePromise<CI | UI | void>;
|
|
1700
|
+
afterChange?: (a: AfterChangeArgs<S, TOps, TChange & TAfterChange> & HookBase<R, Ctx, TApp>) => MaybePromise<void>;
|
|
1701
|
+
beforeDelete?: (a: {
|
|
1702
|
+
doc: S;
|
|
1703
|
+
options: TDelete;
|
|
1704
|
+
} & HookBase<R, Ctx, TApp>) => MaybePromise<void>;
|
|
1705
|
+
afterDelete?: (a: {
|
|
1706
|
+
doc: S;
|
|
1707
|
+
options: TDelete;
|
|
1708
|
+
} & TAfterDelete & HookBase<R, Ctx, TApp>) => MaybePromise<void>;
|
|
1709
|
+
afterCommit?: (a: {
|
|
1710
|
+
op: Operation;
|
|
1711
|
+
doc: S | null;
|
|
1712
|
+
previous: S | null;
|
|
1713
|
+
ctx: Ctx;
|
|
1714
|
+
meta: OperationMeta;
|
|
1715
|
+
}) => MaybePromise<void>;
|
|
1716
|
+
};
|
|
1717
|
+
type AnyRow$1 = Record<string, unknown>;
|
|
1718
|
+
type PluginArgs = Readonly<Record<string, unknown>>;
|
|
1719
|
+
type CoreArgs = VersionsHookArgs<AnyRow$1>;
|
|
1720
|
+
type GlobalHookBase = HookBase<AnyRelations, any> & {
|
|
1721
|
+
entityMeta: EntityMeta;
|
|
1722
|
+
};
|
|
1723
|
+
type GlobalHooks = {
|
|
1724
|
+
entities?: readonly string[];
|
|
1725
|
+
beforeOperation?: (a: {
|
|
1726
|
+
entity: string;
|
|
1727
|
+
op: Operation;
|
|
1728
|
+
args: unknown;
|
|
1729
|
+
} & GlobalHookBase) => MaybePromise<void>;
|
|
1730
|
+
beforeChange?: (a: {
|
|
1731
|
+
entity: string;
|
|
1732
|
+
} & ChangeArgs<AnyRow$1, AnyRow$1, AnyRow$1, string, PluginArgs & CoreArgs['change']> & GlobalHookBase) => MaybePromise<AnyRow$1 | void>;
|
|
1733
|
+
afterChange?: (a: {
|
|
1734
|
+
entity: string;
|
|
1735
|
+
} & AfterChangeArgs<AnyRow$1, string, PluginArgs & CoreArgs['change'] & CoreArgs['afterChange']> & GlobalHookBase) => MaybePromise<void>;
|
|
1736
|
+
afterDelete?: (a: {
|
|
1737
|
+
entity: string;
|
|
1738
|
+
doc: AnyRow$1;
|
|
1739
|
+
previous: AnyRow$1;
|
|
1740
|
+
removed: boolean;
|
|
1741
|
+
options: Readonly<Record<string, unknown>>;
|
|
1742
|
+
} & PluginArgs & CoreArgs['afterDelete'] & GlobalHookBase) => MaybePromise<void>;
|
|
1743
|
+
afterOperation?: (a: {
|
|
1744
|
+
entity: string;
|
|
1745
|
+
op: Operation;
|
|
1746
|
+
result: unknown;
|
|
1747
|
+
} & GlobalHookBase) => MaybePromise<void>;
|
|
1748
|
+
afterLink?: (a: {
|
|
1749
|
+
entity: string;
|
|
1750
|
+
op: 'link' | 'unlink';
|
|
1751
|
+
doc: AnyRow$1;
|
|
1752
|
+
relation: string;
|
|
1753
|
+
ids: readonly unknown[];
|
|
1754
|
+
} & GlobalHookBase) => MaybePromise<void>;
|
|
1755
|
+
afterCommit?: (a: {
|
|
1756
|
+
entity: string;
|
|
1757
|
+
op: Operation;
|
|
1758
|
+
doc: AnyRow$1 | null;
|
|
1759
|
+
previous: AnyRow$1 | null;
|
|
1760
|
+
ctx: any;
|
|
1761
|
+
meta: OperationMeta;
|
|
1762
|
+
}) => MaybePromise<void>;
|
|
1763
|
+
};
|
|
1764
|
+
//#endregion
|
|
1765
|
+
//#region src/types/access.d.ts
|
|
1766
|
+
type RuleSchema<R extends AnyRelations, P extends readonly unknown[]> = { [K in keyof R]: {
|
|
1767
|
+
table: VirtualTable<Assume<R[K]['table'], PgTable>, TableMode<Assume<R[K]['table'], PgTable>, InputModeOf<P>>, never, never>;
|
|
1768
|
+
name: R[K]['name'];
|
|
1769
|
+
relations: R[K]['relations'];
|
|
1770
|
+
}; };
|
|
1771
|
+
type RuleData<R extends AnyRelations, N extends keyof R> = { [K in keyof Insert_<R, N>]: [KindOf<NonNullable<Insert_<R, N>[K]>>] extends [never] ? Insert_<R, N>[K] : unknown; };
|
|
1772
|
+
type RawWhere<R extends AnyRelations, N extends keyof R, P extends readonly unknown[] = readonly []> = RelationsFilter<RuleSchema<R, P>[N], RuleSchema<R, P>>;
|
|
1773
|
+
type Operation = 'find' | 'findOne' | 'findById' | 'count' | 'page' | 'create' | 'update' | 'updateMany' | 'delete' | 'deleteMany' | (string & {});
|
|
1774
|
+
interface OperationMeta {
|
|
1775
|
+
readonly entity: string;
|
|
1776
|
+
readonly operation: Operation;
|
|
1777
|
+
readonly mode: TypionMode;
|
|
1778
|
+
readonly requestId: string;
|
|
1779
|
+
readonly now: Date;
|
|
1780
|
+
readonly systemReason: string | null;
|
|
1781
|
+
}
|
|
1782
|
+
type RuleArgs<R extends AnyRelations, Ctx, TApp = TypionHookApp<R, Ctx>> = {
|
|
1783
|
+
ctx: Ctx;
|
|
1784
|
+
meta: OperationMeta;
|
|
1785
|
+
typion: TApp;
|
|
1786
|
+
};
|
|
1787
|
+
type FilterRule<R extends AnyRelations, N extends keyof R, Ctx, TApp, P extends readonly unknown[], Extra = {}> = boolean | RawWhere<R, N, P> | ((a: RuleArgs<R, Ctx, TApp> & Extra) => MaybePromise<boolean | RawWhere<R, N, P>>);
|
|
1788
|
+
type BooleanRule<R extends AnyRelations, Ctx, TApp> = boolean | ((a: RuleArgs<R, Ctx, TApp>) => MaybePromise<boolean>);
|
|
1789
|
+
type PluginRules<R extends AnyRelations, N extends keyof R & string, Ctx, TApp, P extends readonly unknown[], TRules> = { [K in keyof TRules]?: TRules[K] extends 'boolean' ? BooleanRule<R, Ctx, TApp> : FilterRule<R, N, Ctx, TApp, P>; };
|
|
1790
|
+
type AccessRules<R extends AnyRelations, N extends keyof R & string, Ctx, P extends readonly unknown[] = readonly [], TApp = TypionHookApp<R, Ctx>, TRules = AllTraitRules<P>> = {
|
|
1791
|
+
read?: FilterRule<R, N, Ctx, TApp, P>;
|
|
1792
|
+
create?: boolean | ((a: RuleArgs<R, Ctx, TApp> & {
|
|
1793
|
+
data: RuleData<R, N>;
|
|
1794
|
+
}) => MaybePromise<boolean>);
|
|
1795
|
+
update?: FilterRule<R, N, Ctx, TApp, P, {
|
|
1796
|
+
data: Partial<RuleData<R, N>>;
|
|
1797
|
+
}>;
|
|
1798
|
+
delete?: FilterRule<R, N, Ctx, TApp, P, {
|
|
1799
|
+
options: AllTraitOptions<P, 'delete'>;
|
|
1800
|
+
}>;
|
|
1801
|
+
} & PluginRules<R, N, Ctx, TApp, P, TRules>;
|
|
1802
|
+
type AnyAccessRules = Readonly<Record<string, unknown>>;
|
|
1803
|
+
type AllowAll = {
|
|
1804
|
+
read: true;
|
|
1805
|
+
create: true;
|
|
1806
|
+
update: true;
|
|
1807
|
+
delete: true;
|
|
1808
|
+
};
|
|
1809
|
+
//#endregion
|
|
1810
|
+
//#region src/types/meta.d.ts
|
|
1811
|
+
interface ColumnMeta {
|
|
1812
|
+
readonly key: string;
|
|
1813
|
+
readonly name: string;
|
|
1814
|
+
readonly column: AnyPgColumn;
|
|
1815
|
+
readonly dataType: string;
|
|
1816
|
+
readonly columnType: string;
|
|
1817
|
+
readonly notNull: boolean;
|
|
1818
|
+
readonly hasDefault: boolean;
|
|
1819
|
+
readonly generated: boolean;
|
|
1820
|
+
readonly enumValues: readonly string[] | undefined;
|
|
1821
|
+
readonly kind: string | null;
|
|
1822
|
+
readonly columnKind: ColumnKindRuntime | null;
|
|
1823
|
+
readonly read: true | false | ((a: FieldRuleArgs<any>) => boolean);
|
|
1824
|
+
readonly write: 'user' | 'system' | false | ((a: FieldRuleArgs<any>) => boolean);
|
|
1825
|
+
}
|
|
1826
|
+
interface RelationMeta {
|
|
1827
|
+
readonly key: string;
|
|
1828
|
+
readonly target: string;
|
|
1829
|
+
readonly type: 'one' | 'many';
|
|
1830
|
+
readonly optional: boolean;
|
|
1831
|
+
readonly through: boolean;
|
|
1832
|
+
}
|
|
1833
|
+
interface EntityMeta {
|
|
1834
|
+
readonly name: string;
|
|
1835
|
+
readonly table: PgTable;
|
|
1836
|
+
readonly tableName: string;
|
|
1837
|
+
readonly pgSchema: string | undefined;
|
|
1838
|
+
readonly pk: ColumnMeta;
|
|
1839
|
+
readonly columns: Readonly<Record<string, ColumnMeta>>;
|
|
1840
|
+
readonly visibleKeys: readonly string[];
|
|
1841
|
+
readonly kindKeys: readonly string[];
|
|
1842
|
+
readonly dynamicReadKeys: readonly string[];
|
|
1843
|
+
readonly managedKeys: readonly string[];
|
|
1844
|
+
readonly relations: Readonly<Record<string, RelationMeta>>;
|
|
1845
|
+
readonly links: ReadonlySet<string>;
|
|
1846
|
+
readonly traits: Readonly<Record<string, EntityTrait>>;
|
|
1847
|
+
readonly access: AnyAccessRules;
|
|
1848
|
+
readonly hooks: EntityHooks<AnyRelations, string, any>;
|
|
1849
|
+
readonly validate: {
|
|
1850
|
+
insert?: StandardSchemaV1;
|
|
1851
|
+
update?: StandardSchemaV1;
|
|
1852
|
+
fields?: Record<string, unknown>;
|
|
1853
|
+
} | null;
|
|
1854
|
+
readonly defaultOrder: Readonly<Record<string, 'asc' | 'desc'>> | null;
|
|
1855
|
+
readonly maxLimit: number;
|
|
1856
|
+
readonly pluginOptions: Readonly<Record<string, unknown>>;
|
|
1857
|
+
readonly owner: 'user' | {
|
|
1858
|
+
readonly plugin: string;
|
|
1859
|
+
};
|
|
1860
|
+
}
|
|
1861
|
+
interface TypionDefinition<TE extends TypionTypes> {
|
|
1862
|
+
readonly $types: TE;
|
|
1863
|
+
readonly relations: TE['relations'];
|
|
1864
|
+
readonly schema: Readonly<Record<string, PgTable | PgEnum<any> | PgSchema<string>>>;
|
|
1865
|
+
readonly generated: GeneratedTables<TE> & {
|
|
1866
|
+
readonly $names: readonly string[];
|
|
1867
|
+
};
|
|
1868
|
+
readonly entities: Readonly<Record<EntityName<TE>, EntityMeta>>;
|
|
1869
|
+
readonly plugins: readonly PluginRuntime[];
|
|
1870
|
+
readonly pgSchema: PgSchema<string>;
|
|
1871
|
+
readonly maxLimit: number;
|
|
1872
|
+
readonly validation: ValidationAdapter | null;
|
|
1873
|
+
}
|
|
1874
|
+
type GeneratedTables<TE extends TypionTypes> = PluginTables<TE['plugins']> & Readonly<Record<string, PgTable>>;
|
|
1875
|
+
//#endregion
|
|
1876
|
+
//#region src/types/runtime.d.ts
|
|
1877
|
+
type AnyDb = PgAsyncDatabase<PgQueryResultHKT, AnyRelations>;
|
|
1878
|
+
type AnyTx = PgAsyncTransaction<PgQueryResultHKT, AnyRelations>;
|
|
1879
|
+
type AnyRow = Record<string, unknown>;
|
|
1880
|
+
interface AfterCommitQueue {
|
|
1881
|
+
readonly size: number;
|
|
1882
|
+
flush(): Promise<void>;
|
|
1883
|
+
discard(): void;
|
|
1884
|
+
}
|
|
1885
|
+
interface AnyTypionApp {
|
|
1886
|
+
readonly $ctx: BaseContext & Record<string, unknown>;
|
|
1887
|
+
readonly $mode: TypionMode;
|
|
1888
|
+
readonly $tx: AnyTx | null;
|
|
1889
|
+
readonly $engine: AnyTypion;
|
|
1890
|
+
readonly $executor: AnyDb | AnyTx;
|
|
1891
|
+
$run(descriptor: AnyDescriptor, extend?: Record<string, unknown>): Promise<unknown>;
|
|
1892
|
+
$transaction<T>(fn: (bound: AnyTypionApp) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
|
|
1893
|
+
$withTx(tx: AnyTx): AnyTypionApp;
|
|
1894
|
+
readonly $afterCommit: AfterCommitQueue;
|
|
1895
|
+
entity(name: string): Record<string, unknown>;
|
|
1896
|
+
}
|
|
1897
|
+
interface AnyTypion {
|
|
1898
|
+
readonly $def: TypionDefinition<any>;
|
|
1899
|
+
readonly $db: AnyDb;
|
|
1900
|
+
readonly $dialect: Dialect;
|
|
1901
|
+
readonly $plugins: Record<string, unknown>;
|
|
1902
|
+
$as(ctx: object, opts?: {
|
|
1903
|
+
request?: Request;
|
|
1904
|
+
meta?: Record<string, unknown>;
|
|
1905
|
+
} & Record<string, unknown>): AnyTypionApp;
|
|
1906
|
+
$system(opts: {
|
|
1907
|
+
reason: string;
|
|
1908
|
+
ctx?: object;
|
|
1909
|
+
meta?: Record<string, unknown>;
|
|
1910
|
+
} & Record<string, unknown>): AnyTypionApp;
|
|
1911
|
+
$fromRequest(request: Request, opts?: Record<string, unknown>): Promise<AnyTypionApp>;
|
|
1912
|
+
$execute(descriptor: AnyDescriptor, bound: AnyTypionApp): Promise<unknown>;
|
|
1913
|
+
}
|
|
1914
|
+
interface ValidationAdapter {
|
|
1915
|
+
readonly id: 'structural' | 'zod' | 'valibot' | 'arktype';
|
|
1916
|
+
base(entity: EntityMeta, mode: 'insert' | 'update' | 'select', refinements: Record<string, unknown> | undefined): StandardSchemaV1;
|
|
1917
|
+
}
|
|
1918
|
+
//#endregion
|
|
1919
|
+
//#region src/types/dialect.d.ts
|
|
1920
|
+
type SchemaDrift = {
|
|
1921
|
+
missingTables: string[];
|
|
1922
|
+
missingColumns: {
|
|
1923
|
+
table: string;
|
|
1924
|
+
columns: string[];
|
|
1925
|
+
}[];
|
|
1926
|
+
};
|
|
1927
|
+
interface Dialect {
|
|
1928
|
+
readonly id: 'pg';
|
|
1929
|
+
jsonText(column: AnyPgColumn | SQL, key: string): SQL;
|
|
1930
|
+
cast(value: SQL, type: string): SQL;
|
|
1931
|
+
jsonbMerge(column: AnyPgColumn, patch: unknown): SQL;
|
|
1932
|
+
jsonParam(value: unknown, column: AnyPgColumn): SQL;
|
|
1933
|
+
lockSelect(tx: AnyTx, table: PgTable, where: SQL | undefined): Promise<Record<string, unknown>[]>;
|
|
1934
|
+
mapError(error: unknown): TypionError | null;
|
|
1935
|
+
introspect(db: AnyDb, tables: readonly PgTable[]): Promise<SchemaDrift>;
|
|
1936
|
+
}
|
|
1937
|
+
//#endregion
|
|
1938
|
+
//#region src/contract/errors.d.ts
|
|
1939
|
+
declare const ERROR_STATUS: {
|
|
1940
|
+
readonly NOT_FOUND: 404;
|
|
1941
|
+
readonly FORBIDDEN: 403;
|
|
1942
|
+
readonly VALIDATION: 422;
|
|
1943
|
+
readonly CONFLICT: 409;
|
|
1944
|
+
readonly INVALID_STATE: 409;
|
|
1945
|
+
readonly BAD_REQUEST: 400;
|
|
1946
|
+
readonly UNSUPPORTED: 400;
|
|
1947
|
+
readonly PLUGIN: 500;
|
|
1948
|
+
readonly CONFIG: 500;
|
|
1949
|
+
readonly INTERNAL: 500;
|
|
1950
|
+
};
|
|
1951
|
+
type ErrorStatus = (typeof ERROR_STATUS)[TypionErrorCode];
|
|
1952
|
+
type WireIssue = {
|
|
1953
|
+
readonly path: readonly (string | number)[];
|
|
1954
|
+
readonly message: string;
|
|
1955
|
+
};
|
|
1956
|
+
type WireErrorCode = TypionErrorCode | 'UNAUTHENTICATED';
|
|
1957
|
+
type WireError = {
|
|
1958
|
+
readonly code: WireErrorCode;
|
|
1959
|
+
readonly status: number;
|
|
1960
|
+
readonly message: string;
|
|
1961
|
+
readonly entity?: string;
|
|
1962
|
+
readonly issues?: readonly WireIssue[];
|
|
1963
|
+
readonly details?: Record<string, unknown>;
|
|
1964
|
+
};
|
|
1965
|
+
type WireErrorEnvelope = {
|
|
1966
|
+
readonly error: WireError;
|
|
1967
|
+
};
|
|
1968
|
+
type WireDataEnvelope<T> = {
|
|
1969
|
+
readonly data: T;
|
|
1970
|
+
};
|
|
1971
|
+
type WireEnvelope<T> = WireDataEnvelope<T> | WireErrorEnvelope;
|
|
1972
|
+
type WireBatchEnvelope<T = unknown> = {
|
|
1973
|
+
readonly results: readonly WireEnvelope<T>[];
|
|
1974
|
+
};
|
|
1975
|
+
//#endregion
|
|
1976
|
+
//#region src/http/transport.d.ts
|
|
1977
|
+
type CheckedDescriptor = AnyDescriptor & {
|
|
1978
|
+
readonly '~checked': true;
|
|
1979
|
+
};
|
|
1980
|
+
interface Transport {
|
|
1981
|
+
readonly name: string;
|
|
1982
|
+
handle(call: TransportCall): Promise<Response | undefined> | Response | undefined;
|
|
1983
|
+
}
|
|
1984
|
+
interface TransportCall {
|
|
1985
|
+
readonly request: Request;
|
|
1986
|
+
readonly url: URL;
|
|
1987
|
+
readonly method: string;
|
|
1988
|
+
readonly segments: readonly string[];
|
|
1989
|
+
readonly schema: TransportSchema;
|
|
1990
|
+
body(): Promise<unknown>;
|
|
1991
|
+
descriptor(raw: unknown): CheckedDescriptor;
|
|
1992
|
+
run(descriptor: CheckedDescriptor): Promise<unknown>;
|
|
1993
|
+
respond(status: number, payload: unknown): Response;
|
|
1994
|
+
error(error: unknown): WireError;
|
|
1995
|
+
}
|
|
1996
|
+
interface TransportSchema {
|
|
1997
|
+
readonly maxLimit: number;
|
|
1998
|
+
entity(name: string): TransportEntity | null;
|
|
1999
|
+
readonly readOptions: ReadonlyMap<string, OptionType>;
|
|
2000
|
+
readonly deleteOptions: ReadonlyMap<string, OptionType>;
|
|
2001
|
+
}
|
|
2002
|
+
interface TransportEntity {
|
|
2003
|
+
readonly name: string;
|
|
2004
|
+
readonly operations: readonly TransportOperation[];
|
|
2005
|
+
}
|
|
2006
|
+
interface TransportOperation {
|
|
2007
|
+
readonly name: string;
|
|
2008
|
+
readonly args: readonly string[];
|
|
2009
|
+
readonly options: Readonly<Record<string, OptionType>>;
|
|
2010
|
+
readonly route: {
|
|
2011
|
+
readonly method: string;
|
|
2012
|
+
readonly path: string;
|
|
2013
|
+
} | undefined;
|
|
2014
|
+
}
|
|
2015
|
+
//#endregion
|
|
2016
|
+
//#region src/types/engine.d.ts
|
|
2017
|
+
interface TypionTypes {
|
|
2018
|
+
ctx: object;
|
|
2019
|
+
tables: Record<string, PgTable | PgEnum<any>>;
|
|
2020
|
+
plugins: readonly AnyPlugin[];
|
|
2021
|
+
entities: AnyEntities;
|
|
2022
|
+
relations: AnyRelations;
|
|
2023
|
+
}
|
|
2024
|
+
type EntityName<TE extends TypionTypes> = keyof TE['entities'] & keyof TE['relations'] & string;
|
|
2025
|
+
type BindOptions<TE extends TypionTypes> = {
|
|
2026
|
+
request?: Request;
|
|
2027
|
+
meta?: Record<string, unknown>;
|
|
2028
|
+
} & PluginContextOptions<TE['plugins']>;
|
|
2029
|
+
type DescriptorApi<TE extends TypionTypes, N extends EntityName<TE>> = Pick<EntityApi<TE, N, 'user'>, 'query' | 'queryOne'>;
|
|
2030
|
+
type CorsOptions = {
|
|
2031
|
+
origin?: string | readonly string[] | ((origin: string) => boolean);
|
|
2032
|
+
methods?: readonly string[];
|
|
2033
|
+
headers?: readonly string[];
|
|
2034
|
+
credentials?: boolean;
|
|
2035
|
+
maxAge?: number;
|
|
2036
|
+
};
|
|
2037
|
+
type HandlerOptions<TE extends TypionTypes> = {
|
|
2038
|
+
transports: readonly Transport[];
|
|
2039
|
+
basePath?: string;
|
|
2040
|
+
expose?: readonly EntityName<TE>[];
|
|
2041
|
+
exclude?: readonly EntityName<TE>[];
|
|
2042
|
+
exposeBulk?: boolean;
|
|
2043
|
+
maxLimit?: number;
|
|
2044
|
+
maxDepth?: number;
|
|
2045
|
+
codecs?: readonly ('json' | 'superjson')[];
|
|
2046
|
+
cors?: CorsOptions;
|
|
2047
|
+
debug?: boolean;
|
|
2048
|
+
onError?: (error: unknown) => void;
|
|
2049
|
+
};
|
|
2050
|
+
type TypionApp<TE extends TypionTypes, TMode extends TypionMode> = { [N in EntityName<TE>]: EntityApi<TE, N, TMode> & TraitApi<TE, N, TMode> & LinkApi<TE, N>; } & {
|
|
2051
|
+
readonly $ctx: Ctx<TE>;
|
|
2052
|
+
readonly $mode: TMode;
|
|
2053
|
+
readonly $tx: PgAsyncTransaction<PgQueryResultHKT, TE['relations']> | null;
|
|
2054
|
+
$run<D extends AnyDescriptor>(descriptor: D, extend?: Extend<TE, D['entity'] & EntityName<TE>>): Promise<InferResult<D>>;
|
|
2055
|
+
$transaction<T>(fn: (app: TypionApp<TE, TMode>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
|
|
2056
|
+
readonly $afterCommit: AfterCommitQueue;
|
|
2057
|
+
readonly $plugins: PluginApis<TE['plugins']>;
|
|
2058
|
+
};
|
|
2059
|
+
type TypionEngine<TE extends TypionTypes> = { [N in EntityName<TE>]: DescriptorApi<TE, N>; } & {
|
|
2060
|
+
$as(ctx: TE['ctx'], opts?: BindOptions<TE>): TypionApp<TE, 'user'>;
|
|
2061
|
+
$system(opts: {
|
|
2062
|
+
reason: string;
|
|
2063
|
+
ctx?: Partial<TE['ctx']>;
|
|
2064
|
+
meta?: Record<string, unknown>;
|
|
2065
|
+
} & PluginContextOptions<TE['plugins']> & PluginSystemOptions<TE['plugins']>): TypionApp<TE, 'system'>;
|
|
2066
|
+
$fromRequest(request: Request, opts?: PluginContextOptions<TE['plugins']>): Promise<TypionApp<TE, 'user'>>;
|
|
2067
|
+
$fromHeaders(headers: Headers, opts?: PluginContextOptions<TE['plugins']>): Promise<TypionApp<TE, 'user'>>;
|
|
2068
|
+
$withTx(ctx: TE['ctx'], tx: PgAsyncTransaction<PgQueryResultHKT, TE['relations']>): TypionApp<TE, 'user'>;
|
|
2069
|
+
$execute<D extends AnyDescriptor>(descriptor: D, bound: TypionApp<TE, TypionMode>): Promise<InferResult<D>>;
|
|
2070
|
+
readonly $plugins: PluginApis<TE['plugins']>;
|
|
2071
|
+
readonly $def: TypionDefinition<TE>;
|
|
2072
|
+
readonly $db: PgAsyncDatabase<PgQueryResultHKT, TE['relations']>;
|
|
2073
|
+
readonly $dialect: Dialect;
|
|
2074
|
+
};
|
|
2075
|
+
//#endregion
|
|
2076
|
+
//#region src/types/context.d.ts
|
|
2077
|
+
type TypionMode = 'user' | 'system';
|
|
2078
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
2079
|
+
type BaseContext = {
|
|
2080
|
+
readonly mode: TypionMode;
|
|
2081
|
+
readonly now: Date;
|
|
2082
|
+
readonly requestId: string;
|
|
2083
|
+
readonly request: Request | null;
|
|
2084
|
+
readonly actorId: string | null;
|
|
2085
|
+
readonly systemReason: string | null;
|
|
2086
|
+
readonly meta: Record<string, unknown>;
|
|
2087
|
+
};
|
|
2088
|
+
type ContextInput = {
|
|
2089
|
+
request?: Request;
|
|
2090
|
+
headers?: Headers;
|
|
2091
|
+
options?: Readonly<Record<string, unknown>>;
|
|
2092
|
+
callerLookup?: boolean;
|
|
2093
|
+
};
|
|
2094
|
+
type Ctx<TE extends TypionTypes> = BaseContext & TE['ctx'] & PluginContext<TE['plugins']>;
|
|
2095
|
+
type FullCtx<TCtx extends object, P extends readonly AnyPlugin[]> = BaseContext & TCtx & PluginContext<P>;
|
|
2096
|
+
//#endregion
|
|
2097
|
+
export { AfterChangeArgs as $, InferResult as $a, RequirementsError as $i, MultiTenantPlugin as $n, NullableTimestampKeys as $r, RegisteredContext as $t, Dialect as A, ConfigError as Aa, CollectionSpec as Ai, defineSetup as An, CreateInput as Ar, VersionsTraits as At, EntityMeta as B, PluginError as Ba, PluginContext as Bi, SoftDeleteKinds as Bn, FieldRefinements as Br, ConfigOptions as Bt, WireBatchEnvelope as C, ReadModeOf as Ca, VirtualColumn as Ci, AnySetup as Cn, Jsonified as Cr, VersionsEntityOptions as Ct, WireErrorCode as D, WriteModeOf as Da, AnyPlugin as Di, SetupOptions as Dn, TraitQueries as Dr, VersionsOption as Dt, WireError as E, WriteModeFn as Ea, AnyFeatureTables as Ei, SetupLocalization as En, TraitOptions as Er, VersionsListOptions as Et, AnyTx as F, ForbiddenError as Fa, MergeAll as Fi, versionsTable as Fn, EntityDef as Fr, ByName as Ft, AllowAll as G, UnsupportedError as Ga, PluginErrorFactories as Gi, softDeleteColumn as Gn, LinkApi as Gr, DbAdapter as Gt, RelationMeta as H, TypionError as Ha, PluginEntityDefiner as Hi, SoftDeleteQueries as Hn, HiddenWriteKeys as Hr, ConfigTables as Ht, AnyTypion as I, ForbiddenErrorOptions as Ia, MergeConfigs as Ii, SoftDeleteApi as In, EntityOptions as Ir, Collection as It, OperationMeta as J, attempt as Ja, PluginNeedsContext as Ji, MultiTenantCollectionOptions as Jn, LinkQueries as Jr, HookTypion as Jt, AnyAccessRules as K, ValidationError as Ka, PluginErrorInput as Ki, softUnique as Kn, LinkInput as Kr, FoldKinds as Kt, AnyTypionApp as L, InternalError as La, Plugin as Li, SoftDeleteCollectionOptions as Ln, EntitySchemas as Lr, CollectionDraft as Lt, AfterCommitQueue as M, ConflictError as Ma, DependenciesError as Mi, FeaturePlugins as Mn, DeleteOptions as Mr, AfterCommitErrorHandler as Mt, AnyDb as N, ConflictErrorOptions as Na, FeatureId as Ni, FeaturesOptions as Nn, EntitiesOf$1 as Nr, AnyCollection as Nt, WireErrorEnvelope as O, Attempt as Oa, AnyPluginSpec as Oi, SetupPlugins as On, AnyEntities as Or, VersionsReadOptions as Ot, AnyRow as P, ConflictKind as Pa, FeatureTables as Pi, VersionsPlugin as Pn, EntityApi as Pr, Behaviour as Pt, RuleSchema as Q, InferItem as Qa, PluginTables as Qi, MultiTenantOptions as Qn, NoneIfEmpty as Qr, OneSpec as Qt, ValidationAdapter as R, InvalidStateError as Ra, PluginApis as Ri, SoftDeleteDeleteOptions as Rn, EntityValidation as Rr, CollectionRuntime as Rt, ErrorStatus as S, ReadModeFn as Sa, VS as Si, defineConfig as Sn, collection as Sr, VersionsCreateOptions as St, WireEnvelope as T, ValidationMode as Ta, VirtualTable as Ti, Setup as Tn, timestamps as Tr, VersionsKinds as Tt, TypionDefinition as U, TypionErrorCode as Ua, PluginEntityOptions as Ui, SoftDeleteReadOptions as Un, Id$1 as Ur, ConfigTypes as Ut, GeneratedTables as V, PluginErrorOptions as Va, PluginEntities as Vi, SoftDeletePlugin as Vn, FieldRuleArgs as Vr, ConfigSeedOptions as Vt, AccessRules as W, TypionErrorOptions as Wa, PluginErrorDef as Wi, SoftDeleteTraits as Wn, Insert as Wr, ContextFactory as Wt, RuleArgs as X, AnyDescriptor as Xa, PluginRuntime as Xi, MultiTenantEntityOptions as Xn, ManagedKeys as Xr, MigrationsOptions as Xt, RawWhere as Y, isTypionError as Ya, PluginRoute as Yi, MultiTenantContext as Yn, LinkQueryMethods as Yr, ManySpec as Yt, RuleData as Z, Descriptor as Za, PluginSpec as Zi, MultiTenantKinds as Zn, NoExtraKeys as Zr, NoUnknownKeys as Zt, TransportCall as _, KindedData as _a, Result as _i, GetTypionOptions as _n, localizedUnique as _r, Version as _t, MaybePromise as a, ColumnKindRuntime as aa, UpdateManyOptions as ai, StructureInput as an, TextTenantColumn as ar, HookBase as at, TransportSchema as b, PluginReadOptions as ba, Governed as bi, allowAll as bn, PluginSpecInput as br, VersionState as bt, CorsOptions as c, ColumnKindsSpec as ca, ByIdConfig as ci, ThroughSpec as cn, LocaleReadMode as cr, TypionHookApp as ct, HandlerOptions as d, KeyedShape as da, FindConfig as di, TypionAppOf as dn, LocalizationPlugin as dr, DraftsApi as dt, SeedColumnsInput as ea, ReadRow as ei, RegisteredPlugins as en, Op as eo, MultiTenantSystemOptions as er, ChangeArgs as et, TypionApp as f, KindOf as fa, FirstConfig as fi, TypionConfig as fn, LocalizationReadMode as fr, DraftsQueries as ft, Transport as g, Kinded as ga, ReadOptions as gi, structuralValidation as gn, localizedIndex as gr, PendingDraftPolicy as gt, CheckedDescriptor as h, KindWriteOptions as ha, Page as hi, StructuralValidationAdapter as hn, localized as hr, HistoryQueries as ht, FullCtx as i, COLUMN_KIND as ia, UpdateInput as ii, RelationSpec as in, descriptor as io, TenantIdOf as ir, GlobalHooks as it, SchemaDrift as j, ConfigErrorKind as ja, ColumnKind as ji, DefaultFeaturePlugins as jn, CreateOptions as jr, VersionsUpdateOptions as jt, WireIssue as k, BadRequestError as ka, CollectionKinds as ki, TypionSetup as kn, ColumnKeys as kr, VersionsRestoreOptions as kt, DescriptorApi as l, ColumnKindsTypes as la, CountConfig as li, TypesOf as ln, LocalizationColumnKinds as lr, TypionHookEntityApi as lt, TypionTypes as m, KindWrite as ma, OrderBy as mi, StructuralSchema as mn, Localized as mr, HistoryApi as mt, ContextInput as n, SeedSpec as na, Row as ni, RegisteredTypes as nn, ReadOp as no, TenantColumnOf as nr, CreateInput_ as nt, TypionMode as o, ColumnKindSpec as oa, UpdateOptions as oi, SystemTypion as on, UuidTenantColumn as or, Insert_ as ot, TypionEngine as p, KindRead as pa, InputSchema as pi, Register as pn, LocalizationWriteMode as pr, FieldDiff as pt, Operation as q, ValidationIssue as qa, PluginKinds as qi, IntegerTenantColumn as qn, LinkMethods as qr, HandlerOptionsOf as qt, Ctx as r, TableShape as ra, Select as ri, RelationHelpers as rn, WriteOp as ro, TenantContext as rr, EntityHooks as rt, BindOptions as s, ColumnKindTypes as sa, WriteOptions as si, TableOf as sn, tenantColumn as sr, Select_ as st, BaseContext as t, SeedGenerators as ta, ReferenceOptions as ti, RegisteredSetup as tn, RESULT as to, MultiTenantTraits as tr, ChangeOp as tt, EntityName as u, InputModeOf as ua, Extend as ui, Typion as un, LocalizationOptions as ur, UpdateInput_ as ut, TransportEntity as v, OptionType as va, Where as vi, getTypion as vn, localizedValue as vr, VersionOperation as vt, WireDataEnvelope as w, TableMode as wa, VirtualRelation as wi, DefaultSetup as wn, defaultIdColumn as wr, VersionsHookArgs as wt, ERROR_STATUS as x, PluginSystemOptions as xa, HiddenReadKeys as xi, dbAdapter as xn, definePlugin as xr, VersionsCollectionOptions as xt, TransportOperation as y, PluginContextOptions as ya, DynamicReadKeys as yi, AfterCommitErrorInfo as yn, DefinedPlugin as yr, VersionRef as yt, ColumnMeta as z, NotFoundError as za, PluginCollectionOptions as zi, SoftDeleteEntityOptions as zn, FieldOptions as zr, ColumnsOf as zt };
|
|
2098
|
+
//# sourceMappingURL=context-CpLQy7OI.d.ts.map
|