@leyyo/query 1.2.2 → 1.3.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.
Files changed (55) hide show
  1. package/dist/error/index.d.ts +2 -2
  2. package/dist/error/index.js +2 -18
  3. package/dist/error/index.types.js +1 -2
  4. package/dist/error/invalid-query-value.error.d.ts +3 -2
  5. package/dist/error/invalid-query-value.error.js +4 -5
  6. package/dist/field/index.d.ts +1 -1
  7. package/dist/field/index.js +1 -17
  8. package/dist/field/index.types.js +1 -2
  9. package/dist/group-by/index.d.ts +1 -1
  10. package/dist/group-by/index.js +1 -17
  11. package/dist/group-by/index.types.d.ts +1 -1
  12. package/dist/group-by/index.types.js +1 -2
  13. package/dist/index.d.ts +12 -10
  14. package/dist/index.foretell.d.ts +1 -0
  15. package/dist/index.foretell.js +17 -0
  16. package/dist/index.js +12 -26
  17. package/dist/index.loader.d.ts +1 -0
  18. package/dist/index.loader.js +12 -0
  19. package/dist/internal.d.ts +1 -0
  20. package/dist/internal.js +1 -0
  21. package/dist/operation/index.d.ts +1 -1
  22. package/dist/operation/index.js +1 -17
  23. package/dist/operation/operation-type.d.ts +7 -2
  24. package/dist/operation/operation-type.js +3 -5
  25. package/dist/order-by/index.d.ts +1 -1
  26. package/dist/order-by/index.js +1 -17
  27. package/dist/order-by/index.types.d.ts +2 -2
  28. package/dist/order-by/index.types.js +1 -2
  29. package/dist/order-type/index.d.ts +1 -0
  30. package/dist/order-type/index.js +1 -0
  31. package/dist/order-type/order-type.d.ts +7 -0
  32. package/dist/order-type/order-type.js +2 -0
  33. package/dist/pagination/index.d.ts +1 -1
  34. package/dist/pagination/index.js +1 -17
  35. package/dist/pagination/index.types.js +1 -2
  36. package/dist/parser/index.d.ts +2 -2
  37. package/dist/parser/index.js +2 -18
  38. package/dist/parser/index.types.d.ts +1 -1
  39. package/dist/parser/index.types.js +1 -2
  40. package/dist/parser/query.parser.d.ts +1 -1
  41. package/dist/parser/query.parser.js +56 -60
  42. package/dist/query/index.d.ts +1 -1
  43. package/dist/query/index.js +1 -17
  44. package/dist/query/index.types.d.ts +5 -5
  45. package/dist/query/index.types.js +1 -2
  46. package/dist/select/index.d.ts +1 -1
  47. package/dist/select/index.js +1 -17
  48. package/dist/select/index.types.d.ts +1 -1
  49. package/dist/select/index.types.js +1 -2
  50. package/dist/where/index.d.ts +1 -1
  51. package/dist/where/index.js +1 -17
  52. package/dist/where/index.types.d.ts +2 -2
  53. package/dist/where/index.types.js +1 -2
  54. package/package.json +4 -5
  55. package/dist/assets/.gitkeep +0 -0
