@picobase_app/client 0.1.2 → 0.5.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 +8 -6
- package/dist/index.d.mts +55 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.js +82 -67
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +63 -18
- package/dist/index.mjs.map +1 -0
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -8,6 +8,8 @@ TypeScript SDK for PicoBase — add auth, database, realtime, and file storage t
|
|
|
8
8
|
npm install @picobase_app/client
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
> ⚠️ **Important:** Always install `@picobase_app/client`. If you accidentally installed `pocketbase`, remove it — that's an internal dependency, not the user-facing SDK.
|
|
12
|
+
|
|
11
13
|
## Quickstart
|
|
12
14
|
|
|
13
15
|
```typescript
|
|
@@ -176,11 +178,11 @@ const results = await pb.rpc('search_products', {
|
|
|
176
178
|
})
|
|
177
179
|
```
|
|
178
180
|
|
|
179
|
-
RPC calls are mapped to custom
|
|
181
|
+
RPC calls are mapped to custom endpoints at `/api/rpc/{functionName}`. You can implement these routes in your PicoBase instance.
|
|
180
182
|
|
|
181
183
|
## File Storage
|
|
182
184
|
|
|
183
|
-
|
|
185
|
+
PicoBase stores files as fields on records. Use the storage module to get URLs.
|
|
184
186
|
|
|
185
187
|
```typescript
|
|
186
188
|
const user = await pb.collection('users').getOne('USER_ID')
|
|
@@ -206,12 +208,12 @@ pb.auth.setCollection('members')
|
|
|
206
208
|
await pb.auth.signIn({ email: 'member@example.com', password: 'pass' })
|
|
207
209
|
```
|
|
208
210
|
|
|
209
|
-
### Raw
|
|
211
|
+
### Raw access (advanced)
|
|
210
212
|
|
|
211
|
-
The underlying
|
|
213
|
+
The underlying client instance is exposed for advanced use cases.
|
|
212
214
|
|
|
213
215
|
```typescript
|
|
214
|
-
// Access the
|
|
216
|
+
// Access the internal client directly
|
|
215
217
|
const health = await pb.pb.health.check()
|
|
216
218
|
|
|
217
219
|
// Custom API endpoint
|
|
@@ -297,4 +299,4 @@ result.items[0].title // string — fully typed!
|
|
|
297
299
|
| `pb.collection(name)` | `PicoBaseCollection` | CRUD operations on a collection |
|
|
298
300
|
| `pb.realtime` | `PicoBaseRealtime` | Realtime subscriptions |
|
|
299
301
|
| `pb.storage` | `PicoBaseStorage` | File URLs and tokens |
|
|
300
|
-
| `pb.pb` | `PocketBase` | Underlying
|
|
302
|
+
| `pb.pb` | `PocketBase` | Underlying internal client instance |
|
package/dist/index.d.mts
CHANGED
|
@@ -57,6 +57,33 @@ interface FileOptions {
|
|
|
57
57
|
token?: string;
|
|
58
58
|
download?: boolean;
|
|
59
59
|
}
|
|
60
|
+
type CollectionType = 'base' | 'auth' | 'view';
|
|
61
|
+
interface CollectionModel {
|
|
62
|
+
id: string;
|
|
63
|
+
created: string;
|
|
64
|
+
updated: string;
|
|
65
|
+
name: string;
|
|
66
|
+
type: CollectionType;
|
|
67
|
+
system: boolean;
|
|
68
|
+
schema: SchemaField[];
|
|
69
|
+
indexes: string[];
|
|
70
|
+
listRule: string | null;
|
|
71
|
+
viewRule: string | null;
|
|
72
|
+
createRule: string | null;
|
|
73
|
+
updateRule: string | null;
|
|
74
|
+
deleteRule: string | null;
|
|
75
|
+
options: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
interface SchemaField {
|
|
78
|
+
system: boolean;
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
type: string;
|
|
82
|
+
required: boolean;
|
|
83
|
+
presentable: boolean;
|
|
84
|
+
unique: boolean;
|
|
85
|
+
options: Record<string, unknown>;
|
|
86
|
+
}
|
|
60
87
|
|
|
61
88
|
/**
|
|
62
89
|
* Auth module — handles user sign-up, sign-in, OAuth, and session management.
|
|
@@ -384,6 +411,31 @@ declare class PicoBaseStorage {
|
|
|
384
411
|
getFileToken(): Promise<string>;
|
|
385
412
|
}
|
|
386
413
|
|
|
414
|
+
declare class PicoBaseAdmin {
|
|
415
|
+
private pb;
|
|
416
|
+
constructor(pb: PocketBase);
|
|
417
|
+
/**
|
|
418
|
+
* Fetch a list of all collections.
|
|
419
|
+
*/
|
|
420
|
+
listCollections(): Promise<CollectionModel[]>;
|
|
421
|
+
/**
|
|
422
|
+
* Fetch a single collection by ID or name.
|
|
423
|
+
*/
|
|
424
|
+
getCollection(idOrName: string): Promise<CollectionModel>;
|
|
425
|
+
/**
|
|
426
|
+
* Create a new collection.
|
|
427
|
+
*/
|
|
428
|
+
createCollection(data: Partial<CollectionModel>): Promise<CollectionModel>;
|
|
429
|
+
/**
|
|
430
|
+
* Update an existing collection.
|
|
431
|
+
*/
|
|
432
|
+
updateCollection(idOrName: string, data: Partial<CollectionModel>): Promise<CollectionModel>;
|
|
433
|
+
/**
|
|
434
|
+
* Delete a collection.
|
|
435
|
+
*/
|
|
436
|
+
deleteCollection(idOrName: string): Promise<boolean>;
|
|
437
|
+
}
|
|
438
|
+
|
|
387
439
|
declare class PicoBaseClient {
|
|
388
440
|
/** The underlying PocketBase SDK instance. Exposed for advanced usage. */
|
|
389
441
|
readonly pb: PocketBase;
|
|
@@ -393,6 +445,8 @@ declare class PicoBaseClient {
|
|
|
393
445
|
readonly realtime: PicoBaseRealtime;
|
|
394
446
|
/** Storage module — get file URLs and tokens. */
|
|
395
447
|
readonly storage: PicoBaseStorage;
|
|
448
|
+
/** Admin module — manage collections (requires admin API key). */
|
|
449
|
+
readonly admin: PicoBaseAdmin;
|
|
396
450
|
private readonly apiKey;
|
|
397
451
|
private readonly options;
|
|
398
452
|
constructor(url: string, apiKey: string, options?: PicoBaseClientOptions);
|
|
@@ -548,4 +602,4 @@ declare class RpcError extends PicoBaseError {
|
|
|
548
602
|
constructor(functionName: string, status: number, details?: unknown);
|
|
549
603
|
}
|
|
550
604
|
|
|
551
|
-
export { type AuthEvent, type AuthResponse, type AuthStateChange, type AuthStateChangeCallback, AuthorizationError, CollectionNotFoundError, ConfigurationError, type FileOptions, InstanceUnavailableError, type ListOptions, type OAuthSignInOptions, PicoBaseAuth, PicoBaseClient, type PicoBaseClientOptions, PicoBaseCollection, PicoBaseError, PicoBaseRealtime, PicoBaseStorage, type RealtimeAction, type RealtimeCallback, RecordNotFoundError, type RecordQueryOptions, RequestError, RpcError, type SignInOptions, type SignUpOptions, type UnsubscribeFunc, createClient };
|
|
605
|
+
export { type AuthEvent, type AuthResponse, type AuthStateChange, type AuthStateChangeCallback, AuthorizationError, CollectionNotFoundError, ConfigurationError, type FileOptions, InstanceUnavailableError, type ListOptions, type OAuthSignInOptions, PicoBaseAdmin, PicoBaseAuth, PicoBaseClient, type PicoBaseClientOptions, PicoBaseCollection, PicoBaseError, PicoBaseRealtime, PicoBaseStorage, type RealtimeAction, type RealtimeCallback, RecordNotFoundError, type RecordQueryOptions, RequestError, RpcError, type SignInOptions, type SignUpOptions, type UnsubscribeFunc, createClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -57,6 +57,33 @@ interface FileOptions {
|
|
|
57
57
|
token?: string;
|
|
58
58
|
download?: boolean;
|
|
59
59
|
}
|
|
60
|
+
type CollectionType = 'base' | 'auth' | 'view';
|
|
61
|
+
interface CollectionModel {
|
|
62
|
+
id: string;
|
|
63
|
+
created: string;
|
|
64
|
+
updated: string;
|
|
65
|
+
name: string;
|
|
66
|
+
type: CollectionType;
|
|
67
|
+
system: boolean;
|
|
68
|
+
schema: SchemaField[];
|
|
69
|
+
indexes: string[];
|
|
70
|
+
listRule: string | null;
|
|
71
|
+
viewRule: string | null;
|
|
72
|
+
createRule: string | null;
|
|
73
|
+
updateRule: string | null;
|
|
74
|
+
deleteRule: string | null;
|
|
75
|
+
options: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
interface SchemaField {
|
|
78
|
+
system: boolean;
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
type: string;
|
|
82
|
+
required: boolean;
|
|
83
|
+
presentable: boolean;
|
|
84
|
+
unique: boolean;
|
|
85
|
+
options: Record<string, unknown>;
|
|
86
|
+
}
|
|
60
87
|
|
|
61
88
|
/**
|
|
62
89
|
* Auth module — handles user sign-up, sign-in, OAuth, and session management.
|
|
@@ -384,6 +411,31 @@ declare class PicoBaseStorage {
|
|
|
384
411
|
getFileToken(): Promise<string>;
|
|
385
412
|
}
|
|
386
413
|
|
|
414
|
+
declare class PicoBaseAdmin {
|
|
415
|
+
private pb;
|
|
416
|
+
constructor(pb: PocketBase);
|
|
417
|
+
/**
|
|
418
|
+
* Fetch a list of all collections.
|
|
419
|
+
*/
|
|
420
|
+
listCollections(): Promise<CollectionModel[]>;
|
|
421
|
+
/**
|
|
422
|
+
* Fetch a single collection by ID or name.
|
|
423
|
+
*/
|
|
424
|
+
getCollection(idOrName: string): Promise<CollectionModel>;
|
|
425
|
+
/**
|
|
426
|
+
* Create a new collection.
|
|
427
|
+
*/
|
|
428
|
+
createCollection(data: Partial<CollectionModel>): Promise<CollectionModel>;
|
|
429
|
+
/**
|
|
430
|
+
* Update an existing collection.
|
|
431
|
+
*/
|
|
432
|
+
updateCollection(idOrName: string, data: Partial<CollectionModel>): Promise<CollectionModel>;
|
|
433
|
+
/**
|
|
434
|
+
* Delete a collection.
|
|
435
|
+
*/
|
|
436
|
+
deleteCollection(idOrName: string): Promise<boolean>;
|
|
437
|
+
}
|
|
438
|
+
|
|
387
439
|
declare class PicoBaseClient {
|
|
388
440
|
/** The underlying PocketBase SDK instance. Exposed for advanced usage. */
|
|
389
441
|
readonly pb: PocketBase;
|
|
@@ -393,6 +445,8 @@ declare class PicoBaseClient {
|
|
|
393
445
|
readonly realtime: PicoBaseRealtime;
|
|
394
446
|
/** Storage module — get file URLs and tokens. */
|
|
395
447
|
readonly storage: PicoBaseStorage;
|
|
448
|
+
/** Admin module — manage collections (requires admin API key). */
|
|
449
|
+
readonly admin: PicoBaseAdmin;
|
|
396
450
|
private readonly apiKey;
|
|
397
451
|
private readonly options;
|
|
398
452
|
constructor(url: string, apiKey: string, options?: PicoBaseClientOptions);
|
|
@@ -548,4 +602,4 @@ declare class RpcError extends PicoBaseError {
|
|
|
548
602
|
constructor(functionName: string, status: number, details?: unknown);
|
|
549
603
|
}
|
|
550
604
|
|
|
551
|
-
export { type AuthEvent, type AuthResponse, type AuthStateChange, type AuthStateChangeCallback, AuthorizationError, CollectionNotFoundError, ConfigurationError, type FileOptions, InstanceUnavailableError, type ListOptions, type OAuthSignInOptions, PicoBaseAuth, PicoBaseClient, type PicoBaseClientOptions, PicoBaseCollection, PicoBaseError, PicoBaseRealtime, PicoBaseStorage, type RealtimeAction, type RealtimeCallback, RecordNotFoundError, type RecordQueryOptions, RequestError, RpcError, type SignInOptions, type SignUpOptions, type UnsubscribeFunc, createClient };
|
|
605
|
+
export { type AuthEvent, type AuthResponse, type AuthStateChange, type AuthStateChangeCallback, AuthorizationError, CollectionNotFoundError, ConfigurationError, type FileOptions, InstanceUnavailableError, type ListOptions, type OAuthSignInOptions, PicoBaseAdmin, PicoBaseAuth, PicoBaseClient, type PicoBaseClientOptions, PicoBaseCollection, PicoBaseError, PicoBaseRealtime, PicoBaseStorage, type RealtimeAction, type RealtimeCallback, RecordNotFoundError, type RecordQueryOptions, RequestError, RpcError, type SignInOptions, type SignUpOptions, type UnsubscribeFunc, createClient };
|
package/dist/index.js
CHANGED
|
@@ -1,54 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var PocketBase = require('pocketbase');
|
|
4
|
+
|
|
5
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
29
6
|
|
|
30
|
-
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
AuthorizationError: () => AuthorizationError,
|
|
34
|
-
CollectionNotFoundError: () => CollectionNotFoundError,
|
|
35
|
-
ConfigurationError: () => ConfigurationError,
|
|
36
|
-
InstanceUnavailableError: () => InstanceUnavailableError,
|
|
37
|
-
PicoBaseAuth: () => PicoBaseAuth,
|
|
38
|
-
PicoBaseClient: () => PicoBaseClient,
|
|
39
|
-
PicoBaseCollection: () => PicoBaseCollection,
|
|
40
|
-
PicoBaseError: () => PicoBaseError,
|
|
41
|
-
PicoBaseRealtime: () => PicoBaseRealtime,
|
|
42
|
-
PicoBaseStorage: () => PicoBaseStorage,
|
|
43
|
-
RecordNotFoundError: () => RecordNotFoundError,
|
|
44
|
-
RequestError: () => RequestError,
|
|
45
|
-
RpcError: () => RpcError,
|
|
46
|
-
createClient: () => createClient
|
|
47
|
-
});
|
|
48
|
-
module.exports = __toCommonJS(index_exports);
|
|
7
|
+
var PocketBase__default = /*#__PURE__*/_interopDefault(PocketBase);
|
|
49
8
|
|
|
50
9
|
// src/client.ts
|
|
51
|
-
var import_pocketbase = __toESM(require("pocketbase"));
|
|
52
10
|
|
|
53
11
|
// src/auth.ts
|
|
54
12
|
var PicoBaseAuth = class {
|
|
@@ -75,7 +33,7 @@ var PicoBaseAuth = class {
|
|
|
75
33
|
*/
|
|
76
34
|
async signUp(options) {
|
|
77
35
|
const { email, password, passwordConfirm, ...rest } = options;
|
|
78
|
-
|
|
36
|
+
await this.pb.collection(this._collection).create({
|
|
79
37
|
email,
|
|
80
38
|
password,
|
|
81
39
|
passwordConfirm: passwordConfirm ?? password,
|
|
@@ -382,6 +340,61 @@ var PicoBaseStorage = class {
|
|
|
382
340
|
}
|
|
383
341
|
};
|
|
384
342
|
|
|
343
|
+
// src/admin.ts
|
|
344
|
+
var PicoBaseAdmin = class {
|
|
345
|
+
constructor(pb) {
|
|
346
|
+
this.pb = pb;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Fetch a list of all collections.
|
|
350
|
+
*/
|
|
351
|
+
async listCollections() {
|
|
352
|
+
const result = await this.pb.send("/api/collections", {
|
|
353
|
+
method: "GET"
|
|
354
|
+
});
|
|
355
|
+
return result.items || [];
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Fetch a single collection by ID or name.
|
|
359
|
+
*/
|
|
360
|
+
async getCollection(idOrName) {
|
|
361
|
+
return this.pb.send(`/api/collections/${idOrName}`, {
|
|
362
|
+
method: "GET"
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Create a new collection.
|
|
367
|
+
*/
|
|
368
|
+
async createCollection(data) {
|
|
369
|
+
return this.pb.send("/api/collections", {
|
|
370
|
+
method: "POST",
|
|
371
|
+
body: data
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Update an existing collection.
|
|
376
|
+
*/
|
|
377
|
+
async updateCollection(idOrName, data) {
|
|
378
|
+
return this.pb.send(`/api/collections/${idOrName}`, {
|
|
379
|
+
method: "PATCH",
|
|
380
|
+
body: data
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Delete a collection.
|
|
385
|
+
*/
|
|
386
|
+
async deleteCollection(idOrName) {
|
|
387
|
+
try {
|
|
388
|
+
await this.pb.send(`/api/collections/${idOrName}`, {
|
|
389
|
+
method: "DELETE"
|
|
390
|
+
});
|
|
391
|
+
return true;
|
|
392
|
+
} catch (e) {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
|
|
385
398
|
// src/errors.ts
|
|
386
399
|
var PicoBaseError = class extends Error {
|
|
387
400
|
constructor(message, code, status, details, fix) {
|
|
@@ -534,7 +547,7 @@ var PicoBaseClient = class {
|
|
|
534
547
|
this.apiKey = apiKey;
|
|
535
548
|
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
536
549
|
const baseUrl = url.replace(/\/+$/, "");
|
|
537
|
-
this.pb = new
|
|
550
|
+
this.pb = new PocketBase__default.default(baseUrl);
|
|
538
551
|
this.pb.autoCancellation(false);
|
|
539
552
|
if (this.options.lang) {
|
|
540
553
|
this.pb.lang = this.options.lang;
|
|
@@ -549,6 +562,7 @@ var PicoBaseClient = class {
|
|
|
549
562
|
this.auth = new PicoBaseAuth(this.pb);
|
|
550
563
|
this.realtime = new PicoBaseRealtime(this.pb);
|
|
551
564
|
this.storage = new PicoBaseStorage(this.pb);
|
|
565
|
+
this.admin = new PicoBaseAdmin(this.pb);
|
|
552
566
|
}
|
|
553
567
|
/**
|
|
554
568
|
* Access a collection for CRUD operations.
|
|
@@ -682,20 +696,21 @@ function createClient(urlOrOptions, apiKeyOrUndefined, options) {
|
|
|
682
696
|
}
|
|
683
697
|
return new PicoBaseClient(urlOrOptions, apiKeyOrUndefined, options);
|
|
684
698
|
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
699
|
+
|
|
700
|
+
exports.AuthorizationError = AuthorizationError;
|
|
701
|
+
exports.CollectionNotFoundError = CollectionNotFoundError;
|
|
702
|
+
exports.ConfigurationError = ConfigurationError;
|
|
703
|
+
exports.InstanceUnavailableError = InstanceUnavailableError;
|
|
704
|
+
exports.PicoBaseAdmin = PicoBaseAdmin;
|
|
705
|
+
exports.PicoBaseAuth = PicoBaseAuth;
|
|
706
|
+
exports.PicoBaseClient = PicoBaseClient;
|
|
707
|
+
exports.PicoBaseCollection = PicoBaseCollection;
|
|
708
|
+
exports.PicoBaseError = PicoBaseError;
|
|
709
|
+
exports.PicoBaseRealtime = PicoBaseRealtime;
|
|
710
|
+
exports.PicoBaseStorage = PicoBaseStorage;
|
|
711
|
+
exports.RecordNotFoundError = RecordNotFoundError;
|
|
712
|
+
exports.RequestError = RequestError;
|
|
713
|
+
exports.RpcError = RpcError;
|
|
714
|
+
exports.createClient = createClient;
|
|
715
|
+
//# sourceMappingURL=index.js.map
|
|
716
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/auth.ts","../src/collection.ts","../src/realtime.ts","../src/storage.ts","../src/admin.ts","../src/errors.ts","../src/client.ts"],"names":["PocketBase","url"],"mappings":";;;;;;;;;;;AAqCO,IAAM,eAAN,MAAmB;AAAA,EAKxB,YAAY,EAAA,EAAgB;AAH5B,IAAA,IAAA,CAAQ,SAAA,uBAA8C,GAAA,EAAI;AAC1D,IAAA,IAAA,CAAQ,WAAA,GAAsB,OAAA;AAG5B,IAAA,IAAA,CAAK,EAAA,GAAK,EAAA;AAGV,I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AAI,kBAAA;AAAA,QACR,CAAA,4BAAA,EAA+B,CAAC,GAAA,IAAO,CAAC,SAAS,GAAA,GAAM,EAAE,KAAK,OAAO,CAAA,CAAA;AAAA,QACrE;AAAA,OAQF;AAAA,IACF;AAEA,IAAA,OAAO,IAAI,cAAA,CAAe,GAAA,EAAK,MAAA,EAAQ,YAAY,CAAA;AAAA,EACrD;AAEA,EAAA,OAAO,IAAI,cAAA,CAAe,YAAA,EAAc,iBAAA,EAAoB,OAAO,CAAA;AACrE","file":"index.js","sourcesContent":["import type PocketBase from 'pocketbase'\nimport type {\n AuthResponse,\n AuthStateChangeCallback,\n AuthEvent,\n SignUpOptions,\n SignInOptions,\n OAuthSignInOptions,\n RecordModel,\n} from './types'\n\n/**\n * Auth module — handles user sign-up, sign-in, OAuth, and session management.\n *\n * PicoBase uses PocketBase's built-in `users` collection for auth. Each\n * instance has its own isolated user pool.\n *\n * @example\n * ```ts\n * // Sign up\n * const { token, record } = await pb.auth.signUp({\n * email: 'user@example.com',\n * password: 'securepassword',\n * })\n *\n * // Sign in\n * const { token, record } = await pb.auth.signIn({\n * email: 'user@example.com',\n * password: 'securepassword',\n * })\n *\n * // Listen to auth changes\n * pb.auth.onStateChange((event, record) => {\n * console.log(event, record)\n * })\n * ```\n */\nexport class PicoBaseAuth {\n private pb: PocketBase\n private listeners: Set<AuthStateChangeCallback> = new Set()\n private _collection: string = 'users'\n\n constructor(pb: PocketBase) {\n this.pb = pb\n\n // Listen to PocketBase auth store changes and re-emit\n this.pb.authStore.onChange((token) => {\n const record = this.pb.authStore.record ?? null\n const event: AuthEvent = token ? 'SIGNED_IN' : 'SIGNED_OUT'\n this._notify(event, record)\n })\n }\n\n /**\n * Set which collection to authenticate against.\n * Defaults to 'users'. Use this if you have a custom auth collection.\n */\n setCollection(name: string): this {\n this._collection = name\n return this\n }\n\n /**\n * Create a new user account.\n */\n async signUp(options: SignUpOptions): Promise<AuthResponse> {\n const { email, password, passwordConfirm, ...rest } = options\n\n const record = await this.pb.collection(this._collection).create<RecordModel>({\n email,\n password,\n passwordConfirm: passwordConfirm ?? password,\n ...rest,\n })\n\n // Automatically sign in after sign-up\n const authResult = await this.pb\n .collection(this._collection)\n .authWithPassword<RecordModel>(email, password)\n\n return {\n token: authResult.token,\n record: authResult.record,\n }\n }\n\n /**\n * Sign in with email and password.\n */\n async signIn(options: SignInOptions): Promise<AuthResponse> {\n const result = await this.pb\n .collection(this._collection)\n .authWithPassword<RecordModel>(options.email, options.password)\n\n return {\n token: result.token,\n record: result.record,\n }\n }\n\n /**\n * Sign in with an OAuth2 provider (Google, GitHub, etc.).\n *\n * In browser environments this opens a popup/redirect to the provider.\n * Configure providers in your PicoBase dashboard.\n */\n async signInWithOAuth(options: OAuthSignInOptions): Promise<AuthResponse> {\n const result = await this.pb.collection(this._collection).authWithOAuth2({\n provider: options.provider,\n scopes: options.scopes,\n createData: options.createData,\n urlCallback: options.urlCallback,\n })\n\n return {\n token: result.token,\n record: result.record,\n }\n }\n\n /**\n * Refresh the current auth token.\n */\n async refreshToken(): Promise<AuthResponse> {\n const result = await this.pb.collection(this._collection).authRefresh<RecordModel>()\n this._notify('TOKEN_REFRESHED', result.record)\n return {\n token: result.token,\n record: result.record,\n }\n }\n\n /**\n * Send a password reset email.\n */\n async requestPasswordReset(email: string): Promise<void> {\n await this.pb.collection(this._collection).requestPasswordReset(email)\n }\n\n /**\n * Confirm a password reset with the token from the reset email.\n */\n async confirmPasswordReset(\n token: string,\n password: string,\n passwordConfirm?: string,\n ): Promise<void> {\n await this.pb\n .collection(this._collection)\n .confirmPasswordReset(token, password, passwordConfirm ?? password)\n }\n\n /**\n * Send an email verification email.\n */\n async requestVerification(email: string): Promise<void> {\n await this.pb.collection(this._collection).requestVerification(email)\n }\n\n /**\n * Confirm email verification with the token from the verification email.\n */\n async confirmVerification(token: string): Promise<void> {\n await this.pb.collection(this._collection).confirmVerification(token)\n }\n\n /**\n * Sign out the current user. Clears the local auth store.\n */\n signOut(): void {\n this.pb.authStore.clear()\n }\n\n /**\n * Get the currently authenticated user record, or `null` if not signed in.\n */\n get user(): RecordModel | null {\n return this.pb.authStore.record\n }\n\n /**\n * Get the current auth token, or empty string if not signed in.\n */\n get token(): string {\n return this.pb.authStore.token\n }\n\n /**\n * Check if the current auth session is valid (token exists and not expired).\n */\n get isValid(): boolean {\n return this.pb.authStore.isValid\n }\n\n /**\n * Listen to auth state changes. Returns an unsubscribe function.\n *\n * @example\n * ```ts\n * const unsubscribe = pb.auth.onStateChange((event, record) => {\n * if (event === 'SIGNED_IN') {\n * console.log('Welcome', record.email)\n * }\n * })\n *\n * // Later:\n * unsubscribe()\n * ```\n */\n onStateChange(callback: AuthStateChangeCallback): () => void {\n this.listeners.add(callback)\n return () => {\n this.listeners.delete(callback)\n }\n }\n\n private _notify(event: AuthEvent, record: RecordModel | null): void {\n for (const cb of this.listeners) {\n try {\n cb(event, record)\n } catch {\n // Don't let one listener crash others\n }\n }\n }\n}\n","import type PocketBase from 'pocketbase'\nimport type { RecordModel, ListResult } from 'pocketbase'\n\n/** Options for list queries. */\nexport interface ListOptions {\n sort?: string\n filter?: string\n expand?: string\n fields?: string\n skipTotal?: boolean\n [key: string]: unknown\n}\n\n/** Options for single record queries. */\nexport interface RecordQueryOptions {\n expand?: string\n fields?: string\n [key: string]: unknown\n}\n\n/**\n * Collection module — CRUD operations on a PocketBase collection.\n *\n * @example\n * ```ts\n * const posts = pb.collection('posts')\n *\n * // List with filtering, sorting, and pagination\n * const result = await posts.getList(1, 20, {\n * filter: 'published = true',\n * sort: '-created',\n * expand: 'author',\n * })\n *\n * // Get a single record\n * const post = await posts.getOne('record_id')\n *\n * // Create a record\n * const newPost = await posts.create({\n * title: 'Hello World',\n * content: 'My first post',\n * })\n *\n * // Update a record\n * const updated = await posts.update('record_id', { title: 'Updated' })\n *\n * // Delete a record\n * await posts.delete('record_id')\n * ```\n */\nexport class PicoBaseCollection<T = RecordModel> {\n private pb: PocketBase\n private name: string\n\n constructor(pb: PocketBase, name: string) {\n this.pb = pb\n this.name = name\n }\n\n /**\n * Fetch a paginated list of records.\n *\n * @param page - Page number (1-indexed). Default: 1.\n * @param perPage - Records per page. Default: 30.\n * @param options - Filter, sort, expand, fields.\n */\n async getList(page = 1, perPage = 30, options: ListOptions = {}): Promise<ListResult<T>> {\n return this.pb.collection(this.name).getList<T>(page, perPage, options)\n }\n\n /**\n * Fetch all records matching the filter (auto-paginates).\n *\n * **Warning:** Use with caution on large collections. Prefer `getList()` with pagination.\n */\n async getFullList(options: ListOptions = {}): Promise<T[]> {\n return this.pb.collection(this.name).getFullList<T>(options)\n }\n\n /**\n * Fetch a single record by ID.\n */\n async getOne(id: string, options: RecordQueryOptions = {}): Promise<T> {\n return this.pb.collection(this.name).getOne<T>(id, options)\n }\n\n /**\n * Fetch the first record matching a filter.\n *\n * @example\n * ```ts\n * const admin = await pb.collection('users').getFirstListItem('role = \"admin\"')\n * ```\n */\n async getFirstListItem(filter: string, options: RecordQueryOptions = {}): Promise<T> {\n return this.pb.collection(this.name).getFirstListItem<T>(filter, options)\n }\n\n /**\n * Create a new record.\n *\n * @param data - Record data. Can be a plain object or `FormData` (for file uploads).\n */\n async create(data: Record<string, unknown> | FormData, options: RecordQueryOptions = {}): Promise<T> {\n return this.pb.collection(this.name).create<T>(data, options)\n }\n\n /**\n * Update an existing record.\n *\n * @param id - Record ID.\n * @param data - Fields to update. Can be a plain object or `FormData`.\n */\n async update(id: string, data: Record<string, unknown> | FormData, options: RecordQueryOptions = {}): Promise<T> {\n return this.pb.collection(this.name).update<T>(id, data, options)\n }\n\n /**\n * Delete a record by ID.\n */\n async delete(id: string): Promise<boolean> {\n return this.pb.collection(this.name).delete(id)\n }\n\n /**\n * Subscribe to realtime changes on this collection.\n *\n * @param callback - Called on every create/update/delete event.\n * @param filter - Optional: only receive events matching this filter.\n * @returns Unsubscribe function.\n *\n * @example\n * ```ts\n * const unsubscribe = await pb.collection('posts').subscribe((e) => {\n * console.log(e.action, e.record)\n * })\n *\n * // Later:\n * await unsubscribe()\n * ```\n */\n async subscribe(\n callback: (data: { action: string; record: T }) => void,\n filter?: string,\n ): Promise<() => Promise<void>> {\n const topic = '*'\n await this.pb.collection(this.name).subscribe<T>(topic, callback, filter ? { filter } : undefined)\n return () => this.pb.collection(this.name).unsubscribe(topic)\n }\n\n /**\n * Subscribe to changes on a specific record.\n *\n * @param id - Record ID.\n * @param callback - Called on update/delete events.\n * @returns Unsubscribe function.\n */\n async subscribeOne(\n id: string,\n callback: (data: { action: string; record: T }) => void,\n ): Promise<() => Promise<void>> {\n await this.pb.collection(this.name).subscribe<T>(id, callback)\n return () => this.pb.collection(this.name).unsubscribe(id)\n }\n}\n","import type PocketBase from 'pocketbase'\nimport type { RecordModel, RecordSubscription } from './types'\n\n/**\n * Realtime module — manage global realtime subscriptions.\n *\n * For collection-level subscriptions, prefer `pb.collection('name').subscribe()`.\n * This module is for lower-level control over the SSE connection.\n *\n * @example\n * ```ts\n * // Subscribe to all changes on a collection\n * const unsub = await pb.realtime.subscribe('posts', (e) => {\n * console.log(e.action, e.record)\n * })\n *\n * // Unsubscribe\n * await unsub()\n *\n * // Disconnect all realtime connections\n * pb.realtime.disconnect()\n * ```\n */\nexport class PicoBaseRealtime {\n private pb: PocketBase\n\n constructor(pb: PocketBase) {\n this.pb = pb\n }\n\n /**\n * Subscribe to realtime events on a collection.\n *\n * @param collection - Collection name (e.g. 'posts').\n * @param callback - Called on every create/update/delete event.\n * @returns Unsubscribe function.\n */\n async subscribe<T = RecordModel>(\n collection: string,\n callback: (data: RecordSubscription<T>) => void,\n ): Promise<() => Promise<void>> {\n await this.pb.collection(collection).subscribe<T>('*', callback)\n return () => this.pb.collection(collection).unsubscribe('*')\n }\n\n /**\n * Subscribe to realtime events on a specific record.\n *\n * @param collection - Collection name.\n * @param recordId - Record ID.\n * @param callback - Called on update/delete events.\n * @returns Unsubscribe function.\n */\n async subscribeRecord<T = RecordModel>(\n collection: string,\n recordId: string,\n callback: (data: RecordSubscription<T>) => void,\n ): Promise<() => Promise<void>> {\n await this.pb.collection(collection).subscribe<T>(recordId, callback)\n return () => this.pb.collection(collection).unsubscribe(recordId)\n }\n\n /**\n * Unsubscribe from all realtime events on a collection.\n */\n async unsubscribe(collection: string): Promise<void> {\n await this.pb.collection(collection).unsubscribe()\n }\n\n /**\n * Unsubscribe from ALL realtime events. The SSE connection will be\n * automatically closed when there are no remaining subscriptions.\n */\n async disconnectAll(): Promise<void> {\n await this.pb.realtime.unsubscribe()\n }\n}\n","import type PocketBase from 'pocketbase'\nimport type { RecordModel, FileOptions } from './types'\n\n/**\n * Storage module — work with file fields on PocketBase records.\n *\n * PocketBase stores files as record fields. This module provides helpers\n * to get file URLs and generate access tokens for protected files.\n *\n * @example\n * ```ts\n * const user = await pb.collection('users').getOne('user_id')\n *\n * // Get the URL for the user's avatar\n * const avatarUrl = pb.storage.getFileUrl(user, 'avatar.jpg')\n *\n * // Get a thumbnail URL (100x100)\n * const thumbUrl = pb.storage.getFileUrl(user, 'avatar.jpg', {\n * thumb: '100x100',\n * })\n *\n * // Get a temporary token for protected files\n * const token = await pb.storage.getFileToken()\n * const protectedUrl = pb.storage.getFileUrl(user, 'document.pdf', { token })\n * ```\n */\nexport class PicoBaseStorage {\n private pb: PocketBase\n\n constructor(pb: PocketBase) {\n this.pb = pb\n }\n\n /**\n * Get the public URL for a file attached to a record.\n *\n * @param record - The record that owns the file.\n * @param filename - The filename (as stored in the record's file field).\n * @param options - Optional: thumb size, token for protected files, download flag.\n */\n getFileUrl(record: RecordModel, filename: string, options: FileOptions = {}): string {\n const queryParams: Record<string, string> = {}\n\n if (options.thumb) {\n queryParams['thumb'] = options.thumb\n }\n if (options.token) {\n queryParams['token'] = options.token\n }\n if (options.download) {\n queryParams['download'] = '1'\n }\n\n return this.pb.files.getURL(record, filename, queryParams)\n }\n\n /**\n * Generate a temporary file access token.\n *\n * Use this for accessing protected files. Tokens are short-lived.\n */\n async getFileToken(): Promise<string> {\n return this.pb.files.getToken()\n }\n}\n","import type PocketBase from 'pocketbase'\nimport type { CollectionModel } from './types' // Assuming types are updated\n\nexport class PicoBaseAdmin {\n private pb: PocketBase\n\n constructor(pb: PocketBase) {\n this.pb = pb\n }\n\n /**\n * Fetch a list of all collections.\n */\n async listCollections(): Promise<CollectionModel[]> {\n const result = await this.pb.send<{ items: CollectionModel[] }>('/api/collections', {\n method: 'GET',\n })\n return result.items || []\n }\n\n /**\n * Fetch a single collection by ID or name.\n */\n async getCollection(idOrName: string): Promise<CollectionModel> {\n return this.pb.send<CollectionModel>(`/api/collections/${idOrName}`, {\n method: 'GET',\n })\n }\n\n /**\n * Create a new collection.\n */\n async createCollection(data: Partial<CollectionModel>): Promise<CollectionModel> {\n return this.pb.send<CollectionModel>('/api/collections', {\n method: 'POST',\n body: data,\n })\n }\n\n /**\n * Update an existing collection.\n */\n async updateCollection(idOrName: string, data: Partial<CollectionModel>): Promise<CollectionModel> {\n return this.pb.send<CollectionModel>(`/api/collections/${idOrName}`, {\n method: 'PATCH',\n body: data,\n })\n }\n\n /**\n * Delete a collection.\n */\n async deleteCollection(idOrName: string): Promise<boolean> {\n try {\n await this.pb.send(`/api/collections/${idOrName}`, {\n method: 'DELETE',\n })\n return true\n } catch (e) {\n return false\n }\n }\n}\n","/**\n * Base error class for all PicoBase SDK errors.\n *\n * Every error includes a `code` for programmatic handling and a `fix`\n * suggestion so developers can resolve issues without digging through docs.\n */\nexport class PicoBaseError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n public readonly status?: number,\n public readonly details?: unknown,\n /** Actionable suggestion for how to fix this error. */\n public readonly fix?: string,\n ) {\n super(message)\n this.name = 'PicoBaseError'\n }\n\n /** Formatted error string including fix suggestion. */\n toString(): string {\n let s = `${this.name} [${this.code}]: ${this.message}`\n if (this.fix) s += `\\n Fix: ${this.fix}`\n return s\n }\n}\n\n/**\n * Thrown when the instance is not running and cold-start retries are exhausted.\n */\nexport class InstanceUnavailableError extends PicoBaseError {\n constructor(message = 'Instance is not available. It may be stopped or starting up.') {\n super(\n message,\n 'INSTANCE_UNAVAILABLE',\n 503,\n undefined,\n 'Check your instance status in the PicoBase dashboard, or wait a few seconds and retry. ' +\n 'If this persists, your instance may have been stopped — restart it with `picobase status`.',\n )\n this.name = 'InstanceUnavailableError'\n }\n}\n\n/**\n * Thrown when an API key is invalid or missing.\n */\nexport class AuthorizationError extends PicoBaseError {\n constructor(message = 'Invalid or missing API key.') {\n super(\n message,\n 'UNAUTHORIZED',\n 401,\n undefined,\n 'Make sure PICOBASE_API_KEY is set in your .env file and matches a valid key from your dashboard. ' +\n 'Keys start with \"pbk_\". You can generate a new key at https://picobase.com/dashboard.',\n )\n this.name = 'AuthorizationError'\n }\n}\n\n/**\n * Thrown when a collection is not found.\n */\nexport class CollectionNotFoundError extends PicoBaseError {\n constructor(collectionName: string) {\n super(\n `Collection \"${collectionName}\" not found.`,\n 'COLLECTION_NOT_FOUND',\n 404,\n { collection: collectionName },\n `Make sure the collection \"${collectionName}\" exists in your PicoBase instance. ` +\n 'Collections are auto-created when you first write data, or you can create them ' +\n 'manually in the PicoBase dashboard under Collections.',\n )\n this.name = 'CollectionNotFoundError'\n }\n}\n\n/**\n * Thrown when a record is not found.\n */\nexport class RecordNotFoundError extends PicoBaseError {\n constructor(collectionName: string, recordId: string) {\n super(\n `Record \"${recordId}\" not found in collection \"${collectionName}\".`,\n 'RECORD_NOT_FOUND',\n 404,\n { collection: collectionName, recordId },\n 'Check that the record ID is correct. IDs are 15-character alphanumeric strings (e.g., \"abc123def456789\").',\n )\n this.name = 'RecordNotFoundError'\n }\n}\n\n/**\n * Thrown when a PocketBase API request fails.\n */\nexport class RequestError extends PicoBaseError {\n constructor(message: string, status: number, details?: unknown) {\n const fix = requestErrorFix(status, message)\n super(message, 'REQUEST_FAILED', status, details, fix)\n this.name = 'RequestError'\n }\n}\n\n/**\n * Thrown when the SDK is misconfigured (bad URL, missing params, etc.).\n */\nexport class ConfigurationError extends PicoBaseError {\n constructor(message: string, fix: string) {\n super(message, 'CONFIGURATION_ERROR', undefined, undefined, fix)\n this.name = 'ConfigurationError'\n }\n}\n\n/**\n * Thrown when an RPC (remote procedure call) fails.\n */\nexport class RpcError extends PicoBaseError {\n constructor(functionName: string, status: number, details?: unknown) {\n const fix = rpcErrorFix(functionName, status)\n super(\n `RPC function \"${functionName}\" failed.`,\n 'RPC_ERROR',\n status,\n details,\n fix,\n )\n this.name = 'RpcError'\n }\n}\n\n/** Generate fix suggestions for RPC errors. */\nfunction rpcErrorFix(functionName: string, status: number): string {\n if (status === 404) {\n return `The RPC endpoint \"/api/rpc/${functionName}\" does not exist. ` +\n 'Create a custom route in your PocketBase instance to handle this RPC call. ' +\n 'See: https://pocketbase.io/docs/js-routing/'\n }\n if (status === 400) {\n return 'Check the parameters you are passing to this RPC function. ' +\n 'The function may be expecting different parameters or types.'\n }\n if (status === 403) {\n return 'You don\\'t have permission to call this RPC function. ' +\n 'Check the authentication requirements for this endpoint in your PocketBase routes.'\n }\n return 'Check your PicoBase instance logs for details about this RPC error. ' +\n 'Ensure the custom route is correctly implemented in your PocketBase setup.'\n}\n\n/** Map common HTTP statuses to actionable fixes. */\nfunction requestErrorFix(status: number, message: string): string {\n switch (status) {\n case 400:\n return 'Check the data you are sending — a required field may be missing or have the wrong type. ' +\n 'Run `picobase typegen` to regenerate types and check your field names.'\n case 403:\n return 'You don\\'t have permission for this action. Check your collection API rules in the dashboard. ' +\n 'By default, only authenticated users can read/write records.'\n case 404:\n if (message.toLowerCase().includes('collection'))\n return 'This collection does not exist yet. Write a record to auto-create it, or create it in the dashboard.'\n return 'The requested resource was not found. Double-check IDs and collection names.'\n case 413:\n return 'The request payload is too large. Check file upload size limits in your instance settings.'\n case 429:\n return 'Too many requests. Add a short delay between requests or implement client-side caching.'\n default:\n return 'If this error persists, check your PicoBase dashboard for instance health and logs.'\n }\n}\n","import PocketBase from 'pocketbase'\nimport { PicoBaseAuth } from './auth'\nimport { PicoBaseCollection } from './collection'\nimport { PicoBaseRealtime } from './realtime'\nimport { PicoBaseStorage } from './storage'\nimport { PicoBaseAdmin } from './admin'\nimport { InstanceUnavailableError, AuthorizationError, CollectionNotFoundError, RecordNotFoundError, ConfigurationError, RpcError } from './errors'\nimport type { PicoBaseClientOptions, RecordModel, SendOptions } from './types'\n\nconst DEFAULT_OPTIONS: Required<Omit<PicoBaseClientOptions, 'fetch'>> & { fetch?: typeof globalThis.fetch } = {\n timeout: 30_000,\n maxColdStartRetries: 3,\n lang: 'en-US',\n}\n\nexport class PicoBaseClient {\n /** The underlying PocketBase SDK instance. Exposed for advanced usage. */\n readonly pb: PocketBase\n /** Auth module — sign up, sign in, OAuth, session management. */\n readonly auth: PicoBaseAuth\n /** Realtime module — subscribe to record changes. */\n readonly realtime: PicoBaseRealtime\n /** Storage module — get file URLs and tokens. */\n readonly storage: PicoBaseStorage\n /** Admin module — manage collections (requires admin API key). */\n readonly admin: PicoBaseAdmin\n\n private readonly apiKey: string\n private readonly options: typeof DEFAULT_OPTIONS\n\n constructor(url: string, apiKey: string, options: PicoBaseClientOptions = {}) {\n // Validate inputs with clear messages\n if (!url) {\n throw new ConfigurationError(\n 'PicoBase URL is required.',\n 'Pass the URL as the first argument: createClient(\"https://myapp.picobase.com\", \"pbk_...\") ' +\n 'or set PICOBASE_URL in your .env file.',\n )\n }\n if (!apiKey) {\n throw new ConfigurationError(\n 'PicoBase API key is required.',\n 'Pass the API key as the second argument: createClient(\"https://...\", \"pbk_your_key\") ' +\n 'or set PICOBASE_API_KEY in your .env file. Get a key from your dashboard.',\n )\n }\n if (!url.startsWith('http://') && !url.startsWith('https://')) {\n throw new ConfigurationError(\n `Invalid URL: \"${url}\". Must start with http:// or https://.`,\n `Use the full URL: createClient(\"https://${url}\", \"...\")`,\n )\n }\n\n this.apiKey = apiKey\n this.options = { ...DEFAULT_OPTIONS, ...options }\n\n // Normalize URL — strip trailing slash\n const baseUrl = url.replace(/\\/+$/, '')\n\n this.pb = new PocketBase(baseUrl)\n this.pb.autoCancellation(false)\n\n if (this.options.lang) {\n this.pb.lang = this.options.lang\n }\n\n // Inject API key header into every request via beforeSend hook\n this.pb.beforeSend = (url, reqInit) => {\n const headers = reqInit.headers as Record<string, string> ?? {}\n headers['X-PicoBase-Key'] = this.apiKey\n reqInit.headers = headers\n return { url, options: reqInit }\n }\n\n // Wrap the send method for cold-start retry logic\n this._wrapSendWithRetry()\n\n // Initialize modules\n this.auth = new PicoBaseAuth(this.pb)\n this.realtime = new PicoBaseRealtime(this.pb)\n this.storage = new PicoBaseStorage(this.pb)\n this.admin = new PicoBaseAdmin(this.pb)\n }\n\n /**\n * Access a collection for CRUD operations.\n *\n * @example\n * ```ts\n * const posts = await pb.collection('posts').getList(1, 20)\n * ```\n */\n collection<T = RecordModel>(name: string): PicoBaseCollection<T> {\n return new PicoBaseCollection<T>(this.pb, name)\n }\n\n /**\n * Call a server-side function (PocketBase custom API endpoint).\n * Proxies to PocketBase's send() method.\n */\n async send<T = unknown>(path: string, options?: SendOptions): Promise<T> {\n return this.pb.send<T>(path, options ?? {})\n }\n\n /**\n * Call a remote procedure (RPC) - a convenience method for calling custom API endpoints.\n *\n * Maps Supabase-style RPC calls to PicoBase custom endpoints:\n * - `pb.rpc('my_function', params)` → `POST /api/rpc/my_function` with params as body\n *\n * @example\n * ```ts\n * // Simple RPC call\n * const result = await pb.rpc('calculate_total', { cart_id: '123' })\n *\n * // Complex RPC with typed response\n * interface DashboardStats {\n * posts: number\n * comments: number\n * followers: number\n * }\n * const stats = await pb.rpc<DashboardStats>('get_dashboard_stats', {\n * user_id: currentUser.id\n * })\n * ```\n *\n * @param functionName The name of the RPC function to call\n * @param params Optional parameters to pass to the function\n * @returns The function result\n */\n async rpc<T = unknown>(functionName: string, params?: Record<string, unknown>): Promise<T> {\n try {\n return await this.send<T>(`/api/rpc/${functionName}`, {\n method: 'POST',\n body: params ?? {},\n })\n } catch (err: unknown) {\n // Wrap errors with RpcError for better error messages\n const status = (err as { status?: number })?.status ?? 500\n const details = (err as { data?: unknown })?.data\n throw new RpcError(functionName, status, details)\n }\n }\n\n /**\n * Get the current auth token (if signed in), or empty string.\n */\n get token(): string {\n return this.pb.authStore.token\n }\n\n /**\n * Check if a user is currently authenticated.\n */\n get isAuthenticated(): boolean {\n return this.pb.authStore.isValid\n }\n\n /**\n * Monkey-patch pb.send to retry on 503 (cold start).\n *\n * When an instance is stopped or starting, the proxy returns 503.\n * The SDK automatically retries with exponential backoff so the developer\n * doesn't have to handle cold-start logic.\n */\n private _wrapSendWithRetry(): void {\n const originalSend = this.pb.send.bind(this.pb)\n const maxRetries = this.options.maxColdStartRetries\n\n this.pb.send = async <T>(path: string, options: SendOptions): Promise<T> => {\n let lastError: unknown\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await originalSend<T>(path, options)\n } catch (err: unknown) {\n lastError = err\n\n // Check if this is a 503 (instance starting up)\n const status = (err as { status?: number })?.status\n if (status === 503 && attempt < maxRetries) {\n // Exponential backoff: 2s, 4s, 8s\n const delay = Math.pow(2, attempt + 1) * 1000\n await new Promise(resolve => setTimeout(resolve, delay))\n continue\n }\n\n // Check if this is a 401 from our gateway (bad API key)\n if (status === 401) {\n const data = (err as { data?: { code?: string } })?.data\n if (data?.code === 'INVALID_API_KEY') {\n throw new AuthorizationError()\n }\n }\n\n // Detect collection-not-found for a clearer message\n if (status === 404) {\n const msg = (err as { message?: string })?.message ?? ''\n if (msg.toLowerCase().includes('missing collection') || msg.toLowerCase().includes('not found collection')) {\n const match = msg.match(/[\"']([^\"']+)[\"']/)\n throw new CollectionNotFoundError(match?.[1] ?? 'unknown')\n }\n }\n\n throw err\n }\n }\n\n throw new InstanceUnavailableError(\n `Instance unavailable after ${maxRetries} retries. ` +\n `Original error: ${lastError instanceof Error ? lastError.message : String(lastError)}`\n )\n }\n }\n}\n\n/**\n * Create a new PicoBase client.\n *\n * Can be called with explicit URL and API key, or with zero arguments to\n * auto-detect from environment variables (`PICOBASE_URL` / `NEXT_PUBLIC_PICOBASE_URL`\n * and `PICOBASE_API_KEY` / `NEXT_PUBLIC_PICOBASE_API_KEY`).\n *\n * @example\n * ```ts\n * import { createClient } from '@picobase_app/client'\n *\n * // Zero-config — reads from env vars\n * const pb = createClient()\n *\n * // Or explicit\n * const pb = createClient('https://myapp.picobase.com', 'pbk_abc123_secret')\n *\n * // Sign up a user\n * const user = await pb.auth.signUp({\n * email: 'user@example.com',\n * password: 'securepassword',\n * })\n *\n * // Query records\n * const posts = await pb.collection('posts').getList(1, 20, {\n * filter: 'published = true',\n * sort: '-created',\n * })\n * ```\n */\nexport function createClient(options?: PicoBaseClientOptions): PicoBaseClient\nexport function createClient(url: string, apiKey: string, options?: PicoBaseClientOptions): PicoBaseClient\nexport function createClient(\n urlOrOptions?: string | PicoBaseClientOptions,\n apiKeyOrUndefined?: string,\n options?: PicoBaseClientOptions,\n): PicoBaseClient {\n // Zero-arg / options-only: read from env\n if (typeof urlOrOptions !== 'string') {\n const env = typeof process !== 'undefined' ? process.env : {} as Record<string, string | undefined>\n const url = env.PICOBASE_URL || env.NEXT_PUBLIC_PICOBASE_URL\n const apiKey = env.PICOBASE_API_KEY || env.NEXT_PUBLIC_PICOBASE_API_KEY\n\n if (!url || !apiKey) {\n const missing = [\n !url && 'PICOBASE_URL (or NEXT_PUBLIC_PICOBASE_URL)',\n !apiKey && 'PICOBASE_API_KEY (or NEXT_PUBLIC_PICOBASE_API_KEY)',\n ].filter(Boolean).join(' and ')\n\n throw new ConfigurationError(\n `Missing environment variable${!url && !apiKey ? 's' : ''}: ${missing}`,\n 'Add them to your .env.local file:\\n\\n' +\n ' PICOBASE_URL=https://your-app.picobase.com\\n' +\n ' PICOBASE_API_KEY=pbk_your_key_here\\n\\n' +\n 'Or for Next.js (client-side access), prefix with NEXT_PUBLIC_:\\n\\n' +\n ' NEXT_PUBLIC_PICOBASE_URL=https://your-app.picobase.com\\n' +\n ' NEXT_PUBLIC_PICOBASE_API_KEY=pbk_your_key_here\\n\\n' +\n 'Get your URL and API key from: https://picobase.com/dashboard\\n' +\n 'Or run: picobase init',\n )\n }\n\n return new PicoBaseClient(url, apiKey, urlOrOptions)\n }\n\n return new PicoBaseClient(urlOrOptions, apiKeyOrUndefined!, options)\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import PocketBase from 'pocketbase';
|
|
2
|
+
|
|
1
3
|
// src/client.ts
|
|
2
|
-
import PocketBase from "pocketbase";
|
|
3
4
|
|
|
4
5
|
// src/auth.ts
|
|
5
6
|
var PicoBaseAuth = class {
|
|
@@ -26,7 +27,7 @@ var PicoBaseAuth = class {
|
|
|
26
27
|
*/
|
|
27
28
|
async signUp(options) {
|
|
28
29
|
const { email, password, passwordConfirm, ...rest } = options;
|
|
29
|
-
|
|
30
|
+
await this.pb.collection(this._collection).create({
|
|
30
31
|
email,
|
|
31
32
|
password,
|
|
32
33
|
passwordConfirm: passwordConfirm ?? password,
|
|
@@ -333,6 +334,61 @@ var PicoBaseStorage = class {
|
|
|
333
334
|
}
|
|
334
335
|
};
|
|
335
336
|
|
|
337
|
+
// src/admin.ts
|
|
338
|
+
var PicoBaseAdmin = class {
|
|
339
|
+
constructor(pb) {
|
|
340
|
+
this.pb = pb;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Fetch a list of all collections.
|
|
344
|
+
*/
|
|
345
|
+
async listCollections() {
|
|
346
|
+
const result = await this.pb.send("/api/collections", {
|
|
347
|
+
method: "GET"
|
|
348
|
+
});
|
|
349
|
+
return result.items || [];
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Fetch a single collection by ID or name.
|
|
353
|
+
*/
|
|
354
|
+
async getCollection(idOrName) {
|
|
355
|
+
return this.pb.send(`/api/collections/${idOrName}`, {
|
|
356
|
+
method: "GET"
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Create a new collection.
|
|
361
|
+
*/
|
|
362
|
+
async createCollection(data) {
|
|
363
|
+
return this.pb.send("/api/collections", {
|
|
364
|
+
method: "POST",
|
|
365
|
+
body: data
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Update an existing collection.
|
|
370
|
+
*/
|
|
371
|
+
async updateCollection(idOrName, data) {
|
|
372
|
+
return this.pb.send(`/api/collections/${idOrName}`, {
|
|
373
|
+
method: "PATCH",
|
|
374
|
+
body: data
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Delete a collection.
|
|
379
|
+
*/
|
|
380
|
+
async deleteCollection(idOrName) {
|
|
381
|
+
try {
|
|
382
|
+
await this.pb.send(`/api/collections/${idOrName}`, {
|
|
383
|
+
method: "DELETE"
|
|
384
|
+
});
|
|
385
|
+
return true;
|
|
386
|
+
} catch (e) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
|
|
336
392
|
// src/errors.ts
|
|
337
393
|
var PicoBaseError = class extends Error {
|
|
338
394
|
constructor(message, code, status, details, fix) {
|
|
@@ -500,6 +556,7 @@ var PicoBaseClient = class {
|
|
|
500
556
|
this.auth = new PicoBaseAuth(this.pb);
|
|
501
557
|
this.realtime = new PicoBaseRealtime(this.pb);
|
|
502
558
|
this.storage = new PicoBaseStorage(this.pb);
|
|
559
|
+
this.admin = new PicoBaseAdmin(this.pb);
|
|
503
560
|
}
|
|
504
561
|
/**
|
|
505
562
|
* Access a collection for CRUD operations.
|
|
@@ -633,19 +690,7 @@ function createClient(urlOrOptions, apiKeyOrUndefined, options) {
|
|
|
633
690
|
}
|
|
634
691
|
return new PicoBaseClient(urlOrOptions, apiKeyOrUndefined, options);
|
|
635
692
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
InstanceUnavailableError,
|
|
641
|
-
PicoBaseAuth,
|
|
642
|
-
PicoBaseClient,
|
|
643
|
-
PicoBaseCollection,
|
|
644
|
-
PicoBaseError,
|
|
645
|
-
PicoBaseRealtime,
|
|
646
|
-
PicoBaseStorage,
|
|
647
|
-
RecordNotFoundError,
|
|
648
|
-
RequestError,
|
|
649
|
-
RpcError,
|
|
650
|
-
createClient
|
|
651
|
-
};
|
|
693
|
+
|
|
694
|
+
export { AuthorizationError, CollectionNotFoundError, ConfigurationError, InstanceUnavailableError, PicoBaseAdmin, PicoBaseAuth, PicoBaseClient, PicoBaseCollection, PicoBaseError, PicoBaseRealtime, PicoBaseStorage, RecordNotFoundError, RequestError, RpcError, createClient };
|
|
695
|
+
//# sourceMappingURL=index.mjs.map
|
|
696
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/auth.ts","../src/collection.ts","../src/realtime.ts","../src/storage.ts","../src/admin.ts","../src/errors.ts","../src/client.ts"],"names":["url"],"mappings":";;;;;AAqCO,IAAM,eAAN,MAAmB;AAAA,EAKxB,YAAY,EAAA,EAAgB;AAH5B,IAAA,IAAA,CAAQ,SAAA,uBAA8C,GAAA,EAAI;AAC1D,IAAA,IAAA,CAAQ,WAAA,GAAsB,OAAA;AAG5B,IAAA,IAAA,CAAK,EAAA,GAAK,EAAA;AAGV,IAAA,IAAA,CAAK,EAAA,CAAG,SAAA,CAAU,QAAA,CAAS,CAAC,KAAA,KAAU;AACpC,MAAA,MAAM,MAAA,GAAS,IAAA,CAAK,EAAA,CAAG,SAAA,CAAU,MAAA,IAAU,IAAA;AAC3C,MAAA,MAAM,KAAA,GAAmB,QAAQ,WAAA,GAAc,YAAA;AAC/C,MAAA,IAAA,CAAK,OAAA,CAAQ,OAAO,MAAM,CAAA;AAAA,IAC5B,CAAC,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,cAAc,IAAA,EAAoB;AAChC,IAAA,IAAA,CAAK,WAAA,GAAc,IAAA;AACnB,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,OAA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AA,QACR,CAAA,2BAAA,EAA8B,UAAU,CAAA,0BAAA,EACrB,SAAA,YAAqB,QAAQ,SAAA,CAAU,OAAA,GAAU,MAAA,CAAO,SAAS,CAAC,CAAA;AAAA,OACvF;AAAA,IACF,CAAA;AAAA,EACF;AACF;AAkCO,SAAS,YAAA,CACd,YAAA,EACA,iBAAA,EACA,OAAA,EACgB;AAEhB,EAAA,IAAI,OAAO,iBAAiB,QAAA,EAAU;AACpC,IAAA,MAAM,MAAM,OAAO,OAAA,KAAY,WAAA,GAAc,OAAA,CAAQ,MAAM,EAAC;AAC5D,IAAA,MAAM,GAAA,GAAM,GAAA,CAAI,YAAA,IAAgB,GAAA,CAAI,wBAAA;AACpC,IAAA,MAAM,MAAA,GAAS,GAAA,CAAI,gBAAA,IAAoB,GAAA,CAAI,4BAAA;AAE3C,IAAA,IAAI,CAAC,GAAA,IAAO,CAAC,MAAA,EAAQ;AACnB,MAAA,MAAM,OAAA,GAAU;AAAA,QACd,CAAC,GAAA,IAAO,4CAAA;AAAA,QACR,CAAC,MAAA,IAAU;AAAA,OACb,CAAE,MAAA,CAAO,OAAO,CAAA,CAAE,KAAK,OAAO,CAAA;AAE9B,MAAA,MAAM,IAAI,kBAAA;AAAA,QACR,CAAA,4BAAA,EAA+B,CAAC,GAAA,IAAO,CAAC,SAAS,GAAA,GAAM,EAAE,KAAK,OAAO,CAAA,CAAA;AAAA,QACrE;AAAA,OAQF;AAAA,IACF;AAEA,IAAA,OAAO,IAAI,cAAA,CAAe,GAAA,EAAK,MAAA,EAAQ,YAAY,CAAA;AAAA,EACrD;AAEA,EAAA,OAAO,IAAI,cAAA,CAAe,YAAA,EAAc,iBAAA,EAAoB,OAAO,CAAA;AACrE","file":"index.mjs","sourcesContent":["import type PocketBase from 'pocketbase'\nimport type {\n AuthResponse,\n AuthStateChangeCallback,\n AuthEvent,\n SignUpOptions,\n SignInOptions,\n OAuthSignInOptions,\n RecordModel,\n} from './types'\n\n/**\n * Auth module — handles user sign-up, sign-in, OAuth, and session management.\n *\n * PicoBase uses PocketBase's built-in `users` collection for auth. Each\n * instance has its own isolated user pool.\n *\n * @example\n * ```ts\n * // Sign up\n * const { token, record } = await pb.auth.signUp({\n * email: 'user@example.com',\n * password: 'securepassword',\n * })\n *\n * // Sign in\n * const { token, record } = await pb.auth.signIn({\n * email: 'user@example.com',\n * password: 'securepassword',\n * })\n *\n * // Listen to auth changes\n * pb.auth.onStateChange((event, record) => {\n * console.log(event, record)\n * })\n * ```\n */\nexport class PicoBaseAuth {\n private pb: PocketBase\n private listeners: Set<AuthStateChangeCallback> = new Set()\n private _collection: string = 'users'\n\n constructor(pb: PocketBase) {\n this.pb = pb\n\n // Listen to PocketBase auth store changes and re-emit\n this.pb.authStore.onChange((token) => {\n const record = this.pb.authStore.record ?? null\n const event: AuthEvent = token ? 'SIGNED_IN' : 'SIGNED_OUT'\n this._notify(event, record)\n })\n }\n\n /**\n * Set which collection to authenticate against.\n * Defaults to 'users'. Use this if you have a custom auth collection.\n */\n setCollection(name: string): this {\n this._collection = name\n return this\n }\n\n /**\n * Create a new user account.\n */\n async signUp(options: SignUpOptions): Promise<AuthResponse> {\n const { email, password, passwordConfirm, ...rest } = options\n\n const record = await this.pb.collection(this._collection).create<RecordModel>({\n email,\n password,\n passwordConfirm: passwordConfirm ?? password,\n ...rest,\n })\n\n // Automatically sign in after sign-up\n const authResult = await this.pb\n .collection(this._collection)\n .authWithPassword<RecordModel>(email, password)\n\n return {\n token: authResult.token,\n record: authResult.record,\n }\n }\n\n /**\n * Sign in with email and password.\n */\n async signIn(options: SignInOptions): Promise<AuthResponse> {\n const result = await this.pb\n .collection(this._collection)\n .authWithPassword<RecordModel>(options.email, options.password)\n\n return {\n token: result.token,\n record: result.record,\n }\n }\n\n /**\n * Sign in with an OAuth2 provider (Google, GitHub, etc.).\n *\n * In browser environments this opens a popup/redirect to the provider.\n * Configure providers in your PicoBase dashboard.\n */\n async signInWithOAuth(options: OAuthSignInOptions): Promise<AuthResponse> {\n const result = await this.pb.collection(this._collection).authWithOAuth2({\n provider: options.provider,\n scopes: options.scopes,\n createData: options.createData,\n urlCallback: options.urlCallback,\n })\n\n return {\n token: result.token,\n record: result.record,\n }\n }\n\n /**\n * Refresh the current auth token.\n */\n async refreshToken(): Promise<AuthResponse> {\n const result = await this.pb.collection(this._collection).authRefresh<RecordModel>()\n this._notify('TOKEN_REFRESHED', result.record)\n return {\n token: result.token,\n record: result.record,\n }\n }\n\n /**\n * Send a password reset email.\n */\n async requestPasswordReset(email: string): Promise<void> {\n await this.pb.collection(this._collection).requestPasswordReset(email)\n }\n\n /**\n * Confirm a password reset with the token from the reset email.\n */\n async confirmPasswordReset(\n token: string,\n password: string,\n passwordConfirm?: string,\n ): Promise<void> {\n await this.pb\n .collection(this._collection)\n .confirmPasswordReset(token, password, passwordConfirm ?? password)\n }\n\n /**\n * Send an email verification email.\n */\n async requestVerification(email: string): Promise<void> {\n await this.pb.collection(this._collection).requestVerification(email)\n }\n\n /**\n * Confirm email verification with the token from the verification email.\n */\n async confirmVerification(token: string): Promise<void> {\n await this.pb.collection(this._collection).confirmVerification(token)\n }\n\n /**\n * Sign out the current user. Clears the local auth store.\n */\n signOut(): void {\n this.pb.authStore.clear()\n }\n\n /**\n * Get the currently authenticated user record, or `null` if not signed in.\n */\n get user(): RecordModel | null {\n return this.pb.authStore.record\n }\n\n /**\n * Get the current auth token, or empty string if not signed in.\n */\n get token(): string {\n return this.pb.authStore.token\n }\n\n /**\n * Check if the current auth session is valid (token exists and not expired).\n */\n get isValid(): boolean {\n return this.pb.authStore.isValid\n }\n\n /**\n * Listen to auth state changes. Returns an unsubscribe function.\n *\n * @example\n * ```ts\n * const unsubscribe = pb.auth.onStateChange((event, record) => {\n * if (event === 'SIGNED_IN') {\n * console.log('Welcome', record.email)\n * }\n * })\n *\n * // Later:\n * unsubscribe()\n * ```\n */\n onStateChange(callback: AuthStateChangeCallback): () => void {\n this.listeners.add(callback)\n return () => {\n this.listeners.delete(callback)\n }\n }\n\n private _notify(event: AuthEvent, record: RecordModel | null): void {\n for (const cb of this.listeners) {\n try {\n cb(event, record)\n } catch {\n // Don't let one listener crash others\n }\n }\n }\n}\n","import type PocketBase from 'pocketbase'\nimport type { RecordModel, ListResult } from 'pocketbase'\n\n/** Options for list queries. */\nexport interface ListOptions {\n sort?: string\n filter?: string\n expand?: string\n fields?: string\n skipTotal?: boolean\n [key: string]: unknown\n}\n\n/** Options for single record queries. */\nexport interface RecordQueryOptions {\n expand?: string\n fields?: string\n [key: string]: unknown\n}\n\n/**\n * Collection module — CRUD operations on a PocketBase collection.\n *\n * @example\n * ```ts\n * const posts = pb.collection('posts')\n *\n * // List with filtering, sorting, and pagination\n * const result = await posts.getList(1, 20, {\n * filter: 'published = true',\n * sort: '-created',\n * expand: 'author',\n * })\n *\n * // Get a single record\n * const post = await posts.getOne('record_id')\n *\n * // Create a record\n * const newPost = await posts.create({\n * title: 'Hello World',\n * content: 'My first post',\n * })\n *\n * // Update a record\n * const updated = await posts.update('record_id', { title: 'Updated' })\n *\n * // Delete a record\n * await posts.delete('record_id')\n * ```\n */\nexport class PicoBaseCollection<T = RecordModel> {\n private pb: PocketBase\n private name: string\n\n constructor(pb: PocketBase, name: string) {\n this.pb = pb\n this.name = name\n }\n\n /**\n * Fetch a paginated list of records.\n *\n * @param page - Page number (1-indexed). Default: 1.\n * @param perPage - Records per page. Default: 30.\n * @param options - Filter, sort, expand, fields.\n */\n async getList(page = 1, perPage = 30, options: ListOptions = {}): Promise<ListResult<T>> {\n return this.pb.collection(this.name).getList<T>(page, perPage, options)\n }\n\n /**\n * Fetch all records matching the filter (auto-paginates).\n *\n * **Warning:** Use with caution on large collections. Prefer `getList()` with pagination.\n */\n async getFullList(options: ListOptions = {}): Promise<T[]> {\n return this.pb.collection(this.name).getFullList<T>(options)\n }\n\n /**\n * Fetch a single record by ID.\n */\n async getOne(id: string, options: RecordQueryOptions = {}): Promise<T> {\n return this.pb.collection(this.name).getOne<T>(id, options)\n }\n\n /**\n * Fetch the first record matching a filter.\n *\n * @example\n * ```ts\n * const admin = await pb.collection('users').getFirstListItem('role = \"admin\"')\n * ```\n */\n async getFirstListItem(filter: string, options: RecordQueryOptions = {}): Promise<T> {\n return this.pb.collection(this.name).getFirstListItem<T>(filter, options)\n }\n\n /**\n * Create a new record.\n *\n * @param data - Record data. Can be a plain object or `FormData` (for file uploads).\n */\n async create(data: Record<string, unknown> | FormData, options: RecordQueryOptions = {}): Promise<T> {\n return this.pb.collection(this.name).create<T>(data, options)\n }\n\n /**\n * Update an existing record.\n *\n * @param id - Record ID.\n * @param data - Fields to update. Can be a plain object or `FormData`.\n */\n async update(id: string, data: Record<string, unknown> | FormData, options: RecordQueryOptions = {}): Promise<T> {\n return this.pb.collection(this.name).update<T>(id, data, options)\n }\n\n /**\n * Delete a record by ID.\n */\n async delete(id: string): Promise<boolean> {\n return this.pb.collection(this.name).delete(id)\n }\n\n /**\n * Subscribe to realtime changes on this collection.\n *\n * @param callback - Called on every create/update/delete event.\n * @param filter - Optional: only receive events matching this filter.\n * @returns Unsubscribe function.\n *\n * @example\n * ```ts\n * const unsubscribe = await pb.collection('posts').subscribe((e) => {\n * console.log(e.action, e.record)\n * })\n *\n * // Later:\n * await unsubscribe()\n * ```\n */\n async subscribe(\n callback: (data: { action: string; record: T }) => void,\n filter?: string,\n ): Promise<() => Promise<void>> {\n const topic = '*'\n await this.pb.collection(this.name).subscribe<T>(topic, callback, filter ? { filter } : undefined)\n return () => this.pb.collection(this.name).unsubscribe(topic)\n }\n\n /**\n * Subscribe to changes on a specific record.\n *\n * @param id - Record ID.\n * @param callback - Called on update/delete events.\n * @returns Unsubscribe function.\n */\n async subscribeOne(\n id: string,\n callback: (data: { action: string; record: T }) => void,\n ): Promise<() => Promise<void>> {\n await this.pb.collection(this.name).subscribe<T>(id, callback)\n return () => this.pb.collection(this.name).unsubscribe(id)\n }\n}\n","import type PocketBase from 'pocketbase'\nimport type { RecordModel, RecordSubscription } from './types'\n\n/**\n * Realtime module — manage global realtime subscriptions.\n *\n * For collection-level subscriptions, prefer `pb.collection('name').subscribe()`.\n * This module is for lower-level control over the SSE connection.\n *\n * @example\n * ```ts\n * // Subscribe to all changes on a collection\n * const unsub = await pb.realtime.subscribe('posts', (e) => {\n * console.log(e.action, e.record)\n * })\n *\n * // Unsubscribe\n * await unsub()\n *\n * // Disconnect all realtime connections\n * pb.realtime.disconnect()\n * ```\n */\nexport class PicoBaseRealtime {\n private pb: PocketBase\n\n constructor(pb: PocketBase) {\n this.pb = pb\n }\n\n /**\n * Subscribe to realtime events on a collection.\n *\n * @param collection - Collection name (e.g. 'posts').\n * @param callback - Called on every create/update/delete event.\n * @returns Unsubscribe function.\n */\n async subscribe<T = RecordModel>(\n collection: string,\n callback: (data: RecordSubscription<T>) => void,\n ): Promise<() => Promise<void>> {\n await this.pb.collection(collection).subscribe<T>('*', callback)\n return () => this.pb.collection(collection).unsubscribe('*')\n }\n\n /**\n * Subscribe to realtime events on a specific record.\n *\n * @param collection - Collection name.\n * @param recordId - Record ID.\n * @param callback - Called on update/delete events.\n * @returns Unsubscribe function.\n */\n async subscribeRecord<T = RecordModel>(\n collection: string,\n recordId: string,\n callback: (data: RecordSubscription<T>) => void,\n ): Promise<() => Promise<void>> {\n await this.pb.collection(collection).subscribe<T>(recordId, callback)\n return () => this.pb.collection(collection).unsubscribe(recordId)\n }\n\n /**\n * Unsubscribe from all realtime events on a collection.\n */\n async unsubscribe(collection: string): Promise<void> {\n await this.pb.collection(collection).unsubscribe()\n }\n\n /**\n * Unsubscribe from ALL realtime events. The SSE connection will be\n * automatically closed when there are no remaining subscriptions.\n */\n async disconnectAll(): Promise<void> {\n await this.pb.realtime.unsubscribe()\n }\n}\n","import type PocketBase from 'pocketbase'\nimport type { RecordModel, FileOptions } from './types'\n\n/**\n * Storage module — work with file fields on PocketBase records.\n *\n * PocketBase stores files as record fields. This module provides helpers\n * to get file URLs and generate access tokens for protected files.\n *\n * @example\n * ```ts\n * const user = await pb.collection('users').getOne('user_id')\n *\n * // Get the URL for the user's avatar\n * const avatarUrl = pb.storage.getFileUrl(user, 'avatar.jpg')\n *\n * // Get a thumbnail URL (100x100)\n * const thumbUrl = pb.storage.getFileUrl(user, 'avatar.jpg', {\n * thumb: '100x100',\n * })\n *\n * // Get a temporary token for protected files\n * const token = await pb.storage.getFileToken()\n * const protectedUrl = pb.storage.getFileUrl(user, 'document.pdf', { token })\n * ```\n */\nexport class PicoBaseStorage {\n private pb: PocketBase\n\n constructor(pb: PocketBase) {\n this.pb = pb\n }\n\n /**\n * Get the public URL for a file attached to a record.\n *\n * @param record - The record that owns the file.\n * @param filename - The filename (as stored in the record's file field).\n * @param options - Optional: thumb size, token for protected files, download flag.\n */\n getFileUrl(record: RecordModel, filename: string, options: FileOptions = {}): string {\n const queryParams: Record<string, string> = {}\n\n if (options.thumb) {\n queryParams['thumb'] = options.thumb\n }\n if (options.token) {\n queryParams['token'] = options.token\n }\n if (options.download) {\n queryParams['download'] = '1'\n }\n\n return this.pb.files.getURL(record, filename, queryParams)\n }\n\n /**\n * Generate a temporary file access token.\n *\n * Use this for accessing protected files. Tokens are short-lived.\n */\n async getFileToken(): Promise<string> {\n return this.pb.files.getToken()\n }\n}\n","import type PocketBase from 'pocketbase'\nimport type { CollectionModel } from './types' // Assuming types are updated\n\nexport class PicoBaseAdmin {\n private pb: PocketBase\n\n constructor(pb: PocketBase) {\n this.pb = pb\n }\n\n /**\n * Fetch a list of all collections.\n */\n async listCollections(): Promise<CollectionModel[]> {\n const result = await this.pb.send<{ items: CollectionModel[] }>('/api/collections', {\n method: 'GET',\n })\n return result.items || []\n }\n\n /**\n * Fetch a single collection by ID or name.\n */\n async getCollection(idOrName: string): Promise<CollectionModel> {\n return this.pb.send<CollectionModel>(`/api/collections/${idOrName}`, {\n method: 'GET',\n })\n }\n\n /**\n * Create a new collection.\n */\n async createCollection(data: Partial<CollectionModel>): Promise<CollectionModel> {\n return this.pb.send<CollectionModel>('/api/collections', {\n method: 'POST',\n body: data,\n })\n }\n\n /**\n * Update an existing collection.\n */\n async updateCollection(idOrName: string, data: Partial<CollectionModel>): Promise<CollectionModel> {\n return this.pb.send<CollectionModel>(`/api/collections/${idOrName}`, {\n method: 'PATCH',\n body: data,\n })\n }\n\n /**\n * Delete a collection.\n */\n async deleteCollection(idOrName: string): Promise<boolean> {\n try {\n await this.pb.send(`/api/collections/${idOrName}`, {\n method: 'DELETE',\n })\n return true\n } catch (e) {\n return false\n }\n }\n}\n","/**\n * Base error class for all PicoBase SDK errors.\n *\n * Every error includes a `code` for programmatic handling and a `fix`\n * suggestion so developers can resolve issues without digging through docs.\n */\nexport class PicoBaseError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n public readonly status?: number,\n public readonly details?: unknown,\n /** Actionable suggestion for how to fix this error. */\n public readonly fix?: string,\n ) {\n super(message)\n this.name = 'PicoBaseError'\n }\n\n /** Formatted error string including fix suggestion. */\n toString(): string {\n let s = `${this.name} [${this.code}]: ${this.message}`\n if (this.fix) s += `\\n Fix: ${this.fix}`\n return s\n }\n}\n\n/**\n * Thrown when the instance is not running and cold-start retries are exhausted.\n */\nexport class InstanceUnavailableError extends PicoBaseError {\n constructor(message = 'Instance is not available. It may be stopped or starting up.') {\n super(\n message,\n 'INSTANCE_UNAVAILABLE',\n 503,\n undefined,\n 'Check your instance status in the PicoBase dashboard, or wait a few seconds and retry. ' +\n 'If this persists, your instance may have been stopped — restart it with `picobase status`.',\n )\n this.name = 'InstanceUnavailableError'\n }\n}\n\n/**\n * Thrown when an API key is invalid or missing.\n */\nexport class AuthorizationError extends PicoBaseError {\n constructor(message = 'Invalid or missing API key.') {\n super(\n message,\n 'UNAUTHORIZED',\n 401,\n undefined,\n 'Make sure PICOBASE_API_KEY is set in your .env file and matches a valid key from your dashboard. ' +\n 'Keys start with \"pbk_\". You can generate a new key at https://picobase.com/dashboard.',\n )\n this.name = 'AuthorizationError'\n }\n}\n\n/**\n * Thrown when a collection is not found.\n */\nexport class CollectionNotFoundError extends PicoBaseError {\n constructor(collectionName: string) {\n super(\n `Collection \"${collectionName}\" not found.`,\n 'COLLECTION_NOT_FOUND',\n 404,\n { collection: collectionName },\n `Make sure the collection \"${collectionName}\" exists in your PicoBase instance. ` +\n 'Collections are auto-created when you first write data, or you can create them ' +\n 'manually in the PicoBase dashboard under Collections.',\n )\n this.name = 'CollectionNotFoundError'\n }\n}\n\n/**\n * Thrown when a record is not found.\n */\nexport class RecordNotFoundError extends PicoBaseError {\n constructor(collectionName: string, recordId: string) {\n super(\n `Record \"${recordId}\" not found in collection \"${collectionName}\".`,\n 'RECORD_NOT_FOUND',\n 404,\n { collection: collectionName, recordId },\n 'Check that the record ID is correct. IDs are 15-character alphanumeric strings (e.g., \"abc123def456789\").',\n )\n this.name = 'RecordNotFoundError'\n }\n}\n\n/**\n * Thrown when a PocketBase API request fails.\n */\nexport class RequestError extends PicoBaseError {\n constructor(message: string, status: number, details?: unknown) {\n const fix = requestErrorFix(status, message)\n super(message, 'REQUEST_FAILED', status, details, fix)\n this.name = 'RequestError'\n }\n}\n\n/**\n * Thrown when the SDK is misconfigured (bad URL, missing params, etc.).\n */\nexport class ConfigurationError extends PicoBaseError {\n constructor(message: string, fix: string) {\n super(message, 'CONFIGURATION_ERROR', undefined, undefined, fix)\n this.name = 'ConfigurationError'\n }\n}\n\n/**\n * Thrown when an RPC (remote procedure call) fails.\n */\nexport class RpcError extends PicoBaseError {\n constructor(functionName: string, status: number, details?: unknown) {\n const fix = rpcErrorFix(functionName, status)\n super(\n `RPC function \"${functionName}\" failed.`,\n 'RPC_ERROR',\n status,\n details,\n fix,\n )\n this.name = 'RpcError'\n }\n}\n\n/** Generate fix suggestions for RPC errors. */\nfunction rpcErrorFix(functionName: string, status: number): string {\n if (status === 404) {\n return `The RPC endpoint \"/api/rpc/${functionName}\" does not exist. ` +\n 'Create a custom route in your PocketBase instance to handle this RPC call. ' +\n 'See: https://pocketbase.io/docs/js-routing/'\n }\n if (status === 400) {\n return 'Check the parameters you are passing to this RPC function. ' +\n 'The function may be expecting different parameters or types.'\n }\n if (status === 403) {\n return 'You don\\'t have permission to call this RPC function. ' +\n 'Check the authentication requirements for this endpoint in your PocketBase routes.'\n }\n return 'Check your PicoBase instance logs for details about this RPC error. ' +\n 'Ensure the custom route is correctly implemented in your PocketBase setup.'\n}\n\n/** Map common HTTP statuses to actionable fixes. */\nfunction requestErrorFix(status: number, message: string): string {\n switch (status) {\n case 400:\n return 'Check the data you are sending — a required field may be missing or have the wrong type. ' +\n 'Run `picobase typegen` to regenerate types and check your field names.'\n case 403:\n return 'You don\\'t have permission for this action. Check your collection API rules in the dashboard. ' +\n 'By default, only authenticated users can read/write records.'\n case 404:\n if (message.toLowerCase().includes('collection'))\n return 'This collection does not exist yet. Write a record to auto-create it, or create it in the dashboard.'\n return 'The requested resource was not found. Double-check IDs and collection names.'\n case 413:\n return 'The request payload is too large. Check file upload size limits in your instance settings.'\n case 429:\n return 'Too many requests. Add a short delay between requests or implement client-side caching.'\n default:\n return 'If this error persists, check your PicoBase dashboard for instance health and logs.'\n }\n}\n","import PocketBase from 'pocketbase'\nimport { PicoBaseAuth } from './auth'\nimport { PicoBaseCollection } from './collection'\nimport { PicoBaseRealtime } from './realtime'\nimport { PicoBaseStorage } from './storage'\nimport { PicoBaseAdmin } from './admin'\nimport { InstanceUnavailableError, AuthorizationError, CollectionNotFoundError, RecordNotFoundError, ConfigurationError, RpcError } from './errors'\nimport type { PicoBaseClientOptions, RecordModel, SendOptions } from './types'\n\nconst DEFAULT_OPTIONS: Required<Omit<PicoBaseClientOptions, 'fetch'>> & { fetch?: typeof globalThis.fetch } = {\n timeout: 30_000,\n maxColdStartRetries: 3,\n lang: 'en-US',\n}\n\nexport class PicoBaseClient {\n /** The underlying PocketBase SDK instance. Exposed for advanced usage. */\n readonly pb: PocketBase\n /** Auth module — sign up, sign in, OAuth, session management. */\n readonly auth: PicoBaseAuth\n /** Realtime module — subscribe to record changes. */\n readonly realtime: PicoBaseRealtime\n /** Storage module — get file URLs and tokens. */\n readonly storage: PicoBaseStorage\n /** Admin module — manage collections (requires admin API key). */\n readonly admin: PicoBaseAdmin\n\n private readonly apiKey: string\n private readonly options: typeof DEFAULT_OPTIONS\n\n constructor(url: string, apiKey: string, options: PicoBaseClientOptions = {}) {\n // Validate inputs with clear messages\n if (!url) {\n throw new ConfigurationError(\n 'PicoBase URL is required.',\n 'Pass the URL as the first argument: createClient(\"https://myapp.picobase.com\", \"pbk_...\") ' +\n 'or set PICOBASE_URL in your .env file.',\n )\n }\n if (!apiKey) {\n throw new ConfigurationError(\n 'PicoBase API key is required.',\n 'Pass the API key as the second argument: createClient(\"https://...\", \"pbk_your_key\") ' +\n 'or set PICOBASE_API_KEY in your .env file. Get a key from your dashboard.',\n )\n }\n if (!url.startsWith('http://') && !url.startsWith('https://')) {\n throw new ConfigurationError(\n `Invalid URL: \"${url}\". Must start with http:// or https://.`,\n `Use the full URL: createClient(\"https://${url}\", \"...\")`,\n )\n }\n\n this.apiKey = apiKey\n this.options = { ...DEFAULT_OPTIONS, ...options }\n\n // Normalize URL — strip trailing slash\n const baseUrl = url.replace(/\\/+$/, '')\n\n this.pb = new PocketBase(baseUrl)\n this.pb.autoCancellation(false)\n\n if (this.options.lang) {\n this.pb.lang = this.options.lang\n }\n\n // Inject API key header into every request via beforeSend hook\n this.pb.beforeSend = (url, reqInit) => {\n const headers = reqInit.headers as Record<string, string> ?? {}\n headers['X-PicoBase-Key'] = this.apiKey\n reqInit.headers = headers\n return { url, options: reqInit }\n }\n\n // Wrap the send method for cold-start retry logic\n this._wrapSendWithRetry()\n\n // Initialize modules\n this.auth = new PicoBaseAuth(this.pb)\n this.realtime = new PicoBaseRealtime(this.pb)\n this.storage = new PicoBaseStorage(this.pb)\n this.admin = new PicoBaseAdmin(this.pb)\n }\n\n /**\n * Access a collection for CRUD operations.\n *\n * @example\n * ```ts\n * const posts = await pb.collection('posts').getList(1, 20)\n * ```\n */\n collection<T = RecordModel>(name: string): PicoBaseCollection<T> {\n return new PicoBaseCollection<T>(this.pb, name)\n }\n\n /**\n * Call a server-side function (PocketBase custom API endpoint).\n * Proxies to PocketBase's send() method.\n */\n async send<T = unknown>(path: string, options?: SendOptions): Promise<T> {\n return this.pb.send<T>(path, options ?? {})\n }\n\n /**\n * Call a remote procedure (RPC) - a convenience method for calling custom API endpoints.\n *\n * Maps Supabase-style RPC calls to PicoBase custom endpoints:\n * - `pb.rpc('my_function', params)` → `POST /api/rpc/my_function` with params as body\n *\n * @example\n * ```ts\n * // Simple RPC call\n * const result = await pb.rpc('calculate_total', { cart_id: '123' })\n *\n * // Complex RPC with typed response\n * interface DashboardStats {\n * posts: number\n * comments: number\n * followers: number\n * }\n * const stats = await pb.rpc<DashboardStats>('get_dashboard_stats', {\n * user_id: currentUser.id\n * })\n * ```\n *\n * @param functionName The name of the RPC function to call\n * @param params Optional parameters to pass to the function\n * @returns The function result\n */\n async rpc<T = unknown>(functionName: string, params?: Record<string, unknown>): Promise<T> {\n try {\n return await this.send<T>(`/api/rpc/${functionName}`, {\n method: 'POST',\n body: params ?? {},\n })\n } catch (err: unknown) {\n // Wrap errors with RpcError for better error messages\n const status = (err as { status?: number })?.status ?? 500\n const details = (err as { data?: unknown })?.data\n throw new RpcError(functionName, status, details)\n }\n }\n\n /**\n * Get the current auth token (if signed in), or empty string.\n */\n get token(): string {\n return this.pb.authStore.token\n }\n\n /**\n * Check if a user is currently authenticated.\n */\n get isAuthenticated(): boolean {\n return this.pb.authStore.isValid\n }\n\n /**\n * Monkey-patch pb.send to retry on 503 (cold start).\n *\n * When an instance is stopped or starting, the proxy returns 503.\n * The SDK automatically retries with exponential backoff so the developer\n * doesn't have to handle cold-start logic.\n */\n private _wrapSendWithRetry(): void {\n const originalSend = this.pb.send.bind(this.pb)\n const maxRetries = this.options.maxColdStartRetries\n\n this.pb.send = async <T>(path: string, options: SendOptions): Promise<T> => {\n let lastError: unknown\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await originalSend<T>(path, options)\n } catch (err: unknown) {\n lastError = err\n\n // Check if this is a 503 (instance starting up)\n const status = (err as { status?: number })?.status\n if (status === 503 && attempt < maxRetries) {\n // Exponential backoff: 2s, 4s, 8s\n const delay = Math.pow(2, attempt + 1) * 1000\n await new Promise(resolve => setTimeout(resolve, delay))\n continue\n }\n\n // Check if this is a 401 from our gateway (bad API key)\n if (status === 401) {\n const data = (err as { data?: { code?: string } })?.data\n if (data?.code === 'INVALID_API_KEY') {\n throw new AuthorizationError()\n }\n }\n\n // Detect collection-not-found for a clearer message\n if (status === 404) {\n const msg = (err as { message?: string })?.message ?? ''\n if (msg.toLowerCase().includes('missing collection') || msg.toLowerCase().includes('not found collection')) {\n const match = msg.match(/[\"']([^\"']+)[\"']/)\n throw new CollectionNotFoundError(match?.[1] ?? 'unknown')\n }\n }\n\n throw err\n }\n }\n\n throw new InstanceUnavailableError(\n `Instance unavailable after ${maxRetries} retries. ` +\n `Original error: ${lastError instanceof Error ? lastError.message : String(lastError)}`\n )\n }\n }\n}\n\n/**\n * Create a new PicoBase client.\n *\n * Can be called with explicit URL and API key, or with zero arguments to\n * auto-detect from environment variables (`PICOBASE_URL` / `NEXT_PUBLIC_PICOBASE_URL`\n * and `PICOBASE_API_KEY` / `NEXT_PUBLIC_PICOBASE_API_KEY`).\n *\n * @example\n * ```ts\n * import { createClient } from '@picobase_app/client'\n *\n * // Zero-config — reads from env vars\n * const pb = createClient()\n *\n * // Or explicit\n * const pb = createClient('https://myapp.picobase.com', 'pbk_abc123_secret')\n *\n * // Sign up a user\n * const user = await pb.auth.signUp({\n * email: 'user@example.com',\n * password: 'securepassword',\n * })\n *\n * // Query records\n * const posts = await pb.collection('posts').getList(1, 20, {\n * filter: 'published = true',\n * sort: '-created',\n * })\n * ```\n */\nexport function createClient(options?: PicoBaseClientOptions): PicoBaseClient\nexport function createClient(url: string, apiKey: string, options?: PicoBaseClientOptions): PicoBaseClient\nexport function createClient(\n urlOrOptions?: string | PicoBaseClientOptions,\n apiKeyOrUndefined?: string,\n options?: PicoBaseClientOptions,\n): PicoBaseClient {\n // Zero-arg / options-only: read from env\n if (typeof urlOrOptions !== 'string') {\n const env = typeof process !== 'undefined' ? process.env : {} as Record<string, string | undefined>\n const url = env.PICOBASE_URL || env.NEXT_PUBLIC_PICOBASE_URL\n const apiKey = env.PICOBASE_API_KEY || env.NEXT_PUBLIC_PICOBASE_API_KEY\n\n if (!url || !apiKey) {\n const missing = [\n !url && 'PICOBASE_URL (or NEXT_PUBLIC_PICOBASE_URL)',\n !apiKey && 'PICOBASE_API_KEY (or NEXT_PUBLIC_PICOBASE_API_KEY)',\n ].filter(Boolean).join(' and ')\n\n throw new ConfigurationError(\n `Missing environment variable${!url && !apiKey ? 's' : ''}: ${missing}`,\n 'Add them to your .env.local file:\\n\\n' +\n ' PICOBASE_URL=https://your-app.picobase.com\\n' +\n ' PICOBASE_API_KEY=pbk_your_key_here\\n\\n' +\n 'Or for Next.js (client-side access), prefix with NEXT_PUBLIC_:\\n\\n' +\n ' NEXT_PUBLIC_PICOBASE_URL=https://your-app.picobase.com\\n' +\n ' NEXT_PUBLIC_PICOBASE_API_KEY=pbk_your_key_here\\n\\n' +\n 'Get your URL and API key from: https://picobase.com/dashboard\\n' +\n 'Or run: picobase init',\n )\n }\n\n return new PicoBaseClient(url, apiKey, urlOrOptions)\n }\n\n return new PicoBaseClient(urlOrOptions, apiKeyOrUndefined!, options)\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picobase_app/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "PicoBase client SDK — auth, database, storage, and realtime for your apps",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "tsup
|
|
20
|
-
"dev": "tsup
|
|
19
|
+
"build": "tsup",
|
|
20
|
+
"dev": "tsup --watch",
|
|
21
21
|
"test": "vitest",
|
|
22
22
|
"test:watch": "vitest --watch",
|
|
23
23
|
"test:ui": "vitest --ui",
|
|
@@ -28,24 +28,25 @@
|
|
|
28
28
|
"release:minor": "npm version minor && npm publish",
|
|
29
29
|
"release:major": "npm version major && npm publish"
|
|
30
30
|
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"pocketbase": "^0.25.2"
|
|
33
|
-
},
|
|
34
31
|
"devDependencies": {
|
|
35
32
|
"@types/node": "^25.2.3",
|
|
36
33
|
"@vitest/ui": "^2.1.8",
|
|
37
34
|
"tsup": "^8.4.0",
|
|
38
35
|
"typescript": "^5.7.3",
|
|
39
|
-
"vitest": "^2.1.8"
|
|
36
|
+
"vitest": "^2.1.8",
|
|
37
|
+
"pocketbase": "^0.23.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"pocketbase": "^0.23.0"
|
|
40
41
|
},
|
|
41
42
|
"keywords": [
|
|
42
43
|
"picobase",
|
|
43
|
-
"pocketbase",
|
|
44
44
|
"baas",
|
|
45
45
|
"backend",
|
|
46
46
|
"auth",
|
|
47
47
|
"database",
|
|
48
|
-
"realtime"
|
|
48
|
+
"realtime",
|
|
49
|
+
"supabase-alternative"
|
|
49
50
|
],
|
|
50
51
|
"license": "MIT",
|
|
51
52
|
"repository": {
|