clivly 0.23.1 → 0.24.0-next.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 (103) hide show
  1. package/README.md +28 -0
  2. package/{adapter-B4v4dwgD.d.mts → adapter--YV7du3i.d.cts} +1 -1
  3. package/{adapter-BK3gsby5.d.cts → adapter-DD3K3dCW.d.mts} +1 -1
  4. package/{auth-adapter-BIa-ZyVV.d.mts → auth-adapter-C17dzlzF.d.cts} +1 -1
  5. package/{auth-adapter-DwtMJb7D.d.cts → auth-adapter-CizFv7oU.d.mts} +1 -1
  6. package/auth-better-auth.d.cts +1 -1
  7. package/auth-better-auth.d.mts +1 -1
  8. package/auth-clerk.d.cts +1 -1
  9. package/auth-clerk.d.mts +1 -1
  10. package/auth-supabase.cjs +121 -0
  11. package/auth-supabase.d.cts +23 -0
  12. package/auth-supabase.d.mts +23 -0
  13. package/auth-supabase.mjs +119 -0
  14. package/auth-workos.d.cts +1 -1
  15. package/auth-workos.d.mts +1 -1
  16. package/core-adapter.d.cts +1 -1
  17. package/core-adapter.d.mts +1 -1
  18. package/core-auth-adapter.d.cts +1 -1
  19. package/core-auth-adapter.d.mts +1 -1
  20. package/core-mapping-score.d.cts +1 -0
  21. package/core-sync-engine.cjs +1 -1
  22. package/core-sync-engine.mjs +1 -1
  23. package/core-types.cjs +5 -1
  24. package/core-types.d.cts +2 -2
  25. package/core-types.d.mts +2 -2
  26. package/core-types.mjs +1 -1
  27. package/core-view-compiler.cjs +1 -1
  28. package/core-view-compiler.mjs +1 -1
  29. package/core.cjs +9 -5
  30. package/core.d.cts +6 -6
  31. package/core.d.mts +6 -6
  32. package/core.mjs +6 -6
  33. package/discover-BZIPXl23.cjs +200 -0
  34. package/discover-CFIi43Qn.mjs +195 -0
  35. package/drizzle.cjs +1 -1
  36. package/drizzle.d.cts +2 -2
  37. package/drizzle.d.mts +2 -2
  38. package/drizzle.mjs +1 -1
  39. package/executor-CJEWurjZ.mjs +23 -0
  40. package/executor-CU-jRgpC.cjs +40 -0
  41. package/index-CZkp8TV4.d.cts +108 -0
  42. package/index-Cnrz4ywf.d.mts +108 -0
  43. package/{index-Bh7o2J7K.d.mts → index-DOoX2GgI.d.mts} +3 -3
  44. package/{index-DRRTE5IJ.d.cts → index-uFDiQEjj.d.cts} +231 -5
  45. package/index.cjs +903 -30
  46. package/index.d.cts +27 -0
  47. package/index.d.mts +26 -0
  48. package/index.mjs +901 -28
  49. package/{internal-CdfVkh4O.d.mts → internal-D_2q2BOB.d.mts} +1 -1
  50. package/internal-adapter.d.cts +1 -1
  51. package/internal-adapter.d.mts +1 -1
  52. package/internal-auth-adapter.d.cts +1 -1
  53. package/internal-auth-adapter.d.mts +1 -1
  54. package/internal-sync-engine.cjs +1 -1
  55. package/internal-sync-engine.mjs +1 -1
  56. package/internal-types.cjs +5 -1
  57. package/internal-types.d.cts +2 -2
  58. package/internal-types.d.mts +2 -2
  59. package/internal-types.mjs +1 -1
  60. package/internal-view-compiler.cjs +1 -1
  61. package/internal-view-compiler.mjs +1 -1
  62. package/internal.cjs +9 -5
  63. package/internal.d.cts +5 -6
  64. package/internal.d.mts +6 -6
  65. package/internal.mjs +6 -6
  66. package/introspector-BwYgHGcS.cjs +363 -0
  67. package/introspector-Bz52xOUr.mjs +334 -0
  68. package/{namespace-probe-JuHriruA.d.mts → namespace-probe--GvxJ06J.d.mts} +8 -1
  69. package/package.json +31 -1
  70. package/projection-guard-7AMY0aCk.mjs +389 -0
  71. package/projection-guard-D8VUhCz7.cjs +508 -0
  72. package/{projection-sql-DQQdjw9I.mjs → projection-sql-2joBkLz2.mjs} +13 -3
  73. package/{projection-sql-BkrHR2ea.cjs → projection-sql-DS5sVTY-.cjs} +18 -2
  74. package/sdk-Bzkr24NW.cjs +207 -0
  75. package/sdk-D2WwGBzk.mjs +178 -0
  76. package/sdk.cjs +8 -6
  77. package/sdk.d.cts +7 -1
  78. package/sdk.d.mts +7 -1
  79. package/sdk.mjs +3 -2
  80. package/sql.cjs +13 -0
  81. package/sql.d.cts +2 -0
  82. package/sql.d.mts +2 -0
  83. package/sql.mjs +4 -0
  84. package/{sdk-BkMDOfCk.mjs → src-Dq2nY1Sj.mjs} +36 -495
  85. package/{sdk-BOarpe5I.cjs → src-X0-yIA3O.cjs} +63 -546
  86. package/supabase.cjs +255 -0
  87. package/supabase.d.cts +19 -0
  88. package/supabase.d.mts +19 -0
  89. package/supabase.mjs +254 -0
  90. package/{sync-engine-yFLEyId3.mjs → sync-engine-D0mJUeqP.mjs} +1 -1
  91. package/{sync-engine-DNSoZeo0.cjs → sync-engine-hU041kXO.cjs} +1 -1
  92. package/types-KMH5D5Lg.mjs +32 -0
  93. package/{namespace-probe-CcL6Wj8E.d.cts → types-UR-tT4c1.d.cts} +52 -45
  94. package/{types-BBfwsDxe.d.cts → types-f-Vcv-pl.d.cts} +18 -2
  95. package/{types-BBfwsDxe.d.mts → types-f-Vcv-pl.d.mts} +18 -2
  96. package/types-kR1kUlmz.cjs +67 -0
  97. package/{view-compiler-CSHSqZl7.mjs → view-compiler-BhKiezRH.mjs} +1 -1
  98. package/{view-compiler-NqiortOA.cjs → view-compiler-DgZadq1F.cjs} +1 -1
  99. package/vite.d.cts +1 -1
  100. package/vite.d.mts +1 -1
  101. package/internal-D7qVRIFb.d.cts +0 -228
  102. package/types-8KSw2AWg.mjs +0 -8
  103. package/types-B8m39L1s.cjs +0 -19
