@clivly/core 0.9.0 → 0.9.1

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 (38) hide show
  1. package/README.md +88 -3
  2. package/dist/drizzle.d.cts +1 -1
  3. package/dist/drizzle.d.mts +1 -1
  4. package/dist/{entity-config-Tb5bbKLj.mjs → entity-config-8Fgr6IOH.mjs} +47 -2
  5. package/dist/entity-config-CLxI8dVb.d.cts +556 -0
  6. package/dist/entity-config-CLxI8dVb.d.mts +556 -0
  7. package/dist/{entity-config-PoOGzvpN.cjs → entity-config-Dh8aEcgj.cjs} +52 -1
  8. package/dist/entity-config.cjs +2 -1
  9. package/dist/entity-config.d.cts +2 -414
  10. package/dist/entity-config.d.mts +2 -414
  11. package/dist/entity-config.mjs +2 -2
  12. package/dist/entity-heuristics.cjs +1 -1
  13. package/dist/entity-heuristics.d.cts +1 -1
  14. package/dist/entity-heuristics.d.mts +1 -1
  15. package/dist/entity-heuristics.mjs +1 -1
  16. package/dist/index.cjs +2 -2
  17. package/dist/index.d.cts +2 -2
  18. package/dist/index.d.mts +2 -2
  19. package/dist/index.mjs +2 -2
  20. package/dist/mapping-form.d.cts +1 -1
  21. package/dist/mapping-form.d.mts +1 -1
  22. package/dist/mappings-config.cjs +1 -1
  23. package/dist/mappings-config.d.cts +46 -1
  24. package/dist/mappings-config.d.mts +46 -1
  25. package/dist/mappings-config.mjs +1 -1
  26. package/dist/sync-engine.cjs +1 -1
  27. package/dist/sync-engine.d.cts +1 -1
  28. package/dist/sync-engine.d.mts +1 -1
  29. package/dist/sync-engine.mjs +1 -1
  30. package/dist/{view-compiler-BwZ9UgLp.cjs → view-compiler-BpNI8Ttw.cjs} +22 -0
  31. package/dist/{view-compiler-BKrBA_II.mjs → view-compiler-CcqsGxv4.mjs} +17 -1
  32. package/dist/view-compiler.cjs +2 -1
  33. package/dist/view-compiler.d.cts +12 -2
  34. package/dist/view-compiler.d.mts +12 -2
  35. package/dist/view-compiler.mjs +2 -2
  36. package/package.json +1 -1
  37. package/dist/mappings-config-B0W5bVZj.d.mts +0 -168
  38. package/dist/mappings-config-BWo4cRDF.d.cts +0 -168
@@ -0,0 +1,556 @@
1
+ import { z } from "zod";
2
+ //#region src/projection.d.ts
3
+ /**
4
+ * Projection-backed custom mappings — one custom object derived from a base
5
+ * table plus explicit joins.
6
+ *
7
+ * A projection is deliberately narrow: equality joins only, direct column
8
+ * bindings only, no expressions and no aggregation. Everything a user can
9
+ * express here compiles to a single read-only view whose `id` column is
10
+ * provably unique per row, which is what lets the sync engine consume it
11
+ * unchanged.
12
+ *
13
+ * Refs address tables symbolically: `"base"` for the base table, or a join's
14
+ * `key`. Raw table names are never accepted in a ref, so a projection can
15
+ * never reach a table it did not declare.
16
+ */
17
+ /** The reserved ref name for the projection's base table. */
18
+ declare const BASE_REF = "base";
19
+ declare const projectionRefSchema: z.ZodObject<{
20
+ table: z.ZodString;
21
+ column: z.ZodString;
22
+ }, z.core.$strict>;
23
+ type ProjectionRef = z.infer<typeof projectionRefSchema>;
24
+ declare const projectionJoinSchema: z.ZodObject<{
25
+ key: z.ZodString;
26
+ table: z.ZodString;
27
+ type: z.ZodEnum<{
28
+ inner: "inner";
29
+ left: "left";
30
+ }>;
31
+ on: z.ZodArray<z.ZodObject<{
32
+ left: z.ZodObject<{
33
+ table: z.ZodString;
34
+ column: z.ZodString;
35
+ }, z.core.$strict>;
36
+ op: z.ZodLiteral<"eq">;
37
+ right: z.ZodObject<{
38
+ table: z.ZodString;
39
+ column: z.ZodString;
40
+ }, z.core.$strict>;
41
+ }, z.core.$strict>>;
42
+ }, z.core.$strict>;
43
+ type ProjectionJoin = z.infer<typeof projectionJoinSchema>;
44
+ declare const projectionFieldBindingSchema: z.ZodObject<{
45
+ from: z.ZodObject<{
46
+ table: z.ZodString;
47
+ column: z.ZodString;
48
+ }, z.core.$strict>;
49
+ }, z.core.$strict>;
50
+ type ProjectionFieldBinding = z.infer<typeof projectionFieldBindingSchema>;
51
+ declare const projectionIdentitySchema: z.ZodUnion<readonly [z.ZodObject<{
52
+ kind: z.ZodLiteral<"base_pk">;
53
+ column: z.ZodOptional<z.ZodString>;
54
+ }, z.core.$strict>, z.ZodObject<{
55
+ kind: z.ZodLiteral<"column">;
56
+ from: z.ZodObject<{
57
+ table: z.ZodString;
58
+ column: z.ZodString;
59
+ }, z.core.$strict>;
60
+ }, z.core.$strict>, z.ZodObject<{
61
+ kind: z.ZodLiteral<"composite">;
62
+ parts: z.ZodArray<z.ZodObject<{
63
+ table: z.ZodString;
64
+ column: z.ZodString;
65
+ }, z.core.$strict>>;
66
+ }, z.core.$strict>]>;
67
+ type ProjectionIdentity = z.infer<typeof projectionIdentitySchema>;
68
+ declare const projectionSchema: z.ZodObject<{
69
+ version: z.ZodLiteral<1>;
70
+ kind: z.ZodLiteral<"projection">;
71
+ entityKey: z.ZodString;
72
+ baseTable: z.ZodString;
73
+ joins: z.ZodArray<z.ZodObject<{
74
+ key: z.ZodString;
75
+ table: z.ZodString;
76
+ type: z.ZodEnum<{
77
+ inner: "inner";
78
+ left: "left";
79
+ }>;
80
+ on: z.ZodArray<z.ZodObject<{
81
+ left: z.ZodObject<{
82
+ table: z.ZodString;
83
+ column: z.ZodString;
84
+ }, z.core.$strict>;
85
+ op: z.ZodLiteral<"eq">;
86
+ right: z.ZodObject<{
87
+ table: z.ZodString;
88
+ column: z.ZodString;
89
+ }, z.core.$strict>;
90
+ }, z.core.$strict>>;
91
+ }, z.core.$strict>>;
92
+ fieldBindings: z.ZodRecord<z.ZodString, z.ZodObject<{
93
+ from: z.ZodObject<{
94
+ table: z.ZodString;
95
+ column: z.ZodString;
96
+ }, z.core.$strict>;
97
+ }, z.core.$strict>>;
98
+ identity: z.ZodUnion<readonly [z.ZodObject<{
99
+ kind: z.ZodLiteral<"base_pk">;
100
+ column: z.ZodOptional<z.ZodString>;
101
+ }, z.core.$strict>, z.ZodObject<{
102
+ kind: z.ZodLiteral<"column">;
103
+ from: z.ZodObject<{
104
+ table: z.ZodString;
105
+ column: z.ZodString;
106
+ }, z.core.$strict>;
107
+ }, z.core.$strict>, z.ZodObject<{
108
+ kind: z.ZodLiteral<"composite">;
109
+ parts: z.ZodArray<z.ZodObject<{
110
+ table: z.ZodString;
111
+ column: z.ZodString;
112
+ }, z.core.$strict>>;
113
+ }, z.core.$strict>]>;
114
+ }, z.core.$strict>;
115
+ type ProjectionMapping = z.infer<typeof projectionSchema>;
116
+ /**
117
+ * Every column ref an identity depends on. `basePkColumn` is the base table's
118
+ * discovered PK, used only when a `base_pk` identity omits an explicit column.
119
+ */
120
+ declare function identityRefs(identity: ProjectionIdentity, basePkColumn: string): ProjectionRef[];
121
+ //#endregion
122
+ //#region src/entity-config.d.ts
123
+ /**
124
+ * Entity Config v2 — the declarative contract that turns Clivly's "schema-aware"
125
+ * promise into a real capability.
126
+ *
127
+ * A CRM entity is no longer a flat table name. It is a *derived entity*: a
128
+ * filtered slice of a host table (`source` + `filter`), a column allowlist
129
+ * (`fields` + `readOnly`), and declared `relationships` to other entities. The
130
+ * same host table can back several entities (e.g. `users` → owners + members)
131
+ * distinguished by `role`.
132
+ *
133
+ * This module is the Phase 1 slice: types, schema, `defineClivlyConfig` (a
134
+ * structural helper) and `validateEntitiesConfig` (semantic validation against
135
+ * the host's discovered schema). It performs NO DB access and generates no SQL —
136
+ * the view compiler (Phase 2) and sync engine (Phase 3) consume this contract.
137
+ */
138
+ /** Canonical CRM concepts a host entity can map onto. */
139
+ declare const CRM_CONCEPTS: readonly ["contact", "company", "deal", "activity", "conversation", "note"];
140
+ type CrmConcept = (typeof CRM_CONCEPTS)[number];
141
+ /**
142
+ * The canonical `fields` keys the mirror actually persists, per concept — the
143
+ * crm_* columns the sync store writes. An entity's `fields` map keys must be one
144
+ * of these: a non-canonical key (e.g. `fullName` instead of `name`) validates
145
+ * structurally but has no destination column, so the store silently writes an
146
+ * empty value. `validateEntitiesConfig` flags those.
147
+ *
148
+ * This is the single source of truth — the Drizzle store imports it, so the
149
+ * two can't drift (the drift is what made the silent-data-loss trap possible).
150
+ * Concepts absent here aren't materialized yet, so their field keys are
151
+ * unconstrained.
152
+ */
153
+ declare const CANONICAL_FIELDS: {
154
+ readonly contact: readonly ["name", "email", "title", "status"];
155
+ readonly company: readonly ["name", "domain", "industry", "size"];
156
+ readonly deal: readonly ["name", "value", "stage"];
157
+ };
158
+ /**
159
+ * The concepts the mapping→sync pipeline can actually materialize into `crm_*`
160
+ * tables. These are exactly the CANONICAL_FIELDS keys — the Drizzle sync store's
161
+ * `persist()` throws for any other concept, so offering one (in the mapping
162
+ * editor, in suggestions, or via the upsert API) is a broken affordance.
163
+ *
164
+ * The broader CRM_CONCEPTS set still validates structurally, so previously
165
+ * stored rows for not-yet-materialized concepts keep rendering. When a concept
166
+ * gains a sync-store path, add its canonical fields above and it joins this set
167
+ * automatically (guarded by the MATERIALIZING_CONCEPTS drift test).
168
+ */
169
+ declare const MATERIALIZING_CONCEPTS: readonly ["contact", "company", "deal"];
170
+ type MaterializingConcept = (typeof MATERIALIZING_CONCEPTS)[number];
171
+ /**
172
+ * The org-defined custom-object target. Deliberately NOT a member of
173
+ * CRM_CONCEPTS / CANONICAL_FIELDS / MATERIALIZING_CONCEPTS — a custom object has
174
+ * no fixed canonical columns; its mapping's fieldMap keys ARE its properties.
175
+ * Handled as an explicit branch wherever concepts are switched on, so the
176
+ * canonical-concept invariants (and their drift test) stay intact.
177
+ */
178
+ declare const CUSTOM_CONCEPT: "custom";
179
+ declare const filterValueSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodUnion<readonly [z.ZodObject<{
180
+ eq: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
181
+ }, z.core.$strict>, z.ZodObject<{
182
+ ne: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
183
+ }, z.core.$strict>, z.ZodObject<{
184
+ in: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
185
+ }, z.core.$strict>, z.ZodObject<{
186
+ notIn: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
187
+ }, z.core.$strict>, z.ZodObject<{
188
+ isNull: z.ZodLiteral<true>;
189
+ }, z.core.$strict>, z.ZodObject<{
190
+ isNotNull: z.ZodLiteral<true>;
191
+ }, z.core.$strict>]>]>;
192
+ /** `$raw` is a reserved key; a column literally named `$raw` is not addressable. */
193
+ declare const filterSchema: z.ZodUnion<readonly [z.ZodObject<{
194
+ $raw: z.ZodString;
195
+ }, z.core.$strict>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodUnion<readonly [z.ZodObject<{
196
+ eq: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
197
+ }, z.core.$strict>, z.ZodObject<{
198
+ ne: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
199
+ }, z.core.$strict>, z.ZodObject<{
200
+ in: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
201
+ }, z.core.$strict>, z.ZodObject<{
202
+ notIn: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
203
+ }, z.core.$strict>, z.ZodObject<{
204
+ isNull: z.ZodLiteral<true>;
205
+ }, z.core.$strict>, z.ZodObject<{
206
+ isNotNull: z.ZodLiteral<true>;
207
+ }, z.core.$strict>]>]>>]>;
208
+ type FilterExpr = z.infer<typeof filterSchema>;
209
+ /** A single column predicate value (scalar shorthand or operator object). */
210
+ type FilterValue = z.infer<typeof filterValueSchema>;
211
+ /**
212
+ * How the link between two entities is expressed in the host schema:
213
+ * - `fkOn: "company"` — FK lives on the company table (e.g. organizations.owner_id)
214
+ * - `fkOn: "contact"` — FK lives on the contact table (e.g. users.organization_id)
215
+ * - `through` — a join table sits between them (many-to-many, role often here)
216
+ * - `$raw` — opaque SQL join fragment (escape hatch; not schema-validated)
217
+ *
218
+ * `column` and the join-table keys are `table.column` or bare `column` strings.
219
+ */
220
+ declare const relationshipViaSchema: z.ZodUnion<readonly [z.ZodObject<{
221
+ fkOn: z.ZodEnum<{
222
+ contact: "contact";
223
+ company: "company";
224
+ }>;
225
+ column: z.ZodString;
226
+ }, z.core.$strict>, z.ZodObject<{
227
+ through: z.ZodString;
228
+ localKey: z.ZodString;
229
+ foreignKey: z.ZodString;
230
+ }, z.core.$strict>, z.ZodObject<{
231
+ $raw: z.ZodString;
232
+ }, z.core.$strict>]>;
233
+ type RelationshipVia = z.infer<typeof relationshipViaSchema>;
234
+ declare const relationshipSchema: z.ZodObject<{
235
+ entity: z.ZodString;
236
+ via: z.ZodUnion<readonly [z.ZodObject<{
237
+ fkOn: z.ZodEnum<{
238
+ contact: "contact";
239
+ company: "company";
240
+ }>;
241
+ column: z.ZodString;
242
+ }, z.core.$strict>, z.ZodObject<{
243
+ through: z.ZodString;
244
+ localKey: z.ZodString;
245
+ foreignKey: z.ZodString;
246
+ }, z.core.$strict>, z.ZodObject<{
247
+ $raw: z.ZodString;
248
+ }, z.core.$strict>]>;
249
+ }, z.core.$strict>;
250
+ type RelationshipSpec = z.infer<typeof relationshipSchema>;
251
+ /** A named map of relationships, as stored on an entity / in the mappings row. */
252
+ declare const relationshipsSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
253
+ entity: z.ZodString;
254
+ via: z.ZodUnion<readonly [z.ZodObject<{
255
+ fkOn: z.ZodEnum<{
256
+ contact: "contact";
257
+ company: "company";
258
+ }>;
259
+ column: z.ZodString;
260
+ }, z.core.$strict>, z.ZodObject<{
261
+ through: z.ZodString;
262
+ localKey: z.ZodString;
263
+ foreignKey: z.ZodString;
264
+ }, z.core.$strict>, z.ZodObject<{
265
+ $raw: z.ZodString;
266
+ }, z.core.$strict>]>;
267
+ }, z.core.$strict>>;
268
+ type RelationshipsMap = z.infer<typeof relationshipsSchema>;
269
+ declare const entitySchema: z.ZodObject<{
270
+ concept: z.ZodUnion<readonly [z.ZodEnum<{
271
+ contact: "contact";
272
+ company: "company";
273
+ deal: "deal";
274
+ activity: "activity";
275
+ conversation: "conversation";
276
+ note: "note";
277
+ }>, z.ZodLiteral<"custom">]>;
278
+ source: z.ZodString;
279
+ role: z.ZodOptional<z.ZodString>;
280
+ filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
281
+ $raw: z.ZodString;
282
+ }, z.core.$strict>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodUnion<readonly [z.ZodObject<{
283
+ eq: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
284
+ }, z.core.$strict>, z.ZodObject<{
285
+ ne: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
286
+ }, z.core.$strict>, z.ZodObject<{
287
+ in: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
288
+ }, z.core.$strict>, z.ZodObject<{
289
+ notIn: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
290
+ }, z.core.$strict>, z.ZodObject<{
291
+ isNull: z.ZodLiteral<true>;
292
+ }, z.core.$strict>, z.ZodObject<{
293
+ isNotNull: z.ZodLiteral<true>;
294
+ }, z.core.$strict>]>]>>]>>;
295
+ fields: z.ZodRecord<z.ZodString, z.ZodString>;
296
+ readOnly: z.ZodOptional<z.ZodArray<z.ZodString>>;
297
+ relationships: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
298
+ entity: z.ZodString;
299
+ via: z.ZodUnion<readonly [z.ZodObject<{
300
+ fkOn: z.ZodEnum<{
301
+ contact: "contact";
302
+ company: "company";
303
+ }>;
304
+ column: z.ZodString;
305
+ }, z.core.$strict>, z.ZodObject<{
306
+ through: z.ZodString;
307
+ localKey: z.ZodString;
308
+ foreignKey: z.ZodString;
309
+ }, z.core.$strict>, z.ZodObject<{
310
+ $raw: z.ZodString;
311
+ }, z.core.$strict>]>;
312
+ }, z.core.$strict>>>;
313
+ targetObjectTypeId: z.ZodOptional<z.ZodString>;
314
+ projection: z.ZodOptional<z.ZodObject<{
315
+ version: z.ZodLiteral<1>;
316
+ kind: z.ZodLiteral<"projection">;
317
+ entityKey: z.ZodString;
318
+ baseTable: z.ZodString;
319
+ joins: z.ZodArray<z.ZodObject<{
320
+ key: z.ZodString;
321
+ table: z.ZodString;
322
+ type: z.ZodEnum<{
323
+ inner: "inner";
324
+ left: "left";
325
+ }>;
326
+ on: z.ZodArray<z.ZodObject<{
327
+ left: z.ZodObject<{
328
+ table: z.ZodString;
329
+ column: z.ZodString;
330
+ }, z.core.$strict>;
331
+ op: z.ZodLiteral<"eq">;
332
+ right: z.ZodObject<{
333
+ table: z.ZodString;
334
+ column: z.ZodString;
335
+ }, z.core.$strict>;
336
+ }, z.core.$strict>>;
337
+ }, z.core.$strict>>;
338
+ fieldBindings: z.ZodRecord<z.ZodString, z.ZodObject<{
339
+ from: z.ZodObject<{
340
+ table: z.ZodString;
341
+ column: z.ZodString;
342
+ }, z.core.$strict>;
343
+ }, z.core.$strict>>;
344
+ identity: z.ZodUnion<readonly [z.ZodObject<{
345
+ kind: z.ZodLiteral<"base_pk">;
346
+ column: z.ZodOptional<z.ZodString>;
347
+ }, z.core.$strict>, z.ZodObject<{
348
+ kind: z.ZodLiteral<"column">;
349
+ from: z.ZodObject<{
350
+ table: z.ZodString;
351
+ column: z.ZodString;
352
+ }, z.core.$strict>;
353
+ }, z.core.$strict>, z.ZodObject<{
354
+ kind: z.ZodLiteral<"composite">;
355
+ parts: z.ZodArray<z.ZodObject<{
356
+ table: z.ZodString;
357
+ column: z.ZodString;
358
+ }, z.core.$strict>>;
359
+ }, z.core.$strict>]>;
360
+ }, z.core.$strict>>;
361
+ }, z.core.$strict>;
362
+ type ClivlyEntityConfig = z.infer<typeof entitySchema>;
363
+ declare const entitiesConfigSchema: z.ZodObject<{
364
+ entities: z.ZodRecord<z.ZodString, z.ZodObject<{
365
+ concept: z.ZodUnion<readonly [z.ZodEnum<{
366
+ contact: "contact";
367
+ company: "company";
368
+ deal: "deal";
369
+ activity: "activity";
370
+ conversation: "conversation";
371
+ note: "note";
372
+ }>, z.ZodLiteral<"custom">]>;
373
+ source: z.ZodString;
374
+ role: z.ZodOptional<z.ZodString>;
375
+ filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
376
+ $raw: z.ZodString;
377
+ }, z.core.$strict>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodUnion<readonly [z.ZodObject<{
378
+ eq: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
379
+ }, z.core.$strict>, z.ZodObject<{
380
+ ne: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
381
+ }, z.core.$strict>, z.ZodObject<{
382
+ in: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
383
+ }, z.core.$strict>, z.ZodObject<{
384
+ notIn: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
385
+ }, z.core.$strict>, z.ZodObject<{
386
+ isNull: z.ZodLiteral<true>;
387
+ }, z.core.$strict>, z.ZodObject<{
388
+ isNotNull: z.ZodLiteral<true>;
389
+ }, z.core.$strict>]>]>>]>>;
390
+ fields: z.ZodRecord<z.ZodString, z.ZodString>;
391
+ readOnly: z.ZodOptional<z.ZodArray<z.ZodString>>;
392
+ relationships: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
393
+ entity: z.ZodString;
394
+ via: z.ZodUnion<readonly [z.ZodObject<{
395
+ fkOn: z.ZodEnum<{
396
+ contact: "contact";
397
+ company: "company";
398
+ }>;
399
+ column: z.ZodString;
400
+ }, z.core.$strict>, z.ZodObject<{
401
+ through: z.ZodString;
402
+ localKey: z.ZodString;
403
+ foreignKey: z.ZodString;
404
+ }, z.core.$strict>, z.ZodObject<{
405
+ $raw: z.ZodString;
406
+ }, z.core.$strict>]>;
407
+ }, z.core.$strict>>>;
408
+ targetObjectTypeId: z.ZodOptional<z.ZodString>;
409
+ projection: z.ZodOptional<z.ZodObject<{
410
+ version: z.ZodLiteral<1>;
411
+ kind: z.ZodLiteral<"projection">;
412
+ entityKey: z.ZodString;
413
+ baseTable: z.ZodString;
414
+ joins: z.ZodArray<z.ZodObject<{
415
+ key: z.ZodString;
416
+ table: z.ZodString;
417
+ type: z.ZodEnum<{
418
+ inner: "inner";
419
+ left: "left";
420
+ }>;
421
+ on: z.ZodArray<z.ZodObject<{
422
+ left: z.ZodObject<{
423
+ table: z.ZodString;
424
+ column: z.ZodString;
425
+ }, z.core.$strict>;
426
+ op: z.ZodLiteral<"eq">;
427
+ right: z.ZodObject<{
428
+ table: z.ZodString;
429
+ column: z.ZodString;
430
+ }, z.core.$strict>;
431
+ }, z.core.$strict>>;
432
+ }, z.core.$strict>>;
433
+ fieldBindings: z.ZodRecord<z.ZodString, z.ZodObject<{
434
+ from: z.ZodObject<{
435
+ table: z.ZodString;
436
+ column: z.ZodString;
437
+ }, z.core.$strict>;
438
+ }, z.core.$strict>>;
439
+ identity: z.ZodUnion<readonly [z.ZodObject<{
440
+ kind: z.ZodLiteral<"base_pk">;
441
+ column: z.ZodOptional<z.ZodString>;
442
+ }, z.core.$strict>, z.ZodObject<{
443
+ kind: z.ZodLiteral<"column">;
444
+ from: z.ZodObject<{
445
+ table: z.ZodString;
446
+ column: z.ZodString;
447
+ }, z.core.$strict>;
448
+ }, z.core.$strict>, z.ZodObject<{
449
+ kind: z.ZodLiteral<"composite">;
450
+ parts: z.ZodArray<z.ZodObject<{
451
+ table: z.ZodString;
452
+ column: z.ZodString;
453
+ }, z.core.$strict>>;
454
+ }, z.core.$strict>]>;
455
+ }, z.core.$strict>>;
456
+ }, z.core.$strict>>;
457
+ }, z.core.$strict>;
458
+ type ClivlyEntitiesConfig = z.infer<typeof entitiesConfigSchema>;
459
+ /**
460
+ * What an author may hand to `defineClivlyConfig`. Identical to
461
+ * `ClivlyEntityConfig` except that a projection entity may omit `fields` —
462
+ * it is derived from `projection.fieldBindings`. Without a projection `fields`
463
+ * stays required, so the looser input never weakens the ordinary case.
464
+ */
465
+ type ClivlyEntityConfigInput = (ClivlyEntityConfig & {
466
+ projection?: undefined;
467
+ }) | (Omit<ClivlyEntityConfig, "fields"> & {
468
+ fields?: Record<string, string>;
469
+ projection: ProjectionMapping;
470
+ });
471
+ type ClivlyEntitiesConfigInput = Omit<ClivlyEntitiesConfig, "entities"> & {
472
+ entities: Record<string, ClivlyEntityConfigInput>;
473
+ };
474
+ /** Thrown by `defineClivlyConfig({ strict: true })` on non-canonical field keys. */
475
+ declare class ClivlyConfigError extends Error {
476
+ readonly issues: ConfigValidationError[];
477
+ constructor(issues: ConfigValidationError[]);
478
+ }
479
+ /**
480
+ * Structural helper for `clivly.config.ts`. Gives full type inference on the
481
+ * literal you pass and eagerly parses it, so shape errors surface at config
482
+ * load rather than at sync time.
483
+ *
484
+ * It also catches the silent-data-loss footgun: a non-canonical field key for a
485
+ * materialised concept (e.g. `fullName` instead of `name` on a `contact`) has no
486
+ * destination column, so the store would write an empty value. By default these
487
+ * are reported via `onWarn` (a `console.warn`); pass `{ strict: true }` to throw
488
+ * a `ClivlyConfigError` instead. Does NOT validate against the host schema — that
489
+ * needs the discovered schema; see `validateEntitiesConfig`.
490
+ */
491
+ /**
492
+ * The `fields` entry a projection binding implies, qualified as `ref.column`.
493
+ * Qualified rather than bare: two bindings can pull the same column name from
494
+ * different tables (`cl.full_name` and `adv.full_name`), which a bare column
495
+ * name cannot tell apart.
496
+ */
497
+ declare function projectionFields(projection: ProjectionMapping): Record<string, string>;
498
+ declare function defineClivlyConfig(config: ClivlyEntitiesConfigInput, options?: {
499
+ strict?: boolean;
500
+ onWarn?: (message: string) => void;
501
+ }): ClivlyEntitiesConfig;
502
+ /**
503
+ * Per-column metadata a host reports for a discovered table. Structurally
504
+ * identical to the SDK's `DiscoveredColumn` and to `entity-heuristics.ts`'s
505
+ * (currently separate) `DiscoveredColumnMeta` — a later task converges that
506
+ * module onto this one. Every field is optional: a v1 host reports column
507
+ * names only.
508
+ */
509
+ interface DiscoveredColumnMeta {
510
+ isForeignKey?: boolean;
511
+ isPrimaryKey?: boolean;
512
+ name: string;
513
+ nullable?: boolean;
514
+ references?: {
515
+ table: string;
516
+ column: string;
517
+ };
518
+ type?: string;
519
+ }
520
+ /**
521
+ * A host table the SDK reported for discovery. Structurally identical to the
522
+ * SDK's `DiscoveredTable`; duplicated here to keep `@clivly/core` free of an
523
+ * SDK dependency (core is the base contract SDK builds on).
524
+ *
525
+ * `columns` is the stable v1 contract. `columnsMeta` and `uniqueConstraints`
526
+ * are the enrichment projection mappings require — absent on v1 hosts, which
527
+ * is why projection validation fails closed rather than assuming "no keys".
528
+ */
529
+ interface DiscoveredSchemaTable {
530
+ columns: string[];
531
+ columnsMeta?: DiscoveredColumnMeta[];
532
+ name: string;
533
+ /** Every unique key as DB column names; PKs included. Absent = unknown. */
534
+ uniqueConstraints?: string[][];
535
+ }
536
+ interface ConfigValidationError {
537
+ message: string;
538
+ /** Dotted path into the config, e.g. `entities.owner.fields.email`. */
539
+ path: string;
540
+ }
541
+ interface ConfigValidationResult {
542
+ errors: ConfigValidationError[];
543
+ valid: boolean;
544
+ }
545
+ /**
546
+ * Validate a (structurally valid) config against the host's discovered schema:
547
+ * source tables exist, mapped columns exist, `readOnly` ⊆ `fields`, filter
548
+ * columns exist, and relationships point at real entities/tables/columns.
549
+ *
550
+ * `$raw` filters and `$raw` relationship joins are opaque and skipped. Returns
551
+ * every error found (not just the first) so a mapping UI or CLI can show them
552
+ * all at once.
553
+ */
554
+ declare function validateEntitiesConfig(config: ClivlyEntitiesConfig, schema: DiscoveredSchemaTable[]): ConfigValidationResult;
555
+ //#endregion
556
+ export { ProjectionIdentity as A, filterSchema as C, validateEntitiesConfig as D, relationshipsSchema as E, projectionSchema as F, ProjectionMapping as M, ProjectionRef as N, BASE_REF as O, identityRefs as P, entitiesConfigSchema as S, relationshipSchema as T, MaterializingConcept as _, ClivlyEntitiesConfig as a, RelationshipsMap as b, ClivlyEntityConfigInput as c, CrmConcept as d, DiscoveredColumnMeta as f, MATERIALIZING_CONCEPTS as g, FilterValue as h, ClivlyConfigError as i, ProjectionJoin as j, ProjectionFieldBinding as k, ConfigValidationError as l, FilterExpr as m, CRM_CONCEPTS as n, ClivlyEntitiesConfigInput as o, DiscoveredSchemaTable as p, CUSTOM_CONCEPT as r, ClivlyEntityConfig as s, CANONICAL_FIELDS as t, ConfigValidationResult as u, RelationshipSpec as v, projectionFields as w, defineClivlyConfig as x, RelationshipVia as y };