Skip to content

Commit

Permalink
refactor: export enum (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaddollxz authored Aug 13, 2024
1 parent e295660 commit a5a2a29
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://deno.land/x/deno/cli/schemas/config-file.v1.json",
"name": "@byzanteam/taihaku-schemas",
"version": "0.4.3",
"version": "0.5.0",
"exports": "./types/mod.ts",
"compilerOptions": {
"strict": true,
Expand Down
27 changes: 22 additions & 5 deletions types/persistence_schema/filter.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
import type { DataPointer, SchemaPointer, ValuePointer } from './types.ts'
export type Filter = ConditionalFilter | LogicalFilter

export enum ConditionalFilterOperator {
AND = 'and',
OR = 'or',
}

export enum LogicalFilterOperator {
CO = 'co',
EQ = 'eq',
LT = 'lt',
IS_NULL = 'is_null',
}

export interface ConditionalFilter {
operator: 'and' | 'or'
operator: ConditionalFilterOperator
operands: Array<ConditionalFilter | LogicalFilter>
}

export type LogicalFilter = EQFilter | LTFilter | IsNullFilter
export type LogicalFilter = COFilter | EQFilter | LTFilter | IsNullFilter

export interface COFilter {
operator: LogicalFilterOperator.CO
operands: [Operand, Operand]
}

export interface EQFilter {
operator: 'eq'
operator: LogicalFilterOperator.EQ
operands: [Operand, Operand]
}

export interface LTFilter {
operator: 'lt'
operator: LogicalFilterOperator.LT
operands: [Operand, Operand]
}

export interface IsNullFilter {
operator: 'is_null'
operator: LogicalFilterOperator.IS_NULL
operands: [Operand]
}

Expand Down
6 changes: 3 additions & 3 deletions types/persistence_schema/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Fetching } from './fetching.ts'
import type { Filter } from './filter.ts'
import type { OffsetPagination } from './pagination.ts'
import type { ObjectReturning } from './returning.ts'
import type { Order } from './sorting.ts'
import type { Order, Sorters } from './sorting.ts'
import type { ColumnType } from './types.ts'

export interface ColumnDef {
Expand Down Expand Up @@ -93,7 +93,7 @@ export interface ListAction {
schema: Schema
paramsSchema: JSONSchema
filter: Filter
sorting?: Array<Order>
sorting?: Sorters
pagination: OffsetPagination
fetchingSchema: Array<Fetching>
returningSchema: Array<ObjectReturning>
Expand Down Expand Up @@ -123,6 +123,6 @@ export interface NextjsResult {

export type { InternalError, JSONSchemaError, ValidationError }
export type { FormatedJSONSchemaError, FormatedValidationError }
export type { Filter, Order }
export type { Filter, Order, Sorters }
export type { ConditionalFilter, LogicalFilter } from './filter.ts'
export * from './types.ts'
9 changes: 8 additions & 1 deletion types/persistence_schema/sorting.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export enum OrderDirection {
ASC = 'asc',
DESC = 'desc',
}

export interface Order {
field: string
direction: 'asc' | 'desc'
direction: OrderDirection
}

export type Sorters = Array<Order>
6 changes: 3 additions & 3 deletions types/ui_schema/form/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type { FieldType } from '../field.ts'
import type { ObjectData } from '../types.ts'
import type { ObjectLayout } from './layout.ts'
import type {
AppearanceValue,
CommonCustomFieldUIOptions,
CustomFieldUIOptionsMap,
FormAppearance,
} from './ui_options.ts'

/**
Expand Down Expand Up @@ -54,7 +54,7 @@ type BasicUIOptions = {
}

type GlobalUIOptions = {
'ui:x-appearance'?: AppearanceValue
'ui:x-appearance'?: FormAppearance
disabled?: boolean
readonly?: boolean
}
Expand Down Expand Up @@ -128,7 +128,7 @@ export type {
ObjectFieldUIOptions,
}

export { AppearanceValue, type OptionColumns } from './ui_options.ts'
export { type OptionColumns } from './ui_options.ts'

export type FormSchema<
TData extends ObjectData = ObjectData,
Expand Down
7 changes: 2 additions & 5 deletions types/ui_schema/form/ui_options.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import type { FieldType } from '../field.ts'
import type { FieldTemplate } from './layout.ts'

export enum AppearanceValue {
Input = 'input',
Presentation = 'presentation',
}
export type FormAppearance = 'input' | 'presentation'

export interface CommonCustomFieldUIOptions {
'ui:x-appearance'?: AppearanceValue
'ui:x-appearance'?: FormAppearance
'ui:x-blankslate'?: string
'ui:x-field-template'?: FieldTemplate | Array<FieldTemplate>
}
Expand Down
4 changes: 2 additions & 2 deletions types/ui_schema/table/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FieldType, GenericField } from '../field.ts'
import type { ObjectData } from '../types.ts'
import type { CustomColumnUIOptionsMap } from './ui_options.ts'
import type { CustomColumnUIOptionsMap, TableAppearance } from './ui_options.ts'

type BasicUIOptions = {
/**
Expand Down Expand Up @@ -76,7 +76,7 @@ interface TableOptions<TData extends ObjectData = ObjectData> {
/**
* global appearance setting of table cells
*/
'ui:x-appearance': 'input' | 'presentation'
'ui:x-appearance': TableAppearance
}

export type TableUISchema<
Expand Down
4 changes: 3 additions & 1 deletion types/ui_schema/table/ui_options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { FieldType } from '../field.ts'

export type TableAppearance = 'input' | 'presentation'

interface CommonCustomFieldUIOptions {
'ui:x-appearance'?: 'input' | 'presentation'
'ui:x-appearance'?: TableAppearance
'ui:x-blankslate'?: string
}

Expand Down

0 comments on commit a5a2a29

Please sign in to comment.