@asapjs/sequelize 0.0.5 → 0.0.8
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/dist/dto/index.d.ts +8 -4
- package/dist/dto/index.d.ts.map +1 -1
- package/dist/dto/index.js +15 -43
- package/dist/dto/index.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/repository/index.d.ts +4 -4
- package/dist/repository/index.d.ts.map +1 -1
- package/dist/table/index.d.ts +3 -0
- package/dist/table/index.d.ts.map +1 -0
- package/dist/table/index.js +38 -0
- package/dist/table/index.js.map +1 -0
- package/dist/type/index.d.ts +40 -0
- package/dist/type/index.d.ts.map +1 -0
- package/dist/type/index.js +246 -0
- package/dist/type/index.js.map +1 -0
- package/dist/{util → utils}/getUserIdInQuery.d.ts +0 -0
- package/dist/utils/getUserIdInQuery.d.ts.map +1 -0
- package/dist/{util → utils}/getUserIdInQuery.js +1 -1
- package/dist/utils/getUserIdInQuery.js.map +1 -0
- package/dist/utils/isClass.d.ts +3 -0
- package/dist/utils/isClass.d.ts.map +1 -0
- package/dist/utils/isClass.js +4 -0
- package/dist/utils/isClass.js.map +1 -0
- package/package.json +2 -1
- package/src/dto/index.ts +15 -43
- package/src/index.ts +4 -1
- package/src/repository/index.ts +4 -4
- package/src/table/index.ts +43 -0
- package/src/type/index.ts +274 -0
- package/src/{util → utils}/getUserIdInQuery.ts +1 -1
- package/src/utils/isClass.ts +1 -0
- package/dist/util/getUserIdInQuery.d.ts.map +0 -1
- package/dist/util/getUserIdInQuery.js.map +0 -1
package/dist/dto/index.d.ts
CHANGED
|
@@ -7,18 +7,22 @@ interface DtoMiddlewareReturn {
|
|
|
7
7
|
attributes: string[];
|
|
8
8
|
include?: Includeable[];
|
|
9
9
|
}
|
|
10
|
-
export declare class
|
|
10
|
+
export declare class ExtendableDto {
|
|
11
11
|
id?: number;
|
|
12
12
|
version?: number | any;
|
|
13
|
-
private getExampleDataWithSequelizeDataType;
|
|
14
13
|
private fixValue;
|
|
15
14
|
map: (data: any) => any;
|
|
16
15
|
middleware: (as?: string | undefined, user?: any, extraAs?: string[] | undefined) => DtoMiddlewareReturn;
|
|
17
|
-
swagger: () =>
|
|
16
|
+
swagger: () => {
|
|
17
|
+
type: string;
|
|
18
|
+
properties: {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
18
22
|
}
|
|
19
23
|
export declare function Dto(info: {
|
|
20
24
|
timestamps?: boolean;
|
|
21
|
-
|
|
25
|
+
name?: string;
|
|
22
26
|
defineTable: typeof Model;
|
|
23
27
|
}): (target: any, options?: TableOptions) => void;
|
|
24
28
|
export declare function DtoType(ConnectTo: any, as: string): (target: any, propertyName: string, propertyDescriptor?: PropertyDescriptor | undefined) => void;
|
package/dist/dto/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dto/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dto/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAY,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,WAAW,EAAW,MAAM,WAAW,CAAC;AAI9E,UAAU,mBAAmB;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,qBAAa,aAAa;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,OAAO,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAE9B,OAAO,CAAC,QAAQ,CAkBd;IAEK,GAAG,SAAU,GAAG,KAAG,GAAG,CAsC3B;IAEK,UAAU,mCAAwB,GAAG,yDAsD1C;IAEK,OAAO;;;;;MAeZ;CACH;AAED,wBAAgB,GAAG,CAAC,IAAI,EAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,OAAO,KAAK,CAAA;CAAE,YACzD,GAAG,YAAW,YAAY,KAAQ,IAAI,CAOxE;AAuBD,wBAAgB,OAAO,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,YAChC,GAAG,gBAAgB,MAAM,+DAkB1C;AAED,UAAU,WAAW;IACnB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,cAAc;IACtB,KAAK,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,CAAC;IACtC,IAAI,CAAC,EAAE,2BAA2B,CAAC;IACnC,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED,wBAAgB,QAAQ,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,cAAc,YAC/C,GAAG,gBAAgB,MAAM,+DAe1C"}
|
package/dist/dto/index.js
CHANGED
|
@@ -1,29 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DtoQuery = exports.DtoType = exports.Dto = exports.
|
|
3
|
+
exports.DtoQuery = exports.DtoType = exports.Dto = exports.ExtendableDto = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
6
6
|
const sequelize_1 = require("sequelize");
|
|
7
|
-
|
|
7
|
+
const type_1 = require("../type");
|
|
8
|
+
class ExtendableDto {
|
|
8
9
|
constructor() {
|
|
9
|
-
this.getExampleDataWithSequelizeDataType = (type) => {
|
|
10
|
-
if (typeof type.values === 'object')
|
|
11
|
-
return type.values[0];
|
|
12
|
-
switch (type) {
|
|
13
|
-
case sequelize_typescript_1.DataType.INTEGER:
|
|
14
|
-
return 0;
|
|
15
|
-
case sequelize_typescript_1.DataType.ARRAY:
|
|
16
|
-
return [];
|
|
17
|
-
case sequelize_typescript_1.DataType.STRING:
|
|
18
|
-
return 'string';
|
|
19
|
-
case sequelize_typescript_1.DataType.DATE:
|
|
20
|
-
return '2022-01-01T00:00:00.000Z';
|
|
21
|
-
case sequelize_typescript_1.DataType.BOOLEAN:
|
|
22
|
-
return true;
|
|
23
|
-
default:
|
|
24
|
-
return 'string';
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
10
|
this.fixValue = (type, value) => {
|
|
28
11
|
switch (type) {
|
|
29
12
|
case sequelize_typescript_1.DataType.INTEGER:
|
|
@@ -121,36 +104,25 @@ class SequelizeDto {
|
|
|
121
104
|
return result;
|
|
122
105
|
};
|
|
123
106
|
this.swagger = () => {
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const queryData = queryOptions[key];
|
|
136
|
-
attributes[key] = (queryData === null || queryData === void 0 ? void 0 : queryData.example) || this.getExampleDataWithSequelizeDataType(queryData.data.type);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
if (connectOptions) {
|
|
140
|
-
Object.keys(connectOptions).forEach((key) => {
|
|
141
|
-
attributes[key] = connectOptions[key].example;
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
return attributes;
|
|
107
|
+
const types = (0, type_1.getTypesData)(this);
|
|
108
|
+
const data = Object.keys(types).reduce((p, key) => {
|
|
109
|
+
var _a;
|
|
110
|
+
const property = types[key];
|
|
111
|
+
p[key] = ((_a = property === null || property === void 0 ? void 0 : property.toSwagger) === null || _a === void 0 ? void 0 : _a.call(property)) || null;
|
|
112
|
+
return p;
|
|
113
|
+
}, {});
|
|
114
|
+
return {
|
|
115
|
+
type: 'object',
|
|
116
|
+
properties: data,
|
|
117
|
+
};
|
|
145
118
|
};
|
|
146
119
|
}
|
|
147
120
|
}
|
|
148
|
-
exports.
|
|
121
|
+
exports.ExtendableDto = ExtendableDto;
|
|
149
122
|
function Dto(info) {
|
|
150
123
|
return function annotate(target, options = {}) {
|
|
151
124
|
const args = Object.assign(Object.assign({}, info), { timestamps: info.timestamps === undefined });
|
|
152
125
|
Reflect.defineMetadata('sequelize::dtoInfo', args, target.prototype);
|
|
153
|
-
(0, sequelize_typescript_1.addOptions)(target.prototype, options);
|
|
154
126
|
};
|
|
155
127
|
}
|
|
156
128
|
exports.Dto = Dto;
|
package/dist/dto/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dto/index.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAE1B,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dto/index.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAE1B,+DAAqE;AACrE,yCAA8E;AAE9E,kCAAuC;AASvC,MAAa,aAAa;IAA1B;QAKU,aAAQ,GAAG,CAAC,IAAS,EAAE,KAAU,EAAE,EAAE;YAC3C,QAAQ,IAAI,EAAE;gBACZ,KAAK,+BAAQ,CAAC,OAAO;oBACnB,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;wBAAE,OAAO,KAAK,CAAC;oBACxD,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;gBACrC,KAAK,+BAAQ,CAAC,KAAK;oBACjB,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;wBAAE,OAAO,KAAK,CAAC;oBACxD,OAAO,UAAU,CAAC,MAAM,CAAC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,GAAG,IAAI,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAExD,MAAM,OAAO,GAAG;YACd,IAAI,EAAE,KAAK;YACX,EAAE;YACF,UAAU;YACV,OAAO,EAAE,kBAAkB;SAC5B,CAAC;QAEF,UAAU,CAAC,YAAY,CAAC,qBAAQ,OAAO,CAAE,CAAC;QAE1C,OAAO,CAAC,cAAc,CAAC,qBAAqB,oBAAO,UAAU,GAAI,MAAM,CAAC,CAAC;IAC3E,CAAC,CAAC;AACJ,CAAC;AAnBD,0BAmBC;AAaD,SAAgB,QAAQ,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAkB;IAC/D,OAAO,CAAC,MAAW,EAAE,YAAoB,EAAE,kBAAuC,EAAE,EAAE;QACpF,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QAEtC,OAAO,CAAC,YAAY,CAAC,GAAG;YACtB,IAAI,EAAE,OAAO;YACb,IAAI,EAAE;gBACJ,EAAE,EAAE,YAAY;gBAChB,KAAK,EAAE,CAAC,KAAkB,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC;gBAC3C,IAAI;aACL;YACD,OAAO;SACR,CAAC;QAEF,OAAO,CAAC,cAAc,CAAC,uBAAuB,oBAAO,OAAO,GAAI,MAAM,CAAC,CAAC;IAC1E,CAAC,CAAC;AACJ,CAAC;AAhBD,4BAgBC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ExtendableDto, Dto, DtoType, DtoQuery } from './dto';
|
|
2
2
|
export { initSequelizeModule, getSequelize } from './sequelize';
|
|
3
3
|
export { default as Repository } from './repository';
|
|
4
|
+
export { Table } from './table';
|
|
5
|
+
export { TypeIs, TypeArray, DtoOrTypeIs } from './type';
|
|
6
|
+
export { getUserIdInQuery } from './utils/getUserIdInQuery';
|
|
4
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Repository = exports.getSequelize = exports.initSequelizeModule = exports.DtoQuery = exports.DtoType = exports.Dto = exports.
|
|
6
|
+
exports.getUserIdInQuery = exports.TypeArray = exports.TypeIs = exports.Table = exports.Repository = exports.getSequelize = exports.initSequelizeModule = exports.DtoQuery = exports.DtoType = exports.Dto = exports.ExtendableDto = void 0;
|
|
7
7
|
var dto_1 = require("./dto");
|
|
8
|
-
Object.defineProperty(exports, "
|
|
8
|
+
Object.defineProperty(exports, "ExtendableDto", { enumerable: true, get: function () { return dto_1.ExtendableDto; } });
|
|
9
9
|
Object.defineProperty(exports, "Dto", { enumerable: true, get: function () { return dto_1.Dto; } });
|
|
10
10
|
Object.defineProperty(exports, "DtoType", { enumerable: true, get: function () { return dto_1.DtoType; } });
|
|
11
11
|
Object.defineProperty(exports, "DtoQuery", { enumerable: true, get: function () { return dto_1.DtoQuery; } });
|
|
@@ -14,4 +14,11 @@ Object.defineProperty(exports, "initSequelizeModule", { enumerable: true, get: f
|
|
|
14
14
|
Object.defineProperty(exports, "getSequelize", { enumerable: true, get: function () { return sequelize_1.getSequelize; } });
|
|
15
15
|
var repository_1 = require("./repository");
|
|
16
16
|
Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return __importDefault(repository_1).default; } });
|
|
17
|
+
var table_1 = require("./table");
|
|
18
|
+
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return table_1.Table; } });
|
|
19
|
+
var type_1 = require("./type");
|
|
20
|
+
Object.defineProperty(exports, "TypeIs", { enumerable: true, get: function () { return type_1.TypeIs; } });
|
|
21
|
+
Object.defineProperty(exports, "TypeArray", { enumerable: true, get: function () { return type_1.TypeArray; } });
|
|
22
|
+
var getUserIdInQuery_1 = require("./utils/getUserIdInQuery");
|
|
23
|
+
Object.defineProperty(exports, "getUserIdInQuery", { enumerable: true, get: function () { return getUserIdInQuery_1.getUserIdInQuery; } });
|
|
17
24
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,6BAA8D;AAArD,oGAAA,aAAa,OAAA;AAAE,0FAAA,GAAG,OAAA;AAAE,8FAAA,OAAO,OAAA;AAAE,+FAAA,QAAQ,OAAA;AAC9C,yCAAgE;AAAvD,gHAAA,mBAAmB,OAAA;AAAE,yGAAA,YAAY,OAAA;AAC1C,2CAAqD;AAA5C,yHAAA,OAAO,OAAc;AAC9B,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,+BAAwD;AAA/C,8FAAA,MAAM,OAAA;AAAE,iGAAA,SAAS,OAAA;AAC1B,6DAA4D;AAAnD,oHAAA,gBAAgB,OAAA"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Model, ModelCtor } from 'sequelize-typescript';
|
|
2
2
|
import { FindOptions } from 'sequelize';
|
|
3
|
-
import {
|
|
3
|
+
import { ExtendableDto } from '../dto';
|
|
4
4
|
interface IArgs<T extends Model> extends FindOptions<T> {
|
|
5
|
-
exportTo: typeof
|
|
5
|
+
exportTo: typeof ExtendableDto;
|
|
6
6
|
user?: any;
|
|
7
7
|
withDto?: boolean;
|
|
8
8
|
}
|
|
9
|
-
declare type FindAllResponseWithDto<T> = [T[],
|
|
9
|
+
declare type FindAllResponseWithDto<T> = [T[], ExtendableDto];
|
|
10
10
|
declare type FindAllResponse<T, WithDto = {}> = WithDto extends true ? FindAllResponseWithDto<T> : T[];
|
|
11
|
-
declare type FindOneResponseWithDto<T> = [T | null,
|
|
11
|
+
declare type FindOneResponseWithDto<T> = [T | null, ExtendableDto];
|
|
12
12
|
declare type FindOneResponse<T, WithDto = {}> = WithDto extends true ? FindOneResponseWithDto<T> : T | null;
|
|
13
13
|
export default class Repository {
|
|
14
14
|
private getOptionsWithArgs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/repository/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/repository/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,UAAU,KAAK,CAAC,CAAC,SAAS,KAAK,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAC;IACrD,QAAQ,EAAE,OAAO,aAAa,CAAC;IAC/B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,aAAK,sBAAsB,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;AACtD,aAAK,eAAe,CAAC,CAAC,EAAE,OAAO,GAAG,EAAE,IAAI,OAAO,SAAS,IAAI,GAAG,sBAAsB,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;AAE/F,aAAK,sBAAsB,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,EAAE,aAAa,CAAC,CAAC;AAC3D,aAAK,eAAe,CAAC,CAAC,EAAE,OAAO,GAAG,EAAE,IAAI,OAAO,SAAS,IAAI,GAAG,sBAAsB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;AACpG,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,kBAAkB,CAKxB;IAEF,OAAO,CAAC,OAAO,CAQb;IAEF,OAAO,CAAC,OAAO,CAQb;IAEK,UAAU;;;MAGf;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/table/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,YAAY,EAAE,MAAM,WAAW,CAAC;AAY5F,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY,4BACE,GAAG,EAAE,KAAG,EAAE,qBA6BtD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Table = void 0;
|
|
4
|
+
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
5
|
+
const foreign_key_service_1 = require("sequelize-typescript/dist/associations/foreign-key/foreign-key-service");
|
|
6
|
+
const type_1 = require("../type");
|
|
7
|
+
function Table(options) {
|
|
8
|
+
return function (target) {
|
|
9
|
+
const types = (0, type_1.getTypesData)(target);
|
|
10
|
+
Object.entries(types).forEach(([key, type]) => {
|
|
11
|
+
if (!['foreignkey', 'belongsto'].includes(type.__name)) {
|
|
12
|
+
(0, sequelize_typescript_1.addAttribute)(target.prototype, key, type.toSequelize());
|
|
13
|
+
}
|
|
14
|
+
else if (type.__name === 'foreignkey') {
|
|
15
|
+
(0, foreign_key_service_1.addForeignKey)(target.prototype, type.toSequelize(), key);
|
|
16
|
+
}
|
|
17
|
+
else if (type.__name === 'belongsto') {
|
|
18
|
+
const { associatedClassGetter, optionsOrForeignKey } = type.toSequelize();
|
|
19
|
+
const options = (0, sequelize_typescript_1.getPreparedAssociationOptions)(optionsOrForeignKey);
|
|
20
|
+
if (!options.as)
|
|
21
|
+
options.as = key;
|
|
22
|
+
(0, sequelize_typescript_1.addAssociation)(target.prototype, new sequelize_typescript_1.BelongsToAssociation(associatedClassGetter, options));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
(0, sequelize_typescript_1.addOptions)(target.prototype, {
|
|
26
|
+
createdAt: 'created_at',
|
|
27
|
+
timestamps: true,
|
|
28
|
+
});
|
|
29
|
+
(0, sequelize_typescript_1.addOptions)(target.prototype, {
|
|
30
|
+
updatedAt: 'updated_at',
|
|
31
|
+
timestamps: true,
|
|
32
|
+
});
|
|
33
|
+
(0, sequelize_typescript_1.setModelName)(target.prototype, options.modelName || target.name);
|
|
34
|
+
(0, sequelize_typescript_1.addOptions)(target.prototype, options);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.Table = Table;
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/table/index.ts"],"names":[],"mappings":";;;AACA,+DAO8B;AAC9B,gHAAuG;AACvG,kC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SACjB,CAAC,CAAC;QAEH,IAAA,mCAAY,EAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;QACjE,IAAA,iCAAU,EAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC,CAAC;AACJ,CAAC;AA9BD,sBA8BC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ExtendableDto } from '../dto';
|
|
2
|
+
export declare const getTypesData: (target: any) => any;
|
|
3
|
+
export declare const saveNewTypesData: (attributes: any, target: any) => void;
|
|
4
|
+
export declare const saveTypesData: (target: any, propertyName: any, value: any) => void;
|
|
5
|
+
declare type TypeIsData = {
|
|
6
|
+
__name: string;
|
|
7
|
+
toSwagger?: (...args: any[]) => any;
|
|
8
|
+
toSequelize?: (...args: any[]) => any;
|
|
9
|
+
fixValue?: (o: any) => any;
|
|
10
|
+
};
|
|
11
|
+
export declare const TypeIs: {
|
|
12
|
+
INT: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
13
|
+
LONG: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
14
|
+
FLOAT: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
15
|
+
DOUBLE: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
16
|
+
STRING: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
17
|
+
TEXT: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
18
|
+
PASSWORD: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
19
|
+
ENUM: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
20
|
+
JSON: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
21
|
+
BASE64: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
22
|
+
BINARY: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
23
|
+
BOOLEAN: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
24
|
+
DATEONLY: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
25
|
+
DATETIME: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
26
|
+
FOREIGNKEY: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
27
|
+
BELONGSTO: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
28
|
+
DTO: (...options: any) => (target?: any, propertyName?: string | undefined, propertyDescriptor?: PropertyDescriptor | undefined) => void & TypeIsData;
|
|
29
|
+
};
|
|
30
|
+
export declare type DtoOrTypeIs = typeof ExtendableDto | (() => TypeIsData);
|
|
31
|
+
export declare const TypeArray: (value: DtoOrTypeIs) => {
|
|
32
|
+
new (): {
|
|
33
|
+
swagger: () => {
|
|
34
|
+
type: string;
|
|
35
|
+
items: any;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 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AAG,6FAAmE,IAAI,GAAG,UAAU;2BAD7F,GAAG,eACG,GAAG,6FAAmE,IAAI,GAAG,UAAU;2BAD7F,GAAG,eACG,GAAG,6FAAmE,IAAI,GAAG,UAAU;6BAD7F,GAAG,eACG,GAAG,6FAAmE,IAAI,GAAG,UAAU;4BAD7F,GAAG,eACG,GAAG,6FAAmE,IAAI,GAAG,UAAU;sBAD7F,GAAG,eACG,GAAG,6FAAmE,IAAI,GAAG,UAAU;CA2L3G,CAAC;AAyBF,oBAAY,WAAW,GAAG,OAAO,aAAa,GAAG,CAAC,MAAM,UAAU,CAAC,CAAC;AAEpE,eAAO,MAAM,SAAS,UAAW,WAAW;;;;;;;CAc3C,CAAC"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TypeArray = exports.TypeIs = exports.saveTypesData = exports.saveNewTypesData = exports.getTypesData = void 0;
|
|
7
|
+
const sequelize_1 = require("sequelize");
|
|
8
|
+
const isClass_1 = __importDefault(require("../utils/isClass"));
|
|
9
|
+
const data = {};
|
|
10
|
+
const getTypesData = (target) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const values = data[(target === null || target === void 0 ? void 0 : target.name) || ((_a = target === null || target === void 0 ? void 0 : target.constructor) === null || _a === void 0 ? void 0 : _a.name)];
|
|
13
|
+
if (!values)
|
|
14
|
+
return {};
|
|
15
|
+
return values;
|
|
16
|
+
};
|
|
17
|
+
exports.getTypesData = getTypesData;
|
|
18
|
+
const saveNewTypesData = (attributes, target) => {
|
|
19
|
+
data[target.constructor.name] = attributes;
|
|
20
|
+
};
|
|
21
|
+
exports.saveNewTypesData = saveNewTypesData;
|
|
22
|
+
const saveTypesData = (target, propertyName, value) => {
|
|
23
|
+
const types = (0, exports.getTypesData)(target);
|
|
24
|
+
types[propertyName] = value;
|
|
25
|
+
(0, exports.saveNewTypesData)(types, target);
|
|
26
|
+
};
|
|
27
|
+
exports.saveTypesData = saveTypesData;
|
|
28
|
+
const typeGenerator = (data) => (...options) => {
|
|
29
|
+
return (target, propertyName, propertyDescriptor) => {
|
|
30
|
+
if (target !== undefined) {
|
|
31
|
+
const type = data(...options);
|
|
32
|
+
(0, exports.saveTypesData)(target, propertyName, type);
|
|
33
|
+
if (propertyDescriptor) {
|
|
34
|
+
propertyDescriptor.value = type;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return data(...options);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.TypeIs = {
|
|
43
|
+
INT: typeGenerator((options) => ({
|
|
44
|
+
__name: 'int',
|
|
45
|
+
toSwagger: () => ({
|
|
46
|
+
type: 'integer',
|
|
47
|
+
format: 'int32',
|
|
48
|
+
description: options === null || options === void 0 ? void 0 : options.comment,
|
|
49
|
+
}),
|
|
50
|
+
toSequelize: () => ({ type: sequelize_1.DataTypes.INTEGER(options), comment: options === null || options === void 0 ? void 0 : options.comment }),
|
|
51
|
+
fixValue: (o) => {
|
|
52
|
+
if (o === undefined || o === null)
|
|
53
|
+
return o;
|
|
54
|
+
return parseInt(String(o), 10);
|
|
55
|
+
},
|
|
56
|
+
})),
|
|
57
|
+
LONG: typeGenerator((options) => ({
|
|
58
|
+
__name: 'long',
|
|
59
|
+
toSwagger: () => ({
|
|
60
|
+
type: 'integer',
|
|
61
|
+
format: 'int64',
|
|
62
|
+
description: options === null || options === void 0 ? void 0 : options.comment,
|
|
63
|
+
}),
|
|
64
|
+
toSequelize: () => ({ type: sequelize_1.DataTypes.INTEGER(options), comment: options === null || options === void 0 ? void 0 : options.comment }),
|
|
65
|
+
fixValue: (o) => {
|
|
66
|
+
if (o === undefined || o === null)
|
|
67
|
+
return o;
|
|
68
|
+
return parseInt(String(o), 10);
|
|
69
|
+
},
|
|
70
|
+
})),
|
|
71
|
+
FLOAT: typeGenerator((options) => ({
|
|
72
|
+
__name: 'float',
|
|
73
|
+
toSwagger: () => ({
|
|
74
|
+
type: 'integer',
|
|
75
|
+
format: 'float',
|
|
76
|
+
description: options === null || options === void 0 ? void 0 : options.comment,
|
|
77
|
+
}),
|
|
78
|
+
toSequelize: () => ({ type: sequelize_1.DataTypes.FLOAT(options === null || options === void 0 ? void 0 : options.length, options === null || options === void 0 ? void 0 : options.decimals), comment: options === null || options === void 0 ? void 0 : options.comment }),
|
|
79
|
+
fixValue: (o) => {
|
|
80
|
+
if (o === undefined || o === null)
|
|
81
|
+
return o;
|
|
82
|
+
return parseFloat(String(o));
|
|
83
|
+
},
|
|
84
|
+
})),
|
|
85
|
+
DOUBLE: typeGenerator((options) => ({
|
|
86
|
+
__name: 'double',
|
|
87
|
+
toSwagger: () => ({
|
|
88
|
+
type: 'number',
|
|
89
|
+
format: 'double',
|
|
90
|
+
description: options === null || options === void 0 ? void 0 : options.comment,
|
|
91
|
+
}),
|
|
92
|
+
toSequelize: () => ({ type: sequelize_1.DataTypes.DOUBLE(options === null || options === void 0 ? void 0 : options.length, options === null || options === void 0 ? void 0 : options.decimals), comment: options === null || options === void 0 ? void 0 : options.comment }),
|
|
93
|
+
fixValue: (o) => {
|
|
94
|
+
if (o === undefined || o === null)
|
|
95
|
+
return o;
|
|
96
|
+
return parseFloat(String(o));
|
|
97
|
+
},
|
|
98
|
+
})),
|
|
99
|
+
STRING: typeGenerator((options) => ({
|
|
100
|
+
__name: 'string',
|
|
101
|
+
toSwagger: () => ({
|
|
102
|
+
type: 'string',
|
|
103
|
+
description: options === null || options === void 0 ? void 0 : options.comment,
|
|
104
|
+
}),
|
|
105
|
+
toSequelize: () => ({ type: sequelize_1.DataTypes.STRING(options === null || options === void 0 ? void 0 : options.length, options === null || options === void 0 ? void 0 : options.binary), comment: options === null || options === void 0 ? void 0 : options.comment }),
|
|
106
|
+
fixValue: (o) => {
|
|
107
|
+
if (o === undefined || o === null)
|
|
108
|
+
return o;
|
|
109
|
+
return String(o);
|
|
110
|
+
},
|
|
111
|
+
})),
|
|
112
|
+
TEXT: typeGenerator((options) => ({
|
|
113
|
+
__name: 'text',
|
|
114
|
+
toSwagger: () => ({
|
|
115
|
+
type: 'string',
|
|
116
|
+
description: options === null || options === void 0 ? void 0 : options.comment,
|
|
117
|
+
}),
|
|
118
|
+
toSequelize: () => ({ type: sequelize_1.DataTypes.TEXT({ length: options === null || options === void 0 ? void 0 : options.length }), comment: options === null || options === void 0 ? void 0 : options.comment }),
|
|
119
|
+
fixValue: (o) => {
|
|
120
|
+
if (o === undefined || o === null)
|
|
121
|
+
return o;
|
|
122
|
+
return String(o);
|
|
123
|
+
},
|
|
124
|
+
})),
|
|
125
|
+
PASSWORD: typeGenerator((options) => ({
|
|
126
|
+
__name: 'password',
|
|
127
|
+
toSwagger: () => ({
|
|
128
|
+
type: 'string',
|
|
129
|
+
format: 'password',
|
|
130
|
+
description: options === null || options === void 0 ? void 0 : options.comment,
|
|
131
|
+
}),
|
|
132
|
+
toSequelize: () => ({ type: sequelize_1.DataTypes.STRING(512), comment: options === null || options === void 0 ? void 0 : options.comment }),
|
|
133
|
+
})),
|
|
134
|
+
ENUM: typeGenerator((options) => ({
|
|
135
|
+
__name: 'enum',
|
|
136
|
+
toSwagger: () => {
|
|
137
|
+
var _a;
|
|
138
|
+
return ({
|
|
139
|
+
type: 'string',
|
|
140
|
+
enum: options === null || options === void 0 ? void 0 : options.values,
|
|
141
|
+
description: (_a = options === null || options === void 0 ? void 0 : options.values) === null || _a === void 0 ? void 0 : _a[0],
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
toSequelize: () => ({ type: sequelize_1.DataTypes.ENUM({ values: options === null || options === void 0 ? void 0 : options.values }), comment: options === null || options === void 0 ? void 0 : options.comment }),
|
|
145
|
+
fixValue: (o) => {
|
|
146
|
+
var _a, _b;
|
|
147
|
+
if (o === undefined || o === null)
|
|
148
|
+
return o;
|
|
149
|
+
return ((_b = (_a = options === null || options === void 0 ? void 0 : options.values) === null || _a === void 0 ? void 0 : _a.includes) === null || _b === void 0 ? void 0 : _b.call(_a, String(o))) ? String(o) : undefined;
|
|
150
|
+
},
|
|
151
|
+
})),
|
|
152
|
+
JSON: typeGenerator((options) => ({
|
|
153
|
+
__name: 'json',
|
|
154
|
+
toSwagger: () => ({
|
|
155
|
+
type: 'object',
|
|
156
|
+
description: options === null || options === void 0 ? void 0 : options.comment,
|
|
157
|
+
}),
|
|
158
|
+
toSequelize: () => ({ type: sequelize_1.DataTypes.JSON, comment: options === null || options === void 0 ? void 0 : options.comment }),
|
|
159
|
+
})),
|
|
160
|
+
BASE64: typeGenerator((options) => ({
|
|
161
|
+
__name: 'base64',
|
|
162
|
+
toSwagger: () => ({
|
|
163
|
+
type: 'string',
|
|
164
|
+
format: 'byte',
|
|
165
|
+
description: options === null || options === void 0 ? void 0 : options.comment,
|
|
166
|
+
}),
|
|
167
|
+
toSequelize: () => ({ type: sequelize_1.DataTypes.BLOB(options === null || options === void 0 ? void 0 : options.length), comment: options === null || options === void 0 ? void 0 : options.comment }),
|
|
168
|
+
})),
|
|
169
|
+
BINARY: typeGenerator((options) => ({
|
|
170
|
+
__name: 'binary',
|
|
171
|
+
toSwagger: () => ({
|
|
172
|
+
type: 'string',
|
|
173
|
+
format: 'binary',
|
|
174
|
+
description: options === null || options === void 0 ? void 0 : options.comment,
|
|
175
|
+
}),
|
|
176
|
+
toSequelize: () => ({ type: sequelize_1.DataTypes.BLOB(options === null || options === void 0 ? void 0 : options.length), comment: options === null || options === void 0 ? void 0 : options.comment }),
|
|
177
|
+
})),
|
|
178
|
+
BOOLEAN: typeGenerator((options) => ({
|
|
179
|
+
__name: 'boolean',
|
|
180
|
+
toSwagger: () => ({
|
|
181
|
+
type: 'boolean',
|
|
182
|
+
}),
|
|
183
|
+
toSequelize: () => ({ type: sequelize_1.DataTypes.BOOLEAN, comment: options === null || options === void 0 ? void 0 : options.comment }),
|
|
184
|
+
fixValue: (o) => {
|
|
185
|
+
if (o === undefined || o === null)
|
|
186
|
+
return o;
|
|
187
|
+
return String(o) === 'true' ? true : String(o) === 'false' ? false : !!o;
|
|
188
|
+
},
|
|
189
|
+
})),
|
|
190
|
+
DATEONLY: typeGenerator((options) => ({
|
|
191
|
+
__name: 'date',
|
|
192
|
+
toSwagger: () => ({
|
|
193
|
+
type: 'string',
|
|
194
|
+
format: 'date',
|
|
195
|
+
description: options === null || options === void 0 ? void 0 : options.comment,
|
|
196
|
+
}),
|
|
197
|
+
toSequelize: () => sequelize_1.DataTypes.DATEONLY(),
|
|
198
|
+
})),
|
|
199
|
+
DATETIME: typeGenerator((options) => ({
|
|
200
|
+
__name: 'datetime',
|
|
201
|
+
toSwagger: () => ({
|
|
202
|
+
type: 'string',
|
|
203
|
+
format: 'date-time',
|
|
204
|
+
description: options === null || options === void 0 ? void 0 : options.comment,
|
|
205
|
+
}),
|
|
206
|
+
toSequelize: () => sequelize_1.DataTypes.DATE,
|
|
207
|
+
})),
|
|
208
|
+
FOREIGNKEY: typeGenerator((table) => ({
|
|
209
|
+
__name: 'foreignkey',
|
|
210
|
+
toSequelize: () => table,
|
|
211
|
+
})),
|
|
212
|
+
BELONGSTO: typeGenerator((associatedClassGetter, optionsOrForeignKey) => ({
|
|
213
|
+
__name: 'belongsto',
|
|
214
|
+
toSequelize: () => ({
|
|
215
|
+
associatedClassGetter,
|
|
216
|
+
optionsOrForeignKey,
|
|
217
|
+
}),
|
|
218
|
+
})),
|
|
219
|
+
DTO: typeGenerator((options) => ({
|
|
220
|
+
__name: 'dto',
|
|
221
|
+
toSwagger: () => {
|
|
222
|
+
var _a;
|
|
223
|
+
const result = (_a = new (options === null || options === void 0 ? void 0 : options.dto)()) === null || _a === void 0 ? void 0 : _a.swagger();
|
|
224
|
+
return Object.assign(Object.assign({}, result), { comment: options === null || options === void 0 ? void 0 : options.comment });
|
|
225
|
+
},
|
|
226
|
+
})),
|
|
227
|
+
};
|
|
228
|
+
const TypeArray = (value) => {
|
|
229
|
+
return class {
|
|
230
|
+
constructor() {
|
|
231
|
+
this.swagger = () => {
|
|
232
|
+
var _a, _b, _c;
|
|
233
|
+
const isDto = (0, isClass_1.default)(value);
|
|
234
|
+
return {
|
|
235
|
+
type: 'array',
|
|
236
|
+
items: isDto
|
|
237
|
+
? (_a = new value()) === null || _a === void 0 ? void 0 : _a.swagger()
|
|
238
|
+
: (_c = (_b = value === null || value === void 0 ? void 0 : value()) === null || _b === void 0 ? void 0 : _b.toSwagger) === null || _c === void 0 ? void 0 : _c.call(_b),
|
|
239
|
+
// description: options?.comment,
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
exports.TypeArray = TypeArray;
|
|
246
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/type/index.ts"],"names":[],"mappings":";;;;;;AAAA,yCAA4D;AAC5D,+DAAuC;AAGvC,MAAM,IAAI,GAA2B,EAAE,CAAC;AAEjC,MAAM,YAAY,GAAG,CAAC,MAAW,EAAE,EAAE;;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,MAAI,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,0CAAE,IAAI,CAAA,CAAC,CAAC;IAC/D,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAJW,QAAA,YAAY,gBAIvB;AAEK,MAAM,gBAAgB,GAAG,CAAC,UAAe,EAAE,MAAW,EAAE,EAAE;IAC/D,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC;AAC7C,CAAC,CAAC;AAFW,QAAA,gBAAgB,oBAE3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gBAE7B,OAAO;oBACL,IAAI,EAAE,OAAO;oBACb,KAAK,EAAE,KAAK;wBACV,CAAC,CAAC,MAAA,IAAK,KAA8B,EAAE,0CAAE,OAAO,EAAE;wBAClD,CAAC,CAAC,MAAA,MAAC,KAA0B,aAA1B,KAAK,uBAAL,KAAK,EAAyB,0CAAE,SAAS,kDAAI;oBAClD,iCAAiC;iBAClC,CAAC;YACJ,CAAC,CAAC;QACJ,CAAC;KAAA,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,SAAS,aAcpB"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUserIdInQuery.d.ts","sourceRoot":"","sources":["../../src/utils/getUserIdInQuery.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,UAAW,GAAG,WAAuC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getUserIdInQuery = void 0;
|
|
4
|
-
const getUserIdInQuery = (user) => `"${(user === null || user === void 0 ? void 0 : user.id) || ''}"`;
|
|
4
|
+
const getUserIdInQuery = (user) => `"${(user === null || user === void 0 ? void 0 : user.id) || (user === null || user === void 0 ? void 0 : user._id) || ''}"`;
|
|
5
5
|
exports.getUserIdInQuery = getUserIdInQuery;
|
|
6
6
|
//# sourceMappingURL=getUserIdInQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUserIdInQuery.js","sourceRoot":"","sources":["../../src/utils/getUserIdInQuery.ts"],"names":[],"mappings":";;;AAAO,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAE,EAAE,CAAC,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,EAAE,MAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,GAAG,CAAA,IAAI,EAAE,GAAG,CAAC;AAAtE,QAAA,gBAAgB,oBAAsD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isClass.d.ts","sourceRoot":"","sources":["../../src/utils/isClass.ts"],"names":[],"mappings":"4BAAmB,GAAG;AAAtB,wBAAmE"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (v) => { var _a; return ((_a = v === null || v === void 0 ? void 0 : v.prototype) === null || _a === void 0 ? void 0 : _a.constructor) !== undefined; };
|
|
4
|
+
//# sourceMappingURL=isClass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isClass.js","sourceRoot":"","sources":["../../src/utils/isClass.ts"],"names":[],"mappings":";;AAAA,kBAAe,CAAC,CAAM,EAAE,EAAE,WAAC,OAAA,CAAA,MAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,SAAS,0CAAE,WAAW,MAAK,SAAS,CAAA,EAAA,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asapjs/sequelize",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"@types/cors": "^2.8.12",
|
|
26
26
|
"@types/express": "^4.17.13",
|
|
27
27
|
"@types/node": "^17.0.21",
|
|
28
|
+
"@types/sequelize": "^4.28.11",
|
|
28
29
|
"typescript": "^4.6.2"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
package/src/dto/index.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { DataType, Model, TableOptions } from 'sequelize-typescript';
|
|
4
4
|
import { AbstractDataTypeConstructor, Includeable, literal } from 'sequelize';
|
|
5
5
|
|
|
6
|
+
import { getTypesData } from '../type';
|
|
7
|
+
|
|
6
8
|
interface DtoMiddlewareReturn {
|
|
7
9
|
as?: string;
|
|
8
10
|
model: typeof Model;
|
|
@@ -10,29 +12,11 @@ interface DtoMiddlewareReturn {
|
|
|
10
12
|
include?: Includeable[];
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
export class
|
|
15
|
+
export class ExtendableDto {
|
|
14
16
|
public id?: number;
|
|
15
17
|
|
|
16
18
|
public version?: number | any;
|
|
17
19
|
|
|
18
|
-
private getExampleDataWithSequelizeDataType = (type: any) => {
|
|
19
|
-
if (typeof type.values === 'object') return type.values[0];
|
|
20
|
-
switch (type) {
|
|
21
|
-
case DataType.INTEGER:
|
|
22
|
-
return 0;
|
|
23
|
-
case DataType.ARRAY:
|
|
24
|
-
return [];
|
|
25
|
-
case DataType.STRING:
|
|
26
|
-
return 'string';
|
|
27
|
-
case DataType.DATE:
|
|
28
|
-
return '2022-01-01T00:00:00.000Z';
|
|
29
|
-
case DataType.BOOLEAN:
|
|
30
|
-
return true;
|
|
31
|
-
default:
|
|
32
|
-
return 'string';
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
20
|
private fixValue = (type: any, value: any) => {
|
|
37
21
|
switch (type) {
|
|
38
22
|
case DataType.INTEGER:
|
|
@@ -150,42 +134,30 @@ export class SequelizeDto {
|
|
|
150
134
|
};
|
|
151
135
|
|
|
152
136
|
public swagger = () => {
|
|
153
|
-
const
|
|
154
|
-
const connectOptions = Reflect.getMetadata('sequelize::dtoTypes', this);
|
|
155
|
-
const queryOptions = Reflect.getMetadata('sequelize::queryTypes', this);
|
|
137
|
+
const types = getTypesData(this);
|
|
156
138
|
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
Object.keys(attributesOptions).forEach((key) => {
|
|
160
|
-
attributes[key] = this.getExampleDataWithSequelizeDataType(attributesOptions[key].type);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
139
|
+
const data = Object.keys(types).reduce((p: { [key: string]: any }, key) => {
|
|
140
|
+
const property = types[key];
|
|
163
141
|
|
|
164
|
-
|
|
165
|
-
Object.keys(queryOptions).forEach((key) => {
|
|
166
|
-
const queryData = queryOptions[key];
|
|
167
|
-
attributes[key] = queryData?.example || this.getExampleDataWithSequelizeDataType(queryData.data.type);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
142
|
+
p[key] = property?.toSwagger?.() || null;
|
|
170
143
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
attributes[key] = connectOptions[key].example;
|
|
174
|
-
});
|
|
175
|
-
}
|
|
144
|
+
return p;
|
|
145
|
+
}, {});
|
|
176
146
|
|
|
177
|
-
return
|
|
147
|
+
return {
|
|
148
|
+
type: 'object',
|
|
149
|
+
properties: data,
|
|
150
|
+
};
|
|
178
151
|
};
|
|
179
152
|
}
|
|
180
153
|
|
|
181
|
-
export function Dto(info: { timestamps?: boolean;
|
|
154
|
+
export function Dto(info: { timestamps?: boolean; name?: string; defineTable: typeof Model }) {
|
|
182
155
|
return function annotate(target: any, options: TableOptions = {}): void {
|
|
183
156
|
const args = {
|
|
184
157
|
...info,
|
|
185
158
|
timestamps: info.timestamps === undefined,
|
|
186
159
|
};
|
|
187
160
|
Reflect.defineMetadata('sequelize::dtoInfo', args, target.prototype);
|
|
188
|
-
addOptions(target.prototype, options);
|
|
189
161
|
};
|
|
190
162
|
}
|
|
191
163
|
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ExtendableDto, Dto, DtoType, DtoQuery } from './dto';
|
|
2
2
|
export { initSequelizeModule, getSequelize } from './sequelize';
|
|
3
3
|
export { default as Repository } from './repository';
|
|
4
|
+
export { Table } from './table';
|
|
5
|
+
export { TypeIs, TypeArray, DtoOrTypeIs } from './type';
|
|
6
|
+
export { getUserIdInQuery } from './utils/getUserIdInQuery';
|
package/src/repository/index.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Model, ModelCtor } from 'sequelize-typescript';
|
|
2
2
|
import { FindOptions } from 'sequelize';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { ExtendableDto } from '../dto';
|
|
5
5
|
|
|
6
6
|
interface IArgs<T extends Model> extends FindOptions<T> {
|
|
7
|
-
exportTo: typeof
|
|
7
|
+
exportTo: typeof ExtendableDto;
|
|
8
8
|
user?: any;
|
|
9
9
|
withDto?: boolean;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
type FindAllResponseWithDto<T> = [T[],
|
|
12
|
+
type FindAllResponseWithDto<T> = [T[], ExtendableDto];
|
|
13
13
|
type FindAllResponse<T, WithDto = {}> = WithDto extends true ? FindAllResponseWithDto<T> : T[];
|
|
14
14
|
|
|
15
|
-
type FindOneResponseWithDto<T> = [T | null,
|
|
15
|
+
type FindOneResponseWithDto<T> = [T | null, ExtendableDto];
|
|
16
16
|
type FindOneResponse<T, WithDto = {}> = WithDto extends true ? FindOneResponseWithDto<T> : T | null;
|
|
17
17
|
export default class Repository {
|
|
18
18
|
private getOptionsWithArgs = <T extends Model>(args: IArgs<T>) => {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BelongsToOptions, BlobSize, DataTypes, TextLength, ModelOptions } from 'sequelize';
|
|
2
|
+
import {
|
|
3
|
+
addAttribute,
|
|
4
|
+
getPreparedAssociationOptions,
|
|
5
|
+
BelongsToAssociation,
|
|
6
|
+
addAssociation,
|
|
7
|
+
setModelName,
|
|
8
|
+
addOptions,
|
|
9
|
+
} from 'sequelize-typescript';
|
|
10
|
+
import { addForeignKey } from 'sequelize-typescript/dist/associations/foreign-key/foreign-key-service';
|
|
11
|
+
import { getTypesData } from '../type';
|
|
12
|
+
|
|
13
|
+
export function Table(options: ModelOptions) {
|
|
14
|
+
return function <T extends { new (...args: any[]): {} }>(target: T) {
|
|
15
|
+
const types = getTypesData(target);
|
|
16
|
+
|
|
17
|
+
Object.entries(types).forEach(([key, type]) => {
|
|
18
|
+
if (!['foreignkey', 'belongsto'].includes((type as any).__name)) {
|
|
19
|
+
addAttribute(target.prototype, key, (type as any).toSequelize());
|
|
20
|
+
} else if ((type as any).__name === 'foreignkey') {
|
|
21
|
+
addForeignKey(target.prototype, (type as any).toSequelize(), key);
|
|
22
|
+
} else if ((type as any).__name === 'belongsto') {
|
|
23
|
+
const { associatedClassGetter, optionsOrForeignKey } = (type as any).toSequelize();
|
|
24
|
+
const options: BelongsToOptions = getPreparedAssociationOptions(optionsOrForeignKey);
|
|
25
|
+
if (!options.as) options.as = key;
|
|
26
|
+
addAssociation(target.prototype, new BelongsToAssociation(associatedClassGetter, options));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
addOptions(target.prototype, {
|
|
31
|
+
createdAt: 'created_at',
|
|
32
|
+
timestamps: true,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
addOptions(target.prototype, {
|
|
36
|
+
updatedAt: 'updated_at',
|
|
37
|
+
timestamps: true,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
setModelName(target.prototype, options.modelName || target.name);
|
|
41
|
+
addOptions(target.prototype, options);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { BlobSize, DataTypes, TextLength } from 'sequelize';
|
|
2
|
+
import isClass from 'src/utils/isClass';
|
|
3
|
+
import { ExtendableDto } from '../dto';
|
|
4
|
+
|
|
5
|
+
const data: { [key: string]: any } = {};
|
|
6
|
+
|
|
7
|
+
export const getTypesData = (target: any) => {
|
|
8
|
+
const values = data[target?.name || target?.constructor?.name];
|
|
9
|
+
if (!values) return {};
|
|
10
|
+
return values;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const saveNewTypesData = (attributes: any, target: any) => {
|
|
14
|
+
data[target.constructor.name] = attributes;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const saveTypesData = (target: any, propertyName: any, value: any) => {
|
|
18
|
+
const types = getTypesData(target);
|
|
19
|
+
|
|
20
|
+
types[propertyName] = value;
|
|
21
|
+
|
|
22
|
+
saveNewTypesData(types, target);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type TypeIsData = {
|
|
26
|
+
__name: string;
|
|
27
|
+
toSwagger?: (...args: any[]) => any;
|
|
28
|
+
toSequelize?: (...args: any[]) => any;
|
|
29
|
+
fixValue?: (o: any) => any;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const typeGenerator =
|
|
33
|
+
(data: (...args: any[]) => TypeIsData) =>
|
|
34
|
+
(...options: any) => {
|
|
35
|
+
return (target?: any, propertyName?: string, propertyDescriptor?: PropertyDescriptor): void & TypeIsData => {
|
|
36
|
+
if (target !== undefined) {
|
|
37
|
+
const type = data(...options);
|
|
38
|
+
|
|
39
|
+
saveTypesData(target, propertyName, type);
|
|
40
|
+
|
|
41
|
+
if (propertyDescriptor) {
|
|
42
|
+
propertyDescriptor.value = type;
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
return data(...options) as any;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const TypeIs = {
|
|
51
|
+
INT: typeGenerator((options?: { decimals?: number; precision?: number; scale?: number; comment?: string }) => ({
|
|
52
|
+
__name: 'int',
|
|
53
|
+
toSwagger: () => ({
|
|
54
|
+
type: 'integer',
|
|
55
|
+
format: 'int32',
|
|
56
|
+
description: options?.comment,
|
|
57
|
+
}),
|
|
58
|
+
toSequelize: () => ({ type: DataTypes.INTEGER(options), comment: options?.comment }),
|
|
59
|
+
fixValue: (o: any) => {
|
|
60
|
+
if (o === undefined || o === null) return o;
|
|
61
|
+
return parseInt(String(o), 10);
|
|
62
|
+
},
|
|
63
|
+
})),
|
|
64
|
+
LONG: typeGenerator((options?: { decimals?: number; precision?: number; scale?: number; comment?: string }) => ({
|
|
65
|
+
__name: 'long',
|
|
66
|
+
toSwagger: () => ({
|
|
67
|
+
type: 'integer',
|
|
68
|
+
format: 'int64',
|
|
69
|
+
description: options?.comment,
|
|
70
|
+
}),
|
|
71
|
+
toSequelize: () => ({ type: DataTypes.INTEGER(options), comment: options?.comment }),
|
|
72
|
+
fixValue: (o: any) => {
|
|
73
|
+
if (o === undefined || o === null) return o;
|
|
74
|
+
return parseInt(String(o), 10);
|
|
75
|
+
},
|
|
76
|
+
})),
|
|
77
|
+
FLOAT: typeGenerator((options: { length?: number; decimals?: number; comment?: string }) => ({
|
|
78
|
+
__name: 'float',
|
|
79
|
+
toSwagger: () => ({
|
|
80
|
+
type: 'integer',
|
|
81
|
+
format: 'float',
|
|
82
|
+
description: options?.comment,
|
|
83
|
+
}),
|
|
84
|
+
toSequelize: () => ({ type: DataTypes.FLOAT(options?.length, options?.decimals), comment: options?.comment }),
|
|
85
|
+
fixValue: (o: any) => {
|
|
86
|
+
if (o === undefined || o === null) return o;
|
|
87
|
+
return parseFloat(String(o));
|
|
88
|
+
},
|
|
89
|
+
})),
|
|
90
|
+
DOUBLE: typeGenerator((options: { length?: number; decimals?: number; comment?: string }) => ({
|
|
91
|
+
__name: 'double',
|
|
92
|
+
toSwagger: () => ({
|
|
93
|
+
type: 'number',
|
|
94
|
+
format: 'double',
|
|
95
|
+
description: options?.comment,
|
|
96
|
+
}),
|
|
97
|
+
toSequelize: () => ({ type: DataTypes.DOUBLE(options?.length, options?.decimals), comment: options?.comment }),
|
|
98
|
+
fixValue: (o: any) => {
|
|
99
|
+
if (o === undefined || o === null) return o;
|
|
100
|
+
return parseFloat(String(o));
|
|
101
|
+
},
|
|
102
|
+
})),
|
|
103
|
+
STRING: typeGenerator((options: { length?: number; binary?: boolean; comment?: string }) => ({
|
|
104
|
+
__name: 'string',
|
|
105
|
+
toSwagger: () => ({
|
|
106
|
+
type: 'string',
|
|
107
|
+
description: options?.comment,
|
|
108
|
+
}),
|
|
109
|
+
toSequelize: () => ({ type: DataTypes.STRING(options?.length, options?.binary), comment: options?.comment }),
|
|
110
|
+
fixValue: (o: any) => {
|
|
111
|
+
if (o === undefined || o === null) return o;
|
|
112
|
+
return String(o);
|
|
113
|
+
},
|
|
114
|
+
})),
|
|
115
|
+
TEXT: typeGenerator((options: { length?: TextLength; comment?: string }) => ({
|
|
116
|
+
__name: 'text',
|
|
117
|
+
toSwagger: () => ({
|
|
118
|
+
type: 'string',
|
|
119
|
+
description: options?.comment,
|
|
120
|
+
}),
|
|
121
|
+
toSequelize: () => ({ type: DataTypes.TEXT({ length: options?.length }), comment: options?.comment }),
|
|
122
|
+
fixValue: (o: any) => {
|
|
123
|
+
if (o === undefined || o === null) return o;
|
|
124
|
+
return String(o);
|
|
125
|
+
},
|
|
126
|
+
})),
|
|
127
|
+
PASSWORD: typeGenerator((options: { comment?: string }) => ({
|
|
128
|
+
__name: 'password',
|
|
129
|
+
toSwagger: () => ({
|
|
130
|
+
type: 'string',
|
|
131
|
+
format: 'password',
|
|
132
|
+
description: options?.comment,
|
|
133
|
+
}),
|
|
134
|
+
toSequelize: () => ({ type: DataTypes.STRING(512), comment: options?.comment }),
|
|
135
|
+
})),
|
|
136
|
+
ENUM: typeGenerator((options: { values: string[]; comment?: string }) => ({
|
|
137
|
+
__name: 'enum',
|
|
138
|
+
toSwagger: () => ({
|
|
139
|
+
type: 'string',
|
|
140
|
+
enum: options?.values,
|
|
141
|
+
description: options?.values?.[0],
|
|
142
|
+
}),
|
|
143
|
+
toSequelize: () => ({ type: DataTypes.ENUM({ values: options?.values }), comment: options?.comment }),
|
|
144
|
+
fixValue: (o: any) => {
|
|
145
|
+
if (o === undefined || o === null) return o;
|
|
146
|
+
return options?.values?.includes?.(String(o)) ? String(o) : undefined;
|
|
147
|
+
},
|
|
148
|
+
})),
|
|
149
|
+
JSON: typeGenerator((options: { comment?: string }) => ({
|
|
150
|
+
__name: 'json',
|
|
151
|
+
toSwagger: () => ({
|
|
152
|
+
type: 'object',
|
|
153
|
+
description: options?.comment,
|
|
154
|
+
}),
|
|
155
|
+
toSequelize: () => ({ type: DataTypes.JSON, comment: options?.comment }),
|
|
156
|
+
})),
|
|
157
|
+
BASE64: typeGenerator((options: { length?: BlobSize; comment?: string }) => ({
|
|
158
|
+
__name: 'base64',
|
|
159
|
+
toSwagger: () => ({
|
|
160
|
+
type: 'string',
|
|
161
|
+
format: 'byte',
|
|
162
|
+
description: options?.comment,
|
|
163
|
+
}),
|
|
164
|
+
toSequelize: () => ({ type: DataTypes.BLOB(options?.length), comment: options?.comment }),
|
|
165
|
+
})),
|
|
166
|
+
BINARY: typeGenerator((options: { length?: BlobSize; comment?: string }) => ({
|
|
167
|
+
__name: 'binary',
|
|
168
|
+
toSwagger: () => ({
|
|
169
|
+
type: 'string',
|
|
170
|
+
format: 'binary',
|
|
171
|
+
description: options?.comment,
|
|
172
|
+
}),
|
|
173
|
+
toSequelize: () => ({ type: DataTypes.BLOB(options?.length), comment: options?.comment }),
|
|
174
|
+
})),
|
|
175
|
+
BOOLEAN: typeGenerator((options: { comment?: string }) => ({
|
|
176
|
+
__name: 'boolean',
|
|
177
|
+
toSwagger: () => ({
|
|
178
|
+
type: 'boolean',
|
|
179
|
+
}),
|
|
180
|
+
toSequelize: () => ({ type: DataTypes.BOOLEAN, comment: options?.comment }),
|
|
181
|
+
fixValue: (o: any) => {
|
|
182
|
+
if (o === undefined || o === null) return o;
|
|
183
|
+
return String(o) === 'true' ? true : String(o) === 'false' ? false : !!o;
|
|
184
|
+
},
|
|
185
|
+
})),
|
|
186
|
+
DATEONLY: typeGenerator((options: { comment?: string }) => ({
|
|
187
|
+
__name: 'date',
|
|
188
|
+
toSwagger: () => ({
|
|
189
|
+
type: 'string',
|
|
190
|
+
format: 'date',
|
|
191
|
+
description: options?.comment,
|
|
192
|
+
}),
|
|
193
|
+
toSequelize: () => DataTypes.DATEONLY(),
|
|
194
|
+
})),
|
|
195
|
+
DATETIME: typeGenerator((options: { comment?: string }) => ({
|
|
196
|
+
__name: 'datetime',
|
|
197
|
+
toSwagger: () => ({
|
|
198
|
+
type: 'string',
|
|
199
|
+
format: 'date-time',
|
|
200
|
+
description: options?.comment,
|
|
201
|
+
}),
|
|
202
|
+
toSequelize: () => DataTypes.DATE,
|
|
203
|
+
})),
|
|
204
|
+
FOREIGNKEY: typeGenerator((table: any) => ({
|
|
205
|
+
__name: 'foreignkey',
|
|
206
|
+
toSequelize: () => table,
|
|
207
|
+
})),
|
|
208
|
+
BELONGSTO: typeGenerator((associatedClassGetter: any, optionsOrForeignKey: any) => ({
|
|
209
|
+
__name: 'belongsto',
|
|
210
|
+
toSequelize: () => ({
|
|
211
|
+
associatedClassGetter,
|
|
212
|
+
optionsOrForeignKey,
|
|
213
|
+
}),
|
|
214
|
+
})),
|
|
215
|
+
DTO: typeGenerator((options: { dto: any; comment?: string }) => ({
|
|
216
|
+
__name: 'dto',
|
|
217
|
+
toSwagger: () => {
|
|
218
|
+
const result = new (options?.dto)()?.swagger();
|
|
219
|
+
return { ...result, comment: options?.comment };
|
|
220
|
+
},
|
|
221
|
+
})),
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// export const TypeArray = (options: { dto?: typeof ExtendableDto; type?: TypeIsData; comment?: string }) => {
|
|
225
|
+
// return {
|
|
226
|
+
// __name: 'array',
|
|
227
|
+
// toSwagger: () => ({
|
|
228
|
+
// type: 'array',
|
|
229
|
+
// items: options?.dto ? new options.dto()?.swagger() : options?.type ? options?.type?.toSwagger?.() : null,
|
|
230
|
+
// description: options?.comment,
|
|
231
|
+
// }),
|
|
232
|
+
// };
|
|
233
|
+
// };
|
|
234
|
+
|
|
235
|
+
// export const TypeArray = (options: { dto?: typeof ExtendableDto; type?: () => TypeIsData; comment?: string }) => {
|
|
236
|
+
// return class {
|
|
237
|
+
// public swagger = () => {
|
|
238
|
+
// return {
|
|
239
|
+
// type: 'array',
|
|
240
|
+
// items: options?.dto ? new options.dto()?.swagger() : options?.type ? options?.type?.()?.toSwagger?.() : null,
|
|
241
|
+
// description: options?.comment,
|
|
242
|
+
// };
|
|
243
|
+
// };
|
|
244
|
+
// };
|
|
245
|
+
// };
|
|
246
|
+
|
|
247
|
+
export type DtoOrTypeIs = typeof ExtendableDto | (() => TypeIsData) | TypeArrayClass;
|
|
248
|
+
|
|
249
|
+
interface TypeArrayClass {
|
|
250
|
+
new (n: string): TypeArrayInterface;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export interface TypeArrayInterface {
|
|
254
|
+
swagger: () => {
|
|
255
|
+
type: string;
|
|
256
|
+
items: any;
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export const TypeArray = (value: DtoOrTypeIs) => {
|
|
261
|
+
return class TypeArrayClass implements TypeArrayInterface {
|
|
262
|
+
public swagger = () => {
|
|
263
|
+
const isDto = isClass(value);
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
type: 'array',
|
|
267
|
+
items: isDto
|
|
268
|
+
? new (value as typeof ExtendableDto)()?.swagger()
|
|
269
|
+
: (value as () => TypeIsData)?.()?.toSwagger?.(),
|
|
270
|
+
// description: options?.comment,
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const getUserIdInQuery = (user?: any) => `"${user?.id || ''}"`;
|
|
1
|
+
export const getUserIdInQuery = (user?: any) => `"${user?.id || user?._id || ''}"`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default (v: any) => v?.prototype?.constructor !== undefined;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getUserIdInQuery.d.ts","sourceRoot":"","sources":["../../src/util/getUserIdInQuery.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,UAAW,GAAG,WAA0B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getUserIdInQuery.js","sourceRoot":"","sources":["../../src/util/getUserIdInQuery.ts"],"names":[],"mappings":";;;AAAO,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAE,EAAE,CAAC,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,EAAE,KAAI,EAAE,GAAG,CAAC;AAAzD,QAAA,gBAAgB,oBAAyC"}
|