tspace-mysql 1.8.2 → 1.8.4
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/README.md +443 -68
- package/build/cli/generate/model.js +3 -3
- package/build/cli/generate/model.js.map +1 -1
- package/build/lib/constants/index.d.ts +7 -1
- package/build/lib/constants/index.js +7 -1
- package/build/lib/constants/index.js.map +1 -1
- package/build/lib/core/Abstracts/AbstractBuilder.d.ts +1 -1
- package/build/lib/core/Abstracts/AbstractBuilder.js.map +1 -1
- package/build/lib/core/Abstracts/AbstractDB.d.ts +2 -2
- package/build/lib/core/Abstracts/AbstractDB.js.map +1 -1
- package/build/lib/core/Abstracts/AbstractView.d.ts +10 -0
- package/build/lib/core/Abstracts/AbstractView.js +9 -0
- package/build/lib/core/Abstracts/AbstractView.js.map +1 -0
- package/build/lib/core/Blueprint.d.ts +24 -4
- package/build/lib/core/Blueprint.js +78 -87
- package/build/lib/core/Blueprint.js.map +1 -1
- package/build/lib/core/Builder.d.ts +39 -30
- package/build/lib/core/Builder.js +1094 -1044
- package/build/lib/core/Builder.js.map +1 -1
- package/build/lib/core/Cache/DBCache.js +15 -16
- package/build/lib/core/Cache/DBCache.js.map +1 -1
- package/build/lib/core/DB.d.ts +38 -38
- package/build/lib/core/DB.js +119 -115
- package/build/lib/core/DB.js.map +1 -1
- package/build/lib/core/Decorator.d.ts +1 -1
- package/build/lib/core/Decorator.js.map +1 -1
- package/build/lib/core/Handlers/Relation.d.ts +2 -1
- package/build/lib/core/Handlers/Relation.js +60 -15
- package/build/lib/core/Handlers/Relation.js.map +1 -1
- package/build/lib/core/Handlers/State.d.ts +1 -0
- package/build/lib/core/Handlers/State.js +1 -1
- package/build/lib/core/Handlers/State.js.map +1 -1
- package/build/lib/core/JoinModel.d.ts +1 -1
- package/build/lib/core/JoinModel.js.map +1 -1
- package/build/lib/core/Meta.d.ts +55 -0
- package/build/lib/core/Meta.js +175 -0
- package/build/lib/core/Meta.js.map +1 -0
- package/build/lib/core/Model.d.ts +158 -94
- package/build/lib/core/Model.js +1586 -1203
- package/build/lib/core/Model.js.map +1 -1
- package/build/lib/core/Nest/index.d.ts +3 -1
- package/build/lib/core/Nest/index.js +4 -2
- package/build/lib/core/Nest/index.js.map +1 -1
- package/build/lib/{connection/index.d.ts → core/Pool.d.ts} +2 -1
- package/build/lib/{connection/index.js → core/Pool.js} +74 -6
- package/build/lib/core/Pool.js.map +1 -0
- package/build/lib/core/Repository.d.ts +16 -16
- package/build/lib/core/Repository.js +73 -45
- package/build/lib/core/Repository.js.map +1 -1
- package/build/lib/core/Schema.d.ts +2 -2
- package/build/lib/core/Schema.js +113 -78
- package/build/lib/core/Schema.js.map +1 -1
- package/build/lib/core/SqlLike.js.map +1 -1
- package/build/lib/core/StoredProcedure.d.ts +120 -0
- package/build/lib/core/StoredProcedure.js +161 -0
- package/build/lib/core/StoredProcedure.js.map +1 -0
- package/build/lib/core/UtilityTypes.d.ts +25 -44
- package/build/lib/core/View.d.ts +96 -0
- package/build/lib/core/View.js +141 -0
- package/build/lib/core/View.js.map +1 -0
- package/build/lib/core/index.d.ts +17 -12
- package/build/lib/core/index.js +9 -4
- package/build/lib/core/index.js.map +1 -1
- package/build/lib/types/index.d.ts +23 -3
- package/build/lib/utils/index.js +5 -2
- package/build/lib/utils/index.js.map +1 -1
- package/build/tests/01-Pool.test.js +0 -10
- package/build/tests/01-Pool.test.js.map +1 -1
- package/build/tests/04-Model-pattern.test.js +1 -1
- package/build/tests/04-Model-pattern.test.js.map +1 -1
- package/build/tests/05-View.test.d.ts +1 -0
- package/build/tests/05-View.test.js +83 -0
- package/build/tests/05-View.test.js.map +1 -0
- package/build/tests/06-Meta.test.d.ts +1 -0
- package/build/tests/06-Meta.test.js +103 -0
- package/build/tests/06-Meta.test.js.map +1 -0
- package/build/tests/07-Virtual-column.test.d.ts +1 -0
- package/build/tests/07-Virtual-column.test.js +160 -0
- package/build/tests/07-Virtual-column.test.js.map +1 -0
- package/build/tests/schema-spec.js +25 -25
- package/build/tests/schema-spec.js.map +1 -1
- package/package.json +1 -1
- package/build/lib/connection/index.js.map +0 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Meta = void 0;
|
|
4
|
+
class ModelMeta {
|
|
5
|
+
constructor(model) {
|
|
6
|
+
this.model = model;
|
|
7
|
+
}
|
|
8
|
+
table() {
|
|
9
|
+
return this.model.toTableName();
|
|
10
|
+
}
|
|
11
|
+
column(column) {
|
|
12
|
+
return column;
|
|
13
|
+
}
|
|
14
|
+
columnReference(column) {
|
|
15
|
+
return `\`${this.table()}\`.\`${String(column)}\``;
|
|
16
|
+
}
|
|
17
|
+
columnRef(column) {
|
|
18
|
+
return this.columnReference(column);
|
|
19
|
+
}
|
|
20
|
+
columns() {
|
|
21
|
+
const schemaModel = this.model.getSchemaModel();
|
|
22
|
+
const columns = schemaModel == null
|
|
23
|
+
? []
|
|
24
|
+
: Object.entries(schemaModel).map(([key]) => {
|
|
25
|
+
return key;
|
|
26
|
+
});
|
|
27
|
+
return columns;
|
|
28
|
+
}
|
|
29
|
+
hasColumn(name) {
|
|
30
|
+
const schemaModel = this.model.getSchemaModel();
|
|
31
|
+
const columns = schemaModel == null
|
|
32
|
+
? []
|
|
33
|
+
: Object.entries(schemaModel).map(([key]) => {
|
|
34
|
+
return key;
|
|
35
|
+
});
|
|
36
|
+
return columns.includes(name);
|
|
37
|
+
}
|
|
38
|
+
primaryKey() {
|
|
39
|
+
var _a;
|
|
40
|
+
const schemaModel = this.model.getSchemaModel();
|
|
41
|
+
if (schemaModel == null)
|
|
42
|
+
return undefined;
|
|
43
|
+
return (_a = Object
|
|
44
|
+
.entries(schemaModel)
|
|
45
|
+
.find(([key, blueprint]) => {
|
|
46
|
+
const attr = blueprint['_attributes'];
|
|
47
|
+
if (Array.from(attr).includes(this.model['$constants']('PRIMARY_KEY'))) {
|
|
48
|
+
return key;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
})) === null || _a === void 0 ? void 0 : _a[0];
|
|
52
|
+
}
|
|
53
|
+
indexes() {
|
|
54
|
+
const schemaModel = this.model.getSchemaModel();
|
|
55
|
+
if (schemaModel == null)
|
|
56
|
+
return [];
|
|
57
|
+
return Object
|
|
58
|
+
.entries(schemaModel)
|
|
59
|
+
.map(([key, blueprint]) => {
|
|
60
|
+
const index = blueprint['_index'];
|
|
61
|
+
if (index == null)
|
|
62
|
+
return undefined;
|
|
63
|
+
if (index === '')
|
|
64
|
+
return `unknown_index_${key}`;
|
|
65
|
+
return index;
|
|
66
|
+
})
|
|
67
|
+
.filter(v => v != null);
|
|
68
|
+
}
|
|
69
|
+
nullable() {
|
|
70
|
+
const schemaModel = this.model.getSchemaModel();
|
|
71
|
+
if (schemaModel == null)
|
|
72
|
+
return [];
|
|
73
|
+
return Object
|
|
74
|
+
.entries(schemaModel)
|
|
75
|
+
.map(([key, blueprint]) => {
|
|
76
|
+
const attr = blueprint['_attributes'];
|
|
77
|
+
if (Array.from(attr).includes(this.model['$constants']('NULL'))) {
|
|
78
|
+
return key;
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
})
|
|
82
|
+
.filter(v => v != null);
|
|
83
|
+
}
|
|
84
|
+
defaults() {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
const schemaModel = this.model.getSchemaModel();
|
|
87
|
+
if (schemaModel == null)
|
|
88
|
+
return null;
|
|
89
|
+
const out = {};
|
|
90
|
+
const keyword = this.model['$constants']('DEFAULT');
|
|
91
|
+
for (const [key, blueprint] of Object.entries(schemaModel)) {
|
|
92
|
+
const attr = blueprint['_attributes'];
|
|
93
|
+
if (!attr)
|
|
94
|
+
continue;
|
|
95
|
+
const defaultAttr = Array.from(attr).find(str => str.includes(keyword));
|
|
96
|
+
if (!defaultAttr)
|
|
97
|
+
continue;
|
|
98
|
+
const value = (_b = (_a = defaultAttr.match(new RegExp(`${keyword}\\s+'(.*?)'`))) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : null;
|
|
99
|
+
out[key] = value;
|
|
100
|
+
}
|
|
101
|
+
if (!Object.keys(out).length)
|
|
102
|
+
return null;
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
columnTypeOf(column) {
|
|
106
|
+
const schemaModel = this.model.getSchemaModel();
|
|
107
|
+
if (!schemaModel)
|
|
108
|
+
return undefined;
|
|
109
|
+
const entry = Object.entries(schemaModel).find(([key]) => key === column);
|
|
110
|
+
if (!entry)
|
|
111
|
+
return undefined;
|
|
112
|
+
const blueprint = entry[1];
|
|
113
|
+
const value = blueprint['_valueType'];
|
|
114
|
+
if (value === Number)
|
|
115
|
+
return "number";
|
|
116
|
+
if (value === String)
|
|
117
|
+
return "string";
|
|
118
|
+
if (value === Boolean)
|
|
119
|
+
return "boolean";
|
|
120
|
+
if (value === Date)
|
|
121
|
+
return "date";
|
|
122
|
+
return "unknown";
|
|
123
|
+
}
|
|
124
|
+
columnType(column) {
|
|
125
|
+
const schemaModel = this.model.getSchemaModel();
|
|
126
|
+
if (!schemaModel)
|
|
127
|
+
return undefined;
|
|
128
|
+
const entry = Object.entries(schemaModel).find(([key]) => key === column);
|
|
129
|
+
if (!entry)
|
|
130
|
+
return undefined;
|
|
131
|
+
const blueprint = entry[1];
|
|
132
|
+
return blueprint['_type'];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The 'Meta' used to get the metadata of a Model works only when a schema is added to the Model.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* import { Meta } from 'tspace-mysql';
|
|
140
|
+
* import { User } from './Model/User';
|
|
141
|
+
*
|
|
142
|
+
* const meta = Meta(User)
|
|
143
|
+
* // --- get metadata of User ---
|
|
144
|
+
* const table = meta.table()
|
|
145
|
+
* const column = meta.column('id')
|
|
146
|
+
* const columnRef = meta.columnReference('id')
|
|
147
|
+
* const columnTypeOf = meta.columnTypeOf('id')
|
|
148
|
+
* const columnType = meta.columnType('id')
|
|
149
|
+
* const columns = meta.columns()
|
|
150
|
+
* const hasColumn = meta.hasColumn('id')
|
|
151
|
+
* const primaryKey = meta.primaryKey()
|
|
152
|
+
* const indexes = meta.indexes()
|
|
153
|
+
* const nullable = meta.nullable()
|
|
154
|
+
* const defaults = meta.defaults()
|
|
155
|
+
*
|
|
156
|
+
* console.log({
|
|
157
|
+
* table,
|
|
158
|
+
* column,
|
|
159
|
+
* columnRef
|
|
160
|
+
* columnTypeOf,
|
|
161
|
+
* columnType
|
|
162
|
+
* columns,
|
|
163
|
+
* hasColumn,
|
|
164
|
+
* primaryKey,
|
|
165
|
+
* indexes,
|
|
166
|
+
* nullable,
|
|
167
|
+
* defaults,
|
|
168
|
+
* })
|
|
169
|
+
*/
|
|
170
|
+
const Meta = (model) => {
|
|
171
|
+
return new ModelMeta(new model());
|
|
172
|
+
};
|
|
173
|
+
exports.Meta = Meta;
|
|
174
|
+
exports.default = Meta;
|
|
175
|
+
//# sourceMappingURL=Meta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Meta.js","sourceRoot":"","sources":["../../../src/lib/core/Meta.ts"],"names":[],"mappings":";;;AAEA,MAAM,SAAS;IACX,YAAoB,KAAQ;QAAR,UAAK,GAAL,KAAK,CAAG;IAAG,CAAC;IAChC,KAAK;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,MAAmB;QACtB,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,eAAe,CAAE,MAAmB;QAChC,OAAO,KAAK,IAAI,CAAC,KAAK,EAAE,QAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IACvD,CAAC;IAED,SAAS,CAAE,MAAmB;QAC1B,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,OAAO;QACH,MAAM,WAAW,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