API Reference

sequence-id

API entries in this module: 5

Current sequence-id implementation

This module returns the same id for matching sequence payloads in a specific context object. When the same context and sequence are used again, rs-x reuses the same sequence-id handle.

create(context, sequence) creates or reuses a handle. get(context, sequence) only reads an existing handle. release(context, id) releases one reference for that handle.

The default singleton service is SequenceIdFactory, resolved through RsXCoreInjectionTokens.ISequenceIdFactory. If you call create, call dispose() on the returned handle (or call release) when finished to prevent memory leaks.

Example: use ISequenceIdFactory

import {
  InjectionContainer,
  RsXCoreInjectionTokens,
  RsXCoreModule,
  type ISequenceIdFactory,
} from '@rs-x/core';

await InjectionContainer.load(RsXCoreModule);

const sequenceIdFactory = InjectionContainer.get<ISequenceIdFactory>(
  RsXCoreInjectionTokens.ISequenceIdFactory,
);

const context = {};
const sequence = ['user', 'profile', 'name'];

const handle = sequenceIdFactory.create(context, sequence);
console.log(handle.id);

const sameHandle = sequenceIdFactory.get(context, sequence);
console.log(sameHandle?.id === handle.id); // true

Example: inject into constructor

import {
  Inject,
  RsXCoreInjectionTokens,
  type ISequenceIdFactory,
} from '@rs-x/core';

class SequenceConsumer {
  constructor(
    @Inject(RsXCoreInjectionTokens.ISequenceIdFactory)
    private readonly sequenceIdFactory: ISequenceIdFactory,
  ) {}

  track(context: object, path: unknown[]): string {
    const handle = this.sequenceIdFactory.create(context, path);
    try {
      return handle.id;
    } finally {
      handle.dispose();
    }
  }
}

Module API entries