lombok-typescript 0.6.0 → 0.8.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 { 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 { C as ClassDecoratorLogic, a as CommandHistory, b as FieldDecoratorLogic, c as MethodDecoratorLogic, P as ParameterDecoratorLogic, d as StrategyRegistry, e as createFromFactory, f as defineClassDecorator, g as defineFieldDecorator, h as defineMethodDecorator, i as defineParameterDecorator, 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 { A as AccessorsOptions, F as FieldDefaultsOptions, a as FlyweightOptions, H as HandlerOptions, b as HookOptions, L as LogOptions, M as MemoizeOptions, P as ProxyHooks, S as StateOptions, T as TemplateMethodOptions, c as TransitionOptions, V as VisitorOptions, d as AnyClass } from '../visitor-B5ByGIWE.cjs';
3
+ export { C as ClassDecoratorLogic, e as CommandHistory, f as FieldDecoratorLogic, g as MethodDecoratorLogic, h as ParameterDecoratorLogic, i as StrategyRegistry, j as createFromFactory, k as defineClassDecorator, l as defineFieldDecorator, m as defineMethodDecorator, n as defineParameterDecorator, o as getFactoryRegistry, p as getStrategyFromRegistry, q as getStrategyRegistry, r as getVisitableRegistry, s as listStrategies, t as registerFactory, u as registerStrategy } from '../visitor-B5ByGIWE.cjs';
4
4
 
5
5
  /** Backend for the legacy `experimentalDecorators` standard. Use the singleton `legacyBackend`. */
6
6
  declare class LegacyBackend implements Backend {
@@ -75,5 +75,26 @@ declare function Handler(options: HandlerOptions): MethodDecorator;
75
75
  declare const Iterable: ClassDecorator;
76
76
  /** Marks the collection field iterated by `@Iterable`. */
77
77
  declare const IterateOver: PropertyDecorator;
78
+ /** Shared instance pool keyed by constructor arguments. */
79
+ declare function Flyweight(options: FlyweightOptions): ClassDecorator;
80
+ /** Tree composite API — add, remove, traverse children. */
81
+ declare const Composite: ClassDecorator;
82
+ /** Runtime method interception via Proxy. */
83
+ declare function Proxy(hooks?: ProxyHooks): ClassDecorator;
84
+ /**
85
+ * GoF Decorator — wraps an inner instance as `protected inner`.
86
+ * @see GoF Decorator Pattern (ADR-15)
87
+ */
88
+ declare function Wraps(InnerClass: AnyClass): ClassDecorator;
89
+ /** Codegen template method with ordered `@Hook` steps. */
90
+ declare function TemplateMethod(options: TemplateMethodOptions): ClassDecorator;
91
+ /** Marks a method as a template hook step. */
92
+ declare function Hook(options?: Partial<HookOptions>): MethodDecorator;
93
+ /** Helper scaffold — codegen emits abstract product factory methods. */
94
+ declare function AbstractFactory(products: string[]): ClassDecorator;
95
+ /** Double-dispatch visitor — calls `visit{ClassName}` on the visitor. */
96
+ declare function Visitor(options: VisitorOptions): ClassDecorator;
97
+ /** Registers a node type for visitor dispatch. */
98
+ declare const Visitable: ClassDecorator;
78
99
 
79
- export { Accessors, Builder, ChainOfResponsibility, Command, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Getter, Handler, Iterable, IterateOver, LegacyBackend, Log, Memento, Memoize, NonNull, NonNullParam, Observable, Observer, Prototype, Setter, Singleton, State, Strategy, ToString, Transition, UtilityClass, Value, With, legacyBackend };
100
+ export { AbstractFactory, Accessors, Builder, ChainOfResponsibility, Command, Composite, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Flyweight, Getter, Handler, Hook, Iterable, IterateOver, LegacyBackend, Log, Memento, Memoize, NonNull, NonNullParam, Observable, Observer, Prototype, Proxy, Setter, Singleton, State, Strategy, TemplateMethod, ToString, Transition, UtilityClass, Value, Visitable, Visitor, With, Wraps, legacyBackend };
@@ -1,6 +1,6 @@
1
1
  import { a as Backend, M as MetadataStore } from '../backend-CkLBcDd8.js';
2
- import { 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 { C as ClassDecoratorLogic, a as CommandHistory, b as FieldDecoratorLogic, c as MethodDecoratorLogic, P as ParameterDecoratorLogic, d as StrategyRegistry, e as createFromFactory, f as defineClassDecorator, g as defineFieldDecorator, h as defineMethodDecorator, i as defineParameterDecorator, 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 { A as AccessorsOptions, F as FieldDefaultsOptions, a as FlyweightOptions, H as HandlerOptions, b as HookOptions, L as LogOptions, M as MemoizeOptions, P as ProxyHooks, S as StateOptions, T as TemplateMethodOptions, c as TransitionOptions, V as VisitorOptions, d as AnyClass } from '../visitor-BqARKwCX.js';
3
+ export { C as ClassDecoratorLogic, e as CommandHistory, f as FieldDecoratorLogic, g as MethodDecoratorLogic, h as ParameterDecoratorLogic, i as StrategyRegistry, j as createFromFactory, k as defineClassDecorator, l as defineFieldDecorator, m as defineMethodDecorator, n as defineParameterDecorator, o as getFactoryRegistry, p as getStrategyFromRegistry, q as getStrategyRegistry, r as getVisitableRegistry, s as listStrategies, t as registerFactory, u as registerStrategy } from '../visitor-BqARKwCX.js';
4
4
 
5
5
  /** Backend for the legacy `experimentalDecorators` standard. Use the singleton `legacyBackend`. */
6
6
  declare class LegacyBackend implements Backend {
@@ -75,5 +75,26 @@ declare function Handler(options: HandlerOptions): MethodDecorator;
75
75
  declare const Iterable: ClassDecorator;
76
76
  /** Marks the collection field iterated by `@Iterable`. */
77
77
  declare const IterateOver: PropertyDecorator;
78
+ /** Shared instance pool keyed by constructor arguments. */
79
+ declare function Flyweight(options: FlyweightOptions): ClassDecorator;
80
+ /** Tree composite API — add, remove, traverse children. */
81
+ declare const Composite: ClassDecorator;
82
+ /** Runtime method interception via Proxy. */
83
+ declare function Proxy(hooks?: ProxyHooks): ClassDecorator;
84
+ /**
85
+ * GoF Decorator — wraps an inner instance as `protected inner`.
86
+ * @see GoF Decorator Pattern (ADR-15)
87
+ */
88
+ declare function Wraps(InnerClass: AnyClass): ClassDecorator;
89
+ /** Codegen template method with ordered `@Hook` steps. */
90
+ declare function TemplateMethod(options: TemplateMethodOptions): ClassDecorator;
91
+ /** Marks a method as a template hook step. */
92
+ declare function Hook(options?: Partial<HookOptions>): MethodDecorator;
93
+ /** Helper scaffold — codegen emits abstract product factory methods. */
94
+ declare function AbstractFactory(products: string[]): ClassDecorator;
95
+ /** Double-dispatch visitor — calls `visit{ClassName}` on the visitor. */
96
+ declare function Visitor(options: VisitorOptions): ClassDecorator;
97
+ /** Registers a node type for visitor dispatch. */
98
+ declare const Visitable: ClassDecorator;
78
99
 
79
- export { Accessors, Builder, ChainOfResponsibility, Command, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Getter, Handler, Iterable, IterateOver, LegacyBackend, Log, Memento, Memoize, NonNull, NonNullParam, Observable, Observer, Prototype, Setter, Singleton, State, Strategy, ToString, Transition, UtilityClass, Value, With, legacyBackend };
100
+ export { AbstractFactory, Accessors, Builder, ChainOfResponsibility, Command, Composite, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Flyweight, Getter, Handler, Hook, Iterable, IterateOver, LegacyBackend, Log, Memento, Memoize, NonNull, NonNullParam, Observable, Observer, Prototype, Proxy, Setter, Singleton, State, Strategy, TemplateMethod, ToString, Transition, UtilityClass, Value, Visitable, Visitor, With, Wraps, legacyBackend };
@@ -82,7 +82,12 @@ var MetadataKeys = {
82
82
  // Class-level (GoF)
83
83
  SINGLETON: `${PREFIX}singleton`,
84
84
  FACTORY: `${PREFIX}factory`,
85
+ ABSTRACT_FACTORY: `${PREFIX}abstractFactory`,
85
86
  PROTOTYPE: `${PREFIX}prototype`,
87
+ COMPOSITE: `${PREFIX}composite`,
88
+ WRAPS: `${PREFIX}wraps`,
89
+ FLYWEIGHT: `${PREFIX}flyweight`,
90
+ PROXY: `${PREFIX}proxy`,
86
91
  CHAIN_OF_RESPONSIBILITY: `${PREFIX}chainOfResponsibility`,
87
92
  COMMAND: `${PREFIX}command`,
88
93
  ITERABLE: `${PREFIX}iterable`,
@@ -90,6 +95,9 @@ var MetadataKeys = {
90
95
  MEMENTO_EXCLUDE: `${PREFIX}memento:exclude`,
91
96
  STATE: `${PREFIX}state`,
92
97
  STRATEGY: `${PREFIX}strategy`,
98
+ TEMPLATE_METHOD: `${PREFIX}templateMethod`,
99
+ VISITABLE: `${PREFIX}visitable`,
100
+ VISITOR: `${PREFIX}visitor`,
93
101
  // Field-level
94
102
  GETTER: `${PREFIX}getter`,
95
103
  SETTER: `${PREFIX}setter`,
@@ -102,6 +110,7 @@ var MetadataKeys = {
102
110
  MEMOIZE: `${PREFIX}memoize`,
103
111
  HANDLER: `${PREFIX}handler`,
104
112
  TRANSITION: `${PREFIX}transition`,
113
+ HOOK: `${PREFIX}hook`,
105
114
  // Parameter-level
106
115
  NON_NULL_PARAM: `${PREFIX}nonNull:param`};
107
116
 
@@ -847,6 +856,198 @@ function iterateOverFieldLegacy(backend, targetPrototype, propertyKey) {
847
856
  registerLegacyIterateField(targetPrototype, propertyKey);
848
857
  }
849
858
 
859
+ // src/decorators/shared/flyweight.ts
860
+ var pools = /* @__PURE__ */ new WeakMap();
861
+ function getPool(ctor) {
862
+ let pool = pools.get(ctor);
863
+ if (!pool) {
864
+ pool = /* @__PURE__ */ new Map();
865
+ pools.set(ctor, pool);
866
+ }
867
+ return pool;
868
+ }
869
+ function wrapFlyweightClass(target, options) {
870
+ const pool = getPool(target);
871
+ const FlyweightClass = class extends target {
872
+ constructor(...args) {
873
+ const key = options.key(...args);
874
+ const existing = pool.get(key);
875
+ if (existing) {
876
+ return existing;
877
+ }
878
+ super(...args);
879
+ pool.set(key, this);
880
+ }
881
+ };
882
+ return FlyweightClass;
883
+ }
884
+ function flyweightClassLegacy(backend, target, options) {
885
+ if (typeof options?.key !== "function") {
886
+ throw new Error("@Flyweight requires a `key` function in options");
887
+ }
888
+ backend.metadata.set(MetadataKeys.FLYWEIGHT, target, void 0, options);
889
+ return wrapFlyweightClass(target, options);
890
+ }
891
+
892
+ // src/decorators/shared/composite.ts
893
+ var CHILDREN = /* @__PURE__ */ Symbol("lombok-ts:composite-children");
894
+ function getChildren(instance) {
895
+ const bag = instance;
896
+ if (!bag[CHILDREN]) {
897
+ bag[CHILDREN] = [];
898
+ }
899
+ return bag[CHILDREN];
900
+ }
901
+ function wrapCompositeClass(target) {
902
+ const CompositeClass = class extends target {
903
+ add(child) {
904
+ getChildren(this).push(child);
905
+ }
906
+ remove(child) {
907
+ const children = getChildren(this);
908
+ const index = children.indexOf(child);
909
+ if (index >= 0) {
910
+ children.splice(index, 1);
911
+ }
912
+ }
913
+ getChild(index) {
914
+ const children = getChildren(this);
915
+ const child = children[index];
916
+ if (child === void 0) {
917
+ throw new RangeError(`@Composite: no child at index ${index}`);
918
+ }
919
+ return child;
920
+ }
921
+ getChildren() {
922
+ return [...getChildren(this)];
923
+ }
924
+ traverse(callback) {
925
+ const visit = (node) => {
926
+ callback(node);
927
+ for (const child of getChildren(node)) {
928
+ visit(child);
929
+ }
930
+ };
931
+ visit(this);
932
+ }
933
+ *[Symbol.iterator]() {
934
+ yield* getChildren(this);
935
+ }
936
+ };
937
+ return CompositeClass;
938
+ }
939
+ function compositeClassLegacy(backend, target) {
940
+ backend.metadata.set(MetadataKeys.COMPOSITE, target, void 0, true);
941
+ return wrapCompositeClass(target);
942
+ }
943
+
944
+ // src/decorators/shared/proxy.ts
945
+ function isMethod(key, value) {
946
+ return typeof key === "string" && key !== "constructor" && typeof value === "function";
947
+ }
948
+ function wrapProxyInstance(instance, hooks) {
949
+ const proto = Object.getPrototypeOf(instance);
950
+ return new Proxy(instance, {
951
+ get(target, prop, receiver) {
952
+ const value = Reflect.get(target, prop, receiver);
953
+ if (!isMethod(prop, value)) {
954
+ return value;
955
+ }
956
+ const original = Object.getOwnPropertyDescriptor(proto, prop)?.value ?? value;
957
+ return (...args) => {
958
+ const methodName = String(prop);
959
+ hooks.before?.(methodName, args);
960
+ const result = original.apply(target, args);
961
+ hooks.after?.(methodName, result);
962
+ return result;
963
+ };
964
+ }
965
+ });
966
+ }
967
+ function wrapProxyClass(target, hooks) {
968
+ const ProxyClass = class extends target {
969
+ constructor(...args) {
970
+ super(...args);
971
+ return wrapProxyInstance(this, hooks);
972
+ }
973
+ };
974
+ return ProxyClass;
975
+ }
976
+ function proxyClassLegacy(backend, target, hooks = {}) {
977
+ backend.metadata.set(MetadataKeys.PROXY, target, void 0, hooks);
978
+ return wrapProxyClass(target, hooks);
979
+ }
980
+
981
+ // src/decorators/shared/wraps.ts
982
+ var INNER = /* @__PURE__ */ Symbol("lombok-ts:wraps-inner");
983
+ function wrapWrapsClass(target, InnerClass) {
984
+ if (typeof InnerClass !== "function") {
985
+ throw new TypeError("@Wraps requires a constructor function");
986
+ }
987
+ const WrapsClass = class extends target {
988
+ inner;
989
+ constructor(...args) {
990
+ super();
991
+ const inner = args[0];
992
+ if (inner === void 0 || !(inner instanceof InnerClass)) {
993
+ throw new TypeError(`@Wraps(${InnerClass.name}) expects an instance as the first argument`);
994
+ }
995
+ this.inner = inner;
996
+ this[INNER] = inner;
997
+ }
998
+ };
999
+ return WrapsClass;
1000
+ }
1001
+ function wrapsClassLegacy(backend, target, InnerClass) {
1002
+ backend.metadata.set(MetadataKeys.WRAPS, target, void 0, InnerClass);
1003
+ return wrapWrapsClass(target, InnerClass);
1004
+ }
1005
+
1006
+ // src/decorators/shared/template-method.ts
1007
+ function templateMethodClassLegacy(backend, target, options) {
1008
+ if (!Array.isArray(options?.steps) || options.steps.length === 0) {
1009
+ throw new Error("@TemplateMethod requires a non-empty `steps` array");
1010
+ }
1011
+ backend.metadata.set(MetadataKeys.TEMPLATE_METHOD, target, void 0, options);
1012
+ }
1013
+
1014
+ // src/decorators/shared/hook.ts
1015
+ function hookMethodLegacy(backend, targetPrototype, propertyKey, options) {
1016
+ backend.metadata.set(MetadataKeys.HOOK, targetPrototype, propertyKey, options);
1017
+ }
1018
+
1019
+ // src/decorators/shared/abstract-factory.ts
1020
+ function normalizeProducts(productsOrOptions) {
1021
+ const products = Array.isArray(productsOrOptions) ? productsOrOptions : productsOrOptions.products;
1022
+ if (!Array.isArray(products) || products.length === 0) {
1023
+ throw new Error("@AbstractFactory requires a non-empty product list");
1024
+ }
1025
+ return products;
1026
+ }
1027
+ function abstractFactoryClassLegacy(backend, target, productsOrOptions) {
1028
+ const products = normalizeProducts(productsOrOptions);
1029
+ backend.metadata.set(MetadataKeys.ABSTRACT_FACTORY, target, void 0, { products });
1030
+ }
1031
+
1032
+ // src/decorators/shared/visitor.ts
1033
+ var visitableRegistry = /* @__PURE__ */ new Map();
1034
+ function registerVisitable(name, ctor) {
1035
+ visitableRegistry.set(name, ctor);
1036
+ }
1037
+ function getVisitableRegistry() {
1038
+ return visitableRegistry;
1039
+ }
1040
+ function visitorClassLegacy(backend, target, options) {
1041
+ if (!options?.visitMethods || typeof options.visitMethods !== "object") {
1042
+ throw new Error("@Visitor requires a `visitMethods` map");
1043
+ }
1044
+ backend.metadata.set(MetadataKeys.VISITOR, target, void 0, options);
1045
+ }
1046
+ function visitableClassLegacy(backend, target, options = {}) {
1047
+ backend.metadata.set(MetadataKeys.VISITABLE, target, void 0, options);
1048
+ registerVisitable(target.name, target);
1049
+ }
1050
+
850
1051
  // src/decorators/legacy/index.ts
851
1052
  var NonNull = defineFieldDecorator(nonNullFieldLegacy);
852
1053
  function NonNullParam() {
@@ -952,7 +1153,37 @@ function Handler(options) {
952
1153
  }
953
1154
  var Iterable = defineClassDecorator(iterableClassLegacy);
954
1155
  var IterateOver = defineFieldDecorator(iterateOverFieldLegacy);
1156
+ function Flyweight(options) {
1157
+ return defineClassDecorator((backend, target) => flyweightClassLegacy(backend, target, options));
1158
+ }
1159
+ var Composite = defineClassDecorator(compositeClassLegacy);
1160
+ function Proxy2(hooks = {}) {
1161
+ return defineClassDecorator((backend, target) => proxyClassLegacy(backend, target, hooks));
1162
+ }
1163
+ function Wraps(InnerClass) {
1164
+ return defineClassDecorator((backend, target) => wrapsClassLegacy(backend, target, InnerClass));
1165
+ }
1166
+ function TemplateMethod(options) {
1167
+ return defineClassDecorator(
1168
+ (backend, target) => templateMethodClassLegacy(backend, target, options)
1169
+ );
1170
+ }
1171
+ function Hook(options) {
1172
+ return defineMethodDecorator((backend, target, key) => {
1173
+ const name = options?.name ?? String(key);
1174
+ hookMethodLegacy(backend, target, key, { name });
1175
+ });
1176
+ }
1177
+ function AbstractFactory(products) {
1178
+ return defineClassDecorator(
1179
+ (backend, target) => abstractFactoryClassLegacy(backend, target, products)
1180
+ );
1181
+ }
1182
+ function Visitor(options) {
1183
+ return defineClassDecorator((backend, target) => visitorClassLegacy(backend, target, options));
1184
+ }
1185
+ var Visitable = defineClassDecorator(visitableClassLegacy);
955
1186
 
956
- export { Accessors, Builder, ChainOfResponsibility, Command, CommandHistory, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Getter, Handler, Iterable, IterateOver, LegacyBackend, Log, Memento, Memoize, NonNull, NonNullParam, Observable, Observer, Prototype, Setter, Singleton, State, Strategy, StrategyRegistry, ToString, Transition, UtilityClass, Value, With, createFromFactory, defineClassDecorator, defineFieldDecorator, defineMethodDecorator, defineParameterDecorator, getFactoryRegistry, getStrategyFromRegistry, getStrategyRegistry, legacyBackend, listStrategies, registerFactory, registerStrategy };
1187
+ export { AbstractFactory, Accessors, Builder, ChainOfResponsibility, Command, CommandHistory, Composite, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Flyweight, Getter, Handler, Hook, Iterable, IterateOver, LegacyBackend, Log, Memento, Memoize, NonNull, NonNullParam, Observable, Observer, Prototype, Proxy2 as Proxy, Setter, Singleton, State, Strategy, StrategyRegistry, TemplateMethod, ToString, Transition, UtilityClass, Value, Visitable, Visitor, With, Wraps, createFromFactory, defineClassDecorator, defineFieldDecorator, defineMethodDecorator, defineParameterDecorator, getFactoryRegistry, getStrategyFromRegistry, getStrategyRegistry, getVisitableRegistry, legacyBackend, listStrategies, registerFactory, registerStrategy };
957
1188
  //# sourceMappingURL=index.js.map
958
1189
  //# sourceMappingURL=index.js.map