Lime Web Components API Documentation - v7.4.0
    Preparing search index...

    Interface LimeObjectRepository

    Repository for loading, querying, and managing Lime CRM objects.

    LimeObjectRepository is the primary service for interacting with business objects in Lime CRM (deals, companies, people, etc.). It provides methods to:

    • Load single objects or collections with filtering, sorting, and pagination
    • Load objects related through properties (e.g., deals related to a company)
    • Search across limetypes with a free-text query
    • Delete objects
    • Access cached objects from state
    • Load and retrieve JSON schemas for limetypes

    The repository extends StateRepository, which means:

    • All loaded objects are cached in state
    • Components can subscribe to object changes
    • Use SelectCurrentLimeObject decorator for automatic reactive updates
    import { State } from '@stencil/core';
    import {
    LimeObject,
    SelectCurrentLimeObject,
    } from '@limetech/lime-web-components';

    class MyComponent {
    // The object is replaced whenever the context changes.
    @State()
    @SelectCurrentLimeObject()
    private currentObject: LimeObject;

    private logCurrentObject() {
    console.log(this.currentObject.getValue('name'));
    console.log(this.currentObject.id);
    }
    }
    interface LimeObjectRepository {
        deleteObject(limetype: string, id: number): Promise<void>;
        getObject(limetype: string, id: number): LimeObject | undefined;
        getObjects(limetype: string): LimeObject[];
        getSchema<
            TSchemaType extends Record<string, unknown> = Record<string, unknown>,
        >(
            limetype: string,
        ): TSchemaType | null;
        loadObject(
            limetype: string,
            id: number,
            options?: Pick<LoadOptions, "properties">,
        ): Promise<LimeObject | null>;
        loadObjects(
            limetype: string,
            options?: LoadOptions,
        ): Promise<ObjectResponse>;
        loadRelations(
            limetype: string,
            id: number,
            property: string,
            options?: LoadOptions,
        ): Promise<ObjectResponse>;
        loadSchema<
            TSchemaType extends Record<string, unknown> = Record<string, unknown>,
        >(
            limetype: string,
        ): Promise<TSchemaType>;
        search(text: string, options?: SearchOptions): Promise<SearchResponse>;
        subscribe(
            callback: (...args: unknown[]) => void,
            options?: StateOptions,
        ): () => void;
    }

    Hierarchy (View Summary)

    Index

    Methods

    • Delete an object from the database.

      Permanently removes the specified object. This operation cannot be undone. The object will be removed from the repository state after successful deletion.

      Deletion may fail if:

      • User lacks delete permissions
      • Object has dependent relationships
      • Business rules prevent deletion

      Parameters

      • limetype: string

        Name of the limetype (e.g., 'deal', 'company').

      • id: number

        ID of the object to delete.

      Returns Promise<void>

      Promise that resolves when deletion is complete.

      Error if deletion fails

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const dealId = 1234;

      try {
      await repository.deleteObject('deal', dealId);
      } catch (error) {
      console.error('Failed to delete deal', error);
      }
      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const dealIds = [1, 2, 3];
      const failed: number[] = [];

      for (const id of dealIds) {
      try {
      await repository.deleteObject('deal', id);
      } catch {
      failed.push(id);
      }
      }

      console.log(`Deleted ${dealIds.length - failed.length} of ${dealIds.length}`);
    • Get a single object that has already been loaded into state.

      Retrieves an object from the repository cache without making a network request. Returns undefined if the object has not been loaded yet.

      Use this to access objects that were previously loaded via loadObject, loadObjects, or loadRelations.

      Parameters

      • limetype: string

        Name of the limetype.

      • id: number

        ID of the object to retrieve.

      Returns LimeObject | undefined

      The cached LimeObject, or undefined if not loaded.

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const deal = repository.getObject('deal', 1234);

      if (deal) {
      console.log('Deal name:', deal.getValue('name'));
      } else {
      repository.loadObject('deal', 1234);
      }
      import { PlatformServiceName } from '@limetech/lime-web-components';

      function getDealName(dealId: number): string {
      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const deal = repository.getObject('deal', dealId);

      return deal?.getValue('name') ?? 'Loading...';
      }
    • Get all objects of a specific limetype that are loaded in state.

      Retrieves all cached objects for the specified limetype without making a network request. Only returns objects that have been previously loaded via loadObject, loadObjects, or loadRelations.

      This does NOT load all objects of a type from the database. Use loadObjects to fetch objects from the server.

      Parameters

      • limetype: string

        Name of the limetype to get objects for.

      Returns LimeObject[]

      Array of cached LimeObjects (may be empty).

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const deals = repository.getObjects('deal');

      console.log(`${deals.length} deals are cached`);
      for (const deal of deals) {
      console.log(`- ${deal.getValue('name')}: ${deal.getValue('value')}`);
      }
      import { PlatformServiceName } from '@limetech/lime-web-components';

      function areDealsCached(dealIds: number[]): boolean {
      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const cachedIds = new Set(
      repository.getObjects('deal').map((deal) => deal.id)
      );

      return dealIds.every((id) => cachedIds.has(id));
      }
      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const companies = repository.getObjects('company');

      const options = companies.map((company) => ({
      value: company.id,
      label: company.getValue('name'),
      }));
    • Get a cached JSON schema that has already been loaded.

      Retrieves a schema from the repository cache without making a network request. Returns null if the schema has not been loaded yet. Use loadSchema to fetch and cache the schema first.

      Type Parameters

      • TSchemaType extends Record<string, unknown> = Record<string, unknown>

      Parameters

      • limetype: string

        Name of the limetype to get the schema for.

      Returns TSchemaType | null

      The schema if it has been loaded, otherwise null.

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);

      let schema = repository.getSchema('deal');

      if (!schema) {
      schema = await repository.loadSchema('deal');
      }

      loadSchema to load the schema into cache

    • Load a single object by ID into the state.

      Fetches an object from the database and stores it in the repository state, making it available through getObject. Triggers state updates that notify subscribers.

      Prefer using the SelectCurrentLimeObject decorator for reactive updates.

      Parameters

      • limetype: string

        Name of the limetype (e.g., 'deal', 'company', 'person').

      • id: number

        Unique identifier of the object to load.

      • Optionaloptions: Pick<LoadOptions, "properties">

        Optional configuration to limit which properties are loaded.

      Returns Promise<LimeObject | null>

      The loaded LimeObject, or null if it does not exist.

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const deal = await repository.loadObject('deal', 1234);

      if (deal) {
      console.log(deal.descriptive);
      }
      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);

      await repository.loadObject('company', 789, {
      properties: ['name', 'address', 'phone'],
      });
    • Load a collection of objects with filtering, sorting, and pagination.

      Queries the database for objects matching the specified criteria. Results are both returned in the promise and stored in the repository state. Supports:

      • Complex filter expressions with AND/OR/NOT logic
      • Multi-column sorting
      • Pagination via limit and offset
      • Selecting specific properties to load
      • Aggregate calculations (count, sum, avg, etc.)

      Parameters

      • limetype: string

        Name of the limetype to query (e.g., 'deal', 'company').

      • Optionaloptions: LoadOptions

        Query configuration including filters, sorting, and pagination.

      Returns Promise<ObjectResponse>

      Promise resolving to ObjectResponse with objects and metadata.

      import { Operator, PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);

      const response = await repository.loadObjects('deal', {
      filter: {
      op: Operator.AND,
      exp: [
      { key: 'status', op: Operator.EQUALS, exp: 'active' },
      { key: 'value', op: Operator.GREATER_OR_EQUAL, exp: 50_000 },
      ],
      },
      order: [{ name: 'value', direction: 'DESC' }],
      limit: 50,
      offset: 0,
      });

      console.log(
      `Loaded ${response.objects.length} of ${response.totalCount} deals`
      );
      import { Operator, PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const pageSize = 25;
      const pageNumber = 0;

      const response = await repository.loadObjects('company', {
      filter: { key: 'active', op: Operator.EQUALS, exp: true },
      limit: pageSize,
      offset: pageNumber * pageSize,
      order: [{ name: 'name', direction: 'ASC' }],
      });

      const companies = response.objects;
      const totalPages = Math.ceil(response.totalCount / pageSize);
      import { Operator, PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);

      const response = await repository.loadObjects('deal', {
      filter: { key: 'status', op: Operator.EQUALS, exp: 'active' },
      properties: ['name', 'value', 'closedate', 'company.name'],
      limit: 100,
      });
      import {
      AggregateOperator,
      Operator,
      PlatformServiceName,
      } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const companyId = 456;

      const response = await repository.loadObjects('deal', {
      filter: { key: 'company', op: Operator.EQUALS, exp: companyId },
      properties: [
      'name',
      'value',
      {
      name: 'tasks.status',
      key: 'completed_tasks_count',
      operator: AggregateOperator.Count,
      filter: 'completed_tasks_filter',
      },
      ],
      });

      for (const deal of response.objects) {
      console.log(`${deal['name']}: ${deal['completed_tasks_count']} tasks`);
      }
    • Load objects related to another object through a relation property.

      Fetches objects connected via a relationship (e.g., deals related to a company, tasks assigned to a person). This is equivalent to querying the related limetype with a filter, but more convenient and follows the data model relationships.

      Supports the same filtering, sorting, and pagination options as loadObjects.

      Parameters

      • limetype: string

        Name of the limetype that owns the relation (e.g., 'company').

      • id: number

        ID of the owning object.

      • property: string

        Name of the relation property (e.g., 'deals', 'contacts').

      • Optionaloptions: LoadOptions

        Query configuration for the related objects.

      Returns Promise<ObjectResponse>

      Promise resolving to ObjectResponse with related objects.

      import { Operator, PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const companyId = 456;

      const response = await repository.loadRelations('company', companyId, 'deals', {
      filter: {
      key: 'status',
      op: Operator.IN,
      exp: ['open', 'in_progress'],
      },
      order: [{ name: 'value', direction: 'DESC' }],
      limit: 20,
      });

      console.log(`Company has ${response.totalCount} open deals`);
      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const companyId = 456;
      const page = 0;
      const pageSize = 25;

      const response = await repository.loadRelations(
      'company',
      companyId,
      'contacts',
      {
      order: [{ name: 'name', direction: 'ASC' }],
      limit: pageSize,
      offset: page * pageSize,
      }
      );

      const contacts = response.objects;
      const totalContacts = response.totalCount;
    • Load a JSON schema for a limetype.

      Fetches the JSON schema definition for the specified limetype and stores it in the repository cache. The schema describes the structure, validation rules, and UI hints for the limetype's properties.

      Schemas are typically used by form builders, validation libraries, and UI generation tools. The generic type parameter allows you to specify the expected schema structure.

      Type Parameters

      • TSchemaType extends Record<string, unknown> = Record<string, unknown>

      Parameters

      • limetype: string

        Name of the limetype to load the schema for.

      Returns Promise<TSchemaType>

      Promise resolving to the schema object.

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const formSchema = await repository.loadSchema('deal');
      import { PlatformServiceName } from '@limetech/lime-web-components';

      interface DealSchema extends Record<string, unknown> {
      properties: {
      name: { type: 'string'; required: true };
      value: { type: 'number'; minimum: 0 };
      status: { type: 'string'; enum: string[] };
      };
      }

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const schema = await repository.loadSchema<DealSchema>('deal');

      console.log(schema.properties.name.required);

      getSchema to retrieve a cached schema without loading

    • Beta

      Search for objects matching a free-text query.

      Searches every limetype that has search enabled, or only the limetypes given in SearchOptions.limetypes. Matching objects are stored in the repository state, and the response carries the number of hits per limetype in SearchResponse.aggregates.

      The query is matched term by term, and each term matches as a prefix, which is what makes search-as-you-type work.

      Parameters

      • text: string

        The text to search for.

      • Optionaloptions: SearchOptions

        Search configuration.

      Returns Promise<SearchResponse>

      Promise resolving to SearchResponse with matching objects.

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const limetypes = platform.get(PlatformServiceName.LimeTypeRepository);
      const repository = platform.get(PlatformServiceName.LimeObjectRepository);

      const company = limetypes.getLimeType('company');

      if (company) {
      const response = await repository.search('Lundalogik', {
      limetypes: [company],
      limit: 25,
      });

      console.log(`Found ${response.objects.length} companies`);
      }
      import { PlatformServiceName } from '@limetech/lime-web-components';

      const limetypes = platform.get(PlatformServiceName.LimeTypeRepository);
      const repository = platform.get(PlatformServiceName.LimeObjectRepository);

      // `limit: 0` reports the counts without returning any objects.
      const response = await repository.search('Lundalogik', { limit: 0 });

      for (const [name, [hits]] of Object.entries(response.aggregates ?? {})) {
      const limetype = limetypes.getLimeType(name);

      console.log(
      `${limetype?.localname.plural ?? name}: ${hits.totalCount ?? 0}`
      );
      }
    • Subscribe to state changes with optional transformation and filtering.

      The subscription will immediately invoke the callback with the current state (if any), then continue to call it whenever the state changes. The map and filter options allow you to transform and selectively receive updates.

      Parameters

      • callback: (...args: unknown[]) => void

        Function called with state updates (after map/filter applied)

      • Optionaloptions: StateOptions

        Optional transformations and filters for the subscription

      Returns () => void

      Unsubscribe function - call this to stop receiving updates

      • Map functions are applied sequentially to transform the state
      • Filter functions must all return true for the callback to be invoked
      • Functions in map/filter arrays are bound to the component instance
      • Always store and call the unsubscribe function when component is destroyed
      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.Application);
      const logger = platform
      .get(PlatformServiceName.Logger)
      .createLogger('my-component');

      // Basic subscription
      const unsubscribeState = repository.subscribe((state) => {
      logger.debug('State updated', { state });
      });

      // With transformations
      const unsubscribeUserName = repository.subscribe(
      (userName) => logger.debug('User', { userName }),
      { map: [(state) => state.currentUser?.fullname] }
      );