@akanjs/server 0.0.99 → 0.0.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,42 +1,19 @@
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 schema_exports = {};
19
- __export(schema_exports, {
20
- addSchema: () => addSchema,
21
- schemaOf: () => schemaOf
22
- });
23
- module.exports = __toCommonJS(schema_exports);
24
- var import_base = require("@akanjs/base");
25
- var import_common = require("@akanjs/common");
26
- var import_constant = require("@akanjs/constant");
27
- var import_document = require("@akanjs/document");
28
- var import_signal = require("@akanjs/signal");
29
- var import_mongoose = require("mongoose");
30
- var import__ = require(".");
1
+ import { arraiedModel, dayjs, Enum, Float, ID, Int, JSON } from "@akanjs/base";
2
+ import { isDayjs } from "@akanjs/common";
3
+ import { getClassMeta, getFieldMetas, getFullModelRef, getInputModelRef } from "@akanjs/constant";
4
+ import { getDefaultSchemaOptions, ObjectId } from "@akanjs/document";
5
+ import { makeDefault } from "@akanjs/signal";
6
+ import { Schema, Types } from "mongoose";
7
+ import { applyNestField } from ".";
31
8
  class ScalarSchemaStorage {
32
9
  }
33
10
  class SchemaStorage {
34
11
  }
