Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replicache v15 update #14

Merged
merged 11 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,25 @@ jobs:

- name: Lint
run: yarn run lint

check_workspace_dependency_drift:
name: Check Workspace Dependency Drift
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 16
cache: "yarn"

- name: Generate new syncpack snapshot
run: yarn run update-syncpack-snapshot
shell: bash
- name: Check for unexpected workspace dependency drift
run: git diff --exit-code -- syncpack-snapshot.txt
3 changes: 3 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodejs 16.19.0
yarn 1.22.10
ruby 2.7.6
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

<https://user-images.githubusercontent.com/5165963/219898954-f5e94045-69bf-4c33-84e8-7d152c6f2c32.mov>

## Replicache version compatibility

- 1.0.0 : replicache <= 14.2.2
- 1.3.0 : replicache >= 15

## Why is this needed?

Replicache enables us to build applications that are performant, offline-capable and collaborative. By default, it uses [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) for client-side persistance. Unfortunately, this technology is not available in React Native and is only supported in web-browsers.

Thankfully, Replicache allows us to provide our own transactional data-store via [`experimentalCreateKVStore`](https://doc.replicache.dev/api/interfaces/ReplicacheOptions#experimentalcreatekvstore). The goal of this project is to provide some implementations of such a store, along with some guidance in getting up and running with Replicache in React Native.
Thankfully, Replicache allows us to provide our own transactional data-store via [`kvStore`](https://doc.replicache.dev/api/interfaces/ReplicacheOptions#kvstoree). The goal of this project is to provide some implementations of such a store, along with some guidance in getting up and running with Replicache in React Native.

## What are the strategies?

Expand Down Expand Up @@ -38,10 +43,10 @@ You most likely want to use web-sockets for this. This is relatively trivial wit
- `yarn add expo-sqlite @react-native-replicache/expo-sqlite`
2. Ensure that you've polyfilled `crypto.getRandomValues` on the global namespace.
- See [here for an example](https://github.com/Braden1996/react-native-replicache/blob/master/packages/example/mobile-react-native/src/crypto-polyfill.ts).
3. Pass in your chosen SQLite binding's React Native Replicache binding into Replicache's `experimentalCreateKVStore` option.
3. Pass in your chosen SQLite binding's React Native Replicache binding into Replicache's `kvStore` option.
- This will be one of the following, depending on the binding you chose:
- `createReplicacheOPSQLiteExperimentalCreateKVStore`
- `createReplicacheExpoSQLiteExperimentalCreateKVStore`
- `createReplicacheOPSQLiteKVStore`
- `createReplicacheExpoSQLiteKVStore`
- See [here for an example](https://github.com/Braden1996/react-native-replicache/blob/master/packages/example/mobile-react-native/src/use-replicache.ts).

## How can I experiment with this locally?
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"graph": "turbo run build --graph=graph.pdf",
"root:eslint": "cd $INIT_CWD && eslint",
"root:rimraf": "cd $INIT_CWD && rimraf",
"root:tsc": "cd $INIT_CWD && tsc"
"root:tsc": "cd $INIT_CWD && tsc",
"update-syncpack-snapshot": "syncpack list-mismatch --filter '^(?!@react-native-replicache/)(?!react-native-replicache$).*$' | sed '/^-/d' > syncpack-snapshot.txt"
},
"devDependencies": {
"eslint": "8.56.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/deep-freeze/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-native-replicache/deep-freeze",
"version": "1.1.0",
"version": "1.3.0",
"main": "./dist/commonjs/index.js",
"module": "./dist/module/index.js",
"react-native": "./src/index.ts",
Expand Down Expand Up @@ -37,7 +37,7 @@
"react-native-builder-bob": "^0.20.3"
},
"peerDependencies": {
"replicache": ">=12.2.0"
"replicache": ">=15.0.0"
},
"react-native-builder-bob": {
"source": "src",
Expand Down
2 changes: 1 addition & 1 deletion packages/deep-freeze/src/deep-freeze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function deepFreezeArray(
function deepFreezeObject(v: ReadonlyJSONObject, seen: object[]): void {
for (const k in v) {
if (hasOwn(v, k)) {
deepFreezeInternal(v[k], seen);
deepFreezeInternal(v[k]!, seen);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/deep-freeze/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@braden1996/tsconfig/base.json",
"compilerOptions": {
"target": "ES2017",
"types": ["./types/globals"]
},
"include": ["src"]
Expand Down
4 changes: 2 additions & 2 deletions packages/example/client-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
},
"peerDependencies": {
"react": ">=18.2.0",
"replicache": ">=12.2.0",
"replicache-react": ">=2.10.0"
"replicache": "15.0.0",
"replicache-react": "^2.10.0"
},
"eslintConfig": {
"extends": "universe"
Expand Down
6 changes: 3 additions & 3 deletions packages/example/mobile-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"@op-engineering/op-sqlite": "^6.0.1",
"@react-native-replicache/example-client-shared": "0.0.0",
"@react-native-replicache/example-shared": "0.0.0",
"@react-native-replicache/react-native-expo-sqlite": "1.1.0",
"@react-native-replicache/react-native-op-sqlite": "1.1.0",
"@react-native-replicache/react-native-expo-sqlite": "1.3.0",
"@react-native-replicache/react-native-op-sqlite": "1.3.0",
"expo": "~51.0.8",
"expo-build-properties": "~0.12.1",
"expo-crypto": "~13.0.2",
Expand All @@ -35,7 +35,7 @@
"react-dom": "18.2.0",
"react-native": "0.74.1",
"react-native-sse": "^1.1.0",
"replicache": "12.2.0",
"replicache": "15.0.0",
"replicache-react": "^2.10.0"
},
"devDependencies": {
Expand Down
7 changes: 3 additions & 4 deletions packages/example/mobile-react-native/src/use-replicache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mutators } from "@react-native-replicache/example-shared";
import { createReplicacheExpoSQLiteExperimentalCreateKVStore } from "@react-native-replicache/react-native-expo-sqlite";
// import { createReplicacheReactNativeOpSQLiteExperimentalCreateKVStore } from "@react-native-replicache/react-native-op-sqlite";
import { createReplicacheExpoSQLiteKVStore } from "@react-native-replicache/react-native-expo-sqlite";
// import { createReplicacheReactNativeOPSQLiteKVStore } from "@react-native-replicache/react-native-op-sqlite";
import React from "react";
import EventSource from "react-native-sse";
import { Replicache, TEST_LICENSE_KEY } from "replicache";
Expand All @@ -18,8 +18,7 @@ export function useReplicache(listID: string) {
licenseKey,
pushURL: `http://127.0.0.1:8080/api/replicache/push?spaceID=${listID}`,
pullURL: `http://127.0.0.1:8080/api/replicache/pull?spaceID=${listID}`,
experimentalCreateKVStore:
createReplicacheExpoSQLiteExperimentalCreateKVStore,
kvStore: createReplicacheExpoSQLiteKVStore,
name: listID,
mutators,
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/example/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"dotenv": "^16.0.1",
"express": "^4.18.1",
"pg-mem": "^2.6.4",
"replicache": "12.2.0",
"replicache-express": "^0.2.1"
"replicache": "15.0.0",
"replicache-express": "^0.3.0-beta.2"
},
"devDependencies": {
"@braden1996/tsconfig": "^0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/example/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"ts-node": "^10.9.1"
},
"peerDependencies": {
"replicache": ">=12.2.0"
"replicache": ">=15.0.0"
},
"eslintConfig": {
"extends": "universe"
Expand Down
1 change: 1 addition & 0 deletions packages/example/shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@braden1996/tsconfig/base.json",
"compilerOptions": {
"target": "ES2017",
"rootDir": "./src",
"types": ["./types/replicache"]
},
Expand Down
2 changes: 1 addition & 1 deletion packages/example/web-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"qs": "^6.11.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"replicache": "12.2.0",
"replicache": "15.0.0",
"replicache-react": "^2.10.0",
"todomvc-app-css": "^2.4.2"
},
Expand Down
9 changes: 7 additions & 2 deletions packages/react-native-expo-sqlite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

<https://user-images.githubusercontent.com/5165963/219898954-f5e94045-69bf-4c33-84e8-7d152c6f2c32.mov>

## Replicache version compatibility

- 1.0.0 : replicache <= 14.2.2
- 1.3.0 : replicache >= 15

## Why is this needed?

Replicache enables us to build applications that are performant, offline-capable and collaborative. By default, it uses [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) for client-side persistance. Unfortunately, this technology is not available in React Native and is only supported in web-browsers.

Thankfully, Replicache allows us to provide our own transactional data-store via [`experimentalCreateKVStore`](https://doc.replicache.dev/api/interfaces/ReplicacheOptions#experimentalcreatekvstore). The goal of this project is to provide some implementations of such a store, along with some guidance in getting up and running with Replicache in React Native.
Thankfully, Replicache allows us to provide our own transactional data-store via [`kvStore`](https://doc.replicache.dev/api/interfaces/ReplicacheOptions#kvstoree). The goal of this project is to provide some implementations of such a store, along with some guidance in getting up and running with Replicache in React Native.

## What are the strategies?

Expand All @@ -28,5 +33,5 @@ You most likely want to use web-sockets for this. This is relatively trivial wit
- `yarn add expo-crypto expo-sqlite @react-native-replicache/react-native-expo-sqlite`
2. Ensure that you've polyfilled `crypto.getRandomValues` on the global namespace.
- See [here for an example](https://github.com/Braden1996/react-native-replicache/blob/master/packages/example/mobile-react-native/src/crypto-polyfill.ts).
3. Pass in `createReplicacheExpoSQLiteExperimentalCreateKVStore` to Replicache's `experimentalCreateKVStore` option.
3. Pass in `createReplicacheExpoSQLiteKVStore` to Replicache's `kvStore` option.
- See [here for an example](https://github.com/Braden1996/react-native-replicache/blob/master/packages/example/mobile-react-native/src/use-replicache.ts).
4 changes: 2 additions & 2 deletions packages/react-native-expo-sqlite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-native-replicache/react-native-expo-sqlite",
"version": "1.1.0",
"version": "1.3.0",
"main": "./dist/commonjs/index.js",
"module": "./dist/module/index.js",
"react-native": "./src/index.ts",
Expand Down Expand Up @@ -34,7 +34,7 @@
"clean": "yarn run root:rimraf dist .turbo"
},
"dependencies": {
"@react-native-replicache/replicache-generic-sqlite": "1.1.0"
"@react-native-replicache/replicache-generic-sqlite": "1.3.0"
},
"devDependencies": {
"@braden1996/tsconfig": "^0.0.1",
Expand Down
8 changes: 5 additions & 3 deletions packages/react-native-expo-sqlite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
GenericDatabaseManager,
GenericSQLDatabase,
getCreateReplicacheSQLiteExperimentalCreateKVStore,
getCreateReplicacheSQLiteKVStore,
ReplicacheGenericSQLiteDatabaseManager,
} from "@react-native-replicache/replicache-generic-sqlite";
import * as SQLite from "expo-sqlite";
Expand Down Expand Up @@ -29,5 +29,7 @@ const expoDbManagerInstance = new ReplicacheGenericSQLiteDatabaseManager(
genericDatabase,
);

export const createReplicacheExpoSQLiteExperimentalCreateKVStore =
getCreateReplicacheSQLiteExperimentalCreateKVStore(expoDbManagerInstance);
export const createReplicacheExpoSQLiteKVStore = {
create: getCreateReplicacheSQLiteKVStore(expoDbManagerInstance),
drop: expoDbManagerInstance.destroy,
};
9 changes: 7 additions & 2 deletions packages/react-native-op-sqlite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

<https://user-images.githubusercontent.com/5165963/219898954-f5e94045-69bf-4c33-84e8-7d152c6f2c32.mov>

## Replicache version compatibility

- 1.0.0 : replicache <= 14.2.2
- 1.3.0 : replicache >= 15

## Why is this needed?

Replicache enables us to build applications that are performant, offline-capable and collaborative. By default, it uses [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) for client-side persistance. Unfortunately, this technology is not available in React Native and is only supported in web-browsers.

Thankfully, Replicache allows us to provide our own transactional data-store via [`experimentalCreateKVStore`](https://doc.replicache.dev/api/interfaces/ReplicacheOptions#experimentalcreatekvstore). The goal of this project is to provide some implementations of such a store, along with some guidance in getting up and running with Replicache in React Native.
Thankfully, Replicache allows us to provide our own transactional data-store via [`kvStore`](https://doc.replicache.dev/api/interfaces/ReplicacheOptions#kvstoree). The goal of this project is to provide some implementations of such a store, along with some guidance in getting up and running with Replicache in React Native.

## What are the strategies?

Expand All @@ -28,5 +33,5 @@ You most likely want to use web-sockets for this. This is relatively trivial wit
- `yarn add expo-crypto @op-engineering/op-sqlite @react-native-replicache/react-native-op-sqlite`
2. Ensure that you've polyfilled `crypto.getRandomValues` on the global namespace.
- See [here for an example](https://github.com/Braden1996/react-native-replicache/blob/master/packages/example/mobile-react-native/src/crypto-polyfill.ts).
3. Pass in `createReplicacheOPSQLiteExperimentalCreateKVStore` to Replicache's `experimentalCreateKVStore` option.
3. Pass in `createReplicacheOPSQLiteKVStore` to Replicache's `kvStore` option.
- See [here for an example](https://github.com/Braden1996/react-native-replicache/blob/master/packages/example/mobile-react-native/src/use-replicache.ts).
6 changes: 4 additions & 2 deletions packages/react-native-op-sqlite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-native-replicache/react-native-op-sqlite",
"version": "1.1.0",
"version": "1.3.0",
"main": "./dist/commonjs/index.js",
"module": "./dist/module/index.js",
"react-native": "./src/index.ts",
Expand Down Expand Up @@ -34,9 +34,11 @@
"clean": "yarn run root:rimraf dist .turbo"
},
"dependencies": {
"@react-native-replicache/replicache-generic-sqlite": "1.1.0"
"@react-native-replicache/replicache-generic-sqlite": "1.3.0"
},
"devDependencies": {
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@braden1996/tsconfig": "^0.0.1",
"@types/react": "~18.2.79",
"react-native-builder-bob": "^0.20.3"
Expand Down
8 changes: 5 additions & 3 deletions packages/react-native-op-sqlite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as OPSQLite from "@op-engineering/op-sqlite";
import {
GenericDatabaseManager,
getCreateReplicacheSQLiteExperimentalCreateKVStore,
getCreateReplicacheSQLiteKVStore,
ReplicacheGenericSQLiteDatabaseManager,
} from "@react-native-replicache/replicache-generic-sqlite";

Expand All @@ -23,5 +23,7 @@ const opSqlManagerInstance = new ReplicacheGenericSQLiteDatabaseManager(
genericDatabase,
);

export const createReplicacheReactNativeOPSQLiteExperimentalCreateKVStore =
getCreateReplicacheSQLiteExperimentalCreateKVStore(opSqlManagerInstance);
export const createReplicacheReactNativeOPSQLiteKVStore = {
create: getCreateReplicacheSQLiteKVStore(opSqlManagerInstance),
drop: opSqlManagerInstance.destroy,
Braden1996 marked this conversation as resolved.
Show resolved Hide resolved
};
7 changes: 6 additions & 1 deletion packages/replicache-generic-sqlite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

<https://user-images.githubusercontent.com/5165963/219898954-f5e94045-69bf-4c33-84e8-7d152c6f2c32.mov>

## Replicache version compatibility

- 1.0.0 : replicache <= 14.2.2
- 1.3.0 : replicache >= 15

## Why is this needed?

This package provides a generic SQLite implementation of [`experimentalCreateKVStore`](https://doc.replicache.dev/api/interfaces/ReplicacheOptions#experimentalcreatekvstore) that is agnostic of the underlying SQLite binding. This abstraction enables us to easily support multiple SQLite bindings. It isn't coupled to React Native either, so could work on other platforms - but that remains to be explored.
This package provides a generic SQLite implementation of [`kvStore`](https://doc.replicache.dev/api/interfaces/ReplicacheOptions#kvstoree) that is agnostic of the underlying SQLite binding. This abstraction enables us to easily support multiple SQLite bindings. It isn't coupled to React Native either, so could work on other platforms - but that remains to be explored.
8 changes: 4 additions & 4 deletions packages/replicache-generic-sqlite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-native-replicache/replicache-generic-sqlite",
"version": "1.1.0",
"version": "1.3.0",
"main": "./dist/commonjs/index.js",
"module": "./dist/module/index.js",
"react-native": "./src/index.ts",
Expand Down Expand Up @@ -36,15 +36,15 @@
"clean": "yarn run root:rimraf dist .turbo"
},
"dependencies": {
"@react-native-replicache/deep-freeze": "1.1.0"
"@react-native-replicache/deep-freeze": "1.3.0"
},
"devDependencies": {
"@braden1996/tsconfig": "^0.0.1",
"react-native-builder-bob": "^0.20.3",
"replicache": "12.2.0"
"replicache": "15.0.0"
},
"peerDependencies": {
"replicache": ">=12.2.0"
"replicache": ">=15.0.0"
},
"react-native-builder-bob": {
"source": "src",
Expand Down
2 changes: 1 addition & 1 deletion packages/replicache-generic-sqlite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { ReplicacheGenericSQLiteDatabaseManager } from "./replicache-generic-sqlite-database-manager";
export { getCreateReplicacheSQLiteExperimentalCreateKVStore } from "./replicache-generic-sqlite-store";
export { getCreateReplicacheSQLiteKVStore } from "./replicache-generic-sqlite-store";
export * from "./generic-sqlite-adapter";
Loading
Loading