@take-out/helpers 0.0.42 → 0.0.43
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/cjs/async/asyncContext.native.js +4 -43
- package/dist/cjs/async/asyncContext.native.js.map +3 -3
- package/dist/esm/async/asyncContext.native.js +0 -32
- package/dist/esm/async/asyncContext.native.js.map +1 -1
- package/package.json +3 -3
- package/src/async/asyncContext.native.ts +88 -0
- package/types/async/asyncContext.native.d.ts +1 -1
- package/types/async/asyncContext.native.d.ts.map +2 -2
|
@@ -13,51 +13,12 @@ var __export = (target, all) => {
|
|
|
13
13
|
return to;
|
|
14
14
|
};
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
16
|
-
var
|
|
17
|
-
__export(
|
|
16
|
+
var asyncContext_native_exports = {};
|
|
17
|
+
__export(asyncContext_native_exports, {
|
|
18
18
|
createAsyncContext: () => createAsyncContext
|
|
19
19
|
});
|
|
20
|
-
module.exports = __toCommonJS(
|
|
21
|
-
var nodeAsyncLocalStorageCache = null, nodeModuleId = [
|
|
22
|
-
"node",
|
|
23
|
-
"async_hooks"
|
|
24
|
-
].join(":");
|
|
25
|
-
async function getNodeAsyncLocalStorage() {
|
|
26
|
-
if (!nodeAsyncLocalStorageCache)
|
|
27
|
-
try {
|
|
28
|
-
var module2 = await import(
|
|
29
|
-
/* @vite-ignore */
|
|
30
|
-
nodeModuleId
|
|
31
|
-
);
|
|
32
|
-
nodeAsyncLocalStorageCache = module2.AsyncLocalStorage;
|
|
33
|
-
} catch {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
return nodeAsyncLocalStorageCache;
|
|
37
|
-
}
|
|
20
|
+
module.exports = __toCommonJS(asyncContext_native_exports);
|
|
38
21
|
function createAsyncContext() {
|
|
39
|
-
if (process.env.VITE_ENVIRONMENT === "ssr") {
|
|
40
|
-
var storage = null;
|
|
41
|
-
return getNodeAsyncLocalStorage().then(function(AsyncLocalStorage) {
|
|
42
|
-
AsyncLocalStorage && !storage && (storage = new AsyncLocalStorage());
|
|
43
|
-
}), {
|
|
44
|
-
get() {
|
|
45
|
-
if (!storage) {
|
|
46
|
-
console.warn("\u26A0\uFE0F called AsyncContext before load!");
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
return storage.getStore();
|
|
50
|
-
},
|
|
51
|
-
async run(value, fn) {
|
|
52
|
-
if (!storage)
|
|
53
|
-
throw new Error("\u26A0\uFE0F called AsyncContext before load!");
|
|
54
|
-
return storage.run(value, fn);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
} else
|
|
58
|
-
return createBrowserAsyncContext();
|
|
59
|
-
}
|
|
60
|
-
function createBrowserAsyncContext() {
|
|
61
22
|
var currentContext, contextStack = [];
|
|
62
23
|
return {
|
|
63
24
|
get() {
|
|
@@ -103,4 +64,4 @@ function createBrowserAsyncContext() {
|
|
|
103
64
|
0 && (module.exports = {
|
|
104
65
|
createAsyncContext
|
|
105
66
|
});
|
|
106
|
-
//# sourceMappingURL=asyncContext.js.map
|
|
67
|
+
//# sourceMappingURL=asyncContext.native.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/async/asyncContext.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
5
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../src/async/asyncContext.native.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACO,SAAS,qBAAqB;AACjC,MAAI,gBACA,eAAe,CAAC;AACpB,SAAO;AAAA,IACH,MAAO;AACH,aAAO;AAAA,IACX;AAAA,IACA,MAAM,IAAK,OAAO,IAAI;AAClB,UAAI,cAAc;AAClB,uBAAiB,OACjB,aAAa,KAAK,WAAW;AAE7B,UAAI,kBAAkB,SAClB,eAAe,gBAAgB,UAAU,MACzC,gBAAgB,gBAAgB,UAAU,OAC1C,kBAAkB,gBAAgB,UAAU;AAChD,eAAS,aAAa,UAAU,SAAS;AACrC,eAAK,YACE,WAAW;AACd,mBAAQ,OAAO,UAAU,QAAQ,OAAO,IAAI,MAAM,IAAI,GAAG,OAAO,GAAG,OAAO,MAAM;AAC5E,iBAAK,IAAI,IAAI,UAAU,IAAI;AAE/B,cAAIA,eAAc;AAClB,2BAAiB;AACjB,cAAI;AACA,mBAAO,SAAS,GAAG,IAAI;AAAA,UAC3B,UAAE;AACE,6BAAiBA;AAAA,UACrB;AAAA,QACJ;AAAA,MACJ;AAGA,sBAAgB,UAAU,OAAO,SAAS,aAAa,YAAY;AAC/D,YAAI,UAAU;AACd,eAAO,aAAa,KAAK,MAAM,aAAa,aAAa,OAAO,GAAG,aAAa,YAAY,OAAO,CAAC;AAAA,MACxG,GACA,gBAAgB,UAAU,QAAQ,SAAS,YAAY;AACnD,YAAI,UAAU;AACd,eAAO,cAAc,KAAK,MAAM,aAAa,YAAY,OAAO,CAAC;AAAA,MACrE,GACA,gBAAgB,UAAU,UAAU,SAAS,WAAW;AACpD,YAAI,UAAU;AACd,eAAO,gBAAgB,KAAK,MAAM,aAAa,WAAW,OAAO,CAAC;AAAA,MACtE;AACA,UAAI;AACA,YAAI,SAAS,MAAM,GAAG;AACtB,eAAO;AAAA,MACX,UAAE;AAGE,wBAAgB,UAAU,OAAO,cACjC,gBAAgB,UAAU,QAAQ,eAClC,gBAAgB,UAAU,UAAU,iBACpC,aAAa,IAAI,GACjB,iBAAiB;AAAA,MACrB;AAAA,IACJ;AAAA,EACJ;AACJ;",
|
|
5
|
+
"names": ["prevContext"]
|
|
6
6
|
}
|
|
@@ -1,36 +1,4 @@
|
|
|
1
|
-
var nodeAsyncLocalStorageCache = null,
|
|
2
|
-
nodeModuleId = ["node", "async_hooks"].join(":");
|
|
3
|
-
async function getNodeAsyncLocalStorage() {
|
|
4
|
-
if (!nodeAsyncLocalStorageCache) try {
|
|
5
|
-
var module = await import(/* @vite-ignore */
|
|
6
|
-
nodeModuleId);
|
|
7
|
-
nodeAsyncLocalStorageCache = module.AsyncLocalStorage;
|
|
8
|
-
} catch {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
return nodeAsyncLocalStorageCache;
|
|
12
|
-
}
|
|
13
1
|
function createAsyncContext() {
|
|
14
|
-
if (process.env.VITE_ENVIRONMENT === "ssr") {
|
|
15
|
-
var storage = null;
|
|
16
|
-
return getNodeAsyncLocalStorage().then(function (AsyncLocalStorage) {
|
|
17
|
-
AsyncLocalStorage && !storage && (storage = new AsyncLocalStorage());
|
|
18
|
-
}), {
|
|
19
|
-
get() {
|
|
20
|
-
if (!storage) {
|
|
21
|
-
console.warn("\u26A0\uFE0F called AsyncContext before load!");
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
return storage.getStore();
|
|
25
|
-
},
|
|
26
|
-
async run(value, fn) {
|
|
27
|
-
if (!storage) throw new Error("\u26A0\uFE0F called AsyncContext before load!");
|
|
28
|
-
return storage.run(value, fn);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
} else return createBrowserAsyncContext();
|
|
32
|
-
}
|
|
33
|
-
function createBrowserAsyncContext() {
|
|
34
2
|
var currentContext,
|
|
35
3
|
contextStack = [];
|
|
36
4
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createAsyncContext","currentContext","contextStack","get","run","value","fn","prevContext","push","OriginalPromise","Promise","OriginalThen","prototype","then","OriginalCatch","catch","OriginalFinally","finally","wrapCallback","callback","context","_len","arguments","length","args","Array","_key","prevContext2","onFulfilled","onRejected","call","onFinally","result","pop"],"sources":["../../../src/async/asyncContext.native.ts"],"sourcesContent":[null],"mappings":"AACO,SAASA,mBAAA,EAAqB;EACjC,IAAIC,cAAA;IACAC,YAAA,GAAe,EAAC;EACpB,OAAO;IAC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,CAAaW,UAAA,EAAYT,OAAO,CAAC;MACrE,GACAX,eAAA,CAAgBG,SAAA,CAAUK,OAAA,GAAU,UAASc,SAAA,EAAW;QACpD,IAAIX,OAAA,GAAUnB,cAAA;QACd,OAAOe,eAAA,CAAgBc,IAAA,CAAK,MAAMZ,YAAA,CAAaa,SAAA,EAAWX,OAAO,CAAC;MACtE;MACA,IAAI;QACA,IAAIY,MAAA,GAAS,MAAM1B,EAAA,CAAG;QACtB,OAAO0B,MAAA;MACX,UAAE;QAGEvB,eAAA,CAAgBG,SAAA,CAAUC,IAAA,GAAOF,YAAA,EACjCF,eAAA,CAAgBG,SAAA,CAAUG,KAAA,GAAQD,aAAA,EAClCL,eAAA,CAAgBG,SAAA,CAAUK,OAAA,GAAUD,eAAA,EACpCd,YAAA,CAAa+B,GAAA,CAAI,GACjBhC,cAAA,GAAiBM,WAAA;MACrB;IACJ;EACJ;AACJ","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@take-out/helpers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.43",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@tamagui/constants": "
|
|
58
|
+
"@tamagui/constants": "^2.0.0-1768869088163",
|
|
59
59
|
"dequal": "^2.0.3"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"react-native": "*"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@tamagui/build": "
|
|
68
|
+
"@tamagui/build": "^2.0.0-1768869088163",
|
|
69
69
|
"@types/node": "24.0.3",
|
|
70
70
|
"@types/react": "^19.0.8",
|
|
71
71
|
"oxfmt": "^0.16.0",
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
interface AsyncContext<T> {
|
|
2
|
+
get(): T | undefined
|
|
3
|
+
run<R>(value: T, fn: () => R | Promise<R>): Promise<R>
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// react native implementation - no node:async_hooks available
|
|
7
|
+
export function createAsyncContext<T>(): AsyncContext<T> {
|
|
8
|
+
let currentContext: T | undefined
|
|
9
|
+
const contextStack: (T | undefined)[] = []
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
get(): T | undefined {
|
|
13
|
+
return currentContext
|
|
14
|
+
},
|
|
15
|
+
async run<R>(value: T, fn: () => R | Promise<R>): Promise<R> {
|
|
16
|
+
const prevContext = currentContext
|
|
17
|
+
currentContext = value
|
|
18
|
+
contextStack.push(prevContext)
|
|
19
|
+
|
|
20
|
+
// store original Promise methods
|
|
21
|
+
const OriginalPromise = Promise
|
|
22
|
+
const OriginalThen = OriginalPromise.prototype.then
|
|
23
|
+
const OriginalCatch = OriginalPromise.prototype.catch
|
|
24
|
+
const OriginalFinally = OriginalPromise.prototype.finally
|
|
25
|
+
|
|
26
|
+
function wrapCallback(
|
|
27
|
+
callback: Function | undefined | null,
|
|
28
|
+
context: T | undefined
|
|
29
|
+
): Function | undefined | null {
|
|
30
|
+
if (!callback) return callback
|
|
31
|
+
return (...args: any[]) => {
|
|
32
|
+
const prevContext = currentContext
|
|
33
|
+
currentContext = context
|
|
34
|
+
try {
|
|
35
|
+
return callback(...args)
|
|
36
|
+
} finally {
|
|
37
|
+
currentContext = prevContext
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// patch Promise methods to capture and restore context
|
|
43
|
+
// eslint-disable-next-line no-then-property -- intentional patching for context propagation
|
|
44
|
+
OriginalPromise.prototype.then = function (
|
|
45
|
+
this: Promise<any>,
|
|
46
|
+
onFulfilled?: any,
|
|
47
|
+
onRejected?: any
|
|
48
|
+
): Promise<any> {
|
|
49
|
+
const context = currentContext
|
|
50
|
+
return OriginalThen.call(
|
|
51
|
+
this,
|
|
52
|
+
wrapCallback(onFulfilled, context) as any,
|
|
53
|
+
wrapCallback(onRejected, context) as any
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
OriginalPromise.prototype.catch = function (
|
|
58
|
+
this: Promise<any>,
|
|
59
|
+
onRejected?: any
|
|
60
|
+
): Promise<any> {
|
|
61
|
+
const context = currentContext
|
|
62
|
+
return OriginalCatch.call(this, wrapCallback(onRejected, context) as any)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
OriginalPromise.prototype.finally = function (
|
|
66
|
+
this: Promise<any>,
|
|
67
|
+
onFinally?: any
|
|
68
|
+
): Promise<any> {
|
|
69
|
+
const context = currentContext
|
|
70
|
+
return OriginalFinally.call(this, wrapCallback(onFinally, context) as any)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
const result = await fn()
|
|
75
|
+
return result
|
|
76
|
+
} finally {
|
|
77
|
+
// restore original Promise methods
|
|
78
|
+
// eslint-disable-next-line no-then-property -- restoring original methods
|
|
79
|
+
OriginalPromise.prototype.then = OriginalThen
|
|
80
|
+
OriginalPromise.prototype.catch = OriginalCatch
|
|
81
|
+
OriginalPromise.prototype.finally = OriginalFinally
|
|
82
|
+
|
|
83
|
+
contextStack.pop()
|
|
84
|
+
currentContext = prevContext
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// browser/native implementation - no node:async_hooks
|
|
2
1
|
interface AsyncContext<T> {
|
|
3
2
|
get(): T | undefined;
|
|
4
3
|
run<R>(value: T, fn: () => R | Promise<R>): Promise<R>;
|
|
5
4
|
}
|
|
5
|
+
// react native implementation - no node:async_hooks available
|
|
6
6
|
export declare function createAsyncContext<T>(): AsyncContext<T>;
|
|
7
7
|
export {};
|
|
8
8
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"mappings": "
|
|
2
|
+
"mappings": "UAAU,aAAa,GAAG;CACxB,OAAO;CACP,IAAI,GAAGA,OAAO,GAAGC,UAAU,IAAI,QAAQ,KAAK,QAAQ;AACrD;;AAGD,OAAO,iBAAS,mBAAmB,MAAM,aAAa",
|
|
3
3
|
"names": [
|
|
4
4
|
"value: T",
|
|
5
5
|
"fn: () => R | Promise<R>"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"src/async/asyncContext.native.ts"
|
|
9
9
|
],
|
|
10
10
|
"sourcesContent": [
|
|
11
|
-
"
|
|
11
|
+
"interface AsyncContext<T> {\n get(): T | undefined\n run<R>(value: T, fn: () => R | Promise<R>): Promise<R>\n}\n\n// react native implementation - no node:async_hooks available\nexport function createAsyncContext<T>(): AsyncContext<T> {\n let currentContext: T | undefined\n const contextStack: (T | undefined)[] = []\n\n return {\n get(): T | undefined {\n return currentContext\n },\n async run<R>(value: T, fn: () => R | Promise<R>): Promise<R> {\n const prevContext = currentContext\n currentContext = value\n contextStack.push(prevContext)\n\n // store original Promise methods\n const OriginalPromise = Promise\n const OriginalThen = OriginalPromise.prototype.then\n const OriginalCatch = OriginalPromise.prototype.catch\n const OriginalFinally = OriginalPromise.prototype.finally\n\n function wrapCallback(\n callback: Function | undefined | null,\n context: T | undefined\n ): Function | undefined | null {\n if (!callback) return callback\n return (...args: any[]) => {\n const prevContext = currentContext\n currentContext = context\n try {\n return callback(...args)\n } finally {\n currentContext = prevContext\n }\n }\n }\n\n // patch Promise methods to capture and restore context\n // eslint-disable-next-line no-then-property -- intentional patching for context propagation\n OriginalPromise.prototype.then = function (\n this: Promise<any>,\n onFulfilled?: any,\n onRejected?: any\n ): Promise<any> {\n const context = currentContext\n return OriginalThen.call(\n this,\n wrapCallback(onFulfilled, context) as any,\n wrapCallback(onRejected, context) as any\n )\n }\n\n OriginalPromise.prototype.catch = function (\n this: Promise<any>,\n onRejected?: any\n ): Promise<any> {\n const context = currentContext\n return OriginalCatch.call(this, wrapCallback(onRejected, context) as any)\n }\n\n OriginalPromise.prototype.finally = function (\n this: Promise<any>,\n onFinally?: any\n ): Promise<any> {\n const context = currentContext\n return OriginalFinally.call(this, wrapCallback(onFinally, context) as any)\n }\n\n try {\n const result = await fn()\n return result\n } finally {\n // restore original Promise methods\n // eslint-disable-next-line no-then-property -- restoring original methods\n OriginalPromise.prototype.then = OriginalThen\n OriginalPromise.prototype.catch = OriginalCatch\n OriginalPromise.prototype.finally = OriginalFinally\n\n contextStack.pop()\n currentContext = prevContext\n }\n },\n }\n}\n"
|
|
12
12
|
],
|
|
13
13
|
"version": 3
|
|
14
14
|
}
|