Skip to content

Commit b9cd05e

Browse files
committed
working refactor
1 parent 30a8c18 commit b9cd05e

File tree

13 files changed

+221
-3423
lines changed

13 files changed

+221
-3423
lines changed

examples/react/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
7-
"dev": "vite",
8-
"build": "tsc && vite build",
9-
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
10-
"preview": "vite preview"
7+
"dev": "vite"
118
},
129
"dependencies": {
1310
"react": "^18.2.0",

examples/react/src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import workerUrl from "@orbitinghail/sqlsync-worker/worker.ts?url";
1414
import { SQLSyncProvider, createDocHooks } from "@orbitinghail/sqlsync-react";
1515

1616
const DEMO_REDUCER_URL = new URL(
17-
"../../../target/wasm32-unknown-unknown/debug/sqlsync_react_test_reducer.wasm",
17+
"../../../target/wasm32-unknown-unknown/debug/count_reducer.wasm",
1818
import.meta.url,
1919
);
2020

examples/react/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"lib": ["ES2020", "DOM", "DOM.Iterable"],
66
"module": "ESNext",
77
"skipLibCheck": true,
8+
"types": ["vite/client"],
89

910
/* Bundler mode */
1011
"moduleResolution": "bundler",

justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ wasm-counter-reducer:
3838
wasm-task-reducer:
3939
cargo build --target wasm32-unknown-unknown --example task-reducer
4040

41-
wasm-sqlsync-react-test-reducer:
42-
cargo build --target wasm32-unknown-unknown --package sqlsync-react-test-reducer
41+
wasm-examples-count-reducer:
42+
cargo build --target wasm32-unknown-unknown --package count-reducer
4343

4444
test-end-to-end-local rng_seed="": wasm-task-reducer
4545
RUST_BACKTRACE=1 cargo run --example end-to-end-local {{rng_seed}}

lib/sqlsync-react/package.json

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,46 @@
99
"type": "git",
1010
"url": "https://github.com/orbitinghail/sqlsync"
1111
},
12-
"files": ["dist", "src"],
1312
"type": "module",
14-
"main": "./dist/index.js",
15-
"types": "./dist/index.d.ts",
13+
"files": ["dist"],
14+
"main": "./src/index.ts",
1615
"exports": {
1716
".": {
1817
"import": "./src/index.ts",
19-
"require": "./dist/index.js",
18+
"default": "./src/index.ts",
2019
"types": "./src/index.ts"
2120
}
2221
},
22+
"publishConfig": {
23+
"main": "./dist/index.js",
24+
"types": "./dist/index.d.ts",
25+
"exports": {
26+
".": {
27+
"import": "./dist/index.js",
28+
"default": "./dist/index.js",
29+
"types": "./dist/index.d.ts"
30+
}
31+
}
32+
},
2333
"scripts": {
2434
"build": "rollup --config"
2535
},
2636
"devDependencies": {
2737
"@rollup/plugin-node-resolve": "^15.2.3",
2838
"@rollup/plugin-typescript": "^11.1.5",
39+
"@types/react": "^18.2.31",
40+
"@types/react-dom": "^18.2.14",
41+
"@orbitinghail/sqlsync-worker": "workspace:^",
2942
"rollup": "^3.29.4",
3043
"tslib": "^2.6.2",
31-
"typescript": "^5.2.2",
32-
"@types/react": "^18.2.31",
33-
"@types/react-dom": "^18.2.14"
44+
"typescript": "^5.2.2"
3445
},
3546
"peerDependencies": {
3647
"react": "^18.2.0",
37-
"react-dom": "^18.2.0"
48+
"react-dom": "^18.2.0",
49+
"@orbitinghail/sqlsync-worker": "workspace:^"
3850
},
3951
"dependencies": {
40-
"fast-equals": "^5.0.1",
41-
"@orbitinghail/sqlsync-worker": "workspace:^"
52+
"fast-equals": "^5.0.1"
4253
}
4354
}

lib/sqlsync-react/rollup.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ export default {
55
input: "src/index.ts",
66
output: {
77
dir: "dist",
8-
format: "umd",
8+
format: "es",
99
sourcemap: true,
10-
name: "SQLSyncReact",
1110
},
12-
plugins: [nodeResolve(), typescript()],
11+
external: ["react", "@orbitinghail/sqlsync-worker"],
12+
plugins: [typescript(), nodeResolve()],
1313
};

lib/sqlsync-react/src/context.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SQLSync } from "@orbitinghail/sqlsync-worker";
2-
import { ReactNode, createContext, useEffect, useState } from "react";
2+
import { ReactNode, createContext, createElement, useEffect, useState } from "react";
33

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

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

2525
if (sqlsync) {
26-
return <SQLSyncContext.Provider value={sqlsync}>{children}</SQLSyncContext.Provider>;
26+
return createElement(SQLSyncContext.Provider, { value: sqlsync }, children);
2727
}
2828
};

lib/sqlsync-react/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"module": "esnext",
55
"moduleResolution": "Bundler",
66
"baseUrl": ".",
7-
"lib": ["ES6", "DOM", "WebWorker", "ES2021.WeakRef"],
7+
"lib": ["ES6", "DOM", "ES2021.WeakRef"],
88

