rjweb-server
Advanced tools
Comparing version 9.5.5 to 9.5.6
# Changelog | ||
## 9.5.6 | ||
- Add Routing with unions using template literals | ||
## 9.5.5 | ||
@@ -4,0 +8,0 @@ |
@@ -14,2 +14,6 @@ "use strict"; | ||
const deepClone_1 = __importDefault(require("../../functions/deepClone")); | ||
const location_1 = __importDefault(require("../../functions/location")); | ||
function handlePath(path) { | ||
return typeof path === 'function' ? path(location_1.default) : Array.isArray(path) ? path : [path]; | ||
} | ||
class Path { | ||
@@ -146,7 +150,9 @@ computePath(path) { | ||
*/ path(prefix, callback) { | ||
const path = new Path(this.prefix.concat('/', prefix), this._global, [...this.validators], [this._httpRatelimit, this._wsRatelimit], this.promises, (0, deepClone_1.default)(this.openApi)); | ||
callback(path); | ||
this.routesHttp.push(...path.routesHttp); | ||
this.routesStatic.push(...path.routesStatic); | ||
this.routesWS.push(...path.routesWS); | ||
for (const prefixPath of handlePath(prefix)) { | ||
const path = new Path(this.prefix.concat('/', prefixPath), this._global, [...this.validators], [this._httpRatelimit, this._wsRatelimit], this.promises, (0, deepClone_1.default)(this.openApi)); | ||
callback(path); | ||
this.routesHttp.push(...path.routesHttp); | ||
this.routesStatic.push(...path.routesStatic); | ||
this.routesWS.push(...path.routesWS); | ||
} | ||
return this; | ||
@@ -232,3 +238,3 @@ } | ||
*/ http(method, path, callback) { | ||
for (const p of Array.isArray(path) ? path : [path]) { | ||
for (const p of handlePath(path)) { | ||
const http = new Http_1.default(method, this.computePath(p), this._httpRatelimit); | ||
@@ -261,3 +267,3 @@ http['route'].openApi = (0, deepClone_1.default)(this.openApi); | ||
*/ ws(path, callback) { | ||
for (const p of Array.isArray(path) ? path : [path]) { | ||
for (const p of handlePath(path)) { | ||
const ws = new Ws_1.default(this.computePath(p), this._wsRatelimit); | ||
@@ -264,0 +270,0 @@ ws['route'].openApi = (0, deepClone_1.default)(this.openApi); |
@@ -107,3 +107,2 @@ #! /usr/bin/env node | ||
yargs_1.default | ||
.scriptName('rjweb') | ||
.usage('$0 <command> [args]') | ||
@@ -110,0 +109,0 @@ .version(index_1.version) |
@@ -32,3 +32,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RuntimeError = exports.Middleware = exports.Throttler = exports.Cookie = exports.Channel = exports.ValueCollection = exports.Server = exports.defaultOptions = exports.html = exports.writeHeaders = exports.parseKV = exports.parseURL = exports.parseContent = exports.WsCloseContext = exports.WsMessageContext = exports.WsOpenContext = exports.HttpRequestContext = exports.RequestContext = exports.GlobalContext = exports.ImplementationWsContext = exports.ImplementationHttpContext = exports.Implementation = exports.version = void 0; | ||
exports.RuntimeError = exports.Middleware = exports.Throttler = exports.Cookie = exports.Channel = exports.ValueCollection = exports.Server = exports.defaultOptions = exports.location = exports.html = exports.writeHeaders = exports.parseKV = exports.parseURL = exports.parseContent = exports.WsCloseContext = exports.WsMessageContext = exports.WsOpenContext = exports.HttpRequestContext = exports.RequestContext = exports.GlobalContext = exports.ImplementationWsContext = exports.ImplementationHttpContext = exports.Implementation = exports.version = void 0; | ||
const package_json_1 = require("./package.json"); | ||
@@ -66,2 +66,4 @@ exports.version = package_json_1.version; | ||
exports.html = html_1.default; | ||
const location_1 = __importDefault(require("./functions/location")); | ||
exports.location = location_1.default; | ||
const Server_1 = __importStar(require("./classes/Server")); | ||
@@ -68,0 +70,0 @@ exports.Server = Server_1.default; |
{ | ||
"name": "rjweb-server", | ||
"version": "9.5.5", | ||
"version": "9.5.6", | ||
"description": "Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS", | ||
@@ -61,6 +61,6 @@ "main": "./lib/cjs/index.js", | ||
"dependencies": { | ||
"@rjweb/utils": "^1.12.14", | ||
"@rjweb/utils": "^1.12.15", | ||
"content-disposition": "^0.5.4", | ||
"inquirer": "^9.2.21", | ||
"openapi3-ts": "^4.3.1", | ||
"inquirer": "^9.2.22", | ||
"openapi3-ts": "^4.3.2", | ||
"yargs": "^17.7.2", | ||
@@ -67,0 +67,0 @@ "zod": "^3.23.8" |
@@ -9,2 +9,6 @@ import Route from "../Route"; | ||
import deepClone from "../../functions/deepClone"; | ||
import location from "../../functions/location"; | ||
function handlePath(path) { | ||
return typeof path === 'function' ? path(location) : Array.isArray(path) ? path : [path]; | ||
} | ||
export default class Path { | ||
@@ -141,7 +145,9 @@ computePath(path) { | ||
*/ path(prefix, callback) { | ||
const path = new Path(this.prefix.concat('/', prefix), this._global, [...this.validators], [this._httpRatelimit, this._wsRatelimit], this.promises, deepClone(this.openApi)); | ||
callback(path); | ||
this.routesHttp.push(...path.routesHttp); | ||
this.routesStatic.push(...path.routesStatic); | ||
this.routesWS.push(...path.routesWS); | ||
for (const prefixPath of handlePath(prefix)) { | ||
const path = new Path(this.prefix.concat('/', prefixPath), this._global, [...this.validators], [this._httpRatelimit, this._wsRatelimit], this.promises, deepClone(this.openApi)); | ||
callback(path); | ||
this.routesHttp.push(...path.routesHttp); | ||
this.routesStatic.push(...path.routesStatic); | ||
this.routesWS.push(...path.routesWS); | ||
} | ||
return this; | ||
@@ -227,3 +233,3 @@ } | ||
*/ http(method, path, callback) { | ||
for (const p of Array.isArray(path) ? path : [path]) { | ||
for (const p of handlePath(path)) { | ||
const http = new Http(method, this.computePath(p), this._httpRatelimit); | ||
@@ -256,3 +262,3 @@ http['route'].openApi = deepClone(this.openApi); | ||
*/ ws(path, callback) { | ||
for (const p of Array.isArray(path) ? path : [path]) { | ||
for (const p of handlePath(path)) { | ||
const ws = new Ws(this.computePath(p), this._wsRatelimit); | ||
@@ -259,0 +265,0 @@ ws['route'].openApi = deepClone(this.openApi); |
@@ -79,3 +79,2 @@ #! /usr/bin/env node | ||
yargs | ||
.scriptName('rjweb') | ||
.usage('$0 <command> [args]') | ||
@@ -82,0 +81,0 @@ .version(version) |
@@ -19,2 +19,3 @@ import { version as packageVersion } from "./package.json"; | ||
import html from "./functions/html"; | ||
import location from "./functions/location"; | ||
import Server, { defaultOptions } from "./classes/Server"; | ||
@@ -27,2 +28,2 @@ import ValueCollection from "./classes/ValueCollection"; | ||
import RuntimeError from "./classes/RuntimeError"; | ||
export { parseContent, parseURL, parseKV, writeHeaders, html, defaultOptions, Server, ValueCollection, Channel, Cookie, Throttler, Middleware, RuntimeError }; | ||
export { parseContent, parseURL, parseKV, writeHeaders, html, location, defaultOptions, Server, ValueCollection, Channel, Cookie, Throttler, Middleware, RuntimeError }; |
{ | ||
"name": "rjweb-server", | ||
"version": "9.5.5", | ||
"version": "9.5.6", | ||
"description": "Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS", | ||
@@ -61,6 +61,6 @@ "main": "./lib/cjs/index.js", | ||
"dependencies": { | ||
"@rjweb/utils": "^1.12.14", | ||
"@rjweb/utils": "^1.12.15", | ||
"content-disposition": "^0.5.4", | ||
"inquirer": "^9.2.21", | ||
"openapi3-ts": "^4.3.1", | ||
"inquirer": "^9.2.22", | ||
"openapi3-ts": "^4.3.2", | ||
"yargs": "^17.7.2", | ||
@@ -67,0 +67,0 @@ "zod": "^3.23.8" |
@@ -5,3 +5,3 @@ import { Method } from "../types/global"; | ||
import { UsableValidator } from "./Validator"; | ||
import { OperationObject } from "openapi3-ts/oas31"; | ||
import { oas31 } from "openapi3-ts"; | ||
import HttpRequestContext from "./request/HttpRequestContext"; | ||
@@ -62,3 +62,3 @@ import WsOpenContext from "./request/WsOpenContext"; | ||
* @since 9.0.0 | ||
*/ openApi: OperationObject; | ||
*/ openApi: oas31.OperationObject; | ||
/** | ||
@@ -65,0 +65,0 @@ * Test the Path against the Request Path |
@@ -6,3 +6,3 @@ import { UsableMiddleware } from "../Middleware"; | ||
import GlobalContext from "../../types/internal/classes/GlobalContext"; | ||
import { OperationObject } from "openapi3-ts/oas31"; | ||
import { oas31 } from "openapi3-ts"; | ||
import Path from "./Path"; | ||
@@ -14,3 +14,3 @@ export default class File<Middlewares extends UsableMiddleware[], Validators extends UsableValidator[] = [], Context extends Record<string, any> = {}, Excluded extends (keyof File<Middlewares>)[] = []> { | ||
protected promises: Promise<any>[]; | ||
protected openApi: OperationObject; | ||
protected openApi: oas31.OperationObject; | ||
private _global; | ||
@@ -26,3 +26,3 @@ private prefix; | ||
* @since 9.0.0 | ||
*/ document(item: OperationObject): Omit<File<Middlewares, Validators, Context, [...Excluded, 'document']>, Excluded[number] | 'document'>; | ||
*/ document(item: oas31.OperationObject): Omit<File<Middlewares, Validators, Context, [...Excluded, 'document']>, Excluded[number] | 'document'>; | ||
/** | ||
@@ -29,0 +29,0 @@ * Add a Ratelimit to all HTTP Endpoints in this Path (and all children) |
@@ -9,3 +9,3 @@ /// <reference types="node" /> | ||
import HttpRequestContext from "../request/HttpRequestContext"; | ||
import { OperationObject } from "openapi3-ts/oas31"; | ||
import { oas31 } from "openapi3-ts"; | ||
export default class Http<_Method extends Method, Middlewares extends UsableMiddleware[] = [], Validators extends UsableValidator[] = [], Context extends Record<string, any> = {}, Excluded extends (keyof Http<_Method>)[] = []> { | ||
@@ -20,3 +20,3 @@ protected route: Route<'http'>; | ||
* @since 9.0.0 | ||
*/ document(item: OperationObject): Omit<Http<_Method, Middlewares, Validators, Context, [...Excluded, 'document']>, Excluded[number] | 'document'>; | ||
*/ document(item: oas31.OperationObject): Omit<Http<_Method, Middlewares, Validators, Context, [...Excluded, 'document']>, Excluded[number] | 'document'>; | ||
/** | ||
@@ -23,0 +23,0 @@ * Add a Ratelimit to this Endpoint |
@@ -6,3 +6,3 @@ import Route from "../Route"; | ||
import { UsableValidator } from "../Validator"; | ||
import { RateLimitConfig } from "../../types/internal"; | ||
import { LocationCallback, RateLimitConfig } from "../../types/internal"; | ||
import RateLimit from "./RateLimit"; | ||
@@ -12,3 +12,3 @@ import GlobalContext from "../../types/internal/classes/GlobalContext"; | ||
import Ws from "./Ws"; | ||
import { OperationObject } from "openapi3-ts/oas31"; | ||
import { oas31 } from "openapi3-ts"; | ||
export default class Path<Middlewares extends UsableMiddleware[], Validators extends UsableValidator[] = [], Context extends Record<string, any> = {}, Excluded extends (keyof Path<Middlewares>)[] = []> { | ||
@@ -22,3 +22,3 @@ private validators; | ||
protected promises: Promise<any>[]; | ||
protected openApi: OperationObject; | ||
protected openApi: oas31.OperationObject; | ||
private _global; | ||
@@ -30,7 +30,7 @@ private prefix; | ||
* @since 6.0.0 | ||
*/ constructor(prefix: string, global: GlobalContext, validators?: Validators, ratelimits?: [RateLimitConfig | null, RateLimitConfig | null], promises?: Promise<any>[], openApi?: OperationObject); | ||
*/ constructor(prefix: string, global: GlobalContext, validators?: Validators, ratelimits?: [RateLimitConfig | null, RateLimitConfig | null], promises?: Promise<any>[], openApi?: oas31.OperationObject); | ||
/** | ||
* Add OpenAPI Documentation to all HTTP Endpoints in this Path (and all children) | ||
* @since 9.0.0 | ||
*/ document(item: OperationObject): Omit<Path<Middlewares, Validators, Context, [...Excluded, 'document']>, Excluded[number] | 'document'>; | ||
*/ document(item: oas31.OperationObject): Omit<Path<Middlewares, Validators, Context, [...Excluded, 'document']>, Excluded[number] | 'document'>; | ||
/** | ||
@@ -109,3 +109,3 @@ * Add a Ratelimit to all HTTP Endpoints in this Path (and all children) | ||
* @since 6.0.0 | ||
*/ path(prefix: string, callback: (path: Path<Middlewares, Validators, Context>) => any): this; | ||
*/ path(prefix: ArrayOrNot<string> | LocationCallback, callback: (path: Path<Middlewares, Validators, Context>) => any): this; | ||
/** | ||
@@ -162,3 +162,3 @@ * Use a Validator on all Endpoints in this Path | ||
* @since 6.0.0 | ||
*/ http<_Method extends Method>(method: _Method, path: ArrayOrNot<string | RegExp>, callback: (http: Http<_Method, Middlewares, Validators, Context>) => any): this; | ||
*/ http<_Method extends Method>(method: _Method, path: ArrayOrNot<string | RegExp> | LocationCallback, callback: (http: Http<_Method, Middlewares, Validators, Context>) => any): this; | ||
/** | ||
@@ -179,3 +179,3 @@ * Add a new WebSocket Route | ||
* @since 6.0.0 | ||
*/ ws(path: ArrayOrNot<string | RegExp>, callback: (ws: Ws<Middlewares, Validators, Context>) => any): this; | ||
*/ ws(path: ArrayOrNot<string | RegExp> | LocationCallback, callback: (ws: Ws<Middlewares, Validators, Context>) => any): this; | ||
} |
@@ -10,3 +10,3 @@ import Route from "../Route"; | ||
import WsCloseContext from "../request/WsCloseContext"; | ||
import { OperationObject } from "openapi3-ts/oas31"; | ||
import { oas31 } from "openapi3-ts"; | ||
export default class Ws<Middlewares extends UsableMiddleware[] = [], Validators extends UsableValidator[] = [], Context extends Record<string, any> = {}, Excluded extends (keyof Ws)[] = []> { | ||
@@ -21,3 +21,3 @@ protected route: Route<'ws'>; | ||
* @since 9.0.0 | ||
*/ document(item: OperationObject): Omit<Ws<Middlewares, Validators, Context, [...Excluded, 'document']>, Excluded[number] | 'document'>; | ||
*/ document(item: oas31.OperationObject): Omit<Ws<Middlewares, Validators, Context, [...Excluded, 'document']>, Excluded[number] | 'document'>; | ||
/** | ||
@@ -24,0 +24,0 @@ * Add a Ratelimit to this Endpoint |
@@ -7,3 +7,3 @@ import { DataContext, EndFn, RealAny, SetItemType } from "../types/internal"; | ||
import WsCloseContext from "./request/WsCloseContext"; | ||
import { OperationObject } from "openapi3-ts/oas31"; | ||
import { oas31 } from "openapi3-ts"; | ||
type Listeners<Data extends Record<string, any>, Context extends Record<string, any>, Middlewares extends UsableMiddleware[] = []> = { | ||
@@ -78,3 +78,3 @@ httpRequest: Set<((ctr: DataContext<'HttpRequest', 'POST', HttpRequestContext<Context>, Middlewares>, end: EndFn, data: Data) => RealAny)>; | ||
* @since 9.0.0 | ||
*/ document(item: OperationObject | ((data: Data) => OperationObject)): this; | ||
*/ document(item: oas31.OperationObject | ((data: Data) => oas31.OperationObject)): this; | ||
/** | ||
@@ -114,4 +114,4 @@ * Add context variables to the validator, typescript only | ||
context: Context; | ||
openApi: OperationObject; | ||
openApi: oas31.OperationObject; | ||
}; | ||
export {}; |
@@ -20,2 +20,3 @@ export declare const version: string; | ||
import html, { HTMLContent } from "./functions/html"; | ||
import location from "./functions/location"; | ||
import Server, { defaultOptions } from "./classes/Server"; | ||
@@ -28,3 +29,3 @@ import ValueCollection from "./classes/ValueCollection"; | ||
import RuntimeError from "./classes/RuntimeError"; | ||
export { parseContent, parseURL, parseKV, writeHeaders, html, defaultOptions, Server, ValueCollection, Channel, Cookie, Throttler, Middleware, RuntimeError }; | ||
export { parseContent, parseURL, parseKV, writeHeaders, html, location, defaultOptions, Server, ValueCollection, Channel, Cookie, Throttler, Middleware, RuntimeError }; | ||
export type { HTMLContent }; |
@@ -8,2 +8,3 @@ import { UsableMiddleware } from "../../classes/Middleware"; | ||
import WsOpenContext from "../../classes/request/WsOpenContext"; | ||
import location from "../../functions/location"; | ||
import { Method } from "../global"; | ||
@@ -15,2 +16,3 @@ import { z } from "zod"; | ||
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; | ||
export type LocationCallback = (l: typeof location) => string[]; | ||
export type ZodResponse<Schema extends z.ZodTypeAny> = [z.infer<Schema>, null] | [null, z.ZodError<z.infer<Schema>>]; | ||
@@ -17,0 +19,0 @@ export type AnyClass = new (...args: any[]) => any; |
{ | ||
"name": "rjweb-server", | ||
"version": "9.5.5", | ||
"version": "9.5.6", | ||
"description": "Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS", | ||
@@ -52,6 +52,6 @@ "main": "./lib/cjs/index.js", | ||
"dependencies": { | ||
"@rjweb/utils": "^1.12.14", | ||
"@rjweb/utils": "^1.12.15", | ||
"content-disposition": "^0.5.4", | ||
"inquirer": "^9.2.21", | ||
"openapi3-ts": "^4.3.1", | ||
"inquirer": "^9.2.22", | ||
"openapi3-ts": "^4.3.2", | ||
"yargs": "^17.7.2", | ||
@@ -58,0 +58,0 @@ "zod": "^3.23.8" |
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
591129
177
14288
Updated@rjweb/utils@^1.12.15
Updatedinquirer@^9.2.22
Updatedopenapi3-ts@^4.3.2