@cdk8s/awscdk-resolver 0.0.709 → 0.0.711
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/.jsii +3 -3
- package/lib/resolve.js +1 -1
- package/node_modules/@aws-sdk/client-cloudformation/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-cloudformation/package.json +3 -3
- package/node_modules/@aws-sdk/core/dist-cjs/submodules/httpAuthSchemes/index.js +12 -3
- package/node_modules/@aws-sdk/core/dist-es/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.js +12 -3
- package/node_modules/@aws-sdk/core/package.json +1 -1
- package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-http/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -9
- package/node_modules/@aws-sdk/credential-provider-login/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/package.json +2 -2
- package/node_modules/@aws-sdk/token-providers/package.json +3 -3
- package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +1695 -3
- package/node_modules/@smithy/core/dist-es/submodules/protocols/ConfigurableSerdeContext.js +6 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/UnionSerde.js +26 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/common.js +3 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/index.js +8 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/JsonSettings.js +1 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/SmithyRpcV2JsonProtocol.js +102 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/codec-v1/JsonCodec.js +20 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/codec-v1/JsonSettings.js +1 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/codec-v1/JsonShapeDeserializer.js +167 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/codec-v1/JsonShapeSerializer.js +200 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/codec-v2/JsonBytesStringAdapter.js +103 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/codec-v2/JsonCodec2.js +20 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/codec-v2/JsonShapeDeserializer2.js +211 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/codec-v2/JsonShapeSerializer2.js +529 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/detectBufferParsing.js +18 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/jsonReplacer.js +46 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/jsonReviver.js +121 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/needsReviver.js +41 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/json/parseJsonBody.js +104 -0
- package/node_modules/@smithy/core/dist-es/submodules/protocols/writeKey.js +3 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/ConfigurableSerdeContext.d.ts +8 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/UnionSerde.d.ts +24 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/common.d.ts +2 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/index.d.ts +9 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/JsonSettings.d.ts +13 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/SmithyRpcV2JsonProtocol.d.ts +28 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/codec-v1/JsonCodec.d.ts +15 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/codec-v1/JsonSettings.d.ts +7 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/codec-v1/JsonShapeDeserializer.d.ts +14 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/codec-v1/JsonShapeSerializer.d.ts +29 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/codec-v2/JsonBytesStringAdapter.d.ts +51 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/codec-v2/JsonCodec2.d.ts +13 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/codec-v2/JsonShapeDeserializer2.d.ts +30 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/codec-v2/JsonShapeSerializer2.d.ts +60 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/detectBufferParsing.d.ts +1 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/jsonReplacer.d.ts +21 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/jsonReviver.d.ts +15 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/needsReviver.d.ts +11 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/json/parseJsonBody.d.ts +38 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/writeKey.d.ts +4 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/ConfigurableSerdeContext.d.ts +8 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/UnionSerde.d.ts +24 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/common.d.ts +2 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/index.d.ts +9 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/JsonSettings.d.ts +13 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/SmithyRpcV2JsonProtocol.d.ts +28 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/codec-v1/JsonCodec.d.ts +15 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/codec-v1/JsonSettings.d.ts +7 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/codec-v1/JsonShapeDeserializer.d.ts +14 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/codec-v1/JsonShapeSerializer.d.ts +29 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/codec-v2/JsonBytesStringAdapter.d.ts +51 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/codec-v2/JsonCodec2.d.ts +13 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/codec-v2/JsonShapeDeserializer2.d.ts +30 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/codec-v2/JsonShapeSerializer2.d.ts +60 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/detectBufferParsing.d.ts +1 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/jsonReplacer.d.ts +21 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/jsonReviver.d.ts +15 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/needsReviver.d.ts +11 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/json/parseJsonBody.d.ts +38 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/writeKey.d.ts +4 -0
- package/node_modules/@smithy/core/package.json +2 -1
- package/package.json +5 -5
package/node_modules/@smithy/core/dist-es/submodules/protocols/json/codec-v2/JsonShapeSerializer2.js
ADDED
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import { determineTimestampFormat } from "../../serde/determineTimestampFormat";
|
|
2
|
+
import { NormalizedSchema } from "@smithy/core/schema";
|
|
3
|
+
import { dateToUtcString, generateIdempotencyToken, LazyJsonString, NumericValue, toBase64 } from "@smithy/core/serde";
|
|
4
|
+
import { SerdeContextConfig } from "../../ConfigurableSerdeContext";
|
|
5
|
+
import { hasOwn } from "@smithy/core/transport";
|
|
6
|
+
import { JsonBytesStringAdapter } from "./JsonBytesStringAdapter";
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
const OPEN_BRACE = 0x7b;
|
|
9
|
+
const CLOSE_BRACE = 0x7d;
|
|
10
|
+
const OPEN_BRACKET = 0x5b;
|
|
11
|
+
const CLOSE_BRACKET = 0x5d;
|
|
12
|
+
const QUOTE = 0x22;
|
|
13
|
+
const COLON = 0x3a;
|
|
14
|
+
const COMMA = 0x2c;
|
|
15
|
+
const BACKSLASH = 0x5c;
|
|
16
|
+
const TRUE = new Uint8Array([0x74, 0x72, 0x75, 0x65]);
|
|
17
|
+
const FALSE = new Uint8Array([0x66, 0x61, 0x6c, 0x73, 0x65]);
|
|
18
|
+
const NULL = new Uint8Array([0x6e, 0x75, 0x6c, 0x6c]);
|
|
19
|
+
const ESCAPE_TABLE = new Array(128).fill(null);
|
|
20
|
+
ESCAPE_TABLE[0x08] = "b";
|
|
21
|
+
ESCAPE_TABLE[0x09] = "t";
|
|
22
|
+
ESCAPE_TABLE[0x0a] = "n";
|
|
23
|
+
ESCAPE_TABLE[0x0c] = "f";
|
|
24
|
+
ESCAPE_TABLE[0x0d] = "r";
|
|
25
|
+
ESCAPE_TABLE[0x22] = '"';
|
|
26
|
+
ESCAPE_TABLE[0x5c] = "\\";
|
|
27
|
+
for (let i = 0; i < 0x20; i++) {
|
|
28
|
+
if (ESCAPE_TABLE[i] === null) {
|
|
29
|
+
ESCAPE_TABLE[i] = "u00" + i.toString(16).padStart(2, "0");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const INITIAL_BUFFER_SIZE = 2048;
|
|
33
|
+
function alloc(size) {
|
|
34
|
+
return JsonBytesStringAdapter.allocUnsafe(size);
|
|
35
|
+
}
|
|
36
|
+
export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
37
|
+
settings;
|
|
38
|
+
json;
|
|
39
|
+
i = 0;
|
|
40
|
+
rootSchema;
|
|
41
|
+
rawValue;
|
|
42
|
+
passthrough = false;
|
|
43
|
+
constructor(settings) {
|
|
44
|
+
super();
|
|
45
|
+
this.settings = settings;
|
|
46
|
+
this.json = alloc(INITIAL_BUFFER_SIZE);
|
|
47
|
+
}
|
|
48
|
+
write(schema, value) {
|
|
49
|
+
this.i = 0;
|
|
50
|
+
this.rawValue = value;
|
|
51
|
+
this.rootSchema = NormalizedSchema.of(schema);
|
|
52
|
+
this.passthrough = this.rootSchema.isBlobSchema() || this.rootSchema.isStringSchema();
|
|
53
|
+
if (!this.passthrough) {
|
|
54
|
+
this.writeValue(this.rootSchema, value, undefined);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
writeDiscriminatedDocument(schema, value) {
|
|
58
|
+
this.i = 0;
|
|
59
|
+
this.rootSchema = NormalizedSchema.of(schema);
|
|
60
|
+
const ns = this.rootSchema;
|
|
61
|
+
if (ns.isStructSchema() && value != null && typeof value === "object") {
|
|
62
|
+
this.writeValue(ns, value, undefined);
|
|
63
|
+
const prefix = `"__type":"${ns.getName(true) ?? "Unknown"}",`;
|
|
64
|
+
const z = prefix.length;
|
|
65
|
+
this.ensure(z);
|
|
66
|
+
this.json.copyWithin(1 + z, 1, this.i);
|
|
67
|
+
encoder.encodeInto(prefix, this.json.subarray(1));
|
|
68
|
+
this.i += z;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this.writeValue(ns, value, undefined);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
flush() {
|
|
75
|
+
this.rootSchema = undefined;
|
|
76
|
+
const finalPosition = this.i;
|
|
77
|
+
this.i = 0;
|
|
78
|
+
const raw = this.rawValue;
|
|
79
|
+
this.rawValue = undefined;
|
|
80
|
+
if (finalPosition === 0) {
|
|
81
|
+
return raw;
|
|
82
|
+
}
|
|
83
|
+
const result = this.json.subarray(0, finalPosition);
|
|
84
|
+
this.json = alloc(INITIAL_BUFFER_SIZE);
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
ensure(byteCount) {
|
|
88
|
+
const { i, json } = this;
|
|
89
|
+
if (i + byteCount > json.length) {
|
|
90
|
+
let newSize = json.length * 2;
|
|
91
|
+
while (newSize < i + byteCount) {
|
|
92
|
+
newSize *= 2;
|
|
93
|
+
}
|
|
94
|
+
const next = alloc(newSize);
|
|
95
|
+
next.set(this.json);
|
|
96
|
+
this.json = next;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
writeAscii(s) {
|
|
100
|
+
const z = s.length;
|
|
101
|
+
this.ensure(z);
|
|
102
|
+
let { i, json } = this;
|
|
103
|
+
for (let j = 0; j < z; ++j) {
|
|
104
|
+
json[i] = s.charCodeAt(j);
|
|
105
|
+
i += 1;
|
|
106
|
+
}
|
|
107
|
+
this.i = i;
|
|
108
|
+
}
|
|
109
|
+
writeAsciiQuoted(s) {
|
|
110
|
+
const z = s.length;
|
|
111
|
+
this.ensure(z + 4);
|
|
112
|
+
let { json, i } = this;
|
|
113
|
+
json[i++] = QUOTE;
|
|
114
|
+
for (let j = 0; j < z; ++j) {
|
|
115
|
+
json[i++] = s.charCodeAt(j);
|
|
116
|
+
}
|
|
117
|
+
json[i++] = QUOTE;
|
|
118
|
+
this.i = i;
|
|
119
|
+
}
|
|
120
|
+
writeJsonString(s) {
|
|
121
|
+
this.ensure(s.length * 3 + 2);
|
|
122
|
+
this.json[this.i++] = QUOTE;
|
|
123
|
+
const z = s.length;
|
|
124
|
+
for (let j = 0; j < z; ++j) {
|
|
125
|
+
const c = s.charCodeAt(j);
|
|
126
|
+
if (c > 0x22 && c < 0x5c) {
|
|
127
|
+
this.json[this.i++] = c;
|
|
128
|
+
}
|
|
129
|
+
else if (c < 0x80) {
|
|
130
|
+
const esc = ESCAPE_TABLE[c];
|
|
131
|
+
if (esc !== null) {
|
|
132
|
+
this.ensure(esc.length + 1);
|
|
133
|
+
this.json[this.i++] = BACKSLASH;
|
|
134
|
+
for (let k = 0; k < esc.length; k++) {
|
|
135
|
+
this.json[this.i++] = esc.charCodeAt(k);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.json[this.i++] = c;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else if (c >= 0xd800 && c <= 0xdbff) {
|
|
143
|
+
const next = j + 1 < z ? s.charCodeAt(j + 1) : 0;
|
|
144
|
+
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
145
|
+
this.ensure(4);
|
|
146
|
+
const { written } = encoder.encodeInto(s.substring(j, j + 2), this.json.subarray(this.i));
|
|
147
|
+
this.i += written;
|
|
148
|
+
++j;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
this.ensure(6);
|
|
152
|
+
this.writeUnicodeEscape(c);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else if (c >= 0xdc00 && c <= 0xdfff) {
|
|
156
|
+
this.ensure(6);
|
|
157
|
+
this.writeUnicodeEscape(c);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
let { i, json } = this;
|
|
161
|
+
if (c < 0x800) {
|
|
162
|
+
json[i++] = 0xc0 | (c >> 6);
|
|
163
|
+
json[i++] = 0x80 | (c & 0x3f);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
json[i++] = 0xe0 | (c >> 12);
|
|
167
|
+
json[i++] = 0x80 | ((c >> 6) & 0x3f);
|
|
168
|
+
json[i++] = 0x80 | (c & 0x3f);
|
|
169
|
+
}
|
|
170
|
+
this.i = i;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
this.json[this.i++] = QUOTE;
|
|
174
|
+
}
|
|
175
|
+
writeUnicodeEscape(code) {
|
|
176
|
+
let { json, i } = this;
|
|
177
|
+
json[i++] = BACKSLASH;
|
|
178
|
+
json[i++] = 0x75;
|
|
179
|
+
const hex = code.toString(16).padStart(4, "0");
|
|
180
|
+
for (let j = 0; j < 4; ++j) {
|
|
181
|
+
json[i++] = hex.charCodeAt(j);
|
|
182
|
+
}
|
|
183
|
+
this.i = i;
|
|
184
|
+
}
|
|
185
|
+
static B64 = (() => {
|
|
186
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
187
|
+
const table = new Uint8Array(64);
|
|
188
|
+
for (let i = 0; i < 64; ++i) {
|
|
189
|
+
table[i] = chars.charCodeAt(i);
|
|
190
|
+
}
|
|
191
|
+
return table;
|
|
192
|
+
})();
|
|
193
|
+
writeBase64(data) {
|
|
194
|
+
const b64Len = Math.ceil(data.length / 3) * 4;
|
|
195
|
+
this.ensure(b64Len + 2);
|
|
196
|
+
const json = this.json;
|
|
197
|
+
const B64 = JsonShapeSerializer2.B64;
|
|
198
|
+
let i = this.i;
|
|
199
|
+
json[i++] = QUOTE;
|
|
200
|
+
const len = data.length;
|
|
201
|
+
const remainder = len % 3;
|
|
202
|
+
const mainLen = len - remainder;
|
|
203
|
+
for (let j = 0; j < mainLen; j += 3) {
|
|
204
|
+
const a = data[j];
|
|
205
|
+
const b = data[j + 1];
|
|
206
|
+
const c = data[j + 2];
|
|
207
|
+
json[i++] = B64[a >> 2];
|
|
208
|
+
json[i++] = B64[((a & 0x03) << 4) | (b >> 4)];
|
|
209
|
+
json[i++] = B64[((b & 0x0f) << 2) | (c >> 6)];
|
|
210
|
+
json[i++] = B64[c & 0x3f];
|
|
211
|
+
}
|
|
212
|
+
if (remainder === 2) {
|
|
213
|
+
const a = data[mainLen];
|
|
214
|
+
const b = data[mainLen + 1];
|
|
215
|
+
json[i++] = B64[a >> 2];
|
|
216
|
+
json[i++] = B64[((a & 0x03) << 4) | (b >> 4)];
|
|
217
|
+
json[i++] = B64[(b & 0x0f) << 2];
|
|
218
|
+
json[i++] = 0x3d;
|
|
219
|
+
}
|
|
220
|
+
else if (remainder === 1) {
|
|
221
|
+
const a = data[mainLen];
|
|
222
|
+
json[i++] = B64[a >> 2];
|
|
223
|
+
json[i++] = B64[(a & 0x03) << 4];
|
|
224
|
+
json[i++] = 0x3d;
|
|
225
|
+
json[i++] = 0x3d;
|
|
226
|
+
}
|
|
227
|
+
json[i++] = QUOTE;
|
|
228
|
+
this.i = i;
|
|
229
|
+
}
|
|
230
|
+
writeValue(schema, value, container) {
|
|
231
|
+
if (value == null) {
|
|
232
|
+
if (container?.isStructSchema()) {
|
|
233
|
+
if (value === undefined) {
|
|
234
|
+
const ns = NormalizedSchema.of(schema);
|
|
235
|
+
if (ns.isIdempotencyToken()) {
|
|
236
|
+
this.writeAsciiQuoted(generateIdempotencyToken());
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
this.ensure(4);
|
|
243
|
+
this.json.set(NULL, this.i);
|
|
244
|
+
this.i += 4;
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const ns = NormalizedSchema.of(schema);
|
|
248
|
+
const isObject = typeof value === "object";
|
|
249
|
+
if (ns.isStringSchema()) {
|
|
250
|
+
const mediaType = ns.getMergedTraits().mediaType;
|
|
251
|
+
if (mediaType) {
|
|
252
|
+
const isJson = mediaType === "application/json" || mediaType.endsWith("+json");
|
|
253
|
+
if (isJson) {
|
|
254
|
+
this.writeJsonString(LazyJsonString.from(value).toString());
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (this.settings.bigNumberAsString && value != null && (ns.isBigIntegerSchema() || ns.isBigDecimalSchema())) {
|
|
260
|
+
const asString = value instanceof NumericValue ? value.string : String(value);
|
|
261
|
+
this.writeAsciiQuoted(asString);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (isObject) {
|
|
265
|
+
if (ns.isStructSchema()) {
|
|
266
|
+
this.writeStruct(ns, value);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (Array.isArray(value) && (ns.isListSchema() || ns.isDocumentSchema())) {
|
|
270
|
+
this.writeList(ns, value, ns.isDocumentSchema());
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (ns.isMapSchema()) {
|
|
274
|
+
this.writeMap(ns, value, false);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (value instanceof Uint8Array && (ns.isBlobSchema() || ns.isDocumentSchema())) {
|
|
278
|
+
this.writeBase64(value);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (value instanceof Date && (ns.isTimestampSchema() || ns.isDocumentSchema())) {
|
|
282
|
+
this.writeTimestamp(ns, value);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (value instanceof NumericValue) {
|
|
286
|
+
this.writeAscii(value.string);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (ns.isDocumentSchema()) {
|
|
290
|
+
if (Array.isArray(value)) {
|
|
291
|
+
this.writeList(ns, value, true);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
this.writeMap(ns, value, true);
|
|
295
|
+
}
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const json = JSON.stringify(value);
|
|
299
|
+
this.writeAscii(json);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (typeof value === "string") {
|
|
303
|
+
if (ns.isBlobSchema()) {
|
|
304
|
+
const b64 = (this.serdeContext?.base64Encoder ?? toBase64)(value);
|
|
305
|
+
this.writeAsciiQuoted(b64);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
this.writeJsonString(value);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (typeof value === "number") {
|
|
312
|
+
if (Math.abs(value) === Infinity || Number.isNaN(value)) {
|
|
313
|
+
this.writeAsciiQuoted(String(value));
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const numStr = String(value);
|
|
317
|
+
this.writeAscii(numStr);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (typeof value === "boolean") {
|
|
321
|
+
this.ensure(5);
|
|
322
|
+
let { i, json } = this;
|
|
323
|
+
if (value) {
|
|
324
|
+
json.set(TRUE, i);
|
|
325
|
+
i += 4;
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
json.set(FALSE, i);
|
|
329
|
+
i += 5;
|
|
330
|
+
}
|
|
331
|
+
this.i = i;
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (typeof value === "bigint") {
|
|
335
|
+
this.writeAscii(value.toString());
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
this.writeAscii(String(value));
|
|
339
|
+
}
|
|
340
|
+
writeStruct(ns, value) {
|
|
341
|
+
this.ensure(2);
|
|
342
|
+
this.json[this.i++] = OPEN_BRACE;
|
|
343
|
+
let wroteAny = false;
|
|
344
|
+
const hasType = typeof value.__type === "string";
|
|
345
|
+
let writtenKeys;
|
|
346
|
+
if (hasType) {
|
|
347
|
+
writtenKeys = new Set();
|
|
348
|
+
}
|
|
349
|
+
for (const [memberName, memberSchema] of ns.structIterator()) {
|
|
350
|
+
const item = value[memberName];
|
|
351
|
+
if (item == null && !memberSchema.isIdempotencyToken()) {
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (wroteAny) {
|
|
355
|
+
this.ensure(1);
|
|
356
|
+
this.json[this.i++] = COMMA;
|
|
357
|
+
}
|
|
358
|
+
wroteAny = true;
|
|
359
|
+
const targetKey = this.settings.jsonName ? (memberSchema.getMergedTraits().jsonName ?? memberName) : memberName;
|
|
360
|
+
if (writtenKeys) {
|
|
361
|
+
writtenKeys.add(memberName);
|
|
362
|
+
writtenKeys.add(targetKey);
|
|
363
|
+
}
|
|
364
|
+
this.writeAsciiQuoted(targetKey);
|
|
365
|
+
this.json[this.i++] = COLON;
|
|
366
|
+
this.writeValue(memberSchema, item, ns);
|
|
367
|
+
}
|
|
368
|
+
if (!wroteAny && ns.isUnionSchema()) {
|
|
369
|
+
const { $unknown } = value;
|
|
370
|
+
if (Array.isArray($unknown)) {
|
|
371
|
+
const [k, v] = $unknown;
|
|
372
|
+
this.writeAsciiQuoted(k);
|
|
373
|
+
this.ensure(1);
|
|
374
|
+
this.json[this.i++] = COLON;
|
|
375
|
+
this.writeValue(15, v, ns);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
else if (hasType) {
|
|
379
|
+
for (const k in value) {
|
|
380
|
+
if (writtenKeys.has(k)) {
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
writtenKeys.add(k);
|
|
384
|
+
const v = value[k];
|
|
385
|
+
if (wroteAny) {
|
|
386
|
+
this.ensure(1);
|
|
387
|
+
this.json[this.i++] = COMMA;
|
|
388
|
+
}
|
|
389
|
+
wroteAny = true;
|
|
390
|
+
this.writeAsciiQuoted(k);
|
|
391
|
+
this.ensure(1);
|
|
392
|
+
this.json[this.i++] = COLON;
|
|
393
|
+
this.writeValue(15, v, undefined);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
this.ensure(1);
|
|
397
|
+
this.json[this.i++] = CLOSE_BRACE;
|
|
398
|
+
}
|
|
399
|
+
writeList(ns, value, isDocument) {
|
|
400
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
401
|
+
const valueSchema = ns.getValueSchema();
|
|
402
|
+
if (!isDocument) {
|
|
403
|
+
if (valueSchema.isStringSchema() || valueSchema.isNumericSchema() || valueSchema.isBooleanSchema()) {
|
|
404
|
+
let hasSpecials = false;
|
|
405
|
+
for (let i = 0; i < value.length; ++i) {
|
|
406
|
+
const v = value[i];
|
|
407
|
+
if (Number.isNaN(v) || v === Infinity || v === -Infinity || (v == null && !sparse)) {
|
|
408
|
+
hasSpecials = true;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
let json;
|
|
413
|
+
if (!hasSpecials) {
|
|
414
|
+
json = JSON.stringify(value);
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
const out = [];
|
|
418
|
+
for (let i = 0; i < value.length; ++i) {
|
|
419
|
+
const v = value[i];
|
|
420
|
+
if (v == null && !sparse)
|
|
421
|
+
continue;
|
|
422
|
+
if (Number.isNaN(v) || v === Infinity || v === -Infinity) {
|
|
423
|
+
out.push(String(v));
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
out.push(v);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
json = JSON.stringify(out);
|
|
430
|
+
}
|
|
431
|
+
this.ensure(json.length * 3);
|
|
432
|
+
this.i += encoder.encodeInto(json, this.json.subarray(this.i)).written;
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
this.ensure(2);
|
|
437
|
+
this.json[this.i++] = OPEN_BRACKET;
|
|
438
|
+
let wroteFirstItem = false;
|
|
439
|
+
for (let i = 0; i < value.length; ++i) {
|
|
440
|
+
const item = value[i];
|
|
441
|
+
if (isDocument ? item === undefined : item == null && !sparse) {
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
if (wroteFirstItem) {
|
|
445
|
+
this.ensure(1);
|
|
446
|
+
this.json[this.i++] = COMMA;
|
|
447
|
+
}
|
|
448
|
+
this.writeValue(valueSchema, item, undefined);
|
|
449
|
+
wroteFirstItem = true;
|
|
450
|
+
}
|
|
451
|
+
this.ensure(1);
|
|
452
|
+
this.json[this.i++] = CLOSE_BRACKET;
|
|
453
|
+
}
|
|
454
|
+
writeMap(ns, value, isDocument) {
|
|
455
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
456
|
+
const valueSchema = ns.getValueSchema();
|
|
457
|
+
if (!isDocument) {
|
|
458
|
+
if (valueSchema.isStringSchema() || valueSchema.isNumericSchema() || valueSchema.isBooleanSchema()) {
|
|
459
|
+
let modifications;
|
|
460
|
+
for (const k in value) {
|
|
461
|
+
if (!hasOwn(value, k))
|
|
462
|
+
continue;
|
|
463
|
+
const v = value[k];
|
|
464
|
+
if (Number.isNaN(v) || v === Infinity || v === -Infinity) {
|
|
465
|
+
(modifications ??= {})[k] = v;
|
|
466
|
+
value[k] = String(v);
|
|
467
|
+
}
|
|
468
|
+
else if (v === null && !sparse) {
|
|
469
|
+
(modifications ??= {})[k] = null;
|
|
470
|
+
value[k] = undefined;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const json = JSON.stringify(value);
|
|
474
|
+
if (modifications) {
|
|
475
|
+
Object.assign(value, modifications);
|
|
476
|
+
}
|
|
477
|
+
this.ensure(json.length * 3);
|
|
478
|
+
this.i += encoder.encodeInto(json, this.json.subarray(this.i)).written;
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
this.ensure(2);
|
|
483
|
+
this.json[this.i++] = OPEN_BRACE;
|
|
484
|
+
let first = true;
|
|
485
|
+
for (const k in value) {
|
|
486
|
+
if (!hasOwn(value, k))
|
|
487
|
+
continue;
|
|
488
|
+
const v = value[k];
|
|
489
|
+
if (isDocument ? v === undefined : v == null && !sparse) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
if (!first) {
|
|
493
|
+
this.ensure(1);
|
|
494
|
+
this.json[this.i++] = COMMA;
|
|
495
|
+
}
|
|
496
|
+
first = false;
|
|
497
|
+
this.writeJsonString(k);
|
|
498
|
+
this.ensure(1);
|
|
499
|
+
this.json[this.i++] = COLON;
|
|
500
|
+
this.writeValue(valueSchema, v, undefined);
|
|
501
|
+
}
|
|
502
|
+
this.ensure(1);
|
|
503
|
+
this.json[this.i++] = CLOSE_BRACE;
|
|
504
|
+
}
|
|
505
|
+
writeTimestamp(ns, value) {
|
|
506
|
+
const format = determineTimestampFormat(ns, this.settings);
|
|
507
|
+
switch (format) {
|
|
508
|
+
case 5: {
|
|
509
|
+
const iso = value.toISOString().replace(".000Z", "Z");
|
|
510
|
+
this.writeAsciiQuoted(iso);
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
case 6: {
|
|
514
|
+
this.writeAsciiQuoted(dateToUtcString(value));
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
case 7: {
|
|
518
|
+
const epochSecs = String(value.getTime() / 1000);
|
|
519
|
+
this.writeAscii(epochSecs);
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
default: {
|
|
523
|
+
const epochSecs = String(value.getTime() / 1000);
|
|
524
|
+
this.writeAscii(epochSecs);
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
let canParseBuffer;
|
|
2
|
+
export function detectBufferParsing() {
|
|
3
|
+
if (canParseBuffer === undefined) {
|
|
4
|
+
try {
|
|
5
|
+
if (typeof Buffer !== "function") {
|
|
6
|
+
canParseBuffer = false;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
const result = JSON.parse(Buffer.from([0x7b, 0x7d]));
|
|
10
|
+
canParseBuffer = result !== null && typeof result === "object";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
canParseBuffer = false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return canParseBuffer;
|
|
18
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { NumericValue } from "@smithy/core/serde";
|
|
2
|
+
const NUMERIC_CONTROL_CHAR = String.fromCharCode(925);
|
|
3
|
+
export class JsonReplacer {
|
|
4
|
+
values = new Map();
|
|
5
|
+
counter = 0;
|
|
6
|
+
stage = 0;
|
|
7
|
+
createReplacer() {
|
|
8
|
+
if (this.stage === 1) {
|
|
9
|
+
throw new Error("@aws-sdk/core/protocols - JsonReplacer already created.");
|
|
10
|
+
}
|
|
11
|
+
if (this.stage === 2) {
|
|
12
|
+
throw new Error("@aws-sdk/core/protocols - JsonReplacer exhausted.");
|
|
13
|
+
}
|
|
14
|
+
this.stage = 1;
|
|
15
|
+
return (key, value) => {
|
|
16
|
+
if (value instanceof NumericValue) {
|
|
17
|
+
const v = `${NUMERIC_CONTROL_CHAR + "nv" + this.counter++}_` + value.string;
|
|
18
|
+
this.values.set(`"${v}"`, value.string);
|
|
19
|
+
return v;
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === "bigint") {
|
|
22
|
+
const s = value.toString();
|
|
23
|
+
const v = `${NUMERIC_CONTROL_CHAR + "b" + this.counter++}_` + s;
|
|
24
|
+
this.values.set(`"${v}"`, s);
|
|
25
|
+
return v;
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
replaceInJson(json) {
|
|
31
|
+
if (this.stage === 0) {
|
|
32
|
+
throw new Error("@aws-sdk/core/protocols - JsonReplacer not created yet.");
|
|
33
|
+
}
|
|
34
|
+
if (this.stage === 2) {
|
|
35
|
+
throw new Error("@aws-sdk/core/protocols - JsonReplacer exhausted.");
|
|
36
|
+
}
|
|
37
|
+
this.stage = 2;
|
|
38
|
+
if (this.counter === 0) {
|
|
39
|
+
return json;
|
|
40
|
+
}
|
|
41
|
+
for (const [key, value] of this.values) {
|
|
42
|
+
json = json.replace(key, value);
|
|
43
|
+
}
|
|
44
|
+
return json;
|
|
45
|
+
}
|
|
46
|
+
}
|