@astrox/agent 0.0.20 → 0.0.24
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +4 -4
- package/lib/cjs/actor.d.ts +0 -126
- package/lib/cjs/actor.js +0 -207
- package/lib/cjs/actor.js.map +0 -1
- package/lib/cjs/agent/api.d.ts +0 -140
- package/lib/cjs/agent/api.js +0 -16
- package/lib/cjs/agent/api.js.map +0 -1
- package/lib/cjs/agent/http/index.d.ts +0 -49
- package/lib/cjs/agent/http/index.js +0 -355
- package/lib/cjs/agent/http/index.js.map +0 -1
- package/lib/cjs/agent/http/transforms.d.ts +0 -20
- package/lib/cjs/agent/http/transforms.js +0 -70
- package/lib/cjs/agent/http/transforms.js.map +0 -1
- package/lib/cjs/agent/http/types.d.ts +0 -77
- package/lib/cjs/agent/http/types.js +0 -24
- package/lib/cjs/agent/http/types.js.map +0 -1
- package/lib/cjs/agent/index.d.ts +0 -7
- package/lib/cjs/agent/index.js +0 -42
- package/lib/cjs/agent/index.js.map +0 -1
- package/lib/cjs/agent/proxy.d.ts +0 -85
- package/lib/cjs/agent/proxy.js +0 -159
- package/lib/cjs/agent/proxy.js.map +0 -1
- package/lib/cjs/auth.d.ts +0 -87
- package/lib/cjs/auth.js +0 -70
- package/lib/cjs/auth.js.map +0 -1
- package/lib/cjs/canisters/asset.d.ts +0 -10
- package/lib/cjs/canisters/asset.js +0 -18
- package/lib/cjs/canisters/asset.js.map +0 -1
- package/lib/cjs/canisters/asset_idl.d.ts +0 -7
- package/lib/cjs/canisters/asset_idl.js +0 -14
- package/lib/cjs/canisters/asset_idl.js.map +0 -1
- package/lib/cjs/canisters/management.d.ts +0 -33
- package/lib/cjs/canisters/management.js +0 -30
- package/lib/cjs/canisters/management.js.map +0 -1
- package/lib/cjs/canisters/management_idl.d.ts +0 -7
- package/lib/cjs/canisters/management_idl.js +0 -29
- package/lib/cjs/canisters/management_idl.js.map +0 -1
- package/lib/cjs/cbor.d.ts +0 -9
- package/lib/cjs/cbor.js +0 -138
- package/lib/cjs/cbor.js.map +0 -1
- package/lib/cjs/certificate.d.ts +0 -43
- package/lib/cjs/certificate.js +0 -227
- package/lib/cjs/certificate.js.map +0 -1
- package/lib/cjs/errors.d.ts +0 -8
- package/lib/cjs/errors.js +0 -13
- package/lib/cjs/errors.js.map +0 -1
- package/lib/cjs/index.d.ts +0 -52
- package/lib/cjs/index.js +0 -38
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/polling/index.d.ts +0 -16
- package/lib/cjs/polling/index.js +0 -81
- package/lib/cjs/polling/index.js.map +0 -1
- package/lib/cjs/polling/strategy.d.ts +0 -47
- package/lib/cjs/polling/strategy.js +0 -106
- package/lib/cjs/polling/strategy.js.map +0 -1
- package/lib/cjs/request_id.d.ts +0 -15
- package/lib/cjs/request_id.js +0 -89
- package/lib/cjs/request_id.js.map +0 -1
- package/lib/cjs/utils/bls.d.ts +0 -9
- package/lib/cjs/utils/bls.js +0 -65
- package/lib/cjs/utils/bls.js.map +0 -1
- package/lib/cjs/utils/buffer.d.ts +0 -16
- package/lib/cjs/utils/buffer.js +0 -59
- package/lib/cjs/utils/buffer.js.map +0 -1
- package/lib/cjs/vendor/bls/bls.d.ts +0 -28
- package/lib/cjs/vendor/bls/bls.js +0 -894
- package/lib/cjs/vendor/bls/bls.js.map +0 -1
- package/lib/esm/actor.d.ts +0 -126
- package/lib/esm/actor.js +0 -200
- package/lib/esm/actor.js.map +0 -1
- package/lib/esm/agent/api.d.ts +0 -140
- package/lib/esm/agent/api.js +0 -13
- package/lib/esm/agent/api.js.map +0 -1
- package/lib/esm/agent/http/index.d.ts +0 -49
- package/lib/esm/agent/http/index.js +0 -328
- package/lib/esm/agent/http/index.js.map +0 -1
- package/lib/esm/agent/http/transforms.d.ts +0 -20
- package/lib/esm/agent/http/transforms.js +0 -45
- package/lib/esm/agent/http/transforms.js.map +0 -1
- package/lib/esm/agent/http/types.d.ts +0 -77
- package/lib/esm/agent/http/types.js +0 -20
- package/lib/esm/agent/http/types.js.map +0 -1
- package/lib/esm/agent/index.d.ts +0 -7
- package/lib/esm/agent/index.js +0 -27
- package/lib/esm/agent/index.js.map +0 -1
- package/lib/esm/agent/proxy.d.ts +0 -85
- package/lib/esm/agent/proxy.js +0 -154
- package/lib/esm/agent/proxy.js.map +0 -1
- package/lib/esm/auth.d.ts +0 -87
- package/lib/esm/auth.js +0 -64
- package/lib/esm/auth.js.map +0 -1
- package/lib/esm/canisters/asset.d.ts +0 -10
- package/lib/esm/canisters/asset.js +0 -11
- package/lib/esm/canisters/asset.js.map +0 -1
- package/lib/esm/canisters/asset_idl.d.ts +0 -7
- package/lib/esm/canisters/asset_idl.js +0 -12
- package/lib/esm/canisters/asset_idl.js.map +0 -1
- package/lib/esm/canisters/management.d.ts +0 -37
- package/lib/esm/canisters/management.js +0 -23
- package/lib/esm/canisters/management.js.map +0 -1
- package/lib/esm/canisters/management_idl.d.ts +0 -7
- package/lib/esm/canisters/management_idl.js +0 -27
- package/lib/esm/canisters/management_idl.js.map +0 -1
- package/lib/esm/cbor.d.ts +0 -9
- package/lib/esm/cbor.js +0 -111
- package/lib/esm/cbor.js.map +0 -1
- package/lib/esm/certificate.d.ts +0 -43
- package/lib/esm/certificate.js +0 -200
- package/lib/esm/certificate.js.map +0 -1
- package/lib/esm/errors.d.ts +0 -8
- package/lib/esm/errors.js +0 -9
- package/lib/esm/errors.js.map +0 -1
- package/lib/esm/index.d.ts +0 -52
- package/lib/esm/index.js +0 -14
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/polling/index.d.ts +0 -16
- package/lib/esm/polling/index.js +0 -57
- package/lib/esm/polling/index.js.map +0 -1
- package/lib/esm/polling/strategy.d.ts +0 -47
- package/lib/esm/polling/strategy.js +0 -95
- package/lib/esm/polling/strategy.js.map +0 -1
- package/lib/esm/request_id.d.ts +0 -15
- package/lib/esm/request_id.js +0 -81
- package/lib/esm/request_id.js.map +0 -1
- package/lib/esm/utils/bls.d.ts +0 -9
- package/lib/esm/utils/bls.js +0 -43
- package/lib/esm/utils/bls.js.map +0 -1
- package/lib/esm/utils/buffer.d.ts +0 -16
- package/lib/esm/utils/buffer.js +0 -52
- package/lib/esm/utils/buffer.js.map +0 -1
- package/lib/esm/vendor/bls/bls.d.ts +0 -28
- package/lib/esm/vendor/bls/bls.js +0 -870
- package/lib/esm/vendor/bls/bls.js.map +0 -1
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"bls.js","sourceRoot":"","sources":["../../../../src/vendor/bls/bls.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,sEAAwD;AAExD,oBAAoB;AACpB,oBAAoB;AACpB,IAAI,IAAgB,CAAC;AAErB,qEAAqE;AACrE,uCAAuC;AACvC,oFAAoF;AACpF,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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1
|
-
import { Agent, QueryResponseRejected, SubmitResponse } from './agent';
|
2
|
-
import { AgentError } from './errors';
|
3
|
-
import { IDL } from '@astrox/candid';
|
4
|
-
import { PollStrategyFactory } from './polling';
|
5
|
-
import { Principal } from '@astrox/principal';
|
6
|
-
import { RequestId } from './request_id';
|
7
|
-
export declare class ActorCallError extends AgentError {
|
8
|
-
readonly canisterId: Principal;
|
9
|
-
readonly methodName: string;
|
10
|
-
readonly type: 'query' | 'update';
|
11
|
-
readonly props: Record<string, string>;
|
12
|
-
constructor(canisterId: Principal, methodName: string, type: 'query' | 'update', props: Record<string, string>);
|
13
|
-
}
|
14
|
-
export declare class QueryCallRejectedError extends ActorCallError {
|
15
|
-
readonly result: QueryResponseRejected;
|
16
|
-
constructor(canisterId: Principal, methodName: string, result: QueryResponseRejected);
|
17
|
-
}
|
18
|
-
export declare class UpdateCallRejectedError extends ActorCallError {
|
19
|
-
readonly requestId: RequestId;
|
20
|
-
readonly response: SubmitResponse['response'];
|
21
|
-
constructor(canisterId: Principal, methodName: string, requestId: RequestId, response: SubmitResponse['response']);
|
22
|
-
}
|
23
|
-
/**
|
24
|
-
* Configuration to make calls to the Replica.
|
25
|
-
*/
|
26
|
-
export interface CallConfig {
|
27
|
-
/**
|
28
|
-
* An agent to use in this call, otherwise the actor or call will try to discover the
|
29
|
-
* agent to use.
|
30
|
-
*/
|
31
|
-
agent?: Agent;
|
32
|
-
/**
|
33
|
-
* A polling strategy factory that dictates how much and often we should poll the
|
34
|
-
* read_state endpoint to get the result of an update call.
|
35
|
-
*/
|
36
|
-
pollingStrategyFactory?: PollStrategyFactory;
|
37
|
-
/**
|
38
|
-
* The canister ID of this Actor.
|
39
|
-
*/
|
40
|
-
canisterId?: string | Principal;
|
41
|
-
/**
|
42
|
-
* The effective canister ID. This should almost always be ignored.
|
43
|
-
*/
|
44
|
-
effectiveCanisterId?: Principal;
|
45
|
-
}
|
46
|
-
/**
|
47
|
-
* Configuration that can be passed to customize the Actor behaviour.
|
48
|
-
*/
|
49
|
-
export interface ActorConfig extends CallConfig {
|
50
|
-
/**
|
51
|
-
* The Canister ID of this Actor. This is required for an Actor.
|
52
|
-
*/
|
53
|
-
canisterId: string | Principal;
|
54
|
-
/**
|
55
|
-
* An override function for update calls' CallConfig. This will be called on every calls.
|
56
|
-
*/
|
57
|
-
callTransform?(methodName: string, args: unknown[], callConfig: CallConfig): Partial<CallConfig> | void;
|
58
|
-
/**
|
59
|
-
* An override function for query calls' CallConfig. This will be called on every query.
|
60
|
-
*/
|
61
|
-
queryTransform?(methodName: string, args: unknown[], callConfig: CallConfig): Partial<CallConfig> | void;
|
62
|
-
}
|
63
|
-
/**
|
64
|
-
* A subclass of an actor. Actor class itself is meant to be a based class.
|
65
|
-
*/
|
66
|
-
export declare type ActorSubclass<T = Record<string, ActorMethod>> = Actor & T;
|
67
|
-
/**
|
68
|
-
* An actor method type, defined for each methods of the actor service.
|
69
|
-
*/
|
70
|
-
export interface ActorMethod<Args extends unknown[] = unknown[], Ret extends unknown = unknown> {
|
71
|
-
(...args: Args): Promise<Ret>;
|
72
|
-
withOptions(options: CallConfig): (...args: Args) => Promise<Ret>;
|
73
|
-
}
|
74
|
-
/**
|
75
|
-
* The mode used when installing a canister.
|
76
|
-
*/
|
77
|
-
export declare enum CanisterInstallMode {
|
78
|
-
Install = "install",
|
79
|
-
Reinstall = "reinstall",
|
80
|
-
Upgrade = "upgrade"
|
81
|
-
}
|
82
|
-
/**
|
83
|
-
* Internal metadata for actors. It's an enhanced version of ActorConfig with
|
84
|
-
* some fields marked as required (as they are defaulted) and canisterId as
|
85
|
-
* a Principal type.
|
86
|
-
*/
|
87
|
-
interface ActorMetadata {
|
88
|
-
service: IDL.ServiceClass;
|
89
|
-
agent?: Agent;
|
90
|
-
config: ActorConfig;
|
91
|
-
}
|
92
|
-
declare const metadataSymbol: unique symbol;
|
93
|
-
/**
|
94
|
-
* An actor base class. An actor is an object containing only functions that will
|
95
|
-
* return a promise. These functions are derived from the IDL definition.
|
96
|
-
*/
|
97
|
-
export declare class Actor {
|
98
|
-
/**
|
99
|
-
* Get the Agent class this Actor would call, or undefined if the Actor would use
|
100
|
-
* the default agent (global.ic.agent).
|
101
|
-
* @param actor The actor to get the agent of.
|
102
|
-
*/
|
103
|
-
static agentOf(actor: Actor): Agent | undefined;
|
104
|
-
/**
|
105
|
-
* Get the interface of an actor, in the form of an instance of a Service.
|
106
|
-
* @param actor The actor to get the interface of.
|
107
|
-
*/
|
108
|
-
static interfaceOf(actor: Actor): IDL.ServiceClass;
|
109
|
-
static canisterIdOf(actor: Actor): Principal;
|
110
|
-
static install(fields: {
|
111
|
-
module: ArrayBuffer;
|
112
|
-
mode?: CanisterInstallMode;
|
113
|
-
arg?: ArrayBuffer;
|
114
|
-
}, config: ActorConfig): Promise<void>;
|
115
|
-
static createCanister(config?: CallConfig): Promise<Principal>;
|
116
|
-
static createAndInstallCanister(interfaceFactory: IDL.InterfaceFactory, fields: {
|
117
|
-
module: ArrayBuffer;
|
118
|
-
arg?: ArrayBuffer;
|
119
|
-
}, config?: CallConfig): Promise<ActorSubclass>;
|
120
|
-
static createActorClass(interfaceFactory: IDL.InterfaceFactory): ActorConstructor;
|
121
|
-
static createActor<T = Record<string, ActorMethod>>(interfaceFactory: IDL.InterfaceFactory, configuration: ActorConfig): ActorSubclass<T>;
|
122
|
-
private [metadataSymbol];
|
123
|
-
protected constructor(metadata: ActorMetadata);
|
124
|
-
}
|
125
|
-
export declare type ActorConstructor = new (config: ActorConfig) => ActorSubclass;
|
126
|
-
export {};
|
package/lib/esm/actor.js
DELETED
@@ -1,200 +0,0 @@
|
|
1
|
-
import { Buffer } from 'buffer/';
|
2
|
-
import { getDefaultAgent, ReplicaRejectCode, } from './agent';
|
3
|
-
import { getManagementCanister } from './canisters/management';
|
4
|
-
import { AgentError } from './errors';
|
5
|
-
import { IDL } from '@astrox/candid';
|
6
|
-
import { pollForResponse, strategy } from './polling';
|
7
|
-
import { Principal } from '@astrox/principal';
|
8
|
-
import { toHex } from './utils/buffer';
|
9
|
-
export class ActorCallError extends AgentError {
|
10
|
-
constructor(canisterId, methodName, type, props) {
|
11
|
-
super([
|
12
|
-
`Call failed:`,
|
13
|
-
` Canister: ${canisterId.toText()}`,
|
14
|
-
` Method: ${methodName} (${type})`,
|
15
|
-
...Object.getOwnPropertyNames(props).map(n => ` "${n}": ${JSON.stringify(props[n])}`),
|
16
|
-
].join('\n'));
|
17
|
-
this.canisterId = canisterId;
|
18
|
-
this.methodName = methodName;
|
19
|
-
this.type = type;
|
20
|
-
this.props = props;
|
21
|
-
}
|
22
|
-
}
|
23
|
-
export class QueryCallRejectedError extends ActorCallError {
|
24
|
-
constructor(canisterId, methodName, result) {
|
25
|
-
var _a;
|
26
|
-
super(canisterId, methodName, 'query', {
|
27
|
-
Status: result.status,
|
28
|
-
Code: (_a = ReplicaRejectCode[result.reject_code]) !== null && _a !== void 0 ? _a : `Unknown Code "${result.reject_code}"`,
|
29
|
-
Message: result.reject_message,
|
30
|
-
});
|
31
|
-
this.result = result;
|
32
|
-
}
|
33
|
-
}
|
34
|
-
export class UpdateCallRejectedError extends ActorCallError {
|
35
|
-
constructor(canisterId, methodName, requestId, response) {
|
36
|
-
super(canisterId, methodName, 'update', {
|
37
|
-
'Request ID': toHex(requestId),
|
38
|
-
'HTTP status code': response.status.toString(),
|
39
|
-
'HTTP status text': response.statusText,
|
40
|
-
});
|
41
|
-
this.requestId = requestId;
|
42
|
-
this.response = response;
|
43
|
-
}
|
44
|
-
}
|
45
|
-
/**
|
46
|
-
* The mode used when installing a canister.
|
47
|
-
*/
|
48
|
-
export var CanisterInstallMode;
|
49
|
-
(function (CanisterInstallMode) {
|
50
|
-
CanisterInstallMode["Install"] = "install";
|
51
|
-
CanisterInstallMode["Reinstall"] = "reinstall";
|
52
|
-
CanisterInstallMode["Upgrade"] = "upgrade";
|
53
|
-
})(CanisterInstallMode || (CanisterInstallMode = {}));
|
54
|
-
const metadataSymbol = Symbol.for('ic-agent-metadata');
|
55
|
-
/**
|
56
|
-
* An actor base class. An actor is an object containing only functions that will
|
57
|
-
* return a promise. These functions are derived from the IDL definition.
|
58
|
-
*/
|
59
|
-
export class Actor {
|
60
|
-
constructor(metadata) {
|
61
|
-
this[metadataSymbol] = Object.freeze(metadata);
|
62
|
-
}
|
63
|
-
/**
|
64
|
-
* Get the Agent class this Actor would call, or undefined if the Actor would use
|
65
|
-
* the default agent (global.ic.agent).
|
66
|
-
* @param actor The actor to get the agent of.
|
67
|
-
*/
|
68
|
-
static agentOf(actor) {
|
69
|
-
return actor[metadataSymbol].config.agent;
|
70
|
-
}
|
71
|
-
/**
|
72
|
-
* Get the interface of an actor, in the form of an instance of a Service.
|
73
|
-
* @param actor The actor to get the interface of.
|
74
|
-
*/
|
75
|
-
static interfaceOf(actor) {
|
76
|
-
return actor[metadataSymbol].service;
|
77
|
-
}
|
78
|
-
static canisterIdOf(actor) {
|
79
|
-
return Principal.from(actor[metadataSymbol].config.canisterId);
|
80
|
-
}
|
81
|
-
static async install(fields, config) {
|
82
|
-
const mode = fields.mode === undefined ? CanisterInstallMode.Install : fields.mode;
|
83
|
-
// Need to transform the arg into a number array.
|
84
|
-
const arg = fields.arg ? [...new Uint8Array(fields.arg)] : [];
|
85
|
-
// Same for module.
|
86
|
-
const wasmModule = [...new Uint8Array(fields.module)];
|
87
|
-
const canisterId = typeof config.canisterId === 'string'
|
88
|
-
? Principal.fromText(config.canisterId)
|
89
|
-
: config.canisterId;
|
90
|
-
await getManagementCanister(config).install_code({
|
91
|
-
mode: { [mode]: null },
|
92
|
-
arg,
|
93
|
-
wasm_module: wasmModule,
|
94
|
-
canister_id: canisterId,
|
95
|
-
});
|
96
|
-
}
|
97
|
-
static async createCanister(config) {
|
98
|
-
const { canister_id: canisterId } = await getManagementCanister(config || {}).provisional_create_canister_with_cycles({ amount: [], settings: [] });
|
99
|
-
return canisterId;
|
100
|
-
}
|
101
|
-
static async createAndInstallCanister(interfaceFactory, fields, config) {
|
102
|
-
const canisterId = await this.createCanister(config);
|
103
|
-
await this.install(Object.assign({}, fields), Object.assign(Object.assign({}, config), { canisterId }));
|
104
|
-
return this.createActor(interfaceFactory, Object.assign(Object.assign({}, config), { canisterId }));
|
105
|
-
}
|
106
|
-
static createActorClass(interfaceFactory) {
|
107
|
-
const service = interfaceFactory({ IDL });
|
108
|
-
class CanisterActor extends Actor {
|
109
|
-
constructor(config) {
|
110
|
-
const canisterId = typeof config.canisterId === 'string'
|
111
|
-
? Principal.fromText(config.canisterId)
|
112
|
-
: config.canisterId;
|
113
|
-
super({
|
114
|
-
config: Object.assign(Object.assign(Object.assign({}, DEFAULT_ACTOR_CONFIG), config), { canisterId }),
|
115
|
-
service,
|
116
|
-
});
|
117
|
-
for (const [methodName, func] of service._fields) {
|
118
|
-
this[methodName] = _createActorMethod(this, methodName, func);
|
119
|
-
}
|
120
|
-
}
|
121
|
-
}
|
122
|
-
return CanisterActor;
|
123
|
-
}
|
124
|
-
static createActor(interfaceFactory, configuration) {
|
125
|
-
return new (this.createActorClass(interfaceFactory))(configuration);
|
126
|
-
}
|
127
|
-
}
|
128
|
-
// IDL functions can have multiple return values, so decoding always
|
129
|
-
// produces an array. Ensure that functions with single or zero return
|
130
|
-
// values behave as expected.
|
131
|
-
function decodeReturnValue(types, msg) {
|
132
|
-
const returnValues = IDL.decode(types, Buffer.from(msg));
|
133
|
-
switch (returnValues.length) {
|
134
|
-
case 0:
|
135
|
-
return undefined;
|
136
|
-
case 1:
|
137
|
-
return returnValues[0];
|
138
|
-
default:
|
139
|
-
return returnValues;
|
140
|
-
}
|
141
|
-
}
|
142
|
-
const DEFAULT_ACTOR_CONFIG = {
|
143
|
-
pollingStrategyFactory: strategy.defaultStrategy,
|
144
|
-
};
|
145
|
-
function _createActorMethod(actor, methodName, func) {
|
146
|
-
let caller;
|
147
|
-
if (func.annotations.includes('query')) {
|
148
|
-
caller = async (options, ...args) => {
|
149
|
-
var _a, _b;
|
150
|
-
// First, if there's a config transformation, call it.
|
151
|
-
options = Object.assign(Object.assign({}, options), (_b = (_a = actor[metadataSymbol].config).queryTransform) === null || _b === void 0 ? void 0 : _b.call(_a, methodName, args, Object.assign(Object.assign({}, actor[metadataSymbol].config), options)));
|
152
|
-
const agent = options.agent || actor[metadataSymbol].config.agent || getDefaultAgent();
|
153
|
-
const cid = Principal.from(options.canisterId || actor[metadataSymbol].config.canisterId);
|
154
|
-
const arg = IDL.encode(func.argTypes, args);
|
155
|
-
const result = await agent.query(cid, { methodName, arg });
|
156
|
-
switch (result.status) {
|
157
|
-
case "rejected" /* Rejected */:
|
158
|
-
throw new QueryCallRejectedError(cid, methodName, result);
|
159
|
-
case "replied" /* Replied */:
|
160
|
-
return decodeReturnValue(func.retTypes, result.reply.arg);
|
161
|
-
}
|
162
|
-
};
|
163
|
-
}
|
164
|
-
else {
|
165
|
-
caller = async (options, ...args) => {
|
166
|
-
var _a, _b;
|
167
|
-
// First, if there's a config transformation, call it.
|
168
|
-
options = Object.assign(Object.assign({}, options), (_b = (_a = actor[metadataSymbol].config).callTransform) === null || _b === void 0 ? void 0 : _b.call(_a, methodName, args, Object.assign(Object.assign({}, actor[metadataSymbol].config), options)));
|
169
|
-
const agent = options.agent || actor[metadataSymbol].config.agent || getDefaultAgent();
|
170
|
-
const { canisterId, effectiveCanisterId, pollingStrategyFactory } = Object.assign(Object.assign(Object.assign({}, DEFAULT_ACTOR_CONFIG), actor[metadataSymbol].config), options);
|
171
|
-
const cid = Principal.from(canisterId);
|
172
|
-
const ecid = effectiveCanisterId !== undefined ? Principal.from(effectiveCanisterId) : cid;
|
173
|
-
const arg = IDL.encode(func.argTypes, args);
|
174
|
-
const { requestId, response } = await agent.call(cid, {
|
175
|
-
methodName,
|
176
|
-
arg,
|
177
|
-
effectiveCanisterId: ecid,
|
178
|
-
});
|
179
|
-
if (!response.ok) {
|
180
|
-
throw new UpdateCallRejectedError(cid, methodName, requestId, response);
|
181
|
-
}
|
182
|
-
const pollStrategy = pollingStrategyFactory();
|
183
|
-
const responseBytes = await pollForResponse(agent, ecid, requestId, pollStrategy);
|
184
|
-
if (responseBytes !== undefined) {
|
185
|
-
return decodeReturnValue(func.retTypes, responseBytes);
|
186
|
-
}
|
187
|
-
else if (func.retTypes.length === 0) {
|
188
|
-
return undefined;
|
189
|
-
}
|
190
|
-
else {
|
191
|
-
throw new Error(`Call was returned undefined, but type [${func.retTypes.join(',')}].`);
|
192
|
-
}
|
193
|
-
};
|
194
|
-
}
|
195
|
-
const handler = (...args) => caller({}, ...args);
|
196
|
-
handler.withOptions =
|
197
|
-
(options) => (...args) => caller(options, ...args);
|
198
|
-
return handler;
|
199
|
-
}
|
200
|
-
//# sourceMappingURL=actor.js.map
|
package/lib/esm/actor.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"actor.js","sourceRoot":"","sources":["../../src/actor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAEL,eAAe,EAGf,iBAAiB,GAElB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,eAAe,EAAuB,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,MAAM,OAAO,cAAe,SAAQ,UAAU;IAC5C,YACkB,UAAqB,EACrB,UAAkB,EAClB,IAAwB,EACxB,KAA6B;QAE7C,KAAK,CACH;YACE,cAAc;YACd,eAAe,UAAU,CAAC,MAAM,EAAE,EAAE;YACpC,aAAa,UAAU,KAAK,IAAI,GAAG;YACnC,GAAG,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,GAAG,CA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AAE,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5D,OAAO,CAAC,WAAW;QACjB,CAAC,OAAmB,EAAE,EAAE,CACxB,CAAC,GAAG,IAAe,EAAE,EAAE,CACrB,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAC7B,OAAO,OAAsB,CAAC;AAChC,CAAC"}
|
package/lib/esm/agent/api.d.ts
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
import { Principal } from '@astrox/principal';
|
2
|
-
import { RequestId } from '../request_id';
|
3
|
-
import { JsonObject } from '@astrox/candid';
|
4
|
-
/**
|
5
|
-
* Codes used by the replica for rejecting a message.
|
6
|
-
* See {@link https://sdk.dfinity.org/docs/interface-spec/#reject-codes | the interface spec}.
|
7
|
-
*/
|
8
|
-
export declare enum ReplicaRejectCode {
|
9
|
-
SysFatal = 1,
|
10
|
-
SysTransient = 2,
|
11
|
-
DestinationInvalid = 3,
|
12
|
-
CanisterReject = 4,
|
13
|
-
CanisterError = 5
|
14
|
-
}
|
15
|
-
/**
|
16
|
-
* Options when doing a {@link Agent.readState} call.
|
17
|
-
*/
|
18
|
-
export interface ReadStateOptions {
|
19
|
-
/**
|
20
|
-
* A list of paths to read the state of.
|
21
|
-
*/
|
22
|
-
paths: ArrayBuffer[][];
|
23
|
-
}
|
24
|
-
/**
|
25
|
-
*
|
26
|
-
*/
|
27
|
-
export declare type QueryResponse = QueryResponseReplied | QueryResponseRejected;
|
28
|
-
export declare const enum QueryResponseStatus {
|
29
|
-
Replied = "replied",
|
30
|
-
Rejected = "rejected"
|
31
|
-
}
|
32
|
-
export interface QueryResponseBase {
|
33
|
-
status: QueryResponseStatus;
|
34
|
-
}
|
35
|
-
export interface QueryResponseReplied extends QueryResponseBase {
|
36
|
-
status: QueryResponseStatus.Replied;
|
37
|
-
reply: {
|
38
|
-
arg: ArrayBuffer;
|
39
|
-
};
|
40
|
-
}
|
41
|
-
export interface QueryResponseRejected extends QueryResponseBase {
|
42
|
-
status: QueryResponseStatus.Rejected;
|
43
|
-
reject_code: ReplicaRejectCode;
|
44
|
-
reject_message: string;
|
45
|
-
}
|
46
|
-
/**
|
47
|
-
* Options when doing a {@link Agent.query} call.
|
48
|
-
*/
|
49
|
-
export interface QueryFields {
|
50
|
-
/**
|
51
|
-
* The method name to call.
|
52
|
-
*/
|
53
|
-
methodName: string;
|
54
|
-
/**
|
55
|
-
* A binary encoded argument. This is already encoded and will be sent as is.
|
56
|
-
*/
|
57
|
-
arg: ArrayBuffer;
|
58
|
-
}
|
59
|
-
/**
|
60
|
-
* Options when doing a {@link Agent.call} call.
|
61
|
-
*/
|
62
|
-
export interface CallOptions {
|
63
|
-
/**
|
64
|
-
* The method name to call.
|
65
|
-
*/
|
66
|
-
methodName: string;
|
67
|
-
/**
|
68
|
-
* A binary encoded argument. This is already encoded and will be sent as is.
|
69
|
-
*/
|
70
|
-
arg: ArrayBuffer;
|
71
|
-
/**
|
72
|
-
* An effective canister ID, used for routing. This should only be mentioned if
|
73
|
-
* it's different from the canister ID.
|
74
|
-
*/
|
75
|
-
effectiveCanisterId: Principal | string;
|
76
|
-
}
|
77
|
-
export interface ReadStateResponse {
|
78
|
-
certificate: ArrayBuffer;
|
79
|
-
}
|
80
|
-
export interface SubmitResponse {
|
81
|
-
requestId: RequestId;
|
82
|
-
response: {
|
83
|
-
ok: boolean;
|
84
|
-
status: number;
|
85
|
-
statusText: string;
|
86
|
-
};
|
87
|
-
}
|
88
|
-
/**
|
89
|
-
* An Agent able to make calls and queries to a Replica.
|
90
|
-
*/
|
91
|
-
export interface Agent {
|
92
|
-
readonly rootKey: ArrayBuffer | null;
|
93
|
-
/**
|
94
|
-
* Returns the principal ID associated with this agent (by default). It only shows
|
95
|
-
* the principal of the default identity in the agent, which is the principal used
|
96
|
-
* when calls don't specify it.
|
97
|
-
*/
|
98
|
-
getPrincipal(): Promise<Principal>;
|
99
|
-
/**
|
100
|
-
* Send a read state query to the replica. This includes a list of paths to return,
|
101
|
-
* and will return a Certificate. This will only reject on communication errors,
|
102
|
-
* but the certificate might contain less information than requested.
|
103
|
-
* @param effectiveCanisterId A Canister ID related to this call.
|
104
|
-
* @param options The options for this call.
|
105
|
-
*/
|
106
|
-
readState(effectiveCanisterId: Principal | string, options: ReadStateOptions): Promise<ReadStateResponse>;
|
107
|
-
call(canisterId: Principal | string, fields: CallOptions): Promise<SubmitResponse>;
|
108
|
-
/**
|
109
|
-
* Query the status endpoint of the replica. This normally has a few fields that
|
110
|
-
* corresponds to the version of the replica, its root public key, and any other
|
111
|
-
* information made public.
|
112
|
-
* @returns A JsonObject that is essentially a record of fields from the status
|
113
|
-
* endpoint.
|
114
|
-
*/
|
115
|
-
status(): Promise<JsonObject>;
|
116
|
-
/**
|
117
|
-
* Send a query call to a canister. See
|
118
|
-
* {@link https://sdk.dfinity.org/docs/interface-spec/#http-query | the interface spec}.
|
119
|
-
* @param canisterId The Principal of the Canister to send the query to. Sending a query to
|
120
|
-
* the management canister is not supported (as it has no meaning from an agent).
|
121
|
-
* @param options Options to use to create and send the query.
|
122
|
-
* @returns The response from the replica. The Promise will only reject when the communication
|
123
|
-
* failed. If the query itself failed but no protocol errors happened, the response will
|
124
|
-
* be of type QueryResponseRejected.
|
125
|
-
*/
|
126
|
-
query(canisterId: Principal | string, options: QueryFields): Promise<QueryResponse>;
|
127
|
-
/**
|
128
|
-
* By default, the agent is configured to talk to the main Internet Computer,
|
129
|
-
* and verifies responses using a hard-coded public key.
|
130
|
-
*
|
131
|
-
* This function will instruct the agent to ask the endpoint for its public
|
132
|
-
* key, and use that instead. This is required when talking to a local test
|
133
|
-
* instance, for example.
|
134
|
-
*
|
135
|
-
* Only use this when you are _not_ talking to the main Internet Computer,
|
136
|
-
* otherwise you are prone to man-in-the-middle attacks! Do not call this
|
137
|
-
* function by default.
|
138
|
-
*/
|
139
|
-
fetchRootKey(): Promise<ArrayBuffer>;
|
140
|
-
}
|
package/lib/esm/agent/api.js
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Codes used by the replica for rejecting a message.
|
3
|
-
* See {@link https://sdk.dfinity.org/docs/interface-spec/#reject-codes | the interface spec}.
|
4
|
-
*/
|
5
|
-
export var ReplicaRejectCode;
|
6
|
-
(function (ReplicaRejectCode) {
|
7
|
-
ReplicaRejectCode[ReplicaRejectCode["SysFatal"] = 1] = "SysFatal";
|
8
|
-
ReplicaRejectCode[ReplicaRejectCode["SysTransient"] = 2] = "SysTransient";
|
9
|
-
ReplicaRejectCode[ReplicaRejectCode["DestinationInvalid"] = 3] = "DestinationInvalid";
|
10
|
-
ReplicaRejectCode[ReplicaRejectCode["CanisterReject"] = 4] = "CanisterReject";
|
11
|
-
ReplicaRejectCode[ReplicaRejectCode["CanisterError"] = 5] = "CanisterError";
|
12
|
-
})(ReplicaRejectCode || (ReplicaRejectCode = {}));
|
13
|
-
//# sourceMappingURL=api.js.map
|
package/lib/esm/agent/api.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/agent/api.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,CAAN,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,iEAAY,CAAA;IACZ,yEAAgB,CAAA;IAChB,qFAAsB,CAAA;IACtB,6EAAkB,CAAA;IAClB,2EAAiB,CAAA;AACnB,CAAC,EANW,iBAAiB,KAAjB,iBAAiB,QAM5B"}
|
@@ -1,49 +0,0 @@
|
|
1
|
-
import { JsonObject } from '@astrox/candid';
|
2
|
-
import { Principal } from '@astrox/principal';
|
3
|
-
import { Identity } from '../../auth';
|
4
|
-
import { Agent, QueryFields, QueryResponse, ReadStateOptions, ReadStateResponse, SubmitResponse } from '../api';
|
5
|
-
import { HttpAgentRequest, HttpAgentRequestTransformFn } from './types';
|
6
|
-
export * from './transforms';
|
7
|
-
export { Nonce, makeNonce } from './types';
|
8
|
-
export declare enum RequestStatusResponseStatus {
|
9
|
-
Received = "received",
|
10
|
-
Processing = "processing",
|
11
|
-
Replied = "replied",
|
12
|
-
Rejected = "rejected",
|
13
|
-
Unknown = "unknown",
|
14
|
-
Done = "done"
|
15
|
-
}
|
16
|
-
export interface HttpAgentOptions {
|
17
|
-
source?: HttpAgent;
|
18
|
-
fetch?: typeof fetch;
|
19
|
-
fetchAgent?: typeof fetch;
|
20
|
-
host?: string;
|
21
|
-
identity?: Identity | Promise<Identity>;
|
22
|
-
credentials?: {
|
23
|
-
name: string;
|
24
|
-
password?: string;
|
25
|
-
};
|
26
|
-
}
|
27
|
-
export declare class HttpAgent implements Agent {
|
28
|
-
rootKey: ArrayBuffer;
|
29
|
-
private readonly _pipeline;
|
30
|
-
private readonly _identity;
|
31
|
-
private readonly _fetch;
|
32
|
-
private readonly _fetchAgent;
|
33
|
-
private readonly _host;
|
34
|
-
private readonly _credentials;
|
35
|
-
private _rootKeyFetched;
|
36
|
-
constructor(options?: HttpAgentOptions);
|
37
|
-
addTransform(fn: HttpAgentRequestTransformFn, priority?: number): void;
|
38
|
-
getPrincipal(): Promise<Principal>;
|
39
|
-
call(canisterId: Principal | string, options: {
|
40
|
-
methodName: string;
|
41
|
-
arg: ArrayBuffer;
|
42
|
-
effectiveCanisterId?: Principal | string;
|
43
|
-
}, identity?: Identity | Promise<Identity>): Promise<SubmitResponse>;
|
44
|
-
query(canisterId: Principal | string, fields: QueryFields, identity?: Identity | Promise<Identity>): Promise<QueryResponse>;
|
45
|
-
readState(canisterId: Principal | string, fields: ReadStateOptions, identity?: Identity | Promise<Identity>): Promise<ReadStateResponse>;
|
46
|
-
status(): Promise<JsonObject>;
|
47
|
-
fetchRootKey(): Promise<ArrayBuffer>;
|
48
|
-
protected _transform(request: HttpAgentRequest): Promise<HttpAgentRequest>;
|
49
|
-
}
|