@fabriktor/fx 0.0.157 → 0.0.159

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.
@@ -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?;
@@ -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;
@@ -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 mutating;
203
+ private readonly mutations;
204
204
  private feed;
205
205
  private storage_fx;
206
206
  private keep_alive_interval_ms;
@@ -3,10 +3,11 @@
3
3
  // Licensed under the Apache License, Version 2.0 (the "License"); you may
4
4
  // not use this file except in compliance with the License. You may obtain
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- import { All, PullTypeBatch, PullTypeSingle, PullTypeResearch, PullTypeReplies, PullTypeReferences, PullTypeReactions, PullTypeProfilePosts, PullTypeProfileReplies, PullTypeProfileMedias, FeedLike, FeedDislike, FeedReport, PullTypeKeepAlive, ZeroID, } from "@fabriktor/schema";
6
+ import { All, PullTypeBatch, PullTypeSingle, PullTypeResearch, PullTypeReplies, PullTypeReferences, PullTypeReactions, PullTypeProfilePosts, PullTypeProfileReplies, PullTypeProfileMedias, PullTypeProfileReferences, FeedLike, FeedDislike, FeedReport, PullTypeKeepAlive, ZeroID, } from "@fabriktor/schema";
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
- mutating = false;
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.mutating = true;
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);
@@ -323,6 +313,7 @@ export class FeedFX {
323
313
  PullTypeProfilePosts,
324
314
  PullTypeProfileReplies,
325
315
  PullTypeProfileMedias,
316
+ PullTypeProfileReferences,
326
317
  ];
327
318
  if (!supported.includes(input.pull_type))
328
319
  throw errValidation({
@@ -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 mutating;
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
- mutating = false;
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.mutating = true;
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.157",
3
+ "version": "0.0.159",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {
@@ -19,7 +19,7 @@
19
19
  "dependencies": {
20
20
  "@fabriktor/client": "0.0.101",
21
21
  "@fabriktor/fx": "0.0.94",
22
- "@fabriktor/schema": "0.0.70",
22
+ "@fabriktor/schema": "0.0.71",
23
23
  "convert": "8.0.2"
24
24
  }
25
25
  }