ducks.datasource.DataSource.ts Maven / Gradle / Ivy
The newest version!
/* eslint-disable @typescript-eslint/no-extraneous-class */
import type { DataSourceDependency, SortDirection } from '../../core/datasource/const'
import { ModelPrefix } from '../../core/datasource/const'
import { ValidationsKey, Validation, ValidationResult } from '../../core/validation/types'
import type { Provider, SubmitProvider, Paging, ServiceSubmit } from './Provider'
export type State = Record
export interface DataSourceState {
provider?: Provider
[ValidationsKey.Validations]: Record
[ValidationsKey.FilterValidations]: Record
components: string[]
dependencies: DataSourceDependency[]
paging: Paging
additionalInfo: unknown
loading: boolean
sorting: Partial>
submit?: SubmitProvider
fieldsSubmit: Record
pageId?: string
// TODO: rename to "messages"
errors: Record<
ModelPrefix,
Partial>
>
error?: object
}
export class DataSource {
static get defaultState(): DataSourceState {
return ({
[ValidationsKey.Validations]: {},
[ValidationsKey.FilterValidations]: {},
components: [],
dependencies: [],
paging: {
page: 1,
size: 1,
count: 0,
},
additionalInfo: undefined,
loading: false,
sorting: {},
errors: {
[ModelPrefix.active]: {},
[ModelPrefix.edit]: {},
[ModelPrefix.filter]: {},
[ModelPrefix.selected]: {},
[ModelPrefix.source]: {},
},
fieldsSubmit: {},
})
}
}