hono 4.6.11 → 4.6.12

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.
@@ -251,7 +251,10 @@ var getProcessor = (event) => {
251
251
  return v1Processor;
252
252
  };
253
253
  var isProxyEventALB = (event) => {
254
- return Object.hasOwn(event.requestContext, "elb");
254
+ if (event.requestContext) {
255
+ return Object.hasOwn(event.requestContext, "elb");
256
+ }
257
+ return false;
255
258
  };
256
259
  var isProxyEventV2 = (event) => {
257
260
  return Object.hasOwn(event, "rawPath");
@@ -268,6 +271,10 @@ var isContentEncodingBinary = (contentEncoding) => {
268
271
  return /^(gzip|deflate|compress|br)/.test(contentEncoding);
269
272
  };
270
273
  export {
274
+ ALBProcessor,
275
+ EventProcessor,
276
+ EventV1Processor,
277
+ EventV2Processor,
271
278
  getProcessor,
272
279
  handle,
273
280
  isContentEncodingBinary,
@@ -24,6 +24,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
  var handler_exports = {};
26
26
  __export(handler_exports, {
27
+ ALBProcessor: () => ALBProcessor,
28
+ EventProcessor: () => EventProcessor,
29
+ EventV1Processor: () => EventV1Processor,
30
+ EventV2Processor: () => EventV2Processor,
27
31
  getProcessor: () => getProcessor,
28
32
  handle: () => handle,
29
33
  isContentEncodingBinary: () => isContentEncodingBinary,
@@ -283,7 +287,10 @@ const getProcessor = (event) => {
283
287
  return v1Processor;
284
288
  };
285
289
  const isProxyEventALB = (event) => {
286
- return Object.hasOwn(event.requestContext, "elb");
290
+ if (event.requestContext) {
291
+ return Object.hasOwn(event.requestContext, "elb");
292
+ }
293
+ return false;
287
294
  };
288
295
  const isProxyEventV2 = (event) => {
289
296
  return Object.hasOwn(event, "rawPath");
@@ -301,6 +308,10 @@ const isContentEncodingBinary = (contentEncoding) => {
301
308
  };
302
309
  // Annotate the CommonJS export names for ESM import in node:
303
310
  0 && (module.exports = {
311
+ ALBProcessor,
312
+ EventProcessor,
313
+ EventV1Processor,
314
+ EventV2Processor,
304
315
  getProcessor,
305
316
  handle,
306
317
  isContentEncodingBinary,
@@ -35,7 +35,8 @@ var import_common2 = require("./common");
35
35
  const createCssContext = ({ id }) => {
36
36
  const [cssJsxDomObject, StyleRenderToDom] = (0, import_css.createCssJsxDomObjects)({ id });
37
37
  const contextMap = /* @__PURE__ */ new WeakMap();
38
- const replaceStyleRe = new RegExp(`(<style id="${id}">.*?)(</style>)`);
38
+ const nonceMap = /* @__PURE__ */ new WeakMap();
39
+ const replaceStyleRe = new RegExp(`(<style id="${id}"(?: nonce="[^"]*")?>.*?)(</style>)`);
39
40
  const newCssClassNameObject = (cssClassName) => {
40
41
  const appendStyle = ({ buffer, context }) => {
41
42
  const [toAdd, added] = contextMap.get(context);
@@ -53,9 +54,8 @@ const createCssContext = ({ id }) => {
53
54
  buffer[0] = buffer[0].replace(replaceStyleRe, (_, pre, post) => `${pre}${stylesStr}${post}`);
54
55
  return;
55
56
  }
56
- const appendStyleScript = `<script>document.querySelector('#${id}').textContent+=${JSON.stringify(
57
- stylesStr
58
- )}<\/script>`;
57
+ const nonce = nonceMap.get(context);
58
+ const appendStyleScript = `<script${nonce ? ` nonce="${nonce}"` : ""}>document.querySelector('#${id}').textContent+=${JSON.stringify(stylesStr)}<\/script>`;
59
59
  if (buffer) {
60
60
  buffer[0] = `${appendStyleScript}${buffer[0]}`;
61
61
  return;
@@ -63,7 +63,7 @@ const createCssContext = ({ id }) => {
63
63
  return Promise.resolve(appendStyleScript);
64
64
  };
65
65
  const addClassNameToContext = ({ context }) => {
66
- if (!contextMap.get(context)) {
66
+ if (!contextMap.has(context)) {
67
67
  contextMap.set(context, [{}, {}]);
68
68
  }
69
69
  const [toAdd, added] = contextMap.get(context);
@@ -105,7 +105,15 @@ const createCssContext = ({ id }) => {
105
105
  const viewTransition2 = (strings, ...values) => {
106
106
  return newCssClassNameObject((0, import_common.viewTransitionCommon)(strings, values));
107
107
  };
108
- const Style2 = ({ children } = {}) => children ? (0, import_html.raw)(`<style id="${id}">${children[import_common.STYLE_STRING]}</style>`) : (0, import_html.raw)(`<style id="${id}"></style>`);
108
+ const Style2 = ({ children, nonce } = {}) => (0, import_html.raw)(
109
+ `<style id="${id}"${nonce ? ` nonce="${nonce}"` : ""}>${children ? children[import_common.STYLE_STRING] : ""}</style>`,
110
+ [
111
+ ({ context }) => {
112
+ nonceMap.set(context, nonce);
113
+ return void 0;
114
+ }
115
+ ]
116
+ );
109
117
  Style2[import_constants.DOM_RENDERER] = StyleRenderToDom;
110
118
  return {
111
119
  css: css2,
@@ -105,10 +105,11 @@ const createCssJsxDomObjects = ({ id }) => {
105
105
  return this[import_common.CLASS_NAME];
106
106
  }
107
107
  };
108
- const Style2 = ({ children }) => ({
108
+ const Style2 = ({ children, nonce }) => ({
109
109
  tag: "style",
110
110
  props: {
111
111
  id,
112
+ nonce,
112
113
  children: children && (Array.isArray(children) ? children : [children]).map(
113
114
  (c) => c[import_common.STYLE_STRING]
114
115
  )
@@ -166,10 +166,12 @@ class Node {
166
166
  }
167
167
  curNodes = tempNodes;
168
168
  }
169
- const results = handlerSets.sort((a, b) => {
170
- return a.score - b.score;
171
- });
172
- return [results.map(({ handler, params }) => [handler, params])];
169
+ if (handlerSets.length > 1) {
170
+ handlerSets.sort((a, b) => {
171
+ return a.score - b.score;
172
+ });
173
+ }
174
+ return [handlerSets.map(({ handler, params }) => [handler, params])];
173
175
  }
174
176
  }
175
177
  // Annotate the CommonJS export names for ESM import in node:
@@ -18,7 +18,8 @@ import { rawCssString } from "./common.js";
18
18
  var createCssContext = ({ id }) => {
19
19
  const [cssJsxDomObject, StyleRenderToDom] = createCssJsxDomObjects({ id });
20
20
  const contextMap = /* @__PURE__ */ new WeakMap();
21
- const replaceStyleRe = new RegExp(`(<style id="${id}">.*?)(</style>)`);
21
+ const nonceMap = /* @__PURE__ */ new WeakMap();
22
+ const replaceStyleRe = new RegExp(`(<style id="${id}"(?: nonce="[^"]*")?>.*?)(</style>)`);
22
23
  const newCssClassNameObject = (cssClassName) => {
23
24
  const appendStyle = ({ buffer, context }) => {
24
25
  const [toAdd, added] = contextMap.get(context);
@@ -36,9 +37,8 @@ var createCssContext = ({ id }) => {
36
37
  buffer[0] = buffer[0].replace(replaceStyleRe, (_, pre, post) => `${pre}${stylesStr}${post}`);
37
38
  return;
38
39
  }
39
- const appendStyleScript = `<script>document.querySelector('#${id}').textContent+=${JSON.stringify(
40
- stylesStr
41
- )}<\/script>`;
40
+ const nonce = nonceMap.get(context);
41
+ const appendStyleScript = `<script${nonce ? ` nonce="${nonce}"` : ""}>document.querySelector('#${id}').textContent+=${JSON.stringify(stylesStr)}<\/script>`;
42
42
  if (buffer) {
43
43
  buffer[0] = `${appendStyleScript}${buffer[0]}`;
44
44
  return;
@@ -46,7 +46,7 @@ var createCssContext = ({ id }) => {
46
46
  return Promise.resolve(appendStyleScript);
47
47
  };
48
48
  const addClassNameToContext = ({ context }) => {
49
- if (!contextMap.get(context)) {
49
+ if (!contextMap.has(context)) {
50
50
  contextMap.set(context, [{}, {}]);
51
51
  }
52
52
  const [toAdd, added] = contextMap.get(context);
@@ -88,7 +88,15 @@ var createCssContext = ({ id }) => {
88
88
  const viewTransition2 = (strings, ...values) => {
89
89
  return newCssClassNameObject(viewTransitionCommon(strings, values));
90
90
  };
91
- const Style2 = ({ children } = {}) => children ? raw(`<style id="${id}">${children[STYLE_STRING]}</style>`) : raw(`<style id="${id}"></style>`);
91
+ const Style2 = ({ children, nonce } = {}) => raw(
92
+ `<style id="${id}"${nonce ? ` nonce="${nonce}"` : ""}>${children ? children[STYLE_STRING] : ""}</style>`,
93
+ [
94
+ ({ context }) => {
95
+ nonceMap.set(context, nonce);
96
+ return void 0;
97
+ }
98
+ ]
99
+ );
92
100
  Style2[DOM_RENDERER] = StyleRenderToDom;
93
101
  return {
94
102
  css: css2,
@@ -87,10 +87,11 @@ var createCssJsxDomObjects = ({ id }) => {
87
87
  return this[CLASS_NAME];
88
88
  }
89
89
  };
90
- const Style2 = ({ children }) => ({
90
+ const Style2 = ({ children, nonce }) => ({
91
91
  tag: "style",
92
92
  props: {
93
93
  id,
94
+ nonce,
94
95
  children: children && (Array.isArray(children) ? children : [children]).map(
95
96
  (c) => c[STYLE_STRING]
96
97
  )
@@ -144,10 +144,12 @@ var Node = class {
144
144
  }
145
145
  curNodes = tempNodes;
146
146
  }
147
- const results = handlerSets.sort((a, b) => {
148
- return a.score - b.score;
149
- });
150
- return [results.map(({ handler, params }) => [handler, params])];
147
+ if (handlerSets.length > 1) {
148
+ handlerSets.sort((a, b) => {
149
+ return a.score - b.score;
150
+ });
151
+ }
152
+ return [handlerSets.map(({ handler, params }) => [handler, params])];
151
153
  }
152
154
  };
153
155
  export {
@@ -71,7 +71,7 @@ export declare const streamHandle: <E extends Env = Env, S extends Schema = {},
71
71
  * Accepts events from API Gateway/ELB(`APIGatewayProxyEvent`) and directly through Function Url(`APIGatewayProxyEventV2`)
72
72
  */
73
73
  export declare const handle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => ((event: LambdaEvent, lambdaContext?: LambdaContext) => Promise<APIGatewayProxyResult>);
74
- declare abstract class EventProcessor<E extends LambdaEvent> {
74
+ export declare abstract class EventProcessor<E extends LambdaEvent> {
75
75
  protected abstract getPath(event: E): string;
76
76
  protected abstract getMethod(event: E): string;
77
77
  protected abstract getQueryString(event: E): string;
@@ -82,7 +82,30 @@ declare abstract class EventProcessor<E extends LambdaEvent> {
82
82
  createResult(event: E, res: Response): Promise<APIGatewayProxyResult>;
83
83
  setCookies(event: E, res: Response, result: APIGatewayProxyResult): void;
84
84
  }
85
+ export declare class EventV2Processor extends EventProcessor<APIGatewayProxyEventV2> {
86
+ protected getPath(event: APIGatewayProxyEventV2): string;
87
+ protected getMethod(event: APIGatewayProxyEventV2): string;
88
+ protected getQueryString(event: APIGatewayProxyEventV2): string;
89
+ protected getCookies(event: APIGatewayProxyEventV2, headers: Headers): void;
90
+ protected setCookiesToResult(_: APIGatewayProxyEventV2, result: APIGatewayProxyResult, cookies: string[]): void;
91
+ protected getHeaders(event: APIGatewayProxyEventV2): Headers;
92
+ }
93
+ export declare class EventV1Processor extends EventProcessor<Exclude<LambdaEvent, APIGatewayProxyEventV2>> {
94
+ protected getPath(event: Exclude<LambdaEvent, APIGatewayProxyEventV2>): string;
95
+ protected getMethod(event: Exclude<LambdaEvent, APIGatewayProxyEventV2>): string;
96
+ protected getQueryString(event: Exclude<LambdaEvent, APIGatewayProxyEventV2>): string;
97
+ protected getCookies(event: Exclude<LambdaEvent, APIGatewayProxyEventV2>, headers: Headers): void;
98
+ protected getHeaders(event: APIGatewayProxyEvent): Headers;
99
+ protected setCookiesToResult(_: APIGatewayProxyEvent, result: APIGatewayProxyResult, cookies: string[]): void;
100
+ }
101
+ export declare class ALBProcessor extends EventProcessor<ALBProxyEvent> {
102
+ protected getHeaders(event: ALBProxyEvent): Headers;
103
+ protected getPath(event: ALBProxyEvent): string;
104
+ protected getMethod(event: ALBProxyEvent): string;
105
+ protected getQueryString(event: ALBProxyEvent): string;
106
+ protected getCookies(event: ALBProxyEvent, headers: Headers): void;
107
+ protected setCookiesToResult(event: ALBProxyEvent, result: APIGatewayProxyResult, cookies: string[]): void;
108
+ }
85
109
  export declare const getProcessor: (event: LambdaEvent) => EventProcessor<LambdaEvent>;
86
110
  export declare const isContentTypeBinary: (contentType: string) => boolean;
87
111
  export declare const isContentEncodingBinary: (contentEncoding: string | null) => boolean;
88
- export {};
@@ -23,6 +23,7 @@ interface ViewTransitionType {
23
23
  interface StyleType {
24
24
  (args?: {
25
25
  children?: Promise<string>;
26
+ nonce?: string;
26
27
  }): HtmlEscapedString;
27
28
  }
28
29
  /**
@@ -12,7 +12,7 @@ type HtmlEscapedCallbackOpts = {
12
12
  string
13
13
  ];
14
14
  phase: (typeof HtmlEscapedCallbackPhase)[keyof typeof HtmlEscapedCallbackPhase];
15
- context: object;
15
+ context: Readonly<object>;
16
16
  };
17
17
  export type HtmlEscapedCallback = (opts: HtmlEscapedCallbackOpts) => Promise<string> | undefined;
18
18
  export type HtmlEscaped = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.6.11",
3
+ "version": "4.6.12",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",