Comparing version 0.1.12 to 0.1.13
import { Api } from './Types'; | ||
declare const api: Api; | ||
export default api; | ||
declare const _default: import("../common/Utils").Lock<Api>; | ||
export default _default; |
@@ -12,3 +12,3 @@ "use strict"; | ||
const axios_1 = require("axios"); | ||
const common_1 = require("../common"); | ||
const Utils_1 = require("../common/Utils"); | ||
const system_1 = require("../system"); | ||
@@ -112,3 +112,3 @@ const Consts_1 = require("./Consts"); | ||
} | ||
const api = Object.freeze(common_1.makeCallable(request, { get, delete: del, post, put, search })); | ||
exports.default = api; | ||
const api = Object.freeze(Utils_1.makeCallable(request, { get, delete: del, post, put, search })); | ||
exports.default = system_1.default.sealModule(api); |
import { Auth } from './Types'; | ||
declare const _default: Readonly<Auth>; | ||
declare const _default: import("../common/Utils").Lock<Readonly<Auth>>; | ||
export default _default; |
@@ -65,2 +65,2 @@ "use strict"; | ||
}; | ||
exports.default = Object.freeze(auth); | ||
exports.default = system_1.default.sealModule(Object.freeze(auth)); |
export * from './DataGenerators'; | ||
export * from './Strings'; | ||
export * from './Types'; | ||
export * from './Utils'; |
@@ -9,2 +9,1 @@ "use strict"; | ||
__export(require("./Types")); | ||
__export(require("./Utils")); |
@@ -17,2 +17,4 @@ declare type FunctionType = (...args: any[]) => any; | ||
export declare function proxyWrap<T extends object, W extends Record<string, any> | undefined = T>(target: Record<string, any>, wrapper?: W): [T, T & W]; | ||
export declare type Lock<T> = (suppliedKey: symbol) => T; | ||
export declare function lock<T extends object>(obj: T, key: symbol): Lock<T>; | ||
export {}; |
@@ -42,4 +42,4 @@ "use strict"; | ||
get: intercept(wrapper || {}), | ||
set: () => { | ||
throw new Error('Illegal access to an immutable object.'); | ||
set() { | ||
throw new Error('Illegal access to a protected object.'); | ||
}, | ||
@@ -50,1 +50,18 @@ }); | ||
exports.proxyWrap = proxyWrap; | ||
function lock(obj, key) { | ||
const guard = Object.freeze({ key }); | ||
function unlock(suppliedKey) { | ||
const keyRef = suppliedKey; | ||
if (typeof keyRef === 'symbol' && guard.key === keyRef) { | ||
return obj; | ||
} | ||
throw new Error('Illegal access to a protected object.'); | ||
} | ||
unlock[Symbol.hasInstance] = () => false; | ||
unlock[Symbol.toStringTag] = () => ''; | ||
unlock[Symbol.iterator] = function* () { | ||
yield ''; | ||
}; | ||
return Object.freeze(unlock); | ||
} | ||
exports.lock = lock; |
import { Api } from './api'; | ||
import { Auth } from './auth'; | ||
import { ClientConfig, NexusConfig } from './common'; | ||
import { Module } from './module'; | ||
export { Api, Auth, Module }; | ||
export declare type ConfigSettings = { | ||
@@ -8,6 +10,7 @@ nexus: NexusConfig; | ||
}; | ||
export interface Lib { | ||
export interface BfLib { | ||
api: Api; | ||
auth: Auth; | ||
module: Module; | ||
} | ||
export default function bflib(settings: ConfigSettings): Promise<Lib>; | ||
export default function bflib(settings: ConfigSettings): Promise<BfLib>; |
@@ -22,2 +22,5 @@ "use strict"; | ||
}, | ||
get module() { | ||
return system_1.default.getLibModule(system_1.LibModule.MODULE); | ||
}, | ||
}); | ||
@@ -24,0 +27,0 @@ }); |
{ | ||
"name": "bf-lib", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "the standard client library for block-5 services", |
import { ClientConfig, NexusConfig } from '../common'; | ||
import { Lock } from '../common/Utils'; | ||
import { Nexus as NexusType } from './Nexus'; | ||
@@ -9,3 +10,4 @@ import { LibModule } from './Types'; | ||
interface SystemWrapper { | ||
init: (settings: InitSettings) => void; | ||
init(settings: InitSettings): void; | ||
sealModule<T extends object>(module: T): Lock<T>; | ||
} | ||
@@ -12,0 +14,0 @@ interface SystemInstance { |
@@ -13,6 +13,11 @@ "use strict"; | ||
const Auth_1 = require("../auth/Auth"); | ||
const common_1 = require("../common"); | ||
const Utils_1 = require("../common/Utils"); | ||
const Module_1 = require("../module/Module"); | ||
const Nexus_1 = require("./Nexus"); | ||
const Types_1 = require("./Types"); | ||
let initialized = false; | ||
const seal = Symbol(); | ||
function sealModule(module) { | ||
return Utils_1.lock(module, seal); | ||
} | ||
function init(settings) { | ||
@@ -28,8 +33,9 @@ return __awaiter(this, void 0, void 0, function* () { | ||
if (!module) { | ||
throw new Error(`No instance was found for the ${common_1.toDisplay(type)} Lib Module.`); | ||
throw new Error('An attempt was mad to access an instance for a missing Lib Module.'); | ||
} | ||
return module; | ||
return module(seal); | ||
} | ||
libModuleMap.set(Types_1.LibModule.AUTH, Auth_1.default); | ||
libModuleMap.set(Types_1.LibModule.API, Api_1.default); | ||
libModuleMap.set(Types_1.LibModule.MODULE, Module_1.default); | ||
Object.assign(instance, { getLibModule, nexus }); | ||
@@ -40,3 +46,3 @@ Object.freeze(instance); | ||
} | ||
const [instance, system] = common_1.proxyWrap({}, { init }); | ||
const [instance, system] = Utils_1.proxyWrap({}, { init, sealModule }); | ||
exports.default = system; |
import { EnumLiteralsOf } from 'bf-types'; | ||
export declare type LibModule = EnumLiteralsOf<typeof LibModule>; | ||
export declare const LibModule: Readonly<{ | ||
readonly API: "API"; | ||
readonly AUTH: "AUTH"; | ||
readonly API: symbol; | ||
readonly AUTH: symbol; | ||
readonly MODULE: symbol; | ||
}>; |
@@ -5,4 +5,5 @@ "use strict"; | ||
exports.LibModule = Object.freeze({ | ||
API: 'API', | ||
AUTH: 'AUTH', | ||
API: Symbol('API'), | ||
AUTH: Symbol('AUTH'), | ||
MODULE: Symbol('MODULE'), | ||
}); |
41023
43
947