Problem: the hexagonal refactor churns the backend tree for nine more phases; the UI delivery stack (web/ SPA, cmd/desktop Wails wrapper, compose/web image) must move to its own repo first so doc/layout rewrites land once on a backend-only tree. Change: - New repo git.hubris.network/dtoro/oikos-web (v0.33.0): web/, desktop/ (updateURL repointed to oikos-web releases), compose/, own CI (web + desktop jobs), own deploy script (CI-green gate, TOCTOU guard, version-tagged images, prune-to-3), own webhook receiver on :9798 + launchd unit, own compose project publishing the same 8091:80. - Cutover executed on mac-mini in order: oikos stack's web service stopped+removed, oikos-web project brought up on 8091; outer Caddy untouched (targets the published port) — serving + Authentik flow + /wails 404 quirk verified post-cutover. - Stripped from oikos: web/, cmd/desktop/, compose/web/, desktop CI workflow, ci.yml web job, Makefile ui/desktop/desktop-package/install targets, the compose web service, oikos-web from deploy.sh's fallback prune list; wails + go-keyring dropped from go.mod, vendor synced. - README / CONTRIBUTING / AGENTS.md / .agents dev+operations docs now point at the new repo; mbse + mascot design docs carry a path note. Risk: production SPA serving depends on the new pipeline now; rollback is versioned-image re-up of the old web service from a pre-split checkout (port 8091). Desktop builds installed before the split still check dtoro/oikos releases — one manual reinstall, noted in the oikos-web release notes. Verification: go vet, make test (race), make generate-check, golangci (no new findings; baseline down 400→365); post-cutover curls — localhost:8091 200, /wails/runtime.js 404, outer Caddy 302 Authentik.
169 lines
3.6 KiB
JavaScript
169 lines
3.6 KiB
JavaScript
/** @import { Context, Visitor, Visitors } from './types.js' */
|
|
|
|
/**
|
|
* @template {{ type: string }} T
|
|
* @template {Record<string, any> | null} U
|
|
* @param {T} node
|
|
* @param {U} state
|
|
* @param {Visitors<T, U>} visitors
|
|
*/
|
|
export function walk(node, state, visitors) {
|
|
const universal = visitors._;
|
|
|
|
let stopped = false;
|
|
|
|
/** @type {Visitor<T, U, T>} _ */
|
|
function default_visitor(_, { next, state }) {
|
|
next(state);
|
|
}
|
|
|
|
/**
|
|
* @param {T} node
|
|
* @param {T[]} path
|
|
* @param {U} state
|
|
* @returns {T | undefined}
|
|
*/
|
|
function visit(node, path, state) {
|
|
// Don't return the node here or it could lead to false-positive mutation detection
|
|
if (stopped) return;
|
|
if (!node.type) return;
|
|
|
|
/** @type {T | void} */
|
|
let result;
|
|
|
|
/** @type {Record<string, any>} */
|
|
const mutations = {};
|
|
|
|
/** @type {Context<T, U>} */
|
|
const context = {
|
|
path,
|
|
state,
|
|
next: (next_state = state) => {
|
|
path.push(node);
|
|
for (const key in node) {
|
|
if (key === 'type') continue;
|
|
|
|
const child_node = node[key];
|
|
if (child_node && typeof child_node === 'object') {
|
|
if (Array.isArray(child_node)) {
|
|
/** @type {Record<number, T>} */
|
|
const array_mutations = {};
|
|
const len = child_node.length;
|
|
|
|
let mutated = false;
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
const node = child_node[i];
|
|
if (node && typeof node === 'object') {
|
|
const result = visit(node, path, next_state);
|
|
if (result) {
|
|
array_mutations[i] = result;
|
|
mutated = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (mutated) {
|
|
mutations[key] = child_node.map(
|
|
(node, i) => array_mutations[i] ?? node
|
|
);
|
|
}
|
|
} else {
|
|
const result = visit(
|
|
/** @type {T} */ (child_node),
|
|
path,
|
|
next_state
|
|
);
|
|
|
|
// @ts-ignore
|
|
if (result) {
|
|
mutations[key] = result;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
path.pop();
|
|
|
|
if (Object.keys(mutations).length > 0) {
|
|
return apply_mutations(node, mutations);
|
|
}
|
|
},
|
|
stop: () => {
|
|
stopped = true;
|
|
},
|
|
visit: (next_node, next_state = state) => {
|
|
path.push(node);
|
|
const result = visit(next_node, path, next_state) ?? next_node;
|
|
path.pop();
|
|
return result;
|
|
}
|
|
};
|
|
|
|
let visitor = /** @type {Visitor<T, U, T>} */ (
|
|
visitors[/** @type {T['type']} */ (node.type)] ?? default_visitor
|
|
);
|
|
|
|
if (universal) {
|
|
/** @type {T | void} */
|
|
let inner_result;
|
|
|
|
result = universal(node, {
|
|
...context,
|
|
/** @param {U} next_state */
|
|
next: (next_state = state) => {
|
|
state = next_state; // make it the default for subsequent specialised visitors
|
|
|
|
inner_result = visitor(node, {
|
|
...context,
|
|
state: next_state
|
|
});
|
|
|
|
return inner_result;
|
|
}
|
|
});
|
|
|
|
// @ts-expect-error TypeScript doesn't understand that `context.next(...)` is called immediately
|
|
if (!result && inner_result) {
|
|
result = inner_result;
|
|
}
|
|
} else {
|
|
result = visitor(node, context);
|
|
}
|
|
|
|
if (!result) {
|
|
if (Object.keys(mutations).length > 0) {
|
|
result = apply_mutations(node, mutations);
|
|
}
|
|
}
|
|
|
|
if (result) {
|
|
return result;
|
|
}
|
|
}
|
|
|
|
return visit(node, [], state) ?? node;
|
|
}
|
|
|
|
/**
|
|
* @template {Record<string, any>} T
|
|
* @param {T} node
|
|
* @param {Record<string, any>} mutations
|
|
* @returns {T}
|
|
*/
|
|
function apply_mutations(node, mutations) {
|
|
/** @type {Record<string, any>} */
|
|
const obj = {};
|
|
|
|
const descriptors = Object.getOwnPropertyDescriptors(node);
|
|
|
|
for (const key in descriptors) {
|
|
Object.defineProperty(obj, key, descriptors[key]);
|
|
}
|
|
|
|
for (const key in mutations) {
|
|
obj[key] = mutations[key];
|
|
}
|
|
|
|
return /** @type {T} */ (obj);
|
|
}
|