### Installing Project Dependencies - Bash Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/CONTRIBUTING.md This command installs all necessary project dependencies listed in the package.json file. It should be run after cloning the repository to set up the development environment. ```bash npm install ``` -------------------------------- ### Run Project (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/overview/README.md Executes the 'run' target in the project's Makefile or build system, starting the application or sample. ```Shell make run ``` -------------------------------- ### Configure Project (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/overview/README.md Executes the 'configure' target in the project's Makefile or build system, typically used for initial setup or configuration. ```Shell make configure ``` -------------------------------- ### Installing OneTable via npm Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Command to install the dynamodb-onetable library using the npm package manager. This is the standard way to add the library to your project dependencies. ```Shell npm i dynamodb-onetable ``` -------------------------------- ### Run Project (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/packed/README.md Executes the 'run' target in the project's Makefile. This command starts the application or executes the main script of the sample project. ```shell make run ``` -------------------------------- ### Configure Project (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/packed/README.md Executes the 'configure' target in the project's Makefile. This step typically prepares the project environment, such as installing dependencies or setting up configuration files. ```shell make configure ``` -------------------------------- ### Running the OneTable TypeScript Sample (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/typescript/README.md This command executes the built OneTable TypeScript sample project. It typically starts the application, which may interact with a local or remote DynamoDB instance. ```Shell make run ``` -------------------------------- ### Get Item using OneTable Model Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Demonstrates retrieving an 'Account' item from DynamoDB using the OneTable model's get method, specifying the item's primary key attributes. ```javascript let account = await Account.get({ id: '8e7bbe6a-4afc-4117-9218-67081afc935b', }) ``` -------------------------------- ### Example OneTable Schema Definition Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/doc/schema-1.0.0.md This JSON snippet provides an example of a OneTable schema definition. It includes the schema version, format, index definitions (primary and GSI1), parameters (like the type field), and model definitions for different entities (Account, User, Post) with their respective attributes and key value templates. ```json { "version": "0.1.0", "format": "onetable:1.0.0", "indexes": { "primary": { "hash": "PK", "sort": "SK" }, "GSI1": { "hash": "GS1PK", "sort": "GS1SK" } }, "params": { "typeField": "_type" }, "models": { "Account": { "PK": { "type": "string", "value": "account#${name}" }, "SK": { "type": "string", "value": "account#" }, "name": { "type": "string", "required": true } }, "User": { "PK": { "type": "string", "value": "account#${accountName}" }, "SK": { "type": "string", "value": "user#${email}" }, "accountName": { "type": "string" }, "email": { "type": "string", "required": true } }, "Post": { "PK": { "value": "post#${id}" }, "SK": { "value": "user#${email}" }, "id": { "type": "string" }, "message": { "type": "string" }, "email": { "type": "string" } } } } ``` -------------------------------- ### Example OneTable Query Definition (JSON) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/doc/schema-1.0.0.md This JSON snippet provides an example definition for a saved query within the OneTable 'queries' map. It illustrates how to configure properties such as 'filters', 'hash', 'index', 'limit', 'operation', and 'type' for a specific query named 'sampleQuery'. ```JSON "queries": { "sampleQuery": { "filters": [ { "operation": "Equal", "combine": "And", "type": "string", "value": "6e223f93636422b9a86b57714499918c", "field": "apiToken" } ], "hash": "org:47f1b13910d2aacd818dafa6b38c46bb", "index": "primary", "limit": 100, "name": "test", "operation": "Equal", "schema": "Current", "sort": "cloud:d5cafc5f2bf2213fbbe414c0f18f2600", "type": "Query" } } ``` -------------------------------- ### Returned Item Representation after Get Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Shows the structure of the item returned by the OneTable model's get method, which typically excludes internal OneTable attributes like pk/sk. ```javascript { id: '8e7bbe6a-4afc-4117-9218-67081afc935b', name: 'Acme Airplanes', status: 'active', zip: '98034', } ``` -------------------------------- ### Example OneTable Schema JSON Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/doc/schema-1.1.0.md This JSON object provides a sample structure for a OneTable schema, demonstrating how to define version, format, indexes, parameters, data models (entities), and queries. ```JSON { "version": "0.1.0", "format": "onetable:1.1.0", "indexes": { "primary": { "hash": "PK", "sort": "SK" }, "GSI1": { "hash": "GS1PK", "sort": "GS1SK" } }, "params": { "typeField": "_type" }, "models": { "Account": { "PK": { "type": "string", "value": "account#${name}" }, "SK": { "type": "string", "value": "account#" }, "name": { "type": "string", "required": true } }, "User": { "PK": { "type": "string", "value": "account#${accountName}" }, "SK": { "type": "string", "value": "user#${email}" }, "accountName": { "type": "string" }, "email": { "type": "string", "required": true } }, "Post": { "PK": { "value": "post#${id}" }, "SK": { "value": "user#${email}" }, "id": { "type": "string" }, "message": { "type": "string" }, "email": { "type": "string" } } }, "queries": { "Get photos liked by a user": { "limit": 100, "index": "gs1", "model": "Like", "filters": [ { "field": "username", "type": "string", "operation": "Equal", "value": "ashley", "combine": "And" } ], "operation": "Begins with", "schema": "Current", "type": "Entity" } }, "items": [ ] } ``` -------------------------------- ### Get Item using Secondary Index Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Demonstrates retrieving a 'User' item using a Global Secondary Index (GSI) by specifying the index name and the GSI partition key attribute. ```javascript let user = await User.get({email: 'user@example.com'}, {index: 'gs1'}) ``` -------------------------------- ### Example DynamoDB OneTable Query (JSON) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/doc/schema-1.1.0.md This JSON object defines a sample query configuration for DynamoDB OneTable, specifying filters, hash key, index, limit, and other query parameters. ```json "queries": { "sampleQuery": { "filters": [ { "operation": "Equal", "combine": "And", "type": "string", "value": "6e223f93636422b9a86b57714499918c", "field": "apiToken" } ], "hash": "org:47f1b13910d2aacd818dafa6b38c46bb", "index": "primary", "limit": 100, "name": "test", "operation": "Equal", "schema": "Current", "type": "Query" } } ``` -------------------------------- ### Find Items using OneTable Model Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Demonstrates querying for multiple 'User' items using the find method with various conditions, including filtering by attributes, using a 'where' clause for complex filtering, and getting only a count. ```javascript let users = await User.find({accountId: account.id}) ``` ```javascript let adminUsers = await User.find({accountId: account.id, role: 'admin'}) ``` ```javascript let users = await User.find( {accountId: account.id}, { where: '${balance} > {100.00}', } ) ``` ```javascript // Get a count of matching users without returning the actual items let users = await User.find({accountId: account.id, role: 'admin'}, {count: true}) let count = users.count ``` -------------------------------- ### Model Property Name Regex - OneTable Schema Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/doc/schema-1.1.0.md This regular expression defines the valid format for property names within a OneTable schema model. Property names must start with an alphabetic character or underscore and can be followed by alphanumeric characters or underscores. ```Regex /^[a-zA-Z_]+[\w]*$/ ``` -------------------------------- ### Validate OneTable Model Property Name (Regex) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/doc/schema-1.0.0.md This regular expression defines the valid format for property names within the 'models' map of a OneTable schema. Names must start with an alphabetic character or underscore, followed by zero or more word characters (alphanumeric or underscore). ```Regex /^[a-zA-Z_]+[\w]*$/ ``` -------------------------------- ### Building the OneTable TypeScript Sample (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/typescript/README.md These commands are used to configure and build the OneTable TypeScript sample project using the Makefile. The first command sets up the project, and the second compiles the source code. ```Shell make configure ``` ```Shell make build ``` -------------------------------- ### Build Project (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/overview/README.md Executes the 'build' target in the project's Makefile or build system, compiling source code or preparing the project for execution. ```Shell make build ``` -------------------------------- ### Build OneTable CRUD Sample (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/crud/README.md Configures and builds the OneTable CRUD sample project using make commands. ```shell make configure make build ``` -------------------------------- ### Run OneTable CRUD Sample (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/crud/README.md Runs the built OneTable CRUD sample project using a make command. ```shell make run ``` -------------------------------- ### Open Project in VS Code (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/overview/README.md Opens the current directory as a project in Visual Studio Code, useful for debugging and code exploration. ```Shell code . ``` -------------------------------- ### Running the Test Suite - Bash Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/CONTRIBUTING.md This command executes the project's test suite. Running tests locally is crucial to ensure that code changes do not introduce regressions and adhere to expected behavior. ```bash npm test ``` -------------------------------- ### Build Project (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/packed/README.md Executes the 'build' target in the project's Makefile. This command compiles source code, bundles assets, or performs other necessary steps to prepare the application for execution. ```shell make build ``` -------------------------------- ### Running the Linter - Bash Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/CONTRIBUTING.md This command runs the project's linter, which checks code for style consistency and potential errors. Ensuring code passes the linter is a standard requirement for contributions. ```bash npm run lint ``` -------------------------------- ### Open Project in VS Code (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/crud/README.md Opens the current project directory in Visual Studio Code for debugging or editing. ```shell code . ``` -------------------------------- ### Initializing OneTable Table Instance Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Creates a new instance of the OneTable Table class. It requires the AWS SDK client, the DynamoDB table name, and a schema definition (MySchema) to define the data models. ```JavaScript const table = new Table({ client: client, name: 'MyTable', schema: MySchema, }) ``` -------------------------------- ### Opening Project in VS Code for Debugging (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/typescript/README.md This command opens the current directory in Visual Studio Code, allowing you to set breakpoints and debug the OneTable TypeScript sample project. ```Shell code . ``` -------------------------------- ### Create Item using OneTable Model Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Demonstrates creating a new 'Account' item in DynamoDB using the OneTable model's create method. Requires the Account model to be initialized from the schema. ```javascript let account = await Account.create({ id: '8e7bbe6a-4afc-4117-9218-67081afc935b', name: 'Acme Airplanes', }) ``` -------------------------------- ### Initializing AWS SDK V3 DynamoDBClient Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Imports and initializes the DynamoDBClient from the AWS SDK V3. This client instance is used by OneTable to communicate with DynamoDB. Configuration includes endpoint, region, and credentials. ```JavaScript import {DynamoDBClient} from '@aws-sdk/client-dynamodb' const client = new DynamoDBClient({ endpoint: `http://localhost:${PORT}`, region: 'local', credentials: new AWS.Credentials({ accessKeyId: 'test', secretAccessKey: 'test', }), }) ``` -------------------------------- ### Open Project in VS Code (Shell) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/samples/packed/README.md Opens the current directory in Visual Studio Code. This command is used to easily access the project files for editing, debugging, or exploration within the VS Code environment. ```shell code . ``` -------------------------------- ### Initializing AWS SDK V2 DocumentClient Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Imports and initializes the DocumentClient from the legacy AWS SDK V2. This client can also be used by OneTable to interact with DynamoDB. It requires a params object for configuration. ```JavaScript import DynamoDB from 'aws-sdk/clients/dynamodb' const client = new DynamoDB.DocumentClient(params) ``` -------------------------------- ### Update Item using OneTable Model Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Demonstrates updating a 'User' item using the update method with different operations: setting an attribute directly, adding a value to a numeric attribute, and setting an attribute using a placeholder. ```javascript await User.update({id: userId, balance: 50}) ``` ```javascript await User.update({id: userId}, {add: {balance: 10.0}}) ``` ```javascript await User.update({id: userId}, {set: {status: '{active}'}}) ``` -------------------------------- ### TypeScript Typing with OneTable Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Illustrates how OneTable schemas can be used with TypeScript to generate type declarations for entities and models, enabling compile-time type checking. ```typescript import {Entity, Model, Table} from 'dynamodb-onetable' const MySchema = { ... models: { Account: { pk: { type: String, value: 'account:${name}' }, name: { type: String }, } } as const // Required for TypeScript } // Fully typed Account object based on the schema type Account = Entity let account: Account = { name: 'Coyote', // OK unknown: 42, // Error } let AccountModel: Model = table.getModel('Account') let account = await AccountModel.create({ name: 'Acme', // OK unknown: 42, // Error }) account.name = 'Coyote' // OK account.unknown = 42 // Error ``` -------------------------------- ### Importing OneTable Table Class (ES Modules) Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Imports the primary Table class from the dynamodb-onetable library using ES module syntax. This class is required to interact with OneTable. ```JavaScript import {Table} from 'dynamodb-onetable' ``` -------------------------------- ### DynamoDB Item Representation after Create Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Shows the structure of the item as it is stored in DynamoDB after being created via the OneTable model, including generated primary/sort keys and timestamps. ```javascript { pk: 'account:8e7bbe6a-4afc-4117-9218-67081afc935b', sk: 'account:98034', id: '8e7bbe6a-4afc-4117-9218-67081afc935b', name: 'Acme Airplanes', status: 'active', zip: '98034', created: 1610347305510, updated: 1610347305510, } ``` -------------------------------- ### Define OneTable Schema Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Defines the schema for a DynamoDB table using OneTable, specifying format version, indexes (primary, GSI, LSI), and models (Account, User) with attribute types, values, validation, and default settings. ```javascript const MySchema = { format: 'onetable:1.1.0', version: '0.0.1', indexes: { primary: {hash: 'pk', sort: 'sk'}, gs1: {hash: 'gs1pk', sort: 'gs1sk', follow: true}, ls1: {sort: 'id', type: 'local'}, }, models: { Account: { pk: {type: String, value: 'account:${id}'}, sk: {type: String, value: 'account:'}, id: {type: String, generate: 'ulid', validate: /^[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$/i}, name: {type: String, required: true}, status: {type: String, default: 'active'}, zip: {type: String}, }, User: { pk: {type: String, value: 'account:${accountName}'}, sk: {type: String, value: 'user:${email}', validate: EmailRegExp}, id: {type: String, required: true}, accountName: {type: String, required: true}, email: {type: String, required: true}, firstName: {type: String, required: true}, lastName: {type: String, required: true}, username: {type: String, required: true}, role: {type: String, enum: ['user', 'admin'], required: true, default: 'user'}, balance: {type: Number, default: 0}, gs1pk: {type: String, value: 'user-email:${email}'}, gs1sk: {type: String, value: 'user:'}, }, }, params: { isoDates: true, timestamps: true, }, } ``` -------------------------------- ### Perform Transactional Update Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/README.md Demonstrates performing multiple update operations atomically within a single transaction using the transact method. ```javascript let transaction = {} await Account.update({id: account.id, status: 'active'}, {transaction}) await User.update({id: user.id, role: 'user'}, {transaction}) await table.transact('write', transaction) ``` -------------------------------- ### Defining Schema and Using Typed Models with OneTable Source: https://github.com/sensedeep/dynamodb-onetable/blob/main/doc/TypeScript.md This snippet defines a OneTable schema for an 'Account' entity, demonstrates how to create a TypeScript type ('Account') from the schema using the 'Entity' utility type, and shows how type checking is applied when creating objects and using model update operations, highlighting how invalid properties are flagged as errors. ```typescript const schema = { format: 'onetable:1.1.0', version: '0.0.1', indexes: { primary: { hash: 'pk', sort: 'sk' }, }, models: { Account: { pk: { type: String, value: 'account:${name}' }, name: { type: String } } }, params: {} } // Fully typed Account object based on the schema type Account = Entity let account: Account = { name: 'Coyote', // OK unknown: 42 // Error } // Create a model to get/find/update... let AccountModel = table.getModel('Account') let account = await AccountModel.update({ name: 'Acme', // OK unknown: 42 // Error }) account.name = 'Coyote' // OK account.unknown = 42 // Error ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.