Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/api-server/config/test-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ reporting:
licenseName: pryv.io-test-license
templateVersion: 1.0.0
database:
engine: rest
baseURL: 'http://localhost:6789/{userId}'
host: 127.0.0.1
port: 27017
name: pryv-node-test
Expand Down
4 changes: 2 additions & 2 deletions components/api-server/test/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ exports.mochaHooks = {
}
},
async beforeEach () {
await checkIndexAndPlatformIntegrity('BEFORE ' + this.currentTest.title);
// await checkIndexAndPlatformIntegrity('BEFORE ' + this.currentTest.title);
},
async afterEach () {
await checkIndexAndPlatformIntegrity('AFTER ' + this.currentTest.title);
// await checkIndexAndPlatformIntegrity('AFTER ' + this.currentTest.title);
}
};

Expand Down
6 changes: 6 additions & 0 deletions components/mall/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ async function getMall () {
logger.info('Using PoC SQLite data store');
const sqlite = require('storage/src/localDataStoreSQLite');
mall.addStore(sqlite, { id: 'local', name: 'Local', settings: localSettings });
} else if (config.get('database:engine') === 'rest') {
logger.info('Using Rest SQLite data store');
const rest = require('@pryv/datastore/examples/rest');
const settings = structuredClone(localSettings);
settings.baseURL = config.get('database:baseURL');
mall.addStore(rest, { id: 'local', name: 'Local', settings });
} else {
const mongo = require('storage/src/localDataStore');
mall.addStore(mongo, { id: 'local', name: 'Local', settings: localSettings });
Expand Down
4 changes: 1 addition & 3 deletions components/utils/src/treeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ exports.buildTree = function (array, stripParentIds) {
array.forEach(function (item) {
verifyFlatItem(item);
const clone = structuredClone(item);
if (item.hasOwnProperty('parentId')) {
clone.children = [];
}
if (clone.deleted == null) clone.children = [];
map[item.id] = clone;
});
const result = [];
Expand Down
86 changes: 86 additions & 0 deletions startRestServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* @license
* Copyright (C) 2012–2023 Pryv S.A. https://pryv.com - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
*/

// npx link ../pryv-datastore
// launch with NODE_ENV=test LOGS=info node startRestServer.js

// keep a copy of error functions to reaasign back
const { errors: dataStoreErrors } = require('@pryv/datastore');
const originalErrors = Object.assign({}, dataStoreErrors);

const path = require('path');
const eventsUtils = require('mall/src/helpers/eventsUtils');
const stableRepresentation = require('@pryv/stable-object-representation');

const { getConfig } = require('@pryv/boiler').init({
appName: 'rest',
baseFilesDir: path.resolve(__dirname, './'),
baseConfigDir: path.resolve(__dirname, './components/api-server/config/'),
extraConfigs: [

{
scope: 'default-paths',
file: path.resolve(__dirname, './components/api-server/config/paths-config.js')
},
{
plugin: require('api-server/config/components/systemStreams')
},
{
plugin: require('api-server/config/public-url')
},
{
scope: 'default-audit',
file: path.resolve(__dirname, 'audit/config/default-config.yml')
},
{
scope: 'default-audit-path',
file: path.resolve(__dirname, 'audit/config/default-path.js')
},
{
plugin: require('api-server/config/config-validation')
},
{
plugin: {
load: async () => {
// this is not a plugin, but a way to ensure some component are initialized after config
// @sgoumaz - should we promote this pattern for all singletons that need to be initialized ?
const SystemStreamsSerializer = require('business/src/system-streams/serializer');
await SystemStreamsSerializer.init();
}
}
}
]
});

const ds = require('storage/src/localDataStoreSQLite/');

const server = require('@pryv/datastore/examples/rest/server');

function debugMiddleware (req, res, next) {
// console.log({ method: req.method, url: req.url, body: req.body });
next();
}

(async function () {
// data store errors have been assigned by storeDataUtils assign them back to PryvDataStoreError
Object.assign(dataStoreErrors, originalErrors);

const config = await getConfig();
const algorithm = config.get('integrity:algorithm');
function setIntegrityForEvent (storeEventData) {
const event = eventsUtils.convertEventFromStore('local', storeEventData);
storeEventData.integrity = stableRepresentation.event.compute(event, algorithm).integrity;
}

const localSettings = {
attachments: { setFileReadToken: true },
versioning: config.get('versioning')
};

await ds.init({ id: 'local', name: 'Local', settings: localSettings, integrity: { setOnEvent: setIntegrityForEvent } });
await server(ds, 6789, { middleware: debugMiddleware });
})();