Skip to main content

dari

Every member of the dari object a Script action binds, with its signature, as the code declares it. How the pieces fit together, and what a script hands to a Content Edit Save, is under Content API.

Everything dari exports​

MemberKindWhat it is
RecordclassA content asset: one of the content model's types, with its field values.
RecordRefclassA pointer to content stored separately, which must already exist: the value of a reference field.
LocationclassA point on the earth, as a latitude and a longitude in degrees, for a location field.
RegionclassAn area, as circles and polygons, for a region field.
StorageItemclassA reference to a file the CMS can already reach, for a file field.
LocalDateclassA calendar date with no time or zone, stored as 2026-08-14.
LocalTimeclassA time of day with no date or zone, stored as 09:30, with seconds and a fraction only when they are not zero.
LocalDateTimeclassA date and time with no zone, stored as 2026-08-14T09:30.
ZonedDateTimeclassA date and time in a named zone, stored as 2026-08-14T09:30-04:00[America/New_York].
OffsetDateTimeclassA date and time with an offset from UTC, stored as 2026-08-14T09:30-04:00.
OffsetTimeclassA time of day with an offset from UTC, stored as 09:30-04:00.
ZoneIdclassA time zone, stored by its name, such as America/New_York.
ZoneOffsetclassAn offset from UTC, stored as -04:00, or Z for UTC.
YearclassA year.
YearMonthclassA year and month, stored as 2026-08.
DurationclassAn amount of time: days, hours, minutes and seconds.
PeriodclassAn amount of calendar time: years, months and days.
MonthDayclassA month and day with no year, stored as --08-14.
RichTextclassThe editor's stored markup, which is not HTML: paragraphs are separated by two <br/> rather than wrapped in <p>, and anything richer than a mark or a list is a registered element addressed by tag name.
RichTextElementclassOne rich text element, found in stored markup or built to add: its tag name, its attributes and its body.
InlineTextclassInline content: the marks the editor writes, and nothing it does not.
DifferencesclassThe field changes between two states, keyed by record id: the shape a Content Edit Save's Differences field takes.
DariErrorclassEverything this SDK throws, so a script can tell an SDK complaint from a bug in its own code with error instanceof dari.DariError.
dari.difffunctionWhat changed between two states, keyed by record id, for a Content Edit Save's Differences field.
dari.uuidfunctionA fresh id for a record about to be built: time-ordered, so ids minted here sort beside ids the CMS minted itself.
dari.typefunctionThe named type as the content model describes it: its id, its fields, and what may be named in as().
dari.timeZonepropertyThe zone a plain Date is read in when a field wants a calendar date, a wall-clock time or an offset.

The classes below them, TypeInfo from dari.type() and ModificationView from record.as(), are reached through a return value rather than named on dari.

Record​

A content asset: one of the content model's types, with its field values. Every value set through record.put() is checked against the type and converted to the field's stored form, so a misspelled field name, a value of the wrong type, or a reference where the field embeds an object fails on the line that caused it.

PropertyTypeDescription
idstringThe asset's id, minted when the record is built unless one was given.
typestring or nullThe type's id as the content model knows it, or null for a record built without a type.
typeInfoTypeInfo or nullThe type as the content model describes it, or null for a record built without a type.

new Record(type, [id])​

A record of the named type, with a fresh id unless one is given.

ParameterTypeDescription
typestringThe type's full internal name, its last part when that is unique across the content model, or its id.
idstringOptional. The id to build under, for a record that must take a known id. Omitted, a fresh time-ordered id is minted.

Record.fromState(state)​

Reads a record from its stored form, such as the values a Content Fetch returns, keeping its id and type. Embedded records inside it come back as records, references as a RecordRef, and lists as arrays.

ParameterTypeDescription
stateObject or nullThe stored form.

Returns Record or null: The record, or null for a null state.

Record.fromStateJson(json)​

Reads a record from its stored form as JSON text.

ParameterTypeDescription
jsonstringThe stored form, as JSON.

Returns Record or null: The record, or null when the JSON is null.

record.as(className)​

This record's fields as the named modification class declares them, addressed by their Java field names, with the stored prefix worked out for you. Fails when the class does not modify this type, naming the ones that do.

ParameterTypeDescription
classNamestringThe modification's full class name, such as com.psddev.cms.db.Content$ObjectModification.

Returns ModificationView: The same record, seen through that class.

record.get(name)​

Reads a field's value.

ParameterTypeDescription
namestringThe field's internal name.

Returns *: The value as it was set or read: a record, an array, a value object, or a plain value. Undefined when the field is not set.

record.put(name, value)​

