Docs / data / shared-pool

shared-pool

recipesince 0.2.8

Share one pool of data across all users of the app (leaderboards, feeds, catalogs), readable even before sign-in

Plane: data_pattern

Steps: 1. useCollection — Pass { layer: 'shared' } for signed-in reads/writes into the app-wide pool. 2. usePublicCollection — Use for read-only access WITHOUT sign-in (landing pages, public leaderboards).

Examples

End-to-end example
import { useCollection, usePublicCollection } from '@flowstack/sdk';

export function Leaderboard({ signedIn }: { signedIn: boolean }) {
  // Public, pre-auth read:
  const { documents: publicRows } = usePublicCollection('scores', {
    sort: { points: -1 },
    limit: 10,
  });
  // Signed-in write path:
  const { insert } = useCollection('scores', { layer: 'shared' });

  return (
    <>
      <ol>{publicRows.map(r => <li key={r._id}>{r.player}: {r.points}</li>)}</ol>
      {signedIn && (
        <button onClick={() => insert({ player: 'me', points: 1, at: new Date().toISOString() })}>
          Post score
        </button>
      )}
    </>
  );
}
Warninglayer 'shared' is world-readable within the app — never put private or per-user data here.
WarningusePublicCollection is read-only and needs no auth; writes always go through useCollection with sign-in.
WarningSeed shared catalogs via the agent or an import, not by hardcoding rows in the app source.

See also

per-user-store · form-write-direct · usePublicCollection · useCollection

Source: sync-recipes.mjs ← https://sage-api.flowstack.fun/recipes.json · Also available in llms-full.txt and registry.json.