Lightyear Docs

Collections

What is a collection

A collection serves as a canonical representation of data that needs to be synchronized across multiple applications. At its core, a collection defines one or more models—essentially, the structures that represent the various types of information within the collection. These models can include schemas that enforce data integrity every time new information is written, ensuring consistency and accuracy throughout the system. Additionally, collections support the use of matching rules. These rules are instrumental in merging data from different systems when appropriate. For example, when a contact appears in several systems, an email address can be used as a matching criterion to unify and deduplicate records.

Why have collections in the first place

The motivation for using collections stems from the complexity of mapping data across numerous disparate applications. Attempting to directly connect and map data from N different apps to each other quickly becomes unmanageable. Instead, collections provide a shared, standardized data structure that acts as a common ground. Each connector, then, only needs to define how to translate its data to and from the collection format, greatly simplifying the integration process.

Built-in collections

To accelerate adoption and make integration easier, we plan to offer a set of out-of-the-box collections for the most common integration scenarios. These will include pre-built collections tailored for widely-used domains such as Customer Relationship Management (CRM), Human Resources (HR), Applicant Tracking, Project Management, and more. This approach will allow most developers to get started without too much effort.

Define a custom collection

Basic example

import { defineCollection, FromSchema } from "@runlightyear/lightyear";
 
export const taskManagement = defineCollection({
  name: "taskManagement",
  title: "Task Management",
  models: [
    {
      name: "task",
      title: "Task",
    },
  ],
});

Adding a schema

import { defineCollection } from "@runlightyear/lightyear";
 
export const taskManagement = defineCollection({
  name: "taskManagement",
  title: "Task Management",
  models: [
    {
      name: "task",
      title: "Task",
      schema: {
        type: "object",
        properties: {
          title: {
            type: "string",
          },
          description: {
            type: ["string", "null"],
          },
          status: {
            type: "string",
            enum: ["pending", "inProgress", "completed"],
          },
          dueDate: {
            type: ["string", "null"],
          },
          completedAt: {
            type: ["string", "null"],
          },
        },
        required: ["title", "status"],
      },
    },
  ],
});

Simple matching

import { defineCollection } from "@runlightyear/lightyear";
 
export const crm = defineCollection({
  name: "crm",
  title: "CRM",
  models: [
    {
      name: "contact",
      title: "Contact",
      schema: {
        type: "object",
        properties: {
          name: { type: "string" },
          email: { type: ["string", "null"] },
          phone: { type: ["string", "null"] },
        },
      },
      matchOn: "email",
    },
  ],
});
import { defineCollection } from "@runlightyear/lightyear";
 
export const crm = defineCollection({
  name: "crm",
  title: "CRM",
  models: [
    {
      name: "account",
      title: "Account",
      schema: {
        type: "object",
        properties: {
          name: { type: "string" },
          website: { type: ["string", "null"] },
          industry: { type: ["string", "null"] },
        },
      },
    },
    {
      name: "contact",
      title: "Contact",
      schema: {
        type: "object",
        properties: {
          name: { type: "string" },
          email: { type: ["string", "null"] },
          phone: { type: ["string", "null"] },
          accountId: {
            anyOf: [
              {
                type: "string",
                references: "account",
              },
              { type: "null" },
            ],
          },
        },
      },
    },
  ],
});

On this page