-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): fixes circular dependencies
- Loading branch information
Showing
9 changed files
with
112 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { | ||
Tree, | ||
TreeImplementation, | ||
Service, | ||
ServiceImplementation, | ||
Type, | ||
TypeImplementation | ||
} from '~/types'; | ||
import { | ||
isTreeCollection, | ||
isElementService, | ||
isTypeError, | ||
isTypeRequest | ||
} from './element'; | ||
import { emptyCollection } from '~/utils'; | ||
import { traverse } from '../traverse'; | ||
|
||
export function isTreeImplementation( | ||
tree: Tree, | ||
fail?: boolean | ||
): tree is TreeImplementation { | ||
const collection = isTreeCollection(tree) | ||
? tree | ||
: { ...emptyCollection(), scopes: { tree } }; | ||
|
||
let isImplementation: null | boolean = null; | ||
try { | ||
traverse(collection, (element, next) => { | ||
next(); | ||
|
||
if (isElementService(element)) { | ||
const is = isServiceImplementation(element); | ||
if (isImplementation === null) { | ||
isImplementation = is; | ||
} else if (isImplementation !== is) { | ||
throw Error( | ||
`Both service implementations and declarations were found in tree` | ||
); | ||
} | ||
} | ||
}); | ||
} catch (err) { | ||
if (fail) { | ||
throw err; | ||
} else { | ||
isImplementation = false; | ||
} | ||
} | ||
|
||
return isImplementation === null ? true : isImplementation; | ||
} | ||
|
||
export function isServiceImplementation( | ||
service: Service | ||
): service is ServiceImplementation { | ||
return ( | ||
Object.hasOwnProperty.call(service, 'resolve') && | ||
typeof (service as any).resolve === 'function' | ||
); | ||
} | ||
|
||
export function isTypeImplementation(type: Type): type is TypeImplementation { | ||
return ( | ||
isTypeError(type) || | ||
isTypeRequest(type) || | ||
!type.children || | ||
Object.values(type.children).reduce((acc: boolean, service) => { | ||
return acc && isServiceImplementation(service); | ||
}, true) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './element'; | ||
export * from './implementation'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './replace'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { | ||
QueryService, | ||
MutationService, | ||
SubscriptionService, | ||
Element | ||
} from '~/types'; | ||
|
||
export type ReplaceTransformFn< | ||
Q extends QueryService = QueryService, | ||
M extends MutationService = MutationService, | ||
S extends SubscriptionService = SubscriptionService | ||
> = ( | ||
element: Element<Q, M, S>, | ||
next: ReplaceTransformNextFn<Q, M, S>, | ||
data: ReplaceTransformData | ||
) => Element; | ||
|
||
export type ReplaceTransformNextFn< | ||
Q extends QueryService = QueryService, | ||
M extends MutationService = MutationService, | ||
S extends SubscriptionService = SubscriptionService | ||
> = (element?: Element<Q, M, S>) => Element; | ||
|
||
export interface ReplaceTransformData { | ||
path: string[]; | ||
route: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters