lombok-typescript 0.6.0 → 0.7.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.
@@ -1,6 +1,6 @@
1
1
  import { a as Backend, M as MetadataStore } from '../backend-CkLBcDd8.cjs';
2
- import { o as AnyClass, A as AccessorsOptions, F as FieldDefaultsOptions, H as HandlerOptions, L as LogOptions, M as MemoizeOptions, S as StateOptions, T as TransitionOptions } from '../chain-of-responsibility-CQ7votcC.cjs';
3
- export { a as CommandHistory, d as StrategyRegistry, e as createFromFactory, j as getFactoryRegistry, k as getStrategyFromRegistry, l as getStrategyRegistry, m as listStrategies, r as registerFactory, n as registerStrategy } from '../chain-of-responsibility-CQ7votcC.cjs';
2
+ import { q as AnyClass, A as AccessorsOptions, F as FieldDefaultsOptions, a as FlyweightOptions, H as HandlerOptions, L as LogOptions, M as MemoizeOptions, P as ProxyHooks, S as StateOptions, T as TransitionOptions } from '../proxy-BJ6_DDQ0.cjs';
3
+ export { b as CommandHistory, f as StrategyRegistry, g as createFromFactory, l as getFactoryRegistry, m as getStrategyFromRegistry, n as getStrategyRegistry, o as listStrategies, r as registerFactory, p as registerStrategy } from '../proxy-BJ6_DDQ0.cjs';
4
4
 
5
5
  /**
6
6
  * Backend for the Stage 3 ECMAScript decorator standard (TS 5.0+).
@@ -121,6 +121,12 @@ declare function Handler(options: HandlerOptions): (value: (this: unknown, ...ar
121
121
  declare const Iterable: <T extends AnyClass>(value: T, context: ClassDecoratorContext) => T | void;
122
122
  /** Marks the collection field iterated by `@Iterable`. */
123
123
  declare const IterateOver: <This, Value>(_value: undefined, context: ClassFieldDecoratorContext<This, Value>) => void | ((this: This, initialValue: Value) => Value);
124
+ /** Shared instance pool keyed by constructor arguments. */
125
+ declare function Flyweight(options: FlyweightOptions): <T extends AnyClass>(value: T, context: ClassDecoratorContext) => T | void;
126
+ /** Tree composite API — add, remove, traverse children. */
127
+ declare const Composite: <T extends AnyClass>(value: T, context: ClassDecoratorContext) => T | void;
128
+ /** Runtime method interception via Proxy. */
129
+ declare function Proxy(hooks?: ProxyHooks): <T extends AnyClass>(value: T, context: ClassDecoratorContext) => T | void;
124
130
 
125
131
  /**
126
132
  * Stage 3 decorator backend, for the modern ECMAScript decorator standard
@@ -143,4 +149,4 @@ declare const IterateOver: <This, Value>(_value: undefined, context: ClassFieldD
143
149
  /** Read the Stage 3 `Symbol.metadata` object from a class, if present. */
144
150
  declare function getClassMetadata(cls: new (...args: any[]) => any): object | undefined;
145
151
 
146
- export { Accessors, Builder, ChainOfResponsibility, Command, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Getter, Handler, Iterable, IterateOver, Log, Memento, Memoize, NonNull, Observable, Observer, Prototype, Setter, Singleton, Stage3Backend, type Stage3ClassLogic, type Stage3FieldLogic, type Stage3GetterLogic, type Stage3MethodLogic, type Stage3SetterLogic, State, Strategy, ToString, Transition, UtilityClass, Value, With, defineClassDecorator, defineFieldDecorator, defineGetterDecorator, defineMethodDecorator, defineSetterDecorator, getClassMetadata, stage3Backend };
152
+ export { Accessors, Builder, ChainOfResponsibility, Command, Composite, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Flyweight, Getter, Handler, Iterable, IterateOver, Log, Memento, Memoize, NonNull, Observable, Observer, Prototype, Proxy, Setter, Singleton, Stage3Backend, type Stage3ClassLogic, type Stage3FieldLogic, type Stage3GetterLogic, type Stage3MethodLogic, type Stage3SetterLogic, State, Strategy, ToString, Transition, UtilityClass, Value, With, defineClassDecorator, defineFieldDecorator, defineGetterDecorator, defineMethodDecorator, defineSetterDecorator, getClassMetadata, stage3Backend };
@@ -1,6 +1,6 @@
1
1
  import { a as Backend, M as MetadataStore } from '../backend-CkLBcDd8.js';
