@smithy/core 3.7.2 → 3.9.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 (54) hide show
  1. package/dist-cjs/submodules/cbor/index.js +121 -53
  2. package/dist-cjs/submodules/event-streams/index.js +261 -0
  3. package/dist-cjs/submodules/protocols/index.js +197 -104
  4. package/dist-cjs/submodules/schema/index.js +37 -0
  5. package/dist-cjs/submodules/serde/index.js +6 -51
  6. package/dist-es/submodules/cbor/CborCodec.js +77 -41
  7. package/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +36 -15
  8. package/dist-es/submodules/event-streams/EventStreamSerde.js +200 -0
  9. package/dist-es/submodules/event-streams/index.js +1 -0
  10. package/dist-es/submodules/protocols/HttpBindingProtocol.js +86 -6
  11. package/dist-es/submodules/protocols/HttpProtocol.js +42 -94
  12. package/dist-es/submodules/protocols/RpcProtocol.js +36 -10
  13. package/dist-es/submodules/protocols/index.js +1 -0
  14. package/dist-es/submodules/schema/schemas/NormalizedSchema.js +26 -0
  15. package/dist-es/submodules/serde/copyDocumentWithTransform.js +1 -53
  16. package/dist-es/submodules/serde/generateIdempotencyToken.js +2 -0
  17. package/dist-es/submodules/serde/index.js +1 -0
  18. package/dist-types/submodules/cbor/CborCodec.d.ts +11 -2
  19. package/dist-types/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +1 -0
  20. package/dist-types/submodules/cbor/parseCborBody.d.ts +1 -1
  21. package/dist-types/submodules/event-streams/EventStreamSerde.d.ts +60 -0
  22. package/dist-types/submodules/event-streams/index.d.ts +1 -0
  23. package/dist-types/submodules/protocols/HttpBindingProtocol.d.ts +9 -1
  24. package/dist-types/submodules/protocols/HttpProtocol.d.ts +42 -2
  25. package/dist-types/submodules/protocols/RpcProtocol.d.ts +1 -1
  26. package/dist-types/submodules/protocols/index.d.ts +1 -0
  27. package/dist-types/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +1 -1
  28. package/dist-types/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +1 -1
  29. package/dist-types/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +1 -1
  30. package/dist-types/submodules/protocols/serde/ToStringShapeSerializer.d.ts +1 -1
  31. package/dist-types/submodules/protocols/serde/determineTimestampFormat.d.ts +1 -1
  32. package/dist-types/submodules/schema/middleware/getSchemaSerdePlugin.d.ts +1 -1
  33. package/dist-types/submodules/schema/middleware/schemaDeserializationMiddleware.d.ts +1 -1
  34. package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +15 -0
  35. package/dist-types/submodules/schema/schemas/SimpleSchema.d.ts +1 -1
  36. package/dist-types/submodules/schema/schemas/sentinels.d.ts +1 -1
  37. package/dist-types/submodules/serde/copyDocumentWithTransform.d.ts +2 -1
  38. package/dist-types/submodules/serde/generateIdempotencyToken.d.ts +2 -0
  39. package/dist-types/submodules/serde/index.d.ts +1 -0
  40. package/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +10 -1
  41. package/dist-types/ts3.4/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +1 -0
  42. package/dist-types/ts3.4/submodules/event-streams/EventStreamSerde.d.ts +60 -0
  43. package/dist-types/ts3.4/submodules/event-streams/index.d.ts +1 -0
  44. package/dist-types/ts3.4/submodules/protocols/HttpBindingProtocol.d.ts +9 -1
  45. package/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +42 -2
  46. package/dist-types/ts3.4/submodules/protocols/index.d.ts +1 -0
  47. package/dist-types/ts3.4/submodules/protocols/serde/determineTimestampFormat.d.ts +1 -1
  48. package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +15 -0
  49. package/dist-types/ts3.4/submodules/serde/copyDocumentWithTransform.d.ts +1 -0
  50. package/dist-types/ts3.4/submodules/serde/generateIdempotencyToken.d.ts +2 -0
  51. package/dist-types/ts3.4/submodules/serde/index.d.ts +1 -0
  52. package/event-streams.d.ts +7 -0
  53. package/event-streams.js +6 -0
  54. package/package.json +19 -7
