SDK collections

Create, list, query, and manage collection records with the EmuView TypeScript SDK.

#SDK collections

The SDK provides a fluent API for working with collection records — listing, creating, updating, deleting, and querying with filters.

#List records

import { EmuView } from '@emuview/sdk';

const sdk = new EmuView({
	url: 'https://your-api.example.com',
	auth: { apiKey: 'sk-your-api-key' }
});

const { data, total } = await sdk.collection('products').list({
	limit: 25,
	page: 1,
	sortBy: '-created_at' // Prefix with "-" for descending
});

console.log(`${total} products total`);
for (const product of data) {
	console.log(product.name, product.price);
}

#Paginate results

list() returns pagination metadata alongside the records:

const result = await sdk.collection('products').list({ limit: 50, page: 1 });

console.log(result.page); // 1
console.log(result.totalPages); // 6
console.log(result.hasMore); // true

For large collections, cursor pagination is faster than page numbers:

const page1 = await sdk.collection('products').list({ limit: 50 });

const page2 = await sdk.collection('products').list({
	limit: 50,
	cursor: page1.cursors?.next
});

#Get a single record

const product = await sdk.collection('products').get('01HXK5M...');
console.log(product.name); // "Wireless Headphones"
console.log(product.price); // 79.99

#Create a record

const newProduct = await sdk.collection('products').create({
	name: 'Wireless Headphones',
	price: 79.99,
	sku: 'WH-100',
	status: 'draft'
});

console.log(newProduct.id); // "01HXK5M..."

#Update a record

const updated = await sdk.collection('products').update('01HXK5M...', {
	price: 69.99,
	status: 'published'
});

#Delete a record

await sdk.collection('products').delete('01HXK5M...');

#Filter records

Pass a filter object matching the MongoDB-style syntax (fully typed as CollectionFilter in the SDK):

const published = await sdk.collection('products').list({
	filter: {
		status: { _eq: 'published' },
		price: { _gte: 10, _lte: 100 }
	},
	sortBy: 'price',
	limit: 50
});

The complete operator set:

Operators Meaning
_eq, _neq equals / not equals (a bare value — { status: 'open' } — is _eq shorthand)
_gt, _gte, _lt, _lte comparisons — combine _gte + _lte for a between-range
_in, _nin value in / not in an array
_null, _nnull true/false null checks
_contains, _ncontains substring match / exclusion
_starts_with, _nstarts_with, _ends_with, _nends_with prefix / suffix matching

Combine conditions with _and / _or groups, filter on belongsTo relations with dot-paths, and match parents by child rows with _some / _none:

await sdk.collection('posts').list({
	filter: {
		_or: [
			{ status: { _eq: 'published' } },
			{ author: { _eq: '$CURRENT_USER' } } // server-resolved variable
		],
		'forum.category_id': { _eq: 'news' }, // relation dot-path (depth ≤ 2)
		comments: { _some: { flagged: { _eq: true } } } // reverse relation
	}
});

#Expand relations

Pass expand as a comma-separated string of relation field names. The related record replaces the raw ID inline:

const orders = await sdk.collection('orders').list({
	expand: 'customer'
});

for (const order of orders.data) {
	// Without expand: order.customer is an ID string
	// With expand: order.customer is the full related record
	console.log(order.customer.name);
}
const results = await sdk.collection('posts').list({
	search: 'svelte deployment'
});

#What you learned

  • sdk.collection('name') returns a fluent builder for that collection
  • .list(), .get(), .create(), .update(), .delete() cover all CRUD operations
  • list() returns { data, total, page, limit, totalPages, hasMore } with optional cursors
  • Filters use the same MongoDB-style object syntax as the REST API
  • expand fetches related records inline
  • search performs full-text search across searchable fields

#Next steps