@cdk8s/awscdk-resolver 0.0.609 → 0.0.611

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.
Files changed (145) hide show
  1. package/.jsii +3 -3
  2. package/lib/resolve.js +1 -1
  3. package/node_modules/@aws-sdk/client-cloudformation/package.json +3 -3
  4. package/node_modules/@aws-sdk/core/package.json +2 -2
  5. package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
  6. package/node_modules/@aws-sdk/credential-provider-http/package.json +2 -2
  7. package/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -9
  8. package/node_modules/@aws-sdk/credential-provider-login/package.json +3 -3
  9. package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
  10. package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
  11. package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
  12. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
  13. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
  14. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
  15. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
  16. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
  17. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
  18. package/node_modules/@aws-sdk/nested-clients/package.json +2 -2
  19. package/node_modules/@aws-sdk/token-providers/package.json +3 -3
  20. package/node_modules/@aws-sdk/xml-builder/dist-cjs/xml-parser.browser.js +1 -1
  21. package/node_modules/@aws-sdk/xml-builder/dist-cjs/xml-parser.js +233 -43
  22. package/node_modules/@aws-sdk/xml-builder/dist-es/xml-parser.browser.js +1 -1
  23. package/node_modules/@aws-sdk/xml-builder/dist-es/xml-parser.js +233 -43
  24. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/xml-parser.d.ts +1 -1
  25. package/node_modules/@aws-sdk/xml-builder/dist-types/xml-parser.d.ts +2 -1
  26. package/node_modules/@aws-sdk/xml-builder/package.json +4 -4
  27. package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +518 -371
  28. package/node_modules/@smithy/core/dist-cjs/submodules/client/index.js +1 -1
  29. package/node_modules/@smithy/core/dist-es/submodules/cbor/cbor-decode.js +326 -269
  30. package/node_modules/@smithy/core/dist-es/submodules/cbor/cbor-encode.js +192 -103
  31. package/node_modules/@smithy/core/dist-es/submodules/cbor/cbor.js +4 -2
  32. package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/get-value-from-text-node.js +1 -1
  33. package/node_modules/@smithy/core/dist-types/submodules/cbor/cbor-decode.d.ts +4 -0
  34. package/node_modules/@smithy/core/dist-types/submodules/cbor/cbor-encode.d.ts +8 -4
  35. package/node_modules/@smithy/core/package.json +1 -1
  36. package/node_modules/@smithy/credential-provider-imds/package.json +2 -2
  37. package/node_modules/@smithy/fetch-http-handler/package.json +2 -2
  38. package/node_modules/@smithy/node-http-handler/package.json +2 -2
  39. package/node_modules/@smithy/signature-v4/package.json +2 -2
  40. package/package.json +9 -9
  41. package/node_modules/@aws-sdk/xml-builder/dist-cjs/xml-external/nodable_entities.js +0 -333
  42. package/node_modules/@aws-sdk/xml-builder/dist-es/xml-external/nodable_entities.js +0 -332
  43. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/xml-external/nodable_entities.d.ts +0 -66
  44. package/node_modules/@aws-sdk/xml-builder/dist-types/xml-external/nodable_entities.d.ts +0 -65
  45. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/CHANGELOG.md +0 -827
  46. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/LICENSE +0 -21
  47. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/README.md +0 -202
  48. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxbuilder.min.js +0 -2
  49. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxbuilder.min.js.map +0 -1
  50. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxp.cjs +0 -1
  51. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxp.d.cts +0 -770
  52. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxp.min.js +0 -2
  53. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxp.min.js.map +0 -1
  54. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxparser.min.js +0 -2
  55. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxparser.min.js.map +0 -1
  56. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxvalidator.min.js +0 -2
  57. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxvalidator.min.js.map +0 -1
  58. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/package.json +0 -93
  59. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/cli/cli.js +0 -97
  60. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/cli/man.js +0 -17
  61. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/cli/read.js +0 -43
  62. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/fxp.d.ts +0 -739
  63. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/fxp.js +0 -14
  64. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/ignoreAttributes.js +0 -18
  65. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/util.js +0 -61
  66. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/CharsSymbol.js +0 -16
  67. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/EntitiesParser.js +0 -106
  68. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/OptionsBuilder.js +0 -61
  69. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/OutputBuilders/BaseOutputBuilder.js +0 -69
  70. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsArrBuilder.js +0 -103
  71. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsMinArrBuilder.js +0 -100
  72. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsObjBuilder.js +0 -154
  73. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/OutputBuilders/ParserOptionsBuilder.js +0 -94
  74. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/Report.js +0 -0
  75. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/TagPath.js +0 -81
  76. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/TagPathMatcher.js +0 -13
  77. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/XMLParser.js +0 -83
  78. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/Xml2JsParser.js +0 -235
  79. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/XmlPartReader.js +0 -210
  80. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/XmlSpecialTagsReader.js +0 -111
  81. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/inputSource/BufferSource.js +0 -116
  82. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/inputSource/StringSource.js +0 -121
  83. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/EntitiesParser.js +0 -105
  84. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/booleanParser.js +0 -22
  85. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/booleanParserExt.js +0 -19
  86. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/currency.js +0 -38
  87. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/join.js +0 -13
  88. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/number.js +0 -14
  89. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/trim.js +0 -6
  90. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/validator.js +0 -425
  91. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js +0 -6
  92. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js +0 -407
  93. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js +0 -163
  94. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js +0 -840
  95. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js +0 -71
  96. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlparser/node2json.js +0 -177
  97. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js +0 -40
  98. package/node_modules/@nodable/entities/README.md +0 -41
  99. package/node_modules/@nodable/entities/package.json +0 -57
  100. package/node_modules/@nodable/entities/src/EntityDecoder.js +0 -644
  101. package/node_modules/@nodable/entities/src/EntityEncoder.js +0 -194
  102. package/node_modules/@nodable/entities/src/entities.js +0 -1159
  103. package/node_modules/@nodable/entities/src/entityTries.js +0 -49
  104. package/node_modules/@nodable/entities/src/index.d.ts +0 -341
  105. package/node_modules/@nodable/entities/src/index.js +0 -29
  106. package/node_modules/anynum/LICENSE +0 -21
  107. package/node_modules/anynum/README.md +0 -142
  108. package/node_modules/anynum/anynum.js +0 -135
  109. package/node_modules/anynum/digitTable.js +0 -116
  110. package/node_modules/anynum/package.json +0 -42
  111. package/node_modules/fast-xml-builder/CHANGELOG.md +0 -40
  112. package/node_modules/fast-xml-builder/LICENSE +0 -21
  113. package/node_modules/fast-xml-builder/README.md +0 -74
  114. package/node_modules/fast-xml-builder/lib/fxb.cjs +0 -1
  115. package/node_modules/fast-xml-builder/lib/fxb.d.cts +0 -270
  116. package/node_modules/fast-xml-builder/lib/fxb.min.js +0 -2
  117. package/node_modules/fast-xml-builder/lib/fxb.min.js.map +0 -1
  118. package/node_modules/fast-xml-builder/package.json +0 -81
  119. package/node_modules/fast-xml-builder/src/fxb.d.ts +0 -270
  120. package/node_modules/fast-xml-builder/src/fxb.js +0 -599
  121. package/node_modules/fast-xml-builder/src/ignoreAttributes.js +0 -18
  122. package/node_modules/fast-xml-builder/src/orderedJs2Xml.js +0 -359
  123. package/node_modules/fast-xml-builder/src/prettifyJs2Xml.js +0 -0
  124. package/node_modules/fast-xml-builder/src/util.js +0 -16
  125. package/node_modules/path-expression-matcher/LICENSE +0 -21
  126. package/node_modules/path-expression-matcher/README.md +0 -947
  127. package/node_modules/path-expression-matcher/lib/pem.cjs +0 -1
  128. package/node_modules/path-expression-matcher/lib/pem.d.cts +0 -715
  129. package/node_modules/path-expression-matcher/lib/pem.min.js +0 -2
  130. package/node_modules/path-expression-matcher/lib/pem.min.js.map +0 -1
  131. package/node_modules/path-expression-matcher/package.json +0 -79
  132. package/node_modules/path-expression-matcher/src/Expression.js +0 -232
  133. package/node_modules/path-expression-matcher/src/ExpressionSet.js +0 -225
  134. package/node_modules/path-expression-matcher/src/Matcher.js +0 -660
  135. package/node_modules/path-expression-matcher/src/index.d.ts +0 -589
  136. package/node_modules/path-expression-matcher/src/index.js +0 -29
  137. package/node_modules/strnum/CHANGELOG.md +0 -51
  138. package/node_modules/strnum/LICENSE +0 -21
  139. package/node_modules/strnum/README.md +0 -113
  140. package/node_modules/strnum/package.json +0 -36
  141. package/node_modules/strnum/strnum.js +0 -171
  142. package/node_modules/xml-naming/README.md +0 -189
  143. package/node_modules/xml-naming/package.json +0 -54
  144. package/node_modules/xml-naming/src/index.d.ts +0 -74
  145. package/node_modules/xml-naming/src/index.js +0 -270
@@ -1,4 +1,4 @@
1
- const { nv, toUtf8, fromUtf8, NumericValue, calculateBodyLength, _parseEpochTimestamp, fromBase64, generateIdempotencyToken } = require("@smithy/core/serde");
1
+ const { nv, NumericValue, calculateBodyLength, _parseEpochTimestamp, fromBase64, generateIdempotencyToken } = require("@smithy/core/serde");
2
2
  const { HttpRequest, collectBody, SerdeContext, RpcProtocol } = require("@smithy/core/protocols");
3
3
  const { NormalizedSchema, deref, TypeRegistry } = require("@smithy/core/schema");
4
4
  const { getSmithyContext } = require("@smithy/core/transport");
@@ -29,14 +29,15 @@ function tag(data) {
29
29
  return data;
30
30
  }
31
31
 
32
- const USE_TEXT_DECODER = typeof TextDecoder !== "undefined";
33
32
  const USE_BUFFER$1 = typeof Buffer !== "undefined";
33
+ const textDecoder = new TextDecoder();
34
34
  let payload = alloc(0);
35
+ let isBuffer = false;
35
36
  let dataView$1 = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
36
- const textDecoder = USE_TEXT_DECODER ? new TextDecoder() : null;
37
37
  let _offset = 0;
38
38
  function setPayload(bytes) {
39
39
  payload = bytes;
40
+ isBuffer = USE_BUFFER$1 && payload instanceof Buffer;
40
41
  dataView$1 = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
41
42
  }
