Skip to content

Commit

Permalink
Merge pull request #186 from nzzdev/release-9.0.0
Browse files Browse the repository at this point in the history
Release 9.0.0
  • Loading branch information
benib committed Oct 9, 2019
2 parents c174b5f + 23ac911 commit 5a7785f
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 147 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nzz/q-server",
"version": "8.1.0",
"version": "9.0.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion plugins/core/base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
require("./routes/tool-default.js").getPostRoute(options),
require("./routes/tool-schema.js").getSchema(options),
require("./routes/tool-schema.js").getDisplayOptionsSchema(options),
require("./routes/export-options-schema.js").getGetRoute(options),
require("./routes/display-options-schema.js").getGetRoute(options),
require("./routes/health.js"),
require("./routes/version.js"),
require("./routes/admin/migration.js")
Expand Down
135 changes: 135 additions & 0 deletions plugins/core/base/routes/display-options-schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
const Joi = require("@hapi/joi");
const Bounce = require("@hapi/bounce");
const deepmerge = require("deepmerge");

function getMergedSchema(a, b) {
return deepmerge(a, b, {
arrayMerge: (destArr, srcArr) => {
return [...new Set(srcArr.concat(destArr))]; // merge unique
}
});
}

module.exports = {
getGetRoute: function(options) {
return {
path: "/display-options-schema/{itemId}/{target}.json",
method: "GET",
options: {
description:
"compiles the display-options for the item with the given id and the specified target",
tags: ["api"],
validate: {
params: {
itemId: Joi.string().required(),
target: Joi.string().required()
}
}
},
handler: async (request, h) => {
// load item with given id
const item = await request.server.methods.db.item.getById({
id: request.params.itemId,
ignoreInactive: true,
session: {
credentials: request.auth.credentials,
artifacts: request.auth.artifacts
}
});

// load the tool config
const tool = request.server.settings.app.tools.get(`/${item.tool}`, {
target: request.params.target
});

// load the target config
const target = request.server.settings.app.targets.get(
`/${request.params.target}`
);

let displayOptionsSchema = {};

// load the display-options from the tool with appendItemToPayload
const displayOptionsWithItemResponse = await request.server.inject(
`/tools/${item.tool}/display-options-schema.json?appendItemToPayload=${request.params.itemId}`
);
if (displayOptionsWithItemResponse.statusCode === 200) {
displayOptionsSchema = getMergedSchema(
displayOptionsSchema,
displayOptionsWithItemResponse.result
);
}

// load the display-options from the tool without appendItemToPayload
const displayOptionsWithoutItemResponse = await request.server.inject(
`/tools/${item.tool}/display-options-schema.json`
);
if (displayOptionsWithoutItemResponse.statusCode === 200) {
displayOptionsSchema = getMergedSchema(
displayOptionsSchema,
displayOptionsWithoutItemResponse.result
);
}

// load the export-options from toolEndpoint config
if (tool.endpoint.displayOptionsSchema) {
if (tool.endpoint.displayOptionsSchema instanceof Function) {
toolEndpointDisplayOptionsSchema = await tool.endpoint.displayOptionsSchema.apply(
this,
[
{
item,
tool,
target,
displayOptionsSchema
}
]
);
if (toolEndpointDisplayOptionsSchema) {
displayOptionsSchema = getMergedSchema(
displayOptionsSchema,
toolEndpointDisplayOptionsSchema
);
}
} else {
displayOptionsSchema = getMergedSchema(
displayOptionsSchema,
tool.endpoint.displayOptionsSchema
);
}
}

// load the export options from target config
if (target.displayOptionsSchema) {
if (target.displayOptionsSchema instanceof Function) {
toolEndpointDisplayOptionsSchema = await target.displayOptionsSchema.apply(
this,
[
{
item,
tool,
target,
displayOptionsSchema
}
]
);
if (toolEndpointDisplayOptionsSchema) {
displayOptionsSchema = getMergedSchema(
displayOptionsSchema,
toolEndpointDisplayOptionsSchema
);
}
} else {
displayOptionsSchema = getMergedSchema(
displayOptionsSchema,
target.displayOptionsSchema
);
}
}

// return the complete export options schema
return displayOptionsSchema;
}
};
}
};
144 changes: 0 additions & 144 deletions plugins/core/base/routes/export-options-schema.js

This file was deleted.

0 comments on commit 5a7785f

Please sign in to comment.