35
12
  const scalarMongoTypeMap = /* @__PURE__ */ new Map([
36
- [import_base.ID, import_document.ObjectId],
37
- [import_base.Int, Number],
38
- [import_base.Float, Number],
39
- [import_base.JSON, import_mongoose.Schema.Types.Mixed],
13
+ [ID, ObjectId],
14
+ [Int, Number],
15
+ [Float, Number],
16
+ [JSON, Schema.Types.Mixed],
40
17
  [Map, Map],
41
18
  [String, String],
42
19
  [Boolean, Boolean],
@@ -45,13 +22,13 @@ const scalarMongoTypeMap = /* @__PURE__ */ new Map([
45
22
  const applyMongoProp = (schemaProps, fieldMeta) => {
46
23
  if (["id", "createdAt", "updatedAt"].includes(fieldMeta.key) || fieldMeta.fieldType === "resolve")
47
24
  return;
48
- const type = fieldMeta.isClass ? fieldMeta.isScalar ? createSchema(fieldMeta.modelRef) : import_document.ObjectId : scalarMongoTypeMap.get(fieldMeta.modelRef) ?? fieldMeta.modelRef;
25
+ const type = fieldMeta.isClass ? fieldMeta.isScalar ? createSchema(fieldMeta.modelRef) : ObjectId : scalarMongoTypeMap.get(fieldMeta.modelRef) ?? fieldMeta.modelRef;
49
26
  let prop = {};
50
27
  if (fieldMeta.optArrDepth) {
51
28
  prop.type = type;
52
29
  prop.required = true;
53
30
  if (fieldMeta.isClass && !fieldMeta.refPath)
54
- prop.ref = (0, import_constant.getClassMeta)(fieldMeta.modelRef).refName;
31
+ prop.ref = getClassMeta(fieldMeta.modelRef).refName;
55
32
  if (fieldMeta.refPath)
56
33
  prop.refPath = fieldMeta.refPath;
57
34
  if (typeof fieldMeta.min === "number")
@@ -66,20 +43,20 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
66
43
  prop.maxlength = fieldMeta.maxlength;
67
44
  if (fieldMeta.validate) {
68
45
  prop.validate = function(value) {
69
- return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? (0, import_base.dayjs)() : value, this) ?? true;
46
+ return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? dayjs() : value, this) ?? true;
70
47
  };
71
48
  }
72
- prop = { type: (0, import_base.arraiedModel)(prop, fieldMeta.optArrDepth), default: [], required: true };
49
+ prop = { type: arraiedModel(prop, fieldMeta.optArrDepth), default: [], required: true };
73
50
  if (fieldMeta.modelRef.prototype === Date.prototype) {
74
- prop.get = (dates) => dates.map((date) => (0, import_base.dayjs)(date));
51
+ prop.get = (dates) => dates.map((date) => dayjs(date));
75
52
  prop.set = (days) => days.map((day) => day.toDate());
76
53
  }
77
- if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === import_base.ID.prototype) {
54
+ if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === ID.prototype) {
78
55
  prop.get = (ids) => ids.map((id) => id.toString());
79
- prop.set = (ids) => ids.map((id) => new import_mongoose.Types.ObjectId(id));
56
+ prop.set = (ids) => ids.map((id) => new Types.ObjectId(id));
80
57
  }
81
58
  } else {
82
- prop.type = (0, import_base.arraiedModel)(type, fieldMeta.arrDepth);
59
+ prop.type = arraiedModel(type, fieldMeta.arrDepth);
83
60
  prop.required = !fieldMeta.nullable;
84
61
  if (fieldMeta.isMap) {
85
62
  prop.of = scalarMongoTypeMap.get(fieldMeta.of) ?? createSchema(fieldMeta.of);
@@ -90,15 +67,15 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
90
67
  if (typeof fieldMeta.default === "function")
91
68
  prop.default = function() {
92
69
  const def = fieldMeta.default(this);
93
- return (0, import_common.isDayjs)(def) ? def.toDate() : def;
70
+ return isDayjs(def) ? def.toDate() : def;
94
71
  };
95
72
  else
96
- prop.default = (0, import_common.isDayjs)(fieldMeta.default) ? fieldMeta.default.toDate() : fieldMeta.default instanceof import_base.Enum ? [...fieldMeta.default.values] : fieldMeta.default;
73
+ prop.default = isDayjs(fieldMeta.default) ? fieldMeta.default.toDate() : fieldMeta.default instanceof Enum ? [...fieldMeta.default.values] : fieldMeta.default;
97
74
  }
98
75
  if (typeof fieldMeta.immutable !== "undefined")
99
76
  prop.immutable = fieldMeta.immutable;
100
77
  if (fieldMeta.isClass && !fieldMeta.refPath)
101
- prop.ref = (0, import_constant.getClassMeta)(fieldMeta.modelRef).refName;
78
+ prop.ref = getClassMeta(fieldMeta.modelRef).refName;
102
79
  if (fieldMeta.refPath)
103
80
  prop.refPath = fieldMeta.refPath;
104
81
  if (typeof fieldMeta.min === "number")
@@ -118,60 +95,60 @@ const applyMongoProp = (schemaProps, fieldMeta) => {
118
95
  prop.set = (v) => v === null ? void 0 : v;
119
96
  }
120
97
  if (fieldMeta.modelRef.prototype === Date.prototype) {
121
- prop.get = (date) => date ? (0, import_base.dayjs)(date) : void 0;
122
- prop.set = (day) => day ? (0, import_base.dayjs)(day).toDate() : void 0;
98
+ prop.get = (date) => date ? dayjs(date) : void 0;
99
+ prop.set = (day) => day ? dayjs(day).toDate() : void 0;
123
100
  }
124
- if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === import_base.ID.prototype) {
101
+ if (fieldMeta.isClass && !fieldMeta.isScalar || fieldMeta.modelRef.prototype === ID.prototype) {
125
102
  prop.get = (id) => id ? id.toString() : void 0;
126
- prop.set = (id) => id ? new import_mongoose.Types.ObjectId(id) : void 0;
103
+ prop.set = (id) => id ? new Types.ObjectId(id) : void 0;
127
104
  }
128
105
  if (fieldMeta.isClass && fieldMeta.isScalar && fieldMeta.default === null && !fieldMeta.nullable) {
129
- prop.default = (0, import_signal.makeDefault)(fieldMeta.modelRef);
106
+ prop.default = makeDefault(fieldMeta.modelRef);
130
107
  }
131
108
  if (fieldMeta.validate) {
132
109
  prop.validate = function(value) {
133
- return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? (0, import_base.dayjs)() : value, this) ?? true;
110
+ return fieldMeta.validate?.(fieldMeta.name === "Date" && !!value ? dayjs() : value, this) ?? true;
134
111
  };
135
112
  }
136
113
  }
137
114
  schemaProps[fieldMeta.key] = prop;
138
115
  };
