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
package/supabase.cjs CHANGED
@@ -1,7 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-X0-yIA3O.cjs");
3
- const require_discover = require("./discover-BZIPXl23.cjs");
4
- const require_introspector = require("./introspector-BwYgHGcS.cjs");
2
+ const require_src = require("./src-CZIdwwI2.cjs");
3
+ const require_supabase_contact = require("./supabase-contact-BXQ0nnLq.cjs");
4
+ const require_from_sql = require("./from-sql-CFgXkCe2.cjs");
5
+ const require_sync = require("./sync-CdA9dgZz.cjs");
6
+ const require_app_id = require("./app-id-DcQ4u1c8.cjs");
7
+ const require_introspector = require("./introspector-DT_Ma59k.cjs");
5
8
  // ../sdk/src/supabase/constants.ts
6
9
  /**
7
10
  * The cadence this function reports as its own heartbeat interval.
@@ -17,10 +20,7 @@ const require_introspector = require("./introspector-BwYgHGcS.cjs");
17
20
  */
18
21
  const SUPABASE_EDGE_HEARTBEAT_MS = 9e5;
19
22
  // ../sdk/src/supabase/index.ts
20
- const AUTH_USERS = "auth.users";
21
- const PROFILES = "profiles";
22
23
  const ENTITY_KEY = "users";
23
- const OBJECT_TYPE = "users";
24
24
  const ROUTE_PREFIX = "/functions/v1";
25
25
  const TRAILING_SLASH = /\/+$/;
26
26
  const OK = 200;
@@ -37,75 +37,6 @@ const routeOf = (req) => {
37
37
  if (path === ROUTE_PREFIX || path.startsWith(`${ROUTE_PREFIX}/`)) path = path.slice(13);
38
38
  return path.replace(TRAILING_SLASH, "") || "/";
39
39
  };
40
- /**
41
- * `public.profiles` joins only when its `id` is a foreign key to auth.users.
42
- * Its columns are exposed under their bare names; one that collides with an
43
- * `auth.users` column (`id`, `email`, `created_at`, `updated_at`...) is
44
- * dropped, not prefixed: both rows are the same person, so the auth value
45
- * stays the single source of truth for that name.
46
- */
47
- function profileJoin(tables, authColumns) {
48
- const profiles = tables.find((t) => t.name === PROFILES);
49
- const id = profiles?.columnsMeta?.find((c) => c.name === "id");
50
- if (!(profiles && id?.isForeignKey && id.references?.table === AUTH_USERS)) return null;
51
- const columns = (profiles.columnsMeta ?? []).filter((c) => !authColumns.includes(c.name)).map((c) => ({
52
- ...c,
53
- isPrimaryKey: false,
54
- isForeignKey: false
55
- }));
56
- return columns.length === 0 ? null : { columns };
57
- }
58
- const flatKey = (key) => key.startsWith("base.") || key.startsWith("p.") ? key.slice(key.indexOf(".") + 1) : key;
59
- function profilesProjection(authColumns, join) {
60
- const bindings = {};
61
- for (const column of authColumns) if (column !== "id") bindings[column] = { from: {
62
- table: "base",
63
- column
64
- } };
65
- for (const { name } of join.columns) bindings[name] = { from: {
66
- table: "p",
67
- column: name
68
- } };
69
- return {
70
- version: 1,
71
- kind: "projection",
72
- entityKey: ENTITY_KEY,
73
- baseTable: AUTH_USERS,
74
- joins: [{
75
- key: "p",
76
- table: PROFILES,
77
- type: "left",
78
- on: [{
79
- left: {
80
- table: "base",
81
- column: "id"
82
- },
83
- op: "eq",
84
- right: {
85
- table: "p",
86
- column: "id"
87
- }
88
- }]
89
- }],
90
- fieldBindings: bindings,
91
- identity: {
92
- kind: "base_pk",
93
- column: "id"
94
- }
95
- };
96
- }
97
- /**
98
- * The projection writes each column under its ref token (`p.full_name`). The
99
- * cloud reads `row[sourceColumn]` through a mapping built from the heartbeat
100
- * schema, so contact rows go out flat, under bare column names.
101
- */
102
- const flatten = (source) => ({
103
- ...source,
104
- async fetchPage(args) {
105
- return (await source.fetchPage(args)).map((row) => Object.fromEntries(Object.entries(row).map(([key, value]) => [flatKey(key), value])));
106
- }
107
- });
108
- var ContactTableMissing = class extends Error {};
109
40
  /** A cold-start failure, reduced to the one code that is safe to return. */