Sets a field, converting the value to the field's stored form. Fails, naming the field, when the type has no such field, the value does not suit it, or undefined is given; put null to clear a field.

ParameterTypeDescription
namestringThe field's internal name.
value*The value: a plain value, a Date, a Record for an embedded field, a RecordRef or an id for a reference, or one of the value classes.

Returns Record: This record, so calls chain.

record.putRaw(name, value)​

Writes a value under an internal name with no checking or conversion: the escape hatch for a field type this SDK does not write, or a record built without a type.

ParameterTypeDescription
namestringThe internal name to store under.
value*The value, in its stored form.

Returns Record: This record.

record.putAll(values)​

Sets several fields at once, each as record.put() would.

ParameterTypeDescription
valuesObject<string, *>Values by internal field name.

Returns Record: This record.

record.remove(name)​

Removes a field, so the stored form no longer carries it. To keep the field and clear its value, put null.

ParameterTypeDescription
namestringThe field's internal name.

Returns Record: This record.

record.has(name)​

Whether a field is set, even to null.

ParameterTypeDescription
namestringThe field's internal name.

Returns boolean: True when the field is set.

record.keys()​

Every field name that is set, in the order the fields were set.

Returns string[]: The internal names.

record.entries()​

Every set field with its value, as [name, value] pairs.

Returns Array[]: The pairs, in the order the fields were set.

record.list(name)​

The array at a field, creating an empty one when the field is not set or holds something else, so an item can be pushed without checking first.

ParameterTypeDescription
namestringThe field's internal name.

Returns Array: The array the field holds.

record.toRef()​

A pointer to this record, for a reference field elsewhere. Only content that already exists can be pointed at, so a new record has to be saved before another record references it.

Returns RecordRef: The reference, carrying this record's id and type.

record.descendants()​

Every record reachable from this one, including itself, in document order: the record, then each embedded record as it is met.

Returns Record[]: The records.

record.toState()​

The stored form: every field's value with _id and _type, embedded records serialized inside it. Fails when one record appears twice in the tree; point at it from the second place with record.toRef() instead.

Returns Object: The stored form.

record.toStateJson([indent])​

The stored form as JSON text.

ParameterTypeDescription
indentnumber or stringOptional. Indentation, as JSON.stringify takes it.

Returns string: The JSON.

record.toDifferences()​

Every field on this record and on each record inside it, keyed by record id: the shape a Content Edit Save takes for content being created. For content that already exists, dari.diff() reports only what changed.

Returns Differences: The differences.

RecordRef​

A pointer to content stored separately, which must already exist: the value of a reference field. Carries the content's id and, when known, its type, and no field values.

PropertyTypeDescription
idstringThe content's id.
typestring or nullThe content's type id, or null when it isn't known.

new RecordRef(id, [type])​

Points at existing content by id.

ParameterTypeDescription
idstringThe content's id. Anything but a UUID is refused.
typestringOptional. The content's type id, when known.

RecordRef.fromState(state)​

Reads a reference from its stored form, { _ref, _type }.

ParameterTypeDescription
stateObject or nullThe stored form.

Returns RecordRef or null: The reference, or null for a null state.

recordRef.toState()​

The stored form: { _ref: id }, with _type when the type is known.

Returns Object: The stored form.

Location​

A point on the earth, as a latitude and a longitude in degrees, for a location field.

PropertyTypeDescription
latitudenumberThe latitude.
longitudenumberThe longitude.

new Location(latitude, longitude)​

A point from its coordinates, latitude first. Both must be numbers.

ParameterTypeDescription
latitudenumberThe latitude, in degrees.
longitudenumberThe longitude, in degrees.

Location.fromState(state)​

Reads a point from its stored form, { x: latitude, y: longitude }.

ParameterTypeDescription
stateObject or nullThe stored form.

Returns Location or null: The point, or null for a null state.

location.toState()​

The stored form: { x: latitude, y: longitude }.

Returns Object: The stored form.

location.toString()​

The point as latitude, longitude.

Returns string: The text.

Region​

An area, as circles and polygons, for a region field. Build one with Region.circle() or Region.polygon(), and add shapes with region.addCircle() and region.addPolygon(). Points go in latitude first and radii in metres; the stored form is read back the same way through region.circleList.

PropertyTypeDescription
polygonsArrayThe polygons in their stored form: rings of [longitude, latitude] pairs.
circlesArrayThe circles in their stored form: [longitude, latitude, radiusInDegrees] triples.

Region.circle(center, radiusInMeters)​

A region of one circle.

