@opra/core 0.0.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.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/cjs/constants.js +5 -0
- package/cjs/decorators/entity-resource.decorator.js +24 -0
- package/cjs/enums/http-headers.enum.js +393 -0
- package/cjs/enums/http-status.enum.js +300 -0
- package/cjs/enums/index.js +5 -0
- package/cjs/enums/issue-severity.enum.js +2 -0
- package/cjs/exception/api-exception.js +63 -0
- package/cjs/exception/errors/bad-request.error.js +22 -0
- package/cjs/exception/errors/failed-dependency.error.js +21 -0
- package/cjs/exception/errors/forbidden.error.js +23 -0
- package/cjs/exception/errors/internal-server.error.js +21 -0
- package/cjs/exception/errors/method-not-allowed.error.js +22 -0
- package/cjs/exception/errors/not-found.error.js +25 -0
- package/cjs/exception/errors/unauthorized.error.js +22 -0
- package/cjs/exception/errors/unprocessable-entity.error.js +21 -0
- package/cjs/exception/index.js +11 -0
- package/cjs/implementation/adapter/adapter.js +72 -0
- package/cjs/implementation/adapter/express-adapter.js +93 -0
- package/cjs/implementation/adapter/http-adapter.js +262 -0
- package/cjs/implementation/data-type/complex-type.js +39 -0
- package/cjs/implementation/data-type/data-type.js +35 -0
- package/cjs/implementation/data-type/entity-type.js +33 -0
- package/cjs/implementation/data-type/simple-type.js +30 -0
- package/cjs/implementation/execution-context.js +49 -0
- package/cjs/implementation/opra-document.js +116 -0
- package/cjs/implementation/opra-service.js +59 -0
- package/cjs/implementation/resource/container-resource-controller.js +26 -0
- package/cjs/implementation/resource/entity-resource-info.js +68 -0
- package/cjs/implementation/resource/resource-info.js +24 -0
- package/cjs/implementation/schema-generator.js +173 -0
- package/cjs/index.js +25 -0
- package/cjs/interfaces/entity-resource.interface.js +2 -0
- package/cjs/interfaces/execution-query.interface.js +190 -0
- package/cjs/interfaces/http-context.interface.js +2 -0
- package/cjs/interfaces/opra-schema.metadata.js +2 -0
- package/cjs/interfaces/resource-container.interface.js +2 -0
- package/cjs/package.json +3 -0
- package/cjs/services/data-service.js +9 -0
- package/cjs/services/json-data-service.js +15 -0
- package/cjs/types.js +2 -0
- package/cjs/utils/class-utils.js +37 -0
- package/cjs/utils/headers.js +58 -0
- package/cjs/utils/internal-data-types.js +44 -0
- package/cjs/utils/responsive-object.js +49 -0
- package/cjs/utils/string-path-to-object-tree.js +26 -0
- package/cjs/utils/terminal-utils.js +7 -0
- package/esm/constants.d.ts +2 -0
- package/esm/constants.js +2 -0
- package/esm/decorators/entity-resource.decorator.d.ts +5 -0
- package/esm/decorators/entity-resource.decorator.js +19 -0
- package/esm/enums/http-headers.enum.d.ts +368 -0
- package/esm/enums/http-headers.enum.js +390 -0
- package/esm/enums/http-status.enum.d.ts +290 -0
- package/esm/enums/http-status.enum.js +297 -0
- package/esm/enums/index.d.ts +2 -0
- package/esm/enums/index.js +2 -0
- package/esm/enums/issue-severity.enum.d.ts +1 -0
- package/esm/enums/issue-severity.enum.js +1 -0
- package/esm/exception/api-exception.d.ts +38 -0
- package/esm/exception/api-exception.js +59 -0
- package/esm/exception/errors/bad-request.error.d.ts +9 -0
- package/esm/exception/errors/bad-request.error.js +18 -0
- package/esm/exception/errors/failed-dependency.error.d.ts +8 -0
- package/esm/exception/errors/failed-dependency.error.js +17 -0
- package/esm/exception/errors/forbidden.error.d.ts +10 -0
- package/esm/exception/errors/forbidden.error.js +19 -0
- package/esm/exception/errors/internal-server.error.d.ts +8 -0
- package/esm/exception/errors/internal-server.error.js +17 -0
- package/esm/exception/errors/method-not-allowed.error.d.ts +9 -0
- package/esm/exception/errors/method-not-allowed.error.js +18 -0
- package/esm/exception/errors/not-found.error.d.ts +12 -0
- package/esm/exception/errors/not-found.error.js +21 -0
- package/esm/exception/errors/unauthorized.error.d.ts +9 -0
- package/esm/exception/errors/unauthorized.error.js +18 -0
- package/esm/exception/errors/unprocessable-entity.error.d.ts +8 -0
- package/esm/exception/errors/unprocessable-entity.error.js +17 -0
- package/esm/exception/index.d.ts +8 -0
- package/esm/exception/index.js +8 -0
- package/esm/implementation/adapter/adapter.d.ts +18 -0
- package/esm/implementation/adapter/adapter.js +68 -0
- package/esm/implementation/adapter/express-adapter.d.ts +12 -0
- package/esm/implementation/adapter/express-adapter.js +89 -0
- package/esm/implementation/adapter/http-adapter.d.ts +27 -0
- package/esm/implementation/adapter/http-adapter.js +258 -0
- package/esm/implementation/data-type/complex-type.d.ts +18 -0
- package/esm/implementation/data-type/complex-type.js +35 -0
- package/esm/implementation/data-type/data-type.d.ts +15 -0
- package/esm/implementation/data-type/data-type.js +31 -0
- package/esm/implementation/data-type/entity-type.d.ts +10 -0
- package/esm/implementation/data-type/entity-type.js +29 -0
- package/esm/implementation/data-type/simple-type.d.ts +15 -0
- package/esm/implementation/data-type/simple-type.js +26 -0
- package/esm/implementation/execution-context.d.ts +42 -0
- package/esm/implementation/execution-context.js +43 -0
- package/esm/implementation/opra-document.d.ts +26 -0
- package/esm/implementation/opra-document.js +111 -0
- package/esm/implementation/opra-service.d.ts +19 -0
- package/esm/implementation/opra-service.js +55 -0
- package/esm/implementation/resource/container-resource-controller.d.ts +12 -0
- package/esm/implementation/resource/container-resource-controller.js +22 -0
- package/esm/implementation/resource/entity-resource-info.d.ts +24 -0
- package/esm/implementation/resource/entity-resource-info.js +63 -0
- package/esm/implementation/resource/resource-info.d.ts +10 -0
- package/esm/implementation/resource/resource-info.js +20 -0
- package/esm/implementation/schema-generator.d.ts +21 -0
- package/esm/implementation/schema-generator.js +169 -0
- package/esm/index.d.ts +22 -0
- package/esm/index.js +22 -0
- package/esm/interfaces/entity-resource.interface.d.ts +9 -0
- package/esm/interfaces/entity-resource.interface.js +1 -0
- package/esm/interfaces/execution-query.interface.d.ts +102 -0
- package/esm/interfaces/execution-query.interface.js +186 -0
- package/esm/interfaces/http-context.interface.d.ts +23 -0
- package/esm/interfaces/http-context.interface.js +1 -0
- package/esm/interfaces/opra-schema.metadata.d.ts +14 -0
- package/esm/interfaces/opra-schema.metadata.js +1 -0
- package/esm/interfaces/resource-container.interface.d.ts +6 -0
- package/esm/interfaces/resource-container.interface.js +1 -0
- package/esm/services/data-service.d.ts +2 -0
- package/esm/services/data-service.js +5 -0
- package/esm/services/json-data-service.d.ts +9 -0
- package/esm/services/json-data-service.js +10 -0
- package/esm/types.d.ts +11 -0
- package/esm/types.js +1 -0
- package/esm/utils/class-utils.d.ts +6 -0
- package/esm/utils/class-utils.js +30 -0
- package/esm/utils/headers.d.ts +9 -0
- package/esm/utils/headers.js +55 -0
- package/esm/utils/internal-data-types.d.ts +4 -0
- package/esm/utils/internal-data-types.js +41 -0
- package/esm/utils/responsive-object.d.ts +3 -0
- package/esm/utils/responsive-object.js +45 -0
- package/esm/utils/string-path-to-object-tree.d.ts +4 -0
- package/esm/utils/string-path-to-object-tree.js +22 -0
- package/esm/utils/terminal-utils.d.ts +4 -0
- package/esm/utils/terminal-utils.js +4 -0
- package/package.json +77 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Opaque } from 'ts-gems';
|
|
2
|
+
export declare type HeadersObject = Opaque<Record<string, any>, 'HeadersObject'>;
|
|
3
|
+
/**
|
|
4
|
+
* Create a proxy that ensures header keys are always formatted according to well known header names
|
|
5
|
+
*/
|
|
6
|
+
export declare namespace Headers {
|
|
7
|
+
function from(obj: object): HeadersObject;
|
|
8
|
+
function create(): HeadersObject;
|
|
9
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { HttpHeaders } from '../enums/index.js';
|
|
2
|
+
const wellKnownHeaders = Object.values(HttpHeaders)
|
|
3
|
+
.reduce((target, k) => {
|
|
4
|
+
target[k.toLowerCase()] = k;
|
|
5
|
+
return target;
|
|
6
|
+
}, {});
|
|
7
|
+
const wrapKey = (prop) => {
|
|
8
|
+
return typeof prop == 'string' ? wellKnownHeaders[prop.toLowerCase()] || prop : prop;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Create a proxy that ensures header keys are always formatted according to well known header names
|
|
12
|
+
*/
|
|
13
|
+
export var Headers;
|
|
14
|
+
(function (Headers) {
|
|
15
|
+
function from(obj) {
|
|
16
|
+
const headers = create();
|
|
17
|
+
for (const [k, v] of Object.entries(obj))
|
|
18
|
+
headers[k] = v;
|
|
19
|
+
return headers;
|
|
20
|
+
}
|
|
21
|
+
Headers.from = from;
|
|
22
|
+
function create() {
|
|
23
|
+
return new Proxy({}, {
|
|
24
|
+
set: (target, prop, value, receiver) => {
|
|
25
|
+
let key = prop;
|
|
26
|
+
if (typeof key === 'string')
|
|
27
|
+
key = wellKnownHeaders[key.toLowerCase()] || key;
|
|
28
|
+
const result = Reflect.set(target, key, value, receiver);
|
|
29
|
+
/* istanbul ignore next */
|
|
30
|
+
if (!result && Object.isFrozen(target))
|
|
31
|
+
throw new TypeError('Cannot add property, object is not extensible');
|
|
32
|
+
return result;
|
|
33
|
+
},
|
|
34
|
+
get: (target, prop, receiver) => {
|
|
35
|
+
return Reflect.get(target, wrapKey(prop), receiver);
|
|
36
|
+
},
|
|
37
|
+
deleteProperty: (target, prop) => {
|
|
38
|
+
return Reflect.deleteProperty(target, wrapKey(prop));
|
|
39
|
+
},
|
|
40
|
+
defineProperty: (target, prop, descriptor) => {
|
|
41
|
+
let key = prop;
|
|
42
|
+
if (typeof key === 'string')
|
|
43
|
+
key = wellKnownHeaders[key.toLowerCase()] || key;
|
|
44
|
+
return Reflect.defineProperty(target, key, descriptor);
|
|
45
|
+
},
|
|
46
|
+
getOwnPropertyDescriptor: (target, prop) => {
|
|
47
|
+
return Reflect.getOwnPropertyDescriptor(target, wrapKey(prop));
|
|
48
|
+
},
|
|
49
|
+
has: (target, prop) => {
|
|
50
|
+
return Reflect.has(target, wrapKey(prop));
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
Headers.create = create;
|
|
55
|
+
})(Headers || (Headers = {}));
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const builtinClassMap = new Map();
|
|
2
|
+
builtinClassMap.set(Boolean, 'boolean');
|
|
3
|
+
builtinClassMap.set(Number, 'number');
|
|
4
|
+
builtinClassMap.set(String, 'string');
|
|
5
|
+
builtinClassMap.set(Buffer, 'buffer');
|
|
6
|
+
export const primitiveDataTypeNames = ['boolean', 'number', 'integer', 'string'];
|
|
7
|
+
export const internalDataTypes = new Map();
|
|
8
|
+
const internalDataTypeArray = [
|
|
9
|
+
{
|
|
10
|
+
kind: 'SimpleType',
|
|
11
|
+
name: 'boolean',
|
|
12
|
+
type: 'boolean',
|
|
13
|
+
description: 'Simple true/false value'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
kind: 'SimpleType',
|
|
17
|
+
name: 'number',
|
|
18
|
+
type: 'number',
|
|
19
|
+
description: 'Both Integer as well as Floating-Point numbers'
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
kind: 'SimpleType',
|
|
23
|
+
name: 'string',
|
|
24
|
+
type: 'string',
|
|
25
|
+
description: 'A sequence of characters'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
kind: 'ComplexType',
|
|
29
|
+
name: 'object',
|
|
30
|
+
description: 'Object type with additional properties',
|
|
31
|
+
additionalProperties: true
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
kind: 'SimpleType',
|
|
35
|
+
name: 'integer',
|
|
36
|
+
type: 'number',
|
|
37
|
+
base: 'number',
|
|
38
|
+
description: 'Integer number'
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
internalDataTypeArray.forEach(sch => internalDataTypes.set(sch.name, sch));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function Responsive(wrapped) {
|
|
2
|
+
wrapped = wrapped || {};
|
|
3
|
+
const keyMap = {};
|
|
4
|
+
Object.keys(wrapped).forEach(k => keyMap[k.toLowerCase()] = k);
|
|
5
|
+
const wrapKey = (prop) => {
|
|
6
|
+
return typeof prop == 'string' ? keyMap[prop.toLowerCase()] : prop;
|
|
7
|
+
};
|
|
8
|
+
return new Proxy(wrapped, {
|
|
9
|
+
set: (target, prop, value, receiver) => {
|
|
10
|
+
let key = prop;
|
|
11
|
+
if (typeof key === 'string') {
|
|
12
|
+
const keyLower = key.toLowerCase();
|
|
13
|
+
key = keyMap[keyLower] = keyMap[keyLower] || key;
|
|
14
|
+
}
|
|
15
|
+
const result = Reflect.set(target, key, value, receiver);
|
|
16
|
+
if (!result && Object.isFrozen(target))
|
|
17
|
+
throw new TypeError('Cannot add property, object is not extensible');
|
|
18
|
+
return result;
|
|
19
|
+
},
|
|
20
|
+
get: (target, prop, receiver) => {
|
|
21
|
+
return Reflect.get(target, wrapKey(prop), receiver);
|
|
22
|
+
},
|
|
23
|
+
deleteProperty: (target, prop) => {
|
|
24
|
+
const key = wrapKey(prop);
|
|
25
|
+
if (typeof prop === 'string') {
|
|
26
|
+
delete keyMap[prop.toLowerCase()];
|
|
27
|
+
}
|
|
28
|
+
return Reflect.deleteProperty(target, key);
|
|
29
|
+
},
|
|
30
|
+
defineProperty: (target, prop, descriptor) => {
|
|
31
|
+
let key = prop;
|
|
32
|
+
if (typeof key === 'string') {
|
|
33
|
+
const keyLower = key.toLowerCase();
|
|
34
|
+
key = keyMap[keyLower] = keyMap[keyLower] || key;
|
|
35
|
+
}
|
|
36
|
+
return Reflect.defineProperty(target, key, descriptor);
|
|
37
|
+
},
|
|
38
|
+
getOwnPropertyDescriptor: (target, prop) => {
|
|
39
|
+
return Reflect.getOwnPropertyDescriptor(target, wrapKey(prop));
|
|
40
|
+
},
|
|
41
|
+
has: (target, prop) => {
|
|
42
|
+
return Reflect.has(target, wrapKey(prop));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const dotPattern = /^([^.]+)\.(.*)$/;
|
|
2
|
+
export function stringPathToObjectTree(arr) {
|
|
3
|
+
if (!arr.length)
|
|
4
|
+
return;
|
|
5
|
+
return _stringPathToObjectTree(arr, {});
|
|
6
|
+
}
|
|
7
|
+
function _stringPathToObjectTree(arr, target) {
|
|
8
|
+
for (const k of arr) {
|
|
9
|
+
const m = dotPattern.exec(k);
|
|
10
|
+
if (m) {
|
|
11
|
+
const key = m[1];
|
|
12
|
+
if (target[key] === true)
|
|
13
|
+
continue;
|
|
14
|
+
const sub = target[key] = typeof target[key] === 'object' ? target[key] : {};
|
|
15
|
+
_stringPathToObjectTree([m[2]], sub);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
target[k] = true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return target;
|
|
22
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opra/core",
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "Opra schema package",
|
|
5
|
+
"author": "Panates",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/panates/opra.git",
|
|
10
|
+
"directory": "packages/core"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"compile": "tsc",
|
|
14
|
+
"prebuild": "npm run lint && npm run clean",
|
|
15
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
16
|
+
"build:cjs": "tsc -b tsconfig-build-cjs.json",
|
|
17
|
+
"build:esm": "tsc -b tsconfig-build-esm.json",
|
|
18
|
+
"postbuild": "cp README.md package.json ../../LICENSE ../../build/core && cp ../../package.cjs.json ../../build/core/cjs/package.json",
|
|
19
|
+
"lint": "eslint .",
|
|
20
|
+
"test": "jest",
|
|
21
|
+
"cover": "jest --collect-coverage",
|
|
22
|
+
"clean": "npm run clean:src && npm run clean:dist && npm run clean:cover",
|
|
23
|
+
"clean:src": "ts-cleanup -s src --all",
|
|
24
|
+
"clean:dist": "rimraf ../../build/core",
|
|
25
|
+
"clean:cover": "rimraf ../../coverage/core"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@opra/url": "0.x.x",
|
|
29
|
+
"@opra/i18n": "0.x.x",
|
|
30
|
+
"@opra/schema": "0.x.x",
|
|
31
|
+
"@opra/optionals": "0.x.x",
|
|
32
|
+
"ts-gems": "^2.2.0",
|
|
33
|
+
"lodash": "^4.17.21",
|
|
34
|
+
"putil-isplainobject": "^1.1.4",
|
|
35
|
+
"putil-varhelpers": "^1.6.4",
|
|
36
|
+
"rule-judgment": "^1.1.5"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/express": "^4.17.13",
|
|
40
|
+
"express": "^4.18.1"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {},
|
|
43
|
+
"type": "module",
|
|
44
|
+
"main": "cjs/index.js",
|
|
45
|
+
"module": "esm/index.js",
|
|
46
|
+
"types": "esm/index.d.ts",
|
|
47
|
+
"exports": {
|
|
48
|
+
".": {
|
|
49
|
+
"require": "./cjs/index.js",
|
|
50
|
+
"default": "./esm/index.js"
|
|
51
|
+
},
|
|
52
|
+
"./cjs": "./cjs/index.js",
|
|
53
|
+
"./esm": "./esm/index.js"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=16.0",
|
|
57
|
+
"npm": ">=7.0.0"
|
|
58
|
+
},
|
|
59
|
+
"files": [
|
|
60
|
+
"bin/",
|
|
61
|
+
"cjs/",
|
|
62
|
+
"esm/",
|
|
63
|
+
"LICENSE",
|
|
64
|
+
"README.md"
|
|
65
|
+
],
|
|
66
|
+
"keywords": [
|
|
67
|
+
"opra",
|
|
68
|
+
"rest",
|
|
69
|
+
"api",
|
|
70
|
+
"oas",
|
|
71
|
+
"open",
|
|
72
|
+
"swagger",
|
|
73
|
+
"raml",
|
|
74
|
+
"http",
|
|
75
|
+
"web"
|
|
76
|
+
]
|
|
77
|
+
}
|