@aws/nx-plugin 1.0.0-rc.16 → 1.0.0-rc.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws/nx-plugin",
3
- "version": "1.0.0-rc.16",
3
+ "version": "1.0.0-rc.17",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/awslabs/nx-plugin-for-aws.git",
@@ -740,6 +740,8 @@ export type ApiIntegrations<TOperation extends string, TBaseIntegration> =
740
740
  * @template TDefaultIntegrationProps - Type for default integration properties
741
741
  * @template TDefaultIntegration - Type for default integration implementation
742
742
  * @template TPattern - The integration pattern ('shared' or 'isolated')
743
+ * @template TOverridden - Union of operation names that have been overridden
744
+ * @template TOperationOptioned - Union of operation names with per-operation options
743
745
  */
744
746
  export class IntegrationBuilder<
745
747
  TOperation extends string,
@@ -748,6 +750,8 @@ export class IntegrationBuilder<
748
750
  TDefaultIntegrationProps extends object,
749
751
  TDefaultIntegration extends TBaseIntegration,
750
752
  TPattern extends 'shared' | 'isolated',
753
+ TOverridden extends string = never,
754
+ TOperationOptioned extends string = never,
751
755
  > {
752
756
  /** Options for the integration builder */
753
757
  private options: IntegrationBuilderProps<
@@ -760,6 +764,11 @@ export class IntegrationBuilder<
760
764
  /** Map of operation names to their custom integrations */
761
765
  private integrations: Partial<TIntegrations> = {};
762
766
 
767
+ /** Map of default integration keys to per-operation default option overrides */
768
+ private perOperationOptions: Partial<
769
+ Record<string, Partial<TDefaultIntegrationProps>>
770
+ > = {};
771
+
763
772
  /**
764
773
  * Create an Integration Builder for an HTTP API with a shared pattern
765
774
  */
@@ -914,11 +923,16 @@ export class IntegrationBuilder<
914
923
  /**
915
924
  * Overrides default integrations with custom implementations for specific operations.
916
925
  *
926
+ * Operations which have per-operation options set via withOperationOptions cannot be
927
+ * overridden, since these still use the default integration.
928
+ *
917
929
  * @param overrides - Map of operation names to their custom integration implementations
918
930
  * @returns The builder instance with updated type information reflecting the overrides
919
931
  */
920
932
  public withOverrides<
921
- TOverrideIntegrations extends Partial<Record<TOperation, TBaseIntegration>>,
933
+ TOverrideIntegrations extends Partial<
934
+ Record<Exclude<TOperation, TOperationOptioned>, TBaseIntegration>
935
+ >,
922
936
  >(overrides: TOverrideIntegrations) {
923
937
  this.integrations = { ...this.integrations, ...overrides };
924
938
  // Re-type to include the overridden integration types.
@@ -934,7 +948,9 @@ export class IntegrationBuilder<
934
948
  MergedIntegrations,
935
949
  TDefaultIntegrationProps,
936
950
  TDefaultIntegration,
937
- TPattern
951
+ TPattern,
952
+ TOverridden | Extract<keyof TOverrideIntegrations, string>,
953
+ TOperationOptioned
938
954
  >;
939
955
  }
940
956
 
@@ -953,6 +969,43 @@ export class IntegrationBuilder<
953
969
  return this;
954
970
  }
955
971
 