ParameterTypeDescription
centerLocation or ObjectThe centre: a Location, or anything with latitude and longitude.
radiusInMetersnumberThe radius, in metres.

Returns Region: The region.

Region.polygon(ring)​

A region of one polygon.

ParameterTypeDescription
ringArray<(Location|Object)>The corners in order. The ring is closed for you if it isn't already.

Returns Region: The region.

Region.fromState(state)​

Reads a region from its stored form.

ParameterTypeDescription
stateObject or nullThe stored form.

Returns Region or null: The region, or null for a null state.

region.addCircle(center, radiusInMeters)​

Adds a circle.

ParameterTypeDescription
centerLocation or ObjectThe centre: a Location, or anything with latitude and longitude.
radiusInMetersnumberThe radius, in metres.

Returns Region: This region.

region.addPolygon(ring)​

Adds a polygon from a ring of locations. The ring is closed for you if it isn't already.

ParameterTypeDescription
ringArray<(Location|Object)>The corners in order.

Returns Region: This region.

region.circleList​

The circles as centres and radii in metres, rather than as the stored longitude-first degree triples.

Type: Array<{center: Location, radiusInMeters: number}>

region.toState()​

The stored form: polygons, circles, and the x, y and radius keys Dari still writes.

Returns Object: The stored form.

StorageItem​

A reference to a file the CMS can already reach, for a file field. A script cannot upload, since it has no network, so this points at something that exists rather than putting it there.

PropertyTypeDescription
storagestringThe storage the file is in: _url for a file at a URL.
pathstringThe file's path in that storage, or its URL.
contentTypestring or nullThe file's media type, such as image/png, when known.
metadataObject or nullThe file's metadata, such as its width and height, when known.

new StorageItem(storage, path, [contentType], [metadata])​

A file in a named storage. For a file at a URL, StorageItem.url() is shorter.

ParameterTypeDescription
storagestringThe storage's name.
pathstringThe file's path in that storage.
contentTypestringOptional. The file's media type.
metadataObjectOptional. The file's metadata.

StorageItem.url(url)​

A file at a URL. The only kind a script can create, until the platform has first-class file support.

ParameterTypeDescription
urlstringThe file's URL.

Returns StorageItem: The item.

StorageItem.fromState(state)​

Reads any stored item, whatever its storage, so one can be copied from one record to another.

ParameterTypeDescription
stateObject or nullThe stored form.

Returns StorageItem or null: The item, or null for a null state.

storageItem.withContentType(contentType)​

Sets the media type.

ParameterTypeDescription
contentTypestringThe media type, such as image/png.

Returns StorageItem: This item.

storageItem.withMetadata(metadata)​

Merges into the metadata: width, height, original file name, focus points, crops.

ParameterTypeDescription
metadataObjectThe entries to add or replace.

Returns StorageItem: This item.

storageItem.toState()​

The stored form: storage, path, contentType and metadata.

Returns Object: The stored form.

LocalDate​

A calendar date with no time or zone, stored as 2026-08-14.

LocalDate.parse(text)​

Parses the text form the field stores, refusing anything java.time would.

ParameterTypeDescription
textstringThe value as java.time prints it, such as 2026-08-14 for a LocalDate.

Returns LocalDate: The value.

LocalDate.from(value, [zone])​

The value an instant has in a zone: the same moment is a different calendar date or wall-clock time depending on where it is read.

ParameterTypeDescription
valueDate or number or stringAn instant: a Date, epoch milliseconds, or ISO text.
zonestringOptional. The zone to read it in. Omitted, dari.timeZone.

Returns LocalDate: The value.

LocalDate.of(year, month, day)​

A date from its parts.

ParameterTypeDescription
yearnumberThe year.
monthnumberThe month, 1 to 12.
daynumberThe day of the month.

Returns LocalDate: The date.

localDate.toState()​

The stored form: the text java.time prints for this value.

Returns string: The text.

localDate.toString()​

The same text as the stored form.

Returns string: The text.

LocalTime​

A time of day with no date or zone, stored as 09:30, with seconds and a fraction only when they are not zero.

LocalTime.parse(text)​

Parses the text form the field stores, refusing anything java.time would.

ParameterTypeDescription
textstringThe value as java.time prints it, such as 2026-08-14 for a LocalDate.

Returns LocalTime: The value.

LocalTime.from(value, [zone])​

The value an instant has in a zone: the same moment is a different calendar date or wall-clock time depending on where it is read.

ParameterTypeDescription
valueDate or number or stringAn instant: a Date, epoch milliseconds, or ISO text.
zonestringOptional. The zone to read it in. Omitted, dari.timeZone.

