dynoquery 0.1.17 → 0.1.18
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 +5 -5
- package/dist/index.js +3 -3
- package/dist/partition.d.ts +5 -5
- package/dist/partition.js +20 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -239,12 +239,12 @@ if (token) {
|
|
|
239
239
|
- `findBy[IndexName](id, skValue?)`: Returns an `IndexQuery` instance.
|
|
240
240
|
|
|
241
241
|
### Partition
|
|
242
|
-
- `get(
|
|
242
|
+
- `get(skValue)`: Fetches data for a specific Sort Key value (returns a Promise).
|
|
243
243
|
- `getAll(options?)`: Fetches items in the partition. Options: `{ limit, exclusiveStartKey }`.
|
|
244
|
-
- `create(
|
|
245
|
-
- `update(
|
|
246
|
-
- `delete(
|
|
247
|
-
- `draft(
|
|
244
|
+
- `create(skValue, data, indices?)`: Creates an item. `indices` is an array of `IndexQuery` for GSI population.
|
|
245
|
+
- `update(skValue, data)`: Partial update of an item.
|
|
246
|
+
- `delete(skValue)`: Deletes an item.
|
|
247
|
+
- `draft(skValue, data?)`: Returns an `Item` object initialized with `data` (optional).
|
|
248
248
|
- `deleteAll()`: Deletes all items in the partition.
|
|
249
249
|
- `getLastEvaluatedKey()`: Returns the pagination token from the last `getAll()`.
|
|
250
250
|
|
package/dist/index.js
CHANGED
|
@@ -55,10 +55,10 @@ class DynoQuery {
|
|
|
55
55
|
if (models) {
|
|
56
56
|
this.registeredModels = models;
|
|
57
57
|
Object.entries(models).forEach(([name, def]) => {
|
|
58
|
-
this[name] = (id,
|
|
58
|
+
this[name] = (id, skValue) => {
|
|
59
59
|
const partition = new partition_1.Partition(this, { pkPrefix: this.globalPkPrefix + def.pkPrefix }, id);
|
|
60
|
-
if (
|
|
61
|
-
return partition.draft(
|
|
60
|
+
if (skValue) {
|
|
61
|
+
return partition.draft(skValue);
|
|
62
62
|
}
|
|
63
63
|
return partition;
|
|
64
64
|
};
|
package/dist/partition.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare class Partition {
|
|
|
34
34
|
/**
|
|
35
35
|
* Create an item in this partition.
|
|
36
36
|
*/
|
|
37
|
-
create<T = any>(
|
|
37
|
+
create<T = any>(skValue: string, data: T, indices?: IndexQuery[]): Promise<T>;
|
|
38
38
|
/**
|
|
39
39
|
* Internal method to get raw data for a specific SK.
|
|
40
40
|
*/
|
|
@@ -42,21 +42,21 @@ export declare class Partition {
|
|
|
42
42
|
/**
|
|
43
43
|
* Update an existing item in this partition.
|
|
44
44
|
*/
|
|
45
|
-
update<T = any>(
|
|
45
|
+
update<T = any>(skValue: string, data: Partial<T>, indices?: IndexQuery[]): Promise<T>;
|
|
46
46
|
/**
|
|
47
47
|
* Delete an item by its SK within this partition.
|
|
48
48
|
*/
|
|
49
|
-
delete(
|
|
49
|
+
delete(skValue: string): Promise<void>;
|
|
50
50
|
/**
|
|
51
51
|
* Get data for a specific SK and return it wrapped in a Item object.
|
|
52
52
|
*/
|
|
53
|
-
get<T = any>(
|
|
53
|
+
get<T = any>(skValue: string): Promise<T | null>;
|
|
54
54
|
/**
|
|
55
55
|
* Pre-draft an item for creation. Returns an Item object.
|
|
56
56
|
* @param sk The sort key value
|
|
57
57
|
* @param data Initial data for the row
|
|
58
58
|
*/
|
|
59
|
-
draft<T = any>(
|
|
59
|
+
draft<T = any>(skValue: string, data?: any): T;
|
|
60
60
|
getPkValue(): string;
|
|
61
61
|
getLastEvaluatedKey(): any;
|
|
62
62
|
/**
|
package/dist/partition.js
CHANGED
|
@@ -129,9 +129,9 @@ class Partition {
|
|
|
129
129
|
/**
|
|
130
130
|
* Create an item in this partition.
|
|
131
131
|
*/
|
|
132
|
-
create(
|
|
132
|
+
create(skValue, data, indices) {
|
|
133
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
-
const item = Object.assign({ [this.pkName]: this.pkValue, [this.skName]:
|
|
134
|
+
const item = Object.assign({ [this.pkName]: this.pkValue, [this.skName]: skValue }, data);
|
|
135
135
|
if (indices) {
|
|
136
136
|
indices.forEach((index) => {
|
|
137
137
|
item[index.getPkName()] = index.getPkValue();
|
|
@@ -144,17 +144,17 @@ class Partition {
|
|
|
144
144
|
TableName: this.tableName,
|
|
145
145
|
Item: item,
|
|
146
146
|
});
|
|
147
|
-
this.cache[
|
|
148
|
-
return new Item(this,
|
|
147
|
+
this.cache[skValue] = item;
|
|
148
|
+
return new Item(this, skValue, item);
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
152
|
* Internal method to get raw data for a specific SK.
|
|
153
153
|
*/
|
|
154
|
-
_getRaw(
|
|
154
|
+
_getRaw(skValue) {
|
|
155
155
|
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
-
if (this.cache[
|
|
157
|
-
return this.cache[
|
|
156
|
+
if (this.cache[skValue] !== undefined) {
|
|
157
|
+
return this.cache[skValue] || null;
|
|
158
158
|
}
|
|
159
159
|
if (this.isLoaded) {
|
|
160
160
|
return null;
|
|
@@ -163,12 +163,12 @@ class Partition {
|
|
|
163
163
|
TableName: this.tableName,
|
|
164
164
|
Key: {
|
|
165
165
|
[this.pkName]: this.pkValue,
|
|
166
|
-
[this.skName]:
|
|
166
|
+
[this.skName]: skValue,
|
|
167
167
|
},
|
|
168
168
|
});
|
|
169
169
|
const data = response.Item || null;
|
|
170
170
|
if (data) {
|
|
171
|
-
this.cache[
|
|
171
|
+
this.cache[skValue] = data;
|
|
172
172
|
}
|
|
173
173
|
return data;
|
|
174
174
|
});
|
|
@@ -176,35 +176,35 @@ class Partition {
|
|
|
176
176
|
/**
|
|
177
177
|
* Update an existing item in this partition.
|
|
178
178
|
*/
|
|
179
|
-
update(
|
|
179
|
+
update(skValue, data, indices) {
|
|
180
180
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
-
const current = (yield this._getRaw(
|
|
181
|
+
const current = (yield this._getRaw(skValue)) || {};
|
|
182
182
|
const updated = Object.assign(Object.assign({}, current), data);
|
|
183
|
-
return yield this.create(
|
|
183
|
+
return yield this.create(skValue, updated, indices);
|
|
184
184
|
});
|
|
185
185
|
}
|
|
186
186
|
/**
|
|
187
187
|
* Delete an item by its SK within this partition.
|
|
188
188
|
*/
|
|
189
|
-
delete(
|
|
189
|
+
delete(skValue) {
|
|
190
190
|
return __awaiter(this, void 0, void 0, function* () {
|
|
191
191
|
yield this.db.delete({
|
|
192
192
|
TableName: this.tableName,
|
|
193
193
|
Key: {
|
|
194
194
|
[this.pkName]: this.pkValue,
|
|
195
|
-
[this.skName]:
|
|
195
|
+
[this.skName]: skValue,
|
|
196
196
|
},
|
|
197
197
|
});
|
|
198
|
-
delete this.cache[
|
|
198
|
+
delete this.cache[skValue];
|
|
199
199
|
});
|
|
200
200
|
}
|
|
201
201
|
/**
|
|
202
202
|
* Get data for a specific SK and return it wrapped in a Item object.
|
|
203
203
|
*/
|
|
204
|
-
get(
|
|
204
|
+
get(skValue) {
|
|
205
205
|
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
-
const data = yield this._getRaw(
|
|
207
|
-
return data ? new Item(this,
|
|
206
|
+
const data = yield this._getRaw(skValue);
|
|
207
|
+
return data ? new Item(this, skValue, data) : null;
|
|
208
208
|
});
|
|
209
209
|
}
|
|
210
210
|
/**
|
|
@@ -212,8 +212,8 @@ class Partition {
|
|
|
212
212
|
* @param sk The sort key value
|
|
213
213
|
* @param data Initial data for the row
|
|
214
214
|
*/
|
|
215
|
-
draft(
|
|
216
|
-
return new Item(this,
|
|
215
|
+
draft(skValue, data = {}) {
|
|
216
|
+
return new Item(this, skValue, data);
|
|
217
217
|
}
|
|
218
218
|
getPkValue() {
|
|
219
219
|
return this.pkValue;
|