dynoquery 0.1.7 → 0.1.8

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 CHANGED
@@ -13,7 +13,6 @@ npm install dynoquery
13
13
  - Basic CRUD operations (create, get, update, delete)
14
14
  - Optimized for **Single-Table Design**
15
15
  - Query and Scan support
16
- - Batch operations (batchGet, batchWrite)
17
16
  - TypeScript support
18
17
 
19
18
  ## Usage
@@ -97,48 +96,6 @@ async function example() {
97
96
  }
98
97
  ```
99
98
 
100
- ### Batch Operations
101
-
102
- If you have a `tableName` configured in `DynoQuery`, you can use the `Items` property in `batchGet` and `batchWrite` to automatically target that table.
103
-
104
- You can also generate items for `batchGet` using the `batchGetInput` method from partitions and indexes:
105
-
106
- ```typescript
107
- const john = db.User('john@example.com');
108
- const jack = db.User('jack@example.com');
109
- const cat = db.ByCategory('1');
110
-
111
- const batchItem1 = john.batchGetInput('METADATA');
112
- const batchOthers = cat.batchGetInput('METADATA', 'DATA', 'PROFILE');
113
- const batchCat = cat.batchGetInput(); // No sk defined, so will get partition key only
114
-
115
- await db.batchGet(batchItem1, batchOthers, batchCat);
116
- ```
117
-
118
- ```typescript
119
- // batchGet with explicit Items
120
- await db.batchGet({
121
- Items: [
122
- { PK: 'USER#1', SK: 'METADATA' },
123
- { PK: 'USER#2', SK: 'METADATA' }
124
- ]
125
- });
126
-
127
- // batchWrite with simplified Items (automatically wrapped in PutRequest)
128
- await db.batchWrite({
129
- Items: [
130
- { PK: 'USER#3', SK: 'METADATA', name: 'Alice' },
131
- {
132
- DeleteRequest: {
133
- Key: { PK: 'USER#1', SK: 'SESSION#123' }
134
- }
135
- }
136
- ]
137
- });
138
- ```
139
-
140
- You can still use the standard AWS SDK `RequestItems` if you need to target multiple tables or if you prefer the original syntax.
141
-
142
99
  ## API Reference
143
100
 
144
101
  ### DynoQuery
@@ -149,8 +106,6 @@ The main client for interacting with DynamoDB.
149
106
  - `delete(params)`: Delete an item.
150
107
  - `query(params)`: Query items.
151
108
  - `scan(params)`: Scan items.
152
- - `batchGet(params)`: Batch get items.
153
- - `batchWrite(params)`: Batch write items.
154
109
 
155
110
  ### Partition
156
111
  A way to manage data within a specific partition.
@@ -160,9 +115,6 @@ A way to manage data within a specific partition.
160
115
  - `create(sk, data)`: Creates an item in the partition.
161
116
  - `update(sk, data)`: Updates an existing item (partial update).
162
117
  - `delete(sk)`: Deletes an item.
163
- - `batchGetInput(...sks)`: Generates items for batch query.
164
- - `batchWriteInput(...items)`: Generates items for batch write.
165
- - `batchDeleteInput(...sks)`: Generates items for batch delete.
166
118
  - `deleteAll()`: Deletes all items in the partition.
167
119
 
168
120
  ### IndexQuery
@@ -170,9 +122,6 @@ A way to query Global Secondary Indexes.
170
122
  - `getPkValue()`: Returns the generated partition key value for this index.
171
123
  - `get(skValue | options)`: Query items in the index. Supports `skValue` (string) for `begins_with` search, or an options object with `skValue`, `limit`, and `scanIndexForward`.
172
124
  - `getAll()`: Fetches all items in the index for the given partition key.
173
- - `batchGetInput(...sks)`: Generates items for batch query.
174
- - `batchWriteInput(...items)`: Generates items for batch write.
175
- - `batchDeleteInput(...sks)`: Generates items for batch delete.
176
125
  - Automatically identifies the model name in results using `__model` (based on registered models) and provides `getPartition()` helper.
177
126
 
178
127
  ## License
@@ -22,17 +22,5 @@ export declare class IndexQuery {
22
22
  }): Promise<T[]>;
23
23
  getAll<T = any>(): Promise<T[]>;
24
24
  getPkValue(): string;
25
- /**
26
- * Generates items for batch query.
27
- */
28
- batchGetInput(...sks: string[]): any[];
29
- /**
30
- * Generates items for batch write (put).
31
- */
32
- batchWriteInput(...items: any[]): any[];
33
- /**
34
- * Generates items for batch delete.
35
- */
36
- batchDeleteInput(...sks: string[]): any[];
37
25
  private mapItemToModel;
38
26
  }
@@ -71,49 +71,6 @@ class IndexQuery {
71
71
  getPkValue() {
72
72
  return this.pkValue;
73
73
  }
74
- /**
75
- * Generates items for batch query.
76
- */
77
- batchGetInput(...sks) {
78
- if (sks.length === 0) {
79
- return [{
80
- TableName: this.tableName,
81
- Key: { [this.pkName]: this.pkValue }
82
- }];
83
- }
84
- return sks.map(sk => ({
85
- TableName: this.tableName,
86
- Key: {
87
- [this.pkName]: this.pkValue,
88
- [this.skName]: sk
89
- }
90
- }));
91
- }
92
- /**
93
- * Generates items for batch write (put).
94
- */
95
- batchWriteInput(...items) {
96
- return items.map(item => ({
97
- TableName: this.tableName,
98
- PutRequest: {
99
- Item: Object.assign({ [this.pkName]: this.pkValue }, item)
100
- }
101
- }));
102
- }
103
- /**
104
- * Generates items for batch delete.
105
- */
106
- batchDeleteInput(...sks) {
107
- return sks.map(sk => ({
108
- TableName: this.tableName,
109
- DeleteRequest: {
110
- Key: {
111
- [this.pkName]: this.pkValue,
112
- [this.skName]: sk
113
- }
114
- }
115
- }));
116
- }
117
74
  mapItemToModel(item) {
118
75
  const pkName = this.db.getPkName();
119
76
  const pkValue = item[pkName];
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PutCommandInput, GetCommandInput, UpdateCommandInput, DeleteCommandInput, QueryCommandInput, ScanCommandInput, BatchGetCommandInput, BatchWriteCommandInput } from "@aws-sdk/lib-dynamodb";
1
+ import { PutCommandInput, GetCommandInput, UpdateCommandInput, DeleteCommandInput, QueryCommandInput, ScanCommandInput } from "@aws-sdk/lib-dynamodb";
2
2
  export interface DynoQueryConfig {
3
3
  tableName?: string;
4
4
  pkName?: string;
@@ -21,12 +21,6 @@ export interface DynoQueryConfig {
21
21
  pkPrefix?: string;
22
22
  }>;
23
23
  }
24
- export type BatchGetInput = BatchGetCommandInput & {
25
- Items?: any[];
26
- };
27
- export type BatchWriteInput = BatchWriteCommandInput & {
28
- Items?: any[];
29
- };
30
24
  export declare class DynoQuery {
31
25
  private client;
32
26
  private docClient;
@@ -61,14 +55,6 @@ export declare class DynoQuery {
61
55
  * Scan the table or index for items.
62
56
  */
63
57
  scan(params: ScanCommandInput): Promise<import("@aws-sdk/lib-dynamodb").ScanCommandOutput>;
64
- /**
65
- * Get multiple items by their primary keys.
66
- */
67
- batchGet(params: BatchGetInput | any, ...additionalItems: any[][]): Promise<import("@aws-sdk/lib-dynamodb").BatchGetCommandOutput>;
68
- /**
69
- * Put or delete multiple items in one or more tables.
70
- */
71
- batchWrite(params: BatchWriteInput): Promise<import("@aws-sdk/lib-dynamodb").BatchWriteCommandOutput>;
72
58
  getTableName(): string | undefined;
73
59
  getPkPrefix(): string;
74
60
  getPkName(): string;
package/dist/index.js CHANGED
@@ -147,79 +147,6 @@ class DynoQuery {
147
147
  return yield this.docClient.send(command);
148
148
  });
149
149
  }
150
- /**
151
- * Get multiple items by their primary keys.
152
- */
153
- batchGet(params, ...additionalItems) {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- let finalParams;
156
- if (params && !params.RequestItems && !params.Items && (Array.isArray(params) || additionalItems.length > 0)) {
157
- // Handle the case where arguments are multiple arrays of items
158
- const allItems = Array.isArray(params) ? [...params] : [];
159
- additionalItems.forEach(chunk => {
160
- if (Array.isArray(chunk)) {
161
- allItems.push(...chunk);
162
- }
163
- else {
164
- allItems.push(chunk);
165
- }
166
- });
167
- finalParams = {
168
- Items: allItems
169
- };
170
- }
171
- else {
172
- finalParams = params;
173
- }
174
- if (!finalParams.RequestItems && finalParams.Items) {
175
- finalParams.RequestItems = {};
176
- finalParams.Items.forEach((item) => {
177
- const tableName = item.TableName || this.defaultTableName;
178
- if (!tableName) {
179
- throw new Error("TableName must be provided for batch operations if no default tableName is set");
180
- }
181
- if (!finalParams.RequestItems[tableName]) {
182
- finalParams.RequestItems[tableName] = { Keys: [] };
183
- }
184
- const key = item.Key || item;
185
- finalParams.RequestItems[tableName].Keys.push(key);
186
- });
187
- delete finalParams.Items;
188
- }
189
- else if (!finalParams.RequestItems && this.defaultTableName) {
190
- finalParams.RequestItems = {};
191
- }
192
- const command = new lib_dynamodb_1.BatchGetCommand(finalParams);
193
- return yield this.docClient.send(command);
194
- });
195
- }
196
- /**
197
- * Put or delete multiple items in one or more tables.
198
- */
199
- batchWrite(params) {
200
- return __awaiter(this, void 0, void 0, function* () {
201
- if (!params.RequestItems && params.Items) {
202
- params.RequestItems = {};
203
- params.Items.forEach((item) => {
204
- const tableName = item.TableName || this.defaultTableName;
205
- if (!tableName) {
206
- throw new Error("TableName must be provided for batch operations if no default tableName is set");
207
- }
208
- if (!params.RequestItems[tableName]) {
209
- params.RequestItems[tableName] = [];
210
- }
211
- const request = item.PutRequest || item.DeleteRequest ? item : { PutRequest: { Item: item } };
212
- params.RequestItems[tableName].push(request);
213
- });
214
- delete params.Items;
215
- }
216
- else if (!params.RequestItems && this.defaultTableName) {
217
- params.RequestItems = {};
218
- }
219
- const command = new lib_dynamodb_1.BatchWriteCommand(params);
220
- return yield this.docClient.send(command);
221
- });
222
- }
223
150
  getTableName() {
224
151
  return this.defaultTableName;
225
152
  }
@@ -37,22 +37,6 @@ export declare class Partition {
37
37
  */
38
38
  get<T = any>(sk: string): Promise<T | null>;
39
39
  getPkValue(): string;
40
- /**
41
- * Generates items for batch query.
42
- * If no SKs are provided, it might not be very useful for batchGet (which requires full keys),
43
- * but the requirement says "will get all by pkValue" if no sk defined.
44
- * Actually, BatchGetItem requires both PK and SK if the table has both.
45
- * If it's for IndexQuery, it might be different.
46
- */
47
- batchGetInput(...sks: string[]): any[];
48
- /**
49
- * Generates items for batch write (put).
50
- */
51
- batchWriteInput(...items: any[]): any[];
52
- /**
53
- * Generates items for batch delete.
54
- */
55
- batchDeleteInput(...sks: string[]): any[];
56
40
  /**
57
41
  * Delete all data in this partition.
58
42
  */
package/dist/partition.js CHANGED
@@ -144,53 +144,6 @@ class Partition {
144
144
  getPkValue() {
145
145
  return this.pkValue;
146
146
  }
147
- /**
148
- * Generates items for batch query.
149
- * If no SKs are provided, it might not be very useful for batchGet (which requires full keys),
150
- * but the requirement says "will get all by pkValue" if no sk defined.
151
- * Actually, BatchGetItem requires both PK and SK if the table has both.
152
- * If it's for IndexQuery, it might be different.
153
- */
154
- batchGetInput(...sks) {
155
- if (sks.length === 0) {
156
- return [{
157
- TableName: this.tableName,
158
- Key: { [this.pkName]: this.pkValue }
159
- }];
160
- }
161
- return sks.map(sk => ({
162
- TableName: this.tableName,
163
- Key: {
164
- [this.pkName]: this.pkValue,
165
- [this.skName]: sk
166
- }
167
- }));
168
- }
169
- /**
170
- * Generates items for batch write (put).
171
- */
172
- batchWriteInput(...items) {
173
- return items.map(item => ({
174
- TableName: this.tableName,
175
- PutRequest: {
176
- Item: Object.assign({ [this.pkName]: this.pkValue }, item)
177
- }
178
- }));
179
- }
180
- /**
181
- * Generates items for batch delete.
182
- */
183
- batchDeleteInput(...sks) {
184
- return sks.map(sk => ({
185
- TableName: this.tableName,
186
- DeleteRequest: {
187
- Key: {
188
- [this.pkName]: this.pkValue,
189
- [this.skName]: sk
190
- }
191
- }
192
- }));
193
- }
194
147
  /**
195
148
  * Delete all data in this partition.
196
149
  */
@@ -207,24 +160,12 @@ class Partition {
207
160
  },
208
161
  });
209
162
  if (response.Items && response.Items.length > 0) {
210
- // DynamoDB BatchWriteItem supports up to 25 requests at once
211
- const items = response.Items;
212
- const chunks = [];
213
- for (let i = 0; i < items.length; i += 25) {
214
- chunks.push(items.slice(i, i + 25));
215
- }
216
- for (const chunk of chunks) {
217
- const deleteRequests = chunk.map((item) => ({
218
- DeleteRequest: {
219
- Key: {
220
- [this.pkName]: item[this.pkName],
221
- [this.skName]: item[this.skName],
222
- },
223
- },
224
- }));
225
- yield this.db.batchWrite({
226
- RequestItems: {
227
- [this.tableName]: deleteRequests,
163
+ for (const item of response.Items) {
164
+ yield this.db.delete({
165
+ TableName: this.tableName,
166
+ Key: {
167
+ [this.pkName]: item[this.pkName],
168
+ [this.skName]: item[this.skName],
228
169
  },
229
170
  });
230
171
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dynoquery",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/devspikejs/dynoquery.git"