UNPKG

@squidcloud/client

Version:

A typescript implementation of the Squid client

55 lines (54 loc) 2.56 kB
import { JSONSchema } from 'json-schema-typed'; type ConvertDeep<T extends JSONSchema> = Exclude<T, boolean> & { properties?: Record<string, ConvertDeep<JSONSchema>>; patternProperties?: Record<string, ConvertDeep<JSONSchema>>; nullable?: boolean; /** * The default value will be applied (default to 'empty'): * 'always' - no matter what the client sent, both on update and insert. In case of readOnly - applies only on insert. * 'empty' - only if the value of the field is empty (undefined) * 'updateOrEmpty' - no matter what the client sent, updating the record will use the default value */ applyDefaultValueOn?: 'always' | 'empty' | 'updateOrEmpty'; isDate?: boolean; isJSON?: boolean; /** * Applies to the top level schema, a record in a nested object, or a regular property. * Basically, whether this property can participate in an insert mutation. */ insertable?: boolean; /** Applies to the top level schema or a record in a nested object. */ deletable?: boolean; }; /** Extended JSON schema for a single property, supporting nested structures and Squid-specific metadata. */ export type PropertySchema = ConvertDeep<JSONSchema>; /** Extended JSON schema for a top-level property, including database-related metadata. */ export type TopLevelPropertySchema = PropertySchema & { /** Marks the property as a primary key. */ primaryKey?: boolean; /** * Whether the property is computed based on other properties or some formula. * If true, readonly also needs to be true and this field should not be part of an insert statement. */ isComputed?: boolean; /** * Whether the default value generated by the database. CURRENT_DATE is something generated by the database vs * 'Hello' which is a constant. */ isDefaultComputed?: boolean; /** * The database data type that is represented by this property. This is often different from the actual property * type, with is a Javascript primitive. For example, for a SMALLINT the dataType would be 'smallint', but the type * would be 'integer'. */ dataType?: string; /** * This indicates that although the field exists on the db, it should be ignored by squid. */ hidden?: boolean; }; /** Schema for a full collection, allowing partial property definitions with extended metadata. */ export type CollectionSchema = Omit<ConvertDeep<JSONSchema>, 'properties'> & { properties?: Record<string, TopLevelPropertySchema>; }; export {};