@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
99 lines (97 loc) • 3.25 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/testing/index.ts
var testing_exports = {};
__export(testing_exports, {
createMemoryPricingLineStore: () => createMemoryPricingLineStore,
createMemoryPricingProfileStore: () => createMemoryPricingProfileStore
});
module.exports = __toCommonJS(testing_exports);
// 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);
}
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createMemoryPricingLineStore,
createMemoryPricingProfileStore
});
//# sourceMappingURL=index.cjs.map