42
43
  function decode(at, to) {
@@ -45,10 +46,13 @@ function decode(at, to) {
45
46
  }
46
47
  const major = (payload[at] & 0b1110_0000) >> 5;
47
48
  const minor = payload[at] & 0b0001_1111;
49
+ if (minor === minorIndefinite && 2 <= major && major <= 5) {
50
+ return decodeIndefinite(at, to);
51
+ }
48
52
  switch (major) {
49
53
  case majorUint64:
50
54
  case majorNegativeInt64:
51
- case majorTag:
55
+ case majorTag: {
52
56
  let unsignedInt;
53
57
  let offset;
54
58
  if (minor < 24) {
@@ -58,31 +62,43 @@ function decode(at, to) {
58
62
  else {
59
63
  switch (minor) {
60
64
  case extendedOneByte:
61
- case extendedFloat16:
62
- case extendedFloat32:
63
- case extendedFloat64:
64
- const countLength = minorValueToArgumentLength[minor];
65
- const countOffset = (countLength + 1);
66
- offset = countOffset;
67
- if (to - at < countOffset) {
68
- throw new Error(`countLength ${countLength} greater than remaining buf len.`);
65
+ if (to - at < 2) {
66
+ overflow(1);
69
67
  }
70
- const countIndex = at + 1;
71
- if (countLength === 1) {
72
- unsignedInt = payload[countIndex];
68
+ unsignedInt = payload[at + 1];
69
+ offset = 2;
70
+ break;
71
+ case extendedFloat16:
72
+ if (to - at < 3) {
73
+ overflow(2);
73
74
  }
74
- else if (countLength === 2) {
75
- unsignedInt = dataView$1.getUint16(countIndex);
75
+ unsignedInt = dataView$1.getUint16(at + 1);
76
+ offset = 3;
77
+ break;
78
+ case extendedFloat32:
79
+ if (to - at < 5) {
80
+ overflow(4);
76
81
  }
77
- else if (countLength === 4) {
78
- unsignedInt = dataView$1.getUint32(countIndex);
82
+ unsignedInt = dataView$1.getUint32(at + 1);
83
+ offset = 5;
84
+ break;
85
+ case extendedFloat64:
86
+ if (to - at < 9) {
87
+ overflow(8);
79
88
  }
80
- else {
81
- unsignedInt = dataView$1.getBigUint64(countIndex);
89
+ {
90
+ const hi = dataView$1.getUint32(at + 1);
91
+ if (hi < 0x00200000) {
92
+ unsignedInt = hi * 4294967296 + dataView$1.getUint32(at + 5);
93
+ }
94
+ else {
95
+ unsignedInt = dataView$1.getBigUint64(at + 1);
96
+ }
82
97
  }
98
+ offset = 9;
83
99
  break;
84
100
  default:
85
- throw new Error(`unexpected minor value ${minor}.`);
101
+ unexpectedMinor(minor);
86
102
  }
87
103
  }
88
104
  if (major === majorUint64) {
@@ -101,234 +117,97 @@ function decode(at, to) {
101
117
  return castBigInt(negativeInt);
102
118
  }
103
119
  else {
104
- if (minor === 2 || minor === 3) {
105
- const length = decodeCount(at + offset, to);
106
- let b = BigInt(0);
107
- const start = at + offset + _offset;
108
- for (let i = start; i < start + length; ++i) {
109
- b = (b << BigInt(8)) | BigInt(payload[i]);
110
- }
111
- _offset = offset + _offset + length;
112
- return minor === 3 ? -b - BigInt(1) : b;
113
- }
114
- else if (minor === 4) {
115
- const decimalFraction = decode(at + offset, to);
116
- const [exponent, mantissa] = decimalFraction;
117
- const normalizer = mantissa < 0 ? -1 : 1;
118
- const mantissaStr = "0".repeat(Math.abs(exponent) + 1) + String(BigInt(normalizer) * BigInt(mantissa));
119
- let numericString;
120
- const sign = mantissa < 0 ? "-" : "";
121
- numericString =
122
- exponent === 0
123
- ? mantissaStr
124
- : mantissaStr.slice(0, mantissaStr.length + exponent) + "." + mantissaStr.slice(exponent);
125
- numericString = numericString.replace(/^0+/g, "");
126
- if (numericString === "") {
127
- numericString = "0";
128
- }
129
- if (numericString[0] === ".") {
130
- numericString = "0" + numericString;
131
- }
132
- numericString = sign + numericString;
133
- _offset = offset + _offset;
134
- return nv(numericString);
135
- }
136
- else {
137
- const value = decode(at + offset, to);
138
- const valueOffset = _offset;
139
- _offset = offset + valueOffset;
140
- return tag({ tag: castBigInt(unsignedInt), value });
141
- }
120
+ return decodeTagValue(at, to, minor, unsignedInt, offset);
142
121
  }
122
+ }
143
123
  case majorUtf8String:
124
+ return decodeUtf8String(at, to);
144
125
  case majorMap:
126
+ return decodeMap(at, to);
145
127
  case majorList:
128
+ return decodeList(at, to);
146
129
  case majorUnstructuredByteString:
147
- if (minor === minorIndefinite) {
148
- switch (major) {
149
- case majorUtf8String:
150
- return decodeUtf8StringIndefinite(at, to);
151
- case majorMap:
152
- return decodeMapIndefinite(at, to);
153
- case majorList:
154
- return decodeListIndefinite(at, to);
155
- case majorUnstructuredByteString:
156
- return decodeUnstructuredByteStringIndefinite(at, to);
157
- }
158
- }
159
- else {
160
- switch (major) {
161
- case majorUtf8String:
162
- return decodeUtf8String(at, to);
163
- case majorMap:
164
- return decodeMap(at, to);
165
- case majorList:
166
- return decodeList(at, to);
167
- case majorUnstructuredByteString:
168
- return decodeUnstructuredByteString(at, to);
169
- }
170
- }
130
+ return decodeUnstructuredByteString(at, to);
171
131
  default:
172
132
  return decodeSpecial(at, to);
173
133
  }
174
134
  }
175
- function bytesToUtf8(bytes, at, to) {
176
- if (USE_BUFFER$1 && bytes.constructor?.name === "Buffer") {
177
- return bytes.toString("utf-8", at, to);
178
- }
179
- if (textDecoder) {
180
- return textDecoder.decode(bytes.subarray(at, to));
181
- }
182
- return toUtf8(bytes.subarray(at, to));
183
- }
184
- function demote(bigInteger) {
185
- const num = Number(bigInteger);
186
- if (num < Number.MIN_SAFE_INTEGER || Number.MAX_SAFE_INTEGER < num) {
187
- console.warn(new Error(`@smithy/core/cbor - truncating BigInt(${bigInteger}) to ${num} with loss of precision.`));
135
+ function decodeIndefinite(at, to) {
136
+ const major = (payload[at] & 0b1110_0000) >> 5;
137
+ const minor = payload[at] & 0b0001_1111;
138
+ if (minor === minorIndefinite) {
139
+ switch (major) {
140
+ case majorUtf8String:
141
+ return decodeUtf8StringIndefinite(at, to);
142
+ case majorMap:
143
+ return decodeMapIndefinite(at, to);
144
+ case majorList:
145
+ return decodeListIndefinite(at, to);
146
+ case majorUnstructuredByteString:
147
+ return decodeUnstructuredByteStringIndefinite(at, to);
148
+ }
188
149
  }
189
- return num;
190
150
  }
191
- const minorValueToArgumentLength = {
192
- [extendedOneByte]: 1,
193
- [extendedFloat16]: 2,
194
- [extendedFloat32]: 4,
195
- [extendedFloat64]: 8,
196
- };
197
151
  function bytesToFloat16(a, b) {
198
152
  const sign = a >> 7;
199
153
  const exponent = (a & 0b0111_1100) >> 2;
200
154
  const fraction = ((a & 0b0000_0011) << 8) | b;
201
155
  const scalar = sign === 0 ? 1 : -1;
202
- let exponentComponent;
203
- let summation;
204
156
  if (exponent === 0b00000) {
205
- if (fraction === 0b00000_00000) {
157
+ if (fraction === 0) {
206
158
  return 0;
207
159
  }
208
- else {
209
- exponentComponent = Math.pow(2, 1 - 15);
210
- summation = 0;
211
- }
160
+ return scalar * (Math.pow(2, 1 - 15) * (fraction / 1024));
212
161
  }
213
162
  else if (exponent === 0b11111) {
214
- if (fraction === 0b00000_00000) {
163
+ if (fraction === 0) {
215
164
  return scalar * Infinity;
216
165
  }
217
- else {
218
- return NaN;
219
- }
166
+ return NaN;
220
167
  }
221
- else {
222
- exponentComponent = Math.pow(2, exponent - 15);
223
- summation = 1;
224
- }
225
- summation += fraction / 1024;
226
- return scalar * (exponentComponent * summation);
168
+ return scalar * (Math.pow(2, exponent - 15) * (1 + fraction / 1024));
227
169
  }
228
- function decodeCount(at, to) {
229
- const minor = payload[at] & 0b0001_1111;
230
- if (minor < 24) {
231
- _offset = 1;
232
- return minor;
233
- }
234
- if (minor === extendedOneByte ||
235
- minor === extendedFloat16 ||
236
- minor === extendedFloat32 ||
237
- minor === extendedFloat64) {
238
- const countLength = minorValueToArgumentLength[minor];
239
- _offset = (countLength + 1);
240
- if (to - at < _offset) {
241
- throw new Error(`countLength ${countLength} greater than remaining buf len.`);
242
- }
243
- const countIndex = at + 1;
244
- if (countLength === 1) {
245
- return payload[countIndex];
246
- }
247
- else if (countLength === 2) {
248
- return dataView$1.getUint16(countIndex);
249
- }
250
- else if (countLength === 4) {
251
- return dataView$1.getUint32(countIndex);
252
- }
253
- return demote(dataView$1.getBigUint64(countIndex));
170
+ function decodeMap(at, to) {
171
+ const mapDataLength = decodeCount(at, to);
172
+ if (mapDataLength < 15) {
173
+ return decodeMapSmall(at, to, mapDataLength);
254
174
  }
255
- throw new Error(`unexpected minor value ${minor}.`);
175
+ return decodeMapLarge(at, to, mapDataLength);
256
176
  }
257
- function decodeUtf8String(at, to) {
258
- const length = decodeCount(at, to);
177
+ function decodeMapLarge(at, to, mapDataLength) {
259
178
  const offset = _offset;
260
179
  at += offset;
261
- if (to - at < length) {
262
- throw new Error(`string len ${length} greater than remaining buf len.`);
263
- }
264
- const value = bytesToUtf8(payload, at, at + length);
265
- _offset = offset + length;
266
- return value;
267
- }
268
- function decodeUtf8StringIndefinite(at, to) {
269
- at += 1;
270
- const vector = [];
271
- for (const base = at; at < to;) {
272
- if (payload[at] === 0b1111_1111) {
273
- const data = alloc(vector.length);
274
- data.set(vector, 0);
275
- _offset = at - base + 2;
276
- return bytesToUtf8(data, 0, data.length);
277
- }
278
- const major = (payload[at] & 0b1110_0000) >> 5;
279
- const minor = payload[at] & 0b0001_1111;
280
- if (major !== majorUtf8String) {
281
- throw new Error(`unexpected major type ${major} in indefinite string.`);
282
- }
283
- if (minor === minorIndefinite) {
284
- throw new Error("nested indefinite string.");
180
+ const base = at;
181
+ const map = Object.create(null);
182
+ for (let i = 0; i < mapDataLength; ++i) {
183
+ const key = decodeUtf8String(at, to);
184
+ at += _offset;
185
+ const valMajor = (payload[at] & 0b1110_0000) >> 5;
186
+ if (valMajor === majorUtf8String) {
187
+ map[key] = decodeUtf8String(at, to);
285
188
  }
286
- const bytes = decodeUnstructuredByteString(at, to);
287
- const length = _offset;
288
- at += length;
289
- for (let i = 0; i < bytes.length; ++i) {
290
- vector.push(bytes[i]);
189
+ else {
190
+ map[key] = decode(at, to);
291
191
  }
192
+ at += _offset;
292
193
  }
293
- throw new Error("expected break marker.");
194
+ _offset = offset + (at - base);
195
+ Object.setPrototypeOf(map, Object.prototype);
196
+ return map;
294
197
  }
295
- function decodeUnstructuredByteString(at, to) {
296
- const length = decodeCount(at, to);
198
+ function decodeMapSmall(at, to, mapDataLength) {
297
199
  const offset = _offset;
298
200
  at += offset;
299
- if (to - at < length) {
300
- throw new Error(`unstructured byte string len ${length} greater than remaining buf len.`);
301
- }
302
- const value = payload.subarray(at, at + length);
303
- _offset = offset + length;
304
- return value;
305
- }
306
- function decodeUnstructuredByteStringIndefinite(at, to) {
307
- at += 1;
308
- const vector = [];
309
- for (const base = at; at < to;) {
310
- if (payload[at] === 0b1111_1111) {
311
- const data = alloc(vector.length);
312
- data.set(vector, 0);
313
- _offset = at - base + 2;
314
- return data;
315
- }
316
- const major = (payload[at] & 0b1110_0000) >> 5;
317
- const minor = payload[at] & 0b0001_1111;
318
- if (major !== majorUnstructuredByteString) {
319
- throw new Error(`unexpected major type ${major} in indefinite string.`);
320
- }
321
- if (minor === minorIndefinite) {
322
- throw new Error("nested indefinite string.");
323
- }
324
- const bytes = decodeUnstructuredByteString(at, to);
325
- const length = _offset;
326
- at += length;
327
- for (let i = 0; i < bytes.length; ++i) {
328
- vector.push(bytes[i]);
329
- }
201
+ const base = at;
202
+ const map = {};
203
+ for (let i = 0; i < mapDataLength; ++i) {
204
+ const key = decodeUtf8String(at, to);
205
+ at += _offset;
206
+ map[key] = decode(at, to);
207
+ at += _offset;
330
208
  }
331
- throw new Error("expected break marker.");
209
+ _offset = offset + (at - base);
210
+ return map;
332
211
  }
333
212
  function decodeList(at, to) {
334
213
  const listDataLength = decodeCount(at, to);
@@ -337,75 +216,115 @@ function decodeList(at, to) {
337
216
  const base = at;
338
217
  const list = Array(listDataLength);
339
218
  for (let i = 0; i < listDataLength; ++i) {
340
- const item = decode(at, to);
341
- const itemOffset = _offset;
342
- list[i] = item;
343
- at += itemOffset;
219
+ list[i] = decode(at, to);
220
+ at += _offset;
344
221
  }
345
222
  _offset = offset + (at - base);
346
223
  return list;
347
224
  }
348
- function decodeListIndefinite(at, to) {
349
- at += 1;
350
- const list = [];
351
- for (const base = at; at < to;) {
352
- if (payload[at] === 0b1111_1111) {
353
- _offset = at - base + 2;
354
- return list;
225
+ function decodeUtf8String(at, to) {
226
+ const length = decodeCount(at, to);
227
+ const offset = _offset;
228
+ at += offset;
229
+ if (to - at < length) {
230
+ overflow(length);
231
+ }
232
+ _offset = offset + length;
233
+ if (length < 24) {
234
+ return decodeUtf8StringCached(at, length);
235
+ }
236
+ if (isBuffer) {
237
+ return payload.toString("utf-8", at, at + length);
238
+ }
239
+ return textDecoder.decode(payload.subarray(at, at + length));
240
+ }
241
+ const stringCache = new Array(2048);
242
+ const stringCacheEpochs = new Uint16Array(2048);
243
+ let cacheEpoch = 0;
244
+ function advanceDecodingEpoch() {
245
+ cacheEpoch = (cacheEpoch + 1) & 0b1111_1111_1111_1111;
246
+ }
247
+ function decodeUtf8StringCached(at, length) {
248
+ let h = length;
249
+ for (let i = 0; i < length; ++i) {
250
+ h = (h * 31 + payload[at + i]) | 0;
251
+ }
252
+ const slot = (h >>> 0) & 2047;
253
+ const cached = stringCache[slot];
254
+ if (cached !== undefined) {
255
+ if (cached.length === length) {
256
+ let match = true;
257
+ for (let i = 0; i < length; ++i) {
258
+ if (cached.charCodeAt(i) !== payload[at + i]) {
259
+ match = false;
260
+ break;
261
+ }
262
+ }
263
+ if (match) {
264
+ stringCacheEpochs[slot] = cacheEpoch;
265
+ return cached;
266
+ }
355
267
  }
356
- const item = decode(at, to);
357
- const n = _offset;
358
- at += n;
359
- list.push(item);
360
268
  }
361
- throw new Error("expected break marker.");
269
+ const result = isBuffer
270
+ ? payload.toString("utf-8", at, at + length)
271
+ : textDecoder.decode(payload.subarray(at, at + length));
272
+ if (stringCacheEpochs[slot] !== cacheEpoch) {
273
+ stringCache[slot] = result;
274
+ stringCacheEpochs[slot] = cacheEpoch;
275
+ }
276
+ return result;
362
277
  }
363
- function decodeMap(at, to) {
364
- const mapDataLength = decodeCount(at, to);
278
+ function decodeUnstructuredByteString(at, to) {
279
+ const length = decodeCount(at, to);
365
280
  const offset = _offset;
366
281
  at += offset;
367
- const base = at;
368
- const map = {};
369
- for (let i = 0; i < mapDataLength; ++i) {
370
- if (at >= to) {
371
- throw new Error("unexpected end of map payload.");
372
- }
373
- const major = (payload[at] & 0b1110_0000) >> 5;
374
- if (major !== majorUtf8String) {
375
- throw new Error(`unexpected major type ${major} for map key at index ${at}.`);
376
- }
377
- const key = decode(at, to);
378
- at += _offset;
379
- const value = decode(at, to);
380
- at += _offset;
381
- map[key] = value;
282
+ if (to - at < length) {
283
+ overflow(length);
382
284
  }
383
- _offset = offset + (at - base);
384
- return map;
285
+ const value = payload.subarray(at, at + length);
286
+ _offset = offset + length;
287
+ return value;
385
288
  }
386
- function decodeMapIndefinite(at, to) {
387
- at += 1;
388
- const base = at;
389
- const map = {};
390
- for (; at < to;) {
391
- if (at >= to) {
392
- throw new Error("unexpected end of map payload.");
289
+ function decodeTagValue(at, to, minor, unsignedInt, offset) {
290
+ if (minor === 2 || minor === 3) {
291
+ const length = decodeCount(at + offset, to);
292
+ let b = BigInt(0);
293
+ const start = at + offset + _offset;
294
+ for (let i = start; i < start + length; ++i) {
295
+ b = (b << BigInt(8)) | BigInt(payload[i]);
393
296
  }
394
- if (payload[at] === 0b1111_1111) {
395
- _offset = at - base + 2;
396
- return map;
297
+ _offset = offset + _offset + length;
298
+ return minor === 3 ? -b - BigInt(1) : b;
299
+ }
300
+ else if (minor === 4) {
301
+ const decimalFraction = decode(at + offset, to);
302
+ const [exponent, mantissa] = decimalFraction;
303
+ const normalizer = mantissa < 0 ? -1 : 1;
304
+ const mantissaStr = "0".repeat(Math.abs(exponent) + 1) + String(BigInt(normalizer) * BigInt(mantissa));
305
+ let numericString;
306
+ const sign = mantissa < 0 ? "-" : "";
307
+ numericString =
308
+ exponent === 0
309
+ ? mantissaStr
310
+ : mantissaStr.slice(0, mantissaStr.length + exponent) + "." + mantissaStr.slice(exponent);
311
+ numericString = numericString.replace(/^0+/g, "");
312
+ if (numericString === "") {
313
+ numericString = "0";
397
314
  }
398
- const major = (payload[at] & 0b1110_0000) >> 5;
399
- if (major !== majorUtf8String) {
400
- throw new Error(`unexpected major type ${major} for map key.`);
315
+ if (numericString[0] === ".") {
316
+ numericString = "0" + numericString;
401
317
  }
402
- const key = decode(at, to);
403
- at += _offset;
404
- const value = decode(at, to);
405
- at += _offset;
406
- map[key] = value;
318
+ numericString = sign + numericString;
319
+ _offset = offset + _offset;
320
+ return nv(numericString);
321
+ }
322
+ else {
323
+ const value = decode(at + offset, to);
324
+ const valueOffset = _offset;
325
+ _offset = offset + valueOffset;
326
+ return tag({ tag: castBigInt(unsignedInt), value });
407
327
  }
408
- throw new Error("expected break marker.");
409
328
  }
410
329
  function decodeSpecial(at, to) {
411
330
  const minor = payload[at] & 0b0001_1111;
@@ -439,98 +358,216 @@ function decodeSpecial(at, to) {
439
358
  _offset = 9;
440
359
  return dataView$1.getFloat64(at + 1);
441
360
  default:
442
- throw new Error(`unexpected minor value ${minor}.`);
361
+ unexpectedMinor(minor);
443
362
  }
444
363
  }
445
- function castBigInt(bigInt) {
446
- if (typeof bigInt === "number") {
447
- return bigInt;
364
+ function decodeCount(at, to) {
365
+ const minor = payload[at] & 0b0001_1111;
366
+ if (minor < 24) {
367
+ _offset = 1;
368
+ return minor;
448
369
  }
449
- const num = Number(bigInt);
450
- if (Number.MIN_SAFE_INTEGER <= num && num <= Number.MAX_SAFE_INTEGER) {
451
- return num;
370
+ switch (minor) {
371
+ case extendedOneByte:
372
+ if (to - at < 2) {
373
+ overflow(1);
374
+ }
375
+ _offset = 2;
376
+ return payload[at + 1];
377
+ case extendedFloat16:
378
+ if (to - at < 3) {
379
+ overflow(2);
380
+ }
381
+ _offset = 3;
382
+ return dataView$1.getUint16(at + 1);
383
+ case extendedFloat32:
384
+ if (to - at < 5) {
385
+ overflow(4);
386
+ }
387
+ _offset = 5;
388
+ return dataView$1.getUint32(at + 1);
389
+ case extendedFloat64:
390
+ if (to - at < 9) {
391
+ overflow(8);
392
+ }
393
+ _offset = 9;
394
+ return demote(dataView$1.getBigUint64(at + 1));
395
+ default:
396
+ unexpectedMinor(minor);
452
397
  }
453
- return bigInt;
454
398
  }
455
-
456
- const USE_BUFFER = typeof Buffer !== "undefined";
457
- const initialSize = 2048;
458
- let data = alloc(initialSize);
459
- let dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);
460
- let cursor = 0;
461
- function ensureSpace(bytes) {
462
- const remaining = data.byteLength - cursor;
463
- if (remaining < bytes) {
464
- if (cursor < 16_000_000) {
465
- resize(Math.max(data.byteLength * 4, data.byteLength + bytes));
466
- }
467
- else {
468
- resize(data.byteLength + bytes + 16_000_000);
399
+ function decodeMapIndefinite(at, to) {
400
+ at += 1;
401
+ const base = at;
402
+ const map = {};
403
+ for (; at < to;) {
404
+ if (payload[at] === 0b1111_1111) {
405
+ _offset = at - base + 2;
406
+ return map;
469
407
  }
408
+ const key = decodeUtf8String(at, to);
409
+ at += _offset;
410
+ map[key] = decode(at, to);
411
+ at += _offset;
470
412
  }
413
+ throw new Error("expected break marker.");
471
414
  }
472
- function toUint8Array() {
473
- const out = alloc(cursor);
474
- out.set(data.subarray(0, cursor), 0);
475
- cursor = 0;
476
- return out;
415
+ function decodeListIndefinite(at, to) {
416
+ at += 1;
417
+ const list = [];
418
+ for (const base = at; at < to;) {
419
+ if (payload[at] === 0b1111_1111) {
420
+ _offset = at - base + 2;
421
+ return list;
422
+ }
423
+ list.push(decode(at, to));
424
+ at += _offset;
425
+ }
426
+ throw new Error("expected break marker.");
477
427
  }
478
- function resize(size) {
479
- const old = data;
480
- data = alloc(size);
481
- if (old) {
482
- if (old.copy) {
483
- old.copy(data, 0, 0, old.byteLength);
428
+ function decodeUtf8StringIndefinite(at, to) {
429
+ at += 1;
430
+ const vector = [];
431
+ for (const base = at; at < to;) {
432
+ if (payload[at] === 0b1111_1111) {
433
+ const data = alloc(vector.length);
434
+ data.set(vector, 0);
435
+ _offset = at - base + 2;
436
+ if (USE_BUFFER$1) {
437
+ return data.toString("utf-8", 0, data.length);
438
+ }
439
+ return textDecoder.decode(data);
484
440
  }
485
- else {
486
- data.set(old, 0);
441
+ const major = (payload[at] & 0b1110_0000) >> 5;
442
+ const minor = payload[at] & 0b0001_1111;
443
+ if (major !== majorUtf8String) {
444
+ unexpectedMajorInIndefiniteString(major);
445
+ }
446
+ if (minor === minorIndefinite) {
447
+ throw new Error("nested indefinite string.");
448
+ }
449
+ const bytes = decodeUnstructuredByteString(at, to);
450
+ const length = _offset;
451
+ at += length;
452
+ for (let i = 0; i < bytes.length; ++i) {
453
+ vector.push(bytes[i]);
487
454
  }
488
455
  }
489
- dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);
456
+ throw new Error("expected break marker.");
490
457
  }
491
- function encodeHeader(major, value) {
492
- if (value < 24) {
493
- data[cursor++] = (major << 5) | value;
494
- }
495
- else if (value < 1 << 8) {
496
- data[cursor++] = (major << 5) | 24;
497
- data[cursor++] = value;
458
+ function decodeUnstructuredByteStringIndefinite(at, to) {
459
+ at += 1;
460
+ const vector = [];
461
+ for (const base = at; at < to;) {
462
+ if (payload[at] === 0b1111_1111) {
463
+ const data = alloc(vector.length);
464
+ data.set(vector, 0);
465
+ _offset = at - base + 2;
466
+ return data;
467
+ }
468
+ const major = (payload[at] & 0b1110_0000) >> 5;
469
+ const minor = payload[at] & 0b0001_1111;
470
+ if (major !== majorUnstructuredByteString) {
471
+ unexpectedMajorInIndefiniteString(major);
472
+ }
473
+ if (minor === minorIndefinite) {
474
+ throw new Error("nested indefinite string.");
475
+ }
476
+ const bytes = decodeUnstructuredByteString(at, to);
477
+ const length = _offset;
478
+ at += length;
479
+ for (let i = 0; i < bytes.length; ++i) {
480
+ vector.push(bytes[i]);
481
+ }
498
482
  }
499
- else if (value < 1 << 16) {
500
- data[cursor++] = (major << 5) | extendedFloat16;
501
- dataView.setUint16(cursor, value);
502
- cursor += 2;
483
+ throw new Error("expected break marker.");
484
+ }
485
+ function castBigInt(bigInt) {
486
+ if (typeof bigInt === "number") {
487
+ return bigInt;
503
488
  }
504
- else if (value < 2 ** 32) {
505
- data[cursor++] = (major << 5) | extendedFloat32;
506
- dataView.setUint32(cursor, value);
507
- cursor += 4;
489
+ const num = Number(bigInt);
490
+ if (Number.MIN_SAFE_INTEGER <= num && num <= Number.MAX_SAFE_INTEGER) {
491
+ return num;
508
492
  }
509
- else {
510
- data[cursor++] = (major << 5) | extendedFloat64;
511
- dataView.setBigUint64(cursor, typeof value === "bigint" ? value : BigInt(value));
512
- cursor += 8;
493
+ return bigInt;
494
+ }
495
+ function demote(bigInteger) {
496
+ const num = Number(bigInteger);
497
+ if (num < Number.MIN_SAFE_INTEGER || Number.MAX_SAFE_INTEGER < num) {
498
+ console.warn(new Error(`@smithy/core/cbor - truncating BigInt(${bigInteger}) to ${num} with loss of precision.`));
513
499
  }
500
+ return num;
501
+ }
502
+ function overflow(n) {
503
+ throw new Error(`length ${n} greater than remaining buf len.`);
504
+ }
505
+ function unexpectedMinor(minor) {
506
+ throw new Error(`unexpected minor value ${minor}.`);
514
507
  }
508
+ function unexpectedMajorInIndefiniteString(major) {
509
+ throw new Error(`unexpected major type ${major} in indefinite string.`);
510
+ }
511
+
512
+ const USE_BUFFER = typeof Buffer !== "undefined";
513
+ const encodeStringCache = new Map();
514
+ let encodeCacheEpoch = 0;
515
+ let encodeCacheSaturated = false;
516
+ const initialSize = 2048;
517
+ let data = alloc(initialSize);
518
+ let dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);
519
+ let cursor = 0;
515
520
  function encode(_input) {
516
521
  const encodeStack = [_input];
517
522
  while (encodeStack.length) {
518
523
  const input = encodeStack.pop();
519
- ensureSpace(typeof input === "string" ? input.length * 4 : 64);
520
524
  if (typeof input === "string") {
525
+ const len = input.length;
521
526
  if (USE_BUFFER) {
522
- encodeHeader(majorUtf8String, Buffer.byteLength(input));
523
- cursor += data.write(input, cursor);
527
+ ensureSpace(len * 3 + 9);
528
+ if (len > 23) {
529
+ encodeHeader(majorUtf8String, Buffer.byteLength(input));
530
+ cursor += data.write(input, cursor);
531
+ }
532
+ else {
533
+ encodeStringCached(input);
534
+ }
524
535
  }
525
536
  else {
526
- const bytes = fromUtf8(input);
527
- encodeHeader(majorUtf8String, bytes.byteLength);
528
- data.set(bytes, cursor);
529
- cursor += bytes.byteLength;
537
+ const maxBytes = len * 3;
538
+ ensureSpace(maxBytes + 9);
539
+ const headerPos = cursor;
540
+ const result = new TextEncoder().encodeInto(input, data.subarray(cursor + 9));
541
+ const byteLen = result.written;
542
+ let headerSize;
543
+ if (byteLen < 24) {
544
+ headerSize = 1;
545
+ }
546
+ else if (byteLen < 256) {
547
+ headerSize = 2;
548
+ }
549
+ else if (byteLen < 65536) {
550
+ headerSize = 3;
551
+ }
552
+ else if (byteLen < 4294967296) {
553
+ headerSize = 5;
554
+ }
555
+ else {
556
+ headerSize = 9;
557
+ }
558
+ if (headerSize < 9) {
559
+ data.copyWithin(headerPos + headerSize, headerPos + 9, headerPos + 9 + byteLen);
560
+ }
561
+ cursor = headerPos;
562
+ encodeInteger(majorUtf8String, byteLen);
563
+ cursor += byteLen;
530
564
  }
531
565
  continue;
532
566
  }
533
- else if (typeof input === "number") {
567
+ if (data.byteLength - cursor < 9) {
568
+ ensureSpace(64);
569
+ }
570
+ if (typeof input === "number") {
534
571
  if (Number.isInteger(input)) {
535
572
  const nonNegative = input >= 0;
536
573
  const major = nonNegative ? majorUint64 : majorNegativeInt64;
@@ -545,7 +582,7 @@ function encode(_input) {
545
582
  else if (value < 65536) {
546
583
  data[cursor++] = (major << 5) | extendedFloat16;
547
584
  data[cursor++] = value >> 8;
548
- data[cursor++] = value;
585
+ data[cursor++] = value & 0xff;
549
586
  }
550
587
  else if (value < 4294967296) {
551
588
  data[cursor++] = (major << 5) | extendedFloat32;
@@ -554,7 +591,10 @@ function encode(_input) {
554
591
  }
555
592
  else {
556
593
  data[cursor++] = (major << 5) | extendedFloat64;
557
- dataView.setBigUint64(cursor, BigInt(value));
594
+ const hi = (value / 4294967296) | 0;
595
+ const lo = (value - hi * 4294967296) | 0;
596
+ dataView.setUint32(cursor, hi);
597
+ dataView.setUint32(cursor + 4, lo);
558
598
  cursor += 8;
559
599
  }
560
600
  continue;
@@ -568,28 +608,16 @@ function encode(_input) {
568
608
  const nonNegative = input >= 0;
569
609
  const major = nonNegative ? majorUint64 : majorNegativeInt64;
570
610
  const value = nonNegative ? input : -input - BigInt(1);
571
- const n = Number(value);
572
- if (n < 24) {
573
- data[cursor++] = (major << 5) | n;
574
- }
575
- else if (n < 256) {
576
- data[cursor++] = (major << 5) | 24;
577
- data[cursor++] = n;
578
- }
579
- else if (n < 65536) {
580
- data[cursor++] = (major << 5) | extendedFloat16;
581
- data[cursor++] = n >> 8;
582
- data[cursor++] = n & 0b1111_1111;
583
- }
584
- else if (n < 4294967296) {
585
- data[cursor++] = (major << 5) | extendedFloat32;
586
- dataView.setUint32(cursor, n);
587
- cursor += 4;
588
- }
589
- else if (value < BigInt("18446744073709551616")) {
590
- data[cursor++] = (major << 5) | extendedFloat64;
591
- dataView.setBigUint64(cursor, value);
592
- cursor += 8;
611
+ if (value < BigInt("18446744073709551616")) {
612
+ const n = Number(value);
613
+ if (n < 4294967296) {
614
+ encodeInteger(major, n);
615
+ }
616
+ else {
617
+ data[cursor++] = (major << 5) | extendedFloat64;
618
+ dataView.setBigUint64(cursor, value);
619
+ cursor += 8;
620
+ }
593
621
  }
594
622
  else {
595
623
  const binaryBigInt = value.toString(2);
@@ -600,14 +628,9 @@ function encode(_input) {
600
628
  bigIntBytes[bigIntBytes.byteLength - i] = Number(b & BigInt(255));
601
629
  b >>= BigInt(8);
602
630
  }
603
- ensureSpace(bigIntBytes.byteLength * 2);
631
+ ensureSpace(bigIntBytes.byteLength * 2 + 16);
604
632
  data[cursor++] = nonNegative ? 0b110_00010 : 0b110_00011;
605
- if (USE_BUFFER) {
606
- encodeHeader(majorUnstructuredByteString, Buffer.byteLength(bigIntBytes));
607
- }
608
- else {
609
- encodeHeader(majorUnstructuredByteString, bigIntBytes.byteLength);
610
- }
633
+ encodeHeader(majorUnstructuredByteString, bigIntBytes.byteLength);
611
634
  data.set(bigIntBytes, cursor);
612
635
  cursor += bigIntBytes.byteLength;
613
636
  }
@@ -625,15 +648,16 @@ function encode(_input) {
625
648
  throw new Error("@smithy/core/cbor: client may not serialize undefined value.");
626
649
  }
627
650
  else if (Array.isArray(input)) {
651
+ encodeInteger(majorList, input.length);
652
+ ensureSpace(input.length * 9 + 64);
628
653
  for (let i = input.length - 1; i >= 0; --i) {
629
654
  encodeStack.push(input[i]);
630
655
  }
631
- encodeHeader(majorList, input.length);
632
656
  continue;
633
657
  }
634
658
  else if (typeof input.byteLength === "number") {
635
- ensureSpace(input.length * 2);
636
- encodeHeader(majorUnstructuredByteString, input.length);
659
+ ensureSpace(input.length * 2 + 9);
660
+ encodeInteger(majorUnstructuredByteString, input.length);
637
661
  data.set(input, cursor);
638
662
  cursor += input.byteLength;
639
663
  continue;
@@ -644,9 +668,9 @@ function encode(_input) {
644
668
  const exponent = decimalIndex === -1 ? 0 : decimalIndex - input.string.length + 1;
645
669
  const mantissa = BigInt(input.string.replace(".", ""));
646
670
  data[cursor++] = 0b110_00100;
671
+ encodeInteger(majorList, 2);
647
672
  encodeStack.push(mantissa);
648
673
  encodeStack.push(exponent);
649
- encodeHeader(majorList, 2);
650
674
  continue;
651
675
  }
652
676
  if (input[tagSymbol]) {
@@ -660,24 +684,147 @@ function encode(_input) {
660
684
  }
661
685
  }
662
686
  const keys = Object.keys(input);
663
- for (let i = keys.length - 1; i >= 0; --i) {
664
- const key = keys[i];
665
- encodeStack.push(input[key]);
666
- encodeStack.push(key);
687
+ const len = keys.length;
688
+ encodeInteger(majorMap, len);
689
+ for (let i = len - 1; i >= 0; --i) {
690
+ encodeStack.push(input[keys[i]]);
691
+ encodeStack.push(keys[i]);
667
692
  }
668
- encodeHeader(majorMap, keys.length);
669
693
  continue;
670
694
  }
671
695
  throw new Error(`data type ${input?.constructor?.name ?? typeof input} not compatible for encoding.`);
672
696
  }
673
697
  }
698
+ function advanceEncodingEpoch() {
699
+ encodeCacheEpoch = (encodeCacheEpoch + 1) & 0b1111_1111_1111_1111;
700
+ encodeCacheSaturated = false;
701
+ }
702
+ function toUint8Array() {
703
+ const out = alloc(cursor);
704
+ out.set(data.subarray(0, cursor), 0);
705
+ cursor = 0;
706
+ return out;
707
+ }
708
+ function resize(size) {
709
+ const old = data;
710
+ data = alloc(size);
711
+ if (old) {
712
+ if (old.copy) {
713
+ old.copy(data, 0, 0, old.byteLength);
714
+ }
715
+ else {
716
+ data.set(old, 0);
717
+ }
718
+ }
719
+ dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);
720
+ }
721
+ function encodeStringCached(input) {
722
+ const cached = encodeStringCache.get(input);
723
+ if (cached !== undefined) {
724
+ data.set(cached.bytes, cursor);
725
+ cursor += cached.bytes.length;
726
+ cached.epoch = encodeCacheEpoch;
727
+ return;
728
+ }
729
+ const start = cursor;
730
+ const byteLen = Buffer.byteLength(input);
731
+ encodeInteger(majorUtf8String, byteLen);
732
+ cursor += data.write(input, cursor);
733
+ const bytes = Uint8Array.prototype.slice.call(data, start, cursor);
734
+ if (encodeStringCache.size >= 2048) {
735
+ if (encodeCacheSaturated) {
736
+ return;
737
+ }
738
+ let evicted = 0;
739
+ for (const [key, entry] of encodeStringCache) {
740
+ if (evicted >= 1024) {
741
+ break;
742
+ }
743
+ if (entry.epoch !== encodeCacheEpoch) {
744
+ encodeStringCache.delete(key);
745
+ evicted++;
746
+ }
747
+ }
748
+ if (evicted === 0) {
749
+ encodeCacheSaturated = true;
750
+ return;
751
+ }
752
+ }
753
+ if (encodeStringCache.size < 2048) {
754
+ encodeStringCache.set(input, { epoch: encodeCacheEpoch, bytes });
755
+ }
756
+ }
757
+ function ensureSpace(bytes) {
758
+ const remaining = data.byteLength - cursor;
759
+ if (remaining < bytes) {
760
+ if (cursor < 16_000_000) {
761
+ resize(Math.max(data.byteLength * 4, data.byteLength + bytes));
762
+ }
763
+ else {
764
+ resize(data.byteLength + bytes + 16_000_000);
765
+ }
766
+ }
767
+ }
768
+ function encodeHeader(major, value) {
769
+ if (value < 24) {
770
+ data[cursor++] = (major << 5) | value;
771
+ }
772
+ else if (value < 256) {
773
+ data[cursor++] = (major << 5) | 24;
774
+ data[cursor++] = value;
775
+ }
776
+ else if (value < 65536) {
777
+ data[cursor++] = (major << 5) | extendedFloat16;
778
+ dataView.setUint16(cursor, value);
779
+ cursor += 2;
780
+ }
781
+ else if (value < 4294967296) {
782
+ data[cursor++] = (major << 5) | extendedFloat32;
783
+ dataView.setUint32(cursor, value);
784
+ cursor += 4;
785
+ }
786
+ else {
787
+ data[cursor++] = (major << 5) | extendedFloat64;
788
+ dataView.setBigUint64(cursor, typeof value === "bigint" ? value : BigInt(value));
789
+ cursor += 8;
790
+ }
791
+ }
792
+ function encodeInteger(major, value) {
793
+ if (value < 24) {
794
+ data[cursor++] = (major << 5) | value;
795
+ }
796
+ else if (value < 256) {
797
+ data[cursor++] = (major << 5) | 24;
798
+ data[cursor++] = value;
799
+ }
800
+ else if (value < 65536) {
801
+ data[cursor++] = (major << 5) | extendedFloat16;
802
+ data[cursor++] = value >> 8;
803
+ data[cursor++] = value & 0xff;
804
+ }
805
+ else if (value < 4294967296) {
806
+ data[cursor++] = (major << 5) | extendedFloat32;
807
+ dataView.setUint32(cursor, value);
808
+ cursor += 4;
809
+ }
810
+ else {
811
+ data[cursor++] = (major << 5) | extendedFloat64;
812
+ const hi = (value / 4294967296) | 0;
813
+ const lo = (value - hi * 4294967296) | 0;
814
+ dataView.setUint32(cursor, hi);
815
+ dataView.setUint32(cursor + 4, lo);
816
+ cursor += 8;
817
+ }
818
+ }
674
819
 
675
820
  const cbor = {
676
821
  deserialize(payload) {
822
+ advanceDecodingEpoch();
677
823
  setPayload(payload);
678
824
  return decode(0, payload.length);
679
825
  },
680
826
  serialize(input) {
827
+ advanceEncodingEpoch();
681
828
  try {
682
829
  encode(input);
683
830
  return toUint8Array();