Skip to content

Commit 5473333

Browse files
committed
feat(idempotency): add esmodule support (#1743)
* feat(idempotency): add esmodule support
1 parent 8276cee commit 5473333

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+219
-148
lines changed

packages/idempotency/jest.config.js renamed to packages/idempotency/jest.config.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ module.exports = {
55
},
66
runner: 'groups',
77
preset: 'ts-jest',
8+
moduleNameMapper: {
9+
'^(\\.{1,2}/.*)\\.js$': '$1',
10+
},
811
transform: {
912
'^.+\\.ts?$': 'ts-jest',
1013
},

packages/idempotency/package.json

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,57 +19,78 @@
1919
"test:e2e:nodejs20x": "RUNTIME=nodejs20x jest --group=e2e",
2020
"test:e2e": "jest --group=e2e",
2121
"watch": "jest --watch",
22-
"build": "tsc --build --force",
22+
"build:cjs": "tsc --build --force && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
23+
"build:esm": "tsc --project tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json",
24+
"build": "npm run build:esm & npm run build:cjs",
2325
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
2426
"lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern .",
2527
"prebuild": "rimraf ./lib",
26-
"prepack": "node ../../.github/scripts/release_patch_package_json.js ."
28+
"prepack": "rimraf ./lib/*.tsbuildinfo && node ../../.github/scripts/release_patch_package_json.js ."
2729
},
2830
"lint-staged": {
2931
"*.{js,ts}": "npm run lint-fix"
3032
},
3133
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/packages/idempotency#readme",
3234
"license": "MIT-0",
35+
"type": "module",
3336
"exports": {
3437
".": {
35-
"import": "./lib/index.js",
36-
"require": "./lib/index.js"
38+
"require": {
39+
"types": "./lib/cjs/index.d.ts",
40+
"default": "./lib/cjs/index.js"
41+
},
42+
"import": {
43+
"types": "./lib/esm/index.d.ts",
44+
"default": "./lib/esm/index.js"
45+
}
3746
},
3847
"./persistence": {
39-
"import": "./lib/persistence/index.js",
40-
"require": "./lib/persistence/index.js"
48+
"import": "./lib/esm/persistence/index.js",
49+
"require": "./lib/cjs/persistence/index.js"
4150
},
4251
"./dynamodb": {
43-
"import": "./lib/persistence/DynamoDBPersistenceLayer.js",
44-
"require": "./lib/persistence/DynamoDBPersistenceLayer.js"
52+
"import": "./lib/esm/persistence/DynamoDBPersistenceLayer.js",
53+
"require": "./lib/cjs/persistence/DynamoDBPersistenceLayer.js"
54+
},
55+
"./dynamodb/types": {
56+
"import": "./lib/esm/types/DynamoDBPersistence.js",
57+
"require": "./lib/cjs/types/DynamoDBPersistence.js"
4558
},
4659
"./middleware": {
47-
"import": "./lib/middleware/index.js",
48-
"require": "./lib/middleware/index.js"
60+
"import": "./lib/esm/middleware/makeHandlerIdempotent.js",
61+
"require": "./lib/cjs/middleware/makeHandlerIdempotent.js"
4962
},
5063
"./types": {
51-
"import": "./lib/types/index.d.ts",
52-
"require": "./lib/types/index.d.ts"
64+
"import": "./lib/esm/types/index.d.ts",
65+
"require": "./lib/esm/types/index.d.ts"
5366
}
5467
},
5568
"typesVersions": {
5669
"*": {
5770
"persistence": [
58-
"lib/persistence/index.d.ts"
71+
"lib/esm/persistence/index.d.ts",
72+
"lib/cjs/persistence/index.d.ts"
5973
],
6074
"dynamodb": [
61-
"lib/persistence/DynamoDBPersistenceLayer.d.ts"
75+
"lib/esm/persistence/DynamoDBPersistenceLayer.d.ts",
76+
"lib/cjs/persistence/DynamoDBPersistenceLayer.d.ts"
77+
],
78+
"dynamodb/types": [
79+
"lib/esm/types/DynamoDBPersistence.d.ts",
80+
"lib/cjs/types/DynamoDBPersistence.d.ts"
6281
],
6382
"middleware": [
64-
"lib/middleware/index.d.ts"
83+
"lib/esm/middleware/makeHandlerIdempotent.d.ts",
84+
"lib/cjs/middleware/makeHandlerIdempotent.d.ts"
6585
],
6686
"types": [
67-
"lib/types/index.d.ts"
87+
"lib/esm/types/index.d.ts",
88+
"lib/cjs/types/index.d.ts"
6889
]
6990
}
7091
},
71-
"main": "./lib/index.js",
72-
"types": "./lib/index.d.ts",
92+
"types": "./lib/cjs/index.d.ts",
93+
"main": "./lib/cjs/index.js",
7394
"files": [
7495
"lib"
7596
],

