@fabriktor/fx 0.0.155 → 0.0.157
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 +1 -2
- package/dist/src/feed/feed.js +3 -12
- package/dist/src/feed/media.d.ts +3 -5
- package/dist/src/feed/media.js +16 -25
- package/dist/src/feed/validation.d.ts +2 -0
- package/dist/src/feed/validation.js +29 -8
- package/dist/src/marketplace/marketplace.d.ts +1 -0
- package/dist/src/marketplace/marketplace.js +6 -1
- package/package.json +1 -1
package/dist/src/feed/feed.d.ts
CHANGED
|
@@ -160,7 +160,7 @@ export type CreateFeedPostWithMediaResult = {
|
|
|
160
160
|
status: typeof FeedMediaPostStatus.PatchFailed;
|
|
161
161
|
post_id: string;
|
|
162
162
|
upload: StoragePersonalBoxUploadResult;
|
|
163
|
-
objects:
|
|
163
|
+
objects: FeedPostInsert["objects"];
|
|
164
164
|
error: unknown;
|
|
165
165
|
};
|
|
166
166
|
export interface FeedFXOperator {
|
|
@@ -224,7 +224,6 @@ export declare class FeedFX implements FeedFXOperator {
|
|
|
224
224
|
restrictFeed(opts: {
|
|
225
225
|
new_visibility: number;
|
|
226
226
|
}): Promise<void>;
|
|
227
|
-
private checkVersion;
|
|
228
227
|
private requireFeedPost;
|
|
229
228
|
private changed;
|
|
230
229
|
private mutate;
|
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.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FeedOperator, type StorageUploadFile } from "@fabriktor/client";
|
|
2
|
-
import { type FeedPost, type InFeedPost, type
|
|
2
|
+
import { type FeedPost, type InFeedPost, type Object as StorageObject } from "@fabriktor/schema";
|
|
3
3
|
import type { MultiCreateAttempt } from "../core/multi-create.js";
|
|
4
4
|
import { type StorageFXOperator, type StoragePersonalBoxUploadResult, type StorageUploadResult } from "../storage/storage.js";
|
|
5
5
|
export type FeedPostDraft = {
|
|
@@ -22,9 +22,7 @@ export type FeedPostSaveState = {
|
|
|
22
22
|
baseline?: StorageObject[];
|
|
23
23
|
primary?: StorageUploadResult;
|
|
24
24
|
upload?: StoragePersonalBoxUploadResult;
|
|
25
|
-
input?: InFeedPost
|
|
26
|
-
objects: FeedObject[];
|
|
27
|
-
};
|
|
25
|
+
input?: InFeedPost;
|
|
28
26
|
patch_attempted?: boolean;
|
|
29
27
|
patched?: boolean;
|
|
30
28
|
rejected?: boolean;
|
|
@@ -49,5 +47,5 @@ type SaveDependencies = {
|
|
|
49
47
|
changed: (id: string) => void;
|
|
50
48
|
};
|
|
51
49
|
export declare function saveFeedPost(deps: SaveDependencies, opts: SaveFeedPostOptions): Promise<FeedPostSaveResult>;
|
|
52
|
-
export declare function feedObjects(objects: StorageObject[]):
|
|
50
|
+
export declare function feedObjects(objects: StorageObject[]): InFeedPost["objects"];
|
|
53
51
|
export {};
|
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, feedObjectInput, 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,9 +155,9 @@ 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
|
-
const retained =
|
|
160
|
+
const retained = base.objects.filter((object) => draft.retained_urls.includes(object.public_url));
|
|
161
161
|
let attachments = retained;
|
|
162
162
|
if (draft.retained_urls.some((url) => !original.objects.some((object) => object.public_url === url)))
|
|
163
163
|
throw errValidation({
|
|
@@ -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 &&
|
|
@@ -333,22 +325,21 @@ export function feedObjects(objects) {
|
|
|
333
325
|
});
|
|
334
326
|
return objects.map((object) => {
|
|
335
327
|
const embedding = object.caption;
|
|
336
|
-
if (!object.public_url?.trim() ||
|
|
337
|
-
!object.mime_prefix ||
|
|
338
|
-
!embedding?.plot_embedding?.length ||
|
|
339
|
-
embedding.dim !== embedding.plot_embedding.length ||
|
|
340
|
-
!embedding.plot_embedding.every(Number.isFinite))
|
|
328
|
+
if (!object.public_url?.trim() || !object.mime_prefix?.trim())
|
|
341
329
|
throw errResolveFailed({
|
|
342
330
|
resource: "feed_object",
|
|
343
|
-
msg: "Storage did not return a public URL and
|
|
331
|
+
msg: "Storage did not return a public URL and media type.",
|
|
344
332
|
});
|
|
345
|
-
|
|
333
|
+
if (!embedding?.text?.trim())
|
|
334
|
+
throw errResolveFailed({
|
|
335
|
+
resource: "feed_object",
|
|
336
|
+
msg: "Storage did not return caption text for this media.",
|
|
337
|
+
});
|
|
338
|
+
// Generated Feed inputs contain caption content; Feed computes its vector.
|
|
339
|
+
return feedObjectInput({
|
|
346
340
|
public_url: object.public_url,
|
|
347
341
|
mime_prefix: object.mime_prefix,
|
|
348
|
-
embedding
|
|
349
|
-
|
|
350
|
-
plot_embedding: [...embedding.plot_embedding],
|
|
351
|
-
},
|
|
352
|
-
};
|
|
342
|
+
embedding,
|
|
343
|
+
});
|
|
353
344
|
});
|
|
354
345
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
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;
|
|
5
|
+
export declare function feedObjectInput(object: InFeedPost["objects"][number]): InFeedPost["objects"][number];
|
|
4
6
|
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({
|
|
@@ -16,14 +32,7 @@ export function validateFeedVisibility(value) {
|
|
|
16
32
|
export function feedPostInput(post) {
|
|
17
33
|
return {
|
|
18
34
|
text: { text: post.text.text, file: "", file_url: "", mime: "" },
|
|
19
|
-
objects: post.objects.map(
|
|
20
|
-
public_url: object.public_url,
|
|
21
|
-
mime_prefix: object.mime_prefix,
|
|
22
|
-
embedding: {
|
|
23
|
-
...object.embedding,
|
|
24
|
-
plot_embedding: [...object.embedding.plot_embedding],
|
|
25
|
-
},
|
|
26
|
-
})),
|
|
35
|
+
objects: post.objects.map(feedObjectInput),
|
|
27
36
|
is_uploading: post.is_uploading,
|
|
28
37
|
has_media: post.has_media,
|
|
29
38
|
visibility: post.visibility,
|
|
@@ -31,6 +40,18 @@ export function feedPostInput(post) {
|
|
|
31
40
|
reply_to_post_id: post.reply_to_post_id,
|
|
32
41
|
};
|
|
33
42
|
}
|
|
43
|
+
export function feedObjectInput(object) {
|
|
44
|
+
return {
|
|
45
|
+
public_url: object.public_url,
|
|
46
|
+
mime_prefix: object.mime_prefix,
|
|
47
|
+
embedding: {
|
|
48
|
+
text: object.embedding.text ?? "",
|
|
49
|
+
file: object.embedding.file ?? "",
|
|
50
|
+
file_url: object.embedding.file_url ?? "",
|
|
51
|
+
mime: object.embedding.mime ?? "",
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
34
55
|
// Text publishing uses generated inputs; media creation has its own storage workflow.
|
|
35
56
|
export function prepareFeedTextPost(input) {
|
|
36
57
|
validateFeedVisibility(input.visibility);
|
|
@@ -38,6 +38,7 @@ export type MarketplaceFavoriteOptions = {
|
|
|
38
38
|
export type SetMarketplaceFavoriteOptions = MarketplaceFavoriteOptions & {
|
|
39
39
|
post_id: string;
|
|
40
40
|
saved: boolean;
|
|
41
|
+
on_confirmed?: () => void;
|
|
41
42
|
};
|
|
42
43
|
export type SearchMarketplacePostsPage = SearchPage<MarketplacePost>;
|
|
43
44
|
export type MarketplacePullContext = Pick<MarketplacePullOptions, "pull_type" | "entity_id" | "research" | "research_user_type">;
|
|
@@ -269,8 +269,10 @@ export class MarketplaceFX {
|
|
|
269
269
|
return await this.mutate(async (signal) => {
|
|
270
270
|
const existing = await this.listMarketplaceFavorites({ ...opts, signal });
|
|
271
271
|
if (opts.saved) {
|
|
272
|
-
if (existing.length)
|
|
272
|
+
if (existing.length) {
|
|
273
|
+
notifyObserver(() => opts.on_confirmed?.());
|
|
273
274
|
return existing[0];
|
|
275
|
+
}
|
|
274
276
|
if (!(await this.readMarketplacePost({ id: opts.post_id, signal }))) {
|
|
275
277
|
throw errResolveFailed({
|
|
276
278
|
resource: resourceMarketplacePost,
|
|
@@ -282,6 +284,8 @@ export class MarketplaceFX {
|
|
|
282
284
|
signal,
|
|
283
285
|
});
|
|
284
286
|
signal.throwIfAborted();
|
|
287
|
+
// The write is acknowledged even if resolving its document later fails.
|
|
288
|
+
notifyObserver(() => opts.on_confirmed?.());
|
|
285
289
|
const id = requiredOperationID(out, msgCreatedMarketplaceFavoriteIDMissing);
|
|
286
290
|
const found = await this.marketplace.findOneMarketplaceFavorite({
|
|
287
291
|
id,
|
|
@@ -304,6 +308,7 @@ export class MarketplaceFX {
|
|
|
304
308
|
});
|
|
305
309
|
}
|
|
306
310
|
signal.throwIfAborted();
|
|
311
|
+
notifyObserver(() => opts.on_confirmed?.());
|
|
307
312
|
this.changed(opts.owner_id, "favorites", opts.post_id);
|
|
308
313
|
return null;
|
|
309
314
|
}, opts.signal);
|