Comparing version 4.1.1 to 4.1.2
@@ -26,3 +26,3 @@ "use strict"; | ||
var import_url = require("../../utils/url"); | ||
const emptyParams = {}; | ||
const emptyParams = /* @__PURE__ */ Object.create(null); | ||
const splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g; | ||
@@ -82,3 +82,3 @@ const splitByStarRe = /\*/; | ||
} else if (hasLabel && !hasStar) { | ||
const params = {}; | ||
const params = /* @__PURE__ */ Object.create(null); | ||
const parts = routePath.match(splitPathRe); | ||
@@ -85,0 +85,0 @@ const lastIndex = parts.length - 1; |
@@ -33,15 +33,12 @@ "use strict"; | ||
} | ||
const parts = path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+|(\?)/g) || []; | ||
if (parts[parts.length - 1] === "?") { | ||
this.add(method, parts.slice(0, parts.length - 2).join(""), handler); | ||
parts.pop(); | ||
if (path.at(-1) === "?") { | ||
path = path.slice(0, -1); | ||
this.add(method, path.replace(/\/[^/]+$/, ""), handler); | ||
} | ||
for (let i = 0, len = parts.length; i < len; i++) { | ||
const match = parts[i].match(/^\/:([^{]+)(?:{(.*)})?/); | ||
if (match) { | ||
parts[i] = `/(?<${match[1]}>${match[2] || "[^/]+"})`; | ||
} else if (parts[i] === "/*") { | ||
parts[i] = "/[^/]+"; | ||
const parts = (path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+/g) || []).map( | ||
(part) => { | ||
const match = part.match(/^\/:([^{]+)(?:{(.*)})?/); | ||
return match ? `/(?<${match[1]}>${match[2] || "[^/]+"})` : part === "/*" ? "/[^/]+" : part.replace(/[.\\+*[^\]$()]/g, "\\$&"); | ||
} | ||
} | ||
); | ||
let re; | ||
@@ -61,3 +58,3 @@ try { | ||
if (match) { | ||
handlers.push([handler, match.groups || {}]); | ||
handlers.push([handler, match.groups || /* @__PURE__ */ Object.create(null)]); | ||
} | ||
@@ -64,0 +61,0 @@ } |
@@ -29,2 +29,3 @@ "use strict"; | ||
const PATH_ERROR = Symbol(); | ||
const regExpMetaChars = new Set(".\\+*[^]$()"); | ||
function compareKey(a, b) { | ||
@@ -52,3 +53,3 @@ if (a.length === 1) { | ||
varIndex; | ||
children = {}; | ||
children = /* @__PURE__ */ Object.create(null); | ||
insert(tokens, index, paramMap, context, pathErrorCheckOnly) { | ||
@@ -115,3 +116,3 @@ if (tokens.length === 0) { | ||
const c = this.children[k]; | ||
return (typeof c.varIndex === "number" ? `(${k})@${c.varIndex}` : k) + c.buildRegExpStr(); | ||
return (typeof c.varIndex === "number" ? `(${k})@${c.varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr(); | ||
}); | ||
@@ -118,0 +119,0 @@ if (typeof this.index === "number") { |
@@ -29,4 +29,4 @@ "use strict"; | ||
const emptyParam = []; | ||
const nullMatcher = [/^$/, [], {}]; | ||
let wildcardRegExpCache = {}; | ||
const nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)]; | ||
let wildcardRegExpCache = /* @__PURE__ */ Object.create(null); | ||
function buildWildcardRegExp(path) { | ||
@@ -38,3 +38,3 @@ return wildcardRegExpCache[path] ??= new RegExp( | ||
function clearWildcardRegExpCache() { | ||
wildcardRegExpCache = {}; | ||
wildcardRegExpCache = /* @__PURE__ */ Object.create(null); | ||
} | ||
@@ -52,7 +52,7 @@ function buildMatcherFromPreprocessedRoutes(routes) { | ||
); | ||
const staticMap = {}; | ||
const staticMap = /* @__PURE__ */ Object.create(null); | ||
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) { | ||
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i]; | ||
if (pathErrorCheckOnly) { | ||
staticMap[path] = [handlers.map(([h]) => [h, {}]), emptyParam]; | ||
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam]; | ||
} else { | ||
@@ -71,3 +71,3 @@ j++; | ||
handlerData[j] = handlers.map(([h, paramCount]) => { | ||
const paramIndexMap = {}; | ||
const paramIndexMap = /* @__PURE__ */ Object.create(null); | ||
paramCount -= 1; | ||
@@ -116,4 +116,4 @@ for (; paramCount >= 0; paramCount--) { | ||
constructor() { | ||
this.middleware = { [import_router.METHOD_NAME_ALL]: {} }; | ||
this.routes = { [import_router.METHOD_NAME_ALL]: {} }; | ||
this.middleware = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) }; | ||
this.routes = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) }; | ||
} | ||
@@ -128,3 +128,3 @@ add(method, path, handler) { | ||
[middleware, routes].forEach((handlerMap) => { | ||
handlerMap[method] = {}; | ||
handlerMap[method] = /* @__PURE__ */ Object.create(null); | ||
Object.keys(handlerMap[import_router.METHOD_NAME_ALL]).forEach((p) => { | ||
@@ -196,3 +196,3 @@ handlerMap[method][p] = [...handlerMap[import_router.METHOD_NAME_ALL][p]]; | ||
buildAllMatchers() { | ||
const matchers = {}; | ||
const matchers = /* @__PURE__ */ Object.create(null); | ||
[...Object.keys(this.routes), ...Object.keys(this.middleware)].forEach((method) => { | ||
@@ -199,0 +199,0 @@ matchers[method] ||= this.buildMatcher(method); |
@@ -32,9 +32,9 @@ "use strict"; | ||
name; | ||
params = {}; | ||
params = /* @__PURE__ */ Object.create(null); | ||
constructor(method, handler, children) { | ||
this.children = children || {}; | ||
this.children = children || /* @__PURE__ */ Object.create(null); | ||
this.methods = []; | ||
this.name = ""; | ||
if (method && handler) { | ||
const m = {}; | ||
const m = /* @__PURE__ */ Object.create(null); | ||
m[method] = { handler, possibleKeys: [], score: 0, name: this.name }; | ||
@@ -76,3 +76,3 @@ this.methods = [m]; | ||
} | ||
const m = {}; | ||
const m = /* @__PURE__ */ Object.create(null); | ||
const handlerSet = { | ||
@@ -93,5 +93,5 @@ handler, | ||
const handlerSet = m[method] || m[import_router.METHOD_NAME_ALL]; | ||
const processedSet = {}; | ||
const processedSet = /* @__PURE__ */ Object.create(null); | ||
if (handlerSet !== void 0) { | ||
handlerSet.params = {}; | ||
handlerSet.params = /* @__PURE__ */ Object.create(null); | ||
handlerSet.possibleKeys.forEach((key) => { | ||
@@ -109,3 +109,3 @@ const processed = processedSet[handlerSet.name]; | ||
const handlerSets = []; | ||
this.params = {}; | ||
this.params = /* @__PURE__ */ Object.create(null); | ||
const curNode = this; | ||
@@ -125,5 +125,7 @@ let curNodes = [curNode]; | ||
if (nextNode.children["*"]) { | ||
handlerSets.push(...this.gHSets(nextNode.children["*"], method, node.params, {})); | ||
handlerSets.push( | ||
...this.gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null)) | ||
); | ||
} | ||
handlerSets.push(...this.gHSets(nextNode, method, node.params, {})); | ||
handlerSets.push(...this.gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null))); | ||
} else { | ||
@@ -139,3 +141,3 @@ tempNodes.push(nextNode); | ||
if (astNode) { | ||
handlerSets.push(...this.gHSets(astNode, method, node.params, {})); | ||
handlerSets.push(...this.gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null))); | ||
tempNodes.push(astNode); | ||
@@ -142,0 +144,0 @@ } |
@@ -147,3 +147,3 @@ "use strict"; | ||
}; | ||
const serialize = (name, value, opt = {}) => { | ||
const serialize = (name, value, opt) => { | ||
value = encodeURIComponent(value); | ||
@@ -150,0 +150,0 @@ return _serialize(name, value, opt); |
@@ -86,4 +86,5 @@ "use strict"; | ||
const getPath = (request) => { | ||
const match = request.url.match(/^https?:\/\/[^/]+(\/[^?]*)/); | ||
return match ? match[1] : ""; | ||
const url = request.url; | ||
const queryIndex = url.indexOf("?", 8); | ||
return url.slice(url.indexOf("/", 8), queryIndex === -1 ? void 0 : queryIndex); | ||
}; | ||
@@ -90,0 +91,0 @@ const getQueryStrings = (url) => { |
// src/router/linear-router/router.ts | ||
import { METHOD_NAME_ALL, UnsupportedPathError } from "../../router.js"; | ||
import { checkOptionalParameter } from "../../utils/url.js"; | ||
var emptyParams = {}; | ||
var emptyParams = /* @__PURE__ */ Object.create(null); | ||
var splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g; | ||
@@ -59,3 +59,3 @@ var splitByStarRe = /\*/; | ||
} else if (hasLabel && !hasStar) { | ||
const params = {}; | ||
const params = /* @__PURE__ */ Object.create(null); | ||
const parts = routePath.match(splitPathRe); | ||
@@ -62,0 +62,0 @@ const lastIndex = parts.length - 1; |
@@ -11,15 +11,12 @@ // src/router/pattern-router/router.ts | ||
} | ||
const parts = path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+|(\?)/g) || []; | ||
if (parts[parts.length - 1] === "?") { | ||
this.add(method, parts.slice(0, parts.length - 2).join(""), handler); | ||
parts.pop(); | ||
if (path.at(-1) === "?") { | ||
path = path.slice(0, -1); | ||
this.add(method, path.replace(/\/[^/]+$/, ""), handler); | ||
} | ||
for (let i = 0, len = parts.length; i < len; i++) { | ||
const match = parts[i].match(/^\/:([^{]+)(?:{(.*)})?/); | ||
if (match) { | ||
parts[i] = `/(?<${match[1]}>${match[2] || "[^/]+"})`; | ||
} else if (parts[i] === "/*") { | ||
parts[i] = "/[^/]+"; | ||
const parts = (path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+/g) || []).map( | ||
(part) => { | ||
const match = part.match(/^\/:([^{]+)(?:{(.*)})?/); | ||
return match ? `/(?<${match[1]}>${match[2] || "[^/]+"})` : part === "/*" ? "/[^/]+" : part.replace(/[.\\+*[^\]$()]/g, "\\$&"); | ||
} | ||
} | ||
); | ||
let re; | ||
@@ -39,3 +36,3 @@ try { | ||
if (match) { | ||
handlers.push([handler, match.groups || {}]); | ||
handlers.push([handler, match.groups || /* @__PURE__ */ Object.create(null)]); | ||
} | ||
@@ -42,0 +39,0 @@ } |
@@ -6,2 +6,3 @@ // src/router/reg-exp-router/node.ts | ||
var PATH_ERROR = Symbol(); | ||
var regExpMetaChars = new Set(".\\+*[^]$()"); | ||
function compareKey(a, b) { | ||
@@ -29,3 +30,3 @@ if (a.length === 1) { | ||
varIndex; | ||
children = {}; | ||
children = /* @__PURE__ */ Object.create(null); | ||
insert(tokens, index, paramMap, context, pathErrorCheckOnly) { | ||
@@ -92,3 +93,3 @@ if (tokens.length === 0) { | ||
const c = this.children[k]; | ||
return (typeof c.varIndex === "number" ? `(${k})@${c.varIndex}` : k) + c.buildRegExpStr(); | ||
return (typeof c.varIndex === "number" ? `(${k})@${c.varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr(); | ||
}); | ||
@@ -95,0 +96,0 @@ if (typeof this.index === "number") { |
@@ -11,4 +11,4 @@ // src/router/reg-exp-router/router.ts | ||
var emptyParam = []; | ||
var nullMatcher = [/^$/, [], {}]; | ||
var wildcardRegExpCache = {}; | ||
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)]; | ||
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null); | ||
function buildWildcardRegExp(path) { | ||
@@ -20,3 +20,3 @@ return wildcardRegExpCache[path] ??= new RegExp( | ||
function clearWildcardRegExpCache() { | ||
wildcardRegExpCache = {}; | ||
wildcardRegExpCache = /* @__PURE__ */ Object.create(null); | ||
} | ||
@@ -34,7 +34,7 @@ function buildMatcherFromPreprocessedRoutes(routes) { | ||
); | ||
const staticMap = {}; | ||
const staticMap = /* @__PURE__ */ Object.create(null); | ||
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) { | ||
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i]; | ||
if (pathErrorCheckOnly) { | ||
staticMap[path] = [handlers.map(([h]) => [h, {}]), emptyParam]; | ||
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam]; | ||
} else { | ||
@@ -53,3 +53,3 @@ j++; | ||
handlerData[j] = handlers.map(([h, paramCount]) => { | ||
const paramIndexMap = {}; | ||
const paramIndexMap = /* @__PURE__ */ Object.create(null); | ||
paramCount -= 1; | ||
@@ -98,4 +98,4 @@ for (; paramCount >= 0; paramCount--) { | ||
constructor() { | ||
this.middleware = { [METHOD_NAME_ALL]: {} }; | ||
this.routes = { [METHOD_NAME_ALL]: {} }; | ||
this.middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) }; | ||
this.routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) }; | ||
} | ||
@@ -110,3 +110,3 @@ add(method, path, handler) { | ||
[middleware, routes].forEach((handlerMap) => { | ||
handlerMap[method] = {}; | ||
handlerMap[method] = /* @__PURE__ */ Object.create(null); | ||
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => { | ||
@@ -178,3 +178,3 @@ handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]]; | ||
buildAllMatchers() { | ||
const matchers = {}; | ||
const matchers = /* @__PURE__ */ Object.create(null); | ||
[...Object.keys(this.routes), ...Object.keys(this.middleware)].forEach((method) => { | ||
@@ -181,0 +181,0 @@ matchers[method] ||= this.buildMatcher(method); |
@@ -10,9 +10,9 @@ // src/router/trie-router/node.ts | ||
name; | ||
params = {}; | ||
params = /* @__PURE__ */ Object.create(null); | ||
constructor(method, handler, children) { | ||
this.children = children || {}; | ||
this.children = children || /* @__PURE__ */ Object.create(null); | ||
this.methods = []; | ||
this.name = ""; | ||
if (method && handler) { | ||
const m = {}; | ||
const m = /* @__PURE__ */ Object.create(null); | ||
m[method] = { handler, possibleKeys: [], score: 0, name: this.name }; | ||
@@ -54,3 +54,3 @@ this.methods = [m]; | ||
} | ||
const m = {}; | ||
const m = /* @__PURE__ */ Object.create(null); | ||
const handlerSet = { | ||
@@ -71,5 +71,5 @@ handler, | ||
const handlerSet = m[method] || m[METHOD_NAME_ALL]; | ||
const processedSet = {}; | ||
const processedSet = /* @__PURE__ */ Object.create(null); | ||
if (handlerSet !== void 0) { | ||
handlerSet.params = {}; | ||
handlerSet.params = /* @__PURE__ */ Object.create(null); | ||
handlerSet.possibleKeys.forEach((key) => { | ||
@@ -87,3 +87,3 @@ const processed = processedSet[handlerSet.name]; | ||
const handlerSets = []; | ||
this.params = {}; | ||
this.params = /* @__PURE__ */ Object.create(null); | ||
const curNode = this; | ||
@@ -103,5 +103,7 @@ let curNodes = [curNode]; | ||
if (nextNode.children["*"]) { | ||
handlerSets.push(...this.gHSets(nextNode.children["*"], method, node.params, {})); | ||
handlerSets.push( | ||
...this.gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null)) | ||
); | ||
} | ||
handlerSets.push(...this.gHSets(nextNode, method, node.params, {})); | ||
handlerSets.push(...this.gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null))); | ||
} else { | ||
@@ -117,3 +119,3 @@ tempNodes.push(nextNode); | ||
if (astNode) { | ||
handlerSets.push(...this.gHSets(astNode, method, node.params, {})); | ||
handlerSets.push(...this.gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null))); | ||
tempNodes.push(astNode); | ||
@@ -120,0 +122,0 @@ } |
@@ -415,3 +415,3 @@ import type { Context } from './context'; | ||
type AddDollar<T extends string> = `$${Lowercase<T>}`; | ||
export type MergePath<A extends string, B extends string> = A extends '' ? B : A extends '/' ? B : A extends `${infer P}/` ? B extends `/${infer Q}` ? `${P}/${Q}` : `${P}/${B}` : B extends `/${infer Q}` ? Q extends '' ? A : `${A}/${Q}` : `${A}/${B}`; | ||
export type MergePath<A extends string, B extends string> = B extends '' ? MergePath<A, '/'> : A extends '' ? B : A extends '/' ? B : A extends `${infer P}/` ? B extends `/${infer Q}` ? `${P}/${Q}` : `${P}/${B}` : B extends `/${infer Q}` ? Q extends '' ? A : `${A}/${Q}` : `${A}/${B}`; | ||
export type TypedResponse<T = unknown> = { | ||
@@ -418,0 +418,0 @@ data: T; |
export type Cookie = Record<string, string>; | ||
export type SignedCookie = Record<string, string | false>; | ||
type PartitionCookieConstraint = { | ||
partition: true; | ||
secure: true; | ||
} | { | ||
partition?: boolean; | ||
secure?: boolean; | ||
}; | ||
type SecureCookieConstraint = { | ||
secure: true; | ||
}; | ||
type HostCookieConstraint = { | ||
secure: true; | ||
path: '/'; | ||
domain?: undefined; | ||
}; | ||
export type CookieOptions = { | ||
@@ -14,7 +29,9 @@ domain?: string; | ||
prefix?: CookiePrefixOptions; | ||
}; | ||
} & PartitionCookieConstraint; | ||
export type CookiePrefixOptions = 'host' | 'secure'; | ||
export type CookieConstraint<Name> = Name extends `__Secure-${string}` ? CookieOptions & SecureCookieConstraint : Name extends `__Host-${string}` ? CookieOptions & HostCookieConstraint : CookieOptions; | ||
export declare const parse: (cookie: string, name?: string) => Cookie; | ||
export declare const parseSigned: (cookie: string, secret: string | BufferSource, name?: string) => Promise<SignedCookie>; | ||
export declare const serialize: (name: string, value: string, opt?: CookieOptions) => string; | ||
export declare const serialize: <Name extends string>(name: Name, value: string, opt?: CookieConstraint<Name> | undefined) => string; | ||
export declare const serializeSigned: (name: string, value: string, secret: string | BufferSource, opt?: CookieOptions) => Promise<string>; | ||
export {}; |
@@ -122,3 +122,3 @@ // src/utils/cookie.ts | ||
}; | ||
var serialize = (name, value, opt = {}) => { | ||
var serialize = (name, value, opt) => { | ||
value = encodeURIComponent(value); | ||
@@ -125,0 +125,0 @@ return _serialize(name, value, opt); |
@@ -54,4 +54,5 @@ // src/utils/url.ts | ||
var getPath = (request) => { | ||
const match = request.url.match(/^https?:\/\/[^/]+(\/[^?]*)/); | ||
return match ? match[1] : ""; | ||
const url = request.url; | ||
const queryIndex = url.indexOf("?", 8); | ||
return url.slice(url.indexOf("/", 8), queryIndex === -1 ? void 0 : queryIndex); | ||
}; | ||
@@ -58,0 +59,0 @@ var getQueryStrings = (url) => { |
{ | ||
"name": "hono", | ||
"version": "4.1.1", | ||
"version": "4.1.2", | ||
"description": "Ultrafast web framework for the Edges", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
744095
20678