mirror of
https://github.com/xodio/xod.git
synced 2026-03-21 16:16:55 +01:00
fix(xod-fs): store nodes and links as arrays
This commit is contained in:
@@ -29,14 +29,12 @@ export const getProjectPath = R.pipe(
|
||||
|
||||
export const getPatchFolderName = R.pipe(XP.getPatchPath, XP.getBaseName);
|
||||
|
||||
const removeIds = R.map(R.dissoc('id'));
|
||||
|
||||
export const getXodpContents = R.compose(
|
||||
R.dissoc('impls'),
|
||||
R.dissoc('path'),
|
||||
R.evolve({
|
||||
nodes: removeIds,
|
||||
links: removeIds,
|
||||
nodes: R.values,
|
||||
links: R.values,
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -29,11 +29,11 @@ export const doesFileExist = R.tryCatch(
|
||||
R.F
|
||||
);
|
||||
|
||||
const assocIds = R.mapObjIndexed((entity, id) => R.assoc('id', id, entity));
|
||||
const indexByIds = R.indexBy(R.prop('id'));
|
||||
|
||||
export const reassignIds = R.evolve({
|
||||
nodes: assocIds,
|
||||
links: assocIds,
|
||||
nodes: indexByIds,
|
||||
links: indexByIds,
|
||||
});
|
||||
|
||||
export const getPatchName = (patchPath) => {
|
||||
|
||||
4
packages/xod-fs/test/fixtures/libs.json
vendored
4
packages/xod-fs/test/fixtures/libs.json
vendored
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"xod/core/led": {
|
||||
"label": "LED",
|
||||
"description": "",
|
||||
"links": {},
|
||||
"nodes": {
|
||||
@@ -34,7 +33,6 @@
|
||||
},
|
||||
"xod/core/and": {
|
||||
"path": "xod/core/and",
|
||||
"label": "and",
|
||||
"description": "",
|
||||
"links": {},
|
||||
"nodes": {
|
||||
@@ -88,7 +86,6 @@
|
||||
}
|
||||
},
|
||||
"xod/core/pot": {
|
||||
"label": "pot",
|
||||
"description": "",
|
||||
"links": {},
|
||||
"nodes": {
|
||||
@@ -135,7 +132,6 @@
|
||||
"path": "xod/core/test",
|
||||
"nodes": {},
|
||||
"links": {},
|
||||
"label": "Test",
|
||||
"description": "",
|
||||
"impls": {}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
],
|
||||
"description": "",
|
||||
"license": "",
|
||||
"version": "0.0.1",
|
||||
"patches": {
|
||||
"xod/core/led": {
|
||||
"nodes": {
|
||||
|
||||
3
packages/xod-fs/test/fixtures/unpacked.json
vendored
3
packages/xod-fs/test/fixtures/unpacked.json
vendored
@@ -7,6 +7,7 @@
|
||||
],
|
||||
"description": "",
|
||||
"license": "",
|
||||
"version": "42",
|
||||
"name": "awesome-project",
|
||||
"libs": [
|
||||
"xod/core"
|
||||
@@ -17,7 +18,6 @@
|
||||
"content": {
|
||||
"path": "@/main",
|
||||
"description": "",
|
||||
"label": "Main",
|
||||
"impls": {},
|
||||
"links": {
|
||||
"1d78b081-ebfe-4a2d-b857-08a3b9ddd90f": {
|
||||
@@ -113,7 +113,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"label": "QUX",
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"nodes": {
|
||||
"2c03e470-fefd-4f58-be6a-58d209d9158c": {
|
||||
"nodes": [
|
||||
{
|
||||
"id": "2c03e470-fefd-4f58-be6a-58d209d9158c",
|
||||
"type": "xod/core/pot",
|
||||
"pins": {},
|
||||
"position": {
|
||||
@@ -8,7 +9,8 @@
|
||||
"y": 182
|
||||
}
|
||||
},
|
||||
"89c69d91-b484-478d-8990-027e5f0a2e3e": {
|
||||
{
|
||||
"id": "89c69d91-b484-478d-8990-027e5f0a2e3e",
|
||||
"type": "xod/core/and",
|
||||
"pins": {},
|
||||
"position": {
|
||||
@@ -16,7 +18,8 @@
|
||||
"y": 314
|
||||
}
|
||||
},
|
||||
"4d716df5-81e7-4845-9b82-31a54c1634d7": {
|
||||
{
|
||||
"id": "4d716df5-81e7-4845-9b82-31a54c1634d7",
|
||||
"type": "@/qux",
|
||||
"pins": {},
|
||||
"position": {
|
||||
@@ -24,9 +27,10 @@
|
||||
"y": 322
|
||||
}
|
||||
}
|
||||
},
|
||||
"links": {
|
||||
"3ed564cd-71e5-4ad3-9361-e7b9719bc82a": {
|
||||
],
|
||||
"links": [
|
||||
{
|
||||
"id": "3ed564cd-71e5-4ad3-9361-e7b9719bc82a",
|
||||
"input": {
|
||||
"nodeId": "2c03e470-fefd-4f58-be6a-58d209d9158c",
|
||||
"pinKey": "value"
|
||||
@@ -36,7 +40,8 @@
|
||||
"pinKey": "b"
|
||||
}
|
||||
},
|
||||
"1d78b081-ebfe-4a2d-b857-08a3b9ddd90f": {
|
||||
{
|
||||
"id": "1d78b081-ebfe-4a2d-b857-08a3b9ddd90f",
|
||||
"input": {
|
||||
"nodeId": "2c03e470-fefd-4f58-be6a-58d209d9158c",
|
||||
"pinKey": "value"
|
||||
@@ -46,7 +51,6 @@
|
||||
"pinKey": "38395ee5-8634-40f9-b7fa-dfe9eee208e8"
|
||||
}
|
||||
}
|
||||
},
|
||||
"label": "Main",
|
||||
],
|
||||
"description": ""
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"description": "",
|
||||
"license": "",
|
||||
"name": "awesome-project",
|
||||
"version": "42",
|
||||
"libs": [
|
||||
"xod/core"
|
||||
]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"nodes": {
|
||||
"38395ee5-8634-40f9-b7fa-dfe9eee208e8": {
|
||||
"nodes": [
|
||||
{
|
||||
"id": "38395ee5-8634-40f9-b7fa-dfe9eee208e8",
|
||||
"type": "xod/patch-nodes/input-number",
|
||||
"pins": {},
|
||||
"position": {
|
||||
@@ -8,7 +9,8 @@
|
||||
"y": 155
|
||||
}
|
||||
},
|
||||
"4da4c29d-f482-47c2-825e-a969084b1116": {
|
||||
{
|
||||
"id": "4da4c29d-f482-47c2-825e-a969084b1116",
|
||||
"type": "xod/core/led",
|
||||
"pins": {},
|
||||
"position": {
|
||||
@@ -16,9 +18,10 @@
|
||||
"y": 307
|
||||
}
|
||||
}
|
||||
},
|
||||
"links": {
|
||||
"30dafe79-37e6-4fc0-a8b8-fa5e912ffef1": {
|
||||
],
|
||||
"links": [
|
||||
{
|
||||
"id": "30dafe79-37e6-4fc0-a8b8-fa5e912ffef1",
|
||||
"input": {
|
||||
"nodeId": "38395ee5-8634-40f9-b7fa-dfe9eee208e8",
|
||||
"pinKey": "PIN"
|
||||
@@ -28,7 +31,6 @@
|
||||
"pinKey": "brightness"
|
||||
}
|
||||
}
|
||||
},
|
||||
"label": "QUX",
|
||||
],
|
||||
"description": ""
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"nodes": {},
|
||||
"links": {},
|
||||
"label": "Test",
|
||||
"nodes": [],
|
||||
"links": [],
|
||||
"description": ""
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"label": "and",
|
||||
"description": "",
|
||||
"links": {},
|
||||
"nodes": {
|
||||
"noNativeImpl": {
|
||||
"links": [],
|
||||
"nodes": [
|
||||
{
|
||||
"id": "noNativeImpl",
|
||||
"label": "",
|
||||
"description": "",
|
||||
"pins": {},
|
||||
@@ -13,7 +13,8 @@
|
||||
},
|
||||
"type": "xod/patch-nodes/not-implemented-in-xod"
|
||||
},
|
||||
"a": {
|
||||
{
|
||||
"id": "a",
|
||||
"label": "First input",
|
||||
"description": "",
|
||||
"pins": {},
|
||||
@@ -23,7 +24,8 @@
|
||||
},
|
||||
"type": "xod/patch-nodes/input-boolean"
|
||||
},
|
||||
"b": {
|
||||
{
|
||||
"id": "b",
|
||||
"label": "Second input",
|
||||
"description": "",
|
||||
"pins": {},
|
||||
@@ -33,7 +35,8 @@
|
||||
},
|
||||
"type": "xod/patch-nodes/input-boolean"
|
||||
},
|
||||
"out": {
|
||||
{
|
||||
"id": "out",
|
||||
"label": "output",
|
||||
"description": "\"true\" if both inputs are \"true\"",
|
||||
"pins": {},
|
||||
@@ -43,5 +46,5 @@
|
||||
},
|
||||
"type": "xod/patch-nodes/output-boolean"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"label": "LED",
|
||||
"description": "",
|
||||
"links": {},
|
||||
"nodes": {
|
||||
"noNativeImpl": {
|
||||
"links": [],
|
||||
"nodes": [
|
||||
{
|
||||
"id": "noNativeImpl",
|
||||
"label": "",
|
||||
"description": "",
|
||||
"pins": {},
|
||||
@@ -13,7 +13,8 @@
|
||||
},
|
||||
"type": "xod/patch-nodes/not-implemented-in-xod"
|
||||
},
|
||||
"brightness": {
|
||||
{
|
||||
"id": "brightness",
|
||||
"label": "",
|
||||
"description": "Shine brightness",
|
||||
"pins": {},
|
||||
@@ -23,5 +24,5 @@
|
||||
},
|
||||
"type": "xod/patch-nodes/input-number"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"label": "pot",
|
||||
"description": "",
|
||||
"links": {},
|
||||
"nodes": {
|
||||
"noNativeImpl": {
|
||||
"links": [],
|
||||
"nodes": [
|
||||
{
|
||||
"id": "noNativeImpl",
|
||||
"label": "",
|
||||
"description": "",
|
||||
"pins": {},
|
||||
@@ -13,7 +13,8 @@
|
||||
},
|
||||
"type": "xod/patch-nodes/not-implemented-in-xod"
|
||||
},
|
||||
"sample": {
|
||||
{
|
||||
"id": "sample",
|
||||
"label": "",
|
||||
"description": "Sample current value",
|
||||
"pins": {},
|
||||
@@ -23,7 +24,8 @@
|
||||
},
|
||||
"type": "xod/patch-nodes/input-pulse"
|
||||
},
|
||||
"value": {
|
||||
{
|
||||
"id": "value",
|
||||
"label": "",
|
||||
"description": "Sampled potentiometer value",
|
||||
"pins": {},
|
||||
@@ -33,5 +35,5 @@
|
||||
},
|
||||
"type": "xod/patch-nodes/output-number"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"nodes": {},
|
||||
"links": {},
|
||||
"label": "Test",
|
||||
"nodes": [],
|
||||
"links": [],
|
||||
"description": ""
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"nodes": {},
|
||||
"links": {},
|
||||
"label": "Test",
|
||||
"nodes": [],
|
||||
"links": [],
|
||||
"description": ""
|
||||
}
|
||||
|
||||
7
packages/xod-fs/test/fixtures/xodball.json
vendored
7
packages/xod-fs/test/fixtures/xodball.json
vendored
@@ -4,10 +4,10 @@
|
||||
],
|
||||
"description": "",
|
||||
"license": "",
|
||||
"version": "42",
|
||||
"name": "awesome-project",
|
||||
"patches": {
|
||||
"xod/core/and": {
|
||||
"label": "and",
|
||||
"description": "",
|
||||
"links": {},
|
||||
"nodes": {
|
||||
@@ -62,7 +62,6 @@
|
||||
}
|
||||
},
|
||||
"xod/core/led": {
|
||||
"label": "LED",
|
||||
"description": "",
|
||||
"links": {},
|
||||
"nodes": {
|
||||
@@ -95,7 +94,6 @@
|
||||
}
|
||||
},
|
||||
"xod/core/pot": {
|
||||
"label": "pot",
|
||||
"description": "",
|
||||
"links": {},
|
||||
"nodes": {
|
||||
@@ -141,7 +139,6 @@
|
||||
"xod/core/test": {
|
||||
"nodes": {},
|
||||
"links": {},
|
||||
"label": "Test",
|
||||
"description": "",
|
||||
"path": "xod/core/test",
|
||||
"impls": {}
|
||||
@@ -200,7 +197,6 @@
|
||||
"id": "1d78b081-ebfe-4a2d-b857-08a3b9ddd90f"
|
||||
}
|
||||
},
|
||||
"label": "Main",
|
||||
"description": "",
|
||||
"path": "@/main",
|
||||
"impls": {}
|
||||
@@ -239,7 +235,6 @@
|
||||
"id": "30dafe79-37e6-4fc0-a8b8-fa5e912ffef1"
|
||||
}
|
||||
},
|
||||
"label": "QUX",
|
||||
"description": "",
|
||||
"path": "@/qux",
|
||||
"impls": {}
|
||||
|
||||
@@ -30,6 +30,7 @@ describe('Loader', () => {
|
||||
license: '',
|
||||
name: 'awesome-project',
|
||||
libs: ['xod/core'],
|
||||
version: '42',
|
||||
path: path.resolve(workspace, projectPath),
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -22,14 +22,16 @@ describe('arrangeByFiles', () => {
|
||||
'xod/core',
|
||||
],
|
||||
license: '',
|
||||
version: '0.0.1',
|
||||
name: 'awesome-project',
|
||||
},
|
||||
path: './awesome-project/project.xod',
|
||||
},
|
||||
{
|
||||
content: {
|
||||
nodes: {
|
||||
SJmGlirFpx: {
|
||||
nodes: [
|
||||
{
|
||||
id: 'SJmGlirFpx',
|
||||
type: 'xod/core/led',
|
||||
position: {
|
||||
x: 138,
|
||||
@@ -44,7 +46,8 @@ describe('arrangeByFiles', () => {
|
||||
label: 'my led',
|
||||
description: 'description for my led',
|
||||
},
|
||||
rJxbjrKpl: {
|
||||
{
|
||||
id: 'rJxbjrKpl',
|
||||
type: 'xod/patch-nodes/input-number',
|
||||
position: {
|
||||
x: 138,
|
||||
@@ -54,9 +57,10 @@ describe('arrangeByFiles', () => {
|
||||
label: '',
|
||||
description: '',
|
||||
},
|
||||
},
|
||||
links: {
|
||||
rJIWsrtae: {
|
||||
],
|
||||
links: [
|
||||
{
|
||||
id: 'rJIWsrtae',
|
||||
output: {
|
||||
nodeId: 'rJxbjrKpl',
|
||||
pinKey: 'PIN',
|
||||
@@ -66,7 +70,7 @@ describe('arrangeByFiles', () => {
|
||||
pinKey: 'brightness',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
path: './awesome-project/main/patch.xodp',
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user