@linabase/js 0.2.3 → 0.3.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/dist/index.cjs +28 -4
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +28 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -52,10 +52,9 @@ var DatabaseClient = class {
|
|
|
52
52
|
// ─── Query Methods ──────────────────────────────────────
|
|
53
53
|
/** Select columns. Supports nested joins: "*, comments(*)" and aliases: "full_name:name" */
|
|
54
54
|
select(columns, options) {
|
|
55
|
-
this.method = "GET";
|
|
56
|
-
if (columns) this.params.set("select", columns);
|
|
55
|
+
this.method = options?.head ? "HEAD" : "GET";
|
|
56
|
+
if (columns && columns !== "*") this.params.set("select", columns);
|
|
57
57
|
if (options?.count) this.preferHeaders.push(`count=${options.count}`);
|
|
58
|
-
if (options?.head) this.method = "GET";
|
|
59
58
|
return this;
|
|
60
59
|
}
|
|
61
60
|
insert(data) {
|
|
@@ -269,6 +268,7 @@ var DatabaseClient = class {
|
|
|
269
268
|
async execute() {
|
|
270
269
|
const qs = this.params.toString();
|
|
271
270
|
const path = `/rest/v1/${this.table}${qs ? `?${qs}` : ""}`;
|
|
271
|
+
const isHead = this.method === "HEAD";
|
|
272
272
|
const isSingle = this._single;
|
|
273
273
|
const isMaybeSingle = this._maybeSingle;
|
|
274
274
|
const shouldThrow = this._throwOnError;
|
|
@@ -301,8 +301,11 @@ var DatabaseClient = class {
|
|
|
301
301
|
body: this.body ? JSON.stringify(this.body) : void 0,
|
|
302
302
|
signal: abortSignal
|
|
303
303
|
});
|
|
304
|
-
const countHeader = res.headers.get("X-Total-Count");
|
|
304
|
+
const countHeader = res.headers.get("X-Total-Count") || res.headers.get("content-range")?.split("/")[1];
|
|
305
305
|
const totalCount = countHeader ? parseInt(countHeader) : null;
|
|
306
|
+
if (isHead) {
|
|
307
|
+
return { data: null, error: res.ok ? null : { message: res.statusText }, count: totalCount };
|
|
308
|
+
}
|
|
306
309
|
if (isCsv) {
|
|
307
310
|
if (!res.ok) {
|
|
308
311
|
const text = await res.text();
|
|
@@ -1072,9 +1075,30 @@ function createClient(config) {
|
|
|
1072
1075
|
});
|
|
1073
1076
|
}
|
|
1074
1077
|
const authClient = new AuthClient(request);
|
|
1078
|
+
const persistSession = config.auth?.persistSession !== false && !!config.auth?.storage;
|
|
1079
|
+
const sessionStorage = config.auth?.storage;
|
|
1080
|
+
const sessionKey = config.auth?.storageKey || "@linabase/session";
|
|
1075
1081
|
authClient.onSessionChange = (session) => {
|
|
1076
1082
|
accessToken = session?.access_token || null;
|
|
1077
1083
|
};
|
|
1084
|
+
if (persistSession && sessionStorage) {
|
|
1085
|
+
authClient.onAuthStateChange((event, session) => {
|
|
1086
|
+
if (session) {
|
|
1087
|
+
sessionStorage.setItem(sessionKey, JSON.stringify(session));
|
|
1088
|
+
} else if (event === "SIGNED_OUT") {
|
|
1089
|
+
sessionStorage.removeItem(sessionKey);
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1092
|
+
Promise.resolve(sessionStorage.getItem(sessionKey)).then((raw) => {
|
|
1093
|
+
if (raw) {
|
|
1094
|
+
try {
|
|
1095
|
+
authClient.setSession(JSON.parse(raw));
|
|
1096
|
+
} catch {
|
|
1097
|
+
sessionStorage.removeItem(sessionKey);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1078
1102
|
function buildClient(reqFn, branchSlug) {
|
|
1079
1103
|
const rc = new RpcClient(reqFn);
|
|
1080
1104
|
const ac = new AuthClient(reqFn);
|
package/dist/index.d.cts
CHANGED
|
@@ -416,10 +416,24 @@ declare class FunctionsClient {
|
|
|
416
416
|
}>;
|
|
417
417
|
}
|
|
418
418
|
|
|
419
|
+
/**
|
|
420
|
+
* Minimal async key-value storage interface (compatible with AsyncStorage, localStorage, etc.)
|
|
421
|
+
*/
|
|
422
|
+
interface SessionStorage {
|
|
423
|
+
getItem(key: string): Promise<string | null> | string | null;
|
|
424
|
+
setItem(key: string, value: string): Promise<void> | void;
|
|
425
|
+
removeItem(key: string): Promise<void> | void;
|
|
426
|
+
}
|
|
419
427
|
interface LinabaseConfig {
|
|
420
428
|
url: string;
|
|
421
429
|
anonKey?: string;
|
|
422
430
|
serviceRoleKey?: string;
|
|
431
|
+
/** Persistent storage for auth sessions (e.g., AsyncStorage for React Native). */
|
|
432
|
+
auth?: {
|
|
433
|
+
storage?: SessionStorage;
|
|
434
|
+
storageKey?: string;
|
|
435
|
+
persistSession?: boolean;
|
|
436
|
+
};
|
|
423
437
|
}
|
|
424
438
|
interface LinabaseClient {
|
|
425
439
|
from: (table: string) => DatabaseClient;
|
|
@@ -440,4 +454,4 @@ interface LinabaseClient {
|
|
|
440
454
|
}
|
|
441
455
|
declare function createClient(config: LinabaseConfig): LinabaseClient;
|
|
442
456
|
|
|
443
|
-
export { AuthClient, type AuthSession, type AuthUser, BucketClient, type CsvQueryResult, DatabaseClient, type FunctionInvokeOptions, FunctionsClient, type LinabaseClient, type LinabaseConfig, type OAuthProvider, type PostgrestError, type QueryResult, RpcClient, type SingleQueryResult, StorageClient, createClient };
|
|
457
|
+
export { AuthClient, type AuthSession, type AuthUser, BucketClient, type CsvQueryResult, DatabaseClient, type FunctionInvokeOptions, FunctionsClient, type LinabaseClient, type LinabaseConfig, type OAuthProvider, type PostgrestError, type QueryResult, RpcClient, type SessionStorage, type SingleQueryResult, StorageClient, createClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -416,10 +416,24 @@ declare class FunctionsClient {
|
|
|
416
416
|
}>;
|
|
417
417
|
}
|
|
418
418
|
|
|
419
|
+
/**
|
|
420
|
+
* Minimal async key-value storage interface (compatible with AsyncStorage, localStorage, etc.)
|
|
421
|
+
*/
|
|
422
|
+
interface SessionStorage {
|
|
423
|
+
getItem(key: string): Promise<string | null> | string | null;
|
|
424
|
+
setItem(key: string, value: string): Promise<void> | void;
|
|
425
|
+
removeItem(key: string): Promise<void> | void;
|
|
426
|
+
}
|
|
419
427
|
interface LinabaseConfig {
|
|
420
428
|
url: string;
|
|
421
429
|
anonKey?: string;
|
|
422
430
|
serviceRoleKey?: string;
|
|
431
|
+
/** Persistent storage for auth sessions (e.g., AsyncStorage for React Native). */
|
|
432
|
+
auth?: {
|
|
433
|
+
storage?: SessionStorage;
|
|
434
|
+
storageKey?: string;
|
|
435
|
+
persistSession?: boolean;
|
|
436
|
+
};
|
|
423
437
|
}
|
|
424
438
|
interface LinabaseClient {
|
|
425
439
|
from: (table: string) => DatabaseClient;
|
|
@@ -440,4 +454,4 @@ interface LinabaseClient {
|
|
|
440
454
|
}
|
|
441
455
|
declare function createClient(config: LinabaseConfig): LinabaseClient;
|
|
442
456
|
|
|
443
|
-
export { AuthClient, type AuthSession, type AuthUser, BucketClient, type CsvQueryResult, DatabaseClient, type FunctionInvokeOptions, FunctionsClient, type LinabaseClient, type LinabaseConfig, type OAuthProvider, type PostgrestError, type QueryResult, RpcClient, type SingleQueryResult, StorageClient, createClient };
|
|
457
|
+
export { AuthClient, type AuthSession, type AuthUser, BucketClient, type CsvQueryResult, DatabaseClient, type FunctionInvokeOptions, FunctionsClient, type LinabaseClient, type LinabaseConfig, type OAuthProvider, type PostgrestError, type QueryResult, RpcClient, type SessionStorage, type SingleQueryResult, StorageClient, createClient };
|
package/dist/index.js
CHANGED
|
@@ -20,10 +20,9 @@ var DatabaseClient = class {
|
|
|
20
20
|
// ─── Query Methods ──────────────────────────────────────
|
|
21
21
|
/** Select columns. Supports nested joins: "*, comments(*)" and aliases: "full_name:name" */
|
|
22
22
|
select(columns, options) {
|
|
23
|
-
this.method = "GET";
|
|
24
|
-
if (columns) this.params.set("select", columns);
|
|
23
|
+
this.method = options?.head ? "HEAD" : "GET";
|
|
24
|
+
if (columns && columns !== "*") this.params.set("select", columns);
|
|
25
25
|
if (options?.count) this.preferHeaders.push(`count=${options.count}`);
|
|
26
|
-
if (options?.head) this.method = "GET";
|
|
27
26
|
return this;
|
|
28
27
|
}
|
|
29
28
|
insert(data) {
|
|
@@ -237,6 +236,7 @@ var DatabaseClient = class {
|
|
|
237
236
|
async execute() {
|
|
238
237
|
const qs = this.params.toString();
|
|
239
238
|
const path = `/rest/v1/${this.table}${qs ? `?${qs}` : ""}`;
|
|
239
|
+
const isHead = this.method === "HEAD";
|
|
240
240
|
const isSingle = this._single;
|
|
241
241
|
const isMaybeSingle = this._maybeSingle;
|
|
242
242
|
const shouldThrow = this._throwOnError;
|
|
@@ -269,8 +269,11 @@ var DatabaseClient = class {
|
|
|
269
269
|
body: this.body ? JSON.stringify(this.body) : void 0,
|
|
270
270
|
signal: abortSignal
|
|
271
271
|
});
|
|
272
|
-
const countHeader = res.headers.get("X-Total-Count");
|
|
272
|
+
const countHeader = res.headers.get("X-Total-Count") || res.headers.get("content-range")?.split("/")[1];
|
|
273
273
|
const totalCount = countHeader ? parseInt(countHeader) : null;
|
|
274
|
+
if (isHead) {
|
|
275
|
+
return { data: null, error: res.ok ? null : { message: res.statusText }, count: totalCount };
|
|
276
|
+
}
|
|
274
277
|
if (isCsv) {
|
|
275
278
|
if (!res.ok) {
|
|
276
279
|
const text = await res.text();
|
|
@@ -1040,9 +1043,30 @@ function createClient(config) {
|
|
|
1040
1043
|
});
|
|
1041
1044
|
}
|
|
1042
1045
|
const authClient = new AuthClient(request);
|
|
1046
|
+
const persistSession = config.auth?.persistSession !== false && !!config.auth?.storage;
|
|
1047
|
+
const sessionStorage = config.auth?.storage;
|
|
1048
|
+
const sessionKey = config.auth?.storageKey || "@linabase/session";
|
|
1043
1049
|
authClient.onSessionChange = (session) => {
|
|
1044
1050
|
accessToken = session?.access_token || null;
|
|
1045
1051
|
};
|
|
1052
|
+
if (persistSession && sessionStorage) {
|
|
1053
|
+
authClient.onAuthStateChange((event, session) => {
|
|
1054
|
+
if (session) {
|
|
1055
|
+
sessionStorage.setItem(sessionKey, JSON.stringify(session));
|
|
1056
|
+
} else if (event === "SIGNED_OUT") {
|
|
1057
|
+
sessionStorage.removeItem(sessionKey);
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1060
|
+
Promise.resolve(sessionStorage.getItem(sessionKey)).then((raw) => {
|
|
1061
|
+
if (raw) {
|
|
1062
|
+
try {
|
|
1063
|
+
authClient.setSession(JSON.parse(raw));
|
|
1064
|
+
} catch {
|
|
1065
|
+
sessionStorage.removeItem(sessionKey);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1046
1070
|
function buildClient(reqFn, branchSlug) {
|
|
1047
1071
|
const rc = new RpcClient(reqFn);
|
|
1048
1072
|
const ac = new AuthClient(reqFn);
|