(core) Use GristObjCode in CellValue

Summary: Makes type checking a bit stronger

Test Plan: it just has to compile

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D3065
This commit is contained in:
Alex Hall
2021-10-07 23:02:51 +02:00
parent 62db263d1f
commit a64fb105e3
9 changed files with 58 additions and 49 deletions

View File

@@ -1,6 +1,7 @@
import { CellValue, CellVersions } from 'app/common/DocActions';
import { GristObjCode } from 'app/plugin/GristData';
import isString = require('lodash/isString');
import {removePrefix} from "./gutil";
import { removePrefix } from "./gutil";
// tslint:disable:object-literal-key-quotes
@@ -14,23 +15,6 @@ export type GristTypeInfo =
{type: 'RefList', tableId: string} |
{type: Exclude<GristType, 'DateTime'|'Ref'|'RefList'>};
// Letter codes for CellValue types encoded as [code, args...] tuples.
export const enum GristObjCode {
List = 'L',
Dict = 'O',
DateTime = 'D',
Date = 'd',
Skip = 'S',
Censored = 'C',
Reference = 'R',
ReferenceList = 'r',
Exception = 'E',
Pending = 'P',
Unmarshallable = 'U',
Versions = 'V',
}
export const MANUALSORT = 'manualSort';
// Whether a column is internal and should be hidden.
@@ -93,9 +77,9 @@ export function extractInfoFromColType(colType: string): GristTypeInfo {
export function reencodeAsAny(value: CellValue, typeInfo: GristTypeInfo): CellValue {
if (typeof value === 'number') {
switch (typeInfo.type) {
case 'Date': return ['d', value];
case 'DateTime': return ['D', value, typeInfo.timezone];
case 'Ref': return ['R', typeInfo.tableId, value];
case 'Date': return [GristObjCode.Date, value];
case 'DateTime': return [GristObjCode.DateTime, value, typeInfo.timezone];
case 'Ref': return [GristObjCode.Reference, typeInfo.tableId, value];
}
}
return value;
@@ -105,7 +89,7 @@ export function reencodeAsAny(value: CellValue, typeInfo: GristTypeInfo): CellVa
/**
* Returns whether a value (as received in a DocAction) represents a custom object.
*/
export function isObject(value: CellValue): value is [string, any?] {
export function isObject(value: CellValue): value is [GristObjCode, any?] {
return Array.isArray(value);
}

View File

@@ -1,4 +1,7 @@
/*** THIS FILE IS AUTO-GENERATED BY core/sandbox/gen_js_schema.py ***/
import { GristObjCode } from "app/plugin/GristData";
// tslint:disable:object-literal-key-quotes
export const SCHEMA_VERSION = 24;
@@ -216,7 +219,7 @@ export interface SchemaTypes {
displayCol: number;
visibleCol: number;
recalcWhen: number;
recalcDeps: ['L', ...number[]]|null;
recalcDeps: [GristObjCode.List, ...number[]]|null;
};
"_grist_Imports": {
@@ -328,7 +331,7 @@ export interface SchemaTypes {
"_grist_Triggers": {
tableRef: number;
eventTypes: ['L', ...string[]]|null;
eventTypes: [GristObjCode.List, ...string[]]|null;
isReadyColRef: number;
actions: string;
};