@autofleet/sadot 0.6.8-beta.2 → 0.6.8
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 +7 -0
- package/dist/scopes/filter.js +7 -0
- package/dist/tests/helpers/database-config.d.ts +1 -4
- package/dist/tests/helpers/database-config.js +1 -1
- package/dist/utils/helpers/index.js +2 -1
- package/package.json +1 -1
- package/src/scopes/filter.ts +7 -0
- package/src/tests/helpers/database-config.ts +1 -1
- package/src/utils/helpers/index.ts +2 -1
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
|
@@ -21,6 +21,13 @@ const castIfNeeded = (conditionValue) => {
|
|
|
21
21
|
return '';
|
|
22
22
|
};
|
|
23
23
|
const AND_DELIMETER = ' AND ';
|
|
24
|
+
/**
|
|
25
|
+
* A Sequelize scope for filtering models by custom fields.
|
|
26
|
+
* This scope builds a WHERE clause to be applied on the main query.
|
|
27
|
+
*
|
|
28
|
+
* @param name - The model type name used to join custom_field_definitions.
|
|
29
|
+
* @returns A function that takes conditions and returns the Sequelize options object.
|
|
30
|
+
*/
|
|
24
31
|
const customFieldsFilterScope = (name) => (conditions) => {
|
|
25
32
|
if (!conditions || Object.keys(conditions).length === 0) {
|
|
26
33
|
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
package/src/scopes/filter.ts
CHANGED
|
@@ -38,6 +38,13 @@ const castIfNeeded = (conditionValue: string): string => {
|
|
|
38
38
|
};
|
|
39
39
|
const AND_DELIMETER = ' AND ';
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* A Sequelize scope for filtering models by custom fields.
|
|
43
|
+
* This scope builds a WHERE clause to be applied on the main query.
|
|
44
|
+
*
|
|
45
|
+
* @param name - The model type name used to join custom_field_definitions.
|
|
46
|
+
* @returns A function that takes conditions and returns the Sequelize options object.
|
|
47
|
+
*/
|
|
41
48
|
export const customFieldsFilterScope = (
|
|
42
49
|
name: string,
|
|
43
50
|
) => (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 = (
|