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.
- package/README.md +24 -6
- package/dist/cli/index.cjs +157 -5
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +157 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/codegen/index.cjs +157 -5
- package/dist/codegen/index.cjs.map +1 -1
- package/dist/codegen/index.js +157 -5
- package/dist/codegen/index.js.map +1 -1
- package/dist/legacy/index.cjs +241 -0
- package/dist/legacy/index.cjs.map +1 -1
- package/dist/legacy/index.d.cts +24 -3
- package/dist/legacy/index.d.ts +24 -3
- package/dist/legacy/index.js +232 -1
- package/dist/legacy/index.js.map +1 -1
- package/dist/stage3/index.cjs +257 -1
- package/dist/stage3/index.cjs.map +1 -1
- package/dist/stage3/index.d.cts +24 -3
- package/dist/stage3/index.d.ts +24 -3
- package/dist/stage3/index.js +248 -2
- package/dist/stage3/index.js.map +1 -1
- package/dist/{chain-of-responsibility-CQ7votcC.d.cts → visitor-B5ByGIWE.d.cts} +26 -1
- package/dist/{chain-of-responsibility-Dwsaoe4x.d.ts → visitor-BqARKwCX.d.ts} +26 -1
- package/package.json +5 -5
package/dist/legacy/index.cjs
CHANGED
|
@@ -84,7 +84,12 @@ var MetadataKeys = {
|
|
|
84
84
|
// Class-level (GoF)
|
|
85
85
|
SINGLETON: `${PREFIX}singleton`,
|
|
86
86
|
FACTORY: `${PREFIX}factory`,
|
|
87
|
+
ABSTRACT_FACTORY: `${PREFIX}abstractFactory`,
|
|
87
88
|
PROTOTYPE: `${PREFIX}prototype`,
|
|
89
|
+
COMPOSITE: `${PREFIX}composite`,
|
|
90
|
+
WRAPS: `${PREFIX}wraps`,
|
|
91
|
+
FLYWEIGHT: `${PREFIX}flyweight`,
|
|
92
|
+
PROXY: `${PREFIX}proxy`,
|
|
88
93
|
CHAIN_OF_RESPONSIBILITY: `${PREFIX}chainOfResponsibility`,
|
|
89
94
|
COMMAND: `${PREFIX}command`,
|
|
90
95
|
ITERABLE: `${PREFIX}iterable`,
|
|
@@ -92,6 +97,9 @@ var MetadataKeys = {
|
|
|
92
97
|
MEMENTO_EXCLUDE: `${PREFIX}memento:exclude`,
|
|
93
98
|
STATE: `${PREFIX}state`,
|
|
94
99
|
STRATEGY: `${PREFIX}strategy`,
|
|
100
|
+
TEMPLATE_METHOD: `${PREFIX}templateMethod`,
|
|
101
|
+
VISITABLE: `${PREFIX}visitable`,
|
|
102
|
+
VISITOR: `${PREFIX}visitor`,
|
|
95
103
|
// Field-level
|
|
96
104
|
GETTER: `${PREFIX}getter`,
|
|
97
105
|
SETTER: `${PREFIX}setter`,
|
|
@@ -104,6 +112,7 @@ var MetadataKeys = {
|
|
|
104
112
|
MEMOIZE: `${PREFIX}memoize`,
|
|
105
113
|
HANDLER: `${PREFIX}handler`,
|
|
106
114
|
TRANSITION: `${PREFIX}transition`,
|
|
115
|
+
HOOK: `${PREFIX}hook`,
|
|
107
116
|
// Parameter-level
|
|
108
117
|
NON_NULL_PARAM: `${PREFIX}nonNull:param`};
|
|
109
118
|
|
|
@@ -849,6 +858,198 @@ function iterateOverFieldLegacy(backend, targetPrototype, propertyKey) {
|
|
|
849
858
|
registerLegacyIterateField(targetPrototype, propertyKey);
|
|
850
859
|
}
|
|
851
860
|
|
|
861
|
+
// src/decorators/shared/flyweight.ts
|
|
862
|
+
var pools = /* @__PURE__ */ new WeakMap();
|
|
863
|
+
function getPool(ctor) {
|
|
864
|
+
let pool = pools.get(ctor);
|
|
865
|
+
if (!pool) {
|
|
866
|
+
pool = /* @__PURE__ */ new Map();
|
|
867
|
+
pools.set(ctor, pool);
|
|
868
|
+
}
|
|
869
|
+
return pool;
|
|
870
|
+
}
|
|
871
|
+
function wrapFlyweightClass(target, options) {
|
|
872
|
+
const pool = getPool(target);
|
|
873
|
+
const FlyweightClass = class extends target {
|
|
874
|
+
constructor(...args) {
|
|
875
|
+
const key = options.key(...args);
|
|
876
|
+
const existing = pool.get(key);
|
|
877
|
+
if (existing) {
|
|
878
|
+
return existing;
|
|
879
|
+
}
|
|
880
|
+
super(...args);
|
|
881
|
+
pool.set(key, this);
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
return FlyweightClass;
|
|
885
|
+
}
|
|
886
|
+
function flyweightClassLegacy(backend, target, options) {
|
|
887
|
+
if (typeof options?.key !== "function") {
|
|
888
|
+
throw new Error("@Flyweight requires a `key` function in options");
|
|
889
|
+
}
|
|
890
|
+
backend.metadata.set(MetadataKeys.FLYWEIGHT, target, void 0, options);
|
|
891
|
+
return wrapFlyweightClass(target, options);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
// src/decorators/shared/composite.ts
|
|
895
|
+
var CHILDREN = /* @__PURE__ */ Symbol("lombok-ts:composite-children");
|
|
896
|
+
function getChildren(instance) {
|
|
897
|
+
const bag = instance;
|
|
898
|
+
if (!bag[CHILDREN]) {
|
|
899
|
+
bag[CHILDREN] = [];
|
|
900
|
+
}
|
|
901
|
+
return bag[CHILDREN];
|
|
902
|
+
}
|
|
903
|
+
function wrapCompositeClass(target) {
|
|
904
|
+
const CompositeClass = class extends target {
|
|
905
|
+
add(child) {
|
|
906
|
+
getChildren(this).push(child);
|
|
907
|
+
}
|
|
908
|
+
remove(child) {
|
|
909
|
+
const children = getChildren(this);
|
|
910
|
+
const index = children.indexOf(child);
|
|
911
|
+
if (index >= 0) {
|
|
912
|
+
children.splice(index, 1);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
getChild(index) {
|
|
916
|
+
const children = getChildren(this);
|
|
917
|
+
const child = children[index];
|
|
918
|
+
if (child === void 0) {
|
|
919
|
+
throw new RangeError(`@Composite: no child at index ${index}`);
|
|
920
|
+
}
|
|
921
|
+
return child;
|
|
922
|
+
}
|
|
923
|
+
getChildren() {
|
|
924
|
+
return [...getChildren(this)];
|
|
925
|
+
}
|
|
926
|
+
traverse(callback) {
|
|
927
|
+
const visit = (node) => {
|
|
928
|
+
callback(node);
|
|
929
|
+
for (const child of getChildren(node)) {
|
|
930
|
+
visit(child);
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
visit(this);
|
|
934
|
+
}
|
|
935
|
+
*[Symbol.iterator]() {
|
|
936
|
+
yield* getChildren(this);
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
return CompositeClass;
|
|
940
|
+
}
|
|
941
|
+
function compositeClassLegacy(backend, target) {
|
|
942
|
+
backend.metadata.set(MetadataKeys.COMPOSITE, target, void 0, true);
|
|
943
|
+
return wrapCompositeClass(target);
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// src/decorators/shared/proxy.ts
|
|
947
|
+
function isMethod(key, value) {
|
|
948
|
+
return typeof key === "string" && key !== "constructor" && typeof value === "function";
|
|
949
|
+
}
|
|
950
|
+
function wrapProxyInstance(instance, hooks) {
|
|
951
|
+
const proto = Object.getPrototypeOf(instance);
|
|
952
|
+
return new Proxy(instance, {
|
|
953
|
+
get(target, prop, receiver) {
|
|
954
|
+
const value = Reflect.get(target, prop, receiver);
|
|
955
|
+
if (!isMethod(prop, value)) {
|
|
956
|
+
return value;
|
|
957
|
+
}
|
|
958
|
+
const original = Object.getOwnPropertyDescriptor(proto, prop)?.value ?? value;
|
|
959
|
+
return (...args) => {
|
|
960
|
+
const methodName = String(prop);
|
|
961
|
+
hooks.before?.(methodName, args);
|
|
962
|
+
const result = original.apply(target, args);
|
|
963
|
+
hooks.after?.(methodName, result);
|
|
964
|
+
return result;
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
function wrapProxyClass(target, hooks) {
|
|
970
|
+
const ProxyClass = class extends target {
|
|
971
|
+
constructor(...args) {
|
|
972
|
+
super(...args);
|
|
973
|
+
return wrapProxyInstance(this, hooks);
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
return ProxyClass;
|
|
977
|
+
}
|
|
978
|
+
function proxyClassLegacy(backend, target, hooks = {}) {
|
|
979
|
+
backend.metadata.set(MetadataKeys.PROXY, target, void 0, hooks);
|
|
980
|
+
return wrapProxyClass(target, hooks);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
// src/decorators/shared/wraps.ts
|
|
984
|
+
var INNER = /* @__PURE__ */ Symbol("lombok-ts:wraps-inner");
|
|
985
|
+
function wrapWrapsClass(target, InnerClass) {
|
|
986
|
+
if (typeof InnerClass !== "function") {
|
|
987
|
+
throw new TypeError("@Wraps requires a constructor function");
|
|
988
|
+
}
|
|
989
|
+
const WrapsClass = class extends target {
|
|
990
|
+
inner;
|
|
991
|
+
constructor(...args) {
|
|
992
|
+
super();
|
|
993
|
+
const inner = args[0];
|
|
994
|
+
if (inner === void 0 || !(inner instanceof InnerClass)) {
|
|
995
|
+
throw new TypeError(`@Wraps(${InnerClass.name}) expects an instance as the first argument`);
|
|
996
|
+
}
|
|
997
|
+
this.inner = inner;
|
|
998
|
+
this[INNER] = inner;
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
return WrapsClass;
|
|
1002
|
+
}
|
|
1003
|
+
function wrapsClassLegacy(backend, target, InnerClass) {
|
|
1004
|
+
backend.metadata.set(MetadataKeys.WRAPS, target, void 0, InnerClass);
|
|
1005
|
+
return wrapWrapsClass(target, InnerClass);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// src/decorators/shared/template-method.ts
|
|
1009
|
+
function templateMethodClassLegacy(backend, target, options) {
|
|
1010
|
+
if (!Array.isArray(options?.steps) || options.steps.length === 0) {
|
|
1011
|
+
throw new Error("@TemplateMethod requires a non-empty `steps` array");
|
|
1012
|
+
}
|
|
1013
|
+
backend.metadata.set(MetadataKeys.TEMPLATE_METHOD, target, void 0, options);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// src/decorators/shared/hook.ts
|
|
1017
|
+
function hookMethodLegacy(backend, targetPrototype, propertyKey, options) {
|
|
1018
|
+
backend.metadata.set(MetadataKeys.HOOK, targetPrototype, propertyKey, options);
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
// src/decorators/shared/abstract-factory.ts
|
|
1022
|
+
function normalizeProducts(productsOrOptions) {
|
|
1023
|
+
const products = Array.isArray(productsOrOptions) ? productsOrOptions : productsOrOptions.products;
|
|
1024
|
+
if (!Array.isArray(products) || products.length === 0) {
|
|
1025
|
+
throw new Error("@AbstractFactory requires a non-empty product list");
|
|
1026
|
+
}
|
|
1027
|
+
return products;
|
|
1028
|
+
}
|
|
1029
|
+
function abstractFactoryClassLegacy(backend, target, productsOrOptions) {
|
|
1030
|
+
const products = normalizeProducts(productsOrOptions);
|
|
1031
|
+
backend.metadata.set(MetadataKeys.ABSTRACT_FACTORY, target, void 0, { products });
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
// src/decorators/shared/visitor.ts
|
|
1035
|
+
var visitableRegistry = /* @__PURE__ */ new Map();
|
|
1036
|
+
function registerVisitable(name, ctor) {
|
|
1037
|
+
visitableRegistry.set(name, ctor);
|
|
1038
|
+
}
|
|
1039
|
+
function getVisitableRegistry() {
|
|
1040
|
+
return visitableRegistry;
|
|
1041
|
+
}
|
|
1042
|
+
function visitorClassLegacy(backend, target, options) {
|
|
1043
|
+
if (!options?.visitMethods || typeof options.visitMethods !== "object") {
|
|
1044
|
+
throw new Error("@Visitor requires a `visitMethods` map");
|
|
1045
|
+
}
|
|
1046
|
+
backend.metadata.set(MetadataKeys.VISITOR, target, void 0, options);
|
|
1047
|
+
}
|
|
1048
|
+
function visitableClassLegacy(backend, target, options = {}) {
|
|
1049
|
+
backend.metadata.set(MetadataKeys.VISITABLE, target, void 0, options);
|
|
1050
|
+
registerVisitable(target.name, target);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
852
1053
|
// src/decorators/legacy/index.ts
|
|
853
1054
|
var NonNull = defineFieldDecorator(nonNullFieldLegacy);
|
|
854
1055
|
function NonNullParam() {
|
|
@@ -954,20 +1155,54 @@ function Handler(options) {
|
|
|
954
1155
|
}
|
|
955
1156
|
var Iterable = defineClassDecorator(iterableClassLegacy);
|
|
956
1157
|
var IterateOver = defineFieldDecorator(iterateOverFieldLegacy);
|
|
1158
|
+
function Flyweight(options) {
|
|
1159
|
+
return defineClassDecorator((backend, target) => flyweightClassLegacy(backend, target, options));
|
|
1160
|
+
}
|
|
1161
|
+
var Composite = defineClassDecorator(compositeClassLegacy);
|
|
1162
|
+
function Proxy2(hooks = {}) {
|
|
1163
|
+
return defineClassDecorator((backend, target) => proxyClassLegacy(backend, target, hooks));
|
|
1164
|
+
}
|
|
1165
|
+
function Wraps(InnerClass) {
|
|
1166
|
+
return defineClassDecorator((backend, target) => wrapsClassLegacy(backend, target, InnerClass));
|
|
1167
|
+
}
|
|
1168
|
+
function TemplateMethod(options) {
|
|
1169
|
+
return defineClassDecorator(
|
|
1170
|
+
(backend, target) => templateMethodClassLegacy(backend, target, options)
|
|
1171
|
+
);
|
|
1172
|
+
}
|
|
1173
|
+
function Hook(options) {
|
|
1174
|
+
return defineMethodDecorator((backend, target, key) => {
|
|
1175
|
+
const name = options?.name ?? String(key);
|
|
1176
|
+
hookMethodLegacy(backend, target, key, { name });
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
function AbstractFactory(products) {
|
|
1180
|
+
return defineClassDecorator(
|
|
1181
|
+
(backend, target) => abstractFactoryClassLegacy(backend, target, products)
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
function Visitor(options) {
|
|
1185
|
+
return defineClassDecorator((backend, target) => visitorClassLegacy(backend, target, options));
|
|
1186
|
+
}
|
|
1187
|
+
var Visitable = defineClassDecorator(visitableClassLegacy);
|
|
957
1188
|
|
|
1189
|
+
exports.AbstractFactory = AbstractFactory;
|
|
958
1190
|
exports.Accessors = Accessors;
|
|
959
1191
|
exports.Builder = Builder;
|
|
960
1192
|
exports.ChainOfResponsibility = ChainOfResponsibility;
|
|
961
1193
|
exports.Command = Command;
|
|
962
1194
|
exports.CommandHistory = CommandHistory;
|
|
1195
|
+
exports.Composite = Composite;
|
|
963
1196
|
exports.Data = Data;
|
|
964
1197
|
exports.Delegate = Delegate;
|
|
965
1198
|
exports.Equals = Equals;
|
|
966
1199
|
exports.EqualsExclude = EqualsExclude;
|
|
967
1200
|
exports.Factory = Factory;
|
|
968
1201
|
exports.FieldDefaults = FieldDefaults;
|
|
1202
|
+
exports.Flyweight = Flyweight;
|
|
969
1203
|
exports.Getter = Getter;
|
|
970
1204
|
exports.Handler = Handler;
|
|
1205
|
+
exports.Hook = Hook;
|
|
971
1206
|
exports.Iterable = Iterable;
|
|
972
1207
|
exports.IterateOver = IterateOver;
|
|
973
1208
|
exports.LegacyBackend = LegacyBackend;
|
|
@@ -979,16 +1214,21 @@ exports.NonNullParam = NonNullParam;
|
|
|
979
1214
|
exports.Observable = Observable;
|
|
980
1215
|
exports.Observer = Observer;
|
|
981
1216
|
exports.Prototype = Prototype;
|
|
1217
|
+
exports.Proxy = Proxy2;
|
|
982
1218
|
exports.Setter = Setter;
|
|
983
1219
|
exports.Singleton = Singleton;
|
|
984
1220
|
exports.State = State;
|
|
985
1221
|
exports.Strategy = Strategy;
|
|
986
1222
|
exports.StrategyRegistry = StrategyRegistry;
|
|
1223
|
+
exports.TemplateMethod = TemplateMethod;
|
|
987
1224
|
exports.ToString = ToString;
|
|
988
1225
|
exports.Transition = Transition;
|
|
989
1226
|
exports.UtilityClass = UtilityClass;
|
|
990
1227
|
exports.Value = Value;
|
|
1228
|
+
exports.Visitable = Visitable;
|
|
1229
|
+
exports.Visitor = Visitor;
|
|
991
1230
|
exports.With = With;
|
|
1231
|
+
exports.Wraps = Wraps;
|
|
992
1232
|
exports.createFromFactory = createFromFactory;
|
|
993
1233
|
exports.defineClassDecorator = defineClassDecorator;
|
|
994
1234
|
exports.defineFieldDecorator = defineFieldDecorator;
|
|
@@ -997,6 +1237,7 @@ exports.defineParameterDecorator = defineParameterDecorator;
|
|
|
997
1237
|
exports.getFactoryRegistry = getFactoryRegistry;
|
|
998
1238
|
exports.getStrategyFromRegistry = getStrategyFromRegistry;
|
|
999
1239
|
exports.getStrategyRegistry = getStrategyRegistry;
|
|
1240
|
+
exports.getVisitableRegistry = getVisitableRegistry;
|
|
1000
1241
|
exports.legacyBackend = legacyBackend;
|
|
1001
1242
|
exports.listStrategies = listStrategies;
|
|
1002
1243
|
exports.registerFactory = registerFactory;
|