@orpc/shared 2.0.0-beta.48 → 2.0.0-beta.49
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/README.md +4 -4
- package/dist/args.js +3 -0
- package/dist/array.js +7 -0
- package/dist/bigint.d.ts +9 -0
- package/dist/bigint.js +19 -0
- package/dist/buffer.d.ts +18 -0
- package/dist/buffer.js +77 -0
- package/dist/compare.js +45 -0
- package/dist/consts.js +1 -0
- package/dist/error.js +3 -0
- package/dist/{function.d.mts → function.d.ts} +5 -5
- package/dist/function.js +38 -0
- package/dist/{http.d.mts → http.d.ts} +16 -16
- package/dist/http.js +113 -0
- package/dist/id.d.ts +8 -0
- package/dist/id.js +13 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +32 -0
- package/dist/interceptor.d.ts +60 -0
- package/dist/interceptor.js +139 -0
- package/dist/iterator.d.ts +56 -0
- package/dist/iterator.js +157 -0
- package/dist/object.d.ts +60 -0
- package/dist/object.js +245 -0
- package/dist/plugin.d.ts +12 -0
- package/dist/plugin.js +61 -0
- package/dist/promise.d.ts +17 -0
- package/dist/promise.js +32 -0
- package/dist/proxy.d.ts +12 -0
- package/dist/proxy.js +24 -0
- package/dist/queue.d.ts +16 -0
- package/dist/queue.js +79 -0
- package/dist/signal.d.ts +18 -0
- package/dist/signal.js +85 -0
- package/dist/stream.d.ts +48 -0
- package/dist/stream.js +155 -0
- package/dist/tracing.d.ts +73 -0
- package/dist/tracing.js +94 -0
- package/dist/types.d.ts +26 -0
- package/dist/value.d.ts +2 -0
- package/dist/value.js +6 -0
- package/package.json +16 -18
- package/dist/args.mjs +0 -3
- package/dist/array.mjs +0 -7
- package/dist/bigint.d.mts +0 -9
- package/dist/bigint.mjs +0 -12
- package/dist/buffer.d.mts +0 -18
- package/dist/buffer.mjs +0 -66
- package/dist/compare.mjs +0 -43
- package/dist/consts.mjs +0 -1
- package/dist/error.mjs +0 -3
- package/dist/function.mjs +0 -31
- package/dist/http.mjs +0 -83
- package/dist/id.d.mts +0 -8
- package/dist/id.mjs +0 -7
- package/dist/index.d.mts +0 -25
- package/dist/index.mjs +0 -23
- package/dist/interceptor.d.mts +0 -96
- package/dist/interceptor.mjs +0 -102
- package/dist/iterator.d.mts +0 -82
- package/dist/iterator.mjs +0 -151
- package/dist/object.d.mts +0 -64
- package/dist/object.mjs +0 -221
- package/dist/plugin.d.mts +0 -12
- package/dist/plugin.mjs +0 -58
- package/dist/promise.d.mts +0 -17
- package/dist/promise.mjs +0 -23
- package/dist/proxy.d.mts +0 -15
- package/dist/proxy.mjs +0 -15
- package/dist/queue.d.mts +0 -16
- package/dist/queue.mjs +0 -74
- package/dist/signal.d.mts +0 -13
- package/dist/signal.mjs +0 -74
- package/dist/stream.d.mts +0 -54
- package/dist/stream.mjs +0 -138
- package/dist/tracing.d.mts +0 -73
- package/dist/tracing.mjs +0 -89
- package/dist/types.d.mts +0 -32
- package/dist/value.d.mts +0 -8
- package/dist/value.mjs +0 -6
- /package/dist/{args.d.mts → args.d.ts} +0 -0
- /package/dist/{array.d.mts → array.d.ts} +0 -0
- /package/dist/{compare.d.mts → compare.d.ts} +0 -0
- /package/dist/{consts.d.mts → consts.d.ts} +0 -0
- /package/dist/{error.d.mts → error.d.ts} +0 -0
- /package/dist/{types.mjs → types.js} +0 -0
package/dist/interceptor.mjs
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { isAsyncIteratorObject } from "@standard-server/shared";
|
|
2
|
-
import { wrapAsyncIterator } from "./iterator.mjs";
|
|
3
|
-
import { override } from "./proxy.mjs";
|
|
4
|
-
import { wrapReadableStream } from "./stream.mjs";
|
|
5
|
-
|
|
6
|
-
export function onStart(callback) {
|
|
7
|
-
return async (options, ...rest) => {
|
|
8
|
-
await callback(options, ...rest);
|
|
9
|
-
return await options.next();
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function onSuccess(callback) {
|
|
14
|
-
return async (options, ...rest) => {
|
|
15
|
-
const result = await options.next();
|
|
16
|
-
await callback(result, options, ...rest);
|
|
17
|
-
return result;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function onError(callback) {
|
|
22
|
-
return async (options, ...rest) => {
|
|
23
|
-
try {
|
|
24
|
-
return await options.next();
|
|
25
|
-
} catch (error) {
|
|
26
|
-
await callback(error, options, ...rest);
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function onFinish(callback) {
|
|
33
|
-
return async (options, ...rest) => {
|
|
34
|
-
let state;
|
|
35
|
-
try {
|
|
36
|
-
const result = await options.next();
|
|
37
|
-
state = [
|
|
38
|
-
null,
|
|
39
|
-
result,
|
|
40
|
-
true
|
|
41
|
-
];
|
|
42
|
-
return result;
|
|
43
|
-
} catch (error) {
|
|
44
|
-
state = [
|
|
45
|
-
error,
|
|
46
|
-
undefined,
|
|
47
|
-
false
|
|
48
|
-
];
|
|
49
|
-
throw error;
|
|
50
|
-
} finally {
|
|
51
|
-
await callback(state, options, ...rest);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function onAsyncIteratorObjectError(callback) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return async (options, ...rest) => {
|
|
63
|
-
const output = await options.next();
|
|
64
|
-
if (!isAsyncIteratorObject(output)) {
|
|
65
|
-
return output;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return override(output, wrapAsyncIterator(output, { onError: (error) => callback(error, options, ...rest) }));
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function onReadableStreamError(callback) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return async (options, ...rest) => {
|
|
79
|
-
const output = await options.next();
|
|
80
|
-
if (!(output instanceof ReadableStream)) {
|
|
81
|
-
return output;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return override(output, wrapReadableStream(output, { onError: (error) => callback(error, options, ...rest) }));
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
export function intercept(interceptors, options, main) {
|
|
88
|
-
if (!interceptors?.length) {
|
|
89
|
-
return main(options);
|
|
90
|
-
}
|
|
91
|
-
const next = (options, index) => {
|
|
92
|
-
const interceptor = interceptors[index];
|
|
93
|
-
if (!interceptor) {
|
|
94
|
-
return main(options);
|
|
95
|
-
}
|
|
96
|
-
return interceptor({
|
|
97
|
-
...options,
|
|
98
|
-
next: (newOptions = options) => next(newOptions, index + 1)
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
return next(options, 0);
|
|
102
|
-
}
|
package/dist/iterator.d.mts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from "type-fest";
|
|
2
|
-
import type { StartSpanOptions } from "./tracing.mjs";
|
|
3
|
-
import type { PromiseWithError, ThrowableError } from "./types.mjs";
|
|
4
|
-
import { AsyncIteratorClass } from "@standard-server/shared";
|
|
5
|
-
export interface WrapAsyncIteratorOptions<
|
|
6
|
-
TYield,
|
|
7
|
-
TReturn,
|
|
8
|
-
TMappedYield,
|
|
9
|
-
TMappedReturn
|
|
10
|
-
> {
|
|
11
|
-
/**
|
|
12
|
-
* Any call to the original iterator will be executed inside this function.
|
|
13
|
-
* Useful when you want execution to happen within a specific context,
|
|
14
|
-
* such as AsyncLocalStorage.
|
|
15
|
-
*/
|
|
16
|
-
runWith?: (<T>(run: () => Promise<T>) => Promisable<T>) | undefined;
|
|
17
|
-
mapResult?: ((result: IteratorResult<TYield, TReturn>) => Promisable<IteratorResult<TMappedYield, TMappedReturn>>) | undefined;
|
|
18
|
-
mapError?: ((error: ThrowableError) => Promisable<ThrowableError>) | undefined;
|
|
19
|
-
onError?: ((error: ThrowableError) => Promisable<void>) | undefined;
|
|
20
|
-
/**
|
|
21
|
-
* Execute after the stream finishes or is cancelled.
|
|
22
|
-
*/
|
|
23
|
-
onFinish?: (() => Promisable<void>) | undefined;
|
|
24
|
-
}
|
|
25
|
-
export declare function wrapAsyncIterator<
|
|
26
|
-
TYield,
|
|
27
|
-
TReturn,
|
|
28
|
-
TMappedYield = TYield,
|
|
29
|
-
TMappedReturn = TReturn
|
|
30
|
-
>(iterator: AsyncIterator<TYield, TReturn>, { runWith, mapResult, mapError, onError, onFinish }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): NoInfer<AsyncIteratorClass<TMappedYield, TMappedReturn>>;
|
|
31
|
-
export declare function traceAsyncIterator<
|
|
32
|
-
T,
|
|
33
|
-
TReturn,
|
|
34
|
-
TNext
|
|
35
|
-
>(options: StartSpanOptions | string, iterator: AsyncIterator<T, TReturn, TNext>): AsyncIteratorClass<T, TReturn, TNext>;
|
|
36
|
-
export declare function replicateAsyncIterator<
|
|
37
|
-
T,
|
|
38
|
-
TReturn,
|
|
39
|
-
TNext
|
|
40
|
-
>(source: AsyncIterator<T, TReturn, TNext>, count: number): AsyncIteratorClass<T, TReturn, TNext>[];
|
|
41
|
-
export interface ConsumeAsyncIteratorOptions<
|
|
42
|
-
T,
|
|
43
|
-
TReturn,
|
|
44
|
-
TError
|
|
45
|
-
> {
|
|
46
|
-
/**
|
|
47
|
-
* Called on each event
|
|
48
|
-
*/
|
|
49
|
-
onEvent: (event: T) => void;
|
|
50
|
-
/**
|
|
51
|
-
* Called once error happens
|
|
52
|
-
*/
|
|
53
|
-
onError?: ((error: TError) => void) | undefined;
|
|
54
|
-
/**
|
|
55
|
-
* Called once AsyncIteratorObject is done
|
|
56
|
-
*
|
|
57
|
-
* @remarks
|
|
58
|
-
* **Note**: If iterator is canceled, `undefined` can be passed on success
|
|
59
|
-
*/
|
|
60
|
-
onSuccess?: ((value: TReturn | undefined) => void) | undefined;
|
|
61
|
-
/**
|
|
62
|
-
* Called once after onError or onSuccess
|
|
63
|
-
*
|
|
64
|
-
* @remarks
|
|
65
|
-
* **Note**: If iterator is canceled, `undefined` can be passed on success
|
|
66
|
-
*/
|
|
67
|
-
onFinish?: ((state: [error: TError, data: undefined, isSuccess: false] | [error: null, data: TReturn | undefined, isSuccess: true]) => void) | undefined;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Consumes an AsyncIteratorObject with lifecycle callbacks.
|
|
71
|
-
*
|
|
72
|
-
* @remarks
|
|
73
|
-
* **Warning**: If no `onError` or `onFinish` is provided, errors are thrown into the unhandled rejection channel.
|
|
74
|
-
*
|
|
75
|
-
* @returns An unsubscribe callback that stops consuming and cleans up the iterator.
|
|
76
|
-
* @see {@link https://orpc.dev/docs/client/async-iterator-object#using-consumeasynciterator | AsyncIteratorObject in Client - Using consumeAsyncIterator}
|
|
77
|
-
*/
|
|
78
|
-
export declare function consumeAsyncIterator<
|
|
79
|
-
T,
|
|
80
|
-
TReturn,
|
|
81
|
-
TError = ThrowableError
|
|
82
|
-
>(iterator: AsyncIterator<T, TReturn> | PromiseWithError<AsyncIterator<T, TReturn>, TError>, options: ConsumeAsyncIteratorOptions<T, TReturn, TError | ThrowableError>): () => Promise<void>;
|
package/dist/iterator.mjs
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { AsyncIteratorClass } from "@standard-server/shared";
|
|
2
|
-
import { once } from "./function.mjs";
|
|
3
|
-
import { AsyncIdQueue } from "./queue.mjs";
|
|
4
|
-
import { recordSpanError, runInSpanContext, startSpan } from "./tracing.mjs";
|
|
5
|
-
export function wrapAsyncIterator(iterator, { runWith, mapResult, mapError, onError, onFinish }) {
|
|
6
|
-
runWith ??= (run) => run();
|
|
7
|
-
let isDone;
|
|
8
|
-
return new AsyncIteratorClass(async () => {
|
|
9
|
-
try {
|
|
10
|
-
let result;
|
|
11
|
-
try {
|
|
12
|
-
result = await runWith(() => iterator.next());
|
|
13
|
-
isDone = result.done;
|
|
14
|
-
} catch (error) {
|
|
15
|
-
isDone = true;
|
|
16
|
-
throw error;
|
|
17
|
-
}
|
|
18
|
-
return mapResult ? await mapResult(result) : result;
|
|
19
|
-
} catch (error) {
|
|
20
|
-
await onError?.(error);
|
|
21
|
-
throw mapError ? await mapError(error) : error;
|
|
22
|
-
}
|
|
23
|
-
}, async (_state) => {
|
|
24
|
-
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (!isDone) {
|
|
28
|
-
try {
|
|
29
|
-
await runWith(async () => iterator.return?.());
|
|
30
|
-
} catch (error) {
|
|
31
|
-
await onError?.(error);
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
} finally {
|
|
36
|
-
await onFinish?.();
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
export function traceAsyncIterator(options, iterator) {
|
|
41
|
-
const getSpan = once(() => startSpan(options));
|
|
42
|
-
return wrapAsyncIterator(iterator, {
|
|
43
|
-
runWith: (run) => runInSpanContext(getSpan(), run),
|
|
44
|
-
mapResult(result) {
|
|
45
|
-
getSpan()?.addEvent(result.done ? "completed" : "yielded");
|
|
46
|
-
return result;
|
|
47
|
-
},
|
|
48
|
-
onError(error) {
|
|
49
|
-
recordSpanError(getSpan(), error);
|
|
50
|
-
},
|
|
51
|
-
onFinish() {
|
|
52
|
-
getSpan()?.end();
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
export function replicateAsyncIterator(source, count) {
|
|
57
|
-
const queue = new AsyncIdQueue();
|
|
58
|
-
const ids = Array.from({ length: count }, (_, i) => i.toString());
|
|
59
|
-
let isSourceFinished = false;
|
|
60
|
-
const start = once(async () => {
|
|
61
|
-
try {
|
|
62
|
-
while (true) {
|
|
63
|
-
const item = await source.next();
|
|
64
|
-
ids.forEach((id) => {
|
|
65
|
-
if (queue.isOpen(id)) {
|
|
66
|
-
queue.push(id, { next: item });
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
if (item.done) {
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
} catch (error) {
|
|
74
|
-
ids.forEach((id) => {
|
|
75
|
-
if (queue.isOpen(id)) {
|
|
76
|
-
queue.push(id, { error });
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
} finally {
|
|
80
|
-
isSourceFinished = true;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
const replicated = ids.map((id) => {
|
|
84
|
-
queue.open(id);
|
|
85
|
-
return new AsyncIteratorClass(async () => {
|
|
86
|
-
start();
|
|
87
|
-
const item = await queue.pull(id);
|
|
88
|
-
if (item.next) {
|
|
89
|
-
return item.next;
|
|
90
|
-
}
|
|
91
|
-
throw item.error;
|
|
92
|
-
}, async ({ kind, error }) => {
|
|
93
|
-
queue.close({
|
|
94
|
-
id,
|
|
95
|
-
reason: error
|
|
96
|
-
});
|
|
97
|
-
if (kind === "cancelled" && !queue.size && !isSourceFinished) {
|
|
98
|
-
isSourceFinished = true;
|
|
99
|
-
await source?.return?.();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
return replicated;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function consumeAsyncIterator(iterator, options) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
void (async () => {
|
|
113
|
-
let onFinishState;
|
|
114
|
-
try {
|
|
115
|
-
const resolvedIterator = await iterator;
|
|
116
|
-
while (true) {
|
|
117
|
-
const { done, value } = await resolvedIterator.next();
|
|
118
|
-
if (done) {
|
|
119
|
-
|
|
120
|
-
const realValue = value;
|
|
121
|
-
onFinishState = [
|
|
122
|
-
null,
|
|
123
|
-
realValue,
|
|
124
|
-
true
|
|
125
|
-
];
|
|
126
|
-
options.onSuccess?.(realValue);
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
options.onEvent(value);
|
|
131
|
-
} catch (error) {
|
|
132
|
-
|
|
133
|
-
await resolvedIterator.return?.();
|
|
134
|
-
throw error;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
} catch (error) {
|
|
138
|
-
onFinishState = [
|
|
139
|
-
error,
|
|
140
|
-
undefined,
|
|
141
|
-
false
|
|
142
|
-
];
|
|
143
|
-
options.onError?.(error);
|
|
144
|
-
} finally {
|
|
145
|
-
options.onFinish?.(onFinishState);
|
|
146
|
-
}
|
|
147
|
-
})();
|
|
148
|
-
return async () => {
|
|
149
|
-
await (await iterator)?.return?.();
|
|
150
|
-
};
|
|
151
|
-
}
|
package/dist/object.d.mts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { AnyFunction } from "./function.mjs";
|
|
2
|
-
export type Segment = string | number;
|
|
3
|
-
export declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
4
|
-
maps: Segment[][];
|
|
5
|
-
values: unknown[];
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Get constructor of the value
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
export declare function getConstructor(value: unknown): Function | null | undefined;
|
|
12
|
-
export declare function getConstructors(value: unknown): Generator<Function>;
|
|
13
|
-
/**
|
|
14
|
-
* Checks whether a value is a plain object, including objects created with
|
|
15
|
-
* `Object.create(null)`.
|
|
16
|
-
*/
|
|
17
|
-
export declare function isPlainObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
18
|
-
/**
|
|
19
|
-
* Returns `object[key]` only when it is an own property, so keys like
|
|
20
|
-
* `toString` do not resolve through the prototype chain.
|
|
21
|
-
*/
|
|
22
|
-
export declare function getOwn<T extends object>(object: T, key: PropertyKey): T[keyof T] | undefined;
|
|
23
|
-
export declare function get(object: unknown, path: readonly PropertyKey[]): unknown;
|
|
24
|
-
/**
|
|
25
|
-
* Sets a value at the given path, creating plain objects for intermediate keys as needed.
|
|
26
|
-
*/
|
|
27
|
-
export declare function set(root: object, path: [PropertyKey, ...PropertyKey[]] | [...PropertyKey[], PropertyKey], value: unknown): void;
|
|
28
|
-
/**
|
|
29
|
-
* Sets `object[key]`, defining `__proto__` as an own property instead of re-parenting the object.
|
|
30
|
-
*/
|
|
31
|
-
export declare function setOwn(object: object, key: PropertyKey, value: unknown): void;
|
|
32
|
-
/**
|
|
33
|
-
* Merges two values by copying the second over the first, repeating the merge one level deeper for
|
|
34
|
-
* nested plain objects. Anything that is not a pair of plain objects is replaced by the second one.
|
|
35
|
-
*/
|
|
36
|
-
export declare function mergeTwoLevels(first: unknown, second: unknown): unknown;
|
|
37
|
-
export declare function omit<
|
|
38
|
-
T extends object,
|
|
39
|
-
K extends keyof T
|
|
40
|
-
>(obj: T, keys: readonly K[]): Omit<T, K>;
|
|
41
|
-
export declare function pick<
|
|
42
|
-
T extends object,
|
|
43
|
-
K extends keyof T
|
|
44
|
-
>(obj: T, keys: readonly K[]): Pick<T, K>;
|
|
45
|
-
/**
|
|
46
|
-
* Deep clones arrays and plain objects, leaving every other value as is.
|
|
47
|
-
* Circular and shared references are preserved in the copy.
|
|
48
|
-
*/
|
|
49
|
-
export declare function clone<T>(value: T): T;
|
|
50
|
-
export declare function copyOnWrite(parent: object, key: PropertyKey, original: unknown): unknown;
|
|
51
|
-
export declare function isPropertyKey(value: unknown): value is PropertyKey;
|
|
52
|
-
export declare const NullProtoObj: {
|
|
53
|
-
new <T extends Record<PropertyKey, unknown>>(): T;
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Returns an object containing all methods of the given object, with each
|
|
57
|
-
* method bound to the original object instance.
|
|
58
|
-
*
|
|
59
|
-
* Methods are collected from both the object itself and its prototype chain
|
|
60
|
-
* (excluding `Object.prototype` and the `constructor` property).
|
|
61
|
-
*/
|
|
62
|
-
export declare function bindMethods<T extends object>(obj: T, options?: {
|
|
63
|
-
unbound?: (keyof T)[];
|
|
64
|
-
}): Pick<T, { [K in keyof T]: T[K] extends AnyFunction ? K : never }[keyof T]>;
|
package/dist/object.mjs
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { getOrBind, isTypescriptObject } from "@standard-server/shared";
|
|
2
|
-
export function findDeepMatches(check, payload, segments = [], maps = [], values = []) {
|
|
3
|
-
if (check(payload)) {
|
|
4
|
-
maps.push(segments);
|
|
5
|
-
values.push(payload);
|
|
6
|
-
} else if (Array.isArray(payload)) {
|
|
7
|
-
payload.forEach((v, i) => {
|
|
8
|
-
findDeepMatches(check, v, [...segments, i], maps, values);
|
|
9
|
-
});
|
|
10
|
-
} else if (isPlainObject(payload)) {
|
|
11
|
-
for (const key of Object.keys(payload)) {
|
|
12
|
-
findDeepMatches(check, payload[key], [...segments, key], maps, values);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return {
|
|
16
|
-
maps,
|
|
17
|
-
values
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function getConstructor(value) {
|
|
22
|
-
|
|
23
|
-
if (!isTypescriptObject(value)) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
return Object.getPrototypeOf(value)?.constructor;
|
|
27
|
-
}
|
|
28
|
-
export function* getConstructors(value) {
|
|
29
|
-
if (!isTypescriptObject(value)) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
let proto = Object.getPrototypeOf(value);
|
|
33
|
-
while (proto != null) {
|
|
34
|
-
if (proto.constructor) {
|
|
35
|
-
yield proto.constructor;
|
|
36
|
-
}
|
|
37
|
-
proto = Object.getPrototypeOf(proto);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function isPlainObject(value) {
|
|
42
|
-
if (!value || typeof value !== "object") {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
const proto = Object.getPrototypeOf(value);
|
|
46
|
-
return proto === Object.prototype || !proto || !proto.constructor;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function getOwn(object, key) {
|
|
50
|
-
return Object.hasOwn(object, key) ? object[key] : undefined;
|
|
51
|
-
}
|
|
52
|
-
export function get(object, path) {
|
|
53
|
-
let current = object;
|
|
54
|
-
for (const key of path) {
|
|
55
|
-
if (!isTypescriptObject(current)) {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
current = getOwn(current, key);
|
|
59
|
-
}
|
|
60
|
-
return current;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function set(root, path, value) {
|
|
64
|
-
let current = root;
|
|
65
|
-
for (let i = 0; i < path.length - 1; i++) {
|
|
66
|
-
const key = path[i];
|
|
67
|
-
const next = getOwn(current, key);
|
|
68
|
-
if (!isTypescriptObject(next)) {
|
|
69
|
-
const child = {};
|
|
70
|
-
setOwn(current, key, child);
|
|
71
|
-
current = child;
|
|
72
|
-
} else {
|
|
73
|
-
current = next;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
setOwn(current, path.at(-1), value);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function setOwn(object, key, value) {
|
|
80
|
-
if (key === "__proto__") {
|
|
81
|
-
Object.defineProperty(object, key, {
|
|
82
|
-
value,
|
|
83
|
-
writable: true,
|
|
84
|
-
enumerable: true,
|
|
85
|
-
configurable: true
|
|
86
|
-
});
|
|
87
|
-
} else {
|
|
88
|
-
object[key] = value;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function mergeTwoLevels(first, second) {
|
|
93
|
-
if (!isPlainObject(first) || !isPlainObject(second)) {
|
|
94
|
-
return second;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const result = {
|
|
98
|
-
...first,
|
|
99
|
-
...second
|
|
100
|
-
};
|
|
101
|
-
for (const key of Object.keys(second)) {
|
|
102
|
-
if (!Object.hasOwn(first, key)) {
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
const firstValue = first[key];
|
|
106
|
-
const secondValue = second[key];
|
|
107
|
-
if (isPlainObject(firstValue) && isPlainObject(secondValue)) {
|
|
108
|
-
result[key] = {
|
|
109
|
-
...firstValue,
|
|
110
|
-
...secondValue
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
export function omit(obj, keys) {
|
|
117
|
-
const result = { ...obj };
|
|
118
|
-
for (const key of keys) {
|
|
119
|
-
delete result[key];
|
|
120
|
-
}
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
export function pick(obj, keys) {
|
|
124
|
-
const result = {};
|
|
125
|
-
for (const key of keys) {
|
|
126
|
-
if (Object.hasOwn(obj, key)) {
|
|
127
|
-
result[key] = obj[key];
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return result;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export function clone(value) {
|
|
134
|
-
return cloneWithVisited(value, new WeakMap());
|
|
135
|
-
}
|
|
136
|
-
function cloneWithVisited(value, visited) {
|
|
137
|
-
if (Array.isArray(value)) {
|
|
138
|
-
const existing = visited.get(value);
|
|
139
|
-
if (existing) {
|
|
140
|
-
return existing;
|
|
141
|
-
}
|
|
142
|
-
const result = [];
|
|
143
|
-
visited.set(value, result);
|
|
144
|
-
for (const item of value) {
|
|
145
|
-
result.push(cloneWithVisited(item, visited));
|
|
146
|
-
}
|
|
147
|
-
return result;
|
|
148
|
-
}
|
|
149
|
-
if (isPlainObject(value)) {
|
|
150
|
-
const existing = visited.get(value);
|
|
151
|
-
if (existing) {
|
|
152
|
-
return existing;
|
|
153
|
-
}
|
|
154
|
-
const result = {};
|
|
155
|
-
visited.set(value, result);
|
|
156
|
-
|
|
157
|
-
for (const key of Object.keys(value)) {
|
|
158
|
-
setOwn(result, key, cloneWithVisited(value[key], visited));
|
|
159
|
-
}
|
|
160
|
-
for (const sym of Object.getOwnPropertySymbols(value)) {
|
|
161
|
-
setOwn(result, sym, cloneWithVisited(value[sym], visited));
|
|
162
|
-
}
|
|
163
|
-
return result;
|
|
164
|
-
}
|
|
165
|
-
return value;
|
|
166
|
-
}
|
|
167
|
-
export function copyOnWrite(parent, key, original) {
|
|
168
|
-
const value = parent[key];
|
|
169
|
-
if (value !== original) {
|
|
170
|
-
return value;
|
|
171
|
-
}
|
|
172
|
-
let copy;
|
|
173
|
-
if (Array.isArray(value)) {
|
|
174
|
-
copy = value.slice();
|
|
175
|
-
} else if (isPlainObject(value)) {
|
|
176
|
-
copy = { ...value };
|
|
177
|
-
} else {
|
|
178
|
-
return value;
|
|
179
|
-
}
|
|
180
|
-
setOwn(parent, key, copy);
|
|
181
|
-
return copy;
|
|
182
|
-
}
|
|
183
|
-
export function isPropertyKey(value) {
|
|
184
|
-
const type = typeof value;
|
|
185
|
-
return type === "string" || type === "number" || type === "symbol";
|
|
186
|
-
}
|
|
187
|
-
export const NullProtoObj = /* @__PURE__ */ (() => {
|
|
188
|
-
const e = function() {};
|
|
189
|
-
e.prototype = Object.create(null);
|
|
190
|
-
Object.freeze(e.prototype);
|
|
191
|
-
return e;
|
|
192
|
-
})();
|
|
193
|
-
|
|
194
|
-
export function bindMethods(obj, options = {}) {
|
|
195
|
-
const unbound = new Set(options.unbound);
|
|
196
|
-
|
|
197
|
-
const methods = new NullProtoObj();
|
|
198
|
-
let current = obj;
|
|
199
|
-
while (current && current !== Object.prototype) {
|
|
200
|
-
for (const key of Object.getOwnPropertyNames(current)) {
|
|
201
|
-
if (key === "constructor" || key in methods) {
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
const val = getOrBind(obj, key, { bind: !unbound.has(key) });
|
|
205
|
-
if (typeof val === "function") {
|
|
206
|
-
methods[key] = val;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
for (const sym of Object.getOwnPropertySymbols(current)) {
|
|
210
|
-
if (sym in methods) {
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
const val = getOrBind(obj, sym, { bind: !unbound.has(sym) });
|
|
214
|
-
if (typeof val === "function") {
|
|
215
|
-
methods[sym] = val;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
current = Object.getPrototypeOf(current);
|
|
219
|
-
}
|
|
220
|
-
return methods;
|
|
221
|
-
}
|
package/dist/plugin.d.mts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface OrderablePlugin {
|
|
2
|
-
/** Unique name of the plugin, used for ordering and identification. */
|
|
3
|
-
name: string;
|
|
4
|
-
/** Plugins this plugin should execute before. */
|
|
5
|
-
before?: string[] | undefined;
|
|
6
|
-
/** Plugins this plugin should execute after. */
|
|
7
|
-
after?: string[] | undefined;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Sorts plugins based on their `before` and `after` dependencies.
|
|
11
|
-
*/
|
|
12
|
-
export declare function sortPlugins<T extends OrderablePlugin>(plugins: T[]): T[];
|
package/dist/plugin.mjs
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export function sortPlugins(plugins) {
|
|
3
|
-
const pluginCount = plugins.length;
|
|
4
|
-
const pluginIdToIndices = new Map();
|
|
5
|
-
for (let i = 0; i < pluginCount; i++) {
|
|
6
|
-
const plugin = plugins[i];
|
|
7
|
-
const indices = pluginIdToIndices.get(plugin.name);
|
|
8
|
-
if (indices === undefined) {
|
|
9
|
-
pluginIdToIndices.set(plugin.name, [i]);
|
|
10
|
-
} else {
|
|
11
|
-
indices.push(i);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
const dependencies = Array.from({ length: pluginCount }, () => []);
|
|
15
|
-
for (let i = 0; i < pluginCount; i++) {
|
|
16
|
-
const plugin = plugins[i];
|
|
17
|
-
if (plugin.before !== undefined) {
|
|
18
|
-
for (const beforeId of plugin.before) {
|
|
19
|
-
const beforeIndices = pluginIdToIndices.get(beforeId);
|
|
20
|
-
if (beforeIndices !== undefined) {
|
|
21
|
-
for (const beforeIndex of beforeIndices) {
|
|
22
|
-
dependencies[beforeIndex].push(i);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (plugin.after !== undefined) {
|
|
28
|
-
for (const afterId of plugin.after) {
|
|
29
|
-
const afterIndices = pluginIdToIndices.get(afterId);
|
|
30
|
-
if (afterIndices !== undefined) {
|
|
31
|
-
for (const afterIndex of afterIndices) {
|
|
32
|
-
dependencies[i].push(afterIndex);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const sorted = [];
|
|
39
|
-
const placed = new Set();
|
|
40
|
-
while (sorted.length < pluginCount) {
|
|
41
|
-
const next = plugins.findIndex((_, i) => !placed.has(i) && dependencies[i].every((dependency) => placed.has(dependency)));
|
|
42
|
-
if (next === -1) {
|
|
43
|
-
throw new Error(`Circular dependency detected involving plugin "${findCyclicPlugin(plugins, dependencies, placed).name}"`);
|
|
44
|
-
}
|
|
45
|
-
placed.add(next);
|
|
46
|
-
sorted.push(plugins[next]);
|
|
47
|
-
}
|
|
48
|
-
return sorted;
|
|
49
|
-
}
|
|
50
|
-
function findCyclicPlugin(plugins, dependencies, placed) {
|
|
51
|
-
const seen = new Set();
|
|
52
|
-
let current = plugins.findIndex((_, i) => !placed.has(i));
|
|
53
|
-
while (!seen.has(current)) {
|
|
54
|
-
seen.add(current);
|
|
55
|
-
current = dependencies[current].find((dependency) => !placed.has(dependency));
|
|
56
|
-
}
|
|
57
|
-
return plugins[current];
|
|
58
|
-
}
|
package/dist/promise.d.mts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a promise together with its associated `resolve` and `reject`
|
|
3
|
-
* functions.
|
|
4
|
-
*
|
|
5
|
-
* Equivalent to `Promise.withResolvers()`, but works in environments
|
|
6
|
-
* where that API is not yet available.
|
|
7
|
-
*/
|
|
8
|
-
export declare function promiseWithResolvers<T>(): {
|
|
9
|
-
promise: Promise<T>;
|
|
10
|
-
resolve: (v: T) => void;
|
|
11
|
-
reject: (reason: unknown) => void;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Captures the current async context (such as AsyncLocalStorage) through a promise reaction, so no runtime API is needed.
|
|
15
|
-
* The returned function runs a callback inside it once; later calls reject.
|
|
16
|
-
*/
|
|
17
|
-
export declare function captureAsyncContext(): <T>(callback: () => Promise<T>) => Promise<T>;
|