clivly 0.7.4 → 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 (109) hide show
  1. package/core-drizzle.cjs +3 -1
  2. package/core-drizzle.d.cts +3 -2
  3. package/core-drizzle.d.mts +3 -2
  4. package/core-drizzle.mjs +2 -2
  5. package/core-entity-config.cjs +1 -1
  6. package/core-entity-config.d.cts +2 -2
  7. package/core-entity-config.d.mts +2 -2
  8. package/core-entity-config.mjs +1 -1
  9. package/core-entity-heuristics.d.cts +3 -2
  10. package/core-entity-heuristics.d.mts +3 -2
  11. package/core-mapping-form.d.cts +1 -1
  12. package/core-mapping-form.d.mts +1 -1
  13. package/core-mappings-config.cjs +1 -1
  14. package/core-mappings-config.d.cts +1 -1
  15. package/core-mappings-config.d.mts +1 -1
  16. package/core-mappings-config.mjs +1 -1
  17. package/core-sync-engine.cjs +1 -1
  18. package/core-sync-engine.d.cts +1 -1
  19. package/core-sync-engine.d.mts +1 -1
  20. package/core-sync-engine.mjs +1 -1
  21. package/core-view-compiler.cjs +1 -1
  22. package/core-view-compiler.d.cts +1 -1
  23. package/core-view-compiler.d.mts +1 -1
  24. package/core-view-compiler.mjs +1 -1
  25. package/core.cjs +21 -5
  26. package/core.d.cts +7 -6
  27. package/core.d.mts +7 -6
  28. package/core.mjs +7 -6
  29. package/drizzle-3kvhkwO7.mjs +110 -0
  30. package/drizzle-BhN5M9zt.d.cts +41 -0
  31. package/drizzle-bfjVzYR6.cjs +127 -0
  32. package/drizzle-kBULBAOa.d.mts +41 -0
  33. package/drizzle.cjs +5 -37
  34. package/drizzle.d.cts +3 -3
  35. package/drizzle.d.mts +3 -3
  36. package/drizzle.mjs +5 -38
  37. package/{entity-config-DoUCXtq5.d.cts → entity-config-C4Yf_fPj.d.cts} +120 -1
  38. package/{entity-config-DoUCXtq5.d.mts → entity-config-C4Yf_fPj.d.mts} +120 -1
  39. package/entity-config-CsLl-ftC.cjs +727 -0
  40. package/entity-config-D3LmzgLb.mjs +612 -0
  41. package/index.cjs +28 -2
  42. package/index.d.cts +6 -0
  43. package/index.d.mts +6 -0
  44. package/index.mjs +28 -2
  45. package/internal-B8ydhsKd.d.cts +73 -0
  46. package/internal-BARjyN4n.cjs +97 -0
  47. package/internal-DMySVbM0.mjs +68 -0
  48. package/internal-MBkNo3bw.d.mts +73 -0
  49. package/internal-drizzle.cjs +3 -1
  50. package/internal-drizzle.d.cts +2 -2
  51. package/internal-drizzle.d.mts +2 -2
  52. package/internal-drizzle.mjs +2 -2
  53. package/internal-entity-config.cjs +1 -1
  54. package/internal-entity-config.d.cts +2 -2
  55. package/internal-entity-config.d.mts +2 -2
  56. package/internal-entity-config.mjs +1 -1
  57. package/internal-entity-heuristics.cjs +1 -1
  58. package/internal-entity-heuristics.d.cts +2 -12
  59. package/internal-entity-heuristics.d.mts +2 -12
  60. package/internal-entity-heuristics.mjs +1 -1
  61. package/internal-mapping-form.d.cts +1 -1
  62. package/internal-mapping-form.d.mts +1 -1
  63. package/internal-mappings-config.cjs +1 -1
  64. package/internal-mappings-config.d.cts +1 -1
  65. package/internal-mappings-config.d.mts +1 -1
  66. package/internal-mappings-config.mjs +1 -1
  67. package/internal-sync-engine.cjs +1 -1
  68. package/internal-sync-engine.d.cts +1 -1
  69. package/internal-sync-engine.d.mts +1 -1
  70. package/internal-sync-engine.mjs +1 -1
  71. package/internal-view-compiler.cjs +1 -1
  72. package/internal-view-compiler.d.cts +1 -1
  73. package/internal-view-compiler.d.mts +1 -1
  74. package/internal-view-compiler.mjs +1 -1
  75. package/internal.cjs +21 -4
  76. package/internal.d.cts +7 -6
  77. package/internal.d.mts +7 -6
  78. package/internal.mjs +7 -5
  79. package/{mapping-form-D93lhHEc.d.mts → mapping-form-43bwOTat.d.cts} +1 -1
  80. package/{mapping-form-lfyEE7EJ.d.cts → mapping-form-DUvWUYCo.d.mts} +1 -1
  81. package/{mappings-config-BsRADNRv.cjs → mappings-config-BSSwdHiq.cjs} +32 -6
  82. package/mappings-config-BpcR8bBo.d.mts +167 -0
  83. package/{mappings-config-Dbgxx3Nv.mjs → mappings-config-bJQT_gSa.mjs} +32 -6
  84. package/mappings-config-xsLMn3I-.d.cts +167 -0
  85. package/{namespace-probe-B4WE45TH.d.mts → namespace-probe-BSH_p9TK.d.cts} +10 -1
  86. package/{namespace-probe-DRzOtaRT.d.cts → namespace-probe-Dsp5uNkS.d.mts} +10 -1
  87. package/package.json +1 -1
  88. package/{entity-config-va2bkH5o.mjs → projection-C5244vGa.cjs} +130 -309
  89. package/{entity-config-D87rV-tE.cjs → projection-D7xmQP4S.mjs} +60 -381
  90. package/sdk.cjs +1 -1
  91. package/sdk.d.cts +2 -2
  92. package/sdk.d.mts +2 -2
  93. package/sdk.mjs +1 -1
  94. package/{sync-engine-Do5ru3WF.mjs → sync-engine-Bg6-SznL.mjs} +9 -2
  95. package/{sync-engine-CzEbpQGv.cjs → sync-engine-DEJvKw6E.cjs} +9 -2
  96. package/{sync-engine-DGk_AeHJ.d.mts → sync-engine-GNqRB8eS.d.cts} +2 -2
  97. package/{sync-engine-B7QIbXro.d.cts → sync-engine-ZsusW-q_.d.mts} +2 -2
  98. package/{view-compiler-BWz0sGdm.d.cts → view-compiler-Cin0neDO.d.mts} +1 -1
  99. package/{view-compiler-ChWr_Lml.mjs → view-compiler-DlTpOfZi.mjs} +81 -12
  100. package/{view-compiler-BIwvm-o2.cjs → view-compiler-DplczSjF.cjs} +81 -12
  101. package/{view-compiler-Bn_EJJMO.d.mts → view-compiler-Ll9cbIJz.d.cts} +1 -1
  102. package/vite.d.cts +1 -1
  103. package/vite.d.mts +1 -1
  104. package/drizzle-B89tLo4T.mjs +0 -31
  105. package/drizzle-CFOr9dU9.d.mts +0 -20
  106. package/drizzle-DiReZf6d.cjs +0 -36
  107. package/drizzle-DmeKSqeF.d.cts +0 -20
  108. package/mappings-config-DsUa7-1w.d.mts +0 -41
  109. package/mappings-config-XmzB4dag.d.cts +0 -41
