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 
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>
Task
= import coco.
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
map
({
title: z.z.ZodStringtitle: import zz.
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload)
export string
string
(),
description: z.z.ZodStringdescription: import zz.
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload)
export string
string
(),
status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">status: import zz.
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
literal
(["todo", "in-progress", "completed"]),
assignedTo: z.ZodOptional<z.z.ZodString>assignedTo: import zz.
optional<z.z.ZodString>(innerType: z.z.ZodString): z.ZodOptional<z.z.ZodString>
export optional
optional
(import zz.
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload)
export string
string
()),
}); // ... // Subscribe to a Task by ID const const unsubscribe: () => voidunsubscribe =
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>
Task
.
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
subscribe
(const taskId: "co_123"taskId, {}, (
updatedTask: {
    readonly title: string;
    readonly description: string;
    readonly status: "todo" | "in-progress" | "completed";
    readonly assignedTo: string | undefined;
} & CoMap
updatedTask
) => {
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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
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: {
    readonly title: string;
    readonly description: string;
    readonly status: "todo" | "in-progress" | "completed";
    readonly assignedTo: string | undefined;
} & CoMap
updatedTask
.title: stringtitle);
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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
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: {
    readonly title: string;
    readonly description: string;
    readonly status: "todo" | "in-progress" | "completed";
    readonly assignedTo: string | undefined;
} & CoMap
updatedTask
.status: "todo" | "in-progress" | "completed"status);
}); // Clean up when you're done const unsubscribe: () => voidunsubscribe();

If you already have a CoValue instance, you can subscribe to it by calling its $jazz.subscribe method.

