@standardserver/shared 0.0.1 → 0.0.3
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 +4 -27
- package/dist/index.d.ts +4 -27
- package/dist/index.mjs +20 -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.3";
|
|
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,7 @@ declare function stringifyJSON<T>(value: T | {
|
|
|
67
67
|
*/
|
|
68
68
|
declare function isTypescriptObject(maybeObject: unknown): maybeObject is object;
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
* A ProxyHandler whose `get` trap receives an additional `fallback` function.
|
|
72
|
-
*
|
|
73
|
-
* The `fallback` returns the default property value as if no proxy
|
|
74
|
-
* interception occurred, and automatically binds methods to the target.
|
|
75
|
-
*/
|
|
76
|
-
interface EnhancedProxyHandler<T extends object> extends Omit<ProxyHandler<T>, 'get'> {
|
|
77
|
-
get(target: T, p: PropertyKey, receiver: any, fallback: () => any): any;
|
|
78
|
-
}
|
|
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;
|
|
70
|
+
declare function getOrBind<T extends object, K extends PropertyKey>(target: T, property: K): K extends keyof T ? T[K] : unknown;
|
|
94
71
|
|
|
95
72
|
interface AsyncIdQueueCloseOptions {
|
|
96
73
|
id?: string;
|
|
@@ -128,5 +105,5 @@ declare function sleep(ms: number): Promise<void>;
|
|
|
128
105
|
|
|
129
106
|
declare function tryDecodeURIComponent(value: string): string;
|
|
130
107
|
|
|
131
|
-
export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator,
|
|
132
|
-
export type { AsyncCleanupFn, AsyncIdQueueCloseOptions, AsyncIdQueueOptions, AsyncIteratorClassNextFn
|
|
108
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator, getOrBind, getPackageSymbol, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
|
|
109
|
+
export type { AsyncCleanupFn, AsyncIdQueueCloseOptions, AsyncIdQueueOptions, AsyncIteratorClassNextFn };
|
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.3";
|
|
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,7 @@ declare function stringifyJSON<T>(value: T | {
|
|
|
67
67
|
*/
|
|
68
68
|
declare function isTypescriptObject(maybeObject: unknown): maybeObject is object;
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
* A ProxyHandler whose `get` trap receives an additional `fallback` function.
|
|
72
|
-
*
|
|
73
|
-
* The `fallback` returns the default property value as if no proxy
|
|
74
|
-
* interception occurred, and automatically binds methods to the target.
|
|
75
|
-
*/
|
|
76
|
-
interface EnhancedProxyHandler<T extends object> extends Omit<ProxyHandler<T>, 'get'> {
|
|
77
|
-
get(target: T, p: PropertyKey, receiver: any, fallback: () => any): any;
|
|
78
|
-
}
|
|
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;
|
|
70
|
+
declare function getOrBind<T extends object, K extends PropertyKey>(target: T, property: K): K extends keyof T ? T[K] : unknown;
|
|
94
71
|
|
|
95
72
|
interface AsyncIdQueueCloseOptions {
|
|
96
73
|
id?: string;
|
|
@@ -128,5 +105,5 @@ declare function sleep(ms: number): Promise<void>;
|
|
|
128
105
|
|
|
129
106
|
declare function tryDecodeURIComponent(value: string): string;
|
|
130
107
|
|
|
131
|
-
export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator,
|
|
132
|
-
export type { AsyncCleanupFn, AsyncIdQueueCloseOptions, AsyncIdQueueOptions, AsyncIteratorClassNextFn
|
|
108
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator, getOrBind, getPackageSymbol, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
|
|
109
|
+
export type { AsyncCleanupFn, AsyncIdQueueCloseOptions, AsyncIdQueueOptions, AsyncIteratorClassNextFn };
|
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.3";
|
|
7
7
|
function getPackageSymbol(name) {
|
|
8
8
|
return Symbol.for(`${PACKAGE_NAME}@${PACKAGE_VERSION}/${name}`);
|
|
9
9
|
}
|
|
@@ -119,33 +119,24 @@ 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
|
-
|
|
138
|
-
|
|
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) {
|
|
124
|
+
const value = Reflect.get(target, property);
|
|
125
|
+
if (typeof value !== "function") {
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
let cache = GET_OR_BIND_CACHE.get(target);
|
|
129
|
+
if (!cache) {
|
|
130
|
+
cache = /* @__PURE__ */ new WeakMap();
|
|
131
|
+
GET_OR_BIND_CACHE.set(target, cache);
|
|
132
|
+
}
|
|
133
|
+
const cached = cache.get(value);
|
|
134
|
+
if (cached) {
|
|
135
|
+
return cached;
|
|
136
|
+
}
|
|
137
|
+
const bound = value.bind(target);
|
|
138
|
+
cache.set(value, bound);
|
|
139
|
+
return bound;
|
|
149
140
|
}
|
|
150
141
|
|
|
151
142
|
class AsyncIdQueue {
|
|
@@ -250,4 +241,4 @@ function tryDecodeURIComponent(value) {
|
|
|
250
241
|
}
|
|
251
242
|
}
|
|
252
243
|
|
|
253
|
-
export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator,
|
|
244
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator, getOrBind, getPackageSymbol, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
|