@plitzi/sdk-shared 0.37.1 → 0.37.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/dist/actions/cron.d.ts +21 -12
  3. package/dist/actions/cron.mjs +48 -17
  4. package/dist/actions/index.d.ts +1 -1
  5. package/dist/actions/index.mjs +7 -7
  6. package/dist/actions/triggers.d.ts +4 -0
  7. package/dist/actions/triggers.mjs +4 -1
  8. package/dist/authoring/declare.d.ts +21 -0
  9. package/dist/dataSource/getBindingsDetails.mjs +21 -20
  10. package/dist/dataSource/utility/checkboxParams.d.ts +11 -0
  11. package/dist/dataSource/utility/checkboxParams.mjs +12 -0
  12. package/dist/helpers/index.mjs +13 -12
  13. package/dist/helpers/twigWrapper/Evaluator/Evaluator.mjs +21 -6
  14. package/dist/helpers/twigWrapper/Parser/ExpressionParser.mjs +1 -1
  15. package/dist/helpers/twigWrapper/filters/filters.mjs +10 -5
  16. package/dist/helpers/twigWrapper/index.d.ts +1 -0
  17. package/dist/helpers/twigWrapper/index.mjs +4 -3
  18. package/dist/helpers/twigWrapper/tokens/hasTemplateSyntax.d.ts +9 -0
  19. package/dist/helpers/twigWrapper/tokens/hasTemplateSyntax.mjs +4 -0
  20. package/dist/hooks/usePlitziServiceContext.d.ts +1 -1
  21. package/dist/index.mjs +64 -63
  22. package/dist/navigation/routes.mjs +27 -27
  23. package/dist/schema/serverElements.d.ts +5 -0
  24. package/dist/schema/serverElements.mjs +15 -14
  25. package/dist/state/index.mjs +2 -2
  26. package/dist/state/runtimeStatePersist.d.ts +17 -0
  27. package/dist/state/runtimeStatePersist.mjs +62 -9
  28. package/dist/store/index.d.ts +33 -33
  29. package/dist/theme/ThemeProvider.d.ts +1 -1
  30. package/dist/types/ActionTypes.d.ts +189 -0
  31. package/dist/types/ServerTypes.d.ts +52 -1
  32. package/dist/types/StoreTypes.d.ts +1 -1
  33. package/package.json +20 -12
package/CHANGELOG.md CHANGED
@@ -1,5 +1,147 @@
1
1
  # @plitzi/sdk-shared
2
2
 
