@stompbox/tape-delay 1.0.9 → 1.0.11

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.
package/dist/index.cjs CHANGED
@@ -52,9 +52,9 @@ const Scope = {
52
52
  ConstantValue
53
53
  };
54
54
  class TapeDelay {
55
- constructor(entries, getEnvironment){
55
+ constructor(entries, environmentDetector){
56
56
  this.entries = entries;
57
- this.getEnvironment = getEnvironment;
57
+ this.environmentDetector = environmentDetector;
58
58
  this.key = Math.random().toString();
59
59
  this.container = (environment)=>{
60
60
  const globalContainer = globalThis;
@@ -96,7 +96,7 @@ class TapeDelay {
96
96
  return container;
97
97
  };
98
98
  this.instance = (entryName)=>{
99
- const environment = this.getEnvironment ? this.getEnvironment() : process.env.NODE_ENV;
99
+ const environment = this.environmentDetector ? this.environmentDetector() : process.env.NODE_ENV;
100
100
  const container = this.container(environment);
101
101
  return container.get(entryName.toString());
102
102
  };
package/dist/index.d.ts CHANGED
@@ -20,23 +20,95 @@ export declare const Scope: {
20
20
  ConstantValue: <T>(value: T) => ConstantValueEntry<T>;
21
21
  };
22
22
  /**
23
- * Tape Delay container.
23
+ * Tape Delay container. Takes entries and optional environment detector in the constructor.
24
24
  *
25
25
  * @example
26
26
  * ```ts
27
- * import { TapeDelay, injectable } from '@stompbox/tape-delay'
27
+ * import { TapeDelay } from '@stompbox/tape-delay'
28
+ * import { UserService } from '@/services/user.service'
28
29
  *
29
- * @injectable()
30
- * class A {}
30
+ * export const container = new TapeDelay({ UserService })
31
31
  *
32
- * const container = new TapeDelay({ A })
32
+ * const userService = container.instance('UserService')
33
33
  * ```
34
34
  */
35
35
  export declare class TapeDelay<T extends Entries> {
36
+ /**
37
+ * Entries describing DI container.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { Singleton } from '@stompbox/tape-delay'
42
+ * import { UserService } from '@/services/user.service'
43
+ * import { UsersInMemory, UsersInPrisma } from '@/stores/user'
44
+ *
45
+ * const entries = {
46
+ * // One implementation for all environments
47
+ * UserService,
48
+ * UserStore: [
49
+ * // Implementation for test environment
50
+ * Singleton(UsersInMemory),
51
+ * // Implementation for development environment
52
+ * UsersInPrisma,
53
+ * // Implementation for production environment
54
+ * UsersInPrisma
55
+ * ]
56
+ * }
57
+ * ```
58
+ */
36
59
  private readonly entries;
37
- private readonly getEnvironment?;
60
+ /**
61
+ * Optional environment detector. `process.env.NODE_ENV` is used by default.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const randomEnvDetector: EnvironmentDetector = () => {
66
+ * if (Math.random() > 0.5) { return 'test' }
67
+ * if (Math.random() > 0.5) { return 'development' }
68
+ * return 'production'
69
+ * }
70
+ * ```
71
+ */
72
+ private readonly environmentDetector?;
38
73
  private readonly key;
39
- constructor(entries: T, getEnvironment?: EnvironmentDetector | undefined);
74
+ constructor(
75
+ /**
76
+ * Entries describing DI container.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * import { Singleton } from '@stompbox/tape-delay'
81
+ * import { UserService } from '@/services/user.service'
82
+ * import { UsersInMemory, UsersInPrisma } from '@/stores/user'
83
+ *
84
+ * const entries = {
85
+ * // One implementation for all environments
86
+ * UserService,
87
+ * UserStore: [
88
+ * // Implementation for test environment
89
+ * Singleton(UsersInMemory),
90
+ * // Implementation for development environment
91
+ * UsersInPrisma,
92
+ * // Implementation for production environment
93
+ * UsersInPrisma
94
+ * ]
95
+ * }
96
+ * ```
97
+ */
98
+ entries: T,
99
+ /**
100
+ * Optional environment detector. `process.env.NODE_ENV` is used by default.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const randomEnvDetector: EnvironmentDetector = () => {
105
+ * if (Math.random() > 0.5) { return 'test' }
106
+ * if (Math.random() > 0.5) { return 'development' }
107
+ * return 'production'
108
+ * }
109
+ * ```
110
+ */
111
+ environmentDetector?: EnvironmentDetector | undefined);
40
112
  private container;
41
113
  instance: <E extends keyof T>(entryName: E) => EntryType<T[E]>;
42
114
  }
package/dist/index.js CHANGED
@@ -21,9 +21,9 @@ const Scope = {
21
21
  ConstantValue: ConstantValue
22
22
  };
23
23
  class TapeDelay {
24
- constructor(entries, getEnvironment){
24
+ constructor(entries, environmentDetector){
25
25
  this.entries = entries;
26
- this.getEnvironment = getEnvironment;
26
+ this.environmentDetector = environmentDetector;
27
27
  this.key = Math.random().toString();
28
28
  this.container = (environment)=>{
29
29
  const globalContainer = globalThis;
@@ -65,7 +65,7 @@ class TapeDelay {
65
65
  return container;
66
66
  };
67
67
  this.instance = (entryName)=>{
68
- const environment = this.getEnvironment ? this.getEnvironment() : process.env.NODE_ENV;
68
+ const environment = this.environmentDetector ? this.environmentDetector() : process.env.NODE_ENV;
69
69
  const container = this.container(environment);
70
70
  return container.get(entryName.toString());
71
71
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stompbox/tape-delay",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "license": "MIT",
5
5
  "description": "Plug-and-play DI based on Inversify",
6
6
  "repository": {