@exabugs/dynamodb-client 0.1.1 → 0.2.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +216 -187
  3. package/dist/client/Collection.d.ts +14 -9
  4. package/dist/client/Collection.d.ts.map +1 -1
  5. package/dist/client/Collection.js +3 -9
  6. package/dist/client/Collection.js.map +1 -1
  7. package/dist/client/Database.d.ts +1 -3
  8. package/dist/client/Database.d.ts.map +1 -1
  9. package/dist/client/Database.js +2 -7
  10. package/dist/client/Database.js.map +1 -1
  11. package/dist/client/DynamoClient.d.ts +1 -1
  12. package/dist/client/DynamoClient.d.ts.map +1 -1
  13. package/dist/client/DynamoClient.js +2 -5
  14. package/dist/client/DynamoClient.js.map +1 -1
  15. package/dist/client/FindCursor.d.ts +1 -3
  16. package/dist/client/FindCursor.d.ts.map +1 -1
  17. package/dist/client/FindCursor.js +1 -5
  18. package/dist/client/FindCursor.js.map +1 -1
  19. package/dist/client/index.iam.d.ts +1 -1
  20. package/dist/client/index.iam.d.ts.map +1 -1
  21. package/dist/client/index.iam.js.map +1 -1
  22. package/dist/integrations/react-admin/dataProvider.d.ts +0 -1
  23. package/dist/integrations/react-admin/dataProvider.d.ts.map +1 -1
  24. package/dist/integrations/react-admin/dataProvider.js +10 -11
  25. package/dist/integrations/react-admin/dataProvider.js.map +1 -1
  26. package/dist/integrations/react-admin/types.d.ts +0 -2
  27. package/dist/integrations/react-admin/types.d.ts.map +1 -1
  28. package/dist/scripts/generate-shadow-config.d.ts +3 -0
  29. package/dist/scripts/generate-shadow-config.d.ts.map +1 -0
  30. package/dist/scripts/generate-shadow-config.js +159 -0
  31. package/dist/scripts/generate-shadow-config.js.map +1 -0
  32. package/dist/scripts/repair-shadows.js +1 -1
  33. package/dist/scripts/repair-shadows.js.map +1 -1
  34. package/dist/server/handler.cjs +2 -2
  35. package/dist/shadows/generator.d.ts +14 -3
  36. package/dist/shadows/generator.d.ts.map +1 -1
  37. package/dist/shadows/generator.js +19 -0
  38. package/dist/shadows/generator.js.map +1 -1
  39. package/dist/shadows/index.d.ts +3 -2
  40. package/dist/shadows/index.d.ts.map +1 -1
  41. package/dist/shadows/index.js +1 -1
  42. package/dist/shadows/index.js.map +1 -1
  43. package/dist/shadows/schema.d.ts +60 -0
  44. package/dist/shadows/schema.d.ts.map +1 -0
  45. package/dist/shadows/schema.js +8 -0
  46. package/dist/shadows/schema.js.map +1 -0
  47. package/dist/shadows/types.d.ts +1 -5
  48. package/dist/shadows/types.d.ts.map +1 -1
  49. package/package.json +7 -4
  50. package/terraform/examples/advanced/README.md +0 -129
  51. package/terraform/examples/advanced/main.tf +0 -158
  52. package/terraform/examples/advanced/shadow.config.json +0 -35
  53. package/terraform/examples/advanced/variables.tf +0 -28
  54. package/terraform/examples/basic/README.md +0 -53
  55. package/terraform/examples/basic/main.tf +0 -99
  56. package/terraform/examples/basic/variables.tf +0 -17
