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

71 lines • 2.09 kB
// src/core/stores/memory.ts function cloneField(f) { return { ...f }; } function cloneProfile(p) { return { ...p, fields: p.fields.map(cloneField), allowedModifierKinds: p.allowedModifierKinds ? [...p.allowedModifierKinds] : void 0, createdAt: new Date(p.createdAt), updatedAt: new Date(p.updatedAt) }; } function cloneModifier(m) { return { ...m }; } function cloneValue(v) { return { ...v }; } function cloneLine(r) { return { ...r, modifiers: r.modifiers.map(cloneModifier), fieldValues: r.fieldValues.map(cloneValue), rowExtras: r.rowExtras ? { ...r.rowExtras } : void 0, createdAt: new Date(r.createdAt), updatedAt: new Date(r.updatedAt) }; } function createMemoryPricingProfileStore() { const byId = /* @__PURE__ */ new Map(); return { async save(record) { byId.set(record.id, cloneProfile(record)); }, async findById(id) { const row = byId.get(id); return row ? cloneProfile(row) : null; }, async findActiveByEntityKey(entityKey) { const rows = [...byId.values()].filter((p) => p.entityKey === entityKey && p.active).sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime()); return rows[0] ? cloneProfile(rows[0]) : null; }, async listByEntityKey(entityKey) { return [...byId.values()].filter((p) => p.entityKey === entityKey).sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime()).map(cloneProfile); } }; } function createMemoryPricingLineStore() { const byId = /* @__PURE__ */ new Map(); return { async save(record) { byId.set(record.id, cloneLine(record)); }, async findById(id) { const row = byId.get(id); return row ? cloneLine(row) : null; }, async listByOwnerKey(ownerKey) { return [...byId.values()].filter((r) => r.ownerKey === ownerKey).sort((a, b) => (a.position ?? 0) - (b.position ?? 0)).map(cloneLine); }, async delete(id) { byId.delete(id); } }; } export { createMemoryPricingLineStore, createMemoryPricingProfileStore }; //# sourceMappingURL=index.js.map