dyno-table 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "dyno-table",
3
+ "version": "0.0.1",
4
+ "description": "A TypeScript library to simplify working with DynamoDB",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "commonjs",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js"
12
+ }
13
+ },
14
+ "keywords": [
15
+ "dynamodb",
16
+ "aws",
17
+ "typescript",
18
+ "database"
19
+ ],
20
+ "author": "Maunder",
21
+ "license": "ISC",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/Kysumi/dyno-table.git"
25
+ },
26
+ "devDependencies": {
27
+ "@biomejs/biome": "1.9.4",
28
+ "@types/node": "^20.0.0",
29
+ "typescript": "^5.0.0",
30
+ "vitest": "^2.1.8",
31
+ "rimraf": "^5.0.0",
32
+ "tsup": "^8.0.0"
33
+ },
34
+ "peerDependencies": {
35
+ "@aws-sdk/client-dynamodb": "^3.0.0",
36
+ "@aws-sdk/lib-dynamodb": "^3.0.0",
37
+ "zod": "^3.0.0"
38
+ },
39
+ "files": [
40
+ "dist"
41
+ ],
42
+ "scripts": {
43
+ "build": "tsup src/index.ts --format cjs,esm --dts",
44
+ "clean": "rm -rf dist",
45
+ "test": "vitest",
46
+ "test:int": "vitest --config vitest.integration.ts",
47
+ "lint": "biome lint",
48
+ "check-types": "tsc --noEmit",
49
+ "ddb:start": "docker compose up -d dynamodb"
50
+ }
51
+ }
package/readme.md ADDED
@@ -0,0 +1,132 @@
1
+ # dyno-table ๐Ÿš€
2
+
3
+ A powerful, type-safe, and fluent DynamoDB table abstraction layer for Node.js applications.
4
+
5
+ ## Features โœจ
6
+ - ๐Ÿ”„ **Fluent API**: Intuitive builder pattern for constructing DynamoDB operations
7
+ - ๐ŸŽฏ **Smart Retries**: Built-in exponential backoff with configurable retry strategies
8
+ - ๐Ÿ—๏ธ **Expression Builder**: Automatically handles complex DynamoDB expressions and attribute mappings
9
+ - ๐Ÿ” **Query Builder**: Powerful and flexible query construction with support for GSIs
10
+ - ๐Ÿ“ฆ **Repository Pattern**: Easily create and manage data repositories with type-safe schemas
11
+ - ๐Ÿงช **Type Safety**: Utilizes Zod for runtime schema validation and TypeScript type inference
12
+
13
+ ## Quick Start ๐Ÿš€
14
+
15
+ ```typescript
16
+ import { Table } from 'dyno-table';
17
+ import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
18
+
19
+ // Initialize your DynamoDB client
20
+ const client = DynamoDBDocument.from(/* your DynamoDB client config */);
21
+
22
+ // Create a table instance
23
+ const table = new Table({
24
+ client,
25
+ tableName: 'your-table-name',
26
+ gsiIndexes: {
27
+ base: { pkName: 'PK', skName: 'SK' },
28
+ GSI1: { pkName: 'GSI1PK', skName: 'GSI1SK' }
29
+ }
30
+ });
31
+ ```
32
+
33
+ ## Basic Operations ๐Ÿ’ซ
34
+
35
+ ### Querying Data
36
+
37
+ ```typescript
38
+ // Simple query
39
+ const result = await table
40
+ .query({ pk: 'USER#123', sk: 'PROFILE#' })
41
+ .where('status', '=', 'active')
42
+ .limit(10)
43
+ .execute();
44
+
45
+ // Query with GSI
46
+ const gsiResult = await table
47
+ .query({ pk: 'ORG#123', sk: { operator: 'begins_with', value: 'USER#' }})
48
+ .useIndex('GSI1')
49
+ .where('role', '=', 'admin')
50
+ .execute();
51
+ ```
52
+
53
+ ### Writing Data
54
+
55
+ ```typescript
56
+ // Put item with condition
57
+ await table
58
+ .put({ id: '123', name: 'John', status: 'active' })
59
+ .whereNotExists('id')
60
+ .execute();
61
+
62
+ // Update with conditions
63
+ await table
64
+ .update({ pk: 'USER#123', sk: 'PROFILE#1' })
65
+ .set('name', 'John Doe')
66
+ .set('status', 'active')
67
+ .remove('oldField')
68
+ .whereExists('id')
69
+ .execute();
70
+ ```
71
+
72
+ ## Repository Pattern ๐Ÿ—๏ธ
73
+
74
+ ```typescript
75
+ import { z } from 'zod';
76
+ import { BaseRepository } from 'dyno-table';
77
+
78
+ // Define your schema
79
+ const UserSchema = z.object({
80
+ id: z.string(),
81
+ name: z.string(),
82
+ email: z.string().email(),
83
+ status: z.enum(['active', 'inactive']),
84
+ createdAt: z.string()
85
+ });
86
+
87
+ class UserRepository extends BaseRepository<typeof UserSchema> {
88
+ constructor(table: Table) {
89
+ super(table, UserSchema);
90
+ }
91
+
92
+ protected createPrimaryKey(data: z.infer<typeof UserSchema>) {
93
+ return {
94
+ pk: `USER#${data.id}`,
95
+ sk: `PROFILE#${data.id}`
96
+ };
97
+ }
98
+
99
+ protected getIndexKeys() {
100
+ return {
101
+ pk: 'USER#',
102
+ sk: 'PROFILE#'
103
+ };
104
+ }
105
+
106
+ /**
107
+ * Applies a filter to the query to only return models with this type
108
+ */
109
+ protected getType() {
110
+ return 'USER';
111
+ }
112
+ }
113
+ ```
114
+
115
+ ## Contributing ๐Ÿค
116
+
117
+ ### Developing
118
+
119
+ ```bash
120
+ # Installing the dependencies
121
+ pnpm i
122
+
123
+ # Installing the peerDependencies manually
124
+ pnpm i @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb zod
125
+ ```
126
+
127
+
128
+ ### Testing
129
+
130
+ ```bash
131
+ docker run -p 8000:8000 amazon/dynamodb-local
132
+ ```