patron-oop 1.1.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/CHANGELOG.md +11 -0
- package/LICENSE.md +7 -0
- package/README.md +9 -0
- package/commitizen.cjs +50 -0
- package/dist/patron.d.ts +173 -0
- package/dist/patron.js +363 -0
- package/dist/patron.js.map +1 -0
- package/dist/patron.mjs +346 -0
- package/dist/patron.mjs.map +1 -0
- package/eslint.config.mjs +36 -0
- package/package.json +48 -0
- package/rollup.config.js +35 -0
- package/src/Cache.test.ts +20 -0
- package/src/Cache.ts +31 -0
- package/src/CacheType.ts +4 -0
- package/src/Chain.test.ts +72 -0
- package/src/Chain.ts +79 -0
- package/src/ChainType.ts +7 -0
- package/src/Factory.test.ts +16 -0
- package/src/Factory.ts +21 -0
- package/src/FactoryDynamic.ts +11 -0
- package/src/FactoryType.ts +3 -0
- package/src/FactoryWithFactories.ts +25 -0
- package/src/Guest.test.ts +13 -0
- package/src/Guest.ts +11 -0
- package/src/GuestAware.ts +11 -0
- package/src/GuestAwareType.ts +5 -0
- package/src/GuestCast.ts +20 -0
- package/src/GuestExecutorType.ts +3 -0
- package/src/GuestInTheMiddle.test.ts +71 -0
- package/src/GuestInTheMiddle.ts +20 -0
- package/src/GuestPool.test.ts +41 -0
- package/src/GuestPool.ts +46 -0
- package/src/GuestSync.test.ts +11 -0
- package/src/GuestSync.ts +14 -0
- package/src/GuestType.ts +10 -0
- package/src/GuestValueType.ts +5 -0
- package/src/Patron.test.ts +20 -0
- package/src/Patron.ts +17 -0
- package/src/PatronOnce.test.ts +18 -0
- package/src/PatronOnce.ts +30 -0
- package/src/PatronPool.test.ts +26 -0
- package/src/PatronPool.ts +76 -0
- package/src/PoolType.ts +7 -0
- package/src/Source.test.ts +13 -0
- package/src/Source.ts +20 -0
- package/src/SourceType.ts +4 -0
- package/src/index.ts +16 -0
- package/tsconfig.json +26 -0
package/dist/patron.mjs
ADDED
@@ -0,0 +1,346 @@
|
|
1
|
+
var __defProp$5 = Object.defineProperty;
|
2
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
3
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4
|
+
const poolSets = /* @__PURE__ */ new Map();
|
5
|
+
const removePatronFromPools = (patron) => {
|
6
|
+
poolSets.forEach((pool) => {
|
7
|
+
pool.delete(patron);
|
8
|
+
});
|
9
|
+
};
|
10
|
+
class PatronPool {
|
11
|
+
constructor(initiator) {
|
12
|
+
this.initiator = initiator;
|
13
|
+
__publicField$5(this, "patrons", /* @__PURE__ */ new Set());
|
14
|
+
__publicField$5(this, "receive");
|
15
|
+
poolSets.set(this, this.patrons);
|
16
|
+
let lastMicrotask = null;
|
17
|
+
const doReceive = (value, options) => {
|
18
|
+
this.patrons.forEach((target) => {
|
19
|
+
this.sendValueToGuest(value, target, options);
|
20
|
+
});
|
21
|
+
};
|
22
|
+
this.receive = (value, options) => {
|
23
|
+
const currentMicroTask = () => {
|
24
|
+
if (currentMicroTask === lastMicrotask) {
|
25
|
+
doReceive(value, options);
|
26
|
+
}
|
27
|
+
};
|
28
|
+
lastMicrotask = currentMicroTask;
|
29
|
+
queueMicrotask(currentMicroTask);
|
30
|
+
return this;
|
31
|
+
};
|
32
|
+
}
|
33
|
+
add(shouldBePatron) {
|
34
|
+
if (shouldBePatron.introduction && shouldBePatron.introduction() === "patron") {
|
35
|
+
this.patrons.add(shouldBePatron);
|
36
|
+
}
|
37
|
+
return this;
|
38
|
+
}
|
39
|
+
remove(patron) {
|
40
|
+
this.patrons.delete(patron);
|
41
|
+
return this;
|
42
|
+
}
|
43
|
+
distribute(receiving, possiblePatron) {
|
44
|
+
this.add(possiblePatron);
|
45
|
+
this.sendValueToGuest(receiving, possiblePatron, {});
|
46
|
+
return this;
|
47
|
+
}
|
48
|
+
sendValueToGuest(value, guest, options) {
|
49
|
+
guest.receive(value, {
|
50
|
+
...options,
|
51
|
+
data: {
|
52
|
+
...options?.data ?? {},
|
53
|
+
initiator: this.initiator,
|
54
|
+
pool: this
|
55
|
+
}
|
56
|
+
});
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
var __defProp$4 = Object.defineProperty;
|
61
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
62
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, key + "" , value);
|
63
|
+
class Cache {
|
64
|
+
constructor(initiator, defaultValue = null, theCache = null) {
|
65
|
+
this.defaultValue = defaultValue;
|
66
|
+
this.theCache = theCache;
|
67
|
+
__publicField$4(this, "pool");
|
68
|
+
this.pool = new PatronPool(initiator);
|
69
|
+
}
|
70
|
+
receive(value, options) {
|
71
|
+
this.theCache = value;
|
72
|
+
this.pool.receive(value, options);
|
73
|
+
return this;
|
74
|
+
}
|
75
|
+
receiving(guest) {
|
76
|
+
if (this.theCache !== null) {
|
77
|
+
guest.receive(this.theCache);
|
78
|
+
} else if (this.defaultValue !== null) {
|
79
|
+
guest.receive(this.defaultValue);
|
80
|
+
}
|
81
|
+
this.pool.add(guest);
|
82
|
+
return this;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
class Guest {
|
87
|
+
constructor(receiver) {
|
88
|
+
this.receiver = receiver;
|
89
|
+
}
|
90
|
+
receive(value, options) {
|
91
|
+
this.receiver(value, options);
|
92
|
+
return this;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
var __defProp$3 = Object.defineProperty;
|
97
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
98
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
99
|
+
class GuestPool {
|
100
|
+
constructor(initiator) {
|
101
|
+
__publicField$3(this, "guests", /* @__PURE__ */ new Set());
|
102
|
+
__publicField$3(this, "patronPool");
|
103
|
+
this.patronPool = new PatronPool(initiator);
|
104
|
+
}
|
105
|
+
receive(value, options) {
|
106
|
+
this.deliverToGuests(value, options);
|
107
|
+
this.patronPool.receive(value, options);
|
108
|
+
return this;
|
109
|
+
}
|
110
|
+
add(guest) {
|
111
|
+
if (!guest.introduction || guest.introduction() === "guest") {
|
112
|
+
this.guests.add(guest);
|
113
|
+
}
|
114
|
+
this.patronPool.add(guest);
|
115
|
+
return this;
|
116
|
+
}
|
117
|
+
remove(patron) {
|
118
|
+
this.guests.delete(patron);
|
119
|
+
this.patronPool.remove(patron);
|
120
|
+
return this;
|
121
|
+
}
|
122
|
+
distribute(receiving, possiblePatron) {
|
123
|
+
this.add(possiblePatron);
|
124
|
+
this.receive(receiving);
|
125
|
+
return this;
|
126
|
+
}
|
127
|
+
deliverToGuests(value, options) {
|
128
|
+
this.guests.forEach((target) => {
|
129
|
+
target.receive(value, options);
|
130
|
+
});
|
131
|
+
this.guests.clear();
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
class GuestInTheMiddle {
|
136
|
+
constructor(baseGuest, middleFn) {
|
137
|
+
this.baseGuest = baseGuest;
|
138
|
+
this.middleFn = middleFn;
|
139
|
+
}
|
140
|
+
introduction() {
|
141
|
+
if (!this.baseGuest.introduction) {
|
142
|
+
return "guest";
|
143
|
+
}
|
144
|
+
return this.baseGuest.introduction();
|
145
|
+
}
|
146
|
+
receive(value, options) {
|
147
|
+
this.middleFn(value, options);
|
148
|
+
return this;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
var __defProp$2 = Object.defineProperty;
|
153
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
154
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
155
|
+
class Chain {
|
156
|
+
constructor() {
|
157
|
+
__publicField$2(this, "theChain");
|
158
|
+
__publicField$2(this, "keysKnown", /* @__PURE__ */ new Set());
|
159
|
+
__publicField$2(this, "keysFilled", /* @__PURE__ */ new Set());
|
160
|
+
__publicField$2(this, "filledChainPool", new GuestPool(this));
|
161
|
+
this.theChain = new Cache(this, {});
|
162
|
+
}
|
163
|
+
resultArray(guest) {
|
164
|
+
this.filledChainPool.add(
|
165
|
+
new GuestInTheMiddle(
|
166
|
+
guest,
|
167
|
+
(value) => Object.values(value)
|
168
|
+
)
|
169
|
+
);
|
170
|
+
if (this.isChainFilled()) {
|
171
|
+
this.theChain.receiving(
|
172
|
+
new Guest((chain) => {
|
173
|
+
this.filledChainPool.receive(Object.values(chain));
|
174
|
+
})
|
175
|
+
);
|
176
|
+
}
|
177
|
+
return this;
|
178
|
+
}
|
179
|
+
result(guest) {
|
180
|
+
if (this.isChainFilled()) {
|
181
|
+
this.filledChainPool.add(guest);
|
182
|
+
this.theChain.receiving(
|
183
|
+
new Guest((chain) => {
|
184
|
+
this.filledChainPool.receive(chain);
|
185
|
+
})
|
186
|
+
);
|
187
|
+
} else {
|
188
|
+
this.filledChainPool.add(guest);
|
189
|
+
}
|
190
|
+
return this;
|
191
|
+
}
|
192
|
+
receiveKey(key) {
|
193
|
+
this.keysKnown.add(key);
|
194
|
+
return new Guest((value) => {
|
195
|
+
queueMicrotask(() => {
|
196
|
+
this.theChain.receiving(
|
197
|
+
new Guest((chain) => {
|
198
|
+
this.keysFilled.add(key);
|
199
|
+
const lastChain = {
|
200
|
+
...chain,
|
201
|
+
[key]: value
|
202
|
+
};
|
203
|
+
this.theChain.receive(lastChain);
|
204
|
+
if (this.isChainFilled()) {
|
205
|
+
this.filledChainPool.receive(lastChain);
|
206
|
+
}
|
207
|
+
})
|
208
|
+
);
|
209
|
+
});
|
210
|
+
});
|
211
|
+
}
|
212
|
+
isChainFilled() {
|
213
|
+
return this.keysFilled.size > 0 && this.keysFilled.size === this.keysKnown.size;
|
214
|
+
}
|
215
|
+
}
|
216
|
+
|
217
|
+
class Factory {
|
218
|
+
constructor(constructorFn) {
|
219
|
+
this.constructorFn = constructorFn;
|
220
|
+
}
|
221
|
+
create(...args) {
|
222
|
+
return new this.constructorFn(
|
223
|
+
...args
|
224
|
+
);
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
228
|
+
class FactoryDynamic {
|
229
|
+
constructor(creationFn) {
|
230
|
+
this.creationFn = creationFn;
|
231
|
+
}
|
232
|
+
create(...args) {
|
233
|
+
return this.creationFn(...args);
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
class FactoryWithFactories {
|
238
|
+
constructor(constructorFn, factories = {}) {
|
239
|
+
this.constructorFn = constructorFn;
|
240
|
+
this.factories = factories;
|
241
|
+
}
|
242
|
+
create(...args) {
|
243
|
+
return new this.constructorFn(
|
244
|
+
...args,
|
245
|
+
this.factories
|
246
|
+
);
|
247
|
+
}
|
248
|
+
}
|
249
|
+
|
250
|
+
class GuestAware {
|
251
|
+
constructor(guestReceiver) {
|
252
|
+
this.guestReceiver = guestReceiver;
|
253
|
+
}
|
254
|
+
receiving(guest) {
|
255
|
+
this.guestReceiver(guest);
|
256
|
+
return guest;
|
257
|
+
}
|
258
|
+
}
|
259
|
+
|
260
|
+
class GuestCast {
|
261
|
+
constructor(sourceGuest, targetGuest) {
|
262
|
+
this.sourceGuest = sourceGuest;
|
263
|
+
this.targetGuest = targetGuest;
|
264
|
+
}
|
265
|
+
introduction() {
|
266
|
+
if (!this.sourceGuest.introduction) {
|
267
|
+
return "guest";
|
268
|
+
}
|
269
|
+
return this.sourceGuest.introduction();
|
270
|
+
}
|
271
|
+
receive(value, options) {
|
272
|
+
this.targetGuest.receive(value, options);
|
273
|
+
return this;
|
274
|
+
}
|
275
|
+
}
|
276
|
+
|
277
|
+
class GuestSync {
|
278
|
+
constructor(theValue) {
|
279
|
+
this.theValue = theValue;
|
280
|
+
}
|
281
|
+
receive(value) {
|
282
|
+
this.theValue = value;
|
283
|
+
return this;
|
284
|
+
}
|
285
|
+
value() {
|
286
|
+
return this.theValue;
|
287
|
+
}
|
288
|
+
}
|
289
|
+
|
290
|
+
class Patron {
|
291
|
+
constructor(willBePatron) {
|
292
|
+
this.willBePatron = willBePatron;
|
293
|
+
}
|
294
|
+
introduction() {
|
295
|
+
return "patron";
|
296
|
+
}
|
297
|
+
receive(value, options) {
|
298
|
+
this.willBePatron.receive(value, options);
|
299
|
+
return this;
|
300
|
+
}
|
301
|
+
}
|
302
|
+
|
303
|
+
var __defProp$1 = Object.defineProperty;
|
304
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
305
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, key + "" , value);
|
306
|
+
class PatronOnce {
|
307
|
+
constructor(baseGuest) {
|
308
|
+
this.baseGuest = baseGuest;
|
309
|
+
__publicField$1(this, "received", false);
|
310
|
+
}
|
311
|
+
introduction() {
|
312
|
+
return "patron";
|
313
|
+
}
|
314
|
+
receive(value, options) {
|
315
|
+
if (!this.received) {
|
316
|
+
this.baseGuest.receive(value, options);
|
317
|
+
}
|
318
|
+
const data = options?.data;
|
319
|
+
if (data?.pool) {
|
320
|
+
data.pool.remove(this);
|
321
|
+
}
|
322
|
+
return this;
|
323
|
+
}
|
324
|
+
}
|
325
|
+
|
326
|
+
var __defProp = Object.defineProperty;
|
327
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
328
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
329
|
+
class Source {
|
330
|
+
constructor(sourceDocument) {
|
331
|
+
this.sourceDocument = sourceDocument;
|
332
|
+
__publicField(this, "pool", new PatronPool(this));
|
333
|
+
}
|
334
|
+
receive(value) {
|
335
|
+
this.sourceDocument = value;
|
336
|
+
this.pool.receive(this.sourceDocument);
|
337
|
+
return this;
|
338
|
+
}
|
339
|
+
receiving(guest) {
|
340
|
+
this.pool.distribute(this.sourceDocument, guest);
|
341
|
+
return this;
|
342
|
+
}
|
343
|
+
}
|
344
|
+
|
345
|
+
export { Cache, Chain, Factory, FactoryDynamic, FactoryWithFactories, Guest, GuestAware, GuestCast, GuestInTheMiddle, GuestPool, GuestSync, Patron, PatronOnce, PatronPool, Source, removePatronFromPools };
|
346
|
+
//# sourceMappingURL=patron.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"patron.mjs","sources":["../src/PatronPool.ts","../src/Cache.ts","../src/Guest.ts","../src/GuestPool.ts","../src/GuestInTheMiddle.ts","../src/Chain.ts","../src/Factory.ts","../src/FactoryDynamic.ts","../src/FactoryWithFactories.ts","../src/GuestAware.ts","../src/GuestCast.ts","../src/GuestSync.ts","../src/Patron.ts","../src/PatronOnce.ts","../src/Source.ts"],"sourcesContent":["import { PoolType } from \"./PoolType\";\nimport { GuestType, ReceiveOptions } from \"./GuestType\";\n\nconst poolSets = new Map<PoolType, Set<GuestType>>();\n\n/**\n * Удалить патрон из всех пулов\n */\nexport const removePatronFromPools = (patron: GuestType) => {\n poolSets.forEach((pool) => {\n pool.delete(patron);\n });\n};\n\nexport class PatronPool<T> implements PoolType<T> {\n private patrons = new Set<GuestType<T>>();\n\n public receive: (value: T, options?: ReceiveOptions) => this;\n\n public constructor(private initiator: unknown) {\n poolSets.set(this, this.patrons);\n\n let lastMicrotask: (() => void) | null = null;\n const doReceive = (value: T, options?: ReceiveOptions) => {\n this.patrons.forEach((target) => {\n this.sendValueToGuest(value, target, options);\n });\n };\n this.receive = (value: T, options?: ReceiveOptions) => {\n const currentMicroTask = () => {\n if (currentMicroTask === lastMicrotask) {\n doReceive(value, options);\n }\n };\n lastMicrotask = currentMicroTask;\n queueMicrotask(currentMicroTask);\n return this;\n };\n }\n\n public add(shouldBePatron: GuestType<T>) {\n if (\n shouldBePatron.introduction &&\n shouldBePatron.introduction() === \"patron\"\n ) {\n this.patrons.add(shouldBePatron);\n }\n return this;\n }\n\n public remove(patron: GuestType<T>) {\n this.patrons.delete(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.sendValueToGuest(receiving, possiblePatron, {});\n return this;\n }\n\n private sendValueToGuest(\n value: T,\n guest: GuestType<T>,\n options?: ReceiveOptions,\n ) {\n guest.receive(value, {\n ...options,\n data: {\n ...((options?.data as Record<string, unknown>) ?? {}),\n initiator: this.initiator,\n pool: this,\n },\n });\n }\n}\n","import { PatronPool } from \"./PatronPool\";\nimport { CacheType } from \"./CacheType\";\nimport { GuestType, ReceiveOptions } from \"./GuestType\";\n\nexport class Cache<T> implements CacheType<T> {\n private pool: PatronPool<T>;\n\n public constructor(\n initiator: unknown,\n private defaultValue: T | null = null,\n private theCache: T | null = null,\n ) {\n this.pool = new PatronPool<T>(initiator);\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n this.theCache = value;\n this.pool.receive(value, options);\n return this;\n }\n\n public receiving(guest: GuestType<T>): this {\n if (this.theCache !== null) {\n guest.receive(this.theCache);\n } else if (this.defaultValue !== null) {\n guest.receive(this.defaultValue);\n }\n this.pool.add(guest);\n return this;\n }\n}\n","import { GuestExecutorType } from \"./GuestExecutorType\";\nimport { GuestType, ReceiveOptions } from \"./GuestType\";\n\nexport class Guest<T> implements GuestType<T> {\n public constructor(private receiver: GuestExecutorType<T>) {}\n\n public receive(value: T, options?: ReceiveOptions) {\n this.receiver(value, options);\n return this;\n }\n}\n","import { PatronPool } from \"./PatronPool\";\nimport { PoolType } from \"./PoolType\";\nimport { GuestType, ReceiveOptions } from \"./GuestType\";\n\nexport class GuestPool<T> implements GuestType<T>, PoolType<T> {\n private guests = new Set<GuestType<T>>();\n\n private patronPool: PatronPool<T>;\n\n public constructor(initiator: unknown) {\n this.patronPool = new PatronPool(initiator);\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n this.deliverToGuests(value, options);\n this.patronPool.receive(value, options);\n return this;\n }\n\n public add(guest: GuestType<T>): this {\n if (!guest.introduction || guest.introduction() === \"guest\") {\n this.guests.add(guest);\n }\n this.patronPool.add(guest);\n return this;\n }\n\n public remove(patron: GuestType<T>): this {\n this.guests.delete(patron);\n this.patronPool.remove(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.receive(receiving);\n return this;\n }\n\n private deliverToGuests(value: T, options?: ReceiveOptions) {\n this.guests.forEach((target) => {\n target.receive(value, options);\n });\n this.guests.clear();\n }\n}\n","import { GuestType, ReceiveOptions } from \"./GuestType\";\n\nexport class GuestInTheMiddle<T> implements GuestType<T> {\n public constructor(\n private baseGuest: GuestType<unknown>,\n private middleFn: (value: T, options?: ReceiveOptions) => void,\n ) {}\n\n introduction() {\n if (!this.baseGuest.introduction) {\n return \"guest\";\n }\n return this.baseGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n this.middleFn(value, options);\n return this;\n }\n}\n","import { Cache } from \"./Cache\";\nimport { Guest } from \"./Guest\";\nimport { GuestPool } from \"./GuestPool\";\nimport { ChainType } from \"./ChainType\";\nimport { GuestInTheMiddle } from \"./GuestInTheMiddle\";\nimport { GuestType } from \"./GuestType\";\n\nexport class Chain<T> implements ChainType<T> {\n private theChain: Cache<Record<string, unknown>>;\n\n private keysKnown = new Set();\n\n private keysFilled = new Set();\n\n private filledChainPool = new GuestPool(this);\n\n public constructor() {\n this.theChain = new Cache<Record<string, unknown>>(this, {});\n }\n\n public resultArray(guest: GuestType<T>) {\n this.filledChainPool.add(\n new GuestInTheMiddle(guest, (value: Record<string, unknown>) =>\n Object.values(value),\n ),\n );\n if (this.isChainFilled()) {\n this.theChain.receiving(\n new Guest((chain) => {\n this.filledChainPool.receive(Object.values(chain));\n }),\n );\n }\n\n return this;\n }\n\n public result(guest: GuestType<T>) {\n if (this.isChainFilled()) {\n this.filledChainPool.add(guest);\n this.theChain.receiving(\n new Guest((chain) => {\n this.filledChainPool.receive(chain);\n }),\n );\n } else {\n this.filledChainPool.add(guest);\n }\n return this;\n }\n\n public receiveKey<R>(key: string): GuestType<R> {\n this.keysKnown.add(key);\n return new Guest((value) => {\n // Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей\n queueMicrotask(() => {\n this.theChain.receiving(\n new Guest((chain) => {\n this.keysFilled.add(key);\n const lastChain = {\n ...chain,\n [key]: value,\n };\n this.theChain.receive(lastChain);\n if (this.isChainFilled()) {\n this.filledChainPool.receive(lastChain);\n }\n }),\n );\n });\n });\n }\n\n private isChainFilled() {\n return (\n this.keysFilled.size > 0 && this.keysFilled.size === this.keysKnown.size\n );\n }\n}\n","import { FactoryType } from \"./FactoryType\";\n\ninterface Constructable<T> {\n new (...args: unknown[]): T;\n}\n\ninterface Prototyped<T> {\n prototype: T;\n}\n\nexport class Factory<T> implements FactoryType<T> {\n public constructor(private constructorFn: Prototyped<T>) {}\n\n public create<R extends unknown[], CT = null>(\n ...args: R\n ): CT extends null ? T : CT {\n return new (this.constructorFn as Constructable<T>)(\n ...args,\n ) as CT extends null ? T : CT;\n }\n}\n","import { FactoryType } from \"./FactoryType\";\n\nexport class FactoryDynamic<T> implements FactoryType<T> {\n public constructor(private creationFn: (...args: unknown[]) => T) {}\n\n public create<R extends unknown[], CT = null>(\n ...args: R\n ): CT extends null ? T : CT {\n return this.creationFn(...args) as CT extends null ? T : CT;\n }\n}\n","import { FactoryType } from \"./FactoryType\";\n\ninterface Constructable<T> {\n new (...args: unknown[]): T;\n}\n\ninterface Prototyped<T> {\n prototype: T;\n}\n\nexport class FactoryWithFactories<T> implements FactoryType<T> {\n public constructor(\n private constructorFn: Prototyped<T>,\n private factories: Record<string, unknown> = {},\n ) {}\n\n public create<R extends unknown[], CT = null>(\n ...args: R\n ): CT extends null ? T : CT {\n return new (this.constructorFn as Constructable<T>)(\n ...args,\n this.factories,\n ) as CT extends null ? T : CT;\n }\n}\n","import { GuestType } from \"./GuestType\";\nimport { GuestAwareType } from \"./GuestAwareType\";\n\nexport class GuestAware<T = unknown> implements GuestAwareType<T> {\n public constructor(private guestReceiver: (guest: GuestType<T>) => void) {}\n\n public receiving(guest: GuestType<T>): GuestType<T> {\n this.guestReceiver(guest);\n return guest;\n }\n}\n","import { GuestType, ReceiveOptions } from \"./GuestType\";\n\nexport class GuestCast<T> implements GuestType<T> {\n public constructor(\n private sourceGuest: GuestType<unknown>,\n private targetGuest: GuestType<T>,\n ) {}\n\n introduction() {\n if (!this.sourceGuest.introduction) {\n return \"guest\";\n }\n return this.sourceGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n this.targetGuest.receive(value, options);\n return this;\n }\n}\n","import { GuestValueType } from \"./GuestValueType\";\n\nexport class GuestSync<T> implements GuestValueType<T> {\n public constructor(private theValue: T) {}\n\n public receive(value: T): this {\n this.theValue = value;\n return this;\n }\n\n public value() {\n return this.theValue;\n }\n}\n","import { GuestType, ReceiveOptions } from \"./GuestType\";\n\n/**\n * Патрон - это постоянный посетитель\n */\nexport class Patron<T> implements GuestType<T> {\n public constructor(private willBePatron: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n this.willBePatron.receive(value, options);\n return this;\n }\n}\n","import { GuestType, ReceiveOptions } from \"./GuestType\";\nimport { PoolType } from \"./PoolType\";\n\ntype PoolAware = {\n pool?: PoolType;\n};\n\nexport class PatronOnce<T> implements GuestType<T> {\n private received = false;\n\n public constructor(private baseGuest: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n if (!this.received) {\n this.baseGuest.receive(value, options);\n }\n\n const data = options?.data as PoolAware;\n // Если есть пул, то удаляем себя из пула\n if (data?.pool) {\n data.pool.remove(this);\n }\n\n return this;\n }\n}\n","import { GuestType } from \"./GuestType\";\nimport { PatronPool } from \"./PatronPool\";\nimport { SourceType } from \"./SourceType\";\n\nexport class Source<T> implements SourceType<T> {\n private pool = new PatronPool(this);\n\n public constructor(private sourceDocument: T) {}\n\n public receive(value: T): this {\n this.sourceDocument = value;\n this.pool.receive(this.sourceDocument);\n return this;\n }\n\n public receiving(guest: GuestType<T>): this {\n this.pool.distribute(this.sourceDocument, guest);\n return this;\n }\n}\n"],"names":["__publicField"],"mappings":";;;AAGA,MAAM,QAAA,uBAAe,GAA8B,EAAA,CAAA;AAKtC,MAAA,qBAAA,GAAwB,CAAC,MAAsB,KAAA;AAC1D,EAAS,QAAA,CAAA,OAAA,CAAQ,CAAC,IAAS,KAAA;AACzB,IAAA,IAAA,CAAK,OAAO,MAAM,CAAA,CAAA;AAAA,GACnB,CAAA,CAAA;AACH,EAAA;AAEO,MAAM,UAAqC,CAAA;AAAA,EAKzC,YAAoB,SAAoB,EAAA;AAApB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA,CAAA;AAJ3B,IAAQA,eAAA,CAAA,IAAA,EAAA,SAAA,sBAAc,GAAkB,EAAA,CAAA,CAAA;AAExC,IAAOA,eAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;AAGL,IAAS,QAAA,CAAA,GAAA,CAAI,IAAM,EAAA,IAAA,CAAK,OAAO,CAAA,CAAA;AAE/B,IAAA,IAAI,aAAqC,GAAA,IAAA,CAAA;AACzC,IAAM,MAAA,SAAA,GAAY,CAAC,KAAA,EAAU,OAA6B,KAAA;AACxD,MAAK,IAAA,CAAA,OAAA,CAAQ,OAAQ,CAAA,CAAC,MAAW,KAAA;AAC/B,QAAK,IAAA,CAAA,gBAAA,CAAiB,KAAO,EAAA,MAAA,EAAQ,OAAO,CAAA,CAAA;AAAA,OAC7C,CAAA,CAAA;AAAA,KACH,CAAA;AACA,IAAK,IAAA,CAAA,OAAA,GAAU,CAAC,KAAA,EAAU,OAA6B,KAAA;AACrD,MAAA,MAAM,mBAAmB,MAAM;AAC7B,QAAA,IAAI,qBAAqB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A,CAAA,IAAA,CAAK,OAAQ,CAAA,IAAA,CAAK,cAAc,CAAA,CAAA;AACrC,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAAA,EAEO,UAAU,KAA2B,EAAA;AAC1C,IAAA,IAAA,CAAK,IAAK,CAAA,UAAA,CAAW,IAAK,CAAA,cAAA,EAAgB,KAAK,CAAA,CAAA;AAC/C,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AACF;;;;"}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import typescriptEslint from "@typescript-eslint/eslint-plugin";
|
2
|
+
import tsParser from "@typescript-eslint/parser";
|
3
|
+
import path from "node:path";
|
4
|
+
import { fileURLToPath } from "node:url";
|
5
|
+
import js from "@eslint/js";
|
6
|
+
import { FlatCompat } from "@eslint/eslintrc";
|
7
|
+
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
|
8
|
+
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
10
|
+
const __dirname = path.dirname(__filename);
|
11
|
+
const compat = new FlatCompat({
|
12
|
+
baseDirectory: __dirname,
|
13
|
+
recommendedConfig: js.configs.recommended,
|
14
|
+
allConfig: js.configs.all,
|
15
|
+
});
|
16
|
+
|
17
|
+
export default [
|
18
|
+
{
|
19
|
+
ignores: ["**/node_modules", "**/dist"],
|
20
|
+
},
|
21
|
+
...compat.extends(
|
22
|
+
"eslint:recommended",
|
23
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
24
|
+
"plugin:@typescript-eslint/recommended",
|
25
|
+
),
|
26
|
+
{
|
27
|
+
plugins: {
|
28
|
+
"@typescript-eslint": typescriptEslint,
|
29
|
+
},
|
30
|
+
|
31
|
+
languageOptions: {
|
32
|
+
parser: tsParser,
|
33
|
+
},
|
34
|
+
},
|
35
|
+
eslintPluginPrettierRecommended,
|
36
|
+
];
|
package/package.json
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
{
|
2
|
+
"name": "patron-oop",
|
3
|
+
"version": "1.1.0",
|
4
|
+
"description": "",
|
5
|
+
"type": "module",
|
6
|
+
"main": "dist/patron.js",
|
7
|
+
"module": "dist/patron.mjs",
|
8
|
+
"typings": "dist/patron.d.ts",
|
9
|
+
"scripts": {
|
10
|
+
"build": "rollup -c",
|
11
|
+
"lint": "eslint src",
|
12
|
+
"lint-fix": "eslint src --fix",
|
13
|
+
"test": "vitest",
|
14
|
+
"cz": "git add . && git cz",
|
15
|
+
"test-debug": "env DEBUG=app:* vitest",
|
16
|
+
"release": "standard-version --no-verify"
|
17
|
+
},
|
18
|
+
"repository": {
|
19
|
+
"type": "git",
|
20
|
+
"url": "https://github.com/kosukhin/patron.git"
|
21
|
+
},
|
22
|
+
"private": false,
|
23
|
+
"devDependencies": {
|
24
|
+
"@eslint/eslintrc": "^3.1.0",
|
25
|
+
"@eslint/js": "^9.12.0",
|
26
|
+
"@typescript-eslint/eslint-plugin": "^8.8.1",
|
27
|
+
"@typescript-eslint/parser": "^8.8.1",
|
28
|
+
"cz-customizable": "^7.0.0",
|
29
|
+
"esbuild": "^0.24.0",
|
30
|
+
"eslint": "^9.12.0",
|
31
|
+
"eslint-config-prettier": "^9.1.0",
|
32
|
+
"eslint-plugin-prettier": "^5.2.1",
|
33
|
+
"prettier": "3.3.3",
|
34
|
+
"rollup": "^4.24.0",
|
35
|
+
"rollup-plugin-dts": "^6.1.1",
|
36
|
+
"rollup-plugin-esbuild": "^6.1.1",
|
37
|
+
"standard-version": "^9.5.0",
|
38
|
+
"vitest": "^2.1.2"
|
39
|
+
},
|
40
|
+
"config": {
|
41
|
+
"commitizen": {
|
42
|
+
"path": "./node_modules/cz-customizable"
|
43
|
+
},
|
44
|
+
"cz-customizable": {
|
45
|
+
"config": "./commitizen.cjs"
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
package/rollup.config.js
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
import dts from "rollup-plugin-dts";
|
2
|
+
import esbuild from "rollup-plugin-esbuild";
|
3
|
+
|
4
|
+
const name = "dist/patron";
|
5
|
+
|
6
|
+
const bundle = (config) => ({
|
7
|
+
...config,
|
8
|
+
input: "src/index.ts",
|
9
|
+
external: (id) => !/^[./]/.test(id),
|
10
|
+
});
|
11
|
+
|
12
|
+
export default [
|
13
|
+
bundle({
|
14
|
+
plugins: [esbuild()],
|
15
|
+
output: [
|
16
|
+
{
|
17
|
+
file: `${name}.js`,
|
18
|
+
format: "cjs",
|
19
|
+
sourcemap: true,
|
20
|
+
},
|
21
|
+
{
|
22
|
+
file: `${name}.mjs`,
|
23
|
+
format: "es",
|
24
|
+
sourcemap: true,
|
25
|
+
},
|
26
|
+
],
|
27
|
+
}),
|
28
|
+
bundle({
|
29
|
+
plugins: [dts()],
|
30
|
+
output: {
|
31
|
+
file: `${name}.d.ts`,
|
32
|
+
format: "es",
|
33
|
+
},
|
34
|
+
}),
|
35
|
+
];
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { expect, test } from "vitest";
|
2
|
+
import { Cache } from "./Cache";
|
3
|
+
import { Guest } from "./Guest";
|
4
|
+
|
5
|
+
test("value works", () => {
|
6
|
+
const value = new Cache(null);
|
7
|
+
value.receive(2);
|
8
|
+
value.receiving(
|
9
|
+
new Guest((latestValue: number) => {
|
10
|
+
expect(latestValue).toBe(2);
|
11
|
+
}),
|
12
|
+
);
|
13
|
+
|
14
|
+
value.receive(4);
|
15
|
+
value.receiving(
|
16
|
+
new Guest((latestValue: number) => {
|
17
|
+
expect(latestValue).toBe(4);
|
18
|
+
}),
|
19
|
+
);
|
20
|
+
});
|
package/src/Cache.ts
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
import { PatronPool } from "./PatronPool";
|
2
|
+
import { CacheType } from "./CacheType";
|
3
|
+
import { GuestType, ReceiveOptions } from "./GuestType";
|
4
|
+
|
5
|
+
export class Cache<T> implements CacheType<T> {
|
6
|
+
private pool: PatronPool<T>;
|
7
|
+
|
8
|
+
public constructor(
|
9
|
+
initiator: unknown,
|
10
|
+
private defaultValue: T | null = null,
|
11
|
+
private theCache: T | null = null,
|
12
|
+
) {
|
13
|
+
this.pool = new PatronPool<T>(initiator);
|
14
|
+
}
|
15
|
+
|
16
|
+
public receive(value: T, options?: ReceiveOptions): this {
|
17
|
+
this.theCache = value;
|
18
|
+
this.pool.receive(value, options);
|
19
|
+
return this;
|
20
|
+
}
|
21
|
+
|
22
|
+
public receiving(guest: GuestType<T>): this {
|
23
|
+
if (this.theCache !== null) {
|
24
|
+
guest.receive(this.theCache);
|
25
|
+
} else if (this.defaultValue !== null) {
|
26
|
+
guest.receive(this.defaultValue);
|
27
|
+
}
|
28
|
+
this.pool.add(guest);
|
29
|
+
return this;
|
30
|
+
}
|
31
|
+
}
|
package/src/CacheType.ts
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
import { expect, test } from "vitest";
|
2
|
+
import { Chain } from "./Chain";
|
3
|
+
import { Patron } from "./Patron";
|
4
|
+
import { Guest } from "./Guest";
|
5
|
+
import { Source } from "./Source";
|
6
|
+
|
7
|
+
test("chain guest returns 2 values after result guest", () => {
|
8
|
+
const one = new Source(1);
|
9
|
+
const two = new Source(2);
|
10
|
+
const chain = new Chain<{ one: number; two: number }>();
|
11
|
+
|
12
|
+
chain.result(
|
13
|
+
new Guest((value) => {
|
14
|
+
expect(Object.values(value).join()).toBe("1,2");
|
15
|
+
}),
|
16
|
+
);
|
17
|
+
|
18
|
+
one.receiving(chain.receiveKey("one"));
|
19
|
+
two.receiving(chain.receiveKey("two"));
|
20
|
+
});
|
21
|
+
|
22
|
+
test("chain guest returns 2 values before result guest", () => {
|
23
|
+
const one = new Source(1);
|
24
|
+
const two = new Source(2);
|
25
|
+
const chain = new Chain<{ one: number; two: number }>();
|
26
|
+
|
27
|
+
one.receiving(chain.receiveKey("one"));
|
28
|
+
two.receiving(chain.receiveKey("two"));
|
29
|
+
|
30
|
+
chain.result(
|
31
|
+
new Guest((value) => {
|
32
|
+
expect(Object.values(value).join()).toBe("1,2");
|
33
|
+
}),
|
34
|
+
);
|
35
|
+
});
|
36
|
+
|
37
|
+
test("chain with patron", () => {
|
38
|
+
const one = new Source(1);
|
39
|
+
const two = new Source(2);
|
40
|
+
const chain = new Chain<{ one: number; two: number }>();
|
41
|
+
|
42
|
+
one.receiving(new Patron(chain.receiveKey("one")));
|
43
|
+
two.receiving(new Patron(chain.receiveKey("two")));
|
44
|
+
|
45
|
+
one.receive(3);
|
46
|
+
one.receive(4);
|
47
|
+
|
48
|
+
chain.result(
|
49
|
+
new Patron(
|
50
|
+
new Guest((value) => {
|
51
|
+
expect(Object.values(value).length).toBe(2);
|
52
|
+
}),
|
53
|
+
),
|
54
|
+
);
|
55
|
+
});
|
56
|
+
|
57
|
+
test("chain as array", () => {
|
58
|
+
const one = new Source(1);
|
59
|
+
const two = new Source(2);
|
60
|
+
const chain = new Chain<[number, number]>();
|
61
|
+
|
62
|
+
one.receiving(new Patron(chain.receiveKey("0")));
|
63
|
+
two.receiving(new Patron(chain.receiveKey("1")));
|
64
|
+
|
65
|
+
chain.resultArray(
|
66
|
+
new Patron(
|
67
|
+
new Guest((value) => {
|
68
|
+
expect(JSON.stringify(value)).toBe("[1, 2]");
|
69
|
+
}),
|
70
|
+
),
|
71
|
+
);
|
72
|
+
});
|