Socket
Socket
Sign inDemoInstall

aurelia-metadata

Package Overview
Dependencies
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aurelia-metadata - npm Package Compare versions

Comparing version 0.7.2 to 1.0.0-beta.1

.eslintrc

0

ACKNOWLEDGEMENTS.md

@@ -0,0 +0,0 @@ # Acknowledgements

3

bower.json
{
"name": "aurelia-metadata",
"version": "0.7.2",
"version": "1.0.0-beta.1",
"description": "Utilities for reading and writing the metadata of JavaScript functions.",

@@ -20,4 +20,5 @@ "keywords": [

"dependencies": {
"aurelia-pal": "^1.0.0-beta.1",
"core-js": "zloirock/core-js"
}
}

@@ -0,0 +0,0 @@ var yargs = require('yargs');

@@ -0,0 +0,0 @@ var path = require('path');

@@ -0,0 +0,0 @@ var path = require('path');

@@ -17,3 +17,10 @@ var gulp = require('gulp');

var importsToAdd = [];
var files = ['metadata.js', 'origin.js', 'decorator-applicator.js', 'decorators.js'].map(function(file){
var files = [
'metadata.js',
'origin.js',
'decorators.js',
'deprecated.js',
'mixin.js',
'protocol.js'
].map(function(file){
return paths.root + file;

@@ -20,0 +27,0 @@ });

@@ -0,0 +0,0 @@ var gulp = require('gulp');

@@ -0,0 +0,0 @@ var gulp = require('gulp');

@@ -8,3 +8,3 @@ var gulp = require('gulp');

gulp.task('doc-generate', function(){
return gulp.src([paths.output + '*.d.ts', paths.doc + '/core-js.d.ts', './jspm_packages/github/aurelia/*/*.d.ts'])
return gulp.src([paths.output + '*.d.ts', paths.doc + '/core-js.d.ts', './jspm_packages/npm/*/*.d.ts'])
.pipe(typedoc({

@@ -34,2 +34,2 @@ target: "es6",

);
});
});
var gulp = require('gulp');
var paths = require('../paths');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var eslint = require('gulp-eslint');
gulp.task('lint', function() {
return gulp.src(paths.source)
.pipe(jshint())
.pipe(jshint.reporter(stylish));
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});

@@ -0,0 +0,0 @@ var gulp = require('gulp');

var gulp = require('gulp');
var karma = require('karma').server;
var Karma = require('karma').Server;

@@ -8,8 +8,6 @@ /**

gulp.task('test', function (done) {
karma.start({
configFile: __dirname + '/../../karma.conf.js',
singleRun: true
}, function(e) {
done();
});
new Karma({
configFile: __dirname + '/../../karma.conf.js',
singleRun: true
}, done).start();
});

@@ -21,7 +19,5 @@

gulp.task('tdd', function (done) {
karma.start({
configFile: __dirname + '/../../karma.conf.js'
}, function(e) {
done();
});
new Karma({
configFile: __dirname + '/../../karma.conf.js'
}, done).start();
});

@@ -33,3 +29,3 @@

gulp.task('cover', function (done) {
karma.start({
new Karma({
configFile: __dirname + '/../../karma.conf.js',

@@ -46,5 +42,3 @@ singleRun: true,

}
}, function (e) {
done();
});
}, done).start();
});
System.config({
"transpiler": "babel",
"babelOptions": {
defaultJSExtensions: true,
transpiler: "babel",
babelOptions: {
"optional": [

@@ -9,21 +10,50 @@ "runtime",

},
"paths": {
"*": "*.js",
"github:*": "jspm_packages/github/*.js",
"npm:*": "jspm_packages/npm/*.js"
}
});
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
},
System.config({
"map": {
"babel": "npm:babel-core@5.1.13",
"babel-runtime": "npm:babel-runtime@5.1.13",
"core-js": "npm:core-js@0.9.5",
"github:jspm/nodelibs-process@0.1.1": {
"process": "npm:process@0.10.1"
map: {
"aurelia-pal": "npm:aurelia-pal@1.0.0-beta.1",
"babel": "npm:babel-core@5.8.23",
"babel-runtime": "npm:babel-runtime@5.8.20",
"core-js": "npm:core-js@1.2.6",
"github:jspm/nodelibs-assert@0.1.0": {
"assert": "npm:assert@1.3.0"
},
"npm:core-js@0.9.5": {
"process": "github:jspm/nodelibs-process@0.1.1"
"github:jspm/nodelibs-path@0.1.0": {
"path-browserify": "npm:path-browserify@0.0.0"
},
"github:jspm/nodelibs-process@0.1.2": {
"process": "npm:process@0.11.2"
},
"github:jspm/nodelibs-util@0.1.0": {
"util": "npm:util@0.10.3"
},
"npm:assert@1.3.0": {
"util": "npm:util@0.10.3"
},
"npm:babel-runtime@5.8.20": {
"process": "github:jspm/nodelibs-process@0.1.2"
},
"npm:core-js@1.2.6": {
"fs": "github:jspm/nodelibs-fs@0.1.2",
"path": "github:jspm/nodelibs-path@0.1.0",
"process": "github:jspm/nodelibs-process@0.1.2",
"systemjs-json": "github:systemjs/plugin-json@0.1.0"
},
"npm:inherits@2.0.1": {
"util": "github:jspm/nodelibs-util@0.1.0"
},
"npm:path-browserify@0.0.0": {
"process": "github:jspm/nodelibs-process@0.1.2"
},
"npm:process@0.11.2": {
"assert": "github:jspm/nodelibs-assert@0.1.0"
},
"npm:util@0.10.3": {
"inherits": "npm:inherits@2.0.1",
"process": "github:jspm/nodelibs-process@0.1.2"
}
}
});
# Contributing
We'd love for you to contribute and to make this project even better than it is today! If this interests you, please begin by reading [our contributing guidelines](https://github.com/DurandalProject/about/blob/master/CONTRIBUTING.md). The contributing document will provide you with all the information you need to get started. Once you have read that, you will need to also [sign our CLA](http://goo.gl/forms/dI8QDDSyKR) before we can accept a Pull Request from you. More information on the process is included in the [contributor's guide](https://github.com/DurandalProject/about/blob/master/CONTRIBUTING.md).
declare module 'aurelia-metadata' {
import core from 'core-js';
import 'core-js';
import { PLATFORM } from 'aurelia-pal';
/**
* Helpers for working with metadata on functions.
*/
export interface MetadataType {
/**
* The metadata key representing pluggable resources.
*/
resource: string;
/**
* The metadata key representing parameter type information.
*/
paramTypes: string;
/**
* The metadata key representing property information.
*/
properties: string;
/**
* Gets metadata specified by a key on a target, searching up the inheritance hierarchy.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
get(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Gets metadata specified by a key on a target, only searching the own instance.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
getOwn(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Defines metadata specified by a key on a target.
* @param metadataKey The key for the metadata to define.
* @param target The target to set the metadata on.
* @param targetKey The member on the target to set the metadata on.
*/
define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void;
/**
* Gets metadata specified by a key on a target, or creates an instance of the specified metadata if not found.
* @param metadataKey The key for the metadata to lookup or create.
* @param Type The type of metadata to create if existing metadata is not found.
* @param target The target to lookup or create the metadata on.
* @param targetKey The member on the target to lookup or create the metadata on.
*/
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object;
}
/**
* An object capable of applying it's captured decorators to a target.
*/
export interface DecoratorApplicator {
/**
* Applies the decorators to the target.
* @param target The target.
* @param key If applying to a method, the member name.
* @param key If applying to a method, you may supply an initial descriptor to pass to the decorators.
*/
on(target: any, key?: string, descriptor?: Object): any;
}
/**
* Options that control how the deprected decorator should function at runtime.
*/
export interface DeprecatedOptions {
/**
* Specifies a custom deprecation message.
*/
message: string;
/**
* Specifies whether or not the deprecation should throw an error.
*/
error: boolean;
}
/**
* Options used during protocol creation.
*/
export interface ProtocolOptions {
/**
* A function that will be run to validate the decorated class when the protocol is applied. It is also used to validate adhoc instances.
* If the validation fails, a message should be returned which directs the developer in how to address the issue.
*/
validate?: (target: any) => string | boolean;
/**
* A function which has the opportunity to compose additional behavior into the decorated class when the protocol is applied.
*/
compose?: (target: any) => void;
}
/**
* Provides helpers for working with metadata.
*
* @class Metadata
* @static
*/
export var Metadata: any;
export const metadata: MetadataType;
/**
* A metadata annotation that describes the origin module of the function to which it's attached.
*
* @class Origin
* @constructor
* @param {string} moduleId The origin module id.
* @param {string} moduleMember The name of the export in the origin module.
*/
export class Origin {
/**
* The id of the module from which the item originated.
*/
moduleId: string;
/**
* The member name of the export on the module object from which the item originated.
*/
moduleMember: string;
/**
* Creates an instance of Origin metadata.
* @param moduleId The id of the module from which the item originated.
* @param moduleMember The member name of the export on the module object from which the item originated.
*/
constructor(moduleId: string, moduleMember: string);
/**
* Get the Origin annotation for the specified function.
*
* @method get
* @static
* @param {Function} fn The function to inspect for Origin metadata.
* @return {Origin} Returns the Origin metadata.
* Get the Origin metadata for the specified function.
* @param fn The function to inspect for Origin metadata.
* @return Returns the Origin metadata.
*/
static get(fn: Function): any;
static get(fn: Function): Origin;
/**
* Set the Origin annotation for the specified function.
*
* @method set
* @static
* @param {Function} fn The function to set the Origin metadata on.
* @param {origin} fn The Origin metadata to store on the function.
* @return {Origin} Returns the Origin metadata.
* Set the Origin metadata for the specified function.
* @param fn The function to set the Origin metadata on.
* @param fn The Origin metadata to store on the function.
* @return Returns the Origin metadata.
*/
static set(fn: Function, origin: Origin): any;
static set(fn: Function, origin: Origin): void;
}
export class DecoratorApplicator {
constructor();
decorator(decorator: Function): DecoratorApplicator;
}
export var Decorators: any;
/**
* Enables applying decorators, particularly for use when there is no syntax support in the language, such as with ES5 and ES2016.
* @param rest The decorators to apply.
*/
export function decorators(...rest: Function[]): DecoratorApplicator;
/**
* Decorator: Enables marking methods as deprecated.
* @param optionsOrTarget Options for how the deprected decorator should function at runtime.
*/
export function deprecated(optionsOrTarget?: DeprecatedOptions, maybeKey?: string, maybeDescriptor?: Object): any;
/**
* Decorator: Enables mixing behaior into a class.
* @param behavior An object with keys for each method to mix into the target class.
*/
export function mixin(behavior: Object): any;
/**
* Decorator: Creates a protocol.
* @param name The name of the protocol.
* @param options The validation function or options object used in configuring the protocol.
*/
export function protocol(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): any;
}

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

define(['exports', 'core-js'], function (exports, _coreJs) {
define(['exports', 'core-js', 'aurelia-pal'], function (exports, _coreJs, _aureliaPal) {
'use strict';

@@ -6,31 +6,15 @@

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.decorators = decorators;
exports.deprecated = deprecated;
exports.mixin = mixin;
exports.protocol = protocol;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _core = _interopRequireDefault(_coreJs);
var theGlobal = (function () {
if (typeof self !== 'undefined') {
return self;
}
if (typeof global !== 'undefined') {
return global;
}
return new Function('return this')();
})();
var theGlobal = _aureliaPal.PLATFORM.global;
var emptyMetadata = Object.freeze({});
var metadataContainerKey = '__metadata__';
if (typeof theGlobal.System === 'undefined') {
theGlobal.System = { isFake: true };
}
if (typeof theGlobal.System.forEachModule === 'undefined') {
theGlobal.System.forEachModule = function () {};
}
if (typeof theGlobal.Reflect === 'undefined') {

@@ -48,3 +32,3 @@ theGlobal.Reflect = {};

Reflect.defineMetadata = function (metadataKey, metadataValue, target, targetKey) {
var metadataContainer = target[metadataContainerKey] || (target[metadataContainerKey] = {});
var metadataContainer = target.hasOwnProperty(metadataContainerKey) ? target[metadataContainerKey] : target[metadataContainerKey] = {};
var targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {});

@@ -63,21 +47,3 @@ targetContainer[metadataKey] = metadataValue;

function ensureDecorators(target) {
var applicator;
if (typeof target.decorators === 'function') {
applicator = target.decorators();
} else {
applicator = target.decorators;
}
if (typeof applicator._decorate === 'function') {
delete target.decorators;
applicator._decorate(target);
} else {
throw new Error('The return value of your decorator\'s method was not valid.');
}
}
var Metadata = {
global: theGlobal,
var metadata = {
resource: 'aurelia:resource',

@@ -90,5 +56,4 @@ paramTypes: 'design:paramtypes',

}
var result = Metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? Metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
var result = metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
},

@@ -99,7 +64,2 @@ getOwn: function getOwn(metadataKey, target, targetKey) {

}
if (target.hasOwnProperty('decorators')) {
ensureDecorators(target);
}
return Reflect.getOwnMetadata(metadataKey, target, targetKey);

@@ -111,3 +71,3 @@ },

getOrCreateOwn: function getOrCreateOwn(metadataKey, Type, target, targetKey) {
var result = Metadata.getOwn(metadataKey, target, targetKey);
var result = metadata.getOwn(metadataKey, target, targetKey);

@@ -123,5 +83,5 @@ if (result === undefined) {

exports.Metadata = Metadata;
var originStorage = new Map(),
unknownOrigin = Object.freeze({ moduleId: undefined, moduleMember: undefined });
exports.metadata = metadata;
var originStorage = new Map();
var unknownOrigin = Object.freeze({ moduleId: undefined, moduleMember: undefined });

@@ -140,7 +100,7 @@ var Origin = (function () {

if (origin === undefined) {
System.forEachModule(function (key, value) {
for (var name in value) {
var exp = value[name];
_aureliaPal.PLATFORM.eachModule(function (key, value) {
for (var _name in value) {
var exp = value[_name];
if (exp === fn) {
originStorage.set(fn, origin = new Origin(key, name));
originStorage.set(fn, origin = new Origin(key, _name));
return true;

@@ -169,89 +129,180 @@ }

var DecoratorApplicator = (function () {
function DecoratorApplicator() {
_classCallCheck(this, DecoratorApplicator);
this._first = null;
this._second = null;
this._third = null;
this._rest = null;
function decorators() {
for (var _len = arguments.length, rest = Array(_len), _key = 0; _key < _len; _key++) {
rest[_key] = arguments[_key];
}
DecoratorApplicator.prototype.decorator = function decorator(_decorator) {
if (this._first === null) {
this._first = _decorator;
return this;
}
var applicator = function applicator(target, key, descriptor) {
var i = rest.length;
if (this._second === null) {
this._second = _decorator;
return this;
}
if (key) {
descriptor = descriptor || {
value: target[key],
writable: true,
configurable: true,
enumerable: true
};
if (this._third === null) {
this._third = _decorator;
return this;
}
while (i--) {
descriptor = rest[i](target, key, descriptor) || descriptor;
}
if (this._rest === null) {
this._rest = [];
Object.defineProperty(target, key, descriptor);
} else {
while (i--) {
target = rest[i](target) || target;
}
}
this._rest.push(_decorator);
return this;
return target;
};
DecoratorApplicator.prototype._decorate = function _decorate(target) {
var i, ii, rest;
applicator.on = applicator;
return applicator;
}
if (this._first !== null) {
this._first(target);
}
function deprecated(optionsOrTarget, maybeKey, maybeDescriptor) {
function decorator(target, key, descriptor) {
var methodSignature = target.constructor.name + '#' + key;
var options = maybeKey ? {} : optionsOrTarget || {};
var message = 'DEPRECATION - ' + methodSignature;
if (this._second !== null) {
this._second(target);
if (typeof descriptor.value !== 'function') {
throw new SyntaxError('Only methods can be marked as deprecated.');
}
if (this._third !== null) {
this._third(target);
if (options.message) {
message += ' - ' + options.message;
}
rest = this._rest;
if (rest !== null) {
for (i = 0, ii = rest.length; i < ii; ++i) {
rest[i](target);
return _extends({}, descriptor, {
value: function deprecationWrapper() {
if (options.error) {
throw new Error(message);
} else {
console.warn(message);
}
return descriptor.value.apply(this, arguments);
}
});
}
return maybeKey ? decorator(optionsOrTarget, maybeKey, maybeDescriptor) : decorator;
}
function mixin(behavior) {
var instanceKeys = Object.keys(behavior);
function _mixin(possible) {
var decorator = function decorator(target) {
var resolvedTarget = typeof target === 'function' ? target.prototype : target;
for (var _iterator = instanceKeys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var property = _ref;
Object.defineProperty(resolvedTarget, property, {
value: behavior[property],
writable: true
});
}
};
return possible ? decorator(possible) : decorator;
}
return _mixin;
}
function alwaysValid() {
return true;
}
function noCompose() {}
function ensureProtocolOptions(options) {
if (options === undefined) {
options = {};
} else if (typeof options === 'function') {
options = {
validate: options
};
}
if (!options.validate) {
options.validate = alwaysValid;
}
if (!options.compose) {
options.compose = noCompose;
}
return options;
}
function createProtocolValidator(validate) {
return function (target) {
var result = validate(target);
return result === true;
};
}
function createProtocolAsserter(name, validate) {
return function (target) {
var result = validate(target);
if (result !== true) {
throw new Error(result || name + ' was not correctly implemented.');
}
};
}
return DecoratorApplicator;
})();
function protocol(name, options) {
options = ensureProtocolOptions(options);
exports.DecoratorApplicator = DecoratorApplicator;
var Decorators = {
configure: {
parameterizedDecorator: function parameterizedDecorator(name, decorator) {
Decorators[name] = function () {
var applicator = new DecoratorApplicator();
return applicator[name].apply(applicator, arguments);
};
var result = function result(target) {
var resolvedTarget = typeof target === 'function' ? target.prototype : target;
DecoratorApplicator.prototype[name] = function () {
var result = decorator.apply(null, arguments);
return this.decorator(result);
};
},
simpleDecorator: function simpleDecorator(name, decorator) {
Decorators[name] = function () {
return new DecoratorApplicator().decorator(decorator);
};
options.compose(resolvedTarget);
result.assert(resolvedTarget);
DecoratorApplicator.prototype[name] = function () {
return this.decorator(decorator);
};
}
}
Object.defineProperty(resolvedTarget, 'protocol:' + name, {
enumerable: false,
configurable: false,
writable: false,
value: true
});
};
result.validate = createProtocolValidator(options.validate);
result.assert = createProtocolAsserter(name, options.validate);
return result;
}
protocol.create = function (name, options) {
options = ensureProtocolOptions(options);
var hidden = 'protocol:' + name;
var result = function result(target) {
var decorator = protocol(name, options);
return target ? decorator(target) : decorator;
};
result.decorates = function (obj) {
return obj[hidden] === true;
};
result.validate = createProtocolValidator(options.validate);
result.assert = createProtocolAsserter(name, options.validate);
return result;
};
exports.Decorators = Decorators;
});
declare module 'aurelia-metadata' {
import core from 'core-js';
import 'core-js';
import { PLATFORM } from 'aurelia-pal';
/**
* Helpers for working with metadata on functions.
*/
export interface MetadataType {
/**
* The metadata key representing pluggable resources.
*/
resource: string;
/**
* The metadata key representing parameter type information.
*/
paramTypes: string;
/**
* The metadata key representing property information.
*/
properties: string;
/**
* Gets metadata specified by a key on a target, searching up the inheritance hierarchy.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
get(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Gets metadata specified by a key on a target, only searching the own instance.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
getOwn(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Defines metadata specified by a key on a target.
* @param metadataKey The key for the metadata to define.
* @param target The target to set the metadata on.
* @param targetKey The member on the target to set the metadata on.
*/
define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void;
/**
* Gets metadata specified by a key on a target, or creates an instance of the specified metadata if not found.
* @param metadataKey The key for the metadata to lookup or create.
* @param Type The type of metadata to create if existing metadata is not found.
* @param target The target to lookup or create the metadata on.
* @param targetKey The member on the target to lookup or create the metadata on.
*/
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object;
}
/**
* An object capable of applying it's captured decorators to a target.
*/
export interface DecoratorApplicator {
/**
* Applies the decorators to the target.
* @param target The target.
* @param key If applying to a method, the member name.
* @param key If applying to a method, you may supply an initial descriptor to pass to the decorators.
*/
on(target: any, key?: string, descriptor?: Object): any;
}
/**
* Options that control how the deprected decorator should function at runtime.
*/
export interface DeprecatedOptions {
/**
* Specifies a custom deprecation message.
*/
message: string;
/**
* Specifies whether or not the deprecation should throw an error.
*/
error: boolean;
}
/**
* Options used during protocol creation.
*/
export interface ProtocolOptions {
/**
* A function that will be run to validate the decorated class when the protocol is applied. It is also used to validate adhoc instances.
* If the validation fails, a message should be returned which directs the developer in how to address the issue.
*/
validate?: (target: any) => string | boolean;
/**
* A function which has the opportunity to compose additional behavior into the decorated class when the protocol is applied.
*/
compose?: (target: any) => void;
}
/**
* Provides helpers for working with metadata.
*
* @class Metadata
* @static
*/
export var Metadata: any;
export const metadata: MetadataType;
/**
* A metadata annotation that describes the origin module of the function to which it's attached.
*
* @class Origin
* @constructor
* @param {string} moduleId The origin module id.
* @param {string} moduleMember The name of the export in the origin module.
*/
export class Origin {
/**
* The id of the module from which the item originated.
*/
moduleId: string;
/**
* The member name of the export on the module object from which the item originated.
*/
moduleMember: string;
/**
* Creates an instance of Origin metadata.
* @param moduleId The id of the module from which the item originated.
* @param moduleMember The member name of the export on the module object from which the item originated.
*/
constructor(moduleId: string, moduleMember: string);
/**
* Get the Origin annotation for the specified function.
*
* @method get
* @static
* @param {Function} fn The function to inspect for Origin metadata.
* @return {Origin} Returns the Origin metadata.
* Get the Origin metadata for the specified function.
* @param fn The function to inspect for Origin metadata.
* @return Returns the Origin metadata.
*/
static get(fn: Function): any;
static get(fn: Function): Origin;
/**
* Set the Origin annotation for the specified function.
*
* @method set
* @static
* @param {Function} fn The function to set the Origin metadata on.
* @param {origin} fn The Origin metadata to store on the function.
* @return {Origin} Returns the Origin metadata.
* Set the Origin metadata for the specified function.
* @param fn The function to set the Origin metadata on.
* @param fn The Origin metadata to store on the function.
* @return Returns the Origin metadata.
*/
static set(fn: Function, origin: Origin): any;
static set(fn: Function, origin: Origin): void;
}
export class DecoratorApplicator {
constructor();
decorator(decorator: Function): DecoratorApplicator;
}
export var Decorators: any;
/**
* Enables applying decorators, particularly for use when there is no syntax support in the language, such as with ES5 and ES2016.
* @param rest The decorators to apply.
*/
export function decorators(...rest: Function[]): DecoratorApplicator;
/**
* Decorator: Enables marking methods as deprecated.
* @param optionsOrTarget Options for how the deprected decorator should function at runtime.
*/
export function deprecated(optionsOrTarget?: DeprecatedOptions, maybeKey?: string, maybeDescriptor?: Object): any;
/**
* Decorator: Enables mixing behaior into a class.
* @param behavior An object with keys for each method to mix into the target class.
*/
export function mixin(behavior: Object): any;
/**
* Decorator: Creates a protocol.
* @param name The name of the protocol.
* @param options The validation function or options object used in configuring the protocol.
*/
export function protocol(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): any;
}

@@ -1,35 +0,14 @@

import core from 'core-js';
import 'core-js';
import {PLATFORM} from 'aurelia-pal';
const theGlobal = (function() {
// Workers don’t have `window`, only `self`
if (typeof self !== 'undefined') {
return self;
}
if (typeof global !== 'undefined') {
return global;
}
// Not all environments allow eval and Function
// Use only as a last resort:
return new Function('return this')();
})();
const theGlobal = PLATFORM.global;
const emptyMetadata = Object.freeze({});
const metadataContainerKey = '__metadata__';
if(typeof theGlobal.System === 'undefined'){
theGlobal.System = { isFake:true };
}
if(typeof theGlobal.System.forEachModule === 'undefined'){
theGlobal.System.forEachModule = function(){};
}
if(typeof theGlobal.Reflect === 'undefined'){
if (typeof theGlobal.Reflect === 'undefined') {
theGlobal.Reflect = {};
}
if(typeof theGlobal.Reflect.getOwnMetadata === 'undefined'){
Reflect.getOwnMetadata = function(metadataKey, target, targetKey){
if (typeof theGlobal.Reflect.getOwnMetadata === 'undefined') {
Reflect.getOwnMetadata = function(metadataKey, target, targetKey) {
return ((target[metadataContainerKey] || emptyMetadata)[targetKey] || emptyMetadata)[metadataKey];

@@ -39,6 +18,6 @@ };

if(typeof theGlobal.Reflect.defineMetadata === 'undefined'){
Reflect.defineMetadata = function(metadataKey, metadataValue, target, targetKey){
var metadataContainer = target[metadataContainerKey] || (target[metadataContainerKey] = {});
var targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {});
if (typeof theGlobal.Reflect.defineMetadata === 'undefined') {
Reflect.defineMetadata = function(metadataKey, metadataValue, target, targetKey) {
let metadataContainer = target.hasOwnProperty(metadataContainerKey) ? target[metadataContainerKey] : (target[metadataContainerKey] = {});
let targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {});
targetContainer[metadataKey] = metadataValue;

@@ -48,5 +27,5 @@ };

if(typeof theGlobal.Reflect.metadata === 'undefined'){
Reflect.metadata = function(metadataKey, metadataValue){
return function(target, targetKey){
if (typeof theGlobal.Reflect.metadata === 'undefined') {
Reflect.metadata = function(metadataKey, metadataValue) {
return function(target, targetKey) {
Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey);

@@ -57,17 +36,47 @@ };

function ensureDecorators(target){
var applicator;
if(typeof target.decorators === 'function'){
applicator = target.decorators();
}else{
applicator = target.decorators;
}
if(typeof applicator._decorate === 'function'){
delete target.decorators;
applicator._decorate(target);
}else{
throw new Error('The return value of your decorator\'s method was not valid.');
}
/**
* Helpers for working with metadata on functions.
*/
interface MetadataType {
/**
* The metadata key representing pluggable resources.
*/
resource: string;
/**
* The metadata key representing parameter type information.
*/
paramTypes: string;
/**
* The metadata key representing property information.
*/
properties: string;
/**
* Gets metadata specified by a key on a target, searching up the inheritance hierarchy.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
get(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Gets metadata specified by a key on a target, only searching the own instance.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
getOwn(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Defines metadata specified by a key on a target.
* @param metadataKey The key for the metadata to define.
* @param target The target to set the metadata on.
* @param targetKey The member on the target to set the metadata on.
*/
define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void;
/**
* Gets metadata specified by a key on a target, or creates an instance of the specified metadata if not found.
* @param metadataKey The key for the metadata to lookup or create.
* @param Type The type of metadata to create if existing metadata is not found.
* @param target The target to lookup or create the metadata on.
* @param targetKey The member on the target to lookup or create the metadata on.
*/
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object;
}

@@ -77,37 +86,23 @@

* Provides helpers for working with metadata.
*
* @class Metadata
* @static
*/
export var Metadata = {
global: theGlobal,
resource:'aurelia:resource',
paramTypes:'design:paramtypes',
properties:'design:properties',
get(metadataKey:string, target:Function, targetKey:string){
if(!target){
return undefined;
}
let result = Metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? Metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
export const metadata: MetadataType = {
resource: 'aurelia:resource',
paramTypes: 'design:paramtypes',
properties: 'design:properties',
get(metadataKey: string, target: Function, targetKey: string): Object {
if (!target) { return undefined; }
let result = metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
},
getOwn(metadataKey:string, target:Function, targetKey:string){
if(!target){
return undefined;
}
if(target.hasOwnProperty('decorators')){
ensureDecorators(target);
}
getOwn(metadataKey: string, target: Function, targetKey: string): Object {
if (!target) { return undefined; }
return Reflect.getOwnMetadata(metadataKey, target, targetKey);
},
define(metadataKey:string, metadataValue:string, target:Function, targetKey:string){
define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void {
Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey);
},
getOrCreateOwn(metadataKey:string, Type:Function, target:Function, targetKey:string){
let result = Metadata.getOwn(metadataKey, target, targetKey);
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object {
let result = metadata.getOwn(metadataKey, target, targetKey);
if(result === undefined){
if (result === undefined) {
result = new Type();

@@ -119,17 +114,26 @@ Reflect.defineMetadata(metadataKey, result, target, targetKey);

}
}
};
var originStorage = new Map(),
unknownOrigin = Object.freeze({moduleId:undefined,moduleMember:undefined});
const originStorage = new Map();
const unknownOrigin = Object.freeze({moduleId: undefined, moduleMember: undefined});
/**
* A metadata annotation that describes the origin module of the function to which it's attached.
*
* @class Origin
* @constructor
* @param {string} moduleId The origin module id.
* @param {string} moduleMember The name of the export in the origin module.
*/
export class Origin {
constructor(moduleId:string, moduleMember:string){
/**
* The id of the module from which the item originated.
*/
moduleId: string;
/**
* The member name of the export on the module object from which the item originated.
*/
moduleMember: string;
/**
* Creates an instance of Origin metadata.
* @param moduleId The id of the module from which the item originated.
* @param moduleMember The member name of the export on the module object from which the item originated.
*/
constructor(moduleId: string, moduleMember: string) {
this.moduleId = moduleId;

@@ -140,17 +144,14 @@ this.moduleMember = moduleMember;

/**
* Get the Origin annotation for the specified function.
*
* @method get
* @static
* @param {Function} fn The function to inspect for Origin metadata.
* @return {Origin} Returns the Origin metadata.
* Get the Origin metadata for the specified function.
* @param fn The function to inspect for Origin metadata.
* @return Returns the Origin metadata.
*/
static get(fn:Function){
var origin = originStorage.get(fn);
static get(fn: Function): Origin {
let origin = originStorage.get(fn);
if(origin === undefined){
System.forEachModule((key, value) => {
for(var name in value){
var exp = value[name];
if(exp === fn){
if (origin === undefined) {
PLATFORM.eachModule((key, value) => {
for (let name in value) {
let exp = value[name];
if (exp === fn) {
originStorage.set(fn, origin = new Origin(key, name));

@@ -161,3 +162,3 @@ return true;

if(value === fn){
if (value === fn) {
originStorage.set(fn, origin = new Origin(key, 'default'));

@@ -173,11 +174,8 @@ return true;

/**
* Set the Origin annotation for the specified function.
*
* @method set
* @static
* @param {Function} fn The function to set the Origin metadata on.
* @param {origin} fn The Origin metadata to store on the function.
* @return {Origin} Returns the Origin metadata.
* Set the Origin metadata for the specified function.
* @param fn The function to set the Origin metadata on.
* @param fn The Origin metadata to store on the function.
* @return Returns the Origin metadata.
*/
static set(fn:Function, origin:Origin){
static set(fn: Function, origin: Origin): void {
originStorage.set(fn, origin);

@@ -187,82 +185,228 @@ }

export class DecoratorApplicator {
constructor(){
this._first = null;
this._second = null;
this._third = null;
this._rest = null;
}
/**
* An object capable of applying it's captured decorators to a target.
*/
interface DecoratorApplicator {
/**
* Applies the decorators to the target.
* @param target The target.
* @param key If applying to a method, the member name.
* @param key If applying to a method, you may supply an initial descriptor to pass to the decorators.
*/
on(target: any, key?: string, descriptor?: Object): any;
}
decorator(decorator:Function):DecoratorApplicator{
if(this._first === null){
this._first = decorator;
return this;
}
/**
* Enables applying decorators, particularly for use when there is no syntax support in the language, such as with ES5 and ES2016.
* @param rest The decorators to apply.
*/
export function decorators(...rest: Function[]): DecoratorApplicator {
let applicator = function(target, key, descriptor) {
let i = rest.length;
if(this._second === null){
this._second = decorator;
return this;
}
if (key) {
descriptor = descriptor || {
value: target[key],
writable: true,
configurable: true,
enumerable: true
};
if(this._third === null){
this._third = decorator;
return this;
}
while (i--) {
descriptor = rest[i](target, key, descriptor) || descriptor;
}
if(this._rest === null){
this._rest = [];
Object.defineProperty(target, key, descriptor);
} else {
while (i--) {
target = rest[i](target) || target;
}
}
this._rest.push(decorator);
return target;
};
return this;
}
applicator.on = applicator;
return applicator;
}
_decorate(target:Function){
var i, ii, rest;
/**
* Options that control how the deprected decorator should function at runtime.
*/
interface DeprecatedOptions {
/**
* Specifies a custom deprecation message.
*/
message: string;
/**
* Specifies whether or not the deprecation should throw an error.
*/
error: boolean;
}
if(this._first !== null){
this._first(target);
}
/**
* Decorator: Enables marking methods as deprecated.
* @param optionsOrTarget Options for how the deprected decorator should function at runtime.
*/
export function deprecated(optionsOrTarget?: DeprecatedOptions, maybeKey?: string, maybeDescriptor?: Object): any {
function decorator(target, key, descriptor) {
const methodSignature = `${target.constructor.name}#${key}`;
let options = maybeKey ? {} : optionsOrTarget || {};
let message = `DEPRECATION - ${methodSignature}`;
if(this._second !== null){
this._second(target);
if (typeof descriptor.value !== 'function') {
throw new SyntaxError('Only methods can be marked as deprecated.');
}
if(this._third !== null){
this._third(target);
if (options.message) {
message += ` - ${options.message}`;
}
rest = this._rest;
if(rest !== null){
for(i = 0, ii = rest.length; i < ii; ++i){
rest[i](target);
return {
...descriptor,
value: function deprecationWrapper() {
if (options.error) {
throw new Error(message);
} else {
console.warn(message);
}
return descriptor.value.apply(this, arguments);
}
}
};
}
return maybeKey ? decorator(optionsOrTarget, maybeKey, maybeDescriptor) : decorator;
}
export var Decorators = {
configure: {
parameterizedDecorator(name:string, decorator:Function){
Decorators[name] = function(){
var applicator = new DecoratorApplicator();
return applicator[name].apply(applicator, arguments);
};
/**
* Decorator: Enables mixing behaior into a class.
* @param behavior An object with keys for each method to mix into the target class.
*/
export function mixin(behavior: Object): any {
const instanceKeys = Object.keys(behavior);
DecoratorApplicator.prototype[name] = function(){
var result = decorator.apply(null, arguments);
return this.decorator(result);
};
},
simpleDecorator(name:string, decorator:Function){
Decorators[name] = function(){
return new DecoratorApplicator().decorator(decorator);
};
function _mixin(possible) {
let decorator = function(target) {
let resolvedTarget = typeof target === 'function'
? target.prototype
: target;
DecoratorApplicator.prototype[name] = function(){
return this.decorator(decorator);
for (let property of instanceKeys) {
Object.defineProperty(resolvedTarget, property, {
value: behavior[property],
writable: true
});
}
}
};
return possible ? decorator(possible) : decorator;
}
return _mixin;
}
function alwaysValid() { return true; }
function noCompose() {}
function ensureProtocolOptions(options) {
if (options === undefined) {
options = {};
} else if (typeof options === 'function') {
options = {
validate: options
};
}
if (!options.validate) {
options.validate = alwaysValid;
}
if (!options.compose) {
options.compose = noCompose;
}
return options;
}
function createProtocolValidator(validate) {
return function(target) {
let result = validate(target);
return result === true;
};
}
function createProtocolAsserter(name, validate) {
return function(target) {
let result = validate(target);
if (result !== true) {
throw new Error(result || `${name} was not correctly implemented.`);
}
};
}
/**
* Options used during protocol creation.
*/
interface ProtocolOptions {
/**
* A function that will be run to validate the decorated class when the protocol is applied. It is also used to validate adhoc instances.
* If the validation fails, a message should be returned which directs the developer in how to address the issue.
*/
validate?: (target: any) => string | boolean;
/**
* A function which has the opportunity to compose additional behavior into the decorated class when the protocol is applied.
*/
compose?: (target: any) => void;
}
/**
* Decorator: Creates a protocol.
* @param name The name of the protocol.
* @param options The validation function or options object used in configuring the protocol.
*/
export function protocol(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): any {
options = ensureProtocolOptions(options);
let result = function(target) {
let resolvedTarget = typeof target === 'function'
? target.prototype
: target;
options.compose(resolvedTarget);
result.assert(resolvedTarget);
Object.defineProperty(resolvedTarget, 'protocol:' + name, {
enumerable: false,
configurable: false,
writable: false,
value: true
});
};
result.validate = createProtocolValidator(options.validate);
result.assert = createProtocolAsserter(name, options.validate);
return result;
}
/**
* Creates a protocol decorator.
* @param name The name of the protocol.
* @param options The validation function or options object used in configuring the protocol.
* @return The protocol decorator;
*/
protocol.create = function(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): Function {
options = ensureProtocolOptions(options);
let hidden = 'protocol:' + name;
let result = function(target) {
let decorator = protocol(name, options);
return target ? decorator(target) : decorator;
};
result.decorates = function(obj) { return obj[hidden] === true; };
result.validate = createProtocolValidator(options.validate);
result.assert = createProtocolAsserter(name, options.validate);
return result;
};
declare module 'aurelia-metadata' {
import core from 'core-js';
import 'core-js';
import { PLATFORM } from 'aurelia-pal';
/**
* Helpers for working with metadata on functions.
*/
export interface MetadataType {
/**
* The metadata key representing pluggable resources.
*/
resource: string;
/**
* The metadata key representing parameter type information.
*/
paramTypes: string;
/**
* The metadata key representing property information.
*/
properties: string;
/**
* Gets metadata specified by a key on a target, searching up the inheritance hierarchy.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
get(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Gets metadata specified by a key on a target, only searching the own instance.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
getOwn(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Defines metadata specified by a key on a target.
* @param metadataKey The key for the metadata to define.
* @param target The target to set the metadata on.
* @param targetKey The member on the target to set the metadata on.
*/
define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void;
/**
* Gets metadata specified by a key on a target, or creates an instance of the specified metadata if not found.
* @param metadataKey The key for the metadata to lookup or create.
* @param Type The type of metadata to create if existing metadata is not found.
* @param target The target to lookup or create the metadata on.
* @param targetKey The member on the target to lookup or create the metadata on.
*/
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object;
}
/**
* An object capable of applying it's captured decorators to a target.
*/
export interface DecoratorApplicator {
/**
* Applies the decorators to the target.
* @param target The target.
* @param key If applying to a method, the member name.
* @param key If applying to a method, you may supply an initial descriptor to pass to the decorators.
*/
on(target: any, key?: string, descriptor?: Object): any;
}
/**
* Options that control how the deprected decorator should function at runtime.
*/
export interface DeprecatedOptions {
/**
* Specifies a custom deprecation message.
*/
message: string;
/**
* Specifies whether or not the deprecation should throw an error.
*/
error: boolean;
}
/**
* Options used during protocol creation.
*/
export interface ProtocolOptions {
/**
* A function that will be run to validate the decorated class when the protocol is applied. It is also used to validate adhoc instances.
* If the validation fails, a message should be returned which directs the developer in how to address the issue.
*/
validate?: (target: any) => string | boolean;
/**
* A function which has the opportunity to compose additional behavior into the decorated class when the protocol is applied.
*/
compose?: (target: any) => void;
}
/**
* Provides helpers for working with metadata.
*
* @class Metadata
* @static
*/
export var Metadata: any;
export const metadata: MetadataType;
/**
* A metadata annotation that describes the origin module of the function to which it's attached.
*
* @class Origin
* @constructor
* @param {string} moduleId The origin module id.
* @param {string} moduleMember The name of the export in the origin module.
*/
export class Origin {
/**
* The id of the module from which the item originated.
*/
moduleId: string;
/**
* The member name of the export on the module object from which the item originated.
*/
moduleMember: string;
/**
* Creates an instance of Origin metadata.
* @param moduleId The id of the module from which the item originated.
* @param moduleMember The member name of the export on the module object from which the item originated.
*/
constructor(moduleId: string, moduleMember: string);
/**
* Get the Origin annotation for the specified function.
*
* @method get
* @static
* @param {Function} fn The function to inspect for Origin metadata.
* @return {Origin} Returns the Origin metadata.
* Get the Origin metadata for the specified function.
* @param fn The function to inspect for Origin metadata.
* @return Returns the Origin metadata.
*/
static get(fn: Function): any;
static get(fn: Function): Origin;
/**
* Set the Origin annotation for the specified function.
*
* @method set
* @static
* @param {Function} fn The function to set the Origin metadata on.
* @param {origin} fn The Origin metadata to store on the function.
* @return {Origin} Returns the Origin metadata.
* Set the Origin metadata for the specified function.
* @param fn The function to set the Origin metadata on.
* @param fn The Origin metadata to store on the function.
* @return Returns the Origin metadata.
*/
static set(fn: Function, origin: Origin): any;
static set(fn: Function, origin: Origin): void;
}
export class DecoratorApplicator {
constructor();
decorator(decorator: Function): DecoratorApplicator;
}
export var Decorators: any;
/**
* Enables applying decorators, particularly for use when there is no syntax support in the language, such as with ES5 and ES2016.
* @param rest The decorators to apply.
*/
export function decorators(...rest: Function[]): DecoratorApplicator;
/**
* Decorator: Enables marking methods as deprecated.
* @param optionsOrTarget Options for how the deprected decorator should function at runtime.
*/
export function deprecated(optionsOrTarget?: DeprecatedOptions, maybeKey?: string, maybeDescriptor?: Object): any;
/**
* Decorator: Enables mixing behaior into a class.
* @param behavior An object with keys for each method to mix into the target class.
*/
export function mixin(behavior: Object): any;
/**
* Decorator: Creates a protocol.
* @param name The name of the protocol.
* @param options The validation function or options object used in configuring the protocol.
*/
export function protocol(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): any;
}

@@ -5,33 +5,19 @@ 'use strict';

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.decorators = decorators;
exports.deprecated = deprecated;
exports.mixin = mixin;
exports.protocol = protocol;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _coreJs = require('core-js');
require('core-js');
var _coreJs2 = _interopRequireDefault(_coreJs);
var _aureliaPal = require('aurelia-pal');
var theGlobal = (function () {
if (typeof self !== 'undefined') {
return self;
}
if (typeof global !== 'undefined') {
return global;
}
return new Function('return this')();
})();
var theGlobal = _aureliaPal.PLATFORM.global;
var emptyMetadata = Object.freeze({});
var metadataContainerKey = '__metadata__';
if (typeof theGlobal.System === 'undefined') {
theGlobal.System = { isFake: true };
}
if (typeof theGlobal.System.forEachModule === 'undefined') {
theGlobal.System.forEachModule = function () {};
}
if (typeof theGlobal.Reflect === 'undefined') {

@@ -49,3 +35,3 @@ theGlobal.Reflect = {};

Reflect.defineMetadata = function (metadataKey, metadataValue, target, targetKey) {
var metadataContainer = target[metadataContainerKey] || (target[metadataContainerKey] = {});
var metadataContainer = target.hasOwnProperty(metadataContainerKey) ? target[metadataContainerKey] : target[metadataContainerKey] = {};
var targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {});

@@ -64,21 +50,3 @@ targetContainer[metadataKey] = metadataValue;

function ensureDecorators(target) {
var applicator;
if (typeof target.decorators === 'function') {
applicator = target.decorators();
} else {
applicator = target.decorators;
}
if (typeof applicator._decorate === 'function') {
delete target.decorators;
applicator._decorate(target);
} else {
throw new Error('The return value of your decorator\'s method was not valid.');
}
}
var Metadata = {
global: theGlobal,
var metadata = {
resource: 'aurelia:resource',

@@ -91,5 +59,4 @@ paramTypes: 'design:paramtypes',

}
var result = Metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? Metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
var result = metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
},

@@ -100,7 +67,2 @@ getOwn: function getOwn(metadataKey, target, targetKey) {

}
if (target.hasOwnProperty('decorators')) {
ensureDecorators(target);
}
return Reflect.getOwnMetadata(metadataKey, target, targetKey);

@@ -112,3 +74,3 @@ },

getOrCreateOwn: function getOrCreateOwn(metadataKey, Type, target, targetKey) {
var result = Metadata.getOwn(metadataKey, target, targetKey);
var result = metadata.getOwn(metadataKey, target, targetKey);

@@ -124,5 +86,5 @@ if (result === undefined) {

exports.Metadata = Metadata;
var originStorage = new Map(),
unknownOrigin = Object.freeze({ moduleId: undefined, moduleMember: undefined });
exports.metadata = metadata;
var originStorage = new Map();
var unknownOrigin = Object.freeze({ moduleId: undefined, moduleMember: undefined });

@@ -141,7 +103,7 @@ var Origin = (function () {

if (origin === undefined) {
System.forEachModule(function (key, value) {
for (var name in value) {
var exp = value[name];
_aureliaPal.PLATFORM.eachModule(function (key, value) {
for (var _name in value) {
var exp = value[_name];
if (exp === fn) {
originStorage.set(fn, origin = new Origin(key, name));
originStorage.set(fn, origin = new Origin(key, _name));
return true;

@@ -170,88 +132,179 @@ }

var DecoratorApplicator = (function () {
function DecoratorApplicator() {
_classCallCheck(this, DecoratorApplicator);
this._first = null;
this._second = null;
this._third = null;
this._rest = null;
function decorators() {
for (var _len = arguments.length, rest = Array(_len), _key = 0; _key < _len; _key++) {
rest[_key] = arguments[_key];
}
DecoratorApplicator.prototype.decorator = function decorator(_decorator) {
if (this._first === null) {
this._first = _decorator;
return this;
}
var applicator = function applicator(target, key, descriptor) {
var i = rest.length;
if (this._second === null) {
this._second = _decorator;
return this;
}
if (key) {
descriptor = descriptor || {
value: target[key],
writable: true,
configurable: true,
enumerable: true
};
if (this._third === null) {
this._third = _decorator;
return this;
}
while (i--) {
descriptor = rest[i](target, key, descriptor) || descriptor;
}
if (this._rest === null) {
this._rest = [];
Object.defineProperty(target, key, descriptor);
} else {
while (i--) {
target = rest[i](target) || target;
}
}
this._rest.push(_decorator);
return this;
return target;
};
DecoratorApplicator.prototype._decorate = function _decorate(target) {
var i, ii, rest;
applicator.on = applicator;
return applicator;
}
if (this._first !== null) {
this._first(target);
}
function deprecated(optionsOrTarget, maybeKey, maybeDescriptor) {
function decorator(target, key, descriptor) {
var methodSignature = target.constructor.name + '#' + key;
var options = maybeKey ? {} : optionsOrTarget || {};
var message = 'DEPRECATION - ' + methodSignature;
if (this._second !== null) {
this._second(target);
if (typeof descriptor.value !== 'function') {
throw new SyntaxError('Only methods can be marked as deprecated.');
}
if (this._third !== null) {
this._third(target);
if (options.message) {
message += ' - ' + options.message;
}
rest = this._rest;
if (rest !== null) {
for (i = 0, ii = rest.length; i < ii; ++i) {
rest[i](target);
return _extends({}, descriptor, {
value: function deprecationWrapper() {
if (options.error) {
throw new Error(message);
} else {
console.warn(message);
}
return descriptor.value.apply(this, arguments);
}
});
}
return maybeKey ? decorator(optionsOrTarget, maybeKey, maybeDescriptor) : decorator;
}
function mixin(behavior) {
var instanceKeys = Object.keys(behavior);
function _mixin(possible) {
var decorator = function decorator(target) {
var resolvedTarget = typeof target === 'function' ? target.prototype : target;
for (var _iterator = instanceKeys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var property = _ref;
Object.defineProperty(resolvedTarget, property, {
value: behavior[property],
writable: true
});
}
};
return possible ? decorator(possible) : decorator;
}
return _mixin;
}
function alwaysValid() {
return true;
}
function noCompose() {}
function ensureProtocolOptions(options) {
if (options === undefined) {
options = {};
} else if (typeof options === 'function') {
options = {
validate: options
};
}
if (!options.validate) {
options.validate = alwaysValid;
}
if (!options.compose) {
options.compose = noCompose;
}
return options;
}
function createProtocolValidator(validate) {
return function (target) {
var result = validate(target);
return result === true;
};
}
function createProtocolAsserter(name, validate) {
return function (target) {
var result = validate(target);
if (result !== true) {
throw new Error(result || name + ' was not correctly implemented.');
}
};
}
return DecoratorApplicator;
})();
function protocol(name, options) {
options = ensureProtocolOptions(options);
exports.DecoratorApplicator = DecoratorApplicator;
var Decorators = {
configure: {
parameterizedDecorator: function parameterizedDecorator(name, decorator) {
Decorators[name] = function () {
var applicator = new DecoratorApplicator();
return applicator[name].apply(applicator, arguments);
};
var result = function result(target) {
var resolvedTarget = typeof target === 'function' ? target.prototype : target;
DecoratorApplicator.prototype[name] = function () {
var result = decorator.apply(null, arguments);
return this.decorator(result);
};
},
simpleDecorator: function simpleDecorator(name, decorator) {
Decorators[name] = function () {
return new DecoratorApplicator().decorator(decorator);
};
options.compose(resolvedTarget);
result.assert(resolvedTarget);
DecoratorApplicator.prototype[name] = function () {
return this.decorator(decorator);
};
}
}
};
exports.Decorators = Decorators;
Object.defineProperty(resolvedTarget, 'protocol:' + name, {
enumerable: false,
configurable: false,
writable: false,
value: true
});
};
result.validate = createProtocolValidator(options.validate);
result.assert = createProtocolAsserter(name, options.validate);
return result;
}
protocol.create = function (name, options) {
options = ensureProtocolOptions(options);
var hidden = 'protocol:' + name;
var result = function result(target) {
var decorator = protocol(name, options);
return target ? decorator(target) : decorator;
};
result.decorates = function (obj) {
return obj[hidden] === true;
};
result.validate = createProtocolValidator(options.validate);
result.assert = createProtocolAsserter(name, options.validate);
return result;
};
declare module 'aurelia-metadata' {
import core from 'core-js';
import 'core-js';
import { PLATFORM } from 'aurelia-pal';
/**
* Helpers for working with metadata on functions.
*/
export interface MetadataType {
/**
* The metadata key representing pluggable resources.
*/
resource: string;
/**
* The metadata key representing parameter type information.
*/
paramTypes: string;
/**
* The metadata key representing property information.
*/
properties: string;
/**
* Gets metadata specified by a key on a target, searching up the inheritance hierarchy.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
get(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Gets metadata specified by a key on a target, only searching the own instance.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
getOwn(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Defines metadata specified by a key on a target.
* @param metadataKey The key for the metadata to define.
* @param target The target to set the metadata on.
* @param targetKey The member on the target to set the metadata on.
*/
define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void;
/**
* Gets metadata specified by a key on a target, or creates an instance of the specified metadata if not found.
* @param metadataKey The key for the metadata to lookup or create.
* @param Type The type of metadata to create if existing metadata is not found.
* @param target The target to lookup or create the metadata on.
* @param targetKey The member on the target to lookup or create the metadata on.
*/
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object;
}
/**
* An object capable of applying it's captured decorators to a target.
*/
export interface DecoratorApplicator {
/**
* Applies the decorators to the target.
* @param target The target.
* @param key If applying to a method, the member name.
* @param key If applying to a method, you may supply an initial descriptor to pass to the decorators.
*/
on(target: any, key?: string, descriptor?: Object): any;
}
/**
* Options that control how the deprected decorator should function at runtime.
*/
export interface DeprecatedOptions {
/**
* Specifies a custom deprecation message.
*/
message: string;
/**
* Specifies whether or not the deprecation should throw an error.
*/
error: boolean;
}
/**
* Options used during protocol creation.
*/
export interface ProtocolOptions {
/**
* A function that will be run to validate the decorated class when the protocol is applied. It is also used to validate adhoc instances.
* If the validation fails, a message should be returned which directs the developer in how to address the issue.
*/
validate?: (target: any) => string | boolean;
/**
* A function which has the opportunity to compose additional behavior into the decorated class when the protocol is applied.
*/
compose?: (target: any) => void;
}
/**
* Provides helpers for working with metadata.
*
* @class Metadata
* @static
*/
export var Metadata: any;
export const metadata: MetadataType;
/**
* A metadata annotation that describes the origin module of the function to which it's attached.
*
* @class Origin
* @constructor
* @param {string} moduleId The origin module id.
* @param {string} moduleMember The name of the export in the origin module.
*/
export class Origin {
/**
* The id of the module from which the item originated.
*/
moduleId: string;
/**
* The member name of the export on the module object from which the item originated.
*/
moduleMember: string;
/**
* Creates an instance of Origin metadata.
* @param moduleId The id of the module from which the item originated.
* @param moduleMember The member name of the export on the module object from which the item originated.
*/
constructor(moduleId: string, moduleMember: string);
/**
* Get the Origin annotation for the specified function.
*
* @method get
* @static
* @param {Function} fn The function to inspect for Origin metadata.
* @return {Origin} Returns the Origin metadata.
* Get the Origin metadata for the specified function.
* @param fn The function to inspect for Origin metadata.
* @return Returns the Origin metadata.
*/
static get(fn: Function): any;
static get(fn: Function): Origin;
/**
* Set the Origin annotation for the specified function.
*
* @method set
* @static
* @param {Function} fn The function to set the Origin metadata on.
* @param {origin} fn The Origin metadata to store on the function.
* @return {Origin} Returns the Origin metadata.
* Set the Origin metadata for the specified function.
* @param fn The function to set the Origin metadata on.
* @param fn The Origin metadata to store on the function.
* @return Returns the Origin metadata.
*/
static set(fn: Function, origin: Origin): any;
static set(fn: Function, origin: Origin): void;
}
export class DecoratorApplicator {
constructor();
decorator(decorator: Function): DecoratorApplicator;
}
export var Decorators: any;
/**
* Enables applying decorators, particularly for use when there is no syntax support in the language, such as with ES5 and ES2016.
* @param rest The decorators to apply.
*/
export function decorators(...rest: Function[]): DecoratorApplicator;
/**
* Decorator: Enables marking methods as deprecated.
* @param optionsOrTarget Options for how the deprected decorator should function at runtime.
*/
export function deprecated(optionsOrTarget?: DeprecatedOptions, maybeKey?: string, maybeDescriptor?: Object): any;
/**
* Decorator: Enables mixing behaior into a class.
* @param behavior An object with keys for each method to mix into the target class.
*/
export function mixin(behavior: Object): any;
/**
* Decorator: Creates a protocol.
* @param name The name of the protocol.
* @param options The validation function or options object used in configuring the protocol.
*/
export function protocol(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): any;
}

@@ -1,35 +0,14 @@

import core from 'core-js';
import 'core-js';
import {PLATFORM} from 'aurelia-pal';
const theGlobal = (function() {
// Workers don’t have `window`, only `self`
if (typeof self !== 'undefined') {
return self;
}
if (typeof global !== 'undefined') {
return global;
}
// Not all environments allow eval and Function
// Use only as a last resort:
return new Function('return this')();
})();
const theGlobal = PLATFORM.global;
const emptyMetadata = Object.freeze({});
const metadataContainerKey = '__metadata__';
if(typeof theGlobal.System === 'undefined'){
theGlobal.System = { isFake:true };
}
if(typeof theGlobal.System.forEachModule === 'undefined'){
theGlobal.System.forEachModule = function(){};
}
if(typeof theGlobal.Reflect === 'undefined'){
if (typeof theGlobal.Reflect === 'undefined') {
theGlobal.Reflect = {};
}
if(typeof theGlobal.Reflect.getOwnMetadata === 'undefined'){
Reflect.getOwnMetadata = function(metadataKey, target, targetKey){
if (typeof theGlobal.Reflect.getOwnMetadata === 'undefined') {
Reflect.getOwnMetadata = function(metadataKey, target, targetKey) {
return ((target[metadataContainerKey] || emptyMetadata)[targetKey] || emptyMetadata)[metadataKey];

@@ -39,6 +18,6 @@ };

if(typeof theGlobal.Reflect.defineMetadata === 'undefined'){
Reflect.defineMetadata = function(metadataKey, metadataValue, target, targetKey){
var metadataContainer = target[metadataContainerKey] || (target[metadataContainerKey] = {});
var targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {});
if (typeof theGlobal.Reflect.defineMetadata === 'undefined') {
Reflect.defineMetadata = function(metadataKey, metadataValue, target, targetKey) {
let metadataContainer = target.hasOwnProperty(metadataContainerKey) ? target[metadataContainerKey] : (target[metadataContainerKey] = {});
let targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {});
targetContainer[metadataKey] = metadataValue;

@@ -48,5 +27,5 @@ };

if(typeof theGlobal.Reflect.metadata === 'undefined'){
Reflect.metadata = function(metadataKey, metadataValue){
return function(target, targetKey){
if (typeof theGlobal.Reflect.metadata === 'undefined') {
Reflect.metadata = function(metadataKey, metadataValue) {
return function(target, targetKey) {
Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey);

@@ -57,17 +36,47 @@ };

function ensureDecorators(target){
var applicator;
if(typeof target.decorators === 'function'){
applicator = target.decorators();
}else{
applicator = target.decorators;
}
if(typeof applicator._decorate === 'function'){
delete target.decorators;
applicator._decorate(target);
}else{
throw new Error('The return value of your decorator\'s method was not valid.');
}
/**
* Helpers for working with metadata on functions.
*/
interface MetadataType {
/**
* The metadata key representing pluggable resources.
*/
resource: string;
/**
* The metadata key representing parameter type information.
*/
paramTypes: string;
/**
* The metadata key representing property information.
*/
properties: string;
/**
* Gets metadata specified by a key on a target, searching up the inheritance hierarchy.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
get(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Gets metadata specified by a key on a target, only searching the own instance.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
getOwn(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Defines metadata specified by a key on a target.
* @param metadataKey The key for the metadata to define.
* @param target The target to set the metadata on.
* @param targetKey The member on the target to set the metadata on.
*/
define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void;
/**
* Gets metadata specified by a key on a target, or creates an instance of the specified metadata if not found.
* @param metadataKey The key for the metadata to lookup or create.
* @param Type The type of metadata to create if existing metadata is not found.
* @param target The target to lookup or create the metadata on.
* @param targetKey The member on the target to lookup or create the metadata on.
*/
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object;
}

@@ -77,37 +86,23 @@

* Provides helpers for working with metadata.
*
* @class Metadata
* @static
*/
export var Metadata = {
global: theGlobal,
resource:'aurelia:resource',
paramTypes:'design:paramtypes',
properties:'design:properties',
get(metadataKey:string, target:Function, targetKey:string){
if(!target){
return undefined;
}
let result = Metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? Metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
export const metadata: MetadataType = {
resource: 'aurelia:resource',
paramTypes: 'design:paramtypes',
properties: 'design:properties',
get(metadataKey: string, target: Function, targetKey: string): Object {
if (!target) { return undefined; }
let result = metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
},
getOwn(metadataKey:string, target:Function, targetKey:string){
if(!target){
return undefined;
}
if(target.hasOwnProperty('decorators')){
ensureDecorators(target);
}
getOwn(metadataKey: string, target: Function, targetKey: string): Object {
if (!target) { return undefined; }
return Reflect.getOwnMetadata(metadataKey, target, targetKey);
},
define(metadataKey:string, metadataValue:string, target:Function, targetKey:string){
define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void {
Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey);
},
getOrCreateOwn(metadataKey:string, Type:Function, target:Function, targetKey:string){
let result = Metadata.getOwn(metadataKey, target, targetKey);
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object {
let result = metadata.getOwn(metadataKey, target, targetKey);
if(result === undefined){
if (result === undefined) {
result = new Type();

@@ -119,17 +114,26 @@ Reflect.defineMetadata(metadataKey, result, target, targetKey);

}
}
};
var originStorage = new Map(),
unknownOrigin = Object.freeze({moduleId:undefined,moduleMember:undefined});
const originStorage = new Map();
const unknownOrigin = Object.freeze({moduleId: undefined, moduleMember: undefined});
/**
* A metadata annotation that describes the origin module of the function to which it's attached.
*
* @class Origin
* @constructor
* @param {string} moduleId The origin module id.
* @param {string} moduleMember The name of the export in the origin module.
*/
export class Origin {
constructor(moduleId:string, moduleMember:string){
/**
* The id of the module from which the item originated.
*/
moduleId: string;
/**
* The member name of the export on the module object from which the item originated.
*/
moduleMember: string;
/**
* Creates an instance of Origin metadata.
* @param moduleId The id of the module from which the item originated.
* @param moduleMember The member name of the export on the module object from which the item originated.
*/
constructor(moduleId: string, moduleMember: string) {
this.moduleId = moduleId;

@@ -140,17 +144,14 @@ this.moduleMember = moduleMember;

/**
* Get the Origin annotation for the specified function.
*
* @method get
* @static
* @param {Function} fn The function to inspect for Origin metadata.
* @return {Origin} Returns the Origin metadata.
* Get the Origin metadata for the specified function.
* @param fn The function to inspect for Origin metadata.
* @return Returns the Origin metadata.
*/
static get(fn:Function){
var origin = originStorage.get(fn);
static get(fn: Function): Origin {
let origin = originStorage.get(fn);
if(origin === undefined){
System.forEachModule((key, value) => {
for(var name in value){
var exp = value[name];
if(exp === fn){
if (origin === undefined) {
PLATFORM.eachModule((key, value) => {
for (let name in value) {
let exp = value[name];
if (exp === fn) {
originStorage.set(fn, origin = new Origin(key, name));

@@ -161,3 +162,3 @@ return true;

if(value === fn){
if (value === fn) {
originStorage.set(fn, origin = new Origin(key, 'default'));

@@ -173,11 +174,8 @@ return true;

/**
* Set the Origin annotation for the specified function.
*
* @method set
* @static
* @param {Function} fn The function to set the Origin metadata on.
* @param {origin} fn The Origin metadata to store on the function.
* @return {Origin} Returns the Origin metadata.
* Set the Origin metadata for the specified function.
* @param fn The function to set the Origin metadata on.
* @param fn The Origin metadata to store on the function.
* @return Returns the Origin metadata.
*/
static set(fn:Function, origin:Origin){
static set(fn: Function, origin: Origin): void {
originStorage.set(fn, origin);

@@ -187,82 +185,228 @@ }

export class DecoratorApplicator {
constructor(){
this._first = null;
this._second = null;
this._third = null;
this._rest = null;
}
/**
* An object capable of applying it's captured decorators to a target.
*/
interface DecoratorApplicator {
/**
* Applies the decorators to the target.
* @param target The target.
* @param key If applying to a method, the member name.
* @param key If applying to a method, you may supply an initial descriptor to pass to the decorators.
*/
on(target: any, key?: string, descriptor?: Object): any;
}
decorator(decorator:Function):DecoratorApplicator{
if(this._first === null){
this._first = decorator;
return this;
}
/**
* Enables applying decorators, particularly for use when there is no syntax support in the language, such as with ES5 and ES2016.
* @param rest The decorators to apply.
*/
export function decorators(...rest: Function[]): DecoratorApplicator {
let applicator = function(target, key, descriptor) {
let i = rest.length;
if(this._second === null){
this._second = decorator;
return this;
}
if (key) {
descriptor = descriptor || {
value: target[key],
writable: true,
configurable: true,
enumerable: true
};
if(this._third === null){
this._third = decorator;
return this;
}
while (i--) {
descriptor = rest[i](target, key, descriptor) || descriptor;
}
if(this._rest === null){
this._rest = [];
Object.defineProperty(target, key, descriptor);
} else {
while (i--) {
target = rest[i](target) || target;
}
}
this._rest.push(decorator);
return target;
};
return this;
}
applicator.on = applicator;
return applicator;
}
_decorate(target:Function){
var i, ii, rest;
/**
* Options that control how the deprected decorator should function at runtime.
*/
interface DeprecatedOptions {
/**
* Specifies a custom deprecation message.
*/
message: string;
/**
* Specifies whether or not the deprecation should throw an error.
*/
error: boolean;
}
if(this._first !== null){
this._first(target);
}
/**
* Decorator: Enables marking methods as deprecated.
* @param optionsOrTarget Options for how the deprected decorator should function at runtime.
*/
export function deprecated(optionsOrTarget?: DeprecatedOptions, maybeKey?: string, maybeDescriptor?: Object): any {
function decorator(target, key, descriptor) {
const methodSignature = `${target.constructor.name}#${key}`;
let options = maybeKey ? {} : optionsOrTarget || {};
let message = `DEPRECATION - ${methodSignature}`;
if(this._second !== null){
this._second(target);
if (typeof descriptor.value !== 'function') {
throw new SyntaxError('Only methods can be marked as deprecated.');
}
if(this._third !== null){
this._third(target);
if (options.message) {
message += ` - ${options.message}`;
}
rest = this._rest;
if(rest !== null){
for(i = 0, ii = rest.length; i < ii; ++i){
rest[i](target);
return {
...descriptor,
value: function deprecationWrapper() {
if (options.error) {
throw new Error(message);
} else {
console.warn(message);
}
return descriptor.value.apply(this, arguments);
}
}
};
}
return maybeKey ? decorator(optionsOrTarget, maybeKey, maybeDescriptor) : decorator;
}
export var Decorators = {
configure: {
parameterizedDecorator(name:string, decorator:Function){
Decorators[name] = function(){
var applicator = new DecoratorApplicator();
return applicator[name].apply(applicator, arguments);
};
/**
* Decorator: Enables mixing behaior into a class.
* @param behavior An object with keys for each method to mix into the target class.
*/
export function mixin(behavior: Object): any {
const instanceKeys = Object.keys(behavior);
DecoratorApplicator.prototype[name] = function(){
var result = decorator.apply(null, arguments);
return this.decorator(result);
};
},
simpleDecorator(name:string, decorator:Function){
Decorators[name] = function(){
return new DecoratorApplicator().decorator(decorator);
};
function _mixin(possible) {
let decorator = function(target) {
let resolvedTarget = typeof target === 'function'
? target.prototype
: target;
DecoratorApplicator.prototype[name] = function(){
return this.decorator(decorator);
for (let property of instanceKeys) {
Object.defineProperty(resolvedTarget, property, {
value: behavior[property],
writable: true
});
}
}
};
return possible ? decorator(possible) : decorator;
}
return _mixin;
}
function alwaysValid() { return true; }
function noCompose() {}
function ensureProtocolOptions(options) {
if (options === undefined) {
options = {};
} else if (typeof options === 'function') {
options = {
validate: options
};
}
if (!options.validate) {
options.validate = alwaysValid;
}
if (!options.compose) {
options.compose = noCompose;
}
return options;
}
function createProtocolValidator(validate) {
return function(target) {
let result = validate(target);
return result === true;
};
}
function createProtocolAsserter(name, validate) {
return function(target) {
let result = validate(target);
if (result !== true) {
throw new Error(result || `${name} was not correctly implemented.`);
}
};
}
/**
* Options used during protocol creation.
*/
interface ProtocolOptions {
/**
* A function that will be run to validate the decorated class when the protocol is applied. It is also used to validate adhoc instances.
* If the validation fails, a message should be returned which directs the developer in how to address the issue.
*/
validate?: (target: any) => string | boolean;
/**
* A function which has the opportunity to compose additional behavior into the decorated class when the protocol is applied.
*/
compose?: (target: any) => void;
}
/**
* Decorator: Creates a protocol.
* @param name The name of the protocol.
* @param options The validation function or options object used in configuring the protocol.
*/
export function protocol(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): any {
options = ensureProtocolOptions(options);
let result = function(target) {
let resolvedTarget = typeof target === 'function'
? target.prototype
: target;
options.compose(resolvedTarget);
result.assert(resolvedTarget);
Object.defineProperty(resolvedTarget, 'protocol:' + name, {
enumerable: false,
configurable: false,
writable: false,
value: true
});
};
result.validate = createProtocolValidator(options.validate);
result.assert = createProtocolAsserter(name, options.validate);
return result;
}
/**
* Creates a protocol decorator.
* @param name The name of the protocol.
* @param options The validation function or options object used in configuring the protocol.
* @return The protocol decorator;
*/
protocol.create = function(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): Function {
options = ensureProtocolOptions(options);
let hidden = 'protocol:' + name;
let result = function(target) {
let decorator = protocol(name, options);
return target ? decorator(target) : decorator;
};
result.decorates = function(obj) { return obj[hidden] === true; };
result.validate = createProtocolValidator(options.validate);
result.assert = createProtocolAsserter(name, options.validate);
return result;
};
declare module 'aurelia-metadata' {
import core from 'core-js';
import 'core-js';
import { PLATFORM } from 'aurelia-pal';
/**
* Helpers for working with metadata on functions.
*/
export interface MetadataType {
/**
* The metadata key representing pluggable resources.
*/
resource: string;
/**
* The metadata key representing parameter type information.
*/
paramTypes: string;
/**
* The metadata key representing property information.
*/
properties: string;
/**
* Gets metadata specified by a key on a target, searching up the inheritance hierarchy.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
get(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Gets metadata specified by a key on a target, only searching the own instance.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
getOwn(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Defines metadata specified by a key on a target.
* @param metadataKey The key for the metadata to define.
* @param target The target to set the metadata on.
* @param targetKey The member on the target to set the metadata on.
*/
define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void;
/**
* Gets metadata specified by a key on a target, or creates an instance of the specified metadata if not found.
* @param metadataKey The key for the metadata to lookup or create.
* @param Type The type of metadata to create if existing metadata is not found.
* @param target The target to lookup or create the metadata on.
* @param targetKey The member on the target to lookup or create the metadata on.
*/
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object;
}
/**
* An object capable of applying it's captured decorators to a target.
*/
export interface DecoratorApplicator {
/**
* Applies the decorators to the target.
* @param target The target.
* @param key If applying to a method, the member name.
* @param key If applying to a method, you may supply an initial descriptor to pass to the decorators.
*/
on(target: any, key?: string, descriptor?: Object): any;
}
/**
* Options that control how the deprected decorator should function at runtime.
*/
export interface DeprecatedOptions {
/**
* Specifies a custom deprecation message.
*/
message: string;
/**
* Specifies whether or not the deprecation should throw an error.
*/
error: boolean;
}
/**
* Options used during protocol creation.
*/
export interface ProtocolOptions {
/**
* A function that will be run to validate the decorated class when the protocol is applied. It is also used to validate adhoc instances.
* If the validation fails, a message should be returned which directs the developer in how to address the issue.
*/
validate?: (target: any) => string | boolean;
/**
* A function which has the opportunity to compose additional behavior into the decorated class when the protocol is applied.
*/
compose?: (target: any) => void;
}
/**
* Provides helpers for working with metadata.
*
* @class Metadata
* @static
*/
export var Metadata: any;
export const metadata: MetadataType;
/**
* A metadata annotation that describes the origin module of the function to which it's attached.
*
* @class Origin
* @constructor
* @param {string} moduleId The origin module id.
* @param {string} moduleMember The name of the export in the origin module.
*/
export class Origin {
/**
* The id of the module from which the item originated.
*/
moduleId: string;
/**
* The member name of the export on the module object from which the item originated.
*/
moduleMember: string;
/**
* Creates an instance of Origin metadata.
* @param moduleId The id of the module from which the item originated.
* @param moduleMember The member name of the export on the module object from which the item originated.
*/
constructor(moduleId: string, moduleMember: string);
/**
* Get the Origin annotation for the specified function.
*
* @method get
* @static
* @param {Function} fn The function to inspect for Origin metadata.
* @return {Origin} Returns the Origin metadata.
* Get the Origin metadata for the specified function.
* @param fn The function to inspect for Origin metadata.
* @return Returns the Origin metadata.
*/
static get(fn: Function): any;
static get(fn: Function): Origin;
/**
* Set the Origin annotation for the specified function.
*
* @method set
* @static
* @param {Function} fn The function to set the Origin metadata on.
* @param {origin} fn The Origin metadata to store on the function.
* @return {Origin} Returns the Origin metadata.
* Set the Origin metadata for the specified function.
* @param fn The function to set the Origin metadata on.
* @param fn The Origin metadata to store on the function.
* @return Returns the Origin metadata.
*/
static set(fn: Function, origin: Origin): any;
static set(fn: Function, origin: Origin): void;
}
export class DecoratorApplicator {
constructor();
decorator(decorator: Function): DecoratorApplicator;
}
export var Decorators: any;
/**
* Enables applying decorators, particularly for use when there is no syntax support in the language, such as with ES5 and ES2016.
* @param rest The decorators to apply.
*/
export function decorators(...rest: Function[]): DecoratorApplicator;
/**
* Decorator: Enables marking methods as deprecated.
* @param optionsOrTarget Options for how the deprected decorator should function at runtime.
*/
export function deprecated(optionsOrTarget?: DeprecatedOptions, maybeKey?: string, maybeDescriptor?: Object): any;
/**
* Decorator: Enables mixing behaior into a class.
* @param behavior An object with keys for each method to mix into the target class.
*/
export function mixin(behavior: Object): any;
/**
* Decorator: Creates a protocol.
* @param name The name of the protocol.
* @param options The validation function or options object used in configuring the protocol.
*/
export function protocol(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): any;
}

@@ -1,53 +0,189 @@

System.register(['core-js'], function (_export) {
System.register(['core-js', 'aurelia-pal'], function (_export) {
'use strict';
var core, theGlobal, emptyMetadata, metadataContainerKey, Metadata, originStorage, unknownOrigin, Origin, DecoratorApplicator, Decorators;
var PLATFORM, theGlobal, emptyMetadata, metadataContainerKey, metadata, originStorage, unknownOrigin, Origin;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function ensureDecorators(target) {
var applicator;
_export('decorators', decorators);
if (typeof target.decorators === 'function') {
applicator = target.decorators();
} else {
applicator = target.decorators;
}
_export('deprecated', deprecated);
if (typeof applicator._decorate === 'function') {
delete target.decorators;
applicator._decorate(target);
} else {
throw new Error('The return value of your decorator\'s method was not valid.');
_export('mixin', mixin);
_export('protocol', protocol);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function decorators() {
for (var _len = arguments.length, rest = Array(_len), _key = 0; _key < _len; _key++) {
rest[_key] = arguments[_key];
}
}
return {
setters: [function (_coreJs) {
core = _coreJs['default'];
}],
execute: function () {
theGlobal = (function () {
if (typeof self !== 'undefined') {
return self;
var applicator = function applicator(target, key, descriptor) {
var i = rest.length;
if (key) {
descriptor = descriptor || {
value: target[key],
writable: true,
configurable: true,
enumerable: true
};
while (i--) {
descriptor = rest[i](target, key, descriptor) || descriptor;
}
if (typeof global !== 'undefined') {
return global;
Object.defineProperty(target, key, descriptor);
} else {
while (i--) {
target = rest[i](target) || target;
}
}
return new Function('return this')();
})();
return target;
};
emptyMetadata = Object.freeze({});
metadataContainerKey = '__metadata__';
applicator.on = applicator;
return applicator;
}
if (typeof theGlobal.System === 'undefined') {
theGlobal.System = { isFake: true };
function deprecated(optionsOrTarget, maybeKey, maybeDescriptor) {
function decorator(target, key, descriptor) {
var methodSignature = target.constructor.name + '#' + key;
var options = maybeKey ? {} : optionsOrTarget || {};
var message = 'DEPRECATION - ' + methodSignature;
if (typeof descriptor.value !== 'function') {
throw new SyntaxError('Only methods can be marked as deprecated.');
}
if (typeof theGlobal.System.forEachModule === 'undefined') {
theGlobal.System.forEachModule = function () {};
if (options.message) {
message += ' - ' + options.message;
}
return _extends({}, descriptor, {
value: function deprecationWrapper() {
if (options.error) {
throw new Error(message);
} else {
console.warn(message);
}
return descriptor.value.apply(this, arguments);
}
});
}
return maybeKey ? decorator(optionsOrTarget, maybeKey, maybeDescriptor) : decorator;
}
function mixin(behavior) {
var instanceKeys = Object.keys(behavior);
function _mixin(possible) {
var decorator = function decorator(target) {
var resolvedTarget = typeof target === 'function' ? target.prototype : target;
for (var _iterator = instanceKeys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var property = _ref;
Object.defineProperty(resolvedTarget, property, {
value: behavior[property],
writable: true
});
}
};
return possible ? decorator(possible) : decorator;
}
return _mixin;
}
function alwaysValid() {
return true;
}
function noCompose() {}
function ensureProtocolOptions(options) {
if (options === undefined) {
options = {};
} else if (typeof options === 'function') {
options = {
validate: options
};
}
if (!options.validate) {
options.validate = alwaysValid;
}
if (!options.compose) {
options.compose = noCompose;
}
return options;
}
function createProtocolValidator(validate) {
return function (target) {
var result = validate(target);
return result === true;
};
}
function createProtocolAsserter(name, validate) {
return function (target) {
var result = validate(target);
if (result !== true) {
throw new Error(result || name + ' was not correctly implemented.');
}
};
}
function protocol(name, options) {
options = ensureProtocolOptions(options);
var result = function result(target) {
var resolvedTarget = typeof target === 'function' ? target.prototype : target;
options.compose(resolvedTarget);
result.assert(resolvedTarget);
Object.defineProperty(resolvedTarget, 'protocol:' + name, {
enumerable: false,
configurable: false,
writable: false,
value: true
});
};
result.validate = createProtocolValidator(options.validate);
result.assert = createProtocolAsserter(name, options.validate);
return result;
}
return {
setters: [function (_coreJs) {}, function (_aureliaPal) {
PLATFORM = _aureliaPal.PLATFORM;
}],
execute: function () {
theGlobal = PLATFORM.global;
emptyMetadata = Object.freeze({});
metadataContainerKey = '__metadata__';
if (typeof theGlobal.Reflect === 'undefined') {

@@ -65,3 +201,3 @@ theGlobal.Reflect = {};

Reflect.defineMetadata = function (metadataKey, metadataValue, target, targetKey) {
var metadataContainer = target[metadataContainerKey] || (target[metadataContainerKey] = {});
var metadataContainer = target.hasOwnProperty(metadataContainerKey) ? target[metadataContainerKey] : target[metadataContainerKey] = {};
var targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {});

@@ -78,4 +214,5 @@ targetContainer[metadataKey] = metadataValue;

};
}Metadata = {
global: theGlobal,
}
metadata = {
resource: 'aurelia:resource',

@@ -88,5 +225,4 @@ paramTypes: 'design:paramtypes',

}
var result = Metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? Metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
var result = metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
},

@@ -97,7 +233,2 @@ getOwn: function getOwn(metadataKey, target, targetKey) {

}
if (target.hasOwnProperty('decorators')) {
ensureDecorators(target);
}
return Reflect.getOwnMetadata(metadataKey, target, targetKey);

@@ -109,3 +240,3 @@ },

getOrCreateOwn: function getOrCreateOwn(metadataKey, Type, target, targetKey) {
var result = Metadata.getOwn(metadataKey, target, targetKey);
var result = metadata.getOwn(metadataKey, target, targetKey);

@@ -121,3 +252,3 @@ if (result === undefined) {

_export('Metadata', Metadata);
_export('metadata', metadata);

@@ -139,7 +270,7 @@ originStorage = new Map();

if (origin === undefined) {
System.forEachModule(function (key, value) {
for (var name in value) {
var exp = value[name];
PLATFORM.eachModule(function (key, value) {
for (var _name in value) {
var exp = value[_name];
if (exp === fn) {
originStorage.set(fn, origin = new Origin(key, name));
originStorage.set(fn, origin = new Origin(key, _name));
return true;

@@ -168,93 +299,20 @@ }

DecoratorApplicator = (function () {
function DecoratorApplicator() {
_classCallCheck(this, DecoratorApplicator);
this._first = null;
this._second = null;
this._third = null;
this._rest = null;
}
DecoratorApplicator.prototype.decorator = function decorator(_decorator) {
if (this._first === null) {
this._first = _decorator;
return this;
}
if (this._second === null) {
this._second = _decorator;
return this;
}
if (this._third === null) {
this._third = _decorator;
return this;
}
if (this._rest === null) {
this._rest = [];
}
this._rest.push(_decorator);
return this;
protocol.create = function (name, options) {
options = ensureProtocolOptions(options);
var hidden = 'protocol:' + name;
var result = function result(target) {
var decorator = protocol(name, options);
return target ? decorator(target) : decorator;
};
DecoratorApplicator.prototype._decorate = function _decorate(target) {
var i, ii, rest;
if (this._first !== null) {
this._first(target);
}
if (this._second !== null) {
this._second(target);
}
if (this._third !== null) {
this._third(target);
}
rest = this._rest;
if (rest !== null) {
for (i = 0, ii = rest.length; i < ii; ++i) {
rest[i](target);
}
}
result.decorates = function (obj) {
return obj[hidden] === true;
};
result.validate = createProtocolValidator(options.validate);
result.assert = createProtocolAsserter(name, options.validate);
return DecoratorApplicator;
})();
_export('DecoratorApplicator', DecoratorApplicator);
Decorators = {
configure: {
parameterizedDecorator: function parameterizedDecorator(name, decorator) {
Decorators[name] = function () {
var applicator = new DecoratorApplicator();
return applicator[name].apply(applicator, arguments);
};
DecoratorApplicator.prototype[name] = function () {
var result = decorator.apply(null, arguments);
return this.decorator(result);
};
},
simpleDecorator: function simpleDecorator(name, decorator) {
Decorators[name] = function () {
return new DecoratorApplicator().decorator(decorator);
};
DecoratorApplicator.prototype[name] = function () {
return this.decorator(decorator);
};
}
}
return result;
};
_export('Decorators', Decorators);
}
};
});

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

{"id":2,"name":"\"aurelia-metadata\"","kind":2,"kindString":"Module","flags":{},"children":[{"id":15,"name":"DecoratorApplicator","kind":128,"kindString":"Class","flags":{"isExported":true},"children":[{"id":16,"name":"constructor","kind":512,"kindString":"Constructor","flags":{"isExported":true},"signatures":[{"id":17,"name":"new DecoratorApplicator","kind":16384,"kindString":"Constructor signature","flags":{},"type":{"type":"reference","name":"DecoratorApplicator","id":15}}]},{"id":18,"name":"decorator","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":19,"name":"decorator","kind":4096,"kindString":"Call signature","flags":{},"parameters":[{"id":20,"name":"decorator","kind":32768,"kindString":"Parameter","flags":{},"type":{"type":"reference","name":"Function"}}],"type":{"type":"reference","name":"DecoratorApplicator","id":15}}]}],"groups":[{"title":"Constructors","kind":512,"children":[16]},{"title":"Methods","kind":2048,"children":[18]}]},{"id":3,"name":"Origin","kind":128,"kindString":"Class","flags":{"isExported":true},"comment":{"shortText":"A metadata annotation that describes the origin module of the function to which it's attached.","tags":[{"tag":"class","text":"Origin"},{"tag":"constructor","text":""},{"tag":"param","text":"The origin module id.","param":"moduleId"},{"tag":"param","text":"The name of the export in the origin module.\n","param":"moduleMember"}]},"children":[{"id":4,"name":"constructor","kind":512,"kindString":"Constructor","flags":{"isExported":true},"signatures":[{"id":5,"name":"new Origin","kind":16384,"kindString":"Constructor signature","flags":{},"parameters":[{"id":6,"name":"moduleId","kind":32768,"kindString":"Parameter","flags":{},"type":{"type":"instrinct","name":"string"}},{"id":7,"name":"moduleMember","kind":32768,"kindString":"Parameter","flags":{},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"reference","name":"Origin","id":3}}]},{"id":8,"name":"get","kind":2048,"kindString":"Method","flags":{"isStatic":true,"isExported":true},"signatures":[{"id":9,"name":"get","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Get the Origin annotation for the specified function.","returns":"Returns the Origin metadata.\n","tags":[{"tag":"method","text":"get"},{"tag":"static","text":""}]},"parameters":[{"id":10,"name":"fn","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The function to inspect for Origin metadata."},"type":{"type":"reference","name":"Function"}}],"type":{"type":"instrinct","name":"any"}}]},{"id":11,"name":"set","kind":2048,"kindString":"Method","flags":{"isStatic":true,"isExported":true},"signatures":[{"id":12,"name":"set","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Set the Origin annotation for the specified function.","returns":"Returns the Origin metadata.\n","tags":[{"tag":"method","text":"set"},{"tag":"static","text":""}]},"parameters":[{"id":13,"name":"fn","kind":32768,"kindString":"Parameter","flags":{},"comment":{"shortText":"The Origin metadata to store on the function."},"type":{"type":"reference","name":"Function"}},{"id":14,"name":"origin","kind":32768,"kindString":"Parameter","flags":{},"type":{"type":"reference","name":"Origin","id":3}}],"type":{"type":"instrinct","name":"any"}}]}],"groups":[{"title":"Constructors","kind":512,"children":[4]},{"title":"Methods","kind":2048,"children":[8,11]}]},{"id":22,"name":"Decorators","kind":32,"kindString":"Variable","flags":{"isExported":true},"type":{"type":"instrinct","name":"any"}},{"id":21,"name":"Metadata","kind":32,"kindString":"Variable","flags":{"isExported":true},"comment":{"shortText":"Provides helpers for working with metadata.","tags":[{"tag":"class","text":"Metadata"},{"tag":"static","text":"\n"}]},"type":{"type":"instrinct","name":"any"}}],"groups":[{"title":"Classes","kind":128,"children":[15,3]},{"title":"Variables","kind":32,"children":[22,21]}]}
{"id":2,"name":"\"aurelia-metadata\"","kind":2,"kindString":"Module","flags":{},"children":[{"id":47,"name":"Origin","kind":128,"kindString":"Class","flags":{"isExported":true},"comment":{"shortText":"A metadata annotation that describes the origin module of the function to which it's attached."},"children":[{"id":50,"name":"constructor","kind":512,"kindString":"Constructor","flags":{"isExported":true},"comment":{"shortText":"Creates an instance of Origin metadata."},"signatures":[{"id":51,"name":"new Origin","kind":16384,"kindString":"Constructor signature","flags":{},"comment":{"shortText":"Creates an instance of Origin metadata."},"parameters":[{"id":52,"name":"moduleId","kind":32768,"kindString":"Parameter","flags":{},"comment":{"shortText":"The id of the module from which the item originated."},"type":{"type":"instrinct","name":"string"}},{"id":53,"name":"moduleMember","kind":32768,"kindString":"Parameter","flags":{},"comment":{"shortText":"The member name of the export on the module object from which the item originated.\n"},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"reference","name":"Origin","id":47}}]},{"id":48,"name":"moduleId","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"The id of the module from which the item originated."},"type":{"type":"instrinct","name":"string"}},{"id":49,"name":"moduleMember","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"The member name of the export on the module object from which the item originated."},"type":{"type":"instrinct","name":"string"}},{"id":54,"name":"get","kind":2048,"kindString":"Method","flags":{"isStatic":true,"isExported":true},"signatures":[{"id":55,"name":"get","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Get the Origin metadata for the specified function.","returns":"Returns the Origin metadata.\n"},"parameters":[{"id":56,"name":"fn","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The function to inspect for Origin metadata."},"type":{"type":"reference","name":"Function"}}],"type":{"type":"reference","name":"Origin","id":47}}]},{"id":57,"name":"set","kind":2048,"kindString":"Method","flags":{"isStatic":true,"isExported":true},"signatures":[{"id":58,"name":"set","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Set the Origin metadata for the specified function.","returns":"Returns the Origin metadata.\n"},"parameters":[{"id":59,"name":"fn","kind":32768,"kindString":"Parameter","flags":{},"comment":{"shortText":"The Origin metadata to store on the function."},"type":{"type":"reference","name":"Function"}},{"id":60,"name":"origin","kind":32768,"kindString":"Parameter","flags":{},"type":{"type":"reference","name":"Origin","id":47}}],"type":{"type":"instrinct","name":"void"}}]}],"groups":[{"title":"Constructors","kind":512,"children":[50]},{"title":"Properties","kind":1024,"children":[48,49]},{"title":"Methods","kind":2048,"children":[54,57]}]},{"id":29,"name":"DecoratorApplicator","kind":256,"kindString":"Interface","flags":{"isExported":true},"comment":{"shortText":"An object capable of applying it's captured decorators to a target."},"children":[{"id":30,"name":"on","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":31,"name":"on","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Applies the decorators to the target."},"parameters":[{"id":32,"name":"target","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The target."},"type":{"type":"instrinct","name":"any"}},{"id":33,"name":"key","kind":32768,"kindString":"Parameter","flags":{"isOptional":true},"comment":{"shortText":"If applying to a method, you may supply an initial descriptor to pass to the decorators.\n"},"type":{"type":"instrinct","name":"string"}},{"id":34,"name":"descriptor","kind":32768,"kindString":"Parameter","flags":{"isOptional":true},"type":{"type":"reference","name":"Object"}}],"type":{"type":"instrinct","name":"any"}}]}],"groups":[{"title":"Methods","kind":2048,"children":[30]}]},{"id":35,"name":"DeprecatedOptions","kind":256,"kindString":"Interface","flags":{"isExported":true},"comment":{"shortText":"Options that control how the deprected decorator should function at runtime."},"children":[{"id":37,"name":"error","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"Specifies whether or not the deprecation should throw an error."},"type":{"type":"instrinct","name":"boolean"}},{"id":36,"name":"message","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"Specifies a custom deprecation message."},"type":{"type":"instrinct","name":"string"}}],"groups":[{"title":"Properties","kind":1024,"children":[37,36]}]},{"id":3,"name":"MetadataType","kind":256,"kindString":"Interface","flags":{"isExported":true},"comment":{"shortText":"Helpers for working with metadata on functions."},"children":[{"id":5,"name":"paramTypes","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"The metadata key representing parameter type information."},"type":{"type":"instrinct","name":"string"}},{"id":6,"name":"properties","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"The metadata key representing property information."},"type":{"type":"instrinct","name":"string"}},{"id":4,"name":"resource","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"The metadata key representing pluggable resources."},"type":{"type":"instrinct","name":"string"}},{"id":17,"name":"define","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":18,"name":"define","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Defines metadata specified by a key on a target."},"parameters":[{"id":19,"name":"metadataKey","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The key for the metadata to define."},"type":{"type":"instrinct","name":"string"}},{"id":20,"name":"metadataValue","kind":32768,"kindString":"Parameter","flags":{},"type":{"type":"reference","name":"Object"}},{"id":21,"name":"target","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The target to set the metadata on."},"type":{"type":"reference","name":"Function"}},{"id":22,"name":"targetKey","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The member on the target to set the metadata on.\n"},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"instrinct","name":"void"}}]},{"id":7,"name":"get","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":8,"name":"get","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Gets metadata specified by a key on a target, searching up the inheritance hierarchy."},"parameters":[{"id":9,"name":"metadataKey","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The key for the metadata to lookup."},"type":{"type":"instrinct","name":"string"}},{"id":10,"name":"target","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The target to lookup the metadata on."},"type":{"type":"reference","name":"Function"}},{"id":11,"name":"targetKey","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The member on the target to lookup the metadata on.\n"},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"reference","name":"Object"}}]},{"id":23,"name":"getOrCreateOwn","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":24,"name":"getOrCreateOwn","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Gets metadata specified by a key on a target, or creates an instance of the specified metadata if not found."},"parameters":[{"id":25,"name":"metadataKey","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The key for the metadata to lookup or create."},"type":{"type":"instrinct","name":"string"}},{"id":26,"name":"Type","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The type of metadata to create if existing metadata is not found."},"type":{"type":"reference","name":"Function"}},{"id":27,"name":"target","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The target to lookup or create the metadata on."},"type":{"type":"reference","name":"Function"}},{"id":28,"name":"targetKey","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The member on the target to lookup or create the metadata on.\n"},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"reference","name":"Object"}}]},{"id":12,"name":"getOwn","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":13,"name":"getOwn","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Gets metadata specified by a key on a target, only searching the own instance."},"parameters":[{"id":14,"name":"metadataKey","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The key for the metadata to lookup."},"type":{"type":"instrinct","name":"string"}},{"id":15,"name":"target","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The target to lookup the metadata on."},"type":{"type":"reference","name":"Function"}},{"id":16,"name":"targetKey","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The member on the target to lookup the metadata on.\n"},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"reference","name":"Object"}}]}],"groups":[{"title":"Properties","kind":1024,"children":[5,6,4]},{"title":"Methods","kind":2048,"children":[17,7,23,12]}]},{"id":38,"name":"ProtocolOptions","kind":256,"kindString":"Interface","flags":{"isExported":true},"comment":{"shortText":"Options used during protocol creation."},"children":[{"id":43,"name":"compose","kind":1024,"kindString":"Property","flags":{"isExported":true,"isOptional":true},"comment":{"shortText":"A function which has the opportunity to compose additional behavior into the decorated class when the protocol is applied."},"type":{"type":"reflection","declaration":{"id":44,"name":"__type","kind":65536,"kindString":"Type literal","flags":{},"signatures":[{"id":45,"name":"__call","kind":4096,"kindString":"Call signature","flags":{},"parameters":[{"id":46,"name":"target","kind":32768,"kindString":"Parameter","flags":{},"type":{"type":"instrinct","name":"any"}}],"type":{"type":"instrinct","name":"void"}}]}}},{"id":39,"name":"validate","kind":1024,"kindString":"Property","flags":{"isExported":true,"isOptional":true},"comment":{"shortText":"A function that will be run to validate the decorated class when the protocol is applied. It is also used to validate adhoc instances.\nIf the validation fails, a message should be returned which directs the developer in how to address the issue."},"type":{"type":"reflection","declaration":{"id":40,"name":"__type","kind":65536,"kindString":"Type literal","flags":{},"signatures":[{"id":41,"name":"__call","kind":4096,"kindString":"Call signature","flags":{},"parameters":[{"id":42,"name":"target","kind":32768,"kindString":"Parameter","flags":{},"type":{"type":"instrinct","name":"any"}}],"type":{"type":"union","types":[{"type":"instrinct","name":"string"},{"type":"instrinct","name":"boolean"}]}}]}}}],"groups":[{"title":"Properties","kind":1024,"children":[43,39]}]},{"id":61,"name":"metadata","kind":32,"kindString":"Variable","flags":{"isExported":true},"comment":{"shortText":"Provides helpers for working with metadata."},"type":{"type":"reference","name":"MetadataType","id":3}},{"id":62,"name":"decorators","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":63,"name":"decorators","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Enables applying decorators, particularly for use when there is no syntax support in the language, such as with ES5 and ES2016."},"parameters":[{"id":64,"name":"rest","kind":32768,"kindString":"Parameter","flags":{"isRest":true},"comment":{"text":"The decorators to apply.\n"},"type":{"type":"reference","isArray":true,"name":"Function"}}],"type":{"type":"reference","name":"DecoratorApplicator","id":29}}]},{"id":65,"name":"deprecated","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":66,"name":"deprecated","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Decorator: Enables marking methods as deprecated."},"parameters":[{"id":67,"name":"optionsOrTarget","kind":32768,"kindString":"Parameter","flags":{"isOptional":true},"comment":{"text":"Options for how the deprected decorator should function at runtime.\n"},"type":{"type":"reference","name":"DeprecatedOptions","id":35}},{"id":68,"name":"maybeKey","kind":32768,"kindString":"Parameter","flags":{"isOptional":true},"type":{"type":"instrinct","name":"string"}},{"id":69,"name":"maybeDescriptor","kind":32768,"kindString":"Parameter","flags":{"isOptional":true},"type":{"type":"reference","name":"Object"}}],"type":{"type":"instrinct","name":"any"}}]},{"id":70,"name":"mixin","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":71,"name":"mixin","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Decorator: Enables mixing behaior into a class."},"parameters":[{"id":72,"name":"behavior","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"An object with keys for each method to mix into the target class.\n"},"type":{"type":"reference","name":"Object"}}],"type":{"type":"instrinct","name":"any"}}]},{"id":73,"name":"protocol","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":74,"name":"protocol","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Decorator: Creates a protocol."},"parameters":[{"id":75,"name":"name","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The name of the protocol."},"type":{"type":"instrinct","name":"string"}},{"id":76,"name":"options","kind":32768,"kindString":"Parameter","flags":{"isOptional":true},"comment":{"text":"The validation function or options object used in configuring the protocol.\n"},"type":{"type":"union","types":[{"type":"reflection","declaration":{"id":77,"name":"__type","kind":65536,"kindString":"Type literal","flags":{},"signatures":[{"id":78,"name":"__call","kind":4096,"kindString":"Call signature","flags":{},"parameters":[{"id":79,"name":"target","kind":32768,"kindString":"Parameter","flags":{},"type":{"type":"instrinct","name":"any"}}],"type":{"type":"union","types":[{"type":"instrinct","name":"string"},{"type":"instrinct","name":"boolean"}]}}]}},{"type":"reference","name":"ProtocolOptions","id":38}]}}],"type":{"type":"instrinct","name":"any"}}]}],"groups":[{"title":"Classes","kind":128,"children":[47]},{"title":"Interfaces","kind":256,"children":[29,35,3,38]},{"title":"Variables","kind":32,"children":[61]},{"title":"Functions","kind":64,"children":[62,65,70,73]}]}

@@ -0,1 +1,120 @@

### 1.0.0-beta.1 (2015-11-15)
### 0.10.1 (2015-11-11)
#### Bug Fixes
* **all:** improve TS happiness for decorators ([dd35c4fd](https://github.com/aurelia/metadata/commit/dd35c4fd1ef089764bdbacde8380aa4d47e28d2c))
## 0.10.0 (2015-11-09)
#### Bug Fixes
* **decorators:** remove generics causing the build to fail ([88067ab4](https://github.com/aurelia/metadata/commit/88067ab4d52b9d8d8b8888a78cd92edd5e0f197c))
* **eslintrc:** linting configuration ([86ee6498](https://github.com/aurelia/metadata/commit/86ee6498b26565dac53114d64ab42cab1cbbf44a))
* **protocol:** make decorates work with any object type ([dd64b951](https://github.com/aurelia/metadata/commit/dd64b951f3589573a418ab138046be08ebdc5220))
#### Features
* **all:** new decorators, mixin, protocol and deprecated; new way for ES5/6 to apply decor ([b0c2cd4c](https://github.com/aurelia/metadata/commit/b0c2cd4c018dd5deed22e396cd50b468e633751d))
## 0.9.0 (2015-10-13)
#### Bug Fixes
* **ResourceType:** fix load to return Promise ([a43e8d28](https://github.com/aurelia/metadata/commit/a43e8d28b7c85bcff20119de2b0c384a9853a50e))
* **all:**
* Metadata to metadata Decorators to decorators ([86abaa7b](https://github.com/aurelia/metadata/commit/86abaa7b1c2bcf98681c7ce2eda1686eadd235ae))
* remove System faking and move eachModule helper ([b8c1ce2e](https://github.com/aurelia/metadata/commit/b8c1ce2e3db6c4e54cbe914fe037479c612928db))
* address issue with globals and remove unnecessary Reflect.metadata poly ([93cda3b4](https://github.com/aurelia/metadata/commit/93cda3b401e706b837fc398c1fc106e829e936fe))
* update compiler, fix core-js ref ([b3dd9ea8](https://github.com/aurelia/metadata/commit/b3dd9ea8619f90efbaf9ff2d6617b7d92ad348bb))
* **annotations:**
* remove bad export ([e307aaa8](https://github.com/aurelia/metadata/commit/e307aaa80260b4c674dd6fb577d92be37c297916))
* normalize annotations on the fly ([0c2b6a55](https://github.com/aurelia/metadata/commit/0c2b6a55feb08a6f56605dad245a83ce16172035))
* **annotations spec:** remove bad import ([d949c42d](https://github.com/aurelia/metadata/commit/d949c42d8129829c5168fcf4b861d9e6231af11f))
* **build:**
* update linting, testing and tools ([15c83ea6](https://github.com/aurelia/metadata/commit/15c83ea6414849e0102a5986358d43e9918578a0))
* add missing bower bump ([017aad74](https://github.com/aurelia/metadata/commit/017aad746538ae3f65955e370b57f260946ed01b))
* **metadata:**
* Use correct import for core-js We were previously using `import core from core-j ([d7895cf5](https://github.com/aurelia/metadata/commit/d7895cf54debecce7f281eae33024d74f254815e))
* incorrect types and global references ([88dbfb5e](https://github.com/aurelia/metadata/commit/88dbfb5e5925af9b95f8731f3700bd2e3ec034e6), closes [#16](https://github.com/aurelia/metadata/issues/16), [#17](https://github.com/aurelia/metadata/issues/17))
* mark fake System as such ([c40cfcb8](https://github.com/aurelia/metadata/commit/c40cfcb87c3c788f607d3ff67bf494ca05f5be15))
* store in private map ([52aed24e](https://github.com/aurelia/metadata/commit/52aed24ec5f7f25477cb8021493232c49d67be8b))
* fix initializer for _first property ([740eb07c](https://github.com/aurelia/metadata/commit/740eb07c39b883b1d4e08e5dc779ee9e960a4e07))
* add the locator config back on a configure property ([555612d1](https://github.com/aurelia/metadata/commit/555612d1df56e18c75b2c27bb9c99e0449fefa7e))
* fix safari complaint about variable "locator" ([6e887eac](https://github.com/aurelia/metadata/commit/6e887eac6eb4a7cd74b3b87080c6169d180cfa8e))
* rename configuration helper ([81c73ec1](https://github.com/aurelia/metadata/commit/81c73ec13ceeb6f257d6ae7a6ca91a02ed43ddcf))
* accidental double wrapping of custom location function ([ac11ead8](https://github.com/aurelia/metadata/commit/ac11ead8cdb031c51bf705ea7775108b6f29ddcb))
* **origin:**
* short-circuit module registry search on origin location success ([889e0ce7](https://github.com/aurelia/metadata/commit/889e0ce753d40b320ca803a5e4b16e4716219707))
* never return null for a origin check ([cc25a5e6](https://github.com/aurelia/metadata/commit/cc25a5e6f8e0336cd5817a3460f1921d83969af8))
* **origin.spec:** incorrect test for empty origin data ([14304d56](https://github.com/aurelia/metadata/commit/14304d562eb78c93264052bd1fe21eb74dd69842))
* **package:**
* update aurelia tools and dts generator ([4cba6176](https://github.com/aurelia/metadata/commit/4cba61761b80ad9241a2516c72bee5999abe8986))
* change jspm directories ([2d61d2da](https://github.com/aurelia/metadata/commit/2d61d2dae9b8ce6899afffccd8f93ee0b5de8010))
* **readme:** Now mentions Chrome required to run tests. ([86d9f4c2](https://github.com/aurelia/metadata/commit/86d9f4c29c9a859bb22d981d30707c85761d5a38))
* **test:** correct import sources ([fd5b6f06](https://github.com/aurelia/metadata/commit/fd5b6f0696aa8e735fcf59f633e7b7f75924932f))
#### Features
* **all:**
* update to pal ([6544cec1](https://github.com/aurelia/metadata/commit/6544cec1d8b5d2576ceb53e1d7b5c54718178c88))
* improve d.ts generation and api doc comments ([901f6747](https://github.com/aurelia/metadata/commit/901f6747e6513a6a03b6d9861b63c843d4487f6e))
* improve type info ([1818b0a8](https://github.com/aurelia/metadata/commit/1818b0a8631c32870dc93a7fff53a31e9871cdc7))
* metadata is now based on the ES7 proposal ([32ebe967](https://github.com/aurelia/metadata/commit/32ebe9676b89156cda736ecdf106b92002275ffd))
* new decorator infrastructure ([72a6226e](https://github.com/aurelia/metadata/commit/72a6226e202c28f538f1f6350a130d0d76e23fa9))
* **annotations:** enable deep traversal of inheritance hierarchy ([db07e892](https://github.com/aurelia/metadata/commit/db07e8920ea880ca16f3edc18afc0c99d79360fa))
* **build:**
* d.ts generation and build concat ([e7e24b5b](https://github.com/aurelia/metadata/commit/e7e24b5b0502920c6616219d305134c1e69b4fea))
* update to latest 6to5 and switch to system.register module format ([8d5e644b](https://github.com/aurelia/metadata/commit/8d5e644be29f42f27a0bb2d1e7b0ca63893d1735))
* **docs:** generate api.json from .d.ts file ([8edc2390](https://github.com/aurelia/metadata/commit/8edc2390d55fec7b9538d86d900a921e907b209b))
* **metadata:**
* add a noop property for noop functions ([bcd4fc66](https://github.com/aurelia/metadata/commit/bcd4fc66f49011d55c6635e7025139e139c8867a))
* add firstOrAdd helper ([8ba74b71](https://github.com/aurelia/metadata/commit/8ba74b710f78ddd3f6aa6b059ca54273e91ce960))
* enable adding custom metadata as first metadata method ([705fd865](https://github.com/aurelia/metadata/commit/705fd8650f8d5e20933582cf4d694062cc2e15de), closes [#7](https://github.com/aurelia/metadata/issues/7))
* enhance dsl for configuring added metadata ([8ba28995](https://github.com/aurelia/metadata/commit/8ba2899578cf1353e16f6e695ce93a538153d6bf))
* add a "has" helper to MetadataStorage ([362fcc7b](https://github.com/aurelia/metadata/commit/362fcc7bfe4793cc2b2c296b33d21a5a6a9e99f8))
* new metadata fluent api ([b4c8162f](https://github.com/aurelia/metadata/commit/b4c8162f3428b7aa09db4bd8dd01f6a5505bf7ef))
* re-implement metadata ([ce0304e2](https://github.com/aurelia/metadata/commit/ce0304e2fdc1f2aa69c3146aa9c42a260d868c0e))
* **origin:**
* search module registry for module id if not found ([4abfc246](https://github.com/aurelia/metadata/commit/4abfc2469da4db3d3a077cb733c75e0c364f7068))
* do not alter target object or function with origin data ([cbb8ac3a](https://github.com/aurelia/metadata/commit/cbb8ac3aeb15873232d76a97d1ba97dd8aa63d91))
## 0.8.0 (2015-09-04)
#### Bug Fixes
* **build:** update linting, testing and tools ([15c83ea6](https://github.com/aurelia/metadata/commit/15c83ea6414849e0102a5986358d43e9918578a0))
#### Features
* **all:** improve d.ts generation and api doc comments ([901f6747](https://github.com/aurelia/metadata/commit/901f6747e6513a6a03b6d9861b63c843d4487f6e))
* **metadata:** add a noop property for noop functions ([bcd4fc66](https://github.com/aurelia/metadata/commit/bcd4fc66f49011d55c6635e7025139e139c8867a))
### 0.7.3 (2015-08-14)
#### Bug Fixes
* **metadata:** Use correct import for core-js We were previously using `import core from core-j ([d7895cf5](https://github.com/aurelia/metadata/commit/d7895cf54debecce7f281eae33024d74f254815e))
#### Features
* **all:** improve type info ([1818b0a8](https://github.com/aurelia/metadata/commit/1818b0a8631c32870dc93a7fff53a31e9871cdc7))
* **docs:** generate api.json from .d.ts file ([8edc2390](https://github.com/aurelia/metadata/commit/8edc2390d55fec7b9538d86d900a921e907b209b))
### 0.7.2 (2015-08-04)

@@ -155,2 +274,1 @@

* **annotations:** normalize annotations on the fly ([0c2b6a55](https://github.com/aurelia/metadata/commit/0c2b6a55feb08a6f56605dad245a83ce16172035))

@@ -0,0 +0,0 @@ declare module 'core-js' {

@@ -0,0 +0,0 @@ # What is Metadata?

require('require-dir')('build/tasks');

@@ -0,0 +0,0 @@ // Karma configuration

{
"name": "aurelia-metadata",
"version": "0.7.2",
"version": "1.0.0-beta.1",
"description": "Utilities for reading and writing the metadata of JavaScript functions.",

@@ -21,2 +21,3 @@ "keywords": [

},
"jspmNodeConversion": false,
"jspm": {

@@ -29,3 +30,4 @@ "main": "aurelia-metadata",

"dependencies": {
"core-js": "npm:core-js@^0.9.5"
"aurelia-pal": "npm:aurelia-pal@^1.0.0-beta.1",
"core-js": "npm:core-js@^1.2.6"
},

@@ -35,28 +37,31 @@ "devDependencies": {

"babel-runtime": "npm:babel-runtime@^5.1.13",
"core-js": "npm:core-js@^0.9.5"
"core-js": "npm:core-js@^1.2.6"
}
},
"dependencies": {
"aurelia-pal": "^1.0.0-beta.1",
"core-js": "^1.2.6"
},
"devDependencies": {
"aurelia-tools": "^0.1.6",
"babel-dts-generator": "^0.2.5",
"aurelia-tools": "^0.1.12",
"babel-dts-generator": "^0.2.17",
"babel-eslint": "^4.1.1",
"conventional-changelog": "0.0.11",
"del": "^1.1.0",
"gulp": "^3.8.10",
"gulp-babel": "^5.1.0",
"gulp-babel": "^5.2.1",
"gulp-bump": "^0.3.1",
"gulp-concat": "^2.6.0",
"gulp-eslint": "^1.0.0",
"gulp-insert": "^0.4.0",
"gulp-jshint": "^1.9.0",
"gulp-rename": "^1.2.2",
"gulp-typedoc": "^1.2.1",
"gulp-typedoc-extractor": "0.0.3",
"gulp-yuidoc": "^0.1.2",
"gulp-typedoc-extractor": "0.0.8",
"jasmine-core": "^2.1.3",
"jshint-stylish": "^1.0.0",
"karma": "^0.12.28",
"karma-babel-preprocessor": "^5.2.1",
"karma": "^0.13.15",
"karma-babel-preprocessor": "^5.2.2",
"karma-chrome-launcher": "^0.1.7",
"karma-coverage": "^0.3.1",
"karma-jasmine": "^0.3.2",
"karma-jspm": "^1.1.5",
"karma-jspm": "^2.0.1",
"object.assign": "^1.0.3",

@@ -71,39 +76,6 @@ "require-dir": "^0.1.0",

"aurelia": {
"usedBy": [
"aurelia-binding",
"aurelia-dependency-injection",
"aurelia-framework",
"aurelia-loader-default",
"aurelia-templating",
"aurelia-templating-router"
],
"documentation": {
"links": [
{
"rel": "license",
"mediaType": "text/plain",
"title": "The MIT License (MIT)",
"href": "LICENSE"
},
{
"rel": "describedby",
"mediaType": "application/aurelia-doc+json",
"title": "API",
"href": "doc/api.json"
},
{
"rel": "version-history",
"mediaType": "text/markdown",
"title": "Change Log",
"href": "doc/CHANGELOG.md"
},
{
"rel": "about",
"mediaType": "text/markdown",
"title": "What is Metadata?",
"href": "doc/what-is-metadata.md"
}
]
"articles": []
}
}
}

@@ -0,0 +0,0 @@ # aurelia-metadata

@@ -1,26 +0,46 @@

import {DecoratorApplicator} from './decorator-applicator';
/**
* An object capable of applying it's captured decorators to a target.
*/
interface DecoratorApplicator {
/**
* Applies the decorators to the target.
* @param target The target.
* @param key If applying to a method, the member name.
* @param key If applying to a method, you may supply an initial descriptor to pass to the decorators.
*/
on(target: any, key?: string, descriptor?: Object): any;
}
export var Decorators = {
configure: {
parameterizedDecorator(name:string, decorator:Function){
Decorators[name] = function(){
var applicator = new DecoratorApplicator();
return applicator[name].apply(applicator, arguments);
};
/**
* Enables applying decorators, particularly for use when there is no syntax support in the language, such as with ES5 and ES2016.
* @param rest The decorators to apply.
*/
export function decorators(...rest: Function[]): DecoratorApplicator {
let applicator = function(target, key, descriptor) {
let i = rest.length;
DecoratorApplicator.prototype[name] = function(){
var result = decorator.apply(null, arguments);
return this.decorator(result);
if (key) {
descriptor = descriptor || {
value: target[key],
writable: true,
configurable: true,
enumerable: true
};
},
simpleDecorator(name:string, decorator:Function){
Decorators[name] = function(){
return new DecoratorApplicator().decorator(decorator);
};
DecoratorApplicator.prototype[name] = function(){
return this.decorator(decorator);
while (i--) {
descriptor = rest[i](target, key, descriptor) || descriptor;
}
Object.defineProperty(target, key, descriptor);
} else {
while (i--) {
target = rest[i](target) || target;
}
}
}
return target;
};
applicator.on = applicator;
return applicator;
}

@@ -1,33 +0,13 @@

const theGlobal = (function() {
// Workers don’t have `window`, only `self`
if (typeof self !== 'undefined') {
return self;
}
import {PLATFORM} from 'aurelia-pal';
if (typeof global !== 'undefined') {
return global;
}
// Not all environments allow eval and Function
// Use only as a last resort:
return new Function('return this')();
})();
const theGlobal = PLATFORM.global;
const emptyMetadata = Object.freeze({});
const metadataContainerKey = '__metadata__';
if(typeof theGlobal.System === 'undefined'){
theGlobal.System = { isFake:true };
}
if(typeof theGlobal.System.forEachModule === 'undefined'){
theGlobal.System.forEachModule = function(){};
}
if(typeof theGlobal.Reflect === 'undefined'){
if (typeof theGlobal.Reflect === 'undefined') {
theGlobal.Reflect = {};
}
if(typeof theGlobal.Reflect.getOwnMetadata === 'undefined'){
Reflect.getOwnMetadata = function(metadataKey, target, targetKey){
if (typeof theGlobal.Reflect.getOwnMetadata === 'undefined') {
Reflect.getOwnMetadata = function(metadataKey, target, targetKey) {
return ((target[metadataContainerKey] || emptyMetadata)[targetKey] || emptyMetadata)[metadataKey];

@@ -37,6 +17,6 @@ };

if(typeof theGlobal.Reflect.defineMetadata === 'undefined'){
Reflect.defineMetadata = function(metadataKey, metadataValue, target, targetKey){
var metadataContainer = target[metadataContainerKey] || (target[metadataContainerKey] = {});
var targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {});
if (typeof theGlobal.Reflect.defineMetadata === 'undefined') {
Reflect.defineMetadata = function(metadataKey, metadataValue, target, targetKey) {
let metadataContainer = target.hasOwnProperty(metadataContainerKey) ? target[metadataContainerKey] : (target[metadataContainerKey] = {});
let targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {});
targetContainer[metadataKey] = metadataValue;

@@ -46,5 +26,5 @@ };

if(typeof theGlobal.Reflect.metadata === 'undefined'){
Reflect.metadata = function(metadataKey, metadataValue){
return function(target, targetKey){
if (typeof theGlobal.Reflect.metadata === 'undefined') {
Reflect.metadata = function(metadataKey, metadataValue) {
return function(target, targetKey) {
Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey);

@@ -55,17 +35,47 @@ };

function ensureDecorators(target){
var applicator;
if(typeof target.decorators === 'function'){
applicator = target.decorators();
}else{
applicator = target.decorators;
}
if(typeof applicator._decorate === 'function'){
delete target.decorators;
applicator._decorate(target);
}else{
throw new Error('The return value of your decorator\'s method was not valid.');
}
/**
* Helpers for working with metadata on functions.
*/
interface MetadataType {
/**
* The metadata key representing pluggable resources.
*/
resource: string;
/**
* The metadata key representing parameter type information.
*/
paramTypes: string;
/**
* The metadata key representing property information.
*/
properties: string;
/**
* Gets metadata specified by a key on a target, searching up the inheritance hierarchy.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
get(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Gets metadata specified by a key on a target, only searching the own instance.
* @param metadataKey The key for the metadata to lookup.
* @param target The target to lookup the metadata on.
* @param targetKey The member on the target to lookup the metadata on.
*/
getOwn(metadataKey: string, target: Function, targetKey: string): Object;
/**
* Defines metadata specified by a key on a target.
* @param metadataKey The key for the metadata to define.
* @param target The target to set the metadata on.
* @param targetKey The member on the target to set the metadata on.
*/
define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void;
/**
* Gets metadata specified by a key on a target, or creates an instance of the specified metadata if not found.
* @param metadataKey The key for the metadata to lookup or create.
* @param Type The type of metadata to create if existing metadata is not found.
* @param target The target to lookup or create the metadata on.
* @param targetKey The member on the target to lookup or create the metadata on.
*/
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object;
}

@@ -75,37 +85,23 @@

* Provides helpers for working with metadata.
*
* @class Metadata
* @static
*/
export var Metadata = {
global: theGlobal,
resource:'aurelia:resource',
paramTypes:'design:paramtypes',
properties:'design:properties',
get(metadataKey:string, target:Function, targetKey:string){
if(!target){
return undefined;
}
let result = Metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? Metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
export const metadata: MetadataType = {
resource: 'aurelia:resource',
paramTypes: 'design:paramtypes',
properties: 'design:properties',
get(metadataKey: string, target: Function, targetKey: string): Object {
if (!target) { return undefined; }
let result = metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
},
getOwn(metadataKey:string, target:Function, targetKey:string){
if(!target){
return undefined;
}
if(target.hasOwnProperty('decorators')){
ensureDecorators(target);
}
getOwn(metadataKey: string, target: Function, targetKey: string): Object {
if (!target) { return undefined; }
return Reflect.getOwnMetadata(metadataKey, target, targetKey);
},
define(metadataKey:string, metadataValue:string, target:Function, targetKey:string){
define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void {
Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey);
},
getOrCreateOwn(metadataKey:string, Type:Function, target:Function, targetKey:string){
let result = Metadata.getOwn(metadataKey, target, targetKey);
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object {
let result = metadata.getOwn(metadataKey, target, targetKey);
if(result === undefined){
if (result === undefined) {
result = new Type();

@@ -117,2 +113,2 @@ Reflect.defineMetadata(metadataKey, result, target, targetKey);

}
}
};

@@ -1,16 +0,26 @@

import core from 'core-js';
import 'core-js';
import {PLATFORM} from 'aurelia-pal';
var originStorage = new Map(),
unknownOrigin = Object.freeze({moduleId:undefined,moduleMember:undefined});
const originStorage = new Map();
const unknownOrigin = Object.freeze({moduleId: undefined, moduleMember: undefined});
/**
* A metadata annotation that describes the origin module of the function to which it's attached.
*
* @class Origin
* @constructor
* @param {string} moduleId The origin module id.
* @param {string} moduleMember The name of the export in the origin module.
*/
export class Origin {
constructor(moduleId:string, moduleMember:string){
/**
* The id of the module from which the item originated.
*/
moduleId: string;
/**
* The member name of the export on the module object from which the item originated.
*/
moduleMember: string;
/**
* Creates an instance of Origin metadata.
* @param moduleId The id of the module from which the item originated.
* @param moduleMember The member name of the export on the module object from which the item originated.
*/
constructor(moduleId: string, moduleMember: string) {
this.moduleId = moduleId;

@@ -21,17 +31,14 @@ this.moduleMember = moduleMember;

/**
* Get the Origin annotation for the specified function.
*
* @method get
* @static
* @param {Function} fn The function to inspect for Origin metadata.
* @return {Origin} Returns the Origin metadata.
* Get the Origin metadata for the specified function.
* @param fn The function to inspect for Origin metadata.
* @return Returns the Origin metadata.
*/
static get(fn:Function){
var origin = originStorage.get(fn);
static get(fn: Function): Origin {
let origin = originStorage.get(fn);
if(origin === undefined){
System.forEachModule((key, value) => {
for(var name in value){
var exp = value[name];
if(exp === fn){
if (origin === undefined) {
PLATFORM.eachModule((key, value) => {
for (let name in value) {
let exp = value[name];
if (exp === fn) {
originStorage.set(fn, origin = new Origin(key, name));

@@ -42,3 +49,3 @@ return true;

if(value === fn){
if (value === fn) {
originStorage.set(fn, origin = new Origin(key, 'default'));

@@ -54,13 +61,10 @@ return true;

/**
* Set the Origin annotation for the specified function.
*
* @method set
* @static
* @param {Function} fn The function to set the Origin metadata on.
* @param {origin} fn The Origin metadata to store on the function.
* @return {Origin} Returns the Origin metadata.
* Set the Origin metadata for the specified function.
* @param fn The function to set the Origin metadata on.
* @param fn The Origin metadata to store on the function.
* @return Returns the Origin metadata.
*/
static set(fn:Function, origin:Origin){
static set(fn: Function, origin: Origin): void {
originStorage.set(fn, origin);
}
}

@@ -1,7 +0,7 @@

import {Metadata} from '../src/metadata';
import {Decorators} from '../src/decorators';
import {metadata} from '../src/metadata';
import {decorators} from '../src/decorators';
describe('metadata', () => {
it('can be located by key', () => {
var found = Metadata.getOwn(Metadata.resource, HasMetadata);
var found = metadata.getOwn(metadata.resource, HasMetadata);
expect(found instanceof SampleMetadata).toBe(true);

@@ -11,3 +11,3 @@ });

it('can be normalized to handle the fallback metadata location', () => {
var found = Metadata.getOwn(Metadata.resource, HasFallbackMetadata);
var found = metadata.getOwn(metadata.resource, HasFallbackMetadata);
expect(found instanceof SampleMetadata).toBe(true);

@@ -17,3 +17,3 @@ });

it('can override base metadata', () => {
var found = Metadata.getOwn(Metadata.resource, OverridesMetadata);
var found = metadata.getOwn(metadata.resource, OverridesMetadata);
expect(found.id).toBe(3);

@@ -23,3 +23,3 @@ });

it('can inherit base metadata when searching deep by type', () => {
var found = Metadata.get(Metadata.resource, DerivedWithBaseMetadata);
var found = metadata.get(metadata.resource, DerivedWithBaseMetadata);
expect(found instanceof SampleMetadata).toBe(true);

@@ -31,7 +31,5 @@ });

Annotated.decorators = () => {
return Decorators.sample();
};
decorators(new sampleES7Decorator()).on(Annotated);
var found = Metadata.getOwn(Metadata.resource, Annotated);
var found = metadata.getOwn(metadata.resource, Annotated);
expect(found instanceof SampleMetadata).toBe(true);

@@ -42,8 +40,8 @@ });

it('returns undefined if the input type is falsy', () => {
expect(Metadata.getOwn(Metadata.resource, undefined)).toBe(undefined);
expect(Metadata.getOwn(Metadata.resource, null)).toBe(undefined);
expect(metadata.getOwn(metadata.resource, undefined)).toBe(undefined);
expect(metadata.getOwn(metadata.resource, null)).toBe(undefined);
});
it('returns undefined if no metadata is defined for the type', () => {
var found = Metadata.getOwn(Metadata.resource, HasNoMetadata);
var found = metadata.getOwn(metadata.resource, HasNoMetadata);
expect(found).toBe(undefined);

@@ -53,3 +51,3 @@ });

it('retruns the base metadata when serching deep if no metadata is defined for the type', () => {
var found = Metadata.get(Metadata.resource, DerivedWithBaseMetadata);
var found = metadata.get(metadata.resource, DerivedWithBaseMetadata);
expect(found instanceof SampleMetadata).toBe(true);

@@ -59,10 +57,2 @@ });

function sampleES7Decorator(value){
return function(target){
Metadata.define(Metadata.resource, new SampleMetadata(value), target);
}
}
Decorators.configure.parameterizedDecorator('sample', sampleES7Decorator);
class SampleMetadata {

@@ -74,23 +64,18 @@ constructor(id) {

class HasMetadata {}
HasMetadata.decorators = Decorators.sample();
class HasFallbackMetadata {
static decorators() {
return Decorators.sample();
function sampleES7Decorator(value){
return function(target){
metadata.define(metadata.resource, new SampleMetadata(value), target);
}
}
class HasOneMetadataInstance {}
HasOneMetadataInstance.decorators = Decorators.sample();
let HasMetadata = decorators(sampleES7Decorator()).on(class {});
let HasFallbackMetadata = decorators(sampleES7Decorator()).on(class {});
let HasOneMetadataInstance = decorators(sampleES7Decorator()).on(class {});
let OverridesMetadata = decorators(sampleES7Decorator(3)).on(class extends HasMetadata {});
class OverridesMetadata extends HasMetadata {}
OverridesMetadata.decorators = Decorators.sample(3);
class DerivedWithBaseMetadata extends HasMetadata {}
Metadata.define('another', 'foo', DerivedWithBaseMetadata);
metadata.define('another', 'foo', DerivedWithBaseMetadata);
class HasNoMetadata {}
class DerivedTypeWithNoMetadata extends HasMetadata {}
});

@@ -0,0 +0,0 @@ import {Origin} from '../src/origin';

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