generated from voxpelli/node-module-template
-
-
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.
Initial addition of UmzeptionContext
- Loading branch information
Showing
13 changed files
with
78 additions
and
20 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 |
---|---|---|
@@ -1,8 +1,15 @@ | ||
export type { | ||
UmzeptionDependency, | ||
UmzeptionLookupOptions, | ||
AnyUmzeptionContext, | ||
DefineUmzeptionContexts, | ||
UmzeptionContext, | ||
} from './lib/advanced-types.d.ts'; | ||
|
||
export { | ||
createUmzeptionContext, | ||
} from './lib/context.js'; | ||
|
||
export { | ||
umzeption, | ||
} from './lib/main.js'; |
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,3 +1,7 @@ | ||
export { | ||
createUmzeptionContext, | ||
} from './lib/context.js'; | ||
|
||
export { | ||
umzeption, | ||
} from './lib/main.js'; |
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,27 +1,58 @@ | ||
import type { PluginDefinition } from 'plugin-importer'; | ||
|
||
// What a dependency should provide | ||
export interface UmzeptionDependency<T = unknown> extends PluginDefinition { | ||
export interface UmzeptionDependency<T extends AnyUmzeptionContext = AnyUmzeptionContext> extends PluginDefinition { | ||
glob: string[] | ||
installSchema: import('umzug').MigrationFn<T> | ||
} | ||
|
||
// The fully resolved internal definition | ||
export interface UmzeptionDefinition<T = unknown> extends UmzeptionDependency<T> { | ||
export interface UmzeptionDefinition<T extends AnyUmzeptionContext = AnyUmzeptionContext> extends UmzeptionDependency<T> { | ||
name: string | ||
pluginDir: string | ||
} | ||
|
||
export interface UmzeptionLookupOptions<T> extends PartialKeys< | ||
Omit<UmzeptionDependency<T>, 'pluginDir'>, | ||
'glob' | 'installSchema' | ||
> { | ||
export interface UmzeptionLookupOptions<T extends AnyUmzeptionContext> extends | ||
PartialKeys< | ||
Omit<UmzeptionDependency<T>, 'pluginDir'>, | ||
'glob' | 'installSchema' | ||
> | ||
{ | ||
cwd?: string|undefined | ||
install?: boolean | ||
meta?: ImportMeta | ||
noop?: boolean | ||
} | ||
|
||
// *** Context definitions *** | ||
|
||
export interface DefineUmzeptionContexts { | ||
unknown: UmzeptionContext<'unknown'>, | ||
} | ||
|
||
type ValidUmzeptionContexts = { | ||
[key in keyof DefineUmzeptionContexts as ( | ||
DefineUmzeptionContexts[key] extends BaseUmzeptionContext | ||
? Equal<key, DefineUmzeptionContexts[key]["type"]> | ||
: never | ||
)]: string extends key ? never : DefineUmzeptionContexts[key] | ||
} | ||
|
||
export type AnyUmzeptionContext = ValidUmzeptionContexts[keyof ValidUmzeptionContexts]; | ||
export type UmzeptionContextTypes = AnyUmzeptionContext["type"]; | ||
|
||
interface BaseUmzeptionContext { | ||
type: string | ||
value: unknown | ||
} | ||
|
||
export interface UmzeptionContext<T extends UmzeptionContextTypes, V = unknown> extends BaseUmzeptionContext { | ||
type: string extends T ? never : (T extends string ? T : never); | ||
value: V | ||
} | ||
|
||
// *** Helpers *** | ||
|
||
type PartialKeys<T, Keys extends keyof T> = Omit<T, Keys> & Partial<Pick<T, Keys>>; | ||
type StringLiteral<T> = string extends T ? never : T; | ||
type Equal<A, B> = A extends B ? A : never; |
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,10 @@ | ||
/** | ||
* @template {import("./advanced-types.js").UmzeptionContextTypes} T | ||
* @template {import("./advanced-types.js").DefineUmzeptionContexts[T]["value"]} V | ||
* @param {T} type | ||
* @param {V} value | ||
* @returns {import("./advanced-types.js").UmzeptionContext<T, V>} | ||
*/ | ||
export function createUmzeptionContext (type, value) { | ||
return /** @type {import("./advanced-types.js").UmzeptionContext<T, V>} */ ({ type, value }); | ||
} |
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
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