querier-ts 0.0.0

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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +234 -0
  3. package/lib/base-object.d.ts +6 -0
  4. package/lib/base-object.js +15 -0
  5. package/lib/errors/index.d.ts +2 -0
  6. package/lib/errors/index.js +5 -0
  7. package/lib/errors/invalid-argument-error.d.ts +10 -0
  8. package/lib/errors/invalid-argument-error.js +11 -0
  9. package/lib/index.d.ts +2 -0
  10. package/lib/index.js +5 -0
  11. package/lib/query-conditions-group-nullable.d.ts +4 -0
  12. package/lib/query-conditions-group-nullable.js +2 -0
  13. package/lib/query-conditions-group.d.ts +4 -0
  14. package/lib/query-conditions-group.js +2 -0
  15. package/lib/query-row-validator.d.ts +72 -0
  16. package/lib/query-row-validator.js +85 -0
  17. package/lib/query.d.ts +215 -0
  18. package/lib/query.js +331 -0
  19. package/lib/utils/decorators/number-validaton.d.ts +36 -0
  20. package/lib/utils/decorators/number-validaton.js +124 -0
  21. package/lib/utils/functions/generic/compare-arrays.d.ts +9 -0
  22. package/lib/utils/functions/generic/compare-arrays.js +13 -0
  23. package/lib/utils/functions/generic/get-entries.d.ts +8 -0
  24. package/lib/utils/functions/generic/get-entries.js +12 -0
  25. package/lib/utils/functions/generic/index.d.ts +3 -0
  26. package/lib/utils/functions/generic/index.js +7 -0
  27. package/lib/utils/functions/sort/index.d.ts +3 -0
  28. package/lib/utils/functions/sort/index.js +7 -0
  29. package/lib/utils/functions/sort/sort-by-properties.d.ts +2 -0
  30. package/lib/utils/functions/sort/sort-by-properties.js +17 -0
  31. package/lib/utils/functions/sort/sort-by-property.d.ts +2 -0
  32. package/lib/utils/functions/sort/sort-by-property.js +15 -0
  33. package/lib/utils/functions/type-guards/index.d.ts +4 -0
  34. package/lib/utils/functions/type-guards/index.js +9 -0
  35. package/lib/utils/functions/type-guards/is-function.d.ts +8 -0
  36. package/lib/utils/functions/type-guards/is-function.js +12 -0
  37. package/lib/utils/functions/type-guards/is-number.d.ts +8 -0
  38. package/lib/utils/functions/type-guards/is-number.js +12 -0
  39. package/lib/utils/functions/type-guards/is-object.d.ts +8 -0
  40. package/lib/utils/functions/type-guards/is-object.js +12 -0
  41. package/lib/utils/types/add-prefix-to-object.d.ts +3 -0
  42. package/lib/utils/types/add-prefix-to-object.js +2 -0
  43. package/lib/utils/types/allowed-names.d.ts +5 -0
  44. package/lib/utils/types/allowed-names.js +2 -0
  45. package/lib/utils/types/flag-excluded-type.d.ts +6 -0
  46. package/lib/utils/types/flag-excluded-type.js +2 -0
  47. package/lib/utils/types/generic-object.d.ts +3 -0
  48. package/lib/utils/types/generic-object.js +3 -0
  49. package/lib/utils/types/index.d.ts +10 -0
  50. package/lib/utils/types/index.js +2 -0
  51. package/lib/utils/types/omit-type.d.ts +5 -0
  52. package/lib/utils/types/omit-type.js +2 -0
  53. package/lib/utils/types/partial-of-properties.d.ts +2 -0
  54. package/lib/utils/types/partial-of-properties.js +2 -0
  55. package/lib/utils/types/prop-of.d.ts +5 -0
  56. package/lib/utils/types/prop-of.js +2 -0
  57. package/lib/utils/types/property-only.d.ts +4 -0
  58. package/lib/utils/types/property-only.js +2 -0
  59. package/lib/utils/types/recursive-partial.d.ts +3 -0
  60. package/lib/utils/types/recursive-partial.js +2 -0
  61. package/lib/utils/types/type.d.ts +4 -0
  62. package/lib/utils/types/type.js +2 -0
  63. package/package.json +52 -0
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Compares two arrays.
3
+ *
4
+ * @param {any[]} a First array to compare.
5
+ * @param {any[]} b Second array to compare.
6
+ *
7
+ * @returns {boolean} Validation result.
8
+ */
9
+ export declare const compareArrays: (a: any[], b: any[]) => boolean;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compareArrays = void 0;
4
+ /**
5
+ * Compares two arrays.
6
+ *
7
+ * @param {any[]} a First array to compare.
8
+ * @param {any[]} b Second array to compare.
9
+ *
10
+ * @returns {boolean} Validation result.
11
+ */
12
+ const compareArrays = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
13
+ exports.compareArrays = compareArrays;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns the entries of an object.
3
+ *
4
+ * @param {object} obj The object to retrieve entries.
5
+ *
6
+ * @returns {[string, any]} The entries of the object.
7
+ */
8
+ export declare const getEntries: <T extends object>(obj: T) => [[keyof T, T[keyof T]]];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntries = void 0;
4
+ /**
5
+ * Returns the entries of an object.
6
+ *
7
+ * @param {object} obj The object to retrieve entries.
8
+ *
9
+ * @returns {[string, any]} The entries of the object.
10
+ */
11
+ const getEntries = (obj) => Object.entries(obj);
12
+ exports.getEntries = getEntries;
@@ -0,0 +1,3 @@
1
+ import { compareArrays } from './compare-arrays';
2
+ import { getEntries } from './get-entries';
3
+ export { compareArrays, getEntries, };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntries = exports.compareArrays = void 0;
4
+ const compare_arrays_1 = require("./compare-arrays");
5
+ Object.defineProperty(exports, "compareArrays", { enumerable: true, get: function () { return compare_arrays_1.compareArrays; } });
6
+ const get_entries_1 = require("./get-entries");
7
+ Object.defineProperty(exports, "getEntries", { enumerable: true, get: function () { return get_entries_1.getEntries; } });
@@ -0,0 +1,3 @@
1
+ import { sortByProperties } from './sort-by-properties';
2
+ import { sortByProperty } from './sort-by-property';
3
+ export { sortByProperties, sortByProperty, };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortByProperty = exports.sortByProperties = void 0;
4
+ const sort_by_properties_1 = require("./sort-by-properties");
5
+ Object.defineProperty(exports, "sortByProperties", { enumerable: true, get: function () { return sort_by_properties_1.sortByProperties; } });
6
+ const sort_by_property_1 = require("./sort-by-property");
7
+ Object.defineProperty(exports, "sortByProperty", { enumerable: true, get: function () { return sort_by_property_1.sortByProperty; } });
@@ -0,0 +1,2 @@
1
+ import { GenericObject } from '../../types';
2
+ export declare function sortByProperties(...props: string[]): (obj1: GenericObject, obj2: GenericObject) => number;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortByProperties = void 0;
4
+ const _1 = require(".");
5
+ function sortByProperties(...props) {
6
+ return (obj1, obj2) => {
7
+ const numberOfProperties = props.length;
8
+ let result = 0;
9
+ let i = 0;
10
+ while (result === 0 && i < numberOfProperties) {
11
+ result = (0, _1.sortByProperty)(props[i])(obj1, obj2);
12
+ i++;
13
+ }
14
+ return result;
15
+ };
16
+ }
17
+ exports.sortByProperties = sortByProperties;
@@ -0,0 +1,2 @@
1
+ import { GenericObject } from '../../types';
2
+ export declare function sortByProperty(property: string): (a: GenericObject, b: GenericObject) => number;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortByProperty = void 0;
4
+ function sortByProperty(property) {
5
+ let sortOrder = 1;
6
+ if (property.startsWith('-')) {
7
+ sortOrder = -1;
8
+ property = property.substring(1);
9
+ }
10
+ return (a, b) => {
11
+ const result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
12
+ return result * sortOrder;
13
+ };
14
+ }
15
+ exports.sortByProperty = sortByProperty;
@@ -0,0 +1,4 @@
1
+ import { isFunction } from './is-function';
2
+ import { isNumber } from './is-number';
3
+ import { isObject } from './is-object';
4
+ export { isFunction, isNumber, isObject, };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isObject = exports.isNumber = exports.isFunction = void 0;
4
+ const is_function_1 = require("./is-function");
5
+ Object.defineProperty(exports, "isFunction", { enumerable: true, get: function () { return is_function_1.isFunction; } });
6
+ const is_number_1 = require("./is-number");
7
+ Object.defineProperty(exports, "isNumber", { enumerable: true, get: function () { return is_number_1.isNumber; } });
8
+ const is_object_1 = require("./is-object");
9
+ Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return is_object_1.isObject; } });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Determines if the given value is a function.
3
+ *
4
+ * @param {any} value The value to check.
5
+ *
6
+ * @returns {boolean} Validation result.
7
+ */
8
+ export declare const isFunction: (value: any) => value is (...args: any[]) => any;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFunction = void 0;
4
+ /**
5
+ * Determines if the given value is a function.
6
+ *
7
+ * @param {any} value The value to check.
8
+ *
9
+ * @returns {boolean} Validation result.
10
+ */
11
+ const isFunction = (value) => typeof value === 'function';
12
+ exports.isFunction = isFunction;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Determines if the given value is a number.
3
+ *
4
+ * @param {any} value The value to check.
5
+ *
6
+ * @returns {boolean} Validation result.
7
+ */
8
+ export declare const isNumber: (value: any) => value is number;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNumber = void 0;
4
+ /**
5
+ * Determines if the given value is a number.
6
+ *
7
+ * @param {any} value The value to check.
8
+ *
9
+ * @returns {boolean} Validation result.
10
+ */
11
+ const isNumber = (value) => typeof value === 'number';
12
+ exports.isNumber = isNumber;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Determines if the given value is an object.
3
+ *
4
+ * @param {any} value The value to check.
5
+ *
6
+ * @returns {boolean} Validation result.
7
+ */
8
+ export declare const isObject: (value: any) => value is object;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isObject = void 0;
4
+ /**
5
+ * Determines if the given value is an object.
6
+ *
7
+ * @param {any} value The value to check.
8
+ *
9
+ * @returns {boolean} Validation result.
10
+ */
11
+ const isObject = (value) => typeof value === 'object' && value !== null;
12
+ exports.isObject = isObject;
@@ -0,0 +1,3 @@
1
+ export declare type addPrefixToObject<T, P extends string> = {
2
+ [K in keyof T as K extends string ? `${P}${K}` : never]: T[K];
3
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { FlagExcludedType } from '.';
2
+ /**
3
+ * Gets the keys that are not flagged as 'never'.
4
+ */
5
+ export declare type AllowedNames<Base, Type> = FlagExcludedType<Base, Type>[keyof Base];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Transforms the type to flag all the undesired keys as 'never'.
3
+ */
4
+ export declare type FlagExcludedType<Base, Type> = {
5
+ [Key in keyof Base]: Base[Key] extends Type ? never : Key;
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export interface GenericObject {
2
+ [key: string]: any;
3
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
@@ -0,0 +1,10 @@
1
+ import { addPrefixToObject } from './add-prefix-to-object';
2
+ import { AllowedNames } from './allowed-names';
3
+ import { FlagExcludedType } from './flag-excluded-type';
4
+ import { GenericObject } from './generic-object';
5
+ import { OmitType } from './omit-type';
6
+ import { PartialOfProperties } from './partial-of-properties';
7
+ import { PropertyOnly } from './property-only';
8
+ import { PropOf } from './prop-of';
9
+ import { RecursivePartial } from './recursive-partial';
10
+ export { addPrefixToObject, AllowedNames, FlagExcludedType, GenericObject, OmitType, PartialOfProperties, PropertyOnly, PropOf, RecursivePartial, };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { AllowedNames } from '.';
2
+ /**
3
+ * Use this with a simple Pick to get the right interface, excluding the undesired type.
4
+ */
5
+ export declare type OmitType<Base, Type> = Pick<Base, AllowedNames<Base, Type>>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { PropertyOnly } from '.';
2
+ export declare type PartialOfProperties<T extends object> = Partial<PropertyOnly<T>>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { PropertyOnly } from '.';
2
+ /**
3
+ * Represents a property of a class or interface.
4
+ */
5
+ export declare type PropOf<T extends object> = keyof PropertyOnly<T>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { NonFunctionKeys } from 'utility-types';
2
+ export declare type PropertyOnly<T extends object> = {
3
+ [P in NonFunctionKeys<T>]: T[P];
4
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export declare type RecursivePartial<T> = {
2
+ [P in keyof T]?: T[P] extends (infer U)[] ? RecursivePartial<U>[] : T[P] extends object ? RecursivePartial<T[P]> : T[P];
3
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Represents a class.
3
+ */
4
+ export declare type Type<T = any> = new (...args: any[]) => T;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "querier-ts",
3
+ "version": "0.0.0",
4
+ "description": "Query tool for analysing arrays of objects",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "scripts": {
8
+ "test": "jest --config jestconfig.json",
9
+ "build": "tsc",
10
+ "format": "prettier --write \"src/*.ts\"",
11
+ "lint": "tslint -p tsconfig.json",
12
+ "prepare": "npm run build",
13
+ "prepublishOnly": "npm test && npm run lint",
14
+ "preversion": "npm run lint",
15
+ "version": "npm run format && git add -A src",
16
+ "postversion": "git push && git push --tags"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/luizfilipezs/query-ts.git"
21
+ },
22
+ "keywords": [
23
+ "query",
24
+ "data filtering"
25
+ ],
26
+ "author": {
27
+ "name": "Luiz Filipe da Silva",
28
+ "email": "filipeluiz.bs@gmail.com",
29
+ "url": "https://blogdolipe.com.br"
30
+ },
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/luizfilipezs/query-ts/issues"
34
+ },
35
+ "homepage": "https://github.com/luizfilipezs/query-ts#readme",
36
+ "devDependencies": {
37
+ "@types/jest": "^27.4.0",
38
+ "jest": "^27.5.0",
39
+ "prettier": "^2.5.1",
40
+ "ts-jest": "^27.1.3",
41
+ "tslint": "^6.1.3",
42
+ "tslint-config-prettier": "^1.18.0",
43
+ "typescript": "~4.5.2"
44
+ },
45
+ "files": [
46
+ "lib/**/*"
47
+ ],
48
+ "dependencies": {
49
+ "reflect-metadata": "^0.1.13",
50
+ "utility-types": "^3.10.0"
51
+ }
52
+ }