pocketbase-zod-schema 0.2.5 → 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 +8 -0
- package/dist/cli/index.cjs +374 -296
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +2 -2
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +374 -296
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +374 -296
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +374 -296
- package/dist/cli/migrate.js.map +1 -1
- package/dist/cli/utils/index.d.cts +2 -2
- package/dist/cli/utils/index.d.ts +2 -2
- package/dist/{fields-YjcpBXVp.d.cts → fields-UcOPu1OQ.d.cts} +16 -0
- package/dist/{fields-YjcpBXVp.d.ts → fields-UcOPu1OQ.d.ts} +16 -0
- package/dist/index.cjs +413 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +414 -103
- package/dist/index.js.map +1 -1
- package/dist/migration/analyzer.cjs +12 -2
- package/dist/migration/analyzer.cjs.map +1 -1
- package/dist/migration/analyzer.d.cts +2 -2
- package/dist/migration/analyzer.d.ts +2 -2
- package/dist/migration/analyzer.js +12 -2
- 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 +2 -2
- package/dist/migration/diff.d.ts +2 -2
- 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 +59 -12
- package/dist/migration/generator.d.ts +59 -12
- package/dist/migration/generator.js +319 -47
- package/dist/migration/generator.js.map +1 -1
- package/dist/migration/index.cjs +399 -49
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.d.cts +3 -3
- package/dist/migration/index.d.ts +3 -3
- package/dist/migration/index.js +399 -49
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/snapshot.cjs.map +1 -1
- package/dist/migration/snapshot.d.cts +2 -2
- package/dist/migration/snapshot.d.ts +2 -2
- package/dist/migration/snapshot.js.map +1 -1
- package/dist/migration/utils/index.cjs +64 -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 +63 -1
- package/dist/migration/utils/index.js.map +1 -1
- package/dist/schema.cjs +0 -61
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +2 -86
- package/dist/schema.d.ts +2 -86
- package/dist/schema.js +1 -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-LFBGHl9Y.d.ts → types-Ds3NQvny.d.ts} +33 -2
- package/dist/{types-mhQXWNi3.d.cts → types-YoBjsa-A.d.cts} +33 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as SchemaDiff, C as CollectionSchema, F as FieldDefinition, c as FieldModification } from '../types-
|
|
2
|
-
import '../fields-
|
|
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
3
|
import 'zod';
|
|
4
4
|
import '../permissions-ZHafVSIx.cjs';
|
|
5
5
|
|
|
@@ -53,6 +53,31 @@ interface MigrationGeneratorConfig {
|
|
|
53
53
|
* @returns Timestamp string
|
|
54
54
|
*/
|
|
55
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;
|
|
56
81
|
/**
|
|
57
82
|
* Generates a human-readable description from the diff
|
|
58
83
|
* Creates a concise summary of the main changes
|
|
@@ -94,16 +119,18 @@ declare function writeMigrationFile(migrationDir: string, filename: string, cont
|
|
|
94
119
|
* Creates the field configuration object used in Collection constructor
|
|
95
120
|
*
|
|
96
121
|
* @param field - Field definition
|
|
122
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
97
123
|
* @returns Field definition object as string
|
|
98
124
|
*/
|
|
99
|
-
declare function generateFieldDefinitionObject(field: FieldDefinition): string;
|
|
125
|
+
declare function generateFieldDefinitionObject(field: FieldDefinition, collectionIdMap?: Map<string, string>): string;
|
|
100
126
|
/**
|
|
101
127
|
* Generates fields array for collection creation
|
|
102
128
|
*
|
|
103
129
|
* @param fields - Array of field definitions
|
|
130
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
104
131
|
* @returns Fields array as string
|
|
105
132
|
*/
|
|
106
|
-
declare function generateFieldsArray(fields: FieldDefinition[]): string;
|
|
133
|
+
declare function generateFieldsArray(fields: FieldDefinition[], collectionIdMap?: Map<string, string>): string;
|
|
107
134
|
/**
|
|
108
135
|
* Generates collection rules object
|
|
109
136
|
*
|
|
@@ -126,7 +153,7 @@ declare function generateCollectionPermissions(permissions?: CollectionSchema["p
|
|
|
126
153
|
* @returns Indexes array as string
|
|
127
154
|
*/
|
|
128
155
|
declare function generateIndexesArray(indexes?: string[]): string;
|
|
129
|
-
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;
|
|
130
157
|
/**
|
|
131
158
|
* Generates code for adding a field to an existing collection
|
|
132
159
|
* Uses the appropriate Field constructor based on field type
|
|
@@ -135,9 +162,10 @@ declare function generateCollectionCreation(collection: CollectionSchema, varNam
|
|
|
135
162
|
* @param field - Field definition to add
|
|
136
163
|
* @param varName - Variable name to use for the collection (default: auto-generated)
|
|
137
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
|
|
138
166
|
* @returns JavaScript code for adding the field
|
|
139
167
|
*/
|
|
140
|
-
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;
|
|
141
169
|
/**
|
|
142
170
|
* Generates code for modifying an existing field
|
|
143
171
|
* Updates field properties based on detected changes
|
|
@@ -171,6 +199,24 @@ declare function generateFieldDeletion(collectionName: string, fieldName: string
|
|
|
171
199
|
* @returns JavaScript code for updating the permission
|
|
172
200
|
*/
|
|
173
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;
|
|
174
220
|
/**
|
|
175
221
|
* Generates the up migration function code
|
|
176
222
|
* Applies all changes from the diff in the correct order
|
|
@@ -189,13 +235,13 @@ declare function generateUpMigration(diff: SchemaDiff): string;
|
|
|
189
235
|
declare function generateDownMigration(diff: SchemaDiff): string;
|
|
190
236
|
/**
|
|
191
237
|
* Main generation function
|
|
192
|
-
* Generates
|
|
238
|
+
* Generates migration files from schema diff (one file per collection operation)
|
|
193
239
|
*
|
|
194
240
|
* @param diff - Schema diff containing all changes
|
|
195
241
|
* @param config - Migration generator configuration
|
|
196
|
-
* @returns
|
|
242
|
+
* @returns Array of paths to the generated migration files
|
|
197
243
|
*/
|
|
198
|
-
declare function generate(diff: SchemaDiff, config: MigrationGeneratorConfig | string): string;
|
|
244
|
+
declare function generate(diff: SchemaDiff, config: MigrationGeneratorConfig | string): string[];
|
|
199
245
|
/**
|
|
200
246
|
* MigrationGenerator class for object-oriented usage
|
|
201
247
|
* Provides a stateful interface for migration generation
|
|
@@ -204,9 +250,10 @@ declare class MigrationGenerator {
|
|
|
204
250
|
private config;
|
|
205
251
|
constructor(config: MigrationGeneratorConfig);
|
|
206
252
|
/**
|
|
207
|
-
* Generates
|
|
253
|
+
* Generates migration files from a schema diff
|
|
254
|
+
* Returns array of file paths (one per collection operation)
|
|
208
255
|
*/
|
|
209
|
-
generate(diff: SchemaDiff): string;
|
|
256
|
+
generate(diff: SchemaDiff): string[];
|
|
210
257
|
/**
|
|
211
258
|
* Generates the up migration code without writing to file
|
|
212
259
|
*/
|
|
@@ -221,4 +268,4 @@ declare class MigrationGenerator {
|
|
|
221
268
|
generateMigrationFilename(diff: SchemaDiff): string;
|
|
222
269
|
}
|
|
223
270
|
|
|
224
|
-
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,5 +1,5 @@
|
|
|
1
|
-
import { e as SchemaDiff, C as CollectionSchema, F as FieldDefinition, c as FieldModification } from '../types-
|
|
2
|
-
import '../fields-
|
|
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
3
|
import 'zod';
|
|
4
4
|
import '../permissions-ZHafVSIx.js';
|
|
5
5
|
|
|
@@ -53,6 +53,31 @@ interface MigrationGeneratorConfig {
|
|
|
53
53
|
* @returns Timestamp string
|
|
54
54
|
*/
|
|
55
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;
|
|
56
81
|
/**
|
|
57
82
|
* Generates a human-readable description from the diff
|
|
58
83
|
* Creates a concise summary of the main changes
|
|
@@ -94,16 +119,18 @@ declare function writeMigrationFile(migrationDir: string, filename: string, cont
|
|
|
94
119
|
* Creates the field configuration object used in Collection constructor
|
|
95
120
|
*
|
|
96
121
|
* @param field - Field definition
|
|
122
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
97
123
|
* @returns Field definition object as string
|
|
98
124
|
*/
|
|
99
|
-
declare function generateFieldDefinitionObject(field: FieldDefinition): string;
|
|
125
|
+
declare function generateFieldDefinitionObject(field: FieldDefinition, collectionIdMap?: Map<string, string>): string;
|
|
100
126
|
/**
|
|
101
127
|
* Generates fields array for collection creation
|
|
102
128
|
*
|
|
103
129
|
* @param fields - Array of field definitions
|
|
130
|
+
* @param collectionIdMap - Map of collection names to their pre-generated IDs
|
|
104
131
|
* @returns Fields array as string
|
|
105
132
|
*/
|
|
106
|
-
declare function generateFieldsArray(fields: FieldDefinition[]): string;
|
|
133
|
+
declare function generateFieldsArray(fields: FieldDefinition[], collectionIdMap?: Map<string, string>): string;
|
|
107
134
|
/**
|
|
108
135
|
* Generates collection rules object
|
|
109
136
|
*
|
|
@@ -126,7 +153,7 @@ declare function generateCollectionPermissions(permissions?: CollectionSchema["p
|
|
|
126
153
|
* @returns Indexes array as string
|
|
127
154
|
*/
|
|
128
155
|
declare function generateIndexesArray(indexes?: string[]): string;
|
|
129
|
-
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;
|
|
130
157
|
/**
|
|
131
158
|
* Generates code for adding a field to an existing collection
|
|
132
159
|
* Uses the appropriate Field constructor based on field type
|
|
@@ -135,9 +162,10 @@ declare function generateCollectionCreation(collection: CollectionSchema, varNam
|
|
|
135
162
|
* @param field - Field definition to add
|
|
136
163
|
* @param varName - Variable name to use for the collection (default: auto-generated)
|
|
137
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
|
|
138
166
|
* @returns JavaScript code for adding the field
|
|
139
167
|
*/
|
|
140
|
-
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;
|
|
141
169
|
/**
|
|
142
170
|
* Generates code for modifying an existing field
|
|
143
171
|
* Updates field properties based on detected changes
|
|
@@ -171,6 +199,24 @@ declare function generateFieldDeletion(collectionName: string, fieldName: string
|
|
|
171
199
|
* @returns JavaScript code for updating the permission
|
|
172
200
|
*/
|
|
173
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;
|
|
174
220
|
/**
|
|
175
221
|
* Generates the up migration function code
|
|
176
222
|
* Applies all changes from the diff in the correct order
|
|
@@ -189,13 +235,13 @@ declare function generateUpMigration(diff: SchemaDiff): string;
|
|
|
189
235
|
declare function generateDownMigration(diff: SchemaDiff): string;
|
|
190
236
|
/**
|
|
191
237
|
* Main generation function
|
|
192
|
-
* Generates
|
|
238
|
+
* Generates migration files from schema diff (one file per collection operation)
|
|
193
239
|
*
|
|
194
240
|
* @param diff - Schema diff containing all changes
|
|
195
241
|
* @param config - Migration generator configuration
|
|
196
|
-
* @returns
|
|
242
|
+
* @returns Array of paths to the generated migration files
|
|
197
243
|
*/
|
|
198
|
-
declare function generate(diff: SchemaDiff, config: MigrationGeneratorConfig | string): string;
|
|
244
|
+
declare function generate(diff: SchemaDiff, config: MigrationGeneratorConfig | string): string[];
|
|
199
245
|
/**
|
|
200
246
|
* MigrationGenerator class for object-oriented usage
|
|
201
247
|
* Provides a stateful interface for migration generation
|
|
@@ -204,9 +250,10 @@ declare class MigrationGenerator {
|
|
|
204
250
|
private config;
|
|
205
251
|
constructor(config: MigrationGeneratorConfig);
|
|
206
252
|
/**
|
|
207
|
-
* Generates
|
|
253
|
+
* Generates migration files from a schema diff
|
|
254
|
+
* Returns array of file paths (one per collection operation)
|
|
208
255
|
*/
|
|
209
|
-
generate(diff: SchemaDiff): string;
|
|
256
|
+
generate(diff: SchemaDiff): string[];
|
|
210
257
|
/**
|
|
211
258
|
* Generates the up migration code without writing to file
|
|
212
259
|
*/
|
|
@@ -221,4 +268,4 @@ declare class MigrationGenerator {
|
|
|
221
268
|
generateMigrationFilename(diff: SchemaDiff): string;
|
|
222
269
|
}
|
|
223
270
|
|
|
224
|
-
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 };
|