Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dna properties on install #135

Merged
merged 6 commits into from
Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/tryorama.agenthappoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ A type that specifies either only the DNAs that the hApp to be installed consist
export declare type AgentHappOptions = DnaSource[] | {
dnas: DnaSource[];
signalHandler?: AppSignalCb;
properties?: DnaProperties;
};
```
3 changes: 2 additions & 1 deletion docs/tryorama.conductor.installagentshapps.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ Install a set of DNAs for multiple agents into the conductor.
installAgentsHapps(options: {
agentsDnas: DnaSource[][];
uid?: string;
properties?: DnaProperties;
}): Promise<AgentHapp[]>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| options | { agentsDnas: DnaSource\[\]\[\]; uid?: string; } | An array of DNAs for each agent, resulting in a 2-dimensional array, and a UID for the DNAs (optional). |
| options | { agentsDnas: DnaSource\[\]\[\]; uid?: string; properties?: DnaProperties; } | An array of DNAs for each agent, resulting in a 2-dimensional array, and a UID for the DNAs (optional). |

<b>Returns:</b>

Expand Down
1 change: 1 addition & 0 deletions docs/tryorama.iconductor.installagentshapps.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
installAgentsHapps: (options: {
agentsDnas: DnaSource[][];
uid?: string;
properties?: DnaProperties;
signalHandler?: AppSignalCb;
}) => Promise<AgentHapp[]>;
```
2 changes: 1 addition & 1 deletion docs/tryorama.iconductor.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface IConductor
| --- | --- | --- |
| [adminWs](./tryorama.iconductor.adminws.md) | () =&gt; Omit&lt;AdminWebsocket, "\_requester" \| "client" \| "activateApp" \| "deactivateApp" \| "defaultTimeout" \| "listActiveApps"&gt; | |
| [appWs](./tryorama.iconductor.appws.md) | () =&gt; Pick&lt;AppWebsocket, "callZome" \| "appInfo"&gt; | |
| [installAgentsHapps](./tryorama.iconductor.installagentshapps.md) | (options: { agentsDnas: DnaSource\[\]\[\]; uid?: string; signalHandler?: AppSignalCb; }) =&gt; Promise&lt;[AgentHapp](./tryorama.agenthapp.md)<!-- -->\[\]&gt; | |
| [installAgentsHapps](./tryorama.iconductor.installagentshapps.md) | (options: { agentsDnas: DnaSource\[\]\[\]; uid?: string; properties?: DnaProperties; signalHandler?: AppSignalCb; }) =&gt; Promise&lt;[AgentHapp](./tryorama.agenthapp.md)<!-- -->\[\]&gt; | |
| [shutDown](./tryorama.iconductor.shutdown.md) | () =&gt; Promise&lt;number \| null&gt; | |
| [startUp](./tryorama.iconductor.startup.md) | () =&gt; Promise&lt;void \| null&gt; | |

Expand Down
1 change: 1 addition & 0 deletions docs/tryorama.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ TryCP stands for Tryorama Control Protocol (TryCP) and is a protocol to enable r
| [CellZomeCallRequest](./tryorama.cellzomecallrequest.md) | The zome request options adapted to a specific cell. |
| [ConductorId](./tryorama.conductorid.md) | |
| [CreateConductorOptions](./tryorama.createconductoroptions.md) | Options for using the conductor factory. |
| [RegisterDnaReqOpts](./tryorama.registerdnareqopts.md) | |
| [RequestCallAppInterfaceMessage](./tryorama.requestcallappinterfacemessage.md) | All possible calls to an app interface. |
| [TryCpApiResponse](./tryorama.trycpapiresponse.md) | Possible responses from the Admin and App APIs. |
| [TryCpConductorLogLevel](./tryorama.trycpconductorloglevel.md) | Log level for a TryCP conductor. |
Expand Down
15 changes: 15 additions & 0 deletions docs/tryorama.registerdnareqopts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/tryorama](./tryorama.md) &gt; [RegisterDnaReqOpts](./tryorama.registerdnareqopts.md)

## RegisterDnaReqOpts type

<b>Signature:</b>

