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