Skip to content

Commit

Permalink
feat(core): Lift state loader restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Jan 7, 2024
1 parent 9834b9c commit 515b162
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions packages/kitten-scientists/source/state/State.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { InvalidOperationError, TreeNode } from "@oliversalzburg/js-utils";
import { TreeNode } from "@oliversalzburg/js-utils";
import AjvModule, { SchemaObject } from "ajv";
import { UserScript } from "../UserScript.js";
import { StateLoader } from "./StateLoader.js";
import { StateMerger } from "./StateMerger.js";

export class State extends TreeNode<State> {
static ALLOW_DATA_URL_IMPORT = false;

readonly originUrl: string;

readonly loader: StateLoader;
Expand All @@ -17,14 +15,6 @@ export class State extends TreeNode<State> {

constructor(originUrl: string, parent?: State) {
super(parent);
if (!originUrl.startsWith("https://kitten-science.com/")) {
// Make an exception for data URLs, if the exception was explicitly allowed.
if (!originUrl.startsWith("data:") || !State.ALLOW_DATA_URL_IMPORT) {
throw new InvalidOperationError(
"While state import is experimental, you can only import from 'https://kitten-science.com/'!",
);
}
}

this.originUrl = originUrl;
this.loader = new StateLoader(this);
Expand Down Expand Up @@ -56,14 +46,16 @@ export class State extends TreeNode<State> {
const isValidBaseline = validateBaseline(data);
const isValidProfile = validateProfile(data);
if (isValidProfile && !isValidBaseline) {
console.log(`VALID Profile: ${loader.state.originUrl})`);
console.log(`VALID Profile: ${loader.state.originUrl}`);
return true;
}
if (isValidProfile && isValidBaseline) {
console.log(`VALID Baseline: ${loader.state.originUrl})`);
console.log(`VALID Baseline: ${loader.state.originUrl}`);
return true;
}
console.log(`INVALID: ${loader.state.originUrl})`);
console.log(`INVALID: ${loader.state.originUrl}`);
console.debug(validateBaseline.errors);
console.debug(validateProfile.errors);
return false;
};

Expand Down

0 comments on commit 515b162

Please sign in to comment.