Subscriptions & Deep Loading
Jazz's Collaborative Values (such as CoMaps or CoLists) work like reactive state. By subscribing to them, you can react to both local and remote updates. This is the main way to consume data in your application.
Subscriptions also take care of loading CoValues that are not yet loaded locally and can do so deeply — by resolving nested CoValues. To make use of this, we'll show you how to specify the depth of data you need with resolve queries.
With each update you can also handle loading states and inaccessible CoValues.
Manual subscriptions
You can subscribe to a CoValue from anywhere in your code (if you have its ID) by using CoValue.subscribe()
.
Note: Unless you're using vanilla JavaScript, this is only used outside of React components - for example in server-side code or in tests. See the section below for convenient subscription hooks that you typically use in React.
const
Task =
const Task: co.Map<{ title: z.z.ZodString; description: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">; assignedTo: z.ZodOptional<z.z.ZodString>; }, unknown, Account | Group>
import co
co.map({
map<{ title: z.z.ZodString; description: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">; assignedTo: z.ZodOptional<z.z.ZodString>; }>(shape: { ...; }): co.Map<...> export map
title: z.z.ZodString
title:import z
z.string(),
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export string
description: z.z.ZodString
description:import z
z.string(),
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export string
status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">
status:import z
z.literal(["todo", "in-progress", "completed"]),
literal<readonly ["todo", "in-progress", "completed"]>(value: readonly ["todo", "in-progress", "completed"], params?: string | z.z.core.$ZodLiteralParams): z.z.ZodLiteral<"todo" | "in-progress" | "completed"> (+1 overload) export literal
assignedTo: z.ZodOptional<z.z.ZodString>
assignedTo:import z
z.optional(
optional<z.z.ZodString>(innerType: z.z.ZodString): z.ZodOptional<z.z.ZodString> export optional
import z
z.string()), }); // ... // Subscribe to a Task by ID const
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export string
const unsubscribe: () => void
unsubscribe =Task.
const Task: co.Map<{ title: z.z.ZodString; description: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">; assignedTo: z.ZodOptional<z.z.ZodString>; }, unknown, Account | Group>
subscribe(
CoMapSchema<{ title: ZodString; description: ZodString; status: ZodLiteral<"todo" | "in-progress" | "completed">; assignedTo: ZodOptional<ZodString>; }, unknown, Account | Group>.subscribe<true>(id: string, options: SubscribeListenerOptions<{ readonly title: string; readonly description: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignedTo: string | undefined; } & CoMap, true>, listener: (value: { readonly title: string; readonly description: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignedTo: string | undefined; } & CoMap, unsubscribe: () => void) => void): () => void
const taskId: "co_123"
taskId, {}, (updatedTask) => {
updatedTask: { readonly title: string; readonly description: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignedTo: string | undefined; } & CoMap
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log("Task updated:",updatedTask.
updatedTask: { readonly title: string; readonly description: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignedTo: string | undefined; } & CoMap
title: string
title);var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log("New status:",updatedTask.
updatedTask: { readonly title: string; readonly description: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignedTo: string | undefined; } & CoMap
status: "todo" | "in-progress" | "completed"
status); }); // Clean up when you're doneconst unsubscribe: () => void
unsubscribe();
If you already have a CoValue instance, you can subscribe to it by calling its $jazz.subscribe
method.
const
task =
const task: { readonly title: string; readonly description: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignedTo: string | undefined; } & CoMap
Task.
const Task: co.Map<{ title: z.z.ZodString; description: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">; assignedTo: z.ZodOptional<z.z.ZodString>; }, unknown, Account | Group>
create({
CoMapSchema<{ title: ZodString; description: ZodString; status: ZodLiteral<"todo" | "in-progress" | "completed">; assignedTo: ZodOptional<ZodString>; }, unknown, Account | Group>.create(init: { title: string; description: string; status: "todo" | "in-progress" | "completed"; assignedTo?: string | undefined; }, options?: { owner?: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): { ...; } & CoMap (+1 overload)
title: string
title: "Cut the grass", ...const otherProps: any
otherProps }); constconst unsubscribe: () => void
unsubscribe =task.
const task: { readonly title: string; readonly description: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignedTo: string | undefined; } & CoMap
CoMap.$jazz: CoMapJazzApi<{ readonly title: string; readonly description: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignedTo: string | undefined; } & CoMap>
Jazz methods for CoMaps are inside this property. This allows CoMaps to be used as plain objects while still having access to Jazz methods, and also doesn't limit which key names can be used inside CoMaps.$jazz.
CoMapJazzApi<{ readonly title: string; readonly description: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignedTo: string | undefined; } & CoMap>.subscribe<{ readonly title: string; readonly description: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignedTo: string | undefined; } & CoMap, true>(this: CoMapJazzApi<...>, listener: (value: { ...; } & CoMap, unsubscribe: () => void) => void): () => void (+1 overload)
Given an already loaded `CoMap`, subscribe to updates to the `CoMap` and ensure that the specified fields are loaded to the specified depth. Works like `CoMap.subscribe()`, but you don't need to pass the ID or the account to load as again. Returns an unsubscribe function that you should call when you no longer need updates.subscribe((updatedTask) => {
updatedTask: { readonly title: string; readonly description: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignedTo: string | undefined; } & CoMap
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log("Task updated:",updatedTask.
updatedTask: { readonly title: string; readonly description: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignedTo: string | undefined; } & CoMap
title: string
title); }); // Clean up when you're doneconst unsubscribe: () => void
unsubscribe();
Subscription hooks
useCoState
Jazz provides a useCoState
hook that provides a convenient way to subscribe to CoValues and handle loading states:
import {
function useCoState<S extends CoValueClassOrSchema, const R extends ResolveQuery<S> = true>(Schema: S, id: string | undefined, options?: { resolve?: ResolveQueryStrict<S, R>; }): co.loaded<S, R> | undefined | null
React hook for subscribing to CoValues and handling loading states. This hook provides a convenient way to subscribe to CoValues and automatically handles the subscription lifecycle (subscribe on mount, unsubscribe on unmount). It also supports deep loading of nested CoValues through resolve queries.useCoState } from "jazz-tools/react"; functionGardenPlanner({
function GardenPlanner({ projectId }: { projectId: string; }): "Project not found or not accessible" | "Loading project ..." | React.JSX.Element
projectId: string
projectId }: {projectId: string
projectId: string }) { // Subscribe to a project and its tasks constproject =
const project: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap) | null> | null; } & CoMap, { ...; }, 10, []> | null | undefined
useCoState<co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">; }, unknown, Account | Group>>; }, unknown, Account | Group>, { ...; }>(Schema: co.Map<...>, id: string | undefined, options?: { ...; } | undefined): CoMapLikeLoaded<...> | ... 1 more ... | undefined
React hook for subscribing to CoValues and handling loading states. This hook provides a convenient way to subscribe to CoValues and automatically handles the subscription lifecycle (subscribe on mount, unsubscribe on unmount). It also supports deep loading of nested CoValues through resolve queries.useCoState(Project,
const Project: co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">; }, unknown, Account | Group>>; }, unknown, Account | Group>
projectId: string
projectId, {
resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap) | null> | null; } & CoMap, 10, []> | undefined
Resolve query to specify which nested CoValues to loadresolve: {tasks: {
tasks?: RefsToResolve<CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap) | null>, 10, [0]> | undefined
$each: true }, }, }); if (!
$each?: RefsToResolve<{ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap, 10, [0, 0]> | undefined
project) { return
const project: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap) | null> | null; } & CoMap, { ...; }, 10, []> | null | undefined
const project: null | undefined
project === null ? "Project not found or not accessible" : "Loading project ..."; } return ( <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div> <React.JSX.IntrinsicElements.h1: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>
h1>{project.
const project: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap) | null> | null; } & CoMap, { ...; }, 10, []>
name: string
name}</React.JSX.IntrinsicElements.h1: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>
h1> <TaskList
function TaskList({ tasks }: { tasks: ReadonlyArray<co.loaded<typeof Task>>; }): React.JSX.Element
tasks={
tasks: readonly ({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap)[]
project.
const project: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap) | null> | null; } & CoMap, { ...; }, 10, []>
tasks} /> </
tasks: readonly ({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap)[] & CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap) | null>
React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div> ); } functionTaskList({
function TaskList({ tasks }: { tasks: ReadonlyArray<co.loaded<typeof Task>>; }): React.JSX.Element
tasks }: {
tasks: readonly ({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap)[]
tasks:
tasks: readonly ({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap)[]
interface ReadonlyArray<T>
ReadonlyArray<import co
co.loaded<typeof
type loaded<T extends CoValueClassOrSchema, R extends ResolveQuery<T> = true> = R extends boolean | undefined ? NonNullable<InstanceOfSchemaCoValuesNullable<T>> : [NonNullable<InstanceOfSchemaCoValuesNullable<T>>] extends [...] ? Exclude<...> extends CoValue ? R extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean ... export loaded
Task>> }) { return ( <
const Task: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">; }, unknown, Account | Group>
React.JSX.IntrinsicElements.ul: React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>
ul> {tasks.
tasks: readonly ({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap)[]
ReadonlyArray<{ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap>.map<React.JSX.Element>(callbackfn: (value: { readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap, index: number, array: readonly ({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap)[]) => React.JSX.Element, thisArg?: any): React.JSX.Element[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.map((task) => ( <
task: { readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap
React.JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>
liReact.Attributes.key?: React.Key | null | undefined
key={task.
task: { readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap
CoMap.$jazz: CoMapJazzApi<{ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap>
Jazz methods for CoMaps are inside this property. This allows CoMaps to be used as plain objects while still having access to Jazz methods, and also doesn't limit which key names can be used inside CoMaps.$jazz.CoMapJazzApi<M extends CoMap>.id: string
The ID of this `CoMap`id}> <React.JSX.IntrinsicElements.span: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>
span>{task.
task: { readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap
title: string
title}</React.JSX.IntrinsicElements.span: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>
span> <React.JSX.IntrinsicElements.span: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>
span>{task.
task: { readonly title: string; readonly status: "todo" | "in-progress" | "completed"; } & CoMap
status: "todo" | "in-progress" | "completed"
status}</React.JSX.IntrinsicElements.span: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>
span> </React.JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>
li> ))} </React.JSX.IntrinsicElements.ul: React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>
ul> ); }
The useCoState
hook handles subscribing when the component mounts and unsubscribing when it unmounts, making it easy to keep your UI in sync with the underlying data.
useAccount
useAccount
is used to access the current user's account.
You can use this at the top-level of your app to subscribe to the current user's account profile and root.
Like useCoState
, you can specify a resolve query to also subscribe to CoValues referenced in the account profile or root.
import {
function useAccount<A extends AccountClass<Account> | CoreAccountSchema, R extends ResolveQuery<A> = true>(AccountSchema?: A, options?: { resolve?: ResolveQueryStrict<A, R>; }): { me: co.loaded<A, R> | undefined | null; agent: AnonymousJazzAgent | co.loaded<A, true>; logOut: () => void; }
React hook for accessing the current user's account and authentication state. This hook provides access to the current user's account profile and root data, along with authentication utilities. It automatically handles subscription to the user's account data and provides a logout function.useAccount } from "jazz-tools/react"; functionfunction ProjectList(): React.JSX.Element
ProjectList() { const {me } =
const me: CoMapLikeLoaded<{ readonly root: ({ readonly myProjects: CoList<({ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null; readonly profile: ({ ...; } & CoMap) | null; } & Account, { ...; }, 10, []> | null | undefined
useAccount<co.Account<{ root: co.Map<{ myProjects: co.List<co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; }, unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>; profile: co.Profile<...>; }>, { ...; }>(AccountSchema?: co.Account<...> | undefined, options?: { ...; } | undefined): { ...; }
React hook for accessing the current user's account and authentication state. This hook provides access to the current user's account profile and root data, along with authentication utilities. It automatically handles subscription to the user's account data and provides a logout function.useAccount(MyAppAccount, {
const MyAppAccount: co.Account<{ root: co.Map<{ myProjects: co.List<co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; }, unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>; profile: co.Profile<...>; }>
resolve?: RefsToResolve<{ readonly root: ({ readonly myProjects: CoList<({ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null; readonly profile: ({ ...; } & CoMap) | null; } & Account, 10, []> | undefined
Resolve query to specify which nested CoValues to load from the accountresolve: {profile: true,
profile?: RefsToResolve<{ readonly name: string; readonly inbox: string | undefined; readonly inboxInvite: string | undefined; } & CoMap & Profile, 10, [0]> | undefined
root: {
root?: RefsToResolve<{ readonly myProjects: CoList<({ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap, 10, [...]> | undefined
myProjects: {
myProjects?: RefsToResolve<CoList<({ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap) | null>, 10, [0, 0]> | undefined
$each: {
$each?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap, 10, [0, 0, 0]> | undefined
tasks: true, }, }, }, }, }); if (!
tasks?: RefsToResolve<CoList<({ readonly title: string; } & CoMap) | null>, 10, [0, 0, 0, 0]> | undefined
me) { return <
const me: CoMapLikeLoaded<{ readonly root: ({ readonly myProjects: CoList<({ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null; readonly profile: ({ ...; } & CoMap) | null; } & Account, { ...; }, 10, []> | null | undefined
React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div>Loading...</React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div>; } return ( <React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div> <React.JSX.IntrinsicElements.h1: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>
h1>{me.
const me: CoMapLikeLoaded<{ readonly root: ({ readonly myProjects: CoList<({ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null; readonly profile: ({ ...; } & CoMap) | null; } & Account, { ...; }, 10, []>
profile.
Account.profile: { readonly name: string; readonly inbox: string | undefined; readonly inboxInvite: string | undefined; } & CoMap & Profile
Profile.name: string
name}'s projects</React.JSX.IntrinsicElements.h1: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>
h1> <React.JSX.IntrinsicElements.ul: React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>
ul> {me.
const me: CoMapLikeLoaded<{ readonly root: ({ readonly myProjects: CoList<({ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null; readonly profile: ({ ...; } & CoMap) | null; } & Account, { ...; }, 10, []>
root.
Account.root: { readonly myProjects: readonly ({ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap & { readonly tasks: CoList<({ readonly title: string; } & CoMap) | null>; })[] & CoList<({ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap) | null>; } & { readonly myProjects: CoList<({ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap
myProjects.
myProjects: readonly ({ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap & { readonly tasks: CoList<({ readonly title: string; } & CoMap) | null>; })[] & CoList<({ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap) | null>
map<React.JSX.Element>(callbackfn: (value: { readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap & { readonly tasks: CoList<({ readonly title: string; } & CoMap) | null>; }, index: number, array: readonly ({ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & ... 1 more ... & { readonly tasks: CoList<({ readonly title: string; } & CoMap) | null>; })[]) => React.JSX.Element, thisArg?: any): React.JSX.Element[] (+1 overload)
Calls a defined callback function on each element of an array, and returns an array that contains the results.map((project) => ( <
project: { readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap & { readonly tasks: CoList<({ readonly title: string; } & CoMap) | null>; }
React.JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>
liReact.Attributes.key?: React.Key | null | undefined
key={project.
project: { readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap & { readonly tasks: CoList<({ readonly title: string; } & CoMap) | null>; }
CoMap.$jazz: CoMapJazzApi<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap & { readonly tasks: CoList<({ readonly title: string; } & CoMap) | null>; }>
Jazz methods for CoMaps are inside this property. This allows CoMaps to be used as plain objects while still having access to Jazz methods, and also doesn't limit which key names can be used inside CoMaps.$jazz.CoMapJazzApi<M extends CoMap>.id: string
The ID of this `CoMap`id}> {project.
project: { readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap & { readonly tasks: CoList<({ readonly title: string; } & CoMap) | null>; }
name: string
name} ({project.
project: { readonly name: string; readonly tasks: CoList<({ readonly title: string; } & CoMap) | null> | null; } & CoMap & { readonly tasks: CoList<({ readonly title: string; } & CoMap) | null>; }
tasks.
tasks: CoList<({ readonly title: string; } & CoMap) | null>
Array<T>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.length} tasks) </React.JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>
li> ))} </React.JSX.IntrinsicElements.ul: React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>
ul> </React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div> ); }
Loading States and Permission Checking
When subscribing to or loading a CoValue, you need to handle three possible states:
undefined
: The initial loading state, indicating the value is being fetchednull
: The CoValue was not found or is not accessible (e.g., due to permissions)Value
: The successfully loaded CoValue instance
This allows you to handle loading, error, and success states in your application:
Task.
const Task: co.Map<{ title: z.z.ZodString; }, unknown, Account | Group>
subscribe(
CoMapSchema<{ title: ZodString; }, unknown, Account | Group>.subscribe<true>(id: string, options: SubscribeListenerOptions<{ readonly title: string; } & CoMap, true>, listener: (value: { readonly title: string; } & CoMap, unsubscribe: () => void) => void): () => void
const taskId: "co_123"
taskId, {}, (task:
task: { readonly title: string; } & CoMap
import co
co.loaded<typeof
type loaded<T extends CoValueClassOrSchema, R extends ResolveQuery<T> = true> = R extends boolean | undefined ? NonNullable<InstanceOfSchemaCoValuesNullable<T>> : [NonNullable<InstanceOfSchemaCoValuesNullable<T>>] extends [...] ? Exclude<...> extends CoValue ? R extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean ... export loaded
Task>) => { if (
const Task: co.Map<{ title: z.z.ZodString; }, unknown, Account | Group>
task ===
task: { readonly title: string; } & CoMap
var undefined
undefined) {var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log("Task is loading..."); } else if (task === null) {
task: { readonly title: string; } & CoMap
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log("Task not found or not accessible"); } else {var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log("Task loaded:",task.
task: { readonly title: string; } & CoMap
title: string
title); } });
Deep Loading
When working with related CoValues (like tasks in a project), you often need to load not just the top-level object but also its nested references. This is especially important when working with CoMaps that contain references to other CoValues or with CoLists that contain multiple items. Jazz provides a flexible mechanism for specifying exactly how much of the object graph to load.
Resolve queries
Resolve queries let you declare exactly which references to load and how deep to go using the resolve
property:
const
TeamMember =
const TeamMember: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>
import co
co.map({
map<{ name: z.z.ZodString; }>(shape: { name: z.z.ZodString; }): co.Map<{ name: z.z.ZodString; }, unknown, Account | Group> export map
name: z.z.ZodString
name:import z
z.string(), }); const
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export string
Task =
const Task: co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>
import co
co.map({
map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<co.Map<..., unknown, Account | Group>>; }>(shape: { ...; }): co.Map<...> export map
title: z.z.ZodString
title:import z
z.string(),
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export string
assignee:
assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>
import co
co.optional(
optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>(schema: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>): co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>> export optional
TeamMember), get
const TeamMember: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>
subtasks():
subtasks: co.List<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>
import co
co.List<typeof
class List<T extends AnyZodOrCoValueSchema> export List
Task> { return
const Task: co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>
import co
co.list(
list<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>(element: co.Map<...>): co.List<...> export list
Task) }, }); const
const Task: co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>
Project =
const Project: co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<...>; }, unknown, Account | Group>>; owner: co.Map<...>; }, unknown, Account | Group>
import co
co.map({
map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<...>; }, unknown, Account | Group>>; owner: co.Map<...>; }>(shape: { ...; }): co.Map<...> export map
name: z.z.ZodString
name:import z
z.string(),
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export string
tasks:
tasks: co.List<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>
import co
co.list(
list<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>(element: co.Map<...>): co.List<...> export list
Task),
const Task: co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>
owner:
owner: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>
TeamMember, }); // Load just the project, not its references const
const TeamMember: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>
project = await
const project: ({ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap) | null
Project.
const Project: co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<...>; }, unknown, Account | Group>>; owner: co.Map<...>; }, unknown, Account | Group>
load(
CoMapSchema<{ name: ZodString; tasks: CoListSchema<CoMapSchema<{ title: ZodString; assignee: CoOptionalSchema<CoMapSchema<{ name: ZodString; }, unknown, Account | Group>>; readonly subtasks: CoListSchema<...>; }, unknown, Account | Group>>; owner: CoMapSchema<...>; }, unknown, Account | Group>.load<true>(id: string, options?: { resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<...> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, 10, []> | undefined; loadAs?: Account | AnonymousJazzAgent; skipRetry?: boolean; } | undefined): Promise<...>
const projectId: "co_123"
projectId); if (!project) { throw new
const project: ({ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap) | null
Error("Project not found or not accessible"); } // string - primitive fields are always loaded
var Error: ErrorConstructor new (message?: string, options?: ErrorOptions) => Error (+1 overload)
project.
const project: { readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap
name: string
name; // undefined | null | ListOfTasks - non-requested references might not be loaded, or inaccessibleproject.
const project: { readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap
tasks; // Load the project and shallowly load its list of tasks const
tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null> | null
projectWithTasksShallow = await
const projectWithTasksShallow: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []> | null
Project.
const Project: co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<...>; }, unknown, Account | Group>>; owner: co.Map<...>; }, unknown, Account | Group>
load(
CoMapSchema<{ name: ZodString; tasks: CoListSchema<CoMapSchema<{ title: ZodString; assignee: CoOptionalSchema<CoMapSchema<{ name: ZodString; }, unknown, Account | Group>>; readonly subtasks: CoListSchema<...>; }, unknown, Account | Group>>; owner: CoMapSchema<...>; }, unknown, Account | Group>.load<{ tasks: true; }>(id: string, options?: { resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<...> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, 10, []> | undefined; loadAs?: Account | AnonymousJazzAgent; skipRetry?: boolean; } | undefined): Promise<...>
const projectId: "co_123"
projectId, {resolve: {
resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, 10, []> | undefined
tasks: true } }); if (!
tasks?: RefsToResolve<CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>, 10, [...]> | undefined
projectWithTasksShallow) { throw new
const projectWithTasksShallow: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []> | null
Error("Project or required references not found or not accessible"); } // ListOfTasks - shallowly loaded
var Error: ErrorConstructor new (message?: string, options?: ErrorOptions) => Error (+1 overload)
projectWithTasksShallow.
const projectWithTasksShallow: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
tasks; // number - length of the list
tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>
projectWithTasksShallow.
const projectWithTasksShallow: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
tasks.
tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>
Array<T>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.length; // undefined | null | Task - items might not be loaded, or inaccessibleprojectWithTasksShallow.
const projectWithTasksShallow: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
tasks[0]; // Load the project and its tasks const
tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>
projectWithTasks = await
const projectWithTasks: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []> | null
Project.
const Project: co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<...>; }, unknown, Account | Group>>; owner: co.Map<...>; }, unknown, Account | Group>
load(
CoMapSchema<{ name: ZodString; tasks: CoListSchema<CoMapSchema<{ title: ZodString; assignee: CoOptionalSchema<CoMapSchema<{ name: ZodString; }, unknown, Account | Group>>; readonly subtasks: CoListSchema<...>; }, unknown, Account | Group>>; owner: CoMapSchema<...>; }, unknown, Account | Group>.load<{ tasks: { $each: true; }; }>(id: string, options?: { resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<...> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, 10, []> | undefined; loadAs?: Account | AnonymousJazzAgent; skipRetry?: boolean; } | undefined): Promise<...>
const projectId: "co_123"
projectId, {resolve: {
resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, 10, []> | undefined
tasks: {
tasks?: RefsToResolve<CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>, 10, [...]> | undefined
$each: true } } }); if (!
$each?: RefsToResolve<{ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap, 10, [...]> | undefined
projectWithTasks) { throw new
const projectWithTasks: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []> | null
Error("Project or required references not found or not accessible"); } // ListOfTasks - fully loaded
var Error: ErrorConstructor new (message?: string, options?: ErrorOptions) => Error (+1 overload)
projectWithTasks.
const projectWithTasks: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
tasks; // Task - fully loaded
tasks: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap)[] & CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>
projectWithTasks.
const projectWithTasks: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
tasks[0]; // string - primitive fields are always loaded
tasks: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap)[] & CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>
projectWithTasks.
const projectWithTasks: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
tasks[0].
tasks: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap)[] & CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>
title: string
title; // undefined | null | ListOfTasks - subtasks might not be loaded, or inaccessibleprojectWithTasks.
const projectWithTasks: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
tasks[0].
tasks: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap)[] & CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>
subtasks; // Load the project, its tasks, and their subtasks const
subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null> | null
projectDeep = await
const projectDeep: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []> | null
Project.
const Project: co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<...>; }, unknown, Account | Group>>; owner: co.Map<...>; }, unknown, Account | Group>
load(
CoMapSchema<{ name: ZodString; tasks: CoListSchema<CoMapSchema<{ title: ZodString; assignee: CoOptionalSchema<CoMapSchema<{ name: ZodString; }, unknown, Account | Group>>; readonly subtasks: CoListSchema<...>; }, unknown, Account | Group>>; owner: CoMapSchema<...>; }, unknown, Account | Group>.load<{ tasks: { $each: { subtasks: { $each: true; }; assignee: true; }; }; }>(id: string, options?: { resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<...> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, 10, []> | undefined; loadAs?: Account | AnonymousJazzAgent; skipRetry?: boolean; } | undefined): Promise<...>
const projectId: "co_123"
projectId, {resolve: {
resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, 10, []> | undefined
tasks: {
tasks?: RefsToResolve<CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>, 10, [...]> | undefined
$each: {
$each?: RefsToResolve<{ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap, 10, [...]> | undefined
subtasks: {
subtasks?: RefsToResolve<CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>, 10, [...]> | undefined
$each: true },
$each?: RefsToResolve<{ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap, 10, [...]> | undefined
assignee: true } } } }); if (!
assignee?: RefsToResolve<{ readonly name: string; } & CoMap, 10, [0, 0, 0]> | undefined
projectDeep) { throw new
const projectDeep: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []> | null
Error("Project or required references not found or not accessible"); } // string - primitive fields are always loaded
var Error: ErrorConstructor new (message?: string, options?: ErrorOptions) => Error (+1 overload)
projectDeep.
const projectDeep: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
tasks[0].
tasks: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap & { ...; })[] & CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>
subtasks[0].
subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null> & readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap)[]
title: string
title; // undefined | null | TeamMember - since assignee is optional: // TeamMember - set and definitely loaded // null - set but unavailable/inaccessible // undefined - not set, or loading (in case of subscription)projectDeep.
const projectDeep: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
tasks[0].
tasks: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap & { ...; })[] & CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>
assignee;
assignee: ({ readonly name: string; } & CoMap) | undefined
The resolve query defines which parts of the graph you want to load, making it intuitive to express complex loading patterns.
Loading states and permissions
When loading data with references, the load operation will fail if one of the references is unavailable or if the user doesn't have read access to it. Let's explore what happens in various scenarios:
Resolved References
When a user tries to load a reference they don't have access to:
// If assignee is not accessible to the user: const
task = await
const task: CoMapLikeLoaded<{ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<...> | null; } & CoMap) | null> | null; } & CoMap, { ...; }, 10, []> | null
Task.
const Task: co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>
load(
CoMapSchema<{ title: ZodString; assignee: CoOptionalSchema<CoMapSchema<{ name: ZodString; }, unknown, Account | Group>>; readonly subtasks: CoListSchema<...>; }, unknown, Account | Group>.load<{ assignee: true; }>(id: string, options?: { resolve?: RefsToResolve<{ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | ... 1 more ... | undefined; readonly subtasks: CoList<...> | null; } & CoMap) | null> | null; } & CoMap, 10, []> | undefined; loadAs?: Account | AnonymousJazzAgent; skipRetry?: boolean; } | undefined): Promise<...>
const taskId: "co_123"
taskId, {resolve: {
resolve?: RefsToResolve<{ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<...> | null; } & CoMap) | null> | null; } & CoMap, 10, []> | undefined
assignee: true } });
assignee?: RefsToResolve<{ readonly name: string; } & CoMap, 10, [0]> | undefined
task // => null
const task: CoMapLikeLoaded<{ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<...> | null; } & CoMap) | null> | null; } & CoMap, { ...; }, 10, []> | null
The load operation will fail and return null
if any requested reference is inaccessible. This maintains data consistency by ensuring all requested references are available before returning the object.
The behavior is the same for optional and required references.
List References
When a list contains references to items the user can't access:
// If any item in the list is not accessible: const
project = await
const project: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []> | null
Project.
const Project: co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<...>; }, unknown, Account | Group>>; owner: co.Map<...>; }, unknown, Account | Group>
load(
CoMapSchema<{ name: ZodString; tasks: CoListSchema<CoMapSchema<{ title: ZodString; assignee: CoOptionalSchema<CoMapSchema<{ name: ZodString; }, unknown, Account | Group>>; readonly subtasks: CoListSchema<...>; }, unknown, Account | Group>>; owner: CoMapSchema<...>; }, unknown, Account | Group>.load<{ tasks: { $each: true; }; }>(id: string, options?: { resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<...> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, 10, []> | undefined; loadAs?: Account | AnonymousJazzAgent; skipRetry?: boolean; } | undefined): Promise<...>
const projectId: "co_123"
projectId, {resolve: {
resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, 10, []> | undefined
tasks: {
tasks?: RefsToResolve<CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>, 10, [...]> | undefined
$each: true } } });
$each?: RefsToResolve<{ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap, 10, [...]> | undefined
project // => null
const project: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []> | null
If any item in a list is inaccessible to the user, the entire load operation will fail and return null
. This is because lists expect all their items to be accessible - a partially loaded list could lead to data inconsistencies.
Reading a non-resolved inaccessible reference
When trying to load an object with an inaccessible reference without directly resolving it:
const
project = await
const project: ({ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap) | null
Project.
const Project: co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<...>; }, unknown, Account | Group>>; owner: co.Map<...>; }, unknown, Account | Group>
load(
CoMapSchema<{ name: ZodString; tasks: CoListSchema<CoMapSchema<{ title: ZodString; assignee: CoOptionalSchema<CoMapSchema<{ name: ZodString; }, unknown, Account | Group>>; readonly subtasks: CoListSchema<...>; }, unknown, Account | Group>>; owner: CoMapSchema<...>; }, unknown, Account | Group>.load<true>(id: string, options?: { resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<...> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, 10, []> | undefined; loadAs?: Account | AnonymousJazzAgent; skipRetry?: boolean; } | undefined): Promise<...>
const projectId: "co_123"
projectId, {resolve: true });
resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, 10, []> | undefined
project // => Project // The user doesn't have access to the owner
const project: ({ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap) | null
project?.
const project: ({ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap) | null
owner // => always null
owner: ({ readonly name: string; } & CoMap) | null | undefined
The load operation will succeed and return the object, but the inaccessible reference will always be null
.
Deep loading lists with shared items
When loading a list with shared items, you can use the $onError
option to safely load the list skipping any inaccessible items.
This is especially useful when in your app access to these items might be revoked.
This way the inaccessible items are replaced with null
in the returned list.
const
source =
const source: CoListInstance<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>
import co
co.list(
list<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>(element: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>): co.List<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>> export list
Person).
const Person: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>
create( [
CoListSchema<CoMapSchema<{ name: ZodString; }, unknown, Account | Group>>.create(items: readonly (({ readonly name: string; } & CoMap) | { name: string; })[], options?: { owner: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): CoListInstance<...> (+1 overload)
Person.
const Person: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>
create( {
CoMapSchema<{ name: ZodString; }, unknown, Account | Group>.create(init: { name: string; }, options?: { owner?: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): { readonly name: string; } & CoMap (+1 overload)
name: string
name: "Jane", },const privateGroup: Group
privateGroup, // We don't have access to Jane ),Person.
const Person: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>
create( {
CoMapSchema<{ name: ZodString; }, unknown, Account | Group>.create(init: { name: string; }, options?: { owner?: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): { readonly name: string; } & CoMap (+1 overload)
name: string
name: "Alice", },const publicGroup: Group
publicGroup, // We have access to Alice ), ],const publicGroup: Group
publicGroup, ); constfriends = await
const friends: (readonly (({ readonly name: string; } & CoMap & {}) | null)[] & CoListInstanceCoValuesNullable<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>) | null
import co
co.list(
list<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>(element: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>): co.List<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>> export list
Person).
const Person: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>
load(
CoListSchema<CoMapSchema<{ name: ZodString; }, unknown, Account | Group>>.load<{ $each: { $onError: null; }; }>(id: string, options?: { resolve?: RefsToResolve<CoListInstanceCoValuesNullable<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>, 10, []> | undefined; loadAs?: Account | AnonymousJazzAgent; } | undefined): Promise<...>
source.
const source: CoListInstance<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>
$jazz.
CoList<{ readonly name: string; } & CoMap>.$jazz: CoListJazzApi<CoListInstance<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>>
CoListJazzApi<CoListInstance<CoMapSchema<{ name: ZodString; }, unknown, Account | Group>>>.id: string
The ID of this `CoList`id, {resolve: {
resolve?: RefsToResolve<CoListInstanceCoValuesNullable<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>, 10, []> | undefined
$each: {
$each?: RefsToResolve<{ readonly name: string; } & CoMap, 10, [0]> | undefined
$onError?: null | undefined
$onError: null } },loadAs?: Account | AnonymousJazzAgent | undefined
loadAs:me, }); // Thanks to $onError catching the errors, the list is loaded // because we have access to friends
const me: Account | ({ readonly [x: string]: any; } & Account)
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(friends); // Person[] // Jane is null because we lack access rights // and we have used $onError to catch the error on the list items
const friends: (readonly (({ readonly name: string; } & CoMap & {}) | null)[] & CoListInstanceCoValuesNullable<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>) | null
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(friends?.[0]); // null // Alice is not null because we have access // the type is nullable because we have used $onError
const friends: (readonly (({ readonly name: string; } & CoMap & {}) | null)[] & CoListInstanceCoValuesNullable<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>) | null
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(friends?.[1]); // Person
const friends: (readonly (({ readonly name: string; } & CoMap & {}) | null)[] & CoListInstanceCoValuesNullable<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>) | null
The $onError
works as a "catch" clause option to block any error in the resolved children.
const
source =
const source: CoListInstance<co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>
import co
co.list(
list<co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>(element: co.Map<{ name: z.z.ZodString; dog: co.Map<...>; }, unknown, Account | Group>): co.List<...> export list
Person).
const Person: co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>
create( [
CoListSchema<CoMapSchema<{ name: ZodString; dog: CoMapSchema<{ name: ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>.create(items: readonly (({ readonly name: string; readonly dog: ({ readonly name: string; } & CoMap) | null; } & CoMap) | { name: string; dog: { name: string; } | ({ readonly name: string; } & CoMap); })[], options?: { owner: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): CoListInstance<...> (+1 overload)
Person.
const Person: co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>
create( {
CoMapSchema<{ name: ZodString; dog: CoMapSchema<{ name: ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>.create(init: { name: string; dog: { name: string; } | ({ readonly name: string; } & CoMap); }, options?: { owner?: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): { ...; } & CoMap (+1 overload)
name: string
name: "Jane",dog:
dog: { name: string; } | ({ readonly name: string; } & CoMap)
Dog.
const Dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>
create( {
CoMapSchema<{ name: ZodString; }, unknown, Account | Group>.create(init: { name: string; }, options?: { owner?: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): { readonly name: string; } & CoMap (+1 overload)
name: string
name: "Rex" },const privateGroup: Group
privateGroup, ), // We don't have access to Rex },const publicGroup: Group
publicGroup, ), ],const publicGroup: Group
publicGroup, ); constfriends = await
const friends: (readonly (({ readonly name: string; readonly dog: ({ readonly name: string; } & CoMap) | null; } & CoMap & { readonly dog: { readonly name: string; } & CoMap; }) | null)[] & CoListInstanceCoValuesNullable<...>) | null
import co
co.list(
list<co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>(element: co.Map<{ name: z.z.ZodString; dog: co.Map<...>; }, unknown, Account | Group>): co.List<...> export list
Person).
const Person: co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>
load(
CoListSchema<CoMapSchema<{ name: ZodString; dog: CoMapSchema<{ name: ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>.load<{ $each: { dog: true; $onError: null; }; }>(id: string, options?: { resolve?: RefsToResolve<CoListInstanceCoValuesNullable<co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>, 10, []> | undefined; loadAs?: Account | AnonymousJazzAgent; } | undefined): Promise<...>
source.
const source: CoListInstance<co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>
$jazz.
CoList<{ readonly name: string; readonly dog: { readonly name: string; } & CoMap; } & CoMap>.$jazz: CoListJazzApi<CoListInstance<co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>>
CoListJazzApi<CoListInstance<CoMapSchema<{ name: ZodString; dog: CoMapSchema<{ name: ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>>.id: string
The ID of this `CoList`id, {resolve: {
resolve?: RefsToResolve<CoListInstanceCoValuesNullable<co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>, 10, []> | undefined
$each: {
$each?: RefsToResolve<{ readonly name: string; readonly dog: ({ readonly name: string; } & CoMap) | null; } & CoMap, 10, [0]> | undefined
dog: true,
dog?: RefsToResolve<{ readonly name: string; } & CoMap, 10, [0, 0]> | undefined
$onError?: null | undefined
$onError: null } },loadAs?: Account | AnonymousJazzAgent | undefined
loadAs:me, }); // Jane is null because we don't have access to Rex // and we have used $onError to catch the error on the list items
const me: Account | ({ readonly [x: string]: any; } & Account)
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(friends?.[0]); // null
const friends: (readonly (({ readonly name: string; readonly dog: ({ readonly name: string; } & CoMap) | null; } & CoMap & { readonly dog: { readonly name: string; } & CoMap; }) | null)[] & CoListInstanceCoValuesNullable<...>) | null
We can actually use $onError
everywhere in the resolve query, so we can use it to catch the error on dog:
const
friends = await
const friends: (readonly ({ readonly name: string; readonly dog: ({ readonly name: string; } & CoMap) | null; } & CoMap & { readonly dog: CoMapLikeLoaded<{ readonly name: string; } & CoMap, { $onError: null; }, 10, [...]> | null; })[] & CoListInstanceCoValuesNullable<...>) | null
import co
co.list(
list<co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>(element: co.Map<{ name: z.z.ZodString; dog: co.Map<...>; }, unknown, Account | Group>): co.List<...> export list
Person).
const Person: co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>
load(
CoListSchema<CoMapSchema<{ name: ZodString; dog: CoMapSchema<{ name: ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>.load<{ $each: { dog: { $onError: null; }; }; }>(id: string, options?: { resolve?: RefsToResolve<CoListInstanceCoValuesNullable<co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>, 10, []> | undefined; loadAs?: Account | AnonymousJazzAgent; } | undefined): Promise<...>
source.
const source: CoListInstance<co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>
$jazz.
CoList<{ readonly name: string; readonly dog: { readonly name: string; } & CoMap; } & CoMap>.$jazz: CoListJazzApi<CoListInstance<co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>>
CoListJazzApi<CoListInstance<CoMapSchema<{ name: ZodString; dog: CoMapSchema<{ name: ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>>.id: string
The ID of this `CoList`id, {resolve: {
resolve?: RefsToResolve<CoListInstanceCoValuesNullable<co.Map<{ name: z.z.ZodString; dog: co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>, 10, []> | undefined
$each: {
$each?: RefsToResolve<{ readonly name: string; readonly dog: ({ readonly name: string; } & CoMap) | null; } & CoMap, 10, [0]> | undefined
dog: {
dog?: RefsToResolve<{ readonly name: string; } & CoMap, 10, [0, 0]> | undefined
$onError?: null | undefined
$onError: null } } },loadAs?: Account | AnonymousJazzAgent | undefined
loadAs:me, }); // Jane now is not-nullable at type level because // we have moved $onError down to the dog field // // This also means that if we don't have access to Jane // the entire friends list will be null
const me: Account | ({ readonly [x: string]: any; } & Account)
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(friends?.[0]); // => Person // Jane's dog is null because we don't have access to Rex // and we have used $onError to catch the error
const friends: (readonly ({ readonly name: string; readonly dog: ({ readonly name: string; } & CoMap) | null; } & CoMap & { readonly dog: CoMapLikeLoaded<{ readonly name: string; } & CoMap, { $onError: null; }, 10, [...]> | null; })[] & CoListInstanceCoValuesNullable<...>) | null
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(friends?.[0]?.
const friends: (readonly ({ readonly name: string; readonly dog: ({ readonly name: string; } & CoMap) | null; } & CoMap & { readonly dog: CoMapLikeLoaded<{ readonly name: string; } & CoMap, { $onError: null; }, 10, [...]> | null; })[] & CoListInstanceCoValuesNullable<...>) | null
dog); // => null
dog: ({ readonly name: string; } & CoMap & {}) | null | undefined
Type Safety with co.loaded
Type
Jazz provides the co.loaded
type to help you define and enforce the structure of deeply loaded data in your application. This makes it easier to ensure that components receive the data they expect with proper TypeScript validation.
The co.loaded
type is especially useful when passing data between components, as it guarantees that all necessary nested data has been loaded:
// Define a type that includes loaded nested data type
ProjectWithTasks =
type ProjectWithTasks = { readonly tasks: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap)[] & CoList<(... & CoMap) | null>; } & { ...; } & CoMap
import co
co.loaded< typeof
type loaded<T extends CoValueClassOrSchema, R extends ResolveQuery<T> = true> = R extends boolean | undefined ? NonNullable<InstanceOfSchemaCoValuesNullable<T>> : [NonNullable<InstanceOfSchemaCoValuesNullable<T>>] extends [...] ? Exclude<...> extends CoValue ? R extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean ... export loaded
Project, {
const Project: co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<...>; }, unknown, Account | Group>>; owner: co.Map<...>; }, unknown, Account | Group>
tasks: {
tasks: { $each: true; }
$each: true
$each: true }; } >; // Component that expects a fully loaded project functionTaskList({
function TaskList({ project }: { project: ProjectWithTasks; }): React.JSX.Element
project }: {
project: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
project:
project: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
ProjectWithTasks }) { // TypeScript knows tasks are loaded, so this is type-safe return ( <
type ProjectWithTasks = { readonly tasks: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap)[] & CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null>; } & { readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap
React.JSX.IntrinsicElements.ul: React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>
ul> {project.
project: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
tasks.
tasks: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap)[] & CoList<...>
map<React.JSX.Element>(callbackfn: (value: { readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap, index: number, array: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap)[]) => React.JSX.Element, thisArg?: any): React.JSX.Element[] (+1 overload)
Calls a defined callback function on each element of an array, and returns an array that contains the results.map((task) => ( <
task: { readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap
React.JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>
liReact.Attributes.key?: React.Key | null | undefined
key={task.
task: { readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap
CoMap.$jazz: CoMapJazzApi<{ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap>
Jazz methods for CoMaps are inside this property. This allows CoMaps to be used as plain objects while still having access to Jazz methods, and also doesn't limit which key names can be used inside CoMaps.$jazz.CoMapJazzApi<M extends CoMap>.id: string
The ID of this `CoMap`id}>{task.
task: { readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap
title: string
title}</React.JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>
li> ))} </React.JSX.IntrinsicElements.ul: React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>
ul> ); } // For more complex resolutions typeFullyLoadedProject =
type FullyLoadedProject = { readonly tasks: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap & { ...; })[] & CoList<(... & CoMap) | null>; readonly owner: { readonly name: string; } & CoMap; } & { ...; } & CoMap
import co
co.loaded< typeof
type loaded<T extends CoValueClassOrSchema, R extends ResolveQuery<T> = true> = R extends boolean | undefined ? NonNullable<InstanceOfSchemaCoValuesNullable<T>> : [NonNullable<InstanceOfSchemaCoValuesNullable<T>>] extends [...] ? Exclude<...> extends CoValue ? R extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean ... export loaded
Project, {
const Project: co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; assignee: co.Optional<co.Map<{ name: z.z.ZodString; }, unknown, Account | Group>>; readonly subtasks: co.List<...>; }, unknown, Account | Group>>; owner: co.Map<...>; }, unknown, Account | Group>
tasks: {
tasks: { $each: { subtasks: true; assignee: true; }; }
$each: {
$each: { subtasks: true; assignee: true; }
subtasks: true
subtasks: true;assignee: true
assignee: true; }; };owner: true
owner: true; } >; // Function that requires deeply loaded data functionfunction processProject(project: FullyLoadedProject): void
processProject(project:
project: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
FullyLoadedProject) { // Safe access to all loaded properties
type FullyLoadedProject = { readonly tasks: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap & { ...; })[] & CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null>; readonly owner: { readonly name: string; } & CoMap; } & { readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(`Project ${project.
project: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
name: string
name} owned by ${project.
project: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
owner.
owner: { readonly name: string; } & CoMap
name: string
name}`);project.
project: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ readonly name: string; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
tasks.
tasks: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap & { ...; })[] & CoList<...>
function forEach(callbackfn: (value: { readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap & { ...; }, index: number, array: readonly ({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & ... 1 more ... & { ...; })[]) => void, thisArg?: any): void (+1 overload)
Performs the specified action for each element in an array.forEach((task) => {
task: { readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap & { ...; }
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(`Task: ${task.
task: { readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap & { ...; }
title: string
title}, Assigned to: ${task.
task: { readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap & { ...; }
assignee?.
assignee: ({ readonly name: string; } & CoMap) | undefined
name: string | undefined
name}`);var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(`Subtasks: ${task.
task: { readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap & { ...; }
subtasks: CoList<...>
subtasks.Array<({ readonly title: string; readonly assignee: ({ readonly name: string; } & CoMap) | null | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.length}`); }); }
Using the co.loaded
type helps catch errors at compile time rather than runtime, ensuring that your components and functions receive data with the proper resolution depth. This is especially useful for larger applications where data is passed between many components.
Ensuring Data is Loaded
Sometimes you need to make sure data is loaded before proceeding with an operation. The $jazz.ensureLoaded
method lets you guarantee that a CoValue and its referenced data are loaded to a specific depth:
async function
function completeAllTasks(projectId: string): Promise<void>
completeAllTasks(projectId: string
projectId: string) { // Ensure the project is loaded constproject = await
const project: ({ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ ...; } & CoMap) | null; } & CoMap) | null
Project.
const Project: co.Map<{ name: z.z.ZodString; tasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">; assignee: z.ZodOptional<z.z.ZodString>; readonly subtasks: co.List<...>; }, unknown, Account | Group>>; owner: co.Map<...>; }, unknown, Account | Group>
load(
CoMapSchema<{ name: ZodString; tasks: CoListSchema<CoMapSchema<{ title: ZodString; status: ZodLiteral<"todo" | "in-progress" | "completed">; assignee: ZodOptional<ZodString>; readonly subtasks: CoListSchema<...>; }, unknown, Account | Group>>; owner: CoMapSchema<...>; }, unknown, Account | Group>.load<true>(id: string, options?: { resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<...> | null; } & CoMap) | null> | null; readonly owner: ({ ...; } & CoMap) | null; } & CoMap, 10, []> | undefined; loadAs?: Account | AnonymousJazzAgent; skipRetry?: boolean; } | undefined): Promise<...>
projectId: string
projectId, {resolve: true }); if (!
resolve?: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ ...; } & CoMap) | null; } & CoMap, 10, []> | undefined
project) return; // Ensure tasks are loaded const
const project: ({ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ ...; } & CoMap) | null; } & CoMap) | null
loadedProject = await
const loadedProject: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ ...; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
project.
const project: { readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ ...; } & CoMap) | null; } & CoMap
CoMap.$jazz: CoMapJazzApi<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ ...; } & CoMap) | null; } & CoMap>
Jazz methods for CoMaps are inside this property. This allows CoMaps to be used as plain objects while still having access to Jazz methods, and also doesn't limit which key names can be used inside CoMaps.$jazz.
CoMapJazzApi<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ ...; } & CoMap) | null; } & CoMap>.ensureLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ ...; } & CoMap) | null; } & CoMap, { ...; }>(this: CoMapJazzApi<...>, options: { ...; }): Promise<...>
Given an already loaded `CoMap`, ensure that the specified fields are loaded to the specified depth. Works like `CoMap.load()`, but you don't need to pass the ID or the account to load as again.ensureLoaded({resolve: {
resolve: RefsToResolve<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ ...; } & CoMap) | null; } & CoMap, 10, []>
tasks: {
tasks?: RefsToResolve<CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>, 10, [...]> | undefined
$each: true, }, }, }); // Now we can safely access and modify tasks
$each?: RefsToResolve<{ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap, 10, [...]> | undefined
loadedProject.
const loadedProject: CoMapLikeLoaded<{ readonly name: string; readonly tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; readonly owner: ({ ...; } & CoMap) | null; } & CoMap, { ...; }, 10, []>
tasks.
tasks: readonly ({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap)[] & CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap) | null>
function forEach(callbackfn: (value: { readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap, index: number, array: readonly ({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap)[]) => void, thisArg?: any): void (+1 overload)
Performs the specified action for each element in an array.forEach((task) => {
task: { readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap
task.
task: { readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap
CoMap.$jazz: CoMapJazzApi<{ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap>
Jazz methods for CoMaps are inside this property. This allows CoMaps to be used as plain objects while still having access to Jazz methods, and also doesn't limit which key names can be used inside CoMaps.$jazz.CoMapJazzApi<{ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "completed"; readonly assignee: string | undefined; readonly subtasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null> | null; } & CoMap>.set<"status">(key: "status", value: "todo" | "in-progress" | "completed"): void
Set a value on the CoMapset("status", "completed"); }); }
Best Practices
- Be explicit about resolution depths: Always specify exactly what you need
- Use framework integrations: They handle subscription lifecycle automatically
- Clean up subscriptions: Always store and call the unsubscribe function when you're done
- Handle all loading states: Check for undefined (loading), null (not found), and success states
- Use the
co.loaded
type: Add compile-time type safety for components that require specific resolution patterns