@get-bb/plugin-sdk 0.6.90 → 0.6.94

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.
@@ -1085,11 +1085,16 @@ function createTaggedKeyedQueryOwner(options) {
1085
1085
  registerKeyedView(client, queryKey, keyedRowsView(collection));
1086
1086
  const keys = /* @__PURE__ */ new Map();
1087
1087
  let readingKeys = /* @__PURE__ */ new Set();
1088
+ let collecting = false;
1088
1089
  let missingOnly = false;
1089
1090
  let refreshAll = false;
1090
1091
  const dirtyKeys = /* @__PURE__ */ new Set();
1091
- const collectSubscribedKeys = () => new Promise((resolve) => {
1092
- queueMicrotask(() => resolve([...keys.keys()]));
1092
+ const takeSubscribedKeys = (take) => new Promise((resolve) => {
1093
+ queueMicrotask(() => {
1094
+ readingKeys = new Set(take([...keys.keys()]));
1095
+ collecting = false;
1096
+ resolve([...readingKeys]);
1097
+ });
1093
1098
  });
1094
1099
  const observer = new QueryObserver(client, {
1095
1100
  queryKey,
@@ -1116,23 +1121,26 @@ function createTaggedKeyedQueryOwner(options) {
1116
1121
  const refreshedKeys = /* @__PURE__ */ new Set();
1117
1122
  let refreshedAll = false;
1118
1123
  return runTaggedRead(client, queryKey, async () => {
1119
- const subscribed = await collectSubscribedKeys();
1120
- const all = refreshAll || refresh;
1121
- refresh = false;
1122
- const dirty = new Set(dirtyKeys);
1123
- refreshedAll ||= all;
1124
- if (all)
1125
- for (const key of Object.keys(previous?.result ?? {}))
1126
- dirtyKeys.add(key);
1127
- refreshAll = false;
1128
- const requested = subscribed.filter(
1129
- (key) => all || dirty.has(key) || !Object.hasOwn(previous?.result ?? {}, key)
1130
- );
1131
- for (const key of requested) {
1132
- refreshedKeys.add(key);
1133
- dirtyKeys.delete(key);
1134
- }
1135
- readingKeys = new Set(requested);
1124
+ collecting = true;
1125
+ let all = false;
1126
+ const requested = await takeSubscribedKeys((subscribed) => {
1127
+ all = refreshAll || refresh;
1128
+ refresh = false;
1129
+ const dirty = new Set(dirtyKeys);
1130
+ refreshedAll ||= all;
1131
+ if (all)
1132
+ for (const key of Object.keys(previous?.result ?? {}))
1133
+ dirtyKeys.add(key);
1134
+ refreshAll = false;
1135
+ const taken = subscribed.filter(
1136
+ (key) => all || dirty.has(key) || !Object.hasOwn(previous?.result ?? {}, key)
1137
+ );
1138
+ for (const key of taken) {
1139
+ refreshedKeys.add(key);
1140
+ dirtyKeys.delete(key);
1141
+ }
1142
+ return taken;
1143
+ });
1136
1144
  const started = tick();
1137
1145
  try {
1138
1146
  const results = await Promise.all(
@@ -1188,13 +1196,15 @@ function createTaggedKeyedQueryOwner(options) {
1188
1196
  let stop;
1189
1197
  return {
1190
1198
  observer,
1191
- async refetchKeys(requested) {
1199
+ async refresh(requested) {
1192
1200
  const subscribed = requested.filter((key) => keys.has(key));
1193
1201
  if (subscribed.length === 0) return;
1194
- for (const key of subscribed) dirtyKeys.add(key);
1195
- if (observer.getCurrentResult().isFetching) {
1202
+ const fetching = observer.getCurrentQuery().state.fetchStatus === "fetching";
1203
+ const unread = fetching && !collecting ? subscribed.filter((key) => !readingKeys.has(key)) : subscribed;
1204
+ if (unread.length === 0) return;
1205
+ for (const key of unread) dirtyKeys.add(key);
1206
+ if (fetching && !collecting)
1196
1207
  restartTaggedRead(observer.getCurrentQuery());
1197
- }
1198
1208
  await observer.refetch({ cancelRefetch: false });
1199
1209
  },
1200
1210
  subscribe(requested, listener) {
@@ -1216,7 +1226,7 @@ function createTaggedKeyedQueryOwner(options) {
1216
1226
  }
1217
1227
  if (added && pending.length > 0) {
1218
1228
  if (observer.getCurrentResult().isFetching) {
1219
- if (readingKeys.size > 0 && pending.some((key) => !readingKeys.has(key)))
1229
+ if (!collecting && pending.some((key) => !readingKeys.has(key)))
1220
1230
  restartTaggedRead(observer.getCurrentQuery());
1221
1231
  } else {
1222
1232
  missingOnly = true;
@@ -1268,7 +1278,7 @@ function useQuerySelection(subscribe, getSnapshot, select) {
1268
1278
  import { QueryClient } from "@tanstack/react-query";
1269
1279
 
1270
1280
  // src/internal/rpc-query-host.ts
1271
- import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2 } from "react";
1281
+ import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
1272
1282
  import { useIsFetching } from "@tanstack/react-query";
1273
1283
 
1274
1284
  // ../domain/src/shared-types.ts
@@ -2286,6 +2296,8 @@ var rpcQueryKey = (pluginId, method, input) => [
2286
2296
  input
2287
2297
  ];
2288
2298
  var keyedQueryKey = (pluginId, method) => rpcQueryKey(pluginId, method, { keyed: true });
2299
+ var keyListSchema = z19.array(z19.string());
2300
+ var jsonRecordSchema = z19.record(z19.string(), jsonValueSchema);
2289
2301
  var keyedCollections = /* @__PURE__ */ new Map();
2290
2302
  function keyedCollection(pluginId, method) {
2291
2303
  const name = JSON.stringify([pluginId, method]);
@@ -2420,7 +2432,7 @@ function createRpcQueryHooks(useHost) {
2420
2432
  const enabled = options.enabled ?? true;
2421
2433
  const identity = JSON.stringify([...new Set(options.keys)].sort());
2422
2434
  const keys = useMemo2(
2423
- () => z19.array(z19.string()).parse(JSON.parse(identity)),
2435
+ () => keyListSchema.parse(JSON.parse(identity)),
2424
2436
  [identity]
2425
2437
  );
2426
2438
  let cache = owners.get(host.queryClient);
@@ -2446,7 +2458,7 @@ function createRpcQueryHooks(useHost) {
2446
2458
  );
2447
2459
  return {
2448
2460
  ...response,
2449
- result: z19.record(z19.string(), jsonValueSchema).parse(response.result)
2461
+ result: jsonRecordSchema.parse(response.result)
2450
2462
  };
2451
2463
  }
2452
2464
  });
@@ -2455,8 +2467,7 @@ function createRpcQueryHooks(useHost) {
2455
2467
  const current = owner;
2456
2468
  useSubscription(host, pluginId, enabled && keys.length > 0);
2457
2469
  const subscribe = useCallback2(
2458
- (listener) => enabled && keys.length > 0 ? current.subscribe(keys, listener) : () => {
2459
- },
2470
+ (listener) => current.subscribe(enabled ? keys : [], listener),
2460
2471
  [current, keys, enabled]
2461
2472
  );
2462
2473
  const getSnapshot = useCallback2(
@@ -2483,23 +2494,39 @@ function createRpcQueryHooks(useHost) {
2483
2494
  [keys, enabled, selectRows]
2484
2495
  );
2485
2496
  const query = useQuerySelection(subscribe, getSnapshot, select);
2497
+ const watches = useMemo2(
2498
+ () => /* @__PURE__ */ new Map(),
2499
+ [host, pluginId, options.method]
2500
+ );
2501
+ useEffect2(
2502
+ () => () => {
2503
+ for (const release of watches.values()) release?.();
2504
+ watches.clear();
2505
+ },
2506
+ [watches]
2507
+ );
2486
2508
  useEffect2(() => {
2487
- if (!enabled) return;
2488
- const releases = keys.map(
2489
- (key) => host.watch?.(pluginId, options.method, { key })
2490
- );
2491
- return () => {
2492
- releases.forEach((release) => release?.());
2493
- };
2494
- }, [host, pluginId, options.method, keys, enabled]);
2509
+ const wanted = new Set(enabled ? keys : []);
2510
+ for (const [key, release] of watches) {
2511
+ if (wanted.has(key)) continue;
2512
+ release?.();
2513
+ watches.delete(key);
2514
+ }
2515
+ for (const key of wanted) {
2516
+ if (!watches.has(key))
2517
+ watches.set(key, host.watch?.(pluginId, options.method, { key }));
2518
+ }
2519
+ }, [host, pluginId, options.method, keys, enabled, watches]);
2520
+ const heldKeys = useRef2(keys);
2521
+ useEffect2(() => {
2522
+ heldKeys.current = keys;
2523
+ }, [keys]);
2495
2524
  const refetch = useCallback2(async () => {
2496
- await current.observer.refetch();
2525
+ await current.refresh(heldKeys.current);
2497
2526
  }, [current]);
2498
2527
  const refetchKeys = useCallback2(
2499
2528
  async (requested) => {
2500
- await current.refetchKeys(
2501
- requested.filter((key) => keys.includes(key))
2502
- );
2529
+ await current.refresh(requested.filter((key) => keys.includes(key)));
2503
2530
  },
2504
2531
  [current, keys]
2505
2532
  );
@@ -2514,6 +2541,7 @@ function createRpcQueryHooks(useHost) {
2514
2541
  const pluginId = resolvePluginId(host, options.pluginId);
2515
2542
  const mutation = useTaggedMutation({
2516
2543
  client: host.queryClient,
2544
+ meta: { showErrorToast: false },
2517
2545
  invalidate: (tags) => invalidateTags(host.queryClient, pluginTagScope(pluginId), tags),
2518
2546
  call: async (input) => {
2519
2547
  const response = await callRpc(
@@ -2587,7 +2615,7 @@ import {
2587
2615
  useLayoutEffect,
2588
2616
  useEffect as useEffect3,
2589
2617
  useMemo as useMemo3,
2590
- useRef as useRef2,
2618
+ useRef as useRef3,
2591
2619
  useState as useState2,
2592
2620
  useSyncExternalStore as useSyncExternalStore2
2593
2621
  } from "react";
@@ -3826,6 +3854,7 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
3826
3854
  threadHeaderActions: [],
3827
3855
  threadContextSegments: [],
3828
3856
  threadInfoRows: [],
3857
+ threadRowMetadata: [],
3829
3858
  threadInfoSections: [],
3830
3859
  threadActions: [],
3831
3860
  browserToolbarActions: [],
@@ -3862,6 +3891,7 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
3862
3891
  threadHeaderAction: /* @__PURE__ */ new Set(),
3863
3892
  threadContextSegment: /* @__PURE__ */ new Set(),
3864
3893
  threadInfoRow: /* @__PURE__ */ new Set(),
3894
+ threadRowMetadata: /* @__PURE__ */ new Set(),
3865
3895
  threadInfoSection: /* @__PURE__ */ new Set(),
3866
3896
  threadAction: /* @__PURE__ */ new Set(),
3867
3897
  browserToolbarAction: /* @__PURE__ */ new Set(),
@@ -3982,6 +4012,16 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
3982
4012
  onWarning(`Legacy threadPanelAction ignored: ${String(error)}`);
3983
4013
  }
3984
4014
  },
4015
+ experimental_threadHeaderAction(registration) {
4016
+ const kind = "slots.experimental_threadHeaderAction";
4017
+ const id = requireSlotId(kind, registration?.id);
4018
+ requireUniqueId(kind, seenIds.threadHeaderAction, id);
4019
+ collected.threadHeaderActions.push({
4020
+ id,
4021
+ title: requireNonEmptyString(kind, "title", registration.title),
4022
+ component: requireComponent(kind, registration.component)
4023
+ });
4024
+ },
3985
4025
  experimental_sidebarHeader(registration) {
3986
4026
  legacySidebarHeaders.push(
3987
4027
  collectTitledComponent(
@@ -4187,16 +4227,6 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
4187
4227
  ...headerComponent !== void 0 ? { headerComponent } : {}
4188
4228
  });
4189
4229
  },
4190
- experimental_threadHeaderAction(registration) {
4191
- const kind = "slots.experimental_threadHeaderAction";
4192
- const id = requireSlotId(kind, registration?.id);
4193
- requireUniqueId(kind, seenIds.threadHeaderAction, id);
4194
- collected.threadHeaderActions.push({
4195
- id,
4196
- title: requireNonEmptyString(kind, "title", registration.title),
4197
- component: requireComponent(kind, registration.component)
4198
- });
4199
- },
4200
4230
  experimental_threadContextSegment(registration) {
4201
4231
  const kind = "slots.experimental_threadContextSegment";
4202
4232
  const id = requireSlotId(kind, registration?.id);
@@ -4230,6 +4260,19 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
4230
4260
  ...registration.useVisible !== void 0 ? { useVisible: registration.useVisible } : {}
4231
4261
  });
4232
4262
  },
4263
+ experimental_threadRowMetadata(registration) {
4264
+ const kind = "slots.experimental_threadRowMetadata";
4265
+ const id = requireSlotId(kind, registration?.id);
4266
+ requireUniqueId(kind, seenIds.threadRowMetadata, id);
4267
+ if (registration.useData !== void 0 && typeof registration.useData !== "function")
4268
+ throw new Error(`${kind}: "useData" must be a function`);
4269
+ collected.threadRowMetadata.push({
4270
+ id,
4271
+ ...requireOptionalOrder(kind, registration.order),
4272
+ ...registration.useData !== void 0 ? { useData: registration.useData } : {},
4273
+ component: requireComponent(kind, registration.component)
4274
+ });
4275
+ },
4233
4276
  experimental_threadInfoRow(registration) {
4234
4277
  const kind = "slots.experimental_threadInfoRow";
4235
4278
  const id = requireSlotId(kind, registration?.id);
@@ -4267,12 +4310,16 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
4267
4310
  `${kind}: "experimental_bulkItem" must be a function`
4268
4311
  );
4269
4312
  }
4313
+ if (registration.placement !== void 0 && registration.placement !== "menu" && registration.placement !== "header") {
4314
+ throw new Error(`${kind}: "placement" must be "menu" or "header"`);
4315
+ }
4270
4316
  collected.threadActions.push({
4271
4317
  id,
4272
4318
  title: requireNonEmptyString(kind, "title", registration.title),
4273
4319
  icon: requireNonEmptyString(kind, "icon", registration.icon),
4274
4320
  group: requireNonEmptyString(kind, "group", registration.group),
4275
4321
  ...requireOptionalOrder(kind, registration.order),
4322
+ ...registration.placement !== void 0 ? { placement: registration.placement } : {},
4276
4323
  ...registration.useData !== void 0 ? { useData: registration.useData } : {},
4277
4324
  item: registration.item,
4278
4325
  ...registration.experimental_bulkItem !== void 0 ? {
@@ -4630,6 +4677,9 @@ function TestThreadStatusGlyph({
4630
4677
  }
4631
4678
  );
4632
4679
  }
4680
+ function TestThreadRowMetadata({ thread }) {
4681
+ return /* @__PURE__ */ jsx("span", { "data-thread-row-metadata": thread.id });
4682
+ }
4633
4683
  function SlotLifecycleGuard({
4634
4684
  children,
4635
4685
  onUnmount
@@ -4738,7 +4788,7 @@ function TestThreadActionsMenu({
4738
4788
  onCloseAutoFocus
4739
4789
  }) {
4740
4790
  const menu = useTestMenuOpenState({ onOpenChange, onCloseAutoFocus });
4741
- const triggerElement = useRef2(null);
4791
+ const triggerElement = useRef3(null);
4742
4792
  useLayoutEffect(() => {
4743
4793
  const element = triggerElement.current;
4744
4794
  if (element?.getAttribute("aria-haspopup") !== "menu") {
@@ -5426,7 +5476,7 @@ var testPluginSdkApp = {
5426
5476
  },
5427
5477
  useRealtime(channel, handler) {
5428
5478
  const env = useSlotEnv("useRealtime");
5429
- const handlerRef = useRef2(handler);
5479
+ const handlerRef = useRef3(handler);
5430
5480
  useEffect3(() => {
5431
5481
  handlerRef.current = handler;
5432
5482
  });
@@ -5692,6 +5742,7 @@ var testPluginSdkApp = {
5692
5742
  },
5693
5743
  ThreadTitle: TestThreadTitle,
5694
5744
  experimental_ThreadStatusGlyph: TestThreadStatusGlyph,
5745
+ experimental_ThreadRowMetadata: TestThreadRowMetadata,
5695
5746
  useEnvironmentProviders() {
5696
5747
  return useSlotEnv("useEnvironmentProviders").environmentProviders;
5697
5748
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@get-bb/plugin-sdk",
3
- "version": "0.6.90",
3
+ "version": "0.6.94",
4
4
  "homepage": "https://github.com/get-bb/bb#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/get-bb/bb/issues"
@@ -151,9 +151,9 @@
151
151
  "scripts": {
152
152
  "build": "node scripts/build-runtime.mjs",
153
153
  "build:runtime": "node scripts/build-runtime.mjs",
154
- "build:types": "node scripts/build-bundled-dts.mjs",
154
+ "build:types": "node --max-semi-space-size=128 --max-old-space-size=4096 scripts/build-bundled-dts.mjs",
155
155
  "clean": "rimraf bundled-types dist tsconfig.tsbuildinfo",
156
- "prepack": "node scripts/build-bundled-dts.mjs && node scripts/build-runtime.mjs",
156
+ "prepack": "node --max-semi-space-size=128 --max-old-space-size=4096 scripts/build-bundled-dts.mjs && node scripts/build-runtime.mjs",
157
157
  "test": "vitest run --config vitest.config.ts",
158
158
  "typecheck": "tsrs --noEmit"
159
159
  },