{"version":3,"file":"metadata.mjs","sources":["../../../src/utils/metadata.ts"],"sourcesContent":["import type { Context } from '../context.js'\nimport { NoExplicitTypeError } from '../errors/no_explicit_type.js'\nimport { ReflectMetadataMissingError } from '../errors/reflect_metadata_missing.js'\n\n/**\n * Asserts that `reflect-metadata` exists.\n */\nexport function assertReflectMetadata() {\n  if (typeof Reflect !== 'object' || typeof Reflect.getMetadata !== 'function') {\n    throw new ReflectMetadataMissingError()\n  }\n}\n\nexport type MetadataKey = 'design:type' | 'design:returntype' | 'design:paramtypes'\n\nexport type FindTypeOptions = {\n  context: Context\n  metadataKey: MetadataKey\n  prototype: Object\n  propertyKey: string\n}\n\n/**\n * Returns the type inferred from class member.\n */\nexport function findType({ metadataKey, prototype, propertyKey }: FindTypeOptions) {\n  assertReflectMetadata()\n  const reflectedType: Function | undefined = Reflect.getMetadata(\n    metadataKey,\n    prototype,\n    propertyKey\n  )\n\n  if (!reflectedType) {\n    throw new NoExplicitTypeError(prototype.constructor.name, propertyKey)\n  }\n\n  return reflectedType\n}\n\nconst IS_THUNK_REG = /^.+=>[\\w\\d\\s\\t\\n\\r]*/\n\n/**\n * Asserts that a value is a thunk value.\n *\n * @example isThunk('hello') === false\n * @example isThunk(() => 'hello') === true\n */\nexport function isThunk(value: any): boolean {\n  if (typeof value !== 'function') {\n    return false\n  }\n\n  return Boolean(IS_THUNK_REG.exec(value))\n}\n"],"names":[],"mappings":";;;AAOO,SAAS,qBAAA,GAAwB;AACtC,EAAA,IAAI,OAAO,OAAA,KAAY,QAAA,IAAY,OAAO,OAAA,CAAQ,gBAAgB,UAAA,EAAY;AAC5E,IAAA,MAAM,IAAI,2BAAA,EAA4B;AAAA,EACxC;AACF;AAcO,SAAS,QAAA,CAAS,EAAE,WAAA,EAAa,SAAA,EAAW,aAAY,EAAoB;AACjF,EAAA,qBAAA,EAAsB;AACtB,EAAA,MAAM,gBAAsC,OAAA,CAAQ,WAAA;AAAA,IAClD,WAAA;AAAA,IACA,SAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,MAAM,IAAI,mBAAA,CAAoB,SAAA,CAAU,WAAA,CAAY,MAAM,WAAW,CAAA;AAAA,EACvE;AAEA,EAAA,OAAO,aAAA;AACT;AAEA,MAAM,YAAA,GAAe,sBAAA;AAQd,SAAS,QAAQ,KAAA,EAAqB;AAC3C,EAAA,IAAI,OAAO,UAAU,UAAA,EAAY;AAC/B,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,OAAO,OAAA,CAAQ,YAAA,CAAa,IAAA,CAAK,KAAK,CAAC,CAAA;AACzC;;;;"}