Skip to content

Commit a263a97

Browse files
committed
feat: switch to esm, pnpm, major deps upgrade
1 parent 8150c97 commit a263a97

17 files changed

+251
-126
lines changed

.circleci/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ commands:
1313
install_deps:
1414
steps:
1515
- node/install-packages:
16-
pkg-manager: yarn
16+
pkg-manager: pnpm
1717
cache-version: v2-all
1818
cache-only-lockfile: true
1919
app-dir: ~/repo
20-
override-ci-command: yarn install --pure-lockfile --no-progress
20+
override-ci-command: pnpm install --no-frozen-lockfile --reporter=silent
2121

2222
jobs:
2323
build:
@@ -31,6 +31,6 @@ jobs:
3131
steps:
3232
- checkout
3333
- install_deps
34-
- run: yarn test
35-
- run: yarn type-check
36-
- run: yarn lint:ci
34+
- run: pnpm test
35+
- run: pnpm type-check
36+
- run: pnpm lint:ci

.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

eslint.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import rules from '@shelf/eslint-config/typescript.js';
2+
3+
export default [
4+
...rules,
5+
{files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx', '**/*.json']},
6+
{
7+
ignores: ['**/node_modules/', '**/coverage/', '**/lib/', 'renovate.json', 'tsconfig.json'],
8+
},
9+
];

jest-dynamodb-config.cjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* eslint-disable @typescript-eslint/no-require-imports */
2+
const fs = require('fs');
3+
const path = require('path');
4+
const {pathToFileURL} = require('url');
5+
6+
module.exports = async () => {
7+
const cwd = process.cwd();
8+
const mjsPath = path.resolve(cwd, 'jest-dynamodb-config.mjs');
9+
10+
if (fs.existsSync(mjsPath)) {
11+
const mod = await import(pathToFileURL(mjsPath).href);
12+
13+
return mod.default || mod;
14+
}
15+
16+
// Fallback to built-in default if .mjs is absent
17+
return {
18+
tables: [
19+
{
20+
TableName: `files`,
21+
KeySchema: [{AttributeName: 'id', KeyType: 'HASH'}],
22+
AttributeDefinitions: [{AttributeName: 'id', AttributeType: 'S'}],
23+
ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1},
24+
},
25+
],
26+
};
27+
};

jest-dynamodb-config.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

jest.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

jest.config.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @type {import('jest').Config}
3+
*/
4+
const config = {
5+
preset: '@shelf/jest-dynamodb',
6+
transform: {
7+
'^.+\\.(t|j)sx?$': ['@swc/jest'],
8+
},
9+
moduleNameMapper: {
10+
'^(\\.{1,2}/.*)\\.js$': '$1',
11+
},
12+
resetMocks: true,
13+
};
14+
15+
export default config;

