@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.
- package/cjs/filter/antlr/OpraFilterLexer.js +225 -302
- package/cjs/filter/antlr/OpraFilterListener.js +11 -0
- package/cjs/filter/antlr/OpraFilterParser.js +1120 -721
- package/cjs/filter/antlr/OpraFilterVisitor.js +12 -1
- package/cjs/filter/ast/terms/date-literal.js +4 -3
- package/cjs/filter/filter-tree-visitor.js +31 -28
- package/cjs/filter/index.js +1 -1
- package/cjs/filter/opra-error-listener.js +15 -0
- package/cjs/filter/parse.js +11 -10
- package/cjs/i18n/i18n.js +13 -14
- package/cjs/schema/decorators/opr-collection-resource.decorator.js +3 -2
- package/cjs/schema/decorators/opr-complex-type.decorator.js +3 -2
- package/cjs/schema/decorators/opr-field.decorator.js +3 -2
- package/cjs/schema/decorators/opr-simple-type.decorator.js +3 -2
- package/cjs/schema/decorators/opr-singleton-resource.decorator.js +3 -2
- package/cjs/schema/implementation/data-type/union-type.js +3 -2
- package/cjs/schema/implementation/document-builder.js +4 -3
- package/cjs/schema/implementation/opra-document.js +3 -2
- package/esm/filter/antlr/OpraFilterLexer.d.ts +11 -12
- package/esm/filter/antlr/OpraFilterLexer.js +224 -299
- package/esm/filter/antlr/OpraFilterListener.d.ts +430 -0
- package/esm/filter/antlr/OpraFilterListener.js +8 -0
- package/esm/filter/antlr/OpraFilterParser.d.ts +183 -111
- package/esm/filter/antlr/OpraFilterParser.js +1052 -652
- package/esm/filter/antlr/OpraFilterVisitor.d.ts +77 -107
- package/esm/filter/antlr/OpraFilterVisitor.js +11 -2
- package/esm/filter/ast/terms/date-literal.js +4 -3
- package/esm/filter/errors.d.ts +4 -6
- package/esm/filter/filter-tree-visitor.d.ts +5 -3
- package/esm/filter/filter-tree-visitor.js +23 -21
- package/esm/filter/index.d.ts +1 -1
- package/esm/filter/index.js +1 -1
- package/esm/filter/opra-error-listener.d.ts +8 -0
- package/esm/filter/opra-error-listener.js +11 -0
- package/esm/filter/parse.d.ts +2 -2
- package/esm/filter/parse.js +8 -8
- package/esm/i18n/i18n.d.ts +1 -1
- package/esm/i18n/i18n.js +9 -10
- package/esm/schema/decorators/opr-collection-resource.decorator.js +1 -1
- package/esm/schema/decorators/opr-complex-type.decorator.js +1 -1
- package/esm/schema/decorators/opr-field.decorator.js +1 -1
- package/esm/schema/decorators/opr-simple-type.decorator.js +1 -1
- package/esm/schema/decorators/opr-singleton-resource.decorator.js +1 -1
- package/esm/schema/implementation/data-type/union-type.js +1 -1
- package/esm/schema/implementation/document-builder.js +3 -3
- package/esm/schema/implementation/opra-document.js +1 -1
- package/package.json +7 -7
- package/cjs/filter/error-listener.js +0 -13
- package/esm/filter/error-listener.d.ts +0 -8
- 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
|
|
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 (!(
|
|
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 =
|
|
74
|
+
const languageDirs = fs.readdirSync(dirname);
|
|
76
75
|
for (const lang of languageDirs) {
|
|
77
76
|
const langDir = path.join(dirname, lang);
|
|
78
|
-
if ((
|
|
79
|
-
const nsDirs =
|
|
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' && (
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import
|
|
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)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/common",
|
|
3
|
-
"version": "0.10.
|
|
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
|
-
"
|
|
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.
|
|
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.
|
|
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
|
-
}
|