@fibery/expression-utils 1.1.4 → 1.1.5

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.
@@ -12,7 +12,8 @@ const getEntityQueryVariables = schema => {
12
12
  typeObject,
13
13
  id: `entityQuery_${typeObject.id}`,
14
14
  title: group.length > 1 ? `${typeObject.pluralTitle} (${typeObject.nameParts.namespace})` : typeObject.pluralTitle,
15
- isCollection: true
15
+ isCollection: true,
16
+ description: `All Entities from "${typeObject.title}" Database`
16
17
  }));
17
18
  }));
18
19
  };
@@ -1,12 +1,11 @@
1
1
  var _ = require('lodash');
2
2
  var moment = require('moment');
3
- var util = require('util');
3
+ var trace = require('@fibery/helpers/utils/trace');
4
4
 
5
5
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
6
6
 
7
7
  var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
8
8
  var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
9
- var util__default = /*#__PURE__*/_interopDefaultLegacy(util);
10
9
 
11
10
  const serializeDate = momentDate => {
12
11
  return momentDate.format("YYYY-MM-DD");
@@ -178,41 +177,6 @@ function _extends() {
178
177
  return _extends.apply(this, arguments);
179
178
  }
180
179
 
181
- const formatWithCustomInspectParams = function (args) {
182
- const transformedArgs = args.map(value => {
183
- if (typeof value === "object") {
184
- return {
185
- [util__default["default"].inspect.custom || "inspect"](recurseTimes, ctx) {
186
- return util__default["default"].inspect(value, _extends({}, ctx, {
187
- showHidden: false,
188
- depth: null,
189
- maxArrayLength: null
190
- }));
191
- }
192
-
193
- };
194
- } else if (typeof value === "string") {
195
- return {
196
- [util__default["default"].inspect.custom || "inspect"](recurseTimes, ctx) {
197
- return value;
198
- }
199
-
200
- };
201
- } else {
202
- return value;
203
- }
204
- });
205
- return util__default["default"].format(...transformedArgs);
206
- };
207
- function assert(condition, ...args) {
208
- if (!condition) {
209
- const message = args.length > 0 ? formatWithCustomInspectParams(args) : `Assertion failed with no details`;
210
- throw new Error(message);
211
- }
212
- }
213
-
214
- [console.error.bind(console)];
215
-
216
180
  const stringify = x => {
217
181
  if (x === undefined) {
218
182
  return "undefined";
@@ -229,10 +193,10 @@ class NotImplementedError extends Error {
229
193
  }
230
194
 
231
195
  const assertIsValidExpression = expression => {
232
- assert(Array.isArray(expression), "expression must be array", {
196
+ trace.assert(Array.isArray(expression), "expression must be array", {
233
197
  expression
234
198
  });
235
- assert(expression.length > 0, "empty expression does not make any sense");
199
+ trace.assert(expression.length > 0, "empty expression does not make any sense");
236
200
  };
237
201
  const dateRangeFunctions = new Set(["q/start", "q/end"]);
238
202
  const firstLastFunctions = new Set(["q/first", "q/last"]);
@@ -249,7 +213,7 @@ const logicalOperators = new Set(["and", "or", "q/and", "q/or"]);
249
213
  const relationalOperators = new Set(["=", "!=", "<", ">", "<=", ">="]);
250
214
  const mathOperators = new Set(["+", "-", "*", "/", "q/+", "q/-", "q/concat"]);
251
215
  const isFunctionCallExpression = expression => expression.length > 1 && ___default["default"].isString(expression[0]) && (expression[0].startsWith("q/") || ["=", "!=", "<", ">", "<=", ">=", "+", "-", "*", "/", "in", "and", "or", "not-in"].includes(expression[0]));
252
- const isDateRangeFunctionExpression = expression => expression.length === 2 && dateRangeFunctions.has(expression[0]) && isFieldExpression(expression[1]);
216
+ const isDateRangeFunctionExpression = expression => (expression.length === 2 || expression.length === 3) && dateRangeFunctions.has(expression[0]) && isFieldExpression(expression[1]);
253
217
  const isCollectionFunctionExpression = expression => //expression has length 3 in case of q/join
254
218
  (expression.length === 2 || expression.length === 3) && collectionOps.has(expression[0]) && isFieldExpression(expression[1]);
255
219
  const isAccessFunctionExpression = expresion => expresion.length === 2 && expresion[0] === "q/access?" && isFieldExpression(expresion[1]);
@@ -286,7 +250,7 @@ const isFunctionExpression = expression => {
286
250
  };
287
251
 
288
252
  const collectFieldExpressions = (memo, expression) => {
289
- if (isVariableExpression(expression)) ; else if (isBinaryExpression(expression) || isNaryExpression(expression)) {
253
+ if (isVariableExpression(expression)) ; else if (isFunctionCallExpression(expression)) {
290
254
  for (const part of expression.slice(1)) {
291
255
  if (isVariableExpression(part) || part === null) ; else {
292
256
  if (___default["default"].isString(part)) {
@@ -299,8 +263,6 @@ const collectFieldExpressions = (memo, expression) => {
299
263
  }
300
264
  } else if (isFieldExpression(expression)) {
301
265
  memo.push(expression);
302
- } else if (isDateRangeFunctionExpression(expression) || isCollectionFunctionExpression(expression)) {
303
- collectFieldExpressions(memo, expression[1]);
304
266
  } else if (expression["q/from"] && isFieldExpression(expression["q/from"])) {
305
267
  const innerMemo = [];
306
268
  expression["q/select"] && collectFieldExpressions(innerMemo, expression["q/select"]);
@@ -523,7 +485,7 @@ const replaceNamesWithIdsVisitor = (typeObject, onFieldNotFound = defaultNamesWi
523
485
  }).currentTypeObject;
524
486
 
525
487
  if (subQueryTypeObject) {
526
- const subQueryVisitor = replaceNamesWithIdsVisitor(subQueryTypeObject);
488
+ const subQueryVisitor = replaceNamesWithIdsVisitor(subQueryTypeObject, onFieldNotFound);
527
489
  return _extends({}, subQueryExpression, {
528
490
  "q/from": visitor.visitFieldExpression(fromExpression),
529
491
  "q/select": ___default["default"].isPlainObject(selectExpression) ? ___default["default"].mapValues(selectExpression, val => subQueryVisitor.visitExpression(val)) : subQueryVisitor.visitExpression(selectExpression)
@@ -778,7 +740,8 @@ const getEntityQueryVariables = schema => {
778
740
  typeObject,
779
741
  id: `entityQuery_${typeObject.id}`,
780
742
  title: group.length > 1 ? `${typeObject.pluralTitle} (${typeObject.nameParts.namespace})` : typeObject.pluralTitle,
781
- isCollection: true
743
+ isCollection: true,
744
+ description: `All Entities from "${typeObject.title}" Database`
782
745
  }));
783
746
  }));
784
747
  };
package/lib/utils.js CHANGED
@@ -1,9 +1,8 @@
1
- var util = require('util');
1
+ var trace = require('@fibery/helpers/utils/trace');
2
2
  var _ = require('lodash');
3
3
 
4
4
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
5
5
 
6
- var util__default = /*#__PURE__*/_interopDefaultLegacy(util);
7
6
  var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
8
7
 
9
8
  function _extends() {
@@ -24,41 +23,6 @@ function _extends() {
24
23
  return _extends.apply(this, arguments);
25
24
  }
26
25
 
27
- const formatWithCustomInspectParams = function (args) {
28
- const transformedArgs = args.map(value => {
29
- if (typeof value === "object") {
30
- return {
31
- [util__default["default"].inspect.custom || "inspect"](recurseTimes, ctx) {
32
- return util__default["default"].inspect(value, _extends({}, ctx, {
33
- showHidden: false,
34
- depth: null,
35
- maxArrayLength: null
36
- }));
37
- }
38
-
39
- };
40
- } else if (typeof value === "string") {
41
- return {
42
- [util__default["default"].inspect.custom || "inspect"](recurseTimes, ctx) {
43
- return value;
44
- }
45
-
46
- };
47
- } else {
48
- return value;
49
- }
50
- });
51
- return util__default["default"].format(...transformedArgs);
52
- };
53
- function assert(condition, ...args) {
54
- if (!condition) {
55
- const message = args.length > 0 ? formatWithCustomInspectParams(args) : `Assertion failed with no details`;
56
- throw new Error(message);
57
- }
58
- }
59
-
60
- [console.error.bind(console)];
61
-
62
26
  const stringify = x => {
63
27
  if (x === undefined) {
64
28
  return "undefined";
@@ -75,10 +39,10 @@ class NotImplementedError extends Error {
75
39
  }
76
40
 
77
41
  const assertIsValidExpression = expression => {
78
- assert(Array.isArray(expression), "expression must be array", {
42
+ trace.assert(Array.isArray(expression), "expression must be array", {
79
43
  expression
80
44
  });
81
- assert(expression.length > 0, "empty expression does not make any sense");
45
+ trace.assert(expression.length > 0, "empty expression does not make any sense");
82
46
  };
83
47
  const dateRangeFunctions = new Set(["q/start", "q/end"]);
84
48
  const firstLastFunctions = new Set(["q/first", "q/last"]);
@@ -95,7 +59,7 @@ const logicalOperators = new Set(["and", "or", "q/and", "q/or"]);
95
59
  const relationalOperators = new Set(["=", "!=", "<", ">", "<=", ">="]);
96
60
  const mathOperators = new Set(["+", "-", "*", "/", "q/+", "q/-", "q/concat"]);
97
61
  const isFunctionCallExpression = expression => expression.length > 1 && ___default["default"].isString(expression[0]) && (expression[0].startsWith("q/") || ["=", "!=", "<", ">", "<=", ">=", "+", "-", "*", "/", "in", "and", "or", "not-in"].includes(expression[0]));
98
- const isDateRangeFunctionExpression = expression => expression.length === 2 && dateRangeFunctions.has(expression[0]) && isFieldExpression(expression[1]);
62
+ const isDateRangeFunctionExpression = expression => (expression.length === 2 || expression.length === 3) && dateRangeFunctions.has(expression[0]) && isFieldExpression(expression[1]);
99
63
  const isCollectionFunctionExpression = expression => //expression has length 3 in case of q/join
100
64
  (expression.length === 2 || expression.length === 3) && collectionOps.has(expression[0]) && isFieldExpression(expression[1]);
101
65
  const isAccessFunctionExpression = expresion => expresion.length === 2 && expresion[0] === "q/access?" && isFieldExpression(expresion[1]);
@@ -132,7 +96,7 @@ const isFunctionExpression = expression => {
132
96
  };
133
97
 
134
98
  const collectFieldExpressions = (memo, expression) => {
135
- if (isVariableExpression(expression)) ; else if (isBinaryExpression(expression) || isNaryExpression(expression)) {
99
+ if (isVariableExpression(expression)) ; else if (isFunctionCallExpression(expression)) {
136
100
  for (const part of expression.slice(1)) {
137
101
  if (isVariableExpression(part) || part === null) ; else {
138
102
  if (___default["default"].isString(part)) {
@@ -145,8 +109,6 @@ const collectFieldExpressions = (memo, expression) => {
145
109
  }
146
110
  } else if (isFieldExpression(expression)) {
147
111
  memo.push(expression);
148
- } else if (isDateRangeFunctionExpression(expression) || isCollectionFunctionExpression(expression)) {
149
- collectFieldExpressions(memo, expression[1]);
150
112
  } else if (expression["q/from"] && isFieldExpression(expression["q/from"])) {
151
113
  const innerMemo = [];
152
114
  expression["q/select"] && collectFieldExpressions(innerMemo, expression["q/select"]);
package/lib/visitors.js CHANGED
@@ -1,5 +1,5 @@
1
1
  var _ = require('lodash');
2
- require('util');
2
+ require('@fibery/helpers/utils/trace');
3
3
 
4
4
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
5
5
 
@@ -23,8 +23,6 @@ function _extends() {
23
23
  return _extends.apply(this, arguments);
24
24
  }
25
25
 
26
- [console.error.bind(console)];
27
-
28
26
  const stringify = x => {
29
27
  if (x === undefined) {
30
28
  return "undefined";
@@ -243,7 +241,7 @@ const replaceNamesWithIdsVisitor = (typeObject, onFieldNotFound = defaultNamesWi
243
241
  }).currentTypeObject;
244
242
 
245
243
  if (subQueryTypeObject) {
246
- const subQueryVisitor = replaceNamesWithIdsVisitor(subQueryTypeObject);
244
+ const subQueryVisitor = replaceNamesWithIdsVisitor(subQueryTypeObject, onFieldNotFound);
247
245
  return _extends({}, subQueryExpression, {
248
246
  "q/from": visitor.visitFieldExpression(fromExpression),
249
247
  "q/select": ___default["default"].isPlainObject(selectExpression) ? ___default["default"].mapValues(selectExpression, val => subQueryVisitor.visitExpression(val)) : subQueryVisitor.visitExpression(selectExpression)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/expression-utils",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "utils for working with fibery api expressions",
5
5
  "exports": {
6
6
  ".": "./lib/expression-utils.js",
@@ -22,33 +22,47 @@
22
22
  ],
23
23
  "private": false,
24
24
  "dependencies": {
25
- "lodash": "^4.17.21",
26
- "moment": "^2.20.1"
25
+ "lodash": "4.17.21",
26
+ "moment": "2.20.1",
27
+ "@fibery/helpers": "1.0.0"
27
28
  },
28
29
  "devDependencies": {
29
30
  "@babel/core": "7.15.0",
30
- "babel-jest": "27.0.6",
31
- "babel-loader": "8.2.2",
32
- "babel-preset-fibery": "7.2.0",
33
- "eslint-config-fibery": "7.0.0",
34
- "jest": "27.0.6",
35
- "microbundle": "0.14.1"
31
+ "babel-jest": "27.5.1",
32
+ "babel-loader": "8.2.5",
33
+ "@fibery/babel-preset": "7.2.0",
34
+ "@fibery/eslint-config": "8.1.0",
35
+ "jest": "27.5.1",
36
+ "jest-junit": "13.0.0",
37
+ "microbundle": "0.15.0"
36
38
  },
37
39
  "peerDependencies": {
38
- "fibery-schema": "7.x"
40
+ "@fibery/schema": "^8.0.6"
39
41
  },
40
42
  "scripts": {
41
43
  "build": "rm -rf lib && microbundle paramsPlaceholders.js utils.js visitors.js contextVariables.js index.js -o lib -f cjs --no-compress --target node --sourcemap false",
42
44
  "test": "node scripts/test.js",
45
+ "test:ci": "yarn test --coverage --reporters=default --reporters=jest-junit",
43
46
  "lint": "eslint ."
44
47
  },
45
48
  "jest": {
46
49
  "testEnvironment": "node",
50
+ "coveragePathIgnorePatterns": [
51
+ "/node_modules/"
52
+ ],
53
+ "collectCoverageFrom": [
54
+ "src/**/*.{js,jsx,ts,tsx}",
55
+ "!src/**/*.d.ts"
56
+ ],
57
+ "coverageReporters": [
58
+ "text",
59
+ "cobertura"
60
+ ],
47
61
  "testPathIgnorePatterns": [
48
62
  "<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]"
49
63
  ],
50
64
  "transform": {
51
- "^.+\\.jsx?$": "../fibery-ui/config/jest/babel.js"
65
+ "^.+\\.(js|jsx|ts|tsx)$": "../../fibery-ui/config/jest/babel.js"
52
66
  },
53
67
  "testURL": "http://localhost"
54
68
  }