Commit ae9a2e48 authored by Rasmus Bengtsson's avatar Rasmus Bengtsson
Browse files

added basic scaffolding

parent f458ab81
......@@ -9,6 +9,7 @@
"@typeit/discord@^5.0.13",
"@types/node@^16.9.1",
"discord.js@^13.1.0",
"reflect-metadata@^0.1.13",
"tslib@^2.3.1",
"typescript@^4.4.3"
],
......@@ -47,6 +48,7 @@
"once@^1.3.0": "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1",
"ow@^0.27.0": "https://registry.yarnpkg.com/ow/-/ow-0.27.0.tgz#d44da088e8184fa11de64b5813206f9f86ab68d0",
"path-is-absolute@^1.0.0": "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f",
"reflect-metadata@^0.1.13": "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08",
"ts-mixer@^6.0.0": "https://registry.yarnpkg.com/ts-mixer/-/ts-mixer-6.0.0.tgz#4e631d3a36e3fa9521b973b132e8353bc7267f9f",
"tslib@^2.3.0": "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01",
"tslib@^2.3.1": "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01",
......
reflect-metadata is authored by:
* Cy Brown
* Oleh Dokuka
* Ron Buckton
* William Buchwalter
\ No newline at end of file
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
You must give any other recipients of the Work or Derivative Works a copy of this License; and
You must cause any modified files to carry prominent notices stating that You changed the files; and
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
\ No newline at end of file
# Metadata Reflection API
* [Detailed proposal][Metadata-Spec]
## Installation
```
npm install reflect-metadata
```
## Background
* Decorators add the ability to augment a class and its members as the class is defined, through a declarative syntax.
* Traceur attaches annotations to a static property on the class.
* Languages like C# (.NET), and Java support attributes or annotations that add metadata to types, along with a reflective API for reading metadata.
## Goals
* A number of use cases (Composition/Dependency Injection, Runtime Type Assertions, Reflection/Mirroring, Testing) want the ability to add additional metadata to a class in a consistent manner.
* A consistent approach is needed for various tools and libraries to be able to reason over metadata.
* Metadata-producing decorators (nee. "Annotations") need to be generally composable with mutating decorators.
* Metadata should be available not only on an object but also through a Proxy, with related traps.
* Defining new metadata-producing decorators should not be arduous or over-complex for a developer.
* Metadata should be consistent with other language and runtime features of ECMAScript.
## Syntax
* Declarative definition of metadata:
```JavaScript
class C {
@Reflect.metadata(metadataKey, metadataValue)
method() {
}
}
```
* Imperative definition of metadata:
```JavaScript
Reflect.defineMetadata(metadataKey, metadataValue, C.prototype, "method");
```
* Imperative introspection of metadata:
```JavaScript
let obj = new C();
let metadataValue = Reflect.getMetadata(metadataKey, obj, "method");
```
## Semantics
* Object has a new \[\[Metadata\]\] internal property that will contain a Map whose keys are property keys (or **undefined**) and whose values are Maps of metadata keys to metadata values.
* Object will have a number of new internal methods for \[\[DefineOwnMetadata\]\], \[\[GetOwnMetadata\]\], \[\[HasOwnMetadata\]\], etc.
* These internal methods can be overridden by a Proxy to support additional traps.
* These internal methods will by default call a set of abstract operations to define and read metadata.
* The Reflect object will expose the MOP operations to allow imperative access to metadata.
* Metadata defined on class declaration *C* is stored in *C*.\[\[Metadata\]\], with **undefined** as the key.
* Metadata defined on static members of class declaration *C* are stored in *C*.\[\[Metadata\]\], with the property key as the key.
* Metadata defined on instance members of class declaration *C* are stored in *C*.prototype.\[\[Metadata\]\], with the property key as the key.
## API
```JavaScript
// define metadata on an object or property
Reflect.defineMetadata(metadataKey, metadataValue, target);
Reflect.defineMetadata(metadataKey, metadataValue, target, propertyKey);
// check for presence of a metadata key on the prototype chain of an object or property
let result = Reflect.hasMetadata(metadataKey, target);
let result = Reflect.hasMetadata(metadataKey, target, propertyKey);
// check for presence of an own metadata key of an object or property
let result = Reflect.hasOwnMetadata(metadataKey, target);
let result = Reflect.hasOwnMetadata(metadataKey, target, propertyKey);
// get metadata value of a metadata key on the prototype chain of an object or property
let result = Reflect.getMetadata(metadataKey, target);
let result = Reflect.getMetadata(metadataKey, target, propertyKey);
// get metadata value of an own metadata key of an object or property
let result = Reflect.getOwnMetadata(metadataKey, target);
let result = Reflect.getOwnMetadata(metadataKey, target, propertyKey);
// get all metadata keys on the prototype chain of an object or property
let result = Reflect.getMetadataKeys(target);
let result = Reflect.getMetadataKeys(target, propertyKey);
// get all own metadata keys of an object or property
let result = Reflect.getOwnMetadataKeys(target);
let result = Reflect.getOwnMetadataKeys(target, propertyKey);
// delete metadata from an object or property
let result = Reflect.deleteMetadata(metadataKey, target);
let result = Reflect.deleteMetadata(metadataKey, target, propertyKey);
// apply metadata via a decorator to a constructor
@Reflect.metadata(metadataKey, metadataValue)
class C {
// apply metadata via a decorator to a method (property)
@Reflect.metadata(metadataKey, metadataValue)
method() {
}
}
```
## Alternatives
* Use properties rather than a separate API.
* Obvious downside is that this can be a lot of code:
```JavaScript
function ParamTypes(...types) {
return (target, propertyKey) => {
const symParamTypes = Symbol.for("design:paramtypes");
if (propertyKey === undefined) {
target[symParamTypes] = types;
}
else {
const symProperties = Symbol.for("design:properties");
let properties, property;
if (Object.prototype.hasOwnProperty.call(target, symProperties)) {
properties = target[symProperties];
}
else {
properties = target[symProperties] = {};
}
if (Object.prototype.hasOwnProperty.call(properties, propertyKey)) {
property = properties[propertyKey];
}
else {
property = properties[propertyKey] = {};
}
property[symParamTypes] = types;
}
};
}
```
## Notes
* Though it may seem counterintuitive, the methods on Reflect place the parameters for the metadata key and metadata value before the target or property key. This is due to the fact that the property key is the only optional parameter in the argument list. This also makes the methods easier to curry with Function#bind. This also helps reduce the overall footprint and complexity of a metadata-producing decorator that could target both a class or a property:
```JavaScript
function ParamTypes(...types) {
// as propertyKey is effectively optional, its easier to use here
return (target, propertyKey) => { Reflect.defineMetadata("design:paramtypes", types, target, propertyKey); }
// vs. having multiple overloads with the target and key in the front:
//
// return (target, propertyKey) => {
// if (propertyKey === undefined) {
// Reflect.defineMetadata(target, "design:paramtypes", types);
// }
// else {
// Reflect.defineMetadata(target, propertyKey, "design:paramtypes", types);
// }
// }
//
// vs. having a different methods for the class or a property:
//
// return (target, propertyKey) => {
// if (propertyKey === undefined) {
// Reflect.defineMetadata(target, "design:paramtypes", types);
// }
// else {
// Reflect.definePropertyMetadata(target, propertyKey, "design:paramtypes", types);
// }
// }
}
```
* To enable experimental support for metadata decorators in your TypeScript project, you must add `"experimentalDecorators": true` to your tsconfig.json file.
* To enable experimental support for auto-generated type metadata in your TypeScript project, you must add `"emitDecoratorMetadata": true` to your tsconfig.json file.
* Please note that auto-generated type metadata may have issues with circular or forward references for types.
## Issues
* A poorly written mutating decorator for a class constructor could cause metadata to become lost if the prototype chain is not maintained. Though, not maintaining the prototype chain in a mutating decorator for a class constructor would have other negative side effects as well. @rbuckton
* This is mitigated if the mutating decorator returns a class expression that extends from the target, or returns a proxy for the decorator. @rbuckton
* Metadata for a method is attached to the class (or prototype) via the property key. It would not then be available if trying to read metadata on the function of the method (e.g. "tearing-off" the method from the class). @rbuckton
[Metadata-Spec]: https://rbuckton.github.io/reflect-metadata
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
body {
display: flex;
font-size: 18px;
line-height: 1.5;
font-family: Cambria, Palatino Linotype, Palatino, Liberation Serif, serif;
padding: 0;
margin: 0;
color: #111;
}
#spec-container {
padding: 0 20px;
flex-grow: 1;
flex-basis: 66%;
box-sizing: border-box;
overflow: hidden;
}
body.oldtoc {
margin: 0 auto;
}
a {
text-decoration: none;
color: #206ca7;
}
a:visited {
color: #206ca7;
}
a:hover {
text-decoration: underline;
color: #239dee;
}
code {
font-weight: bold;
font-family: Consolas, Monaco, monospace;
white-space: pre;
}
pre code {
font-weight: inherit;
}
pre code.hljs {
background-color: #fff;
margin: 0;
padding: 0;
}
ol.toc {
list-style: none;
padding-left: 0;
}
ol.toc ol.toc {
padding-left: 2ex;
list-style: none;
}
var {
color: #2aa198;
transition: background-color 0.25s ease;
cursor: pointer;
}
var.referenced {
background-color: #ffff33;
}
emu-const {
font-family: sans-serif;
}
emu-val {
font-weight: bold;
}
emu-alg ol, emu-alg ol ol ol ol {
list-style-type: decimal;
}
emu-alg ol ol, emu-alg ol ol ol ol ol {
list-style-type: lower-alpha;
}
emu-alg ol ol ol, ol ol ol ol ol ol {
list-style-type: lower-roman;
}
emu-eqn {
display: block;
margin-left: 4em;
}
emu-eqn.inline {
display: inline;
margin: 0;
}
emu-eqn div:first-child {
margin-left: -2em;
}
emu-note {
margin: 1em 0;
color: #666;
border-left: 5px solid #ccc;
display: flex;
flex-direction: row;
}
emu-note > span.note {
flex-basis: 100px;
min-width: 100px;
flex-grow: 0;
flex-shrink: 1;
text-transform: uppercase;
padding-left: 5px;
}
emu-note[type=editor] {
border-left-color: #faa;
}
emu-note > div.note-contents {
flex-grow: 1;
flex-shrink: 1;
}
emu-note > div.note-contents > p:first-of-type {
margin-top: 0;
}
emu-note > div.note-contents > p:last-of-type {
margin-bottom: 0;
}
emu-figure {
display: block;
}
emu-example {
display: block;
margin: 1em 3em;
}
emu-example figure figcaption {
margin-top: 0.5em;
text-align: left;
}
emu-figure figure,
emu-example figure,
emu-table figure {
display: flex;
flex-direction: column;
align-items: center;
}
emu-production {
display: block;
margin-top: 1em;
margin-bottom: 1em;
margin-left: 5ex;
}
emu-grammar.inline, emu-production.inline,
emu-grammar.inline emu-production emu-rhs, emu-production.inline emu-rhs,
emu-grammar[collapsed] emu-production emu-rhs, emu-production[collapsed] emu-rhs {
display: inline;
padding-left: 1ex;
margin-left: 0;
}
emu-grammar[collapsed] emu-production, emu-production[collapsed] {
margin: 0;
}
emu-constraints {
font-size: .75em;
margin-right: 1ex;
}
emu-gann {
margin-right: 1ex;
}
emu-gann emu-t:last-child,
emu-gann emu-nt:last-child {
margin-right: 0;
}
emu-geq {
margin-left: 1ex;
font-weight: bold;
}
emu-oneof {
font-weight: bold;
margin-left: 1ex;
}
emu-nt {
display: inline-block;
font-style: italic;
white-space: nowrap;
text-indent: 0;
}
emu-nt a, emu-nt a:visited {
color: #333;
}
emu-rhs emu-nt {
margin-right: 1ex;
}
emu-t {
display: inline-block;
font-family: monospace;
font-weight: bold;
white-space: nowrap;
text-indent: 0;
}
emu-production emu-t {
margin-right: 1ex;
}
emu-rhs {
display: block;
padding-left: 75px;
text-indent: -25px;
}
emu-mods {
font-size: .85em;
vertical-align: sub;
font-style: normal;
font-weight: normal;
}
emu-production[collapsed] emu-mods {
display: none;
}
emu-params, emu-opt {
margin-right: 1ex;
font-family: monospace;
}
emu-params, emu-constraints {
color: #2aa198;
}
emu-opt {
color: #b58900;
}
emu-gprose {
font-size: 0.9em;
font-family: Helvetica, Arial, sans-serif;
}
h1.shortname {
color: #f60;
font-size: 1.5em;
margin: 0;
}
h1.version {
color: #f60;
font-size: 1.5em;
margin: 0;
}
h1.title {
margin-top: 0;
color: #f60;
}
h1.first {
margin-top: 0;
}
h1, h2, h3, h4, h5, h6 {
position: relative;
}
h1 .secnum {
text-decoration: none;
margin-right: 10px;
}
h1 span.title {
order: 2;
}
h1 { font-size: 2.67em; margin-top: 2em; margin-bottom: 0; line-height: 1em;}
h2 { font-size: 2em; }
h3 { font-size: 1.56em; }
h4 { font-size: 1.25em; }
h5 { font-size: 1.11em; }
h6 { font-size: 1em; }
h1:hover span.utils {
display: block;
}
span.utils {
font-size: 18px;
line-height: 18px;
display: none;
position: absolute;
top: 100%;
left: 0;
right: 0;
font-weight: normal;
}
span.utils:before {
content: "⤷";
display: inline-block;
padding