@opra/common 0.25.4 → 0.25.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/browser.js +83 -83
- package/cjs/document/decorators/build-operation-decorator.js +27 -0
- package/cjs/document/decorators/collection-decorator.js +11 -19
- package/cjs/document/decorators/singleton.decorator.js +5 -16
- package/cjs/document/decorators/storage.decorator.js +7 -15
- package/cjs/document/resource/endpoint.js +23 -18
- package/cjs/exception/opra-exception.js +18 -12
- package/cjs/http/opra-url-path.js +3 -0
- package/esm/document/decorators/build-operation-decorator.js +23 -0
- package/esm/document/decorators/collection-decorator.js +11 -19
- package/esm/document/decorators/singleton.decorator.js +5 -16
- package/esm/document/decorators/storage.decorator.js +7 -15
- package/esm/document/resource/endpoint.js +21 -17
- package/esm/exception/opra-exception.js +18 -12
- package/esm/http/opra-url-path.js +3 -0
- package/package.json +1 -1
- package/types/document/decorators/build-operation-decorator.d.ts +13 -0
- package/types/document/decorators/collection-decorator.d.ts +14 -11
- package/types/document/decorators/singleton.decorator.d.ts +4 -4
- package/types/document/decorators/storage.decorator.d.ts +9 -6
- package/types/document/resource/endpoint.d.ts +21 -14
- package/types/exception/opra-exception.d.ts +1 -1
- package/types/http/opra-url-path.d.ts +1 -0
package/browser.js
CHANGED
|
@@ -570,7 +570,7 @@ var OpraException = class extends Error {
|
|
|
570
570
|
this.initString(issue);
|
|
571
571
|
else if (issue instanceof Error)
|
|
572
572
|
this.initError(issue);
|
|
573
|
-
else
|
|
573
|
+
else
|
|
574
574
|
this.init(issue);
|
|
575
575
|
this.message = this.message || this.constructor.name;
|
|
576
576
|
}
|
|
@@ -592,25 +592,31 @@ var OpraException = class extends Error {
|
|
|
592
592
|
}, true);
|
|
593
593
|
}
|
|
594
594
|
init(issue) {
|
|
595
|
-
this.message = issue
|
|
596
|
-
this.severity = issue
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
595
|
+
this.message = issue?.message || this.constructor.name;
|
|
596
|
+
this.severity = issue?.severity || "error";
|
|
597
|
+
if (issue) {
|
|
598
|
+
this.system = issue.system;
|
|
599
|
+
this.code = issue.code;
|
|
600
|
+
this.details = issue.details;
|
|
601
|
+
}
|
|
600
602
|
}
|
|
601
603
|
initString(issue) {
|
|
602
|
-
this.
|
|
603
|
-
|
|
604
|
-
|
|
604
|
+
this.init({
|
|
605
|
+
message: String(issue || "") || this.constructor.name,
|
|
606
|
+
severity: "error",
|
|
607
|
+
code: this.constructor.name
|
|
608
|
+
});
|
|
605
609
|
}
|
|
606
610
|
initError(issue) {
|
|
607
611
|
if (typeof issue.status === "number")
|
|
608
612
|
this.status = issue.status;
|
|
609
613
|
else if (typeof issue.getStatus === "function")
|
|
610
614
|
this.status = issue.getStatus();
|
|
611
|
-
this.
|
|
612
|
-
|
|
613
|
-
|
|
615
|
+
this.init({
|
|
616
|
+
message: issue.message,
|
|
617
|
+
severity: issue.severity || "error",
|
|
618
|
+
code: issue.code || issue.constructor.name
|
|
619
|
+
});
|
|
614
620
|
}
|
|
615
621
|
};
|
|
616
622
|
|
|
@@ -2144,6 +2150,31 @@ __name(extractFieldSchema, "extractFieldSchema");
|
|
|
2144
2150
|
// ../../build/common/esm/document/resource/collection.js
|
|
2145
2151
|
import merge9 from "putil-merge";
|
|
2146
2152
|
|
|
2153
|
+
// ../../build/common/esm/document/decorators/build-operation-decorator.js
|
|
2154
|
+
import "reflect-metadata";
|
|
2155
|
+
function buildOperationDecorator(operation) {
|
|
2156
|
+
return (options) => {
|
|
2157
|
+
const mergeMetadata = {};
|
|
2158
|
+
const decorator = /* @__PURE__ */ __name((target, propertyKey) => {
|
|
2159
|
+
if (propertyKey !== operation)
|
|
2160
|
+
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
2161
|
+
const operationMeta = { ...options };
|
|
2162
|
+
const resourceMetadata = Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {};
|
|
2163
|
+
resourceMetadata.operations = resourceMetadata.operations || {};
|
|
2164
|
+
resourceMetadata.operations[operation] = operationMeta;
|
|
2165
|
+
Object.assign(operationMeta, mergeMetadata);
|
|
2166
|
+
Reflect.defineMetadata(RESOURCE_METADATA, resourceMetadata, target.constructor);
|
|
2167
|
+
}, "decorator");
|
|
2168
|
+
decorator.Parameter = (name) => {
|
|
2169
|
+
mergeMetadata.parameters = mergeMetadata.parameters || {};
|
|
2170
|
+
mergeMetadata.parameters[name] = {};
|
|
2171
|
+
return decorator;
|
|
2172
|
+
};
|
|
2173
|
+
return decorator;
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
__name(buildOperationDecorator, "buildOperationDecorator");
|
|
2177
|
+
|
|
2147
2178
|
// ../../build/common/esm/document/decorators/resource.decorator.js
|
|
2148
2179
|
import omit4 from "lodash.omit";
|
|
2149
2180
|
import merge6 from "putil-merge";
|
|
@@ -2185,14 +2216,17 @@ function CollectionDecorator(type, options) {
|
|
|
2185
2216
|
return ResourceDecorator(opra_schema_ns_exports.Collection.Kind, { ...options, type });
|
|
2186
2217
|
}
|
|
2187
2218
|
__name(CollectionDecorator, "CollectionDecorator");
|
|
2219
|
+
var operationDecorators = {
|
|
2220
|
+
Create: buildOperationDecorator("create"),
|
|
2221
|
+
Delete: buildOperationDecorator("delete"),
|
|
2222
|
+
DeleteMany: buildOperationDecorator("deleteMany"),
|
|
2223
|
+
Get: buildOperationDecorator("get"),
|
|
2224
|
+
FindMany: buildOperationDecorator("findMany"),
|
|
2225
|
+
Update: buildOperationDecorator("update"),
|
|
2226
|
+
UpdateMany: buildOperationDecorator("updateMany")
|
|
2227
|
+
};
|
|
2188
2228
|
Object.assign(CollectionDecorator, ResourceDecorator);
|
|
2189
|
-
CollectionDecorator
|
|
2190
|
-
CollectionDecorator.Delete = createOperationDecorator("delete");
|
|
2191
|
-
CollectionDecorator.DeleteMany = createOperationDecorator("deleteMany");
|
|
2192
|
-
CollectionDecorator.Get = createOperationDecorator("get");
|
|
2193
|
-
CollectionDecorator.FindMany = createOperationDecorator("findMany");
|
|
2194
|
-
CollectionDecorator.Update = createOperationDecorator("update");
|
|
2195
|
-
CollectionDecorator.UpdateMany = createOperationDecorator("updateMany");
|
|
2229
|
+
Object.assign(CollectionDecorator, operationDecorators);
|
|
2196
2230
|
CollectionDecorator.Action = function(options) {
|
|
2197
2231
|
const oldDecorator = ResourceDecorator.Action(options);
|
|
2198
2232
|
return (target, propertyKey) => {
|
|
@@ -2201,18 +2235,6 @@ CollectionDecorator.Action = function(options) {
|
|
|
2201
2235
|
return oldDecorator(target, propertyKey);
|
|
2202
2236
|
};
|
|
2203
2237
|
};
|
|
2204
|
-
function createOperationDecorator(operation) {
|
|
2205
|
-
return (options) => (target, propertyKey) => {
|
|
2206
|
-
if (propertyKey !== operation)
|
|
2207
|
-
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
2208
|
-
const operationMeta = { ...options };
|
|
2209
|
-
const sourceMetadata = Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {};
|
|
2210
|
-
sourceMetadata.operations = sourceMetadata.operations || {};
|
|
2211
|
-
sourceMetadata.operations[operation] = operationMeta;
|
|
2212
|
-
Reflect.defineMetadata(RESOURCE_METADATA, sourceMetadata, target.constructor);
|
|
2213
|
-
};
|
|
2214
|
-
}
|
|
2215
|
-
__name(createOperationDecorator, "createOperationDecorator");
|
|
2216
2238
|
|
|
2217
2239
|
// ../../build/common/esm/document/resource/collection-class.js
|
|
2218
2240
|
import * as vg4 from "valgen";
|
|
@@ -9934,17 +9956,16 @@ function _generateCodec(type, codec, options) {
|
|
|
9934
9956
|
__name(_generateCodec, "_generateCodec");
|
|
9935
9957
|
|
|
9936
9958
|
// ../../build/common/esm/document/resource/endpoint.js
|
|
9937
|
-
var Endpoint = class
|
|
9959
|
+
var Endpoint = class {
|
|
9938
9960
|
static {
|
|
9939
9961
|
__name(this, "Endpoint");
|
|
9940
9962
|
}
|
|
9941
9963
|
constructor(init) {
|
|
9964
|
+
Object.assign(this, init);
|
|
9942
9965
|
this.parameters = new ResponsiveMap();
|
|
9943
|
-
this.name = init.name;
|
|
9944
|
-
this.description = init.description;
|
|
9945
9966
|
if (init.parameters) {
|
|
9946
9967
|
for (const [n, p] of Object.entries(init.parameters)) {
|
|
9947
|
-
this.parameters.set(n, new
|
|
9968
|
+
this.parameters.set(n, new EndpointParameter(p));
|
|
9948
9969
|
}
|
|
9949
9970
|
}
|
|
9950
9971
|
}
|
|
@@ -9961,24 +9982,21 @@ var Endpoint = class _Endpoint {
|
|
|
9961
9982
|
return schema;
|
|
9962
9983
|
}
|
|
9963
9984
|
};
|
|
9964
|
-
|
|
9965
|
-
|
|
9966
|
-
|
|
9967
|
-
|
|
9968
|
-
|
|
9969
|
-
|
|
9970
|
-
Object.assign(this, init);
|
|
9971
|
-
}
|
|
9972
|
-
exportSchema() {
|
|
9973
|
-
return omitUndefined({
|
|
9974
|
-
type: typeof this.type === "string" ? this.type : this.type.exportSchema(),
|
|
9975
|
-
description: this.description,
|
|
9976
|
-
isArray: this.isArray
|
|
9977
|
-
});
|
|
9978
|
-
}
|
|
9985
|
+
var EndpointParameter = class {
|
|
9986
|
+
static {
|
|
9987
|
+
__name(this, "EndpointParameter");
|
|
9988
|
+
}
|
|
9989
|
+
constructor(init) {
|
|
9990
|
+
Object.assign(this, init);
|
|
9979
9991
|
}
|
|
9980
|
-
|
|
9981
|
-
|
|
9992
|
+
exportSchema() {
|
|
9993
|
+
return omitUndefined({
|
|
9994
|
+
type: typeof this.type === "string" ? this.type : this.type.exportSchema(),
|
|
9995
|
+
description: this.description,
|
|
9996
|
+
isArray: this.isArray
|
|
9997
|
+
});
|
|
9998
|
+
}
|
|
9999
|
+
};
|
|
9982
10000
|
|
|
9983
10001
|
// ../../build/common/esm/document/resource/resource.js
|
|
9984
10002
|
var Resource = class {
|
|
@@ -10194,10 +10212,10 @@ function SingletonDecorator(type, options) {
|
|
|
10194
10212
|
}
|
|
10195
10213
|
__name(SingletonDecorator, "SingletonDecorator");
|
|
10196
10214
|
Object.assign(SingletonDecorator, ResourceDecorator);
|
|
10197
|
-
SingletonDecorator.Create =
|
|
10198
|
-
SingletonDecorator.Get =
|
|
10199
|
-
SingletonDecorator.Delete =
|
|
10200
|
-
SingletonDecorator.Update =
|
|
10215
|
+
SingletonDecorator.Create = buildOperationDecorator("create");
|
|
10216
|
+
SingletonDecorator.Get = buildOperationDecorator("get");
|
|
10217
|
+
SingletonDecorator.Delete = buildOperationDecorator("delete");
|
|
10218
|
+
SingletonDecorator.Update = buildOperationDecorator("update");
|
|
10201
10219
|
SingletonDecorator.Action = function(options) {
|
|
10202
10220
|
const oldDecorator = ResourceDecorator.Action(options);
|
|
10203
10221
|
const operators = ["create", "delete", "get", "update"];
|
|
@@ -10207,18 +10225,6 @@ SingletonDecorator.Action = function(options) {
|
|
|
10207
10225
|
return oldDecorator(target, propertyKey);
|
|
10208
10226
|
};
|
|
10209
10227
|
};
|
|
10210
|
-
function createOperationDecorator2(operation) {
|
|
10211
|
-
return (options) => (target, propertyKey) => {
|
|
10212
|
-
if (propertyKey !== operation)
|
|
10213
|
-
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
10214
|
-
const operationMeta = { ...options };
|
|
10215
|
-
const sourceMetadata = Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {};
|
|
10216
|
-
sourceMetadata.operations = sourceMetadata.operations || {};
|
|
10217
|
-
sourceMetadata.operations[operation] = operationMeta;
|
|
10218
|
-
Reflect.defineMetadata(RESOURCE_METADATA, sourceMetadata, target.constructor);
|
|
10219
|
-
};
|
|
10220
|
-
}
|
|
10221
|
-
__name(createOperationDecorator2, "createOperationDecorator");
|
|
10222
10228
|
|
|
10223
10229
|
// ../../build/common/esm/document/resource/singleton-class.js
|
|
10224
10230
|
var SingletonClass = class extends Resource {
|
|
@@ -10291,10 +10297,13 @@ function StorageDecorator(options) {
|
|
|
10291
10297
|
return ResourceDecorator(opra_schema_ns_exports.Storage.Kind, options);
|
|
10292
10298
|
}
|
|
10293
10299
|
__name(StorageDecorator, "StorageDecorator");
|
|
10300
|
+
var operationDecorators2 = {
|
|
10301
|
+
Delete: buildOperationDecorator("delete"),
|
|
10302
|
+
Get: buildOperationDecorator("get"),
|
|
10303
|
+
Post: buildOperationDecorator("post")
|
|
10304
|
+
};
|
|
10294
10305
|
Object.assign(StorageDecorator, ResourceDecorator);
|
|
10295
|
-
StorageDecorator
|
|
10296
|
-
StorageDecorator.Get = createOperationDecorator3("get");
|
|
10297
|
-
StorageDecorator.Post = createOperationDecorator3("post");
|
|
10306
|
+
Object.assign(StorageDecorator, operationDecorators2);
|
|
10298
10307
|
StorageDecorator.Action = function(options) {
|
|
10299
10308
|
const oldDecorator = ResourceDecorator.Action(options);
|
|
10300
10309
|
const operators = ["delete", "get", "post"];
|
|
@@ -10304,18 +10313,6 @@ StorageDecorator.Action = function(options) {
|
|
|
10304
10313
|
return oldDecorator(target, propertyKey);
|
|
10305
10314
|
};
|
|
10306
10315
|
};
|
|
10307
|
-
function createOperationDecorator3(operation) {
|
|
10308
|
-
return (options) => (target, propertyKey) => {
|
|
10309
|
-
if (propertyKey !== operation)
|
|
10310
|
-
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
10311
|
-
const operationMeta = { ...options };
|
|
10312
|
-
const sourceMetadata = Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {};
|
|
10313
|
-
sourceMetadata.operations = sourceMetadata.operations || {};
|
|
10314
|
-
sourceMetadata.operations[operation] = operationMeta;
|
|
10315
|
-
Reflect.defineMetadata(RESOURCE_METADATA, sourceMetadata, target.constructor);
|
|
10316
|
-
};
|
|
10317
|
-
}
|
|
10318
|
-
__name(createOperationDecorator3, "createOperationDecorator");
|
|
10319
10316
|
|
|
10320
10317
|
// ../../build/common/esm/document/resource/storage-class.js
|
|
10321
10318
|
var StorageClass = class extends Resource {
|
|
@@ -10664,6 +10661,9 @@ var OpraURLPath = class _OpraURLPath {
|
|
|
10664
10661
|
get length() {
|
|
10665
10662
|
return this[kLength];
|
|
10666
10663
|
}
|
|
10664
|
+
slice(start, end) {
|
|
10665
|
+
return new _OpraURLPath(...[...this].slice(start, end));
|
|
10666
|
+
}
|
|
10667
10667
|
resolve(...items) {
|
|
10668
10668
|
this._resolve(items);
|
|
10669
10669
|
return this;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildOperationDecorator = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const constants_js_1 = require("../constants.js");
|
|
6
|
+
function buildOperationDecorator(operation) {
|
|
7
|
+
return (options) => {
|
|
8
|
+
const mergeMetadata = {};
|
|
9
|
+
const decorator = ((target, propertyKey) => {
|
|
10
|
+
if (propertyKey !== operation)
|
|
11
|
+
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
12
|
+
const operationMeta = { ...options };
|
|
13
|
+
const resourceMetadata = (Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, target.constructor) || {});
|
|
14
|
+
resourceMetadata.operations = resourceMetadata.operations || {};
|
|
15
|
+
resourceMetadata.operations[operation] = operationMeta;
|
|
16
|
+
Object.assign(operationMeta, mergeMetadata);
|
|
17
|
+
Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, resourceMetadata, target.constructor);
|
|
18
|
+
});
|
|
19
|
+
decorator.Parameter = (name) => {
|
|
20
|
+
mergeMetadata.parameters = mergeMetadata.parameters || {};
|
|
21
|
+
mergeMetadata.parameters[name] = {};
|
|
22
|
+
return decorator;
|
|
23
|
+
};
|
|
24
|
+
return decorator;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.buildOperationDecorator = buildOperationDecorator;
|
|
@@ -2,21 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CollectionDecorator = void 0;
|
|
4
4
|
const index_js_1 = require("../../schema/index.js");
|
|
5
|
-
const
|
|
5
|
+
const build_operation_decorator_js_1 = require("./build-operation-decorator.js");
|
|
6
6
|
const resource_decorator_js_1 = require("./resource.decorator.js");
|
|
7
7
|
const operationProperties = ['create', 'delete', 'deleteMany', 'get', 'findMany', 'update', 'updateMany'];
|
|
8
8
|
function CollectionDecorator(type, options) {
|
|
9
9
|
return (0, resource_decorator_js_1.ResourceDecorator)(index_js_1.OpraSchema.Collection.Kind, { ...options, type });
|
|
10
10
|
}
|
|
11
11
|
exports.CollectionDecorator = CollectionDecorator;
|
|
12
|
+
const operationDecorators = {
|
|
13
|
+
Create: (0, build_operation_decorator_js_1.buildOperationDecorator)('create'),
|
|
14
|
+
Delete: (0, build_operation_decorator_js_1.buildOperationDecorator)('delete'),
|
|
15
|
+
DeleteMany: (0, build_operation_decorator_js_1.buildOperationDecorator)('deleteMany'),
|
|
16
|
+
Get: (0, build_operation_decorator_js_1.buildOperationDecorator)('get'),
|
|
17
|
+
FindMany: (0, build_operation_decorator_js_1.buildOperationDecorator)('findMany'),
|
|
18
|
+
Update: (0, build_operation_decorator_js_1.buildOperationDecorator)('update'),
|
|
19
|
+
UpdateMany: (0, build_operation_decorator_js_1.buildOperationDecorator)('updateMany')
|
|
20
|
+
};
|
|
12
21
|
Object.assign(CollectionDecorator, resource_decorator_js_1.ResourceDecorator);
|
|
13
|
-
CollectionDecorator
|
|
14
|
-
CollectionDecorator.Delete = createOperationDecorator('delete');
|
|
15
|
-
CollectionDecorator.DeleteMany = createOperationDecorator('deleteMany');
|
|
16
|
-
CollectionDecorator.Get = createOperationDecorator('get');
|
|
17
|
-
CollectionDecorator.FindMany = createOperationDecorator('findMany');
|
|
18
|
-
CollectionDecorator.Update = createOperationDecorator('update');
|
|
19
|
-
CollectionDecorator.UpdateMany = createOperationDecorator('updateMany');
|
|
22
|
+
Object.assign(CollectionDecorator, operationDecorators);
|
|
20
23
|
CollectionDecorator.Action = function (options) {
|
|
21
24
|
const oldDecorator = resource_decorator_js_1.ResourceDecorator.Action(options);
|
|
22
25
|
return (target, propertyKey) => {
|
|
@@ -25,14 +28,3 @@ CollectionDecorator.Action = function (options) {
|
|
|
25
28
|
return oldDecorator(target, propertyKey);
|
|
26
29
|
};
|
|
27
30
|
};
|
|
28
|
-
function createOperationDecorator(operation) {
|
|
29
|
-
return (options) => ((target, propertyKey) => {
|
|
30
|
-
if (propertyKey !== operation)
|
|
31
|
-
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
32
|
-
const operationMeta = { ...options };
|
|
33
|
-
const sourceMetadata = (Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, target.constructor) || {});
|
|
34
|
-
sourceMetadata.operations = sourceMetadata.operations || {};
|
|
35
|
-
sourceMetadata.operations[operation] = operationMeta;
|
|
36
|
-
Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, sourceMetadata, target.constructor);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SingletonDecorator = void 0;
|
|
4
4
|
const index_js_1 = require("../../schema/index.js");
|
|
5
|
-
const
|
|
5
|
+
const build_operation_decorator_js_1 = require("./build-operation-decorator.js");
|
|
6
6
|
const resource_decorator_js_1 = require("./resource.decorator.js");
|
|
7
7
|
const operationProperties = ['create', 'delete', 'get', 'update'];
|
|
8
8
|
function SingletonDecorator(type, options) {
|
|
@@ -10,10 +10,10 @@ function SingletonDecorator(type, options) {
|
|
|
10
10
|
}
|
|
11
11
|
exports.SingletonDecorator = SingletonDecorator;
|
|
12
12
|
Object.assign(SingletonDecorator, resource_decorator_js_1.ResourceDecorator);
|
|
13
|
-
SingletonDecorator.Create =
|
|
14
|
-
SingletonDecorator.Get =
|
|
15
|
-
SingletonDecorator.Delete =
|
|
16
|
-
SingletonDecorator.Update =
|
|
13
|
+
SingletonDecorator.Create = (0, build_operation_decorator_js_1.buildOperationDecorator)('create');
|
|
14
|
+
SingletonDecorator.Get = (0, build_operation_decorator_js_1.buildOperationDecorator)('get');
|
|
15
|
+
SingletonDecorator.Delete = (0, build_operation_decorator_js_1.buildOperationDecorator)('delete');
|
|
16
|
+
SingletonDecorator.Update = (0, build_operation_decorator_js_1.buildOperationDecorator)('update');
|
|
17
17
|
SingletonDecorator.Action = function (options) {
|
|
18
18
|
const oldDecorator = resource_decorator_js_1.ResourceDecorator.Action(options);
|
|
19
19
|
const operators = ['create', 'delete', 'get', 'update'];
|
|
@@ -23,14 +23,3 @@ SingletonDecorator.Action = function (options) {
|
|
|
23
23
|
return oldDecorator(target, propertyKey);
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
|
-
function createOperationDecorator(operation) {
|
|
27
|
-
return (options) => ((target, propertyKey) => {
|
|
28
|
-
if (propertyKey !== operation)
|
|
29
|
-
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
30
|
-
const operationMeta = { ...options };
|
|
31
|
-
const sourceMetadata = (Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, target.constructor) || {});
|
|
32
|
-
sourceMetadata.operations = sourceMetadata.operations || {};
|
|
33
|
-
sourceMetadata.operations[operation] = operationMeta;
|
|
34
|
-
Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, sourceMetadata, target.constructor);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
@@ -2,17 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StorageDecorator = void 0;
|
|
4
4
|
const index_js_1 = require("../../schema/index.js");
|
|
5
|
-
const
|
|
5
|
+
const build_operation_decorator_js_1 = require("./build-operation-decorator.js");
|
|
6
6
|
const resource_decorator_js_1 = require("./resource.decorator.js");
|
|
7
7
|
const operationProperties = ['delete', 'get', 'post'];
|
|
8
8
|
function StorageDecorator(options) {
|
|
9
9
|
return (0, resource_decorator_js_1.ResourceDecorator)(index_js_1.OpraSchema.Storage.Kind, options);
|
|
10
10
|
}
|
|
11
11
|
exports.StorageDecorator = StorageDecorator;
|
|
12
|
+
const operationDecorators = {
|
|
13
|
+
Delete: (0, build_operation_decorator_js_1.buildOperationDecorator)('delete'),
|
|
14
|
+
Get: (0, build_operation_decorator_js_1.buildOperationDecorator)('get'),
|
|
15
|
+
Post: (0, build_operation_decorator_js_1.buildOperationDecorator)('post')
|
|
16
|
+
};
|
|
12
17
|
Object.assign(StorageDecorator, resource_decorator_js_1.ResourceDecorator);
|
|
13
|
-
StorageDecorator
|
|
14
|
-
StorageDecorator.Get = createOperationDecorator('get');
|
|
15
|
-
StorageDecorator.Post = createOperationDecorator('post');
|
|
18
|
+
Object.assign(StorageDecorator, operationDecorators);
|
|
16
19
|
StorageDecorator.Action = function (options) {
|
|
17
20
|
const oldDecorator = resource_decorator_js_1.ResourceDecorator.Action(options);
|
|
18
21
|
const operators = ['delete', 'get', 'post'];
|
|
@@ -22,14 +25,3 @@ StorageDecorator.Action = function (options) {
|
|
|
22
25
|
return oldDecorator(target, propertyKey);
|
|
23
26
|
};
|
|
24
27
|
};
|
|
25
|
-
function createOperationDecorator(operation) {
|
|
26
|
-
return (options) => ((target, propertyKey) => {
|
|
27
|
-
if (propertyKey !== operation)
|
|
28
|
-
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
29
|
-
const operationMeta = { ...options };
|
|
30
|
-
const sourceMetadata = (Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, target.constructor) || {});
|
|
31
|
-
sourceMetadata.operations = sourceMetadata.operations || {};
|
|
32
|
-
sourceMetadata.operations[operation] = operationMeta;
|
|
33
|
-
Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, sourceMetadata, target.constructor);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Endpoint = void 0;
|
|
3
|
+
exports.EndpointParameter = exports.Endpoint = void 0;
|
|
4
4
|
const index_js_1 = require("../../helpers/index.js");
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @class Endpoint
|
|
8
|
+
*/
|
|
5
9
|
class Endpoint {
|
|
6
10
|
constructor(init) {
|
|
11
|
+
Object.assign(this, init);
|
|
7
12
|
this.parameters = new index_js_1.ResponsiveMap();
|
|
8
|
-
this.name = init.name;
|
|
9
|
-
this.description = init.description;
|
|
10
13
|
if (init.parameters) {
|
|
11
14
|
for (const [n, p] of Object.entries(init.parameters)) {
|
|
12
|
-
this.parameters.set(n, new
|
|
15
|
+
this.parameters.set(n, new EndpointParameter(p));
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
}
|
|
@@ -27,18 +30,20 @@ class Endpoint {
|
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
exports.Endpoint = Endpoint;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
type: typeof this.type === 'string' ? this.type : this.type.exportSchema(),
|
|
38
|
-
description: this.description,
|
|
39
|
-
isArray: this.isArray
|
|
40
|
-
});
|
|
41
|
-
}
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @class EndpointParameter
|
|
36
|
+
*/
|
|
37
|
+
class EndpointParameter {
|
|
38
|
+
constructor(init) {
|
|
39
|
+
Object.assign(this, init);
|
|
42
40
|
}
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
exportSchema() {
|
|
42
|
+
return (0, index_js_1.omitUndefined)({
|
|
43
|
+
type: typeof this.type === 'string' ? this.type : this.type.exportSchema(),
|
|
44
|
+
description: this.description,
|
|
45
|
+
isArray: this.isArray
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.EndpointParameter = EndpointParameter;
|
|
@@ -25,7 +25,7 @@ class OpraException extends Error {
|
|
|
25
25
|
this.initString(issue);
|
|
26
26
|
else if (issue instanceof Error)
|
|
27
27
|
this.initError(issue);
|
|
28
|
-
else
|
|
28
|
+
else
|
|
29
29
|
this.init(issue);
|
|
30
30
|
this.message = this.message || this.constructor.name;
|
|
31
31
|
}
|
|
@@ -47,25 +47,31 @@ class OpraException extends Error {
|
|
|
47
47
|
}, true);
|
|
48
48
|
}
|
|
49
49
|
init(issue) {
|
|
50
|
-
this.message = issue
|
|
51
|
-
this.severity = issue
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
this.message = issue?.message || this.constructor.name;
|
|
51
|
+
this.severity = issue?.severity || 'error';
|
|
52
|
+
if (issue) {
|
|
53
|
+
this.system = issue.system;
|
|
54
|
+
this.code = issue.code;
|
|
55
|
+
this.details = issue.details;
|
|
56
|
+
}
|
|
55
57
|
}
|
|
56
58
|
initString(issue) {
|
|
57
|
-
this.
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
this.init({
|
|
60
|
+
message: String(issue || '') || this.constructor.name,
|
|
61
|
+
severity: 'error',
|
|
62
|
+
code: this.constructor.name
|
|
63
|
+
});
|
|
60
64
|
}
|
|
61
65
|
initError(issue) {
|
|
62
66
|
if (typeof issue.status === 'number')
|
|
63
67
|
this.status = issue.status;
|
|
64
68
|
else if (typeof issue.getStatus === 'function')
|
|
65
69
|
this.status = issue.getStatus();
|
|
66
|
-
this.
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
this.init({
|
|
71
|
+
message: issue.message,
|
|
72
|
+
severity: issue.severity || 'error',
|
|
73
|
+
code: issue.code || (issue.constructor.name)
|
|
74
|
+
});
|
|
69
75
|
}
|
|
70
76
|
}
|
|
71
77
|
exports.OpraException = OpraException;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { RESOURCE_METADATA } from '../constants.js';
|
|
3
|
+
export function buildOperationDecorator(operation) {
|
|
4
|
+
return (options) => {
|
|
5
|
+
const mergeMetadata = {};
|
|
6
|
+
const decorator = ((target, propertyKey) => {
|
|
7
|
+
if (propertyKey !== operation)
|
|
8
|
+
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
9
|
+
const operationMeta = { ...options };
|
|
10
|
+
const resourceMetadata = (Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {});
|
|
11
|
+
resourceMetadata.operations = resourceMetadata.operations || {};
|
|
12
|
+
resourceMetadata.operations[operation] = operationMeta;
|
|
13
|
+
Object.assign(operationMeta, mergeMetadata);
|
|
14
|
+
Reflect.defineMetadata(RESOURCE_METADATA, resourceMetadata, target.constructor);
|
|
15
|
+
});
|
|
16
|
+
decorator.Parameter = (name) => {
|
|
17
|
+
mergeMetadata.parameters = mergeMetadata.parameters || {};
|
|
18
|
+
mergeMetadata.parameters[name] = {};
|
|
19
|
+
return decorator;
|
|
20
|
+
};
|
|
21
|
+
return decorator;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { OpraSchema } from '../../schema/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { buildOperationDecorator } from './build-operation-decorator.js';
|
|
3
3
|
import { ResourceDecorator } from './resource.decorator.js';
|
|
4
4
|
const operationProperties = ['create', 'delete', 'deleteMany', 'get', 'findMany', 'update', 'updateMany'];
|
|
5
5
|
export function CollectionDecorator(type, options) {
|
|
6
6
|
return ResourceDecorator(OpraSchema.Collection.Kind, { ...options, type });
|
|
7
7
|
}
|
|
8
|
+
const operationDecorators = {
|
|
9
|
+
Create: buildOperationDecorator('create'),
|
|
10
|
+
Delete: buildOperationDecorator('delete'),
|
|
11
|
+
DeleteMany: buildOperationDecorator('deleteMany'),
|
|
12
|
+
Get: buildOperationDecorator('get'),
|
|
13
|
+
FindMany: buildOperationDecorator('findMany'),
|
|
14
|
+
Update: buildOperationDecorator('update'),
|
|
15
|
+
UpdateMany: buildOperationDecorator('updateMany')
|
|
16
|
+
};
|
|
8
17
|
Object.assign(CollectionDecorator, ResourceDecorator);
|
|
9
|
-
CollectionDecorator
|
|
10
|
-
CollectionDecorator.Delete = createOperationDecorator('delete');
|
|
11
|
-
CollectionDecorator.DeleteMany = createOperationDecorator('deleteMany');
|
|
12
|
-
CollectionDecorator.Get = createOperationDecorator('get');
|
|
13
|
-
CollectionDecorator.FindMany = createOperationDecorator('findMany');
|
|
14
|
-
CollectionDecorator.Update = createOperationDecorator('update');
|
|
15
|
-
CollectionDecorator.UpdateMany = createOperationDecorator('updateMany');
|
|
18
|
+
Object.assign(CollectionDecorator, operationDecorators);
|
|
16
19
|
CollectionDecorator.Action = function (options) {
|
|
17
20
|
const oldDecorator = ResourceDecorator.Action(options);
|
|
18
21
|
return (target, propertyKey) => {
|
|
@@ -21,14 +24,3 @@ CollectionDecorator.Action = function (options) {
|
|
|
21
24
|
return oldDecorator(target, propertyKey);
|
|
22
25
|
};
|
|
23
26
|
};
|
|
24
|
-
function createOperationDecorator(operation) {
|
|
25
|
-
return (options) => ((target, propertyKey) => {
|
|
26
|
-
if (propertyKey !== operation)
|
|
27
|
-
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
28
|
-
const operationMeta = { ...options };
|
|
29
|
-
const sourceMetadata = (Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {});
|
|
30
|
-
sourceMetadata.operations = sourceMetadata.operations || {};
|
|
31
|
-
sourceMetadata.operations[operation] = operationMeta;
|
|
32
|
-
Reflect.defineMetadata(RESOURCE_METADATA, sourceMetadata, target.constructor);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { OpraSchema } from '../../schema/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { buildOperationDecorator } from './build-operation-decorator.js';
|
|
3
3
|
import { ResourceDecorator } from './resource.decorator.js';
|
|
4
4
|
const operationProperties = ['create', 'delete', 'get', 'update'];
|
|
5
5
|
export function SingletonDecorator(type, options) {
|
|
6
6
|
return ResourceDecorator(OpraSchema.Singleton.Kind, { ...options, type });
|
|
7
7
|
}
|
|
8
8
|
Object.assign(SingletonDecorator, ResourceDecorator);
|
|
9
|
-
SingletonDecorator.Create =
|
|
10
|
-
SingletonDecorator.Get =
|
|
11
|
-
SingletonDecorator.Delete =
|
|
12
|
-
SingletonDecorator.Update =
|
|
9
|
+
SingletonDecorator.Create = buildOperationDecorator('create');
|
|
10
|
+
SingletonDecorator.Get = buildOperationDecorator('get');
|
|
11
|
+
SingletonDecorator.Delete = buildOperationDecorator('delete');
|
|
12
|
+
SingletonDecorator.Update = buildOperationDecorator('update');
|
|
13
13
|
SingletonDecorator.Action = function (options) {
|
|
14
14
|
const oldDecorator = ResourceDecorator.Action(options);
|
|
15
15
|
const operators = ['create', 'delete', 'get', 'update'];
|
|
@@ -19,14 +19,3 @@ SingletonDecorator.Action = function (options) {
|
|
|
19
19
|
return oldDecorator(target, propertyKey);
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
-
function createOperationDecorator(operation) {
|
|
23
|
-
return (options) => ((target, propertyKey) => {
|
|
24
|
-
if (propertyKey !== operation)
|
|
25
|
-
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
26
|
-
const operationMeta = { ...options };
|
|
27
|
-
const sourceMetadata = (Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {});
|
|
28
|
-
sourceMetadata.operations = sourceMetadata.operations || {};
|
|
29
|
-
sourceMetadata.operations[operation] = operationMeta;
|
|
30
|
-
Reflect.defineMetadata(RESOURCE_METADATA, sourceMetadata, target.constructor);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { OpraSchema } from '../../schema/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { buildOperationDecorator } from './build-operation-decorator.js';
|
|
3
3
|
import { ResourceDecorator } from './resource.decorator.js';
|
|
4
4
|
const operationProperties = ['delete', 'get', 'post'];
|
|
5
5
|
export function StorageDecorator(options) {
|
|
6
6
|
return ResourceDecorator(OpraSchema.Storage.Kind, options);
|
|
7
7
|
}
|
|
8
|
+
const operationDecorators = {
|
|
9
|
+
Delete: buildOperationDecorator('delete'),
|
|
10
|
+
Get: buildOperationDecorator('get'),
|
|
11
|
+
Post: buildOperationDecorator('post')
|
|
12
|
+
};
|
|
8
13
|
Object.assign(StorageDecorator, ResourceDecorator);
|
|
9
|
-
StorageDecorator
|
|
10
|
-
StorageDecorator.Get = createOperationDecorator('get');
|
|
11
|
-
StorageDecorator.Post = createOperationDecorator('post');
|
|
14
|
+
Object.assign(StorageDecorator, operationDecorators);
|
|
12
15
|
StorageDecorator.Action = function (options) {
|
|
13
16
|
const oldDecorator = ResourceDecorator.Action(options);
|
|
14
17
|
const operators = ['delete', 'get', 'post'];
|
|
@@ -18,14 +21,3 @@ StorageDecorator.Action = function (options) {
|
|
|
18
21
|
return oldDecorator(target, propertyKey);
|
|
19
22
|
};
|
|
20
23
|
};
|
|
21
|
-
function createOperationDecorator(operation) {
|
|
22
|
-
return (options) => ((target, propertyKey) => {
|
|
23
|
-
if (propertyKey !== operation)
|
|
24
|
-
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
25
|
-
const operationMeta = { ...options };
|
|
26
|
-
const sourceMetadata = (Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {});
|
|
27
|
-
sourceMetadata.operations = sourceMetadata.operations || {};
|
|
28
|
-
sourceMetadata.operations[operation] = operationMeta;
|
|
29
|
-
Reflect.defineMetadata(RESOURCE_METADATA, sourceMetadata, target.constructor);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { omitUndefined, ResponsiveMap } from '../../helpers/index.js';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @class Endpoint
|
|
5
|
+
*/
|
|
2
6
|
export class Endpoint {
|
|
3
7
|
constructor(init) {
|
|
8
|
+
Object.assign(this, init);
|
|
4
9
|
this.parameters = new ResponsiveMap();
|
|
5
|
-
this.name = init.name;
|
|
6
|
-
this.description = init.description;
|
|
7
10
|
if (init.parameters) {
|
|
8
11
|
for (const [n, p] of Object.entries(init.parameters)) {
|
|
9
|
-
this.parameters.set(n, new
|
|
12
|
+
this.parameters.set(n, new EndpointParameter(p));
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
15
|
}
|
|
@@ -23,18 +26,19 @@ export class Endpoint {
|
|
|
23
26
|
return schema;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
type: typeof this.type === 'string' ? this.type : this.type.exportSchema(),
|
|
34
|
-
description: this.description,
|
|
35
|
-
isArray: this.isArray
|
|
36
|
-
});
|
|
37
|
-
}
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @class EndpointParameter
|
|
32
|
+
*/
|
|
33
|
+
export class EndpointParameter {
|
|
34
|
+
constructor(init) {
|
|
35
|
+
Object.assign(this, init);
|
|
38
36
|
}
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
exportSchema() {
|
|
38
|
+
return omitUndefined({
|
|
39
|
+
type: typeof this.type === 'string' ? this.type : this.type.exportSchema(),
|
|
40
|
+
description: this.description,
|
|
41
|
+
isArray: this.isArray
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -22,7 +22,7 @@ export class OpraException extends Error {
|
|
|
22
22
|
this.initString(issue);
|
|
23
23
|
else if (issue instanceof Error)
|
|
24
24
|
this.initError(issue);
|
|
25
|
-
else
|
|
25
|
+
else
|
|
26
26
|
this.init(issue);
|
|
27
27
|
this.message = this.message || this.constructor.name;
|
|
28
28
|
}
|
|
@@ -44,24 +44,30 @@ export class OpraException extends Error {
|
|
|
44
44
|
}, true);
|
|
45
45
|
}
|
|
46
46
|
init(issue) {
|
|
47
|
-
this.message = issue
|
|
48
|
-
this.severity = issue
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
this.message = issue?.message || this.constructor.name;
|
|
48
|
+
this.severity = issue?.severity || 'error';
|
|
49
|
+
if (issue) {
|
|
50
|
+
this.system = issue.system;
|
|
51
|
+
this.code = issue.code;
|
|
52
|
+
this.details = issue.details;
|
|
53
|
+
}
|
|
52
54
|
}
|
|
53
55
|
initString(issue) {
|
|
54
|
-
this.
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
this.init({
|
|
57
|
+
message: String(issue || '') || this.constructor.name,
|
|
58
|
+
severity: 'error',
|
|
59
|
+
code: this.constructor.name
|
|
60
|
+
});
|
|
57
61
|
}
|
|
58
62
|
initError(issue) {
|
|
59
63
|
if (typeof issue.status === 'number')
|
|
60
64
|
this.status = issue.status;
|
|
61
65
|
else if (typeof issue.getStatus === 'function')
|
|
62
66
|
this.status = issue.getStatus();
|
|
63
|
-
this.
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
this.init({
|
|
68
|
+
message: issue.message,
|
|
69
|
+
severity: issue.severity || 'error',
|
|
70
|
+
code: issue.code || (issue.constructor.name)
|
|
71
|
+
});
|
|
66
72
|
}
|
|
67
73
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
3
|
+
import { TypeThunkAsync } from '../../types.js';
|
|
4
|
+
export declare namespace OperationDecorator {
|
|
5
|
+
interface Options extends Omit<OpraSchema.Endpoint.Parameter, 'type'> {
|
|
6
|
+
type?: OpraSchema.DataType.Name | OpraSchema.DataType | TypeThunkAsync;
|
|
7
|
+
enum?: OpraSchema.EnumObject | string[];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export type OperationDecorator = PropertyDecorator & {
|
|
11
|
+
Parameter: (name: string, options?: OperationDecorator.Options) => OperationDecorator;
|
|
12
|
+
};
|
|
13
|
+
export declare function buildOperationDecorator<T>(operation: string): ((options?: T) => OperationDecorator);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StrictOmit, Type } from 'ts-gems';
|
|
2
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
2
3
|
import type { Collection } from '../resource/collection';
|
|
3
4
|
import { Resource } from '../resource/resource.js';
|
|
4
5
|
import { ResourceDecorator } from './resource.decorator.js';
|
|
@@ -7,22 +8,24 @@ declare const operationProperties: readonly ["create", "delete", "deleteMany", "
|
|
|
7
8
|
type OperationProperties = typeof operationProperties[number];
|
|
8
9
|
export declare function CollectionDecorator(type: Type | string, options?: Collection.DecoratorOptions): ClassDecorator;
|
|
9
10
|
export declare namespace CollectionDecorator {
|
|
10
|
-
var Create: (options?: unknown) => (target: Object, propertyKey: string | symbol) => void;
|
|
11
|
-
var Delete: (options?: unknown) => (target: Object, propertyKey: string | symbol) => void;
|
|
12
|
-
var DeleteMany: (options?: unknown) => (target: Object, propertyKey: string | symbol) => void;
|
|
13
|
-
var Get: (options?: unknown) => (target: Object, propertyKey: string | symbol) => void;
|
|
14
|
-
var FindMany: (options?: unknown) => (target: Object, propertyKey: string | symbol) => void;
|
|
15
|
-
var Update: (options?: unknown) => (target: Object, propertyKey: string | symbol) => void;
|
|
16
|
-
var UpdateMany: (options?: unknown) => (target: Object, propertyKey: string | symbol) => void;
|
|
17
11
|
var Action: (options: any) => PropertyDecorator;
|
|
18
12
|
}
|
|
13
|
+
declare const operationDecorators: {
|
|
14
|
+
Create: (options?: OpraSchema.Collection.CreateEndpoint | undefined) => import("./build-operation-decorator.js").OperationDecorator;
|
|
15
|
+
Delete: (options?: OpraSchema.Endpoint | undefined) => import("./build-operation-decorator.js").OperationDecorator;
|
|
16
|
+
DeleteMany: (options?: OpraSchema.Collection.DeleteManyEndpoint | undefined) => import("./build-operation-decorator.js").OperationDecorator;
|
|
17
|
+
Get: (options?: OpraSchema.Collection.GetEndpoint | undefined) => import("./build-operation-decorator.js").OperationDecorator;
|
|
18
|
+
FindMany: (options?: OpraSchema.Collection.FindManyEndpoint | undefined) => import("./build-operation-decorator.js").OperationDecorator;
|
|
19
|
+
Update: (options?: OpraSchema.Collection.UpdateEndpoint | undefined) => import("./build-operation-decorator.js").OperationDecorator;
|
|
20
|
+
UpdateMany: (options?: OpraSchema.Collection.UpdateManyEndpoint | undefined) => import("./build-operation-decorator.js").OperationDecorator;
|
|
21
|
+
};
|
|
19
22
|
export interface CollectionDecorator extends StrictOmit<ResourceDecorator, 'Action'> {
|
|
20
23
|
<T>(type: Type<T> | string, options?: Collection.DecoratorOptions<T>): ClassDecorator;
|
|
21
24
|
Action: (options?: Resource.ActionOptions) => (<T, K extends keyof T>(target: T, propertyKey: ErrorMessage<Exclude<K, OperationProperties>, `'${string & K}' property is reserved for operation endpoints and can not be used for actions`>) => void);
|
|
22
|
-
Create:
|
|
23
|
-
Delete:
|
|
24
|
-
DeleteMany:
|
|
25
|
-
Get:
|
|
25
|
+
Create: typeof operationDecorators.Create;
|
|
26
|
+
Delete: typeof operationDecorators.Delete;
|
|
27
|
+
DeleteMany: typeof operationDecorators.DeleteMany;
|
|
28
|
+
Get: typeof operationDecorators.Get;
|
|
26
29
|
FindMany: (options?: Collection.FindManyEndpointOptions) => ((target: Object, propertyKey: 'findMany') => void);
|
|
27
30
|
Update: (options?: Collection.UpdateEndpointOptions) => ((target: Object, propertyKey: 'update') => void);
|
|
28
31
|
UpdateMany: (options?: Collection.UpdateManyEndpointOptions) => ((target: Object, propertyKey: 'updateMany') => void);
|
|
@@ -8,10 +8,10 @@ declare const operationProperties: readonly ["create", "delete", "get", "update"
|
|
|
8
8
|
type OperationProperties = typeof operationProperties[number];
|
|
9
9
|
export declare function SingletonDecorator(type: TypeThunkAsync | string, options?: Singleton.DecoratorOptions): ClassDecorator;
|
|
10
10
|
export declare namespace SingletonDecorator {
|
|
11
|
-
var Create: (options?: unknown) => (
|
|
12
|
-
var Get: (options?: unknown) => (
|
|
13
|
-
var Delete: (options?: unknown) => (
|
|
14
|
-
var Update: (options?: unknown) => (
|
|
11
|
+
var Create: (options?: unknown) => import("./build-operation-decorator.js").OperationDecorator;
|
|
12
|
+
var Get: (options?: unknown) => import("./build-operation-decorator.js").OperationDecorator;
|
|
13
|
+
var Delete: (options?: unknown) => import("./build-operation-decorator.js").OperationDecorator;
|
|
14
|
+
var Update: (options?: unknown) => import("./build-operation-decorator.js").OperationDecorator;
|
|
15
15
|
var Action: (options: any) => PropertyDecorator;
|
|
16
16
|
}
|
|
17
17
|
export interface SingletonDecorator extends StrictOmit<ResourceDecorator, 'Action'> {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StrictOmit } from 'ts-gems';
|
|
2
|
+
import { OpraSchema } from '../../schema/index.js';
|
|
2
3
|
import { Resource } from '../resource/resource.js';
|
|
3
4
|
import type { Storage } from '../resource/storage.js';
|
|
4
5
|
import { ResourceDecorator } from './resource.decorator.js';
|
|
@@ -7,16 +8,18 @@ declare const operationProperties: readonly ["delete", "get", "post"];
|
|
|
7
8
|
type OperationProperties = typeof operationProperties[number];
|
|
8
9
|
export declare function StorageDecorator(options?: Storage.DecoratorOptions): ClassDecorator;
|
|
9
10
|
export declare namespace StorageDecorator {
|
|
10
|
-
var Delete: (options?: unknown) => (target: Object, propertyKey: string | symbol) => void;
|
|
11
|
-
var Get: (options?: unknown) => (target: Object, propertyKey: string | symbol) => void;
|
|
12
|
-
var Post: (options?: unknown) => (target: Object, propertyKey: string | symbol) => void;
|
|
13
11
|
var Action: (options: any) => PropertyDecorator;
|
|
14
12
|
}
|
|
13
|
+
declare const operationDecorators: {
|
|
14
|
+
Delete: (options?: OpraSchema.Endpoint | undefined) => import("./build-operation-decorator.js").OperationDecorator;
|
|
15
|
+
Get: (options?: OpraSchema.Endpoint | undefined) => import("./build-operation-decorator.js").OperationDecorator;
|
|
16
|
+
Post: (options?: OpraSchema.Storage.PostEndpoint | undefined) => import("./build-operation-decorator.js").OperationDecorator;
|
|
17
|
+
};
|
|
15
18
|
export interface StorageDecorator extends StrictOmit<ResourceDecorator, 'Action'> {
|
|
16
19
|
(options?: Storage.DecoratorOptions): ClassDecorator;
|
|
17
20
|
Action: (options?: Resource.ActionOptions) => (<T, K extends keyof T>(target: T, propertyKey: ErrorMessage<Exclude<K, OperationProperties>, `'${string & K}' property is reserved for operation endpoints and can not be used for actions`>) => void);
|
|
18
|
-
Delete:
|
|
19
|
-
Get:
|
|
20
|
-
Post:
|
|
21
|
+
Delete: typeof operationDecorators.Delete;
|
|
22
|
+
Get: typeof operationDecorators.Get;
|
|
23
|
+
Post: typeof operationDecorators.Post;
|
|
21
24
|
}
|
|
22
25
|
export {};
|
|
@@ -2,10 +2,15 @@ import { StrictOmit } from 'ts-gems';
|
|
|
2
2
|
import { ResponsiveMap } from '../../helpers/index.js';
|
|
3
3
|
import { OpraSchema } from '../../schema/index.js';
|
|
4
4
|
import { DataType } from '../data-type/data-type.js';
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @class Endpoint
|
|
8
|
+
*/
|
|
5
9
|
export declare class Endpoint {
|
|
6
10
|
readonly name: string;
|
|
7
11
|
description?: string;
|
|
8
|
-
parameters: ResponsiveMap<
|
|
12
|
+
parameters: ResponsiveMap<EndpointParameter>;
|
|
13
|
+
[key: string]: any;
|
|
9
14
|
constructor(init: Endpoint.InitArguments);
|
|
10
15
|
exportSchema(): OpraSchema.Endpoint;
|
|
11
16
|
}
|
|
@@ -13,17 +18,19 @@ export declare namespace Endpoint {
|
|
|
13
18
|
interface InitArguments extends OpraSchema.Endpoint {
|
|
14
19
|
name: string;
|
|
15
20
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @class EndpointParameter
|
|
25
|
+
*/
|
|
26
|
+
export declare class EndpointParameter implements StrictOmit<OpraSchema.Endpoint.Parameter, 'type'> {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly type: string | DataType;
|
|
29
|
+
description?: string;
|
|
30
|
+
isArray?: boolean;
|
|
31
|
+
default?: any;
|
|
32
|
+
required?: boolean;
|
|
33
|
+
deprecated?: boolean | string;
|
|
34
|
+
constructor(init: OpraSchema.Endpoint.Parameter);
|
|
35
|
+
exportSchema(): OpraSchema.Endpoint.Parameter;
|
|
29
36
|
}
|
|
@@ -16,7 +16,7 @@ export declare class OpraException extends Error {
|
|
|
16
16
|
setStatus(status: number): this;
|
|
17
17
|
toString(): string;
|
|
18
18
|
toJSON(): ErrorIssue;
|
|
19
|
-
protected init(issue
|
|
19
|
+
protected init(issue?: Partial<ErrorIssue>): void;
|
|
20
20
|
protected initString(issue: string): void;
|
|
21
21
|
protected initError(issue: Error): void;
|
|
22
22
|
}
|
|
@@ -9,6 +9,7 @@ export declare class OpraURLPath {
|
|
|
9
9
|
[index: number]: OpraURLPathComponent;
|
|
10
10
|
constructor(...init: (OpraURLPath.ComponentLike | null | undefined)[]);
|
|
11
11
|
get length(): number;
|
|
12
|
+
slice(start?: number, end?: number): OpraURLPath;
|
|
12
13
|
resolve(...items: OpraURLPath.ComponentLike[]): this;
|
|
13
14
|
join(...items: OpraURLPath.ComponentLike[]): OpraURLPath;
|
|
14
15
|
isRelativeTo(basePath: string | OpraURLPath): boolean;
|