3
+ ## 0.37.2
4
+
5
+ ### Patch Changes
6
+
7
+ - ## Authoring and agents
8
+ - **A step's params are templates in full.** Only a bare name (`{{ post.slug }}`) used to be recognised, so a
9
+ condition or a loop in a `setState` or a webhook body was handed on as its own text — a flag set to
10
+ `{% if … %}1{% endif %}` stored the template, a non-empty string every later check read as true. Any `{{ }}` or
11
+ `{% %}` in a param is now evaluated; what it resolves to is data and is not evaluated again.
12
+ - **Twig tests work.** `x is defined`, `is empty`, `is null`, `is iterable`, `is even`, `is odd` (and `is not …`) used
13
+ to be read as comparisons with a variable of that name — `x is defined` answered true exactly when `x` was not
14
+ defined. Anything else on the right of `is` still compares.
15
+ - **A group takes an access chain.** `(rows|find('id', 3)).title` read the whole row; the key after the parenthesis
16
+ was never parsed.
17
+ - **An expression that chose to be empty renders empty** under `keepEmptyTokens`. A kept token is for a name still
18
+ waiting for a value; `{{ on ? 'active' : '' }}` said "nothing" on purpose, and handing back its text made the
19
+ empty branch a non-empty string.
20
+ - **Checkbox params written as text are booleans.** `dateConverter({ isUnix: 'false' })` read `'false'` as yes and
21
+ gave an ISO date back raw. Every utility's checkbox params are normalised before its callback runs.
22
+ - **`condition-starts-visible`** warns about a visibility computed from data on an element that starts on screen: it
23
+ is drawn until its provider answers and then hidden — an empty state or a "get started" card flashing past on
24
+ every load. `visible: false` makes it wait hidden. The export reads a visibility binding back in its place, so a
25
+ space whose condition is not its last binding round-trips unchanged.
26
+ - **A source named by its short id inside a binding's template is refused** with the full name, as it already was in
27
+ a flow: `{{ stats.total }}` resolved to nothing and the element showed its empty branch.
28
+ - **`activeOn(class, pageIds)`** marks a menu's current entry from `navigation.currentPageId` — one binding for a menu
29
+ kept in a layout. `variantFrom` now says `append: 'true'`, which is what it did.
30
+ - **Two elements with one id** name where the first one was written. **`template-never-resolved`** warns about a
31
+ condition left in an attribute, which only resolves `{{ name|filter }}` tokens.
32
+ - **The authoring skill is a folder**: `SKILL.md` plus references for layouts, data and visibility, templates,
33
+ flows, structure, testing and a review checklist. `plitzi create` copies all of it, and writes an `AGENTS.md`
34
+ (imported by `CLAUDE.md`) pointing any agent at it.
35
+
36
+ - **A new space starts on a page worth keeping.** The space `POST /spaces` and `plitzi create` both begin from is
37
+ redesigned: a top bar with the theme switch, a hero with two calls to action, and six guides — each a card linking to
38
+ its page of the docs (`https://plitzi.com/docs/…`). Every link used to be `#`, and one promised a course that does
39
+ not exist. The palette is a set of light/dark tokens in Geist, the guides are one list mapped to one card, and the
40
+ bands of the page share a `shell` class — the page is written the way the authoring skill asks a space to be.
41
+ - **The copy `plitzi create` writes passes its own project's lint.** An import of the package that would not fit
42
+ 120 columns is wrapped one name per line, as the project's formatter would wrap it.
43
+
44
+ ## Server actions and scheduled jobs
45
+
46
+ **Scheduled jobs across replicas, out of the box, on the database a deployment already runs.** The scheduler and the
47
+ workers were already the package's; where the jobs wait was left to each deployment to write — and a queue is the part
48
+ that is easiest to get subtly wrong. Two helpers now build the adapters over a store the deployment owns, without the
49
+ package opening a connection or keeping data of its own:
50
+
51
+ - `@plitzi/sdk-server/mongo` — `createMongoJobQueue({ db })` and `createMongoKv({ db })`, over a `Db` (or a getter for a
52
+ client that reconnects). Creates the indexes its queries need; `mongodb` is an optional peer, used for its types.
53
+ - `@plitzi/sdk-server/mysql` — `createMysqlJobQueue({ pool })` and `createMysqlKv({ pool })`, over a `mysql2` pool.
54
+ Each job is claimed by a single-row compare-and-set, so replicas claiming at once never deadlock. Creates its three
55
+ tables on first use, or hands them to your own migrations through `mysqlJobSchemaStatements()`.
56
+
57
+ Every instant is the database server's, never a replica's. The in-process queue and both helpers pass one contract test
58
+ suite: exactly-once enqueue, atomic claims, leases that lapse and are reaped, heartbeats, settlements ignored from a
59
+ worker that lost its claim, refunded hand-backs, schedules advanced by compare-and-set, operator retry and cancel.
60
+
61
+ **`closeOnSignals(server, { afterClose })`** closes the server on SIGTERM/SIGINT and exits only once it has — so a
62
+ deploy finishes the jobs a replica is running and leaves the waiting ones for the next. A second signal exits at once.
63
+ Opt-in: a host with its own signal handling calls `server.close()` itself. Projects from `plitzi create` use it.
64
+
65
+ **A replica that is told to stop finishes the jobs it is running — and only those.** `server.close()` (and the job
66
+ worker's `stop()`) now waits for every running job to end however long past its lease that is, and keeps renewing
67
+ their claims while it waits. It used to stop renewing the moment the drain began and give up at the lease: a job longer
68
+ than its lease was taken over by another replica and run a second time while the first was still finishing it, and the
69
+ process exited in the middle of it. What is still waiting is not touched — it stays in the shared queue for the replica
70
+ that is staying or the one the deploy starts — and a job claimed in the instant the stop arrived is handed back with its
71
+ attempt refunded, never started. A run is bounded by its own timeout, which is the number an orchestrator's grace period
72
+ has to cover.
73
+
74
+ - **An every-minute schedule fired every other minute.** After producing a fire, the scheduler asked for the next
75
+ one from `lateness + 1 minute`, and `cronNextFire` rounds up to a whole minute — so a sweep that ran even a second
76
+ late (with the default 15-second sweep, nearly all of them) skipped the minute it should have produced. It now asks
77
+ from the minute after the one the sweep ran in. Only expressions with consecutive-minute fires were affected;
78
+ hourly and daily schedules were not.
79
+ - **A job that gives up says which step failed and why.** Its `error` and the failed attempt in its history used to
80
+ read "the flow ended failed" for every failure there is; they now read `step "<id>" failed: <message>`, taken from
81
+ the run's outline — already redacted of every credential the run resolved, so nothing reaches the job that the
82
+ run history would not show.
83
+ - **`apiContainer` takes `refreshSeconds`**: it asks again on its own every N seconds, for a page showing something
84
+ still moving — a queue, a feed, a status board. It is the same refresh `performQuery` runs, so it works for both
85
+ runtimes (a browser request is sent again; a server provider asks for its own RSC slice again). It pauses while
86
+ the tab is hidden and never starts a refresh while the last one is in flight. `0`, the default, never does. Before
87
+ this a live server provider needed a plugin element of its own to call `useRscRefresh` on a timer: `onApiSuccess`
88
+ never fires for a server provider, so there was no way to author the loop. The builder shows it as "Refresh every
89
+ (s)" for either runtime.
90
+ - **`onApiSuccess` / `onApiError` fire for a server provider.** The declaration offered them for every
91
+ `apiContainer`, but they were decided from the browser request alone — which a `runtime: 'server'` provider never
92
+ makes — so a flow wired to them never ran. They now fire when the provider's slice arrives (or the payload arrives
93
+ without it), and again on each refresh, the same as a browser refetch. A payload resolved for another page fires
94
+ neither. **A space that wired a flow to one of them will now see it run.**
95
+ - **The theme toggle shows one icon by default.** It renders both — which one is right depends on stored state, and
96
+ markup that depended on it would differ between the server and the browser — and until now every space had to copy
97
+ ten lines of `customCss` to hide the other; one that did not showed a sun and a moon side by side. The SDK's base
98
+ layer now shows the icon of the scheme in use, and a space's own rule still wins.
99
+ - **`variantFrom(cls, source)`** in `@plitzi/sdk-authoring` binds which of a CLASS's variants an element wears to a
100
+ value in the data — a status pill that is amber while a job waits and green once it is done. Written by hand the
101
+ variant key is the trap: it names the selector the variants belong to, and the element's type (`text.base`) is a
102
+ different selector from its class (`statusPill.base`), so the element rendered with no variant and nothing
103
+ reported it. The helper takes the key from the class declaration.
104
+ - **`authorSpace` refuses a flow template that reads a source by its short name.** A binding completes the prefix
105
+ (`jobRows.item.id` → `list_jobRows.item.id`), so the short form is the one an author learns first; a step's params
106
+ are read as written, and there it resolved to nothing — a row's button posted an empty id and every layer below
107
+ reported success. The error names the full source. A root that is a step of the same flow is left alone.
108
+ - New example, [`05-with-server-actions/05-schedules`](../examples/05-with-server-actions/05-schedules): scheduled and
109
+ delayed jobs on a self-hosted server, with the `ActionJobQueue` and `kv` seams written out in full over one SQLite
110
+ file, two replicas sharing it, failover when one is killed, and a board that watches it happen.
111
+
112
+ ## Rendering, data and styles
113
+ - **A server element inside a layout is resolved.** `collectServerElements` walked the page alone, so a
114
+ `runtime: 'server'` provider in a layout — a dashboard's sidebar, a section's header — was never resolved: the RSC
115
+ payload came back empty and the element rendered with nothing. It now walks the page and every shell in its layout
116
+ chain.
117
+ - **The twig `date` filter reads an epoch.** `new Date("1790143200000")` is Invalid Date, so an epoch in milliseconds
118
+ handed over as text — how an attribute passes one — formatted as nothing. A number, or a string of digits, is now
119
+ read as milliseconds.
120
+ - **An action is called by its name, not by its trigger kind.** `actionName` took the first trigger's title, and a
121
+ trigger nobody named is titled with its kind — so every rendered action in a workspace read "render" and every clock
122
+ "schedule". A title that only repeats the kind is no longer a name, and `defineAction` titles each trigger with the
123
+ action's name.
124
+ - **`variant` on an element that wears a class is that class's variant** when the class declares it and the type does
125
+ not. Keyed by the type, `text({ class: avatar, variant: 'violet' })` named `text--violet`, a selector nothing wears,
126
+ and rendered with no variant at all. Exporting a document back to authoring reads the same key back into `variant`.
127
+ - **`variantFrom` takes `{ slot, template }`**, where `template` turns a value into a variant name for data that does
128
+ not already speak in them — `"{{ source == 'code' ? 'on' : '' }}"`. The third argument was the slot name alone.
129
+ - **Entry declarations no longer alternate with `export {}`.** In `@plitzi/sdk-server` and `@plitzi/sdk-mcp` a repeated
130
+ `build:dev` left some `dist/<entry>.d.ts` as a ten-byte `export {}`, and consumers saw "has no exported member". The
131
+ cause was `insertTypesEntry` writing a types entry over the real declaration of the same path; it is gone.
132
+ - **Signing in keeps what a guest was doing.** `runtimeStatePersist` reset `runtime.state` whenever its owner changed,
133
+ and a guest becoming a user is a change — so a sign-in screen that remembered where to send somebody (`?redirect=`)
134
+ forgot it the moment the session arrived, and the sign-in ended on the fallback page instead. Only a change FROM an
135
+ account resets now: one account's state still never reaches the next, and a guest has no account to protect.
136
+
137
+ **A value with functions inside functions is written as it was given, and fast.** A CSS value was split into layers
138
+ at commas by a pattern that could only see one level of parentheses, so `var(--bg, light-dark(#fff, #111))` was cut at
139
+ its inner comma and half a function went on into the stylesheet. The half was then tokenised by an expression that
140
+ nested one quantifier inside another and backtracked exponentially on it — nearly two seconds for thirty characters,
141
+ on every generation of that selector's cache. Both are now one linear scan that splits only outside parentheses and
142
+ quotes. Generated caches keep the spacing the value was written with inside functions (`repeat(3, minmax(0, 1fr))`,
143
+ `color-mix(in oklab, oklch(…) 50%, transparent)`), where they used to drop it after the first comma.
144
+
3
145
  ## 0.37.1
4
146
 
5
147
  ### Patch Changes
@@ -10,25 +10,34 @@ type WallClock = {
10
10
  month: number;
11
11
  weekday: number;
12
12
  };
13
+ export declare const zonedClock: (at: Date, timeZone: string) => WallClock | undefined;
14
+ export declare const cronMatches: (expression: string, at: Date, timeZone?: string) => boolean;
13
15
  /**
14
- * The same instant, as the clock on a wall in `timeZone` reads it.
16
+ * The first minute at or after `from` that this expression fires on, or undefined when it never does.
17
+ *
18
+ * **This is what a schedule stores**, and why it is here rather than in a scheduler: a due time written into a row
19
+ * is a decision made once, by whoever wrote it, and every replica afterwards reads the same instant instead of each
20
+ * asking its own clock whether the moment has come. Nodes in different countries then disagree about what time it
21
+ * is — which they will — without ever disagreeing about which fires have happened.
15
22
  *
16
- * Through `Intl` rather than an offset table, because an offset is not a constant: "9am in Santiago" is a
17
- * different instant in January and in July, and a schedule that means the working day has to follow the change.
18
- * `hourCycle: 'h23'` matters — the other cycles render midnight as 24, which cron has no hour for.
23
+ * Inclusive of `from`, so a caller that wants the one strictly after an instant asks from the minute after it. The
24
+ * search steps by whole minutes, skipping a day at a time when the date cannot match and an hour at a time when the
25
+ * hour cannot — a yearly expression costs a few hundred comparisons rather than half a million.
19
26
  *
20
- * An unknown zone answers `undefined` rather than falling back to UTC. Falling back is what this whole change is
21
- * about: a schedule that fires at the wrong hour and says nothing.
27
+ * DST is the reason the skips are computed from the WALL clock and then re-read rather than added as fixed offsets:
28
+ * jumping "to midnight" lands an hour early on the night a zone falls back, which costs one more comparison, and an
29
+ * hour late on the night it springs forward — into minutes that did not exist locally, so there was nothing there
30
+ * to miss.
22
31
  */
23
- export declare const zonedClock: (at: Date, timeZone: string) => WallClock | undefined;
32
+ export declare const cronNextFire: (expression: string, from: Date, timeZone?: string) => Date | undefined;
24
33
  /**
25
- * Whether an expression fires at this minute — in `timeZone` when one is named, in UTC when none is.
34
+ * How many times an expression would have fired in `(after, until]`.
26
35
  *
27
- * Day-of-month and day-of-week are OR'd when both are restricted, which is the rule every cron implementation
28
- * follows and the one that surprises people who expect AND — `0 0 1 * 1` fires on the first of the month AND on
29
- * every Monday.
36
+ * What an operator is owed after an outage: the run that is about to happen is one fire, and this is the number of
37
+ * others that went by while nothing was there to take them. Capped, because the answer's purpose is to be shown to
38
+ * somebody — a minutely schedule down for a week is "at least `limit`", not a number worth spending a second on.
30
39
  */
