@akanjs/server 0.9.47 → 0.9.49

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/cjs/src/boot.js CHANGED
@@ -67,6 +67,7 @@ const createNestApp = async ({ registerModules, serverMode = "federation", env,
67
67
  const backendLogger = new import_common.Logger("Backend");
68
68
  if (log)
69
69
  backendLogger.rawLog(import_base.logo);
70
+ import_signal.signalInfo.initialize();
70
71
  const jwtSecret = (0, import_nest.generateJwtSecret)(env.appName, env.environment);
71
72
  const [redisUri, mongoUri, meiliUri] = await Promise.all([
72
73
  env.redisUri ?? (0, import_nest.generateRedisUri)({ ...env, ...env.redis?.sshOptions ? { sshOptions: env.redis.sshOptions } : {} }),
package/cjs/src/gql.js CHANGED
@@ -43,6 +43,7 @@ __export(gql_exports, {
43
43
  });
44
44
  module.exports = __toCommonJS(gql_exports);
45
45
  var import_base = require("@akanjs/base");
46
+ var import_common = require("@akanjs/common");
46
47
  var import_constant = require("@akanjs/constant");
47
48
  var Nest = __toESM(require("@nestjs/graphql"));
48
49
  var import_graphql = require("@nestjs/graphql");
@@ -107,40 +108,42 @@ const applyNestField = (model, fieldMeta, type = "object") => {
107
108
  );
108
109
  };
109
110
  const generateGqlInput = (inputRef) => {
110
- const classMeta = (0, import_constant.getClassMeta)(inputRef);
111
- const predefinedInputGql = getPredefinedInqutGql(classMeta.refName);
111
+ const refName = import_constant.constantInfo.getRefName(inputRef);
112
+ const gqlName = `${(0, import_common.capitalize)(refName)}Input`;
113
+ const predefinedInputGql = getPredefinedInqutGql(gqlName);
112
114
  if (predefinedInputGql)
113
115
  return predefinedInputGql;
114
116
  const fieldMetas = (0, import_constant.getFieldMetas)(inputRef);
115
117
  class InputGql {
116
118
  }
117
- const inputGql = classMeta.type === "scalar" ? InputGql : (0, import_constant.getInputModelRef)(classMeta.refName);
119
+ const inputGql = import_constant.constantInfo.isScalar(inputRef) ? InputGql : import_constant.constantInfo.getDatabase(refName).input;
118
120
  fieldMetas.forEach((fieldMeta) => {
119
121
  applyNestField(inputGql, fieldMeta, "input");
120
122
  });
121
- (0, import_graphql.InputType)(classMeta.refName + (classMeta.type === "scalar" ? "Input" : ""))(inputGql);
122
- setPredefinedInqutGql(classMeta.refName, inputGql);
123
+ (0, import_graphql.InputType)(gqlName)(inputGql);
124
+ setPredefinedInqutGql(gqlName, inputGql);
123
125
  return inputGql;
124
126
  };
125
127
  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);
128
+ const refName = import_constant.constantInfo.getRefName(objectRef);
129
+ const isLight = import_constant.constantInfo.isLight(objectRef);
130
+ const gqlName = `${isLight ? "Light" : ""}${(0, import_common.capitalize)(refName)}${import_constant.constantInfo.isInsight(objectRef) ? "Insight" : ""}`;
131
+ if (isLight) {
132
+ const fullModelRef = import_constant.constantInfo.getDatabase(refName).full;
130
133
  return generateGql(fullModelRef);
131
134
  }
132
- const predefinedObjectGql = getPredefinedObjectGql(classMeta.refName);
135
+ const predefinedObjectGql = getPredefinedObjectGql(gqlName);
133
136
  if (predefinedObjectGql)
134
137
  return predefinedObjectGql;
135
138
  const fieldMetas = (0, import_constant.getFieldMetas)(objectRef);
136
139
  class ObjectGql {
137
140
  }
138
- const objectGql = classMeta.type === "scalar" ? ObjectGql : (0, import_constant.getFullModelRef)(classMeta.refName);
141
+ const objectGql = import_constant.constantInfo.isScalar(objectRef) || import_constant.constantInfo.isInsight(objectRef) ? ObjectGql : import_constant.constantInfo.getDatabase(refName).full;
139
142
  fieldMetas.forEach((fieldMeta) => {
140
143
  applyNestField(objectGql, fieldMeta);
141
144
  });
142
- (0, import_graphql.ObjectType)(classMeta.refName)(objectGql);
143
- setPredefinedObjectGql(classMeta.refName, objectGql);
145
+ (0, import_graphql.ObjectType)(gqlName)(objectGql);
146
+ setPredefinedObjectGql(gqlName, objectGql);
144
147
  return objectGql;
145
148
  };
146
149
  // Annotate the CommonJS export names for ESM import in node:
package/cjs/src/module.js CHANGED
@@ -63,7 +63,7 @@ const databaseModuleOf = ({ constant, database, signal, service }, allSrvs) => {
63
63
  import_mongoose.MongooseModule.forFeature([
64
64
  {
65
65
  name: className,
66
- schema: (0, import_schema.hasSchema)(constant.Full) ? (0, import_schema.addSchema)(database.Model, database.Doc, database.Input, database.Middleware) : (0, import_schema.schemaOf)(database.Model, database.Doc, database.Middleware)
66
+ schema: (0, import_schema.hasSchema)(constant.full) ? (0, import_schema.addSchema)(database.Model, database.Doc, database.Input, database.Middleware) : (0, import_schema.schemaOf)(database.Model, database.Doc, database.Middleware)
67
67
  }
68
68
  ]),
69
69
  ...hasProcessor(signal) ? [
@@ -95,17 +95,19 @@ const databaseModuleOf = ({ constant, database, signal, service }, allSrvs) => {
95
95
  return DatabaseModule;
96
96
  };
97
97
  const serviceModuleOf = ({ signal, service }, allSrvs) => {
98
- if (!(0, import_service.isServiceEnabled)(service))
98
+ if (!(0, import_service.isServiceEnabled)(service)) {
99
+ if (signal)
100
+ (0, import_signal.setSigMeta)(signal, Object.assign((0, import_signal.getSigMeta)(signal), { enabled: false }));
99
101
  return null;
102
+ }
100
103
  const serviceMeta = (0, import_service.getServiceMeta)(service);
101
104
  if (!serviceMeta)
102
105
  throw new Error(`Service ${service} is not a valid service`);
103
- const refName = serviceMeta.name.replace("Service", "");
104
- const [modelName, className] = [(0, import_common.lowerlize)(refName), (0, import_common.capitalize)(refName)];
106
+ const [modelName, className] = [serviceMeta.refName, (0, import_common.capitalize)(serviceMeta.refName)];
105
107
  const srvRef = (0, import_service.serviceOf)(service);
106
- let ServiceModule = class {
108
+ let ServiceModule2 = class {
107
109
  };
108
- ServiceModule = __decorateClass([
110
+ ServiceModule2 = __decorateClass([
109
111
  (0, import_common2.Global)(),
110
112
  (0, import_common2.Module)({
111
113
  imports: signal ? [
@@ -129,22 +131,18 @@ const serviceModuleOf = ({ signal, service }, allSrvs) => {
129
131
  controllers: signal ? [(0, import_controller.controllerOf)(signal, filterSrvs(allSrvs))] : [],
130
132
  exports: service === srvRef ? [srvRef] : []
131
133
  })
132
- ], ServiceModule);
133
- return ServiceModule;
134
+ ], ServiceModule2);
135
+ return ServiceModule2;
134
136
  };
135
137
  const scalarModulesOf = ({ constants }, allSrvs) => {
136
138
  const signals = constants.filter((modelRef) => {
137
139
  const childRefs = (0, import_constant.getChildClassRefs)(modelRef);
138
- return childRefs.some((childRef) => {
139
- const classMeta = (0, import_constant.getClassMeta)(childRef);
140
- return ["full", "light"].includes(classMeta.type);
141
- });
140
+ return childRefs.some((childRef) => import_constant.constantInfo.isFull(childRef) || import_constant.constantInfo.isLight(childRef));
142
141
  }).map((modelRef) => {
143
- let ScalarSignal = class extends (0, import_signal.LogSignal)({}) {
144
- };
145
- ScalarSignal = __decorateClass([
146
- (0, import_signal.Signal)(() => modelRef)
147
- ], ScalarSignal);
142
+ const refName = import_constant.constantInfo.getRefName(modelRef);
143
+ class ScalarSignal extends (0, import_signal.internal)(new import_service.ServiceModule(refName, allSrvs), () => ({})) {
144
+ }
145
+ import_signal.signalInfo.registerSignals(ScalarSignal);
148
146
  return ScalarSignal;
149
147
  });
150
148
  let ScalarModule = class {
@@ -21,7 +21,9 @@ __export(processor_exports, {
21
21
  processorOf: () => processorOf
22
22
  });
23
23
  module.exports = __toCommonJS(processor_exports);
24
+ var import_base = require("@akanjs/base");
24
25
  var import_common = require("@akanjs/common");
26
+ var import_constant = require("@akanjs/constant");
25
27
  var import_service = require("@akanjs/service");
26
28
  var import_signal = require("@akanjs/signal");
27
29
  var import_bull = require("@nestjs/bull");
@@ -30,8 +32,9 @@ const convertProcessFunction = (gqlMeta, argMetas, internalArgMetas, fn) => {
30
32
  return async function(job, done) {
31
33
  const args = [];
32
34
  argMetas.forEach((argMeta) => {
35
+ const [argRef, arrDepth] = (0, import_base.getNonArrayModel)(argMeta.returns());
33
36
  if (argMeta.type === "Msg")
34
- args[argMeta.idx] = (0, import_signal.deserializeArg)(argMeta, job.data[argMeta.idx]);
37
+ args[argMeta.idx] = (0, import_constant.deserializeArg)(argRef, arrDepth, job.data[argMeta.idx], argMeta.argsOption);
35
38
  else
36
39
  throw new Error(`Invalid ArgMeta Type ${argMeta.type}`);
37
40
  });
@@ -63,7 +66,7 @@ const processorOf = (sigRef, allSrvs) => {
63
66
  });
64
67
  for (const gqlMeta of gqlMetas) {
65
68
  const [argMetas, internalArgMetas] = (0, import_signal.getArgMetas)(sigRef, gqlMeta.key);
66
- const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
69
+ const descriptor = gqlMeta.descriptor;
67
70
  descriptor.value = convertProcessFunction(
68
71
  gqlMeta,
69
72
  argMetas,
@@ -83,7 +83,7 @@ const resolverOf = (sigRef, allSrvs) => {
83
83
  else if (gqlMeta.signalOption.sso)
84
84
  continue;
85
85
  const [argMetas, internalArgMetas] = (0, import_signal.getArgMetas)(Rsv, gqlMeta.key);
86
- const descriptor = Object.getOwnPropertyDescriptor(Rsv.prototype, gqlMeta.key) ?? {};
86
+ const descriptor = gqlMeta.descriptor;
87
87
  for (const argMeta of argMetas) {
88
88
  Nest.Args({
89
89
  name: argMeta.name,
@@ -95,7 +95,11 @@ const resolverOf = (sigRef, allSrvs) => {
95
95
  const decorate = internalArgMap[internalArgMeta.type];
96
96
  decorate(internalArgMeta.option ?? {})(Rsv.prototype, gqlMeta.key, internalArgMeta.idx);
97
97
  }
98
- (0, import_common2.UseGuards)(...gqlMeta.guards.map((guard) => import_nest.guards[guard]))(Rsv.prototype, gqlMeta.key, descriptor);
98
+ (0, import_common2.UseGuards)(
99
+ ...gqlMeta.guards.map((guard) => {
100
+ return import_nest.guards[guard];
101
+ })
102
+ )(Rsv.prototype, gqlMeta.key, descriptor);
99
103
  if (gqlMeta.type === "Query")
100
104
  Nest.Query(getNestReturn(gqlMeta.returns), gqlMeta.signalOption)(Rsv.prototype, gqlMeta.key, descriptor);
101
105
  else if (gqlMeta.type === "Mutation")
@@ -107,10 +111,9 @@ const resolverOf = (sigRef, allSrvs) => {
107
111
  const modelRef = sigMeta.returns();
108
112
  const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
109
113
  fieldMetas.filter((fieldMeta) => fieldMeta.isClass && !fieldMeta.isScalar && !resolveFieldKeys.includes(fieldMeta.key)).forEach((fieldMeta) => {
110
- const classMeta = (0, import_constant.getClassMeta)(fieldMeta.modelRef);
111
- const modelName = (0, import_common.lowerlize)(classMeta.type === "light" ? classMeta.refName.slice(5) : classMeta.refName);
112
- const className = (0, import_common.capitalize)(modelName);
113
- const serviceName = `${modelName}Service`;
114
+ const refName = import_constant.constantInfo.getRefName(fieldMeta.modelRef);
115
+ const className = (0, import_common.capitalize)(refName);
116
+ const serviceName = `${refName}Service`;
114
117
  Rsv.prototype[fieldMeta.key] = async function(parent) {
115
118
  const service = this[serviceName];
116
119
  return fieldMeta.arrDepth ? await service[`load${className}Many`](parent[fieldMeta.key]) : await service[`load${className}`](parent[fieldMeta.key]);
@@ -129,7 +132,7 @@ const resolverOf = (sigRef, allSrvs) => {
129
132
  const decorate = internalArgMap[internalArgMeta.type];
130
133
  decorate(internalArgMeta.option ?? {})(Rsv.prototype, resolveFieldMeta.key, internalArgMeta.idx);
131
134
  }
132
- Nest.ResolveField(getNestReturn(resolveFieldMeta.returns))(
135
+ Nest.ResolveField(resolveFieldMeta.key, getNestReturn(resolveFieldMeta.returns))(
133
136
  Rsv.prototype,
134
137
  resolveFieldMeta.key,
135
138
  Object.getOwnPropertyDescriptor(Rsv.prototype, resolveFieldMeta.key) ?? {}
@@ -61,7 +61,7 @@ const makeScheduleModule = (serverMode, backendEnv) => {
61
61
  const intervalMetas = [];
62
62
  const timeoutMetas = [];
63
63
  const destroyMetas = [];
64
- sigRefs.forEach((sigRef) => {
64
+ sigRefs.filter((sigRef) => (0, import_signal.getSigMeta)(sigRef).enabled).forEach((sigRef) => {
65
65
  const gqlMetas = (0, import_signal.getGqlMetas)(sigRef);
66
66
  gqlMetas.forEach((gqlMeta) => {
67
67
  const { enabled, operationMode, serverMode: targetServerMode, scheduleType } = gqlMeta.signalOption;
package/cjs/src/schema.js CHANGED
@@ -26,7 +26,6 @@ var import_base = require("@akanjs/base");
26
26
  var import_common = require("@akanjs/common");
27
27
  var import_constant = require("@akanjs/constant");
28
28
  var import_document = require("@akanjs/document");
29
- var import_signal = require("@akanjs/signal");
30
29
  var import_mongoose = require("mongoose");
31
30
  var import__ = require(".");
32
31
  class ScalarSchemaStorage {
@@ -41,8 +40,8 @@ const setSchemaMetaByName = (refName, schema) => {
41
40
  Reflect.defineMetadata(refName, schema, SchemaStorage.prototype);
42
41
  };
43
42
  const hasSchema = (modelRef) => {
44
- const classMeta = (0, import_constant.getClassMeta)(modelRef);
45
- return !!getSchemaMetaByName(classMeta.refName);
43
+ const refName = import_constant.constantInfo.getRefName(modelRef);
44
+ return !!getSchemaMetaByName(refName);
46
45
  };
47
46
  const getScalarSchemaMetaByName = (refName) => {
48
47
  const schemaMeta = Reflect.getMetadata(refName, ScalarSchemaStorage.prototype);
@@ -70,7 +69,7 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
70
69
  prop.type = type;
71
70
  prop.required = true;
72
71
  if (fieldMeta.isClass && !fieldMeta.refPath)
73
- prop.ref = (0, import_constant.getClassMeta)(fieldMeta.modelRef).refName;
72
+ prop.ref = import_constant.constantInfo.getRefName(fieldMeta.modelRef);
74
73
  if (fieldMeta.refPath)
75
74
  prop.refPath = fieldMeta.refPath;
76
75
  if (typeof fieldMeta.min === "number")
@@ -85,7 +84,7 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
85
84
  prop.maxlength = fieldMeta.maxlength;
86
85
  if (fieldMeta.validate) {
87
86
  prop.validate = function(value) {
88
- return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? (0, import_base.dayjs)() : value, this) ?? true;
87
+ return fieldMeta.validate?.(fieldMeta.modelRef === Date && !!value ? (0, import_base.dayjs)() : value, this) ?? true;
89
88
  };
90
89
  }
91
90
  prop = { type: (0, import_base.arraiedModel)(prop, fieldMeta.optArrDepth), default: [], required: true };
@@ -117,7 +116,7 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
117
116
  if (typeof fieldMeta.immutable !== "undefined")
118
117
  prop.immutable = fieldMeta.immutable;
119
118
  if (fieldMeta.isClass && !fieldMeta.refPath)
120
- prop.ref = (0, import_constant.getClassMeta)(fieldMeta.modelRef).refName;
119
+ prop.ref = import_constant.constantInfo.getRefName(fieldMeta.modelRef);
121
120
  if (fieldMeta.refPath)
122
121
  prop.refPath = fieldMeta.refPath;
123
122
  if (typeof fieldMeta.min === "number")
@@ -150,19 +149,19 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
150
149
  }
151
150
  }
152
151
  if (fieldMeta.isClass && fieldMeta.isScalar && fieldMeta.default === null && !fieldMeta.nullable) {
153
- prop.default = (0, import_signal.makeDefault)(fieldMeta.modelRef);
152
+ prop.default = (0, import_constant.makeDefault)(fieldMeta.modelRef);
154
153
  }
155
154
  if (fieldMeta.validate) {
156
155
  prop.validate = function(value) {
157
- return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? (0, import_base.dayjs)() : value, this) ?? true;
156
+ return fieldMeta.validate?.(fieldMeta.modelRef === Date && !!value ? (0, import_base.dayjs)() : value, this) ?? true;
158
157
  };
159
158
  }
160
159
  }
161
160
  schemaProps[fieldMeta.key] = prop;
162
161
  };
163
162
  const createSchema = (modelRef) => {
164
- const classMeta = (0, import_constant.getClassMeta)(modelRef);
165
- const schemaMeta = getScalarSchemaMetaByName(classMeta.refName);
163
+ const refName = import_constant.constantInfo.getRefName(modelRef);
164
+ const schemaMeta = getScalarSchemaMetaByName(refName);
166
165
  if (schemaMeta)
167
166
  return schemaMeta;
168
167
  const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
@@ -171,12 +170,12 @@ const createSchema = (modelRef) => {
171
170
  applyMongoProp(schemaProps, fieldMeta);
172
171
  });
173
172
  const schema = new import_mongoose.Schema(schemaProps);
174
- setScalarSchemaMetaByName(classMeta.refName, schema);
173
+ setScalarSchemaMetaByName(refName, schema);
175
174
  return schema;
176
175
  };
177
176
  const schemaOf = (modelRef, docRef, middleware) => {
178
- const classMeta = (0, import_constant.getClassMeta)(docRef);
179
- const schemaMeta = getSchemaMetaByName(classMeta.refName);
177
+ const refName = import_document.documentInfo.getRefName(docRef);
178
+ const schemaMeta = getSchemaMetaByName(refName);
180
179
  if (schemaMeta)
181
180
  return schemaMeta;
182
181
  const fieldMetas = (0, import_constant.getFieldMetas)(docRef);
@@ -245,18 +244,17 @@ const schemaOf = (modelRef, docRef, middleware) => {
245
244
  const onSchema = Object.getOwnPropertyDescriptor(middleware.prototype, "onSchema")?.value;
246
245
  onSchema?.(schema);
247
246
  schema.index({ removedAt: -1 });
248
- setSchemaMetaByName(classMeta.refName, schema);
247
+ setSchemaMetaByName(refName, schema);
249
248
  return schema;
250
249
  };
251
250
  const addSchema = (modelRef, docRef, inputRef, middleware) => {
252
- const originDocClassMeta = (0, import_constant.getClassMeta)(docRef);
253
- const originInputClassMeta = (0, import_constant.getClassMeta)(inputRef);
254
- const originDoc = (0, import_constant.getFullModelRef)(originDocClassMeta.refName);
255
- const originInput = (0, import_constant.getInputModelRef)(originInputClassMeta.refName);
256
- const classMeta = (0, import_constant.getClassMeta)(docRef);
257
- const modelSchema = Reflect.getMetadata(classMeta.refName, SchemaStorage.prototype);
251
+ const refName = import_document.documentInfo.getRefName(docRef);
252
+ const databaseConstantModelInfo = import_document.documentInfo.getDatabase(refName);
253
+ const originDoc = databaseConstantModelInfo.doc;
254
+ const originInput = databaseConstantModelInfo.input;
255
+ const modelSchema = Reflect.getMetadata(refName, SchemaStorage.prototype);
258
256
  if (!modelSchema)
259
- throw new Error(`Schema of ${classMeta.refName} not found`);
257
+ throw new Error(`Schema of ${refName} not found`);
260
258
  const fieldMetas = (0, import_constant.getFieldMetas)(docRef);
261
259
  const schemaProps = {
262
260
  createdAt: {
@@ -31,6 +31,7 @@ __export(searchDaemon_exports, {
31
31
  makeTextFilter: () => makeTextFilter
32
32
  });
33
33
  module.exports = __toCommonJS(searchDaemon_exports);
34
+ var import_base = require("@akanjs/base");
34
35
  var import_common = require("@akanjs/common");
35
36
  var import_constant = require("@akanjs/constant");
36
37
  var import_document = require("@akanjs/document");
@@ -102,8 +103,8 @@ const makeTextFilter = (modelRef) => {
102
103
  return filterData;
103
104
  };
104
105
  const getSortableAttributes = (refName) => {
105
- const cnst = (0, import_constant.getCnstMeta)(refName);
106
- const sortMap = (0, import_constant.getFilterSortMap)(cnst.Filter);
106
+ const docInfo = import_document.documentInfo.getDatabase(refName);
107
+ const sortMap = (0, import_document.getFilterSortMap)(docInfo.filter);
107
108
  const sortFields = Object.values(sortMap).filter((val) => typeof val === "object").map((sort) => Object.keys(sort)).flat();
108
109
  return [...new Set(sortFields)];
109
110
  };
@@ -114,14 +115,16 @@ let SearchDaemon = class {
114
115
  }
115
116
  logger = new import_common.Logger("SearchDaemon");
116
117
  async onModuleInit() {
117
- const databaseModelNames = (0, import_document.getAllDatabaseModelNames)();
118
+ if (import_base.baseEnv.operationMode === "local")
119
+ return;
120
+ const databaseRefNames = [...import_constant.constantInfo.database.keys()];
118
121
  const indexes = (await this.meili.getIndexes({ limit: 1e3 })).results;
119
122
  const indexMap = new Map(indexes.map((index) => [index.uid, index]));
120
123
  const indexCreationNames = [];
121
124
  const indexUpdateNames = [];
122
- for (const modelName of databaseModelNames) {
123
- const indexName = (0, import_common.lowerlize)(modelName);
124
- const modelRef = (0, import_constant.getFullModelRef)(modelName);
125
+ for (const refName of databaseRefNames) {
126
+ const indexName = refName;
127
+ const modelRef = import_constant.constantInfo.getDatabase(refName).full;
125
128
  if (!hasTextField(modelRef))
126
129
  continue;
127
130
  const index = indexMap.get(indexName);
@@ -134,10 +137,10 @@ let SearchDaemon = class {
134
137
  await this.meili.createIndex(indexName, { primaryKey: "id" });
135
138
  for (const indexName of indexUpdateNames)
136
139
  await this.meili.updateIndex(indexName, { primaryKey: "id" });
137
- for (const modelName of databaseModelNames) {
138
- const indexName = (0, import_common.lowerlize)(modelName);
139
- const model = this.connection.models[modelName];
140
- const modelRef = (0, import_constant.getFullModelRef)(modelName);
140
+ for (const refName of databaseRefNames) {
141
+ const indexName = refName;
142
+ const model = this.connection.models[(0, import_common.capitalize)(refName)];
143
+ const modelRef = import_constant.constantInfo.getDatabase(refName).full;
141
144
  if (!hasTextField(modelRef))
142
145
  continue;
143
146
  const searchIndex = this.meili.index(indexName);
@@ -149,7 +152,7 @@ let SearchDaemon = class {
149
152
  const filterFieldSet = new Set(settings.filterableAttributes);
150
153
  const needUpdateSetting = !allSearchFields.every((field) => searchFieldSet.has(field)) || !allFilterFields.every((field) => filterFieldSet.has(field)) || !settings.searchableAttributes?.every((field) => allSearchFieldSet.has(field)) || !settings.filterableAttributes?.every((field) => allFilterFieldSet.has(field));
151
154
  if (needUpdateSetting) {
152
- this.logger.info(`update index settings (${modelName})`);
155
+ this.logger.info(`update index settings (${refName})`);
153
156
  await searchIndex.updateSettings({
154
157
  searchableAttributes: allSearchFields,
155
158
  filterableAttributes: allFilterFields,
@@ -163,10 +166,10 @@ let SearchDaemon = class {
163
166
  try {
164
167
  const id = data.documentKey._id.toString();
165
168
  if (data.operationType === "delete") {
166
- this.logger.trace(`delete text doc (${modelName}): ${id}`);
169
+ this.logger.trace(`delete text doc (${refName}): ${id}`);
167
170
  return await searchIndex.deleteDocument(id);
168
171
  } else if (data.operationType === "insert") {
169
- this.logger.trace(`insert text doc (${modelName}): ${data.documentKey._id}`);
172
+ this.logger.trace(`insert text doc (${refName}): ${data.documentKey._id}`);
170
173
  if (!data.fullDocument)
171
174
  throw new Error("No fullDocument");
172
175
  const textFilteredData = filterText(data.fullDocument);
@@ -175,10 +178,10 @@ let SearchDaemon = class {
175
178
  const updatedFields = data.updateDescription?.updatedFields ?? {};
176
179
  const isRemoved = !!updatedFields.removedAt;
177
180
  if (isRemoved) {
178
- this.logger.trace(`remove text doc (${modelName}): ${id}`);
181
+ this.logger.trace(`remove text doc (${refName}): ${id}`);
179
182
  return await searchIndex.deleteDocument(id);
180
183
  }
181
- this.logger.trace(`update text doc (${modelName}): ${data.documentKey._id}`);
184
+ this.logger.trace(`update text doc (${refName}): ${data.documentKey._id}`);
182
185
  const updatedFieldKeys = Object.keys(updatedFields);
183
186
  const removedFieldKeys = data.updateDescription?.removedFields ?? [];
184
187
  const isScalarTextFieldUpdated = [...updatedFieldKeys, ...removedFieldKeys].map((key) => key.split(".")[0]).some((key) => scalarTextFieldSet.has(key));
@@ -81,7 +81,7 @@ const websocketOf = (sigRef, allSrvs) => {
81
81
  });
82
82
  const messageGqlMetas = (0, import_signal.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Message");
83
83
  for (const gqlMeta of messageGqlMetas) {
84
- const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
84
+ const descriptor = gqlMeta.descriptor;
85
85
  Object.defineProperty(WsGateway.prototype, gqlMeta.key, descriptor);
86
86
  const [argMetas, internalArgMetas] = (0, import_signal.getArgMetas)(sigRef, gqlMeta.key);
87
87
  argMetas.forEach((argMeta) => {
@@ -98,7 +98,7 @@ const websocketOf = (sigRef, allSrvs) => {
98
98
  }
99
99
  const pubsubGqlMetas = (0, import_signal.getGqlMetas)(sigRef).filter((gqlMeta) => gqlMeta.type === "Pubsub");
100
100
  for (const gqlMeta of pubsubGqlMetas) {
101
- const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
101
+ const descriptor = gqlMeta.descriptor;
102
102
  Object.defineProperty(WsGateway.prototype, gqlMeta.key, descriptor);
103
103
  const [argMetas, internalArgMetas] = (0, import_signal.getArgMetas)(sigRef, gqlMeta.key);
104
104
  argMetas.forEach((argMeta) => {
package/esm/src/boot.js CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  TimeoutInterceptor,
29
29
  verifyToken
30
30
  } from "@akanjs/nest";
31
- import { client } from "@akanjs/signal";
31
+ import { client, signalInfo } from "@akanjs/signal";
32
32
  import { ApolloDriver } from "@nestjs/apollo";
33
33
  import { BullModule } from "@nestjs/bull";
34
34
  import {
@@ -58,6 +58,7 @@ const createNestApp = async ({ registerModules, serverMode = "federation", env,
58
58
  const backendLogger = new Logger("Backend");
59
59
  if (log)
60
60
  backendLogger.rawLog(logo);
61
+ signalInfo.initialize();
61
62
  const jwtSecret = generateJwtSecret(env.appName, env.environment);
62
63
  const [redisUri, mongoUri, meiliUri] = await Promise.all([
63
64
  env.redisUri ?? generateRedisUri({ ...env, ...env.redis?.sshOptions ? { sshOptions: env.redis.sshOptions } : {} }),
package/esm/src/gql.js CHANGED
@@ -10,12 +10,8 @@ var __decorateClass = (decorators, target, key, kind) => {
10
10
  return result;
11
11
  };
12
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";
13
+ import { capitalize } from "@akanjs/common";
14
+ import { constantInfo, getFieldMetas } from "@akanjs/constant";
19
15
  import * as Nest from "@nestjs/graphql";
20
16
  import { Field, InputType, ObjectType } from "@nestjs/graphql";
21
17
  import { isDayjs } from "dayjs";
@@ -79,40 +75,42 @@ const applyNestField = (model, fieldMeta, type = "object") => {
79
75
  );
80
76
  };
81
77
  const generateGqlInput = (inputRef) => {
82
- const classMeta = getClassMeta(inputRef);
83
- const predefinedInputGql = getPredefinedInqutGql(classMeta.refName);
78
+ const refName = constantInfo.getRefName(inputRef);
79
+ const gqlName = `${capitalize(refName)}Input`;
80
+ const predefinedInputGql = getPredefinedInqutGql(gqlName);
84
81
  if (predefinedInputGql)
85
82
  return predefinedInputGql;
86
83
  const fieldMetas = getFieldMetas(inputRef);
87
84
  class InputGql {
88
85
  }
89
- const inputGql = classMeta.type === "scalar" ? InputGql : getInputModelRef(classMeta.refName);
86
+ const inputGql = constantInfo.isScalar(inputRef) ? InputGql : constantInfo.getDatabase(refName).input;
90
87
  fieldMetas.forEach((fieldMeta) => {
91
88
  applyNestField(inputGql, fieldMeta, "input");
92
89
  });
93
- InputType(classMeta.refName + (classMeta.type === "scalar" ? "Input" : ""))(inputGql);
94
- setPredefinedInqutGql(classMeta.refName, inputGql);
90
+ InputType(gqlName)(inputGql);
91
+ setPredefinedInqutGql(gqlName, inputGql);
95
92
  return inputGql;
96
93
  };
97
94
  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);
95
+ const refName = constantInfo.getRefName(objectRef);
96
+ const isLight = constantInfo.isLight(objectRef);
97
+ const gqlName = `${isLight ? "Light" : ""}${capitalize(refName)}${constantInfo.isInsight(objectRef) ? "Insight" : ""}`;
98
+ if (isLight) {
99
+ const fullModelRef = constantInfo.getDatabase(refName).full;
102
100
  return generateGql(fullModelRef);
103
101
  }
104
- const predefinedObjectGql = getPredefinedObjectGql(classMeta.refName);
102
+ const predefinedObjectGql = getPredefinedObjectGql(gqlName);
105
103
  if (predefinedObjectGql)
106
104
  return predefinedObjectGql;
107
105
  const fieldMetas = getFieldMetas(objectRef);
108
106
  class ObjectGql {
109
107
  }
110
- const objectGql = classMeta.type === "scalar" ? ObjectGql : getFullModelRef(classMeta.refName);
108
+ const objectGql = constantInfo.isScalar(objectRef) || constantInfo.isInsight(objectRef) ? ObjectGql : constantInfo.getDatabase(refName).full;
111
109
  fieldMetas.forEach((fieldMeta) => {
112
110
  applyNestField(objectGql, fieldMeta);
113
111
  });
114
- ObjectType(classMeta.refName)(objectGql);
115
- setPredefinedObjectGql(classMeta.refName, objectGql);
112
+ ObjectType(gqlName)(objectGql);
113
+ setPredefinedObjectGql(gqlName, objectGql);
116
114
  return objectGql;
117
115
  };
118
116
  export {
package/esm/src/module.js CHANGED
@@ -10,10 +10,10 @@ var __decorateClass = (decorators, target, key, kind) => {
10
10
  return result;
11
11
  };
12
12
  import { capitalize, lowerlize } from "@akanjs/common";
13
- import { getChildClassRefs, getClassMeta } from "@akanjs/constant";
13
+ import { constantInfo, getChildClassRefs } from "@akanjs/constant";
14
14
  import { databaseModelOf } from "@akanjs/document";
15
- import { getServiceMeta, isServiceEnabled, makeProvidersForSrv, serviceOf } from "@akanjs/service";
16
- import { getGqlMetas, LogSignal, Signal } from "@akanjs/signal";
15
+ import { getServiceMeta, isServiceEnabled, makeProvidersForSrv, ServiceModule, serviceOf } from "@akanjs/service";
16
+ import { getGqlMetas, getSigMeta, internal, setSigMeta, signalInfo } from "@akanjs/signal";
17
17
  import { BullModule } from "@nestjs/bull";
18
18
  import { Global, Injectable, Module } from "@nestjs/common";
19
19
  import { getModelToken, MongooseModule } from "@nestjs/mongoose";
@@ -40,7 +40,7 @@ const databaseModuleOf = ({ constant, database, signal, service }, allSrvs) => {
40
40
  MongooseModule.forFeature([
41
41
  {
42
42
  name: className,
43
- schema: hasSchema(constant.Full) ? addSchema(database.Model, database.Doc, database.Input, database.Middleware) : schemaOf(database.Model, database.Doc, database.Middleware)
43
+ schema: hasSchema(constant.full) ? addSchema(database.Model, database.Doc, database.Input, database.Middleware) : schemaOf(database.Model, database.Doc, database.Middleware)
44
44
  }
45
45
  ]),
46
46
  ...hasProcessor(signal) ? [
@@ -72,17 +72,19 @@ const databaseModuleOf = ({ constant, database, signal, service }, allSrvs) => {
72
72
  return DatabaseModule;
73
73
  };
74
74
  const serviceModuleOf = ({ signal, service }, allSrvs) => {
75
- if (!isServiceEnabled(service))
75
+ if (!isServiceEnabled(service)) {
76
+ if (signal)
77
+ setSigMeta(signal, Object.assign(getSigMeta(signal), { enabled: false }));
76
78
  return null;
79
+ }
77
80
  const serviceMeta = getServiceMeta(service);
78
81
  if (!serviceMeta)
79
82
  throw new Error(`Service ${service} is not a valid service`);
80
- const refName = serviceMeta.name.replace("Service", "");
81
- const [modelName, className] = [lowerlize(refName), capitalize(refName)];
83
+ const [modelName, className] = [serviceMeta.refName, capitalize(serviceMeta.refName)];
82
84
  const srvRef = serviceOf(service);
83
- let ServiceModule = class {
85
+ let ServiceModule2 = class {
84
86
  };
85
- ServiceModule = __decorateClass([
87
+ ServiceModule2 = __decorateClass([
86
88
  Global(),
87
89
  Module({
88
90
  imports: signal ? [
@@ -106,22 +108,18 @@ const serviceModuleOf = ({ signal, service }, allSrvs) => {
106
108
  controllers: signal ? [controllerOf(signal, filterSrvs(allSrvs))] : [],
107
109
  exports: service === srvRef ? [srvRef] : []
108
110
  })
109
- ], ServiceModule);
110
- return ServiceModule;
111
+ ], ServiceModule2);
112
+ return ServiceModule2;
111
113
  };
112
114
  const scalarModulesOf = ({ constants }, allSrvs) => {
113
115
  const signals = constants.filter((modelRef) => {
114
116
  const childRefs = getChildClassRefs(modelRef);
115
- return childRefs.some((childRef) => {
116
- const classMeta = getClassMeta(childRef);
117
- return ["full", "light"].includes(classMeta.type);
118
- });
117
+ return childRefs.some((childRef) => constantInfo.isFull(childRef) || constantInfo.isLight(childRef));
119
118
  }).map((modelRef) => {
120
- let ScalarSignal = class extends LogSignal({}) {
121
- };
122
- ScalarSignal = __decorateClass([
123
- Signal(() => modelRef)
124
- ], ScalarSignal);
119
+ const refName = constantInfo.getRefName(modelRef);
120
+ class ScalarSignal extends internal(new ServiceModule(refName, allSrvs), () => ({})) {
121
+ }
122
+ signalInfo.registerSignals(ScalarSignal);
125
123
  return ScalarSignal;
126
124
  });
127
125
  let ScalarModule = class {
@@ -1,19 +1,17 @@
1
+ import { getNonArrayModel } from "@akanjs/base";
1
2
  import { lowerlize } from "@akanjs/common";
3
+ import { deserializeArg } from "@akanjs/constant";
2
4
  import { getServiceRefs, isServiceEnabled } from "@akanjs/service";
3
- import {
4
- deserializeArg,
5
- getArgMetas,
6
- getGqlMetas,
7
- getSigMeta
8
- } from "@akanjs/signal";
5
+ import { getArgMetas, getGqlMetas, getSigMeta } from "@akanjs/signal";
9
6
  import { getQueueToken, Process, Processor } from "@nestjs/bull";
10
7
  import { Inject } from "@nestjs/common";
11
8
  const convertProcessFunction = (gqlMeta, argMetas, internalArgMetas, fn) => {
12
9
  return async function(job, done) {
13
10
  const args = [];
14
11
  argMetas.forEach((argMeta) => {
12
+ const [argRef, arrDepth] = getNonArrayModel(argMeta.returns());
15
13
  if (argMeta.type === "Msg")
16
- args[argMeta.idx] = deserializeArg(argMeta, job.data[argMeta.idx]);
14
+ args[argMeta.idx] = deserializeArg(argRef, arrDepth, job.data[argMeta.idx], argMeta.argsOption);
17
15
  else
18
16
  throw new Error(`Invalid ArgMeta Type ${argMeta.type}`);
19
17
  });
@@ -45,7 +43,7 @@ const processorOf = (sigRef, allSrvs) => {
45
43
  });
46
44
  for (const gqlMeta of gqlMetas) {
47
45
  const [argMetas, internalArgMetas] = getArgMetas(sigRef, gqlMeta.key);
48
- const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
46
+ const descriptor = gqlMeta.descriptor;
49
47
  descriptor.value = convertProcessFunction(
50
48
  gqlMeta,
51
49
  argMetas,
@@ -1,6 +1,6 @@
1
1
  import { arraiedModel, Float, getNonArrayModel, ID, Int, JSON, Upload } from "@akanjs/base";
2
2
  import { capitalize, lowerlize } from "@akanjs/common";
3
- import { getClassMeta, getFieldMetas } from "@akanjs/constant";
3
+ import { constantInfo, getFieldMetas } from "@akanjs/constant";
4
4
  import { Access, Account, guards, Me, Req, Res, Self, UserIp } from "@akanjs/nest";
5
5
  import { getServiceRefs, isServiceEnabled } from "@akanjs/service";
6
6
  import {
@@ -57,7 +57,7 @@ const resolverOf = (sigRef, allSrvs) => {
57
57
  else if (gqlMeta.signalOption.sso)
58
58
  continue;
59
59
  const [argMetas, internalArgMetas] = getArgMetas(Rsv, gqlMeta.key);
60
- const descriptor = Object.getOwnPropertyDescriptor(Rsv.prototype, gqlMeta.key) ?? {};
60
+ const descriptor = gqlMeta.descriptor;
61
61
  for (const argMeta of argMetas) {
62
62
  Nest.Args({
63
63
  name: argMeta.name,
@@ -69,7 +69,11 @@ const resolverOf = (sigRef, allSrvs) => {
69
69
  const decorate = internalArgMap[internalArgMeta.type];
70
70
  decorate(internalArgMeta.option ?? {})(Rsv.prototype, gqlMeta.key, internalArgMeta.idx);
71
71
  }
72
- UseGuards(...gqlMeta.guards.map((guard) => guards[guard]))(Rsv.prototype, gqlMeta.key, descriptor);
72
+ UseGuards(
73
+ ...gqlMeta.guards.map((guard) => {
74
+ return guards[guard];
75
+ })
76
+ )(Rsv.prototype, gqlMeta.key, descriptor);
73
77
  if (gqlMeta.type === "Query")
74
78
  Nest.Query(getNestReturn(gqlMeta.returns), gqlMeta.signalOption)(Rsv.prototype, gqlMeta.key, descriptor);
75
79
  else if (gqlMeta.type === "Mutation")
@@ -81,10 +85,9 @@ const resolverOf = (sigRef, allSrvs) => {
81
85
  const modelRef = sigMeta.returns();
82
86
  const fieldMetas = getFieldMetas(modelRef);
83
87
  fieldMetas.filter((fieldMeta) => fieldMeta.isClass && !fieldMeta.isScalar && !resolveFieldKeys.includes(fieldMeta.key)).forEach((fieldMeta) => {
84
- const classMeta = getClassMeta(fieldMeta.modelRef);
85
- const modelName = lowerlize(classMeta.type === "light" ? classMeta.refName.slice(5) : classMeta.refName);
86
- const className = capitalize(modelName);
87
- const serviceName = `${modelName}Service`;
88
+ const refName = constantInfo.getRefName(fieldMeta.modelRef);
89
+ const className = capitalize(refName);
90
+ const serviceName = `${refName}Service`;
88
91
  Rsv.prototype[fieldMeta.key] = async function(parent) {
89
92
  const service = this[serviceName];
90
93
  return fieldMeta.arrDepth ? await service[`load${className}Many`](parent[fieldMeta.key]) : await service[`load${className}`](parent[fieldMeta.key]);
@@ -103,7 +106,7 @@ const resolverOf = (sigRef, allSrvs) => {
103
106
  const decorate = internalArgMap[internalArgMeta.type];
104
107
  decorate(internalArgMeta.option ?? {})(Rsv.prototype, resolveFieldMeta.key, internalArgMeta.idx);
105
108
  }
106
- Nest.ResolveField(getNestReturn(resolveFieldMeta.returns))(
109
+ Nest.ResolveField(resolveFieldMeta.key, getNestReturn(resolveFieldMeta.returns))(
107
110
  Rsv.prototype,
108
111
  resolveFieldMeta.key,
109
112
  Object.getOwnPropertyDescriptor(Rsv.prototype, resolveFieldMeta.key) ?? {}
@@ -29,7 +29,7 @@ var __privateAdd = (obj, member, value) => {
29
29
  };
30
30
  import { lowerlize } from "@akanjs/common";
31
31
  import { getAllServiceRefs, getServiceMeta } from "@akanjs/service";
32
- import { getAllSignalRefs, getGqlMetas } from "@akanjs/signal";
32
+ import { getAllSignalRefs, getGqlMetas, getSigMeta } from "@akanjs/signal";
33
33
  import { Global, Inject, Injectable, Logger, Module } from "@nestjs/common";
34
34
  import { CronJob } from "cron";
35
35
  const makeScheduleModule = (serverMode, backendEnv) => {
@@ -41,7 +41,7 @@ const makeScheduleModule = (serverMode, backendEnv) => {
41
41
  const intervalMetas = [];
42
42
  const timeoutMetas = [];
43
43
  const destroyMetas = [];
44
- sigRefs.forEach((sigRef) => {
44
+ sigRefs.filter((sigRef) => getSigMeta(sigRef).enabled).forEach((sigRef) => {
45
45
  const gqlMetas = getGqlMetas(sigRef);
46
46
  gqlMetas.forEach((gqlMeta) => {
47
47
  const { enabled, operationMode, serverMode: targetServerMode, scheduleType } = gqlMeta.signalOption;
package/esm/src/schema.js CHANGED
@@ -9,9 +9,8 @@ import {
9
9
  JSON
10
10
  } from "@akanjs/base";
11
11
  import { isDayjs, Logger } from "@akanjs/common";
12
- import { getClassMeta, getFieldMetas, getFullModelRef, getInputModelRef } from "@akanjs/constant";
13
- import { getDefaultSchemaOptions, ObjectId } from "@akanjs/document";
14
- import { makeDefault } from "@akanjs/signal";
12
+ import { constantInfo, getFieldMetas, makeDefault } from "@akanjs/constant";
13
+ import { documentInfo, getDefaultSchemaOptions, ObjectId } from "@akanjs/document";
15
14
  import { Schema, Types } from "mongoose";
16
15
  import { applyNestField } from ".";
17
16
  class ScalarSchemaStorage {
@@ -26,8 +25,8 @@ const setSchemaMetaByName = (refName, schema) => {
26
25
  Reflect.defineMetadata(refName, schema, SchemaStorage.prototype);
27
26
  };
28
27
  const hasSchema = (modelRef) => {
29
- const classMeta = getClassMeta(modelRef);
30
- return !!getSchemaMetaByName(classMeta.refName);
28
+ const refName = constantInfo.getRefName(modelRef);
29
+ return !!getSchemaMetaByName(refName);
31
30
  };
32
31
  const getScalarSchemaMetaByName = (refName) => {
33
32
  const schemaMeta = Reflect.getMetadata(refName, ScalarSchemaStorage.prototype);
@@ -55,7 +54,7 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
55
54
  prop.type = type;
56
55
  prop.required = true;
57
56
  if (fieldMeta.isClass && !fieldMeta.refPath)
58
- prop.ref = getClassMeta(fieldMeta.modelRef).refName;
57
+ prop.ref = constantInfo.getRefName(fieldMeta.modelRef);
59
58
  if (fieldMeta.refPath)
60
59
  prop.refPath = fieldMeta.refPath;
61
60
  if (typeof fieldMeta.min === "number")
@@ -70,7 +69,7 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
70
69
  prop.maxlength = fieldMeta.maxlength;
71
70
  if (fieldMeta.validate) {
72
71
  prop.validate = function(value) {
73
- return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? dayjs() : value, this) ?? true;
72
+ return fieldMeta.validate?.(fieldMeta.modelRef === Date && !!value ? dayjs() : value, this) ?? true;
74
73
  };
75
74
  }
76
75
  prop = { type: arraiedModel(prop, fieldMeta.optArrDepth), default: [], required: true };
@@ -102,7 +101,7 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
102
101
  if (typeof fieldMeta.immutable !== "undefined")
103
102
  prop.immutable = fieldMeta.immutable;
104
103
  if (fieldMeta.isClass && !fieldMeta.refPath)
105
- prop.ref = getClassMeta(fieldMeta.modelRef).refName;
104
+ prop.ref = constantInfo.getRefName(fieldMeta.modelRef);
106
105
  if (fieldMeta.refPath)
107
106
  prop.refPath = fieldMeta.refPath;
108
107
  if (typeof fieldMeta.min === "number")
@@ -139,15 +138,15 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
139
138
  }
140
139
  if (fieldMeta.validate) {
141
140
  prop.validate = function(value) {
142
- return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? dayjs() : value, this) ?? true;
141
+ return fieldMeta.validate?.(fieldMeta.modelRef === Date && !!value ? dayjs() : value, this) ?? true;
143
142
  };
144
143
  }
145
144
  }
146
145
  schemaProps[fieldMeta.key] = prop;
147
146
  };
148
147
  const createSchema = (modelRef) => {
149
- const classMeta = getClassMeta(modelRef);
150
- const schemaMeta = getScalarSchemaMetaByName(classMeta.refName);
148
+ const refName = constantInfo.getRefName(modelRef);
149
+ const schemaMeta = getScalarSchemaMetaByName(refName);
151
150
  if (schemaMeta)
152
151
  return schemaMeta;
153
152
  const fieldMetas = getFieldMetas(modelRef);
@@ -156,12 +155,12 @@ const createSchema = (modelRef) => {
156
155
  applyMongoProp(schemaProps, fieldMeta);
157
156
  });
158
157
  const schema = new Schema(schemaProps);
159
- setScalarSchemaMetaByName(classMeta.refName, schema);
158
+ setScalarSchemaMetaByName(refName, schema);
160
159
  return schema;
161
160
  };
162
161
  const schemaOf = (modelRef, docRef, middleware) => {
163
- const classMeta = getClassMeta(docRef);
164
- const schemaMeta = getSchemaMetaByName(classMeta.refName);
162
+ const refName = documentInfo.getRefName(docRef);
163
+ const schemaMeta = getSchemaMetaByName(refName);
165
164
  if (schemaMeta)
166
165
  return schemaMeta;
167
166
  const fieldMetas = getFieldMetas(docRef);
@@ -230,18 +229,17 @@ const schemaOf = (modelRef, docRef, middleware) => {
230
229
  const onSchema = Object.getOwnPropertyDescriptor(middleware.prototype, "onSchema")?.value;
231
230
  onSchema?.(schema);
232
231
  schema.index({ removedAt: -1 });
233
- setSchemaMetaByName(classMeta.refName, schema);
232
+ setSchemaMetaByName(refName, schema);
234
233
  return schema;
235
234
  };
236
235
  const addSchema = (modelRef, docRef, inputRef, middleware) => {
237
- const originDocClassMeta = getClassMeta(docRef);
238
- const originInputClassMeta = getClassMeta(inputRef);
239
- const originDoc = getFullModelRef(originDocClassMeta.refName);
240
- const originInput = getInputModelRef(originInputClassMeta.refName);
241
- const classMeta = getClassMeta(docRef);
242
- const modelSchema = Reflect.getMetadata(classMeta.refName, SchemaStorage.prototype);
236
+ const refName = documentInfo.getRefName(docRef);
237
+ const databaseConstantModelInfo = documentInfo.getDatabase(refName);
238
+ const originDoc = databaseConstantModelInfo.doc;
239
+ const originInput = databaseConstantModelInfo.input;
240
+ const modelSchema = Reflect.getMetadata(refName, SchemaStorage.prototype);
243
241
  if (!modelSchema)
244
- throw new Error(`Schema of ${classMeta.refName} not found`);
242
+ throw new Error(`Schema of ${refName} not found`);
245
243
  const fieldMetas = getFieldMetas(docRef);
246
244
  const schemaProps = {
247
245
  createdAt: {
@@ -10,15 +10,10 @@ var __decorateClass = (decorators, target, key, kind) => {
10
10
  return result;
11
11
  };
12
12
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
13
- import { Logger, lowerlize } from "@akanjs/common";
14
- import {
15
- getCnstMeta,
16
- getFieldMetaMap,
17
- getFieldMetas,
18
- getFilterSortMap,
19
- getFullModelRef
20
- } from "@akanjs/constant";
21
- import { getAllDatabaseModelNames } from "@akanjs/document";
13
+ import { baseEnv } from "@akanjs/base";
14
+ import { capitalize, Logger } from "@akanjs/common";
15
+ import { constantInfo, getFieldMetaMap, getFieldMetas } from "@akanjs/constant";
16
+ import { documentInfo, getFilterSortMap } from "@akanjs/document";
22
17
  import { Global, Inject, Injectable, Module } from "@nestjs/common";
23
18
  import { InjectConnection } from "@nestjs/mongoose";
24
19
  const hasTextField = (modelRef) => {
@@ -87,8 +82,8 @@ const makeTextFilter = (modelRef) => {
87
82
  return filterData;
88
83
  };
89
84
  const getSortableAttributes = (refName) => {
90
- const cnst = getCnstMeta(refName);
91
- const sortMap = getFilterSortMap(cnst.Filter);
85
+ const docInfo = documentInfo.getDatabase(refName);
86
+ const sortMap = getFilterSortMap(docInfo.filter);
92
87
  const sortFields = Object.values(sortMap).filter((val) => typeof val === "object").map((sort) => Object.keys(sort)).flat();
93
88
  return [...new Set(sortFields)];
94
89
  };
@@ -99,14 +94,16 @@ let SearchDaemon = class {
99
94
  }
100
95
  logger = new Logger("SearchDaemon");
101
96
  async onModuleInit() {
102
- const databaseModelNames = getAllDatabaseModelNames();
97
+ if (baseEnv.operationMode === "local")
98
+ return;
99
+ const databaseRefNames = [...constantInfo.database.keys()];
103
100
  const indexes = (await this.meili.getIndexes({ limit: 1e3 })).results;
104
101
  const indexMap = new Map(indexes.map((index) => [index.uid, index]));
105
102
  const indexCreationNames = [];
106
103
  const indexUpdateNames = [];
107
- for (const modelName of databaseModelNames) {
108
- const indexName = lowerlize(modelName);
109
- const modelRef = getFullModelRef(modelName);
104
+ for (const refName of databaseRefNames) {
105
+ const indexName = refName;
106
+ const modelRef = constantInfo.getDatabase(refName).full;
110
107
  if (!hasTextField(modelRef))
111
108
  continue;
112
109
  const index = indexMap.get(indexName);
@@ -119,10 +116,10 @@ let SearchDaemon = class {
119
116
  await this.meili.createIndex(indexName, { primaryKey: "id" });
120
117
  for (const indexName of indexUpdateNames)
121
118
  await this.meili.updateIndex(indexName, { primaryKey: "id" });
122
- for (const modelName of databaseModelNames) {
123
- const indexName = lowerlize(modelName);
124
- const model = this.connection.models[modelName];
125
- const modelRef = getFullModelRef(modelName);
119
+ for (const refName of databaseRefNames) {
120
+ const indexName = refName;
121
+ const model = this.connection.models[capitalize(refName)];
122
+ const modelRef = constantInfo.getDatabase(refName).full;
126
123
  if (!hasTextField(modelRef))
127
124
  continue;
128
125
  const searchIndex = this.meili.index(indexName);
@@ -134,7 +131,7 @@ let SearchDaemon = class {
134
131
  const filterFieldSet = new Set(settings.filterableAttributes);
135
132
  const needUpdateSetting = !allSearchFields.every((field) => searchFieldSet.has(field)) || !allFilterFields.every((field) => filterFieldSet.has(field)) || !settings.searchableAttributes?.every((field) => allSearchFieldSet.has(field)) || !settings.filterableAttributes?.every((field) => allFilterFieldSet.has(field));
136
133
  if (needUpdateSetting) {
137
- this.logger.info(`update index settings (${modelName})`);
134
+ this.logger.info(`update index settings (${refName})`);
138
135
  await searchIndex.updateSettings({
139
136
  searchableAttributes: allSearchFields,
140
137
  filterableAttributes: allFilterFields,
@@ -148,10 +145,10 @@ let SearchDaemon = class {
148
145
  try {
149
146
  const id = data.documentKey._id.toString();
150
147
  if (data.operationType === "delete") {
151
- this.logger.trace(`delete text doc (${modelName}): ${id}`);
148
+ this.logger.trace(`delete text doc (${refName}): ${id}`);
152
149
  return await searchIndex.deleteDocument(id);
153
150
  } else if (data.operationType === "insert") {
154
- this.logger.trace(`insert text doc (${modelName}): ${data.documentKey._id}`);
151
+ this.logger.trace(`insert text doc (${refName}): ${data.documentKey._id}`);
155
152
  if (!data.fullDocument)
156
153
  throw new Error("No fullDocument");
157
154
  const textFilteredData = filterText(data.fullDocument);
@@ -160,10 +157,10 @@ let SearchDaemon = class {
160
157
  const updatedFields = data.updateDescription?.updatedFields ?? {};
161
158
  const isRemoved = !!updatedFields.removedAt;
162
159
  if (isRemoved) {
163
- this.logger.trace(`remove text doc (${modelName}): ${id}`);
160
+ this.logger.trace(`remove text doc (${refName}): ${id}`);
164
161
  return await searchIndex.deleteDocument(id);
165
162
  }
166
- this.logger.trace(`update text doc (${modelName}): ${data.documentKey._id}`);
163
+ this.logger.trace(`update text doc (${refName}): ${data.documentKey._id}`);
167
164
  const updatedFieldKeys = Object.keys(updatedFields);
168
165
  const removedFieldKeys = data.updateDescription?.removedFields ?? [];
169
166
  const isScalarTextFieldUpdated = [...updatedFieldKeys, ...removedFieldKeys].map((key) => key.split(".")[0]).some((key) => scalarTextFieldSet.has(key));
@@ -60,7 +60,7 @@ const websocketOf = (sigRef, allSrvs) => {
60
60
  });
61
61
  const messageGqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Message");
62
62
  for (const gqlMeta of messageGqlMetas) {
63
- const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
63
+ const descriptor = gqlMeta.descriptor;
64
64
  Object.defineProperty(WsGateway.prototype, gqlMeta.key, descriptor);
65
65
  const [argMetas, internalArgMetas] = getArgMetas(sigRef, gqlMeta.key);
66
66
  argMetas.forEach((argMeta) => {
@@ -77,7 +77,7 @@ const websocketOf = (sigRef, allSrvs) => {
77
77
  }
78
78
  const pubsubGqlMetas = getGqlMetas(sigRef).filter((gqlMeta) => gqlMeta.type === "Pubsub");
79
79
  for (const gqlMeta of pubsubGqlMetas) {
80
- const descriptor = { ...Object.getOwnPropertyDescriptor(sigRef.prototype, gqlMeta.key) ?? {} };
80
+ const descriptor = gqlMeta.descriptor;
81
81
  Object.defineProperty(WsGateway.prototype, gqlMeta.key, descriptor);
82
82
  const [argMetas, internalArgMetas] = getArgMetas(sigRef, gqlMeta.key);
83
83
  argMetas.forEach((argMeta) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/server",
3
- "version": "0.9.47",
3
+ "version": "0.9.49",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/module.d.ts CHANGED
@@ -3,7 +3,7 @@ import { type ConstantModel } from "@akanjs/constant";
3
3
  import { Database } from "@akanjs/document";
4
4
  import { DynamicModule } from "@nestjs/common";
5
5
  interface DatabaseModuleCreateOptions {
6
- constant: ConstantModel<string, any, any, any, any, any>;
6
+ constant: ConstantModel<string, any, any, any, any>;
7
7
  database: Database<string, any, any, any, any, any, any, any>;
8
8
  signal: Type;
9
9
  service: Type;
@@ -1,4 +1,4 @@
1
- import type { Type } from "@akanjs/base";
1
+ import { type Type } from "@akanjs/base";
2
2
  import { type TextDoc } from "@akanjs/constant";
3
3
  import type { Types } from "mongoose";
4
4
  export interface ChangedData {