@fsvreddit/fsv-devvit-web-helpers 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,28 +1,28 @@
1
- BSD 3-Clause License
2
-
3
- Copyright (c) 2024, fsv
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are met:
7
-
8
- 1. Redistributions of source code must retain the above copyright notice, this
9
- list of conditions and the following disclaimer.
10
-
11
- 2. Redistributions in binary form must reproduce the above copyright notice,
12
- this list of conditions and the following disclaimer in the documentation
13
- and/or other materials provided with the distribution.
14
-
15
- 3. Neither the name of the copyright holder nor the names of its
16
- contributors may be used to endorse or promote products derived from
17
- this software without specific prior written permission.
18
-
19
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, fsv
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -46,4 +46,10 @@ export declare function zRangeAsRecord(key: string, start: number | string, stop
46
46
  * @param expireAt The expiration date.
47
47
  */
48
48
  export declare function expireKeyAt(key: string, expireAt: Date): Promise<void>;
49
+ /**
50
+ * Retrieves multiple keys from Redis and returns them as a record/object.
51
+ * @param keys The keys to retrieve.
52
+ * @returns {Record<string, string>} A record/object with keys and their corresponding values.
53
+ */
54
+ export declare function mGetAsRecord(keys: string[]): Promise<Record<string, string>>;
49
55
  export {};
@@ -6,6 +6,7 @@ exports.hMGetAsRecord = hMGetAsRecord;
6
6
  exports.hGetAllChunked = hGetAllChunked;
7
7
  exports.zRangeAsRecord = zRangeAsRecord;
8
8
  exports.expireKeyAt = expireKeyAt;
9
+ exports.mGetAsRecord = mGetAsRecord;
9
10
  const server_1 = require("@devvit/web/server");
10
11
  const date_fns_1 = require("date-fns");
11
12
  const lodash_es_1 = require("lodash-es");
@@ -120,3 +121,19 @@ async function expireKeyAt(key, expireAt) {
120
121
  throw new Error(`Expire time ${expireAt.toISOString()} is in the past`);
121
122
  }
122
123
  }
124
+ /**
125
+ * Retrieves multiple keys from Redis and returns them as a record/object.
126
+ * @param keys The keys to retrieve.
127
+ * @returns {Record<string, string>} A record/object with keys and their corresponding values.
128
+ */
129
+ async function mGetAsRecord(keys) {
130
+ const results = await server_1.redis.mGet(keys);
131
+ const record = {};
132
+ keys.forEach((key, index) => {
133
+ const value = results[index];
134
+ if (value !== null) {
135
+ record[key] = value;
136
+ }
137
+ });
138
+ return record;
139
+ }
package/eslint.config.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import fsvconfig from "@fsvreddit/eslint-config";
2
-
3
- export default fsvconfig;
1
+ import fsvconfig from "@fsvreddit/eslint-config";
2
+
3
+ export default fsvconfig;
package/package.json CHANGED
@@ -1,46 +1,46 @@
1
- {
2
- "name": "@fsvreddit/fsv-devvit-web-helpers",
3
- "version": "0.2.1",
4
- "description": "Helper functions and utilities for Devvit Web apps on Reddit",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "lint": "eslint . --ext .ts",
8
- "build": "tsc --project tsconfig.build.json",
9
- "prepare": "npm run build"
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "https://github.com/fsvreddit/fsv-devvit-web-helpers.git"
14
- },
15
- "publishConfig": {
16
- "access": "public"
17
- },
18
- "author": "fsv",
19
- "license": "BSD-3-Clause",
20
- "dependencies": {
21
- "date-fns": "^4.1.0",
22
- "hono": "^4.12.30",
23
- "json2md": "^2.0.3",
24
- "lodash-es": "^4.18.1",
25
- "marked": "^18.0.11",
26
- "semver": "^7.8.5"
27
- },
28
- "devDependencies": {
29
- "@fsvreddit/eslint-config": "^0.1.0",
30
- "@types/json2md": "^1.5.4",
31
- "@types/lodash-es": "^4.17.12",
32
- "@types/semver": "^7.7.1",
33
- "eslint": "^10.0.2",
34
- "typescript": "^5.8.3"
35
- },
36
- "keywords": [
37
- "reddit",
38
- "devvit"
39
- ],
40
- "peerDependencies": {
41
- "@devvit/protos": "^0.14.6",
42
- "@devvit/reddit": "^0.14.6",
43
- "@devvit/shared-types": "^0.14.6",
44
- "@devvit/web": "^0.14.6"
45
- }
46
- }
1
+ {
2
+ "name": "@fsvreddit/fsv-devvit-web-helpers",
3
+ "version": "0.2.2",
4
+ "description": "Helper functions and utilities for Devvit Web apps on Reddit",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "lint": "eslint . --ext .ts",
8
+ "build": "tsc --project tsconfig.build.json",
9
+ "prepare": "npm run build"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/fsvreddit/fsv-devvit-web-helpers.git"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "author": "fsv",
19
+ "license": "BSD-3-Clause",
20
+ "dependencies": {
21
+ "date-fns": "^4.1.0",
22
+ "hono": "^4.12.30",
23
+ "json2md": "^2.0.3",
24
+ "lodash-es": "^4.18.1",
25
+ "marked": "^18.0.11",
26
+ "semver": "^7.8.5"
27
+ },
28
+ "devDependencies": {
29
+ "@fsvreddit/eslint-config": "^0.1.0",
30
+ "@types/json2md": "^1.5.4",
31
+ "@types/lodash-es": "^4.17.12",
32
+ "@types/semver": "^7.7.1",
33
+ "eslint": "^10.0.2",
34
+ "typescript": "^5.8.3"
35
+ },
36
+ "keywords": [
37
+ "reddit",
38
+ "devvit"
39
+ ],
40
+ "peerDependencies": {
41
+ "@devvit/protos": "^0.14.6",
42
+ "@devvit/reddit": "^0.14.6",
43
+ "@devvit/shared-types": "^0.14.6",
44
+ "@devvit/web": "^0.14.6"
45
+ }
46
+ }
@@ -1,15 +1,15 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "exclude": [
4
- "vitest.config.ts",
5
- "node_modules",
6
- "tests",
7
- "dist",
8
- "eslint.config.mjs"
9
- ],
10
- "compilerOptions": {
11
- "rootDir": "src",
12
- "outDir": "dist",
13
- "skipLibCheck": true
14
- }
15
- }
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": [
4
+ "vitest.config.ts",
5
+ "node_modules",
6
+ "tests",
7
+ "dist",
8
+ "eslint.config.mjs"
9
+ ],
10
+ "compilerOptions": {
11
+ "rootDir": "src",
12
+ "outDir": "dist",
13
+ "skipLibCheck": true
14
+ }
15
+ }