@opra/core 0.0.13 → 0.1.0
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,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EntityResourceHandler = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
|
-
const i18n_1 = require("@opra/i18n");
|
|
7
|
-
const index_js_1 = require("../../exception/index.js");
|
|
8
|
-
const query_interface_js_1 = require("../../interfaces/query.interface.js");
|
|
9
|
-
const complex_type_js_1 = require("../data-type/complex-type.js");
|
|
10
|
-
const entity_type_js_1 = require("../data-type/entity-type.js");
|
|
11
|
-
const resource_handler_js_1 = require("./resource-handler.js");
|
|
12
|
-
class EntityResourceHandler extends resource_handler_js_1.ResourceHandler {
|
|
13
|
-
service;
|
|
14
|
-
dataType;
|
|
15
|
-
constructor(args) {
|
|
16
|
-
super({
|
|
17
|
-
kind: 'EntityResource',
|
|
18
|
-
...lodash_1.default.omit(args, ['dataType', 'service'])
|
|
19
|
-
});
|
|
20
|
-
this.dataType = args.dataType;
|
|
21
|
-
this.service = args.service;
|
|
22
|
-
// noinspection SuspiciousTypeOfGuard
|
|
23
|
-
if (!(args.dataType instanceof entity_type_js_1.EntityType))
|
|
24
|
-
throw new TypeError(`You should provide an EntityType for EntityResourceController`);
|
|
25
|
-
}
|
|
26
|
-
async execute(ctx) {
|
|
27
|
-
const { query } = ctx;
|
|
28
|
-
if (query_interface_js_1.OpraQuery.isSearchQuery(query)) {
|
|
29
|
-
const promises = [];
|
|
30
|
-
let search;
|
|
31
|
-
let count;
|
|
32
|
-
promises.push(this._executeFn(ctx, query.queryType)
|
|
33
|
-
.then(v => search = v));
|
|
34
|
-
if (query.count) {
|
|
35
|
-
promises.push(this._executeFn(ctx, 'count')
|
|
36
|
-
.then(v => count = v));
|
|
37
|
-
}
|
|
38
|
-
await Promise.all(promises);
|
|
39
|
-
ctx.response.value = {
|
|
40
|
-
...search,
|
|
41
|
-
...count
|
|
42
|
-
};
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
ctx.response.value = await this._executeFn(ctx, query.queryType);
|
|
46
|
-
}
|
|
47
|
-
async _executeFn(ctx, queryType) {
|
|
48
|
-
const resolverInfo = this._args.resolvers?.[queryType];
|
|
49
|
-
if (resolverInfo.forbidden || !resolverInfo.handler)
|
|
50
|
-
throw new index_js_1.ForbiddenError({
|
|
51
|
-
message: (0, i18n_1.translate)('RESOLVER_FORBIDDEN', { queryType }),
|
|
52
|
-
severity: 'error',
|
|
53
|
-
code: 'RESOLVER_FORBIDDEN'
|
|
54
|
-
});
|
|
55
|
-
let result = await resolverInfo.handler(ctx);
|
|
56
|
-
switch (queryType) {
|
|
57
|
-
case 'search':
|
|
58
|
-
return {
|
|
59
|
-
'@opra:metadata': '/$metadata/types/' + this.dataType.name,
|
|
60
|
-
items: Array.isArray(result) ? result : (ctx.response.value ? [result] : [])
|
|
61
|
-
};
|
|
62
|
-
case 'get':
|
|
63
|
-
case 'update':
|
|
64
|
-
if (!result) {
|
|
65
|
-
const query = ctx.query;
|
|
66
|
-
throw new index_js_1.ResourceNotFoundError(this.name, query.keyValue);
|
|
67
|
-
}
|
|
68
|
-
break;
|
|
69
|
-
case 'count':
|
|
70
|
-
return { count: result || 0 };
|
|
71
|
-
case 'delete':
|
|
72
|
-
case 'deleteMany':
|
|
73
|
-
case 'updateMany':
|
|
74
|
-
let affectedRecords;
|
|
75
|
-
if (typeof result === 'number')
|
|
76
|
-
affectedRecords = result;
|
|
77
|
-
if (typeof result === 'boolean')
|
|
78
|
-
affectedRecords = result ? 1 : 0;
|
|
79
|
-
if (typeof result === 'object')
|
|
80
|
-
affectedRecords = result.affectedRows || result.affectedRecords;
|
|
81
|
-
return { affectedRecords };
|
|
82
|
-
}
|
|
83
|
-
if (!result)
|
|
84
|
-
return;
|
|
85
|
-
result = Array.isArray(result) ? result[0] : result;
|
|
86
|
-
let dataType = this.dataType;
|
|
87
|
-
if (ctx.resultPath) {
|
|
88
|
-
const pathArray = ctx.resultPath.split('.');
|
|
89
|
-
for (const property of pathArray) {
|
|
90
|
-
const prop = dataType instanceof complex_type_js_1.ComplexType ? dataType.properties?.[property] : undefined;
|
|
91
|
-
dataType = prop && prop.type ? this.service.types[prop.type || 'string'] : undefined;
|
|
92
|
-
result = result && typeof result === 'object' && result[property];
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (queryType === 'create')
|
|
96
|
-
ctx.response.status = 201;
|
|
97
|
-
return {
|
|
98
|
-
'@opra:metadata': dataType ? '/$metadata/types/' + dataType.name : '__unknown__',
|
|
99
|
-
...result
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
exports.EntityResourceHandler = EntityResourceHandler;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResourceHandler = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
6
|
-
const terminal_utils_js_1 = require("../../utils/terminal-utils.js");
|
|
7
|
-
class ResourceHandler {
|
|
8
|
-
_args;
|
|
9
|
-
path;
|
|
10
|
-
constructor(args) {
|
|
11
|
-
this._args = args;
|
|
12
|
-
}
|
|
13
|
-
get name() {
|
|
14
|
-
return this._args.name;
|
|
15
|
-
}
|
|
16
|
-
get description() {
|
|
17
|
-
return this._args.description;
|
|
18
|
-
}
|
|
19
|
-
toString() {
|
|
20
|
-
return `[${Object.getPrototypeOf(this).constructor.name} ${this.name}]`;
|
|
21
|
-
}
|
|
22
|
-
async prepare(ctx) {
|
|
23
|
-
const { query } = ctx;
|
|
24
|
-
const fn = this._args['pre_' + query.queryType];
|
|
25
|
-
if (fn && typeof fn === 'function') {
|
|
26
|
-
await fn(ctx);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
getMetadata() {
|
|
30
|
-
return (0, putil_merge_1.default)({}, {
|
|
31
|
-
...this._args,
|
|
32
|
-
instance: undefined,
|
|
33
|
-
}, {
|
|
34
|
-
deep: true,
|
|
35
|
-
filter: (source, key) => {
|
|
36
|
-
return (key !== 'instance' && typeof source[key] !== 'function' && source[key] != null);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
[terminal_utils_js_1.nodeInspectCustom]() {
|
|
41
|
-
return `[${terminal_utils_js_1.colorFgYellow + Object.getPrototypeOf(this).constructor.name + terminal_utils_js_1.colorReset}` +
|
|
42
|
-
` ${terminal_utils_js_1.colorFgMagenta + this.name + terminal_utils_js_1.colorReset}]`;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.ResourceHandler = ResourceHandler;
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SchemaGenerator = void 0;
|
|
4
|
-
const types_1 = require("util/types");
|
|
5
|
-
const schema_1 = require("@opra/schema");
|
|
6
|
-
const constants_js_1 = require("../constants.js");
|
|
7
|
-
const class_utils_js_1 = require("../utils/class-utils.js");
|
|
8
|
-
const internal_data_types_js_1 = require("../utils/internal-data-types.js");
|
|
9
|
-
const entityMethods = ['search', 'count', 'create', 'get', 'update', 'updateMany', 'delete', 'deleteMany'];
|
|
10
|
-
class SchemaGenerator {
|
|
11
|
-
_dataTypes = {};
|
|
12
|
-
_resources = {};
|
|
13
|
-
constructor() {
|
|
14
|
-
//
|
|
15
|
-
}
|
|
16
|
-
async addDataType(thunk) {
|
|
17
|
-
thunk = (0, types_1.isPromise)(thunk) ? await thunk : thunk;
|
|
18
|
-
if (typeof thunk === 'function') {
|
|
19
|
-
if (!(0, class_utils_js_1.isConstructor)(thunk))
|
|
20
|
-
return this.addDataType(await thunk());
|
|
21
|
-
if (internal_data_types_js_1.builtinClassMap.has(thunk))
|
|
22
|
-
return this.addDataType(internal_data_types_js_1.builtinClassMap.get(thunk));
|
|
23
|
-
const ctor = thunk;
|
|
24
|
-
const metadata = Reflect.getOwnMetadata(schema_1.DATATYPE_METADATA, ctor);
|
|
25
|
-
if (!metadata)
|
|
26
|
-
throw new TypeError(`Class "${ctor}" has no type metadata`);
|
|
27
|
-
// Add base data type
|
|
28
|
-
let base;
|
|
29
|
-
let baseCtor = Object.getPrototypeOf(ctor);
|
|
30
|
-
if (Reflect.hasMetadata(schema_1.DATATYPE_METADATA, baseCtor)) {
|
|
31
|
-
while (!Reflect.hasOwnMetadata(schema_1.DATATYPE_METADATA, baseCtor)) {
|
|
32
|
-
baseCtor = Object.getPrototypeOf(baseCtor);
|
|
33
|
-
}
|
|
34
|
-
const baseSchema = await this.addDataType(baseCtor);
|
|
35
|
-
base = baseSchema.name;
|
|
36
|
-
}
|
|
37
|
-
const schema = {
|
|
38
|
-
...metadata,
|
|
39
|
-
ctor,
|
|
40
|
-
base
|
|
41
|
-
};
|
|
42
|
-
const properties = Reflect.getMetadata(schema_1.DATATYPE_PROPERTIES, ctor.prototype);
|
|
43
|
-
if (properties) {
|
|
44
|
-
for (const [k, p] of Object.entries(properties)) {
|
|
45
|
-
let type = p.type || 'string';
|
|
46
|
-
if (typeof type !== 'string') {
|
|
47
|
-
const propSchema = await this.addDataType(type);
|
|
48
|
-
type = propSchema.name;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
if (internal_data_types_js_1.internalDataTypes.has(type))
|
|
52
|
-
await this.addDataType(internal_data_types_js_1.internalDataTypes.get(type));
|
|
53
|
-
}
|
|
54
|
-
schema.properties = schema.properties || {};
|
|
55
|
-
schema.properties[k] = { ...p, type };
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return this.addDataType(schema);
|
|
59
|
-
}
|
|
60
|
-
if (!schema_1.OpraSchema.isDataType(thunk))
|
|
61
|
-
throw new TypeError(`Invalid data type schema`);
|
|
62
|
-
// Check if datatype previously added
|
|
63
|
-
const currentSchema = this._dataTypes[thunk.name];
|
|
64
|
-
if (currentSchema) {
|
|
65
|
-
if (!(currentSchema.kind === thunk.kind && currentSchema.ctor && currentSchema.ctor === thunk.ctor))
|
|
66
|
-
throw new Error(`An other instance of "${currentSchema.name}" data type previously defined`);
|
|
67
|
-
return currentSchema;
|
|
68
|
-
}
|
|
69
|
-
if (schema_1.OpraSchema.isSimpleType(thunk) && !internal_data_types_js_1.primitiveDataTypeNames.includes(thunk.type))
|
|
70
|
-
throw new Error(`"type" of SimpleType schema must be one of enumerated value (${internal_data_types_js_1.primitiveDataTypeNames})`);
|
|
71
|
-
return this._dataTypes[thunk.name] = {
|
|
72
|
-
...thunk
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
async addResource(instance) {
|
|
76
|
-
if ((0, class_utils_js_1.isConstructor)(instance))
|
|
77
|
-
throw new Error(`You should provide Resource instance instead of Resource class`);
|
|
78
|
-
const proto = Object.getPrototypeOf(instance);
|
|
79
|
-
const ctor = proto.constructor;
|
|
80
|
-
const metadata = Reflect.getMetadata(constants_js_1.RESOURCE_METADATA, ctor);
|
|
81
|
-
let resourceSchema;
|
|
82
|
-
if (metadata) {
|
|
83
|
-
const name = metadata.name || ctor.name.replace(/Resource$/, '');
|
|
84
|
-
const t = typeof metadata.type === 'function'
|
|
85
|
-
? await (0, class_utils_js_1.resolveClassAsync)(metadata.type)
|
|
86
|
-
: metadata.type;
|
|
87
|
-
const type = typeof t === 'function'
|
|
88
|
-
? (await this.addDataType(t)).name
|
|
89
|
-
: t;
|
|
90
|
-
resourceSchema = {
|
|
91
|
-
...metadata,
|
|
92
|
-
type,
|
|
93
|
-
name,
|
|
94
|
-
instance,
|
|
95
|
-
resolvers: {}
|
|
96
|
-
};
|
|
97
|
-
if (schema_1.OpraSchema.isEntityResource(resourceSchema)) {
|
|
98
|
-
for (const methodName of entityMethods) {
|
|
99
|
-
let fn = instance[methodName];
|
|
100
|
-
if (typeof fn === 'function') {
|
|
101
|
-
const info = resourceSchema.resolvers[methodName] = {
|
|
102
|
-
...Reflect.getMetadata(constants_js_1.RESOLVER_METADATA, proto, methodName)
|
|
103
|
-
};
|
|
104
|
-
if (!info.forbidden) {
|
|
105
|
-
info.handler = fn.bind(instance);
|
|
106
|
-
fn = instance['pre_' + methodName];
|
|
107
|
-
if (typeof fn === 'function')
|
|
108
|
-
resourceSchema['pre_' + methodName] = fn.bind(instance);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
else
|
|
112
|
-
resourceSchema.resolvers[methodName] = { forbidden: true };
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else
|
|
117
|
-
resourceSchema = instance;
|
|
118
|
-
if (schema_1.OpraSchema.isResource(resourceSchema)) {
|
|
119
|
-
if (schema_1.OpraSchema.isEntityResource(resourceSchema)) {
|
|
120
|
-
const t = this._dataTypes[resourceSchema.type];
|
|
121
|
-
if (!t)
|
|
122
|
-
throw new Error(`Resource registration error. Type "${resourceSchema.type}" not found.`);
|
|
123
|
-
if (this._resources[resourceSchema.name])
|
|
124
|
-
throw new Error(`An other instance of "${resourceSchema.name}" resource previously defined`);
|
|
125
|
-
this._resources[resourceSchema.name] = resourceSchema;
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
throw new Error(`Invalid resource metadata`);
|
|
129
|
-
}
|
|
130
|
-
throw new Error(`Invalid resource object`);
|
|
131
|
-
}
|
|
132
|
-
static async generateDocumentSchema(args) {
|
|
133
|
-
const generator = new SchemaGenerator();
|
|
134
|
-
if (args.types) {
|
|
135
|
-
for (const thunk of args.types) {
|
|
136
|
-
await generator.addDataType(thunk);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const types = Object.keys(generator._dataTypes).sort()
|
|
140
|
-
.map(name => generator._dataTypes[name]);
|
|
141
|
-
return {
|
|
142
|
-
version: '1',
|
|
143
|
-
...args,
|
|
144
|
-
types
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
static async generateServiceSchema(args) {
|
|
148
|
-
const generator = new SchemaGenerator();
|
|
149
|
-
if (args.types) {
|
|
150
|
-
for (const thunk of args.types) {
|
|
151
|
-
await generator.addDataType(thunk);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (args.resources) {
|
|
155
|
-
for (const resource of args.resources) {
|
|
156
|
-
await generator.addResource(resource);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
const types = Object.keys(generator._dataTypes)
|
|
160
|
-
.map(name => generator._dataTypes[name])
|
|
161
|
-
.sort((a, b) => {
|
|
162
|
-
if (a.kind !== b.kind) {
|
|
163
|
-
if (a.kind === 'SimpleType')
|
|
164
|
-
return -1;
|
|
165
|
-
if (b.kind === 'SimpleType')
|
|
166
|
-
return 1;
|
|
167
|
-
if (a.kind === 'ComplexType')
|
|
168
|
-
return -1;
|
|
169
|
-
if (b.kind === 'ComplexType')
|
|
170
|
-
return 1;
|
|
171
|
-
}
|
|
172
|
-
return (a.name < b.name ? -1 : 1);
|
|
173
|
-
});
|
|
174
|
-
const resources = Object.keys(generator._resources).sort()
|
|
175
|
-
.map(name => generator._resources[name]);
|
|
176
|
-
return {
|
|
177
|
-
version: '1',
|
|
178
|
-
...args,
|
|
179
|
-
types,
|
|
180
|
-
resources
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
exports.SchemaGenerator = SchemaGenerator;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/*
|
|
4
|
-
export type ResourceReadOperationMetadata = StrictOmit<OpraSchema.ResourceReadOperation, 'handler'>;
|
|
5
|
-
export type ResourceSearchOperationMetadata = StrictOmit<OpraSchema.ResourceSearchOperation, 'handler'>;
|
|
6
|
-
export type ResourceCreateOperationMetadata = StrictOmit<OpraSchema.ResourceCreateOperation, 'handler'>;
|
|
7
|
-
export type ResourceUpdateOperationMetadata = StrictOmit<OpraSchema.ResourceUpdateOperation, 'handler'>;
|
|
8
|
-
export type ResourcePatchOperationMetadata = StrictOmit<OpraSchema.ResourcePatchOperation, 'handler'>;
|
|
9
|
-
export type ResourceDeleteOperationMetadata = StrictOmit<OpraSchema.ResourceDeleteOperation, 'handler'>;
|
|
10
|
-
export type ResourceExecuteOperationMetadata = StrictOmit<OpraSchema.ResourceExecuteOperation, 'handler'>;
|
|
11
|
-
*/
|
package/cjs/utils/class-utils.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isInternalClass = exports.resolveClassAsync = exports.resolveClass = exports.isConstructor = void 0;
|
|
4
|
-
const knownInternalClasses = [String, Number, Boolean, Date];
|
|
5
|
-
function isConstructor(obj) {
|
|
6
|
-
return typeof obj === 'function' &&
|
|
7
|
-
!!(obj.prototype && obj.prototype.constructor);
|
|
8
|
-
}
|
|
9
|
-
exports.isConstructor = isConstructor;
|
|
10
|
-
function resolveClass(typeOrFunc) {
|
|
11
|
-
if (typeof typeOrFunc === 'function' && !isConstructor(typeOrFunc)) {
|
|
12
|
-
typeOrFunc = typeOrFunc();
|
|
13
|
-
if (isConstructor(typeOrFunc))
|
|
14
|
-
return typeOrFunc;
|
|
15
|
-
throw new TypeError(`Function must return a constructor`);
|
|
16
|
-
}
|
|
17
|
-
if (isConstructor(typeOrFunc))
|
|
18
|
-
return typeOrFunc;
|
|
19
|
-
throw new TypeError(`${typeOrFunc} is not a constructor`);
|
|
20
|
-
}
|
|
21
|
-
exports.resolveClass = resolveClass;
|
|
22
|
-
async function resolveClassAsync(typeOrFunc) {
|
|
23
|
-
if (typeof typeOrFunc === 'function' && !isConstructor(typeOrFunc)) {
|
|
24
|
-
typeOrFunc = await typeOrFunc();
|
|
25
|
-
if (isConstructor(typeOrFunc))
|
|
26
|
-
return typeOrFunc;
|
|
27
|
-
throw new TypeError(`Function must return a constructor`);
|
|
28
|
-
}
|
|
29
|
-
if (isConstructor(typeOrFunc))
|
|
30
|
-
return typeOrFunc;
|
|
31
|
-
throw new TypeError(`${typeOrFunc} is not a constructor`);
|
|
32
|
-
}
|
|
33
|
-
exports.resolveClassAsync = resolveClassAsync;
|
|
34
|
-
function isInternalClass(t) {
|
|
35
|
-
return knownInternalClasses.includes(t) || Buffer.isBuffer(t);
|
|
36
|
-
}
|
|
37
|
-
exports.isInternalClass = isInternalClass;
|
package/cjs/utils/headers.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Headers = void 0;
|
|
4
|
-
const index_js_1 = require("../enums/index.js");
|
|
5
|
-
const wellKnownHeaders = Object.values(index_js_1.HttpHeaders)
|
|
6
|
-
.reduce((target, k) => {
|
|
7
|
-
target[k.toLowerCase()] = k;
|
|
8
|
-
return target;
|
|
9
|
-
}, {});
|
|
10
|
-
const wrapKey = (prop) => {
|
|
11
|
-
return typeof prop == 'string' ? wellKnownHeaders[prop.toLowerCase()] || prop : prop;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Create a proxy that ensures header keys are always formatted according to well known header names
|
|
15
|
-
*/
|
|
16
|
-
var Headers;
|
|
17
|
-
(function (Headers) {
|
|
18
|
-
function from(obj) {
|
|
19
|
-
const headers = create();
|
|
20
|
-
for (const [k, v] of Object.entries(obj))
|
|
21
|
-
headers[k] = v;
|
|
22
|
-
return headers;
|
|
23
|
-
}
|
|
24
|
-
Headers.from = from;
|
|
25
|
-
function create() {
|
|
26
|
-
return new Proxy({}, {
|
|
27
|
-
set: (target, prop, value, receiver) => {
|
|
28
|
-
let key = prop;
|
|
29
|
-
if (typeof key === 'string')
|
|
30
|
-
key = wellKnownHeaders[key.toLowerCase()] || key;
|
|
31
|
-
const result = Reflect.set(target, key, value, receiver);
|
|
32
|
-
/* istanbul ignore next */
|
|
33
|
-
if (!result && Object.isFrozen(target))
|
|
34
|
-
throw new TypeError('Cannot add property, object is not extensible');
|
|
35
|
-
return result;
|
|
36
|
-
},
|
|
37
|
-
get: (target, prop, receiver) => {
|
|
38
|
-
return Reflect.get(target, wrapKey(prop), receiver);
|
|
39
|
-
},
|
|
40
|
-
deleteProperty: (target, prop) => {
|
|
41
|
-
return Reflect.deleteProperty(target, wrapKey(prop));
|
|
42
|
-
},
|
|
43
|
-
defineProperty: (target, prop, descriptor) => {
|
|
44
|
-
let key = prop;
|
|
45
|
-
if (typeof key === 'string')
|
|
46
|
-
key = wellKnownHeaders[key.toLowerCase()] || key;
|
|
47
|
-
return Reflect.defineProperty(target, key, descriptor);
|
|
48
|
-
},
|
|
49
|
-
getOwnPropertyDescriptor: (target, prop) => {
|
|
50
|
-
return Reflect.getOwnPropertyDescriptor(target, wrapKey(prop));
|
|
51
|
-
},
|
|
52
|
-
has: (target, prop) => {
|
|
53
|
-
return Reflect.has(target, wrapKey(prop));
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
Headers.create = create;
|
|
58
|
-
})(Headers = exports.Headers || (exports.Headers = {}));
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.internalDataTypes = exports.builtinClassMap = exports.primitiveDataTypeNames = void 0;
|
|
4
|
-
exports.primitiveDataTypeNames = ['boolean', 'number', 'string', 'null'];
|
|
5
|
-
exports.builtinClassMap = new Map();
|
|
6
|
-
exports.internalDataTypes = new Map();
|
|
7
|
-
const internalDataTypeArray = [
|
|
8
|
-
{
|
|
9
|
-
kind: 'SimpleType',
|
|
10
|
-
name: 'boolean',
|
|
11
|
-
type: 'boolean',
|
|
12
|
-
description: 'Simple true/false value',
|
|
13
|
-
ctor: Boolean
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
kind: 'SimpleType',
|
|
17
|
-
name: 'string',
|
|
18
|
-
type: 'string',
|
|
19
|
-
description: 'A sequence of characters',
|
|
20
|
-
ctor: String
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
kind: 'SimpleType',
|
|
24
|
-
name: 'number',
|
|
25
|
-
type: 'number',
|
|
26
|
-
description: 'Both Integer as well as Floating-Point numbers',
|
|
27
|
-
ctor: Number
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
kind: 'SimpleType',
|
|
31
|
-
name: 'integer',
|
|
32
|
-
type: 'number',
|
|
33
|
-
base: 'number',
|
|
34
|
-
description: 'Integer number',
|
|
35
|
-
ctor: Number
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
kind: 'ComplexType',
|
|
39
|
-
name: 'object',
|
|
40
|
-
description: 'Object type with additional properties',
|
|
41
|
-
additionalProperties: true,
|
|
42
|
-
ctor: Object
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
kind: 'SimpleType',
|
|
46
|
-
name: 'date',
|
|
47
|
-
type: 'string',
|
|
48
|
-
description: 'Date',
|
|
49
|
-
format: 'date',
|
|
50
|
-
ctor: Date
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
kind: 'SimpleType',
|
|
54
|
-
name: 'date-time',
|
|
55
|
-
type: 'string',
|
|
56
|
-
description: 'Date time value',
|
|
57
|
-
format: 'date-time',
|
|
58
|
-
ctor: Date
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
kind: 'SimpleType',
|
|
62
|
-
name: 'time',
|
|
63
|
-
type: 'string',
|
|
64
|
-
description: 'Time value',
|
|
65
|
-
format: 'time',
|
|
66
|
-
ctor: String
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
kind: 'SimpleType',
|
|
70
|
-
name: 'buffer',
|
|
71
|
-
type: 'string',
|
|
72
|
-
description: 'Buffer value',
|
|
73
|
-
format: 'base64',
|
|
74
|
-
ctor: Buffer
|
|
75
|
-
}
|
|
76
|
-
];
|
|
77
|
-
internalDataTypeArray.forEach(sch => {
|
|
78
|
-
exports.internalDataTypes.set(sch.name, sch);
|
|
79
|
-
if (sch.ctor && !exports.builtinClassMap.has(sch.ctor))
|
|
80
|
-
exports.builtinClassMap.set(sch.ctor, sch);
|
|
81
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Responsive = void 0;
|
|
4
|
-
function Responsive(wrapped) {
|
|
5
|
-
wrapped = wrapped || {};
|
|
6
|
-
const keyMap = {};
|
|
7
|
-
Object.keys(wrapped).forEach(k => keyMap[k.toLowerCase()] = k);
|
|
8
|
-
const wrapKey = (prop) => {
|
|
9
|
-
return typeof prop == 'string' ? keyMap[prop.toLowerCase()] : prop;
|
|
10
|
-
};
|
|
11
|
-
return new Proxy(wrapped, {
|
|
12
|
-
set: (target, prop, value, receiver) => {
|
|
13
|
-
let key = prop;
|
|
14
|
-
if (typeof key === 'string') {
|
|
15
|
-
const keyLower = key.toLowerCase();
|
|
16
|
-
key = keyMap[keyLower] = keyMap[keyLower] || key;
|
|
17
|
-
}
|
|
18
|
-
const result = Reflect.set(target, key, value, receiver);
|
|
19
|
-
if (!result && Object.isFrozen(target))
|
|
20
|
-
throw new TypeError('Cannot add property, object is not extensible');
|
|
21
|
-
return result;
|
|
22
|
-
},
|
|
23
|
-
get: (target, prop, receiver) => {
|
|
24
|
-
return Reflect.get(target, wrapKey(prop), receiver);
|
|
25
|
-
},
|
|
26
|
-
deleteProperty: (target, prop) => {
|
|
27
|
-
const key = wrapKey(prop);
|
|
28
|
-
if (typeof prop === 'string') {
|
|
29
|
-
delete keyMap[prop.toLowerCase()];
|
|
30
|
-
}
|
|
31
|
-
return Reflect.deleteProperty(target, key);
|
|
32
|
-
},
|
|
33
|
-
defineProperty: (target, prop, descriptor) => {
|
|
34
|
-
let key = prop;
|
|
35
|
-
if (typeof key === 'string') {
|
|
36
|
-
const keyLower = key.toLowerCase();
|
|
37
|
-
key = keyMap[keyLower] = keyMap[keyLower] || key;
|
|
38
|
-
}
|
|
39
|
-
return Reflect.defineProperty(target, key, descriptor);
|
|
40
|
-
},
|
|
41
|
-
getOwnPropertyDescriptor: (target, prop) => {
|
|
42
|
-
return Reflect.getOwnPropertyDescriptor(target, wrapKey(prop));
|
|
43
|
-
},
|
|
44
|
-
has: (target, prop) => {
|
|
45
|
-
return Reflect.has(target, wrapKey(prop));
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
exports.Responsive = Responsive;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.colorFgMagenta = exports.colorFgYellow = exports.colorReset = exports.nodeInspectCustom = void 0;
|
|
4
|
-
exports.nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
|
|
5
|
-
exports.colorReset = "\x1b[0m";
|
|
6
|
-
exports.colorFgYellow = "\x1b[33m";
|
|
7
|
-
exports.colorFgMagenta = "\x1b[35m";
|
package/esm/constants.d.ts
DELETED
package/esm/constants.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { EntityResourceMetadata } from '../interfaces/metadata/opra-schema.metadata.js';
|
|
3
|
-
import { TypeThunkAsync } from '../types.js';
|
|
4
|
-
export declare type EntityResourceOptions = Pick<EntityResourceMetadata, 'name' | 'description'> & {};
|
|
5
|
-
export declare function ApiEntityResource(entityFunc: TypeThunkAsync, options?: EntityResourceOptions): (target: Function) => void;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import { RESOURCE_METADATA } from '../constants.js';
|
|
4
|
-
const NESTJS_INJECTABLE_WATERMARK = '__injectable__';
|
|
5
|
-
const NAME_PATTERN = /^(.*)Resource$/;
|
|
6
|
-
export function ApiEntityResource(entityFunc, options) {
|
|
7
|
-
return function (target) {
|
|
8
|
-
const name = options?.name || target.name.match(NAME_PATTERN)?.[1] || target.name;
|
|
9
|
-
const meta = {
|
|
10
|
-
kind: 'EntityResource',
|
|
11
|
-
type: entityFunc,
|
|
12
|
-
name
|
|
13
|
-
};
|
|
14
|
-
Object.assign(meta, _.omit(options, Object.keys(meta)));
|
|
15
|
-
Reflect.defineMetadata(RESOURCE_METADATA, meta, target);
|
|
16
|
-
/* Define Injectable metadata for NestJS support*/
|
|
17
|
-
Reflect.defineMetadata(NESTJS_INJECTABLE_WATERMARK, true, target);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import { OpraSchema } from '@opra/schema';
|
|
3
|
-
import { ResponsiveObject } from '../../utils/responsive-object.js';
|
|
4
|
-
import { nodeInspectCustom } from '../../utils/terminal-utils.js';
|
|
5
|
-
import type { OpraDocument } from '../opra-document.js';
|
|
6
|
-
import { DataType } from './data-type.js';
|
|
7
|
-
export declare type ComplexTypeArgs = StrictOmit<OpraSchema.ComplexType, 'kind'>;
|
|
8
|
-
export declare class ComplexType extends DataType {
|
|
9
|
-
protected readonly _args: StrictOmit<ComplexTypeArgs, 'properties'>;
|
|
10
|
-
readonly ownProperties?: ResponsiveObject<OpraSchema.Property>;
|
|
11
|
-
readonly properties?: ResponsiveObject<OpraSchema.Property>;
|
|
12
|
-
constructor(owner: OpraDocument, args: ComplexTypeArgs, base?: ComplexType);
|
|
13
|
-
get abstract(): boolean;
|
|
14
|
-
get additionalProperties(): boolean | string | Pick<OpraSchema.Property, 'type' | 'format' | 'isArray' | 'enum'> | undefined;
|
|
15
|
-
getProperty(name: string): OpraSchema.Property;
|
|
16
|
-
getMetadata(): OpraSchema.ComplexTypeMetadata;
|
|
17
|
-
toString(): string;
|
|
18
|
-
[nodeInspectCustom](): string;
|
|
19
|
-
}
|