pocketbase-zod-schema 0.1.2
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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +167 -0
- package/dist/cli/index.cjs +3383 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +30 -0
- package/dist/cli/index.d.ts +30 -0
- package/dist/cli/index.js +3331 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/migrate.cjs +3380 -0
- package/dist/cli/migrate.cjs.map +1 -0
- package/dist/cli/migrate.d.cts +1 -0
- package/dist/cli/migrate.d.ts +1 -0
- package/dist/cli/migrate.js +3353 -0
- package/dist/cli/migrate.js.map +1 -0
- package/dist/cli/utils/index.cjs +540 -0
- package/dist/cli/utils/index.cjs.map +1 -0
- package/dist/cli/utils/index.d.cts +232 -0
- package/dist/cli/utils/index.d.ts +232 -0
- package/dist/cli/utils/index.js +487 -0
- package/dist/cli/utils/index.js.map +1 -0
- package/dist/enums.cjs +19 -0
- package/dist/enums.cjs.map +1 -0
- package/dist/enums.d.cts +6 -0
- package/dist/enums.d.ts +6 -0
- package/dist/enums.js +17 -0
- package/dist/enums.js.map +1 -0
- package/dist/index.cjs +4900 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +4726 -0
- package/dist/index.js.map +1 -0
- package/dist/migration/analyzer.cjs +1267 -0
- package/dist/migration/analyzer.cjs.map +1 -0
- package/dist/migration/analyzer.d.cts +186 -0
- package/dist/migration/analyzer.d.ts +186 -0
- package/dist/migration/analyzer.js +1232 -0
- package/dist/migration/analyzer.js.map +1 -0
- package/dist/migration/diff.cjs +557 -0
- package/dist/migration/diff.cjs.map +1 -0
- package/dist/migration/diff.d.cts +291 -0
- package/dist/migration/diff.d.ts +291 -0
- package/dist/migration/diff.js +534 -0
- package/dist/migration/diff.js.map +1 -0
- package/dist/migration/generator.cjs +778 -0
- package/dist/migration/generator.cjs.map +1 -0
- package/dist/migration/generator.d.cts +225 -0
- package/dist/migration/generator.d.ts +225 -0
- package/dist/migration/generator.js +737 -0
- package/dist/migration/generator.js.map +1 -0
- package/dist/migration/index.cjs +3390 -0
- package/dist/migration/index.cjs.map +1 -0
- package/dist/migration/index.d.cts +103 -0
- package/dist/migration/index.d.ts +103 -0
- package/dist/migration/index.js +3265 -0
- package/dist/migration/index.js.map +1 -0
- package/dist/migration/snapshot.cjs +609 -0
- package/dist/migration/snapshot.cjs.map +1 -0
- package/dist/migration/snapshot.d.cts +167 -0
- package/dist/migration/snapshot.d.ts +167 -0
- package/dist/migration/snapshot.js +575 -0
- package/dist/migration/snapshot.js.map +1 -0
- package/dist/migration/utils/index.cjs +672 -0
- package/dist/migration/utils/index.cjs.map +1 -0
- package/dist/migration/utils/index.d.cts +207 -0
- package/dist/migration/utils/index.d.ts +207 -0
- package/dist/migration/utils/index.js +641 -0
- package/dist/migration/utils/index.js.map +1 -0
- package/dist/mutator.cjs +427 -0
- package/dist/mutator.cjs.map +1 -0
- package/dist/mutator.d.cts +190 -0
- package/dist/mutator.d.ts +190 -0
- package/dist/mutator.js +425 -0
- package/dist/mutator.js.map +1 -0
- package/dist/permissions-ZHafVSIx.d.cts +71 -0
- package/dist/permissions-ZHafVSIx.d.ts +71 -0
- package/dist/schema.cjs +430 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +316 -0
- package/dist/schema.d.ts +316 -0
- package/dist/schema.js +396 -0
- package/dist/schema.js.map +1 -0
- package/dist/types-BbTgmg6H.d.cts +91 -0
- package/dist/types-z1Dkjg8m.d.ts +91 -0
- package/dist/types.cjs +4 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +14 -0
- package/dist/types.d.ts +14 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/user-jS1aYoeD.d.cts +123 -0
- package/dist/user-jS1aYoeD.d.ts +123 -0
- package/package.json +165 -0
package/dist/mutator.js
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/schema/base.ts
|
|
4
|
+
var baseSchema = {
|
|
5
|
+
id: z.string().describe("unique id"),
|
|
6
|
+
collectionId: z.string().describe("collection id"),
|
|
7
|
+
collectionName: z.string().describe("collection name"),
|
|
8
|
+
expand: z.record(z.any()).describe("expandable fields")
|
|
9
|
+
};
|
|
10
|
+
({
|
|
11
|
+
...baseSchema,
|
|
12
|
+
created: z.string().describe("creation timestamp"),
|
|
13
|
+
updated: z.string().describe("last update timestamp")
|
|
14
|
+
});
|
|
15
|
+
({
|
|
16
|
+
...baseSchema,
|
|
17
|
+
thumbnailURL: z.string().optional(),
|
|
18
|
+
imageFiles: z.array(z.string())
|
|
19
|
+
});
|
|
20
|
+
({
|
|
21
|
+
imageFiles: z.array(z.instanceof(File))
|
|
22
|
+
});
|
|
23
|
+
function withPermissions(schema, config) {
|
|
24
|
+
const metadata = {
|
|
25
|
+
permissions: config
|
|
26
|
+
};
|
|
27
|
+
return schema.describe(JSON.stringify(metadata));
|
|
28
|
+
}
|
|
29
|
+
function withIndexes(schema, indexes) {
|
|
30
|
+
let existingMetadata = {};
|
|
31
|
+
if (schema.description) {
|
|
32
|
+
try {
|
|
33
|
+
existingMetadata = JSON.parse(schema.description);
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const metadata = {
|
|
38
|
+
...existingMetadata,
|
|
39
|
+
indexes
|
|
40
|
+
};
|
|
41
|
+
return schema.describe(JSON.stringify(metadata));
|
|
42
|
+
}
|
|
43
|
+
var UserInputSchema = z.object({
|
|
44
|
+
name: z.string().min(2, "Name must be longer").optional(),
|
|
45
|
+
email: z.string().email(),
|
|
46
|
+
password: z.string().min(8, "Password must be at least 8 characters"),
|
|
47
|
+
passwordConfirm: z.string(),
|
|
48
|
+
avatar: z.instanceof(File).optional()
|
|
49
|
+
});
|
|
50
|
+
var UserDatabaseSchema = z.object({
|
|
51
|
+
name: z.string().min(2, "Name must be longer").optional(),
|
|
52
|
+
email: z.string().email(),
|
|
53
|
+
password: z.string().min(8, "Password must be at least 8 characters"),
|
|
54
|
+
avatar: z.instanceof(File).optional()
|
|
55
|
+
});
|
|
56
|
+
withIndexes(
|
|
57
|
+
withPermissions(UserDatabaseSchema.extend(baseSchema), {
|
|
58
|
+
// Users can list other users (for mentions, user search, etc.)
|
|
59
|
+
listRule: "id = @request.auth.id",
|
|
60
|
+
// Users can view their own profile
|
|
61
|
+
viewRule: "id = @request.auth.id",
|
|
62
|
+
// Anyone can create an account (sign up)
|
|
63
|
+
createRule: "",
|
|
64
|
+
// Users can only update their own profile
|
|
65
|
+
updateRule: "id = @request.auth.id",
|
|
66
|
+
// Users can only delete their own account
|
|
67
|
+
deleteRule: "id = @request.auth.id",
|
|
68
|
+
// Users can only manage their own account (change email, password, etc.)
|
|
69
|
+
manageRule: "id = @request.auth.id"
|
|
70
|
+
}),
|
|
71
|
+
[
|
|
72
|
+
// Email should be unique for authentication
|
|
73
|
+
"CREATE UNIQUE INDEX idx_users_email ON users (email)",
|
|
74
|
+
// Index on name for user search and sorting
|
|
75
|
+
"CREATE INDEX idx_users_name ON users (name)"
|
|
76
|
+
]
|
|
77
|
+
);
|
|
78
|
+
var BaseMutator = class {
|
|
79
|
+
pb;
|
|
80
|
+
// Define a default property that subclasses will override
|
|
81
|
+
options = {
|
|
82
|
+
expand: [],
|
|
83
|
+
filter: [],
|
|
84
|
+
sort: []
|
|
85
|
+
};
|
|
86
|
+
constructor(pb, options) {
|
|
87
|
+
this.pb = pb;
|
|
88
|
+
this.initializeOptions();
|
|
89
|
+
if (options) {
|
|
90
|
+
this.overrideOptions(options);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
initializeOptions() {
|
|
94
|
+
this.options = this.setDefaults();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Initialize options with class-specific defaults
|
|
98
|
+
* Subclasses should override this instead of directly setting options
|
|
99
|
+
*/
|
|
100
|
+
setDefaults() {
|
|
101
|
+
return {
|
|
102
|
+
expand: [],
|
|
103
|
+
filter: [],
|
|
104
|
+
sort: []
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Merge provided options with current options
|
|
109
|
+
*/
|
|
110
|
+
overrideOptions(newOptions) {
|
|
111
|
+
if (newOptions.expand !== void 0) {
|
|
112
|
+
this.options.expand = newOptions.expand;
|
|
113
|
+
}
|
|
114
|
+
if (newOptions.filter !== void 0) {
|
|
115
|
+
this.options.filter = newOptions.filter;
|
|
116
|
+
}
|
|
117
|
+
if (newOptions.sort !== void 0) {
|
|
118
|
+
this.options.sort = newOptions.sort;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
toSnakeCase(str) {
|
|
122
|
+
return str.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_|_$/g, "");
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create a new entity
|
|
126
|
+
*/
|
|
127
|
+
async create(input) {
|
|
128
|
+
try {
|
|
129
|
+
const data = await this.validateInput(input);
|
|
130
|
+
const record = await this.entityCreate(data);
|
|
131
|
+
return await this.processRecord(record);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
return this.errorWrapper(error);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Update an existing entity
|
|
138
|
+
*/
|
|
139
|
+
async update(id, input) {
|
|
140
|
+
try {
|
|
141
|
+
const record = await this.entityUpdate(id, input);
|
|
142
|
+
return await this.processRecord(record);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
return this.errorWrapper(error);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Create or update entity (upsert)
|
|
149
|
+
*/
|
|
150
|
+
async upsert(input) {
|
|
151
|
+
if (input?.id) {
|
|
152
|
+
return await this.update(input.id, input);
|
|
153
|
+
}
|
|
154
|
+
return await this.create(input);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get entity by ID
|
|
158
|
+
*/
|
|
159
|
+
async getById(id, expand) {
|
|
160
|
+
try {
|
|
161
|
+
const record = await this.entityGetById(id, expand);
|
|
162
|
+
return await this.processRecord(record);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
return this.handleError(error, { allowNotFound: true });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get first entity by filter
|
|
169
|
+
*/
|
|
170
|
+
async getFirstByFilter(filter, expand, sort) {
|
|
171
|
+
try {
|
|
172
|
+
const record = await this.entityGetFirstByFilter(filter, expand, sort);
|
|
173
|
+
return await this.processRecord(record);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
return this.handleError(error, { allowNotFound: true });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get list of entities
|
|
180
|
+
*/
|
|
181
|
+
async getList(page = 1, perPage = 100, filter, sort, expand) {
|
|
182
|
+
try {
|
|
183
|
+
const result = await this.entityGetList(page, perPage, filter, sort, expand);
|
|
184
|
+
return await this.processListResult(result);
|
|
185
|
+
} catch (error) {
|
|
186
|
+
return this.errorWrapper(error);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Delete entity by ID
|
|
191
|
+
*/
|
|
192
|
+
async delete(id) {
|
|
193
|
+
try {
|
|
194
|
+
return await this.entityDelete(id);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
return this.handleError(error, { returnValue: false });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Process a single record before returning it
|
|
201
|
+
* Can be overridden to handle special cases like mapped entities
|
|
202
|
+
*/
|
|
203
|
+
async processRecord(record) {
|
|
204
|
+
return record;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Process a list result before returning it
|
|
208
|
+
* Can be overridden to handle special cases like mapped entities
|
|
209
|
+
*/
|
|
210
|
+
async processListResult(result) {
|
|
211
|
+
const processedItems = await Promise.all(result.items.map((item) => this.processRecord(item)));
|
|
212
|
+
return {
|
|
213
|
+
...result,
|
|
214
|
+
items: processedItems
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Prepare expand parameter
|
|
219
|
+
* Combines default expands with provided expands
|
|
220
|
+
*/
|
|
221
|
+
prepareExpand(expand) {
|
|
222
|
+
if (!this.options.expand.length && !expand) {
|
|
223
|
+
return void 0;
|
|
224
|
+
}
|
|
225
|
+
let expandArray = [...this.options.expand];
|
|
226
|
+
if (expand) {
|
|
227
|
+
if (typeof expand === "string") {
|
|
228
|
+
expandArray = expandArray.concat(expand.split(",").map((e) => e.trim()));
|
|
229
|
+
} else {
|
|
230
|
+
expandArray = expandArray.concat(expand);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const uniqueExpands = [...new Set(expandArray)].filter((e) => e !== "" && e !== void 0);
|
|
234
|
+
if (!uniqueExpands.length) {
|
|
235
|
+
return void 0;
|
|
236
|
+
}
|
|
237
|
+
return uniqueExpands.join(",");
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Prepare filter parameter
|
|
241
|
+
* Combines default filters with provided filters
|
|
242
|
+
*/
|
|
243
|
+
prepareFilter(filter) {
|
|
244
|
+
if (!this.options.filter.length && !filter) {
|
|
245
|
+
return void 0;
|
|
246
|
+
}
|
|
247
|
+
let filterArray = [...this.options.filter];
|
|
248
|
+
if (filter) {
|
|
249
|
+
if (typeof filter === "string") {
|
|
250
|
+
if (filter) filterArray.push(filter);
|
|
251
|
+
} else {
|
|
252
|
+
filterArray = filterArray.concat(filter);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
const validFilters = filterArray.filter((f) => f !== "" && f !== void 0);
|
|
256
|
+
if (!validFilters.length) {
|
|
257
|
+
return void 0;
|
|
258
|
+
}
|
|
259
|
+
return validFilters.join("&&");
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Prepare sort parameter
|
|
263
|
+
* Uses provided sort or falls back to default sort
|
|
264
|
+
*/
|
|
265
|
+
prepareSort(sort) {
|
|
266
|
+
if (sort && sort !== "") {
|
|
267
|
+
return sort;
|
|
268
|
+
}
|
|
269
|
+
if (this.options.sort.length) {
|
|
270
|
+
const validSorts = this.options.sort.filter((s) => s !== "" && s !== void 0);
|
|
271
|
+
if (validSorts.length) {
|
|
272
|
+
return validSorts.join(",");
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return void 0;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Perform the actual create operation
|
|
279
|
+
*/
|
|
280
|
+
async entityCreate(data) {
|
|
281
|
+
return await this.getCollection().create(data);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Perform the actual update operation
|
|
285
|
+
*/
|
|
286
|
+
async entityUpdate(id, data) {
|
|
287
|
+
return await this.getCollection().update(id, data);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Perform the actual getById operation
|
|
291
|
+
*/
|
|
292
|
+
async entityGetById(id, expand) {
|
|
293
|
+
const finalExpand = this.prepareExpand(expand);
|
|
294
|
+
const options = finalExpand ? { expand: finalExpand } : {};
|
|
295
|
+
return await this.getCollection().getOne(id, options);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Perform the actual getFirstByFilter operation
|
|
299
|
+
*/
|
|
300
|
+
async entityGetFirstByFilter(filter, expand, sort) {
|
|
301
|
+
const finalFilter = this.prepareFilter(filter);
|
|
302
|
+
const finalExpand = this.prepareExpand(expand);
|
|
303
|
+
const finalSort = this.prepareSort(sort);
|
|
304
|
+
const options = {};
|
|
305
|
+
if (finalExpand) options.expand = finalExpand;
|
|
306
|
+
if (finalSort) options.sort = finalSort;
|
|
307
|
+
return await this.getCollection().getFirstListItem(finalFilter || "", options);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Perform the actual getList operation
|
|
311
|
+
* Returns a list result with items of type T
|
|
312
|
+
*/
|
|
313
|
+
async entityGetList(page, perPage, filter, sort, expand) {
|
|
314
|
+
const finalFilter = this.prepareFilter(filter);
|
|
315
|
+
const finalExpand = this.prepareExpand(expand);
|
|
316
|
+
const finalSort = this.prepareSort(sort);
|
|
317
|
+
const options = {};
|
|
318
|
+
if (finalFilter) options.filter = finalFilter;
|
|
319
|
+
if (finalExpand) options.expand = finalExpand;
|
|
320
|
+
if (finalSort) options.sort = finalSort;
|
|
321
|
+
return await this.getCollection().getList(page, perPage, options);
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Perform the actual delete operation
|
|
325
|
+
*/
|
|
326
|
+
async entityDelete(id) {
|
|
327
|
+
await this.getCollection().delete(id);
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Error handler for common errors
|
|
332
|
+
* @param error The error to handle
|
|
333
|
+
* @param options Handler options
|
|
334
|
+
* @returns The value to return if the error is handled, or throws if not handled
|
|
335
|
+
*/
|
|
336
|
+
handleError(error, options = { logError: true }) {
|
|
337
|
+
const { allowNotFound = false, returnValue, logError = true } = options;
|
|
338
|
+
if (logError) {
|
|
339
|
+
console.error(`Error in ${this.constructor.name}:`, error);
|
|
340
|
+
}
|
|
341
|
+
if (allowNotFound && this.isNotFoundError(error)) {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
if (returnValue !== void 0) {
|
|
345
|
+
return returnValue;
|
|
346
|
+
}
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Check if an error is a "not found" error
|
|
351
|
+
*/
|
|
352
|
+
isNotFoundError(error) {
|
|
353
|
+
return error instanceof Error && (error.message.includes("404") || error.message.toLowerCase().includes("not found"));
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Standard error handling wrapper (legacy method, consider using handleError instead)
|
|
357
|
+
*/
|
|
358
|
+
errorWrapper(error) {
|
|
359
|
+
console.error(`Error in ${this.constructor.name}:`, error);
|
|
360
|
+
throw error;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Subscribe to changes on a specific record
|
|
364
|
+
* @param id The ID of the record to subscribe to
|
|
365
|
+
* @param callback Function to call when changes occur
|
|
366
|
+
* @param expand Optional expand parameters
|
|
367
|
+
* @returns Promise that resolves to an unsubscribe function
|
|
368
|
+
*/
|
|
369
|
+
async subscribeToRecord(id, callback, expand) {
|
|
370
|
+
const finalExpand = this.prepareExpand(expand);
|
|
371
|
+
const options = finalExpand ? { expand: finalExpand } : {};
|
|
372
|
+
return this.getCollection().subscribe(id, callback, options);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Subscribe to changes on the entire collection
|
|
376
|
+
* @param callback Function to call when changes occur
|
|
377
|
+
* @param expand Optional expand parameters
|
|
378
|
+
* @returns Promise that resolves to an unsubscribe function
|
|
379
|
+
*/
|
|
380
|
+
async subscribeToCollection(callback, expand) {
|
|
381
|
+
const finalExpand = this.prepareExpand(expand);
|
|
382
|
+
const options = finalExpand ? { expand: finalExpand } : {};
|
|
383
|
+
return this.getCollection().subscribe("*", callback, options);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Unsubscribe from a specific record's changes
|
|
387
|
+
* @param id The ID of the record to unsubscribe from
|
|
388
|
+
*/
|
|
389
|
+
unsubscribeFromRecord(id) {
|
|
390
|
+
this.getCollection().unsubscribe(id);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Unsubscribe from collection-wide changes
|
|
394
|
+
*/
|
|
395
|
+
unsubscribeFromCollection() {
|
|
396
|
+
this.getCollection().unsubscribe("*");
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Unsubscribe from all subscriptions in this collection
|
|
400
|
+
*/
|
|
401
|
+
unsubscribeAll() {
|
|
402
|
+
this.getCollection().unsubscribe();
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
// src/mutator/userMutator.ts
|
|
407
|
+
var UserMutator = class extends BaseMutator {
|
|
408
|
+
setDefaults() {
|
|
409
|
+
return {
|
|
410
|
+
expand: [],
|
|
411
|
+
filter: [],
|
|
412
|
+
sort: ["-updated"]
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
getCollection() {
|
|
416
|
+
return this.pb.collection("Projects");
|
|
417
|
+
}
|
|
418
|
+
async validateInput(input) {
|
|
419
|
+
return UserInputSchema.parse(input);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
export { UserMutator };
|
|
424
|
+
//# sourceMappingURL=mutator.js.map
|
|
425
|
+
//# sourceMappingURL=mutator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema/base.ts","../src/schema/user.ts","../src/mutator/baseMutator.ts","../src/mutator/userMutator.ts"],"names":["z"],"mappings":";;;AAOO,IAAM,UAAA,GAAa;AAAA,EACxB,EAAA,EAAI,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,WAAW,CAAA;AAAA,EACnC,YAAA,EAAc,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,eAAe,CAAA;AAAA,EACjD,cAAA,EAAgB,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,iBAAiB,CAAA;AAAA,EACrD,MAAA,EAAQ,EAAE,MAAA,CAAO,CAAA,CAAE,KAAK,CAAA,CAAE,SAAS,mBAAmB;AACxD,CAAA;CAMwC;AAAA,EACtC,GAAG,UAAA;AAAA,EACH,OAAA,EAAS,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,oBAAoB,CAAA;AAAA,EACjD,OAAA,EAAS,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,uBAAuB;AACtD;CAMmC;AAAA,EACjC,GAAG,UAAA;AAAA,EACH,YAAA,EAAc,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,E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,IAAA,CAAK,EAAA,CAAG,UAAA,CAAW,UAAU,CAAA;AAAA,EACtC;AAAA,EAEA,MAAgB,cAAc,KAAA,EAAsB;AAClD,IAAA,OAAO,eAAA,CAAgB,MAAM,KAAK,CAAA;AAAA,EACpC;AACF","file":"mutator.js","sourcesContent":["import { z } from \"zod\";\nimport type { PermissionSchema, PermissionTemplateConfig } from \"./permissions\";\n\n/**\n * Base schema fields that PocketBase automatically adds to all records\n * These fields are managed by PocketBase and should not be set manually\n */\nexport const baseSchema = {\n id: z.string().describe(\"unique id\"),\n collectionId: z.string().describe(\"collection id\"),\n collectionName: z.string().describe(\"collection name\"),\n expand: z.record(z.any()).describe(\"expandable fields\"),\n};\n\n/**\n * Extended base schema with timestamp fields\n * Includes created and updated autodate fields\n */\nexport const baseSchemaWithTimestamps = {\n ...baseSchema,\n created: z.string().describe(\"creation timestamp\"),\n updated: z.string().describe(\"last update timestamp\"),\n};\n\n/**\n * Base schema for image file collections\n * Extends base schema with thumbnail URL and image files array\n */\nexport const baseImageFileSchema = {\n ...baseSchema,\n thumbnailURL: z.string().optional(),\n imageFiles: z.array(z.string()),\n};\n\n/**\n * Input schema for image file uploads\n * Used in forms where users upload File objects\n * Requires Node.js 20+ or browser environment with File API\n */\nexport const inputImageFileSchema = {\n imageFiles: z.array(z.instanceof(File)),\n};\n\n/**\n * Helper constant for omitting image files from schemas\n * Used with Zod's .omit() method\n */\nexport const omitImageFilesSchema = {\n imageFiles: true,\n} as const;\n\n// ============================================================================\n// Common PocketBase Field Type Patterns\n// ============================================================================\n\n/**\n * Creates a text field schema with optional constraints\n * @param options - Optional constraints for the text field\n */\nexport function textField(options?: { min?: number; max?: number; pattern?: RegExp }) {\n let schema = z.string();\n if (options?.min !== undefined) schema = schema.min(options.min);\n if (options?.max !== undefined) schema = schema.max(options.max);\n if (options?.pattern !== undefined) schema = schema.regex(options.pattern);\n return schema;\n}\n\n/**\n * Creates an email field schema\n * Maps to PocketBase 'email' field type\n */\nexport function emailField() {\n return z.string().email();\n}\n\n/**\n * Creates a URL field schema\n * Maps to PocketBase 'url' field type\n */\nexport function urlField() {\n return z.string().url();\n}\n\n/**\n * Creates a number field schema with optional constraints\n * @param options - Optional constraints for the number field\n */\nexport function numberField(options?: { min?: number; max?: number }) {\n let schema = z.number();\n if (options?.min !== undefined) schema = schema.min(options.min);\n if (options?.max !== undefined) schema = schema.max(options.max);\n return schema;\n}\n\n/**\n * Creates a boolean field schema\n * Maps to PocketBase 'bool' field type\n */\nexport function boolField() {\n return z.boolean();\n}\n\n/**\n * Creates a date field schema\n * Maps to PocketBase 'date' field type\n */\nexport function dateField() {\n return z.date();\n}\n\n/**\n * Creates a select field schema from enum values\n * Maps to PocketBase 'select' field type\n * @param values - Array of allowed string values\n */\nexport function selectField<T extends [string, ...string[]]>(values: T) {\n return z.enum(values);\n}\n\n/**\n * Creates a JSON field schema\n * Maps to PocketBase 'json' field type\n * @param schema - Optional Zod schema for the JSON structure\n */\nexport function jsonField<T extends z.ZodTypeAny>(schema?: T) {\n return schema ?? z.record(z.any());\n}\n\n/**\n * Creates a single file field schema for form input\n * Maps to PocketBase 'file' field type with maxSelect=1\n * Requires Node.js 20+ or browser environment with File API\n */\nexport function fileField() {\n return z.instanceof(File);\n}\n\n/**\n * Creates a multiple file field schema for form input\n * Maps to PocketBase 'file' field type with maxSelect>1\n * Requires Node.js 20+ or browser environment with File API\n * @param options - Optional constraints for the file field\n */\nexport function filesField(options?: { min?: number; max?: number }) {\n let schema = z.array(z.instanceof(File));\n if (options?.min !== undefined) schema = schema.min(options.min);\n if (options?.max !== undefined) schema = schema.max(options.max);\n return schema;\n}\n\n/**\n * Creates a single relation field schema\n * Maps to PocketBase 'relation' field type with maxSelect=1\n * Field name should start with uppercase to be detected as relation\n */\nexport function relationField() {\n return z.string();\n}\n\n/**\n * Creates a multiple relation field schema\n * Maps to PocketBase 'relation' field type with maxSelect>1\n * Field name should contain uppercase to be detected as relation\n * @param options - Optional constraints for the relation field\n */\nexport function relationsField(options?: { min?: number; max?: number }) {\n let schema = z.array(z.string());\n if (options?.min !== undefined) schema = schema.min(options.min);\n if (options?.max !== undefined) schema = schema.max(options.max);\n return schema;\n}\n\n/**\n * Creates an editor field schema (rich text)\n * Maps to PocketBase 'editor' field type\n */\nexport function editorField() {\n return z.string();\n}\n\n/**\n * Creates a geo point field schema\n * Maps to PocketBase 'geoPoint' field type\n */\nexport function geoPointField() {\n return z.object({\n lon: z.number(),\n lat: z.number(),\n });\n}\n\n/**\n * Attach permission metadata to a Zod schema\n *\n * This helper function allows you to define PocketBase API rules alongside your\n * entity schema definitions. The permissions are stored as metadata using Zod's\n * describe() method and will be extracted during migration generation.\n *\n * @param schema - The Zod schema to attach permissions to\n * @param config - Either a PermissionTemplateConfig (for template-based permissions)\n * or a PermissionSchema (for custom permissions)\n * @returns The schema with permission metadata attached\n *\n * @example\n * // Using a template\n * const ProjectSchema = withPermissions(\n * z.object({ title: z.string(), User: z.string() }),\n * { template: 'owner-only', ownerField: 'User' }\n * );\n *\n * @example\n * // Using custom rules\n * const ProjectSchema = withPermissions(\n * z.object({ title: z.string() }),\n * { listRule: '@request.auth.id != \"\"', viewRule: '' }\n * );\n *\n * @example\n * // Using template with custom rule overrides\n * const ProjectSchema = withPermissions(\n * z.object({ title: z.string(), User: z.string() }),\n * {\n * template: 'owner-only',\n * ownerField: 'User',\n * customRules: { listRule: '@request.auth.id != \"\"' }\n * }\n * );\n */\nexport function withPermissions<T extends z.ZodTypeAny>(\n schema: T,\n config: PermissionTemplateConfig | PermissionSchema\n): T {\n // Create metadata object with permissions config directly\n // The PermissionAnalyzer will handle resolving templates vs direct schemas\n const metadata = {\n permissions: config,\n };\n\n // Attach permission metadata to schema using Zod's describe() method\n // The metadata is serialized as JSON and stored in the schema's description\n return schema.describe(JSON.stringify(metadata)) as T;\n}\n\n/**\n * Attach index definitions to a Zod schema\n *\n * This helper function allows you to define PocketBase indexes alongside your\n * entity schema definitions. The indexes are stored as metadata using Zod's\n * describe() method and will be extracted during migration generation.\n *\n * @param schema - The Zod schema to attach indexes to\n * @param indexes - Array of PocketBase index SQL statements\n * @returns The schema with index metadata attached\n *\n * @example\n * // Define indexes for a user schema\n * const UserSchema = withIndexes(\n * withPermissions(\n * z.object({ name: z.string(), email: z.string().email() }),\n * userPermissions\n * ),\n * [\n * 'CREATE UNIQUE INDEX idx_users_email ON users (email)',\n * 'CREATE INDEX idx_users_name ON users (name)'\n * ]\n * );\n *\n * @example\n * // Single index\n * const ProjectSchema = withIndexes(\n * ProjectDatabaseSchema,\n * ['CREATE INDEX idx_projects_status ON projects (status)']\n * );\n */\nexport function withIndexes<T extends z.ZodTypeAny>(schema: T, indexes: string[]): T {\n // Extract existing metadata if present\n let existingMetadata: any = {};\n\n if (schema.description) {\n try {\n existingMetadata = JSON.parse(schema.description);\n } catch {\n // If description is not JSON, ignore it\n }\n }\n\n // Merge indexes with existing metadata\n const metadata = {\n ...existingMetadata,\n indexes,\n };\n\n // Attach metadata to schema using Zod's describe() method\n return schema.describe(JSON.stringify(metadata)) as T;\n}\n","import { z } from \"zod\";\nimport { baseSchema, withIndexes, withPermissions } from \"./base\";\n\n/** -- User Collections -- */\n// Input schema for forms (includes passwordConfirm for validation)\nexport const UserInputSchema = z.object({\n name: z.string().min(2, \"Name must be longer\").optional(),\n email: z.string().email(),\n password: z.string().min(8, \"Password must be at least 8 characters\"),\n passwordConfirm: z.string(),\n avatar: z.instanceof(File).optional(),\n});\n\n// Database schema (excludes passwordConfirm, includes avatar as file field)\nconst UserDatabaseSchema = z.object({\n name: z.string().min(2, \"Name must be longer\").optional(),\n email: z.string().email(),\n password: z.string().min(8, \"Password must be at least 8 characters\"),\n avatar: z.instanceof(File).optional(),\n});\n\n// Apply permissions and indexes for auth collection\n// Users can view all profiles, but only manage their own\nexport const UserSchema = withIndexes(\n withPermissions(UserDatabaseSchema.extend(baseSchema), {\n // Users can list other users (for mentions, user search, etc.)\n listRule: \"id = @request.auth.id\",\n // Users can view their own profile\n viewRule: \"id = @request.auth.id\",\n // Anyone can create an account (sign up)\n createRule: \"\",\n // Users can only update their own profile\n updateRule: \"id = @request.auth.id\",\n // Users can only delete their own account\n deleteRule: \"id = @request.auth.id\",\n // Users can only manage their own account (change email, password, etc.)\n manageRule: \"id = @request.auth.id\",\n }),\n [\n // Email should be unique for authentication\n \"CREATE UNIQUE INDEX idx_users_email ON users (email)\",\n // Index on name for user search and sorting\n \"CREATE INDEX idx_users_name ON users (name)\",\n ]\n);\n","import {\n RecordService,\n type ListResult,\n type RecordListOptions,\n type RecordModel,\n type RecordOptions,\n type RecordSubscribeOptions,\n type RecordSubscription,\n type UnsubscribeFunc,\n} from \"pocketbase\";\nimport type { TypedPocketBase } from \"../types\";\n\nexport interface MutatorOptions {\n expand: string[];\n filter: string[];\n sort: string[];\n}\n\n// T represents the output model type that extends RecordModel\n// InputType represents the input type for creation operations\nexport abstract class BaseMutator<T extends RecordModel, InputType> {\n protected pb: TypedPocketBase;\n\n // Define a default property that subclasses will override\n protected options: MutatorOptions = {\n expand: [],\n filter: [],\n sort: [],\n };\n\n constructor(pb: TypedPocketBase, options?: Partial<MutatorOptions>) {\n this.pb = pb;\n\n // Initialize with default options first\n this.initializeOptions();\n if (options) {\n this.overrideOptions(options);\n }\n }\n\n private initializeOptions(): void {\n this.options = this.setDefaults();\n }\n /**\n * Initialize options with class-specific defaults\n * Subclasses should override this instead of directly setting options\n */\n protected setDefaults(): MutatorOptions {\n return {\n expand: [],\n filter: [],\n sort: [],\n };\n }\n\n /**\n * Merge provided options with current options\n */\n protected overrideOptions(newOptions: Partial<MutatorOptions>): void {\n if (newOptions.expand !== undefined) {\n this.options.expand = newOptions.expand;\n }\n if (newOptions.filter !== undefined) {\n this.options.filter = newOptions.filter;\n }\n if (newOptions.sort !== undefined) {\n this.options.sort = newOptions.sort;\n }\n }\n\n /**\n * Get the collection instance\n */\n protected abstract getCollection(): RecordService<T>;\n\n toSnakeCase(str: string): string {\n return str\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"_\")\n .replace(/^_|_$/g, \"\");\n }\n\n /**\n * Create a new entity\n */\n async create(input: InputType): Promise<T> {\n try {\n const data = await this.validateInput(input);\n const record = await this.entityCreate(data);\n return await this.processRecord(record);\n } catch (error) {\n return this.errorWrapper(error);\n }\n }\n\n /**\n * Update an existing entity\n */\n async update(id: string, input: Partial<T>): Promise<T> {\n try {\n const record = await this.entityUpdate(id, input);\n return await this.processRecord(record);\n } catch (error) {\n return this.errorWrapper(error);\n }\n }\n\n /**\n * Create or update entity (upsert)\n */\n async upsert(input: InputType & { id?: string }): Promise<T> {\n if (input?.id) {\n return await this.update(input.id, input as Partial<T>);\n }\n\n // Implementations should override this method if they need\n // more specific upsert logic like checking for existing entities\n return await this.create(input);\n }\n\n /**\n * Get entity by ID\n */\n async getById(id: string, expand?: string | string[]): Promise<T | null> {\n try {\n const record = await this.entityGetById(id, expand);\n return await this.processRecord(record);\n } catch (error) {\n return this.handleError(error, { allowNotFound: true });\n }\n }\n\n /**\n * Get first entity by filter\n */\n async getFirstByFilter(filter: string | string[], expand?: string | string[], sort?: string): Promise<T | null> {\n try {\n const record = await this.entityGetFirstByFilter(filter, expand, sort);\n return await this.processRecord(record);\n } catch (error) {\n return this.handleError(error, { allowNotFound: true });\n }\n }\n\n /**\n * Get list of entities\n */\n async getList(\n page = 1,\n perPage = 100,\n filter?: string | string[],\n sort?: string,\n expand?: string | string[]\n ): Promise<ListResult<T>> {\n try {\n const result = await this.entityGetList(page, perPage, filter, sort, expand);\n return await this.processListResult(result);\n } catch (error) {\n return this.errorWrapper(error);\n }\n }\n\n /**\n * Delete entity by ID\n */\n async delete(id: string): Promise<boolean> {\n try {\n return await this.entityDelete(id);\n } catch (error) {\n return this.handleError(error, { returnValue: false });\n }\n }\n\n /**\n * Process a single record before returning it\n * Can be overridden to handle special cases like mapped entities\n */\n protected async processRecord(record: T): Promise<T> {\n return record;\n }\n\n /**\n * Process a list result before returning it\n * Can be overridden to handle special cases like mapped entities\n */\n protected async processListResult(result: ListResult<T>): Promise<ListResult<T>> {\n // Process each item in the list\n const processedItems = await Promise.all(result.items.map((item) => this.processRecord(item)));\n\n return {\n ...result,\n items: processedItems,\n };\n }\n\n /**\n * Prepare expand parameter\n * Combines default expands with provided expands\n */\n protected prepareExpand(expand?: string | string[]): string | undefined {\n // Handle empty defaults case\n if (!this.options.expand.length && !expand) {\n return undefined;\n }\n\n // Convert all inputs to arrays for easy processing\n let expandArray: string[] = [...this.options.expand];\n\n if (expand) {\n // If expand is a string, split it and add the parts\n if (typeof expand === \"string\") {\n expandArray = expandArray.concat(expand.split(\",\").map((e) => e.trim()));\n }\n // If expand is already an array, concatenate\n else {\n expandArray = expandArray.concat(expand);\n }\n }\n\n // Filter out duplicates, empty strings, and undefined values\n const uniqueExpands = [...new Set(expandArray)].filter((e) => e !== \"\" && e !== undefined);\n\n // If no valid expands, return undefined\n if (!uniqueExpands.length) {\n return undefined;\n }\n\n // Join with comma and space\n return uniqueExpands.join(\",\");\n }\n\n /**\n * Prepare filter parameter\n * Combines default filters with provided filters\n */\n protected prepareFilter(filter?: string | string[]): string | undefined {\n // Handle empty case\n if (!this.options.filter.length && !filter) {\n return undefined;\n }\n\n // Convert all inputs to arrays for easy processing\n let filterArray: string[] = [...this.options.filter];\n\n if (filter) {\n // If filter is a string, add it as is (it might contain && already)\n if (typeof filter === \"string\") {\n if (filter) filterArray.push(filter);\n }\n // If filter is an array, concatenate\n else {\n filterArray = filterArray.concat(filter);\n }\n }\n\n // Filter out empty strings and undefined values\n const validFilters = filterArray.filter((f) => f !== \"\" && f !== undefined);\n\n // If no valid filters, return undefined\n if (!validFilters.length) {\n return undefined;\n }\n\n // Join with AND operator\n return validFilters.join(\"&&\");\n }\n\n /**\n * Prepare sort parameter\n * Uses provided sort or falls back to default sort\n */\n protected prepareSort(sort?: string): string | undefined {\n // If explicit sort is provided and not empty, use it (overriding defaults)\n if (sort && sort !== \"\") {\n return sort;\n }\n\n // If no explicit sort but we have defaults\n if (this.options.sort.length) {\n // Filter out empty and undefined values\n const validSorts = this.options.sort.filter((s) => s !== \"\" && s !== undefined);\n\n // If we have valid sort items after filtering\n if (validSorts.length) {\n return validSorts.join(\",\");\n }\n }\n\n // No sort specified\n return undefined;\n }\n\n /**\n * Perform the actual create operation\n */\n protected async entityCreate(data: InputType): Promise<T> {\n return await this.getCollection().create(data as Record<string, any>);\n }\n\n /**\n * Perform the actual update operation\n */\n protected async entityUpdate(id: string, data: Partial<T>): Promise<T> {\n return await this.getCollection().update(id, data);\n }\n\n /**\n * Perform the actual getById operation\n */\n protected async entityGetById(id: string, expand?: string | string[]): Promise<T> {\n const finalExpand = this.prepareExpand(expand);\n const options: RecordOptions = finalExpand ? { expand: finalExpand } : {};\n return await this.getCollection().getOne(id, options);\n }\n\n /**\n * Perform the actual getFirstByFilter operation\n */\n protected async entityGetFirstByFilter(\n filter: string | string[],\n expand?: string | string[],\n sort?: string\n ): Promise<T> {\n const finalFilter = this.prepareFilter(filter);\n const finalExpand = this.prepareExpand(expand);\n const finalSort = this.prepareSort(sort);\n\n const options: RecordListOptions = {};\n if (finalExpand) options.expand = finalExpand;\n if (finalSort) options.sort = finalSort;\n\n return await this.getCollection().getFirstListItem(finalFilter || \"\", options);\n }\n\n /**\n * Perform the actual getList operation\n * Returns a list result with items of type T\n */\n protected async entityGetList(\n page: number,\n perPage: number,\n filter?: string | string[],\n sort?: string,\n expand?: string | string[]\n ): Promise<ListResult<T>> {\n const finalFilter = this.prepareFilter(filter);\n const finalExpand = this.prepareExpand(expand);\n const finalSort = this.prepareSort(sort);\n\n const options: RecordListOptions = {};\n if (finalFilter) options.filter = finalFilter;\n if (finalExpand) options.expand = finalExpand;\n if (finalSort) options.sort = finalSort;\n\n return await this.getCollection().getList(page, perPage, options);\n }\n\n /**\n * Perform the actual delete operation\n */\n protected async entityDelete(id: string): Promise<boolean> {\n await this.getCollection().delete(id);\n return true;\n }\n\n /**\n * Error handler for common errors\n * @param error The error to handle\n * @param options Handler options\n * @returns The value to return if the error is handled, or throws if not handled\n */\n protected handleError<R>(\n error: any,\n options: {\n allowNotFound?: boolean;\n returnValue?: R;\n logError?: boolean;\n } = { logError: true }\n ): R {\n const { allowNotFound = false, returnValue, logError = true } = options;\n\n // Log the error if requested\n if (logError) {\n console.error(`Error in ${this.constructor.name}:`, error);\n }\n\n // Handle 404 errors if allowed\n if (allowNotFound && this.isNotFoundError(error)) {\n return null as R;\n }\n\n // Return specified value or rethrow\n if (returnValue !== undefined) {\n return returnValue;\n }\n\n // Rethrow the error\n throw error;\n }\n\n /**\n * Check if an error is a \"not found\" error\n */\n protected isNotFoundError(error: any): boolean {\n return (\n error instanceof Error && (error.message.includes(\"404\") || error.message.toLowerCase().includes(\"not found\"))\n );\n }\n\n /**\n * Standard error handling wrapper (legacy method, consider using handleError instead)\n */\n protected errorWrapper(error: any): never {\n console.error(`Error in ${this.constructor.name}:`, error);\n throw error;\n }\n\n /**\n * Validate input data before creating/updating\n * Should be implemented by child classes\n */\n protected abstract validateInput(input: InputType): Promise<InputType>;\n\n /**\n * Subscribe to changes on a specific record\n * @param id The ID of the record to subscribe to\n * @param callback Function to call when changes occur\n * @param expand Optional expand parameters\n * @returns Promise that resolves to an unsubscribe function\n */\n async subscribeToRecord(\n id: string,\n callback: (data: RecordSubscription<T>) => void,\n expand?: string | string[]\n ): Promise<UnsubscribeFunc> {\n const finalExpand = this.prepareExpand(expand);\n const options: RecordSubscribeOptions = finalExpand ? { expand: finalExpand } : {};\n\n return this.getCollection().subscribe(id, callback, options);\n }\n\n /**\n * Subscribe to changes on the entire collection\n * @param callback Function to call when changes occur\n * @param expand Optional expand parameters\n * @returns Promise that resolves to an unsubscribe function\n */\n async subscribeToCollection(\n callback: (data: RecordSubscription<T>) => void,\n expand?: string | string[]\n ): Promise<UnsubscribeFunc> {\n const finalExpand = this.prepareExpand(expand);\n const options: RecordSubscribeOptions = finalExpand ? { expand: finalExpand } : {};\n\n return this.getCollection().subscribe(\"*\", callback, options);\n }\n\n /**\n * Unsubscribe from a specific record's changes\n * @param id The ID of the record to unsubscribe from\n */\n unsubscribeFromRecord(id: string): void {\n this.getCollection().unsubscribe(id);\n }\n\n /**\n * Unsubscribe from collection-wide changes\n */\n unsubscribeFromCollection(): void {\n this.getCollection().unsubscribe(\"*\");\n }\n\n /**\n * Unsubscribe from all subscriptions in this collection\n */\n unsubscribeAll(): void {\n this.getCollection().unsubscribe();\n }\n}\n","import { UserInputSchema } from \"../schema\";\nimport type { UserInputType, UserType } from \"../types\";\nimport { BaseMutator, type MutatorOptions } from \"./baseMutator\";\n\nexport class UserMutator extends BaseMutator<UserType, UserInputType> {\n protected setDefaults(): MutatorOptions {\n return {\n expand: [],\n filter: [],\n sort: [\"-updated\"],\n };\n }\n\n protected getCollection() {\n return this.pb.collection(\"Projects\");\n }\n\n protected async validateInput(input: UserInputType) {\n return UserInputSchema.parse(input);\n }\n}\n"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission schema types and interfaces for PocketBase API rules
|
|
3
|
+
*
|
|
4
|
+
* This module defines the core types for managing collection-level permissions
|
|
5
|
+
* that control access to list, view, create, update, delete, and manage operations.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* PocketBase API rule types
|
|
9
|
+
*
|
|
10
|
+
* Each rule type corresponds to a specific API operation:
|
|
11
|
+
* - listRule: Controls who can list/query records
|
|
12
|
+
* - viewRule: Controls who can view individual records
|
|
13
|
+
* - createRule: Controls who can create new records
|
|
14
|
+
* - updateRule: Controls who can update existing records
|
|
15
|
+
* - deleteRule: Controls who can delete records
|
|
16
|
+
* - manageRule: Controls who can manage auth records (auth collections only)
|
|
17
|
+
*/
|
|
18
|
+
type APIRuleType = "listRule" | "viewRule" | "createRule" | "updateRule" | "deleteRule" | "manageRule";
|
|
19
|
+
/**
|
|
20
|
+
* Rule expression - can be null (locked), empty string (public), or filter expression
|
|
21
|
+
*
|
|
22
|
+
* - null: Locked to superusers only
|
|
23
|
+
* - "" (empty string): Public access - anyone can perform the operation
|
|
24
|
+
* - string: Filter expression using PocketBase syntax (e.g., "@request.auth.id != ''")
|
|
25
|
+
*/
|
|
26
|
+
type RuleExpression = string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Permission schema definition
|
|
29
|
+
*
|
|
30
|
+
* Defines the complete set of API rules for a collection.
|
|
31
|
+
* All fields are optional - undefined rules will default to null (locked).
|
|
32
|
+
*/
|
|
33
|
+
interface PermissionSchema {
|
|
34
|
+
listRule?: RuleExpression;
|
|
35
|
+
viewRule?: RuleExpression;
|
|
36
|
+
createRule?: RuleExpression;
|
|
37
|
+
updateRule?: RuleExpression;
|
|
38
|
+
deleteRule?: RuleExpression;
|
|
39
|
+
manageRule?: RuleExpression;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Permission template types for common patterns
|
|
43
|
+
*
|
|
44
|
+
* Predefined templates that generate standard permission configurations:
|
|
45
|
+
* - public: All operations are publicly accessible
|
|
46
|
+
* - authenticated: Requires user authentication for all operations
|
|
47
|
+
* - owner-only: Users can only manage their own records
|
|
48
|
+
* - admin-only: Only admin/superusers can perform operations
|
|
49
|
+
* - read-public: Public read access, authenticated write access
|
|
50
|
+
* - custom: Fully custom rules defined by the developer
|
|
51
|
+
*/
|
|
52
|
+
type PermissionTemplate = "public" | "authenticated" | "owner-only" | "admin-only" | "read-public" | "custom";
|
|
53
|
+
/**
|
|
54
|
+
* Template configuration
|
|
55
|
+
*
|
|
56
|
+
* Configuration object for applying permission templates with customization options.
|
|
57
|
+
* Allows templates to be parameterized (e.g., specifying the owner field name)
|
|
58
|
+
* and overridden with custom rules.
|
|
59
|
+
*/
|
|
60
|
+
interface PermissionTemplateConfig {
|
|
61
|
+
/** The template to apply */
|
|
62
|
+
template: PermissionTemplate;
|
|
63
|
+
/** Field name for owner relation (default: 'User') - used with 'owner-only' template */
|
|
64
|
+
ownerField?: string;
|
|
65
|
+
/** Field name for role checking - used with 'admin-only' template */
|
|
66
|
+
roleField?: string;
|
|
67
|
+
/** Custom rules that override template-generated rules */
|
|
68
|
+
customRules?: Partial<PermissionSchema>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type { APIRuleType as A, PermissionSchema as P, RuleExpression as R, PermissionTemplate as a, PermissionTemplateConfig as b };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission schema types and interfaces for PocketBase API rules
|
|
3
|
+
*
|
|
4
|
+
* This module defines the core types for managing collection-level permissions
|
|
5
|
+
* that control access to list, view, create, update, delete, and manage operations.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* PocketBase API rule types
|
|
9
|
+
*
|
|
10
|
+
* Each rule type corresponds to a specific API operation:
|
|
11
|
+
* - listRule: Controls who can list/query records
|
|
12
|
+
* - viewRule: Controls who can view individual records
|
|
13
|
+
* - createRule: Controls who can create new records
|
|
14
|
+
* - updateRule: Controls who can update existing records
|
|
15
|
+
* - deleteRule: Controls who can delete records
|
|
16
|
+
* - manageRule: Controls who can manage auth records (auth collections only)
|
|
17
|
+
*/
|
|
18
|
+
type APIRuleType = "listRule" | "viewRule" | "createRule" | "updateRule" | "deleteRule" | "manageRule";
|
|
19
|
+
/**
|
|
20
|
+
* Rule expression - can be null (locked), empty string (public), or filter expression
|
|
21
|
+
*
|
|
22
|
+
* - null: Locked to superusers only
|
|
23
|
+
* - "" (empty string): Public access - anyone can perform the operation
|
|
24
|
+
* - string: Filter expression using PocketBase syntax (e.g., "@request.auth.id != ''")
|
|
25
|
+
*/
|
|
26
|
+
type RuleExpression = string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Permission schema definition
|
|
29
|
+
*
|
|
30
|
+
* Defines the complete set of API rules for a collection.
|
|
31
|
+
* All fields are optional - undefined rules will default to null (locked).
|
|
32
|
+
*/
|
|
33
|
+
interface PermissionSchema {
|
|
34
|
+
listRule?: RuleExpression;
|
|
35
|
+
viewRule?: RuleExpression;
|
|
36
|
+
createRule?: RuleExpression;
|
|
37
|
+
updateRule?: RuleExpression;
|
|
38
|
+
deleteRule?: RuleExpression;
|
|
39
|
+
manageRule?: RuleExpression;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Permission template types for common patterns
|
|
43
|
+
*
|
|
44
|
+
* Predefined templates that generate standard permission configurations:
|
|
45
|
+
* - public: All operations are publicly accessible
|
|
46
|
+
* - authenticated: Requires user authentication for all operations
|
|
47
|
+
* - owner-only: Users can only manage their own records
|
|
48
|
+
* - admin-only: Only admin/superusers can perform operations
|
|
49
|
+
* - read-public: Public read access, authenticated write access
|
|
50
|
+
* - custom: Fully custom rules defined by the developer
|
|
51
|
+
*/
|
|
52
|
+
type PermissionTemplate = "public" | "authenticated" | "owner-only" | "admin-only" | "read-public" | "custom";
|
|
53
|
+
/**
|
|
54
|
+
* Template configuration
|
|
55
|
+
*
|
|
56
|
+
* Configuration object for applying permission templates with customization options.
|
|
57
|
+
* Allows templates to be parameterized (e.g., specifying the owner field name)
|
|
58
|
+
* and overridden with custom rules.
|
|
59
|
+
*/
|
|
60
|
+
interface PermissionTemplateConfig {
|
|
61
|
+
/** The template to apply */
|
|
62
|
+
template: PermissionTemplate;
|
|
63
|
+
/** Field name for owner relation (default: 'User') - used with 'owner-only' template */
|
|
64
|
+
ownerField?: string;
|
|
65
|
+
/** Field name for role checking - used with 'admin-only' template */
|
|
66
|
+
roleField?: string;
|
|
67
|
+
/** Custom rules that override template-generated rules */
|
|
68
|
+
customRules?: Partial<PermissionSchema>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type { APIRuleType as A, PermissionSchema as P, RuleExpression as R, PermissionTemplate as a, PermissionTemplateConfig as b };
|