Returns LocalTime: The value.

LocalTime.of(hour, minute, [second])​

A time from its parts.

ParameterTypeDescription
hournumberThe hour, 0 to 23.
minutenumberThe minute.
secondnumberOptional. The second. Omitted or zero, the time is stored without seconds.

Returns LocalTime: The time.

localTime.toState()​

The stored form: the text java.time prints for this value.

Returns string: The text.

localTime.toString()​

The same text as the stored form.

Returns string: The text.

LocalDateTime​

A date and time with no zone, stored as 2026-08-14T09:30.

LocalDateTime.parse(text)​

Parses the text form the field stores, refusing anything java.time would.

ParameterTypeDescription
textstringThe value as java.time prints it, such as 2026-08-14 for a LocalDate.

Returns LocalDateTime: The value.

LocalDateTime.from(value, [zone])​

The value an instant has in a zone: the same moment is a different calendar date or wall-clock time depending on where it is read.

ParameterTypeDescription
valueDate or number or stringAn instant: a Date, epoch milliseconds, or ISO text.
zonestringOptional. The zone to read it in. Omitted, dari.timeZone.

Returns LocalDateTime: The value.

localDateTime.toState()​

The stored form: the text java.time prints for this value.

Returns string: The text.

localDateTime.toString()​

The same text as the stored form.

Returns string: The text.

ZonedDateTime​

A date and time in a named zone, stored as 2026-08-14T09:30-04:00[America/New_York].

ZonedDateTime.parse(text)​

Parses the text form the field stores, refusing anything java.time would.

ParameterTypeDescription
textstringThe value as java.time prints it, such as 2026-08-14 for a LocalDate.

Returns ZonedDateTime: The value.

ZonedDateTime.from(value, [zone])​

The value an instant has in a zone: the same moment is a different calendar date or wall-clock time depending on where it is read.

ParameterTypeDescription
valueDate or number or stringAn instant: a Date, epoch milliseconds, or ISO text.
zonestringOptional. The zone to read it in. Omitted, dari.timeZone.

Returns ZonedDateTime: The value.

zonedDateTime.toState()​

The stored form: the text java.time prints for this value.

Returns string: The text.

zonedDateTime.toString()​

The same text as the stored form.

Returns string: The text.

OffsetDateTime​

A date and time with an offset from UTC, stored as 2026-08-14T09:30-04:00.

OffsetDateTime.parse(text)​

Parses the text form the field stores, refusing anything java.time would.

ParameterTypeDescription
textstringThe value as java.time prints it, such as 2026-08-14 for a LocalDate.

Returns OffsetDateTime: The value.

OffsetDateTime.from(value, [zone])​

The value an instant has in a zone: the same moment is a different calendar date or wall-clock time depending on where it is read.

ParameterTypeDescription
valueDate or number or stringAn instant: a Date, epoch milliseconds, or ISO text.
zonestringOptional. The zone to read it in. Omitted, dari.timeZone.

Returns OffsetDateTime: The value.

offsetDateTime.toState()​

The stored form: the text java.time prints for this value.

Returns string: The text.

offsetDateTime.toString()​

The same text as the stored form.

Returns string: The text.

OffsetTime​

A time of day with an offset from UTC, stored as 09:30-04:00.

OffsetTime.parse(text)​

Parses the text form the field stores, refusing anything java.time would.

ParameterTypeDescription
textstringThe value as java.time prints it, such as 2026-08-14 for a LocalDate.

Returns OffsetTime: The value.

OffsetTime.from(value, [zone])​

The value an instant has in a zone: the same moment is a different calendar date or wall-clock time depending on where it is read.

ParameterTypeDescription
valueDate or number or stringAn instant: a Date, epoch milliseconds, or ISO text.
zonestringOptional. The zone to read it in. Omitted, dari.timeZone.

Returns OffsetTime: The value.

offsetTime.toState()​

The stored form: the text java.time prints for this value.

Returns string: The text.

offsetTime.toString()​

The same text as the stored form.

Returns string: The text.

ZoneId​

A time zone, stored by its name, such as America/New_York. from gives the zone the instant was read in.

ZoneId.parse(text)​

Parses the text form the field stores, refusing anything java.time would.

ParameterTypeDescription
textstringThe value as java.time prints it, such as 2026-08-14 for a LocalDate.

Returns ZoneId: The value.

ZoneId.from(value, [zone])​

The value an instant has in a zone: the same moment is a different calendar date or wall-clock time depending on where it is read.

ParameterTypeDescription
valueDate or number or stringAn instant: a Date, epoch milliseconds, or ISO text.
zonestringOptional. The zone to read it in. Omitted, dari.timeZone.

