MCPcopy Create free account
hub / github.com/TanStack/db / CollectionImpl

Class CollectionImpl

packages/db/src/collection/index.ts:273–993  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271}
272
273export class CollectionImpl<
274 TOutput extends object = Record<string, unknown>,
275 TKey extends string | number = string | number,
276 TUtils extends UtilsRecord = {},
277 TSchema extends StandardSchemaV1 = StandardSchemaV1,
278 TInput extends object = TOutput,
279> {
280 public id: string
281 public config: CollectionConfig<TOutput, TKey, TSchema>
282
283 // Utilities namespace
284 // This is populated by createCollection
285 public utils: Record<string, Fn> = {}
286
287 // Managers
288 private _events: CollectionEventsManager
289 private _changes: CollectionChangesManager<TOutput, TKey, TSchema, TInput>
290 public _lifecycle: CollectionLifecycleManager<TOutput, TKey, TSchema, TInput>
291 public _sync: CollectionSyncManager<TOutput, TKey, TSchema, TInput>
292 private _indexes: CollectionIndexesManager<TOutput, TKey, TSchema, TInput>
293 private _mutations: CollectionMutationsManager<
294 TOutput,
295 TKey,
296 TUtils,
297 TSchema,
298 TInput
299 >
300 // The core state of the collection is "public" so that is accessible in tests
301 // and for debugging
302 public _state: CollectionStateManager<TOutput, TKey, TSchema, TInput>
303
304 /**
305 * When set, collection consumers should defer processing incoming data
306 * refreshes until this promise resolves. This prevents stale data from
307 * overwriting optimistic state while pending writes are being applied.
308 */
309 public deferDataRefresh: Promise<void> | null = null
310
311 private comparisonOpts: StringCollationConfig
312
313 /**
314 * Creates a new Collection instance
315 *
316 * @param config - Configuration object for the collection
317 * @throws Error if sync config is missing
318 */
319 constructor(config: CollectionConfig<TOutput, TKey, TSchema>) {
320 // eslint-disable-next-line
321 if (!config) {
322 throw new CollectionRequiresConfigError()
323 }
324
325 // eslint-disable-next-line
326 if (!config.sync) {
327 throw new CollectionRequiresSyncConfigError()
328 }
329
330 if (config.id) {

Callers

nothing calls this directly

Calls 2

insertMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected