Skip to content

Commit

Permalink
working refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
carlsverre committed Jan 4, 2024
1 parent 30a8c18 commit b9cd05e
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 3,423 deletions.
5 changes: 1 addition & 4 deletions examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"dev": "vite"
},
"dependencies": {
"react": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import workerUrl from "@orbitinghail/sqlsync-worker/worker.ts?url";
import { SQLSyncProvider, createDocHooks } from "@orbitinghail/sqlsync-react";

const DEMO_REDUCER_URL = new URL(
"../../../target/wasm32-unknown-unknown/debug/sqlsync_react_test_reducer.wasm",
"../../../target/wasm32-unknown-unknown/debug/count_reducer.wasm",
import.meta.url,
);

Expand Down
1 change: 1 addition & 0 deletions examples/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"types": ["vite/client"],

/* Bundler mode */
"moduleResolution": "bundler",
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ wasm-counter-reducer:
wasm-task-reducer:
cargo build --target wasm32-unknown-unknown --example task-reducer

wasm-sqlsync-react-test-reducer:
cargo build --target wasm32-unknown-unknown --package sqlsync-react-test-reducer
wasm-examples-count-reducer:
cargo build --target wasm32-unknown-unknown --package count-reducer

test-end-to-end-local rng_seed="": wasm-task-reducer
RUST_BACKTRACE=1 cargo run --example end-to-end-local {{rng_seed}}
Expand Down
31 changes: 21 additions & 10 deletions lib/sqlsync-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,46 @@
"type": "git",
"url": "https://github.com/orbitinghail/sqlsync"
},
"files": ["dist", "src"],
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": ["dist"],
"main": "./src/index.ts",
"exports": {
".": {
"import": "./src/index.ts",
"require": "./dist/index.js",
"default": "./src/index.ts",
"types": "./src/index.ts"
}
},
"publishConfig": {
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
}
}
},
"scripts": {
"build": "rollup --config"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.5",
"@types/react": "^18.2.31",
"@types/react-dom": "^18.2.14",
"@orbitinghail/sqlsync-worker": "workspace:^",
"rollup": "^3.29.4",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"@types/react": "^18.2.31",
"@types/react-dom": "^18.2.14"
"typescript": "^5.2.2"
},
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"@orbitinghail/sqlsync-worker": "workspace:^"
},
"dependencies": {
"fast-equals": "^5.0.1",
"@orbitinghail/sqlsync-worker": "workspace:^"
"fast-equals": "^5.0.1"
}
}
6 changes: 3 additions & 3 deletions lib/sqlsync-react/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export default {
input: "src/index.ts",
output: {
dir: "dist",
format: "umd",
format: "es",
sourcemap: true,
name: "SQLSyncReact",
},
plugins: [nodeResolve(), typescript()],
external: ["react", "@orbitinghail/sqlsync-worker"],
plugins: [typescript(), nodeResolve()],
};
4 changes: 2 additions & 2 deletions lib/sqlsync-react/src/context.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SQLSync } from "@orbitinghail/sqlsync-worker";
import { ReactNode, createContext, useEffect, useState } from "react";
import { ReactNode, createContext, createElement, useEffect, useState } from "react";

export const SQLSyncContext = createContext<SQLSync | null>(null);

Expand All @@ -23,6 +23,6 @@ export const SQLSyncProvider = (props: Props) => {
}, [workerUrl, wasmUrl, coordinatorUrl]);

if (sqlsync) {
return <SQLSyncContext.Provider value={sqlsync}>{children}</SQLSyncContext.Provider>;
return createElement(SQLSyncContext.Provider, { value: sqlsync }, children);
}
};
4 changes: 2 additions & 2 deletions lib/sqlsync-react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"module": "esnext",
"moduleResolution": "Bundler",
"baseUrl": ".",
"lib": ["ES6", "DOM", "WebWorker", "ES2021.WeakRef"],
"lib": ["ES6", "DOM", "ES2021.WeakRef"],

