UNPKG

1.32 kBJavaScriptView Raw
1"use strict";
2/*
3 * @adonisjs/lucid
4 *
5 * (c) Harminder Virk <virk@adonisjs.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10Object.defineProperty(exports, "__esModule", { value: true });
11exports.FactoryManager = void 0;
12const FactoryModel_1 = require("./FactoryModel");
13/**
14 * Factory manager exposes the API to register factories.
15 */
16class FactoryManager {
17 constructor() {
18 Object.defineProperty(this, "stubCounter", {
19 enumerable: true,
20 configurable: true,
21 writable: true,
22 value: 1
23 });
24 Object.defineProperty(this, "stubIdCallback", {
25 enumerable: true,
26 configurable: true,
27 writable: true,
28 value: (counter) => counter
29 });
30 }
31 /**
32 * Returns the next id
33 */
34 getNextId(model) {
35 return this.stubIdCallback(this.stubCounter++, model);
36 }
37 /**
38 * Define a factory model
39 */
40 define(model, callback) {
41 return new FactoryModel_1.FactoryModel(model, callback, this);
42 }
43 /**
44 * Define custom callback to generate stub ids
45 */
46 stubId(callback) {
47 this.stubIdCallback = callback;
48 }
49}
50exports.FactoryManager = FactoryManager;