972
+ /**
973
+ * Updates the default integration options for specific operations, without
974
+ * affecting the others. The given options are merged with the defaults (and
975
+ * any options set via withDefaultOptions) when building each default integration.
976
+ *
977
+ * Operations which have been replaced via withOverrides cannot be targeted, since
978
+ * they no longer use the default integration.
979
+ *
980
+ * @param options - Map of operation names to partial default integration options
981
+ * @returns The builder instance
982
+ */
983
+ public withOperationOptions<
984
+ TOptions extends Partial<
985
+ Record<
986
+ Exclude<DefaultIntegrationKeys<TPattern, TOperation>, TOverridden>,
987
+ Partial<TDefaultIntegrationProps>
988
+ >
989
+ >,
990
+ >(options: TOptions) {
991
+ Object.entries(options).forEach(([op, opOptions]) => {
992
+ this.perOperationOptions[op] = {
993
+ ...this.perOperationOptions[op],
994
+ ...(opOptions as Partial<TDefaultIntegrationProps>),
995
+ };
996
+ });
997
+ return this as unknown as IntegrationBuilder<
998
+ TOperation,
999
+ TBaseIntegration,
1000
+ TIntegrations,
1001
+ TDefaultIntegrationProps,
1002
+ TDefaultIntegration,
1003
+ TPattern,
1004
+ TOverridden,
1005
+ TOperationOptioned | Extract<keyof TOptions, string>
1006
+ >;
1007
+ }
1008
+
956
1009
  /**
957
1010
  * Builds and returns the complete set of integrations.
958
1011
  *
@@ -967,6 +1020,10 @@ export class IntegrationBuilder<
967
1020
  */
968
1021
  public build(): TIntegrations {
969
1022
  const options = this.options;
1023
+ const buildOptionsFor = (op: string): TDefaultIntegrationProps => ({
1024
+ ...options.defaultIntegrationOptions,
1025
+ ...this.perOperationOptions[op],
1026
+ });
970
1027
  return {
971
1028
  ...Object.fromEntries(
972
1029
  options.pattern === 'shared'
@@ -975,7 +1032,7 @@ export class IntegrationBuilder<
975
1032
  '$router',
976
1033
  options.buildDefaultIntegration(
977
1034
  '$router',
978
- options.defaultIntegrationOptions,
1035
+ buildOptionsFor('$router'),
979
1036
  ),
980
1037
  ],
981
1038
  ]
@@ -986,10 +1043,7 @@ export class IntegrationBuilder<
986
1043
  )
987
1044
  .map((op) => [
988
1045
  op,
989
- options.buildDefaultIntegration(
990
- op,
991
- options.defaultIntegrationOptions,
992
- ),
1046
+ options.buildDefaultIntegration(op, buildOptionsFor(op)),
993
1047
  ]),
994
1048
  ),
995
1049
  ...this.integrations,
@@ -1639,6 +1693,8 @@ export type ApiIntegrations<TOperation extends string, TBaseIntegration> =
1639
1693
  * @template TDefaultIntegrationProps - Type for default integration properties
1640
1694
  * @template TDefaultIntegration - Type for default integration implementation
1641
1695
  * @template TPattern - The integration pattern ('shared' or 'isolated')
1696
+ * @template TOverridden - Union of operation names that have been overridden
1697
+ * @template TOperationOptioned - Union of operation names with per-operation options
1642
1698
  */
1643
1699
  export class IntegrationBuilder<
1644
1700
  TOperation extends string,
@@ -1647,6 +1703,8 @@ export class IntegrationBuilder<
1647
1703
  TDefaultIntegrationProps extends object,
1648
1704
  TDefaultIntegration extends TBaseIntegration,
1649
1705
  TPattern extends 'shared' | 'isolated',
