@akanjs/document 0.0.97 → 0.0.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +21 -0
- package/index.js +1 -21
- package/package.json +4 -4
- package/src/dataLoader.cjs +152 -0
- package/src/dataLoader.js +19 -61
- package/src/{database.mjs → database.cjs} +64 -47
- package/src/database.js +47 -64
- package/src/{dbDecorators.mjs → dbDecorators.cjs} +43 -14
- package/src/dbDecorators.js +14 -43
- package/src/index.cjs +29 -0
- package/src/index.js +5 -29
- package/src/{schema.mjs → schema.cjs} +33 -9
- package/src/schema.js +9 -33
- package/src/types.cjs +15 -0
- package/src/types.js +0 -15
- package/index.mjs +0 -1
- package/src/dataLoader.mjs +0 -110
- package/src/index.mjs +0 -5
- package/src/types.mjs +0 -0
package/src/database.js
CHANGED
|
@@ -1,36 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 database_exports = {};
|
|
19
|
-
__export(database_exports, {
|
|
20
|
-
databaseModelOf: () => databaseModelOf
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(database_exports);
|
|
23
|
-
var import_base = require("@akanjs/base");
|
|
24
|
-
var import_common = require("@akanjs/common");
|
|
25
|
-
var import_constant = require("@akanjs/constant");
|
|
26
|
-
var import_nest = require("@akanjs/nest");
|
|
27
|
-
var import_dataLoader = require("./dataLoader");
|
|
28
|
-
var import_schema = require("./schema");
|
|
1
|
+
import { dayjs } from "@akanjs/base";
|
|
2
|
+
import { capitalize, Logger, lowerlize } from "@akanjs/common";
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_PAGE_SIZE,
|
|
5
|
+
getFieldMetas,
|
|
6
|
+
getFilterKeyMetaMapOnPrototype,
|
|
7
|
+
getFilterQuery,
|
|
8
|
+
getFilterSort
|
|
9
|
+
} from "@akanjs/constant";
|
|
10
|
+
import { Transaction } from "@akanjs/nest";
|
|
11
|
+
import { createArrayLoader, createLoader, createQueryLoader, getLoaderMetas } from "./dataLoader";
|
|
12
|
+
import { convertAggregateMatch } from "./schema";
|
|
29
13
|
class CacheDatabase {
|
|
30
14
|
constructor(refName, redis) {
|
|
31
15
|
this.refName = refName;
|
|
32
16
|
this.redis = redis;
|
|
33
|
-
this.logger = new
|
|
17
|
+
this.logger = new Logger(`${refName}Cache`);
|
|
34
18
|
}
|
|
35
19
|
logger;
|
|
36
20
|
async set(topic, key, value, option = {}) {
|
|
@@ -49,13 +33,13 @@ class SearchDatabase {
|
|
|
49
33
|
constructor(refName, meili) {
|
|
50
34
|
this.refName = refName;
|
|
51
35
|
this.meili = meili;
|
|
52
|
-
this.logger = new
|
|
53
|
-
this.index = meili.index(
|
|
36
|
+
this.logger = new Logger(`${refName}Search`);
|
|
37
|
+
this.index = meili.index(lowerlize(refName));
|
|
54
38
|
}
|
|
55
39
|
logger;
|
|
56
40
|
index;
|
|
57
41
|
async searchIds(searchText, option = {}) {
|
|
58
|
-
const { skip = 0, limit =
|
|
42
|
+
const { skip = 0, limit = DEFAULT_PAGE_SIZE, sort } = option;
|
|
59
43
|
if (!searchText) {
|
|
60
44
|
const { results, total } = await this.index.getDocuments({ offset: skip ?? 0, limit: limit ?? 0 });
|
|
61
45
|
return { ids: results.map((result) => result.id), total };
|
|
@@ -70,7 +54,7 @@ class SearchDatabase {
|
|
|
70
54
|
return { ids: hits.map((hit) => hit.id), total: estimatedTotalHits };
|
|
71
55
|
}
|
|
72
56
|
async count(searchText, option = {}) {
|
|
73
|
-
const { skip = 0, limit =
|
|
57
|
+
const { skip = 0, limit = DEFAULT_PAGE_SIZE, sort = "" } = option;
|
|
74
58
|
if (!searchText) {
|
|
75
59
|
const { results, total } = await this.index.getDocuments({ offset: skip ?? 0, limit: limit ?? 0 });
|
|
76
60
|
return total;
|
|
@@ -89,40 +73,40 @@ class DatabaseModelStorage {
|
|
|
89
73
|
}
|
|
90
74
|
const databaseModelOf = (database, model, redis, meili) => {
|
|
91
75
|
//! 잘되는지 확인 필요
|
|
92
|
-
const [modelName, className] = [database.refName,
|
|
93
|
-
const insightFieldMetas =
|
|
76
|
+
const [modelName, className] = [database.refName, capitalize(database.refName)];
|
|
77
|
+
const insightFieldMetas = getFieldMetas(database.Insight);
|
|
94
78
|
const accumulator = Object.fromEntries(insightFieldMetas.map((fieldMeta) => [fieldMeta.key, fieldMeta.accumulate]));
|
|
95
79
|
const defaultInsight = Object.fromEntries(insightFieldMetas.map((fieldMeta) => [fieldMeta.key, fieldMeta.default]));
|
|
96
80
|
const makeSafeQuery = (query) => ({ removedAt: { $exists: false }, ...query ?? {} });
|
|
97
81
|
const makeSafeMatchStage = (query) => ({
|
|
98
|
-
$match: { removedAt: { $exists: false }, ...
|
|
82
|
+
$match: { removedAt: { $exists: false }, ...convertAggregateMatch(query) }
|
|
99
83
|
});
|
|
100
84
|
const getListQuery = (query, queryOption) => {
|
|
101
85
|
const find = makeSafeQuery(query);
|
|
102
|
-
const sort =
|
|
86
|
+
const sort = getFilterSort(database.Filter, queryOption?.sort ?? "latest");
|
|
103
87
|
const skip = queryOption?.skip ?? 0;
|
|
104
|
-
const limit = queryOption?.limit === null ?
|
|
88
|
+
const limit = queryOption?.limit === null ? DEFAULT_PAGE_SIZE : queryOption?.limit ?? 0;
|
|
105
89
|
const select = queryOption?.select;
|
|
106
90
|
const sample = queryOption?.sample;
|
|
107
91
|
return { find, sort, skip, limit, select, sample };
|
|
108
92
|
};
|
|
109
93
|
const getFindQuery = (query, queryOption) => {
|
|
110
94
|
const find = makeSafeQuery(query);
|
|
111
|
-
const sort =
|
|
95
|
+
const sort = getFilterSort(database.Filter, queryOption?.sort ?? "latest");
|
|
112
96
|
const skip = queryOption?.skip ?? 0;
|
|
113
97
|
const select = queryOption?.select;
|
|
114
98
|
const sample = queryOption?.sample ?? false;
|
|
115
99
|
return { find, sort, skip, select, sample };
|
|
116
100
|
};
|
|
117
101
|
const getSearchSort = (sortKey) => {
|
|
118
|
-
const sort =
|
|
102
|
+
const sort = getFilterSort(database.Filter, sortKey ?? "latest");
|
|
119
103
|
return Object.entries(sort).map(([key, value]) => `${key}:${value === 1 ? "asc" : "desc"}`);
|
|
120
104
|
};
|
|
121
|
-
const loader =
|
|
105
|
+
const loader = createLoader(model);
|
|
122
106
|
const cacheDatabase = new CacheDatabase(database.refName, redis);
|
|
123
107
|
const searchDatabase = new SearchDatabase(database.refName, meili);
|
|
124
108
|
const DatabaseModel = Reflect.getMetadata(database.refName, DatabaseModelStorage.prototype) ?? class DatabaseModel {
|
|
125
|
-
logger = new
|
|
109
|
+
logger = new Logger(`${modelName}Model`);
|
|
126
110
|
__model = model;
|
|
127
111
|
__cache = cacheDatabase;
|
|
128
112
|
__search = searchDatabase;
|
|
@@ -185,7 +169,7 @@ const databaseModelOf = (database, model, redis, meili) => {
|
|
|
185
169
|
async getDefaultSummary(addQuery = {}) {
|
|
186
170
|
if (!database.Summary)
|
|
187
171
|
return {};
|
|
188
|
-
const fieldMetas =
|
|
172
|
+
const fieldMetas = getFieldMetas(database.Summary);
|
|
189
173
|
const summary = {};
|
|
190
174
|
await Promise.all(
|
|
191
175
|
fieldMetas.filter((fieldMeta) => !!fieldMeta.query).map(async (fieldMeta) => {
|
|
@@ -216,7 +200,7 @@ const databaseModelOf = (database, model, redis, meili) => {
|
|
|
216
200
|
}
|
|
217
201
|
async [`remove${className}`](id) {
|
|
218
202
|
const doc = await this.__model.pickById(id);
|
|
219
|
-
return await doc.set({ removedAt:
|
|
203
|
+
return await doc.set({ removedAt: dayjs() }).save();
|
|
220
204
|
}
|
|
221
205
|
async [`search${className}`](searchText, queryOption = {}) {
|
|
222
206
|
const { skip, limit, sort } = queryOption;
|
|
@@ -240,55 +224,55 @@ const databaseModelOf = (database, model, redis, meili) => {
|
|
|
240
224
|
const getQueryDataFromKey = (queryKey, args) => {
|
|
241
225
|
const lastArg = args.at(-1);
|
|
242
226
|
const hasQueryOption = lastArg && typeof lastArg === "object" && (typeof lastArg.select === "object" || typeof lastArg.skip === "number" || typeof lastArg.limit === "number" || typeof lastArg.sort === "string");
|
|
243
|
-
const queryFn =
|
|
227
|
+
const queryFn = getFilterQuery(database.Filter, queryKey);
|
|
244
228
|
const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
|
|
245
229
|
const queryOption = hasQueryOption ? lastArg : {};
|
|
246
230
|
return { query, queryOption };
|
|
247
231
|
};
|
|
248
|
-
const filterKeyMetaMap =
|
|
232
|
+
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(database.Filter.prototype);
|
|
249
233
|
const queryKeys = [...filterKeyMetaMap.keys()];
|
|
250
234
|
queryKeys.forEach((queryKey) => {
|
|
251
|
-
const queryFn =
|
|
252
|
-
DatabaseModel.prototype[`list${
|
|
235
|
+
const queryFn = getFilterQuery(database.Filter, queryKey);
|
|
236
|
+
DatabaseModel.prototype[`list${capitalize(queryKey)}`] = async function(...args) {
|
|
253
237
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
254
238
|
return this.__list(query, queryOption);
|
|
255
239
|
};
|
|
256
|
-
DatabaseModel.prototype[`listIds${
|
|
240
|
+
DatabaseModel.prototype[`listIds${capitalize(queryKey)}`] = async function(...args) {
|
|
257
241
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
258
242
|
return this.__listIds(query, queryOption);
|
|
259
243
|
};
|
|
260
|
-
DatabaseModel.prototype[`find${
|
|
244
|
+
DatabaseModel.prototype[`find${capitalize(queryKey)}`] = async function(...args) {
|
|
261
245
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
262
246
|
return this.__find(query, queryOption);
|
|
263
247
|
};
|
|
264
|
-
DatabaseModel.prototype[`findId${
|
|
248
|
+
DatabaseModel.prototype[`findId${capitalize(queryKey)}`] = async function(...args) {
|
|
265
249
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
266
250
|
return this.__findId(query, queryOption);
|
|
267
251
|
};
|
|
268
|
-
DatabaseModel.prototype[`pick${
|
|
252
|
+
DatabaseModel.prototype[`pick${capitalize(queryKey)}`] = async function(...args) {
|
|
269
253
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
270
254
|
return this.__pick(query, queryOption);
|
|
271
255
|
};
|
|
272
|
-
DatabaseModel.prototype[`pickId${
|
|
256
|
+
DatabaseModel.prototype[`pickId${capitalize(queryKey)}`] = async function(...args) {
|
|
273
257
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
274
258
|
return this.__pickId(query, queryOption);
|
|
275
259
|
};
|
|
276
|
-
DatabaseModel.prototype[`exists${
|
|
260
|
+
DatabaseModel.prototype[`exists${capitalize(queryKey)}`] = async function(...args) {
|
|
277
261
|
const query = queryFn(...args);
|
|
278
262
|
return this.__exists(query);
|
|
279
263
|
};
|
|
280
|
-
DatabaseModel.prototype[`count${
|
|
264
|
+
DatabaseModel.prototype[`count${capitalize(queryKey)}`] = async function(...args) {
|
|
281
265
|
const query = queryFn(...args);
|
|
282
266
|
return this.__count(query);
|
|
283
267
|
};
|
|
284
|
-
DatabaseModel.prototype[`insight${
|
|
268
|
+
DatabaseModel.prototype[`insight${capitalize(queryKey)}`] = async function(...args) {
|
|
285
269
|
const query = queryFn(...args);
|
|
286
270
|
return this.__insight(query);
|
|
287
271
|
};
|
|
288
272
|
});
|
|
289
|
-
const loaderMetas =
|
|
273
|
+
const loaderMetas = getLoaderMetas(database.Model);
|
|
290
274
|
loaderMetas.forEach((loaderMeta) => {
|
|
291
|
-
const loader2 = loaderMeta.type === "Field" ?
|
|
275
|
+
const loader2 = loaderMeta.type === "Field" ? createLoader(model, loaderMeta.fieldName) : loaderMeta.type === "ArrayField" ? createArrayLoader(model, loaderMeta.fieldName) : loaderMeta.type === "Query" ? createQueryLoader(model, loaderMeta.queryKeys ?? []) : null;
|
|
292
276
|
DatabaseModel.prototype[loaderMeta.key] = loader2;
|
|
293
277
|
});
|
|
294
278
|
Object.getOwnPropertyNames(database.Model.prototype).forEach((key) => {
|
|
@@ -296,17 +280,16 @@ const databaseModelOf = (database, model, redis, meili) => {
|
|
|
296
280
|
});
|
|
297
281
|
const createDescriptor = Object.getOwnPropertyDescriptor(DatabaseModel.prototype, `create${className}`);
|
|
298
282
|
if (createDescriptor)
|
|
299
|
-
|
|
283
|
+
Transaction()(DatabaseModel.prototype, `create${className}`, createDescriptor);
|
|
300
284
|
const updateDescriptor = Object.getOwnPropertyDescriptor(DatabaseModel.prototype, `update${className}`);
|
|
301
285
|
if (updateDescriptor)
|
|
302
|
-
|
|
286
|
+
Transaction()(DatabaseModel.prototype, `update${className}`, updateDescriptor);
|
|
303
287
|
const removeDescriptor = Object.getOwnPropertyDescriptor(DatabaseModel.prototype, `remove${className}`);
|
|
304
288
|
if (removeDescriptor)
|
|
305
|
-
|
|
289
|
+
Transaction()(DatabaseModel.prototype, `remove${className}`, removeDescriptor);
|
|
306
290
|
Reflect.defineMetadata(database.refName, DatabaseModel, DatabaseModelStorage.prototype);
|
|
307
291
|
return new DatabaseModel();
|
|
308
292
|
};
|
|
309
|
-
|
|
310
|
-
0 && (module.exports = {
|
|
293
|
+
export {
|
|
311
294
|
databaseModelOf
|
|
312
|
-
}
|
|
295
|
+
};
|
|
@@ -1,8 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 dbDecorators_exports = {};
|
|
19
|
+
__export(dbDecorators_exports, {
|
|
20
|
+
Database: () => Database,
|
|
21
|
+
DocumentDatabaseStorage: () => DocumentDatabaseStorage,
|
|
22
|
+
InputDatabaseStorage: () => InputDatabaseStorage,
|
|
23
|
+
MiddlewareDatabaseStorage: () => MiddlewareDatabaseStorage,
|
|
24
|
+
ModelDatabaseStorage: () => ModelDatabaseStorage,
|
|
25
|
+
beyond: () => beyond,
|
|
26
|
+
by: () => by,
|
|
27
|
+
dbOf: () => dbOf,
|
|
28
|
+
getAllDatabaseModelNames: () => getAllDatabaseModelNames,
|
|
29
|
+
inside: () => inside,
|
|
30
|
+
into: () => into
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(dbDecorators_exports);
|
|
33
|
+
var import_constant = require("@akanjs/constant");
|
|
6
34
|
const dbOf = (refName, Input, Doc, Model2, Middleware, Obj, Insight, Filter, Summary) => {
|
|
7
35
|
return { refName, Input, Doc, Model: Model2, Middleware, Obj, Insight, Filter, Summary };
|
|
8
36
|
};
|
|
@@ -22,28 +50,28 @@ const Database = {
|
|
|
22
50
|
Input: (returns) => {
|
|
23
51
|
return function(target) {
|
|
24
52
|
const modelRef = returns();
|
|
25
|
-
const classMeta = getClassMeta(modelRef);
|
|
53
|
+
const classMeta = (0, import_constant.getClassMeta)(modelRef);
|
|
26
54
|
Reflect.defineMetadata(classMeta.refName, target, InputDatabaseStorage.prototype);
|
|
27
55
|
};
|
|
28
56
|
},
|
|
29
57
|
Document: (returns) => {
|
|
30
58
|
return function(target) {
|
|
31
59
|
const modelRef = returns();
|
|
32
|
-
const classMeta = getClassMeta(modelRef);
|
|
60
|
+
const classMeta = (0, import_constant.getClassMeta)(modelRef);
|
|
33
61
|
Reflect.defineMetadata(classMeta.refName, target, DocumentDatabaseStorage.prototype);
|
|
34
62
|
};
|
|
35
63
|
},
|
|
36
64
|
Model: (returns) => {
|
|
37
65
|
return function(target) {
|
|
38
66
|
const modelRef = returns();
|
|
39
|
-
const classMeta = getClassMeta(modelRef);
|
|
67
|
+
const classMeta = (0, import_constant.getClassMeta)(modelRef);
|
|
40
68
|
Reflect.defineMetadata(classMeta.refName, target, ModelDatabaseStorage.prototype);
|
|
41
69
|
};
|
|
42
70
|
},
|
|
43
71
|
Middleware: (returns) => {
|
|
44
72
|
return function(target) {
|
|
45
73
|
const modelRef = returns();
|
|
46
|
-
const classMeta = getClassMeta(modelRef);
|
|
74
|
+
const classMeta = (0, import_constant.getClassMeta)(modelRef);
|
|
47
75
|
Reflect.defineMetadata(classMeta.refName, target, MiddlewareDatabaseStorage.prototype);
|
|
48
76
|
};
|
|
49
77
|
}
|
|
@@ -67,9 +95,9 @@ const InputOrDocument = (inputRef) => {
|
|
|
67
95
|
return inputRef;
|
|
68
96
|
};
|
|
69
97
|
const AddInputOrDocument = (modelRef, addRef) => {
|
|
70
|
-
const fieldMetaMap = getFieldMetaMap(modelRef);
|
|
71
|
-
const addFieldMetas = getFieldMetaMap(addRef);
|
|
72
|
-
setFieldMetaMap(modelRef, new Map([...fieldMetaMap, ...addFieldMetas]));
|
|
98
|
+
const fieldMetaMap = (0, import_constant.getFieldMetaMap)(modelRef);
|
|
99
|
+
const addFieldMetas = (0, import_constant.getFieldMetaMap)(addRef);
|
|
100
|
+
(0, import_constant.setFieldMetaMap)(modelRef, new Map([...fieldMetaMap, ...addFieldMetas]));
|
|
73
101
|
return modelRef;
|
|
74
102
|
};
|
|
75
103
|
const beyond = (model, doc) => {
|
|
@@ -78,7 +106,8 @@ const beyond = (model, doc) => {
|
|
|
78
106
|
}
|
|
79
107
|
};
|
|
80
108
|
};
|
|
81
|
-
export
|
|
109
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
+
0 && (module.exports = {
|
|
82
111
|
Database,
|
|
83
112
|
DocumentDatabaseStorage,
|
|
84
113
|
InputDatabaseStorage,
|
|
@@ -90,4 +119,4 @@ export {
|
|
|
90
119
|
getAllDatabaseModelNames,
|
|
91
120
|
inside,
|
|
92
121
|
into
|
|
93
|
-
};
|
|
122
|
+
});
|
package/src/dbDecorators.js
CHANGED
|
@@ -1,36 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 dbDecorators_exports = {};
|
|
19
|
-
__export(dbDecorators_exports, {
|
|
20
|
-
Database: () => Database,
|
|
21
|
-
DocumentDatabaseStorage: () => DocumentDatabaseStorage,
|
|
22
|
-
InputDatabaseStorage: () => InputDatabaseStorage,
|
|
23
|
-
MiddlewareDatabaseStorage: () => MiddlewareDatabaseStorage,
|
|
24
|
-
ModelDatabaseStorage: () => ModelDatabaseStorage,
|
|
25
|
-
beyond: () => beyond,
|
|
26
|
-
by: () => by,
|
|
27
|
-
dbOf: () => dbOf,
|
|
28
|
-
getAllDatabaseModelNames: () => getAllDatabaseModelNames,
|
|
29
|
-
inside: () => inside,
|
|
30
|
-
into: () => into
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(dbDecorators_exports);
|
|
33
|
-
var import_constant = require("@akanjs/constant");
|
|
1
|
+
import {
|
|
2
|
+
getClassMeta,
|
|
3
|
+
getFieldMetaMap,
|
|
4
|
+
setFieldMetaMap
|
|
5
|
+
} from "@akanjs/constant";
|
|
34
6
|
const dbOf = (refName, Input, Doc, Model2, Middleware, Obj, Insight, Filter, Summary) => {
|
|
35
7
|
return { refName, Input, Doc, Model: Model2, Middleware, Obj, Insight, Filter, Summary };
|
|
36
8
|
};
|
|
@@ -50,28 +22,28 @@ const Database = {
|
|
|
50
22
|
Input: (returns) => {
|
|
51
23
|
return function(target) {
|
|
52
24
|
const modelRef = returns();
|
|
53
|
-
const classMeta =
|
|
25
|
+
const classMeta = getClassMeta(modelRef);
|
|
54
26
|
Reflect.defineMetadata(classMeta.refName, target, InputDatabaseStorage.prototype);
|
|
55
27
|
};
|
|
56
28
|
},
|
|
57
29
|
Document: (returns) => {
|
|
58
30
|
return function(target) {
|
|
59
31
|
const modelRef = returns();
|
|
60
|
-
const classMeta =
|
|
32
|
+
const classMeta = getClassMeta(modelRef);
|
|
61
33
|
Reflect.defineMetadata(classMeta.refName, target, DocumentDatabaseStorage.prototype);
|
|
62
34
|
};
|
|
63
35
|
},
|
|
64
36
|
Model: (returns) => {
|
|
65
37
|
return function(target) {
|
|
66
38
|
const modelRef = returns();
|
|
67
|
-
const classMeta =
|
|
39
|
+
const classMeta = getClassMeta(modelRef);
|
|
68
40
|
Reflect.defineMetadata(classMeta.refName, target, ModelDatabaseStorage.prototype);
|
|
69
41
|
};
|
|
70
42
|
},
|
|
71
43
|
Middleware: (returns) => {
|
|
72
44
|
return function(target) {
|
|
73
45
|
const modelRef = returns();
|
|
74
|
-
const classMeta =
|
|
46
|
+
const classMeta = getClassMeta(modelRef);
|
|
75
47
|
Reflect.defineMetadata(classMeta.refName, target, MiddlewareDatabaseStorage.prototype);
|
|
76
48
|
};
|
|
77
49
|
}
|
|
@@ -95,9 +67,9 @@ const InputOrDocument = (inputRef) => {
|
|
|
95
67
|
return inputRef;
|
|
96
68
|
};
|
|
97
69
|
const AddInputOrDocument = (modelRef, addRef) => {
|
|
98
|
-
const fieldMetaMap =
|
|
99
|
-
const addFieldMetas =
|
|
100
|
-
|
|
70
|
+
const fieldMetaMap = getFieldMetaMap(modelRef);
|
|
71
|
+
const addFieldMetas = getFieldMetaMap(addRef);
|
|
72
|
+
setFieldMetaMap(modelRef, new Map([...fieldMetaMap, ...addFieldMetas]));
|
|
101
73
|
return modelRef;
|
|
102
74
|
};
|
|
103
75
|
const beyond = (model, doc) => {
|
|
@@ -106,8 +78,7 @@ const beyond = (model, doc) => {
|
|
|
106
78
|
}
|
|
107
79
|
};
|
|
108
80
|
};
|
|
109
|
-
|
|
110
|
-
0 && (module.exports = {
|
|
81
|
+
export {
|
|
111
82
|
Database,
|
|
112
83
|
DocumentDatabaseStorage,
|
|
113
84
|
InputDatabaseStorage,
|
|
@@ -119,4 +90,4 @@ const beyond = (model, doc) => {
|
|
|
119
90
|
getAllDatabaseModelNames,
|
|
120
91
|
inside,
|
|
121
92
|
into
|
|
122
|
-
}
|
|
93
|
+
};
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var src_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(src_exports);
|
|
17
|
+
__reExport(src_exports, require("./dbDecorators"), module.exports);
|
|
18
|
+
__reExport(src_exports, require("./schema"), module.exports);
|
|
19
|
+
__reExport(src_exports, require("./types"), module.exports);
|
|
20
|
+
__reExport(src_exports, require("./database"), module.exports);
|
|
21
|
+
__reExport(src_exports, require("./dataLoader"), module.exports);
|
|
22
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
23
|
+
0 && (module.exports = {
|
|
24
|
+
...require("./dbDecorators"),
|
|
25
|
+
...require("./schema"),
|
|
26
|
+
...require("./types"),
|
|
27
|
+
...require("./database"),
|
|
28
|
+
...require("./dataLoader")
|
|
29
|
+
});
|
package/src/index.js
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var src_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(src_exports);
|
|
17
|
-
__reExport(src_exports, require("./dbDecorators"), module.exports);
|
|
18
|
-
__reExport(src_exports, require("./schema"), module.exports);
|
|
19
|
-
__reExport(src_exports, require("./types"), module.exports);
|
|
20
|
-
__reExport(src_exports, require("./database"), module.exports);
|
|
21
|
-
__reExport(src_exports, require("./dataLoader"), module.exports);
|
|
22
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
23
|
-
0 && (module.exports = {
|
|
24
|
-
...require("./dbDecorators"),
|
|
25
|
-
...require("./schema"),
|
|
26
|
-
...require("./types"),
|
|
27
|
-
...require("./database"),
|
|
28
|
-
...require("./dataLoader")
|
|
29
|
-
});
|
|
1
|
+
export * from "./dbDecorators";
|
|
2
|
+
export * from "./schema";
|
|
3
|
+
export * from "./types";
|
|
4
|
+
export * from "./database";
|
|
5
|
+
export * from "./dataLoader";
|
|
@@ -1,6 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
convertAggregateMatch: () => convertAggregateMatch,
|
|
21
|
+
getDefaultSchemaOptions: () => getDefaultSchemaOptions
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(schema_exports);
|
|
24
|
+
var import_base = require("@akanjs/base");
|
|
25
|
+
var import_common = require("@akanjs/common");
|
|
26
|
+
var import_mongoose = require("mongoose");
|
|
4
27
|
const getDefaultSchemaOptions = () => ({
|
|
5
28
|
toJSON: { getters: false, virtuals: true },
|
|
6
29
|
toObject: { getters: false, virtuals: true },
|
|
@@ -78,10 +101,10 @@ const convertOperatorValue = (value) => {
|
|
|
78
101
|
return value.map((v) => convertOperatorValue(v));
|
|
79
102
|
else if (!value)
|
|
80
103
|
return value;
|
|
81
|
-
else if (isValidObjectId(value))
|
|
82
|
-
return new Types.ObjectId(value);
|
|
83
|
-
else if (isValidDate(value))
|
|
84
|
-
return dayjs(value).toDate();
|
|
104
|
+
else if ((0, import_mongoose.isValidObjectId)(value))
|
|
105
|
+
return new import_mongoose.Types.ObjectId(value);
|
|
106
|
+
else if ((0, import_common.isValidDate)(value))
|
|
107
|
+
return (0, import_base.dayjs)(value).toDate();
|
|
85
108
|
else if (value.constructor !== Object)
|
|
86
109
|
return value;
|
|
87
110
|
else if (typeof value !== "object")
|
|
@@ -98,7 +121,8 @@ const convertAggregateMatch = (query) => {
|
|
|
98
121
|
})
|
|
99
122
|
);
|
|
100
123
|
};
|
|
101
|
-
export
|
|
124
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
125
|
+
0 && (module.exports = {
|
|
102
126
|
convertAggregateMatch,
|
|
103
127
|
getDefaultSchemaOptions
|
|
104
|
-
};
|
|
128
|
+
});
|
package/src/schema.js
CHANGED
|
@@ -1,29 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
convertAggregateMatch: () => convertAggregateMatch,
|
|
21
|
-
getDefaultSchemaOptions: () => getDefaultSchemaOptions
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(schema_exports);
|
|
24
|
-
var import_base = require("@akanjs/base");
|
|
25
|
-
var import_common = require("@akanjs/common");
|
|
26
|
-
var import_mongoose = require("mongoose");
|
|
1
|
+
import { dayjs } from "@akanjs/base";
|
|
2
|
+
import { isValidDate } from "@akanjs/common";
|
|
3
|
+
import { isValidObjectId, Types } from "mongoose";
|
|
27
4
|
const getDefaultSchemaOptions = () => ({
|
|
28
5
|
toJSON: { getters: false, virtuals: true },
|
|
29
6
|
toObject: { getters: false, virtuals: true },
|
|
@@ -101,10 +78,10 @@ const convertOperatorValue = (value) => {
|
|
|
101
78
|
return value.map((v) => convertOperatorValue(v));
|
|
102
79
|
else if (!value)
|
|
103
80
|
return value;
|
|
104
|
-
else if (
|
|
105
|
-
return new
|
|
106
|
-
else if (
|
|
107
|
-
return
|
|
81
|
+
else if (isValidObjectId(value))
|
|
82
|
+
return new Types.ObjectId(value);
|
|
83
|
+
else if (isValidDate(value))
|
|
84
|
+
return dayjs(value).toDate();
|
|
108
85
|
else if (value.constructor !== Object)
|
|
109
86
|
return value;
|
|
110
87
|
else if (typeof value !== "object")
|
|
@@ -121,8 +98,7 @@ const convertAggregateMatch = (query) => {
|
|
|
121
98
|
})
|
|
122
99
|
);
|
|
123
100
|
};
|
|
124
|
-
|
|
125
|
-
0 && (module.exports = {
|
|
101
|
+
export {
|
|
126
102
|
convertAggregateMatch,
|
|
127
103
|
getDefaultSchemaOptions
|
|
128
|
-
}
|
|
104
|
+
};
|
package/src/types.cjs
ADDED
|
@@ -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.js
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
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);
|