@weirdscience/based-client 0.4.0 → 0.4.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/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAGlB,WAAW,EAEX,aAAa,EAId,MAAM,SAAS,CAAC;AAsBjB,wBAAgB,YAAY,CAC1B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,aAAa,EACjE,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAGlB,WAAW,EAEX,aAAa,EAId,MAAM,SAAS,CAAC;AAsBjB,wBAAgB,YAAY,CAC1B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,aAAa,EACjE,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAAC,CAAC,CAAC,CAkW7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-mutation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9D,KAAK,iBAAiB,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnE,wBAAgB,WAAW,CACzB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,aAAa,EACjE,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,EAE7C,KAAK,EAAE,CAAC,EACR,SAAS,EAAE,iBAAiB,GAC3B,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"use-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-mutation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9D,KAAK,iBAAiB,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnE,wBAAgB,WAAW,CACzB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,aAAa,EACjE,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,EAE7C,KAAK,EAAE,CAAC,EACR,SAAS,EAAE,iBAAiB,GAC3B,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CA0CtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-query.d.ts","sourceRoot":"","sources":["../../src/hooks/use-query.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzE,wBAAgB,QAAQ,CACtB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,aAAa,EACjE,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,EAE7C,KAAK,EAAE,CAAC,EACR,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC3B,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"use-query.d.ts","sourceRoot":"","sources":["../../src/hooks/use-query.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzE,wBAAgB,QAAQ,CACtB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,aAAa,EACjE,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,EAE7C,KAAK,EAAE,CAAC,EACR,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC3B,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CA0CnB"}
|
package/dist/index.js
CHANGED
|
@@ -223,12 +223,12 @@ function createClient(options) {
|
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
async function parseOrThrow(res, fallbackCode) {
|
|
226
|
-
let json =
|
|
226
|
+
let json = {};
|
|
227
227
|
try {
|
|
228
228
|
json = await res.json();
|
|
229
229
|
} catch {}
|
|
230
230
|
if (!res.ok) {
|
|
231
|
-
const err = json
|
|
231
|
+
const err = json.error;
|
|
232
232
|
throw new BasedError(err?.code || fallbackCode, err?.message || `Request failed with status ${res.status}`, res.status, err?.details);
|
|
233
233
|
}
|
|
234
234
|
return json;
|
|
@@ -269,22 +269,25 @@ function createClient(options) {
|
|
|
269
269
|
return json.data;
|
|
270
270
|
},
|
|
271
271
|
async update(id, data) {
|
|
272
|
-
const
|
|
272
|
+
const body = { ...data };
|
|
273
|
+
delete body.id;
|
|
273
274
|
const res = await fetchWithAuth(`${basePath}/${encodeURIComponent(id)}`, {
|
|
274
275
|
method: "PUT",
|
|
275
|
-
body: JSON.stringify(
|
|
276
|
+
body: JSON.stringify(body)
|
|
276
277
|
});
|
|
277
278
|
const json = await parseOrThrow(res, "UPDATE_FAILED");
|
|
278
279
|
return json.data;
|
|
279
280
|
},
|
|
280
281
|
async upsert(data) {
|
|
281
|
-
const {
|
|
282
|
+
const body = { ...data };
|
|
283
|
+
const id = body.id;
|
|
282
284
|
if (!id) {
|
|
283
285
|
throw new BasedError("MISSING_ID", "upsert() requires `data.id`. Use insert() to let the server generate one.", 400);
|
|
284
286
|
}
|
|
287
|
+
delete body.id;
|
|
285
288
|
const res = await fetchWithAuth(`${basePath}/${encodeURIComponent(id)}`, {
|
|
286
289
|
method: "PUT",
|
|
287
|
-
body: JSON.stringify(
|
|
290
|
+
body: JSON.stringify(body)
|
|
288
291
|
});
|
|
289
292
|
const json = await parseOrThrow(res, "UPSERT_FAILED");
|
|
290
293
|
return json.data;
|
|
@@ -351,7 +354,11 @@ function useQuery(table, options) {
|
|
|
351
354
|
setIsLoading(true);
|
|
352
355
|
setError(null);
|
|
353
356
|
try {
|
|
354
|
-
const result = await client.from(table).select({
|
|
357
|
+
const result = await client.from(table).select({
|
|
358
|
+
filter: options?.filter,
|
|
359
|
+
limit: options?.limit,
|
|
360
|
+
offset: options?.offset
|
|
361
|
+
});
|
|
355
362
|
setData(result.data);
|
|
356
363
|
setTotal(result.total);
|
|
357
364
|
} catch (err) {
|
|
@@ -427,8 +434,7 @@ function useMutation(table, operation) {
|
|
|
427
434
|
case "update": {
|
|
428
435
|
if (!data.id)
|
|
429
436
|
throw new BasedError("MISSING_ID", "Update requires an 'id' field", 400);
|
|
430
|
-
|
|
431
|
-
return await builder.update(String(id), rest);
|
|
437
|
+
return await builder.update(String(data.id), data);
|
|
432
438
|
}
|
|
433
439
|
case "upsert": {
|
|
434
440
|
if (!data.id)
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
import type { BasedClient } from "./types";
|
|
3
|
-
export declare function BasedProvider({ client, children, }: {
|
|
4
|
-
client: BasedClient
|
|
2
|
+
import type { BasedClient, DefaultTables } from "./types";
|
|
3
|
+
export declare function BasedProvider<T extends Record<string, Record<string, unknown>> = DefaultTables>({ client, children, }: {
|
|
4
|
+
client: BasedClient<T>;
|
|
5
5
|
children: ReactNode;
|
|
6
6
|
}): import("react/jsx-runtime").JSX.Element;
|
|
7
|
-
export declare function useBasedClient(): BasedClient
|
|
7
|
+
export declare function useBasedClient<T extends Record<string, Record<string, unknown>> = DefaultTables>(): BasedClient<T>;
|
|
8
8
|
//# sourceMappingURL=provider.d.ts.map
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI1D,wBAAgB,aAAa,CAC3B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,aAAa,EACjE,EACA,MAAM,EACN,QAAQ,GACT,EAAE;IACD,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAMA;AAED,wBAAgB,cAAc,CAC5B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,aAAa,KAC9D,WAAW,CAAC,CAAC,CAAC,CAMlB"}
|