```typescript
export declare type RegisterDnaReqOpts = Omit<RegisterDnaRequest, "hash" | "path" | "bundle"> & {
hash?: HoloHash;
path?: string;
bundle?: DnaBundle;
};
```
3 changes: 2 additions & 1 deletion docs/tryorama.trycpconductor.installagentshapps.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ installAgentsHapps(options: {
agentsDnas: DnaSource[][];
signalHandler?: AppSignalCb;
uid?: string;
properties?: DnaProperties;
}): Promise<AgentHapp[]>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| options | { agentsDnas: DnaSource\[\]\[\]; signalHandler?: AppSignalCb; uid?: string; } | An array of DNAs for each agent, resulting in a 2-dimensional array, and a UID for the DNAs (optional). |
| options | { agentsDnas: DnaSource\[\]\[\]; signalHandler?: AppSignalCb; uid?: string; properties?: DnaProperties; } | An array of DNAs for each agent, resulting in a 2-dimensional array, and a UID for the DNAs (optional). |

<b>Returns:</b>

Expand Down
53 changes: 28 additions & 25 deletions ts/src/local/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
AppWebsocket,
AttachAppInterfaceRequest,
DnaSource,
DnaProperties,
InstallAppBundleRequest,
InstallAppDnaPayload,
RegisterDnaRequest,
} from "@holochain/client";
import getPort, { portNumbers } from "get-port";
import pick from "lodash/pick.js";
Expand All @@ -17,7 +19,12 @@ import { v4 as uuidv4 } from "uuid";

import { enableAndGetAgentHapp } from "../common.js";
import { makeLogger } from "../logger.js";
import { AgentHapp, HappBundleOptions, IConductor } from "../types.js";
import {
AgentHapp,
HappBundleOptions,
IConductor,
RegisterDnaReqOpts,
} from "../types.js";

const logger = makeLogger("Local Conductor");

