express-file-cluster 0.9.3 → 0.10.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/dist/auth/index.cjs +6 -7
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +7 -2
- package/dist/auth/index.d.ts +7 -2
- package/dist/auth/index.js +5 -6
- package/dist/{chunk-QL6EWT4B.cjs → chunk-4DOHQU6I.cjs} +9 -7
- package/dist/chunk-4DOHQU6I.cjs.map +1 -0
- package/dist/chunk-73XJUT2S.js +366 -0
- package/dist/chunk-73XJUT2S.js.map +1 -0
- package/dist/{chunk-ATL4GYFU.js → chunk-7KC2H76D.js} +50 -8
- package/dist/chunk-7KC2H76D.js.map +1 -0
- package/dist/{chunk-TYR2GZZE.cjs → chunk-7KO4DJRJ.cjs} +19 -14
- package/dist/chunk-7KO4DJRJ.cjs.map +1 -0
- package/dist/{chunk-UBQYQPBU.js → chunk-ATVD2HGC.js} +4 -4
- package/dist/{chunk-R34R7QPD.cjs → chunk-DCJOWFVD.cjs} +3 -3
- package/dist/{chunk-R34R7QPD.cjs.map → chunk-DCJOWFVD.cjs.map} +1 -1
- package/dist/chunk-DUADUR6R.cjs +366 -0
- package/dist/chunk-DUADUR6R.cjs.map +1 -0
- package/dist/{chunk-BBSZLGZW.js → chunk-EGSSZUVO.js} +8 -6
- package/dist/chunk-EGSSZUVO.js.map +1 -0
- package/dist/{chunk-TI24L4XE.cjs → chunk-GBI77W5T.cjs} +6 -2
- package/dist/chunk-GBI77W5T.cjs.map +1 -0
- package/dist/{chunk-RTF7PHS2.cjs → chunk-HBCY7ILD.cjs} +306 -119
- package/dist/chunk-HBCY7ILD.cjs.map +1 -0
- package/dist/{chunk-ANUSWEAP.cjs → chunk-KFVFP2Q7.cjs} +59 -17
- package/dist/chunk-KFVFP2Q7.cjs.map +1 -0
- package/dist/{chunk-RS4MXCPW.js → chunk-NI2BNGGV.js} +2 -2
- package/dist/{chunk-X2US4RAM.cjs → chunk-NKLOE4AK.cjs} +11 -13
- package/dist/chunk-NKLOE4AK.cjs.map +1 -0
- package/dist/{chunk-RRQ2RK5M.js → chunk-PGJQK36V.js} +195 -8
- package/dist/chunk-PGJQK36V.js.map +1 -0
- package/dist/{chunk-QKQZF573.js → chunk-QDEDOHP7.js} +4 -6
- package/dist/chunk-QDEDOHP7.js.map +1 -0
- package/dist/{chunk-UTM4PEVG.js → chunk-R4XO4SVM.js} +10 -5
- package/dist/chunk-R4XO4SVM.js.map +1 -0
- package/dist/chunk-R52CUEGT.js +74 -0
- package/dist/chunk-R52CUEGT.js.map +1 -0
- package/dist/{chunk-HBYSKULC.js → chunk-RAB44UGX.js} +5 -1
- package/dist/chunk-RAB44UGX.js.map +1 -0
- package/dist/{chunk-7YEX4MQV.cjs → chunk-WBLUGOAG.cjs} +42 -6
- package/dist/chunk-WBLUGOAG.cjs.map +1 -0
- package/dist/{chunk-T4OHFU5T.cjs → chunk-YK4ZM3CA.cjs} +15 -15
- package/dist/{chunk-T4OHFU5T.cjs.map → chunk-YK4ZM3CA.cjs.map} +1 -1
- package/dist/cli/db-runner.cjs +2012 -120
- package/dist/cli/db-runner.cjs.map +1 -1
- package/dist/cli/db-runner.js +1989 -97
- package/dist/cli/db-runner.js.map +1 -1
- package/dist/cli/index.cjs +101 -43
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +80 -22
- package/dist/cli/index.js.map +1 -1
- package/dist/docs/api-reference/auth.md +10 -8
- package/dist/docs/api-reference/collection.md +44 -1
- package/dist/docs/api-reference/ignite.md +22 -3
- package/dist/docs/api-reference/types.md +99 -0
- package/dist/docs/cli/add.md +1 -1
- package/dist/docs/cli/db.md +2 -2
- package/dist/docs/contributing/index.md +1 -1
- package/dist/docs/core-concepts/background-tasks.md +6 -3
- package/dist/docs/getting-started/index.md +3 -2
- package/dist/docs/guides/authentication.md +34 -24
- package/dist/docs/guides/caching.md +32 -1
- package/dist/docs/guides/database.md +14 -0
- package/dist/docs/guides/feature-matrix.md +58 -0
- package/dist/docs/guides/migrations.md +23 -2
- package/dist/docs/guides/oauth.md +15 -1
- package/dist/docs/guides/which-api.md +2 -2
- package/dist/docs/index.md +4 -1
- package/dist/docs/skills/SKILL.md +2 -2
- package/dist/docs/skills/api-surface.md +10 -4
- package/dist/docs/skills/auth-internals.md +3 -3
- package/dist/docs/skills/tasks-internals.md +4 -3
- package/dist/docs/skills/what-not-to-invent.md +4 -3
- package/dist/docs/versioning.md +42 -0
- package/dist/index.cjs +144 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +204 -3
- package/dist/index.d.ts +204 -3
- package/dist/index.js +107 -14
- package/dist/index.js.map +1 -1
- package/dist/pgboss-backend-FW42SBSM.js +14 -0
- package/dist/pgboss-backend-RVHUBJTU.cjs +14 -0
- package/dist/{pgboss-backend-TCHI7CHM.cjs.map → pgboss-backend-RVHUBJTU.cjs.map} +1 -1
- package/dist/registry/index.json +34 -3
- package/dist/registry/js-mongo/account-security.json +1 -1
- package/dist/registry/js-mongo/admin-users.json +1 -1
- package/dist/registry/js-mongo/auth.json +1 -1
- package/dist/registry/js-mongo/auth@apple.json +1 -1
- package/dist/registry/js-mongo/auth@google.json +1 -1
- package/dist/registry/js-mongo/email-verification.json +1 -1
- package/dist/registry/js-mongo/forgot-password.json +1 -1
- package/dist/registry/js-mongo/user-profile.json +1 -1
- package/dist/registry/js-mongo-collection/_base.json +1 -0
- package/dist/registry/js-mongo-collection/account-security.json +1 -0
- package/dist/registry/js-mongo-collection/account-settings.json +1 -0
- package/dist/registry/js-mongo-collection/admin-admins.json +1 -0
- package/dist/registry/js-mongo-collection/admin-analytics.json +1 -0
- package/dist/registry/js-mongo-collection/admin-billing.json +1 -0
- package/dist/registry/js-mongo-collection/admin-content.json +1 -0
- package/dist/registry/js-mongo-collection/admin-logs.json +1 -0
- package/dist/registry/js-mongo-collection/admin-support.json +1 -0
- package/dist/registry/js-mongo-collection/admin-system.json +1 -0
- package/dist/registry/js-mongo-collection/admin-users.json +1 -0
- package/dist/registry/js-mongo-collection/admin.json +1 -0
- package/dist/registry/js-mongo-collection/auth.json +1 -0
- package/dist/registry/js-mongo-collection/auth@apple.json +1 -0
- package/dist/registry/js-mongo-collection/auth@google.json +1 -0
- package/dist/registry/js-mongo-collection/billing.json +1 -0
- package/dist/registry/js-mongo-collection/email-client.json +1 -0
- package/dist/registry/js-mongo-collection/email-verification.json +1 -0
- package/dist/registry/js-mongo-collection/files.json +1 -0
- package/dist/registry/js-mongo-collection/forgot-password.json +1 -0
- package/dist/registry/js-mongo-collection/notifications.json +1 -0
- package/dist/registry/js-mongo-collection/support.json +1 -0
- package/dist/registry/js-mongo-collection/user-profile.json +1 -0
- package/dist/registry/js-pg-model/account-security.json +1 -1
- package/dist/registry/js-pg-model/admin-users.json +1 -1
- package/dist/registry/js-pg-model/auth.json +1 -1
- package/dist/registry/js-pg-model/auth@apple.json +1 -1
- package/dist/registry/js-pg-model/auth@google.json +1 -1
- package/dist/registry/js-pg-model/email-verification.json +1 -1
- package/dist/registry/js-pg-model/forgot-password.json +1 -1
- package/dist/registry/js-pg-model/user-profile.json +1 -1
- package/dist/registry/js-pg-table/account-security.json +1 -1
- package/dist/registry/js-pg-table/admin-users.json +1 -1
- package/dist/registry/js-pg-table/auth.json +1 -1
- package/dist/registry/js-pg-table/auth@apple.json +1 -1
- package/dist/registry/js-pg-table/auth@google.json +1 -1
- package/dist/registry/js-pg-table/email-verification.json +1 -1
- package/dist/registry/js-pg-table/forgot-password.json +1 -1
- package/dist/registry/js-pg-table/user-profile.json +1 -1
- package/dist/registry/ts-mongo/account-security.json +1 -1
- package/dist/registry/ts-mongo/admin-users.json +1 -1
- package/dist/registry/ts-mongo/auth.json +1 -1
- package/dist/registry/ts-mongo/auth@apple.json +1 -1
- package/dist/registry/ts-mongo/auth@google.json +1 -1
- package/dist/registry/ts-mongo/email-verification.json +1 -1
- package/dist/registry/ts-mongo/forgot-password.json +1 -1
- package/dist/registry/ts-mongo/user-profile.json +1 -1
- package/dist/registry/ts-mongo-collection/_base.json +1 -0
- package/dist/registry/ts-mongo-collection/account-security.json +1 -0
- package/dist/registry/ts-mongo-collection/account-settings.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-admins.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-analytics.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-billing.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-content.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-logs.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-support.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-system.json +1 -0
- package/dist/registry/ts-mongo-collection/admin-users.json +1 -0
- package/dist/registry/ts-mongo-collection/admin.json +1 -0
- package/dist/registry/ts-mongo-collection/auth.json +1 -0
- package/dist/registry/ts-mongo-collection/auth@apple.json +1 -0
- package/dist/registry/ts-mongo-collection/auth@google.json +1 -0
- package/dist/registry/ts-mongo-collection/billing.json +1 -0
- package/dist/registry/ts-mongo-collection/email-client.json +1 -0
- package/dist/registry/ts-mongo-collection/email-verification.json +1 -0
- package/dist/registry/ts-mongo-collection/files.json +1 -0
- package/dist/registry/ts-mongo-collection/forgot-password.json +1 -0
- package/dist/registry/ts-mongo-collection/notifications.json +1 -0
- package/dist/registry/ts-mongo-collection/support.json +1 -0
- package/dist/registry/ts-mongo-collection/user-profile.json +1 -0
- package/dist/registry/ts-pg-model/account-security.json +1 -1
- package/dist/registry/ts-pg-model/admin-users.json +1 -1
- package/dist/registry/ts-pg-model/auth.json +1 -1
- package/dist/registry/ts-pg-model/auth@apple.json +1 -1
- package/dist/registry/ts-pg-model/auth@google.json +1 -1
- package/dist/registry/ts-pg-model/email-verification.json +1 -1
- package/dist/registry/ts-pg-model/forgot-password.json +1 -1
- package/dist/registry/ts-pg-model/user-profile.json +1 -1
- package/dist/registry/ts-pg-table/account-security.json +1 -1
- package/dist/registry/ts-pg-table/admin-users.json +1 -1
- package/dist/registry/ts-pg-table/auth.json +1 -1
- package/dist/registry/ts-pg-table/auth@apple.json +1 -1
- package/dist/registry/ts-pg-table/auth@google.json +1 -1
- package/dist/registry/ts-pg-table/email-verification.json +1 -1
- package/dist/registry/ts-pg-table/forgot-password.json +1 -1
- package/dist/registry/ts-pg-table/user-profile.json +1 -1
- package/dist/tasks/index.cjs +4 -2
- package/dist/tasks/index.cjs.map +1 -1
- package/dist/tasks/index.d.cts +4 -2
- package/dist/tasks/index.d.ts +4 -2
- package/dist/tasks/index.js +3 -1
- package/dist/thread-runner.cjs +8 -0
- package/dist/thread-runner.cjs.map +1 -0
- package/dist/thread-runner.d.cts +3 -0
- package/dist/thread-runner.d.ts +3 -0
- package/dist/thread-runner.js +8 -0
- package/dist/thread-runner.js.map +1 -0
- package/dist/{types-BY-ObnZH.d.ts → types-Bnxvj3l0.d.cts} +14 -2
- package/dist/{types-BY-ObnZH.d.cts → types-Bnxvj3l0.d.ts} +14 -2
- package/package.json +1 -1
- package/dist/chunk-277BSYVH.js +0 -127
- package/dist/chunk-277BSYVH.js.map +0 -1
- package/dist/chunk-7YEX4MQV.cjs.map +0 -1
- package/dist/chunk-ANUSWEAP.cjs.map +0 -1
- package/dist/chunk-ATL4GYFU.js.map +0 -1
- package/dist/chunk-BBSZLGZW.js.map +0 -1
- package/dist/chunk-HBYSKULC.js.map +0 -1
- package/dist/chunk-HXV543HZ.js +0 -177
- package/dist/chunk-HXV543HZ.js.map +0 -1
- package/dist/chunk-LJNSJFOL.js +0 -38
- package/dist/chunk-LJNSJFOL.js.map +0 -1
- package/dist/chunk-QKQZF573.js.map +0 -1
- package/dist/chunk-QL6EWT4B.cjs.map +0 -1
- package/dist/chunk-RRQ2RK5M.js.map +0 -1
- package/dist/chunk-RTF7PHS2.cjs.map +0 -1
- package/dist/chunk-TI24L4XE.cjs.map +0 -1
- package/dist/chunk-TYR2GZZE.cjs.map +0 -1
- package/dist/chunk-UTM4PEVG.js.map +0 -1
- package/dist/chunk-VQSWSYK6.cjs +0 -177
- package/dist/chunk-VQSWSYK6.cjs.map +0 -1
- package/dist/chunk-X2US4RAM.cjs.map +0 -1
- package/dist/chunk-YL37D6KM.cjs +0 -127
- package/dist/chunk-YL37D6KM.cjs.map +0 -1
- package/dist/pgboss-backend-QKBXVJ6B.js +0 -14
- package/dist/pgboss-backend-TCHI7CHM.cjs +0 -14
- /package/dist/{chunk-UBQYQPBU.js.map → chunk-ATVD2HGC.js.map} +0 -0
- /package/dist/{chunk-RS4MXCPW.js.map → chunk-NI2BNGGV.js.map} +0 -0
- /package/dist/{pgboss-backend-QKBXVJ6B.js.map → pgboss-backend-FW42SBSM.js.map} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
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, g as SortDirection, C as CollectionSchema, R as RouteEntry, E as EFCConfig } from './types-
|
|
3
|
-
export { A as AuthStrategy,
|
|
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, g as SortDirection, h as InferRecord, C as CollectionSchema, R as RouteEntry, E as EFCConfig } from './types-Bnxvj3l0.js';
|
|
3
|
+
export { A as AuthStrategy, i as CacheConfig, j as CollectionFieldDefinition, k as CorsConfig, D as DatabaseEngine, l as DatabasePoolConfig, m as DefaultOperator, F as FieldDefinition, n as Filter, o as FilterOperators, p as FindOptions, G as GeoPoint, q as IndexDefinition, r as InferCreate, L as LoggingConfig, s as MigrationContext, t as ModelCRUD, u as ModelQueryOptions, v as ModelRecord, Q as QueryLogConfig, w as RequestSchema, x as RouteMeta, y as RouteMethodMeta, z as RouteSchema, B as ScalarKeys, H as SchemaField, J as TableFieldDefinition, K as TableRelation, N as TableSchemaField, a as TaskDefinition, T as TaskOptions, U as Update, V as ValidationIssue, O as Validator } from './types-Bnxvj3l0.js';
|
|
4
4
|
import { Logger } from 'pino';
|
|
5
5
|
import { Request, RequestHandler } from 'express';
|
|
6
6
|
export { listTasks } from './tasks/index.js';
|
|
@@ -672,9 +672,54 @@ interface Cache {
|
|
|
672
672
|
wrap<T>(key: string, options: CacheSetOptions | number, fn: () => Promise<T>): Promise<T>;
|
|
673
673
|
/** Deletes every key starting with `keyPrefix` (all of this app's keys when omitted). */
|
|
674
674
|
clear(keyPrefix?: string): Promise<number>;
|
|
675
|
+
/**
|
|
676
|
+
* Atomically adds 1 and returns the new count — across workers and instances (Redis) or
|
|
677
|
+
* this machine's workers (memory). `ttl` applies when the key is created (a fixed
|
|
678
|
+
* window). Resolves `undefined` when the backend is unreachable: a count can't be made up.
|
|
679
|
+
*/
|
|
680
|
+
incr(key: string, options?: CacheSetOptions): Promise<number | undefined>;
|
|
675
681
|
}
|
|
676
682
|
declare const cache: Cache;
|
|
677
683
|
|
|
684
|
+
interface RateLimitOptions {
|
|
685
|
+
/** Window length: seconds, or `'30s'`, `'15m'`, `'1h'`, `'1d'`. */
|
|
686
|
+
window: number | string;
|
|
687
|
+
/** Requests allowed per window and key. */
|
|
688
|
+
max: number;
|
|
689
|
+
/**
|
|
690
|
+
* Who a request counts against. Default: the client IP (`req.ip`) — behind a proxy or load
|
|
691
|
+
* balancer set `trustProxy` in ignite(), or every client shares the proxy's IP. Return
|
|
692
|
+
* `undefined` to not limit this request.
|
|
693
|
+
*/
|
|
694
|
+
key?: (req: Request) => string | undefined;
|
|
695
|
+
/**
|
|
696
|
+
* Which counter: requests to routes with the same name share a limit. Default: the route
|
|
697
|
+
* pattern (`/users/:id`), so each route file has its own — or the path, for middleware
|
|
698
|
+
* that isn't on a route.
|
|
699
|
+
*/
|
|
700
|
+
name?: string;
|
|
701
|
+
/** Body of the 429 response. Default: `'Too many requests, try again later'`. */
|
|
702
|
+
message?: string;
|
|
703
|
+
/**
|
|
704
|
+
* The cache can't be reached: `'allow'` (default) lets requests through — a limiter
|
|
705
|
+
* shouldn't take the API down with it; `'reject'` answers 503.
|
|
706
|
+
*/
|
|
707
|
+
onCacheError?: 'allow' | 'reject';
|
|
708
|
+
/** Send `RateLimit-Limit/Remaining/Reset` (and `Retry-After` on 429). Default: true. */
|
|
709
|
+
headers?: boolean;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Limits requests per key (default: client IP) to `max` per `window`, counted in the cache
|
|
713
|
+
* so the limit holds across every worker and instance:
|
|
714
|
+
*
|
|
715
|
+
* ```ts
|
|
716
|
+
* export const middlewares = [rateLimit({ window: '15m', max: 10 })];
|
|
717
|
+
* ```
|
|
718
|
+
*
|
|
719
|
+
* Needs `cache` in ignite() — use the Redis backend when you run more than one instance.
|
|
720
|
+
*/
|
|
721
|
+
declare function rateLimit(options: RateLimitOptions): RequestHandler;
|
|
722
|
+
|
|
678
723
|
interface CacheResponseOptions {
|
|
679
724
|
/** Seconds to keep a response. */
|
|
680
725
|
ttl: number;
|
|
@@ -722,6 +767,152 @@ declare function defineModel<T extends object = never, const S extends ModelSche
|
|
|
722
767
|
*/
|
|
723
768
|
declare function defineTable<const S extends TableSchema, const O extends TableOptions = object>(name: string, schema: S, options?: O): TableModel<S, O>;
|
|
724
769
|
|
|
770
|
+
type AnyRecord$1 = Record<string, unknown>;
|
|
771
|
+
type Elem$1<V> = V extends readonly (infer E)[] ? E : never;
|
|
772
|
+
type Keys<T> = keyof T & string;
|
|
773
|
+
/** Values that are objects with fields of their own (not arrays, dates, buffers). */
|
|
774
|
+
type Nested<V> = V extends readonly unknown[] | Date | Uint8Array | bigint ? never : V extends object ? V : never;
|
|
775
|
+
/** A field, or one level into an embedded object: `'name'`, `'address.city'`. */
|
|
776
|
+
type Path<T> = Keys<T> | {
|
|
777
|
+
[K in Keys<T>]: `${K}.${Keys<Nested<NonNullable<T[K]>>>}`;
|
|
778
|
+
}[Keys<T>];
|
|
779
|
+
/** `'$field'` / `'$embedded.field'` — a reference to the current record's values. */
|
|
780
|
+
type FieldRef<T> = `$${Path<T>}`;
|
|
781
|
+
/** The value a `'$field'` reference (or a literal) resolves to. */
|
|
782
|
+
type Ref<T, P> = P extends `$${infer K}.${infer R}` ? K extends keyof T ? R extends keyof Nested<NonNullable<T[K]>> ? Nested<NonNullable<T[K]>>[R] : unknown : unknown : P extends `$${infer K}` ? K extends keyof T ? T[K] : unknown : P;
|
|
783
|
+
/** `$sum` / `$avg` over a decimal field stay exact strings; numbers stay numbers. */
|
|
784
|
+
type Numeric<V> = [NonNullable<V>] extends [string] ? string : number;
|
|
785
|
+
type Accumulator<T> = {
|
|
786
|
+
$sum: FieldRef<T> | number;
|
|
787
|
+
} | {
|
|
788
|
+
$avg: FieldRef<T>;
|
|
789
|
+
} | {
|
|
790
|
+
$min: FieldRef<T>;
|
|
791
|
+
} | {
|
|
792
|
+
$max: FieldRef<T>;
|
|
793
|
+
} | {
|
|
794
|
+
$first: FieldRef<T>;
|
|
795
|
+
} | {
|
|
796
|
+
$last: FieldRef<T>;
|
|
797
|
+
} | {
|
|
798
|
+
$push: FieldRef<T>;
|
|
799
|
+
} | {
|
|
800
|
+
$addToSet: FieldRef<T>;
|
|
801
|
+
} | {
|
|
802
|
+
$count: Record<string, never>;
|
|
803
|
+
};
|
|
804
|
+
type AccResult<T, A> = A extends {
|
|
805
|
+
$sum: infer F;
|
|
806
|
+
} ? F extends number ? number : Numeric<Ref<T, F>> : A extends {
|
|
807
|
+
$avg: infer F;
|
|
808
|
+
} ? Numeric<Ref<T, F>> | null : A extends {
|
|
809
|
+
$count: unknown;
|
|
810
|
+
} ? number : A extends {
|
|
811
|
+
$min: infer F;
|
|
812
|
+
} | {
|
|
813
|
+
$max: infer F;
|
|
814
|
+
} | {
|
|
815
|
+
$first: infer F;
|
|
816
|
+
} | {
|
|
817
|
+
$last: infer F;
|
|
818
|
+
} ? Ref<T, F> : A extends {
|
|
819
|
+
$push: infer F;
|
|
820
|
+
} | {
|
|
821
|
+
$addToSet: infer F;
|
|
822
|
+
} ? NonNullable<Ref<T, F>>[] : unknown;
|
|
823
|
+
type GroupKey<T> = FieldRef<T> | null | {
|
|
824
|
+
[k: string]: FieldRef<T>;
|
|
825
|
+
};
|
|
826
|
+
type GroupId<T, I> = I extends null ? null : I extends string ? Ref<T, I> : {
|
|
827
|
+
-readonly [K in keyof I]: Ref<T, I[K]>;
|
|
828
|
+
};
|
|
829
|
+
/** `$group` output: `_id` (plus `id`, its string form) and one field per accumulator. */
|
|
830
|
+
type GroupResult<T, G> = Simplify<{
|
|
831
|
+
_id: GroupId<T, G extends {
|
|
832
|
+
_id: infer I;
|
|
833
|
+
} ? I : null>;
|
|
834
|
+
id: string;
|
|
835
|
+
} & {
|
|
836
|
+
[K in Exclude<keyof G, '_id'>]: AccResult<T, G[K]>;
|
|
837
|
+
}>;
|
|
838
|
+
/** Fields whose values are arrays. */
|
|
839
|
+
type ArrayKeys<T> = {
|
|
840
|
+
[K in Keys<T>]: NonNullable<T[K]> extends readonly unknown[] ? K : never;
|
|
841
|
+
}[Keys<T>];
|
|
842
|
+
/** `T` with ref field `K` replaced by the `M` record(s) it points to. */
|
|
843
|
+
type LookedUp<T, K extends keyof T, M> = Simplify<Omit<T, K> & {
|
|
844
|
+
[P in K]-?: NonNullable<T[K]> extends readonly unknown[] ? InferRecord<M>[] : InferRecord<M> | null;
|
|
845
|
+
}>;
|
|
846
|
+
/** A model `lookup` can join: anything with inferred record types and a mongoose `raw()`. */
|
|
847
|
+
interface LookupTarget {
|
|
848
|
+
readonly name: string;
|
|
849
|
+
readonly $types?: {
|
|
850
|
+
record: unknown;
|
|
851
|
+
};
|
|
852
|
+
raw(): Promise<unknown>;
|
|
853
|
+
}
|
|
854
|
+
type Stage = AnyRecord$1 | (() => Promise<AnyRecord$1[]>);
|
|
855
|
+
declare class Pipeline<T> implements PromiseLike<T[]> {
|
|
856
|
+
private readonly run;
|
|
857
|
+
private readonly stages;
|
|
858
|
+
/** @internal */
|
|
859
|
+
constructor(run: (stages: AnyRecord$1[]) => Promise<unknown[]>, stages?: Stage[]);
|
|
860
|
+
private next;
|
|
861
|
+
/** `$match` — same filter vocabulary as `find`. */
|
|
862
|
+
match(filter: AnyRecord$1): Pipeline<T>;
|
|
863
|
+
sort(spec: Partial<Record<Keys<T>, SortDirection>> & Record<string, SortDirection>): Pipeline<T>;
|
|
864
|
+
skip(n: number): Pipeline<T>;
|
|
865
|
+
limit(n: number): Pipeline<T>;
|
|
866
|
+
/** `$sample` — `n` random records. */
|
|
867
|
+
sample(n: number): Pipeline<T>;
|
|
868
|
+
/** `$project` with an inclusion spec: the result has only those fields (and `id`). */
|
|
869
|
+
project<const P extends Partial<Record<Keys<T>, 1 | true>>>(spec: P): Pipeline<Simplify<Pick<T, Extract<keyof P, keyof T>> & {
|
|
870
|
+
id: string;
|
|
871
|
+
}>>;
|
|
872
|
+
/**
|
|
873
|
+
* `$unwind` an array field: one result per element, the field holding that element.
|
|
874
|
+
* `preserveNullAndEmptyArrays` keeps records without elements (the field is then null).
|
|
875
|
+
*/
|
|
876
|
+
unwind<K extends ArrayKeys<T>, const Keep extends boolean = false>(path: `$${K}`, options?: {
|
|
877
|
+
preserveNullAndEmptyArrays?: Keep;
|
|
878
|
+
}): Pipeline<Simplify<Omit<T, K> & {
|
|
879
|
+
[P in K]-?: Keep extends true ? Elem$1<NonNullable<T[K]>> | null : Elem$1<NonNullable<T[K]>>;
|
|
880
|
+
}>>;
|
|
881
|
+
/** `$group` — `_id` is `'$field'`, `null` or `{ key: '$field' }`; accumulators are typed. */
|
|
882
|
+
group<const G extends {
|
|
883
|
+
_id: GroupKey<T>;
|
|
884
|
+
} & Record<string, unknown>>(spec: G & {
|
|
885
|
+
[K in Exclude<keyof G, '_id'>]: Accumulator<T>;
|
|
886
|
+
}): Pipeline<GroupResult<T, G>>;
|
|
887
|
+
/** `$count` — a single `{ [field]: n }` (no result at all when nothing matched). */
|
|
888
|
+
count<const F extends string>(field: F): Pipeline<{
|
|
889
|
+
[P in F]: number;
|
|
890
|
+
}>;
|
|
891
|
+
/** `$addFields` / `$set` — say what the new fields are: `addFields<{ total: number }>({ … })`. */
|
|
892
|
+
addFields<A extends AnyRecord$1>(spec: Record<keyof A, unknown>): Pipeline<Simplify<Omit<T, keyof A> & A>>;
|
|
893
|
+
/**
|
|
894
|
+
* `$lookup`. With a field that has a `ref` and its model — `lookup('author', User)` — the
|
|
895
|
+
* field is replaced by the referenced record (or `null`; an array of refs becomes an array
|
|
896
|
+
* of records). Or the full form: `lookup({ from: Review, localField: 'id', foreignField:
|
|
897
|
+
* 'place', as: 'reviews' })` adds `reviews: Review[]`. `id` means `_id` on either side.
|
|
898
|
+
*/
|
|
899
|
+
lookup<K extends Keys<T>, M extends LookupTarget>(field: K, from: M): Pipeline<LookedUp<T, K, M>>;
|
|
900
|
+
lookup<M extends LookupTarget, const As extends string>(spec: {
|
|
901
|
+
from: M;
|
|
902
|
+
localField: Keys<T> | `${string}.${string}`;
|
|
903
|
+
foreignField: string;
|
|
904
|
+
as: As;
|
|
905
|
+
}): Pipeline<Simplify<Omit<T, As> & {
|
|
906
|
+
[P in As]: InferRecord<M>[];
|
|
907
|
+
}>>;
|
|
908
|
+
/** Any other stage, with its output type spelled out: `stage<{ … }>({ $facet: … })`. */
|
|
909
|
+
stage<U = T>(stage: AnyRecord$1): Pipeline<U>;
|
|
910
|
+
/** The stages as plain objects (lookups resolved to collection names). */
|
|
911
|
+
toArray(): Promise<AnyRecord$1[]>;
|
|
912
|
+
exec(): Promise<T[]>;
|
|
913
|
+
then<A = T[], B = never>(onfulfilled?: ((value: T[]) => A | PromiseLike<A>) | null, onrejected?: ((reason: unknown) => B | PromiseLike<B>) | null): Promise<A | B>;
|
|
914
|
+
}
|
|
915
|
+
|
|
725
916
|
type AnyRecord = Record<string, unknown>;
|
|
726
917
|
interface CollectionOptions extends ModelOptions {
|
|
727
918
|
/** Default collation for this collection's queries, e.g. `{ locale: 'en', strength: 2 }`. */
|
|
@@ -895,6 +1086,16 @@ interface CollectionModel<S, O = object, R = Rec<S, O>, C = InferCreateInput<S>>
|
|
|
895
1086
|
deleteMany(filter?: CollectionFilter<R>): Promise<{
|
|
896
1087
|
deletedCount: number;
|
|
897
1088
|
}>;
|
|
1089
|
+
/**
|
|
1090
|
+
* A typed aggregation pipeline: `Order.pipeline().match({ … }).group({ _id: '$customer',
|
|
1091
|
+
* total: { $sum: '$amount' } })` — each stage's output type is inferred. Await it (or `.exec()`).
|
|
1092
|
+
*/
|
|
1093
|
+
pipeline(): Pipeline<R>;
|
|
1094
|
+
/**
|
|
1095
|
+
* `$lookup` for a ref field: `Post.lookup('author', User)` → posts whose `author` is the User
|
|
1096
|
+
* record (or null); an array of refs becomes an array of records. Optional filter first.
|
|
1097
|
+
*/
|
|
1098
|
+
lookup<K extends keyof R & string, M extends LookupTarget>(field: K, from: M, filter?: CollectionFilter<R>): Promise<LookedUp<R, K, M>[]>;
|
|
898
1099
|
/** An aggregation pipeline; type the output with the generic: `aggregate<{ _id: string; n: number }>(…)`. */
|
|
899
1100
|
aggregate<T = Record<string, unknown>>(pipeline: Record<string, unknown>[]): Promise<T[]>;
|
|
900
1101
|
bulkWrite(ops: CollectionBulkOp<R, C>[], options?: {
|
|
@@ -965,4 +1166,4 @@ declare function workerCount(): number;
|
|
|
965
1166
|
declare function ignite(config: EFCConfig): Promise<http.Server | undefined>;
|
|
966
1167
|
declare function gracefulShutdown(server: http.Server | undefined, timeoutMs?: number): void;
|
|
967
1168
|
|
|
968
|
-
export { type CollectionBulkOp, type CollectionBulkResult, type CollectionChange, type CollectionChangeStream, type CollectionFilter, type CollectionFindOptions, type CollectionModel, type CollectionOptions, CollectionSchema, type CollectionUpdate, type CollectionWriteResult, EFCConfig, HttpError, InferCreateInput, InferSchema, type InferTableRecord, type JsonFilter, type ListFilter, ModelOptions, ModelSchema, ModelValidationError, RouteEntry, type ScalarFilter, SortDirection, type StringFilter, type TableAggregateArgs, type TableAggregateResult, type TableCreateData, type TableCreateInput, type TableFindManyArgs, type TableGroupByArgs, type TableInclude, type TableModel, TableOptions, type TableOrderBy, type TableRecord, type TableResult, TableSchema, type TableSelect, type TableUpdateData, type TableUpdateInput, type TableWhere, type TableWhereUnique, type Tables, cache, cacheResponse, compose, db, defineCollection, defineModel, defineTable, getDbClient, getLogger, gracefulShutdown, ignite, isHttpError, logger, scanDir, setDbClient, transaction, workerCount };
|
|
1169
|
+
export { type Accumulator, type CollectionBulkOp, type CollectionBulkResult, type CollectionChange, type CollectionChangeStream, type CollectionFilter, type CollectionFindOptions, type CollectionModel, type CollectionOptions, CollectionSchema, type CollectionUpdate, type CollectionWriteResult, EFCConfig, type FieldRef, type GroupResult, HttpError, InferCreateInput, InferRecord, InferSchema, type InferTableRecord, type JsonFilter, type ListFilter, type LookedUp, type LookupTarget, ModelOptions, ModelSchema, ModelValidationError, Pipeline, type RateLimitOptions, RouteEntry, type ScalarFilter, SortDirection, type StringFilter, type TableAggregateArgs, type TableAggregateResult, type TableCreateData, type TableCreateInput, type TableFindManyArgs, type TableGroupByArgs, type TableInclude, type TableModel, TableOptions, type TableOrderBy, type TableRecord, type TableResult, TableSchema, type TableSelect, type TableUpdateData, type TableUpdateInput, type TableWhere, type TableWhereUnique, type Tables, cache, cacheResponse, compose, db, defineCollection, defineModel, defineTable, getDbClient, getLogger, gracefulShutdown, ignite, isHttpError, logger, rateLimit, scanDir, setDbClient, transaction, workerCount };
|
package/dist/index.js
CHANGED
|
@@ -3,15 +3,17 @@ import {
|
|
|
3
3
|
closeCache,
|
|
4
4
|
configureAuth,
|
|
5
5
|
configureCache,
|
|
6
|
+
isCacheConfigured,
|
|
7
|
+
rawIncr,
|
|
6
8
|
servePrimaryCache
|
|
7
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-7KC2H76D.js";
|
|
8
10
|
import {
|
|
9
11
|
scanDir
|
|
10
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-NI2BNGGV.js";
|
|
11
13
|
import {
|
|
12
14
|
closeBullMQ,
|
|
13
15
|
initBullMQ
|
|
14
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-ATVD2HGC.js";
|
|
15
17
|
import {
|
|
16
18
|
connectMongo,
|
|
17
19
|
db,
|
|
@@ -21,35 +23,34 @@ import {
|
|
|
21
23
|
getDbClient,
|
|
22
24
|
setDbClient,
|
|
23
25
|
transaction
|
|
24
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-PGJQK36V.js";
|
|
25
27
|
import {
|
|
26
28
|
HttpError,
|
|
27
29
|
ModelValidationError,
|
|
28
30
|
isHttpError,
|
|
29
31
|
setAutoSync,
|
|
30
32
|
setDbEngine
|
|
31
|
-
} from "./chunk-
|
|
32
|
-
import {
|
|
33
|
-
configureQueryLog,
|
|
34
|
-
connectPostgres
|
|
35
|
-
} from "./chunk-HXV543HZ.js";
|
|
33
|
+
} from "./chunk-QDEDOHP7.js";
|
|
36
34
|
import {
|
|
37
35
|
closePgBoss,
|
|
38
36
|
initPgBoss
|
|
39
|
-
} from "./chunk-
|
|
40
|
-
import "./chunk-
|
|
37
|
+
} from "./chunk-R4XO4SVM.js";
|
|
38
|
+
import "./chunk-R52CUEGT.js";
|
|
41
39
|
import {
|
|
42
40
|
listTasks,
|
|
43
41
|
registerTask
|
|
44
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-RAB44UGX.js";
|
|
45
43
|
import {
|
|
44
|
+
checkConnectionBudget,
|
|
46
45
|
configureLogger,
|
|
46
|
+
configureQueryLog,
|
|
47
|
+
connectPostgres,
|
|
47
48
|
getCurrentUser,
|
|
48
49
|
getLogger,
|
|
49
50
|
logger,
|
|
50
51
|
requestLogger,
|
|
51
52
|
runWithContext
|
|
52
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-73XJUT2S.js";
|
|
53
54
|
|
|
54
55
|
// src/index.ts
|
|
55
56
|
import fs2 from "fs";
|
|
@@ -854,6 +855,71 @@ function generateDashboard(routes, basePath, port, projectName, projectVersion)
|
|
|
854
855
|
</html>`;
|
|
855
856
|
}
|
|
856
857
|
|
|
858
|
+
// src/rate-limit.ts
|
|
859
|
+
var UNITS = { s: 1, m: 60, h: 3600, d: 86400 };
|
|
860
|
+
function parseWindow(window) {
|
|
861
|
+
if (typeof window === "number") {
|
|
862
|
+
if (window > 0) return window;
|
|
863
|
+
} else {
|
|
864
|
+
const m = /^(\d+(?:\.\d+)?)\s*(s|m|h|d)$/.exec(window.trim());
|
|
865
|
+
if (m) return Number(m[1]) * UNITS[m[2]];
|
|
866
|
+
}
|
|
867
|
+
throw new Error(`[EFC] rateLimit: window must be seconds or like '15m' \u2014 got ${String(window)}`);
|
|
868
|
+
}
|
|
869
|
+
var lastCacheError = 0;
|
|
870
|
+
function rateLimit(options) {
|
|
871
|
+
const windowSeconds = parseWindow(options.window);
|
|
872
|
+
if (!Number.isInteger(options.max) || options.max < 1) {
|
|
873
|
+
throw new Error("[EFC] rateLimit: max must be a positive integer");
|
|
874
|
+
}
|
|
875
|
+
const keyOf = options.key ?? ((req) => req.ip ?? req.socket.remoteAddress);
|
|
876
|
+
const message = options.message ?? "Too many requests, try again later";
|
|
877
|
+
const headers = options.headers ?? true;
|
|
878
|
+
return (req, res, next) => {
|
|
879
|
+
void (async () => {
|
|
880
|
+
const who = keyOf(req);
|
|
881
|
+
if (who === void 0) return next();
|
|
882
|
+
if (!isCacheConfigured()) {
|
|
883
|
+
throw new Error("[EFC] rateLimit needs a cache \u2014 pass cache: { backend } to ignite()");
|
|
884
|
+
}
|
|
885
|
+
const bucket = options.name ?? req.baseUrl + (req.route?.path ?? req.path);
|
|
886
|
+
const windowMs = windowSeconds * 1e3;
|
|
887
|
+
const now = Date.now();
|
|
888
|
+
const slot = Math.floor(now / windowMs);
|
|
889
|
+
const resetMs = (slot + 1) * windowMs - now;
|
|
890
|
+
let count;
|
|
891
|
+
try {
|
|
892
|
+
count = (await rawIncr(`rl:${bucket}:${who}:${slot}`, Math.ceil(resetMs / 1e3) + 1)).value;
|
|
893
|
+
} catch (err) {
|
|
894
|
+
if (Date.now() - lastCacheError > 3e4) {
|
|
895
|
+
lastCacheError = Date.now();
|
|
896
|
+
getLogger().error(
|
|
897
|
+
{ err },
|
|
898
|
+
`rateLimit: cache unavailable \u2014 ${options.onCacheError === "reject" ? "rejecting with 503" : "allowing requests"}`
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
if (options.onCacheError === "reject") {
|
|
902
|
+
res.status(503).json({ error: "Service Unavailable", statusCode: 503 });
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
return next();
|
|
906
|
+
}
|
|
907
|
+
const resetSeconds = Math.max(1, Math.ceil(resetMs / 1e3));
|
|
908
|
+
if (headers) {
|
|
909
|
+
res.setHeader("RateLimit-Limit", String(options.max));
|
|
910
|
+
res.setHeader("RateLimit-Remaining", String(Math.max(0, options.max - count)));
|
|
911
|
+
res.setHeader("RateLimit-Reset", String(resetSeconds));
|
|
912
|
+
}
|
|
913
|
+
if (count > options.max) {
|
|
914
|
+
if (headers) res.setHeader("Retry-After", String(resetSeconds));
|
|
915
|
+
res.status(429).json({ error: message, statusCode: 429 });
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
next();
|
|
919
|
+
})().catch(next);
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
|
|
857
923
|
// src/cache/response.ts
|
|
858
924
|
var RESPONSE_PREFIX = "res:";
|
|
859
925
|
function cacheResponse(options) {
|
|
@@ -953,6 +1019,16 @@ async function ignite(config) {
|
|
|
953
1019
|
const authStrategy = config.authStrategy ?? "http-only";
|
|
954
1020
|
const clusterEnabled = config.cluster ?? process.env["NODE_ENV"] === "production";
|
|
955
1021
|
configureLogger(config.logging);
|
|
1022
|
+
if (!["http-only", "bearer", "localStorage"].includes(authStrategy) && (!clusterEnabled || cluster2.isPrimary)) {
|
|
1023
|
+
getLogger().warn(
|
|
1024
|
+
`[EFC] Unknown authStrategy "${String(authStrategy)}" \u2014 treated as 'bearer'. Use 'http-only' or 'bearer'; this will be an error in 1.0.`
|
|
1025
|
+
);
|
|
1026
|
+
}
|
|
1027
|
+
if (jwtSecret && Buffer.byteLength(jwtSecret) < 32 && process.env["NODE_ENV"] === "production" && (!clusterEnabled || cluster2.isPrimary)) {
|
|
1028
|
+
getLogger().warn(
|
|
1029
|
+
`[EFC] jwtSecret is ${Buffer.byteLength(jwtSecret)} bytes \u2014 use at least 32 random bytes in production (openssl rand -hex 64).`
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
956
1032
|
configureQueryLog(config.logging);
|
|
957
1033
|
if (clusterEnabled && cluster2.isPrimary) {
|
|
958
1034
|
if (config.cache && config.cache.backend === "memory") {
|
|
@@ -966,6 +1042,7 @@ async function ignite(config) {
|
|
|
966
1042
|
return;
|
|
967
1043
|
}
|
|
968
1044
|
const app = express();
|
|
1045
|
+
if (config.trustProxy !== void 0) app.set("trust proxy", config.trustProxy);
|
|
969
1046
|
app.set(
|
|
970
1047
|
"json replacer",
|
|
971
1048
|
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
@@ -1000,12 +1077,26 @@ async function ignite(config) {
|
|
|
1000
1077
|
}
|
|
1001
1078
|
if (database) setDbEngine(database);
|
|
1002
1079
|
setAutoSync(config.autoSync ?? true);
|
|
1080
|
+
const poolWorkers = clusterEnabled ? workers ?? os.cpus().length : 1;
|
|
1081
|
+
const reportsPools = !clusterEnabled || cluster2.worker?.id === 1;
|
|
1003
1082
|
if (database === "mongodb" && databaseUrl) {
|
|
1004
1083
|
const conn = await connectMongo(databaseUrl, config.databasePool);
|
|
1005
1084
|
setDbClient(conn);
|
|
1085
|
+
if (reportsPools) {
|
|
1086
|
+
const max = config.databasePool?.max ?? 100;
|
|
1087
|
+
getLogger().info(
|
|
1088
|
+
`MongoDB connections: up to ${poolWorkers * max} from this machine (${poolWorkers} worker(s) \xD7 maxPoolSize ${max})`
|
|
1089
|
+
);
|
|
1090
|
+
}
|
|
1006
1091
|
} else if (database === "postgresql" && databaseUrl) {
|
|
1007
1092
|
const pool = await connectPostgres(databaseUrl, config.databasePool);
|
|
1008
1093
|
setDbClient(pool);
|
|
1094
|
+
if (reportsPools) {
|
|
1095
|
+
const max = config.databasePool?.max ?? 10;
|
|
1096
|
+
const boss = config.tasks && config.tasks.backend === "pg-boss" && !config.tasks.connectionString ? 10 : 0;
|
|
1097
|
+
const breakdown = `${poolWorkers} worker(s) \xD7 (pool ${max}${boss ? ` + pg-boss ${boss}` : ""})`;
|
|
1098
|
+
await checkConnectionBudget(poolWorkers * (max + boss), breakdown);
|
|
1099
|
+
}
|
|
1009
1100
|
}
|
|
1010
1101
|
if (config.cache) {
|
|
1011
1102
|
await configureCache(config.cache);
|
|
@@ -1065,7 +1156,8 @@ async function ignite(config) {
|
|
|
1065
1156
|
getLogger().warn({ err }, "Error after the response was sent");
|
|
1066
1157
|
return;
|
|
1067
1158
|
}
|
|
1068
|
-
const
|
|
1159
|
+
const status = err?.statusCode;
|
|
1160
|
+
const duckTyped = err instanceof Error && typeof status === "number" && status >= 400 && status < 500 ? err : null;
|
|
1069
1161
|
if (isHttpError(err)) {
|
|
1070
1162
|
const issues = err.issues;
|
|
1071
1163
|
res.status(err.statusCode).json({
|
|
@@ -1137,6 +1229,7 @@ export {
|
|
|
1137
1229
|
isHttpError,
|
|
1138
1230
|
listTasks,
|
|
1139
1231
|
logger,
|
|
1232
|
+
rateLimit,
|
|
1140
1233
|
scanDir,
|
|
1141
1234
|
setDbClient,
|
|
1142
1235
|
transaction,
|