In this section
- Tests test · solar-electrical-topology-analysis-engine-text-based / v9-sandbox/debug/tests.js lines 1–162
- Solar Electrical Topology Analysis Engine Text Based — V9 Sandbox Page render · solar-electrical-topology-analysis-engine-text-based / v9-sandbox/index.html lines 1–73
- Schema transform · solar-electrical-topology-analysis-engine-text-based / v9-sandbox/schema.js lines 1–117
- State transform · solar-electrical-topology-analysis-engine-text-based / v9-sandbox/state.js lines 1–100
- Contract transform · star-solar-star / create/contract.js lines 1–43
- Star Solar Star — Create Page render · star-solar-star / create/index.html lines 1–53
Tests
A JavaScript module in the debug folder of Solar Electrical Topology Analysis Engine Text Based.
testsolar-electrical-topology-analysis-engine-text-based / v9-sandbox/debug/tests.js · lines 1–162 of 162 · pattern assert (shared by 7 files)
- What it does
- It tests its inputs. Defines close, test, assert, runDebugTests.
- Why it exists in the grid workflow
- Domain stage experimental (path word 'sandbox'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: 1500V. README: "`tests.js` — deterministic unit checks and Claude-readable review questions."
- Inputs & outputs
- Voltage levels named: 1500V.
- Downstream impact
- Used directly by 2 files: Solar Electrical Topology Analysis Engine Text Based — V9 Sandbox (solar-electrical-topology-analysis-engine-text-based, https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v9-sandbox/); Run Tests (solar-electrical-topology-analysis-engine-text-based). Reached from 134 other entry points, including GlobalGrid2050 Historical Builds (globalgrid2050, https://globalgrid2050.com/historical_builds.html); GlobalGrid2050 Homepage Before Four Nests (globalgrid2050, https://globalgrid2050.com/homepage-before-four-nests-20260925.html); Homepage V002 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v002.html).
- What it achieves
- It runs debug tests (`runDebugTests`) and is built from the close step (`close`) and the assert step (`assert`). The README says: Deterministic unit checks and Claude-readable review questions.
- Why it matters
- Imported by Solar Electrical Topology Analysis Engine Text Based — V9 Sandbox. Checked by Run Tests.
- Application
- solar-electrical-topology-analysis-engine-text-based · v9-sandbox/debug · JavaScript module
- Uses
- Engine (import)
- Used by
- imported by Solar Electrical Topology Analysis Engine Text Based — V9 Sandbox (import), imported by Run Tests (import)
- Produces
- runDebugTests
- Defines here
- close, test, assert, runDebugTests
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- solar-electrical-topology-analysis-engine-text-based@d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9 v9-sandbox/debug/tests.js:1-162 · blob fb81d35a250e57bce960fa36f97296fa63bcc80c · GitHub at these lines
- State
- achieves: readme · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: production_core
import {
EngineInputError,
allocateMppts,
computeProject,
conductorResistanceOhm,
topologyOrder,
} from "./engine.js";
function close(actual, expected, tolerance = 1e-9) {
return Math.abs(actual - expected) <= tolerance;
}
function test(name, fn) {
try {
const detail = fn();
return {
name,
status: "pass",
detail: detail ?? "ok",
};
} catch (error) {
return {
name,
status: "fail",
detail: error instanceof Error ? error.message : String(error),
};
}
}
function assert(condition, message) {
if (!condition) {
throw new Error(message);
}
}
export function runDebugTests() {
const results = [
test("sequential order", () => {
const actual = JSON.stringify(topologyOrder(5, "sequential"));
assert(actual === "[1,2,3,4,5]", "unexpected sequential order");
}),
test("leapfrog order for 30 modules", () => {
const order = topologyOrder(30, "leapfrog");
assert(order.length === 30, "wrong order length");
assert(new Set(order).size === 30, "duplicate module");
const turningSequenceIsCorrect = (
order[14] === 29
&& order[15] === 30
&& order.at(-1) === 2
);
assert(turningSequenceIsCorrect, "wrong leapfrog turning sequence");
}),
test("custom order accepts module numbers above four", () => {
const order = topologyOrder(
6,
"custom",
[1, 3, 5, 6, 4, 2],
);
const preserved = order[2] === 5 && order[3] === 6;
assert(preserved, "custom order was clamped or altered");
}),
test("invalid custom order is rejected", () => {
let rejected = false;
try {
topologyOrder(4, "custom", [1, 2, 2, 4]);
} catch (error) {
rejected = error instanceof EngineInputError;
}
assert(rejected, "duplicate custom module was not rejected");
}),
test("MPPT allocation caps active strings at 24", () => {
const allocation = allocateMppts({
mpptCount: 100,
defaultInputsPerMppt: 4,
});
assert(allocation.requestedStrings === 400, "wrong requested count");
assert(allocation.activeStrings === 24, "active string cap failed");
assert(allocation.truncated, "truncation flag missing");
}),
test("12 MPPT by two inputs produces 24 strings", () => {
const project = computeProject({
mpptCount: 12,
defaultInputsPerMppt: 2,
modulesPerString: 30,
});
assert(project.strings.length === 24, "wrong string count");
assert(project.totals.modules === 720, "wrong module total");
}),
test("corrected Voc default exceeds 1500 V", () => {
const project = computeProject({
modulesPerString: 30,
moduleVocStcV: 50,
vocTempCoefficientPercentPerC: -0.24,
cellTemperatureC: 20,
});
assert(
close(project.voltage.moduleVocCorrectedV, 50.6),
"wrong corrected module Voc",
);
assert(
close(project.voltage.stringVocV, 1518),
"wrong string Voc",
);
const hasLimitWarning = project.warnings.some(
(warning) => warning.code === "VOLTAGE_LIMIT",
);
assert(hasLimitWarning, "missing voltage-limit warning");
}),
test("copper resistance at 20 C", () => {
const resistance = conductorResistanceOhm({
lengthM: 100,
csaMm2: 10,
conductorTemperatureC: 20,
});
assert(
close(resistance, 0.17241, 1e-8),
`unexpected resistance ${resistance}`,
);
}),
test("segment count is modules plus one", () => {
const project = computeProject({
mpptCount: 1,
defaultInputsPerMppt: 1,
modulesPerString: 6,
});
assert(
project.strings[0].segments.length === 7,
"expected two home runs and five interconnects",
);
}),
test("deterministic result excluding timestamp", () => {
const input = {
mpptCount: 2,
defaultInputsPerMppt: 1,
modulesPerString: 8,
};
const first = computeProject(input);
const second = computeProject(input);
delete first.generatedAt;
delete second.generatedAt;
assert(
JSON.stringify(first) === JSON.stringify(second),
"same input produced different output",
);
}),
];
return {
schema: "globalgrid2050.solar-dc-debug-test-report.v1",
generatedAt: new Date().toISOString(),
passed: results.filter((result) => result.status === "pass").length,
failed: results.filter((result) => result.status === "fail").length,
results,
reviewQuestions: [
"Does each formula use the correct physical quantity and temperature basis?",
"Does the electrical order pass through every module exactly once?",
"Are known routes, factory leads and provisional extensions separated?",
"Are screening estimates clearly distinguished from construction quantities?",
"Which missing physical objects block trusted EMC or transient studies?",
],
};
}Solar Electrical Topology Analysis Engine Text Based — V9 Sandbox Page
A web page that reads inputs for MPPT count, default inputs per MPPT and allocation override (units: mm², °C), using IEC 60228. Published at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v9-sandbox/.
rendersolar-electrical-topology-analysis-engine-text-based / v9-sandbox/index.html · lines 1–73 of 73 · Entry point
- What it does
- It draws its content. Side effects: changes the web page (DOM).
- Why it exists in the grid workflow
- Domain stage experimental (path word 'sandbox'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. README: "The public `v9-sandbox/index.html` entry point is live and temporarily reuses the proven B9 renderer and styles so the browser remains operational while the code is extracted safely."
- Inputs & outputs
- In: form fields (user input). Out: web page.
- Downstream impact
- Used directly by 39 files: GlobalGrid2050 Historical Builds (globalgrid2050, https://globalgrid2050.com/historical_builds.html); Homepage Versions — GlobalGrid2050 Page (globalgrid2050, https://globalgrid2050.com/homepage_versions/202608291526-globalgrid2050/); Homepage V002 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v002.html); Homepage V003 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v003.html); and 35 more. Reached from 85 other entry points, including GlobalGrid2050 Homepage Before Four Nests (globalgrid2050, https://globalgrid2050.com/homepage-before-four-nests-20260925.html); Homepage V037 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v037.html); Homepage V038 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v038.html). It is itself an entry point, published at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v9-sandbox/.
- What it achieves
- Historical computation-first solar PV DC string, MPPT, segment and voltage debug engine with explicit ideal-bulk resistance limits.
- Why it matters
- Loaded by the GlobalGrid2050 Historical Builds map page in GlobalGrid2050 at https://globalgrid2050.com/historical_builds.html and 38 other pages.
- Application
- solar-electrical-topology-analysis-engine-text-based · v9-sandbox · page
- Uses
- Solar Electrical Topology Analysis Engine Text Based — V9 Sandbox (script src)
- Used by
- named by URL in GlobalGrid2050 Historical Builds (estate URL), named by URL in Homepage Versions — GlobalGrid2050 Page (estate URL), named by URL in Homepage V002 (estate URL), named by URL in Homepage V003 (estate URL), named by URL in Homepage V004 (estate URL), named by URL in Homepage V005 (estate URL), named by URL in Homepage V006 (estate URL), named by URL in Homepage V007 (estate URL), and 31 more
- Produces
- none declared
- Defines here
- none
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- solar-electrical-topology-analysis-engine-text-based@d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9 v9-sandbox/index.html:1-73 · blob 4b3b5593cf394ac8e2d97bad308dc398dc437408 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: experimental · users: none · canonical: production_core
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>V9 Solar DC Computation Engine</title>
<meta name="description" content="Historical computation-first solar PV DC string, MPPT, segment and voltage debug engine with explicit ideal-bulk resistance limits.">
<style>
:root{color-scheme:dark;font-family:ui-monospace,SFMono-Regular,Consolas,monospace;background:#071018;color:#e8f4ff}
*{box-sizing:border-box}body{margin:0;padding:20px}main{max-width:1500px;margin:auto;display:grid;grid-template-columns:minmax(300px,430px) 1fr;gap:18px}
section{background:#0d1a24;border:1px solid #294052;border-radius:8px;padding:16px;margin-bottom:14px}h1,h2{margin-top:0}h1{font-size:1.55rem}h2{font-size:1rem;color:#7ee7ff}
.field{display:grid;grid-template-columns:1fr 130px;gap:10px;align-items:center;margin:9px 0}.full{grid-template-columns:1fr}.full input,.full textarea,.full select{width:100%}
input,select,textarea,button{font:inherit;background:#061018;color:#fff;border:1px solid #3c5b70;border-radius:5px;padding:8px}textarea{min-height:70px}button{cursor:pointer}button.primary{border-color:#00d5ff;color:#00e5ff;font-weight:700}
.status{font-weight:700}.pass{color:#59ff76}.fail{color:#ff5d66}.warning{color:#ffd166}.info{color:#84caff}
.authority-warning{border-left:5px solid #ffd166;background:#241c08;color:#ffe7a3}.authority-warning strong{display:block;color:#ffd166;margin-bottom:8px}
dl{display:grid;grid-template-columns:1fr auto;gap:6px 14px;margin:0}dt{color:#9bb2c2}dd{margin:0;text-align:right}pre{white-space:pre-wrap;overflow:auto;max-height:480px;background:#04090d;padding:12px;border-radius:6px;font-size:.78rem}
table{width:100%;border-collapse:collapse;font-size:.82rem}th,td{padding:7px;border-bottom:1px solid #233847;text-align:left}.report-actions{display:flex;gap:8px;flex-wrap:wrap}.small{font-size:.82rem;color:#9bb2c2}
@media(max-width:900px){main{grid-template-columns:1fr}body{padding:10px}.field{grid-template-columns:1fr}.field input,.field select{width:100%}}
</style>
</head>
<body>
<main>
<aside>
<section><h1>V9 Solar DC Computation Engine</h1><p>Historical/reference computation workbench. No plan view. No side view. Governing legacy logic lives in <code>v9-sandbox/debug/</code>; V10 is the canonical candidate authority.</p></section>
<section class="authority-warning" id="legacyResistanceAuthority">
<strong>RESISTANCE AUTHORITY · HISTORICAL LOWER-BOUND SCREEN</strong>
Ideal bulk-copper screening calculation using nominal metallic area.
Not a finished-cable declared resistance and not an IEC 60228
maximum-resistance calculation. Exported V9 reports repeat this
classification as <code>ideal_bulk_estimate</code>.
</section>
<form id="engineForm">
<section><h2>Inverter allocation</h2>
<label class="field">MPPT count<input id="mpptCount" type="number" min="1" max="100" value="12"></label>
<label class="field">Default inputs / MPPT<input id="defaultInputsPerMppt" type="number" min="0" max="4" value="2"></label>
<label class="field full">Allocation override<textarea id="allocationOverride" placeholder="Example: 2,2,1,4"></textarea></label>
</section>
<section><h2>String topology</h2>
<label class="field">Modules / string<input id="modulesPerString" type="number" min="1" max="30" value="30"></label>
<label class="field">Topology<select id="topology"><option value="leapfrog">Leapfrog</option><option value="sequential">Sequential</option><option value="mirrored-sequential">Mirrored sequential</option><option value="alternating-return">Alternating return</option><option value="custom">Custom</option></select></label>
<label class="field full">Custom order<textarea id="customOrder" placeholder="1,3,5,..."></textarea></label>
</section>
<section><h2>Physical and conductor inputs</h2>
<label class="field">Module width (m)<input id="moduleWidthM" type="number" step="0.001" value="1.303"></label>
<label class="field">Module gap (m)<input id="moduleGapM" type="number" step="0.001" value="0"></label>
<label class="field">Positive lead (m)<input id="positiveLeadM" type="number" step="0.01" value="1.4"></label>
<label class="field">Negative lead (m)<input id="negativeLeadM" type="number" step="0.01" value="1.4"></label>
<label class="field">Route one way (m)<input id="routeOneWayM" type="number" step="0.1" value="10"></label>
<label class="field">External CSA (mm²)<input id="externalCableCsaMm2" type="number" step="0.1" value="6"></label>
<label class="field">Factory lead CSA (mm²)<input id="factoryLeadCsaMm2" type="number" step="0.1" value="4"></label>
<label class="field">Conductor temp (°C)<input id="conductorTemperatureC" type="number" step="1" value="70"></label>
</section>
<section><h2>Voltage and operating point</h2>
<label class="field">Module Voc STC (V)<input id="moduleVocStcV" type="number" step="0.1" value="50"></label>
<label class="field">Voc coefficient (%/°C)<input id="vocTempCoefficientPercentPerC" type="number" step="0.01" value="-0.24"></label>
<label class="field">Minimum cell temp (°C)<input id="cellTemperatureC" type="number" step="1" value="20"></label>
<label class="field">System limit (V)<input id="systemVoltageLimitV" type="number" step="1" value="1500"></label>
<label class="field">Operating current (A)<input id="operatingCurrentA" type="number" step="0.01" value="17.31"></label>
</section>
</form>
</aside>
<article>
<section><h2>Engine status</h2><p id="engineStatus" class="status">Starting…</p><div class="report-actions"><button id="downloadReport" class="primary" type="button">Download computation report JSON</button><button id="downloadTests" type="button">Download test report JSON</button></div></section>
<section><h2>Computed block</h2><dl id="summary"></dl></section>
<section><h2>Warnings and assumptions</h2><div id="warnings"></div></section>
<section><h2>Deterministic tests</h2><table><thead><tr><th>Test</th><th>Status</th><th>Detail</th></tr></thead><tbody id="tests"></tbody></table></section>
<section><h2>Selected string segment report</h2><label class="field">String<select id="selectedString"></select></label><pre id="stringReport"></pre></section>
<section><h2>Canonical report preview</h2><pre id="reportPreview"></pre></section>
</article>
</main>
<script type="module" src="./app.js"></script>
</body>
</html>Schema
A JavaScript module in Solar Electrical Topology Analysis Engine Text Based that creates empty scene (`createEmptyScene`) and validates stable (`validateStableId`). Served with the page at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v9-sandbox/.
transformsolar-electrical-topology-analysis-engine-text-based / v9-sandbox/schema.js · lines 1–117 of 117 · Not reached from any entry point (candidate for review)
- What it does
- It calculates its inputs. Defines createEmptyScene, validateStableId, assertSceneShape.
- Why it exists in the grid workflow
- Domain stage experimental (path word 'sandbox'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. README: "`schema.js`: typed canonical stores, evidence classes, object types and segment types."
- What it achieves
- It creates empty scene (`createEmptyScene`) and validates stable id (`validateStableId`). The README says: Typed canonical stores, evidence classes, object types and segment types.
- Why it matters
- No other file in the estate was found to import it.
- Application
- solar-electrical-topology-analysis-engine-text-based · v9-sandbox · JavaScript module
- Uses
- none found
- Used by
- none found
- Produces
- V9_SCHEMA_VERSION, EVIDENCE_CLASSES, OBJECT_TYPES, SEGMENT_TYPES, createEmptyScene, validateStableId, assertSceneShape
- Defines here
- createEmptyScene, validateStableId, assertSceneShape
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- solar-electrical-topology-analysis-engine-text-based@d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9 v9-sandbox/schema.js:1-117 · blob 4ddca460879c2260b400ccb460c6725b2fcd867c · GitHub at these lines
- State
- achieves: readme · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: unreached_review
export const V9_SCHEMA_VERSION = "v9-scene-0.1.0";
export const EVIDENCE_CLASSES = Object.freeze([
"measured",
"declared",
"derived",
"assumed",
"defaulted",
"research-model",
"measurement-required",
]);
export const OBJECT_TYPES = Object.freeze([
"site",
"block",
"cartridge-instance",
"table",
"face",
"tracker",
"module",
"junction-box",
"connector",
"terminal",
"cable-anchor",
"conductor",
"segment",
"coil",
"route-environment",
"frame",
"rail",
"pile",
"earth-node",
"spd",
"combiner",
"mppt",
"inverter",
"assumption",
"measurement",
"study-run",
"result",
"warning",
]);
export const SEGMENT_TYPES = Object.freeze([
"module-interconnect",
"factory-lead",
"extension-lead",
"coil",
"along-rank",
"across-table",
"structure-drop",
"trench",
"termination",
"device",
"bonding",
"earth-return",
]);
export function createEmptyScene() {
return {
schemaVersion: V9_SCHEMA_VERSION,
id: "site-0001",
units: {
length: "m",
area: "m2",
resistance: "ohm",
inductance: "H",
capacitance: "F",
mass: "kg",
},
objects: [],
geometries: [],
terminals: [],
connectivity: [],
segments: [],
materials: [],
environments: [],
assumptions: [],
measurements: [],
studyRuns: [],
studyResults: [],
warnings: [],
};
}
export function validateStableId(id) {
return typeof id === "string" && /^[a-z0-9][a-z0-9-]*$/.test(id);
}
export function assertSceneShape(scene) {
if (!scene || scene.schemaVersion !== V9_SCHEMA_VERSION) {
throw new Error("Scene does not use the current V9 schema version.");
}
const stores = [
"objects",
"geometries",
"terminals",
"connectivity",
"segments",
"materials",
"environments",
"assumptions",
"measurements",
"studyRuns",
"studyResults",
"warnings",
];
stores.forEach((store) => {
if (!Array.isArray(scene[store])) {
throw new Error(`Scene store ${store} must be an array.`);
}
});
return true;
}State
A JavaScript module in Solar Electrical Topology Analysis Engine Text Based that works with stable serialise (`stableSerialise`). Served with the page at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v9-sandbox/.
transformsolar-electrical-topology-analysis-engine-text-based / v9-sandbox/state.js · lines 1–100 of 100 · Not reached from any entry point (candidate for review) · pattern commit (shared by 8 files)
- What it does
- It calculates its inputs. Defines clone, stableSerialise, createStateStore, notify, commit.
- Why it exists in the grid workflow
- Domain stage experimental (path word 'sandbox'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. README: "`state.js`: deterministic state, bounded history, undo, redo and stable serialisation."
- What it achieves
- It creates state store (`createStateStore`) and is built from the clone step (`clone`) and the stable serialise helper (`stableSerialise`). The README says: Deterministic state, bounded history, undo, redo and stable serialisation.
- Why it matters
- No other file in the estate was found to import it.
- Application
- solar-electrical-topology-analysis-engine-text-based · v9-sandbox · JavaScript module
- Uses
- none found
- Used by
- none found
- Produces
- createStateStore
- Defines here
- clone, stableSerialise, createStateStore, notify, commit
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- solar-electrical-topology-analysis-engine-text-based@d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9 v9-sandbox/state.js:1-100 · blob 5d6b97d1bdb2345e30e4b84432674d1e063149f6 · GitHub at these lines
- State
- achieves: readme · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: unreached_review
function clone(value) {
return structuredClone(value);
}
function stableSerialise(value) {
if (Array.isArray(value)) {
return `[${value.map(stableSerialise).join(",")}]`;
}
if (value && typeof value === "object") {
const entries = Object.keys(value)
.sort()
.map((key) => `${JSON.stringify(key)}:${stableSerialise(value[key])}`);
return `{${entries.join(",")}}`;
}
return JSON.stringify(value);
}
export function createStateStore(initialScene, maximumHistory = 100) {
let present = clone(initialScene);
let past = [];
let future = [];
const listeners = new Set();
function notify() {
const snapshot = clone(present);
listeners.forEach((listener) => listener(snapshot));
}
function commit(nextScene) {
const next = clone(nextScene);
if (stableSerialise(next) === stableSerialise(present)) {
return false;
}
past.push(clone(present));
if (past.length > maximumHistory) {
past = past.slice(past.length - maximumHistory);
}
present = next;
future = [];
notify();
return true;
}
return {
getScene() {
return clone(present);
},
getHistoryStatus() {
return {
canUndo: past.length > 0,
canRedo: future.length > 0,
undoDepth: past.length,
redoDepth: future.length,
};
},
commit,
update(mutator) {
const draft = clone(present);
mutator(draft);
return commit(draft);
},
undo() {
if (past.length === 0) {
return false;
}
future.unshift(clone(present));
present = past.pop();
notify();
return true;
},
redo() {
if (future.length === 0) {
return false;
}
past.push(clone(present));
present = future.shift();
notify();
return true;
},
subscribe(listener) {
listeners.add(listener);
return () => listeners.delete(listener);
},
serialise() {
return stableSerialise(present);
},
};
}
export { stableSerialise };Contract
A JavaScript module in the create folder of Star Solar Star that prepares definition (`prepareDefinition`), using SHA-256.
transformstar-solar-star / create/contract.js · lines 1–43 of 43 · Entry point · pattern canonical (shared by 28 files)
- What it does
- It calculates its inputs. Defines validString, canonical, observationBytes, prepareDefinition.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (repository name word 'solar'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary.
- Downstream impact
- Used directly by 1 file: Star Solar Star — Create Page (star-solar-star).
- What it achieves
- It prepares definition (`prepareDefinition`) and is built from the valid string helper (`validString`) and the canonical step (`canonical`). RFC 8785 JSON Canonicalization Scheme with an application safe-integer domain.
- Why it matters
- Loaded by the Create page.
- Application
- star-solar-star · create · JavaScript module
- Uses
- none found
- Used by
- imported by Star Solar Star — Create Page (import)
- Produces
- CANONICALIZATION, canonical, observationBytes, prepareDefinition
- Defines here
- validString, canonical, observationBytes, prepareDefinition
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- star-solar-star@4ac16c0c2297c4b6022afc4d6f921faf091bb74e create/contract.js:1-43 · blob 603e3dc795a4264fe770d7dccd21af494b9fecef · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: unknown
// RFC 8785 JSON Canonicalization Scheme with an application safe-integer domain.
// Observation arrays are ordered by key using UTF-16 code units, separately from JCS.
export const CANONICALIZATION = 'RFC8785-JCS; observations sorted by UTF-16 key; safe integers; v2';
function validString(value) {
if (!value.isWellFormed()) throw new Error('Strings must not contain unpaired surrogates.');
return JSON.stringify(value);
}
export function canonical(value) {
if (value === null || typeof value === 'boolean') return JSON.stringify(value);
if (typeof value === 'string') return validString(value);
if (typeof value === 'number') {
if (!Number.isFinite(value)) throw new Error('Numbers must be finite.');
if (Number.isInteger(value) && !Number.isSafeInteger(value)) throw new Error('Integer values must be within the safe integer domain.');
return JSON.stringify(value);
}
if (Array.isArray(value)) return '[' + value.map(canonical).join(',') + ']';
if (typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype) {
return '{' + Object.keys(value).sort().map(key => validString(key) + ':' + canonical(value[key])).join(',') + '}';
}
throw new Error('Only JSON values are supported.');
}
export function observationBytes(observations) {
const keys = new Set();
for (const row of observations) {
if (!row || typeof row.key !== 'string' || !row.key || keys.has(row.key)) throw new Error('Observation keys must be nonempty and unique.');
if (typeof row.value !== 'number' || !Number.isFinite(row.value)) throw new Error('Observation values must be finite numbers.');
keys.add(row.key);
}
return canonical([...observations].sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
}
export async function prepareDefinition(value) {
if (!Array.isArray(value.sources) || !value.sources.length) throw new Error('Add at least one public source with complete provenance.');
if (!Array.isArray(value.observations) || !value.observations.length) throw new Error('Add at least one source-linked observation.');
const bytes = new TextEncoder().encode(observationBytes(value.observations));
const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', bytes));
const seed = Array.from(digest, b => b.toString(16).padStart(2, '0')).join('');
return {...value, seed: {algorithm:'sha256', canonicalization:CANONICALIZATION,
inputs:value.observations.map(row => row.key).sort(), url_parameter:'seed', value:seed}};
}Star Solar Star — Create Page
A web page that reads inputs for editor, using ISO 3166-1 and SHA-256.
renderstar-solar-star / create/index.html · lines 1–53 of 53 · Entry point
- What it does
- It draws its content. Side effects: changes the web page (DOM).
- Why it exists in the grid workflow
- Domain stage sub33kv_design (repository name word 'solar'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary.
- Inputs & outputs
- In: form fields (user input). Out: web page.
- Downstream impact
- It is itself an entry point (page); no other file was found loading it.
- What it achieves
- Its name says it creates page. It responds to click events.
- Why it matters
- No other file in the estate was found to import it; it is an entry point.
- Application
- star-solar-star · create · page
- Uses
- Contract (import)
- Used by
- none found
- Produces
- none declared
- Defines here
- none
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- star-solar-star@4ac16c0c2297c4b6022afc4d6f921faf091bb74e create/index.html:1-53 · blob ac3fde795fe22de44f5b841713ee8f0d0a3a1a17 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: unknown
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Create a solar star definition</title>
<style>
:root { color-scheme: dark; --space:#07131f; --panel:#10263a; --line:#2d6f88; --text:#f2f7fa; --muted:#a8bdc8; --solar:#e7b84b; --data:#44b7c8; }
* { box-sizing:border-box; }
html,body { margin:0; min-width:0; background:var(--space); color:var(--text); font:16px/1.5 system-ui,sans-serif; }
main { width:min(100%,54rem); margin:0 auto; padding:1rem; overflow-wrap:anywhere; }
h1 { font-size:clamp(1.55rem,7vw,2.4rem); line-height:1.1; margin:.4rem 0; }
p { color:var(--muted); }
.panel { background:var(--panel); border:1px solid var(--line); border-radius:1rem; padding:1rem; }
textarea { display:block; width:100%; min-height:27rem; resize:vertical; border:1px solid var(--line); border-radius:.75rem; padding:.8rem; background:#06101a; color:var(--text); font:13px/1.45 ui-monospace,monospace; }
.actions { display:grid; grid-template-columns:repeat(auto-fit,minmax(11rem,1fr)); gap:.65rem; margin-top:.8rem; }
button,a.button { min-height:48px; display:flex; align-items:center; justify-content:center; border:1px solid var(--line); border-radius:.75rem; padding:.7rem 1rem; background:#15364d; color:var(--text); font:inherit; text-decoration:none; cursor:pointer; }
button.primary { border-color:var(--solar); color:#fff5d3; }
output { display:block; min-height:3rem; margin-top:.8rem; padding:.75rem; border-left:4px solid var(--data); background:#091a27; }
code { color:#9ce4ed; }
@media (max-width:430px) { main { padding:.75rem; } .panel { padding:.75rem; } textarea { min-height:22rem; } }
</style>
</head>
<body>
<main>
<h1>Create a solar star definition</h1>
<p>A star is a small, source-bound JSON record. Enter only public observations. Each number needs a dated HTTPS source, byte count, SHA-256, access time and source locator. Source observations stay separate; the creator does not average them.</p>
<section class="panel" aria-labelledby="editor-label">
<h2 id="editor-label">Definition JSON</h2>
<textarea id="editor" spellcheck="false" aria-describedby="help"></textarea>
<p id="help">Country records use ISO 3166-1 alpha-2. The world record uses UN M49 <code>001</code>. Prepare uses the v2 seed contract and puts the encoded definition in this page's URL. To prepare a new version of a published record, choose a new ID; published records are immutable.</p>
<div class="actions">
<button id="prepare" class="primary" type="button">Prepare definition</button>
<button id="copy" type="button">Copy encoded URL</button>
<a id="issue" class="button" href="https://github.com/Ventusltd/star-solar-star/issues/new">Open proposal issue</a>
</div>
<output id="status" role="status" aria-live="polite">Ready for a public, sourced definition.</output>
</section>
</main>
<script type="module">
import {CANONICALIZATION, prepareDefinition} from './contract.js';
const editor=document.querySelector('#editor'),status=document.querySelector('#status'),issue=document.querySelector('#issue');
const template={schema:'star-solar-star.definition.v1',id:'replace-with-stable-id',type:'country-solar',name:'Replace with public name',description:'Replace with a neutral description of the public observations.',region:{scheme:'ISO_3166-1_alpha-2',code:'GB',name:'United Kingdom'},sources:[],observations:[],seed:{algorithm:'sha256',canonicalization:CANONICALIZATION,inputs:[],url_parameter:'seed',v … [line shortened here: 422 characters; full line on GitHub]
const fromUrl=new URL(location.href).searchParams.get('star');
if(fromUrl){try{editor.value=JSON.stringify(JSON.parse(fromUrl),null,2)}catch(error){editor.value=JSON.stringify(template,null,2);status.textContent='The URL definition could not be decoded.'}}else editor.value=JSON.stringify(template,null,2);
async function prepare(){try{const value=await prepareDefinition(JSON.parse(editor.value));editor.value=JSON.stringify(value,null,2);const encoded=encodeURIComponent(JSON.stringify(value));const page=new URL(location.href);page.search='?star='+encoded;history.replaceState(null,'',page);const body='### Star JSON\n```json\n'+JSON.stringify(value,null,2)+'\n```';issue.href='https://github.com/Ventusl … [line shortened here: 734 characters; full line on GitHub]
document.querySelector('#prepare').addEventListener('click',prepare);
document.querySelector('#copy').addEventListener('click',async()=>{if(!await prepare())return;try{await navigator.clipboard.writeText(location.href);status.textContent='Encoded URL copied.'}catch(error){status.textContent='Copy was unavailable; select the browser URL.'}});
</script>
</body>
</html>