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.
- package/CHANGELOG.md +14 -0
- package/dist/cli/index.cjs +44 -14
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +44 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +44 -14
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +44 -14
- package/dist/cli/migrate.js.map +1 -1
- package/dist/index.cjs +50 -16
- 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 +50 -16
- package/dist/index.js.map +1 -1
- package/dist/migration/analyzer.cjs +38 -12
- 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 +38 -13
- 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 +44 -14
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.js +44 -14
- package/dist/migration/index.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.cjs
CHANGED
|
@@ -30,7 +30,9 @@ var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
|
30
30
|
id: zod.z.string().describe("unique id"),
|
|
31
31
|
collectionId: zod.z.string().describe("collection id"),
|
|
32
32
|
collectionName: zod.z.string().describe("collection name"),
|
|
33
|
-
expand: zod.z.record(zod.z.any()).describe("expandable fields")
|
|
33
|
+
expand: zod.z.record(zod.z.any()).describe("expandable fields"),
|
|
34
|
+
created: zod.z.string().describe("creation timestamp"),
|
|
35
|
+
updated: zod.z.string().describe("last update timestamp")
|
|
34
36
|
});
|
|
35
37
|
({
|
|
36
38
|
created: zod.z.string().describe("creation timestamp"),
|
|
@@ -1365,7 +1367,7 @@ var DEFAULT_CONFIG = {
|
|
|
1365
1367
|
"permission-templates.js"
|
|
1366
1368
|
],
|
|
1367
1369
|
includeExtensions: [".ts", ".js"],
|
|
1368
|
-
schemaPatterns: ["Schema", "InputSchema"],
|
|
1370
|
+
schemaPatterns: ["Schema", "InputSchema", "Collection"],
|
|
1369
1371
|
useCompiledFiles: true
|
|
1370
1372
|
};
|
|
1371
1373
|
function mergeConfig(config) {
|
|
@@ -1502,14 +1504,35 @@ function extractCollectionNameFromSchema(zodSchema) {
|
|
|
1502
1504
|
}
|
|
1503
1505
|
return null;
|
|
1504
1506
|
}
|
|
1505
|
-
function
|
|
1507
|
+
function extractCollectionTypeFromSchema(zodSchema) {
|
|
1508
|
+
if (!zodSchema.description) {
|
|
1509
|
+
return null;
|
|
1510
|
+
}
|
|
1511
|
+
try {
|
|
1512
|
+
const metadata = JSON.parse(zodSchema.description);
|
|
1513
|
+
if (metadata.type === "base" || metadata.type === "auth") {
|
|
1514
|
+
return metadata.type;
|
|
1515
|
+
}
|
|
1516
|
+
} catch {
|
|
1517
|
+
}
|
|
1518
|
+
return null;
|
|
1519
|
+
}
|
|
1520
|
+
function extractSchemaDefinitions(module, patterns = ["Schema", "InputSchema", "Collection"]) {
|
|
1506
1521
|
const result = {};
|
|
1522
|
+
if (module.default instanceof zod.z.ZodObject) {
|
|
1523
|
+
result.schema = module.default;
|
|
1524
|
+
}
|
|
1507
1525
|
for (const [key, value] of Object.entries(module)) {
|
|
1526
|
+
if (key === "default") continue;
|
|
1508
1527
|
if (value instanceof zod.z.ZodObject) {
|
|
1509
1528
|
if (patterns.includes("InputSchema") && key.endsWith("InputSchema")) {
|
|
1510
1529
|
result.inputSchema = value;
|
|
1511
|
-
} else if (
|
|
1512
|
-
|
|
1530
|
+
} else if (!result.schema) {
|
|
1531
|
+
if (patterns.includes("Collection") && key.endsWith("Collection")) {
|
|
1532
|
+
result.schema = value;
|
|
1533
|
+
} else if (patterns.includes("Schema") && key.endsWith("Schema") && !key.endsWith("InputSchema")) {
|
|
1534
|
+
result.schema = value;
|
|
1535
|
+
}
|
|
1513
1536
|
}
|
|
1514
1537
|
}
|
|
1515
1538
|
}
|
|
@@ -1576,11 +1599,8 @@ function buildFieldDefinition(fieldName, zodType) {
|
|
|
1576
1599
|
// Default to false, can be configured later
|
|
1577
1600
|
};
|
|
1578
1601
|
if (fieldDef.options) {
|
|
1579
|
-
const { min, max, pattern, ...relationSafeOptions } = fieldDef.options;
|
|
1580
|
-
|
|
1581
|
-
console.log("max", max);
|
|
1582
|
-
console.log("pattern", pattern);
|
|
1583
|
-
fieldDef.options = Object.keys(relationSafeOptions).length > 0 ? relationSafeOptions : void 0;
|
|
1602
|
+
const { min: _min, max: _max, pattern: _pattern, ...relationSafeOptions } = fieldDef.options;
|
|
1603
|
+
fieldDef.options = Object.keys(relationSafeOptions).length ? relationSafeOptions : void 0;
|
|
1584
1604
|
}
|
|
1585
1605
|
}
|
|
1586
1606
|
return fieldDef;
|
|
@@ -1601,8 +1621,13 @@ function extractIndexes(schema) {
|
|
|
1601
1621
|
}
|
|
1602
1622
|
function convertZodSchemaToCollectionSchema(collectionName, zodSchema) {
|
|
1603
1623
|
const rawFields = extractFieldDefinitions(zodSchema);
|
|
1604
|
-
const
|
|
1605
|
-
const
|
|
1624
|
+
const explicitType = extractCollectionTypeFromSchema(zodSchema);
|
|
1625
|
+
const collectionType = explicitType ?? (isAuthCollection(rawFields) ? "auth" : "base");
|
|
1626
|
+
let fields = rawFields.map(({ name, zodType }) => buildFieldDefinition(name, zodType));
|
|
1627
|
+
if (collectionType === "auth") {
|
|
1628
|
+
const authSystemFieldNames = ["email", "emailVisibility", "verified", "password", "tokenKey"];
|
|
1629
|
+
fields = fields.filter((field) => !authSystemFieldNames.includes(field.name));
|
|
1630
|
+
}
|
|
1606
1631
|
const indexes = extractIndexes(zodSchema) || [];
|
|
1607
1632
|
const permissionAnalyzer = new PermissionAnalyzer();
|
|
1608
1633
|
let permissions = void 0;
|
|
@@ -2586,9 +2611,14 @@ function matchCollectionsByName(currentSchema, previousSnapshot) {
|
|
|
2586
2611
|
if (!previousSnapshot) {
|
|
2587
2612
|
return matches;
|
|
2588
2613
|
}
|
|
2614
|
+
const previousCollectionsLower = /* @__PURE__ */ new Map();
|
|
2615
|
+
for (const [name, collection] of previousSnapshot.collections) {
|
|
2616
|
+
previousCollectionsLower.set(name.toLowerCase(), [name, collection]);
|
|
2617
|
+
}
|
|
2589
2618
|
for (const [collectionName, currentCollection] of currentSchema.collections) {
|
|
2590
|
-
const
|
|
2591
|
-
if (
|
|
2619
|
+
const previousEntry = previousCollectionsLower.get(collectionName.toLowerCase());
|
|
2620
|
+
if (previousEntry) {
|
|
2621
|
+
const [, previousCollection] = previousEntry;
|
|
2592
2622
|
matches.push([currentCollection, previousCollection]);
|
|
2593
2623
|
}
|
|
2594
2624
|
}
|