@smithy/core 3.3.3 → 3.5.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.
Files changed (116) hide show
  1. package/dist-cjs/submodules/cbor/index.js +212 -2
  2. package/dist-cjs/submodules/protocols/index.js +667 -2
  3. package/dist-cjs/submodules/schema/index.js +771 -0
  4. package/dist-cjs/submodules/serde/index.js +680 -2
  5. package/dist-es/submodules/cbor/CborCodec.js +136 -0
  6. package/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +74 -0
  7. package/dist-es/submodules/cbor/index.js +3 -1
  8. package/dist-es/submodules/cbor/parseCborBody.js +3 -2
  9. package/dist-es/submodules/protocols/HttpBindingProtocol.js +183 -0
  10. package/dist-es/submodules/protocols/HttpProtocol.js +164 -0
  11. package/dist-es/submodules/protocols/RpcProtocol.js +68 -0
  12. package/dist-es/submodules/protocols/index.js +7 -0
  13. package/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +64 -0
  14. package/dist-es/submodules/protocols/serde/HttpInterceptingShapeDeserializer.js +38 -0
  15. package/dist-es/submodules/protocols/serde/HttpInterceptingShapeSerializer.js +30 -0
  16. package/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js +87 -0
  17. package/dist-es/submodules/protocols/serde/determineTimestampFormat.js +20 -0
  18. package/dist-es/submodules/schema/TypeRegistry.js +49 -0
  19. package/dist-es/submodules/schema/deref.js +6 -0
  20. package/dist-es/submodules/schema/index.js +12 -0
  21. package/dist-es/submodules/schema/middleware/getSchemaSerdePlugin.js +23 -0
  22. package/dist-es/submodules/schema/middleware/schema-middleware-types.js +1 -0
  23. package/dist-es/submodules/schema/middleware/schemaDeserializationMiddleware.js +60 -0
  24. package/dist-es/submodules/schema/middleware/schemaSerializationMiddleware.js +16 -0
  25. package/dist-es/submodules/schema/schemas/ErrorSchema.js +17 -0
  26. package/dist-es/submodules/schema/schemas/ListSchema.js +15 -0
  27. package/dist-es/submodules/schema/schemas/MapSchema.js +16 -0
  28. package/dist-es/submodules/schema/schemas/NormalizedSchema.js +291 -0
  29. package/dist-es/submodules/schema/schemas/OperationSchema.js +16 -0
  30. package/dist-es/submodules/schema/schemas/Schema.js +6 -0
  31. package/dist-es/submodules/schema/schemas/SimpleSchema.js +15 -0
  32. package/dist-es/submodules/schema/schemas/StructureSchema.js +22 -0
  33. package/dist-es/submodules/schema/schemas/sentinels.js +16 -0
  34. package/dist-es/submodules/serde/copyDocumentWithTransform.js +53 -0
  35. package/dist-es/submodules/serde/date-utils.js +190 -0
  36. package/dist-es/submodules/serde/index.js +7 -0
  37. package/dist-es/submodules/serde/lazy-json.js +24 -0
  38. package/dist-es/submodules/serde/parse-utils.js +230 -0
  39. package/dist-es/submodules/serde/quote-header.js +6 -0
  40. package/dist-es/submodules/serde/split-every.js +27 -0
  41. package/dist-es/submodules/serde/split-header.js +37 -0
  42. package/dist-types/submodules/cbor/CborCodec.d.ts +29 -0
  43. package/dist-types/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +22 -0
  44. package/dist-types/submodules/cbor/index.d.ts +3 -1
  45. package/dist-types/submodules/protocols/HttpBindingProtocol.d.ts +15 -0
  46. package/dist-types/submodules/protocols/HttpProtocol.d.ts +29 -0
  47. package/dist-types/submodules/protocols/RpcProtocol.d.ts +11 -0
  48. package/dist-types/submodules/protocols/index.d.ts +7 -0
  49. package/dist-types/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +14 -0
  50. package/dist-types/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +18 -0
  51. package/dist-types/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +20 -0
  52. package/dist-types/submodules/protocols/serde/ToStringShapeSerializer.d.ts +15 -0
  53. package/dist-types/submodules/protocols/serde/determineTimestampFormat.d.ts +9 -0
  54. package/dist-types/submodules/schema/TypeRegistry.d.ts +55 -0
  55. package/dist-types/submodules/schema/deref.d.ts +6 -0
  56. package/dist-types/submodules/schema/index.d.ts +12 -0
  57. package/dist-types/submodules/schema/middleware/getSchemaSerdePlugin.d.ts +14 -0
  58. package/dist-types/submodules/schema/middleware/schema-middleware-types.d.ts +8 -0
  59. package/dist-types/submodules/schema/middleware/schemaDeserializationMiddleware.d.ts +9 -0
  60. package/dist-types/submodules/schema/middleware/schemaSerializationMiddleware.d.ts +6 -0
  61. package/dist-types/submodules/schema/schemas/ErrorSchema.d.ts +38 -0
  62. package/dist-types/submodules/schema/schemas/ListSchema.d.ts +20 -0
  63. package/dist-types/submodules/schema/schemas/MapSchema.d.ts +25 -0
  64. package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +122 -0
  65. package/dist-types/submodules/schema/schemas/OperationSchema.d.ts +20 -0
  66. package/dist-types/submodules/schema/schemas/Schema.d.ts +11 -0
  67. package/dist-types/submodules/schema/schemas/SimpleSchema.d.ts +20 -0
  68. package/dist-types/submodules/schema/schemas/StructureSchema.d.ts +21 -0
  69. package/dist-types/submodules/schema/schemas/sentinels.d.ts +21 -0
  70. package/dist-types/submodules/serde/copyDocumentWithTransform.d.ts +5 -0
  71. package/dist-types/submodules/serde/date-utils.d.ts +73 -0
  72. package/dist-types/submodules/serde/index.d.ts +7 -0
  73. package/dist-types/submodules/serde/lazy-json.d.ts +45 -0
  74. package/dist-types/submodules/serde/parse-utils.d.ts +270 -0
  75. package/dist-types/submodules/serde/quote-header.d.ts +6 -0
  76. package/dist-types/submodules/serde/split-every.d.ts +11 -0
  77. package/dist-types/submodules/serde/split-header.d.ts +5 -0
  78. package/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +29 -0
  79. package/dist-types/ts3.4/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +22 -0
  80. package/dist-types/ts3.4/submodules/cbor/index.d.ts +3 -1
  81. package/dist-types/ts3.4/submodules/protocols/HttpBindingProtocol.d.ts +15 -0
  82. package/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +29 -0
  83. package/dist-types/ts3.4/submodules/protocols/RpcProtocol.d.ts +11 -0
  84. package/dist-types/ts3.4/submodules/protocols/index.d.ts +7 -0
  85. package/dist-types/ts3.4/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +14 -0
  86. package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +18 -0
  87. package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +20 -0
  88. package/dist-types/ts3.4/submodules/protocols/serde/ToStringShapeSerializer.d.ts +15 -0
  89. package/dist-types/ts3.4/submodules/protocols/serde/determineTimestampFormat.d.ts +9 -0
  90. package/dist-types/ts3.4/submodules/schema/TypeRegistry.d.ts +55 -0
  91. package/dist-types/ts3.4/submodules/schema/deref.d.ts +6 -0
  92. package/dist-types/ts3.4/submodules/schema/index.d.ts +12 -0
  93. package/dist-types/ts3.4/submodules/schema/middleware/getSchemaSerdePlugin.d.ts +14 -0
  94. package/dist-types/ts3.4/submodules/schema/middleware/schema-middleware-types.d.ts +11 -0
  95. package/dist-types/ts3.4/submodules/schema/middleware/schemaDeserializationMiddleware.d.ts +9 -0
  96. package/dist-types/ts3.4/submodules/schema/middleware/schemaSerializationMiddleware.d.ts +6 -0
  97. package/dist-types/ts3.4/submodules/schema/schemas/ErrorSchema.d.ts +38 -0
  98. package/dist-types/ts3.4/submodules/schema/schemas/ListSchema.d.ts +20 -0
  99. package/dist-types/ts3.4/submodules/schema/schemas/MapSchema.d.ts +25 -0
  100. package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +125 -0
  101. package/dist-types/ts3.4/submodules/schema/schemas/OperationSchema.d.ts +20 -0
  102. package/dist-types/ts3.4/submodules/schema/schemas/Schema.d.ts +11 -0
  103. package/dist-types/ts3.4/submodules/schema/schemas/SimpleSchema.d.ts +20 -0
  104. package/dist-types/ts3.4/submodules/schema/schemas/StructureSchema.d.ts +24 -0
  105. package/dist-types/ts3.4/submodules/schema/schemas/sentinels.d.ts +21 -0
  106. package/dist-types/ts3.4/submodules/serde/copyDocumentWithTransform.d.ts +5 -0
  107. package/dist-types/ts3.4/submodules/serde/date-utils.d.ts +73 -0
  108. package/dist-types/ts3.4/submodules/serde/index.d.ts +7 -0
  109. package/dist-types/ts3.4/submodules/serde/lazy-json.d.ts +45 -0
  110. package/dist-types/ts3.4/submodules/serde/parse-utils.d.ts +270 -0
  111. package/dist-types/ts3.4/submodules/serde/quote-header.d.ts +6 -0
  112. package/dist-types/ts3.4/submodules/serde/split-every.d.ts +11 -0
  113. package/dist-types/ts3.4/submodules/serde/split-header.d.ts +5 -0
  114. package/package.json +18 -7
  115. package/schema.d.ts +7 -0
  116. package/schema.js +6 -0
@@ -0,0 +1,291 @@
1
+ import { deref } from "../deref";
2
+ import { ListSchema } from "./ListSchema";
3
+ import { MapSchema } from "./MapSchema";
4
+ import { SCHEMA } from "./sentinels";
5
+ import { SimpleSchema } from "./SimpleSchema";
6
+ import { StructureSchema } from "./StructureSchema";
7
+ export class NormalizedSchema {
8
+ constructor(ref, memberName) {
9
+ this.ref = ref;
10
+ this.memberName = memberName;
11
+ const traitStack = [];
12
+ let _ref = ref;
13
+ let schema = ref;
14
+ this._isMemberSchema = false;
15
+ while (Array.isArray(_ref)) {
16
+ traitStack.push(_ref[1]);
17
+ _ref = _ref[0];
18
+ schema = deref(_ref);
19
+ this._isMemberSchema = true;
20
+ }
21
+ if (traitStack.length > 0) {
22
+ this.memberTraits = {};
23
+ for (let i = traitStack.length - 1; i >= 0; --i) {
24
+ const traitSet = traitStack[i];
25
+ Object.assign(this.memberTraits, NormalizedSchema.translateTraits(traitSet));
26
+ }
27
+ }
28
+ else {
29
+ this.memberTraits = 0;
30
+ }
31
+ if (schema instanceof NormalizedSchema) {
32
+ this.name = schema.name;
33
+ this.traits = schema.traits;
34
+ this._isMemberSchema = schema._isMemberSchema;
35
+ this.schema = schema.schema;
36
+ this.memberTraits = Object.assign({}, schema.getMemberTraits(), this.getMemberTraits());
37
+ this.normalizedTraits = void 0;
38
+ this.ref = schema.ref;
39
+ this.memberName = memberName ?? schema.memberName;
40
+ return;
41
+ }
42
+ this.schema = deref(schema);
43
+ if (this.schema && typeof this.schema === "object") {
44
+ this.traits = this.schema?.traits ?? {};
45
+ }
46
+ else {
47
+ this.traits = 0;
48
+ }
49
+ this.name =
50
+ (typeof this.schema === "object" ? this.schema?.name : void 0) ?? this.memberName ?? this.getSchemaName();
51
+ if (this._isMemberSchema && !memberName) {
52
+ throw new Error(`@smithy/core/schema - NormalizedSchema member schema ${this.getName(true)} must initialize with memberName argument.`);
53
+ }
54
+ }
55
+ static of(ref, memberName) {
56
+ if (ref instanceof NormalizedSchema) {
57
+ return ref;
58
+ }
59
+ return new NormalizedSchema(ref, memberName);
60
+ }
61
+ static translateTraits(indicator) {
62
+ if (typeof indicator === "object") {
63
+ return indicator;
64
+ }
65
+ indicator = indicator | 0;
66
+ const traits = {};
67
+ if ((indicator & 1) === 1) {
68
+ traits.httpLabel = 1;
69
+ }
70
+ if (((indicator >> 1) & 1) === 1) {
71
+ traits.idempotent = 1;
72
+ }
73
+ if (((indicator >> 2) & 1) === 1) {
74
+ traits.idempotencyToken = 1;
75
+ }
76
+ if (((indicator >> 3) & 1) === 1) {
77
+ traits.sensitive = 1;
78
+ }
79
+ if (((indicator >> 4) & 1) === 1) {
80
+ traits.httpPayload = 1;
81
+ }
82
+ if (((indicator >> 5) & 1) === 1) {
83
+ traits.httpResponseCode = 1;
84
+ }
85
+ if (((indicator >> 6) & 1) === 1) {
86
+ traits.httpQueryParams = 1;
87
+ }
88
+ return traits;
89
+ }
90
+ static memberFrom(memberSchema, memberName) {
91
+ if (memberSchema instanceof NormalizedSchema) {
92
+ memberSchema.memberName = memberName;
93
+ memberSchema._isMemberSchema = true;
94
+ return memberSchema;
95
+ }
96
+ return new NormalizedSchema(memberSchema, memberName);
97
+ }
98
+ getSchema() {
99
+ if (this.schema instanceof NormalizedSchema) {
100
+ return (this.schema = this.schema.getSchema());
101
+ }
102
+ if (this.schema instanceof SimpleSchema) {
103
+ return deref(this.schema.schemaRef);
104
+ }
105
+ return deref(this.schema);
106
+ }
107
+ getName(withNamespace = false) {
108
+ if (!withNamespace) {
109
+ if (this.name && this.name.includes("#")) {
110
+ return this.name.split("#")[1];
111
+ }
112
+ }
113
+ return this.name || undefined;
114
+ }
115
+ getMemberName() {
116
+ if (!this.isMemberSchema()) {
117
+ throw new Error(`@smithy/core/schema - cannot get member name on non-member schema: ${this.getName(true)}`);
118
+ }
119
+ return this.memberName;
120
+ }
121
+ isMemberSchema() {
122
+ return this._isMemberSchema;
123
+ }
124
+ isUnitSchema() {
125
+ return this.getSchema() === "unit";
126
+ }
127
+ isListSchema() {
128
+ const inner = this.getSchema();
129
+ if (typeof inner === "number") {
130
+ return inner >= SCHEMA.LIST_MODIFIER && inner < SCHEMA.MAP_MODIFIER;
131
+ }
132
+ return inner instanceof ListSchema;
133
+ }
134
+ isMapSchema() {
135
+ const inner = this.getSchema();
136
+ if (typeof inner === "number") {
137
+ return inner >= SCHEMA.MAP_MODIFIER && inner <= 255;
138
+ }
139
+ return inner instanceof MapSchema;
140
+ }
141
+ isDocumentSchema() {
142
+ return this.getSchema() === SCHEMA.DOCUMENT;
143
+ }
144
+ isStructSchema() {
145
+ const inner = this.getSchema();
146
+ return (inner !== null && typeof inner === "object" && "members" in inner) || inner instanceof StructureSchema;
147
+ }
148
+ isBlobSchema() {
149
+ return this.getSchema() === SCHEMA.BLOB || this.getSchema() === SCHEMA.STREAMING_BLOB;
150
+ }
151
+ isTimestampSchema() {
152
+ const schema = this.getSchema();
153
+ return typeof schema === "number" && schema >= SCHEMA.TIMESTAMP_DEFAULT && schema <= SCHEMA.TIMESTAMP_EPOCH_SECONDS;
154
+ }
155
+ isStringSchema() {
156
+ return this.getSchema() === SCHEMA.STRING;
157
+ }
158
+ isBooleanSchema() {
159
+ return this.getSchema() === SCHEMA.BOOLEAN;
160
+ }
161
+ isNumericSchema() {
162
+ return this.getSchema() === SCHEMA.NUMERIC;
163
+ }
164
+ isBigIntegerSchema() {
165
+ return this.getSchema() === SCHEMA.BIG_INTEGER;
166
+ }
167
+ isBigDecimalSchema() {
168
+ return this.getSchema() === SCHEMA.BIG_DECIMAL;
169
+ }
170
+ isStreaming() {
171
+ const streaming = !!this.getMergedTraits().streaming;
172
+ if (streaming) {
173
+ return true;
174
+ }
175
+ return this.getSchema() === SCHEMA.STREAMING_BLOB;
176
+ }
177
+ getMergedTraits() {
178
+ if (this.normalizedTraits) {
179
+ return this.normalizedTraits;
180
+ }
181
+ this.normalizedTraits = {
182
+ ...this.getOwnTraits(),
183
+ ...this.getMemberTraits(),
184
+ };
185
+ return this.normalizedTraits;
186
+ }
187
+ getMemberTraits() {
188
+ return NormalizedSchema.translateTraits(this.memberTraits);
189
+ }
190
+ getOwnTraits() {
191
+ return NormalizedSchema.translateTraits(this.traits);
192
+ }
193
+ getKeySchema() {
194
+ if (this.isDocumentSchema()) {
195
+ return NormalizedSchema.memberFrom([SCHEMA.DOCUMENT, 0], "key");
196
+ }
197
+ if (!this.isMapSchema()) {
198
+ throw new Error(`@smithy/core/schema - cannot get key schema for non-map schema: ${this.getName(true)}`);
199
+ }
200
+ const schema = this.getSchema();
201
+ if (typeof schema === "number") {
202
+ return NormalizedSchema.memberFrom([63 & schema, 0], "key");
203
+ }
204
+ return NormalizedSchema.memberFrom([schema.keySchema, 0], "key");
205
+ }
206
+ getValueSchema() {
207
+ const schema = this.getSchema();
208
+ if (typeof schema === "number") {
209
+ if (this.isMapSchema()) {
210
+ return NormalizedSchema.memberFrom([63 & schema, 0], "value");
211
+ }
212
+ else if (this.isListSchema()) {
213
+ return NormalizedSchema.memberFrom([63 & schema, 0], "member");
214
+ }
215
+ }
216
+ if (schema && typeof schema === "object") {
217
+ if (this.isStructSchema()) {
218
+ throw new Error(`cannot call getValueSchema() with StructureSchema ${this.getName(true)}`);
219
+ }
220
+ const collection = schema;
221
+ if ("valueSchema" in collection) {
222
+ if (this.isMapSchema()) {
223
+ return NormalizedSchema.memberFrom([collection.valueSchema, 0], "value");
224
+ }
225
+ else if (this.isListSchema()) {
226
+ return NormalizedSchema.memberFrom([collection.valueSchema, 0], "member");
227
+ }
228
+ }
229
+ }
230
+ if (this.isDocumentSchema()) {
231
+ return NormalizedSchema.memberFrom([SCHEMA.DOCUMENT, 0], "value");
232
+ }
233
+ throw new Error(`@smithy/core/schema - the schema ${this.getName(true)} does not have a value member.`);
234
+ }
235
+ getMemberSchema(member) {
236
+ if (this.isStructSchema()) {
237
+ const struct = this.getSchema();
238
+ if (!(member in struct.members)) {
239
+ throw new Error(`@smithy/core/schema - the schema ${this.getName(true)} does not have a member with name=${member}.`);
240
+ }
241
+ return NormalizedSchema.memberFrom(struct.members[member], member);
242
+ }
243
+ if (this.isDocumentSchema()) {
244
+ return NormalizedSchema.memberFrom([SCHEMA.DOCUMENT, 0], member);
245
+ }
246
+ throw new Error(`@smithy/core/schema - the schema ${this.getName(true)} does not have members.`);
247
+ }
248
+ getMemberSchemas() {
249
+ const { schema } = this;
250
+ const struct = schema;
251
+ if (!struct || typeof struct !== "object") {
252
+ return {};
253
+ }
254
+ if ("members" in struct) {
255
+ const buffer = {};
256
+ for (const member of struct.memberNames) {
257
+ buffer[member] = this.getMemberSchema(member);
258
+ }
259
+ return buffer;
260
+ }
261
+ return {};
262
+ }
263
+ *structIterator() {
264
+ if (!this.isStructSchema()) {
265
+ throw new Error("@smithy/core/schema - cannot acquire structIterator on non-struct schema.");
266
+ }
267
+ const struct = this.getSchema();
268
+ for (let i = 0; i < struct.memberNames.length; ++i) {
269
+ yield [struct.memberNames[i], NormalizedSchema.memberFrom([struct.memberList[i], 0], struct.memberNames[i])];
270
+ }
271
+ }
272
+ getSchemaName() {
273
+ const schema = this.getSchema();
274
+ if (typeof schema === "number") {
275
+ const _schema = 63 & schema;
276
+ const container = 192 & schema;
277
+ const type = Object.entries(SCHEMA).find(([, value]) => {
278
+ return value === _schema;
279
+ })?.[0] ?? "Unknown";
280
+ switch (container) {
281
+ case SCHEMA.MAP_MODIFIER:
282
+ return `${type}Map`;
283
+ case SCHEMA.LIST_MODIFIER:
284
+ return `${type}List`;
285
+ case 0:
286
+ return type;
287
+ }
288
+ }
289
+ return "Unknown";
290
+ }
291
+ }
@@ -0,0 +1,16 @@
1
+ import { TypeRegistry } from "../TypeRegistry";
2
+ import { Schema } from "./Schema";
3
+ export class OperationSchema extends Schema {
4
+ constructor(name, traits, input, output) {
5
+ super(name, traits);
6
+ this.name = name;
7
+ this.traits = traits;
8
+ this.input = input;
9
+ this.output = output;
10
+ }
11
+ }
12
+ export function op(namespace, name, traits = {}, input, output) {
13
+ const schema = new OperationSchema(namespace + "#" + name, traits, input, output);
14
+ TypeRegistry.for(namespace).register(name, schema);
15
+ return schema;
16
+ }
@@ -0,0 +1,6 @@
1
+ export class Schema {
2
+ constructor(name, traits) {
3
+ this.name = name;
4
+ this.traits = traits;
5
+ }
6
+ }
@@ -0,0 +1,15 @@
1
+ import { TypeRegistry } from "../TypeRegistry";
2
+ import { Schema } from "./Schema";
3
+ export class SimpleSchema extends Schema {
4
+ constructor(name, schemaRef, traits) {
5
+ super(name, traits);
6
+ this.name = name;
7
+ this.schemaRef = schemaRef;
8
+ this.traits = traits;
9
+ }
10
+ }
11
+ export function sim(namespace, name, schemaRef, traits) {
12
+ const schema = new SimpleSchema(namespace + "#" + name, schemaRef, traits);
13
+ TypeRegistry.for(namespace).register(name, schema);
14
+ return schema;
15
+ }
@@ -0,0 +1,22 @@
1
+ import { TypeRegistry } from "../TypeRegistry";
2
+ import { Schema } from "./Schema";
3
+ export class StructureSchema extends Schema {
4
+ constructor(name, traits, memberNames, memberList) {
5
+ super(name, traits);
6
+ this.name = name;
7
+ this.traits = traits;
8
+ this.memberNames = memberNames;
9
+ this.memberList = memberList;
10
+ this.members = {};
11
+ for (let i = 0; i < memberNames.length; ++i) {
12
+ this.members[memberNames[i]] = Array.isArray(memberList[i])
13
+ ? memberList[i]
14
+ : [memberList[i], 0];
15
+ }
16
+ }
17
+ }
18
+ export function struct(namespace, name, traits, memberNames, memberList) {
19
+ const schema = new StructureSchema(namespace + "#" + name, traits, memberNames, memberList);
20
+ TypeRegistry.for(namespace).register(name, schema);
21
+ return schema;
22
+ }
@@ -0,0 +1,16 @@
1
+ export const SCHEMA = {
2
+ BLOB: 21,
3
+ STREAMING_BLOB: 42,
4
+ BOOLEAN: 2,
5
+ STRING: 0,
6
+ NUMERIC: 1,
7
+ BIG_INTEGER: 17,
8
+ BIG_DECIMAL: 19,
9
+ DOCUMENT: 15,
10
+ TIMESTAMP_DEFAULT: 4,
11
+ TIMESTAMP_DATE_TIME: 5,
12
+ TIMESTAMP_HTTP_DATE: 6,
13
+ TIMESTAMP_EPOCH_SECONDS: 7,
14
+ LIST_MODIFIER: 64,
15
+ MAP_MODIFIER: 128,
16
+ };
@@ -0,0 +1,53 @@
1
+ import { NormalizedSchema } from "@smithy/core/schema";
2
+ export const copyDocumentWithTransform = (source, schemaRef, transform = (_) => _) => {
3
+ const ns = NormalizedSchema.of(schemaRef);
4
+ switch (typeof source) {
5
+ case "undefined":
6
+ case "boolean":
7
+ case "number":
8
+ case "string":
9
+ case "bigint":
10
+ case "symbol":
11
+ return transform(source, ns);
12
+ case "function":
13
+ case "object":
14
+ if (source === null) {
15
+ return transform(null, ns);
16
+ }
17
+ if (Array.isArray(source)) {
18
+ const newArray = new Array(source.length);
19
+ let i = 0;
20
+ for (const item of source) {
21
+ newArray[i++] = copyDocumentWithTransform(item, ns.getValueSchema(), transform);
22
+ }
23
+ return transform(newArray, ns);
24
+ }
25
+ if ("byteLength" in source) {
26
+ const newBytes = new Uint8Array(source.byteLength);
27
+ newBytes.set(source, 0);
28
+ return transform(newBytes, ns);
29
+ }
30
+ if (source instanceof Date) {
31
+ return transform(source, ns);
32
+ }
33
+ const newObject = {};
34
+ if (ns.isMapSchema()) {
35
+ for (const key of Object.keys(source)) {
36
+ newObject[key] = copyDocumentWithTransform(source[key], ns.getValueSchema(), transform);
37
+ }
38
+ }
39
+ else if (ns.isStructSchema()) {
40
+ for (const [key, memberSchema] of ns.structIterator()) {
41
+ newObject[key] = copyDocumentWithTransform(source[key], memberSchema, transform);
42
+ }
43
+ }
44
+ else if (ns.isDocumentSchema()) {
45
+ for (const key of Object.keys(source)) {
46
+ newObject[key] = copyDocumentWithTransform(source[key], ns.getValueSchema(), transform);
47
+ }
48
+ }
49
+ return transform(newObject, ns);
50
+ default:
51
+ return transform(source, ns);
52
+ }
53
+ };
@@ -0,0 +1,190 @@
1
+ import { strictParseByte, strictParseDouble, strictParseFloat32, strictParseShort } from "./parse-utils";
2
+ const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
3
+ const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
4
+ export function dateToUtcString(date) {
5
+ const year = date.getUTCFullYear();
6
+ const month = date.getUTCMonth();
7
+ const dayOfWeek = date.getUTCDay();
8
+ const dayOfMonthInt = date.getUTCDate();
9
+ const hoursInt = date.getUTCHours();
10
+ const minutesInt = date.getUTCMinutes();
11
+ const secondsInt = date.getUTCSeconds();
12
+ const dayOfMonthString = dayOfMonthInt < 10 ? `0${dayOfMonthInt}` : `${dayOfMonthInt}`;
13
+ const hoursString = hoursInt < 10 ? `0${hoursInt}` : `${hoursInt}`;
14
+ const minutesString = minutesInt < 10 ? `0${minutesInt}` : `${minutesInt}`;
15
+ const secondsString = secondsInt < 10 ? `0${secondsInt}` : `${secondsInt}`;
16
+ return `${DAYS[dayOfWeek]}, ${dayOfMonthString} ${MONTHS[month]} ${year} ${hoursString}:${minutesString}:${secondsString} GMT`;
17
+ }
18
+ const RFC3339 = new RegExp(/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?[zZ]$/);
19
+ export const parseRfc3339DateTime = (value) => {
20
+ if (value === null || value === undefined) {
21
+ return undefined;
22
+ }
23
+ if (typeof value !== "string") {
24
+ throw new TypeError("RFC-3339 date-times must be expressed as strings");
25
+ }
26
+ const match = RFC3339.exec(value);
27
+ if (!match) {
28
+ throw new TypeError("Invalid RFC-3339 date-time value");
29
+ }
30
+ const [_, yearStr, monthStr, dayStr, hours, minutes, seconds, fractionalMilliseconds] = match;
31
+ const year = strictParseShort(stripLeadingZeroes(yearStr));
32
+ const month = parseDateValue(monthStr, "month", 1, 12);
33
+ const day = parseDateValue(dayStr, "day", 1, 31);
34
+ return buildDate(year, month, day, { hours, minutes, seconds, fractionalMilliseconds });
35
+ };
36
+ const RFC3339_WITH_OFFSET = new RegExp(/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(([-+]\d{2}\:\d{2})|[zZ])$/);
37
+ export const parseRfc3339DateTimeWithOffset = (value) => {
38
+ if (value === null || value === undefined) {
39
+ return undefined;
40
+ }
41
+ if (typeof value !== "string") {
42
+ throw new TypeError("RFC-3339 date-times must be expressed as strings");
43
+ }
44
+ const match = RFC3339_WITH_OFFSET.exec(value);
45
+ if (!match) {
46
+ throw new TypeError("Invalid RFC-3339 date-time value");
47
+ }
48
+ const [_, yearStr, monthStr, dayStr, hours, minutes, seconds, fractionalMilliseconds, offsetStr] = match;
49
+ const year = strictParseShort(stripLeadingZeroes(yearStr));
50
+ const month = parseDateValue(monthStr, "month", 1, 12);
51
+ const day = parseDateValue(dayStr, "day", 1, 31);
52
+ const date = buildDate(year, month, day, { hours, minutes, seconds, fractionalMilliseconds });
53
+ if (offsetStr.toUpperCase() != "Z") {
54
+ date.setTime(date.getTime() - parseOffsetToMilliseconds(offsetStr));
55
+ }
56
+ return date;
57
+ };
58
+ const IMF_FIXDATE = new RegExp(/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d{2}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d{1,2}):(\d{2}):(\d{2})(?:\.(\d+))? GMT$/);
59
+ const RFC_850_DATE = new RegExp(/^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d{2})-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d{2}) (\d{1,2}):(\d{2}):(\d{2})(?:\.(\d+))? GMT$/);
60
+ const ASC_TIME = new RegExp(/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( [1-9]|\d{2}) (\d{1,2}):(\d{2}):(\d{2})(?:\.(\d+))? (\d{4})$/);
61
+ export const parseRfc7231DateTime = (value) => {
62
+ if (value === null || value === undefined) {
63
+ return undefined;
64
+ }
65
+ if (typeof value !== "string") {
66
+ throw new TypeError("RFC-7231 date-times must be expressed as strings");
67
+ }
68
+ let match = IMF_FIXDATE.exec(value);
69
+ if (match) {
70
+ const [_, dayStr, monthStr, yearStr, hours, minutes, seconds, fractionalMilliseconds] = match;
71
+ return buildDate(strictParseShort(stripLeadingZeroes(yearStr)), parseMonthByShortName(monthStr), parseDateValue(dayStr, "day", 1, 31), { hours, minutes, seconds, fractionalMilliseconds });
72
+ }
73
+ match = RFC_850_DATE.exec(value);
74
+ if (match) {
75
+ const [_, dayStr, monthStr, yearStr, hours, minutes, seconds, fractionalMilliseconds] = match;
76
+ return adjustRfc850Year(buildDate(parseTwoDigitYear(yearStr), parseMonthByShortName(monthStr), parseDateValue(dayStr, "day", 1, 31), {
77
+ hours,
78
+ minutes,
79
+ seconds,
80
+ fractionalMilliseconds,
81
+ }));
82
+ }
83
+ match = ASC_TIME.exec(value);
84
+ if (match) {
85
+ const [_, monthStr, dayStr, hours, minutes, seconds, fractionalMilliseconds, yearStr] = match;
86
+ return buildDate(strictParseShort(stripLeadingZeroes(yearStr)), parseMonthByShortName(monthStr), parseDateValue(dayStr.trimLeft(), "day", 1, 31), { hours, minutes, seconds, fractionalMilliseconds });
87
+ }
88
+ throw new TypeError("Invalid RFC-7231 date-time value");
89
+ };
90
+ export const parseEpochTimestamp = (value) => {
91
+ if (value === null || value === undefined) {
92
+ return undefined;
93
+ }
94
+ let valueAsDouble;
95
+ if (typeof value === "number") {
96
+ valueAsDouble = value;
97
+ }
98
+ else if (typeof value === "string") {
99
+ valueAsDouble = strictParseDouble(value);
100
+ }
101
+ else if (typeof value === "object" && value.tag === 1) {
102
+ valueAsDouble = value.value;
103
+ }
104
+ else {
105
+ throw new TypeError("Epoch timestamps must be expressed as floating point numbers or their string representation");
106
+ }
107
+ if (Number.isNaN(valueAsDouble) || valueAsDouble === Infinity || valueAsDouble === -Infinity) {
108
+ throw new TypeError("Epoch timestamps must be valid, non-Infinite, non-NaN numerics");
109
+ }
110
+ return new Date(Math.round(valueAsDouble * 1000));
111
+ };
112
+ const buildDate = (year, month, day, time) => {
113
+ const adjustedMonth = month - 1;
114
+ validateDayOfMonth(year, adjustedMonth, day);
115
+ return new Date(Date.UTC(year, adjustedMonth, day, parseDateValue(time.hours, "hour", 0, 23), parseDateValue(time.minutes, "minute", 0, 59), parseDateValue(time.seconds, "seconds", 0, 60), parseMilliseconds(time.fractionalMilliseconds)));
116
+ };
117
+ const parseTwoDigitYear = (value) => {
118
+ const thisYear = new Date().getUTCFullYear();
119
+ const valueInThisCentury = Math.floor(thisYear / 100) * 100 + strictParseShort(stripLeadingZeroes(value));
120
+ if (valueInThisCentury < thisYear) {
121
+ return valueInThisCentury + 100;
122
+ }
123
+ return valueInThisCentury;
124
+ };
125
+ const FIFTY_YEARS_IN_MILLIS = 50 * 365 * 24 * 60 * 60 * 1000;
126
+ const adjustRfc850Year = (input) => {
127
+ if (input.getTime() - new Date().getTime() > FIFTY_YEARS_IN_MILLIS) {
128
+ return new Date(Date.UTC(input.getUTCFullYear() - 100, input.getUTCMonth(), input.getUTCDate(), input.getUTCHours(), input.getUTCMinutes(), input.getUTCSeconds(), input.getUTCMilliseconds()));
129
+ }
130
+ return input;
131
+ };
132
+ const parseMonthByShortName = (value) => {
133
+ const monthIdx = MONTHS.indexOf(value);
134
+ if (monthIdx < 0) {
135
+ throw new TypeError(`Invalid month: ${value}`);
136
+ }
137
+ return monthIdx + 1;
138
+ };
139
+ const DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
140
+ const validateDayOfMonth = (year, month, day) => {
141
+ let maxDays = DAYS_IN_MONTH[month];
142
+ if (month === 1 && isLeapYear(year)) {
143
+ maxDays = 29;
144
+ }
145
+ if (day > maxDays) {
146
+ throw new TypeError(`Invalid day for ${MONTHS[month]} in ${year}: ${day}`);
147
+ }
148
+ };
149
+ const isLeapYear = (year) => {
150
+ return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
151
+ };
152
+ const parseDateValue = (value, type, lower, upper) => {
153
+ const dateVal = strictParseByte(stripLeadingZeroes(value));
154
+ if (dateVal < lower || dateVal > upper) {
155
+ throw new TypeError(`${type} must be between ${lower} and ${upper}, inclusive`);
156
+ }
157
+ return dateVal;
158
+ };
159
+ const parseMilliseconds = (value) => {
160
+ if (value === null || value === undefined) {
161
+ return 0;
162
+ }
163
+ return strictParseFloat32("0." + value) * 1000;
164
+ };
165
+ const parseOffsetToMilliseconds = (value) => {
166
+ const directionStr = value[0];
167
+ let direction = 1;
168
+ if (directionStr == "+") {
169
+ direction = 1;
170
+ }
171
+ else if (directionStr == "-") {
172
+ direction = -1;
173
+ }
174
+ else {
175
+ throw new TypeError(`Offset direction, ${directionStr}, must be "+" or "-"`);
176
+ }
177
+ const hour = Number(value.substring(1, 3));
178
+ const minute = Number(value.substring(4, 6));
179
+ return direction * (hour * 60 + minute) * 60 * 1000;
180
+ };
181
+ const stripLeadingZeroes = (value) => {
182
+ let idx = 0;
183
+ while (idx < value.length - 1 && value.charAt(idx) === "0") {
184
+ idx++;
185
+ }
186
+ if (idx === 0) {
187
+ return value;
188
+ }
189
+ return value.slice(idx);
190
+ };
@@ -1 +1,8 @@
1
+ export * from "./copyDocumentWithTransform";
2
+ export * from "./date-utils";
3
+ export * from "./lazy-json";
4
+ export * from "./parse-utils";
5
+ export * from "./quote-header";
6
+ export * from "./split-every";
7
+ export * from "./split-header";
1
8
  export * from "./value/NumericValue";
@@ -0,0 +1,24 @@
1
+ export const LazyJsonString = function LazyJsonString(val) {
2
+ const str = Object.assign(new String(val), {
3
+ deserializeJSON() {
4
+ return JSON.parse(String(val));
5
+ },
6
+ toString() {
7
+ return String(val);
8
+ },
9
+ toJSON() {
10
+ return String(val);
11
+ },
12
+ });
13
+ return str;
14
+ };
15
+ LazyJsonString.from = (object) => {
16
+ if (object && typeof object === "object" && (object instanceof LazyJsonString || "deserializeJSON" in object)) {
17
+ return object;
18
+ }
19
+ else if (typeof object === "string" || Object.getPrototypeOf(object) === String.prototype) {
20
+ return LazyJsonString(String(object));
21
+ }
22
+ return LazyJsonString(JSON.stringify(object));
23
+ };
24
+ LazyJsonString.fromObject = LazyJsonString.from;