@opra/common 0.10.0 → 0.10.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.
Files changed (50) hide show
  1. package/cjs/filter/antlr/OpraFilterLexer.js +225 -302
  2. package/cjs/filter/antlr/OpraFilterListener.js +11 -0
  3. package/cjs/filter/antlr/OpraFilterParser.js +1120 -721
  4. package/cjs/filter/antlr/OpraFilterVisitor.js +12 -1
  5. package/cjs/filter/ast/terms/date-literal.js +4 -3
  6. package/cjs/filter/filter-tree-visitor.js +31 -28
  7. package/cjs/filter/index.js +1 -1
  8. package/cjs/filter/opra-error-listener.js +15 -0
  9. package/cjs/filter/parse.js +11 -10
  10. package/cjs/i18n/i18n.js +13 -14
  11. package/cjs/schema/decorators/opr-collection-resource.decorator.js +3 -2
  12. package/cjs/schema/decorators/opr-complex-type.decorator.js +3 -2
  13. package/cjs/schema/decorators/opr-field.decorator.js +3 -2
  14. package/cjs/schema/decorators/opr-simple-type.decorator.js +3 -2
  15. package/cjs/schema/decorators/opr-singleton-resource.decorator.js +3 -2
  16. package/cjs/schema/implementation/data-type/union-type.js +3 -2
  17. package/cjs/schema/implementation/document-builder.js +4 -3
  18. package/cjs/schema/implementation/opra-document.js +3 -2
  19. package/esm/filter/antlr/OpraFilterLexer.d.ts +11 -12
  20. package/esm/filter/antlr/OpraFilterLexer.js +224 -299
  21. package/esm/filter/antlr/OpraFilterListener.d.ts +430 -0
  22. package/esm/filter/antlr/OpraFilterListener.js +8 -0
  23. package/esm/filter/antlr/OpraFilterParser.d.ts +183 -111
  24. package/esm/filter/antlr/OpraFilterParser.js +1052 -652
  25. package/esm/filter/antlr/OpraFilterVisitor.d.ts +77 -107
  26. package/esm/filter/antlr/OpraFilterVisitor.js +11 -2
  27. package/esm/filter/ast/terms/date-literal.js +4 -3
  28. package/esm/filter/errors.d.ts +4 -6
  29. package/esm/filter/filter-tree-visitor.d.ts +5 -3
  30. package/esm/filter/filter-tree-visitor.js +23 -21
  31. package/esm/filter/index.d.ts +1 -1
  32. package/esm/filter/index.js +1 -1
  33. package/esm/filter/opra-error-listener.d.ts +8 -0
  34. package/esm/filter/opra-error-listener.js +11 -0
  35. package/esm/filter/parse.d.ts +2 -2
  36. package/esm/filter/parse.js +8 -8
  37. package/esm/i18n/i18n.d.ts +1 -1
  38. package/esm/i18n/i18n.js +9 -10
  39. package/esm/schema/decorators/opr-collection-resource.decorator.js +1 -1
  40. package/esm/schema/decorators/opr-complex-type.decorator.js +1 -1
  41. package/esm/schema/decorators/opr-field.decorator.js +1 -1
  42. package/esm/schema/decorators/opr-simple-type.decorator.js +1 -1
  43. package/esm/schema/decorators/opr-singleton-resource.decorator.js +1 -1
  44. package/esm/schema/implementation/data-type/union-type.js +1 -1
  45. package/esm/schema/implementation/document-builder.js +3 -3
  46. package/esm/schema/implementation/opra-document.js +1 -1
  47. package/package.json +7 -7
  48. package/cjs/filter/error-listener.js +0 -13
  49. package/esm/filter/error-listener.d.ts +0 -8
  50. package/esm/filter/error-listener.js +0 -9
package/esm/i18n/i18n.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { splitString, tokenize } from 'fast-tokenizer';
2
+ import fs from 'fs';
2
3
  import i18next from 'i18next';
4
+ import path from 'path';
3
5
  import { isUrl } from '../utils/index.js';
4
6
  import { unescapeString } from './string-utils.js';
5
7
  export const BaseI18n = Object.getPrototypeOf(i18next).constructor;
