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/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ export { UserMutator } from './mutator.cjs';
|
|
|
3
3
|
export { ProjectInputType, ProjectType, TypedPocketBase, UserInputType, UserType } from './types.cjs';
|
|
4
4
|
export { CollectionConfig, PermissionTemplates, PermissionValidationResult, RelationConfig, RelationField, RelationsConfig, RelationsField, baseImageFileSchema, baseSchema, baseSchemaWithTimestamps, boolField, createPermissions, dateField, defineCollection, editorField, emailField, extractRelationMetadata, fileField, filesField, geoPointField, inputImageFileSchema, isPermissionSchema, isTemplateConfig, jsonField, mergePermissions, numberField, omitImageFilesSchema, resolveTemplate, selectField, textField, urlField, validatePermissionConfig, validateRuleExpression, withIndexes, withPermissions } from './schema.cjs';
|
|
5
5
|
export { A as APIRuleType, P as PermissionSchema, a as PermissionTemplate, b as PermissionTemplateConfig, R as RuleExpression } from './permissions-ZHafVSIx.cjs';
|
|
6
|
-
export {
|
|
6
|
+
export { P as ProjectCollection, a as ProjectInputSchema, b as ProjectSchema, U as UserCollection, d as UserCollectionSchema, c as UserInputSchema, e as UserSchema } from './user-BnFWg5tw.cjs';
|
|
7
7
|
export { SchemaAnalyzer, SchemaAnalyzerConfig, buildFieldDefinition, buildSchemaDefinition, convertZodSchemaToCollectionSchema, discoverSchemaFiles, extractFieldDefinitions, extractIndexes, extractSchemaDefinitions, getCollectionNameFromFile, importSchemaModule, isAuthCollection, parseSchemaFiles, selectSchemaForCollection } from './migration/analyzer.cjs';
|
|
8
8
|
export { SnapshotConfig, SnapshotManager, convertPocketBaseMigration, findLatestSnapshot, getSnapshotPath, getSnapshotVersion, loadBaseMigration, loadSnapshot, loadSnapshotIfExists, loadSnapshotWithMigrations, mergeSnapshots, saveSnapshot, snapshotExists, validateSnapshot } from './migration/snapshot.cjs';
|
|
9
9
|
export { ChangeSummary, DestructiveChange, DiffEngine, DiffEngineConfig, aggregateChanges, categorizeChangesBySeverity, compare, compareFieldConstraints, compareFieldOptions, compareFieldTypes, comparePermissions, compareRelationConfigurations, detectDestructiveChanges, detectFieldChanges, filterSystemCollections, findNewCollections, findNewFields, findRemovedCollections, findRemovedFields, generateChangeSummary, getUsersSystemFields, isSystemCollection, matchCollectionsByName, matchFieldsByName, requiresForceFlag } from './migration/diff.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { UserMutator } from './mutator.js';
|
|
|
3
3
|
export { ProjectInputType, ProjectType, TypedPocketBase, UserInputType, UserType } from './types.js';
|
|
4
4
|
export { CollectionConfig, PermissionTemplates, PermissionValidationResult, RelationConfig, RelationField, RelationsConfig, RelationsField, baseImageFileSchema, baseSchema, baseSchemaWithTimestamps, boolField, createPermissions, dateField, defineCollection, editorField, emailField, extractRelationMetadata, fileField, filesField, geoPointField, inputImageFileSchema, isPermissionSchema, isTemplateConfig, jsonField, mergePermissions, numberField, omitImageFilesSchema, resolveTemplate, selectField, textField, urlField, validatePermissionConfig, validateRuleExpression, withIndexes, withPermissions } from './schema.js';
|
|
5
5
|
export { A as APIRuleType, P as PermissionSchema, a as PermissionTemplate, b as PermissionTemplateConfig, R as RuleExpression } from './permissions-ZHafVSIx.js';
|
|
6
|
-
export {
|
|
6
|
+
export { P as ProjectCollection, a as ProjectInputSchema, b as ProjectSchema, U as UserCollection, d as UserCollectionSchema, c as UserInputSchema, e as UserSchema } from './user-BnFWg5tw.js';
|
|
7
7
|
export { SchemaAnalyzer, SchemaAnalyzerConfig, buildFieldDefinition, buildSchemaDefinition, convertZodSchemaToCollectionSchema, discoverSchemaFiles, extractFieldDefinitions, extractIndexes, extractSchemaDefinitions, getCollectionNameFromFile, importSchemaModule, isAuthCollection, parseSchemaFiles, selectSchemaForCollection } from './migration/analyzer.js';
|
|
8
8
|
export { SnapshotConfig, SnapshotManager, convertPocketBaseMigration, findLatestSnapshot, getSnapshotPath, getSnapshotVersion, loadBaseMigration, loadSnapshot, loadSnapshotIfExists, loadSnapshotWithMigrations, mergeSnapshots, saveSnapshot, snapshotExists, validateSnapshot } from './migration/snapshot.js';
|
|
9
9
|
export { ChangeSummary, DestructiveChange, DiffEngine, DiffEngineConfig, aggregateChanges, categorizeChangesBySeverity, compare, compareFieldConstraints, compareFieldOptions, compareFieldTypes, comparePermissions, compareRelationConfigurations, detectDestructiveChanges, detectFieldChanges, filterSystemCollections, findNewCollections, findNewFields, findRemovedCollections, findRemovedFields, generateChangeSummary, getUsersSystemFields, isSystemCollection, matchCollectionsByName, matchFieldsByName, requiresForceFlag } from './migration/diff.js';
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,9 @@ var baseSchema = {
|
|
|
19
19
|
id: z.string().describe("unique id"),
|
|
20
20
|
collectionId: z.string().describe("collection id"),
|
|
21
21
|
collectionName: z.string().describe("collection name"),
|
|
22
|
-
expand: z.record(z.any()).describe("expandable fields")
|
|
22
|
+
expand: z.record(z.any()).describe("expandable fields"),
|
|
23
|
+
created: z.string().describe("creation timestamp"),
|
|
24
|
+
updated: z.string().describe("last update timestamp")
|
|
23
25
|
};
|
|
24
26
|
var baseSchemaWithTimestamps = {
|
|
25
27
|
...baseSchema,
|
|
@@ -150,10 +152,13 @@ function withIndexes(schema, indexes) {
|
|
|
150
152
|
return schema.describe(JSON.stringify(metadata));
|
|
151
153
|
}
|
|
152
154
|
function defineCollection(config) {
|
|
153
|
-
const { collectionName, schema, permissions, indexes, ...futureOptions } = config;
|
|
155
|
+
const { collectionName, schema, permissions, indexes, type, ...futureOptions } = config;
|
|
154
156
|
const metadata = {
|
|
155
157
|
collectionName
|
|
156
158
|
};
|
|
159
|
+
if (type) {
|
|
160
|
+
metadata.type = type;
|
|
161
|
+
}
|
|
157
162
|
if (permissions) {
|
|
158
163
|
metadata.permissions = permissions;
|
|
159
164
|
}
|
|
@@ -422,7 +427,8 @@ var UserCollectionSchema = z.object({
|
|
|
422
427
|
});
|
|
423
428
|
var UserSchema = UserCollectionSchema.extend(baseSchema);
|
|
424
429
|
var UserCollection = defineCollection({
|
|
425
|
-
collectionName: "
|
|
430
|
+
collectionName: "users",
|
|
431
|
+
type: "auth",
|
|
426
432
|
schema: UserSchema,
|
|
427
433
|
permissions: {
|
|
428
434
|
// Users can list their own profile
|
|
@@ -1987,7 +1993,7 @@ var DEFAULT_CONFIG = {
|
|
|
1987
1993
|
"permission-templates.js"
|
|
1988
1994
|
],
|
|
1989
1995
|
includeExtensions: [".ts", ".js"],
|
|
1990
|
-
schemaPatterns: ["Schema", "InputSchema"],
|
|
1996
|
+
schemaPatterns: ["Schema", "InputSchema", "Collection"],
|
|
1991
1997
|
useCompiledFiles: true
|
|
1992
1998
|
};
|
|
1993
1999
|
function mergeConfig(config) {
|
|
@@ -2124,14 +2130,35 @@ function extractCollectionNameFromSchema(zodSchema) {
|
|
|
2124
2130
|
}
|
|
2125
2131
|
return null;
|
|
2126
2132
|
}
|
|
2127
|
-
function
|
|
2133
|
+
function extractCollectionTypeFromSchema(zodSchema) {
|
|
2134
|
+
if (!zodSchema.description) {
|
|
2135
|
+
return null;
|
|
2136
|
+
}
|
|
2137
|
+
try {
|
|
2138
|
+
const metadata = JSON.parse(zodSchema.description);
|
|
2139
|
+
if (metadata.type === "base" || metadata.type === "auth") {
|
|
2140
|
+
return metadata.type;
|
|
2141
|
+
}
|
|
2142
|
+
} catch {
|
|
2143
|
+
}
|
|
2144
|
+
return null;
|
|
2145
|
+
}
|
|
2146
|
+
function extractSchemaDefinitions(module, patterns = ["Schema", "InputSchema", "Collection"]) {
|
|
2128
2147
|
const result = {};
|
|
2148
|
+
if (module.default instanceof z.ZodObject) {
|
|
2149
|
+
result.schema = module.default;
|
|
2150
|
+
}
|
|
2129
2151
|
for (const [key, value] of Object.entries(module)) {
|
|
2152
|
+
if (key === "default") continue;
|
|
2130
2153
|
if (value instanceof z.ZodObject) {
|
|
2131
2154
|
if (patterns.includes("InputSchema") && key.endsWith("InputSchema")) {
|
|
2132
2155
|
result.inputSchema = value;
|
|
2133
|
-
} else if (
|
|
2134
|
-
|
|
2156
|
+
} else if (!result.schema) {
|
|
2157
|
+
if (patterns.includes("Collection") && key.endsWith("Collection")) {
|
|
2158
|
+
result.schema = value;
|
|
2159
|
+
} else if (patterns.includes("Schema") && key.endsWith("Schema") && !key.endsWith("InputSchema")) {
|
|
2160
|
+
result.schema = value;
|
|
2161
|
+
}
|
|
2135
2162
|
}
|
|
2136
2163
|
}
|
|
2137
2164
|
}
|
|
@@ -2198,11 +2225,8 @@ function buildFieldDefinition(fieldName, zodType) {
|
|
|
2198
2225
|
// Default to false, can be configured later
|
|
2199
2226
|
};
|
|
2200
2227
|
if (fieldDef.options) {
|
|
2201
|
-
const { min, max, pattern, ...relationSafeOptions } = fieldDef.options;
|
|
2202
|
-
|
|
2203
|
-
console.log("max", max);
|
|
2204
|
-
console.log("pattern", pattern);
|
|
2205
|
-
fieldDef.options = Object.keys(relationSafeOptions).length > 0 ? relationSafeOptions : void 0;
|
|
2228
|
+
const { min: _min, max: _max, pattern: _pattern, ...relationSafeOptions } = fieldDef.options;
|
|
2229
|
+
fieldDef.options = Object.keys(relationSafeOptions).length ? relationSafeOptions : void 0;
|
|
2206
2230
|
}
|
|
2207
2231
|
}
|
|
2208
2232
|
return fieldDef;
|
|
@@ -2223,8 +2247,13 @@ function extractIndexes(schema) {
|
|
|
2223
2247
|
}
|
|
2224
2248
|
function convertZodSchemaToCollectionSchema(collectionName, zodSchema) {
|
|
2225
2249
|
const rawFields = extractFieldDefinitions(zodSchema);
|
|
2226
|
-
const
|
|
2227
|
-
const
|
|
2250
|
+
const explicitType = extractCollectionTypeFromSchema(zodSchema);
|
|
2251
|
+
const collectionType = explicitType ?? (isAuthCollection(rawFields) ? "auth" : "base");
|
|
2252
|
+
let fields = rawFields.map(({ name, zodType }) => buildFieldDefinition(name, zodType));
|
|
2253
|
+
if (collectionType === "auth") {
|
|
2254
|
+
const authSystemFieldNames = ["email", "emailVisibility", "verified", "password", "tokenKey"];
|
|
2255
|
+
fields = fields.filter((field) => !authSystemFieldNames.includes(field.name));
|
|
2256
|
+
}
|
|
2228
2257
|
const indexes = extractIndexes(zodSchema) || [];
|
|
2229
2258
|
const permissionAnalyzer = new PermissionAnalyzer();
|
|
2230
2259
|
let permissions = void 0;
|
|
@@ -3208,9 +3237,14 @@ function matchCollectionsByName(currentSchema, previousSnapshot) {
|
|
|
3208
3237
|
if (!previousSnapshot) {
|
|
3209
3238
|
return matches;
|
|
3210
3239
|
}
|
|
3240
|
+
const previousCollectionsLower = /* @__PURE__ */ new Map();
|
|
3241
|
+
for (const [name, collection] of previousSnapshot.collections) {
|
|
3242
|
+
previousCollectionsLower.set(name.toLowerCase(), [name, collection]);
|
|
3243
|
+
}
|
|
3211
3244
|
for (const [collectionName, currentCollection] of currentSchema.collections) {
|
|
3212
|
-
const
|
|
3213
|
-
if (
|
|
3245
|
+
const previousEntry = previousCollectionsLower.get(collectionName.toLowerCase());
|
|
3246
|
+
if (previousEntry) {
|
|
3247
|
+
const [, previousCollection] = previousEntry;
|
|
3214
3248
|
matches.push([currentCollection, previousCollection]);
|
|
3215
3249
|
}
|
|
3216
3250
|
}
|