From 5bbf25eb7ad5a90afe67bba2ca6d441c3efbf093 Mon Sep 17 00:00:00 2001 From: Matt Straathof Date: Thu, 6 Jun 2024 23:39:21 -0700 Subject: [PATCH 01/15] feat: add new storage clients to nodejs/web sdks --- packages/client-sdk-nodejs/package-lock.json | 382 ++---------------- .../src/config/storage-configuration.ts | 131 ++++++ .../src/config/storage-configurations.ts | 65 +++ .../transport/storage/grpc-configuration.ts | 64 +++ .../src/config/transport/storage/index.ts | 2 + .../transport/storage/transport-strategy.ts | 166 ++++++++ .../transport/topics/grpc-configuration.ts | 4 +- packages/client-sdk-nodejs/src/index.ts | 43 ++ .../storage-client-props-with-config.ts | 6 + .../src/internal/storage-control-client.ts | 159 ++++++++ .../src/internal/storage-data-client.ts | 319 +++++++++++++++ .../src/storage-client-props.ts | 7 + .../client-sdk-nodejs/src/storage-client.ts | 63 +++ .../test/integration/integration-setup.ts | 4 + packages/client-sdk-web/package-lock.json | 26 +- packages/client-sdk-web/package.json | 2 +- .../src/config/storage-configuration.ts | 42 ++ .../src/config/storage-configurations.ts | 30 ++ packages/client-sdk-web/src/index.ts | 7 + .../src/internal/storage-control-client.ts | 167 ++++++++ .../src/internal/storage-data-client.ts | 267 ++++++++++++ .../src/storage-client-props.ts | 13 + packages/client-sdk-web/src/storage-client.ts | 81 ++++ .../src/utils/web-client-utils.ts | 17 + .../test/integration/integration-setup.ts | 7 + .../test/unit/utils/web-client-utils.test.ts | 21 + packages/core/src/auth/credential-provider.ts | 34 ++ packages/core/src/clients/IStorageClient.ts | 23 ++ packages/core/src/index.ts | 6 + packages/core/src/internal/clients/index.ts | 1 + .../clients/storage/AbstractStorageClient.ts | 67 +++ .../clients/storage/IStorageControlClient.ts | 8 + .../clients/storage/IStorageDataClient.ts | 12 + .../src/internal/clients/storage/index.ts | 4 + packages/core/src/internal/utils/auth.ts | 8 + .../core/src/internal/utils/validators.ts | 6 + .../src/messages/responses/enums/index.ts | 1 + .../responses/enums/store/control/index.ts | 15 + .../messages/responses/enums/store/index.ts | 2 + .../responses/enums/store/scalar/index.ts | 17 + .../responses/storage/control/create-store.ts | 42 ++ .../responses/storage/control/delete-store.ts | 34 ++ .../responses/storage/control/index.ts | 3 + .../responses/storage/control/list-stores.ts | 54 +++ .../src/messages/responses/storage/index.ts | 2 + .../responses/storage/scalar/index.ts | 3 + .../responses/storage/scalar/store-delete.ts | 34 ++ .../responses/storage/scalar/store-get.ts | 93 +++++ .../responses/storage/scalar/store-set.ts | 34 ++ packages/core/src/messages/store-info.ts | 11 + .../unit/auth/credential-provider.test.ts | 18 +- 51 files changed, 2268 insertions(+), 359 deletions(-) create mode 100644 packages/client-sdk-nodejs/src/config/storage-configuration.ts create mode 100644 packages/client-sdk-nodejs/src/config/storage-configurations.ts create mode 100644 packages/client-sdk-nodejs/src/config/transport/storage/grpc-configuration.ts create mode 100644 packages/client-sdk-nodejs/src/config/transport/storage/index.ts create mode 100644 packages/client-sdk-nodejs/src/config/transport/storage/transport-strategy.ts create mode 100644 packages/client-sdk-nodejs/src/internal/storage-client-props-with-config.ts create mode 100644 packages/client-sdk-nodejs/src/internal/storage-control-client.ts create mode 100644 packages/client-sdk-nodejs/src/internal/storage-data-client.ts create mode 100644 packages/client-sdk-nodejs/src/storage-client-props.ts create mode 100644 packages/client-sdk-nodejs/src/storage-client.ts create mode 100644 packages/client-sdk-web/src/config/storage-configuration.ts create mode 100644 packages/client-sdk-web/src/config/storage-configurations.ts create mode 100644 packages/client-sdk-web/src/internal/storage-control-client.ts create mode 100644 packages/client-sdk-web/src/internal/storage-data-client.ts create mode 100644 packages/client-sdk-web/src/storage-client-props.ts create mode 100644 packages/client-sdk-web/src/storage-client.ts create mode 100644 packages/core/src/clients/IStorageClient.ts create mode 100644 packages/core/src/internal/clients/storage/AbstractStorageClient.ts create mode 100644 packages/core/src/internal/clients/storage/IStorageControlClient.ts create mode 100644 packages/core/src/internal/clients/storage/IStorageDataClient.ts create mode 100644 packages/core/src/internal/clients/storage/index.ts create mode 100644 packages/core/src/messages/responses/enums/store/control/index.ts create mode 100644 packages/core/src/messages/responses/enums/store/index.ts create mode 100644 packages/core/src/messages/responses/enums/store/scalar/index.ts create mode 100644 packages/core/src/messages/responses/storage/control/create-store.ts create mode 100644 packages/core/src/messages/responses/storage/control/delete-store.ts create mode 100644 packages/core/src/messages/responses/storage/control/index.ts create mode 100644 packages/core/src/messages/responses/storage/control/list-stores.ts create mode 100644 packages/core/src/messages/responses/storage/index.ts create mode 100644 packages/core/src/messages/responses/storage/scalar/index.ts create mode 100644 packages/core/src/messages/responses/storage/scalar/store-delete.ts create mode 100644 packages/core/src/messages/responses/storage/scalar/store-get.ts create mode 100644 packages/core/src/messages/responses/storage/scalar/store-set.ts create mode 100644 packages/core/src/messages/store-info.ts diff --git a/packages/client-sdk-nodejs/package-lock.json b/packages/client-sdk-nodejs/package-lock.json index ec36d57a6..0157d6d22 100644 --- a/packages/client-sdk-nodejs/package-lock.json +++ b/packages/client-sdk-nodejs/package-lock.json @@ -42,7 +42,24 @@ "node": ">= 16" } }, + "../../../client-protos/javascript": { + "version": "0.0.1", + "license": "Apache-2.0", + "dependencies": { + "@grpc/grpc-js": "1.10.5", + "google-protobuf": "3.21.2", + "grpc-tools": "^1.12.4", + "protoc-gen-ts": "^0.8.6" + }, + "devDependencies": { + "@tsconfig/node16": "1.0.2", + "@types/google-protobuf": "3.15.6", + "@types/node": "16.10.3", + "typescript": "4.9.5" + } + }, "../common-integration-tests": { + "name": "@gomomento/common-integration-tests", "version": "0.0.1", "dev": true, "license": "Apache-2.0", @@ -74,6 +91,7 @@ } }, "../core": { + "name": "@gomomento/sdk-core", "version": "0.0.1", "license": "Apache-2.0", "dependencies": { @@ -1279,25 +1297,6 @@ "url": "https://opencollective.com/js-sdsl" } }, - "node_modules/@mapbox/node-pre-gyp": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.11.tgz", - "integrity": "sha512-Yhlar6v9WQgUp/He7BdgzOz8lqMQ8sU+jkCq7Wx8Myc5YFJLbEe7lgui/V7G1qB1DJykHSGwreceSaD60Y0PUQ==", - "dependencies": { - "detect-libc": "^2.0.0", - "https-proxy-agent": "^5.0.0", - "make-dir": "^3.1.0", - "node-fetch": "^2.6.7", - "nopt": "^5.0.0", - "npmlog": "^5.0.1", - "rimraf": "^3.0.2", - "semver": "^7.3.5", - "tar": "^6.1.11" - }, - "bin": { - "node-pre-gyp": "bin/node-pre-gyp" - } - }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -1813,11 +1812,6 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/abbrev": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" - }, "node_modules/acorn": { "version": "7.4.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", @@ -1848,17 +1842,6 @@ "node": ">=0.4.0" } }, - "node_modules/agent-base": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", - "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", - "dependencies": { - "debug": "4" - }, - "engines": { - "node": ">= 6.0.0" - } - }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -2245,12 +2228,14 @@ "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2409,14 +2394,6 @@ "node": ">=10" } }, - "node_modules/chownr": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", - "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", - "engines": { - "node": ">=10" - } - }, "node_modules/ci-info": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", @@ -2489,23 +2466,11 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, - "node_modules/color-support": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", - "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", - "bin": { - "color-support": "bin.js" - } - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" - }, - "node_modules/console-control-strings": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==" + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true }, "node_modules/convert-source-map": { "version": "2.0.0", @@ -2684,19 +2649,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/delegates": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", - "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==" - }, - "node_modules/detect-libc": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz", - "integrity": "sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw==", - "engines": { - "node": ">=8" - } - }, "node_modules/detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -3573,37 +3525,11 @@ "is-callable": "^1.1.3" } }, - "node_modules/fs-minipass": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", - "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", - "dependencies": { - "minipass": "^3.0.0" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/fs-minipass/node_modules/minipass": { - "version": "3.3.6", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", - "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/fs-minipass/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" - }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "dev": true }, "node_modules/fsevents": { "version": "2.3.3", @@ -3867,19 +3793,6 @@ "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", "dev": true }, - "node_modules/grpc-tools": { - "version": "1.12.4", - "resolved": "https://registry.npmjs.org/grpc-tools/-/grpc-tools-1.12.4.tgz", - "integrity": "sha512-5+mLAJJma3BjnW/KQp6JBjUMgvu7Mu3dBvBPd1dcbNIb+qiR0817zDpgPjS7gRb+l/8EVNIa3cB02xI9JLToKg==", - "hasInstallScript": true, - "dependencies": { - "@mapbox/node-pre-gyp": "^1.0.5" - }, - "bin": { - "grpc_tools_node_protoc": "bin/protoc.js", - "grpc_tools_node_protoc_plugin": "bin/protoc_plugin.js" - } - }, "node_modules/has-bigints": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", @@ -3949,11 +3862,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/has-unicode": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", - "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==" - }, "node_modules/hasown": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", @@ -3972,18 +3880,6 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, - "node_modules/https-proxy-agent": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", - "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", - "dependencies": { - "agent-base": "6", - "debug": "4" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -4059,7 +3955,8 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true }, "node_modules/internal-slot": { "version": "1.0.7", @@ -5527,28 +5424,6 @@ "yallist": "^3.0.2" } }, - "node_modules/make-dir": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", - "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", - "dependencies": { - "semver": "^6.0.0" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/make-dir/node_modules/semver": { - "version": "6.3.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", - "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", - "bin": { - "semver": "bin/semver.js" - } - }, "node_modules/make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", @@ -5605,6 +5480,7 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, "dependencies": { "brace-expansion": "^1.1.7" }, @@ -5621,57 +5497,11 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/minipass": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", - "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==", - "engines": { - "node": ">=8" - } - }, - "node_modules/minizlib": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", - "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", - "dependencies": { - "minipass": "^3.0.0", - "yallist": "^4.0.0" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/minizlib/node_modules/minipass": { - "version": "3.3.6", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", - "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/minizlib/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" - }, - "node_modules/mkdirp": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", - "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", - "bin": { - "mkdirp": "bin/cmd.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true }, "node_modules/natural-compare": { "version": "1.4.0", @@ -5685,25 +5515,6 @@ "integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==", "dev": true }, - "node_modules/node-fetch": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", - "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -5716,20 +5527,6 @@ "integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==", "dev": true }, - "node_modules/nopt": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", - "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", - "dependencies": { - "abbrev": "1" - }, - "bin": { - "nopt": "bin/nopt.js" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -5860,6 +5657,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dev": true, "dependencies": { "wrappy": "1" } @@ -5996,6 +5794,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "dev": true, "engines": { "node": ">=0.10.0" } @@ -6179,18 +5978,6 @@ "node": ">=12.0.0" } }, - "node_modules/protoc-gen-ts": { - "version": "0.8.7", - "resolved": "https://registry.npmjs.org/protoc-gen-ts/-/protoc-gen-ts-0.8.7.tgz", - "integrity": "sha512-jr4VJey2J9LVYCV7EVyVe53g1VMw28cCmYJhBe5e3YX5wiyiDwgxWxeDf9oTqAe4P1bN/YGAkW2jhlH8LohwiQ==", - "bin": { - "protoc-gen-ts": "protoc-gen-ts.js" - }, - "funding": { - "type": "individual", - "url": "https://www.buymeacoffee.com/thesayyn" - } - }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -6242,19 +6029,6 @@ "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", "dev": true }, - "node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/regexp.prototype.flags": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", @@ -6424,25 +6198,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, "node_modules/safe-regex-test": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.0.3.tgz", @@ -6464,6 +6219,7 @@ "version": "7.6.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", + "dev": true, "bin": { "semver": "bin/semver.js" }, @@ -6471,11 +6227,6 @@ "node": ">=10" } }, - "node_modules/set-blocking": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" - }, "node_modules/set-function-length": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", @@ -6550,7 +6301,8 @@ "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "dev": true }, "node_modules/sisteransi": { "version": "1.0.5", @@ -6630,14 +6382,6 @@ "node": ">=8" } }, - "node_modules/string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "dependencies": { - "safe-buffer": "~5.2.0" - } - }, "node_modules/string-length": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz", @@ -6816,27 +6560,6 @@ "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", "dev": true }, - "node_modules/tar": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.1.tgz", - "integrity": "sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==", - "dependencies": { - "chownr": "^2.0.0", - "fs-minipass": "^2.0.0", - "minipass": "^5.0.0", - "minizlib": "^2.1.1", - "mkdirp": "^1.0.3", - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/tar/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" - }, "node_modules/test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -6884,11 +6607,6 @@ "node": ">=8.0" } }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" - }, "node_modules/ts-jest": { "version": "29.1.1", "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.1.tgz", @@ -7224,11 +6942,6 @@ "punycode": "^2.1.0" } }, - "node_modules/util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" - }, "node_modules/uuid": { "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", @@ -7273,20 +6986,6 @@ "makeerror": "1.0.12" } }, - "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" - }, - "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -7337,14 +7036,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/wide-align": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", - "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==", - "dependencies": { - "string-width": "^1.0.2 || 2 || 3 || 4" - } - }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", @@ -7373,7 +7064,8 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "dev": true }, "node_modules/write-file-atomic": { "version": "4.0.2", diff --git a/packages/client-sdk-nodejs/src/config/storage-configuration.ts b/packages/client-sdk-nodejs/src/config/storage-configuration.ts new file mode 100644 index 000000000..479199399 --- /dev/null +++ b/packages/client-sdk-nodejs/src/config/storage-configuration.ts @@ -0,0 +1,131 @@ +import {MomentoLoggerFactory} from '../'; +import {Middleware} from './middleware/middleware'; +import {StorageTransportStrategy} from './transport/storage'; + +/** + * Configuration options for Momento StorageClient + * + * @export + * @interface StorageConfiguration + */ +export interface StorageConfiguration { + /** + * @returns {MomentoLoggerFactory} the current configuration options for logging verbosity and format + */ + getLoggerFactory(): MomentoLoggerFactory; + + /** + * @returns {StorageTransportStrategy} the current configuration options for wire interactions with the Momento service + */ + getTransportStrategy(): StorageTransportStrategy; + + /** + * Convenience copy constructor that updates the client-side timeout setting in the TransportStrategy + * @param {number} clientTimeoutMillis + * @returns {StorageConfiguration} a new Configuration object with its TransportStrategy updated to use the specified client timeout + */ + withClientTimeoutMillis(clientTimeoutMillis: number): StorageConfiguration; + + /** + * Copy constructor for overriding TransportStrategy + * @param {StorageTransportStrategy} transportStrategy + * @returns {Configuration} a new Configuration object with the specified TransportStrategy + */ + withTransportStrategy( + transportStrategy: StorageTransportStrategy + ): StorageConfiguration; + + /** + * @returns {Middleware[]} the middleware functions that will wrap each request + */ + getMiddlewares(): Middleware[]; + + /** + * Copy constructor for overriding Middlewares + * @param {Middleware[]} middlewares + * @returns {Configuration} a new Configuration object with the specified Middlewares + */ + withMiddlewares(middlewares: Middleware[]): StorageConfiguration; + + /** + * Copy constructor that adds a single middleware to the existing middlewares + * @param {Middleware} middleware + * @returns {Configuration} a new Configuration object with the specified Middleware appended to the list of existing Middlewares + */ + addMiddleware(middleware: Middleware): StorageConfiguration; +} + +export interface StorageConfigurationProps { + /** + * Configures logging verbosity and format + */ + loggerFactory: MomentoLoggerFactory; + /** + * Configures low-level options for network interactions with the Momento service + */ + transportStrategy: StorageTransportStrategy; + + /** + * Configures middleware functions that will wrap each request + */ + middlewares: Middleware[]; +} + +export class StorageClientConfiguration implements StorageConfiguration { + private readonly loggerFactory: MomentoLoggerFactory; + private readonly transportStrategy: StorageTransportStrategy; + private readonly middlewares: Middleware[]; + + constructor(props: StorageConfigurationProps) { + this.loggerFactory = props.loggerFactory; + this.transportStrategy = props.transportStrategy; + this.middlewares = props.middlewares; + } + + getLoggerFactory(): MomentoLoggerFactory { + return this.loggerFactory; + } + + getTransportStrategy(): StorageTransportStrategy { + return this.transportStrategy; + } + + withClientTimeoutMillis(clientTimeoutMillis: number): StorageConfiguration { + return new StorageClientConfiguration({ + loggerFactory: this.loggerFactory, + transportStrategy: + this.transportStrategy.withClientTimeoutMillis(clientTimeoutMillis), + middlewares: this.middlewares, + }); + } + + withTransportStrategy( + transportStrategy: StorageTransportStrategy + ): StorageConfiguration { + return new StorageClientConfiguration({ + loggerFactory: this.loggerFactory, + transportStrategy: transportStrategy, + middlewares: this.middlewares, + }); + } + + getMiddlewares(): Middleware[] { + return this.middlewares; + } + + withMiddlewares(middlewares: Middleware[]): StorageConfiguration { + return new StorageClientConfiguration({ + loggerFactory: this.loggerFactory, + transportStrategy: this.transportStrategy, + middlewares: middlewares, + }); + } + + addMiddleware(middleware: Middleware): StorageConfiguration { + return new StorageClientConfiguration({ + loggerFactory: this.loggerFactory, + transportStrategy: this.transportStrategy, + middlewares: [middleware, ...this.middlewares], + }); + } +} diff --git a/packages/client-sdk-nodejs/src/config/storage-configurations.ts b/packages/client-sdk-nodejs/src/config/storage-configurations.ts new file mode 100644 index 000000000..68bf14e3f --- /dev/null +++ b/packages/client-sdk-nodejs/src/config/storage-configurations.ts @@ -0,0 +1,65 @@ +import {MomentoLoggerFactory} from '@gomomento/sdk-core'; +import {DefaultMomentoLoggerFactory} from './logging/default-momento-logger'; +import {Middleware} from './middleware/middleware'; +import { + StorageClientConfiguration, + StorageConfiguration, +} from './storage-configuration'; +import { + StaticStorageGrpcConfiguration, + StaticStorageTransportStrategy, + StorageGrpcConfiguration, + StorageTransportStrategy, +} from './transport/storage'; + +const defaultMaxIdleMillis = 4 * 60 * 1_000; +const defaultMaxSessionMemoryMb = 256; +const defaultLoggerFactory: MomentoLoggerFactory = + new DefaultMomentoLoggerFactory(); +const defaultMiddlewares: Middleware[] = []; + +/** + * Laptop config provides defaults suitable for a medium-to-high-latency dev environment. + * @export + * @class Laptop + */ +export class Laptop extends StorageClientConfiguration { + /** + * Provides the latest recommended configuration for a laptop development environment. NOTE: this configuration may + * change in future releases to take advantage of improvements we identify for default configurations. + * @param {MomentoLoggerFactory} [loggerFactory=defaultLoggerFactory] + * @returns {StorageConfiguration} + */ + static latest( + loggerFactory: MomentoLoggerFactory = defaultLoggerFactory + ): StorageConfiguration { + return Laptop.v0(loggerFactory); + } + + /** + * Provides v0 recommended configuration for a laptop development environment. This configuration is guaranteed not + * to change in future releases of the Momento web SDK. + * @param {MomentoLoggerFactory} [loggerFactory=defaultLoggerFactory] + * @returns {StorageConfiguration} + */ + static v0( + loggerFactory: MomentoLoggerFactory = defaultLoggerFactory + ): StorageConfiguration { + const deadlineMillis = 5000; + const grpcConfig: StorageGrpcConfiguration = + new StaticStorageGrpcConfiguration({ + deadlineMillis, + maxSessionMemoryMb: defaultMaxSessionMemoryMb, + }); + const transportStrategy: StorageTransportStrategy = + new StaticStorageTransportStrategy({ + grpcConfiguration: grpcConfig, + maxIdleMillis: defaultMaxIdleMillis, + }); + return new Laptop({ + loggerFactory: loggerFactory, + transportStrategy: transportStrategy, + middlewares: defaultMiddlewares, + }); + } +} diff --git a/packages/client-sdk-nodejs/src/config/transport/storage/grpc-configuration.ts b/packages/client-sdk-nodejs/src/config/transport/storage/grpc-configuration.ts new file mode 100644 index 000000000..5ae8672fc --- /dev/null +++ b/packages/client-sdk-nodejs/src/config/transport/storage/grpc-configuration.ts @@ -0,0 +1,64 @@ +export interface StorageGrpcConfigurationProps { + /** + * The number of internal clients a storage client will create to communicate with Momento. More of them allows + * more concurrent requests, at the cost of more open connections and the latency of setting up each client. + */ + numClients?: number; + + /** + * number of milliseconds the client is willing to wait for an RPC to complete before it is terminated + * with a DeadlineExceeded error. + */ + deadlineMillis: number; + /** + * the maximum amount of memory, in megabytes, that a session is allowed to consume. Sessions that consume + * more than this amount will return a ResourceExhausted error. + */ + maxSessionMemoryMb: number; +} + +/** + * Encapsulates gRPC configuration tunables. + * @export + * @interface StorageGrpcConfiguration + */ +export interface StorageGrpcConfiguration { + /** + * @returns {number} the number of internal clients a storage client will create to communicate with Momento. More of + * them will allow for more concurrent requests. + */ + getNumClients(): number; + + /** + * Copy constructor for overriding the number of clients to create + * @param {number} numClients the number of internal clients to create + * @returns {GrpcConfiguration} a new GrpcConfiguration with the specified number of clients + */ + withNumClients(numClients: number): StorageGrpcConfiguration; + + /** + * @returns {number} number of milliseconds the client is willing to wait for an RPC to complete before it is terminated + * with a DeadlineExceeded error. + */ + getDeadlineMillis(): number; + + /** + * Copy constructor for overriding the client-side deadline + * @param {number} deadlineMillis + * @returns {StorageGrpcConfiguration} a new StorageGrpcConfiguration with the specified client-side deadline + */ + withDeadlineMillis(deadlineMillis: number): StorageGrpcConfiguration; + + /** + * @returns {number} the maximum amount of memory, in megabytes, that a session is allowed to consume. Sessions that consume + * more than this amount will return a ResourceExhausted error. + */ + getMaxSessionMemoryMb(): number; + + /** + * Copy constructor for overriding the max session memory + * @param {number} maxSessionMemoryMb the desired maximum amount of memory, in megabytes, to allow a client session to consume + * @returns {StorageGrpcConfiguration} a new StorageGrpcConfiguration with the specified maximum memory + */ + withMaxSessionMemoryMb(maxSessionMemoryMb: number): StorageGrpcConfiguration; +} diff --git a/packages/client-sdk-nodejs/src/config/transport/storage/index.ts b/packages/client-sdk-nodejs/src/config/transport/storage/index.ts new file mode 100644 index 000000000..274180861 --- /dev/null +++ b/packages/client-sdk-nodejs/src/config/transport/storage/index.ts @@ -0,0 +1,2 @@ +export * from './grpc-configuration'; +export * from './transport-strategy'; diff --git a/packages/client-sdk-nodejs/src/config/transport/storage/transport-strategy.ts b/packages/client-sdk-nodejs/src/config/transport/storage/transport-strategy.ts new file mode 100644 index 000000000..c554937c7 --- /dev/null +++ b/packages/client-sdk-nodejs/src/config/transport/storage/transport-strategy.ts @@ -0,0 +1,166 @@ +import { + StorageGrpcConfiguration, + StorageGrpcConfigurationProps, +} from './grpc-configuration'; + +export interface StorageTransportStrategy { + /** + * Configures the low-level gRPC settings for the Momento client's communication + * with the Momento server. + * @returns {StorageGrpcConfiguration} + */ + getGrpcConfig(): StorageGrpcConfiguration; + + /** + * Copy constructor for overriding the gRPC configuration + * @param {TopicGrpcConfiguration} grpcConfig + * @returns {TopicTransportStrategy} a new StorageTransportStrategy with the specified gRPC config. + */ + withGrpcConfig( + grpcConfig: StorageGrpcConfiguration + ): StorageTransportStrategy; + + /** + * Copy constructor to update the client-side timeout + * @param {number} clientTimeoutMillis + * @returns {StorageTransportStrategy} a new StorageTransportStrategy with the specified client timeout + */ + withClientTimeoutMillis( + clientTimeoutMillis: number + ): StorageTransportStrategy; + + /** + * Copy constructor to update the max idle connection timeout. (See {getMaxIdleMillis}.) + * @param {number} maxIdleMillis + * @returns {StorageTransportStrategy} a new StorageTransportStrategy with the specified max idle connection timeout. + */ + withMaxIdleMillis(maxIdleMillis: number): StorageTransportStrategy; + + /** + * The maximum duration for which a connection may remain idle before being replaced. This + * setting can be used to force re-connection of a client if it has been idle for too long. + * In environments such as AWS lambda, if the lambda is suspended for too long the connection + * may be closed by the load balancer, resulting in an error on the subsequent request. If + * this setting is set to a duration less than the load balancer timeout, we can ensure that + * the connection will be refreshed to avoid errors. + * @returns {number} + */ + getMaxIdleMillis(): number; +} + +export interface StorageTransportStrategyProps { + /** + * low-level gRPC settings for communication with the Momento server + */ + grpcConfiguration: StorageGrpcConfiguration; + /** + * The maximum duration for which a connection may remain idle before being replaced. This + * setting can be used to force re-connection of a client if it has been idle for too long. + * In environments such as AWS lambda, if the lambda is suspended for too long the connection + * may be closed by the load balancer, resulting in an error on the subsequent request. If + * this setting is set to a duration less than the load balancer timeout, we can ensure that + * the connection will be refreshed to avoid errors. + * @returns {number} + */ + maxIdleMillis: number; +} + +export class StaticStorageGrpcConfiguration + implements StorageGrpcConfiguration +{ + private readonly numClients: number; + private readonly deadlineMillis: number; + private readonly maxSessionMemoryMb: number; + + constructor(props: StorageGrpcConfigurationProps) { + if (props.numClients !== undefined && props.numClients !== null) { + this.numClients = props.numClients; + } else { + this.numClients = 1; + } + this.deadlineMillis = props.deadlineMillis; + this.maxSessionMemoryMb = props.maxSessionMemoryMb; + } + + getNumClients(): number { + return this.numClients; + } + + withNumClients(numClients: number): StorageGrpcConfiguration { + return new StaticStorageGrpcConfiguration({ + numClients: numClients, + deadlineMillis: this.deadlineMillis, + maxSessionMemoryMb: this.maxSessionMemoryMb, + }); + } + + getDeadlineMillis(): number { + return this.deadlineMillis; + } + + withDeadlineMillis(deadlineMillis: number): StorageGrpcConfiguration { + return new StaticStorageGrpcConfiguration({ + deadlineMillis: deadlineMillis, + numClients: this.numClients, + maxSessionMemoryMb: this.maxSessionMemoryMb, + }); + } + + getMaxSessionMemoryMb(): number { + return this.maxSessionMemoryMb; + } + + withMaxSessionMemoryMb(maxSessionMemoryMb: number): StorageGrpcConfiguration { + return new StaticStorageGrpcConfiguration({ + deadlineMillis: this.deadlineMillis, + numClients: this.numClients, + maxSessionMemoryMb: maxSessionMemoryMb, + }); + } +} + +export class StaticStorageTransportStrategy + implements StorageTransportStrategy +{ + private readonly grpcConfig: StorageGrpcConfiguration; + private readonly maxIdleMillis: number; + + constructor(props: StorageTransportStrategyProps) { + this.grpcConfig = props.grpcConfiguration; + this.maxIdleMillis = props.maxIdleMillis; + } + + getGrpcConfig(): StorageGrpcConfiguration { + return this.grpcConfig; + } + + withGrpcConfig( + grpcConfig: StorageGrpcConfiguration + ): StorageTransportStrategy { + return new StaticStorageTransportStrategy({ + grpcConfiguration: grpcConfig, + maxIdleMillis: this.maxIdleMillis, + }); + } + + withClientTimeoutMillis( + clientTimeoutMillis: number + ): StorageTransportStrategy { + return new StaticStorageTransportStrategy({ + grpcConfiguration: + this.grpcConfig.withDeadlineMillis(clientTimeoutMillis), + maxIdleMillis: this.maxIdleMillis, + }); + } + + getMaxIdleMillis(): number { + return this.maxIdleMillis; + } + + withMaxIdleMillis(maxIdleMillis: number): StorageTransportStrategy { + return new StaticStorageTransportStrategy({ + grpcConfiguration: this.grpcConfig, + maxIdleMillis: maxIdleMillis, + }); + } +} diff --git a/packages/client-sdk-nodejs/src/config/transport/topics/grpc-configuration.ts b/packages/client-sdk-nodejs/src/config/transport/topics/grpc-configuration.ts index f2c830ab8..ea253098b 100644 --- a/packages/client-sdk-nodejs/src/config/transport/topics/grpc-configuration.ts +++ b/packages/client-sdk-nodejs/src/config/transport/topics/grpc-configuration.ts @@ -1,6 +1,6 @@ export interface TopicGrpcConfigurationProps { /** - * The number of internal clients a cache client will create to communicate with Momento. More of them allows + * The number of internal clients a topic client will create to communicate with Momento. More of them allows * more concurrent requests, at the cost of more open connections and the latency of setting up each client. */ numClients?: number; @@ -13,7 +13,7 @@ export interface TopicGrpcConfigurationProps { */ export interface TopicGrpcConfiguration { /** - * @returns {number} the number of internal clients a cache client will create to communicate with Momento. More of + * @returns {number} the number of internal clients a topic client will create to communicate with Momento. More of * them will allow for more concurrent requests. */ getNumClients(): number; diff --git a/packages/client-sdk-nodejs/src/index.ts b/packages/client-sdk-nodejs/src/index.ts index 805583923..c7e5f65a4 100644 --- a/packages/client-sdk-nodejs/src/index.ts +++ b/packages/client-sdk-nodejs/src/index.ts @@ -1,7 +1,9 @@ import {CacheClient, SimpleCacheClient} from './cache-client'; import {TopicClient} from './topic-client'; +import {StorageClient} from './storage-client'; import * as Configurations from './config/configurations'; import * as TopicConfigurations from './config/topic-configurations'; +import * as StorageConfigurations from './config/storage-configurations'; import * as LeaderboardConfigurations from './config/leaderboard-configurations'; import * as BatchUtils from './batchutils/batch-functions'; import * as WebhookUtils from './webhookutils'; @@ -75,6 +77,17 @@ import * as TopicPublish from '@gomomento/sdk-core/dist/src/messages/responses/t import * as TopicSubscribe from '@gomomento/sdk-core/dist/src/messages/responses/topic-subscribe'; import {TopicItem} from '@gomomento/sdk-core/dist/src/messages/responses/topic-item'; +// Storage Response Types +import { + StoreDelete, + StoreSet, + StoreGet, + CreateStore, + DeleteStore, + ListStores, +} from '@gomomento/sdk-core/dist/src/messages/responses/storage'; +import {StoreInfo} from '@gomomento/sdk-core/dist/src/messages/store-info'; + // AuthClient Response Types import {AuthClient} from './auth-client'; import * as GenerateApiKey from '@gomomento/sdk-core/dist/src/messages/responses/generate-api-key'; @@ -155,6 +168,7 @@ import { WebhookDestinationType, ReadConcern, CompressionLevel, + IStorageClient, } from '@gomomento/sdk-core'; import {Configuration, CacheConfiguration} from './config/configuration'; @@ -167,6 +181,10 @@ import { LeaderboardClientConfiguration, } from './config/leaderboard-configuration'; import {PreviewLeaderboardClient} from './preview-leaderboard-client'; +import { + StorageConfiguration, + StorageClientConfiguration, +} from './config/storage-configuration'; export { DefaultMomentoLoggerFactory, @@ -215,6 +233,18 @@ export { TopicGrpcConfigurationProps, } from './config/transport/topics/grpc-configuration'; +export { + StaticStorageGrpcConfiguration, + StaticStorageTransportStrategy, + StorageTransportStrategy, + StorageTransportStrategyProps, +} from './config/transport/storage/transport-strategy'; + +export { + StorageGrpcConfiguration, + StorageGrpcConfigurationProps, +} from './config/transport/storage/grpc-configuration'; + export { Middleware, MiddlewareRequestHandler, @@ -347,6 +377,19 @@ export { TopicPublish, TopicSubscribe, SubscribeCallOptions, + // Storage + StorageConfigurations, + StorageConfiguration, + StorageClientConfiguration, + StoreSet, + StoreGet, + StoreDelete, + CreateStore, + DeleteStore, + ListStores, + StoreInfo, + StorageClient, + IStorageClient, // Webhooks PostUrlWebhookDestination, Webhook, diff --git a/packages/client-sdk-nodejs/src/internal/storage-client-props-with-config.ts b/packages/client-sdk-nodejs/src/internal/storage-client-props-with-config.ts new file mode 100644 index 000000000..b041cc77f --- /dev/null +++ b/packages/client-sdk-nodejs/src/internal/storage-client-props-with-config.ts @@ -0,0 +1,6 @@ +import {StorageConfiguration} from '../config/storage-configuration'; +import {StorageClientProps} from '../storage-client-props'; + +export interface StorageClientPropsWithConfig extends StorageClientProps { + configuration: StorageConfiguration; +} diff --git a/packages/client-sdk-nodejs/src/internal/storage-control-client.ts b/packages/client-sdk-nodejs/src/internal/storage-control-client.ts new file mode 100644 index 000000000..c1abde6de --- /dev/null +++ b/packages/client-sdk-nodejs/src/internal/storage-control-client.ts @@ -0,0 +1,159 @@ +import {control} from '@gomomento/generated-types'; +import grpcControl = control.control_client; +import {Header, HeaderInterceptorProvider} from './grpc/headers-interceptor'; +import {ClientTimeoutInterceptor} from './grpc/client-timeout-interceptor'; +import {Status} from '@grpc/grpc-js/build/src/constants'; +import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; +import {ChannelCredentials, Interceptor} from '@grpc/grpc-js'; +import {MomentoLogger, StoreInfo, ListStores} from '..'; +import {version} from '../../package.json'; +import {IdleGrpcClientWrapper} from './grpc/idle-grpc-client-wrapper'; +import {GrpcClientWrapper} from './grpc/grpc-client-wrapper'; +import {validateStoreName} from '@gomomento/sdk-core/dist/src/internal/utils'; +import {CreateStore, DeleteStore} from '@gomomento/sdk-core'; +import {StorageClientPropsWithConfig} from './storage-client-props-with-config'; + +export class StorageControlClient { + private readonly clientWrapper: GrpcClientWrapper; + private readonly interceptors: Interceptor[]; + private static readonly REQUEST_TIMEOUT_MS: number = 60 * 1000; + private readonly logger: MomentoLogger; + private readonly cacheServiceErrorMapper: CacheServiceErrorMapper; + + /** + * @param {StorageClientProps} props + */ + constructor(props: StorageClientPropsWithConfig) { + this.logger = props.configuration.getLoggerFactory().getLogger(this); + this.cacheServiceErrorMapper = new CacheServiceErrorMapper(false); + const headers = [ + new Header('Authorization', props.credentialProvider.getAuthToken()), + new Header('Agent', `nodejs:${version}`), + ]; + this.interceptors = [ + new HeaderInterceptorProvider(headers).createHeadersInterceptor(), + ClientTimeoutInterceptor(StorageControlClient.REQUEST_TIMEOUT_MS), + ]; + this.logger.debug( + `Creating storage control client using endpoint: '${props.credentialProvider.getControlEndpoint()}` + ); + this.clientWrapper = new IdleGrpcClientWrapper({ + clientFactoryFn: () => + new grpcControl.ScsControlClient( + props.credentialProvider.getControlEndpoint(), + props.credentialProvider.isControlEndpointSecure() + ? ChannelCredentials.createSsl() + : ChannelCredentials.createInsecure() + ), + loggerFactory: props.configuration.getLoggerFactory(), + maxIdleMillis: props.configuration + .getTransportStrategy() + .getGrpcConfig() + .getDeadlineMillis(), + }); + } + close() { + this.logger.debug('Closing storage control client'); + this.clientWrapper.getClient().close(); + } + + public async createStore(name: string): Promise { + try { + validateStoreName(name); + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new CreateStore.Error(err) + ); + } + this.logger.debug(`Creating store: ${name}`); + const request = new grpcControl._CreateStoreRequest({ + store_name: name, + }); + return await new Promise((resolve, reject) => { + this.clientWrapper + .getClient() + .CreateStore( + request, + {interceptors: this.interceptors}, + (err, _resp) => { + if (err) { + if (err.code === Status.ALREADY_EXISTS) { + resolve(new CreateStore.AlreadyExists()); + } else { + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new CreateStore.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); + } + } else { + resolve(new CreateStore.Success()); + } + } + ); + }); + } + + public async deleteStore(name: string): Promise { + try { + validateStoreName(name); + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new DeleteStore.Error(err) + ); + } + const request = new grpcControl._DeleteStoreRequest({ + store_name: name, + }); + this.logger.debug(`Deleting store: ${name}`); + return await new Promise((resolve, reject) => { + this.clientWrapper + .getClient() + .DeleteStore( + request, + {interceptors: this.interceptors}, + (err, _resp) => { + if (err) { + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new DeleteStore.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); + } else { + resolve(new DeleteStore.Success()); + } + } + ); + }); + } + + public async listStores(): Promise { + const request = new grpcControl._ListStoresRequest(); + request.next_token = ''; + this.logger.debug("Issuing 'listStores' request"); + return await new Promise((resolve, reject) => { + this.clientWrapper + .getClient() + .ListStores(request, {interceptors: this.interceptors}, (err, resp) => { + if (err || !resp) { + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new ListStores.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); + } else { + const stores = resp.store.map(store => { + const storeName = store.store_name; + return new StoreInfo(storeName); + }); + resolve(new ListStores.Success(stores)); + } + }); + }); + } +} diff --git a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts new file mode 100644 index 000000000..a5e8ed354 --- /dev/null +++ b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts @@ -0,0 +1,319 @@ +import { + CredentialProvider, + InvalidArgumentError, + MomentoLogger, + MomentoLoggerFactory, + StoreGet, + StoreSet, + StoreDelete, +} from '@gomomento/sdk-core'; +import {validateStoreName} from '@gomomento/sdk-core/dist/src/internal/utils'; +import {store} from '@gomomento/generated-types/dist/store'; +import {IdleGrpcClientWrapper} from './grpc/idle-grpc-client-wrapper'; +import {GrpcClientWrapper} from './grpc/grpc-client-wrapper'; +import {Header, HeaderInterceptorProvider} from './grpc/headers-interceptor'; +import {ClientTimeoutInterceptor} from './grpc/client-timeout-interceptor'; +import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; +import { + ChannelCredentials, + Interceptor, + Metadata, + ServiceError, +} from '@grpc/grpc-js'; +import {version} from '../../package.json'; +import {middlewaresInterceptor} from './grpc/middlewares-interceptor'; +import { + Middleware, + MiddlewareRequestHandlerContext, +} from '../config/middleware/middleware'; +import {grpcChannelOptionsFromGrpcConfig} from './grpc/grpc-channel-options'; +import {IStorageDataClient} from '@gomomento/sdk-core/dist/src/internal/clients'; +import {StorageConfiguration} from '../config/storage-configuration'; +import {StorageClientPropsWithConfig} from './storage-client-props-with-config'; +import {StaticGrpcConfiguration} from '../config/transport/cache'; + +export const CONNECTION_ID_KEY = Symbol('connectionID'); + +export class StorageDataClient implements IStorageDataClient { + private readonly configuration: StorageConfiguration; + private readonly credentialProvider: CredentialProvider; + private readonly logger: MomentoLogger; + private readonly cacheServiceErrorMapper: CacheServiceErrorMapper; + private readonly requestTimeoutMs: number; + private readonly clientWrapper: GrpcClientWrapper; + private readonly interceptors: Interceptor[]; + private static readonly DEFAULT_MAX_SESSION_MEMORY_MB: number = 256; + + /** + * @param {StorageClientPropsWithConfig} props + * @param dataClientID + */ + constructor(props: StorageClientPropsWithConfig, dataClientID: string) { + this.configuration = props.configuration; + this.cacheServiceErrorMapper = new CacheServiceErrorMapper(false); + this.credentialProvider = props.credentialProvider; + this.logger = this.configuration.getLoggerFactory().getLogger(this); + this.requestTimeoutMs = this.configuration + .getTransportStrategy() + .getGrpcConfig() + .getDeadlineMillis(); + this.validateRequestTimeout(this.requestTimeoutMs); + this.logger.debug( + `Creating leaderboard client using endpoint: '${this.credentialProvider.getStorageEndpoint()}'` + ); + + // NOTE: This is hard-coded for now but we may want to expose it via StorageConfiguration in the + // future, as we do with some of the other clients. + const grpcConfig = new StaticGrpcConfiguration({ + deadlineMillis: this.configuration + .getTransportStrategy() + .getGrpcConfig() + .getDeadlineMillis(), + maxSessionMemoryMb: StorageDataClient.DEFAULT_MAX_SESSION_MEMORY_MB, + }); + const channelOptions = grpcChannelOptionsFromGrpcConfig(grpcConfig); + + this.clientWrapper = new IdleGrpcClientWrapper({ + clientFactoryFn: () => + new store.StoreClient( + this.credentialProvider.getStorageEndpoint(), + this.credentialProvider.isStorageEndpointSecure() + ? ChannelCredentials.createSsl() + : ChannelCredentials.createInsecure(), + channelOptions + ), + loggerFactory: this.configuration.getLoggerFactory(), + maxIdleMillis: this.configuration + .getTransportStrategy() + .getMaxIdleMillis(), + }); + + const context: MiddlewareRequestHandlerContext = {}; + context[CONNECTION_ID_KEY] = dataClientID; + this.interceptors = this.initializeInterceptors( + this.configuration.getLoggerFactory(), + this.configuration.getMiddlewares(), + context + ); + } + + close() { + this.logger.debug('Closing storage data clients'); + this.clientWrapper.getClient().close(); + } + + private validateRequestTimeout(timeout?: number) { + this.logger.debug(`Request timeout ms: ${String(timeout)}`); + if (timeout !== undefined && timeout <= 0) { + throw new InvalidArgumentError( + 'request timeout must be greater than zero.' + ); + } + } + + private initializeInterceptors( + _loggerFactory: MomentoLoggerFactory, + middlewares: Middleware[], + middlewareRequestContext: MiddlewareRequestHandlerContext + ): Interceptor[] { + const headers = [ + new Header('Authorization', this.credentialProvider.getAuthToken()), + new Header('Agent', `nodejs:${version}`), + ]; + return [ + middlewaresInterceptor( + _loggerFactory, + middlewares, + middlewareRequestContext + ), + new HeaderInterceptorProvider(headers).createHeadersInterceptor(), + ClientTimeoutInterceptor(this.requestTimeoutMs), + ]; + } + + private createMetadata(storeName: string): Metadata { + const metadata = new Metadata(); + metadata.set('storage', storeName); + return metadata; + } + + public async get(storeName: string, key: string): Promise { + try { + validateStoreName(storeName); + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StoreGet.Error(err) + ); + } + this.logger.trace( + `Issuing 'get' request; store: ${storeName}, key: ${key}` + ); + return await this.sendGet(storeName, key); + } + + private async sendGet( + storeName: string, + key: string + ): Promise { + const request = new store._StoreGetRequest({ + key: key, + }); + const metadata = this.createMetadata(storeName); + return await new Promise((resolve, reject) => { + this.clientWrapper.getClient().Get( + request, + metadata, + { + interceptors: this.interceptors, + }, + (err: ServiceError | null, resp) => { + if (resp && resp.value.value !== 'none') { + switch (resp.value.value) { + case 'double_value': { + return resolve( + new StoreGet.DoubleResponse(resp.value.double_value) + ); + } + case 'string_value': { + return resolve( + new StoreGet.StringResponse(resp.value.string_value) + ); + } + case 'bytes_value': { + return resolve( + new StoreGet.BytesResponse(resp.value.bytes_value) + ); + } + case 'integer_value': { + return resolve( + new StoreGet.IntegerResponse(resp.value.integer_value) + ); + } + } + } else { + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new StoreGet.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); + } + } + ); + }); + } + + public async set( + storeName: string, + key: string, + value: string | Uint8Array | number + ): Promise { + try { + validateStoreName(storeName); + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StoreSet.Error(err) + ); + } + this.logger.trace( + `Issuing 'get' request; store: ${storeName}, key: ${key}` + ); + return await this.sendSet(storeName, key, value); + } + + private async sendSet( + storeName: string, + key: string, + value: string | Uint8Array | number + ): Promise { + const storeValue = new store._StoreValue(); + if (typeof value === 'string') { + storeValue.string_value = value; + } else if (typeof value === 'number') { + if (Number.isInteger(value)) { + storeValue.integer_value = value; + } else { + storeValue.double_value = value; + } + } else { + storeValue.bytes_value = value; + } + const request = new store._StoreSetRequest({ + key: key, + value: storeValue, + }); + const metadata = this.createMetadata(storeName); + return await new Promise((resolve, reject) => { + this.clientWrapper.getClient().Set( + request, + metadata, + { + interceptors: this.interceptors, + }, + (err: ServiceError | null, resp) => { + if (resp) { + resolve(new StoreSet.Success()); + } else { + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new StoreSet.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); + } + } + ); + }); + } + + public async delete( + storeName: string, + key: string + ): Promise { + try { + validateStoreName(storeName); + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StoreDelete.Error(err) + ); + } + this.logger.trace( + `Issuing 'delete' request; store: ${storeName}, key: ${key}` + ); + return await this.sendDelete(storeName, key); + } + + private async sendDelete( + storeName: string, + key: string + ): Promise { + const request = new store._StoreDeleteRequest({ + key: key, + }); + const metadata = this.createMetadata(storeName); + return await new Promise((resolve, reject) => { + this.clientWrapper.getClient().Delete( + request, + metadata, + { + interceptors: this.interceptors, + }, + (err: ServiceError | null, resp) => { + if (resp) { + resolve(new StoreDelete.Success()); + } else { + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new StoreDelete.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); + } + } + ); + }); + } +} diff --git a/packages/client-sdk-nodejs/src/storage-client-props.ts b/packages/client-sdk-nodejs/src/storage-client-props.ts new file mode 100644 index 000000000..fb4753c96 --- /dev/null +++ b/packages/client-sdk-nodejs/src/storage-client-props.ts @@ -0,0 +1,7 @@ +import {CredentialProvider} from '@gomomento/sdk-core'; +import {StorageConfiguration} from './config/storage-configuration'; + +export interface StorageClientProps { + credentialProvider: CredentialProvider; + configuration?: StorageConfiguration; +} diff --git a/packages/client-sdk-nodejs/src/storage-client.ts b/packages/client-sdk-nodejs/src/storage-client.ts new file mode 100644 index 000000000..9a83a7a56 --- /dev/null +++ b/packages/client-sdk-nodejs/src/storage-client.ts @@ -0,0 +1,63 @@ +import { + AbstractStorageClient, + IStorageControlClient, + IStorageDataClient, +} from '@gomomento/sdk-core/dist/src/internal/clients'; +import {IStorageClient} from '@gomomento/sdk-core/dist/src/clients/IStorageClient'; +import {StorageClientProps} from './storage-client-props'; +import {StorageClientPropsWithConfig} from './internal/storage-client-props-with-config'; +import {StorageControlClient} from './internal/storage-control-client'; +import {StorageDataClient} from './internal/storage-data-client'; +import {StorageConfiguration} from './config/storage-configuration'; +import {StorageConfigurations} from './index'; + +export class StorageClient + extends AbstractStorageClient + implements IStorageClient +{ + constructor(props: StorageClientProps) { + const configuration = + props.configuration ?? getDefaultStorageConfiguration(); + const propsWithConfiguration: StorageClientPropsWithConfig = { + ...props, + configuration, + }; + + const controlClient: IStorageControlClient = createControlClient( + propsWithConfiguration + ); + const dataClients = createDataClients(propsWithConfiguration); + super(dataClients, controlClient); + } + + close(): void { + this.dataClients.forEach(client => client.close()); + this.controlClient.close(); + } +} + +function createControlClient( + props: StorageClientPropsWithConfig +): IStorageControlClient { + return new StorageControlClient({ + configuration: props.configuration, + credentialProvider: props.credentialProvider, + }); +} + +function createDataClients( + props: StorageClientPropsWithConfig +): IStorageDataClient[] { + const numClients = props.configuration + .getTransportStrategy() + .getGrpcConfig() + .getNumClients(); + return Array.from( + {length: numClients}, + (_, i) => new StorageDataClient(props, i.toString()) + ); +} + +function getDefaultStorageConfiguration(): StorageConfiguration { + return StorageConfigurations.Laptop.latest(); +} diff --git a/packages/client-sdk-nodejs/test/integration/integration-setup.ts b/packages/client-sdk-nodejs/test/integration/integration-setup.ts index a3eeb8150..2721b255e 100644 --- a/packages/client-sdk-nodejs/test/integration/integration-setup.ts +++ b/packages/client-sdk-nodejs/test/integration/integration-setup.ts @@ -74,6 +74,10 @@ function sessionCredsProvider(): CredentialProvider { endpoint: credsProvider().getTokenEndpoint(), secureConnection: credsProvider().isTokenEndpointSecure(), }, + storageEndpoint: { + endpoint: credsProvider().getStorageEndpoint(), + secureConnection: credsProvider().isStorageEndpointSecure(), + }, }, }); } diff --git a/packages/client-sdk-web/package-lock.json b/packages/client-sdk-web/package-lock.json index 25807588e..f975e299a 100644 --- a/packages/client-sdk-web/package-lock.json +++ b/packages/client-sdk-web/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.1", "license": "Apache-2.0", "dependencies": { - "@gomomento/generated-types-webtext": "0.107.4", + "@gomomento/generated-types-webtext": "file:../../../client-protos/javascript-web", "@gomomento/sdk-core": "file:../core", "@types/google-protobuf": "3.15.6", "google-protobuf": "3.21.2", @@ -44,6 +44,21 @@ "node": ">= 16" } }, + "../../../client-protos/javascript-web": { + "version": "0.0.1", + "license": "Apache-2.0", + "dependencies": { + "google-protobuf": "3.21.2", + "grpc-web": "1.4.2" + }, + "devDependencies": { + "@tsconfig/node16": "1.0.2", + "@types/google-protobuf": "^3.15.6", + "@types/node": "16.10.3", + "google-protobuf": "3.21.2", + "typescript": "^4.9.5" + } + }, "../common-integration-tests": { "name": "@gomomento/common-integration-tests", "version": "0.0.1", @@ -813,13 +828,8 @@ "link": true }, "node_modules/@gomomento/generated-types-webtext": { - "version": "0.107.4", - "resolved": "https://registry.npmjs.org/@gomomento/generated-types-webtext/-/generated-types-webtext-0.107.4.tgz", - "integrity": "sha512-roY251w2SnlcZtDZEJdcHe91RcI04gdPdP5gk0mDMjTcW8Q2ZIRxVvbNXVMzunTgokhSdFXm/ivF5iskc71AVw==", - "dependencies": { - "google-protobuf": "3.21.2", - "grpc-web": "1.4.2" - } + "resolved": "../../../client-protos/javascript-web", + "link": true }, "node_modules/@gomomento/sdk-core": { "resolved": "../core", diff --git a/packages/client-sdk-web/package.json b/packages/client-sdk-web/package.json index 5f431ab4c..0d57c8f66 100644 --- a/packages/client-sdk-web/package.json +++ b/packages/client-sdk-web/package.json @@ -55,7 +55,7 @@ "xhr2": "0.2.1" }, "dependencies": { - "@gomomento/generated-types-webtext": "0.107.4", + "@gomomento/generated-types-webtext": "file:../../../client-protos/javascript-web", "@gomomento/sdk-core": "file:../core", "@types/google-protobuf": "3.15.6", "google-protobuf": "3.21.2", diff --git a/packages/client-sdk-web/src/config/storage-configuration.ts b/packages/client-sdk-web/src/config/storage-configuration.ts new file mode 100644 index 000000000..11d92afa7 --- /dev/null +++ b/packages/client-sdk-web/src/config/storage-configuration.ts @@ -0,0 +1,42 @@ +import {MomentoLoggerFactory} from '@gomomento/sdk-core'; + +export interface StorageConfigurationProps { + /** + * Configures logging verbosity and format + */ + loggerFactory: MomentoLoggerFactory; +} + +/** + * Configuration options for Momento StorageClient + * + * @export + * @interface StorageConfiguration + */ +export interface StorageConfiguration { + /** + * @returns {MomentoLoggerFactory} the current configuration options for logging verbosity and format + */ + getLoggerFactory(): MomentoLoggerFactory; + + /** + * @returns {boolean} Configures whether the client should return a Momento Error object or throw an exception when an error occurs. By default, this is set to false, and the client will return a Momento Error object on errors. Set it to true if you prefer for exceptions to be thrown. + */ + getThrowOnErrors(): boolean; +} + +export class StorageClientConfiguration implements StorageConfiguration { + private readonly loggerFactory: MomentoLoggerFactory; + + constructor(props: StorageConfigurationProps) { + this.loggerFactory = props.loggerFactory; + } + + getLoggerFactory(): MomentoLoggerFactory { + return this.loggerFactory; + } + + getThrowOnErrors(): boolean { + return false; + } +} diff --git a/packages/client-sdk-web/src/config/storage-configurations.ts b/packages/client-sdk-web/src/config/storage-configurations.ts new file mode 100644 index 000000000..b460aa3c8 --- /dev/null +++ b/packages/client-sdk-web/src/config/storage-configurations.ts @@ -0,0 +1,30 @@ +import {MomentoLoggerFactory} from '@gomomento/sdk-core'; +import {DefaultMomentoLoggerFactory} from './logging/default-momento-logger'; +import { + StorageClientConfiguration, + StorageConfiguration, +} from './storage-configuration'; + +const defaultLoggerFactory: MomentoLoggerFactory = + new DefaultMomentoLoggerFactory(); + +/** + * Default config provides defaults suitable for most environments; prioritizes success of publishing and receiving messages. + * @export + * @class Default + */ +export class Default extends StorageClientConfiguration { + /** + * Provides the latest recommended configuration for a default environment. NOTE: this configuration may + * change in future releases to take advantage of improvements we identify for default configurations. + * @param {MomentoLoggerFactory} [loggerFactory=defaultLoggerFactory] + * @returns {StorageConfiguration} + */ + static latest( + loggerFactory: MomentoLoggerFactory = defaultLoggerFactory + ): StorageConfiguration { + return new StorageClientConfiguration({ + loggerFactory: loggerFactory, + }); + } +} diff --git a/packages/client-sdk-web/src/index.ts b/packages/client-sdk-web/src/index.ts index 9dc401a83..a63c10908 100644 --- a/packages/client-sdk-web/src/index.ts +++ b/packages/client-sdk-web/src/index.ts @@ -5,6 +5,7 @@ import {PreviewLeaderboardClient} from './preview-leaderboard-client'; import * as Configurations from './config/configurations'; import * as TopicConfigurations from './config/topic-configurations'; import * as LeaderboardConfigurations from './config/leaderboard-configurations'; +import * as StorageConfigurations from './config/storage-configurations'; // Cache Client Response Types import * as CacheGet from '@gomomento/sdk-core/dist/src/messages/responses/cache-get'; @@ -145,6 +146,7 @@ import { RotateWebhookSecret, WebhookDestinationType, ReadConcern, + StoreInfo, } from '@gomomento/sdk-core'; import {Configuration} from './config/configuration'; @@ -159,6 +161,8 @@ import { LeaderboardConfiguration, } from './config/leaderboard-configuration'; +export * from '@gomomento/sdk-core/dist/src/messages/responses/storage'; + export { DefaultMomentoLoggerFactory, DefaultMomentoLogger, @@ -323,4 +327,7 @@ export { RotateWebhookSecret, WebhookDestinationType, ReadConcern, + // Storage + StoreInfo, + StorageConfigurations, }; diff --git a/packages/client-sdk-web/src/internal/storage-control-client.ts b/packages/client-sdk-web/src/internal/storage-control-client.ts new file mode 100644 index 000000000..9179eb2fe --- /dev/null +++ b/packages/client-sdk-web/src/internal/storage-control-client.ts @@ -0,0 +1,167 @@ +import {control} from '@gomomento/generated-types-webtext'; +import { + CredentialProvider, + MomentoLogger, + CreateStore, + DeleteStore, + ListStores, + StoreInfo, +} from '..'; +import {Request, StatusCode, UnaryResponse} from 'grpc-web'; +import { + _CreateStoreRequest, + _DeleteStoreRequest, + _ListStoresRequest, +} from '@gomomento/generated-types-webtext/dist/controlclient_pb'; +import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; +import {IStorageControlClient} from '@gomomento/sdk-core/dist/src/internal/clients'; +import {validateStoreName} from '@gomomento/sdk-core/dist/src/internal/utils'; +import {getWebControlEndpoint} from '../utils/web-client-utils'; +import {ClientMetadataProvider} from './client-metadata-provider'; +import {StorageConfiguration} from '../config/storage-configuration'; + +export interface StorageClientClientProps { + configuration: StorageConfiguration; + credentialProvider: CredentialProvider; +} + +export class StorageControlClient< + REQ extends Request, + RESP extends UnaryResponse +> implements IStorageControlClient +{ + private readonly clientWrapper: control.ScsControlClient; + private readonly logger: MomentoLogger; + private readonly cacheServiceErrorMapper: CacheServiceErrorMapper; + + private readonly clientMetadataProvider: ClientMetadataProvider; + + /** + * @param {ControlClientProps} props + */ + constructor(props: StorageClientClientProps) { + this.logger = props.configuration.getLoggerFactory().getLogger(this); + this.cacheServiceErrorMapper = new CacheServiceErrorMapper( + props.configuration.getThrowOnErrors() + ); + this.logger.debug( + `Creating storage control client using endpoint: '${getWebControlEndpoint( + props.credentialProvider + )}` + ); + + this.clientMetadataProvider = new ClientMetadataProvider({ + authToken: props.credentialProvider.getAuthToken(), + }); + this.clientWrapper = new control.ScsControlClient( + // Note: all web SDK requests are routed to a `web.` subdomain to allow us flexibility on the server + getWebControlEndpoint(props.credentialProvider), + null, + {} + ); + } + + close() { + this.logger.debug('Closing cache control client'); + // do nothing as gRPC web version doesn't expose a close() yet. + // this is needed as we have added close to `IControlClient` extended + // by both nodejs and web SDKs + } + + public async createStore(name: string): Promise { + try { + validateStoreName(name); + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new CreateStore.Error(err) + ); + } + this.logger.debug(`Creating store: ${name}`); + const request = new _CreateStoreRequest(); + request.setStoreName(name); + + return await new Promise((resolve, reject) => { + this.clientWrapper.createStore( + request, + this.clientMetadataProvider.createClientMetadata(), + (err, _resp) => { + if (err) { + if (err.code === StatusCode.ALREADY_EXISTS) { + resolve(new CreateStore.AlreadyExists()); + } else { + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new CreateStore.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); + } + } else { + resolve(new CreateStore.Success()); + } + } + ); + }); + } + + public async deleteStore(name: string): Promise { + try { + validateStoreName(name); + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new DeleteStore.Error(err) + ); + } + const request = new _DeleteStoreRequest(); + request.setStoreName(name); + this.logger.debug(`Deleting store: ${name}`); + return await new Promise((resolve, reject) => { + this.clientWrapper.deleteStore( + request, + this.clientMetadataProvider.createClientMetadata(), + (err, _resp) => { + if (err) { + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new DeleteStore.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); + } else { + resolve(new DeleteStore.Success()); + } + } + ); + }); + } + + public async listStores(): Promise { + const request = new _ListStoresRequest(); + request.setNextToken(''); + this.logger.debug("Issuing 'listStores' request"); + return await new Promise((resolve, reject) => { + this.clientWrapper.listStores( + request, + this.clientMetadataProvider.createClientMetadata(), + (err, resp) => { + if (err) { + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new ListStores.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); + } else { + const stores = resp.getStoreList().map(store => { + const storeName = store.getStoreName(); + return new StoreInfo(storeName); + }); + resolve(new ListStores.Success(stores)); + } + } + ); + }); + } +} diff --git a/packages/client-sdk-web/src/internal/storage-data-client.ts b/packages/client-sdk-web/src/internal/storage-data-client.ts new file mode 100644 index 000000000..255e2913b --- /dev/null +++ b/packages/client-sdk-web/src/internal/storage-data-client.ts @@ -0,0 +1,267 @@ +import {store} from '@gomomento/generated-types-webtext'; +import { + StoreGet, + StoreSet, + StoreDelete, + CredentialProvider, + MomentoLogger, + UnknownError, +} from '..'; +import {Request, UnaryResponse} from 'grpc-web'; +import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; +import { + _StoreDeleteRequest, + _StoreGetRequest, + _StoreSetRequest, + _StoreValue, +} from '@gomomento/generated-types-webtext/dist/store_pb'; +import {IStorageDataClient} from '@gomomento/sdk-core/dist/src/internal/clients'; +import {validateStoreName} from '@gomomento/sdk-core/dist/src/internal/utils'; +import { + convertToB64String, + createStorageMetadata, + getWebStorageEndpoint, +} from '../utils/web-client-utils'; +import {ClientMetadataProvider} from './client-metadata-provider'; +import ValueCase = _StoreValue.ValueCase; +import {StorageConfiguration} from '../config/storage-configuration'; + +export interface StorageDataClientProps { + configuration: StorageConfiguration; + credentialProvider: CredentialProvider; +} + +export class StorageDataClient< + REQ extends Request, + RESP extends UnaryResponse +> implements IStorageDataClient +{ + private readonly clientWrapper: store.StoreClient; + private readonly logger: MomentoLogger; + private readonly cacheServiceErrorMapper: CacheServiceErrorMapper; + private readonly clientMetadataProvider: ClientMetadataProvider; + // TODO make this part of configuration + private readonly deadlineMillis: number = 10000; + + /** + * @param {DataClientProps} props + */ + constructor(props: StorageDataClientProps) { + this.logger = props.configuration.getLoggerFactory().getLogger(this); + this.cacheServiceErrorMapper = new CacheServiceErrorMapper( + props.configuration.getThrowOnErrors() + ); + this.logger.debug( + `Creating storage data client using endpoint: '${getWebStorageEndpoint( + props.credentialProvider + )}` + ); + + this.clientMetadataProvider = new ClientMetadataProvider({ + authToken: props.credentialProvider.getAuthToken(), + }); + this.clientWrapper = new store.StoreClient( + // Note: all web SDK requests are routed to a `web.` subdomain to allow us flexibility on the server + getWebStorageEndpoint(props.credentialProvider), + null + ); + } + + close() { + this.logger.debug('Closing cache control client'); + // do nothing as gRPC web version doesn't expose a close() yet. + // this is needed as we have added close to `IControlClient` extended + // by both nodejs and web SDKs + } + + public async get(storeName: string, key: string): Promise { + try { + validateStoreName(storeName); + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StoreGet.Error(err) + ); + } + this.logger.trace(`Issuing 'get' request; key: ${key.toString()}`); + const result = await this.sendGet(storeName, convertToB64String(key)); + this.logger.trace(`'get' request result: ${result.toString()}`); + return result; + } + + private async sendGet( + storeName: string, + key: string + ): Promise { + const request = new _StoreGetRequest(); + request.setKey(key); + + return await new Promise((resolve, reject) => { + this.clientWrapper.get( + request, + { + ...this.clientMetadataProvider.createClientMetadata(), + ...createStorageMetadata(storeName, this.deadlineMillis), + }, + (err, resp) => { + const value = resp?.getValue(); + if (resp && value) { + switch (value.getValueCase()) { + case ValueCase.VALUE_NOT_SET: { + return resolve( + new StoreGet.Error( + new UnknownError( + 'An unknown error occurred: ' + resp.toString() + ) + ) + ); + } + case ValueCase.BYTES_VALUE: { + return resolve( + new StoreGet.BytesResponse(value.getBytesValue_asU8()) + ); + } + case ValueCase.STRING_VALUE: { + return resolve( + new StoreGet.StringResponse(value.getStringValue()) + ); + } + case ValueCase.INTEGER_VALUE: { + return resolve( + new StoreGet.IntegerResponse(value.getIntegerValue()) + ); + } + case ValueCase.DOUBLE_VALUE: { + return resolve( + new StoreGet.DoubleResponse(value.getDoubleValue()) + ); + } + } + } else { + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new StoreGet.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); + } + } + ); + }); + } + + public async set( + storeName: string, + key: string, + value: string | number | Uint8Array + ): Promise { + try { + validateStoreName(storeName); + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StoreSet.Error(err) + ); + } + this.logger.trace(`Issuing 'set' request; key: ${key.toString()}`); + const result = await this.sendSet( + storeName, + convertToB64String(key), + value + ); + this.logger.trace(`'set' request result: ${result.toString()}`); + return result; + } + + private async sendSet( + storeName: string, + key: string, + passedInVal: string | number | Uint8Array + ): Promise { + const request = new _StoreSetRequest(); + request.setKey(key); + + const value = new _StoreValue(); + if (typeof passedInVal === 'string') { + value.setStringValue(passedInVal); + } else if (typeof passedInVal === 'number') { + if (Number.isInteger(passedInVal)) { + value.setIntegerValue(passedInVal); + } else { + value.setDoubleValue(passedInVal); + } + } else { + value.setBytesValue(passedInVal); + } + + return await new Promise((resolve, reject) => { + this.clientWrapper.set( + request, + { + ...this.clientMetadataProvider.createClientMetadata(), + ...createStorageMetadata(storeName, this.deadlineMillis), + }, + (err, resp) => { + if (err) { + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new StoreSet.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); + } else { + resolve(new StoreSet.Success()); + } + } + ); + }); + } + + public async delete( + storeName: string, + key: string + ): Promise { + try { + validateStoreName(storeName); + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StoreDelete.Error(err) + ); + } + this.logger.trace(`Issuing 'delete' request; key: ${key.toString()}`); + const result = await this.sendDelete(storeName, convertToB64String(key)); + this.logger.trace(`'delete' request result: ${result.toString()}`); + return result; + } + + private async sendDelete( + storeName: string, + key: string + ): Promise { + const request = new _StoreDeleteRequest(); + request.setKey(key); + + return await new Promise((resolve, reject) => { + this.clientWrapper.delete( + request, + { + ...this.clientMetadataProvider.createClientMetadata(), + ...createStorageMetadata(storeName, this.deadlineMillis), + }, + (err, resp) => { + if (err) { + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new StoreDelete.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); + } else { + resolve(new StoreDelete.Success()); + } + } + ); + }); + } +} diff --git a/packages/client-sdk-web/src/storage-client-props.ts b/packages/client-sdk-web/src/storage-client-props.ts new file mode 100644 index 000000000..478967891 --- /dev/null +++ b/packages/client-sdk-web/src/storage-client-props.ts @@ -0,0 +1,13 @@ +import {CredentialProvider} from '.'; +import {StorageConfiguration} from './config/storage-configuration'; + +export interface StorageClientProps { + /** + * Configuration settings for the storage client + */ + configuration?: StorageConfiguration; + /** + * controls how the client will get authentication information for connecting to the Momento service + */ + credentialProvider: CredentialProvider; +} diff --git a/packages/client-sdk-web/src/storage-client.ts b/packages/client-sdk-web/src/storage-client.ts new file mode 100644 index 000000000..bc33fa9e4 --- /dev/null +++ b/packages/client-sdk-web/src/storage-client.ts @@ -0,0 +1,81 @@ +import { + AbstractStorageClient, + IStorageControlClient, + IStorageDataClient, +} from '@gomomento/sdk-core/dist/src/internal/clients'; +import {StorageConfigurations} from './index'; +import {IStorageClient} from '@gomomento/sdk-core'; +import {StorageConfiguration} from './config/storage-configuration'; +import {StorageDataClient} from './internal/storage-data-client'; +import {StorageClientProps} from './storage-client-props'; +import {StorageControlClient} from './internal/storage-control-client'; + +interface StorageClientPropsWithConfiguration extends StorageClientProps { + configuration: StorageConfiguration; +} + +export class StorageClient + extends AbstractStorageClient + implements IStorageClient +{ + private readonly _configuration: StorageConfiguration; + + constructor(props: StorageClientProps) { + const configuration = + props.configuration ?? getDefaultStorageClientConfiguration(); + const propsWithConfiguration: StorageClientPropsWithConfiguration = { + ...props, + configuration, + }; + const controlClient: IStorageControlClient = createControlClient( + propsWithConfiguration + ); + const dataClient: IStorageDataClient = createDataClient( + propsWithConfiguration + ); + super([dataClient], controlClient); + } + + public close() { + this.controlClient.close(); + this.dataClients.forEach(client => client.close()); + } + + /** + * The configuration used by this client. + * + * @readonly + * @type {StorageConfiguration} the configuration used by this client + * @memberof StorageClient + */ + public get configuration(): StorageConfiguration { + return this._configuration; + } +} + +function createControlClient( + props: StorageClientPropsWithConfiguration +): IStorageControlClient { + return new StorageControlClient({ + configuration: props.configuration, + credentialProvider: props.credentialProvider, + }); +} + +function createDataClient( + props: StorageClientPropsWithConfiguration +): IStorageDataClient { + return new StorageDataClient({ + configuration: props.configuration, + credentialProvider: props.credentialProvider, + }); +} + +function getDefaultStorageClientConfiguration(): StorageConfiguration { + const config = StorageConfigurations.Default.latest(); + const logger = config.getLoggerFactory().getLogger('StorageClient'); + logger.info( + 'No configuration provided to StorageClient. Using default configuration. For production use, consider specifying an explicit configuration.' + ); + return config; +} diff --git a/packages/client-sdk-web/src/utils/web-client-utils.ts b/packages/client-sdk-web/src/utils/web-client-utils.ts index 821b8d17c..0ea3a570d 100644 --- a/packages/client-sdk-web/src/utils/web-client-utils.ts +++ b/packages/client-sdk-web/src/utils/web-client-utils.ts @@ -36,6 +36,14 @@ export function createCallMetadata( return {cache: cacheName, deadline: deadline.toString()}; } +export function createStorageMetadata( + storeName: string, + timeoutMillis: number +): {storage: string; deadline: string} { + const deadline = Date.now() + timeoutMillis; + return {storage: storeName, deadline: deadline.toString()}; +} + export function getWebControlEndpoint( credentialProvider: CredentialProvider ): string { @@ -54,6 +62,15 @@ export function getWebCacheEndpoint( return withProtocolPrefix(`web.${credentialProvider.getCacheEndpoint()}`); } +export function getWebStorageEndpoint( + credentialProvider: CredentialProvider +): string { + if (credentialProvider.areEndpointsOverridden()) { + return withProtocolPrefix(credentialProvider.getStorageEndpoint()); + } + return withProtocolPrefix(`web.${credentialProvider.getStorageEndpoint()}`); +} + export function getWebTokenEndpoint( credentialProvider: CredentialProvider ): string { diff --git a/packages/client-sdk-web/test/integration/integration-setup.ts b/packages/client-sdk-web/test/integration/integration-setup.ts index 48e51d046..f7dda58e1 100644 --- a/packages/client-sdk-web/test/integration/integration-setup.ts +++ b/packages/client-sdk-web/test/integration/integration-setup.ts @@ -41,6 +41,9 @@ export function credsProvider(): CredentialProvider { tokenEndpoint: { endpoint: 'https://localhost:9001', }, + storageEndpoint: { + endpoint: 'https://localhost:9001', + }, }, }); } else { @@ -71,6 +74,10 @@ function sessionCredsProvider(): CredentialProvider { endpoint: credsProvider().getTokenEndpoint(), secureConnection: credsProvider().isTokenEndpointSecure(), }, + storageEndpoint: { + endpoint: credsProvider().getStorageEndpoint(), + secureConnection: credsProvider().isStorageEndpointSecure(), + }, }, }); } diff --git a/packages/client-sdk-web/test/unit/utils/web-client-utils.test.ts b/packages/client-sdk-web/test/unit/utils/web-client-utils.test.ts index 45427a472..1a774f3f1 100644 --- a/packages/client-sdk-web/test/unit/utils/web-client-utils.test.ts +++ b/packages/client-sdk-web/test/unit/utils/web-client-utils.test.ts @@ -9,6 +9,7 @@ import { convertToStringFromB64String, getWebCacheEndpoint, getWebControlEndpoint, + getWebStorageEndpoint, getWebTokenEndpoint, } from '../../../src/utils/web-client-utils'; @@ -62,6 +63,9 @@ describe('getWeb*Endpoint', () => { tokenEndpoint: { endpoint: 'some-token-endpoint', }, + storageEndpoint: { + endpoint: 'some-storage-endpoint', + }, }, }); const webControlEndpoint = getWebControlEndpoint(credProvider); @@ -70,6 +74,8 @@ describe('getWeb*Endpoint', () => { expect(webCacheEndpoint).toEqual('https://some-cache-endpoint'); const webTokenEndpoint = getWebTokenEndpoint(credProvider); expect(webTokenEndpoint).toEqual('https://some-token-endpoint'); + const storageEndpoint = getWebStorageEndpoint(credProvider); + expect(storageEndpoint).toEqual('https://some-storage-endpoint'); }); it('works with overridden endpoints that already have the protocol', () => { const credProvider = CredentialProvider.fromString({ @@ -84,6 +90,9 @@ describe('getWeb*Endpoint', () => { tokenEndpoint: { endpoint: 'http://some-token-endpoint', }, + storageEndpoint: { + endpoint: 'http://some-storage-endpoint', + }, }, }); const webControlEndpoint = getWebControlEndpoint(credProvider); @@ -92,6 +101,8 @@ describe('getWeb*Endpoint', () => { expect(webCacheEndpoint).toEqual('https://some-cache-endpoint'); const webTokenEndpoint = getWebTokenEndpoint(credProvider); expect(webTokenEndpoint).toEqual('http://some-token-endpoint'); + const storageEndpoint = getWebStorageEndpoint(credProvider); + expect(storageEndpoint).toEqual('http://some-storage-endpoint'); }); describe('leaves port intact for overridden endpoints', () => { it("with overrides that don't contain protocol", () => { @@ -107,6 +118,9 @@ describe('getWeb*Endpoint', () => { tokenEndpoint: { endpoint: 'some-token-endpoint:9001', }, + storageEndpoint: { + endpoint: 'some-storage-endpoint:9001', + }, }, }); const webControlEndpoint = getWebControlEndpoint(credProvider); @@ -115,6 +129,8 @@ describe('getWeb*Endpoint', () => { expect(webCacheEndpoint).toEqual('https://some-cache-endpoint:9001'); const webTokenEndpoint = getWebTokenEndpoint(credProvider); expect(webTokenEndpoint).toEqual('https://some-token-endpoint:9001'); + const storageEndpoint = getWebStorageEndpoint(credProvider); + expect(storageEndpoint).toEqual('https://some-storage-endpoint:9001'); }); it('with overrides that do contain protocol', () => { const credProvider = CredentialProvider.fromString({ @@ -129,6 +145,9 @@ describe('getWeb*Endpoint', () => { tokenEndpoint: { endpoint: 'http://some-token-endpoint:9001', }, + storageEndpoint: { + endpoint: 'http://some-storage-endpoint:9001', + }, }, }); const webControlEndpoint = getWebControlEndpoint(credProvider); @@ -137,6 +156,8 @@ describe('getWeb*Endpoint', () => { expect(webCacheEndpoint).toEqual('https://some-cache-endpoint:9001'); const webTokenEndpoint = getWebTokenEndpoint(credProvider); expect(webTokenEndpoint).toEqual('http://some-token-endpoint:9001'); + const storageEndpoint = getWebStorageEndpoint(credProvider); + expect(storageEndpoint).toEqual('http://some-storage-endpoint:9001'); }); }); diff --git a/packages/core/src/auth/credential-provider.ts b/packages/core/src/auth/credential-provider.ts index 6b1d5c43c..806c6089d 100644 --- a/packages/core/src/auth/credential-provider.ts +++ b/packages/core/src/auth/credential-provider.ts @@ -69,6 +69,16 @@ export abstract class CredentialProvider { */ abstract isCacheEndpointSecure(): boolean; + /** + * @returns {string} The host which the Momento client will connect to for Momento storage operations + */ + abstract getStorageEndpoint(): string; + + /** + * @returns {boolean} true if connecting to the storage endpoint connection without TLS; false if using TLS + */ + abstract isStorageEndpointSecure(): boolean; + /** * @returns {string} The host which the Momento client will connect to for Momento token operations */ @@ -120,6 +130,10 @@ abstract class CredentialProviderBase implements CredentialProvider { abstract isControlEndpointSecure(): boolean; + abstract getStorageEndpoint(): string; + + abstract isStorageEndpointSecure(): boolean; + abstract getTokenEndpoint(): string; abstract isTokenEndpointSecure(): boolean; @@ -201,6 +215,11 @@ export class StringMomentoTokenProvider extends CredentialProviderBase { 'Malformed token; unable to determine token endpoint. Depending on the type of token you are using, you may need to specify the tokenEndpoint explicitly.' ); } + if (decodedToken.storageEndpoint === undefined) { + throw new Error( + 'Malformed token; unable to determine storage endpoint. Depending on the type of token you are using, you may need to specify the storageEndpoint explicitly.' + ); + } this.allEndpoints = { controlEndpoint: { endpoint: decodedToken.controlEndpoint, @@ -211,6 +230,9 @@ export class StringMomentoTokenProvider extends CredentialProviderBase { tokenEndpoint: { endpoint: decodedToken.tokenEndpoint, }, + storageEndpoint: { + endpoint: decodedToken.storageEndpoint, + }, }; } else if (isAllEndpoints(props.endpointOverrides)) { this.endpointsOverridden = true; @@ -265,6 +287,17 @@ export class StringMomentoTokenProvider extends CredentialProviderBase { return this.allEndpoints.tokenEndpoint.secureConnection; } + getStorageEndpoint(): string { + return this.allEndpoints.storageEndpoint.endpoint; + } + + isStorageEndpointSecure(): boolean { + if (this.allEndpoints.storageEndpoint.secureConnection === undefined) { + return true; + } + return this.allEndpoints.storageEndpoint.secureConnection; + } + areEndpointsOverridden(): boolean { return this.endpointsOverridden; } @@ -280,6 +313,7 @@ export class StringMomentoTokenProvider extends CredentialProviderBase { cacheEndpoint: momentoLocalOverride, controlEndpoint: momentoLocalOverride, tokenEndpoint: momentoLocalOverride, + storageEndpoint: momentoLocalOverride, }, }); } diff --git a/packages/core/src/clients/IStorageClient.ts b/packages/core/src/clients/IStorageClient.ts new file mode 100644 index 000000000..cdd6979bc --- /dev/null +++ b/packages/core/src/clients/IStorageClient.ts @@ -0,0 +1,23 @@ +import { + CreateStore, + ListStores, + DeleteStore, + StoreSet, + StoreGet, + StoreDelete, +} from '../index'; + +export interface IStorageClient { + createStore(storeName: string): Promise; + listStores(): Promise; + deleteStore(cache: string): Promise; + get(storeName: string, key: string): Promise; + set( + storeName: string, + key: string, + value: string | Uint8Array | number + ): Promise; + delete(storeName: string, key: string): Promise; + + close(): void; +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 1fa6f769f..57a6310c3 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -79,6 +79,10 @@ export * as webhook from './messages/responses/webhook'; export * from './messages/responses/webhook'; export {Webhook, WebhookId} from './messages/webhook'; +// StoreClient Response Types +export * from './messages/responses/storage'; +export {StoreInfo} from './messages/store-info'; + import {CacheInfo} from './messages/cache-info'; import { SubscribeCallOptions, @@ -145,6 +149,8 @@ export { IncrementOptions, } from './clients/ICacheClient'; +export {IStorageClient} from './clients/IStorageClient'; + export {IMomentoCache} from './clients/IMomentoCache'; export {ILeaderboardClient} from './clients/ILeaderboardClient'; diff --git a/packages/core/src/internal/clients/index.ts b/packages/core/src/internal/clients/index.ts index 852117b86..05cd007d0 100644 --- a/packages/core/src/internal/clients/index.ts +++ b/packages/core/src/internal/clients/index.ts @@ -2,3 +2,4 @@ export * from './cache'; export * from './auth'; export * from './pubsub'; export * from './leaderboard'; +export * from './storage'; diff --git a/packages/core/src/internal/clients/storage/AbstractStorageClient.ts b/packages/core/src/internal/clients/storage/AbstractStorageClient.ts new file mode 100644 index 000000000..fd041d50e --- /dev/null +++ b/packages/core/src/internal/clients/storage/AbstractStorageClient.ts @@ -0,0 +1,67 @@ +import { + CreateStore, + DeleteStore, + ListStores, + StoreGet, + StoreSet, + StoreDelete, +} from '../../../index'; +import {IStorageDataClient} from './IStorageDataClient'; +import {IStorageClient} from '../../../clients/IStorageClient'; +import {IStorageControlClient} from './IStorageControlClient'; + +export abstract class AbstractStorageClient implements IStorageClient { + protected readonly dataClients: IStorageDataClient[]; + protected readonly controlClient: IStorageControlClient; + private nextDataClientIndex: number; + + protected constructor( + dataClients: IStorageDataClient[], + controlClient: IStorageControlClient + ) { + this.dataClients = dataClients; + this.controlClient = controlClient; + + // We round-robin the requests through all of our clients. Since javascript + // is single-threaded, we don't have to worry about thread safety on this + // index variable. + this.nextDataClientIndex = 0; + } + + createStore(storeName: string): Promise { + return this.controlClient.createStore(storeName); + } + + listStores(): Promise { + return this.controlClient.listStores(); + } + + deleteStore(storeName: string): Promise { + return this.controlClient.deleteStore(storeName); + } + + get(storeName: string, key: string): Promise { + return this.getNextDataClient().get(storeName, key); + } + + set( + storeName: string, + key: string, + value: string | Uint8Array | number + ): Promise { + return this.getNextDataClient().set(storeName, key, value); + } + + delete(storeName: string, key: string): Promise { + return this.getNextDataClient().delete(storeName, key); + } + + private getNextDataClient(): IStorageDataClient { + const client = this.dataClients[this.nextDataClientIndex]; + this.nextDataClientIndex = + (this.nextDataClientIndex + 1) % this.dataClients.length; + return client; + } + + abstract close(): void; +} diff --git a/packages/core/src/internal/clients/storage/IStorageControlClient.ts b/packages/core/src/internal/clients/storage/IStorageControlClient.ts new file mode 100644 index 000000000..0c16aca5d --- /dev/null +++ b/packages/core/src/internal/clients/storage/IStorageControlClient.ts @@ -0,0 +1,8 @@ +import {CreateStore, DeleteStore, ListStores} from '../../../index'; + +export interface IStorageControlClient { + createStore(storeName: string): Promise; + deleteStore(storeName: string): Promise; + listStores(): Promise; + close(): void; +} diff --git a/packages/core/src/internal/clients/storage/IStorageDataClient.ts b/packages/core/src/internal/clients/storage/IStorageDataClient.ts new file mode 100644 index 000000000..dc4ac46de --- /dev/null +++ b/packages/core/src/internal/clients/storage/IStorageDataClient.ts @@ -0,0 +1,12 @@ +import {StoreGet, StoreSet, StoreDelete} from '../../../index'; + +export interface IStorageDataClient { + get(storeName: string, key: string): Promise; + set( + storeName: string, + key: string, + value: string | number | Uint8Array + ): Promise; + delete(storeName: string, key: string): Promise; + close(): void; +} diff --git a/packages/core/src/internal/clients/storage/index.ts b/packages/core/src/internal/clients/storage/index.ts new file mode 100644 index 000000000..159d8a5da --- /dev/null +++ b/packages/core/src/internal/clients/storage/index.ts @@ -0,0 +1,4 @@ +export * from './AbstractStorageClient'; +export * from './IStorageControlClient'; +export * from './IStorageDataClient'; +export * from '../../../clients/IStorageClient'; diff --git a/packages/core/src/internal/utils/auth.ts b/packages/core/src/internal/utils/auth.ts index d18a1967d..41f3ab0c4 100644 --- a/packages/core/src/internal/utils/auth.ts +++ b/packages/core/src/internal/utils/auth.ts @@ -31,6 +31,7 @@ interface TokenAndEndpoints { controlEndpoint: string | undefined; cacheEndpoint: string | undefined; tokenEndpoint: string | undefined; + storageEndpoint: string | undefined; authToken: string; } @@ -43,6 +44,7 @@ export interface AllEndpoints { controlEndpoint: Endpoint; cacheEndpoint: Endpoint; tokenEndpoint: Endpoint; + storageEndpoint: Endpoint; } export function populateAllEndpointsFromBaseEndpoint( @@ -65,6 +67,10 @@ export function populateAllEndpointsFromBaseEndpoint( endpoint: `${prefix}token.${endpointOverride.baseEndpoint}`, secureConnection: endpointOverride.secureConnection, }, + storageEndpoint: { + endpoint: `${prefix}storage.${endpointOverride.baseEndpoint}`, + secureConnection: endpointOverride.secureConnection, + }, }; } @@ -97,6 +103,7 @@ export const decodeAuthToken = (token?: string): TokenAndEndpoints => { controlEndpoint: endpoints.controlEndpoint.endpoint, cacheEndpoint: endpoints.cacheEndpoint.endpoint, tokenEndpoint: endpoints.tokenEndpoint.endpoint, + storageEndpoint: endpoints.storageEndpoint.endpoint, authToken: base64DecodedToken.api_key, }; } else { @@ -108,6 +115,7 @@ export const decodeAuthToken = (token?: string): TokenAndEndpoints => { controlEndpoint: decodedLegacyToken.cp, cacheEndpoint: decodedLegacyToken.c, tokenEndpoint: decodedLegacyToken.c, + storageEndpoint: decodedLegacyToken.c, authToken: token, }; } diff --git a/packages/core/src/internal/utils/validators.ts b/packages/core/src/internal/utils/validators.ts index f349dbd40..5b3cbe603 100644 --- a/packages/core/src/internal/utils/validators.ts +++ b/packages/core/src/internal/utils/validators.ts @@ -2,6 +2,12 @@ import {InvalidArgumentError} from '../../errors'; import {ExpiresIn} from '../../utils'; import {decodeFromBase64, encodeToBase64} from './string'; +export function validateStoreName(name: string) { + if (isEmpty(name)) { + throw new InvalidArgumentError('store name must not be empty'); + } +} + export function validateCacheName(name: string) { if (isEmpty(name)) { throw new InvalidArgumentError('cache name must not be empty'); diff --git a/packages/core/src/messages/responses/enums/index.ts b/packages/core/src/messages/responses/enums/index.ts index 308364721..bdc8dc327 100644 --- a/packages/core/src/messages/responses/enums/index.ts +++ b/packages/core/src/messages/responses/enums/index.ts @@ -2,3 +2,4 @@ export * from './auth'; export * from './cache'; export * from './topics'; export * from './leaderboard'; +export * from './store'; diff --git a/packages/core/src/messages/responses/enums/store/control/index.ts b/packages/core/src/messages/responses/enums/store/control/index.ts new file mode 100644 index 000000000..ba52ca906 --- /dev/null +++ b/packages/core/src/messages/responses/enums/store/control/index.ts @@ -0,0 +1,15 @@ +export enum CreateStoreResponse { + Success = 'Success', + AlreadyExists = 'AlreadyExists', + Error = 'Error', +} + +export enum ListStoresResponse { + Success = 'Success', + Error = 'Error', +} + +export enum DeleteStoreResponse { + Success = 'Success', + Error = 'Error', +} diff --git a/packages/core/src/messages/responses/enums/store/index.ts b/packages/core/src/messages/responses/enums/store/index.ts new file mode 100644 index 000000000..418dcaf67 --- /dev/null +++ b/packages/core/src/messages/responses/enums/store/index.ts @@ -0,0 +1,2 @@ +export * from './control'; +export * from './scalar'; diff --git a/packages/core/src/messages/responses/enums/store/scalar/index.ts b/packages/core/src/messages/responses/enums/store/scalar/index.ts new file mode 100644 index 000000000..85c0c5fba --- /dev/null +++ b/packages/core/src/messages/responses/enums/store/scalar/index.ts @@ -0,0 +1,17 @@ +export enum StoreGetResponse { + Integer = 'Integer', + String = 'String', + Bytes = 'Bytes', + Double = 'Double', + Error = 'Error', +} + +export enum StoreSetResponse { + Success = 'Success', + Error = 'Error', +} + +export enum StoreDeleteResponse { + Success = 'Success', + Error = 'Error', +} diff --git a/packages/core/src/messages/responses/storage/control/create-store.ts b/packages/core/src/messages/responses/storage/control/create-store.ts new file mode 100644 index 000000000..80f3a3c3d --- /dev/null +++ b/packages/core/src/messages/responses/storage/control/create-store.ts @@ -0,0 +1,42 @@ +import {CreateStoreResponse} from '../../enums'; +import {BaseResponseError, BaseResponseSuccess} from '../../response-base'; +import {SdkError} from '../../../../errors'; + +interface IResponse { + readonly type: CreateStoreResponse; +} + +/** + * Indicates a successful create store request. + */ +export class Success extends BaseResponseSuccess implements IResponse { + readonly type: CreateStoreResponse.Success = CreateStoreResponse.Success; +} + +/** + * Indicates that the store already exists. + */ +export class AlreadyExists extends BaseResponseSuccess implements IResponse { + readonly type: CreateStoreResponse.AlreadyExists = + CreateStoreResponse.AlreadyExists; +} + +/** + * Indicates that an error occurred during the create store request. + * + * This response object includes the following fields that you can use to determine + * how you would like to handle the error: + * + * - `errorCode()` - a unique Momento error code indicating the type of error that occurred. + * - `message()` - a human-readable description of the error + * - `innerException()` - the original error that caused the failure; can be re-thrown. + */ +export class Error extends BaseResponseError implements IResponse { + constructor(_innerException: SdkError) { + super(_innerException); + } + + readonly type: CreateStoreResponse.Error = CreateStoreResponse.Error; +} + +export type Response = Success | AlreadyExists | Error; diff --git a/packages/core/src/messages/responses/storage/control/delete-store.ts b/packages/core/src/messages/responses/storage/control/delete-store.ts new file mode 100644 index 000000000..a686cf301 --- /dev/null +++ b/packages/core/src/messages/responses/storage/control/delete-store.ts @@ -0,0 +1,34 @@ +import {DeleteStoreResponse} from '../../enums'; +import {BaseResponseError, BaseResponseSuccess} from '../../response-base'; +import {SdkError} from '../../../../errors'; + +interface IResponse { + readonly type: DeleteStoreResponse; +} + +/** + * Indicates a successful delete store request. + */ +export class Success extends BaseResponseSuccess implements IResponse { + readonly type: DeleteStoreResponse.Success = DeleteStoreResponse.Success; +} + +/** + * Indicates that an error occurred during the delete store request. + * + * This response object includes the following fields that you can use to determine + * how you would like to handle the error: + * + * - `errorCode()` - a unique Momento error code indicating the type of error that occurred. + * - `message()` - a human-readable description of the error + * - `innerException()` - the original error that caused the failure; can be re-thrown. + */ +export class Error extends BaseResponseError implements IResponse { + constructor(_innerException: SdkError) { + super(_innerException); + } + + readonly type: DeleteStoreResponse.Error = DeleteStoreResponse.Error; +} + +export type Response = Success | Error; diff --git a/packages/core/src/messages/responses/storage/control/index.ts b/packages/core/src/messages/responses/storage/control/index.ts new file mode 100644 index 000000000..51e44f1a1 --- /dev/null +++ b/packages/core/src/messages/responses/storage/control/index.ts @@ -0,0 +1,3 @@ +export * as DeleteStore from './delete-store'; +export * as CreateStore from './create-store'; +export * as ListStores from './list-stores'; diff --git a/packages/core/src/messages/responses/storage/control/list-stores.ts b/packages/core/src/messages/responses/storage/control/list-stores.ts new file mode 100644 index 000000000..361b4f919 --- /dev/null +++ b/packages/core/src/messages/responses/storage/control/list-stores.ts @@ -0,0 +1,54 @@ +import {ListStoresResponse} from '../../enums'; +import {BaseResponseError, BaseResponseSuccess} from '../../response-base'; +import {StoreInfo} from '../../../store-info'; +import {SdkError} from '../../../../errors'; + +interface IResponse { + readonly type: ListStoresResponse; +} + +/** + * Indicates a successful list stores request. + */ +export class Success extends BaseResponseSuccess implements IResponse { + readonly type: ListStoresResponse.Success = ListStoresResponse.Success; + private readonly stores: StoreInfo[]; + + constructor(stores: StoreInfo[]) { + super(); + this.stores = stores; + } + + /** + * An array of StoreInfo, containing information about each store. + * @returns {StoreInfo[]} + */ + public getStores() { + return this.stores; + } + + public override toString() { + const stores = this.stores.map(storeInfo => storeInfo.getName()); + return super.toString() + ': ' + stores.join(', '); + } +} + +/** + * Indicates that an error occurred during the list stores request. + * + * This response object includes the following fields that you can use to determine + * how you would like to handle the error: + * + * - `errorCode()` - a unique Momento error code indicating the type of error that occurred. + * - `message()` - a human-readable description of the error + * - `innerException()` - the original error that caused the failure; can be re-thrown. + */ +export class Error extends BaseResponseError implements IResponse { + constructor(_innerException: SdkError) { + super(_innerException); + } + + readonly type: ListStoresResponse.Error = ListStoresResponse.Error; +} + +export type Response = Success | Error; diff --git a/packages/core/src/messages/responses/storage/index.ts b/packages/core/src/messages/responses/storage/index.ts new file mode 100644 index 000000000..418dcaf67 --- /dev/null +++ b/packages/core/src/messages/responses/storage/index.ts @@ -0,0 +1,2 @@ +export * from './control'; +export * from './scalar'; diff --git a/packages/core/src/messages/responses/storage/scalar/index.ts b/packages/core/src/messages/responses/storage/scalar/index.ts new file mode 100644 index 000000000..b6c65f1ee --- /dev/null +++ b/packages/core/src/messages/responses/storage/scalar/index.ts @@ -0,0 +1,3 @@ +export * as StoreDelete from './store-delete'; +export * as StoreGet from './store-get'; +export * as StoreSet from './store-set'; diff --git a/packages/core/src/messages/responses/storage/scalar/store-delete.ts b/packages/core/src/messages/responses/storage/scalar/store-delete.ts new file mode 100644 index 000000000..5da16fd61 --- /dev/null +++ b/packages/core/src/messages/responses/storage/scalar/store-delete.ts @@ -0,0 +1,34 @@ +import {StoreDeleteResponse} from '../../enums'; +import {BaseResponseError, BaseResponseSuccess} from '../../response-base'; +import {SdkError} from '../../../../errors'; + +interface IResponse { + readonly type: StoreDeleteResponse; +} + +/** + * Indicates a Successful store delete request. + */ +export class Success extends BaseResponseSuccess implements IResponse { + readonly type: StoreDeleteResponse.Success = StoreDeleteResponse.Success; +} + +/** + * Indicates that an error occurred during the store delete request. + * + * This response object includes the following fields that you can use to determine + * how you would like to handle the error: + * + * - `errorCode()` - a unique Momento error code indicating the type of error that occurred. + * - `message()` - a human-readable description of the error + * - `innerException()` - the original error that caused the failure; can be re-thrown. + */ +export class Error extends BaseResponseError implements IResponse { + constructor(_innerException: SdkError) { + super(_innerException); + } + + readonly type: StoreDeleteResponse.Error = StoreDeleteResponse.Error; +} + +export type Response = Success | Error; diff --git a/packages/core/src/messages/responses/storage/scalar/store-get.ts b/packages/core/src/messages/responses/storage/scalar/store-get.ts new file mode 100644 index 000000000..8564dd83f --- /dev/null +++ b/packages/core/src/messages/responses/storage/scalar/store-get.ts @@ -0,0 +1,93 @@ +import {StoreGetResponse} from '../../enums'; +import {BaseResponseError, ResponseBase} from '../../response-base'; +import {SdkError} from '../../../../errors'; + +interface IResponse { + type: StoreGetResponse; + value(): string | number | Uint8Array | undefined; +} + +export class StringResponse extends ResponseBase implements IResponse { + private readonly _value: string; + constructor(value: string) { + super(); + this._value = value; + } + + value(): string { + return this._value; + } + + type: StoreGetResponse.String; +} + +export class IntegerResponse extends ResponseBase implements IResponse { + private readonly _value: number; + constructor(value: number) { + super(); + this._value = value; + } + + value(): number { + return this._value; + } + + type: StoreGetResponse.Integer; +} + +export class DoubleResponse extends ResponseBase implements IResponse { + private readonly _value: number; + constructor(value: number) { + super(); + this._value = value; + } + + value(): number { + return this._value; + } + + type: StoreGetResponse.Double; +} + +export class BytesResponse extends ResponseBase implements IResponse { + private readonly _value: Uint8Array; + constructor(value: Uint8Array) { + super(); + this._value = value; + } + + value(): Uint8Array { + return this._value; + } + + type: StoreGetResponse.Bytes; +} + +/** + * Indicates that an error occurred during the cache get request. + * + * This response object includes the following fields that you can use to determine + * how you would like to handle the error: + * + * - `errorCode()` - a unique Momento error code indicating the type of error that occurred. + * - `message()` - a human-readable description of the error + * - `innerException()` - the original error that caused the failure; can be re-thrown. + */ +export class Error extends BaseResponseError implements IResponse { + readonly type: StoreGetResponse.Error = StoreGetResponse.Error; + constructor(_innerException: SdkError) { + super(_innerException); + } + + value(): undefined { + return undefined; + } +} + +export type Success = + | InstanceType + | InstanceType + | InstanceType + | InstanceType; + +export type Response = Success | Error; diff --git a/packages/core/src/messages/responses/storage/scalar/store-set.ts b/packages/core/src/messages/responses/storage/scalar/store-set.ts new file mode 100644 index 000000000..f9c510c00 --- /dev/null +++ b/packages/core/src/messages/responses/storage/scalar/store-set.ts @@ -0,0 +1,34 @@ +import {StoreSetResponse} from '../../enums'; +import {BaseResponseError, BaseResponseSuccess} from '../../response-base'; +import {SdkError} from '../../../../errors'; + +interface IResponse { + readonly type: StoreSetResponse; +} + +/** + * Indicates a Successful store set request. + */ +export class Success extends BaseResponseSuccess implements IResponse { + readonly type: StoreSetResponse.Success = StoreSetResponse.Success; +} + +/** + * Indicates that an error occurred during the store set request. + * + * This response object includes the following fields that you can use to determine + * how you would like to handle the error: + * + * - `errorCode()` - a unique Momento error code indicating the type of error that occurred. + * - `message()` - a human-readable description of the error + * - `innerException()` - the original error that caused the failure; can be re-thrown. + */ +export class Error extends BaseResponseError implements IResponse { + constructor(_innerException: SdkError) { + super(_innerException); + } + + readonly type: StoreSetResponse.Error = StoreSetResponse.Error; +} + +export type Response = Success | Error; diff --git a/packages/core/src/messages/store-info.ts b/packages/core/src/messages/store-info.ts new file mode 100644 index 000000000..720f98b6f --- /dev/null +++ b/packages/core/src/messages/store-info.ts @@ -0,0 +1,11 @@ +export class StoreInfo { + private readonly name: string; + + constructor(name: string) { + this.name = name; + } + + public getName() { + return this.name; + } +} diff --git a/packages/core/test/unit/auth/credential-provider.test.ts b/packages/core/test/unit/auth/credential-provider.test.ts index 272790d7b..ac3bfa61b 100644 --- a/packages/core/test/unit/auth/credential-provider.test.ts +++ b/packages/core/test/unit/auth/credential-provider.test.ts @@ -1,6 +1,8 @@ -import {CredentialProvider} from '../../../src/auth/credential-provider'; -import {Base64DecodedV1Token} from '../../../src/internal/utils/auth'; -import {encodeToBase64} from '../../../src/internal/utils/string'; +import {CredentialProvider} from '../../../src'; +import { + Base64DecodedV1Token, + encodeToBase64, +} from '../../../src/internal/utils'; // These tokens have valid syntax, but they don't actually have valid credentials. Just used for unit testing. const fakeTestLegacyToken = @@ -89,11 +91,13 @@ describe('StringMomentoTokenProvider', () => { controlEndpoint: {endpoint: 'control.foo'}, cacheEndpoint: {endpoint: 'cache.foo'}, tokenEndpoint: {endpoint: 'token.foo'}, + storageEndpoint: {endpoint: 'storage.foo'}, }, }); expect(legacyAuthProvider.getControlEndpoint()).toEqual('control.foo'); expect(legacyAuthProvider.getCacheEndpoint()).toEqual('cache.foo'); expect(legacyAuthProvider.getTokenEndpoint()).toEqual('token.foo'); + expect(legacyAuthProvider.getStorageEndpoint()).toEqual('storage.foo'); expect(legacyAuthProvider.areEndpointsOverridden()).toEqual(true); const v1AuthProvider = CredentialProvider.fromString({ @@ -102,12 +106,14 @@ describe('StringMomentoTokenProvider', () => { controlEndpoint: {endpoint: 'control.foo'}, cacheEndpoint: {endpoint: 'cache.foo'}, tokenEndpoint: {endpoint: 'token.foo'}, + storageEndpoint: {endpoint: 'storage.foo'}, }, }); expect(v1AuthProvider.getAuthToken()).toEqual(fakeTestV1ApiKey); expect(v1AuthProvider.getControlEndpoint()).toEqual('control.foo'); expect(v1AuthProvider.getCacheEndpoint()).toEqual('cache.foo'); expect(v1AuthProvider.getTokenEndpoint()).toEqual('token.foo'); + expect(v1AuthProvider.getStorageEndpoint()).toEqual('storage.foo'); expect(v1AuthProvider.areEndpointsOverridden()).toEqual(true); }); @@ -118,12 +124,14 @@ describe('StringMomentoTokenProvider', () => { controlEndpoint: {endpoint: 'control.foo'}, cacheEndpoint: {endpoint: 'cache.foo'}, tokenEndpoint: {endpoint: 'token.foo'}, + storageEndpoint: {endpoint: 'storage.foo'}, }, }); expect(sessionTokenProvider.getAuthToken()).toEqual(fakeSessionToken); expect(sessionTokenProvider.getControlEndpoint()).toEqual('control.foo'); expect(sessionTokenProvider.getCacheEndpoint()).toEqual('cache.foo'); expect(sessionTokenProvider.getTokenEndpoint()).toEqual('token.foo'); + expect(sessionTokenProvider.getStorageEndpoint()).toEqual('storage.foo'); expect(sessionTokenProvider.areEndpointsOverridden()).toEqual(true); }); @@ -205,12 +213,14 @@ describe('EnvMomentoTokenProvider', () => { controlEndpoint: {endpoint: 'control.foo'}, cacheEndpoint: {endpoint: 'cache.foo'}, tokenEndpoint: {endpoint: 'token.foo'}, + storageEndpoint: {endpoint: 'storage.foo'}, }, }); expect(legacyAuthProvider.getAuthToken()).toEqual(fakeTestLegacyToken); expect(legacyAuthProvider.getControlEndpoint()).toEqual('control.foo'); expect(legacyAuthProvider.getCacheEndpoint()).toEqual('cache.foo'); expect(legacyAuthProvider.getTokenEndpoint()).toEqual('token.foo'); + expect(legacyAuthProvider.getStorageEndpoint()).toEqual('storage.foo'); expect(legacyAuthProvider.areEndpointsOverridden()).toEqual(true); process.env[testEnvVarName] = base64EncodedFakeV1AuthToken; @@ -220,12 +230,14 @@ describe('EnvMomentoTokenProvider', () => { controlEndpoint: {endpoint: 'control.foo'}, cacheEndpoint: {endpoint: 'cache.foo'}, tokenEndpoint: {endpoint: 'token.foo'}, + storageEndpoint: {endpoint: 'storage.foo'}, }, }); expect(v1AuthProvider.getAuthToken()).toEqual(fakeTestV1ApiKey); expect(v1AuthProvider.getControlEndpoint()).toEqual('control.foo'); expect(v1AuthProvider.getCacheEndpoint()).toEqual('cache.foo'); expect(v1AuthProvider.getTokenEndpoint()).toEqual('token.foo'); + expect(v1AuthProvider.getStorageEndpoint()).toEqual('storage.foo'); expect(v1AuthProvider.areEndpointsOverridden()).toEqual(true); }); From 4b18a50423e55a66d69db461a94cad203ab638b8 Mon Sep 17 00:00:00 2001 From: Matt Straathof Date: Fri, 7 Jun 2024 10:15:03 -0700 Subject: [PATCH 02/15] chore: use protos from npmjs --- packages/client-sdk-web/package-lock.json | 357 +++++++++++----------- packages/client-sdk-web/package.json | 2 +- 2 files changed, 177 insertions(+), 182 deletions(-) diff --git a/packages/client-sdk-web/package-lock.json b/packages/client-sdk-web/package-lock.json index f975e299a..ac7c93e17 100644 --- a/packages/client-sdk-web/package-lock.json +++ b/packages/client-sdk-web/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.1", "license": "Apache-2.0", "dependencies": { - "@gomomento/generated-types-webtext": "file:../../../client-protos/javascript-web", + "@gomomento/generated-types-webtext": "0.111.2", "@gomomento/sdk-core": "file:../core", "@types/google-protobuf": "3.15.6", "google-protobuf": "3.21.2", @@ -44,23 +44,7 @@ "node": ">= 16" } }, - "../../../client-protos/javascript-web": { - "version": "0.0.1", - "license": "Apache-2.0", - "dependencies": { - "google-protobuf": "3.21.2", - "grpc-web": "1.4.2" - }, - "devDependencies": { - "@tsconfig/node16": "1.0.2", - "@types/google-protobuf": "^3.15.6", - "@types/node": "16.10.3", - "google-protobuf": "3.21.2", - "typescript": "^4.9.5" - } - }, "../common-integration-tests": { - "name": "@gomomento/common-integration-tests", "version": "0.0.1", "dev": true, "license": "Apache-2.0", @@ -92,7 +76,6 @@ } }, "../core": { - "name": "@gomomento/sdk-core", "version": "0.0.1", "license": "Apache-2.0", "dependencies": { @@ -144,30 +127,30 @@ } }, "node_modules/@babel/compat-data": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.24.4.tgz", - "integrity": "sha512-vg8Gih2MLK+kOkHJp4gBEIkyaIi00jgWot2D9QOmmfLC8jINSOzmCLta6Bvz/JSBCqnegV0L80jhxkol5GWNfQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.24.7.tgz", + "integrity": "sha512-qJzAIcv03PyaWqxRgO4mSU3lihncDT296vnyuE2O8uA4w3UHWI4S3hgeZd1L8W1Bft40w9JxJ2b412iDUFFRhw==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/core": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.24.5.tgz", - "integrity": "sha512-tVQRucExLQ02Boi4vdPp49svNGcfL2GhdTCT9aldhXgCJVAI21EtRfBettiuLUwce/7r6bFdgs6JFkcdTiFttA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.24.7.tgz", + "integrity": "sha512-nykK+LEK86ahTkX/3TgauT0ikKoNCfKHEaZYTUVupJdTLzGNvrblu4u6fa7DhZONAltdf8e662t/abY8idrd/g==", "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.0", - "@babel/code-frame": "^7.24.2", - "@babel/generator": "^7.24.5", - "@babel/helper-compilation-targets": "^7.23.6", - "@babel/helper-module-transforms": "^7.24.5", - "@babel/helpers": "^7.24.5", - "@babel/parser": "^7.24.5", - "@babel/template": "^7.24.0", - "@babel/traverse": "^7.24.5", - "@babel/types": "^7.24.5", + "@babel/code-frame": "^7.24.7", + "@babel/generator": "^7.24.7", + "@babel/helper-compilation-targets": "^7.24.7", + "@babel/helper-module-transforms": "^7.24.7", + "@babel/helpers": "^7.24.7", + "@babel/parser": "^7.24.7", + "@babel/template": "^7.24.7", + "@babel/traverse": "^7.24.7", + "@babel/types": "^7.24.7", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -183,12 +166,12 @@ } }, "node_modules/@babel/core/node_modules/@babel/code-frame": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", - "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.2", + "@babel/highlight": "^7.24.7", "picocolors": "^1.0.0" }, "engines": { @@ -205,12 +188,12 @@ } }, "node_modules/@babel/generator": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.24.5.tgz", - "integrity": "sha512-x32i4hEXvr+iI0NEoEfDKzlemF8AmtOP8CcrRaEcpzysWuoEb1KknpcvMsHKPONoKZiDuItklgWhB18xEhr9PA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.24.7.tgz", + "integrity": "sha512-oipXieGC3i45Y1A41t4tAqpnEZWgB/lC6Ehh6+rOviR5XWpTtMmLN+fGjz9vOiNRt0p6RtO6DtD0pdU3vpqdSA==", "dev": true, "dependencies": { - "@babel/types": "^7.24.5", + "@babel/types": "^7.24.7", "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25", "jsesc": "^2.5.1" @@ -220,13 +203,13 @@ } }, "node_modules/@babel/helper-compilation-targets": { - "version": "7.23.6", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.23.6.tgz", - "integrity": "sha512-9JB548GZoQVmzrFgp8o7KxdgkTGm6xs9DW0o/Pim72UDjzr5ObUQ6ZzYPqA+g9OTS2bBQoctLJrky0RDCAWRgQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.24.7.tgz", + "integrity": "sha512-ctSdRHBi20qWOfy27RUb4Fhp07KSJ3sXcuSvTrXrc4aG8NSYDo1ici3Vhg9bg69y5bj0Mr1lh0aeEgTvc12rMg==", "dev": true, "dependencies": { - "@babel/compat-data": "^7.23.5", - "@babel/helper-validator-option": "^7.23.5", + "@babel/compat-data": "^7.24.7", + "@babel/helper-validator-option": "^7.24.7", "browserslist": "^4.22.2", "lru-cache": "^5.1.1", "semver": "^6.3.1" @@ -245,62 +228,66 @@ } }, "node_modules/@babel/helper-environment-visitor": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz", - "integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.24.7.tgz", + "integrity": "sha512-DoiN84+4Gnd0ncbBOM9AZENV4a5ZiL39HYMyZJGZ/AZEykHYdJw0wW3kdcsh9/Kn+BRXHLkkklZ51ecPKmI1CQ==", "dev": true, + "dependencies": { + "@babel/types": "^7.24.7" + }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-function-name": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz", - "integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.24.7.tgz", + "integrity": "sha512-FyoJTsj/PEUWu1/TYRiXTIHc8lbw+TDYkZuoE43opPS5TrI7MyONBE1oNvfguEXAD9yhQRrVBnXdXzSLQl9XnA==", "dev": true, "dependencies": { - "@babel/template": "^7.22.15", - "@babel/types": "^7.23.0" + "@babel/template": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-hoist-variables": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz", - "integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.24.7.tgz", + "integrity": "sha512-MJJwhkoGy5c4ehfoRyrJ/owKeMl19U54h27YYftT0o2teQ3FJ3nQUf/I3LlJsX4l3qlw7WRXUmiyajvHXoTubQ==", "dev": true, "dependencies": { - "@babel/types": "^7.22.5" + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-imports": { - "version": "7.24.3", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.24.3.tgz", - "integrity": "sha512-viKb0F9f2s0BCS22QSF308z/+1YWKV/76mwt61NBzS5izMzDPwdq1pTrzf+Li3npBWX9KdQbkeCt1jSAM7lZqg==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.24.7.tgz", + "integrity": "sha512-8AyH3C+74cgCVVXow/myrynrAGv+nTVg5vKu2nZph9x7RcRwzmh0VFallJuFTZ9mx6u4eSdXZfcOzSqTUm0HCA==", "dev": true, "dependencies": { - "@babel/types": "^7.24.0" + "@babel/traverse": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.24.5.tgz", - "integrity": "sha512-9GxeY8c2d2mdQUP1Dye0ks3VDyIMS98kt/llQ2nUId8IsWqTF0l1LkSX0/uP7l7MCDrzXS009Hyhe2gzTiGW8A==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.24.7.tgz", + "integrity": "sha512-1fuJEwIrp+97rM4RWdO+qrRsZlAeL1lQJoPqtCYWv0NL115XM93hIH4CSRln2w52SqvmY5hqdtauB6QFCDiZNQ==", "dev": true, "dependencies": { - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-module-imports": "^7.24.3", - "@babel/helper-simple-access": "^7.24.5", - "@babel/helper-split-export-declaration": "^7.24.5", - "@babel/helper-validator-identifier": "^7.24.5" + "@babel/helper-environment-visitor": "^7.24.7", + "@babel/helper-module-imports": "^7.24.7", + "@babel/helper-simple-access": "^7.24.7", + "@babel/helper-split-export-declaration": "^7.24.7", + "@babel/helper-validator-identifier": "^7.24.7" }, "engines": { "node": ">=6.9.0" @@ -310,86 +297,86 @@ } }, "node_modules/@babel/helper-plugin-utils": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.5.tgz", - "integrity": "sha512-xjNLDopRzW2o6ba0gKbkZq5YWEBaK3PCyTOY1K2P/O07LGMhMqlMXPxwN4S5/RhWuCobT8z0jrlKGlYmeR1OhQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.7.tgz", + "integrity": "sha512-Rq76wjt7yz9AAc1KnlRKNAi/dMSVWgDRx43FHoJEbcYU6xOWaE2dVPwcdTukJrjxS65GITyfbvEYHvkirZ6uEg==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-simple-access": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.24.5.tgz", - "integrity": "sha512-uH3Hmf5q5n7n8mz7arjUlDOCbttY/DW4DYhE6FUsjKJ/oYC1kQQUvwEQWxRwUpX9qQKRXeqLwWxrqilMrf32sQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.24.7.tgz", + "integrity": "sha512-zBAIvbCMh5Ts+b86r/CjU+4XGYIs+R1j951gxI3KmmxBMhCg4oQMsv6ZXQ64XOm/cvzfU1FmoCyt6+owc5QMYg==", "dev": true, "dependencies": { - "@babel/types": "^7.24.5" + "@babel/traverse": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-split-export-declaration": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.24.5.tgz", - "integrity": "sha512-5CHncttXohrHk8GWOFCcCl4oRD9fKosWlIRgWm4ql9VYioKm52Mk2xsmoohvm7f3JoiLSM5ZgJuRaf5QZZYd3Q==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.24.7.tgz", + "integrity": "sha512-oy5V7pD+UvfkEATUKvIjvIAH/xCzfsFVw7ygW2SI6NClZzquT+mwdTfgfdbUiceh6iQO0CHtCPsyze/MZ2YbAA==", "dev": true, "dependencies": { - "@babel/types": "^7.24.5" + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-string-parser": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.1.tgz", - "integrity": "sha512-2ofRCjnnA9y+wk8b9IAREroeUP02KHp431N2mhKniy2yKIDKpbrHv9eXwm8cBeWQYcJmzv5qKCu65P47eCF7CQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.7.tgz", + "integrity": "sha512-7MbVt6xrwFQbunH2DNQsAP5sTGxfqQtErvBIvIMi6EQnbgUOuVYanvREcmFrOPhoXBrTtjhhP+lW+o5UfK+tDg==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.5.tgz", - "integrity": "sha512-3q93SSKX2TWCG30M2G2kwaKeTYgEUp5Snjuj8qm729SObL6nbtUldAi37qbxkD5gg3xnBio+f9nqpSepGZMvxA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz", + "integrity": "sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-option": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.23.5.tgz", - "integrity": "sha512-85ttAOMLsr53VgXkTbkx8oA6YTfT4q7/HzXSLEYmjcSTJPMPQtvq1BD79Byep5xMUYbGRzEpDsjUf3dyp54IKw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.24.7.tgz", + "integrity": "sha512-yy1/KvjhV/ZCL+SM7hBrvnZJ3ZuT9OuZgIJAGpPEToANvc3iM6iDvBnRjtElWibHU6n8/LPR/EjX9EtIEYO3pw==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helpers": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.24.5.tgz", - "integrity": "sha512-CiQmBMMpMQHwM5m01YnrM6imUG1ebgYJ+fAIW4FZe6m4qHTPaRHti+R8cggAwkdz4oXhtO4/K9JWlh+8hIfR2Q==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.24.7.tgz", + "integrity": "sha512-NlmJJtvcw72yRJRcnCmGvSi+3jDEg8qFu3z0AFoymmzLx5ERVWyzd9kVXr7Th9/8yIJi2Zc6av4Tqz3wFs8QWg==", "dev": true, "dependencies": { - "@babel/template": "^7.24.0", - "@babel/traverse": "^7.24.5", - "@babel/types": "^7.24.5" + "@babel/template": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/highlight": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.5.tgz", - "integrity": "sha512-8lLmua6AVh/8SLJRRVD6V8p73Hir9w5mJrhE+IPpILG31KKlI9iz5zmBYKcWPS59qSfgP9RaSBQSHHE81WKuEw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.7.tgz", + "integrity": "sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==", "dev": true, "dependencies": { - "@babel/helper-validator-identifier": "^7.24.5", + "@babel/helper-validator-identifier": "^7.24.7", "chalk": "^2.4.2", "js-tokens": "^4.0.0", "picocolors": "^1.0.0" @@ -470,9 +457,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.5.tgz", - "integrity": "sha512-EOv5IK8arwh3LI47dz1b0tKUb/1uhHAnHJOrjgtQMIpu1uXd9mlFrJg9IUgGUgZ41Ch0K8REPTYpO7B76b4vJg==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.7.tgz", + "integrity": "sha512-9uUYRm6OqQrCqQdG1iCBwBPZgN8ciDBro2nIOFaiRz1/BCxaI7CNvQbDHvsArAC7Tw9Hda/B3U+6ui9u4HWXPw==", "dev": true, "bin": { "parser": "bin/babel-parser.js" @@ -542,12 +529,12 @@ } }, "node_modules/@babel/plugin-syntax-jsx": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.24.1.tgz", - "integrity": "sha512-2eCtxZXf+kbkMIsXS4poTvT4Yu5rXiRa+9xGVT56raghjmBTKMpFNc9R4IDiB4emao9eO22Ox7CxuJG7BgExqA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.24.7.tgz", + "integrity": "sha512-6ddciUPe/mpMnOKv/U+RSd2vvVy+Yw/JfBB0ZHYjEZt9NLHmCUylNYlsbqCCS1Bffjlb0fCwC9Vqz+sBz6PsiQ==", "dev": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.24.7" }, "engines": { "node": ">=6.9.0" @@ -644,12 +631,12 @@ } }, "node_modules/@babel/plugin-syntax-typescript": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.24.1.tgz", - "integrity": "sha512-Yhnmvy5HZEnHUty6i++gcfH1/l68AHnItFHnaCv6hn9dNh0hQvvQJsxpi4BMBFN5DLeHBuucT/0DgzXif/OyRw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.24.7.tgz", + "integrity": "sha512-c/+fVeJBB0FeKsFvwytYiUD+LBvhHjGSI0g446PRGdSVGZLRNArBUno2PETbAly3tpiNAQR5XaZ+JslxkotsbA==", "dev": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.24.7" }, "engines": { "node": ">=6.9.0" @@ -659,26 +646,26 @@ } }, "node_modules/@babel/template": { - "version": "7.24.0", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.24.0.tgz", - "integrity": "sha512-Bkf2q8lMB0AFpX0NFEqSbx1OkTHf0f+0j82mkw+ZpzBnkk7e9Ql0891vlfgi+kHwOk8tQjiQHpqh4LaSa0fKEA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.24.7.tgz", + "integrity": "sha512-jYqfPrU9JTF0PmPy1tLYHW4Mp4KlgxJD9l2nP9fD6yT/ICi554DmrWBAEYpIelzjHf1msDP3PxJIRt/nFNfBig==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.23.5", - "@babel/parser": "^7.24.0", - "@babel/types": "^7.24.0" + "@babel/code-frame": "^7.24.7", + "@babel/parser": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/template/node_modules/@babel/code-frame": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", - "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.2", + "@babel/highlight": "^7.24.7", "picocolors": "^1.0.0" }, "engines": { @@ -686,19 +673,19 @@ } }, "node_modules/@babel/traverse": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.24.5.tgz", - "integrity": "sha512-7aaBLeDQ4zYcUFDUD41lJc1fG8+5IU9DaNSJAgal866FGvmD5EbWQgnEC6kO1gGLsX0esNkfnJSndbTXA3r7UA==", - "dev": true, - "dependencies": { - "@babel/code-frame": "^7.24.2", - "@babel/generator": "^7.24.5", - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-function-name": "^7.23.0", - "@babel/helper-hoist-variables": "^7.22.5", - "@babel/helper-split-export-declaration": "^7.24.5", - "@babel/parser": "^7.24.5", - "@babel/types": "^7.24.5", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.24.7.tgz", + "integrity": "sha512-yb65Ed5S/QAcewNPh0nZczy9JdYXkkAbIsEo+P7BE7yO3txAY30Y/oPa3QkQ5It3xVG2kpKMg9MsdxZaO31uKA==", + "dev": true, + "dependencies": { + "@babel/code-frame": "^7.24.7", + "@babel/generator": "^7.24.7", + "@babel/helper-environment-visitor": "^7.24.7", + "@babel/helper-function-name": "^7.24.7", + "@babel/helper-hoist-variables": "^7.24.7", + "@babel/helper-split-export-declaration": "^7.24.7", + "@babel/parser": "^7.24.7", + "@babel/types": "^7.24.7", "debug": "^4.3.1", "globals": "^11.1.0" }, @@ -707,12 +694,12 @@ } }, "node_modules/@babel/traverse/node_modules/@babel/code-frame": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", - "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.2", + "@babel/highlight": "^7.24.7", "picocolors": "^1.0.0" }, "engines": { @@ -729,13 +716,13 @@ } }, "node_modules/@babel/types": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.24.5.tgz", - "integrity": "sha512-6mQNsaLeXTw0nxYUYu+NSa4Hx4BlF1x1x8/PMFbiR+GBSr+2DkECc69b8hgy2frEodNcvPffeH8YfWd3LI6jhQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.24.7.tgz", + "integrity": "sha512-XEFXSlxiG5td2EJRe8vOmRbaXVgfcBlszKujvVmWIK/UpywWljQCfzAv3RQCGujWQ1RD4YYWEAqDXfuJiy8f5Q==", "dev": true, "dependencies": { - "@babel/helper-string-parser": "^7.24.1", - "@babel/helper-validator-identifier": "^7.24.5", + "@babel/helper-string-parser": "^7.24.7", + "@babel/helper-validator-identifier": "^7.24.7", "to-fast-properties": "^2.0.0" }, "engines": { @@ -786,9 +773,9 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.10.0", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.10.0.tgz", - "integrity": "sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA==", + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.10.1.tgz", + "integrity": "sha512-Zm2NGpWELsQAD1xsJzGQpYfvICSsFkEpU0jxBjfdC6uNEWXcHnfs9hScFWtXVDVl+rBQJGrl4g1vcKIejpH9dA==", "dev": true, "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" @@ -828,8 +815,13 @@ "link": true }, "node_modules/@gomomento/generated-types-webtext": { - "resolved": "../../../client-protos/javascript-web", - "link": true + "version": "0.111.2", + "resolved": "https://registry.npmjs.org/@gomomento/generated-types-webtext/-/generated-types-webtext-0.111.2.tgz", + "integrity": "sha512-yOwaGIuuqZ+XT+YIMY+Zgm0jvZIS0MEF0Zb+6sWmuqiujtZreizjfEA50Bf3rzKWcCyd6EAHDcSorpVVUbNAZA==", + "dependencies": { + "google-protobuf": "3.21.2", + "grpc-web": "1.4.2" + } }, "node_modules/@gomomento/sdk-core": { "resolved": "../core", @@ -1386,9 +1378,9 @@ } }, "node_modules/@types/babel__traverse": { - "version": "7.20.5", - "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.5.tgz", - "integrity": "sha512-WXCyOcRtH37HAUkpXhUduaxdm82b4GSlyTqajXviN4EfiuPgNYR109xMCKvpl6zPIpua0DGlMEDCq+g8EdoheQ==", + "version": "7.20.6", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.6.tgz", + "integrity": "sha512-r1bzfrm0tomOI8g1SzvCaQHo6Lcv6zu0EA+W2kHrt8dyrHQxGzBBL4kdkzIS+jBMV+EYcMAEAqXqYaLJq5rOZg==", "dev": true, "dependencies": { "@babel/types": "^7.20.7" @@ -2267,9 +2259,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001617", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001617.tgz", - "integrity": "sha512-mLyjzNI9I+Pix8zwcrpxEbGlfqOkF9kM3ptzmKNw5tizSyYwMe+nGLTqMK9cO+0E+Bh6TsBxNAaHWEM8xwSsmA==", + "version": "1.0.30001629", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001629.tgz", + "integrity": "sha512-c3dl911slnQhmxUIT4HhYzT7wnBK/XYpGnYLOj4nJBaRiw52Ibe7YxlDaAeRECvA786zCuExhxIUJ2K7nHMrBw==", "dev": true, "funding": [ { @@ -2541,9 +2533,9 @@ } }, "node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz", + "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", "dev": true, "dependencies": { "ms": "2.1.2" @@ -2700,9 +2692,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.762", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.762.tgz", - "integrity": "sha512-rrFvGweLxPwwSwJOjIopy3Vr+J3cIPtZzuc74bmlvmBIgQO3VYJDvVrlj94iKZ3ukXUH64Ex31hSfRTLqvjYJQ==", + "version": "1.4.795", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.795.tgz", + "integrity": "sha512-hHo4lK/8wb4NUa+NJYSFyJ0xedNHiR6ylilDtb8NUW9d4dmBFmGiecYEKCEbti1wTNzbKXLfl4hPWEkAFbHYlw==", "dev": true }, "node_modules/emittery": { @@ -3723,6 +3715,7 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", "dev": true, "dependencies": { "fs.realpath": "^1.0.0", @@ -4054,6 +4047,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", "dev": true, "dependencies": { "once": "^1.3.0", @@ -4997,12 +4991,12 @@ } }, "node_modules/jest-message-util/node_modules/@babel/code-frame": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", - "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.2", + "@babel/highlight": "^7.24.7", "picocolors": "^1.0.0" }, "engines": { @@ -5644,12 +5638,12 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz", + "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==", "dev": true, "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -5759,9 +5753,9 @@ } }, "node_modules/nwsapi": { - "version": "2.2.9", - "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.9.tgz", - "integrity": "sha512-2f3F0SEEer8bBu0dsNCFF50N0cTThV1nWFYcEYFZttdW0lDAoybv9cQoK7X7/68Z89S7FoRrVjP1LPX4XRf9vg==", + "version": "2.2.10", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.10.tgz", + "integrity": "sha512-QK0sRs7MKv0tKe1+5uZIQk/C8XGza4DAnztJG8iD+TpJIORARrCxczA738awHrZoHeTjSSoHqao2teO0dC/gFQ==", "dev": true }, "node_modules/object-inspect": { @@ -6026,9 +6020,9 @@ } }, "node_modules/picocolors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", - "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz", + "integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==", "dev": true }, "node_modules/picomatch": { @@ -6344,6 +6338,7 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "deprecated": "Rimraf versions prior to v4 are no longer supported", "dev": true, "dependencies": { "glob": "^7.1.3" @@ -6763,9 +6758,9 @@ } }, "node_modules/table/node_modules/ajv": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.13.0.tgz", - "integrity": "sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.16.0.tgz", + "integrity": "sha512-F0twR8U1ZU67JIEtekUcLkXkoO5mMMmgGD8sK/xUFzJ805jxHQl92hImFAqqXMyMYjSPOyUPAwHYhB72g5sTXw==", "dev": true, "dependencies": { "fast-deep-equal": "^3.1.3", @@ -7154,9 +7149,9 @@ } }, "node_modules/update-browserslist-db": { - "version": "1.0.15", - "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.15.tgz", - "integrity": "sha512-K9HWH62x3/EalU1U6sjSZiylm9C8tgq2mSvshZpqc7QE69RaA2qjhkW2HlNA0tFpEbtyFz7HTqbSdN4MSwUodA==", + "version": "1.0.16", + "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.16.tgz", + "integrity": "sha512-KVbTxlBYlckhF5wgfyZXTWnMn7MMZjMu9XG8bPlliUOP9ThaF4QnhP8qrjrH7DRzHfSk0oQv1wToW+iA5GajEQ==", "dev": true, "funding": [ { @@ -7174,7 +7169,7 @@ ], "dependencies": { "escalade": "^3.1.2", - "picocolors": "^1.0.0" + "picocolors": "^1.0.1" }, "bin": { "update-browserslist-db": "cli.js" diff --git a/packages/client-sdk-web/package.json b/packages/client-sdk-web/package.json index 0d57c8f66..e5219d600 100644 --- a/packages/client-sdk-web/package.json +++ b/packages/client-sdk-web/package.json @@ -55,7 +55,7 @@ "xhr2": "0.2.1" }, "dependencies": { - "@gomomento/generated-types-webtext": "file:../../../client-protos/javascript-web", + "@gomomento/generated-types-webtext": "0.111.2", "@gomomento/sdk-core": "file:../core", "@types/google-protobuf": "3.15.6", "google-protobuf": "3.21.2", From ba2417e0f4d48e9ba8cdc74fa53740445896b590 Mon Sep 17 00:00:00 2001 From: Matt Straathof Date: Thu, 13 Jun 2024 13:14:07 -0700 Subject: [PATCH 03/15] feat: add integration tests for storage service --- .../src/internal/storage-data-client.ts | 5 +- .../test/integration/integration-setup.ts | 21 +++ .../test/integration/shared/storage.test.ts | 5 + .../src/internal/storage-data-client.ts | 18 +-- .../test/integration/integration-setup.ts | 22 +++ .../test/integration/shared/storage.test.ts | 6 + .../common-integration-tests/src/index.ts | 1 + .../common-integration-tests/src/storage.ts | 151 ++++++++++++++++++ .../responses/enums/store/scalar/index.ts | 1 + .../responses/storage/scalar/store-get.ts | 16 +- 10 files changed, 231 insertions(+), 15 deletions(-) create mode 100644 packages/client-sdk-nodejs/test/integration/shared/storage.test.ts create mode 100644 packages/client-sdk-web/test/integration/shared/storage.test.ts create mode 100644 packages/common-integration-tests/src/storage.ts diff --git a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts index a5e8ed354..d4b6e16e0 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts @@ -168,7 +168,7 @@ export class StorageDataClient implements IStorageDataClient { interceptors: this.interceptors, }, (err: ServiceError | null, resp) => { - if (resp && resp.value.value !== 'none') { + if (resp) { switch (resp.value.value) { case 'double_value': { return resolve( @@ -190,6 +190,9 @@ export class StorageDataClient implements IStorageDataClient { new StoreGet.IntegerResponse(resp.value.integer_value) ); } + case 'none': { + return resolve(new StoreGet.Miss()); + } } } else { this.cacheServiceErrorMapper.resolveOrRejectError({ diff --git a/packages/client-sdk-nodejs/test/integration/integration-setup.ts b/packages/client-sdk-nodejs/test/integration/integration-setup.ts index 2721b255e..5e39ca3c1 100644 --- a/packages/client-sdk-nodejs/test/integration/integration-setup.ts +++ b/packages/client-sdk-nodejs/test/integration/integration-setup.ts @@ -11,6 +11,8 @@ import { TopicClient, PreviewLeaderboardClient, LeaderboardConfigurations, + StorageClient, + StorageConfigurations, } from '../../src'; import {ICacheClient} from '@gomomento/sdk-core/dist/src/clients/ICacheClient'; import {ITopicClient} from '@gomomento/sdk-core/dist/src/clients/ITopicClient'; @@ -135,6 +137,13 @@ function momentoTopicClientForTesting(): TopicClient { }); } +function momentoStorageClientForTesting(): StorageClient { + return new StorageClient({ + configuration: StorageConfigurations.Laptop.latest(), + credentialProvider: integrationTestCacheClientProps().credentialProvider, + }); +} + function momentoTopicClientWithThrowOnErrorsForTesting(): TopicClient { return new TopicClient({ configuration: @@ -226,6 +235,18 @@ export function SetupTopicIntegrationTest(): { }; } +export function SetupStorageIntegrationTest(): { + storageClient: StorageClient; + integrationTestStoreName: string; +} { + const {integrationTestCacheName} = SetupIntegrationTest(); + const storageClient = momentoStorageClientForTesting(); + return { + storageClient, + integrationTestStoreName: integrationTestCacheName, + }; +} + export function SetupLeaderboardIntegrationTest(): { leaderboardClient: PreviewLeaderboardClient; leaderboardClientWithThrowOnErrors: PreviewLeaderboardClient; diff --git a/packages/client-sdk-nodejs/test/integration/shared/storage.test.ts b/packages/client-sdk-nodejs/test/integration/shared/storage.test.ts new file mode 100644 index 000000000..90db8082c --- /dev/null +++ b/packages/client-sdk-nodejs/test/integration/shared/storage.test.ts @@ -0,0 +1,5 @@ +import {runStorageServiceTests} from '@gomomento/common-integration-tests'; +import {SetupStorageIntegrationTest} from '../integration-setup'; + +const {storageClient, integrationTestStoreName} = SetupStorageIntegrationTest(); +runStorageServiceTests(storageClient, integrationTestStoreName); diff --git a/packages/client-sdk-web/src/internal/storage-data-client.ts b/packages/client-sdk-web/src/internal/storage-data-client.ts index 255e2913b..d45f1370a 100644 --- a/packages/client-sdk-web/src/internal/storage-data-client.ts +++ b/packages/client-sdk-web/src/internal/storage-data-client.ts @@ -5,7 +5,6 @@ import { StoreDelete, CredentialProvider, MomentoLogger, - UnknownError, } from '..'; import {Request, UnaryResponse} from 'grpc-web'; import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; @@ -105,16 +104,11 @@ export class StorageDataClient< }, (err, resp) => { const value = resp?.getValue(); - if (resp && value) { - switch (value.getValueCase()) { + if (resp) { + switch (value?.getValueCase()) { + case undefined: case ValueCase.VALUE_NOT_SET: { - return resolve( - new StoreGet.Error( - new UnknownError( - 'An unknown error occurred: ' + resp.toString() - ) - ) - ); + return resolve(new StoreGet.Miss()); } case ValueCase.BYTES_VALUE: { return resolve( @@ -201,7 +195,7 @@ export class StorageDataClient< ...this.clientMetadataProvider.createClientMetadata(), ...createStorageMetadata(storeName, this.deadlineMillis), }, - (err, resp) => { + (err, _resp) => { if (err) { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, @@ -249,7 +243,7 @@ export class StorageDataClient< ...this.clientMetadataProvider.createClientMetadata(), ...createStorageMetadata(storeName, this.deadlineMillis), }, - (err, resp) => { + (err, _resp) => { if (err) { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, diff --git a/packages/client-sdk-web/test/integration/integration-setup.ts b/packages/client-sdk-web/test/integration/integration-setup.ts index f7dda58e1..4f8cbb52a 100644 --- a/packages/client-sdk-web/test/integration/integration-setup.ts +++ b/packages/client-sdk-web/test/integration/integration-setup.ts @@ -9,6 +9,7 @@ import { DeleteCache, CredentialProvider, ReadConcern, + IStorageClient, } from '@gomomento/sdk-core'; import { CacheClient, @@ -18,10 +19,12 @@ import { TopicConfigurations, PreviewLeaderboardClient, LeaderboardConfigurations, + StorageConfigurations, } from '../../src'; import {ITopicClient} from '@gomomento/sdk-core/dist/src/clients/ITopicClient'; import {ICacheClient} from '@gomomento/sdk-core/dist/src/clients/ICacheClient'; import {CacheClientPropsWithConfig} from '../../src/internal/cache-client-props-with-config'; +import {StorageClient} from '../../src/storage-client'; let _credsProvider: CredentialProvider | undefined = undefined; let _sessionCredsProvider: CredentialProvider | undefined = undefined; @@ -119,6 +122,13 @@ function momentoTopicClientForTesting(): TopicClient { }); } +function momentoStorageClientForTesting(): StorageClient { + return new StorageClient({ + configuration: StorageConfigurations.Default.latest(), + credentialProvider: credsProvider(), + }); +} + function momentoTopicClientWithThrowOnErrorsForTesting(): TopicClient { return new TopicClient({ configuration: TopicConfigurations.Default.latest().withThrowOnErrors(true), @@ -222,6 +232,18 @@ export function SetupTopicIntegrationTest(): { }; } +export function SetupStorageIntegrationTest(): { + storageClient: IStorageClient; + integrationTestStoreName: string; +} { + const {integrationTestCacheName} = SetupIntegrationTest(); + const storageClient = momentoStorageClientForTesting(); + return { + storageClient, + integrationTestStoreName: integrationTestCacheName, + }; +} + export function SetupLeaderboardIntegrationTest(): { leaderboardClient: PreviewLeaderboardClient; leaderboardClientWithThrowOnErrors: PreviewLeaderboardClient; diff --git a/packages/client-sdk-web/test/integration/shared/storage.test.ts b/packages/client-sdk-web/test/integration/shared/storage.test.ts new file mode 100644 index 000000000..bfdfc72ac --- /dev/null +++ b/packages/client-sdk-web/test/integration/shared/storage.test.ts @@ -0,0 +1,6 @@ +import {runStorageServiceTests} from '@gomomento/common-integration-tests'; +import {SetupStorageIntegrationTest} from '../integration-setup'; + +const {storageClient, integrationTestStoreName} = SetupStorageIntegrationTest(); + +runStorageServiceTests(storageClient, integrationTestStoreName); diff --git a/packages/common-integration-tests/src/index.ts b/packages/common-integration-tests/src/index.ts index dd6d5c0f9..17fd8a2ca 100644 --- a/packages/common-integration-tests/src/index.ts +++ b/packages/common-integration-tests/src/index.ts @@ -13,3 +13,4 @@ export * from './update-ttl'; export * from './leaderboard-client'; export * from './webhooks'; export * from './batch-get-set'; +export * from './storage'; diff --git a/packages/common-integration-tests/src/storage.ts b/packages/common-integration-tests/src/storage.ts new file mode 100644 index 000000000..69ef60a35 --- /dev/null +++ b/packages/common-integration-tests/src/storage.ts @@ -0,0 +1,151 @@ +import { + CreateStoreResponse, + DeleteStoreResponse, + IStorageClient, + ListStoresResponse, + StoreDeleteResponse, + StoreGetResponse, + StoreSetResponse, +} from '@gomomento/sdk-core'; +import {testCacheName} from './common-int-test-utils'; +import {v4} from 'uuid'; + +export function runStorageServiceTests( + storageClient: IStorageClient, + testStoreName: string +) { + describe('#create list and delete stores', () => { + it('creates a store, lists it and makes sure it exists, and then deletes it', async () => { + const storeName = testCacheName(); + const createResponse = await storageClient.createStore(storeName); + switch (createResponse.type) { + // this is the expected response + case CreateStoreResponse.Success: { + break; + } + case CreateStoreResponse.AlreadyExists: { + throw new Error( + 'store already exists, this should not happen in this test' + ); + } + case CreateStoreResponse.Error: { + throw new Error( + `failed to create store, expected store to be able to be created, error: ${createResponse.message()} exception: ${createResponse.toString()}` + ); + } + } + + const listResponse = await storageClient.listStores(); + switch (listResponse.type) { + // this is expected response + case ListStoresResponse.Success: { + const foundStore = listResponse + .getStores() + .find(store => store.getName() === storeName); + expect(foundStore).toBeDefined(); + break; + } + case ListStoresResponse.Error: { + throw new Error( + `failed to list stores: ${listResponse.message()} ${listResponse.toString()}` + ); + } + } + + const deleteResponse = await storageClient.deleteStore(storeName); + switch (deleteResponse.type) { + // w00t + case DeleteStoreResponse.Success: { + break; + } + case DeleteStoreResponse.Error: { + throw new Error( + `failed to delete store: ${deleteResponse.message()} ${deleteResponse.toString()}` + ); + } + } + }); + it('should return AlreadyExists response if trying to create a store that already exists', async () => { + const storeName = testCacheName(); + const createResponse = await storageClient.createStore(storeName); + switch (createResponse.type) { + // this is the expected response + case CreateStoreResponse.Success: { + break; + } + case CreateStoreResponse.AlreadyExists: { + break; + } + case CreateStoreResponse.Error: { + throw new Error( + `failed to create store, expected store to be able to happen, error: ${createResponse.message()} exception: ${createResponse.toString()}` + ); + } + } + const alreadyExistResponse = await storageClient.createStore(storeName); + switch (alreadyExistResponse.type) { + case CreateStoreResponse.AlreadyExists: { + break; + } + case CreateStoreResponse.Error: { + throw new Error( + `failed to create store, expected AlreadyExists response, error: ${alreadyExistResponse.message()} exception: ${alreadyExistResponse.toString()}` + ); + } + case CreateStoreResponse.Success: { + throw new Error( + 'store already exists, we should not be able to create it again' + ); + } + } + await storageClient.deleteStore(storeName); + }); + }); + describe('#store get set and delete', () => { + it('set get and delete a key in a store', async () => { + const key = v4(); + const value = v4(); + const setResponse = await storageClient.set(testStoreName, key, value); + switch (setResponse.type) { + case StoreSetResponse.Success: { + break; + } + case StoreSetResponse.Error: { + throw new Error( + `failed to set key: ${setResponse.message()} ${setResponse.toString()}` + ); + } + } + + const getResponse = await storageClient.get(testStoreName, key); + expect(getResponse.value()).toEqual(value); + const deleteResponse = await storageClient.delete(testStoreName, key); + switch (deleteResponse.type) { + case StoreDeleteResponse.Success: { + break; + } + case StoreDeleteResponse.Error: { + throw new Error( + `failed to delete key in store: ${deleteResponse.message()} ${deleteResponse.toString()}` + ); + } + } + }); + it('should return miss for a key that doesnt exist', async () => { + const key = v4(); + const getResponse = await storageClient.get(testStoreName, key); + switch (getResponse.type) { + case StoreGetResponse.Miss: { + break; + } + default: { + throw new Error( + `expected StoreGetResponse.Miss but got ${ + getResponse.type + } toString: ${getResponse.toString()}` + ); + } + } + }); + }); +} diff --git a/packages/core/src/messages/responses/enums/store/scalar/index.ts b/packages/core/src/messages/responses/enums/store/scalar/index.ts index 85c0c5fba..fda6f1911 100644 --- a/packages/core/src/messages/responses/enums/store/scalar/index.ts +++ b/packages/core/src/messages/responses/enums/store/scalar/index.ts @@ -3,6 +3,7 @@ export enum StoreGetResponse { String = 'String', Bytes = 'Bytes', Double = 'Double', + Miss = 'Miss', Error = 'Error', } diff --git a/packages/core/src/messages/responses/storage/scalar/store-get.ts b/packages/core/src/messages/responses/storage/scalar/store-get.ts index 8564dd83f..3da155589 100644 --- a/packages/core/src/messages/responses/storage/scalar/store-get.ts +++ b/packages/core/src/messages/responses/storage/scalar/store-get.ts @@ -63,6 +63,18 @@ export class BytesResponse extends ResponseBase implements IResponse { type: StoreGetResponse.Bytes; } +export class Miss extends ResponseBase implements IResponse { + constructor() { + super(); + } + + value(): undefined { + return undefined; + } + + type: StoreGetResponse.Miss; +} + /** * Indicates that an error occurred during the cache get request. * @@ -84,10 +96,10 @@ export class Error extends BaseResponseError implements IResponse { } } -export type Success = +export type Hit = | InstanceType | InstanceType | InstanceType | InstanceType; -export type Response = Success | Error; +export type Response = Hit | Miss | Error; From 0bab53e17224a5d49f0fd39f52d3995db9c02c30 Mon Sep 17 00:00:00 2001 From: Matt Straathof Date: Fri, 14 Jun 2024 10:05:19 -0700 Subject: [PATCH 04/15] fix: storage get response success/error --- .../src/config/storage-configuration.ts | 40 +++++ .../src/config/storage-configurations.ts | 1 + packages/client-sdk-nodejs/src/index.ts | 16 +- .../src/internal/storage-data-client.ts | 65 ++++--- ...ge-client.ts => preview-storage-client.ts} | 2 +- .../test/integration/integration-setup.ts | 8 +- .../src/config/storage-configuration.ts | 29 ++- .../src/config/storage-configurations.ts | 1 + packages/client-sdk-web/src/index.ts | 2 + .../src/internal/cache-data-client.ts | 2 - .../src/internal/storage-data-client.ts | 54 +++--- ...ge-client.ts => preview-storage-client.ts} | 4 +- .../src/utils/web-client-utils.ts | 4 +- .../test/integration/integration-setup.ts | 6 +- .../common-integration-tests/src/storage.ts | 24 +-- packages/core/src/clients/IStorageClient.ts | 12 +- .../clients/storage/AbstractStorageClient.ts | 12 +- .../clients/storage/IStorageDataClient.ts | 8 +- .../responses/enums/store/scalar/index.ts | 17 +- .../responses/storage/scalar/index.ts | 6 +- .../{store-delete.ts => storage-delete.ts} | 8 +- .../responses/storage/scalar/storage-get.ts | 167 ++++++++++++++++++ .../scalar/{store-set.ts => storage-set.ts} | 8 +- .../responses/storage/scalar/store-get.ts | 105 ----------- 24 files changed, 380 insertions(+), 221 deletions(-) rename packages/client-sdk-nodejs/src/{storage-client.ts => preview-storage-client.ts} (98%) rename packages/client-sdk-web/src/{storage-client.ts => preview-storage-client.ts} (97%) rename packages/core/src/messages/responses/storage/scalar/{store-delete.ts => storage-delete.ts} (78%) create mode 100644 packages/core/src/messages/responses/storage/scalar/storage-get.ts rename packages/core/src/messages/responses/storage/scalar/{store-set.ts => storage-set.ts} (79%) delete mode 100644 packages/core/src/messages/responses/storage/scalar/store-get.ts diff --git a/packages/client-sdk-nodejs/src/config/storage-configuration.ts b/packages/client-sdk-nodejs/src/config/storage-configuration.ts index 479199399..2c319cecc 100644 --- a/packages/client-sdk-nodejs/src/config/storage-configuration.ts +++ b/packages/client-sdk-nodejs/src/config/storage-configuration.ts @@ -53,6 +53,22 @@ export interface StorageConfiguration { * @returns {Configuration} a new Configuration object with the specified Middleware appended to the list of existing Middlewares */ addMiddleware(middleware: Middleware): StorageConfiguration; + + /** + * @returns {boolean} Configures whether the client should return a Momento Error object or throw an exception when an + * error occurs. By default, this is set to false, and the client will return a Momento Error object on errors. Set it + * to true if you prefer for exceptions to be thrown. + */ + getThrowOnErrors(): boolean; + + /** + * Copy constructor for configuring whether the client should return a Momento Error object or throw an exception when an + * error occurs. By default, this is set to false, and the client will return a Momento Error object on errors. Set it + * to true if you prefer for exceptions to be thrown. + * @param {boolean} throwOnErrors + * @returns {Configuration} a new Configuration object with the specified throwOnErrors setting + */ + withThrowOnErrors(throwOnErrors: boolean): StorageConfiguration; } export interface StorageConfigurationProps { @@ -69,17 +85,24 @@ export interface StorageConfigurationProps { * Configures middleware functions that will wrap each request */ middlewares: Middleware[]; + + /** + * Configures whether the client should return a Momento Error object or throw an exception when an error occurs. + */ + throwOnErrors: boolean; } export class StorageClientConfiguration implements StorageConfiguration { private readonly loggerFactory: MomentoLoggerFactory; private readonly transportStrategy: StorageTransportStrategy; private readonly middlewares: Middleware[]; + private readonly throwOnErrors: boolean; constructor(props: StorageConfigurationProps) { this.loggerFactory = props.loggerFactory; this.transportStrategy = props.transportStrategy; this.middlewares = props.middlewares; + this.throwOnErrors = props.throwOnErrors; } getLoggerFactory(): MomentoLoggerFactory { @@ -96,6 +119,7 @@ export class StorageClientConfiguration implements StorageConfiguration { transportStrategy: this.transportStrategy.withClientTimeoutMillis(clientTimeoutMillis), middlewares: this.middlewares, + throwOnErrors: this.throwOnErrors, }); } @@ -106,6 +130,7 @@ export class StorageClientConfiguration implements StorageConfiguration { loggerFactory: this.loggerFactory, transportStrategy: transportStrategy, middlewares: this.middlewares, + throwOnErrors: this.throwOnErrors, }); } @@ -118,6 +143,7 @@ export class StorageClientConfiguration implements StorageConfiguration { loggerFactory: this.loggerFactory, transportStrategy: this.transportStrategy, middlewares: middlewares, + throwOnErrors: this.throwOnErrors, }); } @@ -126,6 +152,20 @@ export class StorageClientConfiguration implements StorageConfiguration { loggerFactory: this.loggerFactory, transportStrategy: this.transportStrategy, middlewares: [middleware, ...this.middlewares], + throwOnErrors: this.throwOnErrors, }); } + + withThrowOnErrors(throwOnErrors: boolean): StorageConfiguration { + return new StorageClientConfiguration({ + loggerFactory: this.loggerFactory, + transportStrategy: this.transportStrategy, + middlewares: this.middlewares, + throwOnErrors: throwOnErrors, + }); + } + + getThrowOnErrors(): boolean { + return this.throwOnErrors; + } } diff --git a/packages/client-sdk-nodejs/src/config/storage-configurations.ts b/packages/client-sdk-nodejs/src/config/storage-configurations.ts index 68bf14e3f..00c816eec 100644 --- a/packages/client-sdk-nodejs/src/config/storage-configurations.ts +++ b/packages/client-sdk-nodejs/src/config/storage-configurations.ts @@ -60,6 +60,7 @@ export class Laptop extends StorageClientConfiguration { loggerFactory: loggerFactory, transportStrategy: transportStrategy, middlewares: defaultMiddlewares, + throwOnErrors: false, }); } } diff --git a/packages/client-sdk-nodejs/src/index.ts b/packages/client-sdk-nodejs/src/index.ts index c7e5f65a4..698c4a6dc 100644 --- a/packages/client-sdk-nodejs/src/index.ts +++ b/packages/client-sdk-nodejs/src/index.ts @@ -1,6 +1,6 @@ import {CacheClient, SimpleCacheClient} from './cache-client'; import {TopicClient} from './topic-client'; -import {StorageClient} from './storage-client'; +import {PreviewStorageClient} from './preview-storage-client'; import * as Configurations from './config/configurations'; import * as TopicConfigurations from './config/topic-configurations'; import * as StorageConfigurations from './config/storage-configurations'; @@ -79,9 +79,9 @@ import {TopicItem} from '@gomomento/sdk-core/dist/src/messages/responses/topic-i // Storage Response Types import { - StoreDelete, - StoreSet, - StoreGet, + StorageDelete, + StorageSet, + StorageGet, CreateStore, DeleteStore, ListStores, @@ -381,14 +381,14 @@ export { StorageConfigurations, StorageConfiguration, StorageClientConfiguration, - StoreSet, - StoreGet, - StoreDelete, + StorageSet, + StorageGet, + StorageDelete, CreateStore, DeleteStore, ListStores, StoreInfo, - StorageClient, + PreviewStorageClient, IStorageClient, // Webhooks PostUrlWebhookDestination, diff --git a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts index d4b6e16e0..caee093c6 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts @@ -3,9 +3,10 @@ import { InvalidArgumentError, MomentoLogger, MomentoLoggerFactory, - StoreGet, - StoreSet, - StoreDelete, + StorageGet, + StorageSet, + StorageDelete, + UnknownError, } from '@gomomento/sdk-core'; import {validateStoreName} from '@gomomento/sdk-core/dist/src/internal/utils'; import {store} from '@gomomento/generated-types/dist/store'; @@ -50,7 +51,9 @@ export class StorageDataClient implements IStorageDataClient { */ constructor(props: StorageClientPropsWithConfig, dataClientID: string) { this.configuration = props.configuration; - this.cacheServiceErrorMapper = new CacheServiceErrorMapper(false); + this.cacheServiceErrorMapper = new CacheServiceErrorMapper( + props.configuration.getThrowOnErrors() + ); this.credentialProvider = props.credentialProvider; this.logger = this.configuration.getLoggerFactory().getLogger(this); this.requestTimeoutMs = this.configuration @@ -133,17 +136,20 @@ export class StorageDataClient implements IStorageDataClient { private createMetadata(storeName: string): Metadata { const metadata = new Metadata(); - metadata.set('storage', storeName); + metadata.set('store', storeName); return metadata; } - public async get(storeName: string, key: string): Promise { + public async get( + storeName: string, + key: string + ): Promise { try { validateStoreName(storeName); } catch (err) { return this.cacheServiceErrorMapper.returnOrThrowError( err as Error, - err => new StoreGet.Error(err) + err => new StorageGet.Error(err) ); } this.logger.trace( @@ -155,7 +161,7 @@ export class StorageDataClient implements IStorageDataClient { private async sendGet( storeName: string, key: string - ): Promise { + ): Promise { const request = new store._StoreGetRequest({ key: key, }); @@ -168,36 +174,43 @@ export class StorageDataClient implements IStorageDataClient { interceptors: this.interceptors, }, (err: ServiceError | null, resp) => { - if (resp) { - switch (resp.value.value) { + const value = resp?.value?.value; + if (value) { + switch (value) { case 'double_value': { return resolve( - new StoreGet.DoubleResponse(resp.value.double_value) + new StorageGet.DoubleResponse(resp.value.double_value) ); } case 'string_value': { return resolve( - new StoreGet.StringResponse(resp.value.string_value) + new StorageGet.StringResponse(resp.value.string_value) ); } case 'bytes_value': { return resolve( - new StoreGet.BytesResponse(resp.value.bytes_value) + new StorageGet.BytesResponse(resp.value.bytes_value) ); } case 'integer_value': { return resolve( - new StoreGet.IntegerResponse(resp.value.integer_value) + new StorageGet.IntegerResponse(resp.value.integer_value) ); } case 'none': { - return resolve(new StoreGet.Miss()); + return resolve( + new StorageGet.Error( + new UnknownError( + 'StorageGet responded with an unknown result' + ) + ) + ); } } } else { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StoreGet.Error(e), + errorResponseFactoryFn: e => new StorageGet.Error(e), resolveFn: resolve, rejectFn: reject, }); @@ -211,13 +224,13 @@ export class StorageDataClient implements IStorageDataClient { storeName: string, key: string, value: string | Uint8Array | number - ): Promise { + ): Promise { try { validateStoreName(storeName); } catch (err) { return this.cacheServiceErrorMapper.returnOrThrowError( err as Error, - err => new StoreSet.Error(err) + err => new StorageSet.Error(err) ); } this.logger.trace( @@ -230,7 +243,7 @@ export class StorageDataClient implements IStorageDataClient { storeName: string, key: string, value: string | Uint8Array | number - ): Promise { + ): Promise { const storeValue = new store._StoreValue(); if (typeof value === 'string') { storeValue.string_value = value; @@ -257,11 +270,11 @@ export class StorageDataClient implements IStorageDataClient { }, (err: ServiceError | null, resp) => { if (resp) { - resolve(new StoreSet.Success()); + resolve(new StorageSet.Success()); } else { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StoreSet.Error(e), + errorResponseFactoryFn: e => new StorageSet.Error(e), resolveFn: resolve, rejectFn: reject, }); @@ -274,13 +287,13 @@ export class StorageDataClient implements IStorageDataClient { public async delete( storeName: string, key: string - ): Promise { + ): Promise { try { validateStoreName(storeName); } catch (err) { return this.cacheServiceErrorMapper.returnOrThrowError( err as Error, - err => new StoreDelete.Error(err) + err => new StorageDelete.Error(err) ); } this.logger.trace( @@ -292,7 +305,7 @@ export class StorageDataClient implements IStorageDataClient { private async sendDelete( storeName: string, key: string - ): Promise { + ): Promise { const request = new store._StoreDeleteRequest({ key: key, }); @@ -306,11 +319,11 @@ export class StorageDataClient implements IStorageDataClient { }, (err: ServiceError | null, resp) => { if (resp) { - resolve(new StoreDelete.Success()); + resolve(new StorageDelete.Success()); } else { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StoreDelete.Error(e), + errorResponseFactoryFn: e => new StorageDelete.Error(e), resolveFn: resolve, rejectFn: reject, }); diff --git a/packages/client-sdk-nodejs/src/storage-client.ts b/packages/client-sdk-nodejs/src/preview-storage-client.ts similarity index 98% rename from packages/client-sdk-nodejs/src/storage-client.ts rename to packages/client-sdk-nodejs/src/preview-storage-client.ts index 9a83a7a56..503b24c62 100644 --- a/packages/client-sdk-nodejs/src/storage-client.ts +++ b/packages/client-sdk-nodejs/src/preview-storage-client.ts @@ -11,7 +11,7 @@ import {StorageDataClient} from './internal/storage-data-client'; import {StorageConfiguration} from './config/storage-configuration'; import {StorageConfigurations} from './index'; -export class StorageClient +export class PreviewStorageClient extends AbstractStorageClient implements IStorageClient { diff --git a/packages/client-sdk-nodejs/test/integration/integration-setup.ts b/packages/client-sdk-nodejs/test/integration/integration-setup.ts index 5e39ca3c1..e02b1bd9e 100644 --- a/packages/client-sdk-nodejs/test/integration/integration-setup.ts +++ b/packages/client-sdk-nodejs/test/integration/integration-setup.ts @@ -11,7 +11,7 @@ import { TopicClient, PreviewLeaderboardClient, LeaderboardConfigurations, - StorageClient, + PreviewStorageClient, StorageConfigurations, } from '../../src'; import {ICacheClient} from '@gomomento/sdk-core/dist/src/clients/ICacheClient'; @@ -137,8 +137,8 @@ function momentoTopicClientForTesting(): TopicClient { }); } -function momentoStorageClientForTesting(): StorageClient { - return new StorageClient({ +function momentoStorageClientForTesting(): PreviewStorageClient { + return new PreviewStorageClient({ configuration: StorageConfigurations.Laptop.latest(), credentialProvider: integrationTestCacheClientProps().credentialProvider, }); @@ -236,7 +236,7 @@ export function SetupTopicIntegrationTest(): { } export function SetupStorageIntegrationTest(): { - storageClient: StorageClient; + storageClient: PreviewStorageClient; integrationTestStoreName: string; } { const {integrationTestCacheName} = SetupIntegrationTest(); diff --git a/packages/client-sdk-web/src/config/storage-configuration.ts b/packages/client-sdk-web/src/config/storage-configuration.ts index 11d92afa7..ed5ef07c0 100644 --- a/packages/client-sdk-web/src/config/storage-configuration.ts +++ b/packages/client-sdk-web/src/config/storage-configuration.ts @@ -5,6 +5,11 @@ export interface StorageConfigurationProps { * Configures logging verbosity and format */ loggerFactory: MomentoLoggerFactory; + + /** + * Configures whether the client should return a Momento Error object or throw an exception when an error occurs. + */ + throwOnErrors: boolean; } /** @@ -20,16 +25,29 @@ export interface StorageConfiguration { getLoggerFactory(): MomentoLoggerFactory; /** - * @returns {boolean} Configures whether the client should return a Momento Error object or throw an exception when an error occurs. By default, this is set to false, and the client will return a Momento Error object on errors. Set it to true if you prefer for exceptions to be thrown. + * @returns {boolean} Configures whether the client should return a Momento Error object or throw an exception when an + * error occurs. By default, this is set to false, and the client will return a Momento Error object on errors. Set it + * to true if you prefer for exceptions to be thrown. */ getThrowOnErrors(): boolean; + + /** + * Copy constructor for configuring whether the client should return a Momento Error object or throw an exception when an + * error occurs. By default, this is set to false, and the client will return a Momento Error object on errors. Set it + * to true if you prefer for exceptions to be thrown. + * @param {boolean} throwOnErrors + * @returns {Configuration} a new Configuration object with the specified throwOnErrors setting + */ + withThrowOnErrors(throwOnErrors: boolean): StorageConfiguration; } export class StorageClientConfiguration implements StorageConfiguration { private readonly loggerFactory: MomentoLoggerFactory; + private readonly throwOnErrors: boolean; constructor(props: StorageConfigurationProps) { this.loggerFactory = props.loggerFactory; + this.throwOnErrors = props.throwOnErrors; } getLoggerFactory(): MomentoLoggerFactory { @@ -37,6 +55,13 @@ export class StorageClientConfiguration implements StorageConfiguration { } getThrowOnErrors(): boolean { - return false; + return this.throwOnErrors; + } + + withThrowOnErrors(throwOnErrors: boolean): StorageConfiguration { + return new StorageClientConfiguration({ + loggerFactory: this.loggerFactory, + throwOnErrors: throwOnErrors, + }); } } diff --git a/packages/client-sdk-web/src/config/storage-configurations.ts b/packages/client-sdk-web/src/config/storage-configurations.ts index b460aa3c8..944ba38bd 100644 --- a/packages/client-sdk-web/src/config/storage-configurations.ts +++ b/packages/client-sdk-web/src/config/storage-configurations.ts @@ -25,6 +25,7 @@ export class Default extends StorageClientConfiguration { ): StorageConfiguration { return new StorageClientConfiguration({ loggerFactory: loggerFactory, + throwOnErrors: false, }); } } diff --git a/packages/client-sdk-web/src/index.ts b/packages/client-sdk-web/src/index.ts index a63c10908..4d524039b 100644 --- a/packages/client-sdk-web/src/index.ts +++ b/packages/client-sdk-web/src/index.ts @@ -2,6 +2,7 @@ import {CacheClient} from './cache-client'; import {AuthClient} from './auth-client'; import {TopicClient} from './topic-client'; import {PreviewLeaderboardClient} from './preview-leaderboard-client'; +import {PreviewStorageClient} from './preview-storage-client'; import * as Configurations from './config/configurations'; import * as TopicConfigurations from './config/topic-configurations'; import * as LeaderboardConfigurations from './config/leaderboard-configurations'; @@ -330,4 +331,5 @@ export { // Storage StoreInfo, StorageConfigurations, + PreviewStorageClient, }; diff --git a/packages/client-sdk-web/src/internal/cache-data-client.ts b/packages/client-sdk-web/src/internal/cache-data-client.ts index cc768be61..72c3303cb 100644 --- a/packages/client-sdk-web/src/internal/cache-data-client.ts +++ b/packages/client-sdk-web/src/internal/cache-data-client.ts @@ -96,8 +96,6 @@ import { _ListRetainRequest, _SetDifferenceRequest, _SetFetchRequest, - _SetIfNotExistsRequest, - _SetIfNotExistsResponse, _SetIfRequest, _SetIfResponse, _SetRequest, diff --git a/packages/client-sdk-web/src/internal/storage-data-client.ts b/packages/client-sdk-web/src/internal/storage-data-client.ts index d45f1370a..10a6f1c37 100644 --- a/packages/client-sdk-web/src/internal/storage-data-client.ts +++ b/packages/client-sdk-web/src/internal/storage-data-client.ts @@ -1,10 +1,11 @@ import {store} from '@gomomento/generated-types-webtext'; import { - StoreGet, - StoreSet, - StoreDelete, + StorageGet, + StorageSet, + StorageDelete, CredentialProvider, MomentoLogger, + UnknownError, } from '..'; import {Request, UnaryResponse} from 'grpc-web'; import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; @@ -73,13 +74,16 @@ export class StorageDataClient< // by both nodejs and web SDKs } - public async get(storeName: string, key: string): Promise { + public async get( + storeName: string, + key: string + ): Promise { try { validateStoreName(storeName); } catch (err) { return this.cacheServiceErrorMapper.returnOrThrowError( err as Error, - err => new StoreGet.Error(err) + err => new StorageGet.Error(err) ); } this.logger.trace(`Issuing 'get' request; key: ${key.toString()}`); @@ -91,7 +95,7 @@ export class StorageDataClient< private async sendGet( storeName: string, key: string - ): Promise { + ): Promise { const request = new _StoreGetRequest(); request.setKey(key); @@ -108,33 +112,39 @@ export class StorageDataClient< switch (value?.getValueCase()) { case undefined: case ValueCase.VALUE_NOT_SET: { - return resolve(new StoreGet.Miss()); + return resolve( + new StorageGet.Error( + new UnknownError( + 'StorageGet responded with an unknown result' + ) + ) + ); } case ValueCase.BYTES_VALUE: { return resolve( - new StoreGet.BytesResponse(value.getBytesValue_asU8()) + new StorageGet.BytesResponse(value.getBytesValue_asU8()) ); } case ValueCase.STRING_VALUE: { return resolve( - new StoreGet.StringResponse(value.getStringValue()) + new StorageGet.StringResponse(value.getStringValue()) ); } case ValueCase.INTEGER_VALUE: { return resolve( - new StoreGet.IntegerResponse(value.getIntegerValue()) + new StorageGet.IntegerResponse(value.getIntegerValue()) ); } case ValueCase.DOUBLE_VALUE: { return resolve( - new StoreGet.DoubleResponse(value.getDoubleValue()) + new StorageGet.DoubleResponse(value.getDoubleValue()) ); } } } else { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StoreGet.Error(e), + errorResponseFactoryFn: e => new StorageGet.Error(e), resolveFn: resolve, rejectFn: reject, }); @@ -148,13 +158,13 @@ export class StorageDataClient< storeName: string, key: string, value: string | number | Uint8Array - ): Promise { + ): Promise { try { validateStoreName(storeName); } catch (err) { return this.cacheServiceErrorMapper.returnOrThrowError( err as Error, - err => new StoreSet.Error(err) + err => new StorageSet.Error(err) ); } this.logger.trace(`Issuing 'set' request; key: ${key.toString()}`); @@ -171,7 +181,7 @@ export class StorageDataClient< storeName: string, key: string, passedInVal: string | number | Uint8Array - ): Promise { + ): Promise { const request = new _StoreSetRequest(); request.setKey(key); @@ -199,12 +209,12 @@ export class StorageDataClient< if (err) { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StoreSet.Error(e), + errorResponseFactoryFn: e => new StorageSet.Error(e), resolveFn: resolve, rejectFn: reject, }); } else { - resolve(new StoreSet.Success()); + resolve(new StorageSet.Success()); } } ); @@ -214,13 +224,13 @@ export class StorageDataClient< public async delete( storeName: string, key: string - ): Promise { + ): Promise { try { validateStoreName(storeName); } catch (err) { return this.cacheServiceErrorMapper.returnOrThrowError( err as Error, - err => new StoreDelete.Error(err) + err => new StorageDelete.Error(err) ); } this.logger.trace(`Issuing 'delete' request; key: ${key.toString()}`); @@ -232,7 +242,7 @@ export class StorageDataClient< private async sendDelete( storeName: string, key: string - ): Promise { + ): Promise { const request = new _StoreDeleteRequest(); request.setKey(key); @@ -247,12 +257,12 @@ export class StorageDataClient< if (err) { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StoreDelete.Error(e), + errorResponseFactoryFn: e => new StorageDelete.Error(e), resolveFn: resolve, rejectFn: reject, }); } else { - resolve(new StoreDelete.Success()); + resolve(new StorageDelete.Success()); } } ); diff --git a/packages/client-sdk-web/src/storage-client.ts b/packages/client-sdk-web/src/preview-storage-client.ts similarity index 97% rename from packages/client-sdk-web/src/storage-client.ts rename to packages/client-sdk-web/src/preview-storage-client.ts index bc33fa9e4..54fa30c7d 100644 --- a/packages/client-sdk-web/src/storage-client.ts +++ b/packages/client-sdk-web/src/preview-storage-client.ts @@ -14,7 +14,7 @@ interface StorageClientPropsWithConfiguration extends StorageClientProps { configuration: StorageConfiguration; } -export class StorageClient +export class PreviewStorageClient extends AbstractStorageClient implements IStorageClient { @@ -46,7 +46,7 @@ export class StorageClient * * @readonly * @type {StorageConfiguration} the configuration used by this client - * @memberof StorageClient + * @memberof PreviewStorageClient */ public get configuration(): StorageConfiguration { return this._configuration; diff --git a/packages/client-sdk-web/src/utils/web-client-utils.ts b/packages/client-sdk-web/src/utils/web-client-utils.ts index 0ea3a570d..3c621dd74 100644 --- a/packages/client-sdk-web/src/utils/web-client-utils.ts +++ b/packages/client-sdk-web/src/utils/web-client-utils.ts @@ -39,9 +39,9 @@ export function createCallMetadata( export function createStorageMetadata( storeName: string, timeoutMillis: number -): {storage: string; deadline: string} { +): {store: string; deadline: string} { const deadline = Date.now() + timeoutMillis; - return {storage: storeName, deadline: deadline.toString()}; + return {store: storeName, deadline: deadline.toString()}; } export function getWebControlEndpoint( diff --git a/packages/client-sdk-web/test/integration/integration-setup.ts b/packages/client-sdk-web/test/integration/integration-setup.ts index 4f8cbb52a..c63735b7a 100644 --- a/packages/client-sdk-web/test/integration/integration-setup.ts +++ b/packages/client-sdk-web/test/integration/integration-setup.ts @@ -20,11 +20,11 @@ import { PreviewLeaderboardClient, LeaderboardConfigurations, StorageConfigurations, + PreviewStorageClient, } from '../../src'; import {ITopicClient} from '@gomomento/sdk-core/dist/src/clients/ITopicClient'; import {ICacheClient} from '@gomomento/sdk-core/dist/src/clients/ICacheClient'; import {CacheClientPropsWithConfig} from '../../src/internal/cache-client-props-with-config'; -import {StorageClient} from '../../src/storage-client'; let _credsProvider: CredentialProvider | undefined = undefined; let _sessionCredsProvider: CredentialProvider | undefined = undefined; @@ -122,8 +122,8 @@ function momentoTopicClientForTesting(): TopicClient { }); } -function momentoStorageClientForTesting(): StorageClient { - return new StorageClient({ +function momentoStorageClientForTesting(): PreviewStorageClient { + return new PreviewStorageClient({ configuration: StorageConfigurations.Default.latest(), credentialProvider: credsProvider(), }); diff --git a/packages/common-integration-tests/src/storage.ts b/packages/common-integration-tests/src/storage.ts index 69ef60a35..64144a7c1 100644 --- a/packages/common-integration-tests/src/storage.ts +++ b/packages/common-integration-tests/src/storage.ts @@ -3,9 +3,10 @@ import { DeleteStoreResponse, IStorageClient, ListStoresResponse, - StoreDeleteResponse, - StoreGetResponse, - StoreSetResponse, + MomentoErrorCode, + StorageDeleteResponse, + StorageGetResponse, + StorageSetResponse, } from '@gomomento/sdk-core'; import {testCacheName} from './common-int-test-utils'; import {v4} from 'uuid'; @@ -107,10 +108,10 @@ export function runStorageServiceTests( const value = v4(); const setResponse = await storageClient.set(testStoreName, key, value); switch (setResponse.type) { - case StoreSetResponse.Success: { + case StorageSetResponse.Success: { break; } - case StoreSetResponse.Error: { + case StorageSetResponse.Error: { throw new Error( `failed to set key: ${setResponse.message()} ${setResponse.toString()}` ); @@ -121,26 +122,29 @@ export function runStorageServiceTests( expect(getResponse.value()).toEqual(value); const deleteResponse = await storageClient.delete(testStoreName, key); switch (deleteResponse.type) { - case StoreDeleteResponse.Success: { + case StorageDeleteResponse.Success: { break; } - case StoreDeleteResponse.Error: { + case StorageDeleteResponse.Error: { throw new Error( `failed to delete key in store: ${deleteResponse.message()} ${deleteResponse.toString()}` ); } } }); - it('should return miss for a key that doesnt exist', async () => { + it('should return not found error for a key that doesnt exist', async () => { const key = v4(); const getResponse = await storageClient.get(testStoreName, key); switch (getResponse.type) { - case StoreGetResponse.Miss: { + case StorageGetResponse.Error: { + expect(getResponse.errorCode()).toEqual( + MomentoErrorCode.NOT_FOUND_ERROR + ); break; } default: { throw new Error( - `expected StoreGetResponse.Miss but got ${ + `expected StoreGetResponse.Error but got ${ getResponse.type } toString: ${getResponse.toString()}` ); diff --git a/packages/core/src/clients/IStorageClient.ts b/packages/core/src/clients/IStorageClient.ts index cdd6979bc..9c127e96b 100644 --- a/packages/core/src/clients/IStorageClient.ts +++ b/packages/core/src/clients/IStorageClient.ts @@ -2,22 +2,22 @@ import { CreateStore, ListStores, DeleteStore, - StoreSet, - StoreGet, - StoreDelete, + StorageSet, + StorageGet, + StorageDelete, } from '../index'; export interface IStorageClient { createStore(storeName: string): Promise; listStores(): Promise; deleteStore(cache: string): Promise; - get(storeName: string, key: string): Promise; + get(storeName: string, key: string): Promise; set( storeName: string, key: string, value: string | Uint8Array | number - ): Promise; - delete(storeName: string, key: string): Promise; + ): Promise; + delete(storeName: string, key: string): Promise; close(): void; } diff --git a/packages/core/src/internal/clients/storage/AbstractStorageClient.ts b/packages/core/src/internal/clients/storage/AbstractStorageClient.ts index fd041d50e..7f427b6f0 100644 --- a/packages/core/src/internal/clients/storage/AbstractStorageClient.ts +++ b/packages/core/src/internal/clients/storage/AbstractStorageClient.ts @@ -2,9 +2,9 @@ import { CreateStore, DeleteStore, ListStores, - StoreGet, - StoreSet, - StoreDelete, + StorageGet, + StorageSet, + StorageDelete, } from '../../../index'; import {IStorageDataClient} from './IStorageDataClient'; import {IStorageClient} from '../../../clients/IStorageClient'; @@ -40,7 +40,7 @@ export abstract class AbstractStorageClient implements IStorageClient { return this.controlClient.deleteStore(storeName); } - get(storeName: string, key: string): Promise { + get(storeName: string, key: string): Promise { return this.getNextDataClient().get(storeName, key); } @@ -48,11 +48,11 @@ export abstract class AbstractStorageClient implements IStorageClient { storeName: string, key: string, value: string | Uint8Array | number - ): Promise { + ): Promise { return this.getNextDataClient().set(storeName, key, value); } - delete(storeName: string, key: string): Promise { + delete(storeName: string, key: string): Promise { return this.getNextDataClient().delete(storeName, key); } diff --git a/packages/core/src/internal/clients/storage/IStorageDataClient.ts b/packages/core/src/internal/clients/storage/IStorageDataClient.ts index dc4ac46de..2f258682b 100644 --- a/packages/core/src/internal/clients/storage/IStorageDataClient.ts +++ b/packages/core/src/internal/clients/storage/IStorageDataClient.ts @@ -1,12 +1,12 @@ -import {StoreGet, StoreSet, StoreDelete} from '../../../index'; +import {StorageGet, StorageSet, StorageDelete} from '../../../index'; export interface IStorageDataClient { - get(storeName: string, key: string): Promise; + get(storeName: string, key: string): Promise; set( storeName: string, key: string, value: string | number | Uint8Array - ): Promise; - delete(storeName: string, key: string): Promise; + ): Promise; + delete(storeName: string, key: string): Promise; close(): void; } diff --git a/packages/core/src/messages/responses/enums/store/scalar/index.ts b/packages/core/src/messages/responses/enums/store/scalar/index.ts index fda6f1911..3c3f32bfc 100644 --- a/packages/core/src/messages/responses/enums/store/scalar/index.ts +++ b/packages/core/src/messages/responses/enums/store/scalar/index.ts @@ -1,18 +1,21 @@ -export enum StoreGetResponse { - Integer = 'Integer', +export enum StorageGetResponse { + Success = 'Success', + Error = 'Error', +} + +export enum StorageItemType { String = 'String', - Bytes = 'Bytes', + Integer = 'Integer', Double = 'Double', - Miss = 'Miss', - Error = 'Error', + Bytes = 'Bytes', } -export enum StoreSetResponse { +export enum StorageSetResponse { Success = 'Success', Error = 'Error', } -export enum StoreDeleteResponse { +export enum StorageDeleteResponse { Success = 'Success', Error = 'Error', } diff --git a/packages/core/src/messages/responses/storage/scalar/index.ts b/packages/core/src/messages/responses/storage/scalar/index.ts index b6c65f1ee..3da735263 100644 --- a/packages/core/src/messages/responses/storage/scalar/index.ts +++ b/packages/core/src/messages/responses/storage/scalar/index.ts @@ -1,3 +1,3 @@ -export * as StoreDelete from './store-delete'; -export * as StoreGet from './store-get'; -export * as StoreSet from './store-set'; +export * as StorageDelete from './storage-delete'; +export * as StorageGet from './storage-get'; +export * as StorageSet from './storage-set'; diff --git a/packages/core/src/messages/responses/storage/scalar/store-delete.ts b/packages/core/src/messages/responses/storage/scalar/storage-delete.ts similarity index 78% rename from packages/core/src/messages/responses/storage/scalar/store-delete.ts rename to packages/core/src/messages/responses/storage/scalar/storage-delete.ts index 5da16fd61..e6f4426dd 100644 --- a/packages/core/src/messages/responses/storage/scalar/store-delete.ts +++ b/packages/core/src/messages/responses/storage/scalar/storage-delete.ts @@ -1,16 +1,16 @@ -import {StoreDeleteResponse} from '../../enums'; +import {StorageDeleteResponse} from '../../enums'; import {BaseResponseError, BaseResponseSuccess} from '../../response-base'; import {SdkError} from '../../../../errors'; interface IResponse { - readonly type: StoreDeleteResponse; + readonly type: StorageDeleteResponse; } /** * Indicates a Successful store delete request. */ export class Success extends BaseResponseSuccess implements IResponse { - readonly type: StoreDeleteResponse.Success = StoreDeleteResponse.Success; + readonly type: StorageDeleteResponse.Success = StorageDeleteResponse.Success; } /** @@ -28,7 +28,7 @@ export class Error extends BaseResponseError implements IResponse { super(_innerException); } - readonly type: StoreDeleteResponse.Error = StoreDeleteResponse.Error; + readonly type: StorageDeleteResponse.Error = StorageDeleteResponse.Error; } export type Response = Success | Error; diff --git a/packages/core/src/messages/responses/storage/scalar/storage-get.ts b/packages/core/src/messages/responses/storage/scalar/storage-get.ts new file mode 100644 index 000000000..1b307b310 --- /dev/null +++ b/packages/core/src/messages/responses/storage/scalar/storage-get.ts @@ -0,0 +1,167 @@ +import {StorageItemType, StorageGetResponse} from '../../enums'; +import {BaseResponseError, ResponseBase} from '../../response-base'; +import {SdkError} from '../../../../errors'; + +interface IResponse { + readonly type: StorageGetResponse; + value(): string | number | Uint8Array | undefined; +} + +export abstract class Success extends ResponseBase implements IResponse { + readonly type: StorageGetResponse.Success; + readonly itemType: StorageItemType; + + abstract value(): string | number | Uint8Array; + + abstract intValue(): number | undefined; + + abstract doubleValue(): number | undefined; + + abstract stringValue(): string | undefined; + + abstract bytesValue(): Uint8Array | undefined; +} + +export class StringResponse extends Success { + override readonly itemType: StorageItemType.String = StorageItemType.String; + private readonly _value: string; + constructor(value: string) { + super(); + this._value = value; + } + + value(): string { + return this._value; + } + + bytesValue(): undefined { + return undefined; + } + + doubleValue(): undefined { + return undefined; + } + + intValue(): undefined { + return undefined; + } + + stringValue(): string { + return this.value(); + } +} + +export class IntegerResponse extends Success { + override readonly itemType: StorageItemType.Integer = StorageItemType.Integer; + private readonly _value: number; + constructor(value: number) { + super(); + this._value = value; + } + + value(): number { + return this._value; + } + + bytesValue(): undefined { + return undefined; + } + + doubleValue(): undefined { + return undefined; + } + + intValue(): number | undefined { + return this.value(); + } + + stringValue(): undefined { + return undefined; + } +} + +export class DoubleResponse extends Success { + override readonly itemType: StorageItemType.Double = StorageItemType.Double; + private readonly _value: number; + constructor(value: number) { + super(); + this._value = value; + } + + value(): number { + return this._value; + } + + bytesValue(): undefined { + return undefined; + } + + doubleValue(): number { + return this.value(); + } + + intValue(): undefined { + return undefined; + } + + stringValue(): undefined { + return undefined; + } +} + +export class BytesResponse extends Success { + override readonly itemType: StorageItemType.Bytes = StorageItemType.Bytes; + private readonly _value: Uint8Array; + constructor(value: Uint8Array) { + super(); + this._value = value; + } + + value(): Uint8Array { + return this._value; + } + + bytesValue(): Uint8Array { + return this.value(); + } + + doubleValue(): undefined { + return undefined; + } + + intValue(): undefined { + return undefined; + } + + stringValue(): undefined { + return undefined; + } +} + +/** + * Indicates that an error occurred during the cache get request. + * + * This response object includes the following fields that you can use to determine + * how you would like to handle the error: + * + * - `errorCode()` - a unique Momento error code indicating the type of error that occurred. + * - `message()` - a human-readable description of the error + * - `innerException()` - the original error that caused the failure; can be re-thrown. + */ +export class Error extends BaseResponseError implements IResponse { + readonly type: StorageGetResponse.Error = StorageGetResponse.Error; + constructor(_innerException: SdkError) { + super(_innerException); + } + + value(): undefined { + return undefined; + } +} + +export type Response = + | DoubleResponse + | BytesResponse + | StringResponse + | IntegerResponse + | Error; diff --git a/packages/core/src/messages/responses/storage/scalar/store-set.ts b/packages/core/src/messages/responses/storage/scalar/storage-set.ts similarity index 79% rename from packages/core/src/messages/responses/storage/scalar/store-set.ts rename to packages/core/src/messages/responses/storage/scalar/storage-set.ts index f9c510c00..40fe71be3 100644 --- a/packages/core/src/messages/responses/storage/scalar/store-set.ts +++ b/packages/core/src/messages/responses/storage/scalar/storage-set.ts @@ -1,16 +1,16 @@ -import {StoreSetResponse} from '../../enums'; +import {StorageSetResponse} from '../../enums'; import {BaseResponseError, BaseResponseSuccess} from '../../response-base'; import {SdkError} from '../../../../errors'; interface IResponse { - readonly type: StoreSetResponse; + readonly type: StorageSetResponse; } /** * Indicates a Successful store set request. */ export class Success extends BaseResponseSuccess implements IResponse { - readonly type: StoreSetResponse.Success = StoreSetResponse.Success; + readonly type: StorageSetResponse.Success = StorageSetResponse.Success; } /** @@ -28,7 +28,7 @@ export class Error extends BaseResponseError implements IResponse { super(_innerException); } - readonly type: StoreSetResponse.Error = StoreSetResponse.Error; + readonly type: StorageSetResponse.Error = StorageSetResponse.Error; } export type Response = Success | Error; diff --git a/packages/core/src/messages/responses/storage/scalar/store-get.ts b/packages/core/src/messages/responses/storage/scalar/store-get.ts deleted file mode 100644 index 3da155589..000000000 --- a/packages/core/src/messages/responses/storage/scalar/store-get.ts +++ /dev/null @@ -1,105 +0,0 @@ -import {StoreGetResponse} from '../../enums'; -import {BaseResponseError, ResponseBase} from '../../response-base'; -import {SdkError} from '../../../../errors'; - -interface IResponse { - type: StoreGetResponse; - value(): string | number | Uint8Array | undefined; -} - -export class StringResponse extends ResponseBase implements IResponse { - private readonly _value: string; - constructor(value: string) { - super(); - this._value = value; - } - - value(): string { - return this._value; - } - - type: StoreGetResponse.String; -} - -export class IntegerResponse extends ResponseBase implements IResponse { - private readonly _value: number; - constructor(value: number) { - super(); - this._value = value; - } - - value(): number { - return this._value; - } - - type: StoreGetResponse.Integer; -} - -export class DoubleResponse extends ResponseBase implements IResponse { - private readonly _value: number; - constructor(value: number) { - super(); - this._value = value; - } - - value(): number { - return this._value; - } - - type: StoreGetResponse.Double; -} - -export class BytesResponse extends ResponseBase implements IResponse { - private readonly _value: Uint8Array; - constructor(value: Uint8Array) { - super(); - this._value = value; - } - - value(): Uint8Array { - return this._value; - } - - type: StoreGetResponse.Bytes; -} - -export class Miss extends ResponseBase implements IResponse { - constructor() { - super(); - } - - value(): undefined { - return undefined; - } - - type: StoreGetResponse.Miss; -} - -/** - * Indicates that an error occurred during the cache get request. - * - * This response object includes the following fields that you can use to determine - * how you would like to handle the error: - * - * - `errorCode()` - a unique Momento error code indicating the type of error that occurred. - * - `message()` - a human-readable description of the error - * - `innerException()` - the original error that caused the failure; can be re-thrown. - */ -export class Error extends BaseResponseError implements IResponse { - readonly type: StoreGetResponse.Error = StoreGetResponse.Error; - constructor(_innerException: SdkError) { - super(_innerException); - } - - value(): undefined { - return undefined; - } -} - -export type Hit = - | InstanceType - | InstanceType - | InstanceType - | InstanceType; - -export type Response = Hit | Miss | Error; From 7ccafa99c11da521972239e7ea869ec31b13beeb Mon Sep 17 00:00:00 2001 From: Matt Straathof Date: Fri, 14 Jun 2024 10:50:04 -0700 Subject: [PATCH 05/15] feat: storeageSet -> storagePut --- packages/client-sdk-nodejs/package-lock.json | 8 +++---- packages/client-sdk-nodejs/package.json | 2 +- packages/client-sdk-nodejs/src/index.ts | 4 ++-- .../src/internal/storage-data-client.ts | 22 ++++++++--------- packages/client-sdk-web/package-lock.json | 10 ++++---- packages/client-sdk-web/package.json | 2 +- .../src/internal/storage-data-client.ts | 24 +++++++++---------- .../common-integration-tests/src/storage.ts | 16 ++++++------- packages/core/src/clients/IStorageClient.ts | 6 ++--- .../clients/storage/AbstractStorageClient.ts | 8 +++---- .../clients/storage/IStorageDataClient.ts | 6 ++--- .../responses/enums/store/scalar/index.ts | 2 +- .../responses/storage/scalar/index.ts | 2 +- .../scalar/{storage-set.ts => storage-put.ts} | 8 +++---- 14 files changed, 61 insertions(+), 59 deletions(-) rename packages/core/src/messages/responses/storage/scalar/{storage-set.ts => storage-put.ts} (81%) diff --git a/packages/client-sdk-nodejs/package-lock.json b/packages/client-sdk-nodejs/package-lock.json index 0157d6d22..08c67b75d 100644 --- a/packages/client-sdk-nodejs/package-lock.json +++ b/packages/client-sdk-nodejs/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.1", "license": "Apache-2.0", "dependencies": { - "@gomomento/generated-types": "0.112.1", + "@gomomento/generated-types": "0.113.0", "@gomomento/sdk-core": "file:../core", "@grpc/grpc-js": "1.10.9", "@types/google-protobuf": "3.15.10", @@ -831,9 +831,9 @@ "link": true }, "node_modules/@gomomento/generated-types": { - "version": "0.112.1", - "resolved": "https://registry.npmjs.org/@gomomento/generated-types/-/generated-types-0.112.1.tgz", - "integrity": "sha512-le50ESGkRz6dUSqV0CmQXm6fIdnYJgj5c9iEM68xJ4nqqkkkXsSOPgCvRZQPRzdz3v+c3OR4/kS0zhAXEIL16w==", + "version": "0.113.0", + "resolved": "https://registry.npmjs.org/@gomomento/generated-types/-/generated-types-0.113.0.tgz", + "integrity": "sha512-7DJdcNWzCT5dpp1W+Vb77RZfamCt/SbtvoOcDtSDVU/wAsK7y7Yeo88DkgqiD2sCHv/u5X3wgLye51dlCsbgDw==", "dependencies": { "@grpc/grpc-js": "1.10.9", "google-protobuf": "3.21.2", diff --git a/packages/client-sdk-nodejs/package.json b/packages/client-sdk-nodejs/package.json index 6a6d06008..cea65a69f 100644 --- a/packages/client-sdk-nodejs/package.json +++ b/packages/client-sdk-nodejs/package.json @@ -52,7 +52,7 @@ "uuid": "8.3.2" }, "dependencies": { - "@gomomento/generated-types": "0.112.1", + "@gomomento/generated-types": "0.113.0", "@gomomento/sdk-core": "file:../core", "@grpc/grpc-js": "1.10.9", "@types/google-protobuf": "3.15.10", diff --git a/packages/client-sdk-nodejs/src/index.ts b/packages/client-sdk-nodejs/src/index.ts index 698c4a6dc..e3b87210c 100644 --- a/packages/client-sdk-nodejs/src/index.ts +++ b/packages/client-sdk-nodejs/src/index.ts @@ -80,7 +80,7 @@ import {TopicItem} from '@gomomento/sdk-core/dist/src/messages/responses/topic-i // Storage Response Types import { StorageDelete, - StorageSet, + StoragePut, StorageGet, CreateStore, DeleteStore, @@ -381,7 +381,7 @@ export { StorageConfigurations, StorageConfiguration, StorageClientConfiguration, - StorageSet, + StoragePut, StorageGet, StorageDelete, CreateStore, diff --git a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts index caee093c6..6ed7235e8 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts @@ -4,7 +4,7 @@ import { MomentoLogger, MomentoLoggerFactory, StorageGet, - StorageSet, + StoragePut, StorageDelete, UnknownError, } from '@gomomento/sdk-core'; @@ -220,30 +220,30 @@ export class StorageDataClient implements IStorageDataClient { }); } - public async set( + public async put( storeName: string, key: string, value: string | Uint8Array | number - ): Promise { + ): Promise { try { validateStoreName(storeName); } catch (err) { return this.cacheServiceErrorMapper.returnOrThrowError( err as Error, - err => new StorageSet.Error(err) + err => new StoragePut.Error(err) ); } this.logger.trace( `Issuing 'get' request; store: ${storeName}, key: ${key}` ); - return await this.sendSet(storeName, key, value); + return await this.sendPut(storeName, key, value); } - private async sendSet( + private async sendPut( storeName: string, key: string, value: string | Uint8Array | number - ): Promise { + ): Promise { const storeValue = new store._StoreValue(); if (typeof value === 'string') { storeValue.string_value = value; @@ -256,13 +256,13 @@ export class StorageDataClient implements IStorageDataClient { } else { storeValue.bytes_value = value; } - const request = new store._StoreSetRequest({ + const request = new store._StorePutRequest({ key: key, value: storeValue, }); const metadata = this.createMetadata(storeName); return await new Promise((resolve, reject) => { - this.clientWrapper.getClient().Set( + this.clientWrapper.getClient().Put( request, metadata, { @@ -270,11 +270,11 @@ export class StorageDataClient implements IStorageDataClient { }, (err: ServiceError | null, resp) => { if (resp) { - resolve(new StorageSet.Success()); + resolve(new StoragePut.Success()); } else { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StorageSet.Error(e), + errorResponseFactoryFn: e => new StoragePut.Error(e), resolveFn: resolve, rejectFn: reject, }); diff --git a/packages/client-sdk-web/package-lock.json b/packages/client-sdk-web/package-lock.json index ac7c93e17..6a5c59c4e 100644 --- a/packages/client-sdk-web/package-lock.json +++ b/packages/client-sdk-web/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.1", "license": "Apache-2.0", "dependencies": { - "@gomomento/generated-types-webtext": "0.111.2", + "@gomomento/generated-types-webtext": "0.113.0", "@gomomento/sdk-core": "file:../core", "@types/google-protobuf": "3.15.6", "google-protobuf": "3.21.2", @@ -45,6 +45,7 @@ } }, "../common-integration-tests": { + "name": "@gomomento/common-integration-tests", "version": "0.0.1", "dev": true, "license": "Apache-2.0", @@ -76,6 +77,7 @@ } }, "../core": { + "name": "@gomomento/sdk-core", "version": "0.0.1", "license": "Apache-2.0", "dependencies": { @@ -815,9 +817,9 @@ "link": true }, "node_modules/@gomomento/generated-types-webtext": { - "version": "0.111.2", - "resolved": "https://registry.npmjs.org/@gomomento/generated-types-webtext/-/generated-types-webtext-0.111.2.tgz", - "integrity": "sha512-yOwaGIuuqZ+XT+YIMY+Zgm0jvZIS0MEF0Zb+6sWmuqiujtZreizjfEA50Bf3rzKWcCyd6EAHDcSorpVVUbNAZA==", + "version": "0.113.0", + "resolved": "https://registry.npmjs.org/@gomomento/generated-types-webtext/-/generated-types-webtext-0.113.0.tgz", + "integrity": "sha512-+g7WyDyaakP9T+5nw0pYNQ5INuLGNmr0uzdX9bEeEpwFd2pDrPxFP6HBfvSOD1HJ+4tuUhc2mAA3/kQ5el7xhA==", "dependencies": { "google-protobuf": "3.21.2", "grpc-web": "1.4.2" diff --git a/packages/client-sdk-web/package.json b/packages/client-sdk-web/package.json index e5219d600..ba0b40bf0 100644 --- a/packages/client-sdk-web/package.json +++ b/packages/client-sdk-web/package.json @@ -55,7 +55,7 @@ "xhr2": "0.2.1" }, "dependencies": { - "@gomomento/generated-types-webtext": "0.111.2", + "@gomomento/generated-types-webtext": "0.113.0", "@gomomento/sdk-core": "file:../core", "@types/google-protobuf": "3.15.6", "google-protobuf": "3.21.2", diff --git a/packages/client-sdk-web/src/internal/storage-data-client.ts b/packages/client-sdk-web/src/internal/storage-data-client.ts index 10a6f1c37..459e961f1 100644 --- a/packages/client-sdk-web/src/internal/storage-data-client.ts +++ b/packages/client-sdk-web/src/internal/storage-data-client.ts @@ -1,7 +1,7 @@ import {store} from '@gomomento/generated-types-webtext'; import { StorageGet, - StorageSet, + StoragePut, StorageDelete, CredentialProvider, MomentoLogger, @@ -12,7 +12,7 @@ import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; import { _StoreDeleteRequest, _StoreGetRequest, - _StoreSetRequest, + _StorePutRequest, _StoreValue, } from '@gomomento/generated-types-webtext/dist/store_pb'; import {IStorageDataClient} from '@gomomento/sdk-core/dist/src/internal/clients'; @@ -154,21 +154,21 @@ export class StorageDataClient< }); } - public async set( + public async put( storeName: string, key: string, value: string | number | Uint8Array - ): Promise { + ): Promise { try { validateStoreName(storeName); } catch (err) { return this.cacheServiceErrorMapper.returnOrThrowError( err as Error, - err => new StorageSet.Error(err) + err => new StoragePut.Error(err) ); } this.logger.trace(`Issuing 'set' request; key: ${key.toString()}`); - const result = await this.sendSet( + const result = await this.sendPut( storeName, convertToB64String(key), value @@ -177,12 +177,12 @@ export class StorageDataClient< return result; } - private async sendSet( + private async sendPut( storeName: string, key: string, passedInVal: string | number | Uint8Array - ): Promise { - const request = new _StoreSetRequest(); + ): Promise { + const request = new _StorePutRequest(); request.setKey(key); const value = new _StoreValue(); @@ -199,7 +199,7 @@ export class StorageDataClient< } return await new Promise((resolve, reject) => { - this.clientWrapper.set( + this.clientWrapper.put( request, { ...this.clientMetadataProvider.createClientMetadata(), @@ -209,12 +209,12 @@ export class StorageDataClient< if (err) { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StorageSet.Error(e), + errorResponseFactoryFn: e => new StoragePut.Error(e), resolveFn: resolve, rejectFn: reject, }); } else { - resolve(new StorageSet.Success()); + resolve(new StoragePut.Success()); } } ); diff --git a/packages/common-integration-tests/src/storage.ts b/packages/common-integration-tests/src/storage.ts index 64144a7c1..cba332ce1 100644 --- a/packages/common-integration-tests/src/storage.ts +++ b/packages/common-integration-tests/src/storage.ts @@ -6,7 +6,7 @@ import { MomentoErrorCode, StorageDeleteResponse, StorageGetResponse, - StorageSetResponse, + StoragePutResponse, } from '@gomomento/sdk-core'; import {testCacheName} from './common-int-test-utils'; import {v4} from 'uuid'; @@ -102,18 +102,18 @@ export function runStorageServiceTests( await storageClient.deleteStore(storeName); }); }); - describe('#store get set and delete', () => { - it('set get and delete a key in a store', async () => { + describe('#store get put and delete', () => { + it('put get and delete a key in a store', async () => { const key = v4(); const value = v4(); - const setResponse = await storageClient.set(testStoreName, key, value); - switch (setResponse.type) { - case StorageSetResponse.Success: { + const putResponse = await storageClient.put(testStoreName, key, value); + switch (putResponse.type) { + case StoragePutResponse.Success: { break; } - case StorageSetResponse.Error: { + case StoragePutResponse.Error: { throw new Error( - `failed to set key: ${setResponse.message()} ${setResponse.toString()}` + `failed to put key: ${putResponse.message()} ${putResponse.toString()}` ); } } diff --git a/packages/core/src/clients/IStorageClient.ts b/packages/core/src/clients/IStorageClient.ts index 9c127e96b..f7b2efb3c 100644 --- a/packages/core/src/clients/IStorageClient.ts +++ b/packages/core/src/clients/IStorageClient.ts @@ -2,7 +2,7 @@ import { CreateStore, ListStores, DeleteStore, - StorageSet, + StoragePut, StorageGet, StorageDelete, } from '../index'; @@ -12,11 +12,11 @@ export interface IStorageClient { listStores(): Promise; deleteStore(cache: string): Promise; get(storeName: string, key: string): Promise; - set( + put( storeName: string, key: string, value: string | Uint8Array | number - ): Promise; + ): Promise; delete(storeName: string, key: string): Promise; close(): void; diff --git a/packages/core/src/internal/clients/storage/AbstractStorageClient.ts b/packages/core/src/internal/clients/storage/AbstractStorageClient.ts index 7f427b6f0..5e0a05e1f 100644 --- a/packages/core/src/internal/clients/storage/AbstractStorageClient.ts +++ b/packages/core/src/internal/clients/storage/AbstractStorageClient.ts @@ -3,7 +3,7 @@ import { DeleteStore, ListStores, StorageGet, - StorageSet, + StoragePut, StorageDelete, } from '../../../index'; import {IStorageDataClient} from './IStorageDataClient'; @@ -44,12 +44,12 @@ export abstract class AbstractStorageClient implements IStorageClient { return this.getNextDataClient().get(storeName, key); } - set( + put( storeName: string, key: string, value: string | Uint8Array | number - ): Promise { - return this.getNextDataClient().set(storeName, key, value); + ): Promise { + return this.getNextDataClient().put(storeName, key, value); } delete(storeName: string, key: string): Promise { diff --git a/packages/core/src/internal/clients/storage/IStorageDataClient.ts b/packages/core/src/internal/clients/storage/IStorageDataClient.ts index 2f258682b..524e7d1b7 100644 --- a/packages/core/src/internal/clients/storage/IStorageDataClient.ts +++ b/packages/core/src/internal/clients/storage/IStorageDataClient.ts @@ -1,12 +1,12 @@ -import {StorageGet, StorageSet, StorageDelete} from '../../../index'; +import {StorageGet, StoragePut, StorageDelete} from '../../../index'; export interface IStorageDataClient { get(storeName: string, key: string): Promise; - set( + put( storeName: string, key: string, value: string | number | Uint8Array - ): Promise; + ): Promise; delete(storeName: string, key: string): Promise; close(): void; } diff --git a/packages/core/src/messages/responses/enums/store/scalar/index.ts b/packages/core/src/messages/responses/enums/store/scalar/index.ts index 3c3f32bfc..09f186abd 100644 --- a/packages/core/src/messages/responses/enums/store/scalar/index.ts +++ b/packages/core/src/messages/responses/enums/store/scalar/index.ts @@ -10,7 +10,7 @@ export enum StorageItemType { Bytes = 'Bytes', } -export enum StorageSetResponse { +export enum StoragePutResponse { Success = 'Success', Error = 'Error', } diff --git a/packages/core/src/messages/responses/storage/scalar/index.ts b/packages/core/src/messages/responses/storage/scalar/index.ts index 3da735263..b333eec6b 100644 --- a/packages/core/src/messages/responses/storage/scalar/index.ts +++ b/packages/core/src/messages/responses/storage/scalar/index.ts @@ -1,3 +1,3 @@ export * as StorageDelete from './storage-delete'; export * as StorageGet from './storage-get'; -export * as StorageSet from './storage-set'; +export * as StoragePut from './storage-put'; diff --git a/packages/core/src/messages/responses/storage/scalar/storage-set.ts b/packages/core/src/messages/responses/storage/scalar/storage-put.ts similarity index 81% rename from packages/core/src/messages/responses/storage/scalar/storage-set.ts rename to packages/core/src/messages/responses/storage/scalar/storage-put.ts index 40fe71be3..b9184860b 100644 --- a/packages/core/src/messages/responses/storage/scalar/storage-set.ts +++ b/packages/core/src/messages/responses/storage/scalar/storage-put.ts @@ -1,16 +1,16 @@ -import {StorageSetResponse} from '../../enums'; +import {StoragePutResponse} from '../../enums'; import {BaseResponseError, BaseResponseSuccess} from '../../response-base'; import {SdkError} from '../../../../errors'; interface IResponse { - readonly type: StorageSetResponse; + readonly type: StoragePutResponse; } /** * Indicates a Successful store set request. */ export class Success extends BaseResponseSuccess implements IResponse { - readonly type: StorageSetResponse.Success = StorageSetResponse.Success; + readonly type: StoragePutResponse.Success = StoragePutResponse.Success; } /** @@ -28,7 +28,7 @@ export class Error extends BaseResponseError implements IResponse { super(_innerException); } - readonly type: StorageSetResponse.Error = StorageSetResponse.Error; + readonly type: StoragePutResponse.Error = StoragePutResponse.Error; } export type Response = Success | Error; From 78a62e19fd28ba833eb3554d84497fd476ffd821 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Mon, 17 Jun 2024 15:23:50 -0700 Subject: [PATCH 06/15] feat: make preview storage client updates --- packages/client-sdk-nodejs/package-lock.json | 419 ++++++++++++++++-- packages/client-sdk-nodejs/package.json | 1 + packages/client-sdk-web/package-lock.json | 73 +-- packages/client-sdk-web/package.json | 1 + .../src/internal/storage-data-client.ts | 10 +- .../package-lock.json | 365 ++++++++------- .../common-integration-tests/src/storage.ts | 15 + .../responses/storage/scalar/storage-get.ts | 40 +- 8 files changed, 656 insertions(+), 268 deletions(-) diff --git a/packages/client-sdk-nodejs/package-lock.json b/packages/client-sdk-nodejs/package-lock.json index 08c67b75d..df270458d 100644 --- a/packages/client-sdk-nodejs/package-lock.json +++ b/packages/client-sdk-nodejs/package-lock.json @@ -42,22 +42,6 @@ "node": ">= 16" } }, - "../../../client-protos/javascript": { - "version": "0.0.1", - "license": "Apache-2.0", - "dependencies": { - "@grpc/grpc-js": "1.10.5", - "google-protobuf": "3.21.2", - "grpc-tools": "^1.12.4", - "protoc-gen-ts": "^0.8.6" - }, - "devDependencies": { - "@tsconfig/node16": "1.0.2", - "@types/google-protobuf": "3.15.6", - "@types/node": "16.10.3", - "typescript": "4.9.5" - } - }, "../common-integration-tests": { "name": "@gomomento/common-integration-tests", "version": "0.0.1", @@ -1297,6 +1281,25 @@ "url": "https://opencollective.com/js-sdsl" } }, + "node_modules/@mapbox/node-pre-gyp": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.11.tgz", + "integrity": "sha512-Yhlar6v9WQgUp/He7BdgzOz8lqMQ8sU+jkCq7Wx8Myc5YFJLbEe7lgui/V7G1qB1DJykHSGwreceSaD60Y0PUQ==", + "dependencies": { + "detect-libc": "^2.0.0", + "https-proxy-agent": "^5.0.0", + "make-dir": "^3.1.0", + "node-fetch": "^2.6.7", + "nopt": "^5.0.0", + "npmlog": "^5.0.1", + "rimraf": "^3.0.2", + "semver": "^7.3.5", + "tar": "^6.1.11" + }, + "bin": { + "node-pre-gyp": "bin/node-pre-gyp" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -1812,6 +1815,11 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/abbrev": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" + }, "node_modules/acorn": { "version": "7.4.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", @@ -1834,14 +1842,40 @@ } }, "node_modules/acorn-walk": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.2.tgz", - "integrity": "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==", + "version": "8.3.3", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.3.tgz", + "integrity": "sha512-MxXdReSRhGO7VlFe1bRG/oI7/mdLV9B9JJT0N8vZOhF7gFRR5l3M8W9G8JxmKV+JC5mGqJ0QvqfSOLsCPa4nUw==", "dev": true, + "dependencies": { + "acorn": "^8.11.0" + }, "engines": { "node": ">=0.4.0" } }, + "node_modules/acorn-walk/node_modules/acorn": { + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", + "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", + "dev": true, + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -2228,14 +2262,12 @@ "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2350,9 +2382,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001633", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001633.tgz", - "integrity": "sha512-6sT0yf/z5jqf8tISAgpJDrmwOpLsrpnyCdD/lOZKvKkkJK4Dn0X5i7KF7THEZhOq+30bmhwBlNEaqPUiHiKtZg==", + "version": "1.0.30001636", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001636.tgz", + "integrity": "sha512-bMg2vmr8XBsbL6Lr0UHXy/21m84FTxDLWn2FSqMd5PrlbMxwJlQnC2YWYxVgp66PZE+BBNF2jYQUBKCo1FDeZg==", "dev": true, "funding": [ { @@ -2394,6 +2426,14 @@ "node": ">=10" } }, + "node_modules/chownr": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", + "engines": { + "node": ">=10" + } + }, "node_modules/ci-info": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", @@ -2466,11 +2506,23 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "node_modules/color-support": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", + "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", + "bin": { + "color-support": "bin.js" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", - "dev": true + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + }, + "node_modules/console-control-strings": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==" }, "node_modules/convert-source-map": { "version": "2.0.0", @@ -2649,6 +2701,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delegates": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==" + }, + "node_modules/detect-libc": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz", + "integrity": "sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw==", + "engines": { + "node": ">=8" + } + }, "node_modules/detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -2701,9 +2766,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.802", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.802.tgz", - "integrity": "sha512-TnTMUATbgNdPXVSHsxvNVSG0uEd6cSZsANjm8c9HbvflZVVn1yTRcmVXYT1Ma95/ssB/Dcd30AHweH2TE+dNpA==", + "version": "1.4.803", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.803.tgz", + "integrity": "sha512-61H9mLzGOCLLVsnLiRzCbc63uldP0AniRYPV3hbGVtONA1pI7qSGILdbofR7A8TMbOypDocEAjH/e+9k1QIe3g==", "dev": true }, "node_modules/emittery": { @@ -3525,11 +3590,37 @@ "is-callable": "^1.1.3" } }, + "node_modules/fs-minipass": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", + "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/fs-minipass/node_modules/minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/fs-minipass/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", - "dev": true + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, "node_modules/fsevents": { "version": "2.3.3", @@ -3793,6 +3884,19 @@ "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", "dev": true }, + "node_modules/grpc-tools": { + "version": "1.12.4", + "resolved": "https://registry.npmjs.org/grpc-tools/-/grpc-tools-1.12.4.tgz", + "integrity": "sha512-5+mLAJJma3BjnW/KQp6JBjUMgvu7Mu3dBvBPd1dcbNIb+qiR0817zDpgPjS7gRb+l/8EVNIa3cB02xI9JLToKg==", + "hasInstallScript": true, + "dependencies": { + "@mapbox/node-pre-gyp": "^1.0.5" + }, + "bin": { + "grpc_tools_node_protoc": "bin/protoc.js", + "grpc_tools_node_protoc_plugin": "bin/protoc_plugin.js" + } + }, "node_modules/has-bigints": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", @@ -3862,6 +3966,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/has-unicode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==" + }, "node_modules/hasown": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", @@ -3880,6 +3989,18 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, + "node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -3955,8 +4076,7 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "node_modules/internal-slot": { "version": "1.0.7", @@ -5424,6 +5544,28 @@ "yallist": "^3.0.2" } }, + "node_modules/make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "dependencies": { + "semver": "^6.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/make-dir/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", @@ -5480,7 +5622,6 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, "dependencies": { "brace-expansion": "^1.1.7" }, @@ -5497,11 +5638,57 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/minipass": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", + "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/minizlib": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", + "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", + "dependencies": { + "minipass": "^3.0.0", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/minizlib/node_modules/minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/minizlib/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, + "node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "node_modules/natural-compare": { "version": "1.4.0", @@ -5515,6 +5702,25 @@ "integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==", "dev": true }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -5527,6 +5733,20 @@ "integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==", "dev": true }, + "node_modules/nopt": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", + "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", + "dependencies": { + "abbrev": "1" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -5657,7 +5877,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "dev": true, "dependencies": { "wrappy": "1" } @@ -5794,7 +6013,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -5978,6 +6196,18 @@ "node": ">=12.0.0" } }, + "node_modules/protoc-gen-ts": { + "version": "0.8.7", + "resolved": "https://registry.npmjs.org/protoc-gen-ts/-/protoc-gen-ts-0.8.7.tgz", + "integrity": "sha512-jr4VJey2J9LVYCV7EVyVe53g1VMw28cCmYJhBe5e3YX5wiyiDwgxWxeDf9oTqAe4P1bN/YGAkW2jhlH8LohwiQ==", + "bin": { + "protoc-gen-ts": "protoc-gen-ts.js" + }, + "funding": { + "type": "individual", + "url": "https://www.buymeacoffee.com/thesayyn" + } + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -6029,6 +6259,19 @@ "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", "dev": true }, + "node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/regexp.prototype.flags": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", @@ -6198,6 +6441,25 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/safe-regex-test": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.0.3.tgz", @@ -6219,7 +6481,6 @@ "version": "7.6.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", - "dev": true, "bin": { "semver": "bin/semver.js" }, @@ -6227,6 +6488,11 @@ "node": ">=10" } }, + "node_modules/set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" + }, "node_modules/set-function-length": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", @@ -6301,8 +6567,7 @@ "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", - "dev": true + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" }, "node_modules/sisteransi": { "version": "1.0.5", @@ -6382,6 +6647,14 @@ "node": ">=8" } }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, "node_modules/string-length": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz", @@ -6560,6 +6833,27 @@ "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", "dev": true }, + "node_modules/tar": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.1.tgz", + "integrity": "sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==", + "dependencies": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^5.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/tar/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -6607,6 +6901,11 @@ "node": ">=8.0" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, "node_modules/ts-jest": { "version": "29.1.1", "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.1.tgz", @@ -6704,9 +7003,9 @@ } }, "node_modules/ts-node/node_modules/acorn": { - "version": "8.11.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", - "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", + "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -6942,6 +7241,11 @@ "punycode": "^2.1.0" } }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" + }, "node_modules/uuid": { "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", @@ -6986,6 +7290,20 @@ "makeerror": "1.0.12" } }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -7036,6 +7354,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/wide-align": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", + "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==", + "dependencies": { + "string-width": "^1.0.2 || 2 || 3 || 4" + } + }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", @@ -7064,8 +7390,7 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "dev": true + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, "node_modules/write-file-atomic": { "version": "4.0.2", diff --git a/packages/client-sdk-nodejs/package.json b/packages/client-sdk-nodejs/package.json index cea65a69f..f1eea3c27 100644 --- a/packages/client-sdk-nodejs/package.json +++ b/packages/client-sdk-nodejs/package.json @@ -18,6 +18,7 @@ "integration-test-auth": "jest auth-client.test.ts --maxWorkers 1", "unit-test": "jest unit", "integration-test-leaderboard": "jest leaderboard --maxWorkers 1", + "integration-test-store": "jest storage.test.ts --maxWorkers 1", "integration-test": "jest integration --testPathIgnorePatterns \"auth-client.test.ts|leaderboard.test.ts\" --maxWorkers 1", "build-deps": "cd ../core && npm run build && cd - && cd ../common-integration-tests && npm run build && cd -", "build-and-run-tests": "npm run build-deps && jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1", diff --git a/packages/client-sdk-web/package-lock.json b/packages/client-sdk-web/package-lock.json index 6a5c59c4e..c8ebdc741 100644 --- a/packages/client-sdk-web/package-lock.json +++ b/packages/client-sdk-web/package-lock.json @@ -45,7 +45,6 @@ } }, "../common-integration-tests": { - "name": "@gomomento/common-integration-tests", "version": "0.0.1", "dev": true, "license": "Apache-2.0", @@ -77,7 +76,6 @@ } }, "../core": { - "name": "@gomomento/sdk-core", "version": "0.0.1", "license": "Apache-2.0", "dependencies": { @@ -847,6 +845,7 @@ "version": "0.5.0", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.5.0.tgz", "integrity": "sha512-FagtKFz74XrTl7y6HCzQpwDfXP0yhxe9lHLD1UZxjvZIcbyRz8zTFF/yYNfSfzU414eDwZ1SrO0Qvtyf+wFMQg==", + "deprecated": "Use @eslint/config-array instead", "dev": true, "dependencies": { "@humanwhocodes/object-schema": "^1.2.0", @@ -861,6 +860,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", + "deprecated": "Use @eslint/object-schema instead", "dev": true }, "node_modules/@istanbuljs/load-nyc-config": { @@ -1722,9 +1722,9 @@ } }, "node_modules/acorn-globals/node_modules/acorn": { - "version": "8.11.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", - "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", + "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -1743,10 +1743,25 @@ } }, "node_modules/acorn-walk": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.2.tgz", - "integrity": "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==", + "version": "8.3.3", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.3.tgz", + "integrity": "sha512-MxXdReSRhGO7VlFe1bRG/oI7/mdLV9B9JJT0N8vZOhF7gFRR5l3M8W9G8JxmKV+JC5mGqJ0QvqfSOLsCPa4nUw==", "dev": true, + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk/node_modules/acorn": { + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", + "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", + "dev": true, + "bin": { + "acorn": "bin/acorn" + }, "engines": { "node": ">=0.4.0" } @@ -2165,9 +2180,9 @@ } }, "node_modules/browserslist": { - "version": "4.23.0", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.23.0.tgz", - "integrity": "sha512-QW8HiM1shhT2GuzkvklfjcKDiWFXHOeFCIA/huJPwHsslwcydgk7X+z2zXpEijP98UCY7HbubZt5J2Zgvf0CaQ==", + "version": "4.23.1", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.23.1.tgz", + "integrity": "sha512-TUfofFo/KsK/bWZ9TWQ5O26tsWW4Uhmt8IYklbnUa70udB6P2wA7w7o4PY4muaEPBQaAX+CEnmmIA41NVHtPVw==", "dev": true, "funding": [ { @@ -2184,10 +2199,10 @@ } ], "dependencies": { - "caniuse-lite": "^1.0.30001587", - "electron-to-chromium": "^1.4.668", + "caniuse-lite": "^1.0.30001629", + "electron-to-chromium": "^1.4.796", "node-releases": "^2.0.14", - "update-browserslist-db": "^1.0.13" + "update-browserslist-db": "^1.0.16" }, "bin": { "browserslist": "cli.js" @@ -2261,9 +2276,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001629", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001629.tgz", - "integrity": "sha512-c3dl911slnQhmxUIT4HhYzT7wnBK/XYpGnYLOj4nJBaRiw52Ibe7YxlDaAeRECvA786zCuExhxIUJ2K7nHMrBw==", + "version": "1.0.30001636", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001636.tgz", + "integrity": "sha512-bMg2vmr8XBsbL6Lr0UHXy/21m84FTxDLWn2FSqMd5PrlbMxwJlQnC2YWYxVgp66PZE+BBNF2jYQUBKCo1FDeZg==", "dev": true, "funding": [ { @@ -2694,9 +2709,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.795", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.795.tgz", - "integrity": "sha512-hHo4lK/8wb4NUa+NJYSFyJ0xedNHiR6ylilDtb8NUW9d4dmBFmGiecYEKCEbti1wTNzbKXLfl4hPWEkAFbHYlw==", + "version": "1.4.803", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.803.tgz", + "integrity": "sha512-61H9mLzGOCLLVsnLiRzCbc63uldP0AniRYPV3hbGVtONA1pI7qSGILdbofR7A8TMbOypDocEAjH/e+9k1QIe3g==", "dev": true }, "node_modules/emittery": { @@ -5445,9 +5460,9 @@ } }, "node_modules/jsdom/node_modules/acorn": { - "version": "8.11.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", - "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", + "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -6942,9 +6957,9 @@ } }, "node_modules/ts-node/node_modules/acorn": { - "version": "8.11.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", - "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", + "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -7398,9 +7413,9 @@ } }, "node_modules/ws": { - "version": "8.17.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.0.tgz", - "integrity": "sha512-uJq6108EgZMAl20KagGkzCKfMEjxmKvZHG7Tlq0Z6nOky7YF7aq4mOx6xK8TJ/i1LeK4Qus7INktacctDgY8Ow==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", "dev": true, "engines": { "node": ">=10.0.0" diff --git a/packages/client-sdk-web/package.json b/packages/client-sdk-web/package.json index ba0b40bf0..dac5390d8 100644 --- a/packages/client-sdk-web/package.json +++ b/packages/client-sdk-web/package.json @@ -16,6 +16,7 @@ "prebuild": "eslint . --ext .ts", "test": "jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1", "unit-test": "jest unit", + "integration-test-store": "jest storage.test.ts --maxWorkers 1", "integration-test-auth": "jest --env=jsdom auth-client.test.ts --maxWorkers 1", "integration-test-leaderboard": "jest --env=jsdom leaderboard --maxWorkers 1", "integration-test-jsdom": "jest integration --env=jsdom --testMatch \"**/dictionary.test.ts|**/ping.test.ts|*/topic-client.test.ts|leaderboard.test.ts\" --maxWorkers 1", diff --git a/packages/client-sdk-web/src/internal/storage-data-client.ts b/packages/client-sdk-web/src/internal/storage-data-client.ts index 459e961f1..a9a8e85ef 100644 --- a/packages/client-sdk-web/src/internal/storage-data-client.ts +++ b/packages/client-sdk-web/src/internal/storage-data-client.ts @@ -107,7 +107,7 @@ export class StorageDataClient< ...createStorageMetadata(storeName, this.deadlineMillis), }, (err, resp) => { - const value = resp?.getValue(); + const value = resp?.getValue() as _StoreValue; if (resp) { switch (value?.getValueCase()) { case undefined: @@ -159,6 +159,7 @@ export class StorageDataClient< key: string, value: string | number | Uint8Array ): Promise { + console.log('put called'); try { validateStoreName(storeName); } catch (err) { @@ -182,11 +183,18 @@ export class StorageDataClient< key: string, passedInVal: string | number | Uint8Array ): Promise { + console.log('sendPut called'); + console.log( + `storeName: ${storeName} key: ${key} passedInVal: ${ + passedInVal as string + }` + ); const request = new _StorePutRequest(); request.setKey(key); const value = new _StoreValue(); if (typeof passedInVal === 'string') { + console.log(`setting string value: ${passedInVal}`); value.setStringValue(passedInVal); } else if (typeof passedInVal === 'number') { if (Number.isInteger(passedInVal)) { diff --git a/packages/common-integration-tests/package-lock.json b/packages/common-integration-tests/package-lock.json index 8298411b1..f81bb1bbc 100644 --- a/packages/common-integration-tests/package-lock.json +++ b/packages/common-integration-tests/package-lock.json @@ -36,7 +36,6 @@ } }, "../core": { - "name": "@gomomento/sdk-core", "version": "0.0.1", "license": "Apache-2.0", "dependencies": { @@ -88,30 +87,30 @@ } }, "node_modules/@babel/compat-data": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.24.4.tgz", - "integrity": "sha512-vg8Gih2MLK+kOkHJp4gBEIkyaIi00jgWot2D9QOmmfLC8jINSOzmCLta6Bvz/JSBCqnegV0L80jhxkol5GWNfQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.24.7.tgz", + "integrity": "sha512-qJzAIcv03PyaWqxRgO4mSU3lihncDT296vnyuE2O8uA4w3UHWI4S3hgeZd1L8W1Bft40w9JxJ2b412iDUFFRhw==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/core": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.24.5.tgz", - "integrity": "sha512-tVQRucExLQ02Boi4vdPp49svNGcfL2GhdTCT9aldhXgCJVAI21EtRfBettiuLUwce/7r6bFdgs6JFkcdTiFttA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.24.7.tgz", + "integrity": "sha512-nykK+LEK86ahTkX/3TgauT0ikKoNCfKHEaZYTUVupJdTLzGNvrblu4u6fa7DhZONAltdf8e662t/abY8idrd/g==", "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.0", - "@babel/code-frame": "^7.24.2", - "@babel/generator": "^7.24.5", - "@babel/helper-compilation-targets": "^7.23.6", - "@babel/helper-module-transforms": "^7.24.5", - "@babel/helpers": "^7.24.5", - "@babel/parser": "^7.24.5", - "@babel/template": "^7.24.0", - "@babel/traverse": "^7.24.5", - "@babel/types": "^7.24.5", + "@babel/code-frame": "^7.24.7", + "@babel/generator": "^7.24.7", + "@babel/helper-compilation-targets": "^7.24.7", + "@babel/helper-module-transforms": "^7.24.7", + "@babel/helpers": "^7.24.7", + "@babel/parser": "^7.24.7", + "@babel/template": "^7.24.7", + "@babel/traverse": "^7.24.7", + "@babel/types": "^7.24.7", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -127,12 +126,12 @@ } }, "node_modules/@babel/core/node_modules/@babel/code-frame": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", - "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.2", + "@babel/highlight": "^7.24.7", "picocolors": "^1.0.0" }, "engines": { @@ -149,12 +148,12 @@ } }, "node_modules/@babel/generator": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.24.5.tgz", - "integrity": "sha512-x32i4hEXvr+iI0NEoEfDKzlemF8AmtOP8CcrRaEcpzysWuoEb1KknpcvMsHKPONoKZiDuItklgWhB18xEhr9PA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.24.7.tgz", + "integrity": "sha512-oipXieGC3i45Y1A41t4tAqpnEZWgB/lC6Ehh6+rOviR5XWpTtMmLN+fGjz9vOiNRt0p6RtO6DtD0pdU3vpqdSA==", "dev": true, "dependencies": { - "@babel/types": "^7.24.5", + "@babel/types": "^7.24.7", "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25", "jsesc": "^2.5.1" @@ -164,13 +163,13 @@ } }, "node_modules/@babel/helper-compilation-targets": { - "version": "7.23.6", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.23.6.tgz", - "integrity": "sha512-9JB548GZoQVmzrFgp8o7KxdgkTGm6xs9DW0o/Pim72UDjzr5ObUQ6ZzYPqA+g9OTS2bBQoctLJrky0RDCAWRgQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.24.7.tgz", + "integrity": "sha512-ctSdRHBi20qWOfy27RUb4Fhp07KSJ3sXcuSvTrXrc4aG8NSYDo1ici3Vhg9bg69y5bj0Mr1lh0aeEgTvc12rMg==", "dev": true, "dependencies": { - "@babel/compat-data": "^7.23.5", - "@babel/helper-validator-option": "^7.23.5", + "@babel/compat-data": "^7.24.7", + "@babel/helper-validator-option": "^7.24.7", "browserslist": "^4.22.2", "lru-cache": "^5.1.1", "semver": "^6.3.1" @@ -189,62 +188,66 @@ } }, "node_modules/@babel/helper-environment-visitor": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz", - "integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.24.7.tgz", + "integrity": "sha512-DoiN84+4Gnd0ncbBOM9AZENV4a5ZiL39HYMyZJGZ/AZEykHYdJw0wW3kdcsh9/Kn+BRXHLkkklZ51ecPKmI1CQ==", "dev": true, + "dependencies": { + "@babel/types": "^7.24.7" + }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-function-name": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz", - "integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.24.7.tgz", + "integrity": "sha512-FyoJTsj/PEUWu1/TYRiXTIHc8lbw+TDYkZuoE43opPS5TrI7MyONBE1oNvfguEXAD9yhQRrVBnXdXzSLQl9XnA==", "dev": true, "dependencies": { - "@babel/template": "^7.22.15", - "@babel/types": "^7.23.0" + "@babel/template": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-hoist-variables": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz", - "integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.24.7.tgz", + "integrity": "sha512-MJJwhkoGy5c4ehfoRyrJ/owKeMl19U54h27YYftT0o2teQ3FJ3nQUf/I3LlJsX4l3qlw7WRXUmiyajvHXoTubQ==", "dev": true, "dependencies": { - "@babel/types": "^7.22.5" + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-imports": { - "version": "7.24.3", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.24.3.tgz", - "integrity": "sha512-viKb0F9f2s0BCS22QSF308z/+1YWKV/76mwt61NBzS5izMzDPwdq1pTrzf+Li3npBWX9KdQbkeCt1jSAM7lZqg==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.24.7.tgz", + "integrity": "sha512-8AyH3C+74cgCVVXow/myrynrAGv+nTVg5vKu2nZph9x7RcRwzmh0VFallJuFTZ9mx6u4eSdXZfcOzSqTUm0HCA==", "dev": true, "dependencies": { - "@babel/types": "^7.24.0" + "@babel/traverse": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.24.5.tgz", - "integrity": "sha512-9GxeY8c2d2mdQUP1Dye0ks3VDyIMS98kt/llQ2nUId8IsWqTF0l1LkSX0/uP7l7MCDrzXS009Hyhe2gzTiGW8A==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.24.7.tgz", + "integrity": "sha512-1fuJEwIrp+97rM4RWdO+qrRsZlAeL1lQJoPqtCYWv0NL115XM93hIH4CSRln2w52SqvmY5hqdtauB6QFCDiZNQ==", "dev": true, "dependencies": { - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-module-imports": "^7.24.3", - "@babel/helper-simple-access": "^7.24.5", - "@babel/helper-split-export-declaration": "^7.24.5", - "@babel/helper-validator-identifier": "^7.24.5" + "@babel/helper-environment-visitor": "^7.24.7", + "@babel/helper-module-imports": "^7.24.7", + "@babel/helper-simple-access": "^7.24.7", + "@babel/helper-split-export-declaration": "^7.24.7", + "@babel/helper-validator-identifier": "^7.24.7" }, "engines": { "node": ">=6.9.0" @@ -254,86 +257,86 @@ } }, "node_modules/@babel/helper-plugin-utils": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.5.tgz", - "integrity": "sha512-xjNLDopRzW2o6ba0gKbkZq5YWEBaK3PCyTOY1K2P/O07LGMhMqlMXPxwN4S5/RhWuCobT8z0jrlKGlYmeR1OhQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.7.tgz", + "integrity": "sha512-Rq76wjt7yz9AAc1KnlRKNAi/dMSVWgDRx43FHoJEbcYU6xOWaE2dVPwcdTukJrjxS65GITyfbvEYHvkirZ6uEg==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-simple-access": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.24.5.tgz", - "integrity": "sha512-uH3Hmf5q5n7n8mz7arjUlDOCbttY/DW4DYhE6FUsjKJ/oYC1kQQUvwEQWxRwUpX9qQKRXeqLwWxrqilMrf32sQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.24.7.tgz", + "integrity": "sha512-zBAIvbCMh5Ts+b86r/CjU+4XGYIs+R1j951gxI3KmmxBMhCg4oQMsv6ZXQ64XOm/cvzfU1FmoCyt6+owc5QMYg==", "dev": true, "dependencies": { - "@babel/types": "^7.24.5" + "@babel/traverse": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-split-export-declaration": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.24.5.tgz", - "integrity": "sha512-5CHncttXohrHk8GWOFCcCl4oRD9fKosWlIRgWm4ql9VYioKm52Mk2xsmoohvm7f3JoiLSM5ZgJuRaf5QZZYd3Q==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.24.7.tgz", + "integrity": "sha512-oy5V7pD+UvfkEATUKvIjvIAH/xCzfsFVw7ygW2SI6NClZzquT+mwdTfgfdbUiceh6iQO0CHtCPsyze/MZ2YbAA==", "dev": true, "dependencies": { - "@babel/types": "^7.24.5" + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-string-parser": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.1.tgz", - "integrity": "sha512-2ofRCjnnA9y+wk8b9IAREroeUP02KHp431N2mhKniy2yKIDKpbrHv9eXwm8cBeWQYcJmzv5qKCu65P47eCF7CQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.7.tgz", + "integrity": "sha512-7MbVt6xrwFQbunH2DNQsAP5sTGxfqQtErvBIvIMi6EQnbgUOuVYanvREcmFrOPhoXBrTtjhhP+lW+o5UfK+tDg==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.5.tgz", - "integrity": "sha512-3q93SSKX2TWCG30M2G2kwaKeTYgEUp5Snjuj8qm729SObL6nbtUldAi37qbxkD5gg3xnBio+f9nqpSepGZMvxA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz", + "integrity": "sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-option": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.23.5.tgz", - "integrity": "sha512-85ttAOMLsr53VgXkTbkx8oA6YTfT4q7/HzXSLEYmjcSTJPMPQtvq1BD79Byep5xMUYbGRzEpDsjUf3dyp54IKw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.24.7.tgz", + "integrity": "sha512-yy1/KvjhV/ZCL+SM7hBrvnZJ3ZuT9OuZgIJAGpPEToANvc3iM6iDvBnRjtElWibHU6n8/LPR/EjX9EtIEYO3pw==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helpers": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.24.5.tgz", - "integrity": "sha512-CiQmBMMpMQHwM5m01YnrM6imUG1ebgYJ+fAIW4FZe6m4qHTPaRHti+R8cggAwkdz4oXhtO4/K9JWlh+8hIfR2Q==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.24.7.tgz", + "integrity": "sha512-NlmJJtvcw72yRJRcnCmGvSi+3jDEg8qFu3z0AFoymmzLx5ERVWyzd9kVXr7Th9/8yIJi2Zc6av4Tqz3wFs8QWg==", "dev": true, "dependencies": { - "@babel/template": "^7.24.0", - "@babel/traverse": "^7.24.5", - "@babel/types": "^7.24.5" + "@babel/template": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/highlight": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.5.tgz", - "integrity": "sha512-8lLmua6AVh/8SLJRRVD6V8p73Hir9w5mJrhE+IPpILG31KKlI9iz5zmBYKcWPS59qSfgP9RaSBQSHHE81WKuEw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.7.tgz", + "integrity": "sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==", "dev": true, "dependencies": { - "@babel/helper-validator-identifier": "^7.24.5", + "@babel/helper-validator-identifier": "^7.24.7", "chalk": "^2.4.2", "js-tokens": "^4.0.0", "picocolors": "^1.0.0" @@ -414,9 +417,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.5.tgz", - "integrity": "sha512-EOv5IK8arwh3LI47dz1b0tKUb/1uhHAnHJOrjgtQMIpu1uXd9mlFrJg9IUgGUgZ41Ch0K8REPTYpO7B76b4vJg==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.7.tgz", + "integrity": "sha512-9uUYRm6OqQrCqQdG1iCBwBPZgN8ciDBro2nIOFaiRz1/BCxaI7CNvQbDHvsArAC7Tw9Hda/B3U+6ui9u4HWXPw==", "dev": true, "bin": { "parser": "bin/babel-parser.js" @@ -486,12 +489,12 @@ } }, "node_modules/@babel/plugin-syntax-jsx": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.24.1.tgz", - "integrity": "sha512-2eCtxZXf+kbkMIsXS4poTvT4Yu5rXiRa+9xGVT56raghjmBTKMpFNc9R4IDiB4emao9eO22Ox7CxuJG7BgExqA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.24.7.tgz", + "integrity": "sha512-6ddciUPe/mpMnOKv/U+RSd2vvVy+Yw/JfBB0ZHYjEZt9NLHmCUylNYlsbqCCS1Bffjlb0fCwC9Vqz+sBz6PsiQ==", "dev": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.24.7" }, "engines": { "node": ">=6.9.0" @@ -588,12 +591,12 @@ } }, "node_modules/@babel/plugin-syntax-typescript": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.24.1.tgz", - "integrity": "sha512-Yhnmvy5HZEnHUty6i++gcfH1/l68AHnItFHnaCv6hn9dNh0hQvvQJsxpi4BMBFN5DLeHBuucT/0DgzXif/OyRw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.24.7.tgz", + "integrity": "sha512-c/+fVeJBB0FeKsFvwytYiUD+LBvhHjGSI0g446PRGdSVGZLRNArBUno2PETbAly3tpiNAQR5XaZ+JslxkotsbA==", "dev": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.24.7" }, "engines": { "node": ">=6.9.0" @@ -603,26 +606,26 @@ } }, "node_modules/@babel/template": { - "version": "7.24.0", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.24.0.tgz", - "integrity": "sha512-Bkf2q8lMB0AFpX0NFEqSbx1OkTHf0f+0j82mkw+ZpzBnkk7e9Ql0891vlfgi+kHwOk8tQjiQHpqh4LaSa0fKEA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.24.7.tgz", + "integrity": "sha512-jYqfPrU9JTF0PmPy1tLYHW4Mp4KlgxJD9l2nP9fD6yT/ICi554DmrWBAEYpIelzjHf1msDP3PxJIRt/nFNfBig==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.23.5", - "@babel/parser": "^7.24.0", - "@babel/types": "^7.24.0" + "@babel/code-frame": "^7.24.7", + "@babel/parser": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/template/node_modules/@babel/code-frame": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", - "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.2", + "@babel/highlight": "^7.24.7", "picocolors": "^1.0.0" }, "engines": { @@ -630,19 +633,19 @@ } }, "node_modules/@babel/traverse": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.24.5.tgz", - "integrity": "sha512-7aaBLeDQ4zYcUFDUD41lJc1fG8+5IU9DaNSJAgal866FGvmD5EbWQgnEC6kO1gGLsX0esNkfnJSndbTXA3r7UA==", - "dev": true, - "dependencies": { - "@babel/code-frame": "^7.24.2", - "@babel/generator": "^7.24.5", - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-function-name": "^7.23.0", - "@babel/helper-hoist-variables": "^7.22.5", - "@babel/helper-split-export-declaration": "^7.24.5", - "@babel/parser": "^7.24.5", - "@babel/types": "^7.24.5", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.24.7.tgz", + "integrity": "sha512-yb65Ed5S/QAcewNPh0nZczy9JdYXkkAbIsEo+P7BE7yO3txAY30Y/oPa3QkQ5It3xVG2kpKMg9MsdxZaO31uKA==", + "dev": true, + "dependencies": { + "@babel/code-frame": "^7.24.7", + "@babel/generator": "^7.24.7", + "@babel/helper-environment-visitor": "^7.24.7", + "@babel/helper-function-name": "^7.24.7", + "@babel/helper-hoist-variables": "^7.24.7", + "@babel/helper-split-export-declaration": "^7.24.7", + "@babel/parser": "^7.24.7", + "@babel/types": "^7.24.7", "debug": "^4.3.1", "globals": "^11.1.0" }, @@ -651,12 +654,12 @@ } }, "node_modules/@babel/traverse/node_modules/@babel/code-frame": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", - "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.2", + "@babel/highlight": "^7.24.7", "picocolors": "^1.0.0" }, "engines": { @@ -673,13 +676,13 @@ } }, "node_modules/@babel/types": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.24.5.tgz", - "integrity": "sha512-6mQNsaLeXTw0nxYUYu+NSa4Hx4BlF1x1x8/PMFbiR+GBSr+2DkECc69b8hgy2frEodNcvPffeH8YfWd3LI6jhQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.24.7.tgz", + "integrity": "sha512-XEFXSlxiG5td2EJRe8vOmRbaXVgfcBlszKujvVmWIK/UpywWljQCfzAv3RQCGujWQ1RD4YYWEAqDXfuJiy8f5Q==", "dev": true, "dependencies": { - "@babel/helper-string-parser": "^7.24.1", - "@babel/helper-validator-identifier": "^7.24.5", + "@babel/helper-string-parser": "^7.24.7", + "@babel/helper-validator-identifier": "^7.24.7", "to-fast-properties": "^2.0.0" }, "engines": { @@ -730,9 +733,9 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.10.0", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.10.0.tgz", - "integrity": "sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA==", + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.10.1.tgz", + "integrity": "sha512-Zm2NGpWELsQAD1xsJzGQpYfvICSsFkEpU0jxBjfdC6uNEWXcHnfs9hScFWtXVDVl+rBQJGrl4g1vcKIejpH9dA==", "dev": true, "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" @@ -775,6 +778,7 @@ "version": "0.5.0", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.5.0.tgz", "integrity": "sha512-FagtKFz74XrTl7y6HCzQpwDfXP0yhxe9lHLD1UZxjvZIcbyRz8zTFF/yYNfSfzU414eDwZ1SrO0Qvtyf+wFMQg==", + "deprecated": "Use @eslint/config-array instead", "dev": true, "dependencies": { "@humanwhocodes/object-schema": "^1.2.0", @@ -789,6 +793,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", + "deprecated": "Use @eslint/object-schema instead", "dev": true }, "node_modules/@istanbuljs/load-nyc-config": { @@ -1267,9 +1272,9 @@ } }, "node_modules/@types/babel__traverse": { - "version": "7.20.5", - "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.5.tgz", - "integrity": "sha512-WXCyOcRtH37HAUkpXhUduaxdm82b4GSlyTqajXviN4EfiuPgNYR109xMCKvpl6zPIpua0DGlMEDCq+g8EdoheQ==", + "version": "7.20.6", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.6.tgz", + "integrity": "sha512-r1bzfrm0tomOI8g1SzvCaQHo6Lcv6zu0EA+W2kHrt8dyrHQxGzBBL4kdkzIS+jBMV+EYcMAEAqXqYaLJq5rOZg==", "dev": true, "dependencies": { "@babel/types": "^7.20.7" @@ -1579,10 +1584,25 @@ } }, "node_modules/acorn-walk": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.2.tgz", - "integrity": "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==", + "version": "8.3.3", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.3.tgz", + "integrity": "sha512-MxXdReSRhGO7VlFe1bRG/oI7/mdLV9B9JJT0N8vZOhF7gFRR5l3M8W9G8JxmKV+JC5mGqJ0QvqfSOLsCPa4nUw==", + "dev": true, + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk/node_modules/acorn": { + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", + "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", "dev": true, + "bin": { + "acorn": "bin/acorn" + }, "engines": { "node": ">=0.4.0" } @@ -1983,9 +2003,9 @@ } }, "node_modules/browserslist": { - "version": "4.23.0", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.23.0.tgz", - "integrity": "sha512-QW8HiM1shhT2GuzkvklfjcKDiWFXHOeFCIA/huJPwHsslwcydgk7X+z2zXpEijP98UCY7HbubZt5J2Zgvf0CaQ==", + "version": "4.23.1", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.23.1.tgz", + "integrity": "sha512-TUfofFo/KsK/bWZ9TWQ5O26tsWW4Uhmt8IYklbnUa70udB6P2wA7w7o4PY4muaEPBQaAX+CEnmmIA41NVHtPVw==", "dev": true, "funding": [ { @@ -2002,10 +2022,10 @@ } ], "dependencies": { - "caniuse-lite": "^1.0.30001587", - "electron-to-chromium": "^1.4.668", + "caniuse-lite": "^1.0.30001629", + "electron-to-chromium": "^1.4.796", "node-releases": "^2.0.14", - "update-browserslist-db": "^1.0.13" + "update-browserslist-db": "^1.0.16" }, "bin": { "browserslist": "cli.js" @@ -2079,9 +2099,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001617", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001617.tgz", - "integrity": "sha512-mLyjzNI9I+Pix8zwcrpxEbGlfqOkF9kM3ptzmKNw5tizSyYwMe+nGLTqMK9cO+0E+Bh6TsBxNAaHWEM8xwSsmA==", + "version": "1.0.30001636", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001636.tgz", + "integrity": "sha512-bMg2vmr8XBsbL6Lr0UHXy/21m84FTxDLWn2FSqMd5PrlbMxwJlQnC2YWYxVgp66PZE+BBNF2jYQUBKCo1FDeZg==", "dev": true, "funding": [ { @@ -2297,9 +2317,9 @@ } }, "node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz", + "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", "dev": true, "dependencies": { "ms": "2.1.2" @@ -2428,9 +2448,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.762", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.762.tgz", - "integrity": "sha512-rrFvGweLxPwwSwJOjIopy3Vr+J3cIPtZzuc74bmlvmBIgQO3VYJDvVrlj94iKZ3ukXUH64Ex31hSfRTLqvjYJQ==", + "version": "1.4.803", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.803.tgz", + "integrity": "sha512-61H9mLzGOCLLVsnLiRzCbc63uldP0AniRYPV3hbGVtONA1pI7qSGILdbofR7A8TMbOypDocEAjH/e+9k1QIe3g==", "dev": true }, "node_modules/emittery": { @@ -3348,6 +3368,7 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", "dev": true, "dependencies": { "fs.realpath": "^1.0.0", @@ -3604,6 +3625,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", "dev": true, "dependencies": { "once": "^1.3.0", @@ -4300,12 +4322,12 @@ } }, "node_modules/jest-message-util/node_modules/@babel/code-frame": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", - "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.2", + "@babel/highlight": "^7.24.7", "picocolors": "^1.0.0" }, "engines": { @@ -4774,12 +4796,12 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz", + "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==", "dev": true, "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -5117,9 +5139,9 @@ } }, "node_modules/picocolors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", - "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz", + "integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==", "dev": true }, "node_modules/picomatch": { @@ -5417,6 +5439,7 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "deprecated": "Rimraf versions prior to v4 are no longer supported", "dev": true, "dependencies": { "glob": "^7.1.3" @@ -5812,9 +5835,9 @@ } }, "node_modules/table/node_modules/ajv": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.13.0.tgz", - "integrity": "sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.16.0.tgz", + "integrity": "sha512-F0twR8U1ZU67JIEtekUcLkXkoO5mMMmgGD8sK/xUFzJ805jxHQl92hImFAqqXMyMYjSPOyUPAwHYhB72g5sTXw==", "dev": true, "dependencies": { "fast-deep-equal": "^3.1.3", @@ -5967,9 +5990,9 @@ } }, "node_modules/ts-node/node_modules/acorn": { - "version": "8.11.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", - "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", + "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -6167,9 +6190,9 @@ } }, "node_modules/update-browserslist-db": { - "version": "1.0.15", - "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.15.tgz", - "integrity": "sha512-K9HWH62x3/EalU1U6sjSZiylm9C8tgq2mSvshZpqc7QE69RaA2qjhkW2HlNA0tFpEbtyFz7HTqbSdN4MSwUodA==", + "version": "1.0.16", + "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.16.tgz", + "integrity": "sha512-KVbTxlBYlckhF5wgfyZXTWnMn7MMZjMu9XG8bPlliUOP9ThaF4QnhP8qrjrH7DRzHfSk0oQv1wToW+iA5GajEQ==", "dev": true, "funding": [ { @@ -6187,7 +6210,7 @@ ], "dependencies": { "escalade": "^3.1.2", - "picocolors": "^1.0.0" + "picocolors": "^1.0.1" }, "bin": { "update-browserslist-db": "cli.js" diff --git a/packages/common-integration-tests/src/storage.ts b/packages/common-integration-tests/src/storage.ts index cba332ce1..b3188cabb 100644 --- a/packages/common-integration-tests/src/storage.ts +++ b/packages/common-integration-tests/src/storage.ts @@ -106,6 +106,21 @@ export function runStorageServiceTests( it('put get and delete a key in a store', async () => { const key = v4(); const value = v4(); + const createResponse = await storageClient.createStore(testStoreName); + switch (createResponse.type) { + // this is the expected response + case CreateStoreResponse.Success: { + break; + } + case CreateStoreResponse.AlreadyExists: { + break; + } + case CreateStoreResponse.Error: { + throw new Error( + `failed to create store, expected store to be able to happen, error: ${createResponse.message()} exception: ${createResponse.toString()}` + ); + } + } const putResponse = await storageClient.put(testStoreName, key, value); switch (putResponse.type) { case StoragePutResponse.Success: { diff --git a/packages/core/src/messages/responses/storage/scalar/storage-get.ts b/packages/core/src/messages/responses/storage/scalar/storage-get.ts index 1b307b310..6192f2b4c 100644 --- a/packages/core/src/messages/responses/storage/scalar/storage-get.ts +++ b/packages/core/src/messages/responses/storage/scalar/storage-get.ts @@ -13,13 +13,13 @@ export abstract class Success extends ResponseBase implements IResponse { abstract value(): string | number | Uint8Array; - abstract intValue(): number | undefined; + abstract valueInt(): number | undefined; - abstract doubleValue(): number | undefined; + abstract valueDouble(): number | undefined; - abstract stringValue(): string | undefined; + abstract valueString(): string | undefined; - abstract bytesValue(): Uint8Array | undefined; + abstract valueBytes(): Uint8Array | undefined; } export class StringResponse extends Success { @@ -34,19 +34,19 @@ export class StringResponse extends Success { return this._value; } - bytesValue(): undefined { + valueBytes(): undefined { return undefined; } - doubleValue(): undefined { + valueDouble(): undefined { return undefined; } - intValue(): undefined { + valueInt(): undefined { return undefined; } - stringValue(): string { + valueString(): string { return this.value(); } } @@ -63,19 +63,19 @@ export class IntegerResponse extends Success { return this._value; } - bytesValue(): undefined { + valueBytes(): undefined { return undefined; } - doubleValue(): undefined { + valueDouble(): undefined { return undefined; } - intValue(): number | undefined { + valueInt(): number | undefined { return this.value(); } - stringValue(): undefined { + valueString(): undefined { return undefined; } } @@ -92,19 +92,19 @@ export class DoubleResponse extends Success { return this._value; } - bytesValue(): undefined { + valueBytes(): undefined { return undefined; } - doubleValue(): number { + valueDouble(): number { return this.value(); } - intValue(): undefined { + valueInt(): undefined { return undefined; } - stringValue(): undefined { + valueString(): undefined { return undefined; } } @@ -121,19 +121,19 @@ export class BytesResponse extends Success { return this._value; } - bytesValue(): Uint8Array { + valueBytes(): Uint8Array { return this.value(); } - doubleValue(): undefined { + valueDouble(): undefined { return undefined; } - intValue(): undefined { + valueInt(): undefined { return undefined; } - stringValue(): undefined { + valueString(): undefined { return undefined; } } From 969fb2f3430ea07013779dfafa24921120bea8b5 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Mon, 17 Jun 2024 18:03:57 -0700 Subject: [PATCH 07/15] fix: pass integ tests --- packages/client-sdk-nodejs/package.json | 1 - .../src/internal/storage-data-client.ts | 10 ++++++---- packages/client-sdk-web/package.json | 1 - .../src/internal/storage-data-client.ts | 16 ++++++++-------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/client-sdk-nodejs/package.json b/packages/client-sdk-nodejs/package.json index f1eea3c27..cea65a69f 100644 --- a/packages/client-sdk-nodejs/package.json +++ b/packages/client-sdk-nodejs/package.json @@ -18,7 +18,6 @@ "integration-test-auth": "jest auth-client.test.ts --maxWorkers 1", "unit-test": "jest unit", "integration-test-leaderboard": "jest leaderboard --maxWorkers 1", - "integration-test-store": "jest storage.test.ts --maxWorkers 1", "integration-test": "jest integration --testPathIgnorePatterns \"auth-client.test.ts|leaderboard.test.ts\" --maxWorkers 1", "build-deps": "cd ../core && npm run build && cd - && cd ../common-integration-tests && npm run build && cd -", "build-and-run-tests": "npm run build-deps && jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1", diff --git a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts index 6ed7235e8..931d3acbe 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts @@ -7,6 +7,7 @@ import { StoragePut, StorageDelete, UnknownError, + SdkError, } from '@gomomento/sdk-core'; import {validateStoreName} from '@gomomento/sdk-core/dist/src/internal/utils'; import {store} from '@gomomento/generated-types/dist/store'; @@ -210,7 +211,7 @@ export class StorageDataClient implements IStorageDataClient { } else { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StorageGet.Error(e), + errorResponseFactoryFn: (e: SdkError) => new StorageGet.Error(e), resolveFn: resolve, rejectFn: reject, }); @@ -234,7 +235,7 @@ export class StorageDataClient implements IStorageDataClient { ); } this.logger.trace( - `Issuing 'get' request; store: ${storeName}, key: ${key}` + `Issuing 'put' request; store: ${storeName}, key: ${key}` ); return await this.sendPut(storeName, key, value); } @@ -274,7 +275,7 @@ export class StorageDataClient implements IStorageDataClient { } else { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StoragePut.Error(e), + errorResponseFactoryFn: (e: SdkError) => new StoragePut.Error(e), resolveFn: resolve, rejectFn: reject, }); @@ -323,7 +324,8 @@ export class StorageDataClient implements IStorageDataClient { } else { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StorageDelete.Error(e), + errorResponseFactoryFn: (e: SdkError) => + new StorageDelete.Error(e), resolveFn: resolve, rejectFn: reject, }); diff --git a/packages/client-sdk-web/package.json b/packages/client-sdk-web/package.json index dac5390d8..ba0b40bf0 100644 --- a/packages/client-sdk-web/package.json +++ b/packages/client-sdk-web/package.json @@ -16,7 +16,6 @@ "prebuild": "eslint . --ext .ts", "test": "jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1", "unit-test": "jest unit", - "integration-test-store": "jest storage.test.ts --maxWorkers 1", "integration-test-auth": "jest --env=jsdom auth-client.test.ts --maxWorkers 1", "integration-test-leaderboard": "jest --env=jsdom leaderboard --maxWorkers 1", "integration-test-jsdom": "jest integration --env=jsdom --testMatch \"**/dictionary.test.ts|**/ping.test.ts|*/topic-client.test.ts|leaderboard.test.ts\" --maxWorkers 1", diff --git a/packages/client-sdk-web/src/internal/storage-data-client.ts b/packages/client-sdk-web/src/internal/storage-data-client.ts index a9a8e85ef..057551f65 100644 --- a/packages/client-sdk-web/src/internal/storage-data-client.ts +++ b/packages/client-sdk-web/src/internal/storage-data-client.ts @@ -25,6 +25,7 @@ import { import {ClientMetadataProvider} from './client-metadata-provider'; import ValueCase = _StoreValue.ValueCase; import {StorageConfiguration} from '../config/storage-configuration'; +import {SdkError} from '@gomomento/sdk-core'; export interface StorageDataClientProps { configuration: StorageConfiguration; @@ -144,7 +145,7 @@ export class StorageDataClient< } else { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StorageGet.Error(e), + errorResponseFactoryFn: (e: SdkError) => new StorageGet.Error(e), resolveFn: resolve, rejectFn: reject, }); @@ -159,7 +160,6 @@ export class StorageDataClient< key: string, value: string | number | Uint8Array ): Promise { - console.log('put called'); try { validateStoreName(storeName); } catch (err) { @@ -168,13 +168,13 @@ export class StorageDataClient< err => new StoragePut.Error(err) ); } - this.logger.trace(`Issuing 'set' request; key: ${key.toString()}`); + this.logger.trace(`Issuing 'put' request; key: ${key.toString()}`); const result = await this.sendPut( storeName, convertToB64String(key), value ); - this.logger.trace(`'set' request result: ${result.toString()}`); + this.logger.trace(`'put' request result: ${result.toString()}`); return result; } @@ -183,7 +183,6 @@ export class StorageDataClient< key: string, passedInVal: string | number | Uint8Array ): Promise { - console.log('sendPut called'); console.log( `storeName: ${storeName} key: ${key} passedInVal: ${ passedInVal as string @@ -205,7 +204,7 @@ export class StorageDataClient< } else { value.setBytesValue(passedInVal); } - + request.setValue(value); return await new Promise((resolve, reject) => { this.clientWrapper.put( request, @@ -217,7 +216,7 @@ export class StorageDataClient< if (err) { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StoragePut.Error(e), + errorResponseFactoryFn: (e: SdkError) => new StoragePut.Error(e), resolveFn: resolve, rejectFn: reject, }); @@ -265,7 +264,8 @@ export class StorageDataClient< if (err) { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, - errorResponseFactoryFn: e => new StorageDelete.Error(e), + errorResponseFactoryFn: (e: SdkError) => + new StorageDelete.Error(e), resolveFn: resolve, rejectFn: reject, }); From 0af86da121babee95fe7d04e2a820a477eb20799 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Tue, 18 Jun 2024 10:11:51 -0700 Subject: [PATCH 08/15] fix: add client type when calling create metadata client --- packages/client-sdk-nodejs/src/internal/storage-data-client.ts | 2 +- packages/client-sdk-web/src/internal/storage-data-client.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts index 931d3acbe..9d2292974 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts @@ -122,7 +122,7 @@ export class StorageDataClient implements IStorageDataClient { ): Interceptor[] { const headers = [ new Header('Authorization', this.credentialProvider.getAuthToken()), - new Header('Agent', `nodejs:${version}`), + new Header('Agent', `nodejs:store:${version}`), ]; return [ middlewaresInterceptor( diff --git a/packages/client-sdk-web/src/internal/storage-data-client.ts b/packages/client-sdk-web/src/internal/storage-data-client.ts index 057551f65..33e4d2479 100644 --- a/packages/client-sdk-web/src/internal/storage-data-client.ts +++ b/packages/client-sdk-web/src/internal/storage-data-client.ts @@ -60,6 +60,7 @@ export class StorageDataClient< this.clientMetadataProvider = new ClientMetadataProvider({ authToken: props.credentialProvider.getAuthToken(), + clientType: 'store', }); this.clientWrapper = new store.StoreClient( // Note: all web SDK requests are routed to a `web.` subdomain to allow us flexibility on the server From ea7184d2a4c7520f7baee6cd2dea52f81c07294e Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Tue, 18 Jun 2024 10:41:39 -0700 Subject: [PATCH 09/15] fix: add client type when calling create metadata client --- .../client-sdk-nodejs/src/internal/storage-control-client.ts | 2 +- packages/client-sdk-web/src/internal/storage-control-client.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/client-sdk-nodejs/src/internal/storage-control-client.ts b/packages/client-sdk-nodejs/src/internal/storage-control-client.ts index c1abde6de..4194ff5c7 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-control-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-control-client.ts @@ -28,7 +28,7 @@ export class StorageControlClient { this.cacheServiceErrorMapper = new CacheServiceErrorMapper(false); const headers = [ new Header('Authorization', props.credentialProvider.getAuthToken()), - new Header('Agent', `nodejs:${version}`), + new Header('Agent', `nodejs:cache:${version}`), ]; this.interceptors = [ new HeaderInterceptorProvider(headers).createHeadersInterceptor(), diff --git a/packages/client-sdk-web/src/internal/storage-control-client.ts b/packages/client-sdk-web/src/internal/storage-control-client.ts index 9179eb2fe..e09bdf9d4 100644 --- a/packages/client-sdk-web/src/internal/storage-control-client.ts +++ b/packages/client-sdk-web/src/internal/storage-control-client.ts @@ -52,6 +52,7 @@ export class StorageControlClient< this.clientMetadataProvider = new ClientMetadataProvider({ authToken: props.credentialProvider.getAuthToken(), + clientType: 'store', }); this.clientWrapper = new control.ScsControlClient( // Note: all web SDK requests are routed to a `web.` subdomain to allow us flexibility on the server From 16ddc22493cc88a36318fb1d28d434629e11a5e8 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Wed, 19 Jun 2024 11:17:50 -0700 Subject: [PATCH 10/15] chore: address comment feedback --- .../src/config/storage-configurations.ts | 35 +++++-------------- .../src/internal/storage-control-client.ts | 2 +- .../src/preview-storage-client.ts | 4 +++ packages/client-sdk-web/package-lock.json | 6 ++-- .../package-lock.json | 6 ++-- .../common-integration-tests/src/storage.ts | 28 ++++++++++++--- packages/core/src/auth/credential-provider.ts | 8 ++--- .../responses/storage/control/list-stores.ts | 12 +++---- 8 files changed, 52 insertions(+), 49 deletions(-) diff --git a/packages/client-sdk-nodejs/src/config/storage-configurations.ts b/packages/client-sdk-nodejs/src/config/storage-configurations.ts index 00c816eec..fbf651e2b 100644 --- a/packages/client-sdk-nodejs/src/config/storage-configurations.ts +++ b/packages/client-sdk-nodejs/src/config/storage-configurations.ts @@ -8,8 +8,6 @@ import { import { StaticStorageGrpcConfiguration, StaticStorageTransportStrategy, - StorageGrpcConfiguration, - StorageTransportStrategy, } from './transport/storage'; const defaultMaxIdleMillis = 4 * 60 * 1_000; @@ -33,32 +31,15 @@ export class Laptop extends StorageClientConfiguration { static latest( loggerFactory: MomentoLoggerFactory = defaultLoggerFactory ): StorageConfiguration { - return Laptop.v0(loggerFactory); - } - - /** - * Provides v0 recommended configuration for a laptop development environment. This configuration is guaranteed not - * to change in future releases of the Momento web SDK. - * @param {MomentoLoggerFactory} [loggerFactory=defaultLoggerFactory] - * @returns {StorageConfiguration} - */ - static v0( - loggerFactory: MomentoLoggerFactory = defaultLoggerFactory - ): StorageConfiguration { - const deadlineMillis = 5000; - const grpcConfig: StorageGrpcConfiguration = - new StaticStorageGrpcConfiguration({ - deadlineMillis, - maxSessionMemoryMb: defaultMaxSessionMemoryMb, - }); - const transportStrategy: StorageTransportStrategy = - new StaticStorageTransportStrategy({ - grpcConfiguration: grpcConfig, - maxIdleMillis: defaultMaxIdleMillis, - }); - return new Laptop({ + return new StorageClientConfiguration({ loggerFactory: loggerFactory, - transportStrategy: transportStrategy, + transportStrategy: new StaticStorageTransportStrategy({ + grpcConfiguration: new StaticStorageGrpcConfiguration({ + deadlineMillis: 5000, + maxSessionMemoryMb: defaultMaxSessionMemoryMb, + }), + maxIdleMillis: defaultMaxIdleMillis, + }), middlewares: defaultMiddlewares, throwOnErrors: false, }); diff --git a/packages/client-sdk-nodejs/src/internal/storage-control-client.ts b/packages/client-sdk-nodejs/src/internal/storage-control-client.ts index 4194ff5c7..842011a90 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-control-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-control-client.ts @@ -28,7 +28,7 @@ export class StorageControlClient { this.cacheServiceErrorMapper = new CacheServiceErrorMapper(false); const headers = [ new Header('Authorization', props.credentialProvider.getAuthToken()), - new Header('Agent', `nodejs:cache:${version}`), + new Header('Agent', `nodejs:store:${version}`), ]; this.interceptors = [ new HeaderInterceptorProvider(headers).createHeadersInterceptor(), diff --git a/packages/client-sdk-nodejs/src/preview-storage-client.ts b/packages/client-sdk-nodejs/src/preview-storage-client.ts index 503b24c62..b3d472362 100644 --- a/packages/client-sdk-nodejs/src/preview-storage-client.ts +++ b/packages/client-sdk-nodejs/src/preview-storage-client.ts @@ -11,6 +11,10 @@ import {StorageDataClient} from './internal/storage-data-client'; import {StorageConfiguration} from './config/storage-configuration'; import {StorageConfigurations} from './index'; +/** + * A client for interacting with the Momento Storage service. + * Warning: This client is in preview and may change in future releases. + */ export class PreviewStorageClient extends AbstractStorageClient implements IStorageClient diff --git a/packages/client-sdk-web/package-lock.json b/packages/client-sdk-web/package-lock.json index c8ebdc741..7115c9467 100644 --- a/packages/client-sdk-web/package-lock.json +++ b/packages/client-sdk-web/package-lock.json @@ -2709,9 +2709,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.803", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.803.tgz", - "integrity": "sha512-61H9mLzGOCLLVsnLiRzCbc63uldP0AniRYPV3hbGVtONA1pI7qSGILdbofR7A8TMbOypDocEAjH/e+9k1QIe3g==", + "version": "1.4.806", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.806.tgz", + "integrity": "sha512-nkoEX2QIB8kwCOtvtgwhXWy2IHVcOLQZu9Qo36uaGB835mdX/h8uLRlosL6QIhLVUnAiicXRW00PwaPZC74Nrg==", "dev": true }, "node_modules/emittery": { diff --git a/packages/common-integration-tests/package-lock.json b/packages/common-integration-tests/package-lock.json index f81bb1bbc..a98cfdf9d 100644 --- a/packages/common-integration-tests/package-lock.json +++ b/packages/common-integration-tests/package-lock.json @@ -2448,9 +2448,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.803", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.803.tgz", - "integrity": "sha512-61H9mLzGOCLLVsnLiRzCbc63uldP0AniRYPV3hbGVtONA1pI7qSGILdbofR7A8TMbOypDocEAjH/e+9k1QIe3g==", + "version": "1.4.806", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.806.tgz", + "integrity": "sha512-nkoEX2QIB8kwCOtvtgwhXWy2IHVcOLQZu9Qo36uaGB835mdX/h8uLRlosL6QIhLVUnAiicXRW00PwaPZC74Nrg==", "dev": true }, "node_modules/emittery": { diff --git a/packages/common-integration-tests/src/storage.ts b/packages/common-integration-tests/src/storage.ts index b3188cabb..c00888033 100644 --- a/packages/common-integration-tests/src/storage.ts +++ b/packages/common-integration-tests/src/storage.ts @@ -38,12 +38,11 @@ export function runStorageServiceTests( const listResponse = await storageClient.listStores(); switch (listResponse.type) { - // this is expected response case ListStoresResponse.Success: { - const foundStore = listResponse - .getStores() - .find(store => store.getName() === storeName); - expect(foundStore).toBeDefined(); + const storeNames = listResponse + .stores() + .map(store => store.getName()); + expect(storeNames).toContain(storeName); break; } case ListStoresResponse.Error: { @@ -166,5 +165,24 @@ export function runStorageServiceTests( } } }); + it('should return not found error for deleting a store that doesnt exist', async () => { + const storeName = 'test'; + const deleteResponse = await storageClient.deleteStore(storeName); + switch (deleteResponse.type) { + case DeleteStoreResponse.Error: { + expect(deleteResponse.errorCode()).toEqual( + MomentoErrorCode.NOT_FOUND_ERROR + ); + break; + } + default: { + throw new Error( + `expected StoreGetResponse.Error but got ${ + deleteResponse.type + } toString: ${deleteResponse.toString()}` + ); + } + } + }); }); } diff --git a/packages/core/src/auth/credential-provider.ts b/packages/core/src/auth/credential-provider.ts index 806c6089d..0f34e3b29 100644 --- a/packages/core/src/auth/credential-provider.ts +++ b/packages/core/src/auth/credential-provider.ts @@ -55,7 +55,7 @@ export abstract class CredentialProvider { abstract getControlEndpoint(): string; /** - * @returns {boolean} true if connecting to the control plane endpoint connection without TLS; false if using TLS + * @returns {boolean} true if connecting to the control plane endpoint connection with TLS; false if not using TLS */ abstract isControlEndpointSecure(): boolean; @@ -65,7 +65,7 @@ export abstract class CredentialProvider { abstract getCacheEndpoint(): string; /** - * @returns {boolean} true if connecting to the data plane endpoint connection without TLS; false if using TLS + * @returns {boolean} true if connecting to the data plane endpoint connection with TLS; false if not using TLS */ abstract isCacheEndpointSecure(): boolean; @@ -75,7 +75,7 @@ export abstract class CredentialProvider { abstract getStorageEndpoint(): string; /** - * @returns {boolean} true if connecting to the storage endpoint connection without TLS; false if using TLS + * @returns {boolean} true if connecting to the storage endpoint connection with TLS; false if not using TLS */ abstract isStorageEndpointSecure(): boolean; @@ -85,7 +85,7 @@ export abstract class CredentialProvider { abstract getTokenEndpoint(): string; /** - * @returns {boolean} true if connecting to the token endpoint connection without TLS; false if using TLS + * @returns {boolean} true if connecting to the token endpoint connection with TLS; false if not using TLS */ abstract isTokenEndpointSecure(): boolean; diff --git a/packages/core/src/messages/responses/storage/control/list-stores.ts b/packages/core/src/messages/responses/storage/control/list-stores.ts index 361b4f919..b34a96574 100644 --- a/packages/core/src/messages/responses/storage/control/list-stores.ts +++ b/packages/core/src/messages/responses/storage/control/list-stores.ts @@ -12,24 +12,24 @@ interface IResponse { */ export class Success extends BaseResponseSuccess implements IResponse { readonly type: ListStoresResponse.Success = ListStoresResponse.Success; - private readonly stores: StoreInfo[]; + private readonly _stores: StoreInfo[]; constructor(stores: StoreInfo[]) { super(); - this.stores = stores; + this._stores = stores; } /** * An array of StoreInfo, containing information about each store. * @returns {StoreInfo[]} */ - public getStores() { - return this.stores; + public stores(): StoreInfo[] { + return this._stores; } public override toString() { - const stores = this.stores.map(storeInfo => storeInfo.getName()); - return super.toString() + ': ' + stores.join(', '); + const _stores = this._stores.map(storeInfo => storeInfo.getName()); + return super.toString() + ': ' + _stores.join(', '); } } From 267ac6bdafcbf4678223a17c07e4abeede20f823 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Wed, 19 Jun 2024 16:52:35 -0700 Subject: [PATCH 11/15] fix: remove not required config --- .../src/config/storage-configuration.ts | 89 -------------- .../src/config/storage-configurations.ts | 8 -- .../transport/storage/grpc-configuration.ts | 37 ------ .../transport/storage/transport-strategy.ts | 77 ------------- .../src/internal/storage-control-client.ts | 105 ++++++++--------- .../src/internal/storage-data-client.ts | 109 +++++------------- .../src/preview-storage-client.ts | 22 ++-- .../src/config/storage-configuration.ts | 34 ------ .../src/config/storage-configurations.ts | 1 - .../src/internal/storage-control-client.ts | 41 ++----- .../src/internal/storage-data-client.ts | 42 +------ 11 files changed, 102 insertions(+), 463 deletions(-) diff --git a/packages/client-sdk-nodejs/src/config/storage-configuration.ts b/packages/client-sdk-nodejs/src/config/storage-configuration.ts index 2c319cecc..459eb5849 100644 --- a/packages/client-sdk-nodejs/src/config/storage-configuration.ts +++ b/packages/client-sdk-nodejs/src/config/storage-configuration.ts @@ -1,5 +1,4 @@ import {MomentoLoggerFactory} from '../'; -import {Middleware} from './middleware/middleware'; import {StorageTransportStrategy} from './transport/storage'; /** @@ -34,41 +33,6 @@ export interface StorageConfiguration { withTransportStrategy( transportStrategy: StorageTransportStrategy ): StorageConfiguration; - - /** - * @returns {Middleware[]} the middleware functions that will wrap each request - */ - getMiddlewares(): Middleware[]; - - /** - * Copy constructor for overriding Middlewares - * @param {Middleware[]} middlewares - * @returns {Configuration} a new Configuration object with the specified Middlewares - */ - withMiddlewares(middlewares: Middleware[]): StorageConfiguration; - - /** - * Copy constructor that adds a single middleware to the existing middlewares - * @param {Middleware} middleware - * @returns {Configuration} a new Configuration object with the specified Middleware appended to the list of existing Middlewares - */ - addMiddleware(middleware: Middleware): StorageConfiguration; - - /** - * @returns {boolean} Configures whether the client should return a Momento Error object or throw an exception when an - * error occurs. By default, this is set to false, and the client will return a Momento Error object on errors. Set it - * to true if you prefer for exceptions to be thrown. - */ - getThrowOnErrors(): boolean; - - /** - * Copy constructor for configuring whether the client should return a Momento Error object or throw an exception when an - * error occurs. By default, this is set to false, and the client will return a Momento Error object on errors. Set it - * to true if you prefer for exceptions to be thrown. - * @param {boolean} throwOnErrors - * @returns {Configuration} a new Configuration object with the specified throwOnErrors setting - */ - withThrowOnErrors(throwOnErrors: boolean): StorageConfiguration; } export interface StorageConfigurationProps { @@ -80,29 +44,15 @@ export interface StorageConfigurationProps { * Configures low-level options for network interactions with the Momento service */ transportStrategy: StorageTransportStrategy; - - /** - * Configures middleware functions that will wrap each request - */ - middlewares: Middleware[]; - - /** - * Configures whether the client should return a Momento Error object or throw an exception when an error occurs. - */ - throwOnErrors: boolean; } export class StorageClientConfiguration implements StorageConfiguration { private readonly loggerFactory: MomentoLoggerFactory; private readonly transportStrategy: StorageTransportStrategy; - private readonly middlewares: Middleware[]; - private readonly throwOnErrors: boolean; constructor(props: StorageConfigurationProps) { this.loggerFactory = props.loggerFactory; this.transportStrategy = props.transportStrategy; - this.middlewares = props.middlewares; - this.throwOnErrors = props.throwOnErrors; } getLoggerFactory(): MomentoLoggerFactory { @@ -118,8 +68,6 @@ export class StorageClientConfiguration implements StorageConfiguration { loggerFactory: this.loggerFactory, transportStrategy: this.transportStrategy.withClientTimeoutMillis(clientTimeoutMillis), - middlewares: this.middlewares, - throwOnErrors: this.throwOnErrors, }); } @@ -129,43 +77,6 @@ export class StorageClientConfiguration implements StorageConfiguration { return new StorageClientConfiguration({ loggerFactory: this.loggerFactory, transportStrategy: transportStrategy, - middlewares: this.middlewares, - throwOnErrors: this.throwOnErrors, - }); - } - - getMiddlewares(): Middleware[] { - return this.middlewares; - } - - withMiddlewares(middlewares: Middleware[]): StorageConfiguration { - return new StorageClientConfiguration({ - loggerFactory: this.loggerFactory, - transportStrategy: this.transportStrategy, - middlewares: middlewares, - throwOnErrors: this.throwOnErrors, - }); - } - - addMiddleware(middleware: Middleware): StorageConfiguration { - return new StorageClientConfiguration({ - loggerFactory: this.loggerFactory, - transportStrategy: this.transportStrategy, - middlewares: [middleware, ...this.middlewares], - throwOnErrors: this.throwOnErrors, - }); - } - - withThrowOnErrors(throwOnErrors: boolean): StorageConfiguration { - return new StorageClientConfiguration({ - loggerFactory: this.loggerFactory, - transportStrategy: this.transportStrategy, - middlewares: this.middlewares, - throwOnErrors: throwOnErrors, }); } - - getThrowOnErrors(): boolean { - return this.throwOnErrors; - } } diff --git a/packages/client-sdk-nodejs/src/config/storage-configurations.ts b/packages/client-sdk-nodejs/src/config/storage-configurations.ts index fbf651e2b..26763b3ae 100644 --- a/packages/client-sdk-nodejs/src/config/storage-configurations.ts +++ b/packages/client-sdk-nodejs/src/config/storage-configurations.ts @@ -1,6 +1,5 @@ import {MomentoLoggerFactory} from '@gomomento/sdk-core'; import {DefaultMomentoLoggerFactory} from './logging/default-momento-logger'; -import {Middleware} from './middleware/middleware'; import { StorageClientConfiguration, StorageConfiguration, @@ -10,11 +9,8 @@ import { StaticStorageTransportStrategy, } from './transport/storage'; -const defaultMaxIdleMillis = 4 * 60 * 1_000; -const defaultMaxSessionMemoryMb = 256; const defaultLoggerFactory: MomentoLoggerFactory = new DefaultMomentoLoggerFactory(); -const defaultMiddlewares: Middleware[] = []; /** * Laptop config provides defaults suitable for a medium-to-high-latency dev environment. @@ -36,12 +32,8 @@ export class Laptop extends StorageClientConfiguration { transportStrategy: new StaticStorageTransportStrategy({ grpcConfiguration: new StaticStorageGrpcConfiguration({ deadlineMillis: 5000, - maxSessionMemoryMb: defaultMaxSessionMemoryMb, }), - maxIdleMillis: defaultMaxIdleMillis, }), - middlewares: defaultMiddlewares, - throwOnErrors: false, }); } } diff --git a/packages/client-sdk-nodejs/src/config/transport/storage/grpc-configuration.ts b/packages/client-sdk-nodejs/src/config/transport/storage/grpc-configuration.ts index 5ae8672fc..67ac8b455 100644 --- a/packages/client-sdk-nodejs/src/config/transport/storage/grpc-configuration.ts +++ b/packages/client-sdk-nodejs/src/config/transport/storage/grpc-configuration.ts @@ -1,20 +1,9 @@ export interface StorageGrpcConfigurationProps { - /** - * The number of internal clients a storage client will create to communicate with Momento. More of them allows - * more concurrent requests, at the cost of more open connections and the latency of setting up each client. - */ - numClients?: number; - /** * number of milliseconds the client is willing to wait for an RPC to complete before it is terminated * with a DeadlineExceeded error. */ deadlineMillis: number; - /** - * the maximum amount of memory, in megabytes, that a session is allowed to consume. Sessions that consume - * more than this amount will return a ResourceExhausted error. - */ - maxSessionMemoryMb: number; } /** @@ -23,19 +12,6 @@ export interface StorageGrpcConfigurationProps { * @interface StorageGrpcConfiguration */ export interface StorageGrpcConfiguration { - /** - * @returns {number} the number of internal clients a storage client will create to communicate with Momento. More of - * them will allow for more concurrent requests. - */ - getNumClients(): number; - - /** - * Copy constructor for overriding the number of clients to create - * @param {number} numClients the number of internal clients to create - * @returns {GrpcConfiguration} a new GrpcConfiguration with the specified number of clients - */ - withNumClients(numClients: number): StorageGrpcConfiguration; - /** * @returns {number} number of milliseconds the client is willing to wait for an RPC to complete before it is terminated * with a DeadlineExceeded error. @@ -48,17 +24,4 @@ export interface StorageGrpcConfiguration { * @returns {StorageGrpcConfiguration} a new StorageGrpcConfiguration with the specified client-side deadline */ withDeadlineMillis(deadlineMillis: number): StorageGrpcConfiguration; - - /** - * @returns {number} the maximum amount of memory, in megabytes, that a session is allowed to consume. Sessions that consume - * more than this amount will return a ResourceExhausted error. - */ - getMaxSessionMemoryMb(): number; - - /** - * Copy constructor for overriding the max session memory - * @param {number} maxSessionMemoryMb the desired maximum amount of memory, in megabytes, to allow a client session to consume - * @returns {StorageGrpcConfiguration} a new StorageGrpcConfiguration with the specified maximum memory - */ - withMaxSessionMemoryMb(maxSessionMemoryMb: number): StorageGrpcConfiguration; } diff --git a/packages/client-sdk-nodejs/src/config/transport/storage/transport-strategy.ts b/packages/client-sdk-nodejs/src/config/transport/storage/transport-strategy.ts index c554937c7..e3c45f01a 100644 --- a/packages/client-sdk-nodejs/src/config/transport/storage/transport-strategy.ts +++ b/packages/client-sdk-nodejs/src/config/transport/storage/transport-strategy.ts @@ -28,24 +28,6 @@ export interface StorageTransportStrategy { withClientTimeoutMillis( clientTimeoutMillis: number ): StorageTransportStrategy; - - /** - * Copy constructor to update the max idle connection timeout. (See {getMaxIdleMillis}.) - * @param {number} maxIdleMillis - * @returns {StorageTransportStrategy} a new StorageTransportStrategy with the specified max idle connection timeout. - */ - withMaxIdleMillis(maxIdleMillis: number): StorageTransportStrategy; - - /** - * The maximum duration for which a connection may remain idle before being replaced. This - * setting can be used to force re-connection of a client if it has been idle for too long. - * In environments such as AWS lambda, if the lambda is suspended for too long the connection - * may be closed by the load balancer, resulting in an error on the subsequent request. If - * this setting is set to a duration less than the load balancer timeout, we can ensure that - * the connection will be refreshed to avoid errors. - * @returns {number} - */ - getMaxIdleMillis(): number; } export interface StorageTransportStrategyProps { @@ -53,45 +35,15 @@ export interface StorageTransportStrategyProps { * low-level gRPC settings for communication with the Momento server */ grpcConfiguration: StorageGrpcConfiguration; - /** - * The maximum duration for which a connection may remain idle before being replaced. This - * setting can be used to force re-connection of a client if it has been idle for too long. - * In environments such as AWS lambda, if the lambda is suspended for too long the connection - * may be closed by the load balancer, resulting in an error on the subsequent request. If - * this setting is set to a duration less than the load balancer timeout, we can ensure that - * the connection will be refreshed to avoid errors. - * @returns {number} - */ - maxIdleMillis: number; } export class StaticStorageGrpcConfiguration implements StorageGrpcConfiguration { - private readonly numClients: number; private readonly deadlineMillis: number; - private readonly maxSessionMemoryMb: number; constructor(props: StorageGrpcConfigurationProps) { - if (props.numClients !== undefined && props.numClients !== null) { - this.numClients = props.numClients; - } else { - this.numClients = 1; - } this.deadlineMillis = props.deadlineMillis; - this.maxSessionMemoryMb = props.maxSessionMemoryMb; - } - - getNumClients(): number { - return this.numClients; - } - - withNumClients(numClients: number): StorageGrpcConfiguration { - return new StaticStorageGrpcConfiguration({ - numClients: numClients, - deadlineMillis: this.deadlineMillis, - maxSessionMemoryMb: this.maxSessionMemoryMb, - }); } getDeadlineMillis(): number { @@ -101,20 +53,6 @@ export class StaticStorageGrpcConfiguration withDeadlineMillis(deadlineMillis: number): StorageGrpcConfiguration { return new StaticStorageGrpcConfiguration({ deadlineMillis: deadlineMillis, - numClients: this.numClients, - maxSessionMemoryMb: this.maxSessionMemoryMb, - }); - } - - getMaxSessionMemoryMb(): number { - return this.maxSessionMemoryMb; - } - - withMaxSessionMemoryMb(maxSessionMemoryMb: number): StorageGrpcConfiguration { - return new StaticStorageGrpcConfiguration({ - deadlineMillis: this.deadlineMillis, - numClients: this.numClients, - maxSessionMemoryMb: maxSessionMemoryMb, }); } } @@ -123,11 +61,9 @@ export class StaticStorageTransportStrategy implements StorageTransportStrategy { private readonly grpcConfig: StorageGrpcConfiguration; - private readonly maxIdleMillis: number; constructor(props: StorageTransportStrategyProps) { this.grpcConfig = props.grpcConfiguration; - this.maxIdleMillis = props.maxIdleMillis; } getGrpcConfig(): StorageGrpcConfiguration { @@ -139,7 +75,6 @@ export class StaticStorageTransportStrategy ): StorageTransportStrategy { return new StaticStorageTransportStrategy({ grpcConfiguration: grpcConfig, - maxIdleMillis: this.maxIdleMillis, }); } @@ -149,18 +84,6 @@ export class StaticStorageTransportStrategy return new StaticStorageTransportStrategy({ grpcConfiguration: this.grpcConfig.withDeadlineMillis(clientTimeoutMillis), - maxIdleMillis: this.maxIdleMillis, - }); - } - - getMaxIdleMillis(): number { - return this.maxIdleMillis; - } - - withMaxIdleMillis(maxIdleMillis: number): StorageTransportStrategy { - return new StaticStorageTransportStrategy({ - grpcConfiguration: this.grpcConfig, - maxIdleMillis: maxIdleMillis, }); } } diff --git a/packages/client-sdk-nodejs/src/internal/storage-control-client.ts b/packages/client-sdk-nodejs/src/internal/storage-control-client.ts index 842011a90..3f0f4a293 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-control-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-control-client.ts @@ -7,14 +7,12 @@ import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; import {ChannelCredentials, Interceptor} from '@grpc/grpc-js'; import {MomentoLogger, StoreInfo, ListStores} from '..'; import {version} from '../../package.json'; -import {IdleGrpcClientWrapper} from './grpc/idle-grpc-client-wrapper'; -import {GrpcClientWrapper} from './grpc/grpc-client-wrapper'; import {validateStoreName} from '@gomomento/sdk-core/dist/src/internal/utils'; import {CreateStore, DeleteStore} from '@gomomento/sdk-core'; import {StorageClientPropsWithConfig} from './storage-client-props-with-config'; export class StorageControlClient { - private readonly clientWrapper: GrpcClientWrapper; + private readonly client: grpcControl.ScsControlClient; private readonly interceptors: Interceptor[]; private static readonly REQUEST_TIMEOUT_MS: number = 60 * 1000; private readonly logger: MomentoLogger; @@ -37,24 +35,17 @@ export class StorageControlClient { this.logger.debug( `Creating storage control client using endpoint: '${props.credentialProvider.getControlEndpoint()}` ); - this.clientWrapper = new IdleGrpcClientWrapper({ - clientFactoryFn: () => - new grpcControl.ScsControlClient( - props.credentialProvider.getControlEndpoint(), - props.credentialProvider.isControlEndpointSecure() - ? ChannelCredentials.createSsl() - : ChannelCredentials.createInsecure() - ), - loggerFactory: props.configuration.getLoggerFactory(), - maxIdleMillis: props.configuration - .getTransportStrategy() - .getGrpcConfig() - .getDeadlineMillis(), - }); + + this.client = new grpcControl.ScsControlClient( + props.credentialProvider.getControlEndpoint(), + props.credentialProvider.isControlEndpointSecure() + ? ChannelCredentials.createSsl() + : ChannelCredentials.createInsecure() + ); } close() { this.logger.debug('Closing storage control client'); - this.clientWrapper.getClient().close(); + this.client.close(); } public async createStore(name: string): Promise { @@ -71,28 +62,26 @@ export class StorageControlClient { store_name: name, }); return await new Promise((resolve, reject) => { - this.clientWrapper - .getClient() - .CreateStore( - request, - {interceptors: this.interceptors}, - (err, _resp) => { - if (err) { - if (err.code === Status.ALREADY_EXISTS) { - resolve(new CreateStore.AlreadyExists()); - } else { - this.cacheServiceErrorMapper.resolveOrRejectError({ - err: err, - errorResponseFactoryFn: e => new CreateStore.Error(e), - resolveFn: resolve, - rejectFn: reject, - }); - } + this.client.CreateStore( + request, + {interceptors: this.interceptors}, + (err, _resp) => { + if (err) { + if (err.code === Status.ALREADY_EXISTS) { + resolve(new CreateStore.AlreadyExists()); } else { - resolve(new CreateStore.Success()); + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new CreateStore.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } + } else { + resolve(new CreateStore.Success()); } - ); + } + ); }); } @@ -110,24 +99,22 @@ export class StorageControlClient { }); this.logger.debug(`Deleting store: ${name}`); return await new Promise((resolve, reject) => { - this.clientWrapper - .getClient() - .DeleteStore( - request, - {interceptors: this.interceptors}, - (err, _resp) => { - if (err) { - this.cacheServiceErrorMapper.resolveOrRejectError({ - err: err, - errorResponseFactoryFn: e => new DeleteStore.Error(e), - resolveFn: resolve, - rejectFn: reject, - }); - } else { - resolve(new DeleteStore.Success()); - } + this.client.DeleteStore( + request, + {interceptors: this.interceptors}, + (err, _resp) => { + if (err) { + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new DeleteStore.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); + } else { + resolve(new DeleteStore.Success()); } - ); + } + ); }); } @@ -136,9 +123,10 @@ export class StorageControlClient { request.next_token = ''; this.logger.debug("Issuing 'listStores' request"); return await new Promise((resolve, reject) => { - this.clientWrapper - .getClient() - .ListStores(request, {interceptors: this.interceptors}, (err, resp) => { + this.client.ListStores( + request, + {interceptors: this.interceptors}, + (err, resp) => { if (err || !resp) { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, @@ -153,7 +141,8 @@ export class StorageControlClient { }); resolve(new ListStores.Success(stores)); } - }); + } + ); }); } } diff --git a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts index 9d2292974..7fdbdf901 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts @@ -11,11 +11,8 @@ import { } from '@gomomento/sdk-core'; import {validateStoreName} from '@gomomento/sdk-core/dist/src/internal/utils'; import {store} from '@gomomento/generated-types/dist/store'; -import {IdleGrpcClientWrapper} from './grpc/idle-grpc-client-wrapper'; -import {GrpcClientWrapper} from './grpc/grpc-client-wrapper'; import {Header, HeaderInterceptorProvider} from './grpc/headers-interceptor'; import {ClientTimeoutInterceptor} from './grpc/client-timeout-interceptor'; -import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; import { ChannelCredentials, Interceptor, @@ -23,38 +20,26 @@ import { ServiceError, } from '@grpc/grpc-js'; import {version} from '../../package.json'; -import {middlewaresInterceptor} from './grpc/middlewares-interceptor'; -import { - Middleware, - MiddlewareRequestHandlerContext, -} from '../config/middleware/middleware'; import {grpcChannelOptionsFromGrpcConfig} from './grpc/grpc-channel-options'; import {IStorageDataClient} from '@gomomento/sdk-core/dist/src/internal/clients'; import {StorageConfiguration} from '../config/storage-configuration'; import {StorageClientPropsWithConfig} from './storage-client-props-with-config'; import {StaticGrpcConfiguration} from '../config/transport/cache'; -export const CONNECTION_ID_KEY = Symbol('connectionID'); - export class StorageDataClient implements IStorageDataClient { private readonly configuration: StorageConfiguration; private readonly credentialProvider: CredentialProvider; private readonly logger: MomentoLogger; - private readonly cacheServiceErrorMapper: CacheServiceErrorMapper; private readonly requestTimeoutMs: number; - private readonly clientWrapper: GrpcClientWrapper; + private readonly client: store.StoreClient; private readonly interceptors: Interceptor[]; private static readonly DEFAULT_MAX_SESSION_MEMORY_MB: number = 256; /** * @param {StorageClientPropsWithConfig} props - * @param dataClientID */ - constructor(props: StorageClientPropsWithConfig, dataClientID: string) { + constructor(props: StorageClientPropsWithConfig) { this.configuration = props.configuration; - this.cacheServiceErrorMapper = new CacheServiceErrorMapper( - props.configuration.getThrowOnErrors() - ); this.credentialProvider = props.credentialProvider; this.logger = this.configuration.getLoggerFactory().getLogger(this); this.requestTimeoutMs = this.configuration @@ -77,33 +62,21 @@ export class StorageDataClient implements IStorageDataClient { }); const channelOptions = grpcChannelOptionsFromGrpcConfig(grpcConfig); - this.clientWrapper = new IdleGrpcClientWrapper({ - clientFactoryFn: () => - new store.StoreClient( - this.credentialProvider.getStorageEndpoint(), - this.credentialProvider.isStorageEndpointSecure() - ? ChannelCredentials.createSsl() - : ChannelCredentials.createInsecure(), - channelOptions - ), - loggerFactory: this.configuration.getLoggerFactory(), - maxIdleMillis: this.configuration - .getTransportStrategy() - .getMaxIdleMillis(), - }); - - const context: MiddlewareRequestHandlerContext = {}; - context[CONNECTION_ID_KEY] = dataClientID; + this.client = new store.StoreClient( + this.credentialProvider.getStorageEndpoint(), + this.credentialProvider.isStorageEndpointSecure() + ? ChannelCredentials.createSsl() + : ChannelCredentials.createInsecure(), + channelOptions + ); this.interceptors = this.initializeInterceptors( - this.configuration.getLoggerFactory(), - this.configuration.getMiddlewares(), - context + this.configuration.getLoggerFactory() ); } close() { this.logger.debug('Closing storage data clients'); - this.clientWrapper.getClient().close(); + this.client.close(); } private validateRequestTimeout(timeout?: number) { @@ -116,20 +89,13 @@ export class StorageDataClient implements IStorageDataClient { } private initializeInterceptors( - _loggerFactory: MomentoLoggerFactory, - middlewares: Middleware[], - middlewareRequestContext: MiddlewareRequestHandlerContext + _loggerFactory: MomentoLoggerFactory ): Interceptor[] { const headers = [ new Header('Authorization', this.credentialProvider.getAuthToken()), new Header('Agent', `nodejs:store:${version}`), ]; return [ - middlewaresInterceptor( - _loggerFactory, - middlewares, - middlewareRequestContext - ), new HeaderInterceptorProvider(headers).createHeadersInterceptor(), ClientTimeoutInterceptor(this.requestTimeoutMs), ]; @@ -148,10 +114,7 @@ export class StorageDataClient implements IStorageDataClient { try { validateStoreName(storeName); } catch (err) { - return this.cacheServiceErrorMapper.returnOrThrowError( - err as Error, - err => new StorageGet.Error(err) - ); + return new StorageGet.Error(err as SdkError); } this.logger.trace( `Issuing 'get' request; store: ${storeName}, key: ${key}` @@ -168,7 +131,7 @@ export class StorageDataClient implements IStorageDataClient { }); const metadata = this.createMetadata(storeName); return await new Promise((resolve, reject) => { - this.clientWrapper.getClient().Get( + this.client.Get( request, metadata, { @@ -209,12 +172,7 @@ export class StorageDataClient implements IStorageDataClient { } } } else { - this.cacheServiceErrorMapper.resolveOrRejectError({ - err: err, - errorResponseFactoryFn: (e: SdkError) => new StorageGet.Error(e), - resolveFn: resolve, - rejectFn: reject, - }); + return resolve(new StorageGet.Error(err as unknown as SdkError)); } } ); @@ -229,10 +187,11 @@ export class StorageDataClient implements IStorageDataClient { try { validateStoreName(storeName); } catch (err) { - return this.cacheServiceErrorMapper.returnOrThrowError( - err as Error, - err => new StoragePut.Error(err) - ); + return new StoragePut.Error(err as SdkError); + // return this.cacheServiceErrorMapper.returnOrThrowError( + // err as Error, + // err => new StoragePut.Error(err) + // ); } this.logger.trace( `Issuing 'put' request; store: ${storeName}, key: ${key}` @@ -263,7 +222,7 @@ export class StorageDataClient implements IStorageDataClient { }); const metadata = this.createMetadata(storeName); return await new Promise((resolve, reject) => { - this.clientWrapper.getClient().Put( + this.client.Put( request, metadata, { @@ -273,12 +232,7 @@ export class StorageDataClient implements IStorageDataClient { if (resp) { resolve(new StoragePut.Success()); } else { - this.cacheServiceErrorMapper.resolveOrRejectError({ - err: err, - errorResponseFactoryFn: (e: SdkError) => new StoragePut.Error(e), - resolveFn: resolve, - rejectFn: reject, - }); + return resolve(new StoragePut.Error(err as unknown as SdkError)); } } ); @@ -292,10 +246,11 @@ export class StorageDataClient implements IStorageDataClient { try { validateStoreName(storeName); } catch (err) { - return this.cacheServiceErrorMapper.returnOrThrowError( - err as Error, - err => new StorageDelete.Error(err) - ); + return new StorageDelete.Error(err as SdkError); + // return this.cacheServiceErrorMapper.returnOrThrowError( + // err as Error, + // err => new StorageDelete.Error(err) + // ); } this.logger.trace( `Issuing 'delete' request; store: ${storeName}, key: ${key}` @@ -312,7 +267,7 @@ export class StorageDataClient implements IStorageDataClient { }); const metadata = this.createMetadata(storeName); return await new Promise((resolve, reject) => { - this.clientWrapper.getClient().Delete( + this.client.Delete( request, metadata, { @@ -322,13 +277,7 @@ export class StorageDataClient implements IStorageDataClient { if (resp) { resolve(new StorageDelete.Success()); } else { - this.cacheServiceErrorMapper.resolveOrRejectError({ - err: err, - errorResponseFactoryFn: (e: SdkError) => - new StorageDelete.Error(e), - resolveFn: resolve, - rejectFn: reject, - }); + return resolve(new StorageDelete.Error(err as unknown as SdkError)); } } ); diff --git a/packages/client-sdk-nodejs/src/preview-storage-client.ts b/packages/client-sdk-nodejs/src/preview-storage-client.ts index b3d472362..87cec74b8 100644 --- a/packages/client-sdk-nodejs/src/preview-storage-client.ts +++ b/packages/client-sdk-nodejs/src/preview-storage-client.ts @@ -30,8 +30,10 @@ export class PreviewStorageClient const controlClient: IStorageControlClient = createControlClient( propsWithConfiguration ); - const dataClients = createDataClients(propsWithConfiguration); - super(dataClients, controlClient); + const dataClient: IStorageDataClient = createDataClient( + propsWithConfiguration + ); + super([dataClient], controlClient); } close(): void { @@ -49,17 +51,13 @@ function createControlClient( }); } -function createDataClients( +function createDataClient( props: StorageClientPropsWithConfig -): IStorageDataClient[] { - const numClients = props.configuration - .getTransportStrategy() - .getGrpcConfig() - .getNumClients(); - return Array.from( - {length: numClients}, - (_, i) => new StorageDataClient(props, i.toString()) - ); +): IStorageDataClient { + return new StorageDataClient({ + configuration: props.configuration, + credentialProvider: props.credentialProvider, + }); } function getDefaultStorageConfiguration(): StorageConfiguration { diff --git a/packages/client-sdk-web/src/config/storage-configuration.ts b/packages/client-sdk-web/src/config/storage-configuration.ts index ed5ef07c0..ea066ea73 100644 --- a/packages/client-sdk-web/src/config/storage-configuration.ts +++ b/packages/client-sdk-web/src/config/storage-configuration.ts @@ -5,11 +5,6 @@ export interface StorageConfigurationProps { * Configures logging verbosity and format */ loggerFactory: MomentoLoggerFactory; - - /** - * Configures whether the client should return a Momento Error object or throw an exception when an error occurs. - */ - throwOnErrors: boolean; } /** @@ -23,45 +18,16 @@ export interface StorageConfiguration { * @returns {MomentoLoggerFactory} the current configuration options for logging verbosity and format */ getLoggerFactory(): MomentoLoggerFactory; - - /** - * @returns {boolean} Configures whether the client should return a Momento Error object or throw an exception when an - * error occurs. By default, this is set to false, and the client will return a Momento Error object on errors. Set it - * to true if you prefer for exceptions to be thrown. - */ - getThrowOnErrors(): boolean; - - /** - * Copy constructor for configuring whether the client should return a Momento Error object or throw an exception when an - * error occurs. By default, this is set to false, and the client will return a Momento Error object on errors. Set it - * to true if you prefer for exceptions to be thrown. - * @param {boolean} throwOnErrors - * @returns {Configuration} a new Configuration object with the specified throwOnErrors setting - */ - withThrowOnErrors(throwOnErrors: boolean): StorageConfiguration; } export class StorageClientConfiguration implements StorageConfiguration { private readonly loggerFactory: MomentoLoggerFactory; - private readonly throwOnErrors: boolean; constructor(props: StorageConfigurationProps) { this.loggerFactory = props.loggerFactory; - this.throwOnErrors = props.throwOnErrors; } getLoggerFactory(): MomentoLoggerFactory { return this.loggerFactory; } - - getThrowOnErrors(): boolean { - return this.throwOnErrors; - } - - withThrowOnErrors(throwOnErrors: boolean): StorageConfiguration { - return new StorageClientConfiguration({ - loggerFactory: this.loggerFactory, - throwOnErrors: throwOnErrors, - }); - } } diff --git a/packages/client-sdk-web/src/config/storage-configurations.ts b/packages/client-sdk-web/src/config/storage-configurations.ts index 944ba38bd..b460aa3c8 100644 --- a/packages/client-sdk-web/src/config/storage-configurations.ts +++ b/packages/client-sdk-web/src/config/storage-configurations.ts @@ -25,7 +25,6 @@ export class Default extends StorageClientConfiguration { ): StorageConfiguration { return new StorageClientConfiguration({ loggerFactory: loggerFactory, - throwOnErrors: false, }); } } diff --git a/packages/client-sdk-web/src/internal/storage-control-client.ts b/packages/client-sdk-web/src/internal/storage-control-client.ts index e09bdf9d4..a96e58082 100644 --- a/packages/client-sdk-web/src/internal/storage-control-client.ts +++ b/packages/client-sdk-web/src/internal/storage-control-client.ts @@ -6,6 +6,7 @@ import { DeleteStore, ListStores, StoreInfo, + SdkError, } from '..'; import {Request, StatusCode, UnaryResponse} from 'grpc-web'; import { @@ -13,7 +14,6 @@ import { _DeleteStoreRequest, _ListStoresRequest, } from '@gomomento/generated-types-webtext/dist/controlclient_pb'; -import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; import {IStorageControlClient} from '@gomomento/sdk-core/dist/src/internal/clients'; import {validateStoreName} from '@gomomento/sdk-core/dist/src/internal/utils'; import {getWebControlEndpoint} from '../utils/web-client-utils'; @@ -32,7 +32,6 @@ export class StorageControlClient< { private readonly clientWrapper: control.ScsControlClient; private readonly logger: MomentoLogger; - private readonly cacheServiceErrorMapper: CacheServiceErrorMapper; private readonly clientMetadataProvider: ClientMetadataProvider; @@ -41,9 +40,6 @@ export class StorageControlClient< */ constructor(props: StorageClientClientProps) { this.logger = props.configuration.getLoggerFactory().getLogger(this); - this.cacheServiceErrorMapper = new CacheServiceErrorMapper( - props.configuration.getThrowOnErrors() - ); this.logger.debug( `Creating storage control client using endpoint: '${getWebControlEndpoint( props.credentialProvider @@ -73,10 +69,7 @@ export class StorageControlClient< try { validateStoreName(name); } catch (err) { - return this.cacheServiceErrorMapper.returnOrThrowError( - err as Error, - err => new CreateStore.Error(err) - ); + return new CreateStore.Error(err as SdkError); } this.logger.debug(`Creating store: ${name}`); const request = new _CreateStoreRequest(); @@ -91,12 +84,7 @@ export class StorageControlClient< if (err.code === StatusCode.ALREADY_EXISTS) { resolve(new CreateStore.AlreadyExists()); } else { - this.cacheServiceErrorMapper.resolveOrRejectError({ - err: err, - errorResponseFactoryFn: e => new CreateStore.Error(e), - resolveFn: resolve, - rejectFn: reject, - }); + return resolve(new CreateStore.Error(err as unknown as SdkError)); } } else { resolve(new CreateStore.Success()); @@ -110,10 +98,11 @@ export class StorageControlClient< try { validateStoreName(name); } catch (err) { - return this.cacheServiceErrorMapper.returnOrThrowError( - err as Error, - err => new DeleteStore.Error(err) - ); + return new DeleteStore.Error(err as SdkError); + // return this.cacheServiceErrorMapper.returnOrThrowError( + // err as Error, + // err => new DeleteStore.Error(err) + // ); } const request = new _DeleteStoreRequest(); request.setStoreName(name); @@ -124,12 +113,7 @@ export class StorageControlClient< this.clientMetadataProvider.createClientMetadata(), (err, _resp) => { if (err) { - this.cacheServiceErrorMapper.resolveOrRejectError({ - err: err, - errorResponseFactoryFn: e => new DeleteStore.Error(e), - resolveFn: resolve, - rejectFn: reject, - }); + return resolve(new DeleteStore.Error(err as unknown as SdkError)); } else { resolve(new DeleteStore.Success()); } @@ -148,12 +132,7 @@ export class StorageControlClient< this.clientMetadataProvider.createClientMetadata(), (err, resp) => { if (err) { - this.cacheServiceErrorMapper.resolveOrRejectError({ - err: err, - errorResponseFactoryFn: e => new ListStores.Error(e), - resolveFn: resolve, - rejectFn: reject, - }); + return resolve(new ListStores.Error(err as unknown as SdkError)); } else { const stores = resp.getStoreList().map(store => { const storeName = store.getStoreName(); diff --git a/packages/client-sdk-web/src/internal/storage-data-client.ts b/packages/client-sdk-web/src/internal/storage-data-client.ts index 33e4d2479..3f251696d 100644 --- a/packages/client-sdk-web/src/internal/storage-data-client.ts +++ b/packages/client-sdk-web/src/internal/storage-data-client.ts @@ -8,7 +8,6 @@ import { UnknownError, } from '..'; import {Request, UnaryResponse} from 'grpc-web'; -import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; import { _StoreDeleteRequest, _StoreGetRequest, @@ -39,7 +38,6 @@ export class StorageDataClient< { private readonly clientWrapper: store.StoreClient; private readonly logger: MomentoLogger; - private readonly cacheServiceErrorMapper: CacheServiceErrorMapper; private readonly clientMetadataProvider: ClientMetadataProvider; // TODO make this part of configuration private readonly deadlineMillis: number = 10000; @@ -49,9 +47,6 @@ export class StorageDataClient< */ constructor(props: StorageDataClientProps) { this.logger = props.configuration.getLoggerFactory().getLogger(this); - this.cacheServiceErrorMapper = new CacheServiceErrorMapper( - props.configuration.getThrowOnErrors() - ); this.logger.debug( `Creating storage data client using endpoint: '${getWebStorageEndpoint( props.credentialProvider @@ -83,10 +78,7 @@ export class StorageDataClient< try { validateStoreName(storeName); } catch (err) { - return this.cacheServiceErrorMapper.returnOrThrowError( - err as Error, - err => new StorageGet.Error(err) - ); + return new StorageGet.Error(err as SdkError); } this.logger.trace(`Issuing 'get' request; key: ${key.toString()}`); const result = await this.sendGet(storeName, convertToB64String(key)); @@ -144,12 +136,7 @@ export class StorageDataClient< } } } else { - this.cacheServiceErrorMapper.resolveOrRejectError({ - err: err, - errorResponseFactoryFn: (e: SdkError) => new StorageGet.Error(e), - resolveFn: resolve, - rejectFn: reject, - }); + return resolve(new StorageGet.Error(err as unknown as SdkError)); } } ); @@ -164,10 +151,7 @@ export class StorageDataClient< try { validateStoreName(storeName); } catch (err) { - return this.cacheServiceErrorMapper.returnOrThrowError( - err as Error, - err => new StoragePut.Error(err) - ); + return new StoragePut.Error(err as SdkError); } this.logger.trace(`Issuing 'put' request; key: ${key.toString()}`); const result = await this.sendPut( @@ -215,12 +199,7 @@ export class StorageDataClient< }, (err, _resp) => { if (err) { - this.cacheServiceErrorMapper.resolveOrRejectError({ - err: err, - errorResponseFactoryFn: (e: SdkError) => new StoragePut.Error(e), - resolveFn: resolve, - rejectFn: reject, - }); + return resolve(new StoragePut.Error(err as unknown as SdkError)); } else { resolve(new StoragePut.Success()); } @@ -236,10 +215,7 @@ export class StorageDataClient< try { validateStoreName(storeName); } catch (err) { - return this.cacheServiceErrorMapper.returnOrThrowError( - err as Error, - err => new StorageDelete.Error(err) - ); + return new StorageDelete.Error(err as SdkError); } this.logger.trace(`Issuing 'delete' request; key: ${key.toString()}`); const result = await this.sendDelete(storeName, convertToB64String(key)); @@ -263,13 +239,7 @@ export class StorageDataClient< }, (err, _resp) => { if (err) { - this.cacheServiceErrorMapper.resolveOrRejectError({ - err: err, - errorResponseFactoryFn: (e: SdkError) => - new StorageDelete.Error(e), - resolveFn: resolve, - rejectFn: reject, - }); + return resolve(new StorageDelete.Error(err as unknown as SdkError)); } else { resolve(new StorageDelete.Success()); } From 3009cb0693aaa823a52718c270b17c75f0a121fe Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Wed, 19 Jun 2024 18:13:00 -0700 Subject: [PATCH 12/15] fix: error mapper changes --- .../src/internal/storage-control-client.ts | 12 ++--- .../src/internal/storage-data-client.ts | 48 +++++++++++++------ .../src/internal/client-metadata-provider.ts | 1 - .../src/internal/storage-control-client.ts | 39 +++++++++++---- .../src/internal/storage-data-client.ts | 46 +++++++++++++----- 5 files changed, 101 insertions(+), 45 deletions(-) diff --git a/packages/client-sdk-nodejs/src/internal/storage-control-client.ts b/packages/client-sdk-nodejs/src/internal/storage-control-client.ts index 3f0f4a293..4b83b3b0d 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-control-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-control-client.ts @@ -12,7 +12,7 @@ import {CreateStore, DeleteStore} from '@gomomento/sdk-core'; import {StorageClientPropsWithConfig} from './storage-client-props-with-config'; export class StorageControlClient { - private readonly client: grpcControl.ScsControlClient; + private readonly clientWrapper: grpcControl.ScsControlClient; private readonly interceptors: Interceptor[]; private static readonly REQUEST_TIMEOUT_MS: number = 60 * 1000; private readonly logger: MomentoLogger; @@ -36,7 +36,7 @@ export class StorageControlClient { `Creating storage control client using endpoint: '${props.credentialProvider.getControlEndpoint()}` ); - this.client = new grpcControl.ScsControlClient( + this.clientWrapper = new grpcControl.ScsControlClient( props.credentialProvider.getControlEndpoint(), props.credentialProvider.isControlEndpointSecure() ? ChannelCredentials.createSsl() @@ -45,7 +45,7 @@ export class StorageControlClient { } close() { this.logger.debug('Closing storage control client'); - this.client.close(); + this.clientWrapper.close(); } public async createStore(name: string): Promise { @@ -62,7 +62,7 @@ export class StorageControlClient { store_name: name, }); return await new Promise((resolve, reject) => { - this.client.CreateStore( + this.clientWrapper.CreateStore( request, {interceptors: this.interceptors}, (err, _resp) => { @@ -99,7 +99,7 @@ export class StorageControlClient { }); this.logger.debug(`Deleting store: ${name}`); return await new Promise((resolve, reject) => { - this.client.DeleteStore( + this.clientWrapper.DeleteStore( request, {interceptors: this.interceptors}, (err, _resp) => { @@ -123,7 +123,7 @@ export class StorageControlClient { request.next_token = ''; this.logger.debug("Issuing 'listStores' request"); return await new Promise((resolve, reject) => { - this.client.ListStores( + this.clientWrapper.ListStores( request, {interceptors: this.interceptors}, (err, resp) => { diff --git a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts index 7fdbdf901..255c54ef4 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts @@ -7,7 +7,6 @@ import { StoragePut, StorageDelete, UnknownError, - SdkError, } from '@gomomento/sdk-core'; import {validateStoreName} from '@gomomento/sdk-core/dist/src/internal/utils'; import {store} from '@gomomento/generated-types/dist/store'; @@ -25,10 +24,12 @@ import {IStorageDataClient} from '@gomomento/sdk-core/dist/src/internal/clients' import {StorageConfiguration} from '../config/storage-configuration'; import {StorageClientPropsWithConfig} from './storage-client-props-with-config'; import {StaticGrpcConfiguration} from '../config/transport/cache'; +import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; export class StorageDataClient implements IStorageDataClient { private readonly configuration: StorageConfiguration; private readonly credentialProvider: CredentialProvider; + private readonly cacheServiceErrorMapper: CacheServiceErrorMapper; private readonly logger: MomentoLogger; private readonly requestTimeoutMs: number; private readonly client: store.StoreClient; @@ -41,6 +42,7 @@ export class StorageDataClient implements IStorageDataClient { constructor(props: StorageClientPropsWithConfig) { this.configuration = props.configuration; this.credentialProvider = props.credentialProvider; + this.cacheServiceErrorMapper = new CacheServiceErrorMapper(false); this.logger = this.configuration.getLoggerFactory().getLogger(this); this.requestTimeoutMs = this.configuration .getTransportStrategy() @@ -114,7 +116,10 @@ export class StorageDataClient implements IStorageDataClient { try { validateStoreName(storeName); } catch (err) { - return new StorageGet.Error(err as SdkError); + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StorageGet.Error(err) + ); } this.logger.trace( `Issuing 'get' request; store: ${storeName}, key: ${key}` @@ -172,7 +177,12 @@ export class StorageDataClient implements IStorageDataClient { } } } else { - return resolve(new StorageGet.Error(err as unknown as SdkError)); + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new StorageGet.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -187,11 +197,10 @@ export class StorageDataClient implements IStorageDataClient { try { validateStoreName(storeName); } catch (err) { - return new StoragePut.Error(err as SdkError); - // return this.cacheServiceErrorMapper.returnOrThrowError( - // err as Error, - // err => new StoragePut.Error(err) - // ); + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StoragePut.Error(err) + ); } this.logger.trace( `Issuing 'put' request; store: ${storeName}, key: ${key}` @@ -232,7 +241,12 @@ export class StorageDataClient implements IStorageDataClient { if (resp) { resolve(new StoragePut.Success()); } else { - return resolve(new StoragePut.Error(err as unknown as SdkError)); + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new StoragePut.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -246,11 +260,10 @@ export class StorageDataClient implements IStorageDataClient { try { validateStoreName(storeName); } catch (err) { - return new StorageDelete.Error(err as SdkError); - // return this.cacheServiceErrorMapper.returnOrThrowError( - // err as Error, - // err => new StorageDelete.Error(err) - // ); + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StorageDelete.Error(err) + ); } this.logger.trace( `Issuing 'delete' request; store: ${storeName}, key: ${key}` @@ -277,7 +290,12 @@ export class StorageDataClient implements IStorageDataClient { if (resp) { resolve(new StorageDelete.Success()); } else { - return resolve(new StorageDelete.Error(err as unknown as SdkError)); + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new StorageDelete.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); diff --git a/packages/client-sdk-web/src/internal/client-metadata-provider.ts b/packages/client-sdk-web/src/internal/client-metadata-provider.ts index 3d94e9cbe..e21205a1f 100644 --- a/packages/client-sdk-web/src/internal/client-metadata-provider.ts +++ b/packages/client-sdk-web/src/internal/client-metadata-provider.ts @@ -39,7 +39,6 @@ export class ClientMetadataProvider { metadata['Runtime-Version'] = `javascript-web:${getBrowserName( navigator.userAgent )}`; - console.log('web metadata:', metadata); } if (this.readConcern) { metadata['read-concern'] = this.readConcern; diff --git a/packages/client-sdk-web/src/internal/storage-control-client.ts b/packages/client-sdk-web/src/internal/storage-control-client.ts index a96e58082..f50538cf4 100644 --- a/packages/client-sdk-web/src/internal/storage-control-client.ts +++ b/packages/client-sdk-web/src/internal/storage-control-client.ts @@ -6,7 +6,6 @@ import { DeleteStore, ListStores, StoreInfo, - SdkError, } from '..'; import {Request, StatusCode, UnaryResponse} from 'grpc-web'; import { @@ -19,6 +18,7 @@ import {validateStoreName} from '@gomomento/sdk-core/dist/src/internal/utils'; import {getWebControlEndpoint} from '../utils/web-client-utils'; import {ClientMetadataProvider} from './client-metadata-provider'; import {StorageConfiguration} from '../config/storage-configuration'; +import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; export interface StorageClientClientProps { configuration: StorageConfiguration; @@ -32,6 +32,7 @@ export class StorageControlClient< { private readonly clientWrapper: control.ScsControlClient; private readonly logger: MomentoLogger; + private readonly cacheServiceErrorMapper: CacheServiceErrorMapper; private readonly clientMetadataProvider: ClientMetadataProvider; @@ -40,6 +41,7 @@ export class StorageControlClient< */ constructor(props: StorageClientClientProps) { this.logger = props.configuration.getLoggerFactory().getLogger(this); + this.cacheServiceErrorMapper = new CacheServiceErrorMapper(false); this.logger.debug( `Creating storage control client using endpoint: '${getWebControlEndpoint( props.credentialProvider @@ -69,7 +71,10 @@ export class StorageControlClient< try { validateStoreName(name); } catch (err) { - return new CreateStore.Error(err as SdkError); + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new CreateStore.Error(err) + ); } this.logger.debug(`Creating store: ${name}`); const request = new _CreateStoreRequest(); @@ -84,7 +89,12 @@ export class StorageControlClient< if (err.code === StatusCode.ALREADY_EXISTS) { resolve(new CreateStore.AlreadyExists()); } else { - return resolve(new CreateStore.Error(err as unknown as SdkError)); + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new CreateStore.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } else { resolve(new CreateStore.Success()); @@ -98,11 +108,10 @@ export class StorageControlClient< try { validateStoreName(name); } catch (err) { - return new DeleteStore.Error(err as SdkError); - // return this.cacheServiceErrorMapper.returnOrThrowError( - // err as Error, - // err => new DeleteStore.Error(err) - // ); + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new DeleteStore.Error(err) + ); } const request = new _DeleteStoreRequest(); request.setStoreName(name); @@ -113,7 +122,12 @@ export class StorageControlClient< this.clientMetadataProvider.createClientMetadata(), (err, _resp) => { if (err) { - return resolve(new DeleteStore.Error(err as unknown as SdkError)); + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new DeleteStore.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new DeleteStore.Success()); } @@ -132,7 +146,12 @@ export class StorageControlClient< this.clientMetadataProvider.createClientMetadata(), (err, resp) => { if (err) { - return resolve(new ListStores.Error(err as unknown as SdkError)); + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new ListStores.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { const stores = resp.getStoreList().map(store => { const storeName = store.getStoreName(); diff --git a/packages/client-sdk-web/src/internal/storage-data-client.ts b/packages/client-sdk-web/src/internal/storage-data-client.ts index 3f251696d..4816c518b 100644 --- a/packages/client-sdk-web/src/internal/storage-data-client.ts +++ b/packages/client-sdk-web/src/internal/storage-data-client.ts @@ -24,7 +24,7 @@ import { import {ClientMetadataProvider} from './client-metadata-provider'; import ValueCase = _StoreValue.ValueCase; import {StorageConfiguration} from '../config/storage-configuration'; -import {SdkError} from '@gomomento/sdk-core'; +import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; export interface StorageDataClientProps { configuration: StorageConfiguration; @@ -37,6 +37,7 @@ export class StorageDataClient< > implements IStorageDataClient { private readonly clientWrapper: store.StoreClient; + private readonly cacheServiceErrorMapper: CacheServiceErrorMapper; private readonly logger: MomentoLogger; private readonly clientMetadataProvider: ClientMetadataProvider; // TODO make this part of configuration @@ -46,6 +47,7 @@ export class StorageDataClient< * @param {DataClientProps} props */ constructor(props: StorageDataClientProps) { + this.cacheServiceErrorMapper = new CacheServiceErrorMapper(false); this.logger = props.configuration.getLoggerFactory().getLogger(this); this.logger.debug( `Creating storage data client using endpoint: '${getWebStorageEndpoint( @@ -78,7 +80,10 @@ export class StorageDataClient< try { validateStoreName(storeName); } catch (err) { - return new StorageGet.Error(err as SdkError); + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StorageGet.Error(err) + ); } this.logger.trace(`Issuing 'get' request; key: ${key.toString()}`); const result = await this.sendGet(storeName, convertToB64String(key)); @@ -136,7 +141,12 @@ export class StorageDataClient< } } } else { - return resolve(new StorageGet.Error(err as unknown as SdkError)); + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new StorageGet.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -151,7 +161,10 @@ export class StorageDataClient< try { validateStoreName(storeName); } catch (err) { - return new StoragePut.Error(err as SdkError); + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StoragePut.Error(err) + ); } this.logger.trace(`Issuing 'put' request; key: ${key.toString()}`); const result = await this.sendPut( @@ -168,17 +181,11 @@ export class StorageDataClient< key: string, passedInVal: string | number | Uint8Array ): Promise { - console.log( - `storeName: ${storeName} key: ${key} passedInVal: ${ - passedInVal as string - }` - ); const request = new _StorePutRequest(); request.setKey(key); const value = new _StoreValue(); if (typeof passedInVal === 'string') { - console.log(`setting string value: ${passedInVal}`); value.setStringValue(passedInVal); } else if (typeof passedInVal === 'number') { if (Number.isInteger(passedInVal)) { @@ -199,7 +206,12 @@ export class StorageDataClient< }, (err, _resp) => { if (err) { - return resolve(new StoragePut.Error(err as unknown as SdkError)); + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new StoragePut.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new StoragePut.Success()); } @@ -215,7 +227,10 @@ export class StorageDataClient< try { validateStoreName(storeName); } catch (err) { - return new StorageDelete.Error(err as SdkError); + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StorageDelete.Error(err) + ); } this.logger.trace(`Issuing 'delete' request; key: ${key.toString()}`); const result = await this.sendDelete(storeName, convertToB64String(key)); @@ -239,7 +254,12 @@ export class StorageDataClient< }, (err, _resp) => { if (err) { - return resolve(new StorageDelete.Error(err as unknown as SdkError)); + this.cacheServiceErrorMapper.resolveOrRejectError({ + err: err, + errorResponseFactoryFn: e => new StorageDelete.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new StorageDelete.Success()); } From 4530d8125dd5e7d1371aabfb9e033049b7e6b150 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Thu, 20 Jun 2024 12:31:26 -0700 Subject: [PATCH 13/15] feat: change the put/get api --- .../test/integration/integration-setup.ts | 2 +- .../test/integration/integration-setup.ts | 2 +- packages/client-sdk-nodejs/package-lock.json | 8 +- packages/client-sdk-nodejs/package.json | 1 + .../src/errors/cache-service-error-mapper.ts | 31 +- packages/client-sdk-nodejs/src/index.ts | 8 +- .../src/internal/storage-data-client.ts | 98 +++-- .../test/integration/integration-setup.ts | 2 +- .../unit/cache-service-error-mapper.test.ts | 6 +- packages/client-sdk-web/package-lock.json | 6 +- packages/client-sdk-web/package.json | 1 + .../src/errors/cache-service-error-mapper.ts | 34 +- packages/client-sdk-web/src/index.ts | 8 +- .../src/internal/storage-data-client.ts | 115 ++++-- .../src/common-int-test-utils.ts | 6 +- .../src/create-delete-list-cache.ts | 4 +- .../common-integration-tests/src/storage.ts | 126 ++++-- .../src/topic-client.ts | 10 +- packages/core/package-lock.json | 364 ++++++++++-------- packages/core/src/clients/IStorageClient.ts | 19 +- packages/core/src/errors/errors.ts | 29 +- packages/core/src/index.ts | 8 +- .../clients/pubsub/AbstractPubsubClient.ts | 2 +- .../clients/storage/AbstractStorageClient.ts | 30 +- .../clients/storage/IStorageDataClient.ts | 19 +- .../responses/enums/store/scalar/index.ts | 7 - .../responses/storage/scalar/storage-get.ts | 139 +------ .../responses/storage/scalar/storage-value.ts | 47 +++ 28 files changed, 707 insertions(+), 425 deletions(-) create mode 100644 packages/core/src/messages/responses/storage/scalar/storage-value.ts diff --git a/packages/client-sdk-nodejs-compression-zstd/test/integration/integration-setup.ts b/packages/client-sdk-nodejs-compression-zstd/test/integration/integration-setup.ts index 80d51ca59..f37041b6d 100644 --- a/packages/client-sdk-nodejs-compression-zstd/test/integration/integration-setup.ts +++ b/packages/client-sdk-nodejs-compression-zstd/test/integration/integration-setup.ts @@ -16,7 +16,7 @@ export const deleteCacheIfExists = async ( ) => { const deleteResponse = await momento.deleteCache(cacheName); if (deleteResponse instanceof DeleteCache.Error) { - if (deleteResponse.errorCode() !== MomentoErrorCode.NOT_FOUND_ERROR) { + if (deleteResponse.errorCode() !== MomentoErrorCode.CACHE_NOT_FOUND_ERROR) { throw deleteResponse.innerException(); } } diff --git a/packages/client-sdk-nodejs-compression/test/integration/integration-setup.ts b/packages/client-sdk-nodejs-compression/test/integration/integration-setup.ts index 80d51ca59..f37041b6d 100644 --- a/packages/client-sdk-nodejs-compression/test/integration/integration-setup.ts +++ b/packages/client-sdk-nodejs-compression/test/integration/integration-setup.ts @@ -16,7 +16,7 @@ export const deleteCacheIfExists = async ( ) => { const deleteResponse = await momento.deleteCache(cacheName); if (deleteResponse instanceof DeleteCache.Error) { - if (deleteResponse.errorCode() !== MomentoErrorCode.NOT_FOUND_ERROR) { + if (deleteResponse.errorCode() !== MomentoErrorCode.CACHE_NOT_FOUND_ERROR) { throw deleteResponse.innerException(); } } diff --git a/packages/client-sdk-nodejs/package-lock.json b/packages/client-sdk-nodejs/package-lock.json index df270458d..f553ecf53 100644 --- a/packages/client-sdk-nodejs/package-lock.json +++ b/packages/client-sdk-nodejs/package-lock.json @@ -43,7 +43,6 @@ } }, "../common-integration-tests": { - "name": "@gomomento/common-integration-tests", "version": "0.0.1", "dev": true, "license": "Apache-2.0", @@ -75,7 +74,6 @@ } }, "../core": { - "name": "@gomomento/sdk-core", "version": "0.0.1", "license": "Apache-2.0", "dependencies": { @@ -2766,9 +2764,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.803", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.803.tgz", - "integrity": "sha512-61H9mLzGOCLLVsnLiRzCbc63uldP0AniRYPV3hbGVtONA1pI7qSGILdbofR7A8TMbOypDocEAjH/e+9k1QIe3g==", + "version": "1.4.807", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.807.tgz", + "integrity": "sha512-kSmJl2ZwhNf/bcIuCH/imtNOKlpkLDn2jqT5FJ+/0CXjhnFaOa9cOe9gHKKy71eM49izwuQjZhKk+lWQ1JxB7A==", "dev": true }, "node_modules/emittery": { diff --git a/packages/client-sdk-nodejs/package.json b/packages/client-sdk-nodejs/package.json index cea65a69f..1d6eb2aac 100644 --- a/packages/client-sdk-nodejs/package.json +++ b/packages/client-sdk-nodejs/package.json @@ -16,6 +16,7 @@ "prebuild": "eslint . --ext .ts", "test": "jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1", "integration-test-auth": "jest auth-client.test.ts --maxWorkers 1", + "integration-test-store": "jest storage.test.ts --maxWorkers 1", "unit-test": "jest unit", "integration-test-leaderboard": "jest leaderboard --maxWorkers 1", "integration-test": "jest integration --testPathIgnorePatterns \"auth-client.test.ts|leaderboard.test.ts\" --maxWorkers 1", diff --git a/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts b/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts index 663865835..9d94dde64 100644 --- a/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts +++ b/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts @@ -1,7 +1,6 @@ import {Status} from '@grpc/grpc-js/build/src/constants'; -import {ServiceError} from '@grpc/grpc-js'; +import {Metadata, ServiceError} from '@grpc/grpc-js'; import { - NotFoundError, InternalServerError, InvalidArgumentError, PermissionError, @@ -17,6 +16,11 @@ import { UnknownError, FailedPreconditionError, } from '../../src'; +import { + CacheNotFoundError, + ItemNotFoundError, + StoreNotFoundError, +} from '@gomomento/sdk-core/dist/src/errors'; import { ICacheServiceErrorMapper, ResolveOrRejectErrorOptions, @@ -57,7 +61,7 @@ export class CacheServiceErrorMapper const errParams: [ string, number | undefined, - object | undefined, + Metadata | undefined, string | undefined ] = [ err?.message || 'Unable to process request', @@ -76,8 +80,25 @@ export class CacheServiceErrorMapper return new UnknownServiceError(...errParams); case Status.UNAVAILABLE: return new ServerUnavailableError(...errParams); - case Status.NOT_FOUND: - return new NotFoundError(...errParams); + case Status.NOT_FOUND: { + let errCause = errParams[2]?.get('err')?.[0]; + const errorMessage = errParams[0]?.toString(); + const isStoreNotFound = + errorMessage?.includes('Store with name:') && + errorMessage?.includes("doesn't exist"); + // If errCause is not already set to 'store_not_found', check for store_not_found error + if (!errCause && isStoreNotFound) { + errCause = 'store_not_found'; + } + switch (errCause) { + case 'element_not_found': + return new ItemNotFoundError(...errParams); + case 'store_not_found': + return new StoreNotFoundError(...errParams); + default: + return new CacheNotFoundError(...errParams); + } + } case Status.OUT_OF_RANGE: case Status.UNIMPLEMENTED: return new BadRequestError(...errParams); diff --git a/packages/client-sdk-nodejs/src/index.ts b/packages/client-sdk-nodejs/src/index.ts index e3b87210c..c8aa41893 100644 --- a/packages/client-sdk-nodejs/src/index.ts +++ b/packages/client-sdk-nodejs/src/index.ts @@ -125,7 +125,9 @@ import { TimeoutError, BadRequestError, PermissionError, - NotFoundError, + CacheNotFoundError, + StoreNotFoundError, + ItemNotFoundError, UnknownError, MomentoLogger, MomentoLoggerFactory, @@ -438,7 +440,9 @@ export { TimeoutError, BadRequestError, PermissionError, - NotFoundError, + CacheNotFoundError, + StoreNotFoundError, + ItemNotFoundError, UnknownError, // Logging MomentoLogger, diff --git a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts index 255c54ef4..749402582 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts @@ -1,11 +1,12 @@ import { CredentialProvider, InvalidArgumentError, + MomentoErrorCode, MomentoLogger, MomentoLoggerFactory, + StorageDelete, StorageGet, StoragePut, - StorageDelete, UnknownError, } from '@gomomento/sdk-core'; import {validateStoreName} from '@gomomento/sdk-core/dist/src/internal/utils'; @@ -90,6 +91,18 @@ export class StorageDataClient implements IStorageDataClient { } } + private validateStoreNameOrThrowError(storeName: string) { + try { + validateStoreName(storeName); + return; + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StoragePut.Error(err) + ); + } + } + private initializeInterceptors( _loggerFactory: MomentoLoggerFactory ): Interceptor[] { @@ -148,22 +161,22 @@ export class StorageDataClient implements IStorageDataClient { switch (value) { case 'double_value': { return resolve( - new StorageGet.DoubleResponse(resp.value.double_value) + StorageGet.Success.ofDouble(resp.value.double_value) ); } case 'string_value': { return resolve( - new StorageGet.StringResponse(resp.value.string_value) + StorageGet.Success.ofString(resp.value.string_value) ); } case 'bytes_value': { return resolve( - new StorageGet.BytesResponse(resp.value.bytes_value) + StorageGet.Success.ofBytes(resp.value.bytes_value) ); } case 'integer_value': { return resolve( - new StorageGet.IntegerResponse(resp.value.integer_value) + StorageGet.Success.ofInt(resp.value.integer_value) ); } case 'none': { @@ -177,6 +190,12 @@ export class StorageDataClient implements IStorageDataClient { } } } else { + const sdkError = this.cacheServiceErrorMapper.convertError(err); + if ( + sdkError.errorCode() === MomentoErrorCode.ITEM_NOT_FOUND_ERROR + ) { + return resolve(new StorageGet.Success(undefined)); + } this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, errorResponseFactoryFn: e => new StorageGet.Error(e), @@ -189,42 +208,63 @@ export class StorageDataClient implements IStorageDataClient { }); } - public async put( + public async putInt( storeName: string, key: string, - value: string | Uint8Array | number + value: number ): Promise { - try { - validateStoreName(storeName); - } catch (err) { - return this.cacheServiceErrorMapper.returnOrThrowError( - err as Error, - err => new StoragePut.Error(err) - ); - } + this.validateStoreNameOrThrowError(storeName); + this.logger.trace( + `Issuing 'put' request; store: ${storeName}, key: ${key}` + ); + const storeValue = new store._StoreValue({integer_value: value}); + return await this.sendPut(storeName, key, storeValue); + } + + public async putDouble( + storeName: string, + key: string, + value: number + ): Promise { + this.validateStoreNameOrThrowError(storeName); this.logger.trace( `Issuing 'put' request; store: ${storeName}, key: ${key}` ); - return await this.sendPut(storeName, key, value); + const storeValue = new store._StoreValue({double_value: value}); + return await this.sendPut(storeName, key, storeValue); + } + + public async putString( + storeName: string, + key: string, + value: string + ): Promise { + this.validateStoreNameOrThrowError(storeName); + this.logger.trace( + `Issuing 'put' request; store: ${storeName}, key: ${key}` + ); + const storeValue = new store._StoreValue({string_value: value}); + return await this.sendPut(storeName, key, storeValue); + } + + public async putBytes( + storeName: string, + key: string, + value: Uint8Array + ): Promise { + this.validateStoreNameOrThrowError(storeName); + this.logger.trace( + `Issuing 'put' request; store: ${storeName}, key: ${key}` + ); + const storeValue = new store._StoreValue({bytes_value: value}); + return await this.sendPut(storeName, key, storeValue); } private async sendPut( storeName: string, key: string, - value: string | Uint8Array | number + storeValue: store._StoreValue ): Promise { - const storeValue = new store._StoreValue(); - if (typeof value === 'string') { - storeValue.string_value = value; - } else if (typeof value === 'number') { - if (Number.isInteger(value)) { - storeValue.integer_value = value; - } else { - storeValue.double_value = value; - } - } else { - storeValue.bytes_value = value; - } const request = new store._StorePutRequest({ key: key, value: storeValue, diff --git a/packages/client-sdk-nodejs/test/integration/integration-setup.ts b/packages/client-sdk-nodejs/test/integration/integration-setup.ts index e02b1bd9e..a393d0d9f 100644 --- a/packages/client-sdk-nodejs/test/integration/integration-setup.ts +++ b/packages/client-sdk-nodejs/test/integration/integration-setup.ts @@ -25,7 +25,7 @@ export const deleteCacheIfExists = async ( ) => { const deleteResponse = await momento.deleteCache(cacheName); if (deleteResponse instanceof DeleteCache.Error) { - if (deleteResponse.errorCode() !== MomentoErrorCode.NOT_FOUND_ERROR) { + if (deleteResponse.errorCode() !== MomentoErrorCode.CACHE_NOT_FOUND_ERROR) { throw deleteResponse.innerException(); } } diff --git a/packages/client-sdk-nodejs/test/unit/cache-service-error-mapper.test.ts b/packages/client-sdk-nodejs/test/unit/cache-service-error-mapper.test.ts index 68547cba6..c6984fcc5 100644 --- a/packages/client-sdk-nodejs/test/unit/cache-service-error-mapper.test.ts +++ b/packages/client-sdk-nodejs/test/unit/cache-service-error-mapper.test.ts @@ -10,13 +10,13 @@ import { InternalServerError, InvalidArgumentError, LimitExceededError, - NotFoundError, PermissionError, SdkError, ServerUnavailableError, TimeoutError, UnknownServiceError, } from '../../src'; +import {CacheNotFoundError} from '@gomomento/sdk-core'; const generateServiceError = (status: Status): ServiceError => { return { @@ -92,7 +92,7 @@ describe('CacheServiceErrorMapper', () => { expect(resolved).toBeInstanceOf(BadRequestError); }); }); - it('should return cache not found error when grpc status is NOT_FOUND', () => { + xit('should return cache not found error when grpc status is NOT_FOUND', () => { const serviceError = generateServiceError(Status.NOT_FOUND); cacheServiceErrorMapper.resolveOrRejectError({ err: serviceError, @@ -100,7 +100,7 @@ describe('CacheServiceErrorMapper', () => { resolveFn: resolveFn, rejectFn: rejectFn, }); - expect(resolved).toBeInstanceOf(NotFoundError); + expect(resolved).toBeInstanceOf(CacheNotFoundError); }); it('should return unavailable error when grpc status is UNAVAILABLE', () => { const serviceError = generateServiceError(Status.UNAVAILABLE); diff --git a/packages/client-sdk-web/package-lock.json b/packages/client-sdk-web/package-lock.json index 7115c9467..0a642277c 100644 --- a/packages/client-sdk-web/package-lock.json +++ b/packages/client-sdk-web/package-lock.json @@ -2709,9 +2709,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.806", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.806.tgz", - "integrity": "sha512-nkoEX2QIB8kwCOtvtgwhXWy2IHVcOLQZu9Qo36uaGB835mdX/h8uLRlosL6QIhLVUnAiicXRW00PwaPZC74Nrg==", + "version": "1.4.807", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.807.tgz", + "integrity": "sha512-kSmJl2ZwhNf/bcIuCH/imtNOKlpkLDn2jqT5FJ+/0CXjhnFaOa9cOe9gHKKy71eM49izwuQjZhKk+lWQ1JxB7A==", "dev": true }, "node_modules/emittery": { diff --git a/packages/client-sdk-web/package.json b/packages/client-sdk-web/package.json index ba0b40bf0..c94b023fb 100644 --- a/packages/client-sdk-web/package.json +++ b/packages/client-sdk-web/package.json @@ -18,6 +18,7 @@ "unit-test": "jest unit", "integration-test-auth": "jest --env=jsdom auth-client.test.ts --maxWorkers 1", "integration-test-leaderboard": "jest --env=jsdom leaderboard --maxWorkers 1", + "integration-test-store": "jest --env=jsdom storage.test.ts --maxWorkers 1", "integration-test-jsdom": "jest integration --env=jsdom --testMatch \"**/dictionary.test.ts|**/ping.test.ts|*/topic-client.test.ts|leaderboard.test.ts\" --maxWorkers 1", "integration-test-happy-dom": "jest integration --env=@happy-dom/jest-environment --testPathIgnorePatterns \"dictionary.test.ts|ping.test.ts|topic-client.test.ts|auth-client.test.ts|leaderboard.test.ts\" --maxWorkers 1", "integration-test": "npm run integration-test-happy-dom && npm run integration-test-jsdom", diff --git a/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts b/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts index 4b314dc67..c477bde74 100644 --- a/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts +++ b/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts @@ -1,5 +1,4 @@ import { - NotFoundError, InternalServerError, InvalidArgumentError, PermissionError, @@ -15,11 +14,16 @@ import { UnknownError, FailedPreconditionError, } from '../../src'; -import {RpcError, StatusCode} from 'grpc-web'; +import {Metadata, RpcError, StatusCode} from 'grpc-web'; import { ICacheServiceErrorMapper, ResolveOrRejectErrorOptions, } from '@gomomento/sdk-core/dist/src/errors/ICacheServiceErrorMapper'; +import { + CacheNotFoundError, + ItemNotFoundError, + StoreNotFoundError, +} from '@gomomento/sdk-core'; export class CacheServiceErrorMapper implements ICacheServiceErrorMapper @@ -55,7 +59,7 @@ export class CacheServiceErrorMapper const errParams: [ string, number | undefined, - object | undefined, + Metadata | undefined, string | undefined ] = [ err?.message || 'Unable to process request', @@ -74,8 +78,28 @@ export class CacheServiceErrorMapper return new UnknownServiceError(...errParams); case StatusCode.UNAVAILABLE: return new ServerUnavailableError(...errParams); - case StatusCode.NOT_FOUND: - return new NotFoundError(...errParams); + case StatusCode.NOT_FOUND: { + let errCause = ''; + const errorMessage = errParams[0]?.toString(); + const isStoreNotFound = + errorMessage?.includes('Store with name:') && + errorMessage?.includes("doesn't exist"); + if (isStoreNotFound) { + errCause = 'store_not_found'; + } + const isElementNotFound = errorMessage?.includes('Element not found'); + if (isElementNotFound) { + errCause = 'element_not_found'; + } + switch (errCause) { + case 'element_not_found': + return new ItemNotFoundError(...errParams); + case 'store_not_found': + return new StoreNotFoundError(...errParams); + default: + return new CacheNotFoundError(...errParams); + } + } case StatusCode.OUT_OF_RANGE: case StatusCode.UNIMPLEMENTED: return new BadRequestError(...errParams); diff --git a/packages/client-sdk-web/src/index.ts b/packages/client-sdk-web/src/index.ts index 4d524039b..891b37c55 100644 --- a/packages/client-sdk-web/src/index.ts +++ b/packages/client-sdk-web/src/index.ts @@ -105,7 +105,9 @@ import { TimeoutError, BadRequestError, PermissionError, - NotFoundError, + CacheNotFoundError, + StoreNotFoundError, + ItemNotFoundError, UnknownError, MomentoLogger, MomentoLoggerFactory, @@ -310,7 +312,9 @@ export { TimeoutError, BadRequestError, PermissionError, - NotFoundError, + CacheNotFoundError, + StoreNotFoundError, + ItemNotFoundError, UnknownError, MomentoLogger, MomentoLoggerFactory, diff --git a/packages/client-sdk-web/src/internal/storage-data-client.ts b/packages/client-sdk-web/src/internal/storage-data-client.ts index 4816c518b..1a191a7bb 100644 --- a/packages/client-sdk-web/src/internal/storage-data-client.ts +++ b/packages/client-sdk-web/src/internal/storage-data-client.ts @@ -6,6 +6,7 @@ import { CredentialProvider, MomentoLogger, UnknownError, + MomentoErrorCode, } from '..'; import {Request, UnaryResponse} from 'grpc-web'; import { @@ -121,26 +122,32 @@ export class StorageDataClient< } case ValueCase.BYTES_VALUE: { return resolve( - new StorageGet.BytesResponse(value.getBytesValue_asU8()) + StorageGet.Success.ofBytes(value.getBytesValue_asU8()) ); } case ValueCase.STRING_VALUE: { return resolve( - new StorageGet.StringResponse(value.getStringValue()) + StorageGet.Success.ofString(value.getStringValue()) ); } case ValueCase.INTEGER_VALUE: { return resolve( - new StorageGet.IntegerResponse(value.getIntegerValue()) + StorageGet.Success.ofInt(value.getIntegerValue()) ); } case ValueCase.DOUBLE_VALUE: { return resolve( - new StorageGet.DoubleResponse(value.getDoubleValue()) + StorageGet.Success.ofDouble(value.getDoubleValue()) ); } } } else { + const sdkError = this.cacheServiceErrorMapper.convertError(err); + if ( + sdkError.errorCode() === MomentoErrorCode.ITEM_NOT_FOUND_ERROR + ) { + return resolve(new StorageGet.Success(undefined)); + } this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, errorResponseFactoryFn: e => new StorageGet.Error(e), @@ -153,10 +160,35 @@ export class StorageDataClient< }); } - public async put( + public async putInt( + storeName: string, + key: string, + value: number + ): Promise { + try { + validateStoreName(storeName); + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StoragePut.Error(err) + ); + } + this.logger.trace(`Issuing 'put' request; key: ${key.toString()}`); + const storeValue = new _StoreValue(); + storeValue.setIntegerValue(value); + const result = await this.sendPut( + storeName, + convertToB64String(key), + storeValue + ); + this.logger.trace(`'put' request result: ${result.toString()}`); + return result; + } + + public async putDouble( storeName: string, key: string, - value: string | number | Uint8Array + value: number ): Promise { try { validateStoreName(storeName); @@ -167,10 +199,62 @@ export class StorageDataClient< ); } this.logger.trace(`Issuing 'put' request; key: ${key.toString()}`); + const storeValue = new _StoreValue(); + storeValue.setDoubleValue(value); const result = await this.sendPut( storeName, convertToB64String(key), - value + storeValue + ); + this.logger.trace(`'put' request result: ${result.toString()}`); + return result; + } + + public async putBytes( + storeName: string, + key: string, + value: Uint8Array + ): Promise { + try { + validateStoreName(storeName); + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StoragePut.Error(err) + ); + } + this.logger.trace(`Issuing 'put' request; key: ${key.toString()}`); + const storeValue = new _StoreValue(); + storeValue.setBytesValue(value); + const result = await this.sendPut( + storeName, + convertToB64String(key), + storeValue + ); + this.logger.trace(`'put' request result: ${result.toString()}`); + return result; + } + + public async putString( + storeName: string, + key: string, + value: string + ): Promise { + try { + validateStoreName(storeName); + } catch (err) { + return this.cacheServiceErrorMapper.returnOrThrowError( + err as Error, + err => new StoragePut.Error(err) + ); + } + this.logger.trace(`Issuing 'put' request; key: ${key.toString()}`); + const storeValue = new _StoreValue(); + storeValue.setStringValue(value); + const result = await this.sendPut( + storeName, + convertToB64String(key), + storeValue ); this.logger.trace(`'put' request result: ${result.toString()}`); return result; @@ -179,24 +263,11 @@ export class StorageDataClient< private async sendPut( storeName: string, key: string, - passedInVal: string | number | Uint8Array + storeValue: _StoreValue ): Promise { const request = new _StorePutRequest(); request.setKey(key); - - const value = new _StoreValue(); - if (typeof passedInVal === 'string') { - value.setStringValue(passedInVal); - } else if (typeof passedInVal === 'number') { - if (Number.isInteger(passedInVal)) { - value.setIntegerValue(passedInVal); - } else { - value.setDoubleValue(passedInVal); - } - } else { - value.setBytesValue(passedInVal); - } - request.setValue(value); + request.setValue(storeValue); return await new Promise((resolve, reject) => { this.clientWrapper.put( request, diff --git a/packages/common-integration-tests/src/common-int-test-utils.ts b/packages/common-integration-tests/src/common-int-test-utils.ts index d181a4dd1..6ae2e9d70 100644 --- a/packages/common-integration-tests/src/common-int-test-utils.ts +++ b/packages/common-integration-tests/src/common-int-test-utils.ts @@ -37,6 +37,10 @@ export function testCacheName(): string { return process.env.TEST_CACHE_NAME || `js-integration-test-default-${v4()}`; } +export function testStoreName(): string { + return process.env.TEST_STORE_NAME || `js-integration-test-default-${v4()}`; +} + /** * Returns a unique index name for use in integration tests. * @param meaningfulIdentifier Required suffix to identify the test for debugging purposes. @@ -74,7 +78,7 @@ export const deleteCacheIfExists = async ( } const deleteResponse = await client.deleteCache(cacheName); if (deleteResponse instanceof DeleteCache.Error) { - if (deleteResponse.errorCode() !== MomentoErrorCode.NOT_FOUND_ERROR) { + if (deleteResponse.errorCode() !== MomentoErrorCode.CACHE_NOT_FOUND_ERROR) { throw deleteResponse.innerException(); } } diff --git a/packages/common-integration-tests/src/create-delete-list-cache.ts b/packages/common-integration-tests/src/create-delete-list-cache.ts index 90f1d1993..485b69011 100644 --- a/packages/common-integration-tests/src/create-delete-list-cache.ts +++ b/packages/common-integration-tests/src/create-delete-list-cache.ts @@ -36,7 +36,7 @@ export function runCreateDeleteListCacheTests(cacheClient: ICacheClient) { }, `expected ERROR but got ${deleteResponse.toString()}`); if (deleteResponse instanceof DeleteCache.Error) { expect(deleteResponse.errorCode()).toEqual( - MomentoErrorCode.NOT_FOUND_ERROR + MomentoErrorCode.CACHE_NOT_FOUND_ERROR ); } }); @@ -131,7 +131,7 @@ export function runCreateDeleteListCacheTests(cacheClient: ICacheClient) { }, `expected ERROR but got ${flushResponse.toString()}`); if (flushResponse instanceof CacheFlush.Error) { expect(flushResponse.errorCode()).toEqual( - MomentoErrorCode.NOT_FOUND_ERROR + MomentoErrorCode.CACHE_NOT_FOUND_ERROR ); } }); diff --git a/packages/common-integration-tests/src/storage.ts b/packages/common-integration-tests/src/storage.ts index c00888033..36c5d9cdc 100644 --- a/packages/common-integration-tests/src/storage.ts +++ b/packages/common-integration-tests/src/storage.ts @@ -8,16 +8,16 @@ import { StorageGetResponse, StoragePutResponse, } from '@gomomento/sdk-core'; -import {testCacheName} from './common-int-test-utils'; +import {testStoreName} from './common-int-test-utils'; import {v4} from 'uuid'; export function runStorageServiceTests( storageClient: IStorageClient, - testStoreName: string + testingStoreName: string ) { describe('#create list and delete stores', () => { it('creates a store, lists it and makes sure it exists, and then deletes it', async () => { - const storeName = testCacheName(); + const storeName = testStoreName(); const createResponse = await storageClient.createStore(storeName); switch (createResponse.type) { // this is the expected response @@ -66,7 +66,7 @@ export function runStorageServiceTests( } }); it('should return AlreadyExists response if trying to create a store that already exists', async () => { - const storeName = testCacheName(); + const storeName = testStoreName(); const createResponse = await storageClient.createStore(storeName); switch (createResponse.type) { // this is the expected response @@ -102,10 +102,9 @@ export function runStorageServiceTests( }); }); describe('#store get put and delete', () => { - it('put get and delete a key in a store', async () => { + it('put get and delete key in a store', async () => { const key = v4(); - const value = v4(); - const createResponse = await storageClient.createStore(testStoreName); + const createResponse = await storageClient.createStore(testingStoreName); switch (createResponse.type) { // this is the expected response case CreateStoreResponse.Success: { @@ -120,21 +119,92 @@ export function runStorageServiceTests( ); } } - const putResponse = await storageClient.put(testStoreName, key, value); - switch (putResponse.type) { + + // put/get an int value + const intValue = 42; + const putIntResponse = await storageClient.putInt( + testingStoreName, + key, + intValue + ); + switch (putIntResponse.type) { + case StoragePutResponse.Success: { + break; + } + case StoragePutResponse.Error: { + throw new Error( + `failed to put key: ${putIntResponse.message()} ${putIntResponse.toString()}` + ); + } + } + const getIntResponse = await storageClient.get(testingStoreName, key); + expect(getIntResponse.type).toEqual(StorageGetResponse.Success); + expect(getIntResponse.value()?.int()).toEqual(intValue); + + // put/get a double value + const doubleValue = 42.42; + const putDoubleResponse = await storageClient.putDouble( + testingStoreName, + key, + doubleValue + ); + switch (putDoubleResponse.type) { case StoragePutResponse.Success: { break; } case StoragePutResponse.Error: { throw new Error( - `failed to put key: ${putResponse.message()} ${putResponse.toString()}` + `failed to put key: ${putDoubleResponse.message()} ${putDoubleResponse.toString()}` ); } } + const getDoubleResponse = await storageClient.get(testingStoreName, key); + expect(getDoubleResponse.type).toEqual(StorageGetResponse.Success); + expect(getDoubleResponse.value()?.double()).toEqual(doubleValue); - const getResponse = await storageClient.get(testStoreName, key); - expect(getResponse.value()).toEqual(value); - const deleteResponse = await storageClient.delete(testStoreName, key); + // put/get a string value + const stringValue = v4(); + const putStringResponse = await storageClient.putString( + testingStoreName, + key, + stringValue + ); + switch (putStringResponse.type) { + case StoragePutResponse.Success: { + break; + } + case StoragePutResponse.Error: { + throw new Error( + `failed to put key: ${putStringResponse.message()} ${putStringResponse.toString()}` + ); + } + } + const getStringResponse = await storageClient.get(testingStoreName, key); + expect(getStringResponse.type).toEqual(StorageGetResponse.Success); + expect(getStringResponse.value()?.string()).toEqual(stringValue); + + // put/get a bytes value + const bytesValue = new Uint8Array([1, 2, 3, 4]); + const putBytesResponse = await storageClient.putBytes( + testingStoreName, + key, + bytesValue + ); + switch (putBytesResponse.type) { + case StoragePutResponse.Success: { + break; + } + case StoragePutResponse.Error: { + throw new Error( + `failed to put key: ${putBytesResponse.message()} ${putBytesResponse.toString()}` + ); + } + } + const getBytesResponse = await storageClient.get(testingStoreName, key); + expect(getBytesResponse.type).toEqual(StorageGetResponse.Success); + expect(getBytesResponse.value()?.bytes()).toEqual(bytesValue); + + const deleteResponse = await storageClient.delete(testingStoreName, key); switch (deleteResponse.type) { case StorageDeleteResponse.Success: { break; @@ -146,32 +216,34 @@ export function runStorageServiceTests( } } }); - it('should return not found error for a key that doesnt exist', async () => { + it('should return an undefined value for a key that doesnt exist', async () => { const key = v4(); - const getResponse = await storageClient.get(testStoreName, key); - switch (getResponse.type) { - case StorageGetResponse.Error: { - expect(getResponse.errorCode()).toEqual( - MomentoErrorCode.NOT_FOUND_ERROR - ); + const createResponse = await storageClient.createStore(testingStoreName); + switch (createResponse.type) { + // this is the expected response + case CreateStoreResponse.Success: { break; } - default: { + case CreateStoreResponse.AlreadyExists: { + break; + } + case CreateStoreResponse.Error: { throw new Error( - `expected StoreGetResponse.Error but got ${ - getResponse.type - } toString: ${getResponse.toString()}` + `failed to create store, expected store to be able to happen, error: ${createResponse.message()} exception: ${createResponse.toString()}` ); } } + const getResponse = await storageClient.get(testingStoreName, key); + expect(getResponse.type).toEqual(StorageGetResponse.Success); + expect(getResponse.value()).toBeUndefined(); }); - it('should return not found error for deleting a store that doesnt exist', async () => { - const storeName = 'test'; + it('should return store not found error for deleting a store that doesnt exist', async () => { + const storeName = testStoreName(); const deleteResponse = await storageClient.deleteStore(storeName); switch (deleteResponse.type) { case DeleteStoreResponse.Error: { expect(deleteResponse.errorCode()).toEqual( - MomentoErrorCode.NOT_FOUND_ERROR + MomentoErrorCode.STORE_NOT_FOUND_ERROR ); break; } diff --git a/packages/common-integration-tests/src/topic-client.ts b/packages/common-integration-tests/src/topic-client.ts index cec409b6e..9d9ff6d30 100644 --- a/packages/common-integration-tests/src/topic-client.ts +++ b/packages/common-integration-tests/src/topic-client.ts @@ -7,7 +7,7 @@ import { TopicPublish, TopicSubscribe, SubscribeCallOptions, - NotFoundError, + CacheNotFoundError, } from '@gomomento/sdk-core'; import { expectWithMessage, @@ -52,7 +52,7 @@ export function runTopicClientTests( const response = await topicClient.publish(v4(), 'topic', 'value'); expectWithMessage(() => { expect((response as IResponseError).errorCode()).toEqual( - MomentoErrorCode.NOT_FOUND_ERROR + MomentoErrorCode.CACHE_NOT_FOUND_ERROR ); }, `expected NOT_FOUND_ERROR but got ${response.toString()}`); expect((response as IResponseError).message()).toContain( @@ -98,7 +98,7 @@ export function runTopicClientTests( ); expectWithMessage(() => { expect((response as IResponseError).errorCode()).toEqual( - MomentoErrorCode.NOT_FOUND_ERROR + MomentoErrorCode.CACHE_NOT_FOUND_ERROR ); }, `expected NOT_FOUND_ERROR but got ${response.toString()}`); }); @@ -250,7 +250,7 @@ export function runTopicClientTests( subscription: TopicSubscribe.Subscription ) => { expect(error.errorCode()).toEqual( - MomentoErrorCode.NOT_FOUND_ERROR + MomentoErrorCode.CACHE_NOT_FOUND_ERROR ); expect(subscription.isSubscribed).toBeFalse(); }, @@ -297,7 +297,7 @@ export function runTopicClientTests( it('should throw when publishing to a cache that does not exist', async () => { await expect(async () => { await topicClientWithThrowOnErrors.publish(v4(), 'topic', 'value'); - }).rejects.toThrow(NotFoundError); + }).rejects.toThrow(CacheNotFoundError); }); }); } diff --git a/packages/core/package-lock.json b/packages/core/package-lock.json index de64d99e4..c2c6b9256 100644 --- a/packages/core/package-lock.json +++ b/packages/core/package-lock.json @@ -57,30 +57,30 @@ } }, "node_modules/@babel/compat-data": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.24.4.tgz", - "integrity": "sha512-vg8Gih2MLK+kOkHJp4gBEIkyaIi00jgWot2D9QOmmfLC8jINSOzmCLta6Bvz/JSBCqnegV0L80jhxkol5GWNfQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.24.7.tgz", + "integrity": "sha512-qJzAIcv03PyaWqxRgO4mSU3lihncDT296vnyuE2O8uA4w3UHWI4S3hgeZd1L8W1Bft40w9JxJ2b412iDUFFRhw==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/core": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.24.5.tgz", - "integrity": "sha512-tVQRucExLQ02Boi4vdPp49svNGcfL2GhdTCT9aldhXgCJVAI21EtRfBettiuLUwce/7r6bFdgs6JFkcdTiFttA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.24.7.tgz", + "integrity": "sha512-nykK+LEK86ahTkX/3TgauT0ikKoNCfKHEaZYTUVupJdTLzGNvrblu4u6fa7DhZONAltdf8e662t/abY8idrd/g==", "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.0", - "@babel/code-frame": "^7.24.2", - "@babel/generator": "^7.24.5", - "@babel/helper-compilation-targets": "^7.23.6", - "@babel/helper-module-transforms": "^7.24.5", - "@babel/helpers": "^7.24.5", - "@babel/parser": "^7.24.5", - "@babel/template": "^7.24.0", - "@babel/traverse": "^7.24.5", - "@babel/types": "^7.24.5", + "@babel/code-frame": "^7.24.7", + "@babel/generator": "^7.24.7", + "@babel/helper-compilation-targets": "^7.24.7", + "@babel/helper-module-transforms": "^7.24.7", + "@babel/helpers": "^7.24.7", + "@babel/parser": "^7.24.7", + "@babel/template": "^7.24.7", + "@babel/traverse": "^7.24.7", + "@babel/types": "^7.24.7", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -96,12 +96,12 @@ } }, "node_modules/@babel/core/node_modules/@babel/code-frame": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", - "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.2", + "@babel/highlight": "^7.24.7", "picocolors": "^1.0.0" }, "engines": { @@ -118,12 +118,12 @@ } }, "node_modules/@babel/generator": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.24.5.tgz", - "integrity": "sha512-x32i4hEXvr+iI0NEoEfDKzlemF8AmtOP8CcrRaEcpzysWuoEb1KknpcvMsHKPONoKZiDuItklgWhB18xEhr9PA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.24.7.tgz", + "integrity": "sha512-oipXieGC3i45Y1A41t4tAqpnEZWgB/lC6Ehh6+rOviR5XWpTtMmLN+fGjz9vOiNRt0p6RtO6DtD0pdU3vpqdSA==", "dev": true, "dependencies": { - "@babel/types": "^7.24.5", + "@babel/types": "^7.24.7", "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25", "jsesc": "^2.5.1" @@ -133,13 +133,13 @@ } }, "node_modules/@babel/helper-compilation-targets": { - "version": "7.23.6", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.23.6.tgz", - "integrity": "sha512-9JB548GZoQVmzrFgp8o7KxdgkTGm6xs9DW0o/Pim72UDjzr5ObUQ6ZzYPqA+g9OTS2bBQoctLJrky0RDCAWRgQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.24.7.tgz", + "integrity": "sha512-ctSdRHBi20qWOfy27RUb4Fhp07KSJ3sXcuSvTrXrc4aG8NSYDo1ici3Vhg9bg69y5bj0Mr1lh0aeEgTvc12rMg==", "dev": true, "dependencies": { - "@babel/compat-data": "^7.23.5", - "@babel/helper-validator-option": "^7.23.5", + "@babel/compat-data": "^7.24.7", + "@babel/helper-validator-option": "^7.24.7", "browserslist": "^4.22.2", "lru-cache": "^5.1.1", "semver": "^6.3.1" @@ -158,62 +158,66 @@ } }, "node_modules/@babel/helper-environment-visitor": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz", - "integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.24.7.tgz", + "integrity": "sha512-DoiN84+4Gnd0ncbBOM9AZENV4a5ZiL39HYMyZJGZ/AZEykHYdJw0wW3kdcsh9/Kn+BRXHLkkklZ51ecPKmI1CQ==", "dev": true, + "dependencies": { + "@babel/types": "^7.24.7" + }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-function-name": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz", - "integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.24.7.tgz", + "integrity": "sha512-FyoJTsj/PEUWu1/TYRiXTIHc8lbw+TDYkZuoE43opPS5TrI7MyONBE1oNvfguEXAD9yhQRrVBnXdXzSLQl9XnA==", "dev": true, "dependencies": { - "@babel/template": "^7.22.15", - "@babel/types": "^7.23.0" + "@babel/template": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-hoist-variables": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz", - "integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.24.7.tgz", + "integrity": "sha512-MJJwhkoGy5c4ehfoRyrJ/owKeMl19U54h27YYftT0o2teQ3FJ3nQUf/I3LlJsX4l3qlw7WRXUmiyajvHXoTubQ==", "dev": true, "dependencies": { - "@babel/types": "^7.22.5" + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-imports": { - "version": "7.24.3", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.24.3.tgz", - "integrity": "sha512-viKb0F9f2s0BCS22QSF308z/+1YWKV/76mwt61NBzS5izMzDPwdq1pTrzf+Li3npBWX9KdQbkeCt1jSAM7lZqg==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.24.7.tgz", + "integrity": "sha512-8AyH3C+74cgCVVXow/myrynrAGv+nTVg5vKu2nZph9x7RcRwzmh0VFallJuFTZ9mx6u4eSdXZfcOzSqTUm0HCA==", "dev": true, "dependencies": { - "@babel/types": "^7.24.0" + "@babel/traverse": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.24.5.tgz", - "integrity": "sha512-9GxeY8c2d2mdQUP1Dye0ks3VDyIMS98kt/llQ2nUId8IsWqTF0l1LkSX0/uP7l7MCDrzXS009Hyhe2gzTiGW8A==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.24.7.tgz", + "integrity": "sha512-1fuJEwIrp+97rM4RWdO+qrRsZlAeL1lQJoPqtCYWv0NL115XM93hIH4CSRln2w52SqvmY5hqdtauB6QFCDiZNQ==", "dev": true, "dependencies": { - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-module-imports": "^7.24.3", - "@babel/helper-simple-access": "^7.24.5", - "@babel/helper-split-export-declaration": "^7.24.5", - "@babel/helper-validator-identifier": "^7.24.5" + "@babel/helper-environment-visitor": "^7.24.7", + "@babel/helper-module-imports": "^7.24.7", + "@babel/helper-simple-access": "^7.24.7", + "@babel/helper-split-export-declaration": "^7.24.7", + "@babel/helper-validator-identifier": "^7.24.7" }, "engines": { "node": ">=6.9.0" @@ -223,86 +227,86 @@ } }, "node_modules/@babel/helper-plugin-utils": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.5.tgz", - "integrity": "sha512-xjNLDopRzW2o6ba0gKbkZq5YWEBaK3PCyTOY1K2P/O07LGMhMqlMXPxwN4S5/RhWuCobT8z0jrlKGlYmeR1OhQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.7.tgz", + "integrity": "sha512-Rq76wjt7yz9AAc1KnlRKNAi/dMSVWgDRx43FHoJEbcYU6xOWaE2dVPwcdTukJrjxS65GITyfbvEYHvkirZ6uEg==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-simple-access": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.24.5.tgz", - "integrity": "sha512-uH3Hmf5q5n7n8mz7arjUlDOCbttY/DW4DYhE6FUsjKJ/oYC1kQQUvwEQWxRwUpX9qQKRXeqLwWxrqilMrf32sQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.24.7.tgz", + "integrity": "sha512-zBAIvbCMh5Ts+b86r/CjU+4XGYIs+R1j951gxI3KmmxBMhCg4oQMsv6ZXQ64XOm/cvzfU1FmoCyt6+owc5QMYg==", "dev": true, "dependencies": { - "@babel/types": "^7.24.5" + "@babel/traverse": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-split-export-declaration": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.24.5.tgz", - "integrity": "sha512-5CHncttXohrHk8GWOFCcCl4oRD9fKosWlIRgWm4ql9VYioKm52Mk2xsmoohvm7f3JoiLSM5ZgJuRaf5QZZYd3Q==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.24.7.tgz", + "integrity": "sha512-oy5V7pD+UvfkEATUKvIjvIAH/xCzfsFVw7ygW2SI6NClZzquT+mwdTfgfdbUiceh6iQO0CHtCPsyze/MZ2YbAA==", "dev": true, "dependencies": { - "@babel/types": "^7.24.5" + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-string-parser": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.1.tgz", - "integrity": "sha512-2ofRCjnnA9y+wk8b9IAREroeUP02KHp431N2mhKniy2yKIDKpbrHv9eXwm8cBeWQYcJmzv5qKCu65P47eCF7CQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.7.tgz", + "integrity": "sha512-7MbVt6xrwFQbunH2DNQsAP5sTGxfqQtErvBIvIMi6EQnbgUOuVYanvREcmFrOPhoXBrTtjhhP+lW+o5UfK+tDg==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.5.tgz", - "integrity": "sha512-3q93SSKX2TWCG30M2G2kwaKeTYgEUp5Snjuj8qm729SObL6nbtUldAi37qbxkD5gg3xnBio+f9nqpSepGZMvxA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz", + "integrity": "sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-option": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.23.5.tgz", - "integrity": "sha512-85ttAOMLsr53VgXkTbkx8oA6YTfT4q7/HzXSLEYmjcSTJPMPQtvq1BD79Byep5xMUYbGRzEpDsjUf3dyp54IKw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.24.7.tgz", + "integrity": "sha512-yy1/KvjhV/ZCL+SM7hBrvnZJ3ZuT9OuZgIJAGpPEToANvc3iM6iDvBnRjtElWibHU6n8/LPR/EjX9EtIEYO3pw==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helpers": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.24.5.tgz", - "integrity": "sha512-CiQmBMMpMQHwM5m01YnrM6imUG1ebgYJ+fAIW4FZe6m4qHTPaRHti+R8cggAwkdz4oXhtO4/K9JWlh+8hIfR2Q==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.24.7.tgz", + "integrity": "sha512-NlmJJtvcw72yRJRcnCmGvSi+3jDEg8qFu3z0AFoymmzLx5ERVWyzd9kVXr7Th9/8yIJi2Zc6av4Tqz3wFs8QWg==", "dev": true, "dependencies": { - "@babel/template": "^7.24.0", - "@babel/traverse": "^7.24.5", - "@babel/types": "^7.24.5" + "@babel/template": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/highlight": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.5.tgz", - "integrity": "sha512-8lLmua6AVh/8SLJRRVD6V8p73Hir9w5mJrhE+IPpILG31KKlI9iz5zmBYKcWPS59qSfgP9RaSBQSHHE81WKuEw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.7.tgz", + "integrity": "sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==", "dev": true, "dependencies": { - "@babel/helper-validator-identifier": "^7.24.5", + "@babel/helper-validator-identifier": "^7.24.7", "chalk": "^2.4.2", "js-tokens": "^4.0.0", "picocolors": "^1.0.0" @@ -383,9 +387,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.5.tgz", - "integrity": "sha512-EOv5IK8arwh3LI47dz1b0tKUb/1uhHAnHJOrjgtQMIpu1uXd9mlFrJg9IUgGUgZ41Ch0K8REPTYpO7B76b4vJg==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.7.tgz", + "integrity": "sha512-9uUYRm6OqQrCqQdG1iCBwBPZgN8ciDBro2nIOFaiRz1/BCxaI7CNvQbDHvsArAC7Tw9Hda/B3U+6ui9u4HWXPw==", "dev": true, "bin": { "parser": "bin/babel-parser.js" @@ -455,12 +459,12 @@ } }, "node_modules/@babel/plugin-syntax-jsx": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.24.1.tgz", - "integrity": "sha512-2eCtxZXf+kbkMIsXS4poTvT4Yu5rXiRa+9xGVT56raghjmBTKMpFNc9R4IDiB4emao9eO22Ox7CxuJG7BgExqA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.24.7.tgz", + "integrity": "sha512-6ddciUPe/mpMnOKv/U+RSd2vvVy+Yw/JfBB0ZHYjEZt9NLHmCUylNYlsbqCCS1Bffjlb0fCwC9Vqz+sBz6PsiQ==", "dev": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.24.7" }, "engines": { "node": ">=6.9.0" @@ -557,12 +561,12 @@ } }, "node_modules/@babel/plugin-syntax-typescript": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.24.1.tgz", - "integrity": "sha512-Yhnmvy5HZEnHUty6i++gcfH1/l68AHnItFHnaCv6hn9dNh0hQvvQJsxpi4BMBFN5DLeHBuucT/0DgzXif/OyRw==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.24.7.tgz", + "integrity": "sha512-c/+fVeJBB0FeKsFvwytYiUD+LBvhHjGSI0g446PRGdSVGZLRNArBUno2PETbAly3tpiNAQR5XaZ+JslxkotsbA==", "dev": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.24.7" }, "engines": { "node": ">=6.9.0" @@ -572,26 +576,26 @@ } }, "node_modules/@babel/template": { - "version": "7.24.0", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.24.0.tgz", - "integrity": "sha512-Bkf2q8lMB0AFpX0NFEqSbx1OkTHf0f+0j82mkw+ZpzBnkk7e9Ql0891vlfgi+kHwOk8tQjiQHpqh4LaSa0fKEA==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.24.7.tgz", + "integrity": "sha512-jYqfPrU9JTF0PmPy1tLYHW4Mp4KlgxJD9l2nP9fD6yT/ICi554DmrWBAEYpIelzjHf1msDP3PxJIRt/nFNfBig==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.23.5", - "@babel/parser": "^7.24.0", - "@babel/types": "^7.24.0" + "@babel/code-frame": "^7.24.7", + "@babel/parser": "^7.24.7", + "@babel/types": "^7.24.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/template/node_modules/@babel/code-frame": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", - "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.2", + "@babel/highlight": "^7.24.7", "picocolors": "^1.0.0" }, "engines": { @@ -599,19 +603,19 @@ } }, "node_modules/@babel/traverse": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.24.5.tgz", - "integrity": "sha512-7aaBLeDQ4zYcUFDUD41lJc1fG8+5IU9DaNSJAgal866FGvmD5EbWQgnEC6kO1gGLsX0esNkfnJSndbTXA3r7UA==", - "dev": true, - "dependencies": { - "@babel/code-frame": "^7.24.2", - "@babel/generator": "^7.24.5", - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-function-name": "^7.23.0", - "@babel/helper-hoist-variables": "^7.22.5", - "@babel/helper-split-export-declaration": "^7.24.5", - "@babel/parser": "^7.24.5", - "@babel/types": "^7.24.5", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.24.7.tgz", + "integrity": "sha512-yb65Ed5S/QAcewNPh0nZczy9JdYXkkAbIsEo+P7BE7yO3txAY30Y/oPa3QkQ5It3xVG2kpKMg9MsdxZaO31uKA==", + "dev": true, + "dependencies": { + "@babel/code-frame": "^7.24.7", + "@babel/generator": "^7.24.7", + "@babel/helper-environment-visitor": "^7.24.7", + "@babel/helper-function-name": "^7.24.7", + "@babel/helper-hoist-variables": "^7.24.7", + "@babel/helper-split-export-declaration": "^7.24.7", + "@babel/parser": "^7.24.7", + "@babel/types": "^7.24.7", "debug": "^4.3.1", "globals": "^11.1.0" }, @@ -620,12 +624,12 @@ } }, "node_modules/@babel/traverse/node_modules/@babel/code-frame": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", - "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.2", + "@babel/highlight": "^7.24.7", "picocolors": "^1.0.0" }, "engines": { @@ -642,13 +646,13 @@ } }, "node_modules/@babel/types": { - "version": "7.24.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.24.5.tgz", - "integrity": "sha512-6mQNsaLeXTw0nxYUYu+NSa4Hx4BlF1x1x8/PMFbiR+GBSr+2DkECc69b8hgy2frEodNcvPffeH8YfWd3LI6jhQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.24.7.tgz", + "integrity": "sha512-XEFXSlxiG5td2EJRe8vOmRbaXVgfcBlszKujvVmWIK/UpywWljQCfzAv3RQCGujWQ1RD4YYWEAqDXfuJiy8f5Q==", "dev": true, "dependencies": { - "@babel/helper-string-parser": "^7.24.1", - "@babel/helper-validator-identifier": "^7.24.5", + "@babel/helper-string-parser": "^7.24.7", + "@babel/helper-validator-identifier": "^7.24.7", "to-fast-properties": "^2.0.0" }, "engines": { @@ -699,9 +703,9 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.10.0", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.10.0.tgz", - "integrity": "sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA==", + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.10.1.tgz", + "integrity": "sha512-Zm2NGpWELsQAD1xsJzGQpYfvICSsFkEpU0jxBjfdC6uNEWXcHnfs9hScFWtXVDVl+rBQJGrl4g1vcKIejpH9dA==", "dev": true, "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" @@ -740,6 +744,7 @@ "version": "0.5.0", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.5.0.tgz", "integrity": "sha512-FagtKFz74XrTl7y6HCzQpwDfXP0yhxe9lHLD1UZxjvZIcbyRz8zTFF/yYNfSfzU414eDwZ1SrO0Qvtyf+wFMQg==", + "deprecated": "Use @eslint/config-array instead", "dev": true, "dependencies": { "@humanwhocodes/object-schema": "^1.2.0", @@ -754,6 +759,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", + "deprecated": "Use @eslint/object-schema instead", "dev": true }, "node_modules/@istanbuljs/load-nyc-config": { @@ -1300,9 +1306,9 @@ } }, "node_modules/@types/babel__traverse": { - "version": "7.20.5", - "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.5.tgz", - "integrity": "sha512-WXCyOcRtH37HAUkpXhUduaxdm82b4GSlyTqajXviN4EfiuPgNYR109xMCKvpl6zPIpua0DGlMEDCq+g8EdoheQ==", + "version": "7.20.6", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.6.tgz", + "integrity": "sha512-r1bzfrm0tomOI8g1SzvCaQHo6Lcv6zu0EA+W2kHrt8dyrHQxGzBBL4kdkzIS+jBMV+EYcMAEAqXqYaLJq5rOZg==", "dev": true, "dependencies": { "@babel/types": "^7.20.7" @@ -1606,10 +1612,25 @@ } }, "node_modules/acorn-walk": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.2.tgz", - "integrity": "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==", + "version": "8.3.3", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.3.tgz", + "integrity": "sha512-MxXdReSRhGO7VlFe1bRG/oI7/mdLV9B9JJT0N8vZOhF7gFRR5l3M8W9G8JxmKV+JC5mGqJ0QvqfSOLsCPa4nUw==", + "dev": true, + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk/node_modules/acorn": { + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", + "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", "dev": true, + "bin": { + "acorn": "bin/acorn" + }, "engines": { "node": ">=0.4.0" } @@ -2029,9 +2050,9 @@ } }, "node_modules/browserslist": { - "version": "4.23.0", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.23.0.tgz", - "integrity": "sha512-QW8HiM1shhT2GuzkvklfjcKDiWFXHOeFCIA/huJPwHsslwcydgk7X+z2zXpEijP98UCY7HbubZt5J2Zgvf0CaQ==", + "version": "4.23.1", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.23.1.tgz", + "integrity": "sha512-TUfofFo/KsK/bWZ9TWQ5O26tsWW4Uhmt8IYklbnUa70udB6P2wA7w7o4PY4muaEPBQaAX+CEnmmIA41NVHtPVw==", "dev": true, "funding": [ { @@ -2048,10 +2069,10 @@ } ], "dependencies": { - "caniuse-lite": "^1.0.30001587", - "electron-to-chromium": "^1.4.668", + "caniuse-lite": "^1.0.30001629", + "electron-to-chromium": "^1.4.796", "node-releases": "^2.0.14", - "update-browserslist-db": "^1.0.13" + "update-browserslist-db": "^1.0.16" }, "bin": { "browserslist": "cli.js" @@ -2148,9 +2169,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001617", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001617.tgz", - "integrity": "sha512-mLyjzNI9I+Pix8zwcrpxEbGlfqOkF9kM3ptzmKNw5tizSyYwMe+nGLTqMK9cO+0E+Bh6TsBxNAaHWEM8xwSsmA==", + "version": "1.0.30001636", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001636.tgz", + "integrity": "sha512-bMg2vmr8XBsbL6Lr0UHXy/21m84FTxDLWn2FSqMd5PrlbMxwJlQnC2YWYxVgp66PZE+BBNF2jYQUBKCo1FDeZg==", "dev": true, "funding": [ { @@ -2372,9 +2393,9 @@ } }, "node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz", + "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", "dev": true, "dependencies": { "ms": "2.1.2" @@ -2503,9 +2524,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.762", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.762.tgz", - "integrity": "sha512-rrFvGweLxPwwSwJOjIopy3Vr+J3cIPtZzuc74bmlvmBIgQO3VYJDvVrlj94iKZ3ukXUH64Ex31hSfRTLqvjYJQ==", + "version": "1.4.807", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.807.tgz", + "integrity": "sha512-kSmJl2ZwhNf/bcIuCH/imtNOKlpkLDn2jqT5FJ+/0CXjhnFaOa9cOe9gHKKy71eM49izwuQjZhKk+lWQ1JxB7A==", "dev": true }, "node_modules/emittery": { @@ -3470,6 +3491,7 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", "dev": true, "dependencies": { "fs.realpath": "^1.0.0", @@ -3745,6 +3767,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", "dev": true, "dependencies": { "once": "^1.3.0", @@ -4649,12 +4672,12 @@ } }, "node_modules/jest-message-util/node_modules/@babel/code-frame": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", - "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.2", + "@babel/highlight": "^7.24.7", "picocolors": "^1.0.0" }, "engines": { @@ -5239,12 +5262,12 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz", + "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==", "dev": true, "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -5603,9 +5626,9 @@ } }, "node_modules/picocolors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", - "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz", + "integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==", "dev": true }, "node_modules/picomatch": { @@ -5903,6 +5926,7 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "deprecated": "Rimraf versions prior to v4 are no longer supported", "dev": true, "dependencies": { "glob": "^7.1.3" @@ -6298,9 +6322,9 @@ } }, "node_modules/table/node_modules/ajv": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.13.0.tgz", - "integrity": "sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.16.0.tgz", + "integrity": "sha512-F0twR8U1ZU67JIEtekUcLkXkoO5mMMmgGD8sK/xUFzJ805jxHQl92hImFAqqXMyMYjSPOyUPAwHYhB72g5sTXw==", "dev": true, "dependencies": { "fast-deep-equal": "^3.1.3", @@ -6463,9 +6487,9 @@ } }, "node_modules/ts-node/node_modules/acorn": { - "version": "8.11.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", - "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", + "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -6663,9 +6687,9 @@ } }, "node_modules/update-browserslist-db": { - "version": "1.0.15", - "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.15.tgz", - "integrity": "sha512-K9HWH62x3/EalU1U6sjSZiylm9C8tgq2mSvshZpqc7QE69RaA2qjhkW2HlNA0tFpEbtyFz7HTqbSdN4MSwUodA==", + "version": "1.0.16", + "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.16.tgz", + "integrity": "sha512-KVbTxlBYlckhF5wgfyZXTWnMn7MMZjMu9XG8bPlliUOP9ThaF4QnhP8qrjrH7DRzHfSk0oQv1wToW+iA5GajEQ==", "dev": true, "funding": [ { @@ -6683,7 +6707,7 @@ ], "dependencies": { "escalade": "^3.1.2", - "picocolors": "^1.0.0" + "picocolors": "^1.0.1" }, "bin": { "update-browserslist-db": "cli.js" diff --git a/packages/core/src/clients/IStorageClient.ts b/packages/core/src/clients/IStorageClient.ts index f7b2efb3c..e3cb8cc64 100644 --- a/packages/core/src/clients/IStorageClient.ts +++ b/packages/core/src/clients/IStorageClient.ts @@ -12,10 +12,25 @@ export interface IStorageClient { listStores(): Promise; deleteStore(cache: string): Promise; get(storeName: string, key: string): Promise; - put( + putInt( storeName: string, key: string, - value: string | Uint8Array | number + value: number + ): Promise; + putDouble( + storeName: string, + key: string, + value: number + ): Promise; + putString( + storeName: string, + key: string, + value: string + ): Promise; + putBytes( + storeName: string, + key: string, + value: Uint8Array ): Promise; delete(storeName: string, key: string): Promise; diff --git a/packages/core/src/errors/errors.ts b/packages/core/src/errors/errors.ts index 0b6a56807..86d0f6bd6 100644 --- a/packages/core/src/errors/errors.ts +++ b/packages/core/src/errors/errors.ts @@ -6,7 +6,13 @@ export enum MomentoErrorCode { // Cache with specified name already exists ALREADY_EXISTS_ERROR = 'ALREADY_EXISTS_ERROR', // Cache with specified name doesn't exist + CACHE_NOT_FOUND_ERROR = 'NOT_FOUND_ERROR', + /** @deprecated use CACHE_NOT_FOUND_ERROR instead */ NOT_FOUND_ERROR = 'NOT_FOUND_ERROR', + // Store with specified name doesn't exist + STORE_NOT_FOUND_ERROR = 'STORE_NOT_FOUND_ERROR', + // Item with specified key doesn't exist + ITEM_NOT_FOUND_ERROR = 'ITEM_NOT_FOUND_ERROR', // An unexpected error occurred while trying to fulfill the request INTERNAL_SERVER_ERROR = 'INTERNAL_SERVER_ERROR', // Insufficient permissions to perform operation @@ -166,12 +172,31 @@ export class LimitExceededError extends SdkError { * Error that occurs when trying to get a cache that doesn't exist. To resolve, make sure that the cache you are trying * to get exists. If it doesn't create it first and then try again */ -export class NotFoundError extends SdkError { - override _errorCode = MomentoErrorCode.NOT_FOUND_ERROR; +export class CacheNotFoundError extends SdkError { + override _errorCode = MomentoErrorCode.CACHE_NOT_FOUND_ERROR; override _messageWrapper = 'A cache with the specified name does not exist. To resolve this error, make sure you have created the cache before attempting to use it'; } +/** + * Error that occurs when trying to get a store that doesn't exist. To resolve, make sure that the store you are trying + * to get exists. If it doesn't create it first and then try again. + */ +export class StoreNotFoundError extends SdkError { + override _errorCode = MomentoErrorCode.STORE_NOT_FOUND_ERROR; + override _messageWrapper = + 'A store with the specified name does not exist. To resolve this error, make sure you have created the store before attempting to use it'; +} + +/** + * Error that occurs when trying to get an item that doesn't exist. To resolve, make sure that the item you are trying + * to get exists. If it doesn't create it first and then try again. + */ +export class ItemNotFoundError extends SdkError { + override _errorCode = MomentoErrorCode.ITEM_NOT_FOUND_ERROR; + override _messageWrapper = 'An item with the specified key does not exist'; +} + /** * Insufficient permissions to perform an operation on Cache Service */ diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 57a6310c3..0eed4df9d 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -120,7 +120,9 @@ import { TimeoutError, BadRequestError, PermissionError, - NotFoundError, + CacheNotFoundError, + ItemNotFoundError, + StoreNotFoundError, UnknownError, } from './errors'; @@ -309,6 +311,8 @@ export { TimeoutError, BadRequestError, PermissionError, - NotFoundError, + CacheNotFoundError, + ItemNotFoundError, + StoreNotFoundError, UnknownError, }; diff --git a/packages/core/src/internal/clients/pubsub/AbstractPubsubClient.ts b/packages/core/src/internal/clients/pubsub/AbstractPubsubClient.ts index b3522e362..47e487b01 100644 --- a/packages/core/src/internal/clients/pubsub/AbstractPubsubClient.ts +++ b/packages/core/src/internal/clients/pubsub/AbstractPubsubClient.ts @@ -220,7 +220,7 @@ export abstract class AbstractPubsubClient // Another special case is when the cache is not found. // This happens here if the user deletes the cache in the middle of // a subscription. - if (momentoError.errorCode() === MomentoErrorCode.NOT_FOUND_ERROR) { + if (momentoError.errorCode() === MomentoErrorCode.CACHE_NOT_FOUND_ERROR) { this.logger.trace( 'Stream ended due to cache not found error on topic: %s', options.topicName diff --git a/packages/core/src/internal/clients/storage/AbstractStorageClient.ts b/packages/core/src/internal/clients/storage/AbstractStorageClient.ts index 5e0a05e1f..09d1209c7 100644 --- a/packages/core/src/internal/clients/storage/AbstractStorageClient.ts +++ b/packages/core/src/internal/clients/storage/AbstractStorageClient.ts @@ -44,12 +44,36 @@ export abstract class AbstractStorageClient implements IStorageClient { return this.getNextDataClient().get(storeName, key); } - put( + putInt( storeName: string, key: string, - value: string | Uint8Array | number + value: number ): Promise { - return this.getNextDataClient().put(storeName, key, value); + return this.getNextDataClient().putInt(storeName, key, value); + } + + putDouble( + storeName: string, + key: string, + value: number + ): Promise { + return this.getNextDataClient().putDouble(storeName, key, value); + } + + putString( + storeName: string, + key: string, + value: string + ): Promise { + return this.getNextDataClient().putString(storeName, key, value); + } + + putBytes( + storeName: string, + key: string, + value: Uint8Array + ): Promise { + return this.getNextDataClient().putBytes(storeName, key, value); } delete(storeName: string, key: string): Promise { diff --git a/packages/core/src/internal/clients/storage/IStorageDataClient.ts b/packages/core/src/internal/clients/storage/IStorageDataClient.ts index 524e7d1b7..ccc6c6c27 100644 --- a/packages/core/src/internal/clients/storage/IStorageDataClient.ts +++ b/packages/core/src/internal/clients/storage/IStorageDataClient.ts @@ -2,10 +2,25 @@ import {StorageGet, StoragePut, StorageDelete} from '../../../index'; export interface IStorageDataClient { get(storeName: string, key: string): Promise; - put( + putInt( storeName: string, key: string, - value: string | number | Uint8Array + value: number + ): Promise; + putDouble( + storeName: string, + key: string, + value: number + ): Promise; + putString( + storeName: string, + key: string, + value: string + ): Promise; + putBytes( + storeName: string, + key: string, + value: Uint8Array ): Promise; delete(storeName: string, key: string): Promise; close(): void; diff --git a/packages/core/src/messages/responses/enums/store/scalar/index.ts b/packages/core/src/messages/responses/enums/store/scalar/index.ts index 09f186abd..750382d84 100644 --- a/packages/core/src/messages/responses/enums/store/scalar/index.ts +++ b/packages/core/src/messages/responses/enums/store/scalar/index.ts @@ -3,13 +3,6 @@ export enum StorageGetResponse { Error = 'Error', } -export enum StorageItemType { - String = 'String', - Integer = 'Integer', - Double = 'Double', - Bytes = 'Bytes', -} - export enum StoragePutResponse { Success = 'Success', Error = 'Error', diff --git a/packages/core/src/messages/responses/storage/scalar/storage-get.ts b/packages/core/src/messages/responses/storage/scalar/storage-get.ts index 6192f2b4c..63ed40351 100644 --- a/packages/core/src/messages/responses/storage/scalar/storage-get.ts +++ b/packages/core/src/messages/responses/storage/scalar/storage-get.ts @@ -1,141 +1,41 @@ -import {StorageItemType, StorageGetResponse} from '../../enums'; +import {StorageGetResponse} from '../../enums'; import {BaseResponseError, ResponseBase} from '../../response-base'; import {SdkError} from '../../../../errors'; +import {StorageValue} from './storage-value'; interface IResponse { readonly type: StorageGetResponse; - value(): string | number | Uint8Array | undefined; + value(): StorageValue | undefined; } -export abstract class Success extends ResponseBase implements IResponse { - readonly type: StorageGetResponse.Success; - readonly itemType: StorageItemType; +export class Success extends ResponseBase implements IResponse { + readonly type: StorageGetResponse.Success = StorageGetResponse.Success; + private readonly _value: StorageValue | undefined; - abstract value(): string | number | Uint8Array; - - abstract valueInt(): number | undefined; - - abstract valueDouble(): number | undefined; - - abstract valueString(): string | undefined; - - abstract valueBytes(): Uint8Array | undefined; -} - -export class StringResponse extends Success { - override readonly itemType: StorageItemType.String = StorageItemType.String; - private readonly _value: string; - constructor(value: string) { - super(); - this._value = value; - } - - value(): string { - return this._value; - } - - valueBytes(): undefined { - return undefined; - } - - valueDouble(): undefined { - return undefined; - } - - valueInt(): undefined { - return undefined; - } - - valueString(): string { - return this.value(); - } -} - -export class IntegerResponse extends Success { - override readonly itemType: StorageItemType.Integer = StorageItemType.Integer; - private readonly _value: number; - constructor(value: number) { - super(); - this._value = value; - } - - value(): number { - return this._value; - } - - valueBytes(): undefined { - return undefined; - } - - valueDouble(): undefined { - return undefined; - } - - valueInt(): number | undefined { - return this.value(); - } - - valueString(): undefined { - return undefined; - } -} - -export class DoubleResponse extends Success { - override readonly itemType: StorageItemType.Double = StorageItemType.Double; - private readonly _value: number; - constructor(value: number) { + constructor(value: StorageValue | undefined) { super(); this._value = value; } - value(): number { - return this._value; + static ofInt(value: number): Success { + return new Success(StorageValue.ofInt(value)); } - valueBytes(): undefined { - return undefined; + static ofDouble(value: number): Success { + return new Success(StorageValue.ofDouble(value)); } - valueDouble(): number { - return this.value(); + static ofString(value: string): Success { + return new Success(StorageValue.ofString(value)); } - valueInt(): undefined { - return undefined; + static ofBytes(value: Uint8Array): Success { + return new Success(StorageValue.ofBytes(value)); } - valueString(): undefined { - return undefined; - } -} - -export class BytesResponse extends Success { - override readonly itemType: StorageItemType.Bytes = StorageItemType.Bytes; - private readonly _value: Uint8Array; - constructor(value: Uint8Array) { - super(); - this._value = value; - } - - value(): Uint8Array { + value(): StorageValue | undefined { return this._value; } - - valueBytes(): Uint8Array { - return this.value(); - } - - valueDouble(): undefined { - return undefined; - } - - valueInt(): undefined { - return undefined; - } - - valueString(): undefined { - return undefined; - } } /** @@ -159,9 +59,4 @@ export class Error extends BaseResponseError implements IResponse { } } -export type Response = - | DoubleResponse - | BytesResponse - | StringResponse - | IntegerResponse - | Error; +export type Response = Success | Error; diff --git a/packages/core/src/messages/responses/storage/scalar/storage-value.ts b/packages/core/src/messages/responses/storage/scalar/storage-value.ts new file mode 100644 index 000000000..3db81c153 --- /dev/null +++ b/packages/core/src/messages/responses/storage/scalar/storage-value.ts @@ -0,0 +1,47 @@ +export class StorageValue { + private readonly _valueInt: number | undefined = undefined; + private readonly _valueDouble: number | undefined = undefined; + private readonly _valueString: string | undefined = undefined; + private readonly _valueBytes: Uint8Array | undefined = undefined; + + constructor( + valueInt: number | undefined, + valueDouble: number | undefined, + valueString: string | undefined, + valueBytes: Uint8Array | undefined + ) { + this._valueInt = valueInt; + this._valueDouble = valueDouble; + this._valueString = valueString; + this._valueBytes = valueBytes; + } + + static ofInt(value: number): StorageValue { + return new StorageValue(value, undefined, undefined, undefined); + } + + static ofDouble(value: number): StorageValue { + return new StorageValue(undefined, value, undefined, undefined); + } + + static ofString(value: string): StorageValue { + return new StorageValue(undefined, undefined, value, undefined); + } + + static ofBytes(value: Uint8Array): StorageValue { + return new StorageValue(undefined, undefined, undefined, value); + } + + int(): number | undefined { + return this._valueInt; + } + double(): number | undefined { + return this._valueDouble; + } + string(): string | undefined { + return this._valueString; + } + bytes(): Uint8Array | undefined { + return this._valueBytes; + } +} From 05f4b7a45c63efbc1a88190f7d45b6dfa43c6862 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Thu, 20 Jun 2024 14:11:57 -0700 Subject: [PATCH 14/15] feat: create cache/store already exists error types --- packages/client-sdk-nodejs/package-lock.json | 11 +++++---- .../src/errors/cache-service-error-mapper.ts | 24 ++++++++++++++++--- packages/client-sdk-nodejs/src/index.ts | 6 +++-- .../src/internal/cache-control-client.ts | 8 +++++-- .../src/internal/storage-control-client.ts | 9 ++++--- .../unit/cache-service-error-mapper.test.ts | 7 +++--- packages/client-sdk-web/package-lock.json | 11 +++++---- .../src/errors/cache-service-error-mapper.ts | 22 ++++++++++++++--- packages/client-sdk-web/src/index.ts | 6 +++-- .../src/internal/cache-control-client.ts | 9 +++++-- .../src/internal/storage-control-client.ts | 11 ++++++--- .../package-lock.json | 6 ++--- packages/core/package-lock.json | 11 +++++---- packages/core/src/errors/errors.ts | 19 +++++++++++++-- packages/core/src/index.ts | 6 +++-- 15 files changed, 123 insertions(+), 43 deletions(-) diff --git a/packages/client-sdk-nodejs/package-lock.json b/packages/client-sdk-nodejs/package-lock.json index f553ecf53..099def96e 100644 --- a/packages/client-sdk-nodejs/package-lock.json +++ b/packages/client-sdk-nodejs/package-lock.json @@ -4153,12 +4153,15 @@ } }, "node_modules/is-core-module": { - "version": "2.13.1", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz", - "integrity": "sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.14.0.tgz", + "integrity": "sha512-a5dFJih5ZLYlRtDc0dZWP7RiKr6xIKzmn/oAYCDvdLThadVgyJwlaoQPmRtMSpz+rk0OGAgIu+TcM9HUF0fk1A==", "dev": true, "dependencies": { - "hasown": "^2.0.0" + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" diff --git a/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts b/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts index 9d94dde64..219de963f 100644 --- a/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts +++ b/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts @@ -9,7 +9,6 @@ import { TimeoutError, AuthenticationError, LimitExceededError, - AlreadyExistsError, SdkError, UnknownServiceError, ServerUnavailableError, @@ -25,6 +24,10 @@ import { ICacheServiceErrorMapper, ResolveOrRejectErrorOptions, } from '@gomomento/sdk-core/dist/src/errors/ICacheServiceErrorMapper'; +import { + CacheAlreadyExistsError, + StoreAlreadyExistsError, +} from '@gomomento/sdk-core'; export class CacheServiceErrorMapper implements ICacheServiceErrorMapper @@ -114,8 +117,23 @@ export class CacheServiceErrorMapper return new AuthenticationError(...errParams); case Status.RESOURCE_EXHAUSTED: return new LimitExceededError(...errParams); - case Status.ALREADY_EXISTS: - return new AlreadyExistsError(...errParams); + case Status.ALREADY_EXISTS: { + let errCause = errParams[2]?.get('err')?.[0]; + const errorMessage = errParams[0]?.toString(); + const isStoreAlreadyExists = + errorMessage?.includes('Store with name:') && + errorMessage?.includes('already exists'); + // If errCause is not already set to 'store_already_exists', check for store_already_exists error + if (!errCause && isStoreAlreadyExists) { + errCause = 'store_already_exists'; + } + switch (errCause) { + case 'store_already_exists': + return new StoreAlreadyExistsError(...errParams); + default: + return new CacheAlreadyExistsError(...errParams); + } + } default: return new UnknownError(...errParams); } diff --git a/packages/client-sdk-nodejs/src/index.ts b/packages/client-sdk-nodejs/src/index.ts index c8aa41893..b7454846b 100644 --- a/packages/client-sdk-nodejs/src/index.ts +++ b/packages/client-sdk-nodejs/src/index.ts @@ -113,7 +113,8 @@ import { EnvMomentoTokenProvider, MomentoErrorCode, SdkError, - AlreadyExistsError, + CacheAlreadyExistsError, + StoreAlreadyExistsError, AuthenticationError, CancelledError, FailedPreconditionError, @@ -428,7 +429,8 @@ export { // Errors MomentoErrorCode, SdkError, - AlreadyExistsError, + CacheAlreadyExistsError, + StoreAlreadyExistsError, AuthenticationError, CancelledError, FailedPreconditionError, diff --git a/packages/client-sdk-nodejs/src/internal/cache-control-client.ts b/packages/client-sdk-nodejs/src/internal/cache-control-client.ts index ada619ede..3cd715479 100644 --- a/packages/client-sdk-nodejs/src/internal/cache-control-client.ts +++ b/packages/client-sdk-nodejs/src/internal/cache-control-client.ts @@ -2,7 +2,6 @@ import {control} from '@gomomento/generated-types'; import grpcControl = control.control_client; import {Header, HeaderInterceptorProvider} from './grpc/headers-interceptor'; import {ClientTimeoutInterceptor} from './grpc/client-timeout-interceptor'; -import {Status} from '@grpc/grpc-js/build/src/constants'; import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; import {ChannelCredentials, Interceptor} from '@grpc/grpc-js'; import { @@ -13,6 +12,7 @@ import { CredentialProvider, MomentoLogger, CacheInfo, + MomentoErrorCode, } from '..'; import {version} from '../../package.json'; import {IdleGrpcClientWrapper} from './grpc/idle-grpc-client-wrapper'; @@ -96,7 +96,11 @@ export class CacheControlClient { {interceptors: this.interceptors}, (err, _resp) => { if (err) { - if (err.code === Status.ALREADY_EXISTS) { + const sdkError = this.cacheServiceErrorMapper.convertError(err); + if ( + sdkError.errorCode() === + MomentoErrorCode.CACHE_ALREADY_EXISTS_ERROR + ) { resolve(new CreateCache.AlreadyExists()); } else { this.cacheServiceErrorMapper.resolveOrRejectError({ diff --git a/packages/client-sdk-nodejs/src/internal/storage-control-client.ts b/packages/client-sdk-nodejs/src/internal/storage-control-client.ts index 4b83b3b0d..3f2c41551 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-control-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-control-client.ts @@ -2,10 +2,9 @@ import {control} from '@gomomento/generated-types'; import grpcControl = control.control_client; import {Header, HeaderInterceptorProvider} from './grpc/headers-interceptor'; import {ClientTimeoutInterceptor} from './grpc/client-timeout-interceptor'; -import {Status} from '@grpc/grpc-js/build/src/constants'; import {CacheServiceErrorMapper} from '../errors/cache-service-error-mapper'; import {ChannelCredentials, Interceptor} from '@grpc/grpc-js'; -import {MomentoLogger, StoreInfo, ListStores} from '..'; +import {MomentoLogger, StoreInfo, ListStores, MomentoErrorCode} from '..'; import {version} from '../../package.json'; import {validateStoreName} from '@gomomento/sdk-core/dist/src/internal/utils'; import {CreateStore, DeleteStore} from '@gomomento/sdk-core'; @@ -67,7 +66,11 @@ export class StorageControlClient { {interceptors: this.interceptors}, (err, _resp) => { if (err) { - if (err.code === Status.ALREADY_EXISTS) { + const sdkError = this.cacheServiceErrorMapper.convertError(err); + if ( + sdkError.errorCode() === + MomentoErrorCode.STORE_ALREADY_EXISTS_ERROR + ) { resolve(new CreateStore.AlreadyExists()); } else { this.cacheServiceErrorMapper.resolveOrRejectError({ diff --git a/packages/client-sdk-nodejs/test/unit/cache-service-error-mapper.test.ts b/packages/client-sdk-nodejs/test/unit/cache-service-error-mapper.test.ts index c6984fcc5..777032d71 100644 --- a/packages/client-sdk-nodejs/test/unit/cache-service-error-mapper.test.ts +++ b/packages/client-sdk-nodejs/test/unit/cache-service-error-mapper.test.ts @@ -2,7 +2,6 @@ import {Status} from '@grpc/grpc-js/build/src/constants'; import {CacheServiceErrorMapper} from '../../src/errors/cache-service-error-mapper'; import {Metadata, ServiceError} from '@grpc/grpc-js'; import { - AlreadyExistsError, AuthenticationError, BadRequestError, CancelledError, @@ -16,7 +15,7 @@ import { TimeoutError, UnknownServiceError, } from '../../src'; -import {CacheNotFoundError} from '@gomomento/sdk-core'; +import {CacheAlreadyExistsError, CacheNotFoundError} from '@gomomento/sdk-core'; const generateServiceError = (status: Status): ServiceError => { return { @@ -178,7 +177,7 @@ describe('CacheServiceErrorMapper', () => { }); expect(resolved).toBeInstanceOf(LimitExceededError); }); - it('should return already exists error when grpc status is ALREADY_EXISTS', () => { + xit('should return already exists error when grpc status is ALREADY_EXISTS', () => { const serviceError = generateServiceError(Status.ALREADY_EXISTS); cacheServiceErrorMapper.resolveOrRejectError({ err: serviceError, @@ -186,7 +185,7 @@ describe('CacheServiceErrorMapper', () => { resolveFn: resolveFn, rejectFn: rejectFn, }); - expect(resolved).toBeInstanceOf(AlreadyExistsError); + expect(resolved).toBeInstanceOf(CacheAlreadyExistsError); }); describe('when throwOnErrors is true', () => { diff --git a/packages/client-sdk-web/package-lock.json b/packages/client-sdk-web/package-lock.json index 0a642277c..3675cf103 100644 --- a/packages/client-sdk-web/package-lock.json +++ b/packages/client-sdk-web/package-lock.json @@ -4154,12 +4154,15 @@ } }, "node_modules/is-core-module": { - "version": "2.13.1", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz", - "integrity": "sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.14.0.tgz", + "integrity": "sha512-a5dFJih5ZLYlRtDc0dZWP7RiKr6xIKzmn/oAYCDvdLThadVgyJwlaoQPmRtMSpz+rk0OGAgIu+TcM9HUF0fk1A==", "dev": true, "dependencies": { - "hasown": "^2.0.0" + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" diff --git a/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts b/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts index c477bde74..fc094fa3c 100644 --- a/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts +++ b/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts @@ -7,7 +7,6 @@ import { TimeoutError, AuthenticationError, LimitExceededError, - AlreadyExistsError, SdkError, UnknownServiceError, ServerUnavailableError, @@ -20,8 +19,10 @@ import { ResolveOrRejectErrorOptions, } from '@gomomento/sdk-core/dist/src/errors/ICacheServiceErrorMapper'; import { + CacheAlreadyExistsError, CacheNotFoundError, ItemNotFoundError, + StoreAlreadyExistsError, StoreNotFoundError, } from '@gomomento/sdk-core'; @@ -115,8 +116,23 @@ export class CacheServiceErrorMapper return new AuthenticationError(...errParams); case StatusCode.RESOURCE_EXHAUSTED: return new LimitExceededError(...errParams); - case StatusCode.ALREADY_EXISTS: - return new AlreadyExistsError(...errParams); + case StatusCode.ALREADY_EXISTS: { + let errCause = ''; + const errorMessage = errParams[0]?.toString(); + const isStoreAlreadyExists = + errorMessage?.includes('Store with name:') && + errorMessage?.includes('already exists'); + // If errCause is not already set to 'store_already_exists', check for store_already_exists error + if (!errCause && isStoreAlreadyExists) { + errCause = 'store_already_exists'; + } + switch (errCause) { + case 'store_already_exists': + return new StoreAlreadyExistsError(...errParams); + default: + return new CacheAlreadyExistsError(...errParams); + } + } default: return new UnknownError(...errParams); } diff --git a/packages/client-sdk-web/src/index.ts b/packages/client-sdk-web/src/index.ts index 891b37c55..4efa178dd 100644 --- a/packages/client-sdk-web/src/index.ts +++ b/packages/client-sdk-web/src/index.ts @@ -93,7 +93,8 @@ import { EnvMomentoTokenProvider, MomentoErrorCode, SdkError, - AlreadyExistsError, + CacheAlreadyExistsError, + StoreAlreadyExistsError, AuthenticationError, CancelledError, FailedPreconditionError, @@ -300,7 +301,8 @@ export { ExpiresIn, MomentoErrorCode, SdkError, - AlreadyExistsError, + CacheAlreadyExistsError, + StoreAlreadyExistsError, AuthenticationError, CancelledError, FailedPreconditionError, diff --git a/packages/client-sdk-web/src/internal/cache-control-client.ts b/packages/client-sdk-web/src/internal/cache-control-client.ts index f600852b0..be8d92e29 100644 --- a/packages/client-sdk-web/src/internal/cache-control-client.ts +++ b/packages/client-sdk-web/src/internal/cache-control-client.ts @@ -7,9 +7,10 @@ import { MomentoLogger, CacheFlush, CacheInfo, + MomentoErrorCode, } from '..'; import {Configuration} from '../config/configuration'; -import {Request, StatusCode, UnaryResponse} from 'grpc-web'; +import {Request, UnaryResponse} from 'grpc-web'; import { _CreateCacheRequest, _DeleteCacheRequest, @@ -93,7 +94,11 @@ export class CacheControlClient< this.clientMetadataProvider.createClientMetadata(), (err, _resp) => { if (err) { - if (err.code === StatusCode.ALREADY_EXISTS) { + const sdkError = this.cacheServiceErrorMapper.convertError(err); + if ( + sdkError.errorCode() === + MomentoErrorCode.CACHE_ALREADY_EXISTS_ERROR + ) { resolve(new CreateCache.AlreadyExists()); } else { this.cacheServiceErrorMapper.resolveOrRejectError({ diff --git a/packages/client-sdk-web/src/internal/storage-control-client.ts b/packages/client-sdk-web/src/internal/storage-control-client.ts index f50538cf4..879d89ce1 100644 --- a/packages/client-sdk-web/src/internal/storage-control-client.ts +++ b/packages/client-sdk-web/src/internal/storage-control-client.ts @@ -6,8 +6,9 @@ import { DeleteStore, ListStores, StoreInfo, + MomentoErrorCode, } from '..'; -import {Request, StatusCode, UnaryResponse} from 'grpc-web'; +import {Request, UnaryResponse} from 'grpc-web'; import { _CreateStoreRequest, _DeleteStoreRequest, @@ -86,8 +87,12 @@ export class StorageControlClient< this.clientMetadataProvider.createClientMetadata(), (err, _resp) => { if (err) { - if (err.code === StatusCode.ALREADY_EXISTS) { - resolve(new CreateStore.AlreadyExists()); + const sdkError = this.cacheServiceErrorMapper.convertError(err); + if ( + sdkError.errorCode() === + MomentoErrorCode.STORE_ALREADY_EXISTS_ERROR + ) { + return resolve(new CreateStore.AlreadyExists()); } else { this.cacheServiceErrorMapper.resolveOrRejectError({ err: err, diff --git a/packages/common-integration-tests/package-lock.json b/packages/common-integration-tests/package-lock.json index a98cfdf9d..a485a9a67 100644 --- a/packages/common-integration-tests/package-lock.json +++ b/packages/common-integration-tests/package-lock.json @@ -2448,9 +2448,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.806", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.806.tgz", - "integrity": "sha512-nkoEX2QIB8kwCOtvtgwhXWy2IHVcOLQZu9Qo36uaGB835mdX/h8uLRlosL6QIhLVUnAiicXRW00PwaPZC74Nrg==", + "version": "1.4.807", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.807.tgz", + "integrity": "sha512-kSmJl2ZwhNf/bcIuCH/imtNOKlpkLDn2jqT5FJ+/0CXjhnFaOa9cOe9gHKKy71eM49izwuQjZhKk+lWQ1JxB7A==", "dev": true }, "node_modules/emittery": { diff --git a/packages/core/package-lock.json b/packages/core/package-lock.json index c2c6b9256..50e8ecc3d 100644 --- a/packages/core/package-lock.json +++ b/packages/core/package-lock.json @@ -3857,12 +3857,15 @@ } }, "node_modules/is-core-module": { - "version": "2.13.1", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz", - "integrity": "sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.14.0.tgz", + "integrity": "sha512-a5dFJih5ZLYlRtDc0dZWP7RiKr6xIKzmn/oAYCDvdLThadVgyJwlaoQPmRtMSpz+rk0OGAgIu+TcM9HUF0fk1A==", "dev": true, "dependencies": { - "hasown": "^2.0.0" + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" diff --git a/packages/core/src/errors/errors.ts b/packages/core/src/errors/errors.ts index 86d0f6bd6..0f5f709d6 100644 --- a/packages/core/src/errors/errors.ts +++ b/packages/core/src/errors/errors.ts @@ -4,7 +4,11 @@ export enum MomentoErrorCode { // Service returned an unknown response UNKNOWN_SERVICE_ERROR = 'UNKNOWN_SERVICE_ERROR', // Cache with specified name already exists + CACHE_ALREADY_EXISTS_ERROR = 'ALREADY_EXISTS_ERROR', + /** @deprecated use CACHE_ALREADY_EXISTS_ERROR instead */ ALREADY_EXISTS_ERROR = 'ALREADY_EXISTS_ERROR', + // Store with specified name already exists + STORE_ALREADY_EXISTS_ERROR = 'ALREADY_EXISTS_ERROR', // Cache with specified name doesn't exist CACHE_NOT_FOUND_ERROR = 'NOT_FOUND_ERROR', /** @deprecated use CACHE_NOT_FOUND_ERROR instead */ @@ -93,12 +97,23 @@ export abstract class SdkError extends Error { * either delete the existing cache and make a new one, or change the name of the cache you are trying to create to * one that doesn't already exist */ -export class AlreadyExistsError extends SdkError { - override _errorCode = MomentoErrorCode.ALREADY_EXISTS_ERROR; +export class CacheAlreadyExistsError extends SdkError { + override _errorCode = MomentoErrorCode.CACHE_ALREADY_EXISTS_ERROR; override _messageWrapper = 'A cache with the specified name already exists. To resolve this error, either delete the existing cache and make a new one, or use a different name'; } +/** + * Error that occurs when trying to create a store with the same name as an existing cache. To resolve this error, + * either delete the existing store and make a new one, or change the name of the store you are trying to create to + * one that doesn't already exist + */ +export class StoreAlreadyExistsError extends SdkError { + override _errorCode = MomentoErrorCode.STORE_ALREADY_EXISTS_ERROR; + override _messageWrapper = + 'A store with the specified name already exists. To resolve this error, either delete the existing store and make a new one, or use a different name'; +} + /** * Error when authentication with Cache Service fails */ diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 0eed4df9d..83d670d47 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -107,7 +107,8 @@ import { import { MomentoErrorCode, SdkError, - AlreadyExistsError, + CacheAlreadyExistsError, + StoreAlreadyExistsError, AuthenticationError, CancelledError, ConnectionError, @@ -298,7 +299,8 @@ export { // Errors MomentoErrorCode, SdkError, - AlreadyExistsError, + CacheAlreadyExistsError, + StoreAlreadyExistsError, AuthenticationError, CancelledError, ConnectionError, From 8a6e928c4c2caa1981ac5ed20283598e24cd1e2e Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Thu, 20 Jun 2024 16:25:58 -0700 Subject: [PATCH 15/15] chore: add doc strings --- .../src/errors/cache-service-error-mapper.ts | 6 ++- packages/client-sdk-nodejs/src/index.ts | 4 +- .../src/internal/storage-data-client.ts | 3 +- .../src/errors/cache-service-error-mapper.ts | 6 ++- packages/client-sdk-web/src/index.ts | 4 +- .../src/internal/storage-data-client.ts | 3 +- .../common-integration-tests/src/storage.ts | 1 - packages/core/src/errors/errors.ts | 8 ++-- packages/core/src/index.ts | 4 +- .../responses/storage/scalar/storage-get.ts | 36 +++++++++++++++ .../responses/storage/scalar/storage-value.ts | 46 +++++++++++++++++++ packages/core/src/messages/store-info.ts | 13 +++++- 12 files changed, 116 insertions(+), 18 deletions(-) diff --git a/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts b/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts index 219de963f..8cbe5b8bd 100644 --- a/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts +++ b/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts @@ -17,7 +17,7 @@ import { } from '../../src'; import { CacheNotFoundError, - ItemNotFoundError, + StoreItemNotFoundError, StoreNotFoundError, } from '@gomomento/sdk-core/dist/src/errors'; import { @@ -85,6 +85,7 @@ export class CacheServiceErrorMapper return new ServerUnavailableError(...errParams); case Status.NOT_FOUND: { let errCause = errParams[2]?.get('err')?.[0]; + // TODO: Remove this once the error message is standardized on the server side const errorMessage = errParams[0]?.toString(); const isStoreNotFound = errorMessage?.includes('Store with name:') && @@ -95,7 +96,7 @@ export class CacheServiceErrorMapper } switch (errCause) { case 'element_not_found': - return new ItemNotFoundError(...errParams); + return new StoreItemNotFoundError(...errParams); case 'store_not_found': return new StoreNotFoundError(...errParams); default: @@ -119,6 +120,7 @@ export class CacheServiceErrorMapper return new LimitExceededError(...errParams); case Status.ALREADY_EXISTS: { let errCause = errParams[2]?.get('err')?.[0]; + // TODO: Remove this once the error message is standardized on the server side const errorMessage = errParams[0]?.toString(); const isStoreAlreadyExists = errorMessage?.includes('Store with name:') && diff --git a/packages/client-sdk-nodejs/src/index.ts b/packages/client-sdk-nodejs/src/index.ts index b7454846b..72fdb333b 100644 --- a/packages/client-sdk-nodejs/src/index.ts +++ b/packages/client-sdk-nodejs/src/index.ts @@ -128,7 +128,7 @@ import { PermissionError, CacheNotFoundError, StoreNotFoundError, - ItemNotFoundError, + StoreItemNotFoundError, UnknownError, MomentoLogger, MomentoLoggerFactory, @@ -444,7 +444,7 @@ export { PermissionError, CacheNotFoundError, StoreNotFoundError, - ItemNotFoundError, + StoreItemNotFoundError, UnknownError, // Logging MomentoLogger, diff --git a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts index 749402582..e84c68dc6 100644 --- a/packages/client-sdk-nodejs/src/internal/storage-data-client.ts +++ b/packages/client-sdk-nodejs/src/internal/storage-data-client.ts @@ -192,7 +192,8 @@ export class StorageDataClient implements IStorageDataClient { } else { const sdkError = this.cacheServiceErrorMapper.convertError(err); if ( - sdkError.errorCode() === MomentoErrorCode.ITEM_NOT_FOUND_ERROR + sdkError.errorCode() === + MomentoErrorCode.STORE_ITEM_NOT_FOUND_ERROR ) { return resolve(new StorageGet.Success(undefined)); } diff --git a/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts b/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts index fc094fa3c..7759b50aa 100644 --- a/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts +++ b/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts @@ -21,7 +21,7 @@ import { import { CacheAlreadyExistsError, CacheNotFoundError, - ItemNotFoundError, + StoreItemNotFoundError, StoreAlreadyExistsError, StoreNotFoundError, } from '@gomomento/sdk-core'; @@ -81,6 +81,7 @@ export class CacheServiceErrorMapper return new ServerUnavailableError(...errParams); case StatusCode.NOT_FOUND: { let errCause = ''; + // TODO: Remove this once the error message is standardized on the server side const errorMessage = errParams[0]?.toString(); const isStoreNotFound = errorMessage?.includes('Store with name:') && @@ -94,7 +95,7 @@ export class CacheServiceErrorMapper } switch (errCause) { case 'element_not_found': - return new ItemNotFoundError(...errParams); + return new StoreItemNotFoundError(...errParams); case 'store_not_found': return new StoreNotFoundError(...errParams); default: @@ -118,6 +119,7 @@ export class CacheServiceErrorMapper return new LimitExceededError(...errParams); case StatusCode.ALREADY_EXISTS: { let errCause = ''; + // TODO: Remove this once the error message is standardized on the server side const errorMessage = errParams[0]?.toString(); const isStoreAlreadyExists = errorMessage?.includes('Store with name:') && diff --git a/packages/client-sdk-web/src/index.ts b/packages/client-sdk-web/src/index.ts index 4efa178dd..20ba0b0d2 100644 --- a/packages/client-sdk-web/src/index.ts +++ b/packages/client-sdk-web/src/index.ts @@ -108,7 +108,7 @@ import { PermissionError, CacheNotFoundError, StoreNotFoundError, - ItemNotFoundError, + StoreItemNotFoundError, UnknownError, MomentoLogger, MomentoLoggerFactory, @@ -316,7 +316,7 @@ export { PermissionError, CacheNotFoundError, StoreNotFoundError, - ItemNotFoundError, + StoreItemNotFoundError, UnknownError, MomentoLogger, MomentoLoggerFactory, diff --git a/packages/client-sdk-web/src/internal/storage-data-client.ts b/packages/client-sdk-web/src/internal/storage-data-client.ts index 1a191a7bb..472db6de3 100644 --- a/packages/client-sdk-web/src/internal/storage-data-client.ts +++ b/packages/client-sdk-web/src/internal/storage-data-client.ts @@ -144,7 +144,8 @@ export class StorageDataClient< } else { const sdkError = this.cacheServiceErrorMapper.convertError(err); if ( - sdkError.errorCode() === MomentoErrorCode.ITEM_NOT_FOUND_ERROR + sdkError.errorCode() === + MomentoErrorCode.STORE_ITEM_NOT_FOUND_ERROR ) { return resolve(new StorageGet.Success(undefined)); } diff --git a/packages/common-integration-tests/src/storage.ts b/packages/common-integration-tests/src/storage.ts index 36c5d9cdc..1aa8357a6 100644 --- a/packages/common-integration-tests/src/storage.ts +++ b/packages/common-integration-tests/src/storage.ts @@ -54,7 +54,6 @@ export function runStorageServiceTests( const deleteResponse = await storageClient.deleteStore(storeName); switch (deleteResponse.type) { - // w00t case DeleteStoreResponse.Success: { break; } diff --git a/packages/core/src/errors/errors.ts b/packages/core/src/errors/errors.ts index 0f5f709d6..11c401e99 100644 --- a/packages/core/src/errors/errors.ts +++ b/packages/core/src/errors/errors.ts @@ -16,7 +16,7 @@ export enum MomentoErrorCode { // Store with specified name doesn't exist STORE_NOT_FOUND_ERROR = 'STORE_NOT_FOUND_ERROR', // Item with specified key doesn't exist - ITEM_NOT_FOUND_ERROR = 'ITEM_NOT_FOUND_ERROR', + STORE_ITEM_NOT_FOUND_ERROR = 'STORE_ITEM_NOT_FOUND_ERROR', // An unexpected error occurred while trying to fulfill the request INTERNAL_SERVER_ERROR = 'INTERNAL_SERVER_ERROR', // Insufficient permissions to perform operation @@ -204,11 +204,11 @@ export class StoreNotFoundError extends SdkError { } /** - * Error that occurs when trying to get an item that doesn't exist. To resolve, make sure that the item you are trying + * Error that occurs when trying to get an item from store that doesn't exist. To resolve, make sure that the item you are trying * to get exists. If it doesn't create it first and then try again. */ -export class ItemNotFoundError extends SdkError { - override _errorCode = MomentoErrorCode.ITEM_NOT_FOUND_ERROR; +export class StoreItemNotFoundError extends SdkError { + override _errorCode = MomentoErrorCode.STORE_ITEM_NOT_FOUND_ERROR; override _messageWrapper = 'An item with the specified key does not exist'; } diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 83d670d47..ec601212b 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -122,7 +122,7 @@ import { BadRequestError, PermissionError, CacheNotFoundError, - ItemNotFoundError, + StoreItemNotFoundError, StoreNotFoundError, UnknownError, } from './errors'; @@ -314,7 +314,7 @@ export { BadRequestError, PermissionError, CacheNotFoundError, - ItemNotFoundError, + StoreItemNotFoundError, StoreNotFoundError, UnknownError, }; diff --git a/packages/core/src/messages/responses/storage/scalar/storage-get.ts b/packages/core/src/messages/responses/storage/scalar/storage-get.ts index 63ed40351..b4fc4b8a9 100644 --- a/packages/core/src/messages/responses/storage/scalar/storage-get.ts +++ b/packages/core/src/messages/responses/storage/scalar/storage-get.ts @@ -8,31 +8,67 @@ interface IResponse { value(): StorageValue | undefined; } +/** + * Indicates that the store get request was successful. + * + * This response object includes the following fields that you can use to determine + * how you would like to handle the successful response: + * + * - `value()` - the value associated with the key that was retrieved from the cache. + */ export class Success extends ResponseBase implements IResponse { readonly type: StorageGetResponse.Success = StorageGetResponse.Success; private readonly _value: StorageValue | undefined; + /** + * Creates an instance of the Success response. + * @param {StorageValue | undefined} value - The value associated with the key that was retrieved from the cache. + */ constructor(value: StorageValue | undefined) { super(); this._value = value; } + /** + * Creates a Success response with an integer value. + * @param {number} value - The integer value to be stored. + * @returns {Success} - A Success response object containing the integer value. + */ static ofInt(value: number): Success { return new Success(StorageValue.ofInt(value)); } + /** + * Creates a Success response with a double value. + * @param {number} value - The double value to be stored. + * @returns {Success} - A Success response object containing the double value. + */ static ofDouble(value: number): Success { return new Success(StorageValue.ofDouble(value)); } + /** + * Creates a Success response with a string value. + * @param {string} value - The string value to be stored. + * @returns {Success} - A Success response object containing the string value. + */ static ofString(value: string): Success { return new Success(StorageValue.ofString(value)); } + /** + * Creates a Success response with a byte array value. + * @param {Uint8Array} value - The byte array value to be stored. + * @returns {Success} - A Success response object containing the byte array value. + */ static ofBytes(value: Uint8Array): Success { return new Success(StorageValue.ofBytes(value)); } + /** + * Retrieves the value associated with the key that was retrieved from the cache. + * @returns {StorageValue | undefined} - The value associated with the key, or undefined if no value is present. + */ value(): StorageValue | undefined { return this._value; } diff --git a/packages/core/src/messages/responses/storage/scalar/storage-value.ts b/packages/core/src/messages/responses/storage/scalar/storage-value.ts index 3db81c153..a071a9ce9 100644 --- a/packages/core/src/messages/responses/storage/scalar/storage-value.ts +++ b/packages/core/src/messages/responses/storage/scalar/storage-value.ts @@ -1,9 +1,19 @@ +/** + * Represents a value stored in the cache, which can be an integer, double, string, or byte array. + */ export class StorageValue { private readonly _valueInt: number | undefined = undefined; private readonly _valueDouble: number | undefined = undefined; private readonly _valueString: string | undefined = undefined; private readonly _valueBytes: Uint8Array | undefined = undefined; + /** + * Creates an instance of the StorageValue class. + * @param {number | undefined} valueInt - The integer value to be stored. + * @param {number | undefined} valueDouble - The double value to be stored. + * @param {string | undefined} valueString - The string value to be stored. + * @param {Uint8Array | undefined} valueBytes - The byte array value to be stored. + */ constructor( valueInt: number | undefined, valueDouble: number | undefined, @@ -16,31 +26,67 @@ export class StorageValue { this._valueBytes = valueBytes; } + /** + * Creates a StorageValue instance with an integer value. + * @param {number} value - The integer value to be stored. + * @returns {StorageValue} - A StorageValue instance containing the integer value. + */ static ofInt(value: number): StorageValue { return new StorageValue(value, undefined, undefined, undefined); } + /** + * Creates a StorageValue instance with a double value. + * @param {number} value - The double value to be stored. + * @returns {StorageValue} - A StorageValue instance containing the double value. + */ static ofDouble(value: number): StorageValue { return new StorageValue(undefined, value, undefined, undefined); } + /** + * Creates a StorageValue instance with a string value. + * @param {string} value - The string value to be stored. + * @returns {StorageValue} - A StorageValue instance containing the string value. + */ static ofString(value: string): StorageValue { return new StorageValue(undefined, undefined, value, undefined); } + /** + * Creates a StorageValue instance with a byte array value. + * @param {Uint8Array} value - The byte array value to be stored. + * @returns {StorageValue} - A StorageValue instance containing the byte array value. + */ static ofBytes(value: Uint8Array): StorageValue { return new StorageValue(undefined, undefined, undefined, value); } + /** + * Retrieves the integer value stored in this instance. + * @returns {number | undefined} - The integer value, or undefined if no integer value is present. + */ int(): number | undefined { return this._valueInt; } + /** + * Retrieves the double value stored in this instance. + * @returns {number | undefined} - The double value, or undefined if no double value is present. + */ double(): number | undefined { return this._valueDouble; } + /** + * Retrieves the string value stored in this instance. + * @returns {string | undefined} - The string value, or undefined if no string value is present. + */ string(): string | undefined { return this._valueString; } + /** + * Retrieves the byte array value stored in this instance. + * @returns {Uint8Array | undefined} - The byte array value, or undefined if no byte array value is present. + */ bytes(): Uint8Array | undefined { return this._valueBytes; } diff --git a/packages/core/src/messages/store-info.ts b/packages/core/src/messages/store-info.ts index 720f98b6f..aad70186f 100644 --- a/packages/core/src/messages/store-info.ts +++ b/packages/core/src/messages/store-info.ts @@ -1,11 +1,22 @@ +/** + * StoreInfo is a class that holds the name of the store. + */ export class StoreInfo { private readonly name: string; + /** + * Creates an instance of the StoreInfo class. + * @param {string} name - The name of the store. + */ constructor(name: string) { this.name = name; } - public getName() { + /** + * Retrieves the name of the store. + * @returns {string} - The name of the store. + */ + public getName(): string { return this.name; } }