What is Sequence

The module a-sequence provides a sequence feature, which can provide a unique sequence value for a specific business, such as assigning a unique name when creating a new atom draft

Definition of Sequence

Configure sequence in the meta of the module

src/module/test-party/backend/src/meta.js

sequence: {
  providers: {
    test: {
      start: 0,
      expression({ ctx, value }) {
        return ++value;
      },
    },
  },
},
Name Description
test sequence name
test.start initial value
test.expression create a new value, supporting asynchronous function

Operations

Module a-sequence injects sequence into ctx.meta through middleware mechanism, which can facilitate the operations of sequence

src/module/test-party/backend/src/controller/test/feat/sequence.js

current

let current = await this.ctx.meta.sequence.current('test');

next

let next = await this.ctx.meta.sequence.next('test');

reset

await this.ctx.meta.sequence.reset('test');

Across Module

You can access the sequence values of other modules

// other module's sequence
const moduleSequence = this.ctx.meta.sequence.module(`test-party`);
// next
let next = await moduleSequence.next('test');