@cellaware/utils 8.1.7 → 8.1.9
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
CHANGED
|
@@ -82,16 +82,30 @@ export declare function getCosmosCurrentMonthClause(timeZone?: string): string;
|
|
|
82
82
|
* NOTE: default time zone is UTC
|
|
83
83
|
*/
|
|
84
84
|
export declare function getCosmosCurrentYearClause(timeZone?: string): string;
|
|
85
|
+
export declare function _cosmosSelect(endpoint: string, key: string, databaseId: string, collectionId: string, partitionKey: string, query: string): Promise<any[]>;
|
|
85
86
|
export declare function cosmosSelect(databaseId: string, collectionId: string, partitionKey: string, query: string): Promise<any[]>;
|
|
87
|
+
export declare function _cosmosInsert(endpoint: string, key: string, databaseId: string, collectionId: string, partitionKey: string, data: any): Promise<boolean>;
|
|
86
88
|
export declare function cosmosInsert(databaseId: string, collectionId: string, partitionKey: string, data: any): Promise<boolean>;
|
|
89
|
+
/**
|
|
90
|
+
* Will delete **multiple** records if `query` returns multiple rows.
|
|
91
|
+
*/
|
|
92
|
+
export declare function _cosmosDelete(endpoint: string, key: string, databaseId: string, collectionId: string, partitionKey: string, query: string): Promise<boolean>;
|
|
87
93
|
/**
|
|
88
94
|
* Will delete **multiple** records if `query` returns multiple rows.
|
|
89
95
|
*/
|
|
90
96
|
export declare function cosmosDelete(databaseId: string, collectionId: string, partitionKey: string, query: string): Promise<boolean>;
|
|
97
|
+
/**
|
|
98
|
+
* Will only update a **single** record. If multiple records are returned from `query`, we will only update the first one.
|
|
99
|
+
*/
|
|
100
|
+
export declare function _cosmosUpdate(endpoint: string, key: string, databaseId: string, collectionId: string, partitionKey: string, query: string, data: any): Promise<boolean>;
|
|
91
101
|
/**
|
|
92
102
|
* Will only update a **single** record. If multiple records are returned from `query`, we will only update the first one.
|
|
93
103
|
*/
|
|
94
104
|
export declare function cosmosUpdate(databaseId: string, collectionId: string, partitionKey: string, query: string, data: any): Promise<boolean>;
|
|
105
|
+
/**
|
|
106
|
+
* Simply deletes an existing record(s) then inserts a new one.
|
|
107
|
+
*/
|
|
108
|
+
export declare function _cosmosUpsert(endpoint: string, key: string, databaseId: string, collectionId: string, partitionKey: string, query: string, data: any): Promise<boolean>;
|
|
95
109
|
/**
|
|
96
110
|
* Simply deletes an existing record(s) then inserts a new one.
|
|
97
111
|
*/
|
package/dist/azure/cosmos.js
CHANGED
|
@@ -160,11 +160,11 @@ export function getCosmosCurrentMonthClause(timeZone) {
|
|
|
160
160
|
export function getCosmosCurrentYearClause(timeZone) {
|
|
161
161
|
return `DateTimeDiff('yyyy', ${getCosmosTimestampDateTime(timeZone)}, ${getCosmosCurrentDateTime(timeZone)}) = 0`;
|
|
162
162
|
}
|
|
163
|
-
export async function
|
|
163
|
+
export async function _cosmosSelect(endpoint, key, databaseId, collectionId, partitionKey, query) {
|
|
164
164
|
try {
|
|
165
165
|
const cosmosClient = new CosmosClient({
|
|
166
|
-
endpoint
|
|
167
|
-
key
|
|
166
|
+
endpoint,
|
|
167
|
+
key,
|
|
168
168
|
connectionPolicy: { connectionMode: ConnectionMode.Gateway, enableEndpointDiscovery: false }
|
|
169
169
|
});
|
|
170
170
|
const { database } = await cosmosClient.databases.createIfNotExists({ id: databaseId });
|
|
@@ -179,11 +179,14 @@ export async function cosmosSelect(databaseId, collectionId, partitionKey, query
|
|
|
179
179
|
throw new Error(`COSMOS: Select error: ${err.message}`);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
export async function
|
|
182
|
+
export async function cosmosSelect(databaseId, collectionId, partitionKey, query) {
|
|
183
|
+
return _cosmosSelect(process.env.COSMOS_DB_ENDPOINT ?? '', process.env.COSMOS_DB_KEY ?? '', databaseId, collectionId, partitionKey, query);
|
|
184
|
+
}
|
|
185
|
+
export async function _cosmosInsert(endpoint, key, databaseId, collectionId, partitionKey, data) {
|
|
183
186
|
try {
|
|
184
187
|
const cosmosClient = new CosmosClient({
|
|
185
|
-
endpoint
|
|
186
|
-
key
|
|
188
|
+
endpoint,
|
|
189
|
+
key,
|
|
187
190
|
connectionPolicy: { connectionMode: ConnectionMode.Gateway, enableEndpointDiscovery: false }
|
|
188
191
|
});
|
|
189
192
|
const { database } = await cosmosClient.databases.createIfNotExists({ id: databaseId });
|
|
@@ -198,14 +201,17 @@ export async function cosmosInsert(databaseId, collectionId, partitionKey, data)
|
|
|
198
201
|
throw new Error(`COSMOS: Insert error: ${err.message}`);
|
|
199
202
|
}
|
|
200
203
|
}
|
|
204
|
+
export async function cosmosInsert(databaseId, collectionId, partitionKey, data) {
|
|
205
|
+
return _cosmosInsert(process.env.COSMOS_DB_ENDPOINT ?? '', process.env.COSMOS_DB_KEY ?? '', databaseId, collectionId, partitionKey, data);
|
|
206
|
+
}
|
|
201
207
|
/**
|
|
202
208
|
* Will delete **multiple** records if `query` returns multiple rows.
|
|
203
209
|
*/
|
|
204
|
-
export async function
|
|
210
|
+
export async function _cosmosDelete(endpoint, key, databaseId, collectionId, partitionKey, query) {
|
|
205
211
|
try {
|
|
206
212
|
const cosmosClient = new CosmosClient({
|
|
207
|
-
endpoint
|
|
208
|
-
key
|
|
213
|
+
endpoint,
|
|
214
|
+
key,
|
|
209
215
|
connectionPolicy: { connectionMode: ConnectionMode.Gateway, enableEndpointDiscovery: false }
|
|
210
216
|
});
|
|
211
217
|
const { database } = await cosmosClient.databases.createIfNotExists({ id: databaseId });
|
|
@@ -225,17 +231,23 @@ export async function cosmosDelete(databaseId, collectionId, partitionKey, query
|
|
|
225
231
|
throw new Error(`COSMOS: Delete error: ${err.message}`);
|
|
226
232
|
}
|
|
227
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Will delete **multiple** records if `query` returns multiple rows.
|
|
236
|
+
*/
|
|
237
|
+
export async function cosmosDelete(databaseId, collectionId, partitionKey, query) {
|
|
238
|
+
return _cosmosDelete(process.env.COSMOS_DB_ENDPOINT ?? '', process.env.COSMOS_DB_KEY ?? '', databaseId, collectionId, partitionKey, query);
|
|
239
|
+
}
|
|
228
240
|
/**
|
|
229
241
|
* Will only update a **single** record. If multiple records are returned from `query`, we will only update the first one.
|
|
230
242
|
*/
|
|
231
|
-
export async function
|
|
243
|
+
export async function _cosmosUpdate(endpoint, key, databaseId, collectionId, partitionKey, query, data) {
|
|
232
244
|
try {
|
|
233
245
|
if (Array.isArray(data)) {
|
|
234
246
|
throw new Error('Input `data` cannot be an array');
|
|
235
247
|
}
|
|
236
248
|
const cosmosClient = new CosmosClient({
|
|
237
|
-
endpoint
|
|
238
|
-
key
|
|
249
|
+
endpoint,
|
|
250
|
+
key,
|
|
239
251
|
connectionPolicy: { connectionMode: ConnectionMode.Gateway, enableEndpointDiscovery: false }
|
|
240
252
|
});
|
|
241
253
|
const { database } = await cosmosClient.databases.createIfNotExists({ id: databaseId });
|
|
@@ -263,6 +275,23 @@ export async function cosmosUpdate(databaseId, collectionId, partitionKey, query
|
|
|
263
275
|
throw new Error(`COSMOS: Update error: ${err.message}`);
|
|
264
276
|
}
|
|
265
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Will only update a **single** record. If multiple records are returned from `query`, we will only update the first one.
|
|
280
|
+
*/
|
|
281
|
+
export async function cosmosUpdate(databaseId, collectionId, partitionKey, query, data) {
|
|
282
|
+
return _cosmosUpdate(process.env.COSMOS_DB_ENDPOINT ?? '', process.env.COSMOS_DB_KEY ?? '', databaseId, collectionId, partitionKey, query, data);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Simply deletes an existing record(s) then inserts a new one.
|
|
286
|
+
*/
|
|
287
|
+
export async function _cosmosUpsert(endpoint, key, databaseId, collectionId, partitionKey, query, data) {
|
|
288
|
+
const delRes = await _cosmosDelete(endpoint, key, databaseId, collectionId, partitionKey, query);
|
|
289
|
+
if (!delRes) {
|
|
290
|
+
return delRes;
|
|
291
|
+
}
|
|
292
|
+
const insRes = await _cosmosInsert(endpoint, key, databaseId, collectionId, partitionKey, data);
|
|
293
|
+
return insRes;
|
|
294
|
+
}
|
|
266
295
|
/**
|
|
267
296
|
* Simply deletes an existing record(s) then inserts a new one.
|
|
268
297
|
*/
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { cosmosDelete, cosmosInsert, cosmosSelect, cosmosUpdate, cosmosUpsert } from "../../azure/cosmos.js";
|
|
2
2
|
const DATABASE_ID = 'chatwms';
|
|
3
3
|
const PARTITION_KEY = '/clientId';
|
|
4
|
+
export const CHATWMS_DATABASE_ID = DATABASE_ID;
|
|
5
|
+
export const CLIENT_PARTITION_KEY = PARTITION_KEY;
|
|
4
6
|
export const PRODUCT_PARTITION_KEY = '/productId';
|
|
5
7
|
/**
|
|
6
8
|
* Default `partitionKey` is '/clientId'
|