{"_id":"@block65/dynamodb-data-marshaller","_rev":"5-bebfc82727ce357239f071a9988fe854","name":"@block65/dynamodb-data-marshaller","dist-tags":{"latest":"0.7.4-alpha.2"},"versions":{"0.7.4-alpha.2":{"name":"@block65/dynamodb-data-marshaller","version":"0.7.4-alpha.2","keywords":["aws","dynamodb"],"author":{"name":"AWS SDK for JavaScript Team","email":"aws-sdk-js@amazon.com"},"license":"Apache-2.0","_id":"@block65/dynamodb-data-marshaller@0.7.4-alpha.2","maintainers":[{"name":"maxholman","email":"max@holmn.com"}],"homepage":"https://awslabs.github.io/dynamodb-data-mapper-js/packages/dynamodb-data-marshaller/","bugs":{"url":"https://github.com/awslabs/dynamodb-data-mapper-js/issues"},"dist":{"shasum":"6a5205b638a527fa03b9e59a4e3bb723762e6f7a","tarball":"https://registry.npmjs.org/@block65/dynamodb-data-marshaller/-/dynamodb-data-marshaller-0.7.4-alpha.2.tgz","fileCount":42,"integrity":"sha512-teIUSn0D4k2Gz6sBJGMS56w1WI/OA6fqyrUbOHIQlsTFGVhpMyrRazIqusjxNnll8U9Hud6ZoVyYYgb7jwOSyg==","signatures":[{"sig":"MEUCICh7qOdJBkdEyWwUFpOdcGSc4t7cJPw7RDdIy5OahpabAiEAraD6q8U6J2O7AuA6lCG36cQD3CEYXUCICsaQY8x28Y0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":106496,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe/sbgCRA9TVsSAnZWagAA+QUP/3qpC24EMktutUxNOIrc\na7sP464wRAaCDgwSI2cYhyC9LcBxPswmSLNhkvQxWBTwPndyaadNzOxrJcQk\nMN2RNvElT44oeEgCMXBFwBPlD8yxpsBtVRFlT9WvICkZ/Z0iX0eKpLqbsBNY\ncvopvmp+g1vYebfHbVX+yA7/1R6Wwx5vTqS3Hal6/Xl0+6UOMMRacQ14qJ64\nXDJKwZxPb+MxBtTaaQ1iDLpFdVh5Ffa4eh+Fm2KieInE45DzhJxAFO8Yti7P\nfBcaMNyob2tRRpyD2s1qrVsBRrYZ0AGfoX5wS76fcx/89UXjuG17znOQVvMP\ncq1e4y0PiBS/5z3K5YFMc4WRGHRZuaTJI/SPk+FSKg6fC6FdpAs5Br3b/m/e\nA3jMGz+SrvoUWCsd9scfHzHqrNijA5eMR8rjm3Z08DNtGPY8aFCbQnuYhLy7\nFi9lvjYxx+suWcuXZrQDhVYemiF9ORPYzOvhRbI59VW2TyEWX8sdnHsQbwGn\nQp/aLYSw33kO0U6ibK1H8rsLmAKxiK4Ljxzzz3SXlt4EEipj0DmT/FfEyOls\nu3JOxHWJu+Ck5gDD9SoKvUYkpzaS8ZusalMwxH6ou12hqPACbME1VrsyNADu\nZ62e20k6KWmH1NsC2yikR0C89lgcI2vQ33NuiAjicJAmY21pUBUp+1pTQiDV\nJ9fL\r\n=qZD8\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./build/index.js","types":"./build/index.d.ts","gitHead":"93d0f0f9ee8323106eda6e0e8383923f3e6f3b9a","scripts":{"docs":"typedoc src","test":"jest \"build/(.+).spec.js\"","pretest":"tsc -p tsconfig.test.json","prepublishOnly":"tsc"},"_npmUser":{"name":"maxholman","email":"max@holmn.com"},"deprecated":"This package is no longer maintained.","repository":{"url":"git+https://github.com/block65/dynamodb-data-mapper-js.git","type":"git"},"_npmVersion":"lerna/3.22.1/node@v14.5.0+x64 (linux)","description":"A schema-based data marshaller for Amazon DynamoDB","directories":{},"_nodeVersion":"14.5.0","dependencies":{"tslib":"^1.9","utf8-bytes":"^0.0.1","@block65/dynamodb-expressions":"^0.7.4-alpha.2","@block65/dynamodb-auto-marshaller":"^0.7.4-alpha.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^24","aws-sdk":"^2.7.0","typedoc":"^0.14.0","typescript":"^3.4","@types/jest":"^24","@types/node":"^8.0.4"},"peerDependencies":{"aws-sdk":"^2.7.0"},"_npmOperationalInternal":{"tmp":"tmp/dynamodb-data-marshaller_0.7.4-alpha.2_1593755359966_0.5480572402203872","host":"s3://npm-registry-packages"}}},"time":{"created":"2020-07-03T05:49:19.810Z","modified":"2026-09-15T09:40:18.504Z","0.7.4-alpha.2":"2020-07-03T05:49:20.134Z"},"bugs":{"url":"https://github.com/awslabs/dynamodb-data-mapper-js/issues"},"author":{"name":"AWS SDK for JavaScript Team","email":"aws-sdk-js@amazon.com"},"license":"Apache-2.0","homepage":"https://awslabs.github.io/dynamodb-data-mapper-js/packages/dynamodb-data-marshaller/","keywords":["aws","dynamodb"],"repository":{"url":"git+https://github.com/block65/dynamodb-data-mapper-js.git","type":"git"},"description":"A schema-based data marshaller for Amazon DynamoDB","maintainers":[{"email":"max@holmn.com","name":"maxholman"}],"readme":"# Amazon DynamoDB Data Marshaller\n\n[![Apache 2 License](https://img.shields.io/github/license/awslabs/dynamodb-data-mapper-js.svg?style=flat)](http://aws.amazon.com/apache-2-0/)\n\nThis library provides an `marshallItem` and `unmarshallItem` functions that\nconvert native JavaScript values to DynamoDB AttributeValues and back again,\nrespectively, based on a defined schema. While many JavaScript values map\ncleanly to DynamoDB data types and vice versa, schemas allow you to losslessly\npersist any JavaScript type, including dates, class instances, and empty\nstrings.\n\n## Getting started\n\nTo use the data marshaller, begin by defining a schema that describes the\nrelationship between your application's domain objects and their serialized form\nin a DynamoDB table:\n\n```javascript\nconst schema = {\n    foo: {type: 'Binary'},\n    bar: {type: 'Boolean'},\n    baz: {type: 'String'},\n    quux: {\n        type: 'Document',\n        members: {\n            fizz: {type: 'Set', memberType: 'String'},\n            buzz: {\n                type: 'Tuple',\n                members: [\n                    {\n                        type: 'List',\n                        memberType: {type: 'Set', memberType: 'Number'},\n                    },\n                    {\n                        type: 'Map',\n                        memberType: {type: 'Date'},\n                    }\n                ]\n            },\n        },\n    },\n};\n```\n\nThis schema may be used to marshall JavaScript values to DynamoDB attribute\nvalues:\n\n```javascript\nimport {marshallItem} from '@block65/dynamodb-data-marshaller';\n\nconst marshalled = marshallItem(schema, {\n    foo: Uint8Array.from([0xde, 0xad, 0xbe, 0xef]),\n    bar: false,\n    baz: '',\n    quux: {\n        fizz: new Set(['a', 'b', 'c']),\n        buzz: [\n            [\n                new Set([1, 2, 3]),\n                new Set([2, 3, 4]),\n                new Set([3, 4, 5]),\n            ],\n            new Map([\n                ['now', new Date()],\n                ['then', new Date(0)],\n            ]),\n        ]\n    }\n});\n```\n\nThe schema can also be used to unmarshall DynamoDB attribute values back to\ntheir original JavaScript representation:\n\n```javascript\nimport {unmarshallItem} from '@block65/dynamodb-data-marshaller';\n\nconst unmarshalled = unmarshallItem(schema, {\n    foo: {B: Uint8Array.from([0xde, 0xad, 0xbe, 0xef])},\n    bar: {BOOL: false},\n    baz: {NULL: true},\n    quux: {\n        fizz: {SS: ['a', 'b', 'c']},\n        buzz: {\n            L: [\n                L: [\n                    {NS: ['1', '2', '3']},\n                    {NS: ['2', '3', '4']},\n                    {NS: ['3', '4', '5']},\n                ],\n                M: {\n                    now: {N: '1507189047'},\n                    then: {N: '0'}\n                },\n            ],\n        },\n    },\n});\n```\n\n## Specifying keys\n\nDynamoDB tables must define a hash key and may optionally define a range key. In\nDynamoDB documentation, these keys are sometimes referred to as *partition* and\n*sort* keys, respectively. To declare a property to be a key, add a `keyType`\nproperty to its property schema (example taken from the [DynamoDB developer\nguide](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html)):\n\n```javascript\n// Table model taken from http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html\nconst gameScores = {\n    UserId: {\n        type: 'String',\n        keyType: 'HASH'\n    },\n    GameTitle: {\n        type: 'String',\n        keyType: 'RANGE'\n    },\n    TopScore: {type: 'Number'},\n    TopScoreDateTime: {type: 'Date'},\n    Wins: {type: 'Number'},\n    Losses: {type: 'Number'}\n};\n```\n\nThe `keyType` attribute may only be used in types that are serialized as\nstrings, numbers, or binary attributes. In addition to `'String'`, `'Number'`,\nand `'Binary'` properties, it may be used on `'Date'` and `'Custom'` properties.\n\nIndex keys are specified using an object mapping index names to the key type as\nwhich the value is used in a given index. To continue with the `gameScores`\nexample given above, you could add the index key declarations described in [the \nDynamoDB Global Secondary Index developer guide](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html)\nas follows:\n\n```javascript\nconst gameScores = {\n    UserId: {\n        type: 'String',\n        keyType: 'HASH'\n    },\n    GameTitle: {\n        type: 'String',\n        keyType: 'RANGE',\n        indexKeyConfigurations: {\n            GameTitleIndex: 'HASH'\n        }\n    },\n    TopScore: {\n        type: 'Number',\n        indexKeyConfigurations: {\n            GameTitleIndex: 'RANGE'\n        }\n    },\n    TopScoreDateTime: {type: 'Date'},\n    Wins: {type: 'Number'},\n    Losses: {type: 'Number'}\n};\n```\n\n## Supplying defaults\n\nAny property schema may define a `defaultProvider` function to be called when a\nfield is `undefined` in the input provided to `marshallItem`. This function must\nreturn a raw JavaScript value and should not return an already-marshalled\nDynamoDB AttributeValue shape.\n\n```javascript\nconst uuidV4 = require('uuid/v4');\n\nconst schema = {\n    key: {\n        type: 'String',\n        defaultProvider: uuidV4,\n        keyType: 'HASH',\n    },\n    // ...\n};\n```\n\n## Supported types\n\n### Any\n\nWill be marshalled and unmarshalled using the `@block65/dynamodb-auto-marshaller`\npackage, which detects the type of a given value at runtime.\n\n#### Example\n\n```javascript\nconst anyProperty = {\n    type: 'Any',\n    // optionally, you may specify configuration options for the\n    // @block65/dynamodb-auto-marshaller package's Marshaller class:\n    unwrapNumbers: false,\n    onInvalid: 'omit',\n    onEmpty: 'nullify',\n};\n```\n\n### Binary\n\nUsed for `ArrayBuffer` and `ArrayBufferView` objects, as well as Node.JS\nbuffers.\n\n**May be used as a table or index key.**\n\n#### Example\n\n```javascript\nconst binaryProperty = {type: 'Binary'};\n```\n\n### Boolean\n\nUsed for `true`/`false` values.\n\n#### Example\n\n```javascript\nconst booleanProperty = {type: 'Boolean'};\n```\n\n### Collection\n\nDenotes a list of untyped items. The constituent items will be marshalled and\nunmarshalled using the `@block65/dynamodb-auto-marshaller`.\n\n#### Example\n\n```javascript\nconst collectionProperty = {\n    type: 'Collection',\n    // optionally, you may specify configuration options for the\n    // @block65/dynamodb-auto-marshaller package's Marshaller class:\n    unwrapNumbers: false,\n    onInvalid: 'omit',\n    onEmpty: 'nullify',\n};\n```\n\n### Custom\n\nAllows the use of bespoke marshalling and unmarshalling functions. The type\ndefinition for a `'Custom'` property must include a `marshall` function that\nconverts the type's JavaScript representation to a DynamoDB AttributeValue and\nan `unmarshall` function that converts the AttributeValue back to a JavaScript\nvalue.\n\n**May be used as a table or index key.**\n\n#### Example\n\n```javascript\n// This custom property handles strings\nconst customProperty = {\n    type: 'Custom',\n    marshall(input) {\n        return {S: input};\n    },\n    unmarshall(persistedValue) {\n        return persistedValue.S;\n    }\n};\n```\n\n### Date\n\nUsed for time data. Dates will be serialized to DynamoDB as epoch timestamps\nfor easy integration with DynamoDB's time-to-live feature. As a result, timezone\ninformation will not be persisted.\n\n**May be used as a table or index key.**\n\n#### Example\n\n```javascript\nconst dateProperty = {type: 'Date'};\n```\n\n### Document\n\nUsed for object values that have their own schema and (optionally) constructor.\n\n#### Example\n\n```javascript\nclass MyCustomDocument {\n    method() {\n        // pass\n    }\n    \n    get computedProperty() {\n        // pass\n    }\n}\n\nclass documentSchema = {\n    fizz: {type: 'String'},\n    buzz: {type: 'Number'},\n    pop: {type: 'Date'}\n}\n\nconst documentProperty = {\n    type: 'Document',\n    members: documentSchema,\n    // optionally, you may specify a constructor to use to create the object\n    // that will underlie unmarshalled instances. If not specified,\n    // Object.create(null) will be used.\n    valueConstructor: MyCustomDocument\n};\n```\n\n### Hash\n\nUsed for objects with string keys and untyped values.\n\n#### Example\n\n```javascript\nconst collectionProperty = {\n    type: 'Hash',\n    // optionally, you may specify configuration options for the\n    // @block65/dynamodb-auto-marshaller package's Marshaller class:\n    unwrapNumbers: false,\n    onInvalid: 'omit',\n    onEmpty: 'nullify',\n};\n```\n\n### List\n\nUsed for arrays or iterable objects whose elements are all of the same type.\n\n#### Example\n\n```javascript\nconst listOfStrings = {\n    type: 'List',\n    memberType: {type: 'String'}\n};\n```\n\n### Map\n\nUsed for `Map` objects whose values are all of the same type.\n\n#### Example\n\n```javascript\nconst mapOfStrings = {\n    type: 'Map',\n    memberType: {type: 'String'}\n};\n```\n\n### Null\n\nUsed to serialize `null`. Often used as a sigil value.\n\n#### Example\n\n```javascript\nconst nullProperty = {type: 'Null'};\n```\n\n### Number\n\nUsed to serialize numbers.\n\n**May be used as a table or index key.**\n\n#### Example\n\n```javascript\nconst numberProperty = {type: 'Number'};\n```\n\n### Set\n\nUsed to serialize sets whose values are all of the same type. DynamoDB allows\nsets of numbers, sets of strings, and sets of binary values.\n\n#### Example\n\n```javascript\nconst binarySetProperty = {type: 'Set', memberType: 'Binary'};\nconst numberSetProperty = {type: 'Set', memberType: 'Number'};\nconst stringSetProperty = {type: 'Set', memberType: 'String'};\n```\n\n### String\n\nUsed to serialize strings.\n\n**May be used as a table or index key.**\n\n#### Example\n\n```javascript\nconst stringProperty = {type: 'String'};\n```\n\n### Tuple\n\nUsed to store arrays that have a specific length and sequence of elements.\n\n#### Example\n\n```javascript\nconst tupleProperty = {\n    type: 'Tuple',\n    members: [\n        {type: 'Boolean'},\n        {type: 'String'}\n    ]\n};\n```\n","readmeFilename":"README.md"}