Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Braden1996 committed Jul 28, 2024
1 parent 9bc51ff commit e8803e1
Show file tree
Hide file tree
Showing 28 changed files with 91 additions and 85 deletions.
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
## Replicache version compatibility

- 1.0.0 : replicache <= 14.2.2
- 1.1.0 : replicache >= 15
- 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 [`kvStore`](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 @@ -45,8 +45,8 @@ You most likely want to use web-sockets for this. This is relatively trivial wit
- 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 `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
2 changes: 1 addition & 1 deletion 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
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
4 changes: 2 additions & 2 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 Down
6 changes: 3 additions & 3 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,7 +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}`,
kvStore: createReplicacheExpoSQLiteExperimentalCreateKVStore,
kvStore: createReplicacheExpoSQLiteKVStore,
name: listID,
mutators,
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/example/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dotenv": "^16.0.1",
"express": "^4.18.1",
"pg-mem": "^2.6.4",
"replicache": "12.2.0",
"replicache": "15.0.0",
"replicache-express": "^0.2.1"
},
"devDependencies": {
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
6 changes: 3 additions & 3 deletions packages/react-native-expo-sqlite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
## Replicache version compatibility

- 1.0.0 : replicache <= 14.2.2
- 1.1.0 : replicache >= 15
- 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 [`kvStore`](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 @@ -33,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 `kvStore` 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: 3 additions & 5 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,9 +29,7 @@ const expoDbManagerInstance = new ReplicacheGenericSQLiteDatabaseManager(
genericDatabase,
);

export const createReplicacheExpoSQLiteExperimentalCreateKVStore = {
create: getCreateReplicacheSQLiteExperimentalCreateKVStore(
expoDbManagerInstance
),
export const createReplicacheExpoSQLiteKVStore = {
create: getCreateReplicacheSQLiteKVStore(expoDbManagerInstance),
drop: expoDbManagerInstance.destroy,
};
6 changes: 3 additions & 3 deletions packages/react-native-op-sqlite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
## Replicache version compatibility

- 1.0.0 : replicache <= 14.2.2
- 1.1.0 : replicache >= 15
- 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 [`kvStore`](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 @@ -33,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 `kvStore` 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: 3 additions & 3 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.2.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": {
"@babel/preset-env": "^7.20.0",
Expand Down Expand Up @@ -63,4 +63,4 @@
"eslintConfig": {
"extends": "universe/native"
}
}
}
9 changes: 4 additions & 5 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 @@ -20,11 +20,10 @@ const genericDatabase: GenericDatabaseManager = {
};

const opSqlManagerInstance = new ReplicacheGenericSQLiteDatabaseManager(
genericDatabase
genericDatabase,
);

export const createReplicacheReactNativeOPSQLiteExperimentalCreateKVStore = {
create:
getCreateReplicacheSQLiteExperimentalCreateKVStore(opSqlManagerInstance),
export const createReplicacheReactNativeOPSQLiteKVStore = {
create: getCreateReplicacheSQLiteKVStore(opSqlManagerInstance),
drop: opSqlManagerInstance.destroy,
};
4 changes: 2 additions & 2 deletions packages/replicache-generic-sqlite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
## Replicache version compatibility

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

## Why is this needed?

This package provides a generic SQLite implementation of [`kvStore`](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.
4 changes: 2 additions & 2 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,7 +36,7 @@
"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",
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";
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class ReplicacheGenericSQLiteDatabaseManager {
await tx.start(false);
await tx.execute(
"CREATE TABLE IF NOT EXISTS entry (key TEXT PRIMARY KEY, value TEXT)",
[]
[],
);
await tx.commit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class ReplicacheGenericSQLiteReadImpl
private async _getSql(key: string) {
const rows = await this._assertTx().execute(
"SELECT value FROM entry WHERE key = ?",
[key]
[key],
);

if (rows.length === 0) return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class ReplicacheGenericStore implements KVStore {

constructor(
private readonly name: string,
private readonly _dbm: ReplicacheGenericSQLiteDatabaseManager
private readonly _dbm: ReplicacheGenericSQLiteDatabaseManager,
) {}

async read() {
Expand All @@ -20,7 +20,7 @@ export class ReplicacheGenericStore implements KVStore {
}

async withRead<R>(
fn: (read: Awaited<ReturnType<KVStore["read"]>>) => R | Promise<R>
fn: (read: Awaited<ReturnType<KVStore["read"]>>) => R | Promise<R>,
): Promise<R> {
const read = await this.read();
try {
Expand All @@ -38,7 +38,7 @@ export class ReplicacheGenericStore implements KVStore {
}

async withWrite<R>(
fn: (write: Awaited<ReturnType<KVStore["write"]>>) => R | Promise<R>
fn: (write: Awaited<ReturnType<KVStore["write"]>>) => R | Promise<R>,
): Promise<R> {
const write = await this.write();
try {
Expand All @@ -62,8 +62,8 @@ export class ReplicacheGenericStore implements KVStore {
}
}

export function getCreateReplicacheSQLiteExperimentalCreateKVStore(
db: ReplicacheGenericSQLiteDatabaseManager
export function getCreateReplicacheSQLiteKVStore(
db: ReplicacheGenericSQLiteDatabaseManager,
) {
return (name: string) => new ReplicacheGenericStore(name, db);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class ReplicacheGenericSQLiteWriteImpl
const jsonValueString = JSON.stringify(value);
await this._assertTx().execute(
"INSERT OR REPLACE INTO entry (key, value) VALUES (?, ?)",
[key, jsonValueString]
[key, jsonValueString],
);
}

Expand Down
4 changes: 4 additions & 0 deletions syncpack-snapshot.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
✘ expo-sqlite >=14.0.0, ~14.0.3
✘ react 18.2.0, >=18.2.0
✘ react-native 0.74.1, >=0.74.0
✘ replicache 15.0.0, >=15.0.0
Loading

0 comments on commit e8803e1

Please sign in to comment.