@clivly/core 0.9.0 → 0.9.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 (42) hide show
  1. package/README.md +91 -3
  2. package/dist/drizzle.d.cts +1 -1
  3. package/dist/drizzle.d.mts +1 -1
  4. package/dist/{entity-config-PoOGzvpN.cjs → entity-config-Bfq3OkCU.cjs} +88 -13
  5. package/dist/{entity-config-Tb5bbKLj.mjs → entity-config-DFJ8L9jm.mjs} +77 -14
  6. package/dist/entity-config-buOIVtMM.d.cts +580 -0
  7. package/dist/entity-config-buOIVtMM.d.mts +580 -0
  8. package/dist/entity-config.cjs +3 -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/integration-state.cjs +98 -26
  21. package/dist/integration-state.d.cts +94 -7
  22. package/dist/integration-state.d.mts +94 -7
  23. package/dist/integration-state.mjs +96 -27
  24. package/dist/mapping-form.d.cts +1 -1
  25. package/dist/mapping-form.d.mts +1 -1
  26. package/dist/mappings-config.cjs +25 -1
  27. package/dist/mappings-config.d.cts +85 -2
  28. package/dist/mappings-config.d.mts +85 -2
  29. package/dist/mappings-config.mjs +25 -2
  30. package/dist/sync-engine.cjs +1 -1
  31. package/dist/sync-engine.d.cts +1 -1
  32. package/dist/sync-engine.d.mts +1 -1
  33. package/dist/sync-engine.mjs +1 -1
  34. package/dist/{view-compiler-BwZ9UgLp.cjs → view-compiler-BpNI8Ttw.cjs} +22 -0
  35. package/dist/{view-compiler-BKrBA_II.mjs → view-compiler-CcqsGxv4.mjs} +17 -1
  36. package/dist/view-compiler.cjs +2 -1
  37. package/dist/view-compiler.d.cts +12 -2
  38. package/dist/view-compiler.d.mts +12 -2
  39. package/dist/view-compiler.mjs +2 -2
  40. package/package.json +1 -1
  41. package/dist/mappings-config-B0W5bVZj.d.mts +0 -168
  42. package/dist/mappings-config-BWo4cRDF.d.cts +0 -168
