@akanjs/server 0.0.4
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/README.md +11 -0
- package/index.d.ts +1 -0
- package/index.js +21 -0
- package/package.json +68 -0
- package/src/boot.d.ts +18 -0
- package/src/boot.js +200 -0
- package/src/controller.d.ts +6 -0
- package/src/controller.js +99 -0
- package/src/dataLoader.d.ts +26 -0
- package/src/dataLoader.js +152 -0
- package/src/database.d.ts +114 -0
- package/src/database.js +312 -0
- package/src/dbDecorators.d.ts +68 -0
- package/src/dbDecorators.js +130 -0
- package/src/gql.d.ts +14 -0
- package/src/gql.js +152 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +47 -0
- package/src/module.d.ts +72 -0
- package/src/module.js +217 -0
- package/src/processor.d.ts +8 -0
- package/src/processor.js +89 -0
- package/src/resolver.d.ts +6 -0
- package/src/resolver.js +142 -0
- package/src/schema.d.ts +33 -0
- package/src/schema.js +343 -0
- package/src/searchDaemon.d.ts +7 -0
- package/src/searchDaemon.js +228 -0
- package/src/serviceDecorators.d.ts +178 -0
- package/src/serviceDecorators.js +491 -0
- package/src/types.d.ts +14 -0
- package/src/types.js +15 -0
- package/src/websocket.d.ts +17 -0
- package/src/websocket.js +143 -0
package/src/gql.js
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"));
|
|
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"));
|
|
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/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./dataLoader";
|
|
2
|
+
export * from "./serviceDecorators";
|
|
3
|
+
export * from "./gql";
|
|
4
|
+
export * from "./resolver";
|
|
5
|
+
export * from "./schema";
|
|
6
|
+
export * from "./controller";
|
|
7
|
+
export * from "./processor";
|
|
8
|
+
export * from "./module";
|
|
9
|
+
export * from "./database";
|
|
10
|
+
export * from "./dbDecorators";
|
|
11
|
+
export * from "./types";
|
|
12
|
+
export * from "./websocket";
|
|
13
|
+
export * from "./boot";
|
|
14
|
+
export * from "./searchDaemon";
|
package/src/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
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("./dataLoader"), module.exports);
|
|
18
|
+
__reExport(src_exports, require("./serviceDecorators"), module.exports);
|
|
19
|
+
__reExport(src_exports, require("./gql"), module.exports);
|
|
20
|
+
__reExport(src_exports, require("./resolver"), module.exports);
|
|
21
|
+
__reExport(src_exports, require("./schema"), module.exports);
|
|
22
|
+
__reExport(src_exports, require("./controller"), module.exports);
|
|
23
|
+
__reExport(src_exports, require("./processor"), module.exports);
|
|
24
|
+
__reExport(src_exports, require("./module"), module.exports);
|
|
25
|
+
__reExport(src_exports, require("./database"), module.exports);
|
|
26
|
+
__reExport(src_exports, require("./dbDecorators"), module.exports);
|
|
27
|
+
__reExport(src_exports, require("./types"), module.exports);
|
|
28
|
+
__reExport(src_exports, require("./websocket"), module.exports);
|
|
29
|
+
__reExport(src_exports, require("./boot"), module.exports);
|
|
30
|
+
__reExport(src_exports, require("./searchDaemon"), module.exports);
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
...require("./dataLoader"),
|
|
34
|
+
...require("./serviceDecorators"),
|
|
35
|
+
...require("./gql"),
|
|
36
|
+
...require("./resolver"),
|
|
37
|
+
...require("./schema"),
|
|
38
|
+
...require("./controller"),
|
|
39
|
+
...require("./processor"),
|
|
40
|
+
...require("./module"),
|
|
41
|
+
...require("./database"),
|
|
42
|
+
...require("./dbDecorators"),
|
|
43
|
+
...require("./types"),
|
|
44
|
+
...require("./websocket"),
|
|
45
|
+
...require("./boot"),
|
|
46
|
+
...require("./searchDaemon")
|
|
47
|
+
});
|
package/src/module.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Type } from "@akanjs/base";
|
|
2
|
+
import { type ConstantModel } from "@akanjs/constant";
|
|
3
|
+
import { DynamicModule } from "@nestjs/common";
|
|
4
|
+
import type { Database } from "./dbDecorators";
|
|
5
|
+
interface DatabaseModuleCreateOptions {
|
|
6
|
+
constant: ConstantModel<string, any, any, any, any, any>;
|
|
7
|
+
database: Database<string, any, any, any, any, any, any, any, any>;
|
|
8
|
+
signal: Type;
|
|
9
|
+
service: Type;
|
|
10
|
+
uses?: {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
};
|
|
13
|
+
useAsyncs?: {
|
|
14
|
+
[key: string]: () => Promise<any>;
|
|
15
|
+
};
|
|
16
|
+
providers?: Type[];
|
|
17
|
+
extended?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare const databaseModuleOf: ({ constant, database, signal, service, uses, useAsyncs, providers, extended, }: DatabaseModuleCreateOptions, allSrvs: {
|
|
20
|
+
[key: string]: Type | undefined;
|
|
21
|
+
}) => DynamicModule;
|
|
22
|
+
interface ServiceModuleCreateOptions {
|
|
23
|
+
signal: Type;
|
|
24
|
+
service: Type;
|
|
25
|
+
uses?: {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
};
|
|
28
|
+
useAsyncs?: {
|
|
29
|
+
[key: string]: () => Promise<any>;
|
|
30
|
+
};
|
|
31
|
+
providers?: Type[];
|
|
32
|
+
}
|
|
33
|
+
export declare const serviceModuleOf: ({ signal, service, uses, useAsyncs, providers }: ServiceModuleCreateOptions, allSrvs: {
|
|
34
|
+
[key: string]: Type | undefined;
|
|
35
|
+
}) => DynamicModule;
|
|
36
|
+
interface ScalarModuleCreateOptions {
|
|
37
|
+
signals: Type[];
|
|
38
|
+
uses?: {
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
};
|
|
41
|
+
useAsyncs?: {
|
|
42
|
+
[key: string]: () => Promise<any>;
|
|
43
|
+
};
|
|
44
|
+
providers?: Type[];
|
|
45
|
+
}
|
|
46
|
+
export declare const scalarModuleOf: ({ signals, uses, useAsyncs, providers }: ScalarModuleCreateOptions, allSrvs: {
|
|
47
|
+
[key: string]: Type | undefined;
|
|
48
|
+
}) => DynamicModule;
|
|
49
|
+
interface BatchModuleCreateOptions {
|
|
50
|
+
service: Type;
|
|
51
|
+
uses?: {
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
};
|
|
54
|
+
useAsyncs?: {
|
|
55
|
+
[key: string]: () => Promise<any>;
|
|
56
|
+
};
|
|
57
|
+
providers?: Type[];
|
|
58
|
+
}
|
|
59
|
+
export declare const batchModuleOf: ({ service, uses, useAsyncs, providers, }: BatchModuleCreateOptions) => DynamicModule;
|
|
60
|
+
interface UseGlobalsCreateOptions {
|
|
61
|
+
uses?: {
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
};
|
|
64
|
+
useAsyncs?: {
|
|
65
|
+
[key: string]: () => Promise<any>;
|
|
66
|
+
};
|
|
67
|
+
injects?: {
|
|
68
|
+
[key: string]: Type;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export declare const useGlobals: ({ uses, useAsyncs, injects }: UseGlobalsCreateOptions) => DynamicModule;
|
|
72
|
+
export {};
|
package/src/module.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
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 __decorateClass = (decorators, target, key, kind) => {
|
|
19
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
20
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
21
|
+
if (decorator = decorators[i])
|
|
22
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
23
|
+
if (kind && result)
|
|
24
|
+
__defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var module_exports = {};
|
|
28
|
+
__export(module_exports, {
|
|
29
|
+
batchModuleOf: () => batchModuleOf,
|
|
30
|
+
databaseModuleOf: () => databaseModuleOf,
|
|
31
|
+
scalarModuleOf: () => scalarModuleOf,
|
|
32
|
+
serviceModuleOf: () => serviceModuleOf,
|
|
33
|
+
useGlobals: () => useGlobals
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(module_exports);
|
|
36
|
+
var import_common = require("@akanjs/common");
|
|
37
|
+
var import_signal = require("@akanjs/signal");
|
|
38
|
+
var import_bull = require("@nestjs/bull");
|
|
39
|
+
var import_common2 = require("@nestjs/common");
|
|
40
|
+
var import_mongoose = require("@nestjs/mongoose");
|
|
41
|
+
var import_controller = require("./controller");
|
|
42
|
+
var import_database = require("./database");
|
|
43
|
+
var import_processor = require("./processor");
|
|
44
|
+
var import_resolver = require("./resolver");
|
|
45
|
+
var import_schema = require("./schema");
|
|
46
|
+
var import_serviceDecorators = require("./serviceDecorators");
|
|
47
|
+
var import_websocket = require("./websocket");
|
|
48
|
+
const hasWebsocket = (signal) => (0, import_signal.getGqlMetas)(signal).some((gqlMeta) => ["Message", "Pubsub"].includes(gqlMeta.type));
|
|
49
|
+
const hasProcessor = (signal) => (0, import_signal.getGqlMetas)(signal).some((gqlMeta) => gqlMeta.type === "Process");
|
|
50
|
+
const filterSrvs = (srvs) => Object.fromEntries(Object.entries(srvs).filter(([_, srv]) => !!srv));
|
|
51
|
+
const databaseModuleOf = ({
|
|
52
|
+
constant,
|
|
53
|
+
database,
|
|
54
|
+
signal,
|
|
55
|
+
service,
|
|
56
|
+
uses = {},
|
|
57
|
+
useAsyncs = {},
|
|
58
|
+
providers = [],
|
|
59
|
+
extended
|
|
60
|
+
}, allSrvs) => {
|
|
61
|
+
const [modelName, className] = [(0, import_common.lowerlize)(constant.refName), (0, import_common.capitalize)(constant.refName)];
|
|
62
|
+
const mongoToken = (0, import_mongoose.getModelToken)(className);
|
|
63
|
+
let DatabaseModule = class {
|
|
64
|
+
};
|
|
65
|
+
DatabaseModule = __decorateClass([
|
|
66
|
+
(0, import_common2.Global)(),
|
|
67
|
+
(0, import_common2.Module)({
|
|
68
|
+
imports: [
|
|
69
|
+
import_mongoose.MongooseModule.forFeature([
|
|
70
|
+
{
|
|
71
|
+
name: className,
|
|
72
|
+
schema: extended ? (0, import_schema.addSchema)(database.Model, database.Doc, database.Input, database.Middleware) : (0, import_schema.schemaOf)(database.Model, database.Doc, database.Middleware)
|
|
73
|
+
}
|
|
74
|
+
]),
|
|
75
|
+
...hasProcessor(signal) ? [
|
|
76
|
+
import_bull.BullModule.registerQueue({
|
|
77
|
+
name: modelName,
|
|
78
|
+
defaultJobOptions: { removeOnComplete: true, removeOnFail: true }
|
|
79
|
+
})
|
|
80
|
+
] : []
|
|
81
|
+
],
|
|
82
|
+
providers: [
|
|
83
|
+
(0, import_serviceDecorators.serviceOf)(service),
|
|
84
|
+
(0, import_resolver.resolverOf)(signal, filterSrvs(allSrvs)),
|
|
85
|
+
...hasProcessor(signal) ? [
|
|
86
|
+
(0, import_processor.processorOf)(signal, filterSrvs(allSrvs)),
|
|
87
|
+
{ provide: `${className}Queue`, useFactory: (queue) => queue, inject: [(0, import_bull.getQueueToken)(modelName)] }
|
|
88
|
+
] : [],
|
|
89
|
+
...hasWebsocket(signal) ? [(0, import_websocket.websocketOf)(signal, filterSrvs(allSrvs)), { provide: "Websocket", useClass: (0, import_websocket.websocketServerOf)(signal) }] : [],
|
|
90
|
+
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common.capitalize)(key), useValue })),
|
|
91
|
+
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common.capitalize)(key), useFactory })),
|
|
92
|
+
{
|
|
93
|
+
provide: `${modelName}Model`,
|
|
94
|
+
useFactory: (model, redis, meili) => {
|
|
95
|
+
return (0, import_database.databaseModelOf)(database, model, redis, meili);
|
|
96
|
+
},
|
|
97
|
+
inject: [mongoToken, "REDIS_CLIENT", "MEILI_CLIENT"]
|
|
98
|
+
},
|
|
99
|
+
...providers
|
|
100
|
+
],
|
|
101
|
+
controllers: [(0, import_controller.controllerOf)(signal, filterSrvs(allSrvs))],
|
|
102
|
+
exports: [service]
|
|
103
|
+
})
|
|
104
|
+
], DatabaseModule);
|
|
105
|
+
return DatabaseModule;
|
|
106
|
+
};
|
|
107
|
+
const serviceModuleOf = ({ signal, service, uses = {}, useAsyncs = {}, providers = [] }, allSrvs) => {
|
|
108
|
+
const sigMeta = (0, import_signal.getSigMeta)(signal);
|
|
109
|
+
const [modelName, className] = [(0, import_common.lowerlize)(sigMeta.refName), (0, import_common.capitalize)(sigMeta.refName)];
|
|
110
|
+
let ServiceModule = class {
|
|
111
|
+
};
|
|
112
|
+
ServiceModule = __decorateClass([
|
|
113
|
+
(0, import_common2.Global)(),
|
|
114
|
+
(0, import_common2.Module)({
|
|
115
|
+
imports: [
|
|
116
|
+
...hasProcessor(signal) ? [
|
|
117
|
+
import_bull.BullModule.registerQueue({
|
|
118
|
+
name: modelName,
|
|
119
|
+
defaultJobOptions: { removeOnComplete: true, removeOnFail: true }
|
|
120
|
+
})
|
|
121
|
+
] : []
|
|
122
|
+
],
|
|
123
|
+
providers: [
|
|
124
|
+
(0, import_serviceDecorators.serviceOf)(service),
|
|
125
|
+
(0, import_resolver.resolverOf)(signal, filterSrvs(allSrvs)),
|
|
126
|
+
...hasWebsocket(signal) ? [(0, import_websocket.websocketOf)(signal, filterSrvs(allSrvs)), { provide: "Websocket", useClass: (0, import_websocket.websocketServerOf)(signal) }] : [],
|
|
127
|
+
...hasProcessor(signal) ? [
|
|
128
|
+
(0, import_processor.processorOf)(signal, filterSrvs(allSrvs)),
|
|
129
|
+
{ provide: `${className}Queue`, useFactory: (queue) => queue, inject: [(0, import_bull.getQueueToken)(modelName)] }
|
|
130
|
+
] : [],
|
|
131
|
+
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common.capitalize)(key), useValue })),
|
|
132
|
+
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common.capitalize)(key), useFactory })),
|
|
133
|
+
...providers
|
|
134
|
+
],
|
|
135
|
+
controllers: [(0, import_controller.controllerOf)(signal, filterSrvs(allSrvs))],
|
|
136
|
+
exports: [service]
|
|
137
|
+
})
|
|
138
|
+
], ServiceModule);
|
|
139
|
+
return ServiceModule;
|
|
140
|
+
};
|
|
141
|
+
const scalarModuleOf = ({ signals, uses = {}, useAsyncs = {}, providers = [] }, allSrvs) => {
|
|
142
|
+
let ScalarModule = class {
|
|
143
|
+
};
|
|
144
|
+
ScalarModule = __decorateClass([
|
|
145
|
+
(0, import_common2.Global)(),
|
|
146
|
+
(0, import_common2.Module)({
|
|
147
|
+
imports: [],
|
|
148
|
+
providers: [
|
|
149
|
+
...signals.map((signal) => (0, import_resolver.resolverOf)(signal, filterSrvs(allSrvs))),
|
|
150
|
+
...signals.filter(hasWebsocket).map((signal) => [
|
|
151
|
+
(0, import_websocket.websocketOf)(signal, filterSrvs(allSrvs)),
|
|
152
|
+
{ provide: "Websocket", useClass: (0, import_websocket.websocketServerOf)(signal) }
|
|
153
|
+
]).flat(),
|
|
154
|
+
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common.capitalize)(key), useValue })),
|
|
155
|
+
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common.capitalize)(key), useFactory })),
|
|
156
|
+
...providers
|
|
157
|
+
],
|
|
158
|
+
controllers: signals.map((signal) => (0, import_controller.controllerOf)(signal, filterSrvs(allSrvs)))
|
|
159
|
+
})
|
|
160
|
+
], ScalarModule);
|
|
161
|
+
return ScalarModule;
|
|
162
|
+
};
|
|
163
|
+
const batchModuleOf = ({
|
|
164
|
+
service,
|
|
165
|
+
uses = {},
|
|
166
|
+
useAsyncs = {},
|
|
167
|
+
providers = []
|
|
168
|
+
}) => {
|
|
169
|
+
let BatchModule = class {
|
|
170
|
+
};
|
|
171
|
+
BatchModule = __decorateClass([
|
|
172
|
+
(0, import_common2.Global)(),
|
|
173
|
+
(0, import_common2.Module)({
|
|
174
|
+
imports: [],
|
|
175
|
+
providers: [
|
|
176
|
+
(0, import_serviceDecorators.serviceOf)(service),
|
|
177
|
+
...Object.entries(uses).map(([key, useValue]) => ({ provide: (0, import_common.capitalize)(key), useValue })),
|
|
178
|
+
...Object.entries(useAsyncs).map(([key, useFactory]) => ({ provide: (0, import_common.capitalize)(key), useFactory })),
|
|
179
|
+
...providers
|
|
180
|
+
],
|
|
181
|
+
exports: [service]
|
|
182
|
+
})
|
|
183
|
+
], BatchModule);
|
|
184
|
+
return BatchModule;
|
|
185
|
+
};
|
|
186
|
+
const useGlobals = ({ uses, useAsyncs, injects }) => {
|
|
187
|
+
let GlobalsModule = class {
|
|
188
|
+
};
|
|
189
|
+
GlobalsModule = __decorateClass([
|
|
190
|
+
(0, import_common2.Global)(),
|
|
191
|
+
(0, import_common2.Module)({
|
|
192
|
+
imports: [],
|
|
193
|
+
providers: [
|
|
194
|
+
...Object.entries(uses ?? {}).map(([key, useValue]) => ({
|
|
195
|
+
provide: (0, import_common.capitalize)(key),
|
|
196
|
+
useValue
|
|
197
|
+
})),
|
|
198
|
+
...Object.entries(useAsyncs ?? {}).map(([key, useFactory]) => ({ provide: (0, import_common.capitalize)(key), useFactory })),
|
|
199
|
+
...Object.entries(injects ?? {}).map(([key, inject]) => ({ provide: (0, import_common.capitalize)(key), useClass: inject }))
|
|
200
|
+
],
|
|
201
|
+
exports: [
|
|
202
|
+
...Object.keys(uses ?? {}).map((key) => (0, import_common.capitalize)(key)),
|
|
203
|
+
...Object.keys(useAsyncs ?? {}).map((key) => (0, import_common.capitalize)(key)),
|
|
204
|
+
...Object.keys(injects ?? {}).map((key) => (0, import_common.capitalize)(key))
|
|
205
|
+
]
|
|
206
|
+
})
|
|
207
|
+
], GlobalsModule);
|
|
208
|
+
return GlobalsModule;
|
|
209
|
+
};
|
|
210
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
211
|
+
0 && (module.exports = {
|
|
212
|
+
batchModuleOf,
|
|
213
|
+
databaseModuleOf,
|
|
214
|
+
scalarModuleOf,
|
|
215
|
+
serviceModuleOf,
|
|
216
|
+
useGlobals
|
|
217
|
+
});
|
package/src/processor.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
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 processor_exports = {};
|
|
19
|
+
__export(processor_exports, {
|
|
20
|
+
processorOf: () => processorOf,
|
|
21
|
+
queueOf: () => queueOf
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(processor_exports);
|
|
24
|
+
var import_common = require("@akanjs/common");
|
|
25
|
+
var import_signal = require("@akanjs/signal");
|
|
26
|
+
var import_bull = require("@nestjs/bull");
|
|
27
|
+
var import_common2 = require("@nestjs/common");
|
|
28
|
+
const convertProcessFunction = (gqlMeta, argMetas, internalArgMetas, fn) => {
|
|
29
|
+
return async function(job, done) {
|
|
30
|
+
const args = [];
|
|
31
|
+
argMetas.forEach((argMeta) => {
|
|
32
|
+
if (argMeta.type === "Msg")
|
|
33
|
+
args[argMeta.idx] = (0, import_signal.deserializeArg)(argMeta, job.data[argMeta.idx]);
|
|
34
|
+
else
|
|
35
|
+
throw new Error(`Invalid ArgMeta Type ${argMeta.type}`);
|
|
36
|
+
});
|
|
37
|
+
internalArgMetas.forEach((internalArgMeta) => {
|
|
38
|
+
if (internalArgMeta.type === "Job")
|
|
39
|
+
args[internalArgMeta.idx] = job;
|
|
40
|
+
else
|
|
41
|
+
throw new Error(`Invalid InternalArgMeta Type ${internalArgMeta.type}`);
|
|
42
|
+
});
|
|
43
|
+
this.logger?.log(`Process-${gqlMeta.key} started`);
|
|
44
|
+
const result = await fn.apply(this, args);
|
|
45
|
+
this.logger?.log(`Process-${gqlMeta.key} finished`);
|
|
46
|
+
done(null, result);
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const processorOf = (sigRef, allSrvs) => {
|
|
50
|
+
const sigMeta = (0, import_signal.getSigMeta)(sigRef);
|
|
51
|
+
const serverMode = process.env.SERVER_MODE ?? "federation";
|
|
52
|
+
const gqlMetas = (0, import_signal.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Process").filter(
|
|
53
|
+
(gqlMeta) => gqlMeta.signalOption.serverType === "all" || serverMode === "all" || gqlMeta.signalOption.serverType === serverMode
|
|
54
|
+
);
|
|
55
|
+
class QueueProcessor {
|
|
56
|
+
}
|
|
57
|
+
Object.keys(allSrvs).forEach((srv) => {
|
|
58
|
+
(0, import_common2.Inject)(allSrvs[srv])(QueueProcessor.prototype, (0, import_common.lowerlize)(srv));
|
|
59
|
+
});
|
|
60
|
+
for (const gqlMeta of gqlMetas) {
|
|
61
|
+
const [argMetas, internalArgMetas] = (0, import_signal.getArgMetas)(sigRef, gqlMeta.key);
|
|
62
|
+
const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
|
|
63
|
+
descriptor.value = convertProcessFunction(
|
|
64
|
+
gqlMeta,
|
|
65
|
+
argMetas,
|
|
66
|
+
internalArgMetas,
|
|
67
|
+
descriptor.value
|
|
68
|
+
);
|
|
69
|
+
Object.defineProperty(QueueProcessor.prototype, gqlMeta.key, descriptor);
|
|
70
|
+
(0, import_bull.Process)(gqlMeta.key)(QueueProcessor.prototype, gqlMeta.key, descriptor);
|
|
71
|
+
}
|
|
72
|
+
(0, import_bull.Processor)(sigMeta.refName)(QueueProcessor);
|
|
73
|
+
return QueueProcessor;
|
|
74
|
+
};
|
|
75
|
+
const queueOf = (sigRef, queue) => {
|
|
76
|
+
const sigMeta = (0, import_signal.getSigMeta)(sigRef);
|
|
77
|
+
const gqlMetas = (0, import_signal.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Process");
|
|
78
|
+
for (const gqlMeta of gqlMetas) {
|
|
79
|
+
if (queue[gqlMeta.key])
|
|
80
|
+
throw new Error(`Queue already has ${gqlMeta.key} in ${sigMeta.refName}`);
|
|
81
|
+
queue[gqlMeta.key] = (...args) => queue.add(gqlMeta.key, args);
|
|
82
|
+
}
|
|
83
|
+
return queue;
|
|
84
|
+
};
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
processorOf,
|
|
88
|
+
queueOf
|
|
89
|
+
});
|