Skip to content

Commit

Permalink
Add missing by-tokens deserializer config
Browse files Browse the repository at this point in the history
  • Loading branch information
surol committed Jul 26, 2023
1 parent 0279b0f commit 61919fd
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions src/schema/uc-deserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,19 @@ export namespace UcDeserializer {
readonly onMeta?: MetaUcrx;
}

/**
* {@link UcDeserializer Universal} deserializer {@link createUcDeserializer compiler} configuration.
*/
export interface Config {
export interface BaseConfig {
/**
* Target bundle the compiled deserializer will be included into.
*
* Default bundle will be used when omitted.
*/
readonly bundle?: UcBundle | undefined;
}

/**
* {@link UcDeserializer Universal} deserializer {@link createUcDeserializer compiler} configuration.
*/
export interface Config extends BaseConfig {
readonly mode?: 'universal' | undefined;

/**
Expand All @@ -220,16 +222,18 @@ export namespace UcDeserializer {
}

/**
* {@link Sync Synchronous} deserializer {@link createUcDeserializer compiler} configuration.
* {@link UcDeserializer.ByTokens By-tokens} deserializer {@link createUcDeserializer compiler} configuration.
*/
export interface SyncConfig {
/**
* Target bundle the compiled deserializer will be included into.
*
* Default bundle will be used when omitted.
*/
readonly bundle?: UcBundle | undefined;
export interface ByTokensConfig extends BaseConfig {
readonly mode?: 'universal' | undefined;

readonly from: 'tokens';
}

/**
* {@link Sync Synchronous} deserializer {@link createUcDeserializer compiler} configuration.
*/
export interface SyncConfig extends BaseConfig {
readonly mode: 'sync';

/**
Expand All @@ -243,14 +247,7 @@ export namespace UcDeserializer {
/**
* {@link Async Asynchronous} deserializer {@link createUcDeserializer compiler} configuration.
*/
export interface AsyncConfig {
/**
* Target bundle the compiled deserializer will be included into.
*
* Default bundle will be used when omitted.
*/
readonly bundle?: UcBundle | undefined;

export interface AsyncConfig extends BaseConfig {
readonly mode: 'async';

/**
Expand All @@ -264,14 +261,7 @@ export namespace UcDeserializer {
/**
* {@link Async Asynchronous} by-tokens deserializer {@link createUcDeserializer compiler} configuration.
*/
export interface AsyncByTokensConfig {
/**
* Target bundle the compiled deserializer will be included into.
*
* Default bundle will be used when omitted.
*/
readonly bundle?: UcBundle | undefined;

export interface AsyncByTokensConfig extends BaseConfig {
readonly mode: 'async';

readonly from: 'tokens';
Expand All @@ -297,6 +287,25 @@ export function createUcDeserializer<T>(
config?: UcDeserializer.Config,
): UcDeserializer<T>;

/**
* Compiles {@link UcDeserializer.ByTokens by-tokens deserializer} for the given data `model`.
*
* **This is a placeholder**. It is replaced with actual deserializer when TypeScript code compiled with
* [ts-transformer-churi] enabled. It is expected that the result of this function call is stored to constant.
*
* @typeParam T - Deserialized data type.
* @param model - Deserialized data model.
* @param config - Compiler configuration.
*
* @returns Universal deserializer instance.
*
* [ts-transformer-churi]: https://www.npmjs.com/package/ts-transformer-churi
*/
export function createUcDeserializer<T>(
model: UcModel<T>,
config?: UcDeserializer.ByTokensConfig,
): UcDeserializer.ByTokens<T>;

/**
* Compiles {@link UcDeserializer.Sync synchronous deserializer} for the given data `model`.
*
Expand Down Expand Up @@ -358,6 +367,7 @@ export function createUcDeserializer<T>(
model: UcModel<T>,
_init?:
| UcDeserializer.Config
| UcDeserializer.ByTokensConfig
| UcDeserializer.SyncConfig
| UcDeserializer.AsyncConfig
| UcDeserializer.AsyncByTokensConfig,
Expand Down

0 comments on commit 61919fd

Please sign in to comment.