vovk 3.0.0-draft.230 → 3.0.0-draft.232

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.
@@ -42,7 +42,7 @@ const createRPC = (schema, segmentName, rpcModuleName, fetcher = fetcher_js_1.fe
42
42
  .replace(/([^:])\/+/g, '$1/'); // replace // by / but not for protocols (http://, https://)
43
43
  return endpoint;
44
44
  };
45
- const handler = (input = {}) => {
45
+ const handler = async (input = {}) => {
46
46
  const validate = async ({ body, query, params, endpoint, }) => {
47
47
  const validateOnClient = input.validateOnClient ?? options?.validateOnClient;
48
48
  if (validateOnClient && validation) {
@@ -69,10 +69,8 @@ const createRPC = (schema, segmentName, rpcModuleName, fetcher = fetcher_js_1.fe
69
69
  };
70
70
  if (!fetcher)
71
71
  throw new Error('Fetcher is not provided');
72
- const fetcherPromise = fetcher(internalOptions, internalInput);
73
- if (!(fetcherPromise instanceof Promise))
74
- return Promise.resolve(fetcherPromise);
75
- return input.transform ? fetcherPromise.then(input.transform) : fetcherPromise;
72
+ const [respData, resp] = await fetcher(internalOptions, internalInput);
73
+ return input.transform ? input.transform(respData, resp) : respData;
76
74
  };
77
75
  handler.schema = handlerSchema;
78
76
  handler.controllerSchema = controllerSchema;
@@ -81,10 +81,10 @@ function createFetcher({ prepareRequestInit, transformResponse, } = {}) {
81
81
  resp = response;
82
82
  }
83
83
  resp = await resp;
84
- return transformResponse
85
- ? ((await transformResponse(resp, response, options, requestInit)) ??
86
- resp)
84
+ resp = transformResponse
85
+ ? await transformResponse(resp, response, options, requestInit)
87
86
  : resp;
87
+ return [resp, response];
88
88
  };
89
89
  return newFetcher;
90
90
  }
@@ -29,7 +29,7 @@ export type VovkStreamAsyncIterable<T> = {
29
29
  type StaticMethodReturn<T extends ControllerStaticMethod> = ReturnType<T> extends NextResponse<infer U> | Promise<NextResponse<infer U>> ? U : ReturnType<T> extends Response | Promise<Response> ? Awaited<ReturnType<T>> : ReturnType<T>;
30
30
  type StaticMethodReturnPromise<T extends ControllerStaticMethod> = ToPromise<StaticMethodReturn<T>>;
31
31
  type StaticMethodOptions<T extends (req: VovkRequest<KnownAny, KnownAny, KnownAny>, params: KnownAny) => void | object | JSONLinesResponse<STREAM> | Promise<JSONLinesResponse<STREAM>>, OPTS extends Record<string, KnownAny>, STREAM, R, F extends VovkDefaultFetcherOptions<KnownAny>> = Partial<OPTS & {
32
- transform: (staticMethodReturn: Awaited<StaticMethodReturn<T>>) => R;
32
+ transform: (staticMethodReturn: Awaited<StaticMethodReturn<T>>, resp: Response) => R;
33
33
  fetcher: VovkClientFetcher<F>;
34
34
  }>;
35
35
  type ClientMethodReturn<T extends (req: VovkRequest<KnownAny, KnownAny, KnownAny>, params: KnownAny) => void | object | JSONLinesResponse<STREAM> | Promise<JSONLinesResponse<STREAM>>, STREAM, R> = ReturnType<T> extends Promise<JSONLinesResponse<infer U>> | JSONLinesResponse<infer U> | Iterator<infer U> | AsyncIterator<infer U> ? Promise<VovkStreamAsyncIterable<U>> : R extends object ? Promise<Awaited<R>> : StaticMethodReturnPromise<T>;
@@ -44,7 +44,6 @@ type ClientMethod<T extends ((req: VovkRequest<KnownAny, KnownAny, KnownAny>, pa
44
44
  };
45
45
  }, OPTS extends Record<string, KnownAny>, STREAM extends KnownAny = unknown> = (IsEmptyObject<StaticMethodInput<T>> extends true ? <R, F extends VovkDefaultFetcherOptions<KnownAny> = VovkDefaultFetcherOptions<OPTS>>(options?: Prettify<StaticMethodOptions<T, OPTS, STREAM, R, F>>) => ClientMethodReturn<T, STREAM, R> : <R, F extends VovkDefaultFetcherOptions<KnownAny> = VovkDefaultFetcherOptions<OPTS>>(options: Prettify<StaticMethodInput<T> & StaticMethodOptions<T, OPTS, STREAM, R, F>>) => ClientMethodReturn<T, STREAM, R>) & {
46
46
  isRPC: true;
47
- path: string;
48
47
  schema: VovkHandlerSchema;
49
48
  controllerSchema: VovkControllerSchema;
50
49
  segmentSchema: VovkSegmentSchema;
@@ -90,7 +89,7 @@ export type VovkClientFetcher<OPTS> = (options: {
90
89
  params: {
91
90
  [key: string]: string;
92
91
  };
93
- } & OPTS) => KnownAny;
92
+ } & OPTS) => Promise<[KnownAny, Response]>;
94
93
  export type VovkDefaultFetcherOptions<T> = T & {
95
94
  apiRoot?: string;
96
95
  disableClientValidation?: boolean;
@@ -42,7 +42,7 @@ const createRPC = (schema, segmentName, rpcModuleName, fetcher = fetcher_js_1.fe
42
42
  .replace(/([^:])\/+/g, '$1/'); // replace // by / but not for protocols (http://, https://)
43
43
  return endpoint;
44
44
  };
45
- const handler = (input = {}) => {
45
+ const handler = async (input = {}) => {
46
46
  const validate = async ({ body, query, params, endpoint, }) => {
47
47
  const validateOnClient = input.validateOnClient ?? options?.validateOnClient;
48
48
  if (validateOnClient && validation) {
@@ -69,10 +69,8 @@ const createRPC = (schema, segmentName, rpcModuleName, fetcher = fetcher_js_1.fe
69
69
  };
70
70
  if (!fetcher)
71
71
  throw new Error('Fetcher is not provided');
72
- const fetcherPromise = fetcher(internalOptions, internalInput);
73
- if (!(fetcherPromise instanceof Promise))
74
- return Promise.resolve(fetcherPromise);
75
- return input.transform ? fetcherPromise.then(input.transform) : fetcherPromise;
72
+ const [respData, resp] = await fetcher(internalOptions, internalInput);
73
+ return input.transform ? input.transform(respData, resp) : respData;
76
74
  };
77
75
  handler.schema = handlerSchema;
78
76
  handler.controllerSchema = controllerSchema;
@@ -81,10 +81,10 @@ function createFetcher({ prepareRequestInit, transformResponse, } = {}) {
81
81
  resp = response;
82
82
  }
83
83
  resp = await resp;
84
- return transformResponse
85
- ? ((await transformResponse(resp, response, options, requestInit)) ??
86
- resp)
84
+ resp = transformResponse
85
+ ? await transformResponse(resp, response, options, requestInit)
87
86
  : resp;
87
+ return [resp, response];
88
88
  };
89
89
  return newFetcher;
90
90
  }
@@ -29,7 +29,7 @@ export type VovkStreamAsyncIterable<T> = {
29
29
  type StaticMethodReturn<T extends ControllerStaticMethod> = ReturnType<T> extends NextResponse<infer U> | Promise<NextResponse<infer U>> ? U : ReturnType<T> extends Response | Promise<Response> ? Awaited<ReturnType<T>> : ReturnType<T>;
30
30
  type StaticMethodReturnPromise<T extends ControllerStaticMethod> = ToPromise<StaticMethodReturn<T>>;
31
31
  type StaticMethodOptions<T extends (req: VovkRequest<KnownAny, KnownAny, KnownAny>, params: KnownAny) => void | object | JSONLinesResponse<STREAM> | Promise<JSONLinesResponse<STREAM>>, OPTS extends Record<string, KnownAny>, STREAM, R, F extends VovkDefaultFetcherOptions<KnownAny>> = Partial<OPTS & {
32
- transform: (staticMethodReturn: Awaited<StaticMethodReturn<T>>) => R;
32
+ transform: (staticMethodReturn: Awaited<StaticMethodReturn<T>>, resp: Response) => R;
33
33
  fetcher: VovkClientFetcher<F>;
34
34
  }>;
35
35
  type ClientMethodReturn<T extends (req: VovkRequest<KnownAny, KnownAny, KnownAny>, params: KnownAny) => void | object | JSONLinesResponse<STREAM> | Promise<JSONLinesResponse<STREAM>>, STREAM, R> = ReturnType<T> extends Promise<JSONLinesResponse<infer U>> | JSONLinesResponse<infer U> | Iterator<infer U> | AsyncIterator<infer U> ? Promise<VovkStreamAsyncIterable<U>> : R extends object ? Promise<Awaited<R>> : StaticMethodReturnPromise<T>;
@@ -44,7 +44,6 @@ type ClientMethod<T extends ((req: VovkRequest<KnownAny, KnownAny, KnownAny>, pa
44
44
  };
45
45
  }, OPTS extends Record<string, KnownAny>, STREAM extends KnownAny = unknown> = (IsEmptyObject<StaticMethodInput<T>> extends true ? <R, F extends VovkDefaultFetcherOptions<KnownAny> = VovkDefaultFetcherOptions<OPTS>>(options?: Prettify<StaticMethodOptions<T, OPTS, STREAM, R, F>>) => ClientMethodReturn<T, STREAM, R> : <R, F extends VovkDefaultFetcherOptions<KnownAny> = VovkDefaultFetcherOptions<OPTS>>(options: Prettify<StaticMethodInput<T> & StaticMethodOptions<T, OPTS, STREAM, R, F>>) => ClientMethodReturn<T, STREAM, R>) & {
46
46
  isRPC: true;
47
- path: string;
48
47
  schema: VovkHandlerSchema;
49
48
  controllerSchema: VovkControllerSchema;
50
49
  segmentSchema: VovkSegmentSchema;
@@ -90,7 +89,7 @@ export type VovkClientFetcher<OPTS> = (options: {
90
89
  params: {
91
90
  [key: string]: string;
92
91
  };
93
- } & OPTS) => KnownAny;
92
+ } & OPTS) => Promise<[KnownAny, Response]>;
94
93
  export type VovkDefaultFetcherOptions<T> = T & {
95
94
  apiRoot?: string;
96
95
  disableClientValidation?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "3.0.0-draft.230",
3
+ "version": "3.0.0-draft.232",
4
4
  "main": "./cjs/index.js",
5
5
  "module": "./mjs/index.js",
6
6
  "types": "./mjs/index.d.ts",