@orpc/shared 0.0.0-next.31590a1 → 0.0.0-next.32cb70c
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.js +2 -75
- package/dist/src/function.d.ts +0 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/object.d.ts +1 -1
- package/package.json +1 -1
- package/dist/src/interceptor.d.ts +0 -47
package/dist/index.js
CHANGED
|
@@ -22,19 +22,6 @@ function toError(error) {
|
|
|
22
22
|
return new Error("Unknown error", { cause: error });
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
// src/function.ts
|
|
26
|
-
function once(fn) {
|
|
27
|
-
let cached;
|
|
28
|
-
return () => {
|
|
29
|
-
if (cached) {
|
|
30
|
-
return cached.result;
|
|
31
|
-
}
|
|
32
|
-
const result = fn();
|
|
33
|
-
cached = { result };
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
25
|
// src/hook.ts
|
|
39
26
|
async function executeWithHooks(options) {
|
|
40
27
|
const interceptors = convertToArray(options.hooks?.interceptor);
|
|
@@ -54,8 +41,8 @@ async function executeWithHooks(options) {
|
|
|
54
41
|
}
|
|
55
42
|
let state = { status: "pending", input: options.input, output: void 0, error: void 0 };
|
|
56
43
|
try {
|
|
57
|
-
for (const
|
|
58
|
-
await
|
|
44
|
+
for (const onStart of onStarts) {
|
|
45
|
+
await onStart(state, options.context, options.meta);
|
|
59
46
|
}
|
|
60
47
|
const output = await options.execute();
|
|
61
48
|
state = { status: "success", input: options.input, output, error: void 0 };
|
|
@@ -93,60 +80,6 @@ function convertToArray(value2) {
|
|
|
93
80
|
return Array.isArray(value2) ? value2 : [value2];
|
|
94
81
|
}
|
|
95
82
|
|
|
96
|
-
// src/interceptor.ts
|
|
97
|
-
function onStart(callback) {
|
|
98
|
-
return async (options, ...rest) => {
|
|
99
|
-
await callback(options, ...rest);
|
|
100
|
-
return await options.next();
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
function onSuccess(callback) {
|
|
104
|
-
return async (options, ...rest) => {
|
|
105
|
-
const result = await options.next();
|
|
106
|
-
await callback(result, options, ...rest);
|
|
107
|
-
return result;
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
function onError(callback) {
|
|
111
|
-
return async (options, ...rest) => {
|
|
112
|
-
try {
|
|
113
|
-
return await options.next();
|
|
114
|
-
} catch (error) {
|
|
115
|
-
await callback(error, options, ...rest);
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function onFinish(callback) {
|
|
121
|
-
let state;
|
|
122
|
-
return async (options, ...rest) => {
|
|
123
|
-
try {
|
|
124
|
-
const result = await options.next();
|
|
125
|
-
state = [result, void 0, "success"];
|
|
126
|
-
return result;
|
|
127
|
-
} catch (error) {
|
|
128
|
-
state = [void 0, error, "error"];
|
|
129
|
-
throw error;
|
|
130
|
-
} finally {
|
|
131
|
-
await callback(state, options, ...rest);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
async function intercept(interceptors, options, main) {
|
|
136
|
-
let index = 0;
|
|
137
|
-
const next = async (nextOptions = options) => {
|
|
138
|
-
const interceptor = interceptors[index++];
|
|
139
|
-
if (!interceptor) {
|
|
140
|
-
return await main(nextOptions);
|
|
141
|
-
}
|
|
142
|
-
return await interceptor({
|
|
143
|
-
...nextOptions,
|
|
144
|
-
next
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
return await next();
|
|
148
|
-
}
|
|
149
|
-
|
|
150
83
|
// src/json.ts
|
|
151
84
|
function parseJSONSafely(text) {
|
|
152
85
|
if (text === "")
|
|
@@ -252,16 +185,10 @@ export {
|
|
|
252
185
|
get,
|
|
253
186
|
group,
|
|
254
187
|
guard,
|
|
255
|
-
intercept,
|
|
256
188
|
isPlainObject3 as isPlainObject,
|
|
257
189
|
mapEntries,
|
|
258
190
|
mapValues,
|
|
259
191
|
omit,
|
|
260
|
-
onError,
|
|
261
|
-
onFinish,
|
|
262
|
-
onStart,
|
|
263
|
-
onSuccess,
|
|
264
|
-
once,
|
|
265
192
|
parseJSONSafely,
|
|
266
193
|
set,
|
|
267
194
|
toError,
|
package/dist/src/function.d.ts
CHANGED
package/dist/src/index.d.ts
CHANGED
package/dist/src/object.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type Segment = string | number;
|
|
2
|
-
export declare function set(root:
|
|
2
|
+
export declare function set(root: Readonly<Record<string, unknown> | unknown[]>, segments: Readonly<Segment[]>, value: unknown): unknown;
|
|
3
3
|
export declare function get(root: Readonly<Record<string, unknown> | unknown[]>, segments: Readonly<Segment[]>): unknown;
|
|
4
4
|
export declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
5
5
|
maps: Segment[][];
|
package/package.json
CHANGED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from 'type-fest';
|
|
2
|
-
import type { AnyFunction } from './function';
|
|
3
|
-
export type InterceptableOptions = Record<string, any>;
|
|
4
|
-
export type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
5
|
-
next(options?: TOptions): Promise<TResult>;
|
|
6
|
-
};
|
|
7
|
-
export type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult>) => Promise<TResult> & {
|
|
8
|
-
__error?: {
|
|
9
|
-
type: TError;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Can used for interceptors or middlewares
|
|
14
|
-
*/
|
|
15
|
-
export declare function onStart<TOptions extends {
|
|
16
|
-
next(): any;
|
|
17
|
-
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
18
|
-
/**
|
|
19
|
-
* Can used for interceptors or middlewares
|
|
20
|
-
*/
|
|
21
|
-
export declare function onSuccess<TOptions extends {
|
|
22
|
-
next(): any;
|
|
23
|
-
}, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions['next']>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
24
|
-
export type InferError<T extends AnyFunction> = T extends Interceptor<any, any, infer TError> ? TError : unknown;
|
|
25
|
-
/**
|
|
26
|
-
* Can used for interceptors or middlewares
|
|
27
|
-
*/
|
|
28
|
-
export declare function onError<TError, TOptions extends {
|
|
29
|
-
next(): any;
|
|
30
|
-
}, TRest extends any[]>(callback: NoInfer<(error: TError, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>> & {
|
|
31
|
-
__error?: {
|
|
32
|
-
type: TError;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
export type OnFinishState<TResult, TError> = [TResult, undefined, 'success'] | [undefined, TError, 'error'];
|
|
36
|
-
/**
|
|
37
|
-
* Can used for interceptors or middlewares
|
|
38
|
-
*/
|
|
39
|
-
export declare function onFinish<TError, TOptions extends {
|
|
40
|
-
next(): any;
|
|
41
|
-
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>, TError>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>> & {
|
|
42
|
-
__error?: {
|
|
43
|
-
type: TError;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
export declare function intercept<TOptions extends InterceptableOptions, TResult, TError>(interceptors: Interceptor<TOptions, TResult, TError>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => Promisable<TResult>>): Promise<TResult>;
|
|
47
|
-
//# sourceMappingURL=interceptor.d.ts.map
|