@aurelia/metadata
Advanced tools
Comparing version 0.7.0-dev.202004290437 to 0.7.0-dev.202005080323
@@ -0,6 +1,63 @@ | ||
/** | ||
* Determine whether a value is an object. | ||
* | ||
* Uses `typeof` to guarantee this works cross-realm, which is where `instanceof Object` might fail. | ||
* | ||
* Some environments where these issues are known to arise: | ||
* - same-origin iframes (accessing the other realm via `window.top`) | ||
* - `jest`. | ||
* | ||
* The exact test is: | ||
* ```ts | ||
* typeof value === 'object' && value !== null || typeof value === 'function' | ||
* ``` | ||
* | ||
* @param value - The value to test. | ||
* @returns `true` if the value is an object, otherwise `false`. | ||
* Also performs a type assertion that defaults to `value is Object | Function` which, if the input type is a union with an object type, will infer the correct type. | ||
* This can be overridden with the generic type argument. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* class Foo { | ||
* bar = 42; | ||
* } | ||
* | ||
* function doStuff(input?: Foo | null) { | ||
* input.bar; // Object is possibly 'null' or 'undefined' | ||
* | ||
* // input has an object type in its union (Foo) so that type will be extracted for the 'true' condition | ||
* if (isObject(input)) { | ||
* input.bar; // OK (input is now typed as Foo) | ||
* } | ||
* } | ||
* | ||
* function doOtherStuff(input: unknown) { | ||
* input.bar; // Object is of type 'unknown' | ||
* | ||
* // input is 'unknown' so there is no union type to match and it will default to 'Object | Function' | ||
* if (isObject(input)) { | ||
* input.bar; // Property 'bar' does not exist on type 'Object | Function' | ||
* } | ||
* | ||
* // if we know for sure that, if input is an object, it must be a specific type, we can explicitly tell the function to assert that for us | ||
* if (isObject<Foo>(input)) { | ||
* input.bar; // OK (input is now typed as Foo) | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
function isObject(value) { | ||
export function isObject(value) { | ||
return typeof value === 'object' && value !== null || typeof value === 'function'; | ||
} | ||
function isNullOrUndefined(value) { | ||
/** | ||
* Determine whether a value is `null` or `undefined`. | ||
* | ||
* @param value - The value to test. | ||
* @returns `true` if the value is `null` or `undefined`, otherwise `false`. | ||
* Also performs a type assertion that ensures TypeScript treats the value appropriately in the `if` and `else` branches after this check. | ||
*/ | ||
export function isNullOrUndefined(value) { | ||
return value === null || value === void 0; | ||
@@ -272,3 +329,3 @@ } | ||
*/ | ||
function metadata(metadataKey, metadataValue) { | ||
export function metadata(metadataKey, metadataValue) { | ||
function decorator(target, propertyKey) { | ||
@@ -407,3 +464,3 @@ // 1. Assert: F has a [[MetadataKey]] internal slot whose value is an ECMAScript language value, or undefined. | ||
} | ||
const Metadata = { | ||
export const Metadata = { | ||
define: $define, | ||
@@ -426,72 +483,37 @@ has: $has, | ||
} | ||
def(Metadata, '$Internal', metadataInternalSlot); | ||
const hasMetadata = 'metadata' in Reflect; | ||
const hasDecorate = 'decorate' in Reflect; | ||
const hasDefineMetadata = 'defineMetadata' in Reflect; | ||
const hasHasMetadata = 'hasMetadata' in Reflect; | ||
const hasHasOwnMetadata = 'hasOwnMetadata' in Reflect; | ||
const hasGetMetadata = 'getMetadata' in Reflect; | ||
const hasGetOwnMetadata = 'getOwnMetadata' in Reflect; | ||
const hasGetMetadataKeys = 'getMetadataKeys' in Reflect; | ||
const hasGetOwnMetadataKeys = 'getOwnMetadataKeys' in Reflect; | ||
const hasDeleteMetadata = 'deleteMetadata' in Reflect; | ||
const hasSome = (hasMetadata || | ||
hasDecorate || | ||
hasDefineMetadata || | ||
hasHasMetadata || | ||
hasHasOwnMetadata || | ||
hasGetMetadata || | ||
hasGetOwnMetadata || | ||
hasGetMetadataKeys || | ||
hasGetOwnMetadataKeys || | ||
hasDeleteMetadata); | ||
const hasAll = (hasMetadata && | ||
hasDecorate && | ||
hasDefineMetadata && | ||
hasHasMetadata && | ||
hasHasOwnMetadata && | ||
hasGetMetadata && | ||
hasGetOwnMetadata && | ||
hasGetMetadataKeys && | ||
hasGetOwnMetadataKeys && | ||
hasDeleteMetadata); | ||
if (hasSome && !hasAll) { | ||
// This is temporary until we have the reporter / logging component working properly. | ||
// We should kind of throw here, but it's a bit harsh to completely stop Aurelia from loading for something that's not guaranteed to fail, | ||
// so just log a warning instead. | ||
/* eslint-disable no-console, no-undef, @typescript-eslint/ban-ts-ignore */ | ||
// @ts-ignore | ||
console.warn('Partial existing Reflect.metadata polyfill found. Working environment cannot be guaranteed. Please file an issue at https://github.com/aurelia/aurelia/issues so that we can look into compatibility options for this scenario.'); | ||
const internalSlotName = '[[$au]]'; | ||
function hasInternalSlot(reflect) { | ||
return internalSlotName in reflect; | ||
} | ||
if (!hasMetadata) { | ||
def(Reflect, 'metadata', metadata); | ||
export function applyMetadataPolyfill(reflect) { | ||
if (hasInternalSlot(reflect)) { | ||
if (reflect[internalSlotName] === metadataInternalSlot) { | ||
return; | ||
} | ||
throw new Error(`Conflicting @aurelia/metadata module import detected. Please make sure you have the same version of all Aurelia packages in your dependency tree.`); | ||
} | ||
if ('metadata' in reflect || | ||
'decorate' in reflect || | ||
'defineMetadata' in reflect || | ||
'hasMetadata' in reflect || | ||
'hasOwnMetadata' in reflect || | ||
'getMetadata' in reflect || | ||
'getOwnMetadata' in reflect || | ||
'getMetadataKeys' in reflect || | ||
'getOwnMetadataKeys' in reflect || | ||
'deleteMetadata' in reflect) { | ||
throw new Error(`Conflicting reflect.metadata polyfill found. If you have 'reflect-metadata' or any other reflect polyfill imported, please remove it, if not (or if you must use a specific polyfill) please file an issue at https://github.com/aurelia/aurelia/issues so that we can look into compatibility options for this scenario.`); | ||
} | ||
def(Metadata, '$Internal', metadataInternalSlot); | ||
def(reflect, 'metadata', metadata); | ||
def(reflect, 'decorate', decorate); | ||
def(reflect, 'defineMetadata', $define); | ||
def(reflect, 'hasMetadata', $has); | ||
def(reflect, 'hasOwnMetadata', $hasOwn); | ||
def(reflect, 'getMetadata', $get); | ||
def(reflect, 'getOwnMetadata', $getOwn); | ||
def(reflect, 'getMetadataKeys', $getKeys); | ||
def(reflect, 'getOwnMetadataKeys', $getOwnKeys); | ||
def(reflect, 'deleteMetadata', $delete); | ||
} | ||
if (!hasDecorate) { | ||
def(Reflect, 'decorate', decorate); | ||
} | ||
if (!hasDefineMetadata) { | ||
def(Reflect, 'defineMetadata', $define); | ||
} | ||
if (!hasHasMetadata) { | ||
def(Reflect, 'hasMetadata', $has); | ||
} | ||
if (!hasHasOwnMetadata) { | ||
def(Reflect, 'hasOwnMetadata', $hasOwn); | ||
} | ||
if (!hasGetMetadata) { | ||
def(Reflect, 'getMetadata', $get); | ||
} | ||
if (!hasGetOwnMetadata) { | ||
def(Reflect, 'getOwnMetadata', $getOwn); | ||
} | ||
if (!hasGetMetadataKeys) { | ||
def(Reflect, 'getMetadataKeys', $getKeys); | ||
} | ||
if (!hasGetOwnMetadataKeys) { | ||
def(Reflect, 'getOwnMetadataKeys', $getOwnKeys); | ||
} | ||
if (!hasDeleteMetadata) { | ||
def(Reflect, 'deleteMetadata', $delete); | ||
} | ||
export { Metadata, metadata }; | ||
//# sourceMappingURL=index.js.map |
/** | ||
* Determine whether a value is an object. | ||
* | ||
* Uses `typeof` to guarantee this works cross-realm, which is where `instanceof Object` might fail. | ||
* | ||
* Some environments where these issues are known to arise: | ||
* - same-origin iframes (accessing the other realm via `window.top`) | ||
* - `jest`. | ||
* | ||
* The exact test is: | ||
* ```ts | ||
* typeof value === 'object' && value !== null || typeof value === 'function' | ||
* ``` | ||
* | ||
* @param value - The value to test. | ||
* @returns `true` if the value is an object, otherwise `false`. | ||
* Also performs a type assertion that defaults to `value is Object | Function` which, if the input type is a union with an object type, will infer the correct type. | ||
* This can be overridden with the generic type argument. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* class Foo { | ||
* bar = 42; | ||
* } | ||
* | ||
* function doStuff(input?: Foo | null) { | ||
* input.bar; // Object is possibly 'null' or 'undefined' | ||
* | ||
* // input has an object type in its union (Foo) so that type will be extracted for the 'true' condition | ||
* if (isObject(input)) { | ||
* input.bar; // OK (input is now typed as Foo) | ||
* } | ||
* } | ||
* | ||
* function doOtherStuff(input: unknown) { | ||
* input.bar; // Object is of type 'unknown' | ||
* | ||
* // input is 'unknown' so there is no union type to match and it will default to 'Object | Function' | ||
* if (isObject(input)) { | ||
* input.bar; // Property 'bar' does not exist on type 'Object | Function' | ||
* } | ||
* | ||
* // if we know for sure that, if input is an object, it must be a specific type, we can explicitly tell the function to assert that for us | ||
* if (isObject<Foo>(input)) { | ||
* input.bar; // OK (input is now typed as Foo) | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
export declare function isObject<T extends object = Object | Function>(value: unknown): value is T; | ||
/** | ||
* Determine whether a value is `null` or `undefined`. | ||
* | ||
* @param value - The value to test. | ||
* @returns `true` if the value is `null` or `undefined`, otherwise `false`. | ||
* Also performs a type assertion that ensures TypeScript treats the value appropriately in the `if` and `else` branches after this check. | ||
*/ | ||
export declare function isNullOrUndefined(value: unknown): value is null | undefined; | ||
/** | ||
* A default metadata decorator factory that can be used on a class, class member, or parameter. | ||
@@ -10,3 +69,3 @@ * | ||
*/ | ||
declare function metadata(metadataKey: any, metadataValue: any): { | ||
export declare function metadata(metadataKey: any, metadataValue: any): { | ||
(target: Function): void; | ||
@@ -405,3 +464,3 @@ (target: any, propertyKey: string | symbol): void; | ||
declare function $delete(metadataKey: any, target: any, propertyKey: string | symbol): boolean; | ||
declare const Metadata: { | ||
export declare const Metadata: { | ||
define: typeof $define; | ||
@@ -416,3 +475,4 @@ has: typeof $has; | ||
}; | ||
export { Metadata, metadata }; | ||
export declare function applyMetadataPolyfill(reflect: typeof Reflect): void; | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -12,2 +12,52 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Determine whether a value is an object. | ||
* | ||
* Uses `typeof` to guarantee this works cross-realm, which is where `instanceof Object` might fail. | ||
* | ||
* Some environments where these issues are known to arise: | ||
* - same-origin iframes (accessing the other realm via `window.top`) | ||
* - `jest`. | ||
* | ||
* The exact test is: | ||
* ```ts | ||
* typeof value === 'object' && value !== null || typeof value === 'function' | ||
* ``` | ||
* | ||
* @param value - The value to test. | ||
* @returns `true` if the value is an object, otherwise `false`. | ||
* Also performs a type assertion that defaults to `value is Object | Function` which, if the input type is a union with an object type, will infer the correct type. | ||
* This can be overridden with the generic type argument. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* class Foo { | ||
* bar = 42; | ||
* } | ||
* | ||
* function doStuff(input?: Foo | null) { | ||
* input.bar; // Object is possibly 'null' or 'undefined' | ||
* | ||
* // input has an object type in its union (Foo) so that type will be extracted for the 'true' condition | ||
* if (isObject(input)) { | ||
* input.bar; // OK (input is now typed as Foo) | ||
* } | ||
* } | ||
* | ||
* function doOtherStuff(input: unknown) { | ||
* input.bar; // Object is of type 'unknown' | ||
* | ||
* // input is 'unknown' so there is no union type to match and it will default to 'Object | Function' | ||
* if (isObject(input)) { | ||
* input.bar; // Property 'bar' does not exist on type 'Object | Function' | ||
* } | ||
* | ||
* // if we know for sure that, if input is an object, it must be a specific type, we can explicitly tell the function to assert that for us | ||
* if (isObject<Foo>(input)) { | ||
* input.bar; // OK (input is now typed as Foo) | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
@@ -17,5 +67,14 @@ function isObject(value) { | ||
} | ||
exports.isObject = isObject; | ||
/** | ||
* Determine whether a value is `null` or `undefined`. | ||
* | ||
* @param value - The value to test. | ||
* @returns `true` if the value is `null` or `undefined`, otherwise `false`. | ||
* Also performs a type assertion that ensures TypeScript treats the value appropriately in the `if` and `else` branches after this check. | ||
*/ | ||
function isNullOrUndefined(value) { | ||
return value === null || value === void 0; | ||
} | ||
exports.isNullOrUndefined = isNullOrUndefined; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
@@ -420,3 +479,3 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
} | ||
const Metadata = { | ||
exports.Metadata = { | ||
define: $define, | ||
@@ -431,3 +490,2 @@ has: $has, | ||
}; | ||
exports.Metadata = Metadata; | ||
function def(obj, key, value) { | ||
@@ -441,72 +499,39 @@ Reflect.defineProperty(obj, key, { | ||
} | ||
def(Metadata, '$Internal', metadataInternalSlot); | ||
const hasMetadata = 'metadata' in Reflect; | ||
const hasDecorate = 'decorate' in Reflect; | ||
const hasDefineMetadata = 'defineMetadata' in Reflect; | ||
const hasHasMetadata = 'hasMetadata' in Reflect; | ||
const hasHasOwnMetadata = 'hasOwnMetadata' in Reflect; | ||
const hasGetMetadata = 'getMetadata' in Reflect; | ||
const hasGetOwnMetadata = 'getOwnMetadata' in Reflect; | ||
const hasGetMetadataKeys = 'getMetadataKeys' in Reflect; | ||
const hasGetOwnMetadataKeys = 'getOwnMetadataKeys' in Reflect; | ||
const hasDeleteMetadata = 'deleteMetadata' in Reflect; | ||
const hasSome = (hasMetadata || | ||
hasDecorate || | ||
hasDefineMetadata || | ||
hasHasMetadata || | ||
hasHasOwnMetadata || | ||
hasGetMetadata || | ||
hasGetOwnMetadata || | ||
hasGetMetadataKeys || | ||
hasGetOwnMetadataKeys || | ||
hasDeleteMetadata); | ||
const hasAll = (hasMetadata && | ||
hasDecorate && | ||
hasDefineMetadata && | ||
hasHasMetadata && | ||
hasHasOwnMetadata && | ||
hasGetMetadata && | ||
hasGetOwnMetadata && | ||
hasGetMetadataKeys && | ||
hasGetOwnMetadataKeys && | ||
hasDeleteMetadata); | ||
if (hasSome && !hasAll) { | ||
// This is temporary until we have the reporter / logging component working properly. | ||
// We should kind of throw here, but it's a bit harsh to completely stop Aurelia from loading for something that's not guaranteed to fail, | ||
// so just log a warning instead. | ||
/* eslint-disable no-console, no-undef, @typescript-eslint/ban-ts-ignore */ | ||
// @ts-ignore | ||
console.warn('Partial existing Reflect.metadata polyfill found. Working environment cannot be guaranteed. Please file an issue at https://github.com/aurelia/aurelia/issues so that we can look into compatibility options for this scenario.'); | ||
const internalSlotName = '[[$au]]'; | ||
function hasInternalSlot(reflect) { | ||
return internalSlotName in reflect; | ||
} | ||
if (!hasMetadata) { | ||
def(Reflect, 'metadata', metadata); | ||
function applyMetadataPolyfill(reflect) { | ||
if (hasInternalSlot(reflect)) { | ||
if (reflect[internalSlotName] === metadataInternalSlot) { | ||
return; | ||
} | ||
throw new Error(`Conflicting @aurelia/metadata module import detected. Please make sure you have the same version of all Aurelia packages in your dependency tree.`); | ||
} | ||
if ('metadata' in reflect || | ||
'decorate' in reflect || | ||
'defineMetadata' in reflect || | ||
'hasMetadata' in reflect || | ||
'hasOwnMetadata' in reflect || | ||
'getMetadata' in reflect || | ||
'getOwnMetadata' in reflect || | ||
'getMetadataKeys' in reflect || | ||
'getOwnMetadataKeys' in reflect || | ||
'deleteMetadata' in reflect) { | ||
throw new Error(`Conflicting reflect.metadata polyfill found. If you have 'reflect-metadata' or any other reflect polyfill imported, please remove it, if not (or if you must use a specific polyfill) please file an issue at https://github.com/aurelia/aurelia/issues so that we can look into compatibility options for this scenario.`); | ||
} | ||
def(exports.Metadata, '$Internal', metadataInternalSlot); | ||
def(reflect, 'metadata', metadata); | ||
def(reflect, 'decorate', decorate); | ||
def(reflect, 'defineMetadata', $define); | ||
def(reflect, 'hasMetadata', $has); | ||
def(reflect, 'hasOwnMetadata', $hasOwn); | ||
def(reflect, 'getMetadata', $get); | ||
def(reflect, 'getOwnMetadata', $getOwn); | ||
def(reflect, 'getMetadataKeys', $getKeys); | ||
def(reflect, 'getOwnMetadataKeys', $getOwnKeys); | ||
def(reflect, 'deleteMetadata', $delete); | ||
} | ||
if (!hasDecorate) { | ||
def(Reflect, 'decorate', decorate); | ||
} | ||
if (!hasDefineMetadata) { | ||
def(Reflect, 'defineMetadata', $define); | ||
} | ||
if (!hasHasMetadata) { | ||
def(Reflect, 'hasMetadata', $has); | ||
} | ||
if (!hasHasOwnMetadata) { | ||
def(Reflect, 'hasOwnMetadata', $hasOwn); | ||
} | ||
if (!hasGetMetadata) { | ||
def(Reflect, 'getMetadata', $get); | ||
} | ||
if (!hasGetOwnMetadata) { | ||
def(Reflect, 'getOwnMetadata', $getOwn); | ||
} | ||
if (!hasGetMetadataKeys) { | ||
def(Reflect, 'getMetadataKeys', $getKeys); | ||
} | ||
if (!hasGetOwnMetadataKeys) { | ||
def(Reflect, 'getOwnMetadataKeys', $getOwnKeys); | ||
} | ||
if (!hasDeleteMetadata) { | ||
def(Reflect, 'deleteMetadata', $delete); | ||
} | ||
exports.applyMetadataPolyfill = applyMetadataPolyfill; | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@aurelia/metadata", | ||
"version": "0.7.0-dev.202004290437", | ||
"version": "0.7.0-dev.202005080323", | ||
"main": "dist/umd/index.js", | ||
@@ -31,3 +31,2 @@ "module": "dist/esnext/index.js", | ||
"build": "tsc -b", | ||
"bundle": "ts-node -P ../../tsconfig.json ../../scripts/bundle.ts umd,esm,system metadata", | ||
"dev": "tsc -b -w --preserveWatchOutput" | ||
@@ -39,7 +38,5 @@ }, | ||
"devDependencies": { | ||
"reflect-metadata": "^0.1.13", | ||
"tslib": "^1.11.1", | ||
"typescript": "^3.8.3" | ||
}, | ||
"gitHead": "e8c670092c1e96d5d325be100b9221ef6bcaabb7" | ||
"gitHead": "67a7e3e4f8ee7694666523102cc4ce4f0eddf661" | ||
} |
176
src/index.ts
@@ -0,7 +1,64 @@ | ||
/** | ||
* Determine whether a value is an object. | ||
* | ||
* Uses `typeof` to guarantee this works cross-realm, which is where `instanceof Object` might fail. | ||
* | ||
* Some environments where these issues are known to arise: | ||
* - same-origin iframes (accessing the other realm via `window.top`) | ||
* - `jest`. | ||
* | ||
* The exact test is: | ||
* ```ts | ||
* typeof value === 'object' && value !== null || typeof value === 'function' | ||
* ``` | ||
* | ||
* @param value - The value to test. | ||
* @returns `true` if the value is an object, otherwise `false`. | ||
* Also performs a type assertion that defaults to `value is Object | Function` which, if the input type is a union with an object type, will infer the correct type. | ||
* This can be overridden with the generic type argument. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* class Foo { | ||
* bar = 42; | ||
* } | ||
* | ||
* function doStuff(input?: Foo | null) { | ||
* input.bar; // Object is possibly 'null' or 'undefined' | ||
* | ||
* // input has an object type in its union (Foo) so that type will be extracted for the 'true' condition | ||
* if (isObject(input)) { | ||
* input.bar; // OK (input is now typed as Foo) | ||
* } | ||
* } | ||
* | ||
* function doOtherStuff(input: unknown) { | ||
* input.bar; // Object is of type 'unknown' | ||
* | ||
* // input is 'unknown' so there is no union type to match and it will default to 'Object | Function' | ||
* if (isObject(input)) { | ||
* input.bar; // Property 'bar' does not exist on type 'Object | Function' | ||
* } | ||
* | ||
* // if we know for sure that, if input is an object, it must be a specific type, we can explicitly tell the function to assert that for us | ||
* if (isObject<Foo>(input)) { | ||
* input.bar; // OK (input is now typed as Foo) | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
function isObject<T extends object = Object | Function>(value: unknown): value is T { | ||
export function isObject<T extends object = Object | Function>(value: unknown): value is T { | ||
return typeof value === 'object' && value !== null || typeof value === 'function'; | ||
} | ||
function isNullOrUndefined(value: unknown): value is null | undefined { | ||
/** | ||
* Determine whether a value is `null` or `undefined`. | ||
* | ||
* @param value - The value to test. | ||
* @returns `true` if the value is `null` or `undefined`, otherwise `false`. | ||
* Also performs a type assertion that ensures TypeScript treats the value appropriately in the `if` and `else` branches after this check. | ||
*/ | ||
export function isNullOrUndefined(value: unknown): value is null | undefined { | ||
return value === null || value === void 0; | ||
@@ -354,3 +411,3 @@ } | ||
*/ | ||
function metadata(metadataKey: any, metadataValue: any) { | ||
export function metadata(metadataKey: any, metadataValue: any) { | ||
function decorator(target: Function): void; | ||
@@ -931,3 +988,3 @@ function decorator(target: any, propertyKey: string | symbol): void; | ||
const Metadata = { | ||
export const Metadata = { | ||
define: $define, | ||
@@ -952,79 +1009,42 @@ has: $has, | ||
def(Metadata, '$Internal', metadataInternalSlot); | ||
const internalSlotName = '[[$au]]'; | ||
function hasInternalSlot(reflect: typeof Reflect): reflect is typeof Reflect & { [internalSlotName]: typeof metadataInternalSlot } { | ||
return internalSlotName in reflect; | ||
} | ||
const hasMetadata = 'metadata' in Reflect; | ||
const hasDecorate = 'decorate' in Reflect; | ||
const hasDefineMetadata = 'defineMetadata' in Reflect; | ||
const hasHasMetadata = 'hasMetadata' in Reflect; | ||
const hasHasOwnMetadata = 'hasOwnMetadata' in Reflect; | ||
const hasGetMetadata = 'getMetadata' in Reflect; | ||
const hasGetOwnMetadata = 'getOwnMetadata' in Reflect; | ||
const hasGetMetadataKeys = 'getMetadataKeys' in Reflect; | ||
const hasGetOwnMetadataKeys = 'getOwnMetadataKeys' in Reflect; | ||
const hasDeleteMetadata = 'deleteMetadata' in Reflect; | ||
const hasSome = ( | ||
hasMetadata || | ||
hasDecorate || | ||
hasDefineMetadata || | ||
hasHasMetadata || | ||
hasHasOwnMetadata || | ||
hasGetMetadata || | ||
hasGetOwnMetadata || | ||
hasGetMetadataKeys || | ||
hasGetOwnMetadataKeys || | ||
hasDeleteMetadata | ||
); | ||
const hasAll = ( | ||
hasMetadata && | ||
hasDecorate && | ||
hasDefineMetadata && | ||
hasHasMetadata && | ||
hasHasOwnMetadata && | ||
hasGetMetadata && | ||
hasGetOwnMetadata && | ||
hasGetMetadataKeys && | ||
hasGetOwnMetadataKeys && | ||
hasDeleteMetadata | ||
); | ||
export function applyMetadataPolyfill(reflect: typeof Reflect): void { | ||
if (hasInternalSlot(reflect)) { | ||
if (reflect[internalSlotName] === metadataInternalSlot) { | ||
return; | ||
} | ||
throw new Error(`Conflicting @aurelia/metadata module import detected. Please make sure you have the same version of all Aurelia packages in your dependency tree.`); | ||
} | ||
if (hasSome && !hasAll) { | ||
// This is temporary until we have the reporter / logging component working properly. | ||
// We should kind of throw here, but it's a bit harsh to completely stop Aurelia from loading for something that's not guaranteed to fail, | ||
// so just log a warning instead. | ||
/* eslint-disable no-console, no-undef, @typescript-eslint/ban-ts-ignore */ | ||
// @ts-ignore | ||
console.warn('Partial existing Reflect.metadata polyfill found. Working environment cannot be guaranteed. Please file an issue at https://github.com/aurelia/aurelia/issues so that we can look into compatibility options for this scenario.'); | ||
} | ||
if ( | ||
'metadata' in reflect || | ||
'decorate' in reflect || | ||
'defineMetadata' in reflect || | ||
'hasMetadata' in reflect || | ||
'hasOwnMetadata' in reflect || | ||
'getMetadata' in reflect || | ||
'getOwnMetadata' in reflect || | ||
'getMetadataKeys' in reflect || | ||
'getOwnMetadataKeys' in reflect || | ||
'deleteMetadata' in reflect | ||
) { | ||
throw new Error(`Conflicting reflect.metadata polyfill found. If you have 'reflect-metadata' or any other reflect polyfill imported, please remove it, if not (or if you must use a specific polyfill) please file an issue at https://github.com/aurelia/aurelia/issues so that we can look into compatibility options for this scenario.`); | ||
} | ||
if (!hasMetadata) { | ||
def(Reflect, 'metadata', metadata); | ||
def(Metadata, '$Internal', metadataInternalSlot); | ||
def(reflect, 'metadata', metadata); | ||
def(reflect, 'decorate', decorate); | ||
def(reflect, 'defineMetadata', $define); | ||
def(reflect, 'hasMetadata', $has); | ||
def(reflect, 'hasOwnMetadata', $hasOwn); | ||
def(reflect, 'getMetadata', $get); | ||
def(reflect, 'getOwnMetadata', $getOwn); | ||
def(reflect, 'getMetadataKeys', $getKeys); | ||
def(reflect, 'getOwnMetadataKeys', $getOwnKeys); | ||
def(reflect, 'deleteMetadata', $delete); | ||
} | ||
if (!hasDecorate) { | ||
def(Reflect, 'decorate', decorate); | ||
} | ||
if (!hasDefineMetadata) { | ||
def(Reflect, 'defineMetadata', $define); | ||
} | ||
if (!hasHasMetadata) { | ||
def(Reflect, 'hasMetadata', $has); | ||
} | ||
if (!hasHasOwnMetadata) { | ||
def(Reflect, 'hasOwnMetadata', $hasOwn); | ||
} | ||
if (!hasGetMetadata) { | ||
def(Reflect, 'getMetadata', $get); | ||
} | ||
if (!hasGetOwnMetadata) { | ||
def(Reflect, 'getOwnMetadata', $getOwn); | ||
} | ||
if (!hasGetMetadataKeys) { | ||
def(Reflect, 'getMetadataKeys', $getKeys); | ||
} | ||
if (!hasGetOwnMetadataKeys) { | ||
def(Reflect, 'getOwnMetadataKeys', $getOwnKeys); | ||
} | ||
if (!hasDeleteMetadata) { | ||
def(Reflect, 'deleteMetadata', $delete); | ||
} | ||
export { Metadata, metadata }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
134047
1
2464