@akanjs/server 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/dbDecorators-z3rJpvxp.d.ts +36 -0
- package/index.d.ts +23 -0
- package/index.js +20 -3780
- package/package.json +2 -44
- package/src/boot.d.ts +49 -0
- package/src/boot.js +258 -0
- package/src/controller.d.ts +9 -0
- package/src/controller.js +96 -0
- package/src/gql.d.ts +77 -0
- package/src/gql.js +172 -0
- package/src/index.d.ts +23 -0
- package/src/index.js +39 -0
- package/src/module.d.ts +95 -0
- package/src/module.js +347 -0
- package/src/processor.d.ts +11 -0
- package/src/processor.js +85 -0
- package/src/resolver.d.ts +9 -0
- package/src/resolver.js +161 -0
- package/src/schema.d.ts +12 -0
- package/src/schema.js +275 -0
- package/src/searchDaemon.d.ts +13 -0
- package/src/searchDaemon.js +282 -0
- package/src/types.d.ts +18 -0
- package/src/types.js +15 -0
- package/src/websocket.d.ts +20 -0
- package/src/websocket.js +192 -0
- package/types-CUkhtrLV.d.ts +53 -0
- package/types-H2HI4YUe.d.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.40",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"postinstall": "pnpm install @nestjs/mongoose@^10.1.0"
|
|
@@ -20,47 +20,5 @@
|
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=22"
|
|
22
22
|
},
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"@nestjs/apollo": "^12.2.2",
|
|
25
|
-
"@nestjs/bull": "^10.2.3",
|
|
26
|
-
"@nestjs/common": "^10.4.15",
|
|
27
|
-
"@nestjs/core": "^10.4.15",
|
|
28
|
-
"@nestjs/graphql": "^12.2.2",
|
|
29
|
-
"@nestjs/mongoose": "^10.1.0",
|
|
30
|
-
"@nestjs/passport": "^10.0.3",
|
|
31
|
-
"@nestjs/platform-express": "^10.4.15",
|
|
32
|
-
"@nestjs/platform-socket.io": "^10.4.15",
|
|
33
|
-
"@nestjs/schedule": "^4.1.2",
|
|
34
|
-
"@nestjs/websockets": "^10.4.15",
|
|
35
|
-
"@socket.io/redis-adapter": "^8.3.0",
|
|
36
|
-
"@urql/core": "^5.1.0",
|
|
37
|
-
"apple-signin": "^1.0.9",
|
|
38
|
-
"body-parser": "^1.20.3",
|
|
39
|
-
"cookie-parser": "^1.4.7",
|
|
40
|
-
"dataloader": "^2.2.3",
|
|
41
|
-
"dayjs": "^1.11.13",
|
|
42
|
-
"graphql": "^16.10.0",
|
|
43
|
-
"graphql-type-json": "^0.3.2",
|
|
44
|
-
"graphql-upload": "^12.0.0",
|
|
45
|
-
"iap": "^1.1.1",
|
|
46
|
-
"immer": "^10.1.1",
|
|
47
|
-
"jsonwebtoken": "^9.0.2",
|
|
48
|
-
"lodash": "^4.17.21",
|
|
49
|
-
"meilisearch": "^0.47.0",
|
|
50
|
-
"mongoose": "^8.9.3",
|
|
51
|
-
"next": "^15.3.2",
|
|
52
|
-
"passport-apple": "^2.0.2",
|
|
53
|
-
"passport-facebook": "^3.0.0",
|
|
54
|
-
"passport-github": "^1.1.0",
|
|
55
|
-
"passport-google-oauth20": "^2.0.0",
|
|
56
|
-
"passport-kakao": "^1.0.1",
|
|
57
|
-
"passport-naver": "^1.0.6",
|
|
58
|
-
"pluralize": "^8.0.0",
|
|
59
|
-
"redis": "^4.7.0",
|
|
60
|
-
"reflect-metadata": "^0.2.2",
|
|
61
|
-
"rxjs": "^7.8.1",
|
|
62
|
-
"socket.io-client": "^4.8.1",
|
|
63
|
-
"tunnel-ssh": "^5.2.0",
|
|
64
|
-
"ua-parser-js": "^1.0.40"
|
|
65
|
-
}
|
|
23
|
+
"dependencies": {}
|
|
66
24
|
}
|
package/src/boot.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { SshOptions } from 'tunnel-ssh';
|
|
2
|
+
import { INestApplication, DynamicModule } from '@nestjs/common';
|
|
3
|
+
|
|
4
|
+
type Environment = "testing" | "debug" | "develop" | "main";
|
|
5
|
+
interface BaseEnv {
|
|
6
|
+
repoName: string;
|
|
7
|
+
serveDomain: string;
|
|
8
|
+
appName: string;
|
|
9
|
+
environment: Environment;
|
|
10
|
+
operationType: "server" | "client";
|
|
11
|
+
operationMode: "local" | "edge" | "cloud" | "module";
|
|
12
|
+
networkType: "mainnet" | "testnet" | "debugnet";
|
|
13
|
+
tunnelUsername: string;
|
|
14
|
+
tunnelPassword: string;
|
|
15
|
+
}
|
|
16
|
+
type BackendEnv = BaseEnv & {
|
|
17
|
+
hostname: string | null;
|
|
18
|
+
appCode: number;
|
|
19
|
+
mongo: {
|
|
20
|
+
username?: string;
|
|
21
|
+
password?: string;
|
|
22
|
+
sshOptions?: SshOptions;
|
|
23
|
+
};
|
|
24
|
+
redis?: {
|
|
25
|
+
sshOptions?: SshOptions;
|
|
26
|
+
};
|
|
27
|
+
port?: number;
|
|
28
|
+
mongoUri?: string;
|
|
29
|
+
redisUri?: string;
|
|
30
|
+
meiliUri?: string;
|
|
31
|
+
onCleanup?: () => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
interface AppCreateForm {
|
|
35
|
+
registerModules: (options: any) => (DynamicModule | null)[];
|
|
36
|
+
serverMode?: "federation" | "batch" | "all" | "none";
|
|
37
|
+
env: BackendEnv;
|
|
38
|
+
log?: boolean;
|
|
39
|
+
}
|
|
40
|
+
interface BackendApp {
|
|
41
|
+
nestApp: INestApplication;
|
|
42
|
+
close: () => Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
declare const createNestApp: ({ registerModules, serverMode, env, log }: AppCreateForm) => Promise<{
|
|
45
|
+
nestApp: INestApplication<any>;
|
|
46
|
+
close: () => Promise<void>;
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
export { type BackendApp, createNestApp };
|
package/src/boot.js
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
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 boot_exports = {};
|
|
30
|
+
__export(boot_exports, {
|
|
31
|
+
createNestApp: () => createNestApp
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(boot_exports);
|
|
34
|
+
var import_base = require("@akanjs/base");
|
|
35
|
+
var import_common = require("@akanjs/common");
|
|
36
|
+
var import_nest = require("@akanjs/nest");
|
|
37
|
+
var import_signal = require("@akanjs/signal");
|
|
38
|
+
var import_apollo = require("@nestjs/apollo");
|
|
39
|
+
var import_bull = require("@nestjs/bull");
|
|
40
|
+
var import_common2 = require("@nestjs/common");
|
|
41
|
+
var import_core = require("@nestjs/core");
|
|
42
|
+
var import_graphql = require("@nestjs/graphql");
|
|
43
|
+
var import_mongoose = require("@nestjs/mongoose");
|
|
44
|
+
var import_schedule = require("@nestjs/schedule");
|
|
45
|
+
var import_body_parser = require("body-parser");
|
|
46
|
+
var import_cookie_parser = __toESM(require("cookie-parser"));
|
|
47
|
+
var import_dgram = __toESM(require("dgram"));
|
|
48
|
+
var import_events = __toESM(require("events"));
|
|
49
|
+
var import_graphql_upload = require("graphql-upload");
|
|
50
|
+
var import_meilisearch = require("meilisearch");
|
|
51
|
+
var import_path = require("path");
|
|
52
|
+
var import_redis = require("redis");
|
|
53
|
+
var import_gql = require("./gql");
|
|
54
|
+
var import_module = require("./module");
|
|
55
|
+
var import_searchDaemon = require("./searchDaemon");
|
|
56
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
57
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
58
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
59
|
+
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;
|
|
60
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
61
|
+
}
|
|
62
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
63
|
+
const createNestApp = /* @__PURE__ */ __name(async ({ registerModules, serverMode = "federation", env, log = true }) => {
|
|
64
|
+
const backendLogger = new import_common.Logger("Backend");
|
|
65
|
+
if (log) backendLogger.rawLog(import_base.logo);
|
|
66
|
+
const jwtSecret = (0, import_nest.generateJwtSecret)(env.appName, env.environment);
|
|
67
|
+
const [redisUri, mongoUri, meiliUri] = await Promise.all([
|
|
68
|
+
env.redisUri ?? (0, import_nest.generateRedisUri)({
|
|
69
|
+
...env,
|
|
70
|
+
...env.redis?.sshOptions ? {
|
|
71
|
+
sshOptions: env.redis.sshOptions
|
|
72
|
+
} : {}
|
|
73
|
+
}),
|
|
74
|
+
env.mongoUri ?? (0, import_nest.generateMongoUri)({
|
|
75
|
+
...env,
|
|
76
|
+
...env.mongo.username ? {
|
|
77
|
+
username: env.mongo.username
|
|
78
|
+
} : {},
|
|
79
|
+
password: env.mongo.password,
|
|
80
|
+
...env.mongo.sshOptions ? {
|
|
81
|
+
sshOptions: env.mongo.sshOptions
|
|
82
|
+
} : {}
|
|
83
|
+
}),
|
|
84
|
+
env.meiliUri ?? (0, import_nest.generateMeiliUri)(env)
|
|
85
|
+
]);
|
|
86
|
+
if (env.operationMode === "local") {
|
|
87
|
+
backendLogger.verbose(`connect to redis: ${redisUri}`);
|
|
88
|
+
backendLogger.verbose(`connect to mongo: ${mongoUri}`);
|
|
89
|
+
backendLogger.verbose(`connect to meili: ${meiliUri}`);
|
|
90
|
+
}
|
|
91
|
+
(0, import_nest.initMongoDB)({
|
|
92
|
+
logging: import_base.baseEnv.environment !== "main",
|
|
93
|
+
sendReport: false
|
|
94
|
+
});
|
|
95
|
+
import_events.default.EventEmitter.defaultMaxListeners = 1e3;
|
|
96
|
+
let AuthMiddleWare = class AuthMiddleWare {
|
|
97
|
+
static {
|
|
98
|
+
__name(this, "AuthMiddleWare");
|
|
99
|
+
}
|
|
100
|
+
use(req, res, next) {
|
|
101
|
+
const requestHeader = req;
|
|
102
|
+
requestHeader.account = (0, import_nest.verifyToken)(jwtSecret, requestHeader.headers.authorization ?? (requestHeader.cookies?.jwt ? `Bearer ${requestHeader.cookies.jwt}` : void 0));
|
|
103
|
+
requestHeader.userAgent = requestHeader["user-agent"];
|
|
104
|
+
next();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
AuthMiddleWare = _ts_decorate([
|
|
108
|
+
(0, import_common2.Injectable)()
|
|
109
|
+
], AuthMiddleWare);
|
|
110
|
+
const redisClient = await (0, import_redis.createClient)({
|
|
111
|
+
url: redisUri
|
|
112
|
+
}).connect();
|
|
113
|
+
let SubDatabaseModule = class SubDatabaseModule {
|
|
114
|
+
static {
|
|
115
|
+
__name(this, "SubDatabaseModule");
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
SubDatabaseModule = _ts_decorate([
|
|
119
|
+
(0, import_common2.Global)(),
|
|
120
|
+
(0, import_common2.Module)({
|
|
121
|
+
providers: [
|
|
122
|
+
{
|
|
123
|
+
provide: "REDIS_CLIENT",
|
|
124
|
+
useValue: redisClient
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
provide: "MEILI_CLIENT",
|
|
128
|
+
useFactory: /* @__PURE__ */ __name(() => new import_meilisearch.MeiliSearch({
|
|
129
|
+
host: meiliUri,
|
|
130
|
+
apiKey: (0, import_nest.generateMeiliKey)(env)
|
|
131
|
+
}), "useFactory")
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
exports: [
|
|
135
|
+
"REDIS_CLIENT",
|
|
136
|
+
"MEILI_CLIENT"
|
|
137
|
+
]
|
|
138
|
+
})
|
|
139
|
+
], SubDatabaseModule);
|
|
140
|
+
let AppModule = class AppModule {
|
|
141
|
+
static {
|
|
142
|
+
__name(this, "AppModule");
|
|
143
|
+
}
|
|
144
|
+
configure(consumer) {
|
|
145
|
+
consumer.apply(AuthMiddleWare).forRoutes({
|
|
146
|
+
path: "*",
|
|
147
|
+
method: import_common2.RequestMethod.ALL
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
AppModule = _ts_decorate([
|
|
152
|
+
(0, import_common2.Module)({
|
|
153
|
+
imports: [
|
|
154
|
+
import_bull.BullModule.forRoot({
|
|
155
|
+
redis: redisUri
|
|
156
|
+
}),
|
|
157
|
+
import_schedule.ScheduleModule.forRoot(),
|
|
158
|
+
import_graphql.GraphQLModule.forRootAsync({
|
|
159
|
+
imports: [],
|
|
160
|
+
useFactory: /* @__PURE__ */ __name(() => ({
|
|
161
|
+
useGlobalPrefix: true,
|
|
162
|
+
autoSchemaFile: (0, import_path.join)(process.cwd(), "src/schema.gql"),
|
|
163
|
+
sortSchema: true,
|
|
164
|
+
playground: import_base.baseEnv.environment !== "main",
|
|
165
|
+
introspection: import_base.baseEnv.environment !== "main",
|
|
166
|
+
uploads: false,
|
|
167
|
+
debug: false
|
|
168
|
+
}), "useFactory"),
|
|
169
|
+
driver: import_apollo.ApolloDriver
|
|
170
|
+
}),
|
|
171
|
+
import_mongoose.MongooseModule.forRootAsync({
|
|
172
|
+
useFactory: /* @__PURE__ */ __name(() => ({
|
|
173
|
+
uri: mongoUri,
|
|
174
|
+
autoIndex: import_base.baseEnv.environment !== "main"
|
|
175
|
+
}), "useFactory")
|
|
176
|
+
}),
|
|
177
|
+
SubDatabaseModule,
|
|
178
|
+
(0, import_module.useGlobals)({
|
|
179
|
+
injects: {
|
|
180
|
+
SearchClient: import_nest.SearchClient,
|
|
181
|
+
DatabaseClient: import_nest.DatabaseClient,
|
|
182
|
+
CacheClient: import_nest.CacheClient
|
|
183
|
+
}
|
|
184
|
+
}),
|
|
185
|
+
...[
|
|
186
|
+
"batch",
|
|
187
|
+
"all"
|
|
188
|
+
].includes(serverMode) && import_base.baseEnv.operationMode !== "edge" ? [
|
|
189
|
+
import_searchDaemon.SearchDaemonModule
|
|
190
|
+
] : [],
|
|
191
|
+
...registerModules(env).filter((m) => !!m)
|
|
192
|
+
],
|
|
193
|
+
providers: [
|
|
194
|
+
import_gql.DateScalar
|
|
195
|
+
]
|
|
196
|
+
})
|
|
197
|
+
], AppModule);
|
|
198
|
+
const app = await import_core.NestFactory.create(AppModule, {
|
|
199
|
+
logger: backendLogger
|
|
200
|
+
});
|
|
201
|
+
const redisIoAdapter = new import_nest.RedisIoAdapter(app, {
|
|
202
|
+
jwtSecret
|
|
203
|
+
});
|
|
204
|
+
await redisIoAdapter.connectToRedis(redisUri);
|
|
205
|
+
app.enableShutdownHooks();
|
|
206
|
+
const udp = import_dgram.default.createSocket("udp4");
|
|
207
|
+
import_signal.client.setUdp(udp);
|
|
208
|
+
if ([
|
|
209
|
+
"federation",
|
|
210
|
+
"all"
|
|
211
|
+
].includes(serverMode)) {
|
|
212
|
+
app.setGlobalPrefix(process.env.GLOBAL_PREFIX ?? "/backend");
|
|
213
|
+
app.enableCors({
|
|
214
|
+
origin: "*",
|
|
215
|
+
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
|
|
216
|
+
preflightContinue: false,
|
|
217
|
+
optionsSuccessStatus: 204,
|
|
218
|
+
allowedHeaders: "DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,apollo-require-preflight"
|
|
219
|
+
});
|
|
220
|
+
if (env.operationMode !== "local" && process.env.USE_REDIS_IO_ADAPTER !== "false") app.useWebSocketAdapter(redisIoAdapter);
|
|
221
|
+
app.use((0, import_body_parser.json)({
|
|
222
|
+
limit: "100mb"
|
|
223
|
+
}));
|
|
224
|
+
app.use((0, import_body_parser.urlencoded)({
|
|
225
|
+
limit: "100mb",
|
|
226
|
+
extended: true
|
|
227
|
+
}));
|
|
228
|
+
app.use("/backend/graphql", (0, import_graphql_upload.graphqlUploadExpress)());
|
|
229
|
+
app.use((0, import_cookie_parser.default)());
|
|
230
|
+
app.useGlobalInterceptors(new import_nest.LoggingInterceptor());
|
|
231
|
+
app.useGlobalInterceptors(new import_nest.TimeoutInterceptor());
|
|
232
|
+
app.useGlobalInterceptors(new import_nest.CacheInterceptor(redisClient));
|
|
233
|
+
app.useGlobalFilters(new import_nest.AllExceptionsFilter());
|
|
234
|
+
await app.listen(process.env.PORT ?? env.port ?? 8080);
|
|
235
|
+
backendLogger.log(`\u{1F680} Server is running on: ${await app.getUrl()}`);
|
|
236
|
+
} else {
|
|
237
|
+
await app.init();
|
|
238
|
+
backendLogger.log(`\u{1F680} Batch Server is running`);
|
|
239
|
+
}
|
|
240
|
+
if (module.hot) {
|
|
241
|
+
module.hot.accept();
|
|
242
|
+
module.hot.dispose(() => {
|
|
243
|
+
void app.close();
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
nestApp: app,
|
|
248
|
+
close: /* @__PURE__ */ __name(async () => {
|
|
249
|
+
await app.close();
|
|
250
|
+
await redisIoAdapter.destroy();
|
|
251
|
+
await redisClient.quit();
|
|
252
|
+
}, "close")
|
|
253
|
+
};
|
|
254
|
+
}, "createNestApp");
|
|
255
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
256
|
+
0 && (module.exports = {
|
|
257
|
+
createNestApp
|
|
258
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
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 controller_exports = {};
|
|
20
|
+
__export(controller_exports, {
|
|
21
|
+
controllerOf: () => controllerOf
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(controller_exports);
|
|
24
|
+
var import_base = require("@akanjs/base");
|
|
25
|
+
var import_common = require("@akanjs/common");
|
|
26
|
+
var import_nest = require("@akanjs/nest");
|
|
27
|
+
var import_service = require("@akanjs/service");
|
|
28
|
+
var import_signal = require("@akanjs/signal");
|
|
29
|
+
var import_common2 = require("@nestjs/common");
|
|
30
|
+
var import_passport = require("@nestjs/passport");
|
|
31
|
+
var import_platform_express = require("@nestjs/platform-express");
|
|
32
|
+
const internalArgMap = {
|
|
33
|
+
// Parent: Nest.Parent,
|
|
34
|
+
Account: import_nest.Account,
|
|
35
|
+
UserIp: import_nest.UserIp,
|
|
36
|
+
Access: import_nest.Access,
|
|
37
|
+
Self: import_nest.Self,
|
|
38
|
+
Me: import_nest.Me,
|
|
39
|
+
Req: import_nest.Req,
|
|
40
|
+
Res: import_nest.Res
|
|
41
|
+
};
|
|
42
|
+
const controllerOf = /* @__PURE__ */ __name((sigRef, allSrvs) => {
|
|
43
|
+
const sigMeta = (0, import_signal.getSigMeta)(sigRef);
|
|
44
|
+
const gqlMetas = (0, import_signal.getGqlMetas)(sigRef);
|
|
45
|
+
const prefix = (0, import_signal.getControllerPrefix)(sigMeta);
|
|
46
|
+
const Ctrl = (0, import_signal.copySignal)(sigRef);
|
|
47
|
+
Object.keys(allSrvs).forEach((srv) => {
|
|
48
|
+
if (!(0, import_service.isServiceEnabled)(allSrvs[srv])) return;
|
|
49
|
+
(0, import_common2.Inject)(allSrvs[srv])(Ctrl.prototype, (0, import_common.lowerlize)(srv));
|
|
50
|
+
});
|
|
51
|
+
for (const gqlMeta of gqlMetas) {
|
|
52
|
+
if (gqlMeta.guards.some((guard) => guard === "None") || gqlMeta.signalOption.onlyFor === "graphql" || ![
|
|
53
|
+
"Query",
|
|
54
|
+
"Mutation"
|
|
55
|
+
].includes(gqlMeta.type)) continue;
|
|
56
|
+
const [argMetas, internalArgMetas] = (0, import_signal.getArgMetas)(Ctrl, gqlMeta.key);
|
|
57
|
+
internalArgMetas.forEach((internalArgMeta) => {
|
|
58
|
+
const internalDecorator = internalArgMap[internalArgMeta.type];
|
|
59
|
+
internalDecorator(internalArgMeta.option ?? {})(Ctrl.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
60
|
+
});
|
|
61
|
+
const uploadArgMeta = argMetas.find((argMeta) => argMeta.type === "Upload");
|
|
62
|
+
if (uploadArgMeta && gqlMeta.signalOption.onlyFor === "restapi") {
|
|
63
|
+
const [modelRef, arrDepth] = (0, import_base.getNonArrayModel)(uploadArgMeta.returns());
|
|
64
|
+
if (modelRef.prototype !== import_base.Upload.prototype) throw new Error("Upload must be Upload");
|
|
65
|
+
else if (!arrDepth) throw new Error(`Only Array of Upload is allowed - ${sigMeta.refName}/${gqlMeta.key}`);
|
|
66
|
+
(0, import_common2.UseInterceptors)((0, import_platform_express.FilesInterceptor)(uploadArgMeta.name))(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
67
|
+
(0, import_common2.UploadedFiles)(import_nest.MulterToUploadPipe)(Ctrl.prototype, gqlMeta.key, uploadArgMeta.idx);
|
|
68
|
+
}
|
|
69
|
+
const queryArgMetas = argMetas.filter((argMeta) => argMeta.type === "Query");
|
|
70
|
+
queryArgMetas.forEach((argMeta) => {
|
|
71
|
+
const [modelRef, arrDepth] = (0, import_base.getNonArrayModel)(argMeta.returns());
|
|
72
|
+
(0, import_common2.Query)(argMeta.name, ...(0, import_nest.getQueryPipes)(modelRef, arrDepth))(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
73
|
+
});
|
|
74
|
+
const paramArgMetas = argMetas.filter((argMeta) => argMeta.type === "Param");
|
|
75
|
+
paramArgMetas.forEach((argMeta) => {
|
|
76
|
+
(0, import_common2.Param)(argMeta.name)(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
77
|
+
});
|
|
78
|
+
const path = (0, import_signal.getControllerPath)(gqlMeta, paramArgMetas);
|
|
79
|
+
const bodyArgMetas = argMetas.filter((argMeta) => argMeta.type === "Body");
|
|
80
|
+
if (bodyArgMetas.length) bodyArgMetas.forEach((argMeta) => {
|
|
81
|
+
(0, import_common2.Body)(argMeta.name, ...(0, import_nest.getBodyPipes)(argMeta))(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
82
|
+
});
|
|
83
|
+
(0, import_common2.UseGuards)(...gqlMeta.guards.map((guard) => import_nest.guards[guard]), ...gqlMeta.signalOption.sso ? [
|
|
84
|
+
(0, import_passport.AuthGuard)(gqlMeta.signalOption.sso)
|
|
85
|
+
] : [])(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
86
|
+
if (gqlMeta.type === "Query") (0, import_common2.Get)(path)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
87
|
+
else if (gqlMeta.type === "Mutation") (0, import_common2.Post)(path)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
88
|
+
}
|
|
89
|
+
if (prefix) (0, import_common2.Controller)(prefix)(Ctrl);
|
|
90
|
+
else (0, import_common2.Controller)()(Ctrl);
|
|
91
|
+
return Ctrl;
|
|
92
|
+
}, "controllerOf");
|
|
93
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
+
0 && (module.exports = {
|
|
95
|
+
controllerOf
|
|
96
|
+
});
|
package/src/gql.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { G as GqlScalar, D as DocumentModel, B as BaseObject } from '../types-CUkhtrLV.js';
|
|
2
|
+
import { T as Type } from '../types-H2HI4YUe.js';
|
|
3
|
+
import { FilterQuery, AccumulatorOperator } from 'mongoose';
|
|
4
|
+
import { Dayjs } from 'dayjs';
|
|
5
|
+
import { a as Doc } from '../dbDecorators-z3rJpvxp.js';
|
|
6
|
+
import * as Nest from '@nestjs/graphql';
|
|
7
|
+
import { ValueNode } from 'graphql';
|
|
8
|
+
import 'fs';
|
|
9
|
+
import 'stream';
|
|
10
|
+
|
|
11
|
+
declare class Enum<T> {
|
|
12
|
+
readonly values: T[];
|
|
13
|
+
readonly value: T;
|
|
14
|
+
readonly valueMap: Map<T, number>;
|
|
15
|
+
constructor(values: T[]);
|
|
16
|
+
has(value: T): boolean;
|
|
17
|
+
indexOf(value: T): number;
|
|
18
|
+
find(callback: (value: T, index: number, array: T[]) => boolean): T;
|
|
19
|
+
findIndex(callback: (value: T, index: number, array: T[]) => boolean): number;
|
|
20
|
+
filter(callback: (value: T, index: number, array: T[]) => boolean): T[];
|
|
21
|
+
map<R>(callback: (value: T, index: number, array: T[]) => R): R[];
|
|
22
|
+
forEach(callback: (value: T, index: number, array: T[]) => void): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare const fieldTypes: readonly ["email", "password", "url"];
|
|
26
|
+
type FieldType = (typeof fieldTypes)[number];
|
|
27
|
+
interface ConstantFieldProps {
|
|
28
|
+
nullable?: boolean;
|
|
29
|
+
ref?: string;
|
|
30
|
+
refPath?: string;
|
|
31
|
+
refType?: "child" | "parent" | "relation";
|
|
32
|
+
default?: string | number | boolean | object | null | Enum<string | number>;
|
|
33
|
+
type?: FieldType;
|
|
34
|
+
fieldType?: "property" | "hidden" | "resolve";
|
|
35
|
+
immutable?: boolean;
|
|
36
|
+
min?: number;
|
|
37
|
+
max?: number;
|
|
38
|
+
enum?: Enum<string | number>;
|
|
39
|
+
select?: boolean;
|
|
40
|
+
minlength?: number;
|
|
41
|
+
maxlength?: number;
|
|
42
|
+
query?: FilterQuery<any> | (() => FilterQuery<any>);
|
|
43
|
+
accumulate?: AccumulatorOperator;
|
|
44
|
+
example?: string | number | boolean | Dayjs | string[] | number[] | boolean[] | Dayjs[];
|
|
45
|
+
of?: GqlScalar;
|
|
46
|
+
validate?: (value: any, model: any) => boolean;
|
|
47
|
+
text?: "search" | "filter";
|
|
48
|
+
}
|
|
49
|
+
type ConstantFieldMeta = ConstantFieldProps & {
|
|
50
|
+
nullable: boolean;
|
|
51
|
+
default: any;
|
|
52
|
+
fieldType: "property" | "hidden" | "resolve";
|
|
53
|
+
immutable: boolean;
|
|
54
|
+
select: boolean;
|
|
55
|
+
} & {
|
|
56
|
+
key: string;
|
|
57
|
+
name: string;
|
|
58
|
+
isClass: boolean;
|
|
59
|
+
isScalar: boolean;
|
|
60
|
+
modelRef: Type;
|
|
61
|
+
arrDepth: number;
|
|
62
|
+
isArray: boolean;
|
|
63
|
+
optArrDepth: number;
|
|
64
|
+
isMap: boolean;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
declare class DateScalar implements Nest.CustomScalar<Date, Dayjs> {
|
|
68
|
+
description: string;
|
|
69
|
+
parseValue(value: number): Dayjs;
|
|
70
|
+
serialize(value: Dayjs): Date;
|
|
71
|
+
parseLiteral(ast: ValueNode): Dayjs;
|
|
72
|
+
}
|
|
73
|
+
declare const applyNestField: (model: Type, fieldMeta: ConstantFieldMeta, type?: "object" | "input") => void;
|
|
74
|
+
declare const generateGqlInput: <InputModel>(inputRef: Type<InputModel>) => Type<DocumentModel<InputModel>>;
|
|
75
|
+
declare const generateGql: <ObjectModel>(objectRef: Type<ObjectModel>) => Type<ObjectModel extends BaseObject ? Doc<ObjectModel> : DocumentModel<ObjectModel>>;
|
|
76
|
+
|
|
77
|
+
export { DateScalar, applyNestField, generateGql, generateGqlInput };
|