@akanjs/nest 0.0.39 → 0.0.40

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/src/index.js ADDED
@@ -0,0 +1,73 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
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 src_exports = {};
30
+ __export(src_exports, {
31
+ Exporter: () => Exporter,
32
+ guards: () => guards
33
+ });
34
+ module.exports = __toCommonJS(src_exports);
35
+ __reExport(src_exports, require("./authorization"), module.exports);
36
+ __reExport(src_exports, require("./authGuards"), module.exports);
37
+ var guards = __toESM(require("./authGuards"));
38
+ __reExport(src_exports, require("./authentication"), module.exports);
39
+ __reExport(src_exports, require("./interceptors"), module.exports);
40
+ __reExport(src_exports, require("./redis-io.adapter"), module.exports);
41
+ __reExport(src_exports, require("./pipes"), module.exports);
42
+ var Exporter = __toESM(require("./exporter"));
43
+ __reExport(src_exports, require("./exporter"), module.exports);
44
+ __reExport(src_exports, require("./verifyPayment"), module.exports);
45
+ __reExport(src_exports, require("./sso"), module.exports);
46
+ __reExport(src_exports, require("./exceptions"), module.exports);
47
+ __reExport(src_exports, require("./generateSecrets"), module.exports);
48
+ __reExport(src_exports, require("./mongoose"), module.exports);
49
+ __reExport(src_exports, require("./searchClient"), module.exports);
50
+ __reExport(src_exports, require("./cacheClient"), module.exports);
51
+ __reExport(src_exports, require("./databaseClient"), module.exports);
52
+ __reExport(src_exports, require("./decorators"), module.exports);
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ Exporter,
56
+ guards,
57
+ ...require("./authorization"),
58
+ ...require("./authGuards"),
59
+ ...require("./authentication"),
60
+ ...require("./interceptors"),
61
+ ...require("./redis-io.adapter"),
62
+ ...require("./pipes"),
63
+ ...require("./exporter"),
64
+ ...require("./verifyPayment"),
65
+ ...require("./sso"),
66
+ ...require("./exceptions"),
67
+ ...require("./generateSecrets"),
68
+ ...require("./mongoose"),
69
+ ...require("./searchClient"),
70
+ ...require("./cacheClient"),
71
+ ...require("./databaseClient"),
72
+ ...require("./decorators")
73
+ });
@@ -0,0 +1,47 @@
1
+ import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
2
+ import { RedisClientType } from 'redis';
3
+ import { Observable } from 'rxjs';
4
+
5
+ declare const logLevels: readonly ["trace", "verbose", "debug", "log", "info", "warn", "error"];
6
+ type LogLevel = (typeof logLevels)[number];
7
+ declare class Logger {
8
+ #private;
9
+ static level: LogLevel;
10
+ static setLevel(level: LogLevel): void;
11
+ name?: string;
12
+ constructor(name?: string);
13
+ trace(msg: string, context?: string): void;
14
+ verbose(msg: string, context?: string): void;
15
+ debug(msg: string, context?: string): void;
16
+ log(msg: string, context?: string): void;
17
+ info(msg: string, context?: string): void;
18
+ warn(msg: string, context?: string): void;
19
+ error(msg: string, context?: string): void;
20
+ raw(msg: string, method?: "console" | "process"): void;
21
+ rawLog(msg: string, method?: "console" | "process"): void;
22
+ static trace(msg: string, context?: string): void;
23
+ static verbose(msg: string, context?: string): void;
24
+ static debug(msg: string, context?: string): void;
25
+ static log(msg: string, context?: string): void;
26
+ static info(msg: string, context?: string): void;
27
+ static warn(msg: string, context?: string): void;
28
+ static error(msg: string, context?: string): void;
29
+ static rawLog(msg: string, method?: "console" | "process"): void;
30
+ static raw(msg: string, method?: "console" | "process"): void;
31
+ }
32
+
33
+ declare class CacheInterceptor implements NestInterceptor {
34
+ #private;
35
+ private readonly redis;
36
+ constructor(redis: RedisClientType<any, any, any>);
37
+ intercept<T>(context: ExecutionContext, next: CallHandler): Promise<Observable<T>>;
38
+ }
39
+ declare class TimeoutInterceptor implements NestInterceptor {
40
+ intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
41
+ }
42
+ declare class LoggingInterceptor implements NestInterceptor {
43
+ logger: Logger;
44
+ intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
45
+ }
46
+
47
+ export { CacheInterceptor, LoggingInterceptor, TimeoutInterceptor };
@@ -0,0 +1,176 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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 interceptors_exports = {};
20
+ __export(interceptors_exports, {
21
+ CacheInterceptor: () => CacheInterceptor,
22
+ LoggingInterceptor: () => LoggingInterceptor,
23
+ TimeoutInterceptor: () => TimeoutInterceptor
24
+ });
25
+ module.exports = __toCommonJS(interceptors_exports);
26
+ var import_common = require("@akanjs/common");
27
+ var import_signal = require("@akanjs/signal");
28
+ var import_common2 = require("@nestjs/common");
29
+ var import_graphql = require("@nestjs/graphql");
30
+ var import_rxjs = require("rxjs");
31
+ var import_operators = require("rxjs/operators");
32
+ var import_authGuards = require("./authGuards");
33
+ function _ts_decorate(decorators, target, key, desc) {
34
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
35
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
36
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
37
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
38
+ }
39
+ __name(_ts_decorate, "_ts_decorate");
40
+ function _ts_metadata(k, v) {
41
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
42
+ }
43
+ __name(_ts_metadata, "_ts_metadata");
44
+ function _ts_param(paramIndex, decorator) {
45
+ return function(target, key) {
46
+ decorator(target, key, paramIndex);
47
+ };
48
+ }
49
+ __name(_ts_param, "_ts_param");
50
+ class CacheInterceptor {
51
+ static {
52
+ __name(this, "CacheInterceptor");
53
+ }
54
+ redis;
55
+ #logger;
56
+ #CACHE_PREFIX;
57
+ constructor(redis) {
58
+ this.redis = redis;
59
+ this.#logger = new import_common.Logger("CacheInterceptor");
60
+ this.#CACHE_PREFIX = "signal:";
61
+ }
62
+ async intercept(context, next) {
63
+ const handler = context.getHandler();
64
+ const signalKey = handler.name;
65
+ const gqlMeta = (0, import_signal.getGqlMeta)(context.getClass(), signalKey);
66
+ if (gqlMeta.type !== "Query" || !gqlMeta.signalOption.cache) {
67
+ if (gqlMeta.signalOption.cache) this.#logger.warn(`CacheInterceptor: ${signalKey} is not Query endpoint or cache is not set`);
68
+ return next.handle();
69
+ }
70
+ const args = (0, import_authGuards.getArgs)(context);
71
+ const cacheKey = this.#generateCacheKey(signalKey, args);
72
+ const cachedData = await this.#getCache(cacheKey);
73
+ if (cachedData) {
74
+ this.#logger.debug(`Cache hit for key: ${cacheKey}`);
75
+ return next.handle().pipe((0, import_operators.map)(() => cachedData), (0, import_operators.catchError)((error) => {
76
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
77
+ this.#logger.error(`Error in cache interceptor for ${cacheKey}: ${errorMessage}`);
78
+ return (0, import_rxjs.throwError)(() => error);
79
+ }));
80
+ }
81
+ return next.handle().pipe((0, import_operators.map)((data) => {
82
+ const cacheDuration = gqlMeta.signalOption.cache;
83
+ if (typeof cacheDuration === "number") {
84
+ void this.#setCache(cacheKey, data, cacheDuration);
85
+ this.#logger.debug(`Cache set for key: ${cacheKey}`);
86
+ }
87
+ return data;
88
+ }), (0, import_operators.catchError)((error) => {
89
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
90
+ this.#logger.error(`Error in cache interceptor for ${cacheKey}: ${errorMessage}`);
91
+ return (0, import_rxjs.throwError)(() => error);
92
+ }));
93
+ }
94
+ #generateCacheKey(signalKey, args) {
95
+ return `${this.#CACHE_PREFIX}${signalKey}:${JSON.stringify(args)}`;
96
+ }
97
+ async #getCache(key) {
98
+ try {
99
+ const cached = await this.redis.get(key);
100
+ if (!cached) return null;
101
+ const { data } = JSON.parse(cached);
102
+ return data;
103
+ } catch (error) {
104
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
105
+ this.#logger.error(`Error retrieving cache for key ${key}: ${errorMessage}`);
106
+ return null;
107
+ }
108
+ }
109
+ async #setCache(key, data, ttlMs) {
110
+ try {
111
+ const cacheData = {
112
+ data,
113
+ timestamp: Date.now()
114
+ };
115
+ await this.redis.set(key, JSON.stringify(cacheData), {
116
+ PX: ttlMs
117
+ });
118
+ } catch (error) {
119
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
120
+ this.#logger.error(`Error setting cache for key ${key}: ${errorMessage}`);
121
+ }
122
+ }
123
+ }
124
+ CacheInterceptor = _ts_decorate([
125
+ (0, import_common2.Injectable)(),
126
+ _ts_param(0, (0, import_common2.Inject)("REDIS_CLIENT")),
127
+ _ts_metadata("design:type", Function),
128
+ _ts_metadata("design:paramtypes", [
129
+ typeof RedisClientType === "undefined" ? Object : RedisClientType
130
+ ])
131
+ ], CacheInterceptor);
132
+ class TimeoutInterceptor {
133
+ static {
134
+ __name(this, "TimeoutInterceptor");
135
+ }
136
+ intercept(context, next) {
137
+ const gqlMeta = (0, import_signal.getGqlMeta)(context.getClass(), context.getHandler().name);
138
+ const timeoutMs = gqlMeta.signalOption.timeout ?? 3e4;
139
+ if (timeoutMs === 0) return next.handle();
140
+ return next.handle().pipe((0, import_operators.timeout)(timeoutMs), (0, import_operators.catchError)((err) => {
141
+ if (err instanceof import_rxjs.TimeoutError) return (0, import_rxjs.throwError)(() => new import_common2.RequestTimeoutException());
142
+ return (0, import_rxjs.throwError)(() => err);
143
+ }));
144
+ }
145
+ }
146
+ TimeoutInterceptor = _ts_decorate([
147
+ (0, import_common2.Injectable)()
148
+ ], TimeoutInterceptor);
149
+ class LoggingInterceptor {
150
+ static {
151
+ __name(this, "LoggingInterceptor");
152
+ }
153
+ logger = new import_common.Logger("IO");
154
+ intercept(context, next) {
155
+ const gqlReq = context.getArgByIndex(3);
156
+ const req = (0, import_authGuards.getRequest)(context);
157
+ const reqType = gqlReq?.parentType?.name ?? req.method;
158
+ const reqName = gqlReq?.fieldName ?? req.url;
159
+ const before = Date.now();
160
+ const ip = import_graphql.GqlExecutionContext.create(context).getContext().req.ip;
161
+ this.logger.debug(`Before ${reqType}-${reqName} / ${ip} / ${before}`);
162
+ return next.handle().pipe((0, import_operators.tap)(() => {
163
+ const after = Date.now();
164
+ this.logger.debug(`After ${reqType}-${reqName} / ${ip} / ${after} (${after - before}ms)`);
165
+ }));
166
+ }
167
+ }
168
+ LoggingInterceptor = _ts_decorate([
169
+ (0, import_common2.Injectable)()
170
+ ], LoggingInterceptor);
171
+ // Annotate the CommonJS export names for ESM import in node:
172
+ 0 && (module.exports = {
173
+ CacheInterceptor,
174
+ LoggingInterceptor,
175
+ TimeoutInterceptor
176
+ });
@@ -0,0 +1,7 @@
1
+ declare const initMongoDB: ({ logging, threshold, sendReport, }: {
2
+ logging: boolean;
3
+ threshold?: number;
4
+ sendReport?: boolean;
5
+ }) => void;
6
+
7
+ export { initMongoDB };
@@ -0,0 +1,87 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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 mongoose_exports = {};
30
+ __export(mongoose_exports, {
31
+ initMongoDB: () => initMongoDB
32
+ });
33
+ module.exports = __toCommonJS(mongoose_exports);
34
+ var import_common = require("@akanjs/common");
35
+ var import_mongoose = __toESM(require("mongoose"));
36
+ const initMongoDB = /* @__PURE__ */ __name(({ logging, threshold = 5e3, sendReport = false }) => {
37
+ const mongoDBLogger = new import_common.Logger("MongoDB");
38
+ if (logging) import_mongoose.default.set("debug", function(collection, method, ...methodArgs) {
39
+ mongoDBLogger.verbose(`${collection}.${method}(${methodArgs.slice(0, -1).map((arg) => JSON.stringify(arg)).join(", ")})`);
40
+ });
41
+ const originalExec = import_mongoose.default.Query.prototype.exec;
42
+ const getQueryInfo = /* @__PURE__ */ __name((queryAgent) => {
43
+ const model = queryAgent.model;
44
+ const collectionName = model.collection.collectionName;
45
+ const dbName = model.db.name;
46
+ const query = queryAgent.getQuery();
47
+ const queryOptions = queryAgent.getOptions();
48
+ return {
49
+ dbName,
50
+ collectionName,
51
+ query,
52
+ queryOptions
53
+ };
54
+ }, "getQueryInfo");
55
+ import_mongoose.default.Query.prototype.exec = function(...args) {
56
+ const start = Date.now();
57
+ return originalExec.apply(this, args).then((result) => {
58
+ const duration = Date.now() - start;
59
+ const { dbName, collectionName, query, queryOptions } = getQueryInfo(this);
60
+ if (logging) mongoDBLogger.verbose(`Queried ${dbName}.${collectionName}.query(${JSON.stringify(query)}, ${JSON.stringify(queryOptions)}) - ${duration}ms`);
61
+ return result;
62
+ });
63
+ };
64
+ const originalAggregate = import_mongoose.default.Model.aggregate;
65
+ const getAggregateInfo = /* @__PURE__ */ __name((aggregateModel) => {
66
+ const dbName = aggregateModel.db.db?.databaseName ?? "unknown";
67
+ const collectionName = aggregateModel.collection.collectionName;
68
+ return {
69
+ dbName,
70
+ collectionName
71
+ };
72
+ }, "getAggregateInfo");
73
+ import_mongoose.default.Model.aggregate = function(...args) {
74
+ const startTime = Date.now();
75
+ return originalAggregate.apply(this, args).then((result) => {
76
+ const duration = Date.now() - startTime;
77
+ const { dbName, collectionName } = getAggregateInfo(this);
78
+ if (logging) mongoDBLogger.verbose(`Aggregated ${dbName}.${collectionName}.aggregate(${args.map((arg) => JSON.stringify(arg)).join(", ")}) - ${duration}ms`);
79
+ return result;
80
+ });
81
+ };
82
+ import_mongoose.default.set("transactionAsyncLocalStorage", true);
83
+ }, "initMongoDB");
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ initMongoDB
87
+ });
package/src/pipes.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ import * as dayjsLib from 'dayjs';
2
+ import { Readable } from 'stream';
3
+ import { T as Type, a as ArgMeta } from '../signalDecorators-Bh7Aniud.js';
4
+ import { PipeTransform, ArgumentMetadata } from '@nestjs/common';
5
+ import '../baseEnv-Qb_Lg-a-.js';
6
+ import 'tunnel-ssh';
7
+
8
+ declare class ArrayifyPipe implements PipeTransform {
9
+ transform(value: string | string[], metadata: ArgumentMetadata): string[];
10
+ }
11
+ declare class IntPipe implements PipeTransform {
12
+ transform(value: string, metadata: ArgumentMetadata): number[];
13
+ }
14
+ declare class FloatPipe implements PipeTransform {
15
+ transform(value: string, metadata: ArgumentMetadata): number[];
16
+ }
17
+ declare class BooleanPipe implements PipeTransform {
18
+ transform(value: string, metadata: ArgumentMetadata): boolean[];
19
+ }
20
+ declare class DayjsPipe implements PipeTransform {
21
+ transform(value: string, metadata: ArgumentMetadata): dayjsLib.Dayjs[];
22
+ }
23
+ declare class JSONPipe implements PipeTransform {
24
+ transform(value: string | object, metadata: ArgumentMetadata): object;
25
+ }
26
+ interface FileStream {
27
+ originalname: string;
28
+ mimetype: string;
29
+ encoding: string;
30
+ buffer: Buffer;
31
+ }
32
+ declare class MulterToUploadPipe implements PipeTransform {
33
+ transform(value: FileStream, metadata: ArgumentMetadata): {
34
+ filename: string;
35
+ mimetype: string;
36
+ encoding: string;
37
+ createReadStream: () => Readable;
38
+ } | {
39
+ filename: string;
40
+ mimetype: string;
41
+ encoding: string;
42
+ createReadStream: () => Readable;
43
+ }[];
44
+ }
45
+ declare const getQueryPipes: (modelRef: Type, arrDepth: number) => Type[];
46
+ declare const getBodyPipes: (argMeta: ArgMeta) => {
47
+ new (): {
48
+ transform(value: any, metadata: ArgumentMetadata): object[] | null;
49
+ };
50
+ }[];
51
+
52
+ export { ArrayifyPipe, BooleanPipe, DayjsPipe, FloatPipe, IntPipe, JSONPipe, MulterToUploadPipe, getBodyPipes, getQueryPipes };
package/src/pipes.js ADDED
@@ -0,0 +1,195 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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 pipes_exports = {};
20
+ __export(pipes_exports, {
21
+ ArrayifyPipe: () => ArrayifyPipe,
22
+ BooleanPipe: () => BooleanPipe,
23
+ DayjsPipe: () => DayjsPipe,
24
+ FloatPipe: () => FloatPipe,
25
+ IntPipe: () => IntPipe,
26
+ JSONPipe: () => JSONPipe,
27
+ MulterToUploadPipe: () => MulterToUploadPipe,
28
+ getBodyPipes: () => getBodyPipes,
29
+ getQueryPipes: () => getQueryPipes
30
+ });
31
+ module.exports = __toCommonJS(pipes_exports);
32
+ var import_base = require("@akanjs/base");
33
+ var import_signal = require("@akanjs/signal");
34
+ var import_common = require("@nestjs/common");
35
+ var import_stream = require("stream");
36
+ function _ts_decorate(decorators, target, key, desc) {
37
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
38
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
39
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
40
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
41
+ }
42
+ __name(_ts_decorate, "_ts_decorate");
43
+ class ArrayifyPipe {
44
+ static {
45
+ __name(this, "ArrayifyPipe");
46
+ }
47
+ transform(value, metadata) {
48
+ return Array.isArray(value) ? value : value.split(",");
49
+ }
50
+ }
51
+ ArrayifyPipe = _ts_decorate([
52
+ (0, import_common.Injectable)()
53
+ ], ArrayifyPipe);
54
+ class IntPipe {
55
+ static {
56
+ __name(this, "IntPipe");
57
+ }
58
+ transform(value, metadata) {
59
+ return Array.isArray(value) ? value.map(parseInt) : [
60
+ parseInt(value)
61
+ ];
62
+ }
63
+ }
64
+ IntPipe = _ts_decorate([
65
+ (0, import_common.Injectable)()
66
+ ], IntPipe);
67
+ class FloatPipe {
68
+ static {
69
+ __name(this, "FloatPipe");
70
+ }
71
+ transform(value, metadata) {
72
+ return Array.isArray(value) ? value.map(parseFloat) : [
73
+ parseFloat(value)
74
+ ];
75
+ }
76
+ }
77
+ FloatPipe = _ts_decorate([
78
+ (0, import_common.Injectable)()
79
+ ], FloatPipe);
80
+ class BooleanPipe {
81
+ static {
82
+ __name(this, "BooleanPipe");
83
+ }
84
+ transform(value, metadata) {
85
+ return Array.isArray(value) ? value.map((v) => Boolean(v)) : [
86
+ Boolean(value)
87
+ ];
88
+ }
89
+ }
90
+ BooleanPipe = _ts_decorate([
91
+ (0, import_common.Injectable)()
92
+ ], BooleanPipe);
93
+ class DayjsPipe {
94
+ static {
95
+ __name(this, "DayjsPipe");
96
+ }
97
+ transform(value, metadata) {
98
+ return Array.isArray(value) ? value.map(import_base.dayjs) : [
99
+ (0, import_base.dayjs)(value)
100
+ ];
101
+ }
102
+ }
103
+ DayjsPipe = _ts_decorate([
104
+ (0, import_common.Injectable)()
105
+ ], DayjsPipe);
106
+ class JSONPipe {
107
+ static {
108
+ __name(this, "JSONPipe");
109
+ }
110
+ transform(value, metadata) {
111
+ const transformable = typeof value === "string" && value.length;
112
+ const obj = transformable ? JSON.parse(atob(value)) : value;
113
+ return obj;
114
+ }
115
+ }
116
+ JSONPipe = _ts_decorate([
117
+ (0, import_common.Injectable)()
118
+ ], JSONPipe);
119
+ const convertToFileStream = /* @__PURE__ */ __name((value) => ({
120
+ filename: value.originalname,
121
+ mimetype: value.mimetype,
122
+ encoding: value.encoding,
123
+ createReadStream: /* @__PURE__ */ __name(() => import_stream.Readable.from(value.buffer), "createReadStream")
124
+ }), "convertToFileStream");
125
+ class MulterToUploadPipe {
126
+ static {
127
+ __name(this, "MulterToUploadPipe");
128
+ }
129
+ transform(value, metadata) {
130
+ return Array.isArray(value) ? value.map(convertToFileStream) : convertToFileStream(value);
131
+ }
132
+ }
133
+ MulterToUploadPipe = _ts_decorate([
134
+ (0, import_common.Injectable)()
135
+ ], MulterToUploadPipe);
136
+ const gqlScalarPipeMap = /* @__PURE__ */ new Map([
137
+ [
138
+ import_base.Int,
139
+ IntPipe
140
+ ],
141
+ [
142
+ import_base.Float,
143
+ FloatPipe
144
+ ],
145
+ [
146
+ Boolean,
147
+ BooleanPipe
148
+ ],
149
+ [
150
+ Date,
151
+ DayjsPipe
152
+ ],
153
+ [
154
+ import_base.JSON,
155
+ JSONPipe
156
+ ]
157
+ ]);
158
+ const getQueryPipes = /* @__PURE__ */ __name((modelRef, arrDepth) => {
159
+ const pipes = arrDepth ? [
160
+ ArrayifyPipe
161
+ ] : [];
162
+ const scalarPipe = gqlScalarPipeMap.get(modelRef);
163
+ if (scalarPipe) pipes.push(scalarPipe);
164
+ return pipes;
165
+ }, "getQueryPipes");
166
+ const getBodyPipes = /* @__PURE__ */ __name((argMeta) => {
167
+ const [returnRef] = (0, import_base.getNonArrayModel)(argMeta.returns());
168
+ if (returnRef.prototype !== Date.prototype && !(0, import_base.isGqlScalar)(returnRef)) return [];
169
+ let BodyPipe = class BodyPipe {
170
+ static {
171
+ __name(this, "BodyPipe");
172
+ }
173
+ transform(value, metadata) {
174
+ return (0, import_signal.deserializeArg)(argMeta, value);
175
+ }
176
+ };
177
+ BodyPipe = _ts_decorate([
178
+ (0, import_common.Injectable)()
179
+ ], BodyPipe);
180
+ return [
181
+ BodyPipe
182
+ ];
183
+ }, "getBodyPipes");
184
+ // Annotate the CommonJS export names for ESM import in node:
185
+ 0 && (module.exports = {
186
+ ArrayifyPipe,
187
+ BooleanPipe,
188
+ DayjsPipe,
189
+ FloatPipe,
190
+ IntPipe,
191
+ JSONPipe,
192
+ MulterToUploadPipe,
193
+ getBodyPipes,
194
+ getQueryPipes
195
+ });
@@ -0,0 +1,21 @@
1
+ import { INestApplicationContext } from '@nestjs/common';
2
+ import { IoAdapter } from '@nestjs/platform-socket.io';
3
+ import { ServerOptions } from 'socket.io';
4
+
5
+ interface RedisIoAdapterOption extends Partial<ServerOptions> {
6
+ jwtSecret: string;
7
+ }
8
+ declare class RedisIoAdapter extends IoAdapter {
9
+ private adapterConstructor;
10
+ private readonly logger;
11
+ private server;
12
+ private pubClient;
13
+ private subClient;
14
+ option: RedisIoAdapterOption;
15
+ constructor(appOrHttpServer: INestApplicationContext, option: RedisIoAdapterOption);
16
+ connectToRedis(url: string): Promise<void>;
17
+ createIOServer(port: number, options?: ServerOptions): any;
18
+ destroy(): Promise<void>;
19
+ }
20
+
21
+ export { RedisIoAdapter };