vovk 3.0.0-draft.96 → 3.0.0-draft.97

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.
@@ -1,14 +1,12 @@
1
+ import type { headers } from 'next/headers';
1
2
  import type { KnownAny, StreamAbortMessage } from './types';
2
3
  import './utils/shim';
3
4
  export declare class StreamJSONResponse<T> extends Response {
4
- static defaultHeaders: {
5
- 'content-type': string;
6
- };
7
5
  isClosed: boolean;
8
6
  controller?: ReadableStreamDefaultController;
9
7
  readonly encoder: TextEncoder;
10
8
  readonly readableStream: ReadableStream;
11
- constructor(init?: ResponseInit);
9
+ constructor(requestHeaders: Awaited<ReturnType<typeof headers>>, init?: ResponseInit);
12
10
  send(data: T | StreamAbortMessage): void;
13
11
  close(): void;
14
12
  throw(e: KnownAny): void;
@@ -3,14 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StreamJSONResponse = void 0;
4
4
  require("./utils/shim");
5
5
  class StreamJSONResponse extends Response {
6
- static defaultHeaders = {
7
- 'content-type': 'text/plain; x-format=jsonlines',
8
- };
9
6
  isClosed = false;
10
7
  controller;
11
8
  encoder;
12
9
  readableStream;
13
- constructor(init) {
10
+ constructor(requestHeaders, init) {
14
11
  const encoder = new TextEncoder();
15
12
  let readableController;
16
13
  const readableStream = new ReadableStream({
@@ -21,9 +18,16 @@ class StreamJSONResponse extends Response {
21
18
  readableController = controller;
22
19
  },
23
20
  });
21
+ if (!requestHeaders) {
22
+ throw new Error('Request headers are required');
23
+ }
24
+ const accept = requestHeaders.get('accept');
24
25
  super(readableStream, {
25
26
  ...init,
26
- headers: init?.headers ?? StreamJSONResponse.defaultHeaders,
27
+ headers: {
28
+ ...init?.headers,
29
+ 'Content-Type': accept?.includes('application/jsonl') ? 'application/jsonl' : 'plain/text',
30
+ },
27
31
  });
28
32
  this.readableStream = readableStream;
29
33
  this.encoder = encoder;
package/dist/VovkApp.js CHANGED
@@ -11,6 +11,7 @@ const StreamJSONResponse_1 = require("./StreamJSONResponse");
11
11
  const reqQuery_1 = __importDefault(require("./utils/reqQuery"));
12
12
  const reqMeta_1 = __importDefault(require("./utils/reqMeta"));
13
13
  const reqForm_1 = __importDefault(require("./utils/reqForm"));
14
+ const headers_1 = require("next/headers");
14
15
  class VovkApp {
15
16
  static getHeadersFromOptions(options) {
16
17
  if (!options)
@@ -143,9 +144,8 @@ class VovkApp {
143
144
  (Reflect.has(result, Symbol.asyncIterator) &&
144
145
  typeof result[Symbol.asyncIterator] === 'function'));
145
146
  if (isIterator && !(result instanceof Array)) {
146
- const streamResponse = new StreamJSONResponse_1.StreamJSONResponse({
147
+ const streamResponse = new StreamJSONResponse_1.StreamJSONResponse(await (0, headers_1.headers)(), {
147
148
  headers: {
148
- ...StreamJSONResponse_1.StreamJSONResponse.defaultHeaders,
149
149
  ..._a.getHeadersFromOptions(staticMethod._options),
150
150
  },
151
151
  });
@@ -28,6 +28,10 @@ const fetcher = async ({ httpMethod, getEndpoint, validate, defaultHandler, defa
28
28
  const init = {
29
29
  method: httpMethod,
30
30
  ...options,
31
+ headers: {
32
+ ...options.headers,
33
+ accept: 'application/jsonl, application/json',
34
+ },
31
35
  };
32
36
  if (body instanceof FormData) {
33
37
  init.body = body;
package/dist/types.d.ts CHANGED
@@ -114,12 +114,14 @@ export type VovkEnv = {
114
114
  __VOVK_START_WATCHER_IN_STANDALONE_MODE__?: 'true';
115
115
  __VOVK_EXIT__?: 'true' | 'false';
116
116
  };
117
- type GenerateFrom = (string | {
117
+ export type GenerateFromTemplate = {
118
118
  templatePath: string;
119
119
  outDir?: string;
120
120
  templateName?: string;
121
121
  fullSchema?: string | boolean;
122
- })[];
122
+ origin?: string | null;
123
+ };
124
+ type GenerateFrom = (string | GenerateFromTemplate)[];
123
125
  export type VovkConfig = {
124
126
  emitConfig?: boolean | (keyof VovkStrictConfig)[];
125
127
  clientOutDir?: string;
@@ -140,15 +142,15 @@ export type VovkConfig = {
140
142
  controller?: string;
141
143
  [key: string]: string | undefined;
142
144
  };
143
- custom?: Record<string, KnownAny>;
145
+ libs?: Record<string, KnownAny>;
144
146
  };
145
- export type VovkStrictConfig = Required<Omit<VovkConfig, 'emitConfig' | 'validateOnClientImport' | 'fetcherImport' | 'createRPCImport' | 'generateFrom' | 'custom'>> & {
147
+ export type VovkStrictConfig = Required<Omit<VovkConfig, 'emitConfig' | 'validateOnClientImport' | 'fetcherImport' | 'createRPCImport' | 'generateFrom' | 'libs'>> & {
146
148
  emitConfig: (keyof VovkStrictConfig)[];
147
149
  validateOnClientImport: string[] | null;
148
150
  fetcherImport: string[];
149
151
  createRPCImport: string[];
150
152
  generateFrom: GenerateFrom;
151
- custom: Record<string, KnownAny>;
153
+ libs: Record<string, KnownAny>;
152
154
  };
153
155
  export type VovkFullSchema = {
154
156
  config: Partial<VovkStrictConfig>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "3.0.0-draft.96",
3
+ "version": "3.0.0-draft.97",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "description": "RESTful RPC for Next.js - Transforms Next.js into a powerful REST API platform with RPC capabilities.",