Socket
Socket
Sign inDemoInstall

@loopback/metadata

Package Overview
Dependencies
Maintainers
18
Versions
165
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loopback/metadata - npm Package Compare versions

Comparing version 4.0.0-alpha.4 to 4.0.0-alpha.5

18

CHANGELOG.md

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

<a name="4.0.0-alpha.5"></a>
# [4.0.0-alpha.5](https://github.com/strongloop/loopback-next/compare/@loopback/metadata@4.0.0-alpha.4...@loopback/metadata@4.0.0-alpha.5) (2018-01-19)
### Bug Fixes
* **metadata:** use static methods ([eea3c08](https://github.com/strongloop/loopback-next/commit/eea3c08))
* simplify string formatting ([4ea0485](https://github.com/strongloop/loopback-next/commit/4ea0485))
* use version range for [@types](https://github.com/types)/debug ([3adbc0b](https://github.com/strongloop/loopback-next/commit/3adbc0b))
### Features
* **context:** track injections with ResolutionSession ([cd4848e](https://github.com/strongloop/loopback-next/commit/cd4848e))
<a name="4.0.0-alpha.4"></a>

@@ -8,0 +26,0 @@ # [4.0.0-alpha.4](https://github.com/strongloop/loopback-next/compare/@loopback/metadata@4.0.0-alpha.3...@loopback/metadata@4.0.0-alpha.4) (2018-01-11)

2

dist/index.js
"use strict";
// Copyright IBM Corp. 2013,2017. All Rights Reserved.
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Node module: @loopback/metadata

@@ -4,0 +4,0 @@ // This file is licensed under the MIT License.

@@ -78,3 +78,13 @@ /**

/**
* Get name of a decoration target
* Get the qualified name of a decoration target. For example:
* ```
* class MyClass
* MyClass.constructor[0] // First parameter of the constructor
* MyClass.myStaticProperty
* MyClass.myStaticMethod()
* MyClass.myStaticMethod[0] // First parameter of the myStaticMethod
* MyClass.prototype.myProperty
* MyClass.prototype.myMethod()
* MyClass.prototype.myMethod[1] // Second parameter of myMethod
* ```
* @param target Class or prototype of a class

@@ -84,3 +94,3 @@ * @param member Optional property/method name

*/
getTargetName(target: Object, member?: string | symbol, descriptorOrIndex?: TypedPropertyDescriptor<any> | number): string;
static getTargetName(target: Object, member?: string | symbol, descriptorOrIndex?: TypedPropertyDescriptor<any> | number): string;
/**

@@ -91,3 +101,3 @@ * Get the number of parameters for a given constructor or method

*/
getNumberOfParameters(target: Object, member?: string | symbol): number;
static getNumberOfParameters(target: Object, member?: string | symbol): number;
/**

@@ -94,0 +104,0 @@ * Set a reference to the target class or prototype for a given spec if

"use strict";
// Copyright IBM Corp. 2013,2017. All Rights Reserved.
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Node module: @loopback/metadata

@@ -76,3 +76,13 @@ // This file is licensed under the MIT License.

/**
* Get name of a decoration target
* Get the qualified name of a decoration target. For example:
* ```
* class MyClass
* MyClass.constructor[0] // First parameter of the constructor
* MyClass.myStaticProperty
* MyClass.myStaticMethod()
* MyClass.myStaticMethod[0] // First parameter of the myStaticMethod
* MyClass.prototype.myProperty
* MyClass.prototype.myMethod()
* MyClass.prototype.myMethod[1] // Second parameter of myMethod
* ```
* @param target Class or prototype of a class

@@ -82,8 +92,8 @@ * @param member Optional property/method name

*/
getTargetName(target, member, descriptorOrIndex) {
static getTargetName(target, member, descriptorOrIndex) {
let name = target instanceof Function
? target.name
: target.constructor.name + '.prototype';
: `${target.constructor.name}.prototype`;
if (member == null && descriptorOrIndex == null) {
return 'class ' + name;
return `class ${name}`;
}

@@ -94,16 +104,9 @@ if (member == null)

// Parameter
name =
'parameter ' +
name +
'.' +
member.toString() +
'[' +
descriptorOrIndex +
']';
name = `${name}.${member}[${descriptorOrIndex}]`;
}
else if (descriptorOrIndex != null) {
name = 'method ' + name + '.' + member.toString();
name = `${name}.${member}()`;
}
else {
name = 'property ' + name + '.' + member.toString();
name = `${name}.${member}`;
}

@@ -117,4 +120,4 @@ return name;

*/
getNumberOfParameters(target, member) {
if (target instanceof Function && member == null) {
static getNumberOfParameters(target, member) {
if (target instanceof Function && !member) {
// constructor

@@ -204,3 +207,3 @@ return target.length;

decorate(target, member, descriptorOrIndex) {
const targetName = this.getTargetName(target, member, descriptorOrIndex);
const targetName = DecoratorFactory.getTargetName(target, member, descriptorOrIndex);
let meta = reflect_1.Reflector.getOwnMetadata(this.key, target);

@@ -267,3 +270,3 @@ if (meta == null && this.allowInheritance()) {

throw new Error('Decorator cannot be applied more than once on ' +
this.getTargetName(target));
DecoratorFactory.getTargetName(target));
}

@@ -299,3 +302,3 @@ return this.withTarget(this.spec, target);

if (ownMetadata[propertyName] != null) {
const targetName = this.getTargetName(target, propertyName);
const targetName = DecoratorFactory.getTargetName(target, propertyName);
throw new Error('Decorator cannot be applied more than once on ' + targetName);

@@ -335,3 +338,3 @@ }

throw new Error('Decorator cannot be applied more than once on ' +
this.getTargetName(target, methodName, methodDescriptor));
DecoratorFactory.getTargetName(target, methodName, methodDescriptor));
}

@@ -365,3 +368,3 @@ // Set the method metadata

// Initialize the method metadata
methodMeta = new Array(this.getNumberOfParameters(target, methodName)).fill(undefined);
methodMeta = new Array(DecoratorFactory.getNumberOfParameters(target, methodName)).fill(undefined);
meta[method] = methodMeta;

@@ -385,3 +388,3 @@ }

throw new Error('Decorator cannot be applied more than once on ' +
this.getTargetName(target, methodName, parameterIndex));
DecoratorFactory.getTargetName(target, methodName, parameterIndex));
}

@@ -425,5 +428,5 @@ // Set the parameter metadata

getParameterIndex(target, methodName, methodDescriptor) {
const numOfParams = this.getNumberOfParameters(target, methodName);
const numOfParams = DecoratorFactory.getNumberOfParameters(target, methodName);
// Fetch the cached parameter index
let index = reflect_1.Reflector.getOwnMetadata(this.key + ':index', target, methodName);
let index = reflect_1.Reflector.getOwnMetadata(`${this.key}:index`, target, methodName);
// Default to the last parameter

@@ -434,3 +437,3 @@ if (index == null)

// Excessive decorations than the number of parameters detected
const method = this.getTargetName(target, methodName, methodDescriptor);
const method = DecoratorFactory.getTargetName(target, methodName, methodDescriptor);
throw new Error(`The decorator is used more than ${numOfParams} time(s) on ${method}`);

@@ -449,3 +452,3 @@ }

// Cache the index to help us position the next parameter
reflect_1.Reflector.defineMetadata(this.key + ':index', index - 1, target, methodName);
reflect_1.Reflector.defineMetadata(`${this.key}:index`, index - 1, target, methodName);
inheritedMetadata[methodName] = inheritedParams;

@@ -461,3 +464,3 @@ return inheritedMetadata;

// Cache the index to help us position the next parameter
reflect_1.Reflector.defineMetadata(this.key + ':index', index - 1, target, methodName);
reflect_1.Reflector.defineMetadata(`${this.key}:index`, index - 1, target, methodName);
return ownMetadata;

@@ -464,0 +467,0 @@ }

"use strict";
// Copyright IBM Corp. 2013,2017. All Rights Reserved.
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Node module: @loopback/metadata

@@ -4,0 +4,0 @@ // This file is licensed under the MIT License.

"use strict";
// Copyright IBM Corp. 2013,2017. All Rights Reserved.
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Node module: @loopback/metadata

@@ -4,0 +4,0 @@ // This file is licensed under the MIT License.

@@ -78,3 +78,13 @@ /**

/**
* Get name of a decoration target
* Get the qualified name of a decoration target. For example:
* ```
* class MyClass
* MyClass.constructor[0] // First parameter of the constructor
* MyClass.myStaticProperty
* MyClass.myStaticMethod()
* MyClass.myStaticMethod[0] // First parameter of the myStaticMethod
* MyClass.prototype.myProperty
* MyClass.prototype.myMethod()
* MyClass.prototype.myMethod[1] // Second parameter of myMethod
* ```
* @param target Class or prototype of a class

@@ -84,3 +94,3 @@ * @param member Optional property/method name

*/
getTargetName(target: Object, member?: string | symbol, descriptorOrIndex?: TypedPropertyDescriptor<any> | number): string;
static getTargetName(target: Object, member?: string | symbol, descriptorOrIndex?: TypedPropertyDescriptor<any> | number): string;
/**

@@ -91,3 +101,3 @@ * Get the number of parameters for a given constructor or method

*/
getNumberOfParameters(target: Object, member?: string | symbol): number;
static getNumberOfParameters(target: Object, member?: string | symbol): number;
/**

@@ -94,0 +104,0 @@ * Set a reference to the target class or prototype for a given spec if

"use strict";
// Copyright IBM Corp. 2013,2017. All Rights Reserved.
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Node module: @loopback/metadata

@@ -76,3 +76,13 @@ // This file is licensed under the MIT License.

/**
* Get name of a decoration target
* Get the qualified name of a decoration target. For example:
* ```
* class MyClass
* MyClass.constructor[0] // First parameter of the constructor
* MyClass.myStaticProperty
* MyClass.myStaticMethod()
* MyClass.myStaticMethod[0] // First parameter of the myStaticMethod
* MyClass.prototype.myProperty
* MyClass.prototype.myMethod()
* MyClass.prototype.myMethod[1] // Second parameter of myMethod
* ```
* @param target Class or prototype of a class

@@ -82,8 +92,8 @@ * @param member Optional property/method name

*/
getTargetName(target, member, descriptorOrIndex) {
static getTargetName(target, member, descriptorOrIndex) {
let name = target instanceof Function
? target.name
: target.constructor.name + '.prototype';
: `${target.constructor.name}.prototype`;
if (member == null && descriptorOrIndex == null) {
return 'class ' + name;
return `class ${name}`;
}

@@ -94,16 +104,9 @@ if (member == null)

// Parameter
name =
'parameter ' +
name +
'.' +
member.toString() +
'[' +
descriptorOrIndex +
']';
name = `${name}.${member}[${descriptorOrIndex}]`;
}
else if (descriptorOrIndex != null) {
name = 'method ' + name + '.' + member.toString();
name = `${name}.${member}()`;
}
else {
name = 'property ' + name + '.' + member.toString();
name = `${name}.${member}`;
}

@@ -117,4 +120,4 @@ return name;

*/
getNumberOfParameters(target, member) {
if (target instanceof Function && member == null) {
static getNumberOfParameters(target, member) {
if (target instanceof Function && !member) {
// constructor

@@ -204,3 +207,3 @@ return target.length;

decorate(target, member, descriptorOrIndex) {
const targetName = this.getTargetName(target, member, descriptorOrIndex);
const targetName = DecoratorFactory.getTargetName(target, member, descriptorOrIndex);
let meta = reflect_1.Reflector.getOwnMetadata(this.key, target);

@@ -267,3 +270,3 @@ if (meta == null && this.allowInheritance()) {

throw new Error('Decorator cannot be applied more than once on ' +
this.getTargetName(target));
DecoratorFactory.getTargetName(target));
}

@@ -299,3 +302,3 @@ return this.withTarget(this.spec, target);

if (ownMetadata[propertyName] != null) {
const targetName = this.getTargetName(target, propertyName);
const targetName = DecoratorFactory.getTargetName(target, propertyName);
throw new Error('Decorator cannot be applied more than once on ' + targetName);

@@ -335,3 +338,3 @@ }

throw new Error('Decorator cannot be applied more than once on ' +
this.getTargetName(target, methodName, methodDescriptor));
DecoratorFactory.getTargetName(target, methodName, methodDescriptor));
}

@@ -365,3 +368,3 @@ // Set the method metadata

// Initialize the method metadata
methodMeta = new Array(this.getNumberOfParameters(target, methodName)).fill(undefined);
methodMeta = new Array(DecoratorFactory.getNumberOfParameters(target, methodName)).fill(undefined);
meta[method] = methodMeta;

@@ -385,3 +388,3 @@ }

throw new Error('Decorator cannot be applied more than once on ' +
this.getTargetName(target, methodName, parameterIndex));
DecoratorFactory.getTargetName(target, methodName, parameterIndex));
}

@@ -425,5 +428,5 @@ // Set the parameter metadata

getParameterIndex(target, methodName, methodDescriptor) {
const numOfParams = this.getNumberOfParameters(target, methodName);
const numOfParams = DecoratorFactory.getNumberOfParameters(target, methodName);
// Fetch the cached parameter index
let index = reflect_1.Reflector.getOwnMetadata(this.key + ':index', target, methodName);
let index = reflect_1.Reflector.getOwnMetadata(`${this.key}:index`, target, methodName);
// Default to the last parameter

@@ -434,3 +437,3 @@ if (index == null)

// Excessive decorations than the number of parameters detected
const method = this.getTargetName(target, methodName, methodDescriptor);
const method = DecoratorFactory.getTargetName(target, methodName, methodDescriptor);
throw new Error(`The decorator is used more than ${numOfParams} time(s) on ${method}`);

@@ -449,3 +452,3 @@ }

// Cache the index to help us position the next parameter
reflect_1.Reflector.defineMetadata(this.key + ':index', index - 1, target, methodName);
reflect_1.Reflector.defineMetadata(`${this.key}:index`, index - 1, target, methodName);
inheritedMetadata[methodName] = inheritedParams;

@@ -461,3 +464,3 @@ return inheritedMetadata;

// Cache the index to help us position the next parameter
reflect_1.Reflector.defineMetadata(this.key + ':index', index - 1, target, methodName);
reflect_1.Reflector.defineMetadata(`${this.key}:index`, index - 1, target, methodName);
return ownMetadata;

@@ -464,0 +467,0 @@ }

"use strict";
// Copyright IBM Corp. 2013,2017. All Rights Reserved.
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Node module: @loopback/metadata

@@ -4,0 +4,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2017. All Rights Reserved.
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Node module: @loopback/metadata

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

{
"name": "@loopback/metadata",
"version": "4.0.0-alpha.4",
"version": "4.0.0-alpha.5",
"description": "LoopBack's metadata utilities for reflection and decoration",

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

"scripts": {
"acceptance": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/acceptance/**/*.js'",
"acceptance": "lb-dist mocha --opts node_modules/@loopback/build/mocha.opts 'DIST/test/acceptance/**/*.js'",
"build": "npm run build:dist && npm run build:dist6",

@@ -19,7 +19,8 @@ "build:current": "lb-tsc",

"pretest": "npm run build:current",
"test": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'",
"unit": "lb-dist mocha --opts ../../test/mocha.opts 'DIST/test/unit/**/*.js'",
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'",
"unit": "lb-dist mocha --opts node_modules/@loopback/build/mocha.opts 'DIST/test/unit/**/*.js'",
"verify": "npm pack && tar xf loopback-metadata*.tgz && tree package && npm run clean"
},
"author": "IBM",
"copyright.owner": "IBM Corp.",
"license": "MIT",

@@ -32,5 +33,5 @@ "dependencies": {

"devDependencies": {
"@loopback/build": "^4.0.0-alpha.8",
"@loopback/testlab": "^4.0.0-alpha.18",
"@types/debug": "0.0.30",
"@loopback/build": "^4.0.0-alpha.9",
"@loopback/testlab": "^4.0.0-alpha.19",
"@types/debug": "^0.0.30",
"@types/lodash": "^4.14.87"

@@ -37,0 +38,0 @@ },

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2013,2017. All Rights Reserved.
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Node module: @loopback/metadata

@@ -126,3 +126,13 @@ // This file is licensed under the MIT License.

/**
* Get name of a decoration target
* Get the qualified name of a decoration target. For example:
* ```
* class MyClass
* MyClass.constructor[0] // First parameter of the constructor
* MyClass.myStaticProperty
* MyClass.myStaticMethod()
* MyClass.myStaticMethod[0] // First parameter of the myStaticMethod
* MyClass.prototype.myProperty
* MyClass.prototype.myMethod()
* MyClass.prototype.myMethod[1] // Second parameter of myMethod
* ```
* @param target Class or prototype of a class

@@ -132,3 +142,3 @@ * @param member Optional property/method name

*/
getTargetName(
static getTargetName(
target: Object,

@@ -141,5 +151,5 @@ member?: string | symbol,

? target.name
: target.constructor.name + '.prototype';
: `${target.constructor.name}.prototype`;
if (member == null && descriptorOrIndex == null) {
return 'class ' + name;
return `class ${name}`;
}

@@ -149,14 +159,7 @@ if (member == null) member = 'constructor';

// Parameter
name =
'parameter ' +
name +
'.' +
member.toString() +
'[' +
descriptorOrIndex +
']';
name = `${name}.${member}[${descriptorOrIndex}]`;
} else if (descriptorOrIndex != null) {
name = 'method ' + name + '.' + member.toString();
name = `${name}.${member}()`;
} else {
name = 'property ' + name + '.' + member.toString();
name = `${name}.${member}`;
}

@@ -171,4 +174,4 @@ return name;

*/
getNumberOfParameters(target: Object, member?: string | symbol) {
if (target instanceof Function && member == null) {
static getNumberOfParameters(target: Object, member?: string | symbol) {
if (target instanceof Function && !member) {
// constructor

@@ -276,3 +279,7 @@ return target.length;

) {
const targetName = this.getTargetName(target, member, descriptorOrIndex);
const targetName = DecoratorFactory.getTargetName(
target,
member,
descriptorOrIndex,
);
let meta: M = Reflector.getOwnMetadata(this.key, target);

@@ -358,3 +365,3 @@ if (meta == null && this.allowInheritance()) {

'Decorator cannot be applied more than once on ' +
this.getTargetName(target),
DecoratorFactory.getTargetName(target),
);

@@ -411,3 +418,3 @@ }

if (ownMetadata[propertyName!] != null) {
const targetName = this.getTargetName(target, propertyName);
const targetName = DecoratorFactory.getTargetName(target, propertyName);
throw new Error(

@@ -475,3 +482,3 @@ 'Decorator cannot be applied more than once on ' + targetName,

'Decorator cannot be applied more than once on ' +
this.getTargetName(target, methodName, methodDescriptor),
DecoratorFactory.getTargetName(target, methodName, methodDescriptor),
);

@@ -525,3 +532,3 @@ }

methodMeta = new Array(
this.getNumberOfParameters(target, methodName),
DecoratorFactory.getNumberOfParameters(target, methodName),
).fill(undefined);

@@ -566,3 +573,3 @@ meta[method] = methodMeta;

'Decorator cannot be applied more than once on ' +
this.getTargetName(target, methodName, parameterIndex),
DecoratorFactory.getTargetName(target, methodName, parameterIndex),
);

@@ -628,6 +635,9 @@ }

) {
const numOfParams = this.getNumberOfParameters(target, methodName);
const numOfParams = DecoratorFactory.getNumberOfParameters(
target,
methodName,
);
// Fetch the cached parameter index
let index = Reflector.getOwnMetadata(
this.key + ':index',
`${this.key}:index`,
target,

@@ -640,3 +650,7 @@ methodName,

// Excessive decorations than the number of parameters detected
const method = this.getTargetName(target, methodName, methodDescriptor);
const method = DecoratorFactory.getTargetName(
target,
methodName,
methodDescriptor,
);
throw new Error(

@@ -669,3 +683,3 @@ `The decorator is used more than ${numOfParams} time(s) on ${method}`,

Reflector.defineMetadata(
this.key + ':index',
`${this.key}:index`,
index - 1,

@@ -694,3 +708,3 @@ target,

Reflector.defineMetadata(
this.key + ':index',
`${this.key}:index`,
index - 1,

@@ -697,0 +711,0 @@ target,

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2013,2017. All Rights Reserved.
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Node module: @loopback/metadata

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

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