lib/core/src/items/entries/entry.class.ts
Properties |
|
Methods |
|
Accessors |
Public answer |
Type : string | number | boolean
|
Defined in lib/core/src/items/entries/entry.class.ts:36
|
Public date |
Type : string
|
Defined in lib/core/src/items/entries/entry.class.ts:37
|
Public note |
Type : string
|
Defined in lib/core/src/items/entries/entry.class.ts:38
|
Public questionId |
Type : string
|
Defined in lib/core/src/items/entries/entry.class.ts:35
|
Public targetDay |
Type : string
|
Defined in lib/core/src/items/entries/entry.class.ts:39
|
Private Optional _config |
Type : C
|
Inherited from
Item
|
Defined in
Item:54
|
Public Optional id |
Type : string
|
Inherited from
Item
|
Defined in
Item:50
|
Public Optional update$ |
Type : Observable<string>
|
Inherited from
Item
|
Defined in
Item:52
|
Protected Optional updateSubject |
Type : Subject<string>
|
Inherited from
Item
|
Defined in
Item:51
|
Static acceptsAsConfig | ||||
acceptsAsConfig(config)
|
||||
Inherited from
Item
|
||||
Defined in
Item:41
|
||||
Parameters :
Returns :
EntryConfig
|
Static assertData | ||||
assertData(data)
|
||||
Inherited from
Item
|
||||
Defined in
Item:40
|
||||
Parameters :
Returns :
never
|
Static findConfigs | ||||
findConfigs(data)
|
||||
Inherited from
Item
|
||||
Defined in
Item:32
|
||||
Type parameters :
|
||||
Parameters :
Returns :
U[]
|
Public matches | ||||
matches(query)
|
||||
Inherited from
Item
|
||||
Defined in
Item:80
|
||||
TODO: Is this useful or needed anywhere?
Parameters :
Returns :
boolean
|
Public toJSON |
toJSON()
|
Inherited from
Item
|
Defined in
Item:75
|
Returns :
string
|
config | ||||||
getconfig()
|
||||||
Defined in lib/core/src/items/entries/entry.class.ts:56
|
||||||
setconfig(config: EntryConfig)
|
||||||
Defined in lib/core/src/items/entries/entry.class.ts:45
|
||||||
Parameters :
Returns :
void
|
import { Item } from '../item.class'
import {
assert,
isErrorFree
} from '../../utils'
export type EntryConfig = [
string, //Question id
string|number|boolean, //Answer
string, //DateTimeString WITH Timezone ISO8601, RFC3339. Log date.
string?, //note
string?, //Date string. YYYY-MM-DD, TargetDay
]
export function assertEntryConfig(x:unknown) : asserts x is EntryConfig {
assert( Array.isArray(x), "isEntryConfig() config must be an array.")
assert( typeof x[0] == 'string', "isEntryConfig() [0] must be a string.")
assert( typeof x[2] == 'string', "isEntryConfig() [2] must be a string.")
assert( ['string', 'number', 'boolean'].includes(typeof x[1]), "isEntryConfig() [1] must be a string|number|boolean.")
assert( ['string', 'undefined'].includes(typeof x[3]) || x[3] == null, "isEntryConfig() [3] must be a string|null|undefined.")
assert( ['string', 'undefined'].includes(typeof x[4]) || x[4] == null, "isEntryConfig() [4] must be a string|null|undefined.")
}
export function isEntryConfig(x:unknown, throw_errors = false): x is EntryConfig {
return isErrorFree( () => isEntryConfig(x, true) )
}
export class Entry extends Item<EntryConfig> {
public questionId : string
public answer : string|number|boolean
public date : string
public note : string
public targetDay : string //YYYY-MM-DD
public static acceptsAsConfig(config: unknown): config is EntryConfig {
return isEntryConfig(config)
}
set config(config: EntryConfig){
assert( isEntryConfig(config), "Invalid Entry config.")
this.questionId = config[0]
this.answer = config[1]
this.date = config[2]
this.note = config[3]
this.targetDay = config[4]
}
get config(): EntryConfig{
return [this.questionId, this.answer, this.date, this.note, this.targetDay]
}
}