@stackframe/stack-shared
Advanced tools
| declare const globalVar: any; | ||
| export { globalVar, }; | ||
| export declare function createGlobal<T>(key: string, init: () => T): T; |
| const globalVar = typeof globalThis !== 'undefined' ? globalThis : | ||
| typeof window !== 'undefined' ? window : | ||
| typeof global !== 'undefined' ? global : | ||
| typeof self !== 'undefined' ? self : | ||
| {}; | ||
| export { globalVar, }; | ||
| const stackGlobalsSymbol = Symbol.for('__stack-globals'); | ||
| globalVar[stackGlobalsSymbol] ??= {}; | ||
| export function createGlobal(key, init) { | ||
| if (!globalVar[stackGlobalsSymbol][key]) { | ||
| globalVar[stackGlobalsSymbol][key] = init(); | ||
| } | ||
| return globalVar[stackGlobalsSymbol][key]; | ||
| } |
@@ -92,3 +92,5 @@ import { DependenciesMap } from "./maps"; | ||
| _setAsync(value) { | ||
| return pending(this._store.setAsync(value)); | ||
| const promise = pending(value); | ||
| this._pendingPromise = promise; | ||
| return pending(this._store.setAsync(promise)); | ||
| } | ||
@@ -103,3 +105,2 @@ _refetch(cacheStrategy) { | ||
| } | ||
| this._pendingPromise = promise; | ||
| return pending(this._setAsync(promise).then(() => promise)); | ||
@@ -106,0 +107,0 @@ } |
@@ -11,3 +11,3 @@ export type DeepPartial<T> = T extends object ? { | ||
| export declare function typedEntries<T extends {}>(obj: T): [keyof T, T[keyof T]][]; | ||
| export declare function typedFromEntries<T extends {}>(entries: [keyof T, T[keyof T]][]): Partial<T>; | ||
| export declare function typedFromEntries<K extends PropertyKey, V>(entries: [K, V][]): Record<K, V>; | ||
| export declare function typedKeys<T extends {}>(obj: T): (keyof T)[]; | ||
@@ -14,0 +14,0 @@ export declare function typedValues<T extends {}>(obj: T): T[keyof T][]; |
@@ -14,5 +14,3 @@ import { Result } from "./results"; | ||
| */ | ||
| export declare function rejected<T>(reason: unknown, options?: { | ||
| disableErrorWrapping?: boolean; | ||
| }): ReactPromise<T>; | ||
| export declare function rejected<T>(reason: unknown): ReactPromise<T>; | ||
| export declare function neverResolve(): ReactPromise<never>; | ||
@@ -19,0 +17,0 @@ export declare function pending<T>(promise: Promise<T>, options?: { |
@@ -44,7 +44,6 @@ import { StackAssertionError, captureError } from "./errors"; | ||
| */ | ||
| export function rejected(reason, options = {}) { | ||
| const actualReason = options.disableErrorWrapping ? reason : createReactPromiseErrorWrapper(reason); | ||
| return Object.assign(Promise.reject(actualReason), { | ||
| export function rejected(reason) { | ||
| return Object.assign(Promise.reject(reason), { | ||
| status: "rejected", | ||
| reason: actualReason, | ||
| reason: reason, | ||
| }); | ||
@@ -62,5 +61,4 @@ } | ||
| res.status = "rejected"; | ||
| const reason = options.disableErrorWrapping ? actualReason : createReactPromiseErrorWrapper(actualReason); | ||
| res.reason = reason; | ||
| throw reason; | ||
| res.reason = actualReason; | ||
| throw actualReason; | ||
| }); | ||
@@ -70,16 +68,2 @@ res.status = "pending"; | ||
| } | ||
| function createReactPromiseErrorWrapper(error) { | ||
| return new ReactPromiseErrorWrapper(error); | ||
| } | ||
| class ReactPromiseErrorWrapper extends StackAssertionError { | ||
| error; | ||
| wrappedErrorMessage; | ||
| constructor(error) { | ||
| const wrappedErrorMessage = error instanceof ReactPromiseErrorWrapper ? error.wrappedErrorMessage : `${error}`; | ||
| super(`Error occured in a ReactPromise: ${wrappedErrorMessage}\n\nSee the \`cause\` property for the original error. This error is a wrapper around the original error to preserve the stack trace (which would go lost when using Stack's pending(...) or rejected(...) functions).`, { cause: error }); | ||
| this.error = error; | ||
| this.wrappedErrorMessage = wrappedErrorMessage; | ||
| this.name = "ReactPromiseErrorWrapper"; | ||
| } | ||
| } | ||
| export async function wait(ms) { | ||
@@ -86,0 +70,0 @@ return await new Promise(resolve => setTimeout(resolve, ms)); |
+1
-1
| { | ||
| "name": "@stackframe/stack-shared", | ||
| "version": "2.3.3", | ||
| "version": "2.3.5", | ||
| "main": "./dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "./dist/index.d.ts", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
68
3.03%141382
-0.25%