Skip to content

Commit

Permalink
Fix issues when loading modules from the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
freekh committed Aug 24, 2023
1 parent 24c4b0f commit 275a6c8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 1 addition & 3 deletions packages/core/src/schema/validation/ValidationError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ export type ValidationError = {
*
* Global errors have the path `"/"`.
*/
export type ValidationErrors =
| false
| Record<SourcePath | "/", ValidationError[]>;
export type ValidationErrors = false | Record<SourcePath, ValidationError[]>;
1 change: 1 addition & 0 deletions packages/react/src/ValUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ export default function ValUI({ valApi, valStore }: ValUIProps) {
];
return valApi.patchModuleContent(moduleId, patch);
}
console.log("->", input);
throw new Error(
`Unsupported input type: ${(input as any).type}`
);
Expand Down
26 changes: 21 additions & 5 deletions packages/server/src/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,39 @@ export class Service {
this.runtime
);

if (valModule.errors) {
return valModule;
} else {
if (valModule.source && valModule.schema) {
const resolved = Internal.resolvePath(
modulePath,
valModule.source,
valModule.schema
);
const sourcePath = [moduleId, resolved.path].join(".") as SourcePath;
return {
path: [moduleId, resolved.path].join(".") as SourcePath,
path: sourcePath,
schema:
resolved.schema instanceof Schema<SelectorSource>
? resolved.schema.serialize()
: resolved.schema,
source: resolved.source,
errors: false,
errors:
valModule.errors &&
valModule.errors.validation &&
valModule.errors.validation[sourcePath]
? {
validation: valModule.errors.validation[sourcePath]
? {
[sourcePath]: valModule.errors.validation[sourcePath],
}
: undefined,
fatal:
valModule.errors && valModule.errors.fatal
? valModule.errors.fatal
: undefined,
}
: false,
};
} else {
return valModule;
}
}

Expand Down

0 comments on commit 275a6c8

Please sign in to comment.