pocketbase-zod-schema 0.6.1 → 0.7.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 +14 -0
- package/dist/cli/index.cjs +91 -2
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +2 -1
- package/dist/cli/index.d.ts +2 -1
- package/dist/cli/index.js +91 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +130 -11
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +131 -12
- package/dist/cli/migrate.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/migration/diff.cjs +76 -0
- package/dist/migration/diff.cjs.map +1 -1
- package/dist/migration/diff.d.cts +7 -1
- package/dist/migration/diff.d.ts +7 -1
- package/dist/migration/diff.js +76 -1
- package/dist/migration/diff.js.map +1 -1
- package/dist/migration/index.cjs +76 -0
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.d.cts +1 -1
- package/dist/migration/index.d.ts +1 -1
- package/dist/migration/index.js +76 -1
- package/dist/migration/index.js.map +1 -1
- package/dist/mutator.cjs.map +1 -1
- package/dist/mutator.d.cts +10 -10
- package/dist/mutator.d.ts +10 -10
- package/dist/mutator.js.map +1 -1
- package/dist/server.cjs +92 -2
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +92 -3
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.7.0](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.6.1...pocketbase-zod-schema-v0.7.0) (2026-02-13)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* Add migration filtering and skip destructive changes without force ([8b6f4f1](https://github.com/dastron/pocketbase-zod-schema/commit/8b6f4f1e918c40052ec15390b7c5c4df87e8a871))
|
|
9
|
+
* Add migration filtering and skip destructive changes without force ([1a8ea15](https://github.com/dastron/pocketbase-zod-schema/commit/1a8ea15489957ec2407af8b57316f703eb40db57))
|
|
10
|
+
* enhance codegen with complex types and strict mutators ([4086561](https://github.com/dastron/pocketbase-zod-schema/commit/4086561aa4ae8f132e965ff7672a581644eaa364))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* remove idOrName:string from typegen ([423dcbb](https://github.com/dastron/pocketbase-zod-schema/commit/423dcbb1a584f9bf3722c797297cc9450ba45325))
|
|
16
|
+
|
|
3
17
|
## [0.6.1](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.6.0...pocketbase-zod-schema-v0.6.1) (2026-01-26)
|
|
4
18
|
|
|
5
19
|
|
package/dist/cli/index.cjs
CHANGED
|
@@ -2933,6 +2933,81 @@ function categorizeChangesBySeverity(diff, _config) {
|
|
|
2933
2933
|
return { destructive, nonDestructive };
|
|
2934
2934
|
}
|
|
2935
2935
|
|
|
2936
|
+
// src/migration/diff/filter.ts
|
|
2937
|
+
function matchesPattern(text, patterns) {
|
|
2938
|
+
if (!patterns || patterns.length === 0) return true;
|
|
2939
|
+
return patterns.some((pattern) => {
|
|
2940
|
+
try {
|
|
2941
|
+
const regex = new RegExp(pattern);
|
|
2942
|
+
return regex.test(text);
|
|
2943
|
+
} catch {
|
|
2944
|
+
return text.includes(pattern);
|
|
2945
|
+
}
|
|
2946
|
+
});
|
|
2947
|
+
}
|
|
2948
|
+
function isDestructiveFieldModification(mod) {
|
|
2949
|
+
const typeChange = mod.changes.find((c) => c.property === "type");
|
|
2950
|
+
const requiredChange = mod.changes.find((c) => c.property === "required" && c.newValue === true);
|
|
2951
|
+
return !!(typeChange || requiredChange);
|
|
2952
|
+
}
|
|
2953
|
+
function filterDiff(diff, options) {
|
|
2954
|
+
const { patterns = [], skipDestructive = false } = options;
|
|
2955
|
+
const collectionsToCreate = diff.collectionsToCreate.filter((col) => {
|
|
2956
|
+
return matchesPattern(col.name, patterns);
|
|
2957
|
+
});
|
|
2958
|
+
let collectionsToDelete = diff.collectionsToDelete;
|
|
2959
|
+
if (skipDestructive) {
|
|
2960
|
+
collectionsToDelete = [];
|
|
2961
|
+
} else {
|
|
2962
|
+
collectionsToDelete = collectionsToDelete.filter((col) => {
|
|
2963
|
+
return matchesPattern(col.name, patterns);
|
|
2964
|
+
});
|
|
2965
|
+
}
|
|
2966
|
+
const collectionsToModify = diff.collectionsToModify.map((mod) => {
|
|
2967
|
+
const collectionMatches = matchesPattern(mod.collection, patterns);
|
|
2968
|
+
const fieldsToAdd = mod.fieldsToAdd.filter((field) => {
|
|
2969
|
+
return collectionMatches || matchesPattern(`${mod.collection}.${field.name}`, patterns);
|
|
2970
|
+
});
|
|
2971
|
+
let fieldsToRemove = mod.fieldsToRemove;
|
|
2972
|
+
if (skipDestructive) {
|
|
2973
|
+
fieldsToRemove = [];
|
|
2974
|
+
} else {
|
|
2975
|
+
fieldsToRemove = fieldsToRemove.filter((field) => {
|
|
2976
|
+
return collectionMatches || matchesPattern(`${mod.collection}.${field.name}`, patterns);
|
|
2977
|
+
});
|
|
2978
|
+
}
|
|
2979
|
+
let fieldsToModify = mod.fieldsToModify;
|
|
2980
|
+
if (skipDestructive) {
|
|
2981
|
+
fieldsToModify = fieldsToModify.filter((f) => !isDestructiveFieldModification(f));
|
|
2982
|
+
}
|
|
2983
|
+
fieldsToModify = fieldsToModify.filter((f) => {
|
|
2984
|
+
return collectionMatches || matchesPattern(`${mod.collection}.${f.fieldName}`, patterns);
|
|
2985
|
+
});
|
|
2986
|
+
const indexesToAdd = collectionMatches ? mod.indexesToAdd : [];
|
|
2987
|
+
const indexesToRemove = collectionMatches ? mod.indexesToRemove : [];
|
|
2988
|
+
const rulesToUpdate = collectionMatches ? mod.rulesToUpdate : [];
|
|
2989
|
+
const permissionsToUpdate = collectionMatches ? mod.permissionsToUpdate : [];
|
|
2990
|
+
return {
|
|
2991
|
+
...mod,
|
|
2992
|
+
fieldsToAdd,
|
|
2993
|
+
fieldsToRemove,
|
|
2994
|
+
fieldsToModify,
|
|
2995
|
+
indexesToAdd,
|
|
2996
|
+
indexesToRemove,
|
|
2997
|
+
rulesToUpdate,
|
|
2998
|
+
permissionsToUpdate
|
|
2999
|
+
};
|
|
3000
|
+
}).filter((mod) => {
|
|
3001
|
+
return mod.fieldsToAdd.length > 0 || mod.fieldsToRemove.length > 0 || mod.fieldsToModify.length > 0 || mod.indexesToAdd.length > 0 || mod.indexesToRemove.length > 0 || mod.rulesToUpdate.length > 0 || mod.permissionsToUpdate.length > 0;
|
|
3002
|
+
});
|
|
3003
|
+
return {
|
|
3004
|
+
...diff,
|
|
3005
|
+
collectionsToCreate,
|
|
3006
|
+
collectionsToDelete,
|
|
3007
|
+
collectionsToModify
|
|
3008
|
+
};
|
|
3009
|
+
}
|
|
3010
|
+
|
|
2936
3011
|
// src/migration/diff/index.ts
|
|
2937
3012
|
function hasChanges(modification) {
|
|
2938
3013
|
return modification.fieldsToAdd.length > 0 || modification.fieldsToRemove.length > 0 || modification.fieldsToModify.length > 0 || modification.indexesToAdd.length > 0 || modification.indexesToRemove.length > 0 || modification.rulesToUpdate.length > 0 || modification.permissionsToUpdate.length > 0;
|
|
@@ -4521,7 +4596,7 @@ function handleDestructiveChanges(diff, config, force) {
|
|
|
4521
4596
|
}
|
|
4522
4597
|
return true;
|
|
4523
4598
|
}
|
|
4524
|
-
async function executeGenerate(options) {
|
|
4599
|
+
async function executeGenerate(filters, options) {
|
|
4525
4600
|
try {
|
|
4526
4601
|
const parentOpts = options.parent?.opts?.() || {};
|
|
4527
4602
|
if (parentOpts.verbose) {
|
|
@@ -4531,6 +4606,9 @@ async function executeGenerate(options) {
|
|
|
4531
4606
|
}
|
|
4532
4607
|
logDebug("Starting migration generation...");
|
|
4533
4608
|
logDebug(`Options: ${JSON.stringify(options, null, 2)}`);
|
|
4609
|
+
if (filters && filters.length > 0) {
|
|
4610
|
+
logDebug(`Filters: ${JSON.stringify(filters)}`);
|
|
4611
|
+
}
|
|
4534
4612
|
const config = await loadConfig(options);
|
|
4535
4613
|
const schemaDir = getSchemaDirectory(config);
|
|
4536
4614
|
const migrationsDir = getMigrationsDirectory(config);
|
|
@@ -4554,7 +4632,18 @@ async function executeGenerate(options) {
|
|
|
4554
4632
|
logSuccess("Loaded previous snapshot as base reference");
|
|
4555
4633
|
}
|
|
4556
4634
|
logSection("\u{1F4CA} Comparing Schemas");
|
|
4557
|
-
|
|
4635
|
+
let diff = compare(currentSchema, previousSnapshot);
|
|
4636
|
+
const skipDestructive = !options.force;
|
|
4637
|
+
if (skipDestructive) {
|
|
4638
|
+
const destructive = detectDestructiveChanges(diff);
|
|
4639
|
+
if (destructive.length > 0) {
|
|
4640
|
+
logInfo(`\u2139\uFE0F Omitting ${destructive.length} destructive change(s) because --force is not set.`);
|
|
4641
|
+
}
|
|
4642
|
+
}
|
|
4643
|
+
diff = filterDiff(diff, {
|
|
4644
|
+
patterns: filters,
|
|
4645
|
+
skipDestructive
|
|
4646
|
+
});
|
|
4558
4647
|
if (!hasChanges2(diff)) {
|
|
4559
4648
|
logInfo("No changes detected");
|
|
4560
4649
|
console.log();
|