UNPKG

@eristack/qups

Version:

Quantity / unit price / subtotal (QUPS) with 2-of-3 sources of truth, plus modifiers and tax — business line pricing on @eristack/money

1 lines • 56.2 kB
{"version":3,"sources":["../../src/drizzle/index.ts","../../src/drizzle/line-columns.ts","../../src/drizzle/columns-from-profile.ts","../../src/drizzle/tables.ts","../../src/drizzle/profile-store.ts","../../src/drizzle/line-store.ts"],"sourcesContent":["export type { DrizzleDialect, DrizzleLikeDb } from \"./types.js\";\n\nexport {\n  qupsLineColumns,\n  QUPS_LINE_SQL_COLUMNS,\n  type QupsLineColumnOptions,\n} from \"./line-columns.js\";\nexport {\n  qupsLineColumnOptionsFromProfile,\n  qupsLineColumnsFromProfile,\n  type QupsProfileColumnHints,\n} from \"./columns-from-profile.js\";\n\nexport {\n  createQupsProfileTables,\n  createQupsLineSideTables,\n  createQupsTables,\n} from \"./tables.js\";\nexport type {\n  QupsProfileTables,\n  QupsLineSideTables,\n  QupsTables,\n} from \"./tables.js\";\n\nexport { createDrizzlePricingProfileStore } from \"./profile-store.js\";\nexport type { CreateDrizzlePricingProfileStoreOptions } from \"./profile-store.js\";\n\nexport {\n  createDrizzlePricingLineStore,\n  qupsPatchFromRecord,\n  pricingFieldsFromRow,\n} from \"./line-store.js\";\nexport type {\n  CreateDrizzlePricingLineStoreOptions,\n  AnyInjectableLineTable,\n} from \"./line-store.js\";\n","import {\n  text as pgText,\n  integer as pgInteger,\n  timestamp as pgTimestamp,\n  varchar as pgVarchar,\n} from \"drizzle-orm/pg-core\";\nimport {\n  varchar as mysqlVarchar,\n  int as mysqlInt,\n  datetime as mysqlDatetime,\n} from \"drizzle-orm/mysql-core\";\nimport {\n  text as sqliteText,\n  integer as sqliteInteger,\n} from \"drizzle-orm/sqlite-core\";\nimport {\n  moneyAmountColumn,\n} from \"@eristack/money/drizzle\";\nimport type { DrizzleDialect } from \"./types.js\";\n\nconst CURRENCY_LENGTH = 16;\n\nexport type QupsLineColumnOptions = {\n  /**\n   * Optional `profile_id` column on the detail row.\n   * @default true\n   */\n  includeProfileId?: boolean;\n  /**\n   * Optional `position` column (line order).\n   * @default false — apps usually already have `line_no` / similar\n   */\n  includePosition?: boolean;\n  /**\n   * Optional `created_at` / `updated_at`.\n   * @default false — apps usually already have timestamps\n   */\n  includeTimestamps?: boolean;\n};\n\nfunction sharedCurrencyColumns(dialect: DrizzleDialect) {\n  switch (dialect) {\n    case \"pgsql\":\n      return {\n        currency: pgVarchar(\"currency\", { length: CURRENCY_LENGTH }).notNull(),\n      };\n    case \"mysql\":\n      return {\n        currency: mysqlVarchar(\"currency\", { length: CURRENCY_LENGTH }).notNull(),\n      };\n    case \"sqlite\":\n      return {\n        currency: sqliteText(\"currency\").notNull(),\n      };\n    default: {\n      const _e: never = dialect;\n      throw new Error(`Unsupported dialect: ${String(_e)}`);\n    }\n  }\n}\n\nfunction qupsMoneyAmountColumns(dialect: DrizzleDialect) {\n  return {\n    ...moneyAmountColumn(dialect, \"unitPrice\"),\n    ...moneyAmountColumn(dialect, \"subtotal\"),\n    ...moneyAmountColumn(dialect, \"tax\"),\n    ...moneyAmountColumn(dialect, \"net\"),\n    ...moneyAmountColumn(dialect, \"gross\"),\n  };\n}\n\n/**\n * Injectable QUPS pricing columns for an app-owned detail table\n * (invoice lines, order lines, GR lines, …).\n *\n * One shared `currency` column plus numeric `*_amount` columns via\n * `@eristack/money/drizzle` defaults (`unit_price_amount`, …).\n *\n * Spread into your table next to `itemId` and other domain columns:\n *\n * ```ts\n * pgTable(\"invoice_lines\", {\n *   id: text(\"id\").primaryKey(),\n *   invoiceId: text(\"invoice_id\").notNull(),\n *   itemId: text(\"item_id\").notNull(),\n *   ...qupsLineColumns(\"pgsql\"),\n * });\n * ```\n *\n * Does **not** include `id` or parent/owner keys — those stay app-owned.\n */\nexport function qupsLineColumns(\n  dialect: \"pgsql\",\n  options?: QupsLineColumnOptions,\n): ReturnType<typeof pgsqlQupsLineColumns>;\nexport function qupsLineColumns(\n  dialect: \"mysql\",\n  options?: QupsLineColumnOptions,\n): ReturnType<typeof mysqlQupsLineColumns>;\nexport function qupsLineColumns(\n  dialect: \"sqlite\",\n  options?: QupsLineColumnOptions,\n): ReturnType<typeof sqliteQupsLineColumns>;\nexport function qupsLineColumns(\n  dialect: DrizzleDialect,\n  options: QupsLineColumnOptions = {},\n) {\n  switch (dialect) {\n    case \"pgsql\":\n      return pgsqlQupsLineColumns(options);\n    case \"mysql\":\n      return mysqlQupsLineColumns(options);\n    case \"sqlite\":\n      return sqliteQupsLineColumns(options);\n    default: {\n      const _e: never = dialect;\n      throw new Error(`Unsupported dialect: ${String(_e)}`);\n    }\n  }\n}\n\nfunction pgsqlQupsLineColumns(options: QupsLineColumnOptions) {\n  const includeProfileId = options.includeProfileId !== false;\n  const includePosition = options.includePosition === true;\n  const includeTimestamps = options.includeTimestamps === true;\n\n  return {\n    ...(includeProfileId\n      ? { profileId: pgText(\"profile_id\") }\n      : {}),\n    truth: pgText(\"truth\").notNull(),\n    quantity: pgText(\"quantity\").notNull(),\n    quantityRatioNumerator: pgText(\"quantity_ratio_numerator\"),\n    quantityRatioDenominator: pgText(\"quantity_ratio_denominator\"),\n    ...sharedCurrencyColumns(\"pgsql\"),\n    ...qupsMoneyAmountColumns(\"pgsql\"),\n    taxRatePercent: pgText(\"tax_rate_percent\"),\n    taxMode: pgText(\"tax_mode\"),\n    ...(includePosition ? { position: pgInteger(\"position\") } : {}),\n    ...(includeTimestamps\n      ? {\n          createdAt: pgTimestamp(\"created_at\", {\n            withTimezone: true,\n            mode: \"date\",\n          }).notNull(),\n          updatedAt: pgTimestamp(\"updated_at\", {\n            withTimezone: true,\n            mode: \"date\",\n          }).notNull(),\n        }\n      : {}),\n  };\n}\n\nfunction mysqlQupsLineColumns(options: QupsLineColumnOptions) {\n  const includeProfileId = options.includeProfileId !== false;\n  const includePosition = options.includePosition === true;\n  const includeTimestamps = options.includeTimestamps === true;\n\n  return {\n    ...(includeProfileId\n      ? { profileId: mysqlVarchar(\"profile_id\", { length: 64 }) }\n      : {}),\n    truth: mysqlVarchar(\"truth\", { length: 64 }).notNull(),\n    quantity: mysqlVarchar(\"quantity\", { length: 64 }).notNull(),\n    quantityRatioNumerator: mysqlVarchar(\"quantity_ratio_numerator\", {\n      length: 64,\n    }),\n    quantityRatioDenominator: mysqlVarchar(\"quantity_ratio_denominator\", {\n      length: 64,\n    }),\n    ...sharedCurrencyColumns(\"mysql\"),\n    ...qupsMoneyAmountColumns(\"mysql\"),\n    taxRatePercent: mysqlVarchar(\"tax_rate_percent\", { length: 32 }),\n    taxMode: mysqlVarchar(\"tax_mode\", { length: 32 }),\n    ...(includePosition ? { position: mysqlInt(\"position\") } : {}),\n    ...(includeTimestamps\n      ? {\n          createdAt: mysqlDatetime(\"created_at\", { mode: \"date\" }).notNull(),\n          updatedAt: mysqlDatetime(\"updated_at\", { mode: \"date\" }).notNull(),\n        }\n      : {}),\n  };\n}\n\nfunction sqliteQupsLineColumns(options: QupsLineColumnOptions) {\n  const includeProfileId = options.includeProfileId !== false;\n  const includePosition = options.includePosition === true;\n  const includeTimestamps = options.includeTimestamps === true;\n\n  return {\n    ...(includeProfileId\n      ? { profileId: sqliteText(\"profile_id\") }\n      : {}),\n    truth: sqliteText(\"truth\").notNull(),\n    quantity: sqliteText(\"quantity\").notNull(),\n    quantityRatioNumerator: sqliteText(\"quantity_ratio_numerator\"),\n    quantityRatioDenominator: sqliteText(\"quantity_ratio_denominator\"),\n    ...sharedCurrencyColumns(\"sqlite\"),\n    ...qupsMoneyAmountColumns(\"sqlite\"),\n    taxRatePercent: sqliteText(\"tax_rate_percent\"),\n    taxMode: sqliteText(\"tax_mode\"),\n    ...(includePosition ? { position: sqliteInteger(\"position\") } : {}),\n    ...(includeTimestamps\n      ? {\n          createdAt: sqliteInteger(\"created_at\", {\n            mode: \"timestamp_ms\",\n          }).notNull(),\n          updatedAt: sqliteInteger(\"updated_at\", {\n            mode: \"timestamp_ms\",\n          }).notNull(),\n        }\n      : {}),\n  };\n}\n\n/** Canonical SQL names for injectable QUPS columns (docs / migrations). */\nexport const QUPS_LINE_SQL_COLUMNS = [\n  \"profile_id\",\n  \"truth\",\n  \"quantity\",\n  \"quantity_ratio_numerator\",\n  \"quantity_ratio_denominator\",\n  \"currency\",\n  \"unit_price_amount\",\n  \"subtotal_amount\",\n  \"tax_rate_percent\",\n  \"tax_mode\",\n  \"tax_amount\",\n  \"net_amount\",\n  \"gross_amount\",\n] as const;\n","import type { QupsLineColumnOptions } from \"./line-columns.js\";\nimport { qupsLineColumns } from \"./line-columns.js\";\nimport type { DrizzleDialect } from \"./types.js\";\n\nexport type QupsProfileColumnHints = {\n  /** Profile stores line ordering separately. */\n  trackPosition?: boolean;\n  /** Profile row includes created/updated timestamps. */\n  trackTimestamps?: boolean;\n  /** Detail rows reference profile_id. */\n  linkProfile?: boolean;\n};\n\nconst DEFAULT_HINTS: Required<QupsProfileColumnHints> = {\n  trackPosition: false,\n  trackTimestamps: false,\n  linkProfile: true,\n};\n\n/** Map profile storage hints to qupsLineColumns options. */\nexport function qupsLineColumnOptionsFromProfile(\n  hints: QupsProfileColumnHints = {},\n): QupsLineColumnOptions {\n  const merged = { ...DEFAULT_HINTS, ...hints };\n  return {\n    includeProfileId: merged.linkProfile,\n    includePosition: merged.trackPosition,\n    includeTimestamps: merged.trackTimestamps,\n  };\n}\n\n/** Drizzle column bundle from profile hints — Q5 generator entrypoint. */\nexport function qupsLineColumnsFromProfile(\n  dialect: DrizzleDialect,\n  hints?: QupsProfileColumnHints,\n) {\n  const options = qupsLineColumnOptionsFromProfile(hints);\n  switch (dialect) {\n    case \"pgsql\":\n      return qupsLineColumns(\"pgsql\", options);\n    case \"mysql\":\n      return qupsLineColumns(\"mysql\", options);\n    case \"sqlite\":\n      return qupsLineColumns(\"sqlite\", options);\n    default: {\n      const _exhaustive: never = dialect;\n      throw new Error(`Unsupported dialect: ${String(_exhaustive)}`);\n    }\n  }\n}\n","import {\n  pgTable,\n  text as pgText,\n  timestamp as pgTimestamp,\n  boolean as pgBoolean,\n  integer as pgInteger,\n  primaryKey as pgPrimaryKey,\n} from \"drizzle-orm/pg-core\";\nimport {\n  mysqlTable,\n  varchar as mysqlVarchar,\n  datetime as mysqlDatetime,\n  boolean as mysqlBoolean,\n  int as mysqlInt,\n  primaryKey as mysqlPrimaryKey,\n} from \"drizzle-orm/mysql-core\";\nimport {\n  sqliteTable,\n  text as sqliteText,\n  integer as sqliteInteger,\n  primaryKey as sqlitePrimaryKey,\n} from \"drizzle-orm/sqlite-core\";\nimport { entityIdColumn } from \"@eristack/entity-id/drizzle\";\nimport type { DrizzleDialect } from \"./types.js\";\n\n/**\n * Optional **catalog** tables (profiles / field defs).\n * Detail **lines are not owned here** — inject `qupsLineColumns` into your\n * invoice/order/GR line table instead.\n */\nexport function createQupsProfileTables(\n  dialect: DrizzleDialect,\n  prefix = \"qups\",\n) {\n  switch (dialect) {\n    case \"pgsql\":\n      return createPgsqlProfileTables(prefix);\n    case \"mysql\":\n      return createMysqlProfileTables(prefix);\n    case \"sqlite\":\n      return createSqliteProfileTables(prefix);\n    default: {\n      const _e: never = dialect;\n      throw new Error(`Unsupported dialect: ${String(_e)}`);\n    }\n  }\n}\n\n/**\n * Optional side tables for stacked modifiers / dynamic field values,\n * keyed by your app line id (`line_id`).\n */\nexport function createQupsLineSideTables(\n  dialect: DrizzleDialect,\n  prefix = \"qups\",\n) {\n  switch (dialect) {\n    case \"pgsql\":\n      return createPgsqlSideTables(prefix);\n    case \"mysql\":\n      return createMysqlSideTables(prefix);\n    case \"sqlite\":\n      return createSqliteSideTables(prefix);\n    default: {\n      const _e: never = dialect;\n      throw new Error(`Unsupported dialect: ${String(_e)}`);\n    }\n  }\n}\n\n/** @deprecated Use createQupsProfileTables + createQupsLineSideTables + qupsLineColumns */\nexport function createQupsTables(dialect: DrizzleDialect, prefix = \"qups\") {\n  return {\n    ...createQupsProfileTables(dialect, prefix),\n    ...createQupsLineSideTables(dialect, prefix),\n  };\n}\n\nfunction createPgsqlProfileTables(prefix: string) {\n  const profiles = pgTable(`${prefix}_pricing_profiles`, {\n    id: entityIdColumn(\"pgsql\", \"id\").primaryKey(),\n    entityKey: pgText(\"entity_key\").notNull(),\n    defaultTruth: pgText(\"default_truth\").notNull(),\n    defaultCurrencyCode: pgText(\"default_currency_code\").notNull(),\n    defaultTaxRatePercent: pgText(\"default_tax_rate_percent\"),\n    defaultTaxMode: pgText(\"default_tax_mode\"),\n    active: pgBoolean(\"active\").notNull(),\n    createdAt: pgTimestamp(\"created_at\", { withTimezone: true, mode: \"date\" }).notNull(),\n    updatedAt: pgTimestamp(\"updated_at\", { withTimezone: true, mode: \"date\" }).notNull(),\n  });\n\n  const fields = pgTable(`${prefix}_pricing_fields`, {\n    id: entityIdColumn(\"pgsql\", \"id\").primaryKey(),\n    profileId: pgText(\"profile_id\").notNull(),\n    key: pgText(\"key\").notNull(),\n    label: pgText(\"label\"),\n    kind: pgText(\"kind\").notNull(),\n    role: pgText(\"role\").notNull(),\n    enabled: pgBoolean(\"enabled\").notNull(),\n    required: pgBoolean(\"required\"),\n    position: pgInteger(\"position\").notNull(),\n  });\n\n  const profileModifierKinds = pgTable(\n    `${prefix}_pricing_profile_modifier_kinds`,\n    {\n      profileId: pgText(\"profile_id\").notNull(),\n      kind: pgText(\"kind\").notNull(),\n    },\n    (t) => [pgPrimaryKey({ columns: [t.profileId, t.kind] })],\n  );\n\n  return { profiles, fields, profileModifierKinds };\n}\n\nfunction createMysqlProfileTables(prefix: string) {\n  const profiles = mysqlTable(`${prefix}_pricing_profiles`, {\n    id: entityIdColumn(\"mysql\", \"id\").primaryKey(),\n    entityKey: mysqlVarchar(\"entity_key\", { length: 255 }).notNull(),\n    defaultTruth: mysqlVarchar(\"default_truth\", { length: 64 }).notNull(),\n    defaultCurrencyCode: mysqlVarchar(\"default_currency_code\", {\n      length: 16,\n    }).notNull(),\n    defaultTaxRatePercent: mysqlVarchar(\"default_tax_rate_percent\", {\n      length: 32,\n    }),\n    defaultTaxMode: mysqlVarchar(\"default_tax_mode\", { length: 32 }),\n    active: mysqlBoolean(\"active\").notNull(),\n    createdAt: mysqlDatetime(\"created_at\", { mode: \"date\" }).notNull(),\n    updatedAt: mysqlDatetime(\"updated_at\", { mode: \"date\" }).notNull(),\n  });\n\n  const fields = mysqlTable(`${prefix}_pricing_fields`, {\n    id: entityIdColumn(\"mysql\", \"id\").primaryKey(),\n    profileId: mysqlVarchar(\"profile_id\", { length: 64 }).notNull(),\n    key: mysqlVarchar(\"key\", { length: 128 }).notNull(),\n    label: mysqlVarchar(\"label\", { length: 255 }),\n    kind: mysqlVarchar(\"kind\", { length: 32 }).notNull(),\n    role: mysqlVarchar(\"role\", { length: 32 }).notNull(),\n    enabled: mysqlBoolean(\"enabled\").notNull(),\n    required: mysqlBoolean(\"required\"),\n    position: mysqlInt(\"position\").notNull(),\n  });\n\n  const profileModifierKinds = mysqlTable(\n    `${prefix}_pricing_profile_modifier_kinds`,\n    {\n      profileId: mysqlVarchar(\"profile_id\", { length: 64 }).notNull(),\n      kind: mysqlVarchar(\"kind\", { length: 32 }).notNull(),\n    },\n    (t) => [mysqlPrimaryKey({ columns: [t.profileId, t.kind] })],\n  );\n\n  return { profiles, fields, profileModifierKinds };\n}\n\nfunction createSqliteProfileTables(prefix: string) {\n  const profiles = sqliteTable(`${prefix}_pricing_profiles`, {\n    id: entityIdColumn(\"sqlite\", \"id\").primaryKey(),\n    entityKey: sqliteText(\"entity_key\").notNull(),\n    defaultTruth: sqliteText(\"default_truth\").notNull(),\n    defaultCurrencyCode: sqliteText(\"default_currency_code\").notNull(),\n    defaultTaxRatePercent: sqliteText(\"default_tax_rate_percent\"),\n    defaultTaxMode: sqliteText(\"default_tax_mode\"),\n    active: sqliteInteger(\"active\", { mode: \"boolean\" }).notNull(),\n    createdAt: sqliteInteger(\"created_at\", { mode: \"timestamp_ms\" }).notNull(),\n    updatedAt: sqliteInteger(\"updated_at\", { mode: \"timestamp_ms\" }).notNull(),\n  });\n\n  const fields = sqliteTable(`${prefix}_pricing_fields`, {\n    id: entityIdColumn(\"sqlite\", \"id\").primaryKey(),\n    profileId: sqliteText(\"profile_id\").notNull(),\n    key: sqliteText(\"key\").notNull(),\n    label: sqliteText(\"label\"),\n    kind: sqliteText(\"kind\").notNull(),\n    role: sqliteText(\"role\").notNull(),\n    enabled: sqliteInteger(\"enabled\", { mode: \"boolean\" }).notNull(),\n    required: sqliteInteger(\"required\", { mode: \"boolean\" }),\n    position: sqliteInteger(\"position\").notNull(),\n  });\n\n  const profileModifierKinds = sqliteTable(\n    `${prefix}_pricing_profile_modifier_kinds`,\n    {\n      profileId: sqliteText(\"profile_id\").notNull(),\n      kind: sqliteText(\"kind\").notNull(),\n    },\n    (t) => [sqlitePrimaryKey({ columns: [t.profileId, t.kind] })],\n  );\n\n  return { profiles, fields, profileModifierKinds };\n}\n\nfunction createPgsqlSideTables(prefix: string) {\n  const modifiers = pgTable(`${prefix}_pricing_line_modifiers`, {\n    id: entityIdColumn(\"pgsql\", \"id\").primaryKey(),\n    lineId: pgText(\"line_id\").notNull(),\n    position: pgInteger(\"position\").notNull(),\n    kind: pgText(\"kind\").notNull(),\n    type: pgText(\"type\").notNull(),\n    percent: pgText(\"percent\"),\n    amount: pgText(\"amount\"),\n    currency: pgText(\"currency\"),\n  });\n\n  const fieldValues = pgTable(\n    `${prefix}_pricing_line_field_values`,\n    {\n      lineId: pgText(\"line_id\").notNull(),\n      fieldKey: pgText(\"field_key\").notNull(),\n      value: pgText(\"value\").notNull(),\n      currency: pgText(\"currency\"),\n    },\n    (t) => [pgPrimaryKey({ columns: [t.lineId, t.fieldKey] })],\n  );\n\n  return { modifiers, fieldValues };\n}\n\nfunction createMysqlSideTables(prefix: string) {\n  const modifiers = mysqlTable(`${prefix}_pricing_line_modifiers`, {\n    id: entityIdColumn(\"mysql\", \"id\").primaryKey(),\n    lineId: mysqlVarchar(\"line_id\", { length: 64 }).notNull(),\n    position: mysqlInt(\"position\").notNull(),\n    kind: mysqlVarchar(\"kind\", { length: 32 }).notNull(),\n    type: mysqlVarchar(\"type\", { length: 32 }).notNull(),\n    percent: mysqlVarchar(\"percent\", { length: 32 }),\n    amount: mysqlVarchar(\"amount\", { length: 64 }),\n    currency: mysqlVarchar(\"currency\", { length: 16 }),\n  });\n\n  const fieldValues = mysqlTable(\n    `${prefix}_pricing_line_field_values`,\n    {\n      lineId: mysqlVarchar(\"line_id\", { length: 64 }).notNull(),\n      fieldKey: mysqlVarchar(\"field_key\", { length: 128 }).notNull(),\n      value: mysqlVarchar(\"value\", { length: 512 }).notNull(),\n      currency: mysqlVarchar(\"currency\", { length: 16 }),\n    },\n    (t) => [mysqlPrimaryKey({ columns: [t.lineId, t.fieldKey] })],\n  );\n\n  return { modifiers, fieldValues };\n}\n\nfunction createSqliteSideTables(prefix: string) {\n  const modifiers = sqliteTable(`${prefix}_pricing_line_modifiers`, {\n    id: entityIdColumn(\"sqlite\", \"id\").primaryKey(),\n    lineId: sqliteText(\"line_id\").notNull(),\n    position: sqliteInteger(\"position\").notNull(),\n    kind: sqliteText(\"kind\").notNull(),\n    type: sqliteText(\"type\").notNull(),\n    percent: sqliteText(\"percent\"),\n    amount: sqliteText(\"amount\"),\n    currency: sqliteText(\"currency\"),\n  });\n\n  const fieldValues = sqliteTable(\n    `${prefix}_pricing_line_field_values`,\n    {\n      lineId: sqliteText(\"line_id\").notNull(),\n      fieldKey: sqliteText(\"field_key\").notNull(),\n      value: sqliteText(\"value\").notNull(),\n      currency: sqliteText(\"currency\"),\n    },\n    (t) => [sqlitePrimaryKey({ columns: [t.lineId, t.fieldKey] })],\n  );\n\n  return { modifiers, fieldValues };\n}\n\nexport type QupsProfileTables = ReturnType<typeof createQupsProfileTables>;\nexport type QupsLineSideTables = ReturnType<typeof createQupsLineSideTables>;\nexport type QupsTables = QupsProfileTables & QupsLineSideTables;\n","import { and, eq } from \"drizzle-orm\";\nimport type { ModifierKind } from \"../core/modifier.js\";\nimport type { QupsTruthMode } from \"../core/qups.js\";\nimport type {\n  PricingField,\n  PricingFieldKind,\n  PricingFieldRole,\n  PricingProfile,\n  PricingProfileStore,\n} from \"../core/stores/types.js\";\nimport type { QupsProfileTables } from \"./tables.js\";\nimport type { DrizzleDialect, DrizzleLikeDb } from \"./types.js\";\n\nexport interface CreateDrizzlePricingProfileStoreOptions {\n  dialect: DrizzleDialect;\n  db: DrizzleLikeDb;\n  tables: QupsProfileTables;\n}\n\nfunction asDate(v: unknown): Date {\n  return v instanceof Date ? v : new Date(String(v));\n}\n\nfunction toField(row: Record<string, unknown>): PricingField {\n  return {\n    id: String(row.id),\n    profileId: String(row.profileId),\n    key: String(row.key),\n    label: row.label == null ? undefined : String(row.label),\n    kind: String(row.kind) as PricingFieldKind,\n    role: String(row.role) as PricingFieldRole,\n    enabled: Boolean(row.enabled),\n    required: row.required == null ? undefined : Boolean(row.required),\n    position: Number(row.position),\n  };\n}\n\nexport function createDrizzlePricingProfileStore(\n  options: CreateDrizzlePricingProfileStoreOptions,\n): PricingProfileStore {\n  const { db, tables: t } = options;\n\n  async function loadProfile(\n    row: Record<string, unknown>,\n  ): Promise<PricingProfile> {\n    const id = String(row.id);\n    const fieldRows = (await db\n      .select()\n      .from(t.fields)\n      .where(eq(t.fields.profileId, id))) as Array<Record<string, unknown>>;\n    const kindRows = (await db\n      .select()\n      .from(t.profileModifierKinds)\n      .where(eq(t.profileModifierKinds.profileId, id))) as Array<\n      Record<string, unknown>\n    >;\n\n    const fields = fieldRows\n      .map(toField)\n      .sort((a, b) => a.position - b.position);\n\n    const allowedModifierKinds = kindRows.map(\n      (k) => String(k.kind) as ModifierKind,\n    );\n\n    return {\n      id,\n      entityKey: String(row.entityKey),\n      defaultTruth: String(row.defaultTruth) as QupsTruthMode,\n      defaultCurrencyCode: String(row.defaultCurrencyCode),\n      fields,\n      defaultTaxRatePercent:\n        row.defaultTaxRatePercent == null\n          ? undefined\n          : String(row.defaultTaxRatePercent),\n      defaultTaxMode:\n        row.defaultTaxMode == null\n          ? undefined\n          : (String(row.defaultTaxMode) as \"exclusive\" | \"inclusive\"),\n      allowedModifierKinds:\n        allowedModifierKinds.length > 0 ? allowedModifierKinds : undefined,\n      active: Boolean(row.active),\n      createdAt: asDate(row.createdAt),\n      updatedAt: asDate(row.updatedAt),\n    };\n  }\n\n  return {\n    async save(record) {\n      const existing = (await db\n        .select()\n        .from(t.profiles)\n        .where(eq(t.profiles.id, record.id))) as Array<\n        Record<string, unknown>\n      >;\n\n      const profileRow = {\n        id: record.id,\n        entityKey: record.entityKey,\n        defaultTruth: record.defaultTruth,\n        defaultCurrencyCode: record.defaultCurrencyCode,\n        defaultTaxRatePercent: record.defaultTaxRatePercent ?? null,\n        defaultTaxMode: record.defaultTaxMode ?? null,\n        active: record.active,\n        createdAt: record.createdAt,\n        updatedAt: record.updatedAt,\n      };\n\n      if (existing[0]) {\n        await db\n          .update(t.profiles)\n          .set({\n            entityKey: profileRow.entityKey,\n            defaultTruth: profileRow.defaultTruth,\n            defaultCurrencyCode: profileRow.defaultCurrencyCode,\n            defaultTaxRatePercent: profileRow.defaultTaxRatePercent,\n            defaultTaxMode: profileRow.defaultTaxMode,\n            active: profileRow.active,\n            updatedAt: profileRow.updatedAt,\n          })\n          .where(eq(t.profiles.id, record.id));\n      } else {\n        await db.insert(t.profiles).values(profileRow);\n      }\n\n      // Replace field rows + modifier kinds (relational, not JSON).\n      await db.delete(t.fields).where(eq(t.fields.profileId, record.id));\n      await db\n        .delete(t.profileModifierKinds)\n        .where(eq(t.profileModifierKinds.profileId, record.id));\n\n      if (record.fields.length) {\n        await db.insert(t.fields).values(\n          record.fields.map((f) => ({\n            id: f.id,\n            profileId: record.id,\n            key: f.key,\n            label: f.label ?? null,\n            kind: f.kind,\n            role: f.role,\n            enabled: f.enabled,\n            required: f.required ?? null,\n            position: f.position,\n          })),\n        );\n      }\n\n      if (record.allowedModifierKinds?.length) {\n        await db.insert(t.profileModifierKinds).values(\n          record.allowedModifierKinds.map((kind) => ({\n            profileId: record.id,\n            kind,\n          })),\n        );\n      }\n    },\n\n    async findById(id) {\n      const rows = (await db\n        .select()\n        .from(t.profiles)\n        .where(eq(t.profiles.id, id))) as Array<Record<string, unknown>>;\n      return rows[0] ? loadProfile(rows[0]) : null;\n    },\n\n    async findActiveByEntityKey(entityKey) {\n      const rows = (await db\n        .select()\n        .from(t.profiles)\n        .where(\n          and(eq(t.profiles.entityKey, entityKey), eq(t.profiles.active, true)),\n        )) as Array<Record<string, unknown>>;\n      const sorted = [...rows].sort(\n        (a, b) => asDate(b.updatedAt).getTime() - asDate(a.updatedAt).getTime(),\n      );\n      return sorted[0] ? loadProfile(sorted[0]) : null;\n    },\n\n    async listByEntityKey(entityKey) {\n      const rows = (await db\n        .select()\n        .from(t.profiles)\n        .where(eq(t.profiles.entityKey, entityKey))) as Array<\n        Record<string, unknown>\n      >;\n      const profiles = await Promise.all(rows.map(loadProfile));\n      return profiles.sort(\n        (a, b) => b.updatedAt.getTime() - a.updatedAt.getTime(),\n      );\n    },\n  };\n}\n","import { eq } from \"drizzle-orm\";\nimport type { ModifierKind } from \"../core/modifier.js\";\nimport type { QupsTruthMode } from \"../core/qups.js\";\nimport type {\n  PricingFieldValue,\n  PricingLineRecord,\n  PricingLineStore,\n  PricingModifierRecord,\n} from \"../core/stores/types.js\";\nimport type { QupsLineSideTables } from \"./tables.js\";\nimport type { DrizzleDialect, DrizzleLikeDb } from \"./types.js\";\n\n/**\n * App-owned detail table that includes `qupsLineColumns(...)`.\n * Must expose at least `id` plus the injected QUPS columns.\n * Parent document id is whatever you map via `ownerKeyColumn` (e.g. `invoiceId`).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyInjectableLineTable = any;\n\nexport interface CreateDrizzlePricingLineStoreOptions {\n  dialect: DrizzleDialect;\n  db: DrizzleLikeDb;\n  /** Your detail table (invoice_lines, order_lines, …) with qups columns mixed in. */\n  table: AnyInjectableLineTable;\n  /**\n   * JS property on the table/row that holds the parent document id.\n   * @default \"ownerKey\"\n   */\n  ownerKeyColumn?: string;\n  /**\n   * JS property for the line primary key.\n   * @default \"id\"\n   */\n  idColumn?: string;\n  /** Optional side tables keyed by your line id. */\n  modifiers?: QupsLineSideTables[\"modifiers\"];\n  fieldValues?: QupsLineSideTables[\"fieldValues\"];\n}\n\nfunction asDate(v: unknown): Date {\n  return v instanceof Date ? v : new Date(String(v));\n}\n\nfunction hasCol(table: object, name: string): boolean {\n  return name in table;\n}\n\nfunction toModifier(row: Record<string, unknown>): PricingModifierRecord {\n  return {\n    id: String(row.id),\n    position: Number(row.position),\n    kind: String(row.kind) as ModifierKind,\n    type: String(row.type) as \"percent\" | \"nominal\",\n    percent: row.percent == null ? undefined : String(row.percent),\n    amount: row.amount == null ? undefined : String(row.amount),\n    currency: row.currency == null ? undefined : String(row.currency),\n  };\n}\n\nfunction toFieldValue(row: Record<string, unknown>): PricingFieldValue {\n  return {\n    fieldKey: String(row.fieldKey),\n    value: String(row.value),\n    currency: row.currency == null ? undefined : String(row.currency),\n  };\n}\n\n/** Pricing columns only — never touches itemId / other app domain columns. */\nexport function qupsPatchFromRecord(\n  record: PricingLineRecord,\n  table: object,\n): Record<string, unknown> {\n  const patch: Record<string, unknown> = {\n    truth: record.truth,\n    quantity: record.quantity,\n    quantityRatioNumerator: record.quantityRatioNumerator ?? null,\n    quantityRatioDenominator: record.quantityRatioDenominator ?? null,\n    currency: record.currency,\n    unitPriceAmount: record.unitPriceAmount,\n    subtotalAmount: record.subtotalAmount,\n    taxRatePercent: record.taxRatePercent ?? null,\n    taxMode: record.taxMode ?? null,\n    taxAmount: record.taxAmount ?? null,\n    netAmount: record.netAmount ?? null,\n    grossAmount: record.grossAmount ?? null,\n  };\n\n  if (hasCol(table, \"profileId\")) {\n    patch.profileId = record.profileId ?? null;\n  }\n  if (hasCol(table, \"position\")) {\n    patch.position = record.position ?? null;\n  }\n  if (hasCol(table, \"updatedAt\")) {\n    patch.updatedAt = record.updatedAt;\n  }\n\n  return patch;\n}\n\nexport function pricingFieldsFromRow(\n  row: Record<string, unknown>,\n  options: {\n    idColumn?: string;\n    ownerKeyColumn?: string;\n  } = {},\n): Omit<PricingLineRecord, \"modifiers\" | \"fieldValues\"> {\n  const idColumn = options.idColumn ?? \"id\";\n  const ownerKeyColumn = options.ownerKeyColumn ?? \"ownerKey\";\n\n  return {\n    id: String(row[idColumn]),\n    ownerKey: String(row[ownerKeyColumn]),\n    profileId: row.profileId == null ? undefined : String(row.profileId),\n    truth: String(row.truth) as QupsTruthMode,\n    quantity: String(row.quantity),\n    quantityRatioNumerator:\n      row.quantityRatioNumerator == null\n        ? undefined\n        : String(row.quantityRatioNumerator),\n    quantityRatioDenominator:\n      row.quantityRatioDenominator == null\n        ? undefined\n        : String(row.quantityRatioDenominator),\n    currency: String(row.currency),\n    unitPriceAmount: String(row.unitPriceAmount),\n    subtotalAmount: String(row.subtotalAmount),\n    taxRatePercent:\n      row.taxRatePercent == null ? undefined : String(row.taxRatePercent),\n    taxMode:\n      row.taxMode == null\n        ? undefined\n        : (String(row.taxMode) as \"exclusive\" | \"inclusive\"),\n    taxAmount: row.taxAmount == null ? undefined : String(row.taxAmount),\n    netAmount: row.netAmount == null ? undefined : String(row.netAmount),\n    grossAmount: row.grossAmount == null ? undefined : String(row.grossAmount),\n    position: row.position == null ? undefined : Number(row.position),\n    createdAt: row.createdAt != null ? asDate(row.createdAt) : new Date(0),\n    updatedAt: row.updatedAt != null ? asDate(row.updatedAt) : new Date(0),\n    rowExtras: undefined,\n  };\n}\n\n/**\n * Drizzle store against an **app-owned** detail table with injected QUPS columns.\n * Updates only pricing columns so `itemId` and other domain fields stay intact.\n * On insert, merges `record.rowExtras` (e.g. `{ itemId: \"…\" }`).\n */\nexport function createDrizzlePricingLineStore(\n  options: CreateDrizzlePricingLineStoreOptions,\n): PricingLineStore {\n  const {\n    db,\n    table,\n    ownerKeyColumn = \"ownerKey\",\n    idColumn = \"id\",\n    modifiers,\n    fieldValues,\n  } = options;\n\n  async function loadSide(\n    id: string,\n  ): Promise<{\n    modifiers: PricingModifierRecord[];\n    fieldValues: PricingFieldValue[];\n  }> {\n    let modList: PricingModifierRecord[] = [];\n    let valueList: PricingFieldValue[] = [];\n\n    if (modifiers) {\n      const modRows = (await db\n        .select()\n        .from(modifiers)\n        .where(eq(modifiers.lineId, id))) as Array<Record<string, unknown>>;\n      modList = modRows.map(toModifier).sort((a, b) => a.position - b.position);\n    }\n\n    if (fieldValues) {\n      const valueRows = (await db\n        .select()\n        .from(fieldValues)\n        .where(eq(fieldValues.lineId, id))) as Array<Record<string, unknown>>;\n      valueList = valueRows.map(toFieldValue);\n    }\n\n    return { modifiers: modList, fieldValues: valueList };\n  }\n\n  async function loadLine(\n    row: Record<string, unknown>,\n  ): Promise<PricingLineRecord> {\n    const base = pricingFieldsFromRow(row, { idColumn, ownerKeyColumn });\n    const side = await loadSide(base.id);\n    return { ...base, ...side };\n  }\n\n  async function replaceSide(record: PricingLineRecord) {\n    if (modifiers) {\n      await db.delete(modifiers).where(eq(modifiers.lineId, record.id));\n      if (record.modifiers.length) {\n        await db.insert(modifiers).values(\n          record.modifiers.map((m) => ({\n            id: m.id,\n            lineId: record.id,\n            position: m.position,\n            kind: m.kind,\n            type: m.type,\n            percent: m.percent ?? null,\n            amount: m.amount ?? null,\n            currency: m.currency ?? null,\n          })),\n        );\n      }\n    }\n\n    if (fieldValues) {\n      await db.delete(fieldValues).where(eq(fieldValues.lineId, record.id));\n      if (record.fieldValues.length) {\n        await db.insert(fieldValues).values(\n          record.fieldValues.map((v) => ({\n            lineId: record.id,\n            fieldKey: v.fieldKey,\n            value: v.value,\n            currency: v.currency ?? null,\n          })),\n        );\n      }\n    }\n  }\n\n  return {\n    async save(record) {\n      const idCol = table[idColumn];\n      const existing = (await db\n        .select()\n        .from(table)\n        .where(eq(idCol, record.id))) as Array<Record<string, unknown>>;\n\n      const patch = qupsPatchFromRecord(record, table);\n      patch[ownerKeyColumn] = record.ownerKey;\n\n      if (existing[0]) {\n        // Pricing-only update — do not clobber itemId / other app columns.\n        await db.update(table).set(patch).where(eq(idCol, record.id));\n      } else {\n        const insertRow: Record<string, unknown> = {\n          ...(record.rowExtras ?? {}),\n          ...patch,\n          [idColumn]: record.id,\n          [ownerKeyColumn]: record.ownerKey,\n        };\n        if (hasCol(table, \"createdAt\") && insertRow.createdAt == null) {\n          insertRow.createdAt = record.createdAt;\n        }\n        await db.insert(table).values(insertRow);\n      }\n\n      await replaceSide(record);\n    },\n\n    async findById(id) {\n      const rows = (await db\n        .select()\n        .from(table)\n        .where(eq(table[idColumn], id))) as Array<Record<string, unknown>>;\n      return rows[0] ? loadLine(rows[0]) : null;\n    },\n\n    async listByOwnerKey(ownerKey) {\n      const rows = (await db\n        .select()\n        .from(table)\n        .where(eq(table[ownerKeyColumn], ownerKey))) as Array<\n        Record<string, unknown>\n      >;\n      const lines = await Promise.all(rows.map(loadLine));\n      return lines.sort((a, b) => (a.position ?? 0) - (b.position ?? 0));\n    },\n\n    async delete(id) {\n      if (modifiers) {\n        await db.delete(modifiers).where(eq(modifiers.lineId, id));\n      }\n      if (fieldValues) {\n        await db.delete(fieldValues).where(eq(fieldValues.lineId, id));\n      }\n      await db.delete(table).where(eq(table[idColumn], id));\n    },\n  };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAKO;AACP,wBAIO;AACP,yBAGO;AACP,qBAEO;AAGP,IAAM,kBAAkB;AAoBxB,SAAS,sBAAsB,SAAyB;AACtD,UAAQ,SAAS;AAAA,IACf,KAAK;AACH,aAAO;AAAA,QACL,cAAU,eAAAA,SAAU,YAAY,EAAE,QAAQ,gBAAgB,CAAC,EAAE,QAAQ;AAAA,MACvE;AAAA,IACF,KAAK;AACH,aAAO;AAAA,QACL,cAAU,kBAAAC,SAAa,YAAY,EAAE,QAAQ,gBAAgB,CAAC,EAAE,QAAQ;AAAA,MAC1E;AAAA,IACF,KAAK;AACH,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M,eAAe,UAAU;AAC7B,YAAM,OAAQ,MAAM,GACjB,OAAO,EACP,KAAK,KAAK,EACV,UAAM,wBAAG,MAAM,cAAc,GAAG,QAAQ,CAAC;AAG5C,YAAM,QAAQ,MAAM,QAAQ,IAAI,KAAK,IAAI,QAAQ,CAAC;AAClD,aAAO,MAAM,KAAK,CAAC,GAAG,OAAO,EAAE,YAAY,MAAM,EAAE,YAAY,EAAE;AAAA,IACnE;AAAA,IAEA,MAAM,OAAO,IAAI;AACf,UAAI,WAAW;AACb,cAAM,GAAG,OAAO,SAAS,EAAE,UAAM,wBAAG,UAAU,QAAQ,EAAE,CAAC;AAAA,MAC3D;AACA,UAAI,aAAa;AACf,cAAM,GAAG,OAAO,WAAW,EAAE,UAAM,wBAAG,YAAY,QAAQ,EAAE,CAAC;AAAA,MAC/D;AACA,YAAM,GAAG,OAAO,KAAK,EAAE,UAAM,wBAAG,MAAM,QAAQ,GAAG,EAAE,CAAC;AAAA,IACtD;AAAA,EACF;AACF;","names":["pgVarchar","mysqlVarchar","sqliteText","pgText","pgInteger","pgTimestamp","mysqlInt","mysqlDatetime","sqliteInteger","import_pg_core","import_mysql_core","import_sqlite_core","import_drizzle","pgText","pgBoolean","pgTimestamp","pgInteger","pgPrimaryKey","mysqlVarchar","mysqlBoolean","mysqlDatetime","mysqlInt","mysqlPrimaryKey","sqliteText","sqliteInteger","sqlitePrimaryKey","import_drizzle_orm","asDate"]}