@domain.js/main 0.3.4 → 0.3.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.
@@ -27,11 +27,17 @@ export declare function Main(cnf: Cnf, deps: Deps, utils: ReturnType<typeof Util
27
27
  modify: <T extends ModelBase<any, any>>(Model: ModelStatic<T>, model: T, params: Record<string, any>, isAdmin?: boolean, _cols?: string[] | undefined) => Promise<T>;
28
28
  add: <T_1 extends ModelBase<any, any>>(Model: ModelStatic<T_1>, params: Record<string, any>, isAdmin: boolean | undefined, _cols: string[] | undefined, { creatorId, clientIp }: CreatorAndClientIp) => Promise<T_1>;
29
29
  remove: (model: Sequelize.Model, deletorId: UserId) => Promise<void | Sequelize.Model<any, any>>;
30
- list: <T_2 extends ModelBase<any, any>>(Model: ModelStatic<T_2>, params: Record<string, any>, allowAttrs?: string[] | undefined, toJSON?: boolean | undefined) => Promise<{
31
- count: number;
32
- rows: T_2[];
33
- }>;
34
- stats: <T_3 extends ModelBase<any, any>>(Model: ModelStatic<T_3>, params: Record<string, any>, where?: any, conf?: {
30
+ list: {
31
+ <T_2 extends ModelBase<any, any>, J = ReturnType<T_2["toJSON"]>>(Model: ModelStatic<T_2>, params: Record<string, any>, allowAttrs?: string[] | undefined, toJSON?: false | undefined): Promise<{
32
+ rows: T_2[];
33
+ count: number;
34
+ }>;
35
+ <T_3 extends ModelBase<any, any>, J_1 = ReturnType<T_3["toJSON"]>>(Model: ModelStatic<T_3>, params: Record<string, any>, allowAttrs?: string[] | undefined, toJSON?: true | undefined): Promise<{
36
+ rows: J_1[];
37
+ count: number;
38
+ }>;
39
+ };
40
+ stats: <T_4 extends ModelBase<any, any>>(Model: ModelStatic<T_4>, params: Record<string, any>, where?: any, conf?: {
35
41
  dimensions?: Record<string, string> | undefined;
36
42
  metrics: Record<string, string>;
37
43
  pagination?: {
@@ -99,15 +99,7 @@ function Main(cnf, deps, utils) {
99
99
  };
100
100
  // count条件所需属性
101
101
  const COUNT_OPT = Object.freeze(["where", "include"]);
102
- /**
103
- * Restful list (R of CRUD) for list resource
104
- * @param Model Model definition of resources
105
- * @param params parameters for updating
106
- * @param allowAttrs Allow columns to be returned
107
- * @param toJSON Whether to directly return JSON formatted objects
108
- * @returns findAll resource result, object propoties has count, rows
109
- */
110
- const list = async (Model, params, allowAttrs, toJSON) => {
102
+ async function list(Model, params, allowAttrs, toJSON) {
111
103
  const opt = findAllOpts(Model, params);
112
104
  const { _ignoreTotal } = params;
113
105
  // 提高查询速度
@@ -117,13 +109,10 @@ function Main(cnf, deps, utils) {
117
109
  if (Array.isArray(allowAttrs) && allowAttrs.length)
118
110
  opt.attributes = allowAttrs;
119
111
  const rows = await Model.findAll(opt);
120
- if (toJSON) {
121
- for (let i = 0; i < rows.length; i += 1) {
122
- rows[i] = rows[i].toJSON();
123
- }
124
- }
125
- return { count, rows };
126
- };
112
+ if (!toJSON)
113
+ return { rows, count };
114
+ return { count, rows: rows.map((x) => x.toJSON()) };
115
+ }
127
116
  return { modify, add, remove, list, stats: (0, stats_1.Stats)(cnf, deps, utils) };
128
117
  }
129
118
  exports.Main = Main;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {