@biltme/backend 0.5.2 → 0.6.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.
package/README.md CHANGED
@@ -39,6 +39,45 @@ const { data, error } = await bilt.auth.signInWithPassword({ email, password })
39
39
  const { data: rows } = await bilt.from('notes').select('*')
40
40
  ```
41
41
 
42
+ ## Typed queries
43
+
44
+ `createClient` reads the schema off an empty `Database` interface this package
45
+ exports. Augment it and the columns of every table in the file are typed:
46
+
47
+ ```ts
48
+ declare module '@biltme/backend' {
49
+ interface Database {
50
+ public: {
51
+ Tables: {
52
+ notes: {
53
+ Row: { id: string; title: string; tags: string[] | null }
54
+ Insert: { id?: string; title: string; tags?: string[] | null }
55
+ Update: { id?: string; title?: string; tags?: string[] | null }
56
+ Relationships: []
57
+ }
58
+ }
59
+ Views: Record<never, never>
60
+ Functions: Record<never, never>
61
+ Enums: Record<never, never>
62
+ CompositeTypes: Record<never, never>
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ You do not write that by hand. bilt-cloud regenerates it from the live schema on
69
+ every `bilt_apply_sql`, and the agent drops it into the project. Because it is a
70
+ module augmentation rather than `createClient<Database>`, there is no generic to
71
+ thread through and nothing to keep in sync at the call site.
72
+
73
+ What bilt-cloud emits differs from the snippet above in one way that matters:
74
+ its `Views` and `Functions` are open index signatures rather than closed. So a
75
+ column that does not exist on a known table fails to compile, while a view, an
76
+ `rpc()` call, or a table created since the last render falls through to `any`
77
+ instead of erroring. A stale file never blocks a build.
78
+
79
+ Leave `Database` unaugmented and rows come back `any`, which is what 0.5.x did.
80
+
42
81
  ## Calling functions
43
82
 
44
83
  ```ts
@@ -124,7 +163,9 @@ const bilt = createClient(url, key, {
124
163
 
125
164
  ## What this package adds vs `@supabase/supabase-js`
126
165
 
127
- - `createClient` is re-exported verbatim — same positional signature.
166
+ - `createClient` *is* supabase-js's `createClient`, re-typed so that a call with no type
167
+ arguments defaults its schema to the augmentable `Database` interface above instead of `any`.
168
+ - `Database`, the empty interface a project augments to type its schema.
128
169
  - `asyncStorage(impl)` factory wrapping `@react-native-async-storage/async-storage` to the supabase-js storage shape.
129
170
  - `webStorage()` and `memoryStorage()` for completeness.
130
171
  - `FunctionsHttpError`, `FunctionsRelayError`, `FunctionsFetchError`, `FunctionRegion` re-exports for clean `catch` and option typing.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,36 @@
1
- export { createClient } from '@supabase/supabase-js';
1
+ import { createClient as createSupabaseClient } from '@supabase/supabase-js';
2
+ /**
3
+ * Schema of the project's database, in postgrest-js's `Database` shape.
4
+ *
5
+ * Empty here; projects fill it by augmenting this module:
6
+ *
7
+ * ```ts
8
+ * declare module '@biltme/backend' {
9
+ * interface Database {
10
+ * public: { Tables: { … }; Views: { … }; Functions: { … } }
11
+ * }
12
+ * }
13
+ * ```
14
+ *
15
+ * bilt-cloud writes that file after every schema change, so there is nothing to
16
+ * pass to {@link createClient}.
17
+ */
18
+ export interface Database {
19
+ }
20
+ /** {@link Database} once augmented, `any` while empty — which is the untyped behaviour of 0.5.x. */
21
+ type BiltDatabase = [keyof Database] extends [never] ? any : Database;
22
+ /**
23
+ * Creates a Bilt client. supabase-js's `createClient` with two changes: called
24
+ * with no type arguments, the schema is {@link BiltDatabase} instead of `any`,
25
+ * and a missing or malformed URL or key names Bilt Cloud rather than Supabase.
26
+ *
27
+ * The second member of the intersection is supabase-js's own signature. An
28
+ * intersection of function types is an overload set, so a bare call takes the
29
+ * first member and any call with explicit type arguments falls through to the
30
+ * second. Restating the parameter list here instead would have to track
31
+ * supabase-js's defaults by hand across a caret range.
32
+ */
33
+ export declare const createClient: typeof createSupabaseClient<BiltDatabase> & typeof createSupabaseClient;
2
34
  export { webStorage, memoryStorage, asyncStorage } from './storage';
3
35
  export type { StorageAdapter } from './storage';
4
36
  export { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError, FunctionRegion } from '@supabase/supabase-js';
package/dist/index.js CHANGED
@@ -11795,6 +11795,7 @@ function shouldShowDeprecationWarning() {
11795
11795
  }
11796
11796
  if (shouldShowDeprecationWarning())
11797
11797
  console.warn("⚠️ Node.js 20 and below are deprecated and will no longer be supported in future versions of @supabase/supabase-js. Please upgrade to Node.js 22 or later. For more information, visit: https://github.com/orgs/supabase/discussions/45715");
11798
+
11798
11799
  // src/storage/memory.ts
11799
11800
  function memoryStorage() {
11800
11801
  const store = new Map;
@@ -11858,6 +11859,28 @@ function asyncStorage(impl) {
11858
11859
  removeItem: (key) => impl.removeItem(key)
11859
11860
  };
11860
11861
  }
11862
+ // src/index.ts
11863
+ function assertCredentials(url, key) {
11864
+ const trimmed = url?.trim();
11865
+ if (!trimmed) {
11866
+ throw new Error("Bilt Cloud URL is required. Pass process.env.EXPO_PUBLIC_BILT_URL, which is injected into the app at runtime.");
11867
+ }
11868
+ if (!/^https?:\/\//i.test(trimmed)) {
11869
+ throw new Error(`Invalid Bilt Cloud URL: must be an http(s) URL, like https://<project>.cloud.bilt.me. Got: ${url}`);
11870
+ }
11871
+ try {
11872
+ new URL(trimmed);
11873
+ } catch {
11874
+ throw new Error(`Invalid Bilt Cloud URL: ${url} is malformed.`);
11875
+ }
11876
+ if (!key) {
11877
+ throw new Error("Bilt Cloud anon key is required. Pass process.env.EXPO_PUBLIC_BILT_ANON_KEY, which is injected into the app at runtime.");
11878
+ }
11879
+ }
11880
+ var createClient2 = (url, key, options) => {
11881
+ assertCredentials(url, key);
11882
+ return createClient(url, key, options);
11883
+ };
11861
11884
  var export_FunctionsRelayError = import_functions_js.FunctionsRelayError;
11862
11885
  var export_FunctionsHttpError = import_functions_js.FunctionsHttpError;
11863
11886
  var export_FunctionsFetchError = import_functions_js.FunctionsFetchError;
@@ -11866,7 +11889,7 @@ var export_FunctionRegion = import_functions_js.FunctionRegion;
11866
11889
  export {
11867
11890
  webStorage,
11868
11891
  memoryStorage,
11869
- createClient,
11892
+ createClient2 as createClient,
11870
11893
  asyncStorage,
11871
11894
  StorageApiError,
11872
11895
  export_FunctionsRelayError as FunctionsRelayError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biltme/backend",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "Bilt backend SDK — thin shim over @supabase/supabase-js for bilt-cloud projects",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",