{"id":20181726,"url":"https://github.com/nichoth/replicache-supabase","last_synced_at":"2025-07-23T11:37:26.708Z","repository":{"id":208020457,"uuid":"720621542","full_name":"nichoth/replicache-supabase","owner":"nichoth","description":"Use replicache with supabase","archived":false,"fork":false,"pushed_at":"2023-11-26T04:08:02.000Z","size":55,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-16T07:08:49.038Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nichoth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-19T03:29:57.000Z","updated_at":"2023-12-01T13:44:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"2afe53cc-db6c-45c1-8bcf-25801f892ede","html_url":"https://github.com/nichoth/replicache-supabase","commit_stats":null,"previous_names":["nichoth/replicache-supabase"],"tags_count":9,"template":false,"template_full_name":"nichoth/template-ts-browser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Freplicache-supabase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Freplicache-supabase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Freplicache-supabase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Freplicache-supabase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nichoth","download_url":"https://codeload.github.com/nichoth/replicache-supabase/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233779526,"owners_count":18728936,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T02:36:31.118Z","updated_at":"2025-01-13T17:22:23.902Z","avatar_url":"https://github.com/nichoth.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# replicache supabase\n![tests](https://github.com/nichoth/replicache-supabase/actions/workflows/nodejs.yml/badge.svg)\n[![Socket Badge](https://socket.dev/api/badge/npm/package/@nichoth/replicache-supabase)](https://socket.dev/npm/package/@nichoth/replicache-supabase)\n[![types](https://img.shields.io/npm/types/@nichoth/replicache-supabase)](README.md)\n[![module](https://img.shields.io/badge/module-ESM-blue)](README.md)\n[![license](https://img.shields.io/badge/license-MIT-brightgreen)](LICENSE)\n\nUse [replicache](https://replicache.dev/) with [supabase](https://supabase.com/).\n\nThis is some glue code for [replicache](https://replicache.dev/) and [supabase](https://supabase.com/). Use it in your lambda functions.\n\nThis is using the [global version strategy](https://doc.replicache.dev/strategies/global-version).\n\n## install\n```sh\nnpm i -S @nichoth/replicache-supabase\n```\n\n## globals\n\n### env vars\nWe need several environment variables for the DB:\n\n```sh\nSUPABASE_ANON_KEY=\"eyJhbGc...\"\nSUPABASE_DATABASE_PASSWORD=\"123abc\"\nSUPABASE_URL=\"https://my-url.supabase.co\"\n```\n\n## example\n\n### push\nUse this in a lambda function.\n\n```js\n// netlify/functions/replicache-push/replicache-push.ts\nimport 'dotenv/config'\nimport { Handler, HandlerEvent } from '@netlify/functions'\nimport { processPush, PushRequestSchema } from '@nichoth/replicache-supabase/push'\n// mutators are specific to your application\nimport { Mutators } from '../../../example/mutators.js'\n\nexport const handler:Handler = async function (ev:HandlerEvent) {\n    if (!ev.body) return { statusCode: 400 }\n\n    const userID = (ev.headers.cookie \u0026\u0026 ev.headers.cookie['userID']) || 'anon'\n    const body = JSON.parse(ev.body)\n    const push = PushRequestSchema.parse(body)\n\n    try {\n        await processPush(push, userID, Mutators())\n    } catch (err) {\n        return { statusCode: 500 }\n    }\n\n    return { statusCode: 200, body: 'OK' }\n}\n```\n\n### pull\nUse this in a lambda function.\n\n```js\n// netlify/functions/replicache-pull/replicache-pull.ts\nimport { Handler, HandlerEvent } from '@netlify/functions'\nimport {\n    authError,\n    processPull,\n    PullRequestSchema\n} from '@nichoth/replicache-supabase/pull'\n\nexport const handler:Handler = async function (ev:HandlerEvent) {\n    if (!ev.body) return { statusCode: 400 }\n    const userID = (ev.headers.cookie \u0026\u0026 ev.headers.cookie['userID']) || 'anon'\n    const body = JSON.parse(ev.body)\n\n    const pullRequest = PullRequestSchema.parse(body)\n\n    try {\n        const pullResponse = await processPull(pullRequest, userID)\n        return { statusCode: 200, body: JSON.stringify(pullResponse) }\n    } catch (err) {\n        if (err === authError) {\n            return { statusCode: 401, body: 'Unauthorized' }\n        } else {\n            return {\n                statusCode: 500,\n                body: 'Error processing pull: ' + err.toString()\n            }\n        }\n    }\n}\n```\n\n## test\n\nRun the test like this\n```sh\nnpx esbuild test/index.ts --format=cjs --platform=node --bundle | node\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnichoth%2Freplicache-supabase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnichoth%2Freplicache-supabase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnichoth%2Freplicache-supabase/lists"}