@fabriktor/fx 0.0.190 → 0.0.192
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/chat/optimistic.js +22 -5
- package/dist/src/chat/send-queue.d.ts +1 -1
- package/dist/src/chat/send-queue.js +20 -2
- package/dist/src/contacts/contacts.d.ts +6 -0
- package/dist/src/contacts/contacts.js +14 -2
- package/dist/src/fx.js +1 -0
- package/dist/src/users/profile.js +5 -2
- package/dist/src/users/users.js +2 -2
- package/package.json +1 -1
|
@@ -55,19 +55,36 @@ export function projectQueuedChats(chats, snapshot, ownerID, roomID) {
|
|
|
55
55
|
const sequences = new Map(entries
|
|
56
56
|
.filter((entry) => entry.server_id && entry.sequence !== undefined)
|
|
57
57
|
.map((entry) => [entry.server_id, entry.sequence]));
|
|
58
|
+
let afterPending = 0;
|
|
58
59
|
for (const entry of entries) {
|
|
59
60
|
// A room event may arrive before this entry's independent confirmation
|
|
60
61
|
// read. Match the server ID so identical messages remain distinct.
|
|
61
62
|
if (!entry.chat && (!entry.server_id || !confirmed.has(entry.server_id))) {
|
|
62
63
|
// Out-of-order reads must not move a later outgoing bubble ahead of an
|
|
63
64
|
// earlier pending one. Canonical messages keep their server ordering.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
let after = afterPending;
|
|
66
|
+
for (let index = after; index < result.length; index++) {
|
|
67
|
+
const sequence = sequences.get(result[index].id) ??
|
|
68
|
+
snapshot.confirmed_sequences?.[result[index].id];
|
|
69
|
+
if (sequence !== undefined &&
|
|
67
70
|
entry.sequence !== undefined &&
|
|
68
|
-
sequence
|
|
71
|
+
sequence < entry.sequence)
|
|
72
|
+
after = index + 1;
|
|
73
|
+
}
|
|
74
|
+
const before = result.findIndex((chat, index) => {
|
|
75
|
+
if (index < after)
|
|
76
|
+
return false;
|
|
77
|
+
const sequence = sequences.get(chat.id) ?? snapshot.confirmed_sequences?.[chat.id];
|
|
78
|
+
if (sequence !== undefined && entry.sequence !== undefined) {
|
|
79
|
+
return sequence > entry.sequence;
|
|
80
|
+
}
|
|
81
|
+
// Completed entries are no longer in the durable queue after a reload.
|
|
82
|
+
// Keep unresolved messages at their original time, not at the live tail.
|
|
83
|
+
return (Date.parse(chat.created_at) > Date.parse(entry.optimistic.created_at));
|
|
69
84
|
});
|
|
70
|
-
|
|
85
|
+
const index = before < 0 ? result.length : before;
|
|
86
|
+
result.splice(index, 0, entry.optimistic);
|
|
87
|
+
afterPending = index + 1;
|
|
71
88
|
}
|
|
72
89
|
}
|
|
73
90
|
return result.length === chats.length &&
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ChatOperator } from "@fabriktor/client";
|
|
2
2
|
import type { Chat, InChat } from "@fabriktor/schema";
|
|
3
3
|
import { type EventListener } from "../core/events.js";
|
|
4
4
|
import { type QueueRetry, type QueueStore, type QueueLock } from "../core/queue.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ClientErrKind, isClientErr, } from "@fabriktor/client";
|
|
1
2
|
import { requiredOperationID } from "../core/id.js";
|
|
2
3
|
import { createEvent, EventBus, notifyObserver, } from "../core/events.js";
|
|
3
4
|
import { PersistentQueue, QueueWakeup, nextQueueRetry, } from "../core/queue.js";
|
|
@@ -438,6 +439,8 @@ export class ChatSendQueue {
|
|
|
438
439
|
// lock coordinates retries/recovery across tabs without holding later POSTs.
|
|
439
440
|
startConfirmation(entry, owner, signal) {
|
|
440
441
|
const known = entry.server_id && this.confirmed.get(entry.server_id);
|
|
442
|
+
if (!known && this.waitForRetry(entry))
|
|
443
|
+
return;
|
|
441
444
|
if (this.confirmations.has(entry.id) ||
|
|
442
445
|
(!known && this.opts.online?.() === false)) {
|
|
443
446
|
return;
|
|
@@ -455,6 +458,8 @@ export class ChatSendQueue {
|
|
|
455
458
|
(!chatSendCanConfirm(stored) && !this.confirmed.has(stored.server_id))) {
|
|
456
459
|
return;
|
|
457
460
|
}
|
|
461
|
+
if (!this.confirmed.has(stored.server_id) && this.waitForRetry(stored))
|
|
462
|
+
return;
|
|
458
463
|
let current = stored;
|
|
459
464
|
try {
|
|
460
465
|
const chat = this.confirmed.get(current.server_id) ??
|
|
@@ -500,15 +505,20 @@ export class ChatSendQueue {
|
|
|
500
505
|
catch (error) {
|
|
501
506
|
if (this.current(owner, signal))
|
|
502
507
|
this.report(error);
|
|
508
|
+
const retry = !signal.aborted && !current.chat && retryableConfirmation(error)
|
|
509
|
+
? nextQueueRetry(current.retry)
|
|
510
|
+
: undefined;
|
|
503
511
|
await this.save({
|
|
504
512
|
...current,
|
|
505
|
-
retry
|
|
513
|
+
retry,
|
|
506
514
|
status: current.chat
|
|
507
515
|
? ChatSendStatus.UploadInterrupted
|
|
508
516
|
: signal.aborted
|
|
509
517
|
? ChatSendStatus.Interrupted
|
|
510
518
|
: ChatSendStatus.Failed,
|
|
511
519
|
});
|
|
520
|
+
if (retry && this.current(owner, signal))
|
|
521
|
+
this.scheduleRecovery(retry.after);
|
|
512
522
|
}
|
|
513
523
|
})
|
|
514
524
|
.catch((err) => {
|
|
@@ -723,7 +733,15 @@ function chatSendCanConfirm(entry) {
|
|
|
723
733
|
(entry.status === ChatSendStatus.Confirming ||
|
|
724
734
|
entry.status === ChatSendStatus.Sending ||
|
|
725
735
|
entry.status === ChatSendStatus.Queued ||
|
|
726
|
-
entry.status === ChatSendStatus.Interrupted
|
|
736
|
+
entry.status === ChatSendStatus.Interrupted ||
|
|
737
|
+
(entry.status === ChatSendStatus.Failed && !!entry.retry)));
|
|
738
|
+
}
|
|
739
|
+
function retryableConfirmation(error) {
|
|
740
|
+
return (isClientErr(error) &&
|
|
741
|
+
(error.kind === ClientErrKind.HTTPRequestFailed ||
|
|
742
|
+
error.status === 408 ||
|
|
743
|
+
error.status === 429 ||
|
|
744
|
+
(error.status !== undefined && error.status >= 500)));
|
|
727
745
|
}
|
|
728
746
|
export function chatSendNeedsRetry(entry) {
|
|
729
747
|
return (entry.status === ChatSendStatus.Failed ||
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type ContactsOperator, type UsersOperator } from "@fabriktor/client";
|
|
2
2
|
import { Friend, Hired, Manager, Na, OldHire, type Contact, type ID, type OperationResult, type User } from "@fabriktor/schema";
|
|
3
3
|
import { PollScheduler } from "../core/poll.js";
|
|
4
|
+
import { EventBus } from "../core/events.js";
|
|
5
|
+
export declare const ContactsEvents: {
|
|
6
|
+
readonly Changed: import("../index.js").EventKey<void>;
|
|
7
|
+
};
|
|
4
8
|
type ContactInsertOptions = Parameters<ContactsOperator["insertOneContact"]>[0];
|
|
5
9
|
type ContactReplaceOptions = Parameters<ContactsOperator["replaceOneContact"]>[0];
|
|
6
10
|
export type CreateContactOptions = ContactInsertOptions;
|
|
@@ -11,6 +15,7 @@ export type ContactsFXOptions = {
|
|
|
11
15
|
contacts: ContactsOperator;
|
|
12
16
|
users: UsersOperator;
|
|
13
17
|
polling?: PollScheduler;
|
|
18
|
+
events?: EventBus;
|
|
14
19
|
};
|
|
15
20
|
export type LoadContactIndexOptions = {
|
|
16
21
|
owner_id: string;
|
|
@@ -76,6 +81,7 @@ export declare class ContactsFX implements ContactsFXOperator {
|
|
|
76
81
|
private contacts;
|
|
77
82
|
private users;
|
|
78
83
|
private readonly polling;
|
|
84
|
+
private readonly events;
|
|
79
85
|
constructor(opts: ContactsFXOptions);
|
|
80
86
|
createContact(opts: CreateContactOptions): Promise<Contact>;
|
|
81
87
|
replaceContact(opts: ReplaceContactOptions): Promise<Contact>;
|
|
@@ -5,6 +5,10 @@ import { normalizeIDs, requiredOperationID } from "../core/id.js";
|
|
|
5
5
|
import { mergeRecordsByID } from "../core/scope.js";
|
|
6
6
|
import { runSearch } from "../core/search.js";
|
|
7
7
|
import { PollScheduler } from "../core/poll.js";
|
|
8
|
+
import { createEvent, EventBus } from "../core/events.js";
|
|
9
|
+
export const ContactsEvents = {
|
|
10
|
+
Changed: createEvent(),
|
|
11
|
+
};
|
|
8
12
|
const employmentUserBatchSize = 30;
|
|
9
13
|
const resourceContact = "contact";
|
|
10
14
|
const msgCreatedContactIDMissing = "Created contact response did not contain an ID.";
|
|
@@ -19,18 +23,22 @@ export class ContactsFX {
|
|
|
19
23
|
contacts;
|
|
20
24
|
users;
|
|
21
25
|
polling;
|
|
26
|
+
events;
|
|
22
27
|
constructor(opts) {
|
|
23
28
|
this.contacts = opts.contacts;
|
|
24
29
|
this.users = opts.users;
|
|
25
30
|
this.polling = opts.polling ?? new PollScheduler();
|
|
31
|
+
this.events = opts.events ?? new EventBus();
|
|
26
32
|
}
|
|
27
33
|
async createContact(opts) {
|
|
28
34
|
const out = await this.contacts.insertOneContact(opts);
|
|
35
|
+
this.events.publish(ContactsEvents.Changed, undefined);
|
|
29
36
|
const id = requiredOperationID(out, msgCreatedContactIDMissing);
|
|
30
37
|
return await this.findContact(id);
|
|
31
38
|
}
|
|
32
39
|
async replaceContact(opts) {
|
|
33
40
|
await this.contacts.replaceOneContact(opts);
|
|
41
|
+
this.events.publish(ContactsEvents.Changed, undefined);
|
|
34
42
|
return await this.findContact(opts.id);
|
|
35
43
|
}
|
|
36
44
|
async loadContactIndex(opts) {
|
|
@@ -162,7 +170,7 @@ export class ContactsFX {
|
|
|
162
170
|
msg: msgContactIDRequired,
|
|
163
171
|
});
|
|
164
172
|
}
|
|
165
|
-
|
|
173
|
+
const out = await this.contacts.insertOneContact({
|
|
166
174
|
in: {
|
|
167
175
|
contact_id,
|
|
168
176
|
is_pending: true,
|
|
@@ -171,6 +179,8 @@ export class ContactsFX {
|
|
|
171
179
|
is_archived: false,
|
|
172
180
|
},
|
|
173
181
|
});
|
|
182
|
+
this.events.publish(ContactsEvents.Changed, undefined);
|
|
183
|
+
return out;
|
|
174
184
|
}
|
|
175
185
|
async requestRelationUpgrade(opts) {
|
|
176
186
|
if (opts.requested_relation <= opts.contact.relation) {
|
|
@@ -228,7 +238,7 @@ export class ContactsFX {
|
|
|
228
238
|
});
|
|
229
239
|
}
|
|
230
240
|
async replaceContactResult(contact, overrides) {
|
|
231
|
-
|
|
241
|
+
const out = await this.contacts.replaceOneContact({
|
|
232
242
|
id: contact.id,
|
|
233
243
|
in: {
|
|
234
244
|
contact_id: contact.contact_id,
|
|
@@ -239,6 +249,8 @@ export class ContactsFX {
|
|
|
239
249
|
...overrides,
|
|
240
250
|
},
|
|
241
251
|
});
|
|
252
|
+
this.events.publish(ContactsEvents.Changed, undefined);
|
|
253
|
+
return out;
|
|
242
254
|
}
|
|
243
255
|
async usersByIDs(uid, ids) {
|
|
244
256
|
const values = normalizeIDs(ids);
|
package/dist/src/fx.js
CHANGED
|
@@ -89,10 +89,13 @@ export function bannerCrop(width, height, frame) {
|
|
|
89
89
|
export function moveBannerFrame(width, height, frame, dx, dy, viewportWidth) {
|
|
90
90
|
const crop = bannerCrop(width, height, frame);
|
|
91
91
|
const scale = crop.width / Math.max(1, viewportWidth);
|
|
92
|
+
const travelX = width - crop.width;
|
|
93
|
+
const travelY = height - crop.height;
|
|
92
94
|
const clamp = (value) => Math.min(1, Math.max(0, value));
|
|
95
|
+
// A fitted axis (including subpixel overflow) has no visible travel.
|
|
93
96
|
return {
|
|
94
97
|
...frame,
|
|
95
|
-
x: clamp(frame.x - (dx * scale) /
|
|
96
|
-
y: clamp(frame.y - (dy * scale) /
|
|
98
|
+
x: travelX > scale ? clamp(frame.x - (dx * scale) / travelX) : frame.x,
|
|
99
|
+
y: travelY > scale ? clamp(frame.y - (dy * scale) / travelY) : frame.y,
|
|
97
100
|
};
|
|
98
101
|
}
|
package/dist/src/users/users.js
CHANGED
|
@@ -8,9 +8,9 @@ import { normalizeEmail, isValidEmail } from "./email.js";
|
|
|
8
8
|
import { validUserPicturePreview } from "./picture.js";
|
|
9
9
|
import { normalizeUsername, validateUsernameFormat } from "./username.js";
|
|
10
10
|
import { userCardInput, normalizeUserCardInput, validateUserCardInput, } from "./profile.js";
|
|
11
|
-
const msgProfileRequired = "A valid account is required to update the public
|
|
11
|
+
const msgProfileRequired = "A valid account is required to update the public card.";
|
|
12
12
|
const msgPublicUserRequired = "A valid user is required.";
|
|
13
|
-
const msgPublicUserMissing = "Public
|
|
13
|
+
const msgPublicUserMissing = "Public card could not be resolved.";
|
|
14
14
|
const msgPictureRequired = "A valid account and profile preview are required.";
|
|
15
15
|
const msgUnableToResolveUsername = "Unable to resolve username.";
|
|
16
16
|
const msgPhoneRequired = "Phone number is required.";
|