├── .circleci └── config.yml ├── .editorconfig ├── .eslintrc.js ├── .gitignore ├── .npmignore ├── ACKNOWLEDGEMENTS.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── LICENSE ├── README.md ├── bower.json ├── config.js ├── dist ├── amd │ ├── aurelia-metadata.js │ └── index.js ├── aurelia-metadata.js ├── commonjs │ ├── aurelia-metadata.js │ └── index.js ├── es2015 │ ├── aurelia-metadata.js │ └── index.js ├── native-modules │ ├── aurelia-metadata.js │ └── index.js ├── system │ ├── aurelia-metadata.js │ └── index.js └── types │ ├── aurelia-metadata.d.ts │ └── index.d.ts ├── doc ├── CHANGELOG.md └── api.json ├── gulpfile.js ├── karma.conf.js ├── package-lock.json ├── package.json ├── rollup.config.js ├── src ├── decorators.ts ├── deprecated.ts ├── index.ts ├── metadata.ts ├── mixin.ts ├── origin.ts └── protocol.ts ├── test ├── metadata.spec.ts ├── mixin.spec.ts ├── origin.spec.ts └── setup.ts ├── tsconfig.json └── typings.json /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | map-1: &filter_only_develop 4 | filters: 5 | branches: 6 | only: develop 7 | 8 | map-2: &filter_only_tag 9 | filters: 10 | branches: 11 | ignore: /.*/ 12 | tags: 13 | only: /^v?[0-9]+(\.[0-9]+)*$/ 14 | 15 | orbs: 16 | v1: aurelia/v1@volatile 17 | 18 | workflows: 19 | main: 20 | jobs: 21 | - v1/build_test: 22 | use_jspm: false 23 | - v1/build_merge: 24 | <<: *filter_only_develop 25 | use_jspm: false 26 | requires: 27 | - v1/build_test 28 | - v1/npm_publish: 29 | <<: *filter_only_tag 30 | name: npm_publish_dry 31 | args: "--dry-run" 32 | - request_publish_latest: 33 | <<: *filter_only_tag 34 | type: approval 35 | requires: 36 | - npm_publish_dry 37 | - v1/npm_publish: 38 | <<: *filter_only_tag 39 | name: npm_publish 40 | context: Aurelia 41 | requires: 42 | - request_publish_latest 43 | - v1/merge_back: 44 | <<: *filter_only_tag 45 | requires: 46 | - npm_publish 47 | 48 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # 2 space indentation 12 | [**.*] 13 | indent_style = space 14 | indent_size = 2 -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | /**@type {import('eslint').CLIEngine.Options} */ 2 | module.exports = { 3 | root: true, 4 | parser: '@typescript-eslint/parser', 5 | plugins: [ 6 | '@typescript-eslint', 7 | ], 8 | extends: [ 9 | 'eslint:recommended', 10 | 'plugin:@typescript-eslint/recommended', 11 | ], 12 | rules: { 13 | "prefer-rest-params": 0, 14 | "@typescript-eslint/ban-types": 0, 15 | "@typescript-eslint/no-explicit-any": 0, 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | jspm_packages 3 | bower_components 4 | .idea 5 | .DS_STORE 6 | *.swp 7 | build/reports 8 | coverage 9 | .npmrc 10 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | jspm_packages 2 | bower_components 3 | .idea 4 | build/reports 5 | -------------------------------------------------------------------------------- /ACKNOWLEDGEMENTS.md: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | 3 | The `reflect-metadata` is adapted from the polyfill for the proposed ES7 metadata api. The original polyfill can be found [here](https://github.com/rbuckton/ReflectDecorators) and the original license is included below. 4 | 5 | --- 6 | 7 | Apache License 8 | Version 2.0, January 2004 9 | http://www.apache.org/licenses/ 10 | 11 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 12 | 13 | 1. Definitions. 14 | 15 | "License" shall mean the terms and conditions for use, reproduction, 16 | and distribution as defined by Sections 1 through 9 of this document. 17 | 18 | "Licensor" shall mean the copyright owner or entity authorized by 19 | the copyright owner that is granting the License. 20 | 21 | "Legal Entity" shall mean the union of the acting entity and all 22 | other entities that control, are controlled by, or are under common 23 | control with that entity. For the purposes of this definition, 24 | "control" means (i) the power, direct or indirect, to cause the 25 | direction or management of such entity, whether by contract or 26 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 27 | outstanding shares, or (iii) beneficial ownership of such entity. 28 | 29 | "You" (or "Your") shall mean an individual or Legal Entity 30 | exercising permissions granted by this License. 31 | 32 | "Source" form shall mean the preferred form for making modifications, 33 | including but not limited to software source code, documentation 34 | source, and configuration files. 35 | 36 | "Object" form shall mean any form resulting from mechanical 37 | transformation or translation of a Source form, including but 38 | not limited to compiled object code, generated documentation, 39 | and conversions to other media types. 40 | 41 | "Work" shall mean the work of authorship, whether in Source or 42 | Object form, made available under the License, as indicated by a 43 | copyright notice that is included in or attached to the work 44 | (an example is provided in the Appendix below). 45 | 46 | "Derivative Works" shall mean any work, whether in Source or Object 47 | form, that is based on (or derived from) the Work and for which the 48 | editorial revisions, annotations, elaborations, or other modifications 49 | represent, as a whole, an original work of authorship. For the purposes 50 | of this License, Derivative Works shall not include works that remain 51 | separable from, or merely link (or bind by name) to the interfaces of, 52 | the Work and Derivative Works thereof. 53 | 54 | "Contribution" shall mean any work of authorship, including 55 | the original version of the Work and any modifications or additions 56 | to that Work or Derivative Works thereof, that is intentionally 57 | submitted to Licensor for inclusion in the Work by the copyright owner 58 | or by an individual or Legal Entity authorized to submit on behalf of 59 | the copyright owner. For the purposes of this definition, "submitted" 60 | means any form of electronic, verbal, or written communication sent 61 | to the Licensor or its representatives, including but not limited to 62 | communication on electronic mailing lists, source code control systems, 63 | and issue tracking systems that are managed by, or on behalf of, the 64 | Licensor for the purpose of discussing and improving the Work, but 65 | excluding communication that is conspicuously marked or otherwise 66 | designated in writing by the copyright owner as "Not a Contribution." 67 | 68 | "Contributor" shall mean Licensor and any individual or Legal Entity 69 | on behalf of whom a Contribution has been received by Licensor and 70 | subsequently incorporated within the Work. 71 | 72 | 2. Grant of Copyright License. Subject to the terms and conditions of 73 | this License, each Contributor hereby grants to You a perpetual, 74 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 75 | copyright license to reproduce, prepare Derivative Works of, 76 | publicly display, publicly perform, sublicense, and distribute the 77 | Work and such Derivative Works in Source or Object form. 78 | 79 | 3. Grant of Patent License. Subject to the terms and conditions of 80 | this License, each Contributor hereby grants to You a perpetual, 81 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 82 | (except as stated in this section) patent license to make, have made, 83 | use, offer to sell, sell, import, and otherwise transfer the Work, 84 | where such license applies only to those patent claims licensable 85 | by such Contributor that are necessarily infringed by their 86 | Contribution(s) alone or by combination of their Contribution(s) 87 | with the Work to which such Contribution(s) was submitted. If You 88 | institute patent litigation against any entity (including a 89 | cross-claim or counterclaim in a lawsuit) alleging that the Work 90 | or a Contribution incorporated within the Work constitutes direct 91 | or contributory patent infringement, then any patent licenses 92 | granted to You under this License for that Work shall terminate 93 | as of the date such litigation is filed. 94 | 95 | 4. Redistribution. You may reproduce and distribute copies of the 96 | Work or Derivative Works thereof in any medium, with or without 97 | modifications, and in Source or Object form, provided that You 98 | meet the following conditions: 99 | 100 | (a) You must give any other recipients of the Work or 101 | Derivative Works a copy of this License; and 102 | 103 | (b) You must cause any modified files to carry prominent notices 104 | stating that You changed the files; and 105 | 106 | (c) You must retain, in the Source form of any Derivative Works 107 | that You distribute, all copyright, patent, trademark, and 108 | attribution notices from the Source form of the Work, 109 | excluding those notices that do not pertain to any part of 110 | the Derivative Works; and 111 | 112 | (d) If the Work includes a "NOTICE" text file as part of its 113 | distribution, then any Derivative Works that You distribute must 114 | include a readable copy of the attribution notices contained 115 | within such NOTICE file, excluding those notices that do not 116 | pertain to any part of the Derivative Works, in at least one 117 | of the following places: within a NOTICE text file distributed 118 | as part of the Derivative Works; within the Source form or 119 | documentation, if provided along with the Derivative Works; or, 120 | within a display generated by the Derivative Works, if and 121 | wherever such third-party notices normally appear. The contents 122 | of the NOTICE file are for informational purposes only and 123 | do not modify the License. You may add Your own attribution 124 | notices within Derivative Works that You distribute, alongside 125 | or as an addendum to the NOTICE text from the Work, provided 126 | that such additional attribution notices cannot be construed 127 | as modifying the License. 128 | 129 | You may add Your own copyright statement to Your modifications and 130 | may provide additional or different license terms and conditions 131 | for use, reproduction, or distribution of Your modifications, or 132 | for any such Derivative Works as a whole, provided Your use, 133 | reproduction, and distribution of the Work otherwise complies with 134 | the conditions stated in this License. 135 | 136 | 5. Submission of Contributions. Unless You explicitly state otherwise, 137 | any Contribution intentionally submitted for inclusion in the Work 138 | by You to the Licensor shall be under the terms and conditions of 139 | this License, without any additional terms or conditions. 140 | Notwithstanding the above, nothing herein shall supersede or modify 141 | the terms of any separate license agreement you may have executed 142 | with Licensor regarding such Contributions. 143 | 144 | 6. Trademarks. This License does not grant permission to use the trade 145 | names, trademarks, service marks, or product names of the Licensor, 146 | except as required for reasonable and customary use in describing the 147 | origin of the Work and reproducing the content of the NOTICE file. 148 | 149 | 7. Disclaimer of Warranty. Unless required by applicable law or 150 | agreed to in writing, Licensor provides the Work (and each 151 | Contributor provides its Contributions) on an "AS IS" BASIS, 152 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 153 | implied, including, without limitation, any warranties or conditions 154 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 155 | PARTICULAR PURPOSE. You are solely responsible for determining the 156 | appropriateness of using or redistributing the Work and assume any 157 | risks associated with Your exercise of permissions under this License. 158 | 159 | 8. Limitation of Liability. In no event and under no legal theory, 160 | whether in tort (including negligence), contract, or otherwise, 161 | unless required by applicable law (such as deliberate and grossly 162 | negligent acts) or agreed to in writing, shall any Contributor be 163 | liable to You for damages, including any direct, indirect, special, 164 | incidental, or consequential damages of any character arising as a 165 | result of this License or out of the use or inability to use the 166 | Work (including but not limited to damages for loss of goodwill, 167 | work stoppage, computer failure or malfunction, or any and all 168 | other commercial damages or losses), even if such Contributor 169 | has been advised of the possibility of such damages. 170 | 171 | 9. Accepting Warranty or Additional Liability. While redistributing 172 | the Work or Derivative Works thereof, You may choose to offer, 173 | and charge a fee for, acceptance of support, warranty, indemnity, 174 | or other liability obligations and/or rights consistent with this 175 | License. However, in accepting such obligations, You may act only 176 | on Your own behalf and on Your sole responsibility, not on behalf 177 | of any other Contributor, and only if You agree to indemnify, 178 | defend, and hold each Contributor harmless for any liability 179 | incurred by, or claims asserted against, such Contributor by reason 180 | of your accepting any such warranty or additional liability. 181 | 182 | END OF TERMS AND CONDITIONS 183 | 184 | APPENDIX: How to apply the Apache License to your work. 185 | 186 | To apply the Apache License to your work, attach the following 187 | boilerplate notice, with the fields enclosed by brackets "{}" 188 | replaced with your own identifying information. (Don't include 189 | the brackets!) The text should be enclosed in the appropriate 190 | comment syntax for the file format. We also recommend that a 191 | file or class name and description of purpose be included on the 192 | same "printed page" as the copyright notice for easier 193 | identification within third-party archives. 194 | 195 | Copyright {yyyy} {name of copyright owner} 196 | 197 | Licensed under the Apache License, Version 2.0 (the "License"); 198 | you may not use this file except in compliance with the License. 199 | You may obtain a copy of the License at 200 | 201 | http://www.apache.org/licenses/LICENSE-2.0 202 | 203 | Unless required by applicable law or agreed to in writing, software 204 | distributed under the License is distributed on an "AS IS" BASIS, 205 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 206 | See the License for the specific language governing permissions and 207 | limitations under the License. 208 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | 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). 4 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 19 | **I'm submitting a bug report** 20 | **I'm submitting a feature request** 21 | 22 | * **Library Version:** 23 | major.minor.patch-pre 24 | 25 | 26 | **Please tell us about your environment:** 27 | * **Operating System:** 28 | OSX 10.x|Linux (distro)|Windows [7|8|8.1|10] 29 | 30 | * **Node Version:** 31 | 6.2.0 32 | 36 | 37 | * **NPM Version:** 38 | 3.8.9 39 | 43 | 44 | * **JSPM OR Webpack AND Version** 45 | JSPM 0.16.32 | webpack 2.1.0-beta.17 46 | 52 | 53 | * **Browser:** 54 | all | Chrome XX | Firefox XX | Edge XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView 55 | 56 | * **Language:** 57 | all | TypeScript X.X | ESNext 58 | 59 | 60 | **Current behavior:** 61 | 62 | 63 | **Expected/desired behavior:** 64 | 71 | 72 | 73 | * **What is the expected behavior?** 74 | 75 | 76 | * **What is the motivation / use case for changing the behavior?** 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2010 - 2018 Blue Spire Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Aurelia 4 | 5 |

