@sprucelabs/data-stores 17.1.0 → 18.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,11 +7,19 @@ export default class StoreFactory {
7
7
  private storeMap;
8
8
  private db;
9
9
  private static initializations;
10
+ private stores;
10
11
  private constructor();
11
12
  static Factory(db: Database): StoreFactory;
13
+ /**
14
+ * @deprecated stores.Store(..) -> stores.getStore(...)
15
+ * This change has big speed improvements. This factory method
16
+ * will never be removed, but hopefully won't be needed often.
17
+ */
12
18
  Store<Name extends StoreName, Options extends StoreOptions<Name>>(name: Name, options?: Options): Promise<StoreMap[Name]>;
13
19
  getStoreNames(): StoreName[];
14
- setStore(name: string, TestStore: StoreContructor): void;
20
+ setStoreClass(name: string, TestStore: StoreContructor): void;
21
+ setStore(name: StoreName, store: Store): void;
22
+ getStore<Name extends StoreName>(name: Name): Promise<StoreMap[Name]>;
15
23
  static reset(): void;
16
24
  }
17
25
  export {};
@@ -12,11 +12,17 @@ import SpruceError from '../errors/SpruceError.js';
12
12
  export default class StoreFactory {
13
13
  constructor(db) {
14
14
  this.storeMap = {};
15
+ this.stores = {};
15
16
  this.db = db;
16
17
  }
17
18
  static Factory(db) {
18
19
  return new this(db);
19
20
  }
21
+ /**
22
+ * @deprecated stores.Store(..) -> stores.getStore(...)
23
+ * This change has big speed improvements. This factory method
24
+ * will never be removed, but hopefully won't be needed often.
25
+ */
20
26
  Store(name, options) {
21
27
  var _a;
22
28
  return __awaiter(this, void 0, void 0, function* () {
@@ -45,9 +51,20 @@ export default class StoreFactory {
45
51
  getStoreNames() {
46
52
  return Object.keys(this.storeMap);
47
53
  }
48
- setStore(name, TestStore) {
54
+ setStoreClass(name, TestStore) {
49
55
  this.storeMap[name] = TestStore;
50
56
  }
57
+ setStore(name, store) {
58
+ this.stores[name] = store;
59
+ }
60
+ getStore(name) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ if (!this.stores[name]) {
63
+ this.stores[name] = yield this.Store(name);
64
+ }
65
+ return this.stores[name];
66
+ });
67
+ }
51
68
  static reset() {
52
69
  this.initializations = {};
53
70
  }
@@ -67,7 +67,7 @@ export default class StoreLoader {
67
67
  const { stores, errors } = yield this.loadStoreClassesWithErrors();
68
68
  const factory = StoreFactory.Factory(this.db);
69
69
  for (const store of stores) {
70
- factory.setStore(namesUtil.toCamel(store.namePascal), store.Class);
70
+ factory.setStoreClass(namesUtil.toCamel(store.namePascal), store.Class);
71
71
  }
72
72
  return { factory, errors };
73
73
  });
@@ -7,11 +7,19 @@ export default class StoreFactory {
7
7
  private storeMap;
8
8
  private db;
9
9
  private static initializations;
10
+ private stores;
10
11
  private constructor();
11
12
  static Factory(db: Database): StoreFactory;
13
+ /**
14
+ * @deprecated stores.Store(..) -> stores.getStore(...)
15
+ * This change has big speed improvements. This factory method
16
+ * will never be removed, but hopefully won't be needed often.
17
+ */
12
18
  Store<Name extends StoreName, Options extends StoreOptions<Name>>(name: Name, options?: Options): Promise<StoreMap[Name]>;
13
19
  getStoreNames(): StoreName[];
14
- setStore(name: string, TestStore: StoreContructor): void;
20
+ setStoreClass(name: string, TestStore: StoreContructor): void;
21
+ setStore(name: StoreName, store: Store): void;
22
+ getStore<Name extends StoreName>(name: Name): Promise<StoreMap[Name]>;
15
23
  static reset(): void;
16
24
  }
17
25
  export {};
@@ -8,11 +8,17 @@ const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
8
8
  class StoreFactory {
9
9
  constructor(db) {
10
10
  this.storeMap = {};
11
+ this.stores = {};
11
12
  this.db = db;
12
13
  }
13
14
  static Factory(db) {
14
15
  return new this(db);
15
16
  }
17
+ /**
18
+ * @deprecated stores.Store(..) -> stores.getStore(...)
19
+ * This change has big speed improvements. This factory method
20
+ * will never be removed, but hopefully won't be needed often.
21
+ */
16
22
  async Store(name, options) {
17
23
  var _a;
18
24
  const Store = this.storeMap[name];
@@ -39,9 +45,18 @@ class StoreFactory {
39
45
  getStoreNames() {
40
46
  return Object.keys(this.storeMap);
41
47
  }
42
- setStore(name, TestStore) {
48
+ setStoreClass(name, TestStore) {
43
49
  this.storeMap[name] = TestStore;
44
50
  }
51
+ setStore(name, store) {
52
+ this.stores[name] = store;
53
+ }
54
+ async getStore(name) {
55
+ if (!this.stores[name]) {
56
+ this.stores[name] = await this.Store(name);
57
+ }
58
+ return this.stores[name];
59
+ }
45
60
  static reset() {
46
61
  this.initializations = {};
47
62
  }
@@ -56,7 +56,7 @@ class StoreLoader {
56
56
  const { stores, errors } = await this.loadStoreClassesWithErrors();
57
57
  const factory = StoreFactory_1.default.Factory(this.db);
58
58
  for (const store of stores) {
59
- factory.setStore(spruce_skill_utils_1.namesUtil.toCamel(store.namePascal), store.Class);
59
+ factory.setStoreClass(spruce_skill_utils_1.namesUtil.toCamel(store.namePascal), store.Class);
60
60
  }
61
61
  return { factory, errors };
62
62
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "17.1.0",
6
+ "version": "18.0.0",
7
7
  "files": [
8
8
  "build/**/*",
9
9
  "!build/__tests__",