refactor(core): Remove linting exceptions in nodes-base (no-changelog) (#4944)

This commit is contained in:
Michael Kret
2023-01-13 19:11:56 +02:00
committed by GitHub
parent d7732ea150
commit 6608e69457
254 changed files with 2687 additions and 2675 deletions

View File

@@ -20,6 +20,56 @@ import {
import _ from 'lodash';
const userBaseUri = (uri?: string) => {
if (uri === undefined) {
return uri;
}
if (uri.endsWith('/')) {
return uri.slice(0, -1);
}
return uri;
};
export function resolveBaseUri(ctx: ICtx) {
return ctx?.credentials?.environment === 'cloudHosted'
? 'https://cloud.seatable.io'
: userBaseUri(ctx?.credentials?.domain);
}
export async function getBaseAccessToken(
this: IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions,
ctx: ICtx,
) {
if (ctx?.base?.access_token !== undefined) {
return;
}
const options: OptionsWithUri = {
headers: {
Authorization: `Token ${ctx?.credentials?.token}`,
},
uri: `${resolveBaseUri(ctx)}/api/v2.1/dtable/app-access-token/`,
json: true,
};
ctx.base = await this.helpers.request(options);
}
function endpointCtxExpr(ctx: ICtx, endpoint: string): string {
const endpointVariables: IEndpointVariables = {};
endpointVariables.access_token = ctx?.base?.access_token;
endpointVariables.dtable_uuid = ctx?.base?.dtable_uuid;
return endpoint.replace(
/({{ *(access_token|dtable_uuid|server) *}})/g,
(match: string, expr: string, name: TEndpointVariableName) => {
return endpointVariables[name] ?? match;
},
);
}
export async function seaTableApiRequest(
this: IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions,
ctx: ICtx,
@@ -44,7 +94,7 @@ export async function seaTableApiRequest(
method,
qs,
body,
uri: url || `${resolveBaseUri(ctx)}${endpointCtxExpr(ctx, endpoint)}`,
uri: url ?? `${resolveBaseUri(ctx)}${endpointCtxExpr(ctx, endpoint)}`,
json: true,
};
@@ -57,7 +107,6 @@ export async function seaTableApiRequest(
}
try {
//@ts-ignore
return await this.helpers.request(options);
} catch (error) {
throw new NodeApiError(this.getNode(), error);
@@ -138,31 +187,6 @@ export async function getTableViews(
return views;
}
export async function getBaseAccessToken(
this: IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions,
ctx: ICtx,
) {
if (ctx?.base?.access_token !== undefined) {
return;
}
const options: OptionsWithUri = {
headers: {
Authorization: `Token ${ctx?.credentials?.token}`,
},
uri: `${resolveBaseUri(ctx)}/api/v2.1/dtable/app-access-token/`,
json: true,
};
ctx.base = await this.helpers.request(options);
}
export function resolveBaseUri(ctx: ICtx) {
return ctx?.credentials?.environment === 'cloudHosted'
? 'https://cloud.seatable.io'
: userBaseUri(ctx?.credentials?.domain);
}
export function simplify(data: { results: IRow[] }, metadata: IDataObject) {
return data.results.map((row: IDataObject) => {
for (const key of Object.keys(row)) {
@@ -195,6 +219,14 @@ const namePredicate = (name: string) => (named: IName) => named.name === name;
export const nameOfPredicate = (names: readonly IName[]) => (name: string) =>
names.find(namePredicate(name));
const normalize = (subject: string): string => (subject ? subject.normalize() : '');
export const split = (subject: string): string[] =>
normalize(subject)
.split(/\s*((?:[^\\,]*?(?:\\[\s\S])*)*?)\s*(?:,|$)/)
.filter((s) => s.length)
.map((s) => s.replace(/\\([\s\S])/gm, ($0, $1) => $1));
export function columnNamesToArray(columnNames: string): string[] {
return columnNames ? split(columnNames).filter(nonInternalPredicate).filter(uniquePredicate) : [];
}
@@ -308,36 +340,3 @@ export const dtableSchemaColumns = (columns: TDtableMetadataColumns): TDtableMet
export const updateAble = (columns: TDtableMetadataColumns): TDtableMetadataColumns =>
columns.filter(dtableSchemaIsUpdateAbleColumn);
function endpointCtxExpr(ctx: ICtx, endpoint: string): string {
const endpointVariables: IEndpointVariables = {};
endpointVariables.access_token = ctx?.base?.access_token;
endpointVariables.dtable_uuid = ctx?.base?.dtable_uuid;
return endpoint.replace(
/({{ *(access_token|dtable_uuid|server) *}})/g,
(match: string, expr: string, name: TEndpointVariableName) => {
return endpointVariables[name] || match;
},
);
}
const normalize = (subject: string): string => (subject ? subject.normalize() : '');
export const split = (subject: string): string[] =>
normalize(subject)
.split(/\s*((?:[^\\,]*?(?:\\[\s\S])*)*?)\s*(?:,|$)/)
.filter((s) => s.length)
.map((s) => s.replace(/\\([\s\S])/gm, ($0, $1) => $1));
const userBaseUri = (uri?: string) => {
if (uri === undefined) {
return uri;
}
if (uri.endsWith('/')) {
return uri.slice(0, -1);
}
return uri;
};