dynamodb-reactive 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,174 @@
1
+ # **dynamodb-reactive**
2
+
3
+ **Tagline:** A Serverless, Reactive tRPC replacement for AWS - unified package.
4
+
5
+ ## **1. Overview**
6
+
7
+ `dynamodb-reactive` provides type-safe, real-time DynamoDB subscriptions with automatic JSON Patch diffing over WebSockets.
8
+
9
+ **Key Features:**
10
+
11
+ * **Full TypeScript Support:** End-to-end type safety from schema definition to React hooks.
12
+
13
+ ## **2. Installation**
14
+
15
+ ```bash
16
+ npm install dynamodb-reactive zod
17
+ # or
18
+ pnpm add dynamodb-reactive zod
19
+ ```
20
+
21
+ **Peer Dependencies (install as needed):**
22
+
23
+ | Dependency | Required For |
24
+ | :--- | :--- |
25
+ | `zod` | Schema definitions (required) |
26
+ | `react` | React hooks |
27
+ | `aws-cdk-lib` | Infrastructure |
28
+ | `constructs` | Infrastructure |
29
+
30
+ ## **3. Package Exports**
31
+
32
+ | Import Path | Purpose |
33
+ | :--- | :--- |
34
+ | `dynamodb-reactive` | Core exports (DynamoTable, schemas) |
35
+ | `dynamodb-reactive/core` | Core table definitions |
36
+ | `dynamodb-reactive/server` | Server runtime (Router, handlers) |
37
+ | `dynamodb-reactive/client` | Frontend client |
38
+ | `dynamodb-reactive/react` | React hooks |
39
+ | `dynamodb-reactive/infra` | CDK constructs |
40
+
41
+ ## **4. Quick Start**
42
+
43
+ ### **Step 1: Define Your Schema**
44
+
45
+ ```typescript
46
+ import { z } from 'zod';
47
+ import { DynamoTable } from 'dynamodb-reactive/core';
48
+
49
+ export const TodoTable = new DynamoTable({
50
+ tableName: 'my-table',
51
+ schema: z.object({
52
+ PK: z.string(),
53
+ SK: z.string(),
54
+ id: z.string(),
55
+ text: z.string(),
56
+ completed: z.boolean(),
57
+ createdAt: z.number(),
58
+ }),
59
+ pk: 'PK',
60
+ sk: 'SK',
61
+ });
62
+ ```
63
+
64
+ ### **Step 2: Create the Router**
65
+
66
+ ```typescript
67
+ import { z } from 'zod';
68
+ import { initReactive } from 'dynamodb-reactive/server';
69
+ import { TodoTable } from './schema';
70
+
71
+ type AppContext = Record<string, unknown>;
72
+ const t = initReactive<AppContext>();
73
+
74
+ export const appRouter = t.router({
75
+ todos: {
76
+ // Query procedure
77
+ list: t.procedure
78
+ .input(z.object({}).optional())
79
+ .query(async ({ ctx }) => {
80
+ return ctx.db
81
+ .query(TodoTable)
82
+ .filter((q) => q.eq(TodoTable.field.PK, 'TODO'))
83
+ .execute();
84
+ }),
85
+
86
+ // Mutation procedure
87
+ create: t.procedure
88
+ .input(z.object({ text: z.string() }))
89
+ .mutation(async ({ ctx, input }) => {
90
+ const item = {
91
+ PK: 'TODO',
92
+ SK: Date.now().toString(),
93
+ id: Date.now().toString(),
94
+ text: input.text,
95
+ completed: false,
96
+ createdAt: Date.now(),
97
+ };
98
+ await ctx.db.put(TodoTable, item);
99
+ return item;
100
+ }),
101
+ },
102
+ });
103
+
104
+ export type AppRouter = typeof appRouter;
105
+ ```
106
+
107
+ ### **Step 3: Create API Handler**
108
+
109
+ ```typescript
110
+ import { createReactiveHandler } from 'dynamodb-reactive/server';
111
+ import { appRouter } from './router';
112
+
113
+ export const handler = createReactiveHandler({
114
+ router: appRouter,
115
+ dbConfig: { region: 'us-east-1' },
116
+ getContext: async () => ({}),
117
+ });
118
+
119
+ // In Next.js API route:
120
+ export async function POST(request: Request) {
121
+ const body = await request.json();
122
+ const response = await handler.handleRequest('client-id', body);
123
+ return Response.json(response);
124
+ }
125
+ ```
126
+
127
+ ### **Step 4: Call from Client**
128
+
129
+ ```typescript
130
+ // Query
131
+ const response = await fetch('/api/reactive', {
132
+ method: 'POST',
133
+ body: JSON.stringify({
134
+ type: 'subscribe',
135
+ subscriptionId: 'sub-1',
136
+ path: 'todos.list',
137
+ input: {},
138
+ }),
139
+ });
140
+ const { data } = await response.json();
141
+
142
+ // Mutation
143
+ const response = await fetch('/api/reactive', {
144
+ method: 'POST',
145
+ body: JSON.stringify({
146
+ type: 'call',
147
+ callId: 'call-1',
148
+ path: 'todos.create',
149
+ input: { text: 'New todo' },
150
+ }),
151
+ });
152
+ const { data } = await response.json();
153
+ ```
154
+
155
+ ## **5. Database Context Methods**
156
+
157
+ The `ctx.db` object provides these methods:
158
+
159
+ | Method | Description |
160
+ | :--- | :--- |
161
+ | `query(table).filter(...).execute()` | Query with filters |
162
+ | `get(table, key)` | Get single item by key |
163
+ | `put(table, item)` | Create/replace item |
164
+ | `update(table, key, updates)` | Update item fields |
165
+ | `delete(table, key)` | Delete item |
166
+
167
+ ## **6. Requirements**
168
+
169
+ * Node.js >= 18.0.0
170
+ * TypeScript >= 5.3.0
171
+
172
+ ## **7. License**
173
+
174
+ MIT
@@ -0,0 +1,2 @@
1
+ export * from '@dynamodb-reactive/client';
2
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
package/dist/client.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("@dynamodb-reactive/client"), exports);
18
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C"}
package/dist/core.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from '@dynamodb-reactive/core';
2
+ //# sourceMappingURL=core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
package/dist/core.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("@dynamodb-reactive/core"), exports);
18
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC"}
@@ -0,0 +1,2 @@
1
+ export * from '@dynamodb-reactive/core';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("@dynamodb-reactive/core"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC"}
@@ -0,0 +1,2 @@
1
+ export * from '@dynamodb-reactive/infra';
2
+ //# sourceMappingURL=infra.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"infra.d.ts","sourceRoot":"","sources":["../src/infra.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
package/dist/infra.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("@dynamodb-reactive/infra"), exports);
18
+ //# sourceMappingURL=infra.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"infra.js","sourceRoot":"","sources":["../src/infra.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC"}
@@ -0,0 +1,2 @@
1
+ export * from '@dynamodb-reactive/client/react';
2
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC"}
package/dist/react.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("@dynamodb-reactive/client/react"), exports);
18
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kEAAgD"}
@@ -0,0 +1,2 @@
1
+ export * from '@dynamodb-reactive/server';
2
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
package/dist/server.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("@dynamodb-reactive/server"), exports);
18
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C"}
package/package.json ADDED
@@ -0,0 +1,102 @@
1
+ {
2
+ "name": "dynamodb-reactive",
3
+ "version": "0.1.0",
4
+ "description": "A Serverless, Reactive tRPC replacement for AWS DynamoDB",
5
+ "keywords": [
6
+ "dynamodb",
7
+ "reactive",
8
+ "realtime",
9
+ "websocket",
10
+ "aws",
11
+ "serverless",
12
+ "trpc",
13
+ "typescript"
14
+ ],
15
+ "license": "MIT",
16
+ "author": "andreigec@gmail.com",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": ""
20
+ },
21
+ "main": "./dist/index.js",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js",
28
+ "default": "./dist/index.js"
29
+ },
30
+ "./client": {
31
+ "types": "./dist/client.d.ts",
32
+ "import": "./dist/client.js",
33
+ "default": "./dist/client.js"
34
+ },
35
+ "./react": {
36
+ "types": "./dist/react.d.ts",
37
+ "import": "./dist/react.js",
38
+ "default": "./dist/react.js"
39
+ },
40
+ "./server": {
41
+ "types": "./dist/server.d.ts",
42
+ "import": "./dist/server.js",
43
+ "default": "./dist/server.js"
44
+ },
45
+ "./core": {
46
+ "types": "./dist/core.d.ts",
47
+ "import": "./dist/core.js",
48
+ "default": "./dist/core.js"
49
+ },
50
+ "./infra": {
51
+ "types": "./dist/infra.d.ts",
52
+ "import": "./dist/infra.js",
53
+ "default": "./dist/infra.js"
54
+ }
55
+ },
56
+ "files": [
57
+ "dist",
58
+ "!**/*.spec.*",
59
+ "!**/*.test.*"
60
+ ],
61
+ "dependencies": {
62
+ "@dynamodb-reactive/core": "0.1.0",
63
+ "@dynamodb-reactive/client": "0.1.0",
64
+ "@dynamodb-reactive/server": "0.1.0",
65
+ "@dynamodb-reactive/infra": "0.1.0"
66
+ },
67
+ "devDependencies": {
68
+ "rimraf": "^5.0.0",
69
+ "typescript": "^5.3.0",
70
+ "eslint": "8.57.1"
71
+ },
72
+ "peerDependencies": {
73
+ "zod": "^3.22.0",
74
+ "react": "^18.0.0",
75
+ "aws-cdk-lib": "^2.115.0",
76
+ "constructs": "^10.3.0"
77
+ },
78
+ "peerDependenciesMeta": {
79
+ "react": {
80
+ "optional": true
81
+ },
82
+ "aws-cdk-lib": {
83
+ "optional": true
84
+ },
85
+ "constructs": {
86
+ "optional": true
87
+ }
88
+ },
89
+ "publishConfig": {
90
+ "access": "public"
91
+ },
92
+ "engines": {
93
+ "node": ">=18.0.0"
94
+ },
95
+ "sideEffects": false,
96
+ "scripts": {
97
+ "build": "tsc",
98
+ "clean": "rimraf dist",
99
+ "typecheck": "tsc --noEmit",
100
+ "format": "eslint src --fix"
101
+ }
102
+ }