{"version":3,"file":"injectable.decorator.mjs","names":["InjectableScope","InjectableType","InjectableTokenMeta","InjectionToken","globalRegistry","Injectable","scope","Singleton","token","schema","registry","priority","target","context","kind","Function","Error","injectableToken","create","set","Class"],"sources":["../../../src/decorators/injectable.decorator.mts"],"sourcesContent":["import type { z } from 'zod/v4'\n\nimport type {\n  BaseInjectionTokenSchemaType,\n  ClassType,\n  ClassTypeWithArgument,\n  ClassTypeWithInstance,\n  ClassTypeWithInstanceAndArgument,\n  ClassTypeWithInstanceAndOptionalArgument,\n  ClassTypeWithOptionalArgument,\n  ClassTypeWithoutArguments,\n  InjectionTokenSchemaType,\n  OptionalInjectionTokenSchemaType,\n} from '../token/injection-token.mjs'\nimport type { Registry } from '../token/registry.mjs'\n\nimport { InjectableScope, InjectableType } from '../enums/index.mjs'\nimport { InjectableTokenMeta } from '../symbols/index.mjs'\nimport { InjectionToken } from '../token/injection-token.mjs'\nimport { globalRegistry } from '../token/registry.mjs'\n\nexport interface InjectableOptions {\n  scope?: InjectableScope\n  token?: InjectionToken<any, any>\n  schema?: InjectionTokenSchemaType\n  registry?: Registry\n  priority?: number\n}\n\n// #1 Simple constructorless class\nexport function Injectable(): <T extends ClassTypeWithoutArguments>(\n  target: T,\n  context?: ClassDecoratorContext,\n) => T\nexport function Injectable(options: {\n  scope?: InjectableScope\n  registry: Registry\n  priority?: number\n}): <T extends ClassTypeWithoutArguments>(\n  target: T,\n  context?: ClassDecoratorContext,\n) => T\nexport function Injectable(options: {\n  scope: InjectableScope\n  priority?: number\n}): <T extends ClassTypeWithoutArguments>(\n  target: T,\n  context?: ClassDecoratorContext,\n) => T\n// #2 Class with schema\nexport function Injectable<Schema extends InjectionTokenSchemaType>(options: {\n  scope?: InjectableScope\n  schema: Schema\n  registry?: Registry\n  priority?: number\n}): <T extends ClassTypeWithArgument<z.output<Schema>>>(\n  target: T,\n  context?: ClassDecoratorContext,\n) => T\n\n// #3 Class with typeless token and schema\nexport function Injectable<Type, Schema>(options: {\n  scope?: InjectableScope\n  token: InjectionToken<Type, Schema>\n  registry?: Registry\n  priority?: number\n}): Schema extends BaseInjectionTokenSchemaType\n  ? Type extends undefined\n    ? <T extends ClassTypeWithArgument<z.output<Schema>>>(\n        target: T,\n        context?: ClassDecoratorContext,\n      ) => T\n    : <T extends ClassTypeWithInstanceAndArgument<Type, z.output<Schema>>>(\n        target: T,\n        context?: ClassDecoratorContext,\n      ) => T\n  : Schema extends OptionalInjectionTokenSchemaType\n    ? Type extends undefined\n      ? <T extends ClassTypeWithOptionalArgument<z.output<Schema>>>(\n          target: T,\n          context?: ClassDecoratorContext,\n        ) => T\n      : <\n          T extends ClassTypeWithInstanceAndOptionalArgument<\n            Type,\n            z.output<Schema>\n          >,\n        >(\n          target: T,\n          context?: ClassDecoratorContext,\n        ) => T\n    : Schema extends undefined\n      ? <R extends ClassTypeWithInstance<Type>>(\n          target: R,\n          context?: ClassDecoratorContext,\n        ) => R\n      : never\n\nexport function Injectable({\n  scope = InjectableScope.Singleton,\n  token,\n  schema,\n  registry = globalRegistry,\n  priority = 0,\n}: InjectableOptions = {}) {\n  return <T extends ClassType>(\n    target: T,\n    context?: ClassDecoratorContext,\n  ): T => {\n    if (\n      (context && context.kind !== 'class') ||\n      (target instanceof Function && !context)\n    ) {\n      throw new Error('[DI] @Injectable decorator can only be used on classes.')\n    }\n    if (schema && token) {\n      throw new Error(\n        '[DI] @Injectable decorator cannot have both a token and a schema',\n      )\n    }\n    let injectableToken: InjectionToken<any, any> =\n      token ?? InjectionToken.create(target, schema as InjectionTokenSchemaType)\n\n    registry.set(injectableToken, scope, target, InjectableType.Class, priority)\n\n    // @ts-expect-error\n    target[InjectableTokenMeta] = injectableToken\n\n    return target\n  }\n}\n"],"mappings":";;;;;;;AAkGA,SAAgBK,WAAW,EACzBC,QAAQN,gBAAgBO,WACxBC,OACAC,QACAC,WAAWN,gBACXO,WAAW,MACU,EAAE,EAAA;AACvB,SACEC,QACAC,YAAAA;AAEA,MACE,WAAYA,QAAQC,SAAS,WAC5BF,kBAAkBG,YAAY,CAACF,QAEhC,OAAM,IAAIG,MAAM,0DAAA;AAElB,MAAIP,UAAUD,MACZ,OAAM,IAAIQ,MACR,mEAAA;EAGJ,IAAIC,kBACFT,SAASL,eAAee,OAAON,QAAQH,OAAAA;AAEzCC,WAASS,IAAIF,iBAAiBX,OAAOM,QAAQX,eAAemB,OAAOT,SAAAA;AAGnEC,SAAOV,uBAAuBe;AAE9B,SAAOL"}