110
41
  var SetupFailure = class extends Error {
111
42
  reason;
@@ -114,40 +45,6 @@ var SetupFailure = class extends Error {
114
45
  this.reason = reason;
115
46
  }
116
47
  };
117
- function planContact(executor, tables, contact) {
118
- const table = contact?.table ?? AUTH_USERS;
119
- const meta = tables.find((t) => t.name === table);
120
- if (!meta) throw new ContactTableMissing();
121
- const join = table === AUTH_USERS && contact?.joinProfiles !== false ? profileJoin(tables, meta.columns) : null;
122
- const base = require_introspector.fromSql(executor, {
123
- entity: ENTITY_KEY,
124
- table,
125
- meta,
126
- pushSource: table
127
- });
128
- if (!join) return {
129
- schema: tables,
130
- source: base,
131
- table
132
- };
133
- const advertised = {
134
- ...meta,
135
- columns: [...meta.columns, ...join.columns.map((c) => c.name)],
136
- columnsMeta: [...meta.columnsMeta ?? [], ...join.columns]
137
- };
138
- const projected = require_introspector.fromSqlProjection(executor, profilesProjection(meta.columns, join), {
139
- entity: ENTITY_KEY,
140
- objectType: OBJECT_TYPE
141
- });
142
- return {
143
- schema: tables.map((t) => t === meta ? advertised : t),
144
- source: flatten({
145
- ...projected,
146
- pushSource: table
147
- }),
148
- table
149
- };
150
- }
151
48
  /**
152
49
  * The Edge Function handler: `POST /clivly/tick` runs a sync Clivly asked for,
153
50
  * `GET /clivly/connect` checks the connection, and every other request is a 404
@@ -161,18 +58,21 @@ function createSupabaseClivly(opts) {
161
58
  runtime ??= (async () => {
162
59
  let tables;
163
60
  try {
164
- tables = await require_discover.discoverFromSql(executor);
61
+ tables = await require_supabase_contact.discoverFromSql(executor);
165
62
  } catch {
166
63
  throw new SetupFailure("discovery_failed");
167
64
  }
168
65
  let plan;
169
66
  try {
170
- plan = planContact(executor, tables, opts.contact);
67
+ plan = require_supabase_contact.supabaseContactSource(executor, tables, {
68
+ entity: ENTITY_KEY,
69
+ ...opts.contact
70
+ });
171
71
  } catch (error) {
172
- throw new SetupFailure(error instanceof ContactTableMissing ? "contact_table_missing" : "sdk_init_failed");
72
+ throw new SetupFailure(error instanceof require_supabase_contact.ContactTableMissing ? "contact_table_missing" : "sdk_init_failed");
173
73
  }
174
74
  try {
175
- return buildRuntime(plan);
75
+ return buildRuntime(plan, require_sync.filtersAnonymous(tables.find((t) => t.name === plan.table)));
176
76
  } catch {
177
77
  throw new SetupFailure("sdk_init_failed");
178
78
  }
@@ -182,7 +82,7 @@ function createSupabaseClivly(opts) {
182
82
  });
183
83
  return runtime;
184
84
  };
185
- const buildRuntime = (plan) => {
85
+ const buildRuntime = (plan, filterAnonymous) => {
186
86
  const sdk = require_src.createClivlySDK({
187
87
  apiKey: secretKey ?? "",
188
88
  apiUrl: env.CLIVLY_API_URL,
@@ -191,7 +91,7 @@ function createSupabaseClivly(opts) {
191
91
  source: { contacts: plan.source },
192
92
  contactEntity: plan.table,
193
93
  introspector: require_introspector.sqlIntrospector(executor),
194
- appIdStore: require_introspector.sqlAppIdStore(executor),
94
+ appIdStore: require_app_id.sqlAppIdStore(executor),
195
95
  cursorStore: require_src.memoryCursorStore(),
196
96
  syncTrigger: {
197
97
  url: `${env.SUPABASE_URL}/functions/v1/clivly/tick`,
@@ -202,6 +102,7 @@ function createSupabaseClivly(opts) {
202
102
  sync: { onBoot: false }
203
103
  });
204
104
  return {
105
+ filterAnonymous,
205
106
  sdk,
206
107
  table: plan.table,
207
108
  tick: sdk.createClivlyHandler()
@@ -224,12 +125,21 @@ function createSupabaseClivly(opts) {
224
125
  const connect = async () => {
225
126
  if (!secretKey) return missingKey();
226
127
  try {
227
- const { sdk, table } = await getRuntime();
228
- const result = await sdk.connect();
229
- if (!result.ok) return json(result, BAD_GATEWAY);
230
- const hasContacts = await require_introspector.existsFromSql(executor, { table });
128
+ const { filterAnonymous, sdk, table } = await getRuntime();
129
+ const { ok, reason, retryable, status } = await sdk.connect();
130
+ const outcome = {
131
+ ok,
132
+ reason,
133
+ retryable,
134
+ status
135
+ };
136
+ if (!ok) return json(outcome, BAD_GATEWAY);
137
+ const hasContacts = await require_from_sql.existsFromSql(executor, {
138
+ table,
139
+ filterAnonymous
140
+ });
231
141
  return json({
232
- ...result,
142
+ ...outcome,
233
143
  hasContacts
234
144
  }, OK);
235
145
  } catch (error) {
package/supabase.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- import { s as SqlExecutor } from "./index-CZkp8TV4.cjs";
1
+ import { i as SqlExecutor } from "./from-sql-S8dSvU-e.cjs";
2
+ import "./index-CIupXz_w.cjs";
2
3
  export interface SupabaseClivlyOptions {
3
4
  /** Defaults to `auth.users`, joined to `public.profiles` when it qualifies. */
