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.
Files changed (94) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE +21 -0
  3. package/README.md +167 -0
  4. package/dist/cli/index.cjs +3383 -0
  5. package/dist/cli/index.cjs.map +1 -0
  6. package/dist/cli/index.d.cts +30 -0
  7. package/dist/cli/index.d.ts +30 -0
  8. package/dist/cli/index.js +3331 -0
  9. package/dist/cli/index.js.map +1 -0
  10. package/dist/cli/migrate.cjs +3380 -0
  11. package/dist/cli/migrate.cjs.map +1 -0
  12. package/dist/cli/migrate.d.cts +1 -0
  13. package/dist/cli/migrate.d.ts +1 -0
  14. package/dist/cli/migrate.js +3353 -0
  15. package/dist/cli/migrate.js.map +1 -0
  16. package/dist/cli/utils/index.cjs +540 -0
  17. package/dist/cli/utils/index.cjs.map +1 -0
  18. package/dist/cli/utils/index.d.cts +232 -0
  19. package/dist/cli/utils/index.d.ts +232 -0
  20. package/dist/cli/utils/index.js +487 -0
  21. package/dist/cli/utils/index.js.map +1 -0
  22. package/dist/enums.cjs +19 -0
  23. package/dist/enums.cjs.map +1 -0
  24. package/dist/enums.d.cts +6 -0
  25. package/dist/enums.d.ts +6 -0
  26. package/dist/enums.js +17 -0
  27. package/dist/enums.js.map +1 -0
  28. package/dist/index.cjs +4900 -0
  29. package/dist/index.cjs.map +1 -0
  30. package/dist/index.d.cts +18 -0
  31. package/dist/index.d.ts +18 -0
  32. package/dist/index.js +4726 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/migration/analyzer.cjs +1267 -0
  35. package/dist/migration/analyzer.cjs.map +1 -0
  36. package/dist/migration/analyzer.d.cts +186 -0
  37. package/dist/migration/analyzer.d.ts +186 -0
  38. package/dist/migration/analyzer.js +1232 -0
  39. package/dist/migration/analyzer.js.map +1 -0
  40. package/dist/migration/diff.cjs +557 -0
  41. package/dist/migration/diff.cjs.map +1 -0
  42. package/dist/migration/diff.d.cts +291 -0
  43. package/dist/migration/diff.d.ts +291 -0
  44. package/dist/migration/diff.js +534 -0
  45. package/dist/migration/diff.js.map +1 -0
  46. package/dist/migration/generator.cjs +778 -0
  47. package/dist/migration/generator.cjs.map +1 -0
  48. package/dist/migration/generator.d.cts +225 -0
  49. package/dist/migration/generator.d.ts +225 -0
  50. package/dist/migration/generator.js +737 -0
  51. package/dist/migration/generator.js.map +1 -0
  52. package/dist/migration/index.cjs +3390 -0
  53. package/dist/migration/index.cjs.map +1 -0
  54. package/dist/migration/index.d.cts +103 -0
  55. package/dist/migration/index.d.ts +103 -0
  56. package/dist/migration/index.js +3265 -0
  57. package/dist/migration/index.js.map +1 -0
  58. package/dist/migration/snapshot.cjs +609 -0
  59. package/dist/migration/snapshot.cjs.map +1 -0
  60. package/dist/migration/snapshot.d.cts +167 -0
  61. package/dist/migration/snapshot.d.ts +167 -0
  62. package/dist/migration/snapshot.js +575 -0
  63. package/dist/migration/snapshot.js.map +1 -0
  64. package/dist/migration/utils/index.cjs +672 -0
  65. package/dist/migration/utils/index.cjs.map +1 -0
  66. package/dist/migration/utils/index.d.cts +207 -0
  67. package/dist/migration/utils/index.d.ts +207 -0
  68. package/dist/migration/utils/index.js +641 -0
  69. package/dist/migration/utils/index.js.map +1 -0
  70. package/dist/mutator.cjs +427 -0
  71. package/dist/mutator.cjs.map +1 -0
  72. package/dist/mutator.d.cts +190 -0
  73. package/dist/mutator.d.ts +190 -0
  74. package/dist/mutator.js +425 -0
  75. package/dist/mutator.js.map +1 -0
  76. package/dist/permissions-ZHafVSIx.d.cts +71 -0
  77. package/dist/permissions-ZHafVSIx.d.ts +71 -0
  78. package/dist/schema.cjs +430 -0
  79. package/dist/schema.cjs.map +1 -0
  80. package/dist/schema.d.cts +316 -0
  81. package/dist/schema.d.ts +316 -0
  82. package/dist/schema.js +396 -0
  83. package/dist/schema.js.map +1 -0
  84. package/dist/types-BbTgmg6H.d.cts +91 -0
  85. package/dist/types-z1Dkjg8m.d.ts +91 -0
  86. package/dist/types.cjs +4 -0
  87. package/dist/types.cjs.map +1 -0
  88. package/dist/types.d.cts +14 -0
  89. package/dist/types.d.ts +14 -0
  90. package/dist/types.js +3 -0
  91. package/dist/types.js.map +1 -0
  92. package/dist/user-jS1aYoeD.d.cts +123 -0
  93. package/dist/user-jS1aYoeD.d.ts +123 -0
  94. package/package.json +165 -0
