ag-common 0.0.894 → 0.0.896
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/LICENSE.md +2 -3
- package/README.md +2 -2
- package/dist/api/helpers/acm.d.ts +1 -1
- package/dist/api/helpers/acm.js +3 -3
- package/dist/api/helpers/api.d.ts +2 -2
- package/dist/api/helpers/api.js +26 -22
- package/dist/api/helpers/apigw.js +4 -4
- package/dist/api/helpers/aws.js +2 -2
- package/dist/api/helpers/cosmos/delete.d.ts +1 -1
- package/dist/api/helpers/cosmos/delete.js +15 -16
- package/dist/api/helpers/cosmos/get.d.ts +3 -3
- package/dist/api/helpers/cosmos/get.js +26 -32
- package/dist/api/helpers/cosmos/index.d.ts +3 -3
- package/dist/api/helpers/cosmos/index.js +1 -1
- package/dist/api/helpers/cosmos/utils.d.ts +1 -1
- package/dist/api/helpers/cosmos/utils.js +3 -7
- package/dist/api/helpers/cosmos/write.d.ts +1 -1
- package/dist/api/helpers/cosmos/write.js +11 -12
- package/dist/api/helpers/dynamo/delete.d.ts +1 -1
- package/dist/api/helpers/dynamo/delete.js +3 -3
- package/dist/api/helpers/dynamo/get.d.ts +2 -2
- package/dist/api/helpers/dynamo/get.js +20 -14
- package/dist/api/helpers/dynamo/index.d.ts +10 -38
- package/dist/api/helpers/dynamo/index.js +4 -4
- package/dist/api/helpers/dynamo/set.d.ts +1 -1
- package/dist/api/helpers/dynamo/set.js +10 -10
- package/dist/api/helpers/dynamo/types.d.ts +3 -3
- package/dist/api/helpers/dynamo/types.js +1 -1
- package/dist/api/helpers/enforceDynamoProvisionCap.d.ts +13 -1
- package/dist/api/helpers/enforceDynamoProvisionCap.js +3 -4
- package/dist/api/helpers/google/apikey.js +1 -1
- package/dist/api/helpers/google/gemini.d.ts +1 -1
- package/dist/api/helpers/google/gemini.js +43 -45
- package/dist/api/helpers/google/index.d.ts +2 -2
- package/dist/api/helpers/index.d.ts +17 -17
- package/dist/api/helpers/retryOnError.js +6 -11
- package/dist/api/helpers/s3.d.ts +9 -9
- package/dist/api/helpers/s3.js +19 -16
- package/dist/api/helpers/ses.d.ts +1 -1
- package/dist/api/helpers/ses.js +9 -9
- package/dist/api/helpers/sqs.d.ts +1 -1
- package/dist/api/helpers/sqs.js +1 -1
- package/dist/api/helpers/ssm.d.ts +1 -1
- package/dist/api/helpers/ssm.js +2 -2
- package/dist/api/helpers/ssmInfra/apigw.d.ts +6 -6
- package/dist/api/helpers/ssmInfra/apigw.js +6 -10
- package/dist/api/helpers/ssmInfra/dynamo.d.ts +2 -2
- package/dist/api/helpers/ssmInfra/dynamo.js +1 -1
- package/dist/api/helpers/ssmInfra/index.d.ts +4 -4
- package/dist/api/helpers/ssmInfra/s3.d.ts +3 -3
- package/dist/api/helpers/ssmInfra/s3.js +1 -1
- package/dist/api/helpers/ssmInfra/sqs.d.ts +3 -3
- package/dist/api/helpers/ssmInfra/sqs.js +1 -1
- package/dist/api/helpers/sts.d.ts +1 -1
- package/dist/api/helpers/sts.js +4 -4
- package/dist/api/helpers/validations.d.ts +2 -2
- package/dist/api/helpers/validations.js +14 -14
- package/dist/api/helpers/zod.d.ts +1 -1
- package/dist/api/helpers/zod.js +21 -27
- package/dist/api/index.d.ts +2 -2
- package/dist/api/types/aws.d.ts +0 -56
- package/dist/api/types/aws.js +0 -1
- package/dist/api/types/index.d.ts +1 -1
- package/dist/common/helpers/array.js +9 -10
- package/dist/common/helpers/async.js +2 -2
- package/dist/common/helpers/binary.d.ts +1 -1
- package/dist/common/helpers/binary.js +1 -1
- package/dist/common/helpers/csv.d.ts +4 -2
- package/dist/common/helpers/csv.js +8 -12
- package/dist/common/helpers/date.d.ts +2 -4
- package/dist/common/helpers/date.js +2 -2
- package/dist/common/helpers/email.js +2 -2
- package/dist/common/helpers/fetch.js +8 -8
- package/dist/common/helpers/generator.js +2 -2
- package/dist/common/helpers/groupBy.js +0 -2
- package/dist/common/helpers/hashCode.js +2 -6
- package/dist/common/helpers/headers.d.ts +20 -20
- package/dist/common/helpers/headers.js +38 -38
- package/dist/common/helpers/i18n.d.ts +2 -2
- package/dist/common/helpers/i18n.js +5 -6
- package/dist/common/helpers/index.d.ts +25 -25
- package/dist/common/helpers/log.d.ts +1 -1
- package/dist/common/helpers/log.js +30 -30
- package/dist/common/helpers/math.d.ts +2 -2
- package/dist/common/helpers/math.js +6 -6
- package/dist/common/helpers/memo.d.ts +1 -1
- package/dist/common/helpers/memo.js +1 -3
- package/dist/common/helpers/node-cache.d.ts +2 -2
- package/dist/common/helpers/node-cache.js +0 -1
- package/dist/common/helpers/object.d.ts +1 -1
- package/dist/common/helpers/object.js +16 -27
- package/dist/common/helpers/secondsInNearest.js +5 -5
- package/dist/common/helpers/stream.js +4 -6
- package/dist/common/helpers/string/base64.js +2 -2
- package/dist/common/helpers/string/chunk.js +1 -1
- package/dist/common/helpers/string/contains.js +1 -3
- package/dist/common/helpers/string/getExtendedStringSegment.js +1 -1
- package/dist/common/helpers/string/index.d.ts +11 -11
- package/dist/common/helpers/string/json.js +1 -1
- package/dist/common/helpers/string/redact.js +38 -39
- package/dist/common/helpers/string/trim.js +4 -4
- package/dist/common/helpers/string/truncate.js +1 -1
- package/dist/common/helpers/string/url.js +7 -8
- package/dist/common/helpers/withRetry.js +7 -7
- package/dist/common/helpers/xml.d.ts +7 -3
- package/dist/common/helpers/xml.js +33 -36
- package/dist/common/index.d.ts +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/node/helpers/fetch.js +1 -2
- package/dist/node/helpers/fs.js +2 -2
- package/dist/node/helpers/index.d.ts +2 -2
- package/dist/node/index.d.ts +1 -1
- package/dist/ui/components/DarkMode/Base.d.ts +4 -4
- package/dist/ui/components/DarkMode/Base.js +26 -31
- package/dist/ui/components/DarkMode/index.d.ts +2 -2
- package/dist/ui/components/DarkMode/types.d.ts +5 -5
- package/dist/ui/components/HeadersRaw/index.d.ts +2 -2
- package/dist/ui/components/HeadersRaw/index.js +5 -5
- package/dist/ui/components/Markdown/index.d.ts +1 -1
- package/dist/ui/components/Markdown/index.js +10 -10
- package/dist/ui/components/index.d.ts +4 -4
- package/dist/ui/components/shadcn/accordion.d.ts +4 -4
- package/dist/ui/components/shadcn/accordion.js +6 -6
- package/dist/ui/components/shadcn/alert.d.ts +2 -2
- package/dist/ui/components/shadcn/alert.js +6 -6
- package/dist/ui/components/shadcn/avatar.d.ts +2 -2
- package/dist/ui/components/shadcn/avatar.js +4 -4
- package/dist/ui/components/shadcn/button.d.ts +4 -4
- package/dist/ui/components/shadcn/button.js +14 -14
- package/dist/ui/components/shadcn/card.d.ts +2 -2
- package/dist/ui/components/shadcn/card.js +6 -6
- package/dist/ui/components/shadcn/checkbox.d.ts +2 -2
- package/dist/ui/components/shadcn/checkbox.js +3 -3
- package/dist/ui/components/shadcn/dialog.d.ts +10 -10
- package/dist/ui/components/shadcn/dialog.js +9 -11
- package/dist/ui/components/shadcn/divider.d.ts +1 -1
- package/dist/ui/components/shadcn/divider.js +1 -1
- package/dist/ui/components/shadcn/dropdown-list.d.ts +1 -1
- package/dist/ui/components/shadcn/dropdown-list.js +5 -5
- package/dist/ui/components/shadcn/dropdown-menu.d.ts +6 -6
- package/dist/ui/components/shadcn/dropdown-menu.js +11 -11
- package/dist/ui/components/shadcn/index.d.ts +21 -21
- package/dist/ui/components/shadcn/input-selector.d.ts +1 -1
- package/dist/ui/components/shadcn/input-selector.js +10 -12
- package/dist/ui/components/shadcn/input.d.ts +1 -1
- package/dist/ui/components/shadcn/input.js +1 -1
- package/dist/ui/components/shadcn/label.d.ts +3 -3
- package/dist/ui/components/shadcn/label.js +2 -2
- package/dist/ui/components/shadcn/popover.d.ts +2 -2
- package/dist/ui/components/shadcn/popover.js +3 -3
- package/dist/ui/components/shadcn/radio-group.d.ts +2 -2
- package/dist/ui/components/shadcn/radio-group.js +2 -2
- package/dist/ui/components/shadcn/scroll-area.d.ts +2 -2
- package/dist/ui/components/shadcn/scroll-area.js +3 -5
- package/dist/ui/components/shadcn/select.d.ts +2 -2
- package/dist/ui/components/shadcn/select.js +12 -12
- package/dist/ui/components/shadcn/sheet.d.ts +12 -12
- package/dist/ui/components/shadcn/sheet.js +15 -15
- package/dist/ui/components/shadcn/switch.d.ts +2 -2
- package/dist/ui/components/shadcn/switch.js +3 -3
- package/dist/ui/components/shadcn/textarea.d.ts +1 -1
- package/dist/ui/components/shadcn/textarea.js +1 -1
- package/dist/ui/components/shadcn/toast.d.ts +2 -2
- package/dist/ui/components/shadcn/toast.js +25 -25
- package/dist/ui/helpers/cognito.d.ts +1 -1
- package/dist/ui/helpers/cookie/const.js +1 -1
- package/dist/ui/helpers/cookie/get.js +3 -4
- package/dist/ui/helpers/cookie/index.d.ts +5 -5
- package/dist/ui/helpers/cookie/raw.d.ts +1 -1
- package/dist/ui/helpers/cookie/raw.js +8 -9
- package/dist/ui/helpers/cookie/use.d.ts +1 -1
- package/dist/ui/helpers/cookie/use.js +4 -4
- package/dist/ui/helpers/date.js +8 -8
- package/dist/ui/helpers/debounce.js +1 -1
- package/dist/ui/helpers/dom.d.ts +1 -1
- package/dist/ui/helpers/dom.js +4 -14
- package/dist/ui/helpers/index.d.ts +26 -26
- package/dist/ui/helpers/jwt.d.ts +3 -3
- package/dist/ui/helpers/openDialog.d.ts +2 -2
- package/dist/ui/helpers/openDialog.js +8 -8
- package/dist/ui/helpers/plural.js +1 -1
- package/dist/ui/helpers/routes.d.ts +2 -2
- package/dist/ui/helpers/routes.js +14 -15
- package/dist/ui/helpers/serviceWorker.js +1 -1
- package/dist/ui/helpers/useContextMenu.d.ts +1 -1
- package/dist/ui/helpers/useContextMenu.js +9 -10
- package/dist/ui/helpers/useElementAttribute.js +3 -5
- package/dist/ui/helpers/useGranularHook.d.ts +1 -1
- package/dist/ui/helpers/useGranularHook.js +2 -3
- package/dist/ui/helpers/useInterval.d.ts +2 -2
- package/dist/ui/helpers/useInterval.js +2 -2
- package/dist/ui/helpers/useIsInViewport.d.ts +1 -1
- package/dist/ui/helpers/useIsInViewport.js +0 -1
- package/dist/ui/helpers/useLocalStorage.js +6 -6
- package/dist/ui/helpers/useLockBodyScroll.js +2 -2
- package/dist/ui/helpers/useOnClickOutside.d.ts +1 -1
- package/dist/ui/helpers/useOnClickOutside.js +3 -6
- package/dist/ui/helpers/useOnScroll.d.ts +1 -1
- package/dist/ui/helpers/useOnScroll.js +3 -4
- package/dist/ui/helpers/useOverloadPageSearch.js +8 -10
- package/dist/ui/helpers/useQueryString.js +7 -7
- package/dist/ui/helpers/useResize.js +5 -6
- package/dist/ui/helpers/useTimeout.js +1 -1
- package/dist/ui/helpers/useTooltip.d.ts +2 -2
- package/dist/ui/helpers/useTooltip.js +5 -7
- package/dist/ui/helpers/utils.d.ts +2 -2
- package/dist/ui/icons/Checkmark.d.ts +2 -2
- package/dist/ui/icons/Checkmark.js +1 -1
- package/dist/ui/icons/ChevronRight.d.ts +1 -1
- package/dist/ui/icons/Circle.d.ts +2 -2
- package/dist/ui/icons/Circle.js +1 -1
- package/dist/ui/icons/CircleDot.d.ts +2 -2
- package/dist/ui/icons/Cog.d.ts +2 -2
- package/dist/ui/icons/Computer.d.ts +2 -2
- package/dist/ui/icons/Door.d.ts +1 -1
- package/dist/ui/icons/Hamburger.d.ts +1 -1
- package/dist/ui/icons/HorizontalDots.d.ts +1 -1
- package/dist/ui/icons/House.d.ts +2 -2
- package/dist/ui/icons/Magnify.d.ts +2 -2
- package/dist/ui/icons/Magnify.js +1 -1
- package/dist/ui/icons/Moon.d.ts +2 -2
- package/dist/ui/icons/Pencil.d.ts +1 -1
- package/dist/ui/icons/Save.d.ts +1 -1
- package/dist/ui/icons/Sun.d.ts +1 -1
- package/dist/ui/icons/Sun.js +1 -1
- package/dist/ui/icons/Undo.d.ts +1 -1
- package/dist/ui/icons/UserOutline.d.ts +1 -1
- package/dist/ui/icons/Warning.d.ts +2 -2
- package/dist/ui/icons/Warning.js +1 -1
- package/dist/ui/icons/index.d.ts +32 -74
- package/dist/ui/index.d.ts +3 -3
- package/dist/ui/styles/colours.js +29 -29
- package/dist/ui/styles/common.d.ts +1 -1
- package/dist/ui/styles/common.js +10 -10
- package/dist/ui/styles/index.d.ts +3 -3
- package/package.json +65 -75
package/LICENSE.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
ISC License
|
|
2
|
-
---
|
|
1
|
+
## ISC License
|
|
3
2
|
|
|
4
3
|
ag-common - Copyright 2021 Andrei Gec
|
|
5
4
|
check out https://github.com/andreigec/ag-common or https://gec.dev for more info
|
|
@@ -8,4 +7,4 @@ check out https://github.com/andreigec/ag-common or https://gec.dev for more inf
|
|
|
8
7
|
|
|
9
8
|
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
10
9
|
|
|
11
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ag-common
|
|
2
2
|
|
|
3
|
-
> Various reusable
|
|
3
|
+
> Various reusable TypeScript libraries for common, API (AWS Cognito and AWS CDK), and React UI use cases.
|
|
4
4
|
|
|
5
5
|
[![NPM Version][npm-image]][npm-url]
|
|
6
6
|
|
|
@@ -19,4 +19,4 @@ Please raise any issues or requests you might have [here](https://github.com/and
|
|
|
19
19
|
[ISC](./LICENSE.md)
|
|
20
20
|
|
|
21
21
|
[npm-image]: https://img.shields.io/npm/v/ag-common.svg
|
|
22
|
-
[npm-url]: https://www.npmjs.com/package/ag-common
|
|
22
|
+
[npm-url]: https://www.npmjs.com/package/ag-common
|
package/dist/api/helpers/acm.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findCertificateByDomain = exports.acm = exports.setAcm = void 0;
|
|
4
|
-
/* eslint-disable no-await-in-loop */
|
|
5
4
|
const client_acm_1 = require("@aws-sdk/client-acm");
|
|
6
5
|
const setAcm = (region) => {
|
|
7
6
|
const raw = new client_acm_1.ACMClient({ region });
|
|
@@ -9,7 +8,7 @@ const setAcm = (region) => {
|
|
|
9
8
|
return raw;
|
|
10
9
|
};
|
|
11
10
|
exports.setAcm = setAcm;
|
|
12
|
-
exports.acm = (0, exports.setAcm)(
|
|
11
|
+
exports.acm = (0, exports.setAcm)("us-east-1");
|
|
13
12
|
/**
|
|
14
13
|
* Find an ACM certificate that covers both the apex domain and wildcard.
|
|
15
14
|
* @param domain - The domain to find a certificate for (e.g., "bolt.garden")
|
|
@@ -17,7 +16,7 @@ exports.acm = (0, exports.setAcm)('us-east-1');
|
|
|
17
16
|
* @returns The certificate ARN
|
|
18
17
|
* @throws Error if no matching certificate is found
|
|
19
18
|
*/
|
|
20
|
-
const findCertificateByDomain = async (domain, region =
|
|
19
|
+
const findCertificateByDomain = async (domain, region = "us-east-1") => {
|
|
21
20
|
const ar = await exports.acm.config.region();
|
|
22
21
|
if (ar !== region) {
|
|
23
22
|
(0, exports.setAcm)(region);
|
|
@@ -30,6 +29,7 @@ const findCertificateByDomain = async (domain, region = 'us-east-1') => {
|
|
|
30
29
|
for (const cert of listResponse.CertificateSummaryList) {
|
|
31
30
|
if (!cert.CertificateArn)
|
|
32
31
|
continue;
|
|
32
|
+
// oxlint-disable-next-line no-await-in-loop -- stop as soon as a matching certificate is found
|
|
33
33
|
const describeResponse = await exports.acm.send(new client_acm_1.DescribeCertificateCommand({
|
|
34
34
|
CertificateArn: cert.CertificateArn,
|
|
35
35
|
}));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { APIGatewayProxyResult, DYNAMOKEYS } from
|
|
1
|
+
import type { APIGatewayProxyResult, DYNAMOKEYS } from "../types";
|
|
2
2
|
export declare const returnCode: <T>(statusCode: number, body?: T, extraHeaders?: {
|
|
3
3
|
[a: string]: string;
|
|
4
4
|
}, fullSiteUrl?: string) => APIGatewayProxyResult;
|
|
@@ -8,7 +8,7 @@ export declare const returnCode: <T>(statusCode: number, body?: T, extraHeaders?
|
|
|
8
8
|
* @param keepPk if true, will keep PK. default true
|
|
9
9
|
* @returns stripped record
|
|
10
10
|
*/
|
|
11
|
-
export declare const stripPKs: <T
|
|
11
|
+
export declare const stripPKs: <T extends Record<string, unknown>>(record: T, keepPk?: boolean) => T;
|
|
12
12
|
/**
|
|
13
13
|
* generate dynamo PKs.
|
|
14
14
|
* PK = all Ls joined with #
|
package/dist/api/helpers/api.js
CHANGED
|
@@ -4,10 +4,10 @@ exports.generateDynamoPKS = exports.stripPKs = exports.returnCode = void 0;
|
|
|
4
4
|
const array_1 = require("../../common/helpers/array");
|
|
5
5
|
const returnCode = (statusCode, body, extraHeaders, fullSiteUrl) => {
|
|
6
6
|
let headers = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
"Access-Control-Allow-Headers": "Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent,User-Agent,Origin",
|
|
8
|
+
"Access-Control-Allow-Methods": "*",
|
|
9
|
+
"Access-Control-Allow-Origin": fullSiteUrl || "*",
|
|
10
|
+
"Access-Control-Allow-Credentials": true, // Required for cookies, authorization headers with HTTPS
|
|
11
11
|
};
|
|
12
12
|
if (extraHeaders && Object.keys(extraHeaders).length > 0) {
|
|
13
13
|
headers = {
|
|
@@ -18,8 +18,7 @@ const returnCode = (statusCode, body, extraHeaders, fullSiteUrl) => {
|
|
|
18
18
|
return {
|
|
19
19
|
headers,
|
|
20
20
|
statusCode,
|
|
21
|
-
|
|
22
|
-
body: (!body ? undefined : JSON.stringify(body, null, 2)),
|
|
21
|
+
body: body === undefined ? "" : JSON.stringify(body, null, 2),
|
|
23
22
|
};
|
|
24
23
|
};
|
|
25
24
|
exports.returnCode = returnCode;
|
|
@@ -30,19 +29,26 @@ exports.returnCode = returnCode;
|
|
|
30
29
|
* @returns stripped record
|
|
31
30
|
*/
|
|
32
31
|
const stripPKs = (record, keepPk = true) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const result = { ...record };
|
|
33
|
+
const generatedKeys = [
|
|
34
|
+
"PK1",
|
|
35
|
+
"PK2",
|
|
36
|
+
"PK3",
|
|
37
|
+
"PK4",
|
|
38
|
+
"PK5",
|
|
39
|
+
"L1",
|
|
40
|
+
"L2",
|
|
41
|
+
"L3",
|
|
42
|
+
"L4",
|
|
43
|
+
"L5",
|
|
44
|
+
"L6",
|
|
45
|
+
"type",
|
|
46
|
+
];
|
|
47
|
+
generatedKeys.forEach((key) => delete result[key]);
|
|
48
|
+
if (!keepPk) {
|
|
49
|
+
delete result.PK;
|
|
36
50
|
}
|
|
37
|
-
|
|
38
|
-
// eslint-disable-next-line
|
|
39
|
-
const { PK, PK1, PK2, PK3, PK4, PK5, L1, L2, L3, L4, L5, L6, type, ...rest } = record;
|
|
40
|
-
if (keepPk) {
|
|
41
|
-
//@ts-ignore
|
|
42
|
-
rest.PK = PK;
|
|
43
|
-
}
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
return rest;
|
|
51
|
+
return result;
|
|
46
52
|
};
|
|
47
53
|
exports.stripPKs = stripPKs;
|
|
48
54
|
/**
|
|
@@ -56,11 +62,9 @@ exports.stripPKs = stripPKs;
|
|
|
56
62
|
* @returns
|
|
57
63
|
*/
|
|
58
64
|
const generateDynamoPKS = ({ type, L1, L2, L3, L4, L5, L6, additionalPKValues, }) => {
|
|
59
|
-
const c =
|
|
65
|
+
const c = "#";
|
|
60
66
|
const keys = [L1, L2, L3, L4, L5, L6].filter(array_1.notEmpty);
|
|
61
|
-
const additionalPK = additionalPKValues && additionalPKValues.length > 0
|
|
62
|
-
? `#${additionalPKValues.join(c)}`
|
|
63
|
-
: '';
|
|
67
|
+
const additionalPK = additionalPKValues && additionalPKValues.length > 0 ? `#${additionalPKValues.join(c)}` : "";
|
|
64
68
|
return {
|
|
65
69
|
PK: keys.join(c) + additionalPK,
|
|
66
70
|
type,
|
|
@@ -19,10 +19,10 @@ async function sendWebSocketMessage(p) {
|
|
|
19
19
|
if (s.$metadata.httpStatusCode === 200) {
|
|
20
20
|
return true;
|
|
21
21
|
}
|
|
22
|
-
throw new Error(
|
|
22
|
+
throw new Error("Error:" + JSON.stringify(s));
|
|
23
23
|
}
|
|
24
24
|
catch (e) {
|
|
25
|
-
(0, common_1.warn)(
|
|
25
|
+
(0, common_1.warn)("Failed to send WebSocket message:", p, e);
|
|
26
26
|
return false;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -43,7 +43,7 @@ async function deleteConnection({ connectionId, endpoint, }) {
|
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
45
45
|
catch (e) {
|
|
46
|
-
(0, common_1.warn)(
|
|
46
|
+
(0, common_1.warn)("Failed to delete WebSocket connection:", e.message);
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -64,7 +64,7 @@ async function isConnectionActive({ connectionId, endpoint, }) {
|
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
66
|
catch (e) {
|
|
67
|
-
(0, common_1.warn)(
|
|
67
|
+
(0, common_1.warn)("Failed to check if WebSocket connection is active:", e.message);
|
|
68
68
|
return false;
|
|
69
69
|
}
|
|
70
70
|
}
|
package/dist/api/helpers/aws.js
CHANGED
|
@@ -8,9 +8,9 @@ const ses_1 = require("./ses");
|
|
|
8
8
|
const sqs_1 = require("./sqs");
|
|
9
9
|
const setAwsRegion = (region) => {
|
|
10
10
|
(0, dynamo_1.setDynamo)(region);
|
|
11
|
-
(0, s3_1.setS3)({ region, provider:
|
|
11
|
+
(0, s3_1.setS3)({ region, provider: "s3" });
|
|
12
12
|
(0, ses_1.setSes)(region);
|
|
13
13
|
(0, sqs_1.setSqs)(region);
|
|
14
|
-
(0, acm_1.setAcm)(
|
|
14
|
+
(0, acm_1.setAcm)("us-east-1");
|
|
15
15
|
};
|
|
16
16
|
exports.setAwsRegion = setAwsRegion;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Container } from
|
|
1
|
+
import type { Container } from "@azure/cosmos";
|
|
2
2
|
export declare function deleteItemCosmos(container: Container, pk: string): Promise<void>;
|
|
3
3
|
export declare function deleteItemsByField(container: Container, field: string, value: string | number | boolean): Promise<{
|
|
4
4
|
error?: string;
|
|
@@ -9,21 +9,19 @@ async function deleteItemCosmos(container, pk) {
|
|
|
9
9
|
try {
|
|
10
10
|
// First query to find items with matching PK
|
|
11
11
|
const querySpec = {
|
|
12
|
-
query:
|
|
13
|
-
parameters: [{ name:
|
|
12
|
+
query: "SELECT * FROM c WHERE c.PK = @pk",
|
|
13
|
+
parameters: [{ name: "@pk", value: pk }],
|
|
14
14
|
};
|
|
15
|
-
const { resources: items } = await container.items
|
|
16
|
-
.query(querySpec)
|
|
17
|
-
.fetchAll();
|
|
15
|
+
const { resources: items } = await container.items.query(querySpec).fetchAll();
|
|
18
16
|
// Delete each found item and collect their IDs
|
|
19
|
-
|
|
20
|
-
(0, log_1.warn)(
|
|
21
|
-
|
|
22
|
-
}
|
|
17
|
+
await Promise.all(items.map((item) => {
|
|
18
|
+
(0, log_1.warn)("deleting items:", item.id, pk);
|
|
19
|
+
return container.item(item.id, pk).delete();
|
|
20
|
+
}));
|
|
23
21
|
}
|
|
24
22
|
catch (e) {
|
|
25
23
|
const em = e.message;
|
|
26
|
-
(0, log_1.error)(
|
|
24
|
+
(0, log_1.error)("Error deleting item:", em);
|
|
27
25
|
throw e;
|
|
28
26
|
}
|
|
29
27
|
}
|
|
@@ -37,7 +35,7 @@ async function deleteItemsByField(container, field, value) {
|
|
|
37
35
|
const { resources } = await container.items
|
|
38
36
|
.query({
|
|
39
37
|
query,
|
|
40
|
-
parameters: [{ name:
|
|
38
|
+
parameters: [{ name: "@value", value }],
|
|
41
39
|
})
|
|
42
40
|
.fetchAll();
|
|
43
41
|
if (resources.length === 0) {
|
|
@@ -47,24 +45,25 @@ async function deleteItemsByField(container, field, value) {
|
|
|
47
45
|
//throw if item.id or PK doesn't exist on an item
|
|
48
46
|
resources.forEach((item) => {
|
|
49
47
|
if (!item.id || !item.PK) {
|
|
50
|
-
throw new Error(
|
|
48
|
+
throw new Error("Item missing required fields: " + JSON.stringify(item));
|
|
51
49
|
}
|
|
52
50
|
});
|
|
53
51
|
const operations = resources.map((item) => ({
|
|
54
52
|
id: item.id,
|
|
55
53
|
partitionKey: item.PK,
|
|
56
|
-
operationType:
|
|
54
|
+
operationType: "Delete",
|
|
57
55
|
}));
|
|
58
56
|
for (let i = 0; i < operations.length; i += utils_1.BULK_CHUNK_SIZE) {
|
|
59
57
|
const chunk = operations.slice(i, i + utils_1.BULK_CHUNK_SIZE);
|
|
60
58
|
// Execute bulk operation with retry
|
|
59
|
+
// oxlint-disable-next-line no-await-in-loop -- chunks are throttled and processed in order
|
|
61
60
|
await (0, withRetry_1.withRetry)(async () => {
|
|
62
61
|
(0, log_1.info)(`Deleting chunk ${i / utils_1.BULK_CHUNK_SIZE + 1} of ${Math.ceil(operations.length / utils_1.BULK_CHUNK_SIZE)}`);
|
|
63
62
|
const bulkResponse = await container.items.bulk(chunk);
|
|
64
63
|
//if an item contains a statuscode 429, then throw an error
|
|
65
64
|
bulkResponse.forEach((response) => {
|
|
66
65
|
if (response.statusCode === 429) {
|
|
67
|
-
throw new Error(
|
|
66
|
+
throw new Error("429");
|
|
68
67
|
}
|
|
69
68
|
});
|
|
70
69
|
// Process results
|
|
@@ -87,12 +86,12 @@ async function deleteItemsByField(container, field, value) {
|
|
|
87
86
|
return bulkResponse;
|
|
88
87
|
}, `bulk_delete_chunk_${i / utils_1.BULK_CHUNK_SIZE + 1}`);
|
|
89
88
|
}
|
|
90
|
-
(0, log_1.info)(
|
|
89
|
+
(0, log_1.info)("All items deleted successfully");
|
|
91
90
|
return {};
|
|
92
91
|
}
|
|
93
92
|
catch (e) {
|
|
94
93
|
const em = e.message;
|
|
95
|
-
(0, log_1.error)(
|
|
94
|
+
(0, log_1.error)("Error deleting items:", em);
|
|
96
95
|
throw e;
|
|
97
96
|
}
|
|
98
97
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Container } from
|
|
1
|
+
import type { Container } from "@azure/cosmos";
|
|
2
2
|
export declare function getItemCosmos<T>(container: Container, partitionValue: string): Promise<T | null>;
|
|
3
3
|
export declare function getItemsByCosmos<T>(container: Container, partitionValues: string[]): Promise<T[]>;
|
|
4
4
|
export declare function queryItemsByText<T>(container: Container, searchFields: {
|
|
5
5
|
fieldName: keyof T & string;
|
|
6
6
|
fieldValue: string;
|
|
7
|
-
type:
|
|
8
|
-
}[], operator?:
|
|
7
|
+
type: "contains" | "equals" | "not_equals";
|
|
8
|
+
}[], operator?: "AND" | "OR"): Promise<T[] | {
|
|
9
9
|
error: string;
|
|
10
10
|
}>;
|
|
11
11
|
export declare function scanCosmos<T>(container: Container): Promise<T[] | {
|
|
@@ -17,17 +17,15 @@ const cache = new node_cache_1.default({ stdTTL: 5 });
|
|
|
17
17
|
async function getItemCosmos(container, partitionValue) {
|
|
18
18
|
try {
|
|
19
19
|
const querySpec = {
|
|
20
|
-
query:
|
|
20
|
+
query: "SELECT TOP 1 * FROM c WHERE c.PK = @val",
|
|
21
21
|
parameters: [
|
|
22
22
|
{
|
|
23
|
-
name:
|
|
23
|
+
name: "@val",
|
|
24
24
|
value: partitionValue,
|
|
25
25
|
},
|
|
26
26
|
],
|
|
27
27
|
};
|
|
28
|
-
const { resources, requestCharge } = await container.items
|
|
29
|
-
.query(querySpec)
|
|
30
|
-
.fetchAll();
|
|
28
|
+
const { resources, requestCharge } = await container.items.query(querySpec).fetchAll();
|
|
31
29
|
(0, log_1.info)(`getItemCosmos:${partitionValue}. chg=${requestCharge}`);
|
|
32
30
|
if (resources.length > 0) {
|
|
33
31
|
return resources[0];
|
|
@@ -37,11 +35,11 @@ async function getItemCosmos(container, partitionValue) {
|
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
catch (e) {
|
|
40
|
-
if (e.message.includes(
|
|
38
|
+
if (e.message.includes("404")) {
|
|
41
39
|
return null;
|
|
42
40
|
}
|
|
43
41
|
const em = e.message;
|
|
44
|
-
(0, log_1.error)(
|
|
42
|
+
(0, log_1.error)("Error deleting item:", em);
|
|
45
43
|
throw e;
|
|
46
44
|
}
|
|
47
45
|
}
|
|
@@ -51,23 +49,21 @@ async function getItemsByCosmos(container, partitionValues) {
|
|
|
51
49
|
return [];
|
|
52
50
|
}
|
|
53
51
|
const querySpec = {
|
|
54
|
-
query:
|
|
52
|
+
query: "SELECT * FROM c WHERE ARRAY_CONTAINS(@values, c.PK)",
|
|
55
53
|
parameters: [
|
|
56
54
|
{
|
|
57
|
-
name:
|
|
55
|
+
name: "@values",
|
|
58
56
|
value: partitionValues,
|
|
59
57
|
},
|
|
60
58
|
],
|
|
61
59
|
};
|
|
62
|
-
const { resources, requestCharge } = await container.items
|
|
63
|
-
.query(querySpec)
|
|
64
|
-
.fetchAll();
|
|
60
|
+
const { resources, requestCharge } = await container.items.query(querySpec).fetchAll();
|
|
65
61
|
(0, log_1.info)(`getItemsByCosmos: fetched ${resources.length} items. chg=${requestCharge}`);
|
|
66
62
|
return resources;
|
|
67
63
|
}
|
|
68
64
|
catch (e) {
|
|
69
65
|
const em = e.message;
|
|
70
|
-
(0, log_1.error)(
|
|
66
|
+
(0, log_1.error)("Error getting multiple items:", em);
|
|
71
67
|
throw e;
|
|
72
68
|
}
|
|
73
69
|
}
|
|
@@ -85,26 +81,24 @@ async function queryItemsCosmos(container, query, parameters) {
|
|
|
85
81
|
}))
|
|
86
82
|
: undefined,
|
|
87
83
|
};
|
|
88
|
-
const { resources, requestCharge } = await container.items
|
|
89
|
-
.query(querySpec)
|
|
90
|
-
.fetchAll();
|
|
84
|
+
const { resources, requestCharge } = await container.items.query(querySpec).fetchAll();
|
|
91
85
|
return { resources, requestCharge };
|
|
92
86
|
}
|
|
93
87
|
catch (e) {
|
|
94
88
|
const em = e.message;
|
|
95
|
-
(0, log_1.error)(
|
|
89
|
+
(0, log_1.error)("Error queryItemsCosmos item:", em);
|
|
96
90
|
return { error: em };
|
|
97
91
|
}
|
|
98
92
|
}
|
|
99
|
-
async function queryItemsByText(container, searchFields, operator =
|
|
93
|
+
async function queryItemsByText(container, searchFields, operator = "AND") {
|
|
100
94
|
try {
|
|
101
95
|
const conditions = searchFields.map((field, index) => {
|
|
102
96
|
switch (field.type) {
|
|
103
|
-
case
|
|
97
|
+
case "contains":
|
|
104
98
|
return `CONTAINS(c.${field.fieldName}, @value${index}, true)`; //true to ignore case
|
|
105
|
-
case
|
|
99
|
+
case "equals":
|
|
106
100
|
return `c.${field.fieldName} = @value${index}`;
|
|
107
|
-
case
|
|
101
|
+
case "not_equals":
|
|
108
102
|
return `c.${field.fieldName} != @value${index}`;
|
|
109
103
|
default:
|
|
110
104
|
throw new Error(`Unsupported field type: ${field.type}`);
|
|
@@ -117,14 +111,14 @@ async function queryItemsByText(container, searchFields, operator = 'AND') {
|
|
|
117
111
|
}, {});
|
|
118
112
|
const x = await queryItemsCosmos(container, query, parameters);
|
|
119
113
|
(0, log_1.debug)(`queryItemsByText: ${JSON.stringify(searchFields)}, operator=${operator}. chg=${x.requestCharge}`);
|
|
120
|
-
if (
|
|
114
|
+
if ("error" in x) {
|
|
121
115
|
throw x.error;
|
|
122
116
|
}
|
|
123
117
|
return x.resources;
|
|
124
118
|
}
|
|
125
119
|
catch (e) {
|
|
126
120
|
const em = e.message;
|
|
127
|
-
(0, log_1.error)(
|
|
121
|
+
(0, log_1.error)("Error queryItemsByText item:", em);
|
|
128
122
|
return { error: em };
|
|
129
123
|
}
|
|
130
124
|
}
|
|
@@ -133,14 +127,14 @@ async function scanCosmos(container) {
|
|
|
133
127
|
const query = `SELECT * FROM c`;
|
|
134
128
|
const x = await queryItemsCosmos(container, query, {});
|
|
135
129
|
(0, log_1.info)(`scan. chg=${x.requestCharge}`);
|
|
136
|
-
if (
|
|
130
|
+
if ("error" in x) {
|
|
137
131
|
throw x.error;
|
|
138
132
|
}
|
|
139
133
|
return x.resources;
|
|
140
134
|
}
|
|
141
135
|
catch (e) {
|
|
142
136
|
const em = e.message;
|
|
143
|
-
(0, log_1.error)(
|
|
137
|
+
(0, log_1.error)("Error queryItemsByText item:", em);
|
|
144
138
|
return { error: em };
|
|
145
139
|
}
|
|
146
140
|
}
|
|
@@ -152,8 +146,8 @@ async function queryItemsByNumber(container, options) {
|
|
|
152
146
|
WHERE IS_NUMBER(c.${field})
|
|
153
147
|
AND c.${field} > @minValue
|
|
154
148
|
AND c.type = @type
|
|
155
|
-
ORDER BY c.${field} ${descending ?
|
|
156
|
-
${limit ?
|
|
149
|
+
ORDER BY c.${field} ${descending ? "DESC" : "ASC"}
|
|
150
|
+
${limit ? "OFFSET 0 LIMIT @limit" : ""}
|
|
157
151
|
`;
|
|
158
152
|
const parameters = {
|
|
159
153
|
type,
|
|
@@ -164,14 +158,14 @@ async function queryItemsByNumber(container, options) {
|
|
|
164
158
|
}
|
|
165
159
|
const x = await queryItemsCosmos(container, query, parameters);
|
|
166
160
|
(0, log_1.debug)(`queryItemsByNumber: type=${type}, field=${field}, minValue=${minValue}, limit=${limit}. chg=${x.requestCharge}`);
|
|
167
|
-
if (
|
|
161
|
+
if ("error" in x) {
|
|
168
162
|
throw x.error;
|
|
169
163
|
}
|
|
170
164
|
return x.resources;
|
|
171
165
|
}
|
|
172
166
|
catch (e) {
|
|
173
167
|
const em = e.message;
|
|
174
|
-
(0, log_1.error)(
|
|
168
|
+
(0, log_1.error)("Error queryItemsByNumber:", em);
|
|
175
169
|
return { error: em };
|
|
176
170
|
}
|
|
177
171
|
}
|
|
@@ -193,7 +187,7 @@ async function queryItemsByType(container, type) {
|
|
|
193
187
|
};
|
|
194
188
|
const x = await queryItemsCosmos(container, query, parameters);
|
|
195
189
|
(0, log_1.info)(`queryItemsByType: type=${type}. chg=${x.requestCharge}`);
|
|
196
|
-
if (
|
|
190
|
+
if ("error" in x) {
|
|
197
191
|
throw x.error;
|
|
198
192
|
}
|
|
199
193
|
const result = x.resources;
|
|
@@ -203,14 +197,14 @@ async function queryItemsByType(container, type) {
|
|
|
203
197
|
}
|
|
204
198
|
catch (e) {
|
|
205
199
|
const em = e.message;
|
|
206
|
-
(0, log_1.error)(
|
|
200
|
+
(0, log_1.error)("Error queryItemsByType:", em);
|
|
207
201
|
return { error: em };
|
|
208
202
|
}
|
|
209
203
|
}
|
|
210
204
|
async function queryItemsByRelevancy(container, type, limit) {
|
|
211
205
|
return queryItemsByNumber(container, {
|
|
212
206
|
type,
|
|
213
|
-
field:
|
|
207
|
+
field: "relevancy",
|
|
214
208
|
limit,
|
|
215
209
|
descending: true,
|
|
216
210
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CosmosSettings } from
|
|
1
|
+
import { type CosmosSettings } from "./utils";
|
|
2
2
|
export declare class Cosmos {
|
|
3
3
|
private container;
|
|
4
4
|
constructor(settings: CosmosSettings);
|
|
@@ -7,8 +7,8 @@ export declare class Cosmos {
|
|
|
7
7
|
queryItemsByText<T>(searchFields: {
|
|
8
8
|
fieldName: keyof T & string;
|
|
9
9
|
fieldValue: string;
|
|
10
|
-
type:
|
|
11
|
-
}[], operator?:
|
|
10
|
+
type: "contains" | "equals" | "not_equals";
|
|
11
|
+
}[], operator?: "AND" | "OR"): Promise<T[] | {
|
|
12
12
|
error: string;
|
|
13
13
|
}>;
|
|
14
14
|
scan<T>(): Promise<T[] | {
|
|
@@ -17,7 +17,7 @@ class Cosmos {
|
|
|
17
17
|
async getItemsBy(partitionValues) {
|
|
18
18
|
return (0, get_1.getItemsByCosmos)(this.container, partitionValues);
|
|
19
19
|
}
|
|
20
|
-
async queryItemsByText(searchFields, operator =
|
|
20
|
+
async queryItemsByText(searchFields, operator = "AND") {
|
|
21
21
|
return (0, get_1.queryItemsByText)(this.container, searchFields, operator);
|
|
22
22
|
}
|
|
23
23
|
async scan() {
|
|
@@ -5,18 +5,14 @@ exports.createContainer = createContainer;
|
|
|
5
5
|
const cosmos_1 = require("@azure/cosmos");
|
|
6
6
|
exports.BULK_CHUNK_SIZE = 50;
|
|
7
7
|
function createContainer(settings) {
|
|
8
|
-
if (!settings.endpoint ||
|
|
9
|
-
|
|
10
|
-
!settings.database_name ||
|
|
11
|
-
!settings.container_name) {
|
|
12
|
-
throw new Error('no cosmos settings');
|
|
8
|
+
if (!settings.endpoint || !settings.key || !settings.database_name || !settings.container_name) {
|
|
9
|
+
throw new Error("no cosmos settings");
|
|
13
10
|
}
|
|
14
11
|
const client = new cosmos_1.CosmosClient(settings);
|
|
15
12
|
const database = client.database(settings.database_name);
|
|
16
13
|
const container = database.container(settings.container_name);
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
18
14
|
if (!container) {
|
|
19
|
-
throw new Error(
|
|
15
|
+
throw new Error("error, cosmos container undefined!!");
|
|
20
16
|
}
|
|
21
17
|
return container;
|
|
22
18
|
}
|
|
@@ -9,12 +9,10 @@ async function putItemCosmos(container, item) {
|
|
|
9
9
|
try {
|
|
10
10
|
// First, try to find existing item with the same PK
|
|
11
11
|
const querySpec = {
|
|
12
|
-
query:
|
|
13
|
-
parameters: [{ name:
|
|
12
|
+
query: "SELECT * FROM c WHERE c.PK = @pk",
|
|
13
|
+
parameters: [{ name: "@pk", value: item.PK }],
|
|
14
14
|
};
|
|
15
|
-
const { resources: existingItems } = await container.items
|
|
16
|
-
.query(querySpec)
|
|
17
|
-
.fetchAll();
|
|
15
|
+
const { resources: existingItems } = await container.items.query(querySpec).fetchAll();
|
|
18
16
|
if (existingItems.length > 0) {
|
|
19
17
|
// If item exists, update it with the existing ID
|
|
20
18
|
const existingItem = existingItems[0];
|
|
@@ -37,7 +35,7 @@ async function putItemCosmos(container, item) {
|
|
|
37
35
|
}
|
|
38
36
|
catch (e) {
|
|
39
37
|
const em = e.message;
|
|
40
|
-
(0, log_1.error)(
|
|
38
|
+
(0, log_1.error)("Error upserting item:", em);
|
|
41
39
|
throw e;
|
|
42
40
|
}
|
|
43
41
|
}
|
|
@@ -50,20 +48,21 @@ async function putItemsCosmos(container, items) {
|
|
|
50
48
|
for (let i = 0; i < items.length; i += utils_1.BULK_CHUNK_SIZE) {
|
|
51
49
|
const chunk = items.slice(i, i + utils_1.BULK_CHUNK_SIZE);
|
|
52
50
|
// Execute bulk operation with retry
|
|
51
|
+
// oxlint-disable-next-line no-await-in-loop -- chunks are throttled and processed in order
|
|
53
52
|
await (0, withRetry_1.withRetry)(async () => {
|
|
54
53
|
(0, log_1.info)(`Writing chunk ${i / utils_1.BULK_CHUNK_SIZE + 1} of ${Math.ceil(items.length / utils_1.BULK_CHUNK_SIZE)}`);
|
|
55
54
|
const operations = await Promise.all(chunk.map(async (item) => {
|
|
56
55
|
// Query to check if item exists
|
|
57
56
|
const querySpec = {
|
|
58
|
-
query:
|
|
59
|
-
parameters: [{ name:
|
|
57
|
+
query: "SELECT * FROM c WHERE c.PK = @pk",
|
|
58
|
+
parameters: [{ name: "@pk", value: item.PK }],
|
|
60
59
|
};
|
|
61
60
|
const { resources: existingItems } = await container.items
|
|
62
61
|
.query(querySpec)
|
|
63
62
|
.fetchAll();
|
|
64
63
|
const existingItem = existingItems[0];
|
|
65
64
|
return {
|
|
66
|
-
operationType:
|
|
65
|
+
operationType: "Upsert",
|
|
67
66
|
partitionKey: item.PK,
|
|
68
67
|
resourceBody: {
|
|
69
68
|
...item,
|
|
@@ -77,7 +76,7 @@ async function putItemsCosmos(container, items) {
|
|
|
77
76
|
let failureCount = 0;
|
|
78
77
|
bulkResponse.forEach((response, index) => {
|
|
79
78
|
if (response.statusCode === 429) {
|
|
80
|
-
throw new Error(
|
|
79
|
+
throw new Error("429");
|
|
81
80
|
}
|
|
82
81
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
83
82
|
successCount++;
|
|
@@ -92,12 +91,12 @@ async function putItemsCosmos(container, items) {
|
|
|
92
91
|
return bulkResponse;
|
|
93
92
|
}, `bulk_write_chunk_${i / utils_1.BULK_CHUNK_SIZE + 1}`);
|
|
94
93
|
}
|
|
95
|
-
(0, log_1.info)(
|
|
94
|
+
(0, log_1.info)("All items written successfully");
|
|
96
95
|
return {};
|
|
97
96
|
}
|
|
98
97
|
catch (e) {
|
|
99
98
|
const em = e.message;
|
|
100
|
-
(0, log_1.error)(
|
|
99
|
+
(0, log_1.error)("Error bulk writing items:", em);
|
|
101
100
|
throw e;
|
|
102
101
|
}
|
|
103
102
|
}
|