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:
Name of the limetype (e.g., 'deal', 'company').
ID of the object to delete.
Promise that resolves when deletion is complete.
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.
Name of the limetype.
ID of the object to retrieve.
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.
Name of the limetype to get objects for.
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.
Name of the limetype to get the schema for.
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.
Name of the limetype (e.g., 'deal', 'company', 'person').
Unique identifier of the object to load.
Optionaloptions: Pick<LoadOptions, "properties">Optional configuration to limit which properties are loaded.
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:
Name of the limetype to query (e.g., 'deal', 'company').
Optionaloptions: LoadOptionsQuery configuration including filters, sorting, and pagination.
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.
Name of the limetype that owns the relation (e.g., 'company').
ID of the owning object.
Name of the relation property (e.g., 'deals', 'contacts').
Optionaloptions: LoadOptionsQuery configuration for the related objects.
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.
Name of the limetype to load the schema for.
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
BetaSearch 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.
The text to search for.
Optionaloptions: SearchOptionsSearch configuration.
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.
Function called with state updates (after map/filter applied)
Optionaloptions: StateOptionsOptional transformations and filters for the subscription
Unsubscribe function - call this to stop receiving updates
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] }
);
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:
The repository extends StateRepository, which means:
Example: Use a decorator to get the current object from context
See