{"id":16899019,"url":"https://github.com/chrisguttandin/dynamo-converters","last_synced_at":"2025-07-27T21:33:54.978Z","repository":{"id":14294213,"uuid":"17002633","full_name":"chrisguttandin/dynamo-converters","owner":"chrisguttandin","description":"A collection of converter functions to get good old JavaScript key/value objects into a DynamoDB friendly schema and back again.","archived":false,"fork":false,"pushed_at":"2025-07-09T15:19:27.000Z","size":11541,"stargazers_count":24,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-09T16:36:31.522Z","etag":null,"topics":["aws","dynamodb"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chrisguttandin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-02-19T23:17:58.000Z","updated_at":"2025-07-09T15:19:30.000Z","dependencies_parsed_at":"2023-02-16T21:10:28.741Z","dependency_job_id":"b06b9acf-dd65-4b2f-9ed2-9f694423e9fe","html_url":"https://github.com/chrisguttandin/dynamo-converters","commit_stats":{"total_commits":1364,"total_committers":4,"mean_commits":341.0,"dds":0.02639296187683282,"last_synced_commit":"e72429ec633b81d2db03c6b1a7625dde853c8e99"},"previous_names":[],"tags_count":68,"template":false,"template_full_name":null,"purl":"pkg:github/chrisguttandin/dynamo-converters","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisguttandin%2Fdynamo-converters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisguttandin%2Fdynamo-converters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisguttandin%2Fdynamo-converters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisguttandin%2Fdynamo-converters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisguttandin","download_url":"https://codeload.github.com/chrisguttandin/dynamo-converters/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisguttandin%2Fdynamo-converters/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267427477,"owners_count":24085562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","dynamodb"],"created_at":"2024-10-13T17:46:51.837Z","updated_at":"2025-07-27T21:33:54.938Z","avatar_url":"https://github.com/chrisguttandin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dynamo-converters\n\n**A collection of converter functions to get good old JavaScript key/value objects into a DynamoDB friendly schema and back again.**\n\n[![version](https://img.shields.io/npm/v/dynamo-converters.svg?style=flat-square)](https://www.npmjs.com/package/dynamo-converters)\n\n## Functionality\n\nAmazon's official [aws-sdk for JavaScript](https://docs.aws.amazon.com/sdk-for-javascript/) uses a relatively verbose data structure to [put](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#putItem-property), [update](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#updateItem-property) or [delete](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#deleteItem-property) items stored inside a DynamoDB table. This is necessary to cover all possible use cases. But most of the time a much simpler data structure does the job as well. This little package is made for those cases.\n\nIf you think the official SDK is too verbose but this package does not cover all your needs you\nmight want to take a look at [dynamodb-data-types](https://github.com/kayomarz/dynamodb-data-types)\nby [kayomarz](https://github.com/kayomarz).\n\n## Getting Started\n\nThis package is available on [npm](https://www.npmjs.org/package/dynamo-converters) and can be\ninstalled as usual:\n\n```shell\nnpm install dynamo-converters\n```\n\nYou can then use `dynamo-converters` by importing it:\n\n```js\nimport { addValue, createDataToItem, dataToItem, deltaToUpdateParams, itemToData, withDateSerialization } from 'dynamo-converters';\n```\n\n## Documentation\n\n`dynamo-converters` does provide the following functions:\n\n### item : dataToItem( data )\n\nThis function takes a plain JavaScript object as input and returns a structured item which can then\nbe used with the official SDK.\n\n```js\nconst data = {\n    object: {\n        nothing: undefined,\n        number: 2,\n        string: 'lorem ipsum'\n    }\n};\n\nconsole.log(dataToItem(data));\n\n// {\n//     object: {\n//         M: {\n//             number: { N: '2' },\n//             string: { S: 'lorem ipsum' }\n//         }\n//     }\n// }\n```\n\nPlease have a look at the\n[unit tests](https://github.com/chrisguttandin/dynamo-converters/blob/master/test/unit/module.js#L4-L59) for\nmore examples.\n\nThis function is similar to the [`marshall()` function](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_util_dynamodb.html#marshall-1) provided by the [@aws-sdk/util-dynamodb package](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_util_dynamodb.html#aws-sdkutil-dynamodb) but it preserves the property types.\n\n```js\ndataToItem({ a: 0 });\n// {\n//     a: {\n//         N: string;\n//     };\n// }\n\nmarshall({ a: 0 });\n// {\n//     [key: string]: any;\n// }\n```\n\n### dataToItem : createDataToItem( transformSingleValue )\n\nBy default `dataToItem()` only handles values which directly map to the types supported by DynamoDB. If you need to transform certain values before converting them into an item you can create a custom version of `dataToItem()` by using the `createDataToItem()` factory method. It expects to be called with a function that transforms a single value.\n\nHere is an example which turns a `Date` into a `string`.\n\n```js\nimport { createDataToItem } from 'dynamo-converters';\n\nconst dataToItem = createDataToItem((value) =\u003e (value instanceof Date ? value.toJSON() : value));\n```\n\nA function for doing the exact same thing is also provided by `dynamo-converters`. You can therefore simply import it instead.\n\n```js\nimport { createDataToItem, withDateSerialization } from 'dynamo-converters';\n\nconst dataToItem = createDataToItem(withDateSerialization);\n```\n\n### updateParams : deltaToUpdateParams( delta )\n\nThis function takes a plain JavaScript object as input and returns all necessary update params which\ncan then be used with the official SDK.\n\n`deltaToUpdateParams()` also takes care of\n[reserved words](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html)\nand populates the `expressionAttributeNames` property of the returned object if needed. If the delta\ncontains no reserved word this property will be missing.\n\n```js\nconst delta = {\n    nothing: undefined,\n    object: {\n        number: 2,\n        string: 'lorem ipsum'\n    }\n};\n\nconsole.log(deltaToUpdateParams(delta));\n\n// {\n//     ExpressionAttributeNames: {\n//         '#object': 'object'\n//     },\n//     ExpressionAttributeValues: {\n//         ':object': {\n//             M: {\n//                 number: {\n//                     N: '2'\n//                 },\n//                 string: {\n//                     S: 'lorem ipsum'\n//                 }\n//             }\n//         }\n//     },\n//     UpdateExpression: 'REMOVE nothing SET #object = :object'\n// }\n```\n\nThe `addValue()` function can be used to define an [ADD](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.ADD) action.\n\n```js\nconst delta = {\n    counter: addValue(3)\n};\n\nconsole.log(deltaToUpdateParams(delta));\n\n// {\n//     ExpressionAttributeNames: {\n//         '#counter': 'counter'\n//     },\n//     ExpressionAttributeValues: {\n//         ':counter': {\n//             N: '3'\n//         }\n//     },\n//     UpdateExpression: 'ADD #counter = :counter'\n// }\n```\n\nPlease have a look at the\n[unit tests](https://github.com/chrisguttandin/dynamo-converters/blob/master/test/unit/module.js#L61-L182) for\nmore examples.\n\n### data : itemToData( item )\n\nThis function takes a structured item returned by the official SDK and turns it into a plain\nJavaScript object.\n\n```js\nconst item = {\n    object: {\n        M: {\n            number: { N: '2' },\n            string: { S: 'lorem ipsum' }\n        }\n    }\n};\n\nconsole.log(itemToData(item));\n\n// {\n//     object: {\n//         number: 2,\n//         string: 'lorem ipsum'\n//     }\n// }\n```\n\nPlease have a look at the [unit tests](https://github.com/chrisguttandin/dynamo-converters/blob/master/test/unit/module.js#L184-L227) for more examples.\n\nThis function is similar to the [`unmarshall()` function](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_util_dynamodb.html#unmarshall-1) provided by the [@aws-sdk/util-dynamodb package](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_util_dynamodb.html#aws-sdkutil-dynamodb) but it preserves the property types.\n\n```js\nitemToData({ a: { N: '1' } });\n// {\n//     a: number;\n// }\n\nunmarshall({ a: { N: '1' } });\n// {\n//     [key: string]: any;\n// }\n```\n\n### transformedValue : withDateSerialization (value)\n\nThis is an example implementation of a custom transform function. In case it gets called with a `Date` it will turn it into a `string`. Any other value gets just passed through as is.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisguttandin%2Fdynamo-converters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisguttandin%2Fdynamo-converters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisguttandin%2Fdynamo-converters/lists"}