Socket
Socket
Sign inDemoInstall

@loopback/context

Package Overview
Dependencies
Maintainers
17
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loopback/context - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

11

CHANGELOG.md

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

<a name="0.4.0"></a>
# [0.4.0](https://github.com/strongloop/loopback-next/compare/@loopback/context@0.3.0...@loopback/context@0.4.0) (2018-03-23)
### Features
* **context:** add optional typing for Binding ([3c494fa](https://github.com/strongloop/loopback-next/commit/3c494fa))
<a name="0.3.0"></a>

@@ -8,0 +19,0 @@ # [0.3.0](https://github.com/strongloop/loopback-next/compare/@loopback/context@0.2.4...@loopback/context@0.3.0) (2018-03-21)

14

dist/src/binding.d.ts

@@ -80,3 +80,3 @@ import { Context } from './context';

}
export declare class Binding {
export declare class Binding<T = BoundValue> {
isLocked: boolean;

@@ -116,3 +116,3 @@ static PROPERTY_SEPARATOR: string;

private _getValue;
valueConstructor: Constructor<BoundValue>;
valueConstructor: Constructor<T>;
constructor(key: string, isLocked?: boolean);

@@ -149,3 +149,3 @@ /**

*/
getValue(ctx: Context, session?: ResolutionSession): ValueOrPromise<BoundValue>;
getValue(ctx: Context, session?: ResolutionSession): ValueOrPromise<T>;
lock(): this;

@@ -166,3 +166,3 @@ tag(tagName: string | string[]): this;

*/
to(value: BoundValue): this;
to(value: T): this;
/**

@@ -186,3 +186,3 @@ * Bind the key to a computed (dynamic) value.

*/
toDynamicValue(factoryFn: () => ValueOrPromise<BoundValue>): this;
toDynamicValue(factoryFn: () => ValueOrPromise<T>): this;
/**

@@ -204,3 +204,3 @@ * Bind the key to a value computed by a Provider.

*/
toProvider<T>(providerClass: Constructor<Provider<T>>): this;
toProvider(providerClass: Constructor<Provider<T>>): this;
/**

@@ -213,5 +213,5 @@ * Bind the key to an instance of the given class.

*/
toClass<T>(ctor: Constructor<T>): this;
toClass(ctor: Constructor<T>): this;
unlock(): this;
toJSON(): Object;
}

@@ -89,4 +89,2 @@ "use strict";

})(BindingType = exports.BindingType || (exports.BindingType = {}));
// FIXME(bajtos) The binding class should be parameterized by the value
// type stored
class Binding {

@@ -93,0 +91,0 @@ constructor(key, isLocked = false) {

import { Binding } from './binding';
import { BoundValue } from './value-promise';
import { ResolutionOptions, ResolutionSession } from './resolution-session';

@@ -25,3 +26,3 @@ import { ValueOrPromise } from '.';

*/
bind(key: string): Binding;
bind<T = BoundValue>(key: string): Binding<T>;
/**

@@ -84,3 +85,3 @@ * Unbind a binding from the context. No parent contexts will be checked. If

findByTag(pattern: string | RegExp): Readonly<Binding>[];
protected _mergeWithParent(childList: Readonly<Binding>[], parentList?: Readonly<Binding>[]): Readonly<Binding>[];
protected _mergeWithParent(childList: Readonly<Binding>[], parentList?: Readonly<Binding>[]): Readonly<Binding<any>>[];
/**

@@ -87,0 +88,0 @@ * Get the value bound to the given key, throw an error when no value was

@@ -31,7 +31,7 @@ /**

/**
* Get nested properties by path
* @param value Value of an object
* Get nested properties of an object by path
* @param value Value of the source object
* @param path Path to the property
*/
export declare function getDeepProperty(value: BoundValue, path: string): BoundValue;
export declare function getDeepProperty<OUT = BoundValue, IN = BoundValue>(value: IN, path: string): OUT | undefined;
/**

@@ -38,0 +38,0 @@ * Resolve entries of an object into a new object with the same keys. If one or

@@ -22,15 +22,16 @@ "use strict";

/**
* Get nested properties by path
* @param value Value of an object
* Get nested properties of an object by path
* @param value Value of the source object
* @param path Path to the property
*/
function getDeepProperty(value, path) {
let result = value;
const props = path.split('.').filter(Boolean);
for (const p of props) {
if (value == null) {
return value;
if (result == null) {
return undefined;
}
value = value[p];
result = result[p];
}
return value;
return result;
}

@@ -37,0 +38,0 @@ exports.getDeepProperty = getDeepProperty;

{
"name": "@loopback/context",
"version": "0.3.0",
"version": "0.4.0",
"description": "LoopBack's container for Inversion of Control",

@@ -23,3 +23,3 @@ "engines": {

"dependencies": {
"@loopback/metadata": "^0.3.0",
"@loopback/metadata": "^0.3.1",
"debug": "^3.1.0",

@@ -29,4 +29,4 @@ "uuid": "^3.2.1"

"devDependencies": {
"@loopback/build": "^0.3.2",
"@loopback/testlab": "^0.4.0",
"@loopback/build": "^0.3.3",
"@loopback/testlab": "^0.4.1",
"@types/bluebird": "^3.5.18",

@@ -33,0 +33,0 @@ "@types/debug": "^0.0.30",

@@ -87,3 +87,4 @@ # @loopback/context

IBM/StrongLoop is an active supporter of open source and welcomes contributions to our projects as well as those of the Node.js community in general. For more information on how to contribute please refer to the [Contribution Guide](https://loopback.io/doc/en/contrib/index.html).
- [Guidelines](https://github.com/strongloop/loopback-next/blob/master/docs/CONTRIBUTING.md)
- [Join the team](https://github.com/strongloop/loopback-next/issues/110)

@@ -90,0 +91,0 @@ ## Tests

@@ -99,5 +99,3 @@ // Copyright IBM Corp. 2017,2018. All Rights Reserved.

// FIXME(bajtos) The binding class should be parameterized by the value
// type stored
export class Binding {
export class Binding<T = BoundValue> {
static PROPERTY_SEPARATOR = '#';

@@ -154,11 +152,11 @@

private _cache: WeakMap<Context, BoundValue>;
private _cache: WeakMap<Context, T>;
private _getValue: (
ctx?: Context,
session?: ResolutionSession,
) => ValueOrPromise<BoundValue>;
) => ValueOrPromise<T>;
// For bindings bound via toClass, this property contains the constructor
// function
public valueConstructor: Constructor<BoundValue>;
public valueConstructor: Constructor<T>;

@@ -177,6 +175,6 @@ constructor(key: string, public isLocked: boolean = false) {

ctx: Context,
result: ValueOrPromise<BoundValue>,
): ValueOrPromise<BoundValue> {
result: ValueOrPromise<T>,
): ValueOrPromise<T> {
// Initialize the cache as a weakmap keyed by context
if (!this._cache) this._cache = new WeakMap<Context, BoundValue>();
if (!this._cache) this._cache = new WeakMap<Context, T>();
if (isPromiseLike(result)) {

@@ -232,6 +230,3 @@ if (this.scope === BindingScope.SINGLETON) {

*/
getValue(
ctx: Context,
session?: ResolutionSession,
): ValueOrPromise<BoundValue> {
getValue(ctx: Context, session?: ResolutionSession): ValueOrPromise<T> {
/* istanbul ignore if */

@@ -246,7 +241,7 @@ if (debug.enabled) {

if (ownerCtx && this._cache.has(ownerCtx)) {
return this._cache.get(ownerCtx);
return this._cache.get(ownerCtx)!;
}
} else if (this.scope === BindingScope.CONTEXT) {
if (this._cache.has(ctx)) {
return this._cache.get(ctx);
return this._cache.get(ctx)!;
}

@@ -301,3 +296,3 @@ }

*/
to(value: BoundValue): this {
to(value: T): this {
if (isPromiseLike(value)) {

@@ -351,3 +346,3 @@ // Promises are a construct primarily intended for flow control:

*/
toDynamicValue(factoryFn: () => ValueOrPromise<BoundValue>): this {
toDynamicValue(factoryFn: () => ValueOrPromise<T>): this {
/* istanbul ignore if */

@@ -378,3 +373,3 @@ if (debug.enabled) {

*/
public toProvider<T>(providerClass: Constructor<Provider<T>>): this {
public toProvider(providerClass: Constructor<Provider<T>>): this {
/* istanbul ignore if */

@@ -407,3 +402,3 @@ if (debug.enabled) {

*/
toClass<T>(ctor: Constructor<T>): this {
toClass(ctor: Constructor<T>): this {
/* istanbul ignore if */

@@ -410,0 +405,0 @@ if (debug.enabled) {

@@ -7,3 +7,3 @@ // Copyright IBM Corp. 2017,2018. All Rights Reserved.

import {Binding} from './binding';
import {isPromiseLike, getDeepProperty} from './value-promise';
import {isPromiseLike, getDeepProperty, BoundValue} from './value-promise';
import {ResolutionOptions, ResolutionSession} from './resolution-session';

@@ -47,3 +47,3 @@

*/
bind(key: string): Binding {
bind<T = BoundValue>(key: string): Binding<T> {
/* istanbul ignore if */

@@ -62,3 +62,3 @@ if (debug.enabled) {

const binding = new Binding(key);
const binding = new Binding<T>(key);
this.registry.set(key, binding);

@@ -435,6 +435,6 @@ return binding;

if (isPromiseLike(boundValue)) {
return boundValue.then(v => getDeepProperty(v, path) as T);
return boundValue.then(v => getDeepProperty<BoundValue, T>(v, path));
}
return getDeepProperty(boundValue, path) as T;
return getDeepProperty<BoundValue, T>(boundValue, path);
}

@@ -441,0 +441,0 @@

@@ -49,15 +49,19 @@ // Copyright IBM Corp. 2017,2018. All Rights Reserved.

/**
* Get nested properties by path
* @param value Value of an object
* Get nested properties of an object by path
* @param value Value of the source object
* @param path Path to the property
*/
export function getDeepProperty(value: BoundValue, path: string): BoundValue {
export function getDeepProperty<OUT = BoundValue, IN = BoundValue>(
value: IN,
path: string,
): OUT | undefined {
let result: BoundValue = value;
const props = path.split('.').filter(Boolean);
for (const p of props) {
if (value == null) {
return value;
if (result == null) {
return undefined;
}
value = value[p];
result = result[p];
}
return value;
return <OUT>result;
}

@@ -64,0 +68,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

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