patron-oop 1.6.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/patron.d.ts +61 -80
  3. package/dist/patron.js +77 -112
  4. package/dist/patron.js.map +1 -1
  5. package/dist/patron.min.js +1 -1
  6. package/dist/patron.mjs +72 -111
  7. package/dist/patron.mjs.map +1 -1
  8. package/examples/reactive.html +52 -62
  9. package/package.json +1 -1
  10. package/src/Guest/Guest.test.ts +10 -0
  11. package/src/Guest/Guest.ts +28 -35
  12. package/src/Guest/GuestAware.test.ts +6 -8
  13. package/src/Guest/GuestAware.ts +1 -1
  14. package/src/Guest/GuestCast.test.ts +8 -8
  15. package/src/Guest/GuestCast.ts +7 -3
  16. package/src/Guest/GuestChain.test.ts +21 -21
  17. package/src/Guest/GuestChain.ts +14 -14
  18. package/src/Guest/GuestInTheMiddle.test.ts +14 -14
  19. package/src/Guest/GuestInTheMiddle.ts +3 -3
  20. package/src/Guest/GuestPool.test.ts +10 -17
  21. package/src/Guest/GuestPool.ts +10 -6
  22. package/src/Guest/GuestSync.test.ts +4 -4
  23. package/src/Guest/GuestSync.ts +2 -2
  24. package/src/Patron/Patron.test.ts +17 -0
  25. package/src/Patron/Patron.ts +16 -12
  26. package/src/Patron/PatronOnce.test.ts +5 -8
  27. package/src/Patron/PatronOnce.ts +8 -3
  28. package/src/Patron/PatronPool.test.ts +9 -14
  29. package/src/Patron/PatronPool.ts +16 -10
  30. package/src/Source/Source.test.ts +10 -0
  31. package/src/Source/Source.ts +21 -7
  32. package/src/index.ts +36 -14
  33. package/src/Guest/GuestCallback.test.ts +0 -13
  34. package/src/Guest/GuestCallback.ts +0 -21
  35. package/src/Patron/PatronOfGuest.test.ts +0 -20
  36. package/src/Patron/PatronOfGuest.ts +0 -17
  37. package/src/Source/SourceOfValue.test.ts +0 -13
  38. package/src/Source/SourceOfValue.ts +0 -22
  39. package/src/Source/SourcesApplied.test.ts +0 -26
  40. package/src/Source/SourcesApplied.ts +0 -39
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [1.8.0](https://github.com/kosukhin/patron/compare/v1.7.0...v1.8.0) (2024-10-25)
6
+
7
+
8
+ ### Features
9
+
10
+ * **main:** вернул название Source ([9350b13](https://github.com/kosukhin/patron/commit/9350b13eb9d2ad2f26bb5697a8ff42332ef16607))
11
+
12
+ ## [1.7.0](https://github.com/kosukhin/patron/compare/v1.6.1...v1.7.0) (2024-10-25)
13
+
14
+
15
+ ### Features
16
+
17
+ * **main:** возвращение к классам ([037837a](https://github.com/kosukhin/patron/commit/037837a0d08208edb99a2a02c4a32bd1ea36e650))
18
+
19
+ ### [1.6.1](https://github.com/kosukhin/patron/compare/v1.6.0...v1.6.1) (2024-10-25)
20
+
5
21
  ## [1.6.0](https://github.com/kosukhin/patron/compare/v1.5.2...v1.6.0) (2024-10-21)
6
22
 
7
23
 
package/dist/patron.d.ts CHANGED
@@ -2,21 +2,40 @@ type GuestIntroduction = "guest" | "patron";
2
2
  interface ReceiveOptions {
3
3
  data?: unknown;
4
4
  }
5
- type GuestExecutorType<T> = (value: T, options?: ReceiveOptions) => void;
6
- interface GuestType<T = unknown> {
5
+ type GuestExecutorType<T = unknown> = (value: T, options?: ReceiveOptions) => void;
6
+ interface GuestObjectType<T = unknown> {
7
7
  receive(value: T, options?: ReceiveOptions): this;
8
8
  introduction?(): GuestIntroduction;
9
9
  }
10
- declare class GuestCallback<T> implements GuestType<T> {
10
+ type GuestType<T = unknown> = GuestExecutorType<T> | GuestObjectType<T>;
11
+ declare function give<T>(data: T, guest: GuestType<T>, options?: ReceiveOptions): void;
12
+ declare class Guest<T> implements GuestObjectType<T> {
11
13
  private receiver;
12
14
  constructor(receiver: GuestExecutorType<T>);
13
15
  receive(value: T, options?: ReceiveOptions): this;
14
16
  }
15
17
 
18
+ interface GuestAwareType<T = unknown> {
19
+ receiving(guest: GuestType<T>): unknown;
20
+ }
21
+ declare class GuestAware<T = unknown> implements GuestAwareType<T> {
22
+ private guestReceiver;
23
+ constructor(guestReceiver: (guest: GuestType<T>) => void);
24
+ receiving(guest: GuestType<T>): GuestType<T>;
25
+ }
26
+
27
+ declare class GuestCast<T> implements GuestObjectType<T> {
28
+ private sourceGuest;
29
+ private targetGuest;
30
+ constructor(sourceGuest: GuestType<unknown>, targetGuest: GuestType<T>);
31
+ introduction(): "guest" | "patron";
32
+ receive(value: T, options?: ReceiveOptions): this;
33
+ }
34
+
16
35
  interface ChainType<T = unknown> {
17
- result(guest: GuestType<T>): this;
18
- resultArray(guest: GuestType<T>): this;
19
- receiveKey<R>(key: string): GuestType<R>;
36
+ result(guest: GuestObjectType<T>): this;
37
+ resultArray(guest: GuestObjectType<T>): this;
38
+ receiveKey<R>(key: string): GuestObjectType<R>;
20
39
  }
21
40
  declare class GuestChain<T> implements ChainType<T> {
22
41
  private theChain;
@@ -24,30 +43,28 @@ declare class GuestChain<T> implements ChainType<T> {
24
43
  private keysFilled;
25
44
  private filledChainPool;
26
45
  constructor();
27
- resultArray(guest: GuestType<T>): this;
28
- result(guest: GuestType<T>): this;
29
- receiveKey<R>(key: string): GuestType<R>;
46
+ resultArray(guest: GuestObjectType<T>): this;
47
+ result(guest: GuestObjectType<T>): this;
48
+ receiveKey<R>(key: string): GuestObjectType<R>;
30
49
  private isChainFilled;
31
50
  }
32
51
 
33
- interface GuestValueType<T = unknown> extends GuestType<T> {
34
- value(): T;
35
- }
36
- declare class GuestSync<T> implements GuestValueType<T> {
37
- private theValue;
38
- constructor(theValue: T);
39
- receive(value: T): this;
40
- value(): T;
52
+ declare class GuestInTheMiddle<T> implements GuestObjectType<T> {
53
+ private baseGuest;
54
+ private middleFn;
55
+ constructor(baseGuest: GuestObjectType<unknown>, middleFn: (value: T, options?: ReceiveOptions) => void);
56
+ introduction(): "guest" | "patron";
57
+ receive(value: T, options?: ReceiveOptions): this;
41
58
  }
42
59
 
43
60
  /**
44
61
  * Удалить патрон из всех пулов
45
62
  */
46
- declare const removePatronFromPools: (patron: GuestType) => void;
47
- interface PoolType<T = unknown> extends GuestType<T> {
48
- add(guest: GuestType<T>): this;
49
- distribute(receiving: T, possiblePatron: GuestType<T>): this;
50
- remove(patron: GuestType<T>): this;
63
+ declare const removePatronFromPools: (patron: GuestObjectType) => void;
64
+ interface PoolType<T = unknown> extends GuestObjectType<T> {
65
+ add(guest: GuestObjectType<T>): this;
66
+ distribute(receiving: T, possiblePatron: GuestObjectType<T>): this;
67
+ remove(patron: GuestObjectType<T>): this;
51
68
  }
52
69
  declare class PatronPool<T> implements PoolType<T> {
53
70
  private initiator;
@@ -55,77 +72,43 @@ declare class PatronPool<T> implements PoolType<T> {
55
72
  receive: (value: T, options?: ReceiveOptions) => this;
56
73
  constructor(initiator: unknown);
57
74
  add(shouldBePatron: GuestType<T>): this;
58
- remove(patron: GuestType<T>): this;
75
+ remove(patron: GuestObjectType<T>): this;
59
76
  distribute(receiving: T, possiblePatron: GuestType<T>): this;
60
77
  private sendValueToGuest;
61
78
  }
62
79
 
63
- interface GuestAwareType<T = unknown> {
64
- receiving(guest: GuestType<T>): unknown;
65
- }
66
- declare class GuestAware<T = unknown> implements GuestAwareType<T> {
67
- private guestReceiver;
68
- constructor(guestReceiver: (guest: GuestType<T>) => void);
69
- receiving(guest: GuestType<T>): GuestType<T>;
70
- }
71
-
72
- type SourceType<T = unknown> = GuestAwareType<T> & GuestType<T>;
73
- declare class SourceOfValue<T> implements SourceType<T> {
74
- private sourceDocument;
75
- private pool;
76
- constructor(sourceDocument: T);
77
- receive(value: T): this;
78
- receiving(guest: GuestType<T>): this;
79
- }
80
-
81
- declare class GuestCast<T> implements GuestType<T> {
82
- private sourceGuest;
83
- private targetGuest;
84
- constructor(sourceGuest: GuestType<unknown>, targetGuest: GuestType<T>);
85
- introduction(): "guest" | "patron";
86
- receive(value: T, options?: ReceiveOptions): this;
87
- }
88
-
89
- declare class GuestInTheMiddle<T> implements GuestType<T> {
90
- private baseGuest;
91
- private middleFn;
92
- constructor(baseGuest: GuestType<unknown>, middleFn: (value: T, options?: ReceiveOptions) => void);
93
- introduction(): "guest" | "patron";
94
- receive(value: T, options?: ReceiveOptions): this;
95
- }
96
-
97
- declare class GuestPool<T> implements GuestType<T>, PoolType<T> {
80
+ declare class GuestPool<T> implements GuestObjectType<T>, PoolType<T> {
98
81
  private guests;
99
82
  private patronPool;
100
83
  constructor(initiator: unknown);
101
84
  receive(value: T, options?: ReceiveOptions): this;
102
85
  add(guest: GuestType<T>): this;
103
- remove(patron: GuestType<T>): this;
104
- distribute(receiving: T, possiblePatron: GuestType<T>): this;
86
+ remove(patron: GuestObjectType<T>): this;
87
+ distribute(receiving: T, possiblePatron: GuestObjectType<T>): this;
105
88
  private deliverToGuests;
106
89
  }
107
90
 
108
- declare class Guest {
109
- callback<P>(receiver: GuestExecutorType<P>): GuestCallback<P>;
110
- chain(): GuestChain<unknown>;
111
- cast<P>(sourceGuest: GuestType<unknown>, targetGuest: GuestType<P>): GuestCast<P>;
112
- middleware<P>(baseGuest: GuestType<unknown>, middleFn: (value: P, options?: ReceiveOptions) => void): GuestInTheMiddle<P>;
113
- pool(initiator: unknown): GuestPool<unknown>;
114
- aware<P>(guestReceiver: (guest: GuestType<P>) => void): GuestAware<P>;
115
- sync<P>(value: P): GuestSync<P>;
91
+ interface GuestValueType<T = unknown> extends GuestObjectType<T> {
92
+ value(): T;
93
+ }
94
+ declare class GuestSync<T> implements GuestValueType<T> {
95
+ private theValue;
96
+ constructor(theValue: T);
97
+ receive(value: T): this;
98
+ value(): T;
116
99
  }
117
100
 
118
101
  /**
119
102
  * Патрон - это постоянный посетитель
120
103
  */
121
- declare class PatronOfGuest<T> implements GuestType<T> {
104
+ declare class Patron<T> implements GuestObjectType<T> {
122
105
  private willBePatron;
123
106
  constructor(willBePatron: GuestType<T>);
124
107
  introduction(): "patron";
125
108
  receive(value: T, options?: ReceiveOptions): this;
126
109
  }
127
110
 
128
- declare class PatronOnce<T> implements GuestType<T> {
111
+ declare class PatronOnce<T> implements GuestObjectType<T> {
129
112
  private baseGuest;
130
113
  private received;
131
114
  constructor(baseGuest: GuestType<T>);
@@ -133,15 +116,13 @@ declare class PatronOnce<T> implements GuestType<T> {
133
116
  receive(value: T, options?: ReceiveOptions): this;
134
117
  }
135
118
 
136
- declare class Patron {
137
- ofGuest<P>(willBePatron: GuestType<P>): PatronOfGuest<P>;
138
- once<P>(baseGuest: GuestType<P>): PatronOnce<P>;
139
- pool(initiator: unknown): PatronPool<unknown>;
140
- }
141
-
142
- declare class Source {
143
- ofValue<P>(sourceDocument: P): SourceOfValue<P>;
144
- applySources<P>(target: P, methodsSources: Record<string, unknown[]>): any;
119
+ type SourceType<T = unknown> = GuestAwareType<T> & GuestObjectType<T>;
120
+ declare class Source<T> implements SourceType<T> {
121
+ private sourceDocument;
122
+ private pool;
123
+ constructor(sourceDocument: T);
124
+ receive(value: T): this;
125
+ receiving(guest: GuestType<T>): this;
145
126
  }
146
127
 
147
- export { type ChainType, Guest, GuestCallback, GuestChain, type GuestExecutorType, GuestSync, type GuestType, type GuestValueType, Patron, PatronPool, type PoolType, type ReceiveOptions, Source, SourceOfValue, type SourceType, removePatronFromPools };
128
+ export { type ChainType, Guest, GuestAware, type GuestAwareType, GuestCast, GuestChain, type GuestExecutorType, GuestInTheMiddle, type GuestObjectType, GuestPool, GuestSync, type GuestType, type GuestValueType, Patron, PatronOnce, PatronPool, type PoolType, type ReceiveOptions, Source, type SourceType, give, removePatronFromPools };
package/dist/patron.js CHANGED
@@ -1,6 +1,13 @@
1
1
  'use strict';
2
2
 
3
- class GuestCallback {
3
+ function give(data, guest, options) {
4
+ if (typeof guest === "function") {
5
+ guest(data, options);
6
+ } else {
7
+ guest.receive(data, options);
8
+ }
9
+ }
10
+ class Guest {
4
11
  constructor(receiver) {
5
12
  this.receiver = receiver;
6
13
  }
@@ -43,7 +50,7 @@ class PatronPool {
43
50
  };
44
51
  }
45
52
  add(shouldBePatron) {
46
- if (shouldBePatron.introduction && shouldBePatron.introduction() === "patron") {
53
+ if (typeof shouldBePatron !== "function" && shouldBePatron.introduction && shouldBePatron.introduction() === "patron") {
47
54
  this.patrons.add(shouldBePatron);
48
55
  }
49
56
  return this;
@@ -58,7 +65,7 @@ class PatronPool {
58
65
  return this;
59
66
  }
60
67
  sendValueToGuest(value, guest, options) {
61
- guest.receive(value, {
68
+ give(value, guest, {
62
69
  ...options,
63
70
  data: {
64
71
  ...options?.data ?? {},
@@ -69,6 +76,36 @@ class PatronPool {
69
76
  }
70
77
  }
71
78
 
79
+ class GuestAware {
80
+ constructor(guestReceiver) {
81
+ this.guestReceiver = guestReceiver;
82
+ }
83
+ receiving(guest) {
84
+ this.guestReceiver(guest);
85
+ return guest;
86
+ }
87
+ }
88
+
89
+ class GuestCast {
90
+ constructor(sourceGuest, targetGuest) {
91
+ this.sourceGuest = sourceGuest;
92
+ this.targetGuest = targetGuest;
93
+ }
94
+ introduction() {
95
+ if (typeof this.sourceGuest === "function") {
96
+ return "guest";
97
+ }
98
+ if (!this.sourceGuest.introduction) {
99
+ return "guest";
100
+ }
101
+ return this.sourceGuest.introduction();
102
+ }
103
+ receive(value, options) {
104
+ give(value, this.targetGuest, options);
105
+ return this;
106
+ }
107
+ }
108
+
72
109
  var __defProp$3 = Object.defineProperty;
73
110
  var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
74
111
  var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -84,7 +121,7 @@ class GuestPool {
84
121
  return this;
85
122
  }
86
123
  add(guest) {
87
- if (!guest.introduction || guest.introduction() === "guest") {
124
+ if (typeof guest === "function" || !guest.introduction || guest.introduction() === "guest") {
88
125
  this.guests.add(guest);
89
126
  }
90
127
  this.patronPool.add(guest);
@@ -102,7 +139,7 @@ class GuestPool {
102
139
  }
103
140
  deliverToGuests(value, options) {
104
141
  this.guests.forEach((target) => {
105
- target.receive(value, options);
142
+ give(value, target, options);
106
143
  });
107
144
  this.guests.clear();
108
145
  }
@@ -128,7 +165,7 @@ class GuestInTheMiddle {
128
165
  var __defProp$2 = Object.defineProperty;
129
166
  var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
130
167
  var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, key + "" , value);
131
- class SourceOfValue {
168
+ class Source {
132
169
  constructor(sourceDocument) {
133
170
  this.sourceDocument = sourceDocument;
134
171
  __publicField$2(this, "pool", new PatronPool(this));
@@ -139,7 +176,11 @@ class SourceOfValue {
139
176
  return this;
140
177
  }
141
178
  receiving(guest) {
142
- this.pool.distribute(this.sourceDocument, guest);
179
+ if (typeof guest === "function") {
180
+ this.pool.distribute(this.sourceDocument, new Guest(guest));
181
+ } else {
182
+ this.pool.distribute(this.sourceDocument, guest);
183
+ }
143
184
  return this;
144
185
  }
145
186
  }
@@ -153,7 +194,7 @@ class GuestChain {
153
194
  __publicField$1(this, "keysKnown", /* @__PURE__ */ new Set());
154
195
  __publicField$1(this, "keysFilled", /* @__PURE__ */ new Set());
155
196
  __publicField$1(this, "filledChainPool", new GuestPool(this));
156
- this.theChain = new SourceOfValue({});
197
+ this.theChain = new Source({});
157
198
  }
158
199
  resultArray(guest) {
159
200
  this.filledChainPool.add(
@@ -164,7 +205,7 @@ class GuestChain {
164
205
  );
165
206
  if (this.isChainFilled()) {
166
207
  this.theChain.receiving(
167
- new GuestCallback((chain) => {
208
+ new Guest((chain) => {
168
209
  this.filledChainPool.receive(Object.values(chain));
169
210
  })
170
211
  );
@@ -175,7 +216,7 @@ class GuestChain {
175
216
  if (this.isChainFilled()) {
176
217
  this.filledChainPool.add(guest);
177
218
  this.theChain.receiving(
178
- new GuestCallback((chain) => {
219
+ new Guest((chain) => {
179
220
  this.filledChainPool.receive(chain);
180
221
  })
181
222
  );
@@ -186,10 +227,10 @@ class GuestChain {
186
227
  }
187
228
  receiveKey(key) {
188
229
  this.keysKnown.add(key);
189
- return new GuestCallback((value) => {
230
+ return new Guest((value) => {
190
231
  queueMicrotask(() => {
191
232
  this.theChain.receiving(
192
- new GuestCallback((chain) => {
233
+ new Guest((chain) => {
193
234
  this.keysFilled.add(key);
194
235
  const lastChain = {
195
236
  ...chain,
@@ -222,58 +263,7 @@ class GuestSync {
222
263
  }
223
264
  }
224
265
 
225
- class GuestCast {
226
- constructor(sourceGuest, targetGuest) {
227
- this.sourceGuest = sourceGuest;
228
- this.targetGuest = targetGuest;
229
- }
230
- introduction() {
231
- if (!this.sourceGuest.introduction) {
232
- return "guest";
233
- }
234
- return this.sourceGuest.introduction();
235
- }
236
- receive(value, options) {
237
- this.targetGuest.receive(value, options);
238
- return this;
239
- }
240
- }
241
-
242
- class GuestAware {
243
- constructor(guestReceiver) {
244
- this.guestReceiver = guestReceiver;
245
- }
246
- receiving(guest) {
247
- this.guestReceiver(guest);
248
- return guest;
249
- }
250
- }
251
-
252
- class Guest {
253
- callback(receiver) {
254
- return new GuestCallback(receiver);
255
- }
256
- chain() {
257
- return new GuestChain();
258
- }
259
- cast(sourceGuest, targetGuest) {
260
- return new GuestCast(sourceGuest, targetGuest);
261
- }
262
- middleware(baseGuest, middleFn) {
263
- return new GuestInTheMiddle(baseGuest, middleFn);
264
- }
265
- pool(initiator) {
266
- return new GuestPool(initiator);
267
- }
268
- aware(guestReceiver) {
269
- return new GuestAware(guestReceiver);
270
- }
271
- sync(value) {
272
- return new GuestSync(value);
273
- }
274
- }
275
-
276
- class PatronOfGuest {
266
+ class Patron {
277
267
  constructor(willBePatron) {
278
268
  this.willBePatron = willBePatron;
279
269
  }
@@ -281,7 +271,7 @@ class PatronOfGuest {
281
271
  return "patron";
282
272
  }
283
273
  receive(value, options) {
284
- this.willBePatron.receive(value, options);
274
+ give(value, this.willBePatron, options);
285
275
  return this;
286
276
  }
287
277
  }
@@ -299,7 +289,7 @@ class PatronOnce {
299
289
  }
300
290
  receive(value, options) {
301
291
  if (!this.received) {
302
- this.baseGuest.receive(value, options);
292
+ give(value, this.baseGuest, options);
303
293
  }
304
294
  const data = options?.data;
305
295
  if (data?.pool) {
@@ -309,60 +299,35 @@ class PatronOnce {
309
299
  }
310
300
  }
311
301
 
312
- class Patron {
313
- ofGuest(willBePatron) {
314
- return new PatronOfGuest(willBePatron);
315
- }
316
- once(baseGuest) {
317
- return new PatronOnce(baseGuest);
318
- }
319
- pool(initiator) {
320
- return new PatronPool(initiator);
321
- }
322
- }
323
-
324
- const sourcesApplied = (target, methodsSources) => {
325
- return new Proxy(target, {
326
- get: function(target2, property) {
327
- const maybeMethod = target2[property];
328
- if (typeof maybeMethod !== "function") {
329
- return maybeMethod;
330
- }
331
- return (...args) => {
332
- const appliedArgs = methodsSources[property];
333
- if (appliedArgs) {
334
- return maybeMethod(...appliedArgs, ...args);
335
- }
336
- return maybeMethod(...args);
337
- };
338
- }
339
- });
340
- };
341
-
342
- class Source {
343
- ofValue(sourceDocument) {
344
- return new SourceOfValue(sourceDocument);
345
- }
346
- applySources(target, methodsSources) {
347
- return sourcesApplied(target, methodsSources);
348
- }
349
- }
350
-
351
- if (window) {
352
- window["GUEST_LIBRARY"] = {
353
- guest: new Guest(),
354
- patron: new Patron(),
355
- source: new Source()
302
+ if (globalThis) {
303
+ globalThis["GUEST_LIBRARY"] = {
304
+ give,
305
+ removePatronFromPools,
306
+ GuestAware,
307
+ Guest,
308
+ GuestCast,
309
+ GuestChain,
310
+ GuestInTheMiddle,
311
+ GuestPool,
312
+ GuestSync,
313
+ Patron,
314
+ PatronOnce,
315
+ PatronPool,
316
+ Source
356
317
  };
357
318
  }
358
319
 
359
320
  exports.Guest = Guest;
360
- exports.GuestCallback = GuestCallback;
321
+ exports.GuestAware = GuestAware;
322
+ exports.GuestCast = GuestCast;
361
323
  exports.GuestChain = GuestChain;
324
+ exports.GuestInTheMiddle = GuestInTheMiddle;
325
+ exports.GuestPool = GuestPool;
362
326
  exports.GuestSync = GuestSync;
363
327
  exports.Patron = Patron;
328
+ exports.PatronOnce = PatronOnce;
364
329
  exports.PatronPool = PatronPool;
365
330
  exports.Source = Source;
366
- exports.SourceOfValue = SourceOfValue;
331
+ exports.give = give;
367
332
  exports.removePatronFromPools = removePatronFromPools;
368
333
  //# sourceMappingURL=patron.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"patron.js","sources":["../src/Guest/GuestCallback.ts","../src/Patron/PatronPool.ts","../src/Guest/GuestPool.ts","../src/Guest/GuestInTheMiddle.ts","../src/Source/SourceOfValue.ts","../src/Guest/GuestChain.ts","../src/Guest/GuestSync.ts","../src/Guest/GuestCast.ts","../src/Guest/GuestAware.ts","../src/Guest/Guest.ts","../src/Patron/PatronOfGuest.ts","../src/Patron/PatronOnce.ts","../src/Patron/Patron.ts","../src/Source/SourcesApplied.ts","../src/Source/Source.ts","../src/index.ts"],"sourcesContent":["type GuestIntroduction = \"guest\" | \"patron\";\n\nexport interface ReceiveOptions {\n data?: unknown;\n}\n\nexport type GuestExecutorType<T> = (value: T, options?: ReceiveOptions) => void;\n\nexport interface GuestType<T = unknown> {\n receive(value: T, options?: ReceiveOptions): this;\n introduction?(): GuestIntroduction;\n}\n\nexport class GuestCallback<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 { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\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 interface PoolType<T = unknown> extends GuestType<T> {\n add(guest: GuestType<T>): this;\n distribute(receiving: T, possiblePatron: GuestType<T>): this;\n remove(patron: GuestType<T>): this;\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 \"../Patron/PatronPool\";\nimport { PoolType } from \"../Patron/PatronPool\";\nimport { GuestType, ReceiveOptions } from \"./GuestCallback\";\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 \"./GuestCallback\";\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 { GuestAwareType } from \"../Guest/GuestAware\";\nimport { GuestType } from \"../Guest/GuestCallback\";\nimport { PatronPool } from \"../Patron/PatronPool\";\n\nexport type SourceType<T = unknown> = GuestAwareType<T> & GuestType<T>;\n\nexport class SourceOfValue<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","import { GuestCallback, GuestType } from \"./GuestCallback\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestInTheMiddle } from \"./GuestInTheMiddle\";\nimport { SourceOfValue } from \"../Source/SourceOfValue\";\n\nexport interface ChainType<T = unknown> {\n result(guest: GuestType<T>): this;\n resultArray(guest: GuestType<T>): this;\n receiveKey<R>(key: string): GuestType<R>;\n}\n\nexport class GuestChain<T> implements ChainType<T> {\n private theChain: SourceOfValue<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 SourceOfValue<Record<string, unknown>>({});\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 GuestCallback((chain: Record<string, unknown>) => {\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 GuestCallback((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 GuestCallback((value) => {\n // Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей\n queueMicrotask(() => {\n this.theChain.receiving(\n new GuestCallback((chain: Record<string, unknown>) => {\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 { GuestType } from \"./GuestCallback\";\n\nexport interface GuestValueType<T = unknown> extends GuestType<T> {\n value(): T;\n}\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 \"./GuestCallback\";\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 { GuestType } from \"./GuestCallback\";\n\nexport interface GuestAwareType<T = unknown> {\n receiving(guest: GuestType<T>): unknown;\n}\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 {\n GuestCallback,\n GuestExecutorType,\n GuestType,\n ReceiveOptions,\n} from \"./GuestCallback\";\nimport { GuestChain } from \"./GuestChain\";\nimport { GuestCast } from \"./GuestCast\";\nimport { GuestInTheMiddle } from \"./GuestInTheMiddle\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestAware } from \"./GuestAware\";\nimport { GuestSync } from \"./GuestSync\";\n\nexport class Guest {\n public callback<P>(receiver: GuestExecutorType<P>) {\n return new GuestCallback(receiver);\n }\n\n public chain() {\n return new GuestChain();\n }\n\n public cast<P>(sourceGuest: GuestType<unknown>, targetGuest: GuestType<P>) {\n return new GuestCast(sourceGuest, targetGuest);\n }\n\n public middleware<P>(\n baseGuest: GuestType<unknown>,\n middleFn: (value: P, options?: ReceiveOptions) => void,\n ) {\n return new GuestInTheMiddle(baseGuest, middleFn);\n }\n\n public pool(initiator: unknown) {\n return new GuestPool(initiator);\n }\n\n public aware<P>(guestReceiver: (guest: GuestType<P>) => void) {\n return new GuestAware(guestReceiver);\n }\n\n public sync<P>(value: P) {\n return new GuestSync(value);\n }\n}\n","import { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\n\n/**\n * Патрон - это постоянный посетитель\n */\nexport class PatronOfGuest<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 { PoolType } from \"./PatronPool\";\nimport { GuestType, ReceiveOptions } from \"../Guest/GuestCallback\";\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 { PatronOfGuest } from \"./PatronOfGuest\";\nimport { GuestType } from \"../Guest/GuestCallback\";\nimport { PatronOnce } from \"./PatronOnce\";\nimport { PatronPool } from \"./PatronPool\";\n\nexport class Patron {\n public ofGuest<P>(willBePatron: GuestType<P>) {\n return new PatronOfGuest(willBePatron);\n }\n\n public once<P>(baseGuest: GuestType<P>) {\n return new PatronOnce(baseGuest);\n }\n\n public pool(initiator: unknown) {\n return new PatronPool(initiator);\n }\n}\n","type TupleSplit<\n T,\n N extends number,\n O extends readonly any[] = readonly [],\n> = O[\"length\"] extends N\n ? [O, T]\n : T extends readonly [infer F, ...infer R]\n ? TupleSplit<readonly [...R], N, readonly [...O, F]>\n : [O, T];\n\ntype SkipFirst<T extends readonly any[], N extends number> = TupleSplit<\n T,\n N\n>[1];\n\nexport const sourcesApplied = <T>(\n target: T,\n methodsSources: Record<string, unknown[]>,\n) => {\n return new Proxy(target as object, {\n get: function (target: any, property) {\n const maybeMethod = target[property];\n\n if (typeof maybeMethod !== \"function\") {\n return maybeMethod;\n }\n\n return (...args: any[]) => {\n const appliedArgs = (methodsSources as any)[property];\n\n if (appliedArgs) {\n return maybeMethod(...appliedArgs, ...args);\n }\n\n return maybeMethod(...args);\n };\n },\n });\n};\n","import { SourceOfValue } from \"./SourceOfValue\";\nimport { sourcesApplied } from \"./SourcesApplied\";\n\nexport class Source {\n public ofValue<P>(sourceDocument: P) {\n return new SourceOfValue(sourceDocument);\n }\n\n public applySources<P>(target: P, methodsSources: Record<string, unknown[]>) {\n return sourcesApplied(target, methodsSources);\n }\n}\n","export * from \"./Guest/GuestCallback\";\nexport * from \"./Guest/GuestChain\";\nexport * from \"./Guest/GuestSync\";\nexport * from \"./Patron/PatronPool\";\nexport * from \"./Source/SourceOfValue\";\n\nimport { Guest } from \"./Guest/Guest\";\nimport { Patron } from \"./Patron/Patron\";\nimport { Source } from \"./Source/Source\";\n\nexport { Guest, Patron, Source };\n\ndeclare var window: any;\n\nif (window) {\n window[\"GUEST_LIBRARY\"] = {\n guest: new Guest(),\n patron: new Patron(),\n source: new Source(),\n };\n}\n"],"names":["__publicField","target"],"mappings":";;AAaO,MAAM,aAAyC,CAAA;AAAA,EAC7C,YAAoB,QAAgC,EAAA;AAAhC,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA,CAAA;AAAA,GAAiC;AAAA,EAErD,OAAA,CAAQ,OAAU,OAA0B,EAAA;AACjD,IAAK,IAAA,CAAA,QAAA,CAAS,OAAO,OAAO,CAAA,CAAA;AAC5B,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AACF;;;;;AClBA,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;AAQO,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;A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Y,CAAA,GAAG,WAAa,EAAA,GAAG,IAAI,CAAA,CAAA;AAAA,SAC5C;AAEA,QAAO,OAAA,WAAA,CAAY,GAAG,IAAI,CAAA,CAAA;AAAA,OAC5B,CAAA;AAAA,KACF;AAAA,GACD,CAAA,CAAA;AACH,CAAA;;ACnCO,MAAM,MAAO,CAAA;AAAA,EACX,QAAW,cAAmB,EAAA;AACnC,IAAO,OAAA,IAAI,cAAc,cAAc,CAAA,CAAA;AAAA,GACzC;AAAA,EAEO,YAAA,CAAgB,QAAW,cAA2C,EAAA;AAC3E,IAAO,OAAA,cAAA,CAAe,QAAQ,cAAc,CAAA,CAAA;AAAA,GAC9C;AACF;;ACGA,IAAI,MAAQ,EAAA;AACV,EAAA,MAAA,CAAO,eAAe,CAAI,GAAA;AAAA,IACxB,KAAA,EAAO,IAAI,KAAM,EAAA;AAAA,IACjB,MAAA,EAAQ,IAAI,MAAO,EAAA;AAAA,IACnB,MAAA,EAAQ,IAAI,MAAO,EAAA;AAAA,GACrB,CAAA;AACF;;;;;;;;;;;;"}
1
+ {"version":3,"file":"patron.js","sources":["../src/Guest/Guest.ts","../src/Patron/PatronPool.ts","../src/Guest/GuestAware.ts","../src/Guest/GuestCast.ts","../src/Guest/GuestPool.ts","../src/Guest/GuestInTheMiddle.ts","../src/Source/Source.ts","../src/Guest/GuestChain.ts","../src/Guest/GuestSync.ts","../src/Patron/Patron.ts","../src/Patron/PatronOnce.ts","../src/index.ts"],"sourcesContent":["type GuestIntroduction = \"guest\" | \"patron\";\n\nexport interface ReceiveOptions {\n data?: unknown;\n}\n\nexport type GuestExecutorType<T = unknown> = (\n value: T,\n options?: ReceiveOptions,\n) => void;\n\nexport interface GuestObjectType<T = unknown> {\n receive(value: T, options?: ReceiveOptions): this;\n introduction?(): GuestIntroduction;\n}\n\nexport type GuestType<T = unknown> = GuestExecutorType<T> | GuestObjectType<T>;\n\nexport function give<T>(\n data: T,\n guest: GuestType<T>,\n options?: ReceiveOptions,\n) {\n if (typeof guest === \"function\") {\n guest(data, options);\n } else {\n guest.receive(data, options);\n }\n}\n\nexport class Guest<T> implements GuestObjectType<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 {\n give,\n GuestObjectType,\n GuestType,\n ReceiveOptions,\n} from \"../Guest/Guest\";\n\nconst poolSets = new Map<PoolType, Set<GuestObjectType>>();\n\n/**\n * Удалить патрон из всех пулов\n */\nexport const removePatronFromPools = (patron: GuestObjectType) => {\n poolSets.forEach((pool) => {\n pool.delete(patron);\n });\n};\n\nexport interface PoolType<T = unknown> extends GuestObjectType<T> {\n add(guest: GuestObjectType<T>): this;\n distribute(receiving: T, possiblePatron: GuestObjectType<T>): this;\n remove(patron: GuestObjectType<T>): this;\n}\n\nexport class PatronPool<T> implements PoolType<T> {\n private patrons = new Set<GuestObjectType<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 typeof shouldBePatron !== \"function\" &&\n shouldBePatron.introduction &&\n shouldBePatron.introduction() === \"patron\"\n ) {\n this.patrons.add(shouldBePatron);\n }\n return this;\n }\n\n public remove(patron: GuestObjectType<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 give(value, guest, {\n ...options,\n data: {\n ...((options?.data as Record<string, unknown>) ?? {}),\n initiator: this.initiator,\n pool: this,\n },\n });\n }\n}\n","import { GuestType } from \"./Guest\";\n\nexport interface GuestAwareType<T = unknown> {\n receiving(guest: GuestType<T>): unknown;\n}\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 { give, GuestObjectType, GuestType, ReceiveOptions } from \"./Guest\";\n\nexport class GuestCast<T> implements GuestObjectType<T> {\n public constructor(\n private sourceGuest: GuestType<unknown>,\n private targetGuest: GuestType<T>,\n ) {}\n\n introduction() {\n if (typeof this.sourceGuest === \"function\") {\n return \"guest\";\n }\n\n if (!this.sourceGuest.introduction) {\n return \"guest\";\n }\n return this.sourceGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n give(value, this.targetGuest, options);\n return this;\n }\n}\n","import { PatronPool } from \"../Patron/PatronPool\";\nimport { PoolType } from \"../Patron/PatronPool\";\nimport { give, GuestObjectType, GuestType, ReceiveOptions } from \"./Guest\";\n\nexport class GuestPool<T> implements GuestObjectType<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 (\n typeof guest === \"function\" ||\n !guest.introduction ||\n guest.introduction() === \"guest\"\n ) {\n this.guests.add(guest);\n }\n this.patronPool.add(guest);\n return this;\n }\n\n public remove(patron: GuestObjectType<T>): this {\n this.guests.delete(patron);\n this.patronPool.remove(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestObjectType<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 give(value, target, options);\n });\n this.guests.clear();\n }\n}\n","import { GuestObjectType, ReceiveOptions } from \"./Guest\";\n\nexport class GuestInTheMiddle<T> implements GuestObjectType<T> {\n public constructor(\n private baseGuest: GuestObjectType<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 { GuestAwareType } from \"../Guest/GuestAware\";\nimport { Guest, GuestObjectType, GuestType } from \"../Guest/Guest\";\nimport { PatronPool } from \"../Patron/PatronPool\";\n\nexport type SourceType<T = unknown> = GuestAwareType<T> & GuestObjectType<T>;\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 if (typeof guest === \"function\") {\n this.pool.distribute(this.sourceDocument, new Guest(guest));\n } else {\n this.pool.distribute(this.sourceDocument, guest);\n }\n return this;\n }\n}\n","import { Guest, GuestObjectType } from \"./Guest\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestInTheMiddle } from \"./GuestInTheMiddle\";\nimport { Source } from \"../Source/Source\";\n\nexport interface ChainType<T = unknown> {\n result(guest: GuestObjectType<T>): this;\n resultArray(guest: GuestObjectType<T>): this;\n receiveKey<R>(key: string): GuestObjectType<R>;\n}\n\nexport class GuestChain<T> implements ChainType<T> {\n private theChain: Source<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 Source<Record<string, unknown>>({});\n }\n\n public resultArray(guest: GuestObjectType<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: Record<string, unknown>) => {\n this.filledChainPool.receive(Object.values(chain));\n }),\n );\n }\n\n return this;\n }\n\n public result(guest: GuestObjectType<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): GuestObjectType<R> {\n this.keysKnown.add(key);\n return new Guest((value) => {\n // Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей\n queueMicrotask(() => {\n this.theChain.receiving(\n new Guest((chain: Record<string, unknown>) => {\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 { GuestObjectType } from \"./Guest\";\n\nexport interface GuestValueType<T = unknown> extends GuestObjectType<T> {\n value(): T;\n}\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 {\n give,\n GuestObjectType,\n GuestType,\n ReceiveOptions,\n} from \"../Guest/Guest\";\n\n/**\n * Патрон - это постоянный посетитель\n */\nexport class Patron<T> implements GuestObjectType<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 give(value, this.willBePatron, options);\n return this;\n }\n}\n","import { PoolType } from \"./PatronPool\";\nimport {\n give,\n GuestObjectType,\n GuestType,\n ReceiveOptions,\n} from \"../Guest/Guest\";\n\ntype PoolAware = {\n pool?: PoolType;\n};\n\nexport class PatronOnce<T> implements GuestObjectType<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 give(value, this.baseGuest, 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 { give, Guest } from \"./Guest/Guest\";\nimport { PatronPool, removePatronFromPools } from \"./Patron/PatronPool\";\nimport { GuestAware } from \"./Guest/GuestAware\";\nimport { GuestCast } from \"./Guest/GuestCast\";\nimport { GuestChain } from \"./Guest/GuestChain\";\nimport { GuestInTheMiddle } from \"./Guest/GuestInTheMiddle\";\nimport { GuestPool } from \"./Guest/GuestPool\";\nimport { GuestSync } from \"./Guest/GuestSync\";\nimport { Patron } from \"./Patron/Patron\";\nimport { PatronOnce } from \"./Patron/PatronOnce\";\nimport { Source } from \"./Source/Source\";\n\nexport * from \"./Guest/GuestAware\";\nexport * from \"./Guest/Guest\";\nexport * from \"./Guest/GuestCast\";\nexport * from \"./Guest/GuestChain\";\nexport * from \"./Guest/GuestInTheMiddle\";\nexport * from \"./Guest/GuestPool\";\nexport * from \"./Guest/GuestSync\";\nexport * from \"./Patron/Patron\";\nexport * from \"./Patron/PatronOnce\";\nexport * from \"./Patron/PatronPool\";\nexport * from \"./Source/Source\";\n\ndeclare var globalThis: any;\n\nif (globalThis) {\n globalThis[\"GUEST_LIBRARY\"] = {\n give,\n removePatronFromPools,\n GuestAware,\n Guest,\n GuestCast,\n GuestChain,\n GuestInTheMiddle,\n GuestPool,\n GuestSync,\n Patron,\n PatronOnce,\n PatronPool,\n Source,\n };\n}\n"],"names":["__publicField"],"mappings":";;AAkBgB,SAAA,IAAA,CACd,IACA,EAAA,KAAA,EACA,OACA,EAAA;AACA,EAAI,IAAA,OAAO,UAAU,UAAY,EAA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