npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@lastbrain/core

v2.0.16

Published

Utilitaires et types partagés pour LastBrain

Readme

@lastbrain/core

Package de base pour toutes les applications LastBrain. Fournit les types, helpers Supabase et hooks essentiels.

🎯 Vue d'ensemble

@lastbrain/core est la fondation de l'écosystème LastBrain. Il contient :

  • 🔧 Clients Supabase - Configuration pour browser et server
  • 📝 Types TypeScript - Types partagés pour toute l'application
  • 🔄 Hooks realtime - Système de synchronisation en temps réel
  • 🛠️ Helpers utilitaires - Fonctions communes pour tous les modules

🚀 Démarrage rapide

Recommandé : Utilisez le CLI LastBrain pour créer une application complète

# Créer une nouvelle application avec @lastbrain/core inclus
pnpx @lastbrain/app@latest init mon-app
cd mon-app
pnpm dev

📦 Installation manuelle

Si vous intégrez LastBrain dans un projet existant :

pnpm add @lastbrain/core @lastbrain/ui

🔧 Composants exportés

Clients Supabase

import {
  supabaseBrowserClient,
  getSupabaseServerClient,
  createMiddlewareClient,
} from "@lastbrain/core";

// Client côté browser (React components)
const { data } = await supabaseBrowserClient.from("users").select("*");

// Client côté server (API routes, Server Components)
const supabase = await getSupabaseServerClient();

// Client middleware (protection de routes)
const { supabase, response } = createMiddlewareClient(request);

Hooks de base

import {
  useAuth,
  useSupabaseClient,
  useRealtimeListener
} from "@lastbrain/core";

function MyComponent() {
  const { user, session } = useAuth();
  const supabase = useSupabaseClient();
  const { data, loading } = useRealtimeListener("users", {
    event: "*",
    schema: "public"
  });

  return <div>Hello {user?.email}</div>;
}

Types TypeScript

import type {
  Database,
  Tables,
  ModuleConfig,
  RealtimeConfig
} from "@lastbrain/core";

// Types de base de données auto-générés
type User = Tables<"users">;
type Profile = Tables<"user_profil">;

// Configuration des modules
const moduleConfig: ModuleConfig = {
  name: "auth",
  version: "1.0.0",
  pages: [...]
};

Event Bus

import { eventBus } from "@lastbrain/core";

// Émettre un événement
eventBus.emit("user:updated", { userId: "123", data: {...} });

// Écouter un événement
eventBus.on("user:updated", (payload) => {
  console.log("Utilisateur mis à jour:", payload);
});

// Se désabonner
eventBus.off("user:updated", handler);

🔄 Système Realtime

LastBrain inclut un système de synchronisation en temps réel basé sur Supabase Realtime :

import { useRealtimeSignal, useNotificationRealtime } from "@lastbrain/core";

// Hook générique pour n'importe quelle table
const signal = useRealtimeSignal("users", {
  event: "*",
  schema: "public",
  filter: "id=eq.123",
});

// Hook spécialisé pour les notifications
const notificationSignal = useNotificationRealtime();

// Dans votre composant
useEffect(() => {
  if (signal.hasUpdates) {
    // Recharger les données
    refetchUsers();
  }
}, [signal.tick]);

🛠️ Configuration

Variables d'environnement

# .env.local
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key

Configuration TypeScript

// tsconfig.json
{
  "compilerOptions": {
    "types": ["@lastbrain/core/types"]
  }
}

🔐 Authentification

import { supabaseBrowserClient } from "@lastbrain/core";

// Connexion
const { data, error } = await supabaseBrowserClient.auth.signInWithPassword({
  email: "[email protected]",
  password: "password",
});

// Déconnexion
await supabaseBrowserClient.auth.signOut();

// Récupérer l'utilisateur actuel
const {
  data: { user },
} = await supabaseBrowserClient.auth.getUser();

📊 Base de données

import { supabaseBrowserClient } from "@lastbrain/core";
import type { Tables } from "@lastbrain/core";

type User = Tables<"users">;

// CRUD operations
const { data: users } = await supabaseBrowserClient
  .from("users")
  .select("*")
  .eq("active", true);

const { data: newUser } = await supabaseBrowserClient
  .from("users")
  .insert({ email: "[email protected]" })
  .select()
  .single();

🏗️ Architecture

@lastbrain/core/
├── src/
│   ├── supabase/          # Clients et configuration Supabase
│   ├── types/             # Types TypeScript
│   ├── hooks/             # Hooks React
│   ├── realtime/          # Système temps réel
│   ├── eventBus.ts        # Event bus global
│   └── index.ts           # Exports principaux
└── server.ts              # Exports server-only

🔗 Intégration avec les modules

@lastbrain/core est conçu pour être étendu par des modules :

// Dans un module (ex: @lastbrain/module-auth)
import { supabaseBrowserClient, eventBus } from "@lastbrain/core";

export function useAuthActions() {
  const signIn = async (email: string, password: string) => {
    const result = await supabaseBrowserClient.auth.signInWithPassword({
      email,
      password,
    });

    if (result.data.user) {
      eventBus.emit("auth:signin", result.data.user);
    }

    return result;
  };

  return { signIn };
}

🤝 Contribuer

Ce package fait partie du monorepo LastBrain. Voir le CONTRIBUTING.md principal.

📄 Licence

MIT - Voir LICENSE