Skip to content

Commit

Permalink
update from main
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensJourney committed Oct 19, 2023
2 parents 42ca457 + af0031b commit 5c2e676
Show file tree
Hide file tree
Showing 23 changed files with 1,192 additions and 1,618 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
39 changes: 5 additions & 34 deletions .github/workflows/build-packages.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Packages Deploy
# Ensures packages build correctly
name: Build Packages

on:
push:
Expand All @@ -8,42 +9,15 @@ jobs:
name: Build Packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true

- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: 16
cache: 'yarn'

- name: Setup Yarn
run: |
npm install -g yarn
echo "Yarn version: $(yarn -v)"
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" >> ~/.npmrc
- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Build
run: yarn build:packages

publish:
name: Publish Production Packages
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
with:
submodules: true
persist-credentials: false

- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: 18
cache: 'yarn'

- name: Setup Yarn
run: |
Expand All @@ -56,6 +30,3 @@ jobs:

- name: Build
run: yarn build:packages

- name: Publish
run: lerna exec "npm publish --tag=latest --no-git-checks" --parallel
16 changes: 7 additions & 9 deletions .github/workflows/dev-packages.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Action to publish packages under the `next` tag for testing
# Packages are versioned as `0.0.0-{tag}-DATETIMESTAMP`
name: Packages Deploy

on: workflow_dispatch
Expand All @@ -7,9 +9,9 @@ jobs:
name: Publish Dev Packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
persist-credentials: false

- name: Setup NodeJS
uses: actions/setup-node@v2
Expand All @@ -28,11 +30,7 @@ jobs:
- name: Build
run: yarn build:packages

- name: Development Version
run: |
export SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`
export VERSION="0.0.0-dev.$SHORT_SHA"
lerna version $VERSION --no-private --exact --force-publish --no-push --no-git-tag-version --yes
- name: Publish
run: lerna exec "npm publish --tag=next --no-git-checks"
run: |
yarn changeset version --no-git-tag --snapshot dev
yarn changeset publish --tag dev
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install Dependencies
run: yarn

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ dist
tsconfig.tsbuildinfo
yarn-error.log
.vscode
.DS_STORE
.DS_STORE
.idea
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "apps/supabase-todolist"]
path = apps/supabase-todolist
url = [email protected]:journeyapps/powersync-supabase-react-native-todolist-demo.git
[submodule "packages/journeyapps-react-native-quick-sqlite"]
path = packages/journeyapps-react-native-quick-sqlite
url = [email protected]:journeyapps/react-native-quick-sqlite.git
48 changes: 40 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@

Monorepo for all things React Native and PowerSync.

## Monorepo structure
## Monorepo Structure

- `apps/supabase-todolist`
- [apps/supabase-todolist](./apps/supabase-todolist/README.md)
* An Expo React native app using Supabase.

- `packages/powersync-sdk-common`
- [packages/powersync-sdk-common](./packages/powersync-sdk-common/README.md)
* A Typescript implementation of a PowerSync database connector and streaming sync bucket implementation.

- `packages/powersync-sdk-react-native`
- [packages/powersync-sdk-react-native](./packages/powersync-sdk-react-native/README.md)
* An extension of `packages/powersync-sdk-common` which provides React Native specific implementations of abstracted features.

- `packages/journeyapps-react-native-quick-sqlite`
* A Git submodule for a fork of `react-native-quick-sqlite` this module now automatically loads the shared PowerSync Rust SQLite extension.

# Development

## Git submodules
## Git Submodules
After cloning this repo be sure to init the Git submodules

```bash
Expand All @@ -37,6 +34,41 @@ Build packages
yarn build:packages
```


## Versioning


### Development Packages
Development packages can be published by manually triggering the `dev-packages` workflow. Development packages are versioned as `0.0.0-{tag}-DATETIMESTAMP`.

### Production Packages
Pull requests should contain Changesets for changed packages.

Add changesets with
```Bash
yarn changeset add
```

Merging a PR with Changesets will automatically create a PR with version bumps. That PR will be merged when releasing.

## React Native Quick SQLite Development

Testing live development changes to `@journeyapps/react-native-quick-sqlite` will not with with standard `yarn link` commands. Metro does not work well with symlinks https://github.com/facebook/metro/issues/286.

The process of releasing development packages for `@journeyapps/react-native-quick-sqlite` for each change can be tedious and slow. A faster (and hackier) method is to use [mtsl](https://www.npmjs.com/package/mtsl) which will watch and copy the package into this workspace's `node_modules`.

```bash
npm install -g mtsl
```
```bash
mtsl add -s "[source path to your react-native-quick-sqlite repo folder]" -d "[this workspaces root node_modules folder]"/@journeyapps/react-native-quick-sqlite
```

```bash
mtsl start "[the id returned from step above]"
```


## Testing Supabase example app

``` bash
Expand Down
2 changes: 1 addition & 1 deletion apps/supabase-todolist
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"private": true,
"name": "monorepo",
"name": "powersync-react-native",
"version": "1.0.0",
"license": "Apache-2.0",
"scripts": {
"clean:packages": "lerna run clean",
"build:packages": "lerna run build",
"watch:packages": "yarn workspace @journeyapps/powersync-sdk-react-native watch"
"watch:packages": "yarn workspace @journeyapps/powersync-sdk-react-native watch",
"release": "yarn build:packages && yarn changeset publish"
},
"workspaces": {
"packages": [
Expand All @@ -23,6 +24,7 @@
},
"dependencies": {},
"devDependencies": {
"@changesets/cli": "^2.26.2",
"lerna": "7.3.0"
}
}
1 change: 0 additions & 1 deletion packages/journeyapps-react-native-quick-sqlite
Submodule journeyapps-react-native-quick-sqlite deleted from 6fc07f
11 changes: 11 additions & 0 deletions packages/powersync-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @journeyapps/powersync-react

