Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): fix missing type exports #1284

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions api-extractor.json
@@ -1,40 +1,32 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",

"apiReport": {
"enabled": false
},

"docModel": {
"enabled": false
},

"dtsRollup": {
"enabled": true
},

"tsdocMetadata": {
"enabled": false
},

"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "warning"
}
},

"extractorMessageReporting": {
"default": {
"logLevel": "warning",
"addToApiReportFile": true
},

"ae-missing-release-tag": {
"logLevel": "none"
}
},

"tsdocMessageReporting": {
"default": {
"logLevel": "warning"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -33,7 +33,7 @@
"@babel/core": "7.8.7",
"@babel/preset-env": "7.8.7",
"@babel/preset-typescript": "7.8.3",
"@microsoft/api-extractor": "7.7.8",
"@microsoft/api-extractor": "7.18.7",
"@rollup/plugin-alias": "3.0.1",
"@rollup/plugin-json": "4.0.2",
"@rollup/plugin-node-resolve": "7.1.1",
Expand Down Expand Up @@ -92,7 +92,7 @@
"xhr-mock": "2.5.1"
},
"engines": {
"node": ">= 8.0.0",
"node": ">= 12.0.0",
"yarn": ">= 1.6.0"
},
"bundlesize": [
Expand Down
39 changes: 39 additions & 0 deletions packages/algoliasearch/src/builds/browserLite.ts
Expand Up @@ -29,6 +29,45 @@ import { createUserAgent, RequestOptions } from '@algolia/transporter';

import { AlgoliaSearchOptions } from '../types';

export {
MultipleQueriesOptions,
MultipleQueriesQuery,
MultipleQueriesResponse,
SearchClient as BaseSearchClient,
SearchClientOptions,
SearchForFacetValuesResponse,
SearchForFacetValuesQueryParams,
SearchIndex as BaseSearchIndex,
SearchOptions,
SearchResponse,
StrategyType,
ObjectWithObjectID,
FacetHit,
} from '@algolia/client-search';
export { AuthModeType, ClientTransporterOptions } from '@algolia/client-common';
export {
Headers,
HostOptions,
CallType,
QueryParameters,
Transporter,
TransporterOptions,
RequestOptions,
Timeouts,
UserAgent,
UserAgentOptions,
StatelessHost,
Request as TransporterRequest,
} from '@algolia/transporter';
export {
Request as RequesterRequest,
Response as RequesterResponse,
Requester,
MethodType,
} from '@algolia/requester-common';
export { Logger } from '@algolia/logger-common';
export { Cache, CacheEvents } from '@algolia/cache-common';

export default function algoliasearch(
appId: string,
apiKey: string,
Expand Down
42 changes: 40 additions & 2 deletions packages/algoliasearch/src/builds/node.ts
Expand Up @@ -196,6 +196,46 @@ import { createUserAgent, RequestOptions } from '@algolia/transporter';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just do export * from '@algolia/client-*' ?
Types listing seems unnecessary and hard to maintain + we would benefits from exporting helpers too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(for node.ts only obviously)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a good option, would you want to make a PR to take this over @bodinsamuel ? The only thing to be careful of with export * is that in some cases types are exported from JS files and then will have runtime errors when accessed directly from JS. I don't think that's really an issue here, but just to keep in mind

import { AlgoliaSearchOptions, InitAnalyticsOptions, InitPersonalizationOptions } from '../types';

// All exports
export * from '@algolia/cache-common';
export * from '@algolia/cache-in-memory';
export * from '@algolia/client-analytics';
export * from '@algolia/client-common';
export * from '@algolia/client-personalization';
export * from '@algolia/client-search';
export * from '@algolia/logger-common';
export * from '@algolia/requester-common';
export * from '@algolia/requester-node-http';
export * from '@algolia/cache-common';
export * from '@algolia/client-common';
export {
GetPersonalizationStrategyResponse,
PersonalizationStrategy,
RecommendationClient as BaseRecommendationClient,
RecommendationClientOptions,
SetPersonalizationStrategyResponse,
} from '@algolia/client-recommendation';
export {
RequestOptions,
Transporter,
TransporterOptions,
HostOptions,
Headers,
QueryParameters,
CallType,
Timeouts,
UserAgent,
UserAgentOptions,
StatelessHost,
Request as TransporterRequest,
} from '@algolia/transporter';

// To do: reup after eslint upgrade
// export * as recommendation from '@algolia/client-recommendation';
// export * as transporter from '@algolia/transporter';

export * from '../types';

export default function algoliasearch(
appId: string,
apiKey: string,
Expand Down Expand Up @@ -692,5 +732,3 @@ export type SearchClient = BaseSearchClient & {
*/
readonly initRecommendation: (options?: InitPersonalizationOptions) => PersonalizationClient;
} & Destroyable;

export * from '../types';
4 changes: 2 additions & 2 deletions packages/client-common/src/helpers.ts
Expand Up @@ -13,12 +13,12 @@ export function shuffle<TData>(array: TData[]): TData[] {
return array;
}

type Methods<TBase> = {
export type Methods<TBase> = {
// eslint-disable-next-line functional/prefer-readonly-type
readonly [key: string]: (base: TBase) => (...args: any[]) => any;
};

type AddedMethods<TBase, TMethods extends Methods<TBase>> = TBase &
export type AddedMethods<TBase, TMethods extends Methods<TBase>> = TBase &
{
[TKey in keyof TMethods extends string ? keyof TMethods : never]: ReturnType<TMethods[TKey]>;
};
Expand Down
@@ -1,5 +1,5 @@
import { serializeQueryParameters } from '@algolia/transporter';
import * as crypto from 'crypto';
import crypto from 'crypto';

import { SecuredApiKeyRestrictions } from '../..';

Expand Down
4 changes: 2 additions & 2 deletions packages/client-search/src/types/Hit.ts
@@ -1,4 +1,4 @@
type HighlightMatch = {
export type HighlightMatch = {
readonly value: string;
readonly matchLevel: 'none' | 'partial' | 'full';
readonly matchedWords: readonly string[];
Expand All @@ -11,7 +11,7 @@ export type HighlightResult<THit> = THit extends string | number
[KAttribute in keyof THit]?: HighlightResult<THit[KAttribute]>;
};

type SnippetMatch = {
export type SnippetMatch = {
readonly value: string;
readonly matchLevel: 'none' | 'partial' | 'full';
};
Expand Down
2 changes: 1 addition & 1 deletion packages/client-search/src/types/MultipleQueriesQuery.ts
@@ -1,6 +1,6 @@
import { SearchOptions } from '.';

type SharedMultipleQueriesQuery = {
export type SharedMultipleQueriesQuery = {
/**
* The type of query to perform.
*
Expand Down
1 change: 1 addition & 0 deletions packages/client-search/src/types/index.ts
Expand Up @@ -65,6 +65,7 @@ export * from './PartialUpdateObjectResponse';
export * from './PartialUpdateObjectsOptions';
export * from './RemoveUserIDResponse';
export * from './ReplaceAllObjectsOptions';
export * from './RequireAtLeastOne';
export * from './RestoreApiKeyResponse';
export * from './Rule';
export * from './SaveObjectResponse';
Expand Down
1 change: 1 addition & 0 deletions packages/recommend/src/builds/node.ts
Expand Up @@ -50,4 +50,5 @@ recommend.version = version;

export type RecommendClient = WithRecommendMethods<BaseRecommendClient> & Destroyable;

export * from '../methods';
export * from '../types';
@@ -1,7 +1,7 @@
import { BaseRecommendClient, FrequentlyBoughtTogetherQuery, WithRecommendMethods } from '../types';
import { getRecommendations } from './getRecommendations';

type GetFrequentlyBoughtTogether = (
export type GetFrequentlyBoughtTogether = (
base: BaseRecommendClient
) => WithRecommendMethods<BaseRecommendClient>['getFrequentlyBoughtTogether'];

Expand Down
2 changes: 1 addition & 1 deletion packages/recommend/src/methods/getRecommendations.ts
Expand Up @@ -2,7 +2,7 @@ import { MethodEnum } from '@algolia/requester-common';

import { BaseRecommendClient, RecommendationsQuery, WithRecommendMethods } from '../types';

type GetRecommendations = (
export type GetRecommendations = (
base: BaseRecommendClient
) => WithRecommendMethods<BaseRecommendClient>['getRecommendations'];

Expand Down
2 changes: 1 addition & 1 deletion packages/recommend/src/methods/getRelatedProducts.ts
@@ -1,7 +1,7 @@
import { BaseRecommendClient, RelatedProductsQuery, WithRecommendMethods } from '../types';
import { getRecommendations } from './getRecommendations';

type GetRelatedProducts = (
export type GetRelatedProducts = (
base: BaseRecommendClient
) => WithRecommendMethods<BaseRecommendClient>['getRelatedProducts'];

Expand Down
9 changes: 8 additions & 1 deletion scripts/build.js
Expand Up @@ -6,6 +6,8 @@ const execa = require('execa');

const targets = fs.readdirSync('packages').filter(f => fs.statSync(`packages/${f}`).isDirectory());

const bundledPackages = targets.map(target => `@algolia/${target}`);

run();

async function run() {
Expand Down Expand Up @@ -49,7 +51,12 @@ async function buildDefinition(target, config = '') {
pkgDir,
`api-extractor${config ? `-${config}` : ''}.json`
);
const extractorConfig = ExtractorConfig.loadFileAndPrepare(extractorConfigPath);

const extractorConfig = {
...ExtractorConfig.loadFileAndPrepare(extractorConfigPath),
bundledPackages: target === 'algoliasearch' ? bundledPackages : [],
};

const result = Extractor.invoke(extractorConfig, {
localBuild: true,
showVerboseMessages: true,
Expand Down