@ic-naming/client
Advanced tools
Comparing version 0.3.0-1 to 0.3.0-2
@@ -5,2 +5,9 @@ # Changelog | ||
## [0.3.0-2](https://github.com/IC-Naming/js-sdk/compare/v0.3.0-1...v0.3.0-2) (2022-03-24) | ||
### Features | ||
* option `enableTTL` ([45b71c5](https://github.com/IC-Naming/js-sdk/commit/45b71c52fcfeb16e963de960635e7f6b5079af19)) | ||
## [0.3.0-1](https://github.com/IC-Naming/js-sdk/compare/v0.3.0-0...v0.3.0-1) (2022-03-23) | ||
@@ -7,0 +14,0 @@ |
@@ -7,14 +7,2 @@ 'use strict'; | ||
class IcNamingError extends Error { | ||
} | ||
// More error type eg: `export class IcNamingInternalError extends IcNamingError {}` | ||
class IcNamingCanisterError extends IcNamingError { | ||
constructor(rawResult) { | ||
var _a; | ||
const result = rawResult; | ||
super(`IcNamingCanisterError: ${((_a = result === null || result === void 0 ? void 0 : result.Err) === null || _a === void 0 ? void 0 : _a.message) || "unknown"}`); | ||
this.theIcNamingCanisterErrorResult = rawResult; | ||
} | ||
} | ||
/*! ***************************************************************************** | ||
@@ -45,2 +33,45 @@ Copyright (c) Microsoft Corporation. | ||
class InMemoryNameRecordsCacheStore { | ||
constructor() { | ||
this.map = {}; | ||
} | ||
getRecordsByName(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.map[name]; | ||
}); | ||
} | ||
setRecordsByName(name, value) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.map[name] = value; | ||
}); | ||
} | ||
} | ||
class IcNamingError extends Error { | ||
} | ||
// More error type eg: `export class IcNamingInternalError extends IcNamingError {}` | ||
class IcNamingCanisterError extends IcNamingError { | ||
constructor(rawResult) { | ||
var _a; | ||
const result = rawResult; | ||
super(`IcNamingCanisterError: ${((_a = result === null || result === void 0 ? void 0 : result.Err) === null || _a === void 0 ? void 0 : _a.message) || "unknown"}`); | ||
this.theIcNamingCanisterErrorResult = rawResult; | ||
} | ||
} | ||
const IC_PUBLIC_HOST = "https://ic0.app"; | ||
const IC_LOCAL_HOST = "http://127.0.0.1:8000"; | ||
const MAINNET_CANISTER_ID_GROUP = { | ||
registrar: "cymrc-fqaaa-aaaam-aacaa-cai", | ||
registry: "c7nxw-iiaaa-aaaam-aacaq-cai", | ||
resolver: "cwo4k-6aaaa-aaaam-aacba-cai", | ||
favorites: "crp26-tyaaa-aaaam-aacbq-cai", | ||
}; | ||
const TICP_CANISTER_ID_GROUP = { | ||
registrar: "onof3-pyaaa-aaaal-qac6a-cai", | ||
registry: "cxnwn-diaaa-aaaag-aabaq-cai", | ||
resolver: "okpdp-caaaa-aaaal-qac6q-cai", | ||
favorites: "oyjuw-oqaaa-aaaal-qac5q-cai", | ||
}; | ||
const idlFactory$3 = ({ IDL }) => { | ||
@@ -356,20 +387,5 @@ const ErrorInfo = IDL.Record({ 'code' : IDL.Nat32, 'message' : IDL.Text }); | ||
const IC_PUBLIC_HOST = "https://ic0.app"; | ||
const IC_LOCAL_HOST = "http://127.0.0.1:8000"; | ||
const MAINNET_CANISTER_ID_GROUP = { | ||
registrar: "cymrc-fqaaa-aaaam-aacaa-cai", | ||
registry: "c7nxw-iiaaa-aaaam-aacaq-cai", | ||
resolver: "cwo4k-6aaaa-aaaam-aacba-cai", | ||
favorites: "crp26-tyaaa-aaaam-aacbq-cai", | ||
}; | ||
const TICP_CANISTER_ID_GROUP = { | ||
registrar: "onof3-pyaaa-aaaal-qac6a-cai", | ||
registry: "cxnwn-diaaa-aaaag-aabaq-cai", | ||
resolver: "okpdp-caaaa-aaaal-qac6q-cai", | ||
favorites: "oyjuw-oqaaa-aaaal-qac5q-cai", | ||
}; | ||
class IcNamingClientBase { | ||
constructor(options) { | ||
this._options = options; | ||
this.options = options; | ||
this._httpAgent = this._initHttpAgent(); | ||
@@ -386,6 +402,6 @@ this._init_actors_before(); | ||
_initHttpAgent() { | ||
return new agent.HttpAgent(Object.assign({ host: this._options.mode === "local" ? IC_LOCAL_HOST : IC_PUBLIC_HOST }, this._options.httpAgentOptions)); | ||
return new agent.HttpAgent(Object.assign({ host: this.options.mode === "local" ? IC_LOCAL_HOST : IC_PUBLIC_HOST }, this.options.httpAgentOptions)); | ||
} | ||
_init_actors_before() { | ||
if (this._options.mode === "local") { | ||
if (this.options.mode === "local") { | ||
this._httpAgent.fetchRootKey().catch((err) => { | ||
@@ -404,9 +420,2 @@ console.warn("Unable to fetch root key. Check to ensure that your local replica is running"); | ||
} | ||
dispatchNameRecordsCache(fn) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this._options.nameRecordsCacheStore) { | ||
yield fn(this._options.nameRecordsCacheStore); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -430,4 +439,16 @@ const toDidModuleType = (module) => { | ||
constructor(options) { | ||
var _a, _b; | ||
super(options); | ||
this.enableTTL = (_a = options.enableTTL) !== null && _a !== void 0 ? _a : false; | ||
this.nameRecordsCacheStore = this.enableTTL | ||
? (_b = options.nameRecordsCacheStore) !== null && _b !== void 0 ? _b : new InMemoryNameRecordsCacheStore() | ||
: undefined; | ||
} | ||
dispatchNameRecordsCache(fn) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.enableTTL && this.nameRecordsCacheStore) { | ||
yield fn(this.nameRecordsCacheStore); | ||
} | ||
}); | ||
} | ||
/* Registrar */ | ||
@@ -563,2 +584,3 @@ isAvailableNaming(naming) { | ||
exports.IcNamingError = IcNamingError; | ||
exports.InMemoryNameRecordsCacheStore = InMemoryNameRecordsCacheStore; | ||
//# sourceMappingURL=index-cjs.js.map |
import { HttpAgent, Actor } from '@dfinity/agent'; | ||
class IcNamingError extends Error { | ||
} | ||
// More error type eg: `export class IcNamingInternalError extends IcNamingError {}` | ||
class IcNamingCanisterError extends IcNamingError { | ||
constructor(rawResult) { | ||
var _a; | ||
const result = rawResult; | ||
super(`IcNamingCanisterError: ${((_a = result === null || result === void 0 ? void 0 : result.Err) === null || _a === void 0 ? void 0 : _a.message) || "unknown"}`); | ||
this.theIcNamingCanisterErrorResult = rawResult; | ||
} | ||
} | ||
/*! ***************************************************************************** | ||
@@ -40,2 +28,45 @@ Copyright (c) Microsoft Corporation. | ||
class InMemoryNameRecordsCacheStore { | ||
constructor() { | ||
this.map = {}; | ||
} | ||
getRecordsByName(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.map[name]; | ||
}); | ||
} | ||
setRecordsByName(name, value) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.map[name] = value; | ||
}); | ||
} | ||
} | ||
class IcNamingError extends Error { | ||
} | ||
// More error type eg: `export class IcNamingInternalError extends IcNamingError {}` | ||
class IcNamingCanisterError extends IcNamingError { | ||
constructor(rawResult) { | ||
var _a; | ||
const result = rawResult; | ||
super(`IcNamingCanisterError: ${((_a = result === null || result === void 0 ? void 0 : result.Err) === null || _a === void 0 ? void 0 : _a.message) || "unknown"}`); | ||
this.theIcNamingCanisterErrorResult = rawResult; | ||
} | ||
} | ||
const IC_PUBLIC_HOST = "https://ic0.app"; | ||
const IC_LOCAL_HOST = "http://127.0.0.1:8000"; | ||
const MAINNET_CANISTER_ID_GROUP = { | ||
registrar: "cymrc-fqaaa-aaaam-aacaa-cai", | ||
registry: "c7nxw-iiaaa-aaaam-aacaq-cai", | ||
resolver: "cwo4k-6aaaa-aaaam-aacba-cai", | ||
favorites: "crp26-tyaaa-aaaam-aacbq-cai", | ||
}; | ||
const TICP_CANISTER_ID_GROUP = { | ||
registrar: "onof3-pyaaa-aaaal-qac6a-cai", | ||
registry: "cxnwn-diaaa-aaaag-aabaq-cai", | ||
resolver: "okpdp-caaaa-aaaal-qac6q-cai", | ||
favorites: "oyjuw-oqaaa-aaaal-qac5q-cai", | ||
}; | ||
const idlFactory$3 = ({ IDL }) => { | ||
@@ -351,20 +382,5 @@ const ErrorInfo = IDL.Record({ 'code' : IDL.Nat32, 'message' : IDL.Text }); | ||
const IC_PUBLIC_HOST = "https://ic0.app"; | ||
const IC_LOCAL_HOST = "http://127.0.0.1:8000"; | ||
const MAINNET_CANISTER_ID_GROUP = { | ||
registrar: "cymrc-fqaaa-aaaam-aacaa-cai", | ||
registry: "c7nxw-iiaaa-aaaam-aacaq-cai", | ||
resolver: "cwo4k-6aaaa-aaaam-aacba-cai", | ||
favorites: "crp26-tyaaa-aaaam-aacbq-cai", | ||
}; | ||
const TICP_CANISTER_ID_GROUP = { | ||
registrar: "onof3-pyaaa-aaaal-qac6a-cai", | ||
registry: "cxnwn-diaaa-aaaag-aabaq-cai", | ||
resolver: "okpdp-caaaa-aaaal-qac6q-cai", | ||
favorites: "oyjuw-oqaaa-aaaal-qac5q-cai", | ||
}; | ||
class IcNamingClientBase { | ||
constructor(options) { | ||
this._options = options; | ||
this.options = options; | ||
this._httpAgent = this._initHttpAgent(); | ||
@@ -381,6 +397,6 @@ this._init_actors_before(); | ||
_initHttpAgent() { | ||
return new HttpAgent(Object.assign({ host: this._options.mode === "local" ? IC_LOCAL_HOST : IC_PUBLIC_HOST }, this._options.httpAgentOptions)); | ||
return new HttpAgent(Object.assign({ host: this.options.mode === "local" ? IC_LOCAL_HOST : IC_PUBLIC_HOST }, this.options.httpAgentOptions)); | ||
} | ||
_init_actors_before() { | ||
if (this._options.mode === "local") { | ||
if (this.options.mode === "local") { | ||
this._httpAgent.fetchRootKey().catch((err) => { | ||
@@ -399,9 +415,2 @@ console.warn("Unable to fetch root key. Check to ensure that your local replica is running"); | ||
} | ||
dispatchNameRecordsCache(fn) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this._options.nameRecordsCacheStore) { | ||
yield fn(this._options.nameRecordsCacheStore); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -425,4 +434,16 @@ const toDidModuleType = (module) => { | ||
constructor(options) { | ||
var _a, _b; | ||
super(options); | ||
this.enableTTL = (_a = options.enableTTL) !== null && _a !== void 0 ? _a : false; | ||
this.nameRecordsCacheStore = this.enableTTL | ||
? (_b = options.nameRecordsCacheStore) !== null && _b !== void 0 ? _b : new InMemoryNameRecordsCacheStore() | ||
: undefined; | ||
} | ||
dispatchNameRecordsCache(fn) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.enableTTL && this.nameRecordsCacheStore) { | ||
yield fn(this.nameRecordsCacheStore); | ||
} | ||
}); | ||
} | ||
/* Registrar */ | ||
@@ -555,3 +576,3 @@ isAvailableNaming(naming) { | ||
export { IcNamingCanisterError, IcNamingClient, IcNamingError }; | ||
export { IcNamingCanisterError, IcNamingClient, IcNamingError, InMemoryNameRecordsCacheStore }; | ||
//# sourceMappingURL=index-esm.js.map |
@@ -16,2 +16,7 @@ import { Principal } from '@dfinity/principal'; | ||
} | ||
declare class InMemoryNameRecordsCacheStore { | ||
map: Record<string, NameRecordsValue>; | ||
getRecordsByName(name: string): Promise<NameRecordsValue>; | ||
setRecordsByName(name: string, value: NameRecordsValue): Promise<void>; | ||
} | ||
@@ -210,2 +215,10 @@ declare class IcNamingError extends Error { | ||
interface IcNamingClientInitOptions { | ||
net: "MAINNET" | "TICP"; | ||
mode: "production" | "local"; | ||
httpAgentOptions?: HttpAgentOptions; | ||
enableTTL?: boolean; | ||
nameRecordsCacheStore?: NameRecordsCacheStore; | ||
} | ||
interface ErrorInfo$1 { 'code' : number, 'message' : string } | ||
@@ -236,11 +249,4 @@ type Result$1 = { 'Ok' : boolean } | | ||
interface IcNamingClientInitOptions { | ||
net: "MAINNET" | "TICP"; | ||
mode: "production" | "local"; | ||
httpAgentOptions?: HttpAgentOptions; | ||
nameRecordsCacheStore?: NameRecordsCacheStore; | ||
} | ||
declare class IcNamingClientBase { | ||
private _options; | ||
private _httpAgent; | ||
protected options: IcNamingClientInitOptions; | ||
protected favorites: ActorSubclass<_SERVICE$1>; | ||
@@ -250,2 +256,3 @@ protected registrar: ActorSubclass<_SERVICE$2>; | ||
protected resolver: ActorSubclass<_SERVICE>; | ||
private _httpAgent; | ||
constructor(options: IcNamingClientInitOptions); | ||
@@ -255,7 +262,9 @@ private _initHttpAgent; | ||
private _createActor; | ||
dispatchNameRecordsCache(fn: (store: NameRecordsCacheStore) => Promise<void>): Promise<void>; | ||
} | ||
declare class IcNamingClient extends IcNamingClientBase { | ||
private enableTTL; | ||
private nameRecordsCacheStore?; | ||
constructor(options: IcNamingClientInitOptions); | ||
private dispatchNameRecordsCache; | ||
isAvailableNaming(naming: string): Promise<boolean>; | ||
@@ -281,2 +290,2 @@ getExpiredTimeOfName(name: string): Promise<bigint>; | ||
export { IcNamingCanisterError, IcNamingClient, IcNamingError, NameRecordsCacheStore, NameRecordsValue }; | ||
export { IcNamingCanisterError, IcNamingClient, IcNamingError, InMemoryNameRecordsCacheStore, NameRecordsCacheStore, NameRecordsValue }; |
{ | ||
"name": "@ic-naming/client", | ||
"version": "0.3.0-1", | ||
"version": "0.3.0-2", | ||
"main": "dist/index-cjs.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index-esm.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
173483
1386