clivly 0.9.5 → 0.9.6

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 (62) hide show
  1. package/README.md +7 -0
  2. package/core-entity-config.cjs +1 -1
  3. package/core-entity-config.mjs +1 -1
  4. package/core-mappings-config.cjs +1 -1
  5. package/core-mappings-config.mjs +1 -1
  6. package/core-sync-engine.cjs +1 -1
  7. package/core-sync-engine.mjs +1 -1
  8. package/core-view-compiler.cjs +1 -1
  9. package/core-view-compiler.mjs +1 -1
  10. package/core.cjs +13 -7
  11. package/core.d.cts +2 -2
  12. package/core.d.mts +2 -2
  13. package/core.mjs +8 -8
  14. package/drizzle.cjs +19 -2
  15. package/drizzle.d.cts +1 -1
  16. package/drizzle.d.mts +1 -1
  17. package/drizzle.mjs +19 -2
  18. package/{entity-config-B74SPOUZ.mjs → entity-config-CusbTOJ1.mjs} +1 -1
  19. package/{entity-config-7sGCk_nw.cjs → entity-config-DE30_RpU.cjs} +1 -1
  20. package/index.cjs +9 -8
  21. package/index.mjs +9 -8
  22. package/internal-BQ47iN6f.cjs +259 -0
  23. package/internal-ChufvXE6.mjs +212 -0
  24. package/{internal-o2M7FGlR.d.mts → internal-CvlFk3KC.d.mts} +82 -2
  25. package/{internal-wCXSELDN.d.cts → internal-DGUOLQAq.d.cts} +82 -2
  26. package/internal-entity-config.cjs +1 -1
  27. package/internal-entity-config.mjs +1 -1
  28. package/internal-entity-heuristics.cjs +1 -1
  29. package/internal-entity-heuristics.mjs +1 -1
  30. package/internal-mappings-config.cjs +1 -1
  31. package/internal-mappings-config.mjs +1 -1
  32. package/internal-sync-engine.cjs +1 -1
  33. package/internal-sync-engine.mjs +1 -1
  34. package/internal-view-compiler.cjs +1 -1
  35. package/internal-view-compiler.mjs +1 -1
  36. package/internal.cjs +13 -7
  37. package/internal.d.cts +2 -2
  38. package/internal.d.mts +2 -2
  39. package/internal.mjs +8 -8
  40. package/{mappings-config-DQS_s4dg.mjs → mappings-config-7qQ47p9K.mjs} +1 -1
  41. package/{mappings-config-CLyEg0sf.cjs → mappings-config-CjCmT-aU.cjs} +1 -1
  42. package/{namespace-probe-Cn7voAd0.d.mts → namespace-probe-Ckn9yJ6F.d.mts} +45 -2
  43. package/{namespace-probe-BoGI18dQ.d.cts → namespace-probe-DaTJINS-.d.cts} +45 -2
  44. package/package.json +1 -1
  45. package/{projection-Dz6_i1-w.cjs → projection-DEwL-D8R.cjs} +6 -0
  46. package/{projection-CSGJbZlZ.mjs → projection-hnPSgH6G.mjs} +1 -1
  47. package/{projection-sql-BgnfiGqF.mjs → projection-sql-9zzTVGvf.mjs} +34 -2
  48. package/{projection-sql-Cl1qIn8m.cjs → projection-sql-iHy-Cx6V.cjs} +45 -1
  49. package/{sdk-DYBDR939.mjs → sdk-Dkq6ELkf.mjs} +32 -8
  50. package/{sdk-CM1UO-I7.cjs → sdk-w8Kv_XnW.cjs} +32 -8
  51. package/sdk.cjs +2 -2
  52. package/sdk.d.cts +2 -2
  53. package/sdk.d.mts +2 -2
  54. package/sdk.mjs +2 -2
  55. package/{sync-engine-C4A5jgA4.cjs → sync-engine-BLgwLpR6.cjs} +1 -1
  56. package/{sync-engine-Dt5QQSKO.mjs → sync-engine-B_IzoUSx.mjs} +1 -1
  57. package/{view-compiler-B5nDal14.cjs → view-compiler-BHI5E4QI.cjs} +2 -2
  58. package/{view-compiler-CSYwEWf5.mjs → view-compiler-D_6gfXFr.mjs} +2 -2
  59. package/vite.d.cts +1 -1
  60. package/vite.d.mts +1 -1
  61. package/internal-CykXpEGk.mjs +0 -68
  62. package/internal-DqduZU3l.cjs +0 -97