1706
+ TOverridden extends string = never,
1707
+ TOperationOptioned extends string = never,
1650
1708
  > {
1651
1709
  /** Options for the integration builder */
1652
1710
  private options: IntegrationBuilderProps<
@@ -1659,6 +1717,11 @@ export class IntegrationBuilder<
1659
1717
  /** Map of operation names to their custom integrations */
1660
1718
  private integrations: Partial<TIntegrations> = {};
1661
1719
 
1720
+ /** Map of default integration keys to per-operation default option overrides */
1721
+ private perOperationOptions: Partial<
1722
+ Record<string, Partial<TDefaultIntegrationProps>>
1723
+ > = {};
1724
+
1662
1725
  /**
1663
1726
  * Create an Integration Builder for an HTTP API with a shared pattern
1664
1727
  */
@@ -1813,11 +1876,16 @@ export class IntegrationBuilder<
1813
1876
  /**
1814
1877
  * Overrides default integrations with custom implementations for specific operations.
1815
1878
  *
1879
+ * Operations which have per-operation options set via withOperationOptions cannot be
1880
+ * overridden, since these still use the default integration.
1881
+ *
1816
1882
  * @param overrides - Map of operation names to their custom integration implementations
1817
1883
  * @returns The builder instance with updated type information reflecting the overrides
1818
1884
  */
1819
1885
  public withOverrides<
1820
- TOverrideIntegrations extends Partial<Record<TOperation, TBaseIntegration>>,
1886
+ TOverrideIntegrations extends Partial<
1887
+ Record<Exclude<TOperation, TOperationOptioned>, TBaseIntegration>
1888
+ >,
1821
1889
  >(overrides: TOverrideIntegrations) {
1822
1890
  this.integrations = { ...this.integrations, ...overrides };
1823
1891
  // Re-type to include the overridden integration types.
@@ -1833,7 +1901,9 @@ export class IntegrationBuilder<
1833
1901
  MergedIntegrations,
1834
1902
  TDefaultIntegrationProps,
1835
1903
  TDefaultIntegration,
1836
- TPattern
1904
+ TPattern,
1905
+ TOverridden | Extract<keyof TOverrideIntegrations, string>,
1906
+ TOperationOptioned
1837
1907
  >;
1838
1908
  }
1839
1909
 
@@ -1852,6 +1922,43 @@ export class IntegrationBuilder<
1852
1922
  return this;
1853
1923
  }
1854
1924
 
1925
+ /**
1926
+ * Updates the default integration options for specific operations, without
1927
+ * affecting the others. The given options are merged with the defaults (and
1928
+ * any options set via withDefaultOptions) when building each default integration.
1929
+ *
1930
+ * Operations which have been replaced via withOverrides cannot be targeted, since
1931
+ * they no longer use the default integration.
1932
+ *
1933
+ * @param options - Map of operation names to partial default integration options
1934
+ * @returns The builder instance
1935
+ */
1936
+ public withOperationOptions<
1937
+ TOptions extends Partial<
1938
+ Record<
1939
+ Exclude<DefaultIntegrationKeys<TPattern, TOperation>, TOverridden>,
1940
+ Partial<TDefaultIntegrationProps>
1941
+ >
1942
+ >,
1943
+ >(options: TOptions) {
1944
+ Object.entries(options).forEach(([op, opOptions]) => {
1945
+ this.perOperationOptions[op] = {
1946
+ ...this.perOperationOptions[op],
1947
+ ...(opOptions as Partial<TDefaultIntegrationProps>),
1948
+ };
1949
+ });
1950
+ return this as unknown as IntegrationBuilder<
1951
+ TOperation,
1952
+ TBaseIntegration,
1953
+ TIntegrations,
1954
+ TDefaultIntegrationProps,
1955
+ TDefaultIntegration,
1956
+ TPattern,
1957
+ TOverridden,
1958
+ TOperationOptioned | Extract<keyof TOptions, string>
1959
+ >;
1960
+ }
1961
+
1855
1962
  /**
1856
1963
  * Builds and returns the complete set of integrations.
1857
1964
  *
@@ -1866,6 +1973,10 @@ export class IntegrationBuilder<
1866
1973
  */
