@universal-lock/types 1.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/LICENSE +21 -0
- package/README.md +80 -0
- package/dist/index.d.mts +59 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.global.js +21 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Lucas Rainett
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @universal-lock/types
|
|
2
|
+
|
|
3
|
+
Shared TypeScript type definitions for the [`universal-lock`](https://github.com/lucasrainett/universal-lock) ecosystem.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @universal-lock/types
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
> **Note:** You typically don't need to install this package directly. It is included as a dependency of `universal-lock` and all backend packages.
|
|
12
|
+
|
|
13
|
+
## Types
|
|
14
|
+
|
|
15
|
+
### Backend
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
type BackendSetupFunction = () => Promise<void>;
|
|
19
|
+
type BackendAcquireFunction = (lockName: string, stale: number, lockId: string) => Promise<void>;
|
|
20
|
+
type BackendRenewFunction = (lockName: string, lockId: string) => Promise<void>;
|
|
21
|
+
type BackendReleaseFunction = (lockName: string, lockId: string) => Promise<void>;
|
|
22
|
+
|
|
23
|
+
type Backend = {
|
|
24
|
+
setup: BackendSetupFunction;
|
|
25
|
+
acquire: BackendAcquireFunction;
|
|
26
|
+
renew: BackendRenewFunction;
|
|
27
|
+
release: BackendReleaseFunction;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type BackendFactory = (...args: any[]) => Backend;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Utility
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
type AsyncFunction<R = unknown, P extends unknown[] = unknown[]> = (...args: P) => Promise<R>;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Lock
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
type Lock = { acquire: LockAcquireFunction };
|
|
43
|
+
|
|
44
|
+
type LockAcquireFunction = (lockName: string) => Promise<LockReleaseFunction>;
|
|
45
|
+
|
|
46
|
+
type LockReleaseFunction = (() => Promise<void>) & { signal: AbortSignal };
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Configuration
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
type LockConfiguration = {
|
|
53
|
+
acquireInterval: number;
|
|
54
|
+
acquireFailTimeout: number;
|
|
55
|
+
stale: number;
|
|
56
|
+
renewInterval: number;
|
|
57
|
+
maxHoldTime: number;
|
|
58
|
+
onLockLost: (lockName: string, reason: "renewFailed" | "timeout") => void;
|
|
59
|
+
onEvent: (event: LockEvent) => void;
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Events
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
type LockEvent = { type: "acquired"; lockName: string } | { type: "released"; lockName: string } | { type: "renewed"; lockName: string } | { type: "renewFailed"; lockName: string; error: unknown } | { type: "lockLost"; lockName: string; reason: "renewFailed" | "timeout" } | { type: "acquireTimeout"; lockName: string };
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Lock Entry Types
|
|
70
|
+
|
|
71
|
+
Used by backend implementations:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
type TimestampLockEntry = { lockId: string; timestamp: number };
|
|
75
|
+
type CallbackLockEntry = { lockId: string; release: () => void };
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
[MIT](https://github.com/lucasrainett/universal-lock/blob/master/LICENSE)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
type AsyncFunction<R = unknown, P extends unknown[] = unknown[]> = (...args: P) => Promise<R>;
|
|
2
|
+
type BackendSetupFunction = () => Promise<void>;
|
|
3
|
+
type BackendAcquireFunction = (lockName: string, stale: number, lockId: string) => Promise<void>;
|
|
4
|
+
type BackendRenewFunction = (lockName: string, lockId: string) => Promise<void>;
|
|
5
|
+
type BackendReleaseFunction = (lockName: string, lockId: string) => Promise<void>;
|
|
6
|
+
type Backend = {
|
|
7
|
+
setup: BackendSetupFunction;
|
|
8
|
+
acquire: BackendAcquireFunction;
|
|
9
|
+
renew: BackendRenewFunction;
|
|
10
|
+
release: BackendReleaseFunction;
|
|
11
|
+
};
|
|
12
|
+
type BackendFactory = (...args: any[]) => Backend;
|
|
13
|
+
type LockEvent = {
|
|
14
|
+
type: "acquired";
|
|
15
|
+
lockName: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: "released";
|
|
18
|
+
lockName: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: "renewed";
|
|
21
|
+
lockName: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: "renewFailed";
|
|
24
|
+
lockName: string;
|
|
25
|
+
error: unknown;
|
|
26
|
+
} | {
|
|
27
|
+
type: "lockLost";
|
|
28
|
+
lockName: string;
|
|
29
|
+
reason: "renewFailed" | "timeout";
|
|
30
|
+
} | {
|
|
31
|
+
type: "acquireTimeout";
|
|
32
|
+
lockName: string;
|
|
33
|
+
};
|
|
34
|
+
type LockConfiguration = {
|
|
35
|
+
acquireInterval: number;
|
|
36
|
+
acquireFailTimeout: number;
|
|
37
|
+
stale: number;
|
|
38
|
+
renewInterval: number;
|
|
39
|
+
maxHoldTime: number;
|
|
40
|
+
onLockLost: (lockName: string, reason: "renewFailed" | "timeout") => void;
|
|
41
|
+
onEvent: (event: LockEvent) => void;
|
|
42
|
+
};
|
|
43
|
+
type LockReleaseFunction = (() => Promise<void>) & {
|
|
44
|
+
signal: AbortSignal;
|
|
45
|
+
};
|
|
46
|
+
type LockAcquireFunction = (lockName: string) => Promise<LockReleaseFunction>;
|
|
47
|
+
type Lock = {
|
|
48
|
+
acquire: LockAcquireFunction;
|
|
49
|
+
};
|
|
50
|
+
type TimestampLockEntry = {
|
|
51
|
+
lockId: string;
|
|
52
|
+
timestamp: number;
|
|
53
|
+
};
|
|
54
|
+
type CallbackLockEntry = {
|
|
55
|
+
lockId: string;
|
|
56
|
+
release: () => void;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type { AsyncFunction, Backend, BackendAcquireFunction, BackendFactory, BackendReleaseFunction, BackendRenewFunction, BackendSetupFunction, CallbackLockEntry, Lock, LockAcquireFunction, LockConfiguration, LockEvent, LockReleaseFunction, TimestampLockEntry };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
type AsyncFunction<R = unknown, P extends unknown[] = unknown[]> = (...args: P) => Promise<R>;
|
|
2
|
+
type BackendSetupFunction = () => Promise<void>;
|
|
3
|
+
type BackendAcquireFunction = (lockName: string, stale: number, lockId: string) => Promise<void>;
|
|
4
|
+
type BackendRenewFunction = (lockName: string, lockId: string) => Promise<void>;
|
|
5
|
+
type BackendReleaseFunction = (lockName: string, lockId: string) => Promise<void>;
|
|
6
|
+
type Backend = {
|
|
7
|
+
setup: BackendSetupFunction;
|
|
8
|
+
acquire: BackendAcquireFunction;
|
|
9
|
+
renew: BackendRenewFunction;
|
|
10
|
+
release: BackendReleaseFunction;
|
|
11
|
+
};
|
|
12
|
+
type BackendFactory = (...args: any[]) => Backend;
|
|
13
|
+
type LockEvent = {
|
|
14
|
+
type: "acquired";
|
|
15
|
+
lockName: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: "released";
|
|
18
|
+
lockName: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: "renewed";
|
|
21
|
+
lockName: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: "renewFailed";
|
|
24
|
+
lockName: string;
|
|
25
|
+
error: unknown;
|
|
26
|
+
} | {
|
|
27
|
+
type: "lockLost";
|
|
28
|
+
lockName: string;
|
|
29
|
+
reason: "renewFailed" | "timeout";
|
|
30
|
+
} | {
|
|
31
|
+
type: "acquireTimeout";
|
|
32
|
+
lockName: string;
|
|
33
|
+
};
|
|
34
|
+
type LockConfiguration = {
|
|
35
|
+
acquireInterval: number;
|
|
36
|
+
acquireFailTimeout: number;
|
|
37
|
+
stale: number;
|
|
38
|
+
renewInterval: number;
|
|
39
|
+
maxHoldTime: number;
|
|
40
|
+
onLockLost: (lockName: string, reason: "renewFailed" | "timeout") => void;
|
|
41
|
+
onEvent: (event: LockEvent) => void;
|
|
42
|
+
};
|
|
43
|
+
type LockReleaseFunction = (() => Promise<void>) & {
|
|
44
|
+
signal: AbortSignal;
|
|
45
|
+
};
|
|
46
|
+
type LockAcquireFunction = (lockName: string) => Promise<LockReleaseFunction>;
|
|
47
|
+
type Lock = {
|
|
48
|
+
acquire: LockAcquireFunction;
|
|
49
|
+
};
|
|
50
|
+
type TimestampLockEntry = {
|
|
51
|
+
lockId: string;
|
|
52
|
+
timestamp: number;
|
|
53
|
+
};
|
|
54
|
+
type CallbackLockEntry = {
|
|
55
|
+
lockId: string;
|
|
56
|
+
release: () => void;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type { AsyncFunction, Backend, BackendAcquireFunction, BackendFactory, BackendReleaseFunction, BackendRenewFunction, BackendSetupFunction, CallbackLockEntry, Lock, LockAcquireFunction, LockConfiguration, LockEvent, LockReleaseFunction, TimestampLockEntry };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var UniversalLockTypes = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
|
|
17
|
+
// src/index.ts
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
return __toCommonJS(index_exports);
|
|
20
|
+
})();
|
|
21
|
+
//# sourceMappingURL=index.global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type AsyncFunction<R = unknown, P extends unknown[] = unknown[]> = (\n\t...args: P\n) => Promise<R>;\n\nexport type BackendSetupFunction = () => Promise<void>;\nexport type BackendAcquireFunction = (\n\tlockName: string,\n\tstale: number,\n\tlockId: string,\n) => Promise<void>;\nexport type BackendRenewFunction = (\n\tlockName: string,\n\tlockId: string,\n) => Promise<void>;\nexport type BackendReleaseFunction = (\n\tlockName: string,\n\tlockId: string,\n) => Promise<void>;\n\nexport type Backend = {\n\tsetup: BackendSetupFunction;\n\tacquire: BackendAcquireFunction;\n\trenew: BackendRenewFunction;\n\trelease: BackendReleaseFunction;\n};\n\nexport type BackendFactory = (...args: any[]) => Backend;\n\nexport type LockEvent =\n\t| { type: \"acquired\"; lockName: string }\n\t| { type: \"released\"; lockName: string }\n\t| { type: \"renewed\"; lockName: string }\n\t| { type: \"renewFailed\"; lockName: string; error: unknown }\n\t| { type: \"lockLost\"; lockName: string; reason: \"renewFailed\" | \"timeout\" }\n\t| { type: \"acquireTimeout\"; lockName: string };\n\nexport type LockConfiguration = {\n\tacquireInterval: number;\n\tacquireFailTimeout: number;\n\tstale: number;\n\trenewInterval: number;\n\tmaxHoldTime: number;\n\tonLockLost: (lockName: string, reason: \"renewFailed\" | \"timeout\") => void;\n\tonEvent: (event: LockEvent) => void;\n};\n\nexport type LockReleaseFunction = (() => Promise<void>) & {\n\tsignal: AbortSignal;\n};\nexport type LockAcquireFunction = (\n\tlockName: string,\n) => Promise<LockReleaseFunction>;\n\nexport type Lock = { acquire: LockAcquireFunction };\n\nexport type TimestampLockEntry = { lockId: string; timestamp: number };\nexport type CallbackLockEntry = { lockId: string; release: () => void };\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;","names":[]}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/index.ts
|
|
17
|
+
var index_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(index_exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type AsyncFunction<R = unknown, P extends unknown[] = unknown[]> = (\n\t...args: P\n) => Promise<R>;\n\nexport type BackendSetupFunction = () => Promise<void>;\nexport type BackendAcquireFunction = (\n\tlockName: string,\n\tstale: number,\n\tlockId: string,\n) => Promise<void>;\nexport type BackendRenewFunction = (\n\tlockName: string,\n\tlockId: string,\n) => Promise<void>;\nexport type BackendReleaseFunction = (\n\tlockName: string,\n\tlockId: string,\n) => Promise<void>;\n\nexport type Backend = {\n\tsetup: BackendSetupFunction;\n\tacquire: BackendAcquireFunction;\n\trenew: BackendRenewFunction;\n\trelease: BackendReleaseFunction;\n};\n\nexport type BackendFactory = (...args: any[]) => Backend;\n\nexport type LockEvent =\n\t| { type: \"acquired\"; lockName: string }\n\t| { type: \"released\"; lockName: string }\n\t| { type: \"renewed\"; lockName: string }\n\t| { type: \"renewFailed\"; lockName: string; error: unknown }\n\t| { type: \"lockLost\"; lockName: string; reason: \"renewFailed\" | \"timeout\" }\n\t| { type: \"acquireTimeout\"; lockName: string };\n\nexport type LockConfiguration = {\n\tacquireInterval: number;\n\tacquireFailTimeout: number;\n\tstale: number;\n\trenewInterval: number;\n\tmaxHoldTime: number;\n\tonLockLost: (lockName: string, reason: \"renewFailed\" | \"timeout\") => void;\n\tonEvent: (event: LockEvent) => void;\n};\n\nexport type LockReleaseFunction = (() => Promise<void>) & {\n\tsignal: AbortSignal;\n};\nexport type LockAcquireFunction = (\n\tlockName: string,\n) => Promise<LockReleaseFunction>;\n\nexport type Lock = { acquire: LockAcquireFunction };\n\nexport type TimestampLockEntry = { lockId: string; timestamp: number };\nexport type CallbackLockEntry = { lockId: string; release: () => void };\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@universal-lock/types",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Type definitions for universal-lock",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"browser": "dist/index.global.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.mts",
|
|
14
|
+
"default": "./dist/index.mjs"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"/dist"
|
|
24
|
+
],
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/lucasrainett/universal-lock",
|
|
28
|
+
"directory": "packages/types"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"universal-lock",
|
|
32
|
+
"types",
|
|
33
|
+
"typescript"
|
|
34
|
+
],
|
|
35
|
+
"author": {
|
|
36
|
+
"name": "Lucas Rainett",
|
|
37
|
+
"email": "lucas@rainett.dev",
|
|
38
|
+
"url": "https://github.com/lucasrainett"
|
|
39
|
+
},
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup",
|
|
43
|
+
"clean": "rm -rf dist"
|
|
44
|
+
}
|
|
45
|
+
}
|