Skip to content

Commit

Permalink
feat(parameters): add esmodule support (#1736)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamorosi authored Oct 12, 2023
1 parent c7a8511 commit d9a62ea
Show file tree
Hide file tree
Showing 52 changed files with 245 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module.exports = {
},
runner: 'groups',
preset: 'ts-jest',
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.ts?$': 'ts-jest',
},
Expand Down
97 changes: 58 additions & 39 deletions packages/parameters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
"test:e2e:nodejs18x": "RUNTIME=nodejs18x jest --group=e2e",
"test:e2e": "jest --group=e2e",
"watch": "jest --watch",
"build": "tsc --build --force",
"build:cjs": "tsc --build --force && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
"build:esm": "tsc --project tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json",
"build": "npm run build:esm & npm run build:cjs",
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
"lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern .",
"prebuild": "rimraf ./lib",
"prepack": "node ../../.github/scripts/release_patch_package_json.js ."
"prepack": "rimraf ./lib/*.tsbuildinfo && node ../../.github/scripts/release_patch_package_json.js ."
},
"lint-staged": {
"*.{js,ts}": "npm run lint-fix"
Expand All @@ -29,93 +31,110 @@
"license": "MIT-0",
"exports": {
".": {
"import": "./lib/index.js",
"require": "./lib/index.js"
"require": {
"types": "./lib/cjs/index.d.ts",
"default": "./lib/cjs/index.js"
},
"import": {
"types": "./lib/esm/index.d.ts",
"default": "./lib/esm/index.js"
}
},
"./base/types": {
"import": "./lib/types/BaseProvider.d.ts",
"require": "./lib/types/BaseProvider.d.ts"
"import": "./lib/esm/types/BaseProvider.d.ts",
"require": "./lib/cjs/types/BaseProvider.d.ts"
},
"./base": {
"import": "./lib/base/index.js",
"require": "./lib/base/index.js"
"import": "./lib/esm/base/index.js",
"require": "./lib/cjs/base/index.js"
},
"./ssm/types": {
"import": "./lib/types/SSMProvider.d.ts",
"require": "./lib/types/SSMProvider.d.ts"
"import": "./lib/esm/types/SSMProvider.d.ts",
"require": "./lib/cjs/types/SSMProvider.d.ts"
},
"./ssm": {
"import": "./lib/ssm/index.js",
"require": "./lib/ssm/index.js"
"import": "./lib/esm/ssm/index.js",
"require": "./lib/cjs/ssm/index.js"
},
"./secrets/types": {
"import": "./lib/types/SecretsProvider.d.ts",
"require": "./lib/types/SecretsProvider.d.ts"
"import": "./lib/esm/types/SecretsProvider.d.ts",
"require": "./lib/cjs/types/SecretsProvider.d.ts"
},
"./secrets": {
"import": "./lib/secrets/index.js",
"require": "./lib/secrets/index.js"
"import": "./lib/esm/secrets/index.js",
"require": "./lib/cjs/secrets/index.js"
},
"./dynamodb/types": {
"import": "./lib/types/AppConfigProvider.d.ts",
"require": "./lib/types/AppConfigProvider.d.ts"
"import": "./lib/esm/types/AppConfigProvider.d.ts",
"require": "./lib/cjs/types/AppConfigProvider.d.ts"
},
"./dynamodb": {
"import": "./lib/dynamodb/index.js",
"require": "./lib/dynamodb/index.js"
"import": "./lib/esm/dynamodb/index.js",
"require": "./lib/cjs/dynamodb/index.js"
},
"./appconfig/types": {
"import": "./lib/appconfig/index.js",
"require": "./lib/appconfig/index.js"
"import": "./lib/esm/appconfig/index.js",
"require": "./lib/cjs/appconfig/index.js"
},
"./appconfig": {
"import": "./lib/appconfig/index.js",
"require": "./lib/appconfig/index.js"
"import": "./lib/esm/appconfig/index.js",
"require": "./lib/cjs/appconfig/index.js"
},
"./errors": {
"import": "./lib/errors.js",
"require": "./lib/errors.js"
"import": "./lib/esm/errors.js",
"require": "./lib/cjs/errors.js"
}
},
"typesVersions": {
"*": {
"base/types": [
"lib/types/BaseProvider.d.ts"
"lib/cjs/types/BaseProvider.d.ts",
"lib/esm/types/BaseProvider.d.ts"
],
"base": [
"lib/base/index.d.ts"
"lib/cjs/base/index.d.ts",
"lib/esm/base/index.d.ts"
],
"ssm/types": [
"lib/types/SSMProvider.d.ts"
"lib/cjs/types/SSMProvider.d.ts",
"lib/esm/types/SSMProvider.d.ts"
],
"ssm": [
"lib/ssm/index.d.ts"
"lib/cjs/ssm/index.d.ts",
"lib/esm/ssm/index.d.ts"
],
"secrets/types": [
"lib/types/SecretsProvider.d.ts"
"lib/cjs/types/SecretsProvider.d.ts",
"lib/esm/types/SecretsProvider.d.ts"
],
"secrets": [
"lib/secrets/index.d.ts"
"lib/cjs/secrets/index.d.ts",
"lib/esm/secrets/index.d.ts"
],
"dynamodb/types": [
"./lib/types/DynamoDBProvider.d.ts"
"./lib/cjs/types/DynamoDBProvider.d.ts",
"./lib/esm/types/DynamoDBProvider.d.ts"
],
"dynamodb": [
"lib/dynamodb/index.d.ts"
"lib/cjs/dynamodb/index.d.ts",
"lib/esm/dynamodb/index.d.ts"
],
"appconfig/types": [
"./lib/types/AppConfigProvider.d.ts"
"./lib/cjs/types/AppConfigProvider.d.ts",
"./lib/esm/types/AppConfigProvider.d.ts"
],
"appconfig": [
"lib/appconfig/index.d.ts"
"lib/cjs/appconfig/index.d.ts",
"lib/esm/appconfig/index.d.ts"
],
"errors": [
"lib/errors.d.ts"
"lib/cjs/errors.d.ts",
"lib/esm/errors.d.ts"
]
}
},
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"types": "./lib/cjs/index.d.ts",
"main": "./lib/cjs/index.js",
"files": [
"lib"
],
Expand Down
6 changes: 3 additions & 3 deletions packages/parameters/src/appconfig/AppConfigProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseProvider, DEFAULT_PROVIDERS } from '../base';
import { BaseProvider } from '../base/BaseProvider.js';
import {
AppConfigDataClient,
StartConfigurationSessionCommand,
Expand All @@ -9,7 +9,7 @@ import type {
AppConfigProviderOptions,
AppConfigGetOptions,
AppConfigGetOutput,
} from '../types/AppConfigProvider';
} from '../types/AppConfigProvider.js';
import {
addUserAgentMiddleware,
isSdkClient,
Expand Down Expand Up @@ -360,4 +360,4 @@ class AppConfigProvider extends BaseProvider {
}
}

