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/stage3/index.cjs
CHANGED
|
@@ -103,7 +103,12 @@ var MetadataKeys = {
|
|
|
103
103
|
// Class-level (GoF)
|
|
104
104
|
SINGLETON: `${PREFIX}singleton`,
|
|
105
105
|
FACTORY: `${PREFIX}factory`,
|
|
106
|
+
ABSTRACT_FACTORY: `${PREFIX}abstractFactory`,
|
|
106
107
|
PROTOTYPE: `${PREFIX}prototype`,
|
|
108
|
+
COMPOSITE: `${PREFIX}composite`,
|
|
109
|
+
WRAPS: `${PREFIX}wraps`,
|
|
110
|
+
FLYWEIGHT: `${PREFIX}flyweight`,
|
|
111
|
+
PROXY: `${PREFIX}proxy`,
|
|
107
112
|
CHAIN_OF_RESPONSIBILITY: `${PREFIX}chainOfResponsibility`,
|
|
108
113
|
COMMAND: `${PREFIX}command`,
|
|
109
114
|
ITERABLE: `${PREFIX}iterable`,
|
|
@@ -111,6 +116,9 @@ var MetadataKeys = {
|
|
|
111
116
|
MEMENTO_EXCLUDE: `${PREFIX}memento:exclude`,
|
|
112
117
|
STATE: `${PREFIX}state`,
|
|
113
118
|
STRATEGY: `${PREFIX}strategy`,
|
|
119
|
+
TEMPLATE_METHOD: `${PREFIX}templateMethod`,
|
|
120
|
+
VISITABLE: `${PREFIX}visitable`,
|
|
121
|
+
VISITOR: `${PREFIX}visitor`,
|
|
114
122
|
// Field-level
|
|
115
123
|
GETTER: `${PREFIX}getter`,
|
|
116
124
|
SETTER: `${PREFIX}setter`,
|
|
@@ -122,7 +130,8 @@ var MetadataKeys = {
|
|
|
122
130
|
// Method-level
|
|
123
131
|
MEMOIZE: `${PREFIX}memoize`,
|
|
124
132
|
HANDLER: `${PREFIX}handler`,
|
|
125
|
-
TRANSITION: `${PREFIX}transition
|
|
133
|
+
TRANSITION: `${PREFIX}transition`,
|
|
134
|
+
HOOK: `${PREFIX}hook`};
|
|
126
135
|
|
|
127
136
|
// src/decorators/shared/factory.ts
|
|
128
137
|
var factoryRegistry = /* @__PURE__ */ new Map();
|
|
@@ -876,6 +885,205 @@ function iterateOverFieldStage3(backend, context) {
|
|
|
876
885
|
registerStage3IterateField(context.metadata, context.name);
|
|
877
886
|
}
|
|
878
887
|
|
|
888
|
+
// src/decorators/shared/flyweight.ts
|
|
889
|
+
var pools = /* @__PURE__ */ new WeakMap();
|
|
890
|
+
function getPool(ctor) {
|
|
891
|
+
let pool = pools.get(ctor);
|
|
892
|
+
if (!pool) {
|
|
893
|
+
pool = /* @__PURE__ */ new Map();
|
|
894
|
+
pools.set(ctor, pool);
|
|
895
|
+
}
|
|
896
|
+
return pool;
|
|
897
|
+
}
|
|
898
|
+
function wrapFlyweightClass(target, options) {
|
|
899
|
+
const pool = getPool(target);
|
|
900
|
+
const FlyweightClass = class extends target {
|
|
901
|
+
constructor(...args) {
|
|
902
|
+
const key = options.key(...args);
|
|
903
|
+
const existing = pool.get(key);
|
|
904
|
+
if (existing) {
|
|
905
|
+
return existing;
|
|
906
|
+
}
|
|
907
|
+
super(...args);
|
|
908
|
+
pool.set(key, this);
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
return FlyweightClass;
|
|
912
|
+
}
|
|
913
|
+
function flyweightClassStage3(backend, value, context, options) {
|
|
914
|
+
if (typeof options?.key !== "function") {
|
|
915
|
+
throw new Error("@Flyweight requires a `key` function in options");
|
|
916
|
+
}
|
|
917
|
+
backend.metadata.set(MetadataKeys.FLYWEIGHT, context.metadata, void 0, options);
|
|
918
|
+
return wrapFlyweightClass(value, options);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// src/decorators/shared/composite.ts
|
|
922
|
+
var CHILDREN = /* @__PURE__ */ Symbol("lombok-ts:composite-children");
|
|
923
|
+
function getChildren(instance) {
|
|
924
|
+
const bag = instance;
|
|
925
|
+
if (!bag[CHILDREN]) {
|
|
926
|
+
bag[CHILDREN] = [];
|
|
927
|
+
}
|
|
928
|
+
return bag[CHILDREN];
|
|
929
|
+
}
|
|
930
|
+
function wrapCompositeClass(target) {
|
|
931
|
+
const CompositeClass = class extends target {
|
|
932
|
+
add(child) {
|
|
933
|
+
getChildren(this).push(child);
|
|
934
|
+
}
|
|
935
|
+
remove(child) {
|
|
936
|
+
const children = getChildren(this);
|
|
937
|
+
const index = children.indexOf(child);
|
|
938
|
+
if (index >= 0) {
|
|
939
|
+
children.splice(index, 1);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
getChild(index) {
|
|
943
|
+
const children = getChildren(this);
|
|
944
|
+
const child = children[index];
|
|
945
|
+
if (child === void 0) {
|
|
946
|
+
throw new RangeError(`@Composite: no child at index ${index}`);
|
|
947
|
+
}
|
|
948
|
+
return child;
|
|
949
|
+
}
|
|
950
|
+
getChildren() {
|
|
951
|
+
return [...getChildren(this)];
|
|
952
|
+
}
|
|
953
|
+
traverse(callback) {
|
|
954
|
+
const visit = (node) => {
|
|
955
|
+
callback(node);
|
|
956
|
+
for (const child of getChildren(node)) {
|
|
957
|
+
visit(child);
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
visit(this);
|
|
961
|
+
}
|
|
962
|
+
*[Symbol.iterator]() {
|
|
963
|
+
yield* getChildren(this);
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
return CompositeClass;
|
|
967
|
+
}
|
|
968
|
+
function compositeClassStage3(backend, value, context) {
|
|
969
|
+
backend.metadata.set(MetadataKeys.COMPOSITE, context.metadata, void 0, true);
|
|
970
|
+
return wrapCompositeClass(value);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
// src/decorators/shared/proxy.ts
|
|
974
|
+
function isMethod(key, value) {
|
|
975
|
+
return typeof key === "string" && key !== "constructor" && typeof value === "function";
|
|
976
|
+
}
|
|
977
|
+
function wrapProxyInstance(instance, hooks) {
|
|
978
|
+
const proto = Object.getPrototypeOf(instance);
|
|
979
|
+
return new Proxy(instance, {
|
|
980
|
+
get(target, prop, receiver) {
|
|
981
|
+
const value = Reflect.get(target, prop, receiver);
|
|
982
|
+
if (!isMethod(prop, value)) {
|
|
983
|
+
return value;
|
|
984
|
+
}
|
|
985
|
+
const original = Object.getOwnPropertyDescriptor(proto, prop)?.value ?? value;
|
|
986
|
+
return (...args) => {
|
|
987
|
+
const methodName = String(prop);
|
|
988
|
+
hooks.before?.(methodName, args);
|
|
989
|
+
const result = original.apply(target, args);
|
|
990
|
+
hooks.after?.(methodName, result);
|
|
991
|
+
return result;
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
function wrapProxyClass(target, hooks) {
|
|
997
|
+
const ProxyClass = class extends target {
|
|
998
|
+
constructor(...args) {
|
|
999
|
+
super(...args);
|
|
1000
|
+
return wrapProxyInstance(this, hooks);
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
return ProxyClass;
|
|
1004
|
+
}
|
|
1005
|
+
function proxyClassStage3(backend, value, context, hooks = {}) {
|
|
1006
|
+
backend.metadata.set(MetadataKeys.PROXY, context.metadata, void 0, hooks);
|
|
1007
|
+
return wrapProxyClass(value, hooks);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
// src/decorators/shared/wraps.ts
|
|
1011
|
+
var INNER = /* @__PURE__ */ Symbol("lombok-ts:wraps-inner");
|
|
1012
|
+
function wrapWrapsClass(target, InnerClass) {
|
|
1013
|
+
if (typeof InnerClass !== "function") {
|
|
1014
|
+
throw new TypeError("@Wraps requires a constructor function");
|
|
1015
|
+
}
|
|
1016
|
+
const WrapsClass = class extends target {
|
|
1017
|
+
inner;
|
|
1018
|
+
constructor(...args) {
|
|
1019
|
+
super();
|
|
1020
|
+
const inner = args[0];
|
|
1021
|
+
if (inner === void 0 || !(inner instanceof InnerClass)) {
|
|
1022
|
+
throw new TypeError(`@Wraps(${InnerClass.name}) expects an instance as the first argument`);
|
|
1023
|
+
}
|
|
1024
|
+
this.inner = inner;
|
|
1025
|
+
this[INNER] = inner;
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
return WrapsClass;
|
|
1029
|
+
}
|
|
1030
|
+
function wrapsClassStage3(backend, value, context, InnerClass) {
|
|
1031
|
+
backend.metadata.set(MetadataKeys.WRAPS, context.metadata, void 0, InnerClass);
|
|
1032
|
+
return wrapWrapsClass(value, InnerClass);
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
// src/decorators/shared/template-method.ts
|
|
1036
|
+
function templateMethodClassStage3(backend, _value, context, options) {
|
|
1037
|
+
if (!Array.isArray(options?.steps) || options.steps.length === 0) {
|
|
1038
|
+
throw new Error("@TemplateMethod requires a non-empty `steps` array");
|
|
1039
|
+
}
|
|
1040
|
+
backend.metadata.set(
|
|
1041
|
+
MetadataKeys.TEMPLATE_METHOD,
|
|
1042
|
+
context.metadata,
|
|
1043
|
+
void 0,
|
|
1044
|
+
options
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
// src/decorators/shared/hook.ts
|
|
1049
|
+
function hookMethodStage3(backend, _value, context, options) {
|
|
1050
|
+
backend.metadata.set(MetadataKeys.HOOK, context.metadata, context.name, options);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// src/decorators/shared/abstract-factory.ts
|
|
1054
|
+
function normalizeProducts(productsOrOptions) {
|
|
1055
|
+
const products = Array.isArray(productsOrOptions) ? productsOrOptions : productsOrOptions.products;
|
|
1056
|
+
if (!Array.isArray(products) || products.length === 0) {
|
|
1057
|
+
throw new Error("@AbstractFactory requires a non-empty product list");
|
|
1058
|
+
}
|
|
1059
|
+
return products;
|
|
1060
|
+
}
|
|
1061
|
+
function abstractFactoryClassStage3(backend, _value, context, productsOrOptions) {
|
|
1062
|
+
const products = normalizeProducts(productsOrOptions);
|
|
1063
|
+
backend.metadata.set(MetadataKeys.ABSTRACT_FACTORY, context.metadata, void 0, {
|
|
1064
|
+
products
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
// src/decorators/shared/visitor.ts
|
|
1069
|
+
var visitableRegistry = /* @__PURE__ */ new Map();
|
|
1070
|
+
function registerVisitable(name, ctor) {
|
|
1071
|
+
visitableRegistry.set(name, ctor);
|
|
1072
|
+
}
|
|
1073
|
+
function getVisitableRegistry() {
|
|
1074
|
+
return visitableRegistry;
|
|
1075
|
+
}
|
|
1076
|
+
function visitorClassStage3(backend, _value, context, options) {
|
|
1077
|
+
if (!options?.visitMethods || typeof options.visitMethods !== "object") {
|
|
1078
|
+
throw new Error("@Visitor requires a `visitMethods` map");
|
|
1079
|
+
}
|
|
1080
|
+
backend.metadata.set(MetadataKeys.VISITOR, context.metadata, void 0, options);
|
|
1081
|
+
}
|
|
1082
|
+
function visitableClassStage3(backend, value, context, options = {}) {
|
|
1083
|
+
backend.metadata.set(MetadataKeys.VISITABLE, context.metadata, void 0, options);
|
|
1084
|
+
registerVisitable(value.name, value);
|
|
1085
|
+
}
|
|
1086
|
+
|
|
879
1087
|
// src/decorators/stage3/index.ts
|
|
880
1088
|
var NonNull = defineFieldDecorator(nonNullFieldStage3);
|
|
881
1089
|
var Singleton = defineClassDecorator(singletonClassStage3);
|
|
@@ -987,25 +1195,67 @@ function Handler(options) {
|
|
|
987
1195
|
}
|
|
988
1196
|
var Iterable = defineClassDecorator(iterableClassStage3);
|
|
989
1197
|
var IterateOver = defineFieldDecorator(iterateOverFieldStage3);
|
|
1198
|
+
function Flyweight(options) {
|
|
1199
|
+
return defineClassDecorator(
|
|
1200
|
+
(backend, value, context) => flyweightClassStage3(backend, value, context, options)
|
|
1201
|
+
);
|
|
1202
|
+
}
|
|
1203
|
+
var Composite = defineClassDecorator(compositeClassStage3);
|
|
1204
|
+
function Proxy2(hooks = {}) {
|
|
1205
|
+
return defineClassDecorator(
|
|
1206
|
+
(backend, value, context) => proxyClassStage3(backend, value, context, hooks)
|
|
1207
|
+
);
|
|
1208
|
+
}
|
|
1209
|
+
function Wraps(InnerClass) {
|
|
1210
|
+
return defineClassDecorator(
|
|
1211
|
+
(backend, value, context) => wrapsClassStage3(backend, value, context, InnerClass)
|
|
1212
|
+
);
|
|
1213
|
+
}
|
|
1214
|
+
function TemplateMethod(options) {
|
|
1215
|
+
return defineClassDecorator(
|
|
1216
|
+
(backend, value, context) => templateMethodClassStage3(backend, value, context, options)
|
|
1217
|
+
);
|
|
1218
|
+
}
|
|
1219
|
+
function Hook(options) {
|
|
1220
|
+
return defineMethodDecorator((backend, value, context) => {
|
|
1221
|
+
const name = options?.name ?? String(context.name);
|
|
1222
|
+
hookMethodStage3(backend, value, context, { name });
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
function AbstractFactory(products) {
|
|
1226
|
+
return defineClassDecorator(
|
|
1227
|
+
(backend, value, context) => abstractFactoryClassStage3(backend, value, context, products)
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
function Visitor(options) {
|
|
1231
|
+
return defineClassDecorator(
|
|
1232
|
+
(backend, value, context) => visitorClassStage3(backend, value, context, options)
|
|
1233
|
+
);
|
|
1234
|
+
}
|
|
1235
|
+
var Visitable = defineClassDecorator(visitableClassStage3);
|
|
990
1236
|
|
|
991
1237
|
// src/stage3/index.ts
|
|
992
1238
|
function getClassMetadata(cls) {
|
|
993
1239
|
return cls[Symbol.metadata];
|
|
994
1240
|
}
|
|
995
1241
|
|
|
1242
|
+
exports.AbstractFactory = AbstractFactory;
|
|
996
1243
|
exports.Accessors = Accessors;
|
|
997
1244
|
exports.Builder = Builder;
|
|
998
1245
|
exports.ChainOfResponsibility = ChainOfResponsibility;
|
|
999
1246
|
exports.Command = Command;
|
|
1000
1247
|
exports.CommandHistory = CommandHistory;
|
|
1248
|
+
exports.Composite = Composite;
|
|
1001
1249
|
exports.Data = Data;
|
|
1002
1250
|
exports.Delegate = Delegate;
|
|
1003
1251
|
exports.Equals = Equals;
|
|
1004
1252
|
exports.EqualsExclude = EqualsExclude;
|
|
1005
1253
|
exports.Factory = Factory;
|
|
1006
1254
|
exports.FieldDefaults = FieldDefaults;
|
|
1255
|
+
exports.Flyweight = Flyweight;
|
|
1007
1256
|
exports.Getter = Getter;
|
|
1008
1257
|
exports.Handler = Handler;
|
|
1258
|
+
exports.Hook = Hook;
|
|
1009
1259
|
exports.Iterable = Iterable;
|
|
1010
1260
|
exports.IterateOver = IterateOver;
|
|
1011
1261
|
exports.Log = Log;
|
|
@@ -1015,17 +1265,22 @@ exports.NonNull = NonNull;
|
|
|
1015
1265
|
exports.Observable = Observable;
|
|
1016
1266
|
exports.Observer = Observer;
|
|
1017
1267
|
exports.Prototype = Prototype;
|
|
1268
|
+
exports.Proxy = Proxy2;
|
|
1018
1269
|
exports.Setter = Setter;
|
|
1019
1270
|
exports.Singleton = Singleton;
|
|
1020
1271
|
exports.Stage3Backend = Stage3Backend;
|
|
1021
1272
|
exports.State = State;
|
|
1022
1273
|
exports.Strategy = Strategy;
|
|
1023
1274
|
exports.StrategyRegistry = StrategyRegistry;
|
|
1275
|
+
exports.TemplateMethod = TemplateMethod;
|
|
1024
1276
|
exports.ToString = ToString;
|
|
1025
1277
|
exports.Transition = Transition;
|
|
1026
1278
|
exports.UtilityClass = UtilityClass;
|
|
1027
1279
|
exports.Value = Value;
|
|
1280
|
+
exports.Visitable = Visitable;
|
|
1281
|
+
exports.Visitor = Visitor;
|
|
1028
1282
|
exports.With = With;
|
|
1283
|
+
exports.Wraps = Wraps;
|
|
1029
1284
|
exports.createFromFactory = createFromFactory;
|
|
1030
1285
|
exports.defineClassDecorator = defineClassDecorator;
|
|
1031
1286
|
exports.defineFieldDecorator = defineFieldDecorator;
|
|
@@ -1036,6 +1291,7 @@ exports.getClassMetadata = getClassMetadata;
|
|
|
1036
1291
|
exports.getFactoryRegistry = getFactoryRegistry;
|
|
1037
1292
|
exports.getStrategyFromRegistry = getStrategyFromRegistry;
|
|
1038
1293
|
exports.getStrategyRegistry = getStrategyRegistry;
|
|
1294
|
+
exports.getVisitableRegistry = getVisitableRegistry;
|
|
1039
1295
|
exports.listStrategies = listStrategies;
|
|
1040
1296
|
exports.registerFactory = registerFactory;
|
|
1041
1297
|
exports.registerStrategy = registerStrategy;
|