Skip to content

Commit

Permalink
Expose types from package (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
leo authored Nov 7, 2024
1 parent 9082dc5 commit 0d2ed92
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"performance": {
"all": true,

"noBarrelFile": "off"
"noBarrelFile": "off",
"noReExportAll": "off"
},
"security": { "all": true },
"style": {
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,7 @@ export const compileQueryInput = (
values: statementValues,
};
};

// Expose types
export * from '@/src/types/schema';
export * from '@/src/types/query';
49 changes: 47 additions & 2 deletions src/types/schema.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<SchemaIndexField>;
/**
* 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<Exclude<QueryType, 'get' | 'count'>>;
/** 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<Query>;
/** A list of field slugs for which the trigger should fire. */
fields?: Array<string>;
/**
* 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<SchemaField>;
idPrefix?: string;

including?: Record<string, Query>;
for?: Record<string, WithInstruction>;

fields?: Array<SchemaField>;
indexes?: Array<SchemaIndex>;
triggers?: Array<SchemaTrigger>;
}
6 changes: 6 additions & 0 deletions src/utils/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,16 @@ const SYSTEM_SCHEMAS: Array<Schema> = [
{ 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' },
],
},
{
Expand Down

0 comments on commit 0d2ed92

Please sign in to comment.