mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-03-31 15:20:32 +08:00
feat: Import operator plugins in server.
This commit is contained in:
parent
7b2d4b1f64
commit
f913e9e261
74
.pnp.cjs
generated
74
.pnp.cjs
generated
@ -5159,6 +5159,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
||||
["@lowdefy/helpers", "workspace:packages/utils/helpers"],
|
||||
["@lowdefy/node-utils", "workspace:packages/utils/node-utils"],
|
||||
["@lowdefy/nunjucks", "workspace:packages/utils/nunjucks"],
|
||||
["@lowdefy/operators-js", "workspace:packages/plugins/operators/operators-js"],
|
||||
["@swc/cli", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.1.52"],
|
||||
["@swc/core", "npm:1.2.112"],
|
||||
["@swc/jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.2.9"],
|
||||
@ -5457,9 +5458,9 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
||||
["@lowdefy/operators-js", "workspace:packages/plugins/operators/operators-js"],
|
||||
["@lowdefy/helpers", "workspace:packages/utils/helpers"],
|
||||
["@lowdefy/operators", "workspace:packages/operators"],
|
||||
["@swc/cli", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.1.51"],
|
||||
["@swc/cli", "virtual:1ee5265af4e3059507503f93b555c542457968d137fd5e590fb5b6b6f398a27b24bfd891f81d0247bbdeaa9d30f59da5e90093206735e526ca7d8a60c0536045#npm:0.1.51"],
|
||||
["@swc/core", "npm:1.2.107"],
|
||||
["@swc/jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.2.5"],
|
||||
["@swc/jest", "virtual:1ee5265af4e3059507503f93b555c542457968d137fd5e590fb5b6b6f398a27b24bfd891f81d0247bbdeaa9d30f59da5e90093206735e526ca7d8a60c0536045#npm:0.2.5"],
|
||||
["jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:27.3.1"]
|
||||
],
|
||||
"linkType": "SOFT",
|
||||
@ -5491,6 +5492,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
||||
["@lowdefy/engine", "workspace:packages/engine"],
|
||||
["@lowdefy/helpers", "workspace:packages/utils/helpers"],
|
||||
["@lowdefy/layout", "workspace:packages/layout"],
|
||||
["@lowdefy/operators-js", "workspace:packages/plugins/operators/operators-js"],
|
||||
["@next/eslint-plugin-next", "npm:12.0.4"],
|
||||
["less", "npm:4.1.2"],
|
||||
["less-loader", "virtual:003bebd8b7a948d12b44e2c11a621884feb1891eea3645171e827971487f79396db9f7422bc411ccf3f90877e94ec86f5c3da70b96efb5daddb2ee3b35eae5c6#npm:10.2.0"],
|
||||
@ -6140,6 +6142,13 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
||||
}]
|
||||
]],
|
||||
["@swc/cli", [
|
||||
["npm:0.1.51", {
|
||||
"packageLocation": "./.yarn/cache/@swc-cli-npm-0.1.51-a93f90901e-348bf0aee8.zip/node_modules/@swc/cli/",
|
||||
"packageDependencies": [
|
||||
["@swc/cli", "npm:0.1.51"]
|
||||
],
|
||||
"linkType": "SOFT",
|
||||
}],
|
||||
["npm:0.1.52", {
|
||||
"packageLocation": "./.yarn/cache/@swc-cli-npm-0.1.52-72d75b6192-f1fe91deec.zip/node_modules/@swc/cli/",
|
||||
"packageDependencies": [
|
||||
@ -6147,6 +6156,27 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
||||
],
|
||||
"linkType": "SOFT",
|
||||
}],
|
||||
["virtual:1ee5265af4e3059507503f93b555c542457968d137fd5e590fb5b6b6f398a27b24bfd891f81d0247bbdeaa9d30f59da5e90093206735e526ca7d8a60c0536045#npm:0.1.51", {
|
||||
"packageLocation": "./.yarn/__virtual__/@swc-cli-virtual-339b16be67/0/cache/@swc-cli-npm-0.1.51-a93f90901e-348bf0aee8.zip/node_modules/@swc/cli/",
|
||||
"packageDependencies": [
|
||||
["@swc/cli", "virtual:1ee5265af4e3059507503f93b555c542457968d137fd5e590fb5b6b6f398a27b24bfd891f81d0247bbdeaa9d30f59da5e90093206735e526ca7d8a60c0536045#npm:0.1.51"],
|
||||
["@swc/core", "npm:1.2.107"],
|
||||
["@types/chokidar", null],
|
||||
["@types/swc__core", null],
|
||||
["chokidar", null],
|
||||
["commander", "npm:7.2.0"],
|
||||
["fast-glob", "npm:3.2.7"],
|
||||
["slash", "npm:3.0.0"],
|
||||
["source-map", "npm:0.7.3"]
|
||||
],
|
||||
"packagePeers": [
|
||||
"@swc/core",
|
||||
"@types/chokidar",
|
||||
"@types/swc__core",
|
||||
"chokidar"
|
||||
],
|
||||
"linkType": "HARD",
|
||||
}],
|
||||
["virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.1.52", {
|
||||
"packageLocation": "./.yarn/__virtual__/@swc-cli-virtual-4749531c82/0/cache/@swc-cli-npm-0.1.52-72d75b6192-f1fe91deec.zip/node_modules/@swc/cli/",
|
||||
"packageDependencies": [
|
||||
@ -6191,6 +6221,26 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
||||
}]
|
||||
]],
|
||||
["@swc/core", [
|
||||
["npm:1.2.107", {
|
||||
"packageLocation": "./.yarn/cache/@swc-core-npm-1.2.107-8b144c1b65-452fd087c7.zip/node_modules/@swc/core/",
|
||||
"packageDependencies": [
|
||||
["@swc/core", "npm:1.2.107"],
|
||||
["@node-rs/helper", "npm:1.2.1"],
|
||||
["@swc/core-android-arm64", "npm:1.2.112"],
|
||||
["@swc/core-darwin-arm64", "npm:1.2.112"],
|
||||
["@swc/core-darwin-x64", "npm:1.2.112"],
|
||||
["@swc/core-freebsd-x64", "npm:1.2.112"],
|
||||
["@swc/core-linux-arm-gnueabihf", "npm:1.2.112"],
|
||||
["@swc/core-linux-arm64-gnu", "npm:1.2.112"],
|
||||
["@swc/core-linux-arm64-musl", "npm:1.2.112"],
|
||||
["@swc/core-linux-x64-gnu", "npm:1.2.112"],
|
||||
["@swc/core-linux-x64-musl", "npm:1.2.112"],
|
||||
["@swc/core-win32-arm64-msvc", "npm:1.2.112"],
|
||||
["@swc/core-win32-ia32-msvc", "npm:1.2.112"],
|
||||
["@swc/core-win32-x64-msvc", "npm:1.2.112"]
|
||||
],
|
||||
"linkType": "HARD",
|
||||
}],
|
||||
["npm:1.2.112", {
|
||||
"packageLocation": "./.yarn/cache/@swc-core-npm-1.2.112-17b738a25e-4e60e542db.zip/node_modules/@swc/core/",
|
||||
"packageDependencies": [
|
||||
@ -6321,6 +6371,13 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
||||
}]
|
||||
]],
|
||||
["@swc/jest", [
|
||||
["npm:0.2.5", {
|
||||
"packageLocation": "./.yarn/cache/@swc-jest-npm-0.2.5-2355da0fa9-3a1b271762.zip/node_modules/@swc/jest/",
|
||||
"packageDependencies": [
|
||||
["@swc/jest", "npm:0.2.5"]
|
||||
],
|
||||
"linkType": "SOFT",
|
||||
}],
|
||||
["npm:0.2.9", {
|
||||
"packageLocation": "./.yarn/cache/@swc-jest-npm-0.2.9-15fb85e7dd-2463242d9e.zip/node_modules/@swc/jest/",
|
||||
"packageDependencies": [
|
||||
@ -6328,6 +6385,19 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
||||
],
|
||||
"linkType": "SOFT",
|
||||
}],
|
||||
["virtual:1ee5265af4e3059507503f93b555c542457968d137fd5e590fb5b6b6f398a27b24bfd891f81d0247bbdeaa9d30f59da5e90093206735e526ca7d8a60c0536045#npm:0.2.5", {
|
||||
"packageLocation": "./.yarn/__virtual__/@swc-jest-virtual-3fa9b01d34/0/cache/@swc-jest-npm-0.2.5-2355da0fa9-3a1b271762.zip/node_modules/@swc/jest/",
|
||||
"packageDependencies": [
|
||||
["@swc/jest", "virtual:1ee5265af4e3059507503f93b555c542457968d137fd5e590fb5b6b6f398a27b24bfd891f81d0247bbdeaa9d30f59da5e90093206735e526ca7d8a60c0536045#npm:0.2.5"],
|
||||
["@swc/core", "npm:1.2.107"],
|
||||
["@types/swc__core", null]
|
||||
],
|
||||
"packagePeers": [
|
||||
"@swc/core",
|
||||
"@types/swc__core"
|
||||
],
|
||||
"linkType": "HARD",
|
||||
}],
|
||||
["virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.2.9", {
|
||||
"packageLocation": "./.yarn/__virtual__/@swc-jest-virtual-2abfd859ef/0/cache/@swc-jest-npm-0.2.9-15fb85e7dd-2463242d9e.zip/node_modules/@swc/jest/",
|
||||
"packageDependencies": [
|
||||
|
BIN
.yarn/cache/@swc-cli-npm-0.1.51-a93f90901e-348bf0aee8.zip
vendored
Normal file
BIN
.yarn/cache/@swc-cli-npm-0.1.51-a93f90901e-348bf0aee8.zip
vendored
Normal file
Binary file not shown.
BIN
.yarn/cache/@swc-core-npm-1.2.107-8b144c1b65-452fd087c7.zip
vendored
Normal file
BIN
.yarn/cache/@swc-core-npm-1.2.107-8b144c1b65-452fd087c7.zip
vendored
Normal file
Binary file not shown.
BIN
.yarn/cache/@swc-jest-npm-0.2.5-2355da0fa9-3a1b271762.zip
vendored
Normal file
BIN
.yarn/cache/@swc-jest-npm-0.2.5-2355da0fa9-3a1b271762.zip
vendored
Normal file
Binary file not shown.
@ -16,7 +16,7 @@
|
||||
|
||||
import createReadConfigFile from './readConfigFile.js';
|
||||
|
||||
async function createApiContext({ buildDirectory, connections, logger, secrets }) {
|
||||
async function createApiContext({ buildDirectory, connections, logger, operators, secrets }) {
|
||||
const readConfigFile = createReadConfigFile({ buildDirectory });
|
||||
const config = await readConfigFile('config.json');
|
||||
return {
|
||||
@ -25,6 +25,7 @@ async function createApiContext({ buildDirectory, connections, logger, secrets }
|
||||
config,
|
||||
connections,
|
||||
logger,
|
||||
operators,
|
||||
readConfigFile,
|
||||
secrets,
|
||||
};
|
||||
|
@ -14,43 +14,40 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// import { NodeParser } from '@lowdefy/operators';
|
||||
import { NodeParser } from '@lowdefy/operators';
|
||||
|
||||
// import { RequestError } from '../../context/errors.js';
|
||||
import { RequestError } from '../../context/errors.js';
|
||||
|
||||
// async function evaluateOperators({ secrets, user }, { connectionConfig, payload, requestConfig }) {
|
||||
// const operatorsParser = new NodeParser({
|
||||
// payload,
|
||||
// secrets,
|
||||
// user,
|
||||
// });
|
||||
// await operatorsParser.init();
|
||||
// const { output: connectionProperties, errors: connectionErrors } = operatorsParser.parse({
|
||||
// input: connectionConfig.properties || {},
|
||||
// location: connectionConfig.connectionId,
|
||||
// });
|
||||
// if (connectionErrors.length > 0) {
|
||||
// throw new RequestError(connectionErrors[0]);
|
||||
// }
|
||||
async function evaluateOperators(
|
||||
{ operators, secrets, user },
|
||||
{ connectionConfig, payload, requestConfig }
|
||||
) {
|
||||
const operatorsParser = new NodeParser({
|
||||
operators,
|
||||
payload,
|
||||
secrets,
|
||||
user,
|
||||
});
|
||||
await operatorsParser.init();
|
||||
const { output: connectionProperties, errors: connectionErrors } = operatorsParser.parse({
|
||||
input: connectionConfig.properties || {},
|
||||
location: connectionConfig.connectionId,
|
||||
});
|
||||
if (connectionErrors.length > 0) {
|
||||
throw new RequestError(connectionErrors[0]);
|
||||
}
|
||||
|
||||
// const { output: requestProperties, errors: requestErrors } = operatorsParser.parse({
|
||||
// input: requestConfig.properties || {},
|
||||
// location: requestConfig.requestId,
|
||||
// });
|
||||
// if (requestErrors.length > 0) {
|
||||
// throw new RequestError(requestErrors[0]);
|
||||
// }
|
||||
const { output: requestProperties, errors: requestErrors } = operatorsParser.parse({
|
||||
input: requestConfig.properties || {},
|
||||
location: requestConfig.requestId,
|
||||
});
|
||||
if (requestErrors.length > 0) {
|
||||
throw new RequestError(requestErrors[0]);
|
||||
}
|
||||
|
||||
// return {
|
||||
// connectionProperties,
|
||||
// requestProperties,
|
||||
// };
|
||||
// }
|
||||
|
||||
async function evaluateOperators({ secrets, user }, { connectionConfig, payload, requestConfig }) {
|
||||
return {
|
||||
connectionProperties: connectionConfig.properties || {},
|
||||
requestProperties: requestConfig.properties || {},
|
||||
connectionProperties,
|
||||
requestProperties,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,7 @@
|
||||
"devDependencies": {
|
||||
"@lowdefy/blocks-basic": "4.0.0-alpha.4",
|
||||
"@lowdefy/connection-axios-http": "4.0.0-alpha.4",
|
||||
"@lowdefy/operators-js": "4.0.0-alpha.4",
|
||||
"@swc/cli": "0.1.52",
|
||||
"@swc/core": "1.2.112",
|
||||
"@swc/jest": "0.2.9",
|
||||
|
@ -70,19 +70,19 @@ function buildTypes({ components, context }) {
|
||||
typeClass: 'Request',
|
||||
});
|
||||
|
||||
// buildTypeClass({
|
||||
// counter: typeCounters.operators.client,
|
||||
// definitions: context.types.operators.client,
|
||||
// store: components.types.operators.client,
|
||||
// typeClass: 'Operator',
|
||||
// });
|
||||
buildTypeClass({
|
||||
counter: typeCounters.operators.client,
|
||||
definitions: context.types.operators.client,
|
||||
store: components.types.operators.client,
|
||||
typeClass: 'Operator',
|
||||
});
|
||||
|
||||
// buildTypeClass({
|
||||
// counter: typeCounters.operators.server,
|
||||
// definitions: context.types.operators.server,
|
||||
// store: components.types.operators.server,
|
||||
// typeClass: 'Operator',
|
||||
// });
|
||||
buildTypeClass({
|
||||
counter: typeCounters.operators.server,
|
||||
definitions: context.types.operators.server,
|
||||
store: components.types.operators.server,
|
||||
typeClass: 'Operator',
|
||||
});
|
||||
}
|
||||
|
||||
export default buildTypes;
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2020-2021 Lowdefy, Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { nunjucksFunction } from '@lowdefy/nunjucks';
|
||||
|
||||
const template = `{%- for import in imports -%}
|
||||
import { {{ import.type }} } from '{{ import.package }}/{{ importPath }}';
|
||||
{% endfor -%}
|
||||
export default {
|
||||
{% for import in imports -%}
|
||||
{{ import.type }},
|
||||
{% endfor -%}
|
||||
}`;
|
||||
|
||||
function generateImportFile({ types, importPath }) {
|
||||
const templateFn = nunjucksFunction(template);
|
||||
const imports = Object.keys(types).map((type) => ({
|
||||
type,
|
||||
...types[type],
|
||||
}));
|
||||
return templateFn({ imports, importPath });
|
||||
}
|
||||
|
||||
export default generateImportFile;
|
@ -14,27 +14,15 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { nunjucksFunction } from '@lowdefy/nunjucks';
|
||||
|
||||
const template = `{%- for block in blocks -%}
|
||||
import { {{ block.type }} } from '{{ block.package }}/blocks';
|
||||
{% endfor -%}
|
||||
export default {
|
||||
{% for block in blocks -%}
|
||||
{{ block.type }},
|
||||
{% endfor -%}
|
||||
};
|
||||
`;
|
||||
import generateImportFile from './generateImportFile.js';
|
||||
|
||||
async function writeBlockImports({ components, context }) {
|
||||
const templateFn = nunjucksFunction(template);
|
||||
const blocks = Object.keys(components.types.blocks).map((type) => ({
|
||||
type,
|
||||
...components.types.blocks[type],
|
||||
}));
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/blocks.js',
|
||||
content: templateFn({ blocks }),
|
||||
content: generateImportFile({
|
||||
types: components.types.blocks,
|
||||
importPath: 'blocks',
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -14,27 +14,15 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { nunjucksFunction } from '@lowdefy/nunjucks';
|
||||
|
||||
const template = `{%- for connection in connections -%}
|
||||
import { {{ connection.type }} } from '{{ connection.package }}/connections';
|
||||
{% endfor -%}
|
||||
export default {
|
||||
{% for connection in connections -%}
|
||||
{{ connection.type }},
|
||||
{% endfor -%}
|
||||
};
|
||||
`;
|
||||
import generateImportFile from './generateImportFile.js';
|
||||
|
||||
async function writeConnectionImports({ components, context }) {
|
||||
const templateFn = nunjucksFunction(template);
|
||||
const connections = Object.keys(components.types.connections).map((type) => ({
|
||||
type,
|
||||
...components.types.connections[type],
|
||||
}));
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/connections.js',
|
||||
content: templateFn({ connections }),
|
||||
content: generateImportFile({
|
||||
types: components.types.connections,
|
||||
importPath: 'connections',
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright 2020-2021 Lowdefy, Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import generateImportFile from './generateImportFile.js';
|
||||
|
||||
async function writeOperatorImports({ components, context }) {
|
||||
// TODO: import _not and _type for validation.
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/operatorsClient.js',
|
||||
content: generateImportFile({
|
||||
types: components.types.operators.client,
|
||||
importPath: 'operators/client',
|
||||
}),
|
||||
});
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/operatorsServer.js',
|
||||
content: generateImportFile({
|
||||
types: components.types.operators.server,
|
||||
importPath: 'operators/server',
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export default writeOperatorImports;
|
@ -44,6 +44,7 @@ import writeConnections from './build/writeConnections.js';
|
||||
import writeGlobal from './build/writeGlobal.js';
|
||||
import writeIconImports from './build/writePluginImports/writeIconImports.js';
|
||||
import writeMenus from './build/writeMenus.js';
|
||||
import writeOperatorImports from './build/writePluginImports/writeOperatorImports.js';
|
||||
import writePages from './build/writePages.js';
|
||||
import writeRequests from './build/writeRequests.js';
|
||||
import writeStyleImports from './build/writePluginImports/writeStyleImports.js';
|
||||
@ -106,6 +107,7 @@ async function build(options) {
|
||||
await writeTypes({ components, context });
|
||||
await writeBlockImports({ components, context });
|
||||
await writeConnectionImports({ components, context });
|
||||
await writeOperatorImports({ components, context });
|
||||
await writeStyleImports({ components, context });
|
||||
await writeIconImports({ components, context });
|
||||
await updateServerPackageJson({ components, context });
|
||||
|
@ -19,7 +19,11 @@ import path from 'path';
|
||||
import { type } from '@lowdefy/helpers';
|
||||
import { readFile, writeFile } from '@lowdefy/node-utils';
|
||||
|
||||
const defaultPackages = ['@lowdefy/blocks-basic', '@lowdefy/connection-axios-http'];
|
||||
const defaultPackages = [
|
||||
'@lowdefy/blocks-basic',
|
||||
'@lowdefy/connection-axios-http',
|
||||
'@lowdefy/operators-js',
|
||||
];
|
||||
|
||||
function createTypeDefinitions({ typeNames, store, packageName, version }) {
|
||||
if (type.isArray(typeNames)) {
|
||||
|
@ -29,8 +29,6 @@ const blockData = ({
|
||||
field,
|
||||
id,
|
||||
layout,
|
||||
meta,
|
||||
operators,
|
||||
pageId,
|
||||
properties,
|
||||
requests,
|
||||
@ -47,8 +45,6 @@ const blockData = ({
|
||||
field,
|
||||
id,
|
||||
layout,
|
||||
meta,
|
||||
operators,
|
||||
pageId,
|
||||
properties,
|
||||
requests,
|
||||
@ -72,7 +68,6 @@ async function getContext({ config, lowdefy }) {
|
||||
if (!lowdefy.inputs[id]) {
|
||||
lowdefy.inputs[id] = {};
|
||||
}
|
||||
const operatorsSet = new Set([...config.operators, '_not', '_type']);
|
||||
const ctx = {
|
||||
id: id,
|
||||
pageId: config.pageId,
|
||||
@ -81,13 +76,12 @@ async function getContext({ config, lowdefy }) {
|
||||
state: {},
|
||||
_internal: {
|
||||
lowdefy,
|
||||
operators: [...operatorsSet],
|
||||
rootBlock: blockData(config), // filter block to prevent circular structure
|
||||
update: () => {}, // Initialize update since Requests might call it during context creation
|
||||
},
|
||||
};
|
||||
const _internal = ctx._internal;
|
||||
_internal.parser = new WebParser({ context: ctx });
|
||||
_internal.parser = new WebParser({ context: ctx, operators: lowdefy._internal.operators });
|
||||
await _internal.parser.init();
|
||||
_internal.State = new State(ctx);
|
||||
_internal.Actions = new Actions(ctx);
|
||||
|
@ -45,7 +45,6 @@ test('memoize context', async () => {
|
||||
meta: {
|
||||
type: 'container',
|
||||
},
|
||||
operators: [],
|
||||
};
|
||||
const c1 = await getContext({ page, lowdefy });
|
||||
const c2 = await getContext({ page, lowdefy });
|
||||
@ -72,7 +71,6 @@ test('create context', async () => {
|
||||
meta: {
|
||||
type: 'container',
|
||||
},
|
||||
operators: [],
|
||||
};
|
||||
const context = await getContext({ page, lowdefy });
|
||||
expect(context.Actions).toBeDefined();
|
||||
@ -82,7 +80,6 @@ test('create context', async () => {
|
||||
expect(context.lowdefy).toEqual(lowdefy);
|
||||
expect(context.eventLog).toEqual([]);
|
||||
expect(context.id).toEqual('pageId');
|
||||
expect(context.operators).toBeInstanceOf(Array);
|
||||
expect(context.lowdefy.pageId).toEqual('pageId');
|
||||
expect(context.parser).toBeDefined();
|
||||
expect(context.requests).toEqual({});
|
||||
@ -112,7 +109,6 @@ test('create context, initialize input', async () => {
|
||||
meta: {
|
||||
type: 'container',
|
||||
},
|
||||
operators: [],
|
||||
};
|
||||
const context = await getContext({ page, lowdefy });
|
||||
expect(context.lowdefy.inputs.pageId).toEqual({});
|
||||
@ -132,7 +128,6 @@ test('update memoized context', async () => {
|
||||
meta: {
|
||||
type: 'container',
|
||||
},
|
||||
operators: [],
|
||||
};
|
||||
const mockUpdate = jest.fn();
|
||||
const c1 = await getContext({ page, lowdefy });
|
||||
@ -140,23 +135,3 @@ test('update memoized context', async () => {
|
||||
await getContext({ page, lowdefy });
|
||||
expect(mockUpdate.mock.calls.length).toBe(1);
|
||||
});
|
||||
|
||||
test('Add operators for required validation', async () => {
|
||||
const lowdefy = {
|
||||
client,
|
||||
contexts: {},
|
||||
inputs: {},
|
||||
pageId,
|
||||
updateBlock,
|
||||
};
|
||||
const page = {
|
||||
pageId: 'pageId',
|
||||
blockId: 'pageId',
|
||||
meta: {
|
||||
type: 'container',
|
||||
},
|
||||
operators: [],
|
||||
};
|
||||
const context = await getContext({ page, lowdefy });
|
||||
expect(context.operators).toEqual(expect.arrayContaining(['_not', '_type']));
|
||||
});
|
||||
|
@ -21,7 +21,7 @@ import Blocks from '../src/Blocks.js';
|
||||
import Requests from '../src/Requests.js';
|
||||
import State from '../src/State.js';
|
||||
|
||||
const testContext = async ({ lowdefy, rootBlock, initState = {} }) => {
|
||||
const testContext = async ({ lowdefy, operators, rootBlock, initState = {} }) => {
|
||||
const testLowdefy = {
|
||||
inputs: { test: {} },
|
||||
urlQuery: {},
|
||||
@ -44,8 +44,7 @@ const testContext = async ({ lowdefy, rootBlock, initState = {} }) => {
|
||||
},
|
||||
};
|
||||
const _internal = ctx._internal;
|
||||
_internal.parser = new WebParser({ context: ctx, contexts: {} });
|
||||
_internal.operators = Object.keys(_internal.parser.operators);
|
||||
_internal.parser = new WebParser({ context: ctx, contexts: {}, operators: operators || {} });
|
||||
await _internal.parser.init();
|
||||
_internal.State = new State(ctx);
|
||||
_internal.Actions = new Actions(ctx);
|
||||
|
@ -44,6 +44,7 @@
|
||||
"@lowdefy/engine": "4.0.0-alpha.4",
|
||||
"@lowdefy/helpers": "4.0.0-alpha.4",
|
||||
"@lowdefy/layout": "4.0.0-alpha.4",
|
||||
"@lowdefy/operators-js": "4.0.0-alpha.4",
|
||||
"next": "12.0.3",
|
||||
"next-auth": "4.0.0-beta.6",
|
||||
"react": "18.0.0-alpha-327d5c484-20211106",
|
||||
|
@ -18,6 +18,7 @@ import React from 'react';
|
||||
|
||||
import callRequest from '../utils/callRequest.js';
|
||||
import blockComponents from '../../build/plugins/blocks.js';
|
||||
import operators from '../../build/plugins/operatorsClient.js';
|
||||
import components from './components.js';
|
||||
|
||||
const LowdefyContext = ({ children }) => {
|
||||
@ -27,6 +28,7 @@ const LowdefyContext = ({ children }) => {
|
||||
callRequest,
|
||||
components,
|
||||
document,
|
||||
operators,
|
||||
updaters: {},
|
||||
window,
|
||||
displayMessage: ({ content }) => {
|
||||
|
@ -16,18 +16,21 @@
|
||||
|
||||
import { callRequest, createApiContext } from '@lowdefy/api';
|
||||
import connections from '../../../../../build/plugins/connections.js';
|
||||
import operators from '../../../../../build/plugins/operatorsServer.js';
|
||||
|
||||
export default async function handler(req, res) {
|
||||
try {
|
||||
if (req.method !== 'POST') {
|
||||
throw new Error('Only POST requests are supported.');
|
||||
}
|
||||
// TODO: configure API context
|
||||
const apiContext = await createApiContext({
|
||||
buildDirectory: './.lowdefy/build',
|
||||
buildDirectory: './build',
|
||||
connections,
|
||||
// TODO
|
||||
// TODO: use a logger like pino
|
||||
logger: console,
|
||||
// TODO
|
||||
operators,
|
||||
// TODO: get secrets
|
||||
secrets: {},
|
||||
});
|
||||
const { pageId, requestId } = req.query;
|
||||
|
112
yarn.lock
112
yarn.lock
@ -3492,6 +3492,7 @@ __metadata:
|
||||
"@lowdefy/helpers": 4.0.0-alpha.4
|
||||
"@lowdefy/node-utils": 4.0.0-alpha.4
|
||||
"@lowdefy/nunjucks": 4.0.0-alpha.4
|
||||
"@lowdefy/operators-js": 4.0.0-alpha.4
|
||||
"@swc/cli": 0.1.52
|
||||
"@swc/core": 1.2.112
|
||||
"@swc/jest": 0.2.9
|
||||
@ -3733,12 +3734,12 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@lowdefy/operators-js@workspace:packages/plugins/operators/operators-js":
|
||||
"@lowdefy/operators-js@4.0.0-alpha.4, @lowdefy/operators-js@workspace:packages/plugins/operators/operators-js":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@lowdefy/operators-js@workspace:packages/plugins/operators/operators-js"
|
||||
dependencies:
|
||||
"@lowdefy/helpers": 4.0.0-alpha.0
|
||||
"@lowdefy/operators": 4.0.0-alpha.0
|
||||
"@lowdefy/helpers": 4.0.0-alpha.4
|
||||
"@lowdefy/operators": 4.0.0-alpha.4
|
||||
"@swc/cli": 0.1.51
|
||||
"@swc/core": 1.2.107
|
||||
"@swc/jest": 0.2.5
|
||||
@ -3746,7 +3747,7 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@lowdefy/operators@4.0.0-alpha.0, @lowdefy/operators@workspace:packages/operators":
|
||||
"@lowdefy/operators@4.0.0-alpha.4, @lowdefy/operators@workspace:packages/operators":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@lowdefy/operators@workspace:packages/operators"
|
||||
dependencies:
|
||||
@ -3776,7 +3777,7 @@ __metadata:
|
||||
aws-sdk: 2.1021.0
|
||||
jest: 27.3.1
|
||||
peerDependencies:
|
||||
"@lowdefy/api": 4.0.0-alpha.0
|
||||
"@lowdefy/api": 4.0.0-alpha.4
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@ -3790,6 +3791,7 @@ __metadata:
|
||||
"@lowdefy/engine": 4.0.0-alpha.4
|
||||
"@lowdefy/helpers": 4.0.0-alpha.4
|
||||
"@lowdefy/layout": 4.0.0-alpha.4
|
||||
"@lowdefy/operators-js": 4.0.0-alpha.4
|
||||
"@next/eslint-plugin-next": 12.0.4
|
||||
less: 4.1.2
|
||||
less-loader: 10.2.0
|
||||
@ -4293,6 +4295,27 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/cli@npm:0.1.51":
|
||||
version: 0.1.51
|
||||
resolution: "@swc/cli@npm:0.1.51"
|
||||
dependencies:
|
||||
commander: ^7.1.0
|
||||
fast-glob: ^3.2.5
|
||||
slash: 3.0.0
|
||||
source-map: ^0.7.3
|
||||
peerDependencies:
|
||||
"@swc/core": ^1.2.66
|
||||
chokidar: ^3.5.1
|
||||
peerDependenciesMeta:
|
||||
chokidar:
|
||||
optional: true
|
||||
bin:
|
||||
spack: bin/spack.js
|
||||
swc: bin/swc.js
|
||||
checksum: 348bf0aee8e0cab567b75061f71ccbeff4964d9d6af03760f06641dbdb3f753865d2f0806d9adf805f19b9449a9665fdc4260d907246ab045156f427fa6a1ecd
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/cli@npm:0.1.52":
|
||||
version: 0.1.52
|
||||
resolution: "@swc/cli@npm:0.1.52"
|
||||
@ -4314,90 +4337,136 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-android-arm64@npm:^1.2.112":
|
||||
"@swc/core-android-arm64@npm:^1.2.107, @swc/core-android-arm64@npm:^1.2.112":
|
||||
version: 1.2.112
|
||||
resolution: "@swc/core-android-arm64@npm:1.2.112"
|
||||
conditions: os=android & cpu=arm64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-darwin-arm64@npm:^1.2.112":
|
||||
"@swc/core-darwin-arm64@npm:^1.2.107, @swc/core-darwin-arm64@npm:^1.2.112":
|
||||
version: 1.2.112
|
||||
resolution: "@swc/core-darwin-arm64@npm:1.2.112"
|
||||
conditions: os=darwin & cpu=arm64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-darwin-x64@npm:^1.2.112":
|
||||
"@swc/core-darwin-x64@npm:^1.2.107, @swc/core-darwin-x64@npm:^1.2.112":
|
||||
version: 1.2.112
|
||||
resolution: "@swc/core-darwin-x64@npm:1.2.112"
|
||||
conditions: os=darwin & cpu=x64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-freebsd-x64@npm:^1.2.112":
|
||||
"@swc/core-freebsd-x64@npm:^1.2.107, @swc/core-freebsd-x64@npm:^1.2.112":
|
||||
version: 1.2.112
|
||||
resolution: "@swc/core-freebsd-x64@npm:1.2.112"
|
||||
conditions: os=freebsd & cpu=x64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-linux-arm-gnueabihf@npm:^1.2.112":
|
||||
"@swc/core-linux-arm-gnueabihf@npm:^1.2.107, @swc/core-linux-arm-gnueabihf@npm:^1.2.112":
|
||||
version: 1.2.112
|
||||
resolution: "@swc/core-linux-arm-gnueabihf@npm:1.2.112"
|
||||
conditions: os=linux & cpu=arm
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-linux-arm64-gnu@npm:^1.2.112":
|
||||
"@swc/core-linux-arm64-gnu@npm:^1.2.107, @swc/core-linux-arm64-gnu@npm:^1.2.112":
|
||||
version: 1.2.112
|
||||
resolution: "@swc/core-linux-arm64-gnu@npm:1.2.112"
|
||||
conditions: os=linux & cpu=arm64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-linux-arm64-musl@npm:^1.2.112":
|
||||
"@swc/core-linux-arm64-musl@npm:^1.2.107, @swc/core-linux-arm64-musl@npm:^1.2.112":
|
||||
version: 1.2.112
|
||||
resolution: "@swc/core-linux-arm64-musl@npm:1.2.112"
|
||||
conditions: os=linux & cpu=arm64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-linux-x64-gnu@npm:^1.2.112":
|
||||
"@swc/core-linux-x64-gnu@npm:^1.2.107, @swc/core-linux-x64-gnu@npm:^1.2.112":
|
||||
version: 1.2.112
|
||||
resolution: "@swc/core-linux-x64-gnu@npm:1.2.112"
|
||||
conditions: os=linux & cpu=x64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-linux-x64-musl@npm:^1.2.112":
|
||||
"@swc/core-linux-x64-musl@npm:^1.2.107, @swc/core-linux-x64-musl@npm:^1.2.112":
|
||||
version: 1.2.112
|
||||
resolution: "@swc/core-linux-x64-musl@npm:1.2.112"
|
||||
conditions: os=linux & cpu=x64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-win32-arm64-msvc@npm:^1.2.112":
|
||||
"@swc/core-win32-arm64-msvc@npm:^1.2.107, @swc/core-win32-arm64-msvc@npm:^1.2.112":
|
||||
version: 1.2.112
|
||||
resolution: "@swc/core-win32-arm64-msvc@npm:1.2.112"
|
||||
conditions: os=win32 & cpu=arm64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-win32-ia32-msvc@npm:^1.2.112":
|
||||
"@swc/core-win32-ia32-msvc@npm:^1.2.107, @swc/core-win32-ia32-msvc@npm:^1.2.112":
|
||||
version: 1.2.112
|
||||
resolution: "@swc/core-win32-ia32-msvc@npm:1.2.112"
|
||||
conditions: os=win32 & cpu=ia32
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-win32-x64-msvc@npm:^1.2.112":
|
||||
"@swc/core-win32-x64-msvc@npm:^1.2.107, @swc/core-win32-x64-msvc@npm:^1.2.112":
|
||||
version: 1.2.112
|
||||
resolution: "@swc/core-win32-x64-msvc@npm:1.2.112"
|
||||
conditions: os=win32 & cpu=x64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core@npm:1.2.107":
|
||||
version: 1.2.107
|
||||
resolution: "@swc/core@npm:1.2.107"
|
||||
dependencies:
|
||||
"@node-rs/helper": ^1.0.0
|
||||
"@swc/core-android-arm64": ^1.2.107
|
||||
"@swc/core-darwin-arm64": ^1.2.107
|
||||
"@swc/core-darwin-x64": ^1.2.107
|
||||
"@swc/core-freebsd-x64": ^1.2.107
|
||||
"@swc/core-linux-arm-gnueabihf": ^1.2.107
|
||||
"@swc/core-linux-arm64-gnu": ^1.2.107
|
||||
"@swc/core-linux-arm64-musl": ^1.2.107
|
||||
"@swc/core-linux-x64-gnu": ^1.2.107
|
||||
"@swc/core-linux-x64-musl": ^1.2.107
|
||||
"@swc/core-win32-arm64-msvc": ^1.2.107
|
||||
"@swc/core-win32-ia32-msvc": ^1.2.107
|
||||
"@swc/core-win32-x64-msvc": ^1.2.107
|
||||
dependenciesMeta:
|
||||
"@swc/core-android-arm64":
|
||||
optional: true
|
||||
"@swc/core-darwin-arm64":
|
||||
optional: true
|
||||
"@swc/core-darwin-x64":
|
||||
optional: true
|
||||
"@swc/core-freebsd-x64":
|
||||
optional: true
|
||||
"@swc/core-linux-arm-gnueabihf":
|
||||
optional: true
|
||||
"@swc/core-linux-arm64-gnu":
|
||||
optional: true
|
||||
"@swc/core-linux-arm64-musl":
|
||||
optional: true
|
||||
"@swc/core-linux-x64-gnu":
|
||||
optional: true
|
||||
"@swc/core-linux-x64-musl":
|
||||
optional: true
|
||||
"@swc/core-win32-arm64-msvc":
|
||||
optional: true
|
||||
"@swc/core-win32-ia32-msvc":
|
||||
optional: true
|
||||
"@swc/core-win32-x64-msvc":
|
||||
optional: true
|
||||
checksum: 452fd087c7c16caa1bb51c48847b43e5ec57f44dad24b1d5ca64849d050343caeb0942db126296f799778eaf455274a5a25e4b0a9334bf49657ed758babaa846
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core@npm:1.2.112":
|
||||
version: 1.2.112
|
||||
resolution: "@swc/core@npm:1.2.112"
|
||||
@ -4444,6 +4513,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/jest@npm:0.2.5":
|
||||
version: 0.2.5
|
||||
resolution: "@swc/jest@npm:0.2.5"
|
||||
peerDependencies:
|
||||
"@swc/core": "*"
|
||||
checksum: 3a1b2717623a1419f0f3fc04bc7e2cd112a084e1763a33d9df06bda9431b6dd67bff8dba358162b23f1911f9a0e67422f09afd0983c77b4dc6f9fbde7a712bd8
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/jest@npm:0.2.9":
|
||||
version: 0.2.9
|
||||
resolution: "@swc/jest@npm:0.2.9"
|
||||
|
Loading…
x
Reference in New Issue
Block a user