@@ -23,8 +23,6 @@ import {
2323 StyleRuleInfoApiResponse ,
2424 StyleId ,
2525 CustomInstruction ,
26- CustomInstructionInput ,
27- ConfiguredRules ,
2826 TranslationMemoryId ,
2927 TranslationMemoryInfo ,
3028 TranslationMemoryExport ,
@@ -107,12 +105,6 @@ function styleProfileOptionsToJson(
107105 return body ;
108106}
109107
110- /**
111- * @deprecated Pass the label, prompt and source language as separate arguments to
112- * `createStyleRuleCustomInstruction()` and `updateStyleRuleCustomInstruction()`, and use
113- * {@link CustomInstructionInput} with `createStyleRule()`. This type will be removed in the next
114- * major version.
115- */
116108export type CustomInstructionRequestBody = {
117109 label : string ;
118110 prompt : string ;
@@ -140,19 +132,6 @@ function customInstructionToWire(
140132 return body ;
141133}
142134
143- // Converts the camelCase category keys (e.g. datesAndTimes) to the wire's snake_case; the rule
144- // names and values inside each category are sent unchanged.
145- function configuredRulesToWire (
146- configuredRules : ConfiguredRules ,
147- ) : Record < string , Record < string , string > > {
148- const body : Record < string , Record < string , string > > = { } ;
149- for ( const [ category , rules ] of Object . entries ( configuredRules ) ) {
150- if ( rules === undefined ) continue ;
151- body [ category . replace ( / [ A - Z ] / g, ( c ) => `_${ c . toLowerCase ( ) } ` ) ] = rules ;
152- }
153- return body ;
154- }
155-
156135export enum WritingStyle {
157136 ACADEMIC = 'academic' ,
158137 BUSINESS = 'business' ,
@@ -1487,17 +1466,19 @@ export class DeepLClient extends Translator {
14871466 *
14881467 * @param name: The name of the style rule.
14891468 * @param language: The language code of the style rule.
1490- * @param configuredRules: Optional predefined rules to enable, see {@link ConfiguredRules}.
1491- * @param customInstructions: Optional custom instructions, see {@link CustomInstructionInput}.
1469+ * @param configuredRules: Optional configured rules, sent as given as `configured_rules`,
1470+ * e.g. `{ dates_and_times: { calendar_era: 'use_bc_and_ad' } }`.
1471+ * @param customInstructions: Optional custom instructions, sent as given as
1472+ * `custom_instructions`, e.g. `[{ label, prompt, source_language: 'de' }]`.
14921473 * @returns {Promise<StyleRuleInfo> } The created style rule info.
14931474 *
14941475 * @throws {DeepLError } If any error occurs while communicating with the DeepL API.
14951476 */
14961477 async createStyleRule (
14971478 name : string ,
14981479 language : string ,
1499- configuredRules ?: ConfiguredRules ,
1500- customInstructions ?: CustomInstructionInput [ ] ,
1480+ configuredRules ?: Record < string , Record < string , string > > ,
1481+ customInstructions ?: CustomInstructionRequestBody [ ] ,
15011482 ) : Promise < StyleRuleInfo > ;
15021483 /**
15031484 * @deprecated Pass the name, language, configured rules and custom instructions as separate
@@ -1507,24 +1488,14 @@ export class DeepLClient extends Translator {
15071488 async createStyleRule (
15081489 nameOrStyleRule : string | CreateStyleRuleRequestBody ,
15091490 language ?: string ,
1510- configuredRules ?: ConfiguredRules ,
1511- customInstructions ?: CustomInstructionInput [ ] ,
1491+ configuredRules ?: Record < string , Record < string , string > > ,
1492+ customInstructions ?: CustomInstructionRequestBody [ ] ,
15121493 ) : Promise < StyleRuleInfo > {
15131494 let body : CreateStyleRuleRequestBody ;
15141495 if ( typeof nameOrStyleRule === 'string' ) {
15151496 body = { name : nameOrStyleRule , language : language as string } ;
1516- if ( configuredRules !== undefined ) {
1517- body . configured_rules = configuredRulesToWire ( configuredRules ) ;
1518- }
1519- if ( customInstructions !== undefined ) {
1520- body . custom_instructions = customInstructions . map ( ( instruction ) =>
1521- customInstructionToWire (
1522- instruction . label ,
1523- instruction . prompt ,
1524- instruction . sourceLanguage ,
1525- ) ,
1526- ) ;
1527- }
1497+ if ( configuredRules !== undefined ) body . configured_rules = configuredRules ;
1498+ if ( customInstructions !== undefined ) body . custom_instructions = customInstructions ;
15281499 } else {
15291500 body = nameOrStyleRule ;
15301501 }
0 commit comments