Returns ZoneId: The value.

zoneId.toState()​

The stored form: the text java.time prints for this value.

Returns string: The text.

zoneId.toString()​

The same text as the stored form.

Returns string: The text.

ZoneOffset​

An offset from UTC, stored as -04:00, or Z for UTC.

ZoneOffset.parse(text)​

Parses the text form the field stores, refusing anything java.time would.

ParameterTypeDescription
textstringThe value as java.time prints it, such as 2026-08-14 for a LocalDate.

Returns ZoneOffset: The value.

ZoneOffset.from(value, [zone])​

The value an instant has in a zone: the same moment is a different calendar date or wall-clock time depending on where it is read.

ParameterTypeDescription
valueDate or number or stringAn instant: a Date, epoch milliseconds, or ISO text.
zonestringOptional. The zone to read it in. Omitted, dari.timeZone.

Returns ZoneOffset: The value.

zoneOffset.toState()​

The stored form: the text java.time prints for this value.

Returns string: The text.

zoneOffset.toString()​

The same text as the stored form.

Returns string: The text.

Year​

A year. Stored as a number rather than as text, unlike every other date and time value.

PropertyTypeDescription
valuenumberThe year.

new Year(value)​

A year from a whole number.

ParameterTypeDescription
valuenumberThe year.

Year.of(value)​

A year from a whole number.

ParameterTypeDescription
valuenumberThe year.

Returns Year: The year.

Year.parse(text)​

A year from its text.

ParameterTypeDescription
textstringThe year, such as 2026.

Returns Year: The year.

Year.from(value, [zone])​

The year an instant falls in, read in a zone.

ParameterTypeDescription
valueDate or number or stringAn instant: a Date, epoch milliseconds, or ISO text.
zonestringOptional. The zone to read it in. Omitted, dari.timeZone.

Returns Year: The year.

year.toState()​

The stored form: the number.

Returns number: The year.

year.toString()​

The year as text.

Returns string: The text.

YearMonth​

A year and month, stored as 2026-08.

YearMonth.parse(text)​

Parses the text form the field stores, refusing anything java.time would.

ParameterTypeDescription
textstringThe value as java.time prints it, such as 2026-08-14 for a LocalDate.

Returns YearMonth: The value.

YearMonth.from(value, [zone])​

The value an instant has in a zone: the same moment is a different calendar date or wall-clock time depending on where it is read.

ParameterTypeDescription
valueDate or number or stringAn instant: a Date, epoch milliseconds, or ISO text.
zonestringOptional. The zone to read it in. Omitted, dari.timeZone.

Returns YearMonth: The value.

YearMonth.of(year, month)​

A year and month from their parts.

ParameterTypeDescription
yearnumberThe year.
monthnumberThe month, 1 to 12.

Returns YearMonth: The value.

yearMonth.toState()​

The stored form: the text java.time prints for this value.

Returns string: The text.

yearMonth.toString()​

The same text as the stored form.

Returns string: The text.

Duration​

An amount of time: days, hours, minutes and seconds. Not derivable from a Date, which is one instant rather than a span, so this is one of the few date-shaped values a script has to build.

Duration.of(spec)​

A span from its parts.

ParameterTypeDescription
specObjectThe parts: days, hours, minutes and seconds, each optional.

Returns Duration: The span, such as PT4M30S for { minutes: 4, seconds: 30 }.

Duration.ofSeconds(seconds)​

A span of so many seconds, normalized to hours, minutes and seconds, which is how java.time prints the same span back.

ParameterTypeDescription
secondsnumberThe seconds. A fraction is dropped.

Returns Duration: The span.

Duration.ofMinutes(minutes)​

A span of so many minutes.

ParameterTypeDescription
minutesnumberThe minutes.

Returns Duration: The span.

Duration.parse(text)​

A span from the ISO-8601 text java.time accepts.

ParameterTypeDescription
textstringThe text, such as PT4M30S.

Returns Duration: The span.

Duration.between(from, to)​

The span between two instants, to the second.

ParameterTypeDescription
fromDate or number or stringThe earlier instant.
toDate or number or stringThe later instant.

Returns Duration: The span.

duration.toState()​

The stored form: the ISO-8601 text, such as PT4M30S.

Returns string: The text.

duration.toString()​

The same text as the stored form.

Returns string: The text.

Period​

An amount of calendar time: years, months and days. Like Duration, a span rather than an instant.

Period.of(spec)​

An amount from its parts.

ParameterTypeDescription
specObjectThe parts: years, months and days, each optional.

