Skip to content

Commit

Permalink
refactor(sdk)!: rename writeMessage -> sendMessage and createProcess …
Browse files Browse the repository at this point in the history
…-> spawnProcess #142

BREAKING CHANGE
  • Loading branch information
TillaTheHun0 committed Nov 10, 2023
1 parent 3d3b968 commit 2cf3602
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 45 deletions.
34 changes: 17 additions & 17 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ interacting with `ao` Processes.
- [CJS (Node) type: `commonjs`](#cjs-node-type-commonjs)
- [API](#api)
- [`readState`](#readstate)
- [`writeMessage`](#writemessage)
- [`createProcess`](#createprocess)
- [`sendMessage`](#sendmessage)
- [`spawnProcess`](#spawnprocess)
- [`connect`](#connect)
- [`createDataItemSigner`](#createdataitemsigner)
- [Debug Logging](#debug-logging)
Expand All @@ -32,13 +32,13 @@ This module can be used on the server, as well as the browser:
#### ESM (Node & Browser) aka type: `module`

```js
import { createProcess, readState, writeMessage } from "@permaweb/ao-sdk";
import { spawnProcess, readState, sendMessage } from "@permaweb/ao-sdk";
```

#### CJS (Node) type: `commonjs`

```js
const { readState, writeMessage, createProcess } = require("@permaweb/ao-sdk");
const { readState, sendMessage, spawnProcess } = require("@permaweb/ao-sdk");
```

The duration of this document will use `ESM` for examples
Expand All @@ -63,32 +63,32 @@ state = await readState({
});
```

#### `writeMessage`
#### `sendMessage`

write a message to an `ao` Message Unit `mu` targeting an ao `process`.

```js
import { createDataItemSigner, writeMessage } from "@permaweb/ao-sdk";
import { createDataItemSigner, sendMessage } from "@permaweb/ao-sdk";

const messageId = await writeMessage({
const messageId = await sendMessage({
processId,
input,
signer: createDataItemSigner(wallet),
tags,
});
```

> You can pass a 32 byte `anchor` to `writeMessage` which will be set on the
> You can pass a 32 byte `anchor` to `sendMessage` which will be set on the
> DataItem
#### `createProcess`
#### `spawnProcess`

Create an `ao` process, publishing to Arys.

```js
import { createDataItemSigner, createProcess } from "@permaweb/ao-sdk";
import { createDataItemSigner, spawnProcess } from "@permaweb/ao-sdk";

const processId = await createProcess({
const processId = await spawnProcess({
srcId,
signer: createDataItemSigner(wallet),
tags,
Expand All @@ -108,7 +108,7 @@ specify those components by providing their urls to `connect`. You can currently
```js
import { connect } from "@permaweb/ao-sdk";

const { createProcess, writeMessage, readState } = connect({
const { spawnProcess, sendMessage, readState } = connect({
GATEWAY_URL: "...",
MU_URL: "...",
CU_URL: "...",
Expand All @@ -122,23 +122,23 @@ using the top-lvl exports of the SDK:

```js
import {
createProcess,
writeMessage,
spawnProcess,
sendMessage,
readState
connect
} from '@permaweb/ao-sdk';

// These are functionally equivalent
connect() == { createProcess, writeMessage, readState }
connect() == { spawnProcess, sendMessage, readState }
```

#### `createDataItemSigner`

`writeMessage` and `createProcess` both require signing a DataItem with a
`sendMessage` and `spawnProcess` both require signing a DataItem with a
wallet.

`createDataItemSigner` is a convenience api that, given a wallet, returns a
function that can be passed to both `writeMessage` and `createProcess` in order
function that can be passed to both `sendMessage` and `spawnProcess` in order
to properly sign DataItems.

The SDK provides a browser compatible and node compatible version that you can
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/index.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { connect } from './index.common.js'

import { WalletClient } from './client/browser/index.js'

const { readState, writeMessage, createProcess } = connect()
const { readState, sendMessage, spawnProcess } = connect()

export { readState, writeMessage, createProcess }
export { readState, sendMessage, spawnProcess }
export { connect }

/**
Expand Down
28 changes: 14 additions & 14 deletions sdk/src/index.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as GatewayClient from './client/gateway.js'
import { createLogger } from './logger.js'

import { readStateWith } from './lib/readState/index.js'
import { writeMessageWith } from './lib/writeMessage/index.js'
import { createProcessWith } from './lib/createProcess/index.js'
import { sendMessageWith } from './lib/sendMessage/index.js'
import { spawnProcessWith } from './lib/spawnProcess/index.js'

const DEFAULT_GATEWAY_URL = globalThis.GATEWAY || 'https://arweave.net'
const DEFAULT_MU_URL = globalThis.MU_URL || 'https://ao-mu-1.onrender.com'
Expand All @@ -27,14 +27,14 @@ const DEFAULT_SU_URL = globalThis.SU_URL || 'https://ao-su-1.onrender.com'
*
* @example
* import {
* createProcess,
* writeMessage,
* spawnProcess,
* sendMessage,
* readState
* connect
* } from '@permaweb/ao-sdk';
*
* // These are functionally equivalent
* connect() == { createProcess, writeMessage, readState }
* connect() == { spawnProcess, sendMessage, readState }
*
* @typedef Services
* @property {string} [GATEWAY_URL] - the url of the desried Gateway.
Expand Down Expand Up @@ -62,11 +62,11 @@ export function connect ({
* default writeInteraction that works OOTB
* - writes signed data item for message to the MU
*/
const writeMessageLogger = logger.child('writeMessage')
const writeMessage = writeMessageWith({
const sendMessageLogger = logger.child('sendMessage')
const sendMessage = sendMessageWith({
loadProcessMeta: SuClient.loadProcessMetaWith({ fetch, SU_URL }),
deployMessage: MuClient.deployMessageWith({ fetch, MU_URL, logger: writeMessageLogger }),
logger: writeMessageLogger
deployMessage: MuClient.deployMessageWith({ fetch, MU_URL, logger: sendMessageLogger }),
logger: sendMessageLogger
})

/**
Expand All @@ -77,12 +77,12 @@ export function connect ({
* - On server, uses Irys Node to upload process to Irys
* - Registers the Process with SU
*/
const createProcessLogger = logger.child('createProcess')
const createProcess = createProcessWith({
const spawnProcessLogger = logger.child('spawnProcess')
const spawnProcess = spawnProcessWith({
loadTransactionMeta: GatewayClient.loadTransactionMetaWith({ fetch, GATEWAY_URL }),
deployProcess: SuClient.deployProcessWith({ fetch, SU_URL, logger: createProcessLogger }),
logger: createProcessLogger
deployProcess: SuClient.deployProcessWith({ fetch, SU_URL, logger: spawnProcessLogger }),
logger: spawnProcessLogger
})

return { readState, writeMessage, createProcess }
return { readState, sendMessage, spawnProcess }
}
4 changes: 2 additions & 2 deletions sdk/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { connect } from './index.common.js'

import { WalletClient } from './client/node/index.js'

const { readState, writeMessage, createProcess } = connect()
const { readState, sendMessage, spawnProcess } = connect()

export { readState, writeMessage, createProcess }
export { readState, sendMessage, spawnProcess }
export { connect }

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import { uploadMessageWith } from './upload-message.js'
/**
* @typedef Env1
*
* @typedef WriteMessageArgs
* @typedef SendMessageArgs
* @property {string} processId
* @property {string} anchor
* @property {{ name: string, value: string }[]} [tags]
* @property {any} signer
*
* @callback WriteMessage
* @param {WriteMessageArgs} args
* @callback SendMessage
* @param {SendMessageArgs} args
* @returns {Promise<string>} the id of the data item that represents this message
*
* @param {Env1} - the environment
* @returns {WriteMessage}
* @returns {SendMessage}
*/
export function writeMessageWith (env) {
export function sendMessageWith (env) {
const verifyProcess = verifyProcessWith(env)
const uploadMessage = uploadMessageWith(env)

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import { uploadProcessWith } from './upload-process.js'
/**
* @typedef Env1
*
* @typedef CreateProcessArgs
* @typedef SpawnProcessArgs
* @property {string} srcId
* @property {string} signer
* @property {{ name: string, value: string }[]} [tags]
*
* @callback CreateProcess
* @param {CreateProcessArgs} args
* @callback SpawnProcess
* @param {SpawnProcessArgs} args
* @returns {Promise<string>} the tx id of the newly created process
*
* @param {Env1} - the environment
* @returns {CreateProcess}
* @returns {SpawnProcess}
*/
export function createProcessWith (env) {
export function spawnProcessWith (env) {
const verifyInputs = verifyInputsWith(env)
const uploadProcess = uploadProcessWith(env)

Expand Down
File renamed without changes.

0 comments on commit 2cf3602

Please sign in to comment.