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

@aurelia/kernel

Package Overview
Dependencies
Maintainers
1
Versions
1121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aurelia/kernel - npm Package Compare versions

Comparing version 2.1.0-dev.202407271309 to 2.1.0-dev.202409041326

7

CHANGELOG.md

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

<a name="2.0.0-beta.21"></a>
# 2.0.0-beta.21 (2024-08-08)
### Bug Fixes:
* **state:** ensure all actions queued are called (#2023) ([062f398](https://github.com/aurelia/aurelia/commit/062f398))
<a name="2.0.0-beta.20"></a>

@@ -8,0 +15,0 @@ # 2.0.0-beta.20 (2024-07-07)

10

dist/types/functions.d.ts
import { Constructable, Overwrite } from './interfaces';
import { MaybePromise } from './utilities';
/**

@@ -81,4 +82,2 @@ * Efficiently determine whether the provided property key is numeric

export declare const isNativeFunction: (fn: Function) => boolean;
type UnwrapPromise<T> = T extends Promise<infer R> ? R : T;
type MaybePromise<T> = T extends Promise<infer R> ? (T | R) : (T | Promise<T>);
/**

@@ -89,3 +88,7 @@ * Normalize a potential promise via a callback, to ensure things stay synchronous when they can.

*/
export declare const onResolve: <TValue, TRet>(maybePromise: TValue, resolveCallback: (value: UnwrapPromise<TValue>) => TRet) => MaybePromise<TRet>;
export declare const onResolve: {
<TValue, TRet>(maybePromise: Promise<TValue>, resolveCallback: (value: TValue) => MaybePromise<TRet>): Promise<TRet>;
<TValue, TRet>(maybePromise: TValue extends Promise<unknown> ? never : TValue, resolveCallback: (value: TValue) => TRet): TRet extends Promise<infer R> ? Promise<R> : TRet;
<TValue, TRet>(maybePromise: MaybePromise<TValue>, resolveCallback: (value: TValue) => MaybePromise<TRet>): MaybePromise<TRet>;
};
/**

@@ -101,3 +104,2 @@ * Normalize an array of potential promises, to ensure things stay synchronous when they can.

export declare const onResolveAll: (...maybePromises: unknown[]) => void | Promise<void>;
export {};
//# sourceMappingURL=functions.d.ts.map

2

dist/types/index.d.ts

@@ -13,3 +13,3 @@ export { IPlatform, } from './platform';

export { isArrayIndex, camelCase, kebabCase, pascalCase, toArray, bound, mergeArrays, firstDefined, getPrototypeChain, isNativeFunction, onResolve, onResolveAll, } from './functions';
export { isObject, isArray, isMap, isSet, isPromise, isFunction, isNumber, isString, isSymbol, areEqual, createLookup, type AnyFunction, type FunctionPropNames, type MaybePromise, } from './utilities';
export { isObject, isArray, isMap, isSet, isPromise, isFunction, isObjectOrFunction, isNumber, isString, isSymbol, areEqual, createLookup, type AnyFunction, type FunctionPropNames, type MaybePromise, } from './utilities';
//# sourceMappingURL=index.d.ts.map

@@ -28,6 +28,62 @@ /**

* This does not work for objects across different realms (e.g., iframes).
* An utility to be shared among core packages for better size optimization
* An utility to be shared among core packages only for better size optimization
*
* This is semi private to core packages and applications should not depend on this.
*/
export declare const isObject: (v: unknown) => v is object;
/**
* IMPORTANT: This is semi private to core packages and applications should not depend on this.
*
* Determine whether a value is an object.
*
* Uses `typeof` to guarantee this works cross-realm, which is where `instanceof Object` might fail.
*
* Some environments where these issues are known to arise:
* - same-origin iframes (accessing the other realm via `window.top`)
* - `jest`.
*
* The exact test is:
* ```ts
* typeof value === 'object' && value !== null || typeof value === 'function'
* ```
*
* @param value - The value to test.
* @returns `true` if the value is an object, otherwise `false`.
* Also performs a type assertion that defaults to `value is Object | Function` which, if the input type is a union with an object type, will infer the correct type.
* This can be overridden with the generic type argument.
*
* @example
*
* ```ts
* class Foo {
* bar = 42;
* }
*
* function doStuff(input?: Foo | null) {
* input.bar; // Object is possibly 'null' or 'undefined'
*
* // input has an object type in its union (Foo) so that type will be extracted for the 'true' condition
* if (isObject(input)) {
* input.bar; // OK (input is now typed as Foo)
* }
* }
*
* function doOtherStuff(input: unknown) {
* input.bar; // Object is of type 'unknown'
*
* // input is 'unknown' so there is no union type to match and it will default to 'Object | Function'
* if (isObject(input)) {
* input.bar; // Property 'bar' does not exist on type 'Object | Function'
* }
*
* // if we know for sure that, if input is an object, it must be a specific type, we can explicitly tell the function to assert that for us
* if (isObject<Foo>(input)) {
* input.bar; // OK (input is now typed as Foo)
* }
* }
* ```
*
*/
export declare function isObjectOrFunction<T extends object = Object | Function>(value: unknown): value is T;
/**
* Returns true if the value is a function

@@ -34,0 +90,0 @@ * An utility to be shared among core packages for better size optimization

{
"name": "@aurelia/kernel",
"version": "2.1.0-dev.202407271309",
"version": "2.1.0-dev.202409041326",
"main": "dist/cjs/index.cjs",

@@ -57,4 +57,4 @@ "module": "dist/esm/index.mjs",

"dependencies": {
"@aurelia/metadata": "2.1.0-dev.202407271309",
"@aurelia/platform": "2.1.0-dev.202407271309"
"@aurelia/metadata": "2.1.0-dev.202409041326",
"@aurelia/platform": "2.1.0-dev.202409041326"
},

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

/* eslint-disable @typescript-eslint/no-this-alias */
/* eslint-disable @typescript-eslint/strict-boolean-expressions, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any */
import { isObject } from '@aurelia/metadata';
import {

@@ -35,3 +34,3 @@ IContainer,

import { ResourceDefinition, StaticResourceType, resourceBaseName, type ResourceType } from './resource';
import { getMetadata, isFunction, isString } from './utilities';
import { getMetadata, isFunction, isObjectOrFunction, isString } from './utilities';

@@ -170,3 +169,3 @@ export const registrableMetadataKey = Symbol.for('au:registrable');

current = params[i];
if (!isObject(current)) {
if (!isObjectOrFunction(current)) {
continue;

@@ -219,3 +218,3 @@ }

value = current[keys[j]];
if (!isObject(value)) {
if (!isObjectOrFunction(value)) {
continue;

@@ -222,0 +221,0 @@ }

import { ErrorNames, createMappedError } from './errors';
import { Constructable, Overwrite } from './interfaces';
import { createLookup, isPromise, objectAssign } from './utilities';
import { createLookup, isPromise, MaybePromise, objectAssign } from './utilities';

@@ -403,5 +403,2 @@ /**

type UnwrapPromise<T> = T extends Promise<infer R> ? R : T;
type MaybePromise<T> = T extends Promise<infer R> ? (T | R) : (T | Promise<T>);
/**

@@ -412,12 +409,69 @@ * Normalize a potential promise via a callback, to ensure things stay synchronous when they can.

*/
export const onResolve = <TValue, TRet>(
maybePromise: TValue,
resolveCallback: (value: UnwrapPromise<TValue>) => TRet,
): MaybePromise<TRet> => {
if (maybePromise instanceof Promise) {
return maybePromise.then(resolveCallback) as MaybePromise<TRet>;
export const onResolve: {
// used for async code paths
<TValue, TRet>(
maybePromise: Promise<TValue>,
resolveCallback: (value: TValue) => MaybePromise<TRet>,
): Promise<TRet>;
// used for express synchronous only code paths
<TValue, TRet>(
maybePromise: TValue extends Promise<unknown> ? never : TValue,
resolveCallback: (value: TValue) => TRet,
): TRet extends Promise<infer R> ? Promise<R> : TRet;
// used for mixed code paths
<TValue, TRet>(
maybePromise: MaybePromise<TValue>,
resolveCallback: (value: TValue) => MaybePromise<TRet>,
): MaybePromise<TRet>;
}
// implementation
= (maybePromise, resolveCallback) => {
if (isPromise(maybePromise)) {
return maybePromise.then(resolveCallback);
}
return resolveCallback(maybePromise as UnwrapPromise<TValue>) as MaybePromise<TRet>;
return resolveCallback(maybePromise);
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function testOnResolve() {
/* eslint-disable @typescript-eslint/no-floating-promises, @typescript-eslint/ban-ts-comment */
onResolve(Promise.resolve(1), (value) => value === 1);
onResolve(1, value => value === 1);
// @ts-expect-error
onResolve(1, value => value === Promise.resolve(1));
// @ts-expect-error
onResolve(Promise.resolve(1), value => value === Promise.resolve(1));
const ret = onResolve(Promise.resolve(1), (value) => value === 1);
// @ts-expect-error
if (ret === false) {
// nothing
}
// @ts-expect-error
const ret2 = onResolve(1, value => value === Promise.resolve(1));
if (ret2 === false) {
// nothing
}
type Component = {
canDeactivate?: () => boolean | Promise<boolean>;
};
const cmp: Component = {};
onResolve(
cmp.canDeactivate?.(),
canDeactivate => {
if (canDeactivate === false) {
// nothing
}
});
/* eslint-enable @typescript-eslint/no-floating-promises, @typescript-eslint/ban-ts-comment */
}
/**

@@ -424,0 +478,0 @@ * Normalize an array of potential promises, to ensure things stay synchronous when they can.

@@ -151,2 +151,3 @@ export {

isFunction,
isObjectOrFunction,
isNumber,

@@ -153,0 +154,0 @@ isString,

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

* This does not work for objects across different realms (e.g., iframes).
* An utility to be shared among core packages for better size optimization
* An utility to be shared among core packages only for better size optimization
*
* This is semi private to core packages and applications should not depend on this.
*/

@@ -47,2 +49,60 @@ export const isObject = (v: unknown): v is object => v instanceof Object;

/**
* IMPORTANT: This is semi private to core packages and applications should not depend on this.
*
* Determine whether a value is an object.
*
* Uses `typeof` to guarantee this works cross-realm, which is where `instanceof Object` might fail.
*
* Some environments where these issues are known to arise:
* - same-origin iframes (accessing the other realm via `window.top`)
* - `jest`.
*
* The exact test is:
* ```ts
* typeof value === 'object' && value !== null || typeof value === 'function'
* ```
*
* @param value - The value to test.
* @returns `true` if the value is an object, otherwise `false`.
* Also performs a type assertion that defaults to `value is Object | Function` which, if the input type is a union with an object type, will infer the correct type.
* This can be overridden with the generic type argument.
*
* @example
*
* ```ts
* class Foo {
* bar = 42;
* }
*
* function doStuff(input?: Foo | null) {
* input.bar; // Object is possibly 'null' or 'undefined'
*
* // input has an object type in its union (Foo) so that type will be extracted for the 'true' condition
* if (isObject(input)) {
* input.bar; // OK (input is now typed as Foo)
* }
* }
*
* function doOtherStuff(input: unknown) {
* input.bar; // Object is of type 'unknown'
*
* // input is 'unknown' so there is no union type to match and it will default to 'Object | Function'
* if (isObject(input)) {
* input.bar; // Property 'bar' does not exist on type 'Object | Function'
* }
*
* // if we know for sure that, if input is an object, it must be a specific type, we can explicitly tell the function to assert that for us
* if (isObject<Foo>(input)) {
* input.bar; // OK (input is now typed as Foo)
* }
* }
* ```
*
*/
// eslint-disable-next-line @typescript-eslint/ban-types
export function isObjectOrFunction<T extends object = Object | Function>(value: unknown): value is T {
return typeof value === 'object' && value !== null || typeof value === 'function';
}
/**
* Returns true if the value is a function

@@ -49,0 +109,0 @@ * An utility to be shared among core packages for better size optimization

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