@@ -1,3 +1,58 @@
1
+ import { r as identityRefs, t as BASE_REF } from "./projection-D7xmQP4S.mjs";
2
+ //#region ../core/src/projection-sql.ts
3
+ /**
4
+ * SQL generation for projection-backed entities.
5
+ *
6
+ * Base and joins are aliased by their ref key (`base`, then each join's `key`),
7
+ * which is what allows the same table to be joined twice and keeps generated
8
+ * SQL independent of host table names.
9
+ *
10
+ * Pure string generation — no DB access. Identifiers are escaped so output is
11
+ * deterministic and injection-safe.
12
+ */
13
+ /** Quote a single identifier part, escaping embedded double-quotes. */
14
+ function quoteIdent(name) {
15
+ return `"${name.replace(/"/g, "\"\"")}"`;
16
+ }
17
+ function refSql(ref) {
18
+ return `${quoteIdent(ref.table)}.${quoteIdent(ref.column)}`;
19
+ }
20
+ /**
21
+ * The identity expression, aliased as `id`. Composite identities concatenate
22
+ * their parts with `::`; validation guarantees every part is NOT NULL and
23
+ * non-text, which is what makes the concatenation collision-free.
24
+ */
25
+ function identitySql(projection, basePkColumn) {
26
+ const refs = identityRefs(projection.identity, basePkColumn);
27
+ if (projection.identity.kind === "composite") return `CONCAT_WS('::', ${refs.map((ref) => `${refSql(ref)}::text`).join(", ")}) AS ${quoteIdent("id")}`;
28
+ const [ref] = refs;
29
+ if (!ref) throw new Error("projection identity resolved to no column");
30
+ return `${refSql(ref)} AS ${quoteIdent("id")}`;
31
+ }
32
+ function compileProjectionSelect(projection, basePkColumn) {
33
+ const selectItems = [identitySql(projection, basePkColumn)];
34
+ const columns = ["id"];
35
+ for (const [field, binding] of Object.entries(projection.fieldBindings)) {
36
+ selectItems.push(`${refSql(binding.from)} AS ${quoteIdent(field)}`);
37
+ columns.push(field);
38
+ }
39
+ return {
40
+ columns,
41
+ selectItems
42
+ };
43
+ }
44
+ function compileProjectionJoins(projection) {
45
+ return projection.joins.map((join) => {
46
+ const keyword = join.type === "inner" ? "INNER JOIN" : "LEFT JOIN";
47
+ const on = join.on.map((c) => `${refSql(c.left)} = ${refSql(c.right)}`).join(" AND ");
48
+ return `${keyword} ${quoteIdent(join.table)} AS ${quoteIdent(join.key)} ON ${on}`;
49
+ });
50
+ }
51
+ /** `FROM <baseTable> AS "base"` — the alias every ref resolves against. */
52
+ function compileProjectionFrom(projection) {
53
+ return `FROM ${quoteIdent(projection.baseTable)} AS ${quoteIdent(BASE_REF)}`;
54
+ }
55
+ //#endregion
1
56
  //#region ../core/src/view-compiler.ts
