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