|
| 1 | +//// [registryMonoidalPatternNoOOM.ts] |
| 2 | +interface Plugins<TConfig> {} |
| 3 | + |
| 4 | +type PluginNames = keyof Plugins<any>; |
| 5 | + |
| 6 | +interface MiddlewarePlugin<TKind extends PluginNames, TPreviousConfig> { |
| 7 | + readonly _group: TKind; |
| 8 | + configure<TConfig>(cb: (conf: TPreviousConfig) => TConfig): Plugins<TConfig>[TKind]; |
| 9 | + // combine<TConfig>(cb: Plugins<(conf: TPreviousConfig) => TConfig>[TKind]): Plugins<TConfig>[TKind]; |
| 10 | + // The above "works", but the below _should_ result in less to check and is simpler (and is needed to trigger the OOM bug) |
| 11 | + combine<TConfig>(cb: MiddlewarePlugin<TKind, (conf: TPreviousConfig) => TConfig>): Plugins<TConfig>[TKind]; |
| 12 | +} |
| 13 | + |
| 14 | +const GroupOneName = "GroupOne"; |
| 15 | +type GroupOneName = typeof GroupOneName; |
| 16 | +type GroupOne<T> = PluginA<T> | PluginB<T>; |
| 17 | +interface Plugins<TConfig> { |
| 18 | + [GroupOneName]: GroupOne<TConfig>; |
| 19 | +} |
| 20 | +class PluginA<TConf> implements MiddlewarePlugin<GroupOneName, TConf> { |
| 21 | + readonly _kind = "PluginA"; |
| 22 | + readonly _group = GroupOneName; |
| 23 | + constructor(public value: TConf) {} |
| 24 | + configure<T>(cb: (conf: TConf) => T): GroupOne<T> { |
| 25 | + return new PluginA(cb(this.value)); |
| 26 | + } |
| 27 | + combine<T>(plug: GroupOne<(conf: TConf) => T>): GroupOne<T> { |
| 28 | + return plug.configure(f => f(this.value)); |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +class PluginB<TConf> implements MiddlewarePlugin<GroupOneName, TConf> { |
| 33 | + readonly _kind = "PluginB"; |
| 34 | + readonly _group = GroupOneName; |
| 35 | + constructor(public value: TConf) {} |
| 36 | + configure<T>(cb: (conf: TConf) => T): GroupOne<T> { |
| 37 | + return new PluginB(cb(this.value)); |
| 38 | + } |
| 39 | + combine<T>(plug: GroupOne<(conf: TConf) => T>): GroupOne<T> { |
| 40 | + return plug.configure(f => f(this.value)); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +// One plugin group isn't quite enough to run OOM - we need a few more |
| 45 | + |
| 46 | +const GroupTwoName = "GroupTwo"; |
| 47 | +type GroupTwoName = typeof GroupTwoName; |
| 48 | +type GroupTwo<T> = PluginC<T> | PluginD<T>; |
| 49 | +interface Plugins<TConfig> { |
| 50 | + [GroupTwoName]: GroupTwo<TConfig>; |
| 51 | +} |
| 52 | +class PluginC<TConf> implements MiddlewarePlugin<GroupTwoName, TConf> { |
| 53 | + readonly _kind = "PluginC"; |
| 54 | + readonly _group = GroupTwoName; |
| 55 | + constructor(public value: TConf) {} |
| 56 | + configure<T>(cb: (conf: TConf) => T): GroupTwo<T> { |
| 57 | + return new PluginC(cb(this.value)); |
| 58 | + } |
| 59 | + combine<T>(plug: GroupTwo<(conf: TConf) => T>): GroupTwo<T> { |
| 60 | + return plug.configure(f => f(this.value)); |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +class PluginD<TConf> implements MiddlewarePlugin<GroupTwoName, TConf> { |
| 65 | + readonly _kind = "PluginD"; |
| 66 | + readonly _group = GroupTwoName; |
| 67 | + constructor(public value: TConf) {} |
| 68 | + configure<T>(cb: (conf: TConf) => T): GroupTwo<T> { |
| 69 | + return new PluginD(cb(this.value)); |
| 70 | + } |
| 71 | + combine<T>(plug: GroupTwo<(conf: TConf) => T>): GroupTwo<T> { |
| 72 | + return plug.configure(f => f(this.value)); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +const GroupThreeName = "GroupThree"; |
| 77 | +type GroupThreeName = typeof GroupThreeName; |
| 78 | +type GroupThree<T> = PluginE<T> | PluginF<T>; |
| 79 | +interface Plugins<TConfig> { |
| 80 | + [GroupThreeName]: GroupThree<TConfig>; |
| 81 | +} |
| 82 | +class PluginE<TConf> implements MiddlewarePlugin<GroupThreeName, TConf> { |
| 83 | + readonly _kind = "PluginC"; |
| 84 | + readonly _group = GroupThreeName; |
| 85 | + constructor(public value: TConf) {} |
| 86 | + configure<T>(cb: (conf: TConf) => T): GroupThree<T> { |
| 87 | + return new PluginE(cb(this.value)); |
| 88 | + } |
| 89 | + combine<T>(plug: GroupThree<(conf: TConf) => T>): GroupThree<T> { |
| 90 | + return plug.configure(f => f(this.value)); |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +class PluginF<TConf> implements MiddlewarePlugin<GroupThreeName, TConf> { |
| 95 | + readonly _kind = "PluginD"; |
| 96 | + readonly _group = GroupThreeName; |
| 97 | + constructor(public value: TConf) {} |
| 98 | + configure<T>(cb: (conf: TConf) => T): GroupThree<T> { |
| 99 | + return new PluginF(cb(this.value)); |
| 100 | + } |
| 101 | + combine<T>(plug: GroupThree<(conf: TConf) => T>): GroupThree<T> { |
| 102 | + return plug.configure(f => f(this.value)); |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | + |
| 107 | +//// [registryMonoidalPatternNoOOM.js] |
| 108 | +var GroupOneName = "GroupOne"; |
| 109 | +var PluginA = /** @class */ (function () { |
| 110 | + function PluginA(value) { |
| 111 | + this.value = value; |
| 112 | + this._kind = "PluginA"; |
| 113 | + this._group = GroupOneName; |
| 114 | + } |
| 115 | + PluginA.prototype.configure = function (cb) { |
| 116 | + return new PluginA(cb(this.value)); |
| 117 | + }; |
| 118 | + PluginA.prototype.combine = function (plug) { |
| 119 | + var _this = this; |
| 120 | + return plug.configure(function (f) { return f(_this.value); }); |
| 121 | + }; |
| 122 | + return PluginA; |
| 123 | +}()); |
| 124 | +var PluginB = /** @class */ (function () { |
| 125 | + function PluginB(value) { |
| 126 | + this.value = value; |
| 127 | + this._kind = "PluginB"; |
| 128 | + this._group = GroupOneName; |
| 129 | + } |
| 130 | + PluginB.prototype.configure = function (cb) { |
| 131 | + return new PluginB(cb(this.value)); |
| 132 | + }; |
| 133 | + PluginB.prototype.combine = function (plug) { |
| 134 | + var _this = this; |
| 135 | + return plug.configure(function (f) { return f(_this.value); }); |
| 136 | + }; |
| 137 | + return PluginB; |
| 138 | +}()); |
| 139 | +// One plugin group isn't quite enough to run OOM - we need a few more |
| 140 | +var GroupTwoName = "GroupTwo"; |
| 141 | +var PluginC = /** @class */ (function () { |
| 142 | + function PluginC(value) { |
| 143 | + this.value = value; |
| 144 | + this._kind = "PluginC"; |
| 145 | + this._group = GroupTwoName; |
| 146 | + } |
| 147 | + PluginC.prototype.configure = function (cb) { |
| 148 | + return new PluginC(cb(this.value)); |
| 149 | + }; |
| 150 | + PluginC.prototype.combine = function (plug) { |
| 151 | + var _this = this; |
| 152 | + return plug.configure(function (f) { return f(_this.value); }); |
| 153 | + }; |
| 154 | + return PluginC; |
| 155 | +}()); |
| 156 | +var PluginD = /** @class */ (function () { |
| 157 | + function PluginD(value) { |
| 158 | + this.value = value; |
| 159 | + this._kind = "PluginD"; |
| 160 | + this._group = GroupTwoName; |
| 161 | + } |
| 162 | + PluginD.prototype.configure = function (cb) { |
| 163 | + return new PluginD(cb(this.value)); |
| 164 | + }; |
| 165 | + PluginD.prototype.combine = function (plug) { |
| 166 | + var _this = this; |
| 167 | + return plug.configure(function (f) { return f(_this.value); }); |
| 168 | + }; |
| 169 | + return PluginD; |
| 170 | +}()); |
| 171 | +var GroupThreeName = "GroupThree"; |
| 172 | +var PluginE = /** @class */ (function () { |
| 173 | + function PluginE(value) { |
| 174 | + this.value = value; |
| 175 | + this._kind = "PluginC"; |
| 176 | + this._group = GroupThreeName; |
| 177 | + } |
| 178 | + PluginE.prototype.configure = function (cb) { |
| 179 | + return new PluginE(cb(this.value)); |
| 180 | + }; |
| 181 | + PluginE.prototype.combine = function (plug) { |
| 182 | + var _this = this; |
| 183 | + return plug.configure(function (f) { return f(_this.value); }); |
| 184 | + }; |
| 185 | + return PluginE; |
| 186 | +}()); |
| 187 | +var PluginF = /** @class */ (function () { |
| 188 | + function PluginF(value) { |
| 189 | + this.value = value; |
| 190 | + this._kind = "PluginD"; |
| 191 | + this._group = GroupThreeName; |
| 192 | + } |
| 193 | + PluginF.prototype.configure = function (cb) { |
| 194 | + return new PluginF(cb(this.value)); |
| 195 | + }; |
| 196 | + PluginF.prototype.combine = function (plug) { |
| 197 | + var _this = this; |
| 198 | + return plug.configure(function (f) { return f(_this.value); }); |
| 199 | + }; |
| 200 | + return PluginF; |
| 201 | +}()); |
0 commit comments