@@ -0,0 +1,190 @@
1
+ import * as PocketBase from 'pocketbase';
2
+ import { RecordModel, RecordService, ListResult, RecordSubscription, UnsubscribeFunc } from 'pocketbase';
3
+ import { TypedPocketBase, UserType, UserInputType } from './types.cjs';
4
+ import 'zod';
5
+ import './user-jS1aYoeD.cjs';
6
+
7
+ interface MutatorOptions {
8
+ expand: string[];
9
+ filter: string[];
10
+ sort: string[];
11
+ }
12
+ declare abstract class BaseMutator<T extends RecordModel, InputType> {
13
+ protected pb: TypedPocketBase;
14
+ protected options: MutatorOptions;
15
+ constructor(pb: TypedPocketBase, options?: Partial<MutatorOptions>);
16
+ private initializeOptions;
17
+ /**
18
+ * Initialize options with class-specific defaults
19
+ * Subclasses should override this instead of directly setting options
20
+ */
21
+ protected setDefaults(): MutatorOptions;
22
+ /**
23
+ * Merge provided options with current options
24
+ */
25
+ protected overrideOptions(newOptions: Partial<MutatorOptions>): void;
26
+ /**
27
+ * Get the collection instance
28
+ */
29
+ protected abstract getCollection(): RecordService<T>;
30
+ toSnakeCase(str: string): string;
31
+ /**
32
+ * Create a new entity
33
+ */
34
+ create(input: InputType): Promise<T>;
35
+ /**
36
+ * Update an existing entity
37
+ */
38
+ update(id: string, input: Partial<T>): Promise<T>;
39
+ /**
40
+ * Create or update entity (upsert)
41
+ */
42
+ upsert(input: InputType & {
43
+ id?: string;
44
+ }): Promise<T>;
45
+ /**
46
+ * Get entity by ID
47
+ */
48
+ getById(id: string, expand?: string | string[]): Promise<T | null>;
49
+ /**
50
+ * Get first entity by filter
51
+ */
52
+ getFirstByFilter(filter: string | string[], expand?: string | string[], sort?: string): Promise<T | null>;
53
+ /**
54
+ * Get list of entities
55
+ */
56
+ getList(page?: number, perPage?: number, filter?: string | string[], sort?: string, expand?: string | string[]): Promise<ListResult<T>>;
57
+ /**
58
+ * Delete entity by ID
59
+ */
60
+ delete(id: string): Promise<boolean>;
61
+ /**
62
+ * Process a single record before returning it
63
+ * Can be overridden to handle special cases like mapped entities
64
+ */
65
+ protected processRecord(record: T): Promise<T>;
66
+ /**
67
+ * Process a list result before returning it
68
+ * Can be overridden to handle special cases like mapped entities
69
+ */
70
+ protected processListResult(result: ListResult<T>): Promise<ListResult<T>>;
71
+ /**
72
+ * Prepare expand parameter
73
+ * Combines default expands with provided expands
74
+ */
75
+ protected prepareExpand(expand?: string | string[]): string | undefined;
76
+ /**
77
+ * Prepare filter parameter
78
+ * Combines default filters with provided filters
79
+ */
80
+ protected prepareFilter(filter?: string | string[]): string | undefined;
81
+ /**
82
+ * Prepare sort parameter
83
+ * Uses provided sort or falls back to default sort
84
+ */
85
+ protected prepareSort(sort?: string): string | undefined;
86
+ /**
87
+ * Perform the actual create operation
88
+ */
89
+ protected entityCreate(data: InputType): Promise<T>;
90
+ /**
91
+ * Perform the actual update operation
92
+ */
93
+ protected entityUpdate(id: string, data: Partial<T>): Promise<T>;
94
+ /**
95
+ * Perform the actual getById operation
96
+ */
97
+ protected entityGetById(id: string, expand?: string | string[]): Promise<T>;
98
+ /**
99
+ * Perform the actual getFirstByFilter operation
100
+ */
101
+ protected entityGetFirstByFilter(filter: string | string[], expand?: string | string[], sort?: string): Promise<T>;
102
+ /**
103
+ * Perform the actual getList operation
104
+ * Returns a list result with items of type T
105
+ */
106
+ protected entityGetList(page: number, perPage: number, filter?: string | string[], sort?: string, expand?: string | string[]): Promise<ListResult<T>>;
107
+ /**
108
+ * Perform the actual delete operation
109
+ */
110
+ protected entityDelete(id: string): Promise<boolean>;
111
+ /**
112
+ * Error handler for common errors
113
+ * @param error The error to handle
114
+ * @param options Handler options
115
+ * @returns The value to return if the error is handled, or throws if not handled
116
+ */
117
+ protected handleError<R>(error: any, options?: {
118
+ allowNotFound?: boolean;
119
+ returnValue?: R;
120
+ logError?: boolean;
121
+ }): R;
122
+ /**
123
+ * Check if an error is a "not found" error
124
+ */
125
+ protected isNotFoundError(error: any): boolean;
126
+ /**
127
+ * Standard error handling wrapper (legacy method, consider using handleError instead)
128
+ */
129
+ protected errorWrapper(error: any): never;
130
+ /**
131
+ * Validate input data before creating/updating
132
+ * Should be implemented by child classes
133
+ */
134
+ protected abstract validateInput(input: InputType): Promise<InputType>;
135
+ /**
136
+ * Subscribe to changes on a specific record
137
+ * @param id The ID of the record to subscribe to
138
+ * @param callback Function to call when changes occur
139
+ * @param expand Optional expand parameters
140
+ * @returns Promise that resolves to an unsubscribe function
141
+ */
142
+ subscribeToRecord(id: string, callback: (data: RecordSubscription<T>) => void, expand?: string | string[]): Promise<UnsubscribeFunc>;
143
+ /**
144
+ * Subscribe to changes on the entire collection
145
+ * @param callback Function to call when changes occur
146
+ * @param expand Optional expand parameters
147
+ * @returns Promise that resolves to an unsubscribe function
148
+ */
149
+ subscribeToCollection(callback: (data: RecordSubscription<T>) => void, expand?: string | string[]): Promise<UnsubscribeFunc>;
150
+ /**
151
+ * Unsubscribe from a specific record's changes
152
+ * @param id The ID of the record to unsubscribe from
153
+ */
154
+ unsubscribeFromRecord(id: string): void;
155
+ /**
156
+ * Unsubscribe from collection-wide changes
157
+ */
158
+ unsubscribeFromCollection(): void;
159
+ /**
160
+ * Unsubscribe from all subscriptions in this collection
161
+ */
162
+ unsubscribeAll(): void;
163
+ }
164
+
165
+ declare class UserMutator extends BaseMutator<UserType, UserInputType> {
166
+ protected setDefaults(): MutatorOptions;
167
+ protected getCollection(): PocketBase.RecordService<{
168
+ status: "draft" | "active" | "complete" | "fail";
169
+ User: string;
170
+ title: string;
171
+ content: string;
172
+ SubscriberUsers: string[];
173
+ imageFiles: string[];
174
+ id: string;
175
+ collectionId: string;
176
+ collectionName: string;
177
+ expand: Record<string, any>;
178
+ summary?: string | undefined;
179
+ thumbnailURL?: string | undefined;
180
+ }>;
181
+ protected validateInput(input: UserInputType): Promise<{
182
+ email: string;
183
+ password: string;
184
+ passwordConfirm: string;
185
+ name?: string | undefined;
186
+ avatar?: File | undefined;
187
+ }>;
188
+ }
189
+
190
+ export { UserMutator };
@@ -0,0 +1,190 @@
1
+ import * as PocketBase from 'pocketbase';
2
+ import { RecordModel, RecordService, ListResult, RecordSubscription, UnsubscribeFunc } from 'pocketbase';
3
+ import { TypedPocketBase, UserType, UserInputType } from './types.js';
4
+ import 'zod';
5
+ import './user-jS1aYoeD.js';
6
+
7
+ interface MutatorOptions {
8
+ expand: string[];
9
+ filter: string[];
10
+ sort: string[];
11
+ }
12
+ declare abstract class BaseMutator<T extends RecordModel, InputType> {
13
+ protected pb: TypedPocketBase;
14
+ protected options: MutatorOptions;
15
+ constructor(pb: TypedPocketBase, options?: Partial<MutatorOptions>);
16
+ private initializeOptions;
17
+ /**
18
+ * Initialize options with class-specific defaults
19
+ * Subclasses should override this instead of directly setting options
20
+ */
21
+ protected setDefaults(): MutatorOptions;
22
+ /**
23
+ * Merge provided options with current options
24
+ */
25
+ protected overrideOptions(newOptions: Partial<MutatorOptions>): void;
26
+ /**
27
+ * Get the collection instance
28
+ */
29
+ protected abstract getCollection(): RecordService<T>;
30
+ toSnakeCase(str: string): string;
31
+ /**
32
+ * Create a new entity
33
+ */
34
+ create(input: InputType): Promise<T>;
35
+ /**
36
+ * Update an existing entity
37
+ */
38
+ update(id: string, input: Partial<T>): Promise<T>;
39
+ /**
40
+ * Create or update entity (upsert)
41
+ */
42
+ upsert(input: InputType & {
43
+ id?: string;
44
+ }): Promise<T>;
45
+ /**
46
+ * Get entity by ID
47
+ */
48
+ getById(id: string, expand?: string | string[]): Promise<T | null>;
49
+ /**
50
+ * Get first entity by filter
51
+ */
52
+ getFirstByFilter(filter: string | string[], expand?: string | string[], sort?: string): Promise<T | null>;
53
+ /**
54
+ * Get list of entities
55
+ */
56
+ getList(page?: number, perPage?: number, filter?: string | string[], sort?: string, expand?: string | string[]): Promise<ListResult<T>>;
57
+ /**
58
+ * Delete entity by ID
59
+ */
60
+ delete(id: string): Promise<boolean>;
61
+ /**
62
+ * Process a single record before returning it
63
+ * Can be overridden to handle special cases like mapped entities
64
+ */
65
+ protected processRecord(record: T): Promise<T>;
66
+ /**
67
+ * Process a list result before returning it
68
+ * Can be overridden to handle special cases like mapped entities
69
+ */
70
+ protected processListResult(result: ListResult<T>): Promise<ListResult<T>>;
71
+ /**
72
+ * Prepare expand parameter
73
+ * Combines default expands with provided expands
74
+ */
75
+ protected prepareExpand(expand?: string | string[]): string | undefined;
76
+ /**
77
+ * Prepare filter parameter
78
+ * Combines default filters with provided filters
79
+ */
80
+ protected prepareFilter(filter?: string | string[]): string | undefined;
81
+ /**
82
+ * Prepare sort parameter
83
+ * Uses provided sort or falls back to default sort
84
+ */
85
+ protected prepareSort(sort?: string): string | undefined;
86
+ /**
87
+ * Perform the actual create operation
88
+ */
89
+ protected entityCreate(data: InputType): Promise<T>;
90
+ /**
91
+ * Perform the actual update operation
92
+ */
93
+ protected entityUpdate(id: string, data: Partial<T>): Promise<T>;
94
+ /**
95
+ * Perform the actual getById operation
96
+ */
97
+ protected entityGetById(id: string, expand?: string | string[]): Promise<T>;
98
+ /**
99
+ * Perform the actual getFirstByFilter operation
100
+ */
101
+ protected entityGetFirstByFilter(filter: string | string[], expand?: string | string[], sort?: string): Promise<T>;
102
+ /**
103
+ * Perform the actual getList operation
104
+ * Returns a list result with items of type T
105
+ */
106
+ protected entityGetList(page: number, perPage: number, filter?: string | string[], sort?: string, expand?: string | string[]): Promise<ListResult<T>>;
107
+ /**
108
+ * Perform the actual delete operation
109
+ */
110
+ protected entityDelete(id: string): Promise<boolean>;
111
+ /**
112
+ * Error handler for common errors
113
+ * @param error The error to handle
114
+ * @param options Handler options
115
+ * @returns The value to return if the error is handled, or throws if not handled
116
+ */
117
+ protected handleError<R>(error: any, options?: {
118
+ allowNotFound?: boolean;
119
+ returnValue?: R;
120
+ logError?: boolean;
121
+ }): R;
122
+ /**
123
+ * Check if an error is a "not found" error
124
+ */
125
+ protected isNotFoundError(error: any): boolean;
126
+ /**
127
+ * Standard error handling wrapper (legacy method, consider using handleError instead)
128
+ */
129
+ protected errorWrapper(error: any): never;
130
+ /**
131
+ * Validate input data before creating/updating
132
+ * Should be implemented by child classes
133
+ */
134
+ protected abstract validateInput(input: InputType): Promise<InputType>;
135
+ /**
136
+ * Subscribe to changes on a specific record
137
+ * @param id The ID of the record to subscribe to
138
+ * @param callback Function to call when changes occur
139
+ * @param expand Optional expand parameters
140
+ * @returns Promise that resolves to an unsubscribe function
141
+ */
142
+ subscribeToRecord(id: string, callback: (data: RecordSubscription<T>) => void, expand?: string | string[]): Promise<UnsubscribeFunc>;
143
+ /**
144
+ * Subscribe to changes on the entire collection
145
+ * @param callback Function to call when changes occur
146
+ * @param expand Optional expand parameters
147
+ * @returns Promise that resolves to an unsubscribe function
148
+ */
149
+ subscribeToCollection(callback: (data: RecordSubscription<T>) => void, expand?: string | string[]): Promise<UnsubscribeFunc>;
150
+ /**
151
+ * Unsubscribe from a specific record's changes
152
+ * @param id The ID of the record to unsubscribe from
153
+ */
154
+ unsubscribeFromRecord(id: string): void;
155
+ /**
156
+ * Unsubscribe from collection-wide changes
157
+ */
158
+ unsubscribeFromCollection(): void;
159
+ /**
160
+ * Unsubscribe from all subscriptions in this collection
161
+ */
162
+ unsubscribeAll(): void;
163
+ }
164
+
165
+ declare class UserMutator extends BaseMutator<UserType, UserInputType> {
166
+ protected setDefaults(): MutatorOptions;
167
+ protected getCollection(): PocketBase.RecordService<{
168
+ status: "draft" | "active" | "complete" | "fail";
169
+ User: string;
170
+ title: string;
171
+ content: string;
172
+ SubscriberUsers: string[];
173
+ imageFiles: string[];
174
+ id: string;
175
+ collectionId: string;
176
+ collectionName: string;
177
+ expand: Record<string, any>;
178
+ summary?: string | undefined;
179
+ thumbnailURL?: string | undefined;
180
+ }>;
181
+ protected validateInput(input: UserInputType): Promise<{
182
+ email: string;
183
+ password: string;
184
+ passwordConfirm: string;
185
+ name?: string | undefined;
186
+ avatar?: File | undefined;
187
+ }>;
188
+ }
189
+
190
+ export { UserMutator };