package/CHANGELOG.md CHANGED
@@ -7,6 +7,63 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.0] - 2024-12-01
11
+
12
+ ### Changed
13
+
14
+ - **BREAKING**: Removed `databaseName` parameter from all APIs
15
+ - `DynamoClient.db()` no longer requires a database name argument
16
+ - `createDataProvider()` no longer requires `databaseName` option
17
+ - `Database` class no longer stores or uses database name
18
+ - `Collection` and `FindCursor` no longer include database name in requests
19
+ - Simplified architecture: DynamoDB table is 1:1 with Lambda function
20
+ - For multi-tenant use cases, use separate DynamoDB tables instead
21
+
22
+ ### Migration Guide
23
+
24
+ **Before (v0.1.x):**
25
+ ```typescript
26
+ const client = new DynamoClient(apiUrl);
27
+ await client.connect();
28
+ const db = client.db('myapp');
29
+ const collection = db.collection('users');
30
+
31
+ const dataProvider = createDataProvider({
32
+ apiUrl: 'https://...',
33
+ databaseName: 'myapp',
34
+ tokenProvider,
35
+ });
36
+ ```
37
+
38
+ **After (v0.2.0):**
39
+ ```typescript
40
+ const client = new DynamoClient(apiUrl);
41
+ await client.connect();
42
+ const db = client.db();
43
+ const collection = db.collection('users');
44
+
45
+ const dataProvider = createDataProvider({
46
+ apiUrl: 'https://...',
47
+ tokenProvider,
48
+ });
49
+ ```
50
+
51
+ ## [0.1.2] - 2024-11-30
52
+
53
+ ### Added
54
+
55
+ - Boolean type support for shadow fields
56
+ - Added `'boolean'` to `ShadowFieldType`
57
+ - Added `formatBoolean()` function for boolean value formatting
58
+ - Boolean values are formatted as `'true'` or `'false'` strings
59
+ - Full test coverage for boolean shadow records
60
+
61
+ ### Changed
62
+
63
+ - Updated `formatFieldValue()` to handle boolean type
64
+ - Updated `generateShadowSK()` to support boolean values
65
+ - Exported `formatBoolean` from shadows module
66
+
10
67
  ## [0.1.0] - 2024-11-29
11
68
 
12
69
  ### Added
package/README.md CHANGED
@@ -1,267 +1,296 @@
1
- # DynamoDB Client SDK
1
+ <div align="center">
2
+
3
+ # 🚀 DynamoDB Client SDK
4
+
5
+ **MongoDB-like API for DynamoDB with Single-Table Design**
2
6
 
