@odla-ai/crm 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +43 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -1
- package/dist/index.js.map +1 -1
- package/dist/ui/index.js +221 -2
- package/dist/ui/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -647,11 +647,53 @@ function crmDiscussionReferenceHref(current, target, basePath = "/admin/") {
|
|
|
647
647
|
return next.toString();
|
|
648
648
|
}
|
|
649
649
|
|
|
650
|
+
// src/time.ts
|
|
651
|
+
var DATE_FIELDS = new Map(
|
|
652
|
+
Object.entries(CRM_SCHEMA.entities).map(([ns, entity]) => [
|
|
653
|
+
ns,
|
|
654
|
+
new Set(
|
|
655
|
+
Object.entries(entity.attrs).filter(([, attr]) => attr.type === "date").map(([label]) => label)
|
|
656
|
+
)
|
|
657
|
+
])
|
|
658
|
+
);
|
|
659
|
+
function epochOf(value) {
|
|
660
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
661
|
+
if (typeof value !== "string") return void 0;
|
|
662
|
+
const parsed = Date.parse(value);
|
|
663
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
664
|
+
}
|
|
665
|
+
function rowAsWritten(ns, row) {
|
|
666
|
+
const dates = DATE_FIELDS.get(ns);
|
|
667
|
+
if (!dates?.size) return row;
|
|
668
|
+
const out = { ...row };
|
|
669
|
+
for (const field of dates) {
|
|
670
|
+
if (!(field in out)) continue;
|
|
671
|
+
const parsed = epochOf(out[field]);
|
|
672
|
+
if (parsed === void 0) delete out[field];
|
|
673
|
+
else out[field] = parsed;
|
|
674
|
+
}
|
|
675
|
+
return out;
|
|
676
|
+
}
|
|
677
|
+
function resultAsWritten(result) {
|
|
678
|
+
const out = { ...result };
|
|
679
|
+
for (const [ns, rows] of Object.entries(out)) {
|
|
680
|
+
if (Array.isArray(rows)) out[ns] = rows.map((row) => rowAsWritten(ns, row));
|
|
681
|
+
}
|
|
682
|
+
return out;
|
|
683
|
+
}
|
|
684
|
+
|
|
650
685
|
// src/deps.ts
|
|
686
|
+
function readingAsWritten(db) {
|
|
687
|
+
return {
|
|
688
|
+
query: async (query) => resultAsWritten(await db.query(query)),
|
|
689
|
+
transact: (ops, opts) => db.transact(ops, opts),
|
|
690
|
+
aggregate: (ns, spec, queryOpts) => db.aggregate(ns, spec, queryOpts)
|
|
691
|
+
};
|
|
692
|
+
}
|
|
651
693
|
function resolveDeps(deps) {
|
|
652
694
|
return {
|
|
653
695
|
crm: deps.crm,
|
|
654
|
-
db: deps.db,
|
|
696
|
+
db: readingAsWritten(deps.db),
|
|
655
697
|
now: deps.now ?? Date.now,
|
|
656
698
|
newId: deps.newId ?? (() => crypto.randomUUID())
|
|
657
699
|
};
|