@smithy/core 3.13.0 → 3.15.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 (50) hide show
  1. package/dist-cjs/index.js +308 -412
  2. package/dist-cjs/submodules/cbor/index.js +957 -969
  3. package/dist-cjs/submodules/event-streams/index.js +200 -249
  4. package/dist-cjs/submodules/protocols/index.js +795 -895
  5. package/dist-cjs/submodules/schema/index.js +536 -799
  6. package/dist-cjs/submodules/serde/index.js +675 -679
  7. package/dist-es/submodules/cbor/CborCodec.js +6 -2
  8. package/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +3 -3
  9. package/dist-es/submodules/cbor/cbor-decode.js +18 -18
  10. package/dist-es/submodules/cbor/cbor-encode.js +5 -5
  11. package/dist-es/submodules/event-streams/EventStreamSerde.js +10 -3
  12. package/dist-es/submodules/protocols/HttpBindingProtocol.js +4 -4
  13. package/dist-es/submodules/protocols/HttpProtocol.js +5 -3
  14. package/dist-es/submodules/protocols/RpcProtocol.js +2 -2
  15. package/dist-es/submodules/protocols/requestBuilder.js +9 -7
  16. package/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +21 -17
  17. package/dist-es/submodules/protocols/serde/HttpInterceptingShapeDeserializer.js +3 -0
  18. package/dist-es/submodules/protocols/serde/HttpInterceptingShapeSerializer.js +3 -0
  19. package/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js +7 -6
  20. package/dist-es/submodules/protocols/serde/determineTimestampFormat.js +5 -6
  21. package/dist-es/submodules/schema/TypeRegistry.js +4 -1
  22. package/dist-es/submodules/schema/index.js +1 -0
  23. package/dist-es/submodules/schema/schemas/ErrorSchema.js +3 -5
  24. package/dist-es/submodules/schema/schemas/ListSchema.js +5 -5
  25. package/dist-es/submodules/schema/schemas/MapSchema.js +6 -5
  26. package/dist-es/submodules/schema/schemas/NormalizedSchema.js +92 -178
  27. package/dist-es/submodules/schema/schemas/OperationSchema.js +6 -5
  28. package/dist-es/submodules/schema/schemas/Schema.js +3 -0
  29. package/dist-es/submodules/schema/schemas/SimpleSchema.js +5 -5
  30. package/dist-es/submodules/schema/schemas/StructureSchema.js +6 -5
  31. package/dist-es/submodules/schema/schemas/sentinels.js +14 -14
  32. package/dist-es/submodules/schema/schemas/translateTraits.js +22 -0
  33. package/dist-es/submodules/serde/index.js +1 -0
  34. package/dist-es/submodules/serde/schema-serde-lib/schema-date-utils.js +110 -0
  35. package/dist-es/submodules/serde/value/NumericValue.js +6 -26
  36. package/dist-es/util-identity-and-auth/DefaultIdentityProviderConfig.js +1 -1
  37. package/dist-es/util-identity-and-auth/memoizeIdentityProvider.js +4 -2
  38. package/dist-types/submodules/schema/index.d.ts +1 -0
  39. package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +5 -24
  40. package/dist-types/submodules/schema/schemas/sentinels.d.ts +2 -0
  41. package/dist-types/submodules/schema/schemas/translateTraits.d.ts +7 -0
  42. package/dist-types/submodules/serde/index.d.ts +1 -0
  43. package/dist-types/submodules/serde/schema-serde-lib/schema-date-utils.d.ts +47 -0
  44. package/dist-types/ts3.4/submodules/schema/index.d.ts +1 -0
  45. package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +5 -24
  46. package/dist-types/ts3.4/submodules/schema/schemas/sentinels.d.ts +2 -0
  47. package/dist-types/ts3.4/submodules/schema/schemas/translateTraits.d.ts +7 -0
  48. package/dist-types/ts3.4/submodules/serde/index.d.ts +1 -0
  49. package/dist-types/ts3.4/submodules/serde/schema-serde-lib/schema-date-utils.d.ts +47 -0
  50. package/package.json +11 -11
