-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4580bb5
commit d2430c0
Showing
23 changed files
with
1,895 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
export function isPlainObject(wat) { | ||
return Object.prototype.toString.call(wat) === "[object Object]"; | ||
} | ||
|
||
export const DEFAULT_OPTIONS = { | ||
tracing: true, | ||
breadcrumbs: true, | ||
errors: false, | ||
operations: [...AVAILABLE_OPERATIONS], | ||
shouldCreateSpan: undefined, | ||
shouldCreateBreadcrumb: undefined, | ||
sanitizeBody: undefined, | ||
}; | ||
|
||
export function validateOption(availableOptions, key, value) { | ||
if (!availableOptions.includes(key)) { | ||
throw new Error(`Unknown option: ${key}`); | ||
} | ||
|
||
if (key === "operations") { | ||
if (!Array.isArray(value)) { | ||
throw new TypeError(`operations should be an array`); | ||
} | ||
|
||
for (const operation of value) { | ||
if (!AVAILABLE_OPERATIONS.includes(operation)) { | ||
throw new Error(`Unknown operation: ${operation}`); | ||
} | ||
} | ||
} | ||
|
||
if (key === "shouldCreateSpan" && typeof value !== "function") { | ||
throw new TypeError( | ||
"shouldCreateSpan should be a function that returns a boolean" | ||
); | ||
} | ||
|
||
if (key === "shouldCreateBreadcrumb" && typeof value !== "function") { | ||
throw new TypeError( | ||
"shouldCreateBreadcrumb should be a function that returns a boolean" | ||
); | ||
} | ||
|
||
if (key === "sanitizeBody" && typeof value !== "function") { | ||
throw new TypeError( | ||
"sanitizeBody should be a function that returns a valid data object" | ||
); | ||
} | ||
} | ||
|
||
export const AVAILABLE_OPERATIONS = [ | ||
"select", | ||
"insert", | ||
"upsert", | ||
"update", | ||
"delete", | ||
]; | ||
|
||
export function extractOperation(method, headers = {}) { | ||
switch (method) { | ||
case "GET": { | ||
return "select"; | ||
} | ||
case "POST": { | ||
if (headers["Prefer"]?.includes("resolution=")) { | ||
return "upsert"; | ||
} else { | ||
return "insert"; | ||
} | ||
} | ||
case "PATCH": { | ||
return "update"; | ||
} | ||
case "DELETE": { | ||
return "delete"; | ||
} | ||
} | ||
} | ||
|
||
export const FILTER_MAPPINGS = { | ||
eq: "eq", | ||
neq: "neq", | ||
gt: "gt", | ||
gte: "gte", | ||
lt: "lt", | ||
lte: "lte", | ||
like: "like", | ||
"like(all)": "likeAllOf", | ||
"like(any)": "likeAnyOf", | ||
ilike: "ilike", | ||
"ilike(all)": "ilikeAllOf", | ||
"ilike(any)": "ilikeAnyOf", | ||
is: "is", | ||
in: "in", | ||
cs: "contains", | ||
cd: "containedBy", | ||
sr: "rangeGt", | ||
nxl: "rangeGte", | ||
sl: "rangeLt", | ||
nxr: "rangeLte", | ||
adj: "rangeAdjacent", | ||
ov: "overlaps", | ||
fts: "", | ||
plfts: "plain", | ||
phfts: "phrase", | ||
wfts: "websearch", | ||
not: "not", | ||
}; | ||
|
||
export function translateFiltersIntoMethods(key, query) { | ||
if (query === "" || query === "*") { | ||
return `select(*)`; | ||
} | ||
|
||
if (key === "select") { | ||
return `select(${query})`; | ||
} | ||
|
||
if (key === "or" || key.endsWith(".or")) { | ||
return `${key}${query}`; | ||
} | ||
|
||
const [filter, ...value] = query.split("."); | ||
|
||
let method; | ||
// Handle optional `configPart` of the filter | ||
if (filter.startsWith("fts")) { | ||
method = "textSearch"; | ||
} else if (filter.startsWith("plfts")) { | ||
method = "textSearch[plain]"; | ||
} else if (filter.startsWith("phfts")) { | ||
method = "textSearch[phrase]"; | ||
} else if (filter.startsWith("wfts")) { | ||
method = "textSearch[websearch]"; | ||
} else { | ||
method = FILTER_MAPPINGS[filter] || "filter"; | ||
} | ||
|
||
return `${method}(${key}, ${value.join(".")})`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"@sentry/browser": "https://esm.sh/@sentry/browser@8.2.1", | ||
"@supabase/supabase-js": "https://esm.sh/@supabase/supabase-js@2.43.2", | ||
"@supabase/sentry-js-integration": "./integration.js" | ||
} | ||
} | ||
</script> | ||
<script type="module"> | ||
import * as Sentry from "@sentry/browser"; | ||
import { createClient } from "@supabase/supabase-js"; | ||
import { supabaseIntegration } from "@supabase/sentry-js-integration"; | ||
|
||
const supabaseClient = createClient( | ||
"https://ktrpkblcwnulhtgpcrbp.supabase.co", | ||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imt0cnBrYmxjd251bGh0Z3BjcmJwIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDY3ODk0OTAsImV4cCI6MjAyMjM2NTQ5MH0.CXEvu4tYFRXtwYvMFllhAwyu1NsyUmaqhgxfHFhzOHA" | ||
); | ||
|
||
Sentry.init({ | ||
dsn: "https://dsn@sentry.io/1337", | ||
tracesSampleRate: 1.0, | ||
integrations: [ | ||
Sentry.browserTracingIntegration(), | ||
supabaseIntegration(supabaseClient, Sentry, { | ||
tracing: true, | ||
breadcrumbs: true, | ||
errors: true, | ||
}), | ||
], | ||
beforeSend(event) { | ||
console.log("Captured exception:", event); | ||
return null; // Do not send captured exception | ||
}, | ||
beforeSendTransaction(event) { | ||
console.log("Captured transaction:", event); | ||
return null; // Do not send transaction | ||
}, | ||
}); | ||
|
||
// Capture some trace and breadcrumbs via `tracing: true` and `breadcrumbs: true` | ||
{ | ||
const { data, error } = await supabaseClient.from("jokes").select("*"); | ||
console.log("jokes response:"); | ||
console.log({ data }); | ||
console.log({ error }); | ||
} | ||
|
||
// Capture broken calls as exceptions | ||
{ | ||
const { data, error } = await supabaseClient | ||
.from("unknown-table") | ||
.select("*"); | ||
console.log("unknown-table response:"); | ||
console.log({ data }); | ||
console.log({ error }); | ||
} | ||
|
||
Sentry.captureException(new Error("show me the money")); | ||
</script> | ||
</head> | ||
<body> | ||
<h1>Hello there! Open DevTools to see what's going on.</h1> | ||
</body> | ||
</html> |
Oops, something went wrong.