Returns Period: The amount, such as P1Y6M for { years: 1, months: 6 }.

Period.parse(text)​

An amount from the ISO-8601 text java.time accepts.

ParameterTypeDescription
textstringThe text, such as P1Y6M.

Returns Period: The amount.

period.toState()​

The stored form: the ISO-8601 text, such as P1Y6M.

Returns string: The text.

period.toString()​

The same text as the stored form.

Returns string: The text.

MonthDay​

A month and day with no year, stored as --08-14.

MonthDay.parse(text)​

Parses the text form the field stores, refusing anything java.time would.

ParameterTypeDescription
textstringThe value as java.time prints it, such as 2026-08-14 for a LocalDate.

Returns MonthDay: The value.

MonthDay.from(value, [zone])​

The value an instant has in a zone: the same moment is a different calendar date or wall-clock time depending on where it is read.

ParameterTypeDescription
valueDate or number or stringAn instant: a Date, epoch milliseconds, or ISO text.
zonestringOptional. The zone to read it in. Omitted, dari.timeZone.

Returns MonthDay: The value.

MonthDay.of(month, day)​

A month and day from their parts.

ParameterTypeDescription
monthnumberThe month, 1 to 12.
daynumberThe day of the month.

Returns MonthDay: The value.

monthDay.toState()​

The stored form: the text java.time prints for this value.

Returns string: The text.

monthDay.toString()​

The same text as the stored form.

Returns string: The text.

RichText​

The editor's stored markup, which is not HTML: paragraphs are separated by two <br/> rather than wrapped in <p>, and anything richer than a mark or a list is a registered element addressed by tag name. Build one a block at a time, convert plain prose with RichText.fromPlainText(), or read existing markup with RichText.from().

new RichText([markup])​

Starts from existing markup, or from nothing.

ParameterTypeDescription
markupstringOptional. Stored markup to start from.

RichText.from(markup)​

Existing stored markup, for reading or rewriting.

ParameterTypeDescription
markupstring or nullThe markup, such as the value of a rich text field.

Returns RichText: The value.

RichText.fromPlainText(text)​

Plain text as the editor would have stored it: blank lines become paragraph breaks, single newlines become soft line breaks, and the text itself is escaped. For prose that arrived with no idea it was destined for a rich text field, such as a model's answer or an imported description, whose newlines would otherwise be lost and whose < and & would become markup.

ParameterTypeDescription
textstringThe prose.

Returns RichText: The value, ready to build on.

richText.html(markup)​

Markup written unchanged, after the paragraph break a preceding paragraph left pending.

ParameterTypeDescription
markupstringThe markup.

Returns RichText: This value.

richText.paragraph(value)​

A block of text, separated from the next block by two <br/>. The separator is written lazily, so the last paragraph carries no trailing break.

ParameterTypeDescription
valuestring or InlineText or functionThe text, a built InlineText, or a function given an InlineText to build on.

Returns RichText: This value.

richText.line(value)​

A line inside the current block, ending in a single <br/>: the editor's soft break.

ParameterTypeDescription
valuestring or InlineText or functionThe text, a built InlineText, or a function given an InlineText to build on.

Returns RichText: This value.

richText.list(items)​

A bulleted list.

ParameterTypeDescription
itemsArray<(string|InlineText|function())>One entry per item, each as richText.paragraph() takes.

Returns RichText: This value.

richText.orderedList(items)​

A numbered list.

ParameterTypeDescription
itemsArray<(string|InlineText|function())>One entry per item, each as richText.paragraph() takes.

Returns RichText: This value.

richText.element(tagName, [options])​

A registered rich text element, by the tag name the CMS knows it under. Where an element's data goes, in attributes, in the body, or in one attribute holding a serialized record, is that element's own design, so give it the attributes and body it expects. An attribute given a Record is written as that record's state JSON.

ParameterTypeDescription
tagNamestring or RichTextElementThe tag name, or a built RichTextElement.
optionsObjectOptional. attributes and body, as RichTextElement takes.

Returns RichText: This value.

richText.elements(tagName)​

Every occurrence of the named element in this markup, in document order.

ParameterTypeDescription
tagNamestringThe tag name.

Returns RichTextElement[]: The elements.

richText.rewrite(tagName, visitor)​

Rewrites every occurrence of the named element. Markup outside the elements visited is left byte for byte as it was.

ParameterTypeDescription
tagNamestringThe tag name.
visitorfunctionGiven each element in turn. Return the element to keep it, a different one to replace it, or null to remove it.

Returns RichText: This value.

richText.toPlainText()​

