@puca/puca-core 13.2.1 → 13.3.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.
- package/dist/core/services/auth.service.js +3 -1
- package/dist/core/services/auth.service.js.map +1 -1
- package/dist/core/services/crud-base-testable.service.d.ts +6 -0
- package/dist/core/services/crud-base-testable.service.js +12 -6
- package/dist/core/services/crud-base-testable.service.js.map +1 -1
- package/dist/core/services/crud-base.controller.js.map +1 -1
- package/dist/core/services/crud-front-base.service.js.map +1 -1
- package/dist/core/services/domain-life-cycle.service.d.ts +4 -1
- package/dist/core/services/domain-life-cycle.service.js +18 -1
- package/dist/core/services/domain-life-cycle.service.js.map +1 -1
- package/dist/core/services/eval.service.js.map +1 -1
- package/dist/core/services/index.d.ts +5 -1
- package/dist/core/services/index.js +8 -4
- package/dist/core/services/index.js.map +1 -1
- package/dist/core/services/install.service.js.map +1 -1
- package/dist/core/services/kpi.service.d.ts +46 -0
- package/dist/core/services/kpi.service.js +60 -0
- package/dist/core/services/kpi.service.js.map +1 -0
- package/dist/core/services/llm/llm.service.d.ts +5 -1
- package/dist/core/services/llm/llm.service.js +19 -2
- package/dist/core/services/llm/llm.service.js.map +1 -1
- package/dist/core/services/llm/natural-language-to-fuql.service.d.ts +28 -0
- package/dist/core/services/llm/natural-language-to-fuql.service.js +209 -0
- package/dist/core/services/llm/natural-language-to-fuql.service.js.map +1 -0
- package/dist/core/services/migration/migration.service.js.map +1 -1
- package/dist/core/services/mq/mq.service.d.ts +1 -0
- package/dist/core/services/mq/mq.service.js +47 -1
- package/dist/core/services/mq/mq.service.js.map +1 -1
- package/dist/core/services/request-cache.service.d.ts +6 -0
- package/dist/core/services/request-cache.service.js +31 -0
- package/dist/core/services/request-cache.service.js.map +1 -0
- package/dist/core/services/server-life-cycle.service.d.ts +5 -1
- package/dist/core/services/server-life-cycle.service.js +9 -1
- package/dist/core/services/server-life-cycle.service.js.map +1 -1
- package/dist/core/services/source/source.service.js.map +1 -1
- package/dist/core/services/user-config.service.js.map +1 -1
- package/dist/models/user.d.ts +2 -0
- package/dist/orm/services/managers/database-manager.service.d.ts +1 -0
- package/dist/orm/services/managers/database-manager.service.js +15 -4
- package/dist/orm/services/managers/database-manager.service.js.map +1 -1
- package/dist/orm/services/repository-factory.d.ts +1 -1
- package/dist/orm/services/repository-factory.js +2 -2
- package/dist/orm/services/repository-factory.js.map +1 -1
- package/dist/orm/services/repository.d.ts +19 -17
- package/dist/orm/services/repository.js +160 -141
- package/dist/orm/services/repository.js.map +1 -1
- package/dist/orm/services/secondary-database/secondary-database.service.d.ts +1 -0
- package/dist/orm/services/secondary-database/secondary-database.service.js +15 -0
- package/dist/orm/services/secondary-database/secondary-database.service.js.map +1 -1
- package/dist/orm/services/sql/sql-layer.service.js +5 -5
- package/dist/orm/services/sql/sql-layer.service.js.map +1 -1
- package/dist/orm/services/sql/sql-security-layer.service.js +1 -1
- package/dist/orm/services/sql/sql-security-layer.service.js.map +1 -1
- package/dist/plugins/final-user-query-language/final-user-query-language.d.ts +6 -5
- package/dist/plugins/final-user-query-language/final-user-query-language.js +9 -1
- package/dist/plugins/final-user-query-language/final-user-query-language.js.map +1 -1
- package/dist/plugins/multi-tenant/multi-tentant.adapter.d.ts +1 -0
- package/dist/plugins/multi-tenant/multi-tentant.adapter.js +3 -0
- package/dist/plugins/multi-tenant/multi-tentant.adapter.js.map +1 -1
- package/dist/plugins/nestjs/puca-auth.decorators.js +2 -0
- package/dist/plugins/nestjs/puca-auth.decorators.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/fuql-grammar.js +7 -11
- package/fuql-grammar.ne +8 -10
- package/package.json +1 -1
|
@@ -11,17 +11,28 @@ class Database {
|
|
|
11
11
|
this.logger = new logger_1.Logger(this.domain, 'Database');
|
|
12
12
|
this.pucaOrmClient = new puca_orm_client_service_1.PucaOrmClient(domain, config);
|
|
13
13
|
}
|
|
14
|
-
async
|
|
14
|
+
async isAlive(timeoutMs = 5000) {
|
|
15
15
|
try {
|
|
16
|
-
|
|
16
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
17
|
+
setTimeout(() => reject(new Error('Database connection timeout')), timeoutMs);
|
|
18
|
+
});
|
|
19
|
+
const execPromise = this.exec({
|
|
17
20
|
sql: 'select now()',
|
|
18
21
|
commandName: null,
|
|
19
22
|
}, {
|
|
20
23
|
transaction: null
|
|
21
24
|
});
|
|
25
|
+
await Promise.race([execPromise, timeoutPromise]);
|
|
26
|
+
return true;
|
|
22
27
|
}
|
|
23
28
|
catch (e) {
|
|
24
29
|
this.logger.error(e);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async connect() {
|
|
34
|
+
const result = await this.isAlive();
|
|
35
|
+
if (!result) {
|
|
25
36
|
throw new Error('Fail to connect on database');
|
|
26
37
|
}
|
|
27
38
|
}
|
|
@@ -150,8 +161,8 @@ class DatabaseManagerService {
|
|
|
150
161
|
loadBalancerPolicy: 'none'
|
|
151
162
|
});
|
|
152
163
|
try {
|
|
153
|
-
await database.
|
|
154
|
-
await transactionalDatabase.
|
|
164
|
+
await database.isAlive();
|
|
165
|
+
await transactionalDatabase.isAlive();
|
|
155
166
|
this.database = database;
|
|
156
167
|
this.transactionalDabase = transactionalDatabase;
|
|
157
168
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database-manager.service.js","sourceRoot":"","sources":["../../../../src/orm/services/managers/database-manager.service.ts"],"names":[],"mappings":";;;AAAA,4BAA4B;AAG5B,0DAAuD;AACvD,uEAAuE;AAKvE,MAAM,kBAAkB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAI3D,MAAa,QAAQ;IAInB,YACmB,MAAc,EAC/B,MAAwB;QADP,WAAM,GAAN,MAAM,CAAQ;QAJhB,WAAM,GAAG,IAAI,eAAM,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAO5D,IAAI,CAAC,aAAa,GAAG,IAAI,uCAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxD,CAAC;IAED,KAAK,CAAC,OAAO;
|
|
1
|
+
{"version":3,"file":"database-manager.service.js","sourceRoot":"","sources":["../../../../src/orm/services/managers/database-manager.service.ts"],"names":[],"mappings":";;;AAAA,4BAA4B;AAG5B,0DAAuD;AACvD,uEAAuE;AAKvE,MAAM,kBAAkB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAI3D,MAAa,QAAQ;IAInB,YACmB,MAAc,EAC/B,MAAwB;QADP,WAAM,GAAN,MAAM,CAAQ;QAJhB,WAAM,GAAG,IAAI,eAAM,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAO5D,IAAI,CAAC,aAAa,GAAG,IAAI,uCAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,YAAoB,IAAI;QACpC,IAAI;YACF,MAAM,cAAc,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;gBAC/C,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;YAChF,CAAC,CAAC,CAAC;YAEH,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC;gBAC5B,GAAG,EAAE,cAAc;gBACnB,WAAW,EAAE,IAAI;aAClB,EAAE;gBACD,WAAW,EAAE,IAAI;aAClB,CAAC,CAAC;YAEH,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC;YAClD,OAAO,IAAI,CAAA;SACZ;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YACpB,OAAO,KAAK,CAAA;SACb;IACH,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,MAAM,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AAE,MAAM,CAAC,eAAe,IAAI,SAAS;YAC9C,kBAAkB,EAAE,aAAa;SAClC,CAAC,CAAC;QACH,MAAM,qBAAqB,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE;YACtD,kBAAkB,EAAE,OAAO;YAC3B,GAAG;YACH,SAAS,EAAE,MAAM,CAAC,eAAe,IAAI,SAAS;YAC9C,kBAAkB,EAAE,MAAM;SAC3B,CAAC,CAAC;QACH,IAAI;YACF,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;YACzB,MAAM,qBAAqB,CAAC,OAAO,EAAE,CAAA;YAErC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACzB,IAAI,CAAC,mBAAmB,GAAG,qBAAqB,CAAC;SAClD;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACrB,MAAM,CAAC,CAAA;SACR;IACH,CAAC;IAED,GAAG;QACD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAA;YAC1C,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;SACzC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,wBAAwB;QACtB,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE;YAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAA;YAC1C,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;SACzC;QACD,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;CACF;AA3DD,wDA2DC"}
|
|
@@ -18,7 +18,7 @@ export declare class RepositoryFactory {
|
|
|
18
18
|
private readonly uuidService;
|
|
19
19
|
private readonly cacheInstances;
|
|
20
20
|
constructor(domain: string, secondaryDataBase: SecondaryDatabase, databaseManagerService: DatabaseManagerService, transactionFactory: TransactionFactory, funcSqlService: () => SqlService, uuidService: UuidService);
|
|
21
|
-
getInstance<T>({ tableName, transaction: oTransaction }: {
|
|
21
|
+
getInstance<T>({ tableName, transaction: oTransaction, }: {
|
|
22
22
|
tableName: string;
|
|
23
23
|
transaction?: Transaction;
|
|
24
24
|
}): Repository<T>;
|
|
@@ -17,10 +17,10 @@ class RepositoryFactory {
|
|
|
17
17
|
v2: {}
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
getInstance({ tableName, transaction: oTransaction }) {
|
|
20
|
+
getInstance({ tableName, transaction: oTransaction, }) {
|
|
21
21
|
const transaction = oTransaction || this.transactionFactory.getPseudoTransaction();
|
|
22
22
|
const sqlExecutor = new sql_executor_1.SqlExecutor(this.domain, this.funcSqlService, transaction);
|
|
23
|
-
return new repository_1.Repository(
|
|
23
|
+
return new repository_1.Repository(transaction, sqlExecutor, this.secondaryDataBase, this.funcSqlService, this.uuidService, tableName, !oTransaction);
|
|
24
24
|
}
|
|
25
25
|
getCacheInstance({ tableName, version }) {
|
|
26
26
|
const versionKey = version ? 'v' + version : 'v2';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository-factory.js","sourceRoot":"","sources":["../../../src/orm/services/repository-factory.ts"],"names":[],"mappings":";;;AAEA,0EAAsE;AAEtE,6CAA0C;AAE1C,iDAA6C;AAM7C,MAAa,iBAAiB;IAS5B,YACmB,MAAc,EACd,iBAAoC,EACpC,sBAA8C,EAC9C,kBAAsC,EACtC,cAAgC,EAChC,WAAwB;QALxB,WAAM,GAAN,MAAM,CAAQ;QACd,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,2BAAsB,GAAtB,sBAAsB,CAAwB;QAC9C,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,mBAAc,GAAd,cAAc,CAAkB;QAChC,gBAAW,GAAX,WAAW,CAAa;QAd1B,mBAAc,GAG3B;YACA,EAAE,EAAE,EAAE;YACN,EAAE,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"repository-factory.js","sourceRoot":"","sources":["../../../src/orm/services/repository-factory.ts"],"names":[],"mappings":";;;AAEA,0EAAsE;AAEtE,6CAA0C;AAE1C,iDAA6C;AAM7C,MAAa,iBAAiB;IAS5B,YACmB,MAAc,EACd,iBAAoC,EACpC,sBAA8C,EAC9C,kBAAsC,EACtC,cAAgC,EAChC,WAAwB;QALxB,WAAM,GAAN,MAAM,CAAQ;QACd,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,2BAAsB,GAAtB,sBAAsB,CAAwB;QAC9C,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,mBAAc,GAAd,cAAc,CAAkB;QAChC,gBAAW,GAAX,WAAW,CAAa;QAd1B,mBAAc,GAG3B;YACA,EAAE,EAAE,EAAE;YACN,EAAE,EAAE,EAAE;SACP,CAAC;IASA,CAAC;IAEL,WAAW,CAAI,EACb,SAAS,EACT,WAAW,EAAE,YAAY,GAI1B;QACC,MAAM,WAAW,GAAG,YAAY,IAAI,IAAI,CAAC,kBAAkB,CAAC,oBAAoB,EAAE,CAAA;QAClF,MAAM,WAAW,GAAG,IAAI,0BAAW,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,CAAA;QAElF,OAAO,IAAI,uBAAU,CACnB,WAAW,EACX,WAAW,EACX,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,WAAW,EAChB,SAAS,EACT,CAAC,YAAY,CACd,CAAC;IACJ,CAAC;IAED,gBAAgB,CAAkC,EAChD,SAAS,EACT,OAAO,EAIR;QACC,MAAM,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAA;QAEjD,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,EAAE;YAC/C,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,kCAAe,CAC9D,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,EACjC,IAAI,CAAC,iBAAiB,EACtB,SAAS,EACT,EAAE,OAAO,EAAE,OAAO,IAAI,CAAC,EAAE,CAC1B,CAAC;SACH;QACD,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;IACD,KAAK,CAAC,QAAQ;QACZ,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,eAAe,EAAE,EAAE;YACpF,MAAM,eAAe,CAAC,QAAQ,EAAE,CAAA;QAClC,CAAC,CAAC,CAAC,CAAA;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,eAAe,EAAE,EAAE;YACpF,MAAM,eAAe,CAAC,QAAQ,EAAE,CAAA;QAClC,CAAC,CAAC,CAAC,CAAA;IACL,CAAC;CACF;AAnED,8CAmEC"}
|
|
@@ -37,6 +37,7 @@ export interface FindWhereArgs {
|
|
|
37
37
|
union?: Select[];
|
|
38
38
|
unionAll?: Select[];
|
|
39
39
|
disablePermissionSystem?: boolean;
|
|
40
|
+
requestCachePath?: string;
|
|
40
41
|
compress?: boolean;
|
|
41
42
|
}
|
|
42
43
|
export interface FindByInArgs {
|
|
@@ -55,6 +56,7 @@ export interface FindByInArgs {
|
|
|
55
56
|
union?: Select[];
|
|
56
57
|
unionAll?: Select[];
|
|
57
58
|
disablePermissionSystem?: boolean;
|
|
59
|
+
requestCachePath?: string;
|
|
58
60
|
}
|
|
59
61
|
export interface FindByPucaPidArgs {
|
|
60
62
|
pucaPid: string;
|
|
@@ -69,6 +71,7 @@ export interface FindByPucaPidArgs {
|
|
|
69
71
|
union?: Select[];
|
|
70
72
|
unionAll?: Select[];
|
|
71
73
|
disablePermissionSystem?: boolean;
|
|
74
|
+
requestCachePath?: string;
|
|
72
75
|
}
|
|
73
76
|
export interface FindOneByArgs {
|
|
74
77
|
key: string | string[];
|
|
@@ -85,6 +88,7 @@ export interface FindOneByArgs {
|
|
|
85
88
|
union?: Select[];
|
|
86
89
|
unionAll?: Select[];
|
|
87
90
|
disablePermissionSystem?: boolean;
|
|
91
|
+
requestCachePath?: string;
|
|
88
92
|
}
|
|
89
93
|
export interface FindByArgs {
|
|
90
94
|
key: SelectField | SelectField[];
|
|
@@ -106,6 +110,7 @@ export interface FindByArgs {
|
|
|
106
110
|
unionAll?: Select[];
|
|
107
111
|
disablePermissionSystem?: boolean;
|
|
108
112
|
args?: any;
|
|
113
|
+
requestCachePath?: string;
|
|
109
114
|
}
|
|
110
115
|
export interface FindOneWhereArgs {
|
|
111
116
|
fields: SelectField[];
|
|
@@ -122,6 +127,7 @@ export interface FindOneWhereArgs {
|
|
|
122
127
|
union?: Select[];
|
|
123
128
|
unionAll?: Select[];
|
|
124
129
|
disablePermissionSystem?: boolean;
|
|
130
|
+
requestCachePath?: string;
|
|
125
131
|
}
|
|
126
132
|
export interface CountByArgs {
|
|
127
133
|
key: string;
|
|
@@ -137,6 +143,7 @@ export interface CountByArgs {
|
|
|
137
143
|
union?: Select[];
|
|
138
144
|
unionAll?: Select[];
|
|
139
145
|
disablePermissionSystem?: boolean;
|
|
146
|
+
requestCachePath?: string;
|
|
140
147
|
}
|
|
141
148
|
export interface CountWhereArgs {
|
|
142
149
|
where?: Where;
|
|
@@ -152,6 +159,7 @@ export interface CountWhereArgs {
|
|
|
152
159
|
unionAll?: Select[];
|
|
153
160
|
disablePermissionSystem?: boolean;
|
|
154
161
|
compress?: boolean;
|
|
162
|
+
requestCachePath?: string;
|
|
155
163
|
}
|
|
156
164
|
export interface FindAllArgs {
|
|
157
165
|
fields: SelectField[];
|
|
@@ -166,14 +174,15 @@ export interface FindAllArgs {
|
|
|
166
174
|
with?: With[];
|
|
167
175
|
from?: From;
|
|
168
176
|
query?: Query[];
|
|
177
|
+
totalizeMode?: TotalizeMode;
|
|
169
178
|
union?: Select[];
|
|
170
179
|
unionAll?: Select[];
|
|
171
180
|
disablePermissionSystem?: boolean;
|
|
181
|
+
requestCachePath?: string;
|
|
172
182
|
}
|
|
173
183
|
export declare class Repository<T extends {
|
|
174
184
|
puca_pid?: string;
|
|
175
185
|
}> {
|
|
176
|
-
private readonly domain;
|
|
177
186
|
private readonly transaction;
|
|
178
187
|
private readonly sqlExecutor;
|
|
179
188
|
private readonly secondaryDataBase;
|
|
@@ -181,35 +190,28 @@ export declare class Repository<T extends {
|
|
|
181
190
|
private readonly uuidService;
|
|
182
191
|
private readonly table;
|
|
183
192
|
private readonly autoCommit;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
findByIn({ key, values, fields, orderBy, user, alias, totalizeMode, forUpdate, with: w, from, query, join, union, unionAll, disablePermissionSystem }: FindByInArgs): Promise<T[]>;
|
|
193
|
+
constructor(transaction: Transaction, sqlExecutor: SqlExecutor, secondaryDataBase: SecondaryDatabase, sqlServiceFunc: () => SqlService, uuidService: UuidService, table: string, autoCommit: boolean);
|
|
194
|
+
findByIn({ key, values, fields, orderBy, user, alias, totalizeMode, forUpdate, with: w, from, query, join, union, unionAll, disablePermissionSystem, requestCachePath }: FindByInArgs): Promise<T[]>;
|
|
187
195
|
private getAlias;
|
|
188
|
-
findByPucaPid({ pucaPid, fields, user, alias: oAlias, forUpdate, with: w, from, join, query, disablePermissionSystem }: FindByPucaPidArgs & {
|
|
196
|
+
findByPucaPid({ pucaPid, fields, user, alias: oAlias, forUpdate, with: w, from, join, query, disablePermissionSystem, requestCachePath }: FindByPucaPidArgs & {
|
|
189
197
|
disablePermissionSystem?: boolean;
|
|
190
198
|
}): Promise<T>;
|
|
191
199
|
findOneBy(args: FindOneByArgs & {
|
|
192
200
|
disablePermissionSystem?: boolean;
|
|
193
201
|
}): Promise<T>;
|
|
194
202
|
findOneWhere(args: FindOneWhereArgs): Promise<T>;
|
|
195
|
-
countBy({ key, value, user, groupBy, alias, with: w, from, query, union, unionAll, disablePermissionSystem, join }: CountByArgs): Promise<number>;
|
|
196
|
-
countWhere(
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
findWhere({ args, where, fields, join, page, pageSize, orderBy, totalizeMode, user, groupBy, alias: oAlias, forUpdate, with: w, from: oFrom, disablePermissionSystem, query, union, unionAll, compress }: FindWhereArgs & {
|
|
200
|
-
disablePermissionSystem?: boolean;
|
|
201
|
-
}): Promise<SelectResult<T>>;
|
|
202
|
-
findBy({ key: originalKey, value: originalValue, fields, page, pageSize, orderBy, groupBy, user, alias, totalizeMode, forUpdate, with: w, from, disablePermissionSystem, query, join, union, unionAll, args }: FindByArgs & {
|
|
203
|
+
countBy({ key, value, user, groupBy, alias, with: w, from, query, union, unionAll, disablePermissionSystem, join, requestCachePath }: CountByArgs): Promise<number>;
|
|
204
|
+
countWhere(findArgs: CountWhereArgs): Promise<number>;
|
|
205
|
+
findWhere(findArgs: FindWhereArgs): Promise<SelectResult<T>>;
|
|
206
|
+
findBy({ key: originalKey, value: originalValue, fields, page, pageSize, orderBy, groupBy, user, alias, totalizeMode, forUpdate, with: w, from, disablePermissionSystem, query, join, union, unionAll, args, requestCachePath }: FindByArgs & {
|
|
203
207
|
disablePermissionSystem?: boolean;
|
|
204
208
|
}): Promise<SelectResult<T>>;
|
|
205
209
|
countAll(args: {
|
|
206
210
|
user: User;
|
|
207
211
|
disablePermissionSystem?: boolean;
|
|
212
|
+
requestCachePath?: string;
|
|
208
213
|
}): Promise<number>;
|
|
209
|
-
findAll({ fields, page, pageSize, orderBy, groupBy, join, user, alias, forUpdate, with: w, from, query, disablePermissionSystem, union, unionAll, totalizeMode }: FindAllArgs
|
|
210
|
-
disablePermissionSystem?: boolean;
|
|
211
|
-
totalizeMode?: TotalizeMode;
|
|
212
|
-
}): Promise<SelectResult<T>>;
|
|
214
|
+
findAll({ fields, page, pageSize, orderBy, groupBy, join, user, alias, forUpdate, with: w, from, query, disablePermissionSystem, union, unionAll, totalizeMode, requestCachePath }: FindAllArgs): Promise<SelectResult<T>>;
|
|
213
215
|
private _insert;
|
|
214
216
|
private insert;
|
|
215
217
|
private upinsert;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Repository = exports.TotalizeMode = void 0;
|
|
4
4
|
const _ = require("lodash");
|
|
5
|
-
const logger_1 = require("../../core/services/logger");
|
|
6
5
|
const interfaces_1 = require("../cases/bo/interfaces");
|
|
7
6
|
var TotalizeMode;
|
|
8
7
|
(function (TotalizeMode) {
|
|
@@ -10,8 +9,7 @@ var TotalizeMode;
|
|
|
10
9
|
TotalizeMode["never"] = "never";
|
|
11
10
|
})(TotalizeMode = exports.TotalizeMode || (exports.TotalizeMode = {}));
|
|
12
11
|
class Repository {
|
|
13
|
-
constructor(
|
|
14
|
-
this.domain = domain;
|
|
12
|
+
constructor(transaction, sqlExecutor, secondaryDataBase, sqlServiceFunc, uuidService, table, autoCommit) {
|
|
15
13
|
this.transaction = transaction;
|
|
16
14
|
this.sqlExecutor = sqlExecutor;
|
|
17
15
|
this.secondaryDataBase = secondaryDataBase;
|
|
@@ -19,9 +17,8 @@ class Repository {
|
|
|
19
17
|
this.uuidService = uuidService;
|
|
20
18
|
this.table = table;
|
|
21
19
|
this.autoCommit = autoCommit;
|
|
22
|
-
this.log = new logger_1.Logger(this.domain, 'Repository');
|
|
23
20
|
}
|
|
24
|
-
async findByIn({ key, values, fields, orderBy, user, alias, totalizeMode = TotalizeMode.auto, forUpdate, with: w, from, query, join, union, unionAll, disablePermissionSystem }) {
|
|
21
|
+
async findByIn({ key, values, fields, orderBy, user, alias, totalizeMode = TotalizeMode.auto, forUpdate, with: w, from, query, join, union, unionAll, disablePermissionSystem, requestCachePath }) {
|
|
25
22
|
const retorno = await this.findWhere({
|
|
26
23
|
fields,
|
|
27
24
|
args: {
|
|
@@ -43,7 +40,8 @@ class Repository {
|
|
|
43
40
|
join,
|
|
44
41
|
union,
|
|
45
42
|
unionAll,
|
|
46
|
-
disablePermissionSystem
|
|
43
|
+
disablePermissionSystem,
|
|
44
|
+
requestCachePath,
|
|
47
45
|
});
|
|
48
46
|
return retorno.data;
|
|
49
47
|
}
|
|
@@ -51,7 +49,7 @@ class Repository {
|
|
|
51
49
|
var _a;
|
|
52
50
|
return args.alias || (typeof args.from === 'string' ? args.from : (_a = args.from) === null || _a === void 0 ? void 0 : _a.alias) || this.table;
|
|
53
51
|
}
|
|
54
|
-
async findByPucaPid({ pucaPid, fields, user, alias: oAlias, forUpdate, with: w, from, join, query, disablePermissionSystem }) {
|
|
52
|
+
async findByPucaPid({ pucaPid, fields, user, alias: oAlias, forUpdate, with: w, from, join, query, disablePermissionSystem, requestCachePath }) {
|
|
55
53
|
const alias = this.getAlias({ from, alias: oAlias });
|
|
56
54
|
return await this.findOneBy({
|
|
57
55
|
fields,
|
|
@@ -65,11 +63,12 @@ class Repository {
|
|
|
65
63
|
join,
|
|
66
64
|
disablePermissionSystem,
|
|
67
65
|
query,
|
|
66
|
+
requestCachePath,
|
|
68
67
|
});
|
|
69
68
|
}
|
|
70
69
|
async findOneBy(args) {
|
|
71
70
|
const alias = this.getAlias(args);
|
|
72
|
-
const result = await this.findBy(Object.assign(Object.assign({}, args), { pageSize: 1, orderBy: [`${alias}.puca_created_at`], totalizeMode: TotalizeMode.never
|
|
71
|
+
const result = await this.findBy(Object.assign(Object.assign({}, args), { pageSize: 1, orderBy: [`${alias}.puca_created_at`], totalizeMode: TotalizeMode.never }));
|
|
73
72
|
return _.get(result.data, 0);
|
|
74
73
|
}
|
|
75
74
|
async findOneWhere(args) {
|
|
@@ -77,7 +76,7 @@ class Repository {
|
|
|
77
76
|
const result = await this.findWhere(Object.assign(Object.assign({}, args), { pageSize: 1, orderBy: [`${alias}.puca_created_at`], totalizeMode: TotalizeMode.never, forUpdate: args.forUpdate, disablePermissionSystem: args.disablePermissionSystem, union: args.union, unionAll: args.unionAll }));
|
|
78
77
|
return _.get(result.data, 0);
|
|
79
78
|
}
|
|
80
|
-
async countBy({ key, value, user, groupBy, alias, with: w, from, query, union, unionAll, disablePermissionSystem, join }) {
|
|
79
|
+
async countBy({ key, value, user, groupBy, alias, with: w, from, query, union, unionAll, disablePermissionSystem, join, requestCachePath }) {
|
|
81
80
|
return await this.countWhere({
|
|
82
81
|
args: {
|
|
83
82
|
value,
|
|
@@ -96,151 +95,168 @@ class Repository {
|
|
|
96
95
|
query,
|
|
97
96
|
union,
|
|
98
97
|
unionAll,
|
|
99
|
-
disablePermissionSystem
|
|
98
|
+
disablePermissionSystem,
|
|
99
|
+
requestCachePath
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
-
async countWhere(
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
102
|
+
async countWhere(findArgs) {
|
|
103
|
+
const func = async () => {
|
|
104
|
+
const { where, args, join, user, groupBy, alias: oAlias, with: w, from, disablePermissionSystem, query, union, unionAll, compress } = findArgs;
|
|
105
|
+
const alias = this.getAlias({ from, alias: oAlias });
|
|
106
|
+
if (!_.isEmpty(groupBy)) {
|
|
107
|
+
const result = await this.sqlExecutor.select({
|
|
108
|
+
fields: [
|
|
109
|
+
{
|
|
110
|
+
function: 'count',
|
|
111
|
+
args: [`$countWhereOne`],
|
|
112
|
+
alias: 'count',
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
from: from || {
|
|
116
|
+
table: this.table,
|
|
117
|
+
alias,
|
|
111
118
|
},
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
119
|
+
join,
|
|
120
|
+
args: Object.assign(Object.assign({}, args), { countWhereOne: 1 }),
|
|
121
|
+
where,
|
|
122
|
+
groupBy,
|
|
123
|
+
user,
|
|
124
|
+
with: w,
|
|
125
|
+
disablePermissionSystem,
|
|
126
|
+
query: (query || []).map(q => (Object.assign(Object.assign({}, q), { orderByRank: false }))),
|
|
127
|
+
union,
|
|
128
|
+
unionAll,
|
|
129
|
+
compress
|
|
130
|
+
});
|
|
131
|
+
return result.length;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
const fieldCount = {
|
|
135
|
+
field: "$countWhereOne",
|
|
136
|
+
alias: "count",
|
|
137
|
+
};
|
|
138
|
+
const result = await this.sqlExecutor.select({
|
|
139
|
+
with: [{
|
|
140
|
+
alias: "t",
|
|
141
|
+
select: {
|
|
142
|
+
fields: [
|
|
143
|
+
fieldCount
|
|
144
|
+
],
|
|
145
|
+
from: from || {
|
|
146
|
+
table: this.table,
|
|
147
|
+
alias: alias
|
|
148
|
+
},
|
|
149
|
+
join,
|
|
150
|
+
where,
|
|
151
|
+
with: w,
|
|
152
|
+
query: (query || []).map(q => (Object.assign(Object.assign({}, q), { orderByRank: false }))),
|
|
153
|
+
union: (union || []).map(u => (Object.assign(Object.assign({}, u), { fields: [fieldCount] }))),
|
|
154
|
+
unionAll: (unionAll || []).map(u => (Object.assign(Object.assign({}, u), { fields: [fieldCount] }))),
|
|
155
|
+
}
|
|
156
|
+
}],
|
|
157
|
+
fields: [{
|
|
158
|
+
function: 'count',
|
|
159
|
+
args: [`$countWhereOne`],
|
|
160
|
+
alias: 'count',
|
|
161
|
+
}],
|
|
162
|
+
args: Object.assign(Object.assign({}, args), { countWhereOne: 1 }),
|
|
163
|
+
from: "t",
|
|
164
|
+
user,
|
|
165
|
+
disablePermissionSystem,
|
|
166
|
+
compress
|
|
167
|
+
});
|
|
168
|
+
return result[0].count;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
return findArgs.requestCachePath ?
|
|
172
|
+
await findArgs.user.cache
|
|
173
|
+
.getSubCache(findArgs.requestCachePath)
|
|
174
|
+
.get(findArgs, func) :
|
|
175
|
+
await func();
|
|
176
|
+
}
|
|
177
|
+
async findWhere(findArgs) {
|
|
178
|
+
const func = async () => {
|
|
179
|
+
let { args, where, fields, join, page, pageSize, orderBy, totalizeMode, user, groupBy, alias: oAlias, forUpdate, with: w, from: oFrom, disablePermissionSystem, query, union, unionAll, compress } = findArgs;
|
|
180
|
+
const limit = page ? pageSize || 20 : pageSize;
|
|
181
|
+
const offset = ((page || 1) - 1) * (pageSize || 20);
|
|
182
|
+
const queryTableName = (typeof oFrom === 'string' ? oFrom : oFrom === null || oFrom === void 0 ? void 0 : oFrom.table) || this.table;
|
|
183
|
+
const alias = this.getAlias({ from: oFrom, alias: oAlias });
|
|
184
|
+
if (page && _.isEmpty(orderBy)) {
|
|
185
|
+
orderBy = [{
|
|
186
|
+
field: 'puca_created_at',
|
|
187
|
+
table: alias || queryTableName
|
|
188
|
+
}];
|
|
189
|
+
}
|
|
190
|
+
const queryHasTable = queryTableName === this.table || (w || []).find(w => {
|
|
191
|
+
const withTableName = typeof w.select.from === 'string' ? w.select.from : w.select.from.table;
|
|
192
|
+
return withTableName === this.table;
|
|
128
193
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
alias
|
|
194
|
+
if (!queryHasTable) {
|
|
195
|
+
throw new Error(`query must have table ${this.table}`);
|
|
196
|
+
}
|
|
197
|
+
const from = oFrom || {
|
|
198
|
+
table: this.table,
|
|
199
|
+
alias
|
|
135
200
|
};
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
table: this.table,
|
|
145
|
-
alias: alias
|
|
146
|
-
},
|
|
147
|
-
join,
|
|
148
|
-
where,
|
|
149
|
-
with: w,
|
|
150
|
-
query: (query || []).map(q => (Object.assign(Object.assign({}, q), { orderByRank: false }))),
|
|
151
|
-
union: (union || []).map(u => (Object.assign(Object.assign({}, u), { fields: [fieldCount] }))),
|
|
152
|
-
unionAll: (unionAll || []).map(u => (Object.assign(Object.assign({}, u), { fields: [fieldCount] }))),
|
|
153
|
-
}
|
|
154
|
-
}],
|
|
155
|
-
fields: [{
|
|
156
|
-
function: 'count',
|
|
157
|
-
args: [`$countWhereOne`],
|
|
158
|
-
alias: 'count',
|
|
159
|
-
}],
|
|
160
|
-
args: Object.assign(Object.assign({}, args), { countWhereOne: 1 }),
|
|
161
|
-
from: "t",
|
|
162
|
-
user,
|
|
163
|
-
disablePermissionSystem,
|
|
164
|
-
compress
|
|
165
|
-
});
|
|
166
|
-
return result[0].count;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
async findWhere({ args, where, fields, join, page, pageSize, orderBy, totalizeMode, user, groupBy, alias: oAlias, forUpdate, with: w, from: oFrom, disablePermissionSystem, query, union, unionAll, compress }) {
|
|
170
|
-
const limit = page ? pageSize || 20 : pageSize;
|
|
171
|
-
const offset = ((page || 1) - 1) * (pageSize || 20);
|
|
172
|
-
const queryTableName = (typeof oFrom === 'string' ? oFrom : oFrom === null || oFrom === void 0 ? void 0 : oFrom.table) || this.table;
|
|
173
|
-
const alias = this.getAlias({ from: oFrom, alias: oAlias });
|
|
174
|
-
if (page && _.isEmpty(orderBy)) {
|
|
175
|
-
orderBy = [{
|
|
176
|
-
field: 'puca_created_at',
|
|
177
|
-
table: alias || queryTableName
|
|
178
|
-
}];
|
|
179
|
-
}
|
|
180
|
-
const queryHasTable = queryTableName === this.table || (w || []).find(w => {
|
|
181
|
-
const withTableName = typeof w.select.from === 'string' ? w.select.from : w.select.from.table;
|
|
182
|
-
return withTableName === this.table;
|
|
183
|
-
});
|
|
184
|
-
if (!queryHasTable) {
|
|
185
|
-
throw new Error(`query must have table ${this.table}`);
|
|
186
|
-
}
|
|
187
|
-
const from = oFrom || {
|
|
188
|
-
table: this.table,
|
|
189
|
-
alias
|
|
190
|
-
};
|
|
191
|
-
const totalize = {
|
|
192
|
-
[TotalizeMode.never]: false,
|
|
193
|
-
[TotalizeMode.auto]: !!(limit || offset)
|
|
194
|
-
}[totalizeMode || TotalizeMode.auto];
|
|
195
|
-
const [result, count] = await Promise.all([
|
|
196
|
-
this.sqlExecutor.select({
|
|
197
|
-
fields,
|
|
198
|
-
from,
|
|
199
|
-
join,
|
|
200
|
-
args,
|
|
201
|
-
where,
|
|
202
|
-
limit,
|
|
203
|
-
offset,
|
|
204
|
-
orderBy,
|
|
205
|
-
groupBy,
|
|
206
|
-
user,
|
|
207
|
-
forUpdate,
|
|
208
|
-
with: w,
|
|
209
|
-
disablePermissionSystem,
|
|
210
|
-
query,
|
|
211
|
-
union,
|
|
212
|
-
unionAll,
|
|
213
|
-
compress
|
|
214
|
-
}),
|
|
215
|
-
totalize
|
|
216
|
-
? this.countWhere({
|
|
201
|
+
const totalize = {
|
|
202
|
+
[TotalizeMode.never]: false,
|
|
203
|
+
[TotalizeMode.auto]: !!(limit || offset)
|
|
204
|
+
}[totalizeMode || TotalizeMode.auto];
|
|
205
|
+
const [result, count] = await Promise.all([
|
|
206
|
+
this.sqlExecutor.select({
|
|
207
|
+
fields,
|
|
208
|
+
from,
|
|
217
209
|
join,
|
|
218
210
|
args,
|
|
219
211
|
where,
|
|
220
|
-
|
|
212
|
+
limit,
|
|
213
|
+
offset,
|
|
214
|
+
orderBy,
|
|
221
215
|
groupBy,
|
|
222
|
-
|
|
216
|
+
user,
|
|
217
|
+
forUpdate,
|
|
223
218
|
with: w,
|
|
224
|
-
from,
|
|
225
219
|
disablePermissionSystem,
|
|
226
|
-
query
|
|
220
|
+
query,
|
|
227
221
|
union,
|
|
228
222
|
unionAll,
|
|
229
223
|
compress
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
224
|
+
}),
|
|
225
|
+
totalize
|
|
226
|
+
? this.countWhere({
|
|
227
|
+
join,
|
|
228
|
+
args,
|
|
229
|
+
where,
|
|
230
|
+
user,
|
|
231
|
+
groupBy,
|
|
232
|
+
alias,
|
|
233
|
+
with: w,
|
|
234
|
+
from,
|
|
235
|
+
disablePermissionSystem,
|
|
236
|
+
query: (query || []).map(q => (Object.assign(Object.assign({}, q), { orderByRank: false }))),
|
|
237
|
+
union,
|
|
238
|
+
unionAll,
|
|
239
|
+
compress,
|
|
240
|
+
})
|
|
241
|
+
: new Promise(r => r(null)),
|
|
242
|
+
]);
|
|
243
|
+
const retorno = {
|
|
244
|
+
data: result,
|
|
245
|
+
orderBy: orderBy || null,
|
|
246
|
+
page: +page || null,
|
|
247
|
+
pageSize: +pageSize || null,
|
|
248
|
+
totalPages: pageSize ? Math.ceil(+count / +pageSize) : null,
|
|
249
|
+
totalItems: totalize ? +count : null,
|
|
250
|
+
};
|
|
251
|
+
return retorno;
|
|
240
252
|
};
|
|
241
|
-
return
|
|
253
|
+
return findArgs.requestCachePath ?
|
|
254
|
+
await findArgs.user.cache
|
|
255
|
+
.getSubCache(findArgs.requestCachePath)
|
|
256
|
+
.get(findArgs, func) :
|
|
257
|
+
await func();
|
|
242
258
|
}
|
|
243
|
-
async findBy({ key: originalKey, value: originalValue, fields, page, pageSize, orderBy, groupBy, user, alias, totalizeMode, forUpdate, with: w, from, disablePermissionSystem, query, join, union, unionAll, args }) {
|
|
259
|
+
async findBy({ key: originalKey, value: originalValue, fields, page, pageSize, orderBy, groupBy, user, alias, totalizeMode, forUpdate, with: w, from, disablePermissionSystem, query, join, union, unionAll, args, requestCachePath }) {
|
|
244
260
|
const keys = _.isArray(originalKey) ? originalKey : [originalKey];
|
|
245
261
|
const values = _.isArray(originalValue) ? originalValue : [originalValue];
|
|
246
262
|
return await this.findWhere({
|
|
@@ -276,15 +292,17 @@ class Repository {
|
|
|
276
292
|
query,
|
|
277
293
|
union,
|
|
278
294
|
unionAll,
|
|
295
|
+
requestCachePath
|
|
279
296
|
});
|
|
280
297
|
}
|
|
281
298
|
async countAll(args) {
|
|
282
299
|
return await this.countWhere({
|
|
283
300
|
user: args.user,
|
|
284
|
-
disablePermissionSystem: args.disablePermissionSystem
|
|
301
|
+
disablePermissionSystem: args.disablePermissionSystem,
|
|
302
|
+
requestCachePath: args.requestCachePath
|
|
285
303
|
});
|
|
286
304
|
}
|
|
287
|
-
async findAll({ fields, page, pageSize, orderBy, groupBy, join, user, alias, forUpdate, with: w, from, query, disablePermissionSystem, union, unionAll, totalizeMode }) {
|
|
305
|
+
async findAll({ fields, page, pageSize, orderBy, groupBy, join, user, alias, forUpdate, with: w, from, query, disablePermissionSystem, union, unionAll, totalizeMode, requestCachePath }) {
|
|
288
306
|
return await this.findWhere({
|
|
289
307
|
fields,
|
|
290
308
|
join,
|
|
@@ -301,7 +319,8 @@ class Repository {
|
|
|
301
319
|
query,
|
|
302
320
|
disablePermissionSystem,
|
|
303
321
|
union,
|
|
304
|
-
unionAll
|
|
322
|
+
unionAll,
|
|
323
|
+
requestCachePath
|
|
305
324
|
});
|
|
306
325
|
}
|
|
307
326
|
async _insert({ entity: originalEntity, user, disablePermissionSystem }) {
|