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: co.List<z.z.ZodString>
ListOfResources =import co
co.list(
list<z.z.ZodString>(element: z.z.ZodString): co.List<z.z.ZodString> export list
import z
z.string()); export type
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export string
type ListOfResources = CoList<string>
ListOfResources =import co
co.loaded<typeof
type loaded<T extends CoValueClassOrSchema, R extends ResolveQuery<T> = true> = R extends boolean | undefined ? NonNullable<InstanceOfSchemaCoValuesNullable<T>> : [NonNullable<InstanceOfSchemaCoValuesNullable<T>>] extends [...] ? Exclude<...> extends CoValue ? R extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean ... export loaded
const ListOfResources: co.List<z.z.ZodString>
ListOfResources>; constListOfTasks =
const ListOfTasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>
import co
co.list(
list<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>(element: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<...>; }, unknown, Account | Group>): co.List<...> export list
Task); export type
const Task: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>
ListOfTasks =
type ListOfTasks = CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap) | null>
import co
co.loaded<typeof
type loaded<T extends CoValueClassOrSchema, R extends ResolveQuery<T> = true> = R extends boolean | undefined ? NonNullable<InstanceOfSchemaCoValuesNullable<T>> : [NonNullable<InstanceOfSchemaCoValuesNullable<T>>] extends [...] ? Exclude<...> extends CoValue ? R extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean ... export loaded
ListOfTasks>;
const ListOfTasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>
To create a CoList
:
// Create an empty list const
const resources: CoListInstance<z.z.ZodString>
resources =import co
co.list(
list<z.z.ZodString>(element: z.z.ZodString): co.List<z.z.ZodString> export list
import z
z.string()).
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export string
create([]); // Create a list with initial items const
CoListSchema<ZodString>.create(items: readonly string[], options?: { owner: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): CoListInstance<...> (+1 overload)
tasks =
const tasks: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Group | Account>>
import co
co.list(
list<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Group | Account>>(element: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<...>; }, unknown, Group | Account>): co.List<...> export list
Task).
const Task: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Group | Account>
create([ {
CoListSchema<CoMapSchema<{ title: ZodString; status: ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Group | Account>>.create(items: readonly (({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap) | { title: string; status: "todo" | "in-progress" | "complete"; })[], options?: { owner: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): CoListInstance<...> (+1 overload)
title: string
title: "Prepare soil beds",status: "in-progress"
status: "in-progress" }, {title: string
title: "Order compost",status: "todo"
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 (+3 overloads)
addMember(colleagueAccount, "writer"); const
const colleagueAccount: Account | ({ readonly [x: string]: any; } & Account)
teamList =
const teamList: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodString; }, unknown, Group | Account>>
import co
co.list(
list<co.Map<{ title: z.z.ZodString; status: z.z.ZodString; }, unknown, Group | Account>>(element: co.Map<{ title: z.z.ZodString; status: z.z.ZodString; }, unknown, Group | Account>): co.List<...> export list
Task).
const Task: co.Map<{ title: z.z.ZodString; status: z.z.ZodString; }, unknown, Group | Account>
create([], {
CoListSchema<CoMapSchema<{ title: ZodString; status: ZodString; }, unknown, Group | Account>>.create(items: readonly (({ readonly title: string; readonly status: string; } & CoMap) | { title: string; status: string; })[], options?: { owner: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): CoListInstance<...> (+1 overload)
owner: Group
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: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap
tasks[0];
const tasks: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(firstTask.
const firstTask: { readonly title: string; readonly 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 (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(tasks.
const tasks: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>
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: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>
Array<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap>.forEach(callbackfn: (value: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap, index: number, array: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap)[]) => void, thisArg?: any): void
Performs the specified action for each element in an array.forEach(task => {
task: { readonly title: string; readonly 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 (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(task.
task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap
title: string
title); // "Prepare soil beds" // "Order compost" }); // Array methods consttodoTasks =
const todoTasks: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap)[]
tasks.
const tasks: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>
Array<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap>.filter(predicate: (value: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap, index: number, array: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap)[]) => unknown, thisArg?: any): ({ readonly title: string; readonly 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: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap
task.
task: { readonly title: string; readonly 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 (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(todoTasks.
const todoTasks: ({ readonly title: string; readonly 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
Methods to update a CoList's items are grouped inside the $jazz
namespace:
// Add items
const resources: CoListInstance<z.z.ZodString>
resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>
$jazz.CoListJazzApi<CoListInstance<ZodString>>.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: CoListInstance<z.z.ZodString>
resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>
$jazz.CoListJazzApi<CoListInstance<ZodString>>.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: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>
$jazz.
CoList<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap>.$jazz: CoListJazzApi<CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>>
CoListJazzApi<CoListInstance<CoMapSchema<{ title: ZodString; status: ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>>.push(...items: (({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap) | CoMapInit<{ readonly title: string; readonly 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({ // Add complex itemstitle: string
title: "Install irrigation", // (Jazz will createstatus: "todo"
status: "todo" // the CoValue for you!) }); // Replace itemsconst resources: CoListInstance<z.z.ZodString>
resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>
$jazz.CoListJazzApi<CoListInstance<ZodString>>.set(index: number, value: string): void
set(0, "Cucumber"); // Replace by index // Modify nested itemstasks[0].
const tasks: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>
CoMap.$jazz: CoMapJazzApi<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap>
Jazz methods for CoMaps are inside this property. This allows CoMaps to be used as plain objects while still having access to Jazz methods, and also doesn't limit which key names can be used inside CoMaps.$jazz.CoMapJazzApi<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap>.set<"status">(key: "status", value: "todo" | "in-progress" | "complete"): void
Set a value on the CoMapset("status", "complete"); // Update properties of references
Soft Deletion
You can do a soft deletion by using a deleted flag, then creating a helper method that explicitly filters out items where the deleted property is true.
const
Task =
const Task: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>
import co
co.map({
map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }>(shape: { title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | ... 1 more ... | "complete">; deleted: z.ZodOptional<...>; }): co.Map<...> export map
title: z.z.ZodString
title:import z
z.string(),
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export string
status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">
status:import z
z.literal(["todo", "in-progress", "complete"]),
literal<readonly ["todo", "in-progress", "complete"]>(value: readonly ["todo", "in-progress", "complete"], params?: string | z.z.core.$ZodLiteralParams): z.z.ZodLiteral<"todo" | "in-progress" | "complete"> (+1 overload) export literal
deleted: z.ZodOptional<z.z.ZodBoolean>
deleted:import z
z.optional(
optional<z.z.ZodBoolean>(innerType: z.z.ZodBoolean): z.ZodOptional<z.z.ZodBoolean> export optional
import z
z.boolean()) }); type
function boolean(params?: string | z.z.core.$ZodBooleanParams): z.z.ZodBoolean export boolean
Task = typeof
type Task = co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>
Task; const
const Task: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>
ListOfTasks =
const ListOfTasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>
import co
co.list(
list<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>(element: co.Map<...>): co.List<...> export list
Task); type
const Task: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>
ListOfTasks = typeof
type ListOfTasks = co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>
ListOfTasks; export function
const ListOfTasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>
getCurrentTasks(
function getCurrentTasks(list: co.loaded<ListOfTasks>): ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap)[]
list:
list: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap) | null>
import co
co.loaded<
type loaded<T extends CoValueClassOrSchema, R extends ResolveQuery<T> = true> = R extends boolean | undefined ? NonNullable<InstanceOfSchemaCoValuesNullable<T>> : [NonNullable<InstanceOfSchemaCoValuesNullable<T>>] extends [...] ? Exclude<...> extends CoValue ? R extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean ... export loaded
ListOfTasks>) { return
type ListOfTasks = co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>
list.
list: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap) | null>
Array<({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap) | null>.filter<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap>(predicate: (value: ({ readonly title: string; readonly status: "todo" | ... 1 more ... | "complete"; readonly deleted: boolean | undefined; } & CoMap) | null, index: number, array: (({ readonly title: string; readonly status: "todo" | ... 1 more ... | "complete"; readonly deleted: boolean | undefined; } & CoMap) | null)[]) => value is { readonly title: string; readonly status: "todo" | ... 1 more ... | "complete"; readonly deleted: boolean | undefined; } & CoMap, thisArg?: any): ({ readonly title: string; readonly status: "todo" | ... 1 more ... | "complete"; readonly deleted: boolean | undefined; } & CoMap)[] (+1 overload)
Returns the elements of an array that meet the condition specified in a callback function.filter( (task):
task: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap) | null
task is
task: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap) | null
import co
co.loaded<
type loaded<T extends CoValueClassOrSchema, R extends ResolveQuery<T> = true> = R extends boolean | undefined ? NonNullable<InstanceOfSchemaCoValuesNullable<T>> : [NonNullable<InstanceOfSchemaCoValuesNullable<T>>] extends [...] ? Exclude<...> extends CoValue ? R extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean ... export loaded
Task> => !
type Task = co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>
task?.
task: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap) | null
deleted: boolean | undefined
deleted ); } async functionfunction main(): Promise<void>
main() { constmyTaskList =
const myTaskList: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>
ListOfTasks.
const ListOfTasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>
create([]);
CoListSchema<CoMapSchema<{ title: ZodString; status: ZodLiteral<"todo" | "in-progress" | "complete">; deleted: ZodOptional<ZodBoolean>; }, unknown, Account | Group>>.create(items: readonly (({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap) | { title: string; status: "todo" | "in-progress" | "complete"; deleted?: boolean | undefined; })[], options?: { owner: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): CoListInstance<...> (+1 overload)
myTaskList.
const myTaskList: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>
$jazz.
CoList<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap>.$jazz: CoListJazzApi<CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>>
CoListJazzApi<CoListInstance<CoMapSchema<{ title: ZodString; status: ZodLiteral<"todo" | "in-progress" | "complete">; deleted: ZodOptional<ZodBoolean>; }, unknown, Account | Group>>>.push(...items: (({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap) | CoMapInit<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap>)[]): number
Appends new elements to the end of an array, and returns the new length of the array.push({title: string
title: "Tomatoes",status: "todo"
status: "todo",deleted: false
deleted: false });myTaskList.
const myTaskList: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>
$jazz.
CoList<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap>.$jazz: CoListJazzApi<CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>>
CoListJazzApi<CoListInstance<CoMapSchema<{ title: ZodString; status: ZodLiteral<"todo" | "in-progress" | "complete">; deleted: ZodOptional<ZodBoolean>; }, unknown, Account | Group>>>.push(...items: (({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap) | CoMapInit<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap>)[]): number
Appends new elements to the end of an array, and returns the new length of the array.push({title: string
title: "Cucumbers",status: "todo"
status: "todo",deleted: true
deleted: true });myTaskList.
const myTaskList: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>
$jazz.
CoList<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap>.$jazz: CoListJazzApi<CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>>
CoListJazzApi<CoListInstance<CoMapSchema<{ title: ZodString; status: ZodLiteral<"todo" | "in-progress" | "complete">; deleted: ZodOptional<ZodBoolean>; }, unknown, Account | Group>>>.push(...items: (({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap) | CoMapInit<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap>)[]): number
Appends new elements to the end of an array, and returns the new length of the array.push({title: string
title: "Carrots",status: "todo"
status: "todo" }); constactiveTasks =
const activeTasks: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap)[]
getCurrentTasks(
function getCurrentTasks(list: co.loaded<ListOfTasks>): ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap)[]
myTaskList);
const myTaskList: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; deleted: z.ZodOptional<z.z.ZodBoolean>; }, unknown, Account | Group>>
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(activeTasks.
const activeTasks: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap)[]
Array<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap>.map<string>(callbackfn: (value: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap, index: number, array: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap)[]) => string, thisArg?: any): string[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.map((task) =>
task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap
task.
task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap
title: string
title)); // Output: ["Tomatoes", "Carrots"] }
There are several benefits to soft deletions:
- recoverablity - Nothing is truly deleted, so recovery is possible in the future
- data integrity - Relationships can be maintained between current and deleted values
- auditable - The data can still be accessed, good for audit trails and checking compliance
Deleting Items
Jazz provides two methods to retain or remove items from a CoList:
// Remove items
const resources: CoListInstance<z.z.ZodString>
resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>
$jazz.CoListJazzApi<CoListInstance<ZodString>>.remove(...indices: number[]): string[] (+1 overload)
Removes the elements at the specified indices from the array.remove(2); // By indexvar console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const resources: CoListInstance<z.z.ZodString>
resources); // ["Cucumber", "Peppers"]const resources: CoListInstance<z.z.ZodString>
resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>
$jazz.CoListJazzApi<CoListInstance<ZodString>>.remove(predicate: (item: string, index: number, coList: CoListInstance<z.z.ZodString>) => boolean): string[] (+1 overload)
Removes the elements matching the predicate from the array.remove(item: string
item =>item: string
item === "Cucumber"); // Or by predicatevar console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const resources: CoListInstance<z.z.ZodString>
resources); // ["Tomatoes", "Peppers"] // Keep only items matching the predicateconst resources: CoListInstance<z.z.ZodString>
resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>
$jazz.CoListJazzApi<CoListInstance<ZodString>>.retain(predicate: (item: string, index: number, coList: CoListInstance<z.z.ZodString>) => boolean): string[]
Retains only the elements matching the predicate from the array.retain(item: string
item =>item: string
item !== "Cucumber");var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const resources: CoListInstance<z.z.ZodString>
resources); // ["Tomatoes", "Peppers"]
You can also 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: CoListInstance<z.z.ZodString>
resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>
$jazz.CoListJazzApi<CoListInstance<ZodString>>.splice(start: number, deleteCount: number, ...items: string[]): string[]
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.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 (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const resources: CoListInstance<z.z.ZodString>
resources); // ["Tomatoes"] // Remove a single item at index 0const resources: CoListInstance<z.z.ZodString>
resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>
$jazz.CoListJazzApi<CoListInstance<ZodString>>.splice(start: number, deleteCount: number, ...items: string[]): string[]
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.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 (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const resources: CoListInstance<z.z.ZodString>
resources); // ["Cucumber", "Peppers"] // Remove items constconst lastItem: string | undefined
lastItem =const resources: CoListInstance<z.z.ZodString>
resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>
$jazz.CoListJazzApi<CoListInstance<ZodString>>.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: CoListInstance<z.z.ZodString>
resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>
$jazz.CoListJazzApi<CoListInstance<ZodString>>.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. Methods that mutate the array
are grouped inside the $jazz
namespace.
// Add multiple items at once
const resources: CoListInstance<z.z.ZodString>
resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>
$jazz.CoListJazzApi<CoListInstance<ZodString>>.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: CoListInstance<z.z.ZodString>
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: CoListInstance<z.z.ZodString>
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 (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const tItems: string[]
tItems); // ["Tomatoes"]
Type Safety
CoLists maintain type safety for their items:
// TypeScript catches type errors
const resources: CoListInstance<z.z.ZodString>
resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>
$jazz.CoListJazzApi<CoListInstance<ZodString>>.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: CoListInstance<z.z.ZodString>
resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>
$jazz.CoListJazzApi<CoListInstance<ZodString>>.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: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>
Array<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap>.forEach(callbackfn: (value: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap, index: number, array: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap)[]) => void, thisArg?: any): void
Performs the specified action for each element in an array.forEach(task => {
task: { readonly title: string; readonly 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 (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(task.
task: { readonly title: string; readonly 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: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>
import co
co.list(
list<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>(element: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<...>; }, unknown, Account | Group>): co.List<...> export list
Task); // React example function
const Task: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>
TaskList({
function TaskList({ tasks }: { tasks: co.loaded<typeof ListOfTasks>; }): React.JSX.Element
tasks }: {
tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap) | null>
tasks:
tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap) | null>
import co
co.loaded<typeof
type loaded<T extends CoValueClassOrSchema, R extends ResolveQuery<T> = true> = R extends boolean | undefined ? NonNullable<InstanceOfSchemaCoValuesNullable<T>> : [NonNullable<InstanceOfSchemaCoValuesNullable<T>>] extends [...] ? Exclude<...> extends CoValue ? R extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean | undefined ? CoValue & Exclude<...> : [...] extends [...] ? Exclude<...> extends CoValue ? ItemDepth extends { ...; } ? readonly ((CoValue & ... 1 more ... & (ItemDepth extends boolean ... export loaded
ListOfTasks> }) { return ( <
const ListOfTasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>
React.JSX.IntrinsicElements.ul: React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>
ul> {tasks.
tasks: CoList<({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap) | null>
Array<({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap) | null>.map<React.JSX.Element | null>(callbackfn: (value: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap) | null, index: number, array: (({ readonly title: string; readonly 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: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap) | null
task ? ( <
task: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap) | null
React.JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>
liReact.Attributes.key?: React.Key | null | undefined
key={task.
task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap
CoMap.$jazz: CoMapJazzApi<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap>
Jazz methods for CoMaps are inside this property. This allows CoMaps to be used as plain objects while still having access to Jazz methods, and also doesn't limit which key names can be used inside CoMaps.$jazz.CoMapJazzApi<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap>.id: string
The ID of this `CoMap`id}> {task.
task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap
title: string
title} - {task.
task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap
status: "todo" | "in-progress" | "complete"
status} </React.JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>
li> ): null ))} </React.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 } from "jazz-tools"; constTask =
const Task: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>
import co
co.map({
map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }>(shape: { ...; }): co.Map<...> export map
title: z.z.ZodString
title:import z
z.string(),
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export string
status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">
status:import z
z.literal(["todo", "in-progress", "complete"]), get
literal<readonly ["todo", "in-progress", "complete"]>(value: readonly ["todo", "in-progress", "complete"], params?: string | z.z.core.$ZodLiteralParams): z.z.ZodLiteral<"todo" | "in-progress" | "complete"> (+1 overload) export literal
project():
project: co.Optional<co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>>
import co
co.Optional<typeof
class Optional<Shape extends CoreCoValueSchema = CoreCoValueSchema> export Optional
Project> { return
const Project: co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>
import co
co.optional(
optional<co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>>(schema: co.Map<...>): co.Optional<...> export optional
Project); } }); const
const Project: co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>
ListOfTasks =
const ListOfTasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>>
import co
co.list(
list<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>>(element: co.Map<...>): co.List<...> export list
Task); const
const Task: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>
Project =
const Project: co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>
import co
co.map({
map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }>(shape: { ...; }): co.Map<...> export map
name: z.z.ZodString
name:import z
z.string(), get
function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export string
tasks():
tasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>>
import co
co.List<typeof
class List<T extends AnyZodOrCoValueSchema> export List
Task> { return
const Task: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>
ListOfTasks; } }); const
const ListOfTasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>>
project =
const project: { readonly name: string; readonly tasks: CoList<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<... & CoMap>; } & CoMap) | undefined; } & CoMap>; } & CoMap
Project.
const Project: co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>
create( {
CoMapSchema<{ name: ZodString; readonly tasks: CoListSchema<CoMapSchema<{ title: ZodString; status: ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: CoOptionalSchema<CoMapSchema<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>.create(init: { name: string; readonly tasks: readonly (({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null | undefined; } & CoMap) | { ...; })[] | CoList<(... & CoMap) | null>; }, options?: { owner?: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): { ...; } & CoMap (+1 overload)
name: string
name: "Garden Project",tasks:
tasks: readonly (({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null | undefined; } & CoMap) | { ...; })[] | CoList<...>
ListOfTasks.
const ListOfTasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>>
create([]), }, ); const
CoListSchema<CoMapSchema<{ title: ZodString; status: ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: CoOptionalSchema<CoMapSchema<{ name: ZodString; readonly tasks: CoListSchema<CoMapSchema<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>>.create(items: readonly (({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null | undefined; } & CoMap) | { ...; })[], options?: { owner: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): CoListInstance<...> (+1 overload)
task =
const task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<... & CoMap>; } & CoMap) | undefined; } & CoMap
Task.
const Task: co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: co.Optional<co.Map<{ name: z.z.ZodString; readonly tasks: co.List<co.Map<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>
create({
CoMapSchema<{ title: ZodString; status: ZodLiteral<"todo" | "in-progress" | "complete">; readonly project: CoOptionalSchema<CoMapSchema<{ name: ZodString; readonly tasks: CoListSchema<CoMapSchema<..., unknown, Account | Group>>; }, unknown, Account | Group>>; }, unknown, Account | Group>.create(init: { title: string; status: "todo" | "in-progress" | "complete"; readonly project?: { name: string; readonly tasks: readonly (({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ ...; } & CoMap) | ... 1 more ... | undefined; } & CoMap) | ...)[] | CoList<...>; } | ({ ...; } & CoMap) | undefined; }, options?: { owner?: Group; unique?: CoValueUniqueness["uniqueness"]; } | Group): { ...; } & CoMap (+1 overload)
title: string
title: "Plant seedlings",status: "todo" | "in-progress" | "complete"
status: "todo",project:
project?: { name: string; readonly tasks: readonly (({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<(... & CoMap) | null> | null; } & CoMap) | null | undefined; } & CoMap) | { ...; })[] | CoList<(... & CoMap) | null>; } | ({ ...; } & CoMap) | undefined
project, // Add a reference to the project }); // Add a task to a garden project
const project: { readonly name: string; readonly tasks: CoList<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<... & CoMap>; } & CoMap) | undefined; } & CoMap>; } & CoMap
project.
const project: { readonly name: string; readonly tasks: CoList<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<... & CoMap>; } & CoMap) | undefined; } & CoMap>; } & CoMap
tasks.
tasks: CoList<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<... & CoMap>; } & CoMap) | undefined; } & CoMap>
$jazz.
CoList<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<... & CoMap>; } & CoMap) | undefined; } & CoMap>.$jazz: CoListJazzApi<CoList<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<... & CoMap>; } & CoMap) | undefined; } & CoMap>>
CoListJazzApi<CoList<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<... & CoMap>; } & CoMap) | undefined; } & CoMap>>.push(...items: (({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<... & CoMap>; } & CoMap) | undefined; } & CoMap) | CoMapInit<...>)[]): 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: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<... & CoMap>; } & CoMap) | undefined; } & CoMap
var console: Console
The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v20.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```console.Console.log(message?: any, ...optionalParams: any[]): void (+2 overloads)
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(task.
const task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<... & CoMap>; } & CoMap) | undefined; } & CoMap
project); // { name: "Garden Project", tasks: [task] }
project: ({ readonly name: string; readonly tasks: CoList<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<... & CoMap>; } & CoMap) | undefined; } & CoMap>; } & CoMap) | undefined