31
- export declare const cronMatches: (expression: string, at: Date, timeZone?: string) => boolean;
40
+ export declare const cronFiresBetween: (expression: string, after: Date, until: Date, timeZone?: string, limit?: number) => number;
32
41
  /** Whether `Intl` knows this zone. The validator asks so an author hears about a typo in the editor. */
33
42
  export declare const isKnownTimeZone: (timeZone: string) => boolean;
34
43
  export {};
@@ -37,17 +37,23 @@ var e = [
37
37
  day: e.getUTCDate(),
38
38
  month: e.getUTCMonth() + 1,
39
39
  weekday: e.getUTCDay()
40
- }), a = (e, t) => {
40
+ }), a = (e) => {
41
+ let t;
41
42
  try {
42
- let n = new Intl.DateTimeFormat("en-US", {
43
- timeZone: t,
43
+ t = new Intl.DateTimeFormat("en-US", {
44
+ timeZone: e,
44
45
  hourCycle: "h23",
45
46
  month: "numeric",
46
47
  day: "numeric",
47
48
  hour: "numeric",
48
49
  minute: "numeric",
49
50
  weekday: "short"
50
- }).formatToParts(e), i = (e) => n.find((t) => t.type === e)?.value ?? "", a = r.indexOf(i("weekday")), o = {
51
+ });
52
+ } catch {
53
+ return;
54
+ }
55
+ return (e) => {
56
+ let n = t.formatToParts(e), i = (e) => n.find((t) => t.type === e)?.value ?? "", a = r.indexOf(i("weekday")), o = {
51
57
  minute: Number(i("minute")),
52
58
  hour: Number(i("hour")),
53
59
  day: Number(i("day")),
@@ -55,18 +61,43 @@ var e = [
55
61
  weekday: a
56
62
  };
57
63
  return a >= 0 && Object.values(o).every(Number.isFinite) ? o : void 0;
58
- } catch {
59
- return;
64
+ };
65
+ }, o = (e, t) => a(t)?.(e), s = ([, , e, t, n], r) => {
66
+ if (!t.has(r.month)) return !1;
67
+ let i = e.size !== 31, a = n.size !== 7, o = e.has(r.day), s = n.has(r.weekday);
68
+ return i && a ? o || s : o && s;
69
+ }, c = (e, t) => {
70
+ let [n, r] = e;
71
+ return n.has(t.minute) && r.has(t.hour) && s(e, t);
72
+ }, l = (e) => e ? a(e) : i, u = (e, t, r) => {
73
+ let i = n(e), a = i ? l(r)?.(t) : void 0;
74
+ return i !== void 0 && a !== void 0 && c(i, a);
75
+ }, d = 6e4, f = 2108160 * d, p = (e, t, r) => {
76
+ let i = n(e), a = i ? l(r) : void 0;
77
+ if (!i || !a) return;
78
+ let o = Math.ceil(t.getTime() / d) * d, c = o + f, [u, p] = i;
79
+ for (let e = o; e <= c;) {
80
+ let t = new Date(e), n = a(t);
81
+ if (!n) return;
82
+ if (!s(i, n)) {
83
+ e += (1440 - n.hour * 60 - n.minute) * d;
84
+ continue;
85
+ }
86
+ if (!p.has(n.hour)) {
87
+ e += (60 - n.minute) * d;
88
+ continue;
89
+ }
90
+ if (u.has(n.minute)) return t;
91
+ e += d;
92
+ }
93
+ }, m = (e, t, n, r, i = 1e3) => {
94
+ let a = 0, o = new Date(t.getTime() + d);
95
+ for (; a < i;) {
96
+ let t = p(e, o, r);
97
+ if (!t || t > n) return a;
98
+ a += 1, o = new Date(t.getTime() + d);
60
99
  }
61
- }, o = (e, t, r) => {
62
- let o = n(e);
63
- if (!o) return !1;
64
- let s = r ? a(t, r) : i(t);
65
- if (!s) return !1;
66
- let [c, l, u, d, f] = o;
67
- if (!c.has(s.minute) || !l.has(s.hour) || !d.has(s.month)) return !1;
68
- let p = u.size !== 31, m = f.size !== 7, h = u.has(s.day), g = f.has(s.weekday);
69
- return p && m ? h || g : h && g;
70
- }, s = (e) => a(/* @__PURE__ */ new Date(), e) !== void 0;
100
+ return a;
101
+ }, h = (e) => o(/* @__PURE__ */ new Date(), e) !== void 0;
71
102
  //#endregion
72
- export { o as cronMatches, s as isKnownTimeZone, n as parseCron, a as zonedClock };
103
+ export { m as cronFiresBetween, u as cronMatches, p as cronNextFire, h as isKnownTimeZone, n as parseCron, o as zonedClock };
@@ -1,4 +1,4 @@
1
- export { cronMatches, isKnownTimeZone, parseCron, zonedClock } from './cron';
1
+ export { cronFiresBetween, cronMatches, cronNextFire, isKnownTimeZone, parseCron, zonedClock } from './cron';
2
2
  export { FAILURE_HANDLER_TASK } from './failureHandler';
3
3
  export { triggerAccess, triggerCacheMs, triggerHasStaleVerify, triggerInput, triggerVerify } from './triggerParams';
4
4
  export { actionName, actionTriggers, isActionEnabled } from './triggers';
@@ -1,7 +1,7 @@
1
- import { cronMatches as e, isKnownTimeZone as t, parseCron as n, zonedClock as r } from "./cron.mjs";
2
- import { FAILURE_HANDLER_TASK as i } from "./failureHandler.mjs";
3
- import { triggerAccess as a, triggerCacheMs as o, triggerHasStaleVerify as s, triggerInput as c, triggerVerify as l } from "./triggerParams.mjs";
4
- import { actionName as u, actionTriggers as d, isActionEnabled as f } from "./triggers.mjs";
5
- import { validateActionDocument as p } from "./validateDocument.mjs";
6
- import { SMTP_CREDENTIAL_KEYS as m, isSingleEmailAddress as h, readSmtpCredential as g } from "./smtp.mjs";
7
- export { i as FAILURE_HANDLER_TASK, m as SMTP_CREDENTIAL_KEYS, u as actionName, d as actionTriggers, e as cronMatches, f as isActionEnabled, t as isKnownTimeZone, h as isSingleEmailAddress, n as parseCron, g as readSmtpCredential, a as triggerAccess, o as triggerCacheMs, s as triggerHasStaleVerify, c as triggerInput, l as triggerVerify, p as validateActionDocument, r as zonedClock };
1
+ import { cronFiresBetween as e, cronMatches as t, cronNextFire as n, isKnownTimeZone as r, parseCron as i, zonedClock as a } from "./cron.mjs";
2
+ import { FAILURE_HANDLER_TASK as o } from "./failureHandler.mjs";
3
+ import { triggerAccess as s, triggerCacheMs as c, triggerHasStaleVerify as l, triggerInput as u, triggerVerify as d } from "./triggerParams.mjs";
4
+ import { actionName as f, actionTriggers as p, isActionEnabled as m } from "./triggers.mjs";
5
+ import { validateActionDocument as h } from "./validateDocument.mjs";
6
+ import { SMTP_CREDENTIAL_KEYS as g, isSingleEmailAddress as _, readSmtpCredential as v } from "./smtp.mjs";
7
+ export { o as FAILURE_HANDLER_TASK, g as SMTP_CREDENTIAL_KEYS, f as actionName, p as actionTriggers, e as cronFiresBetween, t as cronMatches, n as cronNextFire, m as isActionEnabled, r as isKnownTimeZone, _ as isSingleEmailAddress, i as parseCron, v as readSmtpCredential, s as triggerAccess, c as triggerCacheMs, l as triggerHasStaleVerify, u as triggerInput, d as triggerVerify, h as validateActionDocument, a as zonedClock };
@@ -25,5 +25,9 @@ export declare const isActionEnabled: (document: ActionDocument) => boolean;
25
25
  *
26
26
  * Falls back to whatever the document already carries, so a document written before this — or by a caller that
27
27
  * names it directly, like the authoring API — keeps the name it was given.
28
+ *
29
+ * A title that only repeats the trigger's kind is not a name: it is the default a node gets before anybody names
30
+ * it. Read as one, every page-rendered action in a workspace was called "render" and every clock "schedule" — a list
31
+ * of runs nobody could tell apart — while the document's own name sat unused beside it.
28
32
  */
29
33
  export declare const actionName: (document: ActionDocument) => string;
@@ -1,4 +1,7 @@
1
1
  //#region src/actions/triggers.ts
2
- var e = (e) => Object.values(e.nodes).filter((e) => e.type === "trigger"), t = (t) => e(t).some((e) => e.enabled), n = (t) => e(t).find((e) => e.title.trim() !== "")?.title.trim() ?? t.name;
2
+ var e = (e) => Object.values(e.nodes).filter((e) => e.type === "trigger"), t = (t) => e(t).some((e) => e.enabled), n = (t) => e(t).find((e) => {
3
+ let t = e.title.trim();
4
+ return t !== "" && t !== e.action;
5
+ })?.title.trim() ?? t.name;
3
6
  //#endregion
4
7
  export { n as actionName, e as actionTriggers, t as isActionEnabled };
@@ -1,3 +1,4 @@
1
+ import { InteractionCallback } from '../types/InteractionTypes';
1
2
  /**
2
3
  * How an element says what it can be authored with.
3
4
  *
@@ -29,6 +30,26 @@ export interface ElementDeclarationData {
29
30
  * reads it to resolve a binding that named the element alone.
30
31
  */
31
32
  sourceType?: string;
33
+ /**
34
+ * The triggers this type fires on top of the ones every element does (`onClick`, `onLoad`…), by action name.
35
+ *
36
+ * Declared here for the reason `sourceType` is: the component registers exactly these, and the authoring surface
37
+ * reads them to refuse a flow that starts on a trigger its element never fires — an `onSubmit` on the submit
38
+ * button rather than on the form is a flow that is written, saved and silently never runs.
39
+ */
40
+ triggers?: Record<string, InteractionCallback>;
41
+ /**
42
+ * The callbacks this type runs on itself on top of the ones every element does (`setState`, `toggleState`) —
43
+ * their static half. The component adds what only a mounted element has: the function, a title naming its label,
44
+ * options drawn from its children. Read by the authoring surface to refuse a step aimed at an element that does not
45
+ * answer to it — an `openModal` sent to a plain container is a button that does nothing.
46
+ */
47
+ callbacks?: Record<string, InteractionCallback>;
48
+ /**
49
+ * The type this one only works somewhere inside: it reads its state from that element's context, and anywhere
50
+ * else it throws on its first render. A dropdown's panel, a tab container's header and body.
51
+ */
52
+ ancestorType?: string;
32
53
  content?: {
33
54
  attributes?: Record<string, unknown>;
34
55
  definition?: {
@@ -1,43 +1,44 @@
1
1
  import e from "./utility/index.mjs";
2
- import { camelCase as t, get as n, set as r } from "@plitzi/plitzi-ui/helpers/lodash";
3
- import { QueryBuilderEvaluator as i } from "@plitzi/plitzi-ui/QueryBuilder";
4
- import { produce as a } from "immer";
2
+ import { checkboxParams as t } from "./utility/checkboxParams.mjs";
3
+ import { camelCase as n, get as r, set as i } from "@plitzi/plitzi-ui/helpers/lodash";
4
+ import { QueryBuilderEvaluator as a } from "@plitzi/plitzi-ui/QueryBuilder";
5
+ import { produce as o } from "immer";
5
6
  //#region src/dataSource/getBindingsDetails.ts
6
- var o = (e, t, r, i, a) => {
7
+ var s = (e, t, n, i, a) => {
7
8
  let o = i === "initialState" ? `definition.${i}.${a}` : `${i}.${a}`;
8
9
  return {
9
- fromValue: t ? n(e, t, n(r, o)) : void 0,
10
- toValue: n(r, o, t ? n(e, t) : void 0)
10
+ fromValue: t ? r(e, t, r(n, o)) : void 0,
11
+ toValue: r(n, o, t ? r(e, t) : void 0)
11
12
  };
12
- }, s = (s, c, l = {}) => {
13
+ }, c = (r, c, l = {}) => {
13
14
  let { attributes: u, definition: d } = c, { bindings: f } = d;
14
15
  return !f || typeof f == "object" && !Object.keys(f).length ? {
15
16
  attributes: u,
16
17
  style: {},
17
18
  definition: d
18
- } : a({
19
+ } : o({
19
20
  attributes: u,
20
21
  style: l,
21
22
  definition: d
22
- }, (a) => {
23
+ }, (o) => {
23
24
  Object.keys(f).forEach((c) => {
24
25
  f[c] && Array.isArray(f[c]) && f[c].length && f[c].forEach((l) => {
25
26
  let { source: u, transformers: d, when: f, enabled: p = !0 } = l, { to: m } = l;
26
- if (!m || f && !i(f, s, !1, !0) || !p) return;
27
- c === "style" && (m = t(m));
28
- let { fromValue: h, toValue: g } = o(s, u, a, c, m), _ = h;
29
- d && Array.isArray(d) && d.length > 0 && d.forEach((t) => {
30
- let { action: r, params: i, enabled: o = !0 } = t;
31
- if (!o) return;
32
- let c = n(e, `${r}.callback`);
33
- typeof c == "function" && (_ = c(_, i, a, {
34
- ...s,
27
+ if (!m || f && !a(f, r, !1, !0) || !p) return;
28
+ c === "style" && (m = n(m));
29
+ let { fromValue: h, toValue: g } = s(r, u, o, c, m), _ = h;
30
+ d && Array.isArray(d) && d.length > 0 && d.forEach((n) => {
31
+ let { action: i, params: a, enabled: s = !0 } = n;
32
+ if (!s) return;
33
+ let c = e[i];
34
+ c && (_ = c.callback(_, t(c, a) ?? {}, o, {
35
+ ...r,
35
36
  sourceTo: g
36
37
  }));
37
- }), (typeof _ == "boolean" || typeof _ == "number" || _) && (c === "initialState" ? r(a, `definition.${c}.${m}`, _) : r(a, `${c}.${m}`, _));
38
+ }), (typeof _ == "boolean" || typeof _ == "number" || _) && (c === "initialState" ? i(o, `definition.${c}.${m}`, _) : i(o, `${c}.${m}`, _));
38
39
  });
39
40
  });
40
41
  });
41
42
  };
42
43
  //#endregion
43
- export { s as default };
44
+ export { c as default };
@@ -0,0 +1,11 @@
1
+ import { DataSourceUtility, DataSourceUtilityParamsValue } from '../../types';
2
+ /**
3
+ * A checkbox param as the boolean it means.
4
+ *
5
+ * A document stores what an editor or an author wrote, and a checkbox arrives both ways: `true` from the builder,
6
+ * `'true'` or `'false'` from anything that writes params as text — an authored space, an export, an agent. A callback
7
+ * reading `if (asAge)` takes `'false'` for yes, so `dateConverter({ asAge: 'false' })` printed "3 days ago" and
8
+ * `isUnix: 'false'` parsed an ISO date as a number and gave the raw string back. Normalised once here, before any
9
+ * callback runs, every utility reads a checkbox the same way.
10
+ */
11
+ export declare const checkboxParams: <TParams>(utility: Pick<DataSourceUtility<unknown, unknown, TParams>, "params">, params: DataSourceUtilityParamsValue<TParams> | undefined) => DataSourceUtilityParamsValue<TParams> | undefined;
@@ -0,0 +1,12 @@
1
+ //#region src/dataSource/utility/checkboxParams.ts
2
+ var e = (e, t) => {
3
+ if (!t) return t;
4
+ let n = t;
5
+ for (let [r, i] of Object.entries(e.params)) {
6
+ let e = t[r];
7
+ e !== "true" && e !== "false" || (typeof i.type == "function" ? i.type(t) : i.type) !== "checkbox" || (n === t && (n = { ...t }), n[r] = e === "true");
8
+ }
9
+ return n;
10
+ };
11
+ //#endregion
12
+ export { e as checkboxParams };
@@ -1,14 +1,15 @@
1
1
  import { filters as e } from "./twigWrapper/filters/filters.mjs";
2
2
  import { processTwig as t } from "./twigWrapper/processTwig/processTwig.mjs";
3
- import { hasValidToken as n } from "./twigWrapper/tokens/hasValidToken.mjs";
4
- import { templateRootNames as r } from "./twigWrapper/templateRoots.mjs";
5
- import i from "./fetchManifest.mjs";
6
- import a from "./generateFacade.mjs";
7
- import o from "./syntaxHighlight.mjs";
8
- import { formatDate as s, formatDateUTC as c, formatFromNow as l, formatUTCToLocal as u, getDurationMs as d, isDate as f, isValidFormat as p, parseDate as m, toUnixSeconds as h } from "./formatDate.mjs";
9
- import { isUserEdit as g } from "./reducerOrigin.mjs";
10
- import { evaluateRuleGroup as _ } from "./ruleEvaluator.mjs";
11
- import { ParamsFromURL as v, delay as y, emptyObject as b, getDisplayName as x, getKeyDecoded as S, getPathsFromObeject as C, hexToRGB as w, isInViewport as T, makeId as E } from "./utils.mjs";
12
- import { disableReactDevTools as D } from "./security.mjs";
13
- import { createStripTypenameLink as O, stripTypenameDeep as k } from "./stripTypename.mjs";
14
- export { v as ParamsFromURL, O as createStripTypenameLink, y as delay, D as disableReactDevTools, b as emptyObject, _ as evaluateRuleGroup, i as fetchManifest, e as filters, s as formatDate, c as formatDateUTC, l as formatFromNow, u as formatUTCToLocal, a as generateFacade, x as getDisplayName, d as getDurationMs, S as getKeyDecoded, C as getPathsFromObeject, n as hasValidToken, w as hexToRGB, f as isDate, T as isInViewport, g as isUserEdit, p as isValidFormat, E as makeId, m as parseDate, t as processTwig, k as stripTypenameDeep, o as syntaxHighlight, r as templateRootNames, h as toUnixSeconds };
3
+ import { hasTemplateSyntax as n } from "./twigWrapper/tokens/hasTemplateSyntax.mjs";
4
+ import { hasValidToken as r } from "./twigWrapper/tokens/hasValidToken.mjs";
5
+ import { templateRootNames as i } from "./twigWrapper/templateRoots.mjs";
6
+ import a from "./fetchManifest.mjs";
7
+ import o from "./generateFacade.mjs";
8
+ import s from "./syntaxHighlight.mjs";
9
+ import { formatDate as c, formatDateUTC as l, formatFromNow as u, formatUTCToLocal as d, getDurationMs as f, isDate as p, isValidFormat as m, parseDate as h, toUnixSeconds as g } from "./formatDate.mjs";
10
+ import { isUserEdit as _ } from "./reducerOrigin.mjs";
11
+ import { evaluateRuleGroup as v } from "./ruleEvaluator.mjs";
12
+ import { ParamsFromURL as y, delay as b, emptyObject as x, getDisplayName as S, getKeyDecoded as C, getPathsFromObeject as w, hexToRGB as T, isInViewport as E, makeId as D } from "./utils.mjs";
13
+ import { disableReactDevTools as O } from "./security.mjs";
14
+ import { createStripTypenameLink as k, stripTypenameDeep as A } from "./stripTypename.mjs";
15
+ export { y as ParamsFromURL, k as createStripTypenameLink, b as delay, O as disableReactDevTools, x as emptyObject, v as evaluateRuleGroup, a as fetchManifest, e as filters, c as formatDate, l as formatDateUTC, u as formatFromNow, d as formatUTCToLocal, o as generateFacade, S as getDisplayName, f as getDurationMs, C as getKeyDecoded, w as getPathsFromObeject, n as hasTemplateSyntax, r as hasValidToken, T as hexToRGB, p as isDate, E as isInViewport, _ as isUserEdit, m as isValidFormat, D as makeId, h as parseDate, t as processTwig, A as stripTypenameDeep, s as syntaxHighlight, i as templateRootNames, g as toUnixSeconds };
@@ -1,14 +1,22 @@
1
1
  import { isTruthy as e, resolveCollection as t, resolveObjectEntries as n, valueIn as r } from "./helpers.mjs";
2
2
  import { ARROW_PARAMS as i, filters as a, isRawMarker as o, unwrapRaw as s } from "../filters/filters.mjs";
3
3
  //#region src/helpers/twigWrapper/Evaluator/Evaluator.ts
4
- var c = [], l = (e, t, n = !1) => {
5
- let r = new u(t, n);
4
+ var c = {
5
+ defined: (e) => e !== void 0,
6
+ null: (e) => e == null,
7
+ none: (e) => e == null,
8
+ empty: (e) => e == null || e === "" || e === !1 || Array.isArray(e) && e.length === 0 || typeof e == "object" && !Array.isArray(e) && Object.keys(e).length === 0,
9
+ iterable: (e) => Array.isArray(e) || typeof e == "object" && !!e,
10
+ even: (e) => typeof e == "number" && e % 2 == 0,
11
+ odd: (e) => typeof e == "number" && Math.abs(e % 2) === 1
12
+ }, l = (e) => e.type === "path" || e.type === "filter" && l(e.subject), u = (e, t) => t == null || t === "" && l(e), d = [], f = (e, t, n = !1) => {
13
+ let r = new p(t, n);
6
14
  return {
7
15
  output: r.evalNodes(e),
8
16
  variables: r.variables,
9
17
  hasSet: r.hasSet
10
18
  };
11
- }, u = class l {
19
+ }, p = class l {
12
20
  variables;
13
21
  keepEmptyTokens;
14
22
  breakFlag = !1;
@@ -39,7 +47,7 @@ var c = [], l = (e, t, n = !1) => {
39
47
  }
40
48
  evalVariable(e) {
41
49
  let t = this.evalExpression(e.expression);
42
- return this.keepEmptyTokens && (t == null || t === "") ? e.source : o(t) ? String(s(t)) : typeof t == "function" ? "" : t != null && typeof t != "object" ? String(t) : e.raw ? t == null ? "" : String(t) : typeof t == "object" && t ? JSON.stringify(t) : "";
50
+ return this.keepEmptyTokens && u(e.expression, t) ? e.source : o(t) ? String(s(t)) : typeof t == "function" ? "" : t != null && typeof t != "object" ? String(t) : e.raw ? t == null ? "" : String(t) : typeof t == "object" && t ? JSON.stringify(t) : "";
43
51
  }
44
52
  evalIf(t) {
45
53
  if (e(this.evalExpression(t.condition))) return this.evalNodes(t.body);
@@ -94,7 +102,7 @@ var c = [], l = (e, t, n = !1) => {
94
102
  let n = e;
95
103
  for (let e of t) {
96
104
  let t = a[e.name];
97
- t !== void 0 && (n = t(n, e.args.length === 0 ? c : this.evalArgs(e.args)));
105
+ t !== void 0 && (n = t(n, e.args.length === 0 ? d : this.evalArgs(e.args)));
98
106
  }
99
107
  return n;
100
108
  }
@@ -200,6 +208,13 @@ var c = [], l = (e, t, n = !1) => {
200
208
  return a;
201
209
  }
202
210
  evalBinary(t, n, i) {
211
+ if ((t === "is" || t === "is not") && i.type === "path" && i.segments.length === 1) {
212
+ let e = c[i.segments[0]];
213
+ if (e) {
214
+ let r = e(this.evalExpression(n));
215
+ return t === "is" ? r : !r;
216
+ }
217
+ }
203
218
  if (t === "or") return e(this.evalExpression(n)) || e(this.evalExpression(i));
204
219
  if (t === "and") return e(this.evalExpression(n)) && e(this.evalExpression(i));
205
220
  let a = this.evalExpression(n), o = this.evalExpression(i), s = typeof a == "number" && typeof o == "number";
@@ -224,4 +239,4 @@ var c = [], l = (e, t, n = !1) => {
224
239
  }
225
240
  };
226
241
  //#endregion
227
- export { l as evaluate };
242
+ export { f as evaluate };
@@ -163,7 +163,7 @@ var r = (e) => new a(e).parseTernary(), i = (e) => new a(e).parseApplyChain(), a
163
163
  });
164
164
  this.pos = t;
165
165
  let r = this.parseTernary();
166
- return this.skipWs(), this.peek() === e.RParen && this.pos++, this.maybeTrailingFilters(r);
166
+ return this.skipWs(), this.peek() === e.RParen && this.pos++, this.maybeTrailingFilters(this.parseAccessChain(r, null));
167
167
  }
168
168
  return n === e.SingleQuote || n === e.DoubleQuote ? this.maybeTrailingFilters({
169
169
  type: "literal",
@@ -124,7 +124,12 @@ var e = Symbol("twigArrowParams"), t = (e) => e == null || e === "", n = (e, t)
124
124
  f.set(e, null);
125
125
  }
126
126
  return f.get(e) ?? null;
127
- }, m = (e, t) => {
127
+ }, m = (e) => {
128
+ if (e instanceof Date) return e;
129
+ if (typeof e == "number") return new Date(e);
130
+ let t = String(e).trim();
131
+ return /^-?\d+$/.test(t) ? new Date(Number(t)) : new Date(t);
132
+ }, h = (e, t) => {
128
133
  if (!t) return {
129
134
  year: e.getFullYear(),
130
135
  month: e.getMonth() + 1,
@@ -146,7 +151,7 @@ var e = Symbol("twigArrowParams"), t = (e) => e == null || e === "", n = (e, t)
146
151
  seconds: Number(i("second")),
147
152
  weekday: d.indexOf(i("weekday"))
148
153
  };
149
- }, h = {
154
+ }, g = {
150
155
  raw: (e) => l(e),
151
156
  to_json: (e) => typeof e == "object" && e ? JSON.stringify(e) : r(e),
152
157
  json_encode: (e) => typeof e == "object" && e ? JSON.stringify(e) : r(e),
@@ -307,9 +312,9 @@ var e = Symbol("twigArrowParams"), t = (e) => e == null || e === "", n = (e, t)
307
312
  random: (e) => Array.isArray(e) ? e.length > 0 ? e[Math.floor(Math.random() * e.length)] : void 0 : typeof e == "string" ? e.length > 0 ? e[Math.floor(Math.random() * e.length)] : "" : typeof e == "number" ? Math.floor(Math.random() * e) : e,
308
313
  date: (e, t) => {
309
314
  if (t.length === 0) return e;
310
- let n = r(t[0]), i = e instanceof Date ? e : new Date(String(e));
315
+ let n = r(t[0]), i = m(e);
311
316
  if (Number.isNaN(i.getTime())) return "";
312
- let a = m(i, t.length > 1 ? r(t[1]) : "");
317
+ let a = h(i, t.length > 1 ? r(t[1]) : "");
313
318
  if (!a) return "";
314
319
  let o = (e) => String(e).padStart(2, "0"), s = {
315
320
  Y: String(a.year),
@@ -424,4 +429,4 @@ var e = Symbol("twigArrowParams"), t = (e) => e == null || e === "", n = (e, t)
424
429
  }
425
430
  };
426
431
  //#endregion
427
- export { e as ARROW_PARAMS, s as RAW_MARKER, h as filters, c as isRawMarker, u as unwrapRaw, l as wrapRaw };
432
+ export { e as ARROW_PARAMS, s as RAW_MARKER, g as filters, c as isRawMarker, u as unwrapRaw, l as wrapRaw };
@@ -1,4 +1,5 @@
1
1
  export { processTwig } from './processTwig';
2
+ export { hasTemplateSyntax } from './tokens/hasTemplateSyntax';
2
3
  export { hasValidToken } from './tokens/hasValidToken';
3
4
  export { templateRootNames } from './templateRoots';
4
5
  export { filters } from './filters/filters';
@@ -1,5 +1,6 @@
1
1
  import { filters as e } from "./filters/filters.mjs";
2
2
  import { processTwig as t } from "./processTwig/processTwig.mjs";
3
- import { hasValidToken as n } from "./tokens/hasValidToken.mjs";
4
- import { templateRootNames as r } from "./templateRoots.mjs";
5
- export { e as filters, n as hasValidToken, t as processTwig, r as templateRootNames };
3
+ import { hasTemplateSyntax as n } from "./tokens/hasTemplateSyntax.mjs";
4
+ import { hasValidToken as r } from "./tokens/hasValidToken.mjs";
5
+ import { templateRootNames as i } from "./templateRoots.mjs";
6
+ export { e as filters, n as hasTemplateSyntax, r as hasValidToken, t as processTwig, i as templateRootNames };