├── .changeset ├── README.md └── config.json ├── .env.example ├── .github ├── dependabot.yml └── workflows │ ├── dependabot.yml │ └── release.yml ├── .gitignore ├── .npmrc ├── .prettierignore ├── .prettierrc ├── CHANGELOG.md ├── LICENSE ├── README.md ├── eslint.config.js ├── package.json ├── pnpm-lock.yaml ├── src ├── app.d.ts ├── app.html ├── lib │ ├── Cursors.svelte │ ├── InstantSvelteAbstractDatabase.svelte.ts │ ├── InstantSvelteWebDatabase.ts │ ├── index.ts │ ├── init.ts │ ├── useQuery.svelte.ts │ ├── useTimeout.svelte.ts │ ├── utils.ts │ └── version.ts ├── routes │ ├── +page.svelte │ ├── auth │ │ └── +page.svelte │ ├── cursors │ │ └── +page.svelte │ ├── todos │ │ └── +page.svelte │ └── typing-indicator │ │ └── +page.svelte └── vite-env.d.ts ├── static └── favicon.png ├── svelte.config.js ├── tsconfig.json ├── vite.config.ts └── vite.version.ts /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@3.0.3/schema.json", 3 | "changelog": "@changesets/cli/changelog", 4 | "commit": false, 5 | "fixed": [], 6 | "linked": [], 7 | "access": "public", 8 | "baseBranch": "main", 9 | "updateInternalDependencies": "patch", 10 | "ignore": [] 11 | } 12 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | PUBLIC_INSTANT_APP_ID= 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: npm 9 | directory: / 10 | schedule: 11 | interval: daily 12 | allow: 13 | - dependency-name: '@instantdb/core' 14 | versioning-strategy: increase 15 | -------------------------------------------------------------------------------- /.github/workflows/dependabot.yml: -------------------------------------------------------------------------------- 1 | name: Add changeset to Dependabot updates 2 | 3 | on: 4 | pull_request_target: 5 | types: [opened, synchronize, labeled] 6 | 7 | jobs: 8 | dependabot: 9 | name: Update Dependabot PR 10 | runs-on: ubuntu-latest 11 | if: contains(github.event.pull_request.labels.*.name, 'dependencies') 12 | 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v4 16 | with: 17 | fetch-depth: 0 18 | ref: ${{ github.event.pull_request.head.ref }} 19 | - name: Update PR 20 | uses: StafflinePeoplePlus/dependabot-changesets@v0.1.5 21 | with: 22 | owner: wobsoriano 23 | repo: svelte-instantdb 24 | pr-number: ${{ github.event.pull_request.number }} 25 | token: ${{ secrets.GITHUB_TOKEN }} 26 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | concurrency: ${{ github.workflow }}-${{ github.ref }} 9 | 10 | jobs: 11 | release: 12 | permissions: 13 | contents: write # to create release (changesets/action) 14 | pull-requests: write # to create pull request (changesets/action) 15 | name: Release 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Checkout Repo 19 | uses: actions/checkout@v4 20 | with: 21 | # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits 22 | fetch-depth: 0 23 | - uses: pnpm/action-setup@v4 24 | with: 25 | version: 10.6.3 26 | 27 | - name: Setup Node.js 28 | uses: actions/setup-node@v4 29 | with: 30 | node-version: 22.x 31 | cache: pnpm 32 | 33 | - name: Install dependencies 34 | run: pnpm install --frozen-lockfile 35 | 36 | - name: Create Release Pull Request or Publish to npm 37 | id: changesets 38 | uses: changesets/action@v1 39 | with: 40 | publish: pnpm release 41 | env: 42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | # Output 4 | .output 5 | .vercel 6 | /.svelte-kit 7 | /build 8 | /dist 9 | 10 | # OS 11 | .DS_Store 12 | Thumbs.db 13 | 14 | # Env 15 | .env 16 | .env.* 17 | !.env.example 18 | !.env.test 19 | 20 | # Vite 21 | vite.config.js.timestamp-* 22 | vite.config.ts.timestamp-* 23 | 24 | .cursorrules -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | engine-strict=true 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # Package Managers 2 | package-lock.json 3 | pnpm-lock.yaml 4 | yarn.lock 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "useTabs": true, 3 | "singleQuote": true, 4 | "trailingComma": "none", 5 | "printWidth": 100, 6 | "plugins": ["prettier-plugin-svelte"], 7 | "overrides": [ 8 | { 9 | "files": "*.svelte", 10 | "options": { 11 | "bracketSameLine": false, 12 | "parser": "svelte" 13 | } 14 | }, 15 | { 16 | "files": ["README.md", "**/package.json"], 17 | "options": { 18 | "useTabs": false, 19 | "tabWidth": 2 20 | } 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # svelte-instantdb 2 | 3 | ## 0.4.23 4 | 5 | ### Patch Changes 6 | 7 | - b1bc13d: Bump @instantdb/core from 0.19.10 to 0.19.14 8 | 9 | ## 0.4.22 10 | 11 | ### Patch Changes 12 | 13 | - 6995a2f: Bump @instantdb/core from 0.19.7 to 0.19.10 14 | 15 | ## 0.4.21 16 | 17 | ### Patch Changes 18 | 19 | - c37aea9: Bump @instantdb/core from 0.19.6 to 0.19.7 20 | 21 | ## 0.4.20 22 | 23 | ### Patch Changes 24 | 25 | - 22daffa: Bump @instantdb/core from 0.18.9 to 0.19.6 26 | 27 | ## 0.4.19 28 | 29 | ### Patch Changes 30 | 31 | - 3dae89e: Bump @instantdb/core from 0.18.5 to 0.18.9 32 | 33 | ## 0.4.18 34 | 35 | ### Patch Changes 36 | 37 | - 1325fea: Bump @instantdb/core from 0.18.2 to 0.18.5 38 | 39 | ## 0.4.17 40 | 41 | ### Patch Changes 42 | 43 | - 5c06245: Bump @instantdb/core from 0.17.33 to 0.18.2 44 | - 3a1fedf: Support params in queries and transactions 45 | 46 | Use in queries: 47 | 48 | ```ts 49 | db.useQuery({ docs: {} }, { secret: secret }); 50 | ``` 51 | 52 | and transactions: 53 | 54 | ```ts 55 | db.transact(db.tx.docs[id].ruleParams({ secret: secret }).update({ title: 'eat' })); 56 | ``` 57 | 58 | ## 0.4.16 59 | 60 | ### Patch Changes 61 | 62 | - ab5b089: Bump @instantdb/core from 0.17.32 to 0.17.33 63 | 64 | ## 0.4.15 65 | 66 | ### Patch Changes 67 | 68 | - a5d2f15: Bump @instantdb/core from 0.17.31 to 0.17.32 69 | 70 | ## 0.4.14 71 | 72 | ### Patch Changes 73 | 74 | - 6477b22: Bump @instantdb/core from 0.17.29 to 0.17.31 75 | - 9791baa: Add `useLocalId()` helper, a wrapper around `getLocalId` promise that returns a reactive state. Initially returns `null` and then loads the `localId`. 76 | 77 | ## 0.4.13 78 | 79 | ### Patch Changes 80 | 81 | - 1456c6d: Bump @instantdb/core from 0.17.27 to 0.17.29 82 | 83 | ## 0.4.12 84 | 85 | ### Patch Changes 86 | 87 | - 8ab50b7: Bump @instantdb/core from 0.17.24 to 0.17.27 88 | 89 | ## 0.4.11 90 | 91 | ### Patch Changes 92 | 93 | - 021bba5: Bump @instantdb/core from 0.17.22 to 0.17.24 94 | 95 | ## 0.4.10 96 | 97 | ### Patch Changes 98 | 99 | - 0c58915: Bump @instantdb/core from 0.17.21 to 0.17.22 100 | 101 | ## 0.4.9 102 | 103 | ### Patch Changes 104 | 105 | - 3e9a1a1: Bump @instantdb/core from 0.17.19 to 0.17.21 106 | 107 | ## 0.4.8 108 | 109 | ### Patch Changes 110 | 111 | - 95c99f9: Bump @instantdb/core from 0.17.15 to 0.17.19 112 | 113 | ## 0.4.7 114 | 115 | ### Patch Changes 116 | 117 | - 6110d87: Bump @instantdb/core from 0.17.12 to 0.17.15 118 | 119 | ## 0.4.6 120 | 121 | ### Patch Changes 122 | 123 | - 1ffb133: Bump @instantdb/core from 0.17.10 to 0.17.12 124 | 125 | ## 0.4.5 126 | 127 | ### Patch Changes 128 | 129 | - d3731ad: Bump @instantdb/core from 0.17.6 to 0.17.10 130 | 131 | ## 0.4.4 132 | 133 | ### Patch Changes 134 | 135 | - 372eb46: Bump @instantdb/core from 0.17.5 to 0.17.6 136 | 137 | ## 0.4.3 138 | 139 | ### Patch Changes 140 | 141 | - e6a58c6: Bump @instantdb/core from 0.17.4 to 0.17.5 142 | 143 | ## 0.4.2 144 | 145 | ### Patch Changes 146 | 147 | - 8dfafb4: Bump @instantdb/core from 0.17.3 to 0.17.4 148 | 149 | ## 0.4.1 150 | 151 | ### Patch Changes 152 | 153 | - 591f8e4: Bump @instantdb/core from 0.17.2 to 0.17.3 154 | 155 | ## 0.4.0 156 | 157 | ### Minor Changes 158 | 159 | - 1a8f094: Implement typesafe init and remove stores export 160 | 161 | ### Patch Changes 162 | 163 | - 97944c3: Make sure version is autogenerated 164 | 165 | ## 0.3.4 166 | 167 | ### Patch Changes 168 | 169 | - 4ab22e8: Bump @instantdb/core from 0.15.5 to 0.16.3 170 | 171 | ## 0.3.3 172 | 173 | ### Patch Changes 174 | 175 | - 9b714a8: Bump @instantdb/core from 0.14.30 to 0.15.5 176 | 177 | ## 0.3.2 178 | 179 | ### Patch Changes 180 | 181 | - 1dc021f: Bump @instantdb/core from 0.14.29 to 0.14.30 182 | 183 | ## 0.3.1 184 | 185 | ### Patch Changes 186 | 187 | - 011500b: Bump @instantdb/core from 0.14.27 to 0.14.29 188 | 189 | ## 0.3.0 190 | 191 | ### Minor Changes 192 | 193 | - 7fab8f5: Fix state returned by functions by introducing a `current` getter. 194 | 195 | ```svelte 196 | 209 | 210 | {#if query.current.isLoading} 211 |
Fetching data...
212 | {:else if query.current.error} 213 |
Error fetching data: {query.current.error.message}
214 | {:else} 215 | 216 | {/if} 217 | ``` 218 | 219 | ## 0.2.4 220 | 221 | ### Patch Changes 222 | 223 | - dd28857: Bump @instantdb/core from 0.14.26 to 0.14.27 224 | 225 | ## 0.2.3 226 | 227 | ### Patch Changes 228 | 229 | - 18ecc68: Bump @instantdb/core from 0.14.25 to 0.14.26 230 | 231 | ## 0.2.2 232 | 233 | ### Patch Changes 234 | 235 | - 3ee57cb: Bump @instantdb/core from 0.14.23 to 0.14.25 236 | 237 | ## 0.2.1 238 | 239 | ### Patch Changes 240 | 241 | - 22c9fca: Bump @instantdb/core from 0.14.22 to 0.14.23 242 | 243 | ## 0.2.0 244 | 245 | ### Minor Changes 246 | 247 | - 32eb266: First class Svelte 5 support 248 | 249 | ## 0.1.8 250 | 251 | ### Patch Changes 252 | 253 | - 374156e: Bump @instantdb/core from 0.14.19 to 0.14.22 254 | 255 | ## 0.1.7 256 | 257 | ### Patch Changes 258 | 259 | - b4c1569: Bump @instantdb/core from 0.14.18 to 0.14.19 260 | 261 | ## 0.1.6 262 | 263 | ### Patch Changes 264 | 265 | - 0eb6145: Do not subscribe to query when query is null 266 | - cf91ba5: Use new generics attribute for Cursors component 267 | 268 | ## 0.1.5 269 | 270 | ### Patch Changes 271 | 272 | - bbc8c31: Bump @instantdb/core from 0.14.13 to 0.14.18 273 | 274 | ## 0.1.4 275 | 276 | ### Patch Changes 277 | 278 | - ce7d74b: Bump @instantdb/core from 0.14.12 to 0.14.13 279 | 280 | ## 0.1.3 281 | 282 | ### Patch Changes 283 | 284 | - ff89838: Export more helper types 285 | - 53bbf17: Add a new `queryOnce` method which is `useQuery` but returns a promise. Ported from this [PR](https://github.com/instantdb/instant/pull/285). 286 | - 3e6bfcd: Fix generated types 287 | 288 | ## 0.1.2 289 | 290 | ### Patch Changes 291 | 292 | - dffa0df: Bump `@instantdb/core` to 0.14.0 293 | 294 | ## 0.1.1 295 | 296 | ### Patch Changes 297 | 298 | - 13d5721: Make db functions accept reactive values 299 | 300 | ## 0.1.0 301 | 302 | ### Minor Changes 303 | 304 | - 65cb845: Add Svelte 5 rune support 305 | 306 | ## 0.0.11 307 | 308 | ### Patch Changes 309 | 310 | - 6493824: Bump `@instantdb/core` to `0.13.2` 311 | 312 | ## 0.0.10 313 | 314 | ### Patch Changes 315 | 316 | - d75830a: Update package.json links 317 | 318 | ## 0.0.9 319 | 320 | ### Patch Changes 321 | 322 | - 7df76c2: Fix default cursor color 323 | 324 | ## 0.0.8 325 | 326 | ### Patch Changes 327 | 328 | - a3db05e: Fix rooms bug where we were sending events before receiving a join room 329 | 330 | ## 0.0.7 331 | 332 | ### Patch Changes 333 | 334 | - 9eabe84: Better typing indicator support 335 | 336 | ## 0.0.6 337 | 338 | ### Patch Changes 339 | 340 | - a3a8f31: Add Cursors support 341 | 342 | ## 0.0.5 343 | 344 | ### Patch Changes 345 | 346 | - ccac0a9: Add svelte 5 support 347 | 348 | ## 0.0.4 349 | 350 | ### Patch Changes 351 | 352 | - b421e0f: More updates 353 | 354 | ## 0.0.3 355 | 356 | ### Patch Changes 357 | 358 | - d540ff2: Add license and improvements 359 | 360 | ## 0.0.2 361 | 362 | ### Patch Changes 363 | 364 | - d3e0d26: Initial changeset 365 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Robert Soriano 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # svelte-instantdb 2 | 3 | Unofficial [Instant](http://instantdb.com/) SDK for Svelte 5. 4 | 5 | ## Installation 6 | 7 | ```bash 8 | npm install svelte-instantdb 9 | ``` 10 | 11 | ## Usage 12 | 13 | ### Reading and Writing Data 14 | 15 | ```svelte 16 | 29 | 30 | {#if query.current.isLoading} 31 |
Fetching data...
32 | {:else if query.current.error} 33 |
Error fetching data: {query.current.error.message}
34 | {:else} 35 | 36 | {/if} 37 | ``` 38 | 39 | ### Cursors 40 | 41 | ```svelte 42 | Move your cursor around! ✨ 43 | ``` 44 | 45 | Custom cursors 46 | 47 | ```svelte 48 | 49 | Move your cursor around! ✨ 50 | 51 | {#snippet cursor({ color, presence })} 52 | 53 | {/snippet} 54 | 55 | ``` 56 | 57 | ### Typing indicator 58 | 59 | ```svelte 60 | 87 | 88 |
89 |
90 | 67 |
68 | {#if typingIndicator.current.active.length} 69 | {typingInfo(typingIndicator.current.active)} 70 | {:else} 71 |   72 | {/if} 73 |
74 |
75 |
76 | 77 | 140 | -------------------------------------------------------------------------------- /src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | declare const __LIB_VERSION__: string; 2 | -------------------------------------------------------------------------------- /static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wobsoriano/svelte-instantdb/aac8a02cac6cd1089fb92e8e784305ba4b6d40c6/static/favicon.png -------------------------------------------------------------------------------- /svelte.config.js: -------------------------------------------------------------------------------- 1 | import adapter from '@sveltejs/adapter-auto'; 2 | import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; 3 | 4 | /** @type {import('@sveltejs/kit').Config} */ 5 | const config = { 6 | // Consult https://kit.svelte.dev/docs/integrations#preprocessors 7 | // for more information about preprocessors 8 | preprocess: vitePreprocess(), 9 | 10 | kit: { 11 | // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list. 12 | // If your environment is not supported, or you settled on a specific environment, switch out the adapter. 13 | // See https://kit.svelte.dev/docs/adapters for more information about adapters. 14 | adapter: adapter() 15 | } 16 | }; 17 | 18 | export default config; 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, 5 | "checkJs": true, 6 | "esModuleInterop": true, 7 | "forceConsistentCasingInFileNames": true, 8 | "resolveJsonModule": true, 9 | "skipLibCheck": true, 10 | "sourceMap": true, 11 | "module": "NodeNext", 12 | "moduleResolution": "NodeNext" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import { sveltekit } from '@sveltejs/kit/vite'; 2 | import { defineConfig } from 'vite'; 3 | import pkg from './package.json' with { type: 'json' }; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit()], 7 | define: { 8 | __LIB_VERSION__: JSON.stringify(`v${pkg.version}`) 9 | } 10 | }); 11 | -------------------------------------------------------------------------------- /vite.version.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import pkg from './package.json' with { type: 'json' }; 3 | 4 | // Why this extra Vite config? This is for adding the current library's version 5 | // and pass it to the InstantSvelteWebDatabase class option 6 | 7 | export default defineConfig({ 8 | build: { 9 | emptyOutDir: false, 10 | lib: { 11 | entry: 'src/lib/version.ts', 12 | formats: ['es'], 13 | fileName: 'version' 14 | } 15 | }, 16 | define: { 17 | __LIB_VERSION__: JSON.stringify(`v${pkg.version}`) 18 | } 19 | }); 20 | --------------------------------------------------------------------------------