@emartech/me-idempotency 3.0.20 → 4.0.0
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 +4 -3
- package/dist/index.cjs +51 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +22 -6
- package/dist/index.js.map +1 -1
- package/package.json +27 -32
- package/.env.example +0 -1
- package/.nvmrc +0 -1
- package/CHANGELOG.md +0 -268
- package/dist/src/create-idempotency-fn.d.ts +0 -7
- package/dist/src/create-idempotency-fn.js +0 -23
- package/dist/src/create-idempotency-fn.js.map +0 -1
- package/eslint.config.mjs +0 -17
- package/index.ts +0 -1
- package/src/create-idempotency-fn.spec.ts +0 -60
- package/src/create-idempotency-fn.ts +0 -20
- package/tsconfig.build.json +0 -5
- package/tsconfig.json +0 -9
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# @emartech/me-idempotency
|
|
2
2
|
|
|
3
|
-
|
|
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":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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,"
|
|
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": "
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "Idempotency library using Redis as a backend.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
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
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
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
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"test": "
|
|
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
|
-
"@
|
|
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": "^
|
|
37
|
+
"chai": "^5.1.2",
|
|
39
38
|
"chai-string": "1.5.0",
|
|
40
39
|
"chai-subset": "1.6.0",
|
|
41
40
|
"dotenv": "^16.4.5",
|
|
42
|
-
"eslint": "^9.8.0",
|
|
43
41
|
"mocha": "^10.7.0",
|
|
44
|
-
"sinon": "
|
|
45
|
-
"sinon-chai": "^
|
|
46
|
-
"ts-node": "10.9.2",
|
|
47
|
-
"typescript": "5.7.2",
|
|
48
|
-
"typescript-eslint": "^8.0.0"
|
|
42
|
+
"sinon": "^19.0.2",
|
|
43
|
+
"sinon-chai": "^4.0.0"
|
|
49
44
|
},
|
|
50
45
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
46
|
+
"node": ">=20"
|
|
52
47
|
},
|
|
53
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "4c6211e56dde7136e800806e55fd60f798fccdb9"
|
|
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,268 +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.20](https://github.com/emartech/me-modules/compare/@emartech/me-idempotency@3.0.19...@emartech/me-idempotency@3.0.20) (2024-11-25)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## [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)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## [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)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## [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)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
## [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)
|
|
39
|
-
|
|
40
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
## [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)
|
|
47
|
-
|
|
48
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
## [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)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
### Bug Fixes
|
|
58
|
-
|
|
59
|
-
* linting ([4379d7c](https://github.com/emartech/me-modules/commit/4379d7cc40ce91753b766a4a50e4a74d130bd0ca))
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
## [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)
|
|
66
|
-
|
|
67
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
## [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)
|
|
74
|
-
|
|
75
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
## [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)
|
|
82
|
-
|
|
83
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
## [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)
|
|
90
|
-
|
|
91
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
## [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)
|
|
98
|
-
|
|
99
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
## 3.0.8 (2023-11-22)
|
|
106
|
-
|
|
107
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
## 3.0.7 (2023-11-21)
|
|
114
|
-
|
|
115
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
## [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)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
### Bug Fixes
|
|
125
|
-
|
|
126
|
-
* typescript to 5.2 version ([2df7ee7](https://github.com/emartech/me-idempotency-js/commit/2df7ee7c4100bea4a50db872981cebcf9b642148))
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
### Reverts
|
|
130
|
-
|
|
131
|
-
* Revert "Publish" ([e042768](https://github.com/emartech/me-idempotency-js/commit/e042768f1c906ddac1d50de1baef5ba830c12c21))
|
|
132
|
-
* Revert "Publish" ([a52603a](https://github.com/emartech/me-idempotency-js/commit/a52603a4613cf5706e75b23fbf1fb65a4ff415ba))
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
## 3.0.5 (2023-11-21)
|
|
139
|
-
|
|
140
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
## [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)
|
|
147
|
-
|
|
148
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
## [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)
|
|
155
|
-
|
|
156
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
## [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)
|
|
163
|
-
|
|
164
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
## [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)
|
|
171
|
-
|
|
172
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
# 3.0.0 (2023-10-27)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
* feat!(idempotency): upgrade to redis v4 ([0cd9ba1](https://github.com/emartech/me-idempotency-js/commit/0cd9ba17722ca3881b2e8fe0a1be9c057f13b342))
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
### BREAKING CHANGES
|
|
185
|
-
|
|
186
|
-
* Upgraded to Redis client v4.
|
|
187
|
-
|
|
188
|
-
SUITEDEV-34567
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
## [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)
|
|
195
|
-
|
|
196
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
## 2.0.4 (2023-10-11)
|
|
203
|
-
|
|
204
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
## 2.0.3 (2023-08-16)
|
|
211
|
-
|
|
212
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
## 2.0.2 (2021-06-11)
|
|
219
|
-
|
|
220
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
## [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)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
### Bug Fixes
|
|
230
|
-
|
|
231
|
-
* add build task to idempotency ([a75dd58](https://github.com/emartech/me-idempotency-js/commit/a75dd582ef3947f83b7928c6928b562810bf5809))
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
# [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)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
* feat!: Simplify Idempotency ([174fd0a](https://github.com/emartech/me-idempotency-js/commit/174fd0a302073f22343557a164ca34969193f2bb))
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
### BREAKING CHANGES
|
|
244
|
-
|
|
245
|
-
* Api changed. Now idempotency is not throwing anymore.
|
|
246
|
-
|
|
247
|
-
Relates SUITEDEV-21305
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
## [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)
|
|
254
|
-
|
|
255
|
-
**Note:** Version bump only for package @emartech/me-idempotency
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
# 1.3.0 (2020-03-06)
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
### Features
|
|
265
|
-
|
|
266
|
-
* **idempotency:** Add idempotency ([b8290d1](https://github.com/emartech/me-idempotency-js/commit/b8290d1763f112f2fa950efc4cdda64a53ed151a))
|
|
267
|
-
* **idempotency:** Update idempotency key creation ([e9109f8](https://github.com/emartech/me-idempotency-js/commit/e9109f89a90708fa187fca073f6fce0981bb5384))
|
|
268
|
-
* 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
|
-
}
|
package/tsconfig.build.json
DELETED