@leyyo/query 1.0.3 → 1.2.1

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.
@@ -1 +1 @@
1
- export type QueryErrorCode = 'xxx' | 'field:invalid' | 'field:empty' | 'field:raw-both' | 'field:raw-none' | 'as:invalid' | 'raw:invalid' | 'raw:empty' | 'eq:invalid-key' | 'eq:invalid-type' | 'asc:invalid-key' | 'asc:invalid-type' | 'value:invalid-type' | 'value:invalid-item' | 'integer:invalid' | 'integer:min' | 'select:item' | 'select:body' | 'where:item' | 'where:body' | 'having:item' | 'having:body' | 'groupBy:item' | 'groupBy:body' | 'orderBy:item' | 'orderBy:body' | 'page:conflict' | 'limit:conflict' | 'pagination:invalid-key' | 'pagination:invalid-type';
1
+ export type QueryErrorCode = 'xxx' | 'field:invalid' | 'field:empty' | 'field:raw-both' | 'field:raw-none' | 'as:invalid' | 'raw:invalid' | 'raw:empty' | 'op:invalid-key' | 'op:invalid-type' | 'asc:invalid-key' | 'asc:invalid-type' | 'value:invalid-type' | 'value:invalid-item' | 'integer:invalid' | 'integer:min' | 'select:item' | 'select:body' | 'where:item' | 'where:body' | 'having:item' | 'having:body' | 'groupBy:item' | 'groupBy:body' | 'orderBy:item' | 'orderBy:body' | 'page:conflict' | 'limit:conflict' | 'pagination:invalid-key' | 'pagination:invalid-type';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './condition';
1
+ export * from './operation';
2
2
  export * from './error';
3
3
  export * from './field';
4
4
  export * from './group-by';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./condition"), exports);
17
+ __exportStar(require("./operation"), exports);
18
18
  __exportStar(require("./error"), exports);
19
19
  __exportStar(require("./field"), exports);
20
20
  __exportStar(require("./group-by"), exports);
