@fabriktor/fx 0.0.157 → 0.0.158
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/dist/src/core/queue.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export type QueueRetry = {
|
|
|
7
7
|
attempts: number;
|
|
8
8
|
after: number;
|
|
9
9
|
};
|
|
10
|
+
export declare class MutationQueue {
|
|
11
|
+
private pending;
|
|
12
|
+
run<T>(signal: AbortSignal, fn: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
13
|
+
}
|
|
10
14
|
export declare function nextQueueRetry(previous?: QueueRetry): QueueRetry;
|
|
11
15
|
export declare class QueueWakeup {
|
|
12
16
|
private pending?;
|
package/dist/src/core/queue.js
CHANGED
|
@@ -5,6 +5,20 @@
|
|
|
5
5
|
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
6
|
const queueRetryInitialMilliseconds = 1_000;
|
|
7
7
|
const queueRetryMaximumMilliseconds = 30_000;
|
|
8
|
+
// In-memory mutations stay sequential while unrelated UI remains interactive.
|
|
9
|
+
export class MutationQueue {
|
|
10
|
+
pending = Promise.resolve();
|
|
11
|
+
run(signal, fn) {
|
|
12
|
+
const result = this.pending.then(async () => {
|
|
13
|
+
signal.throwIfAborted();
|
|
14
|
+
const value = await fn(signal);
|
|
15
|
+
signal.throwIfAborted();
|
|
16
|
+
return value;
|
|
17
|
+
});
|
|
18
|
+
this.pending = result.catch(() => undefined);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
8
22
|
// Durable deadlines prevent refreshes and other tabs from bypassing backoff.
|
|
9
23
|
export function nextQueueRetry(previous) {
|
|
10
24
|
const attempts = (previous?.attempts ?? 0) + 1;
|
package/dist/src/feed/feed.d.ts
CHANGED
|
@@ -200,7 +200,7 @@ export interface FeedFXOperator {
|
|
|
200
200
|
export declare class FeedFX implements FeedFXOperator {
|
|
201
201
|
private readonly sessions;
|
|
202
202
|
private readonly events;
|
|
203
|
-
private
|
|
203
|
+
private readonly mutations;
|
|
204
204
|
private feed;
|
|
205
205
|
private storage_fx;
|
|
206
206
|
private keep_alive_interval_ms;
|
package/dist/src/feed/feed.js
CHANGED
|
@@ -7,6 +7,7 @@ import { All, PullTypeBatch, PullTypeSingle, PullTypeResearch, PullTypeReplies,
|
|
|
7
7
|
import { isClientErr, queryParams, } from "@fabriktor/client";
|
|
8
8
|
import { errResolveFailed, errValidation, errUnconfirmedMutation, } from "../core/err.js";
|
|
9
9
|
import { requiredOperationID, resolvedID } from "../core/id.js";
|
|
10
|
+
import { MutationQueue } from "../core/queue.js";
|
|
10
11
|
import { startPullSession, PullSessionScope, } from "../core/pull.js";
|
|
11
12
|
import { runOwnerSearch, } from "../core/search.js";
|
|
12
13
|
import { validateStorageUploadFiles, } from "../storage/storage.js";
|
|
@@ -32,7 +33,6 @@ const msgCreatedFeedReactionIDMissing = "Created feed reaction response did not
|
|
|
32
33
|
const msgFeedReactionResolveMissing = "Feed reaction could not be resolved after the mutation.";
|
|
33
34
|
const msgCreatedFeedFavoriteIDMissing = "Created feed favorite response did not contain an ID.";
|
|
34
35
|
const msgFeedFavoriteResolveMissing = "Feed favorite could not be resolved after the mutation.";
|
|
35
|
-
const msgFeedActionInProgress = "This feed action is already in progress for the post.";
|
|
36
36
|
const msgFeedReactionAlreadyExists = "A reaction already exists for this post.";
|
|
37
37
|
const msgFeedReactionMissing = "No reaction exists for this post.";
|
|
38
38
|
const msgFeedFavoriteAlreadyExists = "A favorite already exists for this post.";
|
|
@@ -59,7 +59,7 @@ export const FeedMediaPostStatus = {
|
|
|
59
59
|
export class FeedFX {
|
|
60
60
|
sessions = new PullSessionScope();
|
|
61
61
|
events;
|
|
62
|
-
|
|
62
|
+
mutations = new MutationQueue();
|
|
63
63
|
feed;
|
|
64
64
|
storage_fx;
|
|
65
65
|
keep_alive_interval_ms;
|
|
@@ -280,19 +280,9 @@ export class FeedFX {
|
|
|
280
280
|
this.events.publish(FeedEvents.Changed, { post_id });
|
|
281
281
|
}
|
|
282
282
|
async mutate(fn, parent) {
|
|
283
|
-
if (this.mutating)
|
|
284
|
-
throw errValidation({ msg: msgFeedActionInProgress });
|
|
285
283
|
const signal = this.sessions.signal(parent);
|
|
286
284
|
signal.throwIfAborted();
|
|
287
|
-
this.
|
|
288
|
-
try {
|
|
289
|
-
const result = await fn(signal);
|
|
290
|
-
signal.throwIfAborted();
|
|
291
|
-
return result;
|
|
292
|
-
}
|
|
293
|
-
finally {
|
|
294
|
-
this.mutating = false;
|
|
295
|
-
}
|
|
285
|
+
return this.mutations.run(signal, fn);
|
|
296
286
|
}
|
|
297
287
|
async createFeedReaction(opts) {
|
|
298
288
|
const out = await this.feed.insertOneFeedReaction(opts);
|
|
@@ -87,7 +87,7 @@ export interface MarketplaceFXOperator {
|
|
|
87
87
|
export declare class MarketplaceFX implements MarketplaceFXOperator {
|
|
88
88
|
private readonly sessions;
|
|
89
89
|
private readonly events;
|
|
90
|
-
private
|
|
90
|
+
private readonly mutations;
|
|
91
91
|
private marketplace;
|
|
92
92
|
private keep_alive_interval_ms;
|
|
93
93
|
constructor(opts: MarketplaceFXOptions);
|
|
@@ -7,6 +7,7 @@ import { isClientErr, queryParams, } from "@fabriktor/client";
|
|
|
7
7
|
import { PullTypeBatch, PullTypeKeepAlive, PullTypeResearch, PullTypeSingle, OwnerIDKey, } from "@fabriktor/schema";
|
|
8
8
|
import { errRequired, errResolveFailed, errValidation, errUnconfirmedMutation, } from "../core/err.js";
|
|
9
9
|
import { requiredOperationID, resolvedID } from "../core/id.js";
|
|
10
|
+
import { MutationQueue } from "../core/queue.js";
|
|
10
11
|
import { startPullSession, PullSessionScope, } from "../core/pull.js";
|
|
11
12
|
import { runOwnerSearch, } from "../core/search.js";
|
|
12
13
|
import { createEvent, EventBus, notifyObserver } from "../core/events.js";
|
|
@@ -34,7 +35,7 @@ const msgMarketplaceCountryRequired = "Country is required for marketplace welco
|
|
|
34
35
|
export class MarketplaceFX {
|
|
35
36
|
sessions = new PullSessionScope();
|
|
36
37
|
events;
|
|
37
|
-
|
|
38
|
+
mutations = new MutationQueue();
|
|
38
39
|
marketplace;
|
|
39
40
|
keep_alive_interval_ms;
|
|
40
41
|
constructor(opts) {
|
|
@@ -334,21 +335,9 @@ export class MarketplaceFX {
|
|
|
334
335
|
});
|
|
335
336
|
}
|
|
336
337
|
async mutate(fn, parent) {
|
|
337
|
-
if (this.mutating)
|
|
338
|
-
throw errValidation({
|
|
339
|
-
msg: "A Marketplace action is already in progress.",
|
|
340
|
-
});
|
|
341
338
|
const signal = this.sessions.signal(parent);
|
|
342
339
|
signal.throwIfAborted();
|
|
343
|
-
this.
|
|
344
|
-
try {
|
|
345
|
-
const result = await fn(signal);
|
|
346
|
-
signal.throwIfAborted();
|
|
347
|
-
return result;
|
|
348
|
-
}
|
|
349
|
-
finally {
|
|
350
|
-
this.mutating = false;
|
|
351
|
-
}
|
|
340
|
+
return this.mutations.run(signal, fn);
|
|
352
341
|
}
|
|
353
342
|
requireID(value) {
|
|
354
343
|
const id = resolvedID(value);
|