@@ -1,2 +1,2 @@
1
- export * from './invalid-query-value.error';
2
- export * from './index.types';
1
+ export * from './invalid-query-value.error.js';
2
+ export * from './index.types.js';
@@ -1,18 +1,2 @@
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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./invalid-query-value.error"), exports);
18
- __exportStar(require("./index.types"), exports);
1
+ export * from './invalid-query-value.error.js';
2
+ export * from './index.types.js';
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,5 +1,6 @@
1
- import { QueryErrorCode } from "./index.types";
2
- export declare class InvalidQueryValueError extends Error {
1
+ import { QueryErrorCode } from "./index.types.js";
2
+ import { LeyyoError } from "@leyyo/common";
3
+ export declare class InvalidQueryValueError extends LeyyoError {
3
4
  readonly message: string;
4
5
  readonly path: string;
5
6
  constructor(code: QueryErrorCode, message: string, path: string);
@@ -1,11 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidQueryValueError = void 0;
4
- class InvalidQueryValueError extends Error {
1
+ import { LeyyoError } from "@leyyo/common";
2
+ export class InvalidQueryValueError extends LeyyoError {
3
+ message;
4
+ path;
5
5
  constructor(code, message, path) {
6
6
  super(`[${code}] ${message} at ${path}`);
7
7
  this.message = message;
8
8
  this.path = path;
9
9
  }
10
10
  }
11
- exports.InvalidQueryValueError = InvalidQueryValueError;
@@ -1 +1 @@
1
- export * from './index.types';
1
+ export * from './index.types.js';
@@ -1,17 +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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./index.types"), exports);
1
+ export * from './index.types.js';
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1 +1 @@
1
- export * from './index.types';
1
+ export * from './index.types.js';
@@ -1,17 +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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./index.types"), exports);
1
+ export * from './index.types.js';
@@ -1,4 +1,4 @@
1
- import type { FieldRaw, FieldRegular } from "../field";
1
+ import { FieldRaw, FieldRegular } from "../field/index.js";
2
2
  export type GroupByAny<K extends string> = Array<K | GroupByGivenRegular<K> | GroupByGivenRaw>;
3
3
  export type GroupByGivenRegular<K extends string> = FieldRegular<K>;
4
4
  export type GroupByGivenRaw = FieldRaw;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
- export * from './operation';
2
- export * from './error';
3
- export * from './field';
4
- export * from './group-by';
5
- export * from './order-by';
6
- export * from './pagination';
7
- export * from './parser';
8
- export * from './query';
9
- export * from './select';
10
- export * from './where';
1
+ export * from './operation/index.js';
2
+ export * from './error/index.js';
3
+ export * from './field/index.js';
4
+ export * from './group-by/index.js';
5
+ export * from './order-by/index.js';
6
+ export * from './pagination/index.js';
7
+ export * from './parser/index.js';
8
+ export * from './query/index.js';
9
+ export * from './select/index.js';
10
+ export * from './where/index.js';
11
+ export * from './index.foretell.js';
12
+ export * from './index.loader.js';
@@ -0,0 +1 @@
1
+ export declare const foretell_leyyoQuery: (() => void)[];
@@ -0,0 +1,17 @@
1
+ import { FQN } from "./internal.js";
2
+ import { errorPool, foretell_leyyoCommon, literalPool } from "@leyyo/common";
3
+ // noinspection JSUnusedGlobalSymbols
4
+ export const foretell_leyyoQuery = [
5
+ // dependencies
6
+ ...foretell_leyyoCommon,
7
+ // errors
8
+ () => errorPool.lazy(FQN, 'InvalidQueryValueError', import('./error/invalid-query-value.error.js').then(m => m.InvalidQueryValueError), { i18n: true, emit: true }),
9
+ // enums
10
+ () => literalPool.register({
11
+ name: 'OperationType',
12
+ fqn: FQN,
13
+ i18n: true,
14
+ lazyTarget: import('./operation/operation-type.js').then(m => m.OperationTypeItems),
15
+ lazyAlt: import('./operation/operation-type.js').then(m => m.OperationTypeMap),
16
+ }),
17
+ ];
package/dist/index.js CHANGED
@@ -1,26 +1,12 @@
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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./operation"), exports);
18
- __exportStar(require("./error"), exports);
19
- __exportStar(require("./field"), exports);
20
- __exportStar(require("./group-by"), exports);
21
- __exportStar(require("./order-by"), exports);
22
- __exportStar(require("./pagination"), exports);
23
- __exportStar(require("./parser"), exports);
24
- __exportStar(require("./query"), exports);
25
- __exportStar(require("./select"), exports);
26
- __exportStar(require("./where"), exports);
1
+ export * from './operation/index.js';
2
+ export * from './error/index.js';
3
+ export * from './field/index.js';
4
+ export * from './group-by/index.js';
5
+ export * from './order-by/index.js';
6
+ export * from './pagination/index.js';
7
+ export * from './parser/index.js';
8
+ export * from './query/index.js';
9
+ export * from './select/index.js';
10
+ export * from './where/index.js';
11
+ export * from './index.foretell.js';
12
+ export * from './index.loader.js';
@@ -0,0 +1 @@
1
+ export declare const loader_leyyoQuery: import("@leyyo/common").LoaderLike;
@@ -0,0 +1,12 @@
1
+ import { defineLoader, loader_leyyoCommon } from "@leyyo/common";
2
+ import { FQN } from "./internal.js";
3
+ // noinspection JSUnusedGlobalSymbols
4
+ export const loader_leyyoQuery = defineLoader(FQN,
5
+ // dependencies
6
+ ...loader_leyyoCommon,
7
+ // errors
8
+ () => import('./error/invalid-query-value.error.js').then(m => m.InvalidQueryValueError),
9
+ // enums
10
+ () => import('./operation/operation-type.js').then(m => m.OperationTypeItems),
11
+ // classes
12
+ () => import('./parser/query.parser.js').then(m => m.queryParser));
@@ -0,0 +1 @@
1
+ export declare const FQN = "leyyo.query";
@@ -0,0 +1 @@
1
+ export const FQN = 'leyyo.query';
@@ -1 +1 @@
1
- export * from './operation-type';
1
+ export * from './operation-type.js';
@@ -1,17 +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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./operation-type"), exports);
1
+ export * from './operation-type.js';
@@ -1,3 +1,8 @@
1
- export declare const ConditionTypeItems: readonly ["eq", "ne", "null", "!null", "missing", "!missing", "gt", "gte", "lt", "lte", "between", "!between", "in", "!in", "starts", "!starts", "ends", "!ends", "matches", "!matches", "contains", "!contains", "contained", "!contained", "true", "false", "includes", "!includes", "intersects", "!intersects", "exists", "!exists"];
2
- export type OperationType = typeof ConditionTypeItems[number];
1
+ declare const literals: readonly ["eq", "ne", "null", "!null", "missing", "!missing", "gt", "gte", "lt", "lte", "between", "!between", "in", "!in", "starts", "!starts", "ends", "!ends", "matches", "!matches", "contains", "!contains", "contained", "!contained", "true", "false", "includes", "!includes", "intersects", "!intersects", "exists", "!exists"];
2
+ /**
3
+ * Operation Type
4
+ * */
5
+ export type OperationType = typeof literals[number];
6
+ export declare const OperationTypeItems: ReadonlyArray<OperationType>;
3
7
  export declare const OperationTypeMap: Record<string, OperationType>;
8
+ export {};
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OperationTypeMap = exports.ConditionTypeItems = void 0;
4
- exports.ConditionTypeItems = [
1
+ const literals = [
5
2
  // all
6
3
  'eq',
7
4
  'ne',
@@ -41,8 +38,9 @@ exports.ConditionTypeItems = [
41
38
  'exists',
42
39
  '!exists',
43
40
  ];
41
+ export const OperationTypeItems = literals;
44
42
  // noinspection JSUnusedGlobalSymbols
45
- exports.OperationTypeMap = {
43
+ export const OperationTypeMap = {
46
44
  // all
47
45
  '=': 'eq',
48
46
  '==': 'eq',
@@ -1 +1 @@
1
- export * from './index.types';
1
+ export * from './index.types.js';
@@ -1,17 +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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./index.types"), exports);
1
+ export * from './index.types.js';
@@ -1,5 +1,5 @@
1
- import type { FieldRaw, FieldRegular } from "../field";
2
- export type OrderType = 'asc' | 'desc';
1
+ import { FieldRaw, FieldRegular } from "../field/index.js";
2
+ import { OrderType } from "../order-type/index.js";
3
3
  export type OrderByAny<K extends string> = K | Array<OrderByGiven<K> | K | OrderByGivenRaw> | OrderByValue<K>;
4
4
  export type OrderByValue<K extends string> = {
5
5
  [field in K]: boolean | OrderType;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './order-type.js';
@@ -0,0 +1 @@
1
+ export * from './order-type.js';
@@ -0,0 +1,7 @@
1
+ declare const literals: readonly ["asc", "desc"];
2
+ /**
3
+ * Order Type
4
+ * */
5
+ export type OrderType = typeof literals[number];
6
+ export declare const OrderTypeItems: ReadonlyArray<OrderType>;
7
+ export {};
@@ -0,0 +1,2 @@
1
+ const literals = ['asc', 'desc'];
2
+ export const OrderTypeItems = literals;
@@ -1 +1 @@
1
- export * from './index.types';
1
+ export * from './index.types.js';
@@ -1,17 +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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./index.types"), exports);
1
+ export * from './index.types.js';
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1,2 @@
1
- export * from './index.types';
2
- export * from './query.parser';
1
+ export * from './index.types.js';
2
+ export * from './query.parser.js';
@@ -1,18 +1,2 @@
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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./index.types"), exports);
18
- __exportStar(require("./query.parser"), exports);
1
+ export * from './index.types.js';
2
+ export * from './query.parser.js';
@@ -1,4 +1,4 @@
1
- import type { QueryAny, QueryRegular } from "../query";
1
+ import { QueryAny, QueryRegular } from "../query/index.js";
2
2
  import { BasicType } from "@leyyo/common";
3
3
  export interface QueryParserLike {
4
4
  exec<K extends string>(query: QueryAny<K>, availableFields: Array<K | string>, name?: string): QueryRegular<K>;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1,2 @@
1
- import type { QueryParserLike } from "./index.types";
1
+ import { QueryParserLike } from "./index.types.js";
2
2
  export declare const queryParser: QueryParserLike;
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.queryParser = void 0;
4
- const operation_1 = require("../operation");
5
- const error_1 = require("../error");
6
- const type_1 = require("@leyyo/type");
1
+ import { isEmpty, isFilledObj, isText } from "@leyyo/common";
2
+ import { OperationTypeItems, OperationTypeMap } from "../operation/index.js";
3
+ import { InvalidQueryValueError } from "../error/index.js";
7
4
  class QueryParser {
8
5
  // region private
9
6
  _error(code, message, path) {
10
- return new error_1.InvalidQueryValueError(code, message, path);
7
+ return new InvalidQueryValueError(code, message, path);
11
8
  }
12
9
  _invalid(value, path, expected, code) {
13
10
  const ex = Array.isArray(expected) ? `[${expected.join(', ')}]` : expected;
14
11
  return this._error(code, `It's expected as ${ex}, but it's type: ${typeof value}`, path);
15
12
  }
16
13
  _emptyOrInvalid(value, path, expected, empty, invalid) {
17
- if ((0, type_1.isEmpty)(value)) {
14
+ if (isEmpty(value)) {
18
15
  return this._error(empty, `It's empty`, path);
19
16
  }
20
17
  if (typeof value === 'string' && value.trim() === '') {
@@ -23,13 +20,13 @@ class QueryParser {
23
20
  return this._invalid(value, path, expected, invalid);
24
21
  }
25
22
  _asc(value, path) {
26
- if ((0, type_1.isEmpty)(value)) {
23
+ if (isEmpty(value)) {
27
24
  return true;
28
25
  }
29
26
  if (typeof value === 'boolean') {
30
27
  return value;
31
28
  }
32
- else if ((0, type_1.isText)(value)) {
29
+ else if (isText(value)) {
33
30
  if (value.toLowerCase() === 'asc') {
34
31
  return true;
35
32
  }
@@ -41,37 +38,37 @@ class QueryParser {
41
38
  throw this._invalid(value, path, ['boolean', 'string'], 'asc:invalid-type');
42
39
  }
43
40
  _field(value, path) {
44
- if ((0, type_1.isText)(value)) {
41
+ if (isText(value)) {
45
42
  return value;
46
43
  }
47
44
  throw this._emptyOrInvalid(value, path, 'string', 'field:empty', 'field:invalid');
48
45
  }
49
46
  _raw(value, path) {
50
- if ((0, type_1.isText)(value)) {
47
+ if (isText(value)) {
51
48
  return value;
52
49
  }
53
50
  throw this._emptyOrInvalid(value, path, 'string', 'raw:empty', 'raw:invalid');
54
51
  }
55
52
  _as(value, path) {
56
- if ((0, type_1.isEmpty)(value)) {
53
+ if (isEmpty(value)) {
57
54
  return undefined;
58
55
  }
59
- else if ((0, type_1.isText)(value)) {
56
+ else if (isText(value)) {
60
57
  return value;
61
58
  }
62
59
  throw this._invalid(value, path, 'string', 'as:invalid');
63
60
  }
64
61
  _operation(value, path) {
65
- if ((0, type_1.isEmpty)(value)) {
62
+ if (isEmpty(value)) {
66
63
  return 'eq';
67
64
  }
68
- else if ((0, type_1.isText)(value)) {
65
+ else if (isText(value)) {
69
66
  const key = value;
70
- if ((0, type_1.isLiteral)(key, operation_1.ConditionTypeItems)) {
67
+ if (isText(key) && OperationTypeItems.includes(key)) {
71
68
  return key;
72
69
  }
73
- if (operation_1.OperationTypeMap[key] !== undefined) {
74
- return operation_1.OperationTypeMap[key];
70
+ if (OperationTypeMap[key] !== undefined) {
71
+ return OperationTypeMap[key];
75
72
  }
76
73
  throw this._error('op:invalid-key', `It should be [@see operations], but it's value: ${value}`, path);
77
74
  }
@@ -98,7 +95,7 @@ class QueryParser {
98
95
  if (Array.isArray(value)) {
99
96
  let index = 0;
100
97
  for (const item of value) {
101
- if (!(0, type_1.isText)(item) && !(0, type_1.isNumberValid)(item) && typeof value !== 'boolean') {
98
+ if (!isText(item) && typeof value !== 'number' && typeof value !== 'boolean') {
102
99
  throw this._invalid(item, `${path}[${index}]`, ['string', 'number', 'boolean', 'array', 'number'], 'value:invalid-item');
103
100
  }
104
101
  index++;
@@ -110,10 +107,10 @@ class QueryParser {
110
107
  throw this._invalid(value, path, ['string', 'number', 'boolean', 'array', 'number'], 'value:invalid-type');
111
108
  }
112
109
  _num(value, path, min) {
113
- if ((0, type_1.isEmpty)(value)) {
110
+ if (isEmpty(value)) {
114
111
  return undefined;
115
112
  }
116
- else if ((0, type_1.isIntegerValid)(value)) {
113
+ else if (Number.isSafeInteger(value)) {
117
114
  if (value >= min) {
118
115
  return value;
119
116
  }
@@ -132,7 +129,7 @@ class QueryParser {
132
129
  // endregion private
133
130
  // region parts
134
131
  _select(given, _availableFields, _name) {
135
- if ((0, type_1.isEmpty)(given)) {
132
+ if (isEmpty(given)) {
136
133
  return { all: true };
137
134
  }
138
135
  // Cases:
@@ -151,7 +148,7 @@ class QueryParser {
151
148
  const arr = given;
152
149
  arr.forEach((item, index) => {
153
150
  // Case 2A: K
154
- if ((0, type_1.isText)(item)) {
151
+ if (isText(item)) {
155
152
  newSelect.fields.push({
156
153
  field: item,
157
154
  });
@@ -164,15 +161,15 @@ class QueryParser {
164
161
  newSelect.fields.push({ field, as, });
165
162
  }
166
163
  // Case 2C: SelectGiven<K> | SelectGivenRaw
167
- else if ((0, type_1.isObjectBare)(item)) {
164
+ else if (isFilledObj(item)) {
168
165
  let as;
169
166
  let field;
170
167
  let raw;
171
168
  const obj = item;
172
- if (!(0, type_1.isEmpty)(obj.raw)) {
169
+ if (!isEmpty(obj.raw)) {
173
170
  raw = this._raw(obj.raw, `select[${index}].raw`);
174
171
  }
175
- if (!(0, type_1.isEmpty)(obj.field)) {
172
+ if (!isEmpty(obj.field)) {
176
173
  field = this._field(obj.field, `select[${index}].field`);
177
174
  }
178
175
  this._fieldXorRaw(field, raw, `select[${index}].field`);
@@ -197,7 +194,7 @@ class QueryParser {
197
194
  return newSelect;
198
195
  }
199
196
  _where(scope, given, _availableFields, _name) {
200
- if ((0, type_1.isEmpty)(given)) {
197
+ if (isEmpty(given)) {
201
198
  return [];
202
199
  }
203
200
  // Cases:
@@ -205,7 +202,7 @@ class QueryParser {
205
202
  // 2 - Array<WhereGiven<K>|WhereGivenRaw|[K, unknown]>
206
203
  const newWhere = [];
207
204
  // case 1: WhereValue<K>
208
- if ((0, type_1.isObjectBare)(given)) {
205
+ if (isFilledObj(given)) {
209
206
  let index = 0;
210
207
  for (let [k, v] of Object.entries(given)) {
211
208
  const field = this._field(k, `${scope}(key=${index})`);
@@ -222,22 +219,22 @@ class QueryParser {
222
219
  const arr = given;
223
220
  arr.forEach((item, index) => {
224
221
  // Case 2A: WhereGiven<K>|WhereGivenRaw
225
- if ((0, type_1.isObjectBare)(item)) {
222
+ if (isFilledObj(item)) {
226
223
  let field;
227
224
  let raw;
228
225
  let op;
229
226
  let value;
230
227
  let fullRaw;
231
228
  const obj = item;
232
- if (!(0, type_1.isEmpty)(obj.raw)) {
229
+ if (!isEmpty(obj.raw)) {
233
230
  raw = this._raw(obj.raw, `${scope}[${index}].raw`);
234
231
  }
235
- if (!(0, type_1.isEmpty)(obj.field)) {
232
+ if (!isEmpty(obj.field)) {
236
233
  field = this._field(obj.field, `${scope}[${index}].field`);
237
234
  }
238
235
  this._fieldXorRaw(field, raw, `${scope}[${index}].field`);
239
236
  const whereItem = obj;
240
- if (raw && (0, type_1.isEmpty)(whereItem.op) && (0, type_1.isEmpty)(whereItem.value)) {
237
+ if (raw && isEmpty(whereItem.op) && isEmpty(whereItem.value)) {
241
238
  fullRaw = true;
242
239
  }
243
240
  op = this._operation(whereItem.op, `${scope}[${index}].op`);
@@ -269,7 +266,7 @@ class QueryParser {
269
266
  return newWhere;
270
267
  }
271
268
  _groupBy(given, _availableFields, _name) {
272
- if ((0, type_1.isEmpty)(given)) {
269
+ if (isEmpty(given)) {
273
270
  return [];
274
271
  }
275
272
  // Cases:
@@ -283,14 +280,14 @@ class QueryParser {
283
280
  const arr = given;
284
281
  arr.forEach((item, index) => {
285
282
  // Case 2A: GroupByGivenRegular<K> | GroupByGivenRaw
286
- if ((0, type_1.isObjectBare)(item)) {
283
+ if (isFilledObj(item)) {
287
284
  let field;
288
285
  let raw;
289
286
  const obj = item;
290
- if (!(0, type_1.isEmpty)(obj.raw)) {
287
+ if (!isEmpty(obj.raw)) {
291
288
  raw = this._raw(obj.raw, `groupBy[${index}].raw`);
292
289
  }
293
- if (!(0, type_1.isEmpty)(obj.field)) {
290
+ if (!isEmpty(obj.field)) {
294
291
  field = this._field(obj.field, `groupBy[${index}].field`);
295
292
  }
296
293
  this._fieldXorRaw(field, raw, `groupBy[${index}].field`);
@@ -302,7 +299,7 @@ class QueryParser {
302
299
  }
303
300
  }
304
301
  // Case 2B: K
305
- else if ((0, type_1.isText)(item)) {
302
+ else if (isText(item)) {
306
303
  newGroup.push({ field: item });
307
304
  }
308
305
  else {
@@ -317,7 +314,7 @@ class QueryParser {
317
314
  return newGroup;
318
315
  }
319
316
  _orderBy(given, _availableFields, _name) {
320
- if ((0, type_1.isEmpty)(given)) {
317
+ if (isEmpty(given)) {
321
318
  return [];
322
319
  }
323
320
  // Cases:
@@ -326,7 +323,7 @@ class QueryParser {
326
323
  // 3 - OrderByValue<K>
327
324
  const newOrder = [];
328
325
  // case 1: string as K
329
- if ((0, type_1.isText)(given)) {
326
+ if (isText(given)) {
330
327
  newOrder.push({ field: given, asc: true });
331
328
  }
332
329
  // case 2: array as Array<OrderByGiven<K>|K|OrderByGivenRaw>
@@ -337,15 +334,15 @@ class QueryParser {
337
334
  const arr = given;
338
335
  arr.forEach((item, index) => {
339
336
  // Case 2A: OrderByGiven<K>|OrderByGivenRaw
340
- if ((0, type_1.isObjectBare)(item)) {
337
+ if (isFilledObj(item)) {
341
338
  let asc;
342
339
  let field;
343
340
  let raw;
344
341
  const obj = item;
345
- if (!(0, type_1.isEmpty)(obj.raw)) {
342
+ if (!isEmpty(obj.raw)) {
346
343
  raw = this._raw(obj.raw, `orderBy[${index}].raw`);
347
344
  }
348
- if (!(0, type_1.isEmpty)(obj.field)) {
345
+ if (!isEmpty(obj.field)) {
349
346
  field = this._field(obj.field, `orderBy[${index}].field`);
350
347
  }
351
348
  this._fieldXorRaw(field, raw, `orderBy[${index}].field`);
@@ -358,7 +355,7 @@ class QueryParser {
358
355
  }
359
356
  }
360
357
  // Case 2B: K
361
- else if ((0, type_1.isText)(item)) {
358
+ else if (isText(item)) {
362
359
  newOrder.push({ field: this._field(item, ''), asc: true });
363
360
  }
364
361
  // other
@@ -368,7 +365,7 @@ class QueryParser {
368
365
  });
369
366
  }
370
367
  // case 3: {'id': true, name: true, ...} as OrderByValue<K>
371
- else if ((0, type_1.isObjectBare)(given)) {
368
+ else if (isFilledObj(given)) {
372
369
  let index = 0;
373
370
  for (let [k, v] of Object.entries(given)) {
374
371
  const field = this._field(k, `orderBy(key=${index})`);
@@ -384,8 +381,7 @@ class QueryParser {
384
381
  return newOrder;
385
382
  }
386
383
  _pagination(given, _name) {
387
- var _a;
388
- if ((0, type_1.isEmpty)(given)) {
384
+ if (isEmpty(given)) {
389
385
  return {};
390
386
  }
391
387
  // Case 1: PaginationLiteral
@@ -399,16 +395,16 @@ class QueryParser {
399
395
  };
400
396
  }
401
397
  // Case 2: PaginationPage | PaginationLimit
402
- else if ((0, type_1.isObjectBare)(given)) {
398
+ else if (isFilledObj(given)) {
403
399
  if (Object.keys(given).length < 1) {
404
400
  return {};
405
401
  }
406
402
  const obj = given;
407
- if (!(0, type_1.isEmpty)(obj.page)) {
403
+ if (!isEmpty(obj.page)) {
408
404
  const page = this._num(obj.page, `pagination.page`, 1);
409
- const size = (_a = this._num(obj.size, `pagination.size`, 1)) !== null && _a !== void 0 ? _a : 50;
405
+ const size = this._num(obj.size, `pagination.size`, 1) ?? 50;
410
406
  ['limit', 'offset'].forEach(f => {
411
- if (!(0, type_1.isEmpty)(given[f])) {
407
+ if (!isEmpty(given[f])) {
412
408
  throw this._error('page:conflict', 'If you give page; limit and offset can not be used anymore', `pagination.page`);
413
409
  }
414
410
  });
@@ -417,9 +413,9 @@ class QueryParser {
417
413
  offset: (page - 1) * size
418
414
  };
419
415
  }
420
- if (!(0, type_1.isEmpty)(obj.limit)) {
416
+ if (!isEmpty(obj.limit)) {
421
417
  ['page', 'size'].forEach(f => {
422
- if (!(0, type_1.isEmpty)(obj[f])) {
418
+ if (!isEmpty(obj[f])) {
423
419
  throw this._error('limit:conflict', 'If you give limit; page and size can not be used anymore', `pagination.limit`);
424
420
  }
425
421
  });
@@ -435,14 +431,14 @@ class QueryParser {
435
431
  // endregion parts
436
432
  exec(query, availableFields, name) {
437
433
  return {
438
- select: this._select(query === null || query === void 0 ? void 0 : query.select, availableFields, name),
439
- where: this._where('where', query === null || query === void 0 ? void 0 : query.where, availableFields, name),
440
- having: this._where('having', query === null || query === void 0 ? void 0 : query.having, availableFields, name),
441
- groupBy: this._groupBy(query === null || query === void 0 ? void 0 : query.groupBy, availableFields, name),
442
- orderBy: this._orderBy(query === null || query === void 0 ? void 0 : query.orderBy, availableFields, name),
443
- pagination: this._pagination(query === null || query === void 0 ? void 0 : query.pagination, name),
434
+ select: this._select(query?.select, availableFields, name),
435
+ where: this._where('where', query?.where, availableFields, name),
436
+ having: this._where('having', query?.having, availableFields, name),
437
+ groupBy: this._groupBy(query?.groupBy, availableFields, name),
438
+ orderBy: this._orderBy(query?.orderBy, availableFields, name),
439
+ pagination: this._pagination(query?.pagination, name),
444
440
  };
445
441
  }
446
442
  }
447
443
  // noinspection JSUnusedGlobalSymbols
448
- exports.queryParser = new QueryParser();
444
+ export const queryParser = new QueryParser();
@@ -1 +1 @@
1
- export * from './index.types';
1
+ export * from './index.types.js';
@@ -1,17 +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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./index.types"), exports);
1
+ export * from './index.types.js';
@@ -1,8 +1,8 @@
1
- import type { Select, SelectAny } from "../select";
2
- import type { Where, WhereAny } from "../where";
3
- import type { GroupBy, GroupByAny } from "../group-by";
4
- import type { OrderBy, OrderByAny } from "../order-by";
5
- import type { PaginationAny, PaginationLimit } from "../pagination";
1
+ import { Select, SelectAny } from "../select/index.js";
2
+ import { Where, WhereAny } from "../where/index.js";
3
+ import { GroupBy, GroupByAny } from "../group-by/index.js";
4
+ import { OrderBy, OrderByAny } from "../order-by/index.js";
5
+ import { PaginationAny, PaginationLimit } from "../pagination/index.js";
6
6
  export interface QueryAny<K extends string> {
7
7
  select?: SelectAny<K>;
8
8
  where?: WhereAny<K>;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1 +1 @@
1
- export * from './index.types';
1
+ export * from './index.types.js';
@@ -1,17 +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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./index.types"), exports);
1
+ export * from './index.types.js';
@@ -1,4 +1,4 @@
1
- import type { FieldAs, FieldRaw, FieldRegular } from "../field";
1
+ import { FieldAs, FieldRaw, FieldRegular } from "../field/index.js";
2
2
  export type SelectAny<K extends string> = '*' | Array<K | [K, string] | SelectGiven<K> | SelectGivenRaw>;
3
3
  export type SelectGiven<K extends string> = FieldRegular<K> & FieldAs;
4
4
  export type SelectGivenRaw = FieldRaw & FieldAs;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1 +1 @@
1
- export * from './index.types';
1
+ export * from './index.types.js';
@@ -1,17 +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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./index.types"), exports);
1
+ export * from './index.types.js';
@@ -1,5 +1,5 @@
1
- import type { OperationType } from "../operation";
2
- import type { FieldRaw, FieldRegular } from "../field";
1
+ import { OperationType } from "../operation/index.js";
2
+ import { FieldRaw, FieldRegular } from "../field/index.js";
3
3
  export type WhereValue<K extends string> = {
4
4
  [P in K]: unknown;
5
5
  };
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leyyo/query",
3
- "version": "1.2.2",
3
+ "version": "1.3.3",
4
4
  "description": "Query common component",
5
5
  "keywords": [
6
6
  "Query"
@@ -19,13 +19,13 @@
19
19
  "email": "mustafayelmer@gmail.com"
20
20
  },
21
21
  "main": "dist/index.js",
22
- "type": "commonjs",
22
+ "type": "module",
23
23
  "scripts": {
24
24
  "clear": "rimraf dist && rimraf coverage",
25
25
  "clear:nm": "rimraf node_modules && npm run clear",
26
26
  "lint": "eslint src/**/*.ts --quiet",
27
27
  "lint:verbose": "eslint src/**/*.ts",
28
- "asset": "node -r ts-node/register commands/assets.ts",
28
+ "asset": "node -r ts-node/register commands/assets.js",
29
29
  "build": "npm run clear && tsc && npm run asset",
30
30
  "test": "jest --config=jest.json --detectOpenHandles",
31
31
  "coverage": "rimraf coverage && jest --config=jest.json --coverage --coverageDirectory=coverage",
@@ -66,7 +66,6 @@
66
66
  }
67
67
  },
68
68
  "dependencies": {
69
- "@leyyo/common": "^1.2.1",
70
- "@leyyo/type": "^1.1.1"
69
+ "@leyyo/common": "^1.3.10"
71
70
  }
72
71
  }
File without changes