CoLists
CoLists are ordered collections that work like JavaScript arrays. They provide indexed access, iteration methods, and length properties, making them perfect for managing sequences of items.
Creating CoLists
CoLists are defined by specifying the type of items they contain:
import {
import co
co,import z
z } from "jazz-tools"; constconst ListOfResources: CoListSchema<z.z.ZodString>
ListOfResources =import co
co.list(
list<z.z.ZodString>(element: z.z.ZodString): CoListSchema<z.z.ZodString> export list
import z
z.string()); const
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString export string
ListOfTasks =
const ListOfTasks: CoListSchema<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>>
import co
co.list(
list<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>>(element: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>): CoListSchema<...> export list
Task);
const Task: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>
To create a CoList
:
// Create an empty list const
const resources: CoList<string>
resources =import co
co.list(
list<z.z.ZodString>(element: z.z.ZodString): CoListSchema<z.z.ZodString> export list
import z
z.string()).
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString export string
create([]); // Create a list with initial items const
create: (items: CoListInit<z.z.ZodString>, options?: { owner: Account | Group; } | Account | Group) => CoList<...>
tasks =
const tasks: CoList<{ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap>
import co
co.list(
list<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>>(element: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>): CoListSchema<...> export list
Task).
const Task: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>
create([
create: (items: CoListInit<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>>, options?: { owner: Account | Group; } | Account | Group) => CoList<...>
Task.
const Task: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>
create({
create: (init: { title: string; status: NonNullable<"todo" | "in-progress" | "complete">; }, options?: Account | Group | { owner: Account | Group; unique?: CoValueUniqueness["uniqueness"]; } | undefined) => { ...; } & CoMap
title: string
title: "Prepare soil beds",status: NonNullable<"todo" | "in-progress" | "complete">
status: "in-progress" }),Task.
const Task: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>
create({
create: (init: { title: string; status: NonNullable<"todo" | "in-progress" | "complete">; }, options?: Account | Group | { owner: Account | Group; unique?: CoValueUniqueness["uniqueness"]; } | undefined) => { ...; } & CoMap
title: string
title: "Order compost",status: NonNullable<"todo" | "in-progress" | "complete">
status: "todo" }) ]);
Ownership
Like other CoValues, you can specify ownership when creating CoLists.
// Create with shared ownership const
const teamGroup: Group
teamGroup =class Group
Group.create();
Group.create<Group>(this: CoValueClass<Group>, options?: { owner: Account; } | Account): Group
const teamGroup: Group
teamGroup.Group.addMember(member: Account, role: AccountRole): void (+1 overload)
addMember(colleagueAccount, "writer"); const
const colleagueAccount: Account | ({ [x: string]: any; } & Account)
teamList =
const teamList: CoList<{ title: string; status: string; } & CoMap>
import co
co.list(
list<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodString; }>>(element: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodString; }>): CoListSchema<CoMapSchema<...>> export list
Task).
const Task: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodString; }>
create([], {
create: (items: CoListInit<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodString; }>>, options?: { owner: Account | Group; } | Account | Group) => CoList<...>
owner: Group | Account
owner:const teamGroup: Group
teamGroup });
See Groups as permission scopes for more information on how to use groups to control access to CoLists.
Reading from CoLists
CoLists support standard array access patterns:
// Access by index const
firstTask =
const firstTask: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap
tasks[0];
const tasks: CoList<{ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap>
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+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.log(firstTask.
const firstTask: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap
title: string
title); // "Prepare soil beds" // Get list lengthvar console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+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.log(tasks.
const tasks: CoList<{ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap>
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); // 2 // Iterationtasks.
const tasks: CoList<{ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap>
Array<{ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap>.forEach(callbackfn: (value: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap, index: number, array: ({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap)[]) => void, thisArg?: any): void
Performs the specified action for each element in an array.forEach(task => {
task: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+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.log(task.
task: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap
title: string
title); // "Prepare soil beds" // "Order compost" }); // Array methods consttodoTasks =
const todoTasks: ({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap)[]
tasks.
const tasks: CoList<{ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap>
Array<{ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap>.filter(predicate: (value: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap, index: number, array: ({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap)[]) => unknown, thisArg?: any): ({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap)[] (+1 overload)
Returns the elements of an array that meet the condition specified in a callback function.filter(task =>
task: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap
task.
task: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap
status: "todo" | "in-progress" | "complete"
status === "todo");var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+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.log(todoTasks.
const todoTasks: ({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap)[]
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); // 1
Updating CoLists
Update CoList
s just like you would JavaScript arrays:
// Add items
const resources: CoList<string>
resources.CoList<string>.push(...items: string[]): number
Appends new elements to the end of an array, and returns the new length of the array.push("Tomatoes"); // Add to endconst resources: CoList<string>
resources.CoList<string>.unshift(...items: string[]): number
Inserts new elements at the start of an array, and returns the new length of the array.unshift("Lettuce"); // Add to beginningtasks.
const tasks: CoList<{ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap>
CoList<{ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap>.push(...items: ({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap)[]): number
Appends new elements to the end of an array, and returns the new length of the array.push(Task.
const Task: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>
create({ // Add complex items
create: (init: { title: string; status: NonNullable<"todo" | "in-progress" | "complete">; }, options?: Account | Group | { owner: Account | Group; unique?: CoValueUniqueness["uniqueness"]; } | undefined) => { ...; } & CoMap
title: string
title: "Install irrigation",status: NonNullable<"todo" | "in-progress" | "complete">
status: "todo" })); // Replace itemsconst resources: CoList<string>
resources[0] = "Cucumber"; // Replace by index // Modify nested itemstasks[0].
const tasks: CoList<{ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap>
status: "todo" | "in-progress" | "complete"
status = "complete"; // Update properties of references
Deleting Items
Remove specific items by index with splice
, or remove the first or last item with pop
or shift
:
// Remove 2 items starting at index 1
const resources: CoList<string>
resources.CoList<string>.splice(start: number, deleteCount: number, ...items: string[]): string[]
Splice the `CoList` at a given index.splice(1, 2);var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+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.log(const resources: CoList<string>
resources); // ["Cucumber", "Peppers"] // Remove a single item at index 0const resources: CoList<string>
resources.CoList<string>.splice(start: number, deleteCount: number, ...items: string[]): string[]
Splice the `CoList` at a given index.splice(0, 1);var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+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.log(const resources: CoList<string>
resources); // ["Peppers"] // Remove items constconst lastItem: string | undefined
lastItem =const resources: CoList<string>
resources.CoList<string>.pop(): string | undefined
Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified.pop(); // Remove and return last itemconst resources: CoList<string>
resources.CoList<string>.shift(): string | undefined
Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified.shift(); // Remove first item
Array Methods
CoList
s support the standard JavaScript array methods you already know:
// Add multiple items at once
const resources: CoList<string>
resources.CoList<string>.push(...items: string[]): number
Appends new elements to the end of an array, and returns the new length of the array.push("Tomatoes", "Basil", "Peppers"); // Find items constconst basil: "Basil" | undefined
basil =const resources: CoList<string>
resources.Array<string>.find<"Basil">(predicate: (value: string, index: number, obj: string[]) => value is "Basil", thisArg?: any): "Basil" | undefined (+1 overload)
Returns the value of the first element in the array where predicate is true, and undefined otherwise.find(r: string
r =>r: string
r === "Basil"); // Filter (returns regular array, not a CoList) constconst tItems: string[]
tItems =const resources: CoList<string>
resources.Array<string>.filter(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[] (+1 overload)
Returns the elements of an array that meet the condition specified in a callback function.filter(r: string
r =>r: string
r.String.startsWith(searchString: string, position?: number): boolean
Returns true if the sequence of elements of searchString converted to a String is the same as the corresponding elements of this object (converted to a String) starting at position. Otherwise returns false.startsWith("T"));var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+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.log(const tItems: string[]
tItems); // ["Tomatoes"] // Sort (modifies the CoList in-place)const resources: CoList<string>
resources.Array<string>.sort(compareFn?: ((a: string, b: string) => number) | undefined): CoList<string>
Sorts an array in place. This method mutates the array and returns a reference to the same array.sort();var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+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.log(const resources: CoList<string>
resources); // ["Basil", "Peppers", "Tomatoes"]
Type Safety
CoLists maintain type safety for their items:
// TypeScript catches type errors
const resources: CoList<string>
resources.CoList<string>.push(...items: string[]): number
Appends new elements to the end of an array, and returns the new length of the array.push("Carrots"); // ✓ Valid stringconst resources: CoList<string>
resources.CoList<string>.push(...items: string[]): number
Appends new elements to the end of an array, and returns the new length of the array.push(42); // ✗ Type error: expected string // For lists of referencestasks.
const tasks: CoList<{ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap>
Array<{ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap>.forEach(callbackfn: (value: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap, index: number, array: ({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap)[]) => void, thisArg?: any): void
Performs the specified action for each element in an array.forEach(task => {
task: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+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.log(task.
task: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap
title: string
title); // TypeScript knows task has title });
Best Practices
Common Patterns
List Rendering
CoLists work well with UI rendering libraries:
import {
import co
co,import z
z } from "jazz-tools"; constListOfTasks =
const ListOfTasks: CoListSchema<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>>
import co
co.list(
list<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>>(element: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>): CoListSchema<...> export list
Task); // React example function
const Task: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>
TaskList({
function TaskList({ tasks }: { tasks: co.loaded<typeof ListOfTasks>; }): React.JSX.Element
tasks }: {
tasks: CoList<({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap) | null>
tasks:
tasks: CoList<({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap) | null>
import co
co.loaded<typeof
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
ListOfTasks> }) { return ( <
const ListOfTasks: CoListSchema<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }>>
JSX.IntrinsicElements.ul: React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>
ul> {tasks.
tasks: CoList<({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap) | null>
Array<({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap) | null>.map<React.JSX.Element | null>(callbackfn: (value: ({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap) | null, index: number, array: (({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap) | null)[]) => React.JSX.Element | null, thisArg?: any): (React.JSX.Element | null)[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.map(task => (
task: ({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap) | null
task ? ( <
task: ({ title: string; status: "todo" | "in-progress" | "complete"; } & CoMap) | null
JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>
liReact.Attributes.key?: React.Key | null | undefined
key={task.
task: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap
CoMap.id: string
The ID of this `CoMap`id}> {task.
task: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap
title: string
title} - {task.
task: { title: string; status: "todo" | "in-progress" | "complete"; } & CoMap
status: "todo" | "in-progress" | "complete"
status} </JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>
li> ): null ))} </JSX.IntrinsicElements.ul: React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>
ul> ); }
Managing Relations
CoLists can be used to create one-to-many relationships:
import {
import co
co,import z
z,CoListSchema } from "jazz-tools"; const
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>; }
Task =
const Task: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: z.ZodOptional<typeof Project>; }>
import co
co.map({
map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: z.ZodOptional<typeof Project>; }>(shape: { title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: z.ZodOptional<typeof Project>; }): CoMapSchema<...> export map
title: z.z.ZodString
title:import z
z.string(),
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString export string
status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">
status:import z
z.literal(["todo", "in-progress", "complete"]), get
literal<["todo", "in-progress", "complete"]>(value: ["todo", "in-progress", "complete"], params?: string | z.z.core.$ZodLiteralParams): z.z.ZodLiteral<"todo" | "in-progress" | "complete"> (+1 overload) export literal
project():
project: z.ZodOptional<CoMapSchema<{ name: z.z.ZodString; readonly tasks: CoListSchema<typeof Task>; }>>
import z
z.ZodOptional<typeof
interface ZodOptional<T extends core.$ZodType = core.$ZodType<unknown, unknown>> export ZodOptional
Project> { return
const Project: CoMapSchema<{ name: z.z.ZodString; readonly tasks: CoListSchema<typeof Task>; }>
import z
z.optional(
optional<CoMapSchema<{ name: z.z.ZodString; readonly tasks: CoListSchema<typeof Task>; }>>(innerType: CoMapSchema<{ name: z.z.ZodString; readonly tasks: CoListSchema<typeof Task>; }>): z.ZodOptional<...> export optional
Project); } }); const
const Project: CoMapSchema<{ name: z.z.ZodString; readonly tasks: CoListSchema<typeof Task>; }>
ListOfTasks =
const ListOfTasks: CoListSchema<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: z.ZodOptional<typeof Project>; }>>
import co
co.list(
list<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: z.ZodOptional<typeof Project>; }>>(element: CoMapSchema<...>): CoListSchema<...> export list
Task); const
const Task: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: z.ZodOptional<typeof Project>; }>
Project =
const Project: CoMapSchema<{ name: z.z.ZodString; readonly tasks: CoListSchema<typeof Task>; }>
import co
co.map({
map<{ name: z.z.ZodString; readonly tasks: CoListSchema<typeof Task>; }>(shape: { name: z.z.ZodString; readonly tasks: CoListSchema<typeof Task>; }): CoMapSchema<{ name: z.z.ZodString; readonly tasks: CoListSchema<typeof Task>; }> export map
name: z.z.ZodString
name:import z
z.string(), get
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString export string
tasks():
tasks: CoListSchema<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: z.ZodOptional<typeof Project>; }>>
CoListSchema<typeof
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>; }
Task> { return
const Task: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: z.ZodOptional<typeof Project>; }>
ListOfTasks; } }); const
const ListOfTasks: CoListSchema<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: z.ZodOptional<typeof Project>; }>>
project =
const project: { name: string; tasks: CoListSchema<typeof Task>; } & CoMap
Project.
const Project: CoMapSchema<{ name: z.z.ZodString; readonly tasks: CoListSchema<typeof Task>; }>
create( {
create: (init: { name: string; tasks: CoListSchema<typeof Task>; }, options?: Account | Group | { owner: Account | Group; unique?: CoValueUniqueness["uniqueness"]; } | undefined) => { ...; } & CoMap
name: string
name: "Garden Project",tasks:
tasks: CoList<({ title: string; status: "todo" | "in-progress" | "complete"; project: z.ZodOptional<typeof Project>; } & CoMap) | null>
ListOfTasks.
const ListOfTasks: CoListSchema<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: z.ZodOptional<typeof Project>; }>>
create([]), }, ); const
create: (items: CoListInit<CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: z.ZodOptional<typeof Project>; }>>, options?: { owner: Account | Group; } | Account | Group) => CoList<...>
task =
const task: { title: string; status: "todo" | "in-progress" | "complete"; project: z.ZodOptional<typeof Project>; } & CoMap
Task.
const Task: CoMapSchema<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: z.ZodOptional<typeof Project>; }>
create({
create: (init: { project?: z.ZodOptional<typeof Project>; title: string; status: NonNullable<"todo" | "in-progress" | "complete">; }, options?: Account | Group | { ...; } | undefined) => { ...; } & CoMap
title: string
title: "Plant seedlings",status: NonNullable<"todo" | "in-progress" | "complete">
status: "todo",project:
project?: ({ name: string; tasks: CoListSchema<typeof Task>; } & CoMap) | undefined
project, // Add a reference to the project }); // Add a task to a garden project
const project: { name: string; tasks: CoListSchema<typeof Task>; } & CoMap
project.
const project: { name: string; tasks: CoListSchema<typeof Task>; } & CoMap
tasks.
tasks: CoList<{ title: string; status: "todo" | "in-progress" | "complete"; project: z.ZodOptional<typeof Project>; } & CoMap>
CoList<{ title: string; status: "todo" | "in-progress" | "complete"; project: z.ZodOptional<typeof Project>; } & CoMap>.push(...items: ({ title: string; status: "todo" | "in-progress" | "complete"; project: z.ZodOptional<typeof Project>; } & CoMap)[]): number
Appends new elements to the end of an array, and returns the new length of the array.push(task); // Access the project from the task
const task: { title: string; status: "todo" | "in-progress" | "complete"; project: z.ZodOptional<typeof Project>; } & CoMap
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+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.log(task.
const task: { title: string; status: "todo" | "in-progress" | "complete"; project: z.ZodOptional<typeof Project>; } & CoMap
project); // { name: "Garden Project", tasks: [task] }
project: ({ name: string; tasks: CoListSchema<typeof Task>; } & CoMap) | undefined