Expand Down Expand Up @@ -395,6 +402,7 @@ export class Conductor implements IConductor {
async installAgentsHapps(options: {
agentsDnas: DnaSource[][];
uid?: string;
properties?: DnaProperties;
}) {
const agentsHapps: AgentHapp[] = [];

Expand All @@ -404,34 +412,29 @@ export class Conductor implements IConductor {
const appId = `app-${uuidv4()}`;

for (const dna of agent) {
let role_id: string;

const registerDnaReqOpts: RegisterDnaReqOpts = {
uid: options.uid,
properties: options.properties,
};

if ("path" in dna) {
const dnaHash = await this.adminWs().registerDna({
path: dna.path,
uid: options.uid,
});
dnas.push({
hash: dnaHash,
role_id: `${dna.path}-${uuidv4()}`,
});
registerDnaReqOpts["path"] = dna.path;
role_id = `${dna.path}-${uuidv4()}`;
} else if ("hash" in dna) {
const dnaHash = await this.adminWs().registerDna({
hash: dna.hash,
uid: options.uid,
});
dnas.push({
hash: dnaHash,
role_id: `dna-${uuidv4()}`,
});
registerDnaReqOpts["hash"] = dna.hash;
role_id = `dna-${uuidv4()}`;
} else {
const dnaHash = await this.adminWs().registerDna({
bundle: dna.bundle,
uid: options.uid,
});
dnas.push({
hash: dnaHash,
role_id: `${dna.bundle.manifest.name}-${uuidv4()}`,
});
registerDnaReqOpts["bundle"] = dna.bundle;
role_id = `${dna.bundle.manifest.name}-${uuidv4()}`;
}

const dnaHash = await this.adminWs().registerDna(
registerDnaReqOpts as RegisterDnaRequest
);

dnas.push({ hash: dnaHash, role_id });
}

const installedAppInfo = await this.adminWs().installApp({
Expand Down
4 changes: 4 additions & 0 deletions ts/src/local/scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ export class Scenario implements IScenario {
const signalHandler = Array.isArray(agentHappOptions)
? undefined
: agentHappOptions.signalHandler;
const properties = Array.isArray(agentHappOptions)
? undefined
: agentHappOptions.properties;
const agentsDnas: DnaSource[][] = Array.isArray(agentHappOptions)
? [agentHappOptions]
: [agentHappOptions.dnas];
const conductor = await this.addConductor(signalHandler);
const [agentHapp] = await conductor.installAgentsHapps({
agentsDnas,
uid: this.uid,
properties,
});
return { conductor, ...agentHapp };
}
Expand Down
47 changes: 22 additions & 25 deletions ts/src/trycp/conductor/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
CreateCloneCellRequest,
DisableAppRequest,
DnaHash,
DnaProperties,
DnaSource,
DumpFullStateRequest,
DumpStateRequest,
Expand All @@ -31,7 +32,7 @@ import { URL } from "node:url";
import { v4 as uuidv4 } from "uuid";
import { enableAndGetAgentHapp } from "../../common.js";
import { makeLogger } from "../../logger.js";
import { AgentHapp, IConductor } from "../../types.js";
import { AgentHapp, IConductor, RegisterDnaReqOpts } from "../../types.js";
import { TryCpClient, TryCpConductorLogLevel } from "../index.js";
import {
RequestAdminInterfaceData,
Expand Down Expand Up @@ -643,6 +644,7 @@ export class TryCpConductor implements IConductor {
agentsDnas: DnaSource[][];
signalHandler?: AppSignalCb;
uid?: string;
properties?: DnaProperties;
}) {
const agentsHapps: AgentHapp[] = [];

Expand All @@ -657,6 +659,13 @@ export class TryCpConductor implements IConductor {
);

for (const dna of agentDnas) {
let role_id: string;

const registerDnaReqOpts: RegisterDnaReqOpts = {
uid: options.uid,
properties: options.properties,
};

if ("path" in dna) {
const dnaContent = await new Promise<Buffer>((resolve, reject) => {
fs.readFile(dna.path, null, (err, data) => {
Expand All @@ -667,33 +676,21 @@ export class TryCpConductor implements IConductor {
});
});
const relativePath = await this.saveDna(dnaContent);
const dnaHash = await this.adminWs().registerDna({
path: relativePath,
uid: options.uid,
});
dnas.push({
hash: dnaHash,
role_id: `${dna.path}-${uuidv4()}`,
});
registerDnaReqOpts["path"] = relativePath;
role_id = `${dna.path}-${uuidv4()}`;
} else if ("hash" in dna) {
const dnaHash = await this.adminWs().registerDna({
hash: dna.hash,
uid: options.uid,
});
dnas.push({
hash: dnaHash,
role_id: `dna-${uuidv4()}`,
});
registerDnaReqOpts["hash"] = dna.hash;
role_id = `dna-${uuidv4()}`;
} else {
const dnaHash = await this.adminWs().registerDna({
bundle: dna.bundle,
uid: options.uid,
});
dnas.push({
hash: dnaHash,
role_id: `${dna.bundle.manifest.name}-${uuidv4()}`,
});
registerDnaReqOpts["bundle"] = dna.bundle;
role_id = `${dna.bundle.manifest.name}-${uuidv4()}`;
}

const dnaHash = await this.adminWs().registerDna(
registerDnaReqOpts as RegisterDnaRequest
);

dnas.push({ hash: dnaHash, role_id });
}

const installedAppInfo = await this.adminWs().installApp({
Expand Down
4 changes: 4 additions & 0 deletions ts/src/trycp/conductor/scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ export class TryCpScenario implements IScenario {
const signalHandler = Array.isArray(agentHappOptions)
? undefined
: agentHappOptions.signalHandler;
const properties = Array.isArray(agentHappOptions)
? undefined
: agentHappOptions.properties;
const agentsDnas: DnaSource[][] = Array.isArray(agentHappOptions)
? [agentHappOptions]
: [agentHappOptions.dnas];
const conductor = await this.addConductor(signalHandler);
const [agentHapp] = await conductor.installAgentsHapps({
agentsDnas,
uid: this.uid,
properties,
signalHandler,
});
return { conductor, ...agentHapp };
Expand Down
20 changes: 19 additions & 1 deletion ts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@ import {
AppWebsocket,
CallZomeRequest,
CapSecret,
DnaProperties,
DnaSource,
DnaBundle,
HoloHash,
InstalledCell,
MembraneProof,
RoleId,
RegisterDnaRequest,
} from "@holochain/client";

export type RegisterDnaReqOpts = Omit<
JettTech marked this conversation as resolved.
Show resolved Hide resolved
RegisterDnaRequest,
"hash" | "path" | "bundle"
> & {
hash?: HoloHash;
path?: string;
bundle?: DnaBundle;
};

/**
* The zome request options adapted to a specific cell.
*
Expand Down Expand Up @@ -104,6 +117,7 @@ export interface IConductor {
installAgentsHapps: (options: {
agentsDnas: DnaSource[][];
uid?: string;
properties?: DnaProperties;
signalHandler?: AppSignalCb;
}) => Promise<AgentHapp[]>;
}
Expand All @@ -116,7 +130,11 @@ export interface IConductor {
*/
export type AgentHappOptions =
| DnaSource[]
| { dnas: DnaSource[]; signalHandler?: AppSignalCb };
| {
dnas: DnaSource[];
signalHandler?: AppSignalCb;
properties?: DnaProperties;
};

/**
* Base interface of a Tryorama test scenario. Both {@link Scenario} and
Expand Down