Skip to content

Commit

Permalink
Add typedoc plugins and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
b3hr4d committed Feb 16, 2024
1 parent a6211a7 commit 986bb95
Show file tree
Hide file tree
Showing 110 changed files with 3,977 additions and 1,017 deletions.
43 changes: 41 additions & 2 deletions docs/classes/_ic_reactor_store.ActorManager.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/classes/_ic_reactor_store.AgentManager.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/classes/_ic_reactor_store.AuthClient.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/classes/_ic_reactor_store.CandidManager.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/classes/_ic_reactor_store.HttpAgent.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/classes/_ic_reactor_store.Principal.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/classes/_ic_reactor_visitor.VisitDetails.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/classes/_ic_reactor_visitor.VisitFields.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/classes/_ic_reactor_visitor.VisitRandomArgs.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/classes/_ic_reactor_visitor.VisitRandomResponse.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/classes/_ic_reactor_visitor.VisitTransform.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/classes/_ic_reactor_visitor.VisitTransformTable.html

Large diffs are not rendered by default.

50 changes: 45 additions & 5 deletions docs/functions/_ic_reactor_store.createActorManager.html

Large diffs are not rendered by default.

60 changes: 54 additions & 6 deletions docs/functions/_ic_reactor_store.createAgentManager.html

Large diffs are not rendered by default.

47 changes: 43 additions & 4 deletions docs/functions/_ic_reactor_store.createReActorStore.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/functions/_ic_reactor_store.generateActorHash.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/functions/_ic_reactor_store.generateHash.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/functions/_ic_reactor_store.generateRequestHash.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/functions/_ic_reactor_store.jsonToString.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/functions/_ic_reactor_store.stringToHash.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/functions/_ic_reactor_visitor.convertStringToNumber.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/functions/_ic_reactor_visitor.extractAndSortArgs.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/functions/_ic_reactor_visitor.isImage.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/functions/_ic_reactor_visitor.isQuery.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/functions/_ic_reactor_visitor.isUrl.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/functions/_ic_reactor_visitor.validateError.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/functions/_ic_reactor_visitor.validateNumberError.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/hierarchy.html

Large diffs are not rendered by default.

Binary file added docs/ic-reactor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 41 additions & 2 deletions docs/index.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_store.ActorManagerOptions.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_store.ActorMethod.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/interfaces/_ic_reactor_store.ActorMethodState.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_store.AgentAuthState.html

Large diffs are not rendered by default.

45 changes: 42 additions & 3 deletions docs/interfaces/_ic_reactor_store.AgentManagerOptions.html

Large diffs are not rendered by default.

47 changes: 43 additions & 4 deletions docs/interfaces/_ic_reactor_store.CreateReActorOptions.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/interfaces/_ic_reactor_store.DefaultActorType.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_store.HttpAgentOptions.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_store.Identity.html

Large diffs are not rendered by default.

45 changes: 42 additions & 3 deletions docs/interfaces/_ic_reactor_store.UpdateAgentOptions.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.DefaultField.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.DynamicDataArgs.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.ExtractedServiceDetails.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.ExtractedServiceFields.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.FieldDetails.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.FieldDetailsWithChild.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.InputDetails.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.InputField.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.MethodFields.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.NumberField.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.OptionalFields.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.PrincipalField.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.RecordFields.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.RecursiveFields.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.ResultArrayData.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.ResultRecordData.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.TupleFields.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.VariantFields.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/interfaces/_ic_reactor_visitor.VectorFields.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/modules/_ic_reactor_core.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/modules/_ic_reactor_react.html

Large diffs are not rendered by default.

81 changes: 63 additions & 18 deletions docs/modules/_ic_reactor_store.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/modules/_ic_reactor_svelte.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/modules/_ic_reactor_visitor.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_store.ActorMethodStates.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_store.ActorState.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_store.ActorStore.html

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions docs/types/_ic_reactor_store.ActorSubclass.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_store.AgentAuthStore.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_store.CallActorMethod.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_store.CanisterId.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_store.ExtractActorMethodArgs.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_store.ExtractActorMethodReturnType.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_store.ExtractVisitorType.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_store.ExtractedService.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_store.FunctionName.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_store.FunctionType.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.AllFieldTypes.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.AllNumberTypes.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.DynamicFieldType.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.DynamicFieldTypeByClass.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.ExtraInputFormFields.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.FieldTypeFromIDLType.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.FunctionCategory.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.MethodDefaultValues.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.MethodDetails.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.MethodResult.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.MethodResultValue.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.OtherDetails.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.ServiceDefaultValues.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.ServiceDetails.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/types/_ic_reactor_visitor.ServiceFields.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/variables/_ic_reactor_store.IC_HOST_NETWORK_URI.html

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/variables/_ic_reactor_store.LOCAL_HOST_NETWORK_URI.html

Large diffs are not rendered by default.

Binary file added ic-reactor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"text-encoding": "0.7.0",
"ts-jest": "29.1",
"typedoc": "^0.25.8",
"typedoc-plugin-extras": "^3.0.0",
"typedoc-plugin-include-example": "^1.2.0",
"typedoc-plugin-mdn-links": "^3.1.16",
"typescript": "^5.3",
"whatwg-fetch": "3.6",
Expand Down
62 changes: 16 additions & 46 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
import {
createReActorStore,
type ActorSubclass,
type DefaultActorType,
} from "@ic-reactor/store"
import {
createReActorCandidStore,
CreateReActorCandidOptions,
ActorCandidManager,
} from "@ic-reactor/candid"
import { type ActorSubclass, type DefaultActorType } from "@ic-reactor/store"
import { createReActorStore, CreateReActorOptions } from "@ic-reactor/store"
import { getActorHooks } from "./hooks/actor"
import { getAuthHooks } from "./hooks/auth"
import { CreateReActor } from "./types"

export * from "@ic-reactor/candid"
export * from "@ic-reactor/store"

export * from "./context/agent"
export * from "./context/actor"

export interface CreateReactActorOptions extends CreateReActorCandidOptions {
withServiceFields?: boolean
withServiceDetails?: boolean
export interface CreateReactActorOptions extends CreateReActorOptions {
withVisitor?: boolean
}

export const createReActor: CreateReActor = <
A extends ActorSubclass<any> = DefaultActorType
>({
isLocalEnv,
withServiceFields,
withServiceDetails,
withVisitor,
...options
}: CreateReactActorOptions) => {
isLocalEnv =
Expand All @@ -36,38 +26,19 @@ export const createReActor: CreateReActor = <
(process.env.DFX_NETWORK === "local" ||
process.env.NODE_ENV === "development"))

let actorManager: ActorCandidManager<A>
let actorManager = createReActorStore<A>({
isLocalEnv,
...options,
})

if (withServiceFields || withServiceDetails) {
actorManager = createReActorCandidStore<A>({
isLocalEnv,
...options,
})
} else {
actorManager = createReActorStore<A>({
isLocalEnv,
...options,
}) as unknown as ActorCandidManager<A>
}

const getServiceFields = () => {
if (!withServiceFields || !actorManager.serviceFields) {
const getVisitFunction = () => {
if (!withVisitor) {
throw new Error(
"Service fields not initialized. Pass `withServiceFields` to initialize service fields."
"Service fields not initialized. Pass `withVisitor` to initialize service fields."
)
}

return actorManager.serviceFields
}

const getServiceDetails = () => {
if (!withServiceDetails || !actorManager.serviceDetails) {
throw new Error(
"Service details not initialized. Pass `withServiceDetails` to initialize service details."
)
}

return actorManager.serviceDetails
return actorManager.visitFunction
}

const getAgent = () => {
Expand All @@ -79,9 +50,8 @@ export const createReActor: CreateReActor = <

return {
getAgent,
getServiceFields,
getServiceDetails,
getVisitFunction,
...actorHooks,
...authHooks,
} as any
}
}
32 changes: 7 additions & 25 deletions packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
ServiceDetails,
MethodDetails,
MethodResult,
} from "@ic-reactor/candid"
} from "@ic-reactor/visitor"
import type {
ActorState,
CanisterId,
Expand All @@ -17,6 +17,7 @@ import type {
Principal,
FunctionType,
FunctionName,
ExtractedService,
} from "@ic-reactor/store"
import type { AuthHooks } from "./hooks/auth"

Expand Down Expand Up @@ -193,40 +194,21 @@ export interface ActorDefaultHooks<A, F extends boolean, D extends boolean> {

export type GetFunctions<A> = {
getAgent: () => HttpAgent
getServiceFields: () => ExtractedServiceFields<A>
getServiceDetails: () => ExtractedServiceDetails<A>
getVisitFunction: () => ExtractedService<A>
}

export type CreateReActor = {
// When withServiceFields is true and withServiceDetails is true
// When withVisitor is true
<A>(
options: CreateReActorOptions & {
withServiceFields: true
withServiceDetails: true
withVisitor: true
}
): GetFunctions<A> & ActorHooks<A, true, true> & AuthHooks

// When withServiceFields is true and withServiceDetails is false or undefined
// When withVisitor are false or undefined
<A>(
options: CreateReActorOptions & {
withServiceFields: true
withServiceDetails?: false | undefined
}
): GetFunctions<A> & ActorHooks<A, true, false> & AuthHooks

// When withServiceFields is false or undefined and withServiceDetails is true
<A>(
options: CreateReActorOptions & {
withServiceFields?: false | undefined
withServiceDetails: true
}
): GetFunctions<A> & ActorHooks<A, false, true> & AuthHooks

// When both withServiceFields and withServiceDetails are false or undefined
<A>(
options: CreateReActorOptions & {
withServiceFields?: false | undefined
withServiceDetails?: false | undefined
withVisitor?: false | undefined
}
): GetFunctions<A> & ActorHooks<A, false, false> & AuthHooks
}
95 changes: 47 additions & 48 deletions packages/store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,77 +26,76 @@ yarn add @ic-reactor/store

## Usage

To use `@ic-reactor/store`, start by creating a ReActor manager with your actor configurations:
You can this packages in two ways:

1. **Automatic Agent Creation**: You can use the `createReActorStore` factory function to create a new ReActor store instance. This will automatically create an agent and manage its state for you.

```ts
import createReActorManager from "@ic-reactor/store"
import { idlFactory, canisterId } from "./declarations/actor"
import { createReActorStore } from "@ic-reactor/store"
import { candid, canisterId, idlFactory } from "./candid"

type Actor = typeof actor
type Candid = typeof candid

const { actorStore, authenticate, callMethod } = createReActorStore<Actor>({
const { callMethod, agentManager } = createReActorStore<Candid>({
canisterId,
idlFactory,
canisterId: "xeka7-ryaaa-aaaal-qb57a-cai",
host: "https://icp-api.io",
})

// later in your code
const identity = await agentManager.authenticate()
const data = await callMethod("version")
```

### Managing Actor State
2. **Manual Agent Creation**: You can use the `createAgentManager` to manually create and manage an agent instance.

Utilize the ReActor manager to manage the state of your IC actors:
- IC Agent

```ts
// Access and update actor state
const actorState = actorStore.getState()
```

### Handling Authentication
// agent.ts
import { createAgentManager } from "@ic-reactor/store"

Manage authentication states and processes:
export const agentManager = createAgentManager() // connect to the default ic network

```javascript
// Authenticate with the IC blockchain
authenticate()
.then(() => {
// Handle successful authentication
})
.catch((error) => {
// Handle authentication errors
})
// later in your code
const identity = await agentManager.authenticate()
```

### Calling Actor Methods
- Local Agent

Call actor methods and handle the results:
```ts
// agent.ts
import { createAgentManager } from "@ic-reactor/store"

```javascript
// Call an actor method
callMethod({
functionName: "get_balance",
args: [principal],
export const agentManager = createAgentManager({
isLocalEnv: true,
port: 8000, // default port is 4943
})
.then((result) => {
// Handle successful method call
})
.catch((error) => {
// Handle method call errors
})
```

## API Reference

`@ic-reactor/store` provides several key functionalities:
- Or you can use the host option directly

- `ReActorManager`: The main class to manage actor states and interactions.
- `createReActorManager`: Factory function to create a new ReActor manager instance.
- State management actions: Methods to initialize actors, handle authentication, and manage global state.
```ts
export const agentManager = createAgentManager({
host: "http://localhost:8000",
})
```

For a detailed API reference, including the complete list of methods and their usage, please refer to the [documentation](#).
then you can use the "createActorManager" to create an actor manager

## Contributing
```ts
// actor.ts
import { createActorManager } from "@ic-reactor/store"
import { candid, canisterId, idlFactory } from "./candid"
import { agentManager } from "./agent"

Contributions to `@ic-reactor/store` are welcome! Please read our [contributing guidelines](#) for more information.
type Candid = typeof candid

## License
const actorManager = createActorManager<Candid>({
agentManager,
canisterId,
idlFactory,
})

`@ic-reactor/store` is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
// later in your code
const data = await actorManager.callMethod("version")
```
Loading

0 comments on commit 986bb95

Please sign in to comment.