@@ -0,0 +1,580 @@
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
+ objectType: z.ZodOptional<z.ZodObject<{
315
+ name: z.ZodString;
316
+ pluralName: z.ZodOptional<z.ZodString>;
317
+ iconKey: z.ZodOptional<z.ZodString>;
318
+ }, z.core.$strict>>;
319
+ projection: z.ZodOptional<z.ZodObject<{
320
+ version: z.ZodLiteral<1>;
321
+ kind: z.ZodLiteral<"projection">;
322
+ entityKey: z.ZodString;
323
+ baseTable: z.ZodString;
324
+ joins: z.ZodArray<z.ZodObject<{
325
+ key: z.ZodString;
326
+ table: z.ZodString;
327
+ type: z.ZodEnum<{
328
+ inner: "inner";
329
+ left: "left";
330
+ }>;
331
+ on: z.ZodArray<z.ZodObject<{
332
+ left: z.ZodObject<{
333
+ table: z.ZodString;
334
+ column: z.ZodString;
335
+ }, z.core.$strict>;
336
+ op: z.ZodLiteral<"eq">;
337
+ right: z.ZodObject<{
338
+ table: z.ZodString;
339
+ column: z.ZodString;
340
+ }, z.core.$strict>;
341
+ }, z.core.$strict>>;
342
+ }, z.core.$strict>>;
343
+ fieldBindings: z.ZodRecord<z.ZodString, z.ZodObject<{
344
+ from: z.ZodObject<{
345
+ table: z.ZodString;
346
+ column: z.ZodString;
347
+ }, z.core.$strict>;
348
+ }, z.core.$strict>>;
349
+ identity: z.ZodUnion<readonly [z.ZodObject<{
350
+ kind: z.ZodLiteral<"base_pk">;
351
+ column: z.ZodOptional<z.ZodString>;
352
+ }, z.core.$strict>, z.ZodObject<{
353
+ kind: z.ZodLiteral<"column">;
354
+ from: z.ZodObject<{
355
+ table: z.ZodString;
356
+ column: z.ZodString;
357
+ }, z.core.$strict>;
358
+ }, z.core.$strict>, z.ZodObject<{
359
+ kind: z.ZodLiteral<"composite">;
360
+ parts: z.ZodArray<z.ZodObject<{
361
+ table: z.ZodString;
362
+ column: z.ZodString;
363
+ }, z.core.$strict>>;
364
+ }, z.core.$strict>]>;
365
+ }, z.core.$strict>>;
366
+ }, z.core.$strict>;
367
+ type ClivlyEntityConfig = z.infer<typeof entitySchema>;
368
+ declare const entitiesConfigSchema: z.ZodObject<{
369
+ entities: z.ZodRecord<z.ZodString, z.ZodObject<{
370
+ concept: z.ZodUnion<readonly [z.ZodEnum<{
371
+ contact: "contact";
372
+ company: "company";
373
+ deal: "deal";
374
+ activity: "activity";
375
+ conversation: "conversation";
376
+ note: "note";
377
+ }>, z.ZodLiteral<"custom">]>;
378
+ source: z.ZodString;
379
+ role: z.ZodOptional<z.ZodString>;
380
+ filter: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
381
+ $raw: z.ZodString;
382
+ }, z.core.$strict>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodUnion<readonly [z.ZodObject<{
383
+ eq: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
384
+ }, z.core.$strict>, z.ZodObject<{
385
+ ne: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
386
+ }, z.core.$strict>, z.ZodObject<{
387
+ in: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
388
+ }, z.core.$strict>, z.ZodObject<{
389
+ notIn: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
390
+ }, z.core.$strict>, z.ZodObject<{
391
+ isNull: z.ZodLiteral<true>;
392
+ }, z.core.$strict>, z.ZodObject<{
393
+ isNotNull: z.ZodLiteral<true>;
394
+ }, z.core.$strict>]>]>>]>>;
395
+ fields: z.ZodRecord<z.ZodString, z.ZodString>;
396
+ readOnly: z.ZodOptional<z.ZodArray<z.ZodString>>;
397
+ relationships: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
398
+ entity: z.ZodString;
399
+ via: z.ZodUnion<readonly [z.ZodObject<{
400
+ fkOn: z.ZodEnum<{
401
+ contact: "contact";
402
+ company: "company";
403
+ }>;
404
+ column: z.ZodString;
405
+ }, z.core.$strict>, z.ZodObject<{
406
+ through: z.ZodString;
407
+ localKey: z.ZodString;
408
+ foreignKey: z.ZodString;
409
+ }, z.core.$strict>, z.ZodObject<{
410
+ $raw: z.ZodString;
411
+ }, z.core.$strict>]>;
412
+ }, z.core.$strict>>>;
413
+ targetObjectTypeId: z.ZodOptional<z.ZodString>;
414
+ objectType: z.ZodOptional<z.ZodObject<{
415
+ name: z.ZodString;
416
+ pluralName: z.ZodOptional<z.ZodString>;
417
+ iconKey: z.ZodOptional<z.ZodString>;
418
+ }, z.core.$strict>>;
419
+ projection: z.ZodOptional<z.ZodObject<{
420
+ version: z.ZodLiteral<1>;
421
+ kind: z.ZodLiteral<"projection">;
422
+ entityKey: z.ZodString;
423
+ baseTable: z.ZodString;
424
+ joins: z.ZodArray<z.ZodObject<{
425
+ key: z.ZodString;
426
+ table: z.ZodString;
427
+ type: z.ZodEnum<{
428
+ inner: "inner";
429
+ left: "left";
430
+ }>;
431
+ on: z.ZodArray<z.ZodObject<{
432
+ left: z.ZodObject<{
433
+ table: z.ZodString;
434
+ column: z.ZodString;
435
+ }, z.core.$strict>;
436
+ op: z.ZodLiteral<"eq">;
437
+ right: z.ZodObject<{
438
+ table: z.ZodString;
439
+ column: z.ZodString;
440
+ }, z.core.$strict>;
441
+ }, z.core.$strict>>;
442
+ }, z.core.$strict>>;
443
+ fieldBindings: z.ZodRecord<z.ZodString, z.ZodObject<{
444
+ from: z.ZodObject<{
445
+ table: z.ZodString;
446
+ column: z.ZodString;
447
+ }, z.core.$strict>;
448
+ }, z.core.$strict>>;
449
+ identity: z.ZodUnion<readonly [z.ZodObject<{
450
+ kind: z.ZodLiteral<"base_pk">;
451
+ column: z.ZodOptional<z.ZodString>;
452
+ }, z.core.$strict>, z.ZodObject<{
453
+ kind: z.ZodLiteral<"column">;
454
+ from: z.ZodObject<{
455
+ table: z.ZodString;
456
+ column: z.ZodString;
457
+ }, z.core.$strict>;
458
+ }, z.core.$strict>, z.ZodObject<{
459
+ kind: z.ZodLiteral<"composite">;
460
+ parts: z.ZodArray<z.ZodObject<{
461
+ table: z.ZodString;
462
+ column: z.ZodString;
463
+ }, z.core.$strict>>;
464
+ }, z.core.$strict>]>;
465
+ }, z.core.$strict>>;
466
+ }, z.core.$strict>>;
467
+ }, z.core.$strict>;
468
+ type ClivlyEntitiesConfig = z.infer<typeof entitiesConfigSchema>;
469
+ /**
470
+ * What an author may hand to `defineClivlyConfig`. Identical to
471
+ * `ClivlyEntityConfig` except that a projection entity may omit `fields` —
472
+ * it is derived from `projection.fieldBindings`. Without a projection `fields`
473
+ * stays required, so the looser input never weakens the ordinary case.
474
+ */
475
+ type ClivlyEntityConfigInput = (ClivlyEntityConfig & {
476
+ projection?: undefined;
477
+ }) | (Omit<ClivlyEntityConfig, "fields"> & {
478
+ fields?: Record<string, string>;
479
+ projection: ProjectionMapping;
480
+ });
481
+ type ClivlyEntitiesConfigInput = Omit<ClivlyEntitiesConfig, "entities"> & {
482
+ entities: Record<string, ClivlyEntityConfigInput>;
483
+ };
484
+ /** Thrown by `defineClivlyConfig({ strict: true })` on non-canonical field keys. */
485
+ declare class ClivlyConfigError extends Error {
486
+ readonly issues: ConfigValidationError[];
487
+ constructor(issues: ConfigValidationError[]);
488
+ }
489
+ /**
490
+ * Structural helper for `clivly.config.ts`. Gives full type inference on the
491
+ * literal you pass and eagerly parses it, so shape errors surface at config
492
+ * load rather than at sync time.
493
+ *
494
+ * It also catches the silent-data-loss footgun: a non-canonical field key for a
495
+ * materialised concept (e.g. `fullName` instead of `name` on a `contact`) has no
496
+ * destination column, so the store would write an empty value. By default these
497
+ * are reported via `onWarn` (a `console.warn`); pass `{ strict: true }` to throw
498
+ * a `ClivlyConfigError` instead. Does NOT validate against the host schema — that
499
+ * needs the discovered schema; see `validateEntitiesConfig`.
500
+ */
501
+ /** A custom object the host declares in config, for `push-schema` to ensure. */
502
+ interface CustomObjectDeclaration {
503
+ iconKey?: string;
504
+ name: string;
505
+ pluralName?: string;
506
+ /** Unique per org and immutable — the entity key. */
507
+ slug: string;
508
+ }
509
+ /**
510
+ * The custom objects a config declares, keyed by entity slug. Entities that
511
+ * already carry an explicit `targetObjectTypeId` are omitted: their object type
512
+ * exists server-side and re-declaring it would be a no-op at best.
513
+ */
514
+ declare function customObjectDeclarations(config: ClivlyEntitiesConfig): CustomObjectDeclaration[];
515
+ /**
516
+ * The `fields` entry a projection binding implies, qualified as `ref.column`.
517
+ * Qualified rather than bare: two bindings can pull the same column name from
518
+ * different tables (`cl.full_name` and `adv.full_name`), which a bare column
519
+ * name cannot tell apart.
520
+ */
521
+ declare function projectionFields(projection: ProjectionMapping): Record<string, string>;
522
+ declare function defineClivlyConfig(config: ClivlyEntitiesConfigInput, options?: {
523
+ strict?: boolean;
524
+ onWarn?: (message: string) => void;
525
+ }): ClivlyEntitiesConfig;
526
+ /**
527
+ * Per-column metadata a host reports for a discovered table. Structurally
528
+ * identical to the SDK's `DiscoveredColumn` and to `entity-heuristics.ts`'s
529
+ * (currently separate) `DiscoveredColumnMeta` — a later task converges that
530
+ * module onto this one. Every field is optional: a v1 host reports column
531
+ * names only.
532
+ */
533
+ interface DiscoveredColumnMeta {
534
+ isForeignKey?: boolean;
535
+ isPrimaryKey?: boolean;
536
+ name: string;
537
+ nullable?: boolean;
538
+ references?: {
539
+ table: string;
540
+ column: string;
541
+ };
542
+ type?: string;
543
+ }
544
+ /**
545
+ * A host table the SDK reported for discovery. Structurally identical to the
546
+ * SDK's `DiscoveredTable`; duplicated here to keep `@clivly/core` free of an
547
+ * SDK dependency (core is the base contract SDK builds on).
548
+ *
549
+ * `columns` is the stable v1 contract. `columnsMeta` and `uniqueConstraints`
550
+ * are the enrichment projection mappings require — absent on v1 hosts, which
551
+ * is why projection validation fails closed rather than assuming "no keys".
552
+ */
553
+ interface DiscoveredSchemaTable {
554
+ columns: string[];
555
+ columnsMeta?: DiscoveredColumnMeta[];
556
+ name: string;
557
+ /** Every unique key as DB column names; PKs included. Absent = unknown. */
558
+ uniqueConstraints?: string[][];
559
+ }
560
+ interface ConfigValidationError {
561
+ message: string;
562
+ /** Dotted path into the config, e.g. `entities.owner.fields.email`. */
563
+ path: string;
564
+ }
565
+ interface ConfigValidationResult {
566
+ errors: ConfigValidationError[];
567
+ valid: boolean;
568
+ }
569
+ /**
570
+ * Validate a (structurally valid) config against the host's discovered schema:
571
+ * source tables exist, mapped columns exist, `readOnly` ⊆ `fields`, filter
572
+ * columns exist, and relationships point at real entities/tables/columns.
573
+ *
574
+ * `$raw` filters and `$raw` relationship joins are opaque and skipped. Returns
575
+ * every error found (not just the first) so a mapping UI or CLI can show them
576
+ * all at once.
577
+ */
578
+ declare function validateEntitiesConfig(config: ClivlyEntitiesConfig, schema: DiscoveredSchemaTable[]): ConfigValidationResult;
579
+ //#endregion
580
+ export { BASE_REF as A, defineClivlyConfig as C, relationshipSchema as D, projectionFields as E, ProjectionRef as F, identityRefs as I, projectionSchema as L, ProjectionIdentity as M, ProjectionJoin as N, relationshipsSchema as O, ProjectionMapping as P, customObjectDeclarations as S, filterSchema as T, MATERIALIZING_CONCEPTS as _, ClivlyEntitiesConfig as a, RelationshipVia as b, ClivlyEntityConfigInput as c, CrmConcept as d, CustomObjectDeclaration as f, FilterValue as g, FilterExpr as h, ClivlyConfigError as i, ProjectionFieldBinding as j, validateEntitiesConfig as k, ConfigValidationError as l, DiscoveredSchemaTable as m, CRM_CONCEPTS as n, ClivlyEntitiesConfigInput as o, DiscoveredColumnMeta as p, CUSTOM_CONCEPT as r, ClivlyEntityConfig as s, CANONICAL_FIELDS as t, ConfigValidationResult as u, MaterializingConcept as v, entitiesConfigSchema as w, RelationshipsMap as x, RelationshipSpec as y };
@@ -1,13 +1,15 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_entity_config = require("./entity-config-PoOGzvpN.cjs");
2
+ const require_entity_config = require("./entity-config-Bfq3OkCU.cjs");
3
3
  exports.CANONICAL_FIELDS = require_entity_config.CANONICAL_FIELDS;
4
4
  exports.CRM_CONCEPTS = require_entity_config.CRM_CONCEPTS;
5
5
  exports.CUSTOM_CONCEPT = require_entity_config.CUSTOM_CONCEPT;
6
6
  exports.ClivlyConfigError = require_entity_config.ClivlyConfigError;
7
7
  exports.MATERIALIZING_CONCEPTS = require_entity_config.MATERIALIZING_CONCEPTS;
8
+ exports.customObjectDeclarations = require_entity_config.customObjectDeclarations;
8
9
  exports.defineClivlyConfig = require_entity_config.defineClivlyConfig;
9
10
  exports.entitiesConfigSchema = require_entity_config.entitiesConfigSchema;
10
11
  exports.filterSchema = require_entity_config.filterSchema;
12
+ exports.projectionFields = require_entity_config.projectionFields;
11
13
  exports.relationshipSchema = require_entity_config.relationshipSchema;
12
14
  exports.relationshipsSchema = require_entity_config.relationshipsSchema;
13
15
  exports.validateEntitiesConfig = require_entity_config.validateEntitiesConfig;