@@ -1,5 +1,5 @@
1
- const require_entity_config = require("./entity-config-7sGCk_nw.cjs");
2
- const require_mappings_config = require("./mappings-config-CLyEg0sf.cjs");
1
+ const require_entity_config = require("./entity-config-DE30_RpU.cjs");
2
+ const require_mappings_config = require("./mappings-config-CjCmT-aU.cjs");
3
3
  const require_drizzle_meta = require("./drizzle-meta-Bb1JWYqf.cjs");
4
4
  //#region ../sdk/src/deployment-identity.ts
5
5
  const MAX_DEPLOYMENT_ID_LENGTH = 128;
@@ -572,12 +572,21 @@ async function runDoctor(args) {
572
572
  ok: entityCount > 0,
573
573
  detail: entityCount > 0 ? `${entityCount} entit${entityCount === 1 ? "y" : "ies"} configured.` : "No `entities` config — pass defineClivlyConfig(...) as `entities`."
574
574
  });
575
+ const sourcesDetail = (count, deferred) => {
576
+ if (deferred) return "Deferred — the coverage check below names the entity and the source key it expected.";
577
+ return count === 0 ? "No `source.contacts` — nothing to sync." : `${count} source(s) to mirror.`;
578
+ };
579
+ const coverage = checkConceptCoverage(config);
580
+ const coverageOwnsIt = !(coverage.ok || coverage.skipped);
581
+ const noSources = sources.length === 0;
582
+ const deferred = noSources && coverageOwnsIt;
575
583
  checks.push({
576
584
  name: "Sources configured",
577
- ok: sources.length > 0,
578
- detail: sources.length > 0 ? `${sources.length} source(s) to mirror.` : "No `source.contacts` — nothing to sync."
585
+ ok: !noSources,
586
+ skipped: deferred,
587
+ detail: sourcesDetail(sources.length, deferred)
579
588
  });
580
- checks.push(checkConceptCoverage(config));
589
+ checks.push(coverage);
581
590
  checks.push(...cursorColumnChecks(sources));
582
591
  for (const source of sources) {
583
592
  const check = cursorMonotonicityCheck(source);
@@ -1533,6 +1542,15 @@ async function handlePreviewRequest(config, preview) {
1533
1542
  sampledCount: rows.length
1534
1543
  }, 200);
1535
1544
  }
