@praxisjs/di 0.1.0 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @praxisjs/di
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bb0d4f8: **Refactor decorator system and component architecture across PraxisJS packages**
8
+
9
+ - Replaced legacy decorator signatures (`constructor`, `target`, `propertyKey`, method descriptor) with the standard TC39 decorator context API (`ClassDecoratorContext`, `ClassFieldDecoratorContext`, `ClassMethodDecoratorContext`) across `@praxisjs/decorators`, `@praxisjs/store`, `@praxisjs/concurrent`, `@praxisjs/router`, `@praxisjs/motion`, `@praxisjs/di`, and `@praxisjs/fsm`.
10
+ - Introduced `StatefulComponent` and `StatelessComponent` as the new base classes, replacing the deprecated `BaseComponent`/`Function Component` pattern, across `@praxisjs/core`, `@praxisjs/runtime`, `@praxisjs/devtools`, and templates.
11
+ - Implemented core rendering functionality in `@praxisjs/runtime` (`mountChildren`, `mountComponent`, reactive scope management) and removed the deprecated `renderer.ts`.
12
+ - Refactored `@praxisjs/jsx` to delegate rendering to `@praxisjs/runtime` and improved type safety with `flattenChildren` and `isComponent` utilities.
13
+ - Updated internal module structure with new `internal` exports in `package.json` files for shared utilities and types.
14
+ - Removed `experimentalDecorators`/`emitDecoratorMetadata` from `tsconfig.json` in favor of native decorator support.
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [bb0d4f8]
19
+ - @praxisjs/core@0.3.0
20
+
21
+ ## 0.1.1
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [f48dbc4]
26
+ - @praxisjs/core@0.2.0
27
+
3
28
  ## 0.1.0
4
29
 
5
30
  ### Minor Changes
