clivly 0.24.0-next.0 → 0.24.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 (54) hide show
  1. package/README.md +26 -14
  2. package/app-id-5cB6yioz.mjs +53 -0
  3. package/app-id-DcQ4u1c8.cjs +70 -0
  4. package/drizzle.cjs +120 -13
  5. package/drizzle.d.cts +7 -1
  6. package/drizzle.d.mts +7 -1
  7. package/drizzle.mjs +126 -19
  8. package/from-sql-BD7gR4bC.mjs +282 -0
  9. package/from-sql-CFgXkCe2.cjs +347 -0
  10. package/{index-CZkp8TV4.d.cts → from-sql-CpGP7K3J.d.mts} +8 -46
  11. package/{index-Cnrz4ywf.d.mts → from-sql-S8dSvU-e.d.cts} +8 -46
  12. package/index-BoemTWH4.d.mts +134 -0
  13. package/index-CIupXz_w.d.cts +134 -0
  14. package/index.cjs +246 -76
  15. package/index.d.cts +11 -2
  16. package/index.d.mts +11 -2
  17. package/index.mjs +245 -75
  18. package/introspector-5w2x89RD.mjs +55 -0
  19. package/introspector-DT_Ma59k.cjs +60 -0
  20. package/kysely.cjs +56 -0
  21. package/kysely.d.cts +45 -0
  22. package/kysely.d.mts +45 -0
  23. package/kysely.mjs +54 -0
  24. package/{namespace-probe--GvxJ06J.d.mts → namespace-probe-CUR2zG2l.d.mts} +33 -3
  25. package/package.json +15 -1
  26. package/projection-guard-C70l5U24.cjs +170 -0
  27. package/projection-guard-DOt_nbGn.mjs +147 -0
  28. package/sdk.cjs +1 -1
  29. package/sdk.d.cts +1 -1
  30. package/sdk.d.mts +1 -1
  31. package/sdk.mjs +1 -1
  32. package/sql.cjs +14 -7
  33. package/sql.d.cts +3 -2
  34. package/sql.d.mts +3 -2
  35. package/sql.mjs +6 -3
  36. package/{src-X0-yIA3O.cjs → src-CZIdwwI2.cjs} +162 -59
  37. package/{src-Dq2nY1Sj.mjs → src-tFhC1Ru2.mjs} +141 -38
  38. package/supabase-contact-3ke1KKUs.mjs +595 -0
  39. package/supabase-contact-BXQ0nnLq.cjs +624 -0
  40. package/supabase.cjs +30 -120
  41. package/supabase.d.cts +2 -1
  42. package/supabase.d.mts +2 -1
  43. package/supabase.mjs +27 -117
  44. package/{projection-guard-D8VUhCz7.cjs → sync-CdA9dgZz.cjs} +165 -154
  45. package/{projection-guard-7AMY0aCk.mjs → sync-Q0O-2kFI.mjs} +136 -143
  46. package/{types-UR-tT4c1.d.cts → types-CzL7lUH9.d.cts} +33 -3
  47. package/vite.d.cts +1 -1
  48. package/vite.d.mts +1 -1
  49. package/discover-BZIPXl23.cjs +0 -200
  50. package/discover-CFIi43Qn.mjs +0 -195
  51. package/drizzle-meta-BPnRLpsB.cjs +0 -8
  52. package/drizzle-meta-D00lFvAk.mjs +0 -3
  53. package/introspector-BwYgHGcS.cjs +0 -363
  54. package/introspector-Bz52xOUr.mjs +0 -334
@@ -0,0 +1,347 @@
1
+ const require_sync = require("./sync-CdA9dgZz.cjs");
2
+ const require_projection_sql = require("./projection-sql-DS5sVTY-.cjs");
3
+ // ../sdk/src/sql/dialect.ts
4
+ const postgresDialect = {
5
+ name: "postgres",
6
+ quoteIdent: require_projection_sql.quoteIdent,
7
+ quoteTableRef: require_projection_sql.quoteTableRef,
8
+ param: (index) => `$${index}`,
9
+ timestampParam: (index) => `$${index}::timestamptz`
10
+ };
11
+ // ../sdk/src/sql/keyset.ts
12
+ /**
13
+ * Keyset paging shared by every cursored source (`fromDrizzle`,
14
+ * `fromDrizzleProjection`, `fromSql`, `fromSqlProjection`).
15
+ *
16
+ * Rows are ordered on the RAW `(cursor, id)` columns, so an index on them is
17
+ * walked in order. The position is carried at the database's precision: each
18
+ * row also reads its cursor as text with microseconds (`exactCursorRead`), and
19
+ * the next page compares `(cursor, id) > ('<that text>', id)` in Postgres. A
20
+ * JS Date keeps only milliseconds, and a cursor truncated to one re-read every
21
+ * row inside that millisecond, forever when a whole page shared it.
22
+ *
23
+ * Rows with no position come first, as if at the epoch (the `fromSql`
24
+ * semantics), read by id in a query of their own so neither query orders on
25
+ * an expression: a NULL cursor, and an `infinity` / `-infinity` timestamp,
26
+ * which `to_char` reads as NULL and no Date can hold. Every row is synced; an
27
+ * infinite stamp simply never moves the position.
28
+ */
29
+ /** Internal alias a page query reads the exact cursor under; never pushed. */
30
+ const CURSOR_ALIAS = "__clivly_cursor__";
31
+ /** `to_char` format of an exact cursor time. */
32
+ const EXACT_FORMAT = `'YYYY-MM-DD"T"HH24:MI:SS.US"Z"'`;
33
+ const CURSOR_LITERAL = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,6})?Z$/;
34
+ const UNSUPPORTED = "unsupported:";
35
+ /**
36
+ * SQL reading a timestamp cursor column as `YYYY-MM-DDTHH:MM:SS.ffffffZ`: the
37
+ * UTC instant of a `timestamptz`, the wall time of a `timestamp` (read as UTC,
38
+ * the convention Drizzle's own column mapping uses), for a caller that does
39
+ * not know which it has. Every branch type-checks for a text or date column
40
+ * too, which reads as `unsupported:<type>` and fails the page with a clear
41
+ * error (`hideCursorAlias`); keyset order on those would be wrong.
42
+ */
43
+ function exactCursorRead(column) {
44
+ return `case pg_typeof(${column}) when 'timestamp with time zone'::regtype then to_char(CAST(${column} AS timestamptz) at time zone 'UTC', ${EXACT_FORMAT}) when 'timestamp without time zone'::regtype then to_char(CAST(${column} AS timestamp), ${EXACT_FORMAT}) else '${UNSUPPORTED}' || pg_typeof(${column})::text end`;
45
+ }
46
+ const TIMESTAMP_TYPE = /^timestamp/i;
47
+ /** True for a timestamp type, or an undiscovered one (`undefined`). */
48
+ const isTimestampType = (type) => type === void 0 || TIMESTAMP_TYPE.test(type);
49
+ /**
50
+ * Throw at construction when a column's known type cannot be a cursor. Only
51
+ * `timestamp` and `timestamptz` order and compare as times; `undefined` (type
52
+ * not discovered) is left to the read-time check.
53
+ */
54
+ function assertTimestampCursor(label, column, type) {
55
+ if (!isTimestampType(type)) throw new Error(`${label}: cursorField "${column}" is ${type}; a cursor must be a timestamp or timestamptz column.`);
56
+ }
57
+ /**
58
+ * The rows with no position (see above), or null when the column can hold
59
+ * none: not nullable and not a timestamp. `timestamp` false is a Drizzle
60
+ * column of another type, which cannot hold `infinity`.
61
+ */
62
+ function unpositionedPredicate(column, opts) {
63
+ const parts = [];
64
+ if (opts.nullable) parts.push(`${column} IS NULL`);
65
+ if (opts.timestamp) parts.push(`${column} = '-infinity'`, `${column} = 'infinity'`);
66
+ return parts.length === 0 ? null : `(${parts.join(" OR ")})`;
67
+ }
68
+ /** The rows with a position: what `unpositionedPredicate` leaves out. */
69
+ function positionedPredicate(column, opts) {
70
+ return opts.timestamp ? `${column} > '-infinity' AND ${column} < 'infinity'` : `${column} IS NOT NULL`;
71
+ }
72
+ /**
73
+ * `since` as an untyped SQL literal. Untyped, it takes the cursor column's own
74
+ * type, so the comparison runs in Postgres at that type's precision, and no
75
+ * driver serialises a Date for it (node-postgres would send local time).
76
+ * Validated to plain ISO 8601 that names a real instant, so it can never
77
+ * carry a quote, and a value like month 99 fails here rather than in SQL.
78
+ */
79
+ function cursorLiteral(since) {
80
+ const value = since.exact ?? since.time.toISOString();
81
+ if (!(CURSOR_LITERAL.test(value) && require_sync.isValidIsoTime(value))) throw new Error(`clivly: cursor time "${value}" is not ISO 8601 UTC.`);
82
+ return `'${value}'`;
83
+ }
84
+ /**
85
+ * Whether `since` stands among the NULL-cursor rows: the epoch with no exact
86
+ * value. A real row exactly at the epoch carries an exact value.
87
+ */
88
+ function isNullGroup(since) {
89
+ return since.exact === void 0 && since.time.getTime() === 0;
90
+ }
91
+ /** One page in `(unpositioned rows first, then (cursor, id))` order. */
92
+ async function keysetPage(since, limit, reads) {
93
+ if (since && !isNullGroup(since)) return await reads.values({
94
+ id: since.id,
95
+ literal: cursorLiteral(since)
96
+ }, limit);
97
+ const nulls = reads.nulls ? await reads.nulls(since?.id ?? null, limit) : [];
98
+ if (nulls.length >= limit) return nulls;
99
+ return [...nulls, ...await reads.values(null, limit - nulls.length)];
100
+ }
101
+ /**
102
+ * Move the exact-cursor alias off each row's visible keys, so the pushed row
103
+ * keeps its own (possibly NULL) cursor value. The position stays on the row,
104
+ * non-enumerable: the exact text, or the epoch for a row with no position.
105
+ */
106
+ function hideCursorAlias(rows) {
107
+ return rows.map((row) => {
108
+ if (!("__clivly_cursor__" in row)) return row;
109
+ const { [CURSOR_ALIAS]: exact, ...visible } = row;
110
+ if (typeof exact === "string" && exact.startsWith(UNSUPPORTED)) throw new Error(`clivly: the cursor column is ${exact.slice(12)}; a cursor must be a timestamp or timestamptz column.`);
111
+ if (exact === null || exact === void 0) Object.defineProperty(visible, require_sync.ROW_CURSOR_KEY, {
112
+ value: /* @__PURE__ */ new Date(0),
113
+ enumerable: false
114
+ });
115
+ else if (typeof exact === "string" && require_sync.isExactCursorTime(exact)) Object.defineProperty(visible, require_sync.ROW_EXACT_CURSOR_KEY, {
116
+ value: exact,
117
+ enumerable: false
118
+ });
119
+ return visible;
120
+ });
121
+ }
122
+ /**
123
+ * The `KeysetReads` of a raw-SQL source (`fromSql`, `fromSqlProjection`) over
124
+ * a timestamp cursor: the same predicates and order for both.
125
+ */
126
+ function sqlKeysetReads(cursor, id, nullable, page) {
127
+ const unpositioned = unpositionedPredicate(cursor, {
128
+ nullable,
129
+ timestamp: true
130
+ });
131
+ const order = `${cursor}, ${id}`;
132
+ return {
133
+ ...unpositioned === null ? {} : { nulls: (afterId, n) => afterId === null ? page(unpositioned, id, [], n) : page(`${unpositioned} AND ${id} > $1`, id, [afterId], n) },
134
+ values: (after, n) => after ? page(`(${cursor}, ${id}) > (${after.literal}, $1) AND ${cursor} >= ${after.literal} AND ${cursor} < 'infinity'`, order, [after.id], n) : page(positionedPredicate(cursor, { timestamp: true }), order, [], n)
135
+ };
136
+ }
137
+ // ../sdk/src/sql/from-sql.ts
138
+ const DEFAULT_CURSOR_COLUMN = "updated_at";
139
+ /**
140
+ * Whether `table` is Supabase's `auth.users`; throws for any other `auth.*`
141
+ * table, which holds sessions, tokens or identities and is never read.
142
+ */
143
+ function authUsersOrRefuse(label, table) {
144
+ const kind = require_sync.authTableKind(table);
145
+ if (kind === "other") throw new Error(`${label}: "${table}" is in the auth schema and cannot be read — only ${require_sync.AUTH_USERS_TABLE} is exposed.`);
146
+ return kind === "users";
147
+ }
148
+ const META_COLUMN = "raw_user_meta_data";
149
+ const dialect = postgresDialect;
150
+ function inferIdField(meta, table) {
151
+ const primaryKeys = (meta.columnsMeta ?? []).filter((c) => c.isPrimaryKey);
152
+ const only = primaryKeys[0];
153
+ if (primaryKeys.length === 1 && only) return only.name;
154
+ const kind = primaryKeys.length === 0 ? "no" : "a composite";
155
+ throw new Error(`fromSql: table "${table}" has ${kind} single-column primary key — pass { idField } explicitly.`);
156
+ }
157
+ const quoteLiteral = (value) => `'${value.replaceAll("'", "''")}'`;
158
+ function narrowedMetaValue(columnSql) {
159
+ return `case when ${columnSql} is null then null else jsonb_strip_nulls(jsonb_build_object(${require_sync.AUTH_USERS_META_KEYS.map((key) => `${quoteLiteral(key)}, ${columnSql}->${quoteLiteral(key)}`).join(", ")})) end`;
160
+ }
161
+ function narrowedMetaExpression() {
162
+ const col = dialect.quoteIdent(META_COLUMN);
163
+ return `${narrowedMetaValue(col)} as ${col}`;
164
+ }
165
+ function selectItem(column, isAuthUsers) {
166
+ if (isAuthUsers && column === META_COLUMN) return narrowedMetaExpression();
167
+ return dialect.quoteIdent(column);
168
+ }
169
+ function normaliseValue(value) {
170
+ if (typeof value !== "bigint") return value;
171
+ const asNumber = Number(value);
172
+ return Number.isSafeInteger(asNumber) ? asNumber : value.toString();
173
+ }
174
+ function normaliseRows(rows) {
175
+ return rows.map((row) => {
176
+ const out = {};
177
+ for (const [key, value] of Object.entries(row)) out[key] = normaliseValue(value);
178
+ return out;
179
+ });
180
+ }
181
+ function resolveColumns(opts, isAuthUsers, required) {
182
+ if (isAuthUsers) return [...require_sync.AUTH_USERS_COLUMNS];
183
+ const base = opts.columns ?? opts.meta.columns;
184
+ return [.../* @__PURE__ */ new Set([...base, ...required])];
185
+ }
186
+ function assertColumn(meta, table, label, column) {
187
+ if (!meta.columns.includes(column)) throw new Error(`fromSql: ${label} "${column}" is not a column on "${table}".`);
188
+ }
189
+ function buildPredicate(opts, excludeAnonymous, keyset) {
190
+ const parts = [];
191
+ if (keyset) parts.push(keyset);
192
+ if (opts.where) parts.push(`(${opts.where})`);
193
+ if (excludeAnonymous) parts.push(`(${require_sync.isAnonymousFilter})`);
194
+ return parts.length === 0 ? "" : ` where ${parts.join(" and ")}`;
195
+ }
196
+ /**
197
+ * The id and cursor of every auth.users row leave the host, so each must be
198
+ * an allowlisted column, and never `raw_user_meta_data` (which is narrowed
199
+ * only when read as a field). `resolveColumns` ignores `required` for
200
+ * auth.users, so without this the cursor read would still reach the column.
201
+ */
202
+ function assertAuthUsersKey(option, column) {
203
+ if (column === void 0 || column !== META_COLUMN && require_sync.AUTH_USERS_COLUMNS.includes(column)) return;
204
+ throw new Error(`fromSql: ${option} "${column}" is not allowed; auth.users only allows ${require_sync.AUTH_USERS_COLUMNS.filter((c) => c !== META_COLUMN).join(", ")} as ${option}.`);
205
+ }
206
+ function fromSql(executor, opts) {
207
+ const { meta, table } = opts;
208
+ const isAuthUsers = authUsersOrRefuse("fromSql", table);
209
+ const excludeAnonymous = isAuthUsers && require_sync.filtersAnonymous(meta);
210
+ const idField = opts.idField ?? inferIdField(meta, table);
211
+ assertColumn(meta, table, "idField", idField);
212
+ const defaultMeta = meta.columnsMeta?.find((c) => c.name === DEFAULT_CURSOR_COLUMN);
213
+ const cursorField = opts.cursorField ?? (meta.columns.includes(DEFAULT_CURSOR_COLUMN) && isTimestampType(defaultMeta?.type) ? DEFAULT_CURSOR_COLUMN : void 0);
214
+ const cursorMeta = meta.columnsMeta?.find((c) => c.name === cursorField);
215
+ if (cursorField !== void 0) {
216
+ assertColumn(meta, table, "cursorField", cursorField);
217
+ assertTimestampCursor("fromSql", cursorField, cursorMeta?.type);
218
+ }
219
+ if (isAuthUsers) {
220
+ assertAuthUsersKey("idField", idField);
221
+ assertAuthUsersKey("cursorField", cursorField);
222
+ }
223
+ const cursorNullable = cursorMeta?.nullable !== false;
224
+ const columns = resolveColumns(opts, isAuthUsers, cursorField === void 0 ? [idField] : [cursorField, idField]);
225
+ const items = columns.map((c) => selectItem(c, isAuthUsers));
226
+ if (cursorField !== void 0) items.push(`${exactCursorRead(dialect.quoteIdent(cursorField))} as ${dialect.quoteIdent(CURSOR_ALIAS)}`);
227
+ const head = `select ${items.join(", ")} from ${dialect.quoteTableRef(table)}`;
228
+ const idSql = dialect.quoteIdent(idField);
229
+ const page = async (keyset, order, params, limit) => {
230
+ const all = [...params, limit];
231
+ const text = `${head}${buildPredicate(opts, excludeAnonymous, keyset)} order by ${order} limit ${dialect.param(all.length)}`;
232
+ return normaliseRows(await executor.query(text, all));
233
+ };
234
+ const fetchIdPage = async ({ afterId, limit }) => await page(afterId === null ? null : `${idSql} > ${dialect.param(1)}`, idSql, afterId === null ? [] : [afterId], limit);
235
+ const fetchPage = async ({ since, limit }) => {
236
+ if (cursorField === void 0) return await fetchIdPage({
237
+ afterId: since?.id ?? null,
238
+ limit
239
+ });
240
+ return hideCursorAlias(await keysetPage(since, limit, sqlKeysetReads(dialect.quoteIdent(cursorField), idSql, cursorNullable, page)));
241
+ };
242
+ const source = {
243
+ entity: opts.entity,
244
+ ...opts.pushSource === void 0 ? {} : { pushSource: opts.pushSource },
245
+ cursorField: cursorField ?? idField,
246
+ idField,
247
+ ...cursorField === void 0 ? { mode: "full" } : {},
248
+ fetchPage,
249
+ fetchIdPage,
250
+ ...opts.objectType === void 0 ? {} : { objectType: opts.objectType }
251
+ };
252
+ const sourceMeta = {
253
+ kind: "sql",
254
+ columnKeys: columns,
255
+ columnsMeta: meta.columnsMeta,
256
+ cursorField: cursorField ?? idField,
257
+ idField,
258
+ tableName: table,
259
+ ...meta.uniqueConstraints === void 0 ? {} : { uniqueConstraints: meta.uniqueConstraints }
260
+ };
261
+ Object.defineProperty(source, require_sync.DRIZZLE_META, {
262
+ value: sourceMeta,
263
+ enumerable: false
264
+ });
265
+ return source;
266
+ }
267
+ /**
268
+ * Whether `fromSql` would sync at least one row for `table`: one
269
+ * `exists(... limit 1)` under `buildPredicate`, the predicate every page query
270
+ * uses, so the `auth.users` anonymous exclusion cannot drift. The projection
271
+ * path (`baseGuard` in projection.ts) applies the same `isAnonymousFilter`;
272
+ * keep the two in step. A boolean on purpose: `/clivly/connect` is a public GET,
273
+ * so it must not reveal how many users exist or run a full count.
274
+ */
275
+ async function existsFromSql(executor, opts) {
276
+ const isAuthUsers = authUsersOrRefuse("existsFromSql", opts.table);
277
+ const predicate = buildPredicate({ where: opts.where }, isAuthUsers && opts.filterAnonymous !== false, null);
278
+ const text = `select exists(select 1 from ${dialect.quoteTableRef(opts.table)}${predicate} limit 1) as present`;
279
+ const [row] = await executor.query(text, []);
280
+ return row?.present === true;
281
+ }
282
+ Object.defineProperty(exports, "CURSOR_ALIAS", {
283
+ enumerable: true,
284
+ get: function() {
285
+ return CURSOR_ALIAS;
286
+ }
287
+ });
288
+ Object.defineProperty(exports, "EXACT_FORMAT", {
289
+ enumerable: true,
290
+ get: function() {
291
+ return EXACT_FORMAT;
292
+ }
293
+ });
294
+ Object.defineProperty(exports, "exactCursorRead", {
295
+ enumerable: true,
296
+ get: function() {
297
+ return exactCursorRead;
298
+ }
299
+ });
300
+ Object.defineProperty(exports, "existsFromSql", {
301
+ enumerable: true,
302
+ get: function() {
303
+ return existsFromSql;
304
+ }
305
+ });
306
+ Object.defineProperty(exports, "fromSql", {
307
+ enumerable: true,
308
+ get: function() {
309
+ return fromSql;
310
+ }
311
+ });
312
+ Object.defineProperty(exports, "hideCursorAlias", {
313
+ enumerable: true,
314
+ get: function() {
315
+ return hideCursorAlias;
316
+ }
317
+ });
318
+ Object.defineProperty(exports, "keysetPage", {
319
+ enumerable: true,
320
+ get: function() {
321
+ return keysetPage;
322
+ }
323
+ });
324
+ Object.defineProperty(exports, "narrowedMetaValue", {
325
+ enumerable: true,
326
+ get: function() {
327
+ return narrowedMetaValue;
328
+ }
329
+ });
330
+ Object.defineProperty(exports, "normaliseRows", {
331
+ enumerable: true,
332
+ get: function() {
333
+ return normaliseRows;
334
+ }
335
+ });
336
+ Object.defineProperty(exports, "postgresDialect", {
337
+ enumerable: true,
338
+ get: function() {
339
+ return postgresDialect;
340
+ }
341
+ });
342
+ Object.defineProperty(exports, "sqlKeysetReads", {
343
+ enumerable: true,
344
+ get: function() {
345
+ return sqlKeysetReads;
346
+ }
347
+ });
@@ -1,6 +1,5 @@
1
- import { C as NamespaceIntrospector, b as SyncSource, t as AppIdStore } from "./types-UR-tT4c1.cjs";
2
- import { R as ProjectionMapping, m as DiscoveredSchemaTable, z as ProjectionRef } from "./entity-config-CXpGowQa.cjs";
3
- import "./index-uFDiQEjj.cjs";
1
+ import { m as DiscoveredSchemaTable } from "./entity-config-CXpGowQa.mjs";
2
+ import { x as SyncSource } from "./namespace-probe-CUR2zG2l.mjs";
4
3
  /** The one raw-SQL seam: every host driver is adapted to this. */
