@asapjs/sequelize 0.0.3 → 0.0.5
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/repository/index.d.ts +23 -0
- package/dist/repository/index.d.ts.map +1 -0
- package/dist/repository/index.js +52 -0
- package/dist/repository/index.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/repository/index.ts +49 -0
package/dist/index.d.ts
CHANGED
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,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSequelize = exports.initSequelizeModule = exports.DtoQuery = exports.DtoType = exports.Dto = exports.SequelizeDto = void 0;
|
|
6
|
+
exports.Repository = exports.getSequelize = exports.initSequelizeModule = exports.DtoQuery = exports.DtoType = exports.Dto = exports.SequelizeDto = void 0;
|
|
4
7
|
var dto_1 = require("./dto");
|
|
5
8
|
Object.defineProperty(exports, "SequelizeDto", { enumerable: true, get: function () { return dto_1.SequelizeDto; } });
|
|
6
9
|
Object.defineProperty(exports, "Dto", { enumerable: true, get: function () { return dto_1.Dto; } });
|
|
@@ -9,4 +12,6 @@ Object.defineProperty(exports, "DtoQuery", { enumerable: true, get: function ()
|
|
|
9
12
|
var sequelize_1 = require("./sequelize");
|
|
10
13
|
Object.defineProperty(exports, "initSequelizeModule", { enumerable: true, get: function () { return sequelize_1.initSequelizeModule; } });
|
|
11
14
|
Object.defineProperty(exports, "getSequelize", { enumerable: true, get: function () { return sequelize_1.getSequelize; } });
|
|
15
|
+
var repository_1 = require("./repository");
|
|
16
|
+
Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return __importDefault(repository_1).default; } });
|
|
12
17
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,6BAA6D;AAApD,mGAAA,YAAY,OAAA;AAAE,0FAAA,GAAG,OAAA;AAAE,8FAAA,OAAO,OAAA;AAAE,+FAAA,QAAQ,OAAA;AAC7C,yCAAgE;AAAvD,gHAAA,mBAAmB,OAAA;AAAE,yGAAA,YAAY,OAAA;AAC1C,2CAAqD;AAA5C,yHAAA,OAAO,OAAc"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Model, ModelCtor } from 'sequelize-typescript';
|
|
2
|
+
import { FindOptions } from 'sequelize';
|
|
3
|
+
import { SequelizeDto } from '../dto';
|
|
4
|
+
interface IArgs<T extends Model> extends FindOptions<T> {
|
|
5
|
+
exportTo: typeof SequelizeDto;
|
|
6
|
+
user?: any;
|
|
7
|
+
withDto?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare type FindAllResponseWithDto<T> = [T[], SequelizeDto];
|
|
10
|
+
declare type FindAllResponse<T, WithDto = {}> = WithDto extends true ? FindAllResponseWithDto<T> : T[];
|
|
11
|
+
declare type FindOneResponseWithDto<T> = [T | null, SequelizeDto];
|
|
12
|
+
declare type FindOneResponse<T, WithDto = {}> = WithDto extends true ? FindOneResponseWithDto<T> : T | null;
|
|
13
|
+
export default class Repository {
|
|
14
|
+
private getOptionsWithArgs;
|
|
15
|
+
private findAll;
|
|
16
|
+
private findOne;
|
|
17
|
+
repository: {
|
|
18
|
+
findAll: <T extends Model<any, any>, WithDto = {}>(model: ModelCtor<T>, args: IArgs<T>) => Promise<FindAllResponse<T, WithDto>>;
|
|
19
|
+
findOne: <T_1 extends Model<any, any>, WithDto_1 = {}>(model: ModelCtor<T_1>, args: IArgs<T_1>) => Promise<FindOneResponse<T_1, WithDto_1>>;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,UAAU,KAAK,CAAC,CAAC,SAAS,KAAK,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAC;IACrD,QAAQ,EAAE,OAAO,YAAY,CAAC;IAC9B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,aAAK,sBAAsB,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;AACrD,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,YAAY,CAAC,CAAC;AAC1D,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,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
class Repository {
|
|
24
|
+
constructor() {
|
|
25
|
+
this.getOptionsWithArgs = (args) => {
|
|
26
|
+
const { exportTo: Dto, user } = args, options = __rest(args, ["exportTo", "user"]);
|
|
27
|
+
const exportDto = new Dto();
|
|
28
|
+
const _a = exportDto.middleware(undefined, user), { model: _ } = _a, queryOptions = __rest(_a, ["model"]);
|
|
29
|
+
return { query: Object.assign(Object.assign({}, queryOptions), options), exportDto };
|
|
30
|
+
};
|
|
31
|
+
this.findAll = (model, args) => __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const { query, exportDto } = this.getOptionsWithArgs(args);
|
|
33
|
+
const raws = yield model.findAll(query);
|
|
34
|
+
if (args.withDto)
|
|
35
|
+
return [raws, exportDto];
|
|
36
|
+
return raws;
|
|
37
|
+
});
|
|
38
|
+
this.findOne = (model, args) => __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const { query, exportDto } = this.getOptionsWithArgs(args);
|
|
40
|
+
const raw = yield model.findOne(query);
|
|
41
|
+
if (args.withDto)
|
|
42
|
+
return [raw, exportDto];
|
|
43
|
+
return raw;
|
|
44
|
+
});
|
|
45
|
+
this.repository = {
|
|
46
|
+
findAll: this.findAll,
|
|
47
|
+
findOne: this.findOne,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.default = Repository;
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/repository/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAqB,UAAU;IAA/B;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I,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;CAAA;AAhCD,6BAgCC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Model, ModelCtor } from 'sequelize-typescript';
|
|
2
|
+
import { FindOptions } from 'sequelize';
|
|
3
|
+
|
|
4
|
+
import { SequelizeDto } from '../dto';
|
|
5
|
+
|
|
6
|
+
interface IArgs<T extends Model> extends FindOptions<T> {
|
|
7
|
+
exportTo: typeof SequelizeDto;
|
|
8
|
+
user?: any;
|
|
9
|
+
withDto?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type FindAllResponseWithDto<T> = [T[], SequelizeDto];
|
|
13
|
+
type FindAllResponse<T, WithDto = {}> = WithDto extends true ? FindAllResponseWithDto<T> : T[];
|
|
14
|
+
|
|
15
|
+
type FindOneResponseWithDto<T> = [T | null, SequelizeDto];
|
|
16
|
+
type FindOneResponse<T, WithDto = {}> = WithDto extends true ? FindOneResponseWithDto<T> : T | null;
|
|
17
|
+
export default class Repository {
|
|
18
|
+
private getOptionsWithArgs = <T extends Model>(args: IArgs<T>) => {
|
|
19
|
+
const { exportTo: Dto, user, ...options } = args;
|
|
20
|
+
const exportDto = new Dto();
|
|
21
|
+
const { model: _, ...queryOptions } = exportDto.middleware(undefined, user);
|
|
22
|
+
return { query: { ...queryOptions, ...options }, exportDto };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
private findAll = async <T extends Model, WithDto = {}>(
|
|
26
|
+
model: ModelCtor<T>,
|
|
27
|
+
args: IArgs<T>,
|
|
28
|
+
): Promise<FindAllResponse<T, WithDto>> => {
|
|
29
|
+
const { query, exportDto } = this.getOptionsWithArgs<T>(args);
|
|
30
|
+
const raws = await model.findAll(query);
|
|
31
|
+
if (args.withDto) return [raws, exportDto] as any;
|
|
32
|
+
return raws as any;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
private findOne = async <T extends Model, WithDto = {}>(
|
|
36
|
+
model: ModelCtor<T>,
|
|
37
|
+
args: IArgs<T>,
|
|
38
|
+
): Promise<FindOneResponse<T, WithDto>> => {
|
|
39
|
+
const { query, exportDto } = this.getOptionsWithArgs<T>(args);
|
|
40
|
+
const raw = await model.findOne(query);
|
|
41
|
+
if (args.withDto) return [raw, exportDto] as any;
|
|
42
|
+
return raw as any;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
public repository = {
|
|
46
|
+
findAll: this.findAll,
|
|
47
|
+
findOne: this.findOne,
|
|
48
|
+
};
|
|
49
|
+
}
|