Skip to content

Commit

Permalink
chore: types running with v4 locally, but also v4 and v3 (#6271)
Browse files Browse the repository at this point in the history
* chore: change type

* WIP: expand search parameters

doesn't work as there still are v4 v5 differences of course

* do it correctly

* use regular client

* not sure if this should stay

* WIP

* changes rule

* fix dependency

* change order to make script work

* almost all types fixed

* improve test

* fix(types): accepts client with wrong types

will be fixed once algolia/api-clients-automation#3357 is done

* tests

* chore(helper): compatibility

* chore(legacy): correct replacement

* don't remove v5 fully

* fix errors

* safer (or less safe lol)

* correct import

* fix fake type

* v5 only works

* tests

* script for examples too

* script for examples too

* chore(answers): bleh get rid of this!

* stuff

* simplify
  • Loading branch information
Haroenv committed Jul 17, 2024
1 parent f69228f commit 341d6de
Show file tree
Hide file tree
Showing 102 changed files with 869 additions and 441 deletions.
2 changes: 1 addition & 1 deletion examples/js/calendar-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"website:examples": "BABEL_ENV=parcel parcel build index.html --public-url . --dist-dir=../../../website/examples/js/calendar-widget"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"instantsearch.js": "4.73.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/js/e-commerce-umd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"browserslist": "firefox 68, chrome 78, IE 11",
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"instantsearch.js": "4.73.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/js/e-commerce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"browserslist": "firefox 68, chrome 78, IE 11",
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"instantsearch.js": "4.73.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/js/getting-started/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint:fix": "npm run lint -- --fix"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"instantsearch.js": "4.73.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/js/getting-started/products.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ <h1 class="header-title">
<div id="related-products"></div>
</div>

<script type="module" src="./src/products.js"></script>
<script type="module" src="./src/products.ts"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const searchParams = new URLSearchParams(document.location.search);

const pid = searchParams.get('pid');

if (!pid) {
throw new Error('No product ID provided');
}

const searchClient = algoliasearch(
'latency',
'6be0576ff61c053d5f9a3225e2a90f76'
Expand Down
2 changes: 1 addition & 1 deletion examples/js/media/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"website:examples": "BABEL_ENV=parcel parcel build index.html --public-url . --dist-dir=../../../website/examples/js/media"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"date-fns": "2.25.0",
"instantsearch.js": "4.73.2"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/js/tourism/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"website:examples": "BABEL_ENV=parcel parcel build index.html --public-url . --dist-dir=../../../website/examples/js/tourism"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"instantsearch.js": "4.73.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/react/default-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "BABEL_ENV=parcel parcel index.html"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"instantsearch.js": "4.73.2",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/e-commerce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"browserslist": "firefox 68, chrome 78, IE 11",
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"instantsearch.js": "4.73.2",
"react": "18.2.0",
"react-compound-slider": "3.4.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/getting-started/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "BABEL_ENV=parcel parcel index.html products.html --port 3000"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"instantsearch.js": "4.73.2",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/next-app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"instantsearch.css": "8.3.0",
"next": "13.5.1",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/next-routing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"instantsearch.css": "8.3.0",
"next": "13.5.1",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"instantsearch.css": "8.3.0",
"next": "13.5.1",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"eject": "expo eject"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"expo": "~44.0.0",
"expo-status-bar": "~1.2.0",
"instantsearch.js": "4.73.2",
Expand Down
4 changes: 2 additions & 2 deletions examples/react/react-native/src/Highlight.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Fragment } from 'react';
import { StyleSheet, Text } from 'react-native';
import { Hit as AlgoliaHit } from '@algolia/client-search';
import { Hit as AlgoliaHit } from 'instantsearch.js';
import {
getHighlightedParts,
getPropertyByPath,
Expand All @@ -26,7 +26,7 @@ type HighlightProps<THit> = {
separator?: string;
};

export function Highlight<THit extends AlgoliaHit<Record<string, unknown>>>({
export function Highlight<THit extends AlgoliaHit>({
hit,
attribute,
separator = ', ',
Expand Down
2 changes: 1 addition & 1 deletion examples/react/react-native/src/InfiniteHits.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { forwardRef } from 'react';
import { StyleSheet, View, FlatList } from 'react-native';
import { Hit as AlgoliaHit } from '@algolia/client-search';
import { Hit as AlgoliaHit } from 'instantsearch.js';
import {
useInfiniteHits,
UseInfiniteHitsProps,
Expand Down
2 changes: 1 addition & 1 deletion examples/react/react-native/types/ProductHit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hit as AlgoliaHit } from '@algolia/client-search';
import { Hit as AlgoliaHit } from 'instantsearch.js';

export type ProductHit = AlgoliaHit<{
brand: string;
Expand Down
2 changes: 1 addition & 1 deletion examples/react/ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"webpack-node-externals": "1.7.2"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"express": "4.17.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/default-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"website:examples": "NODE_OPTIONS=--openssl-legacy-provider vue-cli-service build --dest ../../../website/examples/vue/default-theme"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"core-js": "2",
"instantsearch.js": "4.73.2",
"vue": "2.7.14",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/e-commerce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"website:examples": "NODE_OPTIONS=--openssl-legacy-provider vue-cli-service build --dest ../../../website/examples/vue/e-commerce"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"core-js": "2",
"instantsearch.js": "4.73.2",
"vue": "2.7.14",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/getting-started/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "NODE_OPTIONS=--openssl-legacy-provider vue-cli-service build"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"core-js": "2",
"instantsearch.js": "4.73.2",
"vue": "2.7.14",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/media/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"website:examples": "NODE_OPTIONS=--openssl-legacy-provider vue-cli-service build --dest ../../../website/examples/vue/media"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"core-js": "2",
"instantsearch.js": "4.73.2",
"vue": "2.7.14",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"generate": "nuxt generate"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"cross-env": "^5.2.0",
"css-loader": "^4.3.0",
"nuxt": "^2.4.5",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start": "NODE_ENV=production NODE_OPTIONS=--openssl-legacy-provider vue-cli-service ssr:serve --mode production"
},
"dependencies": {
"algoliasearch": "5.0.0-beta.8",
"algoliasearch": "5.0.0-beta.9",
"core-js": "2",
"instantsearch.css": "8.3.0",
"qs": "6.9.7",
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"devDependencies": {
"@algolia/cache-common": "4.23.2",
"@algolia/cache-in-memory": "4.23.2",
"@algolia/client-search": "4.23.2",
"@algolia/client-search": "5.0.0-beta.9",
"@algolia/client-common": "5.0.0-beta.10",
"@algolia/logger-common": "4.23.2",
"@algolia/requester-node-http": "4.23.2",
"@algolia/transporter": "4.23.2",
Expand Down Expand Up @@ -87,9 +88,10 @@
"@wdio/selenium-standalone-service": "5.16.5",
"@wdio/spec-reporter": "5.16.5",
"@wdio/static-server-service": "5.16.5",
"algoliasearch": "4.23.2",
"algoliasearch-v3": "npm:algoliasearch@3.35.0",
"algoliasearch-v5": "npm:algoliasearch@5.0.0-beta.8",
"algoliasearch-v4": "npm:algoliasearch@4.23.2",
"algoliasearch-v5": "npm:algoliasearch@5.0.0-beta.9",
"algoliasearch": "5.0.0-beta.9",
"babel-eslint": "10.1.0",
"babel-jest": "27.4.6",
"babel-plugin-inline-replace-variables": "1.3.1",
Expand Down Expand Up @@ -145,6 +147,7 @@
"typescript": "5.5.2"
},
"resolutions": {
"places.js/algoliasearch": "5.0.0-beta.9",
"brotli-size": "4.0.0",
"webpack": "4.47.0",
"babel-loader": "8.2.2"
Expand Down
48 changes: 14 additions & 34 deletions packages/algoliasearch-helper/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import EventEmitter from '@algolia/events';

// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import type {
FindAnswersResponse,
FrequentlyBoughtTogetherQuery,
HighlightResult,
LookingSimilarQuery,
RankingInfo,
RecommendResponse,
RelatedProductsQuery,
SearchClient,
SearchOptions,
SearchResponse,
SnippetResult,
SupportedLanguage,
TrendingFacetsQuery,
TrendingItemsQuery,
PlainRecommendParameters as ClientPlainRecommendParameters,
} from './types/algoliasearch';
// @ts-ignore
import type {
FrequentlyBoughtTogetherQuery as RecommendFrequentlyBoughtTogetherQuery,
LookingSimilarQuery as RecommendLookingSimilarQuery,
RelatedProductsQuery as RecommendRelatedProductsQuery,
TrendingFacetsQuery as RecommendTrendingFacetsQuery,
TrendingItemsQuery as RecommendTrendingItemsQuery,
RecommendQueriesResponse,
} from '@algolia/recommend';

/**
* The algoliasearchHelper module is the function that will let its
Expand Down Expand Up @@ -539,7 +539,7 @@ declare namespace algoliasearchHelper {
// types missing in @types/algoliasearch, so duplicated from v4
ruleContexts?: string[];
optionalFilters?: Array<string | string[]>;
queryLanguages?: string[];
queryLanguages?: SupportedLanguage[];

/**
* The relevancy threshold to apply to search in a virtual index [0-100]. A bigger
Expand Down Expand Up @@ -1021,7 +1021,7 @@ declare namespace algoliasearchHelper {
* a list of language ISO codes (as a comma-separated string) for which stop words should be enable
* https://www.algolia.com/doc/api-reference/api-parameters/removeStopWords/
*/
removeStopWords?: boolean | string[];
removeStopWords?: boolean | SupportedLanguage[];
/**
* List of attributes on which you want to disable the computation of exact criteria
* default: []
Expand Down Expand Up @@ -1555,23 +1555,7 @@ declare namespace algoliasearchHelper {
}
}

// We remove `indexName` from the Recommend query types as the helper
// will fill in this value before sending the queries
type FrequentlyBoughtTogetherQuery = Omit<
RecommendFrequentlyBoughtTogetherQuery,
'indexName'
>;
type LookingSimilarQuery = Omit<RecommendLookingSimilarQuery, 'indexName'>;
type RelatedProductsQuery = Omit<RecommendRelatedProductsQuery, 'indexName'>;
type TrendingFacetsQuery = Omit<RecommendTrendingFacetsQuery, 'indexName'>;
type TrendingItemsQuery = Omit<RecommendTrendingItemsQuery, 'indexName'>;

export type PlainRecommendParameters =
| FrequentlyBoughtTogetherQuery
| LookingSimilarQuery
| RelatedProductsQuery
| TrendingFacetsQuery
| TrendingItemsQuery;
export type PlainRecommendParameters = ClientPlainRecommendParameters;

export type RecommendParametersWithId<
T extends PlainRecommendParameters = PlainRecommendParameters
Expand Down Expand Up @@ -1605,19 +1589,15 @@ declare namespace algoliasearchHelper {
): RecommendParameters;
}

type RecommendResponse<TObject> =
RecommendQueriesResponse<TObject>['results'];

type RecommendResultItem<TObject = any> = RecommendResponse<TObject>[0];
type RecommendResultMap<T> = { [index: number]: RecommendResultItem<T> };
type RecommendResultMap<T> = { [index: number]: RecommendResponse<T> };

export class RecommendResults<T = any> {
constructor(state: RecommendParameters, results: RecommendResultMap<T>);

_state: RecommendParameters;
_rawResults: RecommendResultMap<T>;

[index: number]: RecommendResultItem<T>;
[index: number]: RecommendResponse<T>;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if (require.main === module) {
path.join(__dirname.replace('datasets', 'spec'), 'getFacetValues')
);
var algoliasearch = require('algoliasearch');
algoliasearch = algoliasearch.algoliasearch || algoliasearch;

var client = algoliasearch('latency', '6be0576ff61c053d5f9a3225e2a90f76');
var helper = new HelperSaver(client, 'instant_search', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if (require.main === module) {
path.join(__dirname.replace('datasets', 'spec'), 'getRefinements')
);
var algoliasearch = require('algoliasearch');
algoliasearch = algoliasearch.algoliasearch || algoliasearch;

var client = algoliasearch('latency', '6be0576ff61c053d5f9a3225e2a90f76');
var helper = new HelperSaver(client, 'instant_search', {
Expand Down
1 change: 1 addition & 0 deletions packages/algoliasearch-helper/test/integration-utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var algoliasearch = require('algoliasearch');
algoliasearch = algoliasearch.algoliasearch || algoliasearch;

function setup(indexName, fn) {
var appID = process.env.INTEGRATION_TEST_APPID;
Expand Down
1 change: 1 addition & 0 deletions packages/algoliasearch-helper/test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var path = require('path');

var algoliasearch = require('algoliasearch');
algoliasearch = algoliasearch.algoliasearch || algoliasearch;
var jest = require('jest');

var staticJestConfig = require('../jest.config');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var algoliasearch = require('algoliasearch');
algoliasearch = algoliasearch.algoliasearch || algoliasearch;

var algoliaSearchHelper = require('../../../');
var version = require('../../../src/version');
Expand Down
Loading

0 comments on commit 341d6de

Please sign in to comment.