@squidcloud/client
Version:
A typescript implementation of the Squid client
89 lines (88 loc) • 4.3 kB
TypeScript
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;
};
/**
* Milestoning kind on a Legend/PURE class. Drives `.all()` arity and the date
* arguments required when navigating to the class's properties:
* - `business-temporal` → `.all(businessDate)`, `$x.prop(businessDate)`
* - `processing-temporal` → `.all(processingDate)`, `$x.prop(processingDate)`
* - `bitemporal` → `.all(processingDate, businessDate)`, `$x.prop(processingDate, businessDate)`
* Legend integrations populate this when discovering the schema so downstream consumers
* (AI query generation, validation) know whether dates are required.
*/
export type MilestoningKind = 'business-temporal' | 'processing-temporal' | 'bitemporal';
/** Schema for a full collection, allowing partial property definitions with extended metadata. */
export type CollectionSchema = Omit<ConvertDeep<JSONSchema>, 'properties'> & {
properties?: Record<string, TopLevelPropertySchema>;
/** Legend/PURE only: milestoning stereotype on the class, if any. */
milestoning?: MilestoningKind;
};
/**
* API-boundary view of {@link CollectionSchema} for use in OpenAPI-exposed
* controllers. Decouples the public REST surface from `json-schema-typed`'s
* recursive generic, which tsoa's type resolver cannot walk.
*
* The on-the-wire payload is the same as {@link CollectionSchema} — this type
* just describes it as an opaque JSON object for the generated OpenAPI spec
* (which is also what tsoa 5.x emitted for {@link CollectionSchema}: a bare
* `object` with no properties).
*/
export interface CollectionSchemaApi {
/** JSON Schema `type` keyword (e.g. "object"). */
type?: string;
/** Map of property names to their schemas. */
properties?: Record<string, unknown>;
/** Names of required properties. */
required?: string[];
/** Human-readable description of the collection. */
description?: string;
/** Additional JSON Schema / Squid-specific fields are preserved as-is. */
[key: string]: unknown;
}
export {};