typion 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +4 -2
- package/bin/typion.js +7 -0
- package/dist/auth/better-auth.d.ts +13 -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 +883 -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-B4e2eREP.d.ts +2100 -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-BWVU8TCR.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 +26 -0
- package/dist/testing/index.js +92 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/typion-Dh2BCSRz.js +1187 -0
- package/dist/typion-Dh2BCSRz.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 +114 -0
- package/docs/auth.md +195 -0
- package/docs/collections.md +172 -0
- package/docs/database.md +76 -0
- package/docs/features/localization.md +112 -0
- package/docs/features/multi-tenant.md +166 -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 +188 -0
- package/docs/queries.md +200 -0
- package/docs/testing.md +85 -0
- package/package.json +125 -3
|
@@ -0,0 +1,2100 @@
|
|
|
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 ContextFactoryInput = ContextInput & {
|
|
1440
|
+
system: SystemTypion;
|
|
1441
|
+
db: AnyDb;
|
|
1442
|
+
};
|
|
1443
|
+
type ContextFactory<TCtx> = (input: ContextFactoryInput) => MaybePromise<TCtx>;
|
|
1444
|
+
type TypionConfig<TE extends TypionTypes> = {
|
|
1445
|
+
readonly '~types'?: TE;
|
|
1446
|
+
readonly definition: TypionDefinition<TE>;
|
|
1447
|
+
readonly schema: TypionDefinition<TE>['schema'];
|
|
1448
|
+
readonly db: DbAdapter | undefined;
|
|
1449
|
+
readonly context: ContextFactory<object> | undefined;
|
|
1450
|
+
readonly migrations: MigrationsOptions | undefined;
|
|
1451
|
+
readonly seed: ConfigSeedOptions | undefined;
|
|
1452
|
+
readonly onAfterCommitError: AfterCommitErrorHandler | undefined;
|
|
1453
|
+
readonly checkSchema: boolean | undefined;
|
|
1454
|
+
};
|
|
1455
|
+
type AfterCommitErrorHandler = (error: unknown, info: AfterCommitErrorInfo) => void;
|
|
1456
|
+
type ConfigTables = Record<string, PgTable | PgEnum<any>>;
|
|
1457
|
+
type ByName<Cs extends readonly AnyCollection[]> = { [C in Cs[number] as C['name']]: C; };
|
|
1458
|
+
type SameSetup<S> = [S] extends [RegisteredSetup] ? [RegisteredSetup] extends [S] ? unknown : SetupMismatch : SetupMismatch;
|
|
1459
|
+
type SetupMismatch = {
|
|
1460
|
+
'~error': 'setup must be the one in `interface Register { setup }`';
|
|
1461
|
+
};
|
|
1462
|
+
type ConfigOptions<S extends AnySetup, Cs extends readonly AnyCollection[], TCtx, Tb extends ConfigTables = {}> = {
|
|
1463
|
+
setup?: S & SameSetup<S>;
|
|
1464
|
+
collections: Cs;
|
|
1465
|
+
tables?: Tb;
|
|
1466
|
+
db?: DbAdapter;
|
|
1467
|
+
context?: ContextFactory<TCtx> & ContextFactory<PluginNeedsContext<S['~plugins']>> & ContextFactory<RegisteredContext>;
|
|
1468
|
+
migrations?: MigrationsOptions;
|
|
1469
|
+
seed?: ConfigSeedOptions;
|
|
1470
|
+
maxLimit?: number;
|
|
1471
|
+
validation?: ValidationAdapter;
|
|
1472
|
+
onAfterCommitError?: AfterCommitErrorHandler;
|
|
1473
|
+
checkSchema?: boolean;
|
|
1474
|
+
};
|
|
1475
|
+
type Typion<C> = TypionEngine<TypesOf<C>>;
|
|
1476
|
+
type TypionAppOf<C> = TypionApp<TypesOf<C>, 'user'>;
|
|
1477
|
+
type HandlerOptionsOf<C> = HandlerOptions<TypesOf<C>>;
|
|
1478
|
+
//#endregion
|
|
1479
|
+
//#region src/features/versions/types.d.ts
|
|
1480
|
+
type VersionState = 'draft' | 'published';
|
|
1481
|
+
type VersionOperation = 'create' | 'update' | 'draft' | 'publish' | 'unpublish' | 'discard' | 'restoreVersion' | 'delete' | (string & {});
|
|
1482
|
+
type VersionRef = {
|
|
1483
|
+
versionId: string;
|
|
1484
|
+
versionNumber: number;
|
|
1485
|
+
state: VersionState;
|
|
1486
|
+
};
|
|
1487
|
+
type Version<TRow> = {
|
|
1488
|
+
versionId: string;
|
|
1489
|
+
versionNumber: number;
|
|
1490
|
+
state: VersionState;
|
|
1491
|
+
operation: VersionOperation;
|
|
1492
|
+
isLatest: boolean;
|
|
1493
|
+
createdAt: Date;
|
|
1494
|
+
createdBy: string | null;
|
|
1495
|
+
mode: TypionMode;
|
|
1496
|
+
systemReason: string | null;
|
|
1497
|
+
requestId: string | null;
|
|
1498
|
+
data: TRow;
|
|
1499
|
+
};
|
|
1500
|
+
type FieldDiff<TRow> = { [K in keyof TRow]: {
|
|
1501
|
+
field: K;
|
|
1502
|
+
before: TRow[K];
|
|
1503
|
+
after: TRow[K];
|
|
1504
|
+
}; }[keyof TRow];
|
|
1505
|
+
type HasDraftColumns<T> = T extends {
|
|
1506
|
+
_: {
|
|
1507
|
+
columns: {
|
|
1508
|
+
status: AnyPgColumn;
|
|
1509
|
+
publishedAt: AnyPgColumn;
|
|
1510
|
+
};
|
|
1511
|
+
};
|
|
1512
|
+
} ? true : false;
|
|
1513
|
+
type PendingDraftPolicy = 'supersede' | 'reject';
|
|
1514
|
+
type VersionsEntityOptions<T> = {
|
|
1515
|
+
versions?: true | {
|
|
1516
|
+
drafts?: HasDraftColumns<T> extends true ? boolean : never;
|
|
1517
|
+
max?: number;
|
|
1518
|
+
onPendingDraft?: PendingDraftPolicy;
|
|
1519
|
+
table?: PgTable;
|
|
1520
|
+
};
|
|
1521
|
+
};
|
|
1522
|
+
type VersionsOption = true | {
|
|
1523
|
+
drafts?: boolean;
|
|
1524
|
+
max?: number;
|
|
1525
|
+
onPendingDraft?: PendingDraftPolicy;
|
|
1526
|
+
};
|
|
1527
|
+
type VersionsCollectionOptions = {
|
|
1528
|
+
versions?: VersionsOption;
|
|
1529
|
+
};
|
|
1530
|
+
interface VersionsKinds extends CollectionKinds {
|
|
1531
|
+
readonly columns: this['options'] extends {
|
|
1532
|
+
versions: {
|
|
1533
|
+
drafts: true;
|
|
1534
|
+
};
|
|
1535
|
+
} ? ReturnType<typeof draftColumns> : {};
|
|
1536
|
+
readonly entity: this['options'] extends {
|
|
1537
|
+
versions: infer V;
|
|
1538
|
+
} ? {
|
|
1539
|
+
versions: V;
|
|
1540
|
+
} : {};
|
|
1541
|
+
}
|
|
1542
|
+
type Versioned = {
|
|
1543
|
+
versions: true | object;
|
|
1544
|
+
};
|
|
1545
|
+
type Drafts = {
|
|
1546
|
+
versions: {
|
|
1547
|
+
drafts: true;
|
|
1548
|
+
};
|
|
1549
|
+
};
|
|
1550
|
+
type VersionsReadOptions = {
|
|
1551
|
+
draft?: boolean | undefined;
|
|
1552
|
+
};
|
|
1553
|
+
type VersionsCreateOptions = {
|
|
1554
|
+
draft?: boolean;
|
|
1555
|
+
publish?: boolean;
|
|
1556
|
+
};
|
|
1557
|
+
type VersionsUpdateOptions = {
|
|
1558
|
+
draft?: boolean;
|
|
1559
|
+
};
|
|
1560
|
+
type VersionsListOptions = {
|
|
1561
|
+
limit?: number;
|
|
1562
|
+
offset?: number;
|
|
1563
|
+
state?: VersionState;
|
|
1564
|
+
};
|
|
1565
|
+
type VersionsRestoreOptions = {
|
|
1566
|
+
draft?: boolean;
|
|
1567
|
+
};
|
|
1568
|
+
type VersionsHookArgs<TRow> = {
|
|
1569
|
+
change: {
|
|
1570
|
+
draft: boolean;
|
|
1571
|
+
};
|
|
1572
|
+
afterChange: {
|
|
1573
|
+
previousDraft: TRow | null;
|
|
1574
|
+
version: VersionRef | null;
|
|
1575
|
+
};
|
|
1576
|
+
afterDelete: {
|
|
1577
|
+
version: VersionRef | null;
|
|
1578
|
+
};
|
|
1579
|
+
};
|
|
1580
|
+
type DraftsApi<T extends EntityTraits> = {
|
|
1581
|
+
publish(id: EntityIdOf<T>): Promise<EntityRowOf<T>>;
|
|
1582
|
+
unpublish(id: EntityIdOf<T>): Promise<EntityRowOf<T>>;
|
|
1583
|
+
discardDraft(id: EntityIdOf<T>): Promise<EntityRowOf<T>>;
|
|
1584
|
+
};
|
|
1585
|
+
type HistoryApi<T extends EntityTraits> = {
|
|
1586
|
+
versions: {
|
|
1587
|
+
list(id: EntityIdOf<T>, options?: VersionsListOptions): Promise<Version<EntitySelectOf<T>>[]>;
|
|
1588
|
+
get(id: EntityIdOf<T>, versionId: string): Promise<Version<EntitySelectOf<T>>>;
|
|
1589
|
+
restore(id: EntityIdOf<T>, versionId: string, options?: VersionsRestoreOptions): Promise<EntityRowOf<T>>;
|
|
1590
|
+
diff(id: EntityIdOf<T>, from: string, to: string): Promise<FieldDiff<EntitySelectOf<T>>[]>;
|
|
1591
|
+
};
|
|
1592
|
+
};
|
|
1593
|
+
type IdInput<T extends EntityTraits> = {
|
|
1594
|
+
id: EntityIdOf<T>;
|
|
1595
|
+
};
|
|
1596
|
+
type Named<T extends EntityTraits> = T['name'] & string;
|
|
1597
|
+
type ListInput<T extends EntityTraits> = IdInput<T> & VersionsListOptions;
|
|
1598
|
+
type GetInput<T extends EntityTraits> = IdInput<T> & {
|
|
1599
|
+
versionId: string;
|
|
1600
|
+
};
|
|
1601
|
+
type RestoreInput<T extends EntityTraits> = GetInput<T> & VersionsRestoreOptions;
|
|
1602
|
+
type DiffInput<T extends EntityTraits> = IdInput<T> & {
|
|
1603
|
+
from: string;
|
|
1604
|
+
to: string;
|
|
1605
|
+
};
|
|
1606
|
+
type DraftsQueries<T extends EntityTraits> = {
|
|
1607
|
+
publish(input: IdInput<T>): Descriptor<Named<T>, 'publish', IdInput<T>, EntityRowOf<T>>;
|
|
1608
|
+
unpublish(input: IdInput<T>): Descriptor<Named<T>, 'unpublish', IdInput<T>, EntityRowOf<T>>;
|
|
1609
|
+
discardDraft(input: IdInput<T>): Descriptor<Named<T>, 'discardDraft', IdInput<T>, EntityRowOf<T>>;
|
|
1610
|
+
};
|
|
1611
|
+
type HistoryQueries<T extends EntityTraits> = {
|
|
1612
|
+
versions: {
|
|
1613
|
+
list(input: ListInput<T>): Descriptor<Named<T>, 'versions.list', ListInput<T>, Version<EntitySelectOf<T>>[]>;
|
|
1614
|
+
get(input: GetInput<T>): Descriptor<Named<T>, 'versions.get', GetInput<T>, Version<EntitySelectOf<T>>>;
|
|
1615
|
+
restore(input: RestoreInput<T>): Descriptor<Named<T>, 'versions.restore', RestoreInput<T>, EntityRowOf<T>>;
|
|
1616
|
+
diff(input: DiffInput<T>): Descriptor<Named<T>, 'versions.diff', DiffInput<T>, FieldDiff<EntitySelectOf<T>>[]>;
|
|
1617
|
+
};
|
|
1618
|
+
};
|
|
1619
|
+
interface VersionsTraits extends EntityTraits {
|
|
1620
|
+
readonly entityOptions: VersionsEntityOptions<EntityTableOf<this>>;
|
|
1621
|
+
readonly governs: Drafts;
|
|
1622
|
+
readonly managed: this['given'] extends Drafts ? 'status' | 'publishedAt' : never;
|
|
1623
|
+
readonly optionsOn: this['given'] extends Drafts ? 'read' | 'create' | 'update' : never;
|
|
1624
|
+
readonly optionTypes: {
|
|
1625
|
+
read: VersionsReadOptions;
|
|
1626
|
+
create: VersionsCreateOptions;
|
|
1627
|
+
update: VersionsUpdateOptions;
|
|
1628
|
+
};
|
|
1629
|
+
readonly operations: 'publish' | 'unpublish' | 'discardDraft' | 'versions.restore';
|
|
1630
|
+
readonly rules: {
|
|
1631
|
+
readDrafts: 'filter';
|
|
1632
|
+
readVersions: 'boolean';
|
|
1633
|
+
publish: 'filter';
|
|
1634
|
+
};
|
|
1635
|
+
readonly rulesOn: this['given'] extends Drafts ? 'readDrafts' | 'readVersions' | 'publish' : this['given'] extends Versioned ? 'readVersions' : never;
|
|
1636
|
+
readonly hookArgs: VersionsHookArgs<this['row']>;
|
|
1637
|
+
readonly api: this['given'] extends Drafts ? DraftsApi<this> & HistoryApi<this> : this['given'] extends Versioned ? HistoryApi<this> : {};
|
|
1638
|
+
readonly queries: this['given'] extends Drafts ? DraftsQueries<this> & HistoryQueries<this> : this['given'] extends Versioned ? HistoryQueries<this> : {};
|
|
1639
|
+
}
|
|
1640
|
+
//#endregion
|
|
1641
|
+
//#region src/types/hooks.d.ts
|
|
1642
|
+
type ChangeOp = 'create' | 'update';
|
|
1643
|
+
type Select_<R extends AnyRelations, N extends keyof R> = Assume<R[N]['table'], {
|
|
1644
|
+
$inferSelect: Record<string, unknown>;
|
|
1645
|
+
}>['$inferSelect'];
|
|
1646
|
+
type Insert_<R extends AnyRelations, N extends keyof R> = Assume<R[N]['table'], {
|
|
1647
|
+
$inferInsert: Record<string, unknown>;
|
|
1648
|
+
}>['$inferInsert'];
|
|
1649
|
+
type CreateInput_<R extends AnyRelations, N extends keyof R> = Insert_<R, N>;
|
|
1650
|
+
type UpdateInput_<R extends AnyRelations, N extends keyof R> = Partial<Insert_<R, N>>;
|
|
1651
|
+
type HookBase<R extends AnyRelations, Ctx, TApp = TypionHookApp<R, Ctx>> = {
|
|
1652
|
+
ctx: Ctx;
|
|
1653
|
+
meta: OperationMeta;
|
|
1654
|
+
typion: TApp;
|
|
1655
|
+
tx: PgAsyncTransaction<PgQueryResultHKT, any>;
|
|
1656
|
+
bag: Map<string, unknown>;
|
|
1657
|
+
};
|
|
1658
|
+
interface TypionHookEntityApi<R extends AnyRelations, N extends keyof R & string> {
|
|
1659
|
+
find<const C extends DBQueryConfig<'many', R, R[N]>>(config?: KnownKeysOnly<C, DBQueryConfig<'many', R, R[N]>>): Promise<BuildQueryResult<R, R[N], C>[]>;
|
|
1660
|
+
findOne<const C extends DBQueryConfig<'one', R, R[N]>>(config?: KnownKeysOnly<C, DBQueryConfig<'one', R, R[N]>>): Promise<BuildQueryResult<R, R[N], C> | null>;
|
|
1661
|
+
findById<const C extends Omit<DBQueryConfig<'one', R, R[N]>, 'where' | 'offset'>>(id: unknown, config?: C): Promise<BuildQueryResult<R, R[N], C>>;
|
|
1662
|
+
count(config?: {
|
|
1663
|
+
where?: RawWhere<R, N>;
|
|
1664
|
+
}): Promise<number>;
|
|
1665
|
+
create(data: Insert_<R, N>): Promise<Select_<R, N>>;
|
|
1666
|
+
update(id: unknown, data: Partial<Insert_<R, N>>): Promise<Select_<R, N>>;
|
|
1667
|
+
updateMany(where: RawWhere<R, N>, data: Partial<Insert_<R, N>>, options?: {
|
|
1668
|
+
max?: number;
|
|
1669
|
+
}): Promise<{
|
|
1670
|
+
count: number;
|
|
1671
|
+
}>;
|
|
1672
|
+
delete(id: unknown, options?: Readonly<Record<string, unknown>>): Promise<Select_<R, N>>;
|
|
1673
|
+
deleteMany(where: RawWhere<R, N>, options?: {
|
|
1674
|
+
max?: number;
|
|
1675
|
+
} & Readonly<Record<string, unknown>>): Promise<{
|
|
1676
|
+
count: number;
|
|
1677
|
+
}>;
|
|
1678
|
+
}
|
|
1679
|
+
type TypionHookApp<R extends AnyRelations, Ctx> = { [N in keyof R & string]: TypionHookEntityApi<R, N>; } & {
|
|
1680
|
+
readonly $ctx: Ctx;
|
|
1681
|
+
readonly $mode: TypionMode;
|
|
1682
|
+
$transaction<T>(fn: (e: TypionHookApp<R, Ctx>) => Promise<T>): Promise<T>;
|
|
1683
|
+
};
|
|
1684
|
+
type ChangeArgs<S, CI, UI, TOps extends string = never, TArgs = {}> = ({
|
|
1685
|
+
op: 'create';
|
|
1686
|
+
data: CI;
|
|
1687
|
+
original: null;
|
|
1688
|
+
} | {
|
|
1689
|
+
op: 'update' | TOps;
|
|
1690
|
+
data: UI;
|
|
1691
|
+
original: S;
|
|
1692
|
+
}) & TArgs;
|
|
1693
|
+
type AfterChangeArgs<S, TOps extends string = never, TArgs = {}> = {
|
|
1694
|
+
op: ChangeOp | TOps;
|
|
1695
|
+
doc: S;
|
|
1696
|
+
previous: S | null;
|
|
1697
|
+
changes: readonly (keyof S & string)[];
|
|
1698
|
+
} & TArgs;
|
|
1699
|
+
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'>> = {
|
|
1700
|
+
beforeValidate?: (a: ChangeArgs<S, CI, UI, TOps, TChange> & HookBase<R, Ctx, TApp>) => MaybePromise<CI | UI | void>;
|
|
1701
|
+
beforeChange?: (a: ChangeArgs<S, CI, UI, TOps, TChange> & HookBase<R, Ctx, TApp>) => MaybePromise<CI | UI | void>;
|
|
1702
|
+
afterChange?: (a: AfterChangeArgs<S, TOps, TChange & TAfterChange> & HookBase<R, Ctx, TApp>) => MaybePromise<void>;
|
|
1703
|
+
beforeDelete?: (a: {
|
|
1704
|
+
doc: S;
|
|
1705
|
+
options: TDelete;
|
|
1706
|
+
} & HookBase<R, Ctx, TApp>) => MaybePromise<void>;
|
|
1707
|
+
afterDelete?: (a: {
|
|
1708
|
+
doc: S;
|
|
1709
|
+
options: TDelete;
|
|
1710
|
+
} & TAfterDelete & HookBase<R, Ctx, TApp>) => MaybePromise<void>;
|
|
1711
|
+
afterCommit?: (a: {
|
|
1712
|
+
op: Operation;
|
|
1713
|
+
doc: S | null;
|
|
1714
|
+
previous: S | null;
|
|
1715
|
+
ctx: Ctx;
|
|
1716
|
+
meta: OperationMeta;
|
|
1717
|
+
}) => MaybePromise<void>;
|
|
1718
|
+
};
|
|
1719
|
+
type AnyRow$1 = Record<string, unknown>;
|
|
1720
|
+
type PluginArgs = Readonly<Record<string, unknown>>;
|
|
1721
|
+
type CoreArgs = VersionsHookArgs<AnyRow$1>;
|
|
1722
|
+
type GlobalHookBase = HookBase<AnyRelations, any> & {
|
|
1723
|
+
entityMeta: EntityMeta;
|
|
1724
|
+
};
|
|
1725
|
+
type GlobalHooks = {
|
|
1726
|
+
entities?: readonly string[];
|
|
1727
|
+
beforeOperation?: (a: {
|
|
1728
|
+
entity: string;
|
|
1729
|
+
op: Operation;
|
|
1730
|
+
args: unknown;
|
|
1731
|
+
} & GlobalHookBase) => MaybePromise<void>;
|
|
1732
|
+
beforeChange?: (a: {
|
|
1733
|
+
entity: string;
|
|
1734
|
+
} & ChangeArgs<AnyRow$1, AnyRow$1, AnyRow$1, string, PluginArgs & CoreArgs['change']> & GlobalHookBase) => MaybePromise<AnyRow$1 | void>;
|
|
1735
|
+
afterChange?: (a: {
|
|
1736
|
+
entity: string;
|
|
1737
|
+
} & AfterChangeArgs<AnyRow$1, string, PluginArgs & CoreArgs['change'] & CoreArgs['afterChange']> & GlobalHookBase) => MaybePromise<void>;
|
|
1738
|
+
afterDelete?: (a: {
|
|
1739
|
+
entity: string;
|
|
1740
|
+
doc: AnyRow$1;
|
|
1741
|
+
previous: AnyRow$1;
|
|
1742
|
+
removed: boolean;
|
|
1743
|
+
options: Readonly<Record<string, unknown>>;
|
|
1744
|
+
} & PluginArgs & CoreArgs['afterDelete'] & GlobalHookBase) => MaybePromise<void>;
|
|
1745
|
+
afterOperation?: (a: {
|
|
1746
|
+
entity: string;
|
|
1747
|
+
op: Operation;
|
|
1748
|
+
result: unknown;
|
|
1749
|
+
} & GlobalHookBase) => MaybePromise<void>;
|
|
1750
|
+
afterLink?: (a: {
|
|
1751
|
+
entity: string;
|
|
1752
|
+
op: 'link' | 'unlink';
|
|
1753
|
+
doc: AnyRow$1;
|
|
1754
|
+
relation: string;
|
|
1755
|
+
ids: readonly unknown[];
|
|
1756
|
+
} & GlobalHookBase) => MaybePromise<void>;
|
|
1757
|
+
afterCommit?: (a: {
|
|
1758
|
+
entity: string;
|
|
1759
|
+
op: Operation;
|
|
1760
|
+
doc: AnyRow$1 | null;
|
|
1761
|
+
previous: AnyRow$1 | null;
|
|
1762
|
+
ctx: any;
|
|
1763
|
+
meta: OperationMeta;
|
|
1764
|
+
}) => MaybePromise<void>;
|
|
1765
|
+
};
|
|
1766
|
+
//#endregion
|
|
1767
|
+
//#region src/types/access.d.ts
|
|
1768
|
+
type RuleSchema<R extends AnyRelations, P extends readonly unknown[]> = { [K in keyof R]: {
|
|
1769
|
+
table: VirtualTable<Assume<R[K]['table'], PgTable>, TableMode<Assume<R[K]['table'], PgTable>, InputModeOf<P>>, never, never>;
|
|
1770
|
+
name: R[K]['name'];
|
|
1771
|
+
relations: R[K]['relations'];
|
|
1772
|
+
}; };
|
|
1773
|
+
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; };
|
|
1774
|
+
type RawWhere<R extends AnyRelations, N extends keyof R, P extends readonly unknown[] = readonly []> = RelationsFilter<RuleSchema<R, P>[N], RuleSchema<R, P>>;
|
|
1775
|
+
type Operation = 'find' | 'findOne' | 'findById' | 'count' | 'page' | 'create' | 'update' | 'updateMany' | 'delete' | 'deleteMany' | (string & {});
|
|
1776
|
+
interface OperationMeta {
|
|
1777
|
+
readonly entity: string;
|
|
1778
|
+
readonly operation: Operation;
|
|
1779
|
+
readonly mode: TypionMode;
|
|
1780
|
+
readonly requestId: string;
|
|
1781
|
+
readonly now: Date;
|
|
1782
|
+
readonly systemReason: string | null;
|
|
1783
|
+
}
|
|
1784
|
+
type RuleArgs<R extends AnyRelations, Ctx, TApp = TypionHookApp<R, Ctx>> = {
|
|
1785
|
+
ctx: Ctx;
|
|
1786
|
+
meta: OperationMeta;
|
|
1787
|
+
typion: TApp;
|
|
1788
|
+
};
|
|
1789
|
+
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>>);
|
|
1790
|
+
type BooleanRule<R extends AnyRelations, Ctx, TApp> = boolean | ((a: RuleArgs<R, Ctx, TApp>) => MaybePromise<boolean>);
|
|
1791
|
+
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>; };
|
|
1792
|
+
type AccessRules<R extends AnyRelations, N extends keyof R & string, Ctx, P extends readonly unknown[] = readonly [], TApp = TypionHookApp<R, Ctx>, TRules = AllTraitRules<P>> = {
|
|
1793
|
+
read?: FilterRule<R, N, Ctx, TApp, P>;
|
|
1794
|
+
create?: boolean | ((a: RuleArgs<R, Ctx, TApp> & {
|
|
1795
|
+
data: RuleData<R, N>;
|
|
1796
|
+
}) => MaybePromise<boolean>);
|
|
1797
|
+
update?: FilterRule<R, N, Ctx, TApp, P, {
|
|
1798
|
+
data: Partial<RuleData<R, N>>;
|
|
1799
|
+
}>;
|
|
1800
|
+
delete?: FilterRule<R, N, Ctx, TApp, P, {
|
|
1801
|
+
options: AllTraitOptions<P, 'delete'>;
|
|
1802
|
+
}>;
|
|
1803
|
+
} & PluginRules<R, N, Ctx, TApp, P, TRules>;
|
|
1804
|
+
type AnyAccessRules = Readonly<Record<string, unknown>>;
|
|
1805
|
+
type AllowAll = {
|
|
1806
|
+
read: true;
|
|
1807
|
+
create: true;
|
|
1808
|
+
update: true;
|
|
1809
|
+
delete: true;
|
|
1810
|
+
};
|
|
1811
|
+
//#endregion
|
|
1812
|
+
//#region src/types/meta.d.ts
|
|
1813
|
+
interface ColumnMeta {
|
|
1814
|
+
readonly key: string;
|
|
1815
|
+
readonly name: string;
|
|
1816
|
+
readonly column: AnyPgColumn;
|
|
1817
|
+
readonly dataType: string;
|
|
1818
|
+
readonly columnType: string;
|
|
1819
|
+
readonly notNull: boolean;
|
|
1820
|
+
readonly hasDefault: boolean;
|
|
1821
|
+
readonly generated: boolean;
|
|
1822
|
+
readonly enumValues: readonly string[] | undefined;
|
|
1823
|
+
readonly kind: string | null;
|
|
1824
|
+
readonly columnKind: ColumnKindRuntime | null;
|
|
1825
|
+
readonly read: true | false | ((a: FieldRuleArgs<any>) => boolean);
|
|
1826
|
+
readonly write: 'user' | 'system' | false | ((a: FieldRuleArgs<any>) => boolean);
|
|
1827
|
+
}
|
|
1828
|
+
interface RelationMeta {
|
|
1829
|
+
readonly key: string;
|
|
1830
|
+
readonly target: string;
|
|
1831
|
+
readonly type: 'one' | 'many';
|
|
1832
|
+
readonly optional: boolean;
|
|
1833
|
+
readonly through: boolean;
|
|
1834
|
+
}
|
|
1835
|
+
interface EntityMeta {
|
|
1836
|
+
readonly name: string;
|
|
1837
|
+
readonly table: PgTable;
|
|
1838
|
+
readonly tableName: string;
|
|
1839
|
+
readonly pgSchema: string | undefined;
|
|
1840
|
+
readonly pk: ColumnMeta;
|
|
1841
|
+
readonly columns: Readonly<Record<string, ColumnMeta>>;
|
|
1842
|
+
readonly visibleKeys: readonly string[];
|
|
1843
|
+
readonly kindKeys: readonly string[];
|
|
1844
|
+
readonly dynamicReadKeys: readonly string[];
|
|
1845
|
+
readonly managedKeys: readonly string[];
|
|
1846
|
+
readonly relations: Readonly<Record<string, RelationMeta>>;
|
|
1847
|
+
readonly links: ReadonlySet<string>;
|
|
1848
|
+
readonly traits: Readonly<Record<string, EntityTrait>>;
|
|
1849
|
+
readonly access: AnyAccessRules;
|
|
1850
|
+
readonly hooks: EntityHooks<AnyRelations, string, any>;
|
|
1851
|
+
readonly validate: {
|
|
1852
|
+
insert?: StandardSchemaV1;
|
|
1853
|
+
update?: StandardSchemaV1;
|
|
1854
|
+
fields?: Record<string, unknown>;
|
|
1855
|
+
} | null;
|
|
1856
|
+
readonly defaultOrder: Readonly<Record<string, 'asc' | 'desc'>> | null;
|
|
1857
|
+
readonly maxLimit: number;
|
|
1858
|
+
readonly pluginOptions: Readonly<Record<string, unknown>>;
|
|
1859
|
+
readonly owner: 'user' | {
|
|
1860
|
+
readonly plugin: string;
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1863
|
+
interface TypionDefinition<TE extends TypionTypes> {
|
|
1864
|
+
readonly $types: TE;
|
|
1865
|
+
readonly relations: TE['relations'];
|
|
1866
|
+
readonly schema: Readonly<Record<string, PgTable | PgEnum<any> | PgSchema<string>>>;
|
|
1867
|
+
readonly generated: GeneratedTables<TE> & {
|
|
1868
|
+
readonly $names: readonly string[];
|
|
1869
|
+
};
|
|
1870
|
+
readonly entities: Readonly<Record<EntityName<TE>, EntityMeta>>;
|
|
1871
|
+
readonly plugins: readonly PluginRuntime[];
|
|
1872
|
+
readonly pgSchema: PgSchema<string>;
|
|
1873
|
+
readonly maxLimit: number;
|
|
1874
|
+
readonly validation: ValidationAdapter | null;
|
|
1875
|
+
}
|
|
1876
|
+
type GeneratedTables<TE extends TypionTypes> = PluginTables<TE['plugins']> & Readonly<Record<string, PgTable>>;
|
|
1877
|
+
//#endregion
|
|
1878
|
+
//#region src/types/runtime.d.ts
|
|
1879
|
+
type AnyDb = PgAsyncDatabase<PgQueryResultHKT, AnyRelations>;
|
|
1880
|
+
type AnyTx = PgAsyncTransaction<PgQueryResultHKT, AnyRelations>;
|
|
1881
|
+
type AnyRow = Record<string, unknown>;
|
|
1882
|
+
interface AfterCommitQueue {
|
|
1883
|
+
readonly size: number;
|
|
1884
|
+
flush(): Promise<void>;
|
|
1885
|
+
discard(): void;
|
|
1886
|
+
}
|
|
1887
|
+
interface AnyTypionApp {
|
|
1888
|
+
readonly $ctx: BaseContext & Record<string, unknown>;
|
|
1889
|
+
readonly $mode: TypionMode;
|
|
1890
|
+
readonly $tx: AnyTx | null;
|
|
1891
|
+
readonly $engine: AnyTypion;
|
|
1892
|
+
readonly $executor: AnyDb | AnyTx;
|
|
1893
|
+
$run(descriptor: AnyDescriptor, extend?: Record<string, unknown>): Promise<unknown>;
|
|
1894
|
+
$transaction<T>(fn: (bound: AnyTypionApp) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
|
|
1895
|
+
$withTx(tx: AnyTx): AnyTypionApp;
|
|
1896
|
+
readonly $afterCommit: AfterCommitQueue;
|
|
1897
|
+
entity(name: string): Record<string, unknown>;
|
|
1898
|
+
}
|
|
1899
|
+
interface AnyTypion {
|
|
1900
|
+
readonly $def: TypionDefinition<any>;
|
|
1901
|
+
readonly $db: AnyDb;
|
|
1902
|
+
readonly $dialect: Dialect;
|
|
1903
|
+
readonly $plugins: Record<string, unknown>;
|
|
1904
|
+
$as(ctx: object, opts?: {
|
|
1905
|
+
request?: Request;
|
|
1906
|
+
meta?: Record<string, unknown>;
|
|
1907
|
+
} & Record<string, unknown>): AnyTypionApp;
|
|
1908
|
+
$system(opts: {
|
|
1909
|
+
reason: string;
|
|
1910
|
+
ctx?: object;
|
|
1911
|
+
meta?: Record<string, unknown>;
|
|
1912
|
+
} & Record<string, unknown>): AnyTypionApp;
|
|
1913
|
+
$fromRequest(request: Request, opts?: Record<string, unknown>): Promise<AnyTypionApp>;
|
|
1914
|
+
$execute(descriptor: AnyDescriptor, bound: AnyTypionApp): Promise<unknown>;
|
|
1915
|
+
}
|
|
1916
|
+
interface ValidationAdapter {
|
|
1917
|
+
readonly id: 'structural' | 'zod' | 'valibot' | 'arktype';
|
|
1918
|
+
base(entity: EntityMeta, mode: 'insert' | 'update' | 'select', refinements: Record<string, unknown> | undefined): StandardSchemaV1;
|
|
1919
|
+
}
|
|
1920
|
+
//#endregion
|
|
1921
|
+
//#region src/types/dialect.d.ts
|
|
1922
|
+
type SchemaDrift = {
|
|
1923
|
+
missingTables: string[];
|
|
1924
|
+
missingColumns: {
|
|
1925
|
+
table: string;
|
|
1926
|
+
columns: string[];
|
|
1927
|
+
}[];
|
|
1928
|
+
};
|
|
1929
|
+
interface Dialect {
|
|
1930
|
+
readonly id: 'pg';
|
|
1931
|
+
jsonText(column: AnyPgColumn | SQL, key: string): SQL;
|
|
1932
|
+
cast(value: SQL, type: string): SQL;
|
|
1933
|
+
jsonbMerge(column: AnyPgColumn, patch: unknown): SQL;
|
|
1934
|
+
jsonParam(value: unknown, column: AnyPgColumn): SQL;
|
|
1935
|
+
lockSelect(tx: AnyTx, table: PgTable, where: SQL | undefined): Promise<Record<string, unknown>[]>;
|
|
1936
|
+
mapError(error: unknown): TypionError | null;
|
|
1937
|
+
introspect(db: AnyDb, tables: readonly PgTable[]): Promise<SchemaDrift>;
|
|
1938
|
+
}
|
|
1939
|
+
//#endregion
|
|
1940
|
+
//#region src/contract/errors.d.ts
|
|
1941
|
+
declare const ERROR_STATUS: {
|
|
1942
|
+
readonly NOT_FOUND: 404;
|
|
1943
|
+
readonly FORBIDDEN: 403;
|
|
1944
|
+
readonly VALIDATION: 422;
|
|
1945
|
+
readonly CONFLICT: 409;
|
|
1946
|
+
readonly INVALID_STATE: 409;
|
|
1947
|
+
readonly BAD_REQUEST: 400;
|
|
1948
|
+
readonly UNSUPPORTED: 400;
|
|
1949
|
+
readonly PLUGIN: 500;
|
|
1950
|
+
readonly CONFIG: 500;
|
|
1951
|
+
readonly INTERNAL: 500;
|
|
1952
|
+
};
|
|
1953
|
+
type ErrorStatus = (typeof ERROR_STATUS)[TypionErrorCode];
|
|
1954
|
+
type WireIssue = {
|
|
1955
|
+
readonly path: readonly (string | number)[];
|
|
1956
|
+
readonly message: string;
|
|
1957
|
+
};
|
|
1958
|
+
type WireErrorCode = TypionErrorCode | 'UNAUTHENTICATED';
|
|
1959
|
+
type WireError = {
|
|
1960
|
+
readonly code: WireErrorCode;
|
|
1961
|
+
readonly status: number;
|
|
1962
|
+
readonly message: string;
|
|
1963
|
+
readonly entity?: string;
|
|
1964
|
+
readonly issues?: readonly WireIssue[];
|
|
1965
|
+
readonly details?: Record<string, unknown>;
|
|
1966
|
+
};
|
|
1967
|
+
type WireErrorEnvelope = {
|
|
1968
|
+
readonly error: WireError;
|
|
1969
|
+
};
|
|
1970
|
+
type WireDataEnvelope<T> = {
|
|
1971
|
+
readonly data: T;
|
|
1972
|
+
};
|
|
1973
|
+
type WireEnvelope<T> = WireDataEnvelope<T> | WireErrorEnvelope;
|
|
1974
|
+
type WireBatchEnvelope<T = unknown> = {
|
|
1975
|
+
readonly results: readonly WireEnvelope<T>[];
|
|
1976
|
+
};
|
|
1977
|
+
//#endregion
|
|
1978
|
+
//#region src/http/transport.d.ts
|
|
1979
|
+
type CheckedDescriptor = AnyDescriptor & {
|
|
1980
|
+
readonly '~checked': true;
|
|
1981
|
+
};
|
|
1982
|
+
interface Transport {
|
|
1983
|
+
readonly name: string;
|
|
1984
|
+
handle(call: TransportCall): Promise<Response | undefined> | Response | undefined;
|
|
1985
|
+
}
|
|
1986
|
+
interface TransportCall {
|
|
1987
|
+
readonly request: Request;
|
|
1988
|
+
readonly url: URL;
|
|
1989
|
+
readonly method: string;
|
|
1990
|
+
readonly segments: readonly string[];
|
|
1991
|
+
readonly schema: TransportSchema;
|
|
1992
|
+
body(): Promise<unknown>;
|
|
1993
|
+
descriptor(raw: unknown): CheckedDescriptor;
|
|
1994
|
+
run(descriptor: CheckedDescriptor): Promise<unknown>;
|
|
1995
|
+
respond(status: number, payload: unknown): Response;
|
|
1996
|
+
error(error: unknown): WireError;
|
|
1997
|
+
}
|
|
1998
|
+
interface TransportSchema {
|
|
1999
|
+
readonly maxLimit: number;
|
|
2000
|
+
entity(name: string): TransportEntity | null;
|
|
2001
|
+
readonly readOptions: ReadonlyMap<string, OptionType>;
|
|
2002
|
+
readonly deleteOptions: ReadonlyMap<string, OptionType>;
|
|
2003
|
+
}
|
|
2004
|
+
interface TransportEntity {
|
|
2005
|
+
readonly name: string;
|
|
2006
|
+
readonly operations: readonly TransportOperation[];
|
|
2007
|
+
}
|
|
2008
|
+
interface TransportOperation {
|
|
2009
|
+
readonly name: string;
|
|
2010
|
+
readonly args: readonly string[];
|
|
2011
|
+
readonly options: Readonly<Record<string, OptionType>>;
|
|
2012
|
+
readonly route: {
|
|
2013
|
+
readonly method: string;
|
|
2014
|
+
readonly path: string;
|
|
2015
|
+
} | undefined;
|
|
2016
|
+
}
|
|
2017
|
+
//#endregion
|
|
2018
|
+
//#region src/types/engine.d.ts
|
|
2019
|
+
interface TypionTypes {
|
|
2020
|
+
ctx: object;
|
|
2021
|
+
tables: Record<string, PgTable | PgEnum<any>>;
|
|
2022
|
+
plugins: readonly AnyPlugin[];
|
|
2023
|
+
entities: AnyEntities;
|
|
2024
|
+
relations: AnyRelations;
|
|
2025
|
+
}
|
|
2026
|
+
type EntityName<TE extends TypionTypes> = keyof TE['entities'] & keyof TE['relations'] & string;
|
|
2027
|
+
type BindOptions<TE extends TypionTypes> = {
|
|
2028
|
+
request?: Request;
|
|
2029
|
+
meta?: Record<string, unknown>;
|
|
2030
|
+
} & PluginContextOptions<TE['plugins']>;
|
|
2031
|
+
type DescriptorApi<TE extends TypionTypes, N extends EntityName<TE>> = Pick<EntityApi<TE, N, 'user'>, 'query' | 'queryOne'>;
|
|
2032
|
+
type CorsOptions = {
|
|
2033
|
+
origin?: string | readonly string[] | ((origin: string) => boolean);
|
|
2034
|
+
methods?: readonly string[];
|
|
2035
|
+
headers?: readonly string[];
|
|
2036
|
+
credentials?: boolean;
|
|
2037
|
+
maxAge?: number;
|
|
2038
|
+
};
|
|
2039
|
+
type HandlerOptions<TE extends TypionTypes> = {
|
|
2040
|
+
transports: readonly Transport[];
|
|
2041
|
+
basePath?: string;
|
|
2042
|
+
expose?: readonly EntityName<TE>[];
|
|
2043
|
+
exclude?: readonly EntityName<TE>[];
|
|
2044
|
+
exposeBulk?: boolean;
|
|
2045
|
+
maxLimit?: number;
|
|
2046
|
+
maxDepth?: number;
|
|
2047
|
+
codecs?: readonly ('json' | 'superjson')[];
|
|
2048
|
+
cors?: CorsOptions;
|
|
2049
|
+
debug?: boolean;
|
|
2050
|
+
onError?: (error: unknown) => void;
|
|
2051
|
+
};
|
|
2052
|
+
type TypionApp<TE extends TypionTypes, TMode extends TypionMode> = { [N in EntityName<TE>]: EntityApi<TE, N, TMode> & TraitApi<TE, N, TMode> & LinkApi<TE, N>; } & {
|
|
2053
|
+
readonly $ctx: Ctx<TE>;
|
|
2054
|
+
readonly $mode: TMode;
|
|
2055
|
+
readonly $tx: PgAsyncTransaction<PgQueryResultHKT, TE['relations']> | null;
|
|
2056
|
+
$run<D extends AnyDescriptor>(descriptor: D, extend?: Extend<TE, D['entity'] & EntityName<TE>>): Promise<InferResult<D>>;
|
|
2057
|
+
$transaction<T>(fn: (app: TypionApp<TE, TMode>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
|
|
2058
|
+
readonly $afterCommit: AfterCommitQueue;
|
|
2059
|
+
readonly $plugins: PluginApis<TE['plugins']>;
|
|
2060
|
+
};
|
|
2061
|
+
type TypionEngine<TE extends TypionTypes> = { [N in EntityName<TE>]: DescriptorApi<TE, N>; } & {
|
|
2062
|
+
$as(ctx: TE['ctx'], opts?: BindOptions<TE>): TypionApp<TE, 'user'>;
|
|
2063
|
+
$system(opts: {
|
|
2064
|
+
reason: string;
|
|
2065
|
+
ctx?: Partial<TE['ctx']>;
|
|
2066
|
+
meta?: Record<string, unknown>;
|
|
2067
|
+
} & PluginContextOptions<TE['plugins']> & PluginSystemOptions<TE['plugins']>): TypionApp<TE, 'system'>;
|
|
2068
|
+
$fromRequest(request: Request, opts?: PluginContextOptions<TE['plugins']>): Promise<TypionApp<TE, 'user'>>;
|
|
2069
|
+
$fromHeaders(headers: Headers, opts?: PluginContextOptions<TE['plugins']>): Promise<TypionApp<TE, 'user'>>;
|
|
2070
|
+
$withTx(ctx: TE['ctx'], tx: PgAsyncTransaction<PgQueryResultHKT, TE['relations']>): TypionApp<TE, 'user'>;
|
|
2071
|
+
$execute<D extends AnyDescriptor>(descriptor: D, bound: TypionApp<TE, TypionMode>): Promise<InferResult<D>>;
|
|
2072
|
+
readonly $plugins: PluginApis<TE['plugins']>;
|
|
2073
|
+
readonly $def: TypionDefinition<TE>;
|
|
2074
|
+
readonly $db: PgAsyncDatabase<PgQueryResultHKT, TE['relations']>;
|
|
2075
|
+
readonly $dialect: Dialect;
|
|
2076
|
+
};
|
|
2077
|
+
//#endregion
|
|
2078
|
+
//#region src/types/context.d.ts
|
|
2079
|
+
type TypionMode = 'user' | 'system';
|
|
2080
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
2081
|
+
type BaseContext = {
|
|
2082
|
+
readonly mode: TypionMode;
|
|
2083
|
+
readonly now: Date;
|
|
2084
|
+
readonly requestId: string;
|
|
2085
|
+
readonly request: Request | null;
|
|
2086
|
+
readonly actorId: string | null;
|
|
2087
|
+
readonly systemReason: string | null;
|
|
2088
|
+
readonly meta: Record<string, unknown>;
|
|
2089
|
+
};
|
|
2090
|
+
type ContextInput = {
|
|
2091
|
+
request?: Request;
|
|
2092
|
+
headers?: Headers;
|
|
2093
|
+
options?: Readonly<Record<string, unknown>>;
|
|
2094
|
+
callerLookup?: boolean;
|
|
2095
|
+
};
|
|
2096
|
+
type Ctx<TE extends TypionTypes> = BaseContext & TE['ctx'] & PluginContext<TE['plugins']>;
|
|
2097
|
+
type FullCtx<TCtx extends object, P extends readonly AnyPlugin[]> = BaseContext & TCtx & PluginContext<P>;
|
|
2098
|
+
//#endregion
|
|
2099
|
+
export { AfterChangeArgs as $, InferItem as $a, PluginTables as $i, MultiTenantOptions as $n, NoneIfEmpty as $r, OneSpec as $t, Dialect as A, BadRequestError as Aa, CollectionKinds as Ai, TypionSetup as An, ColumnKeys as Ar, VersionsTraits as At, EntityMeta as B, NotFoundError as Ba, PluginCollectionOptions as Bi, SoftDeleteEntityOptions as Bn, FieldOptions as Br, ConfigOptions as Bt, WireBatchEnvelope as C, ReadModeFn as Ca, VS as Ci, defineConfig as Cn, collection as Cr, VersionsEntityOptions as Ct, WireErrorCode as D, WriteModeFn as Da, AnyFeatureTables as Di, SetupLocalization as Dn, TraitOptions as Dr, VersionsOption as Dt, WireError as E, ValidationMode as Ea, VirtualTable as Ei, Setup as En, timestamps as Er, VersionsListOptions as Et, AnyTx as F, ConflictKind as Fa, FeatureTables as Fi, VersionsPlugin as Fn, EntityApi as Fr, ByName as Ft, AllowAll as G, TypionErrorOptions as Ga, PluginErrorDef as Gi, SoftDeleteTraits as Gn, Insert as Gr, ContextFactoryInput as Gt, RelationMeta as H, PluginErrorOptions as Ha, PluginEntities as Hi, SoftDeletePlugin as Hn, FieldRuleArgs as Hr, ConfigTables as Ht, AnyTypion as I, ForbiddenError as Ia, MergeAll as Ii, versionsTable as In, EntityDef as Ir, Collection as It, OperationMeta as J, ValidationIssue as Ja, PluginKinds as Ji, IntegerTenantColumn as Jn, LinkMethods as Jr, HandlerOptionsOf as Jt, AnyAccessRules as K, UnsupportedError as Ka, PluginErrorFactories as Ki, softDeleteColumn as Kn, LinkApi as Kr, DbAdapter as Kt, AnyTypionApp as L, ForbiddenErrorOptions as La, MergeConfigs as Li, SoftDeleteApi as Ln, EntityOptions as Lr, CollectionDraft as Lt, AfterCommitQueue as M, ConfigErrorKind as Ma, ColumnKind as Mi, DefaultFeaturePlugins as Mn, CreateOptions as Mr, AfterCommitErrorHandler as Mt, AnyDb as N, ConflictError as Na, DependenciesError as Ni, FeaturePlugins as Nn, DeleteOptions as Nr, AnyCollection as Nt, WireErrorEnvelope as O, WriteModeOf as Oa, AnyPlugin as Oi, SetupOptions as On, TraitQueries as Or, VersionsReadOptions as Ot, AnyRow as P, ConflictErrorOptions as Pa, FeatureId as Pi, FeaturesOptions as Pn, EntitiesOf$1 as Pr, Behaviour as Pt, RuleSchema as Q, Descriptor as Qa, PluginSpec as Qi, MultiTenantKinds as Qn, NoExtraKeys as Qr, NoUnknownKeys as Qt, ValidationAdapter as R, InternalError as Ra, Plugin as Ri, SoftDeleteCollectionOptions as Rn, EntitySchemas as Rr, CollectionRuntime as Rt, ErrorStatus as S, PluginSystemOptions as Sa, HiddenReadKeys as Si, dbAdapter as Sn, definePlugin as Sr, VersionsCreateOptions as St, WireEnvelope as T, TableMode as Ta, VirtualRelation as Ti, DefaultSetup as Tn, defaultIdColumn as Tr, VersionsKinds as Tt, TypionDefinition as U, TypionError as Ua, PluginEntityDefiner as Ui, SoftDeleteQueries as Un, HiddenWriteKeys as Ur, ConfigTypes as Ut, GeneratedTables as V, PluginError as Va, PluginContext as Vi, SoftDeleteKinds as Vn, FieldRefinements as Vr, ConfigSeedOptions as Vt, AccessRules as W, TypionErrorCode as Wa, PluginEntityOptions as Wi, SoftDeleteReadOptions as Wn, Id$1 as Wr, ContextFactory as Wt, RuleArgs as X, isTypionError as Xa, PluginRoute as Xi, MultiTenantContext as Xn, LinkQueryMethods as Xr, ManySpec as Xt, RawWhere as Y, attempt as Ya, PluginNeedsContext as Yi, MultiTenantCollectionOptions as Yn, LinkQueries as Yr, HookTypion as Yt, RuleData as Z, AnyDescriptor as Za, PluginRuntime as Zi, MultiTenantEntityOptions as Zn, ManagedKeys as Zr, MigrationsOptions as Zt, TransportCall as _, Kinded as _a, ReadOptions as _i, structuralValidation as _n, localizedIndex as _r, Version as _t, MaybePromise as a, COLUMN_KIND as aa, UpdateInput as ai, RelationSpec as an, descriptor as ao, TenantIdOf as ar, HookBase as at, TransportSchema as b, PluginContextOptions as ba, DynamicReadKeys as bi, AfterCommitErrorInfo as bn, DefinedPlugin as br, VersionState as bt, CorsOptions as c, ColumnKindTypes as ca, WriteOptions as ci, TableOf as cn, tenantColumn as cr, TypionHookApp as ct, HandlerOptions as d, InputModeOf as da, Extend as di, Typion as dn, LocalizationOptions as dr, DraftsApi as dt, RequirementsError as ea, NullableTimestampKeys as ei, RegisteredContext as en, InferResult as eo, MultiTenantPlugin as er, ChangeArgs as et, TypionApp as f, KeyedShape as fa, FindConfig as fi, TypionAppOf as fn, LocalizationPlugin as fr, DraftsQueries as ft, Transport as g, KindWriteOptions as ga, Page as gi, StructuralValidationAdapter as gn, localized as gr, PendingDraftPolicy as gt, CheckedDescriptor as h, KindWrite as ha, OrderBy as hi, StructuralSchema as hn, Localized as hr, HistoryQueries as ht, FullCtx as i, TableShape as ia, Select as ii, RelationHelpers as in, WriteOp as io, TenantContext as ir, GlobalHooks as it, SchemaDrift as j, ConfigError as ja, CollectionSpec as ji, defineSetup as jn, CreateInput as jr, VersionsUpdateOptions as jt, WireIssue as k, Attempt as ka, AnyPluginSpec as ki, SetupPlugins as kn, AnyEntities as kr, VersionsRestoreOptions as kt, DescriptorApi as l, ColumnKindsSpec as la, ByIdConfig as li, ThroughSpec as ln, LocaleReadMode as lr, TypionHookEntityApi as lt, TypionTypes as m, KindRead as ma, InputSchema as mi, Register as mn, LocalizationWriteMode as mr, HistoryApi as mt, ContextInput as n, SeedGenerators as na, ReferenceOptions as ni, RegisteredSetup as nn, RESULT as no, MultiTenantTraits as nr, CreateInput_ as nt, TypionMode as o, ColumnKindRuntime as oa, UpdateManyOptions as oi, StructureInput as on, TextTenantColumn as or, Insert_ as ot, TypionEngine as p, KindOf as pa, FirstConfig as pi, TypionConfig as pn, LocalizationReadMode as pr, FieldDiff as pt, Operation as q, ValidationError as qa, PluginErrorInput as qi, softUnique as qn, LinkInput as qr, FoldKinds as qt, Ctx as r, SeedSpec as ra, Row as ri, RegisteredTypes as rn, ReadOp as ro, TenantColumnOf as rr, EntityHooks as rt, BindOptions as s, ColumnKindSpec as sa, UpdateOptions as si, SystemTypion as sn, UuidTenantColumn as sr, Select_ as st, BaseContext as t, SeedColumnsInput as ta, ReadRow as ti, RegisteredPlugins as tn, Op as to, MultiTenantSystemOptions as tr, ChangeOp as tt, EntityName as u, ColumnKindsTypes as ua, CountConfig as ui, TypesOf as un, LocalizationColumnKinds as ur, UpdateInput_ as ut, TransportEntity as v, KindedData as va, Result as vi, GetTypionOptions as vn, localizedUnique as vr, VersionOperation as vt, WireDataEnvelope as w, ReadModeOf as wa, VirtualColumn as wi, AnySetup as wn, Jsonified as wr, VersionsHookArgs as wt, ERROR_STATUS as x, PluginReadOptions as xa, Governed as xi, allowAll as xn, PluginSpecInput as xr, VersionsCollectionOptions as xt, TransportOperation as y, OptionType as ya, Where as yi, getTypion as yn, localizedValue as yr, VersionRef as yt, ColumnMeta as z, InvalidStateError as za, PluginApis as zi, SoftDeleteDeleteOptions as zn, EntityValidation as zr, ColumnsOf as zt };
|
|
2100
|
+
//# sourceMappingURL=context-B4e2eREP.d.ts.map
|