सामग्री पर जाएँ
ऑराबेस लोगो
aurabase

जावास्क्रिप्ट एसडीके

@aurabase/aurabase-js - नोड, बन, Deno, Next.js, React, SvelteKit, Vue के लिए टाइप किया गया क्लाइंट। डेटाबेस, ऑथ, रीयलटाइम, स्टोरेज, फ़ंक्शंस को कवर करता है।

संदर्भ10 मि॰ पढ़ेंस्तर संदर्भ15 अप्रैल 2026 पर संशोधित

यह पृष्ठ स्वचालित रूप से अनुवादित किया गया था. अंग्रेजी संस्करण प्रामाणिक है.

एक पैकेज, चार मैनेजर#

terminalbash
pnpm add @aurabase/aurabase-js
सुझाव

SDK में सीधे Next.js (ऐप राउटर, सर्वर एक्शन, मिडलवेयर), रीमिक्स, Nuxt और SvelteKit के लिए सत्र कुकीज़ और एंटी-ट्रंकेशन चंकिंग के स्वचालित प्रबंधन के साथ @aurabase/aurabase-js/ssr निर्यात शामिल है।

ग्राहक बनाएँ#

src/lib/aurabase.tstypescript
import { createClient } from '@aurabase/aurabase-js'
import type { Database } from './aurabase.types'

export const aura = createClient<Database>(
  process.env.NEXT_PUBLIC_AURABASE_URL!,
  process.env.NEXT_PUBLIC_AURABASE_ANON_KEY!,
  { auth: { persistSession: true } }
)

मूल सर्वर-साइड रेंडरिंग समर्थन#

SSR आर्किटेक्चर (Next.js ऐप राउटर, मिडलवेयर, सर्वर एक्शन, SvelteKit) के लिए, @aurabase/aurabase-js/ssr से createServerClient आयात करें। उपयोगकर्ता सत्र स्वचालित रूप से बड़े टोकन के लिए मल्टी-चंक समर्थन के साथ सुरक्षित httpOnly कुकीज़ में संग्रहीत होता है:

src/middleware.tstypescript
import { createServerClient } from '@aurabase/aurabase-js/ssr'
import { NextResponse, type NextRequest } from 'next/server'

export async function middleware(request: NextRequest) {
  let response = NextResponse.next({ request })
  const aura = createServerClient(
    process.env.NEXT_PUBLIC_AURABASE_URL!,
    process.env.NEXT_PUBLIC_AURABASE_ANON_KEY!,
    {
      cookies: {
        getAll() { return request.cookies.getAll() },
        setAll(cookies) {
          cookies.forEach(({ name, value, options }) => {
            request.cookies.set(name, value)
            response.cookies.set(name, value, options)
          })
        },
      },
    })
  await aura.auth.getSession()
  return response
}

आपके स्कीमा से कोडजन#

npx @aurabase/gen --out lib/aurabase.types.ts (या aura db generate, जो वर्तमान फ़ोल्डर में types.ts लिखता है) आपके संपूर्ण स्कीमा (तालिकाओं, दृश्य, एनम, आरपीसी फ़ंक्शन) से प्रकार फ़ाइल उत्पन्न करता है। अपने सभी प्रश्न टाइप करने के लिए createClient<Database> में प्लग इन करें।

package.jsonjson
{
  "scripts": {
    "types:gen": "npx @aurabase/gen --out src/aurabase.types.ts",
    "migrate": "aura db push && pnpm types:gen"
  }
}

सेवा द्वारा#

डेटाबेस

  • .from(table).select(cols?) → SelectBuilder<T>
  • .from(table).insert(row) → Promise<{ data, error }>
  • .from(table).update(patch) → UpdateBuilder<T>
  • .from(table).delete() → DeleteBuilder<T>
  • .rpc(fn, args) → Promise<{ data, error }>
  • .nosql.collection(name) → NoSqlCollectionClient (find(), insertOne(), aggregate(), createIndex())

