@supabase/auth-js 2.65.2-rc.2 → 2.66.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/dist/main/lib/locks.d.ts +17 -0
- package/dist/main/lib/locks.d.ts.map +1 -1
- package/dist/main/lib/locks.js +60 -1
- package/dist/main/lib/locks.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.d.ts.map +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/main/lib/version.js.map +1 -1
- package/dist/module/lib/locks.d.ts +17 -0
- package/dist/module/lib/locks.d.ts.map +1 -1
- package/dist/module/lib/locks.js +57 -0
- package/dist/module/lib/locks.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.d.ts.map +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/module/lib/version.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/locks.ts +73 -0
- package/src/lib/version.ts +1 -1
package/dist/main/lib/locks.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export declare abstract class LockAcquireTimeoutError extends Error {
|
|
|
18
18
|
}
|
|
19
19
|
export declare class NavigatorLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
|
20
20
|
}
|
|
21
|
+
export declare class ProcessLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
|
22
|
+
}
|
|
21
23
|
/**
|
|
22
24
|
* Implements a global exclusive lock using the Navigator LockManager API. It
|
|
23
25
|
* is available on all browsers released after 2022-03-15 with Safari being the
|
|
@@ -44,4 +46,19 @@ export declare class NavigatorLockAcquireTimeoutError extends LockAcquireTimeout
|
|
|
44
46
|
* @param fn The operation to run once the lock is acquired.
|
|
45
47
|
*/
|
|
46
48
|
export declare function navigatorLock<R>(name: string, acquireTimeout: number, fn: () => Promise<R>): Promise<R>;
|
|
49
|
+
/**
|
|
50
|
+
* Implements a global exclusive lock that works only in the current process.
|
|
51
|
+
* Useful for environments like React Native or other non-browser
|
|
52
|
+
* single-process (i.e. no concept of "tabs") environments.
|
|
53
|
+
*
|
|
54
|
+
* Use {@link #navigatorLock} in browser environments.
|
|
55
|
+
*
|
|
56
|
+
* @param name Name of the lock to be acquired.
|
|
57
|
+
* @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
|
|
58
|
+
* the lock can't be acquired without waiting. If positive, the lock acquire
|
|
59
|
+
* will time out after so many milliseconds. An error is
|
|
60
|
+
* a timeout if it has `isAcquireTimeout` set to true.
|
|
61
|
+
* @param fn The operation to run once the lock is acquired.
|
|
62
|
+
*/
|
|
63
|
+
export declare function processLock<R>(name: string, acquireTimeout: number, fn: () => Promise<R>): Promise<R>;
|
|
47
64
|
//# sourceMappingURL=locks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../../../src/lib/locks.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,SAAS;IACpB;;OAEG;;CAOJ,CAAA;AAED;;;;GAIG;AACH,8BAAsB,uBAAwB,SAAQ,KAAK;IACzD,SAAgB,gBAAgB,QAAO;gBAE3B,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,gCAAiC,SAAQ,uBAAuB;CAAG;
|
|
1
|
+
{"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../../../src/lib/locks.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,SAAS;IACpB;;OAEG;;CAOJ,CAAA;AAED;;;;GAIG;AACH,8BAAsB,uBAAwB,SAAQ,KAAK;IACzD,SAAgB,gBAAgB,QAAO;gBAE3B,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,gCAAiC,SAAQ,uBAAuB;CAAG;AAChF,qBAAa,8BAA+B,SAAQ,uBAAuB;CAAG;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAiFZ;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAkDZ"}
|
package/dist/main/lib/locks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.navigatorLock = exports.NavigatorLockAcquireTimeoutError = exports.LockAcquireTimeoutError = exports.internals = void 0;
|
|
3
|
+
exports.processLock = exports.navigatorLock = exports.ProcessLockAcquireTimeoutError = exports.NavigatorLockAcquireTimeoutError = exports.LockAcquireTimeoutError = exports.internals = void 0;
|
|
4
4
|
const helpers_1 = require("./helpers");
|
|
5
5
|
/**
|
|
6
6
|
* @experimental
|
|
@@ -29,6 +29,9 @@ exports.LockAcquireTimeoutError = LockAcquireTimeoutError;
|
|
|
29
29
|
class NavigatorLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
|
30
30
|
}
|
|
31
31
|
exports.NavigatorLockAcquireTimeoutError = NavigatorLockAcquireTimeoutError;
|
|
32
|
+
class ProcessLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
|
33
|
+
}
|
|
34
|
+
exports.ProcessLockAcquireTimeoutError = ProcessLockAcquireTimeoutError;
|
|
32
35
|
/**
|
|
33
36
|
* Implements a global exclusive lock using the Navigator LockManager API. It
|
|
34
37
|
* is available on all browsers released after 2022-03-15 with Safari being the
|
|
@@ -118,4 +121,60 @@ async function navigatorLock(name, acquireTimeout, fn) {
|
|
|
118
121
|
});
|
|
119
122
|
}
|
|
120
123
|
exports.navigatorLock = navigatorLock;
|
|
124
|
+
const PROCESS_LOCKS = {};
|
|
125
|
+
/**
|
|
126
|
+
* Implements a global exclusive lock that works only in the current process.
|
|
127
|
+
* Useful for environments like React Native or other non-browser
|
|
128
|
+
* single-process (i.e. no concept of "tabs") environments.
|
|
129
|
+
*
|
|
130
|
+
* Use {@link #navigatorLock} in browser environments.
|
|
131
|
+
*
|
|
132
|
+
* @param name Name of the lock to be acquired.
|
|
133
|
+
* @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
|
|
134
|
+
* the lock can't be acquired without waiting. If positive, the lock acquire
|
|
135
|
+
* will time out after so many milliseconds. An error is
|
|
136
|
+
* a timeout if it has `isAcquireTimeout` set to true.
|
|
137
|
+
* @param fn The operation to run once the lock is acquired.
|
|
138
|
+
*/
|
|
139
|
+
async function processLock(name, acquireTimeout, fn) {
|
|
140
|
+
var _a;
|
|
141
|
+
const previousOperation = (_a = PROCESS_LOCKS[name]) !== null && _a !== void 0 ? _a : Promise.resolve();
|
|
142
|
+
const currentOperation = Promise.race([
|
|
143
|
+
previousOperation.catch((e) => {
|
|
144
|
+
// ignore error of previous operation that we're waiting to finish
|
|
145
|
+
return null;
|
|
146
|
+
}),
|
|
147
|
+
acquireTimeout >= 0
|
|
148
|
+
? new Promise((_, reject) => {
|
|
149
|
+
setTimeout(() => {
|
|
150
|
+
reject(new ProcessLockAcquireTimeoutError(`Acquring process lock with name "${name}" timed out`));
|
|
151
|
+
}, acquireTimeout);
|
|
152
|
+
})
|
|
153
|
+
: null,
|
|
154
|
+
].filter((x) => x))
|
|
155
|
+
.catch((e) => {
|
|
156
|
+
if (e && e.isAcquireTimeout) {
|
|
157
|
+
throw e;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
})
|
|
161
|
+
.then(async () => {
|
|
162
|
+
// previous operations finished and we didn't get a race on the acquire
|
|
163
|
+
// timeout, so the current operation can finally start
|
|
164
|
+
return await fn();
|
|
165
|
+
});
|
|
166
|
+
PROCESS_LOCKS[name] = currentOperation.catch(async (e) => {
|
|
167
|
+
if (e && e.isAcquireTimeout) {
|
|
168
|
+
// if the current operation timed out, it doesn't mean that the previous
|
|
169
|
+
// operation finished, so we need contnue waiting for it to finish
|
|
170
|
+
await previousOperation;
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
throw e;
|
|
174
|
+
});
|
|
175
|
+
// finally wait for the current operation to finish successfully, with an
|
|
176
|
+
// error or with an acquire timeout error
|
|
177
|
+
return await currentOperation;
|
|
178
|
+
}
|
|
179
|
+
exports.processLock = processLock;
|
|
121
180
|
//# sourceMappingURL=locks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locks.js","sourceRoot":"","sources":["../../../src/lib/locks.ts"],"names":[],"mappings":";;;AAAA,uCAAgD;AAEhD;;GAEG;AACU,QAAA,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,CAAC,CAAC,CACP,UAAU;QACV,IAAA,8BAAoB,GAAE;QACtB,UAAU,CAAC,YAAY;QACvB,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,gCAAgC,CAAC,KAAK,MAAM,CAC7E;CACF,CAAA;AAED;;;;GAIG;AACH,MAAsB,uBAAwB,SAAQ,KAAK;IAGzD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QAHA,qBAAgB,GAAG,IAAI,CAAA;IAIvC,CAAC;CACF;AAND,0DAMC;AAED,MAAa,gCAAiC,SAAQ,uBAAuB;CAAG;AAAhF,4EAAgF;
|
|
1
|
+
{"version":3,"file":"locks.js","sourceRoot":"","sources":["../../../src/lib/locks.ts"],"names":[],"mappings":";;;AAAA,uCAAgD;AAEhD;;GAEG;AACU,QAAA,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,CAAC,CAAC,CACP,UAAU;QACV,IAAA,8BAAoB,GAAE;QACtB,UAAU,CAAC,YAAY;QACvB,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,gCAAgC,CAAC,KAAK,MAAM,CAC7E;CACF,CAAA;AAED;;;;GAI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|
1
|
+
export declare const version = "2.66.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,WAAW,CAAA"}
|
package/dist/main/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,QAAQ,CAAA"}
|
|
@@ -18,6 +18,8 @@ export declare abstract class LockAcquireTimeoutError extends Error {
|
|
|
18
18
|
}
|
|
19
19
|
export declare class NavigatorLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
|
20
20
|
}
|
|
21
|
+
export declare class ProcessLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
|
22
|
+
}
|
|
21
23
|
/**
|
|
22
24
|
* Implements a global exclusive lock using the Navigator LockManager API. It
|
|
23
25
|
* is available on all browsers released after 2022-03-15 with Safari being the
|
|
@@ -44,4 +46,19 @@ export declare class NavigatorLockAcquireTimeoutError extends LockAcquireTimeout
|
|
|
44
46
|
* @param fn The operation to run once the lock is acquired.
|
|
45
47
|
*/
|
|
46
48
|
export declare function navigatorLock<R>(name: string, acquireTimeout: number, fn: () => Promise<R>): Promise<R>;
|
|
49
|
+
/**
|
|
50
|
+
* Implements a global exclusive lock that works only in the current process.
|
|
51
|
+
* Useful for environments like React Native or other non-browser
|
|
52
|
+
* single-process (i.e. no concept of "tabs") environments.
|
|
53
|
+
*
|
|
54
|
+
* Use {@link #navigatorLock} in browser environments.
|
|
55
|
+
*
|
|
56
|
+
* @param name Name of the lock to be acquired.
|
|
57
|
+
* @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
|
|
58
|
+
* the lock can't be acquired without waiting. If positive, the lock acquire
|
|
59
|
+
* will time out after so many milliseconds. An error is
|
|
60
|
+
* a timeout if it has `isAcquireTimeout` set to true.
|
|
61
|
+
* @param fn The operation to run once the lock is acquired.
|
|
62
|
+
*/
|
|
63
|
+
export declare function processLock<R>(name: string, acquireTimeout: number, fn: () => Promise<R>): Promise<R>;
|
|
47
64
|
//# sourceMappingURL=locks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../../../src/lib/locks.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,SAAS;IACpB;;OAEG;;CAOJ,CAAA;AAED;;;;GAIG;AACH,8BAAsB,uBAAwB,SAAQ,KAAK;IACzD,SAAgB,gBAAgB,QAAO;gBAE3B,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,gCAAiC,SAAQ,uBAAuB;CAAG;
|
|
1
|
+
{"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../../../src/lib/locks.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,SAAS;IACpB;;OAEG;;CAOJ,CAAA;AAED;;;;GAIG;AACH,8BAAsB,uBAAwB,SAAQ,KAAK;IACzD,SAAgB,gBAAgB,QAAO;gBAE3B,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,gCAAiC,SAAQ,uBAAuB;CAAG;AAChF,qBAAa,8BAA+B,SAAQ,uBAAuB;CAAG;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAiFZ;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAkDZ"}
|
package/dist/module/lib/locks.js
CHANGED
|
@@ -24,6 +24,8 @@ export class LockAcquireTimeoutError extends Error {
|
|
|
24
24
|
}
|
|
25
25
|
export class NavigatorLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
|
26
26
|
}
|
|
27
|
+
export class ProcessLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
|
28
|
+
}
|
|
27
29
|
/**
|
|
28
30
|
* Implements a global exclusive lock using the Navigator LockManager API. It
|
|
29
31
|
* is available on all browsers released after 2022-03-15 with Safari being the
|
|
@@ -112,4 +114,59 @@ export async function navigatorLock(name, acquireTimeout, fn) {
|
|
|
112
114
|
}
|
|
113
115
|
});
|
|
114
116
|
}
|
|
117
|
+
const PROCESS_LOCKS = {};
|
|
118
|
+
/**
|
|
119
|
+
* Implements a global exclusive lock that works only in the current process.
|
|
120
|
+
* Useful for environments like React Native or other non-browser
|
|
121
|
+
* single-process (i.e. no concept of "tabs") environments.
|
|
122
|
+
*
|
|
123
|
+
* Use {@link #navigatorLock} in browser environments.
|
|
124
|
+
*
|
|
125
|
+
* @param name Name of the lock to be acquired.
|
|
126
|
+
* @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
|
|
127
|
+
* the lock can't be acquired without waiting. If positive, the lock acquire
|
|
128
|
+
* will time out after so many milliseconds. An error is
|
|
129
|
+
* a timeout if it has `isAcquireTimeout` set to true.
|
|
130
|
+
* @param fn The operation to run once the lock is acquired.
|
|
131
|
+
*/
|
|
132
|
+
export async function processLock(name, acquireTimeout, fn) {
|
|
133
|
+
var _a;
|
|
134
|
+
const previousOperation = (_a = PROCESS_LOCKS[name]) !== null && _a !== void 0 ? _a : Promise.resolve();
|
|
135
|
+
const currentOperation = Promise.race([
|
|
136
|
+
previousOperation.catch((e) => {
|
|
137
|
+
// ignore error of previous operation that we're waiting to finish
|
|
138
|
+
return null;
|
|
139
|
+
}),
|
|
140
|
+
acquireTimeout >= 0
|
|
141
|
+
? new Promise((_, reject) => {
|
|
142
|
+
setTimeout(() => {
|
|
143
|
+
reject(new ProcessLockAcquireTimeoutError(`Acquring process lock with name "${name}" timed out`));
|
|
144
|
+
}, acquireTimeout);
|
|
145
|
+
})
|
|
146
|
+
: null,
|
|
147
|
+
].filter((x) => x))
|
|
148
|
+
.catch((e) => {
|
|
149
|
+
if (e && e.isAcquireTimeout) {
|
|
150
|
+
throw e;
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
})
|
|
154
|
+
.then(async () => {
|
|
155
|
+
// previous operations finished and we didn't get a race on the acquire
|
|
156
|
+
// timeout, so the current operation can finally start
|
|
157
|
+
return await fn();
|
|
158
|
+
});
|
|
159
|
+
PROCESS_LOCKS[name] = currentOperation.catch(async (e) => {
|
|
160
|
+
if (e && e.isAcquireTimeout) {
|
|
161
|
+
// if the current operation timed out, it doesn't mean that the previous
|
|
162
|
+
// operation finished, so we need contnue waiting for it to finish
|
|
163
|
+
await previousOperation;
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
throw e;
|
|
167
|
+
});
|
|
168
|
+
// finally wait for the current operation to finish successfully, with an
|
|
169
|
+
// error or with an acquire timeout error
|
|
170
|
+
return await currentOperation;
|
|
171
|
+
}
|
|
115
172
|
//# sourceMappingURL=locks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locks.js","sourceRoot":"","sources":["../../../src/lib/locks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,CAAC,CAAC,CACP,UA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AAC,CAAM,EAAE,EAAE;QAChB,IAAI,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE;YAC3B,MAAM,CAAC,CAAA;SACR;QAED,OAAO,IAAI,CAAA;IACb,CAAC,CAAC;SACD,IAAI,CAAC,KAAK,IAAI,EAAE;QACf,uEAAuE;QACvE,sDAAsD;QACtD,OAAO,MAAM,EAAE,EAAE,CAAA;IACnB,CAAC,CAAC,CAAA;IAEJ,aAAa,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAK,EAAE,CAAM,EAAE,EAAE;QAC5D,IAAI,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE;YAC3B,wEAAwE;YACxE,kEAAkE;YAClE,MAAM,iBAAiB,CAAA;YAEvB,OAAO,IAAI,CAAA;SACZ;QAED,MAAM,CAAC,CAAA;IACT,CAAC,CAAC,CAAA;IAEF,yEAAyE;IACzE,yCAAyC;IACzC,OAAO,MAAM,gBAAgB,CAAA;AAC/B,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "2.
|
|
1
|
+
export declare const version = "2.66.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,WAAW,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.66.0';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAA"}
|
package/package.json
CHANGED
package/src/lib/locks.ts
CHANGED
|
@@ -29,6 +29,7 @@ export abstract class LockAcquireTimeoutError extends Error {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export class NavigatorLockAcquireTimeoutError extends LockAcquireTimeoutError {}
|
|
32
|
+
export class ProcessLockAcquireTimeoutError extends LockAcquireTimeoutError {}
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* Implements a global exclusive lock using the Navigator LockManager API. It
|
|
@@ -141,3 +142,75 @@ export async function navigatorLock<R>(
|
|
|
141
142
|
}
|
|
142
143
|
)
|
|
143
144
|
}
|
|
145
|
+
|
|
146
|
+
const PROCESS_LOCKS: { [name: string]: Promise<any> } = {}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Implements a global exclusive lock that works only in the current process.
|
|
150
|
+
* Useful for environments like React Native or other non-browser
|
|
151
|
+
* single-process (i.e. no concept of "tabs") environments.
|
|
152
|
+
*
|
|
153
|
+
* Use {@link #navigatorLock} in browser environments.
|
|
154
|
+
*
|
|
155
|
+
* @param name Name of the lock to be acquired.
|
|
156
|
+
* @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
|
|
157
|
+
* the lock can't be acquired without waiting. If positive, the lock acquire
|
|
158
|
+
* will time out after so many milliseconds. An error is
|
|
159
|
+
* a timeout if it has `isAcquireTimeout` set to true.
|
|
160
|
+
* @param fn The operation to run once the lock is acquired.
|
|
161
|
+
*/
|
|
162
|
+
export async function processLock<R>(
|
|
163
|
+
name: string,
|
|
164
|
+
acquireTimeout: number,
|
|
165
|
+
fn: () => Promise<R>
|
|
166
|
+
): Promise<R> {
|
|
167
|
+
const previousOperation = PROCESS_LOCKS[name] ?? Promise.resolve()
|
|
168
|
+
|
|
169
|
+
const currentOperation = Promise.race(
|
|
170
|
+
[
|
|
171
|
+
previousOperation.catch((e: any) => {
|
|
172
|
+
// ignore error of previous operation that we're waiting to finish
|
|
173
|
+
return null
|
|
174
|
+
}),
|
|
175
|
+
acquireTimeout >= 0
|
|
176
|
+
? new Promise((_, reject) => {
|
|
177
|
+
setTimeout(() => {
|
|
178
|
+
reject(
|
|
179
|
+
new ProcessLockAcquireTimeoutError(
|
|
180
|
+
`Acquring process lock with name "${name}" timed out`
|
|
181
|
+
)
|
|
182
|
+
)
|
|
183
|
+
}, acquireTimeout)
|
|
184
|
+
})
|
|
185
|
+
: null,
|
|
186
|
+
].filter((x) => x)
|
|
187
|
+
)
|
|
188
|
+
.catch((e: any) => {
|
|
189
|
+
if (e && e.isAcquireTimeout) {
|
|
190
|
+
throw e
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return null
|
|
194
|
+
})
|
|
195
|
+
.then(async () => {
|
|
196
|
+
// previous operations finished and we didn't get a race on the acquire
|
|
197
|
+
// timeout, so the current operation can finally start
|
|
198
|
+
return await fn()
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
PROCESS_LOCKS[name] = currentOperation.catch(async (e: any) => {
|
|
202
|
+
if (e && e.isAcquireTimeout) {
|
|
203
|
+
// if the current operation timed out, it doesn't mean that the previous
|
|
204
|
+
// operation finished, so we need contnue waiting for it to finish
|
|
205
|
+
await previousOperation
|
|
206
|
+
|
|
207
|
+
return null
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
throw e
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
// finally wait for the current operation to finish successfully, with an
|
|
214
|
+
// error or with an acquire timeout error
|
|
215
|
+
return await currentOperation
|
|
216
|
+
}
|
package/src/lib/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.66.0'
|