Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/svelte-db-provider-declarations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/svelte-db': patch
---

Fix the published DbProvider declarations so TypeScript can resolve the component and its props without Svelte-specific tooling.
2 changes: 2 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ jobs:
run: pnpm run build
- name: Check that no build carries an oracle probe
run: node scripts/check-dist-probes.mjs
- name: Check package exports and types
run: pnpm run test:build
- name: Publish Previews
run: pnpx pkg-pr-new publish --pnpm --compact './packages/*' --template './examples/*/*'
size:
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"scripts": {
"build": "pnpm --filter \"./packages/**\" build",
"build:minified": "pnpm --filter \"./packages/**\" build:minified",
"test:build": "node --test scripts/check-built-package.test.mjs && pnpm --no-sort --filter \"./packages/**\" test:build",
"changeset": "changeset",
"changeset:publish": "node scripts/publish-packages.mjs",
"changeset:version": "node scripts/version-packages.mjs",
Expand Down Expand Up @@ -44,6 +45,7 @@
"test:collection-adapters:oracles:browser": "node scripts/run-collection-adapter-oracles.mjs --browser"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.18.5",
"@changesets/apply-release-plan": "7.1.1",
"@changesets/assemble-release-plan": "6.0.10",
"@changesets/cli": "^2.31.1",
Expand All @@ -67,6 +69,7 @@
"@typescript-eslint/eslint-plugin": "^8.72.1",
"@typescript-eslint/parser": "^8.72.1",
"@vitejs/plugin-react": "^6.2.1",
"cross-spawn": "7.0.6",
"esbuild": "0.28.2",
"eslint": "^9.39.5",
"eslint-import-resolver-typescript": "^4.4.5",
Expand Down
1 change: 1 addition & 0 deletions packages/angular-db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"test": "vitest --run",
"lint": "eslint . --fix"
Expand Down
1 change: 1 addition & 0 deletions packages/browser-db-sqlite-persistence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs --profile node16 --exclude-entrypoints ./wa-sqlite.wasm ./opfs-worker.js",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/capacitor-db-sqlite-persistence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs --profile node16",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/convex-db-collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs --profile node16",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest run",
Expand Down
1 change: 1 addition & 0 deletions packages/db-ivm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/db-sqlite-persistence-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs --profile node16",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"scripts": {
"build": "vite build",
"build:minified": "vite build --minify",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/electric-db-collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest run",
Expand Down
1 change: 1 addition & 0 deletions packages/electron-db-sqlite-persistence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs --profile node16",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/expo-db-sqlite-persistence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs --profile node16",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/node-db-sqlite-persistence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/offline-transactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs --profile node16",
"dev": "vite build --watch",
"test": "vitest",
"test:watch": "vitest --watch",
Expand Down
1 change: 1 addition & 0 deletions packages/powersync-db-collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/powersync-direct-db-collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/preact-db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs --profile esm-only",
"dev": "vite build --watch",
"test": "vitest --run",
"lint": "eslint . --fix"
Expand Down
1 change: 1 addition & 0 deletions packages/query-db-collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest run",
Expand Down
1 change: 1 addition & 0 deletions packages/react-db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"scripts": {
"build": "vite build && node scripts/check-use-client.mjs",
"build:minified": "vite build --minify",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"test": "vitest --run",
"lint": "eslint . --fix"
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-db-sqlite-persistence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs --profile node16",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/react-router-with-db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"scripts": {
"build": "vite build",
"build:minified": "vite build --minify",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run"
Expand Down
1 change: 1 addition & 0 deletions packages/rxdb-db-collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/solid-db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs --profile esm-only",
"dev": "vite build --watch",
"test": "vitest --run",
"lint": "eslint . --fix"
Expand Down
1 change: 1 addition & 0 deletions packages/svelte-db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"scripts": {
"build": "svelte-package --input ./src --output ./dist --tsconfig ./tsconfig.build.json",
"test:build": "tsc --noEmit --strict --skipLibCheck --target ES2022 --module NodeNext scripts/check-provider-types.mts && tsc --noEmit --strict --skipLibCheck --target ES2022 --module ESNext --moduleResolution Bundler scripts/check-provider-types.mts && node ../../scripts/check-built-package.mjs --profile esm-only",
"lint": "eslint . --fix",
"test": "vitest --run",
"test:types": "svelte-check --tsconfig ./tsconfig.json"
Expand Down
24 changes: 24 additions & 0 deletions packages/svelte-db/scripts/check-provider-types.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Resolve the public export and compare it with the declaration generated from the component.
import type { DbProvider } from '@tanstack/svelte-db'
import type SourceProvider from '../dist/DbProvider.svelte.d.ts'
import type { DbClient } from '@tanstack/db'
import type { Component, Snippet } from 'svelte'

type Equal<Left, Right> =
(<T>() => T extends Left ? 1 : 2) extends <T>() => T extends Right ? 1 : 2
? true
: false
type Assert<T extends true> = T
type PublicProvider = typeof DbProvider
type ExpectedProvider = Component<
{ client: DbClient; hydrating?: boolean; children?: Snippet },
Record<never, never>,
''
>
export type PublicContract = Assert<Equal<PublicProvider, ExpectedProvider>>
export type AgreesWithComponent = Assert<
Equal<PublicProvider, typeof SourceProvider>
>
export type InstanceContract = Assert<
Equal<DbProvider, ReturnType<ExpectedProvider>>
>
10 changes: 2 additions & 8 deletions packages/svelte-db/src/DbProvider.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
<script lang="ts">
import { onMount } from 'svelte'
import { setDbClientContext, useDbContext } from './db-context.js'
import type { DbClient } from '@tanstack/db'
import type { Snippet } from 'svelte'
import type { DbProviderProps } from './db-context.js'

let {
client,
hydrating = useDbContext()?.hydrating ?? false,
children,
}: {
client: DbClient
/** Set for a root initialized with Svelte hydrate(); nested providers inherit. */
hydrating?: boolean
children?: Snippet
} = $props()
}: DbProviderProps = $props()

// The host supplies hydration intent. New children after this provider's
// mount read live rows, even while transported server snapshots are retained.
Expand Down
8 changes: 8 additions & 0 deletions packages/svelte-db/src/db-context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { getContext, setContext } from 'svelte'
import type { DbClient } from '@tanstack/db'
import type { Snippet } from 'svelte'

export type DbProviderProps = {
client: DbClient
/** Set for a root initialized with Svelte hydrate(); nested providers inherit. */
hydrating?: boolean
children?: Snippet
}

const dbClientContext = Symbol.for(`@tanstack/svelte-db.DbClient`)
type DbClientContext = () => DbClient
Expand Down
12 changes: 11 additions & 1 deletion packages/svelte-db/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import SvelteDbProvider from './DbProvider.svelte'
import type { Component } from 'svelte'
import type { DbProviderProps } from './db-context.js'

// Re-export all public APIs
export * from './useLiveQuery.svelte.js'
export * from './useLiveInfiniteQuery.svelte.js'
export { useDbClient, useOptionalDbClient } from './db-context.js'
export { default as DbProvider } from './DbProvider.svelte'
// Give the package declaration a type that plain TypeScript can resolve.
export const DbProvider: Component<
DbProviderProps,
Record<never, never>,
''
> = SvelteDbProvider
export type DbProvider = ReturnType<typeof DbProvider>

// Re-export everything from @tanstack/db
export * from '@tanstack/db'
Expand Down
1 change: 1 addition & 0 deletions packages/tauri-db-sqlite-persistence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs --profile node16",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/trailbase-db-collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"lint": "eslint . --fix",
"test": "vitest --run",
Expand Down
1 change: 1 addition & 0 deletions packages/vue-db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"scripts": {
"build": "vite build",
"test:build": "node ../../scripts/check-built-package.mjs",
"dev": "vite build --watch",
"test": "vitest --run",
"lint": "eslint . --fix"
Expand Down
Loading
Loading