pangea-server 1.0.1

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.
Files changed (150) hide show
  1. package/README.md +1 -0
  2. package/dist/authentication/access-token.class.d.ts +13 -0
  3. package/dist/authentication/access-token.class.js +28 -0
  4. package/dist/authentication/authentication.helpers.d.ts +17 -0
  5. package/dist/authentication/authentication.helpers.js +77 -0
  6. package/dist/authentication/authentication.types.d.ts +11 -0
  7. package/dist/authentication/authentication.types.js +2 -0
  8. package/dist/authentication/base-auth.class.d.ts +9 -0
  9. package/dist/authentication/base-auth.class.js +29 -0
  10. package/dist/authentication/index.d.ts +4 -0
  11. package/dist/authentication/index.js +20 -0
  12. package/dist/database/base-service.class.d.ts +15 -0
  13. package/dist/database/base-service.class.js +28 -0
  14. package/dist/database/database.helpers.d.ts +4 -0
  15. package/dist/database/database.helpers.js +19 -0
  16. package/dist/database/database.types.d.ts +59 -0
  17. package/dist/database/database.types.js +2 -0
  18. package/dist/database/db-client.d.ts +11 -0
  19. package/dist/database/db-client.js +69 -0
  20. package/dist/database/db.class.d.ts +64 -0
  21. package/dist/database/db.class.js +270 -0
  22. package/dist/database/decorators/columns/column.d.ts +10 -0
  23. package/dist/database/decorators/columns/column.js +47 -0
  24. package/dist/database/decorators/columns/date.columns.d.ts +4 -0
  25. package/dist/database/decorators/columns/date.columns.js +16 -0
  26. package/dist/database/decorators/columns/general.columns.d.ts +4 -0
  27. package/dist/database/decorators/columns/general.columns.js +54 -0
  28. package/dist/database/decorators/columns/json.columns.d.ts +3 -0
  29. package/dist/database/decorators/columns/json.columns.js +22 -0
  30. package/dist/database/decorators/columns/number.columns.d.ts +10 -0
  31. package/dist/database/decorators/columns/number.columns.js +33 -0
  32. package/dist/database/decorators/columns/string.columns.d.ts +10 -0
  33. package/dist/database/decorators/columns/string.columns.js +55 -0
  34. package/dist/database/decorators/index.d.ts +23 -0
  35. package/dist/database/decorators/index.js +50 -0
  36. package/dist/database/decorators/relations.d.ts +12 -0
  37. package/dist/database/decorators/relations.js +42 -0
  38. package/dist/database/decorators/table.d.ts +6 -0
  39. package/dist/database/decorators/table.js +57 -0
  40. package/dist/database/index.d.ts +8 -0
  41. package/dist/database/index.js +26 -0
  42. package/dist/database/init-database.d.ts +11 -0
  43. package/dist/database/init-database.js +69 -0
  44. package/dist/database/model-decorators/column.d.ts +11 -0
  45. package/dist/database/model-decorators/column.js +51 -0
  46. package/dist/database/model-decorators/date-columns.d.ts +6 -0
  47. package/dist/database/model-decorators/date-columns.js +41 -0
  48. package/dist/database/model-decorators/decorators.types.d.ts +20 -0
  49. package/dist/database/model-decorators/decorators.types.js +2 -0
  50. package/dist/database/model-decorators/general-columns.d.ts +4 -0
  51. package/dist/database/model-decorators/general-columns.js +54 -0
  52. package/dist/database/model-decorators/index.d.ts +23 -0
  53. package/dist/database/model-decorators/index.js +50 -0
  54. package/dist/database/model-decorators/json-columns.d.ts +3 -0
  55. package/dist/database/model-decorators/json-columns.js +46 -0
  56. package/dist/database/model-decorators/number-columns.d.ts +10 -0
  57. package/dist/database/model-decorators/number-columns.js +58 -0
  58. package/dist/database/model-decorators/relations.d.ts +12 -0
  59. package/dist/database/model-decorators/relations.js +42 -0
  60. package/dist/database/model-decorators/string-columns.d.ts +9 -0
  61. package/dist/database/model-decorators/string-columns.js +51 -0
  62. package/dist/database/model-decorators/table.d.ts +6 -0
  63. package/dist/database/model-decorators/table.js +57 -0
  64. package/dist/database/models/base-model.class.d.ts +33 -0
  65. package/dist/database/models/base-model.class.js +76 -0
  66. package/dist/database/models/index.d.ts +2 -0
  67. package/dist/database/models/index.js +18 -0
  68. package/dist/database/models/user.model.d.ts +5 -0
  69. package/dist/database/models/user.model.js +25 -0
  70. package/dist/database/seed.helpers.d.ts +4 -0
  71. package/dist/database/seed.helpers.js +44 -0
  72. package/dist/helpers/console.helpers.d.ts +8 -0
  73. package/dist/helpers/console.helpers.js +29 -0
  74. package/dist/helpers/controllers.helpers.d.ts +2 -0
  75. package/dist/helpers/controllers.helpers.js +6 -0
  76. package/dist/helpers/env.helpers.d.ts +4 -0
  77. package/dist/helpers/env.helpers.js +32 -0
  78. package/dist/helpers/error.helpers.d.ts +20 -0
  79. package/dist/helpers/error.helpers.js +29 -0
  80. package/dist/helpers/file.helpers.d.ts +4 -0
  81. package/dist/helpers/file.helpers.js +78 -0
  82. package/dist/helpers/hashing.helpers.d.ts +2 -0
  83. package/dist/helpers/hashing.helpers.js +16 -0
  84. package/dist/helpers/html-sanitize.helpers.d.ts +4 -0
  85. package/dist/helpers/html-sanitize.helpers.js +30 -0
  86. package/dist/helpers/index.d.ts +11 -0
  87. package/dist/helpers/index.js +27 -0
  88. package/dist/helpers/job.helpers.d.ts +8 -0
  89. package/dist/helpers/job.helpers.js +20 -0
  90. package/dist/helpers/mailer.helpers.d.ts +33 -0
  91. package/dist/helpers/mailer.helpers.js +34 -0
  92. package/dist/helpers/multer.helpers.d.ts +2 -0
  93. package/dist/helpers/multer.helpers.js +52 -0
  94. package/dist/helpers/print.helpers.d.ts +8 -0
  95. package/dist/helpers/print.helpers.js +29 -0
  96. package/dist/helpers/random.helpers.d.ts +4 -0
  97. package/dist/helpers/random.helpers.js +27 -0
  98. package/dist/index.d.ts +8 -0
  99. package/dist/index.js +26 -0
  100. package/dist/main.d.ts +13 -0
  101. package/dist/main.js +65 -0
  102. package/dist/middlewares/delay-request.middleware.d.ts +1 -0
  103. package/dist/middlewares/delay-request.middleware.js +16 -0
  104. package/dist/middlewares/handle-error.middleware.d.ts +1 -0
  105. package/dist/middlewares/handle-error.middleware.js +13 -0
  106. package/dist/resources/color.resources.d.ts +18 -0
  107. package/dist/resources/color.resources.js +20 -0
  108. package/dist/resources/index.d.ts +2 -0
  109. package/dist/resources/index.js +18 -0
  110. package/dist/resources/refs.d.ts +32 -0
  111. package/dist/resources/refs.js +35 -0
  112. package/dist/resources/string.resources.d.ts +15 -0
  113. package/dist/resources/string.resources.js +16 -0
  114. package/dist/router/app-router.class.d.ts +18 -0
  115. package/dist/router/app-router.class.js +34 -0
  116. package/dist/router/call-controller.d.ts +5 -0
  117. package/dist/router/call-controller.js +47 -0
  118. package/dist/router/index.d.ts +1 -0
  119. package/dist/router/index.js +17 -0
  120. package/dist/router/router.types.d.ts +15 -0
  121. package/dist/router/router.types.js +2 -0
  122. package/dist/types/error.types.d.ts +4 -0
  123. package/dist/types/error.types.js +2 -0
  124. package/dist/types/global.types.d.ts +22 -0
  125. package/dist/types/global.types.js +2 -0
  126. package/dist/types/index.d.ts +2 -0
  127. package/dist/types/index.js +4 -0
  128. package/dist/validations/general-schemas.d.ts +20 -0
  129. package/dist/validations/general-schemas.js +15 -0
  130. package/dist/validations/index.d.ts +3 -0
  131. package/dist/validations/index.js +19 -0
  132. package/dist/validations/validate-request.middleware.d.ts +2 -0
  133. package/dist/validations/validate-request.middleware.js +33 -0
  134. package/dist/validations/validation-locations.d.ts +1 -0
  135. package/dist/validations/validation-locations.js +4 -0
  136. package/dist/validations/validations.types.d.ts +23 -0
  137. package/dist/validations/validations.types.js +21 -0
  138. package/dist/validator/general-schemas.d.ts +1 -0
  139. package/dist/validator/general-schemas.js +25 -0
  140. package/dist/validator/index.d.ts +1 -0
  141. package/dist/validator/index.js +17 -0
  142. package/dist/validator/tags.d.ts +1 -0
  143. package/dist/validator/tags.js +5 -0
  144. package/dist/validator/validate-request.d.ts +2 -0
  145. package/dist/validator/validate-request.js +71 -0
  146. package/dist/validator/validator.types.d.ts +6 -0
  147. package/dist/validator/validator.types.js +2 -0
  148. package/dist/validator/validators.helpers.d.ts +38 -0
  149. package/dist/validator/validators.helpers.js +8 -0
  150. package/package.json +78 -0
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Db = void 0;
4
+ const sequelize_1 = require("sequelize");
5
+ const db_client_1 = require("./db-client");
6
+ const _1 = require(".");
7
+ // helpers
8
+ const helpers_1 = require("../helpers");
9
+ const pangea_helpers_1 = require("pangea-helpers");
10
+ class Db {
11
+ constructor(tx) {
12
+ this.__tx = tx;
13
+ }
14
+ // find methods
15
+ findOneOrNull(model, filters, options = {}) {
16
+ const { scopes = [], attributes, include = [], order, paranoid = true } = options;
17
+ const scopedModel = scopes.length ? model.scope(...scopes) : model;
18
+ const baseOptions = { attributes: getFinalAttributes(attributes), paranoid, transaction: this.__tx };
19
+ if (typeof filters === 'number') {
20
+ return scopedModel.findByPk(filters, { ...getIncludeAndWhere(model, include), ...baseOptions });
21
+ }
22
+ return scopedModel.findOne({
23
+ ...getIncludeAndWhere(model, include, filters),
24
+ order: getFinalOrder(order),
25
+ ...baseOptions,
26
+ });
27
+ }
28
+ async findOne(model, filters, options = {}) {
29
+ const instance = await this.findOneOrNull(model, filters, options);
30
+ if (!instance)
31
+ helpers_1.AppError.ThrowEntityNotFound();
32
+ return instance;
33
+ }
34
+ async findMany(model, options = {}) {
35
+ const { attributes, include = [], where, searchFields, search, group, order, page, pageSize, paranoid = 'active', } = options;
36
+ let searchWhere;
37
+ if (searchFields?.length && search) {
38
+ const searchWords = search.split(/\s+/).filter(Boolean);
39
+ searchWhere = {
40
+ [_1.Ops.and]: searchWords.map((word) => ({
41
+ [_1.Ops.or]: searchFields.map((field) => {
42
+ const finalField = field.includes('.') ? `$${field}$` : field;
43
+ return { [finalField]: { [_1.Ops.like]: `%${word}%` } };
44
+ }),
45
+ })),
46
+ };
47
+ }
48
+ const deletedAtWhere = paranoid === 'deleted' ? { deletedAt: { [_1.Ops.not]: null } } : {};
49
+ const baseOptions = {
50
+ attributes: getFinalAttributes(attributes),
51
+ ...getIncludeAndWhere(model, include, {
52
+ ...where,
53
+ ...searchWhere,
54
+ ...deletedAtWhere,
55
+ }),
56
+ ...(group && { group }),
57
+ order: [...getFinalOrder(order), ['createdAt', 'DESC']],
58
+ paranoid: paranoid === 'active',
59
+ subQuery: false,
60
+ transaction: this.__tx,
61
+ };
62
+ if (page && pageSize) {
63
+ const [instances, totalCount] = await Promise.all([
64
+ (async () => {
65
+ const idRows = await model.findAll({
66
+ ...baseOptions,
67
+ attributes: [[(0, sequelize_1.col)(`${model.name}.id`), 'id']],
68
+ group: [`${model.name}.id`],
69
+ raw: true,
70
+ offset: (page - 1) * pageSize,
71
+ limit: pageSize,
72
+ });
73
+ const ids = idRows.map((row) => row.id);
74
+ return model.findAll({
75
+ ...baseOptions,
76
+ where: { id: { [_1.Ops.in]: ids } },
77
+ });
78
+ })(),
79
+ model.count({ ...baseOptions, col: 'id', distinct: true }),
80
+ ]);
81
+ return { instances, totalCount };
82
+ }
83
+ const instances = await model.findAll(baseOptions);
84
+ return { instances, totalCount: instances.length };
85
+ }
86
+ // insert methods
87
+ insertOne(model, params) {
88
+ return handleDbError(async () => {
89
+ const newInstance = await model.create(params, { transaction: this.__tx });
90
+ return this.findOne(model, newInstance.id);
91
+ });
92
+ }
93
+ insertMany(model, data, options = {}) {
94
+ return handleDbError(async () => {
95
+ const newInstances = await model.bulkCreate(data, {
96
+ ...options,
97
+ validate: true,
98
+ transaction: this.__tx,
99
+ });
100
+ return newInstances.length;
101
+ });
102
+ }
103
+ // update methods
104
+ updateOne(model, target, params) {
105
+ return handleDbError(async () => {
106
+ const instance = await this.__getInstance(model, target);
107
+ await instance.update(params, { transaction: this.__tx });
108
+ return this.findOne(model, instance.id);
109
+ });
110
+ }
111
+ updateMany(model, where, params) {
112
+ return handleDbError(async () => {
113
+ const [count] = await model.update(params, { where, transaction: this.__tx });
114
+ return count;
115
+ });
116
+ }
117
+ // delete methods
118
+ deleteOne(model, target) {
119
+ return this.__deleteOne(model, target, false);
120
+ }
121
+ deleteMany(model, where) {
122
+ return this.__deleteMany(model, where, false);
123
+ }
124
+ // destroy methods
125
+ destroyOne(model, target) {
126
+ return this.__deleteOne(model, target, true);
127
+ }
128
+ destroyMany(model, where) {
129
+ return this.__deleteMany(model, where, true);
130
+ }
131
+ // restore methods
132
+ restoreOne(model, target) {
133
+ return handleDbError(async () => {
134
+ const instance = await this.__getInstance(model, target, false);
135
+ await instance.restore({ transaction: this.__tx });
136
+ return this.findOne(model, instance.id);
137
+ });
138
+ }
139
+ restoreMany(model, where) {
140
+ return handleDbError(() => {
141
+ return model.restore({ where, transaction: this.__tx });
142
+ });
143
+ }
144
+ // helpers methods
145
+ __getInstance(model, target, paranoid = true) {
146
+ if (target && typeof target === 'object' && 'id' in target)
147
+ return target;
148
+ return this.findOne(model, target, { paranoid });
149
+ }
150
+ __deleteOne(model, target, force) {
151
+ return handleDbError(async () => {
152
+ const instance = await this.__getInstance(model, target);
153
+ await instance.destroy({ force, transaction: this.__tx });
154
+ return this.findOneOrNull(model, instance.id, { paranoid: false });
155
+ });
156
+ }
157
+ __deleteMany(model, where, force) {
158
+ return handleDbError(() => {
159
+ return model.destroy({ where, force, transaction: this.__tx });
160
+ });
161
+ }
162
+ // foreign key methods
163
+ enableForeignKeyChecks() {
164
+ const dbClient = (0, db_client_1.getDbClient)();
165
+ return dbClient.query('SET FOREIGN_KEY_CHECKS = 1', { transaction: this.__tx });
166
+ }
167
+ disableForeignKeyChecks() {
168
+ const dbClient = (0, db_client_1.getDbClient)();
169
+ return dbClient.query('SET FOREIGN_KEY_CHECKS = 0', { transaction: this.__tx });
170
+ }
171
+ }
172
+ exports.Db = Db;
173
+ // internal functions
174
+ function getFinalAttributes(attributes) {
175
+ if (!attributes)
176
+ return;
177
+ return attributes.map(([column, alias]) => {
178
+ if (typeof column === 'string')
179
+ return [(0, sequelize_1.col)(column), alias];
180
+ const [op, field] = column;
181
+ return [(0, sequelize_1.fn)(op, (0, sequelize_1.col)(field)), alias];
182
+ });
183
+ }
184
+ function convertWhereKeys(obj) {
185
+ if (Array.isArray(obj)) {
186
+ return obj.map(convertWhereKeys);
187
+ }
188
+ else if (obj &&
189
+ typeof obj === 'object' &&
190
+ !(obj instanceof Date) &&
191
+ !(obj instanceof RegExp) &&
192
+ !(obj instanceof Map) &&
193
+ !(obj instanceof Set) &&
194
+ !(typeof obj === 'function')) {
195
+ const newObj = {};
196
+ for (const key of Reflect.ownKeys(obj)) {
197
+ const value = obj[key];
198
+ let newKey = key;
199
+ if (typeof key === 'string' && key.startsWith('$') && key.endsWith('$')) {
200
+ const inner = key.slice(1, -1);
201
+ const parts = inner.split('.');
202
+ if (parts.length >= 2) {
203
+ const last = parts.pop();
204
+ const transformed = (0, pangea_helpers_1.camelToSnake)(last);
205
+ newKey = `$${[...parts, transformed].join('.')}$`;
206
+ }
207
+ }
208
+ newObj[newKey] = convertWhereKeys(value);
209
+ }
210
+ return newObj;
211
+ }
212
+ return obj;
213
+ }
214
+ function getIncludeAndWhere(model, includeItems, where, relDepth = new Map()) {
215
+ const includeOptions = [];
216
+ const cleanWhere = { ...where };
217
+ for (const [relName, rel] of Object.entries(model.Relations)) {
218
+ const relKey = `${model.name}.${relName}`;
219
+ const currentDepth = relDepth.get(relKey) || 0;
220
+ const maxDepth = rel.joinDepth;
221
+ if (currentDepth >= maxDepth)
222
+ continue;
223
+ const { active = true, include: nestedIncludeItems = [] } = includeItems.find((i) => i.relation === relName) || {};
224
+ if (!rel.eager || !active)
225
+ continue;
226
+ const relWhere = cleanWhere[relName];
227
+ delete cleanWhere[relName];
228
+ const newRelDepth = new Map(relDepth);
229
+ newRelDepth.set(relKey, currentDepth + 1);
230
+ const relModel = rel.getModelFn();
231
+ includeOptions.push({
232
+ model: relModel,
233
+ as: relName,
234
+ required: rel.required,
235
+ paranoid: rel.paranoid,
236
+ ...getIncludeAndWhere(relModel, nestedIncludeItems, relWhere, newRelDepth),
237
+ });
238
+ }
239
+ return {
240
+ include: includeOptions,
241
+ ...(Reflect.ownKeys(cleanWhere).length && { where: convertWhereKeys(cleanWhere) }),
242
+ };
243
+ }
244
+ function getFinalOrder(order) {
245
+ return Object.entries(order || {}).map(([key, value]) => {
246
+ const parts = key.split('.');
247
+ const direction = value.toUpperCase();
248
+ return [...parts, direction];
249
+ });
250
+ }
251
+ async function handleDbError(operation) {
252
+ try {
253
+ return await operation();
254
+ }
255
+ catch (err) {
256
+ if (err instanceof sequelize_1.UniqueConstraintError) {
257
+ helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'DUPLICATE_KEY', err });
258
+ }
259
+ if (err instanceof sequelize_1.ForeignKeyConstraintError) {
260
+ const originalErr = err.original;
261
+ if (originalErr.errno === 1451) {
262
+ helpers_1.AppError.Throw({ statusCodeName: 'CONFLICT', errorCode: 'MODELS_ASSOCIATED', err });
263
+ }
264
+ if (originalErr.errno === 1452) {
265
+ helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'FOREIGN_KEY_INTEGRITY', err });
266
+ }
267
+ }
268
+ throw err;
269
+ }
270
+ }
@@ -0,0 +1,10 @@
1
+ import type { ModelValidateOptions } from 'sequelize';
2
+ import type { ColumnType, ColGeneralOptions, ColVirtualOptions } from '../../../database/database.types';
3
+ type ForeignKeyAction = 'RESTRICT' | 'CASCADE' | 'SET NULL';
4
+ type ColumnOptions = ColGeneralOptions & ColVirtualOptions & {
5
+ validate?: ModelValidateOptions;
6
+ onUpdate?: ForeignKeyAction;
7
+ onDelete?: ForeignKeyAction;
8
+ };
9
+ export declare function Column(type: ColumnType, options?: ColumnOptions): (target: any, propertyName: string) => void;
10
+ export {};
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Column = void 0;
27
+ const seq = __importStar(require("sequelize-typescript"));
28
+ function Column(type, options = {}) {
29
+ const { nullable = false, defaultValue, index, unique = false, exclude, get, set, ...restOptions } = options;
30
+ return function (target, propertyName) {
31
+ seq.Column({
32
+ type: typeof type === 'string' ? seq.DataType[type] : type,
33
+ allowNull: nullable,
34
+ defaultValue,
35
+ ...(get && { get }),
36
+ ...(set && { set }),
37
+ ...restOptions,
38
+ })(target, propertyName);
39
+ const model = target.constructor;
40
+ model.AddColumn(propertyName, { allowNull: nullable, defaultValue });
41
+ if (index || unique)
42
+ model.AddColumnIndex({ field: propertyName, unique });
43
+ if (exclude)
44
+ model.AddExcludedAttribute(propertyName);
45
+ };
46
+ }
47
+ exports.Column = Column;
@@ -0,0 +1,4 @@
1
+ import type { ColGeneralOptions } from '../../../database/database.types';
2
+ export declare function ColDatetime(options?: ColGeneralOptions): (target: any, propertyName: string) => void;
3
+ export declare function ColDate(options?: ColGeneralOptions): (target: any, propertyName: string) => void;
4
+ export declare function ColTime(options?: ColGeneralOptions): (target: any, propertyName: string) => void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ColTime = exports.ColDate = exports.ColDatetime = void 0;
4
+ const column_1 = require("./column");
5
+ function ColDatetime(options) {
6
+ return (0, column_1.Column)('DATE', options);
7
+ }
8
+ exports.ColDatetime = ColDatetime;
9
+ function ColDate(options) {
10
+ return (0, column_1.Column)('DATEONLY', options);
11
+ }
12
+ exports.ColDate = ColDate;
13
+ function ColTime(options) {
14
+ return (0, column_1.Column)('TIME', options);
15
+ }
16
+ exports.ColTime = ColTime;
@@ -0,0 +1,4 @@
1
+ import type { ColGeneralOptions, ColVirtualGet, ColVirtualOptions, GetModelFn } from '../../../database/database.types';
2
+ export declare function ColBool(options?: ColGeneralOptions): (target: any, propertyName: string) => void;
3
+ export declare function ColForeignKey(getModelFn: GetModelFn, options?: ColGeneralOptions): (target: any, propertyName: string) => void;
4
+ export declare function ColVirtual(options?: ColVirtualOptions | ColVirtualGet): Function;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ColVirtual = exports.ColForeignKey = exports.ColBool = void 0;
27
+ const seq = __importStar(require("sequelize-typescript"));
28
+ const column_1 = require("./column");
29
+ function ColBool(options) {
30
+ return (0, column_1.Column)('BOOLEAN', options);
31
+ }
32
+ exports.ColBool = ColBool;
33
+ function ColForeignKey(getModelFn, options) {
34
+ return function (target, propertyName) {
35
+ (0, column_1.Column)('INTEGER', { ...options, onUpdate: 'RESTRICT', onDelete: 'RESTRICT' })(target, propertyName);
36
+ seq.ForeignKey(getModelFn)(target, propertyName);
37
+ };
38
+ }
39
+ exports.ColForeignKey = ColForeignKey;
40
+ function ColVirtual(options) {
41
+ let get;
42
+ let set;
43
+ if (options) {
44
+ if (typeof options === 'function') {
45
+ get = options;
46
+ }
47
+ else {
48
+ get = options.get;
49
+ set = options.set;
50
+ }
51
+ }
52
+ return seq.Column({ type: seq.DataType.VIRTUAL, ...(get && { get }), ...(set && { set }) });
53
+ }
54
+ exports.ColVirtual = ColVirtual;
@@ -0,0 +1,3 @@
1
+ import type { ColGeneralOptions } from '../../../database/database.types';
2
+ export declare function ColJson(options?: ColGeneralOptions): (target: any, propertyName: string) => void;
3
+ export declare function ColStrArray(): (target: any, propertyName: string) => void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ColStrArray = exports.ColJson = void 0;
4
+ const column_1 = require("./column");
5
+ function ColJson(options) {
6
+ return (0, column_1.Column)('JSON', options);
7
+ }
8
+ exports.ColJson = ColJson;
9
+ function ColStrArray() {
10
+ return function (target, propertyName) {
11
+ (0, column_1.Column)('TEXT', {
12
+ get() {
13
+ const val = this.getDataValue(propertyName);
14
+ return typeof val === 'string' && val.length > 0 ? val.split(',') : [];
15
+ },
16
+ set(val) {
17
+ this.setDataValue(propertyName, val.join(','));
18
+ },
19
+ })(target, propertyName);
20
+ };
21
+ }
22
+ exports.ColStrArray = ColStrArray;
@@ -0,0 +1,10 @@
1
+ import type { ColGeneralOptions } from '../../../database/database.types';
2
+ type ColNumOptions = ColGeneralOptions & {
3
+ min?: number;
4
+ max?: number;
5
+ };
6
+ export declare function ColInt(options?: ColNumOptions): (target: any, propertyName: string) => void;
7
+ export declare function ColBigInt(options?: ColNumOptions): (target: any, propertyName: string) => void;
8
+ export declare function ColFloat(options?: ColNumOptions): (target: any, propertyName: string) => void;
9
+ export declare function ColDouble(options?: ColNumOptions): (target: any, propertyName: string) => void;
10
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ColDouble = exports.ColFloat = exports.ColBigInt = exports.ColInt = void 0;
4
+ const column_1 = require("./column");
5
+ function ColInt(options) {
6
+ return getNumColumn('INTEGER', options);
7
+ }
8
+ exports.ColInt = ColInt;
9
+ function ColBigInt(options) {
10
+ return getNumColumn('BIGINT', options);
11
+ }
12
+ exports.ColBigInt = ColBigInt;
13
+ function ColFloat(options) {
14
+ return getNumColumn('FLOAT', options);
15
+ }
16
+ exports.ColFloat = ColFloat;
17
+ function ColDouble(options) {
18
+ return getNumColumn('DOUBLE', options);
19
+ }
20
+ exports.ColDouble = ColDouble;
21
+ // internal functions
22
+ function getNumColumn(type, options = {}) {
23
+ const { min, max, ...restOptions } = options;
24
+ const validate = {};
25
+ if (min !== undefined)
26
+ validate.min = min;
27
+ if (max !== undefined)
28
+ validate.max = max;
29
+ return (0, column_1.Column)(type, {
30
+ ...restOptions,
31
+ ...(Object.keys(validate).length ? { validate } : {}),
32
+ });
33
+ }
@@ -0,0 +1,10 @@
1
+ import { type StringLength } from '../../../resources';
2
+ import type { ColGeneralOptions } from '../../../database/database.types';
3
+ type ColStrOptions = ColGeneralOptions & {
4
+ minLength?: StringLength | number;
5
+ maxLength: StringLength | number;
6
+ regex?: RegExp;
7
+ };
8
+ export declare function ColStr(options: ColStrOptions): (target: any, propertyName: string) => void;
9
+ export declare function ColText(options?: Partial<ColStrOptions>): (target: any, propertyName: string) => void;
10
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ColText = exports.ColStr = void 0;
27
+ const seq = __importStar(require("sequelize-typescript"));
28
+ const column_1 = require("./column");
29
+ // resources
30
+ const resources_1 = require("../../../resources");
31
+ function ColStr(options) {
32
+ return getStrColumn(seq.DataType.STRING(getLength(255, options.maxLength)), options);
33
+ }
34
+ exports.ColStr = ColStr;
35
+ function ColText(options) {
36
+ return getStrColumn('TEXT', options);
37
+ }
38
+ exports.ColText = ColText;
39
+ // internal functions
40
+ function getStrColumn(type, options = {}) {
41
+ return (0, column_1.Column)(type, {
42
+ ...options,
43
+ validate: {
44
+ len: [getLength(0, options.minLength), getLength(Infinity, options.maxLength)],
45
+ ...(options.regex ? { is: options.regex } : {}),
46
+ },
47
+ });
48
+ }
49
+ function getLength(fallbackLength, length) {
50
+ if (!length)
51
+ return fallbackLength;
52
+ if (typeof length === 'number')
53
+ return length;
54
+ return resources_1.STRING_LENGTHS[length];
55
+ }
@@ -0,0 +1,23 @@
1
+ import * as str from './columns/string.columns';
2
+ import * as num from './columns/number.columns';
3
+ import * as date from './columns/date.columns';
4
+ import * as json from './columns/json.columns';
5
+ import * as general from './columns/general.columns';
6
+ export { Table } from './table';
7
+ export declare const col: {
8
+ Str: typeof str.ColStr;
9
+ Text: typeof str.ColText;
10
+ Int: typeof num.ColInt;
11
+ BigInt: typeof num.ColBigInt;
12
+ Float: typeof num.ColFloat;
13
+ Double: typeof num.ColDouble;
14
+ Datetime: typeof date.ColDatetime;
15
+ Date: typeof date.ColDate;
16
+ Time: typeof date.ColTime;
17
+ Json: typeof json.ColJson;
18
+ StrArray: typeof json.ColStrArray;
19
+ Bool: typeof general.ColBool;
20
+ ForeignKey: typeof general.ColForeignKey;
21
+ Virtual: typeof general.ColVirtual;
22
+ };
23
+ export * as rel from './relations';
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.rel = exports.col = exports.Table = void 0;
27
+ const str = __importStar(require("./columns/string.columns"));
28
+ const num = __importStar(require("./columns/number.columns"));
29
+ const date = __importStar(require("./columns/date.columns"));
30
+ const json = __importStar(require("./columns/json.columns"));
31
+ const general = __importStar(require("./columns/general.columns"));
32
+ var table_1 = require("./table");
33
+ Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return table_1.Table; } });
34
+ exports.col = {
35
+ Str: str.ColStr,
36
+ Text: str.ColText,
37
+ Int: num.ColInt,
38
+ BigInt: num.ColBigInt,
39
+ Float: num.ColFloat,
40
+ Double: num.ColDouble,
41
+ Datetime: date.ColDatetime,
42
+ Date: date.ColDate,
43
+ Time: date.ColTime,
44
+ Json: json.ColJson,
45
+ StrArray: json.ColStrArray,
46
+ Bool: general.ColBool,
47
+ ForeignKey: general.ColForeignKey,
48
+ Virtual: general.ColVirtual,
49
+ };
50
+ exports.rel = __importStar(require("./relations"));
@@ -0,0 +1,12 @@
1
+ import type { GetModelFn } from '../database.types';
2
+ type RelationOptions = {
3
+ eager?: boolean;
4
+ required?: boolean;
5
+ paranoid?: boolean;
6
+ joinDepth?: number;
7
+ foreignKey?: string;
8
+ };
9
+ export declare const BelongsTo: (getModelFn: GetModelFn, options?: RelationOptions) => (target: any, propertyName: string) => void;
10
+ export declare const HasOne: (getModelFn: GetModelFn, options?: RelationOptions) => (target: any, propertyName: string) => void;
11
+ export declare const HasMany: (getModelFn: GetModelFn, options?: RelationOptions) => (target: any, propertyName: string) => void;
12
+ export {};