Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Latest commit

 

History

History
173 lines (126 loc) · 4.81 KB

weak-record-key.asciidoc

File metadata and controls

173 lines (126 loc) · 4.81 KB

WeakRecordKey

Overview

class WeakRecordKey extends RecordId

Examples of weak record key strings
c154458
i538329@st
.c369683
.i1843944
.i5876342@abcde

Parts

type WeakRecordKey.Parts = {
    initialPeriod = false: boolean,
    recordTypeCode: string,
    recNum: string,
    campusCode = null: null | string
}
Part Description

initialPeriod

true if the weak record key was created from a string that started with an initial period. If true, the result from toString() will start with an initial period by default. Defaults to false.

recordTypeCode

The 1 character code for the record type.

recNum

The actual number part of the record id.

campusCode

The 1-5 character code for a virtual record’s campus/location. null if the record id isn’t for a virtual record. Defaults to null.

You get the parts of a weak record key via the parts property, or you can get individual parts directly.

const weakRecordKey = new WeakRecordKey('c154458')
weakRecordKey.parts
// => { initialPeriod: false, recordTypeCode: 'c', recNum: '154458', campusCode: null }
weakRecordKey.initialPeriod // => false
weakRecordKey.recordTypeCode // => 'c'
weakRecordKey.recNum // => '154458'
weakRecordKey.campsuCode // => null
const weakRecordKey = new WeakRecordKey('.i5876342@abcde')
weakRecordKey.parts
// => { initialPeriod: true, recordTypeCode: 'c', recNum: '154458', campusCode: 'abcde' }
weakRecordKey.initialPeriod // => true
weakRecordKey.recordTypeCode // => 'c'
weakRecordKey.recNum // => '154458'
weakRecordKey.campsuCode // => 'abcde'

You can construct weak record keys from parts.

const weakRecordKey = new WeakRecordKey({ recordTypeCode: 'i', recNum: '1843944' })
weakRecordKey.parts
// => { initialPeriod: false, recordTypeCode: 'i', recNum: '1843944', campusCode: null }
weakRecordKey.toString() // => 'i1843944'
const weakRecordKey =
    new WeakRecordKey({ initialPeriod: true, recordTypeCode: 'p', recNum: '5383293', campusCode: 'st' })
weakRecordKey.parts
// => { initialPeriod: true, recordTypeCode: 'p', recNum: '5383293', campusCode: 'st' }
weakRecordKey.toString() // => '.p5383293@st'

Converting

You can give an initialPeriod option when converting to a weak record key. If you don’t, the initialPeriod part of the weak record key will be false.

const recordId = new RelativeV4ApiUrl('v4/items/1843944')

recordId.convertTo(WeakRecordKey).parts
// => { initialPeriod: false, recordTypeCode: 'i', recNum: '1843944', campusCode: null }

recordId.convertTo(WeakRecordKey, { initialPeriod: false }).parts
// => { initialPeriod: false, recordTypeCode: 'i', recNum: '1843944', campusCode: null }

recordId.convertTo(WeakRecordKey, { initialPeriod: true }).parts
// => { initialPeriod: true, recordTypeCode: 'i', recNum: '1843944', campusCode: null }

Stringifying

initialPeriod campusCode Template

false

null

${recordTypeCode}${recNum}

false

not null

${recordTypeCode}${recNum}@${campusCode}

true

null

.${recordTypeCode}${recNum}

true

not null

.${recordTypeCode}${recNum}@${campusCode}

Validation

Part Validation

recordTypeCode

Is a valid record type code. Which record type codes are valid depends on the apiCompatibleOnly option.

recNum

Is 6 or 7 digits and doesn’t have any zeros before the first non-zero.

campusCode

If not null, is 1-5 alphanumeric characters.

Option Description

apiCompatibleOnly

If true, the record type code must be one that can be converted to an absolute or relative API URL. If false, the record type code can be any of the types Sierra supports. Defaults to false.