1 import { SchemaPropertyMetadata, SchemaPropertyType } from "@medusajs/types"
2
3 /**
4 * Shared parse/type plumbing for schema properties used by DML, the search
5 * DSL, and any future domain language that describes typed fields. Fluent
6 * modifiers (`default()`, `nullable()`, ...) belong to the domains that give
7 * them meaning — a search field has no default value, so the base must not
8 * offer one.
9 */
10 export abstract class BaseSchemaProperty<T> implements SchemaPropertyType<T> {
11 /**
12 * The runtime dataType for the schema. It is not the same as
13 * the "$dataType".
14 */
15 protected abstract dataType: SchemaPropertyMetadata<T>["dataType"]
16
17 /**
18 * A type-only property to infer the JavaScript data-type
19 * of the schema property
20 */
21 declare $dataType: T
22
23 /**
24 * Returns the serialized metadata
25 */
26 parse(fieldName: string): SchemaPropertyMetadata<T> {
27 return {
28 fieldName,
29 dataType: this.dataType,
30 nullable: false,
31 computed: false,
32 }
33 }
34 }