99
/* Compiling */
1010
"allowJs": true,
@@ -19,5 +19,5 @@
1919
"noUnusedParameters": true,
2020
"noFallthroughCasesInSwitch": true
2121
},
22-
"include": ["src", "node_modules/@orbitinghail/sqlsync-worker"]
22+
"include": ["src"]
2323
}

lib/sqlsync-worker/package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,41 @@
44
"description": "SQLSync is a collaborative offline-first wrapper around SQLite. It is designed to synchronize web application state between users, devices, and the edge.",
55
"homepage": "https://sqlsync.dev",
66
"license": "Apache-2.0",
7-
"keywords": [
8-
"sqlsync",
9-
"sql",
10-
"database",
11-
"sqlite",
12-
"offline-first",
13-
"local-first"
14-
],
7+
"keywords": ["sqlsync", "sql", "database", "sqlite", "offline-first", "local-first"],
158
"repository": {
169
"type": "git",
1710
"url": "https://github.com/orbitinghail/sqlsync"
1811
},
1912
"type": "module",
2013
"files": [
2114
"dist",
22-
"src",
2315
"sqlsync-wasm/pkg/sqlsync_wasm.js",
2416
"sqlsync-wasm/pkg/sqlsync_wasm.d.ts",
2517
"sqlsync-wasm/pkg/sqlsync_wasm_bg.wasm"
2618
],
27-
"main": "./dist/index.js",
28-
"types": "./dist/index.d.ts",
19+
"main": "./src/index.ts",
2920
"exports": {
3021
".": {
22+
"default": "./src/index.ts",
3123
"import": "./src/index.ts",
32-
"require": "./dist/index.js",
3324
"types": "./src/index.ts"
3425
},
35-
"./worker.js": "./dist/worker.js",
3626
"./worker.ts": "./src/worker.ts",
3727
"./sqlsync.wasm": "./sqlsync-wasm/pkg/sqlsync_wasm_bg.wasm"
3828
},
29+
"publishConfig": {
30+
"main": "./dist/index.js",
31+
"types": "./dist/index.d.ts",
32+
"exports": {
33+
".": {
34+
"default": "./dist/index.js",
35+
"types": "./dist/index.d.ts"
36+
},
37+
"./worker.js": "./dist/worker.js",
38+
"./sqlsync.wasm": "./sqlsync-wasm/pkg/sqlsync_wasm_bg.wasm"
39+
}
40+
},
3941
"scripts": {
40-
"tsc": "tsc",
4142
"build-wasm": "cd sqlsync-wasm && wasm-pack build --target web --dev",
4243
"build-wasm-release": "cd sqlsync-wasm && wasm-pack build --target web --release",
4344
"build": "pnpm run build-wasm && rollup --config",
@@ -47,7 +48,6 @@
4748
"@rollup/plugin-commonjs": "^25.0.7",
4849
"@rollup/plugin-node-resolve": "^15.2.3",
4950
"@rollup/plugin-typescript": "^11.1.5",
50-
"microbundle": "^0.15.1",
5151
"rollup": "^3.29.4",
5252
"tslib": "^2.6.2",
5353
"typescript": "^5.2.2"

lib/sqlsync-worker/rollup.config.mjs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import commonjs from "@rollup/plugin-commonjs";
22
import { nodeResolve } from "@rollup/plugin-node-resolve";
33
import typescript from "@rollup/plugin-typescript";
44

5-
const output = (name, entry) => ({
5+
const output = (entry) => ({
66
input: entry,
77
output: {
88
dir: "dist",
9-
format: "umd",
9+
format: "es",
1010
sourcemap: true,
11-
name,
1211
},
1312
plugins: [commonjs(), typescript(), nodeResolve()],
1413
});
1514

16-
export default [output("SQLSync", "src/index.ts"), output("SQLSyncWorker", "src/worker.ts")];
15+
export default [output("src/index.ts"), output("src/worker.ts")];

lib/sqlsync-worker/src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ export { normalizeQuery, sql } from "./sql";
88
export { SQLSync } from "./sqlsync";
99
export { pendingPromise, serializeMutationAsJSON } from "./util";
1010

11-
import {
11+
import type {
1212
ConnectionStatus,
1313
DocId,
1414
DocRequest,
1515
HandlerId,
1616
SqlValue,
1717
} from "../sqlsync-wasm/pkg/sqlsync_wasm";
18-
import { JournalId } from "./journal-id";
19-
import { ParameterizedQuery } from "./sql";
20-
import { DocType, QuerySubscription, Row } from "./sqlsync";
18+
import type { JournalId } from "./journal-id";
19+
import type { ParameterizedQuery } from "./sql";
20+
import type { DocType, QuerySubscription } from "./sqlsync";
21+
import type { Row } from "./types";
2122

2223
export type {
2324
ConnectionStatus,

lib/sqlsync-worker/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"outDir": "dist",
1111
"declaration": true,
1212
"sourceMap": true,
13-
"lib": ["ES6", "DOM", "ES2021.WeakRef"],
13+
"lib": ["ES6", "DOM", "WebWorker", "ES2021.WeakRef"],
1414

1515
/* Linting */
1616
"strict": true,

0 commit comments

Comments
 (0)