Browse Source

wip

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/1668/head
Pranav C 3 years ago
parent
commit
4f76ebffcd
  1. 79
      packages/nc-gui/package-lock.json
  2. 2
      packages/nc-gui/package.json
  3. 79
      packages/nocodb/package-lock.json
  4. 44
      packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasApis.ts
  5. 44
      packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasExportApis.ts
  6. 155
      packages/nocodb/src/lib/noco/meta/api/dataApis/helpers.ts
  7. 136
      packages/nocodb/src/lib/noco/meta/api/exportApis.ts
  8. 569
      scripts/sdk/swagger.json

79
packages/nc-gui/package-lock.json generated

@ -26,7 +26,7 @@
"monaco-editor": "^0.19.3", "monaco-editor": "^0.19.3",
"monaco-themes": "^0.2.5", "monaco-themes": "^0.2.5",
"nano-assign": "^1.0.1", "nano-assign": "^1.0.1",
"nocodb-sdk": "0.0.9", "nocodb-sdk": "file:../nocodb-sdk",
"nuxt": "^2.14.0", "nuxt": "^2.14.0",
"odometer": "^0.4.8", "odometer": "^0.4.8",
"papaparse": "^5.3.1", "papaparse": "^5.3.1",
@ -69,6 +69,42 @@
"vue-eslint-parser": "^7.9.0" "vue-eslint-parser": "^7.9.0"
} }
}, },
"../nocodb-sdk": {
"version": "0.0.9",
"license": "MIT",
"dependencies": {
"axios": "^0.21.1",
"jsep": "^0.4.0"
},
"devDependencies": {
"@ava/typescript": "^1.1.1",
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"ava": "^3.12.1",
"codecov": "^3.5.0",
"cspell": "^4.1.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^3.0.2",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-prettier": "^4.0.0",
"gh-pages": "^3.1.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"open-cli": "^6.0.1",
"prettier": "^2.1.1",
"standard-version": "^9.0.0",
"ts-node": "^9.0.0",
"typedoc": "^0.19.0",
"typescript": "^4.0.2"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@ampproject/remapping": { "node_modules/@ampproject/remapping": {
"version": "2.1.2", "version": "2.1.2",
"license": "Apache-2.0", "license": "Apache-2.0",
@ -9541,16 +9577,8 @@
} }
}, },
"node_modules/nocodb-sdk": { "node_modules/nocodb-sdk": {
"version": "0.0.9", "resolved": "../nocodb-sdk",
"resolved": "https://registry.npmjs.org/nocodb-sdk/-/nocodb-sdk-0.0.9.tgz", "link": true
"integrity": "sha512-MwvHh9WtplJtB2z41DbDUF09bYRLX4WBA+IytgPRWr5e3s8UEBzKZiKN7sLcVnmiY6a9ctT4Ad0CS4viwExoQw==",
"dependencies": {
"axios": "^0.21.1",
"jsep": "^0.4.0"
},
"engines": {
"node": ">=10"
}
}, },
"node_modules/node-fetch": { "node_modules/node-fetch": {
"version": "2.6.7", "version": "2.6.7",
@ -21397,12 +21425,33 @@
} }
}, },
"nocodb-sdk": { "nocodb-sdk": {
"version": "0.0.9", "version": "file:../nocodb-sdk",
"resolved": "https://registry.npmjs.org/nocodb-sdk/-/nocodb-sdk-0.0.9.tgz",
"integrity": "sha512-MwvHh9WtplJtB2z41DbDUF09bYRLX4WBA+IytgPRWr5e3s8UEBzKZiKN7sLcVnmiY6a9ctT4Ad0CS4viwExoQw==",
"requires": { "requires": {
"@ava/typescript": "^1.1.1",
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"ava": "^3.12.1",
"axios": "^0.21.1", "axios": "^0.21.1",
"jsep": "^0.4.0" "codecov": "^3.5.0",
"cspell": "^4.1.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^3.0.2",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-prettier": "^4.0.0",
"gh-pages": "^3.1.0",
"jsep": "^0.4.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"open-cli": "^6.0.1",
"prettier": "^2.1.1",
"standard-version": "^9.0.0",
"ts-node": "^9.0.0",
"typedoc": "^0.19.0",
"typescript": "^4.0.2"
} }
}, },
"node-fetch": { "node-fetch": {

2
packages/nc-gui/package.json

@ -29,7 +29,7 @@
"monaco-editor": "^0.19.3", "monaco-editor": "^0.19.3",
"monaco-themes": "^0.2.5", "monaco-themes": "^0.2.5",
"nano-assign": "^1.0.1", "nano-assign": "^1.0.1",
"nocodb-sdk": "0.0.9", "nocodb-sdk": "file:../nocodb-sdk",
"nuxt": "^2.14.0", "nuxt": "^2.14.0",
"odometer": "^0.4.8", "odometer": "^0.4.8",
"papaparse": "^5.3.1", "papaparse": "^5.3.1",

79
packages/nocodb/package-lock.json generated

@ -72,7 +72,7 @@
"nc-lib-gui": "0.84.15", "nc-lib-gui": "0.84.15",
"nc-plugin": "^0.1.1", "nc-plugin": "^0.1.1",
"ncp": "^2.0.0", "ncp": "^2.0.0",
"nocodb-sdk": "0.0.9", "nocodb-sdk": "file:../nocodb-sdk",
"nodemailer": "^6.4.10", "nodemailer": "^6.4.10",
"ora": "^4.0.4", "ora": "^4.0.4",
"os-locale": "^5.0.0", "os-locale": "^5.0.0",
@ -227,6 +227,42 @@
"node": ">=8.9" "node": ">=8.9"
} }
}, },
"../nocodb-sdk": {
"version": "0.0.9",
"license": "MIT",
"dependencies": {
"axios": "^0.21.1",
"jsep": "^0.4.0"
},
"devDependencies": {
"@ava/typescript": "^1.1.1",
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"ava": "^3.12.1",
"codecov": "^3.5.0",
"cspell": "^4.1.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^3.0.2",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-prettier": "^4.0.0",
"gh-pages": "^3.1.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"open-cli": "^6.0.1",
"prettier": "^2.1.1",
"standard-version": "^9.0.0",
"ts-node": "^9.0.0",
"typedoc": "^0.19.0",
"typescript": "^4.0.2"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@assemblyscript/loader": { "node_modules/@assemblyscript/loader": {
"version": "0.10.1", "version": "0.10.1",
"resolved": "https://registry.npmjs.org/@assemblyscript/loader/-/loader-0.10.1.tgz", "resolved": "https://registry.npmjs.org/@assemblyscript/loader/-/loader-0.10.1.tgz",
@ -16216,16 +16252,8 @@
"dev": true "dev": true
}, },
"node_modules/nocodb-sdk": { "node_modules/nocodb-sdk": {
"version": "0.0.9", "resolved": "../nocodb-sdk",
"resolved": "https://registry.npmjs.org/nocodb-sdk/-/nocodb-sdk-0.0.9.tgz", "link": true
"integrity": "sha512-MwvHh9WtplJtB2z41DbDUF09bYRLX4WBA+IytgPRWr5e3s8UEBzKZiKN7sLcVnmiY6a9ctT4Ad0CS4viwExoQw==",
"dependencies": {
"axios": "^0.21.1",
"jsep": "^0.4.0"
},
"engines": {
"node": ">=10"
}
}, },
"node_modules/node-addon-api": { "node_modules/node-addon-api": {
"version": "2.0.0", "version": "2.0.0",
@ -37627,12 +37655,33 @@
"dev": true "dev": true
}, },
"nocodb-sdk": { "nocodb-sdk": {
"version": "0.0.9", "version": "file:../nocodb-sdk",
"resolved": "https://registry.npmjs.org/nocodb-sdk/-/nocodb-sdk-0.0.9.tgz",
"integrity": "sha512-MwvHh9WtplJtB2z41DbDUF09bYRLX4WBA+IytgPRWr5e3s8UEBzKZiKN7sLcVnmiY6a9ctT4Ad0CS4viwExoQw==",
"requires": { "requires": {
"@ava/typescript": "^1.1.1",
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"ava": "^3.12.1",
"axios": "^0.21.1", "axios": "^0.21.1",
"jsep": "^0.4.0" "codecov": "^3.5.0",
"cspell": "^4.1.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^3.0.2",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-prettier": "^4.0.0",
"gh-pages": "^3.1.0",
"jsep": "^0.4.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"open-cli": "^6.0.1",
"prettier": "^2.1.1",
"standard-version": "^9.0.0",
"ts-node": "^9.0.0",
"typedoc": "^0.19.0",
"typescript": "^4.0.2"
} }
}, },
"node-addon-api": { "node-addon-api": {

44
packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasApis.ts

@ -6,16 +6,15 @@ import NcConnectionMgrv2 from '../../../common/NcConnectionMgrv2';
import { PagedResponseImpl } from '../../helpers/PagedResponse'; import { PagedResponseImpl } from '../../helpers/PagedResponse';
import View from '../../../../noco-models/View'; import View from '../../../../noco-models/View';
import ncMetaAclMw from '../../helpers/ncMetaAclMw'; import ncMetaAclMw from '../../helpers/ncMetaAclMw';
import Project from '../../../../noco-models/Project'; import { getViewAndModelFromRequestByAliasOrId } from './helpers';
import { NcError } from '../../helpers/catchError';
export async function dataList(req: Request, res: Response) { export async function dataList(req: Request, res: Response) {
const { model, view } = await getViewAndModelFromRequest(req); const { model, view } = await getViewAndModelFromRequestByAliasOrId(req);
res.json(await getDataList(model, view, req)); res.json(await getDataList(model, view, req));
} }
async function dataInsert(req: Request, res: Response) { async function dataInsert(req: Request, res: Response) {
const { model, view } = await getViewAndModelFromRequest(req); const { model, view } = await getViewAndModelFromRequestByAliasOrId(req);
const base = await Base.get(model.base_id); const base = await Base.get(model.base_id);
@ -29,7 +28,7 @@ async function dataInsert(req: Request, res: Response) {
} }
async function dataUpdate(req: Request, res: Response) { async function dataUpdate(req: Request, res: Response) {
const { model, view } = await getViewAndModelFromRequest(req); const { model, view } = await getViewAndModelFromRequestByAliasOrId(req);
const base = await Base.get(model.base_id); const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({ const baseModel = await Model.getBaseModelSQL({
@ -42,7 +41,7 @@ async function dataUpdate(req: Request, res: Response) {
} }
async function dataDelete(req: Request, res: Response) { async function dataDelete(req: Request, res: Response) {
const { model, view } = await getViewAndModelFromRequest(req); const { model, view } = await getViewAndModelFromRequestByAliasOrId(req);
const base = await Base.get(model.base_id); const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({ const baseModel = await Model.getBaseModelSQL({
id: model.id, id: model.id,
@ -85,25 +84,9 @@ async function getDataList(model, view: View, req) {
count count
}); });
} }
async function getViewAndModelFromRequest(req) {
const project = await Project.getWithInfoByTitle(req.params.projectName);
const model = await Model.getByAliasOrId({
project_id: project.id,
base_id: project.bases?.[0]?.id,
aliasOrId: req.params.tableName
});
const view =
req.params.viewName &&
(await View.getByTitleOrId({
titleOrId: req.params.viewName,
fk_model_id: model.id
}));
if (!model) NcError.notFound('Table not found');
return { model, view };
}
async function dataRead(req: Request, res: Response) { async function dataRead(req: Request, res: Response) {
const { model, view } = await getViewAndModelFromRequest(req); const { model, view } = await getViewAndModelFromRequestByAliasOrId(req);
const base = await Base.get(model.base_id); const base = await Base.get(model.base_id);
@ -125,26 +108,29 @@ async function dataRead(req: Request, res: Response) {
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get('/data/:orgs/:projectName/:tableName', ncMetaAclMw(dataList, 'dataList'));
router.get( router.get(
'/data/:orgs/:projectName/:tableName/views/:viewName', '/api/v1/db/data/:orgs/:projectName/:tableName',
ncMetaAclMw(dataList, 'dataList')
);
router.get(
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName',
ncMetaAclMw(dataList, 'dataList') ncMetaAclMw(dataList, 'dataList')
); );
router.post( router.post(
'/data/:orgs/:projectName/:tableName/views/:viewName', '/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName',
ncMetaAclMw(dataInsert, 'dataInsert') ncMetaAclMw(dataInsert, 'dataInsert')
); );
router.put( router.put(
'/data/:orgs/:projectName/:tableName/views/:viewName/:rowId', '/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/:rowId',
ncMetaAclMw(dataUpdate, 'dataUpdate') ncMetaAclMw(dataUpdate, 'dataUpdate')
); );
router.get( router.get(
'/data/:orgs/:projectName/:tableName/views/:viewName/:rowId', '/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/:rowId',
ncMetaAclMw(dataRead, 'dataRead') ncMetaAclMw(dataRead, 'dataRead')
); );
router.delete( router.delete(
'/data/:orgs/:projectName/:tableName/views/:viewName/:rowId', '/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/:rowId',
ncMetaAclMw(dataDelete, 'dataDelete') ncMetaAclMw(dataDelete, 'dataDelete')
); );

44
packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasExportApis.ts

@ -0,0 +1,44 @@
import { Request, Response, Router } from 'express';
import ncMetaAclMw from '../../helpers/ncMetaAclMw';
import {
extractCsvData,
getViewAndModelFromRequestByAliasOrId
} from './helpers';
import papaparse from 'papaparse';
async function csvDataExport(req: Request, res: Response) {
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req);
const { offset, csvRows, elapsed } = await extractCsvData(model, view, req);
const data = papaparse.unparse(
{
fields: model.columns.map(c => c.title),
data: csvRows
},
{
escapeFormulae: true
}
);
res.set({
'Access-Control-Expose-Headers': 'nc-export-offset',
'nc-export-offset': offset,
'nc-export-elapsed-time': elapsed,
'Content-Disposition': `attachment; filename="${view.title}-export.csv"`
});
res.send(data);
}
const router = Router({ mergeParams: true });
router.get(
'/api/v1/db/data/:orgs/:projectName/:tableName/export/csv',
ncMetaAclMw(csvDataExport, 'csvDataExport')
);
router.get(
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/export/csv',
ncMetaAclMw(csvDataExport, 'csvDataExport')
);
export default router;

155
packages/nocodb/src/lib/noco/meta/api/dataApis/helpers.ts

@ -0,0 +1,155 @@
import Project from '../../../../noco-models/Project';
import Model from '../../../../noco-models/Model';
import View from '../../../../noco-models/View';
import { NcError } from '../../helpers/catchError';
import { Request } from 'express';
import Base from '../../../../noco-models/Base';
import NcConnectionMgrv2 from '../../../common/NcConnectionMgrv2';
import { isSystemColumn, UITypes } from 'nocodb-sdk';
import { nocoExecute } from 'nc-help';
import Column from '../../../../noco-models/Column';
import LookupColumn from '../../../../noco-models/LookupColumn';
import LinkToAnotherRecordColumn from '../../../../noco-models/LinkToAnotherRecordColumn';
export async function getViewAndModelFromRequestByAliasOrId(
req:
| Request<{ projectName: string; tableName: string; viewName?: string }>
| Request
) {
let project = await Project.getWithInfoByTitle(req.params.projectName);
if (!project) {
project = await Project.getWithInfo(req.params.projectName);
}
const model = await Model.getByAliasOrId({
project_id: project.id,
base_id: project.bases?.[0]?.id,
aliasOrId: req.params.tableName
});
const view =
req.params.viewName &&
(await View.getByTitleOrId({
titleOrId: req.params.viewName,
fk_model_id: model.id
}));
if (!model) NcError.notFound('Table not found');
return { model, view };
}
export async function extractCsvData(model: Model, view: View, req: Request) {
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: NcConnectionMgrv2.get(base)
});
let offset = +req.query.offset || 0;
const limit = 100;
// const size = +process.env.NC_EXPORT_MAX_SIZE || 1024;
const timeout = +process.env.NC_EXPORT_MAX_TIMEOUT || 5000;
const csvRows = [];
const startTime = process.hrtime();
let elapsed, temp;
for (
elapsed = 0;
elapsed < timeout;
offset += limit,
temp = process.hrtime(startTime),
elapsed = temp[0] * 1000 + temp[1] / 1000000
) {
const rows = await nocoExecute(
await baseModel.defaultResolverReq(req.query, false, false),
await baseModel.list({ ...req.query, offset, limit }),
{},
req.query
);
if (!rows?.length) {
offset = -1;
break;
}
for (const row of rows) {
const csvRow = { ...row };
for (const column of view.model.columns) {
if (isSystemColumn(column) && !view.show_system_fields) continue;
csvRow[column.title] = await serializeCellValue({
value: row[column.title],
column
});
}
csvRows.push(csvRow);
}
}
return { offset, csvRows, elapsed };
}
export async function serializeCellValue({
value,
column
}: {
column?: Column;
value: any;
}) {
if (!column) {
return value;
}
if (!value) return value;
switch (column?.uidt) {
case UITypes.Attachment: {
let data = value;
try {
if (typeof value === 'string') {
data = JSON.parse(value);
}
} catch {}
return (data || []).map(
attachment =>
`${encodeURI(attachment.title)}(${encodeURI(attachment.url)})`
);
}
case UITypes.Lookup:
{
const colOptions = await column.getColOptions<LookupColumn>();
const lookupColumn = await colOptions.getLookupColumn();
return (
await Promise.all(
[...(Array.isArray(value) ? value : [value])].map(async v =>
serializeCellValue({
value: v,
column: lookupColumn
})
)
)
).join(', ');
}
break;
case UITypes.LinkToAnotherRecord:
{
const colOptions = await column.getColOptions<
LinkToAnotherRecordColumn
>();
const relatedModel = await colOptions.getRelatedTable();
await relatedModel.getColumns();
return [...(Array.isArray(value) ? value : [value])]
.map(v => {
return v[relatedModel.primaryValue?.title];
})
.join(', ');
}
break;
default:
if (value && typeof value === 'object') {
return JSON.stringify(value);
}
return value;
}
}

136
packages/nocodb/src/lib/noco/meta/api/exportApis.ts

@ -1,15 +1,10 @@
import { Request, Response, Router } from 'express'; import { Request, Response, Router } from 'express';
import View from '../../../noco-models/View'; import View from '../../../noco-models/View';
import Model from '../../../noco-models/Model';
import Base from '../../../noco-models/Base';
import NcConnectionMgrv2 from '../../common/NcConnectionMgrv2';
import { nocoExecute } from 'nc-help';
import papaparse from 'papaparse'; import papaparse from 'papaparse';
import { isSystemColumn, UITypes } from 'nocodb-sdk'; import { isSystemColumn } from 'nocodb-sdk';
import Column from '../../../noco-models/Column'; import Column from '../../../noco-models/Column';
import LinkToAnotherRecordColumn from '../../../noco-models/LinkToAnotherRecordColumn';
import LookupColumn from '../../../noco-models/LookupColumn';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { extractCsvData } from './dataApis/helpers';
async function exportCsv(req: Request, res: Response, next) { async function exportCsv(req: Request, res: Response, next) {
const view = await View.get(req.params.viewId); const view = await View.get(req.params.viewId);
@ -26,67 +21,7 @@ async function exportCsv(req: Request, res: Response, next) {
.filter(column => !isSystemColumn(column) || view.show_system_fields); .filter(column => !isSystemColumn(column) || view.show_system_fields);
if (!model) return next(new Error('Table not found')); if (!model) return next(new Error('Table not found'));
const { offset, csvRows, elapsed } = await extractCsvData(model, view, req);
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: NcConnectionMgrv2.get(base)
});
const key = `${model.title}List`;
const requestObj = {
[key]: await baseModel.defaultResolverReq(req.query, false, false)
};
let offset = +req.query.offset || 0;
const limit = 100;
// const size = +process.env.NC_EXPORT_MAX_SIZE || 1024;
const timeout = +process.env.NC_EXPORT_MAX_TIMEOUT || 5000;
const csvRows = [];
const startTime = process.hrtime();
let elapsed, temp;
for (
elapsed = 0;
elapsed < timeout;
offset += limit,
temp = process.hrtime(startTime),
elapsed = temp[0] * 1000 + temp[1] / 1000000
) {
console.time('nocoExecute');
const rows = (
await nocoExecute(
requestObj,
{
[key]: async args => {
return await baseModel.list({ ...args, offset, limit });
}
},
{},
{ nested: { [key]: req.query } }
)
)?.[key];
if (!rows?.length) {
offset = -1;
break;
}
for (const row of rows) {
const csvRow = { ...row };
for (const column of view.model.columns) {
if (isSystemColumn(column) && !view.show_system_fields) continue;
csvRow[column.title] = await serializeCellValue({
value: row[column.title],
column
});
}
csvRows.push(csvRow);
}
console.timeEnd('nocoExecute');
}
const data = papaparse.unparse( const data = papaparse.unparse(
{ {
@ -107,71 +42,6 @@ async function exportCsv(req: Request, res: Response, next) {
res.send(data); res.send(data);
} }
async function serializeCellValue({
value,
column
}: {
column?: Column;
value: any;
}) {
if (!column) {
return value;
}
if (!value) return value;
switch (column?.uidt) {
case UITypes.Attachment: {
let data = value;
try {
if (typeof value === 'string') {
data = JSON.parse(value);
}
} catch {}
return (data || []).map(
attachment =>
`${encodeURI(attachment.title)}(${encodeURI(attachment.url)})`
);
}
case UITypes.Lookup:
{
const colOptions = await column.getColOptions<LookupColumn>();
const lookupColumn = await colOptions.getLookupColumn();
return (
await Promise.all(
[...(Array.isArray(value) ? value : [value])].map(async v =>
serializeCellValue({
value: v,
column: lookupColumn
})
)
)
).join(', ');
}
break;
case UITypes.LinkToAnotherRecord:
{
const colOptions = await column.getColOptions<
LinkToAnotherRecordColumn
>();
const relatedModel = await colOptions.getRelatedTable();
await relatedModel.getColumns();
return [...(Array.isArray(value) ? value : [value])]
.map(v => {
return v[relatedModel.primaryValue?.title];
})
.join(', ');
}
break;
default:
if (value && typeof value === 'object') {
return JSON.stringify(value);
}
return value;
}
}
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get('/data/:viewId/export/csv', ncMetaAclMw(exportCsv, 'exportCsv')); router.get('/data/:viewId/export/csv', ncMetaAclMw(exportCsv, 'exportCsv'));
export default router; export default router;

569
scripts/sdk/swagger.json

@ -2817,7 +2817,59 @@
} }
} }
}, },
"/data/{orgs}/{projectName}/{tableAlias}": { "/data/{tableId}/export/{type}": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "tableId",
"in": "path",
"required": true
},
{
"schema": {
"type": "string",
"enum": [
"csv",
"excel"
]
},
"name": "type",
"in": "path",
"required": true
}
],
"get": {
"summary": "",
"operationId": "data-csv-export",
"description": "CSV or Excel export",
"tags": [
"Data"
],
"wrapped": true,
"responses": {
"200": {
"description": "OK",
"content": {
"application/octet-stream": {
"schema": {}
}
},
"headers": {
"nc-export-offset": {
"schema": {
"type": "integer"
}
}
}
}
},
"parameters": []
}
},
"/api/v1/db/data/{orgs}/{projectName}/{tableAlias}": {
"parameters": [ "parameters": [
{ {
"schema": { "schema": {
@ -2910,7 +2962,7 @@
} }
} }
}, },
"/data/{orgs}/{projectName}/{tableAlias}/views/{viewName}": { "/api/v1/db/data/{orgs}/{projectName}/{tableAlias}/views/{viewName}": {
"parameters": [ "parameters": [
{ {
"schema": { "schema": {
@ -2991,39 +3043,328 @@
} }
} }
} }
}, },
"post": { "post": {
"summary": "",
"operationId": "db-view-row-create",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {}
}
}
}
},
"tags": [
"DB View Row"
],
"requestBody": {
"content": {
"application/json": {
"schema": {}
}
}
}
}
},
"/api/v1/db/data/{orgs}/{projectName}/{tableAlias}/views/{viewName}/{rowId}": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "orgs",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "projectName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "tableAlias",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "viewName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "rowId",
"in": "path",
"required": true
}
],
"get": {
"summary": "",
"operationId": "db-view-row-read",
"responses": {
"201": {
"description": "Created",
"content": {
"application/json": {
"schema": {}
}
}
}
},
"description": "",
"tags": [
"DB View Row"
]
},
"put": {
"summary": "",
"operationId": "db-view-row-update",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {}
}
}
}
},
"tags": [
"DB View Row"
],
"requestBody": {
"content": {
"application/json": {
"schema": {}
}
}
}
},
"delete": {
"summary": "",
"operationId": "db-view-row-delete",
"responses": {
"200": {
"description": "OK"
}
},
"tags": [
"DB View Row"
],
"description": ""
}
},
"/api/v1/db/data/{orgs}/{projectName}/{tableAlias}/{rowId}": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "orgs",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "projectName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "tableAlias",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "rowId",
"in": "path",
"required": true
}
],
"get": {
"summary": "",
"operationId": "db-table-row-read",
"responses": {
"201": {
"description": "Created",
"content": {
"application/json": {
"schema": {}
}
}
}
},
"description": "",
"tags": [
"DB Table Row"
]
},
"put": {
"summary": "",
"operationId": "db-table-row-update",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {}
}
}
}
},
"tags": [
"DB Table Row"
],
"requestBody": {
"content": {
"application/json": {
"schema": {}
}
}
}
},
"delete": {
"summary": "",
"operationId": "db-table-row-model-delete",
"responses": {
"200": {
"description": "OK"
}
},
"tags": [
"DB Table Row"
],
"description": ""
}
},
"/api/v1/db/data/{orgs}/{projectName}/{tableAlias}/views/{viewName}/export/{type}": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "orgs",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "projectName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "tableAlias",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "viewName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string",
"enum": [
"csv",
"excel"
]
},
"name": "type",
"in": "path",
"required": true
}
],
"get": {
"summary": "", "summary": "",
"operationId": "db-view-row-create", "operationId": "data-csv-export",
"description": "CSV or Excel export",
"tags": [
"Data"
],
"wrapped": true,
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
"content": { "content": {
"application/json": { "application/octet-stream": {
"schema": {} "schema": {}
} }
},
"headers": {
"nc-export-offset": {
"schema": {
"type": "integer"
}
}
} }
} }
}, },
"tags": [ "parameters": []
"DB View Row"
],
"requestBody": {
"content": {
"application/json": {
"schema": {}
}
}
}
} }
}, },
"/data/{tableId}/export/{type}": { "/api/v1/db/data/{orgs}/{projectName}/{tableAlias}/export/{type}": {
"parameters": [ "parameters": [
{ {
"schema": { "schema": {
"type": "string" "type": "string"
}, },
"name": "tableId", "name": "orgs",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "projectName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "tableAlias",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "viewName",
"in": "path", "in": "path",
"required": true "required": true
}, },
@ -3068,6 +3409,8 @@
"parameters": [] "parameters": []
} }
}, },
"/public/data/{uuid}/list": { "/public/data/{uuid}/list": {
"parameters": [ "parameters": [
{ {
@ -3792,196 +4135,6 @@
"description": "" "description": ""
} }
}, },
"/data/{orgs}/{projectName}/{tableAlias}/views/{viewName}/{rowId}": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "orgs",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "projectName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "tableAlias",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "viewName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "rowId",
"in": "path",
"required": true
}
],
"get": {
"summary": "",
"operationId": "db-view-row-read",
"responses": {
"201": {
"description": "Created",
"content": {
"application/json": {
"schema": {}
}
}
}
},
"description": "",
"tags": [
"DB View Row"
]
},
"put": {
"summary": "",
"operationId": "db-view-row-update",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {}
}
}
}
},
"tags": [
"DB View Row"
],
"requestBody": {
"content": {
"application/json": {
"schema": {}
}
}
}
},
"delete": {
"summary": "",
"operationId": "db-view-row-delete",
"responses": {
"200": {
"description": "OK"
}
},
"tags": [
"DB View Row"
],
"description": ""
}
},
"/data/{orgs}/{projectName}/{tableAlias}/{rowId}": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "orgs",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "projectName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "tableAlias",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "rowId",
"in": "path",
"required": true
}
],
"get": {
"summary": "",
"operationId": "db-table-row-read",
"responses": {
"201": {
"description": "Created",
"content": {
"application/json": {
"schema": {}
}
}
}
},
"description": "",
"tags": [
"DB Table Row"
]
},
"put": {
"summary": "",
"operationId": "db-table-row-update",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {}
}
}
}
},
"tags": [
"DB Table Row"
],
"requestBody": {
"content": {
"application/json": {
"schema": {}
}
}
}
},
"delete": {
"summary": "",
"operationId": "db-table-row-model-delete",
"responses": {
"200": {
"description": "OK"
}
},
"tags": [
"DB Table Row"
],
"description": ""
}
},
"/audits/comments": { "/audits/comments": {
"parameters": [], "parameters": [],
"get": { "get": {

Loading…
Cancel
Save