@@ -0,0 +1 @@
1
+ export * from './operation-type';
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./condition-type"), exports);
17
+ __exportStar(require("./operation-type"), exports);
@@ -0,0 +1,3 @@
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];
3
+ export declare const OperationTypeMap: Record<string, OperationType>;
@@ -1,26 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConditionTypeMap = exports.ConditionTypeItems = void 0;
3
+ exports.OperationTypeMap = exports.ConditionTypeItems = void 0;
4
4
  exports.ConditionTypeItems = [
5
5
  // all
6
- '==',
7
- '!=',
6
+ 'eq',
7
+ 'ne',
8
8
  'null',
9
9
  '!null',
10
+ 'missing',
11
+ '!missing',
10
12
  // string, number
11
- '>',
12
- '>=',
13
- '<',
14
- '<=',
13
+ 'gt',
14
+ 'gte',
15
+ 'lt',
16
+ 'lte',
15
17
  'between',
16
18
  '!between',
17
19
  'in',
18
20
  '!in',
19
21
  // string
20
- '^',
21
- '!^',
22
- '$',
23
- '!$',
22
+ 'starts',
23
+ '!starts',
24
+ 'ends',
25
+ '!ends',
24
26
  'matches',
25
27
  '!matches',
26
28
  'contains', // left includes right
@@ -40,32 +42,41 @@ exports.ConditionTypeItems = [
40
42
  '!exists',
41
43
  ];
42
44
  // noinspection JSUnusedGlobalSymbols
43
- exports.ConditionTypeMap = {
45
+ exports.OperationTypeMap = {
44
46
  // all
45
- 'eq': '==',
46
- '=': '==',
47
- 'equals': '==',
48
- 'equal': '==',
49
- 'ne': '!=',
50
- '<>': '!=',
51
- 'not-equals': '!=',
52
- 'not-equal': '!=',
47
+ '=': 'eq',
48
+ '==': 'eq',
49
+ 'equals': 'eq',
50
+ 'equal': 'eq',
51
+ '!equals': 'ne',
52
+ '!equal': 'ne',
53
+ '!=': 'ne',
54
+ '<>': 'ne',
55
+ 'not-equals': 'ne',
56
+ 'not-equal': 'ne',
53
57
  'is-null': 'null',
54
58
  '!': 'null',
55
59
  'nil': 'null',
56
60
  '!!': '!null',
57
61
  'not-null': '!null',
62
+ 'is-missing': 'missing',
63
+ 'is-undefined': 'missing',
64
+ 'undefined': 'missing',
65
+ 'not-missing': '!missing',
66
+ 'not-undefined': '!missing',
67
+ 'defined': '!missing',
58
68
  // string, number
59
- 'greater-than': '>',
60
- 'gt': '>',
61
- 'greater-than-or-equals': '>=',
62
- 'gte': '>=',
63
- '=>': '>=',
64
- 'less-than': '<',
65
- 'lt': '<',
66
- 'less-than-or-equals': '<=',
67
- '=<': '<=',
68
- 'lte': '<=',
69
+ 'greater-than': 'gt',
70
+ '>': 'gt',
71
+ 'greater-than-or-equals': 'gte',
72
+ '>=': 'gte',
73
+ '=>': 'gte',
74
+ 'less-than': 'lt',
75
+ 'less': 'lt',
76
+ '<': 'lt',
77
+ 'less-than-or-equals': 'lte',
78
+ '=<': 'lte',
79
+ '<=': 'lte',
69
80
  '()': 'between',
70
81
  'not-between': '!between',
71
82
  ')(': '!between',
@@ -73,30 +84,29 @@ exports.ConditionTypeMap = {
73
84
  '][': '!in',
74
85
  'not-in': '!in',
75
86
  // string
76
- 'starts-with': '^',
77
- 'start-with': '^',
78
- 'starts': '^',
79
- 'start': '^',
80
- 'not-starts-with': '!^',
81
- 'not-start-with': '!^',
82
- 'not-starts': '!^',
83
- 'not-start': '!^',
84
- '!starts-with': '!^',
85
- '!start-with': '!^',
86
- '!starts': '!^',
87
- '!start': '!^',
88
- 'ends-with': '$',
89
- 'end-with': '$',
90
- 'ends': '$',
91
- 'end': '$',
92
- 'not-end-with': '!$',
93
- 'not-ends': '!$',
94
- 'not-end': '!$',
95
- '!$': '!$',
96
- '!ends-with': '!$',
97
- '!end-with': '!$',
98
- '!ends': '!$',
99
- '!end': '!$',
87
+ 'starts-with': 'starts',
88
+ 'start-with': 'starts',
89
+ '^': 'starts',
90
+ 'start': 'starts',
91
+ 'not-starts-with': '!starts',
92
+ 'not-start-with': '!starts',
93
+ 'not-starts': '!starts',
94
+ 'not-start': '!starts',
95
+ '!starts-with': '!starts',
96
+ '!start-with': '!starts',
97
+ '!^': '!starts',
98
+ '!start': '!starts',
99
+ 'ends-with': 'ends',
100
+ 'end-with': 'ends',
101
+ '$': 'ends',
102
+ 'end': 'ends',
103
+ 'not-end-with': '!ends',
104
+ 'not-ends': '!ends',
105
+ 'not-end': '!ends',
106
+ '!$': '!ends',
107
+ '!ends-with': '!ends',
108
+ '!end-with': '!ends',
109
+ '!end': '!ends',
100
110
  'match': 'matches',
101
111
  'not-matches': '!matches',
102
112
  'not-match': '!matches',
@@ -114,10 +124,10 @@ exports.ConditionTypeMap = {
114
124
  '!like': '!contains',
115
125
  // boolean
116
126
  'yes': 'true',
117
- 'on': 'true',
118
- 'ok': 'true',
119
127
  'no': 'false',
128
+ 'on': 'true',
120
129
  'off': 'false',
130
+ 'ok': 'true',
121
131
  'none': 'false',
122
132
  // array object
123
133
  'include': 'includes',
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.queryParser = void 0;
4
- const common_1 = require("@leyyo/common");
5
- const condition_1 = require("../condition");
4
+ const operation_1 = require("../operation");
6
5
  const error_1 = require("../error");
6
+ const type_1 = require("@leyyo/type");
7
7
  class QueryParser {
8
8
  // region private
9
9
  _error(code, message, path) {
@@ -14,7 +14,7 @@ class QueryParser {
14
14
  return this._error(code, `It's expected as ${ex}, but it's type: ${typeof value}`, path);
15
15
  }
16
16
  _emptyOrInvalid(value, path, expected, empty, invalid) {
17
- if (common_1.$is.empty(value)) {
17
+ if ((0, type_1.isEmpty)(value)) {
18
18
  return this._error(empty, `It's empty`, path);
19
19
  }
20
20
  if (typeof value === 'string' && value.trim() === '') {
@@ -23,13 +23,13 @@ class QueryParser {
23
23
  return this._invalid(value, path, expected, invalid);
24
24
  }
25
25
  _asc(value, path) {
26
- if (common_1.$is.empty(value)) {
26
+ if ((0, type_1.isEmpty)(value)) {
27
27
  return true;
28
28
  }
29
- if (common_1.$is.boolean(value)) {
29
+ if (typeof value === 'boolean') {
30
30
  return value;
31
31
  }
32
- else if (common_1.$is.text(value)) {
32
+ else if ((0, type_1.isText)(value)) {
33
33
  if (value.toLowerCase() === 'asc') {
34
34
  return true;
35
35
  }
@@ -41,41 +41,41 @@ class QueryParser {
41
41
  throw this._invalid(value, path, ['boolean', 'string'], 'asc:invalid-type');
42
42
  }
43
43
  _field(value, path) {
44
- if (common_1.$is.text(value)) {
44
+ if ((0, type_1.isText)(value)) {
45
45
  return value;
46
46
  }
47
47
  throw this._emptyOrInvalid(value, path, 'string', 'field:empty', 'field:invalid');
48
48
  }
49
49
  _raw(value, path) {
50
- if (common_1.$is.text(value)) {
50
+ if ((0, type_1.isText)(value)) {
51
51
  return value;
52
52
  }
53
53
  throw this._emptyOrInvalid(value, path, 'string', 'raw:empty', 'raw:invalid');
54
54
  }
55
55
  _as(value, path) {
56
- if (common_1.$is.empty(value)) {
56
+ if ((0, type_1.isEmpty)(value)) {
57
57
  return undefined;
58
58
  }
59
- else if (common_1.$is.text(value)) {
59
+ else if ((0, type_1.isText)(value)) {
60
60
  return value;
61
61
  }
62
62
  throw this._invalid(value, path, 'string', 'as:invalid');
63
63
  }
64
- _condition(value, path) {
65
- if (common_1.$is.empty(value)) {
66
- return '==';
64
+ _operation(value, path) {
65
+ if ((0, type_1.isEmpty)(value)) {
66
+ return 'eq';
67
67
  }
68
- else if (common_1.$is.text(value)) {
68
+ else if ((0, type_1.isText)(value)) {
69
69
  const key = value;
70
- if (common_1.$is.literal(key, condition_1.ConditionTypeItems)) {
70
+ if ((0, type_1.isLiteral)(key, operation_1.ConditionTypeItems)) {
71
71
  return key;
72
72
  }
73
- if (condition_1.ConditionTypeMap[key] !== undefined) {
74
- return condition_1.ConditionTypeMap[key];
73
+ if (operation_1.OperationTypeMap[key] !== undefined) {
74
+ return operation_1.OperationTypeMap[key];
75
75
  }
76
- throw this._error('eq:invalid-key', `It should be [@see equalities], but it's value: ${value}`, path);
76
+ throw this._error('op:invalid-key', `It should be [@see operations], but it's value: ${value}`, path);
77
77
  }
78
- throw this._invalid(value, path, 'string', 'eq:invalid-type');
78
+ throw this._invalid(value, path, 'string', 'op:invalid-type');
79
79
  }
80
80
  _value(value, path) {
81
81
  if (value === undefined) {
@@ -98,7 +98,7 @@ class QueryParser {
98
98
  if (Array.isArray(value)) {
99
99
  let index = 0;
100
100
  for (const item of value) {
101
- if (!common_1.$is.text(item) && !common_1.$is.number(item) && !common_1.$is.boolean(value)) {
101
+ if (!(0, type_1.isText)(item) && !(0, type_1.isNumberValid)(item) && typeof value !== 'boolean') {
102
102
  throw this._invalid(item, `${path}[${index}]`, ['string', 'number', 'boolean', 'array', 'number'], 'value:invalid-item');
103
103
  }
104
104
  index++;
@@ -110,10 +110,10 @@ class QueryParser {
110
110
  throw this._invalid(value, path, ['string', 'number', 'boolean', 'array', 'number'], 'value:invalid-type');
111
111
  }
112
112
  _num(value, path, min) {
113
- if (common_1.$is.empty(value)) {
113
+ if ((0, type_1.isEmpty)(value)) {
114
114
  return undefined;
115
115
  }
116
- else if (common_1.$is.integer(value)) {
116
+ else if ((0, type_1.isIntegerValid)(value)) {
117
117
  if (value >= min) {
118
118
  return value;
119
119
  }
@@ -132,27 +132,27 @@ class QueryParser {
132
132
  // endregion private
133
133
  // region parts
134
134
  _select(given, _availableFields, _name) {
135
- if (common_1.$is.empty(given)) {
136
- return true;
135
+ if ((0, type_1.isEmpty)(given)) {
136
+ return { all: true };
137
137
  }
138
138
  // Cases:
139
139
  // 1 - '*'
140
140
  // 2 - Array<K | [K, string] | SelectGiven<K> | SelectGivenRaw>
141
141
  // case 1: string as K
142
142
  if (given === '*') {
143
- return true;
143
+ return { all: true };
144
144
  }
145
- const newSelect = [];
145
+ const newSelect = { fields: [] };
146
146
  // case 2: Array<K | [K, string] | SelectGiven<K> | SelectGivenRaw>
147
147
  if (Array.isArray(given)) {
148
148
  if (given.length < 1) {
149
- return true;
149
+ return { all: true };
150
150
  }
151
151
  const arr = given;
152
152
  arr.forEach((item, index) => {
153
153
  // Case 2A: K
154
- if (common_1.$is.text(item)) {
155
- newSelect.push({
154
+ if ((0, type_1.isText)(item)) {
155
+ newSelect.fields.push({
156
156
  field: item,
157
157
  });
158
158
  }
@@ -161,27 +161,27 @@ class QueryParser {
161
161
  let [field, as] = item;
162
162
  field = this._field(field, `select[${index}][0]`);
163
163
  as = this._as(as, `select[${index}][1]`);
164
- newSelect.push({ field, as, });
164
+ newSelect.fields.push({ field, as, });
165
165
  }
166
166
  // Case 2C: SelectGiven<K> | SelectGivenRaw
167
- else if (common_1.$is.object(item)) {
167
+ else if ((0, type_1.isObjectBare)(item)) {
168
168
  let as;
169
169
  let field;
170
170
  let raw;
171
171
  const obj = item;
172
- if (!common_1.$is.empty(obj.raw)) {
172
+ if (!(0, type_1.isEmpty)(obj.raw)) {
173
173
  raw = this._raw(obj.raw, `select[${index}].raw`);
174
174
  }
175
- if (!common_1.$is.empty(obj.field)) {
175
+ if (!(0, type_1.isEmpty)(obj.field)) {
176
176
  field = this._field(obj.field, `select[${index}].field`);
177
177
  }
178
178
  this._fieldXorRaw(field, raw, `select[${index}].field`);
179
179
  as = this._as(obj.as, `select[${index}].as`);
180
180
  if (field) {
181
- newSelect.push({ field, as });
181
+ newSelect.fields.push({ field, as });
182
182
  }
183
183
  else {
184
- newSelect.push({ raw, as });
184
+ newSelect.fields.push({ raw, as });
185
185
  }
186
186
  }
187
187
  // other
@@ -197,7 +197,7 @@ class QueryParser {
197
197
  return newSelect;
198
198
  }
199
199
  _where(scope, given, _availableFields, _name) {
200
- if (common_1.$is.empty(given)) {
200
+ if ((0, type_1.isEmpty)(given)) {
201
201
  return [];
202
202
  }
203
203
  // Cases:
@@ -205,12 +205,12 @@ class QueryParser {
205
205
  // 2 - Array<WhereGiven<K>|WhereGivenRaw|[K, unknown]>
206
206
  const newWhere = [];
207
207
  // case 1: WhereValue<K>
208
- if (common_1.$is.object(given)) {
208
+ if ((0, type_1.isObjectBare)(given)) {
209
209
  let index = 0;
210
210
  for (let [k, v] of Object.entries(given)) {
211
211
  const field = this._field(k, `${scope}(key=${index})`);
212
212
  const value = this._value(v, `${scope}.${field}`);
213
- newWhere.push({ field, value, eq: '==' });
213
+ newWhere.push({ field, value, op: 'eq' });
214
214
  index++;
215
215
  }
216
216
  }
@@ -222,31 +222,31 @@ class QueryParser {
222
222
  const arr = given;
223
223
  arr.forEach((item, index) => {
224
224
  // Case 2A: WhereGiven<K>|WhereGivenRaw
225
- if (common_1.$is.object(item)) {
225
+ if ((0, type_1.isObjectBare)(item)) {
226
226
  let field;
227
227
  let raw;
228
- let eq;
228
+ let op;
229
229
  let value;
230
230
  let fullRaw;
231
231
  const obj = item;
232
- if (!common_1.$is.empty(obj.raw)) {
232
+ if (!(0, type_1.isEmpty)(obj.raw)) {
233
233
  raw = this._raw(obj.raw, `${scope}[${index}].raw`);
234
234
  }
235
- if (!common_1.$is.empty(obj.field)) {
235
+ if (!(0, type_1.isEmpty)(obj.field)) {
236
236
  field = this._field(obj.field, `${scope}[${index}].field`);
237
237
  }
238
238
  this._fieldXorRaw(field, raw, `${scope}[${index}].field`);
239
239
  const whereItem = obj;
240
- if (raw && common_1.$is.empty(whereItem.eq) && common_1.$is.empty(whereItem.value)) {
240
+ if (raw && (0, type_1.isEmpty)(whereItem.op) && (0, type_1.isEmpty)(whereItem.value)) {
241
241
  fullRaw = true;
242
242
  }
243
- eq = this._condition(whereItem.eq, `${scope}[${index}].eq`);
243
+ op = this._operation(whereItem.op, `${scope}[${index}].op`);
244
244
  value = this._value(whereItem.value, `${scope}[${index}].value`);
245
245
  if (field) {
246
- newWhere.push({ field, eq, value });
246
+ newWhere.push({ field, op, value });
247
247
  }
248
248
  else {
249
- newWhere.push({ raw, eq, value, fullRaw });
249
+ newWhere.push({ raw, op, value, fullRaw });
250
250
  }
251
251
  }
252
252
  // Case 2B: |[K, unknown]
@@ -255,7 +255,7 @@ class QueryParser {
255
255
  let value;
256
256
  field = this._field(item[0], `${scope}[${index}][0]`);
257
257
  value = this._value(item[1], `${scope}[${index}][1]`);
258
- newWhere.push({ field, value, eq: '==' });
258
+ newWhere.push({ field, value, op: 'eq' });
259
259
  }
260
260
  else {
261
261
  throw this._invalid(item, `${scope}[${index}]`, ['object', 'array'], (scope === 'where') ? 'where:item' : 'having:item');
@@ -269,7 +269,7 @@ class QueryParser {
269
269
  return newWhere;
270
270
  }
271
271
  _groupBy(given, _availableFields, _name) {
272
- if (common_1.$is.empty(given)) {
272
+ if ((0, type_1.isEmpty)(given)) {
273
273
  return [];
274
274
  }
275
275
  // Cases:
@@ -283,14 +283,14 @@ class QueryParser {
283
283
  const arr = given;
284
284
  arr.forEach((item, index) => {
285
285
  // Case 2A: GroupByGivenRegular<K> | GroupByGivenRaw
286
- if (common_1.$is.object(item)) {
286
+ if ((0, type_1.isObjectBare)(item)) {
287
287
  let field;
288
288
  let raw;
289
289
  const obj = item;
290
- if (!common_1.$is.empty(obj.raw)) {
290
+ if (!(0, type_1.isEmpty)(obj.raw)) {
291
291
  raw = this._raw(obj.raw, `groupBy[${index}].raw`);
292
292
  }
293
- if (!common_1.$is.empty(obj.field)) {
293
+ if (!(0, type_1.isEmpty)(obj.field)) {
294
294
  field = this._field(obj.field, `groupBy[${index}].field`);
295
295
  }
296
296
  this._fieldXorRaw(field, raw, `groupBy[${index}].field`);
@@ -302,7 +302,7 @@ class QueryParser {
302
302
  }
303
303
  }
304
304
  // Case 2B: K
305
- else if (common_1.$is.text(item)) {
305
+ else if ((0, type_1.isText)(item)) {
306
306
  newGroup.push({ field: item });
307
307
  }
308
308
  else {
@@ -317,7 +317,7 @@ class QueryParser {
317
317
  return newGroup;
318
318
  }
319
319
  _orderBy(given, _availableFields, _name) {
320
- if (common_1.$is.empty(given)) {
320
+ if ((0, type_1.isEmpty)(given)) {
321
321
  return [];
322
322
  }
323
323
  // Cases:
@@ -326,7 +326,7 @@ class QueryParser {
326
326
  // 3 - OrderByValue<K>
327
327
  const newOrder = [];
328
328
  // case 1: string as K
329
- if (common_1.$is.text(given)) {
329
+ if ((0, type_1.isText)(given)) {
330
330
  newOrder.push({ field: given, asc: true });
331
331
  }
332
332
  // case 2: array as Array<OrderByGiven<K>|K|OrderByGivenRaw>
@@ -337,15 +337,15 @@ class QueryParser {
337
337
  const arr = given;
338
338
  arr.forEach((item, index) => {
339
339
  // Case 2A: OrderByGiven<K>|OrderByGivenRaw
340
- if (common_1.$is.object(item)) {
340
+ if ((0, type_1.isObjectBare)(item)) {
341
341
  let asc;
342
342
  let field;
343
343
  let raw;
344
344
  const obj = item;
345
- if (!common_1.$is.empty(obj.raw)) {
345
+ if (!(0, type_1.isEmpty)(obj.raw)) {
346
346
  raw = this._raw(obj.raw, `orderBy[${index}].raw`);
347
347
  }
348
- if (!common_1.$is.empty(obj.field)) {
348
+ if (!(0, type_1.isEmpty)(obj.field)) {
349
349
  field = this._field(obj.field, `orderBy[${index}].field`);
350
350
  }
351
351
  this._fieldXorRaw(field, raw, `orderBy[${index}].field`);
@@ -358,7 +358,7 @@ class QueryParser {
358
358
  }
359
359
  }
360
360
  // Case 2B: K
361
- else if (common_1.$is.text(item)) {
361
+ else if ((0, type_1.isText)(item)) {
362
362
  newOrder.push({ field: this._field(item, ''), asc: true });
363
363
  }
364
364
  // other
@@ -368,7 +368,7 @@ class QueryParser {
368
368
  });
369
369
  }
370
370
  // case 3: {'id': true, name: true, ...} as OrderByValue<K>
371
- else if (common_1.$is.object(given)) {
371
+ else if ((0, type_1.isObjectBare)(given)) {
372
372
  let index = 0;
373
373
  for (let [k, v] of Object.entries(given)) {
374
374
  const field = this._field(k, `orderBy(key=${index})`);
@@ -385,7 +385,7 @@ class QueryParser {
385
385
  }
386
386
  _pagination(given, _name) {
387
387
  var _a;
388
- if (common_1.$is.empty(given)) {
388
+ if ((0, type_1.isEmpty)(given)) {
389
389
  return {};
390
390
  }
391
391
  // Case 1: PaginationLiteral
@@ -399,16 +399,16 @@ class QueryParser {
399
399
  };
400
400
  }
401
401
  // Case 2: PaginationPage | PaginationLimit
402
- else if (common_1.$is.object(given)) {
402
+ else if ((0, type_1.isObjectBare)(given)) {
403
403
  if (Object.keys(given).length < 1) {
404
404
  return {};
405
405
  }
406
406
  const obj = given;
407
- if (!common_1.$is.empty(obj.page)) {
407
+ if (!(0, type_1.isEmpty)(obj.page)) {
408
408
  const page = this._num(obj.page, `pagination.page`, 1);
409
409
  const size = (_a = this._num(obj.size, `pagination.size`, 1)) !== null && _a !== void 0 ? _a : 50;
410
410
  ['limit', 'offset'].forEach(f => {
411
- if (!common_1.$is.empty(given[f])) {
411
+ if (!(0, type_1.isEmpty)(given[f])) {
412
412
  throw this._error('page:conflict', 'If you give page; limit and offset can not be used anymore', `pagination.page`);
413
413
  }
414
414
  });
@@ -417,9 +417,9 @@ class QueryParser {
417
417
  offset: (page - 1) * size
418
418
  };
419
419
  }
420
- if (!common_1.$is.empty(obj.limit)) {
420
+ if (!(0, type_1.isEmpty)(obj.limit)) {
421
421
  ['page', 'size'].forEach(f => {
422
- if (!common_1.$is.empty(obj[f])) {
422
+ if (!(0, type_1.isEmpty)(obj[f])) {
423
423
  throw this._error('limit:conflict', 'If you give limit; page and size can not be used anymore', `pagination.limit`);
424
424
  }
425
425
  });
@@ -2,6 +2,9 @@ import type { FieldAs, FieldRaw, FieldRegular } from "../field";
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;
5
- export type Select<K extends string> = true | Array<SelectItemRegular<K> | SelectItemRaw>;
5
+ export interface Select<K extends string> {
6
+ all?: true;
7
+ fields?: Array<SelectItemRegular<K> | SelectItemRaw>;
8
+ }
6
9
  export type SelectItemRegular<K extends string> = FieldRegular<K> & FieldAs;
7
10
  export type SelectItemRaw = FieldRaw & FieldAs;
@@ -1,11 +1,11 @@
1
- import type { ConditionType } from "../condition";
1
+ import type { OperationType } from "../operation";
2
2
  import type { FieldRaw, FieldRegular } from "../field";
3
3
  export type WhereValue<K extends string> = {
4
4
  [P in K]: unknown;
5
5
  };
6
6
  export type WhereAny<K extends string> = WhereValue<K> | Array<WhereGiven<K> | WhereGivenRaw | [K, unknown]>;
7
7
  export interface WhereGivenCondition {
8
- eq: string | ConditionType;
8
+ op: string | OperationType;
9
9
  value?: unknown;
10
10
  }
11
11
  export type WhereGiven<K extends string> = FieldRegular<K> & WhereGivenCondition;
@@ -15,6 +15,6 @@ export type WhereItemRegular<K extends string> = FieldRegular<K> & WhereConditio
15
15
  export type WhereItemRaw = FieldRaw & WhereCondition;
16
16
  export interface WhereCondition {
17
17
  fullRaw?: true;
18
- eq?: ConditionType;
18
+ op?: OperationType;
19
19
  value?: unknown;
20
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leyyo/query",
3
- "version": "1.0.3",
3
+ "version": "1.2.1",
4
4
  "description": "Query common component",
5
5
  "keywords": [
6
6
  "Query"
@@ -66,6 +66,7 @@
66
66
  }
67
67
  },
68
68
  "dependencies": {
69
- "@leyyo/common": "^1.0.13"
69
+ "@leyyo/common": "^1.2.1",
70
+ "@leyyo/type": "^1.1.1"
70
71
  }
71
72
  }
@@ -1,3 +0,0 @@
1
- export declare const ConditionTypeItems: readonly ["==", "!=", "null", "!null", ">", ">=", "<", "<=", "between", "!between", "in", "!in", "^", "!^", "$", "!$", "matches", "!matches", "contains", "!contains", "contained", "!contained", "true", "false", "includes", "!includes", "intersects", "!intersects", "exists", "!exists"];
2
- export type ConditionType = typeof ConditionTypeItems[number];
3
- export declare const ConditionTypeMap: Record<string, ConditionType>;
@@ -1 +0,0 @@
1
- export * from './condition-type';