1545
+ async function handleProjectionPreviewRequest(config, request) {
1546
+ const run = config.introspector?.runProjection;
1547
+ if (!run) return jsonResponse({ error: "This app cannot preview derived objects. Set `introspector: drizzleIntrospector(db)` in clivly.config.ts, on a clivly version that supports runProjection." }, 400);
1548
+ const rows = await run.call(config.introspector, request.projection, { limit: request.limit });
1549
+ return jsonResponse({
1550
+ rows,
1551
+ sampledCount: rows.length
1552
+ }, 200);
1553
+ }
1536
1554
  /**
1537
1555
  * Create the Clivly SDK. The implemented surface — heartbeat/discovery reporting
1538
1556
  * and the auth-verify handler — connects a developer's app to a running Clivly
@@ -1662,13 +1680,17 @@ function createClivlySDK(config) {
1662
1680
  lastPushFailure = null;
1663
1681
  if (!await syncOne(resolved.source, resolved.path, "delta", resolved.objectType, runId, SAMPLE_BATCH_SIZE, SAMPLE_BATCH_SIZE, false)) throw new Error(describePushFailure([resolved.source.entity]));
1664
1682
  };
1665
- const sendHeartbeat = () => {
1666
- const triggerUrl = resolveTriggerUrl({
1683
+ const describeSyncTrigger = () => ({
1684
+ configured: config.syncTrigger?.url,
1685
+ resolved: resolveTriggerUrl({
1667
1686
  configuredUrl: config.syncTrigger?.url,
1668
1687
  configuredPath: config.syncTrigger?.path,
1669
1688
  env: config.env ?? process.env,
1670
1689
  observedUrl
1671
- });
1690
+ })
1691
+ });
1692
+ const sendHeartbeat = () => {
1693
+ const triggerUrl = describeSyncTrigger().resolved;
1672
1694
  return fetcher(`${apiUrl}/clivly/sdk/heartbeat`, {
1673
1695
  method: "POST",
1674
1696
  headers: {
@@ -1896,6 +1918,7 @@ function createClivlySDK(config) {
1896
1918
  const startedAt = Date.now();
1897
1919
  try {
1898
1920
  if (payload.preview) return await handlePreviewRequest(config, payload.preview);
1921
+ if (payload.previewProjection) return await handleProjectionPreviewRequest(config, payload.previewProjection);
1899
1922
  if (payload.sample) await runSampleSync(payload.sample.entityKey, payload.runId);
1900
1923
  else await runScheduled({
1901
1924
  mode: payload.mode,
@@ -1991,6 +2014,7 @@ function createClivlySDK(config) {
1991
2014
  connect,
1992
2015
  ping,
1993
2016
  doctor,
2017
+ describeSyncTrigger,
1994
2018
  runScheduled,
1995
2019
  createClivlyHandler,
1996
2020
  sync: runSync,
package/sdk.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_entity_config = require("./entity-config-7sGCk_nw.cjs");
3
- const require_sdk = require("./sdk-CM1UO-I7.cjs");
2
+ const require_entity_config = require("./entity-config-DE30_RpU.cjs");
3
+ const require_sdk = require("./sdk-w8Kv_XnW.cjs");
4
4
  exports.ClivlyAuthError = require_sdk.ClivlyAuthError;
5
5
  exports.ClivlyError = require_sdk.ClivlyError;
6
6
  exports.ClivlyNetworkError = require_sdk.ClivlyNetworkError;
package/sdk.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { C as defineClivlyConfig, S as customObjectDeclarations, a as ClivlyEntitiesConfig, f as CustomObjectDeclaration, k as validateEntitiesConfig, l as ConfigValidationError, m as DiscoveredSchemaTable, u as ConfigValidationResult } from "./entity-config-B2RA53nw.cjs";
2
- import { a as ClivlyConnectResult, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, g as EnsuredObjectTypeResult, h as EnsuredMappingResult, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, m as EnsureSchemaResult, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore } from "./namespace-probe-BoGI18dQ.cjs";
2
+ import { a as ClivlyConnectResult, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, g as EnsuredObjectTypeResult, h as EnsuredMappingResult, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, m as EnsureSchemaResult, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore, v as SyncTriggerDescription } from "./namespace-probe-DaTJINS-.cjs";
3
3
  //#region ../sdk/src/trigger-url.d.ts
4
4
  declare function isPlaceholderUrl(value: string): boolean;
5
5
  //#endregion
@@ -36,4 +36,4 @@ declare class ClivlyNetworkError extends ClivlyError {}
36
36
  */
37
37
  declare function createClivlySDK(config: ClivlySDKConfig): ClivlySDK;
38
38
  //#endregion
