@drakkar.software/starfish-client 3.0.0-alpha.10 → 3.0.0-alpha.11

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/client.d.ts CHANGED
@@ -50,17 +50,22 @@ export interface BatchPullEntry {
50
50
  error?: string;
51
51
  }
52
52
  /** Response of {@link StarfishClient.batchPull}: a map of requested collection
53
- * name → its {@link BatchPullEntry}. */
53
+ * name → an ARRAY of {@link BatchPullEntry}, one per requested param-set, in
54
+ * request order. A collection read with no params yields a one-element array. */
54
55
  export interface BatchPullResult {
55
- collections: Record<string, BatchPullEntry>;
56
+ collections: Record<string, BatchPullEntry[]>;
56
57
  }
57
58
  /** Options for {@link StarfishClient.batchPull}. */
58
59
  export interface BatchPullOptions {
59
- /** Per-collection path params, e.g. `{ notes: { teamId: "42" } }`. Serialized
60
- * to a URL-encoded JSON `params` query parameter. The `{identity}` param is
61
- * auto-filled by the server from the authenticated caller, so it need not be
62
- * supplied (and a supplied identity that isn't the caller's is rejected). */
63
- params?: Record<string, Record<string, string>>;
60
+ /** Per-collection path params: collection name an ARRAY of param-sets, one
61
+ * per document to read from that collection, e.g.
62
+ * `{ profile: [{ identity: "a" }, { identity: "b" }] }` reads two profiles in
63
+ * one round-trip. Serialized to a URL-encoded JSON `params` query. The
64
+ * `{identity}` param is auto-filled by the server from the authenticated
65
+ * caller when a set omits it, so a single self-doc read can pass `[{}]` — or
66
+ * omit the collection from `params` entirely (an unlisted collection reads one
67
+ * auto-filled doc). Results come back under the same name in request order. */
68
+ params?: Record<string, Record<string, string>[]>;
64
69
  }
65
70
  /**
66
71
  * Low-level HTTP client for the Starfish sync protocol.
@@ -138,17 +143,29 @@ export declare class StarfishClient {
138
143
  /** Pull an append-only collection. Extracts and returns `data[appendField]` as `T[]`. */
139
144
  pull<T = unknown>(path: string, options: AppendPullOptions): Promise<T[]>;
140
145
  /**
141
- * Pull several collections in one round-trip via `/batch/pull`. `collections`
142
- * is the list of collection names; `opts.params` supplies path params per
143
- * collection (serialized to a URL-encoded JSON `params` query). The server
144
- * auto-fills the `{identity}` param from the authenticated caller, so per-user
145
- * collections need no params. Returns a map of collection name → its pulled
146
- * document or a per-collection `{ error }`. Honors the configured namespace.
146
+ * Pull several documents in one round-trip via `/batch/pull`. `collections` is
147
+ * the list of distinct collection names; `opts.params` supplies, per collection,
148
+ * an ARRAY of path-param sets — one per document to read so the SAME collection
149
+ * can fan in many documents (e.g. many users' `profile`) in a single request.
150
+ * The server auto-fills the `{identity}` param from the authenticated caller for
151
+ * any set that omits it, so a self-doc collection needs no params. Returns a map
152
+ * of collection name → an ARRAY of pulled documents (or per-document `{ error }`),
153
+ * in request order. Honors the configured namespace.
154
+ *
155
+ * For the common "many docs of one collection" case prefer {@link batchPullMany}.
147
156
  *
148
157
  * Note: not append/checkpoint-aware — for incremental append-only reads use
149
158
  * `pull(path, { since })` (or `AppendLogCursor`) per collection.
150
159
  */
151
160
  batchPull(collections: string[], opts?: BatchPullOptions): Promise<BatchPullResult>;
161
+ /**
162
+ * Convenience over {@link batchPull} for reading MANY documents of ONE
163
+ * collection in a single round-trip: pass the per-document param-sets and get
164
+ * back the {@link BatchPullEntry} array aligned to `paramsList` by index (each
165
+ * entry is `{ data, hash, timestamp }` or `{ error }`). An empty `paramsList`
166
+ * issues no request and returns `[]`.
167
+ */
168
+ batchPullMany(collection: string, paramsList: Record<string, string>[]): Promise<BatchPullEntry[]>;
152
169
  /**
153
170
  * Push synced data to the server.
154
171
  * @param path - The push endpoint path (e.g. "/push/users/abc/settings")
package/dist/index.js CHANGED
@@ -211,12 +211,16 @@ var StarfishClient = class {
211
211
  return result;
212
212
  }
213
213
  /**
214
- * Pull several collections in one round-trip via `/batch/pull`. `collections`
215
- * is the list of collection names; `opts.params` supplies path params per
216
- * collection (serialized to a URL-encoded JSON `params` query). The server
217
- * auto-fills the `{identity}` param from the authenticated caller, so per-user
218
- * collections need no params. Returns a map of collection name → its pulled
219
- * document or a per-collection `{ error }`. Honors the configured namespace.
214
+ * Pull several documents in one round-trip via `/batch/pull`. `collections` is
215
+ * the list of distinct collection names; `opts.params` supplies, per collection,
216
+ * an ARRAY of path-param sets — one per document to read so the SAME collection
217
+ * can fan in many documents (e.g. many users' `profile`) in a single request.
218
+ * The server auto-fills the `{identity}` param from the authenticated caller for
219
+ * any set that omits it, so a self-doc collection needs no params. Returns a map
220
+ * of collection name → an ARRAY of pulled documents (or per-document `{ error }`),
221
+ * in request order. Honors the configured namespace.
222
+ *
223
+ * For the common "many docs of one collection" case prefer {@link batchPullMany}.
220
224
  *
221
225
  * Note: not append/checkpoint-aware — for incremental append-only reads use
222
226
  * `pull(path, { since })` (or `AppendLogCursor`) per collection.
@@ -239,6 +243,18 @@ var StarfishClient = class {
239
243
  }
240
244
  return await res.json();
241
245
  }
246
+ /**
247
+ * Convenience over {@link batchPull} for reading MANY documents of ONE
248
+ * collection in a single round-trip: pass the per-document param-sets and get
249
+ * back the {@link BatchPullEntry} array aligned to `paramsList` by index (each
250
+ * entry is `{ data, hash, timestamp }` or `{ error }`). An empty `paramsList`
251
+ * issues no request and returns `[]`.
252
+ */
253
+ async batchPullMany(collection, paramsList) {
254
+ if (paramsList.length === 0) return [];
255
+ const res = await this.batchPull([collection], { params: { [collection]: paramsList } });
256
+ return res.collections[collection] ?? [];
257
+ }
242
258
  /**
243
259
  * Push synced data to the server.
244
260
  * @param path - The push endpoint path (e.g. "/push/users/abc/settings")