@stardust-collective/dag4-core
Advanced tools
Comparing version 1.1.1 to 1.1.2-beta.2
@@ -6,4 +6,4 @@ "use strict"; | ||
class RestApi { | ||
config = new rest_config_1.RestConfig(); | ||
constructor(baseUrl) { | ||
this.config = new rest_config_1.RestConfig(); | ||
this.config.baseUrl(baseUrl); | ||
@@ -17,11 +17,4 @@ } | ||
const client = this.config.protocolClient(); | ||
return client.invoke({ | ||
authToken: this.config.authToken(), | ||
url, | ||
body: data, | ||
method, | ||
queryParams, | ||
errorHook: this.config.errorHook(), | ||
...options | ||
}); | ||
return client.invoke(Object.assign({ authToken: this.config.authToken(), url, body: data, method, | ||
queryParams, errorHook: this.config.errorHook() }, options)); | ||
} | ||
@@ -55,18 +48,7 @@ configure() { | ||
class RestApiOptions { | ||
baseUrl; | ||
headers; | ||
noAuthHeader; | ||
transformResponse; | ||
retry; | ||
} | ||
exports.RestApiOptions = RestApiOptions; | ||
class RestApiOptionsRequest extends RestApiOptions { | ||
errorHook; | ||
queryParams; | ||
authToken; | ||
method; | ||
body; | ||
url; | ||
} | ||
exports.RestApiOptionsRequest = RestApiOptionsRequest; | ||
//# sourceMappingURL=rest.api.js.map |
@@ -6,6 +6,2 @@ "use strict"; | ||
class RestConfig { | ||
serviceBaseUrl; | ||
serviceAuthToken; | ||
serviceProtocolClient; | ||
errorHookCallback; | ||
baseUrl(val) { | ||
@@ -12,0 +8,0 @@ if (val === undefined) { |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FetchRestService = void 0; | ||
const defaultFetch = typeof window !== 'undefined' ? window.fetch.bind(window) : undefined; | ||
class FetchRestService { | ||
httpClient; | ||
constructor(httpClient = defaultFetch) { | ||
this.httpClient = httpClient; | ||
constructor(httpClient) { | ||
const defaultFetch = (typeof window !== 'undefined' && window.hasOwnProperty('fetch')) ? window.fetch.bind(window) : undefined; | ||
this.httpClient = httpClient || defaultFetch; | ||
} | ||
@@ -51,5 +59,5 @@ invoke(options) { | ||
this.httpClient(options.url, options) | ||
.then(async (res) => { | ||
.then((res) => __awaiter(this, void 0, void 0, function* () { | ||
if (res.status !== 200) { | ||
const text = await res.text(); | ||
const text = yield res.text(); | ||
// let error = new Error(text); | ||
@@ -62,3 +70,3 @@ // | ||
return res.text(); | ||
}) | ||
})) | ||
.then(body => { | ||
@@ -68,3 +76,3 @@ try { | ||
} | ||
catch { } | ||
catch (_a) { } | ||
if (options.transformResponse) { | ||
@@ -71,0 +79,0 @@ resolve(options.transformResponse(body)); |
@@ -5,3 +5,5 @@ "use strict"; | ||
class MemoryStorageClient { | ||
memory = {}; | ||
constructor() { | ||
this.memory = {}; | ||
} | ||
setItem(key, value) { | ||
@@ -8,0 +10,0 @@ this.memory[key] = value; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StateStorageDb = void 0; | ||
const defaultStorage = typeof window !== 'undefined' ? window.localStorage : undefined; | ||
class StateStorageDb { | ||
storageClient; | ||
keyPrefix = 'dag4-'; | ||
constructor(storageClient = defaultStorage) { | ||
this.storageClient = storageClient; | ||
constructor(storageClient) { | ||
this.keyPrefix = 'dag4-'; | ||
this.defaultStorage = (typeof window !== 'undefined' && window.hasOwnProperty('localStorage')) ? window.localStorage : undefined; | ||
this.storageClient = storageClient || this.defaultStorage; | ||
} | ||
setClient(client) { | ||
this.storageClient = client || defaultStorage; | ||
this.storageClient = client || this.defaultStorage; | ||
} | ||
@@ -24,9 +32,13 @@ setPrefix(prefix) { | ||
set(key, value) { | ||
this.storageClient.setItem(this.keyPrefix + key, JSON.stringify(value)); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.storageClient.setItem(this.keyPrefix + key, JSON.stringify(value)); | ||
}); | ||
} | ||
get(key) { | ||
const value = this.storageClient.getItem(this.keyPrefix + key); | ||
if (value) { | ||
return JSON.parse(value); | ||
} | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const value = yield this.storageClient.getItem(this.keyPrefix + key); | ||
if (value) { | ||
return JSON.parse(value); | ||
} | ||
}); | ||
} | ||
@@ -33,0 +45,0 @@ delete(key) { |
@@ -8,7 +8,9 @@ "use strict"; | ||
class CrossPlatformDi { | ||
//====================== | ||
// = HTTP Client = | ||
//====================== | ||
httpClient; | ||
httpClientBaseUrl = ''; | ||
constructor() { | ||
this.httpClientBaseUrl = ''; | ||
//====================== | ||
//= State Storage = | ||
//====================== | ||
this.stateStorageDb = new state_storage_db_1.StateStorageDb(new memory_storage_client_1.MemoryStorageClient()); | ||
} | ||
// Register the platform implementation for http service requests | ||
@@ -25,6 +27,2 @@ registerHttpClient(client, baseUrl) { | ||
} | ||
//====================== | ||
//= State Storage = | ||
//====================== | ||
stateStorageDb = new state_storage_db_1.StateStorageDb(new memory_storage_client_1.MemoryStorageClient()); | ||
useBrowserLocalStorage() { | ||
@@ -31,0 +29,0 @@ this.stateStorageDb.setClient(null); |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.arrayUtils = exports.ArrayUtils = void 0; | ||
class ArrayUtils { | ||
FLAGS = { | ||
CASE_INSENSITIVE: { caseInsensitive: true }, | ||
NUMERIC: { 'numeric': true } | ||
}; | ||
constructor() { | ||
this.FLAGS = { | ||
CASE_INSENSITIVE: { caseInsensitive: true }, | ||
NUMERIC: { 'numeric': true } | ||
}; | ||
} | ||
sortBy(arr, fieldName, flags, sortProcessCall) { | ||
@@ -63,19 +74,23 @@ if (!flags) { | ||
} | ||
async asyncCallEach(array, callback) { | ||
if (!array || array.length === 0) { | ||
return; | ||
} | ||
const promises = array.map(async (item, index) => callback(item, index)); | ||
return await Promise.all(promises); | ||
asyncCallEach(array, callback) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!array || array.length === 0) { | ||
return; | ||
} | ||
const promises = array.map((item, index) => __awaiter(this, void 0, void 0, function* () { return callback(item, index); })); | ||
return yield Promise.all(promises); | ||
}); | ||
} | ||
async syncCallEach(array, callback, options = { stopProcessing: false }) { | ||
if (!array || array.length === 0) { | ||
return; | ||
} | ||
for (let index = 0; index < array.length; index++) { | ||
await callback(array[index], index, options); | ||
if (options.stopProcessing) { | ||
break; | ||
syncCallEach(array, callback, options = { stopProcessing: false }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!array || array.length === 0) { | ||
return; | ||
} | ||
} | ||
for (let index = 0; index < array.length; index++) { | ||
yield callback(array[index], index, options); | ||
if (options.stopProcessing) { | ||
break; | ||
} | ||
} | ||
}); | ||
} | ||
@@ -95,5 +110,7 @@ promiseAny(iterable) { | ||
class Flags { | ||
caseInsensitive = false; | ||
numeric = false; | ||
constructor() { | ||
this.caseInsensitive = false; | ||
this.numeric = false; | ||
} | ||
} | ||
//# sourceMappingURL=array-utils.js.map |
@@ -10,6 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
const defaultFetch = typeof window !== 'undefined' ? window.fetch.bind(window) : undefined; | ||
export class FetchRestService { | ||
constructor(httpClient = defaultFetch) { | ||
this.httpClient = httpClient; | ||
constructor(httpClient) { | ||
const defaultFetch = (typeof window !== 'undefined' && window.hasOwnProperty('fetch')) ? window.fetch.bind(window) : undefined; | ||
this.httpClient = httpClient || defaultFetch; | ||
} | ||
@@ -16,0 +16,0 @@ invoke(options) { |
@@ -1,9 +0,18 @@ | ||
const defaultStorage = typeof window !== 'undefined' ? window.localStorage : undefined; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
export class StateStorageDb { | ||
constructor(storageClient = defaultStorage) { | ||
this.storageClient = storageClient; | ||
constructor(storageClient) { | ||
this.keyPrefix = 'dag4-'; | ||
this.defaultStorage = (typeof window !== 'undefined' && window.hasOwnProperty('localStorage')) ? window.localStorage : undefined; | ||
this.storageClient = storageClient || this.defaultStorage; | ||
} | ||
setClient(client) { | ||
this.storageClient = client || defaultStorage; | ||
this.storageClient = client || this.defaultStorage; | ||
} | ||
@@ -20,9 +29,13 @@ setPrefix(prefix) { | ||
set(key, value) { | ||
this.storageClient.setItem(this.keyPrefix + key, JSON.stringify(value)); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.storageClient.setItem(this.keyPrefix + key, JSON.stringify(value)); | ||
}); | ||
} | ||
get(key) { | ||
const value = this.storageClient.getItem(this.keyPrefix + key); | ||
if (value) { | ||
return JSON.parse(value); | ||
} | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const value = yield this.storageClient.getItem(this.keyPrefix + key); | ||
if (value) { | ||
return JSON.parse(value); | ||
} | ||
}); | ||
} | ||
@@ -29,0 +42,0 @@ delete(key) { |
export declare class FetchRestService { | ||
private httpClient; | ||
constructor(httpClient?: any); | ||
constructor(httpClient: any); | ||
invoke(options: RestApiOptionsRequest): Promise<any>; | ||
@@ -5,0 +5,0 @@ buildRequest(options: RestApiOptionsRequest): { |
export declare class StateStorageDb { | ||
private keyPrefix; | ||
private storageClient; | ||
private keyPrefix; | ||
constructor(storageClient?: IStateStorageClient); | ||
private defaultStorage; | ||
constructor(storageClient: IStateStorageClient); | ||
setClient(client: IStateStorageClient): void; | ||
setPrefix(prefix: string): void; | ||
set(key: string, value: any): void; | ||
get(key: string): any; | ||
set(key: string, value: any): Promise<void>; | ||
get(key: string): Promise<any>; | ||
delete(key: string): void; | ||
@@ -10,0 +11,0 @@ } |
{ | ||
"name": "@stardust-collective/dag4-core", | ||
"version": "1.1.1", | ||
"version": "1.1.2-beta.2", | ||
"description": "Constellation HyperGraph JavaScript API", | ||
@@ -5,0 +5,0 @@ "author": "Frank Fox", |
declare let window; | ||
const defaultFetch = typeof window !== 'undefined' ? window.fetch.bind(window) : undefined; | ||
export class FetchRestService { | ||
constructor (private httpClient = defaultFetch) {} | ||
private httpClient: any; | ||
constructor (httpClient: any) { | ||
const defaultFetch = (typeof window !== 'undefined' && window.hasOwnProperty('fetch')) ? window.fetch.bind(window) : undefined; | ||
this.httpClient = httpClient || defaultFetch; | ||
} | ||
invoke(options: RestApiOptionsRequest): Promise<any> { | ||
@@ -9,0 +13,0 @@ return this.makeServiceRequest(this.buildRequest(options)); |
declare let window; | ||
const defaultStorage = typeof window !== 'undefined' ? window.localStorage : undefined; | ||
@@ -7,7 +6,12 @@ export class StateStorageDb { | ||
private keyPrefix = 'dag4-'; | ||
private storageClient: IStateStorageClient; | ||
private defaultStorage: any; | ||
constructor (private storageClient: IStateStorageClient = defaultStorage) {} | ||
constructor (storageClient: IStateStorageClient) { | ||
this.defaultStorage = (typeof window !== 'undefined' && window.hasOwnProperty('localStorage')) ? window.localStorage : undefined; | ||
this.storageClient = storageClient || this.defaultStorage; | ||
} | ||
setClient (client: IStateStorageClient) { | ||
this.storageClient = client || defaultStorage; | ||
this.storageClient = client || this.defaultStorage; | ||
} | ||
@@ -25,8 +29,8 @@ | ||
set (key: string, value: any) { | ||
this.storageClient.setItem(this.keyPrefix + key, JSON.stringify(value)); | ||
async set (key: string, value: any) { | ||
await this.storageClient.setItem(this.keyPrefix + key, JSON.stringify(value)); | ||
} | ||
get (key: string): any { | ||
const value = this.storageClient.getItem(this.keyPrefix + key); | ||
async get (key: string) { | ||
const value = await this.storageClient.getItem(this.keyPrefix + key); | ||
if (value) { | ||
@@ -33,0 +37,0 @@ return JSON.parse(value); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81614
1539
1