@redmix/api 9.0.0-canary.581 → 9.0.0-canary.583
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.js +10 -49
- package/dist/auth/parseJWT.js +3 -26
- package/dist/auth/verifiers/base64Sha1Verifier.js +18 -37
- package/dist/auth/verifiers/base64Sha256Verifier.js +18 -37
- package/dist/auth/verifiers/common.js +19 -58
- package/dist/auth/verifiers/index.js +8 -33
- package/dist/auth/verifiers/jwtVerifier.js +17 -47
- package/dist/auth/verifiers/secretKeyVerifier.js +7 -26
- package/dist/auth/verifiers/sha1Verifier.js +18 -37
- package/dist/auth/verifiers/sha256Verifier.js +18 -37
- package/dist/auth/verifiers/skipVerifier.js +4 -23
- package/dist/auth/verifiers/timestampSchemeVerifier.js +18 -33
- package/dist/cache/clients/BaseClient.js +4 -23
- package/dist/cache/clients/InMemoryClient.js +6 -35
- package/dist/cache/clients/MemcachedClient.js +6 -35
- package/dist/cache/clients/RedisClient.js +6 -35
- package/dist/cache/errors.js +3 -26
- package/dist/cache/index.js +14 -52
- package/dist/cjs/auth/index.d.ts +51 -0
- package/dist/cjs/auth/index.d.ts.map +1 -0
- package/dist/cjs/auth/index.js +129 -0
- package/dist/cjs/auth/parseJWT.d.ts +6 -0
- package/dist/cjs/auth/parseJWT.d.ts.map +1 -0
- package/dist/cjs/auth/parseJWT.js +57 -0
- package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts +19 -0
- package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/base64Sha1Verifier.js +77 -0
- package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts +19 -0
- package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/base64Sha256Verifier.js +77 -0
- package/dist/cjs/auth/verifiers/common.d.ts +104 -0
- package/dist/cjs/auth/verifiers/common.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/common.js +99 -0
- package/dist/cjs/auth/verifiers/index.d.ts +8 -0
- package/dist/cjs/auth/verifiers/index.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/index.js +38 -0
- package/dist/cjs/auth/verifiers/jwtVerifier.d.ts +26 -0
- package/dist/cjs/auth/verifiers/jwtVerifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/jwtVerifier.js +86 -0
- package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts +14 -0
- package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/secretKeyVerifier.js +40 -0
- package/dist/cjs/auth/verifiers/sha1Verifier.d.ts +25 -0
- package/dist/cjs/auth/verifiers/sha1Verifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/sha1Verifier.js +85 -0
- package/dist/cjs/auth/verifiers/sha256Verifier.d.ts +25 -0
- package/dist/cjs/auth/verifiers/sha256Verifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/sha256Verifier.js +85 -0
- package/dist/cjs/auth/verifiers/skipVerifier.d.ts +13 -0
- package/dist/cjs/auth/verifiers/skipVerifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/skipVerifier.js +37 -0
- package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts +16 -0
- package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/timestampSchemeVerifier.js +81 -0
- package/dist/cjs/bins/redwood.d.ts +9 -0
- package/dist/cjs/bins/redwood.d.ts.map +1 -0
- package/dist/cjs/bins/rwfw.d.ts +3 -0
- package/dist/cjs/bins/rwfw.d.ts.map +1 -0
- package/dist/cjs/bins/tsc.d.ts +3 -0
- package/dist/cjs/bins/tsc.d.ts.map +1 -0
- package/dist/{bins → cjs/bins}/tsc.js +2 -2
- package/dist/cjs/cache/clients/BaseClient.d.ts +11 -0
- package/dist/cjs/cache/clients/BaseClient.d.ts.map +1 -0
- package/dist/cjs/cache/clients/BaseClient.js +27 -0
- package/dist/cjs/cache/clients/InMemoryClient.d.ts +31 -0
- package/dist/cjs/cache/clients/InMemoryClient.d.ts.map +1 -0
- package/dist/cjs/cache/clients/InMemoryClient.js +100 -0
- package/dist/cjs/cache/clients/MemcachedClient.d.ts +16 -0
- package/dist/cjs/cache/clients/MemcachedClient.d.ts.map +1 -0
- package/dist/cjs/cache/clients/MemcachedClient.js +75 -0
- package/dist/cjs/cache/clients/RedisClient.d.ts +20 -0
- package/dist/cjs/cache/clients/RedisClient.d.ts.map +1 -0
- package/dist/cjs/cache/clients/RedisClient.js +79 -0
- package/dist/cjs/cache/errors.d.ts +4 -0
- package/dist/cjs/cache/errors.d.ts.map +1 -0
- package/dist/cjs/cache/errors.js +33 -0
- package/dist/cjs/cache/index.d.ts +35 -0
- package/dist/cjs/cache/index.d.ts.map +1 -0
- package/dist/cjs/cache/index.js +171 -0
- package/dist/cjs/cors.d.ts +16 -0
- package/dist/cjs/cors.d.ts.map +1 -0
- package/dist/cjs/cors.js +93 -0
- package/dist/cjs/errors.d.ts +5 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +38 -0
- package/dist/cjs/event.d.ts +3 -0
- package/dist/cjs/event.d.ts.map +1 -0
- package/dist/cjs/event.js +34 -0
- package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts +4 -0
- package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts.map +1 -0
- package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.js +72 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +63 -0
- package/dist/cjs/logger/index.d.ts +179 -0
- package/dist/cjs/logger/index.d.ts.map +1 -0
- package/dist/cjs/logger/index.js +195 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/transforms.d.ts +35 -0
- package/dist/cjs/transforms.d.ts.map +1 -0
- package/dist/cjs/transforms.js +98 -0
- package/dist/cjs/types.d.ts +25 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +16 -0
- package/dist/cjs/validations/errors.d.ts +101 -0
- package/dist/cjs/validations/errors.d.ts.map +1 -0
- package/dist/cjs/validations/errors.js +298 -0
- package/dist/cjs/validations/validations.d.ts +222 -0
- package/dist/cjs/validations/validations.d.ts.map +1 -0
- package/dist/cjs/validations/validations.js +351 -0
- package/dist/cjs/webhooks/index.d.ts +76 -0
- package/dist/cjs/webhooks/index.d.ts.map +1 -0
- package/dist/cjs/webhooks/index.js +107 -0
- package/dist/cors.js +7 -30
- package/dist/errors.js +3 -26
- package/dist/event.js +5 -28
- package/dist/functions/fixtures/apiGatewayProxyEvent.fixture.js +4 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -46
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +6 -48
- package/dist/package.json +1 -0
- package/dist/transforms.js +6 -33
- package/dist/types.js +1 -16
- package/dist/validations/errors.js +8 -66
- package/dist/validations/validations.js +8 -44
- package/dist/webhooks/index.js +25 -46
- package/package.json +53 -18
- /package/dist/{bins → cjs/bins}/redwood.js +0 -0
- /package/dist/{bins → cjs/bins}/rwfw.js +0 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
export default abstract class BaseClient {
|
2
|
+
constructor();
|
3
|
+
disconnect?(): void | Promise<void>;
|
4
|
+
abstract connect(): void | Promise<void>;
|
5
|
+
abstract get(key: string): any;
|
6
|
+
abstract set(key: string, value: unknown, options: {
|
7
|
+
expires?: number;
|
8
|
+
}): Promise<any> | any;
|
9
|
+
abstract del(key: string): Promise<boolean> | any;
|
10
|
+
}
|
11
|
+
//# sourceMappingURL=BaseClient.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../../../../src/cache/clients/BaseClient.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,UAAU;;IAKtC,UAAU,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAEnC,QAAQ,CAAC,OAAO,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAGxC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG;IAG9B,QAAQ,CAAC,GAAG,CACV,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,EACd,OAAO,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAC5B,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG;IAGrB,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,GAAG;CAClD"}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var BaseClient_exports = {};
|
20
|
+
__export(BaseClient_exports, {
|
21
|
+
default: () => BaseClient
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(BaseClient_exports);
|
24
|
+
class BaseClient {
|
25
|
+
constructor() {
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import BaseClient from './BaseClient.js';
|
2
|
+
type CacheOptions = {
|
3
|
+
expires?: number;
|
4
|
+
};
|
5
|
+
export default class InMemoryClient extends BaseClient {
|
6
|
+
storage: Record<string, {
|
7
|
+
expires: number;
|
8
|
+
value: string;
|
9
|
+
}>;
|
10
|
+
constructor(data?: {});
|
11
|
+
/**
|
12
|
+
* Special function for testing, only available in InMemoryClient
|
13
|
+
*
|
14
|
+
* Returns deserialized content of cache as an array of values (without cache keys)
|
15
|
+
*
|
16
|
+
*/
|
17
|
+
get contents(): any[];
|
18
|
+
disconnect(): Promise<void>;
|
19
|
+
connect(): Promise<void>;
|
20
|
+
get(key: string): Promise<any>;
|
21
|
+
set(key: string, value: unknown, options?: CacheOptions): Promise<boolean>;
|
22
|
+
del(key: string): Promise<boolean>;
|
23
|
+
/**
|
24
|
+
* Special functions for testing, only available in InMemoryClient
|
25
|
+
*/
|
26
|
+
clear(): Promise<void>;
|
27
|
+
cacheKeyForValue(value: any): string | null;
|
28
|
+
isCached(value: any): boolean;
|
29
|
+
}
|
30
|
+
export {};
|
31
|
+
//# sourceMappingURL=InMemoryClient.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"InMemoryClient.d.ts","sourceRoot":"","sources":["../../../../src/cache/clients/InMemoryClient.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,iBAAiB,CAAA;AAExC,KAAK,YAAY,GAAG;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,UAAU;IACpD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;gBAG/C,IAAI,KAAK;IAKrB;;;;;OAKG;IACH,IAAI,QAAQ,UAIX;IAGK,UAAU;IACV,OAAO;IAEP,GAAG,CAAC,GAAG,EAAE,MAAM;IAWf,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,YAAiB;IAU3D,GAAG,CAAC,GAAG,EAAE,MAAM;IASrB;;OAEG;IACG,KAAK;IAIX,gBAAgB,CAAC,KAAK,EAAE,GAAG;IAU3B,QAAQ,CAAC,KAAK,EAAE,GAAG;CAGpB"}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var InMemoryClient_exports = {};
|
30
|
+
__export(InMemoryClient_exports, {
|
31
|
+
default: () => InMemoryClient
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(InMemoryClient_exports);
|
34
|
+
var import_BaseClient = __toESM(require("./BaseClient.js"), 1);
|
35
|
+
class InMemoryClient extends import_BaseClient.default {
|
36
|
+
storage;
|
37
|
+
// initialize with pre-cached data if needed
|
38
|
+
constructor(data = {}) {
|
39
|
+
super();
|
40
|
+
this.storage = data;
|
41
|
+
}
|
42
|
+
/**
|
43
|
+
* Special function for testing, only available in InMemoryClient
|
44
|
+
*
|
45
|
+
* Returns deserialized content of cache as an array of values (without cache keys)
|
46
|
+
*
|
47
|
+
*/
|
48
|
+
get contents() {
|
49
|
+
return Object.values(this.storage).map(
|
50
|
+
(cacheObj) => JSON.parse(cacheObj.value)
|
51
|
+
);
|
52
|
+
}
|
53
|
+
// Not needed for InMemoryClient
|
54
|
+
async disconnect() {
|
55
|
+
}
|
56
|
+
async connect() {
|
57
|
+
}
|
58
|
+
async get(key) {
|
59
|
+
const now = /* @__PURE__ */ new Date();
|
60
|
+
if (this.storage[key] && this.storage[key].expires > now.getTime()) {
|
61
|
+
return JSON.parse(this.storage[key].value);
|
62
|
+
} else {
|
63
|
+
delete this.storage[key];
|
64
|
+
return null;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
// stores expiration dates as epoch
|
68
|
+
async set(key, value, options = {}) {
|
69
|
+
const now = /* @__PURE__ */ new Date();
|
70
|
+
now.setSeconds(now.getSeconds() + (options?.expires || 31536e4));
|
71
|
+
const data = { expires: now.getTime(), value: JSON.stringify(value) };
|
72
|
+
this.storage[key] = data;
|
73
|
+
return true;
|
74
|
+
}
|
75
|
+
async del(key) {
|
76
|
+
if (this.storage[key]) {
|
77
|
+
delete this.storage[key];
|
78
|
+
return true;
|
79
|
+
} else {
|
80
|
+
return false;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
/**
|
84
|
+
* Special functions for testing, only available in InMemoryClient
|
85
|
+
*/
|
86
|
+
async clear() {
|
87
|
+
this.storage = {};
|
88
|
+
}
|
89
|
+
cacheKeyForValue(value) {
|
90
|
+
for (const [cacheKey, cacheObj] of Object.entries(this.storage)) {
|
91
|
+
if (cacheObj.value === JSON.stringify(value)) {
|
92
|
+
return cacheKey;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
return null;
|
96
|
+
}
|
97
|
+
isCached(value) {
|
98
|
+
return !!this.cacheKeyForValue(value);
|
99
|
+
}
|
100
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { Client as ClientType, ClientOptions, ServerOptions } from 'memjs';
|
2
|
+
import BaseClient from './BaseClient.js';
|
3
|
+
export default class MemcachedClient extends BaseClient {
|
4
|
+
client?: ClientType | null;
|
5
|
+
servers: string;
|
6
|
+
options: (ClientOptions<string | Buffer, Buffer | null> & ServerOptions) | undefined;
|
7
|
+
constructor(servers: string, options?: ClientOptions & ServerOptions);
|
8
|
+
connect(): Promise<void>;
|
9
|
+
disconnect(): Promise<void>;
|
10
|
+
get(key: string): Promise<any>;
|
11
|
+
set(key: string, value: unknown, options: {
|
12
|
+
expires?: number;
|
13
|
+
}): Promise<boolean | undefined>;
|
14
|
+
del(key: string): Promise<boolean | undefined>;
|
15
|
+
}
|
16
|
+
//# sourceMappingURL=MemcachedClient.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"MemcachedClient.d.ts","sourceRoot":"","sources":["../../../../src/cache/clients/MemcachedClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE/E,OAAO,UAAU,MAAM,iBAAiB,CAAA;AAExC,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU;IACrD,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;IAC1B,OAAO,SAAA;IACP,OAAO,8EAAA;gBAEK,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,aAAa;IAM9D,OAAO;IAKP,UAAU;IAKV,GAAG,CAAC,GAAG,EAAE,MAAM;IAcf,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAQ9D,GAAG,CAAC,GAAG,EAAE,MAAM;CAQtB"}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var MemcachedClient_exports = {};
|
30
|
+
__export(MemcachedClient_exports, {
|
31
|
+
default: () => MemcachedClient
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(MemcachedClient_exports);
|
34
|
+
var import_BaseClient = __toESM(require("./BaseClient.js"), 1);
|
35
|
+
class MemcachedClient extends import_BaseClient.default {
|
36
|
+
client;
|
37
|
+
servers;
|
38
|
+
options;
|
39
|
+
constructor(servers, options) {
|
40
|
+
super();
|
41
|
+
this.servers = servers;
|
42
|
+
this.options = options;
|
43
|
+
}
|
44
|
+
async connect() {
|
45
|
+
const { Client: MemCachedClient } = await import("memjs");
|
46
|
+
this.client = MemCachedClient.create(this.servers, this.options);
|
47
|
+
}
|
48
|
+
async disconnect() {
|
49
|
+
this.client?.close();
|
50
|
+
this.client = null;
|
51
|
+
}
|
52
|
+
async get(key) {
|
53
|
+
if (!this.client) {
|
54
|
+
await this.connect();
|
55
|
+
}
|
56
|
+
const result = await this.client?.get(key);
|
57
|
+
if (result?.value) {
|
58
|
+
return JSON.parse(result.value.toString());
|
59
|
+
} else {
|
60
|
+
return result?.value;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
async set(key, value, options) {
|
64
|
+
if (!this.client) {
|
65
|
+
await this.connect();
|
66
|
+
}
|
67
|
+
return this.client?.set(key, JSON.stringify(value), options);
|
68
|
+
}
|
69
|
+
async del(key) {
|
70
|
+
if (!this.client) {
|
71
|
+
await this.connect();
|
72
|
+
}
|
73
|
+
return this.client?.delete(key);
|
74
|
+
}
|
75
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { RedisClientType, RedisClientOptions } from 'redis';
|
2
|
+
import type { Logger } from '../../logger/index.js';
|
3
|
+
import BaseClient from './BaseClient.js';
|
4
|
+
type LoggerOptions = {
|
5
|
+
logger?: Logger;
|
6
|
+
};
|
7
|
+
export default class RedisClient extends BaseClient {
|
8
|
+
client?: RedisClientType | null;
|
9
|
+
logger?: Logger;
|
10
|
+
redisOptions?: RedisClientOptions;
|
11
|
+
constructor(options: RedisClientOptions & LoggerOptions);
|
12
|
+
connect(): Promise<void>;
|
13
|
+
get(key: string): Promise<any>;
|
14
|
+
set(key: string, value: unknown, options: {
|
15
|
+
expires?: number;
|
16
|
+
}): Promise<string | null | undefined>;
|
17
|
+
del(key: string): Promise<boolean>;
|
18
|
+
}
|
19
|
+
export {};
|
20
|
+
//# sourceMappingURL=RedisClient.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"RedisClient.d.ts","sourceRoot":"","sources":["../../../../src/cache/clients/RedisClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAEhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAEnD,OAAO,UAAU,MAAM,iBAAiB,CAAA;AAMxC,KAAK,aAAa,GAAG;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,UAAU;IACjD,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,CAAA;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,kBAAkB,CAAA;gBAErB,OAAO,EAAE,kBAAkB,GAAG,aAAa;IAQjD,OAAO;IAiBP,GAAG,CAAC,GAAG,EAAE,MAAM;IAUf,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAc9D,GAAG,CAAC,GAAG,EAAE,MAAM;CAQtB"}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var RedisClient_exports = {};
|
30
|
+
__export(RedisClient_exports, {
|
31
|
+
default: () => RedisClient
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(RedisClient_exports);
|
34
|
+
var import_BaseClient = __toESM(require("./BaseClient.js"), 1);
|
35
|
+
class RedisClient extends import_BaseClient.default {
|
36
|
+
client;
|
37
|
+
logger;
|
38
|
+
redisOptions;
|
39
|
+
constructor(options) {
|
40
|
+
const { logger, ...redisOptions } = options;
|
41
|
+
super();
|
42
|
+
this.logger = logger;
|
43
|
+
this.redisOptions = redisOptions;
|
44
|
+
}
|
45
|
+
async connect() {
|
46
|
+
const { createClient } = await import("redis");
|
47
|
+
this.client = createClient(this.redisOptions);
|
48
|
+
this.client.on(
|
49
|
+
"error",
|
50
|
+
(err) => this.logger?.error(err) || console.error(err)
|
51
|
+
);
|
52
|
+
await this.client.connect();
|
53
|
+
}
|
54
|
+
// @NOTE: disconnect intentionally not implemented for Redis
|
55
|
+
// Because node-redis recovers gracefully from connection loss
|
56
|
+
async get(key) {
|
57
|
+
if (!this.client) {
|
58
|
+
await this.connect();
|
59
|
+
}
|
60
|
+
const result = await this.client?.get(key);
|
61
|
+
return result ? JSON.parse(result) : null;
|
62
|
+
}
|
63
|
+
async set(key, value, options) {
|
64
|
+
const setOptions = {};
|
65
|
+
if (!this.client) {
|
66
|
+
await this.connect();
|
67
|
+
}
|
68
|
+
if (options.expires) {
|
69
|
+
setOptions.EX = options.expires;
|
70
|
+
}
|
71
|
+
return this.client?.set(key, JSON.stringify(value), setOptions);
|
72
|
+
}
|
73
|
+
async del(key) {
|
74
|
+
if (!this.client) {
|
75
|
+
await this.connect();
|
76
|
+
}
|
77
|
+
return !!await this.client?.del([key]);
|
78
|
+
}
|
79
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/cache/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAkB,SAAQ,KAAK;;CAK3C"}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var errors_exports = {};
|
20
|
+
__export(errors_exports, {
|
21
|
+
CacheTimeoutError: () => CacheTimeoutError
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(errors_exports);
|
24
|
+
class CacheTimeoutError extends Error {
|
25
|
+
constructor() {
|
26
|
+
super("Timed out waiting for response from the cache server");
|
27
|
+
this.name = "CacheTimeoutError";
|
28
|
+
}
|
29
|
+
}
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
31
|
+
0 && (module.exports = {
|
32
|
+
CacheTimeoutError
|
33
|
+
});
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import type { Logger } from '../logger/index.js';
|
2
|
+
import type BaseClient from './clients/BaseClient.js';
|
3
|
+
export { default as MemcachedClient } from './clients/MemcachedClient.js';
|
4
|
+
export { default as RedisClient } from './clients/RedisClient.js';
|
5
|
+
export { default as InMemoryClient } from './clients/InMemoryClient.js';
|
6
|
+
export interface CreateCacheOptions {
|
7
|
+
logger?: Logger;
|
8
|
+
timeout?: number;
|
9
|
+
prefix?: string;
|
10
|
+
fields?: {
|
11
|
+
id: string;
|
12
|
+
updatedAt: string;
|
13
|
+
};
|
14
|
+
}
|
15
|
+
export interface CacheOptions {
|
16
|
+
expires?: number;
|
17
|
+
}
|
18
|
+
export interface CacheFindManyOptions<TFindManyArgs extends Record<string, unknown>> extends CacheOptions {
|
19
|
+
conditions?: TFindManyArgs;
|
20
|
+
}
|
21
|
+
export type CacheKey = string | string[];
|
22
|
+
export type LatestQuery = Record<string, unknown>;
|
23
|
+
type GenericDelegate = {
|
24
|
+
findMany: (...args: any) => any;
|
25
|
+
findFirst: (...args: any) => any;
|
26
|
+
};
|
27
|
+
export declare const cacheKeySeparator = "-";
|
28
|
+
export declare const formatCacheKey: (key: CacheKey, prefix?: string) => string;
|
29
|
+
export declare const createCache: (cacheClient: BaseClient, options?: CreateCacheOptions) => {
|
30
|
+
cache: <TResult>(key: CacheKey, input: () => TResult | Promise<TResult>, options?: CacheOptions) => Promise<any>;
|
31
|
+
cacheFindMany: <TDelegate extends GenericDelegate>(key: CacheKey, model: TDelegate, options?: CacheFindManyOptions<Parameters<TDelegate["findMany"]>[0]>) => Promise<any>;
|
32
|
+
cacheClient: BaseClient;
|
33
|
+
deleteCacheKey: (key: CacheKey) => Promise<any>;
|
34
|
+
};
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,KAAK,UAAU,MAAM,yBAAyB,CAAA;AAGrD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAA;AACzE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAEvE,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE;QACP,EAAE,EAAE,MAAM,CAAA;QACV,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,oBAAoB,CACnC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC7C,SAAQ,YAAY;IACpB,UAAU,CAAC,EAAE,aAAa,CAAA;CAC3B;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;AACxC,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEjD,KAAK,eAAe,GAAG;IACrB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,CAAA;IAC/B,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,CAAA;CACjC,CAAA;AAQD,eAAO,MAAM,iBAAiB,MAAM,CAAA;AAEpC,eAAO,MAAM,cAAc,QAAS,QAAQ,WAAW,MAAM,WAkB5D,CAAA;AAMD,eAAO,MAAM,WAAW,gBACT,UAAU,YACb,kBAAkB;YAQP,OAAO,OACrB,QAAQ,SACN,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,YAC7B,YAAY,KACrB,OAAO,CAAC,GAAG,CAAC;oBAqDc,SAAS,SAAS,eAAe,OACvD,QAAQ,SACN,SAAS,YACP,oBAAoB,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;0BAgDlC,QAAQ;CA0B5C,CAAA"}
|
@@ -0,0 +1,171 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var cache_exports = {};
|
30
|
+
__export(cache_exports, {
|
31
|
+
InMemoryClient: () => import_InMemoryClient.default,
|
32
|
+
MemcachedClient: () => import_MemcachedClient.default,
|
33
|
+
RedisClient: () => import_RedisClient.default,
|
34
|
+
cacheKeySeparator: () => cacheKeySeparator,
|
35
|
+
createCache: () => createCache,
|
36
|
+
formatCacheKey: () => formatCacheKey
|
37
|
+
});
|
38
|
+
module.exports = __toCommonJS(cache_exports);
|
39
|
+
var import_errors = require("./errors.js");
|
40
|
+
var import_MemcachedClient = __toESM(require("./clients/MemcachedClient.js"), 1);
|
41
|
+
var import_RedisClient = __toESM(require("./clients/RedisClient.js"), 1);
|
42
|
+
var import_InMemoryClient = __toESM(require("./clients/InMemoryClient.js"), 1);
|
43
|
+
const DEFAULT_LATEST_FIELDS = { id: "id", updatedAt: "updatedAt" };
|
44
|
+
const wait = (ms) => {
|
45
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
46
|
+
};
|
47
|
+
const cacheKeySeparator = "-";
|
48
|
+
const formatCacheKey = (key, prefix) => {
|
49
|
+
let output;
|
50
|
+
if (Array.isArray(key)) {
|
51
|
+
output = key.join(cacheKeySeparator);
|
52
|
+
} else {
|
53
|
+
output = key;
|
54
|
+
}
|
55
|
+
if (prefix && !output.toString().match(new RegExp("^" + prefix + cacheKeySeparator))) {
|
56
|
+
output = `${prefix}${cacheKeySeparator}${output}`;
|
57
|
+
}
|
58
|
+
return output;
|
59
|
+
};
|
60
|
+
const serialize = (input) => {
|
61
|
+
return JSON.parse(JSON.stringify(input));
|
62
|
+
};
|
63
|
+
const createCache = (cacheClient, options) => {
|
64
|
+
const client = cacheClient;
|
65
|
+
const logger = options?.logger;
|
66
|
+
const timeout = options?.timeout || 1e3;
|
67
|
+
const prefix = options?.prefix;
|
68
|
+
const fields = options?.fields || DEFAULT_LATEST_FIELDS;
|
69
|
+
const cache = async (key, input, options2) => {
|
70
|
+
const cacheKey = formatCacheKey(key, prefix);
|
71
|
+
try {
|
72
|
+
const result = await Promise.race([
|
73
|
+
client.get(cacheKey),
|
74
|
+
wait(timeout).then(() => {
|
75
|
+
throw new import_errors.CacheTimeoutError();
|
76
|
+
})
|
77
|
+
]);
|
78
|
+
if (result) {
|
79
|
+
logger?.debug(`[Cache] HIT key '${cacheKey}'`);
|
80
|
+
return result;
|
81
|
+
}
|
82
|
+
} catch (e) {
|
83
|
+
logger?.error(`[Cache] Error GET '${cacheKey}': ${e.message}`);
|
84
|
+
if (e instanceof import_errors.CacheTimeoutError && client.disconnect) {
|
85
|
+
logger?.error(`[Cache] Disconnecting current instance...`);
|
86
|
+
await client.disconnect();
|
87
|
+
}
|
88
|
+
return serialize(await input());
|
89
|
+
}
|
90
|
+
let data;
|
91
|
+
try {
|
92
|
+
data = await input();
|
93
|
+
await Promise.race([
|
94
|
+
client.set(cacheKey, data, options2 || {}),
|
95
|
+
wait(timeout).then(() => {
|
96
|
+
throw new import_errors.CacheTimeoutError();
|
97
|
+
})
|
98
|
+
]);
|
99
|
+
logger?.debug(
|
100
|
+
`[Cache] MISS '${cacheKey}', SET ${JSON.stringify(data).length} bytes`
|
101
|
+
);
|
102
|
+
return serialize(data);
|
103
|
+
} catch (e) {
|
104
|
+
logger?.error(`[Cache] Error SET '${cacheKey}': ${e.message}`);
|
105
|
+
return serialize(data || await input());
|
106
|
+
}
|
107
|
+
};
|
108
|
+
const cacheFindMany = async (key, model, options2 = {}) => {
|
109
|
+
const { conditions, ...rest } = options2;
|
110
|
+
const cacheKey = formatCacheKey(key, prefix);
|
111
|
+
let latest, latestCacheKey;
|
112
|
+
const { PrismaClientValidationError } = await import("@prisma/client");
|
113
|
+
try {
|
114
|
+
latest = await model.findFirst({
|
115
|
+
...conditions,
|
116
|
+
orderBy: { [fields.updatedAt]: "desc" },
|
117
|
+
select: { [fields.id]: true, [fields.updatedAt]: true }
|
118
|
+
});
|
119
|
+
} catch (e) {
|
120
|
+
if (e instanceof PrismaClientValidationError) {
|
121
|
+
logger?.error(
|
122
|
+
`[Cache] cacheFindMany error: model does not contain \`${fields.id}\` or \`${fields.updatedAt}\` fields`
|
123
|
+
);
|
124
|
+
} else {
|
125
|
+
logger?.error(`[Cache] cacheFindMany error: ${e.message}`);
|
126
|
+
}
|
127
|
+
return serialize(await model.findMany(conditions));
|
128
|
+
}
|
129
|
+
if (latest) {
|
130
|
+
latestCacheKey = `${cacheKey}${cacheKeySeparator}${latest.id}${cacheKeySeparator}${latest[fields.updatedAt].getTime()}`;
|
131
|
+
} else {
|
132
|
+
logger?.debug(
|
133
|
+
`[Cache] cacheFindMany: No data to cache for key \`${key}\`, skipping`
|
134
|
+
);
|
135
|
+
return serialize(await model.findMany(conditions));
|
136
|
+
}
|
137
|
+
return cache(latestCacheKey, () => model.findMany(conditions), rest);
|
138
|
+
};
|
139
|
+
const deleteCacheKey = async (key) => {
|
140
|
+
let result;
|
141
|
+
const cacheKey = formatCacheKey(key, prefix);
|
142
|
+
try {
|
143
|
+
await Promise.race([
|
144
|
+
result = client.del(cacheKey),
|
145
|
+
wait(timeout).then(() => {
|
146
|
+
throw new import_errors.CacheTimeoutError();
|
147
|
+
})
|
148
|
+
]);
|
149
|
+
logger?.debug(`[Cache] DEL '${cacheKey}'`);
|
150
|
+
return result;
|
151
|
+
} catch (e) {
|
152
|
+
logger?.error(`[Cache] Error DEL '${cacheKey}': ${e.message}`);
|
153
|
+
return false;
|
154
|
+
}
|
155
|
+
};
|
156
|
+
return {
|
157
|
+
cache,
|
158
|
+
cacheFindMany,
|
159
|
+
cacheClient: client,
|
160
|
+
deleteCacheKey
|
161
|
+
};
|
162
|
+
};
|
163
|
+
// Annotate the CommonJS export names for ESM import in node:
|
164
|
+
0 && (module.exports = {
|
165
|
+
InMemoryClient,
|
166
|
+
MemcachedClient,
|
167
|
+
RedisClient,
|
168
|
+
cacheKeySeparator,
|
169
|
+
createCache,
|
170
|
+
formatCacheKey
|
171
|
+
});
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { PartialRequest } from './transforms.js';
|
2
|
+
export type CorsConfig = {
|
3
|
+
origin?: boolean | string | string[];
|
4
|
+
methods?: string | string[];
|
5
|
+
allowedHeaders?: string | string[];
|
6
|
+
exposedHeaders?: string | string[];
|
7
|
+
credentials?: boolean;
|
8
|
+
maxAge?: number;
|
9
|
+
};
|
10
|
+
export type CorsHeaders = Record<string, string>;
|
11
|
+
export type CorsContext = ReturnType<typeof createCorsContext>;
|
12
|
+
export declare function createCorsContext(cors: CorsConfig | undefined): {
|
13
|
+
shouldHandleCors(request: PartialRequest): boolean;
|
14
|
+
getRequestHeaders(request: PartialRequest): CorsHeaders;
|
15
|
+
};
|
16
|
+
//# sourceMappingURL=cors.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../src/cors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAErD,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;IACpC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAClC,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAClC,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAChD,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAE9D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS;8BA6ChC,cAAc;+BAGb,cAAc,GAAG,WAAW;EAgC1D"}
|