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/stage3/index.js
CHANGED
|
@@ -96,10 +96,19 @@ var MetadataKeys = {
|
|
|
96
96
|
FIELD_DEFAULTS: `${PREFIX}fieldDefaults`,
|
|
97
97
|
ACCESSORS: `${PREFIX}accessors`,
|
|
98
98
|
LOG: `${PREFIX}log`,
|
|
99
|
+
// Class-level (TS-only)
|
|
100
|
+
OBSERVABLE: `${PREFIX}observable`,
|
|
99
101
|
// Class-level (GoF)
|
|
100
102
|
SINGLETON: `${PREFIX}singleton`,
|
|
101
103
|
FACTORY: `${PREFIX}factory`,
|
|
102
104
|
PROTOTYPE: `${PREFIX}prototype`,
|
|
105
|
+
CHAIN_OF_RESPONSIBILITY: `${PREFIX}chainOfResponsibility`,
|
|
106
|
+
COMMAND: `${PREFIX}command`,
|
|
107
|
+
ITERABLE: `${PREFIX}iterable`,
|
|
108
|
+
MEMENTO: `${PREFIX}memento`,
|
|
109
|
+
MEMENTO_EXCLUDE: `${PREFIX}memento:exclude`,
|
|
110
|
+
STATE: `${PREFIX}state`,
|
|
111
|
+
STRATEGY: `${PREFIX}strategy`,
|
|
103
112
|
// Field-level
|
|
104
113
|
GETTER: `${PREFIX}getter`,
|
|
105
114
|
SETTER: `${PREFIX}setter`,
|
|
@@ -107,8 +116,11 @@ var MetadataKeys = {
|
|
|
107
116
|
WITH: `${PREFIX}with`,
|
|
108
117
|
DELEGATE: `${PREFIX}delegate`,
|
|
109
118
|
EQUALS_EXCLUDE: `${PREFIX}equals:exclude`,
|
|
119
|
+
ITERATE_OVER: `${PREFIX}iterateOver`,
|
|
110
120
|
// Method-level
|
|
111
|
-
MEMOIZE: `${PREFIX}memoize
|
|
121
|
+
MEMOIZE: `${PREFIX}memoize`,
|
|
122
|
+
HANDLER: `${PREFIX}handler`,
|
|
123
|
+
TRANSITION: `${PREFIX}transition`};
|
|
112
124
|
|
|
113
125
|
// src/decorators/shared/factory.ts
|
|
114
126
|
var factoryRegistry = /* @__PURE__ */ new Map();
|
|
@@ -358,6 +370,510 @@ function withFieldStage3(backend, context) {
|
|
|
358
370
|
fieldMarkerStage3(backend, context, MetadataKeys.WITH);
|
|
359
371
|
}
|
|
360
372
|
|
|
373
|
+
// src/decorators/shared/strategy.ts
|
|
374
|
+
var strategyRegistry = /* @__PURE__ */ new Map();
|
|
375
|
+
function familyBucket(family, create = false) {
|
|
376
|
+
let bucket = strategyRegistry.get(family);
|
|
377
|
+
if (!bucket && create) {
|
|
378
|
+
bucket = /* @__PURE__ */ new Map();
|
|
379
|
+
strategyRegistry.set(family, bucket);
|
|
380
|
+
}
|
|
381
|
+
return bucket;
|
|
382
|
+
}
|
|
383
|
+
function registerStrategy(family, name, ctor) {
|
|
384
|
+
const bucket = familyBucket(family, true);
|
|
385
|
+
bucket.set(name, ctor);
|
|
386
|
+
}
|
|
387
|
+
function getStrategyFromRegistry(family, name) {
|
|
388
|
+
const ctor = familyBucket(family)?.get(name);
|
|
389
|
+
if (!ctor) {
|
|
390
|
+
throw new Error(`No strategy registered for family "${family}" and name "${name}"`);
|
|
391
|
+
}
|
|
392
|
+
return new ctor();
|
|
393
|
+
}
|
|
394
|
+
function listStrategies(family) {
|
|
395
|
+
const bucket = familyBucket(family);
|
|
396
|
+
return bucket ? Array.from(bucket.keys()) : [];
|
|
397
|
+
}
|
|
398
|
+
function getStrategyRegistry() {
|
|
399
|
+
return strategyRegistry;
|
|
400
|
+
}
|
|
401
|
+
var StrategyRegistry = {
|
|
402
|
+
get: getStrategyFromRegistry,
|
|
403
|
+
list: listStrategies
|
|
404
|
+
};
|
|
405
|
+
function strategyClassStage3(backend, value, context, family, name) {
|
|
406
|
+
backend.metadata.set(MetadataKeys.STRATEGY, context.metadata, void 0, {
|
|
407
|
+
family,
|
|
408
|
+
name
|
|
409
|
+
});
|
|
410
|
+
registerStrategy(family, name, value);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// src/decorators/shared/transition.ts
|
|
414
|
+
function normalizeFromStates(from) {
|
|
415
|
+
return Array.isArray(from) ? from : [from];
|
|
416
|
+
}
|
|
417
|
+
function transitionMethodStage3(backend, value, context, options) {
|
|
418
|
+
backend.metadata.set(MetadataKeys.TRANSITION, context.metadata, context.name, options);
|
|
419
|
+
return value;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// src/decorators/shared/state.ts
|
|
423
|
+
var STATE_SYMBOL = /* @__PURE__ */ Symbol("lombok-ts:state");
|
|
424
|
+
function collectTransitionMethods(metadata, proto, classMetadata) {
|
|
425
|
+
const transitions = /* @__PURE__ */ new Map();
|
|
426
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
427
|
+
if (key === "constructor") continue;
|
|
428
|
+
const options = metadata.get(MetadataKeys.TRANSITION, proto, key) ?? (classMetadata ? metadata.get(MetadataKeys.TRANSITION, classMetadata, key) : void 0);
|
|
429
|
+
if (!options) continue;
|
|
430
|
+
const desc = Object.getOwnPropertyDescriptor(proto, key);
|
|
431
|
+
if (!desc || typeof desc.value !== "function") continue;
|
|
432
|
+
transitions.set(key, { options, original: desc.value });
|
|
433
|
+
}
|
|
434
|
+
return transitions;
|
|
435
|
+
}
|
|
436
|
+
function applyStateWrapping(backend, target, options, classMetadata) {
|
|
437
|
+
const { states, initial, onEnter, onExit, onTransition } = options;
|
|
438
|
+
if (!states.includes(initial)) {
|
|
439
|
+
throw new Error(`@State initial state "${initial}" is not in states: [${states.join(", ")}]`);
|
|
440
|
+
}
|
|
441
|
+
const transitions = collectTransitionMethods(
|
|
442
|
+
backend.metadata,
|
|
443
|
+
target.prototype,
|
|
444
|
+
classMetadata
|
|
445
|
+
);
|
|
446
|
+
const StateClass = class extends target {
|
|
447
|
+
constructor(...args) {
|
|
448
|
+
super(...args);
|
|
449
|
+
Object.defineProperty(this, STATE_SYMBOL, {
|
|
450
|
+
value: initial,
|
|
451
|
+
writable: true,
|
|
452
|
+
enumerable: false,
|
|
453
|
+
configurable: false
|
|
454
|
+
});
|
|
455
|
+
onEnter?.(initial);
|
|
456
|
+
}
|
|
457
|
+
get state() {
|
|
458
|
+
return this[STATE_SYMBOL] ?? initial;
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
const stateProto = StateClass.prototype;
|
|
462
|
+
for (const [methodName, { options: transition, original }] of transitions) {
|
|
463
|
+
const fromStates = normalizeFromStates(transition.from);
|
|
464
|
+
const toState = transition.to;
|
|
465
|
+
if (!states.includes(toState)) {
|
|
466
|
+
throw new Error(`@Transition on "${methodName}" targets unknown state "${toState}"`);
|
|
467
|
+
}
|
|
468
|
+
for (const from of fromStates) {
|
|
469
|
+
if (!states.includes(from)) {
|
|
470
|
+
throw new Error(`@Transition on "${methodName}" references unknown state "${from}"`);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
Object.defineProperty(stateProto, methodName, {
|
|
474
|
+
configurable: true,
|
|
475
|
+
enumerable: false,
|
|
476
|
+
writable: true,
|
|
477
|
+
value: function stateTransitionWrapper(...args) {
|
|
478
|
+
const self = this;
|
|
479
|
+
const current = self[STATE_SYMBOL] ?? "";
|
|
480
|
+
if (!fromStates.includes(current)) {
|
|
481
|
+
throw new Error(
|
|
482
|
+
`Cannot transition from "${current}" to "${toState}" via ${methodName}()`
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
onExit?.(current);
|
|
486
|
+
const result = original.apply(this, args);
|
|
487
|
+
self[STATE_SYMBOL] = toState;
|
|
488
|
+
onTransition?.(current, toState);
|
|
489
|
+
onEnter?.(toState);
|
|
490
|
+
return result;
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
return StateClass;
|
|
495
|
+
}
|
|
496
|
+
function stateClassStage3(backend, value, context, options) {
|
|
497
|
+
backend.metadata.set(MetadataKeys.STATE, context.metadata, void 0, options);
|
|
498
|
+
return applyStateWrapping(backend, value, options, context.metadata);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// src/decorators/shared/command.ts
|
|
502
|
+
function assertCommand(target) {
|
|
503
|
+
const proto = target.prototype;
|
|
504
|
+
if (typeof proto.execute !== "function") {
|
|
505
|
+
throw new Error(`@Command class ${target.name} must define execute()`);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function commandClassStage3(backend, value, context) {
|
|
509
|
+
assertCommand(value);
|
|
510
|
+
backend.metadata.set(MetadataKeys.COMMAND, context.metadata, void 0, true);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// src/decorators/shared/command-history.ts
|
|
514
|
+
var CommandHistory = class {
|
|
515
|
+
undoStack = [];
|
|
516
|
+
redoStack = [];
|
|
517
|
+
execute(cmd) {
|
|
518
|
+
const result = cmd.execute();
|
|
519
|
+
this.undoStack.push(cmd);
|
|
520
|
+
this.redoStack.length = 0;
|
|
521
|
+
return result;
|
|
522
|
+
}
|
|
523
|
+
undo() {
|
|
524
|
+
const cmd = this.undoStack.pop();
|
|
525
|
+
if (!cmd) {
|
|
526
|
+
throw new Error("Nothing to undo");
|
|
527
|
+
}
|
|
528
|
+
if (typeof cmd.undo !== "function") {
|
|
529
|
+
this.undoStack.push(cmd);
|
|
530
|
+
throw new Error("Command does not support undo()");
|
|
531
|
+
}
|
|
532
|
+
const result = cmd.undo();
|
|
533
|
+
this.redoStack.push(cmd);
|
|
534
|
+
return result;
|
|
535
|
+
}
|
|
536
|
+
redo() {
|
|
537
|
+
const cmd = this.redoStack.pop();
|
|
538
|
+
if (!cmd) {
|
|
539
|
+
throw new Error("Nothing to redo");
|
|
540
|
+
}
|
|
541
|
+
const result = cmd.execute();
|
|
542
|
+
this.undoStack.push(cmd);
|
|
543
|
+
return result;
|
|
544
|
+
}
|
|
545
|
+
get canUndo() {
|
|
546
|
+
return this.undoStack.length > 0;
|
|
547
|
+
}
|
|
548
|
+
get canRedo() {
|
|
549
|
+
return this.redoStack.length > 0;
|
|
550
|
+
}
|
|
551
|
+
clear() {
|
|
552
|
+
this.undoStack.length = 0;
|
|
553
|
+
this.redoStack.length = 0;
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
// src/decorators/shared/memento.ts
|
|
558
|
+
var MEMENTO_SNAPSHOT = /* @__PURE__ */ Symbol("lombok-ts:memento-snapshot");
|
|
559
|
+
var stage3MementoExcluded = /* @__PURE__ */ new WeakMap();
|
|
560
|
+
var legacyMementoExcluded = /* @__PURE__ */ new WeakMap();
|
|
561
|
+
function registerStage3MementoExclude(classMetadata, field) {
|
|
562
|
+
const set = stage3MementoExcluded.get(classMetadata) ?? /* @__PURE__ */ new Set();
|
|
563
|
+
set.add(field);
|
|
564
|
+
stage3MementoExcluded.set(classMetadata, set);
|
|
565
|
+
}
|
|
566
|
+
function isMementoSnapshot(value) {
|
|
567
|
+
return typeof value === "object" && value !== null && value[MEMENTO_SNAPSHOT] === true;
|
|
568
|
+
}
|
|
569
|
+
function collectExcludedFields(metadata, proto, classMetadata) {
|
|
570
|
+
const excluded = /* @__PURE__ */ new Set();
|
|
571
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
572
|
+
if (key === "constructor") continue;
|
|
573
|
+
if (metadata.has(MetadataKeys.MEMENTO_EXCLUDE, proto, key) || classMetadata && metadata.has(MetadataKeys.MEMENTO_EXCLUDE, classMetadata, key)) {
|
|
574
|
+
excluded.add(key);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
if (classMetadata) {
|
|
578
|
+
for (const key of stage3MementoExcluded.get(classMetadata) ?? []) {
|
|
579
|
+
excluded.add(key);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
for (const key of legacyMementoExcluded.get(proto) ?? []) {
|
|
583
|
+
excluded.add(key);
|
|
584
|
+
}
|
|
585
|
+
return excluded;
|
|
586
|
+
}
|
|
587
|
+
function snapshotInstance(instance, excluded) {
|
|
588
|
+
const data = {};
|
|
589
|
+
for (const key of Object.keys(instance)) {
|
|
590
|
+
if (excluded.has(key)) continue;
|
|
591
|
+
if (key === "save" || key === "restore") continue;
|
|
592
|
+
data[key] = deepClone(instance[key]);
|
|
593
|
+
}
|
|
594
|
+
return { [MEMENTO_SNAPSHOT]: true, data };
|
|
595
|
+
}
|
|
596
|
+
function applySnapshot(instance, snapshot) {
|
|
597
|
+
for (const [key, value] of Object.entries(snapshot.data)) {
|
|
598
|
+
instance[key] = deepClone(value);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
function wrapMementoClass(backend, target, classMetadata) {
|
|
602
|
+
const excluded = collectExcludedFields(
|
|
603
|
+
backend.metadata,
|
|
604
|
+
target.prototype,
|
|
605
|
+
classMetadata
|
|
606
|
+
);
|
|
607
|
+
const MementoClass = class extends target {
|
|
608
|
+
save() {
|
|
609
|
+
return snapshotInstance(this, excluded);
|
|
610
|
+
}
|
|
611
|
+
restore(snapshot) {
|
|
612
|
+
if (!isMementoSnapshot(snapshot)) {
|
|
613
|
+
throw new TypeError("restore() expects a snapshot returned from save()");
|
|
614
|
+
}
|
|
615
|
+
applySnapshot(this, snapshot);
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
return MementoClass;
|
|
619
|
+
}
|
|
620
|
+
function mementoClassStage3(backend, value, context) {
|
|
621
|
+
backend.metadata.set(MetadataKeys.MEMENTO, context.metadata, void 0, true);
|
|
622
|
+
return wrapMementoClass(backend, value, context.metadata);
|
|
623
|
+
}
|
|
624
|
+
function mementoExcludeFieldStage3(backend, context) {
|
|
625
|
+
backend.metadata.set(
|
|
626
|
+
MetadataKeys.MEMENTO_EXCLUDE,
|
|
627
|
+
context.metadata,
|
|
628
|
+
context.name,
|
|
629
|
+
true
|
|
630
|
+
);
|
|
631
|
+
registerStage3MementoExclude(context.metadata, String(context.name));
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// src/decorators/shared/observable.ts
|
|
635
|
+
var LISTENERS = /* @__PURE__ */ Symbol("lombok-ts:observable-listeners");
|
|
636
|
+
function findGetter(proto, key) {
|
|
637
|
+
let current = proto;
|
|
638
|
+
while (current) {
|
|
639
|
+
const desc = Object.getOwnPropertyDescriptor(current, key);
|
|
640
|
+
if (desc?.get) return desc.get;
|
|
641
|
+
current = Object.getPrototypeOf(current);
|
|
642
|
+
}
|
|
643
|
+
return void 0;
|
|
644
|
+
}
|
|
645
|
+
function getInternals(target) {
|
|
646
|
+
const bag = target;
|
|
647
|
+
if (!bag[LISTENERS]) {
|
|
648
|
+
bag[LISTENERS] = {
|
|
649
|
+
listeners: /* @__PURE__ */ new Map(),
|
|
650
|
+
wildcards: /* @__PURE__ */ new Set(),
|
|
651
|
+
derivedKeys: /* @__PURE__ */ new Set(),
|
|
652
|
+
derivedCache: /* @__PURE__ */ new Map()
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
return bag[LISTENERS];
|
|
656
|
+
}
|
|
657
|
+
function notify(internals, key, next, prev) {
|
|
658
|
+
const keyListeners = internals.listeners.get(key);
|
|
659
|
+
if (keyListeners) {
|
|
660
|
+
for (const listener of keyListeners) {
|
|
661
|
+
listener(next, prev);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
for (const listener of internals.wildcards) {
|
|
665
|
+
listener(key, next, prev);
|
|
666
|
+
}
|
|
667
|
+
if (internals.derivedKeys.size > 0) {
|
|
668
|
+
const instance = targetWithInternals(internals);
|
|
669
|
+
for (const derivedKey of internals.derivedKeys) {
|
|
670
|
+
const prevDerived = internals.derivedCache.get(derivedKey);
|
|
671
|
+
internals.derivedCache.delete(derivedKey);
|
|
672
|
+
const getter = findGetter(Object.getPrototypeOf(instance), derivedKey);
|
|
673
|
+
if (!getter) continue;
|
|
674
|
+
const newDerived = getter.call(instance);
|
|
675
|
+
internals.derivedCache.set(derivedKey, newDerived);
|
|
676
|
+
if (prevDerived !== newDerived) {
|
|
677
|
+
const derivedListeners = internals.listeners.get(derivedKey);
|
|
678
|
+
if (derivedListeners) {
|
|
679
|
+
for (const listener of derivedListeners) {
|
|
680
|
+
listener(newDerived, prevDerived);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
var INSTANCE = /* @__PURE__ */ Symbol("lombok-ts:observable-instance");
|
|
688
|
+
function targetWithInternals(internals) {
|
|
689
|
+
return internals[INSTANCE] ?? {};
|
|
690
|
+
}
|
|
691
|
+
function installSubscribe(proto) {
|
|
692
|
+
Object.defineProperty(proto, "subscribe", {
|
|
693
|
+
configurable: true,
|
|
694
|
+
enumerable: false,
|
|
695
|
+
writable: true,
|
|
696
|
+
value: function subscribe(key, listener) {
|
|
697
|
+
const internals = getInternals(this);
|
|
698
|
+
internals[INSTANCE] = this;
|
|
699
|
+
if (key === "*") {
|
|
700
|
+
const wildcardListener = listener;
|
|
701
|
+
internals.wildcards.add(wildcardListener);
|
|
702
|
+
return () => internals.wildcards.delete(wildcardListener);
|
|
703
|
+
}
|
|
704
|
+
const keyListener = listener;
|
|
705
|
+
let set = internals.listeners.get(key);
|
|
706
|
+
if (!set) {
|
|
707
|
+
set = /* @__PURE__ */ new Set();
|
|
708
|
+
internals.listeners.set(key, set);
|
|
709
|
+
}
|
|
710
|
+
set.add(keyListener);
|
|
711
|
+
const proto2 = Object.getPrototypeOf(this);
|
|
712
|
+
if (findGetter(proto2, key)) {
|
|
713
|
+
internals.derivedKeys.add(key);
|
|
714
|
+
}
|
|
715
|
+
return () => set.delete(keyListener);
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
function wrapObservableInstance(instance) {
|
|
720
|
+
const internals = getInternals(instance);
|
|
721
|
+
internals[INSTANCE] = instance;
|
|
722
|
+
return new Proxy(instance, {
|
|
723
|
+
set(target, prop, value, receiver) {
|
|
724
|
+
if (typeof prop === "symbol") {
|
|
725
|
+
return Reflect.set(target, prop, value, receiver);
|
|
726
|
+
}
|
|
727
|
+
const prev = Reflect.get(target, prop, receiver);
|
|
728
|
+
const result = Reflect.set(target, prop, value, receiver);
|
|
729
|
+
if (prev !== value) {
|
|
730
|
+
notify(internals, prop, value, prev);
|
|
731
|
+
}
|
|
732
|
+
return result;
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
function wrapObservableClass(target) {
|
|
737
|
+
installSubscribe(target.prototype);
|
|
738
|
+
const ObservableClass = class extends target {
|
|
739
|
+
constructor(...args) {
|
|
740
|
+
super(...args);
|
|
741
|
+
return wrapObservableInstance(this);
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
return ObservableClass;
|
|
745
|
+
}
|
|
746
|
+
function observableClassStage3(backend, value, context) {
|
|
747
|
+
backend.metadata.set(MetadataKeys.OBSERVABLE, context.metadata, void 0, true);
|
|
748
|
+
return wrapObservableClass(value);
|
|
749
|
+
}
|
|
750
|
+
function observableDerivedStage3(backend, value, context) {
|
|
751
|
+
backend.metadata.set(MetadataKeys.OBSERVABLE, context.metadata, context.name, {
|
|
752
|
+
derived: true
|
|
753
|
+
});
|
|
754
|
+
const key = context.name;
|
|
755
|
+
return function derivedGetter() {
|
|
756
|
+
const internals = getInternals(this);
|
|
757
|
+
internals[INSTANCE] = this;
|
|
758
|
+
internals.derivedKeys.add(key);
|
|
759
|
+
if (internals.derivedCache.has(key)) {
|
|
760
|
+
return internals.derivedCache.get(key);
|
|
761
|
+
}
|
|
762
|
+
const result = value.call(this);
|
|
763
|
+
internals.derivedCache.set(key, result);
|
|
764
|
+
return result;
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
function observerClassStage3(backend, value, context) {
|
|
768
|
+
return observableClassStage3(backend, value, context);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// src/decorators/shared/chain-of-responsibility.ts
|
|
772
|
+
function collectHandlers(backend, proto, classMetadata) {
|
|
773
|
+
const handlers = [];
|
|
774
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
775
|
+
if (key === "constructor") continue;
|
|
776
|
+
const options = backend.metadata.get(MetadataKeys.HANDLER, proto, key) ?? (classMetadata ? backend.metadata.get(MetadataKeys.HANDLER, classMetadata, key) : void 0);
|
|
777
|
+
if (!options) continue;
|
|
778
|
+
const desc = Object.getOwnPropertyDescriptor(proto, key);
|
|
779
|
+
if (!desc || typeof desc.value !== "function") continue;
|
|
780
|
+
handlers.push({
|
|
781
|
+
order: options.order,
|
|
782
|
+
method: key,
|
|
783
|
+
fn: desc.value
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
handlers.sort((a, b) => a.order - b.order);
|
|
787
|
+
return handlers;
|
|
788
|
+
}
|
|
789
|
+
function wrapChainClass(backend, target, classMetadata) {
|
|
790
|
+
const handlers = collectHandlers(backend, target.prototype, classMetadata);
|
|
791
|
+
const ChainClass = class extends target {
|
|
792
|
+
handle(context) {
|
|
793
|
+
for (const handler of handlers) {
|
|
794
|
+
const result = handler.fn.call(this, context);
|
|
795
|
+
if (result === true || result !== void 0 && result !== false) {
|
|
796
|
+
return true;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
return false;
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
return ChainClass;
|
|
803
|
+
}
|
|
804
|
+
function chainOfResponsibilityClassStage3(backend, value, context) {
|
|
805
|
+
backend.metadata.set(
|
|
806
|
+
MetadataKeys.CHAIN_OF_RESPONSIBILITY,
|
|
807
|
+
context.metadata,
|
|
808
|
+
void 0,
|
|
809
|
+
true
|
|
810
|
+
);
|
|
811
|
+
return wrapChainClass(backend, value, context.metadata);
|
|
812
|
+
}
|
|
813
|
+
function handlerMethodStage3(backend, value, context, options) {
|
|
814
|
+
backend.metadata.set(MetadataKeys.HANDLER, context.metadata, context.name, options);
|
|
815
|
+
return value;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// src/decorators/shared/iterable.ts
|
|
819
|
+
var ITERATE_FIELD = /* @__PURE__ */ Symbol("lombok-ts:iterate-over-field");
|
|
820
|
+
var legacyIterateFields = /* @__PURE__ */ new WeakMap();
|
|
821
|
+
var stage3IterateFields = /* @__PURE__ */ new WeakMap();
|
|
822
|
+
function registerStage3IterateField(classMetadata, field) {
|
|
823
|
+
const existing = stage3IterateFields.get(classMetadata) ?? [];
|
|
824
|
+
existing.push(field);
|
|
825
|
+
stage3IterateFields.set(classMetadata, existing);
|
|
826
|
+
}
|
|
827
|
+
function resolveIterateField(backend, proto, classMetadata) {
|
|
828
|
+
const fields = [];
|
|
829
|
+
for (const key of [
|
|
830
|
+
...Object.getOwnPropertyNames(proto),
|
|
831
|
+
...Object.getOwnPropertySymbols(proto)
|
|
832
|
+
]) {
|
|
833
|
+
if (key === "constructor") continue;
|
|
834
|
+
if (backend.metadata.has(MetadataKeys.ITERATE_OVER, proto, key) || classMetadata && backend.metadata.has(MetadataKeys.ITERATE_OVER, classMetadata, key)) {
|
|
835
|
+
fields.push(key);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
if (classMetadata) {
|
|
839
|
+
fields.push(...stage3IterateFields.get(classMetadata) ?? []);
|
|
840
|
+
}
|
|
841
|
+
fields.push(...legacyIterateFields.get(proto) ?? []);
|
|
842
|
+
if (fields.length === 0) {
|
|
843
|
+
throw new Error("@Iterable requires exactly one @IterateOver field");
|
|
844
|
+
}
|
|
845
|
+
if (fields.length > 1) {
|
|
846
|
+
throw new Error("@Iterable allows only one @IterateOver field");
|
|
847
|
+
}
|
|
848
|
+
return fields[0];
|
|
849
|
+
}
|
|
850
|
+
function installIterator(target, fieldKey) {
|
|
851
|
+
Object.defineProperty(target.prototype, Symbol.iterator, {
|
|
852
|
+
configurable: true,
|
|
853
|
+
enumerable: false,
|
|
854
|
+
writable: true,
|
|
855
|
+
value: function* iterateOver() {
|
|
856
|
+
const collection = this[fieldKey];
|
|
857
|
+
if (collection == null) return;
|
|
858
|
+
yield* collection;
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
function iterableClassStage3(backend, value, context) {
|
|
863
|
+
backend.metadata.set(MetadataKeys.ITERABLE, context.metadata, void 0, true);
|
|
864
|
+
const fieldKey = resolveIterateField(
|
|
865
|
+
backend,
|
|
866
|
+
value.prototype,
|
|
867
|
+
context.metadata
|
|
868
|
+
);
|
|
869
|
+
value[ITERATE_FIELD] = fieldKey;
|
|
870
|
+
installIterator(value, fieldKey);
|
|
871
|
+
}
|
|
872
|
+
function iterateOverFieldStage3(backend, context) {
|
|
873
|
+
backend.metadata.set(MetadataKeys.ITERATE_OVER, context.metadata, context.name, true);
|
|
874
|
+
registerStage3IterateField(context.metadata, context.name);
|
|
875
|
+
}
|
|
876
|
+
|
|
361
877
|
// src/decorators/stage3/index.ts
|
|
362
878
|
var NonNull = defineFieldDecorator(nonNullFieldStage3);
|
|
363
879
|
var Singleton = defineClassDecorator(singletonClassStage3);
|
|
@@ -433,12 +949,48 @@ function Delegate(...methods) {
|
|
|
433
949
|
);
|
|
434
950
|
}
|
|
435
951
|
var EqualsExclude = defineFieldDecorator(equalsExcludeFieldStage3);
|
|
952
|
+
function Strategy(family, name) {
|
|
953
|
+
return defineClassDecorator((backend, value, context) => {
|
|
954
|
+
strategyClassStage3(backend, value, context, family, name);
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
function State(options) {
|
|
958
|
+
return defineClassDecorator(
|
|
959
|
+
(backend, value, context) => stateClassStage3(backend, value, context, options)
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
function Transition(options) {
|
|
963
|
+
return defineMethodDecorator(
|
|
964
|
+
(backend, value, context) => transitionMethodStage3(backend, value, context, options)
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
var Command = defineClassDecorator(commandClassStage3);
|
|
968
|
+
var observableClassDec = defineClassDecorator(observableClassStage3);
|
|
969
|
+
var observableDerivedDec = defineGetterDecorator(observableDerivedStage3);
|
|
970
|
+
function Observable() {
|
|
971
|
+
return observableClassDec;
|
|
972
|
+
}
|
|
973
|
+
Observable.Derived = observableDerivedDec;
|
|
974
|
+
var Observer = defineClassDecorator(observerClassStage3);
|
|
975
|
+
var mementoClassDec = defineClassDecorator(mementoClassStage3);
|
|
976
|
+
function Memento() {
|
|
977
|
+
return mementoClassDec;
|
|
978
|
+
}
|
|
979
|
+
Memento.Exclude = defineFieldDecorator(mementoExcludeFieldStage3);
|
|
980
|
+
var ChainOfResponsibility = defineClassDecorator(chainOfResponsibilityClassStage3);
|
|
981
|
+
function Handler(options) {
|
|
982
|
+
return defineMethodDecorator(
|
|
983
|
+
(backend, value, context) => handlerMethodStage3(backend, value, context, options)
|
|
984
|
+
);
|
|
985
|
+
}
|
|
986
|
+
var Iterable = defineClassDecorator(iterableClassStage3);
|
|
987
|
+
var IterateOver = defineFieldDecorator(iterateOverFieldStage3);
|
|
436
988
|
|
|
437
989
|
// src/stage3/index.ts
|
|
438
990
|
function getClassMetadata(cls) {
|
|
439
991
|
return cls[Symbol.metadata];
|
|
440
992
|
}
|
|
441
993
|
|
|
442
|
-
export { Accessors, Builder, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Getter, Log, Memoize, NonNull, Prototype, Setter, Singleton, Stage3Backend, ToString, UtilityClass, Value, With, createFromFactory, defineClassDecorator, defineFieldDecorator, defineGetterDecorator, defineMethodDecorator, defineSetterDecorator, getClassMetadata, getFactoryRegistry, registerFactory, stage3Backend };
|
|
994
|
+
export { Accessors, Builder, ChainOfResponsibility, Command, CommandHistory, Data, Delegate, Equals, EqualsExclude, Factory, FieldDefaults, Getter, Handler, Iterable, IterateOver, Log, Memento, Memoize, NonNull, Observable, Observer, Prototype, Setter, Singleton, Stage3Backend, State, Strategy, StrategyRegistry, ToString, Transition, UtilityClass, Value, With, createFromFactory, defineClassDecorator, defineFieldDecorator, defineGetterDecorator, defineMethodDecorator, defineSetterDecorator, getClassMetadata, getFactoryRegistry, getStrategyFromRegistry, getStrategyRegistry, listStrategies, registerFactory, registerStrategy, stage3Backend };
|
|
443
995
|
//# sourceMappingURL=index.js.map
|
|
444
996
|
//# sourceMappingURL=index.js.map
|