├── .gitignore ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── apiReference.md ├── dynamodb-doc.min.js ├── jsdocs ├── DynamoDB.html ├── DynamoDBDatatype.html ├── DynamoDBFormatter.html ├── condition.js.html ├── datatypes.js.html ├── dynamodb-doc.js.html ├── formatter.js.html ├── global.html ├── index.html ├── scripts │ ├── linenumber.js │ └── prettify │ │ ├── Apache-License-2.0.txt │ │ ├── lang-css.js │ │ └── prettify.js └── styles │ ├── jsdoc-default.css │ ├── prettify-jsdoc.css │ └── prettify-tomorrow.css ├── lib ├── condition.js ├── datatypes.js ├── dynamodb-doc.js └── formatter.js ├── package.json └── test ├── condition.js ├── datatypes.js ├── formatter.js └── mocha.opts /.gitignore: -------------------------------------------------------------------------------- 1 | *.node 2 | node_modules/ 3 | npm-debug.log 4 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | AWS Document SDK for JavaScript 2 | Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | This product includes software developed at 5 | Amazon Web Services, Inc. (http://aws.amazon.com/). 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DynamoDB Document SDK 2 | 3 | **NOTE:** As of September 10, 2015, this version of the Document SDK will be deprecated in favor of the [AWS.DynamoDB.DocumentClient][1] in the [official AWS SDK for JavaScript][2]. This repository will continued to be hosted, but not maintained outside of bug reports. In addition, discussion and request for guidance should be directed at the [official AWS SDK for JavaScript][2]. Here's how you can get started with [the new client!][3] 4 | 5 | *** 6 | 7 | This SDK abstracts away the typing of attribute values in the low level SDK in order to provide a simpler developing experience. 8 | JS datatypes like `string` or `number` can be passed directly into DynamoDB requests and the wrapping will be handled for you; similarly for responses, datatypes will be unwrapped. 9 | 10 | For those DynamoDB types that do not have direct mappings to JS datatypes, a wrapper Object is provided to handle type ambiguities (i.e. StrSet, NumSet, BinSet). 11 | 12 | Lastly, a Condition Object is being introduced to simplify the use of the KeyCondition and Expected portion of the request params. 13 | Note: Condition Object serves to simplify previous api (NOT new expressions) 14 | 15 | ## Getting Started 16 | 17 | ### Install 18 | ```sh 19 | $ npm install dynamodb-doc --save 20 | ``` 21 | 22 | In order to instantiate the client, you still need the [AWS JS SDK](https://github.com/aws/aws-sdk-js) to store your region/credentials. 23 | 24 | ``` javascript 25 | var AWS = require("aws-sdk"); 26 | var DOC = require("dynamodb-doc"); 27 | 28 | AWS.config.update({region: "us-west-1"}); 29 | 30 | var docClient = new DOC.DynamoDB(); 31 | ``` 32 | 33 | Alternatively if you already have the existing DynamoDB Client, you can pass it in order to instantiate the client. 34 | 35 | ``` javascript 36 | // assumes AWS.config is set up already 37 | var awsClient = AWS.DynamoDB(); 38 | var docClient = new DOC.DynamoDB(awsClient); 39 | ``` 40 | 41 | After this, you can make requests and receive responses with JS datatypes! 42 | 43 | JS datatypes that can be used in place of DynamoDB Datatypes: 44 | 45 | |Javascript| DynamoDB | 46 | |:--------:|:----------:| 47 | |string | S | 48 | |number | N | 49 | |boolean | BOOL | 50 | |null | NULL | 51 | |array | L | 52 | |object | M | 53 | 54 | 55 | For Sets, the client will provide object for you: 56 | 57 | ``` javascript 58 | docClient.Set(["a", "b", "c"], "S") 59 | ``` 60 | 61 | Refer to the *Basic Usage* and *Nested DataTypes and More* sections down below to see examples of the updated API. 62 | 63 | In addition, the SDK also introduces a special kind of Object in order to simplify conditions. 64 | 65 | ``` javascript 66 | docClient.Condition(key, operator, val1, val2) 67 | ``` 68 | 69 | Refer to the section down below on *Condition Objects* to see an example of the usage. 70 | 71 | **NOTE:** To build the node js files for the browser yourself, run 72 | 73 | ``` bash 74 | npm install; uglifyjs lib/* | sed 's/\"use strict\";//' > dynamodb-doc.min.js 75 | # sed portion is optional depending on your use case 76 | ``` 77 | 78 | For each example assume we have these variables available to us. 79 | 80 | ``` javascript 81 | // Basic Client creation 82 | AWS.config.update({ /* ...your config... */ }); 83 | docClient = new DOC.DynamoDB(); 84 | 85 | // Basic Callback 86 | var pfunc = function(err, data) { 87 | if (err) { 88 | console.log(err, err.stack); 89 | } else { 90 | console.log(data); 91 | } 92 | } 93 | ``` 94 | 95 | ## Basic Usage: 96 | 97 | ``` javascript 98 | // Basic Scalar Datatypes 99 | var params = {}; 100 | params.TableName = "Users"; 101 | params.Item = {UserId : "John", 102 | Age : 21, 103 | Pic : docClient.StrToBin("someURI")}; 104 | 105 | docClient.putItem(params, pfunc); 106 | 107 | params = {}; 108 | params.TableName = "Users"; 109 | params.Key = {UserId : "John"}; 110 | 111 | docClient.getItem(params, pfunc); 112 | 113 | /* Response 114 | {Item: {UserId : "John", 115 | Age : 21, 116 | Pic : Bin}} 117 | */ 118 | ``` 119 | 120 | **NOTE:** StrToBin returns either a `Buffer` for NodeJS or `Uint8Array` for the browser. 121 | 122 | ## Nested DataTypes and More: 123 | 124 | ``` javascript 125 | var params = {}; 126 | params.TableName = "Shopping Cart"; 127 | 128 | // Compatible is a Map of Part to List of PartId's 129 | // OnSale is a BOOL type 130 | // Discount is a NULL type 131 | params.Item = {PartId : "CPU1", 132 | OnSale : false, 133 | Discount : null, 134 | Compatible : {Motherboards : ["MB1", "MB2"], 135 | RAM : ["RAM1"]}}; 136 | 137 | docClient.putItem(params, pfunc); 138 | 139 | params = {}; 140 | params.Key = {PartId : "CPU1"}; 141 | params.TableName = "Shopping Cart"; 142 | 143 | docClient.getItem(params, pfunc); 144 | 145 | /*Response 146 | {Item: {PartId : "CPU1", 147 | OnSale : false, 148 | Discount : null, 149 | Compatible : {Motherboards : ["MB1", "MB2"], 150 | RAM : ["RAM1"]}}}; 151 | */ 152 | ``` 153 | 154 | ## Condition Object: 155 | 156 | ``` javascript 157 | var params = {}; 158 | params.TableName = "Houses"; 159 | 160 | // Note: This is a query on the Key Schema of the table. 161 | // For queries on secondary indexes, specify params.IndexName = "index-name" 162 | 163 | // use an array of Condition Objects for multiple conditions 164 | params.KeyConditions = [docClient.Condition("HouseId", "NOT_NULL"), 165 | docClient.Condition("YearBuilt", "GT", 2000)]; 166 | 167 | // use a Condition Object for just a single condition 168 | params.QueryFilter = docClient.Condition("Price", "BETWEEN", 0, 900000); 169 | 170 | docClient.query(params, pfunc); 171 | 172 | /*Reponse 173 | {Count: 3, 174 | Items: [ { HouseId : "123 amzn way", 175 | YearBuilt : 2001, 176 | Price : 450000}, 177 | { HouseId : "321 dynamo st", 178 | YearBuilt : 2012, 179 | Price : 100000}, 180 | { HouseId : "213 JS ave", 181 | YearBuilt : 2014, 182 | Price : 1}], 183 | ScannedCount: 3} 184 | */ 185 | ``` 186 | 187 | ## Expressions (NEW!!): 188 | 189 | ``` javascript 190 | var params = {}; 191 | params.TableName = "SomeTable"; 192 | params.Key = {Some : "Key"}; 193 | 194 | // Use the #(variable) to substitute in place of attribute Names 195 | // Use the :(variable) to subsitute in place of attribute Values 196 | params.UpdateExpression = "set #a = :x + :y"; 197 | params.ConditionExpression = "#a < :MAX and Price = :correct"; 198 | params.ExpressionAttributeNames = {"#a" : "Description"}; 199 | params.ExpressionAttributeValues = {":x" : 20, 200 | ":y" : 45, 201 | ":MAX" : 100, 202 | ":correct" : "is right!!"}; 203 | 204 | docClient.updateItem(params, pfunc); 205 | ``` 206 | [1]: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html 207 | [2]: https://github.com/aws/aws-sdk-js 208 | [3]: http://blogs.aws.amazon.com/javascript/post/Tx1OVH5LUZAFC6T/Announcing-the-Amazon-DynamoDB-Document-Client-in-the-AWS-SDK-for-JavaScript 209 | -------------------------------------------------------------------------------- /apiReference.md: -------------------------------------------------------------------------------- 1 | #Index 2 | 3 | **Classes** 4 | 5 | * [class: DynamoDBDatatype](#DynamoDBDatatype) 6 | * [dynamoDBDatatype.formatDataType(dataType)](#DynamoDBDatatype#formatDataType) 7 | * [dynamoDBDatatype.strToBin(value)](#DynamoDBDatatype#strToBin) 8 | * [dynamoDBDatatype.binToStr(value)](#DynamoDBDatatype#binToStr) 9 | * [dynamoDBDatatype.createSet(set, type)](#DynamoDBDatatype#createSet) 10 | * [dynamoDBDatatype.formatWireType(key, value)](#DynamoDBDatatype#formatWireType) 11 | * [class: DynamoDB](#DynamoDB) 12 | * [new DynamoDB(dynamoDB)](#new_DynamoDB) 13 | * [dynamoDB.Set(set, type)](#DynamoDB#Set) 14 | * [dynamoDB.Condition(key, operator, val1, val2)](#DynamoDB#Condition) 15 | * [dynamoDB.StrToBin(value)](#DynamoDB#StrToBin) 16 | * [dynamoDB.BinToStr(value)](#DynamoDB#BinToStr) 17 | * [class: DynamoDBFormatter](#DynamoDBFormatter) 18 | * [new DynamoDBFormatter()](#new_DynamoDBFormatter) 19 | * [dynamoDBFormatter.formatOutput()](#DynamoDBFormatter#formatOutput) 20 | * [dynamoDBFormatter.formatInput()](#DynamoDBFormatter#formatInput) 21 | 22 | **Functions** 23 | 24 | * [DynamoDBCondition(key, operator, val1, val2)](#DynamoDBCondition) 25 | 26 | 27 | #class: DynamoDBDatatype 28 | Creates a DynamoDBDatatype that takes care of all datatype handling. 29 | 30 | **Members** 31 | 32 | * [class: DynamoDBDatatype](#DynamoDBDatatype) 33 | * [dynamoDBDatatype.formatDataType(dataType)](#DynamoDBDatatype#formatDataType) 34 | * [dynamoDBDatatype.strToBin(value)](#DynamoDBDatatype#strToBin) 35 | * [dynamoDBDatatype.binToStr(value)](#DynamoDBDatatype#binToStr) 36 | * [dynamoDBDatatype.createSet(set, type)](#DynamoDBDatatype#createSet) 37 | * [dynamoDBDatatype.formatWireType(key, value)](#DynamoDBDatatype#formatWireType) 38 | 39 | 40 | ##dynamoDBDatatype.formatDataType(dataType) 41 | Formats Javascript datatypes into DynamoDB wire format. 42 | 43 | **Params** 44 | 45 | - dataType - Javascript datatype (i.e. string, number. For full information, check out the README). 46 | 47 | **Returns**: `object` - DynamoDB JSON-like wire format. 48 | 49 | ##dynamoDBDatatype.strToBin(value) 50 | Utility to convert a String to a Binary object. 51 | 52 | **Params** 53 | 54 | - value `string` - String value to converted to Binary object. 55 | 56 | **Returns**: `object` - (Buffer | Uint8Array) depending on Node or browser. 57 | 58 | ##dynamoDBDatatype.binToStr(value) 59 | Utility to convert a Binary object into a decoded String. 60 | 61 | **Params** 62 | 63 | - value `object` - Binary value (Buffer | Uint8Array) depending on Node or browser. 64 | 65 | **Returns**: `string` - decoded String in UTF-8 66 | 67 | ##dynamoDBDatatype.createSet(set, type) 68 | Utility to create the DynamoDB Set Datatype. 69 | 70 | **Params** 71 | 72 | - set `array` - An array that contains elements of the same typed as defined by {type}. 73 | - type `string` - Can only be a [S]tring, [N]umber, or [B]inary type. 74 | 75 | **Returns**: `Set` - Custom Set object that follow {type}. 76 | 77 | ##dynamoDBDatatype.formatWireType(key, value) 78 | Formats DynamoDB wire format into javascript datatypes. 79 | 80 | **Params** 81 | 82 | - key `string` - Key that represents the type of the attribute value 83 | - value - Javascript datatype of the attribute value produced by DynamoDB 84 | 85 | 86 | #class: DynamoDB 87 | DynamoDB 88 | 89 | **Members** 90 | 91 | * [class: DynamoDB](#DynamoDB) 92 | * [new DynamoDB(dynamoDB)](#new_DynamoDB) 93 | * [dynamoDB.Set(set, type)](#DynamoDB#Set) 94 | * [dynamoDB.Condition(key, operator, val1, val2)](#DynamoDB#Condition) 95 | * [dynamoDB.StrToBin(value)](#DynamoDB#StrToBin) 96 | * [dynamoDB.BinToStr(value)](#DynamoDB#BinToStr) 97 | 98 | 99 | ##new DynamoDB(dynamoDB) 100 | Create an instance of the DynamoDB Document client. 101 | 102 | **Params** 103 | 104 | - dynamoDB `AWS.DynamoDB` - An instance of the service provided AWS SDK (optional). 105 | 106 | **Returns**: [DynamoDB](#DynamoDB) - Modified version of the service for Document support. 107 | 108 | ##dynamoDB.Set(set, type) 109 | Utility to create Set Object for requests. 110 | 111 | **Params** 112 | 113 | - set `array` - An array that contains elements of the same typed as defined by {type}. 114 | - type `string` - Can only be a [S]tring, [N]umber, or [B]inary type. 115 | 116 | **Returns**: `Set` - Custom Set object that follow {type}. 117 | 118 | ##dynamoDB.Condition(key, operator, val1, val2) 119 | Creates an instance of Condition and should be used with the DynamoDB client. 120 | 121 | **Params** 122 | 123 | - key `string` - The attribute name being conditioned. 124 | - operator `string` - The operator in the conditional clause. (See lower level docs for full list of operators) 125 | - val1 - Potential first element in what would be the AttributeValueList 126 | - val2 - Potential second element in what would be the AttributeValueList 127 | 128 | **Returns**: `Condition` - Condition for your DynamoDB request. 129 | 130 | ##dynamoDB.StrToBin(value) 131 | Utility to convert a String to the necessary Binary object. 132 | 133 | **Params** 134 | 135 | - value `string` - String value to converted to Binary object. 136 | 137 | **Returns**: `object` - Return value will be a Buffer or Uint8Array in the browser. 138 | 139 | ##dynamoDB.BinToStr(value) 140 | Utility to convert a Binary object into its String equivalent. 141 | 142 | **Params** 143 | 144 | - value `object` - Binary value (Buffer | Uint8Array) depending on environment. 145 | 146 | **Returns**: `string` - Return value will be the string representation of the Binary object. 147 | 148 | #class: DynamoDBFormatter 149 | **Members** 150 | 151 | * [class: DynamoDBFormatter](#DynamoDBFormatter) 152 | * [new DynamoDBFormatter()](#new_DynamoDBFormatter) 153 | * [dynamoDBFormatter.formatOutput()](#DynamoDBFormatter#formatOutput) 154 | * [dynamoDBFormatter.formatInput()](#DynamoDBFormatter#formatInput) 155 | 156 | 157 | ##new DynamoDBFormatter() 158 | Create an instance of the DynamoDBFormatter. 159 | 160 | **Returns**: [DynamoDBFormatter](#DynamoDBFormatter) - A Formatter object that provides methods for formatting DynamoDB requests and responses. 161 | 162 | ##dynamoDBFormatter.formatOutput() 163 | DynamoDBFormatter specifically for wrapping DynamoDB response objects. 164 | 165 | **Returns**: `object` - Wrapped up response object. 166 | 167 | ##dynamoDBFormatter.formatInput() 168 | DynamoDBFormatter specifically for unwrapping DynamoDB request objects. 169 | 170 | **Returns**: `object` - Returns aws sdk version of the request. 171 | 172 | #DynamoDBCondition(key, operator, val1, val2) 173 | Creates an instance of Condition that is used by the DynamoDB Document client. 174 | 175 | **Params** 176 | 177 | - key `string` - The attribute name being conditioned on. 178 | - operator `string` - The operator in the conditional clause. (See aws sdk docs for full list of operators) 179 | - val1 - Potential first element in what would be the AttributeValueList 180 | - val2 - Potential second element in what would be the AttributeValueList 181 | 182 | **Returns**: `Condition` - Condition for your DynamoDB request. 183 | -------------------------------------------------------------------------------- /dynamodb-doc.min.js: -------------------------------------------------------------------------------- 1 | function DynamoDBCondition(key,operator){var datatypes=typeof window==="undefined"?require("./datatypes").DynamoDBDatatype:window.DynamoDBDatatype;var t=new datatypes;var args=Array.prototype.slice.call(arguments,2);var CondObj=function Condition(key,operator,args){this.key=key;this.operator=operator;this.args=args;this.val1=args[0];this.val2=args[1];this.format=function(){var formatted={};var attrValueList=[];for(var i=0;i0){formatted.AttributeValueList=attrValueList}formatted.ComparisonOperator=this.operator;return formatted}};var cond=new CondObj(key,operator,args);cond.prototype=Object.create(Object.prototype);cond.prototype.instanceOf="DynamoDBConditionObject";return cond}if(typeof module!=="undefined"){var exports=module.exports={};exports.DynamoDBCondition=DynamoDBCondition}"use strict";function DynamoDBDatatype(){var AWS=typeof window==="undefined"?require("aws-sdk"):window.AWS;var Uint8ArrayError="Uint8Array can only be used for Binary in Browser.";var ScalarDatatypeError="Unrecognized Scalar Datatype to be formatted.";var GeneralDatatypeError="Unrecognized Datatype to be formatted.";var BinConversionError="Need to pass in Buffer or Uint8Array. ";var StrConversionError="Need to pass in string primitive to be converted to binary.";function isScalarType(dataType){var type=typeof dataType;return type==="number"||type==="string"||type==="boolean"||dataType instanceof Uint8Array&&AWS.util.isBrowser()||dataType instanceof AWS.util.Buffer||dataType===null}function isSetType(dataType){return dataType.datatype==="SS"||dataType.datatype==="NS"||dataType.datatype==="BS"}function isRecursiveType(dataType){return Array.isArray(dataType)||typeof dataType==="object"}function formatSetValues(datatype,values){if(datatype==="NS"){return values.map(function(n){return n.toString()})}else{return values}}function formatRecursiveType(dataType){var recursiveDoc={};var value={};var type="M";if(Array.isArray(dataType)){value=[];type="L";for(var index=0;index 2 | 3 | 4 | 5 | JSDoc: Class: DynamoDB 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: DynamoDB

21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 |

30 | DynamoDB 31 |

32 | 33 |
DynamoDB
34 | 35 |
36 | 37 |
38 |
39 | 40 | 41 | 42 | 43 |
44 |

new DynamoDB(dynamoDB) → {DynamoDB}

45 | 46 | 47 |
48 |
49 | 50 | 51 |
52 | Create an instance of the DynamoDB Document client. 53 |
54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
Parameters:
62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
NameTypeDescription
dynamoDB 90 | 91 | 92 | AWS.DynamoDB 93 | 94 | 95 | 96 | An instance of the service provided AWS SDK (optional).
108 | 109 | 110 | 111 |
112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 |
Source:
132 |
135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 |
143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 |
Returns:
157 | 158 | 159 |
160 | Modified version of the service for Document support. 161 |
162 | 163 | 164 | 165 |
166 |
167 | Type 168 |
169 |
170 | 171 | DynamoDB 172 | 173 | 174 |
175 |
176 | 177 | 178 | 179 | 180 |
181 | 182 | 183 |
184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 |

Methods

201 | 202 |
203 | 204 |
205 |

BinToStr(value) → {string}

206 | 207 | 208 |
209 |
210 | 211 | 212 |
213 | Utility to convert a Binary object into its String equivalent. 214 |
215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 |
Parameters:
223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 |
NameTypeDescription
value 251 | 252 | 253 | object 254 | 255 | 256 | 257 | Binary value (Buffer | Uint8Array) depending on environment.
269 | 270 | 271 | 272 |
273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 |
Source:
293 |
296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 |
304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 |
Throws:
316 | 317 | 318 | 319 |
320 | 321 | BinConversionError 322 | 323 |
324 | 325 | 326 | 327 | 328 | 329 |
Returns:
330 | 331 | 332 |
333 | Return value will be the string representation of the Binary object. 334 |
335 | 336 | 337 | 338 |
339 |
340 | Type 341 |
342 |
343 | 344 | string 345 | 346 | 347 |
348 |
349 | 350 | 351 | 352 | 353 |
354 | 355 | 356 | 357 |
358 |

Condition(key, operator, val1, val2) → {Condition}

359 | 360 | 361 |
362 |
363 | 364 | 365 |
366 | Creates an instance of Condition and should be used with the DynamoDB client. 367 |
368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 |
Parameters:
376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 |
NameTypeDescription
key 404 | 405 | 406 | string 407 | 408 | 409 | 410 | The attribute name being conditioned.
operator 427 | 428 | 429 | string 430 | 431 | 432 | 433 | The operator in the conditional clause. (See lower level docs for full list of operators)
val1 450 | 451 | Potential first element in what would be the AttributeValueList
val2 468 | 469 | Potential second element in what would be the AttributeValueList
481 | 482 | 483 | 484 |
485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 |
Source:
505 |
508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 |
516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 |
Returns:
530 | 531 | 532 |
533 | Condition for your DynamoDB request. 534 |
535 | 536 | 537 | 538 |
539 |
540 | Type 541 |
542 |
543 | 544 | Condition 545 | 546 | 547 |
548 |
549 | 550 | 551 | 552 | 553 |
554 | 555 | 556 | 557 |
558 |

Set(set, type) → {Set}

559 | 560 | 561 |
562 |
563 | 564 | 565 |
566 | Utility to create Set Object for requests. 567 |
568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 |
Parameters:
576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 |
NameTypeDescription
set 604 | 605 | 606 | array 607 | 608 | 609 | 610 | An array that contains elements of the same typed as defined by {type}.
type 627 | 628 | 629 | string 630 | 631 | 632 | 633 | Can only be a [S]tring, [N]umber, or [B]inary type.
645 | 646 | 647 | 648 |
649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 |
Source:
669 |
672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 |
680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 |
Throws:
692 | 693 | 694 | 695 |
696 | 697 | InvalidSetType, InconsistentType 698 | 699 |
700 | 701 | 702 | 703 | 704 | 705 |
Returns:
706 | 707 | 708 |
709 | Custom Set object that follow {type}. 710 |
711 | 712 | 713 | 714 |
715 |
716 | Type 717 |
718 |
719 | 720 | Set 721 | 722 | 723 |
724 |
725 | 726 | 727 | 728 | 729 |
730 | 731 | 732 | 733 |
734 |

StrToBin(value) → {object}

735 | 736 | 737 |
738 |
739 | 740 | 741 |
742 | Utility to convert a String to the necessary Binary object. 743 |
744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 |
Parameters:
752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 |
NameTypeDescription
value 780 | 781 | 782 | string 783 | 784 | 785 | 786 | String value to converted to Binary object.
798 | 799 | 800 | 801 |
802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 |
Source:
822 |
825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 |
833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 |
Throws:
845 | 846 | 847 | 848 |
849 | 850 | StrConversionError 851 | 852 |
853 | 854 | 855 | 856 | 857 | 858 |
Returns:
859 | 860 | 861 |
862 | Return value will be a Buffer or Uint8Array in the browser. 863 |
864 | 865 | 866 | 867 |
868 |
869 | Type 870 |
871 |
872 | 873 | object 874 | 875 | 876 |
877 |
878 | 879 | 880 | 881 | 882 |
883 | 884 |
885 | 886 | 887 | 888 | 889 | 890 |
891 | 892 |
893 | 894 | 895 | 896 | 897 |
898 | 899 | 902 | 903 |
904 | 905 |
906 | Documentation generated by JSDoc 3.3.0-alpha9 on Tue Oct 07 2014 18:08:15 GMT-0700 (PDT) 907 |
908 | 909 | 910 | 911 | 912 | -------------------------------------------------------------------------------- /jsdocs/DynamoDBDatatype.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: DynamoDBDatatype 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: DynamoDBDatatype

21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 |

30 | DynamoDBDatatype 31 |

32 | 33 |
Creates a DynamoDBDatatype that takes care of all datatype handling.
34 | 35 |
36 | 37 |
38 |
39 | 40 | 41 | 42 | 43 |
44 |

new DynamoDBDatatype()

45 | 46 | 47 |
48 |
49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 |
Source:
80 |
83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 |
91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |
107 | 108 | 109 |
110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 |

Methods

127 | 128 |
129 | 130 |
131 |

binToStr(value) → {string}

132 | 133 | 134 |
135 |
136 | 137 | 138 |
139 | Utility to convert a Binary object into a decoded String. 140 |
141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 |
Parameters:
149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 |
NameTypeDescription
value 177 | 178 | 179 | object 180 | 181 | 182 | 183 | Binary value (Buffer | Uint8Array) depending on Node or browser.
195 | 196 | 197 | 198 |
199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 |
Source:
219 |
222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 |
230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 |
Throws:
242 | 243 | 244 | 245 |
246 | 247 | BinConversionError 248 | 249 |
250 | 251 | 252 | 253 | 254 | 255 |
Returns:
256 | 257 | 258 |
259 | decoded String in UTF-8 260 |
261 | 262 | 263 | 264 |
265 |
266 | Type 267 |
268 |
269 | 270 | string 271 | 272 | 273 |
274 |
275 | 276 | 277 | 278 | 279 |
280 | 281 | 282 | 283 |
284 |

createSet(set, type) → {Set}

285 | 286 | 287 |
288 |
289 | 290 | 291 |
292 | Utility to create the DynamoDB Set Datatype. 293 |
294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 |
Parameters:
302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 |
NameTypeDescription
set 330 | 331 | 332 | array 333 | 334 | 335 | 336 | An array that contains elements of the same typed as defined by {type}.
type 353 | 354 | 355 | string 356 | 357 | 358 | 359 | Can only be a [S]tring, [N]umber, or [B]inary type.
371 | 372 | 373 | 374 |
375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 |
Source:
395 |
398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 |
406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 |
Throws:
418 | 419 | 420 | 421 |
422 | 423 | InvalidSetType, InconsistentType 424 | 425 |
426 | 427 | 428 | 429 | 430 | 431 |
Returns:
432 | 433 | 434 |
435 | Custom Set object that follow {type}. 436 |
437 | 438 | 439 | 440 |
441 |
442 | Type 443 |
444 |
445 | 446 | Set 447 | 448 | 449 |
450 |
451 | 452 | 453 | 454 | 455 |
456 | 457 | 458 | 459 |
460 |

formatDataType(dataType) → {object}

461 | 462 | 463 |
464 |
465 | 466 | 467 |
468 | Formats Javascript datatypes into DynamoDB wire format. 469 |
470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 |
Parameters:
478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 |
NameTypeDescription
dataType 506 | 507 | Javascript datatype (i.e. string, number. For full information, check out the README).
519 | 520 | 521 | 522 |
523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 |
Source:
543 |
546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 |
554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 |
Throws:
566 | 567 | 568 | 569 |
570 | 571 | GeneralDatatypeError 572 | 573 |
574 | 575 | 576 | 577 | 578 | 579 |
Returns:
580 | 581 | 582 |
583 | DynamoDB JSON-like wire format. 584 |
585 | 586 | 587 | 588 |
589 |
590 | Type 591 |
592 |
593 | 594 | object 595 | 596 | 597 |
598 |
599 | 600 | 601 | 602 | 603 |
604 | 605 | 606 | 607 |
608 |

formatWireType(key, value)

609 | 610 | 611 |
612 |
613 | 614 | 615 |
616 | Formats DynamoDB wire format into javascript datatypes. 617 |
618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 |
Parameters:
626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 |
NameTypeDescription
key 654 | 655 | 656 | string 657 | 658 | 659 | 660 | Key that represents the type of the attribute value
value 677 | 678 | Javascript datatype of the attribute value produced by DynamoDB
690 | 691 | 692 | 693 |
694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 |
Source:
714 |
717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 |
725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 |
Throws:
737 | 738 | 739 | 740 |
741 | 742 | GeneralDatatypeError 743 | 744 |
745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 |
753 | 754 | 755 | 756 |
757 |

strToBin(value) → {object}

758 | 759 | 760 |
761 |
762 | 763 | 764 |
765 | Utility to convert a String to a Binary object. 766 |
767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 |
Parameters:
775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 |
NameTypeDescription
value 803 | 804 | 805 | string 806 | 807 | 808 | 809 | String value to converted to Binary object.
821 | 822 | 823 | 824 |
825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 |
Source:
845 |
848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 |
856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 |
Throws:
868 | 869 | 870 | 871 |
872 | 873 | StrConversionError 874 | 875 |
876 | 877 | 878 | 879 | 880 | 881 |
Returns:
882 | 883 | 884 |
885 | (Buffer | Uint8Array) depending on Node or browser. 886 |
887 | 888 | 889 | 890 |
891 |
892 | Type 893 |
894 |
895 | 896 | object 897 | 898 | 899 |
900 |
901 | 902 | 903 | 904 | 905 |
906 | 907 |
908 | 909 | 910 | 911 | 912 | 913 |
914 | 915 |
916 | 917 | 918 | 919 | 920 |
921 | 922 | 925 | 926 |
927 | 928 |
929 | Documentation generated by JSDoc 3.3.0-alpha9 on Tue Oct 07 2014 18:08:15 GMT-0700 (PDT) 930 |
931 | 932 | 933 | 934 | 935 | -------------------------------------------------------------------------------- /jsdocs/DynamoDBFormatter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: DynamoDBFormatter 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: DynamoDBFormatter

21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 |

30 | DynamoDBFormatter 31 |

32 | 33 |
34 | 35 |
36 |
37 | 38 | 39 | 40 | 41 |
42 |

new DynamoDBFormatter() → {DynamoDBFormatter}

43 | 44 | 45 |
46 |
47 | 48 | 49 |
50 | Create an instance of the DynamoDBFormatter. 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 |
Source:
82 |
85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |
Returns:
107 | 108 | 109 |
110 | A Formatter object that provides methods for formatting DynamoDB requests and responses. 111 |
112 | 113 | 114 | 115 |
116 |
117 | Type 118 |
119 |
120 | 121 | DynamoDBFormatter 122 | 123 | 124 |
125 |
126 | 127 | 128 | 129 | 130 |
131 | 132 | 133 |
134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 |

Methods

151 | 152 |
153 | 154 |
155 |

formatInput() → {object}

156 | 157 | 158 |
159 |
160 | 161 | 162 |
163 | DynamoDBFormatter specifically for unwrapping DynamoDB request objects. 164 |
165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 |
175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 |
Source:
195 |
198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 |
206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 |
Returns:
220 | 221 | 222 |
223 | Returns aws sdk version of the request. 224 |
225 | 226 | 227 | 228 |
229 |
230 | Type 231 |
232 |
233 | 234 | object 235 | 236 | 237 |
238 |
239 | 240 | 241 | 242 | 243 |
244 | 245 | 246 | 247 |
248 |

formatOutput() → {object}

249 | 250 | 251 |
252 |
253 | 254 | 255 |
256 | DynamoDBFormatter specifically for wrapping DynamoDB response objects. 257 |
258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 |
268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 |
Source:
288 |
291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 |
299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 |
Returns:
313 | 314 | 315 |
316 | Wrapped up response object. 317 |
318 | 319 | 320 | 321 |
322 |
323 | Type 324 |
325 |
326 | 327 | object 328 | 329 | 330 |
331 |
332 | 333 | 334 | 335 | 336 |
337 | 338 |
339 | 340 | 341 | 342 | 343 | 344 |
345 | 346 |
347 | 348 | 349 | 350 | 351 |
352 | 353 | 356 | 357 |
358 | 359 |
360 | Documentation generated by JSDoc 3.3.0-alpha9 on Tue Oct 07 2014 18:08:15 GMT-0700 (PDT) 361 |
362 | 363 | 364 | 365 | 366 | -------------------------------------------------------------------------------- /jsdocs/condition.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: condition.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: condition.js

21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 |
"use strict";
 29 | 
 30 | /**
 31 |  * Creates an instance of Condition that is used by the DynamoDB Document client.
 32 |  *
 33 |  * @param {string} key The attribute name being conditioned on.
 34 |  * @param {string} operator The operator in the conditional clause. (See aws sdk docs for full list of operators)
 35 |  * @param val1 Potential first element in what would be the AttributeValueList
 36 |  * @param val2 Potential second element in what would be the AttributeValueList
 37 |  * @return {Condition} Condition for your DynamoDB request.
 38 |  */
 39 | function DynamoDBCondition(key, operator, val1, val2) {
 40 |     var datatypes = typeof(window) === "undefined" ? require("./datatypes").DynamoDBDatatype
 41 |                 : window.DynamoDBDatatype;
 42 | 
 43 |     var t = new datatypes();
 44 | 
 45 |     var CondObj = function Condition(key, operator, val1, val2) {
 46 |             this.key = key;
 47 |             this.operator = operator;
 48 |             this.val1 = val1;
 49 |             this.val2 = val2;
 50 |         
 51 |             this.format = function() {
 52 |                 var formatted = {};
 53 |         
 54 |                 var attrValueList = [];
 55 |                 if (this.val1 !== undefined) {
 56 |                     attrValueList.push(t.formatDataType(this.val1)); 
 57 |                 }
 58 |                 if (this.val2 !== undefined) {
 59 |                     attrValueList.push(t.formatDataType(this.val2));
 60 |                 }
 61 |                 if (attrValueList.length > 0) {
 62 |                     formatted.AttributeValueList = attrValueList;
 63 |                 }
 64 |                 formatted.ComparisonOperator = this.operator;
 65 |         
 66 |                 return formatted;
 67 |             };
 68 |     };
 69 | 
 70 |     var cond = new CondObj(key, operator, val1, val2);
 71 |     cond.prototype = Object.create(Object.prototype);
 72 |     cond.prototype.instanceOf  = "DynamoDBConditionObject";
 73 | 
 74 |     return cond;
 75 | }
 76 | 
 77 | if (typeof(module) !== "undefined") {
 78 |     var exports = module.exports = {};
 79 |     exports.DynamoDBCondition = DynamoDBCondition;
 80 | }
 81 | 
82 |
83 |
84 | 85 | 86 | 87 | 88 |
89 | 90 | 93 | 94 |
95 | 96 |
97 | Documentation generated by JSDoc 3.3.0-alpha9 on Tue Oct 07 2014 18:08:15 GMT-0700 (PDT) 98 |
99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /jsdocs/datatypes.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: datatypes.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: datatypes.js

21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 |
"use strict";
 29 | 
 30 | /**
 31 |  * @class Creates a DynamoDBDatatype that takes care of all datatype handling.
 32 |  *
 33 |  * @name DynamoDBDatatype
 34 |  */
 35 | function DynamoDBDatatype() {    
 36 |     var AWS = typeof(window) === "undefined" ? require("aws-sdk") : window.AWS;
 37 |     var Uint8ArrayError = "Uint8Array can only be used for Binary in Browser.";
 38 |     var ScalarDatatypeError = "Unrecognized Scalar Datatype to be formatted.";
 39 |     var GeneralDatatypeError = "Unrecognized Datatype to be formatted.";
 40 |     var BinConversionError = "Need to pass in Buffer or Uint8Array. ";
 41 |     var StrConversionError = "Need to pass in string primitive to be converted to binary.";
 42 | 
 43 |     function isScalarType(dataType) {
 44 |         
 45 |         var type = typeof(dataType);
 46 |         return  type === "number"  ||
 47 |                 type === "string"  ||
 48 |                 type === "boolean" ||
 49 |                 (dataType instanceof(Uint8Array) && AWS.util.isBrowser()) ||
 50 |                 dataType instanceof(AWS.util.Buffer) ||
 51 |                 dataType === null;
 52 |     }
 53 |     
 54 |     function isSetType(dataType) {
 55 |         return dataType.datatype === "SS" ||
 56 |                 dataType.datatype === "NS" ||
 57 |                 dataType.datatype === "BS";
 58 |     }
 59 |     
 60 |     function isRecursiveType(dataType) {
 61 |         
 62 |         return Array.isArray(dataType) ||
 63 |                 typeof(dataType) === "object";
 64 |     }
 65 |     
 66 |     function formatRecursiveType(dataType) {
 67 |         
 68 |         var recursiveDoc = {};
 69 |     
 70 |         var value = {};
 71 |         var type = "M";
 72 |         if (Array.isArray(dataType)) {
 73 |             value = [];
 74 |             type = "L";
 75 |         }
 76 |     
 77 |         for (var key in dataType) {
 78 |             value[key] = this.formatDataType(dataType[key]);
 79 |         }
 80 |     
 81 |         recursiveDoc[type] = value;
 82 |         return recursiveDoc; 
 83 |     }
 84 |     
 85 |     /** @throws Uint8ArrayError, ScalarDatatypeError
 86 |      *  @private */
 87 |     function formatScalarType(dataType) {
 88 |         
 89 |         if (dataType == null) {
 90 |             return { "NULL" : true };
 91 |         }
 92 |     
 93 |         var type = typeof(dataType);
 94 |         if (type === "string") {
 95 |             return { "S" : dataType };
 96 |         } else if (type === "number") {
 97 |             return { "N" : String(dataType) };
 98 |         } else if (type === "boolean") {
 99 |             return { "BOOL" : dataType };
100 |         } else if (dataType instanceof(AWS.util.Buffer)) {
101 |             return { "B" : dataType };
102 |         } else if (dataType instanceof(Uint8Array)) {
103 |             if (AWS.util.isBrowser()) {
104 |                 return { "B" : dataType };
105 |             } else {
106 |                 throw new Error(Uint8ArrayError);
107 |             }
108 |         } else {
109 |             throw new Error(ScalarDatatypeError);
110 |         }
111 |     }
112 |     
113 |     /**
114 |      * Formats Javascript datatypes into DynamoDB wire format.
115 |      * 
116 |      * @name formatDataType
117 |      * @function
118 |      * @memberOf DynamoDBDatatype#
119 |      * @param dataType Javascript datatype (i.e. string, number. For full information, check out the README).
120 |      * @return {object} DynamoDB JSON-like wire format.
121 |      * @throws GeneralDatatypeError
122 |      */
123 |     this.formatDataType = function(dataType) {
124 |         
125 |         if (isScalarType(dataType)) {
126 |             return formatScalarType(dataType);
127 |         } else if (isSetType(dataType)) {
128 |             return dataType.format();
129 |         } else if (isRecursiveType(dataType)) {
130 |             return formatRecursiveType.call(this, dataType);            
131 |         }  else {
132 |             throw new Error(GeneralDatatypeError);
133 |         }
134 |         
135 |     };
136 | 
137 |     function str2Bin(value) {
138 |         if (typeof(value) !== "string") {
139 |             throw new Error(StrConversionError);
140 |         }
141 | 
142 |         if (AWS.util.isBrowser()) {
143 |             var len = value.length;
144 |             var bin = new Uint8Array(new ArrayBuffer(len));
145 |             for (var i = 0; i < len; i++) {
146 |                 bin[i] = value.charCodeAt(i);
147 |             }
148 |             return bin;
149 |         } else {
150 |             return AWS.util.Buffer(value);
151 |         }
152 |     }
153 | 
154 |     /**
155 |      * Utility to convert a String to a Binary object.
156 |      *
157 |      * @function strToBin
158 |      * @memberOf DynamoDBDatatype#
159 |      * @param {string} value String value to converted to Binary object.
160 |      * @return {object} (Buffer | Uint8Array) depending on Node or browser.
161 |      * @throws StrConversionError
162 |      */
163 |     this.strToBin = function(value) {
164 |         return str2Bin.call(this, value);
165 |     };
166 | 
167 |     function bin2Str(value) {
168 |         if (!(value instanceof(AWS.util.Buffer)) && !(value instanceof(Uint8Array))) {
169 |             throw new Error(BinConversionError);
170 |         }
171 | 
172 |         if (AWS.util.isBrowser()) {
173 |             return String.fromCharCode.apply(null, value);
174 |         } else {
175 |             return value.toString("utf-8").valueOf();
176 |         }
177 |     }
178 | 
179 |     /**
180 |      * Utility to convert a Binary object into a decoded String.
181 |      *
182 |      * @function binToStr
183 |      * @memberOf DynamoDBDatatype#
184 |      * @param {object} value Binary value (Buffer | Uint8Array) depending on Node or browser.
185 |      * @return {string} decoded String in UTF-8
186 |      * @throws BinConversionError
187 |      */
188 |     this.binToStr = function(value) {
189 |         return bin2Str.call(this, value);
190 |     };
191 |     
192 |     /**
193 |      * Utility to create the DynamoDB Set Datatype.
194 |      * 
195 |      * @function createSet
196 |      * @memberOf DynamoDBDatatype#
197 |      * @param {array} set An array that contains elements of the same typed as defined by {type}.
198 |      * @param {string} type Can only be a [S]tring, [N]umber, or [B]inary type.
199 |      * @return {Set} Custom Set object that follow {type}.
200 |      * @throws InvalidSetType, InconsistentType
201 |      */
202 |     this.createSet = function(set, type) {
203 |         if (type !== "N" && type !== "S" && type !== "B") {
204 |             throw new Error(this.type + " is an invalid type for Set");
205 |         }
206 |     
207 |         var setObj = function Set(set, type) {
208 |             this.datatype = type + "S";
209 |             this.contents = {};
210 |     
211 |             this.add = function(value) {
212 |                 if (this.datatype === "SS" && typeof(value) === "string") {
213 |                     this.contents[value] = value;
214 |                 } else if (this.datatype === "NS" && typeof(value) === "number") {
215 |                     this.contents[value] = value;
216 |                 } else if (this.datatype === "BS" && value instanceof(AWS.util.Buffer)) {
217 |                     this.contents[bin2Str(value)] = value;
218 |                 } else if (this.datatype === "BS" && value instanceof(Uint8Array)) {
219 |                     if (AWS.util.isBrowser()) {
220 |                         this.contents[bin2Str(value)] = value;
221 |                     } else {
222 |                         throw new Error(Uint8ArrayError);
223 |                     }
224 |                 } else {
225 |                     throw new Error("Inconsistent in this " + this.type + " Set");
226 |                 }
227 |             };
228 |         
229 |             this.contains = function(content) {
230 |                 var value = content;
231 |                 if (content instanceof AWS.util.Buffer || content instanceof(Uint8Array)) {
232 |                     value = bin2Str(content);
233 |                 } 
234 |                 if (this.contents[value] === undefined) {
235 |                     return false;
236 |                 }
237 |                 return true;
238 |             };
239 |     
240 |             this.remove = function(content) {
241 |                 var value = content;
242 |                 if (content instanceof AWS.util.Buffer || content instanceof(Uint8Array)) {
243 |                     value = bin2Str(content);
244 |                 }
245 |                 delete this.contents[value];
246 |             };
247 |     
248 |             this.toArray = function() {
249 |                 var keys = Object.keys(this.contents);
250 |                 var arr = [];
251 |     
252 |                 for (var keyIndex in keys) {
253 |                     var key = keys[keyIndex];
254 |                     if (this.contents.hasOwnProperty(key)) {
255 |                         arr.push(this.contents[key]);
256 |                     }
257 |                 }
258 |     
259 |                 return arr;
260 |             };
261 |     
262 |             this.format = function() {
263 |                 var values = this.toArray(); 
264 |                 var result = {};
265 |                 result[this.datatype] = values;
266 |                 return result;
267 |             };
268 |     
269 |             if (set) {
270 |                 for (var index in set) {
271 |                     this.add(set[index]);
272 |                 }
273 |             }
274 |         };
275 |     
276 |         return new setObj(set, type);
277 |     };
278 | 
279 |     /**
280 |      * Formats DynamoDB wire format into javascript datatypes.
281 |      * 
282 |      * @name formatWireType
283 |      * @function
284 |      * @memberOf DynamoDBDatatype#
285 |      * @param {string} key Key that represents the type of the attribute value
286 |      * @param value Javascript datatype of the attribute value produced by DynamoDB
287 |      * @throws GeneralDatatypeError
288 |      */
289 |     this.formatWireType = function(key, value) {
290 |         switch (key) {
291 |             case "S":
292 |             case "B":
293 |             case "BOOL":
294 |                 return value;
295 |             case "N":
296 |                 return Number(value);
297 |             case "NULL":
298 |                 return null;
299 |             case "L":
300 |             case "M":
301 |                 for (var keyIndex in value) {
302 |                     var subValue = value[keyIndex];
303 |                     var subKey = Object.keys(subValue)[0];
304 |                     value[keyIndex] = this.formatWireType(subKey, subValue[subKey]);
305 |                 }
306 |                 return value;
307 |             case "SS":
308 |                 return new this.createSet(value, "S");
309 |             case "NS":
310 |                 value = value.map(function(each) { return Number(each);});
311 |                 return new this.createSet(value, "N");
312 |             case "BS":
313 |                 return new this.createSet(value, "B");
314 |             default:
315 |                 throw "Service returned unrecognized datatype " + key;
316 |         }
317 |     }
318 | } 
319 | 
320 | if (typeof(module) !== "undefined") {
321 |     var exports = module.exports = {};
322 |     exports.DynamoDBDatatype = DynamoDBDatatype;
323 | }
324 | 
325 |
326 |
327 | 328 | 329 | 330 | 331 |
332 | 333 | 336 | 337 |
338 | 339 |
340 | Documentation generated by JSDoc 3.3.0-alpha9 on Tue Oct 07 2014 18:08:15 GMT-0700 (PDT) 341 |
342 | 343 | 344 | 345 | 346 | 347 | -------------------------------------------------------------------------------- /jsdocs/dynamodb-doc.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: dynamodb-doc.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: dynamodb-doc.js

21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 |
"use strict";
 29 | 
 30 | /**
 31 |  * Create an instance of the DynamoDB Document client.
 32 |  *
 33 |  * @constructor
 34 |  * @class DynamoDB
 35 |  * @param {AWS.DynamoDB} dynamoDB An instance of the service provided AWS SDK (optional).
 36 |  * @returns {DynamoDB} Modified version of the service for Document support.
 37 |  */
 38 | function DynamoDB(dynamoDB) {
 39 |     var isBrowser = typeof(window) === "undefined";
 40 |     var AWS = isBrowser ? require("aws-sdk") : window.AWS;
 41 | 
 42 |     var condition = isBrowser ? require("./condition").DynamoDBCondition : window.DynamoDBCondition;
 43 | 
 44 |     var datatypes = isBrowser ? require("./datatypes").DynamoDBDatatype : window.DynamoDBDatatype;
 45 |     var t = new datatypes();
 46 | 
 47 |     var formatter = isBrowser ? require("./formatter").DynamoDBFormatter : window.DynamoDBFormatter;
 48 |     var f = new formatter();
 49 | 
 50 |     var service = dynamoDB || new AWS.DynamoDB();
 51 | 
 52 |     if (!(service instanceof(AWS.DynamoDB))) {
 53 |         throw new Error("Need an instance of AWS.DynamoDB as an argument.");
 54 |     }
 55 | 
 56 |     var setupLowLevelRequestListeners = service.setupRequestListeners;
 57 |     service.setupRequestListeners = function(request) {
 58 |         setupLowLevelRequestListeners.call(this, request);
 59 | 
 60 |         request._events.validate.unshift(f.formatInput);
 61 |         request.on("extractData", f.formatOutput);
 62 |     };
 63 |     
 64 |     /**
 65 |      * Utility to create Set Object for requests.
 66 |      *
 67 |      * @function Set
 68 |      * @memberOf DynamoDB#
 69 |      * @param {array} set An array that contains elements of the same typed as defined by {type}.
 70 |      * @param {string} type Can only be a [S]tring, [N]umber, or [B]inary type.
 71 |      * @return {Set} Custom Set object that follow {type}.
 72 |      * @throws InvalidSetType, InconsistentType
 73 |      */
 74 |     service.__proto__.Set = function(set, type) {
 75 |         return t.createSet(set, type); 
 76 |     };
 77 | 
 78 |     /**
 79 |     * Creates an instance of Condition and should be used with the DynamoDB client.
 80 |     *
 81 |     * @function Condition
 82 |     * @memberOf DynamoDB#
 83 |     * @param {string} key The attribute name being conditioned.
 84 |     * @param {string} operator The operator in the conditional clause. (See lower level docs for full list of operators)
 85 |     * @param val1 Potential first element in what would be the AttributeValueList
 86 |     * @param val2 Potential second element in what would be the AttributeValueList
 87 |     * @return {Condition} Condition for your DynamoDB request.
 88 |     */
 89 |     service.__proto__.Condition = function(key, operator, val1, val2) {
 90 |         return condition(key, operator, val1, val2);
 91 |     };
 92 | 
 93 |     /**
 94 |      * Utility to convert a String to the necessary Binary object.
 95 |      *
 96 |      * @function StrToBin
 97 |      * @memberOf DynamoDB#
 98 |      * @param {string} value String value to converted to Binary object.
 99 |      * @return {object} Return value will be a Buffer or Uint8Array in the browser.
100 |      * @throws StrConversionError
101 |      */
102 |     service.__proto__.StrToBin = function(value) {
103 |         return t.strToBin(value);
104 |     };
105 |     /**
106 |      * Utility to convert a Binary object into its String equivalent.
107 |      *
108 |      * @function BinToStr
109 |      * @memberOf DynamoDB#
110 |      * @param {object} value Binary value (Buffer | Uint8Array) depending on environment.
111 |      * @return {string} Return value will be the string representation of the Binary object.
112 |      * @throws BinConversionError
113 |      */
114 |     service.__proto__.BinToStr = function(value) {
115 |         return t.binToStr(value);
116 |     };
117 | 
118 |     return service;
119 | }
120 | 
121 | if (typeof(module) !== "undefined") {
122 |     var exports = module.exports = {};
123 |     exports.DynamoDB = DynamoDB;
124 | }
125 |  
126 | 
127 |
128 |
129 | 130 | 131 | 132 | 133 |
134 | 135 | 138 | 139 |
140 | 141 |
142 | Documentation generated by JSDoc 3.3.0-alpha9 on Tue Oct 07 2014 18:08:15 GMT-0700 (PDT) 143 |
144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /jsdocs/formatter.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: formatter.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: formatter.js

21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 |
"use strict";
 29 | 
 30 | /**
 31 |  *  Create an instance of the DynamoDBFormatter.
 32 |  *  @constructor
 33 |  *  @return {DynamoDBFormatter} A Formatter object that provides methods for formatting DynamoDB requests and responses.
 34 |  */
 35 | function DynamoDBFormatter() {    
 36 |     var datatypes = typeof(window) === "undefined" ? require("./datatypes").DynamoDBDatatype : window.DynamoDBDatatype;
 37 |     var t = new datatypes();
 38 |     var EmptyConditionArray = "Need to pass in an array with 1 or more Condition Objects.";
 39 |     var BadElementInConditionArray = "Only Condition objects are allowed as members of the array.";
 40 |     var InvalidCondition = "Need to pass in a valid Condition Object.";
 41 | 
 42 |     function formatAttrValInput(attrValueMap) {
 43 |         var attributeValueMap = {};
 44 |         for (var attr in attrValueMap) {
 45 |             var value = attrValueMap[attr];
 46 |             attributeValueMap[attr] = t.formatDataType(value);
 47 |         }
 48 |         return attributeValueMap;
 49 |     }
 50 |     
 51 |     function formatConditions(conditions) {
 52 |         if (conditions.prototype && conditions.prototype.instanceOf === "DynamoDBConditionObject") {
 53 |             conditions = [conditions];
 54 |         } else {
 55 |             if (Array.isArray(conditions)) {
 56 |                 if (conditions.length === 0) {
 57 |                     throw new Error(EmptyConditionArray);
 58 |                 }
 59 |                 for (var index in conditions) {
 60 |                     var condition = conditions[index];
 61 |                     if (!(condition.prototype) || !(condition.prototype.instanceOf === "DynamoDBConditionObject")) {
 62 |                         throw new Error(BadElementInConditionArray);
 63 |                     }
 64 |                 }
 65 |             } else {
 66 |                 throw new Error(InvalidCondition);
 67 |             }
 68 |         }
 69 |     
 70 |         var expected = {};
 71 |         for (var index in conditions) {
 72 |             var condition = conditions[index];
 73 |             expected[condition.key] = condition.format();
 74 |         }
 75 |         return expected;
 76 |     }
 77 |     
 78 |     function formatUpdates(updates) {
 79 |         var attrUpdates = {};
 80 |         for (var attr in updates) {
 81 |             if (updates.hasOwnProperty(attr)) {
 82 |                 var actionValue = {};
 83 |                 var value = updates[attr].Value;
 84 |                 var action = updates[attr].Action;
 85 |     
 86 |                 actionValue.Action = action;
 87 |                 actionValue.Value = t.formatDataType(value);
 88 |     
 89 |                 attrUpdates[attr] = actionValue;
 90 |             }
 91 |         }
 92 |         
 93 |          return attrUpdates;
 94 |     }
 95 |     
 96 |     function handleWriteRequest(request) {
 97 |         var requestCopy = {};
 98 |     
 99 |         if (request.DeleteRequest) {
100 |             var key = request.DeleteRequest.Key;
101 |             requestCopy.DeleteRequest = {};
102 |             requestCopy.DeleteRequest.Key = formatAttrValInput(key);
103 |         } else {
104 |             var item = request.PutRequest.Item;
105 |             requestCopy.PutRequest = {};
106 |             requestCopy.PutRequest.Item = formatAttrValInput(item);
107 |         }
108 |     
109 |         return requestCopy;
110 |     }
111 |     
112 |     function formatRequestItems(requests) {
113 |         var requestItems = {};
114 |     
115 |         for (var table in requests) {
116 |             if (requests.hasOwnProperty(table)) {
117 |                 requestItems[table] = {};
118 |     
119 |                 var request = requests[table];
120 |                 if (Array.isArray(request)) {
121 |                     var writeRequests = [];
122 |                     for (var wIndex in request) {
123 |                         writeRequests.push(handleWriteRequest(request[wIndex]));
124 |                     }
125 |                     requestItems[table] = writeRequests;
126 |                 } else {
127 |                     if (request.AttributesToGet) {
128 |                         requestItems[table].AttributesToGet = request.AttributesToGet;
129 |                     }
130 |                     if (request.ConsistentRead) {
131 |                         requestItems[table].ConsistentRead = request.ConsistentRead;
132 |                     }
133 |                     if (request.Keys) {
134 |                         var keys = [];
135 |                         for (var gIndex in request.Keys) {
136 |                             var key = request.Keys[gIndex];
137 |                             keys.push(formatAttrValInput(key));
138 |                         }
139 |                         requestItems[table].Keys = keys;
140 |                     }
141 |                 }
142 |             }
143 |         }
144 |     
145 |         return requestItems;
146 |     }
147 |     
148 |     var inputMap = { "AttributeUpdates": formatUpdates,
149 |                      "ExclusiveStartKey": formatAttrValInput,
150 |                      "Expected": formatConditions,
151 |                      "ExpressionAttributeValues": formatAttrValInput,
152 |                      "Item": formatAttrValInput,
153 |                      "Key": formatAttrValInput,
154 |                      "KeyConditions": formatConditions,
155 |                      "RequestItems": formatRequestItems,
156 |                      "ScanFilter": formatConditions,
157 |                      "QueryFilter": formatConditions};
158 |     
159 |     
160 |     function formatAttrValOutput(item) {
161 |         var attrList = {};
162 |         for (var attribute in item) {
163 |             var keys = Object.keys(item[attribute]);
164 |             var key = keys[0];
165 |             var value = item[attribute][key];
166 |         
167 |             value = t.formatWireType(key, value); 
168 |             attrList[attribute] = value;
169 |         }
170 |     
171 |         return attrList;
172 |     }
173 |     
174 |     function formatItems(items) {
175 |         for (var index in items) {
176 |             items[index] = formatAttrValOutput(items[index]);
177 |         }
178 |         return items;
179 |     }
180 |     
181 |     function handleCollectionKey(metrics) {
182 |         var collectionKey = metrics.ItemCollectionKey;
183 |         metrics.ItemCollectionKey = formatAttrValOutput(collectionKey);
184 |         return metrics;
185 |     }
186 |     
187 |     function handleBatchMetrics(metrics) {
188 |         for (var table in metrics) {
189 |             if (metrics.hasOwnProperty(table)) {
190 |                 var listOfKeys = metrics[table];
191 |                 for (var index in listOfKeys) {
192 |                     listOfKeys[index] = handleCollectionKey(listOfKeys[index]);
193 |                 }
194 |             }
195 |         }
196 |         return metrics;
197 |     }
198 |     
199 |     function formatMetrics(metrics) {
200 |         var collectionKey = metrics.ItemCollectionKey;
201 |         if (collectionKey) {
202 |             metrics = handleCollectionKey(metrics);
203 |         } else {
204 |             metrics = handleBatchMetrics(metrics);
205 |         }
206 |         return metrics;
207 |     }
208 |     
209 |     function formatResponses(responses) {
210 |         for (var table in responses) {
211 |             if (responses.hasOwnProperty(table)) {
212 |                 var listOfItems = responses[table];
213 |                 for (var index in listOfItems) {
214 |                     listOfItems[index] = formatAttrValOutput(listOfItems[index]);
215 |                 }
216 |             }
217 |         }
218 |     
219 |         return responses;
220 |     }
221 |     
222 |     function formatUnprocessedItems(unprocessedItems) {
223 |         for(var table in unprocessedItems) {
224 |             if (unprocessedItems.hasOwnProperty(table)) {
225 |                 var tableInfo = unprocessedItems[table];
226 |                 for (var index in tableInfo) {
227 |                     var request = tableInfo[index];
228 |                     if (request.DeleteRequest) {
229 |                         tableInfo[index].DeleteRequest.Key = formatAttrValOutput(request.DeleteRequest.Key);
230 |                     } else {
231 |                         tableInfo[index].PutRequest.Item = formatAttrValOutput(request.PutRequest.Item);
232 |                     }
233 |                 }
234 |             }
235 |         }
236 |         return unprocessedItems;
237 |     }
238 |     
239 |     function formatUnprocessedKeys(unprocessedKeys) {
240 |         for (var table in unprocessedKeys) {
241 |             if (unprocessedKeys.hasOwnProperty(table)) {
242 |                 var tableInfo = unprocessedKeys[table];
243 |                 var listOfKeys = tableInfo.Keys;
244 |                 for (var index in listOfKeys) {
245 |                     tableInfo.Keys[index] = formatAttrValOutput(listOfKeys[index]);
246 |                 }
247 |             }
248 |         }
249 |     
250 |         return unprocessedKeys;
251 |     }
252 |     
253 |     /**
254 |      * DynamoDBFormatter specifically for wrapping DynamoDB response objects.
255 |      *
256 |      * @function formatOutput
257 |      * @memberOf DynamoDBFormatter#
258 |      * @params {object} response Response object directly passed out by the service.
259 |      * @returns {object} Wrapped up response object.
260 |      */
261 |     this.formatOutput = function(response) {
262 |         var outputMap = {"Attributes": formatAttrValOutput,
263 |                          "Item": formatAttrValOutput,
264 |                          "Items": formatItems,
265 |                          "ItemCollectionMetrics": formatMetrics,
266 |                          "LastEvaluatedKey": formatAttrValOutput,
267 |                          "Responses": formatResponses,
268 |                          "UnprocessedKeys": formatUnprocessedKeys,
269 |                          "UnprocessedItems": formatUnprocessedItems};
270 |     
271 |     
272 |         var data = response.data;
273 |         if (data) {
274 |             for (var key in data) {
275 |                 if (data.hasOwnProperty(key)) {
276 |                     var formatFunc = outputMap[key];
277 |                     if (formatFunc) {
278 |                         response.data[key] = formatFunc(data[key]);
279 |                     } 
280 |                 }
281 |             }
282 |         }
283 |     };
284 |     
285 |     /**
286 |      * DynamoDBFormatter specifically for unwrapping DynamoDB request objects.
287 |      *
288 |      * @function formatInput
289 |      * @memberOf DynamoDBFormatter#
290 |      * @params {object} request Request object created by the service.
291 |      * @return {object} Returns aws sdk version of the request.
292 |      */
293 |     this.formatInput = function (request) {
294 |         var paramsCopy = {};
295 |         var params = request.params;
296 |     
297 |         for (var key in params) {
298 |             if (params.hasOwnProperty(key)) {
299 |                 var param = params[key];
300 |                 var formatFunc = inputMap[key];
301 |                 if (formatFunc) {
302 |                     param = formatFunc(param);
303 |                 }
304 |                 paramsCopy[key] = param;
305 |             }
306 |         }
307 |     
308 |         request.params = paramsCopy;
309 |     };
310 | }
311 | 
312 | if (typeof(module) !== "undefined") {
313 |     var exports = module.exports = {};
314 |     exports.DynamoDBFormatter = DynamoDBFormatter;
315 | }
316 | 
317 |
318 |
319 | 320 | 321 | 322 | 323 |
324 | 325 | 328 | 329 |
330 | 331 |
332 | Documentation generated by JSDoc 3.3.0-alpha9 on Tue Oct 07 2014 18:08:15 GMT-0700 (PDT) 333 |
334 | 335 | 336 | 337 | 338 | 339 | -------------------------------------------------------------------------------- /jsdocs/global.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Global 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Global

21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 |

30 | 31 |

32 | 33 |
34 | 35 |
36 |
37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 | 71 | 72 | 73 | 74 |
75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 |

Methods

92 | 93 |
94 | 95 |
96 |

DynamoDBCondition(key, operator, val1, val2) → {Condition}

97 | 98 | 99 |
100 |
101 | 102 | 103 |
104 | Creates an instance of Condition that is used by the DynamoDB Document client. 105 |
106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
Parameters:
114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 |
NameTypeDescription
key 142 | 143 | 144 | string 145 | 146 | 147 | 148 | The attribute name being conditioned on.
operator 165 | 166 | 167 | string 168 | 169 | 170 | 171 | The operator in the conditional clause. (See aws sdk docs for full list of operators)
val1 188 | 189 | Potential first element in what would be the AttributeValueList
val2 206 | 207 | Potential second element in what would be the AttributeValueList
219 | 220 | 221 | 222 |
223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 |
Source:
243 |
246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 |
254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 |
Returns:
268 | 269 | 270 |
271 | Condition for your DynamoDB request. 272 |
273 | 274 | 275 | 276 |
277 |
278 | Type 279 |
280 |
281 | 282 | Condition 283 | 284 | 285 |
286 |
287 | 288 | 289 | 290 | 291 |
292 | 293 |
294 | 295 | 296 | 297 | 298 | 299 |
300 | 301 |
302 | 303 | 304 | 305 | 306 |
307 | 308 | 311 | 312 |
313 | 314 |
315 | Documentation generated by JSDoc 3.3.0-alpha9 on Tue Oct 07 2014 18:08:15 GMT-0700 (PDT) 316 |
317 | 318 | 319 | 320 | 321 | -------------------------------------------------------------------------------- /jsdocs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Index 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Index

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |

29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
49 | 50 | 53 | 54 |
55 | 56 |
57 | Documentation generated by JSDoc 3.3.0-alpha9 on Tue Oct 07 2014 18:08:15 GMT-0700 (PDT) 58 |
59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /jsdocs/scripts/linenumber.js: -------------------------------------------------------------------------------- 1 | /*global document */ 2 | (function() { 3 | var source = document.getElementsByClassName('prettyprint source linenums'); 4 | var i = 0; 5 | var lineNumber = 0; 6 | var lineId; 7 | var lines; 8 | var totalLines; 9 | var anchorHash; 10 | 11 | if (source && source[0]) { 12 | anchorHash = document.location.hash.substring(1); 13 | lines = source[0].getElementsByTagName('li'); 14 | totalLines = lines.length; 15 | 16 | for (; i < totalLines; i++) { 17 | lineNumber++; 18 | lineId = 'line' + lineNumber; 19 | lines[i].id = lineId; 20 | if (lineId === anchorHash) { 21 | lines[i].className += ' selected'; 22 | } 23 | } 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /jsdocs/scripts/prettify/Apache-License-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /jsdocs/scripts/prettify/lang-css.js: -------------------------------------------------------------------------------- 1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", 2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /jsdocs/scripts/prettify/prettify.js: -------------------------------------------------------------------------------- 1 | var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; 2 | (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= 3 | [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), 9 | l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, 10 | q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, 11 | q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, 12 | "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), 13 | a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} 14 | for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], 18 | "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], 19 | H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], 20 | J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ 21 | I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), 22 | ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", 23 | /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), 24 | ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", 25 | hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= 26 | !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p p:first-child 320 | { 321 | margin-top: 0; 322 | padding-top: 0; 323 | } 324 | 325 | .params td.description > p:last-child 326 | { 327 | margin-bottom: 0; 328 | padding-bottom: 0; 329 | } 330 | 331 | .disabled { 332 | color: #454545; 333 | } 334 | -------------------------------------------------------------------------------- /jsdocs/styles/prettify-jsdoc.css: -------------------------------------------------------------------------------- 1 | /* JSDoc prettify.js theme */ 2 | 3 | /* plain text */ 4 | .pln { 5 | color: #000000; 6 | font-weight: normal; 7 | font-style: normal; 8 | } 9 | 10 | /* string content */ 11 | .str { 12 | color: #006400; 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | 17 | /* a keyword */ 18 | .kwd { 19 | color: #000000; 20 | font-weight: bold; 21 | font-style: normal; 22 | } 23 | 24 | /* a comment */ 25 | .com { 26 | font-weight: normal; 27 | font-style: italic; 28 | } 29 | 30 | /* a type name */ 31 | .typ { 32 | color: #000000; 33 | font-weight: normal; 34 | font-style: normal; 35 | } 36 | 37 | /* a literal value */ 38 | .lit { 39 | color: #006400; 40 | font-weight: normal; 41 | font-style: normal; 42 | } 43 | 44 | /* punctuation */ 45 | .pun { 46 | color: #000000; 47 | font-weight: bold; 48 | font-style: normal; 49 | } 50 | 51 | /* lisp open bracket */ 52 | .opn { 53 | color: #000000; 54 | font-weight: bold; 55 | font-style: normal; 56 | } 57 | 58 | /* lisp close bracket */ 59 | .clo { 60 | color: #000000; 61 | font-weight: bold; 62 | font-style: normal; 63 | } 64 | 65 | /* a markup tag name */ 66 | .tag { 67 | color: #006400; 68 | font-weight: normal; 69 | font-style: normal; 70 | } 71 | 72 | /* a markup attribute name */ 73 | .atn { 74 | color: #006400; 75 | font-weight: normal; 76 | font-style: normal; 77 | } 78 | 79 | /* a markup attribute value */ 80 | .atv { 81 | color: #006400; 82 | font-weight: normal; 83 | font-style: normal; 84 | } 85 | 86 | /* a declaration */ 87 | .dec { 88 | color: #000000; 89 | font-weight: bold; 90 | font-style: normal; 91 | } 92 | 93 | /* a variable name */ 94 | .var { 95 | color: #000000; 96 | font-weight: normal; 97 | font-style: normal; 98 | } 99 | 100 | /* a function name */ 101 | .fun { 102 | color: #000000; 103 | font-weight: bold; 104 | font-style: normal; 105 | } 106 | 107 | /* Specify class=linenums on a pre to get line numbering */ 108 | ol.linenums { 109 | margin-top: 0; 110 | margin-bottom: 0; 111 | } 112 | -------------------------------------------------------------------------------- /jsdocs/styles/prettify-tomorrow.css: -------------------------------------------------------------------------------- 1 | /* Tomorrow Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* Pretty printing styles. Used with prettify.js. */ 4 | /* SPAN elements with the classes below are added by prettyprint. */ 5 | /* plain text */ 6 | .pln { 7 | color: #4d4d4c; } 8 | 9 | @media screen { 10 | /* string content */ 11 | .str { 12 | color: #718c00; } 13 | 14 | /* a keyword */ 15 | .kwd { 16 | color: #8959a8; } 17 | 18 | /* a comment */ 19 | .com { 20 | color: #8e908c; } 21 | 22 | /* a type name */ 23 | .typ { 24 | color: #4271ae; } 25 | 26 | /* a literal value */ 27 | .lit { 28 | color: #f5871f; } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #4d4d4c; } 33 | 34 | /* lisp open bracket */ 35 | .opn { 36 | color: #4d4d4c; } 37 | 38 | /* lisp close bracket */ 39 | .clo { 40 | color: #4d4d4c; } 41 | 42 | /* a markup tag name */ 43 | .tag { 44 | color: #c82829; } 45 | 46 | /* a markup attribute name */ 47 | .atn { 48 | color: #f5871f; } 49 | 50 | /* a markup attribute value */ 51 | .atv { 52 | color: #3e999f; } 53 | 54 | /* a declaration */ 55 | .dec { 56 | color: #f5871f; } 57 | 58 | /* a variable name */ 59 | .var { 60 | color: #c82829; } 61 | 62 | /* a function name */ 63 | .fun { 64 | color: #4271ae; } } 65 | /* Use higher contrast and text-weight for printable form. */ 66 | @media print, projection { 67 | .str { 68 | color: #060; } 69 | 70 | .kwd { 71 | color: #006; 72 | font-weight: bold; } 73 | 74 | .com { 75 | color: #600; 76 | font-style: italic; } 77 | 78 | .typ { 79 | color: #404; 80 | font-weight: bold; } 81 | 82 | .lit { 83 | color: #044; } 84 | 85 | .pun, .opn, .clo { 86 | color: #440; } 87 | 88 | .tag { 89 | color: #006; 90 | font-weight: bold; } 91 | 92 | .atn { 93 | color: #404; } 94 | 95 | .atv { 96 | color: #060; } } 97 | /* Style */ 98 | /* 99 | pre.prettyprint { 100 | background: white; 101 | font-family: Menlo, Monaco, Consolas, monospace; 102 | font-size: 12px; 103 | line-height: 1.5; 104 | border: 1px solid #ccc; 105 | padding: 10px; } 106 | */ 107 | 108 | /* Specify class=linenums on a pre to get line numbering */ 109 | ol.linenums { 110 | margin-top: 0; 111 | margin-bottom: 0; } 112 | 113 | /* IE indents via margin-left */ 114 | li.L0, 115 | li.L1, 116 | li.L2, 117 | li.L3, 118 | li.L4, 119 | li.L5, 120 | li.L6, 121 | li.L7, 122 | li.L8, 123 | li.L9 { 124 | /* */ } 125 | 126 | /* Alternate shading for lines */ 127 | li.L1, 128 | li.L3, 129 | li.L5, 130 | li.L7, 131 | li.L9 { 132 | /* */ } 133 | -------------------------------------------------------------------------------- /lib/condition.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Creates an instance of Condition that is used by the DynamoDB Document client. 5 | * 6 | * @param {string} key The attribute name being conditioned on. 7 | * @param {string} operator The operator in the conditional clause. (See aws sdk docs for full list of operators) 8 | * @param val Potential nd element in what would be the AttributeValueList (optional) 9 | * @return {Condition} Condition for your DynamoDB request. 10 | */ 11 | function DynamoDBCondition(key, operator) { /* and variable arguments. */ 12 | var datatypes = typeof(window) === "undefined" ? require("./datatypes").DynamoDBDatatype 13 | : window.DynamoDBDatatype; 14 | 15 | var t = new datatypes(); 16 | 17 | var args = Array.prototype.slice.call(arguments, 2); 18 | 19 | var CondObj = function Condition(key, operator, args) { 20 | this.key = key; 21 | this.operator = operator; 22 | this.args = args; 23 | 24 | // for comatibility 25 | this.val1 = args[0]; 26 | this.val2 = args[1]; 27 | 28 | this.format = function() { 29 | var formatted = {}; 30 | var attrValueList = []; 31 | 32 | for (var i=0; i 0) { 38 | formatted.AttributeValueList = attrValueList; 39 | } 40 | formatted.ComparisonOperator = this.operator; 41 | 42 | return formatted; 43 | }; 44 | }; 45 | 46 | var cond = new CondObj(key, operator, args); 47 | cond.prototype = Object.create(Object.prototype); 48 | cond.prototype.instanceOf = "DynamoDBConditionObject"; 49 | 50 | return cond; 51 | } 52 | 53 | if (typeof(module) !== "undefined") { 54 | var exports = module.exports = {}; 55 | exports.DynamoDBCondition = DynamoDBCondition; 56 | } 57 | -------------------------------------------------------------------------------- /lib/datatypes.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * @class Creates a DynamoDBDatatype that takes care of all datatype handling. 5 | * 6 | * @name DynamoDBDatatype 7 | */ 8 | function DynamoDBDatatype() { 9 | var AWS = typeof(window) === "undefined" ? require("aws-sdk") : window.AWS; 10 | var Uint8ArrayError = "Uint8Array can only be used for Binary in Browser."; 11 | var ScalarDatatypeError = "Unrecognized Scalar Datatype to be formatted."; 12 | var GeneralDatatypeError = "Unrecognized Datatype to be formatted."; 13 | var BinConversionError = "Need to pass in Buffer or Uint8Array. "; 14 | var StrConversionError = "Need to pass in string primitive to be converted to binary."; 15 | 16 | function isScalarType(dataType) { 17 | 18 | var type = typeof(dataType); 19 | return type === "number" || 20 | type === "string" || 21 | type === "boolean" || 22 | (dataType instanceof(Uint8Array) && AWS.util.isBrowser()) || 23 | dataType instanceof(AWS.util.Buffer) || 24 | dataType === null; 25 | } 26 | 27 | function isSetType(dataType) { 28 | return dataType.datatype === "SS" || 29 | dataType.datatype === "NS" || 30 | dataType.datatype === "BS"; 31 | } 32 | 33 | function isRecursiveType(dataType) { 34 | 35 | return Array.isArray(dataType) || 36 | typeof(dataType) === "object"; 37 | } 38 | 39 | function formatSetValues(datatype, values) { 40 | if(datatype === "NS") { 41 | return values.map(function (n) { 42 | return n.toString(); 43 | }); 44 | } else { 45 | return values; 46 | } 47 | }; 48 | 49 | function formatRecursiveType(dataType) { 50 | 51 | var recursiveDoc = {}; 52 | 53 | var value = {}; 54 | var type = "M"; 55 | if (Array.isArray(dataType)) { 56 | value = []; 57 | type = "L"; 58 | for (var index = 0; index < dataType.length; index++) { 59 | value[index] = this.formatDataType(dataType[index]); 60 | } 61 | } else { 62 | for (var key in dataType) { 63 | value[key] = this.formatDataType(dataType[key]); 64 | } 65 | } 66 | 67 | recursiveDoc[type] = value; 68 | return recursiveDoc; 69 | } 70 | 71 | /** @throws Uint8ArrayError, ScalarDatatypeError 72 | * @private */ 73 | function formatScalarType(dataType) { 74 | 75 | if (dataType == null) { 76 | return { "NULL" : true }; 77 | } 78 | 79 | var type = typeof(dataType); 80 | if (type === "string") { 81 | return { "S" : dataType }; 82 | } else if (type === "number") { 83 | return { "N" : String(dataType) }; 84 | } else if (type === "boolean") { 85 | return { "BOOL" : dataType }; 86 | } else if (dataType instanceof(AWS.util.Buffer)) { 87 | return { "B" : dataType }; 88 | } else if (dataType instanceof(Uint8Array)) { 89 | if (AWS.util.isBrowser()) { 90 | return { "B" : dataType }; 91 | } else { 92 | throw new Error(Uint8ArrayError); 93 | } 94 | } else { 95 | throw new Error(ScalarDatatypeError); 96 | } 97 | } 98 | 99 | /** 100 | * Formats Javascript datatypes into DynamoDB wire format. 101 | * 102 | * @name formatDataType 103 | * @function 104 | * @memberOf DynamoDBDatatype# 105 | * @param dataType Javascript datatype (i.e. string, number. For full information, check out the README). 106 | * @return {object} DynamoDB JSON-like wire format. 107 | * @throws GeneralDatatypeError 108 | */ 109 | this.formatDataType = function(dataType) { 110 | 111 | if (typeof(dataType) === "undefined") { 112 | return undefined; 113 | } else if (isScalarType(dataType)) { 114 | return formatScalarType(dataType); 115 | } else if (isSetType(dataType)) { 116 | return dataType.format(); 117 | } else if (isRecursiveType(dataType)) { 118 | return formatRecursiveType.call(this, dataType); 119 | } else { 120 | throw new Error(GeneralDatatypeError); 121 | } 122 | 123 | }; 124 | 125 | function str2Bin(value) { 126 | if (typeof(value) !== "string") { 127 | throw new Error(StrConversionError); 128 | } 129 | 130 | if (AWS.util.isBrowser()) { 131 | var len = value.length; 132 | var bin = new Uint8Array(new ArrayBuffer(len)); 133 | for (var i = 0; i < len; i++) { 134 | bin[i] = value.charCodeAt(i); 135 | } 136 | return bin; 137 | } else { 138 | return AWS.util.Buffer(value); 139 | } 140 | } 141 | 142 | /** 143 | * Utility to convert a String to a Binary object. 144 | * 145 | * @function strToBin 146 | * @memberOf DynamoDBDatatype# 147 | * @param {string} value String value to converted to Binary object. 148 | * @return {object} (Buffer | Uint8Array) depending on Node or browser. 149 | * @throws StrConversionError 150 | */ 151 | this.strToBin = function(value) { 152 | return str2Bin.call(this, value); 153 | }; 154 | 155 | function bin2Str(value) { 156 | if (!(value instanceof(AWS.util.Buffer)) && !(value instanceof(Uint8Array))) { 157 | throw new Error(BinConversionError); 158 | } 159 | 160 | if (AWS.util.isBrowser()) { 161 | return String.fromCharCode.apply(null, value); 162 | } else { 163 | return value.toString("utf-8").valueOf(); 164 | } 165 | } 166 | 167 | /** 168 | * Utility to convert a Binary object into a decoded String. 169 | * 170 | * @function binToStr 171 | * @memberOf DynamoDBDatatype# 172 | * @param {object} value Binary value (Buffer | Uint8Array) depending on Node or browser. 173 | * @return {string} decoded String in UTF-8 174 | * @throws BinConversionError 175 | */ 176 | this.binToStr = function(value) { 177 | return bin2Str.call(this, value); 178 | }; 179 | 180 | /** 181 | * Utility to create the DynamoDB Set Datatype. 182 | * 183 | * @function createSet 184 | * @memberOf DynamoDBDatatype# 185 | * @param {array} set An array that contains elements of the same typed as defined by {type}. 186 | * @param {string} type Can only be a [S]tring, [N]umber, or [B]inary type. 187 | * @return {Set} Custom Set object that follow {type}. 188 | * @throws InvalidSetType, InconsistentType 189 | */ 190 | this.createSet = function(set, type) { 191 | if (type !== "N" && type !== "S" && type !== "B") { 192 | throw new Error(type + " is an invalid type for Set"); 193 | } 194 | 195 | var setObj = function Set(set, type) { 196 | this.datatype = type + "S"; 197 | this.contents = {}; 198 | 199 | this.add = function(value) { 200 | if (this.datatype === "SS" && typeof(value) === "string") { 201 | this.contents[value] = value; 202 | } else if (this.datatype === "NS" && typeof(value) === "number") { 203 | this.contents[value] = value; 204 | } else if (this.datatype === "BS" && value instanceof(AWS.util.Buffer)) { 205 | this.contents[bin2Str(value)] = value; 206 | } else if (this.datatype === "BS" && value instanceof(Uint8Array)) { 207 | if (AWS.util.isBrowser()) { 208 | this.contents[bin2Str(value)] = value; 209 | } else { 210 | throw new Error(Uint8ArrayError); 211 | } 212 | } else { 213 | throw new Error("Inconsistent in this " + type + " Set"); 214 | } 215 | }; 216 | 217 | this.contains = function(content) { 218 | var value = content; 219 | if (content instanceof AWS.util.Buffer || content instanceof(Uint8Array)) { 220 | value = bin2Str(content); 221 | } 222 | if (this.contents[value] === undefined) { 223 | return false; 224 | } 225 | return true; 226 | }; 227 | 228 | this.remove = function(content) { 229 | var value = content; 230 | if (content instanceof AWS.util.Buffer || content instanceof(Uint8Array)) { 231 | value = bin2Str(content); 232 | } 233 | delete this.contents[value]; 234 | }; 235 | 236 | this.toArray = function() { 237 | var keys = Object.keys(this.contents); 238 | var arr = []; 239 | 240 | for (var keyIndex in keys) { 241 | var key = keys[keyIndex]; 242 | if (this.contents.hasOwnProperty(key)) { 243 | arr.push(this.contents[key]); 244 | } 245 | } 246 | 247 | return arr; 248 | }; 249 | 250 | this.format = function() { 251 | var values = this.toArray(); 252 | var result = {}; 253 | result[this.datatype] = formatSetValues(this.datatype, values); 254 | return result; 255 | }; 256 | 257 | if (set) { 258 | for (var index in set) { 259 | this.add(set[index]); 260 | } 261 | } 262 | }; 263 | 264 | return new setObj(set, type); 265 | }; 266 | 267 | /** 268 | * Formats DynamoDB wire format into javascript datatypes. 269 | * 270 | * @name formatWireType 271 | * @function 272 | * @memberOf DynamoDBDatatype# 273 | * @param {string} key Key that represents the type of the attribute value 274 | * @param value Javascript datatype of the attribute value produced by DynamoDB 275 | * @throws GeneralDatatypeError 276 | */ 277 | this.formatWireType = function(key, value) { 278 | switch (key) { 279 | case "S": 280 | case "B": 281 | case "BOOL": 282 | return value; 283 | case "N": 284 | return Number(value); 285 | case "NULL": 286 | return null; 287 | case "L": 288 | for (var lIndex = 0; lIndex < value.length; lIndex++) { 289 | var lValue = value[lIndex]; 290 | var lKey = Object.keys(lValue)[0]; 291 | value[lIndex] = this.formatWireType(lKey, lValue[lKey]); 292 | } 293 | return value; 294 | case "M": 295 | for (var mIndex in value) { 296 | var mValue = value[mIndex]; 297 | var mKey = Object.keys(mValue)[0]; 298 | value[mIndex] = this.formatWireType(mKey, mValue[mKey]); 299 | } 300 | return value; 301 | case "SS": 302 | return new this.createSet(value, "S"); 303 | case "NS": 304 | value = value.map(function(each) { return Number(each);}); 305 | return new this.createSet(value, "N"); 306 | case "BS": 307 | return new this.createSet(value, "B"); 308 | default: 309 | throw "Service returned unrecognized datatype " + key; 310 | } 311 | } 312 | } 313 | 314 | if (typeof(module) !== "undefined") { 315 | var exports = module.exports = {}; 316 | exports.DynamoDBDatatype = DynamoDBDatatype; 317 | } 318 | -------------------------------------------------------------------------------- /lib/dynamodb-doc.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Create an instance of the DynamoDB Document client. 5 | * 6 | * @constructor 7 | * @class DynamoDB 8 | * @param {AWS.DynamoDB} dynamoDB An instance of the service provided AWS SDK (optional). 9 | * @returns {DynamoDB} Modified version of the service for Document support. 10 | */ 11 | function DynamoDB(dynamoDB) { 12 | var isBrowser = typeof(window) === "undefined"; 13 | var AWS = isBrowser ? require("aws-sdk") : window.AWS; 14 | 15 | var condition = isBrowser ? require("./condition").DynamoDBCondition : window.DynamoDBCondition; 16 | 17 | var datatypes = isBrowser ? require("./datatypes").DynamoDBDatatype : window.DynamoDBDatatype; 18 | var t = new datatypes(); 19 | 20 | var formatter = isBrowser ? require("./formatter").DynamoDBFormatter : window.DynamoDBFormatter; 21 | var f = new formatter(); 22 | 23 | var service = dynamoDB || new AWS.DynamoDB(); 24 | 25 | var setupLowLevelRequestListeners = service.setupRequestListeners; 26 | service.setupRequestListeners = function(request) { 27 | setupLowLevelRequestListeners.call(this, request); 28 | 29 | request._events.validate.unshift(f.formatInput); 30 | request.on("build", f.setCustomAgent) 31 | request.on("extractData", f.formatOutput); 32 | }; 33 | 34 | /** 35 | * Utility to create Set Object for requests. 36 | * 37 | * @function Set 38 | * @memberOf DynamoDB# 39 | * @param {array} set An array that contains elements of the same typed as defined by {type}. 40 | * @param {string} type Can only be a [S]tring, [N]umber, or [B]inary type. 41 | * @return {Set} Custom Set object that follow {type}. 42 | * @throws InvalidSetType, InconsistentType 43 | */ 44 | service.__proto__.Set = function(set, type) { 45 | return t.createSet(set, type); 46 | }; 47 | 48 | /** 49 | * Creates an instance of Condition and should be used with the DynamoDB client. 50 | * 51 | * @function Condition 52 | * @memberOf DynamoDB# 53 | * @param {string} key The attribute name being conditioned. 54 | * @param {string} operator The operator in the conditional clause. (See lower level docs for full list of operators) 55 | * @param val1 Potential first element in what would be the AttributeValueList 56 | * @param val* Potential *nd element in what would be the AttributeValueList (optional) 57 | * @return {Condition} Condition for your DynamoDB request. 58 | */ 59 | service.__proto__.Condition = function(/*key, operator, val1, val2, ...*/) { 60 | return condition.apply(this, arguments); 61 | }; 62 | 63 | /** 64 | * Utility to convert a String to the necessary Binary object. 65 | * 66 | * @function StrToBin 67 | * @memberOf DynamoDB# 68 | * @param {string} value String value to converted to Binary object. 69 | * @return {object} Return value will be a Buffer or Uint8Array in the browser. 70 | * @throws StrConversionError 71 | */ 72 | service.__proto__.StrToBin = function(value) { 73 | return t.strToBin(value); 74 | }; 75 | /** 76 | * Utility to convert a Binary object into its String equivalent. 77 | * 78 | * @function BinToStr 79 | * @memberOf DynamoDB# 80 | * @param {object} value Binary value (Buffer | Uint8Array) depending on environment. 81 | * @return {string} Return value will be the string representation of the Binary object. 82 | * @throws BinConversionError 83 | */ 84 | service.__proto__.BinToStr = function(value) { 85 | return t.binToStr(value); 86 | }; 87 | 88 | return service; 89 | } 90 | 91 | if (typeof(module) !== "undefined") { 92 | var exports = module.exports = {}; 93 | exports.DynamoDB = DynamoDB; 94 | } 95 | 96 | -------------------------------------------------------------------------------- /lib/formatter.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Create an instance of the DynamoDBFormatter. 5 | * @constructor 6 | * @return {DynamoDBFormatter} A Formatter object that provides methods for formatting DynamoDB requests and responses. 7 | */ 8 | function DynamoDBFormatter() { 9 | var datatypes = typeof(window) === "undefined" ? require("./datatypes").DynamoDBDatatype : window.DynamoDBDatatype; 10 | var t = new datatypes(); 11 | var EmptyConditionArray = "Need to pass in an array with 1 or more Condition Objects."; 12 | var BadElementInConditionArray = "Only Condition objects are allowed as members of the array."; 13 | var InvalidCondition = "Need to pass in a valid Condition Object."; 14 | 15 | this.setCustomAgent = function (request) { 16 | var isBrowser = typeof(window) === "undefined"; 17 | var prefix = isBrowser ? "" : "X-Amz-"; 18 | var sdk = isBrowser ? "nodejs" : "js"; 19 | var currentHeader = request.httpRequest.headers[prefix + 'User-Agent']; 20 | request.httpRequest.headers[prefix + 'User-Agent'] = currentHeader + "/document-sdk-" + sdk; 21 | } 22 | 23 | function formatAttrValInput(attrValueMap) { 24 | var attributeValueMap = {}; 25 | for (var attr in attrValueMap) { 26 | var value = attrValueMap[attr]; 27 | attributeValueMap[attr] = t.formatDataType(value); 28 | } 29 | return attributeValueMap; 30 | } 31 | 32 | function formatConditions(conditions) { 33 | if (conditions.prototype && conditions.prototype.instanceOf === "DynamoDBConditionObject") { 34 | conditions = [conditions]; 35 | } else { 36 | if (Array.isArray(conditions)) { 37 | if (conditions.length === 0) { 38 | throw new Error(EmptyConditionArray); 39 | } 40 | for (var index = 0; index < conditions.length; index++) { 41 | var condition = conditions[index]; 42 | if (!(condition.prototype) || !(condition.prototype.instanceOf === "DynamoDBConditionObject")) { 43 | throw new Error(BadElementInConditionArray); 44 | } 45 | } 46 | } else { 47 | throw new Error(InvalidCondition); 48 | } 49 | } 50 | 51 | var expected = {}; 52 | for (var index = 0; index < conditions.length; index++) { 53 | var condition = conditions[index]; 54 | expected[condition.key] = condition.format(); 55 | } 56 | return expected; 57 | } 58 | 59 | function formatUpdates(updates) { 60 | var attrUpdates = {}; 61 | for (var attr in updates) { 62 | if (updates.hasOwnProperty(attr)) { 63 | var actionValue = {}; 64 | var value = updates[attr].Value; 65 | var action = updates[attr].Action; 66 | 67 | actionValue.Action = action; 68 | if (value !== undefined) { 69 | actionValue.Value = t.formatDataType(value); 70 | } 71 | attrUpdates[attr] = actionValue; 72 | } 73 | } 74 | 75 | return attrUpdates; 76 | } 77 | 78 | function handleWriteRequest(request) { 79 | var requestCopy = {}; 80 | 81 | if (request.DeleteRequest) { 82 | var key = request.DeleteRequest.Key; 83 | requestCopy.DeleteRequest = {}; 84 | requestCopy.DeleteRequest.Key = formatAttrValInput(key); 85 | } else { 86 | var item = request.PutRequest.Item; 87 | requestCopy.PutRequest = {}; 88 | requestCopy.PutRequest.Item = formatAttrValInput(item); 89 | } 90 | 91 | return requestCopy; 92 | } 93 | 94 | function formatRequestItems(requests) { 95 | var requestItems = {}; 96 | 97 | for (var table in requests) { 98 | if (requests.hasOwnProperty(table)) { 99 | requestItems[table] = {}; 100 | 101 | var request = requests[table]; 102 | if (Array.isArray(request)) { 103 | var writeRequests = []; 104 | for (var wIndex in request) { 105 | writeRequests.push(handleWriteRequest(request[wIndex])); 106 | } 107 | requestItems[table] = writeRequests; 108 | } else { 109 | if (request.AttributesToGet) { 110 | requestItems[table].AttributesToGet = request.AttributesToGet; 111 | } 112 | if (request.ConsistentRead) { 113 | requestItems[table].ConsistentRead = request.ConsistentRead; 114 | } 115 | if (request.ProjectionExpression) { 116 | requestItems[table].ProjectionExpression = request.ProjectionExpression; 117 | } 118 | if (request.ExpressionAttributeNames) { 119 | requestItems[table].ExpressionAttributeNames = request.ExpressionAttributeNames; 120 | } 121 | if (request.Keys) { 122 | var keys = []; 123 | for (var gIndex in request.Keys) { 124 | var key = request.Keys[gIndex]; 125 | keys.push(formatAttrValInput(key)); 126 | } 127 | requestItems[table].Keys = keys; 128 | } 129 | } 130 | } 131 | } 132 | 133 | return requestItems; 134 | } 135 | 136 | var inputMap = { "AttributeUpdates": formatUpdates, 137 | "ExclusiveStartKey": formatAttrValInput, 138 | "Expected": formatConditions, 139 | "ExpressionAttributeValues": formatAttrValInput, 140 | "Item": formatAttrValInput, 141 | "Key": formatAttrValInput, 142 | "KeyConditions": formatConditions, 143 | "RequestItems": formatRequestItems, 144 | "ScanFilter": formatConditions, 145 | "QueryFilter": formatConditions}; 146 | 147 | 148 | function formatAttrValOutput(item) { 149 | var attrList = {}; 150 | for (var attribute in item) { 151 | var keys = Object.keys(item[attribute]); 152 | var key = keys[0]; 153 | var value = item[attribute][key]; 154 | 155 | value = t.formatWireType(key, value); 156 | attrList[attribute] = value; 157 | } 158 | 159 | return attrList; 160 | } 161 | 162 | function formatItems(items) { 163 | for (var index in items) { 164 | items[index] = formatAttrValOutput(items[index]); 165 | } 166 | return items; 167 | } 168 | 169 | function handleCollectionKey(metrics) { 170 | var collectionKey = metrics.ItemCollectionKey; 171 | metrics.ItemCollectionKey = formatAttrValOutput(collectionKey); 172 | return metrics; 173 | } 174 | 175 | function handleBatchMetrics(metrics) { 176 | for (var table in metrics) { 177 | if (metrics.hasOwnProperty(table)) { 178 | var listOfKeys = metrics[table]; 179 | for (var index in listOfKeys) { 180 | listOfKeys[index] = handleCollectionKey(listOfKeys[index]); 181 | } 182 | } 183 | } 184 | return metrics; 185 | } 186 | 187 | function formatMetrics(metrics) { 188 | var collectionKey = metrics.ItemCollectionKey; 189 | if (collectionKey) { 190 | metrics = handleCollectionKey(metrics); 191 | } else { 192 | metrics = handleBatchMetrics(metrics); 193 | } 194 | return metrics; 195 | } 196 | 197 | function formatResponses(responses) { 198 | for (var table in responses) { 199 | if (responses.hasOwnProperty(table)) { 200 | var listOfItems = responses[table]; 201 | for (var index in listOfItems) { 202 | listOfItems[index] = formatAttrValOutput(listOfItems[index]); 203 | } 204 | } 205 | } 206 | 207 | return responses; 208 | } 209 | 210 | function formatUnprocessedItems(unprocessedItems) { 211 | for(var table in unprocessedItems) { 212 | if (unprocessedItems.hasOwnProperty(table)) { 213 | var tableInfo = unprocessedItems[table]; 214 | for (var index in tableInfo) { 215 | var request = tableInfo[index]; 216 | if (request.DeleteRequest) { 217 | tableInfo[index].DeleteRequest.Key = formatAttrValOutput(request.DeleteRequest.Key); 218 | } else { 219 | tableInfo[index].PutRequest.Item = formatAttrValOutput(request.PutRequest.Item); 220 | } 221 | } 222 | } 223 | } 224 | return unprocessedItems; 225 | } 226 | 227 | function formatUnprocessedKeys(unprocessedKeys) { 228 | for (var table in unprocessedKeys) { 229 | if (unprocessedKeys.hasOwnProperty(table)) { 230 | var tableInfo = unprocessedKeys[table]; 231 | var listOfKeys = tableInfo.Keys; 232 | for (var index in listOfKeys) { 233 | tableInfo.Keys[index] = formatAttrValOutput(listOfKeys[index]); 234 | } 235 | } 236 | } 237 | 238 | return unprocessedKeys; 239 | } 240 | 241 | /** 242 | * DynamoDBFormatter specifically for wrapping DynamoDB response objects. 243 | * 244 | * @function formatOutput 245 | * @memberOf DynamoDBFormatter# 246 | * @params {object} response Response object directly passed out by the service. 247 | * @returns {object} Wrapped up response object. 248 | */ 249 | this.formatOutput = function(response) { 250 | var outputMap = {"Attributes": formatAttrValOutput, 251 | "Item": formatAttrValOutput, 252 | "Items": formatItems, 253 | "ItemCollectionMetrics": formatMetrics, 254 | "LastEvaluatedKey": formatAttrValOutput, 255 | "Responses": formatResponses, 256 | "UnprocessedKeys": formatUnprocessedKeys, 257 | "UnprocessedItems": formatUnprocessedItems}; 258 | 259 | 260 | var data = response.data; 261 | if (data) { 262 | for (var key in data) { 263 | if (data.hasOwnProperty(key)) { 264 | var formatFunc = outputMap[key]; 265 | if (formatFunc) { 266 | response.data[key] = formatFunc(data[key]); 267 | } 268 | } 269 | } 270 | } 271 | }; 272 | 273 | /** 274 | * DynamoDBFormatter specifically for unwrapping DynamoDB request objects. 275 | * 276 | * @function formatInput 277 | * @memberOf DynamoDBFormatter# 278 | * @params {object} request Request object created by the service. 279 | * @return {object} Returns aws sdk version of the request. 280 | */ 281 | this.formatInput = function (request) { 282 | var paramsCopy = {}; 283 | var params = request.params; 284 | 285 | for (var key in params) { 286 | if (params.hasOwnProperty(key)) { 287 | var param = params[key]; 288 | var formatFunc = inputMap[key]; 289 | if (formatFunc) { 290 | param = formatFunc(param); 291 | } 292 | paramsCopy[key] = param; 293 | } 294 | } 295 | 296 | request.params = paramsCopy; 297 | }; 298 | } 299 | 300 | if (typeof(module) !== "undefined") { 301 | var exports = module.exports = {}; 302 | exports.DynamoDBFormatter = DynamoDBFormatter; 303 | } 304 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dynamodb-doc", 3 | "description": "DynamoDB Document SDK for Javascript", 4 | "version": "1.0.0", 5 | "author": { 6 | "name": "Amazon Web Services", 7 | "email": "", 8 | "url": "http://aws.amazon.com/" 9 | }, 10 | "homepage": "https://github.com/awslabs/dynamodb-document-js-sdk", 11 | "contributors": [ 12 | "Raymond Lin ", 13 | "Loren Segal " 14 | ], 15 | "devDependencies": { 16 | "chai": "^1.10.0", 17 | "mocha": "^1.21.0", 18 | "uglify-js": ">=2.6.0" 19 | }, 20 | "dependencies": { 21 | "aws-sdk": "^2.0.19" 22 | }, 23 | "main": "lib/dynamodb-doc.js", 24 | "directories": { 25 | "lib": "lib" 26 | }, 27 | "engines": { 28 | "node": ">= 0.8.0" 29 | }, 30 | "repository": { 31 | "type": "git", 32 | "url": "git://github.com/awslabs/dynamodb-document-js-sdk" 33 | }, 34 | "licenses": [ 35 | { 36 | "type": "Apache 2.0", 37 | "url": "https://github.com/awslabs/dynamodb-document-js-sdk/blob/master/LICENSE.txt" 38 | } 39 | ], 40 | "keywords": [ 41 | "dynamodb", 42 | "document", 43 | "js", 44 | "javascript", 45 | "sdk" 46 | ], 47 | "scripts": { 48 | "test": "mocha test" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/condition.js: -------------------------------------------------------------------------------- 1 | var assert = require("assert"); 2 | var cond = require("../lib/condition"); 3 | 4 | describe("Testing Condition", function() { 5 | "use strict"; 6 | var existCond = new cond.DynamoDBCondition("Name", "NOT_NULL"); 7 | var binOpCond = new cond.DynamoDBCondition("Age", "GE", 18); 8 | var btwnCond = new cond.DynamoDBCondition("Weight", "BETWEEN", 150, 170); 9 | 10 | describe("Testing Condition.[key, operator, val1, val2]", function () { 11 | var key = "Weight"; 12 | var op = "BETWEEN"; 13 | var val1 = 150; 14 | var val2 = 170; 15 | 16 | it("Testing on btwnCond", function() { 17 | assert.equal(key, btwnCond.key, "Did not find correct btwnCond.key value"); 18 | assert.equal(op, btwnCond.operator, "Did not find correct btwnCond.operator value"); 19 | assert.equal(val1, btwnCond.val1, "Did not find correct btwnCond.val1 value"); 20 | assert.equal(val2, btwnCond.val2, "Did not find correct btwnCond.val2 value"); 21 | }); 22 | }); 23 | 24 | describe("Testing existCond", function() { 25 | var formatExist = {"ComparisonOperator" : "NOT_NULL"}; 26 | it("Testing format()", function() { 27 | assert.deepEqual(formatExist, existCond.format(), "Format of existCond is incorrect."); 28 | }); 29 | }); 30 | 31 | describe("Testing binOpCond", function() { 32 | var formatBinOp = {"AttributeValueList" : [{"N": "18"}], 33 | "ComparisonOperator" : "GE"}; 34 | it("Testing format()", function() { 35 | assert.deepEqual(formatBinOp, binOpCond.format(), "Format of binOpCond is incorrect."); 36 | }); 37 | }); 38 | 39 | describe("Testing btwnCond", function() { 40 | var formatBtwn = {"AttributeValueList" : [{"N": "150"}, {"N": "170"}], 41 | "ComparisonOperator" : "BETWEEN"}; 42 | it("Testing format()", function() { 43 | assert.deepEqual(formatBtwn, btwnCond.format(), "Format of btwnCond is incorrect."); 44 | }); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /test/datatypes.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var assert = require("assert"); 3 | var expect = require("chai").expect; 4 | var datatypes = require("../lib/datatypes").DynamoDBDatatype; 5 | var t = new datatypes(); 6 | 7 | describe("Testing DataTypes", function() { 8 | describe('Testing undefined dataType', function() { 9 | it("should be undefined", function() { 10 | assert.equal("undefined", typeof(t.formatDataType(undefined))); 11 | }); 12 | }); 13 | 14 | describe("Testing Bin to Str Conversion", function() { 15 | 16 | it("with some alphanumeric string in Buffer", function() { 17 | var bin = new Buffer("q1w2e3r4"); 18 | assert.equal("q1w2e3r4", t.binToStr(bin), "Did not convert Bin to Str properly."); 19 | }); 20 | 21 | it("with some special characters in Buffer", function() { 22 | var bin = new Buffer("q1-w2-e3.mp4"); 23 | assert.equal("q1-w2-e3.mp4", t.binToStr(bin), "Did not convert Bin to Str properly."); 24 | }); 25 | }); 26 | 27 | describe("Testing Str to Bin Conversion", function() { 28 | 29 | it("with some alphanumeric string", function() { 30 | var str = "1q2w3e4r"; 31 | assert.deepEqual(new Buffer(str), t.strToBin(str), "Did not convert Str to Bin properly."); 32 | }); 33 | 34 | it("with some special characters in Buffer", function() { 35 | var str = "q1-w2-e3.mp4"; 36 | assert.deepEqual(new Buffer(str), t.strToBin(str), "Did not convert Str to Bin properly."); 37 | }); 38 | }); 39 | 40 | describe("Testing createSet", function() { 41 | var testStrSet; 42 | var testNumSet; 43 | var testBinSet; 44 | 45 | it("with an invalid type.", function() { 46 | assert.throws(function() { t.createSet([], "INVALID")}, Error); 47 | }); 48 | 49 | it("as a StrSet.", function() { 50 | testStrSet = t.createSet(["a", "b", "c"], "S"); 51 | assert(testStrSet, "Did not successfully create a StrSet."); 52 | }); 53 | 54 | it("as a NumSet.", function() { 55 | testNumSet = t.createSet([1, 2, 3], "N"); 56 | assert(testNumSet, "Did not successfully create a NumSet."); 57 | }); 58 | 59 | it("as a BinSet.", function() { 60 | testBinSet = t.createSet([new Buffer("10"), new Buffer("01")], "B"); 61 | assert(testBinSet, "Did not successfully create a BinSet."); 62 | }); 63 | 64 | it("with inconsistent Attribute.", function() { 65 | assert.throws(function() { t.createSet([2], "S"); }, Error); 66 | }); 67 | 68 | describe("with the methods of the Set", function() { 69 | describe("test add", function() { 70 | it ("with duplicate value.", function() { 71 | var initial_length = testStrSet.toArray().length; 72 | testStrSet.add("a"); 73 | var modified_length = testStrSet.toArray().length; 74 | assert.equal(initial_length, modified_length); 75 | }); 76 | 77 | it("with unique value.", function() { 78 | var initial_length = testStrSet.toArray().length; 79 | testStrSet.add("d"); 80 | var modified_length = testStrSet.toArray().length; 81 | assert.equal(initial_length+1, modified_length); 82 | 83 | }); 84 | }); 85 | 86 | it("test contains.", function() { 87 | assert.equal(true, testBinSet.contains(new Buffer("10"))); 88 | assert.equal(false, testNumSet.contains(4)); 89 | }); 90 | 91 | it("toArray().", function() { 92 | var expectedSet = [1,2,3]; 93 | assert.deepEqual(expectedSet, testNumSet.toArray()); 94 | }); 95 | 96 | it("remove.", function() { 97 | var expectedSet = [new Buffer("10")]; 98 | testBinSet.remove(new Buffer("01")); 99 | assert.deepEqual(expectedSet, testBinSet.toArray()); 100 | }); 101 | }); 102 | 103 | }); 104 | 105 | describe('Testing createSet #format', function () { 106 | it("as a StringSet.", function() { 107 | var stringSet = t.createSet(["a", "b", "c"], "S"); 108 | // nodejs built in assert deep equals does not do strict equality 109 | expect(stringSet.format()).to.eql({SS : ["a", "b", "c"]}); 110 | }); 111 | 112 | it("as a NumSet.", function() { 113 | var numberSet = t.createSet([1, 2, 3], "N"); 114 | // nodejs built in assert deep equals does not do strict equality 115 | expect(numberSet.format()).to.eql({NS : ["1", "2", "3"]}); 116 | }); 117 | 118 | it("as a BinSet.", function() { 119 | var binSet = t.createSet([new Buffer("hello"), new Buffer("world")], "B"); 120 | expect(binSet.format()).to.eql({BS : [new Buffer("hello"), new Buffer("world")]}); 121 | }); 122 | }); 123 | 124 | }); 125 | -------------------------------------------------------------------------------- /test/formatter.js: -------------------------------------------------------------------------------- 1 | var assert = require("assert"); 2 | var datatypes = require("../lib/datatypes").DynamoDBDatatype; 3 | var t = new datatypes(); 4 | var formatter = require("../lib/formatter").DynamoDBFormatter; 5 | var f = new formatter(); 6 | var c = require("../lib/condition"); 7 | 8 | 9 | describe("Testing Format Input", function() { 10 | "use strict"; 11 | 12 | describe("on BatchGetItem Input", function() { 13 | var request = {}; 14 | request.operation = "batchGetItem"; 15 | request.params = {}; 16 | request.params.ReturnConsumedCapacity = "NONE"; 17 | 18 | var gameTable = "Games"; 19 | var gameKeys = [{"GameId": 1}, {"GameId": 2}]; 20 | 21 | var userTable = "Users"; 22 | var userKeys = [{"UserId": "raymolin", "Age": 21}]; 23 | 24 | 25 | it("with hash and hash-range keys", function() { 26 | request.params.RequestItems = {}; 27 | request.params.RequestItems[gameTable] = {"ConsistentRead": "false", 28 | "ProjectionExpression": "#a", 29 | "ExpressionAttributeNames": {"#a": "GameId"}, 30 | "Keys": gameKeys}; 31 | request.params.RequestItems[userTable] = {"AttributesToGet": ["UserId", "Friends"], 32 | "Keys": userKeys}; 33 | 34 | var llRequestParams = {"RequestItems": 35 | {"Games": 36 | {"ConsistentRead": "false", 37 | "ProjectionExpression": "#a", 38 | "ExpressionAttributeNames": {"#a": "GameId"}, 39 | "Keys": [{"GameId": {"N": "1"}}, 40 | {"GameId": {"N": "2"}}]}, 41 | "Users": 42 | {"AttributesToGet": ["UserId", "Friends"], 43 | "Keys": [{"UserId": {"S": "raymolin"}, 44 | "Age": {"N": "21"}}] }}, 45 | "ReturnConsumedCapacity": "NONE"}; 46 | 47 | f.formatInput(request); 48 | assert.deepEqual(request.params, llRequestParams); 49 | }); 50 | 51 | }); 52 | describe("on GetItem Input", function() { 53 | var request = {}; 54 | 55 | var hashKey = {"UserId": "raymolin"}; 56 | 57 | var hashRangeKey = {"UserId": "raymolin", 58 | "HighScore" : 200}; 59 | 60 | beforeEach(function() { 61 | request.params = {}; 62 | request.params.TableName = "Users"; 63 | request.operation = "getItem"; 64 | }); 65 | 66 | it("formatInput on simple Hash Key", function() { 67 | request.params.Key = hashKey; 68 | var llRequestParams = {"Key": 69 | {"UserId": 70 | {"S": "raymolin"}}, 71 | "TableName": 72 | "Users"}; 73 | f.formatInput(request); 74 | assert.deepEqual(request.params, llRequestParams, 75 | "Didn't meet expected params."); 76 | }); 77 | 78 | it("formatInput on Hash-Range Key", function() { 79 | request.params.Key = hashRangeKey; 80 | var llRequestParams = {"Key": 81 | {"UserId": 82 | {"S": "raymolin"}, 83 | "HighScore": 84 | {"N": "200"}}, 85 | "TableName": "Users"}; 86 | f.formatInput(request); 87 | assert.deepEqual(request.params, llRequestParams, 88 | "Didn't meet expected params."); 89 | }); 90 | }); 91 | 92 | describe("on PutItem Input", function() { 93 | var request = {}; 94 | 95 | var basicItem = {"UserId" : "raymolin", 96 | "Age" : 21, 97 | "Coworkers" : new t.createSet(["vijayra", "hulisa"], "S") }; 98 | 99 | var jsonItem = {"UserId" : "raymolin", 100 | "ProfilePic": new Buffer("0101"), 101 | "Spouse" : null, 102 | "isMarried" : false, 103 | "Relationships" : {"Father": "John", 104 | "Mother": "Jane"}, 105 | "Pets" : ["Dog", "Cat"]}; 106 | 107 | beforeEach(function() { 108 | request.params = {}; 109 | request.params.TableName = "Users"; 110 | request.operation = "putItem"; 111 | }); 112 | 113 | it("on basic item", function() { 114 | request.params.Item = basicItem; 115 | var llRequestParams = {"Item": 116 | {"UserId": 117 | {"S": "raymolin"}, 118 | "Age": 119 | {"N": "21"}, 120 | "Coworkers": 121 | {"SS": ["vijayra", "hulisa"]}}, 122 | "TableName": "Users"}; 123 | f.formatInput(request); 124 | 125 | assert.deepEqual(request.params, llRequestParams, 126 | "Didn't meet expected params."); 127 | }); 128 | 129 | it("on json item", function() { 130 | request.params.Item = jsonItem; 131 | var llRequestParams = {"Item": 132 | {"UserId": 133 | {"S": "raymolin"}, 134 | "ProfilePic": 135 | {"B": new Buffer("0101")}, 136 | "isMarried": 137 | {"BOOL": false}, 138 | "Spouse": 139 | {"NULL": true}, 140 | "Relationships": 141 | {"M": {"Father" : 142 | {"S" : "John"}, 143 | "Mother" : 144 | {"S" : "Jane"}}}, 145 | "Pets": 146 | {"L": [{"S": "Dog"}, 147 | {"S": "Cat"}] }}, 148 | "TableName": "Users"}; 149 | f.formatInput(request); 150 | 151 | assert.deepEqual(request.params, llRequestParams, 152 | "Didn't meet expected params."); 153 | }); 154 | 155 | it("with conditions on basic item", function() { 156 | request.params.Item = basicItem; 157 | request.params.Expected = new c.DynamoDBCondition("UserId", "NOT_NULL"); 158 | var llRequestParams = {"Item": 159 | {"UserId": 160 | {"S": "raymolin"}, 161 | "Age": 162 | {"N": "21"}, 163 | "Coworkers": 164 | {"SS": ["vijayra", "hulisa"]}}, 165 | "TableName": "Users", 166 | "Expected" : 167 | {"UserId": 168 | {"ComparisonOperator": "NOT_NULL"}}}; 169 | f.formatInput(request); 170 | assert.deepEqual(request.params, llRequestParams, 171 | "Didn't meet expected params."); 172 | }); 173 | }); 174 | 175 | describe("on DelItem Input", function() { 176 | var request = {}; 177 | 178 | var hashKey = {"UserId" : "raymolin"}; 179 | var hashRangeKey = {"UserId" : "raymolin", 180 | "HighScore" : 200}; 181 | 182 | beforeEach(function () { 183 | request.params = {}; 184 | request.params.TableName = "Users"; 185 | request.operation = "deleteItem"; 186 | }); 187 | 188 | it("with a simple hash key", function() { 189 | request.params.Key = hashKey; 190 | var llRequestParams = {"Key": 191 | {"UserId": 192 | {"S" : "raymolin"}}, 193 | "TableName": "Users"}; 194 | f.formatInput(request); 195 | assert.deepEqual(request.params, llRequestParams, 196 | "Didn't meet expected params."); 197 | }); 198 | 199 | it("with a hash-range key", function() { 200 | request.params.Key = hashRangeKey; 201 | var llRequestParams = {"Key": 202 | {"UserId": 203 | {"S": "raymolin"}, 204 | "HighScore": 205 | {"N": "200" }}, 206 | "TableName": "Users"}; 207 | f.formatInput(request); 208 | assert.deepEqual(request.params, llRequestParams, 209 | "Didn't meet expected params."); 210 | }); 211 | 212 | it("with a condition and hash key", function() { 213 | request.params.Key = hashKey; 214 | request.params.Expected = new c.DynamoDBCondition("Age", "NOT_NULL"); 215 | var llRequestParams = {"Key": 216 | {"UserId": 217 | {"S": "raymolin"}}, 218 | "Expected": 219 | {"Age": 220 | {"ComparisonOperator": "NOT_NULL"}}, 221 | "TableName": "Users"}; 222 | f.formatInput(request); 223 | assert.deepEqual(request.params, llRequestParams, 224 | "Didn't meet expected params."); 225 | }); 226 | 227 | }); 228 | 229 | describe("on UpdateItem Input", function() { 230 | var request = {}; 231 | 232 | var hashKey = {"GameNum" : 1}; 233 | var update = {"Players": { 234 | "Action": "PUT", 235 | "Value": ["P1", "P2"]}}; 236 | var llRequestParams = {"Key": 237 | {"GameNum": 238 | {"N": "1"}}, 239 | "AttributeUpdates": 240 | {"Players": 241 | {"Action": "PUT", 242 | "Value": 243 | {"L" : [ 244 | {"S": "P1"}, 245 | {"S": "P2"}]}}}, 246 | "TableName": "Games"}; 247 | 248 | beforeEach(function () { 249 | request.params = {}; 250 | request.params.TableName = "Games"; 251 | request.params.Key = hashKey; 252 | request.params.AttributeUpdates = update; 253 | request.operation = "updateItem"; 254 | }); 255 | 256 | it("with simple JSON datatype", function() { 257 | f.formatInput(request); 258 | assert.deepEqual(request.params, llRequestParams); 259 | }); 260 | 261 | it("with DELETE Condition and empty Value", function() { 262 | var newUpdate = {"Cache": { 263 | "Action": "DELETE"}}; 264 | var newParams = {}; 265 | newParams.TableName = "Games"; 266 | newParams.Key = hashKey; 267 | newParams.AttributeUpdates = newUpdate; 268 | 269 | var newllRequestParams = {}; 270 | newllRequestParams.Key = llRequestParams.Key; 271 | newllRequestParams.TableName = "Games"; 272 | newllRequestParams.AttributeUpdates = newUpdate; 273 | 274 | var newRequest = {params: newParams, 275 | operation: "updateItem"}; 276 | 277 | f.formatInput(newRequest); 278 | assert.deepEqual(newRequest.params, newllRequestParams); 279 | }); 280 | 281 | it("with simple condition", function() { 282 | request.params.Expected = new c.DynamoDBCondition("Players", "NULL"); 283 | llRequestParams.Expected = {"Players": 284 | {"ComparisonOperator": "NULL"}}; 285 | f.formatInput(request); 286 | assert.deepEqual(request.params, llRequestParams); 287 | }); 288 | 289 | }); 290 | 291 | 292 | 293 | describe("on BatchWriteItem Input", function() { 294 | var request = {}; 295 | request.operation = "batchWriteItem"; 296 | request.params = {}; 297 | request.params.ReturnConsumedCapacity = "NONE"; 298 | 299 | var gameTable = "Games"; 300 | 301 | it("with Delete and Put Requests", function() { 302 | var delRequest = {"DeleteRequest": 303 | {"Key": 304 | {"GameId": 1}}}; 305 | var putRequest = {"PutRequest": 306 | {"Item": 307 | {"GameId": 2, 308 | "Players": ["P1", "P2"]}}}; 309 | 310 | request.params.RequestItems = {}; 311 | request.params.RequestItems[gameTable] = [delRequest, putRequest]; 312 | 313 | var llRequestParams = {"RequestItems": 314 | {"Games": 315 | [{"DeleteRequest": 316 | {"Key": 317 | {"GameId": {"N": "1"}}}}, 318 | {"PutRequest": 319 | {"Item": 320 | {"GameId": {"N": "2"}, 321 | "Players": {"L": [{"S": "P1"}, 322 | {"S": "P2"}]}}}} ]}, 323 | "ReturnConsumedCapacity": "NONE"}; 324 | 325 | f.formatInput(request); 326 | assert.deepEqual(request.params, llRequestParams); 327 | }); 328 | 329 | }); 330 | 331 | describe("on Query Input", function() { 332 | var request = {}; 333 | request.operation = "query"; 334 | request.params = {}; 335 | request.params.TableName = "Users"; 336 | request.params.IndexName = "Age-index"; 337 | 338 | 339 | it("with an Index and QueryFilter", function() { 340 | request.params.KeyConditions = [new c.DynamoDBCondition("Age", "EQ", 21), new c.DynamoDBCondition("Occupation", "EQ", "Driver")]; 341 | request.params.QueryFilter = new c.DynamoDBCondition("DriverLicense", "NOT_NULL"); 342 | 343 | var llRequestParams = {"KeyConditions": 344 | {"Age": 345 | {"AttributeValueList": [{"N": "21"}], 346 | "ComparisonOperator": "EQ"}, 347 | "Occupation": 348 | {"AttributeValueList": [{"S": "Driver"}], 349 | "ComparisonOperator": "EQ"}}, 350 | "QueryFilter": 351 | {"DriverLicense": 352 | {"ComparisonOperator": "NOT_NULL"}}, 353 | "TableName": "Users", 354 | "IndexName": "Age-index"}; 355 | 356 | f.formatInput(request); 357 | assert.deepEqual(request.params, llRequestParams); 358 | }); 359 | }); 360 | 361 | describe("on Scan Input", function() { 362 | var request = {}; 363 | request.operation = "scan"; 364 | request.params = {}; 365 | request.params.TableName = "Users"; 366 | 367 | var startKey = {"UserId": "raymolin"}; 368 | var cop = "OR"; 369 | var scanFilter = [new c.DynamoDBCondition("Age", "GT", 21), 370 | new c.DynamoDBCondition("DriversLicense", "NOT_NULL")]; 371 | 372 | it("with an ExclusiveStartKey, Conditional Operator and Scan Filter", function() { 373 | request.params.ExclusiveStartKey = startKey; 374 | request.params.ConditionalOperator = cop; 375 | request.params.ScanFilter = scanFilter; 376 | 377 | var llRequestParams = {"ExclusiveStartKey": 378 | {"UserId": 379 | {"S": "raymolin"}}, 380 | "ScanFilter": 381 | {"Age": 382 | {"AttributeValueList": [{"N": "21"}], 383 | "ComparisonOperator": "GT"}, 384 | "DriversLicense": 385 | {"ComparisonOperator": "NOT_NULL"}}, 386 | "ConditionalOperator": "OR", 387 | "TableName": "Users"}; 388 | 389 | f.formatInput(request); 390 | assert.deepEqual(request.params, llRequestParams); 391 | }); 392 | }); 393 | 394 | describe("on general JSON expression attribute value map", function() { 395 | var request = {}; 396 | request.params = {}; 397 | request.params.ExpressionAttributeValues = {"maxFirstAttributeValue": 1000, 398 | "interestingAttributeValue": "very interesting"}; 399 | 400 | var llRequestParams = {"ExpressionAttributeValues": 401 | {"maxFirstAttributeValue": 402 | {"N": "1000"}, 403 | "interestingAttributeValue": 404 | {"S": "very interesting"}}}; 405 | 406 | it("with a simple example", function() { 407 | f.formatInput(request); 408 | assert.deepEqual(request.params, llRequestParams); 409 | }); 410 | }); 411 | 412 | }); 413 | 414 | describe("Testing Format Output", function() { 415 | "use strict"; 416 | 417 | describe("on GetItem Output", function() { 418 | var response = {}; 419 | var mlResponseData = {}; 420 | 421 | beforeEach(function() { 422 | mlResponseData.Item = {"UserId": 423 | "raymolin", 424 | "Age": 425 | 21}; 426 | 427 | response.data = {}; 428 | response.data.Item = {"UserId": 429 | {"S": "raymolin"}, 430 | "Age": 431 | {"N": "21"}}; 432 | 433 | Array.prototype.notAnElement = function() {}; 434 | }); 435 | 436 | afterEach(function() { 437 | if (mlResponseData.ConsumedCapacity) { 438 | delete mlResponseData.ConsumedCapacity; 439 | } 440 | delete Array.prototype.notAnElement; 441 | }); 442 | 443 | it("with a simple response", function() { 444 | f.formatOutput(response); 445 | assert.deepEqual(response.data, mlResponseData); 446 | }); 447 | 448 | it("with consumed capacity", function() { 449 | response.data.ConsumedCapacity = {}; 450 | response.data.ConsumedCapacity.TableName = "Users"; 451 | response.data.ConsumedCapacity.CapacityUnits = "10"; 452 | 453 | mlResponseData.ConsumedCapacity = {}; 454 | mlResponseData.ConsumedCapacity.TableName = "Users"; 455 | mlResponseData.ConsumedCapacity.CapacityUnits = "10"; 456 | 457 | f.formatOutput(response); 458 | assert.deepEqual(response.data, mlResponseData); 459 | }); 460 | 461 | it("with Array prototype chain pollution", function() { 462 | mlResponseData.Item.Friends = {Gaming: 463 | ["Abe", "Ally"]}; 464 | response.data.Item.Friends = {M: { 465 | Gaming: 466 | {L: [ 467 | {S: "Abe"}, {S: "Ally"}]}}}; 468 | 469 | f.formatOutput(response); 470 | assert.deepEqual(response.data, mlResponseData); 471 | }); 472 | }); 473 | 474 | 475 | describe("on Put/Delete/Update Item Output", function() { 476 | var response = {}; 477 | var mlResponseData = {}; 478 | mlResponseData.Attributes = {"UserId": 479 | "raymolin", 480 | "Certified": 481 | true, 482 | "Coworkers": 483 | ["joz", "vijayra"], 484 | "Project": 485 | null}; 486 | 487 | beforeEach(function() { 488 | response.data = {}; 489 | response.data.Attributes = {"UserId": 490 | {"S": "raymolin"}, 491 | "Certified": 492 | {"BOOL": true}, 493 | "Coworkers": 494 | {"L": [{"S": "joz"}, 495 | {"S": "vijayra"}]}, 496 | "Project": 497 | {"NULL": true}}; 498 | }); 499 | 500 | it("with just attributes", function() { 501 | f.formatOutput(response); 502 | assert.deepEqual(response.data, mlResponseData); 503 | }); 504 | 505 | it("with Item Collection Metrics", function() { 506 | response.data.ItemCollectionMetrics = {"ItemCollectionKey": 507 | {"UserId": 508 | {"S": "raymolin"}}, 509 | "SizeEstimateRangeGB": 510 | ["10"]}; 511 | mlResponseData.ItemCollectionMetrics = {"ItemCollectionKey": 512 | {"UserId": "raymolin"}, 513 | "SizeEstimateRangeGB": 514 | ["10"]}; 515 | f.formatOutput(response); 516 | assert.deepEqual(response.data, mlResponseData); 517 | }); 518 | }); 519 | 520 | describe("on BatchGetItem Output", function() { 521 | var response = {}; 522 | var mlResponseData = {}; 523 | mlResponseData.Responses = {"Users": 524 | [{"UserId": "raymolin", 525 | "Age": 21}, 526 | {"UserId": "joz", 527 | "Age": 21}], 528 | "Games": 529 | [{"GameId": 1, 530 | "Players": ["raymolin", "joz"]}]}; 531 | beforeEach(function() { 532 | response.data = {}; 533 | response.data.Responses = {"Users": 534 | [{"UserId": 535 | {"S": "raymolin"}, 536 | "Age": 537 | {"N": "21"}}, 538 | {"UserId": 539 | {"S": "joz"}, 540 | "Age": 541 | {"N": "21"}}], 542 | "Games": 543 | [{"GameId": 544 | {"N": "1"}, 545 | "Players": 546 | {"L": [{"S": "raymolin"}, 547 | {"S": "joz"}]}}]}; 548 | 549 | }); 550 | 551 | it("with simple Responses", function() { 552 | f.formatOutput(response); 553 | assert.deepEqual(response.data, mlResponseData); 554 | }); 555 | 556 | it("with UnprocessedKeys", function() { 557 | response.data.UnprocessedKeys = {"Users": 558 | {"Keys": 559 | [{"UserId": 560 | {"S": "vijayra"}}]}}; 561 | mlResponseData.UnprocessedKeys = {"Users": 562 | {"Keys": 563 | [{"UserId": "vijayra"}]}}; 564 | 565 | f.formatOutput(response); 566 | assert.deepEqual(response.data, mlResponseData); 567 | }); 568 | }); 569 | 570 | describe("on BatchWriteItem Output", function() { 571 | var response = {}; 572 | var mlResponseData = {}; 573 | 574 | var raymolin = {"ItemCollectionKey": 575 | {"UserId": "raymolin"}, 576 | "SizeEstimateRangeGB": ["10"]}; 577 | var vinitra = {"ItemCollectionKey": 578 | {"UserId": "vinitra"}, 579 | "SizeEstimateRangeGB": ["5"]}; 580 | 581 | mlResponseData.ItemCollectionMetrics = {"Users": 582 | [raymolin, vinitra]}; 583 | 584 | 585 | beforeEach(function() { 586 | response.data = {}; 587 | var llraymolin = {"ItemCollectionKey": 588 | {"UserId": {"S": "raymolin"}}, 589 | "SizeEstimateRangeGB": ["10"]}; 590 | var llvinitra = {"ItemCollectionKey": 591 | {"UserId": {"S": "vinitra"}}, 592 | "SizeEstimateRangeGB": ["5"]}; 593 | response.data.ItemCollectionMetrics = {"Users": 594 | [llraymolin, llvinitra]}; 595 | }); 596 | 597 | it("with Item Collection Metrics", function() { 598 | f.formatOutput(response); 599 | assert.deepEqual(response.data, mlResponseData); 600 | }); 601 | 602 | it("with UnprocessedItems", function() { 603 | response.data.UnprocessedItems = {"Users": 604 | [{"DeleteRequest": 605 | {"Key": 606 | {"UserId": 607 | {"S": "raymolin"}}}}, 608 | {"PutRequest": 609 | {"Item": 610 | {"UserId": 611 | {"S": "raymolin"}}}}]}; 612 | 613 | mlResponseData.UnprocessedItems = {"Users": 614 | [{"DeleteRequest": 615 | {"Key": 616 | {"UserId": "raymolin"}}}, 617 | {"PutRequest": 618 | {"Item": 619 | {"UserId": "raymolin"}}}]}; 620 | 621 | f.formatOutput(response); 622 | assert.deepEqual(response.data, mlResponseData); 623 | }); 624 | }); 625 | 626 | describe("on Scan/Query", function() { 627 | var response = {}; 628 | var mlResponseData = {"Items": 629 | [{"UserId": "raymolin"}, 630 | {"UserId": "martin"}, 631 | {"UserId": "john"}], 632 | "Count": "3"}; 633 | 634 | beforeEach(function() { 635 | response.data = {}; 636 | response.data.Items = [{"UserId": 637 | {"S": "raymolin"}}, 638 | {"UserId": 639 | {"S": "martin"}}, 640 | {"UserId": 641 | {"S": "john"}}]; 642 | response.data.Count = "3"; 643 | }); 644 | 645 | it("with count and items", function() { 646 | f.formatOutput(response); 647 | assert.deepEqual(response.data, mlResponseData); 648 | }); 649 | 650 | it("with lastEvaluatedKey", function() { 651 | response.data.LastEvaluatedKey = {"UserId": 652 | {"S": "john"}}; 653 | 654 | mlResponseData.LastEvaluatedKey = {"UserId": "john"}; 655 | 656 | f.formatOutput(response); 657 | assert.deepEqual(response.data, mlResponseData); 658 | }); 659 | 660 | }); 661 | }); 662 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --reporter spec 2 | --ui bdd 3 | --recursive 4 | --------------------------------------------------------------------------------