@chillicream/nitro-server-adapter-plugin 33.0.0-insider.5 → 33.0.0-insider.6

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/index.cjs CHANGED
@@ -31,11 +31,11 @@ const Paths = {
31
31
  function resolveUrl(target) {
32
32
  return typeof target === "string"
33
33
  ? target
34
- : `${target?.baseUrl || Defaults.CDN_URL}/${target?.version || Defaults.VERSION}`;
34
+ : `${orDefault(target?.baseUrl, Defaults.CDN_URL)}/${orDefault(target?.version, Defaults.VERSION)}`;
35
35
  }
36
36
  function resolvePath(target) {
37
37
  const require$1 = module$1.createRequire(require('url').pathToFileURL(__filename).toString());
38
- return path.dirname(require$1.resolve(target || Defaults.EMBEDDED_ID));
38
+ return path.dirname(require$1.resolve(orDefault(target, Defaults.EMBEDDED_ID)));
39
39
  }
40
40
  function resolveConfig(config) {
41
41
  return Object.assign({}, Defaults.CONFIG, config);
@@ -43,12 +43,17 @@ function resolveConfig(config) {
43
43
  function resolveOptions(options) {
44
44
  return Object.assign({}, Defaults.OPTIONS, options);
45
45
  }
46
+ function orDefault(value, fallback) {
47
+ return value !== undefined && value !== "" ? value : fallback;
48
+ }
46
49
 
47
50
  function useNitro(config) {
48
51
  const resolvedConfig = resolveConfig(config);
49
52
  const basePath = resolveBasePath(resolvedConfig.path);
50
53
  return {
51
- onRequest({ request, url, fetchAPI, endResponse }) {
54
+ onRequest(payload) {
55
+ const { request, url, fetchAPI } = payload;
56
+ const endResponse = (response) => payload.endResponse(response);
52
57
  if (request.method === "GET" || request.method === "HEAD") {
53
58
  const acceptHeader = request.headers.get("accept");
54
59
  // handle root request
@@ -140,7 +145,9 @@ function serverStatic(path, baseFilePath, fetchAPI, endResponse) {
140
145
  },
141
146
  }));
142
147
  }
143
- catch { }
148
+ catch {
149
+ // Missing or unreadable file; let the request fall through.
150
+ }
144
151
  }
145
152
  if (path.endsWith(".css")) {
146
153
  return write(baseFilePath + path, "text/css");
package/index.d.cts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { ServerAdapterPlugin } from "@whatwg-node/server";
2
- interface HttpHeaderDictionary {
3
- readonly [key: string]: string | string[];
4
- }
2
+ type HttpHeaderDictionary = Readonly<Record<string, string | string[]>>;
5
3
  type SubscriptionProtocol = "auto" | "graphql-transport-ws" | "graphql-ws" | "graphql-sse";
6
4
  interface Options {
7
5
  readonly title?: string;
@@ -16,7 +14,7 @@ interface Options {
16
14
  readonly endpoint?: string;
17
15
  readonly httpHeaders?: HttpHeaderDictionary;
18
16
  readonly graphQLDocument?: string;
19
- readonly variables?: Record<string, any>;
17
+ readonly variables?: Record<string, unknown>;
20
18
  readonly organization?: {
21
19
  readonly serverUrl?: string;
22
20
  readonly name?: string;
package/index.d.mts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { ServerAdapterPlugin } from "@whatwg-node/server";
2
- interface HttpHeaderDictionary {
3
- readonly [key: string]: string | string[];
4
- }
2
+ type HttpHeaderDictionary = Readonly<Record<string, string | string[]>>;
5
3
  type SubscriptionProtocol = "auto" | "graphql-transport-ws" | "graphql-ws" | "graphql-sse";
6
4
  interface Options {
7
5
  readonly title?: string;
@@ -16,7 +14,7 @@ interface Options {
16
14
  readonly endpoint?: string;
17
15
  readonly httpHeaders?: HttpHeaderDictionary;
18
16
  readonly graphQLDocument?: string;
19
- readonly variables?: Record<string, any>;
17
+ readonly variables?: Record<string, unknown>;
20
18
  readonly organization?: {
21
19
  readonly serverUrl?: string;
22
20
  readonly name?: string;
package/index.mjs CHANGED
@@ -29,11 +29,11 @@ const Paths = {
29
29
  function resolveUrl(target) {
30
30
  return typeof target === "string"
31
31
  ? target
32
- : `${target?.baseUrl || Defaults.CDN_URL}/${target?.version || Defaults.VERSION}`;
32
+ : `${orDefault(target?.baseUrl, Defaults.CDN_URL)}/${orDefault(target?.version, Defaults.VERSION)}`;
33
33
  }
34
34
  function resolvePath(target) {
35
35
  const require = module.createRequire(import.meta.url);
36
- return path.dirname(require.resolve(target || Defaults.EMBEDDED_ID));
36
+ return path.dirname(require.resolve(orDefault(target, Defaults.EMBEDDED_ID)));
37
37
  }
38
38
  function resolveConfig(config) {
39
39
  return Object.assign({}, Defaults.CONFIG, config);
@@ -41,12 +41,17 @@ function resolveConfig(config) {
41
41
  function resolveOptions(options) {
42
42
  return Object.assign({}, Defaults.OPTIONS, options);
43
43
  }
44
+ function orDefault(value, fallback) {
45
+ return value !== undefined && value !== "" ? value : fallback;
46
+ }
44
47
 
45
48
  function useNitro(config) {
46
49
  const resolvedConfig = resolveConfig(config);
47
50
  const basePath = resolveBasePath(resolvedConfig.path);
48
51
  return {
49
- onRequest({ request, url, fetchAPI, endResponse }) {
52
+ onRequest(payload) {
53
+ const { request, url, fetchAPI } = payload;
54
+ const endResponse = (response) => payload.endResponse(response);
50
55
  if (request.method === "GET" || request.method === "HEAD") {
51
56
  const acceptHeader = request.headers.get("accept");
52
57
  // handle root request
@@ -138,7 +143,9 @@ function serverStatic(path, baseFilePath, fetchAPI, endResponse) {
138
143
  },
139
144
  }));
140
145
  }
141
- catch { }
146
+ catch {
147
+ // Missing or unreadable file; let the request fall through.
148
+ }
142
149
  }
143
150
  if (path.endsWith(".css")) {
144
151
  return write(baseFilePath + path, "text/css");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chillicream/nitro-server-adapter-plugin",
3
- "version": "33.0.0-insider.5",
3
+ "version": "33.0.0-insider.6",
4
4
  "description": "Server Adapter Plugin for Nitro GraphQL IDE",
5
5
  "homepage": "https://chillicream.com",
6
6
  "repository": "github:ChilliCream/graphql-platform",