The readable text: every tag but an inline mark becomes a space, and runs of whitespace collapse.

Returns string: The text.

richText.isEmpty​

Whether the markup holds no readable text.

Type: boolean

richText.toHtml()​

The markup.

Returns string: The markup.

richText.toState()​

The stored form: the markup.

Returns string: The markup.

richText.toString()​

The markup.

Returns string: The markup.

RichTextElement​

One rich text element, found in stored markup or built to add: its tag name, its attributes and its body. Nothing here interprets what those mean. An element decides for itself whether a value belongs in an attribute, in the body, or in one attribute holding its whole serialized state, and that decision lives in Java code this SDK cannot run. So the element is what it literally is, with richTextElement.record() for the common case where one attribute holds a record.

PropertyTypeDescription
tagNamestringThe element's tag name, such as bsp-pull-quote.
attributesObject<string, *>The attributes, by name.
bodystringThe body text.

new RichTextElement(tagName, [options])​

An element to add to a RichText.

ParameterTypeDescription
tagNamestringThe tag name the CMS knows the element by.
optionsObjectOptional. attributes, the attribute values by name, and body, the body text.

richTextElement.attribute(name, [value])​

Reads an attribute with one argument, writes it with two. A Record is written as its state JSON.

ParameterTypeDescription
namestringThe attribute's name.
value*Optional. The value to write.

Returns *: The attribute's value when reading, or this element when writing.

richTextElement.record(name)​

The named attribute parsed as a record, for an element that stores its fields as serialized state.

ParameterTypeDescription
namestringThe attribute's name.

Returns Record or null: The record, or null when the attribute is empty.

richTextElement.toHtml()​

The element as markup, its attributes escaped and a Record-valued attribute written as that record's state JSON.

Returns string: The markup.

InlineText​

Inline content: the marks the editor writes, and nothing it does not. Given to a RichText block as a function, t => t.text("The ").bold("harbor"), so formatting can be mixed into a paragraph, a line or a list item.

new InlineText()​

An empty run of inline content.

inlineText.text(value)​

Plain text, escaped so that markup characters in it stay text.

ParameterTypeDescription
valuestringThe text.

Returns InlineText: This run.

inlineText.bold(value)​

Text in bold.

ParameterTypeDescription
valuestringThe text.

Returns InlineText: This run.

inlineText.italic(value)​

Text in italics.

ParameterTypeDescription
valuestringThe text.

Returns InlineText: This run.

inlineText.underline(value)​

Underlined text.

ParameterTypeDescription
valuestringThe text.

Returns InlineText: This run.

inlineText.strikethrough(value)​

Struck-through text.

ParameterTypeDescription
valuestringThe text.

Returns InlineText: This run.

inlineText.code(value)​

Text as code.

ParameterTypeDescription
valuestringThe text.

Returns InlineText: This run.

inlineText.wrap(tag, value)​

Text inside one inline mark, by its tag name, for a mark the named methods don't cover, such as sup.

ParameterTypeDescription
tagstringThe mark's tag name.
valuestringThe text.

Returns InlineText: This run.

A link.

ParameterTypeDescription
hrefstringThe URL.
valuestringThe link's text.

Returns InlineText: This run.

inlineText.html(markup)​

Markup written as it is, unescaped.

ParameterTypeDescription
markupstringThe markup.

Returns InlineText: This run.

inlineText.toHtml()​

The run as markup.

Returns string: The markup.

Differences​

The field changes between two states, keyed by record id: the shape a Content Edit Save's Differences field takes. Produced by dari.diff() and record.toDifferences().

PropertyTypeDescription
byRecordObject<string, Object>Every change, keyed by record id, each an object of the changed fields in their stored form: the value the Save's Differences field wants.

differences.isEmpty​

Whether nothing changed.

Type: boolean

differences.recordIds​

The ids of the records that changed.

Type: string[]

differences.forRecord(id)​

One record's changed fields.

ParameterTypeDescription
idstringThe record's id.

Returns Object: The changed fields, empty when that record didn't change.

differences.embeddedFor(id)​

Every changed record except the one named, as a Save's embedded-object rows.

ParameterTypeDescription
idstringThe root record's id.

Returns Array<{objectId: string, fields: Object}>: The other records' changes.

differences.toJson([indent])​

The changes as JSON text, for logging while working out why something is or isn't changing.

ParameterTypeDescription
indentnumber or stringOptional. Indentation, as JSON.stringify takes it.

Returns string: The JSON.

DariError​

Everything this SDK throws, so a script can tell an SDK complaint from a bug in its own code with error instanceof dari.DariError. The message names the field or value and what was expected.

