(core) New type conversion in the backend

Summary: This is https://phab.getgrist.com/D3205 plus some changes (https://github.com/dsagal/grist/compare/type-convert...type-convert-server?expand=1) that move the conversion process to the backend. A new user action ConvertFromColumn uses `call_external` so that the data engine can delegate back to ActiveDoc. Code for creating formatters and parsers is significantly refactored so that most of the logic is in `common` and can be used in different ways.

Test Plan: The original diff adds plenty of tests.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Subscribers: dsagal

Differential Revision: https://phab.getgrist.com/D3240
This commit is contained in:
Alex Hall
2022-02-04 13:13:03 +02:00
parent 4890a1fe89
commit 5d671bf0b3
25 changed files with 593 additions and 492 deletions

View File

@@ -41,6 +41,7 @@ import {schema, SCHEMA_VERSION} from 'app/common/schema';
import {MetaRowRecord} from 'app/common/TableData';
import {FetchUrlOptions, UploadResult} from 'app/common/uploads';
import {DocReplacementOptions, DocState, DocStateComparison} from 'app/common/UserAPI';
import {convertFromColumn} from 'app/common/ValueConverter';
import {parseUserAction} from 'app/common/ValueParser';
import {ParseOptions} from 'app/plugin/FileParserAPI';
import {GristDocAPI} from 'app/plugin/GristAPI';
@@ -1717,6 +1718,12 @@ export class ActiveDoc extends EventEmitter {
logTimes: true,
logMeta: {docId: this._docName},
preferredPythonVersion,
sandboxOptions: {
exports: {
convertFromColumn: (...args: Parameters<ReturnType<typeof convertFromColumn>>) =>
convertFromColumn(this.docData!)(...args)
}
},
});
}
}

View File

@@ -87,6 +87,7 @@ const SPECIAL_ACTIONS = new Set(['InitNewDoc',
'TransformAndFinishImport',
'AddView',
'CopyFromColumn',
'ConvertFromColumn',
'AddHiddenColumn',
]);

View File

@@ -1,4 +1,5 @@
import * as log from 'app/server/lib/log';
import {ISandboxOptions} from 'app/server/lib/NSandbox';
/**
* Starting to whittle down the options used when creating a sandbox, to leave more
@@ -17,6 +18,8 @@ export interface ISandboxCreationOptions {
importMount?: string; // if defined, make this path available read-only as "/importdir"
preferredPythonVersion?: '2' | '3';
sandboxOptions?: Partial<ISandboxOptions>;
}
export interface ISandbox {

View File

@@ -33,7 +33,7 @@ type SandboxMethod = (...args: any[]) => any;
* started by setting `useGristEntrypoint` (the only exception is
* in tests) which runs grist/main.py.
*/
interface ISandboxOptions {
export interface ISandboxOptions {
command?: string; // External program or container to call to run the sandbox.
args: string[]; // The arguments to pass to the python process.
@@ -404,6 +404,7 @@ export class NSandboxCreator implements ISandboxCreator {
preferredPythonVersion: this._preferredPythonVersion || options.preferredPythonVersion,
useGristEntrypoint: true,
importDir: options.importMount,
...options.sandboxOptions,
};
return new NSandbox(translatedOptions, spawners[this._flavor]);
}