Create a new condition that applies if all conditions apply
The conditions that are chained together
Readonly
conditionsConditions that are chained together
Chain this condition with another condition
The condition to chain with
The new condition that applies if both conditions apply
const condition = new ContextConditionAnd([
new ContextConditionPath("/api/:id"),
new ContextConditionMethod("GET"),
]);
const other = new ContextConditionPath("/api/:id2");
const newCondition = condition.and(other);
Check if the condition applies to a request (used for routing) (parses the request itself, so use ContextCondition#parse for performance reasons)
Request to check
Whether the condition applies to the request
Use #parse().applies
instead (For performance reasons, as this method parses the request itself and subRequest again)
Chain this condition with another condition (used for sub-routing)
Check if the condition is equal to another condition
Condition to check
Whether the conditions are equal
const condition = new ContextConditionAnd([
new ContextConditionPath("/api/:id"),
new ContextConditionMethod("GET"),
]);
const other = new ContextConditionAnd([
new ContextConditionPath("/api/:id"),
new ContextConditionMethod("GET"),
]);
const other2 = new ContextConditionAnd([
new ContextConditionPath("/api/:id"),
new ContextConditionMethod("POST"),
]);
condition.equals(other) // true
condition.equals(other2) // false
Get info about the condition (used for collecting info about conditions and squashing them together)
Info about the condition (used for collecting info about conditions and squashing them together)
const condition = new ContextConditionAnd([
new ContextConditionPath("/api/:id"),
new ContextConditionMethod("GET"),
]);
const info = condition.info(); // { path: "/api/:id" , method: "GET", path2: undefined }
Get info about the condition (used for collecting info about conditions and squashing them together)
Info about the condition (used for collecting info about conditions and squashing them together)
const condition = new ContextConditionAnd([
new ContextConditionPath("/api/:id"),
new ContextConditionMethod("GET"),
]);
const info = condition.infoJson(); // { path: "/api/:id" , method: "GET", path2: undefined }
Parse the condition (used for routing and sub-routing)
The request to parse
The result of the parsing
const condition = new ContextConditionAnd([
new ContextConditionPath("/api/:id"),
new ContextConditionMethod("GET"),
]);
const result = condition.parse({ method: "GET", path: "/api/123", params: {} });
result.applies // true
result.parameters() // { id: "123" }
result.subRequest({ method: "GET", path: "/api/123", params: {} }) // { method: "GET", path: "", params: { id: "123" } }
Check if the condition applies to a request (used for routing) (parses the request itself, so use ContextCondition#parse for performance reasons)
Request to check
Parameters of the condition
Use #parse().parameters
instead (For performance reasons, as this method parses the request itself and appliesTo again)
Get JSON representation of the condition (used for collecting info about conditions and squashing them together)
JSON representation of the condition (used for collecting info about conditions and squashing them together)
const condition = new ContextConditionAnd([
new ContextConditionPath("/api/:id"),
new ContextConditionMethod("GET"),
]);
const json = condition.toJson(); // { type: "and", conditions: [{ type: "path", path: "/api/:id" }, { type: "method", method: "GET" }] }
Generated using TypeDoc
Condition that applies if all conditions apply
Example