@smithy/core 1.0.5 → 1.2.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.
package/dist-cjs/index.js CHANGED
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPaginator = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  tslib_1.__exportStar(require("./middleware-http-auth-scheme"), exports);
5
6
  tslib_1.__exportStar(require("./middleware-http-signing"), exports);
6
7
  tslib_1.__exportStar(require("./util-identity-and-auth"), exports);
7
8
  tslib_1.__exportStar(require("./getSmithyContext"), exports);
8
9
  tslib_1.__exportStar(require("./normalizeProvider"), exports);
10
+ tslib_1.__exportStar(require("./protocols/requestBuilder"), exports);
11
+ var createPaginator_1 = require("./pagination/createPaginator");
12
+ Object.defineProperty(exports, "createPaginator", { enumerable: true, get: function () { return createPaginator_1.createPaginator; } });
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPaginator = void 0;
4
+ const makePagedClientRequest = async (CommandCtor, client, input, ...args) => {
5
+ return await client.send(new CommandCtor(input), ...args);
6
+ };
7
+ function createPaginator(ClientCtor, CommandCtor, inputTokenName, outputTokenName, pageSizeTokenName) {
8
+ return async function* paginateOperation(config, input, ...additionalArguments) {
9
+ var _a;
10
+ let token = config.startingToken || undefined;
11
+ let hasNext = true;
12
+ let page;
13
+ while (hasNext) {
14
+ input[inputTokenName] = token;
15
+ if (pageSizeTokenName) {
16
+ input[pageSizeTokenName] = (_a = input[pageSizeTokenName]) !== null && _a !== void 0 ? _a : config.pageSize;
17
+ }
18
+ if (config.client instanceof ClientCtor) {
19
+ page = await makePagedClientRequest(CommandCtor, config.client, input, ...additionalArguments);
20
+ }
21
+ else {
22
+ throw new Error(`Invalid client, expected instance of ${ClientCtor.name}`);
23
+ }
24
+ yield page;
25
+ const prevToken = token;
26
+ token = page[outputTokenName];
27
+ hasNext = !!(token && (!config.stopOnSameToken || token !== prevToken));
28
+ }
29
+ return undefined;
30
+ };
31
+ }
32
+ exports.createPaginator = createPaginator;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequestBuilder = exports.requestBuilder = void 0;
4
+ const protocol_http_1 = require("@smithy/protocol-http");
5
+ const smithy_client_1 = require("@smithy/smithy-client");
6
+ function requestBuilder(input, context) {
7
+ return new RequestBuilder(input, context);
8
+ }
9
+ exports.requestBuilder = requestBuilder;
10
+ class RequestBuilder {
11
+ constructor(input, context) {
12
+ this.input = input;
13
+ this.context = context;
14
+ this.query = {};
15
+ this.method = "";
16
+ this.headers = {};
17
+ this.path = "";
18
+ this.body = null;
19
+ this.hostname = "";
20
+ this.resolvePathStack = [];
21
+ }
22
+ async build() {
23
+ const { hostname, protocol = "https", port, path: basePath } = await this.context.endpoint();
24
+ this.path = basePath;
25
+ for (const resolvePath of this.resolvePathStack) {
26
+ resolvePath(this.path);
27
+ }
28
+ return new protocol_http_1.HttpRequest({
29
+ protocol,
30
+ hostname: this.hostname || hostname,
31
+ port,
32
+ method: this.method,
33
+ path: this.path,
34
+ query: this.query,
35
+ body: this.body,
36
+ headers: this.headers,
37
+ });
38
+ }
39
+ hn(hostname) {
40
+ this.hostname = hostname;
41
+ return this;
42
+ }
43
+ bp(uriLabel) {
44
+ this.resolvePathStack.push((basePath) => {
45
+ this.path = `${(basePath === null || basePath === void 0 ? void 0 : basePath.endsWith("/")) ? basePath.slice(0, -1) : basePath || ""}` + uriLabel;
46
+ });
47
+ return this;
48
+ }
49
+ p(memberName, labelValueProvider, uriLabel, isGreedyLabel) {
50
+ this.resolvePathStack.push((path) => {
51
+ this.path = (0, smithy_client_1.resolvedPath)(path, this.input, memberName, labelValueProvider, uriLabel, isGreedyLabel);
52
+ });
53
+ return this;
54
+ }
55
+ h(headers) {
56
+ this.headers = headers;
57
+ return this;
58
+ }
59
+ q(query) {
60
+ this.query = query;
61
+ return this;
62
+ }
63
+ b(body) {
64
+ this.body = body;
65
+ return this;
66
+ }
67
+ m(method) {
68
+ this.method = method;
69
+ return this;
70
+ }
71
+ }
72
+ exports.RequestBuilder = RequestBuilder;
package/dist-es/index.js CHANGED
@@ -3,3 +3,5 @@ export * from "./middleware-http-signing";
3
3
  export * from "./util-identity-and-auth";
