diff --git a/biome.json b/biome.json index b59338e..b174464 100644 --- a/biome.json +++ b/biome.json @@ -45,7 +45,8 @@ "performance": { "all": true, - "noBarrelFile": "off" + "noBarrelFile": "off", + "noReExportAll": "off" }, "security": { "all": true }, "style": { diff --git a/src/index.ts b/src/index.ts index 4534cca..b8a156a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -266,3 +266,7 @@ export const compileQueryInput = ( values: statementValues, }; }; + +// Expose types +export * from '@/src/types/schema'; +export * from '@/src/types/query'; diff --git a/src/types/schema.ts b/src/types/schema.ts index b56425a..0c2a21c 100644 --- a/src/types/schema.ts +++ b/src/types/schema.ts @@ -1,4 +1,4 @@ -import type { Query, WithInstruction } from '@/src/types/query'; +import type { Query, QueryType, WithInstruction } from '@/src/types/query'; type SchemaFieldBasics = { name?: string; @@ -35,18 +35,63 @@ export type SchemaFieldReference = SchemaFieldBasics & { export type SchemaField = SchemaFieldNormal | SchemaFieldReference; +type SchemaIndexField = { + /** The field slug or expression for which the index should be created. */ + expression: string; + /** The collating sequence used for text placed inside the field. */ + collation?: 'BINARY' | 'NOCASE' | 'RTRIM'; + /** How the records in the index should be ordered. */ + order?: 'ASC' | 'DESC'; +}; + +type SchemaIndex = { + /** + * The list of fields in the schema for which the index should be created. + */ + fields: Array; + /** + * Whether only one record with a unique value for the provided fields will be allowed. + */ + unique?: boolean; + /** + * An object containing query instructions that will be used to match the records that + * should be included in the index. + */ + filter?: WithInstruction; +}; + +type SchemaTrigger = { + /** The type of query for which the trigger should fire. */ + queryType: Uppercase>; + /** When the trigger should fire in the case that a maching query is executed. */ + timing: 'BEFORE' | 'DURING' | 'AFTER'; + /** A list of queries that should be executed when the trigger fires. */ + effects: Array; + /** A list of field slugs for which the trigger should fire. */ + fields?: Array; + /** + * An object containing query instructions used to determine whether the trigger should + * fire, or not. + */ + filter?: WithInstruction; +}; + export interface Schema { name?: string; pluralName?: string; slug: string; pluralSlug?: string; + identifiers?: { title?: string; slug?: string; }; - fields?: Array; idPrefix?: string; including?: Record; for?: Record; + + fields?: Array; + indexes?: Array; + triggers?: Array; } diff --git a/src/utils/schema.ts b/src/utils/schema.ts index 06f2bbc..ee70fae 100644 --- a/src/utils/schema.ts +++ b/src/utils/schema.ts @@ -206,10 +206,16 @@ const SYSTEM_SCHEMAS: Array = [ { slug: 'pluralName', type: 'string' }, { slug: 'slug', type: 'string' }, { slug: 'pluralSlug', type: 'string' }, + { slug: 'idPrefix', type: 'string' }, + { slug: 'identifiers', type: 'group' }, { slug: 'identifiers.title', type: 'string' }, { slug: 'identifiers.slug', type: 'string' }, + + { slug: 'fields', type: 'json' }, + { slug: 'indexes', type: 'json' }, + { slug: 'triggers', type: 'json' }, ], }, {