5
4
  interface SqlExecutor {
6
5
  query(text: string, params?: readonly unknown[]): Promise<Record<string, unknown>[]>;
@@ -24,24 +23,6 @@ declare function connectPostgresJs(url: string, postgres: (url: string, opts: {
24
23
  prepare: false;
25
24
  max: number;
26
25
  }) => unknown): SqlExecutor;
27
- /**
28
- * The raw-SQL twin of `drizzleAppIdStore`: an `AppIdStore` backed by a
29
- * one-row `crm_clivly_app` table, created on first use. The only write Clivly
30
- * ever makes to a host database.
31
- */
32
- declare function sqlAppIdStore(executor: SqlExecutor): AppIdStore;
33
- interface DiscoverFromSqlOptions {
34
- /** Defaults to `[current_schema()]`. */
35
- includeAuthUsers?: boolean;
36
- schemas?: string[];
37
- }
38
- /**
39
- * The raw-SQL twin of `discoverFromDrizzle`: reads Postgres catalogs and
40
- * returns the same `DiscoveredSchemaTable[]` shape. Names are unqualified in
41
- * the default schema and `schema.table` elsewhere. `auth.users` is reported
42
- * with only its allowlisted columns; every other `auth.*` table is omitted.
43
- */
44
- declare function discoverFromSql(executor: SqlExecutor, opts?: DiscoverFromSqlOptions): Promise<DiscoveredSchemaTable[]>;
45
26
  interface FromSqlOptions {
46
27
  /** Columns to read; defaults to every column. Ignored for `auth.users`. */
47
28
  columns?: string[];
@@ -78,31 +59,12 @@ declare function fromSql(executor: SqlExecutor, opts: FromSqlOptions): SyncSourc
78
59
  * so it must not reveal how many users exist or run a full count.
79
60
  */
80
61
  declare function existsFromSql(executor: SqlExecutor, opts: {
62
+ /**
63
+ * False when `auth.users` has no `is_anonymous` column: pass
64
+ * `filtersAnonymous(meta)` for discovery's entry. Defaults to true.
65
+ */
66
+ filterAnonymous?: boolean;
81
67
  table: string;
82
68
  where?: string;
83
69
  }): Promise<boolean>;
84
- /**
85
- * The raw-SQL twin of `drizzleIntrospector`, for apps with no ORM.
86
- * Read-only: every statement here is a SELECT.
87
- */
88
- declare function sqlIntrospector(executor: SqlExecutor): NamespaceIntrospector;
89
- interface FromSqlProjectionOptions {
90
- /** The base table's primary key, for a `base_pk` identity with no column. */
91
- basePkColumn?: string;
92
- /**
93
- * The column to keyset-paginate on, as a ref token (`"base.updated_at"`) or
94
- * a `ProjectionRef`. Omit it to page by identity alone (full snapshot).
95
- */
96
- cursorField?: string | ProjectionRef;
97
- entity: string;
98
- objectType: string;
99
- }
100
- /**
101
- * The raw-SQL twin of `fromDrizzleProjection`: a `SyncSource` that executes a
102
- * projection's joins. Rows are keyed by ref token. Read-only. Without a
103
- * `cursorField` it pages by identity and reports `mode: "full"`.
104
- */
105
- declare function fromSqlProjection(executor: SqlExecutor, projection: ProjectionMapping, opts: FromSqlProjectionOptions): SyncSource & {
106
- objectType: string;
107
- };
108
- export { discoverFromSql as a, connectPostgresJs as c, fromSql as i, pgExecutor as l, sqlIntrospector as n, sqlAppIdStore as o, existsFromSql as r, SqlExecutor as s, fromSqlProjection as t, postgresJsExecutor as u };
70
+ export { connectPostgresJs as a, SqlExecutor as i, existsFromSql as n, pgExecutor as o, fromSql as r, postgresJsExecutor as s, FromSqlOptions as t };
@@ -1,6 +1,5 @@
1
- import { n as AppIdStore, t as NamespaceIntrospector, x as SyncSource } from "./namespace-probe--GvxJ06J.mjs";
2
- import { R as ProjectionMapping, m as DiscoveredSchemaTable, z as ProjectionRef } from "./entity-config-CXpGowQa.mjs";
3
- import "./index-DOoX2GgI.mjs";
1
+ import { m as DiscoveredSchemaTable } from "./entity-config-CXpGowQa.cjs";
2
+ import { b as SyncSource } from "./types-CzL7lUH9.cjs";
4
3
  /** The one raw-SQL seam: every host driver is adapted to this. */
5
4
  interface SqlExecutor {
6
5
  query(text: string, params?: readonly unknown[]): Promise<Record<string, unknown>[]>;
@@ -24,24 +23,6 @@ declare function connectPostgresJs(url: string, postgres: (url: string, opts: {
24
23
  prepare: false;
25
24
  max: number;
26
25
  }) => unknown): SqlExecutor;
27
- /**
28
- * The raw-SQL twin of `drizzleAppIdStore`: an `AppIdStore` backed by a
29
- * one-row `crm_clivly_app` table, created on first use. The only write Clivly
30
- * ever makes to a host database.
31
- */
32
- declare function sqlAppIdStore(executor: SqlExecutor): AppIdStore;
33
- interface DiscoverFromSqlOptions {
34
- /** Defaults to `[current_schema()]`. */
35
- includeAuthUsers?: boolean;
36
- schemas?: string[];
37
- }
38
- /**
39
- * The raw-SQL twin of `discoverFromDrizzle`: reads Postgres catalogs and
40
- * returns the same `DiscoveredSchemaTable[]` shape. Names are unqualified in
41
- * the default schema and `schema.table` elsewhere. `auth.users` is reported
42
- * with only its allowlisted columns; every other `auth.*` table is omitted.
43
- */
44
- declare function discoverFromSql(executor: SqlExecutor, opts?: DiscoverFromSqlOptions): Promise<DiscoveredSchemaTable[]>;
45
26
  interface FromSqlOptions {
46
27
  /** Columns to read; defaults to every column. Ignored for `auth.users`. */
47
28
  columns?: string[];
@@ -78,31 +59,12 @@ declare function fromSql(executor: SqlExecutor, opts: FromSqlOptions): SyncSourc
78
59
  * so it must not reveal how many users exist or run a full count.
79
60
  */
80
61
  declare function existsFromSql(executor: SqlExecutor, opts: {
62
+ /**
63
+ * False when `auth.users` has no `is_anonymous` column: pass
64
+ * `filtersAnonymous(meta)` for discovery's entry. Defaults to true.
65
+ */
66
+ filterAnonymous?: boolean;
81
67
  table: string;
82
68
  where?: string;
83
69
  }): Promise<boolean>;
84
- /**
85
- * The raw-SQL twin of `drizzleIntrospector`, for apps with no ORM.
86
- * Read-only: every statement here is a SELECT.
87
- */
88
- declare function sqlIntrospector(executor: SqlExecutor): NamespaceIntrospector;
89
- interface FromSqlProjectionOptions {
90
- /** The base table's primary key, for a `base_pk` identity with no column. */
91
- basePkColumn?: string;
92
- /**
93
- * The column to keyset-paginate on, as a ref token (`"base.updated_at"`) or
94
- * a `ProjectionRef`. Omit it to page by identity alone (full snapshot).
95
- */
96
- cursorField?: string | ProjectionRef;
97
- entity: string;
98
- objectType: string;
99
- }
100
- /**
101
- * The raw-SQL twin of `fromDrizzleProjection`: a `SyncSource` that executes a
102
- * projection's joins. Rows are keyed by ref token. Read-only. Without a
103
- * `cursorField` it pages by identity and reports `mode: "full"`.
104
- */
105
- declare function fromSqlProjection(executor: SqlExecutor, projection: ProjectionMapping, opts: FromSqlProjectionOptions): SyncSource & {
106
- objectType: string;
107
- };
108
- export { discoverFromSql as a, connectPostgresJs as c, fromSql as i, pgExecutor as l, sqlIntrospector as n, sqlAppIdStore as o, existsFromSql as r, SqlExecutor as s, fromSqlProjection as t, postgresJsExecutor as u };
70
+ export { connectPostgresJs as a, SqlExecutor as i, existsFromSql as n, pgExecutor as o, fromSql as r, postgresJsExecutor as s, FromSqlOptions as t };
@@ -0,0 +1,134 @@
1
+ import { n as AppIdStore, t as NamespaceIntrospector, x as SyncSource } from "./namespace-probe-CUR2zG2l.mjs";
2
+ import { i as SqlExecutor } from "./from-sql-CpGP7K3J.mjs";
3
+ import { R as ProjectionMapping, m as DiscoveredSchemaTable, z as ProjectionRef } from "./entity-config-CXpGowQa.mjs";
4
+ import "./index-DOoX2GgI.mjs";
5
+ /**
6
+ * The raw-SQL twin of `drizzleAppIdStore`: an `AppIdStore` backed by a
7
+ * one-row `crm_clivly_app` table, created on first use. The only write Clivly
8
+ * ever makes to a host database.
9
+ */
10
+ declare function sqlAppIdStore(executor: SqlExecutor): AppIdStore;
11
+ interface DiscoverFromSqlOptions {
12
+ /** Defaults to `[current_schema()]`. */
13
+ includeAuthUsers?: boolean;
14
+ schemas?: string[];
15
+ }
16
+ /**
17
+ * The raw-SQL twin of `discoverFromDrizzle`: reads Postgres catalogs and
18
+ * returns the same `DiscoveredSchemaTable[]` shape. Names are unqualified in
19
+ * the default schema and `schema.table` elsewhere. `auth.users` is reported
20
+ * with only its allowlisted columns; every other `auth.*` table is omitted.
21
+ */
22
+ declare function discoverFromSql(executor: SqlExecutor, opts?: DiscoverFromSqlOptions): Promise<DiscoveredSchemaTable[]>;
23
+ /**
24
+ * The raw-SQL twin of `drizzleIntrospector`, for apps with no ORM.
25
+ * Read-only: every statement here is a SELECT.
26
+ */
27
+ declare function sqlIntrospector(executor: SqlExecutor): NamespaceIntrospector;
28
+ interface FromSqlProjectionOptions {
29
+ /** The base table's primary key, for a `base_pk` identity with no column. */
30
+ basePkColumn?: string;
31
+ /**
32
+ * A cursor computed from several columns, in place of `cursorField`. For
33
+ * the SDK's own sources only (the Supabase contact source pages on the
34
+ * later of two stamps): the SQL is trusted and inlined, never built from a
35
+ * cloud-authored projection. Every ref it reads must be listed in `refs`,
36
+ * which are checked like any other ref.
37
+ */
38
+ cursorExpression?: CursorExpression;
39
+ /**
40
+ * The column to keyset-paginate on, as a ref token (`"base.updated_at"`) or
41
+ * a `ProjectionRef`. Omit it to page by identity alone (full snapshot).
42
+ */
43
+ cursorField?: string | ProjectionRef;
44
+ /**
45
+ * False when the cursor column is NOT NULL (and on the base table, or an
46
+ * inner join), which skips the read of NULL-cursor rows. A projection
47
+ * carries no column metadata, so it defaults to true.
48
+ */
49
+ cursorNullable?: boolean;
50
+ entity: string;
51
+ /**
52
+ * False when `auth.users` has no `is_anonymous` column (Supabase Auth
53
+ * before 2024): pass `filtersAnonymous(meta)` for discovery's entry.
54
+ * Defaults to true, which excludes anonymous sign-ins.
55
+ */
56
+ excludeAnonymous?: boolean;
57
+ objectType: string;
58
+ }
59
+ interface CursorExpression {
60
+ /**
61
+ * The value pushed under `field`; may be NULL. Defaults to `order`. Cast
62
+ * to timestamptz and read back as UTC, as a column cursor's is.
63
+ */
64
+ display?: string;
65
+ /** The key the pushed value is written under: the source's `cursorField`. */
66
+ field: string;
67
+ /** False when `order` can never be NULL, which skips the NULL-cursor read. */
68
+ nullable: boolean;
69
+ /**
70
+ * What rows are ordered, compared and positioned on. Must evaluate to one
71
+ * type (cast a `timestamp` to `timestamptz`, which reads it in the
72
+ * session's TimeZone, before mixing the two). Inlined, parenthesised,
73
+ * everywhere.
74
+ */
75
+ order: string;
76
+ /** Every column the expressions read. */
77
+ refs: ProjectionRef[];
78
+ }
79
+ /**
80
+ * The raw-SQL twin of `fromDrizzleProjection`: a `SyncSource` that executes a
81
+ * projection's joins. Rows are keyed by ref token. Read-only. Without a
82
+ * `cursorField` it pages by identity and reports `mode: "full"`.
83
+ */
84
+ declare function fromSqlProjection(executor: SqlExecutor, projection: ProjectionMapping, opts: FromSqlProjectionOptions): SyncSource & {
85
+ objectType: string;
86
+ };
87
+ /**
88
+ * Whether reads of `auth.users` should exclude anonymous sign-ins. False only
89
+ * when discovery saw no `is_anonymous` column (Supabase Auth before 2024, so
90
+ * no anonymous sign-ins exist to exclude): filtering on it there would fail
91
+ * every page with "column does not exist". A table entry discovery did not
92
+ * build (no mark) still filters, the safe default.
93
+ */
94
+ declare function filtersAnonymous(table: DiscoveredSchemaTable | undefined): boolean;
95
+ /**
96
+ * The flat column every Supabase contact row carries for the person's name:
97
+ * the profile's `full_name` (or `name`) when `public.profiles` joins, else
98
+ * `raw_user_meta_data.full_name` (or `.name`). Map a contact's `name` to it.
99
+ */
100
+ declare const SUPABASE_CONTACT_NAME_COLUMN = "full_name";
101
+ interface SupabaseContactOptions {
102
+ /**
103
+ * The cursor-store key and push label. Defaults to the table name, which is
104
+ * what a declared entity's `source:` and a preview's draft name match.
105
+ */
106
+ entity?: string;
107
+ /** False skips the `public.profiles` join even when it qualifies. */
108
+ joinProfiles?: boolean;
109
+ /** The contact table. Defaults to `auth.users`. */
110
+ table?: string;
111
+ }
112
+ interface SupabaseContactSource {
113
+ /**
114
+ * The schema to hand the SDK: the input, with the contact table advertising
115
+ * the flat shape its rows are pushed in (profile columns, `full_name`).
116
+ */
117
+ schema: DiscoveredSchemaTable[];
118
+ source: SyncSource;
119
+ /** The contact table every push and the heartbeat name. */
120
+ table: string;
121
+ }
122
+ /** The contact table named in options is not in the discovered schema. */
123
+ declare class ContactTableMissing extends Error {
124
+ constructor(table: string);
125
+ }
126
+ /**
127
+ * The contact source for a Supabase app, from `discoverFromSql`'s tables.
128
+ * `auth.users` (the default) joins `public.profiles` on `id` when that table
129
+ * qualifies, and every row carries a flat `full_name` (see
130
+ * `SUPABASE_CONTACT_NAME_COLUMN`). Any other table is read as-is by `fromSql`.
131
+ * Throws `ContactTableMissing` when the table is not in `tables`.
132
+ */
133
+ declare function supabaseContactSource(executor: SqlExecutor, tables: DiscoveredSchemaTable[], opts?: SupabaseContactOptions): SupabaseContactSource;
134
+ export { supabaseContactSource as a, sqlIntrospector as c, SupabaseContactSource as i, discoverFromSql as l, SUPABASE_CONTACT_NAME_COLUMN as n, filtersAnonymous as o, SupabaseContactOptions as r, fromSqlProjection as s, ContactTableMissing as t, sqlAppIdStore as u };