@shelf/dynamodb-parallel-scan
Advanced tools
Comparing version 3.4.0 to 3.5.0
import type { BatchWriteCommandOutput, ScanCommandInput, ScanCommandOutput } from '@aws-sdk/lib-dynamodb'; | ||
export declare function scan(params: ScanCommandInput): Promise<ScanCommandOutput>; | ||
export declare function getTableItemsCount(tableName: string): Promise<number>; | ||
export type Credentials = { | ||
accessKeyId: string; | ||
secretAccessKey: string; | ||
sessionToken: string; | ||
}; | ||
export declare function scan(params: ScanCommandInput, credentials?: Credentials): Promise<ScanCommandOutput>; | ||
export declare function getTableItemsCount(tableName: string, credentials?: Credentials): Promise<number>; | ||
export declare function insertMany({ items, tableName, }: { | ||
items: any[]; | ||
tableName: string; | ||
}): Promise<BatchWriteCommandOutput>; | ||
}, credentials?: Credentials): Promise<BatchWriteCommandOutput>; |
@@ -14,23 +14,31 @@ "use strict"; | ||
const region = process.env.REGION; | ||
const ddbv3Client = new _clientDynamodb.DynamoDBClient({ | ||
const ddbv3Client = credentials => new _clientDynamodb.DynamoDBClient({ | ||
...(isTest && { | ||
endpoint: endpoint ?? 'http://localhost:8000', | ||
tls: false, | ||
region: region ?? 'local-env', | ||
credentials: { | ||
accessKeyId: 'fakeMyKeyId', | ||
secretAccessKey: 'fakeSecretAccessKey' | ||
} | ||
}) | ||
region: region ?? 'local-env' | ||
}), | ||
credentials: getCredentials(credentials) | ||
}); | ||
const ddbv3DocClient = _libDynamodb.DynamoDBDocumentClient.from(ddbv3Client); | ||
function scan(params) { | ||
const getCredentials = credentials => { | ||
if (credentials && Object.keys(credentials).length) { | ||
return credentials; | ||
} | ||
return { | ||
accessKeyId: 'fakeMyKeyId', | ||
secretAccessKey: 'fakeSecretAccessKey' | ||
}; | ||
}; | ||
const ddbv3DocClient = credentials => _libDynamodb.DynamoDBDocumentClient.from(ddbv3Client(credentials)); | ||
function scan(params, credentials) { | ||
const command = new _libDynamodb.ScanCommand(params); | ||
return ddbv3Client.send(command); | ||
// @ts-ignore | ||
return ddbv3Client(credentials).send(command); | ||
} | ||
async function getTableItemsCount(tableName) { | ||
async function getTableItemsCount(tableName, credentials) { | ||
const command = new _clientDynamodb.DescribeTableCommand({ | ||
TableName: tableName | ||
}); | ||
const resp = await ddbv3Client.send(command); | ||
const resp = await ddbv3Client(credentials).send(command); | ||
return resp.Table.ItemCount; | ||
@@ -41,3 +49,3 @@ } | ||
tableName | ||
}) { | ||
}, credentials) { | ||
const params = { | ||
@@ -52,5 +60,5 @@ [tableName]: items.map(item => { | ||
}; | ||
return batchWrite(params); | ||
return batchWrite(params, credentials); | ||
} | ||
function batchWrite(items) { | ||
function batchWrite(items, credentials) { | ||
const command = new _libDynamodb.BatchWriteCommand({ | ||
@@ -61,3 +69,5 @@ RequestItems: items, | ||
}); | ||
return ddbv3DocClient.send(command); | ||
// @ts-ignore | ||
return ddbv3DocClient(credentials).send(command); | ||
} |
/// <reference types="node" /> | ||
import { Readable } from 'stream'; | ||
import type { ScanCommandInput } from '@aws-sdk/lib-dynamodb'; | ||
export declare function parallelScanAsStream(scanParams: ScanCommandInput, { concurrency, chunkSize, highWaterMark, }: { | ||
import type { Credentials } from './ddb'; | ||
export declare function parallelScanAsStream(scanParams: ScanCommandInput, { concurrency, chunkSize, highWaterMark, credentials, }: { | ||
concurrency: number; | ||
chunkSize: number; | ||
highWaterMark?: number; | ||
credentials?: Credentials; | ||
}): Promise<Readable>; |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.parallelScanAsStream = parallelScanAsStream; | ||
var _stream = require("stream"); | ||
var _lodash = _interopRequireDefault(require("lodash.clonedeep")); | ||
@@ -12,3 +13,2 @@ var _lodash2 = _interopRequireDefault(require("lodash.times")); | ||
var _debug = _interopRequireDefault(require("debug")); | ||
var _stream = require("stream"); | ||
var _ddb = require("./ddb"); | ||
@@ -24,5 +24,6 @@ var _blocker = require("./blocker"); | ||
chunkSize, | ||
highWaterMark = Number.MAX_SAFE_INTEGER | ||
highWaterMark = Number.MAX_SAFE_INTEGER, | ||
credentials | ||
}) { | ||
totalTableItemsCount = await (0, _ddb.getTableItemsCount)(scanParams.TableName); | ||
totalTableItemsCount = await (0, _ddb.getTableItemsCount)(scanParams.TableName, credentials); | ||
const segments = (0, _lodash2.default)(concurrency); | ||
@@ -47,3 +48,4 @@ const blocker = new _blocker.Blocker(); | ||
chunkSize, | ||
blocker | ||
blocker, | ||
credentials | ||
}))).then(() => { | ||
@@ -61,3 +63,4 @@ // mark that there will be nothing else pushed into a stream | ||
chunkSize, | ||
blocker | ||
blocker, | ||
credentials | ||
}) { | ||
@@ -84,3 +87,3 @@ let segmentItems = []; | ||
ScannedCount | ||
} = await (0, _ddb.scan)(params); | ||
} = await (0, _ddb.scan)(params, credentials); | ||
ExclusiveStartKey = LastEvaluatedKey; | ||
@@ -87,0 +90,0 @@ totalScannedItemsCount += ScannedCount; |
import type { ScanCommandInput, ScanCommandOutput } from '@aws-sdk/lib-dynamodb'; | ||
import type { Credentials } from './ddb'; | ||
export declare function parallelScan(scanParams: ScanCommandInput, { concurrency }: { | ||
concurrency: number; | ||
}): Promise<ScanCommandOutput['Items']>; | ||
}, credentials?: Credentials): Promise<ScanCommandOutput['Items']>; |
@@ -18,4 +18,4 @@ "use strict"; | ||
concurrency | ||
}) { | ||
totalTableItemsCount = await (0, _ddb.getTableItemsCount)(scanParams.TableName); | ||
}, credentials) { | ||
totalTableItemsCount = await (0, _ddb.getTableItemsCount)(scanParams.TableName, credentials); | ||
const segments = (0, _lodash2.default)(concurrency); | ||
@@ -27,3 +27,4 @@ const totalItems = []; | ||
concurrency, | ||
segmentIndex | ||
segmentIndex, | ||
credentials | ||
}); | ||
@@ -38,3 +39,4 @@ totalItems.push(...segmentItems); | ||
concurrency, | ||
segmentIndex | ||
segmentIndex, | ||
credentials | ||
}) { | ||
@@ -60,3 +62,3 @@ const segmentItems = []; | ||
ScannedCount | ||
} = await (0, _ddb.scan)(params); | ||
} = await (0, _ddb.scan)(params, credentials); | ||
ExclusiveStartKey = LastEvaluatedKey; | ||
@@ -63,0 +65,0 @@ totalScannedItemsCount += ScannedCount; |
{ | ||
"name": "@shelf/dynamodb-parallel-scan", | ||
"version": "3.4.0", | ||
"version": "3.5.0", | ||
"description": "Scan large DynamoDB tables faster with parallelism", | ||
@@ -53,13 +53,13 @@ "keywords": [ | ||
"devDependencies": { | ||
"@aws-sdk/client-dynamodb": "3.259.0", | ||
"@aws-sdk/lib-dynamodb": "3.259.0", | ||
"@babel/cli": "7.20.7", | ||
"@babel/core": "7.20.12", | ||
"@shelf/babel-config": "1.2.0", | ||
"@shelf/eslint-config": "2.22.3", | ||
"@shelf/jest-dynamodb": "3.3.1", | ||
"@aws-sdk/client-dynamodb": "3.358.0", | ||
"@aws-sdk/lib-dynamodb": "3.358.0", | ||
"@babel/cli": "7.22.5", | ||
"@babel/core": "7.22.5", | ||
"@shelf/babel-config": "2.0.1", | ||
"@shelf/eslint-config": "2.29.3", | ||
"@shelf/jest-dynamodb": "3.4.1", | ||
"@shelf/prettier-config": "1.0.0", | ||
"@shelf/tsconfig": "0.0.9", | ||
"@types/debug": "4.1.7", | ||
"@types/jest": "29.4.0", | ||
"@types/jest": "29.5.1", | ||
"@types/lodash.chunk": "4.2.7", | ||
@@ -70,8 +70,8 @@ "@types/lodash.clonedeep": "4.5.7", | ||
"@types/p-map": "2.0.0", | ||
"eslint": "8.32.0", | ||
"eslint": "8.40.0", | ||
"husky": "8.0.3", | ||
"jest": "29.4.1", | ||
"lint-staged": "13.1.0", | ||
"prettier": "2.8.3", | ||
"typescript": "4.9.4" | ||
"jest": "29.5.0", | ||
"lint-staged": "13.2.2", | ||
"prettier": "2.8.8", | ||
"typescript": "4.9.5" | ||
}, | ||
@@ -78,0 +78,0 @@ "peerDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17990
331
1