1867
1974
  public build(): TIntegrations {
1868
1975
  const options = this.options;
1976
+ const buildOptionsFor = (op: string): TDefaultIntegrationProps => ({
1977
+ ...options.defaultIntegrationOptions,
1978
+ ...this.perOperationOptions[op],
1979
+ });
1869
1980
  return {
1870
1981
  ...Object.fromEntries(
1871
1982
  options.pattern === 'shared'
@@ -1874,7 +1985,7 @@ export class IntegrationBuilder<
1874
1985
  '$router',
1875
1986
  options.buildDefaultIntegration(
1876
1987
  '$router',
1877
- options.defaultIntegrationOptions,
1988
+ buildOptionsFor('$router'),
1878
1989
  ),
1879
1990
  ],
1880
1991
  ]
@@ -1885,10 +1996,7 @@ export class IntegrationBuilder<
1885
1996
  )
1886
1997
  .map((op) => [
1887
1998
  op,
1888
- options.buildDefaultIntegration(
1889
- op,
1890
- options.defaultIntegrationOptions,
1891
- ),
1999
+ options.buildDefaultIntegration(op, buildOptionsFor(op)),
1892
2000
  ]),
1893
2001
  ),
1894
2002
  ...this.integrations,
@@ -1751,6 +1751,8 @@ export type ApiIntegrations<TOperation extends string, TBaseIntegration> =
1751
1751
  * @template TDefaultIntegrationProps - Type for default integration properties
1752
1752
  * @template TDefaultIntegration - Type for default integration implementation
1753
1753
  * @template TPattern - The integration pattern ('shared' or 'isolated')
1754
+ * @template TOverridden - Union of operation names that have been overridden
1755
+ * @template TOperationOptioned - Union of operation names with per-operation options
1754
1756
  */
1755
1757
  export class IntegrationBuilder<
1756
1758
  TOperation extends string,
@@ -1759,6 +1761,8 @@ export class IntegrationBuilder<
1759
1761
  TDefaultIntegrationProps extends object,
1760
1762
  TDefaultIntegration extends TBaseIntegration,
1761
1763
  TPattern extends 'shared' | 'isolated',
1764
+ TOverridden extends string = never,
1765
+ TOperationOptioned extends string = never,
1762
1766
  > {
1763
1767
  /** Options for the integration builder */
1764
1768
  private options: IntegrationBuilderProps<
@@ -1771,6 +1775,11 @@ export class IntegrationBuilder<
1771
1775
  /** Map of operation names to their custom integrations */
1772
1776
  private integrations: Partial<TIntegrations> = {};
1773
1777
 
1778
+ /** Map of default integration keys to per-operation default option overrides */
1779
+ private perOperationOptions: Partial<
1780
+ Record<string, Partial<TDefaultIntegrationProps>>
1781
+ > = {};
1782
+
1774
1783
  /**
1775
1784
  * Create an Integration Builder for an HTTP API with a shared pattern
1776
1785
  */
@@ -1925,11 +1934,16 @@ export class IntegrationBuilder<
1925
1934
  /**
1926
1935
  * Overrides default integrations with custom implementations for specific operations.
1927
1936
  *
1937
+ * Operations which have per-operation options set via withOperationOptions cannot be
1938
+ * overridden, since these still use the default integration.
1939
+ *
1928
1940
  * @param overrides - Map of operation names to their custom integration implementations
1929
1941
  * @returns The builder instance with updated type information reflecting the overrides
1930
1942
  */
1931
1943
  public withOverrides<
1932
- TOverrideIntegrations extends Partial<Record<TOperation, TBaseIntegration>>,
1944
+ TOverrideIntegrations extends Partial<
1945
+ Record<Exclude<TOperation, TOperationOptioned>, TBaseIntegration>
1946
+ >,
1933
1947
  >(overrides: TOverrideIntegrations) {
1934
1948
  this.integrations = { ...this.integrations, ...overrides };
1935
1949
  // Re-type to include the overridden integration types.
@@ -1945,7 +1959,9 @@ export class IntegrationBuilder<
1945
1959
  MergedIntegrations,
1946
1960
  TDefaultIntegrationProps,
1947
1961
  TDefaultIntegration,
1948
- TPattern
1962
+ TPattern,
1963
+ TOverridden | Extract<keyof TOverrideIntegrations, string>,
1964
+ TOperationOptioned
1949
1965
  >;
1950
1966
  }
1951
1967
 
@@ -1964,6 +1980,43 @@ export class IntegrationBuilder<
1964
1980
  return this;
1965
1981
  }