@@ -0,0 +1,2 @@
1
+ import { v4 as generateIdempotencyToken } from "uuid";
2
+ export { generateIdempotencyToken };
@@ -1,5 +1,6 @@
1
1
  export * from "./copyDocumentWithTransform";
2
2
  export * from "./date-utils";
3
+ export * from "./generateIdempotencyToken";
3
4
  export * from "./lazy-json";
4
5
  export * from "./parse-utils";
5
6
  export * from "./quote-header";
@@ -16,6 +16,11 @@ export declare class CborShapeSerializer implements ShapeSerializer {
16
16
  private value;
17
17
  setSerdeContext(serdeContext: SerdeFunctions): void;
18
18
  write(schema: Schema, value: unknown): void;
19
+ /**
20
+ * Recursive serializer transform that copies and prepares the user input object
21
+ * for CBOR serialization.
22
+ */
23
+ serialize(schema: Schema, source: unknown): any;
19
24
  flush(): Uint8Array;
20
25
  }
21
26
  /**
@@ -25,5 +30,9 @@ export declare class CborShapeDeserializer implements ShapeDeserializer {
25
30
  private serdeContext?;
26
31
  setSerdeContext(serdeContext: SerdeFunctions): void;
27
32
  read(schema: Schema, bytes: Uint8Array): any;
28
- private readValue;
33
+ /**
34
+ * Public because it's called by the protocol implementation to deserialize errors.
35
+ * @internal
36
+ */
37
+ readValue(_schema: Schema, value: any): any;
29
38
  }
@@ -19,4 +19,5 @@ export declare class SmithyRpcV2CborProtocol extends RpcProtocol {
19
19
  serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<IHttpRequest>;
20
20
  deserializeResponse<Output extends MetadataBearer>(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse): Promise<Output>;
21
21
  protected handleError(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any, metadata: ResponseMetadata): Promise<never>;
22
+ protected getDefaultContentType(): string;
22
23
  }
