@nmtjs/core 0.13.0 → 0.14.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.
@@ -10,6 +10,10 @@ export declare const kFactoryInjectable: unique symbol;
10
10
  export type kFactoryInjectable = typeof kFactoryInjectable;
11
11
  export declare const kClassInjectable: unique symbol;
12
12
  export type kClassInjectable = typeof kClassInjectable;
13
+ export declare const kClassInjectableCreate: unique symbol;
14
+ export type kClassInjectableCreate = typeof kClassInjectableCreate;
15
+ export declare const kClassInjectableDispose: unique symbol;
16
+ export type kClassInjectableDispose = typeof kClassInjectableDispose;
13
17
  export declare const kProvider: unique symbol;
14
18
  export type kProvider = typeof kProvider;
15
19
  export declare const kHookCollection: unique symbol;
package/dist/constants.js CHANGED
@@ -4,6 +4,8 @@ export const kLazyInjectable = Symbol.for('neemata:LazyInjectableKey');
4
4
  export const kValueInjectable = Symbol.for('neemata:ValueInjectableKey');
5
5
  export const kFactoryInjectable = Symbol.for('neemata:FactoryInjectableKey');
6
6
  export const kClassInjectable = Symbol.for('neemata:ClassInjectableKey');
7
+ export const kClassInjectableCreate = Symbol.for('neemata:ClassInjectableCreateKey');
8
+ export const kClassInjectableDispose = Symbol.for('neemata:ClassInjectableDisposeKey');
7
9
  export const kProvider = Symbol.for('neemata:ProviderKey');
8
10
  export const kHookCollection = Symbol.for('neemata:HookCollectionKey');
9
11
  export const kPlugin = Symbol.for('neemata:PluginKey');
@@ -1,7 +1,7 @@
1
- import { Scope } from './enums.ts';
2
- import { type AnyInjectable, type Dependencies, type DependencyContext, type ResolveInjectableType } from './injectables.ts';
1
+ import type { AnyInjectable, Dependencies, DependencyContext, ResolveInjectableType } from './injectables.ts';
3
2
  import type { Logger } from './logger.ts';
4
3
  import type { Registry } from './registry.ts';
