pocketbase-zod-schema 0.2.4 → 0.3.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 +15 -0
- package/README.md +209 -24
- package/dist/cli/index.cjs +406 -294
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +3 -1
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +406 -294
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +406 -294
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +406 -294
- package/dist/cli/migrate.js.map +1 -1
- package/dist/cli/utils/index.d.cts +3 -1
- package/dist/cli/utils/index.d.ts +3 -1
- package/dist/fields-UcOPu1OQ.d.cts +364 -0
- package/dist/fields-UcOPu1OQ.d.ts +364 -0
- package/dist/index.cjs +633 -112
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +619 -101
- package/dist/index.js.map +1 -1
- package/dist/migration/analyzer.cjs +44 -0
- package/dist/migration/analyzer.cjs.map +1 -1
- package/dist/migration/analyzer.d.cts +2 -1
- package/dist/migration/analyzer.d.ts +2 -1
- package/dist/migration/analyzer.js +44 -0
- package/dist/migration/analyzer.js.map +1 -1
- package/dist/migration/diff.cjs +76 -1
- package/dist/migration/diff.cjs.map +1 -1
- package/dist/migration/diff.d.cts +3 -1
- package/dist/migration/diff.d.ts +3 -1
- package/dist/migration/diff.js +76 -1
- package/dist/migration/diff.js.map +1 -1
- package/dist/migration/generator.cjs +323 -46
- package/dist/migration/generator.cjs.map +1 -1
- package/dist/migration/generator.d.cts +60 -11
- package/dist/migration/generator.d.ts +60 -11
- package/dist/migration/generator.js +319 -47
- package/dist/migration/generator.js.map +1 -1
- package/dist/migration/index.cjs +433 -47
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.d.cts +3 -2
- package/dist/migration/index.d.ts +3 -2
- package/dist/migration/index.js +432 -48
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/snapshot.cjs.map +1 -1
- package/dist/migration/snapshot.d.cts +3 -1
- package/dist/migration/snapshot.d.ts +3 -1
- package/dist/migration/snapshot.js.map +1 -1
- package/dist/migration/utils/index.cjs +80 -0
- package/dist/migration/utils/index.cjs.map +1 -1
- package/dist/migration/utils/index.d.cts +39 -202
- package/dist/migration/utils/index.d.ts +39 -202
- package/dist/migration/utils/index.js +77 -1
- package/dist/migration/utils/index.js.map +1 -1
- package/dist/schema.cjs +200 -61
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +2 -85
- package/dist/schema.d.ts +2 -85
- package/dist/schema.js +186 -50
- package/dist/schema.js.map +1 -1
- package/dist/type-mapper-DrQmtznD.d.cts +208 -0
- package/dist/type-mapper-n231Fspm.d.ts +208 -0
- package/dist/{types-z1Dkjg8m.d.ts → types-Ds3NQvny.d.ts} +33 -2
- package/dist/{types-BbTgmg6H.d.cts → types-YoBjsa-A.d.cts} +33 -2
- package/package.json +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { e as SchemaDiff, C as CollectionSchema, F as FieldDefinition, c as FieldModification, f as CollectionOperation } from '../types-YoBjsa-A.cjs';
|
|
2
|
+
import '../fields-UcOPu1OQ.cjs';
|
|
3
|
+
import 'zod';
|
|
2
4
|
import '../permissions-ZHafVSIx.cjs';
|
|
3
5
|
|
|
4
6
|
/**
|
|
@@ -51,6 +53,31 @@ interface MigrationGeneratorConfig {
|
|
|
51
53
|
* @returns Timestamp string
|
|
52
54
|
*/
|
|
53
55
|
declare function generateTimestamp(config?: MigrationGeneratorConfig): string;
|
|
56
|
+
/**
|
|
57
|
+
* Splits a SchemaDiff into individual collection operations
|
|
58
|
+
* Each operation will generate a separate migration file
|
|
59
|
+
*
|
|
60
|
+
* @param diff - Schema diff containing all changes
|
|
61
|
+
* @param baseTimestamp - Base timestamp for the first operation
|
|
62
|
+
* @returns Array of collection operations
|
|
63
|
+
*/
|
|
64
|
+
declare function splitDiffByCollection(diff: SchemaDiff, baseTimestamp: string): CollectionOperation[];
|
|
65
|
+
/**
|
|
66
|
+
* Generates migration filename for a collection operation
|
|
67
|
+
* Format: {timestamp}_{operation}_{collection_name}.js
|
|
68
|
+
*
|
|
69
|
+
* @param operation - Collection operation
|
|
70
|
+
* @returns Migration filename
|
|
71
|
+
*/
|
|
72
|
+
declare function generateCollectionMigrationFilename(operation: CollectionOperation): string;
|
|
73
|
+
/**
|
|
74
|
+
* Increments a timestamp by 1 second
|
|
75
|
+
* Ensures sequential ordering of migration files
|
|
76
|
+
*
|
|
77
|
+
* @param timestamp - Current timestamp string
|
|
78
|
+
* @returns Incremented timestamp string
|
|
79
|
+
*/
|
|
80
|
+
declare function incrementTimestamp(timestamp: string): string;
|
|
54
81
|
/**
|
|
55
82
|
* Generates a human-readable description from the diff
|
|
56
83
|
* Creates a concise summary of the main changes
|
|
@@ -92,16 +119,18 @@ declare function writeMigrationFile(migrationDir: string, filename: string, cont
|
|
|
92
119
|
* Creates the field configuration object used in Collection constructor
|
|
93
120
|
*
|
|
94
121
|
* @param field - Field definition
|
|
122
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
95
123
|
* @returns Field definition object as string
|
|
96
124
|
*/
|
|
97
|
-
declare function generateFieldDefinitionObject(field: FieldDefinition): string;
|
|
125
|
+
declare function generateFieldDefinitionObject(field: FieldDefinition, collectionIdMap?: Map<string, string>): string;
|
|
98
126
|
/**
|
|
99
127
|
* Generates fields array for collection creation
|
|
100
128
|
*
|
|
101
129
|
* @param fields - Array of field definitions
|
|
130
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
102
131
|
* @returns Fields array as string
|
|
103
132
|
*/
|
|
104
|
-
declare function generateFieldsArray(fields: FieldDefinition[]): string;
|
|
133
|
+
declare function generateFieldsArray(fields: FieldDefinition[], collectionIdMap?: Map<string, string>): string;
|
|
105
134
|
/**
|
|
106
135
|
* Generates collection rules object
|
|
107
136
|
*
|
|
@@ -124,7 +153,7 @@ declare function generateCollectionPermissions(permissions?: CollectionSchema["p
|
|
|
124
153
|
* @returns Indexes array as string
|
|
125
154
|
*/
|
|
126
155
|
declare function generateIndexesArray(indexes?: string[]): string;
|
|
127
|
-
declare function generateCollectionCreation(collection: CollectionSchema, varName?: string, isLast?: boolean): string;
|
|
156
|
+
declare function generateCollectionCreation(collection: CollectionSchema, varName?: string, isLast?: boolean, collectionIdMap?: Map<string, string>): string;
|
|
128
157
|
/**
|
|
129
158
|
* Generates code for adding a field to an existing collection
|
|
130
159
|
* Uses the appropriate Field constructor based on field type
|
|
@@ -133,9 +162,10 @@ declare function generateCollectionCreation(collection: CollectionSchema, varNam
|
|
|
133
162
|
* @param field - Field definition to add
|
|
134
163
|
* @param varName - Variable name to use for the collection (default: auto-generated)
|
|
135
164
|
* @param isLast - Whether this is the last operation (will return the result)
|
|
165
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
136
166
|
* @returns JavaScript code for adding the field
|
|
137
167
|
*/
|
|
138
|
-
declare function generateFieldAddition(collectionName: string, field: FieldDefinition, varName?: string, isLast?: boolean): string;
|
|
168
|
+
declare function generateFieldAddition(collectionName: string, field: FieldDefinition, varName?: string, isLast?: boolean, collectionIdMap?: Map<string, string>): string;
|
|
139
169
|
/**
|
|
140
170
|
* Generates code for modifying an existing field
|
|
141
171
|
* Updates field properties based on detected changes
|
|
@@ -169,6 +199,24 @@ declare function generateFieldDeletion(collectionName: string, fieldName: string
|
|
|
169
199
|
* @returns JavaScript code for updating the permission
|
|
170
200
|
*/
|
|
171
201
|
declare function generatePermissionUpdate(collectionName: string, ruleType: string, newValue: string | null, varName?: string, isLast?: boolean): string;
|
|
202
|
+
/**
|
|
203
|
+
* Generates the up migration code for a single collection operation
|
|
204
|
+
* Handles create, modify, and delete operations
|
|
205
|
+
*
|
|
206
|
+
* @param operation - Collection operation to generate migration for
|
|
207
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
208
|
+
* @returns JavaScript code for up migration
|
|
209
|
+
*/
|
|
210
|
+
declare function generateOperationUpMigration(operation: CollectionOperation, collectionIdMap: Map<string, string>): string;
|
|
211
|
+
/**
|
|
212
|
+
* Generates the down migration code for a single collection operation
|
|
213
|
+
* Reverts the operation (inverse of up migration)
|
|
214
|
+
*
|
|
215
|
+
* @param operation - Collection operation to generate rollback for
|
|
216
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
217
|
+
* @returns JavaScript code for down migration
|
|
218
|
+
*/
|
|
219
|
+
declare function generateOperationDownMigration(operation: CollectionOperation, collectionIdMap: Map<string, string>): string;
|
|
172
220
|
/**
|
|
173
221
|
* Generates the up migration function code
|
|
174
222
|
* Applies all changes from the diff in the correct order
|
|
@@ -187,13 +235,13 @@ declare function generateUpMigration(diff: SchemaDiff): string;
|
|
|
187
235
|
declare function generateDownMigration(diff: SchemaDiff): string;
|
|
188
236
|
/**
|
|
189
237
|
* Main generation function
|
|
190
|
-
* Generates
|
|
238
|
+
* Generates migration files from schema diff (one file per collection operation)
|
|
191
239
|
*
|
|
192
240
|
* @param diff - Schema diff containing all changes
|
|
193
241
|
* @param config - Migration generator configuration
|
|
194
|
-
* @returns
|
|
242
|
+
* @returns Array of paths to the generated migration files
|
|
195
243
|
*/
|
|
196
|
-
declare function generate(diff: SchemaDiff, config: MigrationGeneratorConfig | string): string;
|
|
244
|
+
declare function generate(diff: SchemaDiff, config: MigrationGeneratorConfig | string): string[];
|
|
197
245
|
/**
|
|
198
246
|
* MigrationGenerator class for object-oriented usage
|
|
199
247
|
* Provides a stateful interface for migration generation
|
|
@@ -202,9 +250,10 @@ declare class MigrationGenerator {
|
|
|
202
250
|
private config;
|
|
203
251
|
constructor(config: MigrationGeneratorConfig);
|
|
204
252
|
/**
|
|
205
|
-
* Generates
|
|
253
|
+
* Generates migration files from a schema diff
|
|
254
|
+
* Returns array of file paths (one per collection operation)
|
|
206
255
|
*/
|
|
207
|
-
generate(diff: SchemaDiff): string;
|
|
256
|
+
generate(diff: SchemaDiff): string[];
|
|
208
257
|
/**
|
|
209
258
|
* Generates the up migration code without writing to file
|
|
210
259
|
*/
|
|
@@ -219,4 +268,4 @@ declare class MigrationGenerator {
|
|
|
219
268
|
generateMigrationFilename(diff: SchemaDiff): string;
|
|
220
269
|
}
|
|
221
270
|
|
|
222
|
-
export { MigrationGenerator, type MigrationGeneratorConfig, createMigrationFileStructure, generate, generateCollectionCreation, generateCollectionPermissions, generateCollectionRules, generateDownMigration, generateFieldAddition, generateFieldDefinitionObject, generateFieldDeletion, generateFieldModification, generateFieldsArray, generateIndexesArray, generateMigrationDescription, generateMigrationFilename, generatePermissionUpdate, generateTimestamp, generateUpMigration, writeMigrationFile };
|
|
271
|
+
export { MigrationGenerator, type MigrationGeneratorConfig, createMigrationFileStructure, generate, generateCollectionCreation, generateCollectionMigrationFilename, generateCollectionPermissions, generateCollectionRules, generateDownMigration, generateFieldAddition, generateFieldDefinitionObject, generateFieldDeletion, generateFieldModification, generateFieldsArray, generateIndexesArray, generateMigrationDescription, generateMigrationFilename, generateOperationDownMigration, generateOperationUpMigration, generatePermissionUpdate, generateTimestamp, generateUpMigration, incrementTimestamp, splitDiffByCollection, writeMigrationFile };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { e as SchemaDiff, C as CollectionSchema, F as FieldDefinition, c as FieldModification, f as CollectionOperation } from '../types-Ds3NQvny.js';
|
|
2
|
+
import '../fields-UcOPu1OQ.js';
|
|
3
|
+
import 'zod';
|
|
2
4
|
import '../permissions-ZHafVSIx.js';
|
|
3
5
|
|
|
4
6
|
/**
|
|
@@ -51,6 +53,31 @@ interface MigrationGeneratorConfig {
|
|
|
51
53
|
* @returns Timestamp string
|
|
52
54
|
*/
|
|
53
55
|
declare function generateTimestamp(config?: MigrationGeneratorConfig): string;
|
|
56
|
+
/**
|
|
57
|
+
* Splits a SchemaDiff into individual collection operations
|
|
58
|
+
* Each operation will generate a separate migration file
|
|
59
|
+
*
|
|
60
|
+
* @param diff - Schema diff containing all changes
|
|
61
|
+
* @param baseTimestamp - Base timestamp for the first operation
|
|
62
|
+
* @returns Array of collection operations
|
|
63
|
+
*/
|
|
64
|
+
declare function splitDiffByCollection(diff: SchemaDiff, baseTimestamp: string): CollectionOperation[];
|
|
65
|
+
/**
|
|
66
|
+
* Generates migration filename for a collection operation
|
|
67
|
+
* Format: {timestamp}_{operation}_{collection_name}.js
|
|
68
|
+
*
|
|
69
|
+
* @param operation - Collection operation
|
|
70
|
+
* @returns Migration filename
|
|
71
|
+
*/
|
|
72
|
+
declare function generateCollectionMigrationFilename(operation: CollectionOperation): string;
|
|
73
|
+
/**
|
|
74
|
+
* Increments a timestamp by 1 second
|
|
75
|
+
* Ensures sequential ordering of migration files
|
|
76
|
+
*
|
|
77
|
+
* @param timestamp - Current timestamp string
|
|
78
|
+
* @returns Incremented timestamp string
|
|
79
|
+
*/
|
|
80
|
+
declare function incrementTimestamp(timestamp: string): string;
|
|
54
81
|
/**
|
|
55
82
|
* Generates a human-readable description from the diff
|
|
56
83
|
* Creates a concise summary of the main changes
|
|
@@ -92,16 +119,18 @@ declare function writeMigrationFile(migrationDir: string, filename: string, cont
|
|
|
92
119
|
* Creates the field configuration object used in Collection constructor
|
|
93
120
|
*
|
|
94
121
|
* @param field - Field definition
|
|
122
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
95
123
|
* @returns Field definition object as string
|
|
96
124
|
*/
|
|
97
|
-
declare function generateFieldDefinitionObject(field: FieldDefinition): string;
|
|
125
|
+
declare function generateFieldDefinitionObject(field: FieldDefinition, collectionIdMap?: Map<string, string>): string;
|
|
98
126
|
/**
|
|
99
127
|
* Generates fields array for collection creation
|
|
100
128
|
*
|
|
101
129
|
* @param fields - Array of field definitions
|
|
130
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
102
131
|
* @returns Fields array as string
|
|
103
132
|
*/
|
|
104
|
-
declare function generateFieldsArray(fields: FieldDefinition[]): string;
|
|
133
|
+
declare function generateFieldsArray(fields: FieldDefinition[], collectionIdMap?: Map<string, string>): string;
|
|
105
134
|
/**
|
|
106
135
|
* Generates collection rules object
|
|
107
136
|
*
|
|
@@ -124,7 +153,7 @@ declare function generateCollectionPermissions(permissions?: CollectionSchema["p
|
|
|
124
153
|
* @returns Indexes array as string
|
|
125
154
|
*/
|
|
126
155
|
declare function generateIndexesArray(indexes?: string[]): string;
|
|
127
|
-
declare function generateCollectionCreation(collection: CollectionSchema, varName?: string, isLast?: boolean): string;
|
|
156
|
+
declare function generateCollectionCreation(collection: CollectionSchema, varName?: string, isLast?: boolean, collectionIdMap?: Map<string, string>): string;
|
|
128
157
|
/**
|
|
129
158
|
* Generates code for adding a field to an existing collection
|
|
130
159
|
* Uses the appropriate Field constructor based on field type
|
|
@@ -133,9 +162,10 @@ declare function generateCollectionCreation(collection: CollectionSchema, varNam
|
|
|
133
162
|
* @param field - Field definition to add
|
|
134
163
|
* @param varName - Variable name to use for the collection (default: auto-generated)
|
|
135
164
|
* @param isLast - Whether this is the last operation (will return the result)
|
|
165
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
136
166
|
* @returns JavaScript code for adding the field
|
|
137
167
|
*/
|
|
138
|
-
declare function generateFieldAddition(collectionName: string, field: FieldDefinition, varName?: string, isLast?: boolean): string;
|
|
168
|
+
declare function generateFieldAddition(collectionName: string, field: FieldDefinition, varName?: string, isLast?: boolean, collectionIdMap?: Map<string, string>): string;
|
|
139
169
|
/**
|
|
140
170
|
* Generates code for modifying an existing field
|
|
141
171
|
* Updates field properties based on detected changes
|
|
@@ -169,6 +199,24 @@ declare function generateFieldDeletion(collectionName: string, fieldName: string
|
|
|
169
199
|
* @returns JavaScript code for updating the permission
|
|
170
200
|
*/
|
|
171
201
|
declare function generatePermissionUpdate(collectionName: string, ruleType: string, newValue: string | null, varName?: string, isLast?: boolean): string;
|
|
202
|
+
/**
|
|
203
|
+
* Generates the up migration code for a single collection operation
|
|
204
|
+
* Handles create, modify, and delete operations
|
|
205
|
+
*
|
|
206
|
+
* @param operation - Collection operation to generate migration for
|
|
207
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
208
|
+
* @returns JavaScript code for up migration
|
|
209
|
+
*/
|
|
210
|
+
declare function generateOperationUpMigration(operation: CollectionOperation, collectionIdMap: Map<string, string>): string;
|
|
211
|
+
/**
|
|
212
|
+
* Generates the down migration code for a single collection operation
|
|
213
|
+
* Reverts the operation (inverse of up migration)
|
|
214
|
+
*
|
|
215
|
+
* @param operation - Collection operation to generate rollback for
|
|
216
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
217
|
+
* @returns JavaScript code for down migration
|
|
218
|
+
*/
|
|
219
|
+
declare function generateOperationDownMigration(operation: CollectionOperation, collectionIdMap: Map<string, string>): string;
|
|
172
220
|
/**
|
|
173
221
|
* Generates the up migration function code
|
|
174
222
|
* Applies all changes from the diff in the correct order
|
|
@@ -187,13 +235,13 @@ declare function generateUpMigration(diff: SchemaDiff): string;
|
|
|
187
235
|
declare function generateDownMigration(diff: SchemaDiff): string;
|
|
188
236
|
/**
|
|
189
237
|
* Main generation function
|
|
190
|
-
* Generates
|
|
238
|
+
* Generates migration files from schema diff (one file per collection operation)
|
|
191
239
|
*
|
|
192
240
|
* @param diff - Schema diff containing all changes
|
|
193
241
|
* @param config - Migration generator configuration
|
|
194
|
-
* @returns
|
|
242
|
+
* @returns Array of paths to the generated migration files
|
|
195
243
|
*/
|
|
196
|
-
declare function generate(diff: SchemaDiff, config: MigrationGeneratorConfig | string): string;
|
|
244
|
+
declare function generate(diff: SchemaDiff, config: MigrationGeneratorConfig | string): string[];
|
|
197
245
|
/**
|
|
198
246
|
* MigrationGenerator class for object-oriented usage
|
|
199
247
|
* Provides a stateful interface for migration generation
|
|
@@ -202,9 +250,10 @@ declare class MigrationGenerator {
|
|
|
202
250
|
private config;
|
|
203
251
|
constructor(config: MigrationGeneratorConfig);
|
|
204
252
|
/**
|
|
205
|
-
* Generates
|
|
253
|
+
* Generates migration files from a schema diff
|
|
254
|
+
* Returns array of file paths (one per collection operation)
|
|
206
255
|
*/
|
|
207
|
-
generate(diff: SchemaDiff): string;
|
|
256
|
+
generate(diff: SchemaDiff): string[];
|
|
208
257
|
/**
|
|
209
258
|
* Generates the up migration code without writing to file
|
|
210
259
|
*/
|
|
@@ -219,4 +268,4 @@ declare class MigrationGenerator {
|
|
|
219
268
|
generateMigrationFilename(diff: SchemaDiff): string;
|
|
220
269
|
}
|
|
221
270
|
|
|
222
|
-
export { MigrationGenerator, type MigrationGeneratorConfig, createMigrationFileStructure, generate, generateCollectionCreation, generateCollectionPermissions, generateCollectionRules, generateDownMigration, generateFieldAddition, generateFieldDefinitionObject, generateFieldDeletion, generateFieldModification, generateFieldsArray, generateIndexesArray, generateMigrationDescription, generateMigrationFilename, generatePermissionUpdate, generateTimestamp, generateUpMigration, writeMigrationFile };
|
|
271
|
+
export { MigrationGenerator, type MigrationGeneratorConfig, createMigrationFileStructure, generate, generateCollectionCreation, generateCollectionMigrationFilename, generateCollectionPermissions, generateCollectionRules, generateDownMigration, generateFieldAddition, generateFieldDefinitionObject, generateFieldDeletion, generateFieldModification, generateFieldsArray, generateIndexesArray, generateMigrationDescription, generateMigrationFilename, generateOperationDownMigration, generateOperationUpMigration, generatePermissionUpdate, generateTimestamp, generateUpMigration, incrementTimestamp, splitDiffByCollection, writeMigrationFile };
|