pocketbase-zod-schema 0.2.1 → 0.2.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 (48) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cli/index.cjs +42 -9
  3. package/dist/cli/index.cjs.map +1 -1
  4. package/dist/cli/index.js +42 -9
  5. package/dist/cli/index.js.map +1 -1
  6. package/dist/cli/migrate.cjs +42 -9
  7. package/dist/cli/migrate.cjs.map +1 -1
  8. package/dist/cli/migrate.js +42 -9
  9. package/dist/cli/migrate.js.map +1 -1
  10. package/dist/index.cjs +48 -11
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.js +48 -11
  15. package/dist/index.js.map +1 -1
  16. package/dist/migration/analyzer.cjs +36 -7
  17. package/dist/migration/analyzer.cjs.map +1 -1
  18. package/dist/migration/analyzer.d.cts +26 -3
  19. package/dist/migration/analyzer.d.ts +26 -3
  20. package/dist/migration/analyzer.js +36 -8
  21. package/dist/migration/analyzer.js.map +1 -1
  22. package/dist/migration/diff.cjs +7 -2
  23. package/dist/migration/diff.cjs.map +1 -1
  24. package/dist/migration/diff.js +7 -2
  25. package/dist/migration/diff.js.map +1 -1
  26. package/dist/migration/index.cjs +42 -9
  27. package/dist/migration/index.cjs.map +1 -1
  28. package/dist/migration/index.js +42 -9
  29. package/dist/migration/index.js.map +1 -1
  30. package/dist/migration/snapshot.cjs.map +1 -1
  31. package/dist/migration/snapshot.js.map +1 -1
  32. package/dist/mutator.cjs +9 -3
  33. package/dist/mutator.cjs.map +1 -1
  34. package/dist/mutator.d.cts +3 -1
  35. package/dist/mutator.d.ts +3 -1
  36. package/dist/mutator.js +9 -3
  37. package/dist/mutator.js.map +1 -1
  38. package/dist/schema.cjs +9 -3
  39. package/dist/schema.cjs.map +1 -1
  40. package/dist/schema.d.cts +32 -3
  41. package/dist/schema.d.ts +32 -3
  42. package/dist/schema.js +9 -3
  43. package/dist/schema.js.map +1 -1
  44. package/dist/types.d.cts +1 -1
  45. package/dist/types.d.ts +1 -1
  46. package/dist/{user-DTJQIj4K.d.cts → user-BnFWg5tw.d.cts} +13 -1
  47. package/dist/{user-DTJQIj4K.d.ts → user-BnFWg5tw.d.ts} +13 -1
  48. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.2](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.2.1...pocketbase-zod-schema-v0.2.2) (2025-12-20)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * update base schema ([98aaaef](https://github.com/dastron/pocketbase-zod-schema/commit/98aaaef365f3de350837c2390adb6870758781a2))
9
+
3
10
  ## [0.2.1](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.2.0...pocketbase-zod-schema-v0.2.1) (2025-12-20)
4
11
 
5
12
 
@@ -36,7 +36,9 @@ var ora__default = /*#__PURE__*/_interopDefault(ora);
36
36
  id: zod.z.string().describe("unique id"),
37
37
  collectionId: zod.z.string().describe("collection id"),
38
38
  collectionName: zod.z.string().describe("collection name"),
39
- expand: zod.z.record(zod.z.any()).describe("expandable fields")
39
+ expand: zod.z.record(zod.z.any()).describe("expandable fields"),
40
+ created: zod.z.string().describe("creation timestamp"),
41
+ updated: zod.z.string().describe("last update timestamp")
40
42
  });
