@app-config/extension-utils
Advanced tools
Comparing version 3.0.0-alpha.1 to 3.0.0-alpha.2
@@ -1,3 +0,4 @@ | ||
import type { ParsingExtension, ParsingExtensionKey, ParsingExtensionTransform } from '@app-config/core'; | ||
import type { ParsingExtension, ParsingExtensionKey } from '@app-config/core'; | ||
import { AppConfigError } from '@app-config/core'; | ||
import { Json } from '@app-config/utils'; | ||
import { SchemaBuilder } from '@serafin/schema-builder'; | ||
@@ -8,3 +9,3 @@ export declare function composeExtensions(extensions: ParsingExtension[]): ParsingExtension; | ||
} | ||
export declare function validateOptions<T>(builder: (builder: typeof SchemaBuilder) => SchemaBuilder<T>, extension: (value: T, key: ParsingExtensionKey, context: ParsingExtensionKey[]) => ParsingExtensionTransform | false, { lazy }?: { | ||
export declare function validateOptions<T extends Json>(builder: (builder: typeof SchemaBuilder) => SchemaBuilder<T>, extension: ParsingExtension<T>, { lazy }?: { | ||
lazy?: boolean; | ||
@@ -11,0 +12,0 @@ }): ParsingExtension; |
import { parseValue, Root, AppConfigError } from '@app-config/core'; | ||
import { SchemaBuilder } from '@serafin/schema-builder'; | ||
export function composeExtensions(extensions) { | ||
return (value, [k]) => { | ||
return (value, [[k]]) => { | ||
if (k !== Root) | ||
@@ -19,5 +19,5 @@ return false; | ||
}; | ||
return (value, ctxKey, ctx) => { | ||
if (shouldApply(ctxKey)) { | ||
return parsingExtension(value, ctxKey, ctx); | ||
return (value, parentKeys, context) => { | ||
if (shouldApply(parentKeys[0])) { | ||
return parsingExtension(value, parentKeys, context); | ||
} | ||
@@ -31,3 +31,3 @@ return false; | ||
const validate = validationFunction(builder); | ||
return (value, ctxKey, ctx) => { | ||
return (value, parentKeys, context) => { | ||
return async (parse, ...args) => { | ||
@@ -41,4 +41,4 @@ let valid; | ||
} | ||
validate(valid, [...ctx, ctxKey]); | ||
const call = extension(valid, ctxKey, ctx); | ||
validate(valid, parentKeys); | ||
const call = extension(valid, parentKeys, context); | ||
if (call) { | ||
@@ -60,3 +60,4 @@ return call(parse, ...args); | ||
const message = error instanceof Error ? error.message : 'unknown'; | ||
const parents = ctx | ||
const parents = [...ctx] | ||
.reverse() | ||
.map(([, k]) => k) | ||
@@ -63,0 +64,0 @@ .filter((v) => !!v) |
@@ -1,3 +0,4 @@ | ||
import type { ParsingExtension, ParsingExtensionKey, ParsingExtensionTransform } from '@app-config/core'; | ||
import type { ParsingExtension, ParsingExtensionKey } from '@app-config/core'; | ||
import { AppConfigError } from '@app-config/core'; | ||
import { Json } from '@app-config/utils'; | ||
import { SchemaBuilder } from '@serafin/schema-builder'; | ||
@@ -8,3 +9,3 @@ export declare function composeExtensions(extensions: ParsingExtension[]): ParsingExtension; | ||
} | ||
export declare function validateOptions<T>(builder: (builder: typeof SchemaBuilder) => SchemaBuilder<T>, extension: (value: T, key: ParsingExtensionKey, context: ParsingExtensionKey[]) => ParsingExtensionTransform | false, { lazy }?: { | ||
export declare function validateOptions<T extends Json>(builder: (builder: typeof SchemaBuilder) => SchemaBuilder<T>, extension: ParsingExtension<T>, { lazy }?: { | ||
lazy?: boolean; | ||
@@ -11,0 +12,0 @@ }): ParsingExtension; |
@@ -7,3 +7,3 @@ "use strict"; | ||
function composeExtensions(extensions) { | ||
return (value, [k]) => { | ||
return (value, [[k]]) => { | ||
if (k !== core_1.Root) | ||
@@ -24,5 +24,5 @@ return false; | ||
}; | ||
return (value, ctxKey, ctx) => { | ||
if (shouldApply(ctxKey)) { | ||
return parsingExtension(value, ctxKey, ctx); | ||
return (value, parentKeys, context) => { | ||
if (shouldApply(parentKeys[0])) { | ||
return parsingExtension(value, parentKeys, context); | ||
} | ||
@@ -38,3 +38,3 @@ return false; | ||
const validate = validationFunction(builder); | ||
return (value, ctxKey, ctx) => { | ||
return (value, parentKeys, context) => { | ||
return async (parse, ...args) => { | ||
@@ -48,4 +48,4 @@ let valid; | ||
} | ||
validate(valid, [...ctx, ctxKey]); | ||
const call = extension(valid, ctxKey, ctx); | ||
validate(valid, parentKeys); | ||
const call = extension(valid, parentKeys, context); | ||
if (call) { | ||
@@ -68,3 +68,4 @@ return call(parse, ...args); | ||
const message = error instanceof Error ? error.message : 'unknown'; | ||
const parents = ctx | ||
const parents = [...ctx] | ||
.reverse() | ||
.map(([, k]) => k) | ||
@@ -71,0 +72,0 @@ .filter((v) => !!v) |
{ | ||
"name": "@app-config/extension-utils", | ||
"description": "Utilities for writing @app-config parsing extensions", | ||
"version": "3.0.0-alpha.1", | ||
"version": "3.0.0-alpha.2", | ||
"license": "MPL-2.0", | ||
@@ -33,3 +33,3 @@ "author": { | ||
"dependencies": { | ||
"@app-config/core": "^3.0.0-alpha.1", | ||
"@app-config/core": "^3.0.0-alpha.2", | ||
"@serafin/schema-builder": "0.14" | ||
@@ -36,0 +36,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12617
164