package.json

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,63 +14,66 @@
1414
"email": "[email protected]",
1515
"url": "shelf.io"
1616
},
17+
"type": "module",
1718
"main": "lib/index.js",
1819
"types": "lib/index.d.ts",
20+
"exports": {
21+
".": {
22+
"types": "./lib/index.d.ts",
23+
"import": "./lib/index.js"
24+
}
25+
},
1926
"files": [
2027
"lib"
2128
],
2229
"scripts": {
23-
"build": "rm -rf lib/ && yarn build:types && babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts'",
30+
"build": "rm -rf lib/ && tsc -p tsconfig.json",
2431
"build:types": "tsc --emitDeclarationOnly --declaration --isolatedModules false --declarationDir lib",
25-
"coverage": "jest --coverage",
26-
"lint": "eslint . --ext .js,.ts,.json --fix --quiet",
27-
"lint:ci": "eslint . --ext .js,.ts,.json --quiet",
28-
"prepack": "yarn build",
29-
"test": "export ENVIRONMENT=local && jest src --runInBand --forceExit",
32+
"coverage": "export JEST_DYNAMODB_CONFIG=$(pwd)/jest-dynamodb-config.cjs && jest --coverage",
33+
"lint": "pnpm lint:ci --fix",
34+
"lint:ci": "eslint .",
35+
"prepack": "pnpm build",
36+
"test": "export ENVIRONMENT=local JEST_DYNAMODB_CONFIG=$(pwd)/jest-dynamodb-config.cjs && jest src --runInBand --forceExit",
3037
"type-check": "tsc --noEmit",
31-
"type-check:watch": "npm run type-check -- --watch"
38+
"type-check:watch": "pnpm run type-check -- --watch"
3239
},
3340
"lint-staged": {
34-
"*.{html,json,md,yml}": [
35-
"prettier --write --ignore-path=./.eslintignore"
41+
"*.{html,md,yml}": [
42+
"prettier --write"
3643
],
37-
"*.{ts,js}": [
44+
"*.{js,ts,json}": [
3845
"eslint --fix"
3946
]
4047
},
41-
"babel": {
42-
"extends": "@shelf/babel-config/backend"
43-
},
4448
"prettier": "@shelf/prettier-config",
4549
"dependencies": {
46-
"debug": "4.3.4",
50+
"debug": "4.4.1",
4751
"lodash.chunk": "4.2.0",
48-
"lodash.clonedeep": "4.5.0",
49-
"lodash.times": "4.3.2",
50-
"p-map": "4.0.0"
52+
53+
54+
"p-map": "7.0.3"
5155
},
5256
"devDependencies": {
53-
"@aws-sdk/client-dynamodb": "3.538.0",
54-
"@aws-sdk/lib-dynamodb": "3.535.0",
55-
"@babel/cli": "7.27.2",
56-
"@babel/core": "7.27.4",
57-
"@shelf/babel-config": "2.0.1",
58-
"@shelf/eslint-config": "2.29.3",
59-
"@shelf/jest-dynamodb": "3.4.1",
57+
"@aws-sdk/client-dynamodb": "3.879.0",
58+
"@aws-sdk/lib-dynamodb": "3.879.0",
59+
"@swc/core": "1.13.5",
60+
"@swc/jest": "0.2.39",
61+
"@shelf/eslint-config": "5.2.3",
62+
"@shelf/jest-dynamodb": "3.5.0",
6063
"@shelf/prettier-config": "1.0.0",
61-
"@shelf/tsconfig": "0.0.9",
64+
"@shelf/tsconfig": "0.1.0",
6265
"@types/debug": "4.1.12",
63-
"@types/jest": "29.5.14",
66+
"@types/jest": "30.0.0",
6467
"@types/lodash.chunk": "4.2.9",
65-
"@types/lodash.clonedeep": "4.5.9",
66-
"@types/lodash.times": "4.3.9",
67-
"@types/node": "22",
68-
"eslint": "8.57.1",
69-
"husky": "8.0.3",
70-
"jest": "29.7.0",
71-
"lint-staged": "13.3.0",
72-
"prettier": "2.8.8",
73-
"typescript": "5.8.3"
68+
69+
70+
"@types/node": "24.3.0",
71+
"eslint": "9.34.0",
72+
"husky": "9.1.7",
73+
"jest": "30.1.2",
74+
"lint-staged": "16.1.6",
75+
"prettier": "3.6.2",
76+
"typescript": "5.9.2"
7477
},
7578
"peerDependencies": {
7679
"@aws-sdk/client-dynamodb": "3.x.x",

readme.md

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
## Install
88

99
```
10-
$ yarn add @shelf/dynamodb-parallel-scan
10+
$ pnpm add @shelf/dynamodb-parallel-scan
1111
```
1212

13-
This library has 2 peer dependencies:
13+
This library targets ESM and AWS SDK v3. Install alongside peer deps:
1414

15-
- `@aws-sdk/client-dynamodb`
16-
- `@aws-sdk/lib-dynamodb`
15+
```
16+
pnpm add @shelf/dynamodb-parallel-scan @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb
17+
```
1718

18-
Make sure to install them alongside this library.
19+
Requires Node.js 22+.
1920

2021
## Why this is better than a regular scan
2122

@@ -31,50 +32,54 @@ It allows receiving chunks of scanned items, wait until you process them, and th
3132

3233
### Fetch everything at once
3334

34-
```js
35-
const {parallelScan} = require('@shelf/dynamodb-parallel-scan');
36-
37-
(async () => {
38-
const items = await parallelScan(
39-
{
40-
TableName: 'files',
41-
FilterExpression: 'attribute_exists(#fileSize)',
42-
ExpressionAttributeNames: {
43-
'#fileSize': 'fileSize',
44-
},
45-
ProjectionExpression: 'fileSize',
35+
```ts
36+
import {parallelScan} from '@shelf/dynamodb-parallel-scan';
37+
38+
const items = await parallelScan(
39+
{
40+
TableName: 'files',
41+
FilterExpression: 'attribute_exists(#fileSize)',
42+
ExpressionAttributeNames: {
43+
'#fileSize': 'fileSize',
4644
},
47-
{concurrency: 1000}
48-
);
45+
ProjectionExpression: 'fileSize',
46+
},
47+
{concurrency: 1000}
48+
);
4949

50-
console.log(items);
51-
})();
50+
console.log(items);
5251
```
5352

5453
### Use as async generator (or streams)
5554

5655
Note: `highWaterMark` determines items count threshold, so Parallel Scan can fetch `concurrency` \* 1MB more data even after highWaterMark was reached.
5756

58-
```js
59-
const {parallelScanAsStream} = require('@shelf/dynamodb-parallel-scan');
60-
61-
(async () => {
62-
const stream = await parallelScanAsStream(
63-
{
64-
TableName: 'files',
65-
FilterExpression: 'attribute_exists(#fileSize)',
66-
ExpressionAttributeNames: {
67-
'#fileSize': 'fileSize',
68-
},
69-
ProjectionExpression: 'fileSize',
57+
```ts
58+
import {parallelScanAsStream} from '@shelf/dynamodb-parallel-scan';
59+
60+
const stream = await parallelScanAsStream(
61+
{
62+
TableName: 'files',
63+
FilterExpression: 'attribute_exists(#fileSize)',
64+
ExpressionAttributeNames: {
65+
'#fileSize': 'fileSize',
7066
},
71-
{concurrency: 1000, chunkSize: 10000, highWaterMark: 10000}
72-
);
67+
ProjectionExpression: 'fileSize',
68+
},
69+
{concurrency: 1000, chunkSize: 10000, highWaterMark: 10000}
70+
);
71+
72+
for await (const items of stream) {
73+
console.log(items); // 10k items here
74+
}
75+
```
76+
77+
### CommonJS Consumers
7378

74-
for await (const items of stream) {
75-
console.log(items); // 10k items here
76-
}
77-
})();
79+
This package is ESM-only. In CommonJS, use dynamic import:
80+
81+
```js
82+
const {parallelScan, parallelScanAsStream} = await import('@shelf/dynamodb-parallel-scan');
7883
```
7984

8085
## Read
@@ -88,8 +93,8 @@ const {parallelScanAsStream} = require('@shelf/dynamodb-parallel-scan');
8893

8994
```sh
9095
$ git checkout master
91-
$ yarn version
92-
$ yarn publish
96+
$ pnpm version
97+
$ pnpm publish
9398
$ git push origin master --tags
9499
```
95100

src/blocker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export class Blocker {
55

66
constructor() {
77
this._promise = Promise.resolve();
8-
this._promiseResolver = () => {}; // eslint-disable-line @typescript-eslint/no-empty-function
8+
this._promiseResolver = () => {};
99
this._isBlocked = false;
1010
}
1111

0 commit comments

Comments
 (0)