# `web5-js` Discussion Topics
### How do we send a `RecordsWrite` to someone else's dwn without first writing/sending to your own?
> :warning: not possible right now because you have to `web5.dwn.records.write` to get a `record` to then call `send` on
> :bulb: Usecase: the Music suggestion app for Miami. Alice doesn't need to write this to her own dwn first, then send it to her own DID-resolvable DWN(s), _then_ to the DJs. Unless i guess the DJ wants to respond with a thumbs up / like kind of thing?
Maybe we could do this?
```typescript=
const { record, result } = await web5.dwn.records.send(djDid, {
author: aliceDid,
write: {
data: {
"song": "Another one bites the dust"
}
}
});
```
Or this?
```typescript=
const { record, result } = await web5.dwn.records.send(djDid, {
op: "write",
data: {
"song": "Another one bites the dust"
}
})
```
---
### How do we send `RecordsQuery` to someone else's dwn without first querying your own?
> :bulb: Being able to do this seems important i think? imagine that you don't have your own DID-resolvable DWN, so you're polling PFI DWN for your Quote
Maybe this?
```typescript=
const response = await web5.dwn.records.send(pfiDid, {
author: aliceDid,
query: {
filter: {
protocol: "tbdex",
contextId: "abcd123"
}
}
});
```
Or this?
```typescript=
const response = await web5.dwn.records.send(pfiDid, {
op: "query",
filter: {
protocol: "tbdex",
contextId: "abcd123"
}
})
```
---
### How do we send `ProtocolsQuery` to someone else's dwn without first querying your own
> :bulb: Is this allowed? seems important. need to know what protocols someone has installed to know how to talk to them
Maybe this?
```typescript=
const response = await web5.dwn.protocols.send(maybePfiDid, {
author: aliceDid,
query: {
filter: {
protocol: "tbdex",
}
}
});
```
Or this?
```typescript=
const response = await web5.dwn.protocols.send(maybePfiDid, {
op: "query",
filter: {
protocol: "tbdex",
}
})
```
---
### `record.send()` Feels a bit overloaded
> :bulb: `send` tries to fulfill two separate use-cases (send-to-self & send-to-other) while also aiming to remain simple, flexible, and allow for retries.
imagine we have this scenario where i'm writing a not that I intend to send someone else, but am not ready to yet.
```typescript=
const { record, result } await web5.dwn.records.write(moeDid, {
target: danielDid,
data: {
note: {
draft: true,
title: "Birthday Surprise",
text: "Yo Daniel, we oughta do something cool for Frank's birthday"
}
},
message: {
schema: "someapp.io/schemas/note"
}
});
```
I want to go ahead and save it to my own cloud DWN. so what do i do with send?
```typescript=
// can't do this because the default behavior is to send to my own did-resolvable DWN AND then to Daniel's
await record.send();
// so what do i do? this i suppose means write to only mine but not anyone else's? ok fair enough
await record.send({ targets: [myDid] });
```
if i did send to both, what would retrying look like?
```typescript=
const { record, result } await web5.dwn.records.write(moeDid, {
target: danielDid,
data: {
dm: {
title: "Birthday Surprise",
text: "Yo Daniel, we oughta do something cool for Frank's birthday"
}
},
message: {
protocol: 'dignal',
schema: "someapp.io/schemas/dm"
}
});
const responses = await record.send();
// let's say there's a failure. what does a retry look like?
// we know there's a failure if only one response was returned. but whose did it fail to send to?
if (responses.length === 1) {
let [response] = responses;
// sanity check
if (!response.error) {
break;
}
const retryTargets = [danielsDid]
if (response.target === myDid) {
retryTargets.push(myDid);
}
while (retryTargets.length > 0) {
const retryTarget = retryTargets[retryTargets.length - 1];
([response] = await record.send({ targets: [retryTarget] }))
if (!response.error) {
retryTargets.pop();
}
}
}
// that was the tersest way i could think of writing the retry. required some thinking
```
> :bulb: it might be easier if we just had two separate methods, 1 for send-to-self, and 1 for send-to-other
```typescript=
const { record, result } await web5.dwn.records.write({
target: pfiDid,
data: {
amount: Infinity
},
message: {
protocol: 'tbDrat',
schema: "tbdex.io/schemas/rfq"
}
});
const ops = [record.send, record.sync];
while (ops.length > 0) {
const sendTarget = ops[ops.length - 1];
const response = await op();
if (!response.error) {
ops.pop();
}
}
// that took care of writing to me own local, sending to me did-resolvable dwn, and bee-eff-oiii
```
```typescript=
await web5.dwn.records.query(bobDid, {
author: aliceDid,
message: {
filter: {
schema: 'whatever'
}
}
});
await web5.dwn.records.query(aliceDid, {
author: aliceDid,
message: {
filter: {
schema: 'whatever'
}
}
});
```
```typescript=
const { web5, _did } = await Web5.connect();
// write to my own dwn
const record = await web5.dwn.records.write({
data: "hello",
message: {
filter: {
schema: 'yolo'
}
}
});
// sync that record to my own did-resolvable dwns
await record.sync();
// write that record to someone else's dwn
await record.send(targetDid);
// query my own dwn
const records = await web5.dwn.records.query({
filter: {
schema: 'yolo'
}
});
c
```
---
## Option A
```typescript
const { record, status } = web5.dwn.records.create(aliceDid, {
author: alice,
message: {}
});
const { record, status } = web5.dwn.records.createFrom(bobDid, {
record: firstRecord
});
```
## Option B
```typescript
const { record, status } = web5.dwn.records.create(bobDid, {
author: alice,
message: {}
});
const response = record.send()
// retries.... if alice dwn-server fails and/or bob's dwn-server fails
....
```
## Option C
```typescript
const { record, status } = web5.dwn.records.write(bobDid, {
author: alice,
message: {}
});
const responseAlice = await record.sync(); // write alice's dwn-server
const responseBob = await record.send(); // write bob's dwn-server
```
## Variations
```typescript
agent.dwn.records.write(bobDid, {
data: blah
message: {}
});
const { record, status } = web5.dwn.records.write({
message: {}
});
```
1. message-to-self
2. message-to-other
3. message-to-self (to your own dwn-server)
```typescript=
const { web5 } = await Web5.connect();
// message-to-self
web5.dwn.records.write({});
// message-to-other
const { record } = await web5.dwn.records.write({
target: bobsDid
});
web5.dwn.records.query({});
web5.dwn.records.delete({
target: bobsDid
});
const { record } = web5.dwn.records.write();
await record.sync();
await record.send(bobsDid);
await record.send();
```
```typescript=
// just write to local
const record = await web5.records.write({
saveToLocal: true
});
await record.sync();
// just write to your local?
const { record, results } = await web5.records.write({});
// just writes to bob's
const record = await web5.records.write({
target: bobsDid,
saveToLocal: false
})
// writes to local & bob's
const record = await web5.records.write({
target: bobsDid,
});
record.store({ sync: true });
record.send();
await record.sync();
// save to local
// write to bob
const record = await web5.records.write({
target: bobsDid
});
//
await record.send();
```
```typescript=
// when sending to a remote *only*
await web5.dwn.records.send({
method: 'query' || 'write' || 'delete' || 'delete' ... etc,
target: aliceDid || bobDid // could be your own did OR someone else's
// the rest
});
// when storing to yourself
const record = await web5.dwn.records.write({});
// sugar convenience to send to remotes
await record.sync();
await record.send(bobsDid);
// querying yourself
await web5.dwn.records.query({});
```
```typescript=
const record = await web5.dwn.records.write();
```