@fabriktor/fx 0.0.155 → 0.0.156
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/feed/feed.d.ts
CHANGED
package/dist/src/feed/feed.js
CHANGED
|
@@ -11,7 +11,7 @@ import { startPullSession, PullSessionScope, } from "../core/pull.js";
|
|
|
11
11
|
import { runOwnerSearch, } from "../core/search.js";
|
|
12
12
|
import { validateStorageUploadFiles, } from "../storage/storage.js";
|
|
13
13
|
import { createEvent, EventBus } from "../core/events.js";
|
|
14
|
-
import { prepareFeedTextPost, validateFeedVisibility, feedPostInput, } from "./validation.js";
|
|
14
|
+
import { prepareFeedTextPost, validateFeedVisibility, feedPostInput, checkFeedPostVersion, } from "./validation.js";
|
|
15
15
|
export * from "./validation.js";
|
|
16
16
|
export * from "./media.js";
|
|
17
17
|
import { saveFeedPost, newFeedPostSaveState, } from "./media.js";
|
|
@@ -150,7 +150,7 @@ export class FeedFX {
|
|
|
150
150
|
async replaceFeedPost(opts) {
|
|
151
151
|
return this.mutate(async (signal) => {
|
|
152
152
|
const current = await this.findFeedPost(opts.id, signal);
|
|
153
|
-
|
|
153
|
+
checkFeedPostVersion(current, opts.expected);
|
|
154
154
|
// Text editing preserves link identity and cannot overwrite stored media.
|
|
155
155
|
const input = prepareFeedTextPost({
|
|
156
156
|
...feedPostInput(current),
|
|
@@ -246,7 +246,7 @@ export class FeedFX {
|
|
|
246
246
|
async deleteFeedPost(opts) {
|
|
247
247
|
return this.mutate(async (signal) => {
|
|
248
248
|
const current = await this.findFeedPost(requireFeedID(opts.record.id), signal);
|
|
249
|
-
|
|
249
|
+
checkFeedPostVersion(current, {
|
|
250
250
|
...opts.record,
|
|
251
251
|
owner_id: requireFeedID(opts.owner_id),
|
|
252
252
|
});
|
|
@@ -267,15 +267,6 @@ export class FeedFX {
|
|
|
267
267
|
this.changed("");
|
|
268
268
|
});
|
|
269
269
|
}
|
|
270
|
-
checkVersion(current, expected) {
|
|
271
|
-
if (expected &&
|
|
272
|
-
(current.owner_id !== expected.owner_id ||
|
|
273
|
-
current.updated_at !== expected.updated_at))
|
|
274
|
-
throw errValidation({
|
|
275
|
-
field: "updated_at",
|
|
276
|
-
msg: "Reload the post before changing it.",
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
270
|
async requireFeedPost(id, signal) {
|
|
280
271
|
const post = await this.readFeedPost({ id, signal });
|
|
281
272
|
if (!post)
|
package/dist/src/feed/media.js
CHANGED
|
@@ -9,7 +9,7 @@ import { errResolveFailed, errValidation, errUnconfirmedMutation, } from "../cor
|
|
|
9
9
|
import { notifyObserver } from "../core/events.js";
|
|
10
10
|
import { requiredOperationID, resolvedID } from "../core/id.js";
|
|
11
11
|
import { validateStorageUploadFiles, } from "../storage/storage.js";
|
|
12
|
-
import { feedPostInput, validateFeedVisibility } from "./validation.js";
|
|
12
|
+
import { feedPostInput, validateFeedVisibility, checkFeedPostVersion, } from "./validation.js";
|
|
13
13
|
export function newFeedPostSaveState() {
|
|
14
14
|
return {
|
|
15
15
|
create_key: newIdempotencyKey(),
|
|
@@ -66,7 +66,7 @@ export async function saveFeedPost(deps, opts) {
|
|
|
66
66
|
if (!state.post_id) {
|
|
67
67
|
if (expected) {
|
|
68
68
|
const current = await own(expected.id);
|
|
69
|
-
|
|
69
|
+
checkFeedPostVersion(current, expected);
|
|
70
70
|
state.original = current;
|
|
71
71
|
state.post_id = current.id;
|
|
72
72
|
}
|
|
@@ -155,7 +155,7 @@ export async function saveFeedPost(deps, opts) {
|
|
|
155
155
|
if (!state.patched) {
|
|
156
156
|
if (!state.input) {
|
|
157
157
|
const current = await own(id);
|
|
158
|
-
|
|
158
|
+
checkFeedPostVersion(current, original);
|
|
159
159
|
const base = feedPostInput(original);
|
|
160
160
|
const retained = original.objects.filter((object) => draft.retained_urls.includes(object.public_url));
|
|
161
161
|
let attachments = retained;
|
|
@@ -235,7 +235,7 @@ export async function saveFeedPost(deps, opts) {
|
|
|
235
235
|
if (state.patch_attempted && matchesInput(current, state.input))
|
|
236
236
|
state.patched = true;
|
|
237
237
|
else {
|
|
238
|
-
|
|
238
|
+
checkFeedPostVersion(current, original);
|
|
239
239
|
stage("publish");
|
|
240
240
|
opts.before_request?.();
|
|
241
241
|
state.patch_attempted = true;
|
|
@@ -306,14 +306,6 @@ function prepareDraft(draft, editing = false) {
|
|
|
306
306
|
is_uploading: !editing && !!draft.files.length,
|
|
307
307
|
};
|
|
308
308
|
}
|
|
309
|
-
function checkRevision(current, original) {
|
|
310
|
-
if (current.owner_id !== original.owner_id ||
|
|
311
|
-
current.updated_at !== original.updated_at)
|
|
312
|
-
throw errValidation({
|
|
313
|
-
field: "updated_at",
|
|
314
|
-
msg: "This post has changed. Open it again before editing.",
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
309
|
function matchesInput(post, input) {
|
|
318
310
|
return (post.text.text === input.text.text &&
|
|
319
311
|
post.visibility === input.visibility &&
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type FeedPost, type InFeedPost } from "@fabriktor/schema";
|
|
2
|
+
export declare function checkFeedPostVersion(current: FeedPost, expected?: Pick<FeedPost, "owner_id" | "updated_at">): void;
|
|
2
3
|
export declare function validateFeedVisibility(value: number): void;
|
|
3
4
|
export declare function feedPostInput(post: FeedPost): InFeedPost;
|
|
4
5
|
export declare function prepareFeedTextPost(input: InFeedPost): InFeedPost;
|
|
@@ -6,6 +6,22 @@
|
|
|
6
6
|
import { All, Contacts, Private, ZeroID, } from "@fabriktor/schema";
|
|
7
7
|
import { errValidation } from "../core/err.js";
|
|
8
8
|
import { resolvedID } from "../core/id.js";
|
|
9
|
+
import { timestampDate } from "../core/date.js";
|
|
10
|
+
export function checkFeedPostVersion(current, expected) {
|
|
11
|
+
if (!expected)
|
|
12
|
+
return;
|
|
13
|
+
// Mongo stores milliseconds; a pull can return the in-memory nanoseconds.
|
|
14
|
+
const current_time = timestampDate(current.updated_at)?.getTime();
|
|
15
|
+
const expected_time = timestampDate(expected.updated_at)?.getTime();
|
|
16
|
+
if (current.owner_id !== expected.owner_id ||
|
|
17
|
+
current_time === undefined ||
|
|
18
|
+
expected_time === undefined ||
|
|
19
|
+
current_time !== expected_time)
|
|
20
|
+
throw errValidation({
|
|
21
|
+
field: "updated_at",
|
|
22
|
+
msg: "Reload the post before changing it.",
|
|
23
|
+
});
|
|
24
|
+
}
|
|
9
25
|
export function validateFeedVisibility(value) {
|
|
10
26
|
if (![All, Contacts, Private].includes(value))
|
|
11
27
|
throw errValidation({
|