pocketbase-zod-schema 0.2.0 → 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 (46) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cli/index.cjs +44 -14
  3. package/dist/cli/index.cjs.map +1 -1
  4. package/dist/cli/index.js +44 -14
  5. package/dist/cli/index.js.map +1 -1
  6. package/dist/cli/migrate.cjs +44 -14
  7. package/dist/cli/migrate.cjs.map +1 -1
  8. package/dist/cli/migrate.js +44 -14
  9. package/dist/cli/migrate.js.map +1 -1
  10. package/dist/index.cjs +50 -16
  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 +50 -16
  15. package/dist/index.js.map +1 -1
  16. package/dist/migration/analyzer.cjs +38 -12
  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 +38 -13
  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 +44 -14
  27. package/dist/migration/index.cjs.map +1 -1
  28. package/dist/migration/index.js +44 -14
  29. package/dist/migration/index.js.map +1 -1
  30. package/dist/mutator.cjs +9 -3
  31. package/dist/mutator.cjs.map +1 -1
  32. package/dist/mutator.d.cts +3 -1
  33. package/dist/mutator.d.ts +3 -1
  34. package/dist/mutator.js +9 -3
  35. package/dist/mutator.js.map +1 -1
  36. package/dist/schema.cjs +9 -3
  37. package/dist/schema.cjs.map +1 -1
  38. package/dist/schema.d.cts +32 -3
  39. package/dist/schema.d.ts +32 -3
  40. package/dist/schema.js +9 -3
  41. package/dist/schema.js.map +1 -1
  42. package/dist/types.d.cts +1 -1
  43. package/dist/types.d.ts +1 -1
  44. package/dist/{user-DTJQIj4K.d.cts → user-BnFWg5tw.d.cts} +13 -1
  45. package/dist/{user-DTJQIj4K.d.ts → user-BnFWg5tw.d.ts} +13 -1
  46. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
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
+
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)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * remove analyzer console logs ([f632a96](https://github.com/dastron/pocketbase-zod-schema/commit/f632a96ad1d212587b712498e7061662f675bfc9))
16
+
3
17
  ## [0.2.0](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.1.4...pocketbase-zod-schema-v0.2.0) (2025-12-20)
4
18
 
5
19
 
@@ -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
  }
@@ -1310,11 +1333,8 @@ function buildFieldDefinition(fieldName, zodType) {
1310
1333
  // Default to false, can be configured later
1311
1334
  };
1312
1335
  if (fieldDef.options) {
1313
- const { min, max, pattern, ...relationSafeOptions } = fieldDef.options;
1314
- console.log("min", min);
1315
- console.log("max", max);
1316
- console.log("pattern", pattern);
1317
- fieldDef.options = Object.keys(relationSafeOptions).length > 0 ? relationSafeOptions : void 0;
1336
+ const { min: _min, max: _max, pattern: _pattern, ...relationSafeOptions } = fieldDef.options;
1337
+ fieldDef.options = Object.keys(relationSafeOptions).length ? relationSafeOptions : void 0;
1318
1338
  }
1319
1339
  }
1320
1340
  return fieldDef;
@@ -1335,8 +1355,13 @@ function extractIndexes(schema) {
1335
1355
  }
1336
1356
  function convertZodSchemaToCollectionSchema(collectionName, zodSchema) {
1337
1357
  const rawFields = extractFieldDefinitions(zodSchema);
1338
- const collectionType = isAuthCollection(rawFields) ? "auth" : "base";
1339
- 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
+ }
1340
1365
  const indexes = extractIndexes(zodSchema) || [];
1341
1366
  const permissionAnalyzer = new PermissionAnalyzer();
1342
1367
  let permissions = void 0;
@@ -1483,9 +1508,14 @@ function matchCollectionsByName(currentSchema, previousSnapshot) {
1483
1508
  if (!previousSnapshot) {
1484
1509
  return matches;
1485
1510
  }
1511
+ const previousCollectionsLower = /* @__PURE__ */ new Map();
1512
+ for (const [name, collection] of previousSnapshot.collections) {
1513
+ previousCollectionsLower.set(name.toLowerCase(), [name, collection]);
1514
+ }
1486
1515
  for (const [collectionName, currentCollection] of currentSchema.collections) {
1487
- const previousCollection = previousSnapshot.collections.get(collectionName);
1488
- if (previousCollection) {
1516
+ const previousEntry = previousCollectionsLower.get(collectionName.toLowerCase());
1517
+ if (previousEntry) {
1518
+ const [, previousCollection] = previousEntry;
1489
1519
  matches.push([currentCollection, previousCollection]);
1490
1520
  }
1491
1521
  }