39
- export { type ChatSessionRequestBody, type ChatWidgetVisitor, ClivlyAuthError, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyEntitiesConfig, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, createChatSessionHandler, createClivlySDK, customObjectDeclarations, defineClivlyConfig, isPlaceholderUrl, validateEntitiesConfig };
39
+ export { type ChatSessionRequestBody, type ChatWidgetVisitor, ClivlyAuthError, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyEntitiesConfig, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, type SyncTriggerDescription, createChatSessionHandler, createClivlySDK, customObjectDeclarations, defineClivlyConfig, isPlaceholderUrl, validateEntitiesConfig };
package/sdk.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { C as defineClivlyConfig, S as customObjectDeclarations, a as ClivlyEntitiesConfig, f as CustomObjectDeclaration, k as validateEntitiesConfig, l as ConfigValidationError, m as DiscoveredSchemaTable, u as ConfigValidationResult } from "./entity-config-B2RA53nw.mjs";
2
- import { a as ClivlyConnectResult, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, g as EnsuredObjectTypeResult, h as EnsuredMappingResult, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, m as EnsureSchemaResult, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore } from "./namespace-probe-Cn7voAd0.mjs";
2
+ import { a as ClivlyConnectResult, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, g as EnsuredObjectTypeResult, h as EnsuredMappingResult, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, m as EnsureSchemaResult, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore, v as SyncTriggerDescription } from "./namespace-probe-Ckn9yJ6F.mjs";
3
3
  //#region ../sdk/src/trigger-url.d.ts
4
4
  declare function isPlaceholderUrl(value: string): boolean;
5
5
  //#endregion
@@ -36,4 +36,4 @@ declare class ClivlyNetworkError extends ClivlyError {}
36
36
  */
37
37
  declare function createClivlySDK(config: ClivlySDKConfig): ClivlySDK;
38
38
  //#endregion
39
- export { type ChatSessionRequestBody, type ChatWidgetVisitor, ClivlyAuthError, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyEntitiesConfig, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, createChatSessionHandler, createClivlySDK, customObjectDeclarations, defineClivlyConfig, isPlaceholderUrl, validateEntitiesConfig };
39
+ export { type ChatSessionRequestBody, type ChatWidgetVisitor, ClivlyAuthError, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyEntitiesConfig, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, type SyncTriggerDescription, createChatSessionHandler, createClivlySDK, customObjectDeclarations, defineClivlyConfig, isPlaceholderUrl, validateEntitiesConfig };
package/sdk.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { o as customObjectDeclarations, p as validateEntitiesConfig, s as defineClivlyConfig } from "./entity-config-B74SPOUZ.mjs";
2
- import { a as ClivlyRateLimitError, i as ClivlyNetworkError, n as ClivlyAuthError, o as createChatSessionHandler, r as ClivlyError, s as isPlaceholderUrl, t as createClivlySDK } from "./sdk-DYBDR939.mjs";
1
+ import { o as customObjectDeclarations, p as validateEntitiesConfig, s as defineClivlyConfig } from "./entity-config-CusbTOJ1.mjs";
2
+ import { a as ClivlyRateLimitError, i as ClivlyNetworkError, n as ClivlyAuthError, o as createChatSessionHandler, r as ClivlyError, s as isPlaceholderUrl, t as createClivlySDK } from "./sdk-Dkq6ELkf.mjs";
3
3
  export { ClivlyAuthError, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, createChatSessionHandler, createClivlySDK, customObjectDeclarations, defineClivlyConfig, isPlaceholderUrl, validateEntitiesConfig };
@@ -1,4 +1,4 @@
1
- const require_view_compiler = require("./view-compiler-B5nDal14.cjs");
1
+ const require_view_compiler = require("./view-compiler-BHI5E4QI.cjs");
2
2
  //#region ../core/src/sync-engine.ts
