11import * as errors from './errors.ts' ;
22import { urlsafe_b64encode } from './utils.ts' ;
3+ import { ExtractionConfigError } from './errors.ts' ;
34
45export enum CompressionFormat {
56 /**
@@ -21,30 +22,55 @@ type ExtractionConfigOptions = {
2122 content_type : string ;
2223 url ?: string ;
2324 charset ?: string ;
24- template ?: string ; // saved template name
25- ephemeral_template ?: object ; // ephemeraly declared json template
25+ extraction_template ?: string ; // saved template name
26+ extraction_ephemeral_template ?: object ; // ephemeraly declared json template
2627 extraction_prompt ?: string ;
2728 extraction_model ?: string ;
2829 is_document_compressed ?: boolean ;
2930 document_compression_format ?: 'gzip' | 'zstd' | 'deflate' | CompressionFormat ;
3031 webhook ?: string ;
32+
33+ // deprecated options
34+ template ?: string ;
35+ ephemeral_template ?: object ;
3136} ;
3237
3338export class ExtractionConfig {
3439 body : string | Uint8Array ;
3540 content_type : string ;
3641 url ?: string ;
3742 charset ?: string ;
38- template ?: string ; // saved template name
39- ephemeral_template ?: object ; // ephemeraly declared json template
43+ extraction_template ?: string ; // saved template name
44+ extraction_ephemeral_template ?: object ; // ephemeraly declared json template
4045 extraction_prompt ?: string ;
4146 extraction_model ?: string ;
4247 is_document_compressed ?: boolean ;
4348 document_compression_format ?: 'gzip' | 'zstd' | 'deflate' | CompressionFormat ;
4449 webhook ?: string ;
4550
51+ // // deprecated options
52+ template ?: string ;
53+ ephemeral_template ?: object ;
54+
4655 constructor ( options : ExtractionConfigOptions ) {
4756 this . validateOptions ( options ) ;
57+ if ( options . template ) {
58+ console . warn (
59+ `Deprecation warning: 'template' is deprecated. Use 'extraction_template' instead.`
60+ ) ;
61+ this . extraction_template = options . template ;
62+ } else {
63+ this . extraction_template = options . extraction_template ;
64+ }
65+ if ( options . ephemeral_template ) {
66+ console . warn (
67+ `Deprecation warning: 'ephemeral_template' is deprecated. Use 'extraction_ephemeral_template' instead.`
68+ ) ;
69+ this . extraction_ephemeral_template = options . ephemeral_template ;
70+ } else {
71+ this . extraction_ephemeral_template = options . extraction_ephemeral_template ;
72+ }
73+
4874 if (
4975 options . document_compression_format &&
5076 ! Object . values ( CompressionFormat ) . includes ( options . document_compression_format as CompressionFormat )
@@ -57,8 +83,8 @@ export class ExtractionConfig {
5783 this . content_type = options . content_type ;
5884 this . url = options . url ?? this . url ;
5985 this . charset = options . charset ?? this . charset ;
60- this . template = options . template ?? this . template ;
61- this . ephemeral_template = options . ephemeral_template ?? this . ephemeral_template ;
86+ this . extraction_template = options . extraction_template ?? this . extraction_template ;
87+ this . extraction_ephemeral_template = options . extraction_ephemeral_template ?? this . extraction_ephemeral_template ;
6288 this . extraction_prompt = options . extraction_prompt ?? this . extraction_prompt ;
6389 this . extraction_model = options . extraction_model ?? this . extraction_model ;
6490 this . is_document_compressed = options . is_document_compressed ?? this . is_document_compressed ;
@@ -90,18 +116,18 @@ export class ExtractionConfig {
90116 params . charset = this . charset ;
91117 }
92118
93- if ( this . template && this . ephemeral_template ) {
94- throw new errors . ExtractionConfigError (
95- 'You cannot pass both parameters template and ephemeral_template . You must choose' ,
119+ if ( this . extraction_template && this . extraction_ephemeral_template ) {
120+ throw new ExtractionConfigError (
121+ 'You cannot pass both parameters extraction_template and extraction_ephemeral_template . You must choose' ,
96122 ) ;
97123 }
98124
99- if ( this . template ) {
100- params . extraction_template = this . template ;
125+ if ( this . extraction_template ) {
126+ params . extraction_template = this . extraction_template ;
101127 }
102128
103- if ( this . ephemeral_template ) {
104- params . extraction_template = 'ephemeral:' + urlsafe_b64encode ( JSON . stringify ( this . ephemeral_template ) ) ;
129+ if ( this . extraction_ephemeral_template ) {
130+ params . extraction_template = 'ephemeral:' + urlsafe_b64encode ( JSON . stringify ( this . extraction_ephemeral_template ) ) ;
105131 }
106132
107133 if ( this . extraction_prompt ) {
0 commit comments