dyno-table 0.0.1 โ 0.1.2
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/README.md +785 -0
- package/dist/index.d.ts +2869 -274
- package/dist/index.js +3145 -939
- package/package.json +21 -26
- package/readme.md +0 -132
package/package.json
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dyno-table",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A TypeScript library to simplify working with DynamoDB",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"type": "
|
|
7
|
+
"type": "module",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/index.mjs",
|
|
11
11
|
"require": "./dist/index.js"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsup src/index.ts --format esm --dts",
|
|
16
|
+
"clean": "rm -rf dist",
|
|
17
|
+
"test": "vitest run",
|
|
18
|
+
"test:w": "vitest watch",
|
|
19
|
+
"test:int": "vitest --config vitest.integration.ts",
|
|
20
|
+
"lint": "biome lint",
|
|
21
|
+
"check-types": "tsc --noEmit",
|
|
22
|
+
"ddb:start": "docker compose up -d dynamodb"
|
|
23
|
+
},
|
|
24
|
+
"keywords": ["dynamodb", "aws", "typescript", "database"],
|
|
20
25
|
"author": "Maunder",
|
|
21
26
|
"license": "ISC",
|
|
22
27
|
"repository": {
|
|
@@ -24,28 +29,18 @@
|
|
|
24
29
|
"url": "git+https://github.com/Kysumi/dyno-table.git"
|
|
25
30
|
},
|
|
26
31
|
"devDependencies": {
|
|
32
|
+
"@babel/preset-typescript": "^7.26.0",
|
|
27
33
|
"@biomejs/biome": "1.9.4",
|
|
28
34
|
"@types/node": "^20.0.0",
|
|
29
|
-
"typescript": "^5.0.0",
|
|
30
|
-
"vitest": "^2.1.8",
|
|
31
35
|
"rimraf": "^5.0.0",
|
|
32
|
-
"tsup": "^8.0.0"
|
|
36
|
+
"tsup": "^8.0.0",
|
|
37
|
+
"typescript": "^5.0.0",
|
|
38
|
+
"vitest": "^2.1.8"
|
|
33
39
|
},
|
|
34
40
|
"peerDependencies": {
|
|
35
41
|
"@aws-sdk/client-dynamodb": "^3.0.0",
|
|
36
|
-
"@aws-sdk/lib-dynamodb": "^3.0.0"
|
|
37
|
-
"zod": "^3.0.0"
|
|
42
|
+
"@aws-sdk/lib-dynamodb": "^3.0.0"
|
|
38
43
|
},
|
|
39
|
-
"files": [
|
|
40
|
-
|
|
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
|
-
}
|
|
44
|
+
"files": ["dist"],
|
|
45
|
+
"packageManager": "pnpm@10.5.2"
|
|
46
|
+
}
|
package/readme.md
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
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
|
-
```
|