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.
145 lines
4.8 KiB
JavaScript
145 lines
4.8 KiB
JavaScript
import { stringifyCollection } from '../stringify/stringifyCollection.js';
|
|
import { addPairToJSMap } from './addPairToJSMap.js';
|
|
import { Collection } from './Collection.js';
|
|
import { MAP, isPair, isScalar } from './identity.js';
|
|
import { Pair, createPair } from './Pair.js';
|
|
import { isScalarValue } from './Scalar.js';
|
|
|
|
function findPair(items, key) {
|
|
const k = isScalar(key) ? key.value : key;
|
|
for (const it of items) {
|
|
if (isPair(it)) {
|
|
if (it.key === key || it.key === k)
|
|
return it;
|
|
if (isScalar(it.key) && it.key.value === k)
|
|
return it;
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|
|
class YAMLMap extends Collection {
|
|
static get tagName() {
|
|
return 'tag:yaml.org,2002:map';
|
|
}
|
|
constructor(schema) {
|
|
super(MAP, schema);
|
|
this.items = [];
|
|
}
|
|
/**
|
|
* A generic collection parsing method that can be extended
|
|
* to other node classes that inherit from YAMLMap
|
|
*/
|
|
static from(schema, obj, ctx) {
|
|
const { keepUndefined, replacer } = ctx;
|
|
const map = new this(schema);
|
|
const add = (key, value) => {
|
|
if (typeof replacer === 'function')
|
|
value = replacer.call(obj, key, value);
|
|
else if (Array.isArray(replacer) && !replacer.includes(key))
|
|
return;
|
|
if (value !== undefined || keepUndefined)
|
|
map.items.push(createPair(key, value, ctx));
|
|
};
|
|
if (obj instanceof Map) {
|
|
for (const [key, value] of obj)
|
|
add(key, value);
|
|
}
|
|
else if (obj && typeof obj === 'object') {
|
|
for (const key of Object.keys(obj))
|
|
add(key, obj[key]);
|
|
}
|
|
if (typeof schema.sortMapEntries === 'function') {
|
|
map.items.sort(schema.sortMapEntries);
|
|
}
|
|
return map;
|
|
}
|
|
/**
|
|
* Adds a value to the collection.
|
|
*
|
|
* @param overwrite - If not set `true`, using a key that is already in the
|
|
* collection will throw. Otherwise, overwrites the previous value.
|
|
*/
|
|
add(pair, overwrite) {
|
|
let _pair;
|
|
if (isPair(pair))
|
|
_pair = pair;
|
|
else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
|
|
// In TypeScript, this never happens.
|
|
_pair = new Pair(pair, pair?.value);
|
|
}
|
|
else
|
|
_pair = new Pair(pair.key, pair.value);
|
|
const prev = findPair(this.items, _pair.key);
|
|
const sortEntries = this.schema?.sortMapEntries;
|
|
if (prev) {
|
|
if (!overwrite)
|
|
throw new Error(`Key ${_pair.key} already set`);
|
|
// For scalars, keep the old node & its comments and anchors
|
|
if (isScalar(prev.value) && isScalarValue(_pair.value))
|
|
prev.value.value = _pair.value;
|
|
else
|
|
prev.value = _pair.value;
|
|
}
|
|
else if (sortEntries) {
|
|
const i = this.items.findIndex(item => sortEntries(_pair, item) < 0);
|
|
if (i === -1)
|
|
this.items.push(_pair);
|
|
else
|
|
this.items.splice(i, 0, _pair);
|
|
}
|
|
else {
|
|
this.items.push(_pair);
|
|
}
|
|
}
|
|
delete(key) {
|
|
const it = findPair(this.items, key);
|
|
if (!it)
|
|
return false;
|
|
const del = this.items.splice(this.items.indexOf(it), 1);
|
|
return del.length > 0;
|
|
}
|
|
get(key, keepScalar) {
|
|
const it = findPair(this.items, key);
|
|
const node = it?.value;
|
|
return (!keepScalar && isScalar(node) ? node.value : node) ?? undefined;
|
|
}
|
|
has(key) {
|
|
return !!findPair(this.items, key);
|
|
}
|
|
set(key, value) {
|
|
this.add(new Pair(key, value), true);
|
|
}
|
|
/**
|
|
* @param ctx - Conversion context, originally set in Document#toJS()
|
|
* @param {Class} Type - If set, forces the returned collection type
|
|
* @returns Instance of Type, Map, or Object
|
|
*/
|
|
toJSON(_, ctx, Type) {
|
|
const map = Type ? new Type() : ctx?.mapAsMap ? new Map() : {};
|
|
if (ctx?.onCreate)
|
|
ctx.onCreate(map);
|
|
for (const item of this.items)
|
|
addPairToJSMap(ctx, map, item);
|
|
return map;
|
|
}
|
|
toString(ctx, onComment, onChompKeep) {
|
|
if (!ctx)
|
|
return JSON.stringify(this);
|
|
for (const item of this.items) {
|
|
if (!isPair(item))
|
|
throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
|
|
}
|
|
if (!ctx.allNullValues && this.hasAllNullValues(false))
|
|
ctx = Object.assign({}, ctx, { allNullValues: true });
|
|
return stringifyCollection(this, ctx, {
|
|
blockItemPrefix: '',
|
|
flowChars: { start: '{', end: '}' },
|
|
itemIndent: ctx.indent || '',
|
|
onChompKeep,
|
|
onComment
|
|
});
|
|
}
|
|
}
|
|
|
|
export { YAMLMap, findPair };
|