@@ -0,0 +1,334 @@
1
+ import { r as identityRefs, t as BASE_REF } from "./projection-CzBI2NL8.mjs";
2
+ import { a as compileProjectionPreview, c as quoteTableRef, i as compileProjectionJoins, n as compileProjectionFrom, r as compileProjectionIdentity, s as quoteIdent } from "./projection-sql-2joBkLz2.mjs";
3
+ import { t as discoverFromSql } from "./discover-CFIi43Qn.mjs";
4
+ import { _ as AUTH_USERS_META_KEYS, a as ROW_CURSOR_KEY, b as isAnonymousFilter, g as AUTH_USERS_COLUMNS, n as authExposureErrors, t as ProjectionRefusedError, v as AUTH_USERS_TABLE, y as authTableKind } from "./projection-guard-7AMY0aCk.mjs";
5
+ import { t as DRIZZLE_META } from "./drizzle-meta-D00lFvAk.mjs";
6
+ // ../sdk/src/sql/dialect.ts
7
+ const postgresDialect = {
8
+ name: "postgres",
9
+ quoteIdent,
10
+ quoteTableRef,
11
+ param: (index) => `$${index}`,
12
+ timestampParam: (index) => `$${index}::timestamptz`
13
+ };
14
+ // ../sdk/src/sql/app-id.ts
15
+ /** The one-row host table that keeps the ID Clivly issued this app. */
16
+ const APP_ID_TABLE = "crm_clivly_app";
17
+ /**
18
+ * The raw-SQL twin of `drizzleAppIdStore`: an `AppIdStore` backed by a
19
+ * one-row `crm_clivly_app` table, created on first use. The only write Clivly
20
+ * ever makes to a host database.
21
+ */
22
+ function sqlAppIdStore(executor) {
23
+ const { quoteIdent, param } = postgresDialect;
24
+ const table = quoteIdent(APP_ID_TABLE);
25
+ let ready = null;
26
+ const ensureTable = () => {
27
+ ready ??= executor.query(`create table if not exists ${table} (app_id text primary key, created_at timestamptz not null default now())`).catch((error) => {
28
+ ready = null;
29
+ throw error;
30
+ });
31
+ return ready;
32
+ };
33
+ return {
34
+ async get() {
35
+ await ensureTable();
36
+ const value = (await executor.query(`select app_id from ${table} order by created_at limit 1`))[0]?.app_id;
37
+ return typeof value === "string" ? value : null;
38
+ },
39
+ async set(appId) {
40
+ await ensureTable();
41
+ await executor.query(`insert into ${table} (app_id) select ${param(1)} where not exists (select 1 from ${table})`, [appId]);
42
+ }
43
+ };
44
+ }
45
+ // ../sdk/src/sql/from-sql.ts
46
+ const DEFAULT_CURSOR_COLUMN = "updated_at";
47
+ const META_COLUMN$1 = "raw_user_meta_data";
48
+ const dialect$1 = postgresDialect;
49
+ const NULL_CURSOR_FLOOR = "'1970-01-01T00:00:00Z'::timestamptz";
50
+ const CURSOR_ALIAS = "__clivly_cursor__";
51
+ const cursorExpression = (cursorField) => `coalesce(${dialect$1.quoteIdent(cursorField)}, ${NULL_CURSOR_FLOOR})`;
52
+ function inferIdField(meta, table) {
53
+ const primaryKeys = (meta.columnsMeta ?? []).filter((c) => c.isPrimaryKey);
54
+ const only = primaryKeys[0];
55
+ if (primaryKeys.length === 1 && only) return only.name;
56
+ const kind = primaryKeys.length === 0 ? "no" : "a composite";
57
+ throw new Error(`fromSql: table "${table}" has ${kind} single-column primary key — pass { idField } explicitly.`);
58
+ }
59
+ const quoteLiteral = (value) => `'${value.replaceAll("'", "''")}'`;
60
+ function narrowedMetaValue(columnSql) {
61
+ return `case when ${columnSql} is null then null else jsonb_strip_nulls(jsonb_build_object(${AUTH_USERS_META_KEYS.map((key) => `${quoteLiteral(key)}, ${columnSql}->${quoteLiteral(key)}`).join(", ")})) end`;
62
+ }
63
+ function narrowedMetaExpression() {
64
+ const col = dialect$1.quoteIdent(META_COLUMN$1);
65
+ return `${narrowedMetaValue(col)} as ${col}`;
66
+ }
67
+ function selectItem(column, isAuthUsers) {
68
+ if (isAuthUsers && column === META_COLUMN$1) return narrowedMetaExpression();
69
+ return dialect$1.quoteIdent(column);
70
+ }
71
+ function normaliseValue(value) {
72
+ if (typeof value !== "bigint") return value;
73
+ const asNumber = Number(value);
74
+ return Number.isSafeInteger(asNumber) ? asNumber : value.toString();
75
+ }
76
+ function normaliseRows(rows) {
77
+ return rows.map((row) => {
78
+ const out = {};
79
+ for (const [key, value] of Object.entries(row)) out[key] = normaliseValue(value);
80
+ return out;
81
+ });
82
+ }
83
+ function hideCursorAlias(rows) {
84
+ return rows.map((row) => {
85
+ const { [CURSOR_ALIAS]: position, ...visible } = row;
86
+ Object.defineProperty(visible, ROW_CURSOR_KEY, {
87
+ value: position,
88
+ enumerable: false
89
+ });
90
+ return visible;
91
+ });
92
+ }
93
+ function resolveColumns(opts, isAuthUsers, required) {
94
+ if (isAuthUsers) return [...AUTH_USERS_COLUMNS];
95
+ const base = opts.columns ?? opts.meta.columns;
96
+ return [.../* @__PURE__ */ new Set([...base, ...required])];
97
+ }
98
+ function assertColumn(meta, table, label, column) {
99
+ if (!meta.columns.includes(column)) throw new Error(`fromSql: ${label} "${column}" is not a column on "${table}".`);
100
+ }
101
+ function buildPredicate(opts, isAuthUsers, keyset) {
102
+ const parts = [];
103
+ if (keyset) parts.push(keyset);
104
+ if (opts.where) parts.push(`(${opts.where})`);
105
+ if (isAuthUsers) parts.push(`(${isAnonymousFilter})`);
106
+ return parts.length === 0 ? "" : ` where ${parts.join(" and ")}`;
107
+ }
108
+ function fromSql(executor, opts) {
109
+ const { meta, table } = opts;
110
+ const isAuthUsers = table === AUTH_USERS_TABLE;
111
+ const idField = opts.idField ?? inferIdField(meta, table);
112
+ assertColumn(meta, table, "idField", idField);
113
+ const cursorField = opts.cursorField ?? (meta.columns.includes(DEFAULT_CURSOR_COLUMN) ? DEFAULT_CURSOR_COLUMN : void 0);
114
+ if (cursorField !== void 0) assertColumn(meta, table, "cursorField", cursorField);
115
+ const columns = resolveColumns(opts, isAuthUsers, cursorField === void 0 ? [idField] : [cursorField, idField]);
116
+ const items = columns.map((c) => selectItem(c, isAuthUsers));
117
+ if (cursorField !== void 0) items.push(`${cursorExpression(cursorField)} as ${dialect$1.quoteIdent(CURSOR_ALIAS)}`);
118
+ const head = `select ${items.join(", ")} from ${dialect$1.quoteTableRef(table)}`;
119
+ const idSql = dialect$1.quoteIdent(idField);
120
+ const fetchPage = async ({ since, limit }) => {
121
+ const params = [];
122
+ let keyset = null;
123
+ let order = idSql;
124
+ if (cursorField === void 0) {
125
+ if (since) {
126
+ params.push(since.id);
127
+ keyset = `${idSql} > ${dialect$1.param(params.length)}`;
128
+ }
129
+ } else {
130
+ const cursorSql = cursorExpression(cursorField);
131
+ order = `${cursorSql}, ${idSql}`;
132
+ if (since) {
133
+ params.push(since.time.toISOString(), since.id);
134
+ keyset = `(${cursorSql}, ${idSql}) > (${dialect$1.timestampParam(params.length - 1)}, ${dialect$1.param(params.length)})`;
135
+ }
136
+ }
137
+ params.push(limit);
138
+ const text = `${head}${buildPredicate(opts, isAuthUsers, keyset)} order by ${order} limit ${dialect$1.param(params.length)}`;
139
+ const rows = normaliseRows(await executor.query(text, params));
140
+ return cursorField === void 0 ? rows : hideCursorAlias(rows);
141
+ };
142
+ const source = {
143
+ entity: opts.entity,
144
+ ...opts.pushSource === void 0 ? {} : { pushSource: opts.pushSource },
145
+ cursorField: cursorField ?? idField,
146
+ idField,
147
+ ...cursorField === void 0 ? { mode: "full" } : {},
148
+ fetchPage,
149
+ ...opts.objectType === void 0 ? {} : { objectType: opts.objectType }
150
+ };
151
+ const sourceMeta = {
152
+ kind: "sql",
153
+ columnKeys: columns,
154
+ columnsMeta: meta.columnsMeta,
155
+ cursorField: cursorField ?? idField,
156
+ idField,
157
+ tableName: table,
158
+ ...meta.uniqueConstraints === void 0 ? {} : { uniqueConstraints: meta.uniqueConstraints }
159
+ };
160
+ Object.defineProperty(source, DRIZZLE_META, {
161
+ value: sourceMeta,
162
+ enumerable: false
163
+ });
164
+ return source;
165
+ }
166
+ /**
167
+ * Whether `fromSql` would sync at least one row for `table`: one
168
+ * `exists(... limit 1)` under `buildPredicate`, the predicate every page query
169
+ * uses, so the `auth.users` anonymous exclusion cannot drift. The projection
170
+ * path (`baseGuard` in projection.ts) applies the same `isAnonymousFilter`;
171
+ * keep the two in step. A boolean on purpose: `/clivly/connect` is a public GET,
172
+ * so it must not reveal how many users exist or run a full count.
173
+ */
174
+ async function existsFromSql(executor, opts) {
175
+ const isAuthUsers = opts.table === AUTH_USERS_TABLE;
176
+ const predicate = buildPredicate({ where: opts.where }, isAuthUsers, null);
177
+ const text = `select exists(select 1 from ${dialect$1.quoteTableRef(opts.table)}${predicate} limit 1) as present`;
178
+ const [row] = await executor.query(text, []);
179
+ return row?.present === true;
180
+ }
181
+ // ../sdk/src/sql/projection.ts
182
+ const dialect = postgresDialect;
183
+ const META_COLUMN = "raw_user_meta_data";
184
+ const IS_ANONYMOUS = "is_anonymous";
185
+ const CURSOR_FORMAT = `'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'`;
186
+ const ALLOWED_AUTH_COLUMNS = AUTH_USERS_COLUMNS;
187
+ const refToken = (ref) => `${ref.table}.${ref.column}`;
188
+ const refSql = (ref) => `${dialect.quoteIdent(ref.table)}.${dialect.quoteIdent(ref.column)}`;
189
+ function parseRef(value) {
190
+ if (typeof value !== "string") return value;
191
+ const dot = value.indexOf(".");
192
+ if (dot <= 0 || dot === value.length - 1) throw new Error(`fromSqlProjection: cursorField "${value}" must be a ref token like "base.updated_at".`);
193
+ return {
194
+ table: value.slice(0, dot),
195
+ column: value.slice(dot + 1)
196
+ };
197
+ }
198
+ function assertKnownRef(ref, known, context) {
199
+ if (!known.has(ref.table)) throw new Error(`fromSqlProjection: ${context} names unknown ref "${ref.table}" — expected "${[...known].join("\", \"")}".`);
200
+ }
201
+ const anonymousFilterFor = (alias) => isAnonymousFilter.replace(IS_ANONYMOUS, `${dialect.quoteIdent(alias)}.${dialect.quoteIdent(IS_ANONYMOUS)}`);
202
+ function assertAuthColumnsAllowed(refs, isAuthRef) {
203
+ for (const ref of refs) if (isAuthRef(ref) && !ALLOWED_AUTH_COLUMNS.includes(ref.column)) throw new Error(`fromSqlProjection: "${AUTH_USERS_TABLE}.${ref.column}" cannot be read — only ${AUTH_USERS_COLUMNS.join(", ")} are exposed.`);
204
+ }
205
+ function bindingItems(projection, emitted, isAuthRef) {
206
+ const items = [];
207
+ for (const binding of Object.values(projection.fieldBindings)) {
208
+ const token = refToken(binding.from);
209
+ if (emitted.has(token)) continue;
210
+ emitted.add(token);
211
+ const value = isAuthRef(binding.from) && binding.from.column === META_COLUMN ? narrowedMetaValue(refSql(binding.from)) : refSql(binding.from);
212
+ items.push(`${value} AS ${dialect.quoteIdent(token)}`);
213
+ }
214
+ return items;
215
+ }
216
+ /**
217
+ * The raw-SQL twin of `fromDrizzleProjection`: a `SyncSource` that executes a
218
+ * projection's joins. Rows are keyed by ref token. Read-only. Without a
219
+ * `cursorField` it pages by identity and reports `mode: "full"`.
220
+ */
221
+ function fromSqlProjection(executor, projection, opts) {
222
+ const known = /* @__PURE__ */ new Set([BASE_REF, ...projection.joins.map((j) => j.key)]);
223
+ const tableOf = new Map([[BASE_REF, projection.baseTable], ...projection.joins.map((j) => [j.key, j.table])]);
224
+ const isAuthRef = (ref) => authTableKind(tableOf.get(ref.table) ?? "") === "users";
225
+ for (const table of tableOf.values()) if (authTableKind(table) === "other") throw new Error(`fromSqlProjection: "${table}" is in the auth schema and cannot be read — only ${AUTH_USERS_TABLE} is exposed.`);
226
+ if (projection.identity.kind === "base_pk" && projection.identity.column === void 0 && opts.basePkColumn === void 0) throw new Error(`fromSqlProjection: projection "${projection.entityKey}" has a base_pk identity with no column — pass { basePkColumn }.`);
227
+ for (const [field, binding] of Object.entries(projection.fieldBindings)) assertKnownRef(binding.from, known, `field "${field}"`);
228
+ const identityRefList = identityRefs(projection.identity, opts.basePkColumn ?? "");
229
+ const cursorRef = opts.cursorField === void 0 ? void 0 : parseRef(opts.cursorField);
230
+ if (cursorRef) assertKnownRef(cursorRef, known, "cursorField");
231
+ assertAuthColumnsAllowed([
232
+ ...Object.values(projection.fieldBindings).map((b) => b.from),
233
+ ...identityRefList,
234
+ ...projection.joins.flatMap((j) => j.on.flatMap((c) => [c.left, c.right])),
235
+ ...cursorRef ? [cursorRef] : []
236
+ ], isAuthRef);
237
+ const identityExpr = compileProjectionIdentity(projection, opts.basePkColumn ?? "");
238
+ const joins = compileProjectionJoins(projection).map((join, i) => {
239
+ const spec = projection.joins[i];
240
+ return spec && authTableKind(spec.table) === "users" ? `${join} AND (${anonymousFilterFor(spec.key)})` : join;
241
+ });
242
+ const fromClause = [compileProjectionFrom(projection), ...joins].join(" ");
243
+ const baseGuard = authTableKind(projection.baseTable) === "users" ? `(${anonymousFilterFor(BASE_REF)})` : null;
244
+ const selectItems = [`${identityExpr} AS ${dialect.quoteIdent("id")}`];
245
+ const emitted = /* @__PURE__ */ new Set();
246
+ const cursorToken = cursorRef ? refToken(cursorRef) : void 0;
247
+ let cursorExpr = "";
248
+ if (cursorRef && cursorToken) {
249
+ const cast = `CAST(${refSql(cursorRef)} AS timestamptz)`;
250
+ cursorExpr = `coalesce(${cast}, ${NULL_CURSOR_FLOOR})`;
251
+ selectItems.push(`to_char(${cast} AT TIME ZONE 'UTC', ${CURSOR_FORMAT}) AS ${dialect.quoteIdent(cursorToken)}`);
252
+ emitted.add(cursorToken);
253
+ }
254
+ selectItems.push(...bindingItems(projection, emitted, isAuthRef));
255
+ if (cursorExpr) selectItems.push(`${cursorExpr} AS ${dialect.quoteIdent(CURSOR_ALIAS)}`);
256
+ const head = `select ${selectItems.join(", ")} ${fromClause}`;
257
+ const fetchPage = async ({ since, limit }) => {
258
+ const params = [];
259
+ const predicates = [];
260
+ if (since && cursorExpr) {
261
+ params.push(since.time.toISOString(), since.id);
262
+ predicates.push(`(${cursorExpr}, ${identityExpr}) > (${dialect.timestampParam(params.length - 1)}, ${dialect.param(params.length)})`);
263
+ } else if (since) {
264
+ params.push(since.id);
265
+ predicates.push(`${identityExpr} > ${dialect.param(params.length)}`);
266
+ }
267
+ if (baseGuard) predicates.push(baseGuard);
268
+ params.push(limit);
269
+ const where = predicates.length === 0 ? "" : ` where ${predicates.join(" and ")}`;
270
+ const order = cursorExpr ? `${cursorExpr}, ${identityExpr}` : identityExpr;
271
+ const text = `${head}${where} order by ${order} limit ${dialect.param(params.length)}`;
272
+ const rows = normaliseRows(await executor.query(text, params));
273
+ return cursorExpr ? hideCursorAlias(rows) : rows;
274
+ };
275
+ return {
276
+ entity: opts.entity,
277
+ pushSource: projection.baseTable,
278
+ cursorField: cursorToken ?? "id",
279
+ idField: "id",
280
+ ...cursorExpr ? {} : { mode: "full" },
281
+ objectType: opts.objectType,
282
+ fetchPage
283
+ };
284
+ }
285
+ // ../sdk/src/sql/introspector.ts
286
+ function assertAuthRule(projection) {
287
+ const refused = authExposureErrors(projection);
288
+ if (refused.length > 0) throw new ProjectionRefusedError(refused);
289
+ }
290
+ const PREVIEW_ENTITY = "preview";
291
+ function touchesAuthUsers(projection) {
292
+ return [projection.baseTable, ...projection.joins.map((j) => j.table)].some((table) => authTableKind(table) === "users");
293
+ }
294
+ async function previewThroughSource(executor, projection, limit) {
295
+ return (await fromSqlProjection(executor, projection, {
296
+ entity: PREVIEW_ENTITY,
297
+ objectType: PREVIEW_ENTITY,
298
+ basePkColumn: "id"
299
+ }).fetchPage({
300
+ since: null,
301
+ limit: Math.max(1, Math.min(Math.floor(limit), 50))
302
+ })).map((row) => ({
303
+ id: row.id,
304
+ ...Object.fromEntries(Object.entries(projection.fieldBindings).map(([field, binding]) => [field, row[`${binding.from.table}.${binding.from.column}`]]))
305
+ }));
306
+ }
307
+ /**
308
+ * The raw-SQL twin of `drizzleIntrospector`, for apps with no ORM.
309
+ * Read-only: every statement here is a SELECT.
310
+ */
311
+ function sqlIntrospector(executor) {
312
+ return {
313
+ async listTables() {
314
+ return (await discoverFromSql(executor)).map((t) => t.name);
315
+ },
316
+ async sampleSelect(table) {
317
+ await executor.query(`select 1 from ${postgresDialect.quoteTableRef(table)} limit 1`);
318
+ },
319
+ async runProjection(projection, previewOpts) {
320
+ assertAuthRule(projection);
321
+ if (touchesAuthUsers(projection)) return await previewThroughSource(executor, projection, previewOpts.limit);
322
+ return await executor.query(compileProjectionPreview(projection, previewOpts.limit));
323
+ },
324
+ projectionSource(projection, sourceOpts) {
325
+ assertAuthRule(projection);
326
+ return fromSqlProjection(executor, projection, {
327
+ entity: sourceOpts.objectType,
328
+ objectType: sourceOpts.objectType,
329
+ ...sourceOpts.basePkColumn ? { basePkColumn: sourceOpts.basePkColumn } : {}
330
+ });
331
+ }
332
+ };
333
+ }
334
+ export { sqlAppIdStore as a, fromSql as i, fromSqlProjection as n, existsFromSql as r, sqlIntrospector as t };
@@ -1,5 +1,5 @@
1
1
  import { R as ProjectionMapping, a as ClivlyEntitiesConfig } from "./entity-config-CXpGowQa.mjs";
