UNPKG

@appsemble/lang-sdk

Version:

Language SDK for Appsemble

146 lines (145 loc) 4.04 kB
import { type OpenAPIV3 } from 'openapi-types'; import { type HTTPMethods } from './http.js'; import { type Remapper } from './remapper.js'; export type ResourceViewAction = 'get' | 'query'; export type OwnResourceAction = ResourceViewAction | 'delete' | 'patch' | 'update'; export type ResourceAction = ResourceViewAction | 'create' | 'delete' | 'history.get' | 'patch' | 'update.positions' | 'update'; export interface ResourceDefinition { /** * A definition of how versioning should happen for instances of this resource. */ history?: ResourceHistoryDefinition | boolean; /** * Whether to enable position column for the instances of this resource. This is used for keeping * an ordered list to enable custom sorting of the data using drag and drop features. */ positioning?: boolean; /** * Enforce Custom Ordering By the fields. */ enforceOrderingGroupByFields?: string[]; /** * The definition for the `resource.create` action. */ create?: ResourceCall; /** * The definition for the `resource.delete` action. */ delete?: ResourceCall; /** * The definition for the `resource.get` action. */ get?: ResourceCall; /** * The definition for the `resource.query` action. */ query?: ResourceCall; /** * The definition for the `resource.count` action. */ count?: ResourceCall; /** * The definition for the `resource.update` action. */ update?: ResourceCall; /** * The definition for the `resource.patch` action. */ patch?: ResourceCall; /** * The property to use as the id. * * @default `id` */ id?: string; /** * The JSON schema to validate resources against before sending it to the backend. */ schema: OpenAPIV3.SchemaObject; /** * The URL to post the resource to. * * @default autogenerated for use with the Appsemble resource API. */ url?: string; /** * The alternate views of this resource. */ views?: Record<string, ResourceView>; /** * The references this resources has to other resources. */ references?: Record<string, ResourceReference>; /** * A time string representing when a resource should expire. * * @example '1d 8h 30m' */ expires?: string; /** * Whether the resource should be able to be transferred when cloning the app it belongs to. */ clonable?: boolean; } export interface ResourceReferenceActionTrigger { type: 'create' | 'delete' | 'update'; cascade?: 'delete' | 'update'; } interface ResourceReferenceAction { triggers: ResourceReferenceActionTrigger[]; } export interface ResourceReference { /** * The name of the referenced resource. */ resource: string; create?: ResourceReferenceAction; update?: ResourceReferenceAction; delete?: ResourceReferenceAction; } export interface ResourceHistoryDefinition { /** * If set to `false`, edits are still tracked, but exactly what changed is lost. */ data: boolean; } export interface ResourceView { /** * The remappers used to transform the output. */ remap: Remapper; } export interface NotificationDefinition { to?: string[]; subscribe?: 'all' | 'both' | 'single'; data?: { title: string; content: string; link: string; }; } /** * A collection of hooks that are triggered upon calling a resource actions. */ export interface ResourceHooks { notification: NotificationDefinition; } export interface ResourceCall { /** * The HTTP method to use for making the HTTP request. */ method?: HTTPMethods; /** * The URL to which to make the resource request. */ url?: string; /** * The associated hooks with the resource action. */ hooks?: ResourceHooks; /** * Query parameters to pass along with the request. */ query?: Remapper; } export {};