1966
1982
 
1983
+ /**
1984
+ * Updates the default integration options for specific operations, without
1985
+ * affecting the others. The given options are merged with the defaults (and
1986
+ * any options set via withDefaultOptions) when building each default integration.
1987
+ *
1988
+ * Operations which have been replaced via withOverrides cannot be targeted, since
1989
+ * they no longer use the default integration.
1990
+ *
1991
+ * @param options - Map of operation names to partial default integration options
1992
+ * @returns The builder instance
1993
+ */
1994
+ public withOperationOptions<
1995
+ TOptions extends Partial<
1996
+ Record<
1997
+ Exclude<DefaultIntegrationKeys<TPattern, TOperation>, TOverridden>,
1998
+ Partial<TDefaultIntegrationProps>
1999
+ >
2000
+ >,
2001
+ >(options: TOptions) {
2002
+ Object.entries(options).forEach(([op, opOptions]) => {
2003
+ this.perOperationOptions[op] = {
2004
+ ...this.perOperationOptions[op],
2005
+ ...(opOptions as Partial<TDefaultIntegrationProps>),
2006
+ };
2007
+ });
2008
+ return this as unknown as IntegrationBuilder<
2009
+ TOperation,
2010
+ TBaseIntegration,
2011
+ TIntegrations,
2012
+ TDefaultIntegrationProps,
2013
+ TDefaultIntegration,
2014
+ TPattern,
2015
+ TOverridden,
2016
+ TOperationOptioned | Extract<keyof TOptions, string>
2017
+ >;
2018
+ }
2019
+
1967
2020
  /**
1968
2021
  * Builds and returns the complete set of integrations.
1969
2022
  *
@@ -1978,6 +2031,10 @@ export class IntegrationBuilder<
1978
2031
  */
1979
2032
  public build(): TIntegrations {
1980
2033
  const options = this.options;
2034
+ const buildOptionsFor = (op: string): TDefaultIntegrationProps => ({
2035
+ ...options.defaultIntegrationOptions,
2036
+ ...this.perOperationOptions[op],
2037
+ });
1981
2038
  return {
1982
2039
  ...Object.fromEntries(
1983
2040
  options.pattern === 'shared'
@@ -1986,7 +2043,7 @@ export class IntegrationBuilder<
1986
2043
  '$router',
1987
2044
  options.buildDefaultIntegration(
1988
2045
  '$router',
1989
- options.defaultIntegrationOptions,
2046
+ buildOptionsFor('$router'),
1990
2047
  ),
1991
2048
  ],
1992
2049
  ]
@@ -1997,10 +2054,7 @@ export class IntegrationBuilder<
1997
2054
  )
1998
2055
  .map((op) => [
1999
2056
  op,
2000
- options.buildDefaultIntegration(
2001
- op,
2002
- options.defaultIntegrationOptions,
2003
- ),
2057
+ options.buildDefaultIntegration(op, buildOptionsFor(op)),
2004
2058
  ]),
2005
2059
  ),
2006
2060
  ...this.integrations,
@@ -2708,6 +2762,8 @@ export type ApiIntegrations<TOperation extends string, TBaseIntegration> =
2708
2762
  * @template TDefaultIntegrationProps - Type for default integration properties
2709
2763
  * @template TDefaultIntegration - Type for default integration implementation
2710
2764
  * @template TPattern - The integration pattern ('shared' or 'isolated')
2765
+ * @template TOverridden - Union of operation names that have been overridden
2766
+ * @template TOperationOptioned - Union of operation names with per-operation options
2711
2767
  */
