@sdflc/backend-helpers 1.0.52 → 1.0.53
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/build/BaseGateway.js +1 -1
- package/build/commonValidators.d.ts +6 -0
- package/build/commonValidators.js +125 -1
- package/build/dbHelpers.js +20 -0
- package/build/dbTableHelpers.js +6 -2
- package/build/index.d.ts +1 -1
- package/build/index.js +16 -7
- package/build/interfaces/DbFieldAddDefaultInterface.d.ts +2 -0
- package/package.json +1 -1
package/build/BaseGateway.js
CHANGED
|
@@ -86,7 +86,7 @@ class BaseGateway {
|
|
|
86
86
|
const { hasStatus, hasVersion } = this.config;
|
|
87
87
|
const idName = this.getIdField();
|
|
88
88
|
if (filterParams[idName]) {
|
|
89
|
-
query.
|
|
89
|
+
query.whereIn(idName, (0, lodash_1.castArray)(filterParams[idName]));
|
|
90
90
|
}
|
|
91
91
|
if (hasVersion) {
|
|
92
92
|
if (filterParams[constants_1.FIELDS.VERSION] != null && !isNaN(filterParams[constants_1.FIELDS.VERSION])) {
|
|
@@ -2,6 +2,12 @@ import { OpResult } from '@sdflc/api-helpers';
|
|
|
2
2
|
import { BaseCoreActionsInterface, CommonValidatorArgs } from './interfaces';
|
|
3
3
|
export declare const shouldHaveParams: (args: any) => boolean[] | OpResult[];
|
|
4
4
|
export declare const shouldHaveId: (id: any) => boolean[] | OpResult[];
|
|
5
|
+
export declare const validateSingleIntId: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
6
|
+
export declare const validateSingleUuidId: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
7
|
+
export declare const validateSingleTextId: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
8
|
+
export declare const validateMultipleIntIds: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
9
|
+
export declare const validateMultipleUuidIds: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
10
|
+
export declare const validateMultipleTextIds: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
5
11
|
export declare const validateList: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
6
12
|
export declare const validateCreate: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
|
|
7
13
|
export declare const validateUpdate: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
|
|
@@ -8,10 +8,86 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.validateUpdate = exports.validateCreate = exports.validateList = exports.shouldHaveId = exports.shouldHaveParams = void 0;
|
|
15
|
+
exports.validateUpdate = exports.validateCreate = exports.validateList = exports.validateMultipleTextIds = exports.validateMultipleUuidIds = exports.validateMultipleIntIds = exports.validateSingleTextId = exports.validateSingleUuidId = exports.validateSingleIntId = exports.shouldHaveId = exports.shouldHaveParams = void 0;
|
|
13
16
|
const api_helpers_1 = require("@sdflc/api-helpers");
|
|
14
17
|
const checkItHelpers_1 = require("./checkItHelpers");
|
|
18
|
+
const checkit_1 = __importDefault(require("checkit"));
|
|
19
|
+
const rulesSingleIntId = new checkit_1.default({
|
|
20
|
+
id: [
|
|
21
|
+
{
|
|
22
|
+
rule: 'required',
|
|
23
|
+
message: 'ID is required',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
rule: 'integer',
|
|
27
|
+
message: 'ID should be an integer',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
const rulesSingleUuidId = new checkit_1.default({
|
|
32
|
+
id: [
|
|
33
|
+
{
|
|
34
|
+
rule: 'required',
|
|
35
|
+
message: 'ID is required',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
rule: 'uuid',
|
|
39
|
+
message: 'ID should be an integer',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
const rulesSingleTextId = new checkit_1.default({
|
|
44
|
+
id: [
|
|
45
|
+
{
|
|
46
|
+
rule: 'required',
|
|
47
|
+
message: 'ID is required',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
rule: 'string',
|
|
51
|
+
message: 'ID should be a string',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
const rulesMultipleIntIds = new checkit_1.default({
|
|
56
|
+
ids: [
|
|
57
|
+
{
|
|
58
|
+
rule: 'required',
|
|
59
|
+
message: 'IDs is required',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
rule: 'array',
|
|
63
|
+
message: 'IDs should be an array of integer',
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
});
|
|
67
|
+
const rulesMultipleUuidIds = new checkit_1.default({
|
|
68
|
+
ids: [
|
|
69
|
+
{
|
|
70
|
+
rule: 'required',
|
|
71
|
+
message: 'IDs is required',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
rule: 'array',
|
|
75
|
+
message: 'IDs should be an array of UUIDs',
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
const rulesMultipleTextIds = new checkit_1.default({
|
|
80
|
+
ids: [
|
|
81
|
+
{
|
|
82
|
+
rule: 'required',
|
|
83
|
+
message: 'IDs is required',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
rule: 'array',
|
|
87
|
+
message: 'IDs should be an array of strings',
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
});
|
|
15
91
|
const shouldHaveParams = (args) => {
|
|
16
92
|
const keys = Object.keys(args || {});
|
|
17
93
|
if (keys.length === 0) {
|
|
@@ -31,6 +107,54 @@ const shouldHaveId = (id) => {
|
|
|
31
107
|
return [true];
|
|
32
108
|
};
|
|
33
109
|
exports.shouldHaveId = shouldHaveId;
|
|
110
|
+
const validateSingleIntId = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
+
const [result] = rulesSingleIntId.validateSync(args);
|
|
112
|
+
if (result) {
|
|
113
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
114
|
+
}
|
|
115
|
+
return [true, {}];
|
|
116
|
+
});
|
|
117
|
+
exports.validateSingleIntId = validateSingleIntId;
|
|
118
|
+
const validateSingleUuidId = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
|
+
const [result] = rulesSingleUuidId.validateSync(args);
|
|
120
|
+
if (result) {
|
|
121
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
122
|
+
}
|
|
123
|
+
return [true, {}];
|
|
124
|
+
});
|
|
125
|
+
exports.validateSingleUuidId = validateSingleUuidId;
|
|
126
|
+
const validateSingleTextId = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
const [result] = rulesSingleTextId.validateSync(args);
|
|
128
|
+
if (result) {
|
|
129
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
130
|
+
}
|
|
131
|
+
return [true, {}];
|
|
132
|
+
});
|
|
133
|
+
exports.validateSingleTextId = validateSingleTextId;
|
|
134
|
+
const validateMultipleIntIds = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
+
const [result] = rulesMultipleIntIds.validateSync(args);
|
|
136
|
+
if (result) {
|
|
137
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
138
|
+
}
|
|
139
|
+
return [true, {}];
|
|
140
|
+
});
|
|
141
|
+
exports.validateMultipleIntIds = validateMultipleIntIds;
|
|
142
|
+
const validateMultipleUuidIds = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
|
+
const [result] = rulesMultipleUuidIds.validateSync(args);
|
|
144
|
+
if (result) {
|
|
145
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
146
|
+
}
|
|
147
|
+
return [true, {}];
|
|
148
|
+
});
|
|
149
|
+
exports.validateMultipleUuidIds = validateMultipleUuidIds;
|
|
150
|
+
const validateMultipleTextIds = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
|
+
const [result] = rulesMultipleTextIds.validateSync(args);
|
|
152
|
+
if (result) {
|
|
153
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
154
|
+
}
|
|
155
|
+
return [true, {}];
|
|
156
|
+
});
|
|
157
|
+
exports.validateMultipleTextIds = validateMultipleTextIds;
|
|
34
158
|
const validateList = ({ rules }) =>
|
|
35
159
|
// eslint-disable-next-line
|
|
36
160
|
(args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
package/build/dbHelpers.js
CHANGED
|
@@ -36,6 +36,26 @@ const SQLS = {
|
|
|
36
36
|
FROM INFORMATION_SCHEMA.TABLES';
|
|
37
37
|
`,
|
|
38
38
|
},
|
|
39
|
+
mssql: {
|
|
40
|
+
listTablesSchema: (appSettings) => `
|
|
41
|
+
SELECT TABLE_NAME as table_name
|
|
42
|
+
FROM INFORMATION_SCHEMA.TABLES
|
|
43
|
+
WHERE TABLE_SCHEMA = '${appSettings === null || appSettings === void 0 ? void 0 : appSettings.dbSchema}';
|
|
44
|
+
`,
|
|
45
|
+
listTables: () => `
|
|
46
|
+
SELECT TABLE_NAME as table_name
|
|
47
|
+
FROM INFORMATION_SCHEMA.TABLES
|
|
48
|
+
`,
|
|
49
|
+
dropTablesSchema: (appSettings) => `
|
|
50
|
+
SELECT 'DROP TABLE IF EXISTS [${appSettings === null || appSettings === void 0 ? void 0 : appSettings.dbSchema}].[' + TABLE_NAME + '];' as cmd
|
|
51
|
+
FROM INFORMATION_SCHEMA.TABLES
|
|
52
|
+
WHERE TABLE_SCHEMA = '${appSettings === null || appSettings === void 0 ? void 0 : appSettings.dbSchema}';
|
|
53
|
+
`,
|
|
54
|
+
dropTables: () => `
|
|
55
|
+
SELECT 'DROP TABLE IF EXISTS ' + TABLE_NAME + ';' as cmd
|
|
56
|
+
FROM INFORMATION_SCHEMA.TABLES';
|
|
57
|
+
`,
|
|
58
|
+
},
|
|
39
59
|
};
|
|
40
60
|
/**
|
|
41
61
|
* Removes all the records from provided table.
|
package/build/dbTableHelpers.js
CHANGED
|
@@ -9,10 +9,14 @@ const dbFieldAddDefaults = (table, opt) => {
|
|
|
9
9
|
table
|
|
10
10
|
.integer(constants_1.FIELDS.STATUS)
|
|
11
11
|
.defaultTo(utils_1.STATUSES.ACTIVE)
|
|
12
|
-
.comment(
|
|
12
|
+
.comment((opt === null || opt === void 0 ? void 0 : opt.statusComment) ||
|
|
13
|
+
'The field is used to specify record status: 50 - Test, 100 - Active, 200 - Draft, 300 - Pending, 1000 - Blocked, 5000 - Disabled, 10000 - Removed');
|
|
13
14
|
}
|
|
14
15
|
if (addVersion) {
|
|
15
|
-
table
|
|
16
|
+
table
|
|
17
|
+
.integer(constants_1.FIELDS.VERSION)
|
|
18
|
+
.defaultTo(0)
|
|
19
|
+
.comment((opt === null || opt === void 0 ? void 0 : opt.versionComment) || 'The field is used to control versioning');
|
|
16
20
|
}
|
|
17
21
|
if (addUserInfo) {
|
|
18
22
|
table.uuid(constants_1.FIELDS.CREATED_BY).comment('ID of user who created the record');
|
package/build/index.d.ts
CHANGED
|
@@ -17,4 +17,4 @@ export { dbFieldAddDefaults, addOrderNo, addAmount, addSpaceId, addUserId, addAc
|
|
|
17
17
|
export { buildDefaultResolvers } from './resolversHelpers';
|
|
18
18
|
export { createUserToken, verifyUserToken } from './userToken';
|
|
19
19
|
export { getSaltAndHash, checkPassword } from './passwordHelpers';
|
|
20
|
-
export
|
|
20
|
+
export * from './commonValidators';
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
17
|
+
exports.checkPassword = exports.getSaltAndHash = exports.verifyUserToken = exports.createUserToken = exports.buildDefaultResolvers = exports.defaultFields = exports.addLang = exports.addAccountId = exports.addUserId = exports.addSpaceId = exports.addAmount = exports.addOrderNo = exports.dbFieldAddDefaults = exports.BaseController = exports.createContextDefault = exports.createApiContext = exports.BaseCore = exports.BaseGateway = exports.DataCache = exports.createErrorOnCheckError = exports.checkArray = exports.createRedisClient = exports.buildKnexConfig = exports.dbSeed = exports.DbMigratorAndSeeder = exports.dbRunMigrations = exports.dbTransformSeedsToObject = exports.dbReset = exports.dbWipe = exports.dbClean = exports.dbListTables = exports.dbCleanTable = exports.Database = exports.buildConfig = exports.HEADERS = exports.FIELDS = exports.ID_FIELD = void 0;
|
|
4
18
|
var constants_1 = require("./constants");
|
|
5
19
|
Object.defineProperty(exports, "ID_FIELD", { enumerable: true, get: function () { return constants_1.ID_FIELD; } });
|
|
6
20
|
Object.defineProperty(exports, "FIELDS", { enumerable: true, get: function () { return constants_1.FIELDS; } });
|
|
@@ -56,9 +70,4 @@ Object.defineProperty(exports, "verifyUserToken", { enumerable: true, get: funct
|
|
|
56
70
|
var passwordHelpers_1 = require("./passwordHelpers");
|
|
57
71
|
Object.defineProperty(exports, "getSaltAndHash", { enumerable: true, get: function () { return passwordHelpers_1.getSaltAndHash; } });
|
|
58
72
|
Object.defineProperty(exports, "checkPassword", { enumerable: true, get: function () { return passwordHelpers_1.checkPassword; } });
|
|
59
|
-
|
|
60
|
-
Object.defineProperty(exports, "shouldHaveParams", { enumerable: true, get: function () { return commonValidators_1.shouldHaveParams; } });
|
|
61
|
-
Object.defineProperty(exports, "shouldHaveId", { enumerable: true, get: function () { return commonValidators_1.shouldHaveId; } });
|
|
62
|
-
Object.defineProperty(exports, "validateList", { enumerable: true, get: function () { return commonValidators_1.validateList; } });
|
|
63
|
-
Object.defineProperty(exports, "validateCreate", { enumerable: true, get: function () { return commonValidators_1.validateCreate; } });
|
|
64
|
-
Object.defineProperty(exports, "validateUpdate", { enumerable: true, get: function () { return commonValidators_1.validateUpdate; } });
|
|
73
|
+
__exportStar(require("./commonValidators"), exports);
|
package/package.json
CHANGED