@praxisjs/decorators 1.1.1 → 1.3.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.
@@ -0,0 +1,27 @@
1
+ export function createAccessorDecorator(behavior) {
2
+ return function (_target, context) {
3
+ const bindings = new WeakMap();
4
+ const initValues = new WeakMap();
5
+ function getBinding(instance) {
6
+ let b = bindings.get(instance);
7
+ if (!b) {
8
+ b = behavior.bind(instance, context.name, initValues.get(instance));
9
+ bindings.set(instance, b);
10
+ }
11
+ return b;
12
+ }
13
+ return {
14
+ init(value) {
15
+ initValues.set(this, value);
16
+ return value;
17
+ },
18
+ get() {
19
+ return getBinding(this).get();
20
+ },
21
+ set(value) {
22
+ getBinding(this).set?.(value);
23
+ },
24
+ };
25
+ };
26
+ }
27
+ //# sourceMappingURL=create-accessor-decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-accessor-decorator.js","sourceRoot":"","sources":["../src/create-accessor-decorator.ts"],"names":[],"mappings":"AAcA,MAAM,UAAU,uBAAuB,CAAC,QAA0B;IAChE,OAAO,UACL,OAA8C,EAC9C,OAA+C;QAE/C,MAAM,QAAQ,GAAG,IAAI,OAAO,EAA2B,CAAC;QACxD,MAAM,UAAU,GAAG,IAAI,OAAO,EAAmB,CAAC;QAElD,SAAS,UAAU,CAAC,QAAgB;YAClC,IAAI,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC/B,IAAI,CAAC,CAAC,EAAE,CAAC;gBACP,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACpE,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;YAC5B,CAAC;YACD,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO;YACL,IAAI,CAAa,KAAQ;gBACvB,UAAU,CAAC,GAAG,CAAC,IAAc,EAAE,KAAK,CAAC,CAAC;gBACtC,OAAO,KAAK,CAAC;YACf,CAAC;YACD,GAAG;gBACD,OAAO,UAAU,CAAC,IAAc,CAAC,CAAC,GAAG,EAAO,CAAC;YAC/C,CAAC;YACD,GAAG,CAAa,KAAQ;gBACtB,UAAU,CAAC,IAAc,CAAC,CAAC,GAAG,EAAE,CAAC,KAAgB,CAAC,CAAC;YACrD,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -6,6 +6,20 @@ export interface GetterBehavior {
6
6
  wrap(original: (this: object) => unknown, instance: object): () => unknown;
7
7
  }
8
8
  export declare function createGetterDecorator(behavior: GetterBehavior): <This, T>(target: (this: This) => T, _context: ClassGetterDecoratorContext<This, T>) => (this: This) => T;
