clivly 0.8.0 → 0.9.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 (114) hide show
  1. package/README.md +330 -134
  2. package/core-drizzle.cjs +3 -1
  3. package/core-drizzle.d.cts +3 -2
  4. package/core-drizzle.d.mts +3 -2
  5. package/core-drizzle.mjs +2 -2
  6. package/core-entity-config.cjs +1 -1
  7. package/core-entity-config.d.cts +2 -2
  8. package/core-entity-config.d.mts +2 -2
  9. package/core-entity-config.mjs +1 -1
  10. package/core-entity-heuristics.d.cts +3 -2
  11. package/core-entity-heuristics.d.mts +3 -2
  12. package/core-mapping-form.d.cts +1 -1
  13. package/core-mapping-form.d.mts +1 -1
  14. package/core-mappings-config.cjs +1 -1
  15. package/core-mappings-config.d.cts +1 -1
  16. package/core-mappings-config.d.mts +1 -1
  17. package/core-mappings-config.mjs +1 -1
  18. package/core-sync-engine.cjs +1 -1
  19. package/core-sync-engine.d.cts +1 -1
  20. package/core-sync-engine.d.mts +1 -1
  21. package/core-sync-engine.mjs +1 -1
  22. package/core-view-compiler.cjs +1 -1
  23. package/core-view-compiler.d.cts +1 -1
  24. package/core-view-compiler.d.mts +1 -1
  25. package/core-view-compiler.mjs +1 -1
  26. package/core.cjs +21 -5
  27. package/core.d.cts +7 -6
  28. package/core.d.mts +7 -6
  29. package/core.mjs +7 -6
  30. package/drizzle-3kvhkwO7.mjs +110 -0
  31. package/drizzle-BhN5M9zt.d.cts +41 -0
  32. package/drizzle-bfjVzYR6.cjs +127 -0
  33. package/drizzle-kBULBAOa.d.mts +41 -0
  34. package/drizzle.cjs +12 -40
  35. package/drizzle.d.cts +3 -11
  36. package/drizzle.d.mts +3 -11
  37. package/drizzle.mjs +12 -41
  38. package/{entity-config-DoUCXtq5.d.cts → entity-config-C4Yf_fPj.d.cts} +120 -1
  39. package/{entity-config-DoUCXtq5.d.mts → entity-config-C4Yf_fPj.d.mts} +120 -1
  40. package/entity-config-CsLl-ftC.cjs +727 -0
  41. package/entity-config-D3LmzgLb.mjs +612 -0
  42. package/index.cjs +764 -120
  43. package/index.d.cts +12 -0
  44. package/index.d.mts +12 -0
  45. package/index.mjs +765 -121
  46. package/internal-B8ydhsKd.d.cts +73 -0
  47. package/internal-BARjyN4n.cjs +97 -0
  48. package/internal-DMySVbM0.mjs +68 -0
  49. package/internal-MBkNo3bw.d.mts +73 -0
  50. package/internal-drizzle.cjs +3 -1
  51. package/internal-drizzle.d.cts +2 -2
  52. package/internal-drizzle.d.mts +2 -2
  53. package/internal-drizzle.mjs +2 -2
  54. package/internal-entity-config.cjs +1 -1
  55. package/internal-entity-config.d.cts +2 -2
  56. package/internal-entity-config.d.mts +2 -2
  57. package/internal-entity-config.mjs +1 -1
  58. package/internal-entity-heuristics.cjs +28 -8
  59. package/internal-entity-heuristics.d.cts +2 -12
  60. package/internal-entity-heuristics.d.mts +2 -12
  61. package/internal-entity-heuristics.mjs +28 -8
  62. package/internal-mapping-form.d.cts +1 -1
  63. package/internal-mapping-form.d.mts +1 -1
  64. package/internal-mappings-config.cjs +1 -1
  65. package/internal-mappings-config.d.cts +1 -1
  66. package/internal-mappings-config.d.mts +1 -1
  67. package/internal-mappings-config.mjs +1 -1
  68. package/internal-sync-engine.cjs +1 -1
  69. package/internal-sync-engine.d.cts +1 -1
  70. package/internal-sync-engine.d.mts +1 -1
  71. package/internal-sync-engine.mjs +1 -1
  72. package/internal-view-compiler.cjs +1 -1
  73. package/internal-view-compiler.d.cts +1 -1
  74. package/internal-view-compiler.d.mts +1 -1
  75. package/internal-view-compiler.mjs +1 -1
  76. package/internal.cjs +21 -4
  77. package/internal.d.cts +7 -6
  78. package/internal.d.mts +7 -6
  79. package/internal.mjs +7 -5
  80. package/{mapping-form-D93lhHEc.d.mts → mapping-form-43bwOTat.d.cts} +1 -1
  81. package/{mapping-form-lfyEE7EJ.d.cts → mapping-form-DUvWUYCo.d.mts} +1 -1
  82. package/{mappings-config-BsRADNRv.cjs → mappings-config-BSSwdHiq.cjs} +32 -6
  83. package/mappings-config-BpcR8bBo.d.mts +167 -0
  84. package/{mappings-config-Dbgxx3Nv.mjs → mappings-config-bJQT_gSa.mjs} +32 -6
  85. package/mappings-config-xsLMn3I-.d.cts +167 -0
  86. package/namespace-probe-BSH_p9TK.d.cts +381 -0
  87. package/namespace-probe-Dsp5uNkS.d.mts +381 -0
  88. package/package.json +1 -1
  89. package/{entity-config-va2bkH5o.mjs → projection-C5244vGa.cjs} +130 -309
  90. package/{entity-config-D87rV-tE.cjs → projection-D7xmQP4S.mjs} +60 -381
  91. package/{sdk-iqOXeWIp.cjs → sdk-Bj-ZDf4u.cjs} +126 -28
  92. package/{sdk-C6WANW8M.mjs → sdk-BvRD2jAp.mjs} +126 -28
  93. package/sdk.cjs +2 -2
  94. package/sdk.d.cts +36 -1
  95. package/sdk.d.mts +36 -1
  96. package/sdk.mjs +2 -2
  97. package/{sync-engine-Do5ru3WF.mjs → sync-engine-Bg6-SznL.mjs} +9 -2
  98. package/{sync-engine-CzEbpQGv.cjs → sync-engine-DEJvKw6E.cjs} +9 -2
  99. package/{sync-engine-DGk_AeHJ.d.mts → sync-engine-GNqRB8eS.d.cts} +2 -2
  100. package/{sync-engine-B7QIbXro.d.cts → sync-engine-ZsusW-q_.d.mts} +2 -2
  101. package/{view-compiler-BWz0sGdm.d.cts → view-compiler-Cin0neDO.d.mts} +1 -1
  102. package/{view-compiler-ChWr_Lml.mjs → view-compiler-DlTpOfZi.mjs} +81 -12
  103. package/{view-compiler-BIwvm-o2.cjs → view-compiler-DplczSjF.cjs} +81 -12
  104. package/{view-compiler-Bn_EJJMO.d.mts → view-compiler-Ll9cbIJz.d.cts} +1 -1
  105. package/vite.d.cts +1 -1
  106. package/vite.d.mts +1 -1
  107. package/drizzle-B89tLo4T.mjs +0 -31
  108. package/drizzle-CFOr9dU9.d.mts +0 -20
  109. package/drizzle-DiReZf6d.cjs +0 -36
  110. package/drizzle-DmeKSqeF.d.cts +0 -20
  111. package/mappings-config-DsUa7-1w.d.mts +0 -41
  112. package/mappings-config-XmzB4dag.d.cts +0 -41
  113. package/types-CsL0rFYh.d.cts +0 -155
  114. package/types-CsL0rFYh.d.mts +0 -155
@@ -4203,333 +4203,154 @@ function superRefine(fn, params) {
4203
4203
  return /* @__PURE__ */ _superRefine(fn, params);
4204
4204
  }
4205
4205
  //#endregion
4206
- //#region ../core/src/entity-config.ts
4206
+ //#region ../core/src/projection.ts
4207
4207
  /**
4208
- * Entity Config v2 — the declarative contract that turns Clivly's "schema-aware"
4209
- * promise into a real capability.
4208
+ * Projection-backed custom mappings — one custom object derived from a base
4209
+ * table plus explicit joins.
4210
4210
  *
4211
- * A CRM entity is no longer a flat table name. It is a *derived entity*: a
4212
- * filtered slice of a host table (`source` + `filter`), a column allowlist
4213
- * (`fields` + `readOnly`), and declared `relationships` to other entities. The
4214
- * same host table can back several entities (e.g. `users` → owners + members)
4215
- * distinguished by `role`.
4211
+ * A projection is deliberately narrow: equality joins only, direct column
4212
+ * bindings only, no expressions and no aggregation. Everything a user can
4213
+ * express here compiles to a single read-only view whose `id` column is
4214
+ * provably unique per row, which is what lets the sync engine consume it
4215
+ * unchanged.
4216
4216
  *
4217
- * This module is the Phase 1 slice: types, schema, `defineClivlyConfig` (a
4218
- * structural helper) and `validateEntitiesConfig` (semantic validation against
4219
- * the host's discovered schema). It performs NO DB access and generates no SQL —
4220
- * the view compiler (Phase 2) and sync engine (Phase 3) consume this contract.
4217
+ * Refs address tables symbolically: `"base"` for the base table, or a join's
4218
+ * `key`. Raw table names are never accepted in a ref, so a projection can
4219
+ * never reach a table it did not declare.
4221
4220
  */
4222
- /** Canonical CRM concepts a host entity can map onto. */
4223
- const CRM_CONCEPTS = [
4224
- "contact",
4225
- "company",
4226
- "deal",
4227
- "activity",
4228
- "conversation",
4229
- "note"
4230
- ];
4231
- /**
4232
- * The canonical `fields` keys the mirror actually persists, per concept — the
4233
- * crm_* columns the sync store writes. An entity's `fields` map keys must be one
4234
- * of these: a non-canonical key (e.g. `fullName` instead of `name`) validates
4235
- * structurally but has no destination column, so the store silently writes an
4236
- * empty value. `validateEntitiesConfig` flags those.
4237
- *
4238
- * This is the single source of truth — the Drizzle store imports it, so the
4239
- * two can't drift (the drift is what made the silent-data-loss trap possible).
4240
- * Concepts absent here aren't materialized yet, so their field keys are
4241
- * unconstrained.
4242
- */
4243
- const CANONICAL_FIELDS = {
4244
- contact: [
4245
- "name",
4246
- "email",
4247
- "title",
4248
- "status"
4249
- ],
4250
- company: [
4251
- "name",
4252
- "domain",
4253
- "industry",
4254
- "size"
4255
- ],
4256
- deal: [
4257
- "name",
4258
- "value",
4259
- "stage"
4260
- ]
4261
- };
4262
- /**
4263
- * The concepts the mapping→sync pipeline can actually materialize into `crm_*`
4264
- * tables. These are exactly the CANONICAL_FIELDS keys — the Drizzle sync store's
4265
- * `persist()` throws for any other concept, so offering one (in the mapping
4266
- * editor, in suggestions, or via the upsert API) is a broken affordance.
4267
- *
4268
- * The broader CRM_CONCEPTS set still validates structurally, so previously
4269
- * stored rows for not-yet-materialized concepts keep rendering. When a concept
4270
- * gains a sync-store path, add its canonical fields above and it joins this set
4271
- * automatically (guarded by the MATERIALIZING_CONCEPTS drift test).
4272
- */
4273
- const MATERIALIZING_CONCEPTS = [
4274
- "contact",
4275
- "company",
4276
- "deal"
4277
- ];
4278
- /**
4279
- * The org-defined custom-object target. Deliberately NOT a member of
4280
- * CRM_CONCEPTS / CANONICAL_FIELDS / MATERIALIZING_CONCEPTS — a custom object has
4281
- * no fixed canonical columns; its mapping's fieldMap keys ARE its properties.
4282
- * Handled as an explicit branch wherever concepts are switched on, so the
4283
- * canonical-concept invariants (and their drift test) stay intact.
4284
- */
4285
- const CUSTOM_CONCEPT = "custom";
4286
- /**
4287
- * Operator forms for a single column predicate. All predicates on an entity are
4288
- * AND-ed together. `$raw` (see FilterExpr) is the escape hatch for anything the
4289
- * operators can't express.
4290
- */
4291
- const filterOperatorsSchema = union([
4292
- strictObject({ eq: union([
4293
- string(),
4294
- number(),
4295
- boolean()
4296
- ]) }),
4297
- strictObject({ ne: union([
4298
- string(),
4299
- number(),
4300
- boolean()
4301
- ]) }),
4302
- strictObject({ in: array(union([
4303
- string(),
4304
- number(),
4305
- boolean()
4306
- ])).min(1) }),
4307
- strictObject({ notIn: array(union([
4308
- string(),
4309
- number(),
4310
- boolean()
4311
- ])).min(1) }),
4312
- strictObject({ isNull: literal(true) }),
4313
- strictObject({ isNotNull: literal(true) })
4314
- ]);
4315
- const filterValueSchema = union([
4316
- string(),
4317
- number(),
4318
- boolean(),
4319
- filterOperatorsSchema
4320
- ]);
4321
- /** `$raw` is a reserved key; a column literally named `$raw` is not addressable. */
4322
- const filterSchema = union([strictObject({ $raw: string().min(1) }), record(string(), filterValueSchema)]);
4323
- /**
4324
- * How the link between two entities is expressed in the host schema:
4325
- * - `fkOn: "company"` — FK lives on the company table (e.g. organizations.owner_id)
4326
- * - `fkOn: "contact"` — FK lives on the contact table (e.g. users.organization_id)
4327
- * - `through` — a join table sits between them (many-to-many, role often here)
4328
- * - `$raw` — opaque SQL join fragment (escape hatch; not schema-validated)
4329
- *
4330
- * `column` and the join-table keys are `table.column` or bare `column` strings.
4331
- */
4332
- const relationshipViaSchema = union([
4221
+ /** The reserved ref name for the projection's base table. */
4222
+ const BASE_REF = "base";
4223
+ /** Entity keys become view names (`crm_src_<entityKey>`), so keep them slugs. */
4224
+ const PROJECTION_KEY_PATTERN = /^[a-z][a-z0-9_]*$/;
4225
+ const projectionRefSchema = strictObject({
4226
+ table: string().min(1),
4227
+ column: string().min(1)
4228
+ });
4229
+ const projectionJoinConditionSchema = strictObject({
4230
+ left: projectionRefSchema,
4231
+ op: literal("eq"),
4232
+ right: projectionRefSchema
4233
+ });
4234
+ const projectionJoinSchema = strictObject({
4235
+ /** SQL alias and ref target. Unique within the projection. */
4236
+ key: string().regex(PROJECTION_KEY_PATTERN),
4237
+ table: string().min(1),
4238
+ type: _enum(["inner", "left"]),
4239
+ on: array(projectionJoinConditionSchema).min(1)
4240
+ });
4241
+ const projectionFieldBindingSchema = strictObject({ from: projectionRefSchema });
4242
+ const projectionIdentitySchema = union([
4333
4243
  strictObject({
4334
- fkOn: _enum(["company", "contact"]),
4335
- column: string().min(1)
4244
+ kind: literal("base_pk"),
4245
+ /** Defaults to the discovered single-column PK of the base table. */
4246
+ column: string().min(1).optional()
4336
4247
  }),
4337
4248
  strictObject({
4338
- through: string().min(1),
4339
- localKey: string().min(1),
4340
- foreignKey: string().min(1)
4249
+ kind: literal("column"),
4250
+ from: projectionRefSchema
4341
4251
  }),
4342
- strictObject({ $raw: string().min(1) })
4252
+ strictObject({
4253
+ kind: literal("composite"),
4254
+ parts: array(projectionRefSchema).min(2)
4255
+ })
4343
4256
  ]);
4344
- const relationshipSchema = strictObject({
4345
- /** Key of the related entity in the `entities` map. */
4346
- entity: string().min(1),
4347
- via: relationshipViaSchema
4348
- });
4349
- /** A named map of relationships, as stored on an entity / in the mappings row. */
4350
- const relationshipsSchema = record(string(), relationshipSchema);
4351
- const entitySchema = strictObject({
4352
- /** Which CRM concept this entity maps onto — a canonical concept or "custom". */
4353
- concept: union([_enum(CRM_CONCEPTS), literal(CUSTOM_CONCEPT)]),
4354
- /** Host table (or view) this entity is derived from. */
4355
- source: string().min(1),
4356
- /**
4357
- * Distinguishes multiple entities backed by the same table (e.g. "primary"
4358
- * for owners, "secondary" for members). Free text; defaults to "primary".
4359
- */
4360
- role: string().min(1).optional(),
4361
- /** Predicate that narrows `source` into this entity's rows. Omit = whole table. */
4362
- filter: filterSchema.optional(),
4363
- /** clivlyField → sourceColumn. At least one field is required. */
4364
- fields: record(string(), string()).refine((f) => Object.keys(f).length > 0, { message: "at least one field must be mapped" }),
4365
- /**
4366
- * Host-owned identity fields. Sync overwrites them; the CRM UI cannot edit
4367
- * them. Must be a subset of `fields` keys.
4368
- */
4369
- readOnly: array(string()).optional(),
4370
- /** Named relationships to other entities in this config. */
4371
- relationships: record(string(), relationshipSchema).optional(),
4372
- /**
4373
- * For a "custom" entity, the crm_object_types row this materializes into.
4374
- * Required for custom (enforced at the API layer), unused for standard concepts.
4375
- */
4376
- targetObjectTypeId: string().min(1).optional()
4377
- });
4378
- const entitiesConfigSchema = strictObject({ entities: record(string(), entitySchema).refine((e) => Object.keys(e).length > 0, { message: "at least one entity must be defined" }) });
4379
- /** Thrown by `defineClivlyConfig({ strict: true })` on non-canonical field keys. */
4380
- var ClivlyConfigError = class extends Error {
4381
- issues;
4382
- constructor(issues) {
4383
- super(`Clivly config has ${issues.length} non-canonical field mapping(s) that would write empty values at sync time:\n${issues.map((issue) => ` - ${issue.path}: ${issue.message}`).join("\n")}`);
4384
- this.name = "ClivlyConfigError";
4385
- this.issues = issues;
4386
- }
4387
- };
4388
- function nonCanonicalFieldKeys(entity) {
4389
- const canonical = CANONICAL_FIELDS[entity.concept];
4390
- if (!canonical) return [];
4391
- return Object.keys(entity.fields).filter((key) => !canonical.includes(key));
4392
- }
4393
- function nonCanonicalMessage(entity, field) {
4394
- const canonical = CANONICAL_FIELDS[entity.concept] ?? [];
4395
- return `"${field}" is not a canonical ${entity.concept} field (expected one of: ${canonical.join(", ")})`;
4396
- }
4397
- function canonicalFieldIssues(config) {
4398
- const issues = [];
4399
- for (const [key, entity] of Object.entries(config.entities)) for (const field of nonCanonicalFieldKeys(entity)) issues.push({
4400
- path: `entities.${key}.fields.${field}`,
4401
- message: nonCanonicalMessage(entity, field)
4402
- });
4403
- return issues;
4404
- }
4405
- function defaultWarn(message) {
4406
- console.warn(message);
4407
- }
4257
+ const projectionSchema = strictObject({
4258
+ version: literal(1),
4259
+ kind: literal("projection"),
4260
+ entityKey: string().regex(PROJECTION_KEY_PATTERN),
4261
+ baseTable: string().min(1),
4262
+ joins: array(projectionJoinSchema),
4263
+ fieldBindings: record(string(), projectionFieldBindingSchema).refine((b) => Object.keys(b).length > 0, { message: "at least one field must be bound" }),
4264
+ identity: projectionIdentitySchema
4265
+ });
4408
4266
  /**
4409
- * Structural helper for `clivly.config.ts`. Gives full type inference on the
4410
- * literal you pass and eagerly parses it, so shape errors surface at config
4411
- * load rather than at sync time.
4412
- *
4413
- * It also catches the silent-data-loss footgun: a non-canonical field key for a
4414
- * materialised concept (e.g. `fullName` instead of `name` on a `contact`) has no
4415
- * destination column, so the store would write an empty value. By default these
4416
- * are reported via `onWarn` (a `console.warn`); pass `{ strict: true }` to throw
4417
- * a `ClivlyConfigError` instead. Does NOT validate against the host schema — that
4418
- * needs the discovered schema; see `validateEntitiesConfig`.
4267
+ * Every column ref an identity depends on. `basePkColumn` is the base table's
4268
+ * discovered PK, used only when a `base_pk` identity omits an explicit column.
4419
4269
  */
4420
- function defineClivlyConfig(config, options) {
4421
- const parsed = entitiesConfigSchema.parse(config);
4422
- const issues = canonicalFieldIssues(parsed);
4423
- if (issues.length > 0) {
4424
- if (options?.strict) throw new ClivlyConfigError(issues);
4425
- const warn = options?.onWarn ?? defaultWarn;
4426
- for (const issue of issues) warn(`⚠ Clivly config: ${issue.message} (${issue.path}) — this field would write an empty value at sync time. Pass { strict: true } to make this throw.`);
4427
- }
4428
- return parsed;
4429
- }
4430
- /** Split a `table.column` / bare `column` ref into its parts. */
4431
- function parseColumnRef(ref) {
4432
- const dot = ref.indexOf(".");
4433
- if (dot === -1) return { column: ref };
4434
- return {
4435
- table: ref.slice(0, dot),
4436
- column: ref.slice(dot + 1)
4437
- };
4270
+ function identityRefs(identity, basePkColumn) {
4271
+ if (identity.kind === "base_pk") return [{
4272
+ table: BASE_REF,
4273
+ column: identity.column ?? basePkColumn
4274
+ }];
4275
+ if (identity.kind === "column") return [identity.from];
4276
+ return identity.parts;
4438
4277
  }
4439
- /** Shared lookup + error-collection state threaded through the validators. */
4440
- var SchemaValidator = class {
4441
- errors = [];
4442
- columnsByTable = /* @__PURE__ */ new Map();
4443
- constructor(schema) {
4444
- for (const table of schema) this.columnsByTable.set(table.name, new Set(table.columns));
4278
+ //#endregion
4279
+ Object.defineProperty(exports, "BASE_REF", {
4280
+ enumerable: true,
4281
+ get: function() {
4282
+ return BASE_REF;
4445
4283
  }
4446
- tableExists(name) {
4447
- return this.columnsByTable.has(name);
4284
+ });
4285
+ Object.defineProperty(exports, "PROJECTION_KEY_PATTERN", {
4286
+ enumerable: true,
4287
+ get: function() {
4288
+ return PROJECTION_KEY_PATTERN;
4448
4289
  }
4449
- columnExists(table, column) {
4450
- return this.columnsByTable.get(table)?.has(column) ?? false;
4290
+ });
4291
+ Object.defineProperty(exports, "_enum", {
4292
+ enumerable: true,
4293
+ get: function() {
4294
+ return _enum;
4451
4295
  }
4452
- report(path, message) {
4453
- this.errors.push({
4454
- path,
4455
- message
4456
- });
4296
+ });
4297
+ Object.defineProperty(exports, "array", {
4298
+ enumerable: true,
4299
+ get: function() {
4300
+ return array;
4457
4301
  }
4458
- /** Report if `column` is absent from `table`. Returns whether it existed. */
4459
- requireColumn(path, table, column) {
4460
- if (this.columnExists(table, column)) return true;
4461
- this.report(path, `column "${column}" does not exist on "${table}"`);
4462
- return false;
4302
+ });
4303
+ Object.defineProperty(exports, "boolean", {
4304
+ enumerable: true,
4305
+ get: function() {
4306
+ return boolean;
4463
4307
  }
4464
- };
4465
- function validateFields(v, base, entity) {
4466
- for (const [field, column] of Object.entries(entity.fields)) v.requireColumn(`${base}.fields.${field}`, entity.source, column);
4467
- for (const field of nonCanonicalFieldKeys(entity)) v.report(`${base}.fields.${field}`, nonCanonicalMessage(entity, field));
4468
- }
4469
- function validateReadOnly(v, base, entity) {
4470
- for (const field of entity.readOnly ?? []) if (!(field in entity.fields)) v.report(`${base}.readOnly`, `"${field}" is not one of this entity's fields`);
4471
- }
4472
- function validateFilter(v, base, entity) {
4473
- if (!entity.filter || "$raw" in entity.filter) return;
4474
- for (const column of Object.keys(entity.filter)) v.requireColumn(`${base}.filter.${column}`, entity.source, column);
4475
- }
4476
- function validateFkVia(v, relBase, via, entity, related) {
4477
- const { table, column } = parseColumnRef(via.column);
4478
- const fkTable = table ?? (via.fkOn === "contact" ? entity.source : related?.source);
4479
- const path = `${relBase}.via.column`;
4480
- if (!fkTable) {
4481
- v.report(path, `cannot resolve table for FK column "${via.column}"`);
4482
- return;
4308
+ });
4309
+ Object.defineProperty(exports, "identityRefs", {
4310
+ enumerable: true,
4311
+ get: function() {
4312
+ return identityRefs;
4483
4313
  }
4484
- if (!v.tableExists(fkTable)) {
4485
- v.report(path, `table "${fkTable}" is not in the discovered schema`);
4486
- return;
4314
+ });
4315
+ Object.defineProperty(exports, "literal", {
4316
+ enumerable: true,
4317
+ get: function() {
4318
+ return literal;
4487
4319
  }
4488
- v.requireColumn(path, fkTable, column);
4489
- }
4490
- function validateThroughVia(v, relBase, via) {
4491
- if (!v.tableExists(via.through)) {
4492
- v.report(`${relBase}.via.through`, `join table "${via.through}" is not in the discovered schema`);
4493
- return;
4320
+ });
4321
+ Object.defineProperty(exports, "number", {
4322
+ enumerable: true,
4323
+ get: function() {
4324
+ return number;
4494
4325
  }
4495
- v.requireColumn(`${relBase}.via.localKey`, via.through, via.localKey);
4496
- v.requireColumn(`${relBase}.via.foreignKey`, via.through, via.foreignKey);
4497
- }
4498
- function validateRelationship(v, base, config, entity, relName, rel) {
4499
- const relBase = `${base}.relationships.${relName}`;
4500
- const related = config.entities[rel.entity];
4501
- if (!related) v.report(`${relBase}.entity`, `"${rel.entity}" is not a defined entity`);
4502
- const { via } = rel;
4503
- if ("fkOn" in via) validateFkVia(v, relBase, via, entity, related);
4504
- else if ("through" in via) validateThroughVia(v, relBase, via);
4505
- }
4506
- function validateEntity(v, config, key, entity) {
4507
- const base = `entities.${key}`;
4508
- if (!v.tableExists(entity.source)) {
4509
- v.report(`${base}.source`, `table "${entity.source}" is not in the discovered schema`);
4510
- return;
4326
+ });
4327
+ Object.defineProperty(exports, "projectionSchema", {
4328
+ enumerable: true,
4329
+ get: function() {
4330
+ return projectionSchema;
4511
4331
  }
4512
- validateFields(v, base, entity);
4513
- validateReadOnly(v, base, entity);
4514
- validateFilter(v, base, entity);
4515
- for (const [relName, rel] of Object.entries(entity.relationships ?? {})) validateRelationship(v, base, config, entity, relName, rel);
4516
- }
4517
- /**
4518
- * Validate a (structurally valid) config against the host's discovered schema:
4519
- * source tables exist, mapped columns exist, `readOnly` ⊆ `fields`, filter
4520
- * columns exist, and relationships point at real entities/tables/columns.
4521
- *
4522
- * `$raw` filters and `$raw` relationship joins are opaque and skipped. Returns
4523
- * every error found (not just the first) so a mapping UI or CLI can show them
4524
- * all at once.
4525
- */
4526
- function validateEntitiesConfig(config, schema) {
4527
- const validator = new SchemaValidator(schema);
4528
- for (const [key, entity] of Object.entries(config.entities)) validateEntity(validator, config, key, entity);
4529
- return {
4530
- valid: validator.errors.length === 0,
4531
- errors: validator.errors
4532
- };
4533
- }
4534
- //#endregion
4535
- export { MATERIALIZING_CONCEPTS as a, filterSchema as c, validateEntitiesConfig as d, ClivlyConfigError as i, relationshipSchema as l, CRM_CONCEPTS as n, defineClivlyConfig as o, CUSTOM_CONCEPT as r, entitiesConfigSchema as s, CANONICAL_FIELDS as t, relationshipsSchema as u };
4332
+ });
4333
+ Object.defineProperty(exports, "record", {
4334
+ enumerable: true,
4335
+ get: function() {
4336
+ return record;
4337
+ }
4338
+ });
4339
+ Object.defineProperty(exports, "strictObject", {
4340
+ enumerable: true,
4341
+ get: function() {
4342
+ return strictObject;
4343
+ }
4344
+ });
4345
+ Object.defineProperty(exports, "string", {
4346
+ enumerable: true,
4347
+ get: function() {
4348
+ return string;
4349
+ }
4350
+ });
4351
+ Object.defineProperty(exports, "union", {
4352
+ enumerable: true,
4353
+ get: function() {
4354
+ return union;
4355
+ }
4356
+ });