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().

const 
const Task: CoMapSchema<{
    title: z.z.ZodString;
    description: z.z.ZodString;
    status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">;
    assignedTo: z.ZodOptional<z.z.ZodString>;
}>
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: {
    title: z.z.ZodString;
    description: z.z.ZodString;
    status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">;
    assignedTo: z.ZodOptional<z.z.ZodString>;
}): CoMapSchema<...>
export map
map
({
title: z.z.ZodStringtitle: import zz.
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString
export string
string
(),
description: z.z.ZodStringdescription: import zz.
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString
export string
string
(),
status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">status: import zz.
literal<["todo", "in-progress", "completed"]>(value: ["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
export string
string
()),
}); // ... // Subscribe to a Task by ID const const unsubscribe: () => voidunsubscribe =
const Task: CoMapSchema<{
    title: z.z.ZodString;
    description: z.z.ZodString;
    status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">;
    assignedTo: z.ZodOptional<z.z.ZodString>;
}>
Task
.
subscribe<true>(id: string, options: SubscribeListenerOptions<{
    title: string;
    description: string;
    status: "todo" | "in-progress" | "completed";
    assignedTo: string | undefined;
} & CoMap, true>, listener: (value: {
    title: string;
    description: string;
    status: "todo" | "in-progress" | "completed";
    assignedTo: string | undefined;
} & CoMap, unsubscribe: () => void) => void): () => void
subscribe
(const taskId: "co_123"taskId, {}, (
updatedTask: {
    title: string;
    description: string;
    status: "todo" | "in-progress" | "completed";
    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 (+1 overload)
Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args) for more information.
@sincev0.1.100
log
("Task updated:",
updatedTask: {
    title: string;
    description: string;
    status: "todo" | "in-progress" | "completed";
    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 (+1 overload)
Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args) for more information.
@sincev0.1.100
log
("New status:",
updatedTask: {
    title: string;
    description: string;
    status: "todo" | "in-progress" | "completed";
    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 subscribe method.

const 
const task: {
    title: string;
    description: string;
    status: "todo" | "in-progress" | "completed";
    assignedTo: string | undefined;
} & CoMap
task
=
const Task: CoMapSchema<{
    title: z.z.ZodString;
    description: z.z.ZodString;
    status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">;
    assignedTo: z.ZodOptional<z.z.ZodString>;
}>
Task
.
create: (init: {
    assignedTo?: string | undefined;
    title: string;
    description: string;
    status: NonNullable<"todo" | "in-progress" | "completed">;
}, options?: Account | Group | {
    ...;
} | undefined) => {
    ...;
} & CoMap
create
({
title: stringtitle: "Cut the grass", ...const otherProps: anyotherProps }); const const unsubscribe: () => voidunsubscribe =
const task: {
    title: string;
    description: string;
    status: "todo" | "in-progress" | "completed";
    assignedTo: string | undefined;
} & CoMap
task
.
CoMap.subscribe<{
    title: string;
    description: string;
    status: "todo" | "in-progress" | "completed";
    assignedTo: string | undefined;
} & CoMap, true>(this: {
    title: string;
    description: string;
    status: "todo" | "in-progress" | "completed";
    assignedTo: string | undefined;
} & CoMap, listener: (value: {
    title: string;
    description: string;
    status: "todo" | "in-progress" | "completed";
    assignedTo: string | undefined;
} & 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: {
    title: string;
    description: string;
    status: "todo" | "in-progress" | "completed";
    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 (+1 overload)
Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args) for more information.
@sincev0.1.100
log
("Task updated:",
updatedTask: {
    title: string;
    description: string;
    status: "todo" | "in-progress" | "completed";
    assignedTo: string | undefined;
} & CoMap
updatedTask
.title: stringtitle);
}); // Clean up when you're done const unsubscribe: () => voidunsubscribe();

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: CoMapSchema<{
    title: z.z.ZodString;
}>
Task
.
subscribe<true>(id: string, options: SubscribeListenerOptions<{
    title: string;
} & CoMap, true>, listener: (value: {
    title: string;
} & CoMap, unsubscribe: () => void) => void): () => void
subscribe
(const taskId: "co_123"taskId, {}, (
task: {
    title: string;
} & CoMap
task
: import coco.
type loaded<T extends CoValueClass | AnyCoSchema, R extends ResolveQuery<T> = true> = R extends boolean | undefined ? NonNullable<InstanceOfSchemaCoValuesNullable<T>> : [NonNullable<InstanceOfSchemaCoValuesNullable<T>>] extends [...] ? Exclude<...> extends CoValue ? R extends {
    ...;
} ? ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends {
    ...;
} ? ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends {
    ...;
} ? ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends {
    ...;
} ? ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends {
    ...;
} ? ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends {
    ...;
} ? ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends {
    ...;
} ? ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends {
    ...;
} ? ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...
export loaded
loaded
<typeof
const Task: CoMapSchema<{
    title: z.z.ZodString;
}>
Task
>) => {
if (
task: {
    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 (+1 overload)
Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args) for more information.
@sincev0.1.100
log
("Task is loading...");
} else if (
task: {
    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 (+1 overload)
Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args) for more information.
@sincev0.1.100
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 (+1 overload)
Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args) for more information.
@sincev0.1.100
log
("Task loaded:",
task: {
    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: CoMapSchema<{
    name: z.z.ZodString;
}>
TeamMember
= import coco.
map<{
    name: z.z.ZodString;
}>(shape: {
    name: z.z.ZodString;
}): CoMapSchema<{
    name: z.z.ZodString;
}>
export map
map
({
name: z.z.ZodStringname: import zz.
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString
export string
string
(),
}); const
const Task: CoMapSchema<{
    title: z.z.ZodString;
    assignee: z.ZodOptional<CoMapSchema<{
        name: z.z.ZodString;
    }>>;
    readonly subtasks: CoListSchema<typeof Task>;
}>
Task
= import coco.
map<{
    title: z.z.ZodString;
    assignee: z.ZodOptional<CoMapSchema<{
        name: z.z.ZodString;
    }>>;
    readonly subtasks: CoListSchema<typeof Task>;
}>(shape: {
    title: z.z.ZodString;
    assignee: z.ZodOptional<CoMapSchema<{
        name: z.z.ZodString;
    }>>;
    readonly subtasks: CoListSchema<typeof Task>;
}): CoMapSchema<...>
export map
map
({
title: z.z.ZodStringtitle: import zz.
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString
export string
string
(),
assignee: z.ZodOptional<CoMapSchema<{
    name: z.z.ZodString;
}>>
assignee
: import zz.
optional<CoMapSchema<{
    name: z.z.ZodString;
}>>(innerType: CoMapSchema<{
    name: z.z.ZodString;
}>): z.ZodOptional<CoMapSchema<{
    name: z.z.ZodString;
}>>
export optional
optional
(
const TeamMember: CoMapSchema<{
    name: z.z.ZodString;
}>
TeamMember
),
get
subtasks: CoListSchema<CoMapSchema<{
    title: z.z.ZodString;
    assignee: z.ZodOptional<CoMapSchema<{
        name: z.z.ZodString;
    }>>;
    readonly subtasks: CoListSchema<typeof Task>;
}>>
subtasks
():
type CoListSchema<T extends z.core.$ZodType> = z.z.core.$ZodArray<T> & {
    collaborative: true;
    create: (items: CoListInit<T>, options?: {
        owner: Account | Group;
    } | Account | Group) => CoList<InstanceOrPrimitiveOfSchema<T>>;
    load<const R extends RefsToResolve<CoListInstanceCoValuesNullable<T>> = true>(id: string, options?: {
        resolve?: RefsToResolveStrict<CoListInstanceCoValuesNullable<T>, R>;
        loadAs?: Account | AnonymousJazzAgent;
    }): Promise<Resolved<CoListInstanceCoValuesNullable<T>, R> | null>;
    subscribe<const R extends RefsToResolve<CoListInstanceCoValuesNullable<T>> = true>(id: string, options: SubscribeListenerOptions<CoListInstanceCoValuesNullable<T>, R>, listener: (value: Resolved<CoListInstanceCoValuesNullable<T>, R>, unsubscribe: () => void) => void): () => void;
    withHelpers<S extends z.z.core.$ZodType, T extends object>(this: S, helpers: (Self: S) => T): WithHelpers<S, T>;
}
CoListSchema
<typeof
const Task: CoMapSchema<{
    title: z.z.ZodString;
    assignee: z.ZodOptional<CoMapSchema<{
        name: z.z.ZodString;
    }>>;
    readonly subtasks: CoListSchema<typeof Task>;
}>
Task
> { return import coco.
list<CoMapSchema<{
    title: z.z.ZodString;
    assignee: z.ZodOptional<CoMapSchema<{
        name: z.z.ZodString;
    }>>;
    readonly subtasks: CoListSchema<typeof Task>;
}>>(element: CoMapSchema<...>): CoListSchema<...>
export list
list
(
const Task: CoMapSchema<{
    title: z.z.ZodString;
    assignee: z.ZodOptional<CoMapSchema<{
        name: z.z.ZodString;
    }>>;
    readonly subtasks: CoListSchema<typeof Task>;
}>
Task
) },
}); const
const Project: CoMapSchema<{
    name: z.z.ZodString;
    tasks: CoListSchema<CoMapSchema<{
        title: z.z.ZodString;
        assignee: z.ZodOptional<CoMapSchema<{
            name: z.z.ZodString;
        }>>;
        readonly subtasks: CoListSchema<typeof Task>;
    }>>;
    owner: CoMapSchema<...>;
}>
Project
= import coco.
map<{
    name: z.z.ZodString;
    tasks: CoListSchema<CoMapSchema<{
        title: z.z.ZodString;
        assignee: z.ZodOptional<CoMapSchema<{
            name: z.z.ZodString;
        }>>;
        readonly subtasks: CoListSchema<typeof Task>;
    }>>;
    owner: CoMapSchema<...>;
}>(shape: {
    name: z.z.ZodString;
    tasks: CoListSchema<CoMapSchema<{
        title: z.z.ZodString;
        assignee: z.ZodOptional<CoMapSchema<{
            name: z.z.ZodString;
        }>>;
        readonly subtasks: CoListSchema<typeof Task>;
    }>>;
    owner: CoMapSchema<...>;
}): CoMapSchema<...>
export map
map
({
name: z.z.ZodStringname: import zz.
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString
export string
string
(),
tasks: CoListSchema<CoMapSchema<{
    title: z.z.ZodString;
    assignee: z.ZodOptional<CoMapSchema<{
        name: z.z.ZodString;
    }>>;
    readonly subtasks: CoListSchema<typeof Task>;
}>>
tasks
: import coco.
list<CoMapSchema<{
    title: z.z.ZodString;
    assignee: z.ZodOptional<CoMapSchema<{
        name: z.z.ZodString;
    }>>;
    readonly subtasks: CoListSchema<typeof Task>;
}>>(element: CoMapSchema<...>): CoListSchema<...>
export list
list
(
const Task: CoMapSchema<{
    title: z.z.ZodString;
    assignee: z.ZodOptional<CoMapSchema<{
        name: z.z.ZodString;
    }>>;
    readonly subtasks: CoListSchema<typeof Task>;
}>
Task
),
owner: CoMapSchema<{
    name: z.z.ZodString;
}>
owner
:
const TeamMember: CoMapSchema<{
    name: z.z.ZodString;
}>
TeamMember
,
}); // Load just the project, not its references const
const project: ({
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap) | null
project
= await
const Project: CoMapSchema<{
    name: z.z.ZodString;
    tasks: CoListSchema<CoMapSchema<{
        title: z.z.ZodString;
        assignee: z.ZodOptional<CoMapSchema<{
            name: z.z.ZodString;
        }>>;
        readonly subtasks: CoListSchema<typeof Task>;
    }>>;
    owner: CoMapSchema<...>;
}>
Project
.
load<true>(id: string, options?: {
    resolve?: RefsToResolve<{
        name: string;
        tasks: CoList<({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap) | null> | null;
        owner: ({
            name: string;
        } & CoMap) | null;
    } & CoMap, 10, []> | undefined;
    loadAs?: Account | AnonymousJazzAgent;
} | undefined): Promise<...>
load
(const projectId: "co_123"projectId);
if (!
const project: ({
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        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: {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap
project
.name: stringname;
// undefined | null | ListOfTasks - non-requested references might not be loaded, or inaccessible
const project: {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap
project
.
tasks: CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null> | null
tasks
;
// Load the project and shallowly load its list of tasks const
const projectWithTasksShallow: ({
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap) | null
projectWithTasksShallow
= await
const Project: CoMapSchema<{
    name: z.z.ZodString;
    tasks: CoListSchema<CoMapSchema<{
        title: z.z.ZodString;
        assignee: z.ZodOptional<CoMapSchema<{
            name: z.z.ZodString;
        }>>;
        readonly subtasks: CoListSchema<typeof Task>;
    }>>;
    owner: CoMapSchema<...>;
}>
Project
.
load<{
    tasks: true;
}>(id: string, options?: {
    resolve?: RefsToResolve<{
        name: string;
        tasks: CoList<({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap) | null> | null;
        owner: ({
            name: string;
        } & CoMap) | null;
    } & CoMap, 10, []> | undefined;
    loadAs?: Account | AnonymousJazzAgent;
} | undefined): Promise<...>
load
(const projectId: "co_123"projectId, {
resolve?: RefsToResolve<{
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap, 10, []> | undefined
resolve
: {
tasks?: RefsToResolve<CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>, 10, [0]> | undefined
tasks
: true
} }); if (!
const projectWithTasksShallow: ({
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap) | 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: {
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap
projectWithTasksShallow
.
tasks: CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>
tasks
;
// number - length of the list
const projectWithTasksShallow: {
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap
projectWithTasksShallow
.
tasks: CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & 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: {
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap
projectWithTasksShallow
.
tasks: CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>
tasks
[0];
// Load the project and its tasks const
const projectWithTasks: ({
    tasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap)[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap) | null
projectWithTasks
= await
const Project: CoMapSchema<{
    name: z.z.ZodString;
    tasks: CoListSchema<CoMapSchema<{
        title: z.z.ZodString;
        assignee: z.ZodOptional<CoMapSchema<{
            name: z.z.ZodString;
        }>>;
        readonly subtasks: CoListSchema<typeof Task>;
    }>>;
    owner: CoMapSchema<...>;
}>
Project
.
load<{
    tasks: {
        $each: true;
    };
}>(id: string, options?: {
    resolve?: RefsToResolve<{
        name: string;
        tasks: CoList<({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap) | null> | null;
        owner: ({
            name: string;
        } & CoMap) | null;
    } & CoMap, 10, []> | undefined;
    loadAs?: Account | AnonymousJazzAgent;
} | undefined): Promise<...>
load
(const projectId: "co_123"projectId, {
resolve?: RefsToResolve<{
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap, 10, []> | undefined
resolve
: {
tasks?: RefsToResolve<CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>, 10, [0]> | undefined
tasks
: {
$each: RefsToResolve<{
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap, 10, [0, 0]>
$each
: true
} } }); if (!
const projectWithTasks: ({
    tasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap)[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap) | 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: {
    tasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap)[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap
projectWithTasks
.
tasks: ({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap)[] & CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>
tasks
;
// Task - fully loaded
const projectWithTasks: {
    tasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap)[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap
projectWithTasks
.
tasks: ({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap)[] & CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>
tasks
[0];
// string - primitive fields are always loaded
const projectWithTasks: {
    tasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap)[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap
projectWithTasks
.
tasks: ({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap)[] & CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>
tasks
[0].title: stringtitle;
// undefined | null | ListOfTasks - subtasks might not be loaded, or inaccessible
const projectWithTasks: {
    tasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap)[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap
projectWithTasks
.
tasks: ({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap)[] & CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>
tasks
[0].
subtasks: CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null> | null
subtasks
;
// Load the project, its tasks, and their subtasks const
const projectDeep: ({
    tasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap & {
        subtasks: ({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap)[] & CoList<({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap) | null>;
        assignee: ({
            name: string;
        } & CoMap) | undefined;
    })[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap) | null
projectDeep
= await
const Project: CoMapSchema<{
    name: z.z.ZodString;
    tasks: CoListSchema<CoMapSchema<{
        title: z.z.ZodString;
        assignee: z.ZodOptional<CoMapSchema<{
            name: z.z.ZodString;
        }>>;
        readonly subtasks: CoListSchema<typeof Task>;
    }>>;
    owner: CoMapSchema<...>;
}>
Project
.
load<{
    tasks: {
        $each: {
            subtasks: {
                $each: true;
            };
            assignee: true;
        };
    };
}>(id: string, options?: {
    resolve?: RefsToResolve<{
        name: string;
        tasks: CoList<({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap) | null> | null;
        owner: ({
            name: string;
        } & CoMap) | null;
    } & CoMap, 10, []> | undefined;
    loadAs?: Account | AnonymousJazzAgent;
} | undefined): Promise<...>
load
(const projectId: "co_123"projectId, {
resolve?: RefsToResolve<{
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap, 10, []> | undefined
resolve
: {
tasks?: RefsToResolve<CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>, 10, [0]> | undefined
tasks
: {
$each: RefsToResolve<{
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap, 10, [0, 0]>
$each
: {
subtasks?: RefsToResolve<CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>, 10, [0, 0, 0]> | undefined
subtasks
: {
$each: RefsToResolve<{
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap, 10, [0, 0, 0, 0]>
$each
: true
},
assignee?: RefsToResolve<{
    name: string;
} & CoMap, 10, [0, 0, 0]> | undefined
assignee
: true
} } } }); if (!
const projectDeep: ({
    tasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap & {
        subtasks: ({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap)[] & CoList<({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap) | null>;
        assignee: ({
            name: string;
        } & CoMap) | undefined;
    })[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap) | 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: {
    tasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap & {
        subtasks: ({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap)[] & CoList<({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap) | null>;
        assignee: ({
            name: string;
        } & CoMap) | undefined;
    })[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap
projectDeep
.
tasks: ({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap & {
    subtasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap)[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
    assignee: ({
        name: string;
    } & CoMap) | undefined;
})[] & CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>
tasks
[0].
subtasks: CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null> & ({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & 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: {
    tasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap & {
        subtasks: ({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap)[] & CoList<({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap) | null>;
        assignee: ({
            name: string;
        } & CoMap) | undefined;
    })[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap
projectDeep
.
tasks: ({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap & {
    subtasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap)[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
    assignee: ({
        name: string;
    } & CoMap) | undefined;
})[] & CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>
tasks
[0].
assignee: ({
    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: ({
    assignee: ({
        name: string;
    } & CoMap) | undefined;
} & {
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null
task
= await
const Task: CoMapSchema<{
    title: z.z.ZodString;
    assignee: z.ZodOptional<CoMapSchema<{
        name: z.z.ZodString;
    }>>;
    readonly subtasks: CoListSchema<typeof Task>;
}>
Task
.
load<{
    assignee: true;
}>(id: string, options?: {
    resolve?: RefsToResolve<{
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap, 10, []> | undefined;
    loadAs?: Account | AnonymousJazzAgent;
} | undefined): Promise<...>
load
(const taskId: "co_123"taskId, {
resolve?: RefsToResolve<{
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap, 10, []> | undefined
resolve
: {
assignee?: RefsToResolve<{
    name: string;
} & CoMap, 10, [0]> | undefined
assignee
: true }
});
const task: ({
    assignee: ({
        name: string;
    } & CoMap) | undefined;
} & {
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | 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: ({
    tasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap)[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    ...;
} & CoMap) | null
project
= await
const Project: CoMapSchema<{
    name: z.z.ZodString;
    tasks: CoListSchema<CoMapSchema<{
        title: z.z.ZodString;
        assignee: z.ZodOptional<CoMapSchema<{
            name: z.z.ZodString;
        }>>;
        readonly subtasks: CoListSchema<typeof Task>;
    }>>;
    owner: CoMapSchema<...>;
}>
Project
.
load<{
    tasks: {
        $each: true;
    };
}>(id: string, options?: {
    resolve?: RefsToResolve<{
        name: string;
        tasks: CoList<({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap) | null> | null;
        owner: ({
            name: string;
        } & CoMap) | null;
    } & CoMap, 10, []> | undefined;
    loadAs?: Account | AnonymousJazzAgent;
} | undefined): Promise<...>
load
(const projectId: "co_123"projectId, {
resolve?: RefsToResolve<{
    ...;
} & CoMap, 10, []> | undefined
resolve
: {
tasks?: RefsToResolve<CoList<({
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>, 10, [0]> | undefined
tasks
: {
$each: RefsToResolve<{
    title: string;
    assignee: ({
        name: string;
    } & CoMap) | null | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap, 10, [0, 0]>
$each
: true } }
});
const project: ({
    tasks: ({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap)[] & CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    ...;
} & CoMap) | 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: ({
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap) | null
project
= await
const Project: CoMapSchema<{
    name: z.z.ZodString;
    tasks: CoListSchema<CoMapSchema<{
        title: z.z.ZodString;
        assignee: z.ZodOptional<CoMapSchema<{
            name: z.z.ZodString;
        }>>;
        readonly subtasks: CoListSchema<typeof Task>;
    }>>;
    owner: CoMapSchema<...>;
}>
Project
.
load<true>(id: string, options?: {
    resolve?: RefsToResolve<{
        name: string;
        tasks: CoList<({
            title: string;
            assignee: ({
                name: string;
            } & CoMap) | null | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap) | null> | null;
        owner: ({
            name: string;
        } & CoMap) | null;
    } & CoMap, 10, []> | undefined;
    loadAs?: Account | AnonymousJazzAgent;
} | undefined): Promise<...>
load
(const projectId: "co_123"projectId, {
resolve?: RefsToResolve<{
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap, 10, []> | undefined
resolve
: true
});
const project: ({
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap) | null
project
// => Project
// The user doesn't have access to the owner
const project: ({
    name: string;
    tasks: CoList<({
        title: string;
        assignee: ({
            name: string;
        } & CoMap) | null | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        name: string;
    } & CoMap) | null;
} & CoMap) | null
project
?.
owner: ({
    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: CoList<{
    name: string;
} & CoMap>
source
= import coco.
list<CoMapSchema<{
    name: z.z.ZodString;
}>>(element: CoMapSchema<{
    name: z.z.ZodString;
}>): CoListSchema<CoMapSchema<{
    name: z.z.ZodString;
}>>
export list
list
(
const Person: CoMapSchema<{
    name: z.z.ZodString;
}>
Person
).
create: (items: CoListInit<CoMapSchema<{
    name: z.z.ZodString;
}>>, options?: {
    owner: Account | Group;
} | Account | Group) => CoList<...>
create
(
[
const Person: CoMapSchema<{
    name: z.z.ZodString;
}>
Person
.
create: (init: {
    name: string;
}, options?: Account | Group | {
    owner: Account | Group;
    unique?: CoValueUniqueness["uniqueness"];
} | undefined) => {
    ...;
} & CoMap
create
(
{ name: stringname: "Jane", }, const privateGroup: GroupprivateGroup, // We don't have access to Jane ),
const Person: CoMapSchema<{
    name: z.z.ZodString;
}>
Person
.
create: (init: {
    name: string;
}, options?: Account | Group | {
    owner: Account | Group;
    unique?: CoValueUniqueness["uniqueness"];
} | undefined) => {
    ...;
} & CoMap
create
(
{ name: stringname: "Alice", }, const publicGroup: GrouppublicGroup, // We have access to Alice ), ], const publicGroup: GrouppublicGroup, ); const
const friends: ((({
    name: string;
} & CoMap & {
    $onError: never;
}) | null)[] & CoListInstanceCoValuesNullable<CoMapSchema<{
    name: z.z.ZodString;
}>>) | null
friends
= await import coco.
list<CoMapSchema<{
    name: z.z.ZodString;
}>>(element: CoMapSchema<{
    name: z.z.ZodString;
}>): CoListSchema<CoMapSchema<{
    name: z.z.ZodString;
}>>
export list
list
(
const Person: CoMapSchema<{
    name: z.z.ZodString;
}>
Person
).
load<{
    $each: {
        $onError: null;
    };
}>(id: string, options?: {
    resolve?: RefsToResolve<CoListInstanceCoValuesNullable<CoMapSchema<{
        name: z.z.ZodString;
    }>>, 10, []> | undefined;
    loadAs?: Account | AnonymousJazzAgent;
} | undefined): Promise<...>
load
(
const source: CoList<{
    name: string;
} & CoMap>
source
.CoList<{ name: string; } & CoMap>.id: string
The ID of this `CoList`
@categoryContent
id
, {
resolve?: RefsToResolve<CoListInstanceCoValuesNullable<CoMapSchema<{
    name: z.z.ZodString;
}>>, 10, []> | undefined
resolve
: {
$each: RefsToResolve<{
    name: string;
} & CoMap, 10, [0]>
$each
: { $onError?: null | undefined$onError: null }
}, loadAs?: Account | AnonymousJazzAgent | undefinedloadAs:
const me: Account | ({
    [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 (+1 overload)
Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args) for more information.
@sincev0.1.100
log
(
const friends: ((({
    name: string;
} & CoMap & {
    $onError: never;
}) | null)[] & CoListInstanceCoValuesNullable<CoMapSchema<{
    name: z.z.ZodString;
}>>) | 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 (+1 overload)
Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args) for more information.
@sincev0.1.100
log
(
const friends: ((({
    name: string;
} & CoMap & {
    $onError: never;
}) | null)[] & CoListInstanceCoValuesNullable<CoMapSchema<{
    name: z.z.ZodString;
}>>) | 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 (+1 overload)
Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args) for more information.
@sincev0.1.100
log
(
const friends: ((({
    name: string;
} & CoMap & {
    $onError: never;
}) | null)[] & CoListInstanceCoValuesNullable<CoMapSchema<{
    name: z.z.ZodString;
}>>) | null
friends
?.[1]); // Person

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

const 
const source: CoList<{
    name: string;
    dog: {
        name: string;
    } & CoMap;
} & CoMap>
source
= import coco.
list<CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<{
        name: z.z.ZodString;
    }>;
}>>(element: CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<{
        name: z.z.ZodString;
    }>;
}>): CoListSchema<...>
export list
list
(
const Person: CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<{
        name: z.z.ZodString;
    }>;
}>
Person
).
create: (items: CoListInit<CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<{
        name: z.z.ZodString;
    }>;
}>>, options?: {
    owner: Account | Group;
} | Account | Group) => CoList<...>
create
(
[
const Person: CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<{
        name: z.z.ZodString;
    }>;
}>
Person
.
create: (init: {
    name: string;
    dog: {
        name: string;
    } & CoMap;
}, options?: Account | Group | {
    owner: Account | Group;
    unique?: CoValueUniqueness["uniqueness"];
} | undefined) => {
    ...;
} & CoMap
create
(
{ name: stringname: "Jane",
dog: {
    name: string;
} & CoMap
dog
:
const Dog: CoMapSchema<{
    name: z.z.ZodString;
}>
Dog
.
create: (init: {
    name: string;
}, options?: Account | Group | {
    owner: Account | Group;
    unique?: CoValueUniqueness["uniqueness"];
} | undefined) => {
    ...;
} & CoMap
create
(
{ name: stringname: "Rex" }, const privateGroup: GroupprivateGroup, ), // We don't have access to Rex }, const publicGroup: GrouppublicGroup, ), ], const publicGroup: GrouppublicGroup, ); const
const friends: ((({
    name: string;
    dog: ({
        name: string;
    } & CoMap) | null;
} & CoMap & {
    dog: {
        name: string;
    } & CoMap;
    $onError: never;
}) | null)[] & CoListInstanceCoValuesNullable<CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<{
        name: z.z.ZodString;
    }>;
}>>) | null
friends
= await import coco.
list<CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<{
        name: z.z.ZodString;
    }>;
}>>(element: CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<{
        name: z.z.ZodString;
    }>;
}>): CoListSchema<...>
export list
list
(
const Person: CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<{
        name: z.z.ZodString;
    }>;
}>
Person
).
load<{
    $each: {
        dog: true;
        $onError: null;
    };
}>(id: string, options?: {
    resolve?: RefsToResolve<CoListInstanceCoValuesNullable<CoMapSchema<{
        name: z.z.ZodString;
        dog: CoMapSchema<{
            name: z.z.ZodString;
        }>;
    }>>, 10, []> | undefined;
    loadAs?: Account | AnonymousJazzAgent;
} | undefined): Promise<...>
load
(
const source: CoList<{
    name: string;
    dog: {
        name: string;
    } & CoMap;
} & CoMap>
source
.CoList<{ name: string; dog: { name: string; } & CoMap; } & CoMap>.id: string
The ID of this `CoList`
@categoryContent
id
, {
resolve?: RefsToResolve<CoListInstanceCoValuesNullable<CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<{
        name: z.z.ZodString;
    }>;
}>>, 10, []> | undefined
resolve
: {
$each: RefsToResolve<{
    name: string;
    dog: ({
        name: string;
    } & CoMap) | null;
} & CoMap, 10, [0]>
$each
: {
dog?: RefsToResolve<{
    name: string;
} & CoMap, 10, [0, 0]> | undefined
dog
: true, $onError?: null | undefined$onError: null }
}, loadAs?: Account | AnonymousJazzAgent | undefinedloadAs:
const me: Account | ({
    [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 (+1 overload)
Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args) for more information.
@sincev0.1.100
log
(
const friends: ((({
    name: string;
    dog: ({
        name: string;
    } & CoMap) | null;
} & CoMap & {
    dog: {
        name: string;
    } & CoMap;
    $onError: never;
}) | null)[] & CoListInstanceCoValuesNullable<CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<{
        name: z.z.ZodString;
    }>;
}>>) | 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: (({
    name: string;
    dog: ({
        name: string;
    } & CoMap) | null;
} & CoMap & {
    dog: ({
        $onError: never;
    } & {
        name: string;
    } & CoMap) | null;
})[] & CoListInstanceCoValuesNullable<CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<...>;
}>>) | null
friends
= await import coco.
list<CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<{
        name: z.z.ZodString;
    }>;
}>>(element: CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<{
        name: z.z.ZodString;
    }>;
}>): CoListSchema<...>
export list
list
(
const Person: CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<...>;
}>
Person
).
load<{
    $each: {
        dog: {
            $onError: null;
        };
    };
}>(id: string, options?: {
    resolve?: RefsToResolve<CoListInstanceCoValuesNullable<CoMapSchema<{
        name: z.z.ZodString;
        dog: CoMapSchema<{
            name: z.z.ZodString;
        }>;
    }>>, 10, []> | undefined;
    loadAs?: Account | AnonymousJazzAgent;
} | undefined): Promise<...>
load
(
const source: CoList<{
    name: string;
    dog: {
        name: string;
    } & CoMap;
} & CoMap>
source
.CoList<{ name: string; dog: { name: string; } & CoMap; } & CoMap>.id: string
The ID of this `CoList`
@categoryContent
id
, {
resolve?: RefsToResolve<CoListInstanceCoValuesNullable<CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<...>;
}>>, 10, []> | undefined
resolve
: {
$each: RefsToResolve<{
    name: string;
    dog: ({
        name: string;
    } & CoMap) | null;
} & CoMap, 10, [0]>
$each
: {
dog?: RefsToResolve<{
    name: string;
} & CoMap, 10, [0, 0]> | undefined
dog
: { $onError?: null | undefined$onError: null } }
}, loadAs?: Account | AnonymousJazzAgent | undefinedloadAs:
const me: Account | ({
    [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 (+1 overload)
Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args) for more information.
@sincev0.1.100
log
(
const friends: (({
    name: string;
    dog: ({
        name: string;
    } & CoMap) | null;
} & CoMap & {
    dog: ({
        $onError: never;
    } & {
        name: string;
    } & CoMap) | null;
})[] & CoListInstanceCoValuesNullable<CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<...>;
}>>) | 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 (+1 overload)
Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v20.x/api/util.html#utilformatformat-args) for more information.
@sincev0.1.100
log
(
const friends: (({
    name: string;
    dog: ({
        name: string;
    } & CoMap) | null;
} & CoMap & {
    dog: ({
        $onError: never;
    } & {
        name: string;
    } & CoMap) | null;
})[] & CoListInstanceCoValuesNullable<CoMapSchema<{
    name: z.z.ZodString;
    dog: CoMapSchema<...>;
}>>) | null
friends
?.[0]?.
dog: ({
    name: string;
} & CoMap & {
    $onError: never;
}) | 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:

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 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: ({
    name: string;
    tasks: CoList<({
        title: string;
        status: "todo" | "in-progress" | "completed";
        assignee: string | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        ...;
    } & CoMap) | null;
} & CoMap) | null
project
= await
const Project: CoMapSchema<{
    name: z.z.ZodString;
    tasks: CoListSchema<CoMapSchema<{
        title: z.z.ZodString;
        status: z.z.ZodLiteral<"todo" | "in-progress" | "completed">;
        assignee: z.ZodOptional<z.z.ZodString>;
        readonly subtasks: CoListSchema<typeof Task>;
    }>>;
    owner: CoMapSchema<...>;
}>
Project
.
load<true>(id: string, options?: {
    resolve?: RefsToResolve<{
        name: string;
        tasks: CoList<({
            title: string;
            status: "todo" | "in-progress" | "completed";
            assignee: string | undefined;
            subtasks: CoListSchema<typeof Task>;
        } & CoMap) | null> | null;
        owner: ({
            ...;
        } & CoMap) | null;
    } & CoMap, 10, []> | undefined;
    loadAs?: Account | AnonymousJazzAgent;
} | undefined): Promise<...>
load
(projectId: stringprojectId, {
resolve?: RefsToResolve<{
    name: string;
    tasks: CoList<({
        title: string;
        status: "todo" | "in-progress" | "completed";
        assignee: string | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        ...;
    } & CoMap) | null;
} & CoMap, 10, []> | undefined
resolve
: true });
if (!
const project: ({
    name: string;
    tasks: CoList<({
        title: string;
        status: "todo" | "in-progress" | "completed";
        assignee: string | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        ...;
    } & CoMap) | null;
} & CoMap) | null
project
) return;
// Ensure tasks are loaded const
const loadedProject: {
    tasks: ({
        title: string;
        status: "todo" | "in-progress" | "completed";
        assignee: string | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap)[] & CoList<({
        title: string;
        status: "todo" | "in-progress" | "completed";
        assignee: string | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        status: "todo" | "in-progress" | "completed";
        assignee: string | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        ...;
    } & CoMap) | null;
} & CoMap
loadedProject
= await
const project: {
    name: string;
    tasks: CoList<({
        title: string;
        status: "todo" | "in-progress" | "completed";
        assignee: string | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        ...;
    } & CoMap) | null;
} & CoMap
project
.
CoMap.ensureLoaded<{
    name: string;
    tasks: CoList<({
        title: string;
        status: "todo" | "in-progress" | "completed";
        assignee: string | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        ...;
    } & CoMap) | null;
} & CoMap, {
    ...;
}>(this: {
    name: string;
    tasks: CoList<({
        title: string;
        status: "todo" | "in-progress" | "completed";
        assignee: string | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        ...;
    } & CoMap) | null;
} & CoMap, 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<{
    name: string;
    tasks: CoList<({
        title: string;
        status: "todo" | "in-progress" | "completed";
        assignee: string | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        ...;
    } & CoMap) | null;
} & CoMap, 10, []>
resolve
: {
tasks?: RefsToResolve<CoList<({
    title: string;
    status: "todo" | "in-progress" | "completed";
    assignee: string | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>, 10, [...]> | undefined
tasks
: {
$each: RefsToResolve<{
    title: string;
    status: "todo" | "in-progress" | "completed";
    assignee: string | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap, 10, [0, 0]>
$each
: true,
}, }, }); // Now we can safely access and modify tasks
const loadedProject: {
    tasks: ({
        title: string;
        status: "todo" | "in-progress" | "completed";
        assignee: string | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap)[] & CoList<({
        title: string;
        status: "todo" | "in-progress" | "completed";
        assignee: string | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null>;
} & {
    name: string;
    tasks: CoList<({
        title: string;
        status: "todo" | "in-progress" | "completed";
        assignee: string | undefined;
        subtasks: CoListSchema<typeof Task>;
    } & CoMap) | null> | null;
    owner: ({
        ...;
    } & CoMap) | null;
} & CoMap
loadedProject
.
tasks: ({
    title: string;
    status: "todo" | "in-progress" | "completed";
    assignee: string | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap)[] & CoList<({
    title: string;
    status: "todo" | "in-progress" | "completed";
    assignee: string | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap) | null>
tasks
.
Array<T>.forEach(callbackfn: (value: {
    title: string;
    status: "todo" | "in-progress" | "completed";
    assignee: string | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap, index: number, array: ({
    title: string;
    status: "todo" | "in-progress" | "completed";
    assignee: string | undefined;
    subtasks: CoListSchema<typeof Task>;
} & 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: {
    title: string;
    status: "todo" | "in-progress" | "completed";
    assignee: string | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap
task
) => {
task: {
    title: string;
    status: "todo" | "in-progress" | "completed";
    assignee: string | undefined;
    subtasks: CoListSchema<typeof Task>;
} & CoMap
task
.status: "todo" | "in-progress" | "completed"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