9
+ export interface WritableGetterBinding {
10
+ get: () => unknown;
11
+ set?: (value: unknown) => void;
12
+ }
13
+ export interface WritableGetterBehavior {
14
+ /**
15
+ * Called once per instance during construction. Returns the get/set pair
16
+ * that will be installed on the instance via `Object.defineProperty`.
17
+ * If `set` is omitted, the property is read-only at runtime (though TypeScript
18
+ * may still see a setter if one is declared in the class body).
19
+ */
20
+ bind(instance: object, name: string | symbol, original: (this: object) => unknown): WritableGetterBinding;
21
+ }
22
+ export declare function createWritableGetterDecorator(behavior: WritableGetterBehavior): <This, T>(target: (this: This) => T, context: ClassGetterDecoratorContext<This, T>) => (this: This) => T;
9
23
  export interface GetterObserverBehavior {
10
24
  /**
11
25
  * Called once per instance when the class is initialized.
@@ -1 +1 @@
1
- {"version":3,"file":"create-getter-decorator.d.ts","sourceRoot":"","sources":["../src/create-getter-decorator.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,IAAI,CACF,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,EACnC,QAAQ,EAAE,MAAM,GACf,MAAM,OAAO,CAAC;CAClB;AAED,wBAAgB,qBAAqB,CAA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AE,MAAM,EAChB,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAClC,qBAAqB,CAAC;CAC1B;AAED,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,sBAAsB,IAC3D,IAAI,EAAE,CAAC,EACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,EACzB,SAAS,2BAA2B,CAAC,IAAI,EAAE,CAAC,CAAC,KAC5C,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,CAcrB;AAED,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,OAAO,CACL,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,EACjC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,IAAI,CAAC;CACT;AAED,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,sBAAsB,IAC3D,IAAI,EAAE,CAAC,EACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,EACzB,SAAS,2BAA2B,CAAC,IAAI,EAAE,CAAC,CAAC,KAC5C,IAAI,CASR"}
@@ -5,6 +5,23 @@ export function createGetterDecorator(behavior) {
5
5
  };
6
6
  };
7
7
  }
8
+ export function createWritableGetterDecorator(behavior) {
9
+ return function (target, context) {
10
+ context.addInitializer(function () {
11
+ const instance = this;
12
+ const binding = behavior.bind(instance, context.name, target);
13
+ const descriptor = {
14
+ get: binding.get,
15
+ configurable: true,
16
+ enumerable: false,
17
+ };
18
+ if (binding.set !== undefined)
19
+ descriptor.set = binding.set;
20
+ Object.defineProperty(instance, context.name, descriptor);
21
+ });
22
+ return target;
23
+ };
24
+ }
8
25
  export function createGetterObserverDecorator(behavior) {
9
26
  return function (target, context) {
10
27
  context.addInitializer(function () {
@@ -1 +1 @@
1
- {"version":3,"file":"create-getter-decorator.js","sourceRoot":"","sources":["../src/create-getter-decorator.ts"],"names":[],"mappings":"AAWA,MAA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C,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAeD,MAAM,UAAU,6BAA6B,CAAC,QAAgC;IAC5E,OAAO,UACL,MAAyB,EACzB,OAA6C;QAE7C,OAAO,CAAC,cAAc,CAAC;YACrB,QAAQ,CAAC,OAAO,CACd,MAAmC,EACnC,IAAc,EACd,OAAO,CAAC,IAAc,CACvB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare function When(propName: string): (value: (this: import("@praxisjs/core").StatefulComponent, ...args: any[]) => void, _context: ClassMethodDecoratorContext<import("@praxisjs/core").StatefulComponent, (this: import("@praxisjs/core").StatefulComponent, ...args: any) => any>) => void;
1
+ export declare function When<T = unknown>(propName: string, condition?: (value: NonNullable<T>) => boolean): (value: (this: import("@praxisjs/core").StatefulComponent, ...args: any[]) => void, _context: ClassMethodDecoratorContext<import("@praxisjs/core").StatefulComponent, (this: import("@praxisjs/core").StatefulComponent, ...args: any) => any>) => void;
2
2
  //# sourceMappingURL=when.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"when.d.ts","sourceRoot":"","sources":["../../src/functions/when.ts"],"names":[],"mappings":"AAMA,wBAAgB,IAAI,CAAC,QAAQ,EAAE,MAAM,2PAUpC"}
1
+ {"version":3,"file":"when.d.ts","sourceRoot":"","sources":["../../src/functions/when.ts"],"names":[],"mappings":"AAcA,wBAAgB,IAAI,CAAC,CAAC,GAAG,OAAO,EAC9B,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,OAAO,2PAwB/C"}
@@ -1,14 +1,34 @@
1
- import { when } from "@praxisjs/core/internal";
2
- import { isComputed } from "@praxisjs/shared/internal";
1
+ import { effect } from "@praxisjs/core/internal";
2
+ import { isComputed, isSignal } from "@praxisjs/shared/internal";
3
3
  import { createLifecycleMethodDecorator } from "../create-lifecycle-method-decorator";
4
- export function When(propName) {
4
+ /** Read the current value of a property, unwrapping Signal or Computed if needed. */
5
+ function readProp(instance, key) {
6
+ const raw = instance[key];
7
+ if (isComputed(raw))
8
+ return raw();
9
+ if (isSignal(raw))
10
+ return raw();
11
+ return raw;
12
+ }
13
+ export function When(propName, condition) {
5
14
  return createLifecycleMethodDecorator({
6
15
  register(callback, instance) {
7
- const raw = instance[propName];
8
- const source = isComputed(raw)
9
- ? raw
10
- : raw;
11
- return when(source, (val) => { callback(val); });
16
+ const inst = instance;
17
+ let fired = false;
18
+ return effect(() => {
19
+ if (fired)
20
+ return;
21
+ // Reading via readProp subscribes this effect to the underlying signal,
22
+ // whether the property is a raw Signal/Computed or an @State getter.
23
+ const val = readProp(inst, propName);
24
+ const meetsCondition = condition
25
+ ? val != null && condition(val)
26
+ : val != null && Boolean(val);
27
+ if (meetsCondition) {
28
+ fired = true;
29
+ callback(val);
30
+ }
31
+ });
12
32
  },
13
33
  });
14
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"when.js","sourceRoot":"","sources":["../../src/functions/when.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAEtF,MAAM,UAAU,IAAI,CAAC,QAAgB;IACnC,OAAO,8BAA8B,CAAC;QACpC,QAAQ,CAAC,QAAQ,EAAE,QAAQ;YACzB,MAAM,GAAG,GAAI,QAA+C,CAAC,QAAQ,CAAC,CAAC;YACvE,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC;gBAC5B,CAAC,CAAE,GAAyB;gBAC5B,CAAC,CAAE,GAAuB,CAAC;YAC7B,OAAO,IAAI,CAA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CAAC;oBACnB,KAAK,GAAG,IAAI,CAAC;oBACb,QAAQ,CAAC,GAAqB,CAAC,CAAC;gBAClC,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
package/dist/index.d.ts CHANGED
@@ -7,5 +7,6 @@ export { type ReactiveHost } from "./reactive-host";
7
7
  export { createClassDecorator, ClassBehavior, type ClassEnhancement, } from "./create-class-decorator";
8
8
  export { createMethodDecorator, type MethodBehavior, } from "./create-method-decorator";
9
9
  export { createLifecycleMethodDecorator, type LifecycleMethodBehavior, } from "./create-lifecycle-method-decorator";
10
- export { createGetterDecorator, type GetterBehavior, createGetterObserverDecorator, type GetterObserverBehavior, } from "./create-getter-decorator";
10
+ export { createGetterDecorator, type GetterBehavior, createWritableGetterDecorator, type WritableGetterBehavior, type WritableGetterBinding, createGetterObserverDecorator, type GetterObserverBehavior, } from "./create-getter-decorator";
11
+ export { createAccessorDecorator, type AccessorBehavior, type AccessorBinding, } from "./create-accessor-decorator";
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,KAAK,EACL,KAAK,QAAQ,EACb,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,SAAS,EACT,OAAO,EACP,KAAK,SAAS,EACd,OAAO,EACP,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,MAAM,EACN,SAAS,GACV,MAAM,cAAc,CAAC;AACt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oB,EACpB,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,KAAK,gBAAgB,GACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,qBAAqB,EACrB,KAAK,cAAc,GACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,8BAA8B,EAC9B,KAAK,uBAAuB,GAC7B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,qBAAqB,EACrB,KAAK,cAAc,EACnB,6BAA6B,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,6BAA6B,EAC7B,KAAK,sBAAsB,GAC5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,uBAAuB,EACvB,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,6BAA6B,CAAC"}
package/dist/index.js CHANGED
@@ -6,5 +6,6 @@ export { createFieldDecorator, } from "./create-field-decorator";
6
6
  export { createClassDecorator, ClassBehavior, } from "./create-class-decorator";
7
7
  export { createMethodDecorator, } from "./create-method-decorator";
8
8
  export { createLifecycleMethodDecorator, } from "./create-lifecycle-method-decorator";
9
- export { createGetterDecorator, createGetterObserverDecorator, } from "./create-getter-decorator";
9
+ export { createGetterDecorator, createWritableGetterDecorator, createGetterObserverDecorator, } from "./create-getter-decorator";
10
+ export { createAccessorDecorator, } from "./create-accessor-decorator";
10
11
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,I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Ed,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,8BAA8B,GAE/B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,qBAAqB,EAErB,6BAA6B,EAG7B,6BAA6B,GAE9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,uBAAuB,GAGxB,MAAM,6BAA6B,CAAC"}
@@ -1,2 +1,12 @@
1
- export declare function Computed(): <This, T>(target: (this: This) => T, _context: ClassGetterDecoratorContext<This, T>) => (this: This) => T;
1
+ export interface ComputedOptions<T = unknown> {
2
+ get?: (this: object) => T;
3
+ set?: (this: object, value: T) => void;
4
+ }
5
+ export declare function Computed<T, Owner extends object = object>(options: {
6
+ get: (this: Owner) => T;
7
+ set: (this: Owner, value: T) => void;
8
+ }): <This extends object>(target: ClassAccessorDecoratorTarget<This, T>, context: ClassAccessorDecoratorContext<This, T>) => ClassAccessorDecoratorResult<This, T>;
9
+ export declare function Computed(options?: {
10
+ set?: (this: object, value: unknown) => void;
11
+ }): <This, R>(target: (this: This) => R, context: ClassGetterDecoratorContext<This, R>) => (this: This) => R;
2
12
  //# sourceMappingURL=computed.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"computed.d.ts","sourceRoot":"","sources":["../../src/properties/computed.ts"],"names":[],"mappings":"AAIA,wBAAgB,QAAQ,8GAavB"}
1
+ {"version":3,"file":"computed.d.ts","sourceRoot":"","sources":["../../src/properties/computed.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,CAAC,CAAC;IAC1B,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CACxC;AAKD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,SAAS,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE;IAClE,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,CAAC,CAAC;IACxB,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CACtC,GAAG,CAAC,IAAI,SAAS,MAAM,EACtB,MAAM,EAAE,4BAA4B,CAAC,IAAI,EAAE,CAAC,CAAC,EAC7C,OAAO,EAAE,6BAA6B,CAAC,IAAI,EAAE,CAAC,CAAC,KAC5C,4BAA4B,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAG3C,wBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE;IACjC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC9C,GAAG,CAAC,IAAI,EAAE,CAAC,EACV,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,EACzB,OAAO,EAAE,2BAA2B,CAAC,IAAI,EAAE,CAAC,CAAC,KAC1C,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,CAAC"}
@@ -1,15 +1,27 @@
1
1
  import { computed } from "@praxisjs/core/internal";
2
- import { createGetterDecorator } from "../create-getter-decorator";
3
- export function Computed() {
4
- const cache = new WeakMap();
5
- return createGetterDecorator({
6
- wrap(original, instance) {
7
- let c = cache.get(instance);
8
- if (!c) {
9
- c = computed(() => original.call(instance));
10
- cache.set(instance, c);
11
- }
12
- return c;
2
+ import { createAccessorDecorator } from "../create-accessor-decorator";
3
+ import { createWritableGetterDecorator } from "../create-getter-decorator";
4
+ export function Computed(options) {
5
+ const optionsGet = options?.get;
6
+ const optionsSet = options?.set;
7
+ if (optionsGet) {
8
+ return createAccessorDecorator({
9
+ bind(instance, _name, _initialValue) {
10
+ const c = computed(() => optionsGet.call(instance));
11
+ return {
12
+ get: c,
13
+ set: optionsSet ? (value) => { optionsSet.call(instance, value); } : undefined,
14
+ };
15
+ },
16
+ });
17
+ }
18
+ return createWritableGetterDecorator({
19
+ bind(instance, _name, original) {
20
+ const c = computed(() => original.call(instance));
21
+ return {
22
+ get: c,
23
+ set: optionsSet ? (value) => { optionsSet.call(instance, value); } : undefined,
24
+ };
13
25
  },
14
26
  });
15
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"computed.js","sourceRoot":"","sources":["../../src/properties/computed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,MAAM,UAAU,QAAQ;IACtB,MAAM,KAAK,GAAG,IAAI,OAAO,EAAyB,CAAC;IAEnD,OAAO,qBAAqB,CAAC;QAC3B,IAAI,CAAC,QAAQ,EAAE,QAAQ;YACrB,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC5B,IAAI,CAAC,CAAC,EAAE,CAAC;gBACP,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAC5C,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;YACzB,CAAC;YACD,OAAO,CAAC,CAAC;QACX,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"computed.js","sourceRoot":"","sources":["../../src/properties/computed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AA0B3E,MAAM,UAAU,QAAQ,CAAc,OAA4B;IAChE,MAAM,UAAU,GAAG,OAAO,EAAE,GAA8C,CAAC;IAC3E,MAAM,UAAU,GAAG,OAAO,EAAE,GAA2D,CAAC;IAExF,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,uBAAuB,CAAC;YAC7B,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,aAAa;gBACjC,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACpD,OAAO;oBACL,GAAG,EAAE,CAAC;oBACN,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;iBAC/E,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,6BAA6B,CAAC;QACnC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ;YAC5B,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YAClD,OAAO;gBACL,GAAG,EAAE,CAAC;gBACN,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;aAC/E,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@praxisjs/decorators",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -15,8 +15,8 @@
15
15
  "typescript": "^5.9.3"
16
16
  },
17
17
  "dependencies": {
18
- "@praxisjs/core": "1.7.0",
19
- "@praxisjs/shared": "0.2.0"
18
+ "@praxisjs/core": "1.8.0",
19
+ "@praxisjs/shared": "0.3.0"
20
20
  },
21
21
  "scripts": {
22
22
  "build": "tsc",