pocketbase-zod-schema 0.2.4 → 0.3.0
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 +15 -0
- package/README.md +209 -24
- package/dist/cli/index.cjs +406 -294
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +3 -1
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +406 -294
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +406 -294
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +406 -294
- package/dist/cli/migrate.js.map +1 -1
- package/dist/cli/utils/index.d.cts +3 -1
- package/dist/cli/utils/index.d.ts +3 -1
- package/dist/fields-UcOPu1OQ.d.cts +364 -0
- package/dist/fields-UcOPu1OQ.d.ts +364 -0
- package/dist/index.cjs +633 -112
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +619 -101
- package/dist/index.js.map +1 -1
- package/dist/migration/analyzer.cjs +44 -0
- package/dist/migration/analyzer.cjs.map +1 -1
- package/dist/migration/analyzer.d.cts +2 -1
- package/dist/migration/analyzer.d.ts +2 -1
- package/dist/migration/analyzer.js +44 -0
- package/dist/migration/analyzer.js.map +1 -1
- package/dist/migration/diff.cjs +76 -1
- package/dist/migration/diff.cjs.map +1 -1
- package/dist/migration/diff.d.cts +3 -1
- package/dist/migration/diff.d.ts +3 -1
- package/dist/migration/diff.js +76 -1
- package/dist/migration/diff.js.map +1 -1
- package/dist/migration/generator.cjs +323 -46
- package/dist/migration/generator.cjs.map +1 -1
- package/dist/migration/generator.d.cts +60 -11
- package/dist/migration/generator.d.ts +60 -11
- package/dist/migration/generator.js +319 -47
- package/dist/migration/generator.js.map +1 -1
- package/dist/migration/index.cjs +433 -47
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.d.cts +3 -2
- package/dist/migration/index.d.ts +3 -2
- package/dist/migration/index.js +432 -48
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/snapshot.cjs.map +1 -1
- package/dist/migration/snapshot.d.cts +3 -1
- package/dist/migration/snapshot.d.ts +3 -1
- package/dist/migration/snapshot.js.map +1 -1
- package/dist/migration/utils/index.cjs +80 -0
- package/dist/migration/utils/index.cjs.map +1 -1
- package/dist/migration/utils/index.d.cts +39 -202
- package/dist/migration/utils/index.d.ts +39 -202
- package/dist/migration/utils/index.js +77 -1
- package/dist/migration/utils/index.js.map +1 -1
- package/dist/schema.cjs +200 -61
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +2 -85
- package/dist/schema.d.ts +2 -85
- package/dist/schema.js +186 -50
- package/dist/schema.js.map +1 -1
- package/dist/type-mapper-DrQmtznD.d.cts +208 -0
- package/dist/type-mapper-n231Fspm.d.ts +208 -0
- package/dist/{types-z1Dkjg8m.d.ts → types-Ds3NQvny.d.ts} +33 -2
- package/dist/{types-BbTgmg6H.d.cts → types-YoBjsa-A.d.cts} +33 -2
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { S as SchemaDefinition, C as CollectionSchema, F as FieldDefinition } from '../types-
|
|
2
|
+
import { S as SchemaDefinition, C as CollectionSchema, F as FieldDefinition } from '../types-YoBjsa-A.cjs';
|
|
3
|
+
import '../fields-UcOPu1OQ.cjs';
|
|
3
4
|
import '../permissions-ZHafVSIx.cjs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { S as SchemaDefinition, C as CollectionSchema, F as FieldDefinition } from '../types-
|
|
2
|
+
import { S as SchemaDefinition, C as CollectionSchema, F as FieldDefinition } from '../types-Ds3NQvny.js';
|
|
3
|
+
import '../fields-UcOPu1OQ.js';
|
|
3
4
|
import '../permissions-ZHafVSIx.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -34,6 +34,18 @@ function extractRelationMetadata(description) {
|
|
|
34
34
|
}
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
|
+
var FIELD_METADATA_KEY = "__pocketbase_field__";
|
|
38
|
+
function extractFieldMetadata(description) {
|
|
39
|
+
if (!description) return null;
|
|
40
|
+
try {
|
|
41
|
+
const parsed = JSON.parse(description);
|
|
42
|
+
if (parsed[FIELD_METADATA_KEY]) {
|
|
43
|
+
return parsed[FIELD_METADATA_KEY];
|
|
44
|
+
}
|
|
45
|
+
} catch {
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
37
49
|
|
|
38
50
|
// src/migration/errors.ts
|
|
39
51
|
var MigrationError = class _MigrationError extends Error {
|
|
@@ -1182,6 +1194,38 @@ function isAuthCollection(fields) {
|
|
|
1182
1194
|
return hasEmail && hasPassword;
|
|
1183
1195
|
}
|
|
1184
1196
|
function buildFieldDefinition(fieldName, zodType) {
|
|
1197
|
+
const fieldMetadata = extractFieldMetadata(zodType.description);
|
|
1198
|
+
if (fieldMetadata) {
|
|
1199
|
+
let required2;
|
|
1200
|
+
if (fieldMetadata.type === "number") {
|
|
1201
|
+
if (fieldMetadata.options?.required !== void 0) {
|
|
1202
|
+
required2 = fieldMetadata.options.required;
|
|
1203
|
+
} else {
|
|
1204
|
+
required2 = false;
|
|
1205
|
+
}
|
|
1206
|
+
} else {
|
|
1207
|
+
required2 = isFieldRequired(zodType);
|
|
1208
|
+
}
|
|
1209
|
+
const { required: _required, ...options2 } = fieldMetadata.options || {};
|
|
1210
|
+
const fieldDef2 = {
|
|
1211
|
+
name: fieldName,
|
|
1212
|
+
type: fieldMetadata.type,
|
|
1213
|
+
required: required2,
|
|
1214
|
+
options: Object.keys(options2).length > 0 ? options2 : void 0
|
|
1215
|
+
};
|
|
1216
|
+
if (fieldMetadata.type === "relation") {
|
|
1217
|
+
const relationMetadata2 = extractRelationMetadata(zodType.description);
|
|
1218
|
+
if (relationMetadata2) {
|
|
1219
|
+
fieldDef2.relation = {
|
|
1220
|
+
collection: relationMetadata2.collection,
|
|
1221
|
+
maxSelect: relationMetadata2.maxSelect,
|
|
1222
|
+
minSelect: relationMetadata2.minSelect,
|
|
1223
|
+
cascadeDelete: relationMetadata2.cascadeDelete
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
return fieldDef2;
|
|
1228
|
+
}
|
|
1185
1229
|
const fieldType = mapZodTypeToPocketBase(zodType, fieldName);
|
|
1186
1230
|
const required = isFieldRequired(zodType);
|
|
1187
1231
|
const options = extractFieldOptions(zodType);
|