4
4
  export * from "./getSmithyContext";
5
5
  export * from "./normalizeProvider";
6
+ export * from "./protocols/requestBuilder";
7
+ export { createPaginator } from "./pagination/createPaginator";
@@ -0,0 +1,27 @@
1
+ const makePagedClientRequest = async (CommandCtor, client, input, ...args) => {
2
+ return await client.send(new CommandCtor(input), ...args);
3
+ };
4
+ export function createPaginator(ClientCtor, CommandCtor, inputTokenName, outputTokenName, pageSizeTokenName) {
5
+ return async function* paginateOperation(config, input, ...additionalArguments) {
6
+ let token = config.startingToken || undefined;
7
+ let hasNext = true;
8
+ let page;
9
+ while (hasNext) {
10
+ input[inputTokenName] = token;
11
+ if (pageSizeTokenName) {
12
+ input[pageSizeTokenName] = input[pageSizeTokenName] ?? config.pageSize;
13
+ }
14
+ if (config.client instanceof ClientCtor) {
15
+ page = await makePagedClientRequest(CommandCtor, config.client, input, ...additionalArguments);
16
+ }
17
+ else {
18
+ throw new Error(`Invalid client, expected instance of ${ClientCtor.name}`);
19
+ }
20
+ yield page;
21
+ const prevToken = token;
22
+ token = page[outputTokenName];
23
+ hasNext = !!(token && (!config.stopOnSameToken || token !== prevToken));
24
+ }
25
+ return undefined;
26
+ };
27
+ }
@@ -0,0 +1,67 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import { resolvedPath } from "@smithy/smithy-client";
3
+ export function requestBuilder(input, context) {
4
+ return new RequestBuilder(input, context);
5
+ }
6
+ export class RequestBuilder {
7
+ constructor(input, context) {
8
+ this.input = input;
9
+ this.context = context;
10
+ this.query = {};
11
+ this.method = "";
12
+ this.headers = {};
13
+ this.path = "";
14
+ this.body = null;
15
+ this.hostname = "";
16
+ this.resolvePathStack = [];
17
+ }
18
+ async build() {
19
+ const { hostname, protocol = "https", port, path: basePath } = await this.context.endpoint();
20
+ this.path = basePath;
21
+ for (const resolvePath of this.resolvePathStack) {
22
+ resolvePath(this.path);
23
+ }
24
+ return new HttpRequest({
25
+ protocol,
26
+ hostname: this.hostname || hostname,
27
+ port,
28
+ method: this.method,
29
+ path: this.path,
30
+ query: this.query,
31
+ body: this.body,
32
+ headers: this.headers,
33
+ });
34
+ }
35
+ hn(hostname) {
36
+ this.hostname = hostname;
37
+ return this;
38
+ }
39
+ bp(uriLabel) {
40
+ this.resolvePathStack.push((basePath) => {
41
+ this.path = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + uriLabel;
42
+ });
43
+ return this;
44
+ }
45
+ p(memberName, labelValueProvider, uriLabel, isGreedyLabel) {
46
+ this.resolvePathStack.push((path) => {
47
+ this.path = resolvedPath(path, this.input, memberName, labelValueProvider, uriLabel, isGreedyLabel);
48
+ });
49
+ return this;
50
+ }
51
+ h(headers) {
52
+ this.headers = headers;
53
+ return this;
54
+ }
55
+ q(query) {
56
+ this.query = query;
57
+ return this;
58
+ }
59
+ b(body) {
60
+ this.body = body;
61
+ return this;
62
+ }
63
+ m(method) {
64
+ this.method = method;
65
+ return this;
66
+ }
67
+ }
@@ -3,3 +3,5 @@ export * from "./middleware-http-signing";
3
3
  export * from "./util-identity-and-auth";
4
4
  export * from "./getSmithyContext";
5
5
  export * from "./normalizeProvider";
