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.
- package/CHANGELOG.md +7 -0
- package/dist/cli/index.cjs +42 -9
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +42 -9
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +42 -9
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +42 -9
- package/dist/cli/migrate.js.map +1 -1
- package/dist/index.cjs +48 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +48 -11
- package/dist/index.js.map +1 -1
- package/dist/migration/analyzer.cjs +36 -7
- package/dist/migration/analyzer.cjs.map +1 -1
- package/dist/migration/analyzer.d.cts +26 -3
- package/dist/migration/analyzer.d.ts +26 -3
- package/dist/migration/analyzer.js +36 -8
- package/dist/migration/analyzer.js.map +1 -1
- package/dist/migration/diff.cjs +7 -2
- package/dist/migration/diff.cjs.map +1 -1
- package/dist/migration/diff.js +7 -2
- package/dist/migration/diff.js.map +1 -1
- package/dist/migration/index.cjs +42 -9
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.js +42 -9
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/snapshot.cjs.map +1 -1
- package/dist/migration/snapshot.js.map +1 -1
- package/dist/mutator.cjs +9 -3
- package/dist/mutator.cjs.map +1 -1
- package/dist/mutator.d.cts +3 -1
- package/dist/mutator.d.ts +3 -1
- package/dist/mutator.js +9 -3
- package/dist/mutator.js.map +1 -1
- package/dist/schema.cjs +9 -3
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +32 -3
- package/dist/schema.d.ts +32 -3
- package/dist/schema.js +9 -3
- package/dist/schema.js.map +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/{user-DTJQIj4K.d.cts → user-BnFWg5tw.d.cts} +13 -1
- package/dist/{user-DTJQIj4K.d.ts → user-BnFWg5tw.d.ts} +13 -1
- package/package.json +1 -1
package/dist/migration/index.js
CHANGED
|
@@ -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
|
|
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 (
|
|
1489
|
-
|
|
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
|
}
|
|
@@ -1575,8 +1598,13 @@ function extractIndexes(schema) {
|
|
|
1575
1598
|
}
|
|
1576
1599
|
function convertZodSchemaToCollectionSchema(collectionName, zodSchema) {
|
|
1577
1600
|
const rawFields = extractFieldDefinitions(zodSchema);
|
|
1578
|
-
const
|
|
1579
|
-
const
|
|
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
|
+
}
|
|
1580
1608
|
const indexes = extractIndexes(zodSchema) || [];
|
|
1581
1609
|
const permissionAnalyzer = new PermissionAnalyzer();
|
|
1582
1610
|
let permissions = void 0;
|
|
@@ -2560,9 +2588,14 @@ function matchCollectionsByName(currentSchema, previousSnapshot) {
|
|
|
2560
2588
|
if (!previousSnapshot) {
|
|
2561
2589
|
return matches;
|
|
2562
2590
|
}
|
|
2591
|
+
const previousCollectionsLower = /* @__PURE__ */ new Map();
|
|
2592
|
+
for (const [name, collection] of previousSnapshot.collections) {
|
|
2593
|
+
previousCollectionsLower.set(name.toLowerCase(), [name, collection]);
|
|
2594
|
+
}
|
|
2563
2595
|
for (const [collectionName, currentCollection] of currentSchema.collections) {
|
|
2564
|
-
const
|
|
2565
|
-
if (
|
|
2596
|
+
const previousEntry = previousCollectionsLower.get(collectionName.toLowerCase());
|
|
2597
|
+
if (previousEntry) {
|
|
2598
|
+
const [, previousCollection] = previousEntry;
|
|
2566
2599
|
matches.push([currentCollection, previousCollection]);
|
|
2567
2600
|
}
|
|
2568
2601
|
}
|