3
3
  /**
4
4
  * Diff a view's rows against the current mirror population for one entity.
@@ -1,4 +1,4 @@
1
- import { r as compileEntityViews } from "./view-compiler-CSYwEWf5.mjs";
1
+ import { r as compileEntityViews } from "./view-compiler-D_6gfXFr.mjs";
2
2
  //#region ../core/src/sync-engine.ts
3
3
  /**
4
4
  * Diff a view's rows against the current mirror population for one entity.
@@ -1,5 +1,5 @@
1
- const require_projection = require("./projection-Dz6_i1-w.cjs");
2
- const require_projection_sql = require("./projection-sql-Cl1qIn8m.cjs");
1
+ const require_projection = require("./projection-DEwL-D8R.cjs");
2
+ const require_projection_sql = require("./projection-sql-iHy-Cx6V.cjs");
3
3
  //#region ../core/src/view-compiler.ts
4
4
  /**
5
5
  * View compiler (Phase 2) — turns a validated entity config into read-only
@@ -1,5 +1,5 @@
1
- import { t as BASE_REF } from "./projection-CSGJbZlZ.mjs";
2
- import { a as quoteIdent, i as compileProjectionSelect, r as compileProjectionJoins, t as compileProjectionFrom } from "./projection-sql-BgnfiGqF.mjs";
1
+ import { t as BASE_REF } from "./projection-hnPSgH6G.mjs";
2
+ import { i as compileProjectionJoins, n as compileProjectionFrom, o as compileProjectionSelect, s as quoteIdent } from "./projection-sql-9zzTVGvf.mjs";
3
3
  //#region ../core/src/view-compiler.ts
4
4
  /**
5
5
  * View compiler (Phase 2) — turns a validated entity config into read-only
package/vite.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { o as ClivlySDK } from "./namespace-probe-BoGI18dQ.cjs";
1
+ import { o as ClivlySDK } from "./namespace-probe-DaTJINS-.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-Cn7voAd0.mjs";
1
+ import { o as ClivlySDK } from "./namespace-probe-Ckn9yJ6F.mjs";
2
2
  import { Plugin } from "vite";
3
3
  //#region ../sdk/src/vite.d.ts
4
4
  interface ClivlyViteOptions {
@@ -1,68 +0,0 @@
1
- import { n as PROJECTION_KEY_PATTERN, t as BASE_REF } from "./projection-CSGJbZlZ.mjs";
2
- import { h as fanOutJoins, m as validateProjection } from "./entity-config-B74SPOUZ.mjs";
3
- //#region ../core/src/projection-draft.ts
4
- function emptyProjectionDraft(baseTable) {
5
- return {
6
- baseTable,
7
- entityKey: "",
8
- fieldBindings: {},
9
- identity: { kind: "base_pk" },
10
- joins: []
11
- };
12
- }
13
- /**
14
- * The ON conditions implied by a foreign key between the two tables, so the
15
- * builder can pre-fill a join instead of making the user hand-pick columns.
16
- * Returns [] when no FK relates them — the user then picks manually.
17
- */
18
- function suggestJoinConditions(baseTable, joinTable, schema, joinKey) {
19
- const join = schema.find((t) => t.name === joinTable);
20
- const conditions = [];
21
- for (const column of join?.columnsMeta ?? []) if (column.references?.table === baseTable) conditions.push({
22
- left: {
23
- table: joinKey,
24
- column: column.name
25
- },
26
- op: "eq",
27
- right: {
28
- table: BASE_REF,
29
- column: column.references.column
30
- }
31
- });
32
- return conditions;
33
- }
34
- /** A draft becomes a projection once it has a valid key and ≥1 binding. */
35
- function draftToProjection(draft) {
36
- if (!PROJECTION_KEY_PATTERN.test(draft.entityKey)) return null;
37
- if (Object.keys(draft.fieldBindings).length === 0) return null;
38
- return {
39
- version: 1,
40
- kind: "projection",
41
- entityKey: draft.entityKey,
42
- baseTable: draft.baseTable,
43
- joins: draft.joins,
44
- fieldBindings: draft.fieldBindings,
45
- identity: draft.identity
46
- };
47
- }
48
- function draftErrors(draft, schema) {
49
- const projection = draftToProjection(draft);
50
- if (!projection) return [{
51
- path: "projection",
52
- message: "Name the object and map a field."
53
- }];
54
- return validateProjection(projection, schema, "projection");
55
- }
56
- /** Per-join fan-out, for the builder's inline cardinality hints. */
57
- function describeCardinality(draft, schema) {
58
- const projection = draftToProjection(draft);
59
- if (!projection) return [];
60
- const tablesByName = new Map(schema.map((t) => [t.name, t]));
61
- const fanning = new Set(fanOutJoins(projection, tablesByName).map((j) => j.key));
62
- return projection.joins.map((join) => ({
63
- joinKey: join.key,
64
- fansOut: fanning.has(join.key)
65
- }));
66
- }
67
- //#endregion
68
- export { suggestJoinConditions as a, emptyProjectionDraft as i, draftErrors as n, draftToProjection as r, describeCardinality as t };
@@ -1,97 +0,0 @@
1
- const require_projection = require("./projection-Dz6_i1-w.cjs");
2
- const require_entity_config = require("./entity-config-7sGCk_nw.cjs");
3
- //#region ../core/src/projection-draft.ts
4
- function emptyProjectionDraft(baseTable) {
5
- return {
6
- baseTable,
7
- entityKey: "",
8
- fieldBindings: {},
9
- identity: { kind: "base_pk" },
10
- joins: []
11
- };
12
- }
13
- /**
14
- * The ON conditions implied by a foreign key between the two tables, so the
15
- * builder can pre-fill a join instead of making the user hand-pick columns.
16
- * Returns [] when no FK relates them — the user then picks manually.
17
- */
18
- function suggestJoinConditions(baseTable, joinTable, schema, joinKey) {
19
- const join = schema.find((t) => t.name === joinTable);
20
- const conditions = [];
21
- for (const column of join?.columnsMeta ?? []) if (column.references?.table === baseTable) conditions.push({
22
- left: {
23
- table: joinKey,
24
- column: column.name
25
- },
26
- op: "eq",
27
- right: {
28
- table: require_projection.BASE_REF,
29
- column: column.references.column
30
- }
31
- });
32
- return conditions;
33
- }
34
- /** A draft becomes a projection once it has a valid key and ≥1 binding. */
35
- function draftToProjection(draft) {
36
- if (!require_projection.PROJECTION_KEY_PATTERN.test(draft.entityKey)) return null;
37
- if (Object.keys(draft.fieldBindings).length === 0) return null;
38
- return {
39
- version: 1,
40
- kind: "projection",
41
- entityKey: draft.entityKey,
42
- baseTable: draft.baseTable,
43
- joins: draft.joins,
44
- fieldBindings: draft.fieldBindings,
45
- identity: draft.identity
46
- };
47
- }
48
- function draftErrors(draft, schema) {
49
- const projection = draftToProjection(draft);
50
- if (!projection) return [{
51
- path: "projection",
52
- message: "Name the object and map a field."
53
- }];
54
- return require_entity_config.validateProjection(projection, schema, "projection");
55
- }
56
- /** Per-join fan-out, for the builder's inline cardinality hints. */
57
- function describeCardinality(draft, schema) {
58
- const projection = draftToProjection(draft);
59
- if (!projection) return [];
60
- const tablesByName = new Map(schema.map((t) => [t.name, t]));
61
- const fanning = new Set(require_entity_config.fanOutJoins(projection, tablesByName).map((j) => j.key));
62
- return projection.joins.map((join) => ({
63
- joinKey: join.key,
64
- fansOut: fanning.has(join.key)
65
- }));
66
- }
67
- //#endregion
68
- Object.defineProperty(exports, "describeCardinality", {
69
- enumerable: true,
70
- get: function() {
71
- return describeCardinality;
72
- }
73
- });
74
- Object.defineProperty(exports, "draftErrors", {
75
- enumerable: true,
76
- get: function() {
77
- return draftErrors;
78
- }
79
- });
80
- Object.defineProperty(exports, "draftToProjection", {
81
- enumerable: true,
82
- get: function() {
83
- return draftToProjection;
84
- }
85
- });
86
- Object.defineProperty(exports, "emptyProjectionDraft", {
87
- enumerable: true,
88
- get: function() {
89
- return emptyProjectionDraft;
90
- }
91
- });
92
- Object.defineProperty(exports, "suggestJoinConditions", {
93
- enumerable: true,
94
- get: function() {
95
- return suggestJoinConditions;
96
- }
97
- });