Skip to content

Commit

Permalink
Added JavaScript v6 (#1069)
Browse files Browse the repository at this point in the history
* added v6 docs

* removed double await
  • Loading branch information
renebrandel authored Nov 15, 2023
1 parent c429835 commit 362c2ff
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 122 deletions.
154 changes: 111 additions & 43 deletions markdown/storage/web/react.md
Original file line number Diff line number Diff line change
@@ -1,106 +1,174 @@
:::NEW_COMMAND:::
UPLOAD_PUBLIC
```js
import { Storage } from "@aws-amplify/storage"
import { uploadData } from 'aws-amplify/storage';

await Storage.put("test.txt", "Hello");
try {
const result = await uploadData({
key: filename,
data: file
}).result;
console.log('Succeeded: ', result);
} catch (error) {
console.log('Error : ', error);
}
```
:::NEW_COMMAND:::
UPLOAD_PROTECTED
```js
import { Storage } from "@aws-amplify/storage"
import { uploadData } from 'aws-amplify/storage';

await Storage.put('test.txt', 'Protected Content', {
level: 'protected',
contentType: 'text/plain'
});
try {
const result = await uploadData({
key: filename,
data: file,
options: {
accessLevel: 'protected'
}
}).result;
console.log('Succeeded: ', result);
} catch (error) {
console.log('Error : ', error);
}
```
:::NEW_COMMAND:::
UPLOAD_PRIVATE
```js
import { Storage } from "@aws-amplify/storage"
import { uploadData } from 'aws-amplify/storage';

await Storage.put('test.txt', 'Private Content', {
level: 'private',
contentType: 'text/plain'
});
try {
const result = await uploadData({
key: filename,
data: file,
options: {
accessLevel: 'private'
}
}).result;
console.log('Succeeded: ', result);
} catch (error) {
console.log('Error : ', error);
}
```
:::NEW_COMMAND:::
DOWNLOAD_PUBLIC
```js
import { Storage } from "@aws-amplify/storage"
import { getUrl } from 'aws-amplify/storage';

await Storage.get('test.txt', {
level: 'public'
const getUrlResult = await getUrl({
key: filename,
});
```
:::NEW_COMMAND:::
DOWNLOAD_PROTECTED
```js
import { Storage } from "@aws-amplify/storage"
import { getUrl } from 'aws-amplify/storage';

await Storage.get('test.txt', {
level: 'protected'
identityId: 'xxxxxxx' // The identityId of that user. Omit to get current user's objects.
const getUrlResult = await getUrl({
key: filename,
options: {
accessLevel: 'protected'
}
});
```
:::NEW_COMMAND:::
DOWNLOAD_PRIVATE
```js
import { Storage } from "@aws-amplify/storage"
import { getUrl } from 'aws-amplify/storage';

await Storage.get('test.txt', {
level: 'private'
const getUrlResult = await getUrl({
key: filename,
options: {
accessLevel: 'private'
}
});
```
:::NEW_COMMAND:::
LIST_PUBLIC
```js
import { Storage } from "@aws-amplify/storage"
import { list } from 'aws-amplify/storage';

Storage.list('photos/') // for listing ALL files without prefix, pass '' instead
.then(result => console.log(result))
.catch(err => console.log(err));
try {
const result = await list({
prefix: 'photos/'
});
} catch (error) {
console.log(error);
}
```
:::NEW_COMMAND:::
LIST_PROTECTED
```js
import { Storage } from "@aws-amplify/storage"
import { list } from 'aws-amplify/storage';

Storage.list('photos/', {
level: 'protected',
identityId: 'xxxxxxx' // The identityId of that user. Omit to get current user's objects.
})
.then(result => console.log(result))
.catch(err => console.log(err));
try {
const result = await list({
prefix: 'photos/',
options: {
accessLevel: 'protected'
}
});
} catch (error) {
console.log(error);
}
```
:::NEW_COMMAND:::
LIST_PRIVATE
```js
import { Storage } from "@aws-amplify/storage"
import { list } from 'aws-amplify/storage';

try {
const response = await list({
prefix: 'photos/',
options: {
accessLevel: 'private',
}
})
console.log('Listed Items:', response.items);
} catch(error) {
console.log('Error ': error);
}

Storage.list('photos/', { level: 'private' })
.then(result => console.log(result))
.catch(err => console.log(err));
```
:::NEW_COMMAND:::
REMOVE_PUBLIC
```js
import { Storage } from "@aws-amplify/storage"
import { remove } from 'aws-amplify/storage';

await Storage.remove('test.txt');
try {
await remove({ key: filename });
} catch (error) {
console.log('Error ', error);
}
```
:::NEW_COMMAND:::
REMOVE_PROTECTED
```js
import { Storage } from "@aws-amplify/storage"
import { remove } from 'aws-amplify/storage';

await Storage.remove('test.txt', { level: 'protected' });
try {
await remove({
key: filename,
options: {
accessLevel: 'protected'
}
});
} catch (error) {
console.log('Error ', error);
}
```
:::NEW_COMMAND:::
REMOVE_PRIVATE
```js
import { Storage } from "@aws-amplify/storage"
import { remove } from 'aws-amplify/storage';

await Storage.remove('test.txt', { level: 'private' });
try {
await remove({
key: filename,
options: {
accessLevel: 'private'
}
});
} catch (error) {
console.log('Error ', error);
}
```
4 changes: 2 additions & 2 deletions markdown/tests/react_native/react_native_step4.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Configure the React app's Amplify instance. Add the following code snippet to th

```js
import { Amplify } from "aws-amplify";
import awsconfig from "./aws-exports";
import amplifyconfig from "./amplifyconfiguration.json";

Amplify.configure(awsconfig);
Amplify.configure(amplifyconfig);
```
8 changes: 4 additions & 4 deletions markdown/tests/react_native/react_native_step5_data_code.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:::NEW_COMMAND:::
:::CREATE:::
```js
import { DataStore } from '@aws-amplify/datastore';
import { DataStore } from 'aws-amplify/datastore';
import { :::MODEL::: } from './models';
```
```js
Expand All @@ -16,7 +16,7 @@ await DataStore.save(
:::NEW_COMMAND:::
:::UPDATE:::
```js
import { DataStore } from '@aws-amplify/datastore';
import { DataStore } from 'aws-amplify/datastore';
import { :::MODEL::: } from './models';
```
```js
Expand All @@ -33,7 +33,7 @@ await DataStore.save(:::MODEL:::.copyOf(CURRENT_ITEM, item => {
:::NEW_COMMAND:::
:::DELETE:::
```js
import { DataStore } from '@aws-amplify/datastore';
import { DataStore } from 'aws-amplify/datastore';
import { :::MODEL::: } from './models';
```
```js
Expand All @@ -47,7 +47,7 @@ DataStore.delete(modelToDelete);
:::NEW_COMMAND:::
:::QUERY:::
```js
import { DataStore } from '@aws-amplify/datastore';
import { DataStore } from 'aws-amplify/datastore';
import { :::MODEL::: } from './models';
```
```js
Expand Down
26 changes: 17 additions & 9 deletions markdown/tests/react_native/react_native_step5_data_code_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
:::CREATE:::

```js
import { API } from "aws-amplify";
import { generateClient } from "aws-amplify/api";
import { create:::MODEL::: } from './graphql/mutations';

const client = generateClient()
```

```js
Expand All @@ -12,7 +14,7 @@ import { create:::MODEL::: } from './graphql/mutations';
```

```js
const new:::MODEL::: = await API.graphql({
const new:::MODEL::: = await client.graphql({
query: create:::MODEL:::,
variables: {
input: {:::FIELDS:::}
Expand All @@ -24,8 +26,10 @@ const new:::MODEL::: = await API.graphql({
:::UPDATE:::

```js
import { API } from "aws-amplify";
import { generateClient } from "aws-amplify/api";
import { update:::MODEL::: } from './graphql/mutations';

const client = generateClient()
```

```js
Expand All @@ -34,7 +38,7 @@ import { update:::MODEL::: } from './graphql/mutations';
```

```js
const updated:::MODEL::: = await API.graphql({
const updated:::MODEL::: = await client.graphql({
query: update:::MODEL:::,
variables: {
input: todoDetails
Expand All @@ -46,8 +50,10 @@ const updated:::MODEL::: = await API.graphql({
:::DELETE:::

```js
import { API } from "aws-amplify";
import { generateClient } from "aws-amplify/api";
import { delete:::MODEL::: } from './graphql/mutations';

const client = generateClient()
```

```js
Expand All @@ -56,7 +62,7 @@ import { delete:::MODEL::: } from './graphql/mutations';
```

```js
const deleted:::MODEL::: = await API.graphql({
const deleted:::MODEL::: = await client.graphql({
query: delete:::MODEL:::,
variables: {
input: todoDetails
Expand All @@ -68,8 +74,10 @@ const deleted:::MODEL::: = await API.graphql({
:::QUERY:::

```js
import { API } from "aws-amplify";
import { generateClient } from "aws-amplify/api";
import * as queries from "./graphql/queries";

const client = generateClient()
```

```js
Expand All @@ -79,14 +87,14 @@ import * as queries from "./graphql/queries";

```js
// Simple query
const all:::MODEL:::s = await API.graphql({
const all:::MODEL:::s = await client.graphql({
query: queries.list:::MODEL:::s
});
console.log(all:::MODEL:::);
// result: { "data": { "list:::MODEL:::s": { "items": [/* ..... */] } } }

// Query using a parameter
const one:::MODEL::: = await API.graphql({
const one:::MODEL::: = await client.graphql({
query: queries.get:::MODEL:::,
variables: { id: 'some id' }
});
Expand Down
6 changes: 3 additions & 3 deletions markdown/tests/react_native/react_native_sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Pull in the latest backend information into your app's code base.

2. Make sure `Amplify` initialized and configured correctly.
```js
import Amplify from 'aws-amplify'
import awsconfig from './aws-exports'
import { Amplify } from 'aws-amplify'
import amplifyconfig from './amplifyconfiguration.json'

Amplify.configure(awsconfig)
Amplify.configure(amplifyconfig)
```
6 changes: 3 additions & 3 deletions markdown/tests/web/angular_step4.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ npm install aws-amplify

Configure the Angular app's Amplify instance. Add the following code snippet to the top of your **main.ts**:
```ts
import Amplify from 'aws-amplify'
import awsconfig from './aws-exports'
import { Amplify } from 'aws-amplify'
import amplifyconfig from './amplifyconfiguration.json'

Amplify.configure(awsconfig)
Amplify.configure(amplifyconfig)
```
Loading

0 comments on commit 362c2ff

Please sign in to comment.