@@ -9,7 +11,7 @@ export class I18n extends BaseI18n {
9
11
  const options = typeof arg0 === 'object' ? arg0 : {};
10
12
  const callback = typeof arg0 === 'function' ? arg0 : arg1;
11
13
  try {
12
- const t = await super.init(options);
14
+ const t = await super.init(options, callback);
13
15
  // Add formatters
14
16
  const formatter = this.services.formatter;
15
17
  formatter.add('lowercase', (value, lng) => value.toLocaleLowerCase(lng));
@@ -56,31 +58,28 @@ export class I18n extends BaseI18n {
56
58
  obj = (await fetch(filePath, { headers: { accept: 'application/json' } })).json();
57
59
  }
58
60
  else {
59
- const fs = await import('fs/promises');
60
- const content = await fs.readFile(filePath, 'utf8');
61
+ const content = fs.readFileSync(filePath, 'utf8');
61
62
  obj = JSON.parse(content);
62
63
  }
63
64
  this.addResourceBundle(lang, ns, obj, deep, overwrite);
64
65
  }
65
66
  async loadResourceDir(dirnames, deep, overwrite) {
66
- const fs = await import('fs/promises');
67
- const path = await import('path');
68
67
  for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
69
68
  /* istanbul ignore next */
70
- if (!(await fs.stat(dirname)).isDirectory()) {
69
+ if (!(fs.statSync(dirname)).isDirectory()) {
71
70
  // eslint-disable-next-line no-console
72
71
  console.warn(`Locale directory does not exists. (${dirname})`);
73
72
  continue;
74
73
  }
75
- const languageDirs = await fs.readdir(dirname);
74
+ const languageDirs = fs.readdirSync(dirname);
76
75
  for (const lang of languageDirs) {
77
76
  const langDir = path.join(dirname, lang);
78
- if ((await fs.stat(langDir)).isDirectory()) {
79
- const nsDirs = await fs.readdir(langDir);
77
+ if ((fs.statSync(langDir)).isDirectory()) {
78
+ const nsDirs = fs.readdirSync(langDir);
80
79
  for (const nsfile of nsDirs) {
81
80
  const nsFilePath = path.join(langDir, nsfile);
82
81
  const ext = path.extname(nsfile);
83
- if (ext === '.json' && (await fs.stat(nsFilePath)).isFile()) {
82
+ if (ext === '.json' && (fs.statSync(nsFilePath)).isFile()) {
84
83
  const ns = path.basename(nsfile, ext);
85
84
  await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
86
85
  }
@@ -1,5 +1,5 @@
1
1
  import "reflect-metadata";
2
- import { omit } from 'lodash';
2
+ import omit from 'lodash.omit';
3
3
  import { RESOURCE_METADATA } from '../constants.js';
4
4
  const NESTJS_INJECTABLE_WATERMARK = '__injectable__';
5
5
  const NAME_PATTERN = /^(.*)Resource$/;
@@ -1,4 +1,4 @@
1
- import { omit } from 'lodash';
1
+ import omit from 'lodash.omit';
2
2
  import { DATATYPE_METADATA } from '../constants.js';
3
3
  const NAME_PATTERN = /^(.*)Type$/;
4
4
  export function OprComplexType(options) {
@@ -1,4 +1,4 @@
1
- import { omit } from 'lodash';
1
+ import omit from 'lodash.omit';
2
2
  import { COMPLEXTYPE_FIELDS } from '../constants.js';
3
3
  export function OprField(args) {
4
4
  return (target, propertyKey) => {
@@ -1,4 +1,4 @@
1
- import { omit } from 'lodash';
1
+ import omit from 'lodash.omit';
2
2
  import { DATATYPE_METADATA } from '../constants.js';
3
3
  const NAME_PATTERN = /^(.*)Type$/;
4
4
  export function OprSimpleType(options) {
@@ -1,5 +1,5 @@
1
1
  import "reflect-metadata";
2
- import { omit } from 'lodash';
2
+ import omit from 'lodash.omit';
3
3
  import { RESOURCE_METADATA } from '../constants.js';
4
4
  const NESTJS_INJECTABLE_WATERMARK = '__injectable__';
5
5
  const NAME_PATTERN = /^(.*)Resource$/;
@@ -1,4 +1,4 @@
1
- import { omit } from 'lodash';
1
+ import omit from 'lodash.omit';
2
2
  import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom } from '../../utils/inspect.util.js';
3
3
  import { ComplexType } from './complex-type.js';
4
4
  import { DataType } from './data-type.js';
@@ -1,4 +1,4 @@
1
- import { isPromise } from 'putil-promisify';
1
+ import promisify from 'putil-promisify';
2
2
  import { ResponsiveMap } from '../../helpers/responsive-map.js';
3
3
  import { OpraSchema } from '../opra-schema.definition.js';
4
4
  import { isConstructor } from '../utils/class.utils.js';
@@ -62,7 +62,7 @@ export class DocumentBuilder {
62
62
  }
63
63
  }
64
64
  async addDataTypeClass(thunk) {
65
- thunk = isPromise(thunk) ? await thunk : thunk;
65
+ thunk = promisify.isPromise(thunk) ? await thunk : thunk;
66
66
  if (!isConstructor(thunk))
67
67
  return this.addDataTypeClass(thunk());
68
68
  const internalTypeName = primitiveClasses.get(thunk);
@@ -112,7 +112,7 @@ export class DocumentBuilder {
112
112
  this._resources.set(name, schema);
113
113
  }
114
114
  async addResourceInstance(thunk) {
115
- thunk = isPromise(thunk) ? await thunk : thunk;
115
+ thunk = promisify.isPromise(thunk) ? await thunk : thunk;
116
116
  let instance;
117
117
  if (typeof thunk === 'function') {
118
118
  if (isConstructor(thunk)) {
@@ -1,4 +1,4 @@
1
- import { omit } from 'lodash';
1
+ import omit from 'lodash.omit';
2
2
  import { ResponsiveMap } from '../../helpers/responsive-map.js';
3
3
  import { OpraSchema } from '../opra-schema.definition.js';
4
4
  import { cloneObject } from '../utils/clone-object.util.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/common",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Opra internationalization package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -23,19 +23,19 @@
23
23
  "clean": "npm run clean:src && npm run clean:dist && npm run clean:cover",
24
24
  "clean:src": "ts-cleanup -s src --all",
25
25
  "clean:dist": "rimraf ../../build/common",
26
- "clean:cover": "rimraf ../../coverage/common"
26
+ "clean:cover": "rimraf ../../coverage/common",
27
+ "antlr4": "java -jar ./tools/antlr4-4.11.2-SNAPSHOT-complete.jar -Dlanguage=TypeScript ./src/filter/antlr/OpraFilter.g4 -visitor"
27
28
  },
28
29
  "dependencies": {
29
- "antlr4ts": "^0.5.0-alpha.4",
30
+ "antlr4": "^4.12.0-beta.3",
30
31
  "fast-tokenizer": "^1.2.0",
31
32
  "highland": "^2.13.5",
32
33
  "http-parser-js": "^0.5.8",
33
34
  "i18next": "^22.4.6",
34
- "lodash": "^4.17.21",
35
- "luxon": "^3.1.1",
35
+ "lodash.omit": "^4.5.0",
36
36
  "putil-isplainobject": "^1.1.4",
37
37
  "putil-merge": "^3.9.0",
38
- "putil-promisify": "^1.8.5",
38
+ "putil-promisify": "^1.10.0",
39
39
  "putil-varhelpers": "^1.6.4",
40
40
  "reflect-metadata": "^0.1.13",
41
41
  "uid": "^2.0.1"
@@ -67,4 +67,4 @@
67
67
  "opra",
68
68
  "common"
69
69
  ]
70
- }
70
+ }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorListener = void 0;
4
- const errors_js_1 = require("./errors.js");
5
- class ErrorListener {
6
- constructor(errors) {
7
- this.errors = errors;
8
- }
9
- syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e) {
10
- this.errors.push(new errors_js_1.FilterParseError(msg, { recognizer, offendingSymbol, line, charPositionInLine, e }));
11
- }
12
- }
13
- exports.ErrorListener = ErrorListener;
@@ -1,8 +0,0 @@
1
- import { ANTLRErrorListener, Recognizer } from 'antlr4ts';
2
- import { RecognitionException } from 'antlr4ts/RecognitionException';
3
- import { FilterParseError } from './errors.js';
4
- export declare class ErrorListener implements ANTLRErrorListener<any> {
5
- errors: FilterParseError[];
6
- constructor(errors: FilterParseError[]);
7
- syntaxError<T>(recognizer: Recognizer<T, any>, offendingSymbol: T | undefined, line: number, charPositionInLine: number, msg: string, e: RecognitionException | undefined): void;
8
- }
@@ -1,9 +0,0 @@
1
- import { FilterParseError } from './errors.js';
2
- export class ErrorListener {
3
- constructor(errors) {
4
- this.errors = errors;
5
- }
6
- syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e) {
7
- this.errors.push(new FilterParseError(msg, { recognizer, offendingSymbol, line, charPositionInLine, e }));
8
- }
9
- }