Skip to content

Commit 80bca8f

Browse files
author
Will Scullin
committed
Strip unused location fields from models
1 parent 4e9c78e commit 80bca8f

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

scripts/run_code.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,21 @@ export async function runCode(
246246
return renderResult(queryResult, dataStyles, options);
247247
}
248248

249+
// Simple check to prevent dropping sources named "location"
250+
const isLocation = (value: unknown) => {
251+
return value && typeof value === "object" && "url" in value;
252+
};
253+
254+
const stripLocation = (modelDef: ModelDef): ModelDef => {
255+
return JSON.parse(JSON.stringify(modelDef), (key, value) => {
256+
if (key === "location" && isLocation(value)) {
257+
return undefined;
258+
} else {
259+
return value;
260+
}
261+
});
262+
};
263+
249264
async function renderResult(
250265
queryResult: Result,
251266
dataStyles: DataStyles,
@@ -256,9 +271,9 @@ async function renderResult(
256271
const resultContainerId = crypto.randomUUID();
257272
let htmlResult = "";
258273
if (isNextRenderer) {
259-
const script = `
274+
const script = /* javascript */ `
260275
(function() {
261-
const modelDef = ${JSON.stringify(queryResult._modelDef)};
276+
const modelDef = ${JSON.stringify(stripLocation(queryResult._modelDef))};
262277
const queryResult = ${JSON.stringify(queryResult._queryResult)};
263278
const element = document.getElementById("${resultContainerId}");
264279
const malloyRender = document.createElement("malloy-render");

0 commit comments

Comments
 (0)