clivly 0.23.0 → 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 +36 -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,508 @@
1
+ const require_entity_heuristics = require("./entity-heuristics-DNmrcd0b.cjs");
2
+ // ../sdk/src/sql/supabase-auth-users.ts
3
+ /**
4
+ * The one Supabase `auth` table Clivly may read, and exactly how much of it.
5
+ * Every other `auth.*` table is refused; secrets (`encrypted_password`,
6
+ * tokens, `raw_app_meta_data`) are never in this list.
7
+ */
8
+ const AUTH_USERS_TABLE = "auth.users";
9
+ const AUTH_USERS_COLUMNS = [
10
+ "id",
11
+ "email",
12
+ "phone",
13
+ "created_at",
14
+ "updated_at",
15
+ "last_sign_in_at",
16
+ "raw_user_meta_data"
17
+ ];
18
+ /** `raw_user_meta_data` is narrowed to these keys at read time. */
19
+ const AUTH_USERS_META_KEYS = [
20
+ "full_name",
21
+ "name",
22
+ "avatar_url"
23
+ ];
24
+ /** Anonymous sign-ins are not customers. */
25
+ const isAnonymousFilter = "coalesce(is_anonymous, false) = false";
26
+ const QUOTES = /"/g;
27
+ /**
28
+ * Whether a projection table name points into Supabase's `auth` schema, and if
29
+ * so whether it is the one table Clivly may read. Case-insensitive and blind to
30
+ * quotes and padding, so no spelling of a refused table slips through.
31
+ */
32
+ function authTableKind(name) {
33
+ const normal = name.replace(QUOTES, "").trim().toLowerCase();
34
+ if (!normal.startsWith("auth.")) return null;
35
+ return normal === "auth.users" ? "users" : "other";
36
+ }
37
+ // ../sdk/src/entity-source.ts
38
+ const CONCEPT_KEYS = {
39
+ contact: "contacts",
40
+ company: "companies",
41
+ deal: "deals"
42
+ };
43
+ function resolveEntitySource(config, entityKey) {
44
+ const entity = config.entities?.entities?.[entityKey];
45
+ const src = config.source;
46
+ if (!(entity && src)) return null;
47
+ const conceptKey = CONCEPT_KEYS[entity.concept];
48
+ if (conceptKey) {
49
+ const source = src[conceptKey];
50
+ return source ? {
51
+ concept: entity.concept,
52
+ expectedKey: conceptKey,
53
+ source
54
+ } : null;
55
+ }
56
+ if (entity.concept === "custom") {
57
+ const match = (src.custom ?? []).find((c) => c.entity === entity.source || c.entity === entityKey);
58
+ return match ? {
59
+ concept: "custom",
60
+ expectedKey: "custom",
61
+ source: match
62
+ } : null;
63
+ }
64
+ return null;
65
+ }
66
+ /** The `config.source` key an entity's concept requires, present or not. */
67
+ function expectedSourceKey(concept) {
68
+ return CONCEPT_KEYS[concept] ?? "custom";
69
+ }
70
+ /**
71
+ * The `source` label a push must carry for the server to find its mapping.
72
+ *
73
+ * `entity` is the SDK's own name for a source — the cursor-store key, and what
74
+ * the developer wrote in `config.source`. It is NOT always what the server
75
+ * filed the mapping under: for a projection, `ensureSchema` stores
76
+ * `sourceTable` as `projection.baseTable`, because a projection entity's key
77
+ * doubles as a kebab-case object slug and cannot also be the snake_case
78
+ * `projection.entityKey`.
79
+ *
80
+ * Pushing under `entity` therefore dropped 100% of a projection's rows while
81
+ * every local signal said the setup was correct. One function so the three
82
+ * push sites cannot drift apart again.
83
+ */
84
+ function pushSourceOf(source) {
85
+ return source.pushSource ?? source.entity;
86
+ }
87
+ /**
88
+ * The push label for a custom source, resolved against the config.
89
+ *
90
+ * `fromDrizzleProjection` stamps `pushSource` itself, but a projection source
91
+ * can equally be hand-built — `fromDrizzle` with an overridden `fetchPage` is
92
+ * what the README's own example leads you to, and next-finance did exactly
93
+ * that. Such a source has no `pushSource`, so the label has to come from the
94
+ * one place that is true either way: the entity's declared
95
+ * `projection.baseTable`.
96
+ *
97
+ * Matched on the source's `entity`, which for a custom source is also the
98
+ * config entity key (that is what `resolveEntitySource` above pairs them by).
99
+ * Falls back to `pushSourceOf`, so a non-projection custom source and an
100
+ * already-stamped one both keep their current label.
101
+ */
102
+ function customPushSource(config, source) {
103
+ if (source.pushSource) return source.pushSource;
104
+ const entities = config.entities?.entities;
105
+ return (entities?.[source.entity] ?? Object.values(entities ?? {}).find((e) => e.source === source.entity))?.projection?.baseTable ?? source.entity;
106
+ }
107
+ // ../sdk/src/sync.ts
108
+ const DEFAULT_ID_FIELD = "id";
109
+ /**
110
+ * Non-enumerable key a source may set on a row to give its position when the
111
+ * row's own cursor column is NULL (so it is never serialised or pushed).
112
+ * `nextCursor` falls back to it only where the column itself is null.
113
+ */
114
+ const ROW_CURSOR_KEY = "__clivly_row_cursor__";
115
+ function isAfter(candidate, current) {
116
+ const ct = candidate.time.getTime();
117
+ const bt = current.time.getTime();
118
+ if (ct !== bt) return ct > bt;
119
+ return candidate.id > current.id;
120
+ }
121
+ function nextCursor(rows, cursorField, idField, current) {
122
+ let max = current;
123
+ for (const row of rows) {
124
+ const raw = row[cursorField] ?? row["__clivly_row_cursor__"];
125
+ if (raw === null || raw === void 0) continue;
126
+ const time = raw instanceof Date ? raw : new Date(String(raw));
127
+ if (Number.isNaN(time.getTime())) continue;
128
+ const idRaw = row[idField];
129
+ const candidate = {
130
+ time,
131
+ id: idRaw === null || idRaw === void 0 ? "" : String(idRaw)
132
+ };
133
+ if (!max || isAfter(candidate, max)) max = candidate;
134
+ }
135
+ return max;
136
+ }
137
+ function idOnlyCursor(rows, idField, current) {
138
+ const raw = rows.at(-1)?.[idField];
139
+ if (raw === null || raw === void 0) return current;
140
+ return {
141
+ id: String(raw),
142
+ time: /* @__PURE__ */ new Date(0)
143
+ };
144
+ }
145
+ const CREATED_AT_CANDIDATES = [
146
+ "created_at",
147
+ "createdAt",
148
+ "inserted_at",
149
+ "insertedAt",
150
+ "signed_up_at",
151
+ "signedUpAt",
152
+ "joined_at",
153
+ "joinedAt"
154
+ ];
155
+ /**
156
+ * Which columns of these rows hold their times: the cursor column (it moves
157
+ * when a row changes) and the creation column, configured or detected from
158
+ * the rows' own keys. A creation column the rows do not carry is left out.
159
+ */
160
+ function sourceTimeFields(source, rows) {
161
+ const first = rows[0] ?? {};
162
+ const createdAt = source.createdAtField ?? CREATED_AT_CANDIDATES.find((column) => column in first);
163
+ return createdAt === void 0 ? { updatedAt: source.cursorField } : {
164
+ updatedAt: source.cursorField,
165
+ createdAt
166
+ };
167
+ }
168
+ function toWireCursor(cursor) {
169
+ return {
170
+ id: cursor.id,
171
+ time: cursor.time.toISOString()
172
+ };
173
+ }
174
+ /**
175
+ * Read the positions Clivly sent with a triggered sync. Anything malformed is
176
+ * dropped, so that source falls back to the app's own cursor store.
177
+ */
178
+ function parseWireCursors(value) {
179
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return;
180
+ const out = {};
181
+ for (const [entity, raw] of Object.entries(value)) {
182
+ if (raw === null || typeof raw !== "object") continue;
183
+ const { id, time } = raw;
184
+ if (typeof id !== "string" || typeof time !== "string") continue;
185
+ const parsed = new Date(time);
186
+ if (!Number.isNaN(parsed.getTime())) out[entity] = {
187
+ id,
188
+ time: parsed
189
+ };
190
+ }
191
+ return out;
192
+ }
193
+ function cursorReport(source, cursor, report) {
194
+ return report && cursor ? {
195
+ entity: source.entity,
196
+ nextCursor: toWireCursor(cursor)
197
+ } : {};
198
+ }
199
+ async function syncSource(args) {
200
+ const { source, path, since, batchSize, push, objectType, maxRows } = args;
201
+ const reportCursor = args.reportCursor ?? true;
202
+ const idField = source.idField ?? DEFAULT_ID_FIELD;
203
+ let cursor = since;
204
+ let pushed = 0;
205
+ const resumedFrom = since === null ? null : since.time.toISOString();
206
+ for (;;) {
207
+ const rows = await source.fetchPage({
208
+ since: cursor,
209
+ limit: batchSize
210
+ });
211
+ if (rows.length === 0) break;
212
+ const capped = maxRows === void 0 ? rows : rows.slice(0, maxRows);
213
+ const next = nextCursor(capped, source.cursorField, idField, cursor);
214
+ if (!await push(path, {
215
+ source: pushSourceOf(source),
216
+ rows: capped,
217
+ mode: "delta",
218
+ fetched: rows.length,
219
+ cursor: resumedFrom,
220
+ sourceFields: sourceTimeFields(source, capped),
221
+ ...cursorReport(source, next, reportCursor),
222
+ ...objectType ? { objectType } : {}
223
+ })) return {
224
+ pushed,
225
+ cursor,
226
+ ok: false
227
+ };
228
+ pushed += capped.length;
229
+ cursor = next;
230
+ if (maxRows !== void 0 || rows.length < batchSize) break;
231
+ }
232
+ return {
233
+ pushed,
234
+ cursor,
235
+ ok: true
236
+ };
237
+ }
238
+ async function fullSyncSource(args) {
239
+ const { source, path, batchSize, push, objectType } = args;
240
+ const reportCursor = args.reportCursor ?? true;
241
+ const idField = source.idField ?? DEFAULT_ID_FIELD;
242
+ const all = [];
243
+ let cursor = null;
244
+ for (;;) {
245
+ const rows = await source.fetchPage({
246
+ since: cursor,
247
+ limit: batchSize
248
+ });
249
+ if (rows.length === 0) break;
250
+ all.push(...rows);
251
+ const next = source.mode === "full" ? idOnlyCursor(rows, idField, cursor) : nextCursor(rows, source.cursorField, idField, cursor);
252
+ const stalled = next !== null && cursor !== null && next.time.getTime() === cursor.time.getTime() && next.id === cursor.id;
253
+ cursor = next;
254
+ if (rows.length < batchSize || stalled) break;
255
+ }
256
+ if (all.length === 0) return {
257
+ pushed: 0,
258
+ cursor: null,
259
+ ok: true
260
+ };
261
+ const ok = await push(path, {
262
+ source: pushSourceOf(source),
263
+ rows: all,
264
+ mode: "full",
265
+ fetched: all.length,
266
+ cursor: null,
267
+ sourceFields: sourceTimeFields(source, all),
268
+ ...cursorReport(source, cursor, reportCursor),
269
+ ...objectType ? { objectType } : {}
270
+ });
271
+ return {
272
+ pushed: ok ? all.length : 0,
273
+ cursor,
274
+ ok
275
+ };
276
+ }
277
+ // ../sdk/src/projection-guard.ts
278
+ /**
279
+ * Tables auth libraries keep live credentials in. Whole-table: their secrets
280
+ * sit in columns with generic names (`token`, `value`) that a column rule
281
+ * cannot single out. `user`, `member` and `organization` are not here — they
282
+ * are legitimate contact and company sources.
283
+ */
284
+ const CREDENTIAL_TABLES = /* @__PURE__ */ new Set([
285
+ "session",
286
+ "verification",
287
+ "two_factor",
288
+ "twofactor",
289
+ "passkey",
290
+ "apikey",
291
+ "api_key",
292
+ "jwks"
293
+ ]);
294
+ const BASE_ALIAS = "base";
295
+ const AUTH_USERS_ALLOWED = AUTH_USERS_COLUMNS;
296
+ /**
297
+ * Supabase's `auth` schema: only `auth.users`, and only its allowlisted
298
+ * columns. `allowSensitive` never widens this.
299
+ */
300
+ function authTableError(table) {
301
+ return authTableKind(table) === "other" ? `Table "${table}" is in Supabase's auth schema and is never synced; only auth.users is readable.` : null;
302
+ }
303
+ function normalise(name) {
304
+ return name.toLowerCase().replaceAll("-", "_");
305
+ }
306
+ /** Every (table, column) a projection reads, with join aliases resolved. */
307
+ function readColumns(projection) {
308
+ const tableOf = /* @__PURE__ */ new Map([[BASE_ALIAS, projection.baseTable]]);
309
+ for (const join of projection.joins) tableOf.set(join.key, join.table);
310
+ const refs = [];
311
+ for (const join of projection.joins) for (const condition of join.on) refs.push(condition.left, condition.right);
312
+ for (const binding of Object.values(projection.fieldBindings)) refs.push(binding.from);
313
+ const { identity } = projection;
314
+ if (identity.kind === "column") refs.push(identity.from);
315
+ else if (identity.kind === "composite") refs.push(...identity.parts);
316
+ else if (identity.column) refs.push({
317
+ table: BASE_ALIAS,
318
+ column: identity.column
319
+ });
320
+ return refs.map((ref) => ({
321
+ table: tableOf.get(ref.table) ?? ref.table,
322
+ column: ref.column
323
+ }));
324
+ }
325
+ function referencedTables(projection) {
326
+ return [projection.baseTable, ...projection.joins.map((join) => join.table)];
327
+ }
328
+ /** Thrown where a projection is refused outside the route-level checks. */
329
+ var ProjectionRefusedError = class extends Error {
330
+ reasons;
331
+ constructor(reasons) {
332
+ super(`projection refused: ${reasons.join("; ")}`);
333
+ this.name = "ProjectionRefusedError";
334
+ this.reasons = reasons;
335
+ }
336
+ };
337
+ /**
338
+ * Only the unconditional Supabase `auth.*` rule: no other auth table, and only
339
+ * the allowlisted `auth.users` columns. No policy can widen it, so it needs no
340
+ * options and the raw-SQL sources can enforce it on their own.
341
+ */
342
+ function authExposureErrors(projection) {
343
+ const errors = [];
344
+ for (const table of referencedTables(projection)) {
345
+ const authError = authTableError(table);
346
+ if (authError) errors.push(authError);
347
+ }
348
+ for (const { table, column } of readColumns(projection)) if (authTableKind(table) === "users" && !AUTH_USERS_ALLOWED.includes(column)) errors.push(`Column "${table}.${column}" is not exposed; auth.users only exposes ${AUTH_USERS_COLUMNS.join(", ")}.`);
349
+ return [...new Set(errors)];
350
+ }
351
+ /** Why this projection may not run here; empty when it may. */
352
+ function projectionExposureErrors(projection, policy = {}) {
353
+ const allowed = new Set((policy.allowSensitive ?? []).map(normalise));
354
+ const errors = [];
355
+ for (const table of referencedTables(projection)) {
356
+ const authError = authTableError(table);
357
+ if (authError) errors.push(authError);
358
+ if (CREDENTIAL_TABLES.has(normalise(table)) && !allowed.has(normalise(`${table}.*`))) errors.push(`Table "${table}" holds credentials and is never synced.`);
359
+ if (policy.tables && !(table in policy.tables)) errors.push(`Table "${table}" is not in this app's exposure.tables allowlist.`);
360
+ }
361
+ for (const { table, column } of readColumns(projection)) {
362
+ const ref = `${table}.${column}`;
363
+ if (authTableKind(table) === "users" && !AUTH_USERS_ALLOWED.includes(column)) {
364
+ errors.push(`Column "${ref}" is not exposed; auth.users only exposes ${AUTH_USERS_COLUMNS.join(", ")}.`);
365
+ continue;
366
+ }
367
+ if (require_entity_heuristics.isSensitiveColumn(column) && !allowed.has(normalise(ref))) errors.push(`Column "${ref}" looks like a credential and is never synced. List it in exposure.allowSensitive if it is safe.`);
368
+ const columns = policy.tables?.[table];
369
+ if (Array.isArray(columns) && !columns.includes(column)) errors.push(`Column "${ref}" is not in this app's exposure.tables allowlist.`);
370
+ }
371
+ return [...new Set(errors)];
372
+ }
373
+ /** Drop credential columns, and columns outside the allowlist, from a raw-row preview. */
374
+ function exposableColumns(table, columns, policy = {}) {
375
+ const allowed = new Set((policy.allowSensitive ?? []).map(normalise));
376
+ const result = /* @__PURE__ */ new Set();
377
+ const authKind = authTableKind(table);
378
+ if (authKind === "other") return result;
379
+ if (CREDENTIAL_TABLES.has(normalise(table)) && !allowed.has(normalise(`${table}.*`)) || policy.tables !== void 0 && !(table in policy.tables)) return result;
380
+ const listed = policy.tables?.[table];
381
+ for (const column of columns) {
382
+ if (authKind === "users" && !AUTH_USERS_ALLOWED.includes(column)) continue;
383
+ if (require_entity_heuristics.isSensitiveColumn(column) && !allowed.has(normalise(`${table}.${column}`))) continue;
384
+ if (Array.isArray(listed) && !listed.includes(column)) continue;
385
+ result.add(column);
386
+ }
387
+ return result;
388
+ }
389
+ Object.defineProperty(exports, "AUTH_USERS_COLUMNS", {
390
+ enumerable: true,
391
+ get: function() {
392
+ return AUTH_USERS_COLUMNS;
393
+ }
394
+ });
395
+ Object.defineProperty(exports, "AUTH_USERS_META_KEYS", {
396
+ enumerable: true,
397
+ get: function() {
398
+ return AUTH_USERS_META_KEYS;
399
+ }
400
+ });
401
+ Object.defineProperty(exports, "AUTH_USERS_TABLE", {
402
+ enumerable: true,
403
+ get: function() {
404
+ return AUTH_USERS_TABLE;
405
+ }
406
+ });
407
+ Object.defineProperty(exports, "ProjectionRefusedError", {
408
+ enumerable: true,
409
+ get: function() {
410
+ return ProjectionRefusedError;
411
+ }
412
+ });
413
+ Object.defineProperty(exports, "ROW_CURSOR_KEY", {
414
+ enumerable: true,
415
+ get: function() {
416
+ return ROW_CURSOR_KEY;
417
+ }
418
+ });
419
+ Object.defineProperty(exports, "authExposureErrors", {
420
+ enumerable: true,
421
+ get: function() {
422
+ return authExposureErrors;
423
+ }
424
+ });
425
+ Object.defineProperty(exports, "authTableKind", {
426
+ enumerable: true,
427
+ get: function() {
428
+ return authTableKind;
429
+ }
430
+ });
431
+ Object.defineProperty(exports, "customPushSource", {
432
+ enumerable: true,
433
+ get: function() {
434
+ return customPushSource;
435
+ }
436
+ });
437
+ Object.defineProperty(exports, "expectedSourceKey", {
438
+ enumerable: true,
439
+ get: function() {
440
+ return expectedSourceKey;
441
+ }
442
+ });
443
+ Object.defineProperty(exports, "exposableColumns", {
444
+ enumerable: true,
445
+ get: function() {
446
+ return exposableColumns;
447
+ }
448
+ });
449
+ Object.defineProperty(exports, "fullSyncSource", {
450
+ enumerable: true,
451
+ get: function() {
452
+ return fullSyncSource;
453
+ }
454
+ });
455
+ Object.defineProperty(exports, "isAnonymousFilter", {
456
+ enumerable: true,
457
+ get: function() {
458
+ return isAnonymousFilter;
459
+ }
460
+ });
461
+ Object.defineProperty(exports, "nextCursor", {
462
+ enumerable: true,
463
+ get: function() {
464
+ return nextCursor;
465
+ }
466
+ });
467
+ Object.defineProperty(exports, "parseWireCursors", {
468
+ enumerable: true,
469
+ get: function() {
470
+ return parseWireCursors;
471
+ }
472
+ });
473
+ Object.defineProperty(exports, "projectionExposureErrors", {
474
+ enumerable: true,
475
+ get: function() {
476
+ return projectionExposureErrors;
477
+ }
478
+ });
479
+ Object.defineProperty(exports, "pushSourceOf", {
480
+ enumerable: true,
481
+ get: function() {
482
+ return pushSourceOf;
483
+ }
484
+ });
485
+ Object.defineProperty(exports, "resolveEntitySource", {
486
+ enumerable: true,
487
+ get: function() {
488
+ return resolveEntitySource;
489
+ }
490
+ });
491
+ Object.defineProperty(exports, "sourceTimeFields", {
492
+ enumerable: true,
493
+ get: function() {
494
+ return sourceTimeFields;
495
+ }
496
+ });
497
+ Object.defineProperty(exports, "syncSource", {
498
+ enumerable: true,
499
+ get: function() {
500
+ return syncSource;
501
+ }
502
+ });
503
+ Object.defineProperty(exports, "toWireCursor", {
504
+ enumerable: true,
505
+ get: function() {
506
+ return toWireCursor;
507
+ }
508
+ });
@@ -14,6 +14,16 @@ import { r as identityRefs, t as BASE_REF } from "./projection-CzBI2NL8.mjs";
14
14
  function quoteIdent(name) {
15
15
  return `"${name.replace(/"/g, "\"\"")}"`;
16
16
  }
17
+ /**
18
+ * Quote a table in FROM/JOIN position. A `schema.table` name is split on the
19
+ * first dot and each part quoted separately; a dotless name is exactly
20
+ * `quoteIdent(name)`.
21
+ */
22
+ function quoteTableRef(name) {
23
+ const dot = name.indexOf(".");
24
+ if (dot === -1) return quoteIdent(name);
25
+ return `${quoteIdent(name.slice(0, dot))}.${quoteIdent(name.slice(dot + 1))}`;
26
+ }
17
27
  function refSql(ref) {
18
28
  return `${quoteIdent(ref.table)}.${quoteIdent(ref.column)}`;
19
29
  }
@@ -54,12 +64,12 @@ function compileProjectionJoins(projection) {
54
64
  return projection.joins.map((join) => {
55
65
  const keyword = join.type === "inner" ? "INNER JOIN" : "LEFT JOIN";
56
66
  const on = join.on.map((c) => `${refSql(c.left)} = ${refSql(c.right)}`).join(" AND ");
57
- return `${keyword} ${quoteIdent(join.table)} AS ${quoteIdent(join.key)} ON ${on}`;
67
+ return `${keyword} ${quoteTableRef(join.table)} AS ${quoteIdent(join.key)} ON ${on}`;
58
68
  });
59
69
  }
60
70
  /** `FROM <baseTable> AS "base"` — the alias every ref resolves against. */
61
71
  function compileProjectionFrom(projection) {
62
- return `FROM ${quoteIdent(projection.baseTable)} AS ${quoteIdent(BASE_REF)}`;
72
+ return `FROM ${quoteTableRef(projection.baseTable)} AS ${quoteIdent(BASE_REF)}`;
63
73
  }
64
74
  /**
65
75
  * Hard ceiling on preview rows, regardless of what a caller asks for.
@@ -93,4 +103,4 @@ function compileProjectionPreview(projection, limit) {
93
103
  `LIMIT ${Math.max(1, Math.min(Math.floor(limit), 50))}`
94
104
  ].join(" ");
95
105
  }
96
- export { compileProjectionPreview as a, compileProjectionJoins as i, compileProjectionFrom as n, compileProjectionSelect as o, compileProjectionIdentity as r, quoteIdent as s, PREVIEW_MAX_ROWS as t };
106
+ export { compileProjectionPreview as a, quoteTableRef as c, compileProjectionJoins as i, compileProjectionFrom as n, compileProjectionSelect as o, compileProjectionIdentity as r, quoteIdent as s, PREVIEW_MAX_ROWS as t };
@@ -14,6 +14,16 @@ const require_projection = require("./projection-w4Z6vSL2.cjs");
14
14
  function quoteIdent(name) {
15
15
  return `"${name.replace(/"/g, "\"\"")}"`;
16
16
  }
17
+ /**
18
+ * Quote a table in FROM/JOIN position. A `schema.table` name is split on the
19
+ * first dot and each part quoted separately; a dotless name is exactly
20
+ * `quoteIdent(name)`.
21
+ */
22
+ function quoteTableRef(name) {
23
+ const dot = name.indexOf(".");
24
+ if (dot === -1) return quoteIdent(name);
25
+ return `${quoteIdent(name.slice(0, dot))}.${quoteIdent(name.slice(dot + 1))}`;
26
+ }
17
27
  function refSql(ref) {
18
28
  return `${quoteIdent(ref.table)}.${quoteIdent(ref.column)}`;
19
29
  }
@@ -54,12 +64,12 @@ function compileProjectionJoins(projection) {
54
64
  return projection.joins.map((join) => {
55
65
  const keyword = join.type === "inner" ? "INNER JOIN" : "LEFT JOIN";
56
66
  const on = join.on.map((c) => `${refSql(c.left)} = ${refSql(c.right)}`).join(" AND ");
57
- return `${keyword} ${quoteIdent(join.table)} AS ${quoteIdent(join.key)} ON ${on}`;
67
+ return `${keyword} ${quoteTableRef(join.table)} AS ${quoteIdent(join.key)} ON ${on}`;
58
68
  });
59
69
  }
60
70
  /** `FROM <baseTable> AS "base"` — the alias every ref resolves against. */
61
71
  function compileProjectionFrom(projection) {
62
- return `FROM ${quoteIdent(projection.baseTable)} AS ${quoteIdent(require_projection.BASE_REF)}`;
72
+ return `FROM ${quoteTableRef(projection.baseTable)} AS ${quoteIdent(require_projection.BASE_REF)}`;
63
73
  }
64
74
  /**
65
75
  * Hard ceiling on preview rows, regardless of what a caller asks for.
@@ -135,3 +145,9 @@ Object.defineProperty(exports, "quoteIdent", {
135
145
  return quoteIdent;
136
146
  }
137
147
  });
148
+ Object.defineProperty(exports, "quoteTableRef", {
149
+ enumerable: true,
150
+ get: function() {
151
+ return quoteTableRef;
152
+ }
153
+ });