3
7
  [![CI](https://github.com/exabugs/dynamodb-client/actions/workflows/ci.yml/badge.svg)](https://github.com/exabugs/dynamodb-client/actions/workflows/ci.yml)
8
+ [![codecov](https://codecov.io/gh/exabugs/dynamodb-client/branch/main/graph/badge.svg)](https://codecov.io/gh/exabugs/dynamodb-client)
4
9
  [![npm version](https://badge.fury.io/js/@exabugs%2Fdynamodb-client.svg)](https://www.npmjs.com/package/@exabugs/dynamodb-client)
10
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
11
+ [![Node.js Version](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen)](https://nodejs.org/)
5
12
 
6
- DynamoDB Single-Table Client SDK with MongoDB-like API, Shadow Records, and Lambda implementation for serverless applications.
13
+ [Features](#-features)
14
+ [Installation](#-installation) •
15
+ [Quick Start](#-quick-start) •
16
+ [Documentation](#-documentation) •
17
+ [Contributing](#-contributing)
7
18
 
8
- ## Features
19
+ </div>
9
20
 
10
- - 🚀 MongoDB-like API for DynamoDB
11
- - 📦 Single-Table Design with Shadow Records
12
- - 🔐 Multiple authentication methods (IAM, Cognito, Token)
13
- - ⚡ Lambda function implementation included
14
- - 🎨 react-admin integration
15
- - 📝 TypeScript support
16
- - 🏗️ Terraform modules for deployment
21
+ ---
17
22
 
18
- ## Installation
19
-
20
- ```bash
21
- npm install @exabugs/dynamodb-client
22
- # or
23
- pnpm add @exabugs/dynamodb-client
24
- # or
25
- yarn add @exabugs/dynamodb-client
26
- ```
23
+ ## ✨ Features
27
24
 
28
- ## Quick Start
25
+ <table>
26
+ <tr>
27
+ <td width="50%">
29
28
 
30
- ### Client Usage (IAM Authentication)
29
+ ### 🎯 Developer Experience
31
30
 
32
- ```typescript
33
- import { DynamoClient } from '@exabugs/dynamodb-client/client/iam';
31
+ - **MongoDB-like API** - Familiar syntax for DynamoDB
32
+ - **TypeScript First** - Full type safety out of the box
33
+ - **Zero Config** - Works with sensible defaults
34
+ - **Terraform Ready** - Infrastructure as Code included
34
35
 
35
- const client = new DynamoClient(FUNCTION_URL, {
36
- region: 'ap-northeast-1',
37
- });
36
+ </td>
37
+ <td width="50%">
38
38
 
39
- const db = client.db();
40
- const collection = db.collection('articles');
39
+ ### Performance & Scale
41
40
 
42
- // Create
43
- await collection.insertOne({ title: 'Hello World', content: '...' });
41
+ - **Single-Table Design** - Optimized data modeling
42
+ - **Shadow Records** - Efficient sorting without GSIs
43
+ - **Lambda Native** - Serverless-first architecture
44
+ - **ARM64 Support** - Cost-optimized compute
44
45
 
45
- // Read
46
- const article = await collection.findOne({ title: 'Hello World' });
46
+ </td>
47
+ </tr>
48
+ <tr>
49
+ <td width="50%">
47
50
 
48
- // Update
49
- await collection.updateOne({ id: article.id }, { $set: { status: 'published' } });
51
+ ### 🔐 Authentication
50
52
 
51
- // Delete
52
- await collection.deleteOne({ id: article.id });
53
- ```
53
+ - **IAM Roles** - Native AWS authentication
54
+ - **Cognito** - User pool integration
55
+ - **Custom Tokens** - Flexible auth strategies
56
+ - **OIDC + PKCE** - Secure browser flows
54
57
 
55
- ### Server Usage (Lambda Function)
58
+ </td>
59
+ <td width="50%">
56
60
 
57
- ```typescript
58
- import { createHandler } from '@exabugs/dynamodb-client/server/handler';
61
+ ### 🎨 Integrations
59
62
 
60
- export const handler = createHandler({
61
- tableName: process.env.TABLE_NAME!,
62
- region: process.env.AWS_REGION!,
63
- });
64
- ```
63
+ - **react-admin** - Admin UI out of the box
64
+ - **REST API** - Lambda Function URLs
65
+ - **Terraform** - Complete IaC modules
65
66
 
66
- ## Requirements
67
+ </td>
68
+ </tr>
69
+ </table>
67
70
 
68
- - Node.js >= 18.0.0
69
- - AWS Account (for DynamoDB and Lambda)
71
+ ---
70
72
 
71
- ## Development
73
+ ## 📦 Installation
72
74
 
73
75
  ```bash
74
- # Install dependencies
75
- npm install
76
+ # npm
77
+ npm install @exabugs/dynamodb-client
76
78
 
77
- # Run tests
78
- npm test
79
+ # pnpm (recommended)
80
+ pnpm add @exabugs/dynamodb-client
79
81
 
80
- # Run tests with coverage
81
- npm run test:coverage
82
+ # yarn
83
+ yarn add @exabugs/dynamodb-client
84
+ ```
82
85
 
83
- # Build
84
- npm run build
86
+ ---
85
87
 
86
- # Lint
87
- npm run lint
88
+ ## 🏗️ Architecture
88
89
 
89
- # Format
90
- npm run format
91
- ```
90
+ ```mermaid
91
+ graph TB
92
+ subgraph "Client Applications"
93
+ A[React Admin]
94
+ B[Mobile App]
95
+ C[Custom App]
96
+ end
92
97
 
93
- ### 主要コマンド
98
+ subgraph "AWS Lambda"
99
+ D[Lambda Function<br/>Function URL]
100
+ end
94
101
 
95
- ```bash
96
- # ヘルプを表示
97
- make help
98
-
99
- # 開発
100
- make install # 依存関係のインストール
101
- make build # 全パッケージとLambda関数のビルド
102
- make test # 全パッケージのテスト実行
103
- make lint # Lint実行
104
- make format # フォーマット実行
105
- make clean # ビルド成果物の削除
106
-
107
- # デプロイ
108
- make deploy-dev # dev環境にデプロイ
109
- make deploy-stg # stg環境にデプロイ
110
- make deploy-prd # prd環境にデプロイ
111
-
112
- # インフラ操作
113
- make infra-plan ENV=dev # Terraformプランを表示
114
- make infra-apply ENV=dev # Terraformを適用
115
- make infra-status # Terraform状態を表示
116
-
117
- # Lambda操作
118
- make invoke-fetch ENV=dev # Fetch Lambdaを実行
119
- make logs-fetch ENV=dev # Fetch Lambdaのログを表示
120
- make logs-records ENV=dev # Records Lambdaのログを表示
121
-
122
- # その他
123
- make shadow-config # shadow.config.jsonを再生成
102
+ subgraph "AWS DynamoDB"
103
+ E[(DynamoDB<br/>Single Table)]
104
+ end
105
+
106
+ A -->|HTTPS| D
107
+ B -->|HTTPS| D
108
+ C -->|HTTPS| D
109
+ D -->|AWS SDK| E
110
+
111
+ style A fill:#61dafb,stroke:#333,stroke-width:2px
112
+ style B fill:#61dafb,stroke:#333,stroke-width:2px
113
+ style C fill:#61dafb,stroke:#333,stroke-width:2px
114
+ style D fill:#ff9900,stroke:#333,stroke-width:2px
115
+ style E fill:#527fff,stroke:#333,stroke-width:2px
124
116
  ```
125
117
 
126
- ### 個別Makefileの使用
118
+ ---
127
119
 
128
- 各Lambda関数には個別のMakefileも用意されています:
120
+ ## 🚀 Quick Start & Examples
129
121
 
130
- ```bash
131
- # Fetch Lambda
132
- cd functions/fetch
133
- make help
134
- make build
135
- make deploy ENV=dev
136
- make invoke
137
- make logs
138
-
139
- # Terraform
140
- cd infra
141
- make help
142
- make plan ENV=dev
143
- make apply ENV=dev
144
- make status
122
+ Get started in 3 steps: **Schema Definition → Deploy Infrastructure → Use Client**
123
+
124
+ ### Complete Examples Available
125
+
126
+ We provide complete, working examples for every step:
127
+
128
+ | Example | What You'll Learn | Time |
129
+ | ------------------------------------------ | ---------------------------------------------------- | ------ |
130
+ | **[Schema](./examples/schema/)** | Define TypeScript schemas and generate shadow config | 5 min |
131
+ | **[Terraform](./examples/terraform/)** | Deploy Lambda + DynamoDB + Cognito to AWS | 10 min |
132
+ | **[Client](./examples/client/)** | Node.js CRUD operations with MongoDB-like API | 10 min |
133
+ | **[React Admin](./examples/react-admin/)** | Build complete admin UI with authentication | 15 min |
134
+
135
+ ### Quick Example
136
+
137
+ ```typescript
138
+ // 1. Define schema
139
+ export const MySchema: SchemaRegistryConfig = {
140
+ database: {
141
+ timestamps: {
142
+ createdAt: 'createdAt',
143
+ updatedAt: 'updatedAt',
144
+ },
145
+ },
146
+ resources: {
147
+ articles: {
148
+ resource: 'articles',
149
+ type: {} as Article,
150
+ shadows: { sortableFields: { title: { type: 'string' } } },
151
+ },
152
+ },
153
+ };
154
+
155
+ // 2. Deploy with Terraform (see examples/terraform/)
156
+ // terraform apply
157
+
158
+ // 3. Use the client
159
+ const client = new DynamoClient(FUNCTION_URL);
160
+ const articles = client.db().collection('articles');
161
+
162
+ await articles.insertOne({ title: 'Hello DynamoDB' });
163
+ const article = await articles.findOne({ title: 'Hello DynamoDB' });
145
164
  ```
146
165
 
147
- 詳細は[Makefile運用ガイドライン](.kiro/steering/makefile-operations.md)を参照してください。
166
+ ### 📚 Full Documentation
148
167
 
149
- ## Records Lambda
168
+ 👉 **[Complete Examples Guide →](./examples/)** - Step-by-step tutorials with full source code
150
169
 
151
- Records Lambdaは`@exabugs/dynamodb-client`ライブラリに統合されています。
170
+ Each example includes:
152
171
 
153
- 詳細は[packages/core/README.md](packages/core/README.md)を参照してください。
172
+ - ✅ Complete source code
173
+ - ✅ Step-by-step instructions
174
+ - ✅ Terraform integration
175
+ - ✅ Configuration templates
154
176
 
155
- ## ワークスペース構成
177
+ ---
156
178
 
157
- ```
158
- .
159
- ├── apps/ # アプリケーション (Admin UI, Mobile App)
160
- ├── functions/ # Lambda関数 (Fetch, Pipeline, Maintenance)
161
- ├── packages/ # 共有ライブラリ (core, shadows, graphql-types)
162
- │ └── core/ # Records Lambda(サーバー実装)を含む
163
- └── infra/ # Terraform設定
164
- ```
179
+ ## 📚 Documentation
165
180
 
166
- **注**: Records Lambdaは`packages/core/`に統合されています。
181
+ ### Available Documentation
167
182
 
168
- ## Admin UI 開発・デプロイ
183
+ - **[Architecture](docs/ARCHITECTURE.md)** - System architecture and design
184
+ - **[Client Usage](docs/CLIENT_USAGE.md)** - Client-side API guide
185
+ - **[React Admin Integration](docs/react-admin-integration.md)** - Admin UI setup
186
+ - **[Deployment](docs/DEPLOYMENT.md)** - Production deployment guide
187
+ - **[Terraform Modules](terraform/README.md)** - Infrastructure as Code
169
188
 
170
- ### ローカル開発
189
+ ### GitHub Actions
171
190
 
172
- ```bash
173
- # 開発サーバー起動
174
- pnpm --filter @ainews/admin dev
191
+ - **[GitHub Actions Setup](docs/GITHUB_ACTIONS_SETUP.md)** - CI/CD configuration
192
+ - **[Troubleshooting](docs/GITHUB_ACTIONS_TROUBLESHOOTING.md)** - Common issues and solutions
175
193
 
176
- # ブラウザで http://localhost:3000 にアクセス
177
- ```
194
+ ---
178
195
 
179
- ### 環境変数設定
196
+ ## 🛠️ Development
197
+
198
+ ### Prerequisites
199
+
200
+ - Node.js >= 18.0.0
201
+ - npm, pnpm, or yarn
202
+ - AWS Account (for deployment)
180
203
 
181
- `apps/admin/.env`ファイルを作成:
204
+ ### Setup
182
205
 
183
206
  ```bash
184
- # Records Lambda Function URL
185
- VITE_RECORDS_API_URL=https://xxxxx.lambda-url.us-east-1.on.aws/
207
+ # Clone repository
208
+ git clone https://github.com/exabugs/dynamodb-client.git
209
+ cd dynamodb-client
186
210
 
187
- # Cognito User Pool設定
188
- VITE_COGNITO_USER_POOL_ID=us-east-1_xxxxxxxxx
189
- VITE_COGNITO_USER_POOL_CLIENT_ID=xxxxxxxxxxxxxxxxxxxxxxxxxx
190
- VITE_COGNITO_DOMAIN=ainews-dev-auth.auth.us-east-1.amazoncognito.com
191
- VITE_COGNITO_REGION=us-east-1
211
+ # Install dependencies
212
+ npm install
192
213
 
193
- # 開発環境で認証を無効化する場合のみ(本番環境では必ずfalse)
194
- VITE_DISABLE_AUTH=false
214
+ # Run tests
215
+ npm test
216
+
217
+ # Build
218
+ npm run build
195
219
  ```
196
220
 
197
- ### 重要な設定
221
+ ### Available Commands
198
222
 
199
- **必須**: Admin UIは**BrowserRouter**を使用します。HashRouterは使用しないでください。
223
+ ```bash
224
+ npm test # Run tests
225
+ npm run test:coverage # Run tests with coverage
226
+ npm run lint # Lint code
227
+ npm run format # Format code
228
+ npm run build # Build package
229
+ npm run clean # Clean build artifacts
230
+ ```
200
231
 
201
- 理由:
232
+ ---
202
233
 
203
- - Cognito Hosted UIの認証コールバックがクエリパラメータ(`?code=xxx`)を使用
204
- - HashRouter(`#/`)ではクエリパラメータが正しく処理されない
234
+ ## 🚢 Deployment
205
235
 
206
- ### 本番デプロイ(CloudFront)
236
+ ### Using Terraform
207
237
 
208
- CloudFront経由で配信する場合、以下の設定が必要です:
238
+ ```bash
239
+ cd terraform
240
+ terraform init
241
+ terraform plan -var-file=envs/dev.tfvars
242
+ terraform apply -var-file=envs/dev.tfvars
243
+ ```
209
244
 
210
- 1. **エラーページ設定**: 404/403エラーを`/index.html`にリダイレクト(SPA対応)
211
- 2. **キャッシュ設定**:
212
- - `index.html`: キャッシュしない(TTL=0)
213
- - 静的アセット(JS/CSS/画像): 長期キャッシュ(TTL=7日〜1年)
214
- 3. **Cognitoコールバック URL**: 本番ドメインを追加
245
+ ### Using Make
215
246
 
216
- 詳細は[設計書](.kiro/specs/ainews-pipeline/design.md)の「Admin UI 重要な設定」セクションを参照してください。
247
+ ```bash
248
+ make deploy-dev # Deploy to dev environment
249
+ make deploy-stg # Deploy to staging
250
+ make deploy-prd # Deploy to production
251
+ ```
217
252
 
218
- ### トラブルシューティング
253
+ ---
219
254
 
220
- #### CORSエラーが発生する場合
255
+ ## 🤝 Contributing
221
256
 
222
- 1. **Lambda関数を最新版にデプロイ**:
257
+ We welcome contributions!
223
258
 
224
- ```bash
225
- cd functions/records
226
- pnpm build
227
- cd ../../infra
228
- terraform apply -var-file=envs/dev.tfvars
229
- ```
259
+ ### Development Workflow
230
260
 
231
- 2. **ブラウザのキャッシュをクリア**: Cmd+Shift+R (Mac) または Ctrl+Shift+R (Windows/Linux)
261
+ 1. Fork the repository
262
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
263
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
264
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
265
+ 5. Open a Pull Request
232
266
 
233
- 3. **Lambda Function URLのCORS設定を確認**: `infra/modules/api/lambda-records/main.tf`
267
+ ### Guidelines
234
268
 
235
- **重要**: Lambda Function URLのCORS設定を使用するため、Lambda関数のハンドラーではCORSヘッダーを設定しません。
269
+ - Follow the existing code style
270
+ - Add tests for new features
271
+ - Update documentation as needed
272
+ - Ensure all tests pass before submitting
236
273
 
237
- #### Cognito Hosted UIでログインできない場合
274
+ ---
238
275
 
239
- 1. **開発サーバーのポートを確認**: `http://localhost:3000` で起動していることを確認
240
- - Vite設定で `strictPort: true` が設定されているため、ポート3000が使用中の場合はエラーになります
241
- - 他のプロセスがポート3000を使用していないか確認してください
276
+ ## 📄 License
242
277
 
243
- 2. **Cognitoのコールバック/ログアウトURLを確認**: `infra/envs/dev.tfvars`
278
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
244
279
 
245
- ```hcl
246
- admin_callback_urls = [
247
- "http://localhost:3000",
248
- "http://localhost:3000/callback",
249
- ...
250
- ]
251
- ```
280
+ ---
252
281
 
253
- 3. **ブラウザのローカルストレージをクリア**: 古いセッション情報が残っている可能性があります
282
+ ## 🙏 Acknowledgments
254
283
 
255
- ## ドキュメント
284
+ - Built with [AWS SDK for JavaScript](https://aws.amazon.com/sdk-for-javascript/)
285
+ - Inspired by [MongoDB](https://www.mongodb.com/) API design
286
+ - Powered by [TypeScript](https://www.typescriptlang.org/)
256
287
 
257
- 詳細な設計・要件については以下を参照してください:
288
+ ---
258
289
 
259
- - [要件定義書](.kiro/specs/ainews-pipeline/requirements.md)
260
- - [設計書](.kiro/specs/ainews-pipeline/design.md)
261
- - [実装タスクリスト](.kiro/specs/ainews-pipeline/tasks.md)
290
+ <div align="center">
262
291
 
263
- ## ライセンス
292
+ **[⬆ back to top](#-dynamodb-client-sdk)**
264
293
 
265
- MIT License - 詳細は [LICENSE](LICENSE) ファイルを参照してください。
294
+ Made with ❤️ by [exabugs](https://github.com/exabugs)
266
295
 
267
- Copyright (c) 2024 exabugs
296
+ </div>
@@ -11,9 +11,16 @@ import { FindCursor } from './FindCursor.js';
11
11
  */
12
12
  export type AuthHeadersGetter<TAuthOptions = unknown> = (endpoint: string, body: string, authOptions?: TAuthOptions) => Promise<Record<string, string>>;
13
13
  /**
14
- * コレクションのドキュメント型の基本インターフェース
14
+ * ドキュメント入力型の基本インターフェース(id はオプショナル)
15
15
  */
16
- export interface DocumentBase {
16
+ export interface InputBase {
17
+ id?: string;
18
+ [key: string]: unknown;
19
+ }
20
+ /**
21
+ * ドキュメント結果型の基本インターフェース(id は必須)
22
+ */
23
+ export interface ResultBase {
17
24
  id: string;
18
25
  [key: string]: unknown;
19
26
  }
@@ -23,21 +30,19 @@ export interface DocumentBase {
23
30
  * MongoDB風のCRUD操作を提供します。
24
31
  * 型安全なフィルタとクエリAPIでDynamoDBを操作できます。
25
32
  *
26
- * @template TSchema - コレクションのドキュメント型
33
+ * @template TSchema - コレクションのドキュメント型(ResultBase を extends)
27
34
  * @template TAuthOptions - 認証オプションの型
28
35
  */
29
- export declare class Collection<TSchema extends DocumentBase = DocumentBase, TAuthOptions = unknown> {
36
+ export declare class Collection<TSchema extends ResultBase = ResultBase, TAuthOptions = unknown> {
30
37
  private endpoint;
31
- private databaseName;
32
38
  private collectionName;
33
39
  private authToken;
34
40
  private authOptions;
35
41
  private clientOptions;
36
42
  private getAuthHeaders;
37
- constructor(endpoint: string, databaseName: string, collectionName: string, authToken: string | undefined, authOptions: TAuthOptions | undefined, clientOptions: ClientOptions | undefined, getAuthHeaders: AuthHeadersGetter<TAuthOptions>);
43
+ constructor(endpoint: string, collectionName: string, authToken: string | undefined, authOptions: TAuthOptions | undefined, clientOptions: ClientOptions | undefined, getAuthHeaders: AuthHeadersGetter<TAuthOptions>);
38
44
  getName(): string;
39
45
  getEndpoint(): string;
40
- getDatabaseName(): string;
41
46
  getAuthToken(): string | undefined;
42
47
  getAuthOptions(): TAuthOptions | undefined;
43
48
  /**
@@ -47,8 +52,8 @@ export declare class Collection<TSchema extends DocumentBase = DocumentBase, TAu
47
52
  find(filter?: Filter<TSchema>, options?: FindOptions): FindCursor<TSchema, TAuthOptions>;
48
53
  findOne(filter: Filter<TSchema>): Promise<TSchema | null>;
49
54
  findMany(ids: string[]): Promise<TSchema[]>;
50
- insertOne(document: TSchema): Promise<InsertOneResult>;
51
- insertMany(documents: TSchema[]): Promise<InsertManyResult>;
55
+ insertOne(document: InputBase & Omit<TSchema, 'id'>): Promise<InsertOneResult>;
56
+ insertMany(documents: (InputBase & Omit<TSchema, 'id'>)[]): Promise<InsertManyResult>;
52
57
  updateOne(filter: Filter<TSchema>, update: UpdateOperators<TSchema>): Promise<UpdateResult>;
53
58
  updateMany(filter: Filter<TSchema>, update: UpdateOperators<TSchema>): Promise<UpdateResult>;
54
59
  deleteOne(filter: Filter<TSchema>): Promise<DeleteResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../src/client/Collection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EACV,YAAY,EACZ,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,YAAY,EACb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,YAAY,GAAG,OAAO,IAAI,CACtD,QAAQ,EAAE,MAAM,EAChB,IA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AgB,CAAC;IAmBrF,SAAS,CACb,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EACvB,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,GAC/B,OAAO,CAAC,YAAY,CAAC;IAelB,UAAU,CACd,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EACvB,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,GAC/B,OAAO,CAAC,YAAY,CAAC;IAkBlB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;IASzD,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;CAUjE"}
@@ -5,20 +5,18 @@ import { FindCursor } from './FindCursor.js';
5
5
  * MongoDB風のCRUD操作を提供します。
6
6
  * 型安全なフィルタとクエリAPIでDynamoDBを操作できます。
7
7
  *
8
- * @template TSchema - コレクションのドキュメント型
8
+ * @template TSchema - コレクションのドキュメント型(ResultBase を extends)
9
9
  * @template TAuthOptions - 認証オプションの型
10
10
  */
11
11
  export class Collection {
12
12
  endpoint;
13
- databaseName;
14
13
  collectionName;
15
14
  authToken;
16
15
  authOptions;
17
16
  clientOptions;
18
17
  getAuthHeaders;
19
- constructor(endpoint, databaseName, collectionName, authToken, authOptions, clientOptions, getAuthHeaders) {
18
+ constructor(endpoint, collectionName, authToken, authOptions, clientOptions, getAuthHeaders) {
20
19
  this.endpoint = endpoint;
21
- this.databaseName = databaseName;
22
20
  this.collectionName = collectionName;
23
21
  this.authToken = authToken;
24
22
  this.authOptions = authOptions;
@@ -31,9 +29,6 @@ export class Collection {
31
29
  getEndpoint() {
32
30
  return this.endpoint;
33
31
  }
34
- getDatabaseName() {
35
- return this.databaseName;
36
- }
37
32
  getAuthToken() {
38
33
  return this.authToken;
39
34
  }
@@ -46,7 +41,6 @@ export class Collection {
46
41
  async request(operation, params) {
47
42
  const requestBody = JSON.stringify({
48
43
  operation,
49
- database: this.databaseName,
50
44
  collection: this.collectionName,
51
45
  params,
52
46
  });
@@ -88,7 +82,7 @@ export class Collection {
88
82
  }
89
83
  }
90
84
  find(filter = {}, options) {
91
- return new FindCursor(this.endpoint, this.databaseName, this.collectionName, filter, options, this.authToken, this.authOptions, this.clientOptions, this.getAuthHeaders);
85
+ return new FindCursor(this.endpoint, this.collectionName, filter, options, this.authToken, this.authOptions, this.clientOptions, this.getAuthHeaders);
92
86
  }
93
87
  async findOne(filter) {
94
88
  const response = await this.request('findOne', { filter });