express-file-cluster 0.3.15 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -33
- package/dist/auth/index.cjs +12 -2
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +13 -2
- package/dist/auth/index.d.ts +13 -2
- package/dist/auth/index.js +12 -2
- package/dist/chunk-3VWD2ZED.js +60 -0
- package/dist/chunk-3VWD2ZED.js.map +1 -0
- package/dist/chunk-47K2532L.cjs +196 -0
- package/dist/chunk-47K2532L.cjs.map +1 -0
- package/dist/chunk-5PDAWMGF.js +438 -0
- package/dist/chunk-5PDAWMGF.js.map +1 -0
- package/dist/chunk-7YEX4MQV.cjs +38 -0
- package/dist/chunk-7YEX4MQV.cjs.map +1 -0
- package/dist/chunk-ALBDM5R3.cjs +60 -0
- package/dist/chunk-ALBDM5R3.cjs.map +1 -0
- package/dist/chunk-JJJJTACK.js +196 -0
- package/dist/chunk-JJJJTACK.js.map +1 -0
- package/dist/chunk-LJNSJFOL.js +38 -0
- package/dist/chunk-LJNSJFOL.js.map +1 -0
- package/dist/chunk-M7MUPWCE.js +116 -0
- package/dist/chunk-M7MUPWCE.js.map +1 -0
- package/dist/chunk-PMF4GMHD.js +154 -0
- package/dist/chunk-PMF4GMHD.js.map +1 -0
- package/dist/chunk-QTRGJ2EN.cjs +2635 -0
- package/dist/chunk-QTRGJ2EN.cjs.map +1 -0
- package/dist/chunk-RSBW2B3D.cjs +126 -0
- package/dist/chunk-RSBW2B3D.cjs.map +1 -0
- package/dist/chunk-RTFJ32T5.js +2635 -0
- package/dist/chunk-RTFJ32T5.js.map +1 -0
- package/dist/chunk-SFVEQ2T5.cjs +438 -0
- package/dist/chunk-SFVEQ2T5.cjs.map +1 -0
- package/dist/chunk-SZT36SGB.cjs +154 -0
- package/dist/chunk-SZT36SGB.cjs.map +1 -0
- package/dist/chunk-TI24L4XE.cjs.map +1 -1
- package/dist/chunk-ULQXD4YZ.cjs +116 -0
- package/dist/chunk-ULQXD4YZ.cjs.map +1 -0
- package/dist/chunk-VYHJX54R.js +126 -0
- package/dist/chunk-VYHJX54R.js.map +1 -0
- package/dist/cli/db-runner.cjs +497 -0
- package/dist/cli/db-runner.cjs.map +1 -0
- package/dist/cli/db-runner.d.cts +2 -0
- package/dist/cli/db-runner.d.ts +2 -0
- package/dist/cli/db-runner.js +497 -0
- package/dist/cli/db-runner.js.map +1 -0
- package/dist/cli/index.cjs +447 -69
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +473 -95
- package/dist/cli/index.js.map +1 -1
- package/dist/docs/api-reference/auth.md +232 -0
- package/dist/docs/api-reference/compose.md +78 -0
- package/dist/docs/api-reference/db.md +351 -0
- package/dist/docs/api-reference/http-error.md +109 -0
- package/dist/docs/api-reference/ignite.md +323 -0
- package/dist/docs/api-reference/table.md +250 -0
- package/dist/docs/api-reference/tasks.md +140 -0
- package/dist/docs/cli/db.md +38 -0
- package/dist/docs/cli/diagnostics.md +145 -0
- package/dist/docs/cli/generate.md +120 -0
- package/dist/docs/cli/index.md +48 -0
- package/dist/docs/cli/start.md +112 -0
- package/dist/docs/contributing/index.md +139 -0
- package/dist/docs/core-concepts/background-tasks.md +228 -0
- package/dist/docs/core-concepts/clustering.md +114 -0
- package/dist/docs/core-concepts/file-based-routing.md +235 -0
- package/dist/docs/core-concepts/index.md +79 -0
- package/dist/docs/core-concepts/middleware.md +144 -0
- package/dist/docs/getting-started/index.md +91 -0
- package/dist/docs/getting-started/project-structure.md +154 -0
- package/dist/docs/guides/ai-agents.md +48 -0
- package/dist/docs/guides/authentication.md +196 -0
- package/dist/docs/guides/caching.md +124 -0
- package/dist/docs/guides/database.md +217 -0
- package/dist/docs/guides/deployment.md +171 -0
- package/dist/docs/guides/environment-variables.md +106 -0
- package/dist/docs/guides/error-handling.md +172 -0
- package/dist/docs/guides/generated-portals.md +115 -0
- package/dist/docs/guides/logging.md +70 -0
- package/dist/docs/guides/mailer.md +166 -0
- package/dist/docs/guides/migrations.md +106 -0
- package/dist/docs/guides/rbac.md +89 -0
- package/dist/docs/guides/validation.md +95 -0
- package/dist/docs/index.md +93 -0
- package/dist/docs/skills/SKILL.md +44 -0
- package/dist/docs/skills/api-surface.md +308 -0
- package/dist/docs/skills/auth-internals.md +141 -0
- package/dist/docs/skills/pre-flight.md +142 -0
- package/dist/docs/skills/routing-rules.md +114 -0
- package/dist/docs/skills/tasks-internals.md +172 -0
- package/dist/docs/skills/what-not-to-invent.md +251 -0
- package/dist/index.cjs +289 -391
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +472 -7
- package/dist/index.d.ts +472 -7
- package/dist/index.js +283 -385
- package/dist/index.js.map +1 -1
- package/dist/pgboss-backend-3E6ATY42.cjs +14 -0
- package/dist/pgboss-backend-3E6ATY42.cjs.map +1 -0
- package/dist/pgboss-backend-UUJOVEYK.js +14 -0
- package/dist/pgboss-backend-UUJOVEYK.js.map +1 -0
- package/dist/tasks/index.cjs.map +1 -1
- package/dist/tasks/index.d.cts +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/types-DJCPAsM4.d.cts +541 -0
- package/dist/types-DJCPAsM4.d.ts +541 -0
- package/package.json +28 -5
- package/dist/chunk-6522HS2J.cjs +0 -99
- package/dist/chunk-6522HS2J.cjs.map +0 -1
- package/dist/chunk-DGVOJNR6.cjs +0 -55
- package/dist/chunk-DGVOJNR6.cjs.map +0 -1
- package/dist/chunk-KOHLLUN7.js +0 -55
- package/dist/chunk-KOHLLUN7.js.map +0 -1
- package/dist/chunk-VIP3PFWZ.js +0 -99
- package/dist/chunk-VIP3PFWZ.js.map +0 -1
- package/dist/types-BusbSenn.d.cts +0 -162
- package/dist/types-BusbSenn.d.ts +0 -162
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,373 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
|
-
import { M as ModelSchema,
|
|
3
|
-
export { A as AuthStrategy, C as CorsConfig, D as DatabaseEngine,
|
|
4
|
-
import {
|
|
2
|
+
import { S as Simplify, I as InferSchema, b as InferCreateInput, M as ModelSchema, c as ModelOptions, d as InferredModel, e as TableSchema, f as TableOptions, R as RouteEntry, E as EFCConfig } from './types-DJCPAsM4.js';
|
|
3
|
+
export { A as AuthStrategy, C as CacheConfig, g as CorsConfig, D as DatabaseEngine, h as DefaultOperator, F as FieldDefinition, i as Filter, j as FilterOperators, k as FindOptions, l as IndexDefinition, m as InferCreate, n as InferRecord, L as LoggingConfig, o as MigrationContext, p as ModelCRUD, q as ModelQueryOptions, r as ModelRecord, s as RequestSchema, t as RouteMeta, u as RouteMethodMeta, v as RouteSchema, w as ScalarKeys, x as SchemaField, y as SortDirection, z as TableFieldDefinition, B as TableSchemaField, a as TaskDefinition, T as TaskOptions, U as Update, V as ValidationIssue, G as Validator } from './types-DJCPAsM4.js';
|
|
4
|
+
import { Logger } from 'pino';
|
|
5
|
+
import { Request, RequestHandler } from 'express';
|
|
5
6
|
export { listTasks } from './tasks/index.js';
|
|
6
7
|
|
|
8
|
+
/** `id`'s type from `options.id`: uuid → string, serial → number, bigserial → bigint. */
|
|
9
|
+
type IdOf<O> = O extends {
|
|
10
|
+
id: 'serial';
|
|
11
|
+
} ? number : O extends {
|
|
12
|
+
id: 'bigserial';
|
|
13
|
+
} ? bigint : string;
|
|
14
|
+
/** A row of the table, as every read returns it. */
|
|
15
|
+
type TableRecord<S, O = object> = Simplify<{
|
|
16
|
+
id: IdOf<O>;
|
|
17
|
+
} & InferSchema<S, O>>;
|
|
18
|
+
/** The data `create()` accepts. */
|
|
19
|
+
type TableCreateInput<S> = InferCreateInput<S>;
|
|
20
|
+
type FieldKind<F> = F extends readonly [unknown] ? 'json' : F extends {
|
|
21
|
+
type: 'array';
|
|
22
|
+
of: infer Of;
|
|
23
|
+
} ? Of extends 'object' | 'json' ? 'json' : Of extends string ? 'list' : 'json' : F extends {
|
|
24
|
+
type: 'array' | 'object' | 'json';
|
|
25
|
+
} ? 'json' : F extends {
|
|
26
|
+
type: 'number' | 'integer' | 'bigint' | 'decimal';
|
|
27
|
+
} ? 'number' : F extends {
|
|
28
|
+
type: 'string';
|
|
29
|
+
} ? 'string' : F extends {
|
|
30
|
+
type: string;
|
|
31
|
+
} ? 'scalar' : 'json';
|
|
32
|
+
/** Schema keys + id + timestamps, each with its kind. */
|
|
33
|
+
type Kinds<S, O> = {
|
|
34
|
+
[K in keyof S]: FieldKind<S[K]>;
|
|
35
|
+
} & {
|
|
36
|
+
id: O extends {
|
|
37
|
+
id: 'serial' | 'bigserial';
|
|
38
|
+
} ? 'number' : 'scalar';
|
|
39
|
+
} & {
|
|
40
|
+
[K in keyof TimestampKeys<S, O>]: 'scalar';
|
|
41
|
+
};
|
|
42
|
+
type TimestampKeys<S, O> = Omit<InferSchema<S, O>, keyof S>;
|
|
43
|
+
/** What a filter / write accepts for each field (create-input types; dates also as strings). */
|
|
44
|
+
type Inputs<S, O> = {
|
|
45
|
+
[K in keyof TableRecord<S, O>]-?: K extends keyof TableCreateInput<S> ? Exclude<TableCreateInput<S>[K], undefined> : TableRecord<S, O>[K] extends Date ? Date | string : K extends 'id' ? O extends {
|
|
46
|
+
id: 'bigserial';
|
|
47
|
+
} ? bigint | number : TableRecord<S, O>[K] : TableRecord<S, O>[K];
|
|
48
|
+
};
|
|
49
|
+
type KindOf<S, O, K> = K extends keyof Kinds<S, O> ? Kinds<S, O>[K] : 'scalar';
|
|
50
|
+
type KeysOfKind<S, O, Kd> = {
|
|
51
|
+
[K in keyof TableRecord<S, O>]-?: KindOf<S, O, K> extends Kd ? K : never;
|
|
52
|
+
}[keyof TableRecord<S, O>] & string;
|
|
53
|
+
/** Fields that hold one scalar value: sortable, groupable, min/max-able. */
|
|
54
|
+
type TableScalarKeys<S, O = object> = KeysOfKind<S, O, 'scalar' | 'string' | 'number'>;
|
|
55
|
+
/** Fields `_sum` / `_avg` / `increment` apply to. */
|
|
56
|
+
type TableNumericKeys<S, O = object> = KeysOfKind<S, O, 'number'>;
|
|
57
|
+
interface ScalarFilter<V> {
|
|
58
|
+
equals?: V | null;
|
|
59
|
+
not?: V | null | ScalarFilter<V>;
|
|
60
|
+
in?: V[];
|
|
61
|
+
notIn?: V[];
|
|
62
|
+
lt?: V;
|
|
63
|
+
lte?: V;
|
|
64
|
+
gt?: V;
|
|
65
|
+
gte?: V;
|
|
66
|
+
}
|
|
67
|
+
interface StringFilter<V> extends Omit<ScalarFilter<V>, 'not'> {
|
|
68
|
+
not?: V | null | StringFilter<V>;
|
|
69
|
+
contains?: string;
|
|
70
|
+
startsWith?: string;
|
|
71
|
+
endsWith?: string;
|
|
72
|
+
/** `'insensitive'` → case-insensitive matching (ILIKE). */
|
|
73
|
+
mode?: 'default' | 'insensitive';
|
|
74
|
+
}
|
|
75
|
+
/** Filters for scalar lists (native PostgreSQL arrays). */
|
|
76
|
+
interface ListFilter<I> {
|
|
77
|
+
equals?: I[] | null;
|
|
78
|
+
has?: I | null;
|
|
79
|
+
hasEvery?: I[];
|
|
80
|
+
hasSome?: I[];
|
|
81
|
+
isEmpty?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/** Filters for jsonb fields (embedded objects, arrays of objects, `json`), optionally at a `path`. */
|
|
84
|
+
interface JsonFilter {
|
|
85
|
+
path?: string[];
|
|
86
|
+
equals?: unknown;
|
|
87
|
+
not?: unknown;
|
|
88
|
+
string_contains?: string;
|
|
89
|
+
string_starts_with?: string;
|
|
90
|
+
string_ends_with?: string;
|
|
91
|
+
array_contains?: unknown;
|
|
92
|
+
gt?: number | string | Date;
|
|
93
|
+
gte?: number | string | Date;
|
|
94
|
+
lt?: number | string | Date;
|
|
95
|
+
lte?: number | string | Date;
|
|
96
|
+
mode?: 'default' | 'insensitive';
|
|
97
|
+
}
|
|
98
|
+
type FieldWhere<Kd, V> = Kd extends 'json' ? JsonFilter | V | null : Kd extends 'list' ? ListFilter<V extends readonly (infer I)[] ? I : never> | V | null : Kd extends 'string' ? StringFilter<V> | V | null : ScalarFilter<V> | V | null;
|
|
99
|
+
type TableWhere<S, O = object> = {
|
|
100
|
+
[K in keyof TableRecord<S, O>]?: FieldWhere<KindOf<S, O, K>, Inputs<S, O>[K]> | undefined;
|
|
101
|
+
} & {
|
|
102
|
+
AND?: TableWhere<S, O> | TableWhere<S, O>[];
|
|
103
|
+
OR?: TableWhere<S, O>[];
|
|
104
|
+
NOT?: TableWhere<S, O> | TableWhere<S, O>[];
|
|
105
|
+
};
|
|
106
|
+
type UniqueFields<S> = {
|
|
107
|
+
[K in keyof S]: S[K] extends {
|
|
108
|
+
unique: true;
|
|
109
|
+
} ? K : never;
|
|
110
|
+
}[keyof S];
|
|
111
|
+
type CompoundUniques<O> = O extends {
|
|
112
|
+
indexes: readonly (infer X)[];
|
|
113
|
+
} ? X extends {
|
|
114
|
+
unique: true;
|
|
115
|
+
fields: infer F;
|
|
116
|
+
} ? F : never : never;
|
|
117
|
+
/** All of `Keys` at once (a compound key is not split into its fields). */
|
|
118
|
+
type Selector<S, O, Keys> = [Keys] extends [never] ? never : {
|
|
119
|
+
[P in Extract<keyof Inputs<S, O>, Keys>]: Inputs<S, O>[P];
|
|
120
|
+
};
|
|
121
|
+
/** One selector per key in the union. */
|
|
122
|
+
type EachSelector<S, O, Keys> = Keys extends PropertyKey ? Selector<S, O, Keys> : never;
|
|
123
|
+
/**
|
|
124
|
+
* A `where` that names one record: `id`, a `unique` field, or every field of a unique
|
|
125
|
+
* index — optionally with more filters.
|
|
126
|
+
*/
|
|
127
|
+
type TableWhereUnique<S, O = object> = (Selector<S, O, 'id'> | EachSelector<S, O, UniqueFields<S>> | (CompoundUniques<O> extends infer F ? F extends object ? Selector<S, O, keyof F> : never : never)) & TableWhere<S, O>;
|
|
128
|
+
type SortOrder = 'asc' | 'desc';
|
|
129
|
+
type TableOrderBy<S, O = object> = {
|
|
130
|
+
[K in TableScalarKeys<S, O>]?: SortOrder | {
|
|
131
|
+
sort: SortOrder;
|
|
132
|
+
nulls?: 'first' | 'last';
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
type TableSelect<S, O = object> = {
|
|
136
|
+
[K in keyof TableRecord<S, O>]?: boolean;
|
|
137
|
+
};
|
|
138
|
+
/** The record narrowed by `select` / `omit`, as Prisma does it. */
|
|
139
|
+
type TablePayload<R, A> = A extends {
|
|
140
|
+
select: infer Sel;
|
|
141
|
+
} ? Simplify<{
|
|
142
|
+
[K in keyof R as K extends keyof Sel ? (Sel[K] extends true ? K : never) : never]: R[K];
|
|
143
|
+
}> : A extends {
|
|
144
|
+
omit: infer Om;
|
|
145
|
+
} ? Simplify<{
|
|
146
|
+
[K in keyof R as K extends keyof Om ? (Om[K] extends true ? never : K) : K]: R[K];
|
|
147
|
+
}> : R;
|
|
148
|
+
type Projection<S, O> = {
|
|
149
|
+
select?: TableSelect<S, O>;
|
|
150
|
+
omit?: never;
|
|
151
|
+
} | {
|
|
152
|
+
omit?: TableSelect<S, O>;
|
|
153
|
+
select?: never;
|
|
154
|
+
};
|
|
155
|
+
type TableFindManyArgs<S, O = object> = {
|
|
156
|
+
where?: TableWhere<S, O>;
|
|
157
|
+
orderBy?: TableOrderBy<S, O> | TableOrderBy<S, O>[];
|
|
158
|
+
/** Page size; negative reads backwards (from the end, or before `cursor`). */
|
|
159
|
+
take?: number;
|
|
160
|
+
skip?: number;
|
|
161
|
+
/** Start at this record (inclusive — add `skip: 1` to start after it). */
|
|
162
|
+
cursor?: TableWhereUnique<S, O>;
|
|
163
|
+
/** One record per distinct combination of these fields (the first in `orderBy`). */
|
|
164
|
+
distinct?: TableScalarKeys<S, O>[];
|
|
165
|
+
} & Projection<S, O>;
|
|
166
|
+
type TableFindUniqueArgs<S, O = object> = {
|
|
167
|
+
where: TableWhereUnique<S, O>;
|
|
168
|
+
} & Projection<S, O>;
|
|
169
|
+
type NumberOp<V> = {
|
|
170
|
+
set?: V | null;
|
|
171
|
+
increment?: V;
|
|
172
|
+
decrement?: V;
|
|
173
|
+
multiply?: V;
|
|
174
|
+
divide?: V;
|
|
175
|
+
};
|
|
176
|
+
type ListOp<V> = {
|
|
177
|
+
set?: V | null;
|
|
178
|
+
push?: (V extends readonly (infer I)[] ? I : never) | V;
|
|
179
|
+
};
|
|
180
|
+
/** Update data: values (`null` unsets) or Prisma operations per field kind. */
|
|
181
|
+
type TableUpdateData<S, O = object> = {
|
|
182
|
+
[K in keyof TableCreateInput<S>]?: Inputs<S, O>[K & keyof Inputs<S, O>] | null | undefined | (KindOf<S, O, K> extends 'number' ? NumberOp<Inputs<S, O>[K & keyof Inputs<S, O>]> : KindOf<S, O, K> extends 'list' ? ListOp<Inputs<S, O>[K & keyof Inputs<S, O>]> : KindOf<S, O, K> extends 'json' ? never : {
|
|
183
|
+
set?: Inputs<S, O>[K & keyof Inputs<S, O>] | null;
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
type AggFields<Keys extends string> = {
|
|
187
|
+
[K in Keys]?: true;
|
|
188
|
+
};
|
|
189
|
+
type TableAggregateArgs<S, O = object> = Omit<TableFindManyArgs<S, O>, 'select' | 'omit' | 'distinct'> & {
|
|
190
|
+
_count?: true | ({
|
|
191
|
+
_all?: true;
|
|
192
|
+
} & AggFields<keyof TableRecord<S, O> & string>);
|
|
193
|
+
_sum?: AggFields<TableNumericKeys<S, O>>;
|
|
194
|
+
_avg?: AggFields<TableNumericKeys<S, O>>;
|
|
195
|
+
_min?: AggFields<TableScalarKeys<S, O>>;
|
|
196
|
+
_max?: AggFields<TableScalarKeys<S, O>>;
|
|
197
|
+
};
|
|
198
|
+
type SumOf<S, K> = K extends keyof S ? S[K] extends {
|
|
199
|
+
type: 'bigint';
|
|
200
|
+
} ? bigint : S[K] extends {
|
|
201
|
+
type: 'decimal';
|
|
202
|
+
} ? string : number : number;
|
|
203
|
+
type AvgOf<S, K> = K extends keyof S ? S[K] extends {
|
|
204
|
+
type: 'decimal';
|
|
205
|
+
} ? string : number : number;
|
|
206
|
+
/** What `aggregate()` / `groupBy()` return for the requested aggregates. */
|
|
207
|
+
type TableAggregateResult<S, O, A> = Simplify<(A extends {
|
|
208
|
+
_count: infer C;
|
|
209
|
+
} ? {
|
|
210
|
+
_count: C extends true ? number : {
|
|
211
|
+
-readonly [K in keyof C]: number;
|
|
212
|
+
};
|
|
213
|
+
} : unknown) & (A extends {
|
|
214
|
+
_sum: infer X;
|
|
215
|
+
} ? {
|
|
216
|
+
_sum: {
|
|
217
|
+
-readonly [K in keyof X]: SumOf<S, K> | null;
|
|
218
|
+
};
|
|
219
|
+
} : unknown) & (A extends {
|
|
220
|
+
_avg: infer X;
|
|
221
|
+
} ? {
|
|
222
|
+
_avg: {
|
|
223
|
+
-readonly [K in keyof X]: AvgOf<S, K> | null;
|
|
224
|
+
};
|
|
225
|
+
} : unknown) & (A extends {
|
|
226
|
+
_min: infer X;
|
|
227
|
+
} ? {
|
|
228
|
+
_min: {
|
|
229
|
+
-readonly [K in keyof X & keyof TableRecord<S, O>]: NonNullable<TableRecord<S, O>[K]> | null;
|
|
230
|
+
};
|
|
231
|
+
} : unknown) & (A extends {
|
|
232
|
+
_max: infer X;
|
|
233
|
+
} ? {
|
|
234
|
+
_max: {
|
|
235
|
+
-readonly [K in keyof X & keyof TableRecord<S, O>]: NonNullable<TableRecord<S, O>[K]> | null;
|
|
236
|
+
};
|
|
237
|
+
} : unknown)>;
|
|
238
|
+
type AggFilter = {
|
|
239
|
+
equals?: number | string | bigint;
|
|
240
|
+
not?: number | string | bigint;
|
|
241
|
+
gt?: number | string | bigint;
|
|
242
|
+
gte?: number | string | bigint;
|
|
243
|
+
lt?: number | string | bigint;
|
|
244
|
+
lte?: number | string | bigint;
|
|
245
|
+
};
|
|
246
|
+
type TableHaving<S, O = object> = {
|
|
247
|
+
[K in TableScalarKeys<S, O>]?: FieldWhere<KindOf<S, O, K>, Inputs<S, O>[K & keyof Inputs<S, O>]> | {
|
|
248
|
+
_count?: AggFilter;
|
|
249
|
+
_sum?: AggFilter;
|
|
250
|
+
_avg?: AggFilter;
|
|
251
|
+
_min?: AggFilter;
|
|
252
|
+
_max?: AggFilter;
|
|
253
|
+
};
|
|
254
|
+
} & {
|
|
255
|
+
AND?: TableHaving<S, O> | TableHaving<S, O>[];
|
|
256
|
+
OR?: TableHaving<S, O>[];
|
|
257
|
+
NOT?: TableHaving<S, O> | TableHaving<S, O>[];
|
|
258
|
+
};
|
|
259
|
+
type AggOrder<Keys extends string> = {
|
|
260
|
+
[K in Keys]?: SortOrder;
|
|
261
|
+
};
|
|
262
|
+
type TableGroupByArgs<S, O = object> = {
|
|
263
|
+
by: TableScalarKeys<S, O>[];
|
|
264
|
+
where?: TableWhere<S, O>;
|
|
265
|
+
having?: TableHaving<S, O>;
|
|
266
|
+
orderBy?: GroupOrder<S, O> | GroupOrder<S, O>[];
|
|
267
|
+
take?: number;
|
|
268
|
+
skip?: number;
|
|
269
|
+
} & Pick<TableAggregateArgs<S, O>, '_count' | '_sum' | '_avg' | '_min' | '_max'>;
|
|
270
|
+
type GroupOrder<S, O> = TableOrderBy<S, O> & {
|
|
271
|
+
_count?: AggOrder<keyof TableRecord<S, O> & string>;
|
|
272
|
+
_sum?: AggOrder<TableNumericKeys<S, O>>;
|
|
273
|
+
_avg?: AggOrder<TableNumericKeys<S, O>>;
|
|
274
|
+
_min?: AggOrder<TableScalarKeys<S, O>>;
|
|
275
|
+
_max?: AggOrder<TableScalarKeys<S, O>>;
|
|
276
|
+
};
|
|
277
|
+
type TableCountArgs<S, O = object> = Omit<TableFindManyArgs<S, O>, 'select' | 'omit'> & {
|
|
278
|
+
/** Count non-null values per field: `{ _all: true, email: true }` → `{ _all, email }`. */
|
|
279
|
+
select?: {
|
|
280
|
+
_all?: true;
|
|
281
|
+
} & AggFields<keyof TableRecord<S, O> & string>;
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* A `defineTable` model: PostgreSQL-native, Prisma-style. Reads and writes return records
|
|
285
|
+
* typed from the schema, narrowed by `select` / `omit`.
|
|
286
|
+
*/
|
|
287
|
+
interface TableModel<S, O = object> {
|
|
288
|
+
readonly name: string;
|
|
289
|
+
/** Type-level only (always `undefined`): what `InferRecord` / `InferCreate` read. */
|
|
290
|
+
readonly $types?: {
|
|
291
|
+
record: TableRecord<S, O>;
|
|
292
|
+
create: TableCreateInput<S>;
|
|
293
|
+
};
|
|
294
|
+
findMany<const A extends TableFindManyArgs<S, O>>(args?: A): Promise<TablePayload<TableRecord<S, O>, A>[]>;
|
|
295
|
+
findFirst<const A extends TableFindManyArgs<S, O>>(args?: A): Promise<TablePayload<TableRecord<S, O>, A> | null>;
|
|
296
|
+
/** Like `findFirst`, but 404 (`HttpError`) when nothing matches. */
|
|
297
|
+
findFirstOrThrow<const A extends TableFindManyArgs<S, O>>(args?: A): Promise<TablePayload<TableRecord<S, O>, A>>;
|
|
298
|
+
findUnique<const A extends TableFindUniqueArgs<S, O>>(args: A): Promise<TablePayload<TableRecord<S, O>, A> | null>;
|
|
299
|
+
/** Like `findUnique`, but 404 (`HttpError`) when nothing matches. */
|
|
300
|
+
findUniqueOrThrow<const A extends TableFindUniqueArgs<S, O>>(args: A): Promise<TablePayload<TableRecord<S, O>, A>>;
|
|
301
|
+
count<const A extends TableCountArgs<S, O>>(args?: A): Promise<A extends {
|
|
302
|
+
select: infer Sel;
|
|
303
|
+
} ? {
|
|
304
|
+
-readonly [K in keyof Sel]: number;
|
|
305
|
+
} : number>;
|
|
306
|
+
aggregate<const A extends TableAggregateArgs<S, O>>(args: A): Promise<TableAggregateResult<S, O, A>>;
|
|
307
|
+
groupBy<const A extends TableGroupByArgs<S, O>>(args: A): Promise<Simplify<{
|
|
308
|
+
[K in A['by'][number] & keyof TableRecord<S, O>]: NonNullable<TableRecord<S, O>[K]> | null;
|
|
309
|
+
} & TableAggregateResult<S, O, A>>[]>;
|
|
310
|
+
create<const A extends {
|
|
311
|
+
data: TableCreateInput<S>;
|
|
312
|
+
} & Projection<S, O>>(args: A): Promise<TablePayload<TableRecord<S, O>, A>>;
|
|
313
|
+
/** Inserts many rows in one statement; `skipDuplicates` → `ON CONFLICT DO NOTHING`. */
|
|
314
|
+
createMany(args: {
|
|
315
|
+
data: TableCreateInput<S> | TableCreateInput<S>[];
|
|
316
|
+
skipDuplicates?: boolean;
|
|
317
|
+
}): Promise<{
|
|
318
|
+
count: number;
|
|
319
|
+
}>;
|
|
320
|
+
createManyAndReturn<const A extends {
|
|
321
|
+
data: TableCreateInput<S> | TableCreateInput<S>[];
|
|
322
|
+
skipDuplicates?: boolean;
|
|
323
|
+
} & Projection<S, O>>(args: A): Promise<TablePayload<TableRecord<S, O>, A>[]>;
|
|
324
|
+
/** Updates the record `where` names; 404 if there is none. */
|
|
325
|
+
update<const A extends {
|
|
326
|
+
where: TableWhereUnique<S, O>;
|
|
327
|
+
data: TableUpdateData<S, O>;
|
|
328
|
+
} & Projection<S, O>>(args: A): Promise<TablePayload<TableRecord<S, O>, A>>;
|
|
329
|
+
updateMany(args: {
|
|
330
|
+
where?: TableWhere<S, O>;
|
|
331
|
+
data: TableUpdateData<S, O>;
|
|
332
|
+
}): Promise<{
|
|
333
|
+
count: number;
|
|
334
|
+
}>;
|
|
335
|
+
updateManyAndReturn<const A extends {
|
|
336
|
+
where?: TableWhere<S, O>;
|
|
337
|
+
data: TableUpdateData<S, O>;
|
|
338
|
+
} & Projection<S, O>>(args: A): Promise<TablePayload<TableRecord<S, O>, A>[]>;
|
|
339
|
+
/**
|
|
340
|
+
* One `INSERT … ON CONFLICT (<unique key>) DO UPDATE` — atomic, race-free. `where` must
|
|
341
|
+
* name a unique key; its values fill `create` when missing there.
|
|
342
|
+
*/
|
|
343
|
+
upsert<const A extends {
|
|
344
|
+
where: TableWhereUnique<S, O>;
|
|
345
|
+
create: TableCreateInput<S>;
|
|
346
|
+
update: TableUpdateData<S, O>;
|
|
347
|
+
} & Projection<S, O>>(args: A): Promise<TablePayload<TableRecord<S, O>, A>>;
|
|
348
|
+
/** Deletes the record `where` names and returns it; 404 if there is none. */
|
|
349
|
+
delete<const A extends {
|
|
350
|
+
where: TableWhereUnique<S, O>;
|
|
351
|
+
} & Projection<S, O>>(args: A): Promise<TablePayload<TableRecord<S, O>, A>>;
|
|
352
|
+
deleteMany(args?: {
|
|
353
|
+
where?: TableWhere<S, O>;
|
|
354
|
+
}): Promise<{
|
|
355
|
+
count: number;
|
|
356
|
+
}>;
|
|
357
|
+
/** The Drizzle `pgTable` behind the model. */
|
|
358
|
+
raw(): Promise<unknown>;
|
|
359
|
+
sync(options?: {
|
|
360
|
+
dryRun?: boolean;
|
|
361
|
+
}): Promise<string[]>;
|
|
362
|
+
drop(): Promise<void>;
|
|
363
|
+
}
|
|
364
|
+
/** The record type of a `defineTable` model: `type Order = InferTableRecord<typeof Order>`. */
|
|
365
|
+
type InferTableRecord<M> = M extends {
|
|
366
|
+
$types?: {
|
|
367
|
+
record: infer R;
|
|
368
|
+
};
|
|
369
|
+
} ? R : never;
|
|
370
|
+
|
|
7
371
|
/**
|
|
8
372
|
* Represents an HTTP error with a status code and message.
|
|
9
373
|
* Throw this inside any route handler to send a structured error response.
|
|
@@ -45,6 +409,65 @@ declare class HttpError extends Error {
|
|
|
45
409
|
*/
|
|
46
410
|
declare function isHttpError(value: unknown): value is HttpError;
|
|
47
411
|
|
|
412
|
+
/**
|
|
413
|
+
* The logger for the current scope: inside a request it is a child carrying that
|
|
414
|
+
* request's `reqId`, so everything logged while handling it can be correlated;
|
|
415
|
+
* elsewhere (startup, task handlers, timers) it is the root logger.
|
|
416
|
+
*/
|
|
417
|
+
declare function getLogger(): Logger;
|
|
418
|
+
/** Root logger proxy — always reflects the latest configureLogger() call. */
|
|
419
|
+
declare const logger: Logger;
|
|
420
|
+
declare module 'express-serve-static-core' {
|
|
421
|
+
interface Request {
|
|
422
|
+
/** Request ID — the incoming `X-Request-Id` if well-formed, else a UUID. */
|
|
423
|
+
id: string;
|
|
424
|
+
/** Logger bound to this request's ID. */
|
|
425
|
+
log: Logger;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
interface CacheSetOptions {
|
|
430
|
+
/** Seconds until the entry expires. Omit for no expiry. */
|
|
431
|
+
ttl?: number;
|
|
432
|
+
}
|
|
433
|
+
interface Cache {
|
|
434
|
+
/** The cached value, or `undefined` on a miss (or when the backend is unreachable). */
|
|
435
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
436
|
+
set(key: string, value: unknown, options?: CacheSetOptions): Promise<void>;
|
|
437
|
+
has(key: string): Promise<boolean>;
|
|
438
|
+
/** Deletes keys; returns how many existed. */
|
|
439
|
+
del(...keys: string[]): Promise<number>;
|
|
440
|
+
/**
|
|
441
|
+
* Returns the cached value, or runs `fn`, caches its result and returns it.
|
|
442
|
+
* Concurrent calls for the same key in one process share a single `fn` run.
|
|
443
|
+
* `undefined` results are not cached.
|
|
444
|
+
*/
|
|
445
|
+
wrap<T>(key: string, options: CacheSetOptions | number, fn: () => Promise<T>): Promise<T>;
|
|
446
|
+
/** Deletes every key starting with `keyPrefix` (all of this app's keys when omitted). */
|
|
447
|
+
clear(keyPrefix?: string): Promise<number>;
|
|
448
|
+
}
|
|
449
|
+
declare const cache: Cache;
|
|
450
|
+
|
|
451
|
+
interface CacheResponseOptions {
|
|
452
|
+
/** Seconds to keep a response. */
|
|
453
|
+
ttl: number;
|
|
454
|
+
/**
|
|
455
|
+
* Cache per authenticated user (keyed by the JWT's `sub`/`id`). Put `requireAuth`
|
|
456
|
+
* before this middleware. Without it, a response is shared by everyone hitting the URL.
|
|
457
|
+
*/
|
|
458
|
+
perUser?: boolean;
|
|
459
|
+
/** Custom cache key. Default: the request's original URL (path + query). */
|
|
460
|
+
key?: (req: Request) => string;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Caches successful (200) JSON responses of GET/HEAD requests. Adds `X-Cache: HIT|MISS`.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* export const middlewares = [cacheResponse(60)];
|
|
467
|
+
* export const middlewares = [requireAuth, cacheResponse({ ttl: 30, perUser: true })];
|
|
468
|
+
*/
|
|
469
|
+
declare function cacheResponse(options: number | CacheResponseOptions): RequestHandler;
|
|
470
|
+
|
|
48
471
|
/**
|
|
49
472
|
* Chains multiple Express request handlers into a single handler.
|
|
50
473
|
* Each handler calls the next one via its `next` callback.
|
|
@@ -54,17 +477,59 @@ declare function isHttpError(value: unknown): value is HttpError;
|
|
|
54
477
|
*/
|
|
55
478
|
declare function compose(...handlers: RequestHandler[]): RequestHandler;
|
|
56
479
|
|
|
57
|
-
|
|
480
|
+
/**
|
|
481
|
+
* Defines a model once; it compiles to a mongoose model on MongoDB or a Drizzle table
|
|
482
|
+
* on PostgreSQL — whichever engine Pre-Flight connected — the first time it is used,
|
|
483
|
+
* so route files can define models at import time, before the database is up.
|
|
484
|
+
*
|
|
485
|
+
* Record and create-input types are inferred from the schema
|
|
486
|
+
* (`InferRecord<typeof User>`); `defineModel<User>(...)` still takes an explicit type.
|
|
487
|
+
*/
|
|
488
|
+
declare function defineModel<T extends object = never, const S extends ModelSchema = ModelSchema, const O extends ModelOptions = ModelOptions>(name: string, schema: S, options?: O): InferredModel<T, S, O>;
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Defines a PostgreSQL-native model with Prisma's query vocabulary — `findMany`,
|
|
492
|
+
* `findUnique`, `upsert`, `groupBy`, `aggregate` — and SQL types (`integer`, `bigint`,
|
|
493
|
+
* `decimal`, `varchar`, native arrays and enums, serial ids). Record, input, filter and
|
|
494
|
+
* result types are inferred from the schema. Throws at first use on a MongoDB connection.
|
|
495
|
+
*/
|
|
496
|
+
declare function defineTable<const S extends TableSchema, const O extends TableOptions = object>(name: string, schema: S, options?: O): TableModel<S, O>;
|
|
58
497
|
|
|
59
498
|
type AnyClient = Record<string, unknown>;
|
|
60
499
|
declare function setDbClient(client: AnyClient): void;
|
|
61
500
|
declare function getDbClient(): AnyClient;
|
|
62
501
|
declare const db: AnyClient;
|
|
63
502
|
|
|
503
|
+
/**
|
|
504
|
+
* Runs `fn` in a database transaction. Every model call inside it — however deeply
|
|
505
|
+
* nested, through awaits — joins the transaction automatically; throwing rolls it all
|
|
506
|
+
* back. Nested calls reuse the outer transaction.
|
|
507
|
+
*
|
|
508
|
+
* MongoDB transactions need a replica set (Atlas, or `mongod --replSet`).
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* await transaction(async () => {
|
|
512
|
+
* const order = await Order.create({ total: 40 });
|
|
513
|
+
* await Stock.update(itemId, { $inc: { count: -1 } });
|
|
514
|
+
* });
|
|
515
|
+
*/
|
|
516
|
+
declare function transaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
517
|
+
|
|
518
|
+
interface FieldIssue {
|
|
519
|
+
path: string;
|
|
520
|
+
message: string;
|
|
521
|
+
}
|
|
522
|
+
/** Thrown by every model write that fails validation, on either engine. → HTTP 400. */
|
|
523
|
+
declare class ModelValidationError extends HttpError {
|
|
524
|
+
readonly issues: FieldIssue[];
|
|
525
|
+
constructor(model: string, issues: FieldIssue[]);
|
|
526
|
+
}
|
|
527
|
+
|
|
64
528
|
/**
|
|
65
529
|
* Recursively scans `dir` for route files and returns a sorted list of
|
|
66
|
-
* `RouteEntry` objects
|
|
67
|
-
*
|
|
530
|
+
* `RouteEntry` objects, most specific first: at each path position a static
|
|
531
|
+
* segment beats `[id]`, which beats `[[id]]`, then `[...slug]`, then
|
|
532
|
+
* `[[...slug]]`. Ties are sorted alphabetically.
|
|
68
533
|
*
|
|
69
534
|
* @param dir - Root directory to scan (must exist).
|
|
70
535
|
* @param base - Base directory used to derive relative URL paths; defaults to `dir`.
|
|
@@ -83,4 +548,4 @@ declare function workerCount(): number;
|
|
|
83
548
|
declare function ignite(config: EFCConfig): Promise<http.Server | undefined>;
|
|
84
549
|
declare function gracefulShutdown(server: http.Server | undefined, timeoutMs?: number): void;
|
|
85
550
|
|
|
86
|
-
export { EFCConfig, HttpError,
|
|
551
|
+
export { EFCConfig, HttpError, InferCreateInput, InferSchema, type InferTableRecord, type JsonFilter, type ListFilter, ModelOptions, ModelSchema, ModelValidationError, RouteEntry, type ScalarFilter, type StringFilter, type TableAggregateArgs, type TableAggregateResult, type TableCreateInput, type TableFindManyArgs, type TableGroupByArgs, type TableModel, TableOptions, type TableOrderBy, type TableRecord, TableSchema, type TableSelect, type TableUpdateData, type TableWhere, type TableWhereUnique, cache, cacheResponse, compose, db, defineModel, defineTable, getDbClient, getLogger, gracefulShutdown, ignite, isHttpError, logger, scanDir, setDbClient, transaction, workerCount };
|