feat: Phase 1 — extract the client (web SPA + desktop) to dtoro/oikos-web
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.
This commit is contained in:
21
web/node_modules/graphology-utils/LICENSE.txt
generated
vendored
Normal file
21
web/node_modules/graphology-utils/LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017-2021 Guillaume Plique (Yomguithereal)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
274
web/node_modules/graphology-utils/README.md
generated
vendored
Normal file
274
web/node_modules/graphology-utils/README.md
generated
vendored
Normal file
@@ -0,0 +1,274 @@
|
||||
# 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).
|
||||
37
web/node_modules/graphology-utils/add-edge.d.ts
generated
vendored
Normal file
37
web/node_modules/graphology-utils/add-edge.d.ts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import Graph, {Attributes, EdgeMergeResult} from 'graphology-types';
|
||||
|
||||
export function addEdge<EdgeAttributes extends Attributes = Attributes>(
|
||||
graph: Graph,
|
||||
undirected: boolean,
|
||||
key: unknown,
|
||||
source: unknown,
|
||||
target: unknown,
|
||||
attributes?: EdgeAttributes
|
||||
): string;
|
||||
|
||||
export function copyEdge<EdgeAttributes extends Attributes = Attributes>(
|
||||
graph: Graph,
|
||||
undirected: boolean,
|
||||
key: unknown,
|
||||
source: unknown,
|
||||
target: unknown,
|
||||
attributes?: EdgeAttributes
|
||||
): string;
|
||||
|
||||
export function mergeEdge<EdgeAttributes extends Attributes = Attributes>(
|
||||
graph: Graph,
|
||||
undirected: boolean,
|
||||
key: unknown,
|
||||
source: unknown,
|
||||
target: unknown,
|
||||
attributes?: EdgeAttributes
|
||||
): EdgeMergeResult;
|
||||
|
||||
export function updateEdge<EdgeAttributes extends Attributes = Attributes>(
|
||||
graph: Graph,
|
||||
undirected: boolean,
|
||||
key: unknown,
|
||||
source: unknown,
|
||||
target: unknown,
|
||||
updater?: (attributes: EdgeAttributes | {}) => EdgeAttributes
|
||||
): EdgeMergeResult;
|
||||
85
web/node_modules/graphology-utils/add-edge.js
generated
vendored
Normal file
85
web/node_modules/graphology-utils/add-edge.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Graphology Edge Adders
|
||||
* =======================
|
||||
*
|
||||
* Generic edge addition functions that can be used to avoid nasty repetitive
|
||||
* conditions.
|
||||
*/
|
||||
exports.addEdge = function addEdge(
|
||||
graph,
|
||||
undirected,
|
||||
key,
|
||||
source,
|
||||
target,
|
||||
attributes
|
||||
) {
|
||||
if (undirected) {
|
||||
if (key === null || key === undefined)
|
||||
return graph.addUndirectedEdge(source, target, attributes);
|
||||
else return graph.addUndirectedEdgeWithKey(key, source, target, attributes);
|
||||
} else {
|
||||
if (key === null || key === undefined)
|
||||
return graph.addDirectedEdge(source, target, attributes);
|
||||
else return graph.addDirectedEdgeWithKey(key, source, target, attributes);
|
||||
}
|
||||
};
|
||||
|
||||
exports.copyEdge = function copyEdge(
|
||||
graph,
|
||||
undirected,
|
||||
key,
|
||||
source,
|
||||
target,
|
||||
attributes
|
||||
) {
|
||||
attributes = Object.assign({}, attributes);
|
||||
|
||||
if (undirected) {
|
||||
if (key === null || key === undefined)
|
||||
return graph.addUndirectedEdge(source, target, attributes);
|
||||
else return graph.addUndirectedEdgeWithKey(key, source, target, attributes);
|
||||
} else {
|
||||
if (key === null || key === undefined)
|
||||
return graph.addDirectedEdge(source, target, attributes);
|
||||
else return graph.addDirectedEdgeWithKey(key, source, target, attributes);
|
||||
}
|
||||
};
|
||||
|
||||
exports.mergeEdge = function mergeEdge(
|
||||
graph,
|
||||
undirected,
|
||||
key,
|
||||
source,
|
||||
target,
|
||||
attributes
|
||||
) {
|
||||
if (undirected) {
|
||||
if (key === null || key === undefined)
|
||||
return graph.mergeUndirectedEdge(source, target, attributes);
|
||||
else
|
||||
return graph.mergeUndirectedEdgeWithKey(key, source, target, attributes);
|
||||
} else {
|
||||
if (key === null || key === undefined)
|
||||
return graph.mergeDirectedEdge(source, target, attributes);
|
||||
else return graph.mergeDirectedEdgeWithKey(key, source, target, attributes);
|
||||
}
|
||||
};
|
||||
|
||||
exports.updateEdge = function updateEdge(
|
||||
graph,
|
||||
undirected,
|
||||
key,
|
||||
source,
|
||||
target,
|
||||
updater
|
||||
) {
|
||||
if (undirected) {
|
||||
if (key === null || key === undefined)
|
||||
return graph.updateUndirectedEdge(source, target, updater);
|
||||
else return graph.updateUndirectedEdgeWithKey(key, source, target, updater);
|
||||
} else {
|
||||
if (key === null || key === undefined)
|
||||
return graph.updateDirectedEdge(source, target, updater);
|
||||
else return graph.updateDirectedEdgeWithKey(key, source, target, updater);
|
||||
}
|
||||
};
|
||||
7
web/node_modules/graphology-utils/add-node.d.ts
generated
vendored
Normal file
7
web/node_modules/graphology-utils/add-node.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import Graph, {Attributes} from 'graphology-types';
|
||||
|
||||
export function copyNode<NodeAttributes extends Attributes = Attributes>(
|
||||
graph: Graph,
|
||||
key: unknown,
|
||||
attributes?: NodeAttributes
|
||||
): string;
|
||||
11
web/node_modules/graphology-utils/add-node.js
generated
vendored
Normal file
11
web/node_modules/graphology-utils/add-node.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Graphology Node Adders
|
||||
* =======================
|
||||
*
|
||||
* Generic node addition functions that can be used to avoid nasty repetitive
|
||||
* conditions.
|
||||
*/
|
||||
exports.copyNode = function (graph, key, attributes) {
|
||||
attributes = Object.assign({}, attributes);
|
||||
return graph.addNode(key, attributes);
|
||||
};
|
||||
4
web/node_modules/graphology-utils/defaults.d.ts
generated
vendored
Normal file
4
web/node_modules/graphology-utils/defaults.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export default function resolveDefaults<T extends {[key: string]: any}>(
|
||||
target: T | undefined | null,
|
||||
defaults: T
|
||||
): T;
|
||||
47
web/node_modules/graphology-utils/defaults.js
generated
vendored
Normal file
47
web/node_modules/graphology-utils/defaults.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Graphology Defaults
|
||||
* ====================
|
||||
*
|
||||
* Helper function used throughout the standard lib to resolve defaults.
|
||||
*/
|
||||
function isLeaf(o) {
|
||||
return (
|
||||
!o ||
|
||||
typeof o !== 'object' ||
|
||||
typeof o === 'function' ||
|
||||
Array.isArray(o) ||
|
||||
o instanceof Set ||
|
||||
o instanceof Map ||
|
||||
o instanceof RegExp ||
|
||||
o instanceof Date
|
||||
);
|
||||
}
|
||||
|
||||
function resolveDefaults(target, defaults) {
|
||||
target = target || {};
|
||||
|
||||
var output = {};
|
||||
|
||||
for (var k in defaults) {
|
||||
var existing = target[k];
|
||||
var def = defaults[k];
|
||||
|
||||
// Recursion
|
||||
if (!isLeaf(def)) {
|
||||
output[k] = resolveDefaults(existing, def);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Leaf
|
||||
if (existing === undefined) {
|
||||
output[k] = def;
|
||||
} else {
|
||||
output[k] = existing;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
module.exports = resolveDefaults;
|
||||
79
web/node_modules/graphology-utils/getters.d.ts
generated
vendored
Normal file
79
web/node_modules/graphology-utils/getters.d.ts
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
import Graph, {Attributes, NodeMapper, EdgeMapper} from 'graphology-types';
|
||||
|
||||
export type PartialEdgeMapper<
|
||||
T,
|
||||
EdgeAttributes extends Attributes = Attributes
|
||||
> = (
|
||||
edge: string,
|
||||
attributes: EdgeAttributes,
|
||||
source: string,
|
||||
target: string
|
||||
) => T;
|
||||
|
||||
export type MinimalEdgeMapper<
|
||||
T,
|
||||
EdgeAttributes extends Attributes = Attributes
|
||||
> = (edge: string, attributes: EdgeAttributes) => T;
|
||||
|
||||
interface NodeValueGetter<T, NodeAttributes extends Attributes = Attributes> {
|
||||
fromGraph(graph: Graph<NodeAttributes>, node: unknown): T;
|
||||
fromAttributes(attributes: NodeAttributes): T;
|
||||
fromEntry: NodeMapper<T, NodeAttributes>;
|
||||
}
|
||||
|
||||
interface EdgeValueGetter<
|
||||
T,
|
||||
NodeAttributes extends Attributes = Attributes,
|
||||
EdgeAttributes extends Attributes = Attributes
|
||||
> {
|
||||
fromGraph(graph: Graph<NodeAttributes, EdgeAttributes>, edge: unknown): T;
|
||||
// fromPath(
|
||||
// graph: Graph<NodeAttributes, EdgeAttributes>,
|
||||
// source: unknown,
|
||||
// target: unknown
|
||||
// ): T;
|
||||
// fromDirectedPath(
|
||||
// graph: Graph<NodeAttributes, EdgeAttributes>,
|
||||
// source: unknown,
|
||||
// target: unknown
|
||||
// ): T;
|
||||
// fromUndirectedPath(
|
||||
// graph: Graph<NodeAttributes, EdgeAttributes>,
|
||||
// source: unknown,
|
||||
// target: unknown
|
||||
// ): T;
|
||||
fromAttributes(attributes: EdgeAttributes): T;
|
||||
fromEntry: EdgeMapper<T, NodeAttributes, EdgeAttributes>;
|
||||
fromPartialEntry: PartialEdgeMapper<T, EdgeAttributes>;
|
||||
fromMinimalEntry: MinimalEdgeMapper<T, EdgeAttributes>;
|
||||
}
|
||||
|
||||
export function createNodeValueGetter<
|
||||
T,
|
||||
NodeAttributes extends Attributes = Attributes
|
||||
>(
|
||||
target?: string | NodeMapper<T, NodeAttributes>,
|
||||
defaultValue?: T | ((value: unknown) => T)
|
||||
): NodeValueGetter<T, NodeAttributes>;
|
||||
|
||||
export function createEdgeValueGetter<
|
||||
T,
|
||||
NodeAttributes extends Attributes = Attributes,
|
||||
EdgeAttributes extends Attributes = Attributes
|
||||
>(
|
||||
target?:
|
||||
| string
|
||||
| EdgeMapper<T, NodeAttributes, EdgeAttributes>
|
||||
| PartialEdgeMapper<T, EdgeAttributes>,
|
||||
defaultValue?: T | ((value: unknown) => T)
|
||||
): EdgeValueGetter<T, NodeAttributes, EdgeAttributes>;
|
||||
|
||||
export function createEdgeWeightGetter<
|
||||
NodeAttributes extends Attributes = Attributes,
|
||||
EdgeAttributes extends Attributes = Attributes
|
||||
>(
|
||||
target?:
|
||||
| string
|
||||
| EdgeMapper<number, NodeAttributes, EdgeAttributes>
|
||||
| PartialEdgeMapper<number, EdgeAttributes>
|
||||
): EdgeValueGetter<number, NodeAttributes, EdgeAttributes>;
|
||||
137
web/node_modules/graphology-utils/getters.js
generated
vendored
Normal file
137
web/node_modules/graphology-utils/getters.js
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Graphology Weight Getter
|
||||
* =========================
|
||||
*
|
||||
* Function creating weight getters.
|
||||
*/
|
||||
function coerceWeight(value) {
|
||||
// Ensuring target value is a correct number
|
||||
if (typeof value !== 'number' || isNaN(value)) return 1;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function createNodeValueGetter(nameOrFunction, defaultValue) {
|
||||
var getter = {};
|
||||
|
||||
var coerceToDefault = function (v) {
|
||||
if (typeof v === 'undefined') return defaultValue;
|
||||
|
||||
return v;
|
||||
};
|
||||
|
||||
if (typeof defaultValue === 'function') coerceToDefault = defaultValue;
|
||||
|
||||
var get = function (attributes) {
|
||||
return coerceToDefault(attributes[nameOrFunction]);
|
||||
};
|
||||
|
||||
var returnDefault = function () {
|
||||
return coerceToDefault(undefined);
|
||||
};
|
||||
|
||||
if (typeof nameOrFunction === 'string') {
|
||||
getter.fromAttributes = get;
|
||||
getter.fromGraph = function (graph, node) {
|
||||
return get(graph.getNodeAttributes(node));
|
||||
};
|
||||
getter.fromEntry = function (node, attributes) {
|
||||
return get(attributes);
|
||||
};
|
||||
} else if (typeof nameOrFunction === 'function') {
|
||||
getter.fromAttributes = function () {
|
||||
throw new Error(
|
||||
'graphology-utils/getters/createNodeValueGetter: irrelevant usage.'
|
||||
);
|
||||
};
|
||||
getter.fromGraph = function (graph, node) {
|
||||
return coerceToDefault(
|
||||
nameOrFunction(node, graph.getNodeAttributes(node))
|
||||
);
|
||||
};
|
||||
getter.fromEntry = function (node, attributes) {
|
||||
return coerceToDefault(nameOrFunction(node, attributes));
|
||||
};
|
||||
} else {
|
||||
getter.fromAttributes = returnDefault;
|
||||
getter.fromGraph = returnDefault;
|
||||
getter.fromEntry = returnDefault;
|
||||
}
|
||||
|
||||
return getter;
|
||||
}
|
||||
|
||||
function createEdgeValueGetter(nameOrFunction, defaultValue) {
|
||||
var getter = {};
|
||||
|
||||
var coerceToDefault = function (v) {
|
||||
if (typeof v === 'undefined') return defaultValue;
|
||||
|
||||
return v;
|
||||
};
|
||||
|
||||
if (typeof defaultValue === 'function') coerceToDefault = defaultValue;
|
||||
|
||||
var get = function (attributes) {
|
||||
return coerceToDefault(attributes[nameOrFunction]);
|
||||
};
|
||||
|
||||
var returnDefault = function () {
|
||||
return coerceToDefault(undefined);
|
||||
};
|
||||
|
||||
if (typeof nameOrFunction === 'string') {
|
||||
getter.fromAttributes = get;
|
||||
getter.fromGraph = function (graph, edge) {
|
||||
return get(graph.getEdgeAttributes(edge));
|
||||
};
|
||||
getter.fromEntry = function (edge, attributes) {
|
||||
return get(attributes);
|
||||
};
|
||||
getter.fromPartialEntry = getter.fromEntry;
|
||||
getter.fromMinimalEntry = getter.fromEntry;
|
||||
} else if (typeof nameOrFunction === 'function') {
|
||||
getter.fromAttributes = function () {
|
||||
throw new Error(
|
||||
'graphology-utils/getters/createEdgeValueGetter: irrelevant usage.'
|
||||
);
|
||||
};
|
||||
getter.fromGraph = function (graph, edge) {
|
||||
// TODO: we can do better, check #310
|
||||
var extremities = graph.extremities(edge);
|
||||
return coerceToDefault(
|
||||
nameOrFunction(
|
||||
edge,
|
||||
graph.getEdgeAttributes(edge),
|
||||
extremities[0],
|
||||
extremities[1],
|
||||
graph.getNodeAttributes(extremities[0]),
|
||||
graph.getNodeAttributes(extremities[1]),
|
||||
graph.isUndirected(edge)
|
||||
)
|
||||
);
|
||||
};
|
||||
getter.fromEntry = function (e, a, s, t, sa, ta, u) {
|
||||
return coerceToDefault(nameOrFunction(e, a, s, t, sa, ta, u));
|
||||
};
|
||||
getter.fromPartialEntry = function (e, a, s, t) {
|
||||
return coerceToDefault(nameOrFunction(e, a, s, t));
|
||||
};
|
||||
getter.fromMinimalEntry = function (e, a) {
|
||||
return coerceToDefault(nameOrFunction(e, a));
|
||||
};
|
||||
} else {
|
||||
getter.fromAttributes = returnDefault;
|
||||
getter.fromGraph = returnDefault;
|
||||
getter.fromEntry = returnDefault;
|
||||
getter.fromMinimalEntry = returnDefault;
|
||||
}
|
||||
|
||||
return getter;
|
||||
}
|
||||
|
||||
exports.createNodeValueGetter = createNodeValueGetter;
|
||||
exports.createEdgeValueGetter = createEdgeValueGetter;
|
||||
exports.createEdgeWeightGetter = function (name) {
|
||||
return createEdgeValueGetter(name, coerceWeight);
|
||||
};
|
||||
10
web/node_modules/graphology-utils/index.d.ts
generated
vendored
Normal file
10
web/node_modules/graphology-utils/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export {default as inferMulti} from './infer-multi';
|
||||
export {default as inferType} from './infer-type';
|
||||
export {default as isGraph} from './is-graph';
|
||||
export {default as isGraphConstructor} from './is-graph-constructor';
|
||||
export {default as mergeClique} from './merge-clique';
|
||||
export {default as mergeCycle} from './merge-cycle';
|
||||
export {default as mergePath} from './merge-path';
|
||||
export {default as mergeStar} from './merge-star';
|
||||
export {default as renameGraphKeys} from './rename-graph-keys';
|
||||
export {default as updateGraphKeys} from './update-graph-keys';
|
||||
16
web/node_modules/graphology-utils/index.js
generated
vendored
Normal file
16
web/node_modules/graphology-utils/index.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Graphology Utils
|
||||
* =================
|
||||
*
|
||||
* Library endpoint.
|
||||
*/
|
||||
exports.inferMulti = require('./infer-multi.js');
|
||||
exports.inferType = require('./infer-type.js');
|
||||
exports.isGraph = require('./is-graph.js');
|
||||
exports.isGraphConstructor = require('./is-graph-constructor.js');
|
||||
exports.mergeClique = require('./merge-clique.js');
|
||||
exports.mergeCycle = require('./merge-cycle.js');
|
||||
exports.mergePath = require('./merge-path.js');
|
||||
exports.mergeStar = require('./merge-star.js');
|
||||
exports.renameGraphKeys = require('./rename-graph-keys.js');
|
||||
exports.updateGraphKeys = require('./update-graph-keys.js');
|
||||
3
web/node_modules/graphology-utils/infer-multi.d.ts
generated
vendored
Normal file
3
web/node_modules/graphology-utils/infer-multi.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import Graph from 'graphology-types';
|
||||
|
||||
export default function inferMulti(graph: Graph): boolean;
|
||||
48
web/node_modules/graphology-utils/infer-multi.js
generated
vendored
Normal file
48
web/node_modules/graphology-utils/infer-multi.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Graphology inferMulti
|
||||
* ======================
|
||||
*
|
||||
* Useful function used to "guess" if the given graph is truly multi.
|
||||
*/
|
||||
var isGraph = require('./is-graph.js');
|
||||
|
||||
/**
|
||||
* Returning whether the given graph is inferred as multi.
|
||||
*
|
||||
* @param {Graph} graph - Target graph.
|
||||
* @return {boolean}
|
||||
*/
|
||||
module.exports = function inferMulti(graph) {
|
||||
if (!isGraph(graph))
|
||||
throw new Error(
|
||||
'graphology-utils/infer-multi: expecting a valid graphology instance.'
|
||||
);
|
||||
|
||||
if (!graph.multi || graph.order === 0 || graph.size < 2) return false;
|
||||
|
||||
var multi = false;
|
||||
|
||||
// TODO: improve this with suitable methods
|
||||
var previousSource, previousTarget, wasUndirected, tmp;
|
||||
|
||||
graph.forEachAssymetricAdjacencyEntry(function (s, t, sa, ta, e, ea, u) {
|
||||
if (multi) return; // TODO: we need #.someAdjacencyEntry
|
||||
|
||||
if (u && s > t) {
|
||||
tmp = t;
|
||||
t = s;
|
||||
s = tmp;
|
||||
}
|
||||
|
||||
if (s === previousSource && t === previousTarget && u === wasUndirected) {
|
||||
multi = true;
|
||||
return;
|
||||
}
|
||||
|
||||
previousSource = s;
|
||||
previousTarget = t;
|
||||
wasUndirected = u;
|
||||
});
|
||||
|
||||
return multi;
|
||||
};
|
||||
3
web/node_modules/graphology-utils/infer-type.d.ts
generated
vendored
Normal file
3
web/node_modules/graphology-utils/infer-type.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import Graph, {GraphType} from 'graphology-types';
|
||||
|
||||
export default function inferType(graph: Graph): GraphType;
|
||||
35
web/node_modules/graphology-utils/infer-type.js
generated
vendored
Normal file
35
web/node_modules/graphology-utils/infer-type.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Graphology inferType
|
||||
* =====================
|
||||
*
|
||||
* Useful function used to "guess" the real type of the given Graph using
|
||||
* introspection.
|
||||
*/
|
||||
var isGraph = require('./is-graph.js');
|
||||
|
||||
/**
|
||||
* Returning the inferred type of the given graph.
|
||||
*
|
||||
* @param {Graph} graph - Target graph.
|
||||
* @return {boolean}
|
||||
*/
|
||||
module.exports = function inferType(graph) {
|
||||
if (!isGraph(graph))
|
||||
throw new Error(
|
||||
'graphology-utils/infer-type: expecting a valid graphology instance.'
|
||||
);
|
||||
|
||||
var declaredType = graph.type;
|
||||
|
||||
if (declaredType !== 'mixed') return declaredType;
|
||||
|
||||
if (
|
||||
(graph.directedSize === 0 && graph.undirectedSize === 0) ||
|
||||
(graph.directedSize > 0 && graph.undirectedSize > 0)
|
||||
)
|
||||
return 'mixed';
|
||||
|
||||
if (graph.directedSize > 0) return 'directed';
|
||||
|
||||
return 'undirected';
|
||||
};
|
||||
1
web/node_modules/graphology-utils/is-graph-constructor.d.ts
generated
vendored
Normal file
1
web/node_modules/graphology-utils/is-graph-constructor.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export default function isGraphConstructor(value: any): boolean;
|
||||
23
web/node_modules/graphology-utils/is-graph-constructor.js
generated
vendored
Normal file
23
web/node_modules/graphology-utils/is-graph-constructor.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Graphology isGraphConstructor
|
||||
* ==============================
|
||||
*
|
||||
* Very simple function aiming at ensuring the given variable is a
|
||||
* graphology constructor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checking the value is a graphology constructor.
|
||||
*
|
||||
* @param {any} value - Target value.
|
||||
* @return {boolean}
|
||||
*/
|
||||
module.exports = function isGraphConstructor(value) {
|
||||
return (
|
||||
value !== null &&
|
||||
typeof value === 'function' &&
|
||||
typeof value.prototype === 'object' &&
|
||||
typeof value.prototype.addUndirectedEdgeWithKey === 'function' &&
|
||||
typeof value.prototype.dropNode === 'function'
|
||||
);
|
||||
};
|
||||
1
web/node_modules/graphology-utils/is-graph.d.ts
generated
vendored
Normal file
1
web/node_modules/graphology-utils/is-graph.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export default function isGraph(value: any): boolean;
|
||||
23
web/node_modules/graphology-utils/is-graph.js
generated
vendored
Normal file
23
web/node_modules/graphology-utils/is-graph.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Graphology isGraph
|
||||
* ===================
|
||||
*
|
||||
* Very simple function aiming at ensuring the given variable is a
|
||||
* graphology instance.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checking the value is a graphology instance.
|
||||
*
|
||||
* @param {any} value - Target value.
|
||||
* @return {boolean}
|
||||
*/
|
||||
module.exports = function isGraph(value) {
|
||||
return (
|
||||
value !== null &&
|
||||
typeof value === 'object' &&
|
||||
typeof value.addUndirectedEdgeWithKey === 'function' &&
|
||||
typeof value.dropNode === 'function' &&
|
||||
typeof value.multi === 'boolean'
|
||||
);
|
||||
};
|
||||
3
web/node_modules/graphology-utils/merge-clique.d.ts
generated
vendored
Normal file
3
web/node_modules/graphology-utils/merge-clique.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import Graph from 'graphology-types';
|
||||
|
||||
export default function mergeClique(graph: Graph, nodes: Array<unknown>): void;
|
||||
28
web/node_modules/graphology-utils/merge-clique.js
generated
vendored
Normal file
28
web/node_modules/graphology-utils/merge-clique.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Graphology mergeClique
|
||||
* =======================
|
||||
*
|
||||
* Function merging the given clique to the graph.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Merging the given clique to the graph.
|
||||
*
|
||||
* @param {Graph} graph - Target graph.
|
||||
* @param {array} nodes - Nodes representing the clique to merge.
|
||||
*/
|
||||
module.exports = function mergeClique(graph, nodes) {
|
||||
if (nodes.length === 0) return;
|
||||
|
||||
var source, target, i, j, l;
|
||||
|
||||
for (i = 0, l = nodes.length; i < l; i++) {
|
||||
source = nodes[i];
|
||||
|
||||
for (j = i + 1; j < l; j++) {
|
||||
target = nodes[j];
|
||||
|
||||
graph.mergeEdge(source, target);
|
||||
}
|
||||
}
|
||||
};
|
||||
3
web/node_modules/graphology-utils/merge-cycle.d.ts
generated
vendored
Normal file
3
web/node_modules/graphology-utils/merge-cycle.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import Graph from 'graphology-types';
|
||||
|
||||
export default function mergeCycle(graph: Graph, nodes: Array<unknown>): void;
|
||||
31
web/node_modules/graphology-utils/merge-cycle.js
generated
vendored
Normal file
31
web/node_modules/graphology-utils/merge-cycle.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Graphology mergeCycle
|
||||
* =====================
|
||||
*
|
||||
* Function merging the given cycle to the graph.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Merging the given cycle to the graph.
|
||||
*
|
||||
* @param {Graph} graph - Target graph.
|
||||
* @param {array} nodes - Nodes representing the cycle to merge.
|
||||
*/
|
||||
module.exports = function mergeCycle(graph, nodes) {
|
||||
if (nodes.length === 0) return;
|
||||
|
||||
var previousNode, node, i, l;
|
||||
|
||||
graph.mergeNode(nodes[0]);
|
||||
|
||||
if (nodes.length === 1) return;
|
||||
|
||||
for (i = 1, l = nodes.length; i < l; i++) {
|
||||
previousNode = nodes[i - 1];
|
||||
node = nodes[i];
|
||||
|
||||
graph.mergeEdge(previousNode, node);
|
||||
}
|
||||
|
||||
graph.mergeEdge(node, nodes[0]);
|
||||
};
|
||||
3
web/node_modules/graphology-utils/merge-path.d.ts
generated
vendored
Normal file
3
web/node_modules/graphology-utils/merge-path.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import Graph from 'graphology-types';
|
||||
|
||||
export default function mergePath(graph: Graph, nodes: Array<unknown>): void;
|
||||
27
web/node_modules/graphology-utils/merge-path.js
generated
vendored
Normal file
27
web/node_modules/graphology-utils/merge-path.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Graphology mergePath
|
||||
* =====================
|
||||
*
|
||||
* Function merging the given path to the graph.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Merging the given path to the graph.
|
||||
*
|
||||
* @param {Graph} graph - Target graph.
|
||||
* @param {array} nodes - Nodes representing the path to merge.
|
||||
*/
|
||||
module.exports = function mergePath(graph, nodes) {
|
||||
if (nodes.length === 0) return;
|
||||
|
||||
var previousNode, node, i, l;
|
||||
|
||||
graph.mergeNode(nodes[0]);
|
||||
|
||||
for (i = 1, l = nodes.length; i < l; i++) {
|
||||
previousNode = nodes[i - 1];
|
||||
node = nodes[i];
|
||||
|
||||
graph.mergeEdge(previousNode, node);
|
||||
}
|
||||
};
|
||||
3
web/node_modules/graphology-utils/merge-star.d.ts
generated
vendored
Normal file
3
web/node_modules/graphology-utils/merge-star.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import Graph from 'graphology-types';
|
||||
|
||||
export default function mergeStar(graph: Graph, nodes: Array<unknown>): void;
|
||||
28
web/node_modules/graphology-utils/merge-star.js
generated
vendored
Normal file
28
web/node_modules/graphology-utils/merge-star.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Graphology mergeStar
|
||||
* =====================
|
||||
*
|
||||
* Function merging the given star to the graph.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Merging the given star to the graph.
|
||||
*
|
||||
* @param {Graph} graph - Target graph.
|
||||
* @param {array} nodes - Nodes to add, first one being the center of the star.
|
||||
*/
|
||||
module.exports = function mergeStar(graph, nodes) {
|
||||
if (nodes.length === 0) return;
|
||||
|
||||
var node, i, l;
|
||||
|
||||
var center = nodes[0];
|
||||
|
||||
graph.mergeNode(center);
|
||||
|
||||
for (i = 1, l = nodes.length; i < l; i++) {
|
||||
node = nodes[i];
|
||||
|
||||
graph.mergeEdge(center, node);
|
||||
}
|
||||
};
|
||||
56
web/node_modules/graphology-utils/package.json
generated
vendored
Normal file
56
web/node_modules/graphology-utils/package.json
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"name": "graphology-utils",
|
||||
"version": "2.5.2",
|
||||
"description": "Miscellaneous utils for graphology.",
|
||||
"main": "index.js",
|
||||
"files": [
|
||||
"*.d.ts",
|
||||
"add-edge.js",
|
||||
"add-node.js",
|
||||
"defaults.js",
|
||||
"getters.js",
|
||||
"index.js",
|
||||
"infer-type.js",
|
||||
"infer-multi.js",
|
||||
"is-graph.js",
|
||||
"is-graph-constructor.js",
|
||||
"merge-clique.js",
|
||||
"merge-cycle.js",
|
||||
"merge-path.js",
|
||||
"merge-star.js",
|
||||
"rename-graph-keys.js",
|
||||
"update-graph-keys.js"
|
||||
],
|
||||
"types": "./index.d.ts",
|
||||
"scripts": {
|
||||
"prepublishOnly": "npm test",
|
||||
"test": "mocha test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/graphology/graphology.git"
|
||||
},
|
||||
"keywords": [
|
||||
"graph",
|
||||
"graphology",
|
||||
"utils"
|
||||
],
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Guillaume Plique",
|
||||
"url": "http://github.com/Yomguithereal"
|
||||
},
|
||||
{
|
||||
"name": "Jules Farjas",
|
||||
"url": "http://github.com/farjasju"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/graphology/graphology/issues"
|
||||
},
|
||||
"homepage": "https://github.com/graphology/graphology#readme",
|
||||
"peerDependencies": {
|
||||
"graphology-types": ">=0.23.0"
|
||||
}
|
||||
}
|
||||
7
web/node_modules/graphology-utils/rename-graph-keys.d.ts
generated
vendored
Normal file
7
web/node_modules/graphology-utils/rename-graph-keys.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import Graph from 'graphology-types';
|
||||
|
||||
export default function renameGraphKeys(
|
||||
graph: Graph,
|
||||
nodeKeyMapping: Record<string, unknown>,
|
||||
edgeKeyMapping: Record<string, unknown>
|
||||
): Graph;
|
||||
68
web/node_modules/graphology-utils/rename-graph-keys.js
generated
vendored
Normal file
68
web/node_modules/graphology-utils/rename-graph-keys.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Graphology Rename Graph Keys
|
||||
* =============================
|
||||
*
|
||||
* Helpers allowing you to rename (ie. change the key) of nodes & edges .
|
||||
*/
|
||||
var copyEdge = require('./add-edge.js').copyEdge;
|
||||
|
||||
module.exports = function renameGraphKeys(
|
||||
graph,
|
||||
nodeKeyMapping,
|
||||
edgeKeyMapping
|
||||
) {
|
||||
if (typeof nodeKeyMapping === 'undefined') nodeKeyMapping = {};
|
||||
if (typeof edgeKeyMapping === 'undefined') edgeKeyMapping = {};
|
||||
|
||||
var renamed = graph.nullCopy();
|
||||
|
||||
// Renaming nodes
|
||||
graph.forEachNode(function (key, attr) {
|
||||
var renamedKey = nodeKeyMapping[key];
|
||||
|
||||
if (typeof renamedKey === 'undefined') renamedKey = key;
|
||||
|
||||
renamed.addNode(renamedKey, attr);
|
||||
});
|
||||
|
||||
// Renaming edges
|
||||
var currentSource, currentSourceRenamed;
|
||||
|
||||
graph.forEachAssymetricAdjacencyEntry(function (
|
||||
source,
|
||||
target,
|
||||
_sa,
|
||||
_ta,
|
||||
key,
|
||||
attr,
|
||||
undirected
|
||||
) {
|
||||
// Leveraging the ordered adjacency to save lookups
|
||||
if (source !== currentSource) {
|
||||
currentSource = source;
|
||||
currentSourceRenamed = nodeKeyMapping[source];
|
||||
|
||||
if (typeof currentSourceRenamed === 'undefined')
|
||||
currentSourceRenamed = source;
|
||||
}
|
||||
|
||||
var targetRenamed = nodeKeyMapping[target];
|
||||
|
||||
if (typeof targetRenamed === 'undefined') targetRenamed = target;
|
||||
|
||||
var renamedKey = edgeKeyMapping[key];
|
||||
|
||||
if (typeof renamedKey === 'undefined') renamedKey = key;
|
||||
|
||||
copyEdge(
|
||||
renamed,
|
||||
undirected,
|
||||
renamedKey,
|
||||
currentSourceRenamed,
|
||||
targetRenamed,
|
||||
attr
|
||||
);
|
||||
});
|
||||
|
||||
return renamed;
|
||||
};
|
||||
18
web/node_modules/graphology-utils/update-graph-keys.d.ts
generated
vendored
Normal file
18
web/node_modules/graphology-utils/update-graph-keys.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import Graph, {Attributes} from 'graphology-types';
|
||||
|
||||
export default function updateGraphKeys<
|
||||
NodeAttributes extends Attributes = Attributes,
|
||||
EdgeAttributes extends Attributes = Attributes
|
||||
>(
|
||||
graph: Graph<NodeAttributes, EdgeAttributes>,
|
||||
nodeKeyUpdater: (key: string, attributes: NodeAttributes) => unknown,
|
||||
edgeKeyUpdater: (
|
||||
key: string,
|
||||
attributes: EdgeAttributes,
|
||||
source: string,
|
||||
target: string,
|
||||
sourceAttributes: NodeAttributes,
|
||||
targetAttributes: NodeAttributes,
|
||||
undirected: boolean
|
||||
) => unknown
|
||||
): Graph;
|
||||
69
web/node_modules/graphology-utils/update-graph-keys.js
generated
vendored
Normal file
69
web/node_modules/graphology-utils/update-graph-keys.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Graphology Update Graph Keys
|
||||
* =============================
|
||||
*
|
||||
* Helpers allowing you to update keys of nodes & edges .
|
||||
*/
|
||||
var copyEdge = require('./add-edge.js').copyEdge;
|
||||
|
||||
module.exports = function updateGraphKeys(
|
||||
graph,
|
||||
nodeKeyUpdater,
|
||||
edgeKeyUpdater
|
||||
) {
|
||||
var renamed = graph.nullCopy();
|
||||
|
||||
// Renaming nodes
|
||||
graph.forEachNode(function (key, attr) {
|
||||
var renamedKey = nodeKeyUpdater ? nodeKeyUpdater(key, attr) : key;
|
||||
renamed.addNode(renamedKey, attr);
|
||||
});
|
||||
|
||||
// Renaming edges
|
||||
var currentSource, currentSourceRenamed;
|
||||
|
||||
graph.forEachAssymetricAdjacencyEntry(function (
|
||||
source,
|
||||
target,
|
||||
sourceAttr,
|
||||
targetAttr,
|
||||
key,
|
||||
attr,
|
||||
undirected
|
||||
) {
|
||||
// Leveraging the ordered adjacency to save calls
|
||||
if (source !== currentSource) {
|
||||
currentSource = source;
|
||||
currentSourceRenamed = nodeKeyUpdater
|
||||
? nodeKeyUpdater(source, sourceAttr)
|
||||
: source;
|
||||
}
|
||||
|
||||
var targetRenamed = nodeKeyUpdater
|
||||
? nodeKeyUpdater(target, targetAttr)
|
||||
: target;
|
||||
|
||||
var renamedKey = edgeKeyUpdater
|
||||
? edgeKeyUpdater(
|
||||
key,
|
||||
attr,
|
||||
source,
|
||||
target,
|
||||
sourceAttr,
|
||||
targetAttr,
|
||||
undirected
|
||||
)
|
||||
: key;
|
||||
|
||||
copyEdge(
|
||||
renamed,
|
||||
undirected,
|
||||
renamedKey,
|
||||
currentSourceRenamed,
|
||||
targetRenamed,
|
||||
attr
|
||||
);
|
||||
});
|
||||
|
||||
return renamed;
|
||||
};
|
||||
Reference in New Issue
Block a user