11import { isSensitiveConfigPath } from "../../../src/config/sensitive-paths.js" ;
22import type { ConfigUiHint , ConfigUiHints } from "../api/types.ts" ;
3- // Control UI view renders config form.shared screen content.
43import { t } from "../i18n/index.ts" ;
4+ import { hintForPath , pathKey } from "../lib/config-form-utils.ts" ;
55
6- export type JsonSchema = {
7- type ?: string | string [ ] ;
8- title ?: string ;
9- description ?: string ;
10- tags ?: string [ ] ;
11- "x-tags" ?: string [ ] ;
12- properties ?: Record < string , JsonSchema > ;
13- required ?: string [ ] ;
14- items ?: JsonSchema | JsonSchema [ ] ;
15- additionalItems ?: JsonSchema | boolean ;
16- additionalProperties ?: JsonSchema | boolean ;
17- enum ?: unknown [ ] ;
18- enumIncludesNull ?: boolean ;
19- const ?: unknown ;
20- default ?: unknown ;
21- minimum ?: number ;
22- maximum ?: number ;
23- exclusiveMinimum ?: number ;
24- exclusiveMaximum ?: number ;
25- multipleOf ?: number ;
26- minLength ?: number ;
27- maxLength ?: number ;
28- pattern ?: string ;
29- minItems ?: number ;
30- maxItems ?: number ;
31- uniqueItems ?: boolean ;
32- anyOf ?: JsonSchema [ ] ;
33- oneOf ?: JsonSchema [ ] ;
34- allOf ?: JsonSchema [ ] ;
35- nullable ?: boolean ;
36- } ;
37-
38- export function schemaType ( schema : JsonSchema ) : string | undefined {
39- if ( ! schema ) {
40- return undefined ;
41- }
42- if ( Array . isArray ( schema . type ) ) {
43- return schema . type . find ( ( type ) => type !== "null" ) ?? schema . type [ 0 ] ;
44- }
45- return schema . type ;
46- }
47-
48- export function schemaMayAcceptString ( schema : JsonSchema ) : boolean {
49- const declaredTypes = Array . isArray ( schema . type ) ? schema . type : schema . type ? [ schema . type ] : [ ] ;
50- if ( declaredTypes . length > 0 && ! declaredTypes . includes ( "string" ) ) {
51- return false ;
52- }
53- if ( schema . const !== undefined && typeof schema . const !== "string" ) {
54- return false ;
55- }
56- if ( schema . enum && ! schema . enum . some ( ( entry ) => typeof entry === "string" ) ) {
57- return false ;
58- }
59- if ( schema . allOf && ! schema . allOf . every ( schemaMayAcceptString ) ) {
60- return false ;
61- }
62- if ( schema . anyOf && ! schema . anyOf . some ( schemaMayAcceptString ) ) {
63- return false ;
64- }
65- if ( schema . oneOf && ! schema . oneOf . some ( schemaMayAcceptString ) ) {
66- return false ;
67- }
68- return true ;
69- }
6+ export {
7+ hintForPath ,
8+ humanize ,
9+ pathKey ,
10+ schemaMayAcceptString ,
11+ schemaType ,
12+ type JsonSchema ,
13+ } from "../lib/config-form-utils.ts" ;
7014
7115export function configFieldId ( path : Array < string | number > , suffix : string ) : string {
7216 const key =
@@ -86,47 +30,6 @@ export function configFieldId(path: Array<string | number>, suffix: string): str
8630 return `config-field-${ key } -${ suffix } ` ;
8731}
8832
89- export function pathKey ( path : Array < string | number > ) : string {
90- return path . filter ( ( segment ) => typeof segment === "string" ) . join ( "." ) ;
91- }
92-
93- export function hintForPath ( path : Array < string | number > , hints : ConfigUiHints ) {
94- const key = pathKey ( path ) ;
95- const direct = hints [ key ] ;
96- if ( direct ) {
97- return direct ;
98- }
99- const segments = path . map ( String ) ;
100- for ( const [ hintKey , hint ] of Object . entries ( hints ) ) {
101- if ( ! hintKey . includes ( "*" ) ) {
102- continue ;
103- }
104- const hintSegments = hintKey . split ( "." ) ;
105- if ( hintSegments . length !== segments . length ) {
106- continue ;
107- }
108- let match = true ;
109- for ( let i = 0 ; i < segments . length ; i += 1 ) {
110- if ( hintSegments [ i ] !== "*" && hintSegments [ i ] !== segments [ i ] ) {
111- match = false ;
112- break ;
113- }
114- }
115- if ( match ) {
116- return hint ;
117- }
118- }
119- return undefined ;
120- }
121-
122- export function humanize ( raw : string ) {
123- return raw
124- . replace ( / _ / g, " " )
125- . replace ( / ( [ a - z 0 - 9 ] ) ( [ A - Z ] ) / g, "$1 $2" )
126- . replace ( / \s + / g, " " )
127- . replace ( / ^ ./ , ( m ) => m . toUpperCase ( ) ) ;
128- }
129-
13033const ENV_VAR_PLACEHOLDER_PATTERN = / ^ \$ \{ [ ^ } ] * \} $ / ;
13134
13235export function redactedPlaceholder ( ) : string {
0 commit comments