package/dist/container.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export class Token {
2
+ description;
2
3
  constructor(description) {
3
4
  this.description = description;
4
5
  }
@@ -10,8 +11,9 @@ export function token(description) {
10
11
  return new Token(description);
11
12
  }
12
13
  export class Container {
14
+ services = new Map();
15
+ parent;
13
16
  constructor(parent) {
14
- this.services = new Map();
15
17
  this.parent = parent;
16
18
  }
17
19
  register(target, options = {}) {
@@ -1 +1 @@
1
- {"version":3,"file":"container.js","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAcA,MAAM,OAAO,KAAK;IAEhB,YAAY,WAAmB;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IACD,QAAQ;QACN,OAAO,SAAS,IAAI,CAAC,WAAW,GAAG,CAAC;IACtC,CAAC;CACF;AAED,MAAM,UAAU,KAAK,CAAI,WAAmB;IAC1C,OAAO,IAAI,KAAK,CAAI,WAAW,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,OAAO,SAAS;IAOpB,YAAY,MAAkB;QANb,aAAQ,GAAG,IAAI,GAAG,EAGhC,CAAC;QAIF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,QAAQ,CAAI,MAAsB,EAAE,UAA6B,EAAE;QACjE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE;YACxB,MAAM;YACN,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,WAAW;SACR,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,aAAa,CAAI,KAAe,EAAE,KAAQ;QACxC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,eAAe,CACb,KAAe,EACf,OAAoC;QAEpC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CAAI,MAAiC;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,C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AI,EAAE,CAAC;QAEtG,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAkB,CAAC,CAAC,CAAC;QACzE,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC;QAE7C,MAAM,iBAAiB,GAAY,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,SAAmB,CAAC,CAAC;QAC/F,MAAM,cAAc,GACjB,iBAA2E,IAAI,IAAI,GAAG,EAAwC,CAAC;QAElI,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,cAAc,EAAE,CAAC;YACxC,QAAoC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CACxD,GAAkB,CACnB,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,WAAW;QACT,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { type Container, Token, type Constructor, type InjectableOptions } from "./container";
2
- export declare function Injectable(options?: InjectableOptions): <T extends Constructor>(target: T) => T;
3
- export declare function Inject<T>(dep: Constructor<T> | Token<T>): (target: object, propertyKey: string) => void;
4
- export declare function InjectContainer(): (target: object, propertyKey: string) => void;
2
+ export declare function Injectable(options?: InjectableOptions): (value: Constructor, _context: ClassDecoratorContext) => void;
3
+ export declare function Inject<T>(dep: Constructor<T> | Token<T>): (_value: undefined, context: ClassFieldDecoratorContext) => void;
4
+ export declare function InjectContainer(): (_value: undefined, context: ClassFieldDecoratorContext) => void;
5
5
  export declare function useService<T>(dep: Constructor<T> | Token<T>): T;
6
6
  export declare function createScope(configure?: (c: Container) => void): Container;
7
7
  //# sourceMappingURL=decorators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,SAAS,EAAE,KAAK,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAG,MAAM,aAAa,CAAC;AAE1G,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,IACvC,CAAC,SAAS,WAAW,EAAE,QAAQ,CAAC,KAAG,CAAC,CAItD;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAGrC,QAAQ,MAAM,EAAE,aAAa,MAAM,KAAG,IAAI,CAiC5D;AAED,wBAAgB,eAAe,KACZ,QAAQ,MAAM,EAAE,aAAa,MAAM,KAAG,IAAI,CAS5D;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAE/D;AAED,wBAAgB,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,IAAI,GAAG,SAAS,CAIzE"}
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,SAAS,EAAE,KAAK,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAG,MAAM,aAAa,CAAC;AAE1G,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,IACvC,OAAO,WAAW,EAAE,UAAU,qBAAqB,KAAG,IAAI,CAG5E;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IACrC,QAAQ,SAAS,EAAE,SAAS,0BAA0B,KAAG,IAAI,CAsC/E;AAED,wBAAgB,eAAe,KACZ,QAAQ,SAAS,EAAE,SAAS,0BAA0B,KAAG,IAAI,CAW/E;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAE/D;AAED,wBAAgB,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,IAAI,GAAG,SAAS,CAIzE"}
@@ -1,47 +1,51 @@
1
1
  import { container, Token } from "./container";
2
2
  export function Injectable(options = {}) {
3
- return function (target) {
4
- container.register(target, options);
5
- return target;
3
+ return function (value, _context) {
4
+ container.register(value, options);
6
5
  };
7
6
  }
8
7
  export function Inject(dep) {
9
- const cache = new WeakMap();
10
- return function (target, propertyKey) {
11
- Object.defineProperty(target, propertyKey, {
12
- get() {
13
- if (!cache.has(this)) {
14
- let resolved;
15
- try {
16
- resolved = container.resolve(dep);
8
+ return function (_value, context) {
9
+ const cache = new WeakMap();
10
+ const propertyKey = String(context.name);
11
+ context.addInitializer(function () {
12
+ Object.defineProperty(this, context.name, {
13
+ get() {
14
+ if (!cache.has(this)) {
15
+ let resolved;
16
+ try {
17
+ resolved = container.resolve(dep);
18
+ }
19
+ catch (err) {
20
+ throw new Error(`[Inject] Failed to resolve "${dep instanceof Token
21
+ ? dep.toString()
22
+ : dep.name}" in "${this.constructor.name}.${propertyKey}": ${err.message}`);
23
+ }
24
+ cache.set(this, resolved);
17
25
  }
18
- catch (err) {
19
- throw new Error(`[Inject] Failed to resolve "${dep instanceof Token
20
- ? dep.toString()
21
- : dep.name}" in "${this.constructor.name}.${propertyKey}": ${err.message}`);
26
+ return cache.get(this);
27
+ },
28
+ set(_value) {
29
+ if (process.env.NODE_ENV !== "production") {
30
+ console.warn(`[Inject] "${propertyKey}" is managed by the DI container and cannot be assigned directly.`);
22
31
  }
23
- cache.set(this, resolved);
24
- }
25
- return cache.get(this);
26
- },
27
- set(_value) {
28
- if (process.env.NODE_ENV !== "production") {
29
- console.warn(`[Inject] "${propertyKey}" is managed by the DI container and cannot be assigned directly.`);
30
- }
31
- },
32
- enumerable: true,
33
- configurable: true,
32
+ },
33
+ enumerable: true,
34
+ configurable: true,
35
+ });
34
36
  });
35
37
  };
36
38
  }
37
39
  export function InjectContainer() {
38
- return function (target, propertyKey) {
39
- Object.defineProperty(target, propertyKey, {
40
- get() {
41
- return container;
42
- },
43
- enumerable: true,
44
- configurable: true,
40
+ return function (_value, context) {
41
+ context.addInitializer(function () {
42
+ Object.defineProperty(this, context.name, {
43
+ get() {
44
+ return container;
45
+ },
46
+ enumerable: true,
47
+ configurable: true,
48
+ });
45
49
  });
46
50
  };
47
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAkB,KAAK,EAA6C,MAAM,aAAa,CAAC;AAE1G,MAAM,UAAU,UAAU,CAAC,UAA6B,EAAE;IACxD,OAAO,UAAiC,MAAS;QAC/C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACpC,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,MAAM,CAAI,GAA8B;IACtD,MAAM,KAAK,GAAG,IAAI,OAAO,EAAa,CAAC;IAEvC,OAAO,UAAU,MAAc,EAAE,WAAmB;QAClD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;YACzC,GAAG;gBACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBACrB,IAAI,QAAW,CAAC;oBAChB,IAAI,CAAC;wBACH,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC,GAAqB,CAAC,CAAC;oBACtD,CAAC;oBAAC,OAAO,GAAG,EAAE,CAAC;wBACb,MAAM,IAAI,KAAK,CACb,+BACE,GAAG,YAAY,KAAK;4BAClB,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE;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,CAAC;gBACH,CAAC;gBAED,UAAU,EAAE,IAAI;gBAChB,YAAY,EAAE,IAAI;aACnB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,UAAU,MAAiB,EAAE,OAAmC;QACrE,OAAO,CAAC,cAAc,CAAC;YACrB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE;gBACxC,GAAG;oBACD,OAAO,SAAS,CAAC;gBACnB,CAAC;gBACD,UAAU,EAAE,IAAI;gBAChB,YAAY,EAAE,IAAI;aACnB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAI,GAA8B;IAC1D,OAAO,SAAS,CAAC,OAAO,CAAC,GAAqB,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,SAAkC;IAC5D,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;IACtC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC;IACnB,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@praxisjs/di",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "reflect-metadata": "^0.2.2",
15
- "@praxisjs/core": "0.1.0"
15
+ "@praxisjs/core": "0.3.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/node": "^25.3.0",
package/src/decorators.ts CHANGED
@@ -1,58 +1,62 @@
1
1
  import { container, type Container, Token, type Constructor, type InjectableOptions } from "./container";
2
2
 
3
3
  export function Injectable(options: InjectableOptions = {}) {
4
- return function <T extends Constructor>(target: T): T {
5
- container.register(target, options);
6
- return target;
4
+ return function (value: Constructor, _context: ClassDecoratorContext): void {
5
+ container.register(value, options);
7
6
  };
8
7
  }
9
8
 
10
9
  export function Inject<T>(dep: Constructor<T> | Token<T>) {
11
- const cache = new WeakMap<object, T>();
10
+ return function (_value: undefined, context: ClassFieldDecoratorContext): void {
11
+ const cache = new WeakMap<object, T>();
12
+ const propertyKey = String(context.name);
12
13
 
13
- return function (target: object, propertyKey: string): void {
14
- Object.defineProperty(target, propertyKey, {
15
- get(this: object): T {
16
- if (!cache.has(this)) {
17
- let resolved: T;
18
- try {
19
- resolved = container.resolve(dep as Constructor<T>);
20
- } catch (err) {
21
- throw new Error(
22
- `[Inject] Failed to resolve "${
23
- dep instanceof Token
24
- ? dep.toString()
25
- : (dep as Constructor).name
26
- }" in "${(this as { constructor: { name: string } }).constructor.name}.${propertyKey}": ${(err as Error).message}`,
27
- );
14
+ context.addInitializer(function (this: unknown) {
15
+ Object.defineProperty(this, context.name, {
16
+ get(this: object): T {
17
+ if (!cache.has(this)) {
18
+ let resolved: T;
19
+ try {
20
+ resolved = container.resolve(dep as Constructor<T>);
21
+ } catch (err) {
22
+ throw new Error(
23
+ `[Inject] Failed to resolve "${
24
+ dep instanceof Token
25
+ ? dep.toString()
26
+ : (dep as Constructor).name
27
+ }" in "${(this as { constructor: { name: string } }).constructor.name}.${propertyKey}": ${(err as Error).message}`,
28
+ );
29
+ }
30
+ cache.set(this, resolved);
28
31
  }
29
- cache.set(this, resolved);
30
- }
31
- return cache.get(this) as T;
32
- },
32
+ return cache.get(this) as T;
33
+ },
33
34
 
34
- set(_value: unknown): void {
35
- if (process.env.NODE_ENV !== "production") {
36
- console.warn(
37
- `[Inject] "${propertyKey}" is managed by the DI container and cannot be assigned directly.`,
38
- );
39
- }
40
- },
35
+ set(_value: unknown): void {
36
+ if (process.env.NODE_ENV !== "production") {
37
+ console.warn(
38
+ `[Inject] "${propertyKey}" is managed by the DI container and cannot be assigned directly.`,
39
+ );
40
+ }
41
+ },
41
42
 
42
- enumerable: true,
43
- configurable: true,
43
+ enumerable: true,
44
+ configurable: true,
45
+ });
44
46
  });
45
47
  };
46
48
  }
47
49
 
48
50
  export function InjectContainer() {
49
- return function (target: object, propertyKey: string): void {
50
- Object.defineProperty(target, propertyKey, {
51
- get() {
52
- return container;
53
- },
54
- enumerable: true,
55
- configurable: true,
51
+ return function (_value: undefined, context: ClassFieldDecoratorContext): void {
52
+ context.addInitializer(function (this: unknown) {
53
+ Object.defineProperty(this, context.name, {
54
+ get() {
55
+ return container;
56
+ },
57
+ enumerable: true,
58
+ configurable: true,
59
+ });
56
60
  });
57
61
  };
58
62
  }