@@ -2,14 +2,22 @@ import { deref } from "../deref";
2
2
  import { ListSchema } from "./ListSchema";
3
3
  import { MapSchema } from "./MapSchema";
4
4
  import { Schema } from "./Schema";
5
- import { SCHEMA } from "./sentinels";
6
- import { SimpleSchema } from "./SimpleSchema";
7
5
  import { StructureSchema } from "./StructureSchema";
6
+ import { translateTraits } from "./translateTraits";
8
7
  export class NormalizedSchema {
8
+ ref;
9
+ memberName;
10
+ static symbol = Symbol.for("@smithy/nor");
11
+ symbol = NormalizedSchema.symbol;
12
+ name;
13
+ schema;
14
+ _isMemberSchema;
15
+ traits;
16
+ memberTraits;
17
+ normalizedTraits;
9
18
  constructor(ref, memberName) {
10
19
  this.ref = ref;
11
20
  this.memberName = memberName;
12
- this.symbol = NormalizedSchema.symbol;
13
21
  const traitStack = [];
14
22
  let _ref = ref;
15
23
  let schema = ref;
@@ -24,7 +32,7 @@ export class NormalizedSchema {
24
32
  this.memberTraits = {};
25
33
  for (let i = traitStack.length - 1; i >= 0; --i) {
26
34
  const traitSet = traitStack[i];
27
- Object.assign(this.memberTraits, NormalizedSchema.translateTraits(traitSet));
35
+ Object.assign(this.memberTraits, translateTraits(traitSet));
28
36
  }
29
37
  }
30
38
  else {
@@ -45,8 +53,7 @@ export class NormalizedSchema {
45
53
  else {
46
54
  this.traits = 0;
47
55
  }
48
- this.name =
49
- (this.schema instanceof Schema ? this.schema.getName?.() : void 0) ?? this.memberName ?? this.getSchemaName();
56
+ this.name = (this.schema instanceof Schema ? this.schema.getName?.() : void 0) ?? this.memberName ?? String(schema);
50
57
  if (this._isMemberSchema && !memberName) {
51
58
  throw new Error(`@smithy/core/schema - NormalizedSchema member init ${this.getName(true)} missing member name.`);
52
59
  }
@@ -55,138 +62,90 @@ export class NormalizedSchema {
55
62
  return Schema[Symbol.hasInstance].bind(this)(lhs);
56
63
  }
57
64
  static of(ref) {
58
- if (ref instanceof NormalizedSchema) {
59
- return ref;
65
+ const sc = deref(ref);
66
+ if (sc instanceof NormalizedSchema) {
67
+ return sc;
60
68
  }
61
- if (Array.isArray(ref)) {
62
- const [ns, traits] = ref;
69
+ if (Array.isArray(sc)) {
70
+ const [ns, traits] = sc;
63
71
  if (ns instanceof NormalizedSchema) {
64
- Object.assign(ns.getMergedTraits(), NormalizedSchema.translateTraits(traits));
72
+ Object.assign(ns.getMergedTraits(), translateTraits(traits));
65
73
  return ns;
66
74
  }
67
75
  throw new Error(`@smithy/core/schema - may not init unwrapped member schema=${JSON.stringify(ref, null, 2)}.`);
68
76
  }
69
- return new NormalizedSchema(ref);
70
- }
71
- static translateTraits(indicator) {
72
- if (typeof indicator === "object") {
73
- return indicator;
74
- }
75
- indicator = indicator | 0;
76
- const traits = {};
77
- let i = 0;
78
- for (const trait of [
79
- "httpLabel",
80
- "idempotent",
81
- "idempotencyToken",
82
- "sensitive",
83
- "httpPayload",
84
- "httpResponseCode",
85
- "httpQueryParams",
86
- ]) {
87
- if (((indicator >> i++) & 1) === 1) {
88
- traits[trait] = 1;
89
- }
90
- }
91
- return traits;
77
+ return new NormalizedSchema(sc);
92
78
  }
93
79
  getSchema() {
94
- if (this.schema instanceof NormalizedSchema) {
95
- Object.assign(this, { schema: this.schema.getSchema() });
96
- return this.schema;
97
- }
98
- if (this.schema instanceof SimpleSchema) {
99
- return deref(this.schema.schemaRef);
100
- }
101
- return deref(this.schema);
80
+ return deref(this.schema?.schemaRef ?? this.schema);
102
81
  }
103
82
  getName(withNamespace = false) {
104
- if (!withNamespace) {
105
- if (this.name && this.name.includes("#")) {
106
- return this.name.split("#")[1];
107
- }
108
- }
109
- return this.name || undefined;
83
+ const { name } = this;
84
+ const short = !withNamespace && name && name.includes("#");
85
+ return short ? name.split("#")[1] : name || undefined;
110
86
  }
111
87
  getMemberName() {
112
- if (!this.isMemberSchema()) {
113
- throw new Error(`@smithy/core/schema - non-member schema: ${this.getName(true)}`);
114
- }
115
88
  return this.memberName;
116
89
  }
117
90
  isMemberSchema() {
118
91
  return this._isMemberSchema;
119
92
  }
120
- isUnitSchema() {
121
- return this.getSchema() === "unit";
122
- }
123
93
  isListSchema() {
124
- const inner = this.getSchema();
125
- if (typeof inner === "number") {
126
- return inner >= SCHEMA.LIST_MODIFIER && inner < SCHEMA.MAP_MODIFIER;
127
- }
128
- return inner instanceof ListSchema;
94
+ const sc = this.getSchema();
95
+ return typeof sc === "number"
96
+ ? sc >= 64 && sc < 128
97
+ : sc instanceof ListSchema;
129
98
  }
130
99
  isMapSchema() {
131
- const inner = this.getSchema();
132
- if (typeof inner === "number") {
133
- return inner >= SCHEMA.MAP_MODIFIER && inner <= 255;
134
- }
135
- return inner instanceof MapSchema;
100
+ const sc = this.getSchema();
101
+ return typeof sc === "number"
102
+ ? sc >= 128 && sc <= 0b1111_1111
103
+ : sc instanceof MapSchema;
136
104
  }
137
105
  isStructSchema() {
138
- const inner = this.getSchema();
139
- return (inner !== null && typeof inner === "object" && "members" in inner) || inner instanceof StructureSchema;
106
+ const sc = this.getSchema();
107
+ return (sc !== null && typeof sc === "object" && "members" in sc) || sc instanceof StructureSchema;
140
108
  }
141
109
  isBlobSchema() {
142
- return this.getSchema() === SCHEMA.BLOB || this.getSchema() === SCHEMA.STREAMING_BLOB;
110
+ const sc = this.getSchema();
111
+ return sc === 21 || sc === 42;
143
112
  }
144
113
  isTimestampSchema() {
145
- const schema = this.getSchema();
146
- return typeof schema === "number" && schema >= SCHEMA.TIMESTAMP_DEFAULT && schema <= SCHEMA.TIMESTAMP_EPOCH_SECONDS;
114
+ const sc = this.getSchema();
115
+ return (typeof sc === "number" &&
116
+ sc >= 4 &&
117
+ sc <= 7);
118
+ }
119
+ isUnitSchema() {
120
+ return this.getSchema() === "unit";
147
121
  }
148
122
  isDocumentSchema() {
149
- return this.getSchema() === SCHEMA.DOCUMENT;
123
+ return this.getSchema() === 15;
150
124
  }
151
125
  isStringSchema() {
152
- return this.getSchema() === SCHEMA.STRING;
126
+ return this.getSchema() === 0;
153
127
  }
154
128
  isBooleanSchema() {
155
- return this.getSchema() === SCHEMA.BOOLEAN;
129
+ return this.getSchema() === 2;
156
130
  }
157
131
  isNumericSchema() {
158
- return this.getSchema() === SCHEMA.NUMERIC;
132
+ return this.getSchema() === 1;
159
133
  }
160
134
  isBigIntegerSchema() {
161
- return this.getSchema() === SCHEMA.BIG_INTEGER;
135
+ return this.getSchema() === 17;
162
136
  }
163
137
  isBigDecimalSchema() {
164
- return this.getSchema() === SCHEMA.BIG_DECIMAL;
138
+ return this.getSchema() === 19;
165
139
  }
166
140
  isStreaming() {
167
- const streaming = !!this.getMergedTraits().streaming;
168
- if (streaming) {
169
- return true;
170
- }
171
- return this.getSchema() === SCHEMA.STREAMING_BLOB;
141
+ const { streaming } = this.getMergedTraits();
142
+ return !!streaming || this.getSchema() === 42;
172
143
  }
173
144
  isIdempotencyToken() {
174
- if (this.normalizedTraits) {
175
- return !!this.normalizedTraits.idempotencyToken;
176
- }
177
- for (const traits of [this.traits, this.memberTraits]) {
178
- if (typeof traits === "number") {
179
- if ((traits & 0b0100) === 0b0100) {
180
- return true;
181
- }
182
- }
183
- else if (typeof traits === "object") {
184
- if (!!traits.idempotencyToken) {
185
- return true;
186
- }
187
- }
188
- }
189
- return false;
145
+ const match = (traits) => (traits & 0b0100) === 0b0100 ||
146
+ !!traits?.idempotencyToken;
147
+ const { normalizedTraits, traits, memberTraits } = this;
148
+ return match(normalizedTraits) || match(traits) || match(memberTraits);
190
149
  }
191
150
  getMergedTraits() {
192
151
  return (this.normalizedTraits ??
@@ -196,74 +155,48 @@ export class NormalizedSchema {
196
155
  }));
197
156
  }
198
157
  getMemberTraits() {
199
- return NormalizedSchema.translateTraits(this.memberTraits);
158
+ return translateTraits(this.memberTraits);
200
159
  }
201
160
  getOwnTraits() {
202
- return NormalizedSchema.translateTraits(this.traits);
161
+ return translateTraits(this.traits);
203
162
  }
204
163
  getKeySchema() {
205
- if (this.isDocumentSchema()) {
206
- return this.memberFrom([SCHEMA.DOCUMENT, 0], "key");
207
- }
208
- if (!this.isMapSchema()) {
164
+ const [isDoc, isMap] = [this.isDocumentSchema(), this.isMapSchema()];
165
+ if (!isDoc && !isMap) {
209
166
  throw new Error(`@smithy/core/schema - cannot get key for non-map: ${this.getName(true)}`);
210
167
  }
211
168
  const schema = this.getSchema();
212
- if (typeof schema === "number") {
213
- return this.memberFrom([63 & schema, 0], "key");
214
- }
215
- return this.memberFrom([schema.keySchema, 0], "key");
169
+ const memberSchema = isDoc
170
+ ? 15
171
+ : schema?.keySchema ?? 0;
172
+ return member([memberSchema, 0], "key");
216
173
  }
217
174
  getValueSchema() {
218
- const schema = this.getSchema();
219
- if (typeof schema === "number") {
220
- if (this.isMapSchema()) {
221
- return this.memberFrom([63 & schema, 0], "value");
222
- }
223
- else if (this.isListSchema()) {
224
- return this.memberFrom([63 & schema, 0], "member");
225
- }
226
- }
227
- if (schema && typeof schema === "object") {
228
- if (this.isStructSchema()) {
229
- throw new Error(`may not getValueSchema() on structure ${this.getName(true)}`);
230
- }
231
- const collection = schema;
232
- if ("valueSchema" in collection) {
233
- if (this.isMapSchema()) {
234
- return this.memberFrom([collection.valueSchema, 0], "value");
235
- }
236
- else if (this.isListSchema()) {
237
- return this.memberFrom([collection.valueSchema, 0], "member");
238
- }
239
- }
240
- }
241
- if (this.isDocumentSchema()) {
242
- return this.memberFrom([SCHEMA.DOCUMENT, 0], "value");
175
+ const sc = this.getSchema();
176
+ const [isDoc, isMap, isList] = [this.isDocumentSchema(), this.isMapSchema(), this.isListSchema()];
177
+ const memberSchema = typeof sc === "number"
178
+ ? 0b0011_1111 & sc
179
+ : sc && typeof sc === "object" && (isMap || isList)
180
+ ? sc.valueSchema
181
+ : isDoc
182
+ ? 15
183
+ : void 0;
184
+ if (memberSchema != null) {
185
+ return member([memberSchema, 0], isMap ? "value" : "member");
243
186
  }
244
187
  throw new Error(`@smithy/core/schema - ${this.getName(true)} has no value member.`);
245
188
  }
246
- hasMemberSchema(member) {
247
- if (this.isStructSchema()) {
248
- const struct = this.getSchema();
249
- return struct.memberNames.includes(member);
250
- }
251
- return false;
252
- }
253
- getMemberSchema(member) {
254
- if (this.isStructSchema()) {
255
- const struct = this.getSchema();
256
- if (!struct.memberNames.includes(member)) {
257
- throw new Error(`@smithy/core/schema - ${this.getName(true)} has no member=${member}.`);
258
- }
259
- const i = struct.memberNames.indexOf(member);
189
+ getMemberSchema(memberName) {
190
+ const struct = this.getSchema();
191
+ if (this.isStructSchema() && struct.memberNames.includes(memberName)) {
192
+ const i = struct.memberNames.indexOf(memberName);
260
193
  const memberSchema = struct.memberList[i];
261
- return this.memberFrom(Array.isArray(memberSchema) ? memberSchema : [memberSchema, 0], member);
194
+ return member(Array.isArray(memberSchema) ? memberSchema : [memberSchema, 0], memberName);
262
195
  }
263
196
  if (this.isDocumentSchema()) {
264
- return this.memberFrom([SCHEMA.DOCUMENT, 0], member);
197
+ return member([15, 0], memberName);
265
198
  }
266
- throw new Error(`@smithy/core/schema - ${this.getName(true)} has no members.`);
199
+ throw new Error(`@smithy/core/schema - ${this.getName(true)} has no no member=${memberName}.`);
267
200
  }
268
201
  getMemberSchemas() {
269
202
  const buffer = {};
@@ -294,36 +227,17 @@ export class NormalizedSchema {
294
227
  }
295
228
  const struct = this.getSchema();
296
229
  for (let i = 0; i < struct.memberNames.length; ++i) {
297
- yield [struct.memberNames[i], this.memberFrom([struct.memberList[i], 0], struct.memberNames[i])];
298
- }
299
- }
300
- memberFrom(memberSchema, memberName) {
301
- if (memberSchema instanceof NormalizedSchema) {
302
- return Object.assign(memberSchema, {
303
- memberName,
304
- _isMemberSchema: true,
305
- });
306
- }
307
- return new NormalizedSchema(memberSchema, memberName);
308
- }
309
- getSchemaName() {
310
- const schema = this.getSchema();
311
- if (typeof schema === "number") {
312
- const _schema = 63 & schema;
313
- const container = 192 & schema;
314
- const type = Object.entries(SCHEMA).find(([, value]) => {
315
- return value === _schema;
316
- })?.[0] ?? "Unknown";
317
- switch (container) {
318
- case SCHEMA.MAP_MODIFIER:
319
- return `${type}Map`;
320
- case SCHEMA.LIST_MODIFIER:
321
- return `${type}List`;
322
- case 0:
323
- return type;
324
- }
230
+ yield [struct.memberNames[i], member([struct.memberList[i], 0], struct.memberNames[i])];
325
231
  }
326
- return "Unknown";
327
232
  }
328
233
  }
329
- NormalizedSchema.symbol = Symbol.for("@smithy/nor");
234
+ function member(memberSchema, memberName) {
235
+ if (memberSchema instanceof NormalizedSchema) {
236
+ return Object.assign(memberSchema, {
237
+ memberName,
238
+ _isMemberSchema: true,
239
+ });
240
+ }
241
+ const internalCtorAccess = NormalizedSchema;
242
+ return new internalCtorAccess(memberSchema, memberName);
243
+ }
@@ -1,11 +1,12 @@
1
1
  import { Schema } from "./Schema";
2
2
  export class OperationSchema extends Schema {
3
- constructor() {
4
- super(...arguments);
5
- this.symbol = OperationSchema.symbol;
6
- }
3
+ static symbol = Symbol.for("@smithy/ope");
4
+ name;
5
+ traits;
6
+ input;
7
+ output;
8
+ symbol = OperationSchema.symbol;
7
9
  }
8
- OperationSchema.symbol = Symbol.for("@smithy/ope");
9
10
  export const op = (namespace, name, traits, input, output) => Schema.assign(new OperationSchema(), {
10
11
  name,
11
12
  namespace,
@@ -1,5 +1,8 @@
1
1
  import { TypeRegistry } from "../TypeRegistry";
2
2
  export class Schema {
3
+ name;
4
+ namespace;
5
+ traits;
3
6
  static assign(instance, values) {
4
7
  const schema = Object.assign(instance, values);
5
8
  TypeRegistry.for(schema.namespace).register(schema.name, schema);
@@ -1,11 +1,11 @@
1
1
  import { Schema } from "./Schema";
2
2
  export class SimpleSchema extends Schema {
3
- constructor() {
4
- super(...arguments);
5
- this.symbol = SimpleSchema.symbol;
6
- }
3
+ static symbol = Symbol.for("@smithy/sim");
4
+ name;
5
+ schemaRef;
6
+ traits;
7
+ symbol = SimpleSchema.symbol;
7
8
  }
8
- SimpleSchema.symbol = Symbol.for("@smithy/sim");
9
9
  export const sim = (namespace, name, schemaRef, traits) => Schema.assign(new SimpleSchema(), {
10
10
  name,
11
11
  namespace,
@@ -1,11 +1,12 @@
1
1
  import { Schema } from "./Schema";
2
2
  export class StructureSchema extends Schema {
3
- constructor() {
4
- super(...arguments);
5
- this.symbol = StructureSchema.symbol;
6
- }
3
+ static symbol = Symbol.for("@smithy/str");
4
+ name;
5
+ traits;
6
+ memberNames;
7
+ memberList;
8
+ symbol = StructureSchema.symbol;
7
9
  }
8
- StructureSchema.symbol = Symbol.for("@smithy/str");
9
10
  export const struct = (namespace, name, traits, memberNames, memberList) => Schema.assign(new StructureSchema(), {
10
11
  name,
11
12
  namespace,
@@ -1,16 +1,16 @@
1
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,
2
+ BLOB: 0b0001_0101,
3
+ STREAMING_BLOB: 0b0010_1010,
4
+ BOOLEAN: 0b0000_0010,
5
+ STRING: 0b0000_0000,
6
+ NUMERIC: 0b0000_0001,
7
+ BIG_INTEGER: 0b0001_0001,
8
+ BIG_DECIMAL: 0b0001_0011,
9
+ DOCUMENT: 0b0000_1111,
10
+ TIMESTAMP_DEFAULT: 0b0000_0100,
11
+ TIMESTAMP_DATE_TIME: 0b0000_0101,
12
+ TIMESTAMP_HTTP_DATE: 0b0000_0110,
13
+ TIMESTAMP_EPOCH_SECONDS: 0b0000_0111,
14
+ LIST_MODIFIER: 0b0100_0000,
15
+ MAP_MODIFIER: 0b1000_0000,
16
16
  };
@@ -0,0 +1,22 @@
1
+ export function translateTraits(indicator) {
2
+ if (typeof indicator === "object") {
3
+ return indicator;
4
+ }
5
+ indicator = indicator | 0;
6
+ const traits = {};
7
+ let i = 0;
8
+ for (const trait of [
9
+ "httpLabel",
10
+ "idempotent",
11
+ "idempotencyToken",
12
+ "sensitive",
13
+ "httpPayload",
14
+ "httpResponseCode",
15
+ "httpQueryParams",
16
+ ]) {
17
+ if (((indicator >> i++) & 1) === 1) {
18
+ traits[trait] = 1;
19
+ }
20
+ }
21
+ return traits;
22
+ }
@@ -4,6 +4,7 @@ export * from "./generateIdempotencyToken";
4
4
  export * from "./lazy-json";
5
5
  export * from "./parse-utils";
6
6
  export * from "./quote-header";
7
+ export * from "./schema-serde-lib/schema-date-utils";
7
8
  export * from "./split-every";
8
9
  export * from "./split-header";
9
10
  export * from "./value/NumericValue";
@@ -0,0 +1,110 @@
1
+ const ddd = `(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)(?:[ne|u?r]?s?day)?`;
2
+ const mmm = `(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)`;
3
+ const time = `(\\d?\\d):(\\d{2}):(\\d{2})(?:\\.(\\d+))?`;
4
+ const date = `(\\d?\\d)`;
5
+ const year = `(\\d{4})`;
6
+ const RFC3339_WITH_OFFSET = new RegExp(/^(\d{4})-(\d\d)-(\d\d)[tT](\d\d):(\d\d):(\d\d)(\.(\d+))?(([-+]\d\d:\d\d)|[zZ])$/);
7
+ const IMF_FIXDATE = new RegExp(`^${ddd}, ${date} ${mmm} ${year} ${time} GMT$`);
8
+ const RFC_850_DATE = new RegExp(`^${ddd}, ${date}-${mmm}-(\\d\\d) ${time} GMT$`);
9
+ const ASC_TIME = new RegExp(`^${ddd} ${mmm} ( [1-9]|\\d\\d) ${time} ${year}$`);
10
+ const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
11
+ export const _parseEpochTimestamp = (value) => {
12
+ if (value == null) {
13
+ return void 0;
14
+ }
15
+ let num = NaN;
16
+ if (typeof value === "number") {
17
+ num = value;
18
+ }
19
+ else if (typeof value === "string") {
20
+ if (!/^-?\d*\.?\d+$/.test(value)) {
21
+ throw new TypeError(`parseEpochTimestamp - numeric string invalid.`);
22
+ }
23
+ num = Number.parseFloat(value);
24
+ }
25
+ else if (typeof value === "object" && value.tag === 1) {
26
+ num = value.value;
27
+ }
28
+ if (isNaN(num) || Math.abs(num) === Infinity) {
29
+ throw new TypeError("Epoch timestamps must be valid finite numbers.");
30
+ }
31
+ return new Date(Math.round(num * 1000));
32
+ };
33
+ export const _parseRfc3339DateTimeWithOffset = (value) => {
34
+ if (value == null) {
35
+ return void 0;
36
+ }
37
+ if (typeof value !== "string") {
38
+ throw new TypeError("RFC3339 timestamps must be strings");
39
+ }
40
+ const matches = RFC3339_WITH_OFFSET.exec(value);
41
+ if (!matches) {
42
+ throw new TypeError(`Invalid RFC3339 timestamp format ${value}`);
43
+ }
44
+ const [, yearStr, monthStr, dayStr, hours, minutes, seconds, , ms, offsetStr] = matches;
45
+ range(monthStr, 1, 12);
46
+ range(dayStr, 1, 31);
47
+ range(hours, 0, 23);
48
+ range(minutes, 0, 59);
49
+ range(seconds, 0, 60);
50
+ const date = new Date();
51
+ date.setUTCFullYear(Number(yearStr), Number(monthStr) - 1, Number(dayStr));
52
+ date.setUTCHours(Number(hours));
53
+ date.setUTCMinutes(Number(minutes));
54
+ date.setUTCSeconds(Number(seconds));
55
+ date.setUTCMilliseconds(Number(ms) ? Math.round(parseFloat(`0.${ms}`) * 1000) : 0);
56
+ if (offsetStr.toUpperCase() != "Z") {
57
+ const [, sign, offsetH, offsetM] = /([+-])(\d\d):(\d\d)/.exec(offsetStr) || [void 0, "+", 0, 0];
58
+ const scalar = sign === "-" ? 1 : -1;
59
+ date.setTime(date.getTime() + scalar * (Number(offsetH) * 60 * 60 * 1000 + Number(offsetM) * 60 * 1000));
60
+ }
61
+ return date;
62
+ };
63
+ export const _parseRfc7231DateTime = (value) => {
64
+ if (value == null) {
65
+ return void 0;
66
+ }
67
+ if (typeof value !== "string") {
68
+ throw new TypeError("RFC7231 timestamps must be strings.");
69
+ }
70
+ let day;
71
+ let month;
72
+ let year;
73
+ let hour;
74
+ let minute;
75
+ let second;
76
+ let fraction;
77
+ let matches;
78
+ if ((matches = IMF_FIXDATE.exec(value))) {
79
+ [, day, month, year, hour, minute, second, fraction] = matches;
80
+ }
81
+ else if ((matches = RFC_850_DATE.exec(value))) {
82
+ [, day, month, year, hour, minute, second, fraction] = matches;
83
+ year = (Number(year) + 1900).toString();
84
+ }
85
+ else if ((matches = ASC_TIME.exec(value))) {
86
+ [, month, day, hour, minute, second, fraction, year] = matches;
87
+ }
88
+ if (year && second) {
89
+ const date = new Date();
90
+ date.setUTCFullYear(Number(year));
91
+ date.setUTCMonth(months.indexOf(month));
92
+ range(day, 1, 31);
93
+ date.setUTCDate(Number(day));
94
+ range(hour, 0, 23);
95
+ date.setUTCHours(Number(hour));
96
+ range(minute, 0, 59);
97
+ date.setUTCMinutes(Number(minute));
98
+ range(second, 0, 60);
99
+ date.setUTCSeconds(Number(second));
100
+ date.setUTCMilliseconds(fraction ? Math.round(parseFloat(`0.${fraction}`) * 1000) : 0);
101
+ return date;
102
+ }
103
+ throw new TypeError(`Invalid RFC7231 date-time value ${value}.`);
104
+ };
105
+ function range(v, min, max) {
106
+ const _v = Number(v);
107
+ if (_v < min || _v > max) {
108
+ throw new Error(`Value ${_v} out of range [${min}, ${max}]`);
109
+ }
110
+ }
@@ -1,23 +1,12 @@
1
+ const format = /^-?\d*(\.\d+)?$/;
1
2
  export class NumericValue {
3
+ string;
4
+ type;
2
5
  constructor(string, type) {
3
6
  this.string = string;
4
7
  this.type = type;
5
- let dot = 0;
6
- for (let i = 0; i < string.length; ++i) {
7
- const char = string.charCodeAt(i);
8
- if (i === 0 && char === 45) {
9
- continue;
10
- }
11
- if (char === 46) {
12
- if (dot) {
13
- throw new Error("@smithy/core/serde - NumericValue must contain at most one decimal point.");
14
- }
15
- dot = 1;
16
- continue;
17
- }
18
- if (char < 48 || char > 57) {
19
- throw new Error(`@smithy/core/serde - NumericValue must only contain [0-9], at most one decimal point ".", and an optional negation prefix "-".`);
20
- }
8
+ if (!format.test(string)) {
9
+ throw new Error(`@smithy/core/serde - NumericValue must only contain [0-9], at most one decimal point ".", and an optional negation prefix "-".`);
21
10
  }
22
11
  }
23
12
  toString() {
@@ -28,16 +17,7 @@ export class NumericValue {
28
17
  return false;
29
18
  }
30
19
  const _nv = object;
31
- const prototypeMatch = NumericValue.prototype.isPrototypeOf(object);
32
- if (prototypeMatch) {
33
- return prototypeMatch;
34
- }
35
- if (typeof _nv.string === "string" &&
36
- typeof _nv.type === "string" &&
37
- _nv.constructor?.name?.endsWith("NumericValue")) {
38
- return true;
39
- }
40
- return prototypeMatch;
20
+ return NumericValue.prototype.isPrototypeOf(object) || (_nv.type === "bigDecimal" && format.test(_nv.string));
41
21
  }
42
22
  }
43
23
  export function nv(input) {
@@ -1,6 +1,6 @@
1
1
  export class DefaultIdentityProviderConfig {
2
+ authSchemes = new Map();
2
3
  constructor(config) {
3
- this.authSchemes = new Map();
4
4
  for (const [key, value] of Object.entries(config)) {
5
5
  if (value !== undefined) {
6
6
  this.authSchemes.set(key, value);