139
116
  const createSchema = (modelRef) => {
140
- const classMeta = (0, import_constant.getClassMeta)(modelRef);
117
+ const classMeta = getClassMeta(modelRef);
141
118
  const schemaMeta = Reflect.getMetadata(classMeta.refName, ScalarSchemaStorage.prototype);
142
119
  if (schemaMeta)
143
120
  return schemaMeta;
144
- const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
121
+ const fieldMetas = getFieldMetas(modelRef);
145
122
  const schemaProps = {};
146
123
  fieldMetas.forEach((fieldMeta) => {
147
124
  applyMongoProp(schemaProps, fieldMeta);
148
125
  });
149
- const schema = new import_mongoose.Schema(schemaProps);
126
+ const schema = new Schema(schemaProps);
150
127
  Reflect.defineMetadata(classMeta.refName, schema, ScalarSchemaStorage.prototype);
151
128
  return schema;
152
129
  };
153
130
  const schemaOf = (modelRef, docRef, middleware) => {
154
- const classMeta = (0, import_constant.getClassMeta)(docRef);
131
+ const classMeta = getClassMeta(docRef);
155
132
  const schemaMeta = Reflect.getMetadata(classMeta.refName, SchemaStorage.prototype);
156
133
  if (schemaMeta)
157
134
  return schemaMeta;
158
- const fieldMetas = (0, import_constant.getFieldMetas)(docRef);
135
+ const fieldMetas = getFieldMetas(docRef);
159
136
  const schemaProps = {
160
137
  createdAt: {
161
138
  type: Date,
162
- get: (date) => date ? (0, import_base.dayjs)(date) : date,
163
- set: (day) => day ? (0, import_base.dayjs)(day).toDate() : day
139
+ get: (date) => date ? dayjs(date) : date,
140
+ set: (day) => day ? dayjs(day).toDate() : day
164
141
  },
165
142
  updatedAt: {
166
143
  type: Date,
167
- get: (date) => date ? (0, import_base.dayjs)(date) : date,
168
- set: (day) => day ? (0, import_base.dayjs)(day).toDate() : day
144
+ get: (date) => date ? dayjs(date) : date,
145
+ set: (day) => day ? dayjs(day).toDate() : day
169
146
  }
170
147
  };
171
148
  fieldMetas.forEach((fieldMeta) => {
172
149
  applyMongoProp(schemaProps, fieldMeta);
173
150
  });
174
- const schema = new import_mongoose.Schema(schemaProps, (0, import_document.getDefaultSchemaOptions)());
151
+ const schema = new Schema(schemaProps, getDefaultSchemaOptions());
175
152
  schema.methods.refresh = async function() {
176
153
  Object.assign(this, await this.constructor.findById(this._id));
177
154
  return this;
@@ -196,36 +173,36 @@ const schemaOf = (modelRef, docRef, middleware) => {
196
173
  return schema;
197
174
  };
198
175
  const addSchema = (modelRef, docRef, inputRef, middleware) => {
199
- const originDocClassMeta = (0, import_constant.getClassMeta)(docRef);
200
- const originInputClassMeta = (0, import_constant.getClassMeta)(inputRef);
201
- const originDoc = (0, import_constant.getFullModelRef)(originDocClassMeta.refName);
202
- const originInput = (0, import_constant.getInputModelRef)(originInputClassMeta.refName);
203
- const classMeta = (0, import_constant.getClassMeta)(docRef);
176
+ const originDocClassMeta = getClassMeta(docRef);
177
+ const originInputClassMeta = getClassMeta(inputRef);
178
+ const originDoc = getFullModelRef(originDocClassMeta.refName);
179
+ const originInput = getInputModelRef(originInputClassMeta.refName);
180
+ const classMeta = getClassMeta(docRef);
204
181
  const modelSchema = Reflect.getMetadata(classMeta.refName, SchemaStorage.prototype);
205
182
  if (!modelSchema)
206
183
  throw new Error(`Schema of ${classMeta.refName} not found`);
207
- const fieldMetas = (0, import_constant.getFieldMetas)(docRef);
184
+ const fieldMetas = getFieldMetas(docRef);
208
185
  const schemaProps = {
209
186
  createdAt: {
210
187
  type: Date,
211
- get: (date) => date ? (0, import_base.dayjs)(date) : date,
212
- set: (day) => day ? (0, import_base.dayjs)(day).toDate() : day
188
+ get: (date) => date ? dayjs(date) : date,
189
+ set: (day) => day ? dayjs(day).toDate() : day
213
190
  },
214
191
  updatedAt: {
215
192
  type: Date,
216
- get: (date) => date ? (0, import_base.dayjs)(date) : date,
217
- set: (day) => day ? (0, import_base.dayjs)(day).toDate() : day
193
+ get: (date) => date ? dayjs(date) : date,
194
+ set: (day) => day ? dayjs(day).toDate() : day
218
195
  }
219
196
  };
220
197
  fieldMetas.forEach((fieldMeta) => {
221
198
  applyMongoProp(schemaProps, fieldMeta);
222
- (0, import__.applyNestField)(originDoc, fieldMeta);
199
+ applyNestField(originDoc, fieldMeta);
223
200
  });
224
- const inputFieldMetas = (0, import_constant.getFieldMetas)(inputRef);
201
+ const inputFieldMetas = getFieldMetas(inputRef);
225
202
  inputFieldMetas.forEach((fieldMeta) => {
226
- (0, import__.applyNestField)(originInput, fieldMeta, "input");
203
+ applyNestField(originInput, fieldMeta, "input");
227
204
  });
228
- const schema = new import_mongoose.Schema(schemaProps, (0, import_document.getDefaultSchemaOptions)());
205
+ const schema = new Schema(schemaProps, getDefaultSchemaOptions());
229
206
  modelSchema.add(schema);
230
207
  Object.getOwnPropertyNames(docRef.prototype).forEach((name) => {
231
208
  if (name === "constructor")
@@ -236,8 +213,7 @@ const addSchema = (modelRef, docRef, inputRef, middleware) => {
236
213
  onSchema?.(modelSchema);
237
214
  return modelSchema;
238
215
  };
239
- // Annotate the CommonJS export names for ESM import in node:
240
- 0 && (module.exports = {
216
+ export {
241
217
  addSchema,
242
218
  schemaOf
243
- });
219
+ };
@@ -1,5 +1,20 @@
1
1
  var __defProp = Object.defineProperty;
2
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);
3
18
  var __decorateClass = (decorators, target, key, kind) => {
4
19
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
20
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
@@ -10,19 +25,19 @@ var __decorateClass = (decorators, target, key, kind) => {
10
25
  return result;
11
26
  };
12
27
  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";
22
- import { Global, Inject, Injectable, Module } from "@nestjs/common";
23
- import { InjectConnection } from "@nestjs/mongoose";
28
+ var searchDaemon_exports = {};
29
+ __export(searchDaemon_exports, {
30
+ SearchDaemonModule: () => SearchDaemonModule,
31
+ makeTextFilter: () => makeTextFilter
32
+ });
33
+ module.exports = __toCommonJS(searchDaemon_exports);
34
+ var import_common = require("@akanjs/common");
35
+ var import_constant = require("@akanjs/constant");
36
+ var import_document = require("@akanjs/document");
37
+ var import_common2 = require("@nestjs/common");
38
+ var import_mongoose = require("@nestjs/mongoose");
24
39
  const hasTextField = (modelRef) => {
25
- const fieldMetas = getFieldMetas(modelRef);
40
+ const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
26
41
  return fieldMetas.some(
27
42
  (fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
28
43
  );
@@ -30,7 +45,7 @@ const hasTextField = (modelRef) => {
30
45
  const getTextFieldKeys = (modelRef) => {
31
46
  const allSearchFields = [];
32
47
  const allFilterFields = [];
33
- const fieldMetaMap = getFieldMetaMap(modelRef);
48
+ const fieldMetaMap = (0, import_constant.getFieldMetaMap)(modelRef);
34
49
  const fieldMetas = [...fieldMetaMap.values()];
35
50
  const stringTextFields = fieldMetas.filter((fieldMeta) => !!fieldMeta.text).map((fieldMeta) => {
36
51
  if (fieldMeta.text === "filter")
@@ -65,7 +80,7 @@ const getTextFieldKeys = (modelRef) => {
65
80
  };
66
81
  };
67
82
  const makeTextFilter = (modelRef) => {
68
- const fieldMetaMap = getFieldMetaMap(modelRef);
83
+ const fieldMetaMap = (0, import_constant.getFieldMetaMap)(modelRef);
69
84
  const { stringTextFields, scalarTextFields } = getTextFieldKeys(modelRef);
70
85
  const filterData = (data, assignObj = {}) => {
71
86
  if (Array.isArray(data))
@@ -87,8 +102,8 @@ const makeTextFilter = (modelRef) => {
87
102
  return filterData;
88
103
  };
89
104
  const getSortableAttributes = (refName) => {
90
- const cnst = getCnstMeta(refName);
91
- const sortMap = getFilterSortMap(cnst.Filter);
105
+ const cnst = (0, import_constant.getCnstMeta)(refName);
106
+ const sortMap = (0, import_constant.getFilterSortMap)(cnst.Filter);
92
107
  const sortFields = Object.values(sortMap).filter((val) => typeof val === "object").map((sort) => Object.keys(sort)).flat();
93
108
  return [...new Set(sortFields)];
94
109
  };
@@ -97,16 +112,16 @@ let SearchDaemon = class {
97
112
  this.connection = connection;
98
113
  this.meili = meili;
99
114
  }
100
- logger = new Logger("SearchDaemon");
115
+ logger = new import_common.Logger("SearchDaemon");
101
116
  async onModuleInit() {
102
- const databaseModelNames = getAllDatabaseModelNames();
117
+ const databaseModelNames = (0, import_document.getAllDatabaseModelNames)();
103
118
  const indexes = (await this.meili.getIndexes({ limit: 1e3 })).results;
104
119
  const indexMap = new Map(indexes.map((index) => [index.uid, index]));
105
120
  const indexCreationNames = [];
106
121
  const indexUpdateNames = [];
107
122
  for (const modelName of databaseModelNames) {
108
- const indexName = lowerlize(modelName);
109
- const modelRef = getFullModelRef(modelName);
123
+ const indexName = (0, import_common.lowerlize)(modelName);
124
+ const modelRef = (0, import_constant.getFullModelRef)(modelName);
110
125
  if (!hasTextField(modelRef))
111
126
  continue;
112
127
  const index = indexMap.get(indexName);
@@ -120,9 +135,9 @@ let SearchDaemon = class {
120
135
  for (const indexName of indexUpdateNames)
121
136
  await this.meili.updateIndex(indexName, { primaryKey: "id" });
122
137
  for (const modelName of databaseModelNames) {
123
- const indexName = lowerlize(modelName);
138
+ const indexName = (0, import_common.lowerlize)(modelName);
124
139
  const model = this.connection.models[modelName];
125
- const modelRef = getFullModelRef(modelName);
140
+ const modelRef = (0, import_constant.getFullModelRef)(modelName);
126
141
  if (!hasTextField(modelRef))
127
142
  continue;
128
143
  const searchIndex = this.meili.index(indexName);
@@ -194,19 +209,20 @@ let SearchDaemon = class {
194
209
  }
195
210
  };
196
211
  SearchDaemon = __decorateClass([
197
- Injectable(),
198
- __decorateParam(0, InjectConnection()),
199
- __decorateParam(1, Inject("MEILI_CLIENT"))
212
+ (0, import_common2.Injectable)(),
213
+ __decorateParam(0, (0, import_mongoose.InjectConnection)()),
214
+ __decorateParam(1, (0, import_common2.Inject)("MEILI_CLIENT"))
200
215
  ], SearchDaemon);
201
216
  let SearchDaemonModule = class {
202
217
  };
203
218
  SearchDaemonModule = __decorateClass([
204
- Global(),
205
- Module({
219
+ (0, import_common2.Global)(),
220
+ (0, import_common2.Module)({
206
221
  providers: [SearchDaemon]
207
222
  })
208
223
  ], SearchDaemonModule);
209
- export {
224
+ // Annotate the CommonJS export names for ESM import in node:
225
+ 0 && (module.exports = {
210
226
  SearchDaemonModule,
211
227
  makeTextFilter
212
- };
228
+ });
@@ -1,20 +1,5 @@
1
1
  var __defProp = Object.defineProperty;
2
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
3
  var __decorateClass = (decorators, target, key, kind) => {
19
4
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
20
5
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
@@ -25,19 +10,19 @@ var __decorateClass = (decorators, target, key, kind) => {
25
10
  return result;
26
11
  };
27
12
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
28
- var searchDaemon_exports = {};
29
- __export(searchDaemon_exports, {
30
- SearchDaemonModule: () => SearchDaemonModule,
31
- makeTextFilter: () => makeTextFilter
32
- });
33
- module.exports = __toCommonJS(searchDaemon_exports);
34
- var import_common = require("@akanjs/common");
35
- var import_constant = require("@akanjs/constant");
36
- var import_document = require("@akanjs/document");
37
- var import_common2 = require("@nestjs/common");
38
- var import_mongoose = require("@nestjs/mongoose");
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";
22
+ import { Global, Inject, Injectable, Module } from "@nestjs/common";
23
+ import { InjectConnection } from "@nestjs/mongoose";
39
24
  const hasTextField = (modelRef) => {
40
- const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
25
+ const fieldMetas = getFieldMetas(modelRef);
41
26
  return fieldMetas.some(
42
27
  (fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
43
28
  );
@@ -45,7 +30,7 @@ const hasTextField = (modelRef) => {
45
30
  const getTextFieldKeys = (modelRef) => {
46
31
  const allSearchFields = [];
47
32
  const allFilterFields = [];
48
- const fieldMetaMap = (0, import_constant.getFieldMetaMap)(modelRef);
33
+ const fieldMetaMap = getFieldMetaMap(modelRef);
49
34
  const fieldMetas = [...fieldMetaMap.values()];
50
35
  const stringTextFields = fieldMetas.filter((fieldMeta) => !!fieldMeta.text).map((fieldMeta) => {
51
36
  if (fieldMeta.text === "filter")
@@ -80,7 +65,7 @@ const getTextFieldKeys = (modelRef) => {
80
65
  };
81
66
  };
82
67
  const makeTextFilter = (modelRef) => {
83
- const fieldMetaMap = (0, import_constant.getFieldMetaMap)(modelRef);
68
+ const fieldMetaMap = getFieldMetaMap(modelRef);
84
69
  const { stringTextFields, scalarTextFields } = getTextFieldKeys(modelRef);
85
70
  const filterData = (data, assignObj = {}) => {
86
71
  if (Array.isArray(data))
@@ -102,8 +87,8 @@ const makeTextFilter = (modelRef) => {
102
87
  return filterData;
103
88
  };
104
89
  const getSortableAttributes = (refName) => {
105
- const cnst = (0, import_constant.getCnstMeta)(refName);
106
- const sortMap = (0, import_constant.getFilterSortMap)(cnst.Filter);
90
+ const cnst = getCnstMeta(refName);
91
+ const sortMap = getFilterSortMap(cnst.Filter);
107
92
  const sortFields = Object.values(sortMap).filter((val) => typeof val === "object").map((sort) => Object.keys(sort)).flat();
108
93
  return [...new Set(sortFields)];
109
94
  };
@@ -112,16 +97,16 @@ let SearchDaemon = class {
112
97
  this.connection = connection;
113
98
  this.meili = meili;
114
99
  }
115
- logger = new import_common.Logger("SearchDaemon");
100
+ logger = new Logger("SearchDaemon");
116
101
  async onModuleInit() {
117
- const databaseModelNames = (0, import_document.getAllDatabaseModelNames)();
102
+ const databaseModelNames = getAllDatabaseModelNames();
118
103
  const indexes = (await this.meili.getIndexes({ limit: 1e3 })).results;
119
104
  const indexMap = new Map(indexes.map((index) => [index.uid, index]));
120
105
  const indexCreationNames = [];
121
106
  const indexUpdateNames = [];
122
107
  for (const modelName of databaseModelNames) {
123
- const indexName = (0, import_common.lowerlize)(modelName);
124
- const modelRef = (0, import_constant.getFullModelRef)(modelName);
108
+ const indexName = lowerlize(modelName);
109
+ const modelRef = getFullModelRef(modelName);
125
110
  if (!hasTextField(modelRef))
126
111
  continue;
127
112
  const index = indexMap.get(indexName);
@@ -135,9 +120,9 @@ let SearchDaemon = class {
135
120
  for (const indexName of indexUpdateNames)
136
121
  await this.meili.updateIndex(indexName, { primaryKey: "id" });
137
122
  for (const modelName of databaseModelNames) {
138
- const indexName = (0, import_common.lowerlize)(modelName);
123
+ const indexName = lowerlize(modelName);
139
124
  const model = this.connection.models[modelName];
140
- const modelRef = (0, import_constant.getFullModelRef)(modelName);
125
+ const modelRef = getFullModelRef(modelName);
141
126
  if (!hasTextField(modelRef))
142
127
  continue;
143
128
  const searchIndex = this.meili.index(indexName);
@@ -209,20 +194,19 @@ let SearchDaemon = class {
209
194
  }
210
195
  };
211
196
  SearchDaemon = __decorateClass([
212
- (0, import_common2.Injectable)(),
213
- __decorateParam(0, (0, import_mongoose.InjectConnection)()),
214
- __decorateParam(1, (0, import_common2.Inject)("MEILI_CLIENT"))
197
+ Injectable(),
198
+ __decorateParam(0, InjectConnection()),
199
+ __decorateParam(1, Inject("MEILI_CLIENT"))
215
200
  ], SearchDaemon);
216
201
  let SearchDaemonModule = class {
217
202
  };
218
203
  SearchDaemonModule = __decorateClass([
219
- (0, import_common2.Global)(),
220
- (0, import_common2.Module)({
204
+ Global(),
205
+ Module({
221
206
  providers: [SearchDaemon]
222
207
  })
223
208
  ], SearchDaemonModule);
224
- // Annotate the CommonJS export names for ESM import in node:
225
- 0 && (module.exports = {
209
+ export {
226
210
  SearchDaemonModule,
227
211
  makeTextFilter
228
- });
212
+ };
package/src/types.js CHANGED
@@ -0,0 +1,15 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var types_exports = {};
15
+ module.exports = __toCommonJS(types_exports);
package/src/types.mjs ADDED
File without changes