express-file-cluster 0.5.0 → 0.7.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 +2 -2
- package/dist/auth/index.cjs +5 -5
- package/dist/auth/index.d.cts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +4 -4
- package/dist/{chunk-VYHJX54R.js → chunk-277BSYVH.js} +2 -1
- package/dist/chunk-277BSYVH.js.map +1 -0
- package/dist/{chunk-RTFJ32T5.js → chunk-6OGOVV57.js} +1344 -132
- package/dist/chunk-6OGOVV57.js.map +1 -0
- package/dist/{chunk-QTRGJ2EN.cjs → chunk-AZYXQU3Z.cjs} +1378 -166
- package/dist/chunk-AZYXQU3Z.cjs.map +1 -0
- package/dist/chunk-BUBXO7WU.js +170 -0
- package/dist/chunk-BUBXO7WU.js.map +1 -0
- package/dist/chunk-MGH4VDV3.cjs +170 -0
- package/dist/chunk-MGH4VDV3.cjs.map +1 -0
- package/dist/{chunk-ULQXD4YZ.cjs → chunk-R34R7QPD.cjs} +3 -3
- package/dist/{chunk-ULQXD4YZ.cjs.map → chunk-R34R7QPD.cjs.map} +1 -1
- package/dist/{chunk-M7MUPWCE.js → chunk-RS4MXCPW.js} +2 -2
- package/dist/{chunk-SZT36SGB.cjs → chunk-T4OHFU5T.cjs} +8 -8
- package/dist/{chunk-SZT36SGB.cjs.map → chunk-T4OHFU5T.cjs.map} +1 -1
- package/dist/{chunk-5PDAWMGF.js → chunk-TRC4DUZB.js} +4 -4
- package/dist/{chunk-47K2532L.cjs → chunk-TYR2GZZE.cjs} +7 -7
- package/dist/{chunk-47K2532L.cjs.map → chunk-TYR2GZZE.cjs.map} +1 -1
- package/dist/{chunk-PMF4GMHD.js → chunk-UBQYQPBU.js} +2 -2
- package/dist/{chunk-JJJJTACK.js → chunk-UTM4PEVG.js} +2 -2
- package/dist/{chunk-RSBW2B3D.cjs → chunk-YL37D6KM.cjs} +3 -2
- package/dist/chunk-YL37D6KM.cjs.map +1 -0
- package/dist/{chunk-SFVEQ2T5.cjs → chunk-ZDM5JHVK.cjs} +11 -11
- package/dist/{chunk-SFVEQ2T5.cjs.map → chunk-ZDM5JHVK.cjs.map} +1 -1
- package/dist/cli/db-runner.cjs +10 -10
- package/dist/cli/db-runner.js +3 -3
- package/dist/cli/index.cjs +6 -6
- package/dist/cli/index.js +4 -4
- package/dist/docs/api-reference/ignite.md +3 -0
- package/dist/docs/api-reference/table.md +210 -2
- package/dist/docs/guides/logging.md +38 -0
- package/dist/docs/index.md +1 -1
- package/dist/docs/skills/SKILL.md +2 -2
- package/dist/docs/skills/api-surface.md +2 -1
- package/dist/docs/skills/what-not-to-invent.md +1 -1
- package/dist/index.cjs +44 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +248 -21
- package/dist/index.d.ts +248 -21
- package/dist/index.js +12 -37
- package/dist/index.js.map +1 -1
- package/dist/{pgboss-backend-UUJOVEYK.js → pgboss-backend-QKBXVJ6B.js} +3 -3
- package/dist/pgboss-backend-TCHI7CHM.cjs +14 -0
- package/dist/{pgboss-backend-3E6ATY42.cjs.map → pgboss-backend-TCHI7CHM.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 → types-B6lVw4bj.d.cts} +49 -2
- package/dist/{types-DJCPAsM4.d.ts → types-B6lVw4bj.d.ts} +49 -2
- package/package.json +1 -1
- package/dist/chunk-3VWD2ZED.js +0 -60
- package/dist/chunk-3VWD2ZED.js.map +0 -1
- package/dist/chunk-ALBDM5R3.cjs +0 -60
- package/dist/chunk-ALBDM5R3.cjs.map +0 -1
- package/dist/chunk-QTRGJ2EN.cjs.map +0 -1
- package/dist/chunk-RSBW2B3D.cjs.map +0 -1
- package/dist/chunk-RTFJ32T5.js.map +0 -1
- package/dist/chunk-VYHJX54R.js.map +0 -1
- package/dist/pgboss-backend-3E6ATY42.cjs +0 -14
- /package/dist/{chunk-M7MUPWCE.js.map → chunk-RS4MXCPW.js.map} +0 -0
- /package/dist/{chunk-5PDAWMGF.js.map → chunk-TRC4DUZB.js.map} +0 -0
- /package/dist/{chunk-PMF4GMHD.js.map → chunk-UBQYQPBU.js.map} +0 -0
- /package/dist/{chunk-JJJJTACK.js.map → chunk-UTM4PEVG.js.map} +0 -0
- /package/dist/{pgboss-backend-UUJOVEYK.js.map → pgboss-backend-QKBXVJ6B.js.map} +0 -0
|
@@ -83,6 +83,7 @@ interface TableOptions {
|
|
|
83
83
|
timestamps?: boolean | { createdAt?: string | false; updatedAt?: string | false };
|
|
84
84
|
indexes?: { fields: Record<string, 1 | -1 | 'text'>; unique?: boolean; name?: string }[];
|
|
85
85
|
collection?: string; // table name
|
|
86
|
+
relations?: Record<string, { hasMany: string; foreignKey: string } | { hasOne: string; foreignKey: string }>; // see Include
|
|
86
87
|
}
|
|
87
88
|
```
|
|
88
89
|
|
|
@@ -98,6 +99,154 @@ never drops columns or rows. On top of that:
|
|
|
98
99
|
|
|
99
100
|
Preview the changes with `efc db sync --dry-run`.
|
|
100
101
|
|
|
102
|
+
### Foreign keys
|
|
103
|
+
|
|
104
|
+
A top-level `ref` field is a real foreign key to the referenced model's `id`:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
export const Author = defineTable('Author', { name: { type: 'string', required: true } });
|
|
108
|
+
export const Category = defineTable('Category', {
|
|
109
|
+
name: { type: 'string', required: true },
|
|
110
|
+
parent: { type: 'integer', ref: 'Category', onDelete: 'setNull' }, // self-relation
|
|
111
|
+
}, { id: 'serial' });
|
|
112
|
+
|
|
113
|
+
export const Post = defineTable('Post', {
|
|
114
|
+
title: { type: 'string', required: true },
|
|
115
|
+
author: { type: 'uuid', ref: 'Author', required: true, onDelete: 'cascade' },
|
|
116
|
+
reviewer: { type: 'uuid', ref: 'Author' }, // onDelete: 'restrict'
|
|
117
|
+
category: { type: 'integer', ref: 'Category' },
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
| `onDelete` | Deleting the referenced record… |
|
|
122
|
+
|---|---|
|
|
123
|
+
| `'restrict'` (default) | is refused with a **409** while records point at it |
|
|
124
|
+
| `'cascade'` | deletes the records pointing at it too |
|
|
125
|
+
| `'setNull'` | clears the field on those records (not allowed on `required` fields) |
|
|
126
|
+
|
|
127
|
+
- The field's `type` must match the target's id: `uuid` (or `objectId`) for `id: 'uuid'`,
|
|
128
|
+
`integer` for `'serial'`, `bigint` for `'bigserial'`. A mismatch fails at first use, saying
|
|
129
|
+
which type to declare.
|
|
130
|
+
- Writing an id that doesn't exist is a **400** on that field (`author: Author not found`).
|
|
131
|
+
- Ref columns get an index (`<table>_<column>_idx`) unless `index: false`.
|
|
132
|
+
- The referenced model must be defined (imported) before the model that references it is used.
|
|
133
|
+
- The value is still the id: `post.author` is a string (or number). Loading the referenced
|
|
134
|
+
record with `include` comes next (M3b).
|
|
135
|
+
|
|
136
|
+
Sync creates a missing target table first, then adds the key `NOT VALID` (instant, and existing
|
|
137
|
+
rows can't fail the deploy) and validates it right after the commit. If old rows point at
|
|
138
|
+
records that no longer exist, validation is skipped with a warning naming the count. The key
|
|
139
|
+
still applies to new writes; fix the rows and run `efc db sync` to validate it. Changing
|
|
140
|
+
`onDelete` replaces the key, and removing `ref` drops it. Foreign keys on columns the model
|
|
141
|
+
doesn't declare are left alone.
|
|
142
|
+
|
|
143
|
+
`defineModel` keeps `ref` portable: on PostgreSQL it stays a plain column with no foreign key,
|
|
144
|
+
the same as on MongoDB.
|
|
145
|
+
|
|
146
|
+
### Many-to-many
|
|
147
|
+
|
|
148
|
+
An array of refs is a many-to-many relation:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
export const Tag = defineTable('Tag', { label: { type: 'string', required: true, unique: true } });
|
|
152
|
+
export const Post = defineTable('Post', {
|
|
153
|
+
title: { type: 'string', required: true },
|
|
154
|
+
tags: { type: 'array', of: 'uuid', ref: 'Tag' }, // of: matches Tag's id type
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const post = await Post.create({ data: { title: 'Hello', tags: [news, tech] } });
|
|
158
|
+
post.tags; // [news, tech] — ids, in order
|
|
159
|
+
await Post.findMany({ where: { tags: { has: tech } } });
|
|
160
|
+
await Post.update({ where: { id: post.id }, data: { tags: { push: launch } } });
|
|
161
|
+
await Post.update({ where: { id: post.id }, data: { tags: { set: [tech] } } });
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
- Records keep the list of ids (`string[]`, `number[]` or `bigint[]`), in the order written, without
|
|
165
|
+
duplicates. New records start with `[]`.
|
|
166
|
+
- Filters are the list filters: `has`, `hasSome`, `hasEvery`, `isEmpty`, `equals`. Updates take a
|
|
167
|
+
list, `{ set: [...] }` or `{ push: id | [...] }` (ids already linked are left in place).
|
|
168
|
+
`select` / `omit` work as for any field. Ordering, grouping and `_sum`-style aggregates on the
|
|
169
|
+
field are refused.
|
|
170
|
+
- The links live in a join table, `<table>_<column>` (`posts_tags`): `owner_id`, `ref_id`,
|
|
171
|
+
`position`, primary key `(owner_id, ref_id)`, an index on `ref_id`, and foreign keys to both
|
|
172
|
+
tables with `ON DELETE CASCADE`. Deleting a post or a tag removes its links (a deleted tag
|
|
173
|
+
disappears from every post's `tags`). There is no `onDelete` option for these fields.
|
|
174
|
+
- An id that doesn't exist is a **400** on the field, and nothing is written.
|
|
175
|
+
- Reads stay one statement (the list is a subquery). A write that changes links runs in a
|
|
176
|
+
transaction: the row, then the links.
|
|
177
|
+
- Self-relations work (`friends: { type: 'array', of: 'uuid', ref: 'Person' }`).
|
|
178
|
+
|
|
179
|
+
**Moving from an array column.** If the table already stores the field as an array (`uuid[]`,
|
|
180
|
+
or `jsonb` from `defineModel`), the first sync copies it into the join table, keeping the order
|
|
181
|
+
and skipping values that aren't ids. The old column stays (sync never drops columns) but is no
|
|
182
|
+
longer read or written, so a `defineModel` over the same table won't see later changes to the
|
|
183
|
+
list.
|
|
184
|
+
|
|
185
|
+
### Include
|
|
186
|
+
|
|
187
|
+
`include` loads related records into the result: a `ref` field becomes the record it points at,
|
|
188
|
+
a many-to-many field the list of records, and back-relations — declared with `relations` —
|
|
189
|
+
the records pointing here.
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
export const User = defineTable('User', { email: { type: 'string', required: true, unique: true } }, {
|
|
193
|
+
relations: {
|
|
194
|
+
posts: { hasMany: 'Post', foreignKey: 'author' }, // Post.author refs User
|
|
195
|
+
profile: { hasOne: 'Profile', foreignKey: 'user' }, // Profile.user refs User, unique
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
export const Tag = defineTable('Tag', { label: { type: 'string', required: true } }, {
|
|
199
|
+
relations: { posts: { hasMany: 'Post', foreignKey: 'tags' } }, // through Post.tags (m:n)
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const users = await User.findMany({
|
|
203
|
+
include: {
|
|
204
|
+
profile: true,
|
|
205
|
+
posts: {
|
|
206
|
+
where: { published: true },
|
|
207
|
+
orderBy: { createdAt: 'desc' },
|
|
208
|
+
take: 5,
|
|
209
|
+
select: { title: true },
|
|
210
|
+
include: { tags: { select: { label: true } } },
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
// [{ id, email, …, profile: { … } | null, posts: [{ title, tags: [{ label }] }] }]
|
|
215
|
+
|
|
216
|
+
await Post.findUnique({ where: { id }, include: { author: true } }); // author: { … } | null
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
| Relation | Declared as | `include` gives |
|
|
220
|
+
|---|---|---|
|
|
221
|
+
| belongs to | `author: { type: 'uuid', ref: 'User' }` | the record, or `null` (never `null` when `required`) |
|
|
222
|
+
| many-to-many | `tags: { type: 'array', of: 'uuid', ref: 'Tag' }` | the records, in link order |
|
|
223
|
+
| has many | `relations: { posts: { hasMany: 'Post', foreignKey: 'author' } }` | the records (by `id` unless `orderBy`) |
|
|
224
|
+
| has one | `relations: { profile: { hasOne: 'Profile', foreignKey: 'user' } }` | the record or `null` — `foreignKey` must be `unique` |
|
|
225
|
+
|
|
226
|
+
- `true`, or options: `select`, `omit`, a nested `include` (any depth), and on lists `where`,
|
|
227
|
+
`orderBy`, `take`, `skip`. `false` leaves the relation out.
|
|
228
|
+
- `foreignKey` names the field on the other model that refs this one: a scalar `ref` or a
|
|
229
|
+
many-to-many array.
|
|
230
|
+
- **One statement per call**, whatever the depth: each relation is a correlated subquery
|
|
231
|
+
building `jsonb`. Included records read exactly like direct reads (`bigint`s, decimals as
|
|
232
|
+
strings, dates).
|
|
233
|
+
- `findMany`, `findFirst`, `findUnique` (and `…OrThrow`), `create`, `update`, `upsert` and
|
|
234
|
+
`delete` take `include`. Writes read the record back with its relations after writing;
|
|
235
|
+
`delete` reads it first.
|
|
236
|
+
- Self-relations work both ways (`parent` ref + `children: { hasMany: 'Category', foreignKey: 'parent' }`).
|
|
237
|
+
|
|
238
|
+
**Types.** Relations name models by string, so register your models once for typed includes:
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
declare module 'express-file-cluster' {
|
|
242
|
+
interface Tables { User: typeof User; Post: typeof Post; Tag: typeof Tag; Profile: typeof Profile }
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Included records are then typed (`select` / `omit` / nested `include` applied), and `include`
|
|
247
|
+
keys, nested `where` and `orderBy` are checked. A relation to an unregistered model still works,
|
|
248
|
+
typed as `Record<string, unknown>`.
|
|
249
|
+
|
|
101
250
|
---
|
|
102
251
|
|
|
103
252
|
## Reading
|
|
@@ -151,8 +300,22 @@ const next = await Order.findMany({ orderBy: { qty: 'desc' }, take: 20, cursor:
|
|
|
151
300
|
| strings | + `contains`, `startsWith`, `endsWith`, `mode: 'insensitive'` (ILIKE) |
|
|
152
301
|
| native arrays | `has`, `hasEvery`, `hasSome`, `isEmpty`, `equals` |
|
|
153
302
|
| objects / arrays of objects / `json` | `equals`, `not`, and with `path: ['a', 'b']`: `equals`, `string_contains`, `string_starts_with`, `string_ends_with`, `array_contains`, `gt`… |
|
|
303
|
+
| relations, to-many (many-to-many fields, `hasMany`) | `some`, `every`, `none` — each a `where` on the related model |
|
|
304
|
+
| relations, to-one (ref fields, `hasOne`) | `is`, `isNot` — a `where` on the related model, or `null` |
|
|
154
305
|
| combinators | `AND`, `OR`, `NOT` (an object or an array) |
|
|
155
306
|
|
|
307
|
+
```ts
|
|
308
|
+
await User.findMany({ where: { posts: { some: { comments: { some: { approved: false } } } } } });
|
|
309
|
+
await User.findMany({ where: { posts: { none: {} } } }); // users without posts
|
|
310
|
+
await Post.findMany({ where: { author: { is: { role: 'admin' } }, tags: { every: { public: true } } } });
|
|
311
|
+
await Post.findMany({ where: { author: { is: null } } }); // no author
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Relation filters are `EXISTS` subqueries — the read stays one statement — and nest to any
|
|
315
|
+
depth. They work wherever `where` does: reads, `count`, `include`, `updateMany`, `deleteMany`.
|
|
316
|
+
`every` holds for records with no related records at all. A ref or many-to-many field still
|
|
317
|
+
takes its own id filters (`author: id`, `tags: { has: id }`); a back-relation only these.
|
|
318
|
+
|
|
156
319
|
`undefined` values are ignored. Filters on undeclared fields match nothing, as with
|
|
157
320
|
`defineModel`. `LIKE` wildcards in `contains`, `startsWith` and `endsWith` are escaped.
|
|
158
321
|
|
|
@@ -202,6 +365,51 @@ await Order.update({
|
|
|
202
365
|
(400); a duplicate unique value gives a 409. `updatedAt` is refreshed on every update.
|
|
203
366
|
`increment`/`decrement` results are not re-checked against `min`/`max`.
|
|
204
367
|
|
|
368
|
+
### Nested writes
|
|
369
|
+
|
|
370
|
+
`create`, `update` and `upsert` can write related records in the same call:
|
|
371
|
+
|
|
372
|
+
```ts
|
|
373
|
+
await Post.create({
|
|
374
|
+
data: {
|
|
375
|
+
title: 'Hello',
|
|
376
|
+
author: { connect: { email: 'ann@x.io' } }, // a ref: connect / create / connectOrCreate
|
|
377
|
+
tags: { // many-to-many
|
|
378
|
+
connect: [{ label: 'news' }],
|
|
379
|
+
connectOrCreate: [{ where: { label: 'tech' }, create: { label: 'tech' } }],
|
|
380
|
+
create: [{ label: 'launch' }],
|
|
381
|
+
},
|
|
382
|
+
comments: { create: [{ body: 'First!' }] }, // a back-relation (hasMany)
|
|
383
|
+
},
|
|
384
|
+
include: { author: true, tags: true, comments: true },
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
await User.update({
|
|
388
|
+
where: { id },
|
|
389
|
+
data: {
|
|
390
|
+
posts: { connect: [{ id: p1 }], disconnect: [{ id: p2 }], deleteMany: { draft: true } },
|
|
391
|
+
profile: { create: { bio: 'hi' } }, // hasOne: replaces the current one
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
| Relation | `create` | `update` adds |
|
|
397
|
+
|---|---|---|
|
|
398
|
+
| ref field | `connect`, `create`, `connectOrCreate` (or the id) | `disconnect: true` |
|
|
399
|
+
| many-to-many field | `connect`, `create`, `connectOrCreate` (or ids) | `disconnect`, `set`, `push`, `pull` |
|
|
400
|
+
| `hasMany` | `connect`, `create` | `disconnect`, `set`, `delete`, `deleteMany` |
|
|
401
|
+
| `hasOne` | `connect`, `create` | `disconnect: true`, `delete: true` |
|
|
402
|
+
|
|
403
|
+
- `connect`, `disconnect`, `set` and `delete` take unique wheres (or ids); a list or a single one.
|
|
404
|
+
A `connect` that matches nothing is a **400** on the field.
|
|
405
|
+
- Children created through a back-relation get their foreign key from the parent — leave it out.
|
|
406
|
+
- The whole call runs in **one transaction**: anything failing rolls it all back.
|
|
407
|
+
- `createMany` / `updateMany` write rows only; they refuse nested writes, as in Prisma.
|
|
408
|
+
- `upsert` with nested writes reads first, then creates or updates, in the transaction (without
|
|
409
|
+
nested writes it stays a single `INSERT … ON CONFLICT`).
|
|
410
|
+
- A model first used inside a transaction gets its table right away and its foreign keys once
|
|
411
|
+
the transaction commits, so the sync never waits on the transaction's own locks.
|
|
412
|
+
|
|
205
413
|
---
|
|
206
414
|
|
|
207
415
|
## Aggregation
|
|
@@ -246,5 +454,5 @@ Over an empty set, `_sum`, `_avg`, `_min` and `_max` are `null`. `aggregate` als
|
|
|
246
454
|
- `raw()` returns the Drizzle `pgTable`, for anything EFC doesn't cover.
|
|
247
455
|
- `sync({ dryRun })` / `drop()` work as with `defineModel`.
|
|
248
456
|
- `transaction(async () => …)` covers `defineTable` calls too.
|
|
249
|
-
- Relations
|
|
250
|
-
|
|
457
|
+
- Relations are complete: foreign keys, many-to-many, `include`, relation filters and nested
|
|
458
|
+
writes (above).
|
|
@@ -13,6 +13,7 @@ ignite({
|
|
|
13
13
|
level: 'info', // trace | debug | info | warn | error | fatal | silent
|
|
14
14
|
pretty: undefined, // default: true in a non-production TTY, JSON otherwise
|
|
15
15
|
requests: true, // one line per completed request
|
|
16
|
+
queries: false, // model operation logging — see "Query logging" below
|
|
16
17
|
},
|
|
17
18
|
});
|
|
18
19
|
```
|
|
@@ -59,6 +60,43 @@ In production the same record is JSON:
|
|
|
59
60
|
|
|
60
61
|
---
|
|
61
62
|
|
|
63
|
+
## Query logging
|
|
64
|
+
|
|
65
|
+
`logging.queries` reports model operations — every `defineModel` and `defineTable` call — with the model, operation, duration, how many database statements it issued, and the request ID:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
logging: { queries: true } // every operation, plus slow-query warnings
|
|
69
|
+
logging: { queries: { slowMs: 200 } } // only operations taking ≥ 200 ms (production)
|
|
70
|
+
logging: { queries: { all: true, slowMs: 200, nPlusOne: 5 } }
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
| Option | Default | |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| `all` | `true` with `queries: true`, else `false` | log every operation at `info` |
|
|
76
|
+
| `slowMs` | `500` | operations at least this slow log at `warn` with `slow=true` |
|
|
77
|
+
| `nPlusOne` | `10` | warn when one request runs the same `Model.operation` this many times; `false` disables |
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
12:00:01 INFO [w2] 3f9c2a1b Post.findMany 2.1ms model=Post op=findMany durationMs=2.1 statements=1
|
|
81
|
+
12:00:01 WARN [w2] 3f9c2a1b Slow query: Order.aggregate 812.4ms model=Order op=aggregate durationMs=812.4 statements=1 slow=true
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`statements` counts the SQL statements (PostgreSQL) or MongoDB commands the call sent, including nested work such as `populate`; first-use auto-sync is not counted. An operation that throws is still logged, with `error`.
|
|
85
|
+
|
|
86
|
+
### N+1 detection
|
|
87
|
+
|
|
88
|
+
Querying inside a loop is the classic N+1 problem. When one request runs the same model operation `nPlusOne` times, EFC warns once for that request, naming the line that made the call:
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
12:00:01 WARN [w2] 3f9c2a1b Possible N+1: User.findById ran 10 times in one request — load them in one query instead model=User op=findById count=10 site=GET (/app/src/api/posts.ts:14:30)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Load them together instead — `User.find({ id: { $in: ids } })`, `populate`, or `findMany({ where: { id: { in: ids } } })`. Only top-level calls count (not `populate`'s), and only inside a request.
|
|
95
|
+
|
|
96
|
+
On MongoDB, query logging takes mongoose's `debug` hook (`mongoose.set('debug', …)`) to count commands, so it replaces any `debug` setting of your own while it is on.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
62
100
|
## Errors
|
|
63
101
|
|
|
64
102
|
Unhandled errors are logged at `error` with the request ID and full stack (`err`) before the 500 response is sent. Task failures log the task name, job ID and attempt number.
|
package/dist/docs/index.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**express-file-cluster (EFC)** is an opinionated backend framework built on Express. It removes routing ceremony, saturates every CPU core automatically, and ships a production-grade background-task subsystem — all from a single `ignite()` call.
|
|
4
4
|
|
|
5
|
-
> **Status: v0.
|
|
5
|
+
> **Status: v0.7.0 — Beta.** File-based routing (incl. catch-all and optional segments), request validation, clustering, auth, structured logging, MongoDB and PostgreSQL models with types inferred from the schema, PostgreSQL-native `defineTable` (Prisma-style queries and relations: foreign keys, many-to-many, `include`, relation filters, nested writes), query logging, BullMQ and pg-boss tasks with cron and dead-letter tooling, and migrations are all implemented.
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -37,8 +37,8 @@ Load **only** the module the work points to. Each is self-contained.
|
|
|
37
37
|
docs/ ← full documentation
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
## Status (v0.
|
|
40
|
+
## Status (v0.7.0 — Beta, Phase 2 complete + defineTable with relations)
|
|
41
41
|
|
|
42
|
-
Implemented: file-based router (incl. `[[id]]`, `[...slug]`, `[[...slug]]`), request validation (`export const schema`, Standard Schema), multi-core clustering with graceful shutdown, http-only + localStorage auth, structured logging (pino, request IDs), `defineModel` on MongoDB (mongoose) **and** PostgreSQL (Drizzle) with validation, query options, bulk ops, transactions, `sync()`/`drop()`, BullMQ **and** pg-boss task backends with cron schedules and dead-letter CLI, worker_threads for CPU-bound tasks, migrations/seeds/studio (`efc db`), full CLI.
|
|
42
|
+
Implemented: file-based router (incl. `[[id]]`, `[...slug]`, `[[...slug]]`), request validation (`export const schema`, Standard Schema), multi-core clustering with graceful shutdown, http-only + localStorage auth, structured logging (pino, request IDs), `defineModel` on MongoDB (mongoose) **and** PostgreSQL (Drizzle) with validation, query options, bulk ops, transactions, `sync()`/`drop()`, PostgreSQL-native `defineTable` (Prisma-style queries, foreign keys, many-to-many, `include`, relation filters, nested writes), query logging (`logging.queries`), BullMQ **and** pg-boss task backends with cron schedules and dead-letter CLI, worker_threads for CPU-bound tasks, migrations/seeds/studio (`efc db`), full CLI.
|
|
43
43
|
|
|
44
44
|
**Not yet implemented (Phase 3+):** WebSockets, plugins, OpenAPI generation, OpenTelemetry, `efc lint`, `efc deploy`, schema-diff migration generation.
|
|
@@ -51,7 +51,7 @@ function defineTable(name: string, schema: TableSchema, options?: TableOptions):
|
|
|
51
51
|
// arrays: has hasEvery hasSome isEmpty · jsonb: { path: [...], equals | string_contains | array_contains | gt… }
|
|
52
52
|
// AND / OR / NOT · undefined ignored · undeclared fields match nothing
|
|
53
53
|
// data ops: { increment | decrement | multiply | divide } (numbers), { push } (arrays), { set }, null unsets
|
|
54
|
-
// unique where: id | unique field | all fields of a unique index.
|
|
54
|
+
// unique where: id | unique field | all fields of a unique index. Top-level `ref` = FK, `onDelete: 'restrict'|'cascade'|'setNull'`, ref type must match target id (uuid/objectId | integer for serial | bigint for bigserial). Array of refs `{ type: 'array', of: <id type>, ref }` = many-to-many (join table, record keeps id list, list filters, set/push). `include` loads refs, m:n and `options.relations` back-relations (hasMany/hasOne + foreignKey) in one statement; typed via `interface Tables` augmentation. Relation filters `some/every/none`, `is/isNot`; nested writes `connect/create/connectOrCreate/disconnect/set/delete/deleteMany` (one transaction; not in createMany/updateMany).
|
|
55
55
|
|
|
56
56
|
class ModelValidationError extends HttpError { issues: { path: string; message: string }[] } // status 400
|
|
57
57
|
|
|
@@ -127,6 +127,7 @@ interface LoggingConfig {
|
|
|
127
127
|
level?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal' | 'silent'; // default 'info'
|
|
128
128
|
pretty?: boolean; // default: non-production TTY
|
|
129
129
|
requests?: boolean; // default true
|
|
130
|
+
queries?: boolean | { all?: boolean; slowMs?: number; nPlusOne?: number | false }; // default off; slowMs 500, nPlusOne 10
|
|
130
131
|
}
|
|
131
132
|
```
|
|
132
133
|
|
|
@@ -39,7 +39,7 @@ defineTable() // ← EXISTS (PostgreSQL-only, Prisma-style) — see api
|
|
|
39
39
|
defineCollection() // ← NOT YET — planned (MongoDB-native API, prisma-parity-plan M5)
|
|
40
40
|
Model.findMany() / findUnique() / groupBy() // ← only on defineTable, NOT on defineModel
|
|
41
41
|
Table.find() / findById() / $gt / $inc // ← defineModel vocabulary, NOT on defineTable
|
|
42
|
-
Table.findMany({ include }) // ←
|
|
42
|
+
Table.findMany({ include }) // ← EXISTS; so do relation filters `{ posts: { some } }` and nested writes `{ connect }` (defineTable only)
|
|
43
43
|
defineModel(..., { type: 'integer' | 'bigint' | 'decimal' | 'uuid' | 'json' }) // ← defineTable-only types
|
|
44
44
|
Model.updateOne(f, u, { upsert: true }) // ← no options arg; use Model.upsert(filter, create, update)
|
|
45
45
|
getModel() // ← does NOT exist as a public export
|
package/dist/index.cjs
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkZDM5JHVKcjs = require('./chunk-ZDM5JHVK.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkR34R7QPDcjs = require('./chunk-R34R7QPD.cjs');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunkT4OHFU5Tcjs = require('./chunk-T4OHFU5T.cjs');
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
@@ -25,18 +25,15 @@ var _chunkSZT36SGBcjs = require('./chunk-SZT36SGB.cjs');
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
var _chunkAZYXQU3Zcjs = require('./chunk-AZYXQU3Z.cjs');
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
|
|
31
|
-
var
|
|
32
|
+
var _chunkMGH4VDV3cjs = require('./chunk-MGH4VDV3.cjs');
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var _chunk47K2532Lcjs = require('./chunk-47K2532L.cjs');
|
|
36
|
+
var _chunkTYR2GZZEcjs = require('./chunk-TYR2GZZE.cjs');
|
|
40
37
|
require('./chunk-7YEX4MQV.cjs');
|
|
41
38
|
|
|
42
39
|
|
|
@@ -49,7 +46,7 @@ var _chunkTI24L4XEcjs = require('./chunk-TI24L4XE.cjs');
|
|
|
49
46
|
|
|
50
47
|
|
|
51
48
|
|
|
52
|
-
var
|
|
49
|
+
var _chunkYL37D6KMcjs = require('./chunk-YL37D6KM.cjs');
|
|
53
50
|
|
|
54
51
|
// src/index.ts
|
|
55
52
|
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
@@ -201,7 +198,7 @@ function workerCount() {
|
|
|
201
198
|
}
|
|
202
199
|
function shutdownMaster() {
|
|
203
200
|
isShuttingDown = true;
|
|
204
|
-
|
|
201
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).info(`Cluster primary (pid=${process.pid}) shutting down, waiting for workers\u2026`);
|
|
205
202
|
if (workerCount() === 0) process.exit(0);
|
|
206
203
|
for (const worker of Object.values(_nullishCoalesce(_cluster2.default.workers, () => ( {})))) {
|
|
207
204
|
_optionalChain([worker, 'optionalAccess', _3 => _3.process, 'access', _4 => _4.kill, 'call', _5 => _5("SIGTERM")]);
|
|
@@ -209,7 +206,7 @@ function shutdownMaster() {
|
|
|
209
206
|
}
|
|
210
207
|
function runMaster(options = {}) {
|
|
211
208
|
const count = _nullishCoalesce(options.workers, () => ( 1));
|
|
212
|
-
|
|
209
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).info(`Primary ${process.pid} starting ${count} workers`);
|
|
213
210
|
for (let i = 0; i < count; i++) {
|
|
214
211
|
_cluster2.default.fork();
|
|
215
212
|
}
|
|
@@ -219,14 +216,14 @@ function runMaster(options = {}) {
|
|
|
219
216
|
_cluster2.default.on("exit", (worker, code, signal) => {
|
|
220
217
|
const exitCode = _nullishCoalesce(code, () => ( (signal ? -1 : 0)));
|
|
221
218
|
if (isShuttingDown) {
|
|
222
|
-
|
|
219
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).info(`Worker ${worker.id} gracefully exited`);
|
|
223
220
|
if (workerCount() === 0) {
|
|
224
|
-
|
|
221
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).info("All workers exited. Primary exiting.");
|
|
225
222
|
process.exit(0);
|
|
226
223
|
}
|
|
227
224
|
return;
|
|
228
225
|
}
|
|
229
|
-
|
|
226
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).warn(`Worker ${worker.id} exited (code=${exitCode}), respawning\u2026`);
|
|
230
227
|
_optionalChain([options, 'access', _8 => _8.onWorkerCrash, 'optionalCall', _9 => _9(worker.id, exitCode)]);
|
|
231
228
|
_cluster2.default.fork();
|
|
232
229
|
});
|
|
@@ -245,13 +242,13 @@ async function scanTasks(tasksDir) {
|
|
|
245
242
|
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require(filePath)));
|
|
246
243
|
const def = mod["default"];
|
|
247
244
|
if (!def || typeof def.handler !== "function") {
|
|
248
|
-
|
|
245
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).warn(`Task file ${file} has no valid default export \u2014 skipping`);
|
|
249
246
|
continue;
|
|
250
247
|
}
|
|
251
248
|
_chunkTI24L4XEcjs.registerTask.call(void 0, taskName, { ...def, filePath });
|
|
252
|
-
|
|
249
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).debug(`Registered task: ${taskName}`);
|
|
253
250
|
} catch (err) {
|
|
254
|
-
|
|
251
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).warn({ err }, `Failed to load task ${file}`);
|
|
255
252
|
}
|
|
256
253
|
}
|
|
257
254
|
}
|
|
@@ -862,14 +859,14 @@ function cacheResponse(options) {
|
|
|
862
859
|
if (req.method !== "GET" && req.method !== "HEAD") return next();
|
|
863
860
|
let scope = "";
|
|
864
861
|
if (opts.perUser) {
|
|
865
|
-
const user =
|
|
862
|
+
const user = _chunkYL37D6KMcjs.getCurrentUser.call(void 0, );
|
|
866
863
|
const id = _nullishCoalesce(_optionalChain([user, 'optionalAccess', _10 => _10["sub"]]), () => ( _optionalChain([user, 'optionalAccess', _11 => _11["id"]])));
|
|
867
864
|
if (id === void 0) return next();
|
|
868
865
|
scope = `u:${String(id)}:`;
|
|
869
866
|
}
|
|
870
867
|
const key = RESPONSE_PREFIX + scope + (opts.key ? opts.key(req) : req.originalUrl);
|
|
871
868
|
void (async () => {
|
|
872
|
-
const hit = await
|
|
869
|
+
const hit = await _chunkZDM5JHVKcjs.cache.get(key);
|
|
873
870
|
if (hit) {
|
|
874
871
|
res.setHeader("X-Cache", "HIT");
|
|
875
872
|
res.status(hit.status).json(hit.body);
|
|
@@ -878,7 +875,7 @@ function cacheResponse(options) {
|
|
|
878
875
|
res.setHeader("X-Cache", "MISS");
|
|
879
876
|
const json = res.json.bind(res);
|
|
880
877
|
res.json = (body) => {
|
|
881
|
-
if (res.statusCode === 200) void
|
|
878
|
+
if (res.statusCode === 200) void _chunkZDM5JHVKcjs.cache.set(key, { status: 200, body }, { ttl: opts.ttl });
|
|
882
879
|
return json(body);
|
|
883
880
|
};
|
|
884
881
|
next();
|
|
@@ -909,29 +906,6 @@ function compose(...handlers) {
|
|
|
909
906
|
};
|
|
910
907
|
}
|
|
911
908
|
|
|
912
|
-
// src/db/transaction.ts
|
|
913
|
-
async function transaction(fn) {
|
|
914
|
-
if (_chunkQTRGJ2ENcjs.currentTx.call(void 0, )) return fn();
|
|
915
|
-
if (_chunkQTRGJ2ENcjs.getDbEngine.call(void 0, ) === "postgresql") {
|
|
916
|
-
let result;
|
|
917
|
-
await _chunkALBDM5R3cjs.getOrm.call(void 0, ).transaction(async (tx) => {
|
|
918
|
-
result = await _chunkQTRGJ2ENcjs.runInTx.call(void 0, { engine: "postgresql", tx }, fn);
|
|
919
|
-
});
|
|
920
|
-
return result;
|
|
921
|
-
}
|
|
922
|
-
const mg = await _chunkQTRGJ2ENcjs.loadMongoose.call(void 0, );
|
|
923
|
-
const session = await mg.connection.startSession();
|
|
924
|
-
try {
|
|
925
|
-
let result;
|
|
926
|
-
await session.withTransaction(async () => {
|
|
927
|
-
result = await _chunkQTRGJ2ENcjs.runInTx.call(void 0, { engine: "mongodb", session }, fn);
|
|
928
|
-
});
|
|
929
|
-
return result;
|
|
930
|
-
} finally {
|
|
931
|
-
await session.endSession();
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
|
|
935
909
|
// src/index.ts
|
|
936
910
|
function detectDatabase(url) {
|
|
937
911
|
if (!url) return void 0;
|
|
@@ -975,10 +949,11 @@ async function ignite(config) {
|
|
|
975
949
|
const jwtSecret = config.jwtSecret;
|
|
976
950
|
const authStrategy = _nullishCoalesce(config.authStrategy, () => ( "http-only"));
|
|
977
951
|
const clusterEnabled = _nullishCoalesce(config.cluster, () => ( process.env["NODE_ENV"] === "production"));
|
|
978
|
-
|
|
952
|
+
_chunkYL37D6KMcjs.configureLogger.call(void 0, config.logging);
|
|
953
|
+
_chunkMGH4VDV3cjs.configureQueryLog.call(void 0, config.logging);
|
|
979
954
|
if (clusterEnabled && _cluster2.default.isPrimary) {
|
|
980
955
|
if (config.cache && config.cache.backend === "memory") {
|
|
981
|
-
|
|
956
|
+
_chunkZDM5JHVKcjs.servePrimaryCache.call(void 0, _nullishCoalesce(config.cache.maxEntries, () => ( 1e4)));
|
|
982
957
|
}
|
|
983
958
|
runMaster({
|
|
984
959
|
workers: _nullishCoalesce(workers, () => ( _os2.default.cpus().length)),
|
|
@@ -993,9 +968,9 @@ async function ignite(config) {
|
|
|
993
968
|
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
994
969
|
);
|
|
995
970
|
app.use((_req, _res, next) => {
|
|
996
|
-
|
|
971
|
+
_chunkYL37D6KMcjs.runWithContext.call(void 0, {}, next);
|
|
997
972
|
});
|
|
998
|
-
app.use(
|
|
973
|
+
app.use(_chunkYL37D6KMcjs.requestLogger.call(void 0, ));
|
|
999
974
|
if (config.requestTimeout) {
|
|
1000
975
|
const ms = config.requestTimeout;
|
|
1001
976
|
app.use((_req, res, next) => {
|
|
@@ -1020,20 +995,20 @@ async function ignite(config) {
|
|
|
1020
995
|
for (const mw of globalMiddlewares) {
|
|
1021
996
|
app.use(mw);
|
|
1022
997
|
}
|
|
1023
|
-
if (database)
|
|
1024
|
-
|
|
998
|
+
if (database) _chunkAZYXQU3Zcjs.setDbEngine.call(void 0, database);
|
|
999
|
+
_chunkAZYXQU3Zcjs.setAutoSync.call(void 0, _nullishCoalesce(config.autoSync, () => ( true)));
|
|
1025
1000
|
if (database === "mongodb" && databaseUrl) {
|
|
1026
|
-
const conn = await
|
|
1027
|
-
|
|
1001
|
+
const conn = await _chunkAZYXQU3Zcjs.connectMongo.call(void 0, databaseUrl);
|
|
1002
|
+
_chunkAZYXQU3Zcjs.setDbClient.call(void 0, conn);
|
|
1028
1003
|
} else if (database === "postgresql" && databaseUrl) {
|
|
1029
|
-
const pool = await
|
|
1030
|
-
|
|
1004
|
+
const pool = await _chunkMGH4VDV3cjs.connectPostgres.call(void 0, databaseUrl);
|
|
1005
|
+
_chunkAZYXQU3Zcjs.setDbClient.call(void 0, pool);
|
|
1031
1006
|
}
|
|
1032
1007
|
if (config.cache) {
|
|
1033
|
-
await
|
|
1008
|
+
await _chunkZDM5JHVKcjs.configureCache.call(void 0, config.cache);
|
|
1034
1009
|
}
|
|
1035
1010
|
if (jwtSecret) {
|
|
1036
|
-
|
|
1011
|
+
_chunkZDM5JHVKcjs.configureAuth.call(void 0, {
|
|
1037
1012
|
secret: jwtSecret,
|
|
1038
1013
|
strategy: authStrategy,
|
|
1039
1014
|
expiresIn: _nullishCoalesce(config.jwtExpiresIn, () => ( "7d")),
|
|
@@ -1045,7 +1020,7 @@ async function ignite(config) {
|
|
|
1045
1020
|
}
|
|
1046
1021
|
if (config.tasks) {
|
|
1047
1022
|
if (config.tasks.backend === "bullmq") {
|
|
1048
|
-
await
|
|
1023
|
+
await _chunkT4OHFU5Tcjs.initBullMQ.call(void 0, {
|
|
1049
1024
|
redisUrl: _nullishCoalesce(config.tasks.redisUrl, () => ( "redis://localhost:6379")),
|
|
1050
1025
|
concurrency: _nullishCoalesce(config.tasks.concurrency, () => ( 5)),
|
|
1051
1026
|
enqueueTimeout: _nullishCoalesce(config.tasks.enqueueTimeout, () => ( 5e3)),
|
|
@@ -1058,7 +1033,7 @@ async function ignite(config) {
|
|
|
1058
1033
|
'[EFC] tasks.backend "pg-boss" needs tasks.connectionString or databaseUrl'
|
|
1059
1034
|
);
|
|
1060
1035
|
}
|
|
1061
|
-
await
|
|
1036
|
+
await _chunkTYR2GZZEcjs.initPgBoss.call(void 0, {
|
|
1062
1037
|
connectionString,
|
|
1063
1038
|
concurrency: _nullishCoalesce(config.tasks.concurrency, () => ( 5)),
|
|
1064
1039
|
enqueueTimeout: _nullishCoalesce(config.tasks.enqueueTimeout, () => ( 5e3)),
|
|
@@ -1067,7 +1042,7 @@ async function ignite(config) {
|
|
|
1067
1042
|
});
|
|
1068
1043
|
}
|
|
1069
1044
|
}
|
|
1070
|
-
const routes =
|
|
1045
|
+
const routes = _chunkR34R7QPDcjs.scanDir.call(void 0, apiDir);
|
|
1071
1046
|
const apiRouter = _express2.default.Router();
|
|
1072
1047
|
const mounted = await mountRoutes(apiRouter, routes);
|
|
1073
1048
|
app.use(basePath, apiRouter);
|
|
@@ -1084,11 +1059,11 @@ async function ignite(config) {
|
|
|
1084
1059
|
app.use(
|
|
1085
1060
|
(err, _req, res, _next) => {
|
|
1086
1061
|
if (res.headersSent) {
|
|
1087
|
-
|
|
1062
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).warn({ err }, "Error after the response was sent");
|
|
1088
1063
|
return;
|
|
1089
1064
|
}
|
|
1090
1065
|
const duckTyped = err instanceof Error && typeof err.statusCode === "number" ? err : null;
|
|
1091
|
-
if (
|
|
1066
|
+
if (_chunkAZYXQU3Zcjs.isHttpError.call(void 0, err)) {
|
|
1092
1067
|
const issues = err.issues;
|
|
1093
1068
|
res.status(err.statusCode).json({
|
|
1094
1069
|
error: err.message,
|
|
@@ -1098,7 +1073,7 @@ async function ignite(config) {
|
|
|
1098
1073
|
} else if (duckTyped) {
|
|
1099
1074
|
res.status(duckTyped.statusCode).json({ error: duckTyped.message, statusCode: duckTyped.statusCode });
|
|
1100
1075
|
} else {
|
|
1101
|
-
|
|
1076
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).error({ err }, "Unhandled error");
|
|
1102
1077
|
res.status(500).json({ error: "Internal Server Error", statusCode: 500 });
|
|
1103
1078
|
}
|
|
1104
1079
|
}
|
|
@@ -1109,7 +1084,7 @@ async function ignite(config) {
|
|
|
1109
1084
|
server.once("listening", () => {
|
|
1110
1085
|
const wid = _nullishCoalesce(_optionalChain([_cluster2.default, 'access', _12 => _12.worker, 'optionalAccess', _13 => _13.id]), () => ( "primary"));
|
|
1111
1086
|
const addr = server.address();
|
|
1112
|
-
|
|
1087
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).info(`Worker ${wid} listening on :${_nullishCoalesce(_optionalChain([addr, 'optionalAccess', _14 => _14.port]), () => ( port))}`);
|
|
1113
1088
|
resolve(server);
|
|
1114
1089
|
});
|
|
1115
1090
|
server.once("error", reject);
|
|
@@ -1120,21 +1095,21 @@ function gracefulShutdown(server, timeoutMs = 1e4) {
|
|
|
1120
1095
|
const shutdown = (signal) => {
|
|
1121
1096
|
if (shuttingDown) return;
|
|
1122
1097
|
shuttingDown = true;
|
|
1123
|
-
|
|
1098
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).info(`${signal} received \u2014 closing server gracefully\u2026`);
|
|
1124
1099
|
if (server) {
|
|
1125
1100
|
server.closeIdleConnections();
|
|
1126
1101
|
server.close(() => {
|
|
1127
|
-
|
|
1128
|
-
Promise.all([
|
|
1102
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).info("Server closed");
|
|
1103
|
+
Promise.all([_chunkT4OHFU5Tcjs.closeBullMQ.call(void 0, ), _chunkTYR2GZZEcjs.closePgBoss.call(void 0, ), _chunkZDM5JHVKcjs.closeCache.call(void 0, )]).catch((err) => _chunkYL37D6KMcjs.getLogger.call(void 0, ).error({ err }, "Task backend close failed")).finally(() => process.exit(0));
|
|
1129
1104
|
});
|
|
1130
1105
|
setTimeout(() => {
|
|
1131
|
-
|
|
1106
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).error("Forced exit after timeout");
|
|
1132
1107
|
process.exit(1);
|
|
1133
1108
|
}, timeoutMs).unref();
|
|
1134
1109
|
} else {
|
|
1135
1110
|
shutdownMaster();
|
|
1136
1111
|
setTimeout(() => {
|
|
1137
|
-
|
|
1112
|
+
_chunkYL37D6KMcjs.getLogger.call(void 0, ).error("Workers did not exit in time \u2014 forcing primary exit");
|
|
1138
1113
|
process.exit(1);
|
|
1139
1114
|
}, timeoutMs + 2e3).unref();
|
|
1140
1115
|
}
|
|
@@ -1162,5 +1137,5 @@ function gracefulShutdown(server, timeoutMs = 1e4) {
|
|
|
1162
1137
|
|
|
1163
1138
|
|
|
1164
1139
|
|
|
1165
|
-
exports.HttpError =
|
|
1140
|
+
exports.HttpError = _chunkAZYXQU3Zcjs.HttpError; exports.ModelValidationError = _chunkAZYXQU3Zcjs.ModelValidationError; exports.cache = _chunkZDM5JHVKcjs.cache; exports.cacheResponse = cacheResponse; exports.compose = compose; exports.db = _chunkAZYXQU3Zcjs.db; exports.defineModel = _chunkAZYXQU3Zcjs.defineModel; exports.defineTable = _chunkAZYXQU3Zcjs.defineTable; exports.getDbClient = _chunkAZYXQU3Zcjs.getDbClient; exports.getLogger = _chunkYL37D6KMcjs.getLogger; exports.gracefulShutdown = gracefulShutdown; exports.ignite = ignite; exports.isHttpError = _chunkAZYXQU3Zcjs.isHttpError; exports.listTasks = _chunkTI24L4XEcjs.listTasks; exports.logger = _chunkYL37D6KMcjs.logger; exports.scanDir = _chunkR34R7QPDcjs.scanDir; exports.setDbClient = _chunkAZYXQU3Zcjs.setDbClient; exports.transaction = _chunkAZYXQU3Zcjs.transaction; exports.workerCount = workerCount;
|
|
1166
1141
|
//# sourceMappingURL=index.cjs.map
|