API Reference

Complete reference for IgniterCollectionsBuilder, IgniterCollectionModelBuilder, IgniterCollectionViewBuilder, and all manager types.

API Reference

Complete reference for all public builders, managers, and types in @igniter-js/collections.


IgniterCollectionsBuilder

The main entry point. Creates the collections manager.

import { IgniterCollections } from '@igniter-js/collections';

Static Methods

MethodReturnsDescription
IgniterCollections.create()IgniterCollectionsBuilder<{}>Create a new builder instance

Builder Methods

MethodParametersReturnsDescription
withAdapter(adapter)IgniterCollectionAdapterBuilderSet the storage adapter (required)
withBasePath(path)string | string[]BuilderSet content root path(s)
addCollection(collection)IgniterCollectionModelDefinitionBuilder with added typeRegister a collection
addView(view)IgniterCollectionViewDefinitionBuilderRegister a programmatic view
withWatcher(paths, opts?)string | string[], { collections?, views?, autoWatch? }BuilderEnable auto-discovery
withContext(factory)() => unknown | Promise<unknown>BuilderInject dependencies into hooks
withGlobalHooks(hooks)IgniterCollectionModelHooksBuilderHooks for all collections
withTelemetry(telemetry)IgniterTelemetryManagerBuilderObservability integration
withLogger(logger)IgniterLoggerBuilderCustom logger
build()IIgniterCollectionsManagerBuild the manager

Returned Manager (build())

The returned manager provides:

interface IIgniterCollectionsManager<TCollections> {
  // Dynamic collection access (e.g., docs.posts.create())
  [collectionName]: IIgniterCollectionModel;

  // Subscribe to events
  on(event, handler): IgniterCollectionSubscription;

  // Manual refresh
  refresh(): Promise<void>;

  // Namespaces
  readonly views: IIgniterCollectionViewManager;
  readonly collections: IIgniterCollectionsAccessor;
  readonly watcher: IIgniterCollectionWatcher;
}

IgniterCollectionModelBuilder

Defines a collection's schema, patterns, hooks, and sub-collections.

import { IgniterCollectionModel } from '@igniter-js/collections';

Static Methods

MethodParametersReturnsDescription
IgniterCollectionModel.create(name)stringBuilderCreate a new collection builder

Builder Methods

MethodParametersReturnsDescription
withPatterns(patterns)string[]BuilderSet file patterns (e.g., ['posts/{id}.mdx'])
withSchema(schema)StandardSchemaV1 (Zod)Builder with inferred typeSet frontmatter validation schema
onCreated(hook)(ctx) => value | falseBuilderHook before document creation
onUpdated(hook)(ctx) => value | falseBuilderHook before document update
onDeleted(hook)(ctx) => booleanBuilderHook before document deletion
onRead(hook)(ctx) => value | falseBuilderHook after document read
onList(hook)(ctx) => values | falseBuilderHook after document listing
collections.create(name)stringSubCollectionBuilderCreate a sub-collection
build()IgniterCollectionModelDefinitionBuild the collection definition

Collection Manager (IIgniterCollectionModel)

The CRUD interface returned by docs.posts (or docs.collections.get('posts')).

Methods

MethodParametersReturns
create(args){ data, id?, select?, exclude? }Promise<Document<TSchema>>
findUnique(args){ where: { id }, select?, exclude? }Promise<Document<TSchema> | null>
findMany(args?){ where?, orderBy?, take?, skip?, select?, exclude?, include? }Promise<Document<TSchema>[]>
update(args){ where: { id }, data, select?, exclude? }Promise<Document<TSchema>>
delete(args){ where: { id }, select?, exclude? }Promise<Document<TSchema>>
count(args?){ where? }Promise<number>
on(event, handler)string, (data) => voidIgniterCollectionSubscription

IgniterCollectionViewBuilder

Defines a declarative view with data hooks and UI component trees.

import { IgniterCollectionView } from '@igniter-js/collections';

Static Methods

MethodParametersReturnsDescription
IgniterCollectionView.create(name)stringBuilderCreate a new view builder

Builder Methods

MethodParametersReturnsDescription
withTitle(title)stringBuilderDisplay title
withDescription(desc)stringBuilderView description
withMetadata(meta)Record<string, any>BuilderUI metadata (icon, order, etc.)
withData(hook)(ctx) => Promise<any>BuilderData hook (required)
withTree(tree)ViewNode[]BuilderComponent tree
addAction(name, action)string, ViewActionBuilderExecutable action
build()IgniterCollectionViewDefinitionBuild view definition

IgniterCollectionsAccessor

Provides explicit access to collection managers.

interface IIgniterCollectionsAccessor<TCollections> {
  get(name): IIgniterCollectionModel;   // Get a collection manager
  list(): Array<{ name, patterns, schema, source }>;  // List all collections
  entries(): Record<string, { name, patterns, schema, source }>;
}

IgniterCollectionWatcher

Controls the file watcher.

interface IIgniterCollectionWatcher {
  start(): Promise<boolean>;  // Start watching
  stop(): void;               // Stop watching
  readonly isWatching: boolean; // Current state
}

Where Clause Operators

Scalar Operators (IgniterCollectionScalarFilterOperators<T>)

OperatorTypeDescription
equalsTExact match
notTNot equal
inT[]In array of values
notInT[]Not in array
ltTLess than
lteTLess than or equal
gtTGreater than
gteTGreater than or equal
containsstringSubstring match (strings only)
startsWithstringStarts with (strings only)
endsWithstringEnds with (strings only)

Array Operators (IgniterCollectionArrayFilterOperators<T>)

OperatorTypeDescription
hasTArray contains value
hasEveryT[]Array contains ALL values
hasSomeT[]Array contains at least ONE value
isEmptybooleanArray is empty or not
lengthnumberArray length equals

Search Filter (IgniterCollectionSearchFilter<T>)

FieldTypeDefaultDescription
termstring | string[]requiredSearch terms
fieldsSearchFields<T>Common fieldsField weights and fuzziness
thresholdnumber (0-1)0.2Minimum score
fuzzybooleanfalseEnable fuzzy matching
includeSubCollectionsbooleanfalseSearch sub-collections

Error Codes

All codes exported from IGNITER_COLLECTION_ERROR_CODES:

CodeDescription
COLLECTION_ADAPTER_REQUIREDAdapter not configured
COLLECTION_NOT_FOUNDCollection not in registry
COLLECTION_DOCUMENT_NOT_FOUNDDocument not found at path
COLLECTION_VALIDATION_ERRORSchema validation failed
COLLECTION_HOOK_CANCELLEDHook returned false
COLLECTION_PARSE_ERRORFailed to parse frontmatter
COLLECTION_WRITE_ERRORFailed to write document
COLLECTION_DELETE_ERRORFailed to delete document
COLLECTION_REGISTRY_ERRORSchema registry load failed
COLLECTION_VIEW_NOT_FOUNDView not found
COLLECTION_ACTION_NOT_FOUNDAction not found
COLLECTION_CONTEXT_FACTORY_ERRORContext factory failed

Next Steps