Skip to content

Commit

Permalink
minor: typing updates
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidg3 committed May 18, 2020
1 parent ede84f2 commit 5e01caf
Show file tree
Hide file tree
Showing 4 changed files with 2,344 additions and 2,292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AddressField } from '@sprucelabs/schema'
import { BooleanField } from '@sprucelabs/schema'
import { DateField } from '@sprucelabs/schema'
import { DateTimeField } from '@sprucelabs/schema'
import { DirectoryField } from '@sprucelabs/schema'
import { DurationField } from '@sprucelabs/schema'
import { FileField } from '@sprucelabs/schema'
import { IdField } from '@sprucelabs/schema'
Expand All @@ -26,6 +27,7 @@ export const FieldClassMap: Record<FieldType, FieldClass> = {
[FieldType.Boolean]: BooleanField,
[FieldType.Date]: DateField,
[FieldType.DateTime]: DateTimeField,
[FieldType.Directory]: DirectoryField,
[FieldType.Duration]: DurationField,
[FieldType.File]: FileField,
[FieldType.Id]: IdField,
Expand All @@ -47,6 +49,7 @@ export interface IFieldClassMap {
[FieldType.Boolean]: BooleanField,
[FieldType.Date]: DateField,
[FieldType.DateTime]: DateTimeField,
[FieldType.Directory]: DirectoryField,
[FieldType.Duration]: DurationField,
[FieldType.File]: FileField,
[FieldType.Id]: IdField,
Expand Down
2 changes: 2 additions & 0 deletions packages/heartwood-skill/.spruce/schemas/fields/fieldType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export enum FieldType {
Date = 'date',
/** Date and time support. */
DateTime = 'dateTime',
/** A way to select entire directories once! */
Directory = 'directory',
/** A span of time represented in { hours, minutes, seconds, ms } */
Duration = 'duration',
/** A way to handle files. Supports mime-type lookups. */
Expand Down
53 changes: 50 additions & 3 deletions packages/heartwood-skill/.spruce/schemas/fields/fields.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IAddressFieldDefinition, AddressField } from '@sprucelabs/schema'
import { IBooleanFieldDefinition, BooleanField } from '@sprucelabs/schema'
import { IDateFieldDefinition, DateField } from '@sprucelabs/schema'
import { IDateTimeFieldDefinition, DateTimeField } from '@sprucelabs/schema'
import { IDirectoryFieldDefinition, DirectoryField } from '@sprucelabs/schema'
import { IDurationFieldDefinition, DurationField } from '@sprucelabs/schema'
import { IFileFieldDefinition, FileField } from '@sprucelabs/schema'
import { IIdFieldDefinition, IdField } from '@sprucelabs/schema'
Expand All @@ -20,13 +21,13 @@ import NodeField, { INodeFieldDefinition } from '#spruce/../src/fields/NodeField


/** Field definition union */
export type FieldDefinition = | IAddressFieldDefinition| IBooleanFieldDefinition| IDateFieldDefinition| IDateTimeFieldDefinition| IDurationFieldDefinition| IFileFieldDefinition| IIdFieldDefinition| INumberFieldDefinition| IPhoneFieldDefinition| IRawFieldDefinition| ISchemaFieldDefinition| ISelectFieldDefinition| ITextFieldDefinition| ICallbackFieldDefinition| IElementTypeFieldDefinition| IEventCallbackFieldDefinition| INodeFieldDefinition
export type FieldDefinition = | IAddressFieldDefinition| IBooleanFieldDefinition| IDateFieldDefinition| IDateTimeFieldDefinition| IDirectoryFieldDefinition| IDurationFieldDefinition| IFileFieldDefinition| IIdFieldDefinition| INumberFieldDefinition| IPhoneFieldDefinition| IRawFieldDefinition| ISchemaFieldDefinition| ISelectFieldDefinition| ITextFieldDefinition| ICallbackFieldDefinition| IElementTypeFieldDefinition| IEventCallbackFieldDefinition| INodeFieldDefinition

/** Field class union */
export type FieldClass = | typeof AddressField| typeof BooleanField| typeof DateField| typeof DateTimeField| typeof DurationField| typeof FileField| typeof IdField| typeof NumberField| typeof PhoneField| typeof RawField| typeof SchemaField| typeof SelectField| typeof TextField| typeof CallbackField| typeof ElementTypeField| typeof EventCallbackField| typeof NodeField
export type FieldClass = | typeof AddressField| typeof BooleanField| typeof DateField| typeof DateTimeField| typeof DirectoryField| typeof DurationField| typeof FileField| typeof IdField| typeof NumberField| typeof PhoneField| typeof RawField| typeof SchemaField| typeof SelectField| typeof TextField| typeof CallbackField| typeof ElementTypeField| typeof EventCallbackField| typeof NodeField

/** Field instance union **/
export type Field = | AddressField| BooleanField| DateField| DateTimeField| DurationField| FileField| IdField| NumberField| PhoneField| RawField| SchemaField| SelectField| TextField| CallbackField| ElementTypeField| EventCallbackField| NodeField
export type Field = | AddressField| BooleanField| DateField| DateTimeField| DirectoryField| DurationField| FileField| IdField| NumberField| PhoneField| RawField| SchemaField| SelectField| TextField| CallbackField| ElementTypeField| EventCallbackField| NodeField


/** Type for looking up field definitions by field type */
Expand All @@ -35,6 +36,7 @@ export type FieldDefinitionMap = {
[FieldType.Boolean]: IBooleanFieldDefinition
[FieldType.Date]: IDateFieldDefinition
[FieldType.DateTime]: IDateTimeFieldDefinition
[FieldType.Directory]: IDirectoryFieldDefinition
[FieldType.Duration]: IDurationFieldDefinition
[FieldType.File]: IFileFieldDefinition
[FieldType.Id]: IIdFieldDefinition
Expand All @@ -50,3 +52,48 @@ export type FieldDefinitionMap = {
[FieldType.Node]: INodeFieldDefinition
}


/** Type for looking up field definitions by field type */
export interface IFieldDefinitionMap {
[FieldType.Address]: IAddressFieldDefinition
[FieldType.Boolean]: IBooleanFieldDefinition
[FieldType.Date]: IDateFieldDefinition
[FieldType.DateTime]: IDateTimeFieldDefinition
[FieldType.Directory]: IDirectoryFieldDefinition
[FieldType.Duration]: IDurationFieldDefinition
[FieldType.File]: IFileFieldDefinition
[FieldType.Id]: IIdFieldDefinition
[FieldType.Number]: INumberFieldDefinition
[FieldType.Phone]: IPhoneFieldDefinition
[FieldType.Raw]: IRawFieldDefinition
[FieldType.Schema]: ISchemaFieldDefinition
[FieldType.Select]: ISelectFieldDefinition
[FieldType.Text]: ITextFieldDefinition
[FieldType.Callback]: ICallbackFieldDefinition
[FieldType.ElementType]: IElementTypeFieldDefinition
[FieldType.EventCallback]: IEventCallbackFieldDefinition
[FieldType.Node]: INodeFieldDefinition
}

/** All field instances */
export interface IFieldMap {
[FieldType.Address]: AddressField
[FieldType.Boolean]: BooleanField
[FieldType.Date]: DateField
[FieldType.DateTime]: DateTimeField
[FieldType.Directory]: DirectoryField
[FieldType.Duration]: DurationField
[FieldType.File]: FileField
[FieldType.Id]: IdField
[FieldType.Number]: NumberField
[FieldType.Phone]: PhoneField
[FieldType.Raw]: RawField
[FieldType.Schema]: SchemaField
[FieldType.Select]: SelectField
[FieldType.Text]: TextField
[FieldType.Callback]: CallbackField
[FieldType.ElementType]: ElementTypeField
[FieldType.EventCallback]: EventCallbackField
[FieldType.Node]: NodeField
}

Loading

0 comments on commit 5e01caf

Please sign in to comment.