2712
2768
  export class IntegrationBuilder<
2713
2769
  TOperation extends string,
@@ -2716,6 +2772,8 @@ export class IntegrationBuilder<
2716
2772
  TDefaultIntegrationProps extends object,
2717
2773
  TDefaultIntegration extends TBaseIntegration,
2718
2774
  TPattern extends 'shared' | 'isolated',
2775
+ TOverridden extends string = never,
2776
+ TOperationOptioned extends string = never,
2719
2777
  > {
2720
2778
  /** Options for the integration builder */
2721
2779
  private options: IntegrationBuilderProps<
@@ -2728,6 +2786,11 @@ export class IntegrationBuilder<
2728
2786
  /** Map of operation names to their custom integrations */
2729
2787
  private integrations: Partial<TIntegrations> = {};
2730
2788
 
2789
+ /** Map of default integration keys to per-operation default option overrides */
2790
+ private perOperationOptions: Partial<
2791
+ Record<string, Partial<TDefaultIntegrationProps>>
2792
+ > = {};
2793
+
2731
2794
  /**
2732
2795
  * Create an Integration Builder for an HTTP API with a shared pattern
2733
2796
  */
@@ -2882,11 +2945,16 @@ export class IntegrationBuilder<
2882
2945
  /**
2883
2946
  * Overrides default integrations with custom implementations for specific operations.
2884
2947
  *
2948
+ * Operations which have per-operation options set via withOperationOptions cannot be
2949
+ * overridden, since these still use the default integration.
2950
+ *
2885
2951
  * @param overrides - Map of operation names to their custom integration implementations
2886
2952
  * @returns The builder instance with updated type information reflecting the overrides
2887
2953
  */
2888
2954
  public withOverrides<
2889
- TOverrideIntegrations extends Partial<Record<TOperation, TBaseIntegration>>,
2955
+ TOverrideIntegrations extends Partial<
2956
+ Record<Exclude<TOperation, TOperationOptioned>, TBaseIntegration>
2957
+ >,
2890
2958
  >(overrides: TOverrideIntegrations) {
2891
2959
  this.integrations = { ...this.integrations, ...overrides };
2892
2960
  // Re-type to include the overridden integration types.
@@ -2902,7 +2970,9 @@ export class IntegrationBuilder<
2902
2970
  MergedIntegrations,
2903
2971
  TDefaultIntegrationProps,
2904
2972
  TDefaultIntegration,
2905
- TPattern
2973
+ TPattern,
2974
+ TOverridden | Extract<keyof TOverrideIntegrations, string>,
2975
+ TOperationOptioned
2906
2976
  >;
2907
2977
  }
2908
2978
 
@@ -2921,6 +2991,43 @@ export class IntegrationBuilder<
2921
2991
  return this;
2922
2992
  }
2923
2993
 
2994
+ /**
2995
+ * Updates the default integration options for specific operations, without
2996
+ * affecting the others. The given options are merged with the defaults (and
2997
+ * any options set via withDefaultOptions) when building each default integration.
2998
+ *
2999
+ * Operations which have been replaced via withOverrides cannot be targeted, since
3000
+ * they no longer use the default integration.
3001
+ *
3002
+ * @param options - Map of operation names to partial default integration options
3003
+ * @returns The builder instance
3004
+ */
3005
+ public withOperationOptions<
3006
+ TOptions extends Partial<
3007
+ Record<
3008
+ Exclude<DefaultIntegrationKeys<TPattern, TOperation>, TOverridden>,
3009
+ Partial<TDefaultIntegrationProps>
3010
+ >
3011
+ >,
3012
+ >(options: TOptions) {
3013
+ Object.entries(options).forEach(([op, opOptions]) => {
3014
+ this.perOperationOptions[op] = {
3015
+ ...this.perOperationOptions[op],
3016
+ ...(opOptions as Partial<TDefaultIntegrationProps>),
3017
+ };
3018
+ });
3019
+ return this as unknown as IntegrationBuilder<
3020
+ TOperation,
3021
+ TBaseIntegration,
3022
+ TIntegrations,
3023
+ TDefaultIntegrationProps,
3024
+ TDefaultIntegration,
3025
+ TPattern,
3026
+ TOverridden,
3027
+ TOperationOptioned | Extract<keyof TOptions, string>
3028
+ >;
3029
+ }
3030
+
2924
3031
  /**
2925
3032
  * Builds and returns the complete set of integrations.
2926
3033
  *
@@ -2935,6 +3042,10 @@ export class IntegrationBuilder<
2935
3042
  */