/* Compiling */
"allowJs": true,
Expand All @@ -19,5 +19,5 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src", "node_modules/@orbitinghail/sqlsync-worker"]
"include": ["src"]
}
30 changes: 15 additions & 15 deletions lib/sqlsync-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,41 @@
"description": "SQLSync is a collaborative offline-first wrapper around SQLite. It is designed to synchronize web application state between users, devices, and the edge.",
"homepage": "https://sqlsync.dev",
"license": "Apache-2.0",
"keywords": [
"sqlsync",
"sql",
"database",
"sqlite",
"offline-first",
"local-first"
],
"keywords": ["sqlsync", "sql", "database", "sqlite", "offline-first", "local-first"],
"repository": {
"type": "git",
"url": "https://github.com/orbitinghail/sqlsync"
},
"type": "module",
"files": [
"dist",
"src",
"sqlsync-wasm/pkg/sqlsync_wasm.js",
"sqlsync-wasm/pkg/sqlsync_wasm.d.ts",
"sqlsync-wasm/pkg/sqlsync_wasm_bg.wasm"
],
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"main": "./src/index.ts",
"exports": {
".": {
"default": "./src/index.ts",
"import": "./src/index.ts",
"require": "./dist/index.js",
"types": "./src/index.ts"
},
"./worker.js": "./dist/worker.js",
"./worker.ts": "./src/worker.ts",
"./sqlsync.wasm": "./sqlsync-wasm/pkg/sqlsync_wasm_bg.wasm"
},
"publishConfig": {
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./worker.js": "./dist/worker.js",
"./sqlsync.wasm": "./sqlsync-wasm/pkg/sqlsync_wasm_bg.wasm"
}
},
"scripts": {
"tsc": "tsc",
"build-wasm": "cd sqlsync-wasm && wasm-pack build --target web --dev",
"build-wasm-release": "cd sqlsync-wasm && wasm-pack build --target web --release",
"build": "pnpm run build-wasm && rollup --config",
Expand All @@ -47,7 +48,6 @@
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.5",
"microbundle": "^0.15.1",
"rollup": "^3.29.4",
"tslib": "^2.6.2",
"typescript": "^5.2.2"
Expand Down
7 changes: 3 additions & 4 deletions lib/sqlsync-worker/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import commonjs from "@rollup/plugin-commonjs";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";

const output = (name, entry) => ({
const output = (entry) => ({
input: entry,
output: {
dir: "dist",
format: "umd",
format: "es",
sourcemap: true,
name,
},
plugins: [commonjs(), typescript(), nodeResolve()],
});

export default [output("SQLSync", "src/index.ts"), output("SQLSyncWorker", "src/worker.ts")];
export default [output("src/index.ts"), output("src/worker.ts")];
9 changes: 5 additions & 4 deletions lib/sqlsync-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ export { normalizeQuery, sql } from "./sql";
export { SQLSync } from "./sqlsync";
export { pendingPromise, serializeMutationAsJSON } from "./util";

import {
import type {
ConnectionStatus,
DocId,
DocRequest,
HandlerId,
SqlValue,
} from "../sqlsync-wasm/pkg/sqlsync_wasm";
import { JournalId } from "./journal-id";
import { ParameterizedQuery } from "./sql";
import { DocType, QuerySubscription, Row } from "./sqlsync";
import type { JournalId } from "./journal-id";
import type { ParameterizedQuery } from "./sql";
import type { DocType, QuerySubscription } from "./sqlsync";
import type { Row } from "./types";

export type {
ConnectionStatus,
Expand Down
2 changes: 1 addition & 1 deletion lib/sqlsync-worker/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"outDir": "dist",
"declaration": true,
"sourceMap": true,
"lib": ["ES6", "DOM", "ES2021.WeakRef"],
"lib": ["ES6", "DOM", "WebWorker", "ES2021.WeakRef"],

/* Linting */
"strict": true,
Expand Down
Loading

0 comments on commit b9cd05e

Please sign in to comment.