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
@@ -1,2 +1,2 @@
1
- import { a as compileEntityView, i as ExplainResult, n as CompiledView, o as compileEntityViews, r as DEFAULT_VIEW_PREFIX, s as explainEntitiesConfig, t as CompileOptions } from "./view-compiler-BWz0sGdm.cjs";
1
+ import { a as compileEntityView, i as ExplainResult, n as CompiledView, o as compileEntityViews, r as DEFAULT_VIEW_PREFIX, s as explainEntitiesConfig, t as CompileOptions } from "./view-compiler-Ll9cbIJz.cjs";
2
2
  export { CompileOptions, CompiledView, DEFAULT_VIEW_PREFIX, ExplainResult, compileEntityView, compileEntityViews, explainEntitiesConfig };
@@ -1,2 +1,2 @@
1
- import { a as compileEntityView, i as ExplainResult, n as CompiledView, o as compileEntityViews, r as DEFAULT_VIEW_PREFIX, s as explainEntitiesConfig, t as CompileOptions } from "./view-compiler-Bn_EJJMO.mjs";
1
+ import { a as compileEntityView, i as ExplainResult, n as CompiledView, o as compileEntityViews, r as DEFAULT_VIEW_PREFIX, s as explainEntitiesConfig, t as CompileOptions } from "./view-compiler-Cin0neDO.mjs";
2
2
  export { CompileOptions, CompiledView, DEFAULT_VIEW_PREFIX, ExplainResult, compileEntityView, compileEntityViews, explainEntitiesConfig };
@@ -1,2 +1,2 @@
1
- import { i as explainEntitiesConfig, n as compileEntityView, r as compileEntityViews, t as DEFAULT_VIEW_PREFIX } from "./view-compiler-ChWr_Lml.mjs";
1
+ import { i as explainEntitiesConfig, n as compileEntityView, r as compileEntityViews, t as DEFAULT_VIEW_PREFIX } from "./view-compiler-DlTpOfZi.mjs";
2
2
  export { DEFAULT_VIEW_PREFIX, compileEntityView, compileEntityViews, explainEntitiesConfig };
package/internal.cjs CHANGED
@@ -1,10 +1,13 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_entity_config = require("./entity-config-D87rV-tE.cjs");
2
+ const require_projection = require("./projection-C5244vGa.cjs");
3
+ const require_entity_config = require("./entity-config-CsLl-ftC.cjs");
3
4
  const require_auth_adapter = require("./auth-adapter-CiEXcweZ.cjs");
4
5
  const require_mapping_form = require("./mapping-form-BpfON_ME.cjs");
5
- const require_mappings_config = require("./mappings-config-BsRADNRv.cjs");
6
- const require_view_compiler = require("./view-compiler-BIwvm-o2.cjs");
7
- const require_sync_engine = require("./sync-engine-CzEbpQGv.cjs");
6
+ const require_mappings_config = require("./mappings-config-BSSwdHiq.cjs");
7
+ const require_internal = require("./internal-BARjyN4n.cjs");
8
+ const require_view_compiler = require("./view-compiler-DplczSjF.cjs");
9
+ const require_sync_engine = require("./sync-engine-DEJvKw6E.cjs");
10
+ exports.BASE_REF = require_projection.BASE_REF;
8
11
  exports.CANONICAL_FIELDS = require_entity_config.CANONICAL_FIELDS;
9
12
  exports.CRM_CONCEPTS = require_entity_config.CRM_CONCEPTS;
10
13
  exports.ClivlyConfigError = require_entity_config.ClivlyConfigError;
@@ -13,16 +16,30 @@ exports.MATERIALIZING_CONCEPTS = require_entity_config.MATERIALIZING_CONCEPTS;
13
16
  exports.authCustom = require_auth_adapter.authCustom;
14
17
  exports.buildFilterFromDiscriminator = require_mapping_form.buildFilterFromDiscriminator;
15
18
  exports.buildRelationships = require_mapping_form.buildRelationships;
19
+ exports.columnMetaFor = require_entity_config.columnMetaFor;
16
20
  exports.compileEntityView = require_view_compiler.compileEntityView;
17
21
  exports.compileEntityViews = require_view_compiler.compileEntityViews;
22
+ exports.coversUniqueKey = require_entity_config.coversUniqueKey;
18
23
  exports.defineClivlyConfig = require_entity_config.defineClivlyConfig;
24
+ exports.describeCardinality = require_internal.describeCardinality;
25
+ exports.draftErrors = require_internal.draftErrors;
26
+ exports.draftToProjection = require_internal.draftToProjection;
27
+ exports.emptyProjectionDraft = require_internal.emptyProjectionDraft;
19
28
  exports.entitiesConfigSchema = require_entity_config.entitiesConfigSchema;
20
29
  exports.explainEntitiesConfig = require_view_compiler.explainEntitiesConfig;
30
+ exports.fanOutJoins = require_entity_config.fanOutJoins;
21
31
  exports.filterSchema = require_entity_config.filterSchema;
32
+ exports.hasRichMeta = require_entity_config.hasRichMeta;
33
+ exports.identityRefs = require_projection.identityRefs;
34
+ exports.joinFansOut = require_entity_config.joinFansOut;
22
35
  exports.mappingsToEntitiesConfig = require_mappings_config.mappingsToEntitiesConfig;
36
+ exports.primaryKeyColumns = require_entity_config.primaryKeyColumns;
37
+ exports.projectionSchema = require_projection.projectionSchema;
23
38
  exports.reconcile = require_sync_engine.reconcile;
24
39
  exports.relationshipSchema = require_entity_config.relationshipSchema;
25
40
  exports.relationshipViaSignature = require_mapping_form.relationshipViaSignature;
26
41
  exports.relationshipsSchema = require_entity_config.relationshipsSchema;
27
42
  exports.runSync = require_sync_engine.runSync;
43
+ exports.suggestJoinConditions = require_internal.suggestJoinConditions;
28
44
  exports.validateEntitiesConfig = require_entity_config.validateEntitiesConfig;