export { AppConfigProvider, DEFAULT_PROVIDERS };
export { AppConfigProvider };
5 changes: 3 additions & 2 deletions packages/parameters/src/appconfig/getAppConfig.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { AppConfigProvider, DEFAULT_PROVIDERS } from './AppConfigProvider';
import { AppConfigProvider } from './AppConfigProvider.js';
import { DEFAULT_PROVIDERS } from '../base/index.js';
import type {
AppConfigGetOutput,
GetAppConfigOptions,
} from '../types/AppConfigProvider';
} from '../types/AppConfigProvider.js';

/**
* ## Intro
Expand Down
4 changes: 2 additions & 2 deletions packages/parameters/src/appconfig/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './AppConfigProvider';
export * from './getAppConfig';
export { AppConfigProvider } from './AppConfigProvider.js';
export { getAppConfig } from './getAppConfig.js';
14 changes: 7 additions & 7 deletions packages/parameters/src/base/BaseProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import {
isRecord,
isString,
} from '@aws-lambda-powertools/commons';
import { GetOptions } from './GetOptions';
import { GetMultipleOptions } from './GetMultipleOptions';
import { ExpirableValue } from './ExpirableValue';
import { GetParameterError, TransformParameterError } from '../errors';
import { EnvironmentVariablesService } from '../config/EnvironmentVariablesService';
import { transformValue } from './transformValue';
import { GetOptions } from './GetOptions.js';
import { GetMultipleOptions } from './GetMultipleOptions.js';
import { ExpirableValue } from './ExpirableValue.js';
import { GetParameterError, TransformParameterError } from '../errors.js';
import { EnvironmentVariablesService } from '../config/EnvironmentVariablesService.js';
import { transformValue } from './transformValue.js';
import type {
BaseProviderInterface,
GetMultipleOptionsInterface,
GetOptionsInterface,
} from '../types/BaseProvider';
} from '../types/BaseProvider.js';

/**
* Base class for all providers.
Expand Down
2 changes: 1 addition & 1 deletion packages/parameters/src/base/DefaultProviders.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BaseProviderInterface } from '../types/BaseProvider';
import type { BaseProviderInterface } from '../types/BaseProvider.js';

// These providers are dinamycally intialized on first use of the helper functions
const DEFAULT_PROVIDERS: Record<string, BaseProviderInterface> = {};
Expand Down
2 changes: 1 addition & 1 deletion packages/parameters/src/base/ExpirableValue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ExpirableValueInterface } from '../types/BaseProvider';
import type { ExpirableValueInterface } from '../types/BaseProvider.js';

/**
* Class to represent a value that can expire.
Expand Down
6 changes: 3 additions & 3 deletions packages/parameters/src/base/GetMultipleOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GetOptions } from './GetOptions';
import { EnvironmentVariablesService } from '../config/EnvironmentVariablesService';
import type { GetMultipleOptionsInterface } from '../types/BaseProvider';
import { GetOptions } from './GetOptions.js';
import { EnvironmentVariablesService } from '../config/EnvironmentVariablesService.js';
import type { GetMultipleOptionsInterface } from '../types/BaseProvider.js';

/**
* Options for the `getMultiple` method.
Expand Down
6 changes: 3 additions & 3 deletions packages/parameters/src/base/GetOptions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { EnvironmentVariablesService } from '../config/EnvironmentVariablesService';
import { DEFAULT_MAX_AGE_SECS } from '../constants';
import { EnvironmentVariablesService } from '../config/EnvironmentVariablesService.js';
import { DEFAULT_MAX_AGE_SECS } from '../constants.js';
import type {
GetOptionsInterface,
TransformOptions,
} from '../types/BaseProvider';
} from '../types/BaseProvider.js';

/**
* Options for the `get` method.
Expand Down
8 changes: 4 additions & 4 deletions packages/parameters/src/base/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './DefaultProviders';
export * from './BaseProvider';
export * from './GetOptions';
export * from './GetMultipleOptions';
export { BaseProvider } from './BaseProvider.js';
export { DEFAULT_PROVIDERS, clearCaches } from './DefaultProviders.js';
export { GetOptions } from './GetOptions.js';
export { GetMultipleOptions } from './GetMultipleOptions.js';
9 changes: 6 additions & 3 deletions packages/parameters/src/base/transformValue.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { JSONValue } from '@aws-lambda-powertools/commons/types';
import { isString } from '@aws-lambda-powertools/commons';
import { fromBase64 } from '@aws-sdk/util-base64-node';
import { TRANSFORM_METHOD_BINARY, TRANSFORM_METHOD_JSON } from '../constants';
import { TransformParameterError } from '../errors';
import type { TransformOptions } from '../types/BaseProvider';
import {
TRANSFORM_METHOD_BINARY,
TRANSFORM_METHOD_JSON,
} from '../constants.js';
import { TransformParameterError } from '../errors.js';
import type { TransformOptions } from '../types/BaseProvider.js';

/**
* Utility function to transform a value.
Expand Down
4 changes: 2 additions & 2 deletions packages/parameters/src/config/EnvironmentVariablesService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConfigServiceInterface } from './ConfigServiceInterface';
import { DEFAULT_MAX_AGE_SECS } from '../constants';
import { ConfigServiceInterface } from '../types/ConfigServiceInterface.js';
import { DEFAULT_MAX_AGE_SECS } from '../constants.js';
import { EnvironmentVariablesService as CommonEnvironmentVariablesService } from '@aws-lambda-powertools/commons';

class EnvironmentVariablesService
Expand Down
4 changes: 2 additions & 2 deletions packages/parameters/src/dynamodb/DynamoDBProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseProvider } from '../base';
import { BaseProvider } from '../base/BaseProvider.js';
import {
DynamoDBClient,
GetItemCommand,
Expand All @@ -11,7 +11,7 @@ import type {
DynamoDBGetMultipleOptions,
DynamoDBGetOutput,
DynamoDBGetMultipleOutput,
} from '../types/DynamoDBProvider';
} from '../types/DynamoDBProvider.js';
import type {
GetItemCommandInput,
QueryCommandInput,
Expand Down
2 changes: 1 addition & 1 deletion packages/parameters/src/dynamodb/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './DynamoDBProvider';
export { DynamoDBProvider } from './DynamoDBProvider.js';
4 changes: 2 additions & 2 deletions packages/parameters/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './errors';
export * from './constants';
export * from './errors.js';
export * from './constants.js';
4 changes: 2 additions & 2 deletions packages/parameters/src/secrets/SecretsProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseProvider } from '../base';
import { BaseProvider } from '../base/BaseProvider.js';
import {
SecretsManagerClient,
GetSecretValueCommand,
Expand All @@ -8,7 +8,7 @@ import type {
SecretsProviderOptions,
SecretsGetOptions,
SecretsGetOutput,
} from '../types/SecretsProvider';
} from '../types/SecretsProvider.js';
import {
addUserAgentMiddleware,
isSdkClient,
Expand Down
6 changes: 3 additions & 3 deletions packages/parameters/src/secrets/getSecret.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DEFAULT_PROVIDERS } from '../base';
import { SecretsProvider } from './SecretsProvider';
import { DEFAULT_PROVIDERS } from '../base/DefaultProviders.js';
import { SecretsProvider } from './SecretsProvider.js';
import type {
SecretsGetOptions,
SecretsGetOutput,
} from '../types/SecretsProvider';
} from '../types/SecretsProvider.js';

/**
* ## Intro
Expand Down
4 changes: 2 additions & 2 deletions packages/parameters/src/secrets/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './SecretsProvider';
export * from './getSecret';
export { SecretsProvider } from './SecretsProvider.js';
export { getSecret } from './getSecret.js';
12 changes: 6 additions & 6 deletions packages/parameters/src/ssm/SSMProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseProvider, DEFAULT_PROVIDERS } from '../base';
import { transformValue } from '../base/transformValue';
import { GetParameterError } from '../errors';
import { DEFAULT_MAX_AGE_SECS } from '../constants';
import { BaseProvider } from '../base/BaseProvider.js';
import { transformValue } from '../base/transformValue.js';
import { GetParameterError } from '../errors.js';
import { DEFAULT_MAX_AGE_SECS } from '../constants.js';
import {
SSMClient,
GetParameterCommand,
Expand All @@ -25,7 +25,7 @@ import type {
SSMGetParametersByNameOptions,
SSMSplitBatchAndDecryptParametersOutputType,
SSMGetParametersByNameFromCacheOutputType,
} from '../types/SSMProvider';
} from '../types/SSMProvider.js';
import type { PaginationConfiguration } from '@aws-sdk/types';
import {
addUserAgentMiddleware,
Expand Down Expand Up @@ -915,4 +915,4 @@ class SSMProvider extends BaseProvider {
}
}

export { SSMProvider, DEFAULT_PROVIDERS };
export { SSMProvider };
5 changes: 3 additions & 2 deletions packages/parameters/src/ssm/getParameter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SSMProvider, DEFAULT_PROVIDERS } from './SSMProvider';
import type { SSMGetOptions, SSMGetOutput } from '../types/SSMProvider';
import { DEFAULT_PROVIDERS } from '../base/DefaultProviders.js';
import { SSMProvider } from './SSMProvider.js';
import type { SSMGetOptions, SSMGetOutput } from '../types/SSMProvider.js';

/**
* ## Intro
Expand Down
Loading

0 comments on commit d9a62ea

Please sign in to comment.