packages/idempotency/src/IdempotencyConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { EnvironmentVariablesService } from './config';
1+
import { EnvironmentVariablesService } from './config/EnvironmentVariablesService.js';
22
import type { Context } from 'aws-lambda';
3-
import type { IdempotencyConfigOptions } from './types';
3+
import type { IdempotencyConfigOptions } from './types/IdempotencyOptions.js';
44

55
/**
66
* Configuration for the idempotency feature.

packages/idempotency/src/IdempotencyHandler.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@ import type {
22
JSONValue,
33
MiddyLikeRequest,
44
} from '@aws-lambda-powertools/commons/types';
5-
import type { AnyFunction, IdempotencyHandlerOptions } from './types';
5+
import type {
6+
AnyFunction,
7+
IdempotencyHandlerOptions,
8+
} from './types/IdempotencyOptions.js';
69
import {
710
IdempotencyAlreadyInProgressError,
811
IdempotencyInconsistentStateError,
912
IdempotencyItemAlreadyExistsError,
1013
IdempotencyPersistenceLayerError,
11-
} from './errors';
12-
import { BasePersistenceLayer, IdempotencyRecord } from './persistence';
13-
import { IdempotencyConfig } from './IdempotencyConfig';
14-
import { MAX_RETRIES, IdempotencyRecordStatus } from './constants';
14+
} from './errors.js';
15+
import { BasePersistenceLayer } from './persistence/BasePersistenceLayer.js';
16+
import { IdempotencyRecord } from './persistence/IdempotencyRecord.js';
17+
import { IdempotencyConfig } from './IdempotencyConfig.js';
18+
import { MAX_RETRIES, IdempotencyRecordStatus } from './constants.js';
1519
import { search } from 'jmespath';
1620

1721
/**

packages/idempotency/src/config/EnvironmentVariablesService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConfigServiceInterface } from './ConfigServiceInterface';
1+
import type { ConfigServiceInterface } from '../types/ConfigServiceInterface.js';
22
import { EnvironmentVariablesService as CommonEnvironmentVariablesService } from '@aws-lambda-powertools/commons';
33

44
/**

packages/idempotency/src/config/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/idempotency/src/idempotencyDecorator.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { AnyFunction, ItempotentFunctionOptions } from './types';
2-
import { makeIdempotent } from './makeIdempotent';
1+
import {
2+
AnyFunction,
3+
ItempotentFunctionOptions,
4+
} from './types/IdempotencyOptions.js';
5+
import { makeIdempotent } from './makeIdempotent.js';
36

47
/**
58
* Use this decorator to make your lambda handler itempotent.

packages/idempotency/src/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
export * from './errors';
2-
export * from './IdempotencyConfig';
3-
export * from './makeIdempotent';
4-
export * from './idempotencyDecorator';
5-
export { IdempotencyRecordStatus } from './constants';
1+
export {
2+
IdempotencyItemAlreadyExistsError,
3+
IdempotencyItemNotFoundError,
4+
IdempotencyAlreadyInProgressError,
5+
IdempotencyInvalidStatusError,
6+
IdempotencyValidationError,
7+
IdempotencyInconsistentStateError,
8+
IdempotencyPersistenceLayerError,
9+
IdempotencyKeyError,
10+
} from './errors.js';
11+
export { IdempotencyConfig } from './IdempotencyConfig.js';
12+
export { makeIdempotent } from './makeIdempotent.js';
13+
export { idempotent } from './idempotencyDecorator.js';
14+
export { IdempotencyRecordStatus } from './constants.js';

packages/idempotency/src/makeIdempotent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import type {
33
AnyFunction,
44
ItempotentFunctionOptions,
55
IdempotencyLambdaHandlerOptions,
6-
} from './types';
7-
import { IdempotencyHandler } from './IdempotencyHandler';
8-
import { IdempotencyConfig } from './IdempotencyConfig';
6+
} from './types/IdempotencyOptions.js';
7+
import { IdempotencyHandler } from './IdempotencyHandler.js';
8+
import { IdempotencyConfig } from './IdempotencyConfig.js';
99

1010
const isContext = (arg: unknown): arg is Context => {
1111
return (

packages/idempotency/src/middleware/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)