2936
3043
  public build(): TIntegrations {
2937
3044
  const options = this.options;
3045
+ const buildOptionsFor = (op: string): TDefaultIntegrationProps => ({
3046
+ ...options.defaultIntegrationOptions,
3047
+ ...this.perOperationOptions[op],
3048
+ });
2938
3049
  return {
2939
3050
  ...Object.fromEntries(
2940
3051
  options.pattern === 'shared'
@@ -2943,7 +3054,7 @@ export class IntegrationBuilder<
2943
3054
  '$router',
2944
3055
  options.buildDefaultIntegration(
2945
3056
  '$router',
2946
- options.defaultIntegrationOptions,
3057
+ buildOptionsFor('$router'),
2947
3058
  ),
2948
3059
  ],
2949
3060
  ]
@@ -2954,10 +3065,7 @@ export class IntegrationBuilder<
2954
3065
  )
2955
3066
  .map((op) => [
2956
3067
  op,
2957
- options.buildDefaultIntegration(
2958
- op,
2959
- options.defaultIntegrationOptions,
2960
- ),
3068
+ options.buildDefaultIntegration(op, buildOptionsFor(op)),
2961
3069
  ]),
2962
3070
  ),
2963
3071
  ...this.integrations,
@@ -148,6 +148,8 @@ export type ApiIntegrations<TOperation extends string, TBaseIntegration> =
148
148
  * @template TDefaultIntegrationProps - Type for default integration properties
149
149
  * @template TDefaultIntegration - Type for default integration implementation
150
150
  * @template TPattern - The integration pattern ('shared' or 'isolated')
151
+ * @template TOverridden - Union of operation names that have been overridden
152
+ * @template TOperationOptioned - Union of operation names with per-operation options
151
153
  */
152
154
  export class IntegrationBuilder<
153
155
  TOperation extends string,
@@ -156,6 +158,8 @@ export class IntegrationBuilder<
156
158
  TDefaultIntegrationProps extends object,
157
159
  TDefaultIntegration extends TBaseIntegration,
158
160
  TPattern extends 'shared' | 'isolated',
161
+ TOverridden extends string = never,
162
+ TOperationOptioned extends string = never,
159
163
  > {
160
164
  /** Options for the integration builder */
161
165
  private options: IntegrationBuilderProps<
@@ -168,6 +172,11 @@ export class IntegrationBuilder<
168
172
  /** Map of operation names to their custom integrations */
169
173
  private integrations: Partial<TIntegrations> = {};
170
174
 
175
+ /** Map of default integration keys to per-operation default option overrides */
176
+ private perOperationOptions: Partial<
177
+ Record<string, Partial<TDefaultIntegrationProps>>
178
+ > = {};
179
+
171
180
  /**
172
181
  * Create an Integration Builder for an HTTP API with a shared pattern
173
182
  */
@@ -322,11 +331,16 @@ export class IntegrationBuilder<
322
331
  /**
323
332
  * Overrides default integrations with custom implementations for specific operations.
324
333
  *
334
+ * Operations which have per-operation options set via withOperationOptions cannot be
335
+ * overridden, since these still use the default integration.
336
+ *
325
337
  * @param overrides - Map of operation names to their custom integration implementations
326
338
  * @returns The builder instance with updated type information reflecting the overrides
327
339
  */
328
340
  public withOverrides<
329
- TOverrideIntegrations extends Partial<Record<TOperation, TBaseIntegration>>,
341
+ TOverrideIntegrations extends Partial<
342
+ Record<Exclude<TOperation, TOperationOptioned>, TBaseIntegration>
343
+ >,
330
344
  >(overrides: TOverrideIntegrations) {
331
345
  this.integrations = { ...this.integrations, ...overrides };
332
346
  // Re-type to include the overridden integration types.
@@ -342,7 +356,9 @@ export class IntegrationBuilder<
342
356
  MergedIntegrations,
343
357
  TDefaultIntegrationProps,
344
358
  TDefaultIntegration,
345
- TPattern
359
+ TPattern,
360
+ TOverridden | Extract<keyof TOverrideIntegrations, string>,
361
+ TOperationOptioned
346
362
  >;
347
363
  }
348
364
 
@@ -361,6 +377,43 @@ export class IntegrationBuilder<
361
377
  return this;
362
378
  }
