mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-09 13:15:51 +08:00
refactor(editor): add runtime type checks to database cell values (#10770)
This commit is contained in:
@@ -2,21 +2,31 @@ import zod from 'zod';
|
||||
|
||||
import { t } from '../../core/logical/type-presets.js';
|
||||
import { propertyType } from '../../core/property/property-config.js';
|
||||
|
||||
export const imagePropertyType = propertyType('image');
|
||||
|
||||
export const imagePropertyModelConfig = imagePropertyType.modelConfig({
|
||||
name: 'image',
|
||||
valueSchema: zod.string().optional(),
|
||||
hide: true,
|
||||
type: () => t.image.instance(),
|
||||
defaultData: () => ({}),
|
||||
cellToString: ({ value }) => value ?? '',
|
||||
cellFromString: ({ value }) => {
|
||||
return {
|
||||
value: value,
|
||||
};
|
||||
propertyData: {
|
||||
schema: zod.object({}),
|
||||
default: () => ({}),
|
||||
},
|
||||
cellToJson: ({ value }) => value ?? null,
|
||||
cellFromJson: ({ value }) => (typeof value !== 'string' ? undefined : value),
|
||||
isEmpty: ({ value }) => value == null,
|
||||
jsonValue: {
|
||||
schema: zod.string().nullable(),
|
||||
isEmpty: ({ value }) => value == null,
|
||||
type: () => t.image.instance(),
|
||||
},
|
||||
rawValue: {
|
||||
schema: zod.string().nullable(),
|
||||
default: () => null,
|
||||
toString: ({ value }) => value ?? '',
|
||||
fromString: ({ value }) => {
|
||||
return {
|
||||
value: value,
|
||||
};
|
||||
},
|
||||
toJson: ({ value }) => value,
|
||||
fromJson: ({ value }) => value,
|
||||
},
|
||||
hide: true,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user