@emartech/me-idempotency 3.0.21 → 4.0.1

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/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # @emartech/me-idempotency
2
2
 
3
- Small library for idempotency
3
+ Idempotency library using Redis as a backend.
4
+
4
5
  ## Install
5
6
 
6
7
  ```shell script
@@ -13,8 +14,8 @@ npm install --save @emartech/me-idempotency
13
14
  const { createClient } = require('redis')
14
15
  const { createRedisIdempotency, defaultIdempotencyKeyGenerator } = require('@emartech/me-idempotency')
15
16
 
16
- const Idempotency = createRedisIdempotency(createClient())
17
- const key = defaultIdempotencyKeyGenerator(customerId, runId, pushToken)
17
+ const Idempotency = createRedisIdempotency(createClient())
18
+ const key = defaultIdempotencyKeyGenerator(customerId, runId, pushToken)
18
19
  const result = Idempotency.set(key)
19
20
  if (result) console.log('Idemp ok')
20
21
  ```
package/dist/index.cjs ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ createRedisIdempotency: () => createRedisIdempotency,
24
+ defaultIdempotencyKeyGenerator: () => defaultIdempotencyKeyGenerator
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/create-idempotency-fn.ts
29
+ var defaultIdempotencyKeyGenerator = (...args) => {
30
+ const prefix = "idempotency";
31
+ return [prefix].concat(args.map((arg) => `${arg}`)).join(":");
32
+ };
33
+ var createRedisIdempotency = (client, ttlInSec = 60 * 60 * 6) => {
34
+ return {
35
+ del: async (key) => client.del(key),
36
+ set: async (key) => {
37
+ const result = await client.set(key, "1", { EX: ttlInSec, NX: true });
38
+ return result === "OK";
39
+ },
40
+ get: async (key) => {
41
+ const result = await client.get(key);
42
+ return result !== null;
43
+ }
44
+ };
45
+ };
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ createRedisIdempotency,
49
+ defaultIdempotencyKeyGenerator
50
+ });
51
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/create-idempotency-fn.ts"],"sourcesContent":["export { createRedisIdempotency, defaultIdempotencyKeyGenerator } from './create-idempotency-fn'\n","import { RedisClientType } from 'redis'\n\nexport const defaultIdempotencyKeyGenerator = (...args: unknown[]) => {\n const prefix = 'idempotency'\n return [prefix].concat(args.map(arg => `${arg}`)).join(':')\n}\n\nexport const createRedisIdempotency = (client: RedisClientType, ttlInSec: number = 60 * 60 * 6) => {\n return {\n del: async (key: string) => client.del(key),\n set: async (key: string) => {\n const result = await client.set(key, '1', { EX: ttlInSec, NX: true })\n return result === 'OK'\n },\n get: async (key: string) => {\n const result = await client.get(key)\n return result !== null\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,iCAAiC,IAAI,SAAoB;AACpE,QAAM,SAAS;AACf,SAAO,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,SAAO,GAAG,GAAG,EAAE,CAAC,EAAE,KAAK,GAAG;AAC5D;AAEO,IAAM,yBAAyB,CAAC,QAAyB,WAAmB,KAAK,KAAK,MAAM;AACjG,SAAO;AAAA,IACL,KAAK,OAAO,QAAgB,OAAO,IAAI,GAAG;AAAA,IAC1C,KAAK,OAAO,QAAgB;AAC1B,YAAM,SAAS,MAAM,OAAO,IAAI,KAAK,KAAK,EAAE,IAAI,UAAU,IAAI,KAAK,CAAC;AACpE,aAAO,WAAW;AAAA,IACpB;AAAA,IACA,KAAK,OAAO,QAAgB;AAC1B,YAAM,SAAS,MAAM,OAAO,IAAI,GAAG;AACnC,aAAO,WAAW;AAAA,IACpB;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,10 @@
1
+ import { RedisClientType } from 'redis';
2
+
3
+ declare const defaultIdempotencyKeyGenerator: (...args: unknown[]) => string;
4
+ declare const createRedisIdempotency: (client: RedisClientType, ttlInSec?: number) => {
5
+ del: (key: string) => Promise<number>;
6
+ set: (key: string) => Promise<boolean>;
7
+ get: (key: string) => Promise<boolean>;
8
+ };
9
+
10
+ export { createRedisIdempotency, defaultIdempotencyKeyGenerator };
package/dist/index.d.ts CHANGED
@@ -1 +1,10 @@
1
- export { createRedisIdempotency, defaultIdempotencyKeyGenerator } from './src/create-idempotency-fn';
1
+ import { RedisClientType } from 'redis';
2
+
3
+ declare const defaultIdempotencyKeyGenerator: (...args: unknown[]) => string;
4
+ declare const createRedisIdempotency: (client: RedisClientType, ttlInSec?: number) => {
5
+ del: (key: string) => Promise<number>;
6
+ set: (key: string) => Promise<boolean>;
7
+ get: (key: string) => Promise<boolean>;
8
+ };
9
+
10
+ export { createRedisIdempotency, defaultIdempotencyKeyGenerator };
package/dist/index.js CHANGED
@@ -1,7 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultIdempotencyKeyGenerator = exports.createRedisIdempotency = void 0;
4
- var create_idempotency_fn_1 = require("./src/create-idempotency-fn");
5
- Object.defineProperty(exports, "createRedisIdempotency", { enumerable: true, get: function () { return create_idempotency_fn_1.createRedisIdempotency; } });
6
- Object.defineProperty(exports, "defaultIdempotencyKeyGenerator", { enumerable: true, get: function () { return create_idempotency_fn_1.defaultIdempotencyKeyGenerator; } });
1
+ // src/create-idempotency-fn.ts
2
+ var defaultIdempotencyKeyGenerator = (...args) => {
3
+ const prefix = "idempotency";
4
+ return [prefix].concat(args.map((arg) => `${arg}`)).join(":");
5
+ };
6
+ var createRedisIdempotency = (client, ttlInSec = 60 * 60 * 6) => {
7
+ return {
8
+ del: async (key) => client.del(key),
9
+ set: async (key) => {
10
+ const result = await client.set(key, "1", { EX: ttlInSec, NX: true });
11
+ return result === "OK";
12
+ },
13
+ get: async (key) => {
14
+ const result = await client.get(key);
15
+ return result !== null;
16
+ }
17
+ };
18
+ };
19
+ export {
20
+ createRedisIdempotency,
21
+ defaultIdempotencyKeyGenerator
22
+ };
7
23
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,qEAAoG;AAA3F,+HAAA,sBAAsB,OAAA;AAAE,uIAAA,8BAA8B,OAAA"}
1
+ {"version":3,"sources":["../src/create-idempotency-fn.ts"],"sourcesContent":["import { RedisClientType } from 'redis'\n\nexport const defaultIdempotencyKeyGenerator = (...args: unknown[]) => {\n const prefix = 'idempotency'\n return [prefix].concat(args.map(arg => `${arg}`)).join(':')\n}\n\nexport const createRedisIdempotency = (client: RedisClientType, ttlInSec: number = 60 * 60 * 6) => {\n return {\n del: async (key: string) => client.del(key),\n set: async (key: string) => {\n const result = await client.set(key, '1', { EX: ttlInSec, NX: true })\n return result === 'OK'\n },\n get: async (key: string) => {\n const result = await client.get(key)\n return result !== null\n },\n }\n}\n"],"mappings":";AAEO,IAAM,iCAAiC,IAAI,SAAoB;AACpE,QAAM,SAAS;AACf,SAAO,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,SAAO,GAAG,GAAG,EAAE,CAAC,EAAE,KAAK,GAAG;AAC5D;AAEO,IAAM,yBAAyB,CAAC,QAAyB,WAAmB,KAAK,KAAK,MAAM;AACjG,SAAO;AAAA,IACL,KAAK,OAAO,QAAgB,OAAO,IAAI,GAAG;AAAA,IAC1C,KAAK,OAAO,QAAgB;AAC1B,YAAM,SAAS,MAAM,OAAO,IAAI,KAAK,KAAK,EAAE,IAAI,UAAU,IAAI,KAAK,CAAC;AACpE,aAAO,WAAW;AAAA,IACpB;AAAA,IACA,KAAK,OAAO,QAAgB;AAC1B,YAAM,SAAS,MAAM,OAAO,IAAI,GAAG;AACnC,aAAO,WAAW;AAAA,IACpB;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,54 +1,49 @@
1
1
  {
2
2
  "name": "@emartech/me-idempotency",
3
- "version": "3.0.21",
4
- "description": "",
3
+ "version": "4.0.1",
4
+ "description": "Idempotency library using Redis as a backend.",
5
5
  "license": "UNLICENSED",
6
- "homepage": "https://github.com/emartech/me-modules/tree/master/modules/me-idempotency",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/emartech/me-modules.git",
10
- "directory": "modules/me-idempotency"
6
+ "repository": "github:emartech/me-modules",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "require": "./dist/index.cjs",
11
+ "import": "./dist/index.js"
12
+ }
11
13
  },
12
- "bugs": {
13
- "url": "https://github.com/emartech/me-modules/issues"
14
- },
15
- "main": "dist/index.js",
16
- "types": "dist/index.d.ts",
14
+ "main": "./dist/index.cjs",
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "files": [
18
+ "dist"
19
+ ],
17
20
  "scripts": {
18
21
  "clean": "rm -rf dist",
19
- "prebuild": "npm run clean",
20
- "build": "tsc --project tsconfig.build.json",
21
- "build-docs": "rm -rf docs && typedoc --out docs --target es2018 --theme markdown --exclude 'test/**'",
22
- "lint": "eslint .",
23
- "format": "eslint . --fix",
24
- "test": "NODE_ENV=test mocha -r dotenv/config -r ts-node/register '**/*.spec.ts'",
22
+ "build": "tsup src/index.ts --format cjs,esm --sourcemap --dts --clean",
23
+ "lint": "eslint src/",
24
+ "format": "eslint src/ --fix",
25
+ "typecheck": "tsc --noEmit",
26
+ "spec": "NODE_ENV=test mocha",
27
+ "test": "npm run lint && npm run typecheck && npm run spec",
25
28
  "prepublishOnly": "npm run build"
26
29
  },
27
30
  "dependencies": {
28
31
  "redis": "^4.7.0"
29
32
  },
30
33
  "devDependencies": {
31
- "@eslint/js": "^9.8.0",
32
- "@tsconfig/node18": "^18.2.4",
33
- "@types/chai": "^4.3.17",
34
- "@types/eslint__js": "^8.42.3",
34
+ "@types/chai": "^5.0.1",
35
35
  "@types/mocha": "^10.0.7",
36
- "@types/node": "^18.19.43",
37
36
  "@types/sinon": "^17.0.3",
38
- "chai": "^4.3.10",
37
+ "chai": "^5.1.2",
39
38
  "chai-string": "1.5.0",
40
39
  "chai-subset": "1.6.0",
41
- "dotenv": "^16.4.5",
42
- "eslint": "^9.8.0",
43
- "mocha": "^10.7.0",
44
- "sinon": "18.0.1",
45
- "sinon-chai": "^3.7.0",
46
- "ts-node": "10.9.2",
47
- "typescript": "5.7.2",
48
- "typescript-eslint": "^8.0.0"
40
+ "dotenv": "^16.4.7",
41
+ "mocha": "^11.0.1",
42
+ "sinon": "^19.0.2",
43
+ "sinon-chai": "^4.0.0"
49
44
  },
50
45
  "engines": {
51
- "node": ">=18"
46
+ "node": ">=20"
52
47
  },
53
- "gitHead": "f11edaa23e73d44b9da2afa2d21c7b6895140b95"
48
+ "gitHead": "247e4fa9993a1a87f5bcd10b589fbd826b7a922b"
54
49
  }
package/.env.example DELETED
@@ -1 +0,0 @@
1
- REDIS_URL=redis://127.0.0.1:6379
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- 18
package/CHANGELOG.md DELETED
@@ -1,276 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [3.0.21](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.20...@emartech/me-idempotency@3.0.21) (2024-11-26)
7
-
8
- **Note:** Version bump only for package @emartech/me-idempotency
9
-
10
-
11
-
12
-
13
-
14
- ## [3.0.20](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.19...@emartech/me-idempotency@3.0.20) (2024-11-25)
15
-
16
- **Note:** Version bump only for package @emartech/me-idempotency
17
-
18
-
19
-
20
-
21
-
22
- ## [3.0.19](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.18...@emartech/me-idempotency@3.0.19) (2024-11-05)
23
-
24
- **Note:** Version bump only for package @emartech/me-idempotency
25
-
26
-
27
-
28
-
29
-
30
- ## [3.0.18](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.17...@emartech/me-idempotency@3.0.18) (2024-08-04)
31
-
32
- **Note:** Version bump only for package @emartech/me-idempotency
33
-
34
-
35
-
36
-
37
-
38
- ## [3.0.17](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.16...@emartech/me-idempotency@3.0.17) (2024-04-09)
39
-
40
- **Note:** Version bump only for package @emartech/me-idempotency
41
-
42
-
43
-
44
-
45
-
46
- ## [3.0.16](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.15...@emartech/me-idempotency@3.0.16) (2024-03-25)
47
-
48
- **Note:** Version bump only for package @emartech/me-idempotency
49
-
50
-
51
-
52
-
53
-
54
- ## [3.0.15](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.14...@emartech/me-idempotency@3.0.15) (2024-02-20)
55
-
56
- **Note:** Version bump only for package @emartech/me-idempotency
57
-
58
-
59
-
60
-
61
-
62
- ## [3.0.14](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.13...@emartech/me-idempotency@3.0.14) (2024-02-20)
63
-
64
-
65
- ### Bug Fixes
66
-
67
- * linting ([4379d7c](https://github.com/emartech/me-modules/commit/4379d7cc40ce91753b766a4a50e4a74d130bd0ca))
68
-
69
-
70
-
71
-
72
-
73
- ## [3.0.13](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.12...@emartech/me-idempotency@3.0.13) (2024-02-09)
74
-
75
- **Note:** Version bump only for package @emartech/me-idempotency
76
-
77
-
78
-
79
-
80
-
81
- ## [3.0.12](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.11...@emartech/me-idempotency@3.0.12) (2024-01-24)
82
-
83
- **Note:** Version bump only for package @emartech/me-idempotency
84
-
85
-
86
-
87
-
88
-
89
- ## [3.0.11](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.10...@emartech/me-idempotency@3.0.11) (2024-01-11)
90
-
91
- **Note:** Version bump only for package @emartech/me-idempotency
92
-
93
-
94
-
95
-
96
-
97
- ## [3.0.10](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.9...@emartech/me-idempotency@3.0.10) (2023-12-08)
98
-
99
- **Note:** Version bump only for package @emartech/me-idempotency
100
-
101
-
102
-
103
-
104
-
105
- ## [3.0.9](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.8...@emartech/me-idempotency@3.0.9) (2023-11-24)
106
-
107
- **Note:** Version bump only for package @emartech/me-idempotency
108
-
109
-
110
-
111
-
112
-
113
- ## 3.0.8 (2023-11-22)
114
-
115
- **Note:** Version bump only for package @emartech/me-idempotency
116
-
117
-
118
-
119
-
120
-
121
- ## 3.0.7 (2023-11-21)
122
-
123
- **Note:** Version bump only for package @emartech/me-idempotency
124
-
125
-
126
-
127
-
128
-
129
- ## [3.0.6](https://github.com/emartech/me-idempotency-js/compare/@emartech/me-idempotency@3.0.4...@emartech/me-idempotency@3.0.6) (2023-11-21)
130
-
131
-
132
- ### Bug Fixes
133
-
134
- * typescript to 5.2 version ([2df7ee7](https://github.com/emartech/me-idempotency-js/commit/2df7ee7c4100bea4a50db872981cebcf9b642148))
135
-
136
-
137
- ### Reverts
138
-
139
- * Revert "Publish" ([e042768](https://github.com/emartech/me-idempotency-js/commit/e042768f1c906ddac1d50de1baef5ba830c12c21))
140
- * Revert "Publish" ([a52603a](https://github.com/emartech/me-idempotency-js/commit/a52603a4613cf5706e75b23fbf1fb65a4ff415ba))
141
-
142
-
143
-
144
-
145
-
146
- ## 3.0.5 (2023-11-21)
147
-
148
- **Note:** Version bump only for package @emartech/me-idempotency
149
-
150
-
151
-
152
-
153
-
154
- ## [3.0.4](https://github.com/emartech/me-idempotency-js/compare/@emartech/me-idempotency@3.0.3...@emartech/me-idempotency@3.0.4) (2023-11-20)
155
-
156
- **Note:** Version bump only for package @emartech/me-idempotency
157
-
158
-
159
-
160
-
161
-
162
- ## [3.0.3](https://github.com/emartech/me-idempotency-js/compare/@emartech/me-idempotency@3.0.2...@emartech/me-idempotency@3.0.3) (2023-11-06)
163
-
164
- **Note:** Version bump only for package @emartech/me-idempotency
165
-
166
-
167
-
168
-
169
-
170
- ## [3.0.2](https://github.com/emartech/me-idempotency-js/compare/@emartech/me-idempotency@3.0.1...@emartech/me-idempotency@3.0.2) (2023-10-31)
171
-
172
- **Note:** Version bump only for package @emartech/me-idempotency
173
-
174
-
175
-
176
-
177
-
178
- ## [3.0.1](https://github.com/emartech/me-idempotency-js/compare/@emartech/me-idempotency@3.0.0...@emartech/me-idempotency@3.0.1) (2023-10-28)
179
-
180
- **Note:** Version bump only for package @emartech/me-idempotency
181
-
182
-
183
-
184
-
185
-
186
- # 3.0.0 (2023-10-27)
187
-
188
-
189
- * feat!(idempotency): upgrade to redis v4 ([0cd9ba1](https://github.com/emartech/me-idempotency-js/commit/0cd9ba17722ca3881b2e8fe0a1be9c057f13b342))
190
-
191
-
192
- ### BREAKING CHANGES
193
-
194
- * Upgraded to Redis client v4.
195
-
196
- SUITEDEV-34567
197
-
198
-
199
-
200
-
201
-
202
- ## [2.0.5](https://github.com/emartech/me-idempotency-js/compare/@emartech/me-idempotency@2.0.4...@emartech/me-idempotency@2.0.5) (2023-10-17)
203
-
204
- **Note:** Version bump only for package @emartech/me-idempotency
205
-
206
-
207
-
208
-
209
-
210
- ## 2.0.4 (2023-10-11)
211
-
212
- **Note:** Version bump only for package @emartech/me-idempotency
213
-
214
-
215
-
216
-
217
-
218
- ## 2.0.3 (2023-08-16)
219
-
220
- **Note:** Version bump only for package @emartech/me-idempotency
221
-
222
-
223
-
224
-
225
-
226
- ## 2.0.2 (2021-06-11)
227
-
228
- **Note:** Version bump only for package @emartech/me-idempotency
229
-
230
-
231
-
232
-
233
-
234
- ## [2.0.1](https://github.com/emartech/me-idempotency-js/compare/@emartech/me-idempotency@2.0.0...@emartech/me-idempotency@2.0.1) (2020-04-25)
235
-
236
-
237
- ### Bug Fixes
238
-
239
- * add build task to idempotency ([a75dd58](https://github.com/emartech/me-idempotency-js/commit/a75dd582ef3947f83b7928c6928b562810bf5809))
240
-
241
-
242
-
243
-
244
-
245
- # [2.0.0](https://github.com/emartech/me-idempotency-js/compare/@emartech/me-idempotency@1.3.1...@emartech/me-idempotency@2.0.0) (2020-03-17)
246
-
247
-
248
- * feat!: Simplify Idempotency ([174fd0a](https://github.com/emartech/me-idempotency-js/commit/174fd0a302073f22343557a164ca34969193f2bb))
249
-
250
-
251
- ### BREAKING CHANGES
252
-
253
- * Api changed. Now idempotency is not throwing anymore.
254
-
255
- Relates SUITEDEV-21305
256
-
257
-
258
-
259
-
260
-
261
- ## [1.3.1](https://github.com/emartech/me-idempotency-js/compare/@emartech/me-idempotency@1.3.0...@emartech/me-idempotency@1.3.1) (2020-03-10)
262
-
263
- **Note:** Version bump only for package @emartech/me-idempotency
264
-
265
-
266
-
267
-
268
-
269
- # 1.3.0 (2020-03-06)
270
-
271
-
272
- ### Features
273
-
274
- * **idempotency:** Add idempotency ([b8290d1](https://github.com/emartech/me-idempotency-js/commit/b8290d1763f112f2fa950efc4cdda64a53ed151a))
275
- * **idempotency:** Update idempotency key creation ([e9109f8](https://github.com/emartech/me-idempotency-js/commit/e9109f89a90708fa187fca073f6fce0981bb5384))
276
- * move me-idempotency ([355e9e5](https://github.com/emartech/me-idempotency-js/commit/355e9e52a72fda77d189fe07492cf7a5ebdf650a))
@@ -1,7 +0,0 @@
1
- import { RedisClientType } from 'redis';
2
- export declare const defaultIdempotencyKeyGenerator: (...args: unknown[]) => string;
3
- export declare const createRedisIdempotency: (client: RedisClientType, ttlInSec?: number) => {
4
- del: (key: string) => Promise<number>;
5
- set: (key: string) => Promise<boolean>;
6
- get: (key: string) => Promise<boolean>;
7
- };
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRedisIdempotency = exports.defaultIdempotencyKeyGenerator = void 0;
4
- const defaultIdempotencyKeyGenerator = (...args) => {
5
- const prefix = 'idempotency';
6
- return [prefix].concat(args.map((arg) => `${arg}`)).join(':');
7
- };
8
- exports.defaultIdempotencyKeyGenerator = defaultIdempotencyKeyGenerator;
9
- const createRedisIdempotency = (client, ttlInSec = 60 * 60 * 6) => {
10
- return {
11
- del: async (key) => client.del(key),
12
- set: async (key) => {
13
- const result = await client.set(key, '1', { EX: ttlInSec, NX: true });
14
- return result === 'OK';
15
- },
16
- get: async (key) => {
17
- const result = await client.get(key);
18
- return result !== null;
19
- },
20
- };
21
- };
22
- exports.createRedisIdempotency = createRedisIdempotency;
23
- //# sourceMappingURL=create-idempotency-fn.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-idempotency-fn.js","sourceRoot":"","sources":["../../src/create-idempotency-fn.ts"],"names":[],"mappings":";;;AAEO,MAAM,8BAA8B,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE;IACnE,MAAM,MAAM,GAAG,aAAa,CAAA;IAC5B,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC/D,CAAC,CAAA;AAHY,QAAA,8BAA8B,kCAG1C;AAEM,MAAM,sBAAsB,GAAG,CAAC,MAAuB,EAAE,WAAmB,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE;IAChG,OAAO;QACL,GAAG,EAAE,KAAK,EAAE,GAAW,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;QAC3C,GAAG,EAAE,KAAK,EAAE,GAAW,EAAE,EAAE;YACzB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;YACrE,OAAO,MAAM,KAAK,IAAI,CAAA;QACxB,CAAC;QACD,GAAG,EAAE,KAAK,EAAE,GAAW,EAAE,EAAE;YACzB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACpC,OAAO,MAAM,KAAK,IAAI,CAAA;QACxB,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AAZY,QAAA,sBAAsB,0BAYlC"}
package/eslint.config.mjs DELETED
@@ -1,17 +0,0 @@
1
- // @ts-check
2
-
3
- import eslint from '@eslint/js';
4
- import tseslint from 'typescript-eslint';
5
-
6
- export default tseslint.config({
7
- files: ['**/*.ts'],
8
- extends: [
9
- eslint.configs.recommended,
10
- ...tseslint.configs.recommended,
11
- ]
12
- }, {
13
- files: ["**/*.spec.ts"],
14
- rules: {
15
- "@typescript-eslint/no-unused-expressions": "off"
16
- }
17
- })
package/index.ts DELETED
@@ -1 +0,0 @@
1
- export { createRedisIdempotency, defaultIdempotencyKeyGenerator } from './src/create-idempotency-fn'
@@ -1,60 +0,0 @@
1
- import { expect } from 'chai'
2
- import 'mocha'
3
- import { createClient, RedisClientType } from 'redis'
4
- import { createRedisIdempotency, defaultIdempotencyKeyGenerator } from './create-idempotency-fn'
5
-
6
- describe('me-idempotency', () => {
7
- describe('defaultIdempotencyKeyGenerator', () => {
8
- it('should generate a string key', () => {
9
- const key = defaultIdempotencyKeyGenerator(1, 'str', true)
10
- expect(key).to.eql('idempotency:1:str:true')
11
- })
12
- })
13
-
14
- describe('createRedisIdempotency', () => {
15
- const key = `testIdemp-${new Date().toISOString()}`
16
-
17
- let redisClient: RedisClientType
18
- let idemp: ReturnType<typeof createRedisIdempotency>
19
-
20
- before(async () => {
21
- redisClient = createClient({ url: process.env.REDIS_URL! })
22
- await redisClient.connect()
23
- idemp = createRedisIdempotency(redisClient)
24
- })
25
-
26
- afterEach(() => idemp.del(key))
27
-
28
- after(() => redisClient.quit())
29
-
30
- it('should set a new key and return true', async () => {
31
- const result = await idemp.set(key)
32
- expect(result).to.eql(true)
33
- })
34
-
35
- it('should return false setting the key twice', async () => {
36
- await idemp.set(key)
37
- const result = await idemp.set(key)
38
- expect(result).to.eql(false)
39
- })
40
-
41
- it('should delete the key and return the number of deleted key', async () => {
42
- await idemp.set(key)
43
- const result = await idemp.del(key)
44
- const resultSecondDeletion = await idemp.del(key)
45
- expect(result).to.eql(1)
46
- expect(resultSecondDeletion).to.eql(0)
47
- })
48
-
49
- it('should return true when getting existing key', async () => {
50
- await idemp.set(key)
51
- const result = await idemp.get(key)
52
- expect(result).to.eql(true)
53
- })
54
-
55
- it('should return false when getting non-existing key', async () => {
56
- const result = await idemp.get('i-do-not-exist')
57
- expect(result).to.eql(false)
58
- })
59
- })
60
- })
@@ -1,20 +0,0 @@
1
- import { RedisClientType } from 'redis'
2
-
3
- export const defaultIdempotencyKeyGenerator = (...args: unknown[]) => {
4
- const prefix = 'idempotency'
5
- return [prefix].concat(args.map((arg) => `${arg}`)).join(':')
6
- }
7
-
8
- export const createRedisIdempotency = (client: RedisClientType, ttlInSec: number = 60 * 60 * 6) => {
9
- return {
10
- del: async (key: string) => client.del(key),
11
- set: async (key: string) => {
12
- const result = await client.set(key, '1', { EX: ttlInSec, NX: true })
13
- return result === 'OK'
14
- },
15
- get: async (key: string) => {
16
- const result = await client.get(key)
17
- return result !== null
18
- },
19
- }
20
- }
@@ -1,5 +0,0 @@
1
-
2
- {
3
- "extends": "./tsconfig.json",
4
- "exclude": ["src/**/*.spec.ts"]
5
- }
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "@tsconfig/node18/tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "./",
5
- "outDir": "./dist",
6
- "declaration": true,
7
- "sourceMap": true
8
- }
9
- }