2
- import { o as AnyClass, A as AccessorsOptions, F as FieldDefaultsOptions, H as HandlerOptions, L as LogOptions, M as MemoizeOptions, S as StateOptions, T as TransitionOptions } from '../chain-of-responsibility-Dwsaoe4x.js';
3
- export { a as CommandHistory, d as StrategyRegistry, e as createFromFactory, j as getFactoryRegistry, k as getStrategyFromRegistry, l as getStrategyRegistry, m as listStrategies, r as registerFactory, n as registerStrategy } from '../chain-of-responsibility-Dwsaoe4x.js';
2
+ import { q as AnyClass, A as AccessorsOptions, F as FieldDefaultsOptions, a as FlyweightOptions, H as HandlerOptions, L as LogOptions, M as MemoizeOptions, P as ProxyHooks, S as StateOptions, T as TransitionOptions } from '../proxy-BQ3WvvT_.js';
3
+ export { b as CommandHistory, f as StrategyRegistry, g as createFromFactory, l as getFactoryRegistry, m as getStrategyFromRegistry, n as getStrategyRegistry, o as listStrategies, r as registerFactory, p as registerStrategy } from '../proxy-BQ3WvvT_.js';
4
4
 
5
5
  /**
6
6
  * Backend for the Stage 3 ECMAScript decorator standard (TS 5.0+).
@@ -121,6 +121,12 @@ declare function Handler(options: HandlerOptions): (value: (this: unknown, ...ar
121
121
  declare const Iterable: <T extends AnyClass>(value: T, context: ClassDecoratorContext) => T | void;
122
122
  /** Marks the collection field iterated by `@Iterable`. */
123
123
  declare const IterateOver: <This, Value>(_value: undefined, context: ClassFieldDecoratorContext<This, Value>) => void | ((this: This, initialValue: Value) => Value);
124
+ /** Shared instance pool keyed by constructor arguments. */
125
+ declare function Flyweight(options: FlyweightOptions): <T extends AnyClass>(value: T, context: ClassDecoratorContext) => T | void;
126
+ /** Tree composite API — add, remove, traverse children. */
127
+ declare const Composite: <T extends AnyClass>(value: T, context: ClassDecoratorContext) => T | void;
128
+ /** Runtime method interception via Proxy. */
129
+ declare function Proxy(hooks?: ProxyHooks): <T extends AnyClass>(value: T, context: ClassDecoratorContext) => T | void;
124
130
 
125
131
  /**
126
132
  * Stage 3 decorator backend, for the modern ECMAScript decorator standard
@@ -143,4 +149,4 @@ declare const IterateOver: <This, Value>(_value: undefined, context: ClassFieldD
143
149
  /** Read the Stage 3 `Symbol.metadata` object from a class, if present. */
144
150
  declare function getClassMetadata(cls: new (...args: any[]) => any): object | undefined;
145
151
 
