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
@@ -7,7 +7,9 @@ import { z } from 'zod';
7
7
  id: z.string().describe("unique id"),
8
8
  collectionId: z.string().describe("collection id"),
9
9
  collectionName: z.string().describe("collection name"),
10
- expand: z.record(z.any()).describe("expandable fields")
10
+ expand: z.record(z.any()).describe("expandable fields"),
11
+ created: z.string().describe("creation timestamp"),
12
+ updated: z.string().describe("last update timestamp")
11
13
  });
12
14
  ({
13
15
  created: z.string().describe("creation timestamp"),
@@ -1342,7 +1344,7 @@ var DEFAULT_CONFIG = {
1342
1344
  "permission-templates.js"
1343
1345
  ],
1344
1346
  includeExtensions: [".ts", ".js"],
1345
- schemaPatterns: ["Schema", "InputSchema"],
1347
+ schemaPatterns: ["Schema", "InputSchema", "Collection"],
1346
1348
  useCompiledFiles: true
1347
1349
  };
1348
1350
  function mergeConfig(config) {
@@ -1479,14 +1481,35 @@ function extractCollectionNameFromSchema(zodSchema) {
1479
1481
  }
1480
1482
  return null;
1481
1483
  }
1482
- function extractSchemaDefinitions(module, patterns = ["Schema", "InputSchema"]) {
1484
+ function extractCollectionTypeFromSchema(zodSchema) {
1485
+ if (!zodSchema.description) {
1486
+ return null;
1487
+ }
1488
+ try {
1489
+ const metadata = JSON.parse(zodSchema.description);
1490
+ if (metadata.type === "base" || metadata.type === "auth") {
1491
+ return metadata.type;
1492
+ }
1493
+ } catch {
1494
+ }
1495
+ return null;
1496
+ }
1497
+ function extractSchemaDefinitions(module, patterns = ["Schema", "InputSchema", "Collection"]) {
1483
1498
  const result = {};
1499
+ if (module.default instanceof z.ZodObject) {
1500
+ result.schema = module.default;
1501
+ }
1484
1502
  for (const [key, value] of Object.entries(module)) {
1503
+ if (key === "default") continue;
1485
1504
  if (value instanceof z.ZodObject) {
1486
1505
  if (patterns.includes("InputSchema") && key.endsWith("InputSchema")) {
1487
1506
  result.inputSchema = value;
1488
- } else if (patterns.includes("Schema") && key.endsWith("Schema") && !key.endsWith("InputSchema")) {
1489
- result.schema = value;
1507
+ } else if (!result.schema) {
1508
+ if (patterns.includes("Collection") && key.endsWith("Collection")) {
1509
+ result.schema = value;
1510
+ } else if (patterns.includes("Schema") && key.endsWith("Schema") && !key.endsWith("InputSchema")) {
1511
+ result.schema = value;
1512
+ }
1490
1513
  }
1491
1514
  }
1492
1515
  }
@@ -1553,11 +1576,8 @@ function buildFieldDefinition(fieldName, zodType) {
1553
1576
  // Default to false, can be configured later
1554
1577
  };
1555
1578
  if (fieldDef.options) {
1556
- const { min, max, pattern, ...relationSafeOptions } = fieldDef.options;
1557
- console.log("min", min);
1558
- console.log("max", max);
1559
- console.log("pattern", pattern);
1560
- fieldDef.options = Object.keys(relationSafeOptions).length > 0 ? relationSafeOptions : void 0;
1579
+ const { min: _min, max: _max, pattern: _pattern, ...relationSafeOptions } = fieldDef.options;
1580
+ fieldDef.options = Object.keys(relationSafeOptions).length ? relationSafeOptions : void 0;
1561
1581
  }
1562
1582
  }
1563
1583
  return fieldDef;
@@ -1578,8 +1598,13 @@ function extractIndexes(schema) {
1578
1598
  }
1579
1599
  function convertZodSchemaToCollectionSchema(collectionName, zodSchema) {
1580
1600
  const rawFields = extractFieldDefinitions(zodSchema);
1581
- const collectionType = isAuthCollection(rawFields) ? "auth" : "base";
1582
- const fields = rawFields.map(({ name, zodType }) => buildFieldDefinition(name, zodType));
1601
+ const explicitType = extractCollectionTypeFromSchema(zodSchema);
1602
+ const collectionType = explicitType ?? (isAuthCollection(rawFields) ? "auth" : "base");
1603
+ let fields = rawFields.map(({ name, zodType }) => buildFieldDefinition(name, zodType));
1604
+ if (collectionType === "auth") {
1605
+ const authSystemFieldNames = ["email", "emailVisibility", "verified", "password", "tokenKey"];
1606
+ fields = fields.filter((field) => !authSystemFieldNames.includes(field.name));
1607
+ }
1583
1608
  const indexes = extractIndexes(zodSchema) || [];
1584
1609
  const permissionAnalyzer = new PermissionAnalyzer();
1585
1610
  let permissions = void 0;
@@ -2563,9 +2588,14 @@ function matchCollectionsByName(currentSchema, previousSnapshot) {
2563
2588
  if (!previousSnapshot) {
2564
2589
  return matches;
2565
2590
  }
2591
+ const previousCollectionsLower = /* @__PURE__ */ new Map();
2592
+ for (const [name, collection] of previousSnapshot.collections) {
2593
+ previousCollectionsLower.set(name.toLowerCase(), [name, collection]);
2594
+ }
2566
2595
  for (const [collectionName, currentCollection] of currentSchema.collections) {
2567
- const previousCollection = previousSnapshot.collections.get(collectionName);
2568
- if (previousCollection) {
2596
+ const previousEntry = previousCollectionsLower.get(collectionName.toLowerCase());
2597
+ if (previousEntry) {
2598
+ const [, previousCollection] = previousEntry;
2569
2599
  matches.push([currentCollection, previousCollection]);
2570
2600
  }
2571
2601
  }