@opra/common 0.25.4 → 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 +1843 -1355
- 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 +28 -21
- 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/opra-exception.js +18 -12
- package/cjs/exception/wrap-exception.js +2 -1
- package/cjs/helpers/responsive-map.js +3 -3
- package/cjs/http/opra-url-path.js +5 -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 +27 -21
- 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/opra-exception.js +18 -12
- package/esm/exception/wrap-exception.js +2 -1
- package/esm/helpers/responsive-map.js +3 -3
- package/esm/http/opra-url-path.js +4 -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 +26 -19
- 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/exception/opra-exception.d.ts +1 -1
- package/types/http/opra-url-path.d.ts +2 -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/collection-decorator.js +0 -38
- package/cjs/document/decorators/singleton.decorator.js +0 -36
- package/cjs/document/decorators/storage.decorator.js +0 -35
- 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/collection-decorator.js +0 -34
- package/esm/document/decorators/resource.decorator.js +0 -33
- package/esm/document/decorators/singleton.decorator.js +0 -32
- package/esm/document/decorators/storage.decorator.js +0 -31
- 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/collection-decorator.d.ts +0 -30
- 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 -22
- 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]() {
|
|
@@ -570,7 +573,7 @@ var OpraException = class extends Error {
|
|
|
570
573
|
this.initString(issue);
|
|
571
574
|
else if (issue instanceof Error)
|
|
572
575
|
this.initError(issue);
|
|
573
|
-
else
|
|
576
|
+
else
|
|
574
577
|
this.init(issue);
|
|
575
578
|
this.message = this.message || this.constructor.name;
|
|
576
579
|
}
|
|
@@ -592,25 +595,31 @@ var OpraException = class extends Error {
|
|
|
592
595
|
}, true);
|
|
593
596
|
}
|
|
594
597
|
init(issue) {
|
|
595
|
-
this.message = issue
|
|
596
|
-
this.severity = issue
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
598
|
+
this.message = issue?.message || this.constructor.name;
|
|
599
|
+
this.severity = issue?.severity || "error";
|
|
600
|
+
if (issue) {
|
|
601
|
+
this.system = issue.system;
|
|
602
|
+
this.code = issue.code;
|
|
603
|
+
this.details = issue.details;
|
|
604
|
+
}
|
|
600
605
|
}
|
|
601
606
|
initString(issue) {
|
|
602
|
-
this.
|
|
603
|
-
|
|
604
|
-
|
|
607
|
+
this.init({
|
|
608
|
+
message: String(issue || "") || this.constructor.name,
|
|
609
|
+
severity: "error",
|
|
610
|
+
code: this.constructor.name
|
|
611
|
+
});
|
|
605
612
|
}
|
|
606
613
|
initError(issue) {
|
|
607
614
|
if (typeof issue.status === "number")
|
|
608
615
|
this.status = issue.status;
|
|
609
616
|
else if (typeof issue.getStatus === "function")
|
|
610
617
|
this.status = issue.getStatus();
|
|
611
|
-
this.
|
|
612
|
-
|
|
613
|
-
|
|
618
|
+
this.init({
|
|
619
|
+
message: issue.message,
|
|
620
|
+
severity: issue.severity || "error",
|
|
621
|
+
code: issue.code || issue.constructor.name
|
|
622
|
+
});
|
|
614
623
|
}
|
|
615
624
|
};
|
|
616
625
|
|
|
@@ -668,6 +677,25 @@ var ForbiddenError = class extends OpraException {
|
|
|
668
677
|
}
|
|
669
678
|
};
|
|
670
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
|
+
|
|
671
699
|
// ../../build/common/esm/exception/http-errors/method-not-allowed.error.js
|
|
672
700
|
var MethodNotAllowedError = class extends OpraException {
|
|
673
701
|
static {
|
|
@@ -786,7 +814,7 @@ function wrapException(error) {
|
|
|
786
814
|
case 424:
|
|
787
815
|
return new FailedDependencyError(error);
|
|
788
816
|
default:
|
|
789
|
-
return new
|
|
817
|
+
return new InternalServerError(error);
|
|
790
818
|
}
|
|
791
819
|
}
|
|
792
820
|
__name(wrapException, "wrapException");
|
|
@@ -812,24 +840,6 @@ var IssueSeverity;
|
|
|
812
840
|
};
|
|
813
841
|
})(IssueSeverity || (IssueSeverity = {}));
|
|
814
842
|
|
|
815
|
-
// ../../build/common/esm/exception/http-errors/internal-server.error.js
|
|
816
|
-
var InternalServerError = class extends OpraException {
|
|
817
|
-
static {
|
|
818
|
-
__name(this, "InternalServerError");
|
|
819
|
-
}
|
|
820
|
-
constructor() {
|
|
821
|
-
super(...arguments);
|
|
822
|
-
this.status = 500;
|
|
823
|
-
}
|
|
824
|
-
init(issue) {
|
|
825
|
-
super.init({
|
|
826
|
-
message: translate("error:INTERNAL_SERVER_ERROR", "Internal server error"),
|
|
827
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
828
|
-
...issue
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
};
|
|
832
|
-
|
|
833
843
|
// ../../build/common/esm/exception/resource-errors/resource-conflict.error.js
|
|
834
844
|
var ResourceConflictError = class extends OpraException {
|
|
835
845
|
static {
|
|
@@ -897,9 +907,9 @@ __export(opra_schema_ns_exports, {
|
|
|
897
907
|
isDataType: () => isDataType,
|
|
898
908
|
isEnumType: () => isEnumType,
|
|
899
909
|
isMappedType: () => isMappedType,
|
|
910
|
+
isResource: () => isResource,
|
|
900
911
|
isSimpleType: () => isSimpleType,
|
|
901
912
|
isSingleton: () => isSingleton,
|
|
902
|
-
isSource: () => isSource,
|
|
903
913
|
isStorage: () => isStorage,
|
|
904
914
|
isUnionType: () => isUnionType
|
|
905
915
|
});
|
|
@@ -942,8 +952,8 @@ var Collection;
|
|
|
942
952
|
|
|
943
953
|
// ../../build/common/esm/schema/resource/container.interface.js
|
|
944
954
|
var Container;
|
|
945
|
-
(function(
|
|
946
|
-
|
|
955
|
+
(function(Container3) {
|
|
956
|
+
Container3.Kind = "Container";
|
|
947
957
|
})(Container || (Container = {}));
|
|
948
958
|
|
|
949
959
|
// ../../build/common/esm/schema/resource/singleton.interface.js
|
|
@@ -986,10 +996,10 @@ function isEnumType(obj) {
|
|
|
986
996
|
return obj && typeof obj === "object" && obj.kind === EnumType.Kind;
|
|
987
997
|
}
|
|
988
998
|
__name(isEnumType, "isEnumType");
|
|
989
|
-
function
|
|
999
|
+
function isResource(obj) {
|
|
990
1000
|
return obj && typeof obj === "object" && (obj.kind === Container.Kind || obj.kind === Collection.Kind || obj.kind === Singleton.Kind || obj.kind === Storage.Kind);
|
|
991
1001
|
}
|
|
992
|
-
__name(
|
|
1002
|
+
__name(isResource, "isResource");
|
|
993
1003
|
function isCollection(obj) {
|
|
994
1004
|
return obj && typeof obj === "object" && obj.kind === Collection.Kind;
|
|
995
1005
|
}
|
|
@@ -1007,34 +1017,15 @@ function isContainer(obj) {
|
|
|
1007
1017
|
}
|
|
1008
1018
|
__name(isContainer, "isContainer");
|
|
1009
1019
|
|
|
1010
|
-
// ../../build/common/esm/document/data-type/complex-type.js
|
|
1011
|
-
import "reflect-metadata";
|
|
1012
|
-
import merge4 from "putil-merge";
|
|
1013
|
-
|
|
1014
|
-
// ../../build/common/esm/document/decorators/complex-type.decorator.js
|
|
1015
|
-
import omit from "lodash.omit";
|
|
1016
|
-
function ComplexTypeDecorator(options) {
|
|
1017
|
-
return function(target) {
|
|
1018
|
-
const name = options?.name || target.name.match(TYPENAME_PATTERN)?.[1] || target.name;
|
|
1019
|
-
let metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target);
|
|
1020
|
-
if (!metadata) {
|
|
1021
|
-
metadata = {};
|
|
1022
|
-
Reflect.defineMetadata(DATATYPE_METADATA, metadata, target);
|
|
1023
|
-
}
|
|
1024
|
-
metadata.kind = opra_schema_ns_exports.ComplexType.Kind;
|
|
1025
|
-
metadata.name = name;
|
|
1026
|
-
if (options)
|
|
1027
|
-
Object.assign(metadata, omit(options, ["kind", "name", "base", "fields"]));
|
|
1028
|
-
};
|
|
1029
|
-
}
|
|
1030
|
-
__name(ComplexTypeDecorator, "ComplexTypeDecorator");
|
|
1031
|
-
|
|
1032
1020
|
// ../../build/common/esm/document/utils/inspect.util.js
|
|
1033
1021
|
var nodeInspectCustom = Symbol.for("nodejs.util.inspect.custom");
|
|
1034
1022
|
var colorReset = "\x1B[0m";
|
|
1035
1023
|
var colorFgYellow = "\x1B[33m";
|
|
1036
1024
|
var colorFgMagenta = "\x1B[35m";
|
|
1037
1025
|
|
|
1026
|
+
// ../../build/common/esm/document/resource/endpoint.js
|
|
1027
|
+
import * as vg2 from "valgen";
|
|
1028
|
+
|
|
1038
1029
|
// ../../build/common/esm/document/data-type/data-type.js
|
|
1039
1030
|
var DataType = class _DataType {
|
|
1040
1031
|
static {
|
|
@@ -1047,7 +1038,8 @@ var DataType = class _DataType {
|
|
|
1047
1038
|
this.description = init?.description;
|
|
1048
1039
|
this.isAnonymous = !this.name;
|
|
1049
1040
|
}
|
|
1050
|
-
|
|
1041
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1042
|
+
exportSchema(options) {
|
|
1051
1043
|
return omitUndefined({
|
|
1052
1044
|
kind: this.kind,
|
|
1053
1045
|
description: this.description
|
|
@@ -1071,214 +1063,492 @@ var DataType = class _DataType {
|
|
|
1071
1063
|
}
|
|
1072
1064
|
};
|
|
1073
1065
|
|
|
1074
|
-
// ../../build/common/esm/document/
|
|
1075
|
-
import
|
|
1076
|
-
|
|
1077
|
-
// ../../build/common/esm/document/data-type/field-class.js
|
|
1078
|
-
var FieldClass = class {
|
|
1066
|
+
// ../../build/common/esm/document/resource/parameter.js
|
|
1067
|
+
import * as vg from "valgen";
|
|
1068
|
+
var Parameter = class {
|
|
1079
1069
|
static {
|
|
1080
|
-
__name(this, "
|
|
1070
|
+
__name(this, "Parameter");
|
|
1081
1071
|
}
|
|
1082
|
-
constructor(
|
|
1083
|
-
this.
|
|
1084
|
-
this.name = init.name;
|
|
1085
|
-
this.origin = init.origin || owner;
|
|
1072
|
+
constructor(name, init) {
|
|
1073
|
+
this.name = name;
|
|
1086
1074
|
this.type = init.type;
|
|
1087
1075
|
this.description = init.description;
|
|
1088
1076
|
this.isArray = init.isArray;
|
|
1089
1077
|
this.default = init.default;
|
|
1090
|
-
this.fixed = init.fixed;
|
|
1091
1078
|
this.required = init.required;
|
|
1092
|
-
this.exclusive = init.exclusive;
|
|
1093
1079
|
this.deprecated = init.deprecated;
|
|
1094
1080
|
this.examples = init.examples;
|
|
1081
|
+
this.isBuiltin = init.isBuiltin;
|
|
1095
1082
|
}
|
|
1096
|
-
exportSchema() {
|
|
1083
|
+
exportSchema(options) {
|
|
1097
1084
|
return omitUndefined({
|
|
1098
|
-
type: this.type.name ? this.type.name : this.type.exportSchema(),
|
|
1085
|
+
type: this.type.name ? this.type.name : this.type.exportSchema(options),
|
|
1099
1086
|
description: this.description,
|
|
1100
1087
|
isArray: this.isArray,
|
|
1101
1088
|
default: this.default,
|
|
1102
|
-
fixed: this.fixed,
|
|
1103
1089
|
required: this.required,
|
|
1104
|
-
exclusive: this.exclusive,
|
|
1105
1090
|
deprecated: this.deprecated,
|
|
1106
1091
|
examples: this.examples
|
|
1107
1092
|
});
|
|
1108
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
|
+
}
|
|
1109
1110
|
};
|
|
1110
1111
|
|
|
1111
|
-
// ../../build/common/esm/document/
|
|
1112
|
-
|
|
1113
|
-
import omit2 from "lodash.omit";
|
|
1114
|
-
import merge2 from "putil-merge";
|
|
1115
|
-
|
|
1116
|
-
// ../../build/common/esm/document/data-type/enum-type-class.js
|
|
1117
|
-
import * as vg from "valgen";
|
|
1118
|
-
var EnumTypeClass = class extends DataType {
|
|
1112
|
+
// ../../build/common/esm/document/resource/endpoint.js
|
|
1113
|
+
var Endpoint = class {
|
|
1119
1114
|
static {
|
|
1120
|
-
__name(this, "
|
|
1115
|
+
__name(this, "Endpoint");
|
|
1121
1116
|
}
|
|
1122
|
-
constructor(
|
|
1123
|
-
|
|
1124
|
-
this.
|
|
1125
|
-
this.
|
|
1126
|
-
this.
|
|
1127
|
-
this
|
|
1128
|
-
this.
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
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
|
+
}
|
|
1132
1129
|
}
|
|
1133
|
-
|
|
1134
|
-
const
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
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;
|
|
1141
1151
|
}
|
|
1142
1152
|
};
|
|
1143
1153
|
|
|
1144
|
-
// ../../build/common/esm/document/
|
|
1145
|
-
var
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
const values = Array.isArray(enumSource) ? enumSource.reduce((obj, v) => {
|
|
1149
|
-
obj[v] = v;
|
|
1150
|
-
return obj;
|
|
1151
|
-
}, {}) : enumSource;
|
|
1152
|
-
const metadata = {
|
|
1153
|
-
kind: opra_schema_ns_exports.EnumType.Kind,
|
|
1154
|
-
values
|
|
1155
|
-
};
|
|
1156
|
-
if (options)
|
|
1157
|
-
Object.assign(metadata, omit2(options, ["kind", "values"]));
|
|
1158
|
-
Reflect.defineMetadata(DATATYPE_METADATA, metadata, enumSource);
|
|
1159
|
-
return values;
|
|
1154
|
+
// ../../build/common/esm/document/resource/resource.js
|
|
1155
|
+
var Resource = class _Resource {
|
|
1156
|
+
static {
|
|
1157
|
+
__name(this, "Resource");
|
|
1160
1158
|
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
designType
|
|
1180
|
-
};
|
|
1181
|
-
if (designType === Array) {
|
|
1182
|
-
elemMeta.isArray = true;
|
|
1183
|
-
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
|
+
}
|
|
1184
1177
|
}
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
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);
|
|
1199
1193
|
}
|
|
1200
1194
|
}
|
|
1201
|
-
|
|
1202
|
-
};
|
|
1203
|
-
}
|
|
1204
|
-
__name(FieldDecorator, "FieldDecorator");
|
|
1205
|
-
|
|
1206
|
-
// ../../build/common/esm/document/data-type/field.js
|
|
1207
|
-
var ApiField = /* @__PURE__ */ __name(function(...args) {
|
|
1208
|
-
if (!this) {
|
|
1209
|
-
const [options] = args;
|
|
1210
|
-
return ApiField[DECORATOR](options);
|
|
1195
|
+
return schema;
|
|
1211
1196
|
}
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
Object.
|
|
1217
|
-
|
|
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
|
+
};
|
|
1218
1204
|
|
|
1219
|
-
// ../../build/common/esm/document/
|
|
1220
|
-
var
|
|
1205
|
+
// ../../build/common/esm/document/resource/container-class.js
|
|
1206
|
+
var ContainerClass = class _ContainerClass extends Resource {
|
|
1221
1207
|
static {
|
|
1222
|
-
__name(this, "
|
|
1223
|
-
}
|
|
1224
|
-
constructor(document, init) {
|
|
1225
|
-
super(document, init);
|
|
1226
|
-
this.kind = opra_schema_ns_exports.ComplexType.Kind;
|
|
1227
|
-
const own = this.own = {};
|
|
1228
|
-
own.ctor = init?.ctor || init?.base?.ctor;
|
|
1229
|
-
own.abstract = init?.abstract;
|
|
1230
|
-
own.additionalFields = init?.additionalFields;
|
|
1231
|
-
own.fields = new ResponsiveMap();
|
|
1232
|
-
this.kind = opra_schema_ns_exports.ComplexType.Kind;
|
|
1233
|
-
this.base = init?.base;
|
|
1234
|
-
this.ctor = own.ctor || Object;
|
|
1235
|
-
this.abstract = own.abstract;
|
|
1236
|
-
this.additionalFields = own.additionalFields;
|
|
1237
|
-
this.fields = new ResponsiveMap();
|
|
1238
|
-
if (this.base) {
|
|
1239
|
-
if (this.additionalFields == null)
|
|
1240
|
-
this.additionalFields = this.base.additionalFields;
|
|
1241
|
-
if (this.base.fields)
|
|
1242
|
-
for (const [k, el] of this.base.fields.entries()) {
|
|
1243
|
-
const newEl = new ApiField(this, el);
|
|
1244
|
-
this.fields.set(k, newEl);
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1208
|
+
__name(this, "ContainerClass");
|
|
1247
1209
|
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
this.
|
|
1251
|
-
this.
|
|
1252
|
-
|
|
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;
|
|
1253
1215
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
if (
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
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);
|
|
1261
1222
|
}
|
|
1262
|
-
return field;
|
|
1263
1223
|
}
|
|
1264
|
-
return
|
|
1224
|
+
return schema;
|
|
1265
1225
|
}
|
|
1266
|
-
|
|
1267
|
-
let
|
|
1268
|
-
if (
|
|
1269
|
-
|
|
1270
|
-
|
|
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;
|
|
1271
1239
|
}
|
|
1240
|
+
if (!resource || i < l - 1)
|
|
1241
|
+
resource = void 0;
|
|
1272
1242
|
} else
|
|
1273
|
-
|
|
1274
|
-
if (
|
|
1275
|
-
|
|
1276
|
-
|
|
1243
|
+
resource = this.resources.get(path2);
|
|
1244
|
+
if (resource || silent)
|
|
1245
|
+
return resource;
|
|
1246
|
+
throw new ResourceNotFoundError(path2);
|
|
1277
1247
|
}
|
|
1278
|
-
|
|
1279
|
-
const
|
|
1280
|
-
|
|
1281
|
-
|
|
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;
|
|
1282
1552
|
let field;
|
|
1283
1553
|
let curPath = "";
|
|
1284
1554
|
let s;
|
|
@@ -1327,23 +1597,23 @@ var ComplexTypeClass = class extends DataType {
|
|
|
1327
1597
|
}).flat();
|
|
1328
1598
|
return array.length ? array : void 0;
|
|
1329
1599
|
}
|
|
1330
|
-
exportSchema() {
|
|
1331
|
-
const out = super.exportSchema();
|
|
1600
|
+
exportSchema(options) {
|
|
1601
|
+
const out = super.exportSchema(options);
|
|
1332
1602
|
Object.assign(out, omitUndefined({
|
|
1333
|
-
base: this.base ? this.base.name ? this.base.name : this.base.exportSchema() : void 0,
|
|
1334
|
-
abstract: this.
|
|
1603
|
+
base: this.base ? this.base.name ? this.base.name : this.base.exportSchema(options) : void 0,
|
|
1604
|
+
abstract: this.abstract,
|
|
1335
1605
|
additionalFields: this.own.additionalFields
|
|
1336
1606
|
}));
|
|
1337
1607
|
if (this.own.fields.size) {
|
|
1338
1608
|
const fields = out.fields = {};
|
|
1339
1609
|
for (const field of this.own.fields.values()) {
|
|
1340
|
-
fields[field.name] = field.exportSchema();
|
|
1610
|
+
fields[field.name] = field.exportSchema(options);
|
|
1341
1611
|
}
|
|
1342
1612
|
}
|
|
1343
1613
|
return omitUndefined(out);
|
|
1344
1614
|
}
|
|
1345
1615
|
isTypeOf(t) {
|
|
1346
|
-
return t === this.own
|
|
1616
|
+
return t === this.own?.ctor;
|
|
1347
1617
|
}
|
|
1348
1618
|
extendsFrom(t) {
|
|
1349
1619
|
const base = t instanceof DataType ? t : this.document.getDataType(t);
|
|
@@ -1354,6 +1624,18 @@ var ComplexTypeClass = class extends DataType {
|
|
|
1354
1624
|
}
|
|
1355
1625
|
return false;
|
|
1356
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
|
+
}
|
|
1357
1639
|
};
|
|
1358
1640
|
|
|
1359
1641
|
// ../../build/common/esm/document/data-type/complex-type.js
|
|
@@ -1363,28 +1645,47 @@ var ComplexType2 = /* @__PURE__ */ __name(function(...args) {
|
|
|
1363
1645
|
return ComplexType2[DECORATOR](options);
|
|
1364
1646
|
}
|
|
1365
1647
|
const [document, init] = args;
|
|
1366
|
-
|
|
1648
|
+
merge5(this, new ComplexTypeClass(document, init), { descriptor: true });
|
|
1367
1649
|
}, "ComplexType");
|
|
1368
1650
|
ComplexType2.prototype = ComplexTypeClass.prototype;
|
|
1369
1651
|
Object.assign(ComplexType2, ComplexTypeDecorator);
|
|
1370
1652
|
ComplexType2[DECORATOR] = ComplexTypeDecorator;
|
|
1371
1653
|
|
|
1372
|
-
// ../../build/common/esm/document/
|
|
1373
|
-
var
|
|
1654
|
+
// ../../build/common/esm/document/document-base.js
|
|
1655
|
+
var DocumentBase = class {
|
|
1374
1656
|
static {
|
|
1375
|
-
__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");
|
|
1376
1681
|
}
|
|
1377
1682
|
constructor() {
|
|
1683
|
+
super();
|
|
1378
1684
|
this._designCtorMap = /* @__PURE__ */ new Map();
|
|
1379
1685
|
this._typeCache = new ResponsiveMap();
|
|
1380
1686
|
this._typesCacheByCtor = /* @__PURE__ */ new Map();
|
|
1381
1687
|
this.references = new ResponsiveMap();
|
|
1382
1688
|
this.types = new ResponsiveMap();
|
|
1383
|
-
this.resources = new ResponsiveMap();
|
|
1384
|
-
this.info = {
|
|
1385
|
-
version: "",
|
|
1386
|
-
title: ""
|
|
1387
|
-
};
|
|
1388
1689
|
const BigIntConstructor = Object.getPrototypeOf(BigInt(0)).constructor;
|
|
1389
1690
|
const BufferConstructor = Object.getPrototypeOf(Buffer.from([]));
|
|
1390
1691
|
this._designCtorMap.set(String, "string");
|
|
@@ -1401,8 +1702,21 @@ var ApiDocument = class {
|
|
|
1401
1702
|
*
|
|
1402
1703
|
*/
|
|
1403
1704
|
getDataType(arg0, silent) {
|
|
1705
|
+
if (typeof arg0 === "function") {
|
|
1706
|
+
const x = this._designCtorMap.get(arg0);
|
|
1707
|
+
if (x)
|
|
1708
|
+
arg0 = x;
|
|
1709
|
+
}
|
|
1404
1710
|
let dataType;
|
|
1405
|
-
|
|
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);
|
|
1406
1720
|
const t = typeof arg0 === "string" ? this._typeCache.get(arg0) : this._typesCacheByCtor.get(arg0);
|
|
1407
1721
|
if (t)
|
|
1408
1722
|
return t;
|
|
@@ -1411,12 +1725,7 @@ var ApiDocument = class {
|
|
|
1411
1725
|
return;
|
|
1412
1726
|
throw new Error(`Data type "${name}" does not exists`);
|
|
1413
1727
|
}
|
|
1414
|
-
if (typeof arg0 === "
|
|
1415
|
-
const x = this._designCtorMap.get(arg0);
|
|
1416
|
-
if (x)
|
|
1417
|
-
arg0 = x;
|
|
1418
|
-
}
|
|
1419
|
-
if (typeof arg0 === "string") {
|
|
1728
|
+
if (typeof arg0 === "string" && arg0) {
|
|
1420
1729
|
const m = NAMESPACE_PATTERN.exec(arg0);
|
|
1421
1730
|
if (!m)
|
|
1422
1731
|
throw new TypeError(`Invalid data type name "${name}"`);
|
|
@@ -1468,9 +1777,19 @@ var ApiDocument = class {
|
|
|
1468
1777
|
if (dataType)
|
|
1469
1778
|
return dataType;
|
|
1470
1779
|
if (!silent)
|
|
1471
|
-
throw new
|
|
1780
|
+
throw new Error(`No data type mapping found for class "${name}"`);
|
|
1472
1781
|
return;
|
|
1473
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
|
+
}
|
|
1474
1793
|
if (!silent)
|
|
1475
1794
|
throw new TypeError("Invalid argument");
|
|
1476
1795
|
}
|
|
@@ -1492,119 +1811,82 @@ var ApiDocument = class {
|
|
|
1492
1811
|
return t;
|
|
1493
1812
|
throw new NotAcceptableError(`Data type "${t.name || t}" is not a SimpleType`);
|
|
1494
1813
|
}
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
const m = NAMESPACE_PATTERN.exec(path2);
|
|
1498
|
-
if (!m)
|
|
1499
|
-
throw new NotFoundError(`Invalid resource path "${path2}"`);
|
|
1500
|
-
if (m[2]) {
|
|
1501
|
-
const ref = this.references.get(m[1]);
|
|
1502
|
-
if (!ref) {
|
|
1503
|
-
if (silent)
|
|
1504
|
-
return;
|
|
1505
|
-
throw new NotFoundError(`Reference "${m[1]}" not found`);
|
|
1506
|
-
}
|
|
1507
|
-
return ref.getResource(m[2]);
|
|
1508
|
-
} else {
|
|
1509
|
-
const name = m[1];
|
|
1510
|
-
resource = this.resources.get(name);
|
|
1511
|
-
if (resource)
|
|
1512
|
-
return resource;
|
|
1513
|
-
const references = Array.from(this.references.values()).reverse();
|
|
1514
|
-
for (const ref of references) {
|
|
1515
|
-
resource = silent ? ref.getResource(name, silent) : ref.getResource(name);
|
|
1516
|
-
if (resource)
|
|
1517
|
-
return resource;
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
if (silent)
|
|
1521
|
-
return;
|
|
1522
|
-
throw new ResourceNotFoundError(path2);
|
|
1523
|
-
}
|
|
1524
|
-
getCollection(path2, silent) {
|
|
1525
|
-
const t = this.getResource(path2);
|
|
1526
|
-
if (!t && silent)
|
|
1527
|
-
return;
|
|
1528
|
-
if (t && t.kind === opra_schema_ns_exports.Collection.Kind)
|
|
1529
|
-
return t;
|
|
1530
|
-
throw new NotAcceptableError(`Resource type "${t.name}" is not a Collection`);
|
|
1531
|
-
}
|
|
1532
|
-
getSingleton(path2, silent) {
|
|
1533
|
-
const t = this.getResource(path2);
|
|
1534
|
-
if (!t && silent)
|
|
1535
|
-
return;
|
|
1536
|
-
if (t && t.kind === opra_schema_ns_exports.Singleton.Kind)
|
|
1537
|
-
return t;
|
|
1538
|
-
throw new NotAcceptableError(`Resource type "${t.name}" is not a Singleton`);
|
|
1539
|
-
}
|
|
1540
|
-
getStorage(path2, silent) {
|
|
1541
|
-
const t = this.getResource(path2);
|
|
1814
|
+
getEnumType(nameOrCtor, silent) {
|
|
1815
|
+
const t = this.getDataType(nameOrCtor);
|
|
1542
1816
|
if (!t && silent)
|
|
1543
1817
|
return;
|
|
1544
|
-
if (t && t.kind === opra_schema_ns_exports.
|
|
1818
|
+
if (t && t.kind === opra_schema_ns_exports.EnumType.Kind)
|
|
1545
1819
|
return t;
|
|
1546
|
-
throw new NotAcceptableError(`
|
|
1820
|
+
throw new NotAcceptableError(`Data type "${t.name || t}" is not a EnumType`);
|
|
1547
1821
|
}
|
|
1548
1822
|
/**
|
|
1549
1823
|
* Export as Opra schema definition object
|
|
1550
1824
|
*/
|
|
1551
1825
|
exportSchema(options) {
|
|
1552
|
-
|
|
1553
|
-
return cloneObject(this._metadataCache, options?.webSafe);
|
|
1554
|
-
const schema = {
|
|
1555
|
-
version: opra_schema_ns_exports.SpecVersion,
|
|
1556
|
-
url: this.url,
|
|
1557
|
-
info: cloneObject(this.info)
|
|
1558
|
-
};
|
|
1826
|
+
const schema = super.exportSchema();
|
|
1559
1827
|
if (this.references.size) {
|
|
1560
1828
|
const references = {};
|
|
1561
1829
|
let i = 0;
|
|
1562
1830
|
for (const [ns, r] of this.references.entries()) {
|
|
1563
1831
|
if (ns.toLowerCase() === "opra")
|
|
1564
1832
|
continue;
|
|
1565
|
-
references[ns] = r.url ? r.url : r.exportSchema();
|
|
1833
|
+
references[ns] = r.url ? r.url : r.exportSchema(options);
|
|
1566
1834
|
i++;
|
|
1567
1835
|
}
|
|
1568
1836
|
if (i)
|
|
1569
1837
|
schema.references = references;
|
|
1570
1838
|
}
|
|
1571
|
-
if (this.resources.size) {
|
|
1572
|
-
const resources = schema.resources = {};
|
|
1573
|
-
for (const [name, r] of this.resources.entries()) {
|
|
1574
|
-
resources[name] = r.exportSchema();
|
|
1575
|
-
}
|
|
1576
|
-
}
|
|
1577
1839
|
if (this.types.size) {
|
|
1578
1840
|
const types = schema.types = {};
|
|
1579
1841
|
for (const [name, r] of this.types.entries()) {
|
|
1580
|
-
types[name] = r.exportSchema();
|
|
1842
|
+
types[name] = r.exportSchema(options);
|
|
1581
1843
|
}
|
|
1582
1844
|
}
|
|
1583
|
-
|
|
1584
|
-
return this._metadataCache;
|
|
1845
|
+
return schema;
|
|
1585
1846
|
}
|
|
1586
1847
|
invalidate() {
|
|
1587
|
-
this._metadataCache = void 0;
|
|
1588
1848
|
this._typeCache.clear();
|
|
1589
1849
|
this._typesCacheByCtor.clear();
|
|
1590
1850
|
}
|
|
1591
1851
|
};
|
|
1592
1852
|
|
|
1593
|
-
// ../../build/common/esm/document/
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
if (typeof r === "string") {
|
|
1598
|
-
document.references.set(ns, await this.createDocumentFromUrl(r));
|
|
1599
|
-
} else if (r instanceof ApiDocument)
|
|
1600
|
-
document.references.set(ns, r);
|
|
1601
|
-
else if (typeof r === "object") {
|
|
1602
|
-
document.references.set(ns, await this.createDocument(r));
|
|
1603
|
-
} else
|
|
1604
|
-
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");
|
|
1605
1857
|
}
|
|
1606
|
-
|
|
1607
|
-
|
|
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";
|
|
1608
1890
|
|
|
1609
1891
|
// ../../node_modules/tslib/tslib.es6.mjs
|
|
1610
1892
|
function __decorate(decorators, target, key, desc) {
|
|
@@ -1621,9 +1903,9 @@ __name(__decorate, "__decorate");
|
|
|
1621
1903
|
|
|
1622
1904
|
// ../../build/common/esm/document/data-type/simple-type.js
|
|
1623
1905
|
import "reflect-metadata";
|
|
1624
|
-
import
|
|
1906
|
+
import merge6 from "putil-merge";
|
|
1625
1907
|
|
|
1626
|
-
// ../../build/common/esm/document/
|
|
1908
|
+
// ../../build/common/esm/document/data-type/simple-type.decorator.js
|
|
1627
1909
|
import omit3 from "lodash.omit";
|
|
1628
1910
|
function SimpleTypeDecorator(options) {
|
|
1629
1911
|
return function(target) {
|
|
@@ -1640,7 +1922,7 @@ function SimpleTypeDecorator(options) {
|
|
|
1640
1922
|
__name(SimpleTypeDecorator, "SimpleTypeDecorator");
|
|
1641
1923
|
|
|
1642
1924
|
// ../../build/common/esm/document/data-type/simple-type-class.js
|
|
1643
|
-
import * as
|
|
1925
|
+
import * as vg5 from "valgen";
|
|
1644
1926
|
var SimpleTypeClass = class extends DataType {
|
|
1645
1927
|
static {
|
|
1646
1928
|
__name(this, "SimpleTypeClass");
|
|
@@ -1649,13 +1931,24 @@ var SimpleTypeClass = class extends DataType {
|
|
|
1649
1931
|
super(document, init);
|
|
1650
1932
|
this.kind = opra_schema_ns_exports.SimpleType.Kind;
|
|
1651
1933
|
this.base = init.base;
|
|
1652
|
-
this.decode = init.decoder || init.base?.decode ||
|
|
1653
|
-
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();
|
|
1654
1936
|
}
|
|
1655
|
-
exportSchema() {
|
|
1656
|
-
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
|
+
}));
|
|
1657
1944
|
return out;
|
|
1658
1945
|
}
|
|
1946
|
+
generateCodec(codec) {
|
|
1947
|
+
if (codec === "encode")
|
|
1948
|
+
return this.encode;
|
|
1949
|
+
else
|
|
1950
|
+
return this.decode;
|
|
1951
|
+
}
|
|
1659
1952
|
};
|
|
1660
1953
|
|
|
1661
1954
|
// ../../build/common/esm/document/data-type/simple-type.js
|
|
@@ -1665,7 +1958,7 @@ var SimpleType2 = /* @__PURE__ */ __name(function(...args) {
|
|
|
1665
1958
|
return SimpleType2[DECORATOR](options);
|
|
1666
1959
|
}
|
|
1667
1960
|
const [document, init] = args;
|
|
1668
|
-
|
|
1961
|
+
merge6(this, new SimpleTypeClass(document, init), { descriptor: true });
|
|
1669
1962
|
}, "SimpleType");
|
|
1670
1963
|
SimpleType2.prototype = SimpleTypeClass.prototype;
|
|
1671
1964
|
Object.assign(SimpleType2, SimpleTypeDecorator);
|
|
@@ -1895,327 +2188,558 @@ TimestampType = __decorate([
|
|
|
1895
2188
|
})
|
|
1896
2189
|
], TimestampType);
|
|
1897
2190
|
|
|
1898
|
-
// ../../build/common/esm/document/
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
this.document._designTypeMap.set(c, s);
|
|
1908
|
-
}
|
|
1909
|
-
if (init.references)
|
|
1910
|
-
await this.addReferences(init.references);
|
|
1911
|
-
if (init.types) {
|
|
1912
|
-
this.curPath.push("types");
|
|
1913
|
-
if (Array.isArray(init.types)) {
|
|
1914
|
-
for (const type of init.types)
|
|
1915
|
-
await this.importTypeClass(type);
|
|
1916
|
-
} else
|
|
1917
|
-
this.typeQueue.setAll(init.types);
|
|
1918
|
-
await this.processTypes();
|
|
1919
|
-
this.curPath.pop();
|
|
2191
|
+
// ../../build/common/esm/document/data-type/enum-type.js
|
|
2192
|
+
import "reflect-metadata";
|
|
2193
|
+
import merge7 from "putil-merge";
|
|
2194
|
+
|
|
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");
|
|
1920
2200
|
}
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
}
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
this.
|
|
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));
|
|
1930
2210
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
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;
|
|
2222
|
+
else
|
|
2223
|
+
return this.decode;
|
|
2224
|
+
}
|
|
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
|
+
});
|
|
2243
|
+
}
|
|
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;
|
|
2258
|
+
}
|
|
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);
|
|
1958
2287
|
}
|
|
1959
|
-
}
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
2288
|
+
}
|
|
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;
|
|
1976
2309
|
};
|
|
1977
|
-
const factoryClass = Object.getPrototypeOf(this).constructor;
|
|
1978
|
-
const factory = new factoryClass();
|
|
1979
|
-
return await factory.createDocument(init, { noBuiltinTypes: true });
|
|
1980
2310
|
}
|
|
1981
|
-
__name(
|
|
2311
|
+
__name(getIsInheritedPredicateFn, "getIsInheritedPredicateFn");
|
|
1982
2312
|
|
|
1983
|
-
// ../../build/common/esm/document/
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
const { document, sourceQueue, cache } = this;
|
|
1987
|
-
const controller = await resolveThunk(thunk);
|
|
1988
|
-
const cached = cache.get(controller);
|
|
1989
|
-
if (cached)
|
|
1990
|
-
return cached;
|
|
1991
|
-
const ctor = typeof thunk === "function" ? thunk : Object.getPrototypeOf(thunk).constructor;
|
|
1992
|
-
let metadata = Reflect.getMetadata(RESOURCE_METADATA, ctor);
|
|
1993
|
-
if (!metadata && opra_schema_ns_exports.isSource(metadata))
|
|
1994
|
-
throw new TypeError(`Class "${ctor.name}" doesn't have a valid Resource metadata`);
|
|
1995
|
-
metadata = cloneObject(metadata);
|
|
1996
|
-
const schema = cloneObject(metadata);
|
|
1997
|
-
schema.controller = controller;
|
|
1998
|
-
cache.set(thunk, schema);
|
|
1999
|
-
if (opra_schema_ns_exports.isSingleton(schema) || opra_schema_ns_exports.isCollection(schema)) {
|
|
2000
|
-
if (!document.getDataType(metadata.type, true) && typeof metadata.type === "function") {
|
|
2001
|
-
await this.importTypeClass(metadata.type);
|
|
2002
|
-
await this.processTypes();
|
|
2003
|
-
const dataTypeCtor = await resolveClass(metadata.type);
|
|
2004
|
-
const dataType = document.getComplexType(dataTypeCtor);
|
|
2005
|
-
schema.type = dataType.name;
|
|
2006
|
-
}
|
|
2007
|
-
document.getComplexType(schema.type);
|
|
2008
|
-
}
|
|
2009
|
-
if (opra_schema_ns_exports.isSingleton(schema))
|
|
2010
|
-
await this.extractSingletonSchema(schema, ctor, metadata, controller);
|
|
2011
|
-
if (opra_schema_ns_exports.isCollection(schema))
|
|
2012
|
-
await this.extractCollectionSchema(schema, ctor, metadata, controller);
|
|
2013
|
-
sourceQueue.set(metadata.name, schema);
|
|
2014
|
-
}
|
|
2015
|
-
__name(importResourceClass, "importResourceClass");
|
|
2016
|
-
async function extractSingletonSchema(target, ctor, metadata, controller) {
|
|
2313
|
+
// ../../build/common/esm/document/data-type/mapped-type.js
|
|
2314
|
+
function PickType(classRef, keys) {
|
|
2315
|
+
return MappedType2(classRef, { pick: keys });
|
|
2017
2316
|
}
|
|
2018
|
-
__name(
|
|
2019
|
-
|
|
2317
|
+
__name(PickType, "PickType");
|
|
2318
|
+
function OmitType(classRef, keys) {
|
|
2319
|
+
return MappedType2(classRef, { omit: keys });
|
|
2020
2320
|
}
|
|
2021
|
-
__name(
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
const thunk = await resolveThunk(typeThunk);
|
|
2028
|
-
const cached = cache.get(thunk);
|
|
2029
|
-
if (cached)
|
|
2030
|
-
return cached;
|
|
2031
|
-
const dt = document.getDataType(thunk, true);
|
|
2032
|
-
if (dt && dt.name)
|
|
2033
|
-
return dt.name;
|
|
2034
|
-
const metadata = Reflect.getMetadata(DATATYPE_METADATA, thunk);
|
|
2035
|
-
if (!(metadata && opra_schema_ns_exports.isDataType(metadata))) {
|
|
2036
|
-
if (isConstructor(thunk))
|
|
2037
|
-
throw new TypeError(`Class "${thunk.name}" doesn't have a valid DataType metadata`);
|
|
2038
|
-
throw new TypeError(`No EnumType metadata found for object ${JSON.stringify(thunk).substring(0, 20)}...`);
|
|
2039
|
-
}
|
|
2040
|
-
const name = metadata.name;
|
|
2041
|
-
const schema = cloneObject(metadata);
|
|
2042
|
-
const result = name || schema;
|
|
2043
|
-
if (name) {
|
|
2044
|
-
if (this.document.types.has(name) || typeQueue.has(name))
|
|
2045
|
-
throw new TypeError(`Type "${name}" already imported`);
|
|
2046
|
-
cache.set(thunk, result);
|
|
2047
|
-
typeQueue.set(name, schema);
|
|
2048
|
-
}
|
|
2049
|
-
if (isConstructor(thunk)) {
|
|
2050
|
-
const ctor = thunk;
|
|
2051
|
-
if (opra_schema_ns_exports.isSimpleType(schema))
|
|
2052
|
-
await this.extractSimpleTypeSchema(schema, ctor, metadata);
|
|
2053
|
-
else if (opra_schema_ns_exports.isComplexType(schema))
|
|
2054
|
-
await this.extractComplexTypeSchema(schema, ctor, metadata);
|
|
2055
|
-
else if (opra_schema_ns_exports.isMappedType(schema))
|
|
2056
|
-
await this.extractMappedTypeSchema(schema, ctor, metadata);
|
|
2057
|
-
else if (opra_schema_ns_exports.isUnionType(schema))
|
|
2058
|
-
await this.extractUnionTypeSchema(schema, ctor, metadata);
|
|
2059
|
-
else
|
|
2060
|
-
throw new TypeError(`Class "${ctor.name}" doesn't have a valid DataType metadata`);
|
|
2061
|
-
return result;
|
|
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;
|
|
2062
2327
|
}
|
|
2063
|
-
const
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
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);
|
|
2068
2336
|
}
|
|
2069
|
-
schema.base = baseType;
|
|
2070
|
-
await this.extractEnumTypeSchema(schema, enumObject, metadata);
|
|
2071
|
-
return result;
|
|
2072
2337
|
}
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
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
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
}
|
|
2119
|
-
|
|
2120
|
-
throw e;
|
|
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;
|
|
2361
|
+
|
|
2362
|
+
// ../../build/common/esm/document/data-type/union-type.js
|
|
2363
|
+
import "reflect-metadata";
|
|
2364
|
+
import merge9 from "putil-merge";
|
|
2365
|
+
|
|
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";
|
|
2121
2385
|
}
|
|
2386
|
+
this.fields.setAll(base.fields);
|
|
2122
2387
|
}
|
|
2388
|
+
this.types = [...own.types];
|
|
2123
2389
|
}
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
const oldTypes = metadata.types;
|
|
2132
|
-
target.types = [];
|
|
2133
|
-
for (const type of oldTypes)
|
|
2134
|
-
target.types.push(await this.importTypeClass(type));
|
|
2135
|
-
}
|
|
2136
|
-
__name(extractUnionTypeSchema, "extractUnionTypeSchema");
|
|
2137
|
-
async function extractEnumTypeSchema(target, enumObject, metadata) {
|
|
2138
|
-
}
|
|
2139
|
-
__name(extractEnumTypeSchema, "extractEnumTypeSchema");
|
|
2140
|
-
async function extractFieldSchema(target, ctor, metadata, name) {
|
|
2141
|
-
}
|
|
2142
|
-
__name(extractFieldSchema, "extractFieldSchema");
|
|
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
|
+
};
|
|
2143
2397
|
|
|
2144
|
-
// ../../build/common/esm/document/
|
|
2145
|
-
|
|
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: []
|
|
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;
|
|
2146
2436
|
|
|
2147
|
-
// ../../build/common/esm/document/
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
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,
|
|
2162
2711
|
kind,
|
|
2163
|
-
name
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
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
|
+
}
|
|
2180
2735
|
};
|
|
2736
|
+
TypeDocumentFactory.designTypeMap = /* @__PURE__ */ new Map();
|
|
2181
2737
|
|
|
2182
|
-
// ../../build/common/esm/document/
|
|
2183
|
-
|
|
2184
|
-
function CollectionDecorator(type, options) {
|
|
2185
|
-
return ResourceDecorator(opra_schema_ns_exports.Collection.Kind, { ...options, type });
|
|
2186
|
-
}
|
|
2187
|
-
__name(CollectionDecorator, "CollectionDecorator");
|
|
2188
|
-
Object.assign(CollectionDecorator, ResourceDecorator);
|
|
2189
|
-
CollectionDecorator.Create = createOperationDecorator("create");
|
|
2190
|
-
CollectionDecorator.Delete = createOperationDecorator("delete");
|
|
2191
|
-
CollectionDecorator.DeleteMany = createOperationDecorator("deleteMany");
|
|
2192
|
-
CollectionDecorator.Get = createOperationDecorator("get");
|
|
2193
|
-
CollectionDecorator.FindMany = createOperationDecorator("findMany");
|
|
2194
|
-
CollectionDecorator.Update = createOperationDecorator("update");
|
|
2195
|
-
CollectionDecorator.UpdateMany = createOperationDecorator("updateMany");
|
|
2196
|
-
CollectionDecorator.Action = function(options) {
|
|
2197
|
-
const oldDecorator = ResourceDecorator.Action(options);
|
|
2198
|
-
return (target, propertyKey) => {
|
|
2199
|
-
if (typeof propertyKey === "string" && operationProperties.includes(propertyKey))
|
|
2200
|
-
throw new TypeError(`The "${propertyKey}" property is reserved for "${propertyKey}" operations and cannot be used as an action'`);
|
|
2201
|
-
return oldDecorator(target, propertyKey);
|
|
2202
|
-
};
|
|
2203
|
-
};
|
|
2204
|
-
function createOperationDecorator(operation) {
|
|
2205
|
-
return (options) => (target, propertyKey) => {
|
|
2206
|
-
if (propertyKey !== operation)
|
|
2207
|
-
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
2208
|
-
const operationMeta = { ...options };
|
|
2209
|
-
const sourceMetadata = Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {};
|
|
2210
|
-
sourceMetadata.operations = sourceMetadata.operations || {};
|
|
2211
|
-
sourceMetadata.operations[operation] = operationMeta;
|
|
2212
|
-
Reflect.defineMetadata(RESOURCE_METADATA, sourceMetadata, target.constructor);
|
|
2213
|
-
};
|
|
2214
|
-
}
|
|
2215
|
-
__name(createOperationDecorator, "createOperationDecorator");
|
|
2738
|
+
// ../../build/common/esm/document/resource/collection.js
|
|
2739
|
+
import merge10 from "putil-merge";
|
|
2216
2740
|
|
|
2217
2741
|
// ../../build/common/esm/document/resource/collection-class.js
|
|
2218
|
-
import * as
|
|
2742
|
+
import * as vg7 from "valgen";
|
|
2219
2743
|
|
|
2220
2744
|
// ../../build/common/esm/filter/opra-filter.ns.js
|
|
2221
2745
|
var opra_filter_ns_exports = {};
|
|
@@ -9728,308 +10252,43 @@ var _wrapEntryValue = /* @__PURE__ */ __name((v) => {
|
|
|
9728
10252
|
return new StringLiteral("" + v);
|
|
9729
10253
|
}, "_wrapEntryValue");
|
|
9730
10254
|
|
|
9731
|
-
// ../../build/common/esm/document/
|
|
9732
|
-
|
|
9733
|
-
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
|
|
9737
|
-
|
|
9738
|
-
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
9742
|
-
}
|
|
9743
|
-
constructor(document, init) {
|
|
9744
|
-
super(document, init);
|
|
9745
|
-
this.kind = opra_schema_ns_exports.MappedType.Kind;
|
|
9746
|
-
const own = this.own;
|
|
9747
|
-
own.pick = init.pick;
|
|
9748
|
-
own.omit = init.omit;
|
|
9749
|
-
this.kind = opra_schema_ns_exports.MappedType.Kind;
|
|
9750
|
-
this.type = init.type;
|
|
9751
|
-
this.pick = own.pick;
|
|
9752
|
-
this.omit = own.omit;
|
|
9753
|
-
this.fields = new ResponsiveMap();
|
|
9754
|
-
this.additionalFields = this.type.additionalFields;
|
|
9755
|
-
const isInheritedPredicate = getIsInheritedPredicateFn(init.pick, init.omit);
|
|
9756
|
-
for (const [elemName, elem] of this.type.fields.entries()) {
|
|
9757
|
-
if (isInheritedPredicate(elemName))
|
|
9758
|
-
this.fields.set(elemName, elem);
|
|
9759
|
-
}
|
|
9760
|
-
}
|
|
9761
|
-
exportSchema() {
|
|
9762
|
-
const out = DataType.prototype.exportSchema.call(this);
|
|
9763
|
-
Object.assign(out, omitUndefined({
|
|
9764
|
-
type: this.type.name ? this.type.name : this.type.exportSchema(),
|
|
9765
|
-
pick: this.own.pick,
|
|
9766
|
-
omit: this.own.omit
|
|
9767
|
-
}));
|
|
9768
|
-
return out;
|
|
9769
|
-
}
|
|
9770
|
-
};
|
|
9771
|
-
function getIsInheritedPredicateFn(pick, omit5) {
|
|
9772
|
-
const pickKeys = pick?.map((x) => String(x).toLowerCase());
|
|
9773
|
-
const omitKeys = omit5?.map((x) => String(x).toLowerCase());
|
|
9774
|
-
return (propertyName) => {
|
|
9775
|
-
if (omitKeys && omitKeys.includes(propertyName.toLowerCase()))
|
|
9776
|
-
return false;
|
|
9777
|
-
if (pickKeys)
|
|
9778
|
-
return pickKeys.includes(propertyName.toLowerCase());
|
|
9779
|
-
return true;
|
|
9780
|
-
};
|
|
9781
|
-
}
|
|
9782
|
-
__name(getIsInheritedPredicateFn, "getIsInheritedPredicateFn");
|
|
9783
|
-
|
|
9784
|
-
// ../../build/common/esm/document/data-type/mapped-type.js
|
|
9785
|
-
function PickType(classRef, keys) {
|
|
9786
|
-
return MappedType2(classRef, { pick: keys });
|
|
9787
|
-
}
|
|
9788
|
-
__name(PickType, "PickType");
|
|
9789
|
-
function OmitType(classRef, keys) {
|
|
9790
|
-
return MappedType2(classRef, { omit: keys });
|
|
9791
|
-
}
|
|
9792
|
-
__name(OmitType, "OmitType");
|
|
9793
|
-
var MappedType2 = /* @__PURE__ */ __name(function(...args) {
|
|
9794
|
-
if (this) {
|
|
9795
|
-
const [document, init] = args;
|
|
9796
|
-
merge7(this, new MappedTypeClass(document, init), { descriptor: true });
|
|
9797
|
-
return;
|
|
9798
|
-
}
|
|
9799
|
-
const [mappedSource, options] = args;
|
|
9800
|
-
const isInheritedPredicate = getIsInheritedPredicateFn(options.pick, options.omit);
|
|
9801
|
-
class MappedClass {
|
|
9802
|
-
static {
|
|
9803
|
-
__name(this, "MappedClass");
|
|
9804
|
-
}
|
|
9805
|
-
constructor() {
|
|
9806
|
-
inheritPropertyInitializers(this, mappedSource, isInheritedPredicate);
|
|
9807
|
-
}
|
|
9808
|
-
}
|
|
9809
|
-
mergePrototype(MappedClass.prototype, mappedSource.prototype);
|
|
9810
|
-
const m = Reflect.getOwnMetadata(DATATYPE_METADATA, mappedSource);
|
|
9811
|
-
if (!m)
|
|
9812
|
-
throw new TypeError(`Class "${mappedSource}" doesn't have datatype metadata information`);
|
|
9813
|
-
if (!(m.kind === opra_schema_ns_exports.ComplexType.Kind))
|
|
9814
|
-
throw new TypeError(`Class "${mappedSource}" is not a ${opra_schema_ns_exports.ComplexType.Kind}`);
|
|
9815
|
-
const metadata = {
|
|
9816
|
-
kind: "MappedType",
|
|
9817
|
-
type: mappedSource
|
|
9818
|
-
};
|
|
9819
|
-
if (options.pick)
|
|
9820
|
-
metadata.pick = options.pick;
|
|
9821
|
-
if (options.omit)
|
|
9822
|
-
metadata.omit = options.omit;
|
|
9823
|
-
Reflect.defineMetadata(DATATYPE_METADATA, metadata, MappedClass);
|
|
9824
|
-
MappedType2._applyMixin(MappedClass, mappedSource, {
|
|
9825
|
-
...options,
|
|
9826
|
-
isInheritedPredicate
|
|
9827
|
-
});
|
|
9828
|
-
return MappedClass;
|
|
9829
|
-
}, "MappedType");
|
|
9830
|
-
MappedType2.prototype = MappedTypeClass.prototype;
|
|
9831
|
-
MappedType2._applyMixin = () => void 0;
|
|
9832
|
-
|
|
9833
|
-
// ../../build/common/esm/document/data-type/union-type.js
|
|
9834
|
-
import "reflect-metadata";
|
|
9835
|
-
import merge8 from "putil-merge";
|
|
9836
|
-
|
|
9837
|
-
// ../../build/common/esm/document/data-type/union-type-class.js
|
|
9838
|
-
var UnionTypeClass = class extends DataType {
|
|
9839
|
-
static {
|
|
9840
|
-
__name(this, "UnionTypeClass");
|
|
9841
|
-
}
|
|
9842
|
-
constructor(document, init) {
|
|
9843
|
-
super(document, init);
|
|
9844
|
-
this.kind = opra_schema_ns_exports.UnionType.Kind;
|
|
9845
|
-
this.fields = new ResponsiveMap();
|
|
9846
|
-
const own = this.own;
|
|
9847
|
-
own.types = [];
|
|
9848
|
-
const UnionType3 = Object.getPrototypeOf(this).constructor;
|
|
9849
|
-
for (const base of init.types) {
|
|
9850
|
-
if (!(base instanceof ComplexType2 || base instanceof UnionType3 || base instanceof MappedType2))
|
|
9851
|
-
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.`);
|
|
9852
|
-
own.types.push(base);
|
|
9853
|
-
if (base.additionalFields)
|
|
9854
|
-
this.additionalFields = base.additionalFields;
|
|
9855
|
-
this.fields.setAll(base.fields);
|
|
9856
|
-
}
|
|
9857
|
-
this.types = [...own.types];
|
|
9858
|
-
}
|
|
9859
|
-
exportSchema() {
|
|
9860
|
-
const out = super.exportSchema();
|
|
9861
|
-
Object.assign(out, omitUndefined({
|
|
9862
|
-
types: this.own.types.map((t) => t.name ? t.name : t.exportSchema())
|
|
9863
|
-
}));
|
|
9864
|
-
return out;
|
|
9865
|
-
}
|
|
9866
|
-
};
|
|
9867
|
-
|
|
9868
|
-
// ../../build/common/esm/document/data-type/union-type.js
|
|
9869
|
-
var UnionType2 = /* @__PURE__ */ __name(function(...args) {
|
|
9870
|
-
if (this) {
|
|
9871
|
-
const [document, init] = args;
|
|
9872
|
-
merge8(this, new UnionTypeClass(document, init), { descriptor: true });
|
|
9873
|
-
return;
|
|
9874
|
-
}
|
|
9875
|
-
const clasRefs = [...args].filter((x) => !!x);
|
|
9876
|
-
if (!clasRefs.length)
|
|
9877
|
-
throw new TypeError("No Class has been provided");
|
|
9878
|
-
if (clasRefs.length === 1)
|
|
9879
|
-
return clasRefs[0];
|
|
9880
|
-
class UnionClass {
|
|
9881
|
-
static {
|
|
9882
|
-
__name(this, "UnionClass");
|
|
9883
|
-
}
|
|
9884
|
-
constructor() {
|
|
9885
|
-
for (const c of clasRefs)
|
|
9886
|
-
inheritPropertyInitializers(this, c);
|
|
9887
|
-
}
|
|
9888
|
-
}
|
|
9889
|
-
const metadata = {
|
|
9890
|
-
kind: opra_schema_ns_exports.UnionType.Kind,
|
|
9891
|
-
types: []
|
|
9892
|
-
};
|
|
9893
|
-
Reflect.defineMetadata(DATATYPE_METADATA, metadata, UnionClass);
|
|
9894
|
-
for (const c of clasRefs) {
|
|
9895
|
-
const itemMeta = Reflect.getMetadata(DATATYPE_METADATA, c);
|
|
9896
|
-
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)))
|
|
9897
|
-
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}`);
|
|
9898
|
-
metadata.types.push(c);
|
|
9899
|
-
mergePrototype(UnionClass.prototype, c.prototype);
|
|
9900
|
-
}
|
|
9901
|
-
UnionType2._applyMixin(UnionClass, ...clasRefs);
|
|
9902
|
-
return UnionClass;
|
|
9903
|
-
}, "UnionType");
|
|
9904
|
-
UnionType2.prototype = UnionTypeClass.prototype;
|
|
9905
|
-
UnionType2._applyMixin = () => void 0;
|
|
9906
|
-
|
|
9907
|
-
// ../../build/common/esm/document/utils/generate-codec.js
|
|
9908
|
-
function generateCodec(type, codec, options) {
|
|
9909
|
-
return _generateCodec(type, codec, options);
|
|
9910
|
-
}
|
|
9911
|
-
__name(generateCodec, "generateCodec");
|
|
9912
|
-
function _generateCodec(type, codec, options) {
|
|
9913
|
-
const schema = {};
|
|
9914
|
-
for (const f of type.fields.values()) {
|
|
9915
|
-
let fn;
|
|
9916
|
-
if (f.type instanceof SimpleType2 || f.type instanceof EnumType2) {
|
|
9917
|
-
fn = f.type[codec];
|
|
9918
|
-
} else if (f.type instanceof ComplexType2 || f.type instanceof MappedType2 || f.type instanceof UnionType2) {
|
|
9919
|
-
fn = _generateCodec(f.type, codec, options);
|
|
9920
|
-
}
|
|
9921
|
-
if (!fn)
|
|
9922
|
-
throw new TypeError(`Can't generate codec for (${f.type})`);
|
|
9923
|
-
if (f.isArray)
|
|
9924
|
-
fn = vg3.isArray(fn);
|
|
9925
|
-
schema[f.name] = !options.partial && f.required ? vg3.required(fn) : vg3.optional(fn);
|
|
9926
|
-
}
|
|
9927
|
-
return vg3.isObject(schema, {
|
|
9928
|
-
ctor: type.ctor,
|
|
9929
|
-
additionalFields: type.additionalFields ?? false,
|
|
9930
|
-
name: type.name,
|
|
9931
|
-
caseInSensitive: true
|
|
9932
|
-
});
|
|
9933
|
-
}
|
|
9934
|
-
__name(_generateCodec, "_generateCodec");
|
|
9935
|
-
|
|
9936
|
-
// ../../build/common/esm/document/resource/endpoint.js
|
|
9937
|
-
var Endpoint = class _Endpoint {
|
|
9938
|
-
static {
|
|
9939
|
-
__name(this, "Endpoint");
|
|
9940
|
-
}
|
|
9941
|
-
constructor(init) {
|
|
9942
|
-
this.parameters = new ResponsiveMap();
|
|
9943
|
-
this.name = init.name;
|
|
9944
|
-
this.description = init.description;
|
|
9945
|
-
if (init.parameters) {
|
|
9946
|
-
for (const [n, p] of Object.entries(init.parameters)) {
|
|
9947
|
-
this.parameters.set(n, new _Endpoint.Parameter(p));
|
|
9948
|
-
}
|
|
9949
|
-
}
|
|
9950
|
-
}
|
|
9951
|
-
exportSchema() {
|
|
9952
|
-
const schema = omitUndefined({
|
|
9953
|
-
description: this.description
|
|
9954
|
-
});
|
|
9955
|
-
if (this.parameters.size) {
|
|
9956
|
-
schema.parameters = {};
|
|
9957
|
-
for (const [name, param] of this.parameters.entries()) {
|
|
9958
|
-
schema.parameters[name] = param.exportSchema();
|
|
9959
|
-
}
|
|
9960
|
-
}
|
|
9961
|
-
return schema;
|
|
9962
|
-
}
|
|
9963
|
-
};
|
|
9964
|
-
(function(Endpoint2) {
|
|
9965
|
-
class Parameter {
|
|
9966
|
-
static {
|
|
9967
|
-
__name(this, "Parameter");
|
|
9968
|
-
}
|
|
9969
|
-
constructor(init) {
|
|
9970
|
-
Object.assign(this, init);
|
|
9971
|
-
}
|
|
9972
|
-
exportSchema() {
|
|
9973
|
-
return omitUndefined({
|
|
9974
|
-
type: typeof this.type === "string" ? this.type : this.type.exportSchema(),
|
|
9975
|
-
description: this.description,
|
|
9976
|
-
isArray: this.isArray
|
|
9977
|
-
});
|
|
9978
|
-
}
|
|
9979
|
-
}
|
|
9980
|
-
Endpoint2.Parameter = Parameter;
|
|
9981
|
-
})(Endpoint || (Endpoint = {}));
|
|
9982
|
-
|
|
9983
|
-
// ../../build/common/esm/document/resource/resource.js
|
|
9984
|
-
var Resource = class {
|
|
9985
|
-
static {
|
|
9986
|
-
__name(this, "Resource");
|
|
9987
|
-
}
|
|
9988
|
-
constructor(document, init) {
|
|
9989
|
-
this.actions = new ResponsiveMap();
|
|
9990
|
-
this.document = document;
|
|
9991
|
-
this.name = init.name;
|
|
9992
|
-
this.description = init.description;
|
|
9993
|
-
this.controller = init.controller;
|
|
9994
|
-
if (init.actions) {
|
|
9995
|
-
for (const [name, meta] of Object.entries(init.actions)) {
|
|
9996
|
-
this.actions.set(name, new Endpoint({ ...meta, name }));
|
|
10255
|
+
// ../../build/common/esm/document/resource/crud-resource.js
|
|
10256
|
+
var CrudResource = class extends Resource {
|
|
10257
|
+
static {
|
|
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));
|
|
9997
10266
|
}
|
|
9998
10267
|
}
|
|
9999
10268
|
}
|
|
10000
|
-
|
|
10001
|
-
|
|
10002
|
-
|
|
10003
|
-
|
|
10004
|
-
|
|
10005
|
-
if (this.
|
|
10006
|
-
schema.
|
|
10007
|
-
for (const
|
|
10008
|
-
schema.
|
|
10269
|
+
getOperation(name) {
|
|
10270
|
+
return this.operations.get(name);
|
|
10271
|
+
}
|
|
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);
|
|
10009
10278
|
}
|
|
10010
10279
|
}
|
|
10011
10280
|
return schema;
|
|
10012
10281
|
}
|
|
10013
|
-
toString() {
|
|
10014
|
-
return `[${Object.getPrototypeOf(this).constructor.name} ${this.name || "#anonymous"}]`;
|
|
10015
|
-
}
|
|
10016
|
-
[nodeInspectCustom]() {
|
|
10017
|
-
return `[${colorFgYellow + Object.getPrototypeOf(this).constructor.name + colorReset} ${colorFgMagenta + this.name + colorReset}]`;
|
|
10018
|
-
}
|
|
10019
10282
|
};
|
|
10020
10283
|
|
|
10021
10284
|
// ../../build/common/esm/document/resource/collection-class.js
|
|
10022
|
-
var CollectionClass = class extends
|
|
10285
|
+
var CollectionClass = class extends CrudResource {
|
|
10023
10286
|
static {
|
|
10024
10287
|
__name(this, "CollectionClass");
|
|
10025
10288
|
}
|
|
10026
|
-
constructor(
|
|
10027
|
-
super(
|
|
10028
|
-
this._decoders = {};
|
|
10029
|
-
this._encoders = {};
|
|
10289
|
+
constructor(parent, init) {
|
|
10290
|
+
super(parent, init);
|
|
10030
10291
|
this.kind = opra_schema_ns_exports.Collection.Kind;
|
|
10031
|
-
this.controller = init.controller;
|
|
10032
|
-
this.operations = { ...init.operations };
|
|
10033
10292
|
const dataType = this.type = init.type;
|
|
10034
10293
|
this.primaryKey = init.primaryKey ? Array.isArray(init.primaryKey) ? init.primaryKey : [init.primaryKey] : [];
|
|
10035
10294
|
if (!this.primaryKey.length)
|
|
@@ -10039,15 +10298,92 @@ var CollectionClass = class extends Resource {
|
|
|
10039
10298
|
if (!(field?.type instanceof SimpleType2))
|
|
10040
10299
|
throw new TypeError(`Only Simple type allowed for primary keys but "${f}" is a ${field.type.kind}`);
|
|
10041
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
|
+
}
|
|
10042
10376
|
}
|
|
10043
|
-
|
|
10377
|
+
getOperation(name) {
|
|
10378
|
+
return super.getOperation(name);
|
|
10379
|
+
}
|
|
10380
|
+
exportSchema(options) {
|
|
10044
10381
|
return {
|
|
10045
|
-
...super.exportSchema(),
|
|
10046
|
-
|
|
10047
|
-
|
|
10048
|
-
operations: this.operations,
|
|
10382
|
+
...super.exportSchema(options),
|
|
10383
|
+
type: this.type.name || "object",
|
|
10384
|
+
...{
|
|
10049
10385
|
primaryKey: this.primaryKey
|
|
10050
|
-
}
|
|
10386
|
+
}
|
|
10051
10387
|
};
|
|
10052
10388
|
}
|
|
10053
10389
|
parseKeyValue(value) {
|
|
@@ -10086,7 +10422,7 @@ var CollectionClass = class extends Resource {
|
|
|
10086
10422
|
const normalized = this.type.normalizeFieldPath(fields);
|
|
10087
10423
|
if (!normalized)
|
|
10088
10424
|
return;
|
|
10089
|
-
const findManyOp = this.
|
|
10425
|
+
const findManyOp = this.getOperation("findMany");
|
|
10090
10426
|
const sortFields = findManyOp && findManyOp.sortFields;
|
|
10091
10427
|
(Array.isArray(normalized) ? normalized : [normalized]).forEach((field) => {
|
|
10092
10428
|
if (!sortFields?.find((x) => x === field))
|
|
@@ -10104,7 +10440,7 @@ var CollectionClass = class extends Resource {
|
|
|
10104
10440
|
this.normalizeFilter(ast.left);
|
|
10105
10441
|
if (!(ast.left instanceof opra_filter_ns_exports.QualifiedIdentifier && ast.left.field))
|
|
10106
10442
|
throw new TypeError(`Invalid filter query. Left side should be a data field.`);
|
|
10107
|
-
const findManyOp = this.
|
|
10443
|
+
const findManyOp = this.getOperation("findMany");
|
|
10108
10444
|
const fieldLower = ast.left.value.toLowerCase();
|
|
10109
10445
|
const filterDef = (findManyOp && findManyOp.filters || []).find((f) => f.field.toLowerCase() === fieldLower);
|
|
10110
10446
|
if (!filterDef) {
|
|
@@ -10144,33 +10480,204 @@ var CollectionClass = class extends Resource {
|
|
|
10144
10480
|
}
|
|
10145
10481
|
return ast;
|
|
10146
10482
|
}
|
|
10147
|
-
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
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;
|
|
10538
|
+
};
|
|
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;
|
|
10546
|
+
};
|
|
10547
|
+
return decorator;
|
|
10548
|
+
}
|
|
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;
|
|
10153
10628
|
};
|
|
10154
|
-
|
|
10155
|
-
|
|
10156
|
-
|
|
10157
|
-
this._decoders[endpoint] = decoder;
|
|
10158
|
-
return decoder;
|
|
10159
|
-
}
|
|
10160
|
-
getEncoder(endpoint) {
|
|
10161
|
-
let encoder = this._encoders[endpoint];
|
|
10162
|
-
if (encoder)
|
|
10163
|
-
return encoder;
|
|
10164
|
-
const options = {
|
|
10165
|
-
partial: true
|
|
10629
|
+
decorator.InputPickFields = (...fields) => {
|
|
10630
|
+
list.push((operationMeta) => operationMeta.inputPickFields = fields);
|
|
10631
|
+
return decorator;
|
|
10166
10632
|
};
|
|
10167
|
-
|
|
10168
|
-
|
|
10169
|
-
return
|
|
10170
|
-
|
|
10171
|
-
|
|
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;
|
|
10172
10677
|
}
|
|
10173
|
-
|
|
10678
|
+
__name(UpdateMany, "UpdateMany");
|
|
10679
|
+
CollectionDecorator2.UpdateMany = UpdateMany;
|
|
10680
|
+
})(CollectionDecorator || (CollectionDecorator = {}));
|
|
10174
10681
|
|
|
10175
10682
|
// ../../build/common/esm/document/resource/collection.js
|
|
10176
10683
|
var Collection2 = /* @__PURE__ */ __name(function(...args) {
|
|
@@ -10178,468 +10685,439 @@ var Collection2 = /* @__PURE__ */ __name(function(...args) {
|
|
|
10178
10685
|
const [type, options] = args;
|
|
10179
10686
|
return Collection2[DECORATOR].call(void 0, type, options);
|
|
10180
10687
|
}
|
|
10181
|
-
const [
|
|
10182
|
-
|
|
10688
|
+
const [parent, init] = args;
|
|
10689
|
+
merge10(this, new CollectionClass(parent, init), { descriptor: true });
|
|
10183
10690
|
}, "Collection");
|
|
10184
10691
|
Collection2.prototype = CollectionClass.prototype;
|
|
10185
10692
|
Object.assign(Collection2, CollectionDecorator);
|
|
10186
10693
|
Collection2[DECORATOR] = CollectionDecorator;
|
|
10187
10694
|
|
|
10188
10695
|
// ../../build/common/esm/document/resource/singleton.js
|
|
10189
|
-
import
|
|
10190
|
-
|
|
10191
|
-
// ../../build/common/esm/document/decorators/singleton.decorator.js
|
|
10192
|
-
function SingletonDecorator(type, options) {
|
|
10193
|
-
return ResourceDecorator(opra_schema_ns_exports.Singleton.Kind, { ...options, type });
|
|
10194
|
-
}
|
|
10195
|
-
__name(SingletonDecorator, "SingletonDecorator");
|
|
10196
|
-
Object.assign(SingletonDecorator, ResourceDecorator);
|
|
10197
|
-
SingletonDecorator.Create = createOperationDecorator2("create");
|
|
10198
|
-
SingletonDecorator.Get = createOperationDecorator2("get");
|
|
10199
|
-
SingletonDecorator.Delete = createOperationDecorator2("delete");
|
|
10200
|
-
SingletonDecorator.Update = createOperationDecorator2("update");
|
|
10201
|
-
SingletonDecorator.Action = function(options) {
|
|
10202
|
-
const oldDecorator = ResourceDecorator.Action(options);
|
|
10203
|
-
const operators = ["create", "delete", "get", "update"];
|
|
10204
|
-
return (target, propertyKey) => {
|
|
10205
|
-
if (typeof propertyKey === "string" && operators.includes(propertyKey))
|
|
10206
|
-
throw new TypeError(`The "${propertyKey}" property is reserved for "${propertyKey}" operations and cannot be used as an action'`);
|
|
10207
|
-
return oldDecorator(target, propertyKey);
|
|
10208
|
-
};
|
|
10209
|
-
};
|
|
10210
|
-
function createOperationDecorator2(operation) {
|
|
10211
|
-
return (options) => (target, propertyKey) => {
|
|
10212
|
-
if (propertyKey !== operation)
|
|
10213
|
-
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
10214
|
-
const operationMeta = { ...options };
|
|
10215
|
-
const sourceMetadata = Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {};
|
|
10216
|
-
sourceMetadata.operations = sourceMetadata.operations || {};
|
|
10217
|
-
sourceMetadata.operations[operation] = operationMeta;
|
|
10218
|
-
Reflect.defineMetadata(RESOURCE_METADATA, sourceMetadata, target.constructor);
|
|
10219
|
-
};
|
|
10220
|
-
}
|
|
10221
|
-
__name(createOperationDecorator2, "createOperationDecorator");
|
|
10696
|
+
import merge11 from "putil-merge";
|
|
10222
10697
|
|
|
10223
10698
|
// ../../build/common/esm/document/resource/singleton-class.js
|
|
10224
|
-
var SingletonClass = class extends
|
|
10699
|
+
var SingletonClass = class extends CrudResource {
|
|
10225
10700
|
static {
|
|
10226
10701
|
__name(this, "SingletonClass");
|
|
10227
10702
|
}
|
|
10228
|
-
constructor(
|
|
10229
|
-
super(
|
|
10230
|
-
this._decoders = {};
|
|
10231
|
-
this._encoders = {};
|
|
10703
|
+
constructor(parent, init) {
|
|
10704
|
+
super(parent, init);
|
|
10232
10705
|
this.kind = opra_schema_ns_exports.Singleton.Kind;
|
|
10233
|
-
this.controller = init.controller;
|
|
10234
|
-
this.operations = { ...init.operations };
|
|
10235
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
|
+
}
|
|
10236
10752
|
}
|
|
10237
|
-
|
|
10753
|
+
getOperation(name) {
|
|
10754
|
+
return super.getOperation(name);
|
|
10755
|
+
}
|
|
10756
|
+
exportSchema(options) {
|
|
10238
10757
|
return {
|
|
10239
|
-
...super.exportSchema(),
|
|
10240
|
-
|
|
10241
|
-
type: this.type.name || "any",
|
|
10242
|
-
operations: this.operations
|
|
10243
|
-
})
|
|
10758
|
+
...super.exportSchema(options),
|
|
10759
|
+
type: this.type.name || "any"
|
|
10244
10760
|
};
|
|
10245
10761
|
}
|
|
10246
10762
|
normalizeFieldPath(path2) {
|
|
10247
10763
|
return this.type.normalizeFieldPath(path2);
|
|
10248
10764
|
}
|
|
10249
|
-
getDecoder(endpoint) {
|
|
10250
|
-
let decoder = this._decoders[endpoint];
|
|
10251
|
-
if (decoder)
|
|
10252
|
-
return decoder;
|
|
10253
|
-
const options = {
|
|
10254
|
-
partial: endpoint !== "create"
|
|
10255
|
-
};
|
|
10256
|
-
decoder = generateCodec(this.type, "decode", options);
|
|
10257
|
-
this._decoders[endpoint] = decoder;
|
|
10258
|
-
return decoder;
|
|
10259
|
-
}
|
|
10260
|
-
getEncoder(endpoint) {
|
|
10261
|
-
let encoder = this._encoders[endpoint];
|
|
10262
|
-
if (encoder)
|
|
10263
|
-
return encoder;
|
|
10264
|
-
const options = {
|
|
10265
|
-
partial: true
|
|
10266
|
-
};
|
|
10267
|
-
encoder = generateCodec(this.type, "encode", options);
|
|
10268
|
-
this._encoders[endpoint] = encoder;
|
|
10269
|
-
return encoder;
|
|
10270
|
-
}
|
|
10271
10765
|
};
|
|
10272
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
|
+
|
|
10273
10809
|
// ../../build/common/esm/document/resource/singleton.js
|
|
10274
10810
|
var Singleton2 = /* @__PURE__ */ __name(function(...args) {
|
|
10275
10811
|
if (!this) {
|
|
10276
10812
|
const [type, options] = args;
|
|
10277
10813
|
return Singleton2[DECORATOR].call(void 0, type, options);
|
|
10278
10814
|
}
|
|
10279
|
-
const [
|
|
10280
|
-
|
|
10815
|
+
const [parent, init] = args;
|
|
10816
|
+
merge11(this, new SingletonClass(parent, init), { descriptor: true });
|
|
10281
10817
|
}, "Singleton");
|
|
10282
10818
|
Singleton2.prototype = SingletonClass.prototype;
|
|
10283
10819
|
Object.assign(Singleton2, SingletonDecorator);
|
|
10284
10820
|
Singleton2[DECORATOR] = SingletonDecorator;
|
|
10285
10821
|
|
|
10286
10822
|
// ../../build/common/esm/document/resource/storage.js
|
|
10287
|
-
import
|
|
10288
|
-
|
|
10289
|
-
// ../../build/common/esm/document/decorators/storage.decorator.js
|
|
10290
|
-
function StorageDecorator(options) {
|
|
10291
|
-
return ResourceDecorator(opra_schema_ns_exports.Storage.Kind, options);
|
|
10292
|
-
}
|
|
10293
|
-
__name(StorageDecorator, "StorageDecorator");
|
|
10294
|
-
Object.assign(StorageDecorator, ResourceDecorator);
|
|
10295
|
-
StorageDecorator.Delete = createOperationDecorator3("delete");
|
|
10296
|
-
StorageDecorator.Get = createOperationDecorator3("get");
|
|
10297
|
-
StorageDecorator.Post = createOperationDecorator3("post");
|
|
10298
|
-
StorageDecorator.Action = function(options) {
|
|
10299
|
-
const oldDecorator = ResourceDecorator.Action(options);
|
|
10300
|
-
const operators = ["delete", "get", "post"];
|
|
10301
|
-
return (target, propertyKey) => {
|
|
10302
|
-
if (typeof propertyKey === "string" && operators.includes(propertyKey))
|
|
10303
|
-
throw new TypeError(`The "${propertyKey}" property is reserved for "${propertyKey}" operations and cannot be used as an action'`);
|
|
10304
|
-
return oldDecorator(target, propertyKey);
|
|
10305
|
-
};
|
|
10306
|
-
};
|
|
10307
|
-
function createOperationDecorator3(operation) {
|
|
10308
|
-
return (options) => (target, propertyKey) => {
|
|
10309
|
-
if (propertyKey !== operation)
|
|
10310
|
-
throw new TypeError(`Name of the handler name should be '${operation}'`);
|
|
10311
|
-
const operationMeta = { ...options };
|
|
10312
|
-
const sourceMetadata = Reflect.getOwnMetadata(RESOURCE_METADATA, target.constructor) || {};
|
|
10313
|
-
sourceMetadata.operations = sourceMetadata.operations || {};
|
|
10314
|
-
sourceMetadata.operations[operation] = operationMeta;
|
|
10315
|
-
Reflect.defineMetadata(RESOURCE_METADATA, sourceMetadata, target.constructor);
|
|
10316
|
-
};
|
|
10317
|
-
}
|
|
10318
|
-
__name(createOperationDecorator3, "createOperationDecorator");
|
|
10823
|
+
import merge12 from "putil-merge";
|
|
10319
10824
|
|
|
10320
10825
|
// ../../build/common/esm/document/resource/storage-class.js
|
|
10321
|
-
var StorageClass = class extends
|
|
10826
|
+
var StorageClass = class extends CrudResource {
|
|
10322
10827
|
static {
|
|
10323
10828
|
__name(this, "StorageClass");
|
|
10324
10829
|
}
|
|
10325
|
-
constructor(
|
|
10326
|
-
super(
|
|
10830
|
+
constructor(parent, init) {
|
|
10831
|
+
super(parent, init);
|
|
10327
10832
|
this.kind = opra_schema_ns_exports.Storage.Kind;
|
|
10328
|
-
this.controller = init.controller;
|
|
10329
|
-
this.operations = { ...init.operations };
|
|
10330
10833
|
}
|
|
10331
|
-
|
|
10332
|
-
return
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10336
|
-
operations: this.operations
|
|
10337
|
-
})
|
|
10338
|
-
};
|
|
10834
|
+
getOperation(name) {
|
|
10835
|
+
return super.getOperation(name);
|
|
10836
|
+
}
|
|
10837
|
+
exportSchema(options) {
|
|
10838
|
+
return super.exportSchema(options);
|
|
10339
10839
|
}
|
|
10340
10840
|
};
|
|
10341
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
|
+
|
|
10342
10901
|
// ../../build/common/esm/document/resource/storage.js
|
|
10343
10902
|
var Storage2 = /* @__PURE__ */ __name(function(...args) {
|
|
10344
10903
|
if (!this) {
|
|
10345
10904
|
const [options] = args;
|
|
10346
10905
|
return Storage2[DECORATOR].call(void 0, options);
|
|
10347
10906
|
}
|
|
10348
|
-
const [
|
|
10349
|
-
|
|
10907
|
+
const [parent, init] = args;
|
|
10908
|
+
merge12(this, new StorageClass(parent, init), { descriptor: true });
|
|
10350
10909
|
}, "Storage");
|
|
10351
10910
|
Storage2.prototype = StorageClass.prototype;
|
|
10352
10911
|
Object.assign(Storage2, StorageDecorator);
|
|
10353
10912
|
Storage2[DECORATOR] = StorageDecorator;
|
|
10354
10913
|
|
|
10355
|
-
// ../../build/common/esm/document/factory/
|
|
10356
|
-
|
|
10357
|
-
|
|
10358
|
-
|
|
10359
|
-
for (const name of sourceNames) {
|
|
10360
|
-
const schema = sourceQueue.get(name);
|
|
10361
|
-
if (!schema)
|
|
10362
|
-
continue;
|
|
10363
|
-
try {
|
|
10364
|
-
if (opra_schema_ns_exports.isCollection(schema)) {
|
|
10365
|
-
const resource = await this.createCollectionSource(name, schema);
|
|
10366
|
-
document.resources.set(name, resource);
|
|
10367
|
-
continue;
|
|
10368
|
-
}
|
|
10369
|
-
if (opra_schema_ns_exports.isSingleton(schema)) {
|
|
10370
|
-
const resource = await this.createSingletonSource(name, schema);
|
|
10371
|
-
document.resources.set(name, resource);
|
|
10372
|
-
continue;
|
|
10373
|
-
}
|
|
10374
|
-
if (opra_schema_ns_exports.isStorage(schema)) {
|
|
10375
|
-
const resource = await this.createFileSource(name, schema);
|
|
10376
|
-
document.resources.set(name, resource);
|
|
10377
|
-
continue;
|
|
10378
|
-
}
|
|
10379
|
-
} catch (e) {
|
|
10380
|
-
e.message = `Error in Resource schema (${name}): ` + e.message;
|
|
10381
|
-
throw e;
|
|
10382
|
-
}
|
|
10383
|
-
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");
|
|
10384
10918
|
}
|
|
10385
|
-
|
|
10386
|
-
|
|
10387
|
-
|
|
10388
|
-
const { document } = this;
|
|
10389
|
-
const dataType = document.getComplexType(schema.type);
|
|
10390
|
-
const initArgs = {
|
|
10391
|
-
...schema,
|
|
10392
|
-
name,
|
|
10393
|
-
type: dataType
|
|
10394
|
-
};
|
|
10395
|
-
return new Collection2(document, initArgs);
|
|
10396
|
-
}
|
|
10397
|
-
__name(createCollectionResource, "createCollectionResource");
|
|
10398
|
-
async function createSingletonResource(name, schema) {
|
|
10399
|
-
const { document } = this;
|
|
10400
|
-
const dataType = document.getComplexType(schema.type);
|
|
10401
|
-
const initArgs = {
|
|
10402
|
-
...schema,
|
|
10403
|
-
name,
|
|
10404
|
-
type: dataType
|
|
10405
|
-
};
|
|
10406
|
-
return new Singleton2(document, initArgs);
|
|
10407
|
-
}
|
|
10408
|
-
__name(createSingletonResource, "createSingletonResource");
|
|
10409
|
-
async function createStorageResource(name, schema) {
|
|
10410
|
-
const { document } = this;
|
|
10411
|
-
const initArgs = {
|
|
10412
|
-
...schema,
|
|
10413
|
-
name
|
|
10414
|
-
};
|
|
10415
|
-
return new Storage2(document, initArgs);
|
|
10416
|
-
}
|
|
10417
|
-
__name(createStorageResource, "createStorageResource");
|
|
10418
|
-
|
|
10419
|
-
// ../../build/common/esm/document/factory/process-types.js
|
|
10420
|
-
async function processTypes() {
|
|
10421
|
-
const { document, typeQueue } = this;
|
|
10422
|
-
for (const [name, schema] of typeQueue.entries()) {
|
|
10423
|
-
const dataType = this.createDataTypeInstance(schema.kind, name);
|
|
10424
|
-
document.types.set(name, dataType);
|
|
10425
|
-
}
|
|
10426
|
-
const typeNames = Array.from(typeQueue.keys());
|
|
10427
|
-
for (const name of typeNames) {
|
|
10428
|
-
if (!typeQueue.has(name))
|
|
10429
|
-
continue;
|
|
10430
|
-
this.addDataType(name);
|
|
10919
|
+
constructor() {
|
|
10920
|
+
super(...arguments);
|
|
10921
|
+
this.resourceQueue = new ResponsiveMap();
|
|
10431
10922
|
}
|
|
10432
|
-
|
|
10433
|
-
|
|
10434
|
-
|
|
10435
|
-
|
|
10436
|
-
|
|
10437
|
-
|
|
10438
|
-
|
|
10439
|
-
|
|
10440
|
-
|
|
10441
|
-
switch (kind) {
|
|
10442
|
-
case opra_schema_ns_exports.ComplexType.Kind:
|
|
10443
|
-
Object.setPrototypeOf(dataType, ComplexType2.prototype);
|
|
10444
|
-
break;
|
|
10445
|
-
case opra_schema_ns_exports.EnumType.Kind:
|
|
10446
|
-
Object.setPrototypeOf(dataType, EnumType2.prototype);
|
|
10447
|
-
break;
|
|
10448
|
-
case opra_schema_ns_exports.MappedType.Kind:
|
|
10449
|
-
Object.setPrototypeOf(dataType, MappedType2.prototype);
|
|
10450
|
-
break;
|
|
10451
|
-
case opra_schema_ns_exports.SimpleType.Kind:
|
|
10452
|
-
Object.setPrototypeOf(dataType, SimpleType2.prototype);
|
|
10453
|
-
break;
|
|
10454
|
-
case opra_schema_ns_exports.UnionType.Kind:
|
|
10455
|
-
Object.setPrototypeOf(dataType, UnionType2.prototype);
|
|
10456
|
-
break;
|
|
10457
|
-
default:
|
|
10458
|
-
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;
|
|
10459
10932
|
}
|
|
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
|
-
|
|
10498
|
-
|
|
10499
|
-
|
|
10500
|
-
|
|
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 {
|
|
10501
10994
|
...schema,
|
|
10995
|
+
kind: schema.kind,
|
|
10502
10996
|
name,
|
|
10503
|
-
|
|
10997
|
+
type: await this.importDataType(schema.type),
|
|
10998
|
+
actions: await convertEndpoints(schema.actions),
|
|
10999
|
+
operations: await convertEndpoints(schema.operations)
|
|
10504
11000
|
};
|
|
10505
|
-
|
|
10506
|
-
|
|
10507
|
-
curPath.push(name);
|
|
10508
|
-
ComplexType2.apply(dataType, [document, initArgs]);
|
|
10509
|
-
if (name)
|
|
10510
|
-
typeQueue.delete(name);
|
|
10511
|
-
if (schema.fields) {
|
|
10512
|
-
for (const [elemName, v] of Object.entries(schema.fields)) {
|
|
10513
|
-
const elemSchema = typeof v === "object" ? v : { type: v };
|
|
10514
|
-
curPath.push(`${name}.${elemName}[type]`);
|
|
10515
|
-
const elemType = this.addDataType(elemSchema.type);
|
|
10516
|
-
dataType.addField({
|
|
10517
|
-
...elemSchema,
|
|
10518
|
-
name: elemName,
|
|
10519
|
-
type: elemType
|
|
10520
|
-
});
|
|
10521
|
-
curPath.pop();
|
|
10522
|
-
}
|
|
10523
|
-
}
|
|
10524
|
-
if (name)
|
|
10525
|
-
curPath.pop();
|
|
10526
|
-
return dataType;
|
|
10527
|
-
}
|
|
10528
|
-
if (opra_schema_ns_exports.isEnumType(schema)) {
|
|
10529
|
-
const initArgs = {
|
|
11001
|
+
} else if (schema.kind === "Singleton") {
|
|
11002
|
+
return {
|
|
10530
11003
|
...schema,
|
|
11004
|
+
kind: schema.kind,
|
|
10531
11005
|
name,
|
|
10532
|
-
|
|
11006
|
+
type: await this.importDataType(schema.type),
|
|
11007
|
+
actions: await convertEndpoints(schema.actions),
|
|
11008
|
+
operations: await convertEndpoints(schema.operations)
|
|
10533
11009
|
};
|
|
10534
|
-
|
|
10535
|
-
|
|
10536
|
-
curPath.push(name);
|
|
10537
|
-
EnumType2.apply(dataType, [document, initArgs]);
|
|
10538
|
-
if (name)
|
|
10539
|
-
curPath.pop();
|
|
10540
|
-
return dataType;
|
|
10541
|
-
}
|
|
10542
|
-
if (opra_schema_ns_exports.isUnionType(schema)) {
|
|
10543
|
-
const unionTypes = schema.types.map((t) => this.addDataType(t));
|
|
10544
|
-
const initArgs = {
|
|
11010
|
+
} else if (schema.kind === "Storage") {
|
|
11011
|
+
return {
|
|
10545
11012
|
...schema,
|
|
10546
11013
|
name,
|
|
10547
|
-
|
|
11014
|
+
actions: await convertEndpoints(schema.actions),
|
|
11015
|
+
operations: await convertEndpoints(schema.operations)
|
|
10548
11016
|
};
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
|
|
10554
|
-
|
|
10555
|
-
|
|
10556
|
-
|
|
10557
|
-
|
|
10558
|
-
const dt = this.addDataType(schema.type);
|
|
10559
|
-
if (!(dt instanceof ComplexType2))
|
|
10560
|
-
throw new TypeError(`MappedType requires a ComplexType`);
|
|
10561
|
-
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 {
|
|
10562
11026
|
...schema,
|
|
10563
11027
|
name,
|
|
10564
|
-
|
|
11028
|
+
resources,
|
|
11029
|
+
actions: await convertEndpoints(schema.actions)
|
|
10565
11030
|
};
|
|
10566
|
-
dataType = dataType || this.createDataTypeInstance(schema.kind, name);
|
|
10567
|
-
if (name)
|
|
10568
|
-
curPath.push(name);
|
|
10569
|
-
MappedType2.apply(dataType, [document, initArgs]);
|
|
10570
|
-
if (name)
|
|
10571
|
-
curPath.pop();
|
|
10572
|
-
return dataType;
|
|
10573
|
-
}
|
|
10574
|
-
} catch (e) {
|
|
10575
|
-
if (curPath.length)
|
|
10576
|
-
e.message = `Error at ${curPath.join("/")}: ` + e.message;
|
|
10577
|
-
throw e;
|
|
10578
|
-
} finally {
|
|
10579
|
-
if (name) {
|
|
10580
|
-
circularRefs.delete(name);
|
|
10581
|
-
typeQueue.delete(name);
|
|
10582
11031
|
}
|
|
11032
|
+
throw new TypeError(`Can not import resource schema (${schema.kind})`);
|
|
10583
11033
|
}
|
|
10584
|
-
|
|
10585
|
-
|
|
10586
|
-
|
|
10587
|
-
|
|
10588
|
-
|
|
10589
|
-
|
|
10590
|
-
|
|
10591
|
-
|
|
10592
|
-
|
|
10593
|
-
|
|
10594
|
-
|
|
10595
|
-
|
|
10596
|
-
|
|
10597
|
-
|
|
10598
|
-
|
|
10599
|
-
|
|
10600
|
-
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
|
|
10604
|
-
|
|
10605
|
-
|
|
10606
|
-
|
|
10607
|
-
|
|
10608
|
-
|
|
10609
|
-
|
|
10610
|
-
|
|
10611
|
-
|
|
10612
|
-
|
|
10613
|
-
|
|
10614
|
-
|
|
10615
|
-
|
|
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}`);
|
|
10616
11119
|
}
|
|
10617
11120
|
};
|
|
10618
|
-
_a2 = DocumentFactory;
|
|
10619
|
-
DocumentFactory.designTypeMap = /* @__PURE__ */ new Map();
|
|
10620
|
-
(() => {
|
|
10621
|
-
_a2.prototype.createDocument = createDocument;
|
|
10622
|
-
_a2.prototype.createDocumentFromUrl = createDocumentFromUrl;
|
|
10623
|
-
_a2.prototype.createBuiltinTypeDocument = createBuiltinTypeDocument;
|
|
10624
|
-
_a2.prototype.addReferences = addReferences;
|
|
10625
|
-
_a2.prototype.importTypeClass = importTypeClass;
|
|
10626
|
-
_a2.prototype.extractSimpleTypeSchema = extractSimpleTypeSchema;
|
|
10627
|
-
_a2.prototype.extractComplexTypeSchema = extractComplexTypeSchema;
|
|
10628
|
-
_a2.prototype.extractMappedTypeSchema = extractMappedTypeSchema;
|
|
10629
|
-
_a2.prototype.extractUnionTypeSchema = extractUnionTypeSchema;
|
|
10630
|
-
_a2.prototype.extractEnumTypeSchema = extractEnumTypeSchema;
|
|
10631
|
-
_a2.prototype.extractFieldSchema = extractFieldSchema;
|
|
10632
|
-
_a2.prototype.processTypes = processTypes;
|
|
10633
|
-
_a2.prototype.createDataTypeInstance = createDataTypeInstance;
|
|
10634
|
-
_a2.prototype.addDataType = addDataType;
|
|
10635
|
-
_a2.prototype.importSourceClass = importResourceClass;
|
|
10636
|
-
_a2.prototype.extractSingletonSchema = extractSingletonSchema;
|
|
10637
|
-
_a2.prototype.extractCollectionSchema = extractCollectionSchema;
|
|
10638
|
-
_a2.prototype.processSourceQueue = processSourceQueue;
|
|
10639
|
-
_a2.prototype.createCollectionSource = createCollectionResource;
|
|
10640
|
-
_a2.prototype.createSingletonSource = createSingletonResource;
|
|
10641
|
-
_a2.prototype.createFileSource = createStorageResource;
|
|
10642
|
-
})();
|
|
10643
11121
|
|
|
10644
11122
|
// ../../build/common/esm/http/opra-url.js
|
|
10645
11123
|
import { splitString as splitString3, tokenize as tokenize3 } from "fast-tokenizer";
|
|
@@ -10647,7 +11125,7 @@ import { splitString as splitString3, tokenize as tokenize3 } from "fast-tokeniz
|
|
|
10647
11125
|
// ../../build/common/esm/http/opra-url-path.js
|
|
10648
11126
|
import { splitString as splitString2, tokenize as tokenize2 } from "fast-tokenizer";
|
|
10649
11127
|
import isPlainObject2 from "putil-isplainobject";
|
|
10650
|
-
var
|
|
11128
|
+
var _a2;
|
|
10651
11129
|
var nodeInspectCustom2 = Symbol.for("nodejs.util.inspect.custom");
|
|
10652
11130
|
var kLength = Symbol.for("kLength");
|
|
10653
11131
|
var pathComponentRegEx = /^([^/?#:@]+)(?:@([^/?#:]*))?(?:::(.*))?$/;
|
|
@@ -10658,12 +11136,15 @@ var OpraURLPath = class _OpraURLPath {
|
|
|
10658
11136
|
__name(this, "OpraURLPath");
|
|
10659
11137
|
}
|
|
10660
11138
|
constructor(...init) {
|
|
10661
|
-
this[
|
|
11139
|
+
this[_a2] = 0;
|
|
10662
11140
|
this._resolve(init.filter((x) => x));
|
|
10663
11141
|
}
|
|
10664
11142
|
get length() {
|
|
10665
11143
|
return this[kLength];
|
|
10666
11144
|
}
|
|
11145
|
+
slice(start, end) {
|
|
11146
|
+
return new _OpraURLPath(...[...this].slice(start, end));
|
|
11147
|
+
}
|
|
10667
11148
|
resolve(...items) {
|
|
10668
11149
|
this._resolve(items);
|
|
10669
11150
|
return this;
|
|
@@ -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,
|