@common-stack/client-core
Advanced tools
Comparing version 4.0.1-alpha.0 to 4.0.1-alpha.5
@@ -1,3 +0,3 @@ | ||
import { IdGetterObj } from '@apollo/client/core/index.js'; | ||
import { ErrorLink } from '@apollo/client/link/error/index.js'; | ||
import { IdGetterObj, Resolvers } from '@apollo/client/core'; | ||
import { ErrorLink } from '@apollo/client/link/error'; | ||
import { ReducersMapObject } from 'redux'; | ||
@@ -45,10 +45,5 @@ import { interfaces } from 'inversify'; | ||
private _container; | ||
/** | ||
* Constructs Client feature module representation, that folds all the feature modules | ||
* into a single module represented by this instance. | ||
* @param feature | ||
* @param features | ||
*/ | ||
private _apolloResolvers; | ||
constructor(feature?: IModuleShape, ...features: IModuleShape[]); | ||
get envalidConfigs(): any; | ||
getApolloResolvers(resolverContex: any): Resolvers; | ||
private get container(); | ||
@@ -62,3 +57,3 @@ get epics(): any; | ||
createContainers(options: any): interfaces.Container; | ||
createService(options: any, updateOptions: any): any; | ||
createService(options: any, updateOptions: any, overrideContainer: any): any; | ||
getStateParams(args?: { | ||
@@ -65,0 +60,0 @@ resolverContex?: any; |
@@ -1,71 +0,47 @@ | ||
import*as React from'react';import {merge,without,union,map,castArray}from'lodash-es';import {Container}from'inversify';/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import*as React from'react';import {merge,without,union,castArray}from'lodash-es';import {Container}from'inversify';import {consolidatedResolvers}from'../utils/resolversUtils.js';/* eslint-disable no-underscore-dangle */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable no-nested-ternary */ | ||
/* eslint-disable no-use-before-define */ | ||
const combine = (features, extractor) => without(union(...map(features, (res) => castArray(extractor(res)))), undefined); | ||
const combine = (features, extractor) => without(union(...features.map((res) => castArray(extractor(res)))), undefined); | ||
const featureCatalog = {}; | ||
class AbstractFeature { | ||
/** | ||
* Constructs Client feature module representation, that folds all the feature modules | ||
* into a single module represented by this instance. | ||
* @param feature | ||
* @param features | ||
*/ | ||
constructor(feature, | ||
// tslint:disable:trailing-comma | ||
...features) { | ||
// Connectivity | ||
this.link = combine(arguments, (arg) => arg.link); | ||
this.errorLink = combine(arguments, (arg) => arg.errorLink); | ||
this.createFetch = combine(arguments, (arg) => arg.createFetch) | ||
constructor(feature, ...features) { | ||
const args = [feature, ...features]; | ||
this.link = combine(args, (arg) => arg.link); | ||
this.errorLink = combine(args, (arg) => arg.errorLink); | ||
this.createFetch = combine(args, (arg) => arg.createFetch) | ||
.slice(-1) | ||
.pop(); | ||
this.connectionParam = combine(arguments, (arg) => arg.connectionParam); | ||
// State management | ||
this.reducer = combine(arguments, (arg) => arg.reducer); | ||
// Client side schema for apollo-link-state | ||
this.clientStateParams = combine(arguments, (arg) => arg.clientStateParams); | ||
// Envalid config | ||
this.envalidConfig = combine(arguments, (arg) => arg.envalidConfig); | ||
// Epic actions | ||
this.epic = combine(arguments, (arg) => arg.epic); | ||
this.sidebarSegments = combine(arguments, (arg) => arg.sidebarSegments); | ||
this.leftMainPanelItems = combine(arguments, (arg) => arg.leftMainPanelItems); | ||
this.middleMainPanelItems = combine(arguments, (arg) => arg.middleMainPanelItems); | ||
this.middleMainPanelItemsProps = combine(arguments, (arg) => arg.middleMainPanelItemsProps); | ||
this.leftFooterItems = combine(arguments, (arg) => arg.leftFooterItems); | ||
this.rightFooterItems = combine(arguments, (arg) => arg.rightFooterItems); | ||
this.middleLowerPanelItems = combine(arguments, (arg) => arg.middleLowerPanelItems); | ||
this.dataIdFromObject = combine(arguments, (arg) => arg.dataIdFromObject); | ||
this.navItem = combine(arguments, (arg) => arg.navItem); | ||
this.navItemRight = combine(arguments, (arg) => arg.navItemRight); | ||
// UI provider-components | ||
this.rootComponentFactory = combine(arguments, (arg) => arg.rootComponentFactory); | ||
this.dataRootComponent = combine(arguments, (arg) => arg.dataRootComponent); | ||
// UI provider-components | ||
this.languagesFuncs = combine(arguments, (arg) => arg.languagesFuncs); | ||
// container | ||
this.createContainerFunc = combine(arguments, (arg) => arg.createContainerFunc); | ||
// services | ||
this.createServiceFunc = combine(arguments, (arg) => arg.createServiceFunc); | ||
// TODO: Use React Helmet for those. Low level DOM manipulation | ||
this.stylesInsert = combine(arguments, (arg) => arg.stylesInsert); | ||
this.scriptsInsert = combine(arguments, (arg) => arg.scriptsInsert); | ||
this.reduxPersistTransforms = combine(arguments, (arg) => arg.reduxPersistTransforms); | ||
// Shared modules data | ||
this.data = combine([{}].concat(Array.from(arguments)), (arg) => arg.data).reduce((acc, el) => [{ ...acc[0], ...el }], [{}]); | ||
this.connectionParam = combine(args, (arg) => arg.connectionParam); | ||
this.reducer = combine(args, (arg) => arg.reducer); | ||
this.clientStateParams = combine(args, (arg) => arg.clientStateParams); | ||
this.epic = combine(args, (arg) => arg.epic); | ||
this.sidebarSegments = combine(args, (arg) => arg.sidebarSegments); | ||
this.leftMainPanelItems = combine(args, (arg) => arg.leftMainPanelItems); | ||
this.middleMainPanelItems = combine(args, (arg) => arg.middleMainPanelItems); | ||
this.middleMainPanelItemsProps = combine(args, (arg) => arg.middleMainPanelItemsProps); | ||
this.leftFooterItems = combine(args, (arg) => arg.leftFooterItems); | ||
this.rightFooterItems = combine(args, (arg) => arg.rightFooterItems); | ||
this.middleLowerPanelItems = combine(args, (arg) => arg.middleLowerPanelItems); | ||
this.dataIdFromObject = combine(args, (arg) => arg.dataIdFromObject); | ||
this.navItem = combine(args, (arg) => arg.navItem); | ||
this.navItemRight = combine(args, (arg) => arg.navItemRight); | ||
this.rootComponentFactory = combine(args, (arg) => arg.rootComponentFactory); | ||
this.dataRootComponent = combine(args, (arg) => arg.dataRootComponent); | ||
this.languagesFuncs = combine(args, (arg) => arg.languagesFuncs); | ||
this.createContainerFunc = combine(args, (arg) => arg.createContainerFunc); | ||
this.createServiceFunc = combine(args, (arg) => arg.createServiceFunc); | ||
this.stylesInsert = combine(args, (arg) => arg.stylesInsert); | ||
this.scriptsInsert = combine(args, (arg) => arg.scriptsInsert); | ||
this.reduxPersistTransforms = combine(args, (arg) => arg.reduxPersistTransforms); | ||
this.data = combine([{}].concat(args), (arg) => arg.data).reduce((acc, el) => [{ ...acc[0], ...el }], [{}]); | ||
} | ||
get envalidConfigs() { | ||
return this.envalidConfig.reduce((prev, config) => { | ||
for (const key in config) { | ||
if (prev[key]) { | ||
if (prev[key].required) { | ||
config[key].required = prev[key].required; | ||
} | ||
if (prev[key].devRequired) { | ||
config[key].devRequired = prev[key].devRequired; | ||
} | ||
} | ||
return { ...prev, ...config }; | ||
} | ||
}, {}); | ||
getApolloResolvers(resolverContex) { | ||
// Ensure _apolloResolvers is initialized | ||
if (!this._apolloResolvers) { | ||
throw new Error('Resolvers have not been initialized.'); | ||
} | ||
// Loop through each resolver function and process it with consolidatedResolvers | ||
const processedResolvers = Object.keys(this._apolloResolvers).reduce((acc, key) => merge(acc, consolidatedResolvers(this._apolloResolvers[key], resolverContex)), {}); | ||
return processedResolvers; | ||
} | ||
@@ -88,7 +64,6 @@ get container() { | ||
createContainers(options) { | ||
// only create once | ||
if (this.isContainerLoaded) { | ||
return this.container; | ||
} | ||
this.createContainerFunc.map((createModule) => { | ||
this.createContainerFunc.forEach((createModule) => { | ||
this.container.load(createModule(options)); | ||
@@ -99,4 +74,3 @@ }); | ||
} | ||
createService(options, updateOptions) { | ||
// only create once | ||
createService(options, updateOptions, overrideContainer) { | ||
if (this.services) { | ||
@@ -109,6 +83,7 @@ return this.services; | ||
} | ||
this.services = merge({}, ...this.createServiceFunc.map((serviceFunc) => serviceFunc(this.container))); | ||
this.services = merge({}, ...this.createServiceFunc.map((serviceFunc) => serviceFunc(overrideContainer || this.container))); | ||
return this.services; | ||
} | ||
catch (err) { | ||
console.error(err); | ||
throw err; | ||
@@ -120,3 +95,3 @@ } | ||
const { requestResponsePair } = args; | ||
return this.clientStateParams.reduce((acc, curr) => { | ||
const result = this.clientStateParams.reduce((acc, curr) => { | ||
const defs = curr.typeDefs ? (Array.isArray(curr.typeDefs) ? curr.typeDefs : [curr.typeDefs]) : []; | ||
@@ -129,13 +104,10 @@ const preLinksAccumulator = acc.preLinks || []; | ||
const schema = defs | ||
.map((typeDef) => { | ||
if (typeof typeDef === 'string') { | ||
return typeDef; | ||
} | ||
console.warn(`Not supported AST format `, typeDef); | ||
}) | ||
.map((str) => str?.trim()) | ||
.map((typeDef) => (typeof typeDef === 'string' ? typeDef : '')) | ||
.map((str) => str.trim()) | ||
.join('\n'); | ||
const typeDefs = acc.typeDefs ? acc.typeDefs.concat('\n', schema) : schema; | ||
const defaults = curr.defaults ? attemptDefaults.concat(curr.defaults) : attemptDefaults; | ||
const resolvers = merge(acc.resolvers, consoldidatedResolvers(curr.resolvers, args.resolverContex)); | ||
// Merge native resolvers | ||
const nativeResolvers = merge({}, acc.nativeResolvers, curr.resolvers); | ||
const resolvers = merge(acc.resolvers, consolidatedResolvers(curr.resolvers, args.resolverContex)); | ||
const possibleTypes = merge(acc.possibleTypes, curr.possibleTypes); | ||
@@ -148,3 +120,3 @@ const typePolicies = merge(acc.typePolicies, curr.typePolicies); | ||
const connectionParams = curr.connectionParam | ||
? connectionParamsFuncAccumulator.concat(consoldidatedConnection(curr.connectionParam, cn)) | ||
? connectionParamsFuncAccumulator.concat(consolidatedConnection(curr.connectionParam, cn)) | ||
: connectionParamsFuncAccumulator; | ||
@@ -157,2 +129,3 @@ const connectionCallbackFuncs = curr.connectionCallbackFunc | ||
resolvers, | ||
nativeResolvers, | ||
typeDefs, | ||
@@ -167,2 +140,4 @@ possibleTypes, | ||
}, {}); | ||
this._apolloResolvers = result.nativeResolvers; | ||
return result; | ||
} | ||
@@ -198,3 +173,3 @@ get connectionParams() { | ||
}); | ||
return (withProps[key] = React.cloneElement(panelObj[key], mergedProps)); | ||
withProps[key] = React.cloneElement(panelObj[key], mergedProps); | ||
}); | ||
@@ -223,23 +198,7 @@ return withProps; | ||
} | ||
function consoldidatedResolvers(resolvers, context) { | ||
let finalResolvers; | ||
if (Array.isArray(resolvers)) { | ||
const resolverObject = resolvers.map((resolver) => typeof resolver === 'function' ? resolver(context) : resolver); | ||
finalResolvers = merge({}, ...resolverObject); | ||
} | ||
else { | ||
finalResolvers = typeof resolvers === 'function' ? resolvers(context) : resolvers; | ||
} | ||
return finalResolvers; | ||
} | ||
async function consoldidatedConnection(connectionParams, context) { | ||
let finalConnectionParams; | ||
async function consolidatedConnection(connectionParams, context) { | ||
if (Array.isArray(connectionParams)) { | ||
throw new Error('Array is not supported for ConnectionParams'); | ||
} | ||
else { | ||
finalConnectionParams = | ||
typeof connectionParams === 'function' ? await connectionParams(context) : connectionParams; | ||
} | ||
return finalConnectionParams; | ||
return typeof connectionParams === 'function' ? await connectionParams(context) : connectionParams; | ||
}export{AbstractFeature,featureCatalog};//# sourceMappingURL=abstract-connector.js.map |
import { ApolloLink, IdGetterObj, Operation, PossibleTypesMap, Resolvers, TypePolicies } from '@apollo/client/core/index.js'; | ||
import { interfaces } from 'inversify'; | ||
import { Container, interfaces } from 'inversify'; | ||
import { Cache } from '@apollo/client/cache/index.js'; | ||
@@ -51,2 +51,3 @@ import { ReducersMapObject } from 'redux'; | ||
resolvers?: Resolvers; | ||
nativeResolvers?: Resolvers; | ||
defaults: IClientStateDefault[]; | ||
@@ -192,6 +193,2 @@ typeDefs?: string | string[]; | ||
/** | ||
* @returns envalidConfig of all features | ||
*/ | ||
readonly envalidConfigs: any[]; | ||
/** | ||
* @returns Redux-Observable Epics | ||
@@ -237,3 +234,3 @@ */ | ||
createContainers(args: any): any; | ||
createService(options: any, updateOptions: any): any; | ||
createService(options: any, updateOptions?: any, overrideContainer?: Container): any; | ||
/** | ||
@@ -251,2 +248,7 @@ * @param args Provide resolverContext which can be passed to all resolver functions. | ||
/** | ||
* Apollo Resolvers | ||
* @param context | ||
*/ | ||
getApolloResolvers(context: any): any; | ||
/** | ||
* @arguments root React tree root component | ||
@@ -253,0 +255,0 @@ * @arguments req Http Request |
{ | ||
"name": "@common-stack/client-core", | ||
"version": "4.0.1-alpha.0", | ||
"version": "4.0.1-alpha.5", | ||
"description": "common core for higher packages to depend on", | ||
@@ -36,3 +36,3 @@ "license": "ISC", | ||
}, | ||
"gitHead": "d2631ce11c2e00c523f29182bc7817601edc5733" | ||
"gitHead": "b4bebb1d5bef6c408d374da18dac75bc440fd340" | ||
} |
Sorry, the diff of this file is not supported yet
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
32
1
43010
669