@@ -0,0 +1,60 @@
1
+ import { NormalizedSchema } from "@smithy/core/schema";
2
+ import { EventStreamMarshaller, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
3
+ /**
4
+ * Separated module for async mixin of EventStream serde capability.
5
+ * This is used by the HttpProtocol base class from \@smithy/core/protocols.
6
+ *
7
+ * @alpha
8
+ */
9
+ export declare class EventStreamSerde {
10
+ private readonly marshaller;
11
+ private readonly serializer;
12
+ private readonly deserializer;
13
+ private readonly serdeContext?;
14
+ private readonly defaultContentType;
15
+ /**
16
+ * Properties are injected by the HttpProtocol.
17
+ */
18
+ constructor({ marshaller, serializer, deserializer, serdeContext, defaultContentType, }: {
19
+ marshaller: EventStreamMarshaller;
20
+ serializer: ShapeSerializer<string | Uint8Array>;
21
+ deserializer: ShapeDeserializer<string | Uint8Array>;
22
+ serdeContext?: SerdeFunctions;
23
+ defaultContentType: string;
24
+ });
25
+ /**
26
+ * @param eventStream - the iterable provided by the caller.
27
+ * @param requestSchema - the schema of the event stream container (struct).
28
+ * @param [initialRequest] - only provided if the initial-request is part of the event stream (RPC).
29
+ *
30
+ * @returns a stream suitable for the HTTP body of a request.
31
+ */
32
+ serializeEventStream({ eventStream, requestSchema, initialRequest, }: {
33
+ eventStream: AsyncIterable<any>;
34
+ requestSchema: NormalizedSchema;
35
+ initialRequest?: any;
36
+ }): Promise<IHttpRequest["body"] | Uint8Array>;
37
+ /**
38
+ * @param response - http response from which to read the event stream.
39
+ * @param unionSchema - schema of the event stream container (struct).
40
+ * @param [initialResponseContainer] - provided and written to only if the initial response is part of the event stream (RPC).
41
+ *
42
+ * @returns the asyncIterable of the event stream for the end-user.
43
+ */
44
+ deserializeEventStream({ response, responseSchema, initialResponseContainer, }: {
45
+ response: IHttpResponse;
46
+ responseSchema: NormalizedSchema;
47
+ initialResponseContainer?: any;
48
+ }): Promise<AsyncIterable<{
49
+ [key: string]: any;
50
+ $unknown?: unknown;
51
+ }>>;
52
+ /**
53
+ * @param unionMember - member name within the structure that contains an event stream union.
54
+ * @param unionSchema - schema of the union.
55
+ * @param event
56
+ *
57
+ * @returns the event body (bytes) and event type (string).
58
+ */
59
+ private writeEventBody;
60
+ }
@@ -0,0 +1 @@
1
+ export * from "./EventStreamSerde";
@@ -1,6 +1,6 @@
1
1
  import { NormalizedSchema } from "@smithy/core/schema";
2
2
  import { HttpRequest } from "@smithy/protocol-http";
3
- import { EndpointBearer, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, SerdeFunctions } from "@smithy/types";
3
+ import { EndpointBearer, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, Schema, SerdeFunctions } from "@smithy/types";
4
4
  import { HttpProtocol } from "./HttpProtocol";
5
5
  /**
6
6
  * Base for HTTP-binding protocols. Downstream examples
@@ -12,4 +12,12 @@ export declare abstract class HttpBindingProtocol extends HttpProtocol {
12
12
  serializeRequest<Input extends object>(operationSchema: OperationSchema, _input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<IHttpRequest>;
13
13
  protected serializeQuery(ns: NormalizedSchema, data: any, query: HttpRequest["query"]): void;
14
14
  deserializeResponse<Output extends MetadataBearer>(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse): Promise<Output>;
15
+ /**
16
+ * The base method ignores HTTP bindings.
17
+ *
18
+ * @deprecated (only this signature) use signature without headerBindings.
19
+ * @override
20
+ */
21
+ protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, headerBindings: Set<string>, dataObject: any): Promise<string[]>;
22
+ protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any): Promise<string[]>;
15
23
  }
@@ -1,4 +1,6 @@
1
- import { ClientProtocol, Codec, Endpoint, EndpointBearer, EndpointV2, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, ResponseMetadata, Schema, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
1
+ import { EventStreamSerde } from "@smithy/core/event-streams";
2
+ import { NormalizedSchema } from "@smithy/core/schema";
3
+ import { ClientProtocol, Codec, Endpoint, EndpointBearer, EndpointV2, EventStreamMarshaller, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, ResponseMetadata, Schema, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
2
4
  /**
3
5
  * Abstract base for HTTP-based client protocols.
4
6
  *
@@ -26,8 +28,46 @@ export declare abstract class HttpProtocol implements ClientProtocol<IHttpReques
26
28
  protected abstract handleError(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any, metadata: ResponseMetadata): Promise<never>;
27
29
  protected deserializeMetadata(output: IHttpResponse): ResponseMetadata;
28
30
  /**
29
- * @deprecated use signature without headerBindings.
31
+ * @param eventStream - the iterable provided by the caller.
32
+ * @param requestSchema - the schema of the event stream container (struct).
33
+ * @param [initialRequest] - only provided if the initial-request is part of the event stream (RPC).
34
+ *
35
+ * @returns a stream suitable for the HTTP body of a request.
36
+ */
37
+ protected serializeEventStream({ eventStream, requestSchema, initialRequest, }: {
38
+ eventStream: AsyncIterable<any>;
39
+ requestSchema: NormalizedSchema;
40
+ initialRequest?: any;
41
+ }): Promise<IHttpRequest["body"]>;
42
+ /**
43
+ * @param response - http response from which to read the event stream.
44
+ * @param unionSchema - schema of the event stream container (struct).
45
+ * @param [initialResponseContainer] - provided and written to only if the initial response is part of the event stream (RPC).
46
+ *
47
+ * @returns the asyncIterable of the event stream.
48
+ */
49
+ protected deserializeEventStream({ response, responseSchema, initialResponseContainer, }: {
50
+ response: IHttpResponse;
51
+ responseSchema: NormalizedSchema;
52
+ initialResponseContainer?: any;
53
+ }): Promise<AsyncIterable<{
54
+ [key: string]: any;
55
+ $unknown?: unknown;
56
+ }>>;
57
+ /**
58
+ * Loads eventStream capability async (for chunking).
59
+ */
60
+ protected loadEventStreamCapability(): Promise<EventStreamSerde>;
61
+ /**
62
+ * @returns content-type default header value for event stream events and other documents.
63
+ */
64
+ protected getDefaultContentType(): string;
65
+ /**
66
+ * For HTTP binding protocols, this method is overridden in {@link HttpBindingProtocol}.
67
+ *
68
+ * @deprecated only use this for HTTP binding protocols.
30
69
  */
31
70
  protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, headerBindings: Set<string>, dataObject: any): Promise<string[]>;
32
71
  protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any): Promise<string[]>;
72
+ protected getEventStreamMarshaller(): EventStreamMarshaller;
33
73
  }
@@ -1,6 +1,7 @@
1
1
  export * from "./collect-stream-body";
2
2
  export * from "./extended-encode-uri-component";
3
3
  export * from "./HttpBindingProtocol";
4
+ export * from "./HttpProtocol";
4
5
  export * from "./RpcProtocol";
5
6
  export * from "./requestBuilder";
6
7
  export * from "./resolve-path";
@@ -1,5 +1,5 @@
1
1
  import { NormalizedSchema } from "@smithy/core/schema";
2
- import { TimestampDateTimeSchema, TimestampEpochSecondsSchema, TimestampHttpDateSchema, CodecSettings } from "@smithy/types";
2
+ import { CodecSettings, TimestampDateTimeSchema, TimestampEpochSecondsSchema, TimestampHttpDateSchema } from "@smithy/types";
3
3
  /**
4
4
  * Assuming the schema is a timestamp type, the function resolves the format using
5
5
  * either the timestamp's own traits, or the default timestamp format from the CodecSettings.
@@ -66,6 +66,11 @@ export declare class NormalizedSchema implements INormalizedSchema {
66
66
  isBigIntegerSchema(): boolean;
67
67
  isBigDecimalSchema(): boolean;
68
68
  isStreaming(): boolean;
69
+ /**
70
+ * This is a shortcut to avoid calling `getMergedTraits().idempotencyToken` on every string.
71
+ * @returns whether the schema has the idempotencyToken trait.
72
+ */
73
+ isIdempotencyToken(): boolean;
69
74
  /**
70
75
  * @returns own traits merged with member traits, where member traits of the same trait key take priority.
71
76
  * This method is cached.
@@ -93,6 +98,11 @@ export declare class NormalizedSchema implements INormalizedSchema {
93
98
  * @throws Error if the schema is not a Map, List, nor Document.
94
99
  */
95
100
  getValueSchema(): NormalizedSchema;
101
+ /**
102
+ * @param member - to query.
103
+ * @returns whether there is a memberSchema with the given member name. False if not a structure (or union).
104
+ */
105
+ hasMemberSchema(member: string): boolean;
96
106
  /**
97
107
  * @returns the NormalizedSchema for the given member name. The returned instance will return true for `isMemberSchema()`
98
108
  * and will have the member name given.
@@ -111,6 +121,11 @@ export declare class NormalizedSchema implements INormalizedSchema {
111
121
  * @returns a map of member names to member schemas (normalized).
112
122
  */
113
123
  getMemberSchemas(): Record<string, NormalizedSchema>;
124
+ /**
125
+ * @returns member name of event stream or empty string indicating none exists or this
126
+ * isn't a structure schema.
127
+ */
128
+ getEventStreamMember(): string;
114
129
  /**
115
130
  * Allows iteration over members of a structure schema.
116
131
  * Each yield is a pair of the member name and member schema.
@@ -1,5 +1,6 @@
1
1
  import { SchemaRef } from "@smithy/types";
2
2
  /**
3
3
  * @internal
4
+ * @deprecated the former functionality has been internalized to the CborCodec.
4
5
  */
5
6
  export declare const copyDocumentWithTransform: (source: any, schemaRef: SchemaRef, transform?: (_: any, schemaRef: SchemaRef) => any) => any;
@@ -0,0 +1,2 @@
1
+ import { v4 as generateIdempotencyToken } from "uuid";
2
+ export { generateIdempotencyToken };
@@ -1,5 +1,6 @@
1
1
  export * from "./copyDocumentWithTransform";
2
2
  export * from "./date-utils";
3
+ export * from "./generateIdempotencyToken";
3
4
  export * from "./lazy-json";
4
5
  export * from "./parse-utils";
5
6
  export * from "./quote-header";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Do not edit:
3
+ * This is a compatibility redirect for contexts that do not understand package.json exports field.
4
+ */
5
+ declare module "@smithy/core/event-streams" {
6
+ export * from "@smithy/core/dist-types/submodules/event-streams/index.d";
7
+ }
@@ -0,0 +1,6 @@
1
+
2
+ /**
3
+ * Do not edit:
4
+ * This is a compatibility redirect for contexts that do not understand package.json exports field.
5
+ */
6
+ module.exports = require("./dist-cjs/submodules/event-streams/index.js");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/core",
3
- "version": "3.7.2",
3
+ "version": "3.9.0",
4
4
  "scripts": {
5
5
  "build": "yarn lint && concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "node ../../scripts/inline core",
@@ -60,6 +60,13 @@
60
60
  "node": "./dist-cjs/submodules/schema/index.js",
61
61
  "import": "./dist-es/submodules/schema/index.js",
62
62
  "require": "./dist-cjs/submodules/schema/index.js"
63
+ },
64
+ "./event-streams": {
65
+ "types": "./dist-types/submodules/event-streams/index.d.ts",
66
+ "module": "./dist-es/submodules/event-streams/index.js",
67
+ "node": "./dist-cjs/submodules/event-streams/index.js",
68
+ "import": "./dist-es/submodules/event-streams/index.js",
69
+ "require": "./dist-cjs/submodules/event-streams/index.js"
63
70
  }
64
71
  },
65
72
  "author": {
@@ -70,15 +77,17 @@
70
77
  "license": "Apache-2.0",
71
78
  "sideEffects": false,
72
79
  "dependencies": {
73
- "@smithy/middleware-serde": "^4.0.8",
74
- "@smithy/protocol-http": "^5.1.2",
75
- "@smithy/types": "^4.3.1",
80
+ "@smithy/middleware-serde": "^4.0.9",
81
+ "@smithy/protocol-http": "^5.1.3",
82
+ "@smithy/types": "^4.3.2",
76
83
  "@smithy/util-base64": "^4.0.0",
77
84
  "@smithy/util-body-length-browser": "^4.0.0",
78
- "@smithy/util-middleware": "^4.0.4",
79
- "@smithy/util-stream": "^4.2.3",
85
+ "@smithy/util-middleware": "^4.0.5",
86
+ "@smithy/util-stream": "^4.2.4",
80
87
  "@smithy/util-utf8": "^4.0.0",
81
- "tslib": "^2.6.2"
88
+ "@types/uuid": "^9.0.1",
89
+ "tslib": "^2.6.2",
90
+ "uuid": "^9.0.1"
82
91
  },
83
92
  "engines": {
84
93
  "node": ">=18.0.0"
@@ -93,6 +102,8 @@
93
102
  "files": [
94
103
  "./cbor.d.ts",
95
104
  "./cbor.js",
105
+ "./event-streams.d.ts",
106
+ "./event-streams.js",
96
107
  "./protocols.d.ts",
97
108
  "./protocols.js",
98
109
  "./schema.d.ts",
@@ -108,6 +119,7 @@
108
119
  "directory": "packages/core"
109
120
  },
110
121
  "devDependencies": {
122
+ "@smithy/eventstream-serde-node": "^4.0.5",
111
123
  "@types/node": "^18.11.9",
112
124
  "concurrently": "7.0.0",
113
125
  "downlevel-dts": "0.10.1",