@miguelmorales13/nestkit 0.26.0 → 0.28.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/alerts/alert-on-failure.decorator.d.ts +5 -0
- package/dist/alerts/alert-sinks.d.ts +29 -0
- package/dist/alerts/alerts.module.d.ts +19 -0
- package/dist/alerts/alerts.options.d.ts +1 -0
- package/dist/alerts/alerts.service.d.ts +28 -0
- package/dist/alerts/alerts.types.d.ts +66 -0
- package/dist/alerts/index.cjs +276 -0
- package/dist/alerts/index.d.ts +10 -0
- package/dist/alerts/index.js +276 -0
- package/dist/alerts/logger-with-alerts.d.ts +18 -0
- package/dist/alerts/process-guards.d.ts +21 -0
- package/dist/alerts/runtime.d.ts +4 -0
- package/dist/audit/index.cjs +13 -13
- package/dist/audit/index.js +2 -2
- package/dist/auth/index.cjs +21 -21
- package/dist/auth/index.js +3 -3
- package/dist/auth/oauth/index.cjs +101 -101
- package/dist/auth/oauth/index.js +3 -3
- package/dist/bootstrap/apply-defaults.d.ts +9 -0
- package/dist/bootstrap/index.cjs +7 -6
- package/dist/bootstrap/index.js +6 -5
- package/dist/chunk-3TUMVLPJ.js +14 -0
- package/dist/{chunk-PA24P76K.js → chunk-45SW7FBE.js} +1 -1
- package/dist/{chunk-RF75KC63.cjs → chunk-47IYXZHW.cjs} +2 -2
- package/dist/{chunk-TUNDBBQF.js → chunk-4WWOKZIO.js} +4 -4
- package/dist/{chunk-2DUEQKOI.js → chunk-5LVGCTJ3.js} +4 -4
- package/dist/chunk-A6YGIZCQ.cjs +14 -0
- package/dist/chunk-A7FI6HXV.js +40 -0
- package/dist/chunk-CU4FUIVJ.cjs +8 -0
- package/dist/{chunk-FH5UNWWW.cjs → chunk-D35TBVRO.cjs} +4 -4
- package/dist/{chunk-4MGIQFAJ.js → chunk-D3DDJWUD.js} +5 -0
- package/dist/chunk-DVGPEBUL.js +8 -0
- package/dist/{chunk-VKOPDDCC.js → chunk-ENZ7LQRE.js} +1 -1
- package/dist/{chunk-3AUOOEQO.cjs → chunk-F77X4QUN.cjs} +2 -2
- package/dist/chunk-FBNV5X6C.js +61 -0
- package/dist/{chunk-APUFKA4K.cjs → chunk-FDZQCLLK.cjs} +6 -6
- package/dist/{chunk-DYHSOULW.js → chunk-IGSNB5BX.js} +1 -1
- package/dist/chunk-IVWPA6QH.cjs +90 -0
- package/dist/{chunk-LSDY6ETG.cjs → chunk-JJKGQNGD.cjs} +5 -5
- package/dist/{chunk-ALIKVFOV.cjs → chunk-JRFE7NSO.cjs} +12 -4
- package/dist/{chunk-HVHYZXBB.cjs → chunk-KNU5RN3O.cjs} +3 -3
- package/dist/{chunk-52IOOHNX.cjs → chunk-KQPJCVN3.cjs} +26 -26
- package/dist/chunk-LGFHLAY3.cjs +61 -0
- package/dist/{chunk-2REOCMUD.cjs → chunk-LRX7AMSS.cjs} +6 -1
- package/dist/{chunk-4PFAKLT3.js → chunk-MUWHGBIB.js} +1 -1
- package/dist/{chunk-ZJMLEP5H.js → chunk-NJYLQDB3.js} +1 -1
- package/dist/{chunk-IFNYRZP2.js → chunk-OSRH6KYZ.js} +4 -4
- package/dist/{chunk-6RAPVLJM.js → chunk-OTE77ONL.js} +1 -1
- package/dist/chunk-UDACUMLO.cjs +40 -0
- package/dist/{chunk-PFHHLB7B.js → chunk-UGAAJRPO.js} +10 -2
- package/dist/{chunk-SPTDXUED.cjs → chunk-URLDTS2Q.cjs} +2 -2
- package/dist/{chunk-W2T2VFLC.cjs → chunk-VALDHJOO.cjs} +5 -5
- package/dist/chunk-WFCQDOSN.js +90 -0
- package/dist/consent/consent.interceptor.d.ts +20 -0
- package/dist/consent/consent.module.d.ts +25 -0
- package/dist/consent/consent.options.d.ts +30 -0
- package/dist/consent/consent.port.d.ts +17 -0
- package/dist/consent/consent.service.d.ts +44 -0
- package/dist/consent/guard/index.cjs +13 -0
- package/dist/consent/guard/index.d.ts +31 -0
- package/dist/consent/guard/index.js +13 -0
- package/dist/consent/index.cjs +271 -0
- package/dist/consent/index.d.ts +13 -0
- package/dist/consent/index.js +271 -0
- package/dist/consent/memory.store.d.ts +7 -0
- package/dist/consent/shared/index.cjs +11 -0
- package/dist/consent/shared/index.d.ts +19 -0
- package/dist/consent/shared/index.js +11 -0
- package/dist/consent/typeorm.store.d.ts +22 -0
- package/dist/crud/index.cjs +4 -4
- package/dist/crud/index.js +3 -3
- package/dist/database/postgres/index.cjs +3 -3
- package/dist/database/postgres/index.js +2 -2
- package/dist/database/supabase/index.cjs +3 -3
- package/dist/database/supabase/index.js +2 -2
- package/dist/database/typeorm/index.cjs +2 -2
- package/dist/database/typeorm/index.js +1 -1
- package/dist/devices/device-check.interceptor.d.ts +20 -0
- package/dist/devices/devices.module.d.ts +28 -0
- package/dist/devices/devices.options.d.ts +53 -0
- package/dist/devices/devices.port.d.ts +62 -0
- package/dist/devices/devices.service.d.ts +58 -0
- package/dist/devices/index.cjs +327 -0
- package/dist/devices/index.d.ts +8 -0
- package/dist/devices/index.js +327 -0
- package/dist/devices/memory.store.d.ts +12 -0
- package/dist/email/index.cjs +2 -2
- package/dist/email/index.js +1 -1
- package/dist/email/nodemailer/index.cjs +2 -2
- package/dist/email/nodemailer/index.js +1 -1
- package/dist/email/resend/index.cjs +2 -2
- package/dist/email/resend/index.js +1 -1
- package/dist/entities/index.cjs +1 -1
- package/dist/entities/index.js +1 -1
- package/dist/errors/index.cjs +7 -7
- package/dist/errors/index.js +7 -7
- package/dist/events/buses.d.ts +27 -0
- package/dist/events/events.controller.d.ts +15 -0
- package/dist/events/events.module.d.ts +29 -0
- package/dist/events/events.options.d.ts +50 -0
- package/dist/events/events.service.d.ts +49 -0
- package/dist/events/events.types.d.ts +77 -0
- package/dist/events/index.cjs +557 -0
- package/dist/events/index.d.ts +10 -0
- package/dist/events/index.js +557 -0
- package/dist/events/memory-ticket.store.d.ts +9 -0
- package/dist/google-business/google-business-http.d.ts +41 -0
- package/dist/google-business/google-business.errors.d.ts +75 -0
- package/dist/google-business/google-business.mappers.d.ts +52 -0
- package/dist/google-business/google-business.module.d.ts +26 -0
- package/dist/google-business/google-business.options.d.ts +40 -0
- package/dist/google-business/google-business.ports.d.ts +18 -0
- package/dist/google-business/google-business.service.d.ts +120 -0
- package/dist/google-business/google-business.types.d.ts +155 -0
- package/dist/google-business/index.cjs +1025 -0
- package/dist/google-business/index.d.ts +15 -0
- package/dist/google-business/index.js +1025 -0
- package/dist/google-business/testing/google-simulator.d.ts +61 -0
- package/dist/hardening/body-limits.d.ts +24 -0
- package/dist/hardening/http.types.d.ts +26 -0
- package/dist/hardening/index.cjs +179 -0
- package/dist/hardening/index.d.ts +19 -0
- package/dist/hardening/index.js +179 -0
- package/dist/hardening/memory-rate-limit.store.d.ts +10 -0
- package/dist/hardening/origin-secret.d.ts +29 -0
- package/dist/hardening/rate-limit.decorator.d.ts +8 -0
- package/dist/hardening/rate-limit.guard.d.ts +18 -0
- package/dist/hardening/rate-limit.module.d.ts +23 -0
- package/dist/hardening/rate-limit.options.d.ts +35 -0
- package/dist/hardening/rate-limit.port.d.ts +11 -0
- package/dist/hardening/redis-rate-limit.store.d.ts +23 -0
- package/dist/hardening/trust-proxy.d.ts +22 -0
- package/dist/health/health.controller.d.ts +32 -0
- package/dist/health/health.module.d.ts +15 -0
- package/dist/health/health.options.d.ts +24 -0
- package/dist/health/index.cjs +103 -0
- package/dist/health/index.d.ts +5 -0
- package/dist/health/index.js +103 -0
- package/dist/i18n/index.cjs +3 -3
- package/dist/i18n/index.js +2 -2
- package/dist/idempotency/idempotency.interceptor.d.ts +1 -0
- package/dist/idempotency/idempotency.options.d.ts +15 -0
- package/dist/idempotency/index.cjs +214 -7
- package/dist/idempotency/index.d.ts +5 -0
- package/dist/idempotency/index.js +210 -3
- package/dist/idempotency/no-idempotency.decorator.d.ts +8 -0
- package/dist/idempotency/postgres.store.d.ts +49 -0
- package/dist/idempotency/redis.store.d.ts +59 -0
- package/dist/index.cjs +19 -18
- package/dist/index.js +32 -31
- package/dist/invoicing/index.cjs +2 -2
- package/dist/invoicing/index.js +1 -1
- package/dist/jobs/defer-job.d.ts +10 -0
- package/dist/jobs/index.cjs +318 -0
- package/dist/jobs/index.d.ts +8 -0
- package/dist/jobs/index.js +318 -0
- package/dist/jobs/jobs-admin.controller.d.ts +18 -0
- package/dist/jobs/jobs.module.d.ts +33 -0
- package/dist/jobs/jobs.options.d.ts +62 -0
- package/dist/jobs/jobs.service.d.ts +53 -0
- package/dist/jobs/jobs.sql.d.ts +11 -0
- package/dist/media/index.cjs +14 -14
- package/dist/media/index.js +1 -1
- package/dist/meta/index.cjs +3 -3
- package/dist/meta/index.js +1 -1
- package/dist/notifications/index.cjs +375 -0
- package/dist/notifications/index.d.ts +8 -0
- package/dist/notifications/index.js +375 -0
- package/dist/notifications/memory.stores.d.ts +23 -0
- package/dist/notifications/notifications.controller.d.ts +11 -0
- package/dist/notifications/notifications.module.d.ts +31 -0
- package/dist/notifications/notifications.options.d.ts +33 -0
- package/dist/notifications/notifications.port.d.ts +97 -0
- package/dist/notifications/notifier.service.d.ts +31 -0
- package/dist/payments/index.cjs +7 -7
- package/dist/payments/index.js +1 -1
- package/dist/pinterest/index.cjs +3 -3
- package/dist/pinterest/index.js +1 -1
- package/dist/privacy/anonymizer.d.ts +14 -0
- package/dist/privacy/index.cjs +768 -0
- package/dist/privacy/index.d.ts +13 -0
- package/dist/privacy/index.js +768 -0
- package/dist/privacy/memory.store.d.ts +15 -0
- package/dist/privacy/privacy.module.d.ts +30 -0
- package/dist/privacy/privacy.options.d.ts +43 -0
- package/dist/privacy/privacy.port.d.ts +25 -0
- package/dist/privacy/privacy.service.d.ts +69 -0
- package/dist/privacy/privacy.types.d.ts +125 -0
- package/dist/privacy/sql.d.ts +7 -0
- package/dist/privacy/sql.store.d.ts +21 -0
- package/dist/privacy/zip.d.ts +23 -0
- package/dist/push/index.cjs +13 -13
- package/dist/push/index.js +5 -5
- package/dist/resilience/alert-channels.d.ts +39 -0
- package/dist/resilience/alert-errors.interceptor.d.ts +10 -0
- package/dist/resilience/alert-on-failure.decorator.d.ts +10 -0
- package/dist/resilience/alert.service.d.ts +77 -0
- package/dist/resilience/index.cjs +863 -0
- package/dist/resilience/index.d.ts +18 -0
- package/dist/resilience/index.js +863 -0
- package/dist/resilience/memory-alert-store.d.ts +26 -0
- package/dist/resilience/provider-health.controller.d.ts +14 -0
- package/dist/resilience/provider-unavailable.exception.d.ts +11 -0
- package/dist/resilience/resilience.module.d.ts +34 -0
- package/dist/resilience/resilience.options.d.ts +28 -0
- package/dist/resilience/resilience.types.d.ts +167 -0
- package/dist/resilience/resilient-fetch.d.ts +38 -0
- package/dist/resilience/runtime.d.ts +24 -0
- package/dist/resilience/typeorm/alert.entity.d.ts +21 -0
- package/dist/resilience/typeorm/index.cjs +102 -0
- package/dist/resilience/typeorm/index.d.ts +3 -0
- package/dist/resilience/typeorm/index.js +102 -0
- package/dist/resilience/typeorm/typeorm-alert-store.d.ts +39 -0
- package/dist/resilience/validate-destination.d.ts +63 -0
- package/dist/response/index.cjs +3 -3
- package/dist/response/index.js +2 -2
- package/dist/scheduling/cron-lock.service.d.ts +36 -0
- package/dist/scheduling/cron-unico.decorator.d.ts +27 -0
- package/dist/scheduling/fallback.store.d.ts +34 -0
- package/dist/scheduling/index.cjs +392 -0
- package/dist/scheduling/index.d.ts +18 -0
- package/dist/scheduling/index.js +392 -0
- package/dist/scheduling/lock-store.port.d.ts +19 -0
- package/dist/scheduling/memory.store.d.ts +15 -0
- package/dist/scheduling/redis.module.d.ts +31 -0
- package/dist/scheduling/redis.store.d.ts +24 -0
- package/dist/scheduling/scheduling.module.d.ts +24 -0
- package/dist/scheduling/scheduling.options.d.ts +27 -0
- package/dist/scheduling/sql.store.d.ts +26 -0
- package/dist/secrets/index.cjs +274 -0
- package/dist/secrets/index.d.ts +8 -0
- package/dist/secrets/index.js +274 -0
- package/dist/secrets/secrets.errors.d.ts +6 -0
- package/dist/secrets/secrets.module.d.ts +21 -0
- package/dist/secrets/secrets.options.d.ts +32 -0
- package/dist/secrets/secrets.service.d.ts +54 -0
- package/dist/secrets/secrets.transformer.d.ts +33 -0
- package/dist/security/hash.d.ts +8 -0
- package/dist/security/index.cjs +119 -2
- package/dist/security/index.d.ts +5 -0
- package/dist/security/index.js +119 -2
- package/dist/security/mask.d.ts +22 -0
- package/dist/security/signed-grant.d.ts +30 -0
- package/dist/storage/index.cjs +2 -2
- package/dist/storage/index.js +1 -1
- package/dist/stripe/index.cjs +7 -7
- package/dist/stripe/index.js +1 -1
- package/dist/telegram/index.cjs +2 -2
- package/dist/telegram/index.js +1 -1
- package/dist/tenancy/app-role.d.ts +24 -0
- package/dist/tenancy/db-helpers.d.ts +12 -0
- package/dist/tenancy/index.cjs +205 -0
- package/dist/tenancy/index.d.ts +14 -0
- package/dist/tenancy/index.js +205 -0
- package/dist/tenancy/pg/index.cjs +34 -0
- package/dist/tenancy/pg/index.d.ts +2 -0
- package/dist/tenancy/pg/index.js +34 -0
- package/dist/tenancy/pg/with-tenant.d.ts +23 -0
- package/dist/tenancy/request-context.d.ts +18 -0
- package/dist/tenancy/rls-guardrail.d.ts +38 -0
- package/dist/tenancy/scope.d.ts +5 -0
- package/dist/tenancy/tenancy.errors.d.ts +5 -0
- package/dist/tenancy/tenancy.middleware.d.ts +8 -0
- package/dist/tenancy/tenancy.module.d.ts +37 -0
- package/dist/tenancy/tenancy.options.d.ts +34 -0
- package/dist/tenancy/typeorm/index.cjs +41 -0
- package/dist/tenancy/typeorm/index.d.ts +2 -0
- package/dist/tenancy/typeorm/index.js +41 -0
- package/dist/tenancy/typeorm/with-tenant.d.ts +23 -0
- package/dist/tiktok/index.cjs +3 -3
- package/dist/tiktok/index.js +1 -1
- package/dist/tracking/index.cjs +3 -3
- package/dist/tracking/index.js +2 -2
- package/dist/umami/index.cjs +4 -4
- package/dist/umami/index.js +1 -1
- package/dist/whatsapp/index.cjs +2 -2
- package/dist/whatsapp/index.js +1 -1
- package/package.json +107 -2
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { LookupFunction } from 'node:net';
|
|
2
|
+
/**
|
|
3
|
+
* Defensa contra SSRF: valida que una URL que la API va a llamar por cuenta de un tenant
|
|
4
|
+
* (webhook saliente, imagen externa…) no apunte a la red interna. Úsala dos veces: al guardar el
|
|
5
|
+
* destino (rechazo de entrada) y justo antes del `fetch` real (el DNS puede cambiar entre el alta
|
|
6
|
+
* y el envío: "rebinding"). Nunca sigas una redirección 3xx: trátala como fallo, o revalida cada salto.
|
|
7
|
+
*
|
|
8
|
+
* `validarDestinoFijo` va un paso más allá: resuelve UNA vez, valida esa IP y devuelve la dirección
|
|
9
|
+
* fijada (y, si `undici` está instalado, un `Dispatcher` con ella clavada) para que el `fetch` no
|
|
10
|
+
* resuelva de nuevo. Eso solo protege en runtimes cuyo `fetch` respeta `dispatcher` (Node); Bun
|
|
11
|
+
* lo ignora sin romper.
|
|
12
|
+
*/
|
|
13
|
+
export interface DestinationPolicy {
|
|
14
|
+
/**
|
|
15
|
+
* Exige `https` y rechaza IP privada/loopback/link-local. Por defecto `NODE_ENV === 'production'`.
|
|
16
|
+
* Fuera de producción se relaja (pruebas contra un receptor local); nunca lo relajes en producción.
|
|
17
|
+
*/
|
|
18
|
+
estricto?: boolean;
|
|
19
|
+
/** Si no está vacía, el host DEBE coincidir con alguno: `api.x.com` o `*.x.com`. */
|
|
20
|
+
hostsPermitidos?: string[];
|
|
21
|
+
/** Hosts siempre rechazados (mismo formato). Ganan sobre `hostsPermitidos`. */
|
|
22
|
+
hostsBloqueados?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* IP o CIDR (`10.1.2.3`, `10.0.0.0/8`) que se aceptan aunque sean privadas: un servicio interno
|
|
25
|
+
* conocido. Es una excepción explícita, no un relajamiento general.
|
|
26
|
+
*/
|
|
27
|
+
ipsPermitidas?: string[];
|
|
28
|
+
/** Protocolos aceptados. Por defecto `https:` en estricto, `http:` y `https:` si no. */
|
|
29
|
+
protocolos?: string[];
|
|
30
|
+
/** Si se da, solo estos puertos (el implícito de https es 443, el de http 80). */
|
|
31
|
+
puertosPermitidos?: number[];
|
|
32
|
+
/** Códigos de las excepciones. Por defecto `DESTINATION_INVALID`, `DESTINATION_NOT_ALLOWED`, `DESTINATION_UNRESOLVABLE`. */
|
|
33
|
+
codigos?: {
|
|
34
|
+
invalido?: string;
|
|
35
|
+
noPermitido?: string;
|
|
36
|
+
noResuelve?: string;
|
|
37
|
+
};
|
|
38
|
+
/** Resolución de DNS (pruebas). Por defecto `dns.lookup(host, { all: true })`. */
|
|
39
|
+
resolver?: (host: string) => Promise<{
|
|
40
|
+
address: string;
|
|
41
|
+
family: number;
|
|
42
|
+
}[]>;
|
|
43
|
+
}
|
|
44
|
+
/** `true` si la dirección no es pública. */
|
|
45
|
+
export declare function esIpPrivada(ip: string, family?: number): boolean;
|
|
46
|
+
/** Lanza `ValidationAppException` (`DESTINATION_*`) si `urlStr` no es una URL pública y segura de llamar. */
|
|
47
|
+
export declare function validarDestino(urlStr: string, policy?: DestinationPolicy): Promise<URL>;
|
|
48
|
+
/** Alias de {@link validarDestino}, para revalidar cada salto si algún día se siguen redirecciones. */
|
|
49
|
+
export declare const revalidarTrasRedirect: typeof validarDestino;
|
|
50
|
+
export interface PinnedDestination {
|
|
51
|
+
url: URL;
|
|
52
|
+
/** La IP ya validada, a la que debe conectarse el `fetch`. */
|
|
53
|
+
address: string;
|
|
54
|
+
family: number;
|
|
55
|
+
/** `lookup` de `net` fijado a esa IP, para `http.request`/`undici` `connect.lookup`. */
|
|
56
|
+
lookup: LookupFunction;
|
|
57
|
+
/** Dispatcher de `undici` con la IP clavada, si `undici` está instalado; pásalo como `{ dispatcher }`. Ciérralo al terminar. */
|
|
58
|
+
dispatcher?: {
|
|
59
|
+
close(): Promise<void>;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Como {@link validarDestino}, pero fija la IP validada para que el `fetch` no vuelva a resolver DNS. */
|
|
63
|
+
export declare function validarDestinoFijo(urlStr: string, policy?: DestinationPolicy): Promise<PinnedDestination>;
|
package/dist/response/index.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-H2EHN366.cjs');
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkF77X4QUNcjs = require('../chunk-F77X4QUN.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkY72D5L6Icjs = require('../chunk-Y72D5L6I.cjs');
|
|
10
10
|
require('../chunk-SDWHKPXI.cjs');
|
|
11
|
-
require('../chunk-
|
|
11
|
+
require('../chunk-LRX7AMSS.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
exports.ResponseInterceptor =
|
|
17
|
+
exports.ResponseInterceptor = _chunkF77X4QUNcjs.ResponseInterceptor; exports.buildPageMeta = _chunkY72D5L6Icjs.buildPageMeta; exports.isPaginated = _chunkY72D5L6Icjs.isPaginated; exports.paginated = _chunkY72D5L6Icjs.paginated;
|
package/dist/response/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import "../chunk-ODPSIFOB.js";
|
|
2
2
|
import {
|
|
3
3
|
ResponseInterceptor
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-IGSNB5BX.js";
|
|
5
5
|
import {
|
|
6
6
|
buildPageMeta,
|
|
7
7
|
isPaginated,
|
|
8
8
|
paginated
|
|
9
9
|
} from "../chunk-TCAMLNUZ.js";
|
|
10
10
|
import "../chunk-ETRUVZTJ.js";
|
|
11
|
-
import "../chunk-
|
|
11
|
+
import "../chunk-D3DDJWUD.js";
|
|
12
12
|
export {
|
|
13
13
|
ResponseInterceptor,
|
|
14
14
|
buildPageMeta,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type OnApplicationShutdown, type OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { type LockStore } from './lock-store.port.js';
|
|
3
|
+
import { type SchedulingOptions } from './scheduling.options.js';
|
|
4
|
+
export interface RunLockedOptions {
|
|
5
|
+
/** Random wait `[0, jitterMs)` before asking for the lock. */
|
|
6
|
+
jitterMs?: number;
|
|
7
|
+
/** Hold the lock at least this long from the start of the run. */
|
|
8
|
+
toleranceMs?: number;
|
|
9
|
+
}
|
|
10
|
+
/** What `@CronUnico` talks to. Set by `CronLockService` on boot. */
|
|
11
|
+
export interface CronRunner {
|
|
12
|
+
runLocked(name: string, job: () => unknown, opts?: RunLockedOptions): Promise<boolean>;
|
|
13
|
+
}
|
|
14
|
+
export declare function setCronRunner(runner: CronRunner | null): void;
|
|
15
|
+
export declare function getCronRunner(): CronRunner | null;
|
|
16
|
+
/**
|
|
17
|
+
* Runs a job only if this instance wins the lock for `name`. This is what
|
|
18
|
+
* `@CronUnico` calls, and it is usable directly (queues, bootstraps…).
|
|
19
|
+
*
|
|
20
|
+
* - A run still going in THIS instance makes the next tick skip.
|
|
21
|
+
* - The lease renews while the job runs and is trimmed to the tolerance after.
|
|
22
|
+
* - An error in the job is re-thrown after the lock is settled.
|
|
23
|
+
*/
|
|
24
|
+
export declare class CronLockService implements CronRunner, OnModuleInit, OnApplicationShutdown {
|
|
25
|
+
private readonly store;
|
|
26
|
+
private readonly options;
|
|
27
|
+
private readonly log;
|
|
28
|
+
private readonly running;
|
|
29
|
+
readonly instanceId: string;
|
|
30
|
+
constructor(store: LockStore, options: SchedulingOptions);
|
|
31
|
+
onModuleInit(): void;
|
|
32
|
+
onApplicationShutdown(): void;
|
|
33
|
+
/** `true` if the job ran in this instance. */
|
|
34
|
+
runLocked(name: string, job: () => unknown, opts?: RunLockedOptions): Promise<boolean>;
|
|
35
|
+
private sleep;
|
|
36
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type CronOptions } from '@nestjs/schedule';
|
|
2
|
+
export interface CronUnicoOptions {
|
|
3
|
+
/** Stable name of the cron (the lock key). Unique across the whole app. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Random wait before asking for the lock, `[0, jitterMs)`, so crons that share `:00` do not pile up. */
|
|
6
|
+
jitterMs?: number;
|
|
7
|
+
/** Hold the lock this long from the start even if the run ends sooner. Keep it below the period. */
|
|
8
|
+
toleranceMs?: number;
|
|
9
|
+
/** Options forwarded to `@nestjs/schedule` (`timeZone`, …). */
|
|
10
|
+
cron?: CronOptions;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* `@Cron(expression)` plus a lock across instances: with N replicas only the
|
|
14
|
+
* one that wins the lock for `name` runs the job on each tick.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* @CronUnico('0 3 * * *', { name: 'purge-sessions', jitterMs: 5_000 })
|
|
18
|
+
* async purge() { ... }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* The original method is untouched — calling it directly (an endpoint, a
|
|
22
|
+
* spec) skips the lock. The scheduler is wired to a sibling method
|
|
23
|
+
* (`__cronUnico_<method>`) that goes through the lock. Needs
|
|
24
|
+
* `ScheduleModule.forRoot()` and `SchedulingModule` in the app; without the
|
|
25
|
+
* latter it behaves as a plain `@Cron` and says so once.
|
|
26
|
+
*/
|
|
27
|
+
export declare function CronUnico(expression: string, options: CronUnicoOptions): MethodDecorator;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { LockStore } from './lock-store.port.js';
|
|
2
|
+
export type LockOperation = 'tryAcquire' | 'extend' | 'release';
|
|
3
|
+
export interface FallbackLockStoreOptions {
|
|
4
|
+
/** Called with the error and failing operation; throttled to once a minute per operation. */
|
|
5
|
+
onFail?: (error: unknown, operation: LockOperation) => void;
|
|
6
|
+
/**
|
|
7
|
+
* What a failed `tryAcquire` means. `'memory'` (default): take a per-instance
|
|
8
|
+
* lock so the cron still runs — with N instances it may run N times while the
|
|
9
|
+
* store is down. `'skip'`: do not run (better a missed run than a duplicate).
|
|
10
|
+
*/
|
|
11
|
+
onStoreDown?: 'memory' | 'skip';
|
|
12
|
+
/** Local lock used while the primary is down. */
|
|
13
|
+
fallback?: LockStore;
|
|
14
|
+
now?: () => number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Wraps a shared store and degrades safely: when it throws, the operation
|
|
18
|
+
* moves to process memory (or is skipped) and `onFail` is told. It remembers
|
|
19
|
+
* which backend granted each lock so `extend`/`release` go to the same one.
|
|
20
|
+
*/
|
|
21
|
+
export declare class FallbackLockStore implements LockStore {
|
|
22
|
+
private readonly primary;
|
|
23
|
+
private readonly fallback;
|
|
24
|
+
private readonly onFail?;
|
|
25
|
+
private readonly mode;
|
|
26
|
+
private readonly now;
|
|
27
|
+
private readonly granted;
|
|
28
|
+
private readonly lastWarn;
|
|
29
|
+
constructor(primary: LockStore, options?: FallbackLockStoreOptions);
|
|
30
|
+
tryAcquire(key: string, token: string, ttlMs: number): Promise<boolean>;
|
|
31
|
+
extend(key: string, token: string, ttlMs: number): Promise<boolean>;
|
|
32
|
+
release(key: string, token: string): Promise<boolean>;
|
|
33
|
+
private warn;
|
|
34
|
+
}
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkLRX7AMSScjs = require('../chunk-LRX7AMSS.cjs');
|
|
5
|
+
|
|
6
|
+
// src/scheduling/lock-store.port.ts
|
|
7
|
+
var LOCK_STORE = /* @__PURE__ */ Symbol("LOCK_STORE");
|
|
8
|
+
|
|
9
|
+
// src/scheduling/memory.store.ts
|
|
10
|
+
var MemoryLockStore = class {
|
|
11
|
+
constructor(now = Date.now) {
|
|
12
|
+
this.now = now;
|
|
13
|
+
this.locks = /* @__PURE__ */ new Map();
|
|
14
|
+
}
|
|
15
|
+
async tryAcquire(key, token, ttlMs) {
|
|
16
|
+
const current = this.locks.get(key);
|
|
17
|
+
if (current && current.until > this.now()) return false;
|
|
18
|
+
this.locks.set(key, { token, until: this.now() + ttlMs });
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
async extend(key, token, ttlMs) {
|
|
22
|
+
const current = this.locks.get(key);
|
|
23
|
+
if (!current || current.token !== token || current.until <= this.now()) return false;
|
|
24
|
+
current.until = this.now() + ttlMs;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
async release(key, token) {
|
|
28
|
+
const current = this.locks.get(key);
|
|
29
|
+
if (!current || current.token !== token) return false;
|
|
30
|
+
this.locks.delete(key);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/scheduling/redis.store.ts
|
|
36
|
+
var RELEASE_IF_OWNER = `if redis.call('GET', KEYS[1]) == ARGV[1] then return redis.call('DEL', KEYS[1]) else return 0 end`;
|
|
37
|
+
var EXTEND_IF_OWNER = `if redis.call('GET', KEYS[1]) == ARGV[1] then return redis.call('PEXPIRE', KEYS[1], ARGV[2]) else return 0 end`;
|
|
38
|
+
var RedisLockStore = class {
|
|
39
|
+
constructor(client, prefix = "nestkit:lock:") {
|
|
40
|
+
this.client = client;
|
|
41
|
+
this.prefix = prefix;
|
|
42
|
+
}
|
|
43
|
+
async tryAcquire(key, token, ttlMs) {
|
|
44
|
+
const reply = await this.client.set(this.prefix + key, token, "PX", Math.ceil(ttlMs), "NX");
|
|
45
|
+
return reply === "OK";
|
|
46
|
+
}
|
|
47
|
+
async extend(key, token, ttlMs) {
|
|
48
|
+
const reply = await this.client.eval(
|
|
49
|
+
EXTEND_IF_OWNER,
|
|
50
|
+
1,
|
|
51
|
+
this.prefix + key,
|
|
52
|
+
token,
|
|
53
|
+
Math.ceil(ttlMs)
|
|
54
|
+
);
|
|
55
|
+
return Number(reply) === 1;
|
|
56
|
+
}
|
|
57
|
+
async release(key, token) {
|
|
58
|
+
const reply = await this.client.eval(RELEASE_IF_OWNER, 1, this.prefix + key, token);
|
|
59
|
+
return Number(reply) === 1;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/scheduling/sql.store.ts
|
|
64
|
+
var IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?$/;
|
|
65
|
+
function checkTable(table) {
|
|
66
|
+
if (!IDENTIFIER.test(table)) throw new Error(`SqlLockStore: invalid table name "${table}"`);
|
|
67
|
+
return table;
|
|
68
|
+
}
|
|
69
|
+
var SqlLockStore = class _SqlLockStore {
|
|
70
|
+
constructor(query, options = {}) {
|
|
71
|
+
this.query = query;
|
|
72
|
+
this.table = checkTable(_nullishCoalesce(options.table, () => ( "cron_lock")));
|
|
73
|
+
}
|
|
74
|
+
static createTableSql(table = "cron_lock") {
|
|
75
|
+
return `CREATE TABLE IF NOT EXISTS ${checkTable(table)} (
|
|
76
|
+
name text PRIMARY KEY,
|
|
77
|
+
owner text NOT NULL,
|
|
78
|
+
until timestamptz NOT NULL,
|
|
79
|
+
acquired_at timestamptz NOT NULL DEFAULT now()
|
|
80
|
+
)`;
|
|
81
|
+
}
|
|
82
|
+
async ensureTable() {
|
|
83
|
+
await this.query(_SqlLockStore.createTableSql(this.table), []);
|
|
84
|
+
}
|
|
85
|
+
async tryAcquire(key, token, ttlMs) {
|
|
86
|
+
const rows = await this.query(
|
|
87
|
+
`INSERT INTO ${this.table} (name, owner, until, acquired_at)
|
|
88
|
+
VALUES ($1, $2, now() + make_interval(secs => $3::double precision / 1000), now())
|
|
89
|
+
ON CONFLICT (name) DO UPDATE
|
|
90
|
+
SET owner = EXCLUDED.owner, until = EXCLUDED.until, acquired_at = EXCLUDED.acquired_at
|
|
91
|
+
WHERE ${this.table}.until <= now()
|
|
92
|
+
RETURNING owner`,
|
|
93
|
+
[key, token, ttlMs]
|
|
94
|
+
);
|
|
95
|
+
return Array.isArray(rows) && rows.length > 0;
|
|
96
|
+
}
|
|
97
|
+
async extend(key, token, ttlMs) {
|
|
98
|
+
const rows = await this.query(
|
|
99
|
+
`UPDATE ${this.table} SET until = now() + make_interval(secs => $3::double precision / 1000)
|
|
100
|
+
WHERE name = $1 AND owner = $2 AND until > now() RETURNING owner`,
|
|
101
|
+
[key, token, ttlMs]
|
|
102
|
+
);
|
|
103
|
+
return affected(rows);
|
|
104
|
+
}
|
|
105
|
+
async release(key, token) {
|
|
106
|
+
const rows = await this.query(
|
|
107
|
+
`DELETE FROM ${this.table} WHERE name = $1 AND owner = $2 RETURNING owner`,
|
|
108
|
+
[key, token]
|
|
109
|
+
);
|
|
110
|
+
return affected(rows);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
function affected(result) {
|
|
114
|
+
if (Array.isArray(result)) {
|
|
115
|
+
if (result.length === 2 && Array.isArray(result[0])) return result[0].length > 0;
|
|
116
|
+
return result.length > 0;
|
|
117
|
+
}
|
|
118
|
+
const count = _optionalChain([result, 'optionalAccess', _ => _.rowCount]);
|
|
119
|
+
return typeof count === "number" && count > 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/scheduling/fallback.store.ts
|
|
123
|
+
var FallbackLockStore = class {
|
|
124
|
+
constructor(primary, options = {}) {
|
|
125
|
+
this.primary = primary;
|
|
126
|
+
this.granted = /* @__PURE__ */ new Map();
|
|
127
|
+
this.lastWarn = /* @__PURE__ */ new Map();
|
|
128
|
+
this.now = _nullishCoalesce(options.now, () => ( Date.now));
|
|
129
|
+
this.fallback = _nullishCoalesce(options.fallback, () => ( new MemoryLockStore(this.now)));
|
|
130
|
+
this.onFail = options.onFail;
|
|
131
|
+
this.mode = _nullishCoalesce(options.onStoreDown, () => ( "memory"));
|
|
132
|
+
}
|
|
133
|
+
async tryAcquire(key, token, ttlMs) {
|
|
134
|
+
try {
|
|
135
|
+
const ok = await this.primary.tryAcquire(key, token, ttlMs);
|
|
136
|
+
if (ok) this.granted.set(`${key}\0${token}`, "primary");
|
|
137
|
+
return ok;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
this.warn(error, "tryAcquire");
|
|
140
|
+
if (this.mode === "skip") return false;
|
|
141
|
+
const ok = await this.fallback.tryAcquire(key, token, ttlMs);
|
|
142
|
+
if (ok) this.granted.set(`${key}\0${token}`, "fallback");
|
|
143
|
+
return ok;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async extend(key, token, ttlMs) {
|
|
147
|
+
if (this.granted.get(`${key}\0${token}`) === "fallback") {
|
|
148
|
+
return this.fallback.extend(key, token, ttlMs);
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
return await this.primary.extend(key, token, ttlMs);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
this.warn(error, "extend");
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async release(key, token) {
|
|
158
|
+
const id = `${key}\0${token}`;
|
|
159
|
+
const where = this.granted.get(id);
|
|
160
|
+
this.granted.delete(id);
|
|
161
|
+
if (where === "fallback") return this.fallback.release(key, token);
|
|
162
|
+
try {
|
|
163
|
+
return await this.primary.release(key, token);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
this.warn(error, "release");
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
warn(error, operation) {
|
|
170
|
+
const now = this.now();
|
|
171
|
+
if ((_nullishCoalesce(this.lastWarn.get(operation), () => ( 0))) > now - 6e4) return;
|
|
172
|
+
this.lastWarn.set(operation, now);
|
|
173
|
+
try {
|
|
174
|
+
_optionalChain([this, 'access', _2 => _2.onFail, 'optionalCall', _3 => _3(error, operation)]);
|
|
175
|
+
} catch (e2) {
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// src/scheduling/scheduling.options.ts
|
|
181
|
+
var SCHEDULING_OPTIONS = /* @__PURE__ */ Symbol("SCHEDULING_OPTIONS");
|
|
182
|
+
|
|
183
|
+
// src/scheduling/cron-lock.service.ts
|
|
184
|
+
var _crypto = require('crypto');
|
|
185
|
+
var _os = require('os');
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
var _common = require('@nestjs/common');
|
|
191
|
+
var currentRunner = null;
|
|
192
|
+
function setCronRunner(runner) {
|
|
193
|
+
currentRunner = runner;
|
|
194
|
+
}
|
|
195
|
+
function getCronRunner() {
|
|
196
|
+
return currentRunner;
|
|
197
|
+
}
|
|
198
|
+
var CronLockService = class {
|
|
199
|
+
constructor(store, options) {
|
|
200
|
+
this.store = store;
|
|
201
|
+
this.options = options;
|
|
202
|
+
this.log = new (0, _common.Logger)("CronLock");
|
|
203
|
+
this.running = /* @__PURE__ */ new Set();
|
|
204
|
+
this.instanceId = _nullishCoalesce(options.instanceId, () => ( `${_os.hostname.call(void 0, )}:${process.pid}:${_crypto.randomUUID.call(void 0, ).slice(0, 8)}`));
|
|
205
|
+
}
|
|
206
|
+
onModuleInit() {
|
|
207
|
+
setCronRunner(this);
|
|
208
|
+
}
|
|
209
|
+
onApplicationShutdown() {
|
|
210
|
+
if (getCronRunner() === this) setCronRunner(null);
|
|
211
|
+
}
|
|
212
|
+
/** `true` if the job ran in this instance. */
|
|
213
|
+
async runLocked(name, job, opts = {}) {
|
|
214
|
+
if (this.running.has(name)) {
|
|
215
|
+
this.log.warn(`"${name}": previous run still going in this instance; skipping`);
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
this.running.add(name);
|
|
219
|
+
try {
|
|
220
|
+
const jitter = Math.max(0, _nullishCoalesce(_nullishCoalesce(opts.jitterMs, () => ( this.options.jitterMs)), () => ( 0)));
|
|
221
|
+
if (jitter > 0) await this.sleep(Math.floor((_nullishCoalesce(this.options.random, () => ( Math.random)))() * jitter));
|
|
222
|
+
const tolerance = Math.max(
|
|
223
|
+
0,
|
|
224
|
+
_nullishCoalesce(_nullishCoalesce(opts.toleranceMs, () => ( this.options.toleranceMs)), () => ( jitter + 1e4))
|
|
225
|
+
);
|
|
226
|
+
const lease = Math.max(_nullishCoalesce(this.options.ttlMs, () => ( 12e4)), tolerance);
|
|
227
|
+
const token = `${this.instanceId}:${_crypto.randomUUID.call(void 0, )}`;
|
|
228
|
+
if (!await this.store.tryAcquire(name, token, lease)) return false;
|
|
229
|
+
const renew = setInterval(
|
|
230
|
+
() => void this.store.extend(name, token, lease).catch(() => void 0),
|
|
231
|
+
Math.max(1, Math.floor(lease / 3))
|
|
232
|
+
);
|
|
233
|
+
_optionalChain([renew, 'access', _4 => _4.unref, 'optionalCall', _5 => _5()]);
|
|
234
|
+
const started = Date.now();
|
|
235
|
+
try {
|
|
236
|
+
await job();
|
|
237
|
+
} finally {
|
|
238
|
+
clearInterval(renew);
|
|
239
|
+
const remaining = tolerance - (Date.now() - started);
|
|
240
|
+
await (remaining > 0 ? this.store.extend(name, token, remaining) : this.store.release(name, token)).catch(
|
|
241
|
+
(e) => this.log.warn(`"${name}": lock not settled (${String(e)}); it expires by itself`)
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
return true;
|
|
245
|
+
} finally {
|
|
246
|
+
this.running.delete(name);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
sleep(ms) {
|
|
250
|
+
return this.options.sleep ? this.options.sleep(ms) : new Promise((r) => setTimeout(r, ms));
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
CronLockService = exports.CronLockService = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
254
|
+
_common.Injectable.call(void 0, ),
|
|
255
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, LOCK_STORE)),
|
|
256
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Inject.call(void 0, SCHEDULING_OPTIONS))
|
|
257
|
+
], CronLockService);
|
|
258
|
+
|
|
259
|
+
// src/scheduling/cron-unico.decorator.ts
|
|
260
|
+
|
|
261
|
+
var _schedule = require('@nestjs/schedule');
|
|
262
|
+
var log = new (0, _common.Logger)("CronUnico");
|
|
263
|
+
var warnedNoRunner = false;
|
|
264
|
+
function CronUnico(expression, options) {
|
|
265
|
+
return (target, key) => {
|
|
266
|
+
const sibling = `__cronUnico_${String(key)}`;
|
|
267
|
+
async function wrapper(...args) {
|
|
268
|
+
const original = () => this[key].apply(this, args);
|
|
269
|
+
const runner = getCronRunner();
|
|
270
|
+
if (!runner) {
|
|
271
|
+
if (!warnedNoRunner) {
|
|
272
|
+
warnedNoRunner = true;
|
|
273
|
+
log.warn("SchedulingModule not registered: crons run without coordination");
|
|
274
|
+
}
|
|
275
|
+
await original();
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
await runner.runLocked(options.name, original, {
|
|
279
|
+
jitterMs: options.jitterMs,
|
|
280
|
+
toleranceMs: options.toleranceMs
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
Object.defineProperty(target, sibling, {
|
|
284
|
+
value: wrapper,
|
|
285
|
+
writable: true,
|
|
286
|
+
configurable: true,
|
|
287
|
+
enumerable: false
|
|
288
|
+
});
|
|
289
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, sibling);
|
|
290
|
+
_schedule.Cron.call(void 0, expression, _nullishCoalesce(options.cron, () => ( {})))(target, sibling, descriptor);
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/scheduling/scheduling.module.ts
|
|
295
|
+
|
|
296
|
+
function resolveStore(options) {
|
|
297
|
+
if (!options.store) return new MemoryLockStore();
|
|
298
|
+
return new FallbackLockStore(options.store, {
|
|
299
|
+
onFail: options.onFail,
|
|
300
|
+
onStoreDown: options.onStoreDown
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
var SchedulingModule = class {
|
|
304
|
+
static forRoot(options = {}) {
|
|
305
|
+
const providers = [
|
|
306
|
+
{ provide: SCHEDULING_OPTIONS, useValue: options },
|
|
307
|
+
{ provide: LOCK_STORE, useFactory: () => resolveStore(options) },
|
|
308
|
+
CronLockService
|
|
309
|
+
];
|
|
310
|
+
return {
|
|
311
|
+
module: SchedulingModule,
|
|
312
|
+
providers,
|
|
313
|
+
exports: [LOCK_STORE, SCHEDULING_OPTIONS, CronLockService]
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
static forRootAsync(config) {
|
|
317
|
+
const providers = [
|
|
318
|
+
{ provide: SCHEDULING_OPTIONS, useFactory: config.useFactory, inject: _nullishCoalesce(config.inject, () => ( [])) },
|
|
319
|
+
{
|
|
320
|
+
provide: LOCK_STORE,
|
|
321
|
+
useFactory: (options) => resolveStore(options),
|
|
322
|
+
inject: [SCHEDULING_OPTIONS]
|
|
323
|
+
},
|
|
324
|
+
CronLockService
|
|
325
|
+
];
|
|
326
|
+
return {
|
|
327
|
+
module: SchedulingModule,
|
|
328
|
+
imports: _nullishCoalesce(config.imports, () => ( [])),
|
|
329
|
+
providers,
|
|
330
|
+
exports: [LOCK_STORE, SCHEDULING_OPTIONS, CronLockService]
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
SchedulingModule = exports.SchedulingModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
335
|
+
_common.Global.call(void 0, ),
|
|
336
|
+
_common.Module.call(void 0, {})
|
|
337
|
+
], SchedulingModule);
|
|
338
|
+
|
|
339
|
+
// src/scheduling/redis.module.ts
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
var REDIS_CLIENT = /* @__PURE__ */ Symbol("REDIS_CLIENT");
|
|
347
|
+
var RedisCloser = class {
|
|
348
|
+
constructor(client) {
|
|
349
|
+
this.client = client;
|
|
350
|
+
}
|
|
351
|
+
async onApplicationShutdown() {
|
|
352
|
+
if (!this.client) return;
|
|
353
|
+
try {
|
|
354
|
+
if (this.client.quit) await this.client.quit();
|
|
355
|
+
else _optionalChain([this, 'access', _6 => _6.client, 'access', _7 => _7.disconnect, 'optionalCall', _8 => _8()]);
|
|
356
|
+
} catch (e3) {
|
|
357
|
+
_optionalChain([this, 'access', _9 => _9.client, 'access', _10 => _10.disconnect, 'optionalCall', _11 => _11()]);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
RedisCloser = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
362
|
+
_common.Injectable.call(void 0, ),
|
|
363
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, REDIS_CLIENT))
|
|
364
|
+
], RedisCloser);
|
|
365
|
+
var RedisModule = class {
|
|
366
|
+
static forRoot(options) {
|
|
367
|
+
return {
|
|
368
|
+
module: RedisModule,
|
|
369
|
+
providers: [{ provide: REDIS_CLIENT, useFactory: options.create }, RedisCloser],
|
|
370
|
+
exports: [REDIS_CLIENT]
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
RedisModule = exports.RedisModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
375
|
+
_common.Global.call(void 0, ),
|
|
376
|
+
_common.Module.call(void 0, {})
|
|
377
|
+
], RedisModule);
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
exports.CronLockService = CronLockService; exports.CronUnico = CronUnico; exports.FallbackLockStore = FallbackLockStore; exports.LOCK_STORE = LOCK_STORE; exports.MemoryLockStore = MemoryLockStore; exports.REDIS_CLIENT = REDIS_CLIENT; exports.RedisLockStore = RedisLockStore; exports.RedisModule = RedisModule; exports.SCHEDULING_OPTIONS = SCHEDULING_OPTIONS; exports.SchedulingModule = SchedulingModule; exports.SqlLockStore = SqlLockStore; exports.getCronRunner = getCronRunner; exports.setCronRunner = setCronRunner;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { LOCK_STORE } from './lock-store.port.js';
|
|
2
|
+
export type { LockStore } from './lock-store.port.js';
|
|
3
|
+
export { MemoryLockStore } from './memory.store.js';
|
|
4
|
+
export { RedisLockStore } from './redis.store.js';
|
|
5
|
+
export type { RedisLockClient } from './redis.store.js';
|
|
6
|
+
export { SqlLockStore } from './sql.store.js';
|
|
7
|
+
export type { SqlQuery, SqlLockStoreOptions } from './sql.store.js';
|
|
8
|
+
export { FallbackLockStore } from './fallback.store.js';
|
|
9
|
+
export type { FallbackLockStoreOptions, LockOperation } from './fallback.store.js';
|
|
10
|
+
export { SCHEDULING_OPTIONS } from './scheduling.options.js';
|
|
11
|
+
export type { SchedulingOptions } from './scheduling.options.js';
|
|
12
|
+
export { CronLockService, setCronRunner, getCronRunner } from './cron-lock.service.js';
|
|
13
|
+
export type { CronRunner, RunLockedOptions } from './cron-lock.service.js';
|
|
14
|
+
export { CronUnico } from './cron-unico.decorator.js';
|
|
15
|
+
export type { CronUnicoOptions } from './cron-unico.decorator.js';
|
|
16
|
+
export { SchedulingModule } from './scheduling.module.js';
|
|
17
|
+
export { RedisModule, REDIS_CLIENT } from './redis.module.js';
|
|
18
|
+
export type { RedisModuleOptions, ClosableRedis } from './redis.module.js';
|