@cellaware/utils 5.3.2 → 5.3.3
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/dist/azure/cosmos.d.ts +6 -0
- package/dist/azure/cosmos.js +14 -4
- package/package.json +1 -1
package/dist/azure/cosmos.d.ts
CHANGED
|
@@ -84,5 +84,11 @@ export declare function getCosmosCurrentMonthWhereClause(timeZone?: string): str
|
|
|
84
84
|
export declare function getCosmosCurrentYearWhereClause(timeZone?: string): string;
|
|
85
85
|
export declare function cosmosSelect(databaseId: string, collectionId: string, partitionKey: string, query: string): Promise<any[]>;
|
|
86
86
|
export declare function cosmosInsert(databaseId: string, collectionId: string, partitionKey: string, data: any): Promise<boolean>;
|
|
87
|
+
/**
|
|
88
|
+
* Will delete **multiple** records if `query` returns multiple rows.
|
|
89
|
+
*/
|
|
87
90
|
export declare function cosmosDelete(databaseId: string, collectionId: string, partitionKey: string, query: string): Promise<boolean>;
|
|
91
|
+
/**
|
|
92
|
+
* Will only update a **single** record. If multiple records are returned from `query`, we will only update the first one.
|
|
93
|
+
*/
|
|
88
94
|
export declare function cosmosUpdate(databaseId: string, collectionId: string, partitionKey: string, query: string, data: any): Promise<boolean>;
|
package/dist/azure/cosmos.js
CHANGED
|
@@ -184,6 +184,9 @@ export async function cosmosInsert(databaseId, collectionId, partitionKey, data)
|
|
|
184
184
|
return false;
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Will delete **multiple** records if `query` returns multiple rows.
|
|
189
|
+
*/
|
|
187
190
|
export async function cosmosDelete(databaseId, collectionId, partitionKey, query) {
|
|
188
191
|
try {
|
|
189
192
|
const cosmosClient = new CosmosClient({
|
|
@@ -210,8 +213,14 @@ export async function cosmosDelete(databaseId, collectionId, partitionKey, query
|
|
|
210
213
|
return false;
|
|
211
214
|
}
|
|
212
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Will only update a **single** record. If multiple records are returned from `query`, we will only update the first one.
|
|
218
|
+
*/
|
|
213
219
|
export async function cosmosUpdate(databaseId, collectionId, partitionKey, query, data) {
|
|
214
220
|
try {
|
|
221
|
+
if (Array.isArray(data)) {
|
|
222
|
+
throw new Error('`data` cannot be an array');
|
|
223
|
+
}
|
|
215
224
|
const cosmosClient = new CosmosClient({
|
|
216
225
|
endpoint: process.env.COSMOS_DB_ENDPOINT ?? '',
|
|
217
226
|
key: process.env.COSMOS_DB_KEY ?? ''
|
|
@@ -226,11 +235,12 @@ export async function cosmosUpdate(databaseId, collectionId, partitionKey, query
|
|
|
226
235
|
}).fetchAll();
|
|
227
236
|
// NOTE: need to remove the '/' at the beginning.
|
|
228
237
|
const partitionKeyColumn = partitionKey.startsWith('/') ? partitionKey.substring(1) : partitionKey;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
238
|
+
if (resources.length > 0) {
|
|
239
|
+
const doc = resources[0];
|
|
240
|
+
// Data needs to have `id` field that matches the original.
|
|
241
|
+
data.id = doc.id;
|
|
232
242
|
container.item(doc.id, doc[partitionKeyColumn]).replace(data);
|
|
233
|
-
}
|
|
243
|
+
}
|
|
234
244
|
return true;
|
|
235
245
|
}
|
|
236
246
|
catch (err) {
|