@akanjs/server 0.0.99 → 0.0.100
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.js +21 -1
- package/index.mjs +1 -0
- package/package.json +4 -4
- package/src/boot.js +94 -84
- package/src/boot.mjs +190 -0
- package/src/controller.js +63 -70
- package/src/controller.mjs +109 -0
- package/src/gql.js +64 -35
- package/src/gql.mjs +123 -0
- package/src/index.js +39 -10
- package/src/index.mjs +10 -0
- package/src/module.js +103 -77
- package/src/module.mjs +229 -0
- package/src/processor.js +41 -22
- package/src/processor.mjs +73 -0
- package/src/resolver.js +76 -49
- package/src/resolver.mjs +118 -0
- package/src/schema.js +78 -54
- package/src/{schema.cjs → schema.mjs} +54 -78
- package/src/searchDaemon.js +45 -29
- package/src/{searchDaemon.cjs → searchDaemon.mjs} +29 -45
- package/src/types.js +15 -0
- package/src/types.mjs +0 -0
- package/src/websocket.js +55 -33
- package/src/websocket.mjs +124 -0
- package/index.cjs +0 -21
- package/src/boot.cjs +0 -200
- package/src/controller.cjs +0 -102
- package/src/gql.cjs +0 -152
- package/src/index.cjs +0 -39
- package/src/module.cjs +0 -255
- package/src/processor.cjs +0 -92
- package/src/resolver.cjs +0 -145
- package/src/types.cjs +0 -15
- package/src/websocket.cjs +0 -146
package/src/controller.js
CHANGED
|
@@ -1,109 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
Post,
|
|
32
|
-
Query,
|
|
33
|
-
UploadedFiles,
|
|
34
|
-
UseGuards,
|
|
35
|
-
UseInterceptors
|
|
36
|
-
} from "@nestjs/common";
|
|
37
|
-
import { AuthGuard } from "@nestjs/passport";
|
|
38
|
-
import { FilesInterceptor } from "@nestjs/platform-express";
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var controller_exports = {};
|
|
19
|
+
__export(controller_exports, {
|
|
20
|
+
controllerOf: () => controllerOf
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(controller_exports);
|
|
23
|
+
var import_base = require("@akanjs/base");
|
|
24
|
+
var import_common = require("@akanjs/common");
|
|
25
|
+
var import_nest = require("@akanjs/nest");
|
|
26
|
+
var import_service = require("@akanjs/service");
|
|
27
|
+
var import_signal = require("@akanjs/signal");
|
|
28
|
+
var import_common2 = require("@nestjs/common");
|
|
29
|
+
var import_passport = require("@nestjs/passport");
|
|
30
|
+
var import_platform_express = require("@nestjs/platform-express");
|
|
39
31
|
const internalArgMap = {
|
|
40
32
|
// Parent: Nest.Parent,
|
|
41
|
-
Account,
|
|
42
|
-
UserIp,
|
|
43
|
-
Access,
|
|
44
|
-
Self,
|
|
45
|
-
Me,
|
|
46
|
-
Req,
|
|
47
|
-
Res
|
|
33
|
+
Account: import_nest.Account,
|
|
34
|
+
UserIp: import_nest.UserIp,
|
|
35
|
+
Access: import_nest.Access,
|
|
36
|
+
Self: import_nest.Self,
|
|
37
|
+
Me: import_nest.Me,
|
|
38
|
+
Req: import_nest.Req,
|
|
39
|
+
Res: import_nest.Res
|
|
48
40
|
};
|
|
49
41
|
const controllerOf = (sigRef, allSrvs) => {
|
|
50
|
-
const sigMeta = getSigMeta(sigRef);
|
|
51
|
-
const gqlMetas = getGqlMetas(sigRef);
|
|
52
|
-
const prefix = getControllerPrefix(sigMeta);
|
|
53
|
-
const Ctrl = copySignal(sigRef);
|
|
42
|
+
const sigMeta = (0, import_signal.getSigMeta)(sigRef);
|
|
43
|
+
const gqlMetas = (0, import_signal.getGqlMetas)(sigRef);
|
|
44
|
+
const prefix = (0, import_signal.getControllerPrefix)(sigMeta);
|
|
45
|
+
const Ctrl = (0, import_signal.copySignal)(sigRef);
|
|
54
46
|
Object.keys(allSrvs).forEach((srv) => {
|
|
55
|
-
if (!isServiceEnabled(allSrvs[srv]))
|
|
47
|
+
if (!(0, import_service.isServiceEnabled)(allSrvs[srv]))
|
|
56
48
|
return;
|
|
57
|
-
Inject(allSrvs[srv])(Ctrl.prototype, lowerlize(srv));
|
|
49
|
+
(0, import_common2.Inject)(allSrvs[srv])(Ctrl.prototype, (0, import_common.lowerlize)(srv));
|
|
58
50
|
});
|
|
59
51
|
for (const gqlMeta of gqlMetas) {
|
|
60
52
|
if (gqlMeta.guards.some((guard) => guard === "None") || gqlMeta.signalOption.onlyFor === "graphql" || !["Query", "Mutation"].includes(gqlMeta.type))
|
|
61
53
|
continue;
|
|
62
|
-
const [argMetas, internalArgMetas] = getArgMetas(Ctrl, gqlMeta.key);
|
|
54
|
+
const [argMetas, internalArgMetas] = (0, import_signal.getArgMetas)(Ctrl, gqlMeta.key);
|
|
63
55
|
internalArgMetas.forEach((internalArgMeta) => {
|
|
64
56
|
const internalDecorator = internalArgMap[internalArgMeta.type];
|
|
65
57
|
internalDecorator(internalArgMeta.option ?? {})(Ctrl.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
66
58
|
});
|
|
67
59
|
const uploadArgMeta = argMetas.find((argMeta) => argMeta.type === "Upload");
|
|
68
60
|
if (uploadArgMeta && gqlMeta.signalOption.onlyFor === "restapi") {
|
|
69
|
-
const [modelRef, arrDepth] = getNonArrayModel(uploadArgMeta.returns());
|
|
70
|
-
if (modelRef.prototype !== Upload.prototype)
|
|
61
|
+
const [modelRef, arrDepth] = (0, import_base.getNonArrayModel)(uploadArgMeta.returns());
|
|
62
|
+
if (modelRef.prototype !== import_base.Upload.prototype)
|
|
71
63
|
throw new Error("Upload must be Upload");
|
|
72
64
|
else if (!arrDepth)
|
|
73
65
|
throw new Error(`Only Array of Upload is allowed - ${sigMeta.refName}/${gqlMeta.key}`);
|
|
74
|
-
UseInterceptors(FilesInterceptor(uploadArgMeta.name))(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
75
|
-
UploadedFiles(MulterToUploadPipe)(Ctrl.prototype, gqlMeta.key, uploadArgMeta.idx);
|
|
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);
|
|
76
68
|
}
|
|
77
69
|
const queryArgMetas = argMetas.filter((argMeta) => argMeta.type === "Query");
|
|
78
70
|
queryArgMetas.forEach((argMeta) => {
|
|
79
|
-
const [modelRef, arrDepth] = getNonArrayModel(argMeta.returns());
|
|
80
|
-
Query(argMeta.name, ...getQueryPipes(modelRef, arrDepth))(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
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);
|
|
81
73
|
});
|
|
82
74
|
const paramArgMetas = argMetas.filter((argMeta) => argMeta.type === "Param");
|
|
83
75
|
paramArgMetas.forEach((argMeta) => {
|
|
84
|
-
Param(argMeta.name)(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
76
|
+
(0, import_common2.Param)(argMeta.name)(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
85
77
|
});
|
|
86
|
-
const path = getControllerPath(gqlMeta, paramArgMetas);
|
|
78
|
+
const path = (0, import_signal.getControllerPath)(gqlMeta, paramArgMetas);
|
|
87
79
|
const bodyArgMetas = argMetas.filter((argMeta) => argMeta.type === "Body");
|
|
88
80
|
if (bodyArgMetas.length)
|
|
89
81
|
bodyArgMetas.forEach((argMeta) => {
|
|
90
|
-
Body(argMeta.name, ...getBodyPipes(argMeta))(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
82
|
+
(0, import_common2.Body)(argMeta.name, ...(0, import_nest.getBodyPipes)(argMeta))(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
91
83
|
});
|
|
92
|
-
UseGuards(
|
|
93
|
-
...gqlMeta.guards.map((guard) => guards[guard]),
|
|
94
|
-
...gqlMeta.signalOption.sso ? [AuthGuard(gqlMeta.signalOption.sso)] : []
|
|
84
|
+
(0, import_common2.UseGuards)(
|
|
85
|
+
...gqlMeta.guards.map((guard) => import_nest.guards[guard]),
|
|
86
|
+
...gqlMeta.signalOption.sso ? [(0, import_passport.AuthGuard)(gqlMeta.signalOption.sso)] : []
|
|
95
87
|
)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
96
88
|
if (gqlMeta.type === "Query")
|
|
97
|
-
Get(path)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
89
|
+
(0, import_common2.Get)(path)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
98
90
|
else if (gqlMeta.type === "Mutation")
|
|
99
|
-
Post(path)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
91
|
+
(0, import_common2.Post)(path)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
100
92
|
}
|
|
101
93
|
if (prefix)
|
|
102
|
-
Controller(prefix)(Ctrl);
|
|
94
|
+
(0, import_common2.Controller)(prefix)(Ctrl);
|
|
103
95
|
else
|
|
104
|
-
Controller()(Ctrl);
|
|
96
|
+
(0, import_common2.Controller)()(Ctrl);
|
|
105
97
|
return Ctrl;
|
|
106
98
|
};
|
|
107
|
-
export
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
108
101
|
controllerOf
|
|
109
|
-
};
|
|
102
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { getNonArrayModel, Upload } from "@akanjs/base";
|
|
2
|
+
import { lowerlize } from "@akanjs/common";
|
|
3
|
+
import {
|
|
4
|
+
Access,
|
|
5
|
+
Account,
|
|
6
|
+
getBodyPipes,
|
|
7
|
+
getQueryPipes,
|
|
8
|
+
guards,
|
|
9
|
+
Me,
|
|
10
|
+
MulterToUploadPipe,
|
|
11
|
+
Req,
|
|
12
|
+
Res,
|
|
13
|
+
Self,
|
|
14
|
+
UserIp
|
|
15
|
+
} from "@akanjs/nest";
|
|
16
|
+
import { isServiceEnabled } from "@akanjs/service";
|
|
17
|
+
import {
|
|
18
|
+
copySignal,
|
|
19
|
+
getArgMetas,
|
|
20
|
+
getControllerPath,
|
|
21
|
+
getControllerPrefix,
|
|
22
|
+
getGqlMetas,
|
|
23
|
+
getSigMeta
|
|
24
|
+
} from "@akanjs/signal";
|
|
25
|
+
import {
|
|
26
|
+
Body,
|
|
27
|
+
Controller,
|
|
28
|
+
Get,
|
|
29
|
+
Inject,
|
|
30
|
+
Param,
|
|
31
|
+
Post,
|
|
32
|
+
Query,
|
|
33
|
+
UploadedFiles,
|
|
34
|
+
UseGuards,
|
|
35
|
+
UseInterceptors
|
|
36
|
+
} from "@nestjs/common";
|
|
37
|
+
import { AuthGuard } from "@nestjs/passport";
|
|
38
|
+
import { FilesInterceptor } from "@nestjs/platform-express";
|
|
39
|
+
const internalArgMap = {
|
|
40
|
+
// Parent: Nest.Parent,
|
|
41
|
+
Account,
|
|
42
|
+
UserIp,
|
|
43
|
+
Access,
|
|
44
|
+
Self,
|
|
45
|
+
Me,
|
|
46
|
+
Req,
|
|
47
|
+
Res
|
|
48
|
+
};
|
|
49
|
+
const controllerOf = (sigRef, allSrvs) => {
|
|
50
|
+
const sigMeta = getSigMeta(sigRef);
|
|
51
|
+
const gqlMetas = getGqlMetas(sigRef);
|
|
52
|
+
const prefix = getControllerPrefix(sigMeta);
|
|
53
|
+
const Ctrl = copySignal(sigRef);
|
|
54
|
+
Object.keys(allSrvs).forEach((srv) => {
|
|
55
|
+
if (!isServiceEnabled(allSrvs[srv]))
|
|
56
|
+
return;
|
|
57
|
+
Inject(allSrvs[srv])(Ctrl.prototype, lowerlize(srv));
|
|
58
|
+
});
|
|
59
|
+
for (const gqlMeta of gqlMetas) {
|
|
60
|
+
if (gqlMeta.guards.some((guard) => guard === "None") || gqlMeta.signalOption.onlyFor === "graphql" || !["Query", "Mutation"].includes(gqlMeta.type))
|
|
61
|
+
continue;
|
|
62
|
+
const [argMetas, internalArgMetas] = getArgMetas(Ctrl, gqlMeta.key);
|
|
63
|
+
internalArgMetas.forEach((internalArgMeta) => {
|
|
64
|
+
const internalDecorator = internalArgMap[internalArgMeta.type];
|
|
65
|
+
internalDecorator(internalArgMeta.option ?? {})(Ctrl.prototype, gqlMeta.key, internalArgMeta.idx);
|
|
66
|
+
});
|
|
67
|
+
const uploadArgMeta = argMetas.find((argMeta) => argMeta.type === "Upload");
|
|
68
|
+
if (uploadArgMeta && gqlMeta.signalOption.onlyFor === "restapi") {
|
|
69
|
+
const [modelRef, arrDepth] = getNonArrayModel(uploadArgMeta.returns());
|
|
70
|
+
if (modelRef.prototype !== Upload.prototype)
|
|
71
|
+
throw new Error("Upload must be Upload");
|
|
72
|
+
else if (!arrDepth)
|
|
73
|
+
throw new Error(`Only Array of Upload is allowed - ${sigMeta.refName}/${gqlMeta.key}`);
|
|
74
|
+
UseInterceptors(FilesInterceptor(uploadArgMeta.name))(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
75
|
+
UploadedFiles(MulterToUploadPipe)(Ctrl.prototype, gqlMeta.key, uploadArgMeta.idx);
|
|
76
|
+
}
|
|
77
|
+
const queryArgMetas = argMetas.filter((argMeta) => argMeta.type === "Query");
|
|
78
|
+
queryArgMetas.forEach((argMeta) => {
|
|
79
|
+
const [modelRef, arrDepth] = getNonArrayModel(argMeta.returns());
|
|
80
|
+
Query(argMeta.name, ...getQueryPipes(modelRef, arrDepth))(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
81
|
+
});
|
|
82
|
+
const paramArgMetas = argMetas.filter((argMeta) => argMeta.type === "Param");
|
|
83
|
+
paramArgMetas.forEach((argMeta) => {
|
|
84
|
+
Param(argMeta.name)(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
85
|
+
});
|
|
86
|
+
const path = getControllerPath(gqlMeta, paramArgMetas);
|
|
87
|
+
const bodyArgMetas = argMetas.filter((argMeta) => argMeta.type === "Body");
|
|
88
|
+
if (bodyArgMetas.length)
|
|
89
|
+
bodyArgMetas.forEach((argMeta) => {
|
|
90
|
+
Body(argMeta.name, ...getBodyPipes(argMeta))(Ctrl.prototype, gqlMeta.key, argMeta.idx);
|
|
91
|
+
});
|
|
92
|
+
UseGuards(
|
|
93
|
+
...gqlMeta.guards.map((guard) => guards[guard]),
|
|
94
|
+
...gqlMeta.signalOption.sso ? [AuthGuard(gqlMeta.signalOption.sso)] : []
|
|
95
|
+
)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
96
|
+
if (gqlMeta.type === "Query")
|
|
97
|
+
Get(path)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
98
|
+
else if (gqlMeta.type === "Mutation")
|
|
99
|
+
Post(path)(Ctrl.prototype, gqlMeta.key, gqlMeta.descriptor);
|
|
100
|
+
}
|
|
101
|
+
if (prefix)
|
|
102
|
+
Controller(prefix)(Ctrl);
|
|
103
|
+
else
|
|
104
|
+
Controller()(Ctrl);
|
|
105
|
+
return Ctrl;
|
|
106
|
+
};
|
|
107
|
+
export {
|
|
108
|
+
controllerOf
|
|
109
|
+
};
|
package/src/gql.js
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
3
28
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
29
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
30
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -9,34 +34,37 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
9
34
|
__defProp(target, key, result);
|
|
10
35
|
return result;
|
|
11
36
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
37
|
+
var gql_exports = {};
|
|
38
|
+
__export(gql_exports, {
|
|
39
|
+
DateScalar: () => DateScalar,
|
|
40
|
+
applyNestField: () => applyNestField,
|
|
41
|
+
generateGql: () => generateGql,
|
|
42
|
+
generateGqlInput: () => generateGqlInput
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(gql_exports);
|
|
45
|
+
var import_base = require("@akanjs/base");
|
|
46
|
+
var import_constant = require("@akanjs/constant");
|
|
47
|
+
var Nest = __toESM(require("@nestjs/graphql"));
|
|
48
|
+
var import_graphql = require("@nestjs/graphql");
|
|
49
|
+
var import_dayjs = require("dayjs");
|
|
50
|
+
var import_graphql2 = require("graphql");
|
|
51
|
+
var import_graphql_type_json = __toESM(require("graphql-type-json"));
|
|
24
52
|
let DateScalar = class {
|
|
25
53
|
description = "Date custom scalar type";
|
|
26
54
|
parseValue(value) {
|
|
27
|
-
return dayjs(value);
|
|
55
|
+
return (0, import_base.dayjs)(value);
|
|
28
56
|
}
|
|
29
57
|
serialize(value) {
|
|
30
|
-
if (isDayjs(value))
|
|
58
|
+
if ((0, import_dayjs.isDayjs)(value))
|
|
31
59
|
return value.toDate();
|
|
32
60
|
else
|
|
33
61
|
return new Date(value);
|
|
34
62
|
}
|
|
35
63
|
parseLiteral(ast) {
|
|
36
|
-
if (ast.kind === Kind.INT)
|
|
37
|
-
return dayjs(ast.value);
|
|
38
|
-
else if (ast.kind === Kind.STRING)
|
|
39
|
-
return dayjs(ast.value);
|
|
64
|
+
if (ast.kind === import_graphql2.Kind.INT)
|
|
65
|
+
return (0, import_base.dayjs)(ast.value);
|
|
66
|
+
else if (ast.kind === import_graphql2.Kind.STRING)
|
|
67
|
+
return (0, import_base.dayjs)(ast.value);
|
|
40
68
|
else
|
|
41
69
|
return null;
|
|
42
70
|
}
|
|
@@ -63,61 +91,62 @@ const setPredefinedObjectGql = (refName, objectGql) => {
|
|
|
63
91
|
Reflect.defineMetadata(refName, objectGql, ObjectGqlStorage.prototype);
|
|
64
92
|
};
|
|
65
93
|
const gqlNestFieldMap = /* @__PURE__ */ new Map([
|
|
66
|
-
[ID, Nest.ID],
|
|
67
|
-
[Int, Nest.Int],
|
|
68
|
-
[Float, Nest.Float],
|
|
69
|
-
[JSON,
|
|
70
|
-
[Map,
|
|
94
|
+
[import_base.ID, Nest.ID],
|
|
95
|
+
[import_base.Int, Nest.Int],
|
|
96
|
+
[import_base.Float, Nest.Float],
|
|
97
|
+
[import_base.JSON, import_graphql_type_json.default],
|
|
98
|
+
[Map, import_graphql_type_json.default]
|
|
71
99
|
]);
|
|
72
100
|
const applyNestField = (model, fieldMeta, type = "object") => {
|
|
73
101
|
if (fieldMeta.fieldType === "hidden" && type === "object")
|
|
74
102
|
return;
|
|
75
103
|
const modelRef = fieldMeta.isClass ? type === "object" ? generateGql(fieldMeta.modelRef) : fieldMeta.isScalar ? generateGqlInput(fieldMeta.modelRef) : Nest.ID : gqlNestFieldMap.get(fieldMeta.modelRef) ?? fieldMeta.modelRef;
|
|
76
|
-
Field(() => arraiedModel(modelRef, fieldMeta.arrDepth), { nullable: fieldMeta.nullable })(
|
|
104
|
+
(0, import_graphql.Field)(() => (0, import_base.arraiedModel)(modelRef, fieldMeta.arrDepth), { nullable: fieldMeta.nullable })(
|
|
77
105
|
model.prototype,
|
|
78
106
|
fieldMeta.key
|
|
79
107
|
);
|
|
80
108
|
};
|
|
81
109
|
const generateGqlInput = (inputRef) => {
|
|
82
|
-
const classMeta = getClassMeta(inputRef);
|
|
110
|
+
const classMeta = (0, import_constant.getClassMeta)(inputRef);
|
|
83
111
|
const predefinedInputGql = getPredefinedInqutGql(classMeta.refName);
|
|
84
112
|
if (predefinedInputGql)
|
|
85
113
|
return predefinedInputGql;
|
|
86
|
-
const fieldMetas = getFieldMetas(inputRef);
|
|
114
|
+
const fieldMetas = (0, import_constant.getFieldMetas)(inputRef);
|
|
87
115
|
class InputGql {
|
|
88
116
|
}
|
|
89
|
-
const inputGql = classMeta.type === "scalar" ? InputGql : getInputModelRef(classMeta.refName);
|
|
117
|
+
const inputGql = classMeta.type === "scalar" ? InputGql : (0, import_constant.getInputModelRef)(classMeta.refName);
|
|
90
118
|
fieldMetas.forEach((fieldMeta) => {
|
|
91
119
|
applyNestField(inputGql, fieldMeta, "input");
|
|
92
120
|
});
|
|
93
|
-
InputType(classMeta.refName + (classMeta.type === "scalar" ? "Input" : ""))(inputGql);
|
|
121
|
+
(0, import_graphql.InputType)(classMeta.refName + (classMeta.type === "scalar" ? "Input" : ""))(inputGql);
|
|
94
122
|
setPredefinedInqutGql(classMeta.refName, inputGql);
|
|
95
123
|
return inputGql;
|
|
96
124
|
};
|
|
97
125
|
const generateGql = (objectRef) => {
|
|
98
|
-
const classMeta = getClassMeta(objectRef);
|
|
126
|
+
const classMeta = (0, import_constant.getClassMeta)(objectRef);
|
|
99
127
|
if (classMeta.type === "light") {
|
|
100
128
|
const fullModelRefName = classMeta.refName.slice(5);
|
|
101
|
-
const fullModelRef = getFullModelRef(fullModelRefName);
|
|
129
|
+
const fullModelRef = (0, import_constant.getFullModelRef)(fullModelRefName);
|
|
102
130
|
return generateGql(fullModelRef);
|
|
103
131
|
}
|
|
104
132
|
const predefinedObjectGql = getPredefinedObjectGql(classMeta.refName);
|
|
105
133
|
if (predefinedObjectGql)
|
|
106
134
|
return predefinedObjectGql;
|
|
107
|
-
const fieldMetas = getFieldMetas(objectRef);
|
|
135
|
+
const fieldMetas = (0, import_constant.getFieldMetas)(objectRef);
|
|
108
136
|
class ObjectGql {
|
|
109
137
|
}
|
|
110
|
-
const objectGql = classMeta.type === "scalar" ? ObjectGql : getFullModelRef(classMeta.refName);
|
|
138
|
+
const objectGql = classMeta.type === "scalar" ? ObjectGql : (0, import_constant.getFullModelRef)(classMeta.refName);
|
|
111
139
|
fieldMetas.forEach((fieldMeta) => {
|
|
112
140
|
applyNestField(objectGql, fieldMeta);
|
|
113
141
|
});
|
|
114
|
-
ObjectType(classMeta.refName)(objectGql);
|
|
142
|
+
(0, import_graphql.ObjectType)(classMeta.refName)(objectGql);
|
|
115
143
|
setPredefinedObjectGql(classMeta.refName, objectGql);
|
|
116
144
|
return objectGql;
|
|
117
145
|
};
|
|
118
|
-
export
|
|
146
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
147
|
+
0 && (module.exports = {
|
|
119
148
|
DateScalar,
|
|
120
149
|
applyNestField,
|
|
121
150
|
generateGql,
|
|
122
151
|
generateGqlInput
|
|
123
|
-
};
|
|
152
|
+
});
|
package/src/gql.mjs
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import { arraiedModel, dayjs, Float, ID, Int, JSON } from "@akanjs/base";
|
|
13
|
+
import {
|
|
14
|
+
getClassMeta,
|
|
15
|
+
getFieldMetas,
|
|
16
|
+
getFullModelRef,
|
|
17
|
+
getInputModelRef
|
|
18
|
+
} from "@akanjs/constant";
|
|
19
|
+
import * as Nest from "@nestjs/graphql";
|
|
20
|
+
import { Field, InputType, ObjectType } from "@nestjs/graphql";
|
|
21
|
+
import { isDayjs } from "dayjs";
|
|
22
|
+
import { Kind } from "graphql";
|
|
23
|
+
import { default as GraphQLJSON } from "graphql-type-json";
|
|
24
|
+
let DateScalar = class {
|
|
25
|
+
description = "Date custom scalar type";
|
|
26
|
+
parseValue(value) {
|
|
27
|
+
return dayjs(value);
|
|
28
|
+
}
|
|
29
|
+
serialize(value) {
|
|
30
|
+
if (isDayjs(value))
|
|
31
|
+
return value.toDate();
|
|
32
|
+
else
|
|
33
|
+
return new Date(value);
|
|
34
|
+
}
|
|
35
|
+
parseLiteral(ast) {
|
|
36
|
+
if (ast.kind === Kind.INT)
|
|
37
|
+
return dayjs(ast.value);
|
|
38
|
+
else if (ast.kind === Kind.STRING)
|
|
39
|
+
return dayjs(ast.value);
|
|
40
|
+
else
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
DateScalar = __decorateClass([
|
|
45
|
+
Nest.Scalar("Date", () => Date)
|
|
46
|
+
], DateScalar);
|
|
47
|
+
class ObjectGqlStorage {
|
|
48
|
+
}
|
|
49
|
+
class InputGqlStorage {
|
|
50
|
+
}
|
|
51
|
+
const getPredefinedInqutGql = (refName) => {
|
|
52
|
+
const inputGql = Reflect.getMetadata(refName, InputGqlStorage.prototype);
|
|
53
|
+
return inputGql;
|
|
54
|
+
};
|
|
55
|
+
const setPredefinedInqutGql = (refName, inputGql) => {
|
|
56
|
+
Reflect.defineMetadata(refName, inputGql, InputGqlStorage.prototype);
|
|
57
|
+
};
|
|
58
|
+
const getPredefinedObjectGql = (refName) => {
|
|
59
|
+
const objectGql = Reflect.getMetadata(refName, ObjectGqlStorage.prototype);
|
|
60
|
+
return objectGql;
|
|
61
|
+
};
|
|
62
|
+
const setPredefinedObjectGql = (refName, objectGql) => {
|
|
63
|
+
Reflect.defineMetadata(refName, objectGql, ObjectGqlStorage.prototype);
|
|
64
|
+
};
|
|
65
|
+
const gqlNestFieldMap = /* @__PURE__ */ new Map([
|
|
66
|
+
[ID, Nest.ID],
|
|
67
|
+
[Int, Nest.Int],
|
|
68
|
+
[Float, Nest.Float],
|
|
69
|
+
[JSON, GraphQLJSON],
|
|
70
|
+
[Map, GraphQLJSON]
|
|
71
|
+
]);
|
|
72
|
+
const applyNestField = (model, fieldMeta, type = "object") => {
|
|
73
|
+
if (fieldMeta.fieldType === "hidden" && type === "object")
|
|
74
|
+
return;
|
|
75
|
+
const modelRef = fieldMeta.isClass ? type === "object" ? generateGql(fieldMeta.modelRef) : fieldMeta.isScalar ? generateGqlInput(fieldMeta.modelRef) : Nest.ID : gqlNestFieldMap.get(fieldMeta.modelRef) ?? fieldMeta.modelRef;
|
|
76
|
+
Field(() => arraiedModel(modelRef, fieldMeta.arrDepth), { nullable: fieldMeta.nullable })(
|
|
77
|
+
model.prototype,
|
|
78
|
+
fieldMeta.key
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
const generateGqlInput = (inputRef) => {
|
|
82
|
+
const classMeta = getClassMeta(inputRef);
|
|
83
|
+
const predefinedInputGql = getPredefinedInqutGql(classMeta.refName);
|
|
84
|
+
if (predefinedInputGql)
|
|
85
|
+
return predefinedInputGql;
|
|
86
|
+
const fieldMetas = getFieldMetas(inputRef);
|
|
87
|
+
class InputGql {
|
|
88
|
+
}
|
|
89
|
+
const inputGql = classMeta.type === "scalar" ? InputGql : getInputModelRef(classMeta.refName);
|
|
90
|
+
fieldMetas.forEach((fieldMeta) => {
|
|
91
|
+
applyNestField(inputGql, fieldMeta, "input");
|
|
92
|
+
});
|
|
93
|
+
InputType(classMeta.refName + (classMeta.type === "scalar" ? "Input" : ""))(inputGql);
|
|
94
|
+
setPredefinedInqutGql(classMeta.refName, inputGql);
|
|
95
|
+
return inputGql;
|
|
96
|
+
};
|
|
97
|
+
const generateGql = (objectRef) => {
|
|
98
|
+
const classMeta = getClassMeta(objectRef);
|
|
99
|
+
if (classMeta.type === "light") {
|
|
100
|
+
const fullModelRefName = classMeta.refName.slice(5);
|
|
101
|
+
const fullModelRef = getFullModelRef(fullModelRefName);
|
|
102
|
+
return generateGql(fullModelRef);
|
|
103
|
+
}
|
|
104
|
+
const predefinedObjectGql = getPredefinedObjectGql(classMeta.refName);
|
|
105
|
+
if (predefinedObjectGql)
|
|
106
|
+
return predefinedObjectGql;
|
|
107
|
+
const fieldMetas = getFieldMetas(objectRef);
|
|
108
|
+
class ObjectGql {
|
|
109
|
+
}
|
|
110
|
+
const objectGql = classMeta.type === "scalar" ? ObjectGql : getFullModelRef(classMeta.refName);
|
|
111
|
+
fieldMetas.forEach((fieldMeta) => {
|
|
112
|
+
applyNestField(objectGql, fieldMeta);
|
|
113
|
+
});
|
|
114
|
+
ObjectType(classMeta.refName)(objectGql);
|
|
115
|
+
setPredefinedObjectGql(classMeta.refName, objectGql);
|
|
116
|
+
return objectGql;
|
|
117
|
+
};
|
|
118
|
+
export {
|
|
119
|
+
DateScalar,
|
|
120
|
+
applyNestField,
|
|
121
|
+
generateGql,
|
|
122
|
+
generateGqlInput
|
|
123
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,10 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var src_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(src_exports);
|
|
17
|
+
__reExport(src_exports, require("./gql"), module.exports);
|
|
18
|
+
__reExport(src_exports, require("./resolver"), module.exports);
|
|
19
|
+
__reExport(src_exports, require("./controller"), module.exports);
|
|
20
|
+
__reExport(src_exports, require("./processor"), module.exports);
|
|
21
|
+
__reExport(src_exports, require("./module"), module.exports);
|
|
22
|
+
__reExport(src_exports, require("./types"), module.exports);
|
|
23
|
+
__reExport(src_exports, require("./websocket"), module.exports);
|
|
24
|
+
__reExport(src_exports, require("./boot"), module.exports);
|
|
25
|
+
__reExport(src_exports, require("./searchDaemon"), module.exports);
|
|
26
|
+
__reExport(src_exports, require("./schema"), module.exports);
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
...require("./gql"),
|
|
30
|
+
...require("./resolver"),
|
|
31
|
+
...require("./controller"),
|
|
32
|
+
...require("./processor"),
|
|
33
|
+
...require("./module"),
|
|
34
|
+
...require("./types"),
|
|
35
|
+
...require("./websocket"),
|
|
36
|
+
...require("./boot"),
|
|
37
|
+
...require("./searchDaemon"),
|
|
38
|
+
...require("./schema")
|
|
39
|
+
});
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./gql";
|
|
2
|
+
export * from "./resolver";
|
|
3
|
+
export * from "./controller";
|
|
4
|
+
export * from "./processor";
|
|
5
|
+
export * from "./module";
|
|
6
|
+
export * from "./types";
|
|
7
|
+
export * from "./websocket";
|
|
8
|
+
export * from "./boot";
|
|
9
|
+
export * from "./searchDaemon";
|
|
10
|
+
export * from "./schema";
|