mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 01:15:03 +03:00
docs: Update old Deno usage (#45934)
This commit is contained in:
1 parent
ebfec0df36
commit
2024855c8d
5 files changed
+10
-15
No files matched your search
@@ -39,9 +39,9 @@ supabase gen types typescript --project-id=your-project-ref --schema=storage,pub
|
||||
Find the complete code on [GitHub](https://github.com/supabase/supabase/tree/master/examples/edge-functions/supabase/functions/huggingface-image-captioning).
|
||||
|
||||
```ts
|
||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
|
||||
import { HfInference } from 'https://esm.sh/@huggingface/inference@2.3.2'
|
||||
import { createClient } from 'npm:@supabase/supabase-js@2'
|
||||
|
||||
import { Database } from './types.ts'
|
||||
|
||||
console.log('Hello from `huggingface-image-captioning` function!')
|
||||
@@ -57,7 +57,7 @@ interface WebhookPayload {
|
||||
old_record: null | SoRecord
|
||||
}
|
||||
|
||||
serve(async (req) => {
|
||||
Deno.serve(async (req) => {
|
||||
const payload: WebhookPayload = await req.json()
|
||||
const soRecord = payload.record
|
||||
const SUPABASE_SECRET_KEYS = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)
|
||||
|
||||
@@ -94,12 +94,11 @@ HUGGING_FACE_ACCESS_TOKEN=<your-token-here>
|
||||
Let's modify the Edge Function to import Hugging Face's inference client and perform a `text-to-image` request:
|
||||
|
||||
```ts
|
||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
|
||||
import { HfInference } from 'https://esm.sh/@huggingface/inference@2.3.2'
|
||||
|
||||
const hf = new HfInference(Deno.env.get('HUGGING_FACE_ACCESS_TOKEN'))
|
||||
|
||||
serve(async (req) => {
|
||||
Deno.serve(async (req) => {
|
||||
const { prompt } = await req.json()
|
||||
|
||||
const image = await hf.textToImage(
|
||||
|
||||
@@ -182,9 +182,7 @@ Custom Access Token Hooks are triggered for **all** token issuance. Use `client_
|
||||
A common use case is customizing the `audience` claim for different OAuth clients. This allows third-party services to validate that tokens were issued specifically for them:
|
||||
|
||||
```typescript
|
||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
|
||||
|
||||
serve(async (req) => {
|
||||
Deno.serve(async (req) => {
|
||||
const { user, claims, client_id } = await req.json()
|
||||
|
||||
// Customize audience based on OAuth client
|
||||
@@ -230,10 +228,9 @@ The `audience` claim is especially important for:
|
||||
You can also add custom claims and metadata based on the OAuth client:
|
||||
|
||||
```typescript
|
||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
|
||||
|
||||
serve(async (req) => {
|
||||
Deno.serve(async (req) => {
|
||||
const { user, claims, client_id } = await req.json()
|
||||
|
||||
const supabase = createClient(Deno.env.get('SUPABASE_URL')!, Deno.env.get('SUPABASE_SECRET_KEY')!)
|
||||
|
||||
@@ -34,6 +34,7 @@ GET YOUR CERT FROM YOUR PROJECT DASHBOARD
|
||||
Create a `DenoPostgresDriver.ts` file to manage the connection to Postgres via [deno-postgres](https://deno-postgres.com/):
|
||||
|
||||
```ts DenoPostgresDriver.ts
|
||||
import { Pool, PoolClient } from 'https://deno.land/x/postgres@v0.17.0/mod.ts'
|
||||
import {
|
||||
CompiledQuery,
|
||||
DatabaseConnection,
|
||||
@@ -44,7 +45,6 @@ import {
|
||||
} from 'https://esm.sh/kysely@0.23.4'
|
||||
import { freeze, isFunction } from 'https://esm.sh/kysely@0.23.4/dist/esm/util/object-utils.js'
|
||||
import { extendStackTrace } from 'https://esm.sh/kysely@0.23.4/dist/esm/util/stack-trace-utils.js'
|
||||
import { Pool, PoolClient } from 'https://deno.land/x/postgres@v0.17.0/mod.ts'
|
||||
|
||||
export interface PostgresDialectConfig {
|
||||
pool: Pool | (() => Promise<Pool>)
|
||||
@@ -190,15 +190,15 @@ class PostgresConnection implements DatabaseConnection {
|
||||
Create an `index.ts` file to execute a query on incoming requests:
|
||||
|
||||
```ts index.ts
|
||||
import { serve } from 'https://deno.land/std@0.175.0/http/server.ts'
|
||||
import { Pool } from 'https://deno.land/x/postgres@v0.17.0/mod.ts'
|
||||
import {
|
||||
Kysely,
|
||||
Generated,
|
||||
Kysely,
|
||||
PostgresAdapter,
|
||||
PostgresIntrospector,
|
||||
PostgresQueryCompiler,
|
||||
} from 'https://esm.sh/kysely@0.23.4'
|
||||
|
||||
import { PostgresDriver } from './DenoPostgresDriver.ts'
|
||||
|
||||
console.log(`Function "kysely-postgres" up and running!`)
|
||||
@@ -245,7 +245,7 @@ const db = new Kysely<Database>({
|
||||
},
|
||||
})
|
||||
|
||||
serve(async (_req) => {
|
||||
Deno.serve(async (_req) => {
|
||||
try {
|
||||
// Run a query
|
||||
const animals = await db.selectFrom('animals').select(['id', 'animal', 'created_at']).execute()
|
||||
|
||||
@@ -23,14 +23,13 @@ set SLACK_TOKEN=<xoxb-0000000000-0000000000-01010101010nacho101010>
|
||||
Here's the code of the Edge Function, you can change the response to handle the text received:
|
||||
|
||||
```ts index.ts
|
||||
import { serve } from 'https://deno.land/std@0.197.0/http/server.ts'
|
||||
import { WebClient } from 'https://deno.land/x/slack_web_api@6.7.2/mod.js'
|
||||
|
||||
const slackBotToken = Deno.env.get('SLACK_TOKEN') ?? ''
|
||||
const botClient = new WebClient(slackBotToken)
|
||||
|
||||
console.log(`Slack URL verification function up and running!`)
|
||||
serve(async (req) => {
|
||||
Deno.serve(async (req) => {
|
||||
try {
|
||||
const reqBody = await req.json()
|
||||
console.log(JSON.stringify(reqBody, null, 2))
|
||||
|
||||
Reference in new issue
Block a user