PropertyTypeDescription
namestringAlways DariError.

new DariError(message)​

An error of this SDK's kind, for a script that wants its own checks to fail the same way.

ParameterTypeDescription
messagestringWhat went wrong.

dari.diff(before, after, [options])​

What changed between two states, keyed by record id, for a Content Edit Save's Differences field. Compares as Dari does: null equals false and every empty value, a field missing on one side counts as null, and lists compare in order unless named in unorderedFields.

ParameterTypeDescription
beforeObject or RecordThe earlier state, such as a Content Fetch's values, or an empty object for content being created.
afterObject or RecordThe later state, or the record itself.
optionsObjectOptional. unorderedFields: the names of fields whose lists compare as sets, for a list whose order carries no meaning.

Returns Differences: The changes.

dari.uuid()​

A fresh id for a record about to be built: time-ordered, so ids minted here sort beside ids the CMS minted itself.

Returns string: The id.

dari.type(identifier)​

The named type as the content model describes it: its id, its fields, and what may be named in as(). Fails when there is no such type.

ParameterTypeDescription
identifierstringThe type's full internal name, its last part when that is unique across the content model, or its id.

Returns TypeInfo: The type.

dari.timeZone​

The zone a plain Date is read in when a field wants a calendar date, a wall-clock time or an offset. Defaults to UTC. Set it once at the top of a script that cares, to a name the runtime knows, such as America/New_York.

Type: string

TypeInfo​

One content type as the content model describes it: what dari.type returns. Its fields are described as objects with a name, a type such as text, number, date, record or list/text, the permittedValues of a fixed list, and isEmbedded for a record field that holds its value inside the parent.

PropertyTypeDescription
idstringThe type's id.
namestringThe type's full internal name, such as com.example.Article.
displayNamestringThe type's display name.
isEmbeddedbooleanWhether content of this type lives inside its parent rather than on its own.
isAbstractbooleanWhether the type only exists to be extended.
isConcretebooleanWhether content of exactly this type can exist.
modificationsstring[]The modification classes that apply to the type, which record.as() may name.

typeInfo.field(internalName)​

The field stored under an internal name, the type's own or a global one.

ParameterTypeDescription
internalNamestringThe name the field is stored under.

Returns Object or null: The field's description, or null when the type has no such field.

typeInfo.fieldOf(declaringClassName, javaFieldName)​

The field a modification class declares under a Java field name.

ParameterTypeDescription
declaringClassNamestringThe modification's full class name.
javaFieldNamestringThe field's name in that class.

Returns Object or null: The field's description, or null when that class declares no such field.

typeInfo.fieldNames()​

Every field's internal name, the type's own and the global ones.

Returns string[]: The names.

typeInfo.declares(className)​

Whether as(className) is meaningful here: the class modifies this type, or declares a global field.

ParameterTypeDescription
classNamestringThe class's full name.

Returns boolean: True when the class may be named.

typeInfo.javaFieldNamesOf(className)​

The Java field names a modification class declares on this type.

ParameterTypeDescription
classNamestringThe class's full name.

Returns string[]: The names, empty for a class that declares none.

typeInfo.modificationNames()​

Every class that may be named in record.as() on this type.

Returns string[]: The full class names.

ModificationView​

A record's fields as one modification class declares them, addressed by their Java field names: what record.as() returns. Reads and writes go to the record itself, under the prefixed names the fields are stored under.

modificationView.get(javaFieldName)​

Reads a field's value.

ParameterTypeDescription
javaFieldNamestringThe field's name in the modification class.

Returns *: The value, or undefined when the field is not set.

modificationView.put(javaFieldName, value)​

Sets a field, converting the value as record.put() does.

ParameterTypeDescription
javaFieldNamestringThe field's name in the modification class.
value*The value.

Returns ModificationView: This view.

modificationView.putAll(values)​

Sets several fields at once.

ParameterTypeDescription
valuesObject<string, *>Values by Java field name.

Returns ModificationView: This view.

modificationView.remove(javaFieldName)​

Removes a field.

ParameterTypeDescription
javaFieldNamestringThe field's name in the modification class.

Returns ModificationView: This view.

modificationView.has(javaFieldName)​

Whether a field is set.

ParameterTypeDescription
javaFieldNamestringThe field's name in the modification class.

Returns boolean: True when the field is set.

modificationView.internalName(javaFieldName)​

The internal name this modification's field is stored under: the prefix applied, ready for a state map or record.putRaw().

ParameterTypeDescription
javaFieldNamestringThe field's name in the modification class.

Returns string: The stored name.

Was this page helpful?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.