@ai-matrx/records 0.96.1 → 0.96.2

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.
@@ -1,5 +1,5 @@
1
1
  import { d as RecordsDataSource, a as RecordsConfig } from '../ports-DEkN-WfA.cjs';
2
- import { T as TemplateSpec } from '../types-SezYoQ5_.cjs';
2
+ import { T as TemplateSpec } from '../types-BhGs3f8s.cjs';
3
3
  import { P as PgError } from '../record-zwSBU5PQ.cjs';
4
4
  import '../field-DjS7iId2.cjs';
5
5
  import '../subscription-ycCVo9e2.cjs';
@@ -1,5 +1,5 @@
1
1
  import { d as RecordsDataSource, a as RecordsConfig } from '../ports-YOhD5T7h.js';
2
- import { T as TemplateSpec } from '../types-Cl0b_Hy8.js';
2
+ import { T as TemplateSpec } from '../types-DAruHh1G.js';
3
3
  import { P as PgError } from '../record-zwSBU5PQ.js';
4
4
  import '../field-D-1OKy5r.js';
5
5
  import '../subscription-DucBLG-Y.js';
@@ -582,7 +582,20 @@ function checklistSpec(checklist, tables, forms, documents) {
582
582
  };
583
583
  }
584
584
  function automationHeld(a) {
585
- return `The automation "${a.name}" is held for lane 11: no store door runs automations yet, so a template carrying one is held, never installed without it.`;
585
+ return `The automation "${a.name}" has a trigger the install cannot set up (${a.when.event}); a template automation runs on created, due or overdue.`;
586
+ }
587
+ function automationSpec(a, fieldIds) {
588
+ const text = (a.message?.trim() || a.then.trim()).slice(0, 600);
589
+ const actions = [{ do: "notify", to: { author: true }, text }];
590
+ const at = a.at && /^([01][0-9]|2[0-3]):[0-5][0-9]$/.test(a.at) ? a.at : "09:00";
591
+ if (a.when.event === "created") return { name: a.name, trigger: { on: "row_added" }, actions };
592
+ if (a.when.event === "due" || a.when.event === "overdue") {
593
+ const field = a.when.field ? fieldIds[a.when.field] : void 0;
594
+ if (!field) throw new Error(`The automation "${a.name}" waits for "${a.when.field ?? "?"}", which "${a.when.table}" does not declare.`);
595
+ const offset = a.when.event === "due" ? -Math.max(0, Math.round(a.when.daysBefore ?? 0)) : 1;
596
+ return { name: a.name, trigger: { on: "date_arrives", field, offset_days: offset, at }, actions };
597
+ }
598
+ throw new Error(automationHeld(a));
586
599
  }
587
600
  function bookingColumnsProblem(tables, booking) {
588
601
  const t = tables.find((x) => x.token === booking.table);
@@ -1954,6 +1967,8 @@ function compileInstallPlan(written) {
1954
1967
  }
1955
1968
  const needIds = /* @__PURE__ */ new Set([
1956
1969
  ...spec.extras.filter((e) => e.kind === "document" || e.kind === "row_action").map((e) => e.table),
1970
+ // A date reminder names its date Field by id.
1971
+ ...spec.extras.filter((e) => e.kind === "automation" && e.when.field).map((e) => e.when.table),
1957
1972
  ...spec.views.filter((v) => v.anyOf && Object.keys(v.anyOf).length).map((v) => v.table)
1958
1973
  ]);
1959
1974
  const fieldRefs = (token) => {
@@ -2119,7 +2134,13 @@ function compileInstallPlan(written) {
2119
2134
  });
2120
2135
  break;
2121
2136
  case "automation":
2122
- throw new Error(automationHeld(e));
2137
+ steps.push({
2138
+ label: `automations.${e.token}`,
2139
+ door: "automation_declare",
2140
+ args: { p_organization_id: "${org}", p_table_id: tableRef(e.when.table), p_spec: automationSpec(e, fieldRefs(e.when.table)), p_automation_id: null },
2141
+ save: { [`automations.${e.token}`]: ["automation_id"] }
2142
+ });
2143
+ break;
2123
2144
  default:
2124
2145
  throw new Error(`The install plan has no door for a ${e.kind} yet ("${e.token ?? "?"}"), so this template cannot be declared until it does.`);
2125
2146
  }