@shipengine/connect
Version:
The official developer tooling for building ShipEngine connect apps
29 lines • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.inMemorySequence = void 0;
const inMemorySequence = () => {
const sequences = {};
return {
create: async (request) => {
if (sequences[request.uid]) {
throw new Error(`Sequence ${request.uid} already exists`);
}
sequences[request.uid] = {
value: request.current,
request: request,
};
},
next: async (identifier) => {
const sequence = sequences[identifier];
if (!sequence) {
throw new Error(`Sequence ${identifier} does not exist`);
}
if (sequence.value + 1 > sequence.request.to) {
throw new Error(`Number range has reached maximum value. Please update the number range with id: \'${identifier}\'`);
}
return (sequence.value += 1);
},
};
};
exports.inMemorySequence = inMemorySequence;
//# sourceMappingURL=in-memory-sequence.js.map