import {cutMapNodes, Id, newSystemClient, Pipe, SystemError} from '../node'; import {newServiceClient as newServiceClient} from '../node'; import {globalApiUrl, globalSystemUrl, globalUniverse, layerProfileStr} from './config'; import {Client} from "../client"; test('newClient returns instance', async () => { const client = new Client(newServiceClient(globalApiUrl), newSystemClient(globalSystemUrl)); const universe = (await client.loadUniverse(globalUniverse))!; expect(universe).toBeTruthy(); const pipe = new Pipe(`on base.object -> @id`); await pipe.loadPipe(universe); }); test('pipe1 works', async () => { const client = new Client(newServiceClient(globalApiUrl), newSystemClient(globalSystemUrl)); await client.loadProfile(layerProfileStr); const universe = (await client.loadUniverse(globalUniverse))!; expect(universe).toBeTruthy(); const pipe = new Pipe(`on base.object -> {@id}`); const result = await client.getObjects(pipe.filter('id', 'gt', '5')); console.log(result); }); test('pipe2 works', async () => { const client = new Client(newServiceClient(globalApiUrl), newSystemClient(globalSystemUrl)); await client.loadProfile(layerProfileStr); const universe = (await client.loadUniverse(globalUniverse))!; expect(universe).toBeTruthy(); const pipe = new Pipe(`on base.object -> {@id}`); const result = await client.getObject(pipe); console.log(result); }); test('cutMapNodes works 1', async () => { const nd = cutMapNodes(['id'], { type: 'map', map: { entries: [ { name: 'id', node: { type: 'value', value: { field: 'id', format: 'hex', } } } ] } }); expect(nd.node.type).toBe('value'); expect(nd.format).toBe('hex'); }); test('cutMapNodes works 2', async () => { const nd = cutMapNodes(['rel1'], { type: 'map', map: { entries: [ { name: 'id', node: { type: 'value', value: { field: 'id', format: 'hex', } } }, { name: 'rel1', node: { type: 'relation', relation: { relation: 'rel1', type: 'primitive', reverse: false, node: { type: 'value', value: { field: 'data', format: 'string', } } } } } ] } }); expect(nd.node.type).toBe('relation'); expect(nd.node.relation?.node?.type).toBe('value'); expect(nd.format).toBe('string'); }); test('cutMapNodes works nested 1', async () => { const nd = cutMapNodes(['rel1', 'rel2'], { type: 'map', map: { entries: [ { name: 'rel1', node: { type: 'relation', relation: { relation: 'rel1', type: 'primitive', reverse: false, node: { type: 'map', map: { entries: [ { name: 'rel2', node: { type: 'relation', relation: { relation: 'rel1', type: 'primitive', reverse: false, node: { type: 'value', value: { field: 'data', format: 'string', } } } } } ] } } } } } ] } }); expect(nd.node.type).toBe('relation'); expect(nd.node.relation?.node?.relation?.node?.type).toBe('value'); expect(nd.format).toBe('string'); });