@opra/common 0.25.5 → 0.26.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/browser.js +1826 -1338
- package/cjs/document/api-document.js +16 -220
- package/cjs/document/data-type/complex-type-class.js +41 -19
- package/cjs/document/data-type/complex-type.js +1 -1
- package/cjs/document/data-type/data-type.js +2 -1
- package/cjs/document/data-type/enum-type-class.js +15 -12
- package/cjs/document/data-type/enum-type.js +28 -14
- package/cjs/document/data-type/field-class.js +21 -3
- package/cjs/document/data-type/field-decorator.js +0 -19
- package/cjs/document/data-type/mapped-type-class.js +8 -10
- package/cjs/document/data-type/mapped-type.js +1 -1
- package/cjs/document/data-type/simple-type-class.js +17 -8
- package/cjs/document/data-type/simple-type.js +1 -1
- package/cjs/document/data-type/union-type-class.js +15 -13
- package/cjs/document/document-base.js +24 -0
- package/cjs/document/factory/api-document-factory.js +231 -0
- package/cjs/document/factory/type-document-factory.js +324 -0
- package/cjs/document/index.js +7 -1
- package/cjs/document/resource/action-decorator.js +27 -0
- package/cjs/document/resource/collection-class.js +95 -44
- package/cjs/document/resource/collection-decorator.js +182 -0
- package/cjs/document/resource/collection.js +4 -4
- package/cjs/document/resource/container-class.js +82 -0
- package/cjs/document/resource/container-decorator.js +24 -0
- package/cjs/document/resource/container.js +29 -0
- package/cjs/document/resource/crud-resource.js +31 -0
- package/cjs/document/resource/endpoint.js +24 -22
- package/cjs/document/resource/operation-decorator.js +27 -0
- package/cjs/document/resource/parameter.js +51 -0
- package/cjs/document/{decorators/resource.decorator.js → resource/resource-decorator.js} +9 -14
- package/cjs/document/resource/resource.js +20 -5
- package/cjs/document/resource/singleton-class.js +60 -40
- package/cjs/document/resource/singleton-decorator.js +57 -0
- package/cjs/document/resource/singleton.js +4 -4
- package/cjs/document/resource/storage-class.js +11 -17
- package/cjs/document/resource/storage-decorator.js +66 -0
- package/cjs/document/resource/storage.js +3 -3
- package/cjs/document/type-document.js +195 -0
- package/cjs/exception/http-errors/internal-server.error.js +1 -0
- package/cjs/exception/wrap-exception.js +2 -1
- package/cjs/helpers/responsive-map.js +3 -3
- package/cjs/http/opra-url-path.js +2 -1
- package/cjs/schema/document/document-base.interface.js +2 -0
- package/cjs/schema/document/type-document.interface.js +2 -0
- package/cjs/schema/opra-schema.ns.js +3 -1
- package/cjs/schema/type-guards.js +3 -3
- package/esm/document/api-document.js +16 -220
- package/esm/document/data-type/complex-type-class.js +40 -19
- package/esm/document/data-type/complex-type.js +1 -1
- package/esm/document/data-type/data-type.js +2 -1
- package/esm/document/data-type/enum-type-class.js +15 -12
- package/esm/document/data-type/enum-type.js +26 -12
- package/esm/document/data-type/field-class.js +20 -3
- package/esm/document/data-type/field-decorator.js +0 -19
- package/esm/document/data-type/mapped-type-class.js +9 -11
- package/esm/document/data-type/mapped-type.js +1 -1
- package/esm/document/data-type/simple-type-class.js +15 -6
- package/esm/document/data-type/simple-type.js +1 -1
- package/esm/document/data-type/union-type-class.js +11 -9
- package/esm/document/document-base.js +20 -0
- package/esm/document/factory/api-document-factory.js +227 -0
- package/esm/document/factory/type-document-factory.js +320 -0
- package/esm/document/index.js +7 -1
- package/esm/document/resource/action-decorator.js +23 -0
- package/esm/document/resource/collection-class.js +95 -44
- package/esm/document/resource/collection-decorator.js +178 -0
- package/esm/document/resource/collection.js +4 -4
- package/esm/document/resource/container-class.js +78 -0
- package/esm/document/resource/container-decorator.js +20 -0
- package/esm/document/resource/container.js +25 -0
- package/esm/document/resource/crud-resource.js +27 -0
- package/esm/document/resource/endpoint.js +22 -20
- package/esm/document/resource/operation-decorator.js +23 -0
- package/esm/document/resource/parameter.js +46 -0
- package/esm/document/resource/resource-decorator.js +28 -0
- package/esm/document/resource/resource.js +20 -5
- package/esm/document/resource/singleton-class.js +58 -38
- package/esm/document/resource/singleton-decorator.js +53 -0
- package/esm/document/resource/singleton.js +4 -4
- package/esm/document/resource/storage-class.js +9 -15
- package/esm/document/resource/storage-decorator.js +62 -0
- package/esm/document/resource/storage.js +3 -3
- package/esm/document/type-document.js +191 -0
- package/esm/exception/http-errors/internal-server.error.js +1 -0
- package/esm/exception/wrap-exception.js +2 -1
- package/esm/helpers/responsive-map.js +3 -3
- package/esm/http/opra-url-path.js +1 -1
- package/esm/schema/document/document-base.interface.js +1 -0
- package/esm/schema/document/type-document.interface.js +1 -0
- package/esm/schema/opra-schema.ns.js +3 -1
- package/esm/schema/type-guards.js +1 -1
- package/package.json +2 -2
- package/types/document/api-document.d.ts +32 -73
- package/types/document/data-type/complex-type-class.d.ts +5 -5
- package/types/document/data-type/complex-type.d.ts +8 -3
- package/types/document/{decorators → data-type}/complex-type.decorator.d.ts +1 -1
- package/types/document/data-type/data-type.d.ts +11 -1
- package/types/document/data-type/enum-type-class.d.ts +6 -6
- package/types/document/data-type/enum-type.d.ts +12 -6
- package/types/document/data-type/field-class.d.ts +9 -1
- package/types/document/data-type/field-decorator.d.ts +1 -1
- package/types/document/data-type/field.d.ts +4 -3
- package/types/document/data-type/mapped-type-class.d.ts +5 -9
- package/types/document/data-type/mapped-type.d.ts +6 -7
- package/types/document/data-type/simple-type-class.d.ts +6 -3
- package/types/document/{decorators → data-type}/simple-type.decorator.d.ts +1 -1
- package/types/document/data-type/union-type-class.d.ts +2 -8
- package/types/document/data-type/union-type.d.ts +7 -6
- package/types/document/document-base.d.ts +10 -0
- package/types/document/factory/api-document-factory.d.ts +50 -0
- package/types/document/factory/type-document-factory.d.ts +56 -0
- package/types/document/index.d.ts +7 -1
- package/types/document/resource/action-decorator.d.ts +6 -0
- package/types/document/resource/collection-class.d.ts +17 -12
- package/types/document/resource/collection-decorator.d.ts +192 -0
- package/types/document/resource/collection.d.ts +11 -19
- package/types/document/resource/container-class.d.ts +66 -0
- package/types/document/resource/container-decorator.d.ts +37 -0
- package/types/document/resource/container.d.ts +25 -0
- package/types/document/resource/crud-resource.d.ts +16 -0
- package/types/document/resource/endpoint.d.ts +21 -21
- package/types/document/resource/operation-decorator.d.ts +6 -0
- package/types/document/resource/parameter.d.ts +35 -0
- package/types/document/resource/resource-decorator.d.ts +32 -0
- package/types/document/resource/resource.d.ts +15 -13
- package/types/document/resource/singleton-class.d.ts +15 -14
- package/types/document/resource/singleton-decorator.d.ts +125 -0
- package/types/document/resource/singleton.d.ts +11 -16
- package/types/document/resource/storage-class.d.ts +13 -6
- package/types/document/resource/storage-decorator.d.ts +98 -0
- package/types/document/resource/storage.d.ts +9 -12
- package/types/document/type-document.d.ts +68 -0
- package/types/http/opra-url-path.d.ts +1 -1
- package/types/schema/data-type/complex-type.interface.d.ts +1 -1
- package/types/schema/data-type/data-type.interface.d.ts +3 -3
- package/types/schema/data-type/enum-type.interface.d.ts +6 -7
- package/types/schema/data-type/mapped-type.interface.d.ts +4 -3
- package/types/schema/data-type/simple-type.interface.d.ts +3 -3
- package/types/schema/data-type/union-type.interface.d.ts +6 -4
- package/types/schema/document/api-document.interface.d.ts +11 -0
- package/types/schema/document/document-base.interface.d.ts +24 -0
- package/types/schema/document/type-document.interface.d.ts +6 -0
- package/types/schema/opra-schema.ns.d.ts +3 -1
- package/types/schema/resource/collection.interface.d.ts +31 -31
- package/types/schema/resource/container.interface.d.ts +4 -3
- package/types/schema/resource/resource.interface.d.ts +1 -1
- package/types/schema/resource/singleton.interface.d.ts +15 -10
- package/types/schema/resource/storage.interface.d.ts +49 -45
- package/types/schema/type-guards.d.ts +3 -2
- package/cjs/document/decorators/build-operation-decorator.js +0 -27
- package/cjs/document/decorators/collection-decorator.js +0 -30
- package/cjs/document/decorators/singleton.decorator.js +0 -25
- package/cjs/document/decorators/storage.decorator.js +0 -27
- package/cjs/document/factory/add-references.js +0 -20
- package/cjs/document/factory/create-document.js +0 -83
- package/cjs/document/factory/factory.js +0 -66
- package/cjs/document/factory/import-resource-class.js +0 -54
- package/cjs/document/factory/import-type-class.js +0 -146
- package/cjs/document/factory/index.js +0 -4
- package/cjs/document/factory/process-resources.js +0 -70
- package/cjs/document/factory/process-types.js +0 -191
- package/cjs/document/utils/generate-codec.js +0 -39
- package/esm/document/decorators/build-operation-decorator.js +0 -23
- package/esm/document/decorators/collection-decorator.js +0 -26
- package/esm/document/decorators/resource.decorator.js +0 -33
- package/esm/document/decorators/singleton.decorator.js +0 -21
- package/esm/document/decorators/storage.decorator.js +0 -23
- package/esm/document/factory/add-references.js +0 -16
- package/esm/document/factory/create-document.js +0 -77
- package/esm/document/factory/factory.js +0 -62
- package/esm/document/factory/import-resource-class.js +0 -48
- package/esm/document/factory/import-type-class.js +0 -136
- package/esm/document/factory/index.js +0 -1
- package/esm/document/factory/process-resources.js +0 -63
- package/esm/document/factory/process-types.js +0 -185
- package/esm/document/utils/generate-codec.js +0 -33
- package/types/document/decorators/build-operation-decorator.d.ts +0 -13
- package/types/document/decorators/collection-decorator.d.ts +0 -33
- package/types/document/decorators/resource.decorator.d.ts +0 -9
- package/types/document/decorators/singleton.decorator.d.ts +0 -25
- package/types/document/decorators/storage.decorator.d.ts +0 -25
- package/types/document/factory/add-references.d.ts +0 -4
- package/types/document/factory/create-document.d.ts +0 -12
- package/types/document/factory/factory.d.ts +0 -63
- package/types/document/factory/import-resource-class.d.ts +0 -10
- package/types/document/factory/import-type-class.d.ts +0 -17
- package/types/document/factory/index.d.ts +0 -1
- package/types/document/factory/process-resources.d.ts +0 -9
- package/types/document/factory/process-types.d.ts +0 -6
- package/types/document/utils/generate-codec.d.ts +0 -10
- package/types/schema/document.interface.d.ts +0 -34
- /package/cjs/document/{decorators → data-type}/complex-type.decorator.js +0 -0
- /package/cjs/document/{decorators → data-type}/simple-type.decorator.js +0 -0
- /package/cjs/schema/{document.interface.js → document/api-document.interface.js} +0 -0
- /package/esm/document/{decorators → data-type}/complex-type.decorator.js +0 -0
- /package/esm/document/{decorators → data-type}/simple-type.decorator.js +0 -0
- /package/esm/schema/{document.interface.js → document/api-document.interface.js} +0 -0
package/browser.js
CHANGED
|
@@ -20,6 +20,9 @@ var DECORATOR = Symbol("DECORATOR");
|
|
|
20
20
|
var NAMESPACE_PATTERN = /([A-Z$_]\w+)(?::.+)?/i;
|
|
21
21
|
var TYPENAME_PATTERN = /^(.*)Type(\d*)$/;
|
|
22
22
|
|
|
23
|
+
// ../../build/common/esm/document/resource/container.js
|
|
24
|
+
import merge3 from "putil-merge";
|
|
25
|
+
|
|
23
26
|
// ../../build/common/esm/helpers/function-utils.js
|
|
24
27
|
import promisify from "putil-promisify";
|
|
25
28
|
|
|
@@ -246,11 +249,11 @@ var ResponsiveMap = class extends Map {
|
|
|
246
249
|
return this;
|
|
247
250
|
}
|
|
248
251
|
keys() {
|
|
249
|
-
return this[kKeyOrder][Symbol.iterator]();
|
|
252
|
+
return [...this[kKeyOrder]][Symbol.iterator]();
|
|
250
253
|
}
|
|
251
254
|
values() {
|
|
252
255
|
let i = -1;
|
|
253
|
-
const arr = this[kKeyOrder];
|
|
256
|
+
const arr = [...this[kKeyOrder]];
|
|
254
257
|
const map = this;
|
|
255
258
|
return {
|
|
256
259
|
[Symbol.iterator]() {
|
|
@@ -267,7 +270,7 @@ var ResponsiveMap = class extends Map {
|
|
|
267
270
|
}
|
|
268
271
|
entries() {
|
|
269
272
|
let i = -1;
|
|
270
|
-
const arr = this[kKeyOrder];
|
|
273
|
+
const arr = [...this[kKeyOrder]];
|
|
271
274
|
const map = this;
|
|
272
275
|
return {
|
|
273
276
|
[Symbol.iterator]() {
|
|
@@ -674,6 +677,25 @@ var ForbiddenError = class extends OpraException {
|
|
|
674
677
|
}
|
|
675
678
|
};
|
|
676
679
|
|
|
680
|
+
// ../../build/common/esm/exception/http-errors/internal-server.error.js
|
|
681
|
+
var InternalServerError = class extends OpraException {
|
|
682
|
+
static {
|
|
683
|
+
__name(this, "InternalServerError");
|
|
684
|
+
}
|
|
685
|
+
constructor() {
|
|
686
|
+
super(...arguments);
|
|
687
|
+
this.status = 500;
|
|
688
|
+
}
|
|
689
|
+
init(issue) {
|
|
690
|
+
super.init({
|
|
691
|
+
message: translate("error:INTERNAL_SERVER_ERROR", "Internal server error"),
|
|
692
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
693
|
+
severity: "fatal",
|
|
694
|
+
...issue
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
|
|
677
699
|
// ../../build/common/esm/exception/http-errors/method-not-allowed.error.js
|
|
678
700
|
var MethodNotAllowedError = class extends OpraException {
|
|
679
701
|
static {
|
|
@@ -792,7 +814,7 @@ function wrapException(error) {
|
|
|
792
814
|
case 424:
|
|
793
815
|
return new FailedDependencyError(error);
|
|
794
816
|
default:
|
|
795
|
-
return new
|
|
817
|
+
return new InternalServerError(error);
|
|
796
818
|
}
|
|
797
819
|
}
|
|
798
820
|
__name(wrapException, "wrapException");
|
|
@@ -818,24 +840,6 @@ var IssueSeverity;
|
|
|
818
840
|
};
|
|
819
841
|
})(IssueSeverity || (IssueSeverity = {}));
|
|
820
842
|
|
|
821
|
-
// ../../build/common/esm/exception/http-errors/internal-server.error.js
|
|
822
|
-
var InternalServerError = class extends OpraException {
|
|
823
|
-
static {
|
|
824
|
-
__name(this, "InternalServerError");
|
|
825
|
-
}
|
|
826
|
-
constructor() {
|
|
827
|
-
super(...arguments);
|
|
828
|
-
this.status = 500;
|
|
829
|
-
}
|
|
830
|
-
init(issue) {
|
|
831
|
-
super.init({
|
|
832
|
-
message: translate("error:INTERNAL_SERVER_ERROR", "Internal server error"),
|
|
833
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
834
|
-
...issue
|
|
835
|
-
});
|
|
836
|
-
}
|
|
837
|
-
};
|
|
838
|
-
|
|
839
843
|
// ../../build/common/esm/exception/resource-errors/resource-conflict.error.js
|
|
840
844
|
var ResourceConflictError = class extends OpraException {
|
|
841
845
|
static {
|
|
@@ -903,9 +907,9 @@ __export(opra_schema_ns_exports, {
|
|
|
903
907
|
isDataType: () => isDataType,
|
|
904
908
|
isEnumType: () => isEnumType,
|
|
905
909
|
isMappedType: () => isMappedType,
|
|
910
|
+
isResource: () => isResource,
|
|
906
911
|
isSimpleType: () => isSimpleType,
|
|
907
912
|
isSingleton: () => isSingleton,
|
|
908
|
-
isSource: () => isSource,
|
|
909
913
|
isStorage: () => isStorage,
|
|
910
914
|
isUnionType: () => isUnionType
|
|
911
915
|
});
|
|
@@ -948,8 +952,8 @@ var Collection;
|
|
|
948
952
|
|
|
949
953
|
// ../../build/common/esm/schema/resource/container.interface.js
|
|
950
954
|
var Container;
|
|
951
|
-
(function(
|
|
952
|
-
|
|
955
|
+
(function(Container3) {
|
|
956
|
+
Container3.Kind = "Container";
|
|
953
957
|
})(Container || (Container = {}));
|
|
954
958
|
|
|
955
959
|
// ../../build/common/esm/schema/resource/singleton.interface.js
|
|
@@ -992,10 +996,10 @@ function isEnumType(obj) {
|
|
|
992
996
|
return obj && typeof obj === "object" && obj.kind === EnumType.Kind;
|
|
993
997
|
}
|
|
994
998
|
__name(isEnumType, "isEnumType");
|
|
995
|
-
function
|
|
999
|
+
function isResource(obj) {
|
|
996
1000
|
return obj && typeof obj === "object" && (obj.kind === Container.Kind || obj.kind === Collection.Kind || obj.kind === Singleton.Kind || obj.kind === Storage.Kind);
|
|
997
1001
|
}
|
|
998
|
-
__name(
|
|
1002
|
+
__name(isResource, "isResource");
|
|
999
1003
|
function isCollection(obj) {
|
|
1000
1004
|
return obj && typeof obj === "object" && obj.kind === Collection.Kind;
|
|
1001
1005
|
}
|
|
@@ -1013,34 +1017,15 @@ function isContainer(obj) {
|
|
|
1013
1017
|
}
|
|
1014
1018
|
__name(isContainer, "isContainer");
|
|
1015
1019
|
|
|
1016
|
-
// ../../build/common/esm/document/data-type/complex-type.js
|
|
1017
|
-
import "reflect-metadata";
|
|
1018
|
-
import merge4 from "putil-merge";
|
|
1019
|
-
|
|
1020
|
-
// ../../build/common/esm/document/decorators/complex-type.decorator.js
|
|
1021
|
-
import omit from "lodash.omit";
|
|
1022
|
-
function ComplexTypeDecorator(options) {
|
|
1023
|
-
return function(target) {
|
|
1024
|
-
const name = options?.name || target.name.match(TYPENAME_PATTERN)?.[1] || target.name;
|
|
1025
|
-
let metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target);
|
|
1026
|
-
if (!metadata) {
|
|
1027
|
-
metadata = {};
|
|
1028
|
-
Reflect.defineMetadata(DATATYPE_METADATA, metadata, target);
|
|
1029
|
-
}
|
|
1030
|
-
metadata.kind = opra_schema_ns_exports.ComplexType.Kind;
|
|
1031
|
-
metadata.name = name;
|
|
1032
|
-
if (options)
|
|
1033
|
-
Object.assign(metadata, omit(options, ["kind", "name", "base", "fields"]));
|
|
1034
|
-
};
|
|
1035
|
-
}
|
|
1036
|
-
__name(ComplexTypeDecorator, "ComplexTypeDecorator");
|
|
1037
|
-
|
|
1038
1020
|
// ../../build/common/esm/document/utils/inspect.util.js
|
|
1039
1021
|
var nodeInspectCustom = Symbol.for("nodejs.util.inspect.custom");
|
|
1040
1022
|
var colorReset = "\x1B[0m";
|
|
1041
1023
|
var colorFgYellow = "\x1B[33m";
|
|
1042
1024
|
var colorFgMagenta = "\x1B[35m";
|
|
1043
1025
|
|
|
1026
|
+
// ../../build/common/esm/document/resource/endpoint.js
|
|
1027
|
+
import * as vg2 from "valgen";
|
|
1028
|
+
|
|
1044
1029
|
// ../../build/common/esm/document/data-type/data-type.js
|
|
1045
1030
|
var DataType = class _DataType {
|
|
1046
1031
|
static {
|
|
@@ -1053,7 +1038,8 @@ var DataType = class _DataType {
|
|
|
1053
1038
|
this.description = init?.description;
|
|
1054
1039
|
this.isAnonymous = !this.name;
|
|
1055
1040
|
}
|
|
1056
|
-
|
|
1041
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1042
|
+
exportSchema(options) {
|
|
1057
1043
|
return omitUndefined({
|
|
1058
1044
|
kind: this.kind,
|
|
1059
1045
|
description: this.description
|
|
@@ -1077,217 +1063,495 @@ var DataType = class _DataType {
|
|
|
1077
1063
|
}
|
|
1078
1064
|
};
|
|
1079
1065
|
|
|
1080
|
-
// ../../build/common/esm/document/
|
|
1081
|
-
import
|
|
1082
|
-
|
|
1083
|
-
// ../../build/common/esm/document/data-type/field-class.js
|
|
1084
|
-
var FieldClass = class {
|
|
1066
|
+
// ../../build/common/esm/document/resource/parameter.js
|
|
1067
|
+
import * as vg from "valgen";
|
|
1068
|
+
var Parameter = class {
|
|
1085
1069
|
static {
|
|
1086
|
-
__name(this, "
|
|
1070
|
+
__name(this, "Parameter");
|
|
1087
1071
|
}
|
|
1088
|
-
constructor(
|
|
1089
|
-
this.
|
|
1090
|
-
this.name = init.name;
|
|
1091
|
-
this.origin = init.origin || owner;
|
|
1072
|
+
constructor(name, init) {
|
|
1073
|
+
this.name = name;
|
|
1092
1074
|
this.type = init.type;
|
|
1093
1075
|
this.description = init.description;
|
|
1094
1076
|
this.isArray = init.isArray;
|
|
1095
1077
|
this.default = init.default;
|
|
1096
|
-
this.fixed = init.fixed;
|
|
1097
1078
|
this.required = init.required;
|
|
1098
|
-
this.exclusive = init.exclusive;
|
|
1099
1079
|
this.deprecated = init.deprecated;
|
|
1100
1080
|
this.examples = init.examples;
|
|
1081
|
+
this.isBuiltin = init.isBuiltin;
|
|
1101
1082
|
}
|
|
1102
|
-
exportSchema() {
|
|
1083
|
+
exportSchema(options) {
|
|
1103
1084
|
return omitUndefined({
|
|
1104
|
-
type: this.type.name ? this.type.name : this.type.exportSchema(),
|
|
1085
|
+
type: this.type.name ? this.type.name : this.type.exportSchema(options),
|
|
1105
1086
|
description: this.description,
|
|
1106
1087
|
isArray: this.isArray,
|
|
1107
1088
|
default: this.default,
|
|
1108
|
-
fixed: this.fixed,
|
|
1109
1089
|
required: this.required,
|
|
1110
|
-
exclusive: this.exclusive,
|
|
1111
1090
|
deprecated: this.deprecated,
|
|
1112
1091
|
examples: this.examples
|
|
1113
1092
|
});
|
|
1114
1093
|
}
|
|
1094
|
+
getDecoder() {
|
|
1095
|
+
if (!this._decoder)
|
|
1096
|
+
this._decoder = this.generateCodec("decode");
|
|
1097
|
+
return this._decoder;
|
|
1098
|
+
}
|
|
1099
|
+
getEncoder() {
|
|
1100
|
+
if (!this._encoder)
|
|
1101
|
+
this._encoder = this.generateCodec("encode");
|
|
1102
|
+
return this._encoder;
|
|
1103
|
+
}
|
|
1104
|
+
generateCodec(codec, options) {
|
|
1105
|
+
let fn = this.type.generateCodec(codec, options);
|
|
1106
|
+
if (this.isArray)
|
|
1107
|
+
fn = vg.stringSplit(",");
|
|
1108
|
+
return !options?.partial && this.required ? vg.required(fn) : vg.optional(fn);
|
|
1109
|
+
}
|
|
1115
1110
|
};
|
|
1116
1111
|
|
|
1117
|
-
// ../../build/common/esm/document/
|
|
1118
|
-
|
|
1119
|
-
import omit2 from "lodash.omit";
|
|
1120
|
-
import merge2 from "putil-merge";
|
|
1121
|
-
|
|
1122
|
-
// ../../build/common/esm/document/data-type/enum-type-class.js
|
|
1123
|
-
import * as vg from "valgen";
|
|
1124
|
-
var EnumTypeClass = class extends DataType {
|
|
1112
|
+
// ../../build/common/esm/document/resource/endpoint.js
|
|
1113
|
+
var Endpoint = class {
|
|
1125
1114
|
static {
|
|
1126
|
-
__name(this, "
|
|
1115
|
+
__name(this, "Endpoint");
|
|
1127
1116
|
}
|
|
1128
|
-
constructor(
|
|
1129
|
-
|
|
1130
|
-
this.
|
|
1131
|
-
this.
|
|
1132
|
-
this.
|
|
1133
|
-
this
|
|
1134
|
-
this.
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1117
|
+
constructor(resource, name, init) {
|
|
1118
|
+
this.resource = resource;
|
|
1119
|
+
this.name = name;
|
|
1120
|
+
this.decode = vg2.isAny();
|
|
1121
|
+
this.encode = vg2.isAny();
|
|
1122
|
+
Object.assign(this, init);
|
|
1123
|
+
this.parameters = new ResponsiveMap();
|
|
1124
|
+
if (init.parameters) {
|
|
1125
|
+
for (const [n, p] of Object.entries(init.parameters)) {
|
|
1126
|
+
this.defineParameter(n, p);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1138
1129
|
}
|
|
1139
|
-
|
|
1140
|
-
const
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
return
|
|
1130
|
+
defineParameter(name, init) {
|
|
1131
|
+
const type = init.type && init.type instanceof DataType ? init.type : this.resource.document.getDataType(init.type || "any");
|
|
1132
|
+
const prm = new Parameter(name, {
|
|
1133
|
+
...init,
|
|
1134
|
+
type
|
|
1135
|
+
});
|
|
1136
|
+
this.parameters.set(prm.name, prm);
|
|
1137
|
+
return prm;
|
|
1138
|
+
}
|
|
1139
|
+
exportSchema(options) {
|
|
1140
|
+
const schema = omitUndefined({
|
|
1141
|
+
description: this.description
|
|
1142
|
+
});
|
|
1143
|
+
if (this.parameters.size) {
|
|
1144
|
+
schema.parameters = {};
|
|
1145
|
+
for (const [name, param] of this.parameters.entries()) {
|
|
1146
|
+
if (!param.isBuiltin)
|
|
1147
|
+
schema.parameters[name] = param.exportSchema(options);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
return schema;
|
|
1147
1151
|
}
|
|
1148
1152
|
};
|
|
1149
1153
|
|
|
1150
|
-
// ../../build/common/esm/document/
|
|
1151
|
-
var
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
const values = Array.isArray(enumSource) ? enumSource.reduce((obj, v) => {
|
|
1155
|
-
obj[v] = v;
|
|
1156
|
-
return obj;
|
|
1157
|
-
}, {}) : enumSource;
|
|
1158
|
-
const metadata = {
|
|
1159
|
-
kind: opra_schema_ns_exports.EnumType.Kind,
|
|
1160
|
-
values
|
|
1161
|
-
};
|
|
1162
|
-
if (options)
|
|
1163
|
-
Object.assign(metadata, omit2(options, ["kind", "values"]));
|
|
1164
|
-
Reflect.defineMetadata(DATATYPE_METADATA, metadata, enumSource);
|
|
1165
|
-
return values;
|
|
1154
|
+
// ../../build/common/esm/document/resource/resource.js
|
|
1155
|
+
var Resource = class _Resource {
|
|
1156
|
+
static {
|
|
1157
|
+
__name(this, "Resource");
|
|
1166
1158
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
designType
|
|
1186
|
-
};
|
|
1187
|
-
if (designType === Array) {
|
|
1188
|
-
elemMeta.isArray = true;
|
|
1189
|
-
delete elemMeta.designType;
|
|
1159
|
+
constructor(parent, init) {
|
|
1160
|
+
this.actions = new ResponsiveMap();
|
|
1161
|
+
if (parent instanceof _Resource) {
|
|
1162
|
+
this.document = parent.document;
|
|
1163
|
+
this.parent = parent;
|
|
1164
|
+
} else
|
|
1165
|
+
this.document = parent;
|
|
1166
|
+
this.name = init.name;
|
|
1167
|
+
this.description = init.description;
|
|
1168
|
+
this.controller = init.controller;
|
|
1169
|
+
if (this.controller) {
|
|
1170
|
+
this.ctor = Object.getPrototypeOf(this.controller).constructor;
|
|
1171
|
+
} else
|
|
1172
|
+
this.ctor = init.ctor;
|
|
1173
|
+
if (init.actions) {
|
|
1174
|
+
for (const [name, meta] of Object.entries(init.actions)) {
|
|
1175
|
+
this.actions.set(name, new Endpoint(this, name, meta));
|
|
1176
|
+
}
|
|
1190
1177
|
}
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1178
|
+
}
|
|
1179
|
+
getFullPath() {
|
|
1180
|
+
if (this.parent && this.parent.name)
|
|
1181
|
+
return this.parent?.getFullPath() + "/" + this.name;
|
|
1182
|
+
return this.name;
|
|
1183
|
+
}
|
|
1184
|
+
exportSchema(options) {
|
|
1185
|
+
const schema = omitUndefined({
|
|
1186
|
+
kind: this.kind,
|
|
1187
|
+
description: this.description
|
|
1188
|
+
});
|
|
1189
|
+
if (this.actions.size) {
|
|
1190
|
+
schema.actions = {};
|
|
1191
|
+
for (const action of this.actions.values()) {
|
|
1192
|
+
schema.actions[action.name] = action.exportSchema(options);
|
|
1205
1193
|
}
|
|
1206
1194
|
}
|
|
1207
|
-
|
|
1208
|
-
};
|
|
1209
|
-
}
|
|
1210
|
-
__name(FieldDecorator, "FieldDecorator");
|
|
1211
|
-
|
|
1212
|
-
// ../../build/common/esm/document/data-type/field.js
|
|
1213
|
-
var ApiField = /* @__PURE__ */ __name(function(...args) {
|
|
1214
|
-
if (!this) {
|
|
1215
|
-
const [options] = args;
|
|
1216
|
-
return ApiField[DECORATOR](options);
|
|
1195
|
+
return schema;
|
|
1217
1196
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
|
-
Object.
|
|
1223
|
-
|
|
1197
|
+
toString() {
|
|
1198
|
+
return `[${Object.getPrototypeOf(this).constructor.name} ${this.name || "#anonymous"}]`;
|
|
1199
|
+
}
|
|
1200
|
+
[nodeInspectCustom]() {
|
|
1201
|
+
return `[${colorFgYellow + Object.getPrototypeOf(this).constructor.name + colorReset} ${colorFgMagenta + this.name + colorReset}]`;
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1224
1204
|
|
|
1225
|
-
// ../../build/common/esm/document/
|
|
1226
|
-
var
|
|
1205
|
+
// ../../build/common/esm/document/resource/container-class.js
|
|
1206
|
+
var ContainerClass = class _ContainerClass extends Resource {
|
|
1227
1207
|
static {
|
|
1228
|
-
__name(this, "
|
|
1229
|
-
}
|
|
1230
|
-
constructor(document, init) {
|
|
1231
|
-
super(document, init);
|
|
1232
|
-
this.kind = opra_schema_ns_exports.ComplexType.Kind;
|
|
1233
|
-
const own = this.own = {};
|
|
1234
|
-
own.ctor = init?.ctor || init?.base?.ctor;
|
|
1235
|
-
own.abstract = init?.abstract;
|
|
1236
|
-
own.additionalFields = init?.additionalFields;
|
|
1237
|
-
own.fields = new ResponsiveMap();
|
|
1238
|
-
this.kind = opra_schema_ns_exports.ComplexType.Kind;
|
|
1239
|
-
this.base = init?.base;
|
|
1240
|
-
this.ctor = own.ctor || Object;
|
|
1241
|
-
this.abstract = own.abstract;
|
|
1242
|
-
this.additionalFields = own.additionalFields;
|
|
1243
|
-
this.fields = new ResponsiveMap();
|
|
1244
|
-
if (this.base) {
|
|
1245
|
-
if (this.additionalFields == null)
|
|
1246
|
-
this.additionalFields = this.base.additionalFields;
|
|
1247
|
-
if (this.base.fields)
|
|
1248
|
-
for (const [k, el] of this.base.fields.entries()) {
|
|
1249
|
-
const newEl = new ApiField(this, el);
|
|
1250
|
-
this.fields.set(k, newEl);
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1208
|
+
__name(this, "ContainerClass");
|
|
1253
1209
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
this.
|
|
1257
|
-
this.
|
|
1258
|
-
|
|
1210
|
+
constructor(owner, init) {
|
|
1211
|
+
super(owner instanceof _ContainerClass ? owner.document : owner, init);
|
|
1212
|
+
this.kind = opra_schema_ns_exports.Container.Kind;
|
|
1213
|
+
this.resources = new ResponsiveMap();
|
|
1214
|
+
this.parent = owner instanceof _ContainerClass ? owner : void 0;
|
|
1259
1215
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
if (
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
field = f;
|
|
1216
|
+
exportSchema(options) {
|
|
1217
|
+
const schema = super.exportSchema(options);
|
|
1218
|
+
if (this.resources.size) {
|
|
1219
|
+
const resources = schema.resources = {};
|
|
1220
|
+
for (const [name, r] of this.resources.entries()) {
|
|
1221
|
+
resources[name] = r.exportSchema(options);
|
|
1267
1222
|
}
|
|
1268
|
-
return field;
|
|
1269
1223
|
}
|
|
1270
|
-
return
|
|
1224
|
+
return schema;
|
|
1271
1225
|
}
|
|
1272
|
-
|
|
1273
|
-
let
|
|
1274
|
-
if (
|
|
1275
|
-
|
|
1276
|
-
|
|
1226
|
+
getResource(path2, silent) {
|
|
1227
|
+
let resource;
|
|
1228
|
+
if (path2.includes("/")) {
|
|
1229
|
+
const arr = path2.split("/");
|
|
1230
|
+
let i;
|
|
1231
|
+
const l = arr.length;
|
|
1232
|
+
let container = this;
|
|
1233
|
+
for (i = 0; i < l; i++) {
|
|
1234
|
+
resource = container.resources.get(arr[i]);
|
|
1235
|
+
if (resource instanceof _ContainerClass)
|
|
1236
|
+
container = resource;
|
|
1237
|
+
else
|
|
1238
|
+
break;
|
|
1277
1239
|
}
|
|
1240
|
+
if (!resource || i < l - 1)
|
|
1241
|
+
resource = void 0;
|
|
1278
1242
|
} else
|
|
1279
|
-
|
|
1280
|
-
if (
|
|
1281
|
-
|
|
1282
|
-
|
|
1243
|
+
resource = this.resources.get(path2);
|
|
1244
|
+
if (resource || silent)
|
|
1245
|
+
return resource;
|
|
1246
|
+
throw new ResourceNotFoundError(path2);
|
|
1283
1247
|
}
|
|
1284
|
-
|
|
1285
|
-
const
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1248
|
+
getContainer(path2, silent) {
|
|
1249
|
+
const t = this.getResource(path2);
|
|
1250
|
+
if (!t && silent)
|
|
1251
|
+
return;
|
|
1252
|
+
if (t && t.kind === opra_schema_ns_exports.Container.Kind)
|
|
1253
|
+
return t;
|
|
1254
|
+
throw new NotAcceptableError(`Resource type "${t.name}" is not a Container`);
|
|
1255
|
+
}
|
|
1256
|
+
getCollection(path2, silent) {
|
|
1257
|
+
const t = this.getResource(path2);
|
|
1258
|
+
if (!t && silent)
|
|
1259
|
+
return;
|
|
1260
|
+
if (t && t.kind === opra_schema_ns_exports.Collection.Kind)
|
|
1261
|
+
return t;
|
|
1262
|
+
throw new NotAcceptableError(`Resource type "${t.name}" is not a Collection`);
|
|
1263
|
+
}
|
|
1264
|
+
getSingleton(path2, silent) {
|
|
1265
|
+
const t = this.getResource(path2);
|
|
1266
|
+
if (!t && silent)
|
|
1267
|
+
return;
|
|
1268
|
+
if (t && t.kind === opra_schema_ns_exports.Singleton.Kind)
|
|
1269
|
+
return t;
|
|
1270
|
+
throw new NotAcceptableError(`Resource type "${t.name}" is not a Singleton`);
|
|
1271
|
+
}
|
|
1272
|
+
getStorage(path2, silent) {
|
|
1273
|
+
const t = this.getResource(path2);
|
|
1274
|
+
if (!t && silent)
|
|
1275
|
+
return;
|
|
1276
|
+
if (t && t.kind === opra_schema_ns_exports.Storage.Kind)
|
|
1277
|
+
return t;
|
|
1278
|
+
throw new NotAcceptableError(`Resource type "${t.name}" is not a Storage`);
|
|
1279
|
+
}
|
|
1280
|
+
};
|
|
1281
|
+
|
|
1282
|
+
// ../../build/common/esm/document/resource/action-decorator.js
|
|
1283
|
+
function createActionDecorator(options, bannedProperties, list) {
|
|
1284
|
+
const decorator = /* @__PURE__ */ __name((target, propertyKey) => {
|
|
1285
|
+
if (typeof propertyKey === "string" && bannedProperties.includes(propertyKey))
|
|
1286
|
+
throw new TypeError(`The "${propertyKey}" property is reserved for "${propertyKey}" operations and cannot be used as an action'`);
|
|
1287
|
+
const resourceMetadata = Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {};
|
|
1288
|
+
resourceMetadata.actions = resourceMetadata.actions || {};
|
|
1289
|
+
const actionMeta = { ...options };
|
|
1290
|
+
resourceMetadata.actions[propertyKey] = actionMeta;
|
|
1291
|
+
for (const fn of list)
|
|
1292
|
+
fn(actionMeta);
|
|
1293
|
+
Reflect.defineMetadata(RESOURCE_METADATA, resourceMetadata, target.constructor);
|
|
1294
|
+
}, "decorator");
|
|
1295
|
+
decorator.Parameter = (name, arg0) => {
|
|
1296
|
+
const parameterOptions = typeof arg0 === "string" || typeof arg0 === "function" ? { type: arg0 } : { ...arg0 };
|
|
1297
|
+
list.push((operationMeta) => {
|
|
1298
|
+
operationMeta.parameters = operationMeta.parameters || {};
|
|
1299
|
+
operationMeta.parameters[name] = { ...parameterOptions };
|
|
1300
|
+
});
|
|
1301
|
+
return decorator;
|
|
1302
|
+
};
|
|
1303
|
+
return decorator;
|
|
1304
|
+
}
|
|
1305
|
+
__name(createActionDecorator, "createActionDecorator");
|
|
1306
|
+
|
|
1307
|
+
// ../../build/common/esm/document/resource/resource-decorator.js
|
|
1308
|
+
import omit from "lodash.omit";
|
|
1309
|
+
import merge2 from "putil-merge";
|
|
1310
|
+
function ResourceDecorator(kind, meta) {
|
|
1311
|
+
const namePattern = new RegExp(`^(.*)(${kind}|Resource|Controller)$`);
|
|
1312
|
+
return function(target) {
|
|
1313
|
+
let name = meta?.name;
|
|
1314
|
+
if (!name) {
|
|
1315
|
+
name = namePattern.exec(target.name)?.[1] || target.name;
|
|
1316
|
+
if (kind === "Container")
|
|
1317
|
+
name = name.charAt(0).toLowerCase() + name.substring(1);
|
|
1318
|
+
}
|
|
1319
|
+
const metadata = { kind, name };
|
|
1320
|
+
const baseMetadata = Reflect.getOwnMetadata(RESOURCE_METADATA, Object.getPrototypeOf(target));
|
|
1321
|
+
if (baseMetadata)
|
|
1322
|
+
merge2(metadata, baseMetadata, { deep: true });
|
|
1323
|
+
const oldMetadata = Reflect.getOwnMetadata(RESOURCE_METADATA, target);
|
|
1324
|
+
if (oldMetadata)
|
|
1325
|
+
merge2(metadata, oldMetadata, { deep: true });
|
|
1326
|
+
merge2(metadata, {
|
|
1327
|
+
kind,
|
|
1328
|
+
name,
|
|
1329
|
+
...omit(meta, ["kind", "name", "controller"])
|
|
1330
|
+
}, { deep: true });
|
|
1331
|
+
Reflect.defineMetadata(RESOURCE_METADATA, metadata, target);
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
__name(ResourceDecorator, "ResourceDecorator");
|
|
1335
|
+
|
|
1336
|
+
// ../../build/common/esm/document/resource/container-decorator.js
|
|
1337
|
+
function ContainerDecorator(options) {
|
|
1338
|
+
return ResourceDecorator(opra_schema_ns_exports.Container.Kind, options);
|
|
1339
|
+
}
|
|
1340
|
+
__name(ContainerDecorator, "ContainerDecorator");
|
|
1341
|
+
Object.assign(ContainerDecorator, ResourceDecorator);
|
|
1342
|
+
(function(ContainerDecorator2) {
|
|
1343
|
+
function Action(options) {
|
|
1344
|
+
const list = [];
|
|
1345
|
+
return createActionDecorator(options, [], list);
|
|
1346
|
+
}
|
|
1347
|
+
__name(Action, "Action");
|
|
1348
|
+
ContainerDecorator2.Action = Action;
|
|
1349
|
+
})(ContainerDecorator || (ContainerDecorator = {}));
|
|
1350
|
+
|
|
1351
|
+
// ../../build/common/esm/document/resource/container.js
|
|
1352
|
+
var Container2 = /* @__PURE__ */ __name(function(...args) {
|
|
1353
|
+
if (!this) {
|
|
1354
|
+
const [options] = args;
|
|
1355
|
+
return Container2[DECORATOR].call(void 0, options);
|
|
1356
|
+
}
|
|
1357
|
+
const [parent, init] = args;
|
|
1358
|
+
merge3(this, new ContainerClass(parent, init), { descriptor: true });
|
|
1359
|
+
if (init.resources) {
|
|
1360
|
+
const container = this;
|
|
1361
|
+
init.resources.forEach((r) => container.resources.set(r.name, r));
|
|
1362
|
+
}
|
|
1363
|
+
}, "Container");
|
|
1364
|
+
Container2.prototype = ContainerClass.prototype;
|
|
1365
|
+
Object.assign(Container2, ContainerDecorator);
|
|
1366
|
+
Container2[DECORATOR] = ContainerDecorator;
|
|
1367
|
+
|
|
1368
|
+
// ../../build/common/esm/document/data-type/complex-type.js
|
|
1369
|
+
import "reflect-metadata";
|
|
1370
|
+
import merge5 from "putil-merge";
|
|
1371
|
+
|
|
1372
|
+
// ../../build/common/esm/document/data-type/complex-type.decorator.js
|
|
1373
|
+
import omit2 from "lodash.omit";
|
|
1374
|
+
function ComplexTypeDecorator(options) {
|
|
1375
|
+
return function(target) {
|
|
1376
|
+
const name = options?.name || target.name.match(TYPENAME_PATTERN)?.[1] || target.name;
|
|
1377
|
+
let metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target);
|
|
1378
|
+
if (!metadata) {
|
|
1379
|
+
metadata = {};
|
|
1380
|
+
Reflect.defineMetadata(DATATYPE_METADATA, metadata, target);
|
|
1381
|
+
}
|
|
1382
|
+
metadata.kind = opra_schema_ns_exports.ComplexType.Kind;
|
|
1383
|
+
metadata.name = name;
|
|
1384
|
+
if (options)
|
|
1385
|
+
Object.assign(metadata, omit2(options, ["kind", "name", "base", "fields"]));
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
__name(ComplexTypeDecorator, "ComplexTypeDecorator");
|
|
1389
|
+
|
|
1390
|
+
// ../../build/common/esm/document/data-type/complex-type-class.js
|
|
1391
|
+
import * as vg4 from "valgen";
|
|
1392
|
+
|
|
1393
|
+
// ../../build/common/esm/document/data-type/field.js
|
|
1394
|
+
import merge4 from "putil-merge";
|
|
1395
|
+
|
|
1396
|
+
// ../../build/common/esm/document/data-type/field-class.js
|
|
1397
|
+
import * as vg3 from "valgen";
|
|
1398
|
+
var FieldClass = class {
|
|
1399
|
+
static {
|
|
1400
|
+
__name(this, "FieldClass");
|
|
1401
|
+
}
|
|
1402
|
+
constructor(owner, init) {
|
|
1403
|
+
this.owner = owner;
|
|
1404
|
+
this.origin = init.origin || owner;
|
|
1405
|
+
this.type = init.type;
|
|
1406
|
+
this.name = init.name;
|
|
1407
|
+
this.description = init.description;
|
|
1408
|
+
this.isArray = init.isArray;
|
|
1409
|
+
this.default = init.default;
|
|
1410
|
+
this.fixed = init.fixed;
|
|
1411
|
+
this.required = init.required;
|
|
1412
|
+
this.exclusive = init.exclusive;
|
|
1413
|
+
this.deprecated = init.deprecated;
|
|
1414
|
+
this.examples = init.examples;
|
|
1415
|
+
}
|
|
1416
|
+
exportSchema(options) {
|
|
1417
|
+
return omitUndefined({
|
|
1418
|
+
type: this.type.name ? this.type.name : this.type.exportSchema(options),
|
|
1419
|
+
description: this.description,
|
|
1420
|
+
isArray: this.isArray,
|
|
1421
|
+
default: this.default,
|
|
1422
|
+
fixed: this.fixed,
|
|
1423
|
+
required: this.required,
|
|
1424
|
+
exclusive: this.exclusive,
|
|
1425
|
+
deprecated: this.deprecated,
|
|
1426
|
+
examples: this.examples
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
getDecoder() {
|
|
1430
|
+
if (!this._decoder)
|
|
1431
|
+
this._decoder = this.generateCodec("decode");
|
|
1432
|
+
return this._decoder;
|
|
1433
|
+
}
|
|
1434
|
+
getEncoder() {
|
|
1435
|
+
if (!this._encoder)
|
|
1436
|
+
this._encoder = this.generateCodec("encode");
|
|
1437
|
+
return this._encoder;
|
|
1438
|
+
}
|
|
1439
|
+
generateCodec(codec, options) {
|
|
1440
|
+
let fn = this.type.generateCodec(codec, options);
|
|
1441
|
+
if (this.isArray)
|
|
1442
|
+
fn = vg3.isArray(fn);
|
|
1443
|
+
return !options?.partial && this.required ? vg3.required(fn) : vg3.optional(fn);
|
|
1444
|
+
}
|
|
1445
|
+
};
|
|
1446
|
+
|
|
1447
|
+
// ../../build/common/esm/document/data-type/field-decorator.js
|
|
1448
|
+
function FieldDecorator(options) {
|
|
1449
|
+
return function(target, propertyKey) {
|
|
1450
|
+
if (typeof propertyKey !== "string")
|
|
1451
|
+
throw new TypeError(`Symbol properties can't be used as a field`);
|
|
1452
|
+
const metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target.constructor) || {};
|
|
1453
|
+
metadata.kind = opra_schema_ns_exports.ComplexType.Kind;
|
|
1454
|
+
metadata.fields = metadata.fields || {};
|
|
1455
|
+
const designType = Reflect.getMetadata("design:type", target, propertyKey);
|
|
1456
|
+
const elemMeta = metadata.fields[propertyKey] = {
|
|
1457
|
+
...options,
|
|
1458
|
+
designType
|
|
1459
|
+
};
|
|
1460
|
+
if (designType === Array) {
|
|
1461
|
+
elemMeta.isArray = true;
|
|
1462
|
+
delete elemMeta.designType;
|
|
1463
|
+
}
|
|
1464
|
+
Reflect.defineMetadata(DATATYPE_METADATA, omitUndefined(metadata), target.constructor);
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
__name(FieldDecorator, "FieldDecorator");
|
|
1468
|
+
|
|
1469
|
+
// ../../build/common/esm/document/data-type/field.js
|
|
1470
|
+
var ApiField = /* @__PURE__ */ __name(function(...args) {
|
|
1471
|
+
if (!this) {
|
|
1472
|
+
const [options] = args;
|
|
1473
|
+
return ApiField[DECORATOR](options);
|
|
1474
|
+
}
|
|
1475
|
+
const [owner, init] = args;
|
|
1476
|
+
merge4(this, new FieldClass(owner, init), { descriptor: true });
|
|
1477
|
+
}, "ApiField");
|
|
1478
|
+
ApiField.prototype = FieldClass.prototype;
|
|
1479
|
+
Object.assign(ApiField, FieldDecorator);
|
|
1480
|
+
ApiField[DECORATOR] = FieldDecorator;
|
|
1481
|
+
|
|
1482
|
+
// ../../build/common/esm/document/data-type/complex-type-class.js
|
|
1483
|
+
var ComplexTypeClass = class extends DataType {
|
|
1484
|
+
static {
|
|
1485
|
+
__name(this, "ComplexTypeClass");
|
|
1486
|
+
}
|
|
1487
|
+
constructor(document, init) {
|
|
1488
|
+
super(document, init);
|
|
1489
|
+
this.kind = opra_schema_ns_exports.ComplexType.Kind;
|
|
1490
|
+
const own = this.own = {};
|
|
1491
|
+
own.ctor = init.ctor;
|
|
1492
|
+
if (init.base) {
|
|
1493
|
+
if (!(init.base.kind === "ComplexType" || init.base.kind === "MappedType" || init.base.kind === "UnionType"))
|
|
1494
|
+
throw new TypeError('"base" argument must be one of ComplexType or MappedType or UnionType');
|
|
1495
|
+
own.ctor = own.ctor || init.base.ctor;
|
|
1496
|
+
}
|
|
1497
|
+
own.additionalFields = init?.additionalFields;
|
|
1498
|
+
own.fields = new ResponsiveMap();
|
|
1499
|
+
this.kind = opra_schema_ns_exports.ComplexType.Kind;
|
|
1500
|
+
this.base = init?.base;
|
|
1501
|
+
this.ctor = own.ctor || Object;
|
|
1502
|
+
this.abstract = init.abstract;
|
|
1503
|
+
this.additionalFields = own.additionalFields;
|
|
1504
|
+
if (this.base?.additionalFields === true && this.additionalFields !== true)
|
|
1505
|
+
this.additionalFields = true;
|
|
1506
|
+
else if (this.base?.additionalFields === "error" && !this.additionalFields)
|
|
1507
|
+
this.additionalFields = "error";
|
|
1508
|
+
this.fields = new ResponsiveMap();
|
|
1509
|
+
if (this.base) {
|
|
1510
|
+
if (this.base.fields)
|
|
1511
|
+
for (const [k, el] of this.base.fields.entries()) {
|
|
1512
|
+
const field = new ApiField(this, el);
|
|
1513
|
+
this.fields.set(k, field);
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
if (init.fields) {
|
|
1517
|
+
for (const [k, el] of Object.entries(init.fields)) {
|
|
1518
|
+
const field = new ApiField(this, el);
|
|
1519
|
+
this.own.fields.set(field.name, field);
|
|
1520
|
+
this.fields.set(k, field);
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
findField(nameOrPath) {
|
|
1525
|
+
let field;
|
|
1526
|
+
if (nameOrPath.includes(".")) {
|
|
1527
|
+
for (const [, f] of this.iteratePath(nameOrPath, true)) {
|
|
1528
|
+
if (!f)
|
|
1529
|
+
return;
|
|
1530
|
+
field = f;
|
|
1531
|
+
}
|
|
1532
|
+
return field;
|
|
1533
|
+
}
|
|
1534
|
+
return this.fields.get(nameOrPath);
|
|
1535
|
+
}
|
|
1536
|
+
getField(nameOrPath) {
|
|
1537
|
+
let field;
|
|
1538
|
+
if (nameOrPath.includes(".")) {
|
|
1539
|
+
for (const [, f] of this.iteratePath(nameOrPath)) {
|
|
1540
|
+
field = f;
|
|
1541
|
+
}
|
|
1542
|
+
} else
|
|
1543
|
+
field = this.fields.get(nameOrPath);
|
|
1544
|
+
if (!field)
|
|
1545
|
+
throw new Error(translate("error:UNKNOWN_FIELD", { field: nameOrPath }));
|
|
1546
|
+
return field;
|
|
1547
|
+
}
|
|
1548
|
+
iteratePath(path2, silent) {
|
|
1549
|
+
const arr = path2.split(".");
|
|
1550
|
+
const len = arr.length;
|
|
1551
|
+
let dataType = this;
|
|
1552
|
+
let field;
|
|
1553
|
+
let curPath = "";
|
|
1554
|
+
let s;
|
|
1291
1555
|
let i = -1;
|
|
1292
1556
|
const ComplexType3 = Object.getPrototypeOf(this).constructor;
|
|
1293
1557
|
return {
|
|
@@ -1333,23 +1597,23 @@ var ComplexTypeClass = class extends DataType {
|
|
|
1333
1597
|
}).flat();
|
|
1334
1598
|
return array.length ? array : void 0;
|
|
1335
1599
|
}
|
|
1336
|
-
exportSchema() {
|
|
1337
|
-
const out = super.exportSchema();
|
|
1600
|
+
exportSchema(options) {
|
|
1601
|
+
const out = super.exportSchema(options);
|
|
1338
1602
|
Object.assign(out, omitUndefined({
|
|
1339
|
-
base: this.base ? this.base.name ? this.base.name : this.base.exportSchema() : void 0,
|
|
1340
|
-
abstract: this.
|
|
1603
|
+
base: this.base ? this.base.name ? this.base.name : this.base.exportSchema(options) : void 0,
|
|
1604
|
+
abstract: this.abstract,
|
|
1341
1605
|
additionalFields: this.own.additionalFields
|
|
1342
1606
|
}));
|
|
1343
1607
|
if (this.own.fields.size) {
|
|
1344
1608
|
const fields = out.fields = {};
|
|
1345
1609
|
for (const field of this.own.fields.values()) {
|
|
1346
|
-
fields[field.name] = field.exportSchema();
|
|
1610
|
+
fields[field.name] = field.exportSchema(options);
|
|
1347
1611
|
}
|
|
1348
1612
|
}
|
|
1349
1613
|
return omitUndefined(out);
|
|
1350
1614
|
}
|
|
1351
1615
|
isTypeOf(t) {
|
|
1352
|
-
return t === this.own
|
|
1616
|
+
return t === this.own?.ctor;
|
|
1353
1617
|
}
|
|
1354
1618
|
extendsFrom(t) {
|
|
1355
1619
|
const base = t instanceof DataType ? t : this.document.getDataType(t);
|
|
@@ -1360,6 +1624,18 @@ var ComplexTypeClass = class extends DataType {
|
|
|
1360
1624
|
}
|
|
1361
1625
|
return false;
|
|
1362
1626
|
}
|
|
1627
|
+
generateCodec(codec, options) {
|
|
1628
|
+
const schema = {};
|
|
1629
|
+
for (const f of this.fields.values()) {
|
|
1630
|
+
schema[f.name] = f.generateCodec(codec, options);
|
|
1631
|
+
}
|
|
1632
|
+
return vg4.isObject(schema, {
|
|
1633
|
+
ctor: this.ctor,
|
|
1634
|
+
additionalFields: this.additionalFields ?? false,
|
|
1635
|
+
name: this.name,
|
|
1636
|
+
caseInSensitive: !options?.caseSensitive
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1363
1639
|
};
|
|
1364
1640
|
|
|
1365
1641
|
// ../../build/common/esm/document/data-type/complex-type.js
|
|
@@ -1369,28 +1645,47 @@ var ComplexType2 = /* @__PURE__ */ __name(function(...args) {
|
|
|
1369
1645
|
return ComplexType2[DECORATOR](options);
|
|
1370
1646
|
}
|
|
1371
1647
|
const [document, init] = args;
|
|
1372
|
-
|
|
1648
|
+
merge5(this, new ComplexTypeClass(document, init), { descriptor: true });
|
|
1373
1649
|
}, "ComplexType");
|
|
1374
1650
|
ComplexType2.prototype = ComplexTypeClass.prototype;
|
|
1375
1651
|
Object.assign(ComplexType2, ComplexTypeDecorator);
|
|
1376
1652
|
ComplexType2[DECORATOR] = ComplexTypeDecorator;
|
|
1377
1653
|
|
|
1378
|
-
// ../../build/common/esm/document/
|
|
1379
|
-
var
|
|
1654
|
+
// ../../build/common/esm/document/document-base.js
|
|
1655
|
+
var DocumentBase = class {
|
|
1380
1656
|
static {
|
|
1381
|
-
__name(this, "
|
|
1657
|
+
__name(this, "DocumentBase");
|
|
1658
|
+
}
|
|
1659
|
+
constructor() {
|
|
1660
|
+
this.info = {
|
|
1661
|
+
version: "",
|
|
1662
|
+
title: ""
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Export as OPRA schema definition object
|
|
1667
|
+
*/
|
|
1668
|
+
exportSchema() {
|
|
1669
|
+
return omitUndefined({
|
|
1670
|
+
version: opra_schema_ns_exports.SpecVersion,
|
|
1671
|
+
url: this.url,
|
|
1672
|
+
info: cloneObject(this.info, true)
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
};
|
|
1676
|
+
|
|
1677
|
+
// ../../build/common/esm/document/type-document.js
|
|
1678
|
+
var TypeDocument = class extends DocumentBase {
|
|
1679
|
+
static {
|
|
1680
|
+
__name(this, "TypeDocument");
|
|
1382
1681
|
}
|
|
1383
1682
|
constructor() {
|
|
1683
|
+
super();
|
|
1384
1684
|
this._designCtorMap = /* @__PURE__ */ new Map();
|
|
1385
1685
|
this._typeCache = new ResponsiveMap();
|
|
1386
1686
|
this._typesCacheByCtor = /* @__PURE__ */ new Map();
|
|
1387
1687
|
this.references = new ResponsiveMap();
|
|
1388
1688
|
this.types = new ResponsiveMap();
|
|
1389
|
-
this.resources = new ResponsiveMap();
|
|
1390
|
-
this.info = {
|
|
1391
|
-
version: "",
|
|
1392
|
-
title: ""
|
|
1393
|
-
};
|
|
1394
1689
|
const BigIntConstructor = Object.getPrototypeOf(BigInt(0)).constructor;
|
|
1395
1690
|
const BufferConstructor = Object.getPrototypeOf(Buffer.from([]));
|
|
1396
1691
|
this._designCtorMap.set(String, "string");
|
|
@@ -1407,22 +1702,30 @@ var ApiDocument = class {
|
|
|
1407
1702
|
*
|
|
1408
1703
|
*/
|
|
1409
1704
|
getDataType(arg0, silent) {
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1705
|
+
if (typeof arg0 === "function") {
|
|
1706
|
+
const x = this._designCtorMap.get(arg0);
|
|
1707
|
+
if (x)
|
|
1708
|
+
arg0 = x;
|
|
1709
|
+
}
|
|
1710
|
+
let dataType;
|
|
1711
|
+
let name;
|
|
1712
|
+
if (typeof arg0 === "function") {
|
|
1713
|
+
const metadata = Reflect.getMetadata(DATATYPE_METADATA, arg0);
|
|
1714
|
+
name = metadata?.name || arg0.name;
|
|
1715
|
+
} else if (typeof arg0 === "function") {
|
|
1716
|
+
const metadata = Reflect.getMetadata(DATATYPE_METADATA, arg0);
|
|
1717
|
+
name = metadata?.name;
|
|
1718
|
+
} else
|
|
1719
|
+
name = String(arg0);
|
|
1720
|
+
const t = typeof arg0 === "string" ? this._typeCache.get(arg0) : this._typesCacheByCtor.get(arg0);
|
|
1721
|
+
if (t)
|
|
1414
1722
|
return t;
|
|
1415
1723
|
if (t === null) {
|
|
1416
1724
|
if (silent)
|
|
1417
1725
|
return;
|
|
1418
1726
|
throw new Error(`Data type "${name}" does not exists`);
|
|
1419
1727
|
}
|
|
1420
|
-
if (typeof arg0 === "
|
|
1421
|
-
const x = this._designCtorMap.get(arg0);
|
|
1422
|
-
if (x)
|
|
1423
|
-
arg0 = x;
|
|
1424
|
-
}
|
|
1425
|
-
if (typeof arg0 === "string") {
|
|
1728
|
+
if (typeof arg0 === "string" && arg0) {
|
|
1426
1729
|
const m = NAMESPACE_PATTERN.exec(arg0);
|
|
1427
1730
|
if (!m)
|
|
1428
1731
|
throw new TypeError(`Invalid data type name "${name}"`);
|
|
@@ -1474,9 +1777,19 @@ var ApiDocument = class {
|
|
|
1474
1777
|
if (dataType)
|
|
1475
1778
|
return dataType;
|
|
1476
1779
|
if (!silent)
|
|
1477
|
-
throw new
|
|
1780
|
+
throw new Error(`No data type mapping found for class "${name}"`);
|
|
1478
1781
|
return;
|
|
1479
1782
|
}
|
|
1783
|
+
if (typeof arg0 === "object") {
|
|
1784
|
+
const metadata = arg0[DATATYPE_METADATA];
|
|
1785
|
+
if (metadata && metadata.name) {
|
|
1786
|
+
dataType = this.getDataType(metadata.name, true);
|
|
1787
|
+
if (dataType)
|
|
1788
|
+
return dataType;
|
|
1789
|
+
if (!silent)
|
|
1790
|
+
throw new Error(`No data type mapping found for class "${name}"`);
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1480
1793
|
if (!silent)
|
|
1481
1794
|
throw new TypeError("Invalid argument");
|
|
1482
1795
|
}
|
|
@@ -1498,119 +1811,82 @@ var ApiDocument = class {
|
|
|
1498
1811
|
return t;
|
|
1499
1812
|
throw new NotAcceptableError(`Data type "${t.name || t}" is not a SimpleType`);
|
|
1500
1813
|
}
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
const m = NAMESPACE_PATTERN.exec(path2);
|
|
1504
|
-
if (!m)
|
|
1505
|
-
throw new NotFoundError(`Invalid resource path "${path2}"`);
|
|
1506
|
-
if (m[2]) {
|
|
1507
|
-
const ref = this.references.get(m[1]);
|
|
1508
|
-
if (!ref) {
|
|
1509
|
-
if (silent)
|
|
1510
|
-
return;
|
|
1511
|
-
throw new NotFoundError(`Reference "${m[1]}" not found`);
|
|
1512
|
-
}
|
|
1513
|
-
return ref.getResource(m[2]);
|
|
1514
|
-
} else {
|
|
1515
|
-
const name = m[1];
|
|
1516
|
-
resource = this.resources.get(name);
|
|
1517
|
-
if (resource)
|
|
1518
|
-
return resource;
|
|
1519
|
-
const references = Array.from(this.references.values()).reverse();
|
|
1520
|
-
for (const ref of references) {
|
|
1521
|
-
resource = silent ? ref.getResource(name, silent) : ref.getResource(name);
|
|
1522
|
-
if (resource)
|
|
1523
|
-
return resource;
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
if (silent)
|
|
1527
|
-
return;
|
|
1528
|
-
throw new ResourceNotFoundError(path2);
|
|
1529
|
-
}
|
|
1530
|
-
getCollection(path2, silent) {
|
|
1531
|
-
const t = this.getResource(path2);
|
|
1532
|
-
if (!t && silent)
|
|
1533
|
-
return;
|
|
1534
|
-
if (t && t.kind === opra_schema_ns_exports.Collection.Kind)
|
|
1535
|
-
return t;
|
|
1536
|
-
throw new NotAcceptableError(`Resource type "${t.name}" is not a Collection`);
|
|
1537
|
-
}
|
|
1538
|
-
getSingleton(path2, silent) {
|
|
1539
|
-
const t = this.getResource(path2);
|
|
1814
|
+
getEnumType(nameOrCtor, silent) {
|
|
1815
|
+
const t = this.getDataType(nameOrCtor);
|
|
1540
1816
|
if (!t && silent)
|
|
1541
1817
|
return;
|
|
1542
|
-
if (t && t.kind === opra_schema_ns_exports.
|
|
1818
|
+
if (t && t.kind === opra_schema_ns_exports.EnumType.Kind)
|
|
1543
1819
|
return t;
|
|
1544
|
-
throw new NotAcceptableError(`
|
|
1545
|
-
}
|
|
1546
|
-
getStorage(path2, silent) {
|
|
1547
|
-
const t = this.getResource(path2);
|
|
1548
|
-
if (!t && silent)
|
|
1549
|
-
return;
|
|
1550
|
-
if (t && t.kind === opra_schema_ns_exports.Storage.Kind)
|
|
1551
|
-
return t;
|
|
1552
|
-
throw new NotAcceptableError(`Resource type "${t.name}" is not a Storage`);
|
|
1820
|
+
throw new NotAcceptableError(`Data type "${t.name || t}" is not a EnumType`);
|
|
1553
1821
|
}
|
|
1554
1822
|
/**
|
|
1555
1823
|
* Export as Opra schema definition object
|
|
1556
1824
|
*/
|
|
1557
1825
|
exportSchema(options) {
|
|
1558
|
-
|
|
1559
|
-
return cloneObject(this._metadataCache, options?.webSafe);
|
|
1560
|
-
const schema = {
|
|
1561
|
-
version: opra_schema_ns_exports.SpecVersion,
|
|
1562
|
-
url: this.url,
|
|
1563
|
-
info: cloneObject(this.info)
|
|
1564
|
-
};
|
|
1826
|
+
const schema = super.exportSchema();
|
|
1565
1827
|
if (this.references.size) {
|
|
1566
1828
|
const references = {};
|
|
1567
1829
|
let i = 0;
|
|
1568
1830
|
for (const [ns, r] of this.references.entries()) {
|
|
1569
1831
|
if (ns.toLowerCase() === "opra")
|
|
1570
1832
|
continue;
|
|
1571
|
-
references[ns] = r.url ? r.url : r.exportSchema();
|
|
1833
|
+
references[ns] = r.url ? r.url : r.exportSchema(options);
|
|
1572
1834
|
i++;
|
|
1573
1835
|
}
|
|
1574
1836
|
if (i)
|
|
1575
1837
|
schema.references = references;
|
|
1576
1838
|
}
|
|
1577
|
-
if (this.resources.size) {
|
|
1578
|
-
const resources = schema.resources = {};
|
|
1579
|
-
for (const [name, r] of this.resources.entries()) {
|
|
1580
|
-
resources[name] = r.exportSchema();
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
1839
|
if (this.types.size) {
|
|
1584
1840
|
const types = schema.types = {};
|
|
1585
1841
|
for (const [name, r] of this.types.entries()) {
|
|
1586
|
-
types[name] = r.exportSchema();
|
|
1842
|
+
types[name] = r.exportSchema(options);
|
|
1587
1843
|
}
|
|
1588
1844
|
}
|
|
1589
|
-
|
|
1590
|
-
return this._metadataCache;
|
|
1845
|
+
return schema;
|
|
1591
1846
|
}
|
|
1592
1847
|
invalidate() {
|
|
1593
|
-
this._metadataCache = void 0;
|
|
1594
1848
|
this._typeCache.clear();
|
|
1595
1849
|
this._typesCacheByCtor.clear();
|
|
1596
1850
|
}
|
|
1597
1851
|
};
|
|
1598
1852
|
|
|
1599
|
-
// ../../build/common/esm/document/
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
if (typeof r === "string") {
|
|
1604
|
-
document.references.set(ns, await this.createDocumentFromUrl(r));
|
|
1605
|
-
} else if (r instanceof ApiDocument)
|
|
1606
|
-
document.references.set(ns, r);
|
|
1607
|
-
else if (typeof r === "object") {
|
|
1608
|
-
document.references.set(ns, await this.createDocument(r));
|
|
1609
|
-
} else
|
|
1610
|
-
throw new TypeError(`Invalid document reference (${ns}) in schema`);
|
|
1853
|
+
// ../../build/common/esm/document/api-document.js
|
|
1854
|
+
var ApiDocument = class extends TypeDocument {
|
|
1855
|
+
static {
|
|
1856
|
+
__name(this, "ApiDocument");
|
|
1611
1857
|
}
|
|
1612
|
-
|
|
1613
|
-
|
|
1858
|
+
constructor() {
|
|
1859
|
+
super(...arguments);
|
|
1860
|
+
this.root = new Container2(this, { name: "" });
|
|
1861
|
+
}
|
|
1862
|
+
getResource(path2, silent) {
|
|
1863
|
+
return this.root.getResource(path2, silent);
|
|
1864
|
+
}
|
|
1865
|
+
getContainer(path2, silent) {
|
|
1866
|
+
return this.root.getContainer(path2, silent);
|
|
1867
|
+
}
|
|
1868
|
+
getCollection(path2, silent) {
|
|
1869
|
+
return this.root.getCollection(path2, silent);
|
|
1870
|
+
}
|
|
1871
|
+
getSingleton(path2, silent) {
|
|
1872
|
+
return this.root.getSingleton(path2, silent);
|
|
1873
|
+
}
|
|
1874
|
+
getStorage(path2, silent) {
|
|
1875
|
+
return this.root.getStorage(path2, silent);
|
|
1876
|
+
}
|
|
1877
|
+
/**
|
|
1878
|
+
* Export as Opra schema definition object
|
|
1879
|
+
*/
|
|
1880
|
+
exportSchema(options) {
|
|
1881
|
+
const schema = super.exportSchema(options);
|
|
1882
|
+
schema.root = this.root.exportSchema(options);
|
|
1883
|
+
delete schema.root.kind;
|
|
1884
|
+
return schema;
|
|
1885
|
+
}
|
|
1886
|
+
};
|
|
1887
|
+
|
|
1888
|
+
// ../../build/common/esm/document/factory/type-document-factory.js
|
|
1889
|
+
import { validator } from "valgen";
|
|
1614
1890
|
|
|
1615
1891
|
// ../../node_modules/tslib/tslib.es6.mjs
|
|
1616
1892
|
function __decorate(decorators, target, key, desc) {
|
|
@@ -1627,9 +1903,9 @@ __name(__decorate, "__decorate");
|
|
|
1627
1903
|
|
|
1628
1904
|
// ../../build/common/esm/document/data-type/simple-type.js
|
|
1629
1905
|
import "reflect-metadata";
|
|
1630
|
-
import
|
|
1906
|
+
import merge6 from "putil-merge";
|
|
1631
1907
|
|
|
1632
|
-
// ../../build/common/esm/document/
|
|
1908
|
+
// ../../build/common/esm/document/data-type/simple-type.decorator.js
|
|
1633
1909
|
import omit3 from "lodash.omit";
|
|
1634
1910
|
function SimpleTypeDecorator(options) {
|
|
1635
1911
|
return function(target) {
|
|
@@ -1646,7 +1922,7 @@ function SimpleTypeDecorator(options) {
|
|
|
1646
1922
|
__name(SimpleTypeDecorator, "SimpleTypeDecorator");
|
|
1647
1923
|
|
|
1648
1924
|
// ../../build/common/esm/document/data-type/simple-type-class.js
|
|
1649
|
-
import * as
|
|
1925
|
+
import * as vg5 from "valgen";
|
|
1650
1926
|
var SimpleTypeClass = class extends DataType {
|
|
1651
1927
|
static {
|
|
1652
1928
|
__name(this, "SimpleTypeClass");
|
|
@@ -1655,13 +1931,24 @@ var SimpleTypeClass = class extends DataType {
|
|
|
1655
1931
|
super(document, init);
|
|
1656
1932
|
this.kind = opra_schema_ns_exports.SimpleType.Kind;
|
|
1657
1933
|
this.base = init.base;
|
|
1658
|
-
this.decode = init.decoder || init.base?.decode ||
|
|
1659
|
-
this.encode = init.encoder || init.base?.encode ||
|
|
1934
|
+
this.decode = init.decoder || init.base?.decode || vg5.isAny();
|
|
1935
|
+
this.encode = init.encoder || init.base?.encode || vg5.isAny();
|
|
1660
1936
|
}
|
|
1661
|
-
exportSchema() {
|
|
1662
|
-
const out = super.exportSchema();
|
|
1937
|
+
exportSchema(options) {
|
|
1938
|
+
const out = super.exportSchema(options);
|
|
1939
|
+
Object.assign(out, omitUndefined({
|
|
1940
|
+
base: this.base ? this.base.name ? this.base.name : this.base.exportSchema(options) : void 0,
|
|
1941
|
+
decode: !options?.webSafe ? this.decode : void 0,
|
|
1942
|
+
encode: !options?.webSafe ? this.encode : void 0
|
|
1943
|
+
}));
|
|
1663
1944
|
return out;
|
|
1664
1945
|
}
|
|
1946
|
+
generateCodec(codec) {
|
|
1947
|
+
if (codec === "encode")
|
|
1948
|
+
return this.encode;
|
|
1949
|
+
else
|
|
1950
|
+
return this.decode;
|
|
1951
|
+
}
|
|
1665
1952
|
};
|
|
1666
1953
|
|
|
1667
1954
|
// ../../build/common/esm/document/data-type/simple-type.js
|
|
@@ -1671,7 +1958,7 @@ var SimpleType2 = /* @__PURE__ */ __name(function(...args) {
|
|
|
1671
1958
|
return SimpleType2[DECORATOR](options);
|
|
1672
1959
|
}
|
|
1673
1960
|
const [document, init] = args;
|
|
1674
|
-
|
|
1961
|
+
merge6(this, new SimpleTypeClass(document, init), { descriptor: true });
|
|
1675
1962
|
}, "SimpleType");
|
|
1676
1963
|
SimpleType2.prototype = SimpleTypeClass.prototype;
|
|
1677
1964
|
Object.assign(SimpleType2, SimpleTypeDecorator);
|
|
@@ -1901,343 +2188,558 @@ TimestampType = __decorate([
|
|
|
1901
2188
|
})
|
|
1902
2189
|
], TimestampType);
|
|
1903
2190
|
|
|
1904
|
-
// ../../build/common/esm/document/
|
|
1905
|
-
async function createDocument(init, options) {
|
|
1906
|
-
this.document.url = init.url;
|
|
1907
|
-
if (init.info)
|
|
1908
|
-
Object.assign(this.document.info, init.info);
|
|
1909
|
-
if (!options?.noBuiltinTypes) {
|
|
1910
|
-
const builtinDocument = await this.createBuiltinTypeDocument();
|
|
1911
|
-
this.document.references.set("Opra", builtinDocument);
|
|
1912
|
-
for (const [c, s] of Object.getPrototypeOf(this).constructor.designTypeMap.entries())
|
|
1913
|
-
this.document._designTypeMap.set(c, s);
|
|
1914
|
-
}
|
|
1915
|
-
if (init.references)
|
|
1916
|
-
await this.addReferences(init.references);
|
|
1917
|
-
if (init.types) {
|
|
1918
|
-
this.curPath.push("types");
|
|
1919
|
-
if (Array.isArray(init.types)) {
|
|
1920
|
-
for (const type of init.types)
|
|
1921
|
-
await this.importTypeClass(type);
|
|
1922
|
-
} else
|
|
1923
|
-
this.typeQueue.setAll(init.types);
|
|
1924
|
-
await this.processTypes();
|
|
1925
|
-
this.curPath.pop();
|
|
1926
|
-
}
|
|
1927
|
-
if (init.resources) {
|
|
1928
|
-
this.curPath.push("resources");
|
|
1929
|
-
if (Array.isArray(init.resources)) {
|
|
1930
|
-
for (const res of init.resources)
|
|
1931
|
-
await this.importSourceClass(res);
|
|
1932
|
-
} else
|
|
1933
|
-
this.sourceQueue.setAll(init.resources);
|
|
1934
|
-
await this.processSourceQueue();
|
|
1935
|
-
this.curPath.pop();
|
|
1936
|
-
}
|
|
1937
|
-
this.document.types.sort();
|
|
1938
|
-
this.document.resources.sort();
|
|
1939
|
-
return this.document;
|
|
1940
|
-
}
|
|
1941
|
-
__name(createDocument, "createDocument");
|
|
1942
|
-
async function createDocumentFromUrl(url) {
|
|
1943
|
-
const resp = await fetch(url, { method: "GET" });
|
|
1944
|
-
const init = await resp.json();
|
|
1945
|
-
if (!init)
|
|
1946
|
-
throw new TypeError(`Invalid response returned from url: ${url}`);
|
|
1947
|
-
return await this.createDocument({ ...init, url });
|
|
1948
|
-
}
|
|
1949
|
-
__name(createDocumentFromUrl, "createDocumentFromUrl");
|
|
1950
|
-
async function createBuiltinTypeDocument() {
|
|
1951
|
-
const init = {
|
|
1952
|
-
version: opra_schema_ns_exports.SpecVersion,
|
|
1953
|
-
info: {
|
|
1954
|
-
version: opra_schema_ns_exports.SpecVersion,
|
|
1955
|
-
title: "Opra built-in types",
|
|
1956
|
-
contact: [
|
|
1957
|
-
{
|
|
1958
|
-
url: "https://github.com/oprajs/opra"
|
|
1959
|
-
}
|
|
1960
|
-
],
|
|
1961
|
-
license: {
|
|
1962
|
-
url: "https://github.com/oprajs/opra/blob/main/LICENSE",
|
|
1963
|
-
name: "MIT"
|
|
1964
|
-
}
|
|
1965
|
-
},
|
|
1966
|
-
types: [
|
|
1967
|
-
AnyType,
|
|
1968
|
-
Base64Type,
|
|
1969
|
-
BigintType,
|
|
1970
|
-
BooleanType,
|
|
1971
|
-
DateType,
|
|
1972
|
-
UuidType,
|
|
1973
|
-
IntegerType,
|
|
1974
|
-
NullType,
|
|
1975
|
-
NumberType,
|
|
1976
|
-
ObjectType,
|
|
1977
|
-
ObjectIdType,
|
|
1978
|
-
StringType,
|
|
1979
|
-
TimeType,
|
|
1980
|
-
TimestampType
|
|
1981
|
-
]
|
|
1982
|
-
};
|
|
1983
|
-
const factoryClass = Object.getPrototypeOf(this).constructor;
|
|
1984
|
-
const factory = new factoryClass();
|
|
1985
|
-
return await factory.createDocument(init, { noBuiltinTypes: true });
|
|
1986
|
-
}
|
|
1987
|
-
__name(createBuiltinTypeDocument, "createBuiltinTypeDocument");
|
|
1988
|
-
|
|
1989
|
-
// ../../build/common/esm/document/factory/import-resource-class.js
|
|
2191
|
+
// ../../build/common/esm/document/data-type/enum-type.js
|
|
1990
2192
|
import "reflect-metadata";
|
|
1991
|
-
|
|
1992
|
-
const { document, sourceQueue, cache } = this;
|
|
1993
|
-
const controller = await resolveThunk(thunk);
|
|
1994
|
-
const cached = cache.get(controller);
|
|
1995
|
-
if (cached)
|
|
1996
|
-
return cached;
|
|
1997
|
-
const ctor = typeof thunk === "function" ? thunk : Object.getPrototypeOf(thunk).constructor;
|
|
1998
|
-
let metadata = Reflect.getMetadata(RESOURCE_METADATA, ctor);
|
|
1999
|
-
if (!metadata && opra_schema_ns_exports.isSource(metadata))
|
|
2000
|
-
throw new TypeError(`Class "${ctor.name}" doesn't have a valid Resource metadata`);
|
|
2001
|
-
metadata = cloneObject(metadata);
|
|
2002
|
-
const schema = cloneObject(metadata);
|
|
2003
|
-
schema.controller = controller;
|
|
2004
|
-
cache.set(thunk, schema);
|
|
2005
|
-
if (opra_schema_ns_exports.isSingleton(schema) || opra_schema_ns_exports.isCollection(schema)) {
|
|
2006
|
-
if (!document.getDataType(metadata.type, true) && typeof metadata.type === "function") {
|
|
2007
|
-
await this.importTypeClass(metadata.type);
|
|
2008
|
-
await this.processTypes();
|
|
2009
|
-
const dataTypeCtor = await resolveClass(metadata.type);
|
|
2010
|
-
const dataType = document.getComplexType(dataTypeCtor);
|
|
2011
|
-
schema.type = dataType.name;
|
|
2012
|
-
}
|
|
2013
|
-
document.getComplexType(schema.type);
|
|
2014
|
-
}
|
|
2015
|
-
if (opra_schema_ns_exports.isSingleton(schema))
|
|
2016
|
-
await this.extractSingletonSchema(schema, ctor, metadata, controller);
|
|
2017
|
-
if (opra_schema_ns_exports.isCollection(schema))
|
|
2018
|
-
await this.extractCollectionSchema(schema, ctor, metadata, controller);
|
|
2019
|
-
sourceQueue.set(metadata.name, schema);
|
|
2020
|
-
}
|
|
2021
|
-
__name(importResourceClass, "importResourceClass");
|
|
2022
|
-
async function extractSingletonSchema(target, ctor, metadata, controller) {
|
|
2023
|
-
}
|
|
2024
|
-
__name(extractSingletonSchema, "extractSingletonSchema");
|
|
2025
|
-
async function extractCollectionSchema(target, ctor, metadata, controller) {
|
|
2026
|
-
}
|
|
2027
|
-
__name(extractCollectionSchema, "extractCollectionSchema");
|
|
2193
|
+
import merge7 from "putil-merge";
|
|
2028
2194
|
|
|
2029
|
-
// ../../build/common/esm/document/
|
|
2030
|
-
import
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
const ctor = thunk;
|
|
2057
|
-
if (opra_schema_ns_exports.isSimpleType(schema))
|
|
2058
|
-
await this.extractSimpleTypeSchema(schema, ctor, metadata);
|
|
2059
|
-
else if (opra_schema_ns_exports.isComplexType(schema))
|
|
2060
|
-
await this.extractComplexTypeSchema(schema, ctor, metadata);
|
|
2061
|
-
else if (opra_schema_ns_exports.isMappedType(schema))
|
|
2062
|
-
await this.extractMappedTypeSchema(schema, ctor, metadata);
|
|
2063
|
-
else if (opra_schema_ns_exports.isUnionType(schema))
|
|
2064
|
-
await this.extractUnionTypeSchema(schema, ctor, metadata);
|
|
2195
|
+
// ../../build/common/esm/document/data-type/enum-type-class.js
|
|
2196
|
+
import * as vg6 from "valgen";
|
|
2197
|
+
var EnumTypeClass = class extends DataType {
|
|
2198
|
+
static {
|
|
2199
|
+
__name(this, "EnumTypeClass");
|
|
2200
|
+
}
|
|
2201
|
+
constructor(document, init) {
|
|
2202
|
+
super(document, init);
|
|
2203
|
+
this.kind = opra_schema_ns_exports.EnumType.Kind;
|
|
2204
|
+
this.enumObject = init.enumObject;
|
|
2205
|
+
this.base = init.base;
|
|
2206
|
+
this.ownValues = { ...init.values };
|
|
2207
|
+
this.values = { ...this.base?.values, ...this.ownValues };
|
|
2208
|
+
this.decode = vg6.isEnum(Object.keys(this.values));
|
|
2209
|
+
this.encode = vg6.isEnum(Object.keys(this.values));
|
|
2210
|
+
}
|
|
2211
|
+
exportSchema() {
|
|
2212
|
+
const out = super.exportSchema();
|
|
2213
|
+
out.values = {};
|
|
2214
|
+
Object.entries(this.values).forEach(([k, i]) => {
|
|
2215
|
+
out.values[k] = omitUndefined({ key: i.key, description: i.description });
|
|
2216
|
+
});
|
|
2217
|
+
return out;
|
|
2218
|
+
}
|
|
2219
|
+
generateCodec(codec) {
|
|
2220
|
+
if (codec === "encode")
|
|
2221
|
+
return this.encode;
|
|
2065
2222
|
else
|
|
2066
|
-
|
|
2067
|
-
return result;
|
|
2223
|
+
return this.decode;
|
|
2068
2224
|
}
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2225
|
+
};
|
|
2226
|
+
|
|
2227
|
+
// ../../build/common/esm/document/data-type/enum-type.js
|
|
2228
|
+
var EnumType2 = /* @__PURE__ */ __name(function(...args) {
|
|
2229
|
+
if (!this) {
|
|
2230
|
+
const [enumSource, options] = args;
|
|
2231
|
+
let values = {};
|
|
2232
|
+
if (Array.isArray(enumSource)) {
|
|
2233
|
+
values = {};
|
|
2234
|
+
enumSource.forEach((k) => {
|
|
2235
|
+
const description = options?.meanings?.[k];
|
|
2236
|
+
values[k] = omitUndefined({ description });
|
|
2237
|
+
});
|
|
2238
|
+
} else {
|
|
2239
|
+
Object.keys(enumSource).forEach((k) => {
|
|
2240
|
+
const description = options?.meanings?.[k];
|
|
2241
|
+
values[enumSource[k]] = omitUndefined({ key: k, description });
|
|
2242
|
+
});
|
|
2074
2243
|
}
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2244
|
+
const metadata = {
|
|
2245
|
+
kind: opra_schema_ns_exports.EnumType.Kind,
|
|
2246
|
+
values,
|
|
2247
|
+
base: options?.base,
|
|
2248
|
+
name: options?.name,
|
|
2249
|
+
description: options?.description
|
|
2250
|
+
};
|
|
2251
|
+
Object.defineProperty(enumSource, DATATYPE_METADATA, {
|
|
2252
|
+
value: metadata,
|
|
2253
|
+
enumerable: false,
|
|
2254
|
+
configurable: true,
|
|
2255
|
+
writable: true
|
|
2256
|
+
});
|
|
2257
|
+
return metadata;
|
|
2078
2258
|
}
|
|
2079
|
-
|
|
2080
|
-
}
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
if (elemMeta.enum)
|
|
2108
|
-
elemSchema.type = await this.importTypeClass(elemMeta.enum);
|
|
2109
|
-
if (!elemSchema.type && elemMeta.designType) {
|
|
2110
|
-
const mappingType = this.document.getDataType(elemMeta.designType, true);
|
|
2111
|
-
if (mappingType)
|
|
2112
|
-
elemSchema.type = mappingType.name;
|
|
2113
|
-
else
|
|
2114
|
-
elemSchema.type = await this.importTypeClass(elemMeta.designType);
|
|
2115
|
-
}
|
|
2116
|
-
await this.extractFieldSchema(elemSchema, ctor, elemMeta, elemName);
|
|
2117
|
-
if (elemMeta.enum)
|
|
2118
|
-
elemSchema.type = await this.importTypeClass(elemMeta.enum);
|
|
2119
|
-
if (typeof elemSchema.type === "function")
|
|
2120
|
-
elemSchema.type = await this.importTypeClass(elemSchema.type);
|
|
2121
|
-
if (elemSchema.isArray && !elemSchema.type)
|
|
2122
|
-
throw new TypeError(`"type" must be defined explicitly for array properties`);
|
|
2123
|
-
elemSchema.type = elemSchema.type || "any";
|
|
2124
|
-
} catch (e) {
|
|
2125
|
-
e.message = `Error in class "${ctor.name}.${elemName}". ` + e.message;
|
|
2126
|
-
throw e;
|
|
2259
|
+
const [document, init] = args;
|
|
2260
|
+
merge7(this, new EnumTypeClass(document, init), { descriptor: true });
|
|
2261
|
+
return;
|
|
2262
|
+
}, "EnumType");
|
|
2263
|
+
EnumType2.prototype = EnumTypeClass.prototype;
|
|
2264
|
+
|
|
2265
|
+
// ../../build/common/esm/document/data-type/mapped-type.js
|
|
2266
|
+
import "reflect-metadata";
|
|
2267
|
+
import merge8 from "putil-merge";
|
|
2268
|
+
|
|
2269
|
+
// ../../build/common/esm/document/data-type/mapped-type-class.js
|
|
2270
|
+
var MappedTypeClass = class extends ComplexTypeClass {
|
|
2271
|
+
static {
|
|
2272
|
+
__name(this, "MappedTypeClass");
|
|
2273
|
+
}
|
|
2274
|
+
constructor(document, init) {
|
|
2275
|
+
super(document, init);
|
|
2276
|
+
this.kind = opra_schema_ns_exports.MappedType.Kind;
|
|
2277
|
+
const own = this.own;
|
|
2278
|
+
own.pick = init.pick;
|
|
2279
|
+
own.omit = init.omit;
|
|
2280
|
+
this.kind = opra_schema_ns_exports.MappedType.Kind;
|
|
2281
|
+
this.pick = own.pick;
|
|
2282
|
+
this.omit = own.omit;
|
|
2283
|
+
const isInheritedPredicate = getIsInheritedPredicateFn(init.pick, init.omit);
|
|
2284
|
+
for (const fieldName of this.fields.keys()) {
|
|
2285
|
+
if (!isInheritedPredicate(fieldName)) {
|
|
2286
|
+
this.fields.delete(fieldName);
|
|
2127
2287
|
}
|
|
2128
2288
|
}
|
|
2129
2289
|
}
|
|
2290
|
+
// @ts-ignore
|
|
2291
|
+
exportSchema() {
|
|
2292
|
+
const out = super.exportSchema();
|
|
2293
|
+
Object.assign(out, omitUndefined({
|
|
2294
|
+
pick: this.own.pick,
|
|
2295
|
+
omit: this.own.omit
|
|
2296
|
+
}));
|
|
2297
|
+
return out;
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
function getIsInheritedPredicateFn(pick, omit4) {
|
|
2301
|
+
const pickKeys = pick?.map((x) => String(x).toLowerCase());
|
|
2302
|
+
const omitKeys = omit4?.map((x) => String(x).toLowerCase());
|
|
2303
|
+
return (propertyName) => {
|
|
2304
|
+
if (omitKeys && omitKeys.includes(propertyName.toLowerCase()))
|
|
2305
|
+
return false;
|
|
2306
|
+
if (pickKeys)
|
|
2307
|
+
return pickKeys.includes(propertyName.toLowerCase());
|
|
2308
|
+
return true;
|
|
2309
|
+
};
|
|
2130
2310
|
}
|
|
2131
|
-
__name(
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
async function extractUnionTypeSchema(target, ctor, metadata) {
|
|
2137
|
-
const oldTypes = metadata.types;
|
|
2138
|
-
target.types = [];
|
|
2139
|
-
for (const type of oldTypes)
|
|
2140
|
-
target.types.push(await this.importTypeClass(type));
|
|
2141
|
-
}
|
|
2142
|
-
__name(extractUnionTypeSchema, "extractUnionTypeSchema");
|
|
2143
|
-
async function extractEnumTypeSchema(target, enumObject, metadata) {
|
|
2311
|
+
__name(getIsInheritedPredicateFn, "getIsInheritedPredicateFn");
|
|
2312
|
+
|
|
2313
|
+
// ../../build/common/esm/document/data-type/mapped-type.js
|
|
2314
|
+
function PickType(classRef, keys) {
|
|
2315
|
+
return MappedType2(classRef, { pick: keys });
|
|
2144
2316
|
}
|
|
2145
|
-
__name(
|
|
2146
|
-
|
|
2317
|
+
__name(PickType, "PickType");
|
|
2318
|
+
function OmitType(classRef, keys) {
|
|
2319
|
+
return MappedType2(classRef, { omit: keys });
|
|
2147
2320
|
}
|
|
2148
|
-
__name(
|
|
2321
|
+
__name(OmitType, "OmitType");
|
|
2322
|
+
var MappedType2 = /* @__PURE__ */ __name(function(...args) {
|
|
2323
|
+
if (this) {
|
|
2324
|
+
const [document, init] = args;
|
|
2325
|
+
merge8(this, new MappedTypeClass(document, init), { descriptor: true });
|
|
2326
|
+
return;
|
|
2327
|
+
}
|
|
2328
|
+
const [mappedSource, options] = args;
|
|
2329
|
+
const isInheritedPredicate = getIsInheritedPredicateFn(options.pick, options.omit);
|
|
2330
|
+
class MappedClass {
|
|
2331
|
+
static {
|
|
2332
|
+
__name(this, "MappedClass");
|
|
2333
|
+
}
|
|
2334
|
+
constructor() {
|
|
2335
|
+
inheritPropertyInitializers(this, mappedSource, isInheritedPredicate);
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
mergePrototype(MappedClass.prototype, mappedSource.prototype);
|
|
2339
|
+
const m = Reflect.getOwnMetadata(DATATYPE_METADATA, mappedSource);
|
|
2340
|
+
if (!m)
|
|
2341
|
+
throw new TypeError(`Class "${mappedSource}" doesn't have datatype metadata information`);
|
|
2342
|
+
if (!(m.kind === opra_schema_ns_exports.ComplexType.Kind))
|
|
2343
|
+
throw new TypeError(`Class "${mappedSource}" is not a ${opra_schema_ns_exports.ComplexType.Kind}`);
|
|
2344
|
+
const metadata = {
|
|
2345
|
+
kind: "MappedType",
|
|
2346
|
+
base: mappedSource
|
|
2347
|
+
};
|
|
2348
|
+
if (options.pick)
|
|
2349
|
+
metadata.pick = options.pick;
|
|
2350
|
+
if (options.omit)
|
|
2351
|
+
metadata.omit = options.omit;
|
|
2352
|
+
Reflect.defineMetadata(DATATYPE_METADATA, metadata, MappedClass);
|
|
2353
|
+
MappedType2._applyMixin(MappedClass, mappedSource, {
|
|
2354
|
+
...options,
|
|
2355
|
+
isInheritedPredicate
|
|
2356
|
+
});
|
|
2357
|
+
return MappedClass;
|
|
2358
|
+
}, "MappedType");
|
|
2359
|
+
MappedType2.prototype = MappedTypeClass.prototype;
|
|
2360
|
+
MappedType2._applyMixin = () => void 0;
|
|
2149
2361
|
|
|
2150
|
-
// ../../build/common/esm/document/
|
|
2362
|
+
// ../../build/common/esm/document/data-type/union-type.js
|
|
2363
|
+
import "reflect-metadata";
|
|
2151
2364
|
import merge9 from "putil-merge";
|
|
2152
2365
|
|
|
2153
|
-
// ../../build/common/esm/document/
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2366
|
+
// ../../build/common/esm/document/data-type/union-type-class.js
|
|
2367
|
+
var UnionTypeClass = class extends ComplexType2 {
|
|
2368
|
+
static {
|
|
2369
|
+
__name(this, "UnionTypeClass");
|
|
2370
|
+
}
|
|
2371
|
+
constructor(document, init) {
|
|
2372
|
+
super(document, init);
|
|
2373
|
+
this.kind = opra_schema_ns_exports.UnionType.Kind;
|
|
2374
|
+
const own = this.own;
|
|
2375
|
+
own.types = [];
|
|
2376
|
+
const UnionType3 = Object.getPrototypeOf(this).constructor;
|
|
2377
|
+
for (const base of init.types) {
|
|
2378
|
+
if (!(base instanceof ComplexType2 || base instanceof UnionType3 || base instanceof MappedType2))
|
|
2379
|
+
throw new TypeError(`${opra_schema_ns_exports.UnionType.Kind} shall contain ${opra_schema_ns_exports.ComplexType.Kind}, ${opra_schema_ns_exports.UnionType.Kind} of ${opra_schema_ns_exports.MappedType.Kind} types.`);
|
|
2380
|
+
own.types.push(base);
|
|
2381
|
+
if (base.additionalFields === true && this.additionalFields !== true) {
|
|
2382
|
+
this.additionalFields = true;
|
|
2383
|
+
} else if (base.additionalFields === "error" && !this.additionalFields) {
|
|
2384
|
+
this.additionalFields = "error";
|
|
2385
|
+
}
|
|
2386
|
+
this.fields.setAll(base.fields);
|
|
2387
|
+
}
|
|
2388
|
+
this.types = [...own.types];
|
|
2389
|
+
}
|
|
2390
|
+
// @ts-ignore
|
|
2391
|
+
exportSchema() {
|
|
2392
|
+
const out = super.exportSchema();
|
|
2393
|
+
out.types = this.own.types.map((t) => t.name ? t.name : t.exportSchema());
|
|
2394
|
+
return out;
|
|
2395
|
+
}
|
|
2396
|
+
};
|
|
2177
2397
|
|
|
2178
|
-
// ../../build/common/esm/document/
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
}
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
return (target, propertyKey) => {
|
|
2203
|
-
if (typeof propertyKey !== "string")
|
|
2204
|
-
throw new TypeError(`This decorator can't be used for Symbol keys'`);
|
|
2205
|
-
const actionMeta = { ...options };
|
|
2206
|
-
const resourceMetadata = Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {};
|
|
2207
|
-
resourceMetadata.actions = resourceMetadata.actions || {};
|
|
2208
|
-
resourceMetadata.actions[propertyKey] = actionMeta;
|
|
2209
|
-
Reflect.defineMetadata(RESOURCE_METADATA, resourceMetadata, target.constructor);
|
|
2398
|
+
// ../../build/common/esm/document/data-type/union-type.js
|
|
2399
|
+
var UnionType2 = /* @__PURE__ */ __name(function(...args) {
|
|
2400
|
+
if (this) {
|
|
2401
|
+
const [document, init] = args;
|
|
2402
|
+
merge9(this, new UnionTypeClass(document, init), { descriptor: true });
|
|
2403
|
+
return;
|
|
2404
|
+
}
|
|
2405
|
+
const clasRefs = [...args].filter((x) => !!x);
|
|
2406
|
+
if (!clasRefs.length)
|
|
2407
|
+
throw new TypeError("No Class has been provided");
|
|
2408
|
+
if (clasRefs.length === 1)
|
|
2409
|
+
return clasRefs[0];
|
|
2410
|
+
class UnionClass {
|
|
2411
|
+
static {
|
|
2412
|
+
__name(this, "UnionClass");
|
|
2413
|
+
}
|
|
2414
|
+
constructor() {
|
|
2415
|
+
for (const c of clasRefs)
|
|
2416
|
+
inheritPropertyInitializers(this, c);
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
const metadata = {
|
|
2420
|
+
kind: opra_schema_ns_exports.UnionType.Kind,
|
|
2421
|
+
types: []
|
|
2210
2422
|
};
|
|
2423
|
+
Reflect.defineMetadata(DATATYPE_METADATA, metadata, UnionClass);
|
|
2424
|
+
for (const c of clasRefs) {
|
|
2425
|
+
const itemMeta = Reflect.getMetadata(DATATYPE_METADATA, c);
|
|
2426
|
+
if (!(itemMeta && (itemMeta.kind === opra_schema_ns_exports.ComplexType.Kind || itemMeta.kind === opra_schema_ns_exports.UnionType.Kind || itemMeta.kind === opra_schema_ns_exports.MappedType.Kind)))
|
|
2427
|
+
throw new TypeError(`Class "${c.name}" is not a ${opra_schema_ns_exports.ComplexType.Kind}, ${opra_schema_ns_exports.UnionType.Kind} or ${opra_schema_ns_exports.MappedType.Kind}`);
|
|
2428
|
+
metadata.types.push(c);
|
|
2429
|
+
mergePrototype(UnionClass.prototype, c.prototype);
|
|
2430
|
+
}
|
|
2431
|
+
UnionType2._applyMixin(UnionClass, ...clasRefs);
|
|
2432
|
+
return UnionClass;
|
|
2433
|
+
}, "UnionType");
|
|
2434
|
+
UnionType2.prototype = UnionTypeClass.prototype;
|
|
2435
|
+
UnionType2._applyMixin = () => void 0;
|
|
2436
|
+
|
|
2437
|
+
// ../../build/common/esm/document/factory/type-document-factory.js
|
|
2438
|
+
var TypeDocumentFactory = class _TypeDocumentFactory {
|
|
2439
|
+
static {
|
|
2440
|
+
__name(this, "TypeDocumentFactory");
|
|
2441
|
+
}
|
|
2442
|
+
constructor() {
|
|
2443
|
+
this.typeQueue = new ResponsiveMap();
|
|
2444
|
+
this.circularRefs = /* @__PURE__ */ new Map();
|
|
2445
|
+
this.curPath = [];
|
|
2446
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
2447
|
+
}
|
|
2448
|
+
/**
|
|
2449
|
+
* Creates ApiDocument instance from given schema object
|
|
2450
|
+
*/
|
|
2451
|
+
static async createDocument(init) {
|
|
2452
|
+
const factory = new _TypeDocumentFactory();
|
|
2453
|
+
const document = factory.document = new TypeDocument();
|
|
2454
|
+
await factory.initDocument(init);
|
|
2455
|
+
return document;
|
|
2456
|
+
}
|
|
2457
|
+
/**
|
|
2458
|
+
* Downloads schema from the given URL and creates the document instance * @param url
|
|
2459
|
+
*/
|
|
2460
|
+
static async createDocumentFromUrl(url) {
|
|
2461
|
+
const factory = new _TypeDocumentFactory();
|
|
2462
|
+
const document = factory.document = new TypeDocument();
|
|
2463
|
+
await factory.initDocumentFromUrl(url);
|
|
2464
|
+
return document;
|
|
2465
|
+
}
|
|
2466
|
+
async initDocument(init) {
|
|
2467
|
+
this.document.url = init.url;
|
|
2468
|
+
if (init.info)
|
|
2469
|
+
Object.assign(this.document.info, init.info);
|
|
2470
|
+
if (!init?.noBuiltinTypes) {
|
|
2471
|
+
const builtinDocument = await this.createBuiltinTypeDocument();
|
|
2472
|
+
this.document.references.set("Opra", builtinDocument);
|
|
2473
|
+
}
|
|
2474
|
+
if (init.references)
|
|
2475
|
+
await this.addReferences(init.references);
|
|
2476
|
+
if (init.types) {
|
|
2477
|
+
this.curPath.push("Types->");
|
|
2478
|
+
if (Array.isArray(init.types)) {
|
|
2479
|
+
let i = 0;
|
|
2480
|
+
for (const thunk of init.types) {
|
|
2481
|
+
const metadata = Reflect.getMetadata(DATATYPE_METADATA, thunk) || thunk[DATATYPE_METADATA];
|
|
2482
|
+
if (!(metadata && metadata.name))
|
|
2483
|
+
throw new TypeError(`Metadata information not found at types[${i++}] "${String(thunk)}"`);
|
|
2484
|
+
this.typeQueue.set(metadata.name, thunk);
|
|
2485
|
+
}
|
|
2486
|
+
} else
|
|
2487
|
+
for (const [name, schema] of Object.entries(init.types)) {
|
|
2488
|
+
this.typeQueue.set(name, { ...schema, name });
|
|
2489
|
+
}
|
|
2490
|
+
for (const thunk of this.typeQueue.values()) {
|
|
2491
|
+
await this.importDataType(thunk);
|
|
2492
|
+
}
|
|
2493
|
+
this.document.types.sort();
|
|
2494
|
+
this.curPath.pop();
|
|
2495
|
+
}
|
|
2496
|
+
this.document.invalidate();
|
|
2497
|
+
return this.document;
|
|
2498
|
+
}
|
|
2499
|
+
async initDocumentFromUrl(url) {
|
|
2500
|
+
const resp = await fetch(url, { method: "GET" });
|
|
2501
|
+
const init = await resp.json();
|
|
2502
|
+
if (!init)
|
|
2503
|
+
throw new TypeError(`Invalid response returned from url: ${url}`);
|
|
2504
|
+
return await this.initDocument({ ...init, url });
|
|
2505
|
+
}
|
|
2506
|
+
async createBuiltinTypeDocument() {
|
|
2507
|
+
const init = {
|
|
2508
|
+
version: opra_schema_ns_exports.SpecVersion,
|
|
2509
|
+
info: {
|
|
2510
|
+
version: opra_schema_ns_exports.SpecVersion,
|
|
2511
|
+
title: "Opra built-in types",
|
|
2512
|
+
contact: [
|
|
2513
|
+
{
|
|
2514
|
+
url: "https://github.com/oprajs/opra"
|
|
2515
|
+
}
|
|
2516
|
+
],
|
|
2517
|
+
license: {
|
|
2518
|
+
url: "https://github.com/oprajs/opra/blob/main/LICENSE",
|
|
2519
|
+
name: "MIT"
|
|
2520
|
+
}
|
|
2521
|
+
},
|
|
2522
|
+
types: [
|
|
2523
|
+
AnyType,
|
|
2524
|
+
Base64Type,
|
|
2525
|
+
BigintType,
|
|
2526
|
+
BooleanType,
|
|
2527
|
+
DateType,
|
|
2528
|
+
UuidType,
|
|
2529
|
+
IntegerType,
|
|
2530
|
+
NullType,
|
|
2531
|
+
NumberType,
|
|
2532
|
+
ObjectType,
|
|
2533
|
+
ObjectIdType,
|
|
2534
|
+
StringType,
|
|
2535
|
+
TimeType,
|
|
2536
|
+
TimestampType
|
|
2537
|
+
]
|
|
2538
|
+
};
|
|
2539
|
+
const factory = new _TypeDocumentFactory();
|
|
2540
|
+
factory.document = new TypeDocument();
|
|
2541
|
+
return await factory.initDocument({ ...init, noBuiltinTypes: true });
|
|
2542
|
+
}
|
|
2543
|
+
async addReferences(references) {
|
|
2544
|
+
const { document } = this;
|
|
2545
|
+
for (const [ns, r] of Object.entries(references)) {
|
|
2546
|
+
if (typeof r === "string") {
|
|
2547
|
+
document.references.set(ns, await this.initDocumentFromUrl(r));
|
|
2548
|
+
} else if (r instanceof TypeDocument)
|
|
2549
|
+
document.references.set(ns, r);
|
|
2550
|
+
else if (typeof r === "object") {
|
|
2551
|
+
document.references.set(ns, await this.initDocument(r));
|
|
2552
|
+
} else
|
|
2553
|
+
throw new TypeError(`Invalid document reference (${ns}) in schema`);
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
async importDataType(thunk) {
|
|
2557
|
+
thunk = await resolveThunk(thunk);
|
|
2558
|
+
let name = "";
|
|
2559
|
+
let schema;
|
|
2560
|
+
let ctor;
|
|
2561
|
+
if (typeof thunk === "string") {
|
|
2562
|
+
name = thunk;
|
|
2563
|
+
schema = this.typeQueue.get(name);
|
|
2564
|
+
} else if (typeof thunk === "function") {
|
|
2565
|
+
const metadata = Reflect.getMetadata(DATATYPE_METADATA, thunk);
|
|
2566
|
+
if (!metadata) {
|
|
2567
|
+
const dataType = this.document.getDataType(thunk, true);
|
|
2568
|
+
if (dataType)
|
|
2569
|
+
return dataType;
|
|
2570
|
+
throw new TypeError(`Class "${thunk.name}" doesn't have a valid DataType metadata`);
|
|
2571
|
+
}
|
|
2572
|
+
name = metadata.name;
|
|
2573
|
+
schema = metadata;
|
|
2574
|
+
ctor = thunk;
|
|
2575
|
+
} else if (typeof thunk === "object") {
|
|
2576
|
+
if (opra_schema_ns_exports.isDataType(thunk)) {
|
|
2577
|
+
name = thunk.name;
|
|
2578
|
+
ctor = thunk.ctor || ctor;
|
|
2579
|
+
schema = thunk;
|
|
2580
|
+
} else {
|
|
2581
|
+
const metadata = thunk[DATATYPE_METADATA];
|
|
2582
|
+
if (!metadata)
|
|
2583
|
+
throw new TypeError(`No EnumType metadata found for object ${JSON.stringify(thunk).substring(0, 20)}...`);
|
|
2584
|
+
name = metadata.name;
|
|
2585
|
+
const dataType = this.document.getDataType(name, true);
|
|
2586
|
+
if (dataType)
|
|
2587
|
+
return dataType;
|
|
2588
|
+
schema = cloneObject(metadata);
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
ctor = ctor ?? (schema && isConstructor(schema.ctor) ? schema.ctor : void 0);
|
|
2592
|
+
if (name) {
|
|
2593
|
+
if (this.circularRefs.has(name.toLowerCase()))
|
|
2594
|
+
throw new TypeError("Circular reference detected");
|
|
2595
|
+
const dataType = this.document.getDataType(name, true);
|
|
2596
|
+
if (dataType)
|
|
2597
|
+
return dataType;
|
|
2598
|
+
this.curPath.push("/" + name);
|
|
2599
|
+
this.circularRefs.set(name, 1);
|
|
2600
|
+
}
|
|
2601
|
+
if (ctor) {
|
|
2602
|
+
if (this.circularRefs.has(ctor))
|
|
2603
|
+
throw new TypeError("Circular reference detected");
|
|
2604
|
+
const dataType = this.document.getDataType(ctor, true);
|
|
2605
|
+
if (dataType)
|
|
2606
|
+
return dataType;
|
|
2607
|
+
this.circularRefs.set(ctor, 1);
|
|
2608
|
+
}
|
|
2609
|
+
try {
|
|
2610
|
+
if (!opra_schema_ns_exports.isDataType(schema))
|
|
2611
|
+
throw new TypeError(`No DataType schema determined`);
|
|
2612
|
+
const instance = this.createDataTypeInstance(schema.kind, name);
|
|
2613
|
+
if (name)
|
|
2614
|
+
this.document.types.set(name, instance);
|
|
2615
|
+
const initArguments = cloneObject(schema);
|
|
2616
|
+
await this.prepareDataTypeInitArguments(initArguments, ctor);
|
|
2617
|
+
if (initArguments.kind === "ComplexType")
|
|
2618
|
+
ComplexType2.apply(instance, [this.document, initArguments]);
|
|
2619
|
+
else if (initArguments.kind === "SimpleType")
|
|
2620
|
+
SimpleType2.apply(instance, [this.document, initArguments]);
|
|
2621
|
+
else if (initArguments.kind === "EnumType")
|
|
2622
|
+
EnumType2.apply(instance, [this.document, initArguments]);
|
|
2623
|
+
else if (initArguments.kind === "MappedType")
|
|
2624
|
+
MappedType2.apply(instance, [this.document, initArguments]);
|
|
2625
|
+
else if (initArguments.kind === "UnionType")
|
|
2626
|
+
UnionType2.apply(instance, [this.document, initArguments]);
|
|
2627
|
+
else
|
|
2628
|
+
throw new TypeError(`Invalid data type schema: ${String(schema)}`);
|
|
2629
|
+
return instance;
|
|
2630
|
+
} finally {
|
|
2631
|
+
if (name) {
|
|
2632
|
+
this.curPath.pop();
|
|
2633
|
+
this.circularRefs.delete(name.toLowerCase());
|
|
2634
|
+
}
|
|
2635
|
+
if (ctor)
|
|
2636
|
+
this.circularRefs.delete(ctor);
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
async prepareDataTypeInitArguments(schema, ctor) {
|
|
2640
|
+
const initArguments = schema;
|
|
2641
|
+
if (initArguments.kind === "SimpleType" || initArguments.kind === "ComplexType" || initArguments.kind === "EnumType") {
|
|
2642
|
+
if (ctor) {
|
|
2643
|
+
const baseClass = Object.getPrototypeOf(ctor.prototype).constructor;
|
|
2644
|
+
const baseMeta = Reflect.getMetadata(DATATYPE_METADATA, baseClass);
|
|
2645
|
+
if (baseMeta) {
|
|
2646
|
+
initArguments.base = await this.importDataType(baseClass);
|
|
2647
|
+
}
|
|
2648
|
+
} else if (initArguments.base) {
|
|
2649
|
+
initArguments.base = await this.importDataType(initArguments.base);
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
if (initArguments.kind === "SimpleType" && ctor) {
|
|
2653
|
+
if (typeof ctor.prototype.decode === "function")
|
|
2654
|
+
initArguments.decoder = initArguments.name ? validator(initArguments.name, ctor.prototype.decode) : validator(ctor.prototype.decode);
|
|
2655
|
+
if (typeof ctor.prototype.encode === "function")
|
|
2656
|
+
initArguments.decoder = initArguments.name ? validator(initArguments.name, ctor.prototype.encode) : validator(ctor.prototype.encode);
|
|
2657
|
+
return;
|
|
2658
|
+
}
|
|
2659
|
+
if (initArguments.kind === "ComplexType") {
|
|
2660
|
+
initArguments.ctor = ctor;
|
|
2661
|
+
if (initArguments.fields) {
|
|
2662
|
+
const srcFields = initArguments.fields;
|
|
2663
|
+
const trgFields = initArguments.fields = {};
|
|
2664
|
+
for (const [fieldName, o] of Object.entries(srcFields)) {
|
|
2665
|
+
try {
|
|
2666
|
+
this.curPath.push("." + fieldName);
|
|
2667
|
+
const srcMeta = typeof o === "string" ? { type: o } : o;
|
|
2668
|
+
const fieldInit = trgFields[fieldName] = {
|
|
2669
|
+
...srcMeta,
|
|
2670
|
+
name: fieldName
|
|
2671
|
+
};
|
|
2672
|
+
if (srcMeta.enum) {
|
|
2673
|
+
const enumObject = srcMeta.enum;
|
|
2674
|
+
delete srcMeta.enum;
|
|
2675
|
+
if (enumObject[DATATYPE_METADATA]) {
|
|
2676
|
+
fieldInit.type = await this.importDataType(enumObject);
|
|
2677
|
+
} else {
|
|
2678
|
+
const enumMeta = EnumType2(enumObject);
|
|
2679
|
+
fieldInit.type = await this.importDataType({ ...enumMeta, kind: "EnumType", base: void 0 });
|
|
2680
|
+
}
|
|
2681
|
+
} else {
|
|
2682
|
+
if (srcMeta.isArray && !srcMeta.type)
|
|
2683
|
+
throw new TypeError(`"type" must be defined explicitly for array properties`);
|
|
2684
|
+
fieldInit.type = await this.importDataType(srcMeta.type || srcMeta.designType || "any");
|
|
2685
|
+
}
|
|
2686
|
+
this.curPath.pop();
|
|
2687
|
+
} catch (e) {
|
|
2688
|
+
e.message = `Error in resource "${initArguments.name}.${fieldName}". ` + e.message;
|
|
2689
|
+
throw e;
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
if (initArguments.kind === "MappedType") {
|
|
2695
|
+
const dataType = await this.importDataType(initArguments.base);
|
|
2696
|
+
if (!(dataType instanceof ComplexType2))
|
|
2697
|
+
throw new TypeError("MappedType.type property must address to a ComplexType");
|
|
2698
|
+
initArguments.base = dataType;
|
|
2699
|
+
}
|
|
2700
|
+
if (initArguments.kind === "UnionType") {
|
|
2701
|
+
const oldTypes = initArguments.types;
|
|
2702
|
+
initArguments.types = [];
|
|
2703
|
+
for (const type of oldTypes)
|
|
2704
|
+
initArguments.types.push(await this.importDataType(type));
|
|
2705
|
+
}
|
|
2706
|
+
return initArguments;
|
|
2707
|
+
}
|
|
2708
|
+
createDataTypeInstance(kind, name) {
|
|
2709
|
+
const dataType = {
|
|
2710
|
+
document: this.document,
|
|
2711
|
+
kind,
|
|
2712
|
+
name
|
|
2713
|
+
};
|
|
2714
|
+
switch (kind) {
|
|
2715
|
+
case opra_schema_ns_exports.ComplexType.Kind:
|
|
2716
|
+
Object.setPrototypeOf(dataType, ComplexType2.prototype);
|
|
2717
|
+
break;
|
|
2718
|
+
case opra_schema_ns_exports.EnumType.Kind:
|
|
2719
|
+
Object.setPrototypeOf(dataType, EnumType2.prototype);
|
|
2720
|
+
break;
|
|
2721
|
+
case opra_schema_ns_exports.MappedType.Kind:
|
|
2722
|
+
Object.setPrototypeOf(dataType, MappedType2.prototype);
|
|
2723
|
+
break;
|
|
2724
|
+
case opra_schema_ns_exports.SimpleType.Kind:
|
|
2725
|
+
Object.setPrototypeOf(dataType, SimpleType2.prototype);
|
|
2726
|
+
break;
|
|
2727
|
+
case opra_schema_ns_exports.UnionType.Kind:
|
|
2728
|
+
Object.setPrototypeOf(dataType, UnionType2.prototype);
|
|
2729
|
+
break;
|
|
2730
|
+
default:
|
|
2731
|
+
throw new TypeError(`Unknown DataType kind (${kind})`);
|
|
2732
|
+
}
|
|
2733
|
+
return dataType;
|
|
2734
|
+
}
|
|
2211
2735
|
};
|
|
2736
|
+
TypeDocumentFactory.designTypeMap = /* @__PURE__ */ new Map();
|
|
2212
2737
|
|
|
2213
|
-
// ../../build/common/esm/document/
|
|
2214
|
-
|
|
2215
|
-
function CollectionDecorator(type, options) {
|
|
2216
|
-
return ResourceDecorator(opra_schema_ns_exports.Collection.Kind, { ...options, type });
|
|
2217
|
-
}
|
|
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
|
-
};
|
|
2228
|
-
Object.assign(CollectionDecorator, ResourceDecorator);
|
|
2229
|
-
Object.assign(CollectionDecorator, operationDecorators);
|
|
2230
|
-
CollectionDecorator.Action = function(options) {
|
|
2231
|
-
const oldDecorator = ResourceDecorator.Action(options);
|
|
2232
|
-
return (target, propertyKey) => {
|
|
2233
|
-
if (typeof propertyKey === "string" && operationProperties.includes(propertyKey))
|
|
2234
|
-
throw new TypeError(`The "${propertyKey}" property is reserved for "${propertyKey}" operations and cannot be used as an action'`);
|
|
2235
|
-
return oldDecorator(target, propertyKey);
|
|
2236
|
-
};
|
|
2237
|
-
};
|
|
2738
|
+
// ../../build/common/esm/document/resource/collection.js
|
|
2739
|
+
import merge10 from "putil-merge";
|
|
2238
2740
|
|
|
2239
2741
|
// ../../build/common/esm/document/resource/collection-class.js
|
|
2240
|
-
import * as
|
|
2742
|
+
import * as vg7 from "valgen";
|
|
2241
2743
|
|
|
2242
2744
|
// ../../build/common/esm/filter/opra-filter.ns.js
|
|
2243
2745
|
var opra_filter_ns_exports = {};
|
|
@@ -9750,304 +10252,43 @@ var _wrapEntryValue = /* @__PURE__ */ __name((v) => {
|
|
|
9750
10252
|
return new StringLiteral("" + v);
|
|
9751
10253
|
}, "_wrapEntryValue");
|
|
9752
10254
|
|
|
9753
|
-
// ../../build/common/esm/document/
|
|
9754
|
-
|
|
9755
|
-
|
|
9756
|
-
// ../../build/common/esm/document/data-type/mapped-type.js
|
|
9757
|
-
import "reflect-metadata";
|
|
9758
|
-
import merge7 from "putil-merge";
|
|
9759
|
-
|
|
9760
|
-
// ../../build/common/esm/document/data-type/mapped-type-class.js
|
|
9761
|
-
var MappedTypeClass = class extends DataType {
|
|
9762
|
-
static {
|
|
9763
|
-
__name(this, "MappedTypeClass");
|
|
9764
|
-
}
|
|
9765
|
-
constructor(document, init) {
|
|
9766
|
-
super(document, init);
|
|
9767
|
-
this.kind = opra_schema_ns_exports.MappedType.Kind;
|
|
9768
|
-
const own = this.own;
|
|
9769
|
-
own.pick = init.pick;
|
|
9770
|
-
own.omit = init.omit;
|
|
9771
|
-
this.kind = opra_schema_ns_exports.MappedType.Kind;
|
|
9772
|
-
this.type = init.type;
|
|
9773
|
-
this.pick = own.pick;
|
|
9774
|
-
this.omit = own.omit;
|
|
9775
|
-
this.fields = new ResponsiveMap();
|
|
9776
|
-
this.additionalFields = this.type.additionalFields;
|
|
9777
|
-
const isInheritedPredicate = getIsInheritedPredicateFn(init.pick, init.omit);
|
|
9778
|
-
for (const [elemName, elem] of this.type.fields.entries()) {
|
|
9779
|
-
if (isInheritedPredicate(elemName))
|
|
9780
|
-
this.fields.set(elemName, elem);
|
|
9781
|
-
}
|
|
9782
|
-
}
|
|
9783
|
-
exportSchema() {
|
|
9784
|
-
const out = DataType.prototype.exportSchema.call(this);
|
|
9785
|
-
Object.assign(out, omitUndefined({
|
|
9786
|
-
type: this.type.name ? this.type.name : this.type.exportSchema(),
|
|
9787
|
-
pick: this.own.pick,
|
|
9788
|
-
omit: this.own.omit
|
|
9789
|
-
}));
|
|
9790
|
-
return out;
|
|
9791
|
-
}
|
|
9792
|
-
};
|
|
9793
|
-
function getIsInheritedPredicateFn(pick, omit5) {
|
|
9794
|
-
const pickKeys = pick?.map((x) => String(x).toLowerCase());
|
|
9795
|
-
const omitKeys = omit5?.map((x) => String(x).toLowerCase());
|
|
9796
|
-
return (propertyName) => {
|
|
9797
|
-
if (omitKeys && omitKeys.includes(propertyName.toLowerCase()))
|
|
9798
|
-
return false;
|
|
9799
|
-
if (pickKeys)
|
|
9800
|
-
return pickKeys.includes(propertyName.toLowerCase());
|
|
9801
|
-
return true;
|
|
9802
|
-
};
|
|
9803
|
-
}
|
|
9804
|
-
__name(getIsInheritedPredicateFn, "getIsInheritedPredicateFn");
|
|
9805
|
-
|
|
9806
|
-
// ../../build/common/esm/document/data-type/mapped-type.js
|
|
9807
|
-
function PickType(classRef, keys) {
|
|
9808
|
-
return MappedType2(classRef, { pick: keys });
|
|
9809
|
-
}
|
|
9810
|
-
__name(PickType, "PickType");
|
|
9811
|
-
function OmitType(classRef, keys) {
|
|
9812
|
-
return MappedType2(classRef, { omit: keys });
|
|
9813
|
-
}
|
|
9814
|
-
__name(OmitType, "OmitType");
|
|
9815
|
-
var MappedType2 = /* @__PURE__ */ __name(function(...args) {
|
|
9816
|
-
if (this) {
|
|
9817
|
-
const [document, init] = args;
|
|
9818
|
-
merge7(this, new MappedTypeClass(document, init), { descriptor: true });
|
|
9819
|
-
return;
|
|
9820
|
-
}
|
|
9821
|
-
const [mappedSource, options] = args;
|
|
9822
|
-
const isInheritedPredicate = getIsInheritedPredicateFn(options.pick, options.omit);
|
|
9823
|
-
class MappedClass {
|
|
9824
|
-
static {
|
|
9825
|
-
__name(this, "MappedClass");
|
|
9826
|
-
}
|
|
9827
|
-
constructor() {
|
|
9828
|
-
inheritPropertyInitializers(this, mappedSource, isInheritedPredicate);
|
|
9829
|
-
}
|
|
9830
|
-
}
|
|
9831
|
-
mergePrototype(MappedClass.prototype, mappedSource.prototype);
|
|
9832
|
-
const m = Reflect.getOwnMetadata(DATATYPE_METADATA, mappedSource);
|
|
9833
|
-
if (!m)
|
|
9834
|
-
throw new TypeError(`Class "${mappedSource}" doesn't have datatype metadata information`);
|
|
9835
|
-
if (!(m.kind === opra_schema_ns_exports.ComplexType.Kind))
|
|
9836
|
-
throw new TypeError(`Class "${mappedSource}" is not a ${opra_schema_ns_exports.ComplexType.Kind}`);
|
|
9837
|
-
const metadata = {
|
|
9838
|
-
kind: "MappedType",
|
|
9839
|
-
type: mappedSource
|
|
9840
|
-
};
|
|
9841
|
-
if (options.pick)
|
|
9842
|
-
metadata.pick = options.pick;
|
|
9843
|
-
if (options.omit)
|
|
9844
|
-
metadata.omit = options.omit;
|
|
9845
|
-
Reflect.defineMetadata(DATATYPE_METADATA, metadata, MappedClass);
|
|
9846
|
-
MappedType2._applyMixin(MappedClass, mappedSource, {
|
|
9847
|
-
...options,
|
|
9848
|
-
isInheritedPredicate
|
|
9849
|
-
});
|
|
9850
|
-
return MappedClass;
|
|
9851
|
-
}, "MappedType");
|
|
9852
|
-
MappedType2.prototype = MappedTypeClass.prototype;
|
|
9853
|
-
MappedType2._applyMixin = () => void 0;
|
|
9854
|
-
|
|
9855
|
-
// ../../build/common/esm/document/data-type/union-type.js
|
|
9856
|
-
import "reflect-metadata";
|
|
9857
|
-
import merge8 from "putil-merge";
|
|
9858
|
-
|
|
9859
|
-
// ../../build/common/esm/document/data-type/union-type-class.js
|
|
9860
|
-
var UnionTypeClass = class extends DataType {
|
|
9861
|
-
static {
|
|
9862
|
-
__name(this, "UnionTypeClass");
|
|
9863
|
-
}
|
|
9864
|
-
constructor(document, init) {
|
|
9865
|
-
super(document, init);
|
|
9866
|
-
this.kind = opra_schema_ns_exports.UnionType.Kind;
|
|
9867
|
-
this.fields = new ResponsiveMap();
|
|
9868
|
-
const own = this.own;
|
|
9869
|
-
own.types = [];
|
|
9870
|
-
const UnionType3 = Object.getPrototypeOf(this).constructor;
|
|
9871
|
-
for (const base of init.types) {
|
|
9872
|
-
if (!(base instanceof ComplexType2 || base instanceof UnionType3 || base instanceof MappedType2))
|
|
9873
|
-
throw new TypeError(`${opra_schema_ns_exports.UnionType.Kind} shall contain ${opra_schema_ns_exports.ComplexType.Kind}, ${opra_schema_ns_exports.UnionType.Kind} of ${opra_schema_ns_exports.MappedType.Kind} types.`);
|
|
9874
|
-
own.types.push(base);
|
|
9875
|
-
if (base.additionalFields)
|
|
9876
|
-
this.additionalFields = base.additionalFields;
|
|
9877
|
-
this.fields.setAll(base.fields);
|
|
9878
|
-
}
|
|
9879
|
-
this.types = [...own.types];
|
|
9880
|
-
}
|
|
9881
|
-
exportSchema() {
|
|
9882
|
-
const out = super.exportSchema();
|
|
9883
|
-
Object.assign(out, omitUndefined({
|
|
9884
|
-
types: this.own.types.map((t) => t.name ? t.name : t.exportSchema())
|
|
9885
|
-
}));
|
|
9886
|
-
return out;
|
|
9887
|
-
}
|
|
9888
|
-
};
|
|
9889
|
-
|
|
9890
|
-
// ../../build/common/esm/document/data-type/union-type.js
|
|
9891
|
-
var UnionType2 = /* @__PURE__ */ __name(function(...args) {
|
|
9892
|
-
if (this) {
|
|
9893
|
-
const [document, init] = args;
|
|
9894
|
-
merge8(this, new UnionTypeClass(document, init), { descriptor: true });
|
|
9895
|
-
return;
|
|
9896
|
-
}
|
|
9897
|
-
const clasRefs = [...args].filter((x) => !!x);
|
|
9898
|
-
if (!clasRefs.length)
|
|
9899
|
-
throw new TypeError("No Class has been provided");
|
|
9900
|
-
if (clasRefs.length === 1)
|
|
9901
|
-
return clasRefs[0];
|
|
9902
|
-
class UnionClass {
|
|
9903
|
-
static {
|
|
9904
|
-
__name(this, "UnionClass");
|
|
9905
|
-
}
|
|
9906
|
-
constructor() {
|
|
9907
|
-
for (const c of clasRefs)
|
|
9908
|
-
inheritPropertyInitializers(this, c);
|
|
9909
|
-
}
|
|
9910
|
-
}
|
|
9911
|
-
const metadata = {
|
|
9912
|
-
kind: opra_schema_ns_exports.UnionType.Kind,
|
|
9913
|
-
types: []
|
|
9914
|
-
};
|
|
9915
|
-
Reflect.defineMetadata(DATATYPE_METADATA, metadata, UnionClass);
|
|
9916
|
-
for (const c of clasRefs) {
|
|
9917
|
-
const itemMeta = Reflect.getMetadata(DATATYPE_METADATA, c);
|
|
9918
|
-
if (!(itemMeta && (itemMeta.kind === opra_schema_ns_exports.ComplexType.Kind || itemMeta.kind === opra_schema_ns_exports.UnionType.Kind || itemMeta.kind === opra_schema_ns_exports.MappedType.Kind)))
|
|
9919
|
-
throw new TypeError(`Class "${c.name}" is not a ${opra_schema_ns_exports.ComplexType.Kind}, ${opra_schema_ns_exports.UnionType.Kind} or ${opra_schema_ns_exports.MappedType.Kind}`);
|
|
9920
|
-
metadata.types.push(c);
|
|
9921
|
-
mergePrototype(UnionClass.prototype, c.prototype);
|
|
9922
|
-
}
|
|
9923
|
-
UnionType2._applyMixin(UnionClass, ...clasRefs);
|
|
9924
|
-
return UnionClass;
|
|
9925
|
-
}, "UnionType");
|
|
9926
|
-
UnionType2.prototype = UnionTypeClass.prototype;
|
|
9927
|
-
UnionType2._applyMixin = () => void 0;
|
|
9928
|
-
|
|
9929
|
-
// ../../build/common/esm/document/utils/generate-codec.js
|
|
9930
|
-
function generateCodec(type, codec, options) {
|
|
9931
|
-
return _generateCodec(type, codec, options);
|
|
9932
|
-
}
|
|
9933
|
-
__name(generateCodec, "generateCodec");
|
|
9934
|
-
function _generateCodec(type, codec, options) {
|
|
9935
|
-
const schema = {};
|
|
9936
|
-
for (const f of type.fields.values()) {
|
|
9937
|
-
let fn;
|
|
9938
|
-
if (f.type instanceof SimpleType2 || f.type instanceof EnumType2) {
|
|
9939
|
-
fn = f.type[codec];
|
|
9940
|
-
} else if (f.type instanceof ComplexType2 || f.type instanceof MappedType2 || f.type instanceof UnionType2) {
|
|
9941
|
-
fn = _generateCodec(f.type, codec, options);
|
|
9942
|
-
}
|
|
9943
|
-
if (!fn)
|
|
9944
|
-
throw new TypeError(`Can't generate codec for (${f.type})`);
|
|
9945
|
-
if (f.isArray)
|
|
9946
|
-
fn = vg3.isArray(fn);
|
|
9947
|
-
schema[f.name] = !options.partial && f.required ? vg3.required(fn) : vg3.optional(fn);
|
|
9948
|
-
}
|
|
9949
|
-
return vg3.isObject(schema, {
|
|
9950
|
-
ctor: type.ctor,
|
|
9951
|
-
additionalFields: type.additionalFields ?? false,
|
|
9952
|
-
name: type.name,
|
|
9953
|
-
caseInSensitive: true
|
|
9954
|
-
});
|
|
9955
|
-
}
|
|
9956
|
-
__name(_generateCodec, "_generateCodec");
|
|
9957
|
-
|
|
9958
|
-
// ../../build/common/esm/document/resource/endpoint.js
|
|
9959
|
-
var Endpoint = class {
|
|
10255
|
+
// ../../build/common/esm/document/resource/crud-resource.js
|
|
10256
|
+
var CrudResource = class extends Resource {
|
|
9960
10257
|
static {
|
|
9961
|
-
__name(this, "
|
|
9962
|
-
}
|
|
9963
|
-
constructor(init) {
|
|
9964
|
-
|
|
9965
|
-
this.
|
|
9966
|
-
if (init.
|
|
9967
|
-
for (const [
|
|
9968
|
-
this.
|
|
9969
|
-
}
|
|
9970
|
-
}
|
|
9971
|
-
}
|
|
9972
|
-
exportSchema() {
|
|
9973
|
-
const schema = omitUndefined({
|
|
9974
|
-
description: this.description
|
|
9975
|
-
});
|
|
9976
|
-
if (this.parameters.size) {
|
|
9977
|
-
schema.parameters = {};
|
|
9978
|
-
for (const [name, param] of this.parameters.entries()) {
|
|
9979
|
-
schema.parameters[name] = param.exportSchema();
|
|
10258
|
+
__name(this, "CrudResource");
|
|
10259
|
+
}
|
|
10260
|
+
constructor(parent, init) {
|
|
10261
|
+
super(parent, init);
|
|
10262
|
+
this.operations = new ResponsiveMap();
|
|
10263
|
+
if (init.operations) {
|
|
10264
|
+
for (const [name, meta] of Object.entries(init.operations)) {
|
|
10265
|
+
this.operations.set(name, new Endpoint(this, name, meta));
|
|
9980
10266
|
}
|
|
9981
10267
|
}
|
|
9982
|
-
return schema;
|
|
9983
|
-
}
|
|
9984
|
-
};
|
|
9985
|
-
var EndpointParameter = class {
|
|
9986
|
-
static {
|
|
9987
|
-
__name(this, "EndpointParameter");
|
|
9988
|
-
}
|
|
9989
|
-
constructor(init) {
|
|
9990
|
-
Object.assign(this, init);
|
|
9991
|
-
}
|
|
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
|
-
};
|
|
10000
|
-
|
|
10001
|
-
// ../../build/common/esm/document/resource/resource.js
|
|
10002
|
-
var Resource = class {
|
|
10003
|
-
static {
|
|
10004
|
-
__name(this, "Resource");
|
|
10005
10268
|
}
|
|
10006
|
-
|
|
10007
|
-
this.
|
|
10008
|
-
this.document = document;
|
|
10009
|
-
this.name = init.name;
|
|
10010
|
-
this.description = init.description;
|
|
10011
|
-
this.controller = init.controller;
|
|
10012
|
-
if (init.actions) {
|
|
10013
|
-
for (const [name, meta] of Object.entries(init.actions)) {
|
|
10014
|
-
this.actions.set(name, new Endpoint({ ...meta, name }));
|
|
10015
|
-
}
|
|
10016
|
-
}
|
|
10269
|
+
getOperation(name) {
|
|
10270
|
+
return this.operations.get(name);
|
|
10017
10271
|
}
|
|
10018
|
-
exportSchema() {
|
|
10019
|
-
const schema =
|
|
10020
|
-
|
|
10021
|
-
|
|
10022
|
-
|
|
10023
|
-
|
|
10024
|
-
schema.actions = {};
|
|
10025
|
-
for (const action of this.actions.values()) {
|
|
10026
|
-
schema.actions[action.name] = action.exportSchema();
|
|
10272
|
+
exportSchema(options) {
|
|
10273
|
+
const schema = super.exportSchema(options);
|
|
10274
|
+
if (this.operations.size) {
|
|
10275
|
+
schema.operations = {};
|
|
10276
|
+
for (const operation of this.operations.values()) {
|
|
10277
|
+
schema.operations[operation.name] = operation.exportSchema(options);
|
|
10027
10278
|
}
|
|
10028
10279
|
}
|
|
10029
10280
|
return schema;
|
|
10030
10281
|
}
|
|
10031
|
-
toString() {
|
|
10032
|
-
return `[${Object.getPrototypeOf(this).constructor.name} ${this.name || "#anonymous"}]`;
|
|
10033
|
-
}
|
|
10034
|
-
[nodeInspectCustom]() {
|
|
10035
|
-
return `[${colorFgYellow + Object.getPrototypeOf(this).constructor.name + colorReset} ${colorFgMagenta + this.name + colorReset}]`;
|
|
10036
|
-
}
|
|
10037
10282
|
};
|
|
10038
10283
|
|
|
10039
10284
|
// ../../build/common/esm/document/resource/collection-class.js
|
|
10040
|
-
var CollectionClass = class extends
|
|
10285
|
+
var CollectionClass = class extends CrudResource {
|
|
10041
10286
|
static {
|
|
10042
10287
|
__name(this, "CollectionClass");
|
|
10043
10288
|
}
|
|
10044
|
-
constructor(
|
|
10045
|
-
super(
|
|
10046
|
-
this._decoders = {};
|
|
10047
|
-
this._encoders = {};
|
|
10289
|
+
constructor(parent, init) {
|
|
10290
|
+
super(parent, init);
|
|
10048
10291
|
this.kind = opra_schema_ns_exports.Collection.Kind;
|
|
10049
|
-
this.controller = init.controller;
|
|
10050
|
-
this.operations = { ...init.operations };
|
|
10051
10292
|
const dataType = this.type = init.type;
|
|
10052
10293
|
this.primaryKey = init.primaryKey ? Array.isArray(init.primaryKey) ? init.primaryKey : [init.primaryKey] : [];
|
|
10053
10294
|
if (!this.primaryKey.length)
|
|
@@ -10057,15 +10298,92 @@ var CollectionClass = class extends Resource {
|
|
|
10057
10298
|
if (!(field?.type instanceof SimpleType2))
|
|
10058
10299
|
throw new TypeError(`Only Simple type allowed for primary keys but "${f}" is a ${field.type.kind}`);
|
|
10059
10300
|
});
|
|
10301
|
+
let endpoint = this.operations.get("create");
|
|
10302
|
+
if (endpoint) {
|
|
10303
|
+
endpoint.returnType = this.type;
|
|
10304
|
+
endpoint.decode = this.type.generateCodec("decode", {
|
|
10305
|
+
partial: true,
|
|
10306
|
+
pick: endpoint.inputPickFields,
|
|
10307
|
+
omit: endpoint.inputOmitFields
|
|
10308
|
+
});
|
|
10309
|
+
endpoint.encode = this.type.generateCodec("encode", {
|
|
10310
|
+
partial: true,
|
|
10311
|
+
pick: endpoint.outputPickFields,
|
|
10312
|
+
omit: endpoint.outputOmitFields
|
|
10313
|
+
});
|
|
10314
|
+
endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
|
|
10315
|
+
endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
|
|
10316
|
+
endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
|
|
10317
|
+
}
|
|
10318
|
+
endpoint = this.operations.get("deleteMany");
|
|
10319
|
+
if (endpoint) {
|
|
10320
|
+
endpoint.defineParameter("filter", { type: "string", isBuiltin: true });
|
|
10321
|
+
}
|
|
10322
|
+
endpoint = this.operations.get("get");
|
|
10323
|
+
if (endpoint) {
|
|
10324
|
+
endpoint.returnType = this.type;
|
|
10325
|
+
endpoint.encode = this.type.generateCodec("encode", {
|
|
10326
|
+
partial: true,
|
|
10327
|
+
pick: endpoint.outputPickFields,
|
|
10328
|
+
omit: endpoint.outputOmitFields
|
|
10329
|
+
});
|
|
10330
|
+
endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
|
|
10331
|
+
endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
|
|
10332
|
+
endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
|
|
10333
|
+
}
|
|
10334
|
+
endpoint = this.operations.get("findMany");
|
|
10335
|
+
if (endpoint) {
|
|
10336
|
+
endpoint.returnType = this.type;
|
|
10337
|
+
endpoint.encode = vg7.isArray(this.type.generateCodec("encode", {
|
|
10338
|
+
partial: true,
|
|
10339
|
+
pick: endpoint.outputPickFields,
|
|
10340
|
+
omit: endpoint.outputOmitFields
|
|
10341
|
+
}));
|
|
10342
|
+
endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
|
|
10343
|
+
endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
|
|
10344
|
+
endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
|
|
10345
|
+
endpoint.defineParameter("sort", { type: "string", isArray: true, isBuiltin: true });
|
|
10346
|
+
endpoint.defineParameter("filter", { type: "string", isBuiltin: true });
|
|
10347
|
+
endpoint.defineParameter("limit", { type: "integer", isBuiltin: true });
|
|
10348
|
+
endpoint.defineParameter("skip", { type: "integer", isBuiltin: true });
|
|
10349
|
+
endpoint.defineParameter("distinct", { type: "boolean", isBuiltin: true });
|
|
10350
|
+
endpoint.defineParameter("count", { type: "boolean", isBuiltin: true });
|
|
10351
|
+
}
|
|
10352
|
+
endpoint = this.operations.get("update");
|
|
10353
|
+
if (endpoint) {
|
|
10354
|
+
endpoint.returnType = this.type;
|
|
10355
|
+
endpoint.decode = this.type.generateCodec("decode", {
|
|
10356
|
+
pick: endpoint.inputPickFields,
|
|
10357
|
+
omit: endpoint.inputOmitFields
|
|
10358
|
+
});
|
|
10359
|
+
endpoint.encode = this.type.generateCodec("encode", {
|
|
10360
|
+
partial: true,
|
|
10361
|
+
pick: endpoint.outputPickFields,
|
|
10362
|
+
omit: endpoint.outputOmitFields
|
|
10363
|
+
});
|
|
10364
|
+
endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
|
|
10365
|
+
endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
|
|
10366
|
+
endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
|
|
10367
|
+
}
|
|
10368
|
+
endpoint = this.operations.get("updateMany");
|
|
10369
|
+
if (endpoint) {
|
|
10370
|
+
endpoint.decode = this.type.generateCodec("decode", {
|
|
10371
|
+
pick: endpoint.inputPickFields,
|
|
10372
|
+
omit: endpoint.inputOmitFields
|
|
10373
|
+
});
|
|
10374
|
+
endpoint.defineParameter("filter", { type: "string", isBuiltin: true });
|
|
10375
|
+
}
|
|
10060
10376
|
}
|
|
10061
|
-
|
|
10377
|
+
getOperation(name) {
|
|
10378
|
+
return super.getOperation(name);
|
|
10379
|
+
}
|
|
10380
|
+
exportSchema(options) {
|
|
10062
10381
|
return {
|
|
10063
|
-
...super.exportSchema(),
|
|
10064
|
-
|
|
10065
|
-
|
|
10066
|
-
operations: this.operations,
|
|
10382
|
+
...super.exportSchema(options),
|
|
10383
|
+
type: this.type.name || "object",
|
|
10384
|
+
...{
|
|
10067
10385
|
primaryKey: this.primaryKey
|
|
10068
|
-
}
|
|
10386
|
+
}
|
|
10069
10387
|
};
|
|
10070
10388
|
}
|
|
10071
10389
|
parseKeyValue(value) {
|
|
@@ -10104,7 +10422,7 @@ var CollectionClass = class extends Resource {
|
|
|
10104
10422
|
const normalized = this.type.normalizeFieldPath(fields);
|
|
10105
10423
|
if (!normalized)
|
|
10106
10424
|
return;
|
|
10107
|
-
const findManyOp = this.
|
|
10425
|
+
const findManyOp = this.getOperation("findMany");
|
|
10108
10426
|
const sortFields = findManyOp && findManyOp.sortFields;
|
|
10109
10427
|
(Array.isArray(normalized) ? normalized : [normalized]).forEach((field) => {
|
|
10110
10428
|
if (!sortFields?.find((x) => x === field))
|
|
@@ -10122,7 +10440,7 @@ var CollectionClass = class extends Resource {
|
|
|
10122
10440
|
this.normalizeFilter(ast.left);
|
|
10123
10441
|
if (!(ast.left instanceof opra_filter_ns_exports.QualifiedIdentifier && ast.left.field))
|
|
10124
10442
|
throw new TypeError(`Invalid filter query. Left side should be a data field.`);
|
|
10125
|
-
const findManyOp = this.
|
|
10443
|
+
const findManyOp = this.getOperation("findMany");
|
|
10126
10444
|
const fieldLower = ast.left.value.toLowerCase();
|
|
10127
10445
|
const filterDef = (findManyOp && findManyOp.filters || []).find((f) => f.field.toLowerCase() === fieldLower);
|
|
10128
10446
|
if (!filterDef) {
|
|
@@ -10162,33 +10480,204 @@ var CollectionClass = class extends Resource {
|
|
|
10162
10480
|
}
|
|
10163
10481
|
return ast;
|
|
10164
10482
|
}
|
|
10165
|
-
|
|
10166
|
-
|
|
10167
|
-
|
|
10168
|
-
|
|
10169
|
-
|
|
10170
|
-
|
|
10483
|
+
};
|
|
10484
|
+
|
|
10485
|
+
// ../../build/common/esm/document/resource/operation-decorator.js
|
|
10486
|
+
function createOperationDecorator(operation, options, list) {
|
|
10487
|
+
const decorator = /* @__PURE__ */ __name((target, propertyKey) => {
|
|
10488
|
+
if (propertyKey !== operation)
|
|
10489
|
+
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
10490
|
+
const resourceMetadata = Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {};
|
|
10491
|
+
resourceMetadata.operations = resourceMetadata.operations || {};
|
|
10492
|
+
const operationMeta = { ...options };
|
|
10493
|
+
resourceMetadata.operations[operation] = operationMeta;
|
|
10494
|
+
for (const fn of list)
|
|
10495
|
+
fn(operationMeta, target, propertyKey);
|
|
10496
|
+
Reflect.defineMetadata(RESOURCE_METADATA, resourceMetadata, target.constructor);
|
|
10497
|
+
}, "decorator");
|
|
10498
|
+
decorator.Parameter = (name, arg0) => {
|
|
10499
|
+
const parameterOptions = typeof arg0 === "string" || typeof arg0 === "function" ? { type: arg0 } : { ...arg0 };
|
|
10500
|
+
list.push((operationMeta) => {
|
|
10501
|
+
operationMeta.parameters = operationMeta.parameters || {};
|
|
10502
|
+
operationMeta.parameters[name] = { ...parameterOptions };
|
|
10503
|
+
});
|
|
10504
|
+
return decorator;
|
|
10505
|
+
};
|
|
10506
|
+
return decorator;
|
|
10507
|
+
}
|
|
10508
|
+
__name(createOperationDecorator, "createOperationDecorator");
|
|
10509
|
+
|
|
10510
|
+
// ../../build/common/esm/document/resource/collection-decorator.js
|
|
10511
|
+
var operationProperties = ["create", "delete", "deleteMany", "get", "findMany", "update", "updateMany"];
|
|
10512
|
+
function CollectionDecorator(type, options) {
|
|
10513
|
+
return ResourceDecorator(opra_schema_ns_exports.Collection.Kind, { ...options, type });
|
|
10514
|
+
}
|
|
10515
|
+
__name(CollectionDecorator, "CollectionDecorator");
|
|
10516
|
+
Object.assign(CollectionDecorator, ResourceDecorator);
|
|
10517
|
+
(function(CollectionDecorator2) {
|
|
10518
|
+
function Action(options) {
|
|
10519
|
+
const list = [];
|
|
10520
|
+
return createActionDecorator(options, operationProperties, list);
|
|
10521
|
+
}
|
|
10522
|
+
__name(Action, "Action");
|
|
10523
|
+
CollectionDecorator2.Action = Action;
|
|
10524
|
+
function Create(options) {
|
|
10525
|
+
const list = [];
|
|
10526
|
+
const decorator = createOperationDecorator("create", options, list);
|
|
10527
|
+
decorator.InputMaxContentSize = (sizeInBytes) => {
|
|
10528
|
+
list.push((operationMeta) => operationMeta.inputMaxContentSize = sizeInBytes);
|
|
10529
|
+
return decorator;
|
|
10530
|
+
};
|
|
10531
|
+
decorator.InputPickFields = (...fields) => {
|
|
10532
|
+
list.push((operationMeta) => operationMeta.inputPickFields = fields);
|
|
10533
|
+
return decorator;
|
|
10534
|
+
};
|
|
10535
|
+
decorator.InputOmitFields = (...fields) => {
|
|
10536
|
+
list.push((operationMeta) => operationMeta.inputOmitFields = fields);
|
|
10537
|
+
return decorator;
|
|
10171
10538
|
};
|
|
10172
|
-
|
|
10173
|
-
|
|
10174
|
-
|
|
10175
|
-
|
|
10176
|
-
|
|
10177
|
-
|
|
10178
|
-
|
|
10179
|
-
let encoder = this._encoders[endpoint];
|
|
10180
|
-
if (encoder)
|
|
10181
|
-
return encoder;
|
|
10182
|
-
const options = {
|
|
10183
|
-
partial: true
|
|
10539
|
+
decorator.OutputPickFields = (...fields) => {
|
|
10540
|
+
list.push((operationMeta) => operationMeta.outputPickFields = fields);
|
|
10541
|
+
return decorator;
|
|
10542
|
+
};
|
|
10543
|
+
decorator.OutputOmitFields = (...fields) => {
|
|
10544
|
+
list.push((operationMeta) => operationMeta.outputOmitFields = fields);
|
|
10545
|
+
return decorator;
|
|
10184
10546
|
};
|
|
10185
|
-
|
|
10186
|
-
if (endpoint === "findMany")
|
|
10187
|
-
return vg4.isArray(encoder);
|
|
10188
|
-
this._encoders[endpoint] = encoder;
|
|
10189
|
-
return encoder;
|
|
10547
|
+
return decorator;
|
|
10190
10548
|
}
|
|
10191
|
-
|
|
10549
|
+
__name(Create, "Create");
|
|
10550
|
+
CollectionDecorator2.Create = Create;
|
|
10551
|
+
function Delete(options) {
|
|
10552
|
+
const list = [];
|
|
10553
|
+
return createOperationDecorator("delete", options, list);
|
|
10554
|
+
}
|
|
10555
|
+
__name(Delete, "Delete");
|
|
10556
|
+
CollectionDecorator2.Delete = Delete;
|
|
10557
|
+
function DeleteMany(options) {
|
|
10558
|
+
const list = [];
|
|
10559
|
+
const decorator = createOperationDecorator("deleteMany", options, list);
|
|
10560
|
+
decorator.Filter = (field, operators, notes) => {
|
|
10561
|
+
if (typeof operators === "string")
|
|
10562
|
+
operators = operators.split(/\s*[,| ]\s*/);
|
|
10563
|
+
list.push((operationMeta) => {
|
|
10564
|
+
operationMeta.filters = operationMeta.filters || [];
|
|
10565
|
+
operationMeta.filters.push(omitUndefined({ field, operators, notes }));
|
|
10566
|
+
});
|
|
10567
|
+
return decorator;
|
|
10568
|
+
};
|
|
10569
|
+
return decorator;
|
|
10570
|
+
}
|
|
10571
|
+
__name(DeleteMany, "DeleteMany");
|
|
10572
|
+
CollectionDecorator2.DeleteMany = DeleteMany;
|
|
10573
|
+
function Get(options) {
|
|
10574
|
+
const list = [];
|
|
10575
|
+
const decorator = createOperationDecorator("get", options, list);
|
|
10576
|
+
decorator.OutputPickFields = (...fields) => {
|
|
10577
|
+
list.push((operationMeta) => operationMeta.outputPickFields = fields);
|
|
10578
|
+
return decorator;
|
|
10579
|
+
};
|
|
10580
|
+
decorator.OutputOmitFields = (...fields) => {
|
|
10581
|
+
list.push((operationMeta) => operationMeta.outputOmitFields = fields);
|
|
10582
|
+
return decorator;
|
|
10583
|
+
};
|
|
10584
|
+
return decorator;
|
|
10585
|
+
}
|
|
10586
|
+
__name(Get, "Get");
|
|
10587
|
+
CollectionDecorator2.Get = Get;
|
|
10588
|
+
function FindMany(options) {
|
|
10589
|
+
const list = [];
|
|
10590
|
+
const decorator = createOperationDecorator("findMany", options, list);
|
|
10591
|
+
decorator.SortFields = (...fields) => {
|
|
10592
|
+
list.push((operationMeta) => operationMeta.sortFields = fields);
|
|
10593
|
+
return decorator;
|
|
10594
|
+
};
|
|
10595
|
+
decorator.DefaultSort = (...fields) => {
|
|
10596
|
+
list.push((operationMeta) => operationMeta.defaultSort = fields);
|
|
10597
|
+
return decorator;
|
|
10598
|
+
};
|
|
10599
|
+
decorator.Filter = (field, operators, notes) => {
|
|
10600
|
+
if (typeof operators === "string")
|
|
10601
|
+
operators = operators.split(/\s*[,| ]\s*/);
|
|
10602
|
+
list.push((operationMeta) => {
|
|
10603
|
+
operationMeta.filters = operationMeta.filters || [];
|
|
10604
|
+
operationMeta.filters.push(omitUndefined({ field, operators, notes }));
|
|
10605
|
+
});
|
|
10606
|
+
return decorator;
|
|
10607
|
+
};
|
|
10608
|
+
decorator.OutputPickFields = (...fields) => {
|
|
10609
|
+
list.push((operationMeta) => operationMeta.outputPickFields = fields);
|
|
10610
|
+
return decorator;
|
|
10611
|
+
};
|
|
10612
|
+
decorator.OutputOmitFields = (...fields) => {
|
|
10613
|
+
list.push((operationMeta) => operationMeta.outputOmitFields = fields);
|
|
10614
|
+
return decorator;
|
|
10615
|
+
};
|
|
10616
|
+
return decorator;
|
|
10617
|
+
}
|
|
10618
|
+
__name(FindMany, "FindMany");
|
|
10619
|
+
CollectionDecorator2.FindMany = FindMany;
|
|
10620
|
+
})(CollectionDecorator || (CollectionDecorator = {}));
|
|
10621
|
+
(function(CollectionDecorator2) {
|
|
10622
|
+
function Update(options) {
|
|
10623
|
+
const list = [];
|
|
10624
|
+
const decorator = createOperationDecorator("update", options, list);
|
|
10625
|
+
decorator.InputMaxContentSize = (sizeInBytes) => {
|
|
10626
|
+
list.push((operationMeta) => operationMeta.inputMaxContentSize = sizeInBytes);
|
|
10627
|
+
return decorator;
|
|
10628
|
+
};
|
|
10629
|
+
decorator.InputPickFields = (...fields) => {
|
|
10630
|
+
list.push((operationMeta) => operationMeta.inputPickFields = fields);
|
|
10631
|
+
return decorator;
|
|
10632
|
+
};
|
|
10633
|
+
decorator.InputOmitFields = (...fields) => {
|
|
10634
|
+
list.push((operationMeta) => operationMeta.inputOmitFields = fields);
|
|
10635
|
+
return decorator;
|
|
10636
|
+
};
|
|
10637
|
+
decorator.OutputPickFields = (...fields) => {
|
|
10638
|
+
list.push((operationMeta) => operationMeta.outputPickFields = fields);
|
|
10639
|
+
return decorator;
|
|
10640
|
+
};
|
|
10641
|
+
decorator.OutputOmitFields = (...fields) => {
|
|
10642
|
+
list.push((operationMeta) => operationMeta.outputOmitFields = fields);
|
|
10643
|
+
return decorator;
|
|
10644
|
+
};
|
|
10645
|
+
return decorator;
|
|
10646
|
+
}
|
|
10647
|
+
__name(Update, "Update");
|
|
10648
|
+
CollectionDecorator2.Update = Update;
|
|
10649
|
+
})(CollectionDecorator || (CollectionDecorator = {}));
|
|
10650
|
+
(function(CollectionDecorator2) {
|
|
10651
|
+
function UpdateMany(arg0) {
|
|
10652
|
+
const list = [];
|
|
10653
|
+
const options = typeof arg0 === "string" ? { description: arg0 } : { ...arg0 };
|
|
10654
|
+
const decorator = createOperationDecorator("updateMany", options, list);
|
|
10655
|
+
decorator.InputMaxContentSize = (sizeInBytes) => {
|
|
10656
|
+
list.push((operationMeta) => operationMeta.inputMaxContentSize = sizeInBytes);
|
|
10657
|
+
return decorator;
|
|
10658
|
+
};
|
|
10659
|
+
decorator.InputPickFields = (...fields) => {
|
|
10660
|
+
list.push((operationMeta) => operationMeta.inputPickFields = fields);
|
|
10661
|
+
return decorator;
|
|
10662
|
+
};
|
|
10663
|
+
decorator.InputOmitFields = (...fields) => {
|
|
10664
|
+
list.push((operationMeta) => operationMeta.inputOmitFields = fields);
|
|
10665
|
+
return decorator;
|
|
10666
|
+
};
|
|
10667
|
+
decorator.Filter = (field, operators, notes) => {
|
|
10668
|
+
if (typeof operators === "string")
|
|
10669
|
+
operators = operators.split(/\s*[,| ]\s*/);
|
|
10670
|
+
list.push((operationMeta) => {
|
|
10671
|
+
operationMeta.filters = operationMeta.filters || [];
|
|
10672
|
+
operationMeta.filters.push(omitUndefined({ field, operators, notes }));
|
|
10673
|
+
});
|
|
10674
|
+
return decorator;
|
|
10675
|
+
};
|
|
10676
|
+
return decorator;
|
|
10677
|
+
}
|
|
10678
|
+
__name(UpdateMany, "UpdateMany");
|
|
10679
|
+
CollectionDecorator2.UpdateMany = UpdateMany;
|
|
10680
|
+
})(CollectionDecorator || (CollectionDecorator = {}));
|
|
10192
10681
|
|
|
10193
10682
|
// ../../build/common/esm/document/resource/collection.js
|
|
10194
10683
|
var Collection2 = /* @__PURE__ */ __name(function(...args) {
|
|
@@ -10196,447 +10685,439 @@ var Collection2 = /* @__PURE__ */ __name(function(...args) {
|
|
|
10196
10685
|
const [type, options] = args;
|
|
10197
10686
|
return Collection2[DECORATOR].call(void 0, type, options);
|
|
10198
10687
|
}
|
|
10199
|
-
const [
|
|
10200
|
-
|
|
10688
|
+
const [parent, init] = args;
|
|
10689
|
+
merge10(this, new CollectionClass(parent, init), { descriptor: true });
|
|
10201
10690
|
}, "Collection");
|
|
10202
10691
|
Collection2.prototype = CollectionClass.prototype;
|
|
10203
10692
|
Object.assign(Collection2, CollectionDecorator);
|
|
10204
10693
|
Collection2[DECORATOR] = CollectionDecorator;
|
|
10205
10694
|
|
|
10206
10695
|
// ../../build/common/esm/document/resource/singleton.js
|
|
10207
|
-
import
|
|
10208
|
-
|
|
10209
|
-
// ../../build/common/esm/document/decorators/singleton.decorator.js
|
|
10210
|
-
function SingletonDecorator(type, options) {
|
|
10211
|
-
return ResourceDecorator(opra_schema_ns_exports.Singleton.Kind, { ...options, type });
|
|
10212
|
-
}
|
|
10213
|
-
__name(SingletonDecorator, "SingletonDecorator");
|
|
10214
|
-
Object.assign(SingletonDecorator, ResourceDecorator);
|
|
10215
|
-
SingletonDecorator.Create = buildOperationDecorator("create");
|
|
10216
|
-
SingletonDecorator.Get = buildOperationDecorator("get");
|
|
10217
|
-
SingletonDecorator.Delete = buildOperationDecorator("delete");
|
|
10218
|
-
SingletonDecorator.Update = buildOperationDecorator("update");
|
|
10219
|
-
SingletonDecorator.Action = function(options) {
|
|
10220
|
-
const oldDecorator = ResourceDecorator.Action(options);
|
|
10221
|
-
const operators = ["create", "delete", "get", "update"];
|
|
10222
|
-
return (target, propertyKey) => {
|
|
10223
|
-
if (typeof propertyKey === "string" && operators.includes(propertyKey))
|
|
10224
|
-
throw new TypeError(`The "${propertyKey}" property is reserved for "${propertyKey}" operations and cannot be used as an action'`);
|
|
10225
|
-
return oldDecorator(target, propertyKey);
|
|
10226
|
-
};
|
|
10227
|
-
};
|
|
10696
|
+
import merge11 from "putil-merge";
|
|
10228
10697
|
|
|
10229
10698
|
// ../../build/common/esm/document/resource/singleton-class.js
|
|
10230
|
-
var SingletonClass = class extends
|
|
10699
|
+
var SingletonClass = class extends CrudResource {
|
|
10231
10700
|
static {
|
|
10232
10701
|
__name(this, "SingletonClass");
|
|
10233
10702
|
}
|
|
10234
|
-
constructor(
|
|
10235
|
-
super(
|
|
10236
|
-
this._decoders = {};
|
|
10237
|
-
this._encoders = {};
|
|
10703
|
+
constructor(parent, init) {
|
|
10704
|
+
super(parent, init);
|
|
10238
10705
|
this.kind = opra_schema_ns_exports.Singleton.Kind;
|
|
10239
|
-
this.controller = init.controller;
|
|
10240
|
-
this.operations = { ...init.operations };
|
|
10241
10706
|
this.type = init.type;
|
|
10707
|
+
let endpoint = this.operations.get("create");
|
|
10708
|
+
if (endpoint) {
|
|
10709
|
+
endpoint.returnType = this.type;
|
|
10710
|
+
endpoint.decode = this.type.generateCodec("decode", {
|
|
10711
|
+
partial: true,
|
|
10712
|
+
pick: endpoint.inputPickFields,
|
|
10713
|
+
omit: endpoint.inputOmitFields
|
|
10714
|
+
});
|
|
10715
|
+
endpoint.encode = this.type.generateCodec("encode", {
|
|
10716
|
+
partial: true,
|
|
10717
|
+
pick: endpoint.outputPickFields,
|
|
10718
|
+
omit: endpoint.outputOmitFields
|
|
10719
|
+
});
|
|
10720
|
+
endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
|
|
10721
|
+
endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
|
|
10722
|
+
endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
|
|
10723
|
+
}
|
|
10724
|
+
endpoint = this.operations.get("get");
|
|
10725
|
+
if (endpoint) {
|
|
10726
|
+
endpoint.returnType = this.type;
|
|
10727
|
+
endpoint.encode = this.type.generateCodec("encode", {
|
|
10728
|
+
partial: true,
|
|
10729
|
+
pick: endpoint.outputPickFields,
|
|
10730
|
+
omit: endpoint.outputOmitFields
|
|
10731
|
+
});
|
|
10732
|
+
endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
|
|
10733
|
+
endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
|
|
10734
|
+
endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
|
|
10735
|
+
}
|
|
10736
|
+
endpoint = this.operations.get("update");
|
|
10737
|
+
if (endpoint) {
|
|
10738
|
+
endpoint.returnType = this.type;
|
|
10739
|
+
endpoint.decode = this.type.generateCodec("decode", {
|
|
10740
|
+
pick: endpoint.inputPickFields,
|
|
10741
|
+
omit: endpoint.inputOmitFields
|
|
10742
|
+
});
|
|
10743
|
+
endpoint.encode = this.type.generateCodec("encode", {
|
|
10744
|
+
partial: true,
|
|
10745
|
+
pick: endpoint.outputPickFields,
|
|
10746
|
+
omit: endpoint.outputOmitFields
|
|
10747
|
+
});
|
|
10748
|
+
endpoint.defineParameter("pick", { type: "string", isArray: true, isBuiltin: true });
|
|
10749
|
+
endpoint.defineParameter("omit", { type: "string", isArray: true, isBuiltin: true });
|
|
10750
|
+
endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
|
|
10751
|
+
}
|
|
10242
10752
|
}
|
|
10243
|
-
|
|
10753
|
+
getOperation(name) {
|
|
10754
|
+
return super.getOperation(name);
|
|
10755
|
+
}
|
|
10756
|
+
exportSchema(options) {
|
|
10244
10757
|
return {
|
|
10245
|
-
...super.exportSchema(),
|
|
10246
|
-
|
|
10247
|
-
type: this.type.name || "any",
|
|
10248
|
-
operations: this.operations
|
|
10249
|
-
})
|
|
10758
|
+
...super.exportSchema(options),
|
|
10759
|
+
type: this.type.name || "any"
|
|
10250
10760
|
};
|
|
10251
10761
|
}
|
|
10252
10762
|
normalizeFieldPath(path2) {
|
|
10253
10763
|
return this.type.normalizeFieldPath(path2);
|
|
10254
10764
|
}
|
|
10255
|
-
getDecoder(endpoint) {
|
|
10256
|
-
let decoder = this._decoders[endpoint];
|
|
10257
|
-
if (decoder)
|
|
10258
|
-
return decoder;
|
|
10259
|
-
const options = {
|
|
10260
|
-
partial: endpoint !== "create"
|
|
10261
|
-
};
|
|
10262
|
-
decoder = generateCodec(this.type, "decode", options);
|
|
10263
|
-
this._decoders[endpoint] = decoder;
|
|
10264
|
-
return decoder;
|
|
10265
|
-
}
|
|
10266
|
-
getEncoder(endpoint) {
|
|
10267
|
-
let encoder = this._encoders[endpoint];
|
|
10268
|
-
if (encoder)
|
|
10269
|
-
return encoder;
|
|
10270
|
-
const options = {
|
|
10271
|
-
partial: true
|
|
10272
|
-
};
|
|
10273
|
-
encoder = generateCodec(this.type, "encode", options);
|
|
10274
|
-
this._encoders[endpoint] = encoder;
|
|
10275
|
-
return encoder;
|
|
10276
|
-
}
|
|
10277
10765
|
};
|
|
10278
10766
|
|
|
10767
|
+
// ../../build/common/esm/document/resource/singleton-decorator.js
|
|
10768
|
+
var operationProperties2 = ["create", "delete", "get", "update"];
|
|
10769
|
+
function SingletonDecorator(type, options) {
|
|
10770
|
+
return ResourceDecorator(opra_schema_ns_exports.Singleton.Kind, { ...options, type });
|
|
10771
|
+
}
|
|
10772
|
+
__name(SingletonDecorator, "SingletonDecorator");
|
|
10773
|
+
Object.assign(SingletonDecorator, ResourceDecorator);
|
|
10774
|
+
(function(SingletonDecorator2) {
|
|
10775
|
+
function Action(options) {
|
|
10776
|
+
const list = [];
|
|
10777
|
+
return createActionDecorator(options, operationProperties2, list);
|
|
10778
|
+
}
|
|
10779
|
+
__name(Action, "Action");
|
|
10780
|
+
SingletonDecorator2.Action = Action;
|
|
10781
|
+
function Create(options) {
|
|
10782
|
+
return CollectionDecorator.Create(options);
|
|
10783
|
+
}
|
|
10784
|
+
__name(Create, "Create");
|
|
10785
|
+
SingletonDecorator2.Create = Create;
|
|
10786
|
+
})(SingletonDecorator || (SingletonDecorator = {}));
|
|
10787
|
+
(function(SingletonDecorator2) {
|
|
10788
|
+
function Get(options) {
|
|
10789
|
+
return CollectionDecorator.Get(options);
|
|
10790
|
+
}
|
|
10791
|
+
__name(Get, "Get");
|
|
10792
|
+
SingletonDecorator2.Get = Get;
|
|
10793
|
+
})(SingletonDecorator || (SingletonDecorator = {}));
|
|
10794
|
+
(function(SingletonDecorator2) {
|
|
10795
|
+
function Delete(options) {
|
|
10796
|
+
return CollectionDecorator.Delete(options);
|
|
10797
|
+
}
|
|
10798
|
+
__name(Delete, "Delete");
|
|
10799
|
+
SingletonDecorator2.Delete = Delete;
|
|
10800
|
+
})(SingletonDecorator || (SingletonDecorator = {}));
|
|
10801
|
+
(function(SingletonDecorator2) {
|
|
10802
|
+
function Update(options) {
|
|
10803
|
+
return CollectionDecorator.Update(options);
|
|
10804
|
+
}
|
|
10805
|
+
__name(Update, "Update");
|
|
10806
|
+
SingletonDecorator2.Update = Update;
|
|
10807
|
+
})(SingletonDecorator || (SingletonDecorator = {}));
|
|
10808
|
+
|
|
10279
10809
|
// ../../build/common/esm/document/resource/singleton.js
|
|
10280
10810
|
var Singleton2 = /* @__PURE__ */ __name(function(...args) {
|
|
10281
10811
|
if (!this) {
|
|
10282
10812
|
const [type, options] = args;
|
|
10283
10813
|
return Singleton2[DECORATOR].call(void 0, type, options);
|
|
10284
10814
|
}
|
|
10285
|
-
const [
|
|
10286
|
-
|
|
10815
|
+
const [parent, init] = args;
|
|
10816
|
+
merge11(this, new SingletonClass(parent, init), { descriptor: true });
|
|
10287
10817
|
}, "Singleton");
|
|
10288
10818
|
Singleton2.prototype = SingletonClass.prototype;
|
|
10289
10819
|
Object.assign(Singleton2, SingletonDecorator);
|
|
10290
10820
|
Singleton2[DECORATOR] = SingletonDecorator;
|
|
10291
10821
|
|
|
10292
10822
|
// ../../build/common/esm/document/resource/storage.js
|
|
10293
|
-
import
|
|
10294
|
-
|
|
10295
|
-
// ../../build/common/esm/document/decorators/storage.decorator.js
|
|
10296
|
-
function StorageDecorator(options) {
|
|
10297
|
-
return ResourceDecorator(opra_schema_ns_exports.Storage.Kind, options);
|
|
10298
|
-
}
|
|
10299
|
-
__name(StorageDecorator, "StorageDecorator");
|
|
10300
|
-
var operationDecorators2 = {
|
|
10301
|
-
Delete: buildOperationDecorator("delete"),
|
|
10302
|
-
Get: buildOperationDecorator("get"),
|
|
10303
|
-
Post: buildOperationDecorator("post")
|
|
10304
|
-
};
|
|
10305
|
-
Object.assign(StorageDecorator, ResourceDecorator);
|
|
10306
|
-
Object.assign(StorageDecorator, operationDecorators2);
|
|
10307
|
-
StorageDecorator.Action = function(options) {
|
|
10308
|
-
const oldDecorator = ResourceDecorator.Action(options);
|
|
10309
|
-
const operators = ["delete", "get", "post"];
|
|
10310
|
-
return (target, propertyKey) => {
|
|
10311
|
-
if (typeof propertyKey === "string" && operators.includes(propertyKey))
|
|
10312
|
-
throw new TypeError(`The "${propertyKey}" property is reserved for "${propertyKey}" operations and cannot be used as an action'`);
|
|
10313
|
-
return oldDecorator(target, propertyKey);
|
|
10314
|
-
};
|
|
10315
|
-
};
|
|
10823
|
+
import merge12 from "putil-merge";
|
|
10316
10824
|
|
|
10317
10825
|
// ../../build/common/esm/document/resource/storage-class.js
|
|
10318
|
-
var StorageClass = class extends
|
|
10826
|
+
var StorageClass = class extends CrudResource {
|
|
10319
10827
|
static {
|
|
10320
10828
|
__name(this, "StorageClass");
|
|
10321
10829
|
}
|
|
10322
|
-
constructor(
|
|
10323
|
-
super(
|
|
10830
|
+
constructor(parent, init) {
|
|
10831
|
+
super(parent, init);
|
|
10324
10832
|
this.kind = opra_schema_ns_exports.Storage.Kind;
|
|
10325
|
-
this.controller = init.controller;
|
|
10326
|
-
this.operations = { ...init.operations };
|
|
10327
10833
|
}
|
|
10328
|
-
|
|
10329
|
-
return
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
|
|
10333
|
-
operations: this.operations
|
|
10334
|
-
})
|
|
10335
|
-
};
|
|
10834
|
+
getOperation(name) {
|
|
10835
|
+
return super.getOperation(name);
|
|
10836
|
+
}
|
|
10837
|
+
exportSchema(options) {
|
|
10838
|
+
return super.exportSchema(options);
|
|
10336
10839
|
}
|
|
10337
10840
|
};
|
|
10338
10841
|
|
|
10842
|
+
// ../../build/common/esm/document/resource/storage-decorator.js
|
|
10843
|
+
var operationProperties3 = ["delete", "get", "post"];
|
|
10844
|
+
function StorageDecorator(options) {
|
|
10845
|
+
return ResourceDecorator(opra_schema_ns_exports.Storage.Kind, options);
|
|
10846
|
+
}
|
|
10847
|
+
__name(StorageDecorator, "StorageDecorator");
|
|
10848
|
+
Object.assign(StorageDecorator, ResourceDecorator);
|
|
10849
|
+
(function(StorageDecorator2) {
|
|
10850
|
+
function Action(options) {
|
|
10851
|
+
const list = [];
|
|
10852
|
+
return createActionDecorator(options, operationProperties3, list);
|
|
10853
|
+
}
|
|
10854
|
+
__name(Action, "Action");
|
|
10855
|
+
StorageDecorator2.Action = Action;
|
|
10856
|
+
function Delete(options) {
|
|
10857
|
+
const list = [];
|
|
10858
|
+
return createOperationDecorator("delete", options, list);
|
|
10859
|
+
}
|
|
10860
|
+
__name(Delete, "Delete");
|
|
10861
|
+
StorageDecorator2.Delete = Delete;
|
|
10862
|
+
function Get(options) {
|
|
10863
|
+
const list = [];
|
|
10864
|
+
return createOperationDecorator("get", options, list);
|
|
10865
|
+
}
|
|
10866
|
+
__name(Get, "Get");
|
|
10867
|
+
StorageDecorator2.Get = Get;
|
|
10868
|
+
function Post(options) {
|
|
10869
|
+
const list = [];
|
|
10870
|
+
const decorator = createOperationDecorator("post", options, list);
|
|
10871
|
+
decorator.MaxFields = (amount) => {
|
|
10872
|
+
list.push((operationMeta) => operationMeta.maxFields = amount);
|
|
10873
|
+
return decorator;
|
|
10874
|
+
};
|
|
10875
|
+
decorator.MaxFieldSize = (amount) => {
|
|
10876
|
+
list.push((operationMeta) => operationMeta.maxFieldsSize = amount);
|
|
10877
|
+
return decorator;
|
|
10878
|
+
};
|
|
10879
|
+
decorator.MaxFiles = (amount) => {
|
|
10880
|
+
list.push((operationMeta) => operationMeta.maxFiles = amount);
|
|
10881
|
+
return decorator;
|
|
10882
|
+
};
|
|
10883
|
+
decorator.MaxFileSize = (sizeInBytes) => {
|
|
10884
|
+
list.push((operationMeta) => operationMeta.maxFileSize = sizeInBytes);
|
|
10885
|
+
return decorator;
|
|
10886
|
+
};
|
|
10887
|
+
decorator.MaxTotalFileSize = (sizeInBytes) => {
|
|
10888
|
+
list.push((operationMeta) => operationMeta.maxTotalFileSize = sizeInBytes);
|
|
10889
|
+
return decorator;
|
|
10890
|
+
};
|
|
10891
|
+
decorator.MinFileSize = (sizeInBytes) => {
|
|
10892
|
+
list.push((operationMeta) => operationMeta.minFileSize = sizeInBytes);
|
|
10893
|
+
return decorator;
|
|
10894
|
+
};
|
|
10895
|
+
return decorator;
|
|
10896
|
+
}
|
|
10897
|
+
__name(Post, "Post");
|
|
10898
|
+
StorageDecorator2.Post = Post;
|
|
10899
|
+
})(StorageDecorator || (StorageDecorator = {}));
|
|
10900
|
+
|
|
10339
10901
|
// ../../build/common/esm/document/resource/storage.js
|
|
10340
10902
|
var Storage2 = /* @__PURE__ */ __name(function(...args) {
|
|
10341
10903
|
if (!this) {
|
|
10342
10904
|
const [options] = args;
|
|
10343
10905
|
return Storage2[DECORATOR].call(void 0, options);
|
|
10344
10906
|
}
|
|
10345
|
-
const [
|
|
10346
|
-
|
|
10907
|
+
const [parent, init] = args;
|
|
10908
|
+
merge12(this, new StorageClass(parent, init), { descriptor: true });
|
|
10347
10909
|
}, "Storage");
|
|
10348
10910
|
Storage2.prototype = StorageClass.prototype;
|
|
10349
10911
|
Object.assign(Storage2, StorageDecorator);
|
|
10350
10912
|
Storage2[DECORATOR] = StorageDecorator;
|
|
10351
10913
|
|
|
10352
|
-
// ../../build/common/esm/document/factory/
|
|
10353
|
-
|
|
10354
|
-
|
|
10355
|
-
|
|
10356
|
-
for (const name of sourceNames) {
|
|
10357
|
-
const schema = sourceQueue.get(name);
|
|
10358
|
-
if (!schema)
|
|
10359
|
-
continue;
|
|
10360
|
-
try {
|
|
10361
|
-
if (opra_schema_ns_exports.isCollection(schema)) {
|
|
10362
|
-
const resource = await this.createCollectionSource(name, schema);
|
|
10363
|
-
document.resources.set(name, resource);
|
|
10364
|
-
continue;
|
|
10365
|
-
}
|
|
10366
|
-
if (opra_schema_ns_exports.isSingleton(schema)) {
|
|
10367
|
-
const resource = await this.createSingletonSource(name, schema);
|
|
10368
|
-
document.resources.set(name, resource);
|
|
10369
|
-
continue;
|
|
10370
|
-
}
|
|
10371
|
-
if (opra_schema_ns_exports.isStorage(schema)) {
|
|
10372
|
-
const resource = await this.createFileSource(name, schema);
|
|
10373
|
-
document.resources.set(name, resource);
|
|
10374
|
-
continue;
|
|
10375
|
-
}
|
|
10376
|
-
} catch (e) {
|
|
10377
|
-
e.message = `Error in Resource schema (${name}): ` + e.message;
|
|
10378
|
-
throw e;
|
|
10379
|
-
}
|
|
10380
|
-
throw new TypeError(`Invalid Resource schema: ${JSON.stringify(schema).substring(0, 20)}...`);
|
|
10914
|
+
// ../../build/common/esm/document/factory/api-document-factory.js
|
|
10915
|
+
var ApiDocumentFactory = class _ApiDocumentFactory extends TypeDocumentFactory {
|
|
10916
|
+
static {
|
|
10917
|
+
__name(this, "ApiDocumentFactory");
|
|
10381
10918
|
}
|
|
10382
|
-
|
|
10383
|
-
|
|
10384
|
-
|
|
10385
|
-
const { document } = this;
|
|
10386
|
-
const dataType = document.getComplexType(schema.type);
|
|
10387
|
-
const initArgs = {
|
|
10388
|
-
...schema,
|
|
10389
|
-
name,
|
|
10390
|
-
type: dataType
|
|
10391
|
-
};
|
|
10392
|
-
return new Collection2(document, initArgs);
|
|
10393
|
-
}
|
|
10394
|
-
__name(createCollectionResource, "createCollectionResource");
|
|
10395
|
-
async function createSingletonResource(name, schema) {
|
|
10396
|
-
const { document } = this;
|
|
10397
|
-
const dataType = document.getComplexType(schema.type);
|
|
10398
|
-
const initArgs = {
|
|
10399
|
-
...schema,
|
|
10400
|
-
name,
|
|
10401
|
-
type: dataType
|
|
10402
|
-
};
|
|
10403
|
-
return new Singleton2(document, initArgs);
|
|
10404
|
-
}
|
|
10405
|
-
__name(createSingletonResource, "createSingletonResource");
|
|
10406
|
-
async function createStorageResource(name, schema) {
|
|
10407
|
-
const { document } = this;
|
|
10408
|
-
const initArgs = {
|
|
10409
|
-
...schema,
|
|
10410
|
-
name
|
|
10411
|
-
};
|
|
10412
|
-
return new Storage2(document, initArgs);
|
|
10413
|
-
}
|
|
10414
|
-
__name(createStorageResource, "createStorageResource");
|
|
10415
|
-
|
|
10416
|
-
// ../../build/common/esm/document/factory/process-types.js
|
|
10417
|
-
async function processTypes() {
|
|
10418
|
-
const { document, typeQueue } = this;
|
|
10419
|
-
for (const [name, schema] of typeQueue.entries()) {
|
|
10420
|
-
const dataType = this.createDataTypeInstance(schema.kind, name);
|
|
10421
|
-
document.types.set(name, dataType);
|
|
10422
|
-
}
|
|
10423
|
-
const typeNames = Array.from(typeQueue.keys());
|
|
10424
|
-
for (const name of typeNames) {
|
|
10425
|
-
if (!typeQueue.has(name))
|
|
10426
|
-
continue;
|
|
10427
|
-
this.addDataType(name);
|
|
10919
|
+
constructor() {
|
|
10920
|
+
super(...arguments);
|
|
10921
|
+
this.resourceQueue = new ResponsiveMap();
|
|
10428
10922
|
}
|
|
10429
|
-
|
|
10430
|
-
|
|
10431
|
-
|
|
10432
|
-
|
|
10433
|
-
|
|
10434
|
-
|
|
10435
|
-
|
|
10436
|
-
|
|
10437
|
-
|
|
10438
|
-
switch (kind) {
|
|
10439
|
-
case opra_schema_ns_exports.ComplexType.Kind:
|
|
10440
|
-
Object.setPrototypeOf(dataType, ComplexType2.prototype);
|
|
10441
|
-
break;
|
|
10442
|
-
case opra_schema_ns_exports.EnumType.Kind:
|
|
10443
|
-
Object.setPrototypeOf(dataType, EnumType2.prototype);
|
|
10444
|
-
break;
|
|
10445
|
-
case opra_schema_ns_exports.MappedType.Kind:
|
|
10446
|
-
Object.setPrototypeOf(dataType, MappedType2.prototype);
|
|
10447
|
-
break;
|
|
10448
|
-
case opra_schema_ns_exports.SimpleType.Kind:
|
|
10449
|
-
Object.setPrototypeOf(dataType, SimpleType2.prototype);
|
|
10450
|
-
break;
|
|
10451
|
-
case opra_schema_ns_exports.UnionType.Kind:
|
|
10452
|
-
Object.setPrototypeOf(dataType, UnionType2.prototype);
|
|
10453
|
-
break;
|
|
10454
|
-
default:
|
|
10455
|
-
throw new TypeError(`Unknown DataType kind (${kind})`);
|
|
10923
|
+
/**
|
|
10924
|
+
* Creates ApiDocument instance from given schema object
|
|
10925
|
+
* @param init
|
|
10926
|
+
*/
|
|
10927
|
+
static async createDocument(init) {
|
|
10928
|
+
const factory = new _ApiDocumentFactory();
|
|
10929
|
+
const document = factory.document = new ApiDocument();
|
|
10930
|
+
await factory.initDocument(init);
|
|
10931
|
+
return document;
|
|
10456
10932
|
}
|
|
10457
|
-
|
|
10458
|
-
|
|
10459
|
-
|
|
10460
|
-
|
|
10461
|
-
|
|
10462
|
-
|
|
10463
|
-
|
|
10464
|
-
|
|
10465
|
-
|
|
10466
|
-
|
|
10467
|
-
|
|
10468
|
-
|
|
10469
|
-
|
|
10470
|
-
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10481
|
-
|
|
10482
|
-
|
|
10483
|
-
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
|
|
10489
|
-
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
|
|
10493
|
-
|
|
10494
|
-
|
|
10495
|
-
|
|
10496
|
-
|
|
10497
|
-
|
|
10933
|
+
/**
|
|
10934
|
+
* Downloads schema from the given URL and creates the document instance * @param url
|
|
10935
|
+
*/
|
|
10936
|
+
static async createDocumentFromUrl(url) {
|
|
10937
|
+
const factory = new _ApiDocumentFactory();
|
|
10938
|
+
const document = factory.document = new ApiDocument();
|
|
10939
|
+
await factory.initDocumentFromUrl(url);
|
|
10940
|
+
return document;
|
|
10941
|
+
}
|
|
10942
|
+
async initDocument(init) {
|
|
10943
|
+
await super.initDocument(init);
|
|
10944
|
+
const processContainer = /* @__PURE__ */ __name(async (container, containerInit) => {
|
|
10945
|
+
if (!containerInit.resources)
|
|
10946
|
+
return;
|
|
10947
|
+
if (Array.isArray(containerInit.resources)) {
|
|
10948
|
+
for (const thunk of containerInit.resources) {
|
|
10949
|
+
const initArguments = await this.importResourceInstance(thunk);
|
|
10950
|
+
container.resources.set(initArguments.name, await this.createResource(container, initArguments));
|
|
10951
|
+
}
|
|
10952
|
+
} else
|
|
10953
|
+
for (const [name, schema] of Object.entries(containerInit.resources)) {
|
|
10954
|
+
const initArguments = await this.importResourceSchema(name, schema);
|
|
10955
|
+
container.resources.set(initArguments.name, await this.createResource(container, initArguments));
|
|
10956
|
+
}
|
|
10957
|
+
container.resources.sort();
|
|
10958
|
+
}, "processContainer");
|
|
10959
|
+
if (init.root) {
|
|
10960
|
+
this.curPath.push("/root");
|
|
10961
|
+
await processContainer(this.document.root, init.root);
|
|
10962
|
+
this.curPath.pop();
|
|
10963
|
+
this.document.invalidate();
|
|
10964
|
+
}
|
|
10965
|
+
return this.document;
|
|
10966
|
+
}
|
|
10967
|
+
async importResourceSchema(name, schema) {
|
|
10968
|
+
const convertEndpoints = /* @__PURE__ */ __name(async (source) => {
|
|
10969
|
+
if (!source)
|
|
10970
|
+
return;
|
|
10971
|
+
const output = {};
|
|
10972
|
+
for (const [kA, oA] of Object.entries(source)) {
|
|
10973
|
+
if (!oA)
|
|
10974
|
+
continue;
|
|
10975
|
+
let parameters;
|
|
10976
|
+
if (oA.parameters) {
|
|
10977
|
+
parameters = {};
|
|
10978
|
+
for (const [kP, oP] of Object.entries(oA.parameters)) {
|
|
10979
|
+
if (oP.enum) {
|
|
10980
|
+
oP.type = EnumType2(oP.enum, { name: kP + "Enum" });
|
|
10981
|
+
}
|
|
10982
|
+
parameters[kP] = {
|
|
10983
|
+
...oP,
|
|
10984
|
+
type: await this.importDataType(oP.type || "any")
|
|
10985
|
+
};
|
|
10986
|
+
}
|
|
10987
|
+
}
|
|
10988
|
+
output[kA] = { ...oA[kA], parameters };
|
|
10989
|
+
}
|
|
10990
|
+
return output;
|
|
10991
|
+
}, "convertEndpoints");
|
|
10992
|
+
if (schema.kind === "Collection") {
|
|
10993
|
+
return {
|
|
10498
10994
|
...schema,
|
|
10995
|
+
kind: schema.kind,
|
|
10499
10996
|
name,
|
|
10500
|
-
|
|
10997
|
+
type: await this.importDataType(schema.type),
|
|
10998
|
+
actions: await convertEndpoints(schema.actions),
|
|
10999
|
+
operations: await convertEndpoints(schema.operations)
|
|
10501
11000
|
};
|
|
10502
|
-
|
|
10503
|
-
|
|
10504
|
-
curPath.push(name);
|
|
10505
|
-
ComplexType2.apply(dataType, [document, initArgs]);
|
|
10506
|
-
if (name)
|
|
10507
|
-
typeQueue.delete(name);
|
|
10508
|
-
if (schema.fields) {
|
|
10509
|
-
for (const [elemName, v] of Object.entries(schema.fields)) {
|
|
10510
|
-
const elemSchema = typeof v === "object" ? v : { type: v };
|
|
10511
|
-
curPath.push(`${name}.${elemName}[type]`);
|
|
10512
|
-
const elemType = this.addDataType(elemSchema.type);
|
|
10513
|
-
dataType.addField({
|
|
10514
|
-
...elemSchema,
|
|
10515
|
-
name: elemName,
|
|
10516
|
-
type: elemType
|
|
10517
|
-
});
|
|
10518
|
-
curPath.pop();
|
|
10519
|
-
}
|
|
10520
|
-
}
|
|
10521
|
-
if (name)
|
|
10522
|
-
curPath.pop();
|
|
10523
|
-
return dataType;
|
|
10524
|
-
}
|
|
10525
|
-
if (opra_schema_ns_exports.isEnumType(schema)) {
|
|
10526
|
-
const initArgs = {
|
|
11001
|
+
} else if (schema.kind === "Singleton") {
|
|
11002
|
+
return {
|
|
10527
11003
|
...schema,
|
|
11004
|
+
kind: schema.kind,
|
|
10528
11005
|
name,
|
|
10529
|
-
|
|
11006
|
+
type: await this.importDataType(schema.type),
|
|
11007
|
+
actions: await convertEndpoints(schema.actions),
|
|
11008
|
+
operations: await convertEndpoints(schema.operations)
|
|
10530
11009
|
};
|
|
10531
|
-
|
|
10532
|
-
|
|
10533
|
-
curPath.push(name);
|
|
10534
|
-
EnumType2.apply(dataType, [document, initArgs]);
|
|
10535
|
-
if (name)
|
|
10536
|
-
curPath.pop();
|
|
10537
|
-
return dataType;
|
|
10538
|
-
}
|
|
10539
|
-
if (opra_schema_ns_exports.isUnionType(schema)) {
|
|
10540
|
-
const unionTypes = schema.types.map((t) => this.addDataType(t));
|
|
10541
|
-
const initArgs = {
|
|
11010
|
+
} else if (schema.kind === "Storage") {
|
|
11011
|
+
return {
|
|
10542
11012
|
...schema,
|
|
10543
11013
|
name,
|
|
10544
|
-
|
|
11014
|
+
actions: await convertEndpoints(schema.actions),
|
|
11015
|
+
operations: await convertEndpoints(schema.operations)
|
|
10545
11016
|
};
|
|
10546
|
-
|
|
10547
|
-
|
|
10548
|
-
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
|
|
10554
|
-
|
|
10555
|
-
const dt = this.addDataType(schema.type);
|
|
10556
|
-
if (!(dt instanceof ComplexType2))
|
|
10557
|
-
throw new TypeError(`MappedType requires a ComplexType`);
|
|
10558
|
-
const initArgs = {
|
|
11017
|
+
} else if (schema.kind === "Container") {
|
|
11018
|
+
const resources = [];
|
|
11019
|
+
if (schema.resources) {
|
|
11020
|
+
for (const [k, o] of Object.entries(schema.resources)) {
|
|
11021
|
+
const rinit = await this.importResourceSchema(k, o);
|
|
11022
|
+
resources.push(rinit);
|
|
11023
|
+
}
|
|
11024
|
+
}
|
|
11025
|
+
return {
|
|
10559
11026
|
...schema,
|
|
10560
11027
|
name,
|
|
10561
|
-
|
|
11028
|
+
resources,
|
|
11029
|
+
actions: await convertEndpoints(schema.actions)
|
|
10562
11030
|
};
|
|
10563
|
-
dataType = dataType || this.createDataTypeInstance(schema.kind, name);
|
|
10564
|
-
if (name)
|
|
10565
|
-
curPath.push(name);
|
|
10566
|
-
MappedType2.apply(dataType, [document, initArgs]);
|
|
10567
|
-
if (name)
|
|
10568
|
-
curPath.pop();
|
|
10569
|
-
return dataType;
|
|
10570
11031
|
}
|
|
10571
|
-
|
|
10572
|
-
if (curPath.length)
|
|
10573
|
-
e.message = `Error at ${curPath.join("/")}: ` + e.message;
|
|
10574
|
-
throw e;
|
|
10575
|
-
} finally {
|
|
10576
|
-
if (name) {
|
|
10577
|
-
circularRefs.delete(name);
|
|
10578
|
-
typeQueue.delete(name);
|
|
10579
|
-
}
|
|
10580
|
-
}
|
|
10581
|
-
throw new TypeError(`Invalid DataType schema: ${JSON.stringify(schema).substring(0, 20)}...`);
|
|
10582
|
-
}
|
|
10583
|
-
__name(addDataType, "addDataType");
|
|
10584
|
-
|
|
10585
|
-
// ../../build/common/esm/document/factory/factory.js
|
|
10586
|
-
var _a2;
|
|
10587
|
-
var DocumentFactory = class _DocumentFactory {
|
|
10588
|
-
static {
|
|
10589
|
-
__name(this, "DocumentFactory");
|
|
11032
|
+
throw new TypeError(`Can not import resource schema (${schema.kind})`);
|
|
10590
11033
|
}
|
|
10591
|
-
|
|
10592
|
-
|
|
10593
|
-
|
|
10594
|
-
|
|
10595
|
-
|
|
10596
|
-
|
|
10597
|
-
|
|
10598
|
-
|
|
10599
|
-
|
|
10600
|
-
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
|
|
10604
|
-
|
|
10605
|
-
|
|
10606
|
-
|
|
10607
|
-
|
|
10608
|
-
|
|
10609
|
-
|
|
10610
|
-
|
|
10611
|
-
|
|
10612
|
-
|
|
11034
|
+
async importResourceInstance(thunk) {
|
|
11035
|
+
thunk = await resolveThunk(thunk);
|
|
11036
|
+
let ctor;
|
|
11037
|
+
let metadata;
|
|
11038
|
+
let instance;
|
|
11039
|
+
if (typeof thunk === "function") {
|
|
11040
|
+
ctor = thunk;
|
|
11041
|
+
} else {
|
|
11042
|
+
ctor = Object.getPrototypeOf(thunk).constructor;
|
|
11043
|
+
instance = thunk;
|
|
11044
|
+
if (!Reflect.hasMetadata(RESOURCE_METADATA, ctor) && opra_schema_ns_exports.isResource(thunk) && typeof thunk.controller === "object") {
|
|
11045
|
+
ctor = Object.getPrototypeOf(thunk.controller).constructor;
|
|
11046
|
+
metadata = thunk;
|
|
11047
|
+
instance = thunk.controller;
|
|
11048
|
+
}
|
|
11049
|
+
}
|
|
11050
|
+
metadata = metadata || Reflect.getMetadata(RESOURCE_METADATA, ctor);
|
|
11051
|
+
if (!metadata && opra_schema_ns_exports.isResource(metadata))
|
|
11052
|
+
throw new TypeError(`Class "${ctor.name}" doesn't have a valid Resource metadata`);
|
|
11053
|
+
const convertEndpoints = /* @__PURE__ */ __name(async (source) => {
|
|
11054
|
+
if (!source)
|
|
11055
|
+
return;
|
|
11056
|
+
const output = {};
|
|
11057
|
+
for (const [kA, oA] of Object.entries(source)) {
|
|
11058
|
+
let parameters;
|
|
11059
|
+
if (oA.parameters) {
|
|
11060
|
+
parameters = {};
|
|
11061
|
+
for (const [kP, oP] of Object.entries(oA.parameters)) {
|
|
11062
|
+
if (oP.enum) {
|
|
11063
|
+
oP.type = EnumType2(oP.enum, { name: kP + "Enum" });
|
|
11064
|
+
}
|
|
11065
|
+
parameters[kP] = {
|
|
11066
|
+
...oP,
|
|
11067
|
+
type: await this.importDataType(oP.type || "any")
|
|
11068
|
+
};
|
|
11069
|
+
}
|
|
11070
|
+
}
|
|
11071
|
+
output[kA] = { ...oA, parameters };
|
|
11072
|
+
}
|
|
11073
|
+
return output;
|
|
11074
|
+
}, "convertEndpoints");
|
|
11075
|
+
const initArguments = cloneObject(metadata);
|
|
11076
|
+
initArguments.controller = instance;
|
|
11077
|
+
initArguments.ctor = ctor;
|
|
11078
|
+
if (initArguments.actions)
|
|
11079
|
+
initArguments.actions = await convertEndpoints(initArguments.actions);
|
|
11080
|
+
if (initArguments.kind === "Collection" || initArguments.kind === "Singleton") {
|
|
11081
|
+
const dataType = await this.importDataType(metadata.type);
|
|
11082
|
+
if (!dataType)
|
|
11083
|
+
throw new TypeError(`Unable to determine data type of "${initArguments.name}" resource`);
|
|
11084
|
+
if (!(dataType instanceof ComplexType2))
|
|
11085
|
+
throw new TypeError(`Data type of "${initArguments.name}" resource is not a ComplexType`);
|
|
11086
|
+
initArguments.type = dataType;
|
|
11087
|
+
if (initArguments.operations)
|
|
11088
|
+
initArguments.operations = await convertEndpoints(initArguments.operations);
|
|
11089
|
+
} else if (initArguments.kind === "Container") {
|
|
11090
|
+
const oldResources = initArguments.resources;
|
|
11091
|
+
if (Array.isArray(oldResources)) {
|
|
11092
|
+
initArguments.resources = [];
|
|
11093
|
+
for (const t of oldResources) {
|
|
11094
|
+
const rinit = await this.importResourceInstance(t);
|
|
11095
|
+
initArguments.resources.push(rinit);
|
|
11096
|
+
}
|
|
11097
|
+
}
|
|
11098
|
+
}
|
|
11099
|
+
return initArguments;
|
|
11100
|
+
}
|
|
11101
|
+
async createResource(container, initArguments) {
|
|
11102
|
+
if (initArguments.kind === "Collection")
|
|
11103
|
+
return new Collection2(container, initArguments);
|
|
11104
|
+
if (initArguments.kind === "Singleton")
|
|
11105
|
+
return new Singleton2(container, initArguments);
|
|
11106
|
+
if (initArguments.kind === "Storage")
|
|
11107
|
+
return new Storage2(container, initArguments);
|
|
11108
|
+
if (initArguments.kind === "Container") {
|
|
11109
|
+
const newContainer = new Container2(container, { ...initArguments, resources: void 0 });
|
|
11110
|
+
if (initArguments.resources) {
|
|
11111
|
+
for (const r of initArguments.resources) {
|
|
11112
|
+
const res = await this.createResource(newContainer, r);
|
|
11113
|
+
newContainer.resources.set(res.name, res);
|
|
11114
|
+
}
|
|
11115
|
+
}
|
|
11116
|
+
return newContainer;
|
|
11117
|
+
} else
|
|
11118
|
+
throw new Error(`Unknown resource type ${initArguments.kind}`);
|
|
10613
11119
|
}
|
|
10614
11120
|
};
|
|
10615
|
-
_a2 = DocumentFactory;
|
|
10616
|
-
DocumentFactory.designTypeMap = /* @__PURE__ */ new Map();
|
|
10617
|
-
(() => {
|
|
10618
|
-
_a2.prototype.createDocument = createDocument;
|
|
10619
|
-
_a2.prototype.createDocumentFromUrl = createDocumentFromUrl;
|
|
10620
|
-
_a2.prototype.createBuiltinTypeDocument = createBuiltinTypeDocument;
|
|
10621
|
-
_a2.prototype.addReferences = addReferences;
|
|
10622
|
-
_a2.prototype.importTypeClass = importTypeClass;
|
|
10623
|
-
_a2.prototype.extractSimpleTypeSchema = extractSimpleTypeSchema;
|
|
10624
|
-
_a2.prototype.extractComplexTypeSchema = extractComplexTypeSchema;
|
|
10625
|
-
_a2.prototype.extractMappedTypeSchema = extractMappedTypeSchema;
|
|
10626
|
-
_a2.prototype.extractUnionTypeSchema = extractUnionTypeSchema;
|
|
10627
|
-
_a2.prototype.extractEnumTypeSchema = extractEnumTypeSchema;
|
|
10628
|
-
_a2.prototype.extractFieldSchema = extractFieldSchema;
|
|
10629
|
-
_a2.prototype.processTypes = processTypes;
|
|
10630
|
-
_a2.prototype.createDataTypeInstance = createDataTypeInstance;
|
|
10631
|
-
_a2.prototype.addDataType = addDataType;
|
|
10632
|
-
_a2.prototype.importSourceClass = importResourceClass;
|
|
10633
|
-
_a2.prototype.extractSingletonSchema = extractSingletonSchema;
|
|
10634
|
-
_a2.prototype.extractCollectionSchema = extractCollectionSchema;
|
|
10635
|
-
_a2.prototype.processSourceQueue = processSourceQueue;
|
|
10636
|
-
_a2.prototype.createCollectionSource = createCollectionResource;
|
|
10637
|
-
_a2.prototype.createSingletonSource = createSingletonResource;
|
|
10638
|
-
_a2.prototype.createFileSource = createStorageResource;
|
|
10639
|
-
})();
|
|
10640
11121
|
|
|
10641
11122
|
// ../../build/common/esm/http/opra-url.js
|
|
10642
11123
|
import { splitString as splitString3, tokenize as tokenize3 } from "fast-tokenizer";
|
|
@@ -10644,7 +11125,7 @@ import { splitString as splitString3, tokenize as tokenize3 } from "fast-tokeniz
|
|
|
10644
11125
|
// ../../build/common/esm/http/opra-url-path.js
|
|
10645
11126
|
import { splitString as splitString2, tokenize as tokenize2 } from "fast-tokenizer";
|
|
10646
11127
|
import isPlainObject2 from "putil-isplainobject";
|
|
10647
|
-
var
|
|
11128
|
+
var _a2;
|
|
10648
11129
|
var nodeInspectCustom2 = Symbol.for("nodejs.util.inspect.custom");
|
|
10649
11130
|
var kLength = Symbol.for("kLength");
|
|
10650
11131
|
var pathComponentRegEx = /^([^/?#:@]+)(?:@([^/?#:]*))?(?:::(.*))?$/;
|
|
@@ -10655,7 +11136,7 @@ var OpraURLPath = class _OpraURLPath {
|
|
|
10655
11136
|
__name(this, "OpraURLPath");
|
|
10656
11137
|
}
|
|
10657
11138
|
constructor(...init) {
|
|
10658
|
-
this[
|
|
11139
|
+
this[_a2] = 0;
|
|
10659
11140
|
this._resolve(init.filter((x) => x));
|
|
10660
11141
|
}
|
|
10661
11142
|
get length() {
|
|
@@ -10698,7 +11179,7 @@ var OpraURLPath = class _OpraURLPath {
|
|
|
10698
11179
|
return v ? "/" + v : "";
|
|
10699
11180
|
}
|
|
10700
11181
|
/* istanbul ignore next */
|
|
10701
|
-
[(
|
|
11182
|
+
[(_a2 = kLength, nodeInspectCustom2)]() {
|
|
10702
11183
|
return `(UrlPath [${this.toString()}])`;
|
|
10703
11184
|
}
|
|
10704
11185
|
[Symbol.iterator]() {
|
|
@@ -10887,7 +11368,7 @@ function removeLeadingSeparator(s) {
|
|
|
10887
11368
|
__name(removeLeadingSeparator, "removeLeadingSeparator");
|
|
10888
11369
|
|
|
10889
11370
|
// ../../build/common/esm/http/opra-url.js
|
|
10890
|
-
var
|
|
11371
|
+
var _a3;
|
|
10891
11372
|
var nodeInspectCustom3 = Symbol.for("nodejs.util.inspect.custom");
|
|
10892
11373
|
var urlRegEx = /^(?:((?:[A-Z][A-Z+-.]+:)+)\/\/([^/?]+))?(.*)?$/i;
|
|
10893
11374
|
var schemeRegEx = /^([A-Z][A-Z+-.]+:?)+$/i;
|
|
@@ -10901,7 +11382,7 @@ var OpraURL = class _OpraURL {
|
|
|
10901
11382
|
__name(this, "OpraURL");
|
|
10902
11383
|
}
|
|
10903
11384
|
constructor(input, base) {
|
|
10904
|
-
this[
|
|
11385
|
+
this[_a3] = {
|
|
10905
11386
|
protocol: "",
|
|
10906
11387
|
username: "",
|
|
10907
11388
|
hostname: "",
|
|
@@ -11102,7 +11583,7 @@ var OpraURL = class _OpraURL {
|
|
|
11102
11583
|
this.search = tokenizer.join("&");
|
|
11103
11584
|
}
|
|
11104
11585
|
/* istanbul ignore next */
|
|
11105
|
-
[(
|
|
11586
|
+
[(_a3 = kContext, nodeInspectCustom3)]() {
|
|
11106
11587
|
return {
|
|
11107
11588
|
protocol: this.protocol,
|
|
11108
11589
|
username: this.username,
|
|
@@ -11348,15 +11829,18 @@ var HttpStatusMessages = {
|
|
|
11348
11829
|
import { uid } from "uid";
|
|
11349
11830
|
export {
|
|
11350
11831
|
ApiDocument,
|
|
11832
|
+
ApiDocumentFactory,
|
|
11351
11833
|
ApiField,
|
|
11352
11834
|
BadRequestError,
|
|
11353
11835
|
BaseI18n,
|
|
11354
11836
|
Collection2 as Collection,
|
|
11355
11837
|
ComplexType2 as ComplexType,
|
|
11838
|
+
Container2 as Container,
|
|
11839
|
+
CrudResource,
|
|
11356
11840
|
DATATYPE_METADATA,
|
|
11357
11841
|
DECORATOR,
|
|
11358
11842
|
DataType,
|
|
11359
|
-
|
|
11843
|
+
Endpoint,
|
|
11360
11844
|
EnumType2 as EnumType,
|
|
11361
11845
|
FailedDependencyError,
|
|
11362
11846
|
ForbiddenError,
|
|
@@ -11377,6 +11861,8 @@ export {
|
|
|
11377
11861
|
opra_schema_ns_exports as OpraSchema,
|
|
11378
11862
|
OpraURL,
|
|
11379
11863
|
OpraURLPath,
|
|
11864
|
+
OpraURLPathComponent,
|
|
11865
|
+
Parameter,
|
|
11380
11866
|
PickType,
|
|
11381
11867
|
RESOURCE_METADATA,
|
|
11382
11868
|
Resource,
|
|
@@ -11387,6 +11873,8 @@ export {
|
|
|
11387
11873
|
Singleton2 as Singleton,
|
|
11388
11874
|
Storage2 as Storage,
|
|
11389
11875
|
TYPENAME_PATTERN,
|
|
11876
|
+
TypeDocument,
|
|
11877
|
+
TypeDocumentFactory,
|
|
11390
11878
|
UnauthorizedError,
|
|
11391
11879
|
UnionType2 as UnionType,
|
|
11392
11880
|
UnprocessableEntityError,
|