4
5
  contact?: {
package/supabase.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- import { s as SqlExecutor } from "./index-Cnrz4ywf.mjs";
1
+ import { i as SqlExecutor } from "./from-sql-CpGP7K3J.mjs";
2
+ import "./index-BoemTWH4.mjs";
2
3
  export interface SupabaseClivlyOptions {
3
4
  /** Defaults to `auth.users`, joined to `public.profiles` when it qualifies. */
4
5
  contact?: {
package/supabase.mjs CHANGED
@@ -1,6 +1,9 @@
1
- import { i as memoryCursorStore, n as createClivlySDK } from "./src-Dq2nY1Sj.mjs";
2
- import { t as discoverFromSql } from "./discover-CFIi43Qn.mjs";
3
- import { a as sqlAppIdStore, i as fromSql, n as fromSqlProjection, r as existsFromSql, t as sqlIntrospector } from "./introspector-Bz52xOUr.mjs";
1
+ import { i as memoryCursorStore, n as createClivlySDK } from "./src-tFhC1Ru2.mjs";
2
+ import { a as discoverFromSql, r as supabaseContactSource, t as ContactTableMissing } from "./supabase-contact-3ke1KKUs.mjs";
3
+ import { t as existsFromSql } from "./from-sql-BD7gR4bC.mjs";
4
+ import { x as filtersAnonymous } from "./sync-Q0O-2kFI.mjs";
5
+ import { r as sqlAppIdStore } from "./app-id-5cB6yioz.mjs";
6
+ import { t as sqlIntrospector } from "./introspector-5w2x89RD.mjs";
4
7
  // ../sdk/src/supabase/constants.ts
5
8
  /**
6
9
  * The cadence this function reports as its own heartbeat interval.
@@ -16,10 +19,7 @@ import { a as sqlAppIdStore, i as fromSql, n as fromSqlProjection, r as existsFr
16
19
  */
17
20
  const SUPABASE_EDGE_HEARTBEAT_MS = 9e5;
18
21
  // ../sdk/src/supabase/index.ts
19
- const AUTH_USERS = "auth.users";
20
- const PROFILES = "profiles";
21
22
  const ENTITY_KEY = "users";
22
- const OBJECT_TYPE = "users";
23
23
  const ROUTE_PREFIX = "/functions/v1";
24
24
  const TRAILING_SLASH = /\/+$/;
25
25
  const OK = 200;
@@ -36,75 +36,6 @@ const routeOf = (req) => {
36
36
  if (path === ROUTE_PREFIX || path.startsWith(`${ROUTE_PREFIX}/`)) path = path.slice(13);
37
37
  return path.replace(TRAILING_SLASH, "") || "/";
38
38
  };
39
- /**
40
- * `public.profiles` joins only when its `id` is a foreign key to auth.users.
41
- * Its columns are exposed under their bare names; one that collides with an
42
- * `auth.users` column (`id`, `email`, `created_at`, `updated_at`...) is
43
- * dropped, not prefixed: both rows are the same person, so the auth value
44
- * stays the single source of truth for that name.
45
- */
46
- function profileJoin(tables, authColumns) {
47
- const profiles = tables.find((t) => t.name === PROFILES);
48
- const id = profiles?.columnsMeta?.find((c) => c.name === "id");
49
- if (!(profiles && id?.isForeignKey && id.references?.table === AUTH_USERS)) return null;
50
- const columns = (profiles.columnsMeta ?? []).filter((c) => !authColumns.includes(c.name)).map((c) => ({
51
- ...c,
52
- isPrimaryKey: false,
53
- isForeignKey: false
54
- }));
55
- return columns.length === 0 ? null : { columns };
56
- }
57
- const flatKey = (key) => key.startsWith("base.") || key.startsWith("p.") ? key.slice(key.indexOf(".") + 1) : key;
58
- function profilesProjection(authColumns, join) {
59
- const bindings = {};
60
- for (const column of authColumns) if (column !== "id") bindings[column] = { from: {
61
- table: "base",
62
- column
63
- } };
64
- for (const { name } of join.columns) bindings[name] = { from: {
65
- table: "p",
66
- column: name
67
- } };
68
- return {
69
- version: 1,
70
- kind: "projection",
71
- entityKey: ENTITY_KEY,
72
- baseTable: AUTH_USERS,
73
- joins: [{
74
- key: "p",
75
- table: PROFILES,
76
- type: "left",
77
- on: [{
78
- left: {
79
- table: "base",
80
- column: "id"
81
- },
82
- op: "eq",
83
- right: {
84
- table: "p",
85
- column: "id"
86
- }
87
- }]
88
- }],
89
- fieldBindings: bindings,
90
- identity: {
91
- kind: "base_pk",
92
- column: "id"
93
- }
94
- };
95
- }
96
- /**
97
- * The projection writes each column under its ref token (`p.full_name`). The
98
- * cloud reads `row[sourceColumn]` through a mapping built from the heartbeat
99
- * schema, so contact rows go out flat, under bare column names.
100
- */
101
- const flatten = (source) => ({
102
- ...source,
103
- async fetchPage(args) {
104
- return (await source.fetchPage(args)).map((row) => Object.fromEntries(Object.entries(row).map(([key, value]) => [flatKey(key), value])));
105
- }
106
- });
107
- var ContactTableMissing = class extends Error {};
108
39
  /** A cold-start failure, reduced to the one code that is safe to return. */
109
40
  var SetupFailure = class extends Error {
110
41
  reason;
@@ -113,40 +44,6 @@ var SetupFailure = class extends Error {
113
44
  this.reason = reason;
114
45
  }
115
46
  };
116
- function planContact(executor, tables, contact) {
117
- const table = contact?.table ?? AUTH_USERS;
118
- const meta = tables.find((t) => t.name === table);
119
- if (!meta) throw new ContactTableMissing();
120
- const join = table === AUTH_USERS && contact?.joinProfiles !== false ? profileJoin(tables, meta.columns) : null;
121
- const base = fromSql(executor, {
122
- entity: ENTITY_KEY,
123
- table,
124
- meta,
125
- pushSource: table
126
- });
127
- if (!join) return {
128
- schema: tables,
129
- source: base,
130
- table
131
- };
132
- const advertised = {
133
- ...meta,
134
- columns: [...meta.columns, ...join.columns.map((c) => c.name)],
135
- columnsMeta: [...meta.columnsMeta ?? [], ...join.columns]
136
- };
137
- const projected = fromSqlProjection(executor, profilesProjection(meta.columns, join), {
138
- entity: ENTITY_KEY,
139
- objectType: OBJECT_TYPE
140
- });
141
- return {
142
- schema: tables.map((t) => t === meta ? advertised : t),
143
- source: flatten({
144
- ...projected,
145
- pushSource: table
146
- }),
147
- table
148
- };
149
- }
150
47
  /**
151
48
  * The Edge Function handler: `POST /clivly/tick` runs a sync Clivly asked for,
152
49
  * `GET /clivly/connect` checks the connection, and every other request is a 404
@@ -166,12 +63,15 @@ function createSupabaseClivly(opts) {
166
63
  }
167
64
  let plan;
168
65
  try {
169
- plan = planContact(executor, tables, opts.contact);
66
+ plan = supabaseContactSource(executor, tables, {
67
+ entity: ENTITY_KEY,
68
+ ...opts.contact
69
+ });
170
70
  } catch (error) {
171
71
  throw new SetupFailure(error instanceof ContactTableMissing ? "contact_table_missing" : "sdk_init_failed");
172
72
  }
173
73
  try {
174
- return buildRuntime(plan);
74
+ return buildRuntime(plan, filtersAnonymous(tables.find((t) => t.name === plan.table)));
175
75
  } catch {
176
76
  throw new SetupFailure("sdk_init_failed");
177
77
  }
@@ -181,7 +81,7 @@ function createSupabaseClivly(opts) {
181
81
  });
182
82
  return runtime;
183
83
  };
184
- const buildRuntime = (plan) => {
84
+ const buildRuntime = (plan, filterAnonymous) => {
185
85
  const sdk = createClivlySDK({
186
86
  apiKey: secretKey ?? "",
187
87
  apiUrl: env.CLIVLY_API_URL,
@@ -201,6 +101,7 @@ function createSupabaseClivly(opts) {
201
101
  sync: { onBoot: false }
202
102
  });
203
103
  return {
104
+ filterAnonymous,
204
105
  sdk,
205
106
  table: plan.table,
206
107
  tick: sdk.createClivlyHandler()
@@ -223,12 +124,21 @@ function createSupabaseClivly(opts) {
223
124
  const connect = async () => {
224
125
  if (!secretKey) return missingKey();
225
126
  try {
226
- const { sdk, table } = await getRuntime();
227
- const result = await sdk.connect();
228
- if (!result.ok) return json(result, BAD_GATEWAY);
229
- const hasContacts = await existsFromSql(executor, { table });
127
+ const { filterAnonymous, sdk, table } = await getRuntime();
128
+ const { ok, reason, retryable, status } = await sdk.connect();
129
+ const outcome = {
130
+ ok,
131
+ reason,
132
+ retryable,
133
+ status
134
+ };
135
+ if (!ok) return json(outcome, BAD_GATEWAY);
136
+ const hasContacts = await existsFromSql(executor, {
137
+ table,
138
+ filterAnonymous
139
+ });
230
140
  return json({
231
- ...result,
141
+ ...outcome,
232
142
  hasContacts
233
143
  }, OK);
234
144
  } catch (error) {