@akanjs/nest 0.0.40 → 0.0.41
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/index.d.ts +1 -31
- package/index.js +2134 -21
- package/package.json +32 -2
- package/src/authGuards.d.ts +51 -7
- package/src/authentication.d.ts +13 -17
- package/src/authorization.d.ts +3 -9
- package/src/cacheClient.d.ts +2 -5
- package/src/databaseClient.d.ts +3 -7
- package/src/decorators.d.ts +8 -9
- package/src/exceptions.d.ts +2 -5
- package/src/exporter.d.ts +22 -2
- package/src/generateSecrets.d.ts +11 -13
- package/src/index.d.ts +18 -31
- package/src/interceptors.d.ts +7 -37
- package/src/mongoose.d.ts +1 -3
- package/src/pipes.d.ts +15 -19
- package/src/redis-io.adapter.d.ts +5 -7
- package/src/searchClient.d.ts +7 -14
- package/src/sso.d.ts +14 -19
- package/src/verifyPayment.d.ts +2 -3
- package/authGuards-BrXXzJa_.d.ts +0 -80
- package/baseEnv-Qb_Lg-a-.d.ts +0 -33
- package/exporter-BJ7Vr_DT.d.ts +0 -36
- package/signalDecorators-Bh7Aniud.d.ts +0 -121
- package/src/authGuards.js +0 -193
- package/src/authentication.js +0 -119
- package/src/authorization.js +0 -75
- package/src/cacheClient.js +0 -52
- package/src/databaseClient.js +0 -58
- package/src/decorators.js +0 -162
- package/src/exceptions.js +0 -76
- package/src/exporter.js +0 -117
- package/src/generateSecrets.js +0 -136
- package/src/index.js +0 -73
- package/src/interceptors.js +0 -176
- package/src/mongoose.js +0 -87
- package/src/pipes.js +0 -195
- package/src/redis-io.adapter.js +0 -96
- package/src/searchClient.js +0 -106
- package/src/sso.js +0 -250
- package/src/verifyPayment.js +0 -49
package/src/interceptors.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
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
|
-
});
|
package/src/mongoose.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
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.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
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
|
-
});
|
package/src/redis-io.adapter.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
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 redis_io_adapter_exports = {};
|
|
20
|
-
__export(redis_io_adapter_exports, {
|
|
21
|
-
RedisIoAdapter: () => RedisIoAdapter
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(redis_io_adapter_exports);
|
|
24
|
-
var import_common = require("@akanjs/common");
|
|
25
|
-
var import_platform_socket = require("@nestjs/platform-socket.io");
|
|
26
|
-
var import_redis_adapter = require("@socket.io/redis-adapter");
|
|
27
|
-
var import_redis = require("redis");
|
|
28
|
-
class RedisIoAdapter extends import_platform_socket.IoAdapter {
|
|
29
|
-
static {
|
|
30
|
-
__name(this, "RedisIoAdapter");
|
|
31
|
-
}
|
|
32
|
-
adapterConstructor;
|
|
33
|
-
logger = new import_common.Logger("RedisIoAdapter");
|
|
34
|
-
server;
|
|
35
|
-
pubClient;
|
|
36
|
-
subClient;
|
|
37
|
-
option;
|
|
38
|
-
constructor(appOrHttpServer, option) {
|
|
39
|
-
super(appOrHttpServer);
|
|
40
|
-
this.option = option;
|
|
41
|
-
}
|
|
42
|
-
async connectToRedis(url) {
|
|
43
|
-
this.pubClient = (0, import_redis.createClient)({
|
|
44
|
-
url
|
|
45
|
-
});
|
|
46
|
-
this.subClient = this.pubClient.duplicate();
|
|
47
|
-
this.pubClient.on("disconnect", (err) => {
|
|
48
|
-
this.logger.error(`Redis pub database is disconnected. Error: ${err}`);
|
|
49
|
-
void this.pubClient.connect();
|
|
50
|
-
});
|
|
51
|
-
this.subClient.on("disconnect", (err) => {
|
|
52
|
-
this.logger.error(`Redis sub database is disconnected. Error: ${err}`);
|
|
53
|
-
void this.subClient.connect();
|
|
54
|
-
});
|
|
55
|
-
this.pubClient.on("error", (err) => {
|
|
56
|
-
this.logger.error(`Redis pub database is errored. Error: ${err}`);
|
|
57
|
-
const reconnect = /* @__PURE__ */ __name(async () => {
|
|
58
|
-
await this.pubClient.quit();
|
|
59
|
-
await (0, import_common.sleep)(1e3);
|
|
60
|
-
await this.pubClient.connect();
|
|
61
|
-
}, "reconnect");
|
|
62
|
-
void reconnect();
|
|
63
|
-
});
|
|
64
|
-
this.subClient.on("error", (err) => {
|
|
65
|
-
this.logger.error(`Redis sub database is errored. Error: ${err}`);
|
|
66
|
-
const reconnect = /* @__PURE__ */ __name(async () => {
|
|
67
|
-
await this.subClient.quit();
|
|
68
|
-
await (0, import_common.sleep)(1e3);
|
|
69
|
-
await this.subClient.connect();
|
|
70
|
-
}, "reconnect");
|
|
71
|
-
void reconnect();
|
|
72
|
-
});
|
|
73
|
-
await Promise.all([
|
|
74
|
-
this.pubClient.connect(),
|
|
75
|
-
this.subClient.connect()
|
|
76
|
-
]);
|
|
77
|
-
this.adapterConstructor = (0, import_redis_adapter.createAdapter)(this.pubClient, this.subClient);
|
|
78
|
-
}
|
|
79
|
-
createIOServer(port, options) {
|
|
80
|
-
this.server = super.createIOServer(port, options);
|
|
81
|
-
this.server.adapter(this.adapterConstructor);
|
|
82
|
-
return this.server;
|
|
83
|
-
}
|
|
84
|
-
async destroy() {
|
|
85
|
-
await Promise.all([
|
|
86
|
-
this.pubClient.quit(),
|
|
87
|
-
this.subClient.quit()
|
|
88
|
-
]);
|
|
89
|
-
await this.close(this.server);
|
|
90
|
-
this.logger.log("RedisIoAdapter is closed");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
-
0 && (module.exports = {
|
|
95
|
-
RedisIoAdapter
|
|
96
|
-
});
|
package/src/searchClient.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
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 searchClient_exports = {};
|
|
30
|
-
__export(searchClient_exports, {
|
|
31
|
-
SearchClient: () => SearchClient
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(searchClient_exports);
|
|
34
|
-
var import_constant = require("@akanjs/constant");
|
|
35
|
-
var import_common = require("@nestjs/common");
|
|
36
|
-
var import_meilisearch = __toESM(require("meilisearch"));
|
|
37
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
38
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
39
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
40
|
-
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;
|
|
41
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
42
|
-
}
|
|
43
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
44
|
-
function _ts_metadata(k, v) {
|
|
45
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
46
|
-
}
|
|
47
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
48
|
-
class SearchClient {
|
|
49
|
-
static {
|
|
50
|
-
__name(this, "SearchClient");
|
|
51
|
-
}
|
|
52
|
-
meili;
|
|
53
|
-
async getIndexNames() {
|
|
54
|
-
const { results } = await this.meili.getIndexes({
|
|
55
|
-
limit: 1e3
|
|
56
|
-
});
|
|
57
|
-
return results.map((index) => index.uid);
|
|
58
|
-
}
|
|
59
|
-
async getSearchResult(indexName, option) {
|
|
60
|
-
const { skip = 0, limit = import_constant.DEFAULT_PAGE_SIZE, sort = "", searchString } = option;
|
|
61
|
-
if (!searchString) {
|
|
62
|
-
const { results, total } = await this.meili.index(indexName).getDocuments({
|
|
63
|
-
offset: skip,
|
|
64
|
-
limit
|
|
65
|
-
});
|
|
66
|
-
return {
|
|
67
|
-
docs: results,
|
|
68
|
-
skip,
|
|
69
|
-
limit,
|
|
70
|
-
sort,
|
|
71
|
-
total
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
const { hits, estimatedTotalHits } = await this.meili.index(indexName).search(searchString, {
|
|
75
|
-
offset: skip,
|
|
76
|
-
limit
|
|
77
|
-
});
|
|
78
|
-
return {
|
|
79
|
-
docs: hits,
|
|
80
|
-
skip,
|
|
81
|
-
limit,
|
|
82
|
-
sort,
|
|
83
|
-
total: estimatedTotalHits,
|
|
84
|
-
query: searchString
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
async upsertDocuments(indexName, documents) {
|
|
88
|
-
const task = await this.meili.index(indexName).addDocuments(documents);
|
|
89
|
-
return task;
|
|
90
|
-
}
|
|
91
|
-
async dropIndex(indexName) {
|
|
92
|
-
const task = await this.meili.index(indexName).delete();
|
|
93
|
-
return task;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
_ts_decorate([
|
|
97
|
-
(0, import_common.Inject)("MEILI_CLIENT"),
|
|
98
|
-
_ts_metadata("design:type", typeof import_meilisearch.default === "undefined" ? Object : import_meilisearch.default)
|
|
99
|
-
], SearchClient.prototype, "meili", void 0);
|
|
100
|
-
SearchClient = _ts_decorate([
|
|
101
|
-
(0, import_common.Injectable)()
|
|
102
|
-
], SearchClient);
|
|
103
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
-
0 && (module.exports = {
|
|
105
|
-
SearchClient
|
|
106
|
-
});
|