@biltme/backend 0.6.0 → 0.7.1
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 +36 -6
- package/dist/index.d.ts +68 -2
- package/dist/index.js +50 -1
- package/dist/realtime.d.ts +11 -0
- package/dist/uploads.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,14 +70,36 @@ every `bilt_apply_sql`, and the agent drops it into the project. Because it is a
|
|
|
70
70
|
module augmentation rather than `createClient<Database>`, there is no generic to
|
|
71
71
|
thread through and nothing to keep in sync at the call site.
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
instead of erroring. A stale file never blocks a build.
|
|
73
|
+
Every key bilt-cloud emits is closed. A table, view or column that is not in
|
|
74
|
+
the file fails to compile, and so does an `rpc()` call to a function the file
|
|
75
|
+
does not list or with an argument it does not have. A stale file therefore
|
|
76
|
+
blocks a build until the next schema change regenerates it.
|
|
78
77
|
|
|
79
78
|
Leave `Database` unaugmented and rows come back `any`, which is what 0.5.x did.
|
|
80
79
|
|
|
80
|
+
### Naming a row
|
|
81
|
+
|
|
82
|
+
Four helpers resolve over that same augmented `Database`, so a row can cross a
|
|
83
|
+
component boundary without being restated:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import type { Tables, TablesInsert, TablesUpdate, Enums } from '@biltme/backend'
|
|
87
|
+
|
|
88
|
+
function MessageCard({ message }: { message: Tables<'messages'> }) { … }
|
|
89
|
+
function draft(): TablesInsert<'messages'> { … }
|
|
90
|
+
function patch(): TablesUpdate<'messages'> { … }
|
|
91
|
+
function badge(status: Enums<'order_status'>) { … }
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`Tables` spans tables and views and gives the same type `select()` returns per
|
|
95
|
+
element. `TablesInsert` and `TablesUpdate` take tables only, as in supabase-js,
|
|
96
|
+
so a writable view has a row name but no payload name. `Enums` resolves to the
|
|
97
|
+
union bilt-cloud renders under `Database['public']['Enums']`, so a `switch` over
|
|
98
|
+
it is checked for exhaustiveness.
|
|
99
|
+
|
|
100
|
+
Before the first schema change there are no names, and passing one is a compile
|
|
101
|
+
error rather than `any`.
|
|
102
|
+
|
|
81
103
|
## Calling functions
|
|
82
104
|
|
|
83
105
|
```ts
|
|
@@ -141,6 +163,12 @@ Bucket admin (`createBucket`, `updateBucket`, `deleteBucket`, `emptyBucket`,
|
|
|
141
163
|
policies on `storage.objects` — author them with the `bilt_storage_apply`
|
|
142
164
|
agent tool or the SQL editor.
|
|
143
165
|
|
|
166
|
+
On React Native, a `Blob` passed to `upload`, `update` or `uploadToSignedUrl`
|
|
167
|
+
is sent as bytes labelled with `contentType`, so `fetch(uri).blob()` from a
|
|
168
|
+
picked file passes a bucket's MIME allowlist. Pass `contentType` for such
|
|
169
|
+
files: a React Native Blob has no type of its own, and without one the upload
|
|
170
|
+
is labelled `application/octet-stream`.
|
|
171
|
+
|
|
144
172
|
## Web
|
|
145
173
|
|
|
146
174
|
```ts
|
|
@@ -166,6 +194,8 @@ const bilt = createClient(url, key, {
|
|
|
166
194
|
- `createClient` *is* supabase-js's `createClient`, re-typed so that a call with no type
|
|
167
195
|
arguments defaults its schema to the augmentable `Database` interface above instead of `any`.
|
|
168
196
|
- `Database`, the empty interface a project augments to type its schema.
|
|
197
|
+
- On React Native, storage uploads send a `Blob` as bytes so `contentType` reaches the bucket (see Storage).
|
|
198
|
+
- Realtime is not available: `bilt.channel()` throws `REALTIME_NOT_SUPPORTED`. Refetch with `bilt.from(...)` on an interval or on screen focus instead.
|
|
169
199
|
- `asyncStorage(impl)` factory wrapping `@react-native-async-storage/async-storage` to the supabase-js storage shape.
|
|
170
200
|
- `webStorage()` and `memoryStorage()` for completeness.
|
|
171
201
|
- `FunctionsHttpError`, `FunctionsRelayError`, `FunctionsFetchError`, `FunctionRegion` re-exports for clean `catch` and option typing.
|
|
@@ -174,6 +204,6 @@ const bilt = createClient(url, key, {
|
|
|
174
204
|
|
|
175
205
|
## Docs
|
|
176
206
|
|
|
177
|
-
For everything else (auth flows, RLS, OAuth,
|
|
207
|
+
For everything else (auth flows, RLS, OAuth, functions reference),
|
|
178
208
|
use [Supabase's docs](https://supabase.com/docs/reference/javascript/introduction).
|
|
179
209
|
The bilt backend speaks the same wire protocol.
|
package/dist/index.d.ts
CHANGED
|
@@ -19,10 +19,75 @@ export interface Database {
|
|
|
19
19
|
}
|
|
20
20
|
/** {@link Database} once augmented, `any` while empty — which is the untyped behaviour of 0.5.x. */
|
|
21
21
|
type BiltDatabase = [keyof Database] extends [never] ? any : Database;
|
|
22
|
+
type PublicEnums = Database extends {
|
|
23
|
+
public: {
|
|
24
|
+
Enums: infer E;
|
|
25
|
+
};
|
|
26
|
+
} ? E : {
|
|
27
|
+
[_ in never]: never;
|
|
28
|
+
};
|
|
29
|
+
type PublicTables = Database extends {
|
|
30
|
+
public: {
|
|
31
|
+
Tables: infer T;
|
|
32
|
+
};
|
|
33
|
+
} ? T : {
|
|
34
|
+
[_ in never]: never;
|
|
35
|
+
};
|
|
36
|
+
type PublicViews = Database extends {
|
|
37
|
+
public: {
|
|
38
|
+
Views: infer V;
|
|
39
|
+
};
|
|
40
|
+
} ? V : {
|
|
41
|
+
[_ in never]: never;
|
|
42
|
+
};
|
|
43
|
+
type PublicRelations = PublicTables & PublicViews;
|
|
22
44
|
/**
|
|
23
|
-
*
|
|
45
|
+
* The labels of a Postgres enum in the project's `public` schema, by name.
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* import type { Enums } from '@biltme/backend'
|
|
49
|
+
* function badge(status: Enums<'order_status'>) { … }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* Resolves to the union bilt-cloud renders under `Database['public']['Enums']`,
|
|
53
|
+
* so a `switch` over it is checked for exhaustiveness. Before the first schema
|
|
54
|
+
* change there are no names, and any argument is a compile error.
|
|
55
|
+
*/
|
|
56
|
+
export type Enums<Name extends keyof PublicEnums> = PublicEnums[Name];
|
|
57
|
+
/**
|
|
58
|
+
* A row of a table or view in the project's `public` schema, by name.
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* import type { Tables } from '@biltme/backend'
|
|
62
|
+
* function MessageCard({ message }: { message: Tables<'messages'> }) { … }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* The same type `bilt.from(name).select()` returns per element, so a row can
|
|
66
|
+
* cross a component boundary without being restated. Before the first schema
|
|
67
|
+
* change there are no names, and any argument is a compile error.
|
|
68
|
+
*/
|
|
69
|
+
export type Tables<Name extends keyof PublicRelations> = PublicRelations[Name] extends {
|
|
70
|
+
Row: infer R;
|
|
71
|
+
} ? R : never;
|
|
72
|
+
/**
|
|
73
|
+
* The payload `bilt.from(name).insert()` accepts, for a table in the `public`
|
|
74
|
+
* schema. Keyed on tables alone, as in supabase-js: a writable view has a
|
|
75
|
+
* {@link Tables} row but no name for its insert payload.
|
|
76
|
+
*/
|
|
77
|
+
export type TablesInsert<Name extends keyof PublicTables> = PublicTables[Name] extends {
|
|
78
|
+
Insert: infer I;
|
|
79
|
+
} ? I : never;
|
|
80
|
+
/** The payload `bilt.from(name).update()` accepts. Tables only, like {@link TablesInsert}. */
|
|
81
|
+
export type TablesUpdate<Name extends keyof PublicTables> = PublicTables[Name] extends {
|
|
82
|
+
Update: infer U;
|
|
83
|
+
} ? U : never;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a Bilt client. supabase-js's `createClient` with four changes: called
|
|
24
86
|
* with no type arguments, the schema is {@link BiltDatabase} instead of `any`,
|
|
25
|
-
*
|
|
87
|
+
* a missing or malformed URL or key names Bilt Cloud rather than Supabase, on
|
|
88
|
+
* React Native a Blob upload is sent as bytes so `contentType` reaches the
|
|
89
|
+
* bucket's MIME allowlist (see {@link sendNativeBlobsAsBytes}), and opening a
|
|
90
|
+
* realtime channel throws because Bilt Cloud has no realtime (see {@link blockRealtime}).
|
|
26
91
|
*
|
|
27
92
|
* The second member of the intersection is supabase-js's own signature. An
|
|
28
93
|
* intersection of function types is an overload set, so a bare call takes the
|
|
@@ -31,6 +96,7 @@ type BiltDatabase = [keyof Database] extends [never] ? any : Database;
|
|
|
31
96
|
* supabase-js's defaults by hand across a caret range.
|
|
32
97
|
*/
|
|
33
98
|
export declare const createClient: typeof createSupabaseClient<BiltDatabase> & typeof createSupabaseClient;
|
|
99
|
+
export { REALTIME_NOT_SUPPORTED } from './realtime';
|
|
34
100
|
export { webStorage, memoryStorage, asyncStorage } from './storage';
|
|
35
101
|
export type { StorageAdapter } from './storage';
|
|
36
102
|
export { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError, FunctionRegion } from '@supabase/supabase-js';
|
package/dist/index.js
CHANGED
|
@@ -11796,6 +11796,51 @@ function shouldShowDeprecationWarning() {
|
|
|
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/realtime.ts
|
|
11800
|
+
var REALTIME_NOT_SUPPORTED = "Realtime is not supported by Bilt Cloud yet. Refetch with bilt.from(...) on an interval or when the screen regains focus instead.";
|
|
11801
|
+
function notSupported() {
|
|
11802
|
+
throw new Error(REALTIME_NOT_SUPPORTED);
|
|
11803
|
+
}
|
|
11804
|
+
function blockRealtime(client) {
|
|
11805
|
+
client.channel = notSupported;
|
|
11806
|
+
client.realtime.channel = notSupported;
|
|
11807
|
+
client.realtime.connect = notSupported;
|
|
11808
|
+
}
|
|
11809
|
+
|
|
11810
|
+
// src/uploads.ts
|
|
11811
|
+
function isReactNative() {
|
|
11812
|
+
return typeof navigator !== "undefined" && navigator.product === "ReactNative";
|
|
11813
|
+
}
|
|
11814
|
+
function readBytes(blob) {
|
|
11815
|
+
if (typeof FileReader === "undefined")
|
|
11816
|
+
return blob.arrayBuffer();
|
|
11817
|
+
return new Promise((resolve, reject) => {
|
|
11818
|
+
const reader = new FileReader;
|
|
11819
|
+
reader.onload = () => resolve(reader.result);
|
|
11820
|
+
reader.onerror = () => reject(reader.error);
|
|
11821
|
+
reader.readAsArrayBuffer(blob);
|
|
11822
|
+
});
|
|
11823
|
+
}
|
|
11824
|
+
async function asBytes(body, options) {
|
|
11825
|
+
if (!isReactNative() || typeof Blob === "undefined" || !(body instanceof Blob))
|
|
11826
|
+
return [body, options];
|
|
11827
|
+
const contentType = options?.contentType ?? (body.type || "application/octet-stream");
|
|
11828
|
+
return [await readBytes(body), { ...options, contentType }];
|
|
11829
|
+
}
|
|
11830
|
+
function sendNativeBlobsAsBytes(client) {
|
|
11831
|
+
const storage = client.storage;
|
|
11832
|
+
const from = storage.from.bind(storage);
|
|
11833
|
+
storage.from = (id) => {
|
|
11834
|
+
const api = from(id);
|
|
11835
|
+
const upload = api.upload.bind(api);
|
|
11836
|
+
const update = api.update.bind(api);
|
|
11837
|
+
const uploadToSignedUrl = api.uploadToSignedUrl.bind(api);
|
|
11838
|
+
api.upload = async (path, body, options) => upload(path, ...await asBytes(body, options));
|
|
11839
|
+
api.update = async (path, body, options) => update(path, ...await asBytes(body, options));
|
|
11840
|
+
api.uploadToSignedUrl = async (path, token, body, options) => uploadToSignedUrl(path, token, ...await asBytes(body, options));
|
|
11841
|
+
return api;
|
|
11842
|
+
};
|
|
11843
|
+
}
|
|
11799
11844
|
// src/storage/memory.ts
|
|
11800
11845
|
function memoryStorage() {
|
|
11801
11846
|
const store = new Map;
|
|
@@ -11879,7 +11924,10 @@ function assertCredentials(url, key) {
|
|
|
11879
11924
|
}
|
|
11880
11925
|
var createClient2 = (url, key, options) => {
|
|
11881
11926
|
assertCredentials(url, key);
|
|
11882
|
-
|
|
11927
|
+
const client = createClient(url, key, options);
|
|
11928
|
+
sendNativeBlobsAsBytes(client);
|
|
11929
|
+
blockRealtime(client);
|
|
11930
|
+
return client;
|
|
11883
11931
|
};
|
|
11884
11932
|
var export_FunctionsRelayError = import_functions_js.FunctionsRelayError;
|
|
11885
11933
|
var export_FunctionsHttpError = import_functions_js.FunctionsHttpError;
|
|
@@ -11892,6 +11940,7 @@ export {
|
|
|
11892
11940
|
createClient2 as createClient,
|
|
11893
11941
|
asyncStorage,
|
|
11894
11942
|
StorageApiError,
|
|
11943
|
+
REALTIME_NOT_SUPPORTED,
|
|
11895
11944
|
export_FunctionsRelayError as FunctionsRelayError,
|
|
11896
11945
|
export_FunctionsHttpError as FunctionsHttpError,
|
|
11897
11946
|
export_FunctionsFetchError as FunctionsFetchError,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
+
export declare const REALTIME_NOT_SUPPORTED = "Realtime is not supported by Bilt Cloud yet. Refetch with bilt.from(...) on an interval or when the screen regains focus instead.";
|
|
3
|
+
/**
|
|
4
|
+
* Makes every way of opening a realtime socket throw {@link REALTIME_NOT_SUPPORTED}.
|
|
5
|
+
*
|
|
6
|
+
* bilt-cloud has no realtime endpoint, so a channel would retry its socket against
|
|
7
|
+
* a 404 for as long as the app runs. `setAuth`, `getChannels`, `removeChannel` and
|
|
8
|
+
* `removeAllChannels` keep working: supabase-js calls `setAuth` on every auth
|
|
9
|
+
* change, and cleanup code must not throw.
|
|
10
|
+
*/
|
|
11
|
+
export declare function blockRealtime(client: SupabaseClient<any, any, any>): void;
|