@standardserver/shared 0.0.2 → 0.0.4
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/index.d.mts +11 -26
- package/dist/index.d.ts +11 -26
- package/dist/index.mjs +17 -29
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
|
|
2
2
|
|
|
3
3
|
declare const PACKAGE_NAME = "@standardserver/shared";
|
|
4
|
-
declare const PACKAGE_VERSION = "0.0.
|
|
4
|
+
declare const PACKAGE_VERSION = "0.0.4";
|
|
5
5
|
/**
|
|
6
6
|
* Generates a unique symbol for the specified name within the package scope.
|
|
7
7
|
* The symbol is globally registered using `Symbol.for` to ensure consistency across modules.
|
|
@@ -67,30 +67,15 @@ declare function stringifyJSON<T>(value: T | {
|
|
|
67
67
|
*/
|
|
68
68
|
declare function isTypescriptObject(maybeObject: unknown): maybeObject is object;
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
get(target: T, p: PropertyKey, receiver: any, fallback: () => any): any;
|
|
70
|
+
interface GetOrBindOptions {
|
|
71
|
+
/**
|
|
72
|
+
* Whether to bind the function to the target before returning it.
|
|
73
|
+
*
|
|
74
|
+
* @default true
|
|
75
|
+
*/
|
|
76
|
+
bind?: boolean;
|
|
78
77
|
}
|
|
79
|
-
|
|
80
|
-
* Creates a Proxy that enhances the standard `get` trap by providing:
|
|
81
|
-
*
|
|
82
|
-
* - A `fallback` function that:
|
|
83
|
-
* - Reads the property directly from the target
|
|
84
|
-
* - Automatically binds methods to the target
|
|
85
|
-
* - Caches bound methods for stable identity
|
|
86
|
-
* - An internal symbol that allows accessing the original target
|
|
87
|
-
*/
|
|
88
|
-
declare function createEnhancedProxy<T extends object>(target: T, handler: EnhancedProxyHandler<T>): T;
|
|
89
|
-
/**
|
|
90
|
-
* Returns the underlying target of an enhanced proxy.
|
|
91
|
-
* If the given value is not an enhanced proxy, it is returned as-is.
|
|
92
|
-
*/
|
|
93
|
-
declare function getEnhancedProxyTarget<T extends object>(value: T): T;
|
|
78
|
+
declare function getOrBind<T extends object, K extends PropertyKey>(target: T, property: K, { bind }?: GetOrBindOptions): K extends keyof T ? T[K] : unknown;
|
|
94
79
|
|
|
95
80
|
interface AsyncIdQueueCloseOptions {
|
|
96
81
|
id?: string;
|
|
@@ -128,5 +113,5 @@ declare function sleep(ms: number): Promise<void>;
|
|
|
128
113
|
|
|
129
114
|
declare function tryDecodeURIComponent(value: string): string;
|
|
130
115
|
|
|
131
|
-
export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator,
|
|
132
|
-
export type { AsyncCleanupFn, AsyncIdQueueCloseOptions, AsyncIdQueueOptions, AsyncIteratorClassNextFn,
|
|
116
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator, getOrBind, getPackageSymbol, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
|
|
117
|
+
export type { AsyncCleanupFn, AsyncIdQueueCloseOptions, AsyncIdQueueOptions, AsyncIteratorClassNextFn, GetOrBindOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
|
|
2
2
|
|
|
3
3
|
declare const PACKAGE_NAME = "@standardserver/shared";
|
|
4
|
-
declare const PACKAGE_VERSION = "0.0.
|
|
4
|
+
declare const PACKAGE_VERSION = "0.0.4";
|
|
5
5
|
/**
|
|
6
6
|
* Generates a unique symbol for the specified name within the package scope.
|
|
7
7
|
* The symbol is globally registered using `Symbol.for` to ensure consistency across modules.
|
|
@@ -67,30 +67,15 @@ declare function stringifyJSON<T>(value: T | {
|
|
|
67
67
|
*/
|
|
68
68
|
declare function isTypescriptObject(maybeObject: unknown): maybeObject is object;
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
get(target: T, p: PropertyKey, receiver: any, fallback: () => any): any;
|
|
70
|
+
interface GetOrBindOptions {
|
|
71
|
+
/**
|
|
72
|
+
* Whether to bind the function to the target before returning it.
|
|
73
|
+
*
|
|
74
|
+
* @default true
|
|
75
|
+
*/
|
|
76
|
+
bind?: boolean;
|
|
78
77
|
}
|
|
79
|
-
|
|
80
|
-
* Creates a Proxy that enhances the standard `get` trap by providing:
|
|
81
|
-
*
|
|
82
|
-
* - A `fallback` function that:
|
|
83
|
-
* - Reads the property directly from the target
|
|
84
|
-
* - Automatically binds methods to the target
|
|
85
|
-
* - Caches bound methods for stable identity
|
|
86
|
-
* - An internal symbol that allows accessing the original target
|
|
87
|
-
*/
|
|
88
|
-
declare function createEnhancedProxy<T extends object>(target: T, handler: EnhancedProxyHandler<T>): T;
|
|
89
|
-
/**
|
|
90
|
-
* Returns the underlying target of an enhanced proxy.
|
|
91
|
-
* If the given value is not an enhanced proxy, it is returned as-is.
|
|
92
|
-
*/
|
|
93
|
-
declare function getEnhancedProxyTarget<T extends object>(value: T): T;
|
|
78
|
+
declare function getOrBind<T extends object, K extends PropertyKey>(target: T, property: K, { bind }?: GetOrBindOptions): K extends keyof T ? T[K] : unknown;
|
|
94
79
|
|
|
95
80
|
interface AsyncIdQueueCloseOptions {
|
|
96
81
|
id?: string;
|
|
@@ -128,5 +113,5 @@ declare function sleep(ms: number): Promise<void>;
|
|
|
128
113
|
|
|
129
114
|
declare function tryDecodeURIComponent(value: string): string;
|
|
130
115
|
|
|
131
|
-
export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator,
|
|
132
|
-
export type { AsyncCleanupFn, AsyncIdQueueCloseOptions, AsyncIdQueueOptions, AsyncIteratorClassNextFn,
|
|
116
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator, getOrBind, getPackageSymbol, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
|
|
117
|
+
export type { AsyncCleanupFn, AsyncIdQueueCloseOptions, AsyncIdQueueOptions, AsyncIteratorClassNextFn, GetOrBindOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ function toArray(value) {
|
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
const PACKAGE_NAME = "@standardserver/shared";
|
|
6
|
-
const PACKAGE_VERSION = "0.0.
|
|
6
|
+
const PACKAGE_VERSION = "0.0.4";
|
|
7
7
|
function getPackageSymbol(name) {
|
|
8
8
|
return Symbol.for(`${PACKAGE_NAME}@${PACKAGE_VERSION}/${name}`);
|
|
9
9
|
}
|
|
@@ -119,33 +119,21 @@ function isTypescriptObject(maybeObject) {
|
|
|
119
119
|
return type === "object" || type === "function";
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
const
|
|
123
|
-
function
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (cached) {
|
|
138
|
-
return cached;
|
|
139
|
-
}
|
|
140
|
-
const bound = value.bind(target2);
|
|
141
|
-
boundMethodCache.set(value, bound);
|
|
142
|
-
return bound;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
function getEnhancedProxyTarget(value) {
|
|
148
|
-
return value[ENHANCED_PROXY_TARGET_SYMBOL] ?? value;
|
|
122
|
+
const GET_OR_BIND_CACHE = /* @__PURE__ */ new WeakMap();
|
|
123
|
+
function getOrBind(target, property, { bind = true } = {}) {
|
|
124
|
+
const value = Reflect.get(target, property);
|
|
125
|
+
if (!bind || typeof value !== "function") {
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
let targetCache = GET_OR_BIND_CACHE.get(value);
|
|
129
|
+
if (!targetCache) {
|
|
130
|
+
GET_OR_BIND_CACHE.set(value, targetCache = /* @__PURE__ */ new WeakMap());
|
|
131
|
+
}
|
|
132
|
+
let bound = targetCache.get(target);
|
|
133
|
+
if (!bound) {
|
|
134
|
+
targetCache.set(target, bound = value.bind(target));
|
|
135
|
+
}
|
|
136
|
+
return bound;
|
|
149
137
|
}
|
|
150
138
|
|
|
151
139
|
class AsyncIdQueue {
|
|
@@ -250,4 +238,4 @@ function tryDecodeURIComponent(value) {
|
|
|
250
238
|
}
|
|
251
239
|
}
|
|
252
240
|
|
|
253
|
-
export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator,
|
|
241
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator, getOrBind, getPackageSymbol, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
|