@autofleet/sadot 0.6.8-beta.2 → 0.6.8-beta.3
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/scopes/filter.d.ts
CHANGED
|
@@ -17,6 +17,13 @@ export type CustomFieldFilterOptions = {
|
|
|
17
17
|
where?: WhereOptions;
|
|
18
18
|
replacements?: Record<string, string>;
|
|
19
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* A Sequelize scope for filtering models by custom fields.
|
|
22
|
+
* This scope builds a WHERE clause to be applied on the main query.
|
|
23
|
+
*
|
|
24
|
+
* @param name - The model type name used to join custom_field_definitions.
|
|
25
|
+
* @returns A function that takes conditions and returns the Sequelize options object.
|
|
26
|
+
*/
|
|
20
27
|
export declare const customFieldsFilterScope: (name: string) => (conditions: Record<string, ConditionValue>) => CustomFieldFilterOptions;
|
|
21
28
|
export declare const scopeName = "filterByCustomFields";
|
|
22
29
|
export declare const customFieldsSortScope: (name: string) => (sort: CustomFieldSort[]) => {
|
package/dist/scopes/filter.js
CHANGED
|
@@ -5,14 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.customFieldsSortScope = exports.scopeName = exports.customFieldsFilterScope = void 0;
|
|
7
7
|
/* eslint-disable import/prefer-default-export */
|
|
8
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
9
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
10
|
const sequelize_1 = require("sequelize");
|
|
9
11
|
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
10
12
|
const common_types_1 = require("@autofleet/common-types");
|
|
11
|
-
const moment_1 = __importDefault(require("moment"));
|
|
12
13
|
const helpers_1 = require("../utils/helpers");
|
|
13
14
|
const { CUSTOM_FIELDS_FILTER_SCOPE } = common_types_1.customFields;
|
|
14
15
|
const castIfNeeded = (conditionValue) => {
|
|
15
|
-
if (
|
|
16
|
+
if ((0, dayjs_1.default)(conditionValue).isValid()) {
|
|
16
17
|
return '::timestamp';
|
|
17
18
|
}
|
|
18
19
|
if (!Number.isNaN(Number(conditionValue))) {
|
|
@@ -21,6 +22,13 @@ const castIfNeeded = (conditionValue) => {
|
|
|
21
22
|
return '';
|
|
22
23
|
};
|
|
23
24
|
const AND_DELIMETER = ' AND ';
|
|
25
|
+
/**
|
|
26
|
+
* A Sequelize scope for filtering models by custom fields.
|
|
27
|
+
* This scope builds a WHERE clause to be applied on the main query.
|
|
28
|
+
*
|
|
29
|
+
* @param name - The model type name used to join custom_field_definitions.
|
|
30
|
+
* @returns A function that takes conditions and returns the Sequelize options object.
|
|
31
|
+
*/
|
|
24
32
|
const customFieldsFilterScope = (name) => (conditions) => {
|
|
25
33
|
if (!conditions || Object.keys(conditions).length === 0) {
|
|
26
34
|
return {};
|
|
@@ -4,10 +4,11 @@ exports.generateCustomFieldSearchQueryPayload = exports.generateRandomString = v
|
|
|
4
4
|
/* eslint-disable import/prefer-default-export */
|
|
5
5
|
const sequelize_1 = require("sequelize");
|
|
6
6
|
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
7
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
8
|
const constants_1 = require("../constants");
|
|
8
9
|
const generateRandomString = (length = 5) => {
|
|
9
10
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
10
|
-
return Array.from({ length }, () => characters.charAt(
|
|
11
|
+
return Array.from({ length }, () => characters.charAt((0, node_crypto_1.randomInt)(characters.length))).join('');
|
|
11
12
|
};
|
|
12
13
|
exports.generateRandomString = generateRandomString;
|
|
13
14
|
const generateCustomFieldSearchQueryPayload = (searchTerm, model, entityId, customFieldsTypesToExclude = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/sadot",
|
|
3
|
-
"version": "0.6.8-beta.
|
|
3
|
+
"version": "0.6.8-beta.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"@autofleet/errors": "^1.0.10",
|
|
35
35
|
"@autofleet/events": "^2.0.0",
|
|
36
36
|
"@autofleet/logger": "^2.0.5",
|
|
37
|
+
"dayjs": "^1.11.11",
|
|
37
38
|
"express": "^4.18.2",
|
|
38
39
|
"joi": "^17.7.0",
|
|
39
|
-
"moment": "^2.30.1",
|
|
40
40
|
"pg": "^8.10.0",
|
|
41
41
|
"reflect-metadata": "^0.1.13",
|
|
42
42
|
"sequelize": "^6.31.1",
|
package/src/scopes/filter.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
|
+
import dayjs from 'dayjs';
|
|
2
4
|
import { Op, type WhereOptions } from 'sequelize';
|
|
3
5
|
import { Sequelize } from 'sequelize-typescript';
|
|
4
6
|
import { customFields } from '@autofleet/common-types';
|
|
5
|
-
import moment from 'moment';
|
|
6
7
|
import { generateRandomString } from '../utils/helpers';
|
|
7
8
|
|
|
8
9
|
const { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;
|
|
@@ -29,15 +30,23 @@ export type CustomFieldFilterOptions = {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
const castIfNeeded = (conditionValue: string): string => {
|
|
32
|
-
if (
|
|
33
|
+
if (dayjs(conditionValue).isValid()) {
|
|
33
34
|
return '::timestamp';
|
|
34
35
|
} if (!Number.isNaN(Number(conditionValue))) {
|
|
35
36
|
return '::numeric';
|
|
36
37
|
}
|
|
37
38
|
return '';
|
|
38
39
|
};
|
|
40
|
+
|
|
39
41
|
const AND_DELIMETER = ' AND ';
|
|
40
42
|
|
|
43
|
+
/**
|
|
44
|
+
* A Sequelize scope for filtering models by custom fields.
|
|
45
|
+
* This scope builds a WHERE clause to be applied on the main query.
|
|
46
|
+
*
|
|
47
|
+
* @param name - The model type name used to join custom_field_definitions.
|
|
48
|
+
* @returns A function that takes conditions and returns the Sequelize options object.
|
|
49
|
+
*/
|
|
41
50
|
export const customFieldsFilterScope = (
|
|
42
51
|
name: string,
|
|
43
52
|
) => (conditions: Record<string, ConditionValue>): CustomFieldFilterOptions => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable import/prefer-default-export */
|
|
2
2
|
import { type WhereOptions, Op, type BindOrReplacements } from 'sequelize';
|
|
3
3
|
import { type ModelStatic, Sequelize } from 'sequelize-typescript';
|
|
4
|
+
import { randomInt } from 'node:crypto';
|
|
4
5
|
import { CustomFieldDefinitionType } from '../constants';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -27,7 +28,7 @@ interface CustomFieldsSearchPayload {
|
|
|
27
28
|
|
|
28
29
|
export const generateRandomString = (length = 5): string => {
|
|
29
30
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
30
|
-
return Array.from({ length }, () => characters.charAt(
|
|
31
|
+
return Array.from({ length }, () => characters.charAt(randomInt(characters.length))).join('');
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
export const generateCustomFieldSearchQueryPayload = (
|