const 
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>
Task
.
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)
create
({
title: stringtitle: "Cut the grass", ...const otherProps: anyotherProps }); const const unsubscribe: () => voidunsubscribe =
const task: {
    readonly title: string;
    readonly description: string;
    readonly status: "todo" | "in-progress" | "completed";
    readonly assignedTo: string | undefined;
} & CoMap
task
.
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.
@categorySubscription & Loading
subscribe
((
updatedTask: {
    readonly title: string;
    readonly description: string;
    readonly status: "todo" | "in-progress" | "completed";
    readonly assignedTo: string | undefined;
} & CoMap
updatedTask
) => {
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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
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: {
    readonly title: string;
    readonly description: string;
    readonly status: "todo" | "in-progress" | "completed";
    readonly assignedTo: string | undefined;
} & CoMap
updatedTask
.title: stringtitle);
}); // Clean up when you're done const unsubscribe: () => voidunsubscribe();

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.
@returnsThe loaded CoValue, or `undefined` if loading, or `null` if not found/not accessible@example```tsx // Deep loading with resolve queries const Project = co.map({ name: z.string(), tasks: co.list(Task), owner: TeamMember, }); function ProjectView({ projectId }: { projectId: string }) { const project = useCoState(Project, projectId, { resolve: { tasks: { $each: true }, owner: true, }, }); if (!project) { return project === null ? "Project not found or not accessible" : "Loading project..."; } return ( <div> <h1>{project.name}</h1> <p>Owner: {project.owner.name}</p> <ul> {project.tasks.map((task) => ( <li key={task.id}>{task.title}</li> ))} </ul> </div> ); } ```@example```tsx // Using with optional references and error handling const Task = co.map({ title: z.string(), assignee: co.optional(TeamMember), subtasks: co.list(Task), }); function TaskDetail({ taskId }: { taskId: string }) { const task = useCoState(Task, taskId, { resolve: { assignee: true, subtasks: { $each: { $onError: null } }, }, }); if (!task) { return task === null ? "Task not found or not accessible" : "Loading task..."; } return ( <div> <h2>{task.title}</h2> {task.assignee && <p>Assigned to: {task.assignee.name}</p>} <ul> {task.subtasks.map((subtask, index) => ( subtask ? <li key={subtask.id}>{subtask.title}</li> : <li key={index}>Inaccessible subtask</li> ))} </ul> </div> ); } ``` For more examples, see the [subscription and deep loading](https://jazz.tools/docs/react/using-covalues/subscription-and-loading) documentation.
useCoState
} from "jazz-tools/react";
function
function GardenPlanner({ projectId }: {
    projectId: string;
}): "Project not found or not accessible" | "Loading project ..." | React.JSX.Element
GardenPlanner
({ projectId: stringprojectId }: { projectId: stringprojectId: string }) {
// Subscribe to a project and its tasks const
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
project
=
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.
@returnsThe loaded CoValue, or `undefined` if loading, or `null` if not found/not accessible@example```tsx // Deep loading with resolve queries const Project = co.map({ name: z.string(), tasks: co.list(Task), owner: TeamMember, }); function ProjectView({ projectId }: { projectId: string }) { const project = useCoState(Project, projectId, { resolve: { tasks: { $each: true }, owner: true, }, }); if (!project) { return project === null ? "Project not found or not accessible" : "Loading project..."; } return ( <div> <h1>{project.name}</h1> <p>Owner: {project.owner.name}</p> <ul> {project.tasks.map((task) => ( <li key={task.id}>{task.title}</li> ))} </ul> </div> ); } ```@example```tsx // Using with optional references and error handling const Task = co.map({ title: z.string(), assignee: co.optional(TeamMember), subtasks: co.list(Task), }); function TaskDetail({ taskId }: { taskId: string }) { const task = useCoState(Task, taskId, { resolve: { assignee: true, subtasks: { $each: { $onError: null } }, }, }); if (!task) { return task === null ? "Task not found or not accessible" : "Loading task..."; } return ( <div> <h2>{task.title}</h2> {task.assignee && <p>Assigned to: {task.assignee.name}</p>} <ul> {task.subtasks.map((subtask, index) => ( subtask ? <li key={subtask.id}>{subtask.title}</li> : <li key={index}>Inaccessible subtask</li> ))} </ul> </div> ); } ``` For more examples, see the [subscription and deep loading](https://jazz.tools/docs/react/using-covalues/subscription-and-loading) documentation.
useCoState
(
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>
Project
, projectId: stringprojectId, {
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 load
resolve
: {
tasks?: RefsToResolve<CoList<({
    readonly title: string;
    readonly status: "todo" | "in-progress" | "completed";
} & CoMap) | null>, 10, [0]> | undefined
tasks
: {
$each?: RefsToResolve<{
    readonly title: string;
    readonly status: "todo" | "in-progress" | "completed";
} & CoMap, 10, [0, 0]> | undefined
$each
: true },
}, }); if (!
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
project
) {
return const project: null | undefinedproject === 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>{
const project: CoMapLikeLoaded<{
    readonly name: string;
    readonly tasks: CoList<({
        readonly title: string;
        readonly status: "todo" | "in-progress" | "completed";
    } & CoMap) | null> | null;
} & CoMap, {
    ...;
}, 10, []>
project
.name: stringname}</React.JSX.IntrinsicElements.h1: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>h1>
<
function TaskList({ tasks }: {
    tasks: ReadonlyArray<co.loaded<typeof Task>>;
}): React.JSX.Element
TaskList
tasks: readonly ({
    readonly title: string;
    readonly status: "todo" | "in-progress" | "completed";
} & CoMap)[]
tasks
={
const project: CoMapLikeLoaded<{
    readonly name: string;
    readonly tasks: CoList<({
        readonly title: string;
        readonly status: "todo" | "in-progress" | "completed";
    } & CoMap) | null> | null;
} & CoMap, {
    ...;
}, 10, []>
project
.
tasks: readonly ({
    readonly title: string;
    readonly status: "todo" | "in-progress" | "completed";
} & CoMap)[] & CoList<({
    readonly title: string;
    readonly status: "todo" | "in-progress" | "completed";
} & CoMap) | null>
tasks
} />
</React.JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>div> ); } function
function TaskList({ tasks }: {
    tasks: ReadonlyArray<co.loaded<typeof Task>>;
}): React.JSX.Element
TaskList
({
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)[]
tasks
: interface ReadonlyArray<T>ReadonlyArray<import coco.
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
loaded
<typeof
const Task: co.Map<{
    title: z.z.ZodString;
    status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">;
}, unknown, Account | Group>
Task
>> }) {
return ( <React.JSX.IntrinsicElements.ul: React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>ul> {
tasks: readonly ({
    readonly title: string;
    readonly status: "todo" | "in-progress" | "completed";
} & CoMap)[]
tasks
.
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.
@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
map
((
task: {
    readonly title: string;
    readonly status: "todo" | "in-progress" | "completed";
} & CoMap
task
) => (
<React.JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>li React.Attributes.key?: React.Key | null | undefinedkey={
task: {
    readonly title: string;
    readonly status: "todo" | "in-progress" | "completed";
} & CoMap
task
.
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`
@categoryContent
id
}>
<React.JSX.IntrinsicElements.span: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>span>{
task: {
    readonly title: string;
    readonly status: "todo" | "in-progress" | "completed";
} & CoMap
task
.title: stringtitle}</React.JSX.IntrinsicElements.span: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>span>
<React.JSX.IntrinsicElements.span: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>span>{
task: {
    readonly title: string;
    readonly status: "todo" | "in-progress" | "completed";
} & CoMap
task
.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.
@returnsAn object containing: - `me`: The loaded account data, or `undefined` if loading, or `null` if not authenticated - `agent`: The current agent (anonymous or authenticated user). Can be used as `loadAs` parameter for load and subscribe methods. - `logOut`: Function to log out the current user@example```tsx // Deep loading with resolve queries function ProjectListWithDetails() { const { me } = useAccount(MyAppAccount, { resolve: { profile: true, root: { myProjects: { $each: { tasks: true, }, }, }, }, }); if (!me) { return me === null ? <div>Failed to load your projects</div> : <div>Loading...</div>; } return ( <div> <h1>{me.profile.name}'s projects</h1> <ul> {me.root.myProjects.map((project) => ( <li key={project.id}> {project.name} ({project.tasks.length} tasks) </li> ))} </ul> </div> ); } ```
useAccount
} from "jazz-tools/react";
function function ProjectList(): React.JSX.ElementProjectList() { const {
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
me
} =
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.
@returnsAn object containing: - `me`: The loaded account data, or `undefined` if loading, or `null` if not authenticated - `agent`: The current agent (anonymous or authenticated user). Can be used as `loadAs` parameter for load and subscribe methods. - `logOut`: Function to log out the current user@example```tsx // Deep loading with resolve queries function ProjectListWithDetails() { const { me } = useAccount(MyAppAccount, { resolve: { profile: true, root: { myProjects: { $each: { tasks: true, }, }, }, }, }); if (!me) { return me === null ? <div>Failed to load your projects</div> : <div>Loading...</div>; } return ( <div> <h1>{me.profile.name}'s projects</h1> <ul> {me.root.myProjects.map((project) => ( <li key={project.id}> {project.name} ({project.tasks.length} tasks) </li> ))} </ul> </div> ); } ```
useAccount
(
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<...>;
}>
MyAppAccount
, {
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 account
resolve
: {
profile?: RefsToResolve<{
    readonly name: string;
    readonly inbox: string | undefined;
    readonly inboxInvite: string | undefined;
} & CoMap & Profile, 10, [0]> | undefined
profile
: true,
root?: RefsToResolve<{
    readonly myProjects: CoList<({
        readonly name: string;
        readonly tasks: CoList<({
            readonly title: string;
        } & CoMap) | null> | null;
    } & CoMap) | null> | null;
} & CoMap, 10, [...]> | undefined
root
: {
myProjects?: RefsToResolve<CoList<({
    readonly name: string;
    readonly tasks: CoList<({
        readonly title: string;
    } & CoMap) | null> | null;
} & CoMap) | null>, 10, [0, 0]> | undefined
myProjects
: {
$each?: RefsToResolve<{
    readonly name: string;
    readonly tasks: CoList<({
        readonly title: string;
    } & CoMap) | null> | null;
} & CoMap, 10, [0, 0, 0]> | undefined
$each
: {
tasks?: RefsToResolve<CoList<({
    readonly title: string;
} & CoMap) | null>, 10, [0, 0, 0, 0]> | undefined
tasks
: true,
}, }, }, }, }); if (!
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
me
) {
return <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>{
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, []>
me
.
Account.profile: {
    readonly name: string;
    readonly inbox: string | undefined;
    readonly inboxInvite: string | undefined;
} & CoMap & Profile
profile
.Profile.name: stringname}'s projects</React.JSX.IntrinsicElements.h1: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>h1>
<React.JSX.IntrinsicElements.ul: React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>ul> {
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, []>
me
.
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
root
.
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>
myProjects
.
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.
@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
map
((
project: {
    readonly name: string;
    readonly tasks: CoList<({
        readonly title: string;
    } & CoMap) | null> | null;
} & CoMap & {
    readonly tasks: CoList<({
        readonly title: string;
    } & CoMap) | null>;
}
project
) => (
<React.JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>li React.Attributes.key?: React.Key | null | undefinedkey={
project: {
    readonly name: string;
    readonly tasks: CoList<({
        readonly title: string;
    } & CoMap) | null> | null;
} & CoMap & {
    readonly tasks: CoList<({
        readonly title: string;
    } & CoMap) | null>;
}
project
.
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`
@categoryContent
id
}>
{
project: {
    readonly name: string;
    readonly tasks: CoList<({
        readonly title: string;
    } & CoMap) | null> | null;
} & CoMap & {
    readonly tasks: CoList<({
        readonly title: string;
    } & CoMap) | null>;
}
project
.name: stringname} ({
project: {
    readonly name: string;
    readonly tasks: CoList<({
        readonly title: string;
    } & CoMap) | null> | null;
} & CoMap & {
    readonly tasks: CoList<({
        readonly title: string;
    } & CoMap) | null>;
}
project
.
tasks: CoList<({
    readonly title: string;
} & CoMap) | null>
tasks
.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 fetched
  • null: 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:

const Task: co.Map<{
    title: z.z.ZodString;
}, unknown, Account | Group>
Task
.
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
subscribe
(const taskId: "co_123"taskId, {}, (
task: {
    readonly title: string;
} & CoMap
task
: import coco.
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
loaded
<typeof
const Task: co.Map<{
    title: z.z.ZodString;
}, unknown, Account | Group>
Task
>) => {
if (
task: {
    readonly title: string;
} & CoMap
task
=== var undefinedundefined) {
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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
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: {
    readonly title: string;
} & CoMap
task
=== 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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
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: {
    readonly title: string;
} & CoMap
task
.title: stringtitle);
} });

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 
const TeamMember: co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>
TeamMember
= import coco.
map<{
    name: z.z.ZodString;
}>(shape: {
    name: z.z.ZodString;
}): co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>
export map
map
({
name: z.z.ZodStringname: import zz.
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload)
export string
string
(),
}); 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>
Task
= import coco.
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
map
({
title: z.z.ZodStringtitle: import zz.
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload)
export string
string
(),
assignee: co.Optional<co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>>
assignee
: import coco.
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
optional
(
const TeamMember: co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>
TeamMember
),
get
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>>
subtasks
(): import coco.
class List<T extends AnyZodOrCoValueSchema>
export List
List
<typeof
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>
Task
> { return import coco.
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
list
(
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>
Task
) },
}); const
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>
Project
= import coco.
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
map
({
name: z.z.ZodStringname: import zz.
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload)
export string
string
(),
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>>
tasks
: import coco.
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
list
(
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>
Task
),
owner: co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>
owner
:
const TeamMember: co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>
TeamMember
,
}); // Load just the project, not its references const
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
= await
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>
Project
.
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<...>
load
(const projectId: "co_123"projectId);
if (!
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
) { throw new
var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error
("Project not found or not accessible"); }
// string - primitive fields are always loaded
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
project
.name: stringname;
// undefined | null | ListOfTasks - non-requested references might not be loaded, or inaccessible
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
project
.
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
tasks
;
// Load the project and shallowly load its list of tasks const
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
projectWithTasksShallow
= await
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>
Project
.
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<...>
load
(const projectId: "co_123"projectId, {
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
resolve
: {
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
tasks
: true
} }); if (!
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
projectWithTasksShallow
) { throw new
var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error
("Project or required references not found or not accessible"); }
// ListOfTasks - shallowly loaded
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, []>
projectWithTasksShallow
.
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>
tasks
;
// number - length of the list
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, []>
projectWithTasksShallow
.
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>
tasks
.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 inaccessible
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, []>
projectWithTasksShallow
.
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>
tasks
[0];
// Load the project and its tasks const
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
projectWithTasks
= await
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>
Project
.
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<...>
load
(const projectId: "co_123"projectId, {
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
resolve
: {
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
tasks
: {
$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
$each
: true
} } }); if (!
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
projectWithTasks
) { throw new
var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error
("Project or required references not found or not accessible"); }
// ListOfTasks - fully loaded
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, []>
projectWithTasks
.
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>
tasks
;
// Task - fully loaded
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, []>
projectWithTasks
.
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>
tasks
[0];
// string - primitive fields are always loaded
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, []>
projectWithTasks
.
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>
tasks
[0].title: stringtitle;
// undefined | null | ListOfTasks - subtasks might not be loaded, or inaccessible
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, []>
projectWithTasks
.
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>
tasks
[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> | null
subtasks
;
// Load the project, its tasks, and their subtasks const
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
projectDeep
= await
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>
Project
.
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<...>
load
(const projectId: "co_123"projectId, {
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
resolve
: {
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
tasks
: {
$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
$each
: {
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
subtasks
: {
$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
$each
: true
},
assignee?: RefsToResolve<{
    readonly name: string;
} & CoMap, 10, [0, 0, 0]> | undefined
assignee
: true
} } } }); if (!
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
projectDeep
) { throw new
var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error
("Project or required references not found or not accessible"); }
// string - primitive fields are always loaded
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, []>
projectDeep
.
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>
tasks
[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)[]
subtasks
[0].title: stringtitle;
// 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)
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, []>
projectDeep
.
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>
tasks
[0].
assignee: ({
    readonly name: string;
} & CoMap) | undefined
assignee
;

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 
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
= await
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>
Task
.
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<...>
load
(const taskId: "co_123"taskId, {
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
resolve
: {
assignee?: RefsToResolve<{
    readonly name: string;
} & CoMap, 10, [0]> | undefined
assignee
: true }
});
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
// => 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 
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
= await
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>
Project
.
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<...>
load
(const projectId: "co_123"projectId, {
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
resolve
: {
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
tasks
: {
$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
$each
: true } }
});
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
// => 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 
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
= await
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>
Project
.
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<...>
load
(const projectId: "co_123"projectId, {
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
resolve
: true
});
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
// => 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
?.
owner: ({
    readonly name: string;
} & CoMap) | null | undefined
owner
// => always null

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 
const source: CoListInstance<co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>>
source
= import coco.
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
list
(
const Person: co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>
Person
).
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)
create
(
[
const Person: co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>
Person
.
CoMapSchema<{ name: ZodString; }, unknown, Account | Group>.create(init: {
    name: string;
}, options?: {
    owner?: Group;
    unique?: CoValueUniqueness["uniqueness"];
} | Group): {
    readonly name: string;
} & CoMap (+1 overload)
create
(
{ name: stringname: "Jane", }, const privateGroup: GroupprivateGroup, // We don't have access to Jane ),
const Person: co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>
Person
.
CoMapSchema<{ name: ZodString; }, unknown, Account | Group>.create(init: {
    name: string;
}, options?: {
    owner?: Group;
    unique?: CoValueUniqueness["uniqueness"];
} | Group): {
    readonly name: string;
} & CoMap (+1 overload)
create
(
{ name: stringname: "Alice", }, const publicGroup: GrouppublicGroup, // We have access to Alice ), ], const publicGroup: GrouppublicGroup, ); const
const friends: (readonly (({
    readonly name: string;
} & CoMap & {}) | null)[] & CoListInstanceCoValuesNullable<co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>>) | null
friends
= await import coco.
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
list
(
const Person: co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>
Person
).
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<...>
load
(
const source: CoListInstance<co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>>
source
.
CoList<{ readonly name: string; } & CoMap>.$jazz: CoListJazzApi<CoListInstance<co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>>>
$jazz
.CoListJazzApi<CoListInstance<CoMapSchema<{ name: ZodString; }, unknown, Account | Group>>>.id: string
The ID of this `CoList`
@categoryContent
id
, {
resolve?: RefsToResolve<CoListInstanceCoValuesNullable<co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>>, 10, []> | undefined
resolve
: {
$each?: RefsToResolve<{
    readonly name: string;
} & CoMap, 10, [0]> | undefined
$each
: { $onError?: null | undefined$onError: null }
}, loadAs?: Account | AnonymousJazzAgent | undefinedloadAs:
const me: Account | ({
    readonly [x: string]: any;
} & Account)
me
,
}); // Thanks to $onError catching the errors, the list is loaded // because we have access to friends 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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(
const friends: (readonly (({
    readonly name: string;
} & CoMap & {}) | null)[] & CoListInstanceCoValuesNullable<co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>>) | null
friends
); // Person[]
// Jane is null because we lack access rights // and we have used $onError to catch the error on the list items 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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(
const friends: (readonly (({
    readonly name: string;
} & CoMap & {}) | null)[] & CoListInstanceCoValuesNullable<co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>>) | null
friends
?.[0]); // null
// Alice is not null because we have access // the type is nullable because we have used $onError 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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(
const friends: (readonly (({
    readonly name: string;
} & CoMap & {}) | null)[] & CoListInstanceCoValuesNullable<co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>>) | null
friends
?.[1]); // Person

The $onError works as a "catch" clause option to block any error in the resolved children.

const 
const source: CoListInstance<co.Map<{
    name: z.z.ZodString;
    dog: co.Map<{
        name: z.z.ZodString;
    }, unknown, Account | Group>;
}, unknown, Account | Group>>
source
= import coco.
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
list
(
const Person: co.Map<{
    name: z.z.ZodString;
    dog: co.Map<{
        name: z.z.ZodString;
    }, unknown, Account | Group>;
}, unknown, Account | Group>
Person
).
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)
create
(
[
const Person: co.Map<{
    name: z.z.ZodString;
    dog: co.Map<{
        name: z.z.ZodString;
    }, unknown, Account | Group>;
}, unknown, Account | Group>
Person
.
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)
create
(
{ name: stringname: "Jane",
dog: {
    name: string;
} | ({
    readonly name: string;
} & CoMap)
dog
:
const Dog: co.Map<{
    name: z.z.ZodString;
}, unknown, Account | Group>
Dog
.
CoMapSchema<{ name: ZodString; }, unknown, Account | Group>.create(init: {
    name: string;
}, options?: {
    owner?: Group;
    unique?: CoValueUniqueness["uniqueness"];
} | Group): {
    readonly name: string;
} & CoMap (+1 overload)
create
(
{ name: stringname: "Rex" }, const privateGroup: GroupprivateGroup, ), // We don't have access to Rex }, const publicGroup: GrouppublicGroup, ), ], const publicGroup: GrouppublicGroup, ); const
const friends: (readonly (({
    readonly name: string;
    readonly dog: ({
        readonly name: string;
    } & CoMap) | null;
} & CoMap & {
    readonly dog: {
        readonly name: string;
    } & CoMap;
}) | null)[] & CoListInstanceCoValuesNullable<...>) | null
friends
= await import coco.
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
list
(
const Person: co.Map<{
    name: z.z.ZodString;
    dog: co.Map<{
        name: z.z.ZodString;
    }, unknown, Account | Group>;
}, unknown, Account | Group>
Person
).
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<...>
load
(
const source: CoListInstance<co.Map<{
    name: z.z.ZodString;
    dog: co.Map<{
        name: z.z.ZodString;
    }, unknown, Account | Group>;
}, unknown, Account | Group>>
source
.
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>>>
$jazz
.CoListJazzApi<CoListInstance<CoMapSchema<{ name: ZodString; dog: CoMapSchema<{ name: ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>>.id: string
The ID of this `CoList`
@categoryContent
id
, {
resolve?: RefsToResolve<CoListInstanceCoValuesNullable<co.Map<{
    name: z.z.ZodString;
    dog: co.Map<{
        name: z.z.ZodString;
    }, unknown, Account | Group>;
}, unknown, Account | Group>>, 10, []> | undefined
resolve
: {
$each?: RefsToResolve<{
    readonly name: string;
    readonly dog: ({
        readonly name: string;
    } & CoMap) | null;
} & CoMap, 10, [0]> | undefined
$each
: {
dog?: RefsToResolve<{
    readonly name: string;
} & CoMap, 10, [0, 0]> | undefined
dog
: true, $onError?: null | undefined$onError: null }
}, loadAs?: Account | AnonymousJazzAgent | undefinedloadAs:
const me: Account | ({
    readonly [x: string]: any;
} & Account)
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 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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(
const friends: (readonly (({
    readonly name: string;
    readonly dog: ({
        readonly name: string;
    } & CoMap) | null;
} & CoMap & {
    readonly dog: {
        readonly name: string;
    } & CoMap;
}) | null)[] & CoListInstanceCoValuesNullable<...>) | null
friends
?.[0]); // null

We can actually use $onError everywhere in the resolve query, so we can use it to catch the error on dog:

const 
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
friends
= await import coco.
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
list
(
const Person: co.Map<{
    name: z.z.ZodString;
    dog: co.Map<{
        name: z.z.ZodString;
    }, unknown, Account | Group>;
}, unknown, Account | Group>
Person
).
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<...>
load
(
const source: CoListInstance<co.Map<{
    name: z.z.ZodString;
    dog: co.Map<{
        name: z.z.ZodString;
    }, unknown, Account | Group>;
}, unknown, Account | Group>>
source
.
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>>>
$jazz
.CoListJazzApi<CoListInstance<CoMapSchema<{ name: ZodString; dog: CoMapSchema<{ name: ZodString; }, unknown, Account | Group>; }, unknown, Account | Group>>>.id: string
The ID of this `CoList`
@categoryContent
id
, {
resolve?: RefsToResolve<CoListInstanceCoValuesNullable<co.Map<{
    name: z.z.ZodString;
    dog: co.Map<{
        name: z.z.ZodString;
    }, unknown, Account | Group>;
}, unknown, Account | Group>>, 10, []> | undefined
resolve
: {
$each?: RefsToResolve<{
    readonly name: string;
    readonly dog: ({
        readonly name: string;
    } & CoMap) | null;
} & CoMap, 10, [0]> | undefined
$each
: {
dog?: RefsToResolve<{
    readonly name: string;
} & CoMap, 10, [0, 0]> | undefined
dog
: { $onError?: null | undefined$onError: null } }
}, loadAs?: Account | AnonymousJazzAgent | undefinedloadAs:
const me: Account | ({
    readonly [x: string]: any;
} & Account)
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 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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(
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
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 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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
console
.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(
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
friends
?.[0]?.
dog: ({
    readonly name: string;
} & CoMap & {}) | null | undefined
dog
); // => null

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 
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
ProjectWithTasks
= import coco.
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
loaded
<
typeof
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>
Project
,
{
tasks: {
    $each: true;
}
tasks
: { $each: true$each: true };
} >; // Component that expects a fully loaded project function
function TaskList({ project }: {
    project: ProjectWithTasks;
}): React.JSX.Element
TaskList
({
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, []>
project
:
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
ProjectWithTasks
}) {
// TypeScript knows tasks are loaded, so this is type-safe return ( <React.JSX.IntrinsicElements.ul: React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>ul> {
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
.
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<...>
tasks
.
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.
@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
map
((
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
task
) => (
<React.JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>li React.Attributes.key?: React.Key | null | undefinedkey={
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
task
.
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`
@categoryContent
id
}>{
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
task
.title: stringtitle}</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 type
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
FullyLoadedProject
= import coco.
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
loaded
<
typeof
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>
Project
,
{
tasks: {
    $each: {
        subtasks: true;
        assignee: true;
    };
}
tasks
: {
$each: {
    subtasks: true;
    assignee: true;
}
$each
: {
subtasks: truesubtasks: true; assignee: trueassignee: true; }; }; owner: trueowner: true; } >; // Function that requires deeply loaded data function function processProject(project: FullyLoadedProject): voidprocessProject(
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
:
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
FullyLoadedProject
) {
// Safe access to all loaded properties 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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
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: 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
.name: stringname} owned by ${
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
.
owner: {
    readonly name: string;
} & CoMap
owner
.name: stringname}`);
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
.
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<...>
tasks
.
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.
@paramcallbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
forEach
((
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 & {
    ...;
}
task
) => {
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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
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: {
    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 & {
    ...;
}
task
.title: stringtitle}, Assigned to: ${
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 & {
    ...;
}
task
.
assignee: ({
    readonly name: string;
} & CoMap) | undefined
assignee
?.name: string | undefinedname}`);
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 ```
@see[source](https://github.com/nodejs/node/blob/v20.11.1/lib/console.js)
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: {
    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 & {
    ...;
}
task
.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: stringprojectId: string) {
  // Ensure the project is 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
project
= await
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>
Project
.
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<...>
load
(projectId: stringprojectId, {
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
resolve
: true });
if (!
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
) return;
// Ensure tasks are loaded const
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, []>
loadedProject
= 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
project
.
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.
@categorySubscription & Loading
ensureLoaded
({
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, []>
resolve
: {
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
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
$each
: true,
}, }, }); // Now we can safely access and modify tasks
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, []>
loadedProject
.
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>
tasks
.
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.
@paramcallbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
forEach
((
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
task
.
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 CoMap
@paramkey The key to set@paramvalue The value to set@categoryContent
set
("status", "completed");
}); }

Best Practices

  1. Be explicit about resolution depths: Always specify exactly what you need
  2. Use framework integrations: They handle subscription lifecycle automatically
  3. Clean up subscriptions: Always store and call the unsubscribe function when you're done
  4. Handle all loading states: Check for undefined (loading), null (not found), and success states
  5. Use the co.loaded type: Add compile-time type safety for components that require specific resolution patterns