@fabriktor/fx 0.0.156 → 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 -1
- package/dist/src/feed/media.d.ts +3 -5
- package/dist/src/feed/media.js +13 -14
- package/dist/src/feed/validation.d.ts +1 -0
- package/dist/src/feed/validation.js +13 -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 {
|
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, checkFeedPostVersion, } 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(),
|
|
@@ -157,7 +157,7 @@ export async function saveFeedPost(deps, opts) {
|
|
|
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({
|
|
@@ -325,22 +325,21 @@ export function feedObjects(objects) {
|
|
|
325
325
|
});
|
|
326
326
|
return objects.map((object) => {
|
|
327
327
|
const embedding = object.caption;
|
|
328
|
-
if (!object.public_url?.trim() ||
|
|
329
|
-
!object.mime_prefix ||
|
|
330
|
-
!embedding?.plot_embedding?.length ||
|
|
331
|
-
embedding.dim !== embedding.plot_embedding.length ||
|
|
332
|
-
!embedding.plot_embedding.every(Number.isFinite))
|
|
328
|
+
if (!object.public_url?.trim() || !object.mime_prefix?.trim())
|
|
333
329
|
throw errResolveFailed({
|
|
334
330
|
resource: "feed_object",
|
|
335
|
-
msg: "Storage did not return a public URL and
|
|
331
|
+
msg: "Storage did not return a public URL and media type.",
|
|
336
332
|
});
|
|
337
|
-
|
|
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({
|
|
338
340
|
public_url: object.public_url,
|
|
339
341
|
mime_prefix: object.mime_prefix,
|
|
340
|
-
embedding
|
|
341
|
-
|
|
342
|
-
plot_embedding: [...embedding.plot_embedding],
|
|
343
|
-
},
|
|
344
|
-
};
|
|
342
|
+
embedding,
|
|
343
|
+
});
|
|
345
344
|
});
|
|
346
345
|
}
|
|
@@ -2,4 +2,5 @@ import { type FeedPost, type InFeedPost } from "@fabriktor/schema";
|
|
|
2
2
|
export declare function checkFeedPostVersion(current: FeedPost, expected?: Pick<FeedPost, "owner_id" | "updated_at">): void;
|
|
3
3
|
export declare function validateFeedVisibility(value: number): void;
|
|
4
4
|
export declare function feedPostInput(post: FeedPost): InFeedPost;
|
|
5
|
+
export declare function feedObjectInput(object: InFeedPost["objects"][number]): InFeedPost["objects"][number];
|
|
5
6
|
export declare function prepareFeedTextPost(input: InFeedPost): InFeedPost;
|
|
@@ -32,14 +32,7 @@ export function validateFeedVisibility(value) {
|
|
|
32
32
|
export function feedPostInput(post) {
|
|
33
33
|
return {
|
|
34
34
|
text: { text: post.text.text, file: "", file_url: "", mime: "" },
|
|
35
|
-
objects: post.objects.map(
|
|
36
|
-
public_url: object.public_url,
|
|
37
|
-
mime_prefix: object.mime_prefix,
|
|
38
|
-
embedding: {
|
|
39
|
-
...object.embedding,
|
|
40
|
-
plot_embedding: [...object.embedding.plot_embedding],
|
|
41
|
-
},
|
|
42
|
-
})),
|
|
35
|
+
objects: post.objects.map(feedObjectInput),
|
|
43
36
|
is_uploading: post.is_uploading,
|
|
44
37
|
has_media: post.has_media,
|
|
45
38
|
visibility: post.visibility,
|
|
@@ -47,6 +40,18 @@ export function feedPostInput(post) {
|
|
|
47
40
|
reply_to_post_id: post.reply_to_post_id,
|
|
48
41
|
};
|
|
49
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
|
+
}
|
|
50
55
|
// Text publishing uses generated inputs; media creation has its own storage workflow.
|
|
51
56
|
export function prepareFeedTextPost(input) {
|
|
52
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);
|