From 60f20762f190e594ea7ebda577d79549e6f4545c Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 4 Jun 2025 14:47:24 +0200 Subject: [PATCH 1/2] feat(javascript): add `exactOptionalPropertyTypes` to tsconfig --- .../src/createIterablePromise.ts | 2 +- .../src/logger/createNullLogger.ts | 6 ++-- .../client-common/src/transporter/errors.ts | 4 +-- .../client-common/src/transporter/helpers.ts | 2 +- .../packages/client-common/src/types/cache.ts | 8 +++--- .../client-common/src/types/createClient.ts | 2 +- .../src/types/createIterablePromise.ts | 2 +- .../packages/client-common/src/types/host.ts | 2 +- .../client-common/src/types/logger.ts | 6 ++-- .../client-common/src/types/requester.ts | 8 +++--- .../client-common/src/types/transporter.ts | 10 +++---- .../algoliasearch/builds/definition.mustache | 8 +++--- .../javascript/clients/api-single.mustache | 4 +-- .../clients/client/api/helpers.mustache | 28 +++++++++---------- .../clients/client/api/hosts.mustache | 4 +-- .../clients/client/api/nodeHelpers.mustache | 2 +- .../legacySearchCompatible/model.mustache | 4 +-- .../client/api/operation/parameters.mustache | 2 +- .../clients/client/builds/definition.mustache | 4 +-- .../client/model/clientMethodProps.mustache | 16 +++++------ .../client/model/types/dataType.mustache | 3 ++ templates/javascript/clients/model.mustache | 2 +- .../javascript/clients/tsconfig.mustache | 3 +- 23 files changed, 68 insertions(+), 64 deletions(-) diff --git a/clients/algoliasearch-client-javascript/packages/client-common/src/createIterablePromise.ts b/clients/algoliasearch-client-javascript/packages/client-common/src/createIterablePromise.ts index c9ba843d28..fc86f3dd34 100644 --- a/clients/algoliasearch-client-javascript/packages/client-common/src/createIterablePromise.ts +++ b/clients/algoliasearch-client-javascript/packages/client-common/src/createIterablePromise.ts @@ -17,7 +17,7 @@ export function createIterablePromise({ error, timeout = (): number => 0, }: CreateIterablePromise): Promise { - const retry = (previousResponse?: TResponse): Promise => { + const retry = (previousResponse?: TResponse | undefined): Promise => { return new Promise((resolve, reject) => { func(previousResponse) .then(async (response) => { diff --git a/clients/algoliasearch-client-javascript/packages/client-common/src/logger/createNullLogger.ts b/clients/algoliasearch-client-javascript/packages/client-common/src/logger/createNullLogger.ts index 68c5f3d765..b9a1672a57 100644 --- a/clients/algoliasearch-client-javascript/packages/client-common/src/logger/createNullLogger.ts +++ b/clients/algoliasearch-client-javascript/packages/client-common/src/logger/createNullLogger.ts @@ -2,13 +2,13 @@ import type { Logger } from '../types/logger'; export function createNullLogger(): Logger { return { - debug(_message: string, _args?: any): Promise { + debug(_message: string, _args?: any | undefined): Promise { return Promise.resolve(); }, - info(_message: string, _args?: any): Promise { + info(_message: string, _args?: any | undefined): Promise { return Promise.resolve(); }, - error(_message: string, _args?: any): Promise { + error(_message: string, _args?: any | undefined): Promise { return Promise.resolve(); }, }; diff --git a/clients/algoliasearch-client-javascript/packages/client-common/src/transporter/errors.ts b/clients/algoliasearch-client-javascript/packages/client-common/src/transporter/errors.ts index 60b93cd2ab..b109e04de0 100644 --- a/clients/algoliasearch-client-javascript/packages/client-common/src/transporter/errors.ts +++ b/clients/algoliasearch-client-javascript/packages/client-common/src/transporter/errors.ts @@ -76,12 +76,12 @@ export type DetailedErrorWithMessage = { export type DetailedErrorWithTypeID = { id: string; type: string; - name?: string; + name?: string | undefined; }; export type DetailedError = { code: string; - details?: DetailedErrorWithMessage[] | DetailedErrorWithTypeID[]; + details?: DetailedErrorWithMessage[] | DetailedErrorWithTypeID[] | undefined; }; // DetailedApiError is only used by the ingestion client to return more informative error, other clients will use ApiClient. diff --git a/clients/algoliasearch-client-javascript/packages/client-common/src/transporter/helpers.ts b/clients/algoliasearch-client-javascript/packages/client-common/src/transporter/helpers.ts index 25cd25ae68..96e0716e5a 100644 --- a/clients/algoliasearch-client-javascript/packages/client-common/src/transporter/helpers.ts +++ b/clients/algoliasearch-client-javascript/packages/client-common/src/transporter/helpers.ts @@ -56,7 +56,7 @@ export function serializeData(request: Request, requestOptions: RequestOptions): export function serializeHeaders( baseHeaders: Headers, requestHeaders: Headers, - requestOptionsHeaders?: Headers, + requestOptionsHeaders?: Headers | undefined, ): Headers { const headers: Headers = { Accept: 'application/json', diff --git a/clients/algoliasearch-client-javascript/packages/client-common/src/types/cache.ts b/clients/algoliasearch-client-javascript/packages/client-common/src/types/cache.ts index 6a7e9fff1a..a04b1ea040 100644 --- a/clients/algoliasearch-client-javascript/packages/client-common/src/types/cache.ts +++ b/clients/algoliasearch-client-javascript/packages/client-common/src/types/cache.ts @@ -5,7 +5,7 @@ export type Cache = { get: ( key: Record | string, defaultValue: () => Promise, - events?: CacheEvents, + events?: CacheEvents | undefined, ) => Promise; /** @@ -35,7 +35,7 @@ export type MemoryCacheOptions = { /** * If keys and values should be serialized using `JSON.stringify`. */ - serializable?: boolean; + serializable?: boolean | undefined; }; export type BrowserLocalStorageOptions = { @@ -47,12 +47,12 @@ export type BrowserLocalStorageOptions = { /** * The time to live for each cached item in seconds. */ - timeToLive?: number; + timeToLive?: number | undefined; /** * The native local storage implementation. */ - localStorage?: Storage; + localStorage?: Storage | undefined; }; export type BrowserLocalStorageCacheItem = { diff --git a/clients/algoliasearch-client-javascript/packages/client-common/src/types/createClient.ts b/clients/algoliasearch-client-javascript/packages/client-common/src/types/createClient.ts index 1238b9a08a..102f1b446b 100644 --- a/clients/algoliasearch-client-javascript/packages/client-common/src/types/createClient.ts +++ b/clients/algoliasearch-client-javascript/packages/client-common/src/types/createClient.ts @@ -8,7 +8,7 @@ export type CreateClientOptions = Omit> & { appId: string; apiKey: string; - authMode?: AuthMode; + authMode?: AuthMode | undefined; algoliaAgents: AlgoliaAgentOptions[]; }; diff --git a/clients/algoliasearch-client-javascript/packages/client-common/src/types/createIterablePromise.ts b/clients/algoliasearch-client-javascript/packages/client-common/src/types/createIterablePromise.ts index 62178b9e14..ffe84bd6fb 100644 --- a/clients/algoliasearch-client-javascript/packages/client-common/src/types/createIterablePromise.ts +++ b/clients/algoliasearch-client-javascript/packages/client-common/src/types/createIterablePromise.ts @@ -31,7 +31,7 @@ export type CreateIterablePromise = IterableOptions & { * * The `previousResponse` parameter (`undefined` on the first call) allows you to build your request with incremental logic, to iterate on `page` or `cursor` for example. */ - func: (previousResponse?: TResponse) => Promise; + func: (previousResponse?: TResponse | undefined) => Promise; /** * The validator function. It receive the resolved return of the API call. diff --git a/clients/algoliasearch-client-javascript/packages/client-common/src/types/host.ts b/clients/algoliasearch-client-javascript/packages/client-common/src/types/host.ts index ba0ab05247..f079b48273 100644 --- a/clients/algoliasearch-client-javascript/packages/client-common/src/types/host.ts +++ b/clients/algoliasearch-client-javascript/packages/client-common/src/types/host.ts @@ -17,7 +17,7 @@ export type Host = { /** * The port of the host URL. */ - port?: number; + port?: number | undefined; }; export type StatefulHost = Host & { diff --git a/clients/algoliasearch-client-javascript/packages/client-common/src/types/logger.ts b/clients/algoliasearch-client-javascript/packages/client-common/src/types/logger.ts index 77e866392c..298f9ec6e8 100644 --- a/clients/algoliasearch-client-javascript/packages/client-common/src/types/logger.ts +++ b/clients/algoliasearch-client-javascript/packages/client-common/src/types/logger.ts @@ -10,15 +10,15 @@ export type Logger = { /** * Logs debug messages. */ - debug: (message: string, args?: any) => Promise; + debug: (message: string, args?: any | undefined) => Promise; /** * Logs info messages. */ - info: (message: string, args?: any) => Promise; + info: (message: string, args?: any | undefined) => Promise; /** * Logs error messages. */ - error: (message: string, args?: any) => Promise; + error: (message: string, args?: any | undefined) => Promise; }; diff --git a/clients/algoliasearch-client-javascript/packages/client-common/src/types/requester.ts b/clients/algoliasearch-client-javascript/packages/client-common/src/types/requester.ts index ae8ce160dc..cac5a0ec3a 100644 --- a/clients/algoliasearch-client-javascript/packages/client-common/src/types/requester.ts +++ b/clients/algoliasearch-client-javascript/packages/client-common/src/types/requester.ts @@ -14,18 +14,18 @@ export type Request = { */ path: string; queryParameters: QueryParameters; - data?: Array> | Record; + data?: Array> | Record | undefined; headers: Headers; /** * If the given request should persist on the cache. Keep in mind, * that some methods may have this option enabled by default. */ - cacheable?: boolean; + cacheable?: boolean | undefined; /** * Some POST methods in the Algolia REST API uses the `read` transporter. * This information is defined at the spec level. */ - useReadTransporter?: boolean; + useReadTransporter?: boolean | undefined; }; export type EndRequest = Pick & { @@ -41,7 +41,7 @@ export type EndRequest = Pick & { * The response timeout, in milliseconds. */ responseTimeout: number; - data?: string; + data?: string | undefined; }; export type Response = { diff --git a/clients/algoliasearch-client-javascript/packages/client-common/src/types/transporter.ts b/clients/algoliasearch-client-javascript/packages/client-common/src/types/transporter.ts index b0614f58ed..c1733bdfc5 100644 --- a/clients/algoliasearch-client-javascript/packages/client-common/src/types/transporter.ts +++ b/clients/algoliasearch-client-javascript/packages/client-common/src/types/transporter.ts @@ -9,25 +9,25 @@ export type RequestOptions = Pick & { * the given timeout will be applied. But the transporter layer may * increase this timeout if there is need for it. */ - timeouts?: Partial; + timeouts?: Partial | undefined; /** * Custom headers for the request. This headers are * going to be merged the transporter headers. */ - headers?: Headers; + headers?: Headers | undefined; /** * Custom query parameters for the request. This query parameters are * going to be merged the transporter query parameters. */ - queryParameters?: QueryParameters; + queryParameters?: QueryParameters | undefined; /** * Custom data for the request. This data is * going to be merged the transporter data. */ - data?: Array> | Record; + data?: Array> | Record | undefined; }; export type StackFrame = { @@ -46,7 +46,7 @@ export type AlgoliaAgentOptions = { /** * The version. Usually the integration version. */ - version?: string; + version?: string | undefined; }; export type AlgoliaAgent = { diff --git a/templates/javascript/clients/algoliasearch/builds/definition.mustache b/templates/javascript/clients/algoliasearch/builds/definition.mustache index 72cc59995f..be0d440cff 100644 --- a/templates/javascript/clients/algoliasearch/builds/definition.mustache +++ b/templates/javascript/clients/algoliasearch/builds/definition.mustache @@ -42,7 +42,7 @@ export type Algoliasearch = SearchClient & { * @param saveObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable. * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions. */ - saveObjectsWithTransformation: (options: SaveObjectsOptions, requestOptions?: RequestOptions) => Promise; + saveObjectsWithTransformation: (options: SaveObjectsOptions, requestOptions?: RequestOptions | undefined) => Promise; /** * Helper: Similar to the `partialUpdateObjects` method but requires a Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/) to be created first, in order to transform records before indexing them to Algolia. The `region` must've been passed to the client instantiation method. @@ -56,7 +56,7 @@ export type Algoliasearch = SearchClient & { * @param partialUpdateObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable. * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions. */ - partialUpdateObjectsWithTransformation: (options: PartialUpdateObjectsOptions, requestOptions?: RequestOptions) => Promise; + partialUpdateObjectsWithTransformation: (options: PartialUpdateObjectsOptions, requestOptions?: RequestOptions | undefined) => Promise; }; export type TransformationOptions = { @@ -64,13 +64,13 @@ export type TransformationOptions = { transformation?: { // The region of your Algolia application ID, used to target the correct hosts of the transformation service. region: IngestionRegion; - }; + } | undefined; }; export function algoliasearch( appId: string, apiKey: string, - options?: ClientOptions & TransformationOptions, + options?: ClientOptions & TransformationOptions | undefined, ): Algoliasearch { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); diff --git a/templates/javascript/clients/api-single.mustache b/templates/javascript/clients/api-single.mustache index 5062c57cd5..e4ff19d3ab 100644 --- a/templates/javascript/clients/api-single.mustache +++ b/templates/javascript/clients/api-single.mustache @@ -75,7 +75,7 @@ export function create{{#lambda.titlecase}}{{clientName}}{{/lambda.titlecase}}({ * @param segment - The algolia agent (user-agent) segment to add. * @param version - The version of the agent. */ - addAlgoliaAgent(segment: string, version?: string): void { + addAlgoliaAgent(segment: string, version?: string | undefined): void { transporter.algoliaAgent.add({ segment, version }); }, @@ -182,4 +182,4 @@ export function create{{#lambda.titlecase}}{{clientName}}{{/lambda.titlecase}}({ }; } -{{/operations}} +{{/operations}} \ No newline at end of file diff --git a/templates/javascript/clients/client/api/helpers.mustache b/templates/javascript/clients/client/api/helpers.mustache index 7cb260944c..eb781bc99c 100644 --- a/templates/javascript/clients/client/api/helpers.mustache +++ b/templates/javascript/clients/client/api/helpers.mustache @@ -18,7 +18,7 @@ waitForTask( timeout = (retryCount: number): number => Math.min(retryCount * 200, 5000), }: WaitForTaskOptions, - requestOptions?: RequestOptions + requestOptions?: RequestOptions | undefined ): Promise { let retryCount = 0; @@ -52,7 +52,7 @@ waitForAppTask( timeout = (retryCount: number): number => Math.min(retryCount * 200, 5000), }: WaitForAppTaskOptions, - requestOptions?: RequestOptions + requestOptions?: RequestOptions | undefined ): Promise { let retryCount = 0; @@ -90,7 +90,7 @@ waitForApiKey( timeout = (retryCount: number): number => Math.min(retryCount * 200, 5000), }: WaitForApiKeyOptions, - requestOptions?: RequestOptions + requestOptions?: RequestOptions | undefined ): Promise { let retryCount = 0; const baseIteratorOptions: IterableOptions< @@ -167,7 +167,7 @@ browseObjects( browseParams, ...browseObjectsOptions }: BrowseOptions> & BrowseProps, - requestOptions?: RequestOptions + requestOptions?: RequestOptions | undefined ): Promise> { return createIterablePromise>({ func: (previousResponse) => { @@ -205,11 +205,11 @@ browseRules( searchRulesParams, ...browseRulesOptions }: BrowseOptions & SearchRulesProps, - requestOptions?: RequestOptions + requestOptions?: RequestOptions | undefined ): Promise { const params = { - hitsPerPage: 1000, ...searchRulesParams, + hitsPerPage: searchRulesParams?.hitsPerPage || 1000, }; return createIterablePromise({ @@ -249,11 +249,11 @@ browseSynonyms( searchSynonymsParams, ...browseSynonymsOptions }: BrowseOptions & SearchSynonymsProps, - requestOptions?: RequestOptions + requestOptions?: RequestOptions | undefined ): Promise { const params = { - page: 0, ...searchSynonymsParams, + page: searchSynonymsParams?.page || 0, hitsPerPage: 1000, }; @@ -324,7 +324,7 @@ async chunkedBatch({ indexName, objects, action = 'addObject', waitForTasks, bat */ async saveObjects( { indexName, objects, waitForTasks, batchSize }: SaveObjectsOptions, - requestOptions?: RequestOptions + requestOptions?: RequestOptions | undefined ): Promise { return await this.chunkedBatch( { indexName, objects, action: 'addObject', waitForTasks, batchSize }, @@ -345,7 +345,7 @@ async saveObjects( */ async deleteObjects( { indexName, objectIDs, waitForTasks, batchSize }: DeleteObjectsOptions, - requestOptions?: RequestOptions + requestOptions?: RequestOptions | undefined ): Promise { return await this.chunkedBatch( { @@ -373,7 +373,7 @@ async deleteObjects( */ async partialUpdateObjects( { indexName, objects, createIfNotExists, waitForTasks, batchSize }: PartialUpdateObjectsOptions, - requestOptions?: RequestOptions + requestOptions?: RequestOptions | undefined ): Promise { return await this.chunkedBatch( { @@ -403,7 +403,7 @@ async partialUpdateObjects( */ async replaceAllObjects( { indexName, objects, batchSize, scopes }: ReplaceAllObjectsOptions, - requestOptions?: RequestOptions + requestOptions?: RequestOptions | undefined ): Promise { const randomSuffix = Math.floor(Math.random() * 1000000) + 100000; const tmpIndexName = `${indexName}_tmp_${randomSuffix}`; @@ -495,7 +495,7 @@ async indexExists({ indexName }: GetSettingsProps): Promise { */ searchForHits( searchMethodParams: LegacySearchMethodProps | SearchMethodParams, - requestOptions?: RequestOptions + requestOptions?: RequestOptions | undefined ): Promise<{results: Array>}> { return this.search(searchMethodParams, requestOptions) as Promise<{results: Array>}>; }, @@ -510,7 +510,7 @@ searchForHits( */ searchForFacets( searchMethodParams: LegacySearchMethodProps | SearchMethodParams, - requestOptions?: RequestOptions + requestOptions?: RequestOptions | undefined ): Promise<{results: Array}> { return this.search(searchMethodParams, requestOptions) as Promise<{results: Array}>; }, \ No newline at end of file diff --git a/templates/javascript/clients/client/api/hosts.mustache b/templates/javascript/clients/client/api/hosts.mustache index 8f201a1b3c..345c9fc1ca 100644 --- a/templates/javascript/clients/client/api/hosts.mustache +++ b/templates/javascript/clients/client/api/hosts.mustache @@ -1,7 +1,7 @@ {{#hasRegionalHost}} export const REGIONS = [{{#allowedRegions}}'{{.}}'{{^-last}},{{/-last}}{{/allowedRegions}}] as const; export type Region = (typeof REGIONS)[number]; -export type RegionOptions = {region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}: Region }; +export type RegionOptions = {region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}: Region{{#fallbackToAliasHost}}|undefined{{/fallbackToAliasHost}}}; {{/hasRegionalHost}} {{^hasRegionalHost}} @@ -53,7 +53,7 @@ function getDefaultHosts({{#hostWithAppID}}appId: string{{/hostWithAppID}}): Hos {{/hasRegionalHost}} {{#hasRegionalHost}} -function getDefaultHosts(region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}: Region): Host[] { +function getDefaultHosts(region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}: Region{{#fallbackToAliasHost}}|undefined{{/fallbackToAliasHost}}): Host[] { const url = {{#fallbackToAliasHost}}!region ? '{{{hostWithFallback}}}' : {{/fallbackToAliasHost}} '{{{regionalHost}}}'.replace('{region}', region); return [{ url, accept: 'readWrite', protocol: 'https' }]; diff --git a/templates/javascript/clients/client/api/nodeHelpers.mustache b/templates/javascript/clients/client/api/nodeHelpers.mustache index 083fd1f403..9aa1017361 100644 --- a/templates/javascript/clients/client/api/nodeHelpers.mustache +++ b/templates/javascript/clients/client/api/nodeHelpers.mustache @@ -49,7 +49,7 @@ generateSecuredApiKey: ({ */ async accountCopyIndex( { sourceIndexName, destinationAppID, destinationApiKey, destinationIndexName }: AccountCopyIndexOptions, - requestOptions?: RequestOptions, + requestOptions?: RequestOptions | undefined, ): Promise { const responses: Array<{ taskID: UpdatedAtResponse['taskID'] }> = []; diff --git a/templates/javascript/clients/client/api/operation/legacySearchCompatible/model.mustache b/templates/javascript/clients/client/api/operation/legacySearchCompatible/model.mustache index bd35b303d2..e43f042a3e 100644 --- a/templates/javascript/clients/client/api/operation/legacySearchCompatible/model.mustache +++ b/templates/javascript/clients/client/api/operation/legacySearchCompatible/model.mustache @@ -4,7 +4,7 @@ * @deprecated The `search` method now accepts flat `searchParams` at the root of the method. */ type LegacySearchParams = { - params?: SearchParamsObject; + params?: SearchParamsObject | undefined; }; /** @@ -28,4 +28,4 @@ type LegacySearchQuery = LegacySearchForFacets | LegacySearchForHits; * * @deprecated This signature will be removed from the next major version, we recommend using the `SearchMethodParams` type for performances and future proof reasons. */ -export type LegacySearchMethodProps = LegacySearchQuery[]; +export type LegacySearchMethodProps = LegacySearchQuery[]; \ No newline at end of file diff --git a/templates/javascript/clients/client/api/operation/parameters.mustache b/templates/javascript/clients/client/api/operation/parameters.mustache index 523892e5cd..e8ea2e477c 100644 --- a/templates/javascript/clients/client/api/operation/parameters.mustache +++ b/templates/javascript/clients/client/api/operation/parameters.mustache @@ -8,4 +8,4 @@ {{/bodyParams}} {{/x-is-single-body-param}} {{/vendorExtensions}} -requestOptions{{^hasParams}}?{{/hasParams}}{{#hasParams}}{{#hasRequiredParams}}?{{/hasRequiredParams}}{{/hasParams}}: RequestOptions{{#hasParams}}{{^hasRequiredParams}} | undefined = undefined{{/hasRequiredParams}}{{/hasParams}} +requestOptions{{^hasParams}}?{{/hasParams}}{{#hasParams}}{{#hasRequiredParams}}?{{/hasRequiredParams}}{{/hasParams}}: RequestOptions{{#hasParams}}{{^hasRequiredParams}} | undefined = undefined{{/hasRequiredParams}}{{/hasParams}}{{^hasParams}} | undefined{{/hasParams}} \ No newline at end of file diff --git a/templates/javascript/clients/client/builds/definition.mustache b/templates/javascript/clients/client/builds/definition.mustache index b3e41bd74a..6750f1a7cd 100644 --- a/templates/javascript/clients/client/builds/definition.mustache +++ b/templates/javascript/clients/client/builds/definition.mustache @@ -53,8 +53,8 @@ import type { export function {{clientName}}( appId: string, - apiKey: string,{{#hasRegionalHost}}region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}: Region,{{/hasRegionalHost}} - options?: ClientOptions + apiKey: string,{{#hasRegionalHost}}region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}: Region{{#fallbackToAliasHost}} | undefined {{/fallbackToAliasHost}},{{/hasRegionalHost}} + options?: ClientOptions | undefined ): {{#lambda.titlecase}}{{clientName}}{{/lambda.titlecase}} { if (!appId || typeof appId !== 'string') { throw new Error("`appId` is missing."); diff --git a/templates/javascript/clients/client/model/clientMethodProps.mustache b/templates/javascript/clients/client/model/clientMethodProps.mustache index 904c463d16..8400fc8e3b 100644 --- a/templates/javascript/clients/client/model/clientMethodProps.mustache +++ b/templates/javascript/clients/client/model/clientMethodProps.mustache @@ -33,7 +33,7 @@ export type {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props{{#x-has- * {{{description}}} */ {{/description}} - {{paramName}}{{^required}}?{{/required}}: {{#vendorExtensions.x-is-generic}}T{{/vendorExtensions.x-is-generic}}{{^vendorExtensions.x-is-generic}}{{{dataType}}}{{/vendorExtensions.x-is-generic}}; + {{paramName}}{{^required}}?{{/required}}: {{#vendorExtensions.x-is-generic}}T{{/vendorExtensions.x-is-generic}}{{^vendorExtensions.x-is-generic}}{{{dataType}}}{{/vendorExtensions.x-is-generic}}{{^required}}|undefined{{/required}}; {{/allParams}} } {{/x-create-wrapping-object}} @@ -117,7 +117,7 @@ export type GenerateSecuredApiKeyOptions = { /** * A set of properties defining the restrictions of the secured API key. */ - restrictions?: SecuredApiKeyRestrictions; + restrictions?: SecuredApiKeyRestrictions | undefined; } export type GetSecuredApiKeyRemainingValidityOptions = { @@ -148,7 +148,7 @@ export type PartialUpdateObjectsOptions = Pick< /** *To be provided if non-existing objects are passed, otherwise, the call will fail. */ - createIfNotExists?: boolean; + createIfNotExists?: boolean | undefined; }; export type SaveObjectsOptions = Pick< @@ -160,12 +160,12 @@ export type ChunkedBatchOptions = ReplaceAllObjectsOptions & { /** * The `batch` `action` to perform on the given array of `objects`, defaults to `addObject`. */ - action?: Action; + action?: Action | undefined; /** * Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable. */ - waitForTasks?: boolean; + waitForTasks?: boolean | undefined; } export type ReplaceAllObjectsOptions = { @@ -182,12 +182,12 @@ export type ReplaceAllObjectsOptions = { /** * The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000. */ - batchSize?: number; + batchSize?: number | undefined; /** * The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms']. */ - scopes?: Array; + scopes?: Array | undefined; } export type AccountCopyIndexOptions = { @@ -218,7 +218,7 @@ export type WaitForCompositionTaskOptions = { /** * The maximum number of retries. 50 by default. */ - maxRetries?: number; + maxRetries?: number | undefined; /** * The function to decide how long to wait between retries. diff --git a/templates/javascript/clients/client/model/types/dataType.mustache b/templates/javascript/clients/client/model/types/dataType.mustache index efd9013cca..dea93449a4 100644 --- a/templates/javascript/clients/client/model/types/dataType.mustache +++ b/templates/javascript/clients/client/model/types/dataType.mustache @@ -17,4 +17,7 @@ {{#isNullable}} | null {{/isNullable}} + {{^required}} + | undefined + {{/required}} {{/isEnum}} \ No newline at end of file diff --git a/templates/javascript/clients/model.mustache b/templates/javascript/clients/model.mustache index 453d2bfc09..2823470a23 100644 --- a/templates/javascript/clients/model.mustache +++ b/templates/javascript/clients/model.mustache @@ -34,7 +34,7 @@ export type {{classname}}{{> client/model/types/isGeneric}} = {{^vendorExtension */{{/description}} {{name}}{{^required}}?{{/required}}: {{> client/model/types/dataType}} ; {{/vars}} -} {{#x-is-SearchForHitsOptions}} & { facet?: never; maxFacetHits?: never; facetQuery?: never }; {{/x-is-SearchForHitsOptions}} +} {{#x-is-SearchForHitsOptions}} & { facet?: never | undefined; maxFacetHits?: never | undefined; facetQuery?: never | undefined}; {{/x-is-SearchForHitsOptions}} {{/vendorExtensions}} {{/isEnum}} {{#hasEnums}}{{#vars}}{{#isEnum}}export type {{classname}}{{nameInCamelCase}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}|{{/-last}}{{/enumVars}}{{/allowableValues}}{{/isEnum}}{{/vars}}{{/hasEnums}} diff --git a/templates/javascript/clients/tsconfig.mustache b/templates/javascript/clients/tsconfig.mustache index 845995826f..f8c516f004 100644 --- a/templates/javascript/clients/tsconfig.mustache +++ b/templates/javascript/clients/tsconfig.mustache @@ -4,7 +4,8 @@ {{#isAlgoliasearchClient}} "types": ["node", "@cloudflare/workers-types", "@cloudflare/vitest-pool-workers", "vitest/globals"], {{/isAlgoliasearchClient}} - "outDir": "dist" + "outDir": "dist", + "exactOptionalPropertyTypes": true }, "include": ["{{apiPackage}}", "model", "builds"], "exclude": ["dist", "node_modules"] From f3cb9011eac58c88bacf03ec03a41b371f33e7a4 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 4 Jun 2025 15:04:51 +0200 Subject: [PATCH 2/2] chore: enforce common pkgs as well --- .../packages/logger-console/src/logger.ts | 6 +++--- .../packages/requester-fetch/src/createFetchRequester.ts | 2 +- .../packages/requester-testing/src/createEchoRequester.ts | 4 ++-- clients/algoliasearch-client-javascript/tsconfig.json | 7 ++++--- templates/javascript/clients/tsconfig.mustache | 3 +-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clients/algoliasearch-client-javascript/packages/logger-console/src/logger.ts b/clients/algoliasearch-client-javascript/packages/logger-console/src/logger.ts index 974796ca0e..5bed071bda 100644 --- a/clients/algoliasearch-client-javascript/packages/logger-console/src/logger.ts +++ b/clients/algoliasearch-client-javascript/packages/logger-console/src/logger.ts @@ -3,7 +3,7 @@ import { LogLevelEnum } from '@algolia/client-common'; export function createConsoleLogger(logLevel: LogLevelType): Logger { return { - debug(message: string, args?: any): Readonly> { + debug(message: string, args?: any | undefined): Readonly> { if (LogLevelEnum.Debug >= logLevel) { console.debug(message, args); } @@ -11,7 +11,7 @@ export function createConsoleLogger(logLevel: LogLevelType): Logger { return Promise.resolve(); }, - info(message: string, args?: any): Readonly> { + info(message: string, args?: any | undefined): Readonly> { if (LogLevelEnum.Info >= logLevel) { console.info(message, args); } @@ -19,7 +19,7 @@ export function createConsoleLogger(logLevel: LogLevelType): Logger { return Promise.resolve(); }, - error(message: string, args?: any): Readonly> { + error(message: string, args?: any | undefined): Readonly> { console.error(message, args); return Promise.resolve(); diff --git a/clients/algoliasearch-client-javascript/packages/requester-fetch/src/createFetchRequester.ts b/clients/algoliasearch-client-javascript/packages/requester-fetch/src/createFetchRequester.ts index df66e7bbb9..c797794b68 100644 --- a/clients/algoliasearch-client-javascript/packages/requester-fetch/src/createFetchRequester.ts +++ b/clients/algoliasearch-client-javascript/packages/requester-fetch/src/createFetchRequester.ts @@ -12,7 +12,7 @@ function getErrorMessage(error: unknown, abortContent: string): string { } export type FetchRequesterOptions = { - readonly requesterOptions?: RequestInit; + readonly requesterOptions?: RequestInit | undefined; }; export function createFetchRequester({ requesterOptions = {} }: FetchRequesterOptions = {}): Requester { diff --git a/clients/algoliasearch-client-javascript/packages/requester-testing/src/createEchoRequester.ts b/clients/algoliasearch-client-javascript/packages/requester-testing/src/createEchoRequester.ts index 7eb8c66610..308a944ead 100644 --- a/clients/algoliasearch-client-javascript/packages/requester-testing/src/createEchoRequester.ts +++ b/clients/algoliasearch-client-javascript/packages/requester-testing/src/createEchoRequester.ts @@ -4,7 +4,7 @@ export type EchoResponse = Omit & Pick & { host: string; algoliaAgent: string; - searchParams?: Record; + searchParams?: Record | undefined; }; type BasicURL = { @@ -15,7 +15,7 @@ type BasicURL = { export type EchoRequesterParams = { getURL: (url: string) => BasicURL; - status?: number; + status?: number | undefined; }; function getUrlParams({ diff --git a/clients/algoliasearch-client-javascript/tsconfig.json b/clients/algoliasearch-client-javascript/tsconfig.json index c5d1e1c914..9befe28d71 100644 --- a/clients/algoliasearch-client-javascript/tsconfig.json +++ b/clients/algoliasearch-client-javascript/tsconfig.json @@ -1,16 +1,16 @@ { "compilerOptions": { "allowJs": false, - "verbatimModuleSyntax": true, "allowSyntheticDefaultImports": true, "declaration": true, "esModuleInterop": true, + "exactOptionalPropertyTypes": true, "lib": ["dom", "esnext", "dom.iterable", "scripthost"], "module": "esnext", "moduleResolution": "node", "noImplicitAny": true, - "noImplicitThis": true, "noImplicitOverride": true, + "noImplicitThis": true, "noLib": false, "noUnusedLocals": true, "outDir": "dist", @@ -18,7 +18,8 @@ "sourceMap": true, "strict": true, "target": "esnext", - "types": ["node"] + "types": ["node"], + "verbatimModuleSyntax": true }, "include": ["packages/**/*.ts"], "exclude": ["dist", "node_modules"] diff --git a/templates/javascript/clients/tsconfig.mustache b/templates/javascript/clients/tsconfig.mustache index f8c516f004..845995826f 100644 --- a/templates/javascript/clients/tsconfig.mustache +++ b/templates/javascript/clients/tsconfig.mustache @@ -4,8 +4,7 @@ {{#isAlgoliasearchClient}} "types": ["node", "@cloudflare/workers-types", "@cloudflare/vitest-pool-workers", "vitest/globals"], {{/isAlgoliasearchClient}} - "outDir": "dist", - "exactOptionalPropertyTypes": true + "outDir": "dist" }, "include": ["{{apiPackage}}", "model", "builds"], "exclude": ["dist", "node_modules"]