{"version":3,"sources":["/home/runner/work/emmett/emmett/src/packages/emmett/dist/chunk-WND32L6P.cjs","../src/config/plugins/index.ts","../src/validation/index.ts","../src/errors/index.ts","../src/validation/dates.ts"],"names":["ValidationErrors"],"mappings":"AAAA;ACyBO,IAAM,eAAA,EAAiB,CAC5B,MAAA,EAAA,GAEA,OAAA,IAAW,KAAA,EAAA,GAAA,CACV,OAAO,OAAA,IAAW,SAAA,GAChB,OAAA,GAAU,OAAA,GACT,MAAA,CAAO,KAAA,IAAS,KAAA,EAAA,GAChB,OAAO,MAAA,CAAO,KAAA,IAAS,QAAA,CAAA;AD9B7B;AACA;AEDO,IAAW,iBAAA,kBAAX,CAAA,CAAWA,iBAAAA,EAAAA,GAAX;AACL,EAAAA,iBAAAA,CAAA,uBAAA,EAAA,EAAwB,uBAAA;AACxB,EAAAA,iBAAAA,CAAA,uBAAA,EAAA,EAAwB,uBAAA;AACxB,EAAAA,iBAAAA,CAAA,wBAAA,EAAA,EAAyB,wBAAA;AAHT,EAAA,OAAAA,iBAAAA;AAAA,CAAA,CAAA,CAAA,iBAAA,GAAA,CAAA,CAAA,CAAA;AAMX,IAAM,SAAA,EAAW,CAAC,GAAA,EAAA,GACvB,OAAO,IAAA,IAAQ,SAAA,GAAY,IAAA,IAAQ,GAAA;AAG9B,IAAM,SAAA,EAAW,CAAC,GAAA,EAAA,GACvB,OAAO,IAAA,IAAQ,SAAA,GAAY,IAAA,IAAQ,GAAA;AAE9B,IAAM,SAAA,EAAW,CAAC,GAAA,EAAA,GACvB,OAAO,IAAA,IAAQ,QAAA;AAEV,IAAM,qBAAA,EAAuB,CAAC,KAAA,EAAA,GAA2B;AAC9D,EAAA,GAAA,CAAI,CAAC,QAAA,CAAS,KAAK,EAAA,GAAK,KAAA,CAAM,OAAA,IAAW,CAAA,EAAG;AAC1C,IAAA,MAAM,IAAI,eAAA,CAAgB,mDAAsC,CAAA;AAAA,EAClE;AACA,EAAA,OAAO,KAAA;AACT,CAAA;AAEO,IAAM,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mBACE,OAAA,UACA,CAAA,iBAAA,EAAoB,QAAA,CAAS,QAAA,CAAS,CAAC,CAAA,wBAAA,kBAA2B,OAAA,2BAAS,QAAA,mBAAS,GAAC,CAAA;AAAA,IAAA;AARlF,IAAA;AACA,IAAA;AAWP,IAAA;AAAsD,EAAA;AAE1D;AAIO;AAA2D,EAAA;AAE9D,IAAA;AAAM,MAAA;AACyB,MAAA;AACT,IAAA;AAItB,IAAA;AAAsE,EAAA;AAE1E;AAEO;AAA0C,EAAA;AAE7C,IAAA;AAAM,MAAA;AACyB,MAAA;AACT,IAAA;AAItB,IAAA;AAAqD,EAAA;AAEzD;AAEO;AAA4C,EAAA;AAE/C,IAAA;AAAM,MAAA;AACyB,MAAA;AACT,IAAA;AAItB,IAAA;AAAuD,EAAA;AAE3D;AAEO;AAAwC,EAAA;AAE3C,IAAA;AAAM,MAAA;AACyB,MAAA;AASrB,IAAA;AAIV,IAAA;AAAmD,EAAA;AAEvD;AH9CA;AACA;AIjHO;AAEL,EAAA;AAAmD,IAAA;AACvC,IAAA;AACJ,IAAA;AACC,IAAA;AACF,EAAA;AAIP,EAAA;AACF;AAGO;AACL,EAAA;AACA,EAAA;AACF;AAEO;AACL,EAAA;AAEA,EAAA;AACE,IAAA;AAAmE,EAAA;AAGrE,EAAA;AACE,IAAA;AAA+C,EAAA;AAGjD,EAAA;AACF;AJ0GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/emmett/emmett/src/packages/emmett/dist/chunk-WND32L6P.cjs","sourcesContent":[null,"export type EmmettPluginConfig =\n  | {\n      name: string;\n      register: EmmettPluginRegistration[];\n    }\n  | string;\n\nexport type EmmettPluginType = 'cli';\n\nexport type EmmettCliPluginRegistration = { pluginType: 'cli'; path?: string };\n\nexport type EmmettPluginRegistration = EmmettCliPluginRegistration;\n\nexport type EmmettCliCommand = {\n  addCommand<CliCommand>(command: CliCommand): CliCommand;\n};\n\nexport type EmmettCliPlugin = {\n  pluginType: 'cli';\n  name: string;\n  registerCommands: (program: EmmettCliCommand) => Promise<void> | void;\n};\n\nexport type EmmettPlugin = EmmettCliPlugin;\n\nexport const isPluginConfig = (\n  plugin: Partial<EmmettPluginConfig> | string | undefined,\n): plugin is EmmettPluginConfig =>\n  plugin !== undefined &&\n  (typeof plugin === 'string' ||\n    ('name' in plugin &&\n      plugin.name !== undefined &&\n      typeof plugin.name === 'string'));\n","import { ValidationError } from '../errors';\n\nexport const enum ValidationErrors {\n  NOT_A_NONEMPTY_STRING = 'NOT_A_NONEMPTY_STRING',\n  NOT_A_POSITIVE_NUMBER = 'NOT_A_POSITIVE_NUMBER',\n  NOT_AN_UNSIGNED_BIGINT = 'NOT_AN_UNSIGNED_BIGINT',\n}\n\nexport const isNumber = (val: unknown): val is number =>\n  typeof val === 'number' && val === val;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isBigint = (val: any): val is bigint =>\n  typeof val === 'bigint' && val === val;\n\nexport const isString = (val: unknown): val is string =>\n  typeof val === 'string';\n\nexport const assertNotEmptyString = (value: unknown): string => {\n  if (!isString(value) || value.length === 0) {\n    throw new ValidationError(ValidationErrors.NOT_A_NONEMPTY_STRING);\n  }\n  return value;\n};\n\nexport const assertPositiveNumber = (value: unknown): number => {\n  if (!isNumber(value) || value <= 0) {\n    throw new ValidationError(ValidationErrors.NOT_A_POSITIVE_NUMBER);\n  }\n  return value;\n};\n\nexport const assertUnsignedBigInt = (value: string): bigint => {\n  const number = BigInt(value);\n  if (number < 0) {\n    throw new ValidationError(ValidationErrors.NOT_AN_UNSIGNED_BIGINT);\n  }\n  return number;\n};\n\nexport * from './dates';\n","import { isNumber, isString } from '../validation';\n\nexport type ErrorConstructor<ErrorType extends Error> = new (\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  ...args: any[]\n) => ErrorType;\n\nexport const isErrorConstructor = <ErrorType extends Error>(\n  // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n  expect: Function,\n): expect is ErrorConstructor<ErrorType> => {\n  // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n  return (\n    typeof expect === 'function' &&\n    expect.prototype &&\n    // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n    expect.prototype.constructor === expect\n  );\n};\n\nexport class EmmettError extends Error {\n  public static readonly Codes = {\n    ValidationError: 400,\n    IllegalStateError: 403,\n    NotFoundError: 404,\n    ConcurrencyError: 412,\n    InternalServerError: 500,\n  };\n\n  public errorCode: number;\n\n  constructor(\n    options?: { errorCode: number; message?: string } | string | number,\n  ) {\n    const errorCode =\n      options && typeof options === 'object' && 'errorCode' in options\n        ? options.errorCode\n        : isNumber(options)\n          ? options\n          : EmmettError.Codes.InternalServerError;\n    const message =\n      options && typeof options === 'object' && 'message' in options\n        ? options.message\n        : isString(options)\n          ? options\n          : `Error with status code '${errorCode}' ocurred during Emmett processing`;\n\n    super(message);\n    this.errorCode = errorCode;\n\n    // 👇️ because we are extending a built-in class\n    Object.setPrototypeOf(this, EmmettError.prototype);\n  }\n\n  public static mapFrom(\n    error: Error | { message?: string; errorCode?: number },\n  ): EmmettError {\n    if (EmmettError.isInstanceOf(error)) {\n      return error;\n    }\n\n    return new EmmettError({\n      errorCode:\n        'errorCode' in error &&\n        error.errorCode !== undefined &&\n        error.errorCode !== null\n          ? error.errorCode\n          : EmmettError.Codes.InternalServerError,\n      message: error.message ?? 'An unknown error occurred',\n    });\n  }\n\n  public static isInstanceOf<ErrorType extends EmmettError = EmmettError>(\n    error: unknown,\n    errorCode?: (typeof EmmettError.Codes)[keyof typeof EmmettError.Codes],\n  ): error is ErrorType {\n    return (\n      typeof error === 'object' &&\n      error !== null &&\n      'errorCode' in error &&\n      isNumber(error.errorCode) &&\n      (errorCode === undefined || error.errorCode === errorCode)\n    );\n  }\n}\n\nexport class ConcurrencyError extends EmmettError {\n  constructor(\n    public current: string | undefined,\n    public expected: string,\n    message?: string,\n  ) {\n    super({\n      errorCode: EmmettError.Codes.ConcurrencyError,\n      message:\n        message ??\n        `Expected version ${expected.toString()} does not match current ${current?.toString()}`,\n    });\n\n    // 👇️ because we are extending a built-in class\n    Object.setPrototypeOf(this, ConcurrencyError.prototype);\n  }\n}\n\n// TODO: Make it derive from ConcurrencyError to avoid code duplication\n// Or add additional type to distinguinsh both errors\nexport class ConcurrencyInMemoryDatabaseError extends EmmettError {\n  constructor(message?: string) {\n    super({\n      errorCode: EmmettError.Codes.ConcurrencyError,\n      message: message ?? `Expected document state does not match current one!`,\n    });\n\n    // 👇️ because we are extending a built-in class\n    Object.setPrototypeOf(this, ConcurrencyInMemoryDatabaseError.prototype);\n  }\n}\n\nexport class ValidationError extends EmmettError {\n  constructor(message?: string) {\n    super({\n      errorCode: EmmettError.Codes.ValidationError,\n      message: message ?? `Validation Error ocurred during Emmett processing`,\n    });\n\n    // 👇️ because we are extending a built-in class\n    Object.setPrototypeOf(this, ValidationError.prototype);\n  }\n}\n\nexport class IllegalStateError extends EmmettError {\n  constructor(message?: string) {\n    super({\n      errorCode: EmmettError.Codes.IllegalStateError,\n      message: message ?? `Illegal State ocurred during Emmett processing`,\n    });\n\n    // 👇️ because we are extending a built-in class\n    Object.setPrototypeOf(this, IllegalStateError.prototype);\n  }\n}\n\nexport class NotFoundError extends EmmettError {\n  constructor(options?: { id: string; type: string; message?: string }) {\n    super({\n      errorCode: EmmettError.Codes.NotFoundError,\n      message:\n        options?.message ??\n        (options?.id\n          ? options.type\n            ? `${options.type} with ${options.id} was not found during Emmett processing`\n            : `State with ${options.id} was not found during Emmett processing`\n          : options?.type\n            ? `${options.type} was not found during Emmett processing`\n            : 'State was not found during Emmett processing'),\n    });\n\n    // 👇️ because we are extending a built-in class\n    Object.setPrototypeOf(this, NotFoundError.prototype);\n  }\n}\n","import { ValidationError } from '../errors';\n\nexport const formatDateToUtcYYYYMMDD = (date: Date) => {\n  // Use the 'en-CA' locale which formats as 'yyyy-mm-dd'\n  const formatter = new Intl.DateTimeFormat('en-CA', {\n    timeZone: 'UTC',\n    year: 'numeric',\n    month: '2-digit',\n    day: '2-digit',\n  });\n\n  // Format the date\n  return formatter.format(date);\n};\n\n// Function to validate 'yyyy-mm-dd' format\nexport const isValidYYYYMMDD = (dateString: string) => {\n  const regex = /^\\d{4}-\\d{2}-\\d{2}$/;\n  return regex.test(dateString);\n};\n\nexport const parseDateFromUtcYYYYMMDD = (dateString: string) => {\n  const date = new Date(dateString + 'T00:00:00Z');\n\n  if (!isValidYYYYMMDD(dateString)) {\n    throw new ValidationError('Invalid date format, must be yyyy-mm-dd');\n  }\n\n  if (isNaN(date.getTime())) {\n    throw new ValidationError('Invalid date format');\n  }\n\n  return date;\n};\n"]}