-
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.
feat(core): implements service errors as arrays; removes references c…
…reate function; adds item create
- Loading branch information
Showing
17 changed files
with
112 additions
and
131 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
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
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,5 +1,6 @@ | ||
export * from './implement'; | ||
export * from './collections'; | ||
export * from './item'; | ||
export * from './schema'; | ||
export * from './scopes'; | ||
export * from './references'; | ||
export * from './reference'; |
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,14 @@ | ||
import { Element, ElementItem } from '~/types'; | ||
|
||
/** | ||
* Returns an *Element* `element` as an `ElementItem` with `name`. | ||
*/ | ||
export function item<N extends string, T extends Element>( | ||
name: N, | ||
element: T | ||
): ElementItem<T, N> { | ||
return { | ||
name, | ||
item: element | ||
}; | ||
} |
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,31 @@ | ||
import { CollectionTree } from '~/types'; | ||
|
||
export function reference<T extends CollectionTree, K extends keyof T['types']>( | ||
collection: T, | ||
name: K | ||
): K; | ||
export function reference<T extends CollectionTree, K extends keyof T['types']>( | ||
collection: T, | ||
name: K[] | ||
): K[]; | ||
|
||
/** | ||
* Returns `name`, as a *string* or a *string array*, while ensuring | ||
* types with `name`s exist on `collection`. | ||
* A helper to be used for type safety when referencing types on service creation. | ||
*/ | ||
export function reference( | ||
collection: CollectionTree, | ||
name: string | string[] | ||
): string | string[] { | ||
const isArray = Array.isArray(name); | ||
const names = isArray ? (name as string[]) : [name as string]; | ||
|
||
for (const name of names) { | ||
if (!Object.hasOwnProperty.call(collection.types, name)) { | ||
throw Error(`Can't reference "${name}" on collection`); | ||
} | ||
} | ||
|
||
return isArray ? names : names[0]; | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.