6
+ export * from "./protocols/requestBuilder";
7
+ export { createPaginator } from "./pagination/createPaginator";
@@ -0,0 +1,7 @@
1
+ import type { PaginationConfiguration, Paginator } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ *
5
+ * Creates a paginator.
6
+ */
7
+ export declare function createPaginator<PaginationConfigType extends PaginationConfiguration, InputType extends object, OutputType extends object>(ClientCtor: any, CommandCtor: any, inputTokenName: string, outputTokenName: string, pageSizeTokenName?: string): (config: PaginationConfigType, input: InputType, ...additionalArguments: any[]) => Paginator<OutputType>;
@@ -0,0 +1,51 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import type { SerdeContext } from "@smithy/types";
3
+ /**
4
+ * @internal
5
+ * used in code-generated serde.
6
+ */
7
+ export declare function requestBuilder(input: any, context: SerdeContext): RequestBuilder;
8
+ /**
9
+ * @internal
10
+ */
11
+ export declare class RequestBuilder {
12
+ private input;
13
+ private context;
14
+ private query;
15
+ private method;
16
+ private headers;
17
+ private path;
18
+ private body;
19
+ private hostname;
20
+ private resolvePathStack;
21
+ constructor(input: any, context: SerdeContext);
22
+ build(): Promise<HttpRequest>;
23
+ /**
24
+ * Brevity setter for "hostname".
25
+ */
26
+ hn(hostname: string): this;
27
+ /**
28
+ * Brevity initial builder for "basepath".
29
+ */
30
+ bp(uriLabel: string): this;
31
+ /**
32
+ * Brevity incremental builder for "path".
33
+ */
34
+ p(memberName: string, labelValueProvider: () => string | undefined, uriLabel: string, isGreedyLabel: boolean): this;
35
+ /**
36
+ * Brevity setter for "headers".
37
+ */
38
+ h(headers: Record<string, string>): this;
39
+ /**
40
+ * Brevity setter for "query".
41
+ */
42
+ q(query: Record<string, string>): this;
43
+ /**
44
+ * Brevity setter for "body".
45
+ */
46
+ b(body: any): this;
47
+ /**
48
+ * Brevity setter for "method".
49
+ */
50
+ m(method: string): this;
51
+ }
@@ -3,3 +3,5 @@ export * from "./middleware-http-signing";
3
3
  export * from "./util-identity-and-auth";
4
4
  export * from "./getSmithyContext";
5
5
  export * from "./normalizeProvider";
6
+ export * from "./protocols/requestBuilder";
7
+ export { createPaginator } from "./pagination/createPaginator";
@@ -0,0 +1,7 @@
1
+ import { PaginationConfiguration, Paginator } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ *
5
+ * Creates a paginator.
6
+ */
7
+ export declare function createPaginator<PaginationConfigType extends PaginationConfiguration, InputType extends object, OutputType extends object>(ClientCtor: any, CommandCtor: any, inputTokenName: string, outputTokenName: string, pageSizeTokenName?: string): (config: PaginationConfigType, input: InputType, ...additionalArguments: any[]) => Paginator<OutputType>;
@@ -0,0 +1,51 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import { SerdeContext } from "@smithy/types";
3
+ /**
4
+ * @internal
5
+ * used in code-generated serde.
6
+ */
7
+ export declare function requestBuilder(input: any, context: SerdeContext): RequestBuilder;
8
+ /**
9
+ * @internal
10
+ */
11
+ export declare class RequestBuilder {
12
+ private input;
13
+ private context;
14
+ private query;
15
+ private method;
16
+ private headers;
17
+ private path;
18
+ private body;
19
+ private hostname;
20
+ private resolvePathStack;
21
+ constructor(input: any, context: SerdeContext);
22
+ build(): Promise<HttpRequest>;
23
+ /**
24
+ * Brevity setter for "hostname".
25
+ */
26
+ hn(hostname: string): this;
27
+ /**
28
+ * Brevity initial builder for "basepath".
29
+ */
30
+ bp(uriLabel: string): this;
31
+ /**
32
+ * Brevity incremental builder for "path".
33
+ */
34
+ p(memberName: string, labelValueProvider: () => string | undefined, uriLabel: string, isGreedyLabel: boolean): this;
35
+ /**
36
+ * Brevity setter for "headers".
37
+ */
38
+ h(headers: Record<string, string>): this;
39
+ /**
40
+ * Brevity setter for "query".
41
+ */
42
+ q(query: Record<string, string>): this;
43
+ /**
44
+ * Brevity setter for "body".
45
+ */
46
+ b(body: any): this;
47
+ /**
48
+ * Brevity setter for "method".
49
+ */
50
+ m(method: string): this;
51
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/core",
3
- "version": "1.0.5",
3
+ "version": "1.2.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "yarn g:tsc -p tsconfig.cjs.json",
@@ -27,7 +27,9 @@
27
27
  "@smithy/middleware-retry": "^2.0.24",
28
28
  "@smithy/middleware-serde": "^2.0.15",
29
29
  "@smithy/protocol-http": "^3.0.11",
30
+ "@smithy/smithy-client": "^2.1.18",
30
31
  "@smithy/types": "^2.7.0",
32
+ "@smithy/util-middleware": "^2.0.8",
31
33
  "tslib": "^2.5.0"
32
34
  },
33
35
  "engines": {