pocketbase-zod-schema 0.2.1 → 0.2.3
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 +94 -10
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +94 -10
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +94 -10
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +94 -10
- package/dist/cli/migrate.js.map +1 -1
- package/dist/index.cjs +100 -12
- 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 +100 -12
- 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/generator.cjs +52 -1
- package/dist/migration/generator.cjs.map +1 -1
- package/dist/migration/generator.d.cts +0 -7
- package/dist/migration/generator.d.ts +0 -7
- package/dist/migration/generator.js +52 -1
- package/dist/migration/generator.js.map +1 -1
- package/dist/migration/index.cjs +94 -10
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.js +94 -10
- 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
|
@@ -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"),
|
|
@@ -1003,7 +1005,7 @@ var DEFAULT_CONFIG = {
|
|
|
1003
1005
|
"permission-templates.js"
|
|
1004
1006
|
],
|
|
1005
1007
|
includeExtensions: [".ts", ".js"],
|
|
1006
|
-
schemaPatterns: ["Schema", "InputSchema"],
|
|
1008
|
+
schemaPatterns: ["Schema", "InputSchema", "Collection"],
|
|
1007
1009
|
useCompiledFiles: true
|
|
1008
1010
|
};
|
|
1009
1011
|
function mergeConfig(config) {
|
|
@@ -1140,14 +1142,35 @@ function extractCollectionNameFromSchema(zodSchema) {
|
|
|
1140
1142
|
}
|
|
1141
1143
|
return null;
|
|
1142
1144
|
}
|
|
1143
|
-
function
|
|
1145
|
+
function extractCollectionTypeFromSchema(zodSchema) {
|
|
1146
|
+
if (!zodSchema.description) {
|
|
1147
|
+
return null;
|
|
1148
|
+
}
|
|
1149
|
+
try {
|
|
1150
|
+
const metadata = JSON.parse(zodSchema.description);
|
|
1151
|
+
if (metadata.type === "base" || metadata.type === "auth") {
|
|
1152
|
+
return metadata.type;
|
|
1153
|
+
}
|
|
1154
|
+
} catch {
|
|
1155
|
+
}
|
|
1156
|
+
return null;
|
|
1157
|
+
}
|
|
1158
|
+
function extractSchemaDefinitions(module, patterns = ["Schema", "InputSchema", "Collection"]) {
|
|
1144
1159
|
const result = {};
|
|
1160
|
+
if (module.default instanceof zod.z.ZodObject) {
|
|
1161
|
+
result.schema = module.default;
|
|
1162
|
+
}
|
|
1145
1163
|
for (const [key, value] of Object.entries(module)) {
|
|
1164
|
+
if (key === "default") continue;
|
|
1146
1165
|
if (value instanceof zod.z.ZodObject) {
|
|
1147
1166
|
if (patterns.includes("InputSchema") && key.endsWith("InputSchema")) {
|
|
1148
1167
|
result.inputSchema = value;
|
|
1149
|
-
} else if (
|
|
1150
|
-
|
|
1168
|
+
} else if (!result.schema) {
|
|
1169
|
+
if (patterns.includes("Collection") && key.endsWith("Collection")) {
|
|
1170
|
+
result.schema = value;
|
|
1171
|
+
} else if (patterns.includes("Schema") && key.endsWith("Schema") && !key.endsWith("InputSchema")) {
|
|
1172
|
+
result.schema = value;
|
|
1173
|
+
}
|
|
1151
1174
|
}
|
|
1152
1175
|
}
|
|
1153
1176
|
}
|
|
@@ -1236,8 +1259,13 @@ function extractIndexes(schema) {
|
|
|
1236
1259
|
}
|
|
1237
1260
|
function convertZodSchemaToCollectionSchema(collectionName, zodSchema) {
|
|
1238
1261
|
const rawFields = extractFieldDefinitions(zodSchema);
|
|
1239
|
-
const
|
|
1240
|
-
const
|
|
1262
|
+
const explicitType = extractCollectionTypeFromSchema(zodSchema);
|
|
1263
|
+
const collectionType = explicitType ?? (isAuthCollection(rawFields) ? "auth" : "base");
|
|
1264
|
+
let fields = rawFields.map(({ name, zodType }) => buildFieldDefinition(name, zodType));
|
|
1265
|
+
if (collectionType === "auth") {
|
|
1266
|
+
const authSystemFieldNames = ["email", "emailVisibility", "verified", "password", "tokenKey"];
|
|
1267
|
+
fields = fields.filter((field) => !authSystemFieldNames.includes(field.name));
|
|
1268
|
+
}
|
|
1241
1269
|
const indexes = extractIndexes(zodSchema) || [];
|
|
1242
1270
|
const permissionAnalyzer = new PermissionAnalyzer();
|
|
1243
1271
|
let permissions = void 0;
|
|
@@ -1363,6 +1391,7 @@ exports.buildSchemaDefinition = buildSchemaDefinition;
|
|
|
1363
1391
|
exports.convertZodSchemaToCollectionSchema = convertZodSchemaToCollectionSchema;
|
|
1364
1392
|
exports.discoverSchemaFiles = discoverSchemaFiles;
|
|
1365
1393
|
exports.extractCollectionNameFromSchema = extractCollectionNameFromSchema;
|
|
1394
|
+
exports.extractCollectionTypeFromSchema = extractCollectionTypeFromSchema;
|
|
1366
1395
|
exports.extractFieldDefinitions = extractFieldDefinitions;
|
|
1367
1396
|
exports.extractIndexes = extractIndexes;
|
|
1368
1397
|
exports.extractSchemaDefinitions = extractSchemaDefinitions;
|