## 0.0.1

### Patch Changes

- 5abb174: Fix issue with PowerSync React hooks that caused an infinite re-renders, when no `parameters` are provided
- 822bab9: Bump version to exit prerelease mode. Update SDK readme with known issues.
- Updated dependencies [aad52c8]
- Updated dependencies [822bab9]
- @journeyapps/powersync-sdk-common@0.0.1
6 changes: 3 additions & 3 deletions packages/powersync-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@journeyapps/powersync-react",
"version": "0.0.1-alpha.0",
"version": "0.0.1",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
Expand All @@ -22,9 +22,9 @@
"bugs": {
"url": "https://github.com/journeyapps/powersync-react-native-sdk/issues"
},
"homepage": "https://github.com/journeyapps/powersync-react-native-sdk/packages/powersync-react/#readme",
"homepage": "https://docs.powersync.co/resources/api-reference",
"dependencies": {
"@journeyapps/powersync-sdk-common": "^0.0.1-alpha.0"
"@journeyapps/powersync-sdk-common": "^0.0.1"
},
"peerDependencies": {
"react": "*"
Expand Down
16 changes: 11 additions & 5 deletions packages/powersync-react/src/hooks/usePowerSyncQuery.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import React from 'react';
import { usePowerSync } from './PowerSyncContext';
import React from "react";
import { usePowerSync } from "./PowerSyncContext";

/**
* A hook to access a single static query.
* For an updated result, use usePowerSyncWatchedQuery instead
*/
export const usePowerSyncQuery = <T = any>(sqlStatement: string, parameters: any[] = []): T[] => {
export const usePowerSyncQuery = <T = any>(
sqlStatement: string,
parameters: any[] = []
): T[] => {
const powerSync = usePowerSync();
if (!powerSync) {
return [];
}

// This will return the previous parameters until the contents of parameters array change,
// thereby providing a stable array reference and preventing excessive useEffect runs
const memoizedParams = React.useMemo(() => parameters, [...parameters]);
const [data, setData] = React.useState<T[]>([]);

React.useEffect(() => {
powerSync.execute(sqlStatement, parameters).then((result) => {
setData(result.rows?._array ?? []);
});
}, [powerSync, sqlStatement, parameters]);
//
}, [powerSync, sqlStatement, memoizedParams]);

return data;
};
17 changes: 11 additions & 6 deletions packages/powersync-react/src/hooks/usePowerSyncWatchedQuery.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { SQLWatchOptions } from '@journeyapps/powersync-sdk-common';
import React from 'react';
import { usePowerSync } from './PowerSyncContext';
import { SQLWatchOptions } from "@journeyapps/powersync-sdk-common";
import React from "react";
import { usePowerSync } from "./PowerSyncContext";

/**
* A hook to access the results of a watched query.
*/
export const usePowerSyncWatchedQuery = <T = any>(
sqlStatement: string,
parameters: any[] = [],
options: Omit<SQLWatchOptions, 'signal'> = {}
options: Omit<SQLWatchOptions, "signal"> = {}
): T[] => {
const powerSync = usePowerSync();
if (!powerSync) {
return [];
}

const memoizedParams = React.useMemo(() => parameters, [...parameters]);
const memoizedOptions = React.useMemo(
() => options,
[JSON.stringify(options)]
);
const [data, setData] = React.useState<T[]>([]);
const abortController = React.useRef(new AbortController());

Expand All @@ -25,7 +30,7 @@ export const usePowerSyncWatchedQuery = <T = any>(
(async () => {
for await (const result of powerSync.watch(sqlStatement, parameters, {
...options,
signal: abortController.current.signal
signal: abortController.current.signal,
})) {
setData(result.rows?._array ?? []);
}
Expand All @@ -34,7 +39,7 @@ export const usePowerSyncWatchedQuery = <T = any>(
return () => {
abortController.current?.abort();
};
}, [powerSync, sqlStatement, parameters]);
}, [powerSync, sqlStatement, memoizedParams, memoizedOptions]);

return data;
};
14 changes: 14 additions & 0 deletions packages/powersync-sdk-common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# @journeyapps/powersync-sdk-common

## 0.0.1

### Patch Changes

- aad52c8: Updated watched queries to trigger for local only tables.
- 822bab9: Bump version to exit prerelease mode. Update SDK readme with known issues.

## 0.0.1-alpha.1

### Patch Changes

- aad52c8: Updated watched queries to trigger for local only tables.
Loading

0 comments on commit 5c2e676

Please sign in to comment.