@smithy/core 1.1.0 → 1.2.1
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 +3 -0
- package/dist-cjs/pagination/createPaginator.js +32 -0
- package/dist-es/index.js +1 -0
- package/dist-es/pagination/createPaginator.js +27 -0
- package/dist-types/index.d.ts +1 -0
- package/dist-types/pagination/createPaginator.d.ts +7 -0
- package/dist-types/ts3.4/index.d.ts +1 -0
- package/dist-types/ts3.4/pagination/createPaginator.d.ts +7 -0
- package/package.json +4 -3
package/dist-cjs/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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);
|
|
@@ -7,3 +8,5 @@ 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);
|
|
9
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;
|
package/dist-es/index.js
CHANGED
|
@@ -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
|
+
}
|
package/dist-types/index.d.ts
CHANGED
|
@@ -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,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>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/core",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
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",
|
|
@@ -24,11 +24,12 @@
|
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@smithy/middleware-endpoint": "^2.2.3",
|
|
27
|
-
"@smithy/middleware-retry": "^2.0.
|
|
27
|
+
"@smithy/middleware-retry": "^2.0.25",
|
|
28
28
|
"@smithy/middleware-serde": "^2.0.15",
|
|
29
29
|
"@smithy/protocol-http": "^3.0.11",
|
|
30
|
-
"@smithy/smithy-client": "^2.
|
|
30
|
+
"@smithy/smithy-client": "^2.2.0",
|
|
31
31
|
"@smithy/types": "^2.7.0",
|
|
32
|
+
"@smithy/util-middleware": "^2.0.8",
|
|
32
33
|
"tslib": "^2.5.0"
|
|
33
34
|
},
|
|
34
35
|
"engines": {
|