146
- export { Accessors, Builder, ChainOfResponsibility, Command, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Getter, Handler, Iterable, IterateOver, Log, Memento, Memoize, NonNull, Observable, Observer, Prototype, Setter, Singleton, Stage3Backend, type Stage3ClassLogic, type Stage3FieldLogic, type Stage3GetterLogic, type Stage3MethodLogic, type Stage3SetterLogic, State, Strategy, ToString, Transition, UtilityClass, Value, With, defineClassDecorator, defineFieldDecorator, defineGetterDecorator, defineMethodDecorator, defineSetterDecorator, getClassMetadata, stage3Backend };
152
+ export { Accessors, Builder, ChainOfResponsibility, Command, Composite, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Flyweight, Getter, Handler, Iterable, IterateOver, Log, Memento, Memoize, NonNull, Observable, Observer, Prototype, Proxy, Setter, Singleton, Stage3Backend, type Stage3ClassLogic, type Stage3FieldLogic, type Stage3GetterLogic, type Stage3MethodLogic, type Stage3SetterLogic, State, Strategy, ToString, Transition, UtilityClass, Value, With, defineClassDecorator, defineFieldDecorator, defineGetterDecorator, defineMethodDecorator, defineSetterDecorator, getClassMetadata, stage3Backend };
@@ -102,6 +102,9 @@ var MetadataKeys = {
102
102
  SINGLETON: `${PREFIX}singleton`,
103
103
  FACTORY: `${PREFIX}factory`,
104
104
  PROTOTYPE: `${PREFIX}prototype`,
105
+ COMPOSITE: `${PREFIX}composite`,
106
+ FLYWEIGHT: `${PREFIX}flyweight`,
107
+ PROXY: `${PREFIX}proxy`,
105
108
  CHAIN_OF_RESPONSIBILITY: `${PREFIX}chainOfResponsibility`,
106
109
  COMMAND: `${PREFIX}command`,
107
110
  ITERABLE: `${PREFIX}iterable`,
@@ -874,6 +877,128 @@ function iterateOverFieldStage3(backend, context) {
874
877
  registerStage3IterateField(context.metadata, context.name);
875
878
  }
876
879
 
880
+ // src/decorators/shared/flyweight.ts
881
+ var pools = /* @__PURE__ */ new WeakMap();
882
+ function getPool(ctor) {
883
+ let pool = pools.get(ctor);
884
+ if (!pool) {
885
+ pool = /* @__PURE__ */ new Map();
886
+ pools.set(ctor, pool);
887
+ }
888
+ return pool;
889
+ }
890
+ function wrapFlyweightClass(target, options) {
891
+ const pool = getPool(target);
892
+ const FlyweightClass = class extends target {
893
+ constructor(...args) {
894
+ const key = options.key(...args);
895
+ const existing = pool.get(key);
896
+ if (existing) {
897
+ return existing;
898
+ }
899
+ super(...args);
900
+ pool.set(key, this);
901
+ }
902
+ };
903
+ return FlyweightClass;
904
+ }
905
+ function flyweightClassStage3(backend, value, context, options) {
906
+ if (typeof options?.key !== "function") {
907
+ throw new Error("@Flyweight requires a `key` function in options");
908
+ }
909
+ backend.metadata.set(MetadataKeys.FLYWEIGHT, context.metadata, void 0, options);
910
+ return wrapFlyweightClass(value, options);
911
+ }
912
+
913
+ // src/decorators/shared/composite.ts
914
+ var CHILDREN = /* @__PURE__ */ Symbol("lombok-ts:composite-children");
915
+ function getChildren(instance) {
916
+ const bag = instance;
917
+ if (!bag[CHILDREN]) {
918
+ bag[CHILDREN] = [];
919
+ }
920
+ return bag[CHILDREN];
921
+ }
922
+ function wrapCompositeClass(target) {
923
+ const CompositeClass = class extends target {
924
+ add(child) {
925
+ getChildren(this).push(child);
926
+ }
927
+ remove(child) {
928
+ const children = getChildren(this);
929
+ const index = children.indexOf(child);
930
+ if (index >= 0) {
931
+ children.splice(index, 1);
932
+ }
933
+ }
934
+ getChild(index) {
935
+ const children = getChildren(this);
936
+ const child = children[index];
937
+ if (child === void 0) {
938
+ throw new RangeError(`@Composite: no child at index ${index}`);
939
+ }
940
+ return child;
941
+ }
942
+ getChildren() {
943
+ return [...getChildren(this)];
944
+ }
945
+ traverse(callback) {
946
+ const visit = (node) => {
947
+ callback(node);
948
+ for (const child of getChildren(node)) {
949
+ visit(child);
950
+ }
951
+ };
952
+ visit(this);
953
+ }
954
+ *[Symbol.iterator]() {
955
+ yield* getChildren(this);
956
+ }
957
+ };
958
+ return CompositeClass;
959
+ }
960
+ function compositeClassStage3(backend, value, context) {
961
+ backend.metadata.set(MetadataKeys.COMPOSITE, context.metadata, void 0, true);
962
+ return wrapCompositeClass(value);
963
+ }
964
+
965
+ // src/decorators/shared/proxy.ts
966
+ function isMethod(key, value) {
967
+ return typeof key === "string" && key !== "constructor" && typeof value === "function";
968
+ }
969
+ function wrapProxyInstance(instance, hooks) {
970
+ const proto = Object.getPrototypeOf(instance);
971
+ return new Proxy(instance, {
972
+ get(target, prop, receiver) {
973
+ const value = Reflect.get(target, prop, receiver);
974
+ if (!isMethod(prop, value)) {
975
+ return value;
976
+ }
977
+ const original = Object.getOwnPropertyDescriptor(proto, prop)?.value ?? value;
978
+ return (...args) => {
979
+ const methodName = String(prop);
980
+ hooks.before?.(methodName, args);
981
+ const result = original.apply(target, args);
982
+ hooks.after?.(methodName, result);
983
+ return result;
984
+ };
985
+ }
986
+ });
987
+ }
988
+ function wrapProxyClass(target, hooks) {
989
+ const ProxyClass = class extends target {
990
+ constructor(...args) {
991
+ super(...args);
992
+ return wrapProxyInstance(this, hooks);
993
+ }
994
+ };
995
+ return ProxyClass;
996
+ }
997
+ function proxyClassStage3(backend, value, context, hooks = {}) {
998
+ backend.metadata.set(MetadataKeys.PROXY, context.metadata, void 0, hooks);
999
+ return wrapProxyClass(value, hooks);
1000
+ }
1001
+
877
1002
  // src/decorators/stage3/index.ts
878
1003
  var NonNull = defineFieldDecorator(nonNullFieldStage3);
879
1004
  var Singleton = defineClassDecorator(singletonClassStage3);
@@ -985,12 +1110,23 @@ function Handler(options) {
985
1110
  }
986
1111
  var Iterable = defineClassDecorator(iterableClassStage3);
987
1112
  var IterateOver = defineFieldDecorator(iterateOverFieldStage3);
1113
+ function Flyweight(options) {
1114
+ return defineClassDecorator(
1115
+ (backend, value, context) => flyweightClassStage3(backend, value, context, options)
1116
+ );
1117
+ }
1118
+ var Composite = defineClassDecorator(compositeClassStage3);
1119
+ function Proxy2(hooks = {}) {
1120
+ return defineClassDecorator(
1121
+ (backend, value, context) => proxyClassStage3(backend, value, context, hooks)
1122
+ );
1123
+ }
988
1124
 
989
1125
  // src/stage3/index.ts
990
1126
  function getClassMetadata(cls) {
991
1127
  return cls[Symbol.metadata];
992
1128
  }
993
1129
 
994
- export { Accessors, Builder, ChainOfResponsibility, Command, CommandHistory, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Getter, Handler, Iterable, IterateOver, Log, Memento, Memoize, NonNull, Observable, Observer, Prototype, Setter, Singleton, Stage3Backend, State, Strategy, StrategyRegistry, ToString, Transition, UtilityClass, Value, With, createFromFactory, defineClassDecorator, defineFieldDecorator, defineGetterDecorator, defineMethodDecorator, defineSetterDecorator, getClassMetadata, getFactoryRegistry, getStrategyFromRegistry, getStrategyRegistry, listStrategies, registerFactory, registerStrategy, stage3Backend };
1130
+ export { Accessors, Builder, ChainOfResponsibility, Command, CommandHistory, Composite, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Flyweight, Getter, Handler, Iterable, IterateOver, Log, Memento, Memoize, NonNull, Observable, Observer, Prototype, Proxy2 as Proxy, Setter, Singleton, Stage3Backend, State, Strategy, StrategyRegistry, ToString, Transition, UtilityClass, Value, With, createFromFactory, defineClassDecorator, defineFieldDecorator, defineGetterDecorator, defineMethodDecorator, defineSetterDecorator, getClassMetadata, getFactoryRegistry, getStrategyFromRegistry, getStrategyRegistry, listStrategies, registerFactory, registerStrategy, stage3Backend };
995
1131
  //# sourceMappingURL=index.js.map
996
1132
  //# sourceMappingURL=index.js.map