4
+ import { Scope } from './enums.ts';
5
5
  type InstanceWrapper = {
6
6
  private: any;
7
7
  public: any;
package/dist/container.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import assert from 'node:assert';
2
2
  import { tryCaptureStackTrace } from '@nmtjs/common';
3
+ import { kClassInjectableCreate, kClassInjectableDispose } from "./constants.js";
3
4
  import { Scope } from "./enums.js";
4
5
  import { CoreInjectables, compareScope, createExtendableClassInjectable, createValueInjectable, getDepedencencyInjectable, isClassInjectable, isFactoryInjectable, isInjectable, isLazyInjectable, isOptionalInjectable, isValueInjectable, } from "./injectables.js";
5
6
  export class Container {
@@ -102,11 +103,7 @@ export class Container {
102
103
  throw new Error('Invalid scope'); // TODO: more informative error
103
104
  }
104
105
  this.instances.set(injectable, [
105
- {
106
- private: instance,
107
- public: instance,
108
- context: undefined,
109
- },
106
+ { private: instance, public: instance, context: undefined },
110
107
  ]);
111
108
  }
112
109
  satisfies(injectable) {
@@ -186,7 +183,7 @@ export class Container {
186
183
  else if (isClassInjectable(injectable)) {
187
184
  wrapper.private = new injectable(context);
188
185
  wrapper.public = wrapper.private;
189
- await wrapper.private.$onCreate();
186
+ await wrapper.private[kClassInjectableCreate]();
190
187
  }
191
188
  else {
192
189
  throw new Error('Invalid injectable type');
@@ -201,9 +198,7 @@ export class Container {
201
198
  }
202
199
  createInjectFunction() {
203
200
  const inject = (injectable, context) => {
204
- const dependencies = {
205
- ...injectable.dependencies,
206
- };
201
+ const dependencies = { ...injectable.dependencies };
207
202
  for (const key in context) {
208
203
  const dep = context[key];
209
204
  if (isInjectable(dep) || isOptionalInjectable(dep)) {
@@ -307,7 +302,7 @@ export class Container {
307
302
  await dispose(instance, context);
308
303
  }
309
304
  else if (isClassInjectable(injectable)) {
310
- await instance.$onDispose();
305
+ await instance[kClassInjectableDispose]();
311
306
  }
312
307
  }
313
308
  }
package/dist/hooks.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Callback } from '@nmtjs/common';
2
- import { kHookCollection } from './constants.ts';
3
2
  import type { Hook } from './enums.ts';
3
+ import { kHookCollection } from './constants.ts';
4
4
  export interface HookType {
5
5
  [key: string]: (...args: any[]) => any;
6
6
  }
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- // biome-ignore lint/correctness/noUnusedImports: TSC wants it
2
- // biome-ignore assist/source/organizeImports: TSC wants it
3
- import {} from 'pino';
1
+ // // biome-ignore lint/correctness/noUnusedImports: TSC wants it
2
+ // // biome-ignore assist/source/organizeImports: TSC wants it
3
+ // import {} from 'pino'
4
4
  export * from "./constants.js";
5
5
  export * from "./container.js";
6
6
  export * from "./enums.js";
@@ -1,9 +1,11 @@
1
- import { type Async, type ClassConstructor, type ClassConstructorArgs, type ClassInstance } from '@nmtjs/common';
2
- import { kClassInjectable, kFactoryInjectable, kInjectable, kLazyInjectable, kOptionalDependency, kValueInjectable } from './constants.ts';
3
- import { type Hook, Scope } from './enums.ts';
4
- import { Hooks, type HookType } from './hooks.ts';
1
+ import type { Async, ClassConstructor, ClassConstructorArgs, ClassInstance } from '@nmtjs/common';
2
+ import type { Hook } from './enums.ts';
3
+ import type { HookType } from './hooks.ts';
5
4
  import type { Logger } from './logger.ts';
6
5
  import type { Registry } from './registry.ts';
6
+ import { kClassInjectable, kClassInjectableCreate, kClassInjectableDispose, kFactoryInjectable, kInjectable, kLazyInjectable, kOptionalDependency, kValueInjectable } from './constants.ts';
7
+ import { Scope } from './enums.ts';
8
+ import { Hooks } from './hooks.ts';
7
9
  export type DependencyOptional<T extends AnyInjectable = AnyInjectable> = {
8
10
  [kOptionalDependency]: any;
9
11
  injectable: T;
@@ -81,8 +83,8 @@ export declare function createFactoryInjectable<T, D extends Dependencies = {},
81
83
  export declare const createClassInjectable: <D extends Dependencies = {}, S extends Scope = Scope.Global>(dependencies?: D, scope?: S, stackTraceDepth?: number) => ClassInjectable<ClassInstance<{
82
84
  new ($context: DependencyContext<D>): {
83
85
  $context: DependencyContext<D>;
84
- $onCreate(): Promise<void>;
85
- $onDispose(): Promise<void>;
86
+ [kClassInjectableCreate](): Promise<void>;
87
+ [kClassInjectableDispose](): Promise<void>;
86
88
  };
87
89
  dependencies: D;
88
90
  scope: S;
@@ -1,5 +1,5 @@
1
- import { tryCaptureStackTrace, } from '@nmtjs/common';
2
- import { kClassInjectable, kFactoryInjectable, kHookCollection, kInjectable, kLazyInjectable, kOptionalDependency, kValueInjectable, } from "./constants.js";
1
+ import { tryCaptureStackTrace } from '@nmtjs/common';
2
+ import { kClassInjectable, kClassInjectableCreate, kClassInjectableDispose, kFactoryInjectable, kHookCollection, kInjectable, kLazyInjectable, kOptionalDependency, kValueInjectable, } from "./constants.js";
3
3
  import { Scope } from "./enums.js";
4
4
  import { Hooks } from "./hooks.js";
5
5
  const ScopeStrictness = {
@@ -94,8 +94,8 @@ export const createClassInjectable = (dependencies = {}, scope, stackTraceDepth
94
94
  constructor($context) {
95
95
  this.$context = $context;
96
96
  }
97
- async $onCreate() { }
98
- async $onDispose() { }
97
+ async [kClassInjectableCreate]() { }
98
+ async [kClassInjectableDispose]() { }
99
99
  };
100
100
  InjectableClass.scope = resolveInjectableScope(typeof scope === 'undefined', InjectableClass);
101
101
  return InjectableClass;
@@ -163,10 +163,7 @@ export function substitute(injectable, substitution, stackTraceDepth = 0) {
163
163
  }
164
164
  else if (isFactoryInjectable(injectable)) {
165
165
  // @ts-expect-error
166
- return createFactoryInjectable({
167
- ...injectable,
168
- dependencies,
169
- }, injectable.label, depth);
166
+ return createFactoryInjectable({ ...injectable, dependencies }, injectable.label, depth);
170
167
  }
171
168
  throw new Error('Invalid injectable type');
172
169
  }
@@ -221,10 +218,4 @@ function resolveInjectableScope(isDefaultScope, injectable) {
221
218
  throw new Error(`Invalid scope ${injectable.scope} for an injectable: dependencies have stricter scope - ${actualScope}`);
222
219
  return actualScope;
223
220
  }
224
- export const CoreInjectables = {
225
- logger,
226
- registry,
227
- inject,
228
- dispose,
229
- hook,
230
- };
221
+ export const CoreInjectables = { logger, registry, inject, dispose, hook };
package/dist/logger.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { type DestinationStream, type Level, type LoggerOptions, type Logger as PinoLogger, pino, type StreamEntry } from 'pino';
1
+ import type { DestinationStream, Level, LoggerOptions, Logger as PinoLogger, StreamEntry } from 'pino';
2
+ import { pino } from 'pino';
2
3
  export type { StreamEntry } from 'pino';
3
4
  export type Logger = PinoLogger;
4
5
  export type LoggingOptions = {
package/dist/logger.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { threadId } from 'node:worker_threads';
2
- import { pino, stdTimeFunctions, } from 'pino';
2
+ import { pino, stdTimeFunctions } from 'pino';
3
3
  import { build as pretty } from 'pino-pretty';
4
4
  // TODO: use node:util inspect
5
5
  const bg = (value, color) => `\x1b[${color}m${value}\x1b[0m`;
@@ -40,11 +40,7 @@ export const createLogger = (options = {}, $group) => {
40
40
  ? pino.levels.values[destination.level]
41
41
  : Number.POSITIVE_INFINITY), Number.POSITIVE_INFINITY);
42
42
  const level = pino.levels.labels[lowestLevelValue];
43
- return pino({
44
- timestamp: stdTimeFunctions.isoTime,
45
- ...pinoOptions,
46
- level,
47
- }, pino.multistream(destinations)).child({ $group, $threadId: threadId });
43
+ return pino({ timestamp: stdTimeFunctions.isoTime, ...pinoOptions, level }, pino.multistream(destinations)).child({ $group, $threadId: threadId });
48
44
  };
49
45
  export const createConsolePrettyDestination = (level, sync = true) => ({
50
46
  level,
package/dist/plugin.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Async } from '@nmtjs/common';
2
- import { kPlugin } from './constants.ts';
3
2
  import type { PluginContext } from './types.ts';
3
+ import { kPlugin } from './constants.ts';
4
4
  export interface BasePlugin<Type = any, Options = unknown, Context extends PluginContext = PluginContext> {
5
5
  name: string;
6
6
  init: (context: Context, options: Options) => Async<Type>;
@@ -1,7 +1,9 @@
1
- import { type Hook, Scope } from './enums.ts';
2
- import { Hooks, type HookType } from './hooks.ts';
3
- import { type AnyInjectable, type Dependant } from './injectables.ts';
1
+ import type { Hook } from './enums.ts';
2
+ import type { HookType } from './hooks.ts';
3
+ import type { AnyInjectable, Dependant } from './injectables.ts';
4
4
  import type { Logger } from './logger.ts';
5
+ import { Scope } from './enums.ts';
6
+ import { Hooks } from './hooks.ts';
5
7
  export declare class Registry {
6
8
  protected readonly application: {
7
9
  logger: Logger;
package/dist/registry.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Scope } from "./enums.js";
2
2
  import { Hooks } from "./hooks.js";
3
- import { getInjectableScope, } from "./injectables.js";
3
+ import { getInjectableScope } from "./injectables.js";
4
4
  export class Registry {
5
5
  application;
6
6
  hooks = new Hooks();
package/package.json CHANGED
@@ -6,27 +6,32 @@
6
6
  "types": "./dist/index.d.ts",
7
7
  "import": "./dist/index.js",
8
8
  "module-sync": "./dist/index.js"
9
+ },
10
+ "./constants": {
11
+ "types": "./dist/constants.d.ts",
12
+ "import": "./dist/constants.js",
13
+ "module-sync": "./dist/constants.js"
9
14
  }
10
15
  },
11
16
  "peerDependencies": {
12
17
  "pino": "^9.6.0",
13
18
  "pino-pretty": "^13.0.0",
14
- "@nmtjs/common": "0.13.0",
15
- "@nmtjs/type": "0.13.0"
19
+ "@nmtjs/common": "0.14.0",
20
+ "@nmtjs/type": "0.14.0"
16
21
  },
17
22
  "devDependencies": {
18
23
  "@types/node": "^20",
19
24
  "pino": "^9.6.0",
20
25
  "pino-pretty": "^13.0.0",
21
- "@nmtjs/common": "0.13.0",
22
- "@nmtjs/type": "0.13.0"
26
+ "@nmtjs/common": "0.14.0",
27
+ "@nmtjs/type": "0.14.0"
23
28
  },
24
29
  "files": [
25
30
  "dist",
26
31
  "LICENSE.md",
27
32
  "README.md"
28
33
  ],
29
- "version": "0.13.0",
34
+ "version": "0.14.0",
30
35
  "scripts": {
31
36
  "build": "tsc",
32
37
  "type-check": "tsc --noEmit"