@opra/core 0.0.13 → 0.1.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/enums/http-headers.enum.js +2 -1
- package/cjs/implementation/adapter-utils/entity-resource-execute.util.js +84 -0
- package/cjs/implementation/adapter-utils/resource-execute.util.js +11 -0
- package/cjs/implementation/adapter-utils/resource-prepare.util.js +11 -0
- package/cjs/implementation/{adapter/adapter.js → adapter.js} +21 -18
- package/cjs/implementation/{adapter/express-adapter.js → express-adapter.js} +0 -0
- package/cjs/implementation/{adapter/http-adapter.js → http-adapter.js} +26 -24
- package/cjs/implementation/query-context.js +5 -3
- package/cjs/index.js +5 -15
- package/cjs/{services/entity-resource-controller.js → interfaces/entity-service.interface.js} +0 -0
- package/cjs/interfaces/query.interface.js +10 -10
- package/cjs/services/json-data-service.js +11 -5
- package/cjs/utils/{string-path-to-object-tree.js → path-to-tree.js} +3 -3
- package/esm/enums/http-headers.enum.d.ts +2 -1
- package/esm/enums/http-headers.enum.js +2 -1
- package/esm/implementation/adapter-utils/entity-resource-execute.util.d.ts +3 -0
- package/esm/implementation/adapter-utils/entity-resource-execute.util.js +80 -0
- package/esm/implementation/adapter-utils/resource-execute.util.d.ts +3 -0
- package/esm/implementation/adapter-utils/resource-execute.util.js +7 -0
- package/esm/implementation/adapter-utils/resource-prepare.util.d.ts +3 -0
- package/esm/implementation/adapter-utils/resource-prepare.util.js +7 -0
- package/esm/implementation/{adapter/adapter.d.ts → adapter.d.ts} +5 -5
- package/esm/implementation/{adapter/adapter.js → adapter.js} +18 -15
- package/esm/implementation/{adapter/express-adapter.d.ts → express-adapter.d.ts} +2 -2
- package/esm/implementation/{adapter/express-adapter.js → express-adapter.js} +0 -0
- package/esm/implementation/{adapter/http-adapter.d.ts → http-adapter.d.ts} +6 -7
- package/esm/implementation/{adapter/http-adapter.js → http-adapter.js} +25 -23
- package/esm/implementation/query-context.d.ts +3 -4
- package/esm/implementation/query-context.js +5 -3
- package/esm/index.d.ts +5 -15
- package/esm/index.js +5 -15
- package/esm/{services/entity-resource-controller.d.ts → interfaces/entity-service.interface.d.ts} +0 -0
- package/esm/{services/entity-resource-controller.js → interfaces/entity-service.interface.js} +0 -0
- package/esm/interfaces/query.interface.d.ts +25 -26
- package/esm/interfaces/query.interface.js +10 -10
- package/esm/services/json-data-service.d.ts +2 -2
- package/esm/services/json-data-service.js +11 -5
- package/esm/types.d.ts +1 -8
- package/esm/utils/create-i18n.d.ts +1 -1
- package/esm/utils/path-to-tree.d.ts +4 -0
- package/esm/utils/{string-path-to-object-tree.js → path-to-tree.js} +1 -1
- package/package.json +6 -6
- package/cjs/constants.js +0 -6
- package/cjs/decorators/api-entity-resource.decorator.js +0 -24
- package/cjs/decorators/api-resolver.decorator.js +0 -13
- package/cjs/implementation/data-type/complex-type.js +0 -53
- package/cjs/implementation/data-type/data-type.js +0 -47
- package/cjs/implementation/data-type/entity-type.js +0 -34
- package/cjs/implementation/data-type/simple-type.js +0 -30
- package/cjs/implementation/opra-document.js +0 -112
- package/cjs/implementation/opra-service.js +0 -81
- package/cjs/implementation/resource/container-resource-handler.js +0 -30
- package/cjs/implementation/resource/entity-resource-handler.js +0 -103
- package/cjs/implementation/resource/resource-handler.js +0 -45
- package/cjs/implementation/schema-generator.js +0 -184
- package/cjs/interfaces/metadata/api-resolver.metadata.js +0 -2
- package/cjs/interfaces/metadata/opra-schema.metadata.js +0 -11
- package/cjs/interfaces/resource-container.interface.js +0 -2
- package/cjs/utils/class-utils.js +0 -37
- package/cjs/utils/headers.js +0 -58
- package/cjs/utils/internal-data-types.js +0 -81
- package/cjs/utils/responsive-object.js +0 -49
- package/cjs/utils/terminal-utils.js +0 -7
- package/esm/constants.d.ts +0 -3
- package/esm/constants.js +0 -3
- package/esm/decorators/api-entity-resource.decorator.d.ts +0 -5
- package/esm/decorators/api-entity-resource.decorator.js +0 -19
- package/esm/decorators/api-resolver.decorator.d.ts +0 -2
- package/esm/decorators/api-resolver.decorator.js +0 -9
- package/esm/implementation/data-type/complex-type.d.ts +0 -19
- package/esm/implementation/data-type/complex-type.js +0 -48
- package/esm/implementation/data-type/data-type.d.ts +0 -17
- package/esm/implementation/data-type/data-type.js +0 -43
- package/esm/implementation/data-type/entity-type.d.ts +0 -10
- package/esm/implementation/data-type/entity-type.js +0 -29
- package/esm/implementation/data-type/simple-type.d.ts +0 -15
- package/esm/implementation/data-type/simple-type.js +0 -26
- package/esm/implementation/opra-document.d.ts +0 -26
- package/esm/implementation/opra-document.js +0 -107
- package/esm/implementation/opra-service.d.ts +0 -20
- package/esm/implementation/opra-service.js +0 -76
- package/esm/implementation/resource/container-resource-handler.d.ts +0 -14
- package/esm/implementation/resource/container-resource-handler.js +0 -26
- package/esm/implementation/resource/entity-resource-handler.d.ts +0 -18
- package/esm/implementation/resource/entity-resource-handler.js +0 -98
- package/esm/implementation/resource/resource-handler.d.ts +0 -15
- package/esm/implementation/resource/resource-handler.js +0 -40
- package/esm/implementation/schema-generator.d.ts +0 -21
- package/esm/implementation/schema-generator.js +0 -180
- package/esm/interfaces/metadata/api-resolver.metadata.d.ts +0 -3
- package/esm/interfaces/metadata/api-resolver.metadata.js +0 -1
- package/esm/interfaces/metadata/opra-schema.metadata.d.ts +0 -7
- package/esm/interfaces/metadata/opra-schema.metadata.js +0 -10
- package/esm/interfaces/resource-container.interface.d.ts +0 -6
- package/esm/interfaces/resource-container.interface.js +0 -1
- package/esm/utils/class-utils.d.ts +0 -6
- package/esm/utils/class-utils.js +0 -30
- package/esm/utils/headers.d.ts +0 -9
- package/esm/utils/headers.js +0 -55
- package/esm/utils/internal-data-types.d.ts +0 -5
- package/esm/utils/internal-data-types.js +0 -78
- package/esm/utils/responsive-object.d.ts +0 -3
- package/esm/utils/responsive-object.js +0 -45
- package/esm/utils/string-path-to-object-tree.d.ts +0 -4
- package/esm/utils/terminal-utils.d.ts +0 -4
- package/esm/utils/terminal-utils.js +0 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import { ComplexType } from '
|
|
3
|
-
import {
|
|
2
|
+
import { ComplexType } from '@opra/schema';
|
|
3
|
+
import { pathToTree } from '../utils/path-to-tree.js';
|
|
4
4
|
export var OpraQuery;
|
|
5
5
|
(function (OpraQuery) {
|
|
6
6
|
function forCreate(resource, values, options) {
|
|
@@ -21,7 +21,7 @@ export var OpraQuery;
|
|
|
21
21
|
return out;
|
|
22
22
|
}
|
|
23
23
|
OpraQuery.forCreate = forCreate;
|
|
24
|
-
function
|
|
24
|
+
function forGetSchema(resourcePath, options) {
|
|
25
25
|
// if (options?.pick)
|
|
26
26
|
// options.pick = normalizePick(resource, options.pick);
|
|
27
27
|
// if (options?.omit)
|
|
@@ -29,7 +29,7 @@ export var OpraQuery;
|
|
|
29
29
|
// if (options?.include)
|
|
30
30
|
// options.include = normalizePick(resource, options.include);
|
|
31
31
|
const out = {
|
|
32
|
-
queryType: '
|
|
32
|
+
queryType: 'schema',
|
|
33
33
|
scope: 'instance',
|
|
34
34
|
resourcePath,
|
|
35
35
|
operation: 'read',
|
|
@@ -37,7 +37,7 @@ export var OpraQuery;
|
|
|
37
37
|
Object.assign(out, _.omit(options, Object.keys(out)));
|
|
38
38
|
return out;
|
|
39
39
|
}
|
|
40
|
-
OpraQuery.
|
|
40
|
+
OpraQuery.forGetSchema = forGetSchema;
|
|
41
41
|
function forGetEntity(resource, key, options) {
|
|
42
42
|
if (options?.pick)
|
|
43
43
|
options.pick = normalizePick(resource, options.pick);
|
|
@@ -164,19 +164,19 @@ function checkKeyFields(resource, key) {
|
|
|
164
164
|
throw new Error(`"${resource.name}" has no primary key`);
|
|
165
165
|
}
|
|
166
166
|
function normalizePick(resource, fields) {
|
|
167
|
-
const fieldsTree =
|
|
167
|
+
const fieldsTree = pathToTree(fields) || {};
|
|
168
168
|
return _normalizeFieldsList([], resource.service, resource, resource.dataType, fieldsTree, '', {
|
|
169
|
-
|
|
169
|
+
additionalFields: true
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
function _normalizeFieldsList(target, service, resource, dataType, node, parentPath = '', options) {
|
|
173
173
|
let curPath = '';
|
|
174
174
|
for (const k of Object.keys(node)) {
|
|
175
175
|
const nodeVal = node[k];
|
|
176
|
-
const prop = dataType?.
|
|
176
|
+
const prop = dataType?.fields.get(k);
|
|
177
177
|
if (!prop) {
|
|
178
178
|
curPath = parentPath ? parentPath + '.' + k : k;
|
|
179
|
-
if (!options?.
|
|
179
|
+
if (!options?.additionalFields || (dataType && !dataType.additionalFields))
|
|
180
180
|
throw new TypeError(`Unknown field path "${resource.name + '.' + curPath}"`);
|
|
181
181
|
if (typeof nodeVal === 'object')
|
|
182
182
|
_normalizeFieldsList(target, service, resource, undefined, nodeVal, curPath, options);
|
|
@@ -187,7 +187,7 @@ function _normalizeFieldsList(target, service, resource, dataType, node, parentP
|
|
|
187
187
|
curPath = parentPath ? parentPath + '.' + prop.name : prop.name;
|
|
188
188
|
const propType = service.getDataType(prop.type || 'string');
|
|
189
189
|
if (typeof nodeVal === 'object') {
|
|
190
|
-
if (!(propType instanceof ComplexType))
|
|
190
|
+
if (!(propType && propType instanceof ComplexType))
|
|
191
191
|
throw new TypeError(`"${curPath}" is not a complex type and has no sub fields`);
|
|
192
192
|
if (target.findIndex(x => x === parentPath) >= 0)
|
|
193
193
|
continue;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Maybe } from 'ts-gems';
|
|
2
2
|
import { Expression } from '@opra/url';
|
|
3
3
|
import { QueryContext } from '../implementation/query-context.js';
|
|
4
|
+
import { IEntityService } from '../interfaces/entity-service.interface.js';
|
|
4
5
|
import { OpraQuery } from '../interfaces/query.interface.js';
|
|
5
6
|
import { EntityInput, EntityOutput, QueryType } from '../types.js';
|
|
6
|
-
import { IEntityService } from './entity-resource-controller.js';
|
|
7
7
|
export interface JsonDataServiceAgs<T> {
|
|
8
8
|
resourceName: string;
|
|
9
9
|
data: T[];
|
|
@@ -56,7 +56,7 @@ export declare class JsonDataService<T, TOutput = EntityOutput<T>> implements IE
|
|
|
56
56
|
updateMany(data: EntityInput<T>, options?: JsonDataService.UpdateManyOptions): number;
|
|
57
57
|
delete(keyValue: any): boolean;
|
|
58
58
|
deleteMany(options?: JsonDataService.DeleteManyOptions): number;
|
|
59
|
-
static
|
|
59
|
+
static filterFields(obj: any, pick: string[] | undefined, omit: string[] | undefined, include: string[] | undefined): any;
|
|
60
60
|
static prepare(query: OpraQuery): {
|
|
61
61
|
method: QueryType;
|
|
62
62
|
options: any;
|
|
@@ -25,7 +25,7 @@ export class JsonDataService {
|
|
|
25
25
|
get(keyValue, options) {
|
|
26
26
|
const primaryKey = this.primaryKey;
|
|
27
27
|
let v = this.data.find(x => '' + x[primaryKey] === '' + keyValue);
|
|
28
|
-
v = JsonDataService.
|
|
28
|
+
v = JsonDataService.filterFields(v, options?.pick, options?.omit, options?.include);
|
|
29
29
|
return v;
|
|
30
30
|
}
|
|
31
31
|
count(options) {
|
|
@@ -40,20 +40,20 @@ export class JsonDataService {
|
|
|
40
40
|
}
|
|
41
41
|
else
|
|
42
42
|
out = this.data;
|
|
43
|
-
return out.map(v => JsonDataService.
|
|
43
|
+
return out.map(v => JsonDataService.filterFields(v, options?.pick, options?.omit, options?.include));
|
|
44
44
|
}
|
|
45
45
|
create(data, options) {
|
|
46
46
|
if (this.get(data[this.primaryKey]))
|
|
47
47
|
throw new ResourceConflictError(this.resourceName, this.primaryKey);
|
|
48
48
|
this.data.push(data);
|
|
49
|
-
return JsonDataService.
|
|
49
|
+
return JsonDataService.filterFields(data, options?.pick, options?.omit, options?.include);
|
|
50
50
|
}
|
|
51
51
|
update(keyValue, data, options) {
|
|
52
52
|
const primaryKey = this.primaryKey;
|
|
53
53
|
const i = this.data.findIndex(x => '' + x[primaryKey] === '' + keyValue);
|
|
54
54
|
if (i >= 0) {
|
|
55
55
|
data = Object.assign(this.data[i], data);
|
|
56
|
-
return JsonDataService.
|
|
56
|
+
return JsonDataService.filterFields(data, options?.pick, options?.omit, options?.include);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
updateMany(data, options) {
|
|
@@ -77,7 +77,13 @@ export class JsonDataService {
|
|
|
77
77
|
this.data = this.data.filter(x => !items.includes(x));
|
|
78
78
|
return items.length;
|
|
79
79
|
}
|
|
80
|
-
static
|
|
80
|
+
static filterFields(obj,
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
82
|
+
pick,
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
84
|
+
omit,
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
86
|
+
include) {
|
|
81
87
|
if (!obj)
|
|
82
88
|
return;
|
|
83
89
|
return obj;
|
package/esm/types.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import type { Type } from 'ts-gems';
|
|
2
1
|
import { Builtin, DeepPickWritable } from 'ts-gems';
|
|
3
2
|
import { OpraSchema } from '@opra/schema';
|
|
4
|
-
export declare type
|
|
5
|
-
export declare type ThunkAsync<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
|
|
6
|
-
export declare type TypeThunk<T = any> = Thunk<Type<T>>;
|
|
7
|
-
export declare type TypeThunkAsync<T = any> = ThunkAsync<Type<T>>;
|
|
8
|
-
export declare type QueryScope = 'collection' | 'instance' | 'property';
|
|
9
|
-
export declare type QueryType = OpraSchema.EntityResolverType | 'metadata' | 'execute';
|
|
10
|
-
export declare type OperationType = 'create' | 'read' | 'update' | 'patch' | 'delete' | 'execute';
|
|
3
|
+
export declare type QueryType = OpraSchema.EntityMethodType | 'schema' | 'execute';
|
|
11
4
|
export declare type KeyValue = string | number | boolean | object;
|
|
12
5
|
export declare type EntityInput<T> = DeepNullableIfPartial<DeepPickWritable<T>>;
|
|
13
6
|
export declare type EntityOutput<T> = DeepNullableIfPartial<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"clean:cover": "rimraf ../../coverage/core"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@opra/i18n": "^0.
|
|
31
|
-
"@opra/optionals": "^0.
|
|
32
|
-
"@opra/schema": "^0.
|
|
33
|
-
"@opra/url": "^0.
|
|
30
|
+
"@opra/i18n": "^0.1.1",
|
|
31
|
+
"@opra/optionals": "^0.1.1",
|
|
32
|
+
"@opra/schema": "^0.1.1",
|
|
33
|
+
"@opra/url": "^0.1.1",
|
|
34
34
|
"lodash": "^4.17.21",
|
|
35
35
|
"putil-isplainobject": "^1.1.4",
|
|
36
36
|
"putil-varhelpers": "^1.6.4",
|
|
37
|
-
"putil-merge": "^3.
|
|
37
|
+
"putil-merge": "^3.9.0",
|
|
38
38
|
"rule-judgment": "^1.1.5",
|
|
39
39
|
"strict-typed-events": "^2.2.0",
|
|
40
40
|
"ts-gems": "^2.2.0"
|
package/cjs/constants.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RESOLVER_METADATA = exports.RESOURCE_METADATA = exports.OpraVersion = void 0;
|
|
4
|
-
exports.OpraVersion = '1.0';
|
|
5
|
-
exports.RESOURCE_METADATA = 'opra:resource.metadata';
|
|
6
|
-
exports.RESOLVER_METADATA = 'opra:resolver.metadata';
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiEntityResource = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
require("reflect-metadata");
|
|
6
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
7
|
-
const constants_js_1 = require("../constants.js");
|
|
8
|
-
const NESTJS_INJECTABLE_WATERMARK = '__injectable__';
|
|
9
|
-
const NAME_PATTERN = /^(.*)Resource$/;
|
|
10
|
-
function ApiEntityResource(entityFunc, options) {
|
|
11
|
-
return function (target) {
|
|
12
|
-
const name = options?.name || target.name.match(NAME_PATTERN)?.[1] || target.name;
|
|
13
|
-
const meta = {
|
|
14
|
-
kind: 'EntityResource',
|
|
15
|
-
type: entityFunc,
|
|
16
|
-
name
|
|
17
|
-
};
|
|
18
|
-
Object.assign(meta, lodash_1.default.omit(options, Object.keys(meta)));
|
|
19
|
-
Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, meta, target);
|
|
20
|
-
/* Define Injectable metadata for NestJS support*/
|
|
21
|
-
Reflect.defineMetadata(NESTJS_INJECTABLE_WATERMARK, true, target);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
exports.ApiEntityResource = ApiEntityResource;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiResolver = void 0;
|
|
4
|
-
const constants_js_1 = require("../constants.js");
|
|
5
|
-
function ApiResolver(options) {
|
|
6
|
-
return (target, propertyKey) => {
|
|
7
|
-
const metadata = {
|
|
8
|
-
...options
|
|
9
|
-
};
|
|
10
|
-
Reflect.defineMetadata(constants_js_1.RESOLVER_METADATA, metadata, target, propertyKey);
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
exports.ApiResolver = ApiResolver;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ComplexType = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
6
|
-
const responsive_object_js_1 = require("../../utils/responsive-object.js");
|
|
7
|
-
const terminal_utils_js_1 = require("../../utils/terminal-utils.js");
|
|
8
|
-
const data_type_js_1 = require("./data-type.js");
|
|
9
|
-
class ComplexType extends data_type_js_1.DataType {
|
|
10
|
-
ownProperties;
|
|
11
|
-
properties;
|
|
12
|
-
constructor(owner, args, base) {
|
|
13
|
-
super(owner, {
|
|
14
|
-
kind: 'ComplexType',
|
|
15
|
-
...args
|
|
16
|
-
}, base);
|
|
17
|
-
this.ownProperties = args?.properties && (0, responsive_object_js_1.Responsive)(args.properties);
|
|
18
|
-
this.properties = (base?.properties || this.ownProperties) &&
|
|
19
|
-
(0, responsive_object_js_1.Responsive)({ ...base?.properties, ...this.ownProperties });
|
|
20
|
-
}
|
|
21
|
-
get abstract() {
|
|
22
|
-
return !!this._args.abstract;
|
|
23
|
-
}
|
|
24
|
-
get additionalProperties() {
|
|
25
|
-
return this._args.additionalProperties;
|
|
26
|
-
}
|
|
27
|
-
getProperty(name) {
|
|
28
|
-
const t = this.properties?.[name];
|
|
29
|
-
if (!t)
|
|
30
|
-
throw new Error(`"${this.name}" type has no property named "${name}"`);
|
|
31
|
-
return t;
|
|
32
|
-
}
|
|
33
|
-
getMetadata() {
|
|
34
|
-
const out = super.getMetadata();
|
|
35
|
-
if (this.additionalProperties)
|
|
36
|
-
out.additionalProperties = this.additionalProperties;
|
|
37
|
-
if (this.ownProperties) {
|
|
38
|
-
out.properties = {};
|
|
39
|
-
for (const [k, prop] of Object.entries(this.ownProperties)) {
|
|
40
|
-
out.properties[k] = (0, putil_merge_1.default)({}, prop, { deep: true });
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return out;
|
|
44
|
-
}
|
|
45
|
-
toString() {
|
|
46
|
-
return `[${Object.getPrototypeOf(this).constructor.name} ${this.name}]`;
|
|
47
|
-
}
|
|
48
|
-
[terminal_utils_js_1.nodeInspectCustom]() {
|
|
49
|
-
return `[${terminal_utils_js_1.colorFgYellow + Object.getPrototypeOf(this).constructor.name + terminal_utils_js_1.colorReset}` +
|
|
50
|
-
` ${terminal_utils_js_1.colorFgMagenta + this.name + terminal_utils_js_1.colorReset}]`;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.ComplexType = ComplexType;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataType = void 0;
|
|
4
|
-
class DataType {
|
|
5
|
-
_owner;
|
|
6
|
-
_args;
|
|
7
|
-
base;
|
|
8
|
-
constructor(owner, args, base) {
|
|
9
|
-
this._args = { ...args };
|
|
10
|
-
this._owner = owner;
|
|
11
|
-
if (base) {
|
|
12
|
-
this.base = base;
|
|
13
|
-
Object.setPrototypeOf(this._args, base._args);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
get owner() {
|
|
17
|
-
return this._owner;
|
|
18
|
-
}
|
|
19
|
-
get kind() {
|
|
20
|
-
return this._args.kind;
|
|
21
|
-
}
|
|
22
|
-
get name() {
|
|
23
|
-
return this._args.name;
|
|
24
|
-
}
|
|
25
|
-
get description() {
|
|
26
|
-
return this._args.description;
|
|
27
|
-
}
|
|
28
|
-
get abstract() {
|
|
29
|
-
return !!this._args.abstract;
|
|
30
|
-
}
|
|
31
|
-
get ctor() {
|
|
32
|
-
return this._args.ctor;
|
|
33
|
-
}
|
|
34
|
-
is(typeName) {
|
|
35
|
-
return this.name === typeName || !!(this.base && this.base.is(typeName));
|
|
36
|
-
}
|
|
37
|
-
getMetadata() {
|
|
38
|
-
return {
|
|
39
|
-
kind: this.kind,
|
|
40
|
-
base: this.base?.name,
|
|
41
|
-
abstract: this.abstract ? true : undefined,
|
|
42
|
-
name: this.name,
|
|
43
|
-
description: this.description,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.DataType = DataType;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EntityType = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const Optionals = tslib_1.__importStar(require("@opra/optionals"));
|
|
6
|
-
const complex_type_js_1 = require("./complex-type.js");
|
|
7
|
-
class EntityType extends complex_type_js_1.ComplexType {
|
|
8
|
-
constructor(owner, args, base) {
|
|
9
|
-
super(owner, {
|
|
10
|
-
...args
|
|
11
|
-
}, base);
|
|
12
|
-
this._args.kind = 'EntityType';
|
|
13
|
-
// Try to determine primary key info from SQB
|
|
14
|
-
if (Optionals.SqbConnect && args.ctor) {
|
|
15
|
-
const sqbEntity = Optionals.SqbConnect.EntityMetadata.get(args.ctor);
|
|
16
|
-
if (sqbEntity?.indexes) {
|
|
17
|
-
const primaryIndex = sqbEntity.indexes.find(x => x.primary);
|
|
18
|
-
if (primaryIndex) {
|
|
19
|
-
if (primaryIndex.columns.length > 1)
|
|
20
|
-
throw new TypeError(`Multi-key indexes is not implemented yet`);
|
|
21
|
-
this._args.primaryKey = primaryIndex.columns[0];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (!this.primaryKey)
|
|
26
|
-
throw new TypeError(`You must provide primaryKey fo "${this.name}" entity`);
|
|
27
|
-
if (!this.getProperty(this.primaryKey))
|
|
28
|
-
throw new TypeError(`"${this.name}" entity has no such property named "${this.primaryKey}" which defined as primary key`);
|
|
29
|
-
}
|
|
30
|
-
get primaryKey() {
|
|
31
|
-
return this._args.primaryKey;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.EntityType = EntityType;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimpleType = void 0;
|
|
4
|
-
const terminal_utils_js_1 = require("../../utils/terminal-utils.js");
|
|
5
|
-
const data_type_js_1 = require("./data-type.js");
|
|
6
|
-
class SimpleType extends data_type_js_1.DataType {
|
|
7
|
-
constructor(owner, args, base) {
|
|
8
|
-
super(owner, {
|
|
9
|
-
kind: 'SimpleType',
|
|
10
|
-
...args
|
|
11
|
-
}, base);
|
|
12
|
-
}
|
|
13
|
-
get type() {
|
|
14
|
-
return this._args.type;
|
|
15
|
-
}
|
|
16
|
-
get format() {
|
|
17
|
-
return this._args.format;
|
|
18
|
-
}
|
|
19
|
-
get default() {
|
|
20
|
-
return this._args.default;
|
|
21
|
-
}
|
|
22
|
-
toString() {
|
|
23
|
-
return `[${Object.getPrototypeOf(this).constructor.name} ${this.name}]`;
|
|
24
|
-
}
|
|
25
|
-
[terminal_utils_js_1.nodeInspectCustom]() {
|
|
26
|
-
return `[${terminal_utils_js_1.colorFgYellow + Object.getPrototypeOf(this).constructor.name + terminal_utils_js_1.colorReset}` +
|
|
27
|
-
` ${terminal_utils_js_1.colorFgMagenta + this.name + terminal_utils_js_1.colorReset}]`;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.SimpleType = SimpleType;
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpraDocument = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
|
-
const schema_1 = require("@opra/schema");
|
|
7
|
-
const internal_data_types_js_1 = require("../utils/internal-data-types.js");
|
|
8
|
-
const responsive_object_js_1 = require("../utils/responsive-object.js");
|
|
9
|
-
const terminal_utils_js_1 = require("../utils/terminal-utils.js");
|
|
10
|
-
const complex_type_js_1 = require("./data-type/complex-type.js");
|
|
11
|
-
const entity_type_js_1 = require("./data-type/entity-type.js");
|
|
12
|
-
const simple_type_js_1 = require("./data-type/simple-type.js");
|
|
13
|
-
const schema_generator_js_1 = require("./schema-generator.js");
|
|
14
|
-
class OpraDocument {
|
|
15
|
-
_args;
|
|
16
|
-
_types = (0, responsive_object_js_1.Responsive)();
|
|
17
|
-
constructor(schema) {
|
|
18
|
-
this._args = lodash_1.default.omit(schema, 'types');
|
|
19
|
-
if (schema.types)
|
|
20
|
-
this._addDataTypes(schema.types);
|
|
21
|
-
}
|
|
22
|
-
get name() {
|
|
23
|
-
return this._args.info?.title || '';
|
|
24
|
-
}
|
|
25
|
-
get info() {
|
|
26
|
-
return this._args.info;
|
|
27
|
-
}
|
|
28
|
-
get types() {
|
|
29
|
-
return this._types;
|
|
30
|
-
}
|
|
31
|
-
getDataType(name) {
|
|
32
|
-
const t = this.types[name];
|
|
33
|
-
if (!t)
|
|
34
|
-
throw new Error(`Data type "${name}" does not exists`);
|
|
35
|
-
return t;
|
|
36
|
-
}
|
|
37
|
-
getComplexDataType(name) {
|
|
38
|
-
const t = this.getDataType(name);
|
|
39
|
-
if (!(t instanceof complex_type_js_1.ComplexType))
|
|
40
|
-
throw new Error(`Data type "${name}" is not a ComplexType`);
|
|
41
|
-
return t;
|
|
42
|
-
}
|
|
43
|
-
getEntityDataType(name) {
|
|
44
|
-
const t = this.getDataType(name);
|
|
45
|
-
if (!(t instanceof entity_type_js_1.EntityType))
|
|
46
|
-
throw new Error(`Data type "${name}" is not an EntityType`);
|
|
47
|
-
return t;
|
|
48
|
-
}
|
|
49
|
-
getSimpleDataType(name) {
|
|
50
|
-
const t = this.getDataType(name);
|
|
51
|
-
if (!(t instanceof simple_type_js_1.SimpleType))
|
|
52
|
-
throw new Error(`Data type "${name}" is not a SimpleType`);
|
|
53
|
-
return t;
|
|
54
|
-
}
|
|
55
|
-
toString() {
|
|
56
|
-
return `[${Object.getPrototypeOf(this).constructor.name} ${this.name}]`;
|
|
57
|
-
}
|
|
58
|
-
[terminal_utils_js_1.nodeInspectCustom]() {
|
|
59
|
-
return `[${terminal_utils_js_1.colorFgYellow + Object.getPrototypeOf(this).constructor.name + terminal_utils_js_1.colorReset}` +
|
|
60
|
-
` ${terminal_utils_js_1.colorFgMagenta + this.name + terminal_utils_js_1.colorReset}]`;
|
|
61
|
-
}
|
|
62
|
-
static async create(args) {
|
|
63
|
-
const schema = await schema_generator_js_1.SchemaGenerator.generateDocumentSchema(args);
|
|
64
|
-
return new OpraDocument(schema);
|
|
65
|
-
}
|
|
66
|
-
_addDataTypes(dataTypes) {
|
|
67
|
-
const recursiveSet = new Set();
|
|
68
|
-
const nameSet = new Set(dataTypes.map(x => x.name));
|
|
69
|
-
const processDataType = (schema) => {
|
|
70
|
-
if ((!internal_data_types_js_1.internalDataTypes.has(schema.name) && !nameSet.has(schema.name)) || this.types[schema.name])
|
|
71
|
-
return;
|
|
72
|
-
if (recursiveSet.has(schema.name))
|
|
73
|
-
throw new TypeError(`Recursive dependency detected. ${Array.from(recursiveSet).join('>')}`);
|
|
74
|
-
recursiveSet.add(schema.name);
|
|
75
|
-
let baseType;
|
|
76
|
-
if (schema.base) {
|
|
77
|
-
baseType = this.types[schema.base];
|
|
78
|
-
if (!baseType) {
|
|
79
|
-
const baseSchema = dataTypes.find(dt => dt.name.toLowerCase() === schema.base?.toLowerCase()) ||
|
|
80
|
-
internal_data_types_js_1.internalDataTypes.get(schema.base.toLowerCase());
|
|
81
|
-
if (!baseSchema)
|
|
82
|
-
throw new TypeError(`Base schema (${schema.base}) of data type "${schema.name}" does not exists`);
|
|
83
|
-
baseType = processDataType(baseSchema);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
let dataType;
|
|
87
|
-
if (schema_1.OpraSchema.isSimpleType(schema)) {
|
|
88
|
-
if (baseType && !(baseType instanceof simple_type_js_1.SimpleType))
|
|
89
|
-
throw new TypeError(`Can't extend a SimpleType (${schema.name}) from a ComplexType "${baseType.name}"`);
|
|
90
|
-
dataType = new simple_type_js_1.SimpleType(this, schema, baseType);
|
|
91
|
-
}
|
|
92
|
-
else if (schema_1.OpraSchema.isComplexType(schema)) {
|
|
93
|
-
if (baseType && !(baseType instanceof complex_type_js_1.ComplexType))
|
|
94
|
-
throw new TypeError(`Can't extend a ComplexType (${schema.name}) from a SimpleType "${baseType.name}"`);
|
|
95
|
-
dataType = new complex_type_js_1.ComplexType(this, schema, baseType);
|
|
96
|
-
}
|
|
97
|
-
else if (schema_1.OpraSchema.isEntityType(schema)) {
|
|
98
|
-
if (baseType && !(baseType instanceof complex_type_js_1.ComplexType))
|
|
99
|
-
throw new TypeError(`Can't extend an EntityType (${schema.name}) from a SimpleType "${baseType.name}"`);
|
|
100
|
-
dataType = new entity_type_js_1.EntityType(this, schema, baseType);
|
|
101
|
-
}
|
|
102
|
-
else
|
|
103
|
-
throw new TypeError(`Invalid data type schema`);
|
|
104
|
-
nameSet.delete(schema.name);
|
|
105
|
-
this.types[dataType.name] = dataType;
|
|
106
|
-
recursiveSet.delete(schema.name);
|
|
107
|
-
return dataType;
|
|
108
|
-
};
|
|
109
|
-
dataTypes.forEach(dataType => processDataType(dataType));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
exports.OpraDocument = OpraDocument;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpraService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
6
|
-
const schema_1 = require("@opra/schema");
|
|
7
|
-
const constants_js_1 = require("../constants.js");
|
|
8
|
-
const internal_data_types_js_1 = require("../utils/internal-data-types.js");
|
|
9
|
-
const responsive_object_js_1 = require("../utils/responsive-object.js");
|
|
10
|
-
const entity_type_js_1 = require("./data-type/entity-type.js");
|
|
11
|
-
const opra_document_js_1 = require("./opra-document.js");
|
|
12
|
-
const entity_resource_handler_js_1 = require("./resource/entity-resource-handler.js");
|
|
13
|
-
const schema_generator_js_1 = require("./schema-generator.js");
|
|
14
|
-
class OpraService extends opra_document_js_1.OpraDocument {
|
|
15
|
-
_resources = (0, responsive_object_js_1.Responsive)();
|
|
16
|
-
constructor(schema) {
|
|
17
|
-
super(schema);
|
|
18
|
-
if (schema.resources)
|
|
19
|
-
this._addResources(schema.resources);
|
|
20
|
-
}
|
|
21
|
-
get resources() {
|
|
22
|
-
return this._resources;
|
|
23
|
-
}
|
|
24
|
-
get servers() {
|
|
25
|
-
return this._args.servers;
|
|
26
|
-
}
|
|
27
|
-
getResource(name) {
|
|
28
|
-
const t = this.resources[name];
|
|
29
|
-
if (!t)
|
|
30
|
-
throw new Error(`Resource "${name}" does not exists`);
|
|
31
|
-
return t;
|
|
32
|
-
}
|
|
33
|
-
getEntityResource(name) {
|
|
34
|
-
const t = this.getResource(name);
|
|
35
|
-
if (!(t instanceof entity_resource_handler_js_1.EntityResourceHandler))
|
|
36
|
-
throw new Error(`"${name}" is not an EntityResource`);
|
|
37
|
-
return t;
|
|
38
|
-
}
|
|
39
|
-
getMetadata() {
|
|
40
|
-
const out = {
|
|
41
|
-
'@opra:metadata': '/$metadata',
|
|
42
|
-
version: constants_js_1.OpraVersion,
|
|
43
|
-
servers: this.servers?.map(x => (0, putil_merge_1.default)({}, x, { deep: true })),
|
|
44
|
-
info: (0, putil_merge_1.default)({}, this.info, { deep: true }),
|
|
45
|
-
types: [],
|
|
46
|
-
resources: []
|
|
47
|
-
};
|
|
48
|
-
for (const [k, dataType] of Object.entries(this.types)) {
|
|
49
|
-
if (!internal_data_types_js_1.internalDataTypes.has(k))
|
|
50
|
-
out.types.push(dataType.getMetadata());
|
|
51
|
-
}
|
|
52
|
-
for (const resource of Object.values(this.resources)) {
|
|
53
|
-
out.resources.push(resource.getMetadata());
|
|
54
|
-
}
|
|
55
|
-
return out;
|
|
56
|
-
}
|
|
57
|
-
_addResources(resources) {
|
|
58
|
-
for (const r of resources) {
|
|
59
|
-
if (schema_1.OpraSchema.isEntityResource(r)) {
|
|
60
|
-
const dataType = this.getDataType(r.type);
|
|
61
|
-
if (!dataType)
|
|
62
|
-
throw new TypeError(`Datatype "${r.type}" declared in EntityResource (${r.name}) does not exists`);
|
|
63
|
-
if (!(dataType instanceof entity_type_js_1.EntityType))
|
|
64
|
-
throw new TypeError(`${r.type} is not an EntityType`);
|
|
65
|
-
this.resources[r.name] = new entity_resource_handler_js_1.EntityResourceHandler({ ...r, service: this, dataType });
|
|
66
|
-
}
|
|
67
|
-
else
|
|
68
|
-
throw new TypeError(`Unknown resource kind (${r.kind})`);
|
|
69
|
-
}
|
|
70
|
-
// Sort data types by name
|
|
71
|
-
const newResources = (0, responsive_object_js_1.Responsive)();
|
|
72
|
-
Object.keys(this.resources).sort()
|
|
73
|
-
.forEach(name => newResources[name] = this.resources[name]);
|
|
74
|
-
this._resources = newResources;
|
|
75
|
-
}
|
|
76
|
-
static async create(args) {
|
|
77
|
-
const schema = await schema_generator_js_1.SchemaGenerator.generateServiceSchema(args);
|
|
78
|
-
return new OpraService(schema);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.OpraService = OpraService;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ContainerResourceHandler = void 0;
|
|
4
|
-
const entity_resource_handler_js_1 = require("./entity-resource-handler.js");
|
|
5
|
-
const resource_handler_js_1 = require("./resource-handler.js");
|
|
6
|
-
class ContainerResourceHandler extends resource_handler_js_1.ResourceHandler {
|
|
7
|
-
constructor(args) {
|
|
8
|
-
super({
|
|
9
|
-
kind: 'ContainerResource',
|
|
10
|
-
...args
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
getResource(name) {
|
|
14
|
-
const t = this._args.resources[name];
|
|
15
|
-
if (!t)
|
|
16
|
-
throw new Error(`Resource "${name}" does not exists`);
|
|
17
|
-
return t;
|
|
18
|
-
}
|
|
19
|
-
getEntityResource(name) {
|
|
20
|
-
const t = this.getResource(name);
|
|
21
|
-
if (!(t instanceof entity_resource_handler_js_1.EntityResourceHandler))
|
|
22
|
-
throw new Error(`"${name}" is not an EntityResource`);
|
|
23
|
-
return t;
|
|
24
|
-
}
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
26
|
-
execute(ctx) {
|
|
27
|
-
return Promise.resolve(undefined);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.ContainerResourceHandler = ContainerResourceHandler;
|