Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 49 additions & 6 deletions ops/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ printf "╭───────╮\n"
printf "│ \e[0;36mBuild\e[0;36m │\n"
printf "╰───────╯\e[0m\n"

printf "\e[0;36m(Installing)\e[0m\n"
pnpm i
# printf "\e[0;36m(Installing)\e[0m\n"
# pnpm i

printf "\e[0;36m(Linting)\e[0m\n"
pnpm run lint
# printf "\e[0;36m(Linting)\e[0m\n"
# pnpm run lint

printf "\e[0;36m(Testing)\e[0m\n"
pnpm run test
# printf "\e[0;36m(Testing)\e[0m\n"
# pnpm run test

printf "\e[0;36m(Bundling)\e[0m\n"
pnpm run build
Expand All @@ -31,4 +31,47 @@ if [ ! -f ./dist/index.mjs ]; then
exit 1
fi

printf "\e[0;36m(Generating types)\e[0m\n"

rm -rf ./dts-out

npx -y -p typescript tsc \
--allowJs --checkJs false --strict false \
--module nodenext --target ES2024 \
--skipLibCheck --declaration --emitDeclarationOnly \
--declarationDir ./dts-out \
src/index.js

echo '{
"compilerOptions": {
"target": "ES2024",
"typeRoots": []
}
}' > ./dts-out/tsconfig.json

echo '{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"projectFolder": ".",
"mainEntryPointFilePath": "<projectFolder>/dts-out/index.d.ts",
"compiler": {
"tsconfigFilePath": "<projectFolder>/dts-out/tsconfig.json"
},
"apiReport": { "enabled": false },
"docModel": { "enabled": false },
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "<projectFolder>/dist/index.d.ts"
},
"tsdocMetadata": { "enabled": false }
}' > ./api-extractor.json

npx -y @microsoft/api-extractor run --config ./api-extractor.json --local

rm -f ./api-extractor.json

# npx -y dts-bundle-generator \
# --out-file dist/index.d.ts \
# --project ./dts-out/tsconfig.json \
# ./dts-out/index.d.ts

printf "\e[0;36m(Done)\e[0m\n"
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"./dist"
],
"type": "module",
"types": "./dist/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
},
Expand All @@ -36,7 +38,7 @@
],
"scripts": {
"build": "webpack --stats errors-only",
"test": "node --experimental-test-module-mocks --test",
"test": "node --experimental-test-module-mocks --test --test-reporter=spec",
"lint:fix": "eslint --fix",
"lint": "eslint"
},
Expand Down
20 changes: 18 additions & 2 deletions src/aws/dynamo/get.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { GetCommand } from '@aws-sdk/lib-dynamodb';

/**
* @typedef {import("@aws-sdk/lib-dynamodb").GetCommandInput} GetCommandInput
*/

const parseArgs = args => {
// native args mode
if ( args[0] instanceof Object ) {
Expand All @@ -12,7 +16,19 @@ const parseArgs = args => {
};
};

export const get = async ( client, ...args ) => {
const response = await client.send( new GetCommand( parseArgs( args ) ) );
/**
* Parses the arguments for the DynamoDB GetCommand
*
* @param {GetCommandInput|string} tableNameOrNativeArgs - The table name or the native GetCommand input object
* @param {Object} [args] - The key object if the first argument is a table name
* @returns {Object}
*/
const get = async ( ...args ) => {
const [ client, ...rest ] = args;
const response = await client.send( new GetCommand( parseArgs( rest ) ) );
return response.Item;
};

export {
get
}
4 changes: 2 additions & 2 deletions src/lambda_api/lambda_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class LambdaApi {
* Creates a new Lambda Api
*
* @param {Object} args
* @param {Object} [args.headers={}] Any headers to be included in all responses. Defaults to none.
* @param {Object<string, string|number>} [args.headers={}] Any headers to be included in all responses. Defaults to none.
* @param {'camelcase'|'snakecase'} [args.transformRequest=false]
* Transform the request query string, parameters and body to camelCase or snake_case.
* Defaults to no transformation.
Expand Down Expand Up @@ -77,7 +77,7 @@ export class LambdaApi {
* Register an automatic error code response for given error class (constructor name)
*
* @param {Object} args
* @param {class} args.errorType The error class
* @param {Function} args.errorType The error class
* @param {number} args.code The HTTP status code to return
* @param {string} [args.message=null] Optional message to return for the status code, if not present will default to Error.message
*/
Expand Down
29 changes: 19 additions & 10 deletions src/utils/retry_on_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,25 @@ const execWithRetry = async ( closure, { limit, delay, retryHook, execCount = 0
};

/**
*
* @param {Function} closure A self contained function that will be invoked
* Retry a closure on error
*
* @template {any[]} Args
* @template T
*
* @param {{(...args: Args) => Promise<T> | T}} closure A self contained function that will be invoked
* @param {Object} config
* @param {Number} config.limit The max number of retries
* @param {Number} config.delay The delay between each retry (it will be raised to the power of the number of retries, so it is exponential back-off)
* @param {Function} config.retryHook A function to be called every time a retry is needed.
* If this functions returns true, the retry flow continues until limit
* If this functions returns false, the retry flow is aborted, returning false
* If this functions throws an error, the retry flow is aborted with that error
* @returns {Any} The closure result
* @param {Number} [config.limit=0] The max number of retries
* @param {Number} [config.delay=0] The delay between each retry (it will be raised to the power of the number of retries, so it is exponential back-off)
* @param {{(error: Error, execCount: number) => Promise<boolean> | boolean}} [config.retryHook=null]
* A function to be called every time a retry is needed.
* - If this functions returns true, the retry flow continues until limit
* - If this functions returns false, the retry flow is aborted, returning false
* - If this functions throws an error, the retry flow is aborted with that error
* @returns {Promise<T>} The closure result
*/
export const retryOnError = async ( closure, { limit = 0, delay = 0, retryHook = null } = {} ) =>
const retryOnError = async ( closure, { limit = 0, delay = 0, retryHook = null } = {} ) =>
execWithRetry( closure, { limit, delay, retryHook } );

export {
retryOnError
};
7 changes: 7 additions & 0 deletions src/utils/sleep.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
/**
* Sleep for a specified amount of time
*
* @param {number} t The time to sleep in milliseconds
* @returns {Promise<void>} A promise that resolves after the specified time
* @type {(t: number) => Promise<void>}
*/
export const sleep = t => new Promise( r => setTimeout( r, t ) );
Loading