Properties

A property is a named value on an object, such as an invoice's number, status, or due date. Its schema determines which values Sixb accepts.

Define a property

Add prop(id, schema, options?) to an object type's properties array:

TS
import { prop, stringEnum } from "@sixb/core/ontology"

prop("number", "string", { required: true })
prop("status", stringEnum(["draft", "sent", "paid"]))

IDs must be unique within the type. Use name for a separate display label and description for additional context. Without a name, Sixb uses the ID.

Choose a schema

SchemaValues
"string", "uuid"Text or a UUID string.
"boolean"true or false.
"integer", "double"Whole numbers or floating-point numbers.
"decimal"Exact decimal values, represented as strings.
"date", "timestamp"A calendar date or timestamp. Writes accept Date values or ISO strings.
ref.file()A reference to an uploaded file. The string "fileRef" is equivalent.
ref.user()A reference to a Sixb user, such as an assignee.
ref.artifact()A reference to an artifact, such as a meeting's kick-off canvas.
stringEnum([...]), integerEnum([...])A fixed set of string or integer values.
array, object, mapStructured values, shown below.
valueTypeRef(ValueType)A reusable schema.

Scalar schemas are strings. Schemas that point somewhere else are built with ref: ref.file(), ref.user(), ref.artifact(), and ref(ObjectType) for action parameters. To point from one object to another, use a link instead; ref(ObjectType) on a property is rejected.

For exact decimal values, use decimal() with a string rather than converting through a JavaScript number:

TS
import { decimal, prop } from "@sixb/core/ontology"

prop("amount", "decimal")
const amount = decimal("124.50")

Keep a separate currency property when an amount represents money. Physical units are for measurements such as temperature or pressure.

Required and nullable values

Properties are optional and non-nullable by default. required means a new object must include the property. nullable allows an explicit null value. The two options are independent:

TS
prop("number", "string", { required: true })
prop("note", "string", { nullable: true })

An omitted property and a property set to null are different values. Updating an existing object can leave required properties unchanged; see Create or update an object.

The primary property is always a required string.

Unique values

Set unique: true when no two objects of a type may share a value, such as an email or an external key:

TS
prop("email", "string", { unique: true })
prop("account", ref.user(), { nullable: true, unique: true })

A write that would give a value to a second object is refused, whichever way it arrives: your code, an action, or a projection. To find the object that holds a value, use getBy():

TS
const ada = await sixb.objects(Person).getBy(Person.p.email, "ada@example.com")
  • Strings, UUIDs, integers, dates, enums, user references, and value types of those can be unique.
  • Values compare exactly: Ada@example.com and ada@example.com are different values. Normalize values before writing them if they should match.
  • null and missing values never conflict.
  • Uniqueness holds within one object type. A subtype that inherits the property keeps its own values, so a Person and an Employee may share one.
  • One write can move values between objects, such as swapping the emails of two people.

When a property becomes unique, startup (or sixb db migrate) collects the values that existing objects hold. If two objects share a value, startup fails and names both: fix the data, then start again. Values written during a rollout by instances that don't declare unique yet are not tracked, so a value they free can stay refused and a value they write can later be duplicated. Add unique in a release where older instances no longer write that type. To repair the values after such a rollout, remove unique in one release and add it back in the next: startup drops the values, then rebuilds them from the objects.

Structured values

Use arrays for lists, objects for named fields, and maps for dynamic keys:

TS
prop("tags", { type: "array", items: "string" })

prop("address", {
  type: "object",
  properties: {
    street: { schema: "string", required: true },
    city: { schema: "string", required: true },
    postcode: { schema: "string" },
  },
})

prop("labels", { type: "map", keySchema: "string", valueSchema: "string" })

Nested fields can be required or nullable, and structured schemas can be nested. There is no unrestricted json property schema; describe the shape you expect.

Use a value type when several properties share a shape. If the value needs its own identity or relationships, define an object type and connect it with a link.

Reference a user

Use ref.user() when a property names a member of your project, such as a task's assignee or a request's reviewer:

TS
import { prop, ref } from "@sixb/core/ontology"

prop("assignee", ref.user(), {
  nullable: true,
  query: { searchable: true, filterable: true, facet: true },
})
prop("reviewers", { type: "array", items: ref.user() })

The value is { type: "user", id }, with the ID of a Sixb user. A write can only set a user who exists and is active. Values an object already holds stay valid: suspending a user does not block later updates of objects that reference them. The reference carries no display data and grants no access by itself.

Build a value with userRef(id). Queries can match a user with eq, neq, in, and exists, find a user in an array with contains, and group objects by user with facet:

TS
import { userRef } from "@sixb/core"

const assignee = userRef("usr_1")
await sixb.objects(Task).upsert({ properties: { id: "task-1", assignee } })

await sixb
  .objects(Task)
  .query()
  .where((task) => task.or(task.p.assignee.eq(assignee), task.p.reviewers.contains(assignee)))
  .list()

A signed-in Principal whose type is "user" is already a user reference. User references cannot be sorted, searched as text, or listed in search.exact.