6 | 7 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 8 | [![npm Version](https://img.shields.io/npm/v/aurelia-metadata.svg)](https://www.npmjs.com/package/aurelia-metadata) 9 | [![Discourse status](https://img.shields.io/discourse/https/meta.discourse.org/status.svg)](https://discourse.aurelia.io) 10 | [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/) 11 | [![Twitter](https://img.shields.io/twitter/follow/aureliaeffect.svg?style=social&label=Follow)](https://twitter.com/intent/follow?screen_name=aureliaeffect) 12 | 13 | [![Backers on Open Collective](https://opencollective.com/aurelia/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/aurelia/sponsors/badge.svg)](#sponsors) 14 | [![Discord Chat](https://img.shields.io/discord/448698263508615178.svg)](https://discord.gg/RBtyM6u) 15 | 16 | # aurelia-metadata 17 | 18 | This library is part of the [Aurelia](http://www.aurelia.io/) platform and contains utilities for reading and writing the metadata of JavaScript functions. It provides a consistent way of accessing type, annotation and origin metadata across a number of languages and formats. This library supports TypeScript metadata and contains helper functions that understand several simple, alternate locations and formats for metadata which are more easily leveraged by developers authoring code in plain ES6 or ES5. 19 | 20 | > To keep up to date on [Aurelia](http://www.aurelia.io/), please visit and subscribe to [the official blog](http://blog.aurelia.io/) and [our email list](http://eepurl.com/ces50j). We also invite you to [follow us on twitter](https://twitter.com/aureliaeffect). If you have questions, please [join our community on Gitter](https://gitter.im/aurelia/discuss) or use [stack overflow](http://stackoverflow.com/search?q=aurelia). Documentation can be found [in our developer hub](http://aurelia.io/hub.html). 21 | 22 | ## Platform Support 23 | 24 | This library can be used in the **browser** as well as on the **server**. 25 | 26 | ## Building The Code 27 | 28 | To build the code, follow these steps. 29 | 30 | 1. Ensure that [NodeJS](http://nodejs.org/) version 12+ is installed. This provides the platform on which the build tooling runs. 31 | 2. From the project folder, execute the following command: 32 | 33 | ```shell 34 | npm ci 35 | ``` 36 | 3. To build the code, you can now run: 37 | 38 | ```shell 39 | npm run build 40 | ``` 41 | 5. You will find the compiled code in the `dist` folder, available in three module formats: AMD, CommonJS and ES6. 42 | 43 | 6. See `gulpfile.js`, or `package.json` (`scripts` section) for other tasks related to generating the docs and linting. 44 | 45 | ## Running The Tests 46 | 47 | To run the unit tests, first ensure that you have followed the steps above in order to install all dependencies and successfully build the library. Once you have done that, proceed with these additional steps: 48 | 49 | 1. You can now run the tests with this command: 50 | 51 | ```shell 52 | npm run test 53 | ``` 54 | 55 | If you want to run the test in watch mode, you can run this command: 56 | 57 | ```shell 58 | npm run test:watch 59 | ``` 60 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aurelia-metadata", 3 | "version": "1.0.8", 4 | "description": "Utilities for reading and writing the metadata of JavaScript functions.", 5 | "keywords": [ 6 | "aurelia", 7 | "metadata", 8 | "annotations" 9 | ], 10 | "homepage": "http://aurelia.io", 11 | "main": "dist/commonjs/aurelia-metadata.js", 12 | "moduleType": "node", 13 | "license": "MIT", 14 | "authors": [ 15 | "Rob Eisenberg (http://robeisenberg.com/)" 16 | ], 17 | "repository": { 18 | "type": "git", 19 | "url": "https://github.com/aurelia/metadata" 20 | }, 21 | "dependencies": { 22 | "aurelia-pal": "^1.0.0" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | System.config({ 2 | defaultJSExtensions: true, 3 | transpiler: "babel", 4 | babelOptions: { 5 | "optional": [ 6 | "runtime", 7 | "optimisation.modules.system" 8 | ] 9 | }, 10 | paths: { 11 | "github:*": "jspm_packages/github/*", 12 | "npm:*": "jspm_packages/npm/*" 13 | }, 14 | 15 | map: { 16 | "aurelia-pal": "npm:aurelia-pal@1.0.0", 17 | "aurelia-polyfills": "npm:aurelia-polyfills@0.1.2", 18 | "babel": "npm:babel-core@5.8.38", 19 | "babel-runtime": "npm:babel-runtime@5.8.38", 20 | "core-js": "npm:core-js@2.4.1", 21 | "github:jspm/nodelibs-assert@0.1.0": { 22 | "assert": "npm:assert@1.4.1" 23 | }, 24 | "github:jspm/nodelibs-buffer@0.1.0": { 25 | "buffer": "npm:buffer@3.6.0" 26 | }, 27 | "github:jspm/nodelibs-path@0.1.0": { 28 | "path-browserify": "npm:path-browserify@0.0.0" 29 | }, 30 | "github:jspm/nodelibs-process@0.1.2": { 31 | "process": "npm:process@0.11.6" 32 | }, 33 | "github:jspm/nodelibs-util@0.1.0": { 34 | "util": "npm:util@0.10.3" 35 | }, 36 | "github:jspm/nodelibs-vm@0.1.0": { 37 | "vm-browserify": "npm:vm-browserify@0.0.4" 38 | }, 39 | "npm:assert@1.4.1": { 40 | "assert": "github:jspm/nodelibs-assert@0.1.0", 41 | "buffer": "github:jspm/nodelibs-buffer@0.1.0", 42 | "process": "github:jspm/nodelibs-process@0.1.2", 43 | "util": "npm:util@0.10.3" 44 | }, 45 | "npm:aurelia-polyfills@0.1.2": { 46 | "aurelia-pal": "npm:aurelia-pal@1.0.0" 47 | }, 48 | "npm:babel-runtime@5.8.38": { 49 | "process": "github:jspm/nodelibs-process@0.1.2" 50 | }, 51 | "npm:buffer@3.6.0": { 52 | "base64-js": "npm:base64-js@0.0.8", 53 | "child_process": "github:jspm/nodelibs-child_process@0.1.0", 54 | "fs": "github:jspm/nodelibs-fs@0.1.2", 55 | "ieee754": "npm:ieee754@1.1.6", 56 | "isarray": "npm:isarray@1.0.0", 57 | "process": "github:jspm/nodelibs-process@0.1.2" 58 | }, 59 | "npm:core-js@2.4.1": { 60 | "fs": "github:jspm/nodelibs-fs@0.1.2", 61 | "path": "github:jspm/nodelibs-path@0.1.0", 62 | "process": "github:jspm/nodelibs-process@0.1.2", 63 | "systemjs-json": "github:systemjs/plugin-json@0.1.2" 64 | }, 65 | "npm:inherits@2.0.1": { 66 | "util": "github:jspm/nodelibs-util@0.1.0" 67 | }, 68 | "npm:path-browserify@0.0.0": { 69 | "process": "github:jspm/nodelibs-process@0.1.2" 70 | }, 71 | "npm:process@0.11.6": { 72 | "assert": "github:jspm/nodelibs-assert@0.1.0", 73 | "fs": "github:jspm/nodelibs-fs@0.1.2", 74 | "vm": "github:jspm/nodelibs-vm@0.1.0" 75 | }, 76 | "npm:util@0.10.3": { 77 | "inherits": "npm:inherits@2.0.1", 78 | "process": "github:jspm/nodelibs-process@0.1.2" 79 | }, 80 | "npm:vm-browserify@0.0.4": { 81 | "indexof": "npm:indexof@0.0.1" 82 | } 83 | } 84 | }); 85 | -------------------------------------------------------------------------------- /dist/amd/aurelia-metadata.js: -------------------------------------------------------------------------------- 1 | define(['exports', 'aurelia-pal'], function (exports, _aureliaPal) { 2 | 'use strict'; 3 | 4 | Object.defineProperty(exports, "__esModule", { 5 | value: true 6 | }); 7 | exports.Origin = exports.metadata = undefined; 8 | exports.decorators = decorators; 9 | exports.deprecated = deprecated; 10 | exports.mixin = mixin; 11 | exports.protocol = protocol; 12 | 13 | var _extends = Object.assign || function (target) { 14 | for (var i = 1; i < arguments.length; i++) { 15 | var source = arguments[i]; 16 | 17 | for (var key in source) { 18 | if (Object.prototype.hasOwnProperty.call(source, key)) { 19 | target[key] = source[key]; 20 | } 21 | } 22 | } 23 | 24 | return target; 25 | }; 26 | 27 | 28 | 29 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { 30 | return typeof obj; 31 | } : function (obj) { 32 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; 33 | }; 34 | 35 | function isObject(val) { 36 | return val && (typeof val === 'function' || (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object'); 37 | } 38 | 39 | var metadata = exports.metadata = { 40 | resource: 'aurelia:resource', 41 | paramTypes: 'design:paramtypes', 42 | propertyType: 'design:type', 43 | properties: 'design:properties', 44 | get: function get(metadataKey, target, targetKey) { 45 | if (!isObject(target)) { 46 | return undefined; 47 | } 48 | var result = metadata.getOwn(metadataKey, target, targetKey); 49 | return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result; 50 | }, 51 | getOwn: function getOwn(metadataKey, target, targetKey) { 52 | if (!isObject(target)) { 53 | return undefined; 54 | } 55 | return Reflect.getOwnMetadata(metadataKey, target, targetKey); 56 | }, 57 | define: function define(metadataKey, metadataValue, target, targetKey) { 58 | Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey); 59 | }, 60 | getOrCreateOwn: function getOrCreateOwn(metadataKey, Type, target, targetKey) { 61 | var result = metadata.getOwn(metadataKey, target, targetKey); 62 | 63 | if (result === undefined) { 64 | result = new Type(); 65 | Reflect.defineMetadata(metadataKey, result, target, targetKey); 66 | } 67 | 68 | return result; 69 | } 70 | }; 71 | 72 | var originStorage = new Map(); 73 | var unknownOrigin = Object.freeze({ moduleId: undefined, moduleMember: undefined }); 74 | 75 | var Origin = exports.Origin = function () { 76 | function Origin(moduleId, moduleMember) { 77 | 78 | 79 | this.moduleId = moduleId; 80 | this.moduleMember = moduleMember; 81 | } 82 | 83 | Origin.get = function get(fn) { 84 | var origin = originStorage.get(fn); 85 | 86 | if (origin === undefined) { 87 | _aureliaPal.PLATFORM.eachModule(function (key, value) { 88 | if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { 89 | var isBrowserWindow = typeof window !== 'undefined' && value === window; 90 | for (var name in value) { 91 | if (isBrowserWindow && name === 'webkitStorageInfo') { 92 | continue; 93 | } 94 | try { 95 | var exp = value[name]; 96 | if (exp === fn) { 97 | originStorage.set(fn, origin = new Origin(key, name)); 98 | return true; 99 | } 100 | } catch (e) {} 101 | } 102 | } 103 | 104 | if (value === fn) { 105 | originStorage.set(fn, origin = new Origin(key, 'default')); 106 | return true; 107 | } 108 | 109 | return false; 110 | }); 111 | } 112 | 113 | return origin || unknownOrigin; 114 | }; 115 | 116 | Origin.set = function set(fn, origin) { 117 | originStorage.set(fn, origin); 118 | }; 119 | 120 | return Origin; 121 | }(); 122 | 123 | function decorators() { 124 | for (var _len = arguments.length, rest = Array(_len), _key = 0; _key < _len; _key++) { 125 | rest[_key] = arguments[_key]; 126 | } 127 | 128 | var applicator = function applicator(target, key, descriptor) { 129 | var i = rest.length; 130 | 131 | if (key) { 132 | descriptor = descriptor || { 133 | value: target[key], 134 | writable: true, 135 | configurable: true, 136 | enumerable: true 137 | }; 138 | 139 | while (i--) { 140 | descriptor = rest[i](target, key, descriptor) || descriptor; 141 | } 142 | 143 | Object.defineProperty(target, key, descriptor); 144 | } else { 145 | while (i--) { 146 | target = rest[i](target) || target; 147 | } 148 | } 149 | 150 | return target; 151 | }; 152 | 153 | applicator.on = applicator; 154 | return applicator; 155 | } 156 | 157 | function deprecated(optionsOrTarget, maybeKey, maybeDescriptor) { 158 | function decorator(target, key, descriptor) { 159 | var methodSignature = target.constructor.name + '#' + key; 160 | var options = maybeKey ? {} : optionsOrTarget || {}; 161 | var message = 'DEPRECATION - ' + methodSignature; 162 | 163 | if (typeof descriptor.value !== 'function') { 164 | throw new SyntaxError('Only methods can be marked as deprecated.'); 165 | } 166 | 167 | if (options.message) { 168 | message += ' - ' + options.message; 169 | } 170 | 171 | return _extends({}, descriptor, { 172 | value: function deprecationWrapper() { 173 | if (options.error) { 174 | throw new Error(message); 175 | } else { 176 | console.warn(message); 177 | } 178 | 179 | return descriptor.value.apply(this, arguments); 180 | } 181 | }); 182 | } 183 | 184 | return maybeKey ? decorator(optionsOrTarget, maybeKey, maybeDescriptor) : decorator; 185 | } 186 | 187 | function mixin(behavior) { 188 | var instanceKeys = Object.keys(behavior); 189 | 190 | function _mixin(possible) { 191 | var decorator = function decorator(target) { 192 | var resolvedTarget = typeof target === 'function' ? target.prototype : target; 193 | 194 | var i = instanceKeys.length; 195 | while (i--) { 196 | var property = instanceKeys[i]; 197 | Object.defineProperty(resolvedTarget, property, { 198 | value: behavior[property], 199 | writable: true 200 | }); 201 | } 202 | }; 203 | 204 | return possible ? decorator(possible) : decorator; 205 | } 206 | 207 | return _mixin; 208 | } 209 | 210 | function alwaysValid() { 211 | return true; 212 | } 213 | function noCompose() {} 214 | 215 | function ensureProtocolOptions(options) { 216 | if (options === undefined) { 217 | options = {}; 218 | } else if (typeof options === 'function') { 219 | options = { 220 | validate: options 221 | }; 222 | } 223 | 224 | if (!options.validate) { 225 | options.validate = alwaysValid; 226 | } 227 | 228 | if (!options.compose) { 229 | options.compose = noCompose; 230 | } 231 | 232 | return options; 233 | } 234 | 235 | function createProtocolValidator(validate) { 236 | return function (target) { 237 | var result = validate(target); 238 | return result === true; 239 | }; 240 | } 241 | 242 | function createProtocolAsserter(name, validate) { 243 | return function (target) { 244 | var result = validate(target); 245 | if (result !== true) { 246 | throw new Error(result || name + ' was not correctly implemented.'); 247 | } 248 | }; 249 | } 250 | 251 | function protocol(name, options) { 252 | options = ensureProtocolOptions(options); 253 | 254 | var result = function result(target) { 255 | var resolvedTarget = typeof target === 'function' ? target.prototype : target; 256 | 257 | options.compose(resolvedTarget); 258 | result.assert(resolvedTarget); 259 | 260 | Object.defineProperty(resolvedTarget, 'protocol:' + name, { 261 | enumerable: false, 262 | configurable: false, 263 | writable: false, 264 | value: true 265 | }); 266 | }; 267 | 268 | result.validate = createProtocolValidator(options.validate); 269 | result.assert = createProtocolAsserter(name, options.validate); 270 | 271 | return result; 272 | } 273 | 274 | protocol.create = function (name, options) { 275 | options = ensureProtocolOptions(options); 276 | var hidden = 'protocol:' + name; 277 | var result = function result(target) { 278 | var decorator = protocol(name, options); 279 | return target ? decorator(target) : decorator; 280 | }; 281 | 282 | result.decorates = function (obj) { 283 | return obj[hidden] === true; 284 | }; 285 | result.validate = createProtocolValidator(options.validate); 286 | result.assert = createProtocolAsserter(name, options.validate); 287 | 288 | return result; 289 | }; 290 | }); -------------------------------------------------------------------------------- /dist/amd/index.js: -------------------------------------------------------------------------------- 1 | define(['exports', './aurelia-metadata'], function (exports, _aureliaMetadata) { 2 | 'use strict'; 3 | 4 | Object.defineProperty(exports, "__esModule", { 5 | value: true 6 | }); 7 | Object.keys(_aureliaMetadata).forEach(function (key) { 8 | if (key === "default" || key === "__esModule") return; 9 | Object.defineProperty(exports, key, { 10 | enumerable: true, 11 | get: function () { 12 | return _aureliaMetadata[key]; 13 | } 14 | }); 15 | }); 16 | }); -------------------------------------------------------------------------------- /dist/aurelia-metadata.js: -------------------------------------------------------------------------------- 1 | import {PLATFORM} from 'aurelia-pal'; 2 | 3 | function isObject(val) { 4 | return val && (typeof val === 'function' || typeof val === 'object'); 5 | } 6 | 7 | /** 8 | * Helpers for working with metadata on functions. 9 | * 10 | * Note for the Typescript to ES5 transpiler: Due to the non-standard compliant implementation of 'extends', these methods, when applied to derived classes, will operate on the parent class and not on the child class. This can be circumvented by either transpiling to ES2015 (ES6) or by making the targetKey parameter class-specific eg. by using target.name for the targetKey parameter. 11 | */ 12 | interface MetadataType { 13 | /** 14 | * The metadata key representing pluggable resources. 15 | */ 16 | resource: string; 17 | /** 18 | * The metadata key representing parameter type information. 19 | */ 20 | paramTypes: string; 21 | /** 22 | * The metadata key representing object property type information. 23 | */ 24 | propertyType: string; 25 | /** 26 | * The metadata key representing property information. 27 | */ 28 | properties: string; 29 | /** 30 | * Gets metadata specified by a key on a target, searching up the inheritance hierarchy. 31 | * @param metadataKey The key for the metadata to lookup. 32 | * @param target The target to lookup the metadata on. 33 | * @param targetKey The member on the target to lookup the metadata on. 34 | */ 35 | get(metadataKey: string, target: Function, targetKey?: string): Object; 36 | /** 37 | * Gets metadata specified by a key on a target, only searching the own instance. 38 | * @param metadataKey The key for the metadata to lookup. 39 | * @param target The target to lookup the metadata on. 40 | * @param targetKey The member on the target to lookup the metadata on. 41 | */ 42 | getOwn(metadataKey: string, target: Function, targetKey?: string): Object; 43 | /** 44 | * Defines metadata specified by a key on a target. 45 | * @param metadataKey The key for the metadata to define. 46 | * @param target The target to set the metadata on. 47 | * @param targetKey The member on the target to set the metadata on. 48 | */ 49 | define(metadataKey: string, metadataValue: Object, target: Function, targetKey?: string): void; 50 | /** 51 | * Gets metadata specified by a key on a target, or creates an instance of the specified metadata if not found. 52 | * @param metadataKey The key for the metadata to lookup or create. 53 | * @param Type The type of metadata to create if existing metadata is not found. 54 | * @param target The target to lookup or create the metadata on. 55 | * @param targetKey The member on the target to lookup or create the metadata on. 56 | */ 57 | getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey?: string): Object; 58 | } 59 | 60 | /** 61 | * Provides helpers for working with metadata. 62 | */ 63 | export const metadata: MetadataType = { 64 | resource: 'aurelia:resource', 65 | paramTypes: 'design:paramtypes', 66 | propertyType: 'design:type', 67 | properties: 'design:properties', 68 | get(metadataKey: string, target: Function, targetKey?: string): Object { 69 | if (!isObject(target)) { 70 | return undefined; 71 | } 72 | let result = metadata.getOwn(metadataKey, target, targetKey); 73 | return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result; 74 | }, 75 | getOwn(metadataKey: string, target: Function, targetKey?: string): Object { 76 | if (!isObject(target)) { 77 | return undefined; 78 | } 79 | return Reflect.getOwnMetadata(metadataKey, target, targetKey); 80 | }, 81 | define(metadataKey: string, metadataValue: Object, target: Function, targetKey?: string): void { 82 | Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey); 83 | }, 84 | getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey?: string): Object { 85 | let result = metadata.getOwn(metadataKey, target, targetKey); 86 | 87 | if (result === undefined) { 88 | result = new Type(); 89 | Reflect.defineMetadata(metadataKey, result, target, targetKey); 90 | } 91 | 92 | return result; 93 | } 94 | }; 95 | 96 | const originStorage = new Map(); 97 | const unknownOrigin = Object.freeze({moduleId: undefined, moduleMember: undefined}); 98 | 99 | /** 100 | * A metadata annotation that describes the origin module of the function to which it's attached. 101 | */ 102 | export class Origin { 103 | /** 104 | * The id of the module from which the item originated. 105 | */ 106 | moduleId: string; 107 | /** 108 | * The member name of the export on the module object from which the item originated. 109 | */ 110 | moduleMember: string; 111 | 112 | /** 113 | * Creates an instance of Origin metadata. 114 | * @param moduleId The id of the module from which the item originated. 115 | * @param moduleMember The member name of the export on the module object from which the item originated. 116 | */ 117 | constructor(moduleId: string, moduleMember: string) { 118 | this.moduleId = moduleId; 119 | this.moduleMember = moduleMember; 120 | } 121 | 122 | /** 123 | * Get the Origin metadata for the specified function. 124 | * @param fn The function to inspect for Origin metadata. 125 | * @return Returns the Origin metadata. 126 | */ 127 | static get(fn: Function): Origin { 128 | let origin = originStorage.get(fn); 129 | 130 | if (origin === undefined) { 131 | PLATFORM.eachModule((key, value) => { 132 | if (typeof value === 'object') { 133 | let isBrowserWindow = typeof window !== 'undefined' && value === window; 134 | for (let name in value) { 135 | if (isBrowserWindow && name === 'webkitStorageInfo') { continue; } // Avoid warning to console 136 | try { 137 | let exp = value[name]; 138 | if (exp === fn) { 139 | originStorage.set(fn, origin = new Origin(key, name)); 140 | return true; 141 | } 142 | } catch (e) { 143 | // IE11 in cross origin frame fails when accessing Window['frameElement'] with Access Denied script error. 144 | // Window gets exported from webpack buildin/global.js. 145 | } 146 | } 147 | } 148 | 149 | if (value === fn) { 150 | originStorage.set(fn, origin = new Origin(key, 'default')); 151 | return true; 152 | } 153 | 154 | return false; 155 | }); 156 | } 157 | 158 | return origin || unknownOrigin; 159 | } 160 | 161 | /** 162 | * Set the Origin metadata for the specified function. 163 | * @param fn The function to set the Origin metadata on. 164 | * @param fn The Origin metadata to store on the function. 165 | * @return Returns the Origin metadata. 166 | */ 167 | static set(fn: Function, origin: Origin): void { 168 | originStorage.set(fn, origin); 169 | } 170 | } 171 | 172 | /** 173 | * An object capable of applying it's captured decorators to a target. 174 | */ 175 | interface DecoratorApplicator { 176 | /** 177 | * Applies the decorators to the target. 178 | * @param target The target. 179 | * @param key If applying to a method, the member name. 180 | * @param descriptor If applying to a method, you may supply an initial descriptor to pass to the decorators. 181 | */ 182 | on(target: any, key?: string, descriptor?: PropertyDescriptor): any; 183 | } 184 | 185 | /** 186 | * Enables applying decorators, particularly for use when there is no syntax support in the language, such as with ES5 and ES2016. 187 | * @param rest The decorators to apply. 188 | */ 189 | export function decorators(...rest: Function[]): DecoratorApplicator { 190 | let applicator = function(target, key, descriptor) { 191 | let i = rest.length; 192 | 193 | if (key) { 194 | descriptor = descriptor || { 195 | value: target[key], 196 | writable: true, 197 | configurable: true, 198 | enumerable: true 199 | }; 200 | 201 | while (i--) { 202 | descriptor = rest[i](target, key, descriptor) || descriptor; 203 | } 204 | 205 | Object.defineProperty(target, key, descriptor); 206 | } else { 207 | while (i--) { 208 | target = rest[i](target) || target; 209 | } 210 | } 211 | 212 | return target; 213 | }; 214 | 215 | applicator.on = applicator; 216 | return applicator; 217 | } 218 | 219 | /** 220 | * Options that control how the deprected decorator should function at runtime. 221 | */ 222 | interface DeprecatedOptions { 223 | /** 224 | * Specifies a custom deprecation message. 225 | */ 226 | message: string; 227 | /** 228 | * Specifies whether or not the deprecation should throw an error. 229 | */ 230 | error: boolean; 231 | } 232 | 233 | /** 234 | * Decorator: Enables marking methods as deprecated. 235 | * @param optionsOrTarget Options for how the deprected decorator should function at runtime. 236 | */ 237 | export function deprecated(optionsOrTarget?: DeprecatedOptions, maybeKey?: string, maybeDescriptor?: Object): any { 238 | function decorator(target, key, descriptor) { 239 | const methodSignature = `${target.constructor.name}#${key}`; 240 | let options = maybeKey ? {} : optionsOrTarget || {}; 241 | let message = `DEPRECATION - ${methodSignature}`; 242 | 243 | if (typeof descriptor.value !== 'function') { 244 | throw new SyntaxError('Only methods can be marked as deprecated.'); 245 | } 246 | 247 | if (options.message) { 248 | message += ` - ${options.message}`; 249 | } 250 | 251 | return { 252 | ...descriptor, 253 | value: function deprecationWrapper() { 254 | if (options.error) { 255 | throw new Error(message); 256 | } else { 257 | console.warn(message); 258 | } 259 | 260 | return descriptor.value.apply(this, arguments); 261 | } 262 | }; 263 | } 264 | 265 | return maybeKey ? decorator(optionsOrTarget, maybeKey, maybeDescriptor) : decorator; 266 | } 267 | 268 | /** 269 | * Decorator: Enables mixing behaior into a class. 270 | * @param behavior An object with keys for each method to mix into the target class. 271 | */ 272 | export function mixin(behavior: Object): any { 273 | const instanceKeys = Object.keys(behavior); 274 | 275 | function _mixin(possible) { 276 | let decorator = function(target) { 277 | let resolvedTarget = typeof target === 'function' 278 | ? target.prototype 279 | : target; 280 | 281 | let i = instanceKeys.length; 282 | while (i--) { 283 | let property = instanceKeys[i]; 284 | Object.defineProperty(resolvedTarget, property, { 285 | value: behavior[property], 286 | writable: true 287 | }); 288 | } 289 | }; 290 | 291 | return possible ? decorator(possible) : decorator; 292 | } 293 | 294 | return _mixin; 295 | } 296 | 297 | function alwaysValid() { return true; } 298 | function noCompose() {} 299 | 300 | function ensureProtocolOptions(options) { 301 | if (options === undefined) { 302 | options = {}; 303 | } else if (typeof options === 'function') { 304 | options = { 305 | validate: options 306 | }; 307 | } 308 | 309 | if (!options.validate) { 310 | options.validate = alwaysValid; 311 | } 312 | 313 | if (!options.compose) { 314 | options.compose = noCompose; 315 | } 316 | 317 | return options; 318 | } 319 | 320 | function createProtocolValidator(validate) { 321 | return function(target) { 322 | let result = validate(target); 323 | return result === true; 324 | }; 325 | } 326 | 327 | function createProtocolAsserter(name, validate) { 328 | return function(target) { 329 | let result = validate(target); 330 | if (result !== true) { 331 | throw new Error(result || `${name} was not correctly implemented.`); 332 | } 333 | }; 334 | } 335 | 336 | /** 337 | * Options used during protocol creation. 338 | */ 339 | interface ProtocolOptions { 340 | /** 341 | * A function that will be run to validate the decorated class when the protocol is applied. It is also used to validate adhoc instances. 342 | * If the validation fails, a message should be returned which directs the developer in how to address the issue. 343 | */ 344 | validate?: (target: any) => string | boolean; 345 | /** 346 | * A function which has the opportunity to compose additional behavior into the decorated class when the protocol is applied. 347 | */ 348 | compose?: (target: any) => void; 349 | } 350 | 351 | /** 352 | * Decorator: Creates a protocol. 353 | * @param name The name of the protocol. 354 | * @param options The validation function or options object used in configuring the protocol. 355 | */ 356 | export function protocol(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): any { 357 | options = ensureProtocolOptions(options); 358 | 359 | let result = function(target) { 360 | let resolvedTarget = typeof target === 'function' 361 | ? target.prototype 362 | : target; 363 | 364 | options.compose(resolvedTarget); 365 | result.assert(resolvedTarget); 366 | 367 | Object.defineProperty(resolvedTarget, 'protocol:' + name, { 368 | enumerable: false, 369 | configurable: false, 370 | writable: false, 371 | value: true 372 | }); 373 | }; 374 | 375 | result.validate = createProtocolValidator(options.validate); 376 | result.assert = createProtocolAsserter(name, options.validate); 377 | 378 | return result; 379 | } 380 | 381 | /** 382 | * Creates a protocol decorator. 383 | * @param name The name of the protocol. 384 | * @param options The validation function or options object used in configuring the protocol. 385 | * @return The protocol decorator; 386 | */ 387 | protocol.create = function(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): Function { 388 | options = ensureProtocolOptions(options); 389 | let hidden = 'protocol:' + name; 390 | let result = function(target) { 391 | let decorator = protocol(name, options); 392 | return target ? decorator(target) : decorator; 393 | }; 394 | 395 | result.decorates = function(obj) { return obj[hidden] === true; }; 396 | result.validate = createProtocolValidator(options.validate); 397 | result.assert = createProtocolAsserter(name, options.validate); 398 | 399 | return result; 400 | }; 401 | -------------------------------------------------------------------------------- /dist/commonjs/aurelia-metadata.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.Origin = exports.metadata = undefined; 7 | 8 | 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; }; 9 | 10 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; 11 | 12 | exports.decorators = decorators; 13 | exports.deprecated = deprecated; 14 | exports.mixin = mixin; 15 | exports.protocol = protocol; 16 | 17 | var _aureliaPal = require('aurelia-pal'); 18 | 19 | 20 | 21 | function isObject(val) { 22 | return val && (typeof val === 'function' || (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object'); 23 | } 24 | 25 | var metadata = exports.metadata = { 26 | resource: 'aurelia:resource', 27 | paramTypes: 'design:paramtypes', 28 | propertyType: 'design:type', 29 | properties: 'design:properties', 30 | get: function get(metadataKey, target, targetKey) { 31 | if (!isObject(target)) { 32 | return undefined; 33 | } 34 | var result = metadata.getOwn(metadataKey, target, targetKey); 35 | return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result; 36 | }, 37 | getOwn: function getOwn(metadataKey, target, targetKey) { 38 | if (!isObject(target)) { 39 | return undefined; 40 | } 41 | return Reflect.getOwnMetadata(metadataKey, target, targetKey); 42 | }, 43 | define: function define(metadataKey, metadataValue, target, targetKey) { 44 | Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey); 45 | }, 46 | getOrCreateOwn: function getOrCreateOwn(metadataKey, Type, target, targetKey) { 47 | var result = metadata.getOwn(metadataKey, target, targetKey); 48 | 49 | if (result === undefined) { 50 | result = new Type(); 51 | Reflect.defineMetadata(metadataKey, result, target, targetKey); 52 | } 53 | 54 | return result; 55 | } 56 | }; 57 | 58 | var originStorage = new Map(); 59 | var unknownOrigin = Object.freeze({ moduleId: undefined, moduleMember: undefined }); 60 | 61 | var Origin = exports.Origin = function () { 62 | function Origin(moduleId, moduleMember) { 63 | 64 | 65 | this.moduleId = moduleId; 66 | this.moduleMember = moduleMember; 67 | } 68 | 69 | Origin.get = function get(fn) { 70 | var origin = originStorage.get(fn); 71 | 72 | if (origin === undefined) { 73 | _aureliaPal.PLATFORM.eachModule(function (key, value) { 74 | if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { 75 | var isBrowserWindow = typeof window !== 'undefined' && value === window; 76 | for (var name in value) { 77 | if (isBrowserWindow && name === 'webkitStorageInfo') { 78 | continue; 79 | } 80 | try { 81 | var exp = value[name]; 82 | if (exp === fn) { 83 | originStorage.set(fn, origin = new Origin(key, name)); 84 | return true; 85 | } 86 | } catch (e) {} 87 | } 88 | } 89 | 90 | if (value === fn) { 91 | originStorage.set(fn, origin = new Origin(key, 'default')); 92 | return true; 93 | } 94 | 95 | return false; 96 | }); 97 | } 98 | 99 | return origin || unknownOrigin; 100 | }; 101 | 102 | Origin.set = function set(fn, origin) { 103 | originStorage.set(fn, origin); 104 | }; 105 | 106 | return Origin; 107 | }(); 108 | 109 | function decorators() { 110 | for (var _len = arguments.length, rest = Array(_len), _key = 0; _key < _len; _key++) { 111 | rest[_key] = arguments[_key]; 112 | } 113 | 114 | var applicator = function applicator(target, key, descriptor) { 115 | var i = rest.length; 116 | 117 | if (key) { 118 | descriptor = descriptor || { 119 | value: target[key], 120 | writable: true, 121 | configurable: true, 122 | enumerable: true 123 | }; 124 | 125 | while (i--) { 126 | descriptor = rest[i](target, key, descriptor) || descriptor; 127 | } 128 | 129 | Object.defineProperty(target, key, descriptor); 130 | } else { 131 | while (i--) { 132 | target = rest[i](target) || target; 133 | } 134 | } 135 | 136 | return target; 137 | }; 138 | 139 | applicator.on = applicator; 140 | return applicator; 141 | } 142 | 143 | function deprecated(optionsOrTarget, maybeKey, maybeDescriptor) { 144 | function decorator(target, key, descriptor) { 145 | var methodSignature = target.constructor.name + '#' + key; 146 | var options = maybeKey ? {} : optionsOrTarget || {}; 147 | var message = 'DEPRECATION - ' + methodSignature; 148 | 149 | if (typeof descriptor.value !== 'function') { 150 | throw new SyntaxError('Only methods can be marked as deprecated.'); 151 | } 152 | 153 | if (options.message) { 154 | message += ' - ' + options.message; 155 | } 156 | 157 | return _extends({}, descriptor, { 158 | value: function deprecationWrapper() { 159 | if (options.error) { 160 | throw new Error(message); 161 | } else { 162 | console.warn(message); 163 | } 164 | 165 | return descriptor.value.apply(this, arguments); 166 | } 167 | }); 168 | } 169 | 170 | return maybeKey ? decorator(optionsOrTarget, maybeKey, maybeDescriptor) : decorator; 171 | } 172 | 173 | function mixin(behavior) { 174 | var instanceKeys = Object.keys(behavior); 175 | 176 | function _mixin(possible) { 177 | var decorator = function decorator(target) { 178 | var resolvedTarget = typeof target === 'function' ? target.prototype : target; 179 | 180 | var i = instanceKeys.length; 181 | while (i--) { 182 | var property = instanceKeys[i]; 183 | Object.defineProperty(resolvedTarget, property, { 184 | value: behavior[property], 185 | writable: true 186 | }); 187 | } 188 | }; 189 | 190 | return possible ? decorator(possible) : decorator; 191 | } 192 | 193 | return _mixin; 194 | } 195 | 196 | function alwaysValid() { 197 | return true; 198 | } 199 | function noCompose() {} 200 | 201 | function ensureProtocolOptions(options) { 202 | if (options === undefined) { 203 | options = {}; 204 | } else if (typeof options === 'function') { 205 | options = { 206 | validate: options 207 | }; 208 | } 209 | 210 | if (!options.validate) { 211 | options.validate = alwaysValid; 212 | } 213 | 214 | if (!options.compose) { 215 | options.compose = noCompose; 216 | } 217 | 218 | return options; 219 | } 220 | 221 | function createProtocolValidator(validate) { 222 | return function (target) { 223 | var result = validate(target); 224 | return result === true; 225 | }; 226 | } 227 | 228 | function createProtocolAsserter(name, validate) { 229 | return function (target) { 230 | var result = validate(target); 231 | if (result !== true) { 232 | throw new Error(result || name + ' was not correctly implemented.'); 233 | } 234 | }; 235 | } 236 | 237 | function protocol(name, options) { 238 | options = ensureProtocolOptions(options); 239 | 240 | var result = function result(target) { 241 | var resolvedTarget = typeof target === 'function' ? target.prototype : target; 242 | 243 | options.compose(resolvedTarget); 244 | result.assert(resolvedTarget); 245 | 246 | Object.defineProperty(resolvedTarget, 'protocol:' + name, { 247 | enumerable: false, 248 | configurable: false, 249 | writable: false, 250 | value: true 251 | }); 252 | }; 253 | 254 | result.validate = createProtocolValidator(options.validate); 255 | result.assert = createProtocolAsserter(name, options.validate); 256 | 257 | return result; 258 | } 259 | 260 | protocol.create = function (name, options) { 261 | options = ensureProtocolOptions(options); 262 | var hidden = 'protocol:' + name; 263 | var result = function result(target) { 264 | var decorator = protocol(name, options); 265 | return target ? decorator(target) : decorator; 266 | }; 267 | 268 | result.decorates = function (obj) { 269 | return obj[hidden] === true; 270 | }; 271 | result.validate = createProtocolValidator(options.validate); 272 | result.assert = createProtocolAsserter(name, options.validate); 273 | 274 | return result; 275 | }; -------------------------------------------------------------------------------- /dist/commonjs/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | 7 | var _aureliaMetadata = require('./aurelia-metadata'); 8 | 9 | Object.keys(_aureliaMetadata).forEach(function (key) { 10 | if (key === "default" || key === "__esModule") return; 11 | Object.defineProperty(exports, key, { 12 | enumerable: true, 13 | get: function get() { 14 | return _aureliaMetadata[key]; 15 | } 16 | }); 17 | }); -------------------------------------------------------------------------------- /dist/es2015/aurelia-metadata.js: -------------------------------------------------------------------------------- 1 | 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; }; 2 | 3 | import { PLATFORM } from 'aurelia-pal'; 4 | 5 | function isObject(val) { 6 | return val && (typeof val === 'function' || typeof val === 'object'); 7 | } 8 | 9 | export const metadata = { 10 | resource: 'aurelia:resource', 11 | paramTypes: 'design:paramtypes', 12 | propertyType: 'design:type', 13 | properties: 'design:properties', 14 | get(metadataKey, target, targetKey) { 15 | if (!isObject(target)) { 16 | return undefined; 17 | } 18 | let result = metadata.getOwn(metadataKey, target, targetKey); 19 | return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result; 20 | }, 21 | getOwn(metadataKey, target, targetKey) { 22 | if (!isObject(target)) { 23 | return undefined; 24 | } 25 | return Reflect.getOwnMetadata(metadataKey, target, targetKey); 26 | }, 27 | define(metadataKey, metadataValue, target, targetKey) { 28 | Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey); 29 | }, 30 | getOrCreateOwn(metadataKey, Type, target, targetKey) { 31 | let result = metadata.getOwn(metadataKey, target, targetKey); 32 | 33 | if (result === undefined) { 34 | result = new Type(); 35 | Reflect.defineMetadata(metadataKey, result, target, targetKey); 36 | } 37 | 38 | return result; 39 | } 40 | }; 41 | 42 | const originStorage = new Map(); 43 | const unknownOrigin = Object.freeze({ moduleId: undefined, moduleMember: undefined }); 44 | 45 | export let Origin = class Origin { 46 | constructor(moduleId, moduleMember) { 47 | this.moduleId = moduleId; 48 | this.moduleMember = moduleMember; 49 | } 50 | 51 | static get(fn) { 52 | let origin = originStorage.get(fn); 53 | 54 | if (origin === undefined) { 55 | PLATFORM.eachModule((key, value) => { 56 | if (typeof value === 'object') { 57 | let isBrowserWindow = typeof window !== 'undefined' && value === window; 58 | for (let name in value) { 59 | if (isBrowserWindow && name === 'webkitStorageInfo') { 60 | continue; 61 | } 62 | try { 63 | let exp = value[name]; 64 | if (exp === fn) { 65 | originStorage.set(fn, origin = new Origin(key, name)); 66 | return true; 67 | } 68 | } catch (e) {} 69 | } 70 | } 71 | 72 | if (value === fn) { 73 | originStorage.set(fn, origin = new Origin(key, 'default')); 74 | return true; 75 | } 76 | 77 | return false; 78 | }); 79 | } 80 | 81 | return origin || unknownOrigin; 82 | } 83 | 84 | static set(fn, origin) { 85 | originStorage.set(fn, origin); 86 | } 87 | }; 88 | 89 | export function decorators(...rest) { 90 | let applicator = function (target, key, descriptor) { 91 | let i = rest.length; 92 | 93 | if (key) { 94 | descriptor = descriptor || { 95 | value: target[key], 96 | writable: true, 97 | configurable: true, 98 | enumerable: true 99 | }; 100 | 101 | while (i--) { 102 | descriptor = rest[i](target, key, descriptor) || descriptor; 103 | } 104 | 105 | Object.defineProperty(target, key, descriptor); 106 | } else { 107 | while (i--) { 108 | target = rest[i](target) || target; 109 | } 110 | } 111 | 112 | return target; 113 | }; 114 | 115 | applicator.on = applicator; 116 | return applicator; 117 | } 118 | 119 | export function deprecated(optionsOrTarget, maybeKey, maybeDescriptor) { 120 | function decorator(target, key, descriptor) { 121 | const methodSignature = `${target.constructor.name}#${key}`; 122 | let options = maybeKey ? {} : optionsOrTarget || {}; 123 | let message = `DEPRECATION - ${methodSignature}`; 124 | 125 | if (typeof descriptor.value !== 'function') { 126 | throw new SyntaxError('Only methods can be marked as deprecated.'); 127 | } 128 | 129 | if (options.message) { 130 | message += ` - ${options.message}`; 131 | } 132 | 133 | return _extends({}, descriptor, { 134 | value: function deprecationWrapper() { 135 | if (options.error) { 136 | throw new Error(message); 137 | } else { 138 | console.warn(message); 139 | } 140 | 141 | return descriptor.value.apply(this, arguments); 142 | } 143 | }); 144 | } 145 | 146 | return maybeKey ? decorator(optionsOrTarget, maybeKey, maybeDescriptor) : decorator; 147 | } 148 | 149 | export function mixin(behavior) { 150 | const instanceKeys = Object.keys(behavior); 151 | 152 | function _mixin(possible) { 153 | let decorator = function (target) { 154 | let resolvedTarget = typeof target === 'function' ? target.prototype : target; 155 | 156 | let i = instanceKeys.length; 157 | while (i--) { 158 | let property = instanceKeys[i]; 159 | Object.defineProperty(resolvedTarget, property, { 160 | value: behavior[property], 161 | writable: true 162 | }); 163 | } 164 | }; 165 | 166 | return possible ? decorator(possible) : decorator; 167 | } 168 | 169 | return _mixin; 170 | } 171 | 172 | function alwaysValid() { 173 | return true; 174 | } 175 | function noCompose() {} 176 | 177 | function ensureProtocolOptions(options) { 178 | if (options === undefined) { 179 | options = {}; 180 | } else if (typeof options === 'function') { 181 | options = { 182 | validate: options 183 | }; 184 | } 185 | 186 | if (!options.validate) { 187 | options.validate = alwaysValid; 188 | } 189 | 190 | if (!options.compose) { 191 | options.compose = noCompose; 192 | } 193 | 194 | return options; 195 | } 196 | 197 | function createProtocolValidator(validate) { 198 | return function (target) { 199 | let result = validate(target); 200 | return result === true; 201 | }; 202 | } 203 | 204 | function createProtocolAsserter(name, validate) { 205 | return function (target) { 206 | let result = validate(target); 207 | if (result !== true) { 208 | throw new Error(result || `${name} was not correctly implemented.`); 209 | } 210 | }; 211 | } 212 | 213 | export function protocol(name, options) { 214 | options = ensureProtocolOptions(options); 215 | 216 | let result = function (target) { 217 | let resolvedTarget = typeof target === 'function' ? target.prototype : target; 218 | 219 | options.compose(resolvedTarget); 220 | result.assert(resolvedTarget); 221 | 222 | Object.defineProperty(resolvedTarget, 'protocol:' + name, { 223 | enumerable: false, 224 | configurable: false, 225 | writable: false, 226 | value: true 227 | }); 228 | }; 229 | 230 | result.validate = createProtocolValidator(options.validate); 231 | result.assert = createProtocolAsserter(name, options.validate); 232 | 233 | return result; 234 | } 235 | 236 | protocol.create = function (name, options) { 237 | options = ensureProtocolOptions(options); 238 | let hidden = 'protocol:' + name; 239 | let result = function (target) { 240 | let decorator = protocol(name, options); 241 | return target ? decorator(target) : decorator; 242 | }; 243 | 244 | result.decorates = function (obj) { 245 | return obj[hidden] === true; 246 | }; 247 | result.validate = createProtocolValidator(options.validate); 248 | result.assert = createProtocolAsserter(name, options.validate); 249 | 250 | return result; 251 | }; -------------------------------------------------------------------------------- /dist/es2015/index.js: -------------------------------------------------------------------------------- 1 | export * from './aurelia-metadata'; -------------------------------------------------------------------------------- /dist/native-modules/aurelia-metadata.js: -------------------------------------------------------------------------------- 1 | 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; }; 2 | 3 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; 4 | 5 | 6 | 7 | import { PLATFORM } from 'aurelia-pal'; 8 | 9 | function isObject(val) { 10 | return val && (typeof val === 'function' || (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object'); 11 | } 12 | 13 | export var metadata = { 14 | resource: 'aurelia:resource', 15 | paramTypes: 'design:paramtypes', 16 | propertyType: 'design:type', 17 | properties: 'design:properties', 18 | get: function get(metadataKey, target, targetKey) { 19 | if (!isObject(target)) { 20 | return undefined; 21 | } 22 | var result = metadata.getOwn(metadataKey, target, targetKey); 23 | return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result; 24 | }, 25 | getOwn: function getOwn(metadataKey, target, targetKey) { 26 | if (!isObject(target)) { 27 | return undefined; 28 | } 29 | return Reflect.getOwnMetadata(metadataKey, target, targetKey); 30 | }, 31 | define: function define(metadataKey, metadataValue, target, targetKey) { 32 | Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey); 33 | }, 34 | getOrCreateOwn: function getOrCreateOwn(metadataKey, Type, target, targetKey) { 35 | var result = metadata.getOwn(metadataKey, target, targetKey); 36 | 37 | if (result === undefined) { 38 | result = new Type(); 39 | Reflect.defineMetadata(metadataKey, result, target, targetKey); 40 | } 41 | 42 | return result; 43 | } 44 | }; 45 | 46 | var originStorage = new Map(); 47 | var unknownOrigin = Object.freeze({ moduleId: undefined, moduleMember: undefined }); 48 | 49 | export var Origin = function () { 50 | function Origin(moduleId, moduleMember) { 51 | 52 | 53 | this.moduleId = moduleId; 54 | this.moduleMember = moduleMember; 55 | } 56 | 57 | Origin.get = function get(fn) { 58 | var origin = originStorage.get(fn); 59 | 60 | if (origin === undefined) { 61 | PLATFORM.eachModule(function (key, value) { 62 | if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { 63 | var isBrowserWindow = typeof window !== 'undefined' && value === window; 64 | for (var name in value) { 65 | if (isBrowserWindow && name === 'webkitStorageInfo') { 66 | continue; 67 | } 68 | try { 69 | var exp = value[name]; 70 | if (exp === fn) { 71 | originStorage.set(fn, origin = new Origin(key, name)); 72 | return true; 73 | } 74 | } catch (e) {} 75 | } 76 | } 77 | 78 | if (value === fn) { 79 | originStorage.set(fn, origin = new Origin(key, 'default')); 80 | return true; 81 | } 82 | 83 | return false; 84 | }); 85 | } 86 | 87 | return origin || unknownOrigin; 88 | }; 89 | 90 | Origin.set = function set(fn, origin) { 91 | originStorage.set(fn, origin); 92 | }; 93 | 94 | return Origin; 95 | }(); 96 | 97 | export function decorators() { 98 | for (var _len = arguments.length, rest = Array(_len), _key = 0; _key < _len; _key++) { 99 | rest[_key] = arguments[_key]; 100 | } 101 | 102 | var applicator = function applicator(target, key, descriptor) { 103 | var i = rest.length; 104 | 105 | if (key) { 106 | descriptor = descriptor || { 107 | value: target[key], 108 | writable: true, 109 | configurable: true, 110 | enumerable: true 111 | }; 112 | 113 | while (i--) { 114 | descriptor = rest[i](target, key, descriptor) || descriptor; 115 | } 116 | 117 | Object.defineProperty(target, key, descriptor); 118 | } else { 119 | while (i--) { 120 | target = rest[i](target) || target; 121 | } 122 | } 123 | 124 | return target; 125 | }; 126 | 127 | applicator.on = applicator; 128 | return applicator; 129 | } 130 | 131 | export function deprecated(optionsOrTarget, maybeKey, maybeDescriptor) { 132 | function decorator(target, key, descriptor) { 133 | var methodSignature = target.constructor.name + '#' + key; 134 | var options = maybeKey ? {} : optionsOrTarget || {}; 135 | var message = 'DEPRECATION - ' + methodSignature; 136 | 137 | if (typeof descriptor.value !== 'function') { 138 | throw new SyntaxError('Only methods can be marked as deprecated.'); 139 | } 140 | 141 | if (options.message) { 142 | message += ' - ' + options.message; 143 | } 144 | 145 | return _extends({}, descriptor, { 146 | value: function deprecationWrapper() { 147 | if (options.error) { 148 | throw new Error(message); 149 | } else { 150 | console.warn(message); 151 | } 152 | 153 | return descriptor.value.apply(this, arguments); 154 | } 155 | }); 156 | } 157 | 158 | return maybeKey ? decorator(optionsOrTarget, maybeKey, maybeDescriptor) : decorator; 159 | } 160 | 161 | export function mixin(behavior) { 162 | var instanceKeys = Object.keys(behavior); 163 | 164 | function _mixin(possible) { 165 | var decorator = function decorator(target) { 166 | var resolvedTarget = typeof target === 'function' ? target.prototype : target; 167 | 168 | var i = instanceKeys.length; 169 | while (i--) { 170 | var property = instanceKeys[i]; 171 | Object.defineProperty(resolvedTarget, property, { 172 | value: behavior[property], 173 | writable: true 174 | }); 175 | } 176 | }; 177 | 178 | return possible ? decorator(possible) : decorator; 179 | } 180 | 181 | return _mixin; 182 | } 183 | 184 | function alwaysValid() { 185 | return true; 186 | } 187 | function noCompose() {} 188 | 189 | function ensureProtocolOptions(options) { 190 | if (options === undefined) { 191 | options = {}; 192 | } else if (typeof options === 'function') { 193 | options = { 194 | validate: options 195 | }; 196 | } 197 | 198 | if (!options.validate) { 199 | options.validate = alwaysValid; 200 | } 201 | 202 | if (!options.compose) { 203 | options.compose = noCompose; 204 | } 205 | 206 | return options; 207 | } 208 | 209 | function createProtocolValidator(validate) { 210 | return function (target) { 211 | var result = validate(target); 212 | return result === true; 213 | }; 214 | } 215 | 216 | function createProtocolAsserter(name, validate) { 217 | return function (target) { 218 | var result = validate(target); 219 | if (result !== true) { 220 | throw new Error(result || name + ' was not correctly implemented.'); 221 | } 222 | }; 223 | } 224 | 225 | export function protocol(name, options) { 226 | options = ensureProtocolOptions(options); 227 | 228 | var result = function result(target) { 229 | var resolvedTarget = typeof target === 'function' ? target.prototype : target; 230 | 231 | options.compose(resolvedTarget); 232 | result.assert(resolvedTarget); 233 | 234 | Object.defineProperty(resolvedTarget, 'protocol:' + name, { 235 | enumerable: false, 236 | configurable: false, 237 | writable: false, 238 | value: true 239 | }); 240 | }; 241 | 242 | result.validate = createProtocolValidator(options.validate); 243 | result.assert = createProtocolAsserter(name, options.validate); 244 | 245 | return result; 246 | } 247 | 248 | protocol.create = function (name, options) { 249 | options = ensureProtocolOptions(options); 250 | var hidden = 'protocol:' + name; 251 | var result = function result(target) { 252 | var decorator = protocol(name, options); 253 | return target ? decorator(target) : decorator; 254 | }; 255 | 256 | result.decorates = function (obj) { 257 | return obj[hidden] === true; 258 | }; 259 | result.validate = createProtocolValidator(options.validate); 260 | result.assert = createProtocolAsserter(name, options.validate); 261 | 262 | return result; 263 | }; -------------------------------------------------------------------------------- /dist/native-modules/index.js: -------------------------------------------------------------------------------- 1 | export * from './aurelia-metadata'; -------------------------------------------------------------------------------- /dist/system/aurelia-metadata.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | System.register(['aurelia-pal'], function (_export, _context) { 4 | "use strict"; 5 | 6 | var PLATFORM, _extends, _typeof, metadata, originStorage, unknownOrigin, Origin; 7 | 8 | 9 | 10 | function isObject(val) { 11 | return val && (typeof val === 'function' || (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object'); 12 | } 13 | 14 | function decorators() { 15 | for (var _len = arguments.length, rest = Array(_len), _key = 0; _key < _len; _key++) { 16 | rest[_key] = arguments[_key]; 17 | } 18 | 19 | var applicator = function applicator(target, key, descriptor) { 20 | var i = rest.length; 21 | 22 | if (key) { 23 | descriptor = descriptor || { 24 | value: target[key], 25 | writable: true, 26 | configurable: true, 27 | enumerable: true 28 | }; 29 | 30 | while (i--) { 31 | descriptor = rest[i](target, key, descriptor) || descriptor; 32 | } 33 | 34 | Object.defineProperty(target, key, descriptor); 35 | } else { 36 | while (i--) { 37 | target = rest[i](target) || target; 38 | } 39 | } 40 | 41 | return target; 42 | }; 43 | 44 | applicator.on = applicator; 45 | return applicator; 46 | } 47 | 48 | _export('decorators', decorators); 49 | 50 | function deprecated(optionsOrTarget, maybeKey, maybeDescriptor) { 51 | function decorator(target, key, descriptor) { 52 | var methodSignature = target.constructor.name + '#' + key; 53 | var options = maybeKey ? {} : optionsOrTarget || {}; 54 | var message = 'DEPRECATION - ' + methodSignature; 55 | 56 | if (typeof descriptor.value !== 'function') { 57 | throw new SyntaxError('Only methods can be marked as deprecated.'); 58 | } 59 | 60 | if (options.message) { 61 | message += ' - ' + options.message; 62 | } 63 | 64 | return _extends({}, descriptor, { 65 | value: function deprecationWrapper() { 66 | if (options.error) { 67 | throw new Error(message); 68 | } else { 69 | console.warn(message); 70 | } 71 | 72 | return descriptor.value.apply(this, arguments); 73 | } 74 | }); 75 | } 76 | 77 | return maybeKey ? decorator(optionsOrTarget, maybeKey, maybeDescriptor) : decorator; 78 | } 79 | 80 | _export('deprecated', deprecated); 81 | 82 | function mixin(behavior) { 83 | var instanceKeys = Object.keys(behavior); 84 | 85 | function _mixin(possible) { 86 | var decorator = function decorator(target) { 87 | var resolvedTarget = typeof target === 'function' ? target.prototype : target; 88 | 89 | var i = instanceKeys.length; 90 | while (i--) { 91 | var property = instanceKeys[i]; 92 | Object.defineProperty(resolvedTarget, property, { 93 | value: behavior[property], 94 | writable: true 95 | }); 96 | } 97 | }; 98 | 99 | return possible ? decorator(possible) : decorator; 100 | } 101 | 102 | return _mixin; 103 | } 104 | 105 | _export('mixin', mixin); 106 | 107 | function alwaysValid() { 108 | return true; 109 | } 110 | function noCompose() {} 111 | 112 | function ensureProtocolOptions(options) { 113 | if (options === undefined) { 114 | options = {}; 115 | } else if (typeof options === 'function') { 116 | options = { 117 | validate: options 118 | }; 119 | } 120 | 121 | if (!options.validate) { 122 | options.validate = alwaysValid; 123 | } 124 | 125 | if (!options.compose) { 126 | options.compose = noCompose; 127 | } 128 | 129 | return options; 130 | } 131 | 132 | function createProtocolValidator(validate) { 133 | return function (target) { 134 | var result = validate(target); 135 | return result === true; 136 | }; 137 | } 138 | 139 | function createProtocolAsserter(name, validate) { 140 | return function (target) { 141 | var result = validate(target); 142 | if (result !== true) { 143 | throw new Error(result || name + ' was not correctly implemented.'); 144 | } 145 | }; 146 | } 147 | 148 | function protocol(name, options) { 149 | options = ensureProtocolOptions(options); 150 | 151 | var result = function result(target) { 152 | var resolvedTarget = typeof target === 'function' ? target.prototype : target; 153 | 154 | options.compose(resolvedTarget); 155 | result.assert(resolvedTarget); 156 | 157 | Object.defineProperty(resolvedTarget, 'protocol:' + name, { 158 | enumerable: false, 159 | configurable: false, 160 | writable: false, 161 | value: true 162 | }); 163 | }; 164 | 165 | result.validate = createProtocolValidator(options.validate); 166 | result.assert = createProtocolAsserter(name, options.validate); 167 | 168 | return result; 169 | } 170 | 171 | _export('protocol', protocol); 172 | 173 | return { 174 | setters: [function (_aureliaPal) { 175 | PLATFORM = _aureliaPal.PLATFORM; 176 | }], 177 | execute: function () { 178 | _extends = Object.assign || function (target) { 179 | for (var i = 1; i < arguments.length; i++) { 180 | var source = arguments[i]; 181 | 182 | for (var key in source) { 183 | if (Object.prototype.hasOwnProperty.call(source, key)) { 184 | target[key] = source[key]; 185 | } 186 | } 187 | } 188 | 189 | return target; 190 | }; 191 | 192 | _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { 193 | return typeof obj; 194 | } : function (obj) { 195 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; 196 | }; 197 | 198 | _export('metadata', metadata = { 199 | resource: 'aurelia:resource', 200 | paramTypes: 'design:paramtypes', 201 | propertyType: 'design:type', 202 | properties: 'design:properties', 203 | get: function get(metadataKey, target, targetKey) { 204 | if (!isObject(target)) { 205 | return undefined; 206 | } 207 | var result = metadata.getOwn(metadataKey, target, targetKey); 208 | return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result; 209 | }, 210 | getOwn: function getOwn(metadataKey, target, targetKey) { 211 | if (!isObject(target)) { 212 | return undefined; 213 | } 214 | return Reflect.getOwnMetadata(metadataKey, target, targetKey); 215 | }, 216 | define: function define(metadataKey, metadataValue, target, targetKey) { 217 | Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey); 218 | }, 219 | getOrCreateOwn: function getOrCreateOwn(metadataKey, Type, target, targetKey) { 220 | var result = metadata.getOwn(metadataKey, target, targetKey); 221 | 222 | if (result === undefined) { 223 | result = new Type(); 224 | Reflect.defineMetadata(metadataKey, result, target, targetKey); 225 | } 226 | 227 | return result; 228 | } 229 | }); 230 | 231 | _export('metadata', metadata); 232 | 233 | originStorage = new Map(); 234 | unknownOrigin = Object.freeze({ moduleId: undefined, moduleMember: undefined }); 235 | 236 | _export('Origin', Origin = function () { 237 | function Origin(moduleId, moduleMember) { 238 | 239 | 240 | this.moduleId = moduleId; 241 | this.moduleMember = moduleMember; 242 | } 243 | 244 | Origin.get = function get(fn) { 245 | var origin = originStorage.get(fn); 246 | 247 | if (origin === undefined) { 248 | PLATFORM.eachModule(function (key, value) { 249 | if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { 250 | var isBrowserWindow = typeof window !== 'undefined' && value === window; 251 | for (var name in value) { 252 | if (isBrowserWindow && name === 'webkitStorageInfo') { 253 | continue; 254 | } 255 | try { 256 | var exp = value[name]; 257 | if (exp === fn) { 258 | originStorage.set(fn, origin = new Origin(key, name)); 259 | return true; 260 | } 261 | } catch (e) {} 262 | } 263 | } 264 | 265 | if (value === fn) { 266 | originStorage.set(fn, origin = new Origin(key, 'default')); 267 | return true; 268 | } 269 | 270 | return false; 271 | }); 272 | } 273 | 274 | return origin || unknownOrigin; 275 | }; 276 | 277 | Origin.set = function set(fn, origin) { 278 | originStorage.set(fn, origin); 279 | }; 280 | 281 | return Origin; 282 | }()); 283 | 284 | _export('Origin', Origin); 285 | 286 | protocol.create = function (name, options) { 287 | options = ensureProtocolOptions(options); 288 | var hidden = 'protocol:' + name; 289 | var result = function result(target) { 290 | var decorator = protocol(name, options); 291 | return target ? decorator(target) : decorator; 292 | }; 293 | 294 | result.decorates = function (obj) { 295 | return obj[hidden] === true; 296 | }; 297 | result.validate = createProtocolValidator(options.validate); 298 | result.assert = createProtocolAsserter(name, options.validate); 299 | 300 | return result; 301 | }; 302 | } 303 | }; 304 | }); -------------------------------------------------------------------------------- /dist/system/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | System.register(['./aurelia-metadata'], function (_export, _context) { 4 | "use strict"; 5 | 6 | return { 7 | setters: [function (_aureliaMetadata) { 8 | var _exportObj = {}; 9 | 10 | for (var _key in _aureliaMetadata) { 11 | if (_key !== "default" && _key !== "__esModule") _exportObj[_key] = _aureliaMetadata[_key]; 12 | } 13 | 14 | _export(_exportObj); 15 | }], 16 | execute: function () {} 17 | }; 18 | }); -------------------------------------------------------------------------------- /dist/types/aurelia-metadata.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Helpers for working with metadata on functions. 3 | * 4 | * Note for the Typescript to ES5 transpiler: Due to the non-standard compliant implementation of 'extends', these methods, when applied to derived classes, will operate on the parent class and not on the child class. This can be circumvented by either transpiling to ES2015 (ES6) or by making the targetKey parameter class-specific eg. by using target.name for the targetKey parameter. 5 | */ 6 | export declare interface MetadataType { 7 | 8 | /** 9 | * The metadata key representing pluggable resources. 10 | */ 11 | resource: string; 12 | 13 | /** 14 | * The metadata key representing parameter type information. 15 | */ 16 | paramTypes: string; 17 | 18 | /** 19 | * The metadata key representing object property type information. 20 | */ 21 | propertyType: string; 22 | 23 | /** 24 | * The metadata key representing property information. 25 | */ 26 | properties: string; 27 | 28 | /** 29 | * Gets metadata specified by a key on a target, searching up the inheritance hierarchy. 30 | * @param metadataKey The key for the metadata to lookup. 31 | * @param target The target to lookup the metadata on. 32 | * @param targetKey The member on the target to lookup the metadata on. 33 | */ 34 | get(metadataKey: string, target: Function, targetKey?: string): Object; 35 | 36 | /** 37 | * Gets metadata specified by a key on a target, only searching the own instance. 38 | * @param metadataKey The key for the metadata to lookup. 39 | * @param target The target to lookup the metadata on. 40 | * @param targetKey The member on the target to lookup the metadata on. 41 | */ 42 | getOwn(metadataKey: string, target: Function, targetKey?: string): Object; 43 | 44 | /** 45 | * Defines metadata specified by a key on a target. 46 | * @param metadataKey The key for the metadata to define. 47 | * @param target The target to set the metadata on. 48 | * @param targetKey The member on the target to set the metadata on. 49 | */ 50 | define(metadataKey: string, metadataValue: Object, target: Function, targetKey?: string): void; 51 | 52 | /** 53 | * Gets metadata specified by a key on a target, or creates an instance of the specified metadata if not found. 54 | * @param metadataKey The key for the metadata to lookup or create. 55 | * @param Type The type of metadata to create if existing metadata is not found. 56 | * @param target The target to lookup or create the metadata on. 57 | * @param targetKey The member on the target to lookup or create the metadata on. 58 | */ 59 | getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey?: string): Object; 60 | } 61 | 62 | /** 63 | * An object capable of applying it's captured decorators to a target. 64 | */ 65 | export declare interface DecoratorApplicator { 66 | 67 | /** 68 | * Applies the decorators to the target. 69 | * @param target The target. 70 | * @param key If applying to a method, the member name. 71 | * @param descriptor If applying to a method, you may supply an initial descriptor to pass to the decorators. 72 | */ 73 | on(target: any, key?: string, descriptor?: PropertyDescriptor): any; 74 | } 75 | 76 | /** 77 | * Options that control how the deprected decorator should function at runtime. 78 | */ 79 | export declare interface DeprecatedOptions { 80 | 81 | /** 82 | * Specifies a custom deprecation message. 83 | */ 84 | message: string; 85 | 86 | /** 87 | * Specifies whether or not the deprecation should throw an error. 88 | */ 89 | error: boolean; 90 | } 91 | 92 | /** 93 | * Options used during protocol creation. 94 | */ 95 | export declare interface ProtocolOptions { 96 | 97 | /** 98 | * A function that will be run to validate the decorated class when the protocol is applied. It is also used to validate adhoc instances. 99 | * If the validation fails, a message should be returned which directs the developer in how to address the issue. 100 | */ 101 | validate?: (target: any) => string | boolean; 102 | 103 | /** 104 | * A function which has the opportunity to compose additional behavior into the decorated class when the protocol is applied. 105 | */ 106 | compose?: (target: any) => void; 107 | } 108 | 109 | /** 110 | * Provides helpers for working with metadata. 111 | */ 112 | /** 113 | * Provides helpers for working with metadata. 114 | */ 115 | export declare const metadata: MetadataType; 116 | 117 | /** 118 | * A metadata annotation that describes the origin module of the function to which it's attached. 119 | */ 120 | export declare class Origin { 121 | 122 | /** 123 | * The id of the module from which the item originated. 124 | */ 125 | moduleId: string; 126 | 127 | /** 128 | * The member name of the export on the module object from which the item originated. 129 | */ 130 | moduleMember: string; 131 | 132 | /** 133 | * Creates an instance of Origin metadata. 134 | * @param moduleId The id of the module from which the item originated. 135 | * @param moduleMember The member name of the export on the module object from which the item originated. 136 | */ 137 | constructor(moduleId: string, moduleMember: string); 138 | 139 | /** 140 | * Get the Origin metadata for the specified function. 141 | * @param fn The function to inspect for Origin metadata. 142 | * @return Returns the Origin metadata. 143 | */ 144 | static get(fn: Function): Origin; 145 | 146 | /** 147 | * Set the Origin metadata for the specified function. 148 | * @param fn The function to set the Origin metadata on. 149 | * @param fn The Origin metadata to store on the function. 150 | * @return Returns the Origin metadata. 151 | */ 152 | static set(fn: Function, origin: Origin): void; 153 | } 154 | 155 | /** 156 | * Enables applying decorators, particularly for use when there is no syntax support in the language, such as with ES5 and ES2016. 157 | * @param rest The decorators to apply. 158 | */ 159 | /** 160 | * Enables applying decorators, particularly for use when there is no syntax support in the language, such as with ES5 and ES2016. 161 | * @param rest The decorators to apply. 162 | */ 163 | export declare function decorators(...rest: Function[]): DecoratorApplicator; 164 | 165 | /** 166 | * Decorator: Enables marking methods as deprecated. 167 | * @param optionsOrTarget Options for how the deprected decorator should function at runtime. 168 | */ 169 | /** 170 | * Decorator: Enables marking methods as deprecated. 171 | * @param optionsOrTarget Options for how the deprected decorator should function at runtime. 172 | */ 173 | export declare function deprecated(optionsOrTarget?: DeprecatedOptions, maybeKey?: string, maybeDescriptor?: Object): any; 174 | 175 | /** 176 | * Decorator: Enables mixing behaior into a class. 177 | * @param behavior An object with keys for each method to mix into the target class. 178 | */ 179 | export declare function mixin(behavior: Object): any; 180 | 181 | /** 182 | * Decorator: Creates a protocol. 183 | * @param name The name of the protocol. 184 | * @param options The validation function or options object used in configuring the protocol. 185 | */ 186 | /** 187 | * Decorator: Creates a protocol. 188 | * @param name The name of the protocol. 189 | * @param options The validation function or options object used in configuring the protocol. 190 | */ 191 | export declare function protocol(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): any; -------------------------------------------------------------------------------- /dist/types/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './aurelia-metadata'; -------------------------------------------------------------------------------- /doc/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | ## [1.0.8](https://github.com/aurelia/metadata/compare/1.0.6...1.0.8) (2020-11-05) 3 | 4 | 5 | 6 | 7 | ## [1.0.7](https://github.com/aurelia/metadata/compare/1.0.5...1.0.7) (2019-03-26) 8 | 9 | 10 | ### Bug Fixes 11 | 12 | * **all:** change es2015 back to native-modules ([1d4bfe2](https://github.com/aurelia/metadata/commit/1d4bfe2)) 13 | 14 | 15 | 16 | 17 | ## [1.0.6](https://github.com/aurelia/metadata/compare/1.0.5...1.0.6) (2019-02-04) 18 | 19 | 20 | ### Bug Fixes 21 | 22 | * **all:** change es2015 back to native-modules ([1d4bfe2](https://github.com/aurelia/metadata/commit/1d4bfe2)) 23 | 24 | 25 | 26 | 27 | ## [1.0.5](https://github.com/aurelia/metadata/compare/1.0.4...1.0.5) (2019-01-18) 28 | 29 | * Add module field to package.json. 30 | 31 | 32 | ## [1.0.4](https://github.com/aurelia/metadata/compare/1.0.3...1.0.4) (2018-06-13) 33 | 34 | 35 | ### Bug Fixes 36 | 37 | * **metadata:** IE cross origin frame Access Denied on Window['frameElement'] in Origin.get ([5e678d7](https://github.com/aurelia/metadata/commit/5e678d7)) 38 | * **metadata:** IE cross origin frame Access Denied on Window['frameElement'] in Origin.get - add test ([553c5a2](https://github.com/aurelia/metadata/commit/553c5a2)) 39 | 40 | 41 | 42 | 43 | ## [1.0.3](https://github.com/aurelia/metadata/compare/1.0.2...v1.0.3) (2016-12-23) 44 | 45 | 46 | ### Bug Fixes 47 | 48 | * **metadata:** handle primitive targets ([ecf28dd](https://github.com/aurelia/metadata/commit/ecf28dd)), closes [aurelia/templating-resources#267](https://github.com/aurelia/templating-resources/issues/267) [aurelia/metadata#47](https://github.com/aurelia/metadata/issues/47) [aurelia/binding#551](https://github.com/aurelia/binding/issues/551) [aurelia/dependency-injection#141](https://github.com/aurelia/dependency-injection/issues/141) [aurelia/binding#376](https://github.com/aurelia/binding/issues/376) 49 | 50 | 51 | 52 | 53 | ## [1.0.1](https://github.com/aurelia/metadata/compare/1.0.0...v1.0.1) (2016-10-05) 54 | 55 | 56 | ### Bug Fixes 57 | 58 | * issue [#41](https://github.com/aurelia/metadata/issues/41) ([7b4a0bc](https://github.com/aurelia/metadata/commit/7b4a0bc)) 59 | 60 | 61 | 62 | 63 | # [1.0.0](https://github.com/aurelia/metadata/compare/1.0.0-rc.1.0.1...v1.0.0) (2016-07-27) 64 | 65 | 66 | 67 | 68 | # [1.0.0-rc.1.0.1](https://github.com/aurelia/metadata/compare/1.0.0-rc.1.0.0...v1.0.0-rc.1.0.1) (2016-07-12) 69 | 70 | 71 | 72 | 73 | # [1.0.0-rc.1.0.0](https://github.com/aurelia/metadata/compare/1.0.0-beta.2.0.1...v1.0.0-rc.1.0.0) (2016-06-22) 74 | 75 | 76 | 77 | ### 1.0.0-beta.1.2.1 (2016-05-10) 78 | 79 | 80 | #### Bug Fixes 81 | 82 | * **metadata:** targetKey in Reflect.defineMetadata is optional ([fa861f7c](https://github.com/aurelia/metadata/commit/fa861f7c8fd867331b607021ec3b0e871262990f)) 83 | 84 | 85 | ### 1.0.0-beta.1.2.0 (2016-03-22) 86 | 87 | * Update to Babel 6 88 | 89 | ### 1.0.0-beta.1.1.6 (2016-03-02) 90 | 91 | 92 | #### Bug Fixes 93 | 94 | * **for-of:** remove for of loop ([cd1fca10](https://github.com/aurelia/metadata/commit/cd1fca10af480a0228d4e6a8dba8cf3d9b2c0754)) 95 | 96 | 97 | ### 1.0.0-beta.1.1.5 (2016-03-01) 98 | 99 | 100 | #### Bug Fixes 101 | 102 | * **all:** remove core-js dependency ([3a300a87](https://github.com/aurelia/metadata/commit/3a300a87126ccf1ab2656c3a09a983a72316d9c9)) 103 | 104 | 105 | #### Features 106 | 107 | * **all:** remove duplicate code and use new polyfills ([ec2b65ee](https://github.com/aurelia/metadata/commit/ec2b65ee17db5e24b050fca3ea1e088f8ca7aff7)) 108 | 109 | 110 | ### 1.0.0-beta.1.1.4 (2016-02-08) 111 | 112 | 113 | ### 1.0.0-beta.1.1.2 (2016-01-28) 114 | 115 | * fix package metadata for jspm 116 | 117 | ### 1.0.0-beta.1.1.0 (2016-01-28) 118 | 119 | 120 | #### Features 121 | 122 | * **all:** update for jspm; update core-js; update aurelia deps ([01aa7e40](https://github.com/aurelia/metadata/commit/01aa7e404834a5d1824501108fc17bce98536a8c)) 123 | 124 | 125 | ### 1.0.0-beta.1 (2015-11-15) 126 | 127 | 128 | ### 0.10.1 (2015-11-11) 129 | 130 | 131 | #### Bug Fixes 132 | 133 | * **all:** improve TS happiness for decorators ([dd35c4fd](https://github.com/aurelia/metadata/commit/dd35c4fd1ef089764bdbacde8380aa4d47e28d2c)) 134 | 135 | 136 | ## 0.10.0 (2015-11-09) 137 | 138 | 139 | #### Bug Fixes 140 | 141 | * **decorators:** remove generics causing the build to fail ([88067ab4](https://github.com/aurelia/metadata/commit/88067ab4d52b9d8d8b8888a78cd92edd5e0f197c)) 142 | * **eslintrc:** linting configuration ([86ee6498](https://github.com/aurelia/metadata/commit/86ee6498b26565dac53114d64ab42cab1cbbf44a)) 143 | * **protocol:** make decorates work with any object type ([dd64b951](https://github.com/aurelia/metadata/commit/dd64b951f3589573a418ab138046be08ebdc5220)) 144 | 145 | 146 | #### Features 147 | 148 | * **all:** new decorators, mixin, protocol and deprecated; new way for ES5/6 to apply decor ([b0c2cd4c](https://github.com/aurelia/metadata/commit/b0c2cd4c018dd5deed22e396cd50b468e633751d)) 149 | 150 | 151 | ## 0.9.0 (2015-10-13) 152 | 153 | 154 | #### Bug Fixes 155 | 156 | * **ResourceType:** fix load to return Promise ([a43e8d28](https://github.com/aurelia/metadata/commit/a43e8d28b7c85bcff20119de2b0c384a9853a50e)) 157 | * **all:** 158 | * Metadata to metadata Decorators to decorators ([86abaa7b](https://github.com/aurelia/metadata/commit/86abaa7b1c2bcf98681c7ce2eda1686eadd235ae)) 159 | * remove System faking and move eachModule helper ([b8c1ce2e](https://github.com/aurelia/metadata/commit/b8c1ce2e3db6c4e54cbe914fe037479c612928db)) 160 | * address issue with globals and remove unnecessary Reflect.metadata poly ([93cda3b4](https://github.com/aurelia/metadata/commit/93cda3b401e706b837fc398c1fc106e829e936fe)) 161 | * update compiler, fix core-js ref ([b3dd9ea8](https://github.com/aurelia/metadata/commit/b3dd9ea8619f90efbaf9ff2d6617b7d92ad348bb)) 162 | * **annotations:** 163 | * remove bad export ([e307aaa8](https://github.com/aurelia/metadata/commit/e307aaa80260b4c674dd6fb577d92be37c297916)) 164 | * normalize annotations on the fly ([0c2b6a55](https://github.com/aurelia/metadata/commit/0c2b6a55feb08a6f56605dad245a83ce16172035)) 165 | * **annotations spec:** remove bad import ([d949c42d](https://github.com/aurelia/metadata/commit/d949c42d8129829c5168fcf4b861d9e6231af11f)) 166 | * **build:** 167 | * update linting, testing and tools ([15c83ea6](https://github.com/aurelia/metadata/commit/15c83ea6414849e0102a5986358d43e9918578a0)) 168 | * add missing bower bump ([017aad74](https://github.com/aurelia/metadata/commit/017aad746538ae3f65955e370b57f260946ed01b)) 169 | * **metadata:** 170 | * Use correct import for core-js We were previously using `import core from core-j ([d7895cf5](https://github.com/aurelia/metadata/commit/d7895cf54debecce7f281eae33024d74f254815e)) 171 | * 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)) 172 | * mark fake System as such ([c40cfcb8](https://github.com/aurelia/metadata/commit/c40cfcb87c3c788f607d3ff67bf494ca05f5be15)) 173 | * store in private map ([52aed24e](https://github.com/aurelia/metadata/commit/52aed24ec5f7f25477cb8021493232c49d67be8b)) 174 | * fix initializer for _first property ([740eb07c](https://github.com/aurelia/metadata/commit/740eb07c39b883b1d4e08e5dc779ee9e960a4e07)) 175 | * add the locator config back on a configure property ([555612d1](https://github.com/aurelia/metadata/commit/555612d1df56e18c75b2c27bb9c99e0449fefa7e)) 176 | * fix safari complaint about variable "locator" ([6e887eac](https://github.com/aurelia/metadata/commit/6e887eac6eb4a7cd74b3b87080c6169d180cfa8e)) 177 | * rename configuration helper ([81c73ec1](https://github.com/aurelia/metadata/commit/81c73ec13ceeb6f257d6ae7a6ca91a02ed43ddcf)) 178 | * accidental double wrapping of custom location function ([ac11ead8](https://github.com/aurelia/metadata/commit/ac11ead8cdb031c51bf705ea7775108b6f29ddcb)) 179 | * **origin:** 180 | * short-circuit module registry search on origin location success ([889e0ce7](https://github.com/aurelia/metadata/commit/889e0ce753d40b320ca803a5e4b16e4716219707)) 181 | * never return null for a origin check ([cc25a5e6](https://github.com/aurelia/metadata/commit/cc25a5e6f8e0336cd5817a3460f1921d83969af8)) 182 | * **origin.spec:** incorrect test for empty origin data ([14304d56](https://github.com/aurelia/metadata/commit/14304d562eb78c93264052bd1fe21eb74dd69842)) 183 | * **package:** 184 | * update aurelia tools and dts generator ([4cba6176](https://github.com/aurelia/metadata/commit/4cba61761b80ad9241a2516c72bee5999abe8986)) 185 | * change jspm directories ([2d61d2da](https://github.com/aurelia/metadata/commit/2d61d2dae9b8ce6899afffccd8f93ee0b5de8010)) 186 | * **readme:** Now mentions Chrome required to run tests. ([86d9f4c2](https://github.com/aurelia/metadata/commit/86d9f4c29c9a859bb22d981d30707c85761d5a38)) 187 | * **test:** correct import sources ([fd5b6f06](https://github.com/aurelia/metadata/commit/fd5b6f0696aa8e735fcf59f633e7b7f75924932f)) 188 | 189 | 190 | #### Features 191 | 192 | * **all:** 193 | * update to pal ([6544cec1](https://github.com/aurelia/metadata/commit/6544cec1d8b5d2576ceb53e1d7b5c54718178c88)) 194 | * improve d.ts generation and api doc comments ([901f6747](https://github.com/aurelia/metadata/commit/901f6747e6513a6a03b6d9861b63c843d4487f6e)) 195 | * improve type info ([1818b0a8](https://github.com/aurelia/metadata/commit/1818b0a8631c32870dc93a7fff53a31e9871cdc7)) 196 | * metadata is now based on the ES7 proposal ([32ebe967](https://github.com/aurelia/metadata/commit/32ebe9676b89156cda736ecdf106b92002275ffd)) 197 | * new decorator infrastructure ([72a6226e](https://github.com/aurelia/metadata/commit/72a6226e202c28f538f1f6350a130d0d76e23fa9)) 198 | * **annotations:** enable deep traversal of inheritance hierarchy ([db07e892](https://github.com/aurelia/metadata/commit/db07e8920ea880ca16f3edc18afc0c99d79360fa)) 199 | * **build:** 200 | * d.ts generation and build concat ([e7e24b5b](https://github.com/aurelia/metadata/commit/e7e24b5b0502920c6616219d305134c1e69b4fea)) 201 | * update to latest 6to5 and switch to system.register module format ([8d5e644b](https://github.com/aurelia/metadata/commit/8d5e644be29f42f27a0bb2d1e7b0ca63893d1735)) 202 | * **docs:** generate api.json from .d.ts file ([8edc2390](https://github.com/aurelia/metadata/commit/8edc2390d55fec7b9538d86d900a921e907b209b)) 203 | * **metadata:** 204 | * add a noop property for noop functions ([bcd4fc66](https://github.com/aurelia/metadata/commit/bcd4fc66f49011d55c6635e7025139e139c8867a)) 205 | * add firstOrAdd helper ([8ba74b71](https://github.com/aurelia/metadata/commit/8ba74b710f78ddd3f6aa6b059ca54273e91ce960)) 206 | * 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)) 207 | * enhance dsl for configuring added metadata ([8ba28995](https://github.com/aurelia/metadata/commit/8ba2899578cf1353e16f6e695ce93a538153d6bf)) 208 | * add a "has" helper to MetadataStorage ([362fcc7b](https://github.com/aurelia/metadata/commit/362fcc7bfe4793cc2b2c296b33d21a5a6a9e99f8)) 209 | * new metadata fluent api ([b4c8162f](https://github.com/aurelia/metadata/commit/b4c8162f3428b7aa09db4bd8dd01f6a5505bf7ef)) 210 | * re-implement metadata ([ce0304e2](https://github.com/aurelia/metadata/commit/ce0304e2fdc1f2aa69c3146aa9c42a260d868c0e)) 211 | * **origin:** 212 | * search module registry for module id if not found ([4abfc246](https://github.com/aurelia/metadata/commit/4abfc2469da4db3d3a077cb733c75e0c364f7068)) 213 | * do not alter target object or function with origin data ([cbb8ac3a](https://github.com/aurelia/metadata/commit/cbb8ac3aeb15873232d76a97d1ba97dd8aa63d91)) 214 | 215 | 216 | ## 0.8.0 (2015-09-04) 217 | 218 | 219 | #### Bug Fixes 220 | 221 | * **build:** update linting, testing and tools ([15c83ea6](https://github.com/aurelia/metadata/commit/15c83ea6414849e0102a5986358d43e9918578a0)) 222 | 223 | 224 | #### Features 225 | 226 | * **all:** improve d.ts generation and api doc comments ([901f6747](https://github.com/aurelia/metadata/commit/901f6747e6513a6a03b6d9861b63c843d4487f6e)) 227 | * **metadata:** add a noop property for noop functions ([bcd4fc66](https://github.com/aurelia/metadata/commit/bcd4fc66f49011d55c6635e7025139e139c8867a)) 228 | 229 | 230 | ### 0.7.3 (2015-08-14) 231 | 232 | 233 | #### Bug Fixes 234 | 235 | * **metadata:** Use correct import for core-js We were previously using `import core from core-j ([d7895cf5](https://github.com/aurelia/metadata/commit/d7895cf54debecce7f281eae33024d74f254815e)) 236 | 237 | 238 | #### Features 239 | 240 | * **all:** improve type info ([1818b0a8](https://github.com/aurelia/metadata/commit/1818b0a8631c32870dc93a7fff53a31e9871cdc7)) 241 | * **docs:** generate api.json from .d.ts file ([8edc2390](https://github.com/aurelia/metadata/commit/8edc2390d55fec7b9538d86d900a921e907b209b)) 242 | 243 | 244 | ### 0.7.2 (2015-08-04) 245 | 246 | 247 | ### 0.7.1 (2015-07-29) 248 | 249 | 250 | #### Bug Fixes 251 | 252 | * **metadata:** 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)) 253 | 254 | 255 | ## 0.7.0 (2015-07-01) 256 | 257 | 258 | #### Bug Fixes 259 | 260 | * **all:** address issue with globals and remove unnecessary Reflect.metadata poly ([93cda3b4](https://github.com/aurelia/metadata/commit/93cda3b401e706b837fc398c1fc106e829e936fe)) 261 | * **metadata:** mark fake System as such ([c40cfcb8](https://github.com/aurelia/metadata/commit/c40cfcb87c3c788f607d3ff67bf494ca05f5be15)) 262 | * **origin:** short-circuit module registry search on origin location success ([889e0ce7](https://github.com/aurelia/metadata/commit/889e0ce753d40b320ca803a5e4b16e4716219707)) 263 | * **package:** update aurelia tools and dts generator ([4cba6176](https://github.com/aurelia/metadata/commit/4cba61761b80ad9241a2516c72bee5999abe8986)) 264 | * **test:** correct import sources ([fd5b6f06](https://github.com/aurelia/metadata/commit/fd5b6f0696aa8e735fcf59f633e7b7f75924932f)) 265 | 266 | 267 | #### Features 268 | 269 | * **build:** d.ts generation and build concat ([e7e24b5b](https://github.com/aurelia/metadata/commit/e7e24b5b0502920c6616219d305134c1e69b4fea)) 270 | 271 | 272 | ## 0.6.0 (2015-06-08) 273 | 274 | 275 | #### Bug Fixes 276 | 277 | * **readme:** Now mentions Chrome required to run tests. ([86d9f4c2](https://github.com/aurelia/metadata/commit/86d9f4c29c9a859bb22d981d30707c85761d5a38)) 278 | 279 | 280 | #### Features 281 | 282 | * **origin:** search module registry for module id if not found ([4abfc246](https://github.com/aurelia/metadata/commit/4abfc2469da4db3d3a077cb733c75e0c364f7068)) 283 | 284 | 285 | ## 0.5.0 (2015-04-30) 286 | 287 | 288 | #### Bug Fixes 289 | 290 | * **origin:** never return null for a origin check ([cc25a5e6](https://github.com/aurelia/metadata/commit/cc25a5e6f8e0336cd5817a3460f1921d83969af8)) 291 | * **origin.spec:** incorrect test for empty origin data ([14304d56](https://github.com/aurelia/metadata/commit/14304d562eb78c93264052bd1fe21eb74dd69842)) 292 | 293 | 294 | #### Features 295 | 296 | * **all:** metadata is now based on the ES7 proposal ([32ebe967](https://github.com/aurelia/metadata/commit/32ebe9676b89156cda736ecdf106b92002275ffd)) 297 | 298 | 299 | ## 0.4.0 (2015-04-09) 300 | 301 | 302 | #### Bug Fixes 303 | 304 | * **ResourceType:** fix load to return Promise ([a43e8d28](https://github.com/aurelia/metadata/commit/a43e8d28b7c85bcff20119de2b0c384a9853a50e)) 305 | * **all:** update compiler, fix core-js ref ([b3dd9ea8](https://github.com/aurelia/metadata/commit/b3dd9ea8619f90efbaf9ff2d6617b7d92ad348bb)) 306 | * **metadata:** 307 | * store in private map ([52aed24e](https://github.com/aurelia/metadata/commit/52aed24ec5f7f25477cb8021493232c49d67be8b)) 308 | * fix initializer for _first property ([740eb07c](https://github.com/aurelia/metadata/commit/740eb07c39b883b1d4e08e5dc779ee9e960a4e07)) 309 | * add the locator config back on a configure property ([555612d1](https://github.com/aurelia/metadata/commit/555612d1df56e18c75b2c27bb9c99e0449fefa7e)) 310 | 311 | 312 | #### Features 313 | 314 | * **all:** new decorator infrastructure ([72a6226e](https://github.com/aurelia/metadata/commit/72a6226e202c28f538f1f6350a130d0d76e23fa9)) 315 | * **metadata:** add firstOrAdd helper ([8ba74b71](https://github.com/aurelia/metadata/commit/8ba74b710f78ddd3f6aa6b059ca54273e91ce960)) 316 | 317 | 318 | ### 0.3.4 (2015-03-24) 319 | 320 | 321 | #### Features 322 | 323 | * **metadata:** 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)) 324 | 325 | 326 | ### 0.3.3 (2015-02-28) 327 | 328 | 329 | #### Bug Fixes 330 | 331 | * **package:** change jspm directories ([2d61d2da](https://github.com/aurelia/metadata/commit/2d61d2dae9b8ce6899afffccd8f93ee0b5de8010)) 332 | 333 | 334 | ### 0.3.2 (2015-02-27) 335 | 336 | 337 | #### Bug Fixes 338 | 339 | * **build:** add missing bower bump ([017aad74](https://github.com/aurelia/metadata/commit/017aad746538ae3f65955e370b57f260946ed01b)) 340 | 341 | 342 | ### 0.3.1 (2015-01-25) 343 | 344 | 345 | #### Bug Fixes 346 | 347 | * **metadata:** fix safari complaint about variable "locator" ([6e887eac](https://github.com/aurelia/metadata/commit/6e887eac6eb4a7cd74b3b87080c6169d180cfa8e)) 348 | 349 | 350 | ## 0.3.0 (2015-01-22) 351 | 352 | 353 | #### Bug Fixes 354 | 355 | * **metadata:** 356 | * rename configuration helper ([81c73ec1](https://github.com/aurelia/metadata/commit/81c73ec13ceeb6f257d6ae7a6ca91a02ed43ddcf)) 357 | * accidental double wrapping of custom location function ([ac11ead8](https://github.com/aurelia/metadata/commit/ac11ead8cdb031c51bf705ea7775108b6f29ddcb)) 358 | 359 | 360 | #### Features 361 | 362 | * **metadata:** 363 | * enhance dsl for configuring added metadata ([8ba28995](https://github.com/aurelia/metadata/commit/8ba2899578cf1353e16f6e695ce93a538153d6bf)) 364 | * add a "has" helper to MetadataStorage ([362fcc7b](https://github.com/aurelia/metadata/commit/362fcc7bfe4793cc2b2c296b33d21a5a6a9e99f8)) 365 | * new metadata fluent api ([b4c8162f](https://github.com/aurelia/metadata/commit/b4c8162f3428b7aa09db4bd8dd01f6a5505bf7ef)) 366 | * re-implement metadata ([ce0304e2](https://github.com/aurelia/metadata/commit/ce0304e2fdc1f2aa69c3146aa9c42a260d868c0e)) 367 | * **origin:** do not alter target object or function with origin data ([cbb8ac3a](https://github.com/aurelia/metadata/commit/cbb8ac3aeb15873232d76a97d1ba97dd8aa63d91)) 368 | 369 | 370 | ### 0.2.4 (2015-01-12) 371 | 372 | 373 | #### Bug Fixes 374 | 375 | * **annotations:** remove bad export ([e307aaa8](https://github.com/aurelia/metadata/commit/e307aaa80260b4c674dd6fb577d92be37c297916)) 376 | * **annotations spec:** remove bad import ([d949c42d](https://github.com/aurelia/metadata/commit/d949c42d8129829c5168fcf4b861d9e6231af11f)) 377 | 378 | 379 | ### 0.2.3 (2015-01-06) 380 | 381 | * Updated package data to ensure proper system.register module format detetion by jspm. 382 | 383 | ## 0.2.0 (2015-01-06) 384 | 385 | 386 | #### Features 387 | 388 | * **annotations:** enable deep traversal of inheritance hierarchy ([db07e892](https://github.com/aurelia/metadata/commit/db07e8920ea880ca16f3edc18afc0c99d79360fa)) 389 | * **build:** update to latest 6to5 and switch to system.register module format ([8d5e644b](https://github.com/aurelia/metadata/commit/8d5e644be29f42f27a0bb2d1e7b0ca63893d1735)) 390 | 391 | 392 | ## 0.1.0 (2014-12-11) 393 | 394 | 395 | #### Bug Fixes 396 | 397 | * **annotations:** normalize annotations on the fly ([0c2b6a55](https://github.com/aurelia/metadata/commit/0c2b6a55feb08a6f56605dad245a83ce16172035)) 398 | -------------------------------------------------------------------------------- /doc/api.json: -------------------------------------------------------------------------------- 1 | {"name":"aurelia-metadata","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}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":134,"character":23}]},{"id":48,"name":"moduleId","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"The id of the module from which the item originated."},"sources":[{"fileName":"aurelia-metadata.d.ts","line":129,"character":10}],"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."},"sources":[{"fileName":"aurelia-metadata.d.ts","line":134,"character":14}],"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}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":148,"character":12}]},{"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"}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":156,"character":12}]}],"groups":[{"title":"Constructors","kind":512,"children":[50]},{"title":"Properties","kind":1024,"children":[48,49]},{"title":"Methods","kind":2048,"children":[54,57]}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":124,"character":27}]},{"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":{"text":"If applying to a method, the member name."},"type":{"type":"instrinct","name":"string"}},{"id":34,"name":"descriptor","kind":32768,"kindString":"Parameter","flags":{"isOptional":true},"comment":{"text":"If applying to a method, you may supply an initial descriptor to pass to the decorators.\n"},"type":{"type":"reference","name":"PropertyDescriptor"}}],"type":{"type":"instrinct","name":"any"}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":77,"character":4}]}],"groups":[{"title":"Methods","kind":2048,"children":[30]}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":69,"character":44}]},{"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."},"sources":[{"fileName":"aurelia-metadata.d.ts","line":93,"character":7}],"type":{"type":"instrinct","name":"boolean"}},{"id":36,"name":"message","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"Specifies a custom deprecation message."},"sources":[{"fileName":"aurelia-metadata.d.ts","line":88,"character":9}],"type":{"type":"instrinct","name":"string"}}],"groups":[{"title":"Properties","kind":1024,"children":[37,36]}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":83,"character":42}]},{"id":2,"name":"MetadataType","kind":256,"kindString":"Interface","flags":{"isExported":true},"comment":{"shortText":"Helpers for working with metadata on functions.","text":"Note for the Typescript to ES5 transpiler: Due to the non-standard compliant implementation of 'extends', these methods, when applied to derived classes, will operate on the parent class and not on the child class. This can be circumvented by either transpiling to ES2015 (ES6) or by making the targetKey parameter class-specific eg. by using target.name for the targetKey parameter.\n"},"children":[{"id":4,"name":"paramTypes","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"The metadata key representing parameter type information."},"sources":[{"fileName":"aurelia-metadata.d.ts","line":20,"character":12}],"type":{"type":"instrinct","name":"string"}},{"id":6,"name":"properties","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"The metadata key representing property information."},"sources":[{"fileName":"aurelia-metadata.d.ts","line":30,"character":12}],"type":{"type":"instrinct","name":"string"}},{"id":5,"name":"propertyType","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"The metadata key representing object property type information."},"sources":[{"fileName":"aurelia-metadata.d.ts","line":25,"character":14}],"type":{"type":"instrinct","name":"string"}},{"id":3,"name":"resource","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"The metadata key representing pluggable resources."},"sources":[{"fileName":"aurelia-metadata.d.ts","line":15,"character":10}],"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":{"isOptional":true},"comment":{"text":"The member on the target to set the metadata on.\n"},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":54,"character":8}]},{"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":{"isOptional":true},"comment":{"text":"The member on the target to lookup the metadata on.\n"},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"reference","name":"Object"}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":38,"character":5}]},{"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":{"isOptional":true},"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"}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":63,"character":16}]},{"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":{"isOptional":true},"comment":{"text":"The member on the target to lookup the metadata on.\n"},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"reference","name":"Object"}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":46,"character":8}]}],"groups":[{"title":"Properties","kind":1024,"children":[4,6,5,3]},{"title":"Methods","kind":2048,"children":[17,7,23,12]}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":10,"character":37}]},{"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."},"sources":[{"fileName":"aurelia-metadata.d.ts","line":110,"character":9}],"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"}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":110,"character":11}]}}},{"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."},"sources":[{"fileName":"aurelia-metadata.d.ts","line":105,"character":10}],"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"}]}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":105,"character":12}]}}}],"groups":[{"title":"Properties","kind":1024,"children":[43,39]}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":99,"character":40}]},{"id":61,"name":"metadata","kind":32,"kindString":"Variable","flags":{"isExported":true},"comment":{"shortText":"Provides helpers for working with metadata."},"sources":[{"fileName":"aurelia-metadata.d.ts","line":119,"character":29}],"type":{"type":"reference","name":"MetadataType","id":2}},{"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}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":167,"character":34}]},{"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"}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":177,"character":34}]},{"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"}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":183,"character":29}]},{"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"}]}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":195,"character":56}]}},{"type":"reference","name":"ProtocolOptions","id":38}]}}],"type":{"type":"instrinct","name":"any"}}],"sources":[{"fileName":"aurelia-metadata.d.ts","line":195,"character":32}]}],"groups":[{"title":"Classes","kind":128,"children":[47]},{"title":"Interfaces","kind":256,"children":[29,35,2,38]},{"title":"Variables","kind":32,"children":[61]},{"title":"Functions","kind":64,"children":[62,65,70,73]}]} -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | const gulp = require('gulp'); 3 | const bump = require('gulp-bump'); 4 | const conventionalChangelog = require('gulp-conventional-changelog'); 5 | const yargs = require('yargs'); 6 | const fs = require('fs'); 7 | const path = require('path'); 8 | const exec = require('child_process').exec; 9 | const promisify = require('util').promisify; 10 | const DIR_DOC = './doc'; 11 | const FILE_DOC = path.resolve(DIR_DOC, 'CHANGELOG.md'); 12 | /**@type {{ bump: 'major' | 'minor' | 'patch' | 'prerelease' }} 13 | // @ts-ignore */ 14 | const argv = yargs.argv; 15 | const validBumpTypes = "major|minor|patch|prerelease".split("|"); 16 | /**@type */ 17 | const bumpType = (argv.bump || 'patch').toLowerCase(); 18 | 19 | if(validBumpTypes.indexOf(bumpType) === -1) { 20 | throw new Error('Unrecognized bump "' + bumpType + '".'); 21 | } 22 | 23 | gulp.task('build', async () => { 24 | const { stderr: err1, stdout: out1 } = await promisify(exec)('npm run build'); 25 | if (err1) { 26 | console.log('==== build warning ===='); 27 | console.log(err1); 28 | } 29 | console.log('==== build output ===='); 30 | console.log(out1); 31 | }); 32 | 33 | gulp.task('lint', async () => { 34 | const { stderr: err2, stdout: out2 } = await promisify(exec)('npm run lint'); 35 | if (err2) { 36 | console.log('==== lint warning ===='); 37 | console.log(err2); 38 | } 39 | console.log('==== lint output ===='); 40 | console.log(out2); 41 | }); 42 | 43 | gulp.task('doc', async () => { 44 | const { stderr, stdout } = await promisify(exec)('npm run doc'); 45 | if (stderr) { 46 | console.log('==== doc warning ===='); 47 | console.log(stderr); 48 | } 49 | // quite a pain (no API from typeodc) to generate a json string 50 | // in memory, so just double write 51 | try { 52 | const content = fs.readFileSync(DIR_DOC + '/api.json', { encoding: 'utf-8' }); 53 | fs.writeFileSync(path.resolve(DIR_DOC, 'api.json'), JSON.stringify(JSON.parse(content))); 54 | } finally {} 55 | console.log('==== doc output ===='); 56 | console.log(stdout); 57 | }); 58 | 59 | gulp.task('changelog', function () { 60 | return gulp 61 | .src(FILE_DOC) 62 | .pipe(conventionalChangelog({})) 63 | .pipe(gulp.dest(DIR_DOC)); 64 | }); 65 | 66 | gulp.task('bump-version', function () { 67 | return gulp.src(['./package.json', './bower.json']) 68 | .pipe(bump({ type: bumpType })) 69 | .pipe(gulp.dest('./')); 70 | }); 71 | 72 | gulp.task( 73 | 'prepare-release', 74 | gulp.series( 75 | 'build', 76 | 'lint', 77 | gulp.parallel( 78 | 'doc', 79 | 'bump-version', 80 | 'changelog' 81 | ) 82 | ) 83 | ); 84 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | module.exports = function (config) { 2 | config.set({ 3 | basePath: '', 4 | frameworks: ['jasmine', 'karma-typescript'], 5 | files: [ 6 | "test/**/*.ts", 7 | "src/**/*.ts", 8 | ], 9 | preprocessors: { 10 | "**/*.ts": "karma-typescript", 11 | }, 12 | reporters: ["progress", "karma-typescript"], 13 | karmaTypescriptConfig: (() => { 14 | /**@type {import('karma-typescript').KarmaTypescriptConfig} */ 15 | const options = { 16 | bundlerOptions: { 17 | entrypoints: /\.spec\.ts$/ 18 | }, 19 | compilerOptions: { 20 | emitDecoratorMetadata: true, 21 | experimentalDecorators: true, 22 | module: "commonjs", 23 | sourceMap: true, 24 | target: "ES2015", 25 | lib: ['es2015', 'dom'], 26 | }, 27 | exclude: ["node_modules"] 28 | }; 29 | return options; 30 | })(), 31 | 32 | // web server port 33 | port: 9876, 34 | 35 | // enable / disable colors in the output (reporters and logs) 36 | colors: true, 37 | 38 | // level of logging 39 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 40 | logLevel: config.LOG_INFO, 41 | 42 | // enable / disable watching file and executing tests whenever any file changes 43 | autoWatch: true, 44 | 45 | // start these browsers 46 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 47 | browsers: ['Chrome'], 48 | 49 | // Continuous Integration mode 50 | // if true, Karma captures browsers, runs the tests and exits 51 | singleRun: false 52 | }); 53 | }; 54 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aurelia-metadata", 3 | "version": "1.0.8", 4 | "description": "Utilities for reading and writing the metadata of JavaScript functions.", 5 | "keywords": [ 6 | "aurelia", 7 | "metadata", 8 | "annotations" 9 | ], 10 | "homepage": "http://aurelia.io", 11 | "bugs": { 12 | "url": "https://github.com/aurelia/metadata/issues" 13 | }, 14 | "license": "MIT", 15 | "author": "Rob Eisenberg (http://robeisenberg.com/)", 16 | "main": "dist/commonjs/aurelia-metadata.js", 17 | "module": "dist/native-modules/aurelia-metadata.js", 18 | "typings": "dist/types/aurelia-metadata.d.ts", 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/aurelia/metadata" 22 | }, 23 | "scripts": { 24 | "clean": "rimraf dist", 25 | "test": "karma start --single-run", 26 | "test:watch": "karma start", 27 | "build": "npm run clean && npm run rollup && npm run build:types", 28 | "doc": "typedoc --entryPoints src/index.ts --json doc/api.json", 29 | "rollup": "rollup -c", 30 | "build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types", 31 | "lint": "eslint ./src ./test --ext .ts,.tsx", 32 | "cut-release": "gulp prepare-release" 33 | }, 34 | "files": [ 35 | "dist", 36 | "doc", 37 | "src", 38 | "typings.json", 39 | "README.md", 40 | "LICENSE" 41 | ], 42 | "jspm": { 43 | "registry": "npm", 44 | "main": "aurelia-metadata", 45 | "format": "amd", 46 | "directories": { 47 | "dist": "dist/amd" 48 | }, 49 | "dependencies": { 50 | "aurelia-pal": "^1.0.0" 51 | }, 52 | "devDependencies": { 53 | "aurelia-polyfills": "^0.1.1", 54 | "babel": "babel-core@^5.1.13", 55 | "babel-runtime": "^5.1.13", 56 | "core-js": "^2.0.3" 57 | } 58 | }, 59 | "dependencies": { 60 | "aurelia-pal": "^1.0.0" 61 | }, 62 | "devDependencies": { 63 | "@rollup/plugin-typescript": "^8.1.0", 64 | "@types/jasmine": "^3.6.2", 65 | "@typescript-eslint/eslint-plugin": "^4.14.0", 66 | "@typescript-eslint/parser": "^4.14.0", 67 | "aurelia-polyfills": "^1.3.4", 68 | "eslint": "^7.18.0", 69 | "gulp": "^4.0.2", 70 | "gulp-bump": "^3.2.0", 71 | "gulp-conventional-changelog": "^2.0.35", 72 | "gulp-util": "^3.0.7", 73 | "jasmine-core": "^3.6.0", 74 | "karma": "^5.2.3", 75 | "karma-chrome-launcher": "^3.1.0", 76 | "karma-coverage": "^1.1.1", 77 | "karma-jasmine": "^4.0.1", 78 | "karma-typescript": "^5.2.0", 79 | "merge2": "^1.0.2", 80 | "rimraf": "^3.0.2", 81 | "rollup": "^2.36.2", 82 | "through2": "^2.0.1", 83 | "tslib": "^2.1.0", 84 | "typedoc": "^0.20.16", 85 | "typescript": "^4.1.3", 86 | "vinyl": "^2.2.1", 87 | "vinyl-paths": "^3.0.1", 88 | "yargs": "^4.8.1" 89 | }, 90 | "standard-version": { 91 | "skip": { 92 | "commit": true, 93 | "tag": true 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | import typescript from '@rollup/plugin-typescript'; 3 | 4 | const name = require('./package.json').name; 5 | 6 | /** 7 | * @type {import('rollup').RollupOptions[]} 8 | */ 9 | const rollupOptions = [ 10 | { 11 | input: 'src/index.ts', 12 | external: [ 13 | 'aurelia-pal' 14 | ], 15 | output: [ 16 | { 17 | file: `dist/es2015/${name}.js`, 18 | format: 'es', 19 | sourcemap: true, 20 | }, 21 | ], 22 | plugins: [ 23 | typescript({ 24 | removeComments: true, 25 | sourceMap: true, 26 | }) 27 | ] 28 | }, 29 | { 30 | input: 'src/index.ts', 31 | external: [ 32 | 'aurelia-pal' 33 | ], 34 | output: [ 35 | { 36 | file: `dist/native-modules/${name}.js`, 37 | format: 'es', 38 | sourcemap: true, 39 | }, 40 | { 41 | file: `dist/amd/${name}.js`, 42 | format: 'amd', 43 | name: 'aurelia-metadata', 44 | sourcemap: true, 45 | }, 46 | { 47 | file: `dist/commonjs/${name}.js`, 48 | format: 'cjs', 49 | sourcemap: true, 50 | }, 51 | { 52 | file: `dist/system/${name}.js`, 53 | format: 'system', 54 | sourcemap: true, 55 | } 56 | ], 57 | plugins: [ 58 | typescript({ 59 | target: 'es5', 60 | removeComments: true, 61 | sourceMap: true, 62 | }) 63 | ] 64 | } 65 | ]; 66 | 67 | export default rollupOptions; 68 | -------------------------------------------------------------------------------- /src/decorators.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * An object capable of applying it's captured decorators to a target. 3 | */ 4 | export interface DecoratorApplicator { 5 | /** 6 | * Applies the decorators to the target. 7 | * @param target The target. 8 | * @param key If applying to a method, the member name. 9 | * @param descriptor If applying to a method, you may supply an initial descriptor to pass to the decorators. 10 | */ 11 | on(target: any, key?: string, descriptor?: PropertyDescriptor): any; 12 | } 13 | 14 | /** 15 | * Enables applying decorators, particularly for use when there is no syntax support in the language, such as with ES5 and ES2016. 16 | * @param rest The decorators to apply. 17 | */ 18 | export function decorators(...rest: Function[]): DecoratorApplicator { 19 | const applicator = function(target, key, descriptor) { 20 | let i = rest.length; 21 | 22 | if (key) { 23 | descriptor = descriptor || { 24 | value: target[key], 25 | writable: true, 26 | configurable: true, 27 | enumerable: true 28 | }; 29 | 30 | while (i--) { 31 | descriptor = rest[i](target, key, descriptor) || descriptor; 32 | } 33 | 34 | Object.defineProperty(target, key, descriptor); 35 | } else { 36 | while (i--) { 37 | target = rest[i](target) || target; 38 | } 39 | } 40 | 41 | return target; 42 | } as unknown as DecoratorApplicator; 43 | 44 | applicator.on = applicator as unknown as DecoratorApplicator['on']; 45 | return applicator; 46 | } 47 | -------------------------------------------------------------------------------- /src/deprecated.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Options that control how the deprected decorator should function at runtime. 3 | */ 4 | export interface DeprecatedOptions { 5 | /** 6 | * Specifies a custom deprecation message. 7 | */ 8 | message: string; 9 | /** 10 | * Specifies whether or not the deprecation should throw an error. 11 | */ 12 | error: boolean; 13 | } 14 | 15 | /** 16 | * Decorator: Enables marking methods as deprecated. 17 | * @param optionsOrTarget Options for how the deprected decorator should function at runtime. 18 | */ 19 | export function deprecated(optionsOrTarget?: DeprecatedOptions, maybeKey?: string, maybeDescriptor?: Object): any { 20 | function decorator(target, key, descriptor) { 21 | const methodSignature = `${target.constructor.name}#${key}`; 22 | const options = (maybeKey ? {} : optionsOrTarget || {}) as DeprecatedOptions; 23 | let message = `DEPRECATION - ${methodSignature}`; 24 | 25 | if (typeof descriptor.value !== 'function') { 26 | throw new SyntaxError('Only methods can be marked as deprecated.'); 27 | } 28 | 29 | if (options.message) { 30 | message += ` - ${options.message}`; 31 | } 32 | 33 | return { 34 | ...descriptor, 35 | value: function deprecationWrapper() { 36 | if (options.error) { 37 | throw new Error(message); 38 | } else { 39 | console.warn(message); 40 | } 41 | 42 | return descriptor.value.apply(this, arguments); 43 | } 44 | }; 45 | } 46 | 47 | return maybeKey ? decorator(optionsOrTarget, maybeKey, maybeDescriptor) : decorator; 48 | } 49 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export { decorators, DecoratorApplicator } from './decorators'; 2 | export { deprecated, DeprecatedOptions } from './deprecated'; 3 | export { metadata, MetadataType } from './metadata'; 4 | export { mixin } from './mixin'; 5 | export { Origin } from './origin'; 6 | export { protocol } from './protocol'; 7 | -------------------------------------------------------------------------------- /src/metadata.ts: -------------------------------------------------------------------------------- 1 | function isObject(val) { 2 | return val && (typeof val === 'function' || typeof val === 'object'); 3 | } 4 | 5 | /** 6 | * @internal 7 | */ 8 | declare global { 9 | // eslint-disable-next-line 10 | namespace Reflect { 11 | export function getOwnMetadata(key: any, target: any, targetKey?: any): any; 12 | export function defineMetadata(key: any, value: any, target: any, targetKey?: any): void; 13 | } 14 | } 15 | 16 | /** 17 | * Helpers for working with metadata on functions. 18 | * 19 | * Note for the Typescript to ES5 transpiler: Due to the non-standard compliant implementation of 'extends', these methods, when applied to derived classes, will operate on the parent class and not on the child class. This can be circumvented by either transpiling to ES2015 (ES6) or by making the targetKey parameter class-specific eg. by using target.name for the targetKey parameter. 20 | */ 21 | export interface MetadataType { 22 | /** 23 | * The metadata key representing pluggable resources. 24 | */ 25 | resource: string; 26 | /** 27 | * The metadata key representing parameter type information. 28 | */ 29 | paramTypes: string; 30 | /** 31 | * The metadata key representing object property type information. 32 | */ 33 | propertyType: string; 34 | /** 35 | * The metadata key representing property information. 36 | */ 37 | properties: string; 38 | /** 39 | * Gets metadata specified by a key on a target, searching up the inheritance hierarchy. 40 | * @param metadataKey The key for the metadata to lookup. 41 | * @param target The target to lookup the metadata on. 42 | * @param targetKey The member on the target to lookup the metadata on. 43 | */ 44 | get(metadataKey: string, target: Function, targetKey?: string): Object; 45 | /** 46 | * Gets metadata specified by a key on a target, only searching the own instance. 47 | * @param metadataKey The key for the metadata to lookup. 48 | * @param target The target to lookup the metadata on. 49 | * @param targetKey The member on the target to lookup the metadata on. 50 | */ 51 | getOwn(metadataKey: string, target: Function, targetKey?: string): Object; 52 | /** 53 | * Defines metadata specified by a key on a target. 54 | * @param metadataKey The key for the metadata to define. 55 | * @param target The target to set the metadata on. 56 | * @param targetKey The member on the target to set the metadata on. 57 | */ 58 | define(metadataKey: string, metadataValue: Object, target: Function, targetKey?: string): void; 59 | /** 60 | * Gets metadata specified by a key on a target, or creates an instance of the specified metadata if not found. 61 | * @param metadataKey The key for the metadata to lookup or create. 62 | * @param Type The type of metadata to create if existing metadata is not found. 63 | * @param target The target to lookup or create the metadata on. 64 | * @param targetKey The member on the target to lookup or create the metadata on. 65 | */ 66 | getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey?: string): Object; 67 | } 68 | 69 | /** 70 | * Provides helpers for working with metadata. 71 | */ 72 | export const metadata: MetadataType = { 73 | resource: 'aurelia:resource', 74 | paramTypes: 'design:paramtypes', 75 | propertyType: 'design:type', 76 | properties: 'design:properties', 77 | get(metadataKey: string, target: Function, targetKey?: string): Object { 78 | if (!isObject(target)) { 79 | return undefined; 80 | } 81 | const result = metadata.getOwn(metadataKey, target, targetKey); 82 | return result === undefined ? metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result; 83 | }, 84 | getOwn(metadataKey: string, target: Function, targetKey?: string): Object { 85 | if (!isObject(target)) { 86 | return undefined; 87 | } 88 | return Reflect.getOwnMetadata(metadataKey, target, targetKey); 89 | }, 90 | define(metadataKey: string, metadataValue: Object, target: Function, targetKey?: string): void { 91 | Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey); 92 | }, 93 | getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey?: string): Object { 94 | let result = metadata.getOwn(metadataKey, target, targetKey); 95 | 96 | if (result === undefined) { 97 | result = new (Type as { new(): any })(); 98 | Reflect.defineMetadata(metadataKey, result, target, targetKey); 99 | } 100 | 101 | return result; 102 | } 103 | }; 104 | -------------------------------------------------------------------------------- /src/mixin.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Decorator: Enables mixing behaior into a class. 3 | * @param behavior An object with keys for each method to mix into the target class. 4 | */ 5 | export function mixin(behavior: Object): any { 6 | const instanceKeys = Object.keys(behavior); 7 | 8 | function _mixin(possible) { 9 | const decorator = function(target) { 10 | const resolvedTarget = typeof target === 'function' 11 | ? target.prototype 12 | : target; 13 | 14 | let i = instanceKeys.length; 15 | while (i--) { 16 | const property = instanceKeys[i]; 17 | Object.defineProperty(resolvedTarget, property, { 18 | value: behavior[property], 19 | writable: true 20 | }); 21 | } 22 | }; 23 | 24 | return possible ? decorator(possible) : decorator; 25 | } 26 | 27 | return _mixin; 28 | } 29 | -------------------------------------------------------------------------------- /src/origin.ts: -------------------------------------------------------------------------------- 1 | import { PLATFORM } from 'aurelia-pal'; 2 | 3 | const originStorage = new Map(); 4 | const unknownOrigin = Object.freeze({moduleId: undefined, moduleMember: undefined}); 5 | 6 | /** 7 | * A metadata annotation that describes the origin module of the function to which it's attached. 8 | */ 9 | export class Origin { 10 | /** 11 | * The id of the module from which the item originated. 12 | */ 13 | moduleId: string; 14 | /** 15 | * The member name of the export on the module object from which the item originated. 16 | */ 17 | moduleMember: string; 18 | 19 | /** 20 | * Creates an instance of Origin metadata. 21 | * @param moduleId The id of the module from which the item originated. 22 | * @param moduleMember The member name of the export on the module object from which the item originated. 23 | */ 24 | constructor(moduleId: string, moduleMember: string) { 25 | this.moduleId = moduleId; 26 | this.moduleMember = moduleMember; 27 | } 28 | 29 | /** 30 | * Get the Origin metadata for the specified function. 31 | * @param fn The function to inspect for Origin metadata. 32 | * @return Returns the Origin metadata. 33 | */ 34 | static get(fn: Function): Origin { 35 | let origin = originStorage.get(fn); 36 | 37 | if (origin === undefined) { 38 | PLATFORM.eachModule((key, value) => { 39 | if (typeof value === 'object') { 40 | const isBrowserWindow = typeof window !== 'undefined' && value === window; 41 | for (const name in value) { 42 | if (isBrowserWindow && name === 'webkitStorageInfo') { continue; } // Avoid warning to console 43 | try { 44 | const exp = value[name]; 45 | if (exp === fn) { 46 | originStorage.set(fn, origin = new Origin(key, name)); 47 | return true; 48 | } 49 | } catch (e) { 50 | // IE11 in cross origin frame fails when accessing Window['frameElement'] with Access Denied script error. 51 | // Window gets exported from webpack buildin/global.js. 52 | } 53 | } 54 | } 55 | 56 | if (value === fn) { 57 | originStorage.set(fn, origin = new Origin(key, 'default')); 58 | return true; 59 | } 60 | 61 | return false; 62 | }); 63 | } 64 | 65 | return origin || unknownOrigin; 66 | } 67 | 68 | /** 69 | * Set the Origin metadata for the specified function. 70 | * @param fn The function to set the Origin metadata on. 71 | * @param fn The Origin metadata to store on the function. 72 | * @return Returns the Origin metadata. 73 | */ 74 | static set(fn: Function, origin: Origin): void { 75 | originStorage.set(fn, origin); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/protocol.ts: -------------------------------------------------------------------------------- 1 | function alwaysValid() { return true; } 2 | function noCompose() {/* empty */} 3 | 4 | function ensureProtocolOptions(options): ProtocolOptions { 5 | if (options === undefined) { 6 | options = {}; 7 | } else if (typeof options === 'function') { 8 | options = { 9 | validate: options 10 | }; 11 | } 12 | 13 | if (!options.validate) { 14 | options.validate = alwaysValid; 15 | } 16 | 17 | if (!options.compose) { 18 | options.compose = noCompose; 19 | } 20 | 21 | return options; 22 | } 23 | 24 | function createProtocolValidator(validate) { 25 | return function(target) { 26 | const result = validate(target); 27 | return result === true; 28 | }; 29 | } 30 | 31 | function createProtocolAsserter(name, validate) { 32 | return function(target) { 33 | const result = validate(target); 34 | if (result !== true) { 35 | throw new Error(result || `${name} was not correctly implemented.`); 36 | } 37 | }; 38 | } 39 | 40 | /** 41 | * Options used during protocol creation. 42 | */ 43 | interface ProtocolOptions { 44 | /** 45 | * A function that will be run to validate the decorated class when the protocol is applied. It is also used to validate adhoc instances. 46 | * If the validation fails, a message should be returned which directs the developer in how to address the issue. 47 | */ 48 | validate?: (target: any) => string | boolean; 49 | /** 50 | * A function which has the opportunity to compose additional behavior into the decorated class when the protocol is applied. 51 | */ 52 | compose?: (target: any) => void; 53 | } 54 | 55 | /** 56 | * Decorator: Creates a protocol. 57 | * @param name The name of the protocol. 58 | * @param options The validation function or options object used in configuring the protocol. 59 | */ 60 | export function protocol(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): any { 61 | options = ensureProtocolOptions(options); 62 | 63 | const result = function(target) { 64 | const resolvedTarget = typeof target === 'function' 65 | ? target.prototype 66 | : target; 67 | 68 | (options as ProtocolOptions).compose(resolvedTarget); 69 | result.assert(resolvedTarget); 70 | 71 | Object.defineProperty(resolvedTarget, 'protocol:' + name, { 72 | enumerable: false, 73 | configurable: false, 74 | writable: false, 75 | value: true 76 | }); 77 | } as any; 78 | 79 | result.validate = createProtocolValidator((options as ProtocolOptions).validate); 80 | result.assert = createProtocolAsserter(name, (options as ProtocolOptions).validate); 81 | 82 | return result; 83 | } 84 | 85 | /** 86 | * Creates a protocol decorator. 87 | * @param name The name of the protocol. 88 | * @param options The validation function or options object used in configuring the protocol. 89 | * @return The protocol decorator; 90 | */ 91 | protocol.create = function(name: string, options?: ((target: any) => string | boolean) | ProtocolOptions): Function { 92 | options = ensureProtocolOptions(options); 93 | const hidden = 'protocol:' + name; 94 | const result = function(target) { 95 | const decorator = protocol(name, options); 96 | return target ? decorator(target) : decorator; 97 | } as any; 98 | 99 | result.decorates = function(obj) { return obj[hidden] === true; }; 100 | result.validate = createProtocolValidator(options.validate); 101 | result.assert = createProtocolAsserter(name, options.validate); 102 | 103 | return result as Function; 104 | }; 105 | -------------------------------------------------------------------------------- /test/metadata.spec.ts: -------------------------------------------------------------------------------- 1 | import './setup'; 2 | import { metadata } from '../src/metadata'; 3 | import { decorators } from '../src/decorators'; 4 | 5 | declare global { 6 | // eslint-disable-next-line 7 | namespace Reflect { 8 | const deleteMetadata: (...args: any[]) => void; 9 | } 10 | } 11 | 12 | describe('metadata', () => { 13 | it('can be located by key', () => { 14 | const found = metadata.getOwn(metadata.resource, HasMetadata); 15 | expect(found instanceof SampleMetadata).toBe(true); 16 | }); 17 | 18 | it('can be normalized to handle the fallback metadata location', () => { 19 | const found = metadata.getOwn(metadata.resource, HasFallbackMetadata); 20 | expect(found instanceof SampleMetadata).toBe(true); 21 | }); 22 | 23 | it('can override base metadata', () => { 24 | const found = metadata.getOwn(metadata.resource, OverridesMetadata) as typeof OverridesMetadata; 25 | expect(found.id).toBe(3); 26 | }); 27 | 28 | it('can inherit base metadata when searching deep by type', () => { 29 | const found = metadata.get(metadata.resource, DerivedWithBaseMetadata); 30 | expect(found instanceof SampleMetadata).toBe(true); 31 | }); 32 | 33 | it('attempting to access metadata of primitive targets returns undefined', () => { 34 | const metadataKey = 'fizz:bang'; 35 | const targets = [null, undefined, 'aurelia-dom-boundary', '', 0, 1, true, false]; 36 | let i = targets.length; 37 | while (i--) { 38 | const target = targets[i] as any; 39 | expect(metadata.get(metadataKey, target)).toBe(undefined); 40 | expect(metadata.getOwn(metadataKey, target)).toBe(undefined); 41 | } 42 | }); 43 | 44 | it('attempting to access metadata of object targets succeeds', () => { 45 | const metadataKey = 'fizz:bang'; 46 | const metadataValue = 'foo bar'; 47 | const targets = [function () {/* empty */}, {}, /*Object.create(null),*/ Object.prototype]; 48 | let i = targets.length; 49 | while (i--) { 50 | const target = targets[i] as any; 51 | 52 | expect(metadata.get(metadataKey, target)).toBe(undefined); 53 | expect(metadata.getOwn(metadataKey, target)).toBe(undefined); 54 | 55 | Reflect.defineMetadata(metadataKey, metadataValue, target); 56 | 57 | expect(metadata.get(metadataKey, target)).toBe(metadataValue); 58 | expect(metadata.getOwn(metadataKey, target)).toBe(metadataValue); 59 | 60 | if (Reflect.deleteMetadata) { 61 | Reflect.deleteMetadata(metadataKey, target); 62 | } else if (target.__metadata__) { 63 | delete target.__metadata__; 64 | } 65 | 66 | expect(metadata.get(metadataKey, target)).toBe(undefined); 67 | expect(metadata.getOwn(metadataKey, target)).toBe(undefined); 68 | } 69 | }); 70 | 71 | it('can be added with function', () => { 72 | class Annotated { } 73 | 74 | decorators(sampleES7Decorator()).on(Annotated); 75 | 76 | const found = metadata.getOwn(metadata.resource, Annotated); 77 | expect(found instanceof SampleMetadata).toBe(true); 78 | }); 79 | 80 | describe('when searching', () => { 81 | it('returns undefined if the input type is falsy', () => { 82 | expect(metadata.getOwn(metadata.resource, undefined)).toBe(undefined); 83 | expect(metadata.getOwn(metadata.resource, null)).toBe(undefined); 84 | }); 85 | 86 | it('returns undefined if no metadata is defined for the type', () => { 87 | const found = metadata.getOwn(metadata.resource, HasNoMetadata); 88 | expect(found).toBe(undefined); 89 | }); 90 | 91 | it('retruns the base metadata when serching deep if no metadata is defined for the type', () => { 92 | const found = metadata.get(metadata.resource, DerivedWithBaseMetadata); 93 | expect(found instanceof SampleMetadata).toBe(true); 94 | }); 95 | }); 96 | 97 | class SampleMetadata { 98 | constructor(public id) {} 99 | } 100 | 101 | function sampleES7Decorator(value?) { 102 | return function (target) { 103 | metadata.define(metadata.resource, new SampleMetadata(value), target); 104 | } 105 | } 106 | 107 | const HasMetadata = decorators(sampleES7Decorator()).on(class { }); 108 | const HasFallbackMetadata = decorators(sampleES7Decorator()).on(class { }); 109 | const HasOneMetadataInstance = decorators(sampleES7Decorator()).on(class { }); 110 | const OverridesMetadata = decorators(sampleES7Decorator(3)).on(class extends HasMetadata { }); 111 | 112 | class DerivedWithBaseMetadata extends HasMetadata { } 113 | metadata.define('another', 'foo', DerivedWithBaseMetadata); 114 | 115 | class HasNoMetadata { } 116 | class DerivedTypeWithNoMetadata extends HasMetadata { } 117 | }); 118 | -------------------------------------------------------------------------------- /test/mixin.spec.ts: -------------------------------------------------------------------------------- 1 | import './setup'; 2 | import {mixin} from '../src/mixin'; 3 | 4 | describe('mixin', () => { 5 | it('can add methods to a class', () => { 6 | const instance = new TargetClass() as TargetClass & typeof sourceMixin; 7 | expect(typeof instance.testMethod1).toBe('function'); 8 | expect(typeof instance.testMethod2).toBe('function'); 9 | expect(typeof instance.testMethod3).toBe('function'); 10 | }); 11 | 12 | it('can add properties to a class', () => { 13 | const instance = new TargetClass() as TargetClass & typeof sourceMixin; 14 | expect(instance.name).toBe('aurelia'); 15 | 16 | instance.name = 'framework'; 17 | expect(instance.name).toBe('framework'); 18 | }); 19 | 20 | const sourceMixin = { 21 | testMethod1() {/* empty */}, 22 | testMethod2() {/* empty */}, 23 | testMethod3() {/* empty */}, 24 | name: 'aurelia' 25 | }; 26 | 27 | @mixin(sourceMixin) 28 | class TargetClass {} 29 | }); 30 | -------------------------------------------------------------------------------- /test/origin.spec.ts: -------------------------------------------------------------------------------- 1 | import './setup'; 2 | import {Origin} from '../src/origin'; 3 | import {PLATFORM} from 'aurelia-pal'; 4 | 5 | describe('origin', () => { 6 | let origin1; 7 | let origin2; 8 | 9 | beforeEach(() => { 10 | origin1 = new Origin('ModuleId1', 'ModuleMember1'); 11 | origin2 = new Origin('ModuleId2', 'ModuleMember2'); 12 | }); 13 | 14 | describe('get', () => { 15 | it('should return an empty origin if not set', () => { 16 | class HasNoOrigin {} 17 | expect(Origin.get(HasNoOrigin).moduleId).toBe(undefined); 18 | }); 19 | 20 | it('should return the origin if set', () => { 21 | class HasOrigin {} 22 | Origin.set(HasOrigin, origin1); 23 | 24 | expect(Origin.get(HasOrigin)).toBe(origin1); 25 | }); 26 | }); 27 | 28 | describe('get - search modules', () => { 29 | let modules = undefined; 30 | beforeEach(()=> { 31 | modules = {'text-file': 'abcdef', 'real-module':{name: 'test', x() { return 'hey' }}}; 32 | spyOn(PLATFORM, 'eachModule').and.callFake((callback) => { 33 | for (const key in modules) callback(key, modules[key]); 34 | }); 35 | }); 36 | 37 | it('should search modules when called', () => { 38 | class Test {} 39 | expect(Origin.get(Test).moduleId).toBe(undefined); 40 | expect(PLATFORM.eachModule).toHaveBeenCalled(); 41 | }); 42 | 43 | it('should find member of loaded module', () => { 44 | const origin = Origin.get(modules['real-module']['x']); 45 | expect(origin.moduleId).toBe('real-module'); 46 | }); 47 | 48 | it('but it should not search in strings', () => { 49 | expect(Origin.get('a' as any).moduleId).toBe(undefined); 50 | }); 51 | 52 | it('should not fail on accessing restricted/failing members', () => { 53 | Object.defineProperty(modules['real-module'], 'restricted1', { get: () => { throw new Error('restricted') }, enumerable: true }); 54 | class Test {} 55 | expect(Origin.get(Test).moduleId).toBe(undefined); 56 | expect(PLATFORM.eachModule).toHaveBeenCalled(); 57 | }); 58 | }); 59 | 60 | describe('set', () => { 61 | it('should attach an origin if one does not exist', () => { 62 | class HasNoOrigin {} 63 | Origin.set(HasNoOrigin, origin2); 64 | 65 | expect(Origin.get(HasNoOrigin)).toBe(origin2); 66 | }); 67 | }); 68 | }); 69 | -------------------------------------------------------------------------------- /test/setup.ts: -------------------------------------------------------------------------------- 1 | import 'aurelia-polyfills'; -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015", 4 | "module": "es2015", 5 | "experimentalDecorators": true, 6 | "emitDecoratorMetadata": false, 7 | "moduleResolution": "node", 8 | "stripInternal": true, 9 | "preserveConstEnums": true, 10 | "lib": ["es2015", "dom"] 11 | }, 12 | "exclude": [ 13 | "node_modules", 14 | "dist", 15 | "build", 16 | "doc", 17 | "test", 18 | "config.js", 19 | "gulpfile.js", 20 | "karma.conf.js" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aurelia-metadata", 3 | "main": "dist/types/aurelia-metadata.d.ts", 4 | "dependencies": { 5 | "aurelia-pal": "github:aurelia/pal" 6 | } 7 | } 8 | --------------------------------------------------------------------------------