Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aurelia/route-recognizer

Package Overview
Dependencies
Maintainers
1
Versions
629
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aurelia/route-recognizer - npm Package Compare versions

Comparing version 2.0.0-beta.9 to 2.0.0-beta.10

14

CHANGELOG.md

@@ -6,2 +6,16 @@ # Change Log

<a name="2.0.0-beta.10"></a>
# 2.0.0-beta.10 (2024-01-26)
### Features:
* **route-recognizer:** support for route parameter constraints (#1862) ([8f29cfd](https://github.com/aurelia/aurelia/commit/8f29cfd))
* **route-recognizer:** parameter constraint ([8f29cfd](https://github.com/aurelia/aurelia/commit/8f29cfd))
### Refactorings:
* **router-lite:** constrained route for Router#load ([8f29cfd](https://github.com/aurelia/aurelia/commit/8f29cfd))
* **route-recognizer:** removed auto end-markers from patterns ([8f29cfd](https://github.com/aurelia/aurelia/commit/8f29cfd))
<a name="2.0.0-beta.9"></a>

@@ -8,0 +22,0 @@ # 2.0.0-beta.9 (2023-12-12)

4

dist/types/index.d.ts

@@ -10,3 +10,5 @@ export interface IConfigurableRoute<T> {

readonly isStar: boolean;
constructor(name: string, isOptional: boolean, isStar: boolean);
readonly pattern: RegExp | null;
constructor(name: string, isOptional: boolean, isStar: boolean, pattern: RegExp | null);
satisfiesPattern(value: string): boolean;
}

@@ -13,0 +15,0 @@ export declare class ConfigurableRoute<T> implements IConfigurableRoute<T> {

{
"name": "@aurelia/route-recognizer",
"version": "2.0.0-beta.9",
"version": "2.0.0-beta.10",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
"exports": {
"types": "./dist/types/index.d.ts",
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.mjs",
"development": "./dist/esm/index.dev.mjs"
".": {
"types": "./dist/types/index.d.ts",
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.mjs",
"development": "./dist/esm/index.dev.mjs"
},
"./development": {
"types": "./dist/types/index.d.ts",
"require": "./dist/cjs/index.dev.cjs",
"import": "./dist/esm/index.dev.mjs"
}
},

@@ -12,0 +19,0 @@ "types": "dist/types/index.d.ts",

@@ -12,3 +12,10 @@ export interface IConfigurableRoute<T> {

public readonly isStar: boolean,
public readonly pattern: RegExp | null,
){}
public satisfiesPattern(value: string): boolean {
if (this.pattern === null) return true;
this.pattern.lastIndex = 0;
return this.pattern.test(value);
}
}

@@ -61,2 +68,5 @@

public endpoint: Endpoint<T>;
private params: Record<string, string | undefined> | null = null;
private isConstrained: boolean = false;
private satisfiesConstraints: boolean | null = null;

@@ -128,2 +138,5 @@ public constructor(

chars.push(ch);
this.isConstrained = this.isConstrained
|| (stateToAdd as AnyState<T>).isDynamic
&& ((stateToAdd as AnyState<T>).segment as DynamicSegment<T>)!.isConstrained;
if ((stateToAdd as AnyState<T>).endpoint !== null) {

@@ -139,3 +152,4 @@ this.endpoint = (stateToAdd as AnyState<T>).endpoint!;

public finalize(): void {
/** @internal */
public _finalize(): boolean {
function collectSkippedStates(

@@ -165,8 +179,15 @@ skippedStates: DynamicState<T>[],

collectSkippedStates(this.skippedStates, this.head);
if (!this.isConstrained) return true;
this._getParams();
return this.satisfiesConstraints!;
}
public getParams(): Record<string, string | undefined> {
/** @internal */
public _getParams(): Record<string, string | undefined> {
let params = this.params;
if (params != null) return params;
const { states, chars, endpoint } = this;
const params: Record<string, string | undefined> = {};
params = {};
this.satisfiesConstraints = true;
// First initialize all properties with undefined so they all exist (even if they're not filled, e.g. non-matched optional params)

@@ -180,3 +201,4 @@ for (const param of endpoint.params) {

if (state.isDynamic) {
const name = state.segment.name;
const segment = state.segment;
const name = segment.name;
if (params[name] === void 0) {

@@ -187,5 +209,18 @@ params[name] = chars[i];

}
// check for constraint if this state's segment is constrained
// and the state is the last dynamic state in a series of dynamic states.
// null fallback is used, as a star segment can also be a dynamic segment, but without a pattern.
const checkConstraint = state.isConstrained
&& !Object.is(states[i + 1]?.segment, segment);
if (!checkConstraint) continue;
this.satisfiesConstraints = this.satisfiesConstraints && state.satisfiesConstraint(params[name]!);
}
}
if(this.satisfiesConstraints) {
this.params = params;
}
return params;

@@ -322,3 +357,3 @@ }

public getSolution(): Candidate<T> | null {
const candidates = this.candidates.filter(hasEndpoint);
const candidates = this.candidates.filter(x => hasEndpoint(x) && x._finalize());
if (candidates.length === 0) {

@@ -328,6 +363,2 @@ return null;

for (const candidate of candidates) {
candidate.finalize();
}
candidates.sort(compareChains);

@@ -360,2 +391,4 @@

const routeParameterPattern = /^:(?<name>[^?\s{}]+)(?:\{\{(?<constraint>.+)\}\})?(?<optional>\?)?$/g;
export class RouteRecognizer<T> {

@@ -380,3 +413,3 @@ private readonly rootState: SeparatorState<T> = new State(null, null, '') as SeparatorState<T>;

params = endpoint.params;
// add residue iff the last parameter is not a star segment.
// add residue iff the last parameter is not a star segment.
if (addResidue && !(params[params.length - 1]?.isStar ?? false)) {

@@ -409,7 +442,11 @@ endpoint.residualEndpoint = this.$add({ ...routeOrRoutes, path: `${routeOrRoutes.path}/*${RESIDUE}` }, true);

case ':': { // route parameter
const isOptional = part.endsWith('?');
const name = isOptional ? part.slice(1, -1) : part.slice(1);
routeParameterPattern.lastIndex = 0;
const match = routeParameterPattern.exec(part);
const { name, optional } = match?.groups ?? {};
const isOptional = optional === '?';
if (name === RESIDUE) throw new Error(`Invalid parameter name; usage of the reserved parameter name '${RESIDUE}' is used.`);
params.push(new Parameter(name, isOptional, false));
state = new DynamicSegment<T>(name, isOptional).appendTo(state);
const constraint = match?.groups?.constraint;
const pattern: RegExp | null = constraint != null ? new RegExp(constraint) : null;
params.push(new Parameter(name, isOptional, false, pattern));
state = new DynamicSegment<T>(name, isOptional, pattern).appendTo(state);
break;

@@ -426,3 +463,3 @@ }

}
params.push(new Parameter(name, true, true));
params.push(new Parameter(name, true, true, null));
state = new StarSegment<T>(name, kind).appendTo(state);

@@ -480,3 +517,3 @@ break;

const { endpoint } = candidate;
const params = candidate.getParams();
const params = candidate._getParams();

@@ -550,2 +587,3 @@ return new RecognizedRoute<T>(endpoint, params);

public readonly length: number;
public readonly isConstrained: boolean = false;

@@ -563,2 +601,3 @@ public constructor(

this.isOptional = segment.optional;
this.isConstrained = segment.isConstrained;
break;

@@ -633,2 +672,8 @@ case SegmentKind.star:

}
public satisfiesConstraint(value: string): boolean {
return this.isConstrained
? (this.segment as DynamicSegment<T>).satisfiesPattern(value)
: true;
}
}

@@ -697,2 +742,3 @@

public get kind(): SegmentKind.dynamic { return SegmentKind.dynamic; }
public readonly isConstrained: boolean;

@@ -702,3 +748,7 @@ public constructor(

public readonly optional: boolean,
) {}
public readonly pattern: RegExp | null,
) {
if (pattern === void 0) throw new Error(`Pattern is undefined`);
this.isConstrained = pattern !== null;
}

@@ -721,2 +771,8 @@ public appendTo(state: AnyState<T>): DynamicState<T> {

}
public satisfiesPattern(value: string): boolean {
if (this.pattern === null) return true;
this.pattern.lastIndex = 0;
return this.pattern.test(value);
}
}

@@ -723,0 +779,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc