@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 CHANGED
@@ -766,11 +766,53 @@ function crmDiscussionReferenceHref(current, target, basePath = "/admin/") {
766
766
  return next.toString();
767
767
  }
768
768
 
769
+ // src/time.ts
770
+ var DATE_FIELDS = new Map(
771
+ Object.entries(CRM_SCHEMA.entities).map(([ns, entity]) => [
772
+ ns,
773
+ new Set(
774
+ Object.entries(entity.attrs).filter(([, attr]) => attr.type === "date").map(([label]) => label)
775
+ )
776
+ ])
777
+ );
778
+ function epochOf(value) {
779
+ if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
780
+ if (typeof value !== "string") return void 0;
781
+ const parsed = Date.parse(value);
782
+ return Number.isNaN(parsed) ? void 0 : parsed;
783
+ }
784
+ function rowAsWritten(ns, row) {
785
+ const dates = DATE_FIELDS.get(ns);
786
+ if (!dates?.size) return row;
787
+ const out = { ...row };
788
+ for (const field of dates) {
789
+ if (!(field in out)) continue;
790
+ const parsed = epochOf(out[field]);
791
+ if (parsed === void 0) delete out[field];
792
+ else out[field] = parsed;
793
+ }
794
+ return out;
795
+ }
796
+ function resultAsWritten(result) {
797
+ const out = { ...result };
798
+ for (const [ns, rows] of Object.entries(out)) {
799
+ if (Array.isArray(rows)) out[ns] = rows.map((row) => rowAsWritten(ns, row));
800
+ }
801
+ return out;
802
+ }
803
+
769
804
  // src/deps.ts
805
+ function readingAsWritten(db) {
806
+ return {
807
+ query: async (query) => resultAsWritten(await db.query(query)),
808
+ transact: (ops, opts) => db.transact(ops, opts),
809
+ aggregate: (ns, spec, queryOpts) => db.aggregate(ns, spec, queryOpts)
810
+ };
811
+ }
770
812
  function resolveDeps(deps) {
771
813
  return {
772
814
  crm: deps.crm,
773
- db: deps.db,
815
+ db: readingAsWritten(deps.db),
774
816
  now: deps.now ?? Date.now,
775
817
  newId: deps.newId ?? (() => crypto.randomUUID())
776
818
  };