clivly 0.19.0 → 0.21.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.
Files changed (136) hide show
  1. package/README.md +14 -4
  2. package/{adapter-BXykDFyG.d.mts → adapter-B4v4dwgD.d.mts} +1 -1
  3. package/{adapter-BiUN_I3u.d.cts → adapter-BK3gsby5.d.cts} +1 -1
  4. package/{auth-adapter-BNvri2gX.d.mts → auth-adapter-BIa-ZyVV.d.mts} +1 -1
  5. package/{auth-adapter-D2MUT1Hk.d.cts → auth-adapter-DwtMJb7D.d.cts} +1 -1
  6. package/auth-better-auth.d.cts +1 -1
  7. package/auth-better-auth.d.mts +1 -1
  8. package/auth-clerk.d.cts +1 -1
  9. package/auth-clerk.d.mts +1 -1
  10. package/auth-workos.d.cts +1 -1
  11. package/auth-workos.d.mts +1 -1
  12. package/core-adapter.d.cts +2 -1
  13. package/core-adapter.d.mts +2 -1
  14. package/core-auth-adapter.d.cts +2 -1
  15. package/core-auth-adapter.d.mts +2 -1
  16. package/core-drizzle.d.cts +1 -1
  17. package/core-drizzle.d.mts +1 -1
  18. package/core-entity-config.cjs +1 -1
  19. package/core-entity-config.d.cts +2 -1
  20. package/core-entity-config.d.mts +2 -1
  21. package/core-entity-config.mjs +1 -1
  22. package/core-entity-heuristics.cjs +1 -1
  23. package/core-entity-heuristics.d.cts +1 -1
  24. package/core-entity-heuristics.d.mts +1 -1
  25. package/core-entity-heuristics.mjs +1 -1
  26. package/core-mapping-form.d.cts +2 -1
  27. package/core-mapping-form.d.mts +2 -1
  28. package/core-mappings-config.cjs +1 -1
  29. package/core-mappings-config.d.cts +2 -1
  30. package/core-mappings-config.d.mts +2 -1
  31. package/core-mappings-config.mjs +1 -1
  32. package/core-sync-engine.cjs +1 -1
  33. package/core-sync-engine.d.cts +2 -1
  34. package/core-sync-engine.d.mts +2 -1
  35. package/core-sync-engine.mjs +1 -1
  36. package/core-types.d.cts +2 -1
  37. package/core-types.d.mts +2 -1
  38. package/core-view-compiler.cjs +1 -1
  39. package/core-view-compiler.d.cts +2 -1
  40. package/core-view-compiler.d.mts +2 -1
  41. package/core-view-compiler.mjs +1 -1
  42. package/core.cjs +7 -7
  43. package/core.d.cts +10 -10
  44. package/core.d.mts +10 -10
  45. package/core.mjs +7 -7
  46. package/{drizzle-B9cjBavj.d.cts → drizzle-BNHGQXiY.d.cts} +1 -1
  47. package/{drizzle-L5FOGe_-.d.mts → drizzle-DFe7ILmd.d.mts} +1 -1
  48. package/drizzle.cjs +2 -2
  49. package/drizzle.d.cts +4 -3
  50. package/drizzle.d.mts +4 -3
  51. package/drizzle.mjs +2 -2
  52. package/{entity-config-DiCJ6mhI.cjs → entity-config-BP8Cc_nC.cjs} +54 -53
  53. package/{entity-config-g_oMPXlN.mjs → entity-config-CI5CGfaN.mjs} +54 -53
  54. package/{entity-config-X-KlnYXX.d.mts → entity-config-CXpGowQa.d.cts} +339 -339
  55. package/{entity-config-dNclLyBM.d.cts → entity-config-CXpGowQa.d.mts} +339 -339
  56. package/{entity-heuristics-DE5ujoHw.mjs → entity-heuristics-DAxqagJA.mjs} +1 -1
  57. package/{entity-heuristics-CIParuQe.cjs → entity-heuristics-DNmrcd0b.cjs} +1 -1
  58. package/index-Bh7o2J7K.d.mts +308 -0
  59. package/index-DRRTE5IJ.d.cts +308 -0
  60. package/index.cjs +3 -3
  61. package/index.mjs +3 -3
  62. package/{internal-COALpgov.d.cts → internal-C8TGcv_X.d.mts} +2 -131
  63. package/{internal-9oDwwbNg.mjs → internal-DWpLw0t5.mjs} +5 -5
  64. package/{internal-BKYt5j0l.cjs → internal-G5tXjqwl.cjs} +5 -5
  65. package/{internal-D3q4FPcA.d.mts → internal-Nrhf76Jn.d.cts} +2 -131
  66. package/internal-adapter.d.cts +1 -1
  67. package/internal-adapter.d.mts +1 -1
  68. package/internal-auth-adapter.d.cts +1 -1
  69. package/internal-auth-adapter.d.mts +1 -1
  70. package/internal-drizzle.d.cts +1 -1
  71. package/internal-drizzle.d.mts +1 -1
  72. package/internal-entity-config.cjs +1 -1
  73. package/internal-entity-config.d.cts +1 -1
  74. package/internal-entity-config.d.mts +1 -1
  75. package/internal-entity-config.mjs +1 -1
  76. package/internal-entity-heuristics.cjs +1 -1
  77. package/internal-entity-heuristics.d.cts +1 -1
  78. package/internal-entity-heuristics.d.mts +1 -1
  79. package/internal-entity-heuristics.mjs +1 -1
  80. package/internal-mapping-form.d.cts +1 -1
  81. package/internal-mapping-form.d.mts +1 -1
  82. package/internal-mappings-config.cjs +1 -1
  83. package/internal-mappings-config.d.cts +1 -1
  84. package/internal-mappings-config.d.mts +1 -1
  85. package/internal-mappings-config.mjs +1 -1
  86. package/internal-sync-engine.cjs +1 -1
  87. package/internal-sync-engine.d.cts +1 -1
  88. package/internal-sync-engine.d.mts +1 -1
  89. package/internal-sync-engine.mjs +1 -1
  90. package/internal-types.d.cts +1 -1
  91. package/internal-types.d.mts +1 -1
  92. package/internal-view-compiler.cjs +1 -1
  93. package/internal-view-compiler.d.cts +1 -1
  94. package/internal-view-compiler.d.mts +1 -1
  95. package/internal-view-compiler.mjs +1 -1
  96. package/internal.cjs +7 -7
  97. package/internal.d.cts +10 -10
  98. package/internal.d.mts +10 -10
  99. package/internal.mjs +7 -7
  100. package/{mapping-form-Bpvgf5b8.d.mts → mapping-form-Bg_hgNoL.d.cts} +1 -1
  101. package/{mapping-form-CV7y6qox.d.cts → mapping-form-KHUlnC7A.d.mts} +1 -1
  102. package/{mappings-config-CNxBrbt9.cjs → mappings-config-CC-vltWb.cjs} +1 -1
  103. package/{mappings-config-BBppW9fp.d.cts → mappings-config-DNo_Cum_.d.cts} +1 -1
  104. package/{mappings-config-D_g20PyS.mjs → mappings-config-Opw7ZM6Y.mjs} +1 -1
  105. package/{mappings-config-Dmm0H6p_.d.mts → mappings-config-wAe-p1rG.d.mts} +1 -1
  106. package/{namespace-probe-C1tm5rGh.d.cts → namespace-probe-Dh6LFwfo.d.cts} +9 -2
  107. package/{namespace-probe-ah2awcHO.d.mts → namespace-probe-xESu83KG.d.mts} +9 -2
  108. package/package.json +6 -4
  109. package/projection-CzBI2NL8.mjs +95 -0
  110. package/{projection-sql-CHz7KzNS.cjs → projection-sql-BkrHR2ea.cjs} +1 -1
  111. package/{projection-sql-C3gZE3GS.mjs → projection-sql-DQQdjw9I.mjs} +1 -1
  112. package/projection-w4Z6vSL2.cjs +118 -0
  113. package/{sdk-ChyrSl32.mjs → sdk-DfdHv-S9.mjs} +154 -13
  114. package/{sdk-BEHVvB18.cjs → sdk-oUjl5HNU.cjs} +154 -13
  115. package/sdk.cjs +2 -2
  116. package/sdk.d.cts +2 -2
  117. package/sdk.d.mts +2 -2
  118. package/sdk.mjs +2 -2
  119. package/{sync-engine-C7W0Gkq0.d.cts → sync-engine-DCjTr2XQ.d.cts} +2 -2
  120. package/{sync-engine-Di-vF26b.cjs → sync-engine-DNSoZeo0.cjs} +1 -1
  121. package/{sync-engine-C9Q2FkR9.d.mts → sync-engine-UNORma7f.d.mts} +2 -2
  122. package/{sync-engine-CwdLkmch.mjs → sync-engine-yFLEyId3.mjs} +1 -1
  123. package/{types-C08UluBS.d.cts → types-BBfwsDxe.d.cts} +13 -7
  124. package/{types-CZsSYbeC.d.mts → types-BBfwsDxe.d.mts} +13 -7
  125. package/{view-compiler-M23WiVGG.d.mts → view-compiler-BDD93Luw.d.cts} +1 -1
  126. package/{view-compiler-CLTi1VL-.mjs → view-compiler-CSHSqZl7.mjs} +2 -2
  127. package/{view-compiler-cXqt4X-c.d.cts → view-compiler-CSNhmCY2.d.mts} +1 -1
  128. package/{view-compiler-DaOz5QVl.cjs → view-compiler-NqiortOA.cjs} +2 -2
  129. package/vite.d.cts +1 -1
  130. package/vite.d.mts +1 -1
  131. package/integration-state-xK4PLm5T.d.cts +0 -171
  132. package/integration-state-xK4PLm5T.d.mts +0 -171
  133. package/projection-BkYXvjTr.mjs +0 -5587
  134. package/projection-By63gMC-.cjs +0 -5670
  135. package/schemas-BSuo_eZQ.d.cts +0 -2160
  136. package/schemas-BSuo_eZQ.d.mts +0 -2160
@@ -1,4 +1,4 @@
1
- import { a as MATERIALIZING_CONCEPTS } from "./entity-config-g_oMPXlN.mjs";
1
+ import { a as MATERIALIZING_CONCEPTS } from "./entity-config-CI5CGfaN.mjs";
2
2
  import { a as W, c as isTextLike, i as RELATIONSHIP_TIERS, l as isTimestampLike, n as CONCEPT_TIERS, o as isAmbiguous, r as FIELD_TIERS, s as isNumericLike, u as tierFor } from "./mapping-score-CS-MTDL9.mjs";
3
3
  // ../core/src/entity-heuristics.ts
4
4
  const TARGET_CONCEPTS = [
@@ -1,4 +1,4 @@
1
- const require_entity_config = require("./entity-config-DiCJ6mhI.cjs");
1
+ const require_entity_config = require("./entity-config-BP8Cc_nC.cjs");
2
2
  const require_mapping_score = require("./mapping-score-D2TCQiOr.cjs");
3
3
  // ../core/src/entity-heuristics.ts
4
4
  const TARGET_CONCEPTS = [
@@ -0,0 +1,308 @@
1
+ import "./types-BBfwsDxe.mjs";
2
+ import "./auth-adapter-BIa-ZyVV.mjs";
3
+ import "./adapter-B4v4dwgD.mjs";
4
+ import { L as ProjectionJoin, R as ProjectionMapping, h as FilterExpr, l as ConfigValidationError, m as DiscoveredSchemaTable, p as DiscoveredColumnMeta } from "./entity-config-CXpGowQa.mjs";
5
+ import "./mapping-form-KHUlnC7A.mjs";
6
+ import "./mappings-config-wAe-p1rG.mjs";
7
+ import "./view-compiler-CSNhmCY2.mjs";
8
+ import "./sync-engine-UNORma7f.mjs";
9
+ declare const INTEGRATION_STEPS: readonly ["credential", "application", "schema", "mapping", "trigger", "sync", "widget"];
10
+ type StepId = (typeof INTEGRATION_STEPS)[number];
11
+ /** `blocked` means "prerequisite unmet", never "broken" — see C-19. */
12
+ type StepState = "done" | "active" | "blocked" | "failed" | "skipped";
13
+ type IntegrationStatus = "not_configured" | "sdk_installed" | "awaiting_connection" | "connected" | "schema_discovered" | "mapping_required" | "trigger_required" | "ready_to_sync" | "syncing" | "healthy" | "warning" | "error" |
14
+ /**
15
+ * @deprecated No longer derived. Liveness is its own dimension — read
16
+ * `ConnectionHealth` from `deriveLiveness`. Setup progress does not move
17
+ * backwards just because an app stopped running.
18
+ */
19
+ "disconnected";
20
+ interface RunFact {
21
+ at: number;
22
+ message?: string;
23
+ ok: boolean;
24
+ /**
25
+ * The HTTP status the host answered with, when there was one.
26
+ *
27
+ * Absent for a run that failed before any response existed, and for callers
28
+ * that do not track it — so every read must treat `undefined` as "unknown",
29
+ * never as "fine".
30
+ */
31
+ status?: number;
32
+ }
33
+ /**
34
+ * Where the reporting app is running, as the app itself understands it.
35
+ *
36
+ * `unknown` is a real value, not an absence: `detectHostEnvironment` refuses to
37
+ * guess when nothing places the app, and a bare `node server.js` with no
38
+ * NODE_ENV must still be able to connect and be shown as itself. Defaulting
39
+ * such a host to `local_dev` would file a production box's faults under local
40
+ * development, where nobody would look for them.
41
+ */
42
+ type HostEnvironment = "local_dev" | "preview" | "production" | "unknown";
43
+ interface IntegrationFacts {
44
+ discoveredTableCount: number;
45
+ /** The environment the app reported on its last heartbeat. */
46
+ environment?: HostEnvironment | null;
47
+ /**
48
+ * Has this app ever checked in? Distinguishes "never installed" from "was
49
+ * working, now silent" — the same absent heartbeat means different things,
50
+ * and only one of them is diagnosed rather than set up.
51
+ */
52
+ everConnected: boolean;
53
+ hasCredential: boolean;
54
+ /**
55
+ * The cadence the app said it heartbeats at. Liveness windows are multiples
56
+ * of this rather than a fixed constant, so an app that deliberately reports
57
+ * slowly is not called dead for obeying its own configuration.
58
+ */
59
+ heartbeatIntervalMs?: number | null;
60
+ lastHeartbeatAt: number | null;
61
+ lastRun: RunFact | null;
62
+ /**
63
+ * Whether any entity is mapped, expressed as a number for historical
64
+ * reasons — every producer sets it to 0 or 1, never a real total. Read it as
65
+ * a flag (`> 0`) and never render it as a quantity: doing so reported "1
66
+ * entity mapped" to a workspace with three. The true count lives on the
67
+ * mappings list, which the What syncs tab reads directly.
68
+ */
69
+ mappedEntityCount: number;
70
+ now: number;
71
+ /**
72
+ * Deployment presence, when this deployment has one. Absent or `http`
73
+ * transport keeps the cadence-derived behaviour every SDK in the field uses.
74
+ */
75
+ presence?: DeploymentPresence | null;
76
+ /**
77
+ * The result of Clivly asking the app directly whether it is up.
78
+ *
79
+ * Every other signal here is *pushed* by the app. On a serverless host there
80
+ * is no process between requests to push anything: the SDK's heartbeat timer
81
+ * fires once at boot and is then frozen, so cadence alone reports a perfectly
82
+ * healthy deployment as offline forever. A probe inverts that — Clivly asks,
83
+ * and a host that answers is up by definition.
84
+ *
85
+ * Absent keeps the pure cadence behaviour, so nothing changes for apps that
86
+ * do hold a long-lived process.
87
+ */
88
+ reachabilityProbe?: ReachabilityProbe | null;
89
+ /**
90
+ * Faults the running app diagnosed about itself on its last heartbeat — an
91
+ * unreadable database, a secret missing from the process environment. These
92
+ * are what make a reachable app `live_with_issues`; unfinished setup is not.
93
+ */
94
+ reportedIssues?: StepProblem[];
95
+ syncInFlight: boolean;
96
+ /** A trigger URL and secret both exist, so Clivly can ask the app to sync. */
97
+ triggerConfigured: boolean;
98
+ warnings: string[];
99
+ widgetInstalled: boolean;
100
+ }
101
+ interface StepProblem {
102
+ code: string;
103
+ fix: string;
104
+ message: string;
105
+ }
106
+ interface IntegrationStep {
107
+ blockedBy: StepId | null;
108
+ evidence: string | null;
109
+ id: StepId;
110
+ label: string;
111
+ problem: StepProblem | null;
112
+ state: StepState;
113
+ }
114
+ type ConnectionHealth = "live" | "live_with_issues" | "stale" | "offline";
115
+ /**
116
+ * Clivly's own answer to "is this app up", obtained by asking it rather than
117
+ * waiting to be told.
118
+ *
119
+ * `reachable` is deliberately about the *connection*, not the response body: an
120
+ * app that answers `401` has proved it is running just as conclusively as one
121
+ * that answers `200`. Only silence — a timeout, a refused connection, DNS that
122
+ * does not resolve — means offline.
123
+ */
124
+ interface ReachabilityProbe {
125
+ /** When Clivly performed the check. Probe results are cached, so this ages. */
126
+ checkedAt: number;
127
+ /** Did anything answer at the other end? */
128
+ reachable: boolean;
129
+ }
130
+ /** Which algorithm decides whether this deployment is up. */
131
+ type PresenceTransport = "websocket" | "http";
132
+ type PresenceConnectionState = "connected" | "reconnecting" | "disconnected";
133
+ /**
134
+ * A deployment's connection state as its `PresenceRoom` last persisted it.
135
+ *
136
+ * This exists because a socket has an explicit state and a timestamp does not.
137
+ * Deriving WebSocket liveness from heartbeat age would leave a disconnected app
138
+ * shown as live for 150 seconds and offline only after ten minutes, which is
139
+ * the whole reason this transport exists.
140
+ */
141
+ interface DeploymentPresence {
142
+ /** Sockets currently accepted in the room. */
143
+ activeInstanceCount: number;
144
+ connectionState: PresenceConnectionState;
145
+ transport: PresenceTransport;
146
+ }
147
+ interface ConnectionLiveness {
148
+ /** `"8s ago"`, or `"No heartbeat yet"` when the app has never reported. */
149
+ ageLabel: string;
150
+ ageMs: number | null;
151
+ environment: HostEnvironment | null;
152
+ health: ConnectionHealth;
153
+ /**
154
+ * Faults on a reachable app. Empty unless `health` is `live_with_issues`.
155
+ */
156
+ issues: StepProblem[];
157
+ /** Present when a deployment-presence record supplied this liveness result. */
158
+ presence?: Pick<DeploymentPresence, "connectionState" | "transport">;
159
+ /** Is a heartbeat recent enough to speak for the app as it is right now? */
160
+ reachable: boolean;
161
+ }
162
+ interface NextAction {
163
+ command: string | null;
164
+ envFile: string | null;
165
+ label: string;
166
+ }
167
+ interface IntegrationState {
168
+ /**
169
+ * Is the app running right now. Deliberately alongside `status` rather than
170
+ * folded into it: a surface must be able to say "setup reached mapping" and
171
+ * "the app is offline" in the same breath without either overwriting the
172
+ * other.
173
+ */
174
+ liveness: ConnectionLiveness;
175
+ next: NextAction | null;
176
+ status: IntegrationStatus;
177
+ steps: IntegrationStep[];
178
+ }
179
+ declare function joinFansOut(join: ProjectionJoin, joinTable: DiscoveredSchemaTable): boolean;
180
+ /** Every join in the projection that can multiply rows. */
181
+ declare function fanOutJoins(projection: ProjectionMapping, tablesByName: Map<string, DiscoveredSchemaTable>): ProjectionJoin[];
182
+ /**
183
+ * SQL generation for projection-backed entities.
184
+ *
185
+ * Base and joins are aliased by their ref key (`base`, then each join's `key`),
186
+ * which is what allows the same table to be joined twice and keeps generated
187
+ * SQL independent of host table names.
188
+ *
189
+ * Pure string generation — no DB access. Identifiers are escaped so output is
190
+ * deterministic and injection-safe.
191
+ */
192
+ /** Quote a single identifier part, escaping embedded double-quotes. */
193
+ declare function quoteIdent(name: string): string;
194
+ /**
195
+ * The identity expression. Composite identities concatenate their parts with
196
+ * `::`; validation guarantees every part is NOT NULL and non-text, which is
197
+ * what makes the concatenation collision-free.
198
+ *
199
+ * Exported unaliased because two paths need the same expression under different
200
+ * names: the view compiler aliases it `id`, and the SDK's projection push source
201
+ * also orders and keyset-paginates by it. Sharing one definition is what keeps
202
+ * a pushed row's `id` identical to the one the view would have produced.
203
+ */
204
+ declare function compileProjectionIdentity(projection: ProjectionMapping, basePkColumn: string): string;
205
+ declare function compileProjectionSelect(projection: ProjectionMapping, basePkColumn: string): {
206
+ columns: string[];
207
+ selectItems: string[];
208
+ };
209
+ declare function compileProjectionJoins(projection: ProjectionMapping): string[];
210
+ /** `FROM <baseTable> AS "base"` — the alias every ref resolves against. */
211
+ declare function compileProjectionFrom(projection: ProjectionMapping): string;
212
+ /**
213
+ * Hard ceiling on preview rows, regardless of what a caller asks for.
214
+ *
215
+ * A preview runs against a production database from a button a user can click
216
+ * as often as they like, so the cap belongs beside the query rather than in
217
+ * whichever caller happens to be passing a limit today.
218
+ */
219
+ declare const PREVIEW_MAX_ROWS = 50;
220
+ /**
221
+ * One SELECT reading a few rows through an UNSAVED projection, for the derived
222
+ * object builder's preview.
223
+ *
224
+ * Lives here, beside the view compiler, because both sides of the round trip
225
+ * need the identical statement: an embedded org runs it against its own
226
+ * database from `@clivly.com/api`, and a cloud org's host app runs it from
227
+ * `@clivly/sdk`. Two copies would be free to disagree about what the user is
228
+ * being shown, which is the whole value of a preview.
229
+ *
230
+ * Columns are aliased by FIELD NAME, not by ref token. That is the deliberate
231
+ * difference from the push source, which aliases by token because cloud ingest
232
+ * reads `row[token]`; a preview is read by a person, in a table whose headers
233
+ * are the field names they just typed.
234
+ */
235
+ declare function compileProjectionPreview(projection: ProjectionMapping, limit: number): string;
236
+ /**
237
+ * A derived object's filter is evaluated in the cloud against pushed rows, so
238
+ * it can only name columns of the base table.
239
+ *
240
+ * Every rejected shape here fails *silently* today, which is the whole reason
241
+ * the check exists — a filter that cannot be honoured must error, never quietly
242
+ * return the wrong rows. The three shapes fail in different directions:
243
+ *
244
+ * - `$raw` is opaque SQL meant for the embedded model. The cloud path cannot
245
+ * evaluate it and passes every row, so the filter is ignored and the object
246
+ * syncs UNFILTERED.
247
+ * - A joined-table column resolves to nothing on a pushed row, so under a
248
+ * positive operator (`eq`, `in`) no row matches and the object syncs EMPTY.
249
+ * - The same unresolvable column under a NEGATIVE operator (`ne`, `isNull`,
250
+ * `notIn`) is the dangerous one: the missing cell reads as null, so the
251
+ * predicate is true for every row and a filter meant to narrow the sync
252
+ * ADMITS EVERYTHING. Nobody notices extra rows arriving.
253
+ *
254
+ * Rejecting an unresolvable column closes the last two together.
255
+ */
256
+ declare function validateProjectionFilter(filter: FilterExpr | undefined, projection: ProjectionMapping, schema: DiscoveredSchemaTable[], base: string): ConfigValidationError[];
257
+ /**
258
+ * Validate a projection against the discovered schema. Returns every error
259
+ * found (not just the first) so a builder UI can show them all at once.
260
+ */
261
+ declare function validateProjection(projection: ProjectionMapping, schema: DiscoveredSchemaTable[], base: string): ConfigValidationError[];
262
+ /**
263
+ * Accessors over a discovered table's schema-v2 metadata.
264
+ *
265
+ * Every helper treats *absent* metadata as **unknown**, never as a negative
266
+ * fact. `coversUniqueKey` returning false on a v1 payload is what makes
267
+ * projection validation fail closed: we cannot prove a join is many-to-one, so
268
+ * we refuse to compile it rather than guess.
269
+ */
270
+ declare function columnMetaFor(table: DiscoveredSchemaTable, column: string): DiscoveredColumnMeta | undefined;
271
+ /**
272
+ * Every primary-key column. More than one entry means a composite PK, which is
273
+ * why `base_pk` identity is rejected for such tables.
274
+ */
275
+ declare function primaryKeyColumns(table: DiscoveredSchemaTable): string[];
276
+ /**
277
+ * Do `columns` contain every column of at least one unique key on `table`?
278
+ *
279
+ * This is the fan-out test. A join whose ON columns cover a unique key of the
280
+ * joined table matches at most one row per base row; one that does not can
281
+ * match many.
282
+ */
283
+ declare function coversUniqueKey(table: DiscoveredSchemaTable, columns: string[]): boolean;
284
+ /**
285
+ * A discovered table whose enrichment metadata is known to be present.
286
+ *
287
+ * This narrows only the *presence* of the two optional fields. It says nothing
288
+ * about their contents — an empty `uniqueConstraints` is a known-empty fact
289
+ * (the table genuinely has no unique keys), which is exactly the distinction
290
+ * `hasRichMeta` has always drawn and must keep drawing.
291
+ */
292
+ type RichMetaTable = DiscoveredSchemaTable & {
293
+ columnsMeta: DiscoveredColumnMeta[];
294
+ uniqueConstraints: string[][];
295
+ };
296
+ /**
297
+ * Is this table's payload rich enough to validate a projection against?
298
+ *
299
+ * A type predicate rather than a plain boolean so the narrowing is visible to
300
+ * the compiler: callers that guard on this can iterate `columnsMeta` directly
301
+ * instead of casting, and a cast that outlives its guard becomes a type error
302
+ * rather than a silent walk over `undefined`.
303
+ *
304
+ * The invariant is unchanged: this reports whether the metadata is *known*,
305
+ * never whether the table has keys. Absent metadata stays UNKNOWN.
306
+ */
307
+ declare function hasRichMeta(table: DiscoveredSchemaTable): table is RichMetaTable;
308
+ export { StepProblem as C, StepId as S, IntegrationFacts as _, validateProjection as a, IntegrationStep as b, compileProjectionFrom as c, compileProjectionPreview as d, compileProjectionSelect as f, ConnectionLiveness as g, joinFansOut as h, primaryKeyColumns as i, compileProjectionIdentity as l, fanOutJoins as m, coversUniqueKey as n, validateProjectionFilter as o, quoteIdent as p, hasRichMeta as r, PREVIEW_MAX_ROWS as s, columnMetaFor as t, compileProjectionJoins as u, IntegrationState as v, StepState as w, NextAction as x, IntegrationStatus as y };
@@ -0,0 +1,308 @@
1
+ import "./types-BBfwsDxe.cjs";
2
+ import "./auth-adapter-DwtMJb7D.cjs";
3
+ import "./adapter-BK3gsby5.cjs";
4
+ import { L as ProjectionJoin, R as ProjectionMapping, h as FilterExpr, l as ConfigValidationError, m as DiscoveredSchemaTable, p as DiscoveredColumnMeta } from "./entity-config-CXpGowQa.cjs";
5
+ import "./mapping-form-Bg_hgNoL.cjs";
6
+ import "./mappings-config-DNo_Cum_.cjs";
7
+ import "./view-compiler-BDD93Luw.cjs";
8
+ import "./sync-engine-DCjTr2XQ.cjs";
9
+ declare const INTEGRATION_STEPS: readonly ["credential", "application", "schema", "mapping", "trigger", "sync", "widget"];
10
+ type StepId = (typeof INTEGRATION_STEPS)[number];
11
+ /** `blocked` means "prerequisite unmet", never "broken" — see C-19. */
12
+ type StepState = "done" | "active" | "blocked" | "failed" | "skipped";
13
+ type IntegrationStatus = "not_configured" | "sdk_installed" | "awaiting_connection" | "connected" | "schema_discovered" | "mapping_required" | "trigger_required" | "ready_to_sync" | "syncing" | "healthy" | "warning" | "error" |
14
+ /**
15
+ * @deprecated No longer derived. Liveness is its own dimension — read
16
+ * `ConnectionHealth` from `deriveLiveness`. Setup progress does not move
17
+ * backwards just because an app stopped running.
18
+ */
19
+ "disconnected";
20
+ interface RunFact {
21
+ at: number;
22
+ message?: string;
23
+ ok: boolean;
24
+ /**
25
+ * The HTTP status the host answered with, when there was one.
26
+ *
27
+ * Absent for a run that failed before any response existed, and for callers
28
+ * that do not track it — so every read must treat `undefined` as "unknown",
29
+ * never as "fine".
30
+ */
31
+ status?: number;
32
+ }
33
+ /**
34
+ * Where the reporting app is running, as the app itself understands it.
35
+ *
36
+ * `unknown` is a real value, not an absence: `detectHostEnvironment` refuses to
37
+ * guess when nothing places the app, and a bare `node server.js` with no
38
+ * NODE_ENV must still be able to connect and be shown as itself. Defaulting
39
+ * such a host to `local_dev` would file a production box's faults under local
40
+ * development, where nobody would look for them.
41
+ */
42
+ type HostEnvironment = "local_dev" | "preview" | "production" | "unknown";
43
+ interface IntegrationFacts {
44
+ discoveredTableCount: number;
45
+ /** The environment the app reported on its last heartbeat. */
46
+ environment?: HostEnvironment | null;
47
+ /**
48
+ * Has this app ever checked in? Distinguishes "never installed" from "was
49
+ * working, now silent" — the same absent heartbeat means different things,
50
+ * and only one of them is diagnosed rather than set up.
51
+ */
52
+ everConnected: boolean;
53
+ hasCredential: boolean;
54
+ /**
55
+ * The cadence the app said it heartbeats at. Liveness windows are multiples
56
+ * of this rather than a fixed constant, so an app that deliberately reports
57
+ * slowly is not called dead for obeying its own configuration.
58
+ */
59
+ heartbeatIntervalMs?: number | null;
60
+ lastHeartbeatAt: number | null;
61
+ lastRun: RunFact | null;
62
+ /**
63
+ * Whether any entity is mapped, expressed as a number for historical
64
+ * reasons — every producer sets it to 0 or 1, never a real total. Read it as
65
+ * a flag (`> 0`) and never render it as a quantity: doing so reported "1
66
+ * entity mapped" to a workspace with three. The true count lives on the
67
+ * mappings list, which the What syncs tab reads directly.
68
+ */
69
+ mappedEntityCount: number;
70
+ now: number;
71
+ /**
72
+ * Deployment presence, when this deployment has one. Absent or `http`
73
+ * transport keeps the cadence-derived behaviour every SDK in the field uses.
74
+ */
75
+ presence?: DeploymentPresence | null;
76
+ /**
77
+ * The result of Clivly asking the app directly whether it is up.
78
+ *
79
+ * Every other signal here is *pushed* by the app. On a serverless host there
80
+ * is no process between requests to push anything: the SDK's heartbeat timer
81
+ * fires once at boot and is then frozen, so cadence alone reports a perfectly
82
+ * healthy deployment as offline forever. A probe inverts that — Clivly asks,
83
+ * and a host that answers is up by definition.
84
+ *
85
+ * Absent keeps the pure cadence behaviour, so nothing changes for apps that
86
+ * do hold a long-lived process.
87
+ */
88
+ reachabilityProbe?: ReachabilityProbe | null;
89
+ /**
90
+ * Faults the running app diagnosed about itself on its last heartbeat — an
91
+ * unreadable database, a secret missing from the process environment. These
92
+ * are what make a reachable app `live_with_issues`; unfinished setup is not.
93
+ */
94
+ reportedIssues?: StepProblem[];
95
+ syncInFlight: boolean;
96
+ /** A trigger URL and secret both exist, so Clivly can ask the app to sync. */
97
+ triggerConfigured: boolean;
98
+ warnings: string[];
99
+ widgetInstalled: boolean;
100
+ }
101
+ interface StepProblem {
102
+ code: string;
103
+ fix: string;
104
+ message: string;
105
+ }
106
+ interface IntegrationStep {
107
+ blockedBy: StepId | null;
108
+ evidence: string | null;
109
+ id: StepId;
110
+ label: string;
111
+ problem: StepProblem | null;
112
+ state: StepState;
113
+ }
114
+ type ConnectionHealth = "live" | "live_with_issues" | "stale" | "offline";
115
+ /**
116
+ * Clivly's own answer to "is this app up", obtained by asking it rather than
117
+ * waiting to be told.
118
+ *
119
+ * `reachable` is deliberately about the *connection*, not the response body: an
120
+ * app that answers `401` has proved it is running just as conclusively as one
121
+ * that answers `200`. Only silence — a timeout, a refused connection, DNS that
122
+ * does not resolve — means offline.
123
+ */
124
+ interface ReachabilityProbe {
125
+ /** When Clivly performed the check. Probe results are cached, so this ages. */
126
+ checkedAt: number;
127
+ /** Did anything answer at the other end? */
128
+ reachable: boolean;
129
+ }
130
+ /** Which algorithm decides whether this deployment is up. */
131
+ type PresenceTransport = "websocket" | "http";
132
+ type PresenceConnectionState = "connected" | "reconnecting" | "disconnected";
133
+ /**
134
+ * A deployment's connection state as its `PresenceRoom` last persisted it.
135
+ *
136
+ * This exists because a socket has an explicit state and a timestamp does not.
137
+ * Deriving WebSocket liveness from heartbeat age would leave a disconnected app
138
+ * shown as live for 150 seconds and offline only after ten minutes, which is
139
+ * the whole reason this transport exists.
140
+ */
141
+ interface DeploymentPresence {
142
+ /** Sockets currently accepted in the room. */
143
+ activeInstanceCount: number;
144
+ connectionState: PresenceConnectionState;
145
+ transport: PresenceTransport;
146
+ }
147
+ interface ConnectionLiveness {
148
+ /** `"8s ago"`, or `"No heartbeat yet"` when the app has never reported. */
149
+ ageLabel: string;
150
+ ageMs: number | null;
151
+ environment: HostEnvironment | null;
152
+ health: ConnectionHealth;
153
+ /**
154
+ * Faults on a reachable app. Empty unless `health` is `live_with_issues`.
155
+ */
156
+ issues: StepProblem[];
157
+ /** Present when a deployment-presence record supplied this liveness result. */
158
+ presence?: Pick<DeploymentPresence, "connectionState" | "transport">;
159
+ /** Is a heartbeat recent enough to speak for the app as it is right now? */
160
+ reachable: boolean;
161
+ }
162
+ interface NextAction {
163
+ command: string | null;
164
+ envFile: string | null;
165
+ label: string;
166
+ }
167
+ interface IntegrationState {
168
+ /**
169
+ * Is the app running right now. Deliberately alongside `status` rather than
170
+ * folded into it: a surface must be able to say "setup reached mapping" and
171
+ * "the app is offline" in the same breath without either overwriting the
172
+ * other.
173
+ */
174
+ liveness: ConnectionLiveness;
175
+ next: NextAction | null;
176
+ status: IntegrationStatus;
177
+ steps: IntegrationStep[];
178
+ }
179
+ declare function joinFansOut(join: ProjectionJoin, joinTable: DiscoveredSchemaTable): boolean;
180
+ /** Every join in the projection that can multiply rows. */
181
+ declare function fanOutJoins(projection: ProjectionMapping, tablesByName: Map<string, DiscoveredSchemaTable>): ProjectionJoin[];
182
+ /**
183
+ * SQL generation for projection-backed entities.
184
+ *
185
+ * Base and joins are aliased by their ref key (`base`, then each join's `key`),
186
+ * which is what allows the same table to be joined twice and keeps generated
187
+ * SQL independent of host table names.
188
+ *
189
+ * Pure string generation — no DB access. Identifiers are escaped so output is
190
+ * deterministic and injection-safe.
191
+ */
192
+ /** Quote a single identifier part, escaping embedded double-quotes. */
193
+ declare function quoteIdent(name: string): string;
194
+ /**
195
+ * The identity expression. Composite identities concatenate their parts with
196
+ * `::`; validation guarantees every part is NOT NULL and non-text, which is
197
+ * what makes the concatenation collision-free.
198
+ *
199
+ * Exported unaliased because two paths need the same expression under different
200
+ * names: the view compiler aliases it `id`, and the SDK's projection push source
201
+ * also orders and keyset-paginates by it. Sharing one definition is what keeps
202
+ * a pushed row's `id` identical to the one the view would have produced.
203
+ */
204
+ declare function compileProjectionIdentity(projection: ProjectionMapping, basePkColumn: string): string;
205
+ declare function compileProjectionSelect(projection: ProjectionMapping, basePkColumn: string): {
206
+ columns: string[];
207
+ selectItems: string[];
208
+ };
209
+ declare function compileProjectionJoins(projection: ProjectionMapping): string[];
210
+ /** `FROM <baseTable> AS "base"` — the alias every ref resolves against. */
211
+ declare function compileProjectionFrom(projection: ProjectionMapping): string;
212
+ /**
213
+ * Hard ceiling on preview rows, regardless of what a caller asks for.
214
+ *
215
+ * A preview runs against a production database from a button a user can click
216
+ * as often as they like, so the cap belongs beside the query rather than in
217
+ * whichever caller happens to be passing a limit today.
218
+ */
219
+ declare const PREVIEW_MAX_ROWS = 50;
220
+ /**
221
+ * One SELECT reading a few rows through an UNSAVED projection, for the derived
222
+ * object builder's preview.
223
+ *
224
+ * Lives here, beside the view compiler, because both sides of the round trip
225
+ * need the identical statement: an embedded org runs it against its own
226
+ * database from `@clivly.com/api`, and a cloud org's host app runs it from
227
+ * `@clivly/sdk`. Two copies would be free to disagree about what the user is
228
+ * being shown, which is the whole value of a preview.
229
+ *
230
+ * Columns are aliased by FIELD NAME, not by ref token. That is the deliberate
231
+ * difference from the push source, which aliases by token because cloud ingest
232
+ * reads `row[token]`; a preview is read by a person, in a table whose headers
233
+ * are the field names they just typed.
234
+ */
235
+ declare function compileProjectionPreview(projection: ProjectionMapping, limit: number): string;
236
+ /**
237
+ * A derived object's filter is evaluated in the cloud against pushed rows, so
238
+ * it can only name columns of the base table.
239
+ *
240
+ * Every rejected shape here fails *silently* today, which is the whole reason
241
+ * the check exists — a filter that cannot be honoured must error, never quietly
242
+ * return the wrong rows. The three shapes fail in different directions:
243
+ *
244
+ * - `$raw` is opaque SQL meant for the embedded model. The cloud path cannot
245
+ * evaluate it and passes every row, so the filter is ignored and the object
246
+ * syncs UNFILTERED.
247
+ * - A joined-table column resolves to nothing on a pushed row, so under a
248
+ * positive operator (`eq`, `in`) no row matches and the object syncs EMPTY.
249
+ * - The same unresolvable column under a NEGATIVE operator (`ne`, `isNull`,
250
+ * `notIn`) is the dangerous one: the missing cell reads as null, so the
251
+ * predicate is true for every row and a filter meant to narrow the sync
252
+ * ADMITS EVERYTHING. Nobody notices extra rows arriving.
253
+ *
254
+ * Rejecting an unresolvable column closes the last two together.
255
+ */
256
+ declare function validateProjectionFilter(filter: FilterExpr | undefined, projection: ProjectionMapping, schema: DiscoveredSchemaTable[], base: string): ConfigValidationError[];
257
+ /**
258
+ * Validate a projection against the discovered schema. Returns every error
259
+ * found (not just the first) so a builder UI can show them all at once.
260
+ */
261
+ declare function validateProjection(projection: ProjectionMapping, schema: DiscoveredSchemaTable[], base: string): ConfigValidationError[];
262
+ /**
263
+ * Accessors over a discovered table's schema-v2 metadata.
264
+ *
265
+ * Every helper treats *absent* metadata as **unknown**, never as a negative
266
+ * fact. `coversUniqueKey` returning false on a v1 payload is what makes
267
+ * projection validation fail closed: we cannot prove a join is many-to-one, so
268
+ * we refuse to compile it rather than guess.
269
+ */
270
+ declare function columnMetaFor(table: DiscoveredSchemaTable, column: string): DiscoveredColumnMeta | undefined;
271
+ /**
272
+ * Every primary-key column. More than one entry means a composite PK, which is
273
+ * why `base_pk` identity is rejected for such tables.
274
+ */
275
+ declare function primaryKeyColumns(table: DiscoveredSchemaTable): string[];
276
+ /**
277
+ * Do `columns` contain every column of at least one unique key on `table`?
278
+ *
279
+ * This is the fan-out test. A join whose ON columns cover a unique key of the
280
+ * joined table matches at most one row per base row; one that does not can
281
+ * match many.
282
+ */
283
+ declare function coversUniqueKey(table: DiscoveredSchemaTable, columns: string[]): boolean;
284
+ /**
285
+ * A discovered table whose enrichment metadata is known to be present.
286
+ *
287
+ * This narrows only the *presence* of the two optional fields. It says nothing
288
+ * about their contents — an empty `uniqueConstraints` is a known-empty fact
289
+ * (the table genuinely has no unique keys), which is exactly the distinction
290
+ * `hasRichMeta` has always drawn and must keep drawing.
291
+ */
292
+ type RichMetaTable = DiscoveredSchemaTable & {
293
+ columnsMeta: DiscoveredColumnMeta[];
294
+ uniqueConstraints: string[][];
295
+ };
296
+ /**
297
+ * Is this table's payload rich enough to validate a projection against?
298
+ *
299
+ * A type predicate rather than a plain boolean so the narrowing is visible to
300
+ * the compiler: callers that guard on this can iterate `columnsMeta` directly
301
+ * instead of casting, and a cast that outlives its guard becomes a type error
302
+ * rather than a silent walk over `undefined`.
303
+ *
304
+ * The invariant is unchanged: this reports whether the metadata is *known*,
305
+ * never whether the table has keys. Absent metadata stays UNKNOWN.
306
+ */
307
+ declare function hasRichMeta(table: DiscoveredSchemaTable): table is RichMetaTable;
308
+ export { StepProblem as C, StepId as S, IntegrationFacts as _, validateProjection as a, IntegrationStep as b, compileProjectionFrom as c, compileProjectionPreview as d, compileProjectionSelect as f, ConnectionLiveness as g, joinFansOut as h, primaryKeyColumns as i, compileProjectionIdentity as l, fanOutJoins as m, coversUniqueKey as n, validateProjectionFilter as o, quoteIdent as p, hasRichMeta as r, PREVIEW_MAX_ROWS as s, columnMetaFor as t, compileProjectionJoins as u, IntegrationState as v, StepState as w, NextAction as x, IntegrationStatus as y };
package/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const require_entity_config = require("./entity-config-DiCJ6mhI.cjs");
4
- const require_entity_heuristics = require("./entity-heuristics-CIParuQe.cjs");
3
+ const require_entity_config = require("./entity-config-BP8Cc_nC.cjs");
4
+ const require_entity_heuristics = require("./entity-heuristics-DNmrcd0b.cjs");
5
5
  require("./mapping-score-D2TCQiOr.cjs");
6
- const require_sdk = require("./sdk-BEHVvB18.cjs");
6
+ const require_sdk = require("./sdk-oUjl5HNU.cjs");
7
7
  let node_child_process = require("node:child_process");
8
8
  let node_fs = require("node:fs");
9
9
  let node_module = require("node:module");
package/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { t as CANONICAL_FIELDS } from "./entity-config-g_oMPXlN.mjs";
3
- import { d as suggestCursorField, i as isFrameworkTable, l as scoreFieldMap, n as hasDefiningColumn, o as matchesConcept, p as toFieldMap, s as requiredFieldsFor, u as scoreRelationships } from "./entity-heuristics-DE5ujoHw.mjs";
2
+ import { t as CANONICAL_FIELDS } from "./entity-config-CI5CGfaN.mjs";
3
+ import { d as suggestCursorField, i as isFrameworkTable, l as scoreFieldMap, n as hasDefiningColumn, o as matchesConcept, p as toFieldMap, s as requiredFieldsFor, u as scoreRelationships } from "./entity-heuristics-DAxqagJA.mjs";
4
4
  import "./mapping-score-CS-MTDL9.mjs";
5
- import { n as createClivlySDK, u as isPlaceholderUrl } from "./sdk-ChyrSl32.mjs";
5
+ import { n as createClivlySDK, u as isPlaceholderUrl } from "./sdk-DfdHv-S9.mjs";
6
6
  import { createRequire } from "node:module";
7
7
  import { spawn } from "node:child_process";
8
8
  import { accessSync, constants, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, watch, writeFileSync } from "node:fs";