प्रमाणीकरण

  • .auth.signUp({ email, password, options? }) → Promise<AuraResponse<LoginResponse>>
  • .auth.signInWithPassword({ email, password }) → Promise<AuraResponse<LoginResponse>>
  • .auth.signInWithOAuth(provider, opts?) | ({ provider, ... }) → Promise<AuraResponse<{ url }>>
  • .auth.getSession() → Promise<{ data: { session }, error }>
  • .auth.signOut() → Promise<AuraResponse<void>>
  • .auth.mfa.enroll() | .auth.mfaEnroll() → Promise<AuraResponse<MfaEnrollResponse>>

रियल टाइम

  • .channel(name, config?) → Channel
  • channel.on(event, filter, cb) → Channel
  • channel.subscribe() → Channel
  • channel.send({ type, event, payload }) → Promise<void>
  • channel.unsubscribe() → Promise<void>

भंडारण

  • .storage.from(bucket).upload(path, file, opts?) → Promise<{ data, error }>
  • .storage.from(bucket).download(path) → Promise<Blob>
  • .storage.from(bucket).getPublicUrl(path, opts?) → { publicUrl }
  • .storage.from(bucket).createSignedUrl(path, expiresIn) → Promise<{ signedUrl }>
  • .storage.from(bucket).remove(paths[]) → Promise<{ data, error }>

कार्य

  • .functions.invoke(name, { body?, method?, path?, headers?, responseType?, signal?, timeout? }) → Promise<{ data, error }>
  • .functions.list() → Promise<{ data: FunctionDef[], error }>
  • .functions.get(nameOrId) → Promise<{ data: FunctionDef, error }>
  • .functions.listJobs({ status?, limit? }) → Promise<{ data: Job[], error }>
  • .functions.getJob(jobId) → Promise<{ data: Job, error }>
  • .functions.enqueueJob(functionName, { payload?, delaySecs?, maxAttempts? }) → Promise<{ data: Job, error }>
  • .functions.listCronJobs() → Promise<{ data: CronJob[], error }>
  • .functions.createCronJob(name, schedule, functionName, { payload? }) → Promise<{ data: CronJob, error }>
  • .functions.deleteCronJob(name) → Promise<{ data, error }>

केवल invoke सार्वजनिक (anon) कुंजी के लिए खुला है। list, get, listJobs, getJob, enqueueJob, listCronJobs, createCronJob और deleteCronJob को service_role कुंजी की आवश्यकता होती है और यह आपके सर्वर पर होती है: FunctionDef में फ़ंक्शन का स्रोत कोड और पर्यावरण चर होते हैं, इसलिए ये कॉल उत्तर देते हैं सार्वजनिक कुंजी के लिए 403। invoke त्रुटियों को FunctionsHttpError (फ़ंक्शन एक त्रुटि, किसी भी स्थिति के साथ उत्तर दिया गया) या FunctionsRelayError (प्लेटफ़ॉर्म विफल: नेटवर्क, 502, 503, 504) के रूप में रिपोर्ट करता है, दोनों को @aurabase/aurabase-js द्वारा निर्यात किया जाता है।

एकसमान आकार { डेटा, त्रुटि }#

प्रत्येक async विधि { data, error } लौटाती है। error सफलता पर null है, अन्यथा code, message, status और details के साथ एक AuraError उदाहरण (उपनाम AurabaseError के तहत भी निर्यात किया जाता है)। यदि आपका स्कीमा Number.MAX_SAFE_INTEGER से आगे 64-बिट bigint मानों का उपयोग करता है, तो createClient विकल्पों में { parseBigIntAsString: true } पास करें।

errors.tstypescript
import { AurabaseError } from '@aurabase/aurabase-js'

const { data, error } = await aura.from('users').select('*').single()

if (error) {
  if (error.code === 'PGRST116') notFound()
  throw error // AuraError / AurabaseError का उदाहरण
}

आगे जाने के लिए#