363
379
 
380
+ /**
381
+ * Updates the default integration options for specific operations, without
382
+ * affecting the others. The given options are merged with the defaults (and
383
+ * any options set via withDefaultOptions) when building each default integration.
384
+ *
385
+ * Operations which have been replaced via withOverrides cannot be targeted, since
386
+ * they no longer use the default integration.
387
+ *
388
+ * @param options - Map of operation names to partial default integration options
389
+ * @returns The builder instance
390
+ */
391
+ public withOperationOptions<
392
+ TOptions extends Partial<
393
+ Record<
394
+ Exclude<DefaultIntegrationKeys<TPattern, TOperation>, TOverridden>,
395
+ Partial<TDefaultIntegrationProps>
396
+ >
397
+ >,
398
+ >(options: TOptions) {
399
+ Object.entries(options).forEach(([op, opOptions]) => {
400
+ this.perOperationOptions[op] = {
401
+ ...this.perOperationOptions[op],
402
+ ...(opOptions as Partial<TDefaultIntegrationProps>),
403
+ };
404
+ });
405
+ return this as unknown as IntegrationBuilder<
406
+ TOperation,
407
+ TBaseIntegration,
408
+ TIntegrations,
409
+ TDefaultIntegrationProps,
410
+ TDefaultIntegration,
411
+ TPattern,
412
+ TOverridden,
413
+ TOperationOptioned | Extract<keyof TOptions, string>
414
+ >;
415
+ }
416
+
364
417
  /**
365
418
  * Builds and returns the complete set of integrations.
366
419
  *
@@ -375,6 +428,10 @@ export class IntegrationBuilder<
375
428
  */
376
429
  public build(): TIntegrations {
377
430
  const options = this.options;
431
+ const buildOptionsFor = (op: string): TDefaultIntegrationProps => ({
432
+ ...options.defaultIntegrationOptions,
433
+ ...this.perOperationOptions[op],
434
+ });
378
435
  return {
379
436
  ...Object.fromEntries(
380
437
  options.pattern === 'shared'
@@ -383,7 +440,7 @@ export class IntegrationBuilder<
383
440
  '$router',
384
441
  options.buildDefaultIntegration(
385
442
  '$router',
386
- options.defaultIntegrationOptions,
443
+ buildOptionsFor('$router'),
387
444
  ),
388
445
  ],
389
446
  ]
@@ -394,10 +451,7 @@ export class IntegrationBuilder<
394
451
  )
395
452
  .map((op) => [
396
453
  op,
397
- options.buildDefaultIntegration(
398
- op,
399
- options.defaultIntegrationOptions,
400
- ),
454
+ options.buildDefaultIntegration(op, buildOptionsFor(op)),
401
455
  ]),
402
456
  ),
403
457
  ...this.integrations,