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 coco,import zz } from "jazz-tools"; constconst ListOfResources: co.List<z.z.ZodString>ListOfResources =import coco.list(list<z.z.ZodString>(element: z.z.ZodString): co.List<z.z.ZodString> export listimport zz.string()); export typefunction string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export stringtype ListOfResources = CoList<string>ListOfResources =import coco.loaded<typeoftype 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 loadedconst 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 coco.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 listTask); export typeconst 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 coco.loaded<typeoftype 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 loadedListOfTasks>; export typeconst ListOfTasks: co.List<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>ListOfTasksInitShape =type ListOfTasksInitShape = readonly (({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap) | { title: string; status: "todo" | "in-progress" | "complete"; })[]import coco.type input<S extends CoValueClass | AnyZodOrCoValueSchema> = S extends CoreCoValueSchema ? Exclude<CoFieldSchemaInit<S>, NonNullable<InstanceOfSchemaCoValuesNullable<S>>> : CoFieldSchemaInit<...> export inputThe convenience type for extracting the init type of a CoValue schema.input<typeofListOfTasks>; // type accepted by `ListOfTasks.create`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 constconst resources: CoListInstance<z.z.ZodString>resources =import coco.list(list<z.z.ZodString>(element: z.z.ZodString): co.List<z.z.ZodString> export listimport zz.string()).function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export stringcreate([]); // Create a list with initial items constCoListSchema<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 coco.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 listTask).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: stringtitle: "Prepare soil beds",status: "in-progress"status: "in-progress" }, {title: stringtitle: "Order compost",status: "todo"status: "todo" } ]);
Ownership
Like other CoValues, you can specify ownership when creating CoLists.
// Create with shared ownership constconst teamGroup: GroupteamGroup =class GroupGroup.create();Group.create<Group>(this: CoValueClass<Group>, options?: { owner: Account; } | Account): Groupconst teamGroup: GroupteamGroup.Group.addMember(member: Account, role: AccountRole): void (+3 overloads)addMember(colleagueAccount, "writer"); constconst 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 coco.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 listTask).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: Groupowner:const teamGroup: GroupteamGroup });
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 constfirstTask =const firstTask: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMaptasks[0];const tasks: CoListInstance<co.Map<{ title: z.z.ZodString; status: z.z.ZodLiteral<"todo" | "in-progress" | "complete">; }, unknown, Account | Group>>var console: ConsoleThe `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"; } & CoMaptitle: stringtitle); // "Prepare soil beds" // Get list lengthvar console: ConsoleThe `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: numberGets 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): voidPerforms the specified action for each element in an array.forEach(task => {task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMapvar console: ConsoleThe `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"; } & CoMaptitle: stringtitle); // "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"; } & CoMaptask.task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMapstatus: "todo" | "in-progress" | "complete"status === "todo");var console: ConsoleThe `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: numberGets 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 itemsconst resources: CoListInstance<z.z.ZodString>resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>$jazz.CoListJazzApi<CoListInstance<ZodString>>.push(...items: string[]): numberAppends 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[]): numberInserts 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>)[]): numberAppends new elements to the end of an array, and returns the new length of the array.push({ // Add complex itemstitle: stringtitle: "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): voidset(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"): voidSet 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.
constTask =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 coco.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 maptitle: z.z.ZodStringtitle:import zz.string(),function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export stringstatus: z.z.ZodLiteral<"todo" | "in-progress" | "complete">status:import zz.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 literaldeleted: z.ZodOptional<z.z.ZodBoolean>deleted:import zz.optional(optional<z.z.ZodBoolean>(innerType: z.z.ZodBoolean): z.ZodOptional<z.z.ZodBoolean> export optionalimport zz.boolean()) }); typefunction boolean(params?: string | z.z.core.$ZodBooleanParams): z.z.ZodBoolean export booleanTask = typeoftype 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; constconst 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 coco.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 listTask); typeconst 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 = typeoftype 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 functionconst 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 coco.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 loadedListOfTasks>) { returntype 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) | nulltask istask: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMap) | nullimport coco.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 loadedTask> => !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) | nulldeleted: boolean | undefineddeleted ); } 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>)[]): numberAppends new elements to the end of an array, and returns the new length of the array.push({title: stringtitle: "Tomatoes",status: "todo"status: "todo",deleted: falsedeleted: 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>)[]): numberAppends new elements to the end of an array, and returns the new length of the array.push({title: stringtitle: "Cucumbers",status: "todo"status: "todo",deleted: truedeleted: 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>)[]): numberAppends new elements to the end of an array, and returns the new length of the array.push({title: stringtitle: "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: ConsoleThe `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; } & CoMaptask.task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly deleted: boolean | undefined; } & CoMaptitle: stringtitle)); // 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 itemsconst 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: ConsoleThe `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: stringitem =>item: stringitem === "Cucumber"); // Or by predicatevar console: ConsoleThe `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: stringitem =>item: stringitem !== "Cucumber");var console: ConsoleThe `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 1const 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: ConsoleThe `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: ConsoleThe `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 | undefinedlastItem =const resources: CoListInstance<z.z.ZodString>resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>$jazz.CoListJazzApi<CoListInstance<ZodString>>.pop(): string | undefinedRemoves 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 | undefinedRemoves 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
CoLists support the standard JavaScript array methods you already know. Methods that mutate the array
are grouped inside the $jazz namespace.
// Add multiple items at onceconst resources: CoListInstance<z.z.ZodString>resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>$jazz.CoListJazzApi<CoListInstance<ZodString>>.push(...items: string[]): numberAppends 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" | undefinedbasil =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: stringr =>r: stringr === "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: stringr =>r: stringr.String.startsWith(searchString: string, position?: number): booleanReturns 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: ConsoleThe `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 errorsconst resources: CoListInstance<z.z.ZodString>resources.CoList<string>.$jazz: CoListJazzApi<CoListInstance<z.z.ZodString>>$jazz.CoListJazzApi<CoListInstance<ZodString>>.push(...items: string[]): numberAppends 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[]): numberAppends 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): voidPerforms the specified action for each element in an array.forEach(task => {task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMapvar console: ConsoleThe `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"; } & CoMaptitle: stringtitle); // TypeScript knows task has title });
Best Practices
Common Patterns
List Rendering
CoLists work well with UI rendering libraries:
import {import coco,import zz } 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 coco.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 listTask); // React example functionconst 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.Elementtasks }: {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 coco.loaded<typeoftype 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 loadedListOfTasks> }) { 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) | nulltask ? ( <task: ({ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap) | nullReact.JSX.IntrinsicElements.li: React.DetailedHTMLProps<React.LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>liReact.Attributes.key?: React.Key | null | undefinedkey={task.task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMapCoMap.$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.CoValueJazzApi<{ readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMap>.id: stringid}> {task.task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMaptitle: stringtitle} - {task.task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; } & CoMapstatus: "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 coco,import zz } 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 coco.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 maptitle: z.z.ZodStringtitle:import zz.string(),function string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export stringstatus: z.z.ZodLiteral<"todo" | "in-progress" | "complete">status:import zz.literal(["todo", "in-progress", "complete"]), getliteral<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 literalproject():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 coco.Optional<typeofclass Optional<Shape extends CoreCoValueSchema = CoreCoValueSchema> export OptionalProject> { returnconst 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 coco.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 optionalProject); } }); constconst 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 coco.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 listTask); constconst 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 coco.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 mapname: z.z.ZodStringname:import zz.string(), getfunction string(params?: string | z.z.core.$ZodStringParams): z.z.ZodString (+1 overload) export stringtasks():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 coco.List<typeofclass List<T extends AnyZodOrCoValueSchema> export ListTask> { returnconst 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; } }); constconst 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>; } & CoMapProject.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: stringname: "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([]), }, ); constCoListSchema<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; } & CoMapTask.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: stringtitle: "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) | undefinedproject, // Add a reference to the project }); // Add a task to a garden projectconst 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>; } & CoMapproject.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>; } & CoMaptasks.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<...>)[]): numberAppends new elements to the end of an array, and returns the new length of the array.push(task); // Access the project from the taskconst task: { readonly title: string; readonly status: "todo" | "in-progress" | "complete"; readonly project: ({ readonly name: string; readonly tasks: CoList<... & CoMap>; } & CoMap) | undefined; } & CoMapvar console: ConsoleThe `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; } & CoMapproject); // { 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