lombok-typescript 0.3.0 → 0.5.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 +44 -12
- package/dist/{log-Dpr79VRt.d.cts → chain-of-responsibility-CQ7votcC.d.cts} +45 -1
- package/dist/{log-Dbe0sSP1.d.ts → chain-of-responsibility-Dwsaoe4x.d.ts} +45 -1
- package/dist/cli/index.cjs +19 -1
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +19 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/codegen/index.cjs +18 -0
- package/dist/codegen/index.cjs.map +1 -1
- package/dist/codegen/index.js +18 -0
- package/dist/codegen/index.js.map +1 -1
- package/dist/core/index.cjs +1 -0
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/legacy/index.cjs +539 -0
- package/dist/legacy/index.cjs.map +1 -1
- package/dist/legacy/index.d.cts +29 -3
- package/dist/legacy/index.d.ts +29 -3
- package/dist/legacy/index.js +523 -1
- package/dist/legacy/index.js.map +1 -1
- package/dist/observable-AIiQMzLD.d.cts +6 -0
- package/dist/observable-AIiQMzLD.d.ts +6 -0
- package/dist/observers/mobx.cjs +17 -0
- package/dist/observers/mobx.cjs.map +1 -0
- package/dist/observers/mobx.d.cts +10 -0
- package/dist/observers/mobx.d.ts +10 -0
- package/dist/observers/mobx.js +12 -0
- package/dist/observers/mobx.js.map +1 -0
- package/dist/observers/rxjs.cjs +17 -0
- package/dist/observers/rxjs.cjs.map +1 -0
- package/dist/observers/rxjs.d.cts +10 -0
- package/dist/observers/rxjs.d.ts +10 -0
- package/dist/observers/rxjs.js +15 -0
- package/dist/observers/rxjs.js.map +1 -0
- package/dist/stage3/index.cjs +570 -1
- package/dist/stage3/index.cjs.map +1 -1
- package/dist/stage3/index.d.cts +31 -3
- package/dist/stage3/index.d.ts +31 -3
- package/dist/stage3/index.js +554 -2
- package/dist/stage3/index.js.map +1 -1
- package/package.json +40 -5
package/dist/legacy/index.js
CHANGED
|
@@ -77,10 +77,19 @@ var MetadataKeys = {
|
|
|
77
77
|
FIELD_DEFAULTS: `${PREFIX}fieldDefaults`,
|
|
78
78
|
ACCESSORS: `${PREFIX}accessors`,
|
|
79
79
|
LOG: `${PREFIX}log`,
|
|
80
|
+
// Class-level (TS-only)
|
|
81
|
+
OBSERVABLE: `${PREFIX}observable`,
|
|
80
82
|
// Class-level (GoF)
|
|
81
83
|
SINGLETON: `${PREFIX}singleton`,
|
|
82
84
|
FACTORY: `${PREFIX}factory`,
|
|
83
85
|
PROTOTYPE: `${PREFIX}prototype`,
|
|
86
|
+
CHAIN_OF_RESPONSIBILITY: `${PREFIX}chainOfResponsibility`,
|
|
87
|
+
COMMAND: `${PREFIX}command`,
|
|
88
|
+
ITERABLE: `${PREFIX}iterable`,
|
|
89
|
+
MEMENTO: `${PREFIX}memento`,
|
|
90
|
+
MEMENTO_EXCLUDE: `${PREFIX}memento:exclude`,
|
|
91
|
+
STATE: `${PREFIX}state`,
|
|
92
|
+
STRATEGY: `${PREFIX}strategy`,
|
|
84
93
|
// Field-level
|
|
85
94
|
GETTER: `${PREFIX}getter`,
|
|
86
95
|
SETTER: `${PREFIX}setter`,
|
|
@@ -88,8 +97,11 @@ var MetadataKeys = {
|
|
|
88
97
|
WITH: `${PREFIX}with`,
|
|
89
98
|
DELEGATE: `${PREFIX}delegate`,
|
|
90
99
|
EQUALS_EXCLUDE: `${PREFIX}equals:exclude`,
|
|
100
|
+
ITERATE_OVER: `${PREFIX}iterateOver`,
|
|
91
101
|
// Method-level
|
|
92
102
|
MEMOIZE: `${PREFIX}memoize`,
|
|
103
|
+
HANDLER: `${PREFIX}handler`,
|
|
104
|
+
TRANSITION: `${PREFIX}transition`,
|
|
93
105
|
// Parameter-level
|
|
94
106
|
NON_NULL_PARAM: `${PREFIX}nonNull:param`};
|
|
95
107
|
|
|
@@ -357,6 +369,484 @@ function withFieldLegacy(backend, targetPrototype, propertyKey) {
|
|
|
357
369
|
fieldMarkerLegacy(backend, targetPrototype, propertyKey, MetadataKeys.WITH);
|
|
358
370
|
}
|
|
359
371
|
|
|
372
|
+
// src/decorators/shared/strategy.ts
|
|
373
|
+
var strategyRegistry = /* @__PURE__ */ new Map();
|
|
374
|
+
function familyBucket(family, create = false) {
|
|
375
|
+
let bucket = strategyRegistry.get(family);
|
|
376
|
+
if (!bucket && create) {
|
|
377
|
+
bucket = /* @__PURE__ */ new Map();
|
|
378
|
+
strategyRegistry.set(family, bucket);
|
|
379
|
+
}
|
|
380
|
+
return bucket;
|
|
381
|
+
}
|
|
382
|
+
function registerStrategy(family, name, ctor) {
|
|
383
|
+
const bucket = familyBucket(family, true);
|
|
384
|
+
bucket.set(name, ctor);
|
|
385
|
+
}
|
|
386
|
+
function getStrategyFromRegistry(family, name) {
|
|
387
|
+
const ctor = familyBucket(family)?.get(name);
|
|
388
|
+
if (!ctor) {
|
|
389
|
+
throw new Error(`No strategy registered for family "${family}" and name "${name}"`);
|
|
390
|
+
}
|
|
391
|
+
return new ctor();
|
|
392
|
+
}
|
|
393
|
+
function listStrategies(family) {
|
|
394
|
+
const bucket = familyBucket(family);
|
|
395
|
+
return bucket ? Array.from(bucket.keys()) : [];
|
|
396
|
+
}
|
|
397
|
+
function getStrategyRegistry() {
|
|
398
|
+
return strategyRegistry;
|
|
399
|
+
}
|
|
400
|
+
var StrategyRegistry = {
|
|
401
|
+
get: getStrategyFromRegistry,
|
|
402
|
+
list: listStrategies
|
|
403
|
+
};
|
|
404
|
+
function strategyClassLegacy(backend, target, family, name) {
|
|
405
|
+
backend.metadata.set(MetadataKeys.STRATEGY, target, void 0, { family, name });
|
|
406
|
+
registerStrategy(family, name, target);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/decorators/shared/transition.ts
|
|
410
|
+
function normalizeFromStates(from) {
|
|
411
|
+
return Array.isArray(from) ? from : [from];
|
|
412
|
+
}
|
|
413
|
+
function transitionMethodLegacy(backend, targetPrototype, propertyKey, descriptor, options) {
|
|
414
|
+
backend.metadata.set(MetadataKeys.TRANSITION, targetPrototype, propertyKey, options);
|
|
415
|
+
return descriptor;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// src/decorators/shared/state.ts
|
|
419
|
+
var STATE_SYMBOL = /* @__PURE__ */ Symbol("lombok-ts:state");
|
|
420
|
+
function collectTransitionMethods(metadata, proto, classMetadata) {
|
|
421
|
+
const transitions = /* @__PURE__ */ new Map();
|
|
422
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
423
|
+
if (key === "constructor") continue;
|
|
424
|
+
const options = metadata.get(MetadataKeys.TRANSITION, proto, key) ?? (void 0);
|
|
425
|
+
if (!options) continue;
|
|
426
|
+
const desc = Object.getOwnPropertyDescriptor(proto, key);
|
|
427
|
+
if (!desc || typeof desc.value !== "function") continue;
|
|
428
|
+
transitions.set(key, { options, original: desc.value });
|
|
429
|
+
}
|
|
430
|
+
return transitions;
|
|
431
|
+
}
|
|
432
|
+
function applyStateWrapping(backend, target, options, classMetadata) {
|
|
433
|
+
const { states, initial, onEnter, onExit, onTransition } = options;
|
|
434
|
+
if (!states.includes(initial)) {
|
|
435
|
+
throw new Error(`@State initial state "${initial}" is not in states: [${states.join(", ")}]`);
|
|
436
|
+
}
|
|
437
|
+
const transitions = collectTransitionMethods(
|
|
438
|
+
backend.metadata,
|
|
439
|
+
target.prototype);
|
|
440
|
+
const StateClass = class extends target {
|
|
441
|
+
constructor(...args) {
|
|
442
|
+
super(...args);
|
|
443
|
+
Object.defineProperty(this, STATE_SYMBOL, {
|
|
444
|
+
value: initial,
|
|
445
|
+
writable: true,
|
|
446
|
+
enumerable: false,
|
|
447
|
+
configurable: false
|
|
448
|
+
});
|
|
449
|
+
onEnter?.(initial);
|
|
450
|
+
}
|
|
451
|
+
get state() {
|
|
452
|
+
return this[STATE_SYMBOL] ?? initial;
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
const stateProto = StateClass.prototype;
|
|
456
|
+
for (const [methodName, { options: transition, original }] of transitions) {
|
|
457
|
+
const fromStates = normalizeFromStates(transition.from);
|
|
458
|
+
const toState = transition.to;
|
|
459
|
+
if (!states.includes(toState)) {
|
|
460
|
+
throw new Error(`@Transition on "${methodName}" targets unknown state "${toState}"`);
|
|
461
|
+
}
|
|
462
|
+
for (const from of fromStates) {
|
|
463
|
+
if (!states.includes(from)) {
|
|
464
|
+
throw new Error(`@Transition on "${methodName}" references unknown state "${from}"`);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
Object.defineProperty(stateProto, methodName, {
|
|
468
|
+
configurable: true,
|
|
469
|
+
enumerable: false,
|
|
470
|
+
writable: true,
|
|
471
|
+
value: function stateTransitionWrapper(...args) {
|
|
472
|
+
const self = this;
|
|
473
|
+
const current = self[STATE_SYMBOL] ?? "";
|
|
474
|
+
if (!fromStates.includes(current)) {
|
|
475
|
+
throw new Error(
|
|
476
|
+
`Cannot transition from "${current}" to "${toState}" via ${methodName}()`
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
onExit?.(current);
|
|
480
|
+
const result = original.apply(this, args);
|
|
481
|
+
self[STATE_SYMBOL] = toState;
|
|
482
|
+
onTransition?.(current, toState);
|
|
483
|
+
onEnter?.(toState);
|
|
484
|
+
return result;
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
return StateClass;
|
|
489
|
+
}
|
|
490
|
+
function stateClassLegacy(backend, target, options) {
|
|
491
|
+
backend.metadata.set(MetadataKeys.STATE, target, void 0, options);
|
|
492
|
+
return applyStateWrapping(backend, target, options);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// src/decorators/shared/command.ts
|
|
496
|
+
function assertCommand(target) {
|
|
497
|
+
const proto = target.prototype;
|
|
498
|
+
if (typeof proto.execute !== "function") {
|
|
499
|
+
throw new Error(`@Command class ${target.name} must define execute()`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
function commandClassLegacy(backend, target) {
|
|
503
|
+
assertCommand(target);
|
|
504
|
+
backend.metadata.set(MetadataKeys.COMMAND, target, void 0, true);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// src/decorators/shared/command-history.ts
|
|
508
|
+
var CommandHistory = class {
|
|
509
|
+
undoStack = [];
|
|
510
|
+
redoStack = [];
|
|
511
|
+
execute(cmd) {
|
|
512
|
+
const result = cmd.execute();
|
|
513
|
+
this.undoStack.push(cmd);
|
|
514
|
+
this.redoStack.length = 0;
|
|
515
|
+
return result;
|
|
516
|
+
}
|
|
517
|
+
undo() {
|
|
518
|
+
const cmd = this.undoStack.pop();
|
|
519
|
+
if (!cmd) {
|
|
520
|
+
throw new Error("Nothing to undo");
|
|
521
|
+
}
|
|
522
|
+
if (typeof cmd.undo !== "function") {
|
|
523
|
+
this.undoStack.push(cmd);
|
|
524
|
+
throw new Error("Command does not support undo()");
|
|
525
|
+
}
|
|
526
|
+
const result = cmd.undo();
|
|
527
|
+
this.redoStack.push(cmd);
|
|
528
|
+
return result;
|
|
529
|
+
}
|
|
530
|
+
redo() {
|
|
531
|
+
const cmd = this.redoStack.pop();
|
|
532
|
+
if (!cmd) {
|
|
533
|
+
throw new Error("Nothing to redo");
|
|
534
|
+
}
|
|
535
|
+
const result = cmd.execute();
|
|
536
|
+
this.undoStack.push(cmd);
|
|
537
|
+
return result;
|
|
538
|
+
}
|
|
539
|
+
get canUndo() {
|
|
540
|
+
return this.undoStack.length > 0;
|
|
541
|
+
}
|
|
542
|
+
get canRedo() {
|
|
543
|
+
return this.redoStack.length > 0;
|
|
544
|
+
}
|
|
545
|
+
clear() {
|
|
546
|
+
this.undoStack.length = 0;
|
|
547
|
+
this.redoStack.length = 0;
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
// src/decorators/shared/memento.ts
|
|
552
|
+
var MEMENTO_SNAPSHOT = /* @__PURE__ */ Symbol("lombok-ts:memento-snapshot");
|
|
553
|
+
var legacyMementoExcluded = /* @__PURE__ */ new WeakMap();
|
|
554
|
+
function registerLegacyMementoExclude(proto, field) {
|
|
555
|
+
const set = legacyMementoExcluded.get(proto) ?? /* @__PURE__ */ new Set();
|
|
556
|
+
set.add(field);
|
|
557
|
+
legacyMementoExcluded.set(proto, set);
|
|
558
|
+
}
|
|
559
|
+
function isMementoSnapshot(value) {
|
|
560
|
+
return typeof value === "object" && value !== null && value[MEMENTO_SNAPSHOT] === true;
|
|
561
|
+
}
|
|
562
|
+
function collectExcludedFields(metadata, proto, classMetadata) {
|
|
563
|
+
const excluded = /* @__PURE__ */ new Set();
|
|
564
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
565
|
+
if (key === "constructor") continue;
|
|
566
|
+
if (metadata.has(MetadataKeys.MEMENTO_EXCLUDE, proto, key) || classMetadata) {
|
|
567
|
+
excluded.add(key);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
for (const key of legacyMementoExcluded.get(proto) ?? []) {
|
|
571
|
+
excluded.add(key);
|
|
572
|
+
}
|
|
573
|
+
return excluded;
|
|
574
|
+
}
|
|
575
|
+
function snapshotInstance(instance, excluded) {
|
|
576
|
+
const data = {};
|
|
577
|
+
for (const key of Object.keys(instance)) {
|
|
578
|
+
if (excluded.has(key)) continue;
|
|
579
|
+
if (key === "save" || key === "restore") continue;
|
|
580
|
+
data[key] = deepClone(instance[key]);
|
|
581
|
+
}
|
|
582
|
+
return { [MEMENTO_SNAPSHOT]: true, data };
|
|
583
|
+
}
|
|
584
|
+
function applySnapshot(instance, snapshot) {
|
|
585
|
+
for (const [key, value] of Object.entries(snapshot.data)) {
|
|
586
|
+
instance[key] = deepClone(value);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
function wrapMementoClass(backend, target, classMetadata) {
|
|
590
|
+
const excluded = collectExcludedFields(
|
|
591
|
+
backend.metadata,
|
|
592
|
+
target.prototype,
|
|
593
|
+
classMetadata
|
|
594
|
+
);
|
|
595
|
+
const MementoClass = class extends target {
|
|
596
|
+
save() {
|
|
597
|
+
return snapshotInstance(this, excluded);
|
|
598
|
+
}
|
|
599
|
+
restore(snapshot) {
|
|
600
|
+
if (!isMementoSnapshot(snapshot)) {
|
|
601
|
+
throw new TypeError("restore() expects a snapshot returned from save()");
|
|
602
|
+
}
|
|
603
|
+
applySnapshot(this, snapshot);
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
return MementoClass;
|
|
607
|
+
}
|
|
608
|
+
function mementoClassLegacy(backend, target) {
|
|
609
|
+
backend.metadata.set(MetadataKeys.MEMENTO, target, void 0, true);
|
|
610
|
+
return wrapMementoClass(backend, target);
|
|
611
|
+
}
|
|
612
|
+
function mementoExcludeFieldLegacy(backend, targetPrototype, propertyKey) {
|
|
613
|
+
backend.metadata.set(MetadataKeys.MEMENTO_EXCLUDE, targetPrototype, propertyKey, true);
|
|
614
|
+
registerLegacyMementoExclude(targetPrototype, String(propertyKey));
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// src/decorators/shared/observable.ts
|
|
618
|
+
var LISTENERS = /* @__PURE__ */ Symbol("lombok-ts:observable-listeners");
|
|
619
|
+
function findGetter(proto, key) {
|
|
620
|
+
let current = proto;
|
|
621
|
+
while (current) {
|
|
622
|
+
const desc = Object.getOwnPropertyDescriptor(current, key);
|
|
623
|
+
if (desc?.get) return desc.get;
|
|
624
|
+
current = Object.getPrototypeOf(current);
|
|
625
|
+
}
|
|
626
|
+
return void 0;
|
|
627
|
+
}
|
|
628
|
+
function getInternals(target) {
|
|
629
|
+
const bag = target;
|
|
630
|
+
if (!bag[LISTENERS]) {
|
|
631
|
+
bag[LISTENERS] = {
|
|
632
|
+
listeners: /* @__PURE__ */ new Map(),
|
|
633
|
+
wildcards: /* @__PURE__ */ new Set(),
|
|
634
|
+
derivedKeys: /* @__PURE__ */ new Set(),
|
|
635
|
+
derivedCache: /* @__PURE__ */ new Map()
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
return bag[LISTENERS];
|
|
639
|
+
}
|
|
640
|
+
function notify(internals, key, next, prev) {
|
|
641
|
+
const keyListeners = internals.listeners.get(key);
|
|
642
|
+
if (keyListeners) {
|
|
643
|
+
for (const listener of keyListeners) {
|
|
644
|
+
listener(next, prev);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
for (const listener of internals.wildcards) {
|
|
648
|
+
listener(key, next, prev);
|
|
649
|
+
}
|
|
650
|
+
if (internals.derivedKeys.size > 0) {
|
|
651
|
+
const instance = targetWithInternals(internals);
|
|
652
|
+
for (const derivedKey of internals.derivedKeys) {
|
|
653
|
+
const prevDerived = internals.derivedCache.get(derivedKey);
|
|
654
|
+
internals.derivedCache.delete(derivedKey);
|
|
655
|
+
const getter = findGetter(Object.getPrototypeOf(instance), derivedKey);
|
|
656
|
+
if (!getter) continue;
|
|
657
|
+
const newDerived = getter.call(instance);
|
|
658
|
+
internals.derivedCache.set(derivedKey, newDerived);
|
|
659
|
+
if (prevDerived !== newDerived) {
|
|
660
|
+
const derivedListeners = internals.listeners.get(derivedKey);
|
|
661
|
+
if (derivedListeners) {
|
|
662
|
+
for (const listener of derivedListeners) {
|
|
663
|
+
listener(newDerived, prevDerived);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
var INSTANCE = /* @__PURE__ */ Symbol("lombok-ts:observable-instance");
|
|
671
|
+
function targetWithInternals(internals) {
|
|
672
|
+
return internals[INSTANCE] ?? {};
|
|
673
|
+
}
|
|
674
|
+
function installSubscribe(proto) {
|
|
675
|
+
Object.defineProperty(proto, "subscribe", {
|
|
676
|
+
configurable: true,
|
|
677
|
+
enumerable: false,
|
|
678
|
+
writable: true,
|
|
679
|
+
value: function subscribe(key, listener) {
|
|
680
|
+
const internals = getInternals(this);
|
|
681
|
+
internals[INSTANCE] = this;
|
|
682
|
+
if (key === "*") {
|
|
683
|
+
const wildcardListener = listener;
|
|
684
|
+
internals.wildcards.add(wildcardListener);
|
|
685
|
+
return () => internals.wildcards.delete(wildcardListener);
|
|
686
|
+
}
|
|
687
|
+
const keyListener = listener;
|
|
688
|
+
let set = internals.listeners.get(key);
|
|
689
|
+
if (!set) {
|
|
690
|
+
set = /* @__PURE__ */ new Set();
|
|
691
|
+
internals.listeners.set(key, set);
|
|
692
|
+
}
|
|
693
|
+
set.add(keyListener);
|
|
694
|
+
const proto2 = Object.getPrototypeOf(this);
|
|
695
|
+
if (findGetter(proto2, key)) {
|
|
696
|
+
internals.derivedKeys.add(key);
|
|
697
|
+
}
|
|
698
|
+
return () => set.delete(keyListener);
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
function wrapObservableInstance(instance) {
|
|
703
|
+
const internals = getInternals(instance);
|
|
704
|
+
internals[INSTANCE] = instance;
|
|
705
|
+
return new Proxy(instance, {
|
|
706
|
+
set(target, prop, value, receiver) {
|
|
707
|
+
if (typeof prop === "symbol") {
|
|
708
|
+
return Reflect.set(target, prop, value, receiver);
|
|
709
|
+
}
|
|
710
|
+
const prev = Reflect.get(target, prop, receiver);
|
|
711
|
+
const result = Reflect.set(target, prop, value, receiver);
|
|
712
|
+
if (prev !== value) {
|
|
713
|
+
notify(internals, prop, value, prev);
|
|
714
|
+
}
|
|
715
|
+
return result;
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
function wrapObservableClass(target) {
|
|
720
|
+
installSubscribe(target.prototype);
|
|
721
|
+
const ObservableClass = class extends target {
|
|
722
|
+
constructor(...args) {
|
|
723
|
+
super(...args);
|
|
724
|
+
return wrapObservableInstance(this);
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
return ObservableClass;
|
|
728
|
+
}
|
|
729
|
+
function observableClassLegacy(backend, target) {
|
|
730
|
+
backend.metadata.set(MetadataKeys.OBSERVABLE, target, void 0, true);
|
|
731
|
+
return wrapObservableClass(target);
|
|
732
|
+
}
|
|
733
|
+
function observableDerivedLegacy(backend, targetPrototype, propertyKey, descriptor) {
|
|
734
|
+
backend.metadata.set(MetadataKeys.OBSERVABLE, targetPrototype, propertyKey, { derived: true });
|
|
735
|
+
const originalGet = descriptor.get;
|
|
736
|
+
if (!originalGet) return;
|
|
737
|
+
const key = propertyKey;
|
|
738
|
+
return {
|
|
739
|
+
...descriptor,
|
|
740
|
+
get() {
|
|
741
|
+
const internals = getInternals(this);
|
|
742
|
+
internals[INSTANCE] = this;
|
|
743
|
+
internals.derivedKeys.add(key);
|
|
744
|
+
if (internals.derivedCache.has(key)) {
|
|
745
|
+
return internals.derivedCache.get(key);
|
|
746
|
+
}
|
|
747
|
+
const value = originalGet.call(this);
|
|
748
|
+
internals.derivedCache.set(key, value);
|
|
749
|
+
return value;
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
function observerClassLegacy(backend, target) {
|
|
754
|
+
return observableClassLegacy(backend, target);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// src/decorators/shared/chain-of-responsibility.ts
|
|
758
|
+
function collectHandlers(backend, proto, classMetadata) {
|
|
759
|
+
const handlers = [];
|
|
760
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
761
|
+
if (key === "constructor") continue;
|
|
762
|
+
const options = backend.metadata.get(MetadataKeys.HANDLER, proto, key) ?? (void 0);
|
|
763
|
+
if (!options) continue;
|
|
764
|
+
const desc = Object.getOwnPropertyDescriptor(proto, key);
|
|
765
|
+
if (!desc || typeof desc.value !== "function") continue;
|
|
766
|
+
handlers.push({
|
|
767
|
+
order: options.order,
|
|
768
|
+
method: key,
|
|
769
|
+
fn: desc.value
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
handlers.sort((a, b) => a.order - b.order);
|
|
773
|
+
return handlers;
|
|
774
|
+
}
|
|
775
|
+
function wrapChainClass(backend, target, classMetadata) {
|
|
776
|
+
const handlers = collectHandlers(backend, target.prototype);
|
|
777
|
+
const ChainClass = class extends target {
|
|
778
|
+
handle(context) {
|
|
779
|
+
for (const handler of handlers) {
|
|
780
|
+
const result = handler.fn.call(this, context);
|
|
781
|
+
if (result === true || result !== void 0 && result !== false) {
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return false;
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
return ChainClass;
|
|
789
|
+
}
|
|
790
|
+
function chainOfResponsibilityClassLegacy(backend, target) {
|
|
791
|
+
backend.metadata.set(MetadataKeys.CHAIN_OF_RESPONSIBILITY, target, void 0, true);
|
|
792
|
+
return wrapChainClass(backend, target);
|
|
793
|
+
}
|
|
794
|
+
function handlerMethodLegacy(backend, targetPrototype, propertyKey, descriptor, options) {
|
|
795
|
+
backend.metadata.set(MetadataKeys.HANDLER, targetPrototype, propertyKey, options);
|
|
796
|
+
return descriptor;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// src/decorators/shared/iterable.ts
|
|
800
|
+
var ITERATE_FIELD = /* @__PURE__ */ Symbol("lombok-ts:iterate-over-field");
|
|
801
|
+
var legacyIterateFields = /* @__PURE__ */ new WeakMap();
|
|
802
|
+
function registerLegacyIterateField(proto, field) {
|
|
803
|
+
const existing = legacyIterateFields.get(proto) ?? [];
|
|
804
|
+
existing.push(field);
|
|
805
|
+
legacyIterateFields.set(proto, existing);
|
|
806
|
+
}
|
|
807
|
+
function resolveIterateField(backend, proto, classMetadata) {
|
|
808
|
+
const fields = [];
|
|
809
|
+
for (const key of [
|
|
810
|
+
...Object.getOwnPropertyNames(proto),
|
|
811
|
+
...Object.getOwnPropertySymbols(proto)
|
|
812
|
+
]) {
|
|
813
|
+
if (key === "constructor") continue;
|
|
814
|
+
if (backend.metadata.has(MetadataKeys.ITERATE_OVER, proto, key) || classMetadata) {
|
|
815
|
+
fields.push(key);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
fields.push(...legacyIterateFields.get(proto) ?? []);
|
|
819
|
+
if (fields.length === 0) {
|
|
820
|
+
throw new Error("@Iterable requires exactly one @IterateOver field");
|
|
821
|
+
}
|
|
822
|
+
if (fields.length > 1) {
|
|
823
|
+
throw new Error("@Iterable allows only one @IterateOver field");
|
|
824
|
+
}
|
|
825
|
+
return fields[0];
|
|
826
|
+
}
|
|
827
|
+
function installIterator(target, fieldKey) {
|
|
828
|
+
Object.defineProperty(target.prototype, Symbol.iterator, {
|
|
829
|
+
configurable: true,
|
|
830
|
+
enumerable: false,
|
|
831
|
+
writable: true,
|
|
832
|
+
value: function* iterateOver() {
|
|
833
|
+
const collection = this[fieldKey];
|
|
834
|
+
if (collection == null) return;
|
|
835
|
+
yield* collection;
|
|
836
|
+
}
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
function iterableClassLegacy(backend, target) {
|
|
840
|
+
backend.metadata.set(MetadataKeys.ITERABLE, target, void 0, true);
|
|
841
|
+
const fieldKey = resolveIterateField(backend, target.prototype);
|
|
842
|
+
target[ITERATE_FIELD] = fieldKey;
|
|
843
|
+
installIterator(target, fieldKey);
|
|
844
|
+
}
|
|
845
|
+
function iterateOverFieldLegacy(backend, targetPrototype, propertyKey) {
|
|
846
|
+
backend.metadata.set(MetadataKeys.ITERATE_OVER, targetPrototype, propertyKey, true);
|
|
847
|
+
registerLegacyIterateField(targetPrototype, propertyKey);
|
|
848
|
+
}
|
|
849
|
+
|
|
360
850
|
// src/decorators/legacy/index.ts
|
|
361
851
|
var NonNull = defineFieldDecorator(nonNullFieldLegacy);
|
|
362
852
|
function NonNullParam() {
|
|
@@ -430,7 +920,39 @@ function Delegate(...methods) {
|
|
|
430
920
|
);
|
|
431
921
|
}
|
|
432
922
|
var EqualsExclude = defineFieldDecorator(equalsExcludeFieldLegacy);
|
|
923
|
+
function Strategy(family, name) {
|
|
924
|
+
return defineClassDecorator((backend, target) => {
|
|
925
|
+
strategyClassLegacy(backend, target, family, name);
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
function State(options) {
|
|
929
|
+
return defineClassDecorator((backend, target) => stateClassLegacy(backend, target, options));
|
|
930
|
+
}
|
|
931
|
+
function Transition(options) {
|
|
932
|
+
return defineMethodDecorator(
|
|
933
|
+
(backend, target, key, descriptor) => transitionMethodLegacy(backend, target, key, descriptor, options)
|
|
934
|
+
);
|
|
935
|
+
}
|
|
936
|
+
var Command = defineClassDecorator(commandClassLegacy);
|
|
937
|
+
var Observable = defineClassDecorator(observableClassLegacy);
|
|
938
|
+
Observable.Derived = ((target, propertyKey, descriptor) => {
|
|
939
|
+
if (descriptor === void 0 || typeof descriptor.get !== "function") {
|
|
940
|
+
throw new TypeError("@Observable.Derived requires a getter");
|
|
941
|
+
}
|
|
942
|
+
observableDerivedLegacy(legacyBackend, target, propertyKey, descriptor);
|
|
943
|
+
});
|
|
944
|
+
var Observer = defineClassDecorator(observerClassLegacy);
|
|
945
|
+
var Memento = defineClassDecorator(mementoClassLegacy);
|
|
946
|
+
Memento.Exclude = defineFieldDecorator(mementoExcludeFieldLegacy);
|
|
947
|
+
var ChainOfResponsibility = defineClassDecorator(chainOfResponsibilityClassLegacy);
|
|
948
|
+
function Handler(options) {
|
|
949
|
+
return defineMethodDecorator(
|
|
950
|
+
(backend, target, key, descriptor) => handlerMethodLegacy(backend, target, key, descriptor, options)
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
var Iterable = defineClassDecorator(iterableClassLegacy);
|
|
954
|
+
var IterateOver = defineFieldDecorator(iterateOverFieldLegacy);
|
|
433
955
|
|
|
434
|
-
export { Accessors, Builder, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Getter, LegacyBackend, Log, Memoize, NonNull, NonNullParam, Prototype, Setter, Singleton, ToString, UtilityClass, Value, With, createFromFactory, defineClassDecorator, defineFieldDecorator, defineMethodDecorator, defineParameterDecorator, getFactoryRegistry, legacyBackend, registerFactory };
|
|
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 };
|
|
435
957
|
//# sourceMappingURL=index.js.map
|
|
436
958
|
//# sourceMappingURL=index.js.map
|