gristlabs_grist-core/sandbox/gen_js_schema.py
Paul Fitzpatrick b3b7410ede (core) open documents without blocking on data engine
Summary:
With this diff, when a user opens a Grist document in a browser, they will be able to view its contents without waiting for the data engine to start up. Once the data engine starts, it will run a calculation and send any updates made. Changes to the document will be blocked until the engine is started and the initial calculation is complete.

The increase in responsiveness is useful in its own right, and also reduces the impact of an extra startup time in a candidate next-generation sandbox.

A small unrelated fix is included for `core/package.json`, to catch up with a recent change to `package.json`.

A small `./build schema` convenience is added to just rebuild the typescript schema file.

Test Plan: added test; existing tests pass - small fixes needed in some cases because of new timing

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D3036
2021-10-01 10:18:56 -04:00

53 lines
1.4 KiB
Python

#!/usr/bin/env python -B
"""
Generates a JS schema file from sandbox/grist/schema.py.
"""
import schema # pylint: disable=import-error
# These are the types that appear in Grist metadata columns.
_ts_types = {
"Bool": "boolean",
"DateTime": "number",
"Int": "number",
"PositionNumber": "number",
"Ref": "number",
"RefList": "['L', ...number[]]|null", # Non-primitive values are encoded
"ChoiceList": "['L', ...string[]]|null",
"Text": "string",
}
def get_ts_type(col_type):
col_type = col_type.split(':', 1)[0] # Strip suffix for Ref:, DateTime:, etc.
return _ts_types.get(col_type, "CellValue")
def main():
print("""\
/*** THIS FILE IS AUTO-GENERATED BY %s ***/
// tslint:disable:object-literal-key-quotes
export const SCHEMA_VERSION = %d;
export const schema = {
""" % (__file__, schema.SCHEMA_VERSION))
for table in schema.schema_create_actions():
print(' "%s": {' % table.table_id)
for column in table.columns:
print(' %-20s: "%s",' % (column['id'], column['type']))
print(' },\n')
print("""};
export interface SchemaTypes {
""")
for table in schema.schema_create_actions():
print(' "%s": {' % table.table_id)
for column in table.columns:
print(' %s: %s;' % (column['id'], get_ts_type(column['type'])))
print(' };\n')
print("}")
if __name__ == '__main__':
main()