2
- import { v as IntegrationState } from "./index-Bh7o2J7K.mjs";
2
+ import { v as IntegrationState } from "./index-DOoX2GgI.mjs";
3
3
  declare const DRIZZLE_META: "__clivly_drizzle_source_meta__";
4
4
  interface DrizzleSourceMeta {
5
5
  /** Drizzle property keys of every column on the source table. */
@@ -8,6 +8,8 @@ interface DrizzleSourceMeta {
8
8
  columnsMeta?: DiscoveredColumn[];
9
9
  cursorField: string;
10
10
  idField: string;
11
+ /** Which source builder attached this: `fromDrizzle` (default) or `fromSql`. */
12
+ kind?: "drizzle" | "sql";
11
13
  /** The backing table's real name, so discovery can key metadata by table. */
12
14
  tableName?: string;
13
15
  /** Every unique key on the table, each as its DB column names. */
@@ -395,6 +397,11 @@ interface SyncSource {
395
397
  }): Promise<Record<string, unknown>[]>;
396
398
  /** Stable, unique tie-breaker column for keyset paging. Defaults to "id". */
397
399
  idField?: string;
400
+ /**
401
+ * `"full"` when the source has no change cursor and every sync is a complete
402
+ * snapshot paged by id alone (a table with no `updated_at`).
403
+ */
404
+ mode?: SyncMode;
398
405
  /**
399
406
  * Custom-object slug this source mirrors into. Only meaningful for entries in
400
407
  * `source.custom`, whose element type narrows it to required — declared here
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clivly",
3
- "version": "0.23.1",
3
+ "version": "0.24.0-next.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Clivly CLI — scaffold a CRM into your app (clivly init).",
@@ -319,6 +319,26 @@
319
319
  "default": "./drizzle.cjs"
320
320
  }
321
321
  },
322
+ "./sql": {
323
+ "import": {
324
+ "types": "./sql.d.mts",
325
+ "default": "./sql.mjs"
326
+ },
327
+ "require": {
328
+ "types": "./sql.d.cts",
329
+ "default": "./sql.cjs"
330
+ }
331
+ },
332
+ "./supabase": {
333
+ "import": {
334
+ "types": "./supabase.d.mts",
335
+ "default": "./supabase.mjs"
336
+ },
337
+ "require": {
338
+ "types": "./supabase.d.cts",
339
+ "default": "./supabase.cjs"
340
+ }
341
+ },
322
342
  "./vite": {
323
343
  "import": {
324
344
  "types": "./vite.d.mts",
@@ -349,6 +369,16 @@
349
369
  "default": "./auth-workos.cjs"
350
370
  }
351
371
  },
372
+ "./auth/supabase": {
373
+ "import": {
374
+ "types": "./auth-supabase.d.mts",
375
+ "default": "./auth-supabase.mjs"
376
+ },
377
+ "require": {
378
+ "types": "./auth-supabase.d.cts",
379
+ "default": "./auth-supabase.cjs"
380
+ }
381
+ },
352
382
  "./auth/better-auth": {
353
383
  "import": {
354
384
  "types": "./auth-better-auth.d.mts",