41
43
  ({
42
44
  created: zod.z.string().describe("creation timestamp"),
@@ -1099,7 +1101,7 @@ var DEFAULT_CONFIG = {
1099
1101
  "permission-templates.js"
1100
1102
  ],
1101
1103
  includeExtensions: [".ts", ".js"],
1102
- schemaPatterns: ["Schema", "InputSchema"],
1104
+ schemaPatterns: ["Schema", "InputSchema", "Collection"],
1103
1105
  useCompiledFiles: true
1104
1106
  };
1105
1107
  function mergeConfig(config) {
@@ -1236,14 +1238,35 @@ function extractCollectionNameFromSchema(zodSchema) {
1236
1238
  }
1237
1239
  return null;
1238
1240
  }
1239
- function extractSchemaDefinitions(module, patterns = ["Schema", "InputSchema"]) {
1241
+ function extractCollectionTypeFromSchema(zodSchema) {
1242
+ if (!zodSchema.description) {
1243
+ return null;
1244
+ }
1245
+ try {
1246
+ const metadata = JSON.parse(zodSchema.description);
1247
+ if (metadata.type === "base" || metadata.type === "auth") {
1248
+ return metadata.type;
1249
+ }
1250
+ } catch {
1251
+ }
1252
+ return null;
1253
+ }
1254
+ function extractSchemaDefinitions(module, patterns = ["Schema", "InputSchema", "Collection"]) {
1240
1255
  const result = {};
1256
+ if (module.default instanceof zod.z.ZodObject) {
1257
+ result.schema = module.default;
1258
+ }
1241
1259
  for (const [key, value] of Object.entries(module)) {
1260
+ if (key === "default") continue;
1242
1261
  if (value instanceof zod.z.ZodObject) {
1243
1262
  if (patterns.includes("InputSchema") && key.endsWith("InputSchema")) {
1244
1263
  result.inputSchema = value;
1245
- } else if (patterns.includes("Schema") && key.endsWith("Schema") && !key.endsWith("InputSchema")) {
1246
- result.schema = value;
1264
+ } else if (!result.schema) {
1265
+ if (patterns.includes("Collection") && key.endsWith("Collection")) {
1266
+ result.schema = value;
1267
+ } else if (patterns.includes("Schema") && key.endsWith("Schema") && !key.endsWith("InputSchema")) {
1268
+ result.schema = value;
1269
+ }
1247
1270
  }
1248
1271
  }
1249
1272
  }
@@ -1332,8 +1355,13 @@ function extractIndexes(schema) {
1332
1355
  }
1333
1356
  function convertZodSchemaToCollectionSchema(collectionName, zodSchema) {
1334
1357
  const rawFields = extractFieldDefinitions(zodSchema);
1335
- const collectionType = isAuthCollection(rawFields) ? "auth" : "base";
1336
- const fields = rawFields.map(({ name, zodType }) => buildFieldDefinition(name, zodType));
1358
+ const explicitType = extractCollectionTypeFromSchema(zodSchema);
1359
+ const collectionType = explicitType ?? (isAuthCollection(rawFields) ? "auth" : "base");
1360
+ let fields = rawFields.map(({ name, zodType }) => buildFieldDefinition(name, zodType));
1361
+ if (collectionType === "auth") {
1362
+ const authSystemFieldNames = ["email", "emailVisibility", "verified", "password", "tokenKey"];
1363
+ fields = fields.filter((field) => !authSystemFieldNames.includes(field.name));
1364
+ }
1337
1365
  const indexes = extractIndexes(zodSchema) || [];
1338
1366
  const permissionAnalyzer = new PermissionAnalyzer();
1339
1367
  let permissions = void 0;
@@ -1480,9 +1508,14 @@ function matchCollectionsByName(currentSchema, previousSnapshot) {
1480
1508
  if (!previousSnapshot) {
1481
1509
  return matches;
1482
1510
  }
1511
+ const previousCollectionsLower = /* @__PURE__ */ new Map();
1512
+ for (const [name, collection] of previousSnapshot.collections) {
1513
+ previousCollectionsLower.set(name.toLowerCase(), [name, collection]);
1514
+ }
1483
1515
  for (const [collectionName, currentCollection] of currentSchema.collections) {
1484
- const previousCollection = previousSnapshot.collections.get(collectionName);
1485
- if (previousCollection) {
1516
+ const previousEntry = previousCollectionsLower.get(collectionName.toLowerCase());
1517
+ if (previousEntry) {
1518
+ const [, previousCollection] = previousEntry;
1486
1519
  matches.push([currentCollection, previousCollection]);
1487
1520
  }
1488
1521
  }