mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-11 14:20:07 +08:00
Merge branch 'v4' into v4-connection-stripe
This commit is contained in:
commit
f322e53245
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,7 +21,6 @@ packages/server-dev/build/**
|
||||
|
||||
.DS_Store
|
||||
|
||||
packages/build/src/test/writeFile.txt
|
||||
packages/build/build/**
|
||||
|
||||
packages/plugins/connections/connection-mongodb/mongod-*
|
||||
|
3
.pnp.cjs
generated
3
.pnp.cjs
generated
@ -5207,7 +5207,10 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
||||
["@lowdefy/blocks-markdown", "workspace:packages/plugins/blocks/blocks-markdown"],
|
||||
["@lowdefy/connection-axios-http", "workspace:packages/plugins/connections/connection-axios-http"],
|
||||
["@lowdefy/connection-elasticsearch", "workspace:packages/plugins/connections/connection-elasticsearch"],
|
||||
["@lowdefy/connection-knex", "workspace:packages/plugins/connections/connection-knex"],
|
||||
["@lowdefy/connection-mongodb", "workspace:packages/plugins/connections/connection-mongodb"],
|
||||
["@lowdefy/connection-redis", "workspace:packages/plugins/connections/connection-redis"],
|
||||
["@lowdefy/connection-sendgrid", "workspace:packages/plugins/connections/connection-sendgrid"],
|
||||
["@lowdefy/connection-stripe", "workspace:packages/plugins/connections/connection-stripe"],
|
||||
["@lowdefy/helpers", "workspace:packages/utils/helpers"],
|
||||
["@lowdefy/node-utils", "workspace:packages/utils/node-utils"],
|
||||
|
@ -64,7 +64,10 @@
|
||||
"@lowdefy/blocks-markdown": "4.0.0-alpha.6",
|
||||
"@lowdefy/connection-axios-http": "4.0.0-alpha.6",
|
||||
"@lowdefy/connection-elasticsearch": "4.0.0-alpha.6",
|
||||
"@lowdefy/connection-knex": "4.0.0-alpha.6",
|
||||
"@lowdefy/connection-mongodb": "4.0.0-alpha.6",
|
||||
"@lowdefy/connection-redis": "4.0.0-alpha.6",
|
||||
"@lowdefy/connection-sendgrid": "4.0.0-alpha.6",
|
||||
"@lowdefy/connection-stripe": "4.0.0-alpha.6",
|
||||
"@lowdefy/operators-change-case": "4.0.0-alpha.6",
|
||||
"@lowdefy/operators-diff": "4.0.0-alpha.6",
|
||||
@ -81,4 +84,4 @@
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
||||
}
|
@ -62,7 +62,6 @@ test('addDefaultPages, no pages array', async () => {
|
||||
},
|
||||
id: 'home',
|
||||
properties: {
|
||||
icon: 'HomeOutlined',
|
||||
title: 'Go to home page',
|
||||
type: 'Link',
|
||||
},
|
||||
@ -109,7 +108,6 @@ test('addDefaultPages, empty pages array', async () => {
|
||||
},
|
||||
id: 'home',
|
||||
properties: {
|
||||
icon: 'HomeOutlined',
|
||||
title: 'Go to home page',
|
||||
type: 'Link',
|
||||
},
|
||||
@ -160,7 +158,6 @@ test('addDefaultPages, pages without 404 page', async () => {
|
||||
},
|
||||
id: 'home',
|
||||
properties: {
|
||||
icon: 'HomeOutlined',
|
||||
title: 'Go to home page',
|
||||
type: 'Link',
|
||||
},
|
||||
|
@ -38,6 +38,7 @@ test('buildAuth default', async () => {
|
||||
roles: {},
|
||||
},
|
||||
},
|
||||
theme: {},
|
||||
},
|
||||
pages: [
|
||||
{ id: 'a', type: 'Context', auth: { public: true } },
|
||||
@ -59,6 +60,7 @@ test('buildAuth no pages', async () => {
|
||||
roles: {},
|
||||
},
|
||||
},
|
||||
theme: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
@ -89,6 +91,7 @@ test('buildAuth all protected, some public', async () => {
|
||||
roles: {},
|
||||
},
|
||||
},
|
||||
theme: {},
|
||||
},
|
||||
pages: [
|
||||
{ id: 'a', type: 'Context', auth: { public: true } },
|
||||
@ -124,6 +127,7 @@ test('buildAuth all public, some protected', async () => {
|
||||
roles: {},
|
||||
},
|
||||
},
|
||||
theme: {},
|
||||
},
|
||||
pages: [
|
||||
{ id: 'a', type: 'Context', auth: { public: false } },
|
||||
@ -159,6 +163,7 @@ test('buildAuth all public', async () => {
|
||||
roles: {},
|
||||
},
|
||||
},
|
||||
theme: {},
|
||||
},
|
||||
pages: [
|
||||
{ id: 'a', type: 'Context', auth: { public: true } },
|
||||
@ -194,6 +199,7 @@ test('buildAuth all protected', async () => {
|
||||
roles: {},
|
||||
},
|
||||
},
|
||||
theme: {},
|
||||
},
|
||||
pages: [
|
||||
{ id: 'a', type: 'Context', auth: { public: false } },
|
||||
@ -233,6 +239,7 @@ test('buildAuth roles', async () => {
|
||||
},
|
||||
},
|
||||
},
|
||||
theme: {},
|
||||
},
|
||||
pages: [
|
||||
{ id: 'page1', type: 'Context', auth: { public: false, roles: ['role1', 'role2'] } },
|
||||
@ -288,6 +295,7 @@ test('buildAuth roles and protected pages array', async () => {
|
||||
protected: ['page1'],
|
||||
},
|
||||
},
|
||||
theme: {},
|
||||
},
|
||||
pages: [{ id: 'page1', type: 'Context', auth: { public: false, roles: ['role1'] } }],
|
||||
});
|
||||
@ -319,6 +327,7 @@ test('buildAuth roles and protected true', async () => {
|
||||
protected: true,
|
||||
},
|
||||
},
|
||||
theme: {},
|
||||
},
|
||||
pages: [{ id: 'page1', type: 'Context', auth: { public: false, roles: ['role1'] } }],
|
||||
});
|
||||
|
@ -17,7 +17,7 @@
|
||||
import { cleanDirectory } from '@lowdefy/node-utils';
|
||||
|
||||
async function cleanBuildDirectory({ context }) {
|
||||
return cleanDirectory(context.directories.build);
|
||||
await cleanDirectory(context.directories.build);
|
||||
}
|
||||
|
||||
export default cleanBuildDirectory;
|
||||
|
@ -15,10 +15,7 @@
|
||||
*/
|
||||
|
||||
async function writeApp({ components, context }) {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'app.json',
|
||||
content: JSON.stringify(components.app || {}, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact('app.json', JSON.stringify(components.app || {}, null, 2));
|
||||
}
|
||||
|
||||
export default writeApp;
|
||||
|
@ -34,12 +34,10 @@ test('writeApp', async () => {
|
||||
await writeApp({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'app.json',
|
||||
content: `{
|
||||
'app.json',
|
||||
`{
|
||||
"key": "value"
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -49,25 +47,11 @@ test('writeApp empty config', async () => {
|
||||
app: {},
|
||||
};
|
||||
await writeApp({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'app.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['app.json', `{}`]]);
|
||||
});
|
||||
|
||||
test('writeApp config undefined', async () => {
|
||||
const components = {};
|
||||
await writeApp({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'app.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['app.json', `{}`]]);
|
||||
});
|
||||
|
@ -15,10 +15,7 @@
|
||||
*/
|
||||
|
||||
async function writeConfig({ components, context }) {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'config.json',
|
||||
content: JSON.stringify(components.config || {}, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact('config.json', JSON.stringify(components.config || {}, null, 2));
|
||||
}
|
||||
|
||||
export default writeConfig;
|
||||
|
@ -34,12 +34,10 @@ test('writeConfig', async () => {
|
||||
await writeConfig({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'config.json',
|
||||
content: `{
|
||||
'config.json',
|
||||
`{
|
||||
"key": "value"
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -49,25 +47,11 @@ test('writeConfig empty config', async () => {
|
||||
config: {},
|
||||
};
|
||||
await writeConfig({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'config.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['config.json', `{}`]]);
|
||||
});
|
||||
|
||||
test('writeConfig config undefined', async () => {
|
||||
const components = {};
|
||||
await writeConfig({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'config.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['config.json', `{}`]]);
|
||||
});
|
||||
|
@ -22,10 +22,10 @@ async function writeConnections({ components, context }) {
|
||||
throw new Error(`Connections is not an array.`);
|
||||
}
|
||||
const writePromises = components.connections.map(async (connection) => {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: `connections/${connection.connectionId}.json`,
|
||||
content: JSON.stringify(connection, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact(
|
||||
`connections/${connection.connectionId}.json`,
|
||||
JSON.stringify(connection, null, 2)
|
||||
);
|
||||
});
|
||||
return Promise.all(writePromises);
|
||||
}
|
||||
|
@ -40,16 +40,14 @@ test('writeConnections write connection', async () => {
|
||||
await writeConnections({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'connections/connection1.json',
|
||||
content: `{
|
||||
'connections/connection1.json',
|
||||
`{
|
||||
"id": "connection:connection1",
|
||||
"connectionId": "connection1",
|
||||
"properties": {
|
||||
"prop": "val"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -70,22 +68,18 @@ test('writeConnections multiple connection', async () => {
|
||||
await writeConnections({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'connections/connection1.json',
|
||||
content: `{
|
||||
'connections/connection1.json',
|
||||
`{
|
||||
"id": "connection:connection1",
|
||||
"connectionId": "connection1"
|
||||
}`,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
filePath: 'connections/connection2.json',
|
||||
content: `{
|
||||
'connections/connection2.json',
|
||||
`{
|
||||
"id": "connection:connection2",
|
||||
"connectionId": "connection2"
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
@ -23,10 +23,7 @@ async function writeGlobal({ components, context }) {
|
||||
if (!type.isObject(components.global)) {
|
||||
throw new Error('Global is not an object.');
|
||||
}
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'global.json',
|
||||
content: JSON.stringify(components.global, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact('global.json', JSON.stringify(components.global, null, 2));
|
||||
}
|
||||
|
||||
export default writeGlobal;
|
||||
|
@ -34,12 +34,10 @@ test('writeGlobal', async () => {
|
||||
await writeGlobal({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'global.json',
|
||||
content: `{
|
||||
'global.json',
|
||||
`{
|
||||
"key": "value"
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -49,27 +47,13 @@ test('writeGlobal empty global', async () => {
|
||||
global: {},
|
||||
};
|
||||
await writeGlobal({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'global.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['global.json', `{}`]]);
|
||||
});
|
||||
|
||||
test('writeGlobal global undefined', async () => {
|
||||
const components = {};
|
||||
await writeGlobal({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'global.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['global.json', `{}`]]);
|
||||
});
|
||||
|
||||
test('writeGlobal global not an object', async () => {
|
||||
|
@ -20,10 +20,7 @@ async function writeMenus({ components, context }) {
|
||||
if (!type.isArray(components.menus)) {
|
||||
throw new Error('Menus is not an array.');
|
||||
}
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'menus.json',
|
||||
content: JSON.stringify(components.menus, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact('menus.json', JSON.stringify(components.menus, null, 2));
|
||||
}
|
||||
|
||||
export default writeMenus;
|
||||
|
@ -38,16 +38,14 @@ test('writeMenus', async () => {
|
||||
await writeMenus({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'menus.json',
|
||||
content: `[
|
||||
'menus.json',
|
||||
`[
|
||||
{
|
||||
"id": "menu:default",
|
||||
"menuId": "default",
|
||||
"links": []
|
||||
}
|
||||
]`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -57,14 +55,7 @@ test('writeMenus empty menus', async () => {
|
||||
menus: [],
|
||||
};
|
||||
await writeMenus({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'menus.json',
|
||||
content: `[]`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['menus.json', `[]`]]);
|
||||
});
|
||||
|
||||
test('writeMenus menus undefined', async () => {
|
||||
|
@ -20,10 +20,10 @@ async function writePage({ page, context }) {
|
||||
if (!type.isObject(page)) {
|
||||
throw new Error(`Page is not an object. Received ${JSON.stringify(page)}`);
|
||||
}
|
||||
await context.writeBuildArtifact({
|
||||
filePath: `pages/${page.pageId}/${page.pageId}.json`,
|
||||
content: JSON.stringify(page, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact(
|
||||
`pages/${page.pageId}/${page.pageId}.json`,
|
||||
JSON.stringify(page, null, 2)
|
||||
);
|
||||
}
|
||||
|
||||
async function writePages({ components, context }) {
|
||||
|
@ -39,15 +39,13 @@ test('writePages write page', async () => {
|
||||
await writePages({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page1/page1.json',
|
||||
content: `{
|
||||
'pages/page1/page1.json',
|
||||
`{
|
||||
"id": "page:page1",
|
||||
"pageId": "page1",
|
||||
"blockId": "page1",
|
||||
"requests": []
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -72,26 +70,22 @@ test('writePages multiple pages', async () => {
|
||||
await writePages({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page1/page1.json',
|
||||
content: `{
|
||||
'pages/page1/page1.json',
|
||||
`{
|
||||
"id": "page:page1",
|
||||
"pageId": "page1",
|
||||
"blockId": "page1",
|
||||
"requests": []
|
||||
}`,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page2/page2.json',
|
||||
content: `{
|
||||
'pages/page2/page2.json',
|
||||
`{
|
||||
"id": "page:page2",
|
||||
"pageId": "page2",
|
||||
"blockId": "page2",
|
||||
"requests": []
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
@ -17,13 +17,13 @@
|
||||
import generateImportFile from './generateImportFile.js';
|
||||
|
||||
async function writeBlockImports({ components, context }) {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/blocks.js',
|
||||
content: generateImportFile({
|
||||
await context.writeBuildArtifact(
|
||||
'plugins/blocks.js',
|
||||
generateImportFile({
|
||||
types: components.types.blocks,
|
||||
importPath: 'blocks',
|
||||
}),
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export default writeBlockImports;
|
||||
|
@ -17,13 +17,13 @@
|
||||
import generateImportFile from './generateImportFile.js';
|
||||
|
||||
async function writeConnectionImports({ components, context }) {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/connections.js',
|
||||
content: generateImportFile({
|
||||
await context.writeBuildArtifact(
|
||||
'plugins/connections.js',
|
||||
generateImportFile({
|
||||
types: components.types.connections,
|
||||
importPath: 'connections',
|
||||
}),
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export default writeConnectionImports;
|
||||
|
@ -28,10 +28,7 @@ export default {
|
||||
|
||||
async function writeIconImports({ components, context }) {
|
||||
const templateFn = nunjucksFunction(template);
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/icons.js',
|
||||
content: templateFn({ packages: components.icons }),
|
||||
});
|
||||
await context.writeBuildArtifact('plugins/icons.js', templateFn({ packages: components.icons }));
|
||||
}
|
||||
|
||||
export default writeIconImports;
|
||||
|
@ -18,20 +18,20 @@ 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({
|
||||
await context.writeBuildArtifact(
|
||||
'plugins/operatorsClient.js',
|
||||
generateImportFile({
|
||||
types: components.types.operators.client,
|
||||
importPath: 'operators/client',
|
||||
}),
|
||||
});
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/operatorsServer.js',
|
||||
content: generateImportFile({
|
||||
})
|
||||
);
|
||||
await context.writeBuildArtifact(
|
||||
'plugins/operatorsServer.js',
|
||||
generateImportFile({
|
||||
types: components.types.operators.server,
|
||||
importPath: 'operators/server',
|
||||
}),
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export default writeOperatorImports;
|
||||
|
@ -24,10 +24,10 @@ const template = `@import '@lowdefy/layout/style.less';
|
||||
|
||||
async function writeStyleImports({ components, context }) {
|
||||
const templateFn = nunjucksFunction(template);
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/styles.less',
|
||||
content: templateFn({ styles: components.styles }),
|
||||
});
|
||||
await context.writeBuildArtifact(
|
||||
'plugins/styles.less',
|
||||
templateFn({ styles: components.styles })
|
||||
);
|
||||
}
|
||||
|
||||
export default writeStyleImports;
|
||||
|
@ -19,10 +19,10 @@ import { type } from '@lowdefy/helpers';
|
||||
async function writeRequestsOnPage({ page, context }) {
|
||||
return Promise.all(
|
||||
page.requests.map(async (request) => {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: `pages/${page.pageId}/requests/${request.requestId}.json`,
|
||||
content: JSON.stringify(request, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact(
|
||||
`pages/${page.pageId}/requests/${request.requestId}.json`,
|
||||
JSON.stringify(request, null, 2)
|
||||
);
|
||||
delete request.properties;
|
||||
delete request.type;
|
||||
delete request.connectionId;
|
||||
|
@ -49,9 +49,8 @@ test('writeRequests write request', async () => {
|
||||
await writeRequests({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page1/requests/request1.json',
|
||||
content: `{
|
||||
'pages/page1/requests/request1.json',
|
||||
`{
|
||||
"id": "request:page1:request1",
|
||||
"requestId": "request1",
|
||||
"pageId": "page1",
|
||||
@ -65,7 +64,6 @@ test('writeRequests write request', async () => {
|
||||
"key": "value"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -104,9 +102,8 @@ test('writeRequests write multiple requests on a page', async () => {
|
||||
await writeRequests({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page1/requests/request1.json',
|
||||
content: `{
|
||||
'pages/page1/requests/request1.json',
|
||||
`{
|
||||
"id": "request:page1:request1",
|
||||
"requestId": "request1",
|
||||
"pageId": "page1",
|
||||
@ -120,12 +117,10 @@ test('writeRequests write multiple requests on a page', async () => {
|
||||
"key": "value"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page1/requests/request2.json',
|
||||
content: `{
|
||||
'pages/page1/requests/request2.json',
|
||||
`{
|
||||
"id": "request:page1:request2",
|
||||
"requestId": "request2",
|
||||
"pageId": "page1",
|
||||
@ -139,7 +134,6 @@ test('writeRequests write multiple requests on a page', async () => {
|
||||
"key": "value"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -184,9 +178,8 @@ test('writeRequests write requests on a for multiple pages', async () => {
|
||||
await writeRequests({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page1/requests/request1.json',
|
||||
content: `{
|
||||
'pages/page1/requests/request1.json',
|
||||
`{
|
||||
"id": "request:page1:request1",
|
||||
"requestId": "request1",
|
||||
"pageId": "page1",
|
||||
@ -200,12 +193,10 @@ test('writeRequests write requests on a for multiple pages', async () => {
|
||||
"key": "value"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page2/requests/request1.json',
|
||||
content: `{
|
||||
'pages/page2/requests/request1.json',
|
||||
`{
|
||||
"id": "request:page2:request1",
|
||||
"requestId": "request1",
|
||||
"pageId": "page2",
|
||||
@ -219,7 +210,6 @@ test('writeRequests write requests on a for multiple pages', async () => {
|
||||
"key": "value"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
@ -15,10 +15,7 @@
|
||||
*/
|
||||
|
||||
async function writeTypes({ components, context }) {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'types.json',
|
||||
content: JSON.stringify(components.types, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact('types.json', JSON.stringify(components.types, null, 2));
|
||||
}
|
||||
|
||||
export default writeTypes;
|
||||
|
@ -19,8 +19,8 @@
|
||||
import { readFile } from '@lowdefy/node-utils';
|
||||
|
||||
import createCounter from './utils/createCounter.js';
|
||||
import createReadConfigFile from './utils/files/readConfigFile.js';
|
||||
import createWriteBuildArtifact from './utils/files/writeBuildArtifact.js';
|
||||
import createReadConfigFile from './utils/readConfigFile.js';
|
||||
import createWriteBuildArtifact from './utils/writeBuildArtifact.js';
|
||||
|
||||
import addDefaultPages from './build/addDefaultPages/addDefaultPages.js';
|
||||
import buildAuth from './build/buildAuth/buildAuth.js';
|
||||
|
@ -28,7 +28,10 @@ const defaultPackages = [
|
||||
'@lowdefy/blocks-markdown',
|
||||
'@lowdefy/connection-axios-http',
|
||||
'@lowdefy/connection-elasticsearch',
|
||||
'@lowdefy/connection-knex',
|
||||
'@lowdefy/connection-mongodb',
|
||||
'@lowdefy/connection-redis',
|
||||
'@lowdefy/connection-sendgrid',
|
||||
'@lowdefy/connection-stripe',
|
||||
'@lowdefy/operators-change-case',
|
||||
// '@lowdefy/operators-diff',
|
||||
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
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 fs from 'fs';
|
||||
import path from 'path';
|
||||
import createWriteBuildArtifact from './writeBuildArtifact.js';
|
||||
|
||||
const directories = { build: path.resolve(process.cwd(), 'src/test/fileSetter') };
|
||||
|
||||
test('writeFile', async () => {
|
||||
const filePath = path.resolve(directories.build, 'writeFile.txt');
|
||||
try {
|
||||
fs.unlinkSync(filePath);
|
||||
} catch (error) {
|
||||
//pass
|
||||
}
|
||||
expect(fs.existsSync(filePath)).toBe(false);
|
||||
const writeBuildArtifact = createWriteBuildArtifact({ directories });
|
||||
|
||||
await writeBuildArtifact({
|
||||
filePath: 'writeFile.txt',
|
||||
content: 'Test fileSetter file',
|
||||
});
|
||||
const res = fs.readFileSync(filePath, 'utf8');
|
||||
expect(res).toEqual('Test fileSetter file');
|
||||
try {
|
||||
fs.unlinkSync(filePath);
|
||||
} catch (error) {
|
||||
//pass
|
||||
}
|
||||
});
|
@ -18,8 +18,8 @@ import path from 'path';
|
||||
import { writeFile } from '@lowdefy/node-utils';
|
||||
|
||||
function createWriteBuildArtifact({ directories }) {
|
||||
async function writeBuildArtifact({ filePath, content }) {
|
||||
return writeFile(path.resolve(directories.build, filePath), content);
|
||||
async function writeBuildArtifact(filePath, content) {
|
||||
await writeFile(path.join(directories.build, filePath), content);
|
||||
}
|
||||
return writeBuildArtifact;
|
||||
}
|
33
packages/build/src/utils/writeBuildArtifact.test.js
Normal file
33
packages/build/src/utils/writeBuildArtifact.test.js
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
jest.mock('@lowdefy/node-utils', () => {
|
||||
return {
|
||||
writeFile: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
const directories = { build: '/build' };
|
||||
|
||||
test('Write build artifact.', async () => {
|
||||
const nodeUtils = await import('@lowdefy/node-utils');
|
||||
nodeUtils.readFile.mockImplementation(() => Promise.resolve(null));
|
||||
const createWriteBuildArtifact = (await import('./writeBuildArtifact.js')).default;
|
||||
|
||||
const writeBuildArtifact = createWriteBuildArtifact({ directories });
|
||||
|
||||
await writeBuildArtifact('artifact.txt', 'Test artifact content');
|
||||
expect(nodeUtils.writeFile.mock.calls).toEqual([
|
||||
['/build/artifact.txt', 'Test artifact content'],
|
||||
]);
|
||||
});
|
@ -27,8 +27,8 @@
|
||||
},
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./dist/index.js",
|
||||
"./connections/*": "./dist/connections/*"
|
||||
"./connections": "./dist/connections.js",
|
||||
"./types": "./dist/types.js"
|
||||
},
|
||||
"files": [
|
||||
"dist/*"
|
||||
|
@ -14,13 +14,4 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
export default {
|
||||
import: {
|
||||
path: 'connections/Knex/KnexRaw/KnexRaw.js',
|
||||
schema: 'connections/Knex/KnexRaw/KnexRawSchema.json',
|
||||
},
|
||||
meta: {
|
||||
checkRead: false,
|
||||
checkWrite: false,
|
||||
},
|
||||
};
|
||||
export { default as Knex } from './connections/Knex/Knex.js';
|
@ -17,10 +17,10 @@
|
||||
import KnexBuilder from './KnexBuilder/KnexBuilder.js';
|
||||
import KnexRaw from './KnexRaw/KnexRaw.js';
|
||||
|
||||
import schema from './schema.js';
|
||||
|
||||
export default {
|
||||
import: {
|
||||
schema: 'connections/Knex/KnexSchema.json',
|
||||
},
|
||||
schema,
|
||||
requests: {
|
||||
KnexBuilder,
|
||||
KnexRaw,
|
||||
|
@ -16,7 +16,8 @@
|
||||
|
||||
import { validate } from '@lowdefy/ajv';
|
||||
import Knex from './Knex.js';
|
||||
import schema from './KnexSchema.json';
|
||||
|
||||
const schema = Knex.schema;
|
||||
|
||||
test('All requests are present', () => {
|
||||
expect(Knex.requests.KnexRaw).toBeDefined();
|
||||
|
@ -16,8 +16,9 @@
|
||||
|
||||
import knex from 'knex';
|
||||
import { type } from '@lowdefy/helpers';
|
||||
import schema from './schema.js';
|
||||
|
||||
async function knexBuilder({ request, connection }) {
|
||||
async function KnexBuilder({ request, connection }) {
|
||||
let client = knex(connection);
|
||||
if (request.tableName) {
|
||||
client = client(request.tableName);
|
||||
@ -47,4 +48,10 @@ async function knexBuilder({ request, connection }) {
|
||||
return client;
|
||||
}
|
||||
|
||||
export default knexBuilder;
|
||||
KnexBuilder.schema = schema;
|
||||
KnexBuilder.meta = {
|
||||
checkRead: false,
|
||||
checkWrite: false,
|
||||
};
|
||||
|
||||
export default KnexBuilder;
|
||||
|
@ -16,8 +16,10 @@
|
||||
|
||||
import { validate } from '@lowdefy/ajv';
|
||||
import knex from 'knex';
|
||||
import knexBuilder from './KnexBuilder.js';
|
||||
import schema from './KnexBuilderSchema.json';
|
||||
import KnexBuilder from './KnexBuilder.js';
|
||||
|
||||
const { checkRead, checkWrite } = KnexBuilder.meta;
|
||||
const schema = KnexBuilder.schema;
|
||||
|
||||
const mockKnexClient = jest.fn(() => mockKnexClient);
|
||||
|
||||
@ -44,7 +46,7 @@ test('KnexBuilder with tableName', async () => {
|
||||
query: [{ select: ['*'] }, { where: ['name', 'steve'] }],
|
||||
tableName: 'table',
|
||||
};
|
||||
const res = await knexBuilder({ request, connection });
|
||||
const res = await KnexBuilder({ request, connection });
|
||||
expect(knex.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
@ -74,7 +76,7 @@ test('KnexBuilder', async () => {
|
||||
const request = {
|
||||
query: [{ select: ['*'] }, { from: ['table'] }, { where: ['name', 'steve'] }],
|
||||
};
|
||||
const res = await knexBuilder({ request, connection });
|
||||
const res = await KnexBuilder({ request, connection });
|
||||
expect(knex.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
@ -97,7 +99,7 @@ test('KnexBuilder, invalid method', async () => {
|
||||
const request = {
|
||||
query: [{ invalid: ['*'] }],
|
||||
};
|
||||
await expect(knexBuilder({ request, connection })).rejects.toThrow(
|
||||
await expect(KnexBuilder({ request, connection })).rejects.toThrow(
|
||||
'Invalid query builder method "invalid".'
|
||||
);
|
||||
});
|
||||
@ -106,7 +108,7 @@ test('KnexBuilder, more than one method', async () => {
|
||||
const request = {
|
||||
query: [{ select: ['*'], where: ['name', 'steve'] }],
|
||||
};
|
||||
await expect(knexBuilder({ request, connection })).rejects.toThrow(
|
||||
await expect(KnexBuilder({ request, connection })).rejects.toThrow(
|
||||
'Invalid query, more than one method defined in a method object, received ["select","where"].'
|
||||
);
|
||||
});
|
||||
@ -115,7 +117,7 @@ test('KnexBuilder, method args not an array', async () => {
|
||||
const request = {
|
||||
query: [{ select: '*' }],
|
||||
};
|
||||
await expect(knexBuilder({ request, connection })).rejects.toThrow(
|
||||
await expect(KnexBuilder({ request, connection })).rejects.toThrow(
|
||||
'Invalid query, method "select" arguments should be an array, received "*".'
|
||||
);
|
||||
});
|
||||
@ -143,3 +145,11 @@ test('query missing', () => {
|
||||
'KnexBuilder request should have required property "query".'
|
||||
);
|
||||
});
|
||||
|
||||
test('checkRead should be false', async () => {
|
||||
expect(checkRead).toBe(false);
|
||||
});
|
||||
|
||||
test('checkWrite should be false', async () => {
|
||||
expect(checkWrite).toBe(false);
|
||||
});
|
||||
|
@ -1,28 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Lowdefy Request Schema - KnexBuilder",
|
||||
"type": "object",
|
||||
"required": ["query"],
|
||||
"properties": {
|
||||
"query": {
|
||||
"type": "array",
|
||||
"description": "SQL query builder array. An array of objects, with a single key which is the name of the knex builder function. The value should be an array of arguments to pass to the builder function.",
|
||||
"errorMessage": {
|
||||
"type": "KnexBuilder request property \"query\" should be an array."
|
||||
}
|
||||
},
|
||||
"tableName": {
|
||||
"type": ["string", "object"],
|
||||
"description": "The name of the table to query from.",
|
||||
"errorMessage": {
|
||||
"type": "KnexBuilder request property \"tableName\" should be a string or object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "KnexBuilder request properties should be an object.",
|
||||
"required": {
|
||||
"query": "KnexBuilder request should have required property \"query\"."
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
title: 'Lowdefy Request Schema - KnexBuilder',
|
||||
type: 'object',
|
||||
required: ['query'],
|
||||
properties: {
|
||||
query: {
|
||||
type: 'array',
|
||||
description:
|
||||
'SQL query builder array. An array of objects, with a single key which is the name of the knex builder function. The value should be an array of arguments to pass to the builder function.',
|
||||
errorMessage: {
|
||||
type: 'KnexBuilder request property "query" should be an array.',
|
||||
},
|
||||
},
|
||||
tableName: {
|
||||
type: ['string', 'object'],
|
||||
description: 'The name of the table to query from.',
|
||||
errorMessage: {
|
||||
type: 'KnexBuilder request property "tableName" should be a string or object',
|
||||
},
|
||||
},
|
||||
},
|
||||
errorMessage: {
|
||||
type: 'KnexBuilder request properties should be an object.',
|
||||
required: {
|
||||
query: 'KnexBuilder request should have required property "query".',
|
||||
},
|
||||
},
|
||||
};
|
@ -15,8 +15,9 @@
|
||||
*/
|
||||
|
||||
import knex from 'knex';
|
||||
import schema from './schema.js';
|
||||
|
||||
async function knexRaw({ request, connection }) {
|
||||
async function KnexRaw({ request, connection }) {
|
||||
const client = knex(connection);
|
||||
const res = await client.raw(request.query, request.parameters);
|
||||
Object.keys(res).forEach((key) => {
|
||||
@ -27,4 +28,10 @@ async function knexRaw({ request, connection }) {
|
||||
return res;
|
||||
}
|
||||
|
||||
export default knexRaw;
|
||||
KnexRaw.schema = schema;
|
||||
KnexRaw.meta = {
|
||||
checkRead: false,
|
||||
checkWrite: false,
|
||||
};
|
||||
|
||||
export default KnexRaw;
|
||||
|
@ -16,8 +16,10 @@
|
||||
|
||||
import { validate } from '@lowdefy/ajv';
|
||||
import knex from 'knex';
|
||||
import knexRaw from './KnexRaw.js';
|
||||
import schema from './KnexRawSchema.json';
|
||||
import KnexRaw from './KnexRaw.js';
|
||||
|
||||
const { checkRead, checkWrite } = KnexRaw.meta;
|
||||
const schema = KnexRaw.schema;
|
||||
|
||||
const mockRaw = jest.fn(() => {
|
||||
return Promise.resolve({ rows: [{ name: 'name' }], _types: 'types' });
|
||||
@ -39,7 +41,7 @@ const connection = {
|
||||
};
|
||||
|
||||
test('knexRaw', async () => {
|
||||
const res = await knexRaw({ request, connection });
|
||||
const res = await KnexRaw({ request, connection });
|
||||
expect(knex.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
@ -88,3 +90,11 @@ test('query missing', () => {
|
||||
'KnexRaw request should have required property "query".'
|
||||
);
|
||||
});
|
||||
|
||||
test('checkRead should be false', async () => {
|
||||
expect(checkRead).toBe(false);
|
||||
});
|
||||
|
||||
test('checkWrite should be false', async () => {
|
||||
expect(checkWrite).toBe(false);
|
||||
});
|
||||
|
@ -1,28 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Lowdefy Request Schema - KnexRaw",
|
||||
"type": "object",
|
||||
"required": ["query"],
|
||||
"properties": {
|
||||
"query": {
|
||||
"type": "string",
|
||||
"description": "SQL query string.",
|
||||
"errorMessage": {
|
||||
"type": "KnexRaw request property \"query\" should be a string."
|
||||
}
|
||||
},
|
||||
"parameters": {
|
||||
"type": ["string","number", "array", "object"],
|
||||
"description": "SQL query parameters.",
|
||||
"errorMessage": {
|
||||
"type": "KnexRaw request property \"parameters\" should be a string, number, array, or object."
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "KnexRaw request properties should be an object.",
|
||||
"required": {
|
||||
"query": "KnexRaw request should have required property \"query\"."
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
title: 'Lowdefy Request Schema - KnexRaw',
|
||||
type: 'object',
|
||||
required: ['query'],
|
||||
properties: {
|
||||
query: {
|
||||
type: 'string',
|
||||
description: 'SQL query string.',
|
||||
errorMessage: {
|
||||
type: 'KnexRaw request property "query" should be a string.',
|
||||
},
|
||||
},
|
||||
parameters: {
|
||||
type: ['string', 'number', 'array', 'object'],
|
||||
description: 'SQL query parameters.',
|
||||
errorMessage: {
|
||||
type: 'KnexRaw request property "parameters" should be a string, number, array, or object.',
|
||||
},
|
||||
},
|
||||
},
|
||||
errorMessage: {
|
||||
type: 'KnexRaw request properties should be an object.',
|
||||
required: {
|
||||
query: 'KnexRaw request should have required property "query".',
|
||||
},
|
||||
},
|
||||
};
|
@ -1,43 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Lowdefy Connection Schema - Knex",
|
||||
"type": "object",
|
||||
"required": ["client", "connection"],
|
||||
"properties": {
|
||||
"client": {
|
||||
"type": "string",
|
||||
"description": "SQL query string.",
|
||||
"errorMessage": {
|
||||
"type": "Knex connection property \"client\" should be a string."
|
||||
}
|
||||
},
|
||||
"connection": {
|
||||
"type": ["string", "object"],
|
||||
"description": "SQL query string.",
|
||||
"errorMessage": {
|
||||
"type": "Knex connection property \"connection\" should be a string or object."
|
||||
}
|
||||
},
|
||||
"searchPath": {
|
||||
"type": "string",
|
||||
"description": "Set PostgreSQL search path.",
|
||||
"errorMessage": {
|
||||
"type": "Knex connection property \"searchPath\" should be a string."
|
||||
}
|
||||
},
|
||||
"version": {
|
||||
"type": "string",
|
||||
"description": "Set database version.",
|
||||
"errorMessage": {
|
||||
"type": "Knex connection property \"version\" should be a string."
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "Knex connection properties should be an object.",
|
||||
"required": {
|
||||
"client": "Knex connection should have required property \"client\".",
|
||||
"connection": "Knex connection should have required property \"connection\"."
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
title: 'Lowdefy Connection Schema - Knex',
|
||||
type: 'object',
|
||||
required: ['client', 'connection'],
|
||||
properties: {
|
||||
client: {
|
||||
type: 'string',
|
||||
description: 'SQL query string.',
|
||||
errorMessage: {
|
||||
type: 'Knex connection property "client" should be a string.',
|
||||
},
|
||||
},
|
||||
connection: {
|
||||
type: ['string', 'object'],
|
||||
description: 'SQL query string.',
|
||||
errorMessage: {
|
||||
type: 'Knex connection property "connection" should be a string or object.',
|
||||
},
|
||||
},
|
||||
searchPath: {
|
||||
type: 'string',
|
||||
description: 'Set PostgreSQL search path.',
|
||||
errorMessage: {
|
||||
type: 'Knex connection property "searchPath" should be a string.',
|
||||
},
|
||||
},
|
||||
version: {
|
||||
type: 'string',
|
||||
description: 'Set database version.',
|
||||
errorMessage: {
|
||||
type: 'Knex connection property "version" should be a string.',
|
||||
},
|
||||
},
|
||||
},
|
||||
errorMessage: {
|
||||
type: 'Knex connection properties should be an object.',
|
||||
required: {
|
||||
client: 'Knex connection should have required property "client".',
|
||||
connection: 'Knex connection should have required property "connection".',
|
||||
},
|
||||
},
|
||||
};
|
@ -1,7 +0,0 @@
|
||||
import Knex from './connections/Knex/Knex.js';
|
||||
|
||||
export const connections = {
|
||||
Knex,
|
||||
};
|
||||
|
||||
export default { connections };
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable import/namespace */
|
||||
/*
|
||||
Copyright 2020-2021 Lowdefy, Inc
|
||||
|
||||
@ -13,14 +14,16 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import * as connections from './connections.js';
|
||||
|
||||
export default {
|
||||
import: {
|
||||
path: 'connections/MongoDBCollection/MongoDBDeleteMany/MongoDBDeleteMany.js',
|
||||
schema: 'connections/MongoDBCollection/MongoDBDeleteMany/MongoDBDeleteManySchema.json',
|
||||
},
|
||||
meta: {
|
||||
checkRead: false,
|
||||
checkWrite: true,
|
||||
},
|
||||
connections: Object.keys(connections),
|
||||
requests: Object.keys(connections)
|
||||
.map((connection) => Object.keys(connections[connection].requests))
|
||||
.flat(),
|
||||
};
|
||||
|
||||
// export default {
|
||||
// connections: ['Knex'],
|
||||
// requests: ['KnexBuilder', 'KnexRaw'],
|
||||
// };
|
@ -27,8 +27,8 @@
|
||||
},
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./dist/index.js",
|
||||
"./connections/*": "./dist/connections/*"
|
||||
"./connections": "./dist/connections.js",
|
||||
"./types": "./dist/types.js"
|
||||
},
|
||||
"files": [
|
||||
"dist/*"
|
||||
|
@ -14,13 +14,4 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
export default {
|
||||
import: {
|
||||
path: 'connections/Knex/KnexBuilder/KnexBuilder.js',
|
||||
schema: 'connections/Knex/KnexBuilder/KnexBuilderSchema.json',
|
||||
},
|
||||
meta: {
|
||||
checkRead: false,
|
||||
checkWrite: false,
|
||||
},
|
||||
};
|
||||
export { default as MongoDBCollection } from './connections/MongoDBCollection/MongoDBCollection.js';
|
@ -16,6 +16,7 @@
|
||||
|
||||
import getCollection from '../getCollection.js';
|
||||
import { serialize, deserialize } from '../serialize.js';
|
||||
import schema from './schema.js';
|
||||
|
||||
function checkOutAndMerge({ pipeline, connection }) {
|
||||
if (connection.write !== true) {
|
||||
@ -29,7 +30,7 @@ function checkOutAndMerge({ pipeline, connection }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function mongodbAggregation({ request, connection }) {
|
||||
async function MongodbAggregation({ request, connection }) {
|
||||
const deserializedRequest = deserialize(request);
|
||||
const { pipeline, options } = deserializedRequest;
|
||||
checkOutAndMerge({ pipeline, connection });
|
||||
@ -46,4 +47,10 @@ async function mongodbAggregation({ request, connection }) {
|
||||
return serialize(res);
|
||||
}
|
||||
|
||||
export default mongodbAggregation;
|
||||
MongodbAggregation.schema = schema;
|
||||
MongodbAggregation.meta = {
|
||||
checkRead: true,
|
||||
checkWrite: false,
|
||||
};
|
||||
|
||||
export default MongodbAggregation;
|
||||
|
@ -15,12 +15,11 @@
|
||||
*/
|
||||
|
||||
import { validate } from '@lowdefy/ajv';
|
||||
import mongoDBAggregation from './MongoDBAggregation.js';
|
||||
import MongoDBAggregation from './MongoDBAggregation.js';
|
||||
import populateTestMongoDb from '../../../../test/populateTestMongoDb.js';
|
||||
import requestIndex from './index.js';
|
||||
import schema from './MongoDBAggregationSchema.json';
|
||||
|
||||
const { checkRead, checkWrite } = requestIndex.meta;
|
||||
const { checkRead, checkWrite } = MongoDBAggregation.meta;
|
||||
const schema = MongoDBAggregation.schema;
|
||||
|
||||
const pipeline = [
|
||||
{
|
||||
@ -52,7 +51,7 @@ test('aggregation', async () => {
|
||||
collection,
|
||||
read: true,
|
||||
};
|
||||
const res = await mongoDBAggregation({ request, connection });
|
||||
const res = await MongoDBAggregation({ request, connection });
|
||||
expect(res).toEqual([
|
||||
{
|
||||
_id: 1,
|
||||
@ -69,7 +68,7 @@ test('aggregation connection error', async () => {
|
||||
collection,
|
||||
read: true,
|
||||
};
|
||||
await expect(mongoDBAggregation({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBAggregation({ request, connection })).rejects.toThrow(
|
||||
'Invalid connection string'
|
||||
);
|
||||
});
|
||||
@ -82,7 +81,7 @@ test('aggregation mongodb error', async () => {
|
||||
collection,
|
||||
read: true,
|
||||
};
|
||||
await expect(mongoDBAggregation({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBAggregation({ request, connection })).rejects.toThrow(
|
||||
"Unrecognized pipeline stage name: '$badStage'"
|
||||
);
|
||||
});
|
||||
@ -111,7 +110,7 @@ test('aggregation match dates', async () => {
|
||||
collection,
|
||||
read: true,
|
||||
};
|
||||
const res = await mongoDBAggregation({ request, connection });
|
||||
const res = await MongoDBAggregation({ request, connection });
|
||||
expect(res).toEqual([
|
||||
{
|
||||
_id: 2,
|
||||
@ -159,7 +158,7 @@ test('$out is not allowed with write undefined', async () => {
|
||||
databaseName,
|
||||
collection,
|
||||
};
|
||||
await expect(mongoDBAggregation({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBAggregation({ request, connection })).rejects.toThrow(
|
||||
'Connection does not allow writes and aggregation pipeline contains a "$merge" or "$out" stage.'
|
||||
);
|
||||
});
|
||||
@ -172,7 +171,7 @@ test('$out is not allowed with write false', async () => {
|
||||
collection,
|
||||
write: false,
|
||||
};
|
||||
await expect(mongoDBAggregation({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBAggregation({ request, connection })).rejects.toThrow(
|
||||
'Connection does not allow writes and aggregation pipeline contains a "$merge" or "$out" stage.'
|
||||
);
|
||||
});
|
||||
@ -185,7 +184,7 @@ test('$out is allowed with write true', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBAggregation({ request, connection });
|
||||
const res = await MongoDBAggregation({ request, connection });
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
|
||||
@ -196,7 +195,7 @@ test('$merge is not allowed with write undefined', async () => {
|
||||
databaseName,
|
||||
collection,
|
||||
};
|
||||
await expect(mongoDBAggregation({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBAggregation({ request, connection })).rejects.toThrow(
|
||||
'Connection does not allow writes and aggregation pipeline contains a "$merge" or "$out" stage.'
|
||||
);
|
||||
});
|
||||
@ -209,7 +208,7 @@ test('$merge is not allowed with write false', async () => {
|
||||
collection,
|
||||
write: false,
|
||||
};
|
||||
await expect(mongoDBAggregation({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBAggregation({ request, connection })).rejects.toThrow(
|
||||
'Connection does not allow writes and aggregation pipeline contains a "$merge" or "$out" stage.'
|
||||
);
|
||||
});
|
||||
|
@ -1,26 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Lowdefy Request Schema - MongoDBAggregation",
|
||||
"type": "object",
|
||||
"required": ["pipeline"],
|
||||
"properties": {
|
||||
"pipeline": {
|
||||
"type": "array",
|
||||
"description": "Array containing all the aggregation framework commands for the execution.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBAggregation request property \"pipeline\" should be an array."
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"type": "object",
|
||||
"description": "Optional settings.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBAggregation request property \"options\" should be an object."
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "MongoDBAggregation request properties should be an object.",
|
||||
"required": "MongoDBAggregation request should have required property \"pipeline\"."
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
title: 'Lowdefy Request Schema - MongoDBAggregation',
|
||||
type: 'object',
|
||||
required: ['pipeline'],
|
||||
properties: {
|
||||
pipeline: {
|
||||
type: 'array',
|
||||
description: 'Array containing all the aggregation framework commands for the execution.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBAggregation request property "pipeline" should be an array.',
|
||||
},
|
||||
},
|
||||
options: {
|
||||
type: 'object',
|
||||
description: 'Optional settings.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBAggregation request property "options" should be an object.',
|
||||
},
|
||||
},
|
||||
},
|
||||
errorMessage: {
|
||||
type: 'MongoDBAggregation request properties should be an object.',
|
||||
required: 'MongoDBAggregation request should have required property "pipeline".',
|
||||
},
|
||||
};
|
@ -23,11 +23,10 @@ import MongoDBInsertMany from './MongoDBInsertMany/MongoDBInsertMany.js';
|
||||
import MongoDBInsertOne from './MongoDBInsertOne/MongoDBInsertOne.js';
|
||||
import MongoDBUpdateMany from './MongoDBUpdateMany/MongoDBUpdateMany.js';
|
||||
import MongoDBUpdateOne from './MongoDBUpdateOne/MongoDBUpdateOne.js';
|
||||
import schema from './schema.js';
|
||||
|
||||
export default {
|
||||
import: {
|
||||
schema: 'connections/MongoDBCollection/MongoDBCollectionSchema.json',
|
||||
},
|
||||
schema,
|
||||
requests: {
|
||||
MongoDBAggregation,
|
||||
MongoDBDeleteMany,
|
||||
|
@ -16,7 +16,8 @@
|
||||
|
||||
import { validate } from '@lowdefy/ajv';
|
||||
import MongoDBCollection from './MongoDBCollection.js';
|
||||
import schema from './MongoDBCollectionSchema.json';
|
||||
|
||||
const schema = MongoDBCollection.schema;
|
||||
|
||||
test('All requests are present', () => {
|
||||
expect(MongoDBCollection.requests.MongoDBAggregation).toBeDefined();
|
||||
|
@ -1,52 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Lowdefy Connection Schema - MongoDBCollection",
|
||||
"type": "object",
|
||||
"required": ["databaseUri", "collection"],
|
||||
"properties": {
|
||||
"databaseUri": {
|
||||
"type": "string",
|
||||
"description": "Connection uri string for the MongoDb deployment.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBCollection connection property \"databaseUri\" should be a string."
|
||||
}
|
||||
},
|
||||
"databaseName": {
|
||||
"type": "string",
|
||||
"description": "AWS IAM secret access key with s3 access.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBCollection connection property \"databaseName\" should be a string."
|
||||
}
|
||||
},
|
||||
"collection": {
|
||||
"type": "string",
|
||||
"description": "AWS region the bucket is located in.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBCollection connection property \"collection\" should be a string."
|
||||
}
|
||||
},
|
||||
"read": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Allow reads from the collection.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBCollection connection property \"read\" should be a boolean."
|
||||
}
|
||||
},
|
||||
"write": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Allow writes to the collection.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBCollection connection property \"write\" should be a boolean."
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "MongoDBCollection connection properties should be an object.",
|
||||
"required": {
|
||||
"databaseUri": "MongoDBCollection connection should have required property \"databaseUri\".",
|
||||
"collection": "MongoDBCollection connection should have required property \"collection\"."
|
||||
}
|
||||
}
|
||||
}
|
@ -16,8 +16,9 @@
|
||||
|
||||
import getCollection from '../getCollection.js';
|
||||
import { serialize, deserialize } from '../serialize.js';
|
||||
import schema from './schema.js';
|
||||
|
||||
async function mongodbDeleteMany({ request, connection }) {
|
||||
async function MongodbDeleteMany({ request, connection }) {
|
||||
const deserializedRequest = deserialize(request);
|
||||
const { filter, options } = deserializedRequest;
|
||||
const { collection, client } = await getCollection({ connection });
|
||||
@ -33,4 +34,10 @@ async function mongodbDeleteMany({ request, connection }) {
|
||||
return { deletedCount };
|
||||
}
|
||||
|
||||
export default mongodbDeleteMany;
|
||||
MongodbDeleteMany.schema = schema;
|
||||
MongodbDeleteMany.meta = {
|
||||
checkRead: false,
|
||||
checkWrite: true,
|
||||
};
|
||||
|
||||
export default MongodbDeleteMany;
|
||||
|
@ -15,12 +15,11 @@
|
||||
*/
|
||||
|
||||
import { validate } from '@lowdefy/ajv';
|
||||
import mongoDBDeleteMany from './MongoDBDeleteMany.js';
|
||||
import MongoDBDeleteMany from './MongoDBDeleteMany.js';
|
||||
import populateTestMongoDb from '../../../../test/populateTestMongoDb.js';
|
||||
import requestIndex from './index.js';
|
||||
import schema from './MongoDBDeleteManySchema.json';
|
||||
|
||||
const { checkRead, checkWrite } = requestIndex.meta;
|
||||
const { checkRead, checkWrite } = MongoDBDeleteMany.meta;
|
||||
const schema = MongoDBDeleteMany.schema;
|
||||
|
||||
const databaseUri = process.env.MONGO_URL;
|
||||
const databaseName = 'test';
|
||||
@ -49,7 +48,7 @@ test('deleteMany - Single Document', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBDeleteMany({ request, connection });
|
||||
const res = await MongoDBDeleteMany({ request, connection });
|
||||
expect(res).toEqual({
|
||||
deletedCount: 1,
|
||||
});
|
||||
@ -65,7 +64,7 @@ test('deleteMany - Multiple Documents', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBDeleteMany({ request, connection });
|
||||
const res = await MongoDBDeleteMany({ request, connection });
|
||||
expect(res).toEqual({
|
||||
deletedCount: 3,
|
||||
});
|
||||
@ -81,7 +80,7 @@ test('deleteMany - Multiple Documents one field', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBDeleteMany({ request, connection });
|
||||
const res = await MongoDBDeleteMany({ request, connection });
|
||||
expect(res).toEqual({
|
||||
deletedCount: 3,
|
||||
});
|
||||
@ -97,7 +96,7 @@ test('deleteMany connection error', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
await expect(mongoDBDeleteMany({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBDeleteMany({ request, connection })).rejects.toThrow(
|
||||
'Invalid connection string'
|
||||
);
|
||||
});
|
||||
@ -113,7 +112,7 @@ test('deleteMany mongodb error', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
await expect(mongoDBDeleteMany({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBDeleteMany({ request, connection })).rejects.toThrow(
|
||||
'w has to be a number or a string'
|
||||
);
|
||||
});
|
||||
|
@ -1,26 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Lowdefy Request Schema - MongoDBDeleteMany",
|
||||
"type": "object",
|
||||
"required": ["filter"],
|
||||
"properties": {
|
||||
"filter": {
|
||||
"type": "object",
|
||||
"description": "The filter used to select the document to update.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBDeleteMany request property \"filter\" should be an object."
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"type": "object",
|
||||
"description": "Optional settings.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBDeleteMany request property \"options\" should be an object."
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "MongoDBDeleteMany request properties should be an object.",
|
||||
"required": "MongoDBDeleteMany request should have required property \"filter\"."
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
title: 'Lowdefy Request Schema - MongoDBDeleteMany',
|
||||
type: 'object',
|
||||
required: ['filter'],
|
||||
properties: {
|
||||
filter: {
|
||||
type: 'object',
|
||||
description: 'The filter used to select the document to update.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBDeleteMany request property "filter" should be an object.',
|
||||
},
|
||||
},
|
||||
options: {
|
||||
type: 'object',
|
||||
description: 'Optional settings.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBDeleteMany request property "options" should be an object.',
|
||||
},
|
||||
},
|
||||
},
|
||||
errorMessage: {
|
||||
type: 'MongoDBDeleteMany request properties should be an object.',
|
||||
required: 'MongoDBDeleteMany request should have required property "filter".',
|
||||
},
|
||||
};
|
@ -16,8 +16,9 @@
|
||||
|
||||
import getCollection from '../getCollection.js';
|
||||
import { serialize, deserialize } from '../serialize.js';
|
||||
import schema from './schema.js';
|
||||
|
||||
async function mongodbDeleteOne({ request, connection }) {
|
||||
async function MongodbDeleteOne({ request, connection }) {
|
||||
const deserializedRequest = deserialize(request);
|
||||
const { filter, options } = deserializedRequest;
|
||||
const { collection, client } = await getCollection({ connection });
|
||||
@ -33,4 +34,10 @@ async function mongodbDeleteOne({ request, connection }) {
|
||||
return { deletedCount };
|
||||
}
|
||||
|
||||
export default mongodbDeleteOne;
|
||||
MongodbDeleteOne.schema = schema;
|
||||
MongodbDeleteOne.meta = {
|
||||
checkRead: false,
|
||||
checkWrite: true,
|
||||
};
|
||||
|
||||
export default MongodbDeleteOne;
|
||||
|
@ -15,12 +15,11 @@
|
||||
*/
|
||||
|
||||
import { validate } from '@lowdefy/ajv';
|
||||
import mongoDBDeleteOne from './MongoDBDeleteOne.js';
|
||||
import MongoDBDeleteOne from './MongoDBDeleteOne.js';
|
||||
import populateTestMongoDb from '../../../../test/populateTestMongoDb.js';
|
||||
import requestIndex from './index.js';
|
||||
import schema from './MongoDBDeleteOneSchema.json';
|
||||
|
||||
const { checkRead, checkWrite } = requestIndex.meta;
|
||||
const { checkRead, checkWrite } = MongoDBDeleteOne.meta;
|
||||
const schema = MongoDBDeleteOne.schema;
|
||||
|
||||
const databaseUri = process.env.MONGO_URL;
|
||||
const databaseName = 'test';
|
||||
@ -41,7 +40,7 @@ test('deleteOne', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBDeleteOne({ request, connection });
|
||||
const res = await MongoDBDeleteOne({ request, connection });
|
||||
expect(res).toEqual({
|
||||
deletedCount: 1,
|
||||
});
|
||||
@ -57,7 +56,7 @@ test('deleteOne connection error', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
await expect(mongoDBDeleteOne({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBDeleteOne({ request, connection })).rejects.toThrow(
|
||||
'Invalid connection string'
|
||||
);
|
||||
});
|
||||
@ -81,7 +80,7 @@ test('deleteOne catch invalid options', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
await expect(mongoDBDeleteOne({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBDeleteOne({ request, connection })).rejects.toThrow(
|
||||
'w has to be a number or a string'
|
||||
);
|
||||
});
|
||||
|
@ -1,26 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Lowdefy Request Schema - MongoDBDeleteOne",
|
||||
"type": "object",
|
||||
"required": ["filter"],
|
||||
"properties": {
|
||||
"filter": {
|
||||
"type": "object",
|
||||
"description": "The filter used to select the document to update.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBDeleteOne request property \"filter\" should be an object."
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"type": "object",
|
||||
"description": "Optional settings.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBDeleteOne request property \"options\" should be an object."
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "MongoDBDeleteOne request properties should be an object.",
|
||||
"required": "MongoDBDeleteOne request should have required property \"filter\"."
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
import: {
|
||||
path: 'connections/MongoDBCollection/MongoDBDeleteOne/MongoDBDeleteOne.js',
|
||||
schema: 'connections/MongoDBCollection/MongoDBDeleteOne/MongoDBDeleteOneSchema.json',
|
||||
},
|
||||
meta: {
|
||||
checkRead: false,
|
||||
checkWrite: true,
|
||||
},
|
||||
};
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
title: 'Lowdefy Request Schema - MongoDBDeleteOne',
|
||||
type: 'object',
|
||||
required: ['filter'],
|
||||
properties: {
|
||||
filter: {
|
||||
type: 'object',
|
||||
description: 'The filter used to select the document to update.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBDeleteOne request property "filter" should be an object.',
|
||||
},
|
||||
},
|
||||
options: {
|
||||
type: 'object',
|
||||
description: 'Optional settings.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBDeleteOne request property "options" should be an object.',
|
||||
},
|
||||
},
|
||||
},
|
||||
errorMessage: {
|
||||
type: 'MongoDBDeleteOne request properties should be an object.',
|
||||
required: 'MongoDBDeleteOne request should have required property "filter".',
|
||||
},
|
||||
};
|
@ -16,8 +16,9 @@
|
||||
|
||||
import getCollection from '../getCollection.js';
|
||||
import { serialize, deserialize } from '../serialize.js';
|
||||
import schema from './schema.js';
|
||||
|
||||
async function mongodbFind({ request, connection }) {
|
||||
async function MongodbFind({ request, connection }) {
|
||||
const deserializedRequest = deserialize(request);
|
||||
const { query, options } = deserializedRequest;
|
||||
const { collection, client } = await getCollection({ connection });
|
||||
@ -33,4 +34,10 @@ async function mongodbFind({ request, connection }) {
|
||||
return serialize(res);
|
||||
}
|
||||
|
||||
export default mongodbFind;
|
||||
MongodbFind.schema = schema;
|
||||
MongodbFind.meta = {
|
||||
checkRead: true,
|
||||
checkWrite: false,
|
||||
};
|
||||
|
||||
export default MongodbFind;
|
||||
|
@ -15,12 +15,11 @@
|
||||
*/
|
||||
|
||||
import { validate } from '@lowdefy/ajv';
|
||||
import mongoDBFind from './MongoDBFind.js';
|
||||
import MongoDBFind from './MongoDBFind.js';
|
||||
import populateTestMongoDb from '../../../../test/populateTestMongoDb.js';
|
||||
import requestIndex from './index.js';
|
||||
import schema from './MongoDBFindSchema.json';
|
||||
|
||||
const { checkRead, checkWrite } = requestIndex.meta;
|
||||
const { checkRead, checkWrite } = MongoDBFind.meta;
|
||||
const schema = MongoDBFind.schema;
|
||||
|
||||
const query = { _id: 1 };
|
||||
|
||||
@ -41,7 +40,7 @@ test('find', async () => {
|
||||
collection,
|
||||
read: true,
|
||||
};
|
||||
const res = await mongoDBFind({ request, connection });
|
||||
const res = await MongoDBFind({ request, connection });
|
||||
expect(res).toEqual([
|
||||
{
|
||||
_id: 1,
|
||||
@ -60,7 +59,7 @@ test('find options', async () => {
|
||||
collection,
|
||||
read: true,
|
||||
};
|
||||
const res = await mongoDBFind({ request, connection });
|
||||
const res = await MongoDBFind({ request, connection });
|
||||
expect(res).toEqual([
|
||||
{
|
||||
_id: 2,
|
||||
@ -76,7 +75,7 @@ test('find mongodb error', async () => {
|
||||
collection,
|
||||
read: true,
|
||||
};
|
||||
await expect(mongoDBFind({ request, connection })).rejects.toThrow('unknown operator: $badOp');
|
||||
await expect(MongoDBFind({ request, connection })).rejects.toThrow('unknown operator: $badOp');
|
||||
});
|
||||
|
||||
test('checkRead should be true', async () => {
|
||||
|
@ -1,26 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Lowdefy Request Schema - MongoDBFind",
|
||||
"type": "object",
|
||||
"required": ["query"],
|
||||
"properties": {
|
||||
"query": {
|
||||
"type": "object",
|
||||
"description": "A MongoDB query object",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBFind request property \"query\" should be an object."
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"type": "object",
|
||||
"description": "Optional settings.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBFind request property \"options\" should be an object."
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "MongoDBFind request properties should be an object.",
|
||||
"required": "MongoDBFind request should have required property \"query\"."
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
title: 'Lowdefy Request Schema - MongoDBFind',
|
||||
type: 'object',
|
||||
required: ['query'],
|
||||
properties: {
|
||||
query: {
|
||||
type: 'object',
|
||||
description: 'A MongoDB query object',
|
||||
errorMessage: {
|
||||
type: 'MongoDBFind request property "query" should be an object.',
|
||||
},
|
||||
},
|
||||
options: {
|
||||
type: 'object',
|
||||
description: 'Optional settings.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBFind request property "options" should be an object.',
|
||||
},
|
||||
},
|
||||
},
|
||||
errorMessage: {
|
||||
type: 'MongoDBFind request properties should be an object.',
|
||||
required: 'MongoDBFind request should have required property "query".',
|
||||
},
|
||||
};
|
@ -16,8 +16,9 @@
|
||||
|
||||
import getCollection from '../getCollection.js';
|
||||
import { serialize, deserialize } from '../serialize.js';
|
||||
import schema from './schema.js';
|
||||
|
||||
async function mongodbFindOne({ request, connection }) {
|
||||
async function MongodbFindOne({ request, connection }) {
|
||||
const deserializedRequest = deserialize(request);
|
||||
const { query, options } = deserializedRequest;
|
||||
const { collection, client } = await getCollection({ connection });
|
||||
@ -32,4 +33,10 @@ async function mongodbFindOne({ request, connection }) {
|
||||
return serialize(res);
|
||||
}
|
||||
|
||||
export default mongodbFindOne;
|
||||
MongodbFindOne.schema = schema;
|
||||
MongodbFindOne.meta = {
|
||||
checkRead: true,
|
||||
checkWrite: false,
|
||||
};
|
||||
|
||||
export default MongodbFindOne;
|
||||
|
@ -15,12 +15,11 @@
|
||||
*/
|
||||
|
||||
import { validate } from '@lowdefy/ajv';
|
||||
import mongoDBFindOne from './MongoDBFindOne.js';
|
||||
import MongoDBFindOne from './MongoDBFindOne.js';
|
||||
import populateTestMongoDb from '../../../../test/populateTestMongoDb.js';
|
||||
import requestIndex from './index.js';
|
||||
import schema from './MongoDBFindOneSchema.json';
|
||||
|
||||
const { checkRead, checkWrite } = requestIndex.meta;
|
||||
const { checkRead, checkWrite } = MongoDBFindOne.meta;
|
||||
const schema = MongoDBFindOne.schema;
|
||||
|
||||
const databaseUri = process.env.MONGO_URL;
|
||||
const databaseName = 'test';
|
||||
@ -39,7 +38,7 @@ test('findOne', async () => {
|
||||
collection,
|
||||
read: true,
|
||||
};
|
||||
const res = await mongoDBFindOne({ request, connection });
|
||||
const res = await MongoDBFindOne({ request, connection });
|
||||
expect(res).toEqual({
|
||||
_id: 1,
|
||||
});
|
||||
@ -55,7 +54,7 @@ test('findOne only find one', async () => {
|
||||
collection,
|
||||
read: true,
|
||||
};
|
||||
const res = await mongoDBFindOne({ request, connection });
|
||||
const res = await MongoDBFindOne({ request, connection });
|
||||
expect(res).toEqual({
|
||||
_id: 2,
|
||||
});
|
||||
@ -72,7 +71,7 @@ test('find options', async () => {
|
||||
collection,
|
||||
read: true,
|
||||
};
|
||||
const res = await mongoDBFindOne({ request, connection });
|
||||
const res = await MongoDBFindOne({ request, connection });
|
||||
expect(res).toEqual({
|
||||
_id: 2,
|
||||
});
|
||||
@ -86,7 +85,7 @@ test('findOne connection error', async () => {
|
||||
collection,
|
||||
read: true,
|
||||
};
|
||||
await expect(mongoDBFindOne({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBFindOne({ request, connection })).rejects.toThrow(
|
||||
'Invalid connection string'
|
||||
);
|
||||
});
|
||||
@ -99,7 +98,7 @@ test('findOne mongodb error', async () => {
|
||||
collection,
|
||||
read: true,
|
||||
};
|
||||
await expect(mongoDBFindOne({ request, connection })).rejects.toThrow('unknown operator: $badOp');
|
||||
await expect(MongoDBFindOne({ request, connection })).rejects.toThrow('unknown operator: $badOp');
|
||||
});
|
||||
|
||||
test('checkRead should be true', async () => {
|
||||
|
@ -1,26 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Lowdefy Request Schema - MongoDBFindOne",
|
||||
"type": "object",
|
||||
"required": ["query"],
|
||||
"properties": {
|
||||
"query": {
|
||||
"type": "object",
|
||||
"description": "A MongoDB query object",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBFindOne request property \"query\" should be an object."
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"type": "object",
|
||||
"description": "Optional settings.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBFindOne request property \"options\" should be an object."
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "MongoDBFindOne request properties should be an object.",
|
||||
"required": "MongoDBFindOne request should have required property \"query\"."
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
import: {
|
||||
path: 'connections/MongoDBCollection/MongoDBFindOne/MongoDBFindOne.js',
|
||||
schema: 'connections/MongoDBCollection/MongoDBFindOne/MongoDBFindOneSchema.json',
|
||||
},
|
||||
meta: {
|
||||
checkRead: true,
|
||||
checkWrite: false,
|
||||
},
|
||||
};
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
title: 'Lowdefy Request Schema - MongoDBFindOne',
|
||||
type: 'object',
|
||||
required: ['query'],
|
||||
properties: {
|
||||
query: {
|
||||
type: 'object',
|
||||
description: 'A MongoDB query object',
|
||||
errorMessage: {
|
||||
type: 'MongoDBFindOne request property "query" should be an object.',
|
||||
},
|
||||
},
|
||||
options: {
|
||||
type: 'object',
|
||||
description: 'Optional settings.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBFindOne request property "options" should be an object.',
|
||||
},
|
||||
},
|
||||
},
|
||||
errorMessage: {
|
||||
type: 'MongoDBFindOne request properties should be an object.',
|
||||
required: 'MongoDBFindOne request should have required property "query".',
|
||||
},
|
||||
};
|
@ -16,8 +16,9 @@
|
||||
|
||||
import getCollection from '../getCollection.js';
|
||||
import { serialize, deserialize } from '../serialize.js';
|
||||
import schema from './schema.js';
|
||||
|
||||
async function mongodbInsertMany({ request, connection }) {
|
||||
async function MongodbInsertMany({ request, connection }) {
|
||||
const deserializedRequest = deserialize(request);
|
||||
const { docs, options } = deserializedRequest;
|
||||
const { collection, client } = await getCollection({ connection });
|
||||
@ -33,4 +34,10 @@ async function mongodbInsertMany({ request, connection }) {
|
||||
return { insertedCount, ops };
|
||||
}
|
||||
|
||||
export default mongodbInsertMany;
|
||||
MongodbInsertMany.schema = schema;
|
||||
MongodbInsertMany.meta = {
|
||||
checkRead: false,
|
||||
checkWrite: true,
|
||||
};
|
||||
|
||||
export default MongodbInsertMany;
|
||||
|
@ -15,12 +15,11 @@
|
||||
*/
|
||||
|
||||
import { validate } from '@lowdefy/ajv';
|
||||
import mongoDBInsertMany from './MongoDBInsertMany.js';
|
||||
import MongoDBInsertMany from './MongoDBInsertMany.js';
|
||||
import clearTestMongoDb from '../../../../test/clearTestMongoDb.js';
|
||||
import requestIndex from './index.js';
|
||||
import schema from './MongoDBInsertManySchema.json';
|
||||
|
||||
const { checkRead, checkWrite } = requestIndex.meta;
|
||||
const { checkRead, checkWrite } = MongoDBInsertMany.meta;
|
||||
const schema = MongoDBInsertMany.schema;
|
||||
|
||||
const databaseUri = process.env.MONGO_URL;
|
||||
const databaseName = 'test';
|
||||
@ -40,7 +39,7 @@ test('insertMany', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBInsertMany({ request, connection });
|
||||
const res = await MongoDBInsertMany({ request, connection });
|
||||
expect(res).toEqual({
|
||||
insertedCount: 3,
|
||||
ops: [
|
||||
@ -68,7 +67,7 @@ test('insertMany options', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBInsertMany({ request, connection });
|
||||
const res = await MongoDBInsertMany({ request, connection });
|
||||
expect(res).toEqual({
|
||||
insertedCount: 2,
|
||||
ops: [
|
||||
@ -90,7 +89,7 @@ test('insertMany connection error', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
await expect(mongoDBInsertMany({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBInsertMany({ request, connection })).rejects.toThrow(
|
||||
'Invalid connection string'
|
||||
);
|
||||
});
|
||||
@ -103,8 +102,8 @@ test('insertMany mongodb error', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
await mongoDBInsertMany({ request, connection });
|
||||
await expect(mongoDBInsertMany({ request, connection })).rejects.toThrow(
|
||||
await MongoDBInsertMany({ request, connection });
|
||||
await expect(MongoDBInsertMany({ request, connection })).rejects.toThrow(
|
||||
'E11000 duplicate key error'
|
||||
);
|
||||
});
|
||||
|
@ -1,32 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Lowdefy Request Schema - MongoDBInsertMany",
|
||||
"type": "object",
|
||||
"required": ["docs"],
|
||||
"properties": {
|
||||
"docs": {
|
||||
"type": "array",
|
||||
"description": "The array of documents to be inserted.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBInsertMany request property \"docs\" should be an array."
|
||||
},
|
||||
"items": {
|
||||
"type": "object",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBInsertMany request property \"docs\" should be an array of documents to insert."
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"type": "object",
|
||||
"description": "Optional settings.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBInsertMany request property \"options\" should be an object."
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "MongoDBInsertMany request properties should be an object.",
|
||||
"required": "MongoDBInsertMany request should have required property \"docs\"."
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
import: {
|
||||
path: 'connections/MongoDBCollection/MongoDBInsertMany/MongoDBInsertMany.test.js',
|
||||
schema: 'connections/MongoDBCollection/MongoDBInsertMany/MongoDBInsertManySchema.json',
|
||||
},
|
||||
meta: {
|
||||
checkRead: false,
|
||||
checkWrite: true,
|
||||
},
|
||||
};
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
title: 'Lowdefy Request Schema - MongoDBInsertMany',
|
||||
type: 'object',
|
||||
required: ['docs'],
|
||||
properties: {
|
||||
docs: {
|
||||
type: 'array',
|
||||
description: 'The array of documents to be inserted.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBInsertMany request property "docs" should be an array.',
|
||||
},
|
||||
items: {
|
||||
type: 'object',
|
||||
errorMessage: {
|
||||
type: 'MongoDBInsertMany request property "docs" should be an array of documents to insert.',
|
||||
},
|
||||
},
|
||||
},
|
||||
options: {
|
||||
type: 'object',
|
||||
description: 'Optional settings.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBInsertMany request property "options" should be an object.',
|
||||
},
|
||||
},
|
||||
},
|
||||
errorMessage: {
|
||||
type: 'MongoDBInsertMany request properties should be an object.',
|
||||
required: 'MongoDBInsertMany request should have required property "docs".',
|
||||
},
|
||||
};
|
@ -16,8 +16,9 @@
|
||||
|
||||
import getCollection from '../getCollection.js';
|
||||
import { serialize, deserialize } from '../serialize.js';
|
||||
import schema from './schema.js';
|
||||
|
||||
async function mongodbInsertOne({ request, connection }) {
|
||||
async function MongodbInsertOne({ request, connection }) {
|
||||
const deserializedRequest = deserialize(request);
|
||||
const { doc, options } = deserializedRequest;
|
||||
const { collection, client } = await getCollection({ connection });
|
||||
@ -33,4 +34,10 @@ async function mongodbInsertOne({ request, connection }) {
|
||||
return { insertedCount, insertedId, ops };
|
||||
}
|
||||
|
||||
export default mongodbInsertOne;
|
||||
MongodbInsertOne.schema = schema;
|
||||
MongodbInsertOne.meta = {
|
||||
checkRead: false,
|
||||
checkWrite: true,
|
||||
};
|
||||
|
||||
export default MongodbInsertOne;
|
||||
|
@ -16,12 +16,11 @@
|
||||
|
||||
import { validate } from '@lowdefy/ajv';
|
||||
import { MongoClient } from 'mongodb';
|
||||
import mongoDBInsertOne from './MongoDBInsertOne.js';
|
||||
import MongoDBInsertOne from './MongoDBInsertOne.js';
|
||||
import clearTestMongoDb from '../../../../test/clearTestMongoDb.js';
|
||||
import requestIndex from './index.js';
|
||||
import schema from './MongoDBInsertOneSchema.json';
|
||||
|
||||
const { checkRead, checkWrite } = requestIndex.meta;
|
||||
const { checkRead, checkWrite } = MongoDBInsertOne.meta;
|
||||
const schema = MongoDBInsertOne.schema;
|
||||
|
||||
const databaseUri = process.env.MONGO_URL;
|
||||
const databaseName = 'test';
|
||||
@ -39,7 +38,7 @@ test('insertOne', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBInsertOne({ request, connection });
|
||||
const res = await MongoDBInsertOne({ request, connection });
|
||||
expect(res).toEqual({
|
||||
insertedCount: 1,
|
||||
insertedId: 'insertOne',
|
||||
@ -62,7 +61,7 @@ test('insertOne options', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBInsertOne({ request, connection });
|
||||
const res = await MongoDBInsertOne({ request, connection });
|
||||
expect(res).toEqual({
|
||||
insertedCount: 1,
|
||||
insertedId: 'insertOne_options',
|
||||
@ -82,7 +81,7 @@ test('insertOne connection error', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
await expect(mongoDBInsertOne({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBInsertOne({ request, connection })).rejects.toThrow(
|
||||
'Invalid connection string'
|
||||
);
|
||||
});
|
||||
@ -95,8 +94,8 @@ test('insertOne mongodb error', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
await mongoDBInsertOne({ request, connection });
|
||||
await expect(mongoDBInsertOne({ request, connection })).rejects.toThrow(
|
||||
await MongoDBInsertOne({ request, connection });
|
||||
await expect(MongoDBInsertOne({ request, connection })).rejects.toThrow(
|
||||
'E11000 duplicate key error'
|
||||
);
|
||||
});
|
||||
@ -122,7 +121,7 @@ test('insertOne insert a date', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBInsertOne({ request, connection });
|
||||
const res = await MongoDBInsertOne({ request, connection });
|
||||
expect(res).toEqual({
|
||||
insertedCount: 1,
|
||||
insertedId: 'insertOneDate',
|
||||
|
@ -1,26 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Lowdefy Request Schema - MongoDBInsertOne",
|
||||
"type": "object",
|
||||
"required": ["doc"],
|
||||
"properties": {
|
||||
"doc": {
|
||||
"type": "object",
|
||||
"description": "The document to be inserted.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBInsertOne request property \"doc\" should be an object."
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"type": "object",
|
||||
"description": "Optional settings.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBInsertOne request property \"options\" should be an object."
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "MongoDBInsertOne request properties should be an object.",
|
||||
"required": "MongoDBInsertOne request should have required property \"doc\"."
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
import: {
|
||||
path: 'connections/MongoDBCollection/MongoDBInsertOne/MongoDBInsertOne.js',
|
||||
schema: 'connections/MongoDBCollection/MongoDBInsertOne/MongoDBInsertOneSchema.json',
|
||||
},
|
||||
meta: {
|
||||
checkRead: false,
|
||||
checkWrite: true,
|
||||
},
|
||||
};
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
title: 'Lowdefy Request Schema - MongoDBInsertOne',
|
||||
type: 'object',
|
||||
required: ['doc'],
|
||||
properties: {
|
||||
doc: {
|
||||
type: 'object',
|
||||
description: 'The document to be inserted.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBInsertOne request property "doc" should be an object.',
|
||||
},
|
||||
},
|
||||
options: {
|
||||
type: 'object',
|
||||
description: 'Optional settings.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBInsertOne request property "options" should be an object.',
|
||||
},
|
||||
},
|
||||
},
|
||||
errorMessage: {
|
||||
type: 'MongoDBInsertOne request properties should be an object.',
|
||||
required: 'MongoDBInsertOne request should have required property "doc".',
|
||||
},
|
||||
};
|
@ -16,8 +16,9 @@
|
||||
|
||||
import getCollection from '../getCollection.js';
|
||||
import { serialize, deserialize } from '../serialize.js';
|
||||
import schema from './schema.js';
|
||||
|
||||
async function mongodbUpdateMany({ request, connection }) {
|
||||
async function MongodbUpdateMany({ request, connection }) {
|
||||
const deserializedRequest = deserialize(request);
|
||||
const { filter, update, options } = deserializedRequest;
|
||||
const { collection, client } = await getCollection({ connection });
|
||||
@ -33,4 +34,10 @@ async function mongodbUpdateMany({ request, connection }) {
|
||||
return { modifiedCount, upsertedId, upsertedCount, matchedCount };
|
||||
}
|
||||
|
||||
export default mongodbUpdateMany;
|
||||
MongodbUpdateMany.schema = schema;
|
||||
MongodbUpdateMany.meta = {
|
||||
checkRead: false,
|
||||
checkWrite: true,
|
||||
};
|
||||
|
||||
export default MongodbUpdateMany;
|
||||
|
@ -15,12 +15,11 @@
|
||||
*/
|
||||
|
||||
import { validate } from '@lowdefy/ajv';
|
||||
import mongoDBUpdateMany from './MongoDBUpdateMany.js';
|
||||
import MongoDBUpdateMany from './MongoDBUpdateMany.js';
|
||||
import populateTestMongoDb from '../../../../test/populateTestMongoDb.js';
|
||||
import requestIndex from './index.js';
|
||||
import schema from './MongoDBUpdateManySchema.json';
|
||||
|
||||
const { checkRead, checkWrite } = requestIndex.meta;
|
||||
const { checkRead, checkWrite } = MongoDBUpdateMany.meta;
|
||||
const schema = MongoDBUpdateMany.schema;
|
||||
|
||||
const databaseUri = process.env.MONGO_URL;
|
||||
const databaseName = 'test';
|
||||
@ -50,7 +49,7 @@ test('updateMany - Single Document', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBUpdateMany({ request, connection });
|
||||
const res = await MongoDBUpdateMany({ request, connection });
|
||||
expect(res).toEqual({
|
||||
modifiedCount: 1,
|
||||
upsertedId: null,
|
||||
@ -70,7 +69,7 @@ test('updateMany - Multiple Documents', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBUpdateMany({ request, connection });
|
||||
const res = await MongoDBUpdateMany({ request, connection });
|
||||
expect(res).toEqual({
|
||||
modifiedCount: 3,
|
||||
upsertedId: null,
|
||||
@ -90,7 +89,7 @@ test('updateMany - Multiple Documents one field', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBUpdateMany({ request, connection });
|
||||
const res = await MongoDBUpdateMany({ request, connection });
|
||||
expect(res).toEqual({
|
||||
modifiedCount: 3,
|
||||
upsertedId: null,
|
||||
@ -111,7 +110,7 @@ test('updateMany upsert', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBUpdateMany({ request, connection });
|
||||
const res = await MongoDBUpdateMany({ request, connection });
|
||||
expect(res).toEqual({
|
||||
modifiedCount: 0,
|
||||
upsertedId: {
|
||||
@ -135,7 +134,7 @@ test('updateMany upsert false', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBUpdateMany({ request, connection });
|
||||
const res = await MongoDBUpdateMany({ request, connection });
|
||||
expect(res).toEqual({
|
||||
modifiedCount: 0,
|
||||
upsertedId: null,
|
||||
@ -155,7 +154,7 @@ test('updateMany upsert default false', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBUpdateMany({ request, connection });
|
||||
const res = await MongoDBUpdateMany({ request, connection });
|
||||
expect(res).toEqual({
|
||||
modifiedCount: 0,
|
||||
upsertedId: null,
|
||||
@ -175,7 +174,7 @@ test('updateMany connection error', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
await expect(mongoDBUpdateMany({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBUpdateMany({ request, connection })).rejects.toThrow(
|
||||
'Invalid connection string'
|
||||
);
|
||||
});
|
||||
@ -191,7 +190,7 @@ test('updateMany mongodb error', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
await expect(mongoDBUpdateMany({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBUpdateMany({ request, connection })).rejects.toThrow(
|
||||
'Unknown modifier: $badOp'
|
||||
);
|
||||
});
|
||||
|
@ -1,36 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Lowdefy Request Schema - MongoDBUpdateMany",
|
||||
"type": "object",
|
||||
"required": ["filter", "update"],
|
||||
"properties": {
|
||||
"filter": {
|
||||
"type": "object",
|
||||
"description": "The filter used to select the documents to update.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBUpdateMany request property \"filter\" should be an object."
|
||||
}
|
||||
},
|
||||
"update": {
|
||||
"type": ["object", "array"],
|
||||
"description": "The update operations to be applied to the documents.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBUpdateMany request property \"update\" should be an object."
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"type": "object",
|
||||
"description": "Optional settings.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBUpdateMany request property \"options\" should be an object."
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "MongoDBUpdateMany request properties should be an object.",
|
||||
"required": {
|
||||
"filter": "MongoDBUpdateMany request should have required property \"filter\".",
|
||||
"update": "MongoDBUpdateMany request should have required property \"update\"."
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
import: {
|
||||
path: 'connections/MongoDBCollection/MongoDBUpdateMany/MongoDBUpdateMany.js',
|
||||
schema: 'connections/MongoDBCollection/MongoDBUpdateMany/MongoDBUpdateManySchema.json',
|
||||
},
|
||||
meta: {
|
||||
checkRead: false,
|
||||
checkWrite: true,
|
||||
},
|
||||
};
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
title: 'Lowdefy Request Schema - MongoDBUpdateMany',
|
||||
type: 'object',
|
||||
required: ['filter', 'update'],
|
||||
properties: {
|
||||
filter: {
|
||||
type: 'object',
|
||||
description: 'The filter used to select the documents to update.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBUpdateMany request property "filter" should be an object.',
|
||||
},
|
||||
},
|
||||
update: {
|
||||
type: ['object', 'array'],
|
||||
description: 'The update operations to be applied to the documents.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBUpdateMany request property "update" should be an object.',
|
||||
},
|
||||
},
|
||||
options: {
|
||||
type: 'object',
|
||||
description: 'Optional settings.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBUpdateMany request property "options" should be an object.',
|
||||
},
|
||||
},
|
||||
},
|
||||
errorMessage: {
|
||||
type: 'MongoDBUpdateMany request properties should be an object.',
|
||||
required: {
|
||||
filter: 'MongoDBUpdateMany request should have required property "filter".',
|
||||
update: 'MongoDBUpdateMany request should have required property "update".',
|
||||
},
|
||||
},
|
||||
};
|
@ -16,8 +16,9 @@
|
||||
|
||||
import getCollection from '../getCollection.js';
|
||||
import { serialize, deserialize } from '../serialize.js';
|
||||
import schema from './schema.js';
|
||||
|
||||
async function mongodbUpdateOne({ request, connection }) {
|
||||
async function MongodbUpdateOne({ request, connection }) {
|
||||
const deserializedRequest = deserialize(request);
|
||||
const { filter, update, options } = deserializedRequest;
|
||||
const { collection, client } = await getCollection({ connection });
|
||||
@ -33,4 +34,10 @@ async function mongodbUpdateOne({ request, connection }) {
|
||||
return { modifiedCount, upsertedId, upsertedCount, matchedCount };
|
||||
}
|
||||
|
||||
export default mongodbUpdateOne;
|
||||
MongodbUpdateOne.schema = schema;
|
||||
MongodbUpdateOne.meta = {
|
||||
checkRead: false,
|
||||
checkWrite: true,
|
||||
};
|
||||
|
||||
export default MongodbUpdateOne;
|
||||
|
@ -15,12 +15,11 @@
|
||||
*/
|
||||
|
||||
import { validate } from '@lowdefy/ajv';
|
||||
import mongoDBUpdateOne from './MongoDBUpdateOne.js';
|
||||
import MongoDBUpdateOne from './MongoDBUpdateOne.js';
|
||||
import populateTestMongoDb from '../../../../test/populateTestMongoDb.js';
|
||||
import requestIndex from './index.js';
|
||||
import schema from './MongoDBUpdateOneSchema.json';
|
||||
|
||||
const { checkRead, checkWrite } = requestIndex.meta;
|
||||
const { checkRead, checkWrite } = MongoDBUpdateOne.meta;
|
||||
const schema = MongoDBUpdateOne.schema;
|
||||
|
||||
const databaseUri = process.env.MONGO_URL;
|
||||
const databaseName = 'test';
|
||||
@ -42,7 +41,7 @@ test('updateOne', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBUpdateOne({ request, connection });
|
||||
const res = await MongoDBUpdateOne({ request, connection });
|
||||
expect(res).toEqual({
|
||||
modifiedCount: 1,
|
||||
upsertedId: null,
|
||||
@ -63,7 +62,7 @@ test('updateOne upsert', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBUpdateOne({ request, connection });
|
||||
const res = await MongoDBUpdateOne({ request, connection });
|
||||
expect(res).toEqual({
|
||||
modifiedCount: 0,
|
||||
upsertedId: {
|
||||
@ -87,7 +86,7 @@ test('updateOne upsert false', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBUpdateOne({ request, connection });
|
||||
const res = await MongoDBUpdateOne({ request, connection });
|
||||
expect(res).toEqual({
|
||||
modifiedCount: 0,
|
||||
upsertedId: null,
|
||||
@ -107,7 +106,7 @@ test('updateOne upsert default false', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await mongoDBUpdateOne({ request, connection });
|
||||
const res = await MongoDBUpdateOne({ request, connection });
|
||||
expect(res).toEqual({
|
||||
modifiedCount: 0,
|
||||
upsertedId: null,
|
||||
@ -127,7 +126,7 @@ test('updateOne connection error', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
await expect(mongoDBUpdateOne({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBUpdateOne({ request, connection })).rejects.toThrow(
|
||||
'Invalid connection string'
|
||||
);
|
||||
});
|
||||
@ -143,7 +142,7 @@ test('updateOne mongodb error', async () => {
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
await expect(mongoDBUpdateOne({ request, connection })).rejects.toThrow(
|
||||
await expect(MongoDBUpdateOne({ request, connection })).rejects.toThrow(
|
||||
'Unknown modifier: $badOp'
|
||||
);
|
||||
});
|
||||
|
@ -1,36 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Lowdefy Request Schema - MongoDBUpdateOne",
|
||||
"type": "object",
|
||||
"required": ["filter", "update"],
|
||||
"properties": {
|
||||
"filter": {
|
||||
"type": "object",
|
||||
"description": "The filter used to select the document to update.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBUpdateOne request property \"filter\" should be an object."
|
||||
}
|
||||
},
|
||||
"update": {
|
||||
"type": ["object", "array"],
|
||||
"description": "The update operations to be applied to the document.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBUpdateOne request property \"update\" should be an object."
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"type": "object",
|
||||
"description": "Optional settings.",
|
||||
"errorMessage": {
|
||||
"type": "MongoDBUpdateOne request property \"options\" should be an object."
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "MongoDBUpdateOne request properties should be an object.",
|
||||
"required": {
|
||||
"filter": "MongoDBUpdateOne request should have required property \"filter\".",
|
||||
"update": "MongoDBUpdateOne request should have required property \"update\"."
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
import: {
|
||||
path: 'connections/MongoDBCollection/MongoDBUpdateOne/MongoDBUpdateOne.js',
|
||||
schema: 'connections/MongoDBCollection/MongoDBUpdateOne/MongoDBUpdateOneSchema.json',
|
||||
},
|
||||
meta: {
|
||||
checkRead: false,
|
||||
checkWrite: true,
|
||||
},
|
||||
};
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
title: 'Lowdefy Request Schema - MongoDBUpdateOne',
|
||||
type: 'object',
|
||||
required: ['filter', 'update'],
|
||||
properties: {
|
||||
filter: {
|
||||
type: 'object',
|
||||
description: 'The filter used to select the document to update.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBUpdateOne request property "filter" should be an object.',
|
||||
},
|
||||
},
|
||||
update: {
|
||||
type: ['object', 'array'],
|
||||
description: 'The update operations to be applied to the document.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBUpdateOne request property "update" should be an object.',
|
||||
},
|
||||
},
|
||||
options: {
|
||||
type: 'object',
|
||||
description: 'Optional settings.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBUpdateOne request property "options" should be an object.',
|
||||
},
|
||||
},
|
||||
},
|
||||
errorMessage: {
|
||||
type: 'MongoDBUpdateOne request properties should be an object.',
|
||||
required: {
|
||||
filter: 'MongoDBUpdateOne request should have required property "filter".',
|
||||
update: 'MongoDBUpdateOne request should have required property "update".',
|
||||
},
|
||||
},
|
||||
};
|
@ -14,7 +14,8 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { MongoClient } from 'mongodb';
|
||||
import Mongo from 'mongodb';
|
||||
const { MongoClient } = Mongo;
|
||||
|
||||
async function getCollection({ connection }) {
|
||||
let client;
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export default {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
title: 'Lowdefy Connection Schema - MongoDBCollection',
|
||||
type: 'object',
|
||||
required: ['databaseUri', 'collection'],
|
||||
properties: {
|
||||
databaseUri: {
|
||||
type: 'string',
|
||||
description: 'Connection uri string for the MongoDb deployment.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBCollection connection property "databaseUri" should be a string.',
|
||||
},
|
||||
},
|
||||
databaseName: {
|
||||
type: 'string',
|
||||
description: 'AWS IAM secret access key with s3 access.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBCollection connection property "databaseName" should be a string.',
|
||||
},
|
||||
},
|
||||
collection: {
|
||||
type: 'string',
|
||||
description: 'AWS region the bucket is located in.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBCollection connection property "collection" should be a string.',
|
||||
},
|
||||
},
|
||||
read: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Allow reads from the collection.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBCollection connection property "read" should be a boolean.',
|
||||
},
|
||||
},
|
||||
write: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Allow writes to the collection.',
|
||||
errorMessage: {
|
||||
type: 'MongoDBCollection connection property "write" should be a boolean.',
|
||||
},
|
||||
},
|
||||
},
|
||||
errorMessage: {
|
||||
type: 'MongoDBCollection connection properties should be an object.',
|
||||
required: {
|
||||
databaseUri: 'MongoDBCollection connection should have required property "databaseUri".',
|
||||
collection: 'MongoDBCollection connection should have required property "collection".',
|
||||
},
|
||||
},
|
||||
};
|
@ -14,13 +14,15 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { ObjectID } from 'mongodb';
|
||||
import Mongo from 'mongodb';
|
||||
import { type } from '@lowdefy/helpers';
|
||||
|
||||
const { ObjectId } = Mongo;
|
||||
|
||||
function replacer(_, value) {
|
||||
if (type.isObject(value)) {
|
||||
Object.keys(value).forEach((key) => {
|
||||
if (value[key] instanceof ObjectID) {
|
||||
if (value[key] instanceof ObjectId) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
value[key] = { _oid: value[key].toHexString() };
|
||||
}
|
||||
@ -34,7 +36,7 @@ function replacer(_, value) {
|
||||
}
|
||||
if (type.isArray(value)) {
|
||||
return value.map((item) => {
|
||||
if (item instanceof ObjectID) {
|
||||
if (item instanceof ObjectId) {
|
||||
return { _oid: item.toHexString() };
|
||||
}
|
||||
if (type.isDate(item)) {
|
||||
@ -49,7 +51,7 @@ function replacer(_, value) {
|
||||
function reviver(key, value) {
|
||||
if (type.isObject(value)) {
|
||||
if (value._oid) {
|
||||
return ObjectID.createFromHexString(value._oid);
|
||||
return ObjectId.createFromHexString(value._oid);
|
||||
}
|
||||
if (type.isInt(value._date) || type.isString(value._date)) {
|
||||
return new Date(value._date);
|
||||
|
@ -1,7 +0,0 @@
|
||||
import MongoDBCollection from './connections/MongoDBCollection/MongoDBCollection.js';
|
||||
|
||||
export const connections = {
|
||||
MongoDBCollection,
|
||||
};
|
||||
|
||||
export default { connections };
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user