{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export interface ParamSpec {\n  readonly codecId?: string;\n  readonly traits?: readonly string[];\n  readonly nullable: boolean;\n}\n\nexport interface ReturnSpec {\n  readonly codecId: string;\n  readonly nullable: boolean;\n}\n\nexport type SelfSpec =\n  | { readonly codecId: string; readonly traits?: never }\n  | { readonly traits: readonly string[]; readonly codecId?: never };\n\nexport interface OperationEntry {\n  readonly self?: SelfSpec;\n  readonly impl: (...args: never[]) => unknown;\n}\n\nexport type OperationDescriptor<T extends OperationEntry = OperationEntry> = T;\n\nexport type OperationDescriptors<T extends OperationEntry = OperationEntry> = Readonly<\n  Record<string, OperationDescriptor<T>>\n>;\n\nexport interface OperationRegistry<T extends OperationEntry = OperationEntry> {\n  register(name: string, descriptor: OperationDescriptor<T>): void;\n  entries(): Readonly<Record<string, T>>;\n}\n\nexport function createOperationRegistry<\n  T extends OperationEntry = OperationEntry,\n>(): OperationRegistry<T> {\n  const operations: Record<string, T> = Object.create(null);\n\n  return {\n    register(name: string, descriptor: OperationDescriptor<T>) {\n      if (name in operations) {\n        throw new Error(`Operation \"${name}\" is already registered`);\n      }\n      if (descriptor.self) {\n        const hasCodecId = descriptor.self.codecId !== undefined;\n        const hasTraits = descriptor.self.traits !== undefined && descriptor.self.traits.length > 0;\n        if (!hasCodecId && !hasTraits) {\n          throw new Error(`Operation \"${name}\" self has neither codecId nor traits`);\n        }\n        if (hasCodecId && hasTraits) {\n          throw new Error(`Operation \"${name}\" self has both codecId and traits`);\n        }\n      }\n      operations[name] = descriptor;\n    },\n    entries() {\n      return Object.freeze({ ...operations });\n    },\n  };\n}\n"],"mappings":";AA+BA,SAAgB,0BAEU;CACxB,MAAM,aAAgC,OAAO,OAAO,IAAI;CAExD,OAAO;EACL,SAAS,MAAc,YAAoC;GACzD,IAAI,QAAQ,YACV,MAAM,IAAI,MAAM,cAAc,KAAK,wBAAwB;GAE7D,IAAI,WAAW,MAAM;IACnB,MAAM,aAAa,WAAW,KAAK,YAAY,KAAA;IAC/C,MAAM,YAAY,WAAW,KAAK,WAAW,KAAA,KAAa,WAAW,KAAK,OAAO,SAAS;IAC1F,IAAI,CAAC,cAAc,CAAC,WAClB,MAAM,IAAI,MAAM,cAAc,KAAK,sCAAsC;IAE3E,IAAI,cAAc,WAChB,MAAM,IAAI,MAAM,cAAc,KAAK,mCAAmC;GAE1E;GACA,WAAW,QAAQ;EACrB;EACA,UAAU;GACR,OAAO,OAAO,OAAO,EAAE,GAAG,WAAW,CAAC;EACxC;CACF;AACF"}