2
57
  /**
3
58
  * View compiler (Phase 2) — turns a validated entity config into read-only
@@ -22,10 +77,6 @@
22
77
  const SOURCE_KEY = "id";
23
78
  const DEFAULT_VIEW_PREFIX = "crm_src_";
24
79
  const DEFAULT_ROLE = "primary";
25
- /** Quote a single identifier part, escaping embedded double-quotes. */
26
- function quoteIdent(name) {
27
- return `"${name.replace(/"/g, "\"\"")}"`;
28
- }
29
80
  /** Emit a SQL literal for a scalar filter value. */
30
81
  function quoteLiteral(value) {
31
82
  if (typeof value === "number") return String(value);
@@ -106,17 +157,24 @@ function compileRelationship(relName, rel, source, related) {
106
157
  refColumn: refCol
107
158
  };
108
159
  }
109
- function compileEntityView(config, entityKey, options = {}) {
110
- const entity = config.entities[entityKey];
111
- if (!entity) throw new Error(`entity "${entityKey}" is not defined`);
112
- const viewName = `${options.viewPrefix ?? "crm_src_"}${entityKey}`;
113
- const src = entity.source;
160
+ /** SELECT items for a legacy single-table entity: source key, then fields. */
161
+ function legacySelect(entity, src) {
114
162
  const selectItems = [`${quoteIdent(src)}.${quoteIdent(SOURCE_KEY)} AS ${quoteIdent("id")}`];
115
163
  const columns = ["id"];
116
164
  for (const [field, column] of Object.entries(entity.fields)) {
117
165
  selectItems.push(`${quoteIdent(src)}.${quoteIdent(column)} AS ${quoteIdent(field)}`);
118
166
  columns.push(field);
119
167
  }
168
+ return {
169
+ columns,
170
+ selectItems
171
+ };
172
+ }
173
+ /**
174
+ * Relationship JOINs for a legacy entity. Appends each relationship's ref
175
+ * column to `columns`/`selectItems` in place, preserving the existing order.
176
+ */
177
+ function legacyJoins(config, entity, columns, selectItems) {
120
178
  const joins = [];
121
179
  for (const [relName, rel] of Object.entries(entity.relationships ?? {})) {
122
180
  const compiled = compileRelationship(relName, rel, entity, config.entities[rel.entity]);
@@ -126,12 +184,23 @@ function compileEntityView(config, entityKey, options = {}) {
126
184
  columns.push(compiled.refColumn);
127
185
  }
128
186
  }
129
- const conditions = compileFilterConditions(src, entity.filter);
130
- if (options.orgScope) conditions.push(`${quoteIdent(src)}.${quoteIdent(options.orgScope.column)} = ${quoteLiteral(options.orgScope.value)}`);
187
+ return joins;
188
+ }
189
+ function compileEntityView(config, entityKey, options = {}) {
190
+ const entity = config.entities[entityKey];
191
+ if (!entity) throw new Error(`entity "${entityKey}" is not defined`);
192
+ const viewName = `${options.viewPrefix ?? "crm_src_"}${entityKey}`;
193
+ const src = entity.source;
194
+ const projection = entity.projection;
195
+ const filterTable = projection ? BASE_REF : src;
196
+ const { selectItems, columns } = projection ? compileProjectionSelect(projection, SOURCE_KEY) : legacySelect(entity, src);
197
+ const joins = projection ? compileProjectionJoins(projection) : legacyJoins(config, entity, columns, selectItems);
198
+ const conditions = compileFilterConditions(filterTable, entity.filter);
199
+ if (options.orgScope) conditions.push(`${quoteIdent(filterTable)}.${quoteIdent(options.orgScope.column)} = ${quoteLiteral(options.orgScope.value)}`);
131
200
  const lines = [
132
201
  options.securityInvoker ?? true ? `CREATE OR REPLACE VIEW ${quoteIdent(viewName)} WITH (security_invoker = true) AS` : `CREATE OR REPLACE VIEW ${quoteIdent(viewName)} AS`,
133
202
  `SELECT ${selectItems.join(", ")}`,
134
- `FROM ${quoteIdent(src)}`,
203
+ projection ? compileProjectionFrom(projection) : `FROM ${quoteIdent(src)}`,
135
204
  ...joins
136
205
  ];
137
206
  if (conditions.length > 0) lines.push(`WHERE ${conditions.join(" AND ")}`);
@@ -1,3 +1,58 @@
1
+ const require_projection = require("./projection-C5244vGa.cjs");
2
+ //#region ../core/src/projection-sql.ts
3
+ /**
4
+ * SQL generation for projection-backed entities.
5
+ *
6
+ * Base and joins are aliased by their ref key (`base`, then each join's `key`),
7
+ * which is what allows the same table to be joined twice and keeps generated
8
+ * SQL independent of host table names.
9
+ *
10
+ * Pure string generation — no DB access. Identifiers are escaped so output is
11
+ * deterministic and injection-safe.
12
+ */
13
+ /** Quote a single identifier part, escaping embedded double-quotes. */
14
+ function quoteIdent(name) {
15
+ return `"${name.replace(/"/g, "\"\"")}"`;
16
+ }
17
+ function refSql(ref) {
18
+ return `${quoteIdent(ref.table)}.${quoteIdent(ref.column)}`;
19
+ }
20
+ /**
21
+ * The identity expression, aliased as `id`. Composite identities concatenate
22
+ * their parts with `::`; validation guarantees every part is NOT NULL and
23
+ * non-text, which is what makes the concatenation collision-free.
24
+ */
25
+ function identitySql(projection, basePkColumn) {
26
+ const refs = require_projection.identityRefs(projection.identity, basePkColumn);
27
+ if (projection.identity.kind === "composite") return `CONCAT_WS('::', ${refs.map((ref) => `${refSql(ref)}::text`).join(", ")}) AS ${quoteIdent("id")}`;
28
+ const [ref] = refs;
29
+ if (!ref) throw new Error("projection identity resolved to no column");
30
+ return `${refSql(ref)} AS ${quoteIdent("id")}`;
31
+ }
32
+ function compileProjectionSelect(projection, basePkColumn) {
33
+ const selectItems = [identitySql(projection, basePkColumn)];
34
+ const columns = ["id"];
35
+ for (const [field, binding] of Object.entries(projection.fieldBindings)) {
36
+ selectItems.push(`${refSql(binding.from)} AS ${quoteIdent(field)}`);
37
+ columns.push(field);
38
+ }
39
+ return {
40
+ columns,
41
+ selectItems
42
+ };
43
+ }
44
+ function compileProjectionJoins(projection) {
45
+ return projection.joins.map((join) => {
46
+ const keyword = join.type === "inner" ? "INNER JOIN" : "LEFT JOIN";
47
+ const on = join.on.map((c) => `${refSql(c.left)} = ${refSql(c.right)}`).join(" AND ");
48
+ return `${keyword} ${quoteIdent(join.table)} AS ${quoteIdent(join.key)} ON ${on}`;
49
+ });
50
+ }
51
+ /** `FROM <baseTable> AS "base"` — the alias every ref resolves against. */
52
+ function compileProjectionFrom(projection) {
53
+ return `FROM ${quoteIdent(projection.baseTable)} AS ${quoteIdent(require_projection.BASE_REF)}`;
54
+ }
55
+ //#endregion
1
56
  //#region ../core/src/view-compiler.ts
2
57
  /**
3
58
  * View compiler (Phase 2) — turns a validated entity config into read-only
@@ -22,10 +77,6 @@
22
77
  const SOURCE_KEY = "id";
23
78
  const DEFAULT_VIEW_PREFIX = "crm_src_";
24
79
  const DEFAULT_ROLE = "primary";
25
- /** Quote a single identifier part, escaping embedded double-quotes. */
26
- function quoteIdent(name) {
27
- return `"${name.replace(/"/g, "\"\"")}"`;
28
- }
29
80
  /** Emit a SQL literal for a scalar filter value. */
30
81
  function quoteLiteral(value) {
31
82
  if (typeof value === "number") return String(value);
@@ -106,17 +157,24 @@ function compileRelationship(relName, rel, source, related) {
106
157
  refColumn: refCol
107
158
  };
108
159
  }
109
- function compileEntityView(config, entityKey, options = {}) {
110
- const entity = config.entities[entityKey];
111
- if (!entity) throw new Error(`entity "${entityKey}" is not defined`);
112
- const viewName = `${options.viewPrefix ?? "crm_src_"}${entityKey}`;
113
- const src = entity.source;
160
+ /** SELECT items for a legacy single-table entity: source key, then fields. */
161
+ function legacySelect(entity, src) {
114
162
  const selectItems = [`${quoteIdent(src)}.${quoteIdent(SOURCE_KEY)} AS ${quoteIdent("id")}`];
115
163
  const columns = ["id"];
116
164
  for (const [field, column] of Object.entries(entity.fields)) {
117
165
  selectItems.push(`${quoteIdent(src)}.${quoteIdent(column)} AS ${quoteIdent(field)}`);
118
166
  columns.push(field);
119
167
  }
168
+ return {
169
+ columns,
170
+ selectItems
171
+ };
172
+ }
173
+ /**
174
+ * Relationship JOINs for a legacy entity. Appends each relationship's ref
175
+ * column to `columns`/`selectItems` in place, preserving the existing order.
176
+ */
177
+ function legacyJoins(config, entity, columns, selectItems) {
120
178
  const joins = [];
121
179
  for (const [relName, rel] of Object.entries(entity.relationships ?? {})) {
122
180
  const compiled = compileRelationship(relName, rel, entity, config.entities[rel.entity]);
@@ -126,12 +184,23 @@ function compileEntityView(config, entityKey, options = {}) {
126
184
  columns.push(compiled.refColumn);
127
185
  }
128
186
  }
129
- const conditions = compileFilterConditions(src, entity.filter);
130
- if (options.orgScope) conditions.push(`${quoteIdent(src)}.${quoteIdent(options.orgScope.column)} = ${quoteLiteral(options.orgScope.value)}`);
187
+ return joins;
188
+ }
189
+ function compileEntityView(config, entityKey, options = {}) {
190
+ const entity = config.entities[entityKey];
191
+ if (!entity) throw new Error(`entity "${entityKey}" is not defined`);
192
+ const viewName = `${options.viewPrefix ?? "crm_src_"}${entityKey}`;
193
+ const src = entity.source;
194
+ const projection = entity.projection;
195
+ const filterTable = projection ? require_projection.BASE_REF : src;
196
+ const { selectItems, columns } = projection ? compileProjectionSelect(projection, SOURCE_KEY) : legacySelect(entity, src);
197
+ const joins = projection ? compileProjectionJoins(projection) : legacyJoins(config, entity, columns, selectItems);
198
+ const conditions = compileFilterConditions(filterTable, entity.filter);
199
+ if (options.orgScope) conditions.push(`${quoteIdent(filterTable)}.${quoteIdent(options.orgScope.column)} = ${quoteLiteral(options.orgScope.value)}`);
131
200
  const lines = [
132
201
  options.securityInvoker ?? true ? `CREATE OR REPLACE VIEW ${quoteIdent(viewName)} WITH (security_invoker = true) AS` : `CREATE OR REPLACE VIEW ${quoteIdent(viewName)} AS`,
133
202
  `SELECT ${selectItems.join(", ")}`,
134
- `FROM ${quoteIdent(src)}`,
203
+ projection ? compileProjectionFrom(projection) : `FROM ${quoteIdent(src)}`,
135
204
  ...joins
136
205
  ];
137
206
  if (conditions.length > 0) lines.push(`WHERE ${conditions.join(" AND ")}`);
@@ -1,4 +1,4 @@
1
- import { a as ClivlyEntitiesConfig } from "./entity-config-DoUCXtq5.mjs";
1
+ import { a as ClivlyEntitiesConfig } from "./entity-config-C4Yf_fPj.cjs";
2
2
  //#region ../core/src/view-compiler.d.ts
3
3
  declare const DEFAULT_VIEW_PREFIX = "crm_src_";
4
4
  interface CompileOptions {
package/vite.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { o as ClivlySDK } from "./namespace-probe-DRzOtaRT.cjs";
1
+ import { o as ClivlySDK } from "./namespace-probe-BSH_p9TK.cjs";
2
2
  import { Plugin } from "vite";
3
3
  //#region ../sdk/src/vite.d.ts
4
4
  interface ClivlyViteOptions {
package/vite.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { o as ClivlySDK } from "./namespace-probe-B4WE45TH.mjs";
1
+ import { o as ClivlySDK } from "./namespace-probe-Dsp5uNkS.mjs";
2
2
  import { Plugin } from "vite";
3
3
  //#region ../sdk/src/vite.d.ts
4
4
  interface ClivlyViteOptions {
@@ -1,31 +0,0 @@
1
- import { Table, getTableColumns, getTableName, is } from "drizzle-orm";
2
- //#region ../core/src/drizzle.ts
3
- /**
4
- * Derive Clivly's discovery shape (table + column names) from a Drizzle schema
5
- * object — the `* as schema` you pass to `drizzle(client, { schema })`. This
6
- * delivers the "reads your schema" promise for Drizzle hosts: no hand-authored
7
- * `DiscoveredTable[]`. Feed the result to the SDK's `schema` option, or diff it
8
- * against your entity config.
9
- *
10
- * Column names are the real database column names (e.g. `full_name`), not the
11
- * Drizzle property keys (`fullName`). Non-table values in the schema object
12
- * (relations, enums, helpers) are ignored.
13
- *
14
- * `drizzle-orm` is an **optional peer dependency** — you only need it installed
15
- * when you import this entry (`@clivly/core/drizzle`); the rest of `@clivly/core`
16
- * stays dependency-free.
17
- */
18
- function discoverFromDrizzle(schema) {
19
- const tables = [];
20
- for (const value of Object.values(schema)) {
21
- if (!is(value, Table)) continue;
22
- const columns = getTableColumns(value);
23
- tables.push({
24
- name: getTableName(value),
25
- columns: Object.values(columns).map((column) => column.name)
26
- });
27
- }
28
- return tables;
29
- }
30
- //#endregion
31
- export { discoverFromDrizzle as t };
@@ -1,20 +0,0 @@
1
- import { u as DiscoveredSchemaTable } from "./entity-config-DoUCXtq5.mjs";
2
- //#region ../core/src/drizzle.d.ts
3
- /**
4
- * Derive Clivly's discovery shape (table + column names) from a Drizzle schema
5
- * object — the `* as schema` you pass to `drizzle(client, { schema })`. This
6
- * delivers the "reads your schema" promise for Drizzle hosts: no hand-authored
7
- * `DiscoveredTable[]`. Feed the result to the SDK's `schema` option, or diff it
8
- * against your entity config.
9
- *
10
- * Column names are the real database column names (e.g. `full_name`), not the
11
- * Drizzle property keys (`fullName`). Non-table values in the schema object
12
- * (relations, enums, helpers) are ignored.
13
- *
14
- * `drizzle-orm` is an **optional peer dependency** — you only need it installed
15
- * when you import this entry (`@clivly/core/drizzle`); the rest of `@clivly/core`
16
- * stays dependency-free.
17
- */
18
- declare function discoverFromDrizzle(schema: Record<string, unknown>): DiscoveredSchemaTable[];
19
- //#endregion
20
- export { discoverFromDrizzle as t };
@@ -1,36 +0,0 @@
1
- let drizzle_orm = require("drizzle-orm");
2
- //#region ../core/src/drizzle.ts
3
- /**
4
- * Derive Clivly's discovery shape (table + column names) from a Drizzle schema
5
- * object — the `* as schema` you pass to `drizzle(client, { schema })`. This
6
- * delivers the "reads your schema" promise for Drizzle hosts: no hand-authored
7
- * `DiscoveredTable[]`. Feed the result to the SDK's `schema` option, or diff it
8
- * against your entity config.
9
- *
10
- * Column names are the real database column names (e.g. `full_name`), not the
11
- * Drizzle property keys (`fullName`). Non-table values in the schema object
12
- * (relations, enums, helpers) are ignored.
13
- *
14
- * `drizzle-orm` is an **optional peer dependency** — you only need it installed
15
- * when you import this entry (`@clivly/core/drizzle`); the rest of `@clivly/core`
16
- * stays dependency-free.
17
- */
18
- function discoverFromDrizzle(schema) {
19
- const tables = [];
20
- for (const value of Object.values(schema)) {
21
- if (!(0, drizzle_orm.is)(value, drizzle_orm.Table)) continue;
22
- const columns = (0, drizzle_orm.getTableColumns)(value);
23
- tables.push({
24
- name: (0, drizzle_orm.getTableName)(value),
25
- columns: Object.values(columns).map((column) => column.name)
26
- });
27
- }
28
- return tables;
29
- }
30
- //#endregion
31
- Object.defineProperty(exports, "discoverFromDrizzle", {
32
- enumerable: true,
33
- get: function() {
34
- return discoverFromDrizzle;
35
- }
36
- });
@@ -1,20 +0,0 @@
1
- import { u as DiscoveredSchemaTable } from "./entity-config-DoUCXtq5.cjs";
2
- //#region ../core/src/drizzle.d.ts
3
- /**
4
- * Derive Clivly's discovery shape (table + column names) from a Drizzle schema
5
- * object — the `* as schema` you pass to `drizzle(client, { schema })`. This
6
- * delivers the "reads your schema" promise for Drizzle hosts: no hand-authored
7
- * `DiscoveredTable[]`. Feed the result to the SDK's `schema` option, or diff it
8
- * against your entity config.
9
- *
10
- * Column names are the real database column names (e.g. `full_name`), not the
11
- * Drizzle property keys (`fullName`). Non-table values in the schema object
12
- * (relations, enums, helpers) are ignored.
13
- *
14
- * `drizzle-orm` is an **optional peer dependency** — you only need it installed
15
- * when you import this entry (`@clivly/core/drizzle`); the rest of `@clivly/core`
16
- * stays dependency-free.
17
- */
18
- declare function discoverFromDrizzle(schema: Record<string, unknown>): DiscoveredSchemaTable[];
19
- //#endregion
20
- export { discoverFromDrizzle as t };
@@ -1,41 +0,0 @@
1
- import { a as ClivlyEntitiesConfig } from "./entity-config-DoUCXtq5.mjs";
2
- //#region ../core/src/mappings-config.d.ts
3
- /**
4
- * Mappings → Entity Config bridge.
5
- *
6
- * `crm_entity_mappings` rows are the single source of truth for how a host
7
- * schema maps onto Clivly's CRM concepts. This module compiles those rows into
8
- * a `ClivlyEntitiesConfig` — the contract the view compiler and sync engine
9
- * consume — so the persisted mapping and the runtime pipeline never diverge.
10
- *
11
- * The row model has no explicit entity-key column (it's keyed by
12
- * `sourceTable + targetConcept + role`), but the config's `relationships`
13
- * reference other entities *by key*. This builder therefore derives a stable
14
- * key per row and resolves each relationship's `entity` reference through the
15
- * same derivation — so a relationship stored as `entity: "<relatedTable>"`
16
- * (the shape `mappings.suggest` produces) resolves to the right entity.
17
- */
18
- /**
19
- * A persisted `crm_entity_mappings` row, narrowed to the columns the builder
20
- * reads. Structurally compatible with the Drizzle row (jsonb columns typed
21
- * loosely) so the API layer can pass `db.select()` results straight in.
22
- */
23
- interface EntityMappingRow {
24
- fieldMap: Record<string, string>;
25
- filter?: Record<string, unknown> | null;
26
- relationships?: Record<string, unknown> | null;
27
- role?: string | null;
28
- sourceTable: string;
29
- status?: string | null;
30
- targetConcept: string;
31
- targetObjectTypeId?: string | null;
32
- }
33
- /**
34
- * Compile persisted mapping rows into a `ClivlyEntitiesConfig`. Only `active`
35
- * rows with at least one mapped field are included; disabled/suggested rows and
36
- * unmapped rows are skipped. Returns `{ entities: {} }` when nothing is
37
- * eligible — a no-op the view compiler and sync engine both tolerate.
38
- */
39
- declare function mappingsToEntitiesConfig(rows: EntityMappingRow[]): ClivlyEntitiesConfig;
40
- //#endregion
41
- export { mappingsToEntitiesConfig as n, EntityMappingRow as t };
@@ -1,41 +0,0 @@
1
- import { a as ClivlyEntitiesConfig } from "./entity-config-DoUCXtq5.cjs";
2
- //#region ../core/src/mappings-config.d.ts
3
- /**
4
- * Mappings → Entity Config bridge.
5
- *
6
- * `crm_entity_mappings` rows are the single source of truth for how a host
7
- * schema maps onto Clivly's CRM concepts. This module compiles those rows into
8
- * a `ClivlyEntitiesConfig` — the contract the view compiler and sync engine
9
- * consume — so the persisted mapping and the runtime pipeline never diverge.
10
- *
11
- * The row model has no explicit entity-key column (it's keyed by
12
- * `sourceTable + targetConcept + role`), but the config's `relationships`
13
- * reference other entities *by key*. This builder therefore derives a stable
14
- * key per row and resolves each relationship's `entity` reference through the
15
- * same derivation — so a relationship stored as `entity: "<relatedTable>"`
16
- * (the shape `mappings.suggest` produces) resolves to the right entity.
17
- */
18
- /**
19
- * A persisted `crm_entity_mappings` row, narrowed to the columns the builder
20
- * reads. Structurally compatible with the Drizzle row (jsonb columns typed
21
- * loosely) so the API layer can pass `db.select()` results straight in.
22
- */
23
- interface EntityMappingRow {
24
- fieldMap: Record<string, string>;
25
- filter?: Record<string, unknown> | null;
26
- relationships?: Record<string, unknown> | null;
27
- role?: string | null;
28
- sourceTable: string;
29
- status?: string | null;
30
- targetConcept: string;
31
- targetObjectTypeId?: string | null;
32
- }
33
- /**
34
- * Compile persisted mapping rows into a `ClivlyEntitiesConfig`. Only `active`
35
- * rows with at least one mapped field are included; disabled/suggested rows and
36
- * unmapped rows are skipped. Returns `{ entities: {} }` when nothing is
37
- * eligible — a no-op the view compiler and sync engine both tolerate.
38
- */
39
- declare function mappingsToEntitiesConfig(rows: EntityMappingRow[]): ClivlyEntitiesConfig;
40
- //#endregion
41
- export { mappingsToEntitiesConfig as n, EntityMappingRow as t };