@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.
@@ -0,0 +1,85 @@
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 processor_exports = {};
20
+ __export(processor_exports, {
21
+ processorOf: () => processorOf,
22
+ queueOf: () => queueOf
23
+ });
24
+ module.exports = __toCommonJS(processor_exports);
25
+ var import_common = require("@akanjs/common");
26
+ var import_service = require("@akanjs/service");
27
+ var import_signal = require("@akanjs/signal");
28
+ var import_bull = require("@nestjs/bull");
29
+ var import_common2 = require("@nestjs/common");
30
+ const convertProcessFunction = /* @__PURE__ */ __name((gqlMeta, argMetas, internalArgMetas, fn) => {
31
+ return async function(job, done) {
32
+ const args = [];
33
+ argMetas.forEach((argMeta) => {
34
+ if (argMeta.type === "Msg") args[argMeta.idx] = (0, import_signal.deserializeArg)(argMeta, job.data[argMeta.idx]);
35
+ else throw new Error(`Invalid ArgMeta Type ${argMeta.type}`);
36
+ });
37
+ internalArgMetas.forEach((internalArgMeta) => {
38
+ if (internalArgMeta.type === "Job") args[internalArgMeta.idx] = job;
39
+ else throw new Error(`Invalid InternalArgMeta Type ${internalArgMeta.type}`);
40
+ });
41
+ this.logger?.log(`Process-${gqlMeta.key} started`);
42
+ const result = await fn.apply(this, args);
43
+ this.logger?.log(`Process-${gqlMeta.key} finished`);
44
+ done(null, result);
45
+ };
46
+ }, "convertProcessFunction");
47
+ const processorOf = /* @__PURE__ */ __name((sigRef, allSrvs) => {
48
+ const sigMeta = (0, import_signal.getSigMeta)(sigRef);
49
+ const serverMode = process.env.SERVER_MODE ?? "federation";
50
+ const gqlMetas = (0, import_signal.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Process").filter((gqlMeta) => gqlMeta.signalOption.serverType === "all" || serverMode === "all" || gqlMeta.signalOption.serverType === serverMode);
51
+ let QueueProcessor = class QueueProcessor {
52
+ static {
53
+ __name(this, "QueueProcessor");
54
+ }
55
+ };
56
+ Object.keys(allSrvs).forEach((srv) => {
57
+ if (!(0, import_service.isServiceEnabled)(allSrvs[srv])) return;
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 = {
63
+ ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {}
64
+ };
65
+ descriptor.value = convertProcessFunction(gqlMeta, argMetas, internalArgMetas, descriptor.value);
66
+ Object.defineProperty(QueueProcessor.prototype, gqlMeta.key, descriptor);
67
+ (0, import_bull.Process)(gqlMeta.key)(QueueProcessor.prototype, gqlMeta.key, descriptor);
68
+ }
69
+ (0, import_bull.Processor)(sigMeta.refName)(QueueProcessor);
70
+ return QueueProcessor;
71
+ }, "processorOf");
72
+ const queueOf = /* @__PURE__ */ __name((sigRef, queue) => {
73
+ const sigMeta = (0, import_signal.getSigMeta)(sigRef);
74
+ const gqlMetas = (0, import_signal.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Process");
75
+ for (const gqlMeta of gqlMetas) {
76
+ if (queue[gqlMeta.key]) throw new Error(`Queue already has ${gqlMeta.key} in ${sigMeta.refName}`);
77
+ queue[gqlMeta.key] = (...args) => queue.add(gqlMeta.key, args);
78
+ }
79
+ return queue;
80
+ }, "queueOf");
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ processorOf,
84
+ queueOf
85
+ });
@@ -0,0 +1,9 @@
1
+ import { T as Type } from '../types-H2HI4YUe.js';
2
+
3
+ declare const resolverOf: (sigRef: Type, allSrvs: {
4
+ [key: string]: Type;
5
+ }) => {
6
+ new (): {};
7
+ };
8
+
9
+ export { resolverOf };
@@ -0,0 +1,161 @@
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 resolver_exports = {};
30
+ __export(resolver_exports, {
31
+ resolverOf: () => resolverOf
32
+ });
33
+ module.exports = __toCommonJS(resolver_exports);
34
+ var import_base = require("@akanjs/base");
35
+ var import_common = require("@akanjs/common");
36
+ var import_constant = require("@akanjs/constant");
37
+ var import_nest = require("@akanjs/nest");
38
+ var import_service = require("@akanjs/service");
39
+ var import_signal = require("@akanjs/signal");
40
+ var import_common2 = require("@nestjs/common");
41
+ var Nest = __toESM(require("@nestjs/graphql"));
42
+ var import_graphql_type_json = __toESM(require("graphql-type-json"));
43
+ var import_graphql_upload = require("graphql-upload");
44
+ var import_gql = require("./gql");
45
+ const scalarNestReturnMap = /* @__PURE__ */ new Map([
46
+ [
47
+ import_base.Upload,
48
+ import_graphql_upload.GraphQLUpload
49
+ ],
50
+ [
51
+ import_base.ID,
52
+ Nest.ID
53
+ ],
54
+ [
55
+ import_base.Int,
56
+ Nest.Int
57
+ ],
58
+ [
59
+ import_base.Float,
60
+ Nest.Float
61
+ ],
62
+ [
63
+ import_base.JSON,
64
+ import_graphql_type_json.default
65
+ ],
66
+ [
67
+ Boolean,
68
+ Boolean
69
+ ],
70
+ [
71
+ Date,
72
+ Date
73
+ ],
74
+ [
75
+ String,
76
+ String
77
+ ],
78
+ [
79
+ Map,
80
+ import_graphql_type_json.default
81
+ ]
82
+ ]);
83
+ const getNestReturn = /* @__PURE__ */ __name((returns, type = "object") => {
84
+ const [model, arrDepth] = (0, import_base.getNonArrayModel)(returns());
85
+ const modelRef = scalarNestReturnMap.get(model) ?? (type === "object" ? (0, import_gql.generateGql)(model) : (0, import_gql.generateGqlInput)(model));
86
+ return () => (0, import_base.arraiedModel)(modelRef, arrDepth);
87
+ }, "getNestReturn");
88
+ const internalArgMap = {
89
+ Parent: Nest.Parent,
90
+ Account: import_nest.Account,
91
+ UserIp: import_nest.UserIp,
92
+ Access: import_nest.Access,
93
+ Self: import_nest.Self,
94
+ Me: import_nest.Me,
95
+ Req: import_nest.Req,
96
+ Res: import_nest.Res
97
+ };
98
+ const resolverOf = /* @__PURE__ */ __name((sigRef, allSrvs) => {
99
+ const Rsv = (0, import_signal.copySignal)(sigRef);
100
+ const sigMeta = (0, import_signal.getSigMeta)(Rsv);
101
+ const gqlMetas = (0, import_signal.getGqlMetas)(Rsv);
102
+ Object.keys(allSrvs).forEach((srv) => {
103
+ if (!(0, import_service.isServiceEnabled)(allSrvs[srv])) return;
104
+ (0, import_common2.Inject)(allSrvs[srv])(Rsv.prototype, (0, import_common.lowerlize)(srv));
105
+ });
106
+ for (const gqlMeta of gqlMetas) {
107
+ if (gqlMeta.guards.some((guard) => guard === "None") || gqlMeta.signalOption.onlyFor === "restapi" || ![
108
+ "Query",
109
+ "Mutation"
110
+ ].includes(gqlMeta.type)) continue;
111
+ else if (gqlMeta.signalOption.sso) continue;
112
+ const [argMetas, internalArgMetas] = (0, import_signal.getArgMetas)(Rsv, gqlMeta.key);
113
+ const descriptor = Object.getOwnPropertyDescriptor(Rsv.prototype, gqlMeta.key) ?? {};
114
+ for (const argMeta of argMetas) {
115
+ Nest.Args({
116
+ name: argMeta.name,
117
+ type: getNestReturn(argMeta.returns, "input"),
118
+ ...argMeta.argsOption
119
+ })(Rsv.prototype, gqlMeta.key, argMeta.idx);
120
+ }
121
+ for (const internalArgMeta of internalArgMetas) {
122
+ const decorate = internalArgMap[internalArgMeta.type];
123
+ decorate(internalArgMeta.option ?? {})(Rsv.prototype, gqlMeta.key, internalArgMeta.idx);
124
+ }
125
+ (0, import_common2.UseGuards)(...gqlMeta.guards.map((guard) => import_nest.guards[guard]))(Rsv.prototype, gqlMeta.key, descriptor);
126
+ if (gqlMeta.type === "Query") Nest.Query(getNestReturn(gqlMeta.returns), gqlMeta.signalOption)(Rsv.prototype, gqlMeta.key, descriptor);
127
+ else if (gqlMeta.type === "Mutation") Nest.Mutation(getNestReturn(gqlMeta.returns), gqlMeta.signalOption)(Rsv.prototype, gqlMeta.key, descriptor);
128
+ }
129
+ const resolveFieldMetas = (0, import_signal.getResolveFieldMetas)(Rsv);
130
+ if (sigMeta.returns) {
131
+ const modelRef = sigMeta.returns();
132
+ const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
133
+ fieldMetas.filter((fieldMeta) => fieldMeta.isClass && !fieldMeta.isScalar).forEach((fieldMeta) => {
134
+ const classMeta = (0, import_constant.getClassMeta)(fieldMeta.modelRef);
135
+ const modelName = (0, import_common.lowerlize)(classMeta.type === "light" ? classMeta.refName.slice(5) : classMeta.refName);
136
+ const className = (0, import_common.capitalize)(modelName);
137
+ const serviceName = `${modelName}Service`;
138
+ Rsv.prototype[fieldMeta.key] = async function(parent) {
139
+ const service = this[serviceName];
140
+ return fieldMeta.arrDepth ? await service[`load${className}Many`](parent[fieldMeta.key]) : await service[`load${className}`](parent[fieldMeta.key]);
141
+ };
142
+ Nest.Parent()(Rsv.prototype, fieldMeta.key, 0);
143
+ Nest.ResolveField(getNestReturn(() => (0, import_base.arraiedModel)(fieldMeta.modelRef, fieldMeta.arrDepth)))(Rsv.prototype, fieldMeta.key, Object.getOwnPropertyDescriptor(Rsv.prototype, fieldMeta.key) ?? {});
144
+ });
145
+ }
146
+ for (const resolveFieldMeta of resolveFieldMetas) {
147
+ const [, internalArgMetas] = (0, import_signal.getArgMetas)(Rsv, resolveFieldMeta.key);
148
+ for (const internalArgMeta of internalArgMetas) {
149
+ const decorate = internalArgMap[internalArgMeta.type];
150
+ decorate(internalArgMeta.option ?? {})(Rsv.prototype, resolveFieldMeta.key, internalArgMeta.idx);
151
+ }
152
+ Nest.ResolveField(getNestReturn(resolveFieldMeta.returns))(Rsv.prototype, resolveFieldMeta.key, Object.getOwnPropertyDescriptor(Rsv.prototype, resolveFieldMeta.key) ?? {});
153
+ }
154
+ if (sigMeta.returns) Nest.Resolver(getNestReturn(sigMeta.returns))(Rsv);
155
+ else Nest.Resolver()(Rsv);
156
+ return Rsv;
157
+ }, "resolverOf");
158
+ // Annotate the CommonJS export names for ESM import in node:
159
+ 0 && (module.exports = {
160
+ resolverOf
161
+ });
@@ -0,0 +1,12 @@
1
+ import { T as Type } from '../types-H2HI4YUe.js';
2
+ import { B as BaseMiddleware } from '../dbDecorators-z3rJpvxp.js';
3
+ import { Schema } from 'mongoose';
4
+ import '../types-CUkhtrLV.js';
5
+ import 'dayjs';
6
+ import 'fs';
7
+ import 'stream';
8
+
9
+ declare const schemaOf: <Mdl, Doc, Middleware extends BaseMiddleware>(modelRef: Type<Mdl>, docRef: Type<Doc>, middleware: Type<Middleware>) => Schema<null, Mdl, Doc, undefined, null, Mdl>;
10
+ declare const addSchema: <Mdl, Doc, Input, Middleware extends BaseMiddleware>(modelRef: Type<Mdl>, docRef: Type<Doc>, inputRef: Type<Input>, middleware: Type<Middleware>) => Schema<null, Mdl, Doc, undefined, null, Mdl>;
11
+
12
+ export { addSchema, schemaOf };
package/src/schema.js ADDED
@@ -0,0 +1,275 @@
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 schema_exports = {};
20
+ __export(schema_exports, {
21
+ addSchema: () => addSchema,
22
+ schemaOf: () => schemaOf
23
+ });
24
+ module.exports = __toCommonJS(schema_exports);
25
+ var import_base = require("@akanjs/base");
26
+ var import_common = require("@akanjs/common");
27
+ var import_constant = require("@akanjs/constant");
28
+ var import_document = require("@akanjs/document");
29
+ var import_signal = require("@akanjs/signal");
30
+ var import_mongoose = require("mongoose");
31
+ var import__ = require(".");
32
+ let ScalarSchemaStorage = class ScalarSchemaStorage2 {
33
+ static {
34
+ __name(this, "ScalarSchemaStorage");
35
+ }
36
+ };
37
+ let SchemaStorage = class SchemaStorage2 {
38
+ static {
39
+ __name(this, "SchemaStorage");
40
+ }
41
+ };
42
+ const scalarMongoTypeMap = /* @__PURE__ */ new Map([
43
+ [
44
+ import_base.ID,
45
+ import_document.ObjectId
46
+ ],
47
+ [
48
+ import_base.Int,
49
+ Number
50
+ ],
51
+ [
52
+ import_base.Float,
53
+ Number
54
+ ],
55
+ [
56
+ import_base.JSON,
57
+ import_mongoose.Schema.Types.Mixed
58
+ ],
59
+ [
60
+ Map,
61
+ Map
62
+ ],
63
+ [
64
+ String,
65
+ String
66
+ ],
67
+ [
68
+ Boolean,
69
+ Boolean
70
+ ],
71
+ [
72
+ Date,
73
+ Date
74
+ ]
75
+ ]);
76
+ const applyMongoProp = /* @__PURE__ */ __name((schemaProps, fieldMeta) => {
77
+ if ([
78
+ "id",
79
+ "createdAt",
80
+ "updatedAt"
81
+ ].includes(fieldMeta.key) || fieldMeta.fieldType === "resolve") return;
82
+ const type = fieldMeta.isClass ? fieldMeta.isScalar ? createSchema(fieldMeta.modelRef) : import_document.ObjectId : scalarMongoTypeMap.get(fieldMeta.modelRef) ?? fieldMeta.modelRef;
83
+ let prop = {};
84
+ if (fieldMeta.optArrDepth) {
85
+ prop.type = type;
86
+ prop.required = true;
87
+ if (fieldMeta.isClass && !fieldMeta.refPath) prop.ref = (0, import_constant.getClassMeta)(fieldMeta.modelRef).refName;
88
+ if (fieldMeta.refPath) prop.refPath = fieldMeta.refPath;
89
+ if (typeof fieldMeta.min === "number") prop.min = fieldMeta.min;
90
+ if (typeof fieldMeta.max === "number") prop.max = fieldMeta.max;
91
+ if (fieldMeta.enum) prop.enum = [
92
+ ...fieldMeta.enum.values,
93
+ ...fieldMeta.nullable ? [
94
+ null
95
+ ] : []
96
+ ];
97
+ if (typeof fieldMeta.minlength === "number") prop.minlength = fieldMeta.minlength;
98
+ if (typeof fieldMeta.maxlength === "number") prop.maxlength = fieldMeta.maxlength;
99
+ if (fieldMeta.validate) {
100
+ prop.validate = function(value) {
101
+ return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? (0, import_base.dayjs)() : value, this) ?? true;
102
+ };
103
+ }
104
+ prop = {
105
+ type: (0, import_base.arraiedModel)(prop, fieldMeta.optArrDepth),
106
+ default: [],
107
+ required: true
108
+ };
109
+ if (fieldMeta.modelRef.prototype === Date.prototype) {
110
+ prop.get = (dates) => dates.map((date) => (0, import_base.dayjs)(date));
111
+ prop.set = (days) => days.map((day) => day.toDate());
112
+ }
113
+ if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === import_base.ID.prototype) {
114
+ prop.get = (ids) => ids.map((id) => id.toString());
115
+ prop.set = (ids) => ids.map((id) => new import_mongoose.Types.ObjectId(id));
116
+ }
117
+ } else {
118
+ prop.type = (0, import_base.arraiedModel)(type, fieldMeta.arrDepth);
119
+ prop.required = !fieldMeta.nullable;
120
+ if (fieldMeta.isMap) {
121
+ prop.of = scalarMongoTypeMap.get(fieldMeta.of) ?? createSchema(fieldMeta.of);
122
+ if (!fieldMeta.default) prop.default = /* @__PURE__ */ new Map();
123
+ }
124
+ if (fieldMeta.default !== null) {
125
+ if (typeof fieldMeta.default === "function") prop.default = function() {
126
+ const def = fieldMeta.default(this);
127
+ return (0, import_common.isDayjs)(def) ? def.toDate() : def;
128
+ };
129
+ else prop.default = (0, import_common.isDayjs)(fieldMeta.default) ? fieldMeta.default.toDate() : fieldMeta.default instanceof import_base.Enum ? [
130
+ ...fieldMeta.default.values
131
+ ] : fieldMeta.default;
132
+ }
133
+ if (typeof fieldMeta.immutable !== "undefined") prop.immutable = fieldMeta.immutable;
134
+ if (fieldMeta.isClass && !fieldMeta.refPath) prop.ref = (0, import_constant.getClassMeta)(fieldMeta.modelRef).refName;
135
+ if (fieldMeta.refPath) prop.refPath = fieldMeta.refPath;
136
+ if (typeof fieldMeta.min === "number") prop.min = fieldMeta.min;
137
+ if (typeof fieldMeta.max === "number") prop.max = fieldMeta.max;
138
+ if (fieldMeta.enum) prop.enum = [
139
+ ...fieldMeta.enum.values,
140
+ ...fieldMeta.nullable ? [
141
+ null
142
+ ] : []
143
+ ];
144
+ if (typeof fieldMeta.select === "boolean") prop.select = fieldMeta.select;
145
+ if (typeof fieldMeta.minlength === "number") prop.minlength = fieldMeta.minlength;
146
+ if (typeof fieldMeta.maxlength === "number") prop.maxlength = fieldMeta.maxlength;
147
+ if (fieldMeta.nullable) {
148
+ prop.get = (v) => v === void 0 ? void 0 : v;
149
+ prop.set = (v) => v === null ? void 0 : v;
150
+ }
151
+ if (fieldMeta.modelRef.prototype === Date.prototype) {
152
+ prop.get = (date) => date ? (0, import_base.dayjs)(date) : void 0;
153
+ prop.set = (day) => day ? (0, import_base.dayjs)(day).toDate() : void 0;
154
+ }
155
+ if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === import_base.ID.prototype) {
156
+ prop.get = (id) => id ? id.toString() : void 0;
157
+ prop.set = (id) => id ? new import_mongoose.Types.ObjectId(id) : void 0;
158
+ }
159
+ if (fieldMeta.isClass && fieldMeta.isScalar && fieldMeta.default === null && !fieldMeta.nullable) {
160
+ prop.default = (0, import_signal.makeDefault)(fieldMeta.modelRef);
161
+ }
162
+ if (fieldMeta.validate) {
163
+ prop.validate = function(value) {
164
+ return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? (0, import_base.dayjs)() : value, this) ?? true;
165
+ };
166
+ }
167
+ }
168
+ schemaProps[fieldMeta.key] = prop;
169
+ }, "applyMongoProp");
170
+ const createSchema = /* @__PURE__ */ __name((modelRef) => {
171
+ const classMeta = (0, import_constant.getClassMeta)(modelRef);
172
+ const schemaMeta = Reflect.getMetadata(classMeta.refName, ScalarSchemaStorage.prototype);
173
+ if (schemaMeta) return schemaMeta;
174
+ const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
175
+ const schemaProps = {};
176
+ fieldMetas.forEach((fieldMeta) => {
177
+ applyMongoProp(schemaProps, fieldMeta);
178
+ });
179
+ const schema = new import_mongoose.Schema(schemaProps);
180
+ Reflect.defineMetadata(classMeta.refName, schema, ScalarSchemaStorage.prototype);
181
+ return schema;
182
+ }, "createSchema");
183
+ const schemaOf = /* @__PURE__ */ __name((modelRef, docRef, middleware) => {
184
+ const classMeta = (0, import_constant.getClassMeta)(docRef);
185
+ const schemaMeta = Reflect.getMetadata(classMeta.refName, SchemaStorage.prototype);
186
+ if (schemaMeta) return schemaMeta;
187
+ const fieldMetas = (0, import_constant.getFieldMetas)(docRef);
188
+ const schemaProps = {
189
+ createdAt: {
190
+ type: Date,
191
+ get: /* @__PURE__ */ __name((date) => date ? (0, import_base.dayjs)(date) : date, "get"),
192
+ set: /* @__PURE__ */ __name((day) => day ? (0, import_base.dayjs)(day).toDate() : day, "set")
193
+ },
194
+ updatedAt: {
195
+ type: Date,
196
+ get: /* @__PURE__ */ __name((date) => date ? (0, import_base.dayjs)(date) : date, "get"),
197
+ set: /* @__PURE__ */ __name((day) => day ? (0, import_base.dayjs)(day).toDate() : day, "set")
198
+ }
199
+ };
200
+ fieldMetas.forEach((fieldMeta) => {
201
+ applyMongoProp(schemaProps, fieldMeta);
202
+ });
203
+ const schema = new import_mongoose.Schema(schemaProps, (0, import_document.getDefaultSchemaOptions)());
204
+ schema.methods.refresh = async function() {
205
+ Object.assign(this, await this.constructor.findById(this._id));
206
+ return this;
207
+ };
208
+ Object.getOwnPropertyNames(docRef.prototype).forEach((name) => {
209
+ if (name === "constructor") return;
210
+ schema.methods[name] = Object.getOwnPropertyDescriptor(docRef.prototype, name)?.value;
211
+ });
212
+ schema.pre("save", async function(next) {
213
+ const model = this.constructor;
214
+ if (this.isNew) model.addSummary([
215
+ "total",
216
+ this.status
217
+ ]);
218
+ else if (!!this.removedAt && this.isModified("removedAt")) model.subSummary([
219
+ "total",
220
+ this.status
221
+ ]);
222
+ next();
223
+ });
224
+ const onSchema = Object.getOwnPropertyDescriptor(middleware.prototype, "onSchema")?.value;
225
+ onSchema?.(schema);
226
+ schema.index({
227
+ removedAt: -1
228
+ });
229
+ Reflect.defineMetadata(classMeta.refName, schema, SchemaStorage.prototype);
230
+ return schema;
231
+ }, "schemaOf");
232
+ const addSchema = /* @__PURE__ */ __name((modelRef, docRef, inputRef, middleware) => {
233
+ const originDocClassMeta = (0, import_constant.getClassMeta)(docRef);
234
+ const originInputClassMeta = (0, import_constant.getClassMeta)(inputRef);
235
+ const originDoc = (0, import_constant.getFullModelRef)(originDocClassMeta.refName);
236
+ const originInput = (0, import_constant.getInputModelRef)(originInputClassMeta.refName);
237
+ const classMeta = (0, import_constant.getClassMeta)(docRef);
238
+ const modelSchema = Reflect.getMetadata(classMeta.refName, SchemaStorage.prototype);
239
+ if (!modelSchema) throw new Error(`Schema of ${classMeta.refName} not found`);
240
+ const fieldMetas = (0, import_constant.getFieldMetas)(docRef);
241
+ const schemaProps = {
242
+ createdAt: {
243
+ type: Date,
244
+ get: /* @__PURE__ */ __name((date) => date ? (0, import_base.dayjs)(date) : date, "get"),
245
+ set: /* @__PURE__ */ __name((day) => day ? (0, import_base.dayjs)(day).toDate() : day, "set")
246
+ },
247
+ updatedAt: {
248
+ type: Date,
249
+ get: /* @__PURE__ */ __name((date) => date ? (0, import_base.dayjs)(date) : date, "get"),
250
+ set: /* @__PURE__ */ __name((day) => day ? (0, import_base.dayjs)(day).toDate() : day, "set")
251
+ }
252
+ };
253
+ fieldMetas.forEach((fieldMeta) => {
254
+ applyMongoProp(schemaProps, fieldMeta);
255
+ (0, import__.applyNestField)(originDoc, fieldMeta);
256
+ });
257
+ const inputFieldMetas = (0, import_constant.getFieldMetas)(inputRef);
258
+ inputFieldMetas.forEach((fieldMeta) => {
259
+ (0, import__.applyNestField)(originInput, fieldMeta, "input");
260
+ });
261
+ const schema = new import_mongoose.Schema(schemaProps, (0, import_document.getDefaultSchemaOptions)());
262
+ modelSchema.add(schema);
263
+ Object.getOwnPropertyNames(docRef.prototype).forEach((name) => {
264
+ if (name === "constructor") return;
265
+ modelSchema.methods[name] = Object.getOwnPropertyDescriptor(docRef.prototype, name)?.value;
266
+ });
267
+ const onSchema = Object.getOwnPropertyDescriptor(middleware.prototype, "onSchema")?.value;
268
+ onSchema?.(modelSchema);
269
+ return modelSchema;
270
+ }, "addSchema");
271
+ // Annotate the CommonJS export names for ESM import in node:
272
+ 0 && (module.exports = {
273
+ addSchema,
274
+ schemaOf
275
+ });
@@ -0,0 +1,13 @@
1
+ import { T as Type } from '../types-H2HI4YUe.js';
2
+ import { T as TextDoc } from '../types-CUkhtrLV.js';
3
+ import 'dayjs';
4
+ import 'fs';
5
+ import 'stream';
6
+
7
+ declare const makeTextFilter: (modelRef: Type) => (data: Record<string, any>, assignObj?: {
8
+ [key: string]: string;
9
+ }) => TextDoc;
10
+ declare class SearchDaemonModule {
11
+ }
12
+
13
+ export { SearchDaemonModule, makeTextFilter };