AppBuilder
Declares one App in a composition, whether it is the root App or an imported App.
Remarks
Section titled “Remarks”Call AppBuilder.configure first to give the App its canonical key, then declare data and
behavior. Resource keys must start with a lowercase letter, contain only letters and digits, be
at most 64 characters long, and be unique within their collection regardless of case. The
TTypes mapping supplies generated application-specific types; the Extract helpers select the
matching input, output, Item or Template type from that mapping.
- Compose apps
- Your first application
- AppDefinition for the emitted Definition
- ReadAppInstance for the App inside an execution
Extends
Section titled “Extends”Type Parameters
Section titled “Type Parameters”TTypes
Section titled “TTypes”TTypes extends AppBuilderTypes = AppBuilderTypes
Generated type mapping of this App.
Properties
Section titled “Properties”dependencies
Section titled “dependencies”
readonlydependencies:Record<string,DependencyAppBuilder<any>>
Imported Apps, keyed by the local dependency key passed to AppBuilder.addDependency.
events
Section titled “events”
readonlyevents:Record<string,EventBuilder>
App-level Events, keyed by Event key.
Inherited from
Section titled “Inherited from”
readonlyhooks:AppHookDefinition
App Hooks registered with AppBuilder.onCreate and AppBuilder.onSeed.
readonlykey:string
Canonical App key set by AppBuilder.configure.
Inherited from
Section titled “Inherited from”mutations
Section titled “mutations”
readonlymutations:Record<string,MutationBuilder>
Mutations, keyed by Mutation key.
readonlyprn:string
Platform Resource Name of the declared resource, derived from the App key and resource key.
Inherited from
Section titled “Inherited from”queries
Section titled “queries”
readonlyqueries:Record<string,QueryBuilder>
Queries, keyed by Query key.
readonlyroles:Record<string,AppRoleBuilder>
App Roles, keyed by Role key.
Overrides
Section titled “Overrides”searches
Section titled “searches”
readonlysearches:Record<string,SearchIndexBuilder>
Search indexes, keyed by index key.
Overrides
Section titled “Overrides”templates
Section titled “templates”
readonlytemplates:Record<string,TemplateBuilder>
Templates, keyed by Template key.
Inherited from
Section titled “Inherited from”DependencyAppBuilder.templates
unions
Section titled “unions”
readonlyunions:Record<string,UnionBuilder>
Unions, keyed by Union key.
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”addDependency()
Section titled “addDependency()”addDependency<
TKey>(key,spec):DependencyAppBuilder<any>
Imports another App under a key local to this App and returns its resources.
Type Parameters
Section titled “Type Parameters”TKey extends string
Dependency key, used to select the generated type of the imported App.
Parameters
Section titled “Parameters”TKey
Dependency key this App uses for the imported App.
AppSpec | ((builder) => void)
Spec of the App to import.
Returns
Section titled “Returns”DependencyAppBuilder<any>
The imported App’s resources, specialized by generated App types when available.
Remarks
Section titled “Remarks”The imported spec supplies its own canonical key through configure. A canonical App is built
once per composition, so two importers of the same spec share one builder. Importing the same
key twice returns the existing imported App without evaluating the spec again.
Example
Section titled “Example”Importing the core App
const core = app.addDependency('core', coreSpec);const employeeProfile = app.addDependency('employeeProfile', employeeProfileSpec);task.addRelation('assignee', 'many-to-one', employeeProfile.templates.employee);addEvent()
Section titled “addEvent()”addEvent(
key):EventBuilder
Declares an App-level Event, which the Runtime publishes against the Workspace Item.
Parameters
Section titled “Parameters”string
Event key within this App.
Returns
Section titled “Returns”The Event builder for payload, Listeners, child Events and schedules.
Remarks
Section titled “Remarks”Use Template Events for Events about a particular Item. Declare the payload on the returned builder, then register Listeners and schedules.
- TemplateBuilder.addEvent for Item-level Events
- Events
addMetric()
Section titled “addMetric()”addMetric(
key):MetricBuilder
Declares a Metric projected from the Events added to it.
Parameters
Section titled “Parameters”string
Metric key within this App.
Returns
Section titled “Returns”The Metric builder for selecting Events and Dimensions.
Remarks
Section titled “Remarks”Every selected Event contributes one entry to the Metric’s time series, valued by its calculation handler and tagged with the Dimension values resolved for that Event. Query the Metric by interval and Dimension at run time.
Example
Section titled “Example”Counting deliveries by channel
const deliveries = app.addMetric('deliveries');deliveries.addEvent(slack.templates.delivery.events.delivered);deliveries.addDimension(channelDimension, 1, channelDimensionHandler);addMetricDimension()
Section titled “addMetricDimension()”addMetricDimension(
key,subject):MetricDimensionBuilder
Declares a Dimension that Metrics of this App can be broken down by.
Parameters
Section titled “Parameters”string
Dimension key within this App.
subject
Section titled “subject”(TemplateBuilder | UnionBuilder)[]
Templates or Unions whose Items are the Dimension values.
Returns
Section titled “Returns”The Dimension builder.
Remarks
Section titled “Remarks”A Dimension value is an Item of one of the subject Templates or Unions, for example a country Item when the subject is the country Template. Attach the Dimension to a Metric with MetricBuilder.addDimension, supplying the handler that maps each Event to its Item.
addMutation()
Section titled “addMutation()”Call Signature
Section titled “Call Signature”addMutation<
TKey>(key,handler):MutationBuilder
Declares a Mutation and returns its builder for input, output and Grants.
Type Parameters
Section titled “Type Parameters”TKey extends string
Mutation key, used to select generated input and output types.
Parameters
Section titled “Parameters”TKey
Mutation key within this App.
handler
Section titled “handler”MutationHandler<ExtractMutationInput<TKey, TTypes>, ExtractMutationOutput<TKey, TTypes>, TTypes["WriteAppInstance"], TTypes["WriteRuntimeInstance"]>
Behavior the Runtime invokes when the Mutation is called.
Returns
Section titled “Returns”The Mutation builder.
Remarks
Section titled “Remarks”The handler receives the parsed input, this App as current and a write context as ctx.
Declare input with mutation.input, the result with mutation.output, and which App Roles may
call it with mutation.addGrant. With a generated TTypes mapping the handler’s input and
result types are selected by key.
Example
Section titled “Example”Archiving an Item by id
const archive = app.addMutation('archive', async (input, _current, ctx) => { const item = await ctx.getItem(input.id); if (!item) throw new Error('Item not found'); return await item.archive();});archive.input.addProperty('id', 'id').mandatory();archive.output.item(task);archive.addGrant(core.roles.admin);- MutationHandler for the handler signature
- Behavior and change
Call Signature
Section titled “Call Signature”addMutation<
TKey>(key,options,handler):MutationBuilder
Declares a Mutation with shorthand input and output declarations.
Type Parameters
Section titled “Type Parameters”TKey extends string
Mutation key, used to select generated input and output types.
Parameters
Section titled “Parameters”TKey
Mutation key within this App.
options
Section titled “options”Shorthand input and output declarations.
handler
Section titled “handler”MutationHandler<ExtractMutationInput<TKey, TTypes>, ExtractMutationOutput<TKey, TTypes>, TTypes["WriteAppInstance"], TTypes["WriteRuntimeInstance"]>
Behavior the Runtime invokes when the Mutation is called.
Returns
Section titled “Returns”The Mutation builder.
Remarks
Section titled “Remarks”The shorthand in options is applied to the Mutation’s input and output before the builder is
returned; refine it further through mutation.input and mutation.output.
HandlerOptions for the shorthand forms
addQuery()
Section titled “addQuery()”Call Signature
Section titled “Call Signature”addQuery<
TKey>(key,handler):QueryBuilder
Declares a Query and returns its builder for input, output and Grants.
Type Parameters
Section titled “Type Parameters”TKey extends string
Query key, used to select generated input and output types.
Parameters
Section titled “Parameters”TKey
Query key within this App.
handler
Section titled “handler”QueryHandler<ExtractQueryInput<TKey, TTypes>, ExtractQueryOutput<TKey, TTypes>, TTypes["ReadAppInstance"], TTypes["ReadRuntimeInstance"]>
Behavior the Runtime invokes when the Query is called.
Returns
Section titled “Returns”The Query builder.
Remarks
Section titled “Remarks”The handler receives the parsed input, this App as current and a read context as ctx.
Declare input with query.input, the result with query.output, and which App Roles may call
it with query.addGrant. A Grant permits the call; Item and Property access inside the handler
is still checked against the caller.
Example
Section titled “Example”Listing Items as a cursor
const getFlows = app.addQuery('getFlows', async (_input, current, _ctx) => { return current.templates.workflow.selectItems().execute();});getFlows.output.item(workflow).cursor();getFlows.addGrant(core.roles.user);- QueryHandler for the handler signature
- Grant access
Call Signature
Section titled “Call Signature”addQuery<
TKey>(key,options,handler):QueryBuilder
Declares a Query with shorthand input and output declarations.
Type Parameters
Section titled “Type Parameters”TKey extends string
Query key, used to select generated input and output types.
Parameters
Section titled “Parameters”TKey
Query key within this App.
options
Section titled “options”Shorthand input and output declarations.
handler
Section titled “handler”QueryHandler<ExtractQueryInput<TKey, TTypes>, ExtractQueryOutput<TKey, TTypes>, TTypes["ReadAppInstance"], TTypes["ReadRuntimeInstance"]>
Behavior the Runtime invokes when the Query is called.
Returns
Section titled “Returns”The Query builder.
Remarks
Section titled “Remarks”The shorthand in options is applied to the Query’s input and output before the builder is
returned; refine it further through query.input and query.output.
HandlerOptions for the shorthand forms
addRole()
Section titled “addRole()”addRole(
key,options):AppRoleBuilder
Declares an App Role that principals can be assigned across the whole App.
Parameters
Section titled “Parameters”string
Role key within this App.
options
Section titled “options”Display options for the Role.
Returns
Section titled “Returns”The Role builder, which can extend other App Roles.
Remarks
Section titled “Remarks”App Roles are broad, such as admin or user. Grant them operations with
BaseOperationBuilder.addGrant. For access relative to an Item, declare a Template Role
with TemplateBuilder.addRole instead.
Example
Section titled “Example”Two App Roles
const userRole = app.addRole('user', { label: 'User' });const adminRole = app.addRole('admin', { label: 'Admin' });adminRole.extend(userRole);addSearch()
Section titled “addSearch()”addSearch(
key):SearchIndexBuilder
Declares a search index that Items of selected Templates are indexed into.
Parameters
Section titled “Parameters”string
Index key within this App.
Returns
Section titled “Returns”The search index builder.
Remarks
Section titled “Remarks”The Builder also registers a Union with the same key on this App to hold the indexed Templates, so the key must not collide with a Union key. Add Templates and their indexing handlers with SearchIndexBuilder.addTemplate.
addTemplate()
Section titled “addTemplate()”addTemplate<
TKey>(key):ExtractTemplate<TKey,TTypes>
Declares a Template for Items belonging to this App and returns its builder.
Type Parameters
Section titled “Type Parameters”TKey extends string
Template key, used to select the generated Template builder type.
Parameters
Section titled “Parameters”TKey
Template key within this App.
Returns
Section titled “Returns”ExtractTemplate<TKey, TTypes>
The Template builder, specialized by the generated TTypes mapping when available.
Remarks
Section titled “Remarks”The key workspace is reserved for the Workspace Template returned by
AppBuilder.getWorkspaceTemplate.
Throws
Section titled “Throws”When key is workspace or is not a valid key.
Example
Section titled “Example”Declaring a Template with Properties
const task = app.addTemplate('task').setDescription('A unit of work assigned to an employee');task.addProperty('title', 'string', { label: 'Title' }).index();task.addProperty('dueDate', 'date');addUnion()
Section titled “addUnion()”addUnion(
key,templates):UnionBuilder
Groups Templates so that Relations, Events and operation outputs can target any member.
Parameters
Section titled “Parameters”string
Union key within this App.
templates
Section titled “templates”Initial member Templates; pass [] to add every member with addTemplate.
Returns
Section titled “Returns”The Union builder.
Remarks
Section titled “Remarks”A Union is a membership list, not an inheritance mechanism: it does not give members shared Properties or Grants. Add further members with UnionBuilder.addTemplate.
configure()
Section titled “configure()”configure(
key):this
Sets the canonical key of this App, used in the Definition and in every resource PRN.
Parameters
Section titled “Parameters”string
Canonical App key.
Returns
Section titled “Returns”this
This builder for chaining.
Remarks
Section titled “Remarks”The canonical key is distinct from the local key an importer passes to
AppBuilder.addDependency. Call it first in the spec: reading AppBuilder.key or
any resource prn before it is set throws.
Throws
Section titled “Throws”When key is not a valid key.
getWorkspaceTemplate()
Section titled “getWorkspaceTemplate()”getWorkspaceTemplate():
TemplateBuilder
Returns the Workspace Template, on which Apps declare Workspace-level Properties and Roles.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”One Workspace Template instance is shared by every App in a composition, so Properties an App
declares on it are visible to every other App through the Workspace Item. A spec imported by
several Apps is evaluated once per importer; guard Workspace declarations with a check such as
if (!workspace.properties.timeZones) so a second evaluation does not redeclare a key.
Example
Section titled “Example”Declaring a Workspace setting
const workspace = app.getWorkspaceTemplate();if (!workspace.properties.dailyLimit) workspace.addProperty('dailyLimit', 'integer');onCreate()
Section titled “onCreate()”onCreate(
fn):this
Registers an App Hook that runs when a Workspace is created for this App.
Parameters
Section titled “Parameters”App Hook to run on creation.
Returns
Section titled “Returns”this
This builder for chaining.
Remarks
Section titled “Remarks”App Hooks form a chain: each receives prev, which runs the remaining App Hooks, along with
this App and a system write context. Await prev() to preserve the chain. App Hooks registered after
another on the same App run before it.
Example
Section titled “Example”Assigning the creating principal a Role
app.onCreate(async (prev, _current, ctx) => { await prev(); await ctx.apps.core.roles.admin.assign('current');});onSeed()
Section titled “onSeed()”onSeed(
fn):this
Registers an App Hook that seeds initial Items when a Workspace is created for this App.
Parameters
Section titled “Parameters”App Hook to run when seeding.
Returns
Section titled “Returns”this
This builder for chaining.
Remarks
Section titled “Remarks”App Hooks form a chain: each receives prev, which runs the remaining App Hooks, along with
this App and a system write context whose seed operation persists the Items. Await prev() to
preserve the chain.
Example
Section titled “Example”Seeding a fixed Item
app.onSeed(async (prev, _current, ctx) => { await prev(); await ctx.seed({ items: [{ id: HOME_ID, key: 'home', properties: {}, templatePrn: home.prn }] });});setDescription()
Section titled “setDescription()”setDescription(
description):this
Sets the description emitted into the definition and rendered in generated reference and application assets.
Parameters
Section titled “Parameters”description
Section titled “description”string
Human-readable description of the resource.
Returns
Section titled “Returns”this
This builder for chaining.
Inherited from
Section titled “Inherited from”toDefinition()
Section titled “toDefinition()”toDefinition():
AppDefinition
Emits the Definition of this App, including its executable handlers.
Returns
Section titled “Returns”The App Definition.
Remarks
Section titled “Remarks”The result is memoized and frozen. The root App’s Definition includes the Workspace Template
under the key workspace. Serializing the Definition alone does not retain handler functions.

