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.
275 lines
6.4 KiB
Markdown
275 lines
6.4 KiB
Markdown
# Graphology Utils
|
|
|
|
Miscellaneous utility functions to be used with [`graphology`](https://graphology.github.io).
|
|
|
|
## Installation
|
|
|
|
```
|
|
npm install graphology-utils
|
|
```
|
|
|
|
## Usage
|
|
|
|
_Assertions_
|
|
|
|
- [#.isGraph](#isgraph)
|
|
- [#.isGraphConstructor](#isgraphconstructor)
|
|
|
|
_Introspection_
|
|
|
|
- [#.inferMulti](#infermulti)
|
|
- [#.inferType](#infertype)
|
|
|
|
_Typical edge patterns_
|
|
|
|
- [#.mergeClique](#mergeclique)
|
|
- [#.mergeCycle](#mergecycle)
|
|
- [#.mergePath](#mergepath)
|
|
- [#.mergeStar](#mergestar)
|
|
|
|
_Miscellaneous helpers_
|
|
|
|
- [#.renameGraphKeys](#renamegraphkeys)
|
|
- [#.updateGraphKeys](#updategraphkeys)
|
|
|
|
### #.isGraph
|
|
|
|
Function returning whether the given value is a `graphology` implementation's instance.
|
|
|
|
```js
|
|
import {isGraph} from 'graphology-utils';
|
|
// Alternatively, if you want to only load the relevant code:
|
|
import isGraph from 'graphology-utils/is-graph';
|
|
|
|
const graph = new Graph();
|
|
|
|
isGraph(graph);
|
|
>>> true
|
|
|
|
isGraph(45);
|
|
>>> false
|
|
|
|
isGraph({hello: 'world'});
|
|
>>> false
|
|
```
|
|
|
|
_Arguments_
|
|
|
|
- **value** _any_: value to test.
|
|
|
|
### #.isGraphConstructor
|
|
|
|
Function returning whether the given value is a `graphology` constructor.
|
|
|
|
```js
|
|
import {isGraphConstructor} from 'graphology-utils';
|
|
// Alternatively, if you want to only load the relevant code:
|
|
import isGraphConstructor from 'graphology-utils/is-graph-constructor';
|
|
|
|
isGraphConstructor(Graph);
|
|
>>> true
|
|
|
|
isGraphConstructor(45);
|
|
>>> false
|
|
|
|
isGraphConstructor(new Graph());
|
|
>>> false
|
|
```
|
|
|
|
_Arguments_
|
|
|
|
- **value** _any_: value to test.
|
|
|
|
### #.inferMulti
|
|
|
|
Function returning whether the given graph is truly multi, i.e. if we can find at least one occurrence of multiple edges of the same type and direction between two nodes.
|
|
|
|
```js
|
|
import {inferMulti} from 'graphology-utils';
|
|
// Alternatively, if you want to only load the relevant code:
|
|
import inferMulti from 'graphology-utils/infer-multi';
|
|
|
|
const graph = new MultiGraph();
|
|
graph.addEdge(1, 2);
|
|
|
|
inferMulti(graph);
|
|
>>> false
|
|
|
|
graph.addEdge(1, 2);
|
|
|
|
inferMulti(graph);
|
|
>>> true
|
|
```
|
|
|
|
### #.inferType
|
|
|
|
Function returning the inferred type of the given graph. This function is useful to check whether a given mixed graph is in fact a mere `directed` or `undirected` graph based on its actual edges.
|
|
|
|
```js
|
|
import {inferType} from 'graphology-utils';
|
|
// Alternatively, if you want to only load the relevant code:
|
|
import inferType from 'graphology-utils/infer-type';
|
|
|
|
const graph = new Graph();
|
|
graph.addUndirectedEdge(1, 2);
|
|
|
|
inferType(graph);
|
|
>>> 'directed'
|
|
```
|
|
|
|
### #.mergeClique
|
|
|
|
Function adding a clique to the given graph.
|
|
|
|
```js
|
|
import {mergeClique} from 'graphology-utils';
|
|
// Alternatively, if you want to only load the relevant code:
|
|
import mergeClique from 'graphology-utils/merge-clique';
|
|
|
|
const graph = new Graph();
|
|
|
|
mergeClique(graph, [1, 2, 3]);
|
|
graph.edges().map(e => graph.extremities(e));
|
|
>>> [[1, 2], [1, 3], [2, 3]]
|
|
```
|
|
|
|
### #.mergeCycle
|
|
|
|
Function adding a cycle to the given graph.
|
|
|
|
```js
|
|
import {mergeCycle} from 'graphology-utils';
|
|
// Alternatively, if you want to only load the relevant code:
|
|
import mergeCycle from 'graphology-utils/merge-cycle';
|
|
|
|
const graph = new Graph();
|
|
|
|
mergeCycle(graph, [1, 2, 3, 4, 5]);
|
|
graph.edges().map(e => graph.extremities(e));
|
|
>>> [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]
|
|
```
|
|
|
|
_Arguments_
|
|
|
|
- **graph** _Graph_: target graph.
|
|
- **cycle** _array_: array of nodes representing the cycle to add.
|
|
|
|
### #.mergePath
|
|
|
|
Function adding a path to the given graph.
|
|
|
|
```js
|
|
import {mergePath} from 'graphology-utils';
|
|
// Alternatively, if you want to only load the relevant code:
|
|
import mergePath from 'graphology-utils/merge-path';
|
|
|
|
const graph = new Graph();
|
|
|
|
mergePath(graph, [1, 2, 3, 4, 5]);
|
|
graph.edges().map(e => graph.extremities(e));
|
|
>>> [[1, 2], [2, 3], [3, 4], [4, 5]]
|
|
```
|
|
|
|
_Arguments_
|
|
|
|
- **graph** _Graph_: target graph.
|
|
- **path** _array_: array of nodes representing the path to add.
|
|
|
|
### #.mergeStar
|
|
|
|
Function adding a star to the given graph.
|
|
|
|
```js
|
|
import {mergeStar} from 'graphology-utils';
|
|
// Alternatively, if you want to only load the relevant code:
|
|
import mergeStar from 'graphology-utils/merge-star';
|
|
|
|
const graph = new Graph();
|
|
|
|
mergeStar(graph, [1, 2, 3, 4, 5]);
|
|
graph.edges().map(e => graph.extremities(e));
|
|
>>> [[1, 2], [1, 3], [1, 4], [1, 5]]
|
|
```
|
|
|
|
_Arguments_
|
|
|
|
- **graph** _Graph_: target graph.
|
|
- **star** _array_: array of nodes representing the star to add.
|
|
|
|
### #.renameGraphKeys
|
|
|
|
Function renaming the nodes & edges key of a graph using mappings and returning a new graph with renamed keys.
|
|
|
|
```js
|
|
import {renameGraphKeys} from 'graphology-utils';
|
|
// Alternatively, if you want to only load the relevant code:
|
|
import renameGraphKeys from 'graphology-utils/rename-graph-keys';
|
|
|
|
const graph = new Graph();
|
|
graph.addNode('Martha');
|
|
graph.addNode('Catherine');
|
|
graph.addNode('John');
|
|
graph.addEdgeWithKey('M->C', 'Martha', 'Catherine');
|
|
graph.addEdgeWithKey('C->J', 'Catherine', 'John');
|
|
|
|
const renamedGraph = renameGraphKeys(
|
|
graph,
|
|
{Martha: 1, Catherine: 2, John: 3},
|
|
{'M->C': 'rel1', 'C->J': 'rel2'}
|
|
);
|
|
|
|
renamedGraph.nodes();
|
|
>>> [1, 2, 3];
|
|
|
|
renamedGraph.edges();
|
|
>>> ['rel1', 'rel2'];
|
|
```
|
|
|
|
_Arguments_
|
|
|
|
- **graph** _Graph_: target graph.
|
|
- **nodeKeyMapping** _object_: A key/value map for the node key mapping.
|
|
- **edgeKeyMapping** _?object_: A key/value map for the edge key mapping.
|
|
|
|
### #.updateGraphKeys
|
|
|
|
Function updating the nodes & edges key of a graph using functions and returning a new graph with updated keys.
|
|
|
|
```js
|
|
import {updateGraphKeys} from 'graphology-utils';
|
|
// Alternatively, if you want to only load the relevant code:
|
|
import updateGraphKeys from 'graphology-utils/update-graph-keys';
|
|
|
|
const graph = new Graph();
|
|
graph.addNode('Martha');
|
|
graph.addNode('Catherine');
|
|
graph.addNode('John');
|
|
graph.addEdgeWithKey('M->C', 'Martha', 'Catherine');
|
|
graph.addEdgeWithKey('C->J', 'Catherine', 'John');
|
|
|
|
const updatedGraph = updateGraphKeys(
|
|
graph,
|
|
(key)=> {
|
|
if (key === 'Martha') return 1;
|
|
if (key === 'Catherine') return 2;
|
|
return 3;
|
|
},
|
|
(key) => {
|
|
if (key === 'M->C') return 'rel1';
|
|
return 'rel2';
|
|
}
|
|
);
|
|
|
|
updatedGraph.nodes();
|
|
>>> [1, 2, 3];
|
|
|
|
updatedGraph.edges();
|
|
>>> ['rel1', 'rel2'];
|
|
```
|
|
|
|
_Arguments_
|
|
|
|
- **graph** _Graph_: target graph.
|
|
- **nodeKeyUdater** _function_: A function to compute a new node key from the same arguments that would be given to [`#.forEachNode`](https://graphology.github.io/iteration.html#foreachnode).
|
|
- **edgeKeyUpdater** _function_: A function to compute a new edge key from the same arguments that would be given to [`#.forEachEdge`](https://graphology.github.io/iteration.html#foreachedge).
|