To show the member's name, email, or avatar, read the member directory, or include the profiles in a query with expand().

To match the user who runs a query, use currentUser() instead of a fixed ID: task.p.assignee.eq(currentUser()). It only stands for that user in a query predicate, so a property cannot store it.

User references are set by your code, actions, and workflows, or by a projection that matches members by email. Telemetry properties, link properties, and action parameters of a share cannot use them yet. For a person who is part of your domain rather than a project member, such as a customer contact, define an object type.

Reference an artifact

Use ref.artifact() when a property holds an artifact, such as the canvas a meeting is prepared in:

TS
import { prop, ref } from "@sixb/core/ontology"

prop("kickoffDoc", ref.artifact(), {
  nullable: true,
  query: { searchable: true, filterable: true },
})
prop("attachments", { type: "array", items: ref.artifact() })

The value is { type: "artifact", id } and follows the artifact's latest version. Build one with artifactRef(id):

TS
import { artifactRef } from "@sixb/core"

const { artifact } = await sixb.artifacts.create({ kind: "canvas", title: "Kick-off", files })
await sixb.objects(Meeting).upsert({
  properties: { id: "meeting-1", kickoffDoc: artifactRef(artifact.id) },
})
Who writesMay set
A signed-in user or a service accountAn artifact they can change
An action's parameters, a workflow's inputAn artifact whoever requested the run can change
An action's edits, server code running as the systemAny existing artifact
  • Whoever reads the object and the property reads the artifact; whoever may also edit the object changes it. See Hold an artifact in an object.
  • Putting an artifact in a property shares it with that object's readers and editors, whoever set it. Like a file, the artifact does not take the property's markings: whoever reaches it another way, such as through another object, still reads it.
  • An artifact that does not exist, and one the writer cannot change, are refused with the same error. Reading an artifact is not enough to put it in a property.
  • Values an object already holds stay valid, even after the artifact is deleted.
  • Deleting the object leaves the artifact as it is.
  • Queries match an artifact with eq, neq, in, and exists, and find one in an array with contains. Artifact references cannot be sorted, grouped, searched as text, or unique.
  • Telemetry properties, link properties, projections, and action parameters of a share cannot use them.

Enable queries

Add query options to the properties you filter, sort, search, or group. Set searchable: true alongside the capabilities you need:

TS
prop("status", stringEnum(["draft", "sent", "paid"]), {
  query: { searchable: true, filterable: true, facet: true },
})

prop("dueDate", "date", {
  query: { searchable: true, filterable: true, sortable: true },
})
OptionEnables
searchableRequired for all other query options.
filterableProperty predicates such as equality, ranges, and existence.
sortableOrdering results by this property.
textKeyword search on a string or string enum.
exactUsing this property in the type's exact-match search profile.
facetGrouped counts for scalar, enum, or user reference values, excluding file references.
weightPositive text-ranking weight; also requires text: true and provider support.

Without query options, a property can still be stored and read. Comparing the primary ID with eq or in does not need query options. See Querying for the calls these settings enable.

Set search.defaultText on the object type to choose which fields a plain search("...") query uses. Enable text on those properties in the same definition:

TS
// ontology/customer.ts
import { defineObjectType, prop } from "@sixb/core/ontology"

export const Customer = defineObjectType({
  id: "Customer",
  name: "Customer",
  properties: [
    prop("id", "string", { required: true, primary: true }),
    prop("name", "string", {
      required: true,
      query: { searchable: true, text: true, sortable: true },
    }),
  ],
  search: {
    title: "name",
    defaultText: ["name"],
    exact: ["id"],
  },
})

title selects the string field used to label search results. exact lists exact-match fields; each needs query.exact: true, except the primary ID. Search profiles use static properties.

Use search.vectors to search by meaning. Each named profile combines static string or string-enum properties with a registered embedding model:

TS
// ontology/product.ts
import { defineObjectType, prop } from "@sixb/core/ontology"
import { productEmbedding } from "../lib/models"

export const Product = defineObjectType({
  id: "Product",
  name: "Product",
  properties: [
    prop("id", "string", { required: true, primary: true }),
    prop("title", "string", { required: true }),
    prop("description", "string"),
  ],
  search: {
    vectors: {
      content: { source: ["title", "description"], model: productEmbedding },
    },
  },
})

The source properties need no query flags. Sixb stores embeddings separately from your object's properties. See Search by meaning for indexing and querying.

Record history

Properties use mode: "static" by default: they hold the object's current value. Use mode: "telemetry" when you also need a timestamped history:

TS
prop("progress", "integer", { mode: "telemetry" })
prop("online", "boolean", { mode: "telemetry" })

Telemetry supports scalar and structured values, but cannot contain file or user references. Values with a physical semanticType also require a valid unit.

See Telemetry for appending readings and querying their history.

Protect sensitive values

Mark a property to hide its value from roles without the matching clearance:

TS
prop("amount", "decimal", { markings: [financial] })

See Markings.

Search docs

Search the documentation