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.
- package/README.md +11 -5
- package/dist/cli/index.cjs +8 -0
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +8 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/codegen/index.cjs +8 -0
- package/dist/codegen/index.cjs.map +1 -1
- package/dist/codegen/index.js +8 -0
- package/dist/codegen/index.js.map +1 -1
- package/dist/legacy/index.cjs +135 -0
- package/dist/legacy/index.cjs.map +1 -1
- package/dist/legacy/index.d.cts +9 -3
- package/dist/legacy/index.d.ts +9 -3
- package/dist/legacy/index.js +133 -1
- package/dist/legacy/index.js.map +1 -1
- package/dist/{chain-of-responsibility-CQ7votcC.d.cts → proxy-BJ6_DDQ0.d.cts} +10 -1
- package/dist/{chain-of-responsibility-Dwsaoe4x.d.ts → proxy-BQ3WvvT_.d.ts} +10 -1
- package/dist/stage3/index.cjs +139 -0
- package/dist/stage3/index.cjs.map +1 -1
- package/dist/stage3/index.d.cts +9 -3
- package/dist/stage3/index.d.ts +9 -3
- package/dist/stage3/index.js +137 -1
- package/dist/stage3/index.js.map +1 -1
- package/package.json +5 -5
package/dist/legacy/index.js
CHANGED
|
@@ -83,6 +83,9 @@ var MetadataKeys = {
|
|
|
83
83
|
SINGLETON: `${PREFIX}singleton`,
|
|
84
84
|
FACTORY: `${PREFIX}factory`,
|
|
85
85
|
PROTOTYPE: `${PREFIX}prototype`,
|
|
86
|
+
COMPOSITE: `${PREFIX}composite`,
|
|
87
|
+
FLYWEIGHT: `${PREFIX}flyweight`,
|
|
88
|
+
PROXY: `${PREFIX}proxy`,
|
|
86
89
|
CHAIN_OF_RESPONSIBILITY: `${PREFIX}chainOfResponsibility`,
|
|
87
90
|
COMMAND: `${PREFIX}command`,
|
|
88
91
|
ITERABLE: `${PREFIX}iterable`,
|
|
@@ -847,6 +850,128 @@ function iterateOverFieldLegacy(backend, targetPrototype, propertyKey) {
|
|
|
847
850
|
registerLegacyIterateField(targetPrototype, propertyKey);
|
|
848
851
|
}
|
|
849
852
|
|
|
853
|
+
// src/decorators/shared/flyweight.ts
|
|
854
|
+
var pools = /* @__PURE__ */ new WeakMap();
|
|
855
|
+
function getPool(ctor) {
|
|
856
|
+
let pool = pools.get(ctor);
|
|
857
|
+
if (!pool) {
|
|
858
|
+
pool = /* @__PURE__ */ new Map();
|
|
859
|
+
pools.set(ctor, pool);
|
|
860
|
+
}
|
|
861
|
+
return pool;
|
|
862
|
+
}
|
|
863
|
+
function wrapFlyweightClass(target, options) {
|
|
864
|
+
const pool = getPool(target);
|
|
865
|
+
const FlyweightClass = class extends target {
|
|
866
|
+
constructor(...args) {
|
|
867
|
+
const key = options.key(...args);
|
|
868
|
+
const existing = pool.get(key);
|
|
869
|
+
if (existing) {
|
|
870
|
+
return existing;
|
|
871
|
+
}
|
|
872
|
+
super(...args);
|
|
873
|
+
pool.set(key, this);
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
return FlyweightClass;
|
|
877
|
+
}
|
|
878
|
+
function flyweightClassLegacy(backend, target, options) {
|
|
879
|
+
if (typeof options?.key !== "function") {
|
|
880
|
+
throw new Error("@Flyweight requires a `key` function in options");
|
|
881
|
+
}
|
|
882
|
+
backend.metadata.set(MetadataKeys.FLYWEIGHT, target, void 0, options);
|
|
883
|
+
return wrapFlyweightClass(target, options);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// src/decorators/shared/composite.ts
|
|
887
|
+
var CHILDREN = /* @__PURE__ */ Symbol("lombok-ts:composite-children");
|
|
888
|
+
function getChildren(instance) {
|
|
889
|
+
const bag = instance;
|
|
890
|
+
if (!bag[CHILDREN]) {
|
|
891
|
+
bag[CHILDREN] = [];
|
|
892
|
+
}
|
|
893
|
+
return bag[CHILDREN];
|
|
894
|
+
}
|
|
895
|
+
function wrapCompositeClass(target) {
|
|
896
|
+
const CompositeClass = class extends target {
|
|
897
|
+
add(child) {
|
|
898
|
+
getChildren(this).push(child);
|
|
899
|
+
}
|
|
900
|
+
remove(child) {
|
|
901
|
+
const children = getChildren(this);
|
|
902
|
+
const index = children.indexOf(child);
|
|
903
|
+
if (index >= 0) {
|
|
904
|
+
children.splice(index, 1);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
getChild(index) {
|
|
908
|
+
const children = getChildren(this);
|
|
909
|
+
const child = children[index];
|
|
910
|
+
if (child === void 0) {
|
|
911
|
+
throw new RangeError(`@Composite: no child at index ${index}`);
|
|
912
|
+
}
|
|
913
|
+
return child;
|
|
914
|
+
}
|
|
915
|
+
getChildren() {
|
|
916
|
+
return [...getChildren(this)];
|
|
917
|
+
}
|
|
918
|
+
traverse(callback) {
|
|
919
|
+
const visit = (node) => {
|
|
920
|
+
callback(node);
|
|
921
|
+
for (const child of getChildren(node)) {
|
|
922
|
+
visit(child);
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
visit(this);
|
|
926
|
+
}
|
|
927
|
+
*[Symbol.iterator]() {
|
|
928
|
+
yield* getChildren(this);
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
return CompositeClass;
|
|
932
|
+
}
|
|
933
|
+
function compositeClassLegacy(backend, target) {
|
|
934
|
+
backend.metadata.set(MetadataKeys.COMPOSITE, target, void 0, true);
|
|
935
|
+
return wrapCompositeClass(target);
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// src/decorators/shared/proxy.ts
|
|
939
|
+
function isMethod(key, value) {
|
|
940
|
+
return typeof key === "string" && key !== "constructor" && typeof value === "function";
|
|
941
|
+
}
|
|
942
|
+
function wrapProxyInstance(instance, hooks) {
|
|
943
|
+
const proto = Object.getPrototypeOf(instance);
|
|
944
|
+
return new Proxy(instance, {
|
|
945
|
+
get(target, prop, receiver) {
|
|
946
|
+
const value = Reflect.get(target, prop, receiver);
|
|
947
|
+
if (!isMethod(prop, value)) {
|
|
948
|
+
return value;
|
|
949
|
+
}
|
|
950
|
+
const original = Object.getOwnPropertyDescriptor(proto, prop)?.value ?? value;
|
|
951
|
+
return (...args) => {
|
|
952
|
+
const methodName = String(prop);
|
|
953
|
+
hooks.before?.(methodName, args);
|
|
954
|
+
const result = original.apply(target, args);
|
|
955
|
+
hooks.after?.(methodName, result);
|
|
956
|
+
return result;
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
function wrapProxyClass(target, hooks) {
|
|
962
|
+
const ProxyClass = class extends target {
|
|
963
|
+
constructor(...args) {
|
|
964
|
+
super(...args);
|
|
965
|
+
return wrapProxyInstance(this, hooks);
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
return ProxyClass;
|
|
969
|
+
}
|
|
970
|
+
function proxyClassLegacy(backend, target, hooks = {}) {
|
|
971
|
+
backend.metadata.set(MetadataKeys.PROXY, target, void 0, hooks);
|
|
972
|
+
return wrapProxyClass(target, hooks);
|
|
973
|
+
}
|
|
974
|
+
|
|
850
975
|
// src/decorators/legacy/index.ts
|
|
851
976
|
var NonNull = defineFieldDecorator(nonNullFieldLegacy);
|
|
852
977
|
function NonNullParam() {
|
|
@@ -952,7 +1077,14 @@ function Handler(options) {
|
|
|
952
1077
|
}
|
|
953
1078
|
var Iterable = defineClassDecorator(iterableClassLegacy);
|
|
954
1079
|
var IterateOver = defineFieldDecorator(iterateOverFieldLegacy);
|
|
1080
|
+
function Flyweight(options) {
|
|
1081
|
+
return defineClassDecorator((backend, target) => flyweightClassLegacy(backend, target, options));
|
|
1082
|
+
}
|
|
1083
|
+
var Composite = defineClassDecorator(compositeClassLegacy);
|
|
1084
|
+
function Proxy2(hooks = {}) {
|
|
1085
|
+
return defineClassDecorator((backend, target) => proxyClassLegacy(backend, target, hooks));
|
|
1086
|
+
}
|
|
955
1087
|
|
|
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 };
|
|
1088
|
+
export { Accessors, Builder, ChainOfResponsibility, Command, CommandHistory, Composite, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Flyweight, Getter, Handler, Iterable, IterateOver, LegacyBackend, Log, Memento, Memoize, NonNull, NonNullParam, Observable, Observer, Prototype, Proxy2 as Proxy, Setter, Singleton, State, Strategy, StrategyRegistry, ToString, Transition, UtilityClass, Value, With, createFromFactory, defineClassDecorator, defineFieldDecorator, defineMethodDecorator, defineParameterDecorator, getFactoryRegistry, getStrategyFromRegistry, getStrategyRegistry, legacyBackend, listStrategies, registerFactory, registerStrategy };
|
|
957
1089
|
//# sourceMappingURL=index.js.map
|
|
958
1090
|
//# sourceMappingURL=index.js.map
|