Compare commits

..

27 Commits

Author SHA1 Message Date
Pilou
9e21de3819 Merge pull request #771 from nhost/changeset-release/main
chore: update versions
2022-06-29 21:55:36 +02:00
Pierre-Louis Mercereau
a7f3599fb1 chore: unbump peer dep versions 2022-06-29 14:21:20 +02:00
github-actions[bot]
c789102189 chore: update versions 2022-06-29 12:11:21 +00:00
Pilou
b638173181 Merge pull request #768 from nhost/storage-improvements
Storage fixes and improvements
2022-06-29 14:10:11 +02:00
Pierre-Louis Mercereau
d65df02adb docs: format inline example 2022-06-29 14:08:49 +02:00
Pierre-Louis Mercereau
4f9287562e chore: changeset 2022-06-29 12:16:39 +02:00
Pierre-Louis Mercereau
58f82f9aad fix: adapt to new signature 2022-06-29 11:56:05 +02:00
Johan Eliasson
38462c45b6 Merge pull request #762 from nhost/docs-seed
docs: Added seed data information
2022-06-29 08:22:38 +02:00
Johan Eliasson
8e03ed43b7 prepending with zeros 2022-06-29 08:21:31 +02:00
Pierre-Louis Mercereau
b4d52debff chore: wip 2022-06-28 18:49:38 +02:00
Pilou
287e48a51a Merge pull request #766 from nhost/docs/example-on-vercel
fix: force redirectTo link
2022-06-28 16:58:12 +02:00
Pierre-Louis Mercereau
9370e06b68 fix: simplify 2022-06-28 16:53:19 +02:00
Pierre-Louis Mercereau
d5b775c630 fix: force redirectTo link 2022-06-28 16:46:12 +02:00
Pilou
ea8e1df8da Merge pull request #743 from nhost/docs/example-on-vercel
React-apollo example on Vercel
2022-06-28 16:23:06 +02:00
Pierre-Louis Mercereau
ced8100168 build: adjust env vars in turborepo 2022-06-28 14:39:54 +02:00
Pierre-Louis Mercereau
36d6db526c feat: add perms to anonymous users & on delete 2022-06-28 14:36:58 +02:00
Pierre-Louis Mercereau
fb53e94193 feat: use CDN backend 2022-06-28 14:36:20 +02:00
Pierre-Louis Mercereau
165ff16cdc Merge branch 'main' into docs/example-on-vercel 2022-06-28 13:25:50 +02:00
Pierre-Louis Mercereau
e3ef4a0188 revert: keep localhost:1337 as default url 2022-06-28 12:21:18 +02:00
Pierre-Louis Mercereau
0dc01a99e9 add redirectTo to oauth links 2022-06-28 11:11:07 +02:00
Pierre-Louis Mercereau
0e782b8e99 chore: default backend url and update readme 2022-06-28 10:51:34 +02:00
Pierre-Louis Mercereau
3e9d864899 Merge branch 'main' into docs/example-on-vercel 2022-06-28 10:26:31 +02:00
Johan Eliasson
73e4702a1a wording 2022-06-28 08:33:41 +02:00
Johan Eliasson
93cc6bc1cf added seed data information 2022-06-28 07:35:49 +02:00
Pierre-Louis Mercereau
2d1185f7ec chore: turborepo cache input 2022-06-22 16:33:51 +02:00
Pierre-Louis Mercereau
c6d4c5e943 chore: add VITE_NHOST_URL as a turborepo dep 2022-06-22 16:29:35 +02:00
Pierre-Louis Mercereau
0a536ccfda build: add vercel.json 2022-06-22 16:18:53 +02:00
52 changed files with 293 additions and 97 deletions

View File

@@ -21,10 +21,10 @@ The database is managed via the Hasura Console where you can manage the database
Hasura Console is where you manage your database. This is where you create and manage tables, schemas, and data.
1) Open the Hasura Console by clicking on **GraphQL** in the top menu in the Nhost Dashboard.
2) Click **Open Hasura Console** at the top right of the page.
3) Copy the **admin secret**, and click **Open Hasura**.
4) Use the **admin secret** to sign in.
1. Open the Hasura Console by clicking on **GraphQL** in the top menu in the Nhost Dashboard.
2. Click **Open Hasura Console** at the top right of the page.
3. Copy the **admin secret**, and click **Open Hasura**.
4. Use the **admin secret** to sign in.
<video width="99%" autoPlay muted loop controls="true">
<source src="/videos/open-hasura-console.mp4" type="video/mp4" />
@@ -131,6 +131,21 @@ To track database changes, use the [Nhost CLI](/platform/cli) to develop locally
Learn how to [get started with Nhost CLI](/platform/overview/get-started-with-nhost-cli).
## Seed Data
Seed data is a way of automatically adding data to your database using SQL when a new environment is created. This is, for the moment, only applicable when you're using the [Nhost CLI](/platform/cli) to develop locally. When you're running `nhost up` for the first time, seed data is added.
In the future, seed data will also be added to new preview environments.
Seed data should be located in `nhost/seeds/default/` and are executed in alphabetical order.
**Example:** Two seed scripts with countries and products.
```text
nhost/seeds/default/001-countries.sql
nhost/seeds/default/002-products.sql
```
## Backups
Databases on [Pro and Enterprise plans](https://nhost.io/pricing) are backed up automatically.

View File

@@ -7,7 +7,7 @@ Launch the development environment for your app. Once the environment is up, the
- Apply database migrations.
- Apply the Hasura metadata.
- Apply seed data.
- Apply [seed data](/platform/database#seed-data).
```bash
nhost up

View File

@@ -31,7 +31,7 @@ nhost.auth.signOut()
nhost.auth.signOut()
```
### Sign out the user from all decvices
### Sign out the user from all devices
```ts
nhost.auth.signOut({ all: true })

View File

@@ -4,7 +4,7 @@ title: createMultipleFilesUploadMachine()
sidebar_label: createMultipleFilesUploadMachine()
slug: /reference/javascript/storage/create-multiple-files-upload-machine
description: No description provided.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storage-js/src/packages/hasura-storage-js/src/machines/multiple-files-upload.ts#L28
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storage-js/src/packages/hasura-storage-js/src/machines/multiple-files-upload.ts#L37
---
# `createMultipleFilesUploadMachine()`

View File

@@ -27,6 +27,6 @@ custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storag
---
**<span className="parameter-name">\_\_namedParameters</span>** <span className="optional-status">required</span> `Partial<StorageUploadParams>`
**<span className="parameter-name">params</span>** <span className="optional-status">required</span> `Partial<StorageUploadParams>`
---

View File

@@ -4,7 +4,7 @@ title: uploadMultipleFilesPromise()
sidebar_label: uploadMultipleFilesPromise()
slug: /reference/javascript/storage/upload-multiple-files-promise
description: No description provided.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storage-js/src/packages/hasura-storage-js/src/promises/multiple-files-upload.ts#L45
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storage-js/src/packages/hasura-storage-js/src/promises/multiple-files-upload.ts#L46
---
# `uploadMultipleFilesPromise()`
@@ -23,14 +23,15 @@ custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storag
---
**<span className="parameter-name">service</span>** <span className="optional-status">required</span> `Interpreter<MultipleFilesUploadContext, any, { type: "ADD", files: File | Array<File> } | { type: "UPLOAD", url: string, bucketId: string, accessToken: string, adminSecret: string } | { type: "UPLOAD_PROGRESS", additions: number } | { type: "UPLOAD_DONE" } | { type: "UPLOAD_ERROR" } | { type: "CANCEL" } | { type: "REMOVE" } | { type: "CLEAR" }, { value: any, context: MultipleFilesUploadContext }, ResolveTypegenMeta<Typegen0, { type: "ADD", files: File | Array<File> } | { type: "UPLOAD", url: string, bucketId: string, accessToken: string, adminSecret: string } | { type: "UPLOAD_PROGRESS", additions: number } | { type: "UPLOAD_DONE" } | { type: "UPLOAD_ERROR" } | { type: "CANCEL" } | { type: "REMOVE" } | { type: "CLEAR" }, BaseActionObject, ServiceMap>>`
**<span className="parameter-name">service</span>** <span className="optional-status">required</span> `Interpreter<MultipleFilesUploadContext, any, { type: "ADD", files: AnyFileList, bucketId: string } | { type: "UPLOAD", url: string, files: AnyFileList, bucketId: string, accessToken: string, adminSecret: string } | { type: "UPLOAD_PROGRESS", additions: number } | { type: "UPLOAD_DONE" } | { type: "UPLOAD_ERROR" } | { type: "CANCEL" } | { type: "REMOVE" } | { type: "CLEAR" }, { value: any, context: MultipleFilesUploadContext }, ResolveTypegenMeta<Typegen0, { type: "ADD", files: AnyFileList, bucketId: string } | { type: "UPLOAD", url: string, files: AnyFileList, bucketId: string, accessToken: string, adminSecret: string } | { type: "UPLOAD_PROGRESS", additions: number } | { type: "UPLOAD_DONE" } | { type: "UPLOAD_ERROR" } | { type: "CANCEL" } | { type: "REMOVE" } | { type: "CLEAR" }, BaseActionObject, ServiceMap>>`
---
**<span className="parameter-name">options</span>** <span className="optional-status">required</span> [`UploadMultipleFilesActionParams`](/reference/docgen/javascript/storage/types/upload-multiple-files-action-params)
**<span className="parameter-name">params</span>** <span className="optional-status">optional</span> [`UploadMultipleFilesActionParams`](/reference/docgen/javascript/storage/types/upload-multiple-files-action-params)
| Property | Type | Required | Notes |
| :------------------------------------------------------------------------------------------- | :------- | :------: | :---- |
| <span className="parameter-name"><span className="light-grey">options.</span>bucketId</span> | `string` | | |
| Property | Type | Required | Notes |
| :------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------ | :------: | :---- |
| <span className="parameter-name"><span className="light-grey">params.</span>bucketId</span> | `string` | | |
| <span className="parameter-name"><span className="light-grey">params.</span>files</span> | [`AnyFileList`](/reference/docgen/javascript/storage/types/any-file-list) | | |
---

View File

@@ -0,0 +1,14 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: AnyFileList
sidebar_label: AnyFileList
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storage-js/src/packages/hasura-storage-js/src/machines/multiple-files-upload.ts#L9
---
# `AnyFileList`
```ts
type AnyFileList = File | Array<File> | FileList
```

View File

@@ -4,7 +4,7 @@ title: MultipleFilesUploadContext
sidebar_label: MultipleFilesUploadContext
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storage-js/src/packages/hasura-storage-js/src/machines/multiple-files-upload.ts#L9
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storage-js/src/packages/hasura-storage-js/src/machines/multiple-files-upload.ts#L11
---
# `MultipleFilesUploadContext`

View File

@@ -4,17 +4,18 @@ title: MultipleFilesUploadEvents
sidebar_label: MultipleFilesUploadEvents
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storage-js/src/packages/hasura-storage-js/src/machines/multiple-files-upload.ts#L16
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storage-js/src/packages/hasura-storage-js/src/machines/multiple-files-upload.ts#L18
---
# `MultipleFilesUploadEvents`
```ts
type MultipleFilesUploadEvents =
| { type: 'ADD'; files: File | Array<File> }
| { type: 'ADD'; files: AnyFileList; bucketId: string }
| {
type: 'UPLOAD'
url: string
files: AnyFileList
bucketId: string
accessToken: string
adminSecret: string

View File

@@ -4,7 +4,7 @@ title: MultipleFilesUploadMachine
sidebar_label: MultipleFilesUploadMachine
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storage-js/src/packages/hasura-storage-js/src/machines/multiple-files-upload.ts#L26
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storage-js/src/packages/hasura-storage-js/src/machines/multiple-files-upload.ts#L35
---
# `MultipleFilesUploadMachine`

View File

@@ -10,5 +10,5 @@ custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-storag
# `UploadMultipleFilesActionParams`
```ts
type UploadMultipleFilesActionParams = () => { bucketId: string }
type UploadMultipleFilesActionParams = () => { bucketId: string, files: [AnyFileList](/reference/docgen/javascript/storage/types/any-file-list) }
```

View File

@@ -4,7 +4,7 @@ title: useFileUploadItem()
sidebar_label: useFileUploadItem()
slug: /reference/nextjs/use-file-upload-item
description: Use the hook `useFileUploadItem` to control the file upload of a file in a multiple file upload.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useFileUpload.ts#L59
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useFileUpload.ts#L61
---
# `useFileUploadItem()`

View File

@@ -4,7 +4,7 @@ title: useFileUpload()
sidebar_label: useFileUpload()
slug: /reference/nextjs/use-file-upload
description: Use the hook `useFileUpload` to upload a file.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useFileUpload.ts#L129
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useFileUpload.ts#L142
---
# `useFileUpload()`

View File

@@ -4,7 +4,7 @@ title: useMultipleFilesUpload()
sidebar_label: useMultipleFilesUpload()
slug: /reference/nextjs/use-multiple-files-upload
description: Use the hook `useFileUpload` to upload multiple files.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useMultipleFilesUpload.ts#L52
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useMultipleFilesUpload.ts#L55
---
# `useMultipleFilesUpload()`

View File

@@ -4,7 +4,7 @@ title: FileUploadHookResult
sidebar_label: FileUploadHookResult
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useFileUpload.ts#L14
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useFileUpload.ts#L16
---
# `FileUploadHookResult`
@@ -67,11 +67,11 @@ Returns the name of the file.
---
**<span className="parameter-name">add</span>** <span className="optional-status">required</span> `(file: File) => void`
**<span className="parameter-name">add</span>** <span className="optional-status">required</span> `(params: StorageUploadParams) => void`
---
**<span className="parameter-name">upload</span>** <span className="optional-status">required</span> `(file: File) => Promise<UploadFileHandlerResult>`
**<span className="parameter-name">upload</span>** <span className="optional-status">required</span> `(params: Partial<StorageUploadParams>) => Promise<UploadFileHandlerResult>`
---

View File

@@ -49,11 +49,11 @@ Returns `true` when all the files have been successfully uploaded.
---
**<span className="parameter-name">add</span>** <span className="optional-status">required</span> `(files: Array<File>) => void`
**<span className="parameter-name">add</span>** <span className="optional-status">required</span> `(params: Required<Pick<UploadMultipleFilesActionParams, "files">> & UploadMultipleFilesActionParams) => void`
---
**<span className="parameter-name">upload</span>** <span className="optional-status">required</span> `(options: UploadMultipleFilesActionParams) => Promise<MultipleFilesHandlerResult>`
**<span className="parameter-name">upload</span>** <span className="optional-status">required</span> `(params: UploadMultipleFilesActionParams) => Promise<MultipleFilesHandlerResult>`
---

View File

@@ -4,7 +4,7 @@ title: useFileUploadItem()
sidebar_label: useFileUploadItem()
slug: /reference/react/use-file-upload-item
description: Use the hook `useFileUploadItem` to control the file upload of a file in a multiple file upload.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useFileUpload.ts#L59
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useFileUpload.ts#L61
---
# `useFileUploadItem()`

View File

@@ -4,7 +4,7 @@ title: useFileUpload()
sidebar_label: useFileUpload()
slug: /reference/react/use-file-upload
description: Use the hook `useFileUpload` to upload a file.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useFileUpload.ts#L129
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useFileUpload.ts#L142
---
# `useFileUpload()`

View File

@@ -4,7 +4,7 @@ title: useMultipleFilesUpload()
sidebar_label: useMultipleFilesUpload()
slug: /reference/react/use-multiple-files-upload
description: Use the hook `useFileUpload` to upload multiple files.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useMultipleFilesUpload.ts#L52
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useMultipleFilesUpload.ts#L55
---
# `useMultipleFilesUpload()`

View File

@@ -4,7 +4,7 @@ title: FileUploadHookResult
sidebar_label: FileUploadHookResult
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useFileUpload.ts#L14
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/useFileUpload.ts#L16
---
# `FileUploadHookResult`
@@ -67,11 +67,11 @@ Returns the name of the file.
---
**<span className="parameter-name">add</span>** <span className="optional-status">required</span> `(file: File) => void`
**<span className="parameter-name">add</span>** <span className="optional-status">required</span> `(params: StorageUploadParams) => void`
---
**<span className="parameter-name">upload</span>** <span className="optional-status">required</span> `(file: File) => Promise<UploadFileHandlerResult>`
**<span className="parameter-name">upload</span>** <span className="optional-status">required</span> `(params: Partial<StorageUploadParams>) => Promise<UploadFileHandlerResult>`
---

View File

@@ -49,11 +49,11 @@ Returns `true` when all the files have been successfully uploaded.
---
**<span className="parameter-name">add</span>** <span className="optional-status">required</span> `(files: Array<File>) => void`
**<span className="parameter-name">add</span>** <span className="optional-status">required</span> `(params: Required<Pick<UploadMultipleFilesActionParams, "files">> & UploadMultipleFilesActionParams) => void`
---
**<span className="parameter-name">upload</span>** <span className="optional-status">required</span> `(options: UploadMultipleFilesActionParams) => Promise<MultipleFilesHandlerResult>`
**<span className="parameter-name">upload</span>** <span className="optional-status">required</span> `(params: UploadMultipleFilesActionParams) => Promise<MultipleFilesHandlerResult>`
---

View File

@@ -1,5 +1,9 @@
# React-Apollo example
## See this example live
Visit our demo application on [react-apollo.example.nhost.io](https://react-apollo.example.nhost.io)
## Get started
1. Clone the repository
@@ -22,7 +26,7 @@ pnpm install
nhost dev
```
4. Terminal 2: Start React App
4. Terminal 2: Start the React application
```sh
pnpm run dev

View File

@@ -50,6 +50,22 @@ object_relationships:
using:
foreign_key_constraint_on: bucket_id
insert_permissions:
- permission:
check:
size:
_lt: 1024000
columns:
- is_uploaded
- size
- bucket_id
- etag
- mime_type
- name
- created_at
- updated_at
- id
- uploaded_by_user_id
role: anonymous
- permission:
check: {}
columns:
@@ -65,6 +81,20 @@ insert_permissions:
- uploaded_by_user_id
role: user
select_permissions:
- permission:
columns:
- is_uploaded
- size
- bucket_id
- etag
- mime_type
- name
- created_at
- updated_at
- id
- uploaded_by_user_id
filter: {}
role: anonymous
- permission:
columns:
- is_uploaded
@@ -80,6 +110,21 @@ select_permissions:
filter: {}
role: user
update_permissions:
- permission:
check: {}
columns:
- is_uploaded
- size
- bucket_id
- etag
- mime_type
- name
- created_at
- updated_at
- id
- uploaded_by_user_id
filter: {}
role: anonymous
- permission:
check: {}
columns:
@@ -95,3 +140,12 @@ update_permissions:
- uploaded_by_user_id
filter: {}
role: user
delete_permissions:
- permission:
backend_only: false
filter: {}
role: anonymous
- permission:
backend_only: false
filter: {}
role: user

View File

@@ -131,7 +131,7 @@ export const StoragePage: React.FC = () => {
<Dropzone
onDrop={([file]) => {
console.log('accepted file', file)
upload(file)
upload({ file })
}}
onReject={(additions) => console.log('rejected files', additions)}
multiple={false}
@@ -163,7 +163,7 @@ export const StoragePage: React.FC = () => {
<Dropzone
onDrop={(additions) => {
console.log('accepted files', additions)
add(additions)
add({ files: additions })
}}
onReject={(additions) => console.log('rejected files', additions)}
>

View File

@@ -5,7 +5,7 @@ import { useProviderLink } from '@nhost/react'
import AuthLink from './AuthLink'
export default function OauthLinks() {
const { github, google, facebook } = useProviderLink()
const { github, google, facebook } = useProviderLink({ redirectTo: window.location.origin })
return (
<>
<AuthLink leftIcon={<FaGithub />} link={github} color="#333">

View File

@@ -16,7 +16,8 @@ if (devTools) {
}
const nhost = new NhostClient({
backendUrl: import.meta.env.VITE_NHOST_URL || 'http://localhost:1337',
subdomain: import.meta.env.VITE_NHOST_SUBDOMAIN || 'localhost:1337',
region: import.meta.env.VITE_NHOST_REGION,
devTools
})

View File

@@ -18,15 +18,14 @@ export const EmailPassword: React.FC = () => {
() => password && password !== confirmPassword && 'Should match the given password',
[password, confirmPassword]
)
const options = useMemo(
() => ({ displayName: `${firstName} ${lastName}`, metadata: { firstName, lastName } }),
[firstName, lastName]
)
const navigate = useNavigate()
const { signUpEmailPassword } = useSignUpEmailPassword(options)
const { signUpEmailPassword } = useSignUpEmailPassword()
const signUp = async () => {
const result = await signUpEmailPassword(email, password, { metadata: { firstName, lastName } })
const result = await signUpEmailPassword(email, password, {
metadata: { firstName, lastName, displayName: `${firstName} ${lastName}` },
redirectTo: window.location.origin
})
if (result.isError) {
showNotification({
color: 'red',

View File

@@ -0,0 +1,3 @@
{
"rewrites": [{ "source": "/(.*)", "destination": "/" }]
}

View File

@@ -1,5 +1,11 @@
# @nhost/apollo
## 0.5.20
### Patch Changes
- @nhost/nhost-js@1.4.4
## 0.5.19
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/apollo",
"version": "0.5.19",
"version": "0.5.20",
"description": "Nhost Apollo Client library",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,15 @@
# @nhost/hasura-storage-js
## 0.5.0
### Minor Changes
- 4f928756: Extend file upload parameters
- `bucketId` is available everywhere as an option
- It is possible to pass files as a parameter on a multiple `upload`, making the `add` action optional.
- The `add` and `upload` actions of multiple file upload accepts both a `File`, an array of `File` items, and a `FileList`
## 0.4.0
### Minor Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/hasura-storage-js",
"version": "0.4.0",
"version": "0.5.0",
"description": "Hasura-storage client",
"license": "MIT",
"keywords": [

View File

@@ -156,9 +156,9 @@ export const createFileUploadMachine = () =>
type: 'UPLOAD_ERROR',
error: {
status: response?.status ?? 0,
message: response?.data.error?.message || message,
message: response?.data?.error?.message || message,
// TODO errors from hasura-storage are not codified
error: response?.data.error?.message || message
error: response?.data?.error?.message || message
}
})
})

View File

@@ -6,6 +6,8 @@ const { pure, sendParent } = actions
export type FileItemRef = ActorRefFrom<FileUploadMachine>
export type AnyFileList = File | File[] | FileList
export type MultipleFilesUploadContext = {
progress: number | null
files: FileItemRef[]
@@ -14,8 +16,15 @@ export type MultipleFilesUploadContext = {
}
export type MultipleFilesUploadEvents =
| { type: 'ADD'; files: File | File[] }
| { type: 'UPLOAD'; url: string; bucketId?: string; accessToken?: string; adminSecret?: string }
| { type: 'ADD'; files: AnyFileList; bucketId?: string }
| {
type: 'UPLOAD'
url: string
files?: AnyFileList
bucketId?: string
accessToken?: string
adminSecret?: string
}
| { type: 'UPLOAD_PROGRESS'; additions: number }
| { type: 'UPLOAD_DONE' }
| { type: 'UPLOAD_ERROR' }
@@ -42,7 +51,7 @@ export const createMultipleFilesUploadMachine = () => {
},
initial: 'idle',
on: {
UPLOAD: { cond: 'hasFileToDownload', target: 'uploading' },
UPLOAD: { cond: 'hasFileToDownload', actions: 'addItem', target: 'uploading' },
ADD: { actions: 'addItem' },
REMOVE: { actions: 'removeItem' }
},
@@ -83,8 +92,8 @@ export const createMultipleFilesUploadMachine = () => {
},
{
guards: {
hasFileToDownload: (context) =>
context.files.some((ref) => ref.getSnapshot()!.matches('idle')),
hasFileToDownload: (context, event) =>
context.files.some((ref) => ref.getSnapshot()!.matches('idle')) || !!event.files,
isAllUploaded: (context) =>
context.files.every((item) => item.getSnapshot()?.matches('uploaded')),
isAllUploadedOrError: (context) =>
@@ -118,8 +127,14 @@ export const createMultipleFilesUploadMachine = () => {
resetLoaded: assign({ loaded: (_) => 0 }),
startProgress: assign({ progress: (_) => 0 }),
resetProgress: assign({ progress: (_) => null }),
addItem: assign((context, { files }) => {
const additions = Array.isArray(files) ? files : [files]
addItem: assign((context, { files, bucketId }) => {
const additions = files
? Array.isArray(files)
? files // File[]
: 'length' in files // FileList
? Array.from(files)
: [files] // File
: [] // No file
const total = context.total + additions.reduce((agg, curr) => agg + curr.size, 0)
const progress = Math.round((context.loaded * 100) / total)
return {
@@ -139,7 +154,7 @@ export const createMultipleFilesUploadMachine = () => {
sendDestroy: sendParent('REMOVE')
}
})
.withContext({ ...INITIAL_FILE_CONTEXT, file }),
.withContext({ ...INITIAL_FILE_CONTEXT, file, bucketId }),
{ sync: true }
)
)

View File

@@ -3,7 +3,7 @@
export interface Typegen0 {
'@@xstate/typegen': true
eventsCausingActions: {
addItem: 'ADD'
addItem: 'UPLOAD' | 'ADD'
removeItem: 'REMOVE'
clearList: 'CLEAR'
incrementProgress: 'UPLOAD_PROGRESS'

View File

@@ -40,18 +40,15 @@ export interface FileUploadState extends UploadFileHandlerResult, UploadProgress
export const uploadFilePromise = async (
nhost: NhostClientReturnType,
interpreter: FileItemRef | InterpreterFrom<FileUploadMachine>,
{ file, bucketId, id, name }: Partial<StorageUploadParams>
params: Partial<StorageUploadParams>
): Promise<UploadFileHandlerResult> =>
new Promise<UploadFileHandlerResult>((resolve) => {
interpreter.send({
type: 'UPLOAD',
url: nhost.storage.url,
file,
accessToken: nhost.auth.getAccessToken(),
adminSecret: nhost.adminSecret,
bucketId,
id,
name
...params
})
interpreter.subscribe((s) => {
if (s.matches('error')) {

View File

@@ -1,6 +1,6 @@
import { InterpreterFrom } from 'xstate'
import { FileItemRef, MultipleFilesUploadMachine } from '../machines'
import { AnyFileList, FileItemRef, MultipleFilesUploadMachine } from '../machines'
import { NhostClientReturnType } from '../utils/types'
export interface MultipleUploadProgressState {
@@ -39,22 +39,23 @@ export interface MultipleFilesUploadState
}
export type UploadMultipleFilesActionParams = {
files?: AnyFileList
bucketId?: string
}
export const uploadMultipleFilesPromise = async (
nhost: NhostClientReturnType,
service: InterpreterFrom<MultipleFilesUploadMachine>,
options: UploadMultipleFilesActionParams = { bucketId: 'default' }
params?: UploadMultipleFilesActionParams
): Promise<MultipleFilesHandlerResult> =>
new Promise((resolve) => {
const { bucketId } = options
service.send({
type: 'UPLOAD',
url: nhost.storage.url,
bucketId,
accessToken: nhost.auth.getAccessToken(),
adminSecret: nhost.adminSecret
adminSecret: nhost.adminSecret,
bucketId: params?.bucketId,
files: params?.files
})
service.onTransition((s) => {
if (s.matches('error')) {

View File

@@ -1,5 +1,13 @@
# @nhost/nextjs
## 1.6.0
### Patch Changes
- Updated dependencies [4f928756]
- @nhost/react@0.11.0
- @nhost/nhost-js@1.4.4
## 1.5.0
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/nextjs",
"version": "1.5.0",
"version": "1.6.0",
"description": "Nhost NextJS library",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,12 @@
# @nhost/nhost-js
## 1.4.4
### Patch Changes
- Updated dependencies [4f928756]
- @nhost/hasura-storage-js@0.5.0
## 1.4.3
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/nhost-js",
"version": "1.4.3",
"version": "1.4.4",
"description": "Nhost JavaScript SDK",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,13 @@
# @nhost/react-apollo
## 4.6.0
### Patch Changes
- Updated dependencies [4f928756]
- @nhost/react@0.11.0
- @nhost/apollo@0.5.20
## 4.5.0
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/react-apollo",
"version": "4.5.0",
"version": "4.6.0",
"description": "Nhost React Apollo client",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,12 @@
# @nhost/react-auth
## 3.4.0
### Patch Changes
- Updated dependencies [4f928756]
- @nhost/react@0.11.0
## 3.3.0
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/react-auth",
"version": "3.3.0",
"version": "3.4.0",
"description": "Nhost React client",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,21 @@
# @nhost/react
## 0.11.0
### Minor Changes
- 4f928756: Extend file upload parameters
- `bucketId` is available everywhere as an option
- It is possible to pass files as a parameter on a multiple `upload`, making the `add` action optional.
- The `add` and `upload` actions of multiple file upload accepts both a `File`, an array of `File` items, and a `FileList`
### Patch Changes
- Updated dependencies [4f928756]
- @nhost/hasura-storage-js@0.5.0
- @nhost/nhost-js@1.4.4
## 0.10.0
### Minor Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/react",
"version": "0.10.0",
"version": "0.11.0",
"description": "Nhost React library",
"license": "MIT",
"keywords": [

View File

@@ -5,22 +5,24 @@ import {
FileItemRef,
FileUploadMachine,
FileUploadState,
StorageUploadParams,
UploadFileHandlerResult,
uploadFilePromise
} from '@nhost/hasura-storage-js'
import { useInterpret, useSelector } from '@xstate/react'
import { useNhostClient } from './useNhostClient'
export interface FileUploadHookResult extends FileUploadState {
/**
* Add the file without uploading it.
*/
add: (file: File) => void
add: (params: StorageUploadParams) => void
/**
* Upload the file given as a parameter, or that has been previously added.
*/
upload: (file?: File) => Promise<UploadFileHandlerResult>
upload: (params: Partial<StorageUploadParams>) => Promise<UploadFileHandlerResult>
/**
* Cancel the ongoing upload.
@@ -61,11 +63,21 @@ export const useFileUploadItem = (
): FileUploadHookResult => {
const nhost = useNhostClient()
const add = (file: File) => {
ref.send({ type: 'ADD', file })
const add = (params: StorageUploadParams) => {
ref.send({
type: 'ADD',
file: params.file,
bucketId: params.bucketId || bucketId
})
}
const upload = (file?: File) => uploadFilePromise(nhost, ref, { file, bucketId, id, name })
const upload = (params: Partial<StorageUploadParams>) =>
uploadFilePromise(nhost, ref, {
file: params.file,
bucketId: params.bucketId || bucketId,
id,
name
})
const cancel = () => {
ref.send('CANCEL')
@@ -106,15 +118,16 @@ export const useFileUploadItem = (
* @example
* ```tsx
* const { add,
upload,
cancel,
isUploaded,
isUploading,
isError,
progress,
id,
bucketId,
name } = useFileUpload();
* upload,
* cancel,
* isUploaded,
* isUploading,
* isError,
* progress,
* id,
* bucketId,
* name
* } = useFileUpload();
*
*
* const handleFormSubmit = async (e) => {

View File

@@ -16,11 +16,14 @@ export interface MultipleFilesHookResult extends MultipleFilesUploadState {
/**
* Add one or multiple files to add to the list of files to upload.
*/
add: (files: File[]) => void
add: (
params: Required<Pick<UploadMultipleFilesActionParams, 'files'>> &
UploadMultipleFilesActionParams
) => void
/**
* Upload the files that has been previously added to the list.
*/
upload: (options?: UploadMultipleFilesActionParams) => Promise<MultipleFilesHandlerResult>
upload: (params?: UploadMultipleFilesActionParams) => Promise<MultipleFilesHandlerResult>
/**
* Cancel the ongoing upload. The files that have been successfully uploaded will not be deleted from the server.
*/
@@ -38,8 +41,8 @@ export interface MultipleFilesHookResult extends MultipleFilesUploadState {
* ```tsx
* const { upload, add, clear, progress, isUploaded, isUploading, files, isError, cancel } = useMultipleFilesUpload()
*
* const addFile = async (file: File) => {
* add(file)
* const addFile = async (files: File | File[] | FileList) => {
* add({ files })
* }
*
* const handleSubmit = async (e) => {
@@ -61,12 +64,15 @@ export const useMultipleFilesUpload = (): MultipleFilesHookResult => {
}
})
const add = (files: File | File[]) => {
service.send('ADD', { files })
const add = (
params: Required<Pick<UploadMultipleFilesActionParams, 'files'>> &
UploadMultipleFilesActionParams
) => {
service.send({ type: 'ADD', ...params })
}
const upload = (options: UploadMultipleFilesActionParams = { bucketId: 'default' }) =>
uploadMultipleFilesPromise(nhost, service, options)
const upload = (params?: UploadMultipleFilesActionParams) =>
uploadMultipleFilesPromise(nhost, service, params)
const cancel = () => {
service.send('CANCEL')

View File

@@ -1,5 +1,11 @@
# @nhost/vue
## 0.3.4
### Patch Changes
- @nhost/nhost-js@1.4.4
## 0.3.3
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/vue",
"version": "0.3.3",
"version": "0.3.4",
"description": "Nhost Vue library",
"license": "MIT",
"keywords": [

View File

@@ -6,6 +6,10 @@
"dependsOn": ["^build"],
"outputs": ["dist/**", "umd/**", "build/**", ".next"]
},
"@nhost-examples/react-apollo#build": {
"dependsOn": ["^build", "$VITE_NHOST_SUBDOMAIN", "$VITE_NHOST_REGION"],
"outputs": ["dist/**"]
},
"test": {
"dependsOn": ["^build"],
"outputs": ["coverage/**"]