@@ -140,6 +140,64 @@ export class RootDecoratorInstance extends DecoratorInstance {
140140}
141141
142142
143+
144+ // ~ setValuesBulk helpers ----------------------------------------
145+
146+ function detectBulkFormat ( data : string ) : 'json' | 'env' {
147+ return data . trimStart ( ) . startsWith ( '{' ) ? 'json' : 'env' ;
148+ }
149+
150+ function parseJsonBulkValues ( data : string ) : Record < string , { value : string | number | boolean } > {
151+ let parsed : any ;
152+ try {
153+ parsed = JSON . parse ( data ) ;
154+ } catch ( err ) {
155+ throw new SchemaError ( `@setValuesBulk: invalid JSON data - ${ ( err as Error ) . message } ` ) ;
156+ }
157+ if ( ! _ . isPlainObject ( parsed ) ) {
158+ throw new SchemaError ( '@setValuesBulk: JSON data must be a flat object' ) ;
159+ }
160+ const result : Record < string , { value : string | number | boolean } > = { } ;
161+ for ( const [ key , val ] of Object . entries ( parsed ) ) {
162+ if ( val === null || val === undefined ) continue ; // skip nulls
163+ if ( _ . isPlainObject ( val ) || _ . isArray ( val ) ) {
164+ throw new SchemaError ( `@setValuesBulk: JSON value for "${ key } " must be a scalar, not an object or array` ) ;
165+ }
166+ result [ key ] = { value : val as string | number | boolean } ;
167+ }
168+ return result ;
169+ }
170+
171+ function parseEnvBulkValues (
172+ data : string ,
173+ ) : Record < string , { value : string , description ?: string } > {
174+ let parsedFile ;
175+ try {
176+ parsedFile = parseEnvSpecDotEnvFile ( data ) ;
177+ } catch ( err ) {
178+ throw new SchemaError ( `@setValuesBulk: failed to parse env data - ${ ( err as Error ) . message } ` ) ;
179+ }
180+ const result : Record < string , { value : string , description ?: string } > = { } ;
181+ for ( const item of parsedFile . configItems ) {
182+ if ( item . value instanceof ParsedEnvSpecFunctionCall ) {
183+ throw new SchemaError (
184+ `@setValuesBulk: env format does not support function calls for "${ item . key } ".`
185+ + ' Use single quotes for literal values or use format=json instead.' ,
186+ ) ;
187+ }
188+ if ( item . value instanceof ParsedEnvSpecStaticValue ) {
189+ result [ item . key ] = {
190+ value : String ( item . value . unescapedValue ?? '' ) ,
191+ description : item . description || undefined ,
192+ } ;
193+ } else {
194+ // undefined value (empty assignment like `KEY=`)
195+ result [ item . key ] = { value : '' , description : item . description || undefined } ;
196+ }
197+ }
198+ return result ;
199+ }
200+
143201// ~ Root decorators ----------------------------------------
144202export type RootDecoratorDef < Processed = any > = {
145203 name : string ,
@@ -286,7 +344,7 @@ export const builtInRootDecorators: Array<RootDecoratorDef<any>> = [
286344 if ( effectiveFormat === 'json' ) {
287345 entries = parseJsonBulkValues ( dataString ) ;
288346 } else {
289- entries = parseEnvBulkValues ( dataString , graph . registeredResolverFunctions ) ;
347+ entries = parseEnvBulkValues ( dataString ) ;
290348 }
291349 } catch ( err ) {
292350 // surface parse errors as loading errors on the data source
@@ -328,66 +386,6 @@ export const builtInRootDecorators: Array<RootDecoratorDef<any>> = [
328386 } ,
329387] ;
330388
331-
332-
333- // ~ setValuesBulk helpers ----------------------------------------
334-
335- function detectBulkFormat ( data : string ) : 'json' | 'env' {
336- return data . trimStart ( ) . startsWith ( '{' ) ? 'json' : 'env' ;
337- }
338-
339- function parseJsonBulkValues ( data : string ) : Record < string , { value : string | number | boolean } > {
340- let parsed : any ;
341- try {
342- parsed = JSON . parse ( data ) ;
343- } catch ( err ) {
344- throw new SchemaError ( `@setValuesBulk: invalid JSON data - ${ ( err as Error ) . message } ` ) ;
345- }
346- if ( ! _ . isPlainObject ( parsed ) ) {
347- throw new SchemaError ( '@setValuesBulk: JSON data must be a flat object' ) ;
348- }
349- const result : Record < string , { value : string | number | boolean } > = { } ;
350- for ( const [ key , val ] of Object . entries ( parsed ) ) {
351- if ( val === null || val === undefined ) continue ; // skip nulls
352- if ( _ . isPlainObject ( val ) || _ . isArray ( val ) ) {
353- throw new SchemaError ( `@setValuesBulk: JSON value for "${ key } " must be a scalar, not an object or array` ) ;
354- }
355- result [ key ] = { value : val as string | number | boolean } ;
356- }
357- return result ;
358- }
359-
360- function parseEnvBulkValues (
361- data : string ,
362- registeredResolvers : Record < string , any > ,
363- ) : Record < string , { value : string , description ?: string } > {
364- let parsedFile ;
365- try {
366- parsedFile = parseEnvSpecDotEnvFile ( data ) ;
367- } catch ( err ) {
368- throw new SchemaError ( `@setValuesBulk: failed to parse env data - ${ ( err as Error ) . message } ` ) ;
369- }
370- const result : Record < string , { value : string , description ?: string } > = { } ;
371- for ( const item of parsedFile . configItems ) {
372- if ( item . value instanceof ParsedEnvSpecFunctionCall ) {
373- throw new SchemaError (
374- `@setValuesBulk: env format does not support function calls for "${ item . key } ".`
375- + ' Use single quotes for literal values or use format=json instead.' ,
376- ) ;
377- }
378- if ( item . value instanceof ParsedEnvSpecStaticValue ) {
379- result [ item . key ] = {
380- value : String ( item . value . unescapedValue ?? '' ) ,
381- description : item . description || undefined ,
382- } ;
383- } else {
384- // undefined value (empty assignment like `KEY=`)
385- result [ item . key ] = { value : '' , description : item . description || undefined } ;
386- }
387- }
388- return result ;
389- }
390-
391389// ~ Item decorators ----------------------------------------
392390export type ItemDecoratorDef < T = any > = {
393391 name : string ,
0 commit comments