pocketbase-zod-schema 0.7.2 → 1.0.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/CHANGELOG.md +25 -0
- package/README.md +198 -25
- package/dist/cli/index.cjs +3740 -1233
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +3737 -1232
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +3815 -1201
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +3811 -1199
- package/dist/cli/migrate.js.map +1 -1
- package/dist/cli/utils/index.cjs +52 -13
- package/dist/cli/utils/index.cjs.map +1 -1
- package/dist/cli/utils/index.d.cts +46 -1
- package/dist/cli/utils/index.d.ts +46 -1
- package/dist/cli/utils/index.js +51 -13
- package/dist/cli/utils/index.js.map +1 -1
- package/dist/migration/analyzer.cjs +123 -42
- package/dist/migration/analyzer.cjs.map +1 -1
- package/dist/migration/analyzer.js +123 -42
- package/dist/migration/analyzer.js.map +1 -1
- package/dist/migration/diff.cjs +13 -0
- package/dist/migration/diff.cjs.map +1 -1
- package/dist/migration/diff.js +13 -0
- package/dist/migration/diff.js.map +1 -1
- package/dist/migration/engine.cjs +3263 -0
- package/dist/migration/engine.cjs.map +1 -0
- package/dist/migration/engine.d.cts +105 -0
- package/dist/migration/engine.d.ts +105 -0
- package/dist/migration/engine.js +3173 -0
- package/dist/migration/engine.js.map +1 -0
- package/dist/migration/generator.cjs +40 -18
- package/dist/migration/generator.cjs.map +1 -1
- package/dist/migration/generator.d.cts +45 -2
- package/dist/migration/generator.d.ts +45 -2
- package/dist/migration/generator.js +39 -19
- package/dist/migration/generator.js.map +1 -1
- package/dist/migration/index.cjs +3479 -1145
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.d.cts +21 -4
- package/dist/migration/index.d.ts +21 -4
- package/dist/migration/index.js +3433 -1142
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/snapshot.cjs +2200 -804
- package/dist/migration/snapshot.cjs.map +1 -1
- package/dist/migration/snapshot.d.cts +24 -66
- package/dist/migration/snapshot.d.ts +24 -66
- package/dist/migration/snapshot.js +2198 -801
- package/dist/migration/snapshot.js.map +1 -1
- package/dist/migration/utils/index.cjs +51 -9
- package/dist/migration/utils/index.cjs.map +1 -1
- package/dist/migration/utils/index.d.cts +1 -1
- package/dist/migration/utils/index.d.ts +1 -1
- package/dist/migration/utils/index.js +50 -10
- package/dist/migration/utils/index.js.map +1 -1
- package/dist/server.cjs +3837 -1248
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +6 -4
- package/dist/server.d.ts +6 -4
- package/dist/server.js +3791 -1245
- package/dist/server.js.map +1 -1
- package/dist/{type-mapper-Bu9qjCdd.d.cts → type-mapper-BSPTj8t5.d.cts} +23 -1
- package/dist/{type-mapper-JBaVuKE2.d.ts → type-mapper-D31WYDee.d.ts} +23 -1
- package/dist/types-B_MLb1Ob.d.ts +475 -0
- package/dist/types-upZBVMfb.d.cts +475 -0
- package/dist/verify-BF72n2df.d.ts +402 -0
- package/dist/verify-DTzYpiXX.d.cts +402 -0
- package/package.json +7 -1
|
@@ -1,49 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as EngineOptions, j as AppliedMigrationsSource } from '../types-upZBVMfb.cjs';
|
|
2
|
+
import { a as SchemaSnapshot, S as SchemaDefinition } from '../types-CnzfX6JH.cjs';
|
|
2
3
|
import '../fields-B96iGprI.cjs';
|
|
3
4
|
import 'zod';
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
-
* Migration File Parser
|
|
7
|
-
* Parses PocketBase migration files to extract collection operations
|
|
8
|
-
*
|
|
9
|
-
* This module handles parsing migration files to extract:
|
|
10
|
-
* - Collection creations (new Collection(...))
|
|
11
|
-
* - Collection deletions (app.delete(...))
|
|
12
|
-
* - Field modifications (field.property = value)
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
interface ParsedCollectionUpdate {
|
|
16
|
-
collectionName: string;
|
|
17
|
-
fieldsToAdd: FieldDefinition[];
|
|
18
|
-
fieldsToRemove: string[];
|
|
19
|
-
fieldsToUpdate: {
|
|
20
|
-
fieldName: string;
|
|
21
|
-
changes: Record<string, any>;
|
|
22
|
-
}[];
|
|
23
|
-
indexesToAdd: string[];
|
|
24
|
-
indexesToRemove: string[];
|
|
25
|
-
rulesToUpdate: Record<string, string | null>;
|
|
26
|
-
/** New SQL query for a view collection, when the migration updates one */
|
|
27
|
-
viewQuery?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* PocketBase Format Converter
|
|
32
|
-
* Converts PocketBase collection objects to our internal CollectionSchema format
|
|
33
|
-
*
|
|
34
|
-
* This module handles conversion between PocketBase's native collection format
|
|
35
|
-
* (as found in migration files and snapshots) and our internal schema representation.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Converts PocketBase migration format to SchemaSnapshot
|
|
40
|
-
* Extracts the snapshot array from the migration file content
|
|
41
|
-
*
|
|
42
|
-
* @param migrationContent - Raw migration file content
|
|
43
|
-
* @returns SchemaSnapshot with collections map
|
|
44
|
-
*/
|
|
45
|
-
declare function convertPocketBaseMigration(migrationContent: string): SchemaSnapshot;
|
|
46
|
-
|
|
47
6
|
/**
|
|
48
7
|
* Snapshot Manager
|
|
49
8
|
* Handles saving and loading schema snapshots from JSON files
|
|
@@ -81,6 +40,18 @@ interface SnapshotConfig {
|
|
|
81
40
|
* Custom snapshot version for testing
|
|
82
41
|
*/
|
|
83
42
|
version?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Options forwarded to the execution engine, which reconstructs state by
|
|
45
|
+
* executing migration files in a simulated PocketBase JSVM.
|
|
46
|
+
*/
|
|
47
|
+
engineOptions?: EngineOptions;
|
|
48
|
+
/**
|
|
49
|
+
* Migrations PocketBase has actually applied, read from its `_migrations`
|
|
50
|
+
* table (see `readAppliedMigrations`). When supplied, replay starts from
|
|
51
|
+
* the newest applied snapshot and stops at the applied set, so a migration
|
|
52
|
+
* written but not yet run does not leak into the reconstructed state.
|
|
53
|
+
*/
|
|
54
|
+
appliedMigrations?: AppliedMigrationsSource | string[] | null;
|
|
84
55
|
}
|
|
85
56
|
/**
|
|
86
57
|
* Gets the snapshot file path from configuration
|
|
@@ -133,32 +104,24 @@ declare function mergeSnapshots(baseSnapshot: SchemaSnapshot, customSnapshot: Sc
|
|
|
133
104
|
*/
|
|
134
105
|
declare function findLatestSnapshot(migrationsPath: string): string | null;
|
|
135
106
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
107
|
+
* Reconstructs the current database state: executes the snapshot migration and
|
|
108
|
+
* every migration after it in a simulated PocketBase JSVM.
|
|
138
109
|
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*/
|
|
143
|
-
declare function applyMigrationOperations(snapshot: SchemaSnapshot, operations: {
|
|
144
|
-
collectionsToCreate: CollectionSchema[];
|
|
145
|
-
collectionsToDelete: string[];
|
|
146
|
-
collectionsToUpdate: ParsedCollectionUpdate[];
|
|
147
|
-
}): SchemaSnapshot;
|
|
148
|
-
/**
|
|
149
|
-
* Loads snapshot and applies all migrations that come after it
|
|
150
|
-
* This gives us the current state of the database schema
|
|
110
|
+
* A migration that cannot be executed fails hard — continuing past it would
|
|
111
|
+
* silently reconstruct the wrong state and cause the generator to emit
|
|
112
|
+
* incorrect diffs.
|
|
151
113
|
*
|
|
152
114
|
* @param config - Snapshot configuration (must include migrationsPath)
|
|
153
|
-
* @returns SchemaSnapshot
|
|
115
|
+
* @returns SchemaSnapshot representing the current state, or null when there is
|
|
116
|
+
* nothing to replay (an empty database)
|
|
154
117
|
*/
|
|
155
118
|
declare function loadSnapshotWithMigrations(config?: SnapshotConfig): SchemaSnapshot | null;
|
|
156
119
|
/**
|
|
157
120
|
* Loads snapshot if it exists, returns null for first run
|
|
158
121
|
* Convenience method that handles missing snapshot gracefully
|
|
159
122
|
* Finds the most recent snapshot file from migrations directory
|
|
160
|
-
* NOTE: This function only
|
|
161
|
-
* Use loadSnapshotWithMigrations()
|
|
123
|
+
* NOTE: This function only executes the snapshot file, not the migrations
|
|
124
|
+
* after it. Use loadSnapshotWithMigrations() for the current state.
|
|
162
125
|
*
|
|
163
126
|
* @param config - Snapshot configuration (must include migrationsPath)
|
|
164
127
|
* @returns SchemaSnapshot object or null if snapshot doesn't exist
|
|
@@ -184,7 +147,6 @@ declare function validateSnapshot(snapshot: SchemaSnapshot): {
|
|
|
184
147
|
valid: boolean;
|
|
185
148
|
issues: string[];
|
|
186
149
|
};
|
|
187
|
-
|
|
188
150
|
/**
|
|
189
151
|
* SnapshotManager class for object-oriented usage
|
|
190
152
|
* Provides a stateful interface for snapshot management
|
|
@@ -208,10 +170,6 @@ declare class SnapshotManager {
|
|
|
208
170
|
* Checks if a snapshot exists
|
|
209
171
|
*/
|
|
210
172
|
snapshotExists(): boolean;
|
|
211
|
-
/**
|
|
212
|
-
* Converts a PocketBase migration to a snapshot
|
|
213
|
-
*/
|
|
214
|
-
convertPocketBaseMigration(content: string): SchemaSnapshot;
|
|
215
173
|
/**
|
|
216
174
|
* Gets the snapshot file path
|
|
217
175
|
*/
|
|
@@ -225,4 +183,4 @@ declare class SnapshotManager {
|
|
|
225
183
|
};
|
|
226
184
|
}
|
|
227
185
|
|
|
228
|
-
export { type SnapshotConfig, SnapshotManager,
|
|
186
|
+
export { type SnapshotConfig, SnapshotManager, findLatestSnapshot, getSnapshotPath, getSnapshotVersion, loadBaseMigration, loadSnapshot, loadSnapshotIfExists, loadSnapshotWithMigrations, mergeSnapshots, saveSnapshot, snapshotExists, validateSnapshot };
|
|
@@ -1,49 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as EngineOptions, j as AppliedMigrationsSource } from '../types-B_MLb1Ob.js';
|
|
2
|
+
import { a as SchemaSnapshot, S as SchemaDefinition } from '../types-Do3jyFBm.js';
|
|
2
3
|
import '../fields-B96iGprI.js';
|
|
3
4
|
import 'zod';
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
-
* Migration File Parser
|
|
7
|
-
* Parses PocketBase migration files to extract collection operations
|
|
8
|
-
*
|
|
9
|
-
* This module handles parsing migration files to extract:
|
|
10
|
-
* - Collection creations (new Collection(...))
|
|
11
|
-
* - Collection deletions (app.delete(...))
|
|
12
|
-
* - Field modifications (field.property = value)
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
interface ParsedCollectionUpdate {
|
|
16
|
-
collectionName: string;
|
|
17
|
-
fieldsToAdd: FieldDefinition[];
|
|
18
|
-
fieldsToRemove: string[];
|
|
19
|
-
fieldsToUpdate: {
|
|
20
|
-
fieldName: string;
|
|
21
|
-
changes: Record<string, any>;
|
|
22
|
-
}[];
|
|
23
|
-
indexesToAdd: string[];
|
|
24
|
-
indexesToRemove: string[];
|
|
25
|
-
rulesToUpdate: Record<string, string | null>;
|
|
26
|
-
/** New SQL query for a view collection, when the migration updates one */
|
|
27
|
-
viewQuery?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* PocketBase Format Converter
|
|
32
|
-
* Converts PocketBase collection objects to our internal CollectionSchema format
|
|
33
|
-
*
|
|
34
|
-
* This module handles conversion between PocketBase's native collection format
|
|
35
|
-
* (as found in migration files and snapshots) and our internal schema representation.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Converts PocketBase migration format to SchemaSnapshot
|
|
40
|
-
* Extracts the snapshot array from the migration file content
|
|
41
|
-
*
|
|
42
|
-
* @param migrationContent - Raw migration file content
|
|
43
|
-
* @returns SchemaSnapshot with collections map
|
|
44
|
-
*/
|
|
45
|
-
declare function convertPocketBaseMigration(migrationContent: string): SchemaSnapshot;
|
|
46
|
-
|
|
47
6
|
/**
|
|
48
7
|
* Snapshot Manager
|
|
49
8
|
* Handles saving and loading schema snapshots from JSON files
|
|
@@ -81,6 +40,18 @@ interface SnapshotConfig {
|
|
|
81
40
|
* Custom snapshot version for testing
|
|
82
41
|
*/
|
|
83
42
|
version?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Options forwarded to the execution engine, which reconstructs state by
|
|
45
|
+
* executing migration files in a simulated PocketBase JSVM.
|
|
46
|
+
*/
|
|
47
|
+
engineOptions?: EngineOptions;
|
|
48
|
+
/**
|
|
49
|
+
* Migrations PocketBase has actually applied, read from its `_migrations`
|
|
50
|
+
* table (see `readAppliedMigrations`). When supplied, replay starts from
|
|
51
|
+
* the newest applied snapshot and stops at the applied set, so a migration
|
|
52
|
+
* written but not yet run does not leak into the reconstructed state.
|
|
53
|
+
*/
|
|
54
|
+
appliedMigrations?: AppliedMigrationsSource | string[] | null;
|
|
84
55
|
}
|
|
85
56
|
/**
|
|
86
57
|
* Gets the snapshot file path from configuration
|
|
@@ -133,32 +104,24 @@ declare function mergeSnapshots(baseSnapshot: SchemaSnapshot, customSnapshot: Sc
|
|
|
133
104
|
*/
|
|
134
105
|
declare function findLatestSnapshot(migrationsPath: string): string | null;
|
|
135
106
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
107
|
+
* Reconstructs the current database state: executes the snapshot migration and
|
|
108
|
+
* every migration after it in a simulated PocketBase JSVM.
|
|
138
109
|
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*/
|
|
143
|
-
declare function applyMigrationOperations(snapshot: SchemaSnapshot, operations: {
|
|
144
|
-
collectionsToCreate: CollectionSchema[];
|
|
145
|
-
collectionsToDelete: string[];
|
|
146
|
-
collectionsToUpdate: ParsedCollectionUpdate[];
|
|
147
|
-
}): SchemaSnapshot;
|
|
148
|
-
/**
|
|
149
|
-
* Loads snapshot and applies all migrations that come after it
|
|
150
|
-
* This gives us the current state of the database schema
|
|
110
|
+
* A migration that cannot be executed fails hard — continuing past it would
|
|
111
|
+
* silently reconstruct the wrong state and cause the generator to emit
|
|
112
|
+
* incorrect diffs.
|
|
151
113
|
*
|
|
152
114
|
* @param config - Snapshot configuration (must include migrationsPath)
|
|
153
|
-
* @returns SchemaSnapshot
|
|
115
|
+
* @returns SchemaSnapshot representing the current state, or null when there is
|
|
116
|
+
* nothing to replay (an empty database)
|
|
154
117
|
*/
|
|
155
118
|
declare function loadSnapshotWithMigrations(config?: SnapshotConfig): SchemaSnapshot | null;
|
|
156
119
|
/**
|
|
157
120
|
* Loads snapshot if it exists, returns null for first run
|
|
158
121
|
* Convenience method that handles missing snapshot gracefully
|
|
159
122
|
* Finds the most recent snapshot file from migrations directory
|
|
160
|
-
* NOTE: This function only
|
|
161
|
-
* Use loadSnapshotWithMigrations()
|
|
123
|
+
* NOTE: This function only executes the snapshot file, not the migrations
|
|
124
|
+
* after it. Use loadSnapshotWithMigrations() for the current state.
|
|
162
125
|
*
|
|
163
126
|
* @param config - Snapshot configuration (must include migrationsPath)
|
|
164
127
|
* @returns SchemaSnapshot object or null if snapshot doesn't exist
|
|
@@ -184,7 +147,6 @@ declare function validateSnapshot(snapshot: SchemaSnapshot): {
|
|
|
184
147
|
valid: boolean;
|
|
185
148
|
issues: string[];
|
|
186
149
|
};
|
|
187
|
-
|
|
188
150
|
/**
|
|
189
151
|
* SnapshotManager class for object-oriented usage
|
|
190
152
|
* Provides a stateful interface for snapshot management
|
|
@@ -208,10 +170,6 @@ declare class SnapshotManager {
|
|
|
208
170
|
* Checks if a snapshot exists
|
|
209
171
|
*/
|
|
210
172
|
snapshotExists(): boolean;
|
|
211
|
-
/**
|
|
212
|
-
* Converts a PocketBase migration to a snapshot
|
|
213
|
-
*/
|
|
214
|
-
convertPocketBaseMigration(content: string): SchemaSnapshot;
|
|
215
173
|
/**
|
|
216
174
|
* Gets the snapshot file path
|
|
217
175
|
*/
|
|
@@ -225,4 +183,4 @@ declare class SnapshotManager {
|
|
|
225
183
|
};
|
|
226
184
|
}
|
|
227
185
|
|
|
228
|
-
export { type SnapshotConfig, SnapshotManager,
|
|
186
|
+
export { type SnapshotConfig, SnapshotManager, findLatestSnapshot, getSnapshotPath, getSnapshotVersion, loadBaseMigration, loadSnapshot, loadSnapshotIfExists, loadSnapshotWithMigrations, mergeSnapshots, saveSnapshot, snapshotExists, validateSnapshot };
|