1 | "use strict";
|
2 | require("source-map-support/register");
|
3 | const Model_1 = require("./Model");
|
4 | const Schema_1 = require("./Schema");
|
5 | const Condition_1 = require("./Condition");
|
6 | const Transaction_1 = require("./Transaction");
|
7 | const aws = require("./aws");
|
8 | const Internal = require("./Internal");
|
9 | const utils = require("./utils");
|
10 | const logger = require("./logger");
|
11 | const ModelStore = require("./ModelStore");
|
12 | const model = (name, schema, options = {}) => {
|
13 | let model;
|
14 | let storedSchema;
|
15 | if (name) {
|
16 | storedSchema = ModelStore(name);
|
17 | }
|
18 |
|
19 | |
20 |
|
21 |
|
22 | if (!schema && storedSchema) {
|
23 | model = storedSchema;
|
24 | }
|
25 | else {
|
26 | model = new Model_1.Model(name, schema, options);
|
27 | }
|
28 | const returnObject = model.Document;
|
29 | const keys = utils.array_flatten([
|
30 | Object.keys(model),
|
31 | Object.keys(Object.getPrototypeOf(model)),
|
32 | Object.getOwnPropertyNames(Object.getPrototypeOf(model))
|
33 | ]).filter((key) => !["constructor", "name"].includes(key));
|
34 | keys.forEach((key) => {
|
35 | if (typeof model[key] === "object") {
|
36 | const main = (key) => {
|
37 | utils.object.set(returnObject, key, {});
|
38 | const value = utils.object.get(model, key);
|
39 | if (value === null || value.constructor !== Object && value.constructor !== Array) {
|
40 | utils.object.set(returnObject, key, value);
|
41 | }
|
42 | else {
|
43 | Object.keys(value).forEach((subKey) => {
|
44 | const newKey = `${key}.${subKey}`;
|
45 | const subValue = utils.object.get(model, newKey);
|
46 | if (typeof subValue === "object") {
|
47 | main(newKey);
|
48 | }
|
49 | else {
|
50 | utils.object.set(returnObject, newKey, typeof subValue === "function" ? subValue.bind(model) : subValue);
|
51 | }
|
52 | });
|
53 | }
|
54 | };
|
55 | main(key);
|
56 | }
|
57 | else if (typeof model[key] === "function") {
|
58 | returnObject[key] = model[key].bind(model);
|
59 | }
|
60 | else {
|
61 | returnObject[key] = model[key];
|
62 | }
|
63 | });
|
64 | return returnObject;
|
65 | };
|
66 | model.defaults = Object.assign({}, require("./Model/defaults").custom);
|
67 | module.exports = {
|
68 | model,
|
69 | Schema: Schema_1.Schema,
|
70 | Condition: Condition_1.Condition,
|
71 | transaction: Transaction_1.default,
|
72 | aws,
|
73 | logger,
|
74 | "UNDEFINED": Internal.Public.undefined,
|
75 | "THIS": Internal.Public.this
|
76 | };
|
77 |
|
\ | No newline at end of file |