45
+ exports.validateProjection = require_entity_config.validateProjection;
package/internal.d.cts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { C as UpdateDealInput, S as UpdateContactInput, _ as Task, a as ContactFilters, b as TaskPriority, c as CreateCompanyInput, d as CreateTaskInput, f as CrmRole, g as RecordSource, h as Note, i as Contact, l as CreateContactInput, m as DealStage, n as ActivityType, o as ContactStatus, p as Deal, r as Company, s as CreateActivityInput, t as Activity, u as CreateDealInput, v as TaskEntityType, w as UpdateTaskInput, x as TaskStatus, y as TaskFilters } from "./types-B1oRXdNP.cjs";
2
2
  import { a as authCustom, i as MembershipResolver, n as ClivlyUser, r as CrmMembership, t as ClivlyAuthAdapter } from "./auth-adapter-DWzgl5Yq.cjs";
3
3
  import { t as CRMAdapter } from "./adapter-C2eRbBfo.cjs";
4
- import { C as validateEntitiesConfig, S as relationshipsSchema, _ as RelationshipsMap, a as ClivlyEntitiesConfig, b as filterSchema, c as ConfigValidationResult, d as FilterExpr, f as FilterValue, g as RelationshipVia, h as RelationshipSpec, i as ClivlyConfigError, l as CrmConcept, m as MaterializingConcept, n as CRM_CONCEPTS, o as ClivlyEntityConfig, p as MATERIALIZING_CONCEPTS, s as ConfigValidationError, t as CANONICAL_FIELDS, u as DiscoveredSchemaTable, v as defineClivlyConfig, x as relationshipSchema, y as entitiesConfigSchema } from "./entity-config-DoUCXtq5.cjs";
5
- import { i as relationshipViaSignature, n as buildFilterFromDiscriminator, r as buildRelationships, t as RelationshipCandidate } from "./mapping-form-lfyEE7EJ.cjs";
6
- import { n as mappingsToEntitiesConfig, t as EntityMappingRow } from "./mappings-config-XmzB4dag.cjs";
7
- import { a as compileEntityView, i as ExplainResult, n as CompiledView, o as compileEntityViews, r as DEFAULT_VIEW_PREFIX, s as explainEntitiesConfig, t as CompileOptions } from "./view-compiler-BWz0sGdm.cjs";
8
- import { c as SyncResult, f as reconcile, l as SyncStore, n as MirrorRecord, o as SourceRow, p as runSync, r as PersistAction, s as SyncAction, t as EntitySyncResult } from "./sync-engine-B7QIbXro.cjs";
9
- export { type Activity, type ActivityType, CANONICAL_FIELDS, type CRMAdapter, CRM_CONCEPTS, type ClivlyAuthAdapter, ClivlyConfigError, type ClivlyEntitiesConfig, type ClivlyEntityConfig, type ClivlyUser, type Company, type CompileOptions, type CompiledView, type ConfigValidationError, type ConfigValidationResult, type Contact, type ContactFilters, type ContactStatus, type CreateActivityInput, type CreateCompanyInput, type CreateContactInput, type CreateDealInput, type CreateTaskInput, type CrmConcept, type CrmMembership, type CrmRole, DEFAULT_VIEW_PREFIX, type Deal, type DealStage, type DiscoveredSchemaTable, type EntityMappingRow, type EntitySyncResult, type ExplainResult, type FilterExpr, type FilterValue, MATERIALIZING_CONCEPTS, type MaterializingConcept, type MembershipResolver, type MirrorRecord, type Note, type PersistAction, type RecordSource, type RelationshipCandidate, type RelationshipSpec, type RelationshipVia, type RelationshipsMap, type SourceRow, type SyncAction, type SyncResult, type SyncStore, type Task, type TaskEntityType, type TaskFilters, type TaskPriority, type TaskStatus, type UpdateContactInput, type UpdateDealInput, type UpdateTaskInput, authCustom, buildFilterFromDiscriminator, buildRelationships, compileEntityView, compileEntityViews, defineClivlyConfig, entitiesConfigSchema, explainEntitiesConfig, filterSchema, mappingsToEntitiesConfig, reconcile, relationshipSchema, relationshipViaSignature, relationshipsSchema, runSync, validateEntitiesConfig };
4
+ import { C as relationshipsSchema, S as relationshipSchema, _ as RelationshipVia, a as ClivlyEntitiesConfig, b as entitiesConfigSchema, c as ConfigValidationResult, d as DiscoveredSchemaTable, f as FilterExpr, g as RelationshipSpec, h as MaterializingConcept, i as ClivlyConfigError, l as CrmConcept, m as MATERIALIZING_CONCEPTS, n as CRM_CONCEPTS, o as ClivlyEntityConfig, p as FilterValue, s as ConfigValidationError, t as CANONICAL_FIELDS, u as DiscoveredColumnMeta, v as RelationshipsMap, w as validateEntitiesConfig, x as filterSchema, y as defineClivlyConfig } from "./entity-config-C4Yf_fPj.cjs";
5
+ import { i as relationshipViaSignature, n as buildFilterFromDiscriminator, r as buildRelationships, t as RelationshipCandidate } from "./mapping-form-43bwOTat.cjs";
6
+ import { a as ProjectionIdentity, c as ProjectionRef, i as ProjectionFieldBinding, l as identityRefs, n as mappingsToEntitiesConfig, o as ProjectionJoin, r as BASE_REF, s as ProjectionMapping, t as EntityMappingRow, u as projectionSchema } from "./mappings-config-xsLMn3I-.cjs";
7
+ import { a as compileEntityView, i as ExplainResult, n as CompiledView, o as compileEntityViews, r as DEFAULT_VIEW_PREFIX, s as explainEntitiesConfig, t as CompileOptions } from "./view-compiler-Ll9cbIJz.cjs";
8
+ import { c as SyncResult, f as reconcile, l as SyncStore, n as MirrorRecord, o as SourceRow, p as runSync, r as PersistAction, s as SyncAction, t as EntitySyncResult } from "./sync-engine-GNqRB8eS.cjs";
9
+ import { a as validateProjection, c as draftErrors, d as suggestJoinConditions, f as fanOutJoins, i as primaryKeyColumns, l as draftToProjection, n as coversUniqueKey, o as ProjectionDraft, p as joinFansOut, r as hasRichMeta, s as describeCardinality, t as columnMetaFor, u as emptyProjectionDraft } from "./internal-B8ydhsKd.cjs";
10
+ export { type Activity, type ActivityType, BASE_REF, CANONICAL_FIELDS, type CRMAdapter, CRM_CONCEPTS, type ClivlyAuthAdapter, ClivlyConfigError, type ClivlyEntitiesConfig, type ClivlyEntityConfig, type ClivlyUser, type Company, type CompileOptions, type CompiledView, type ConfigValidationError, type ConfigValidationResult, type Contact, type ContactFilters, type ContactStatus, type CreateActivityInput, type CreateCompanyInput, type CreateContactInput, type CreateDealInput, type CreateTaskInput, type CrmConcept, type CrmMembership, type CrmRole, DEFAULT_VIEW_PREFIX, type Deal, type DealStage, type DiscoveredColumnMeta, type DiscoveredSchemaTable, type EntityMappingRow, type EntitySyncResult, type ExplainResult, type FilterExpr, type FilterValue, MATERIALIZING_CONCEPTS, type MaterializingConcept, type MembershipResolver, type MirrorRecord, type Note, type PersistAction, type ProjectionDraft, type ProjectionFieldBinding, type ProjectionIdentity, type ProjectionJoin, type ProjectionMapping, type ProjectionRef, type RecordSource, type RelationshipCandidate, type RelationshipSpec, type RelationshipVia, type RelationshipsMap, type SourceRow, type SyncAction, type SyncResult, type SyncStore, type Task, type TaskEntityType, type TaskFilters, type TaskPriority, type TaskStatus, type UpdateContactInput, type UpdateDealInput, type UpdateTaskInput, authCustom, buildFilterFromDiscriminator, buildRelationships, columnMetaFor, compileEntityView, compileEntityViews, coversUniqueKey, defineClivlyConfig, describeCardinality, draftErrors, draftToProjection, emptyProjectionDraft, entitiesConfigSchema, explainEntitiesConfig, fanOutJoins, filterSchema, hasRichMeta, identityRefs, joinFansOut, mappingsToEntitiesConfig, primaryKeyColumns, projectionSchema, reconcile, relationshipSchema, relationshipViaSignature, relationshipsSchema, runSync, suggestJoinConditions, validateEntitiesConfig, validateProjection };
package/internal.d.mts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { C as UpdateDealInput, S as UpdateContactInput, _ as Task, a as ContactFilters, b as TaskPriority, c as CreateCompanyInput, d as CreateTaskInput, f as CrmRole, g as RecordSource, h as Note, i as Contact, l as CreateContactInput, m as DealStage, n as ActivityType, o as ContactStatus, p as Deal, r as Company, s as CreateActivityInput, t as Activity, u as CreateDealInput, v as TaskEntityType, w as UpdateTaskInput, x as TaskStatus, y as TaskFilters } from "./types-B1oRXdNP.mjs";
2
2
  import { a as authCustom, i as MembershipResolver, n as ClivlyUser, r as CrmMembership, t as ClivlyAuthAdapter } from "./auth-adapter-Bjgo8LhN.mjs";
3
3
  import { t as CRMAdapter } from "./adapter-D5LRa-NA.mjs";
4
- import { C as validateEntitiesConfig, S as relationshipsSchema, _ as RelationshipsMap, a as ClivlyEntitiesConfig, b as filterSchema, c as ConfigValidationResult, d as FilterExpr, f as FilterValue, g as RelationshipVia, h as RelationshipSpec, i as ClivlyConfigError, l as CrmConcept, m as MaterializingConcept, n as CRM_CONCEPTS, o as ClivlyEntityConfig, p as MATERIALIZING_CONCEPTS, s as ConfigValidationError, t as CANONICAL_FIELDS, u as DiscoveredSchemaTable, v as defineClivlyConfig, x as relationshipSchema, y as entitiesConfigSchema } from "./entity-config-DoUCXtq5.mjs";
5
- import { i as relationshipViaSignature, n as buildFilterFromDiscriminator, r as buildRelationships, t as RelationshipCandidate } from "./mapping-form-D93lhHEc.mjs";
6
- import { n as mappingsToEntitiesConfig, t as EntityMappingRow } from "./mappings-config-DsUa7-1w.mjs";
7
- import { a as compileEntityView, i as ExplainResult, n as CompiledView, o as compileEntityViews, r as DEFAULT_VIEW_PREFIX, s as explainEntitiesConfig, t as CompileOptions } from "./view-compiler-Bn_EJJMO.mjs";
8
- import { c as SyncResult, f as reconcile, l as SyncStore, n as MirrorRecord, o as SourceRow, p as runSync, r as PersistAction, s as SyncAction, t as EntitySyncResult } from "./sync-engine-DGk_AeHJ.mjs";
9
- export { type Activity, type ActivityType, CANONICAL_FIELDS, type CRMAdapter, CRM_CONCEPTS, type ClivlyAuthAdapter, ClivlyConfigError, type ClivlyEntitiesConfig, type ClivlyEntityConfig, type ClivlyUser, type Company, type CompileOptions, type CompiledView, type ConfigValidationError, type ConfigValidationResult, type Contact, type ContactFilters, type ContactStatus, type CreateActivityInput, type CreateCompanyInput, type CreateContactInput, type CreateDealInput, type CreateTaskInput, type CrmConcept, type CrmMembership, type CrmRole, DEFAULT_VIEW_PREFIX, type Deal, type DealStage, type DiscoveredSchemaTable, type EntityMappingRow, type EntitySyncResult, type ExplainResult, type FilterExpr, type FilterValue, MATERIALIZING_CONCEPTS, type MaterializingConcept, type MembershipResolver, type MirrorRecord, type Note, type PersistAction, type RecordSource, type RelationshipCandidate, type RelationshipSpec, type RelationshipVia, type RelationshipsMap, type SourceRow, type SyncAction, type SyncResult, type SyncStore, type Task, type TaskEntityType, type TaskFilters, type TaskPriority, type TaskStatus, type UpdateContactInput, type UpdateDealInput, type UpdateTaskInput, authCustom, buildFilterFromDiscriminator, buildRelationships, compileEntityView, compileEntityViews, defineClivlyConfig, entitiesConfigSchema, explainEntitiesConfig, filterSchema, mappingsToEntitiesConfig, reconcile, relationshipSchema, relationshipViaSignature, relationshipsSchema, runSync, validateEntitiesConfig };
4
+ import { C as relationshipsSchema, S as relationshipSchema, _ as RelationshipVia, a as ClivlyEntitiesConfig, b as entitiesConfigSchema, c as ConfigValidationResult, d as DiscoveredSchemaTable, f as FilterExpr, g as RelationshipSpec, h as MaterializingConcept, i as ClivlyConfigError, l as CrmConcept, m as MATERIALIZING_CONCEPTS, n as CRM_CONCEPTS, o as ClivlyEntityConfig, p as FilterValue, s as ConfigValidationError, t as CANONICAL_FIELDS, u as DiscoveredColumnMeta, v as RelationshipsMap, w as validateEntitiesConfig, x as filterSchema, y as defineClivlyConfig } from "./entity-config-C4Yf_fPj.mjs";
5
+ import { i as relationshipViaSignature, n as buildFilterFromDiscriminator, r as buildRelationships, t as RelationshipCandidate } from "./mapping-form-DUvWUYCo.mjs";
6
+ import { a as ProjectionIdentity, c as ProjectionRef, i as ProjectionFieldBinding, l as identityRefs, n as mappingsToEntitiesConfig, o as ProjectionJoin, r as BASE_REF, s as ProjectionMapping, t as EntityMappingRow, u as projectionSchema } from "./mappings-config-BpcR8bBo.mjs";
7
+ import { a as compileEntityView, i as ExplainResult, n as CompiledView, o as compileEntityViews, r as DEFAULT_VIEW_PREFIX, s as explainEntitiesConfig, t as CompileOptions } from "./view-compiler-Cin0neDO.mjs";
8
+ import { c as SyncResult, f as reconcile, l as SyncStore, n as MirrorRecord, o as SourceRow, p as runSync, r as PersistAction, s as SyncAction, t as EntitySyncResult } from "./sync-engine-ZsusW-q_.mjs";
9
+ import { a as validateProjection, c as draftErrors, d as suggestJoinConditions, f as fanOutJoins, i as primaryKeyColumns, l as draftToProjection, n as coversUniqueKey, o as ProjectionDraft, p as joinFansOut, r as hasRichMeta, s as describeCardinality, t as columnMetaFor, u as emptyProjectionDraft } from "./internal-MBkNo3bw.mjs";
10
+ export { type Activity, type ActivityType, BASE_REF, CANONICAL_FIELDS, type CRMAdapter, CRM_CONCEPTS, type ClivlyAuthAdapter, ClivlyConfigError, type ClivlyEntitiesConfig, type ClivlyEntityConfig, type ClivlyUser, type Company, type CompileOptions, type CompiledView, type ConfigValidationError, type ConfigValidationResult, type Contact, type ContactFilters, type ContactStatus, type CreateActivityInput, type CreateCompanyInput, type CreateContactInput, type CreateDealInput, type CreateTaskInput, type CrmConcept, type CrmMembership, type CrmRole, DEFAULT_VIEW_PREFIX, type Deal, type DealStage, type DiscoveredColumnMeta, type DiscoveredSchemaTable, type EntityMappingRow, type EntitySyncResult, type ExplainResult, type FilterExpr, type FilterValue, MATERIALIZING_CONCEPTS, type MaterializingConcept, type MembershipResolver, type MirrorRecord, type Note, type PersistAction, type ProjectionDraft, type ProjectionFieldBinding, type ProjectionIdentity, type ProjectionJoin, type ProjectionMapping, type ProjectionRef, type RecordSource, type RelationshipCandidate, type RelationshipSpec, type RelationshipVia, type RelationshipsMap, type SourceRow, type SyncAction, type SyncResult, type SyncStore, type Task, type TaskEntityType, type TaskFilters, type TaskPriority, type TaskStatus, type UpdateContactInput, type UpdateDealInput, type UpdateTaskInput, authCustom, buildFilterFromDiscriminator, buildRelationships, columnMetaFor, compileEntityView, compileEntityViews, coversUniqueKey, defineClivlyConfig, describeCardinality, draftErrors, draftToProjection, emptyProjectionDraft, entitiesConfigSchema, explainEntitiesConfig, fanOutJoins, filterSchema, hasRichMeta, identityRefs, joinFansOut, mappingsToEntitiesConfig, primaryKeyColumns, projectionSchema, reconcile, relationshipSchema, relationshipViaSignature, relationshipsSchema, runSync, suggestJoinConditions, validateEntitiesConfig, validateProjection };
package/internal.mjs CHANGED
@@ -1,7 +1,9 @@
1
- import { a as MATERIALIZING_CONCEPTS, c as filterSchema, d as validateEntitiesConfig, i as ClivlyConfigError, l as relationshipSchema, n as CRM_CONCEPTS, o as defineClivlyConfig, s as entitiesConfigSchema, t as CANONICAL_FIELDS, u as relationshipsSchema } from "./entity-config-va2bkH5o.mjs";
1
+ import { i as projectionSchema, r as identityRefs, t as BASE_REF } from "./projection-D7xmQP4S.mjs";
2
+ import { _ as hasRichMeta, a as MATERIALIZING_CONCEPTS, c as filterSchema, d as validateEntitiesConfig, f as validateProjection, g as coversUniqueKey, h as columnMetaFor, i as ClivlyConfigError, l as relationshipSchema, m as joinFansOut, n as CRM_CONCEPTS, o as defineClivlyConfig, p as fanOutJoins, s as entitiesConfigSchema, t as CANONICAL_FIELDS, u as relationshipsSchema, v as primaryKeyColumns } from "./entity-config-D3LmzgLb.mjs";
2
3
  import { t as authCustom } from "./auth-adapter-gfVDxf3d.mjs";
3
4
  import { n as buildRelationships, r as relationshipViaSignature, t as buildFilterFromDiscriminator } from "./mapping-form-DigkuvFc.mjs";
4
- import { t as mappingsToEntitiesConfig } from "./mappings-config-Dbgxx3Nv.mjs";
5
- import { i as explainEntitiesConfig, n as compileEntityView, r as compileEntityViews, t as DEFAULT_VIEW_PREFIX } from "./view-compiler-ChWr_Lml.mjs";
6
- import { i as runSync, r as reconcile } from "./sync-engine-Do5ru3WF.mjs";
7
- export { CANONICAL_FIELDS, CRM_CONCEPTS, ClivlyConfigError, DEFAULT_VIEW_PREFIX, MATERIALIZING_CONCEPTS, authCustom, buildFilterFromDiscriminator, buildRelationships, compileEntityView, compileEntityViews, defineClivlyConfig, entitiesConfigSchema, explainEntitiesConfig, filterSchema, mappingsToEntitiesConfig, reconcile, relationshipSchema, relationshipViaSignature, relationshipsSchema, runSync, validateEntitiesConfig };
5
+ import { t as mappingsToEntitiesConfig } from "./mappings-config-bJQT_gSa.mjs";
6
+ import { a as suggestJoinConditions, i as emptyProjectionDraft, n as draftErrors, r as draftToProjection, t as describeCardinality } from "./internal-DMySVbM0.mjs";
7
+ import { i as explainEntitiesConfig, n as compileEntityView, r as compileEntityViews, t as DEFAULT_VIEW_PREFIX } from "./view-compiler-DlTpOfZi.mjs";
8
+ import { i as runSync, r as reconcile } from "./sync-engine-Bg6-SznL.mjs";
9
+ export { BASE_REF, CANONICAL_FIELDS, CRM_CONCEPTS, ClivlyConfigError, DEFAULT_VIEW_PREFIX, MATERIALIZING_CONCEPTS, authCustom, buildFilterFromDiscriminator, buildRelationships, columnMetaFor, compileEntityView, compileEntityViews, coversUniqueKey, defineClivlyConfig, describeCardinality, draftErrors, draftToProjection, emptyProjectionDraft, entitiesConfigSchema, explainEntitiesConfig, fanOutJoins, filterSchema, hasRichMeta, identityRefs, joinFansOut, mappingsToEntitiesConfig, primaryKeyColumns, projectionSchema, reconcile, relationshipSchema, relationshipViaSignature, relationshipsSchema, runSync, suggestJoinConditions, validateEntitiesConfig, validateProjection };
@@ -1,4 +1,4 @@
1
- import { _ as RelationshipsMap, d as FilterExpr, g as RelationshipVia } from "./entity-config-DoUCXtq5.mjs";
1
+ import { _ as RelationshipVia, f as FilterExpr, v as RelationshipsMap } from "./entity-config-C4Yf_fPj.cjs";
2
2
  //#region ../core/src/mapping-form.d.ts
3
3
  /**
4
4
  * A relationship the mapping UI can offer or has configured, in the shape the
@@ -1,4 +1,4 @@
1
- import { _ as RelationshipsMap, d as FilterExpr, g as RelationshipVia } from "./entity-config-DoUCXtq5.cjs";
1
+ import { _ as RelationshipVia, f as FilterExpr, v as RelationshipsMap } from "./entity-config-C4Yf_fPj.mjs";
2
2
  //#region ../core/src/mapping-form.d.ts
3
3
  /**
4
4
  * A relationship the mapping UI can offer or has configured, in the shape the
@@ -1,4 +1,4 @@
1
- const require_entity_config = require("./entity-config-D87rV-tE.cjs");
1
+ const require_entity_config = require("./entity-config-CsLl-ftC.cjs");
2
2
  //#region ../core/src/mappings-config.ts
3
3
  const RESERVED_FIELD = "id";
4
4
  /**
@@ -21,7 +21,9 @@ function canonicalFields(concept, fieldMap) {
21
21
  const DEFAULT_ROLE = "primary";
22
22
  const ACTIVE_STATUS = "active";
23
23
  function isEligible(row) {
24
- return (row.status ?? ACTIVE_STATUS) === ACTIVE_STATUS && Object.keys(row.fieldMap ?? {}).length > 0;
24
+ if ((row.status ?? ACTIVE_STATUS) !== ACTIVE_STATUS) return false;
25
+ if (row.projection) return Object.keys(row.projection.fieldBindings ?? {}).length > 0;
26
+ return Object.keys(row.fieldMap ?? {}).length > 0;
25
27
  }
26
28
  /**
27
29
  * Preferred key for a row: the bare source table when it backs a single entity,
@@ -45,13 +47,28 @@ function uniquify(base, used) {
45
47
  used.add(key);
46
48
  return key;
47
49
  }
50
+ /**
51
+ * A projection's `fields` map, derived mechanically from its bindings.
52
+ *
53
+ * `ClivlyEntityConfig.fields` is required and read by existing consumers, so a
54
+ * projection entity must populate it. The values are ref *tokens*
55
+ * (`"base.full_name"`), never host column names — the compiler reads
56
+ * `projection.fieldBindings`, and `validateEntitiesConfig` skips the legacy
57
+ * column check for projection entities precisely because of this.
58
+ */
59
+ function projectionFields(projection) {
60
+ const fields = {};
61
+ for (const [field, binding] of Object.entries(projection.fieldBindings)) fields[field] = `${binding.from.table}.${binding.from.column}`;
62
+ return fields;
63
+ }
48
64
  function buildEntity(row, refIndex) {
49
65
  const entity = {
50
66
  concept: row.targetConcept,
51
- source: row.sourceTable,
67
+ source: row.projection?.baseTable ?? row.sourceTable,
52
68
  role: row.role ?? DEFAULT_ROLE,
53
- fields: canonicalFields(row.targetConcept, row.fieldMap)
69
+ fields: row.projection ? projectionFields(row.projection) : canonicalFields(row.targetConcept, row.fieldMap)
54
70
  };
71
+ if (row.projection) entity.projection = row.projection;
55
72
  if (row.targetConcept === "custom" && row.targetObjectTypeId) entity.targetObjectTypeId = row.targetObjectTypeId;
56
73
  if (row.filter && Object.keys(row.filter).length > 0) entity.filter = row.filter;
57
74
  if (row.relationships && Object.keys(row.relationships).length > 0) {
@@ -76,11 +93,16 @@ function buildEntity(row, refIndex) {
76
93
  function mappingsToEntitiesConfig(rows) {
77
94
  const eligible = rows.filter(isEligible);
78
95
  const tableCounts = /* @__PURE__ */ new Map();
79
- for (const row of eligible) tableCounts.set(row.sourceTable, (tableCounts.get(row.sourceTable) ?? 0) + 1);
96
+ for (const row of eligible) {
97
+ if (row.projection) continue;
98
+ tableCounts.set(row.sourceTable, (tableCounts.get(row.sourceTable) ?? 0) + 1);
99
+ }
80
100
  const used = /* @__PURE__ */ new Set();
81
101
  const tableAnchor = /* @__PURE__ */ new Map();
82
102
  const assigned = [];
83
- for (const row of eligible) {
103
+ const legacyRows = eligible.filter((row) => !row.projection);
104
+ const projectionRows = eligible.filter((row) => row.projection);
105
+ for (const row of legacyRows) {
84
106
  const key = uniquify(preferredKey(row, tableCounts), used);
85
107
  assigned.push({
86
108
  row,
@@ -88,6 +110,10 @@ function mappingsToEntitiesConfig(rows) {
88
110
  });
89
111
  if ((row.role ?? DEFAULT_ROLE) === DEFAULT_ROLE || !tableAnchor.has(row.sourceTable)) tableAnchor.set(row.sourceTable, key);
90
112
  }
113
+ for (const row of projectionRows) assigned.push({
114
+ row,
115
+ key: uniquify(row.projection?.entityKey ?? row.sourceTable, used)
116
+ });
91
117
  const refIndex = /* @__PURE__ */ new Map();
92
118
  for (const { key } of assigned) refIndex.set(key, key);
93
119
  for (const [table, key] of tableAnchor) if (!refIndex.has(table)) refIndex.set(table, key);
@@ -0,0 +1,167 @@
1
+ import { A as ZodRecord, D as ZodLiteral, E as ZodEnum, M as ZodUnion, N as output, O as ZodObject, P as $strict, T as ZodArray, a as ClivlyEntitiesConfig, j as ZodString, k as ZodOptional } from "./entity-config-C4Yf_fPj.mjs";
2
+ //#region ../core/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: ZodObject<{
20
+ table: ZodString;
21
+ column: ZodString;
22
+ }, $strict>;
23
+ type ProjectionRef = output<typeof projectionRefSchema>;
24
+ declare const projectionJoinSchema: ZodObject<{
25
+ key: ZodString;
26
+ table: ZodString;
27
+ type: ZodEnum<{
28
+ inner: "inner";
29
+ left: "left";
30
+ }>;
31
+ on: ZodArray<ZodObject<{
32
+ left: ZodObject<{
33
+ table: ZodString;
34
+ column: ZodString;
35
+ }, $strict>;
36
+ op: ZodLiteral<"eq">;
37
+ right: ZodObject<{
38
+ table: ZodString;
39
+ column: ZodString;
40
+ }, $strict>;
41
+ }, $strict>>;
42
+ }, $strict>;
43
+ type ProjectionJoin = output<typeof projectionJoinSchema>;
44
+ declare const projectionFieldBindingSchema: ZodObject<{
45
+ from: ZodObject<{
46
+ table: ZodString;
47
+ column: ZodString;
48
+ }, $strict>;
49
+ }, $strict>;
50
+ type ProjectionFieldBinding = output<typeof projectionFieldBindingSchema>;
51
+ declare const projectionIdentitySchema: ZodUnion<readonly [ZodObject<{
52
+ kind: ZodLiteral<"base_pk">;
53
+ column: ZodOptional<ZodString>;
54
+ }, $strict>, ZodObject<{
55
+ kind: ZodLiteral<"column">;
56
+ from: ZodObject<{
57
+ table: ZodString;
58
+ column: ZodString;
59
+ }, $strict>;
60
+ }, $strict>, ZodObject<{
61
+ kind: ZodLiteral<"composite">;
62
+ parts: ZodArray<ZodObject<{
63
+ table: ZodString;
64
+ column: ZodString;
65
+ }, $strict>>;
66
+ }, $strict>]>;
67
+ type ProjectionIdentity = output<typeof projectionIdentitySchema>;
68
+ declare const projectionSchema: ZodObject<{
69
+ version: ZodLiteral<1>;
70
+ kind: ZodLiteral<"projection">;
71
+ entityKey: ZodString;
72
+ baseTable: ZodString;
73
+ joins: ZodArray<ZodObject<{
74
+ key: ZodString;
75
+ table: ZodString;
76
+ type: ZodEnum<{
77
+ inner: "inner";
78
+ left: "left";
79
+ }>;
80
+ on: ZodArray<ZodObject<{
81
+ left: ZodObject<{
82
+ table: ZodString;
83
+ column: ZodString;
84
+ }, $strict>;
85
+ op: ZodLiteral<"eq">;
86
+ right: ZodObject<{
87
+ table: ZodString;
88
+ column: ZodString;
89
+ }, $strict>;
90
+ }, $strict>>;
91
+ }, $strict>>;
92
+ fieldBindings: ZodRecord<ZodString, ZodObject<{
93
+ from: ZodObject<{
94
+ table: ZodString;
95
+ column: ZodString;
96
+ }, $strict>;
97
+ }, $strict>>;
98
+ identity: ZodUnion<readonly [ZodObject<{
99
+ kind: ZodLiteral<"base_pk">;
100
+ column: ZodOptional<ZodString>;
101
+ }, $strict>, ZodObject<{
102
+ kind: ZodLiteral<"column">;
103
+ from: ZodObject<{
104
+ table: ZodString;
105
+ column: ZodString;
106
+ }, $strict>;
107
+ }, $strict>, ZodObject<{
108
+ kind: ZodLiteral<"composite">;
109
+ parts: ZodArray<ZodObject<{
110
+ table: ZodString;
111
+ column: ZodString;
112
+ }, $strict>>;
113
+ }, $strict>]>;
114
+ }, $strict>;
115
+ type ProjectionMapping = output<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 ../core/src/mappings-config.d.ts
123
+ /**
124
+ * Mappings → Entity Config bridge.
125
+ *
126
+ * `crm_entity_mappings` rows are the single source of truth for how a host
127
+ * schema maps onto Clivly's CRM concepts. This module compiles those rows into
128
+ * a `ClivlyEntitiesConfig` — the contract the view compiler and sync engine
129
+ * consume — so the persisted mapping and the runtime pipeline never diverge.
130
+ *
131
+ * The row model has no explicit entity-key column (it's keyed by
132
+ * `sourceTable + targetConcept + role`), but the config's `relationships`
133
+ * reference other entities *by key*. This builder therefore derives a stable
134
+ * key per row and resolves each relationship's `entity` reference through the
135
+ * same derivation — so a relationship stored as `entity: "<relatedTable>"`
136
+ * (the shape `mappings.suggest` produces) resolves to the right entity.
137
+ */
138
+ /**
139
+ * A persisted `crm_entity_mappings` row, narrowed to the columns the builder
140
+ * reads. Structurally compatible with the Drizzle row (jsonb columns typed
141
+ * loosely) so the API layer can pass `db.select()` results straight in.
142
+ */
143
+ interface EntityMappingRow {
144
+ fieldMap: Record<string, string>;
145
+ filter?: Record<string, unknown> | null;
146
+ /**
147
+ * Advanced mapping: a base table plus explicit joins. When set, this — not
148
+ * `fieldMap` — is the authored source of truth, and `sourceTable` merely
149
+ * mirrors `projection.baseTable`.
150
+ */
151
+ projection?: ProjectionMapping | null;
152
+ relationships?: Record<string, unknown> | null;
153
+ role?: string | null;
154
+ sourceTable: string;
155
+ status?: string | null;
156
+ targetConcept: string;
157
+ targetObjectTypeId?: string | null;
158
+ }
159
+ /**
160
+ * Compile persisted mapping rows into a `ClivlyEntitiesConfig`. Only `active`
161
+ * rows with at least one mapped field are included; disabled/suggested rows and
162
+ * unmapped rows are skipped. Returns `{ entities: {} }` when nothing is
163
+ * eligible — a no-op the view compiler and sync engine both tolerate.
164
+ */
165
+ declare function mappingsToEntitiesConfig(rows: EntityMappingRow[]): ClivlyEntitiesConfig;
166
+ //#endregion
167
+ export { ProjectionIdentity as a, ProjectionRef as c, ProjectionFieldBinding as i, identityRefs as l, mappingsToEntitiesConfig as n, ProjectionJoin as o, BASE_REF as r, ProjectionMapping as s, EntityMappingRow as t, projectionSchema as u };
@@ -1,4 +1,4 @@
1
- import { t as CANONICAL_FIELDS } from "./entity-config-va2bkH5o.mjs";
1
+ import { t as CANONICAL_FIELDS } from "./entity-config-D3LmzgLb.mjs";
2
2
  //#region ../core/src/mappings-config.ts
3
3
  const RESERVED_FIELD = "id";
4
4
  /**
@@ -21,7 +21,9 @@ function canonicalFields(concept, fieldMap) {
21
21
  const DEFAULT_ROLE = "primary";
22
22
  const ACTIVE_STATUS = "active";
23
23
  function isEligible(row) {
24
- return (row.status ?? ACTIVE_STATUS) === ACTIVE_STATUS && Object.keys(row.fieldMap ?? {}).length > 0;
24
+ if ((row.status ?? ACTIVE_STATUS) !== ACTIVE_STATUS) return false;
25
+ if (row.projection) return Object.keys(row.projection.fieldBindings ?? {}).length > 0;
26
+ return Object.keys(row.fieldMap ?? {}).length > 0;
25
27
  }
26
28
  /**
27
29
  * Preferred key for a row: the bare source table when it backs a single entity,
@@ -45,13 +47,28 @@ function uniquify(base, used) {
45
47
  used.add(key);
46
48
  return key;
47
49
  }
50
+ /**
51
+ * A projection's `fields` map, derived mechanically from its bindings.
52
+ *
53
+ * `ClivlyEntityConfig.fields` is required and read by existing consumers, so a
54
+ * projection entity must populate it. The values are ref *tokens*
55
+ * (`"base.full_name"`), never host column names — the compiler reads
56
+ * `projection.fieldBindings`, and `validateEntitiesConfig` skips the legacy
57
+ * column check for projection entities precisely because of this.
58
+ */
59
+ function projectionFields(projection) {
60
+ const fields = {};
61
+ for (const [field, binding] of Object.entries(projection.fieldBindings)) fields[field] = `${binding.from.table}.${binding.from.column}`;
62
+ return fields;
63
+ }
48
64
  function buildEntity(row, refIndex) {
49
65
  const entity = {
50
66
  concept: row.targetConcept,
51
- source: row.sourceTable,
67
+ source: row.projection?.baseTable ?? row.sourceTable,
52
68
  role: row.role ?? DEFAULT_ROLE,
53
- fields: canonicalFields(row.targetConcept, row.fieldMap)
69
+ fields: row.projection ? projectionFields(row.projection) : canonicalFields(row.targetConcept, row.fieldMap)
54
70
  };
71
+ if (row.projection) entity.projection = row.projection;
55
72
  if (row.targetConcept === "custom" && row.targetObjectTypeId) entity.targetObjectTypeId = row.targetObjectTypeId;
56
73
  if (row.filter && Object.keys(row.filter).length > 0) entity.filter = row.filter;
57
74
  if (row.relationships && Object.keys(row.relationships).length > 0) {
@@ -76,11 +93,16 @@ function buildEntity(row, refIndex) {
76
93
  function mappingsToEntitiesConfig(rows) {
77
94
  const eligible = rows.filter(isEligible);
78
95
  const tableCounts = /* @__PURE__ */ new Map();
79
- for (const row of eligible) tableCounts.set(row.sourceTable, (tableCounts.get(row.sourceTable) ?? 0) + 1);
96
+ for (const row of eligible) {
97
+ if (row.projection) continue;
98
+ tableCounts.set(row.sourceTable, (tableCounts.get(row.sourceTable) ?? 0) + 1);
99
+ }
80
100
  const used = /* @__PURE__ */ new Set();
81
101
  const tableAnchor = /* @__PURE__ */ new Map();
82
102
  const assigned = [];
83
- for (const row of eligible) {
103
+ const legacyRows = eligible.filter((row) => !row.projection);
104
+ const projectionRows = eligible.filter((row) => row.projection);
105
+ for (const row of legacyRows) {
84
106
  const key = uniquify(preferredKey(row, tableCounts), used);
85
107
  assigned.push({
86
108
  row,
@@ -88,6 +110,10 @@ function mappingsToEntitiesConfig(rows) {
88
110
  });
89
111
  if ((row.role ?? DEFAULT_ROLE) === DEFAULT_ROLE || !tableAnchor.has(row.sourceTable)) tableAnchor.set(row.sourceTable, key);
90
112
  }
113
+ for (const row of projectionRows) assigned.push({
114
+ row,
115
+ key: uniquify(row.projection?.entityKey ?? row.sourceTable, used)
116
+ });
91
117
  const refIndex = /* @__PURE__ */ new Map();
92
118
  for (const { key } of assigned) refIndex.set(key, key);
93
119
  for (const [table, key] of tableAnchor) if (!refIndex.has(table)) refIndex.set(table, key);
@@ -0,0 +1,167 @@
1
+ import { A as ZodRecord, D as ZodLiteral, E as ZodEnum, M as ZodUnion, N as output, O as ZodObject, P as $strict, T as ZodArray, a as ClivlyEntitiesConfig, j as ZodString, k as ZodOptional } from "./entity-config-C4Yf_fPj.cjs";
2
+ //#region ../core/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: ZodObject<{
20
+ table: ZodString;
21
+ column: ZodString;
22
+ }, $strict>;
23
+ type ProjectionRef = output<typeof projectionRefSchema>;
24
+ declare const projectionJoinSchema: ZodObject<{
25
+ key: ZodString;
26
+ table: ZodString;
27
+ type: ZodEnum<{
28
+ inner: "inner";
29
+ left: "left";
30
+ }>;
31
+ on: ZodArray<ZodObject<{
32
+ left: ZodObject<{
33
+ table: ZodString;
34
+ column: ZodString;
35
+ }, $strict>;
36
+ op: ZodLiteral<"eq">;
37
+ right: ZodObject<{
38
+ table: ZodString;
39
+ column: ZodString;
40
+ }, $strict>;
41
+ }, $strict>>;
42
+ }, $strict>;
43
+ type ProjectionJoin = output<typeof projectionJoinSchema>;
44
+ declare const projectionFieldBindingSchema: ZodObject<{
45
+ from: ZodObject<{
46
+ table: ZodString;
47
+ column: ZodString;
48
+ }, $strict>;
49
+ }, $strict>;
50
+ type ProjectionFieldBinding = output<typeof projectionFieldBindingSchema>;
51
+ declare const projectionIdentitySchema: ZodUnion<readonly [ZodObject<{
52
+ kind: ZodLiteral<"base_pk">;
53
+ column: ZodOptional<ZodString>;
54
+ }, $strict>, ZodObject<{
55
+ kind: ZodLiteral<"column">;
56
+ from: ZodObject<{
57
+ table: ZodString;
58
+ column: ZodString;
59
+ }, $strict>;
60
+ }, $strict>, ZodObject<{
61
+ kind: ZodLiteral<"composite">;
62
+ parts: ZodArray<ZodObject<{
63
+ table: ZodString;
64
+ column: ZodString;
65
+ }, $strict>>;
66
+ }, $strict>]>;
67
+ type ProjectionIdentity = output<typeof projectionIdentitySchema>;
68
+ declare const projectionSchema: ZodObject<{
69
+ version: ZodLiteral<1>;
70
+ kind: ZodLiteral<"projection">;
71
+ entityKey: ZodString;
72
+ baseTable: ZodString;
73
+ joins: ZodArray<ZodObject<{
74
+ key: ZodString;
75
+ table: ZodString;
76
+ type: ZodEnum<{
77
+ inner: "inner";
78
+ left: "left";
79
+ }>;
80
+ on: ZodArray<ZodObject<{
81
+ left: ZodObject<{
82
+ table: ZodString;
83
+ column: ZodString;
84
+ }, $strict>;
85
+ op: ZodLiteral<"eq">;
86
+ right: ZodObject<{
87
+ table: ZodString;
88
+ column: ZodString;
89
+ }, $strict>;
90
+ }, $strict>>;
91
+ }, $strict>>;
92
+ fieldBindings: ZodRecord<ZodString, ZodObject<{
93
+ from: ZodObject<{
94
+ table: ZodString;
95
+ column: ZodString;
96
+ }, $strict>;
97
+ }, $strict>>;
98
+ identity: ZodUnion<readonly [ZodObject<{
99
+ kind: ZodLiteral<"base_pk">;
100
+ column: ZodOptional<ZodString>;
101
+ }, $strict>, ZodObject<{
102
+ kind: ZodLiteral<"column">;
103
+ from: ZodObject<{
104
+ table: ZodString;
105
+ column: ZodString;
106
+ }, $strict>;
107
+ }, $strict>, ZodObject<{
108
+ kind: ZodLiteral<"composite">;
109
+ parts: ZodArray<ZodObject<{
110
+ table: ZodString;
111
+ column: ZodString;
112
+ }, $strict>>;
113
+ }, $strict>]>;
114
+ }, $strict>;
115
+ type ProjectionMapping = output<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 ../core/src/mappings-config.d.ts
123
+ /**
124
+ * Mappings → Entity Config bridge.
125
+ *
126
+ * `crm_entity_mappings` rows are the single source of truth for how a host
127
+ * schema maps onto Clivly's CRM concepts. This module compiles those rows into
128
+ * a `ClivlyEntitiesConfig` — the contract the view compiler and sync engine
129
+ * consume — so the persisted mapping and the runtime pipeline never diverge.
130
+ *
131
+ * The row model has no explicit entity-key column (it's keyed by
132
+ * `sourceTable + targetConcept + role`), but the config's `relationships`
133
+ * reference other entities *by key*. This builder therefore derives a stable
134
+ * key per row and resolves each relationship's `entity` reference through the
135
+ * same derivation — so a relationship stored as `entity: "<relatedTable>"`
136
+ * (the shape `mappings.suggest` produces) resolves to the right entity.
137
+ */
138
+ /**
139
+ * A persisted `crm_entity_mappings` row, narrowed to the columns the builder
140
+ * reads. Structurally compatible with the Drizzle row (jsonb columns typed
141
+ * loosely) so the API layer can pass `db.select()` results straight in.
142
+ */
143
+ interface EntityMappingRow {
144
+ fieldMap: Record<string, string>;
145
+ filter?: Record<string, unknown> | null;
146
+ /**
147
+ * Advanced mapping: a base table plus explicit joins. When set, this — not
148
+ * `fieldMap` — is the authored source of truth, and `sourceTable` merely
149
+ * mirrors `projection.baseTable`.
150
+ */
151
+ projection?: ProjectionMapping | null;
152
+ relationships?: Record<string, unknown> | null;
153
+ role?: string | null;
154
+ sourceTable: string;
155
+ status?: string | null;
156
+ targetConcept: string;
157
+ targetObjectTypeId?: string | null;
158
+ }
159
+ /**
160
+ * Compile persisted mapping rows into a `ClivlyEntitiesConfig`. Only `active`
161
+ * rows with at least one mapped field are included; disabled/suggested rows and
162
+ * unmapped rows are skipped. Returns `{ entities: {} }` when nothing is
163
+ * eligible — a no-op the view compiler and sync engine both tolerate.
164
+ */
165
+ declare function mappingsToEntitiesConfig(rows: EntityMappingRow[]): ClivlyEntitiesConfig;
166
+ //#endregion
167
+ export { ProjectionIdentity as a, ProjectionRef as c, ProjectionFieldBinding as i, identityRefs as l, mappingsToEntitiesConfig as n, ProjectionJoin as o, BASE_REF as r, ProjectionMapping as s, EntityMappingRow as t, projectionSchema as u };