Socket
Socket
Sign inDemoInstall

@aurelia/router-lite

Package Overview
Dependencies
Maintainers
1
Versions
263
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aurelia/router-lite - npm Package Compare versions

Comparing version 2.0.0-alpha.33 to 2.0.0-alpha.34

2

dist/types/component-agent.d.ts

@@ -9,3 +9,5 @@ import { LifecycleFlags } from '@aurelia/runtime';

import { Batch } from './util';
import { IRouteConfig } from './route';
export interface IRouteViewModel extends ICustomElementViewModel {
getRouteConfig?(parentDefinition: RouteDefinition | null, routeNode: RouteNode | null): IRouteConfig;
canLoad?(params: Params, next: RouteNode, current: RouteNode | null): boolean | NavigationInstruction | NavigationInstruction[] | Promise<boolean | NavigationInstruction | NavigationInstruction[]>;

@@ -12,0 +14,0 @@ load?(params: Params, next: RouteNode, current: RouteNode | null): void | Promise<void>;

7

dist/types/route-context.d.ts

@@ -10,3 +10,2 @@ import { IContainer, IModule } from '@aurelia/kernel';

import { IViewport } from './resources/viewport';
import { Routeable } from './route';
export interface IRouteContext extends RouteContext {

@@ -30,3 +29,2 @@ }

readonly parentContainer: IContainer;
get id(): number;
private readonly childViewportAgents;

@@ -66,3 +64,5 @@ readonly root: IRouteContext;

private readonly recognizer;
private _childRoutesConfigured;
constructor(viewportAgent: ViewportAgent | null, parent: IRouteContext | null, component: CustomElementDefinition, definition: RouteDefinition, parentContainer: IContainer);
private processDefinition;
/**

@@ -91,4 +91,3 @@ * Create a new `RouteContext` and register it in the provided container.

recognize(path: string, searchAncestor?: boolean): $RecognizedRoute | null;
addRoute(routeable: Promise<IModule>): Promise<void>;
addRoute(routeable: Exclude<Routeable, Promise<IModule>>): void | Promise<void>;
private addRoute;
private $addRoute;

@@ -95,0 +94,0 @@ resolveLazy(promise: Promise<IModule>): Promise<CustomElementDefinition> | CustomElementDefinition;

import { IContainer, IModule } from '@aurelia/kernel';
import { CustomElementDefinition } from '@aurelia/runtime-html';
import { Params } from './instructions';
import { RouteConfig, IChildRouteConfig, type Routeable, IRedirectRouteConfig } from './route';
import { RouteConfig, IChildRouteConfig, type Routeable } from './route';
import { IRouteContext } from './route-context';
import { RouteNode } from './route-tree';
export declare const defaultViewportName = "default";

@@ -19,8 +20,8 @@ export declare class RouteDefinition {

constructor(config: RouteConfig, component: CustomElementDefinition | null, parentDefinition: RouteDefinition | null);
static resolve(routeable: Promise<IModule>, parentDefinition: RouteDefinition | null, context: IRouteContext): RouteDefinition | Promise<RouteDefinition>;
static resolve(routeable: string | IChildRouteConfig, parentDefinition: RouteDefinition | null, context: IRouteContext): RouteDefinition;
static resolve(routeable: string | IChildRouteConfig | Promise<IModule>, parentDefinition: RouteDefinition | null): never;
static resolve(routeable: Exclude<Routeable, Promise<IModule> | string | IChildRouteConfig>, parentDefinition: RouteDefinition | null): RouteDefinition;
static resolve(routeable: Routeable, parentDefinition: RouteDefinition | null, context: IRouteContext): RouteDefinition | Promise<RouteDefinition>;
static resolveCustomElementDefinition(routeable: Exclude<Routeable, IRedirectRouteConfig>, context?: IRouteContext): CustomElementDefinition | Promise<CustomElementDefinition>;
static resolve(routeable: Promise<IModule>, parentDefinition: RouteDefinition | null, routeNode: RouteNode | null, context: IRouteContext): RouteDefinition | Promise<RouteDefinition>;
static resolve(routeable: string | IChildRouteConfig, parentDefinition: RouteDefinition | null, routeNode: RouteNode | null, context: IRouteContext): RouteDefinition;
static resolve(routeable: string | IChildRouteConfig | Promise<IModule>, parentDefinition: RouteDefinition | null, routeNode: RouteNode | null): never;
static resolve(routeable: Exclude<Routeable, Promise<IModule> | string | IChildRouteConfig>, parentDefinition: RouteDefinition | null, routeNode: RouteNode | null): RouteDefinition;
static resolve(routeable: Routeable, parentDefinition: RouteDefinition | null, routeNode: RouteNode | null, context: IRouteContext): RouteDefinition | Promise<RouteDefinition>;
private static createNavigationInstruction;
register(container: IContainer): void;

@@ -27,0 +28,0 @@ toUrlComponent(): string;

@@ -298,7 +298,7 @@ import { IContainer, ILogger } from '@aurelia/kernel';

* @param viewportAgent - The ViewportAgent hosting the component associated with this RouteContext. If the RouteContext for the component+viewport combination already exists, the ViewportAgent will be updated in case it changed.
* @param component - The custom element definition.
* @param componentDefinition - The custom element definition.
* @param container - The `controller.container` of the component hosting the viewport that the route will be loaded into.
*
*/
getRouteContext(viewportAgent: ViewportAgent | null, component: CustomElementDefinition, container: IContainer, parentDefinition: RouteDefinition | null): IRouteContext;
getRouteContext(viewportAgent: ViewportAgent | null, componentDefinition: CustomElementDefinition, componentInstance: IRouteViewModel | null, container: IContainer, parentDefinition: RouteDefinition | null): IRouteContext;
createViewportInstructions(instructionOrInstructions: NavigationInstruction | readonly NavigationInstruction[], options?: INavigationOptions): ViewportInstructionTree;

@@ -305,0 +305,0 @@ /**

{
"name": "@aurelia/router-lite",
"version": "2.0.0-alpha.33",
"version": "2.0.0-alpha.34",
"main": "dist/cjs/index.cjs",

@@ -47,9 +47,9 @@ "module": "dist/esm/index.mjs",

"dependencies": {
"@aurelia/kernel": "2.0.0-alpha.33",
"@aurelia/metadata": "2.0.0-alpha.33",
"@aurelia/platform": "2.0.0-alpha.33",
"@aurelia/platform-browser": "2.0.0-alpha.33",
"@aurelia/route-recognizer": "2.0.0-alpha.33",
"@aurelia/runtime": "2.0.0-alpha.33",
"@aurelia/runtime-html": "2.0.0-alpha.33"
"@aurelia/kernel": "2.0.0-alpha.34",
"@aurelia/metadata": "2.0.0-alpha.34",
"@aurelia/platform": "2.0.0-alpha.34",
"@aurelia/platform-browser": "2.0.0-alpha.34",
"@aurelia/route-recognizer": "2.0.0-alpha.34",
"@aurelia/runtime": "2.0.0-alpha.34",
"@aurelia/runtime-html": "2.0.0-alpha.34"
},

@@ -56,0 +56,0 @@ "devDependencies": {

@@ -11,4 +11,6 @@ import { Constructable, ILogger } from '@aurelia/kernel';

import { Batch } from './util';
import { IRouteConfig } from './route';
export interface IRouteViewModel extends ICustomElementViewModel {
getRouteConfig?(parentDefinition: RouteDefinition | null, routeNode: RouteNode | null): IRouteConfig;
canLoad?(params: Params, next: RouteNode, current: RouteNode | null): boolean | NavigationInstruction | NavigationInstruction[] | Promise<boolean | NavigationInstruction | NavigationInstruction[]>;

@@ -67,3 +69,3 @@ load?(params: Params, next: RouteNode, current: RouteNode | null): void | Promise<void>;

const container = ctx.container;
const definition = RouteDefinition.resolve(componentInstance.constructor as Constructable, ctx.definition);
const definition = RouteDefinition.resolve(componentInstance.constructor as Constructable, ctx.definition, null);
const controller = Controller.$el(container, componentInstance, hostController.host, null);

@@ -70,0 +72,0 @@

@@ -30,6 +30,2 @@ import { IContainer, ResourceDefinition, DI, InstanceProvider, Registration, ILogger, IModuleLoader, IModule, onResolve, noop } from '@aurelia/kernel';

export class RouteContext {
public get id(): number {
return this.container.id;
}
private readonly childViewportAgents: ViewportAgent[] = [];

@@ -119,2 +115,3 @@ public readonly root: IRouteContext;

private readonly recognizer: RouteRecognizer<RouteDefinition | Promise<RouteDefinition>>;
private _childRoutesConfigured: boolean = false;

@@ -160,6 +157,18 @@ public constructor(

this.recognizer = new RouteRecognizer();
this.processDefinition(definition);
}
private processDefinition(definition: RouteDefinition): void {
const promises: Promise<void>[] = [];
const allPromises: Promise<void>[] = [];
for (const child of definition.config.routes) {
const children = definition.config.routes;
const len = children.length;
if(len === 0) {
const getRouteConfig = (definition.component?.Type.prototype as IRouteViewModel)?.getRouteConfig;
this._childRoutesConfigured = getRouteConfig == null ? true : typeof getRouteConfig !== 'function';
return;
}
let i = 0;
for (; i < len; i++) {
const child = children[i];
if (child instanceof Promise) {

@@ -170,3 +179,3 @@ const p = this.addRoute(child);

} else {
const routeDef = RouteDefinition.resolve(child, definition, this);
const routeDef = RouteDefinition.resolve(child, definition, null, this);
if (routeDef instanceof Promise) {

@@ -194,2 +203,3 @@ if (isPartialChildRouteConfig(child) && child.path != null) {

}
this._childRoutesConfigured = true;

@@ -232,3 +242,3 @@ if (promises.length > 0) {

const router = container.get(IRouter);
const routeContext = router.getRouteContext(null, controller.definition, controller.container, null);
const routeContext = router.getRouteContext(null, controller.definition, controller.viewModel, controller.container, null);
container.register(Registration.instance(IRouteContext, routeContext));

@@ -318,4 +328,8 @@ routeContext.node = router.routeTree.root;

this.hostControllerProvider.prepare(hostController);
const routeDefinition = RouteDefinition.resolve(routeNode.component, this.definition);
const componentInstance = this.container.get<IRouteViewModel>(routeDefinition.component!.key);
const componentInstance = this.container.get<IRouteViewModel>(routeNode.component.key);
// this is the point where we can load the delayed (non-static) child route configuration by calling the getRouteConfig
if(!this._childRoutesConfigured) {
const routeDef = RouteDefinition.resolve(componentInstance, this.definition, routeNode);
this.processDefinition(routeDef);
}
const componentAgent = ComponentAgent.for(componentInstance, hostController, routeNode, this);

@@ -378,7 +392,7 @@

public addRoute(routeable: Promise<IModule>): Promise<void>;
public addRoute(routeable: Exclude<Routeable, Promise<IModule>>): void | Promise<void>;
public addRoute(routeable: Routeable): void | Promise<void> {
private addRoute(routeable: Promise<IModule>): Promise<void>;
private addRoute(routeable: Exclude<Routeable, Promise<IModule>>): void | Promise<void>;
private addRoute(routeable: Routeable): void | Promise<void> {
this.logger.trace(`addRoute(routeable:'${routeable}')`);
return onResolve(RouteDefinition.resolve(routeable, this.definition, this), routeDef => {
return onResolve(RouteDefinition.resolve(routeable, this.definition, null, this), routeDef => {
for (const path of routeDef.path) {

@@ -385,0 +399,0 @@ this.$addRoute(path, routeDef.caseSensitive, routeDef);

import { Metadata } from '@aurelia/metadata';
import {
emptyObject,
IContainer,

@@ -7,2 +8,3 @@ IModule,

Protocol,
Writable,
} from '@aurelia/kernel';

@@ -18,2 +20,3 @@ import {

Params,
ITypedNavigationInstruction_Component,
} from './instructions';

@@ -39,2 +42,4 @@ import {

} from './util';
import { IRouteViewModel } from './component-agent';
import { RouteNode } from './route-tree';

@@ -67,10 +72,32 @@ export const defaultViewportName = 'default';

public static resolve(routeable: Promise<IModule>, parentDefinition: RouteDefinition | null, context: IRouteContext): RouteDefinition | Promise<RouteDefinition>;
public static resolve(routeable: string | IChildRouteConfig, parentDefinition: RouteDefinition | null, context: IRouteContext): RouteDefinition;
public static resolve(routeable: string | IChildRouteConfig | Promise<IModule>, parentDefinition: RouteDefinition | null): never;
public static resolve(routeable: Exclude<Routeable, Promise<IModule> | string | IChildRouteConfig>, parentDefinition: RouteDefinition | null): RouteDefinition;
public static resolve(routeable: Routeable, parentDefinition: RouteDefinition | null, context: IRouteContext): RouteDefinition | Promise<RouteDefinition>;
public static resolve(routeable: Routeable, parentDefinition: RouteDefinition | null, context?: IRouteContext): RouteDefinition | Promise<RouteDefinition> {
if (isPartialRedirectRouteConfig(routeable)) {
return new RouteDefinition(RouteConfig.create(routeable, null), null, parentDefinition);
// Note on component instance: it is non-null for the root, and when the component agent is created via the route context (if the child routes are not yet configured).
public static resolve(routeable: Promise<IModule>, parentDefinition: RouteDefinition | null, routeNode: RouteNode | null, context: IRouteContext): RouteDefinition | Promise<RouteDefinition>;
public static resolve(routeable: string | IChildRouteConfig, parentDefinition: RouteDefinition | null, routeNode: RouteNode | null, context: IRouteContext): RouteDefinition;
public static resolve(routeable: string | IChildRouteConfig | Promise<IModule>, parentDefinition: RouteDefinition | null, routeNode: RouteNode | null): never;
public static resolve(routeable: Exclude<Routeable, Promise<IModule> | string | IChildRouteConfig>, parentDefinition: RouteDefinition | null, routeNode: RouteNode | null): RouteDefinition;
public static resolve(routeable: Routeable, parentDefinition: RouteDefinition | null, routeNode: RouteNode | null, context: IRouteContext): RouteDefinition | Promise<RouteDefinition>;
public static resolve(routeable: Routeable, parentDefinition: RouteDefinition | null, routeNode: RouteNode | null, context?: IRouteContext): RouteDefinition | Promise<RouteDefinition> {
if (isPartialRedirectRouteConfig(routeable)) return new RouteDefinition(RouteConfig.create(routeable, null), null, parentDefinition);
const instruction = this.createNavigationInstruction(routeable);
let ceDef: CustomElementDefinition | Promise<CustomElementDefinition>;
switch (instruction.type) {
case NavigationInstructionType.string: {
if (context === void 0) throw new Error(`When retrieving the RouteDefinition for a component name, a RouteContext (that can resolve it) must be provided`);
const component = context.container.find(CustomElement, instruction.value);
if (component === null) throw new Error(`Could not find a CustomElement named '${instruction.value}' in the current container scope of ${context}. This means the component is neither registered at Aurelia startup nor via the 'dependencies' decorator or static property.`);
ceDef = component;
break;
}
case NavigationInstructionType.CustomElementDefinition:
ceDef = instruction.value;
break;
case NavigationInstructionType.IRouteViewModel:
// Get the class from the constructor property. There might be static properties on it.
ceDef = CustomElement.getDefinition(instruction.value.constructor as RouteType);
break;
case NavigationInstructionType.Promise:
if (context === void 0) throw new Error(`RouteContext must be provided when resolving an imported module`);
ceDef = context.resolveLazy(instruction.value);
break;
}

@@ -81,7 +108,12 @@

// Note: RouteConfig is associated with Type, but RouteDefinition is associated with CustomElementDefinition.
return onResolve(this.resolveCustomElementDefinition(routeable, context), def => {
return onResolve(ceDef, def => {
let routeDefinition = $RouteDefinition.get(def);
const hasRouteConfigHook = instruction.type === NavigationInstructionType.IRouteViewModel && typeof (routeable as IRouteViewModel).getRouteConfig === 'function';
if (routeDefinition === null) {
const type = def.Type;
const config = isPartialChildRouteConfig(routeable)
let config: RouteConfig | null = null;
if(hasRouteConfigHook) {
config = RouteConfig.create((routeable as IRouteViewModel).getRouteConfig!(parentDefinition, routeNode) ?? emptyObject, type);
} else {
config = isPartialChildRouteConfig(routeable)
? Route.isConfigured(type)

@@ -91,5 +123,8 @@ ? Route.getConfig(type).applyChildRouteConfig(routeable)

: Route.getConfig(def.Type);
}
routeDefinition = new RouteDefinition(config, def, parentDefinition);
$RouteDefinition.define(routeDefinition, def);
} else if(routeDefinition.config.routes.length === 0 && hasRouteConfigHook) {
routeDefinition.applyChildRouteConfig((routeable as IRouteViewModel).getRouteConfig?.(parentDefinition, routeNode) as IChildRouteConfig ?? emptyObject);
}

@@ -100,33 +135,19 @@ return routeDefinition;

public static resolveCustomElementDefinition(
routeable: Exclude<Routeable, IRedirectRouteConfig>,
context?: IRouteContext,
): CustomElementDefinition | Promise<CustomElementDefinition> {
if (isPartialChildRouteConfig(routeable)) {
return this.resolveCustomElementDefinition(routeable.component, context);
}
private static createNavigationInstruction(routeable: Exclude<Routeable, IRedirectRouteConfig>): ITypedNavigationInstruction_Component {
return isPartialChildRouteConfig(routeable)
? this.createNavigationInstruction(routeable.component)
: TypedNavigationInstruction.create(routeable);
}
const typedInstruction = TypedNavigationInstruction.create(routeable);
switch (typedInstruction.type) {
case NavigationInstructionType.string: {
if (context === void 0) {
throw new Error(`When retrieving the RouteDefinition for a component name, a RouteContext (that can resolve it) must be provided`);
}
const component = context.container.find(CustomElement, typedInstruction.value);
if (component === null) {
throw new Error(`Could not find a CustomElement named '${typedInstruction.value}' in the current container scope of ${context}. This means the component is neither registered at Aurelia startup nor via the 'dependencies' decorator or static property.`);
}
return component as CustomElementDefinition;
}
case NavigationInstructionType.CustomElementDefinition:
return typedInstruction.value;
case NavigationInstructionType.IRouteViewModel:
// Get the class from the constructor property. There might be static properties on it.
return CustomElement.getDefinition(typedInstruction.value.constructor as RouteType);
case NavigationInstructionType.Promise:
if (context === void 0) {
throw new Error(`RouteContext must be provided when resolving an imported module`);
}
return context.resolveLazy(typedInstruction.value);
}
/** @internal */
private applyChildRouteConfig(config: IChildRouteConfig) {
(this as Writable<RouteDefinition>).config = config = this.config.applyChildRouteConfig(config);
(this as Writable<RouteDefinition>).hasExplicitPath = config.path !== null;
(this as Writable<RouteDefinition>).caseSensitive = config.caseSensitive ?? this.caseSensitive;
(this as Writable<RouteDefinition>).path = ensureArrayOfStrings(config.path ?? this.path);
(this as Writable<RouteDefinition>).redirectTo = config.redirectTo ?? null;
(this as Writable<RouteDefinition>).viewport = config.viewport ?? defaultViewportName;
(this as Writable<RouteDefinition>).id = ensureString(config.id ?? this.path);
(this as Writable<RouteDefinition>).data = config.data ?? {};
(this as Writable<RouteDefinition>).fallback = config.fallback ?? this.fallback;
}

@@ -133,0 +154,0 @@

@@ -500,3 +500,3 @@ import {

case NavigationInstructionType.CustomElementDefinition: {
const rd = RouteDefinition.resolve(vi.component.value, node.context.definition);
const rd = RouteDefinition.resolve(vi.component.value, node.context.definition, null);
const params = vi.params ?? emptyObject;

@@ -561,11 +561,11 @@ const rr = new $RecognizedRoute(

const rd = (ctx.childRoutes as RouteDefinition[]).find(x => x.id === fallback);
if(rd !== void 0) return createFallbackNode(log, rd, node, vi, append);
if (rd !== void 0) return createFallbackNode(log, rd, node, vi, append);
log.trace(`No route definition for the fallback '${fallback}' is found; trying to recognize the route.`);
const rr = ctx.recognize(fallback, true);
if(rr !== null) return createConfiguredNode(log, node, vi as ViewportInstruction<ITypedNavigationInstruction_ResolvedComponent>, append, rr);
if (rr !== null) return createConfiguredNode(log, node, vi as ViewportInstruction<ITypedNavigationInstruction_ResolvedComponent>, append, rr);
// fallback is not recognized as a configured route; treat as CE and look for a route definition.
log.trace(`The fallback '${fallback}' is not recognized as a route; treating as custom element name.`);
return createFallbackNode(log, RouteDefinition.resolve(fallback, ctx.definition, ctx), node, vi, append);
return createFallbackNode(log, RouteDefinition.resolve(fallback, ctx.definition, null, ctx), node, vi, append);
}

@@ -615,3 +615,3 @@

const router = ctx.container.get(IRouter);
const childCtx = router.getRouteContext(vpa, ced, vpa.hostController.container, ctx.definition);
const childCtx = router.getRouteContext(vpa, ced, null, vpa.hostController.container, ctx.definition);

@@ -618,0 +618,0 @@ log.trace('createConfiguredNode setting the context node');

@@ -90,3 +90,3 @@ import { Metadata } from '@aurelia/metadata';

if (!shallowEquals(current.params, next.params)) {
return 'invoke-lifecycles';
return 'replace';
}

@@ -93,0 +93,0 @@

@@ -559,3 +559,3 @@ import { isObject } from '@aurelia/metadata';

* @param viewportAgent - The ViewportAgent hosting the component associated with this RouteContext. If the RouteContext for the component+viewport combination already exists, the ViewportAgent will be updated in case it changed.
* @param component - The custom element definition.
* @param componentDefinition - The custom element definition.
* @param container - The `controller.container` of the component hosting the viewport that the route will be loaded into.

@@ -566,3 +566,4 @@ *

viewportAgent: ViewportAgent | null,
component: CustomElementDefinition,
componentDefinition: CustomElementDefinition,
componentInstance: IRouteViewModel | null,
container: IContainer,

@@ -573,3 +574,4 @@ parentDefinition: RouteDefinition | null,

const routeDefinition = RouteDefinition.resolve(component.Type, parentDefinition);
// getRouteConfig is prioritized over the statically configured routes via @route decorator.
const routeDefinition = RouteDefinition.resolve(typeof componentInstance?.getRouteConfig === 'function' ? componentInstance : componentDefinition.Type, parentDefinition, null);
let routeDefinitionLookup = this.vpaLookup.get(viewportAgent);

@@ -591,3 +593,3 @@ if (routeDefinitionLookup === void 0) {

parent,
component,
componentDefinition,
routeDefinition,

@@ -594,0 +596,0 @@ container,

Sorry, the diff of this file is too big to display

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

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