@smithy/core 3.40.0 → 3.41.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/CHANGELOG.md +10 -0
- package/dist-cjs/submodules/protocols/index.js +600 -328
- package/dist-cjs/submodules/serde/index.browser.js +9 -4
- package/dist-cjs/submodules/serde/index.js +9 -4
- package/dist-cjs/submodules/serde/index.native.js +9 -4
- package/dist-es/submodules/protocols/HttpBindingNormalizedSchema.js +215 -0
- package/dist-es/submodules/protocols/HttpBindingProtocol.js +223 -195
- package/dist-es/submodules/protocols/HttpProtocol.js +22 -23
- package/dist-es/submodules/protocols/extended-encode-uri-component.js +3 -0
- package/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +54 -47
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeDeserializer.js +23 -18
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeSerializer.js +12 -5
- package/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js +33 -27
- package/dist-es/submodules/protocols/serde/determineTimestampFormat.js +5 -5
- package/dist-es/submodules/serde/quote-header.js +1 -1
- package/dist-es/submodules/serde/schema-serde-lib/schema-date-utils.js +4 -0
- package/dist-es/submodules/serde/split-header.js +4 -3
- package/dist-types/submodules/protocols/HttpBindingNormalizedSchema.d.ts +75 -0
- package/dist-types/submodules/protocols/HttpBindingProtocol.d.ts +11 -8
- package/dist-types/submodules/protocols/HttpProtocol.d.ts +2 -2
- package/dist-types/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +2 -1
- package/dist-types/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +4 -0
- package/dist-types/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +3 -0
- package/dist-types/submodules/protocols/serde/ToStringShapeSerializer.d.ts +2 -0
- package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +1 -1
- package/dist-types/ts3.4/submodules/protocols/HttpBindingNormalizedSchema.d.ts +81 -0
- package/dist-types/ts3.4/submodules/protocols/HttpBindingProtocol.d.ts +11 -8
- package/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +1 -1
- package/dist-types/ts3.4/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +2 -1
- package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +4 -0
- package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +3 -0
- package/dist-types/ts3.4/submodules/protocols/serde/ToStringShapeSerializer.d.ts +2 -0
- package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +1 -1
- package/package.json +1 -1
|
@@ -607,7 +607,7 @@ LazyJsonString.fromObject = LazyJsonString.from;
|
|
|
607
607
|
|
|
608
608
|
function quoteHeader(part) {
|
|
609
609
|
if (part.includes(",") || part.includes('"')) {
|
|
610
|
-
part = `"${part.replace(/"/g, '\\"')}"`;
|
|
610
|
+
part = `"${part.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
611
611
|
}
|
|
612
612
|
return part;
|
|
613
613
|
}
|
|
@@ -618,6 +618,7 @@ const time = `(\\d?\\d):(\\d{2}):(\\d{2})(?:\\.(\\d+))?`;
|
|
|
618
618
|
const date = `(\\d?\\d)`;
|
|
619
619
|
const year = `(\\d{4})`;
|
|
620
620
|
const RFC3339_WITH_OFFSET = new RegExp(/^(\d{4})-(\d\d)-(\d\d)[tT](\d\d):(\d\d):(\d\d)(\.(\d+))?(([-+]\d\d:\d\d)|[zZ])$/);
|
|
621
|
+
const IMF_FIXDATE_NATIVE = /^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (?:0[1-9]|[12]\d|3[01]) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [1-9]\d{3} (?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d GMT$/;
|
|
621
622
|
const IMF_FIXDATE = new RegExp(`^${ddd}, ${date} ${mmm} ${year} ${time} GMT$`);
|
|
622
623
|
const RFC_850_DATE = new RegExp(`^${ddd}, ${date}-${mmm}-(\\d\\d) ${time} GMT$`);
|
|
623
624
|
const ASC_TIME = new RegExp(`^${ddd} ${mmm} ( [1-9]|\\d\\d) ${time} ${year}$`);
|
|
@@ -677,6 +678,9 @@ const _parseRfc7231DateTime = (value) => {
|
|
|
677
678
|
if (typeof value !== "string") {
|
|
678
679
|
throw new TypeError("RFC7231 timestamps must be strings.");
|
|
679
680
|
}
|
|
681
|
+
if (IMF_FIXDATE_NATIVE.test(value)) {
|
|
682
|
+
return new Date(value);
|
|
683
|
+
}
|
|
680
684
|
let day;
|
|
681
685
|
let month;
|
|
682
686
|
let year;
|
|
@@ -746,13 +750,13 @@ const splitHeader = (value) => {
|
|
|
746
750
|
const z = value.length;
|
|
747
751
|
const values = [];
|
|
748
752
|
let withinQuotes = false;
|
|
749
|
-
let
|
|
753
|
+
let escaped = false;
|
|
750
754
|
let anchor = 0;
|
|
751
755
|
for (let i = 0; i < z; ++i) {
|
|
752
756
|
const char = value[i];
|
|
753
757
|
switch (char) {
|
|
754
758
|
case `"`:
|
|
755
|
-
if (
|
|
759
|
+
if (!escaped) {
|
|
756
760
|
withinQuotes = !withinQuotes;
|
|
757
761
|
}
|
|
758
762
|
break;
|
|
@@ -763,7 +767,7 @@ const splitHeader = (value) => {
|
|
|
763
767
|
}
|
|
764
768
|
break;
|
|
765
769
|
}
|
|
766
|
-
|
|
770
|
+
escaped = char === "\\" && !escaped;
|
|
767
771
|
}
|
|
768
772
|
values.push(value.slice(anchor));
|
|
769
773
|
return values.map((v) => {
|
|
@@ -774,6 +778,7 @@ const splitHeader = (value) => {
|
|
|
774
778
|
}
|
|
775
779
|
if (v[0] === `"` && v[z - 1] === `"`) {
|
|
776
780
|
v = v.slice(1, z - 1);
|
|
781
|
+
return v.replace(/\\(["\\])/g, "$1");
|
|
777
782
|
}
|
|
778
783
|
return v.replace(/\\"/g, '"');
|
|
779
784
|
});
|
|
@@ -575,7 +575,7 @@ LazyJsonString.fromObject = LazyJsonString.from;
|
|
|
575
575
|
|
|
576
576
|
function quoteHeader(part) {
|
|
577
577
|
if (part.includes(",") || part.includes('"')) {
|
|
578
|
-
part = `"${part.replace(/"/g, '\\"')}"`;
|
|
578
|
+
part = `"${part.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
579
579
|
}
|
|
580
580
|
return part;
|
|
581
581
|
}
|
|
@@ -586,6 +586,7 @@ const time = `(\\d?\\d):(\\d{2}):(\\d{2})(?:\\.(\\d+))?`;
|
|
|
586
586
|
const date = `(\\d?\\d)`;
|
|
587
587
|
const year = `(\\d{4})`;
|
|
588
588
|
const RFC3339_WITH_OFFSET = new RegExp(/^(\d{4})-(\d\d)-(\d\d)[tT](\d\d):(\d\d):(\d\d)(\.(\d+))?(([-+]\d\d:\d\d)|[zZ])$/);
|
|
589
|
+
const IMF_FIXDATE_NATIVE = /^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (?:0[1-9]|[12]\d|3[01]) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [1-9]\d{3} (?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d GMT$/;
|
|
589
590
|
const IMF_FIXDATE = new RegExp(`^${ddd}, ${date} ${mmm} ${year} ${time} GMT$`);
|
|
590
591
|
const RFC_850_DATE = new RegExp(`^${ddd}, ${date}-${mmm}-(\\d\\d) ${time} GMT$`);
|
|
591
592
|
const ASC_TIME = new RegExp(`^${ddd} ${mmm} ( [1-9]|\\d\\d) ${time} ${year}$`);
|
|
@@ -645,6 +646,9 @@ const _parseRfc7231DateTime = (value) => {
|
|
|
645
646
|
if (typeof value !== "string") {
|
|
646
647
|
throw new TypeError("RFC7231 timestamps must be strings.");
|
|
647
648
|
}
|
|
649
|
+
if (IMF_FIXDATE_NATIVE.test(value)) {
|
|
650
|
+
return new Date(value);
|
|
651
|
+
}
|
|
648
652
|
let day;
|
|
649
653
|
let month;
|
|
650
654
|
let year;
|
|
@@ -714,13 +718,13 @@ const splitHeader = (value) => {
|
|
|
714
718
|
const z = value.length;
|
|
715
719
|
const values = [];
|
|
716
720
|
let withinQuotes = false;
|
|
717
|
-
let
|
|
721
|
+
let escaped = false;
|
|
718
722
|
let anchor = 0;
|
|
719
723
|
for (let i = 0; i < z; ++i) {
|
|
720
724
|
const char = value[i];
|
|
721
725
|
switch (char) {
|
|
722
726
|
case `"`:
|
|
723
|
-
if (
|
|
727
|
+
if (!escaped) {
|
|
724
728
|
withinQuotes = !withinQuotes;
|
|
725
729
|
}
|
|
726
730
|
break;
|
|
@@ -731,7 +735,7 @@ const splitHeader = (value) => {
|
|
|
731
735
|
}
|
|
732
736
|
break;
|
|
733
737
|
}
|
|
734
|
-
|
|
738
|
+
escaped = char === "\\" && !escaped;
|
|
735
739
|
}
|
|
736
740
|
values.push(value.slice(anchor));
|
|
737
741
|
return values.map((v) => {
|
|
@@ -742,6 +746,7 @@ const splitHeader = (value) => {
|
|
|
742
746
|
}
|
|
743
747
|
if (v[0] === `"` && v[z - 1] === `"`) {
|
|
744
748
|
v = v.slice(1, z - 1);
|
|
749
|
+
return v.replace(/\\(["\\])/g, "$1");
|
|
745
750
|
}
|
|
746
751
|
return v.replace(/\\"/g, '"');
|
|
747
752
|
});
|
|
@@ -607,7 +607,7 @@ LazyJsonString.fromObject = LazyJsonString.from;
|
|
|
607
607
|
|
|
608
608
|
function quoteHeader(part) {
|
|
609
609
|
if (part.includes(",") || part.includes('"')) {
|
|
610
|
-
part = `"${part.replace(/"/g, '\\"')}"`;
|
|
610
|
+
part = `"${part.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
611
611
|
}
|
|
612
612
|
return part;
|
|
613
613
|
}
|
|
@@ -618,6 +618,7 @@ const time = `(\\d?\\d):(\\d{2}):(\\d{2})(?:\\.(\\d+))?`;
|
|
|
618
618
|
const date = `(\\d?\\d)`;
|
|
619
619
|
const year = `(\\d{4})`;
|
|
620
620
|
const RFC3339_WITH_OFFSET = new RegExp(/^(\d{4})-(\d\d)-(\d\d)[tT](\d\d):(\d\d):(\d\d)(\.(\d+))?(([-+]\d\d:\d\d)|[zZ])$/);
|
|
621
|
+
const IMF_FIXDATE_NATIVE = /^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (?:0[1-9]|[12]\d|3[01]) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [1-9]\d{3} (?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d GMT$/;
|
|
621
622
|
const IMF_FIXDATE = new RegExp(`^${ddd}, ${date} ${mmm} ${year} ${time} GMT$`);
|
|
622
623
|
const RFC_850_DATE = new RegExp(`^${ddd}, ${date}-${mmm}-(\\d\\d) ${time} GMT$`);
|
|
623
624
|
const ASC_TIME = new RegExp(`^${ddd} ${mmm} ( [1-9]|\\d\\d) ${time} ${year}$`);
|
|
@@ -677,6 +678,9 @@ const _parseRfc7231DateTime = (value) => {
|
|
|
677
678
|
if (typeof value !== "string") {
|
|
678
679
|
throw new TypeError("RFC7231 timestamps must be strings.");
|
|
679
680
|
}
|
|
681
|
+
if (IMF_FIXDATE_NATIVE.test(value)) {
|
|
682
|
+
return new Date(value);
|
|
683
|
+
}
|
|
680
684
|
let day;
|
|
681
685
|
let month;
|
|
682
686
|
let year;
|
|
@@ -746,13 +750,13 @@ const splitHeader = (value) => {
|
|
|
746
750
|
const z = value.length;
|
|
747
751
|
const values = [];
|
|
748
752
|
let withinQuotes = false;
|
|
749
|
-
let
|
|
753
|
+
let escaped = false;
|
|
750
754
|
let anchor = 0;
|
|
751
755
|
for (let i = 0; i < z; ++i) {
|
|
752
756
|
const char = value[i];
|
|
753
757
|
switch (char) {
|
|
754
758
|
case `"`:
|
|
755
|
-
if (
|
|
759
|
+
if (!escaped) {
|
|
756
760
|
withinQuotes = !withinQuotes;
|
|
757
761
|
}
|
|
758
762
|
break;
|
|
@@ -763,7 +767,7 @@ const splitHeader = (value) => {
|
|
|
763
767
|
}
|
|
764
768
|
break;
|
|
765
769
|
}
|
|
766
|
-
|
|
770
|
+
escaped = char === "\\" && !escaped;
|
|
767
771
|
}
|
|
768
772
|
values.push(value.slice(anchor));
|
|
769
773
|
return values.map((v) => {
|
|
@@ -774,6 +778,7 @@ const splitHeader = (value) => {
|
|
|
774
778
|
}
|
|
775
779
|
if (v[0] === `"` && v[z - 1] === `"`) {
|
|
776
780
|
v = v.slice(1, z - 1);
|
|
781
|
+
return v.replace(/\\(["\\])/g, "$1");
|
|
777
782
|
}
|
|
778
783
|
return v.replace(/\\"/g, '"');
|
|
779
784
|
});
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { NormalizedSchema, translateTraits } from "@smithy/core/schema";
|
|
2
|
+
import { writeKey } from "@smithy/core/serde";
|
|
3
|
+
const HTTP_BINDINGS = Symbol.for("@smithy/schema-x");
|
|
4
|
+
export class HttpBindingNormalizedSchema extends NormalizedSchema {
|
|
5
|
+
static identity = Symbol.for("@smithy/HttpBindingNormalizedSchema");
|
|
6
|
+
identity = HttpBindingNormalizedSchema.identity;
|
|
7
|
+
bindings;
|
|
8
|
+
constructor(schema) {
|
|
9
|
+
super(schema);
|
|
10
|
+
}
|
|
11
|
+
static of(schema) {
|
|
12
|
+
const ns = NormalizedSchema.of(schema);
|
|
13
|
+
if (ns.identity === HttpBindingNormalizedSchema.identity) {
|
|
14
|
+
return ns;
|
|
15
|
+
}
|
|
16
|
+
const schemaCache = ns.isMemberSchema() ? ns : ns.getSchema();
|
|
17
|
+
const cache = typeof schemaCache === "object" && schemaCache !== null ? schemaCache : ns;
|
|
18
|
+
return (cache[HTTP_BINDINGS] ??= new HttpBindingNormalizedSchema(ns));
|
|
19
|
+
}
|
|
20
|
+
getHttpBindingLocation(traits) {
|
|
21
|
+
if (traits.httpPayload) {
|
|
22
|
+
return 0b100_100;
|
|
23
|
+
}
|
|
24
|
+
if (traits.httpLabel) {
|
|
25
|
+
return 0b100_001;
|
|
26
|
+
}
|
|
27
|
+
if (traits.httpHeader) {
|
|
28
|
+
return 0b100_110;
|
|
29
|
+
}
|
|
30
|
+
if (typeof traits.httpPrefixHeaders === "string") {
|
|
31
|
+
return 0b100_111;
|
|
32
|
+
}
|
|
33
|
+
if (traits.httpQuery) {
|
|
34
|
+
return 0b100_010;
|
|
35
|
+
}
|
|
36
|
+
if (traits.httpQueryParams) {
|
|
37
|
+
return 0b100_011;
|
|
38
|
+
}
|
|
39
|
+
if (traits.httpResponseCode) {
|
|
40
|
+
return 0b100_101;
|
|
41
|
+
}
|
|
42
|
+
return 0b100_000;
|
|
43
|
+
}
|
|
44
|
+
getHttpBindingValue(location, traits, nested = false) {
|
|
45
|
+
const raw = this.getSchema();
|
|
46
|
+
const type = typeof raw === "number" ? raw & 0xff : this.isListSchema() ? 0b0100_0000 : 0xff;
|
|
47
|
+
const slot = location & 0b111;
|
|
48
|
+
const media = (traits.mediaType ? (traits.mediaType === "application/json" || traits.mediaType.endsWith("+json") ? 2 : 1) : 0);
|
|
49
|
+
const stream = (traits.streaming || type === 42 ? (this.isStructSchema() ? 2 : 1) : 0);
|
|
50
|
+
const timestamp = (type >= 4 && type <= 7
|
|
51
|
+
? slot >= 6
|
|
52
|
+
? 2
|
|
53
|
+
: slot > 0 && slot < 4
|
|
54
|
+
? 1
|
|
55
|
+
: 0
|
|
56
|
+
: 0);
|
|
57
|
+
let flags = type |
|
|
58
|
+
(media << 8) |
|
|
59
|
+
((traits.idempotencyToken ? 1 : 0) << 10) |
|
|
60
|
+
(stream << 11) |
|
|
61
|
+
((traits.sparse ? 1 : 0) << 13) |
|
|
62
|
+
(timestamp << 14) |
|
|
63
|
+
((traits.hostLabel ? 1 : 0) << 17) |
|
|
64
|
+
((location === 0b100_100 && typeof raw !== "object" ? 1 : 0) << 18);
|
|
65
|
+
const category = type & 0b1100_0000;
|
|
66
|
+
const collectionValue = slot & 0b010 && (category === 0b0100_0000 || (!nested && slot & 1))
|
|
67
|
+
? this.getHttpBindingCollectionValue(location, traits)
|
|
68
|
+
: undefined;
|
|
69
|
+
const valueType = (collectionValue?.[1] ?? 0) & 0xff;
|
|
70
|
+
flags |=
|
|
71
|
+
(slot >= 6 &&
|
|
72
|
+
(valueType === 4 || valueType === 6)
|
|
73
|
+
? 1
|
|
74
|
+
: 0) << 16;
|
|
75
|
+
return [this, flags, collectionValue];
|
|
76
|
+
}
|
|
77
|
+
getHttpBindingCollectionValue(location, traits = this.getMergedTraits()) {
|
|
78
|
+
const valueSchema = HttpBindingNormalizedSchema.of(this.getValueSchema());
|
|
79
|
+
return valueSchema.getHttpBindingValue(location, { ...valueSchema.getMergedTraits(), ...traits }, true);
|
|
80
|
+
}
|
|
81
|
+
getHttpBindings() {
|
|
82
|
+
const source = this.getSchema();
|
|
83
|
+
return typeof source !== "object" || source === null ? EMPTY_BINDINGS : (this.bindings ??= buildHttpBindings(this));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const buildHttpBindings = (schema) => {
|
|
87
|
+
const bodyMemberNames = [];
|
|
88
|
+
const bodyMemberSchemas = [];
|
|
89
|
+
const requestBodyMemberNames = [];
|
|
90
|
+
const requestBodyMemberSchemas = [];
|
|
91
|
+
const memberBindings = [];
|
|
92
|
+
const byName = {};
|
|
93
|
+
const headers = {};
|
|
94
|
+
const prefixHeaders = [];
|
|
95
|
+
const responseBindings = { headers, prefixHeaders };
|
|
96
|
+
const bindings = {
|
|
97
|
+
request: { memberBindings, byName },
|
|
98
|
+
response: {
|
|
99
|
+
bodyMemberNames,
|
|
100
|
+
bindings: responseBindings,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
const { request, response } = bindings;
|
|
104
|
+
for (const [name, member] of schema.structIterator()) {
|
|
105
|
+
const bindingSchema = HttpBindingNormalizedSchema.of(member);
|
|
106
|
+
const traits = bindingSchema.getMergedTraits();
|
|
107
|
+
const location = bindingSchema.getHttpBindingLocation(traits);
|
|
108
|
+
const wireName = traits.httpHeader?.toLowerCase() ?? traits.httpPrefixHeaders?.toLowerCase() ?? traits.httpQuery;
|
|
109
|
+
const value = bindingSchema.getHttpBindingValue(location, traits);
|
|
110
|
+
const binding = [name, value, location, wireName];
|
|
111
|
+
if (name === "__proto__") {
|
|
112
|
+
writeKey(byName);
|
|
113
|
+
}
|
|
114
|
+
byName[name] = binding;
|
|
115
|
+
if ((value[1] >> 10) & 1) {
|
|
116
|
+
request.hasIdempotency = true;
|
|
117
|
+
}
|
|
118
|
+
memberBindings.push(binding);
|
|
119
|
+
const slot = location & 0b111;
|
|
120
|
+
if (slot === 0) {
|
|
121
|
+
requestBodyMemberNames.push(name);
|
|
122
|
+
requestBodyMemberSchemas.push(member);
|
|
123
|
+
}
|
|
124
|
+
if ((slot & 0b100) === 0) {
|
|
125
|
+
bodyMemberNames.push(name);
|
|
126
|
+
bodyMemberSchemas.push(member);
|
|
127
|
+
}
|
|
128
|
+
else if ((slot & 0b110) === 0b100) {
|
|
129
|
+
if (slot & 0b001) {
|
|
130
|
+
responseBindings.statusCode = binding;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
responseBindings.payload = binding;
|
|
134
|
+
const type = value[1] & 0xff;
|
|
135
|
+
request.contentTypeInstruction =
|
|
136
|
+
traits.mediaType ??
|
|
137
|
+
(type === 0
|
|
138
|
+
? "text/plain"
|
|
139
|
+
: type === 21 || type === 42
|
|
140
|
+
? "application/octet-stream"
|
|
141
|
+
: null);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else if (slot & 0b001) {
|
|
145
|
+
request.hasPrefixHeaders = true;
|
|
146
|
+
prefixHeaders.push(binding);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
if (wireName === "__proto__") {
|
|
150
|
+
writeKey(headers);
|
|
151
|
+
}
|
|
152
|
+
headers[wireName] = binding;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (request.contentTypeInstruction === undefined && requestBodyMemberNames.length) {
|
|
156
|
+
request.contentTypeInstruction = null;
|
|
157
|
+
}
|
|
158
|
+
request.syntheticBodySchema = createBodySchema(schema, requestBodyMemberNames, requestBodyMemberSchemas);
|
|
159
|
+
response.syntheticBodySchema = createBodySchema(schema, bodyMemberNames, bodyMemberSchemas);
|
|
160
|
+
return bindings;
|
|
161
|
+
};
|
|
162
|
+
const buildPathSegments = (path) => {
|
|
163
|
+
const segments = [];
|
|
164
|
+
let offset = 0;
|
|
165
|
+
for (const match of path.matchAll(/\{([^{}+]+)(\+)?\}/g)) {
|
|
166
|
+
if (match.index > offset) {
|
|
167
|
+
segments.push([path.slice(offset, match.index), 0]);
|
|
168
|
+
}
|
|
169
|
+
segments.push([match[1], match[2] ? 2 : 1]);
|
|
170
|
+
offset = match.index + match[0].length;
|
|
171
|
+
}
|
|
172
|
+
if (segments.length && offset < path.length) {
|
|
173
|
+
segments.push([path.slice(offset), 0]);
|
|
174
|
+
}
|
|
175
|
+
return segments.length ? segments : undefined;
|
|
176
|
+
};
|
|
177
|
+
const buildHttpOperationBindings = (schema) => {
|
|
178
|
+
const { http, endpoint } = translateTraits(schema.traits ?? {});
|
|
179
|
+
const [path, search] = http?.[1].split("?") ?? [];
|
|
180
|
+
return [
|
|
181
|
+
http?.[0],
|
|
182
|
+
path,
|
|
183
|
+
search ? [...new URLSearchParams(search)] : [],
|
|
184
|
+
path ? buildPathSegments(path) : undefined,
|
|
185
|
+
endpoint?.[0],
|
|
186
|
+
];
|
|
187
|
+
};
|
|
188
|
+
const EMPTY_BINDINGS = {
|
|
189
|
+
request: { memberBindings: [], byName: {} },
|
|
190
|
+
response: {
|
|
191
|
+
bodyMemberNames: [],
|
|
192
|
+
bindings: { headers: {}, prefixHeaders: [] },
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
export const getHttpOperationBindings = (schema) => (schema[HTTP_BINDINGS] ??= buildHttpOperationBindings(schema));
|
|
196
|
+
const createBodySchema = (schema, memberNames, memberSchemas) => {
|
|
197
|
+
if (!memberNames.length) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
const source = schema.getSchema();
|
|
201
|
+
const body = [
|
|
202
|
+
3,
|
|
203
|
+
source[1],
|
|
204
|
+
source[2],
|
|
205
|
+
schema.getMergedTraits(),
|
|
206
|
+
memberNames,
|
|
207
|
+
memberSchemas,
|
|
208
|
+
];
|
|
209
|
+
const required = source[6];
|
|
210
|
+
const bodyRequired = required && memberNames.reduce((count, name) => count + (source[4].indexOf(name) < required ? 1 : 0), 0);
|
|
211
|
+
if (bodyRequired) {
|
|
212
|
+
body[6] = bodyRequired;
|
|
213
|
+
}
|
|
214
|
+
return body;
|
|
215
|
+
};
|