Skip to content

Commit

Permalink
[search] Precise Typechecking (Azure#32160)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR
- @azure/search-documents

### Issues associated with this PR
N/A

### Describe the problem that is addressed by this PR
Tests are not being typechecked and linting isn't configured correctly.
This PR migrates those libraries to precise typechecking setup
introduced in Azure#31786

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?

### Are there test cases added in this PR? _(If not, why?)_
N/A

### Provide a list of related PRs _(if any)_
Azure#31786

### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [x] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
deyaaeldeen authored Dec 12, 2024
1 parent fc1786f commit 2e4f955
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 50 deletions.
13 changes: 5 additions & 8 deletions sdk/search/search-documents/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ import azsdkEslint from "@azure/eslint-plugin-azure-sdk";

export default azsdkEslint.config([
{
ignores: ["src/shims.d.ts"],
},
{
files: ["samples-dev/**/*.ts"],
rules: {
"@azure/azure-sdk/ts-naming-options": "warn",
// Suppresses errors for the custom TSDoc syntax we use for docs
"tsdoc/syntax": "off",
files: ["**/*.ts", "**/*.cts", "**/*.mts"],
languageOptions: {
parserOptions: {
project: ["./tsconfig.test.json", "./tsconfig.samples.json"],
},
},
},
]);
5 changes: 3 additions & 2 deletions sdk/search/search-documents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"generate:embeddings": "ts-node scripts/generateSampleEmbeddings.ts",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"integration-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
"integration-test:node": "dev-tool run test:vitest",
"integration-test:node": "dev-tool run test:vitest --esm",
"lint": "eslint package.json api-extractor.json src test samples-dev",
"lint:fix": "eslint package.json api-extractor.json src test samples-dev --fix --fix-type [problem,suggestion]",
"pack": "npm pack 2>&1",
Expand Down Expand Up @@ -133,7 +133,8 @@
"browser",
"react-native"
],
"selfLink": false
"selfLink": false,
"project": "./tsconfig.src.json"
},
"exports": {
"./package.json": "./package.json",
Expand Down
1 change: 0 additions & 1 deletion sdk/search/search-documents/samples-dev/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export function delay(timeInMs: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, timeInMs));
}

// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters
export async function createIndex(client: SearchIndexClient, name: string): Promise<void> {
const hotelIndex: SearchIndex = {
name,
Expand Down
2 changes: 0 additions & 2 deletions sdk/search/search-documents/src/serviceModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1443,12 +1443,10 @@ export enum KnownTokenizerNames {
/**
* Divides text using language-specific rules.
*/
// eslint-disable-next-line @typescript-eslint/no-shadow
MicrosoftLanguageTokenizer = "microsoft_language_tokenizer",
/**
* Divides text using language-specific rules and reduces words to their base forms.
*/
// eslint-disable-next-line @typescript-eslint/no-shadow
MicrosoftLanguageStemmingTokenizer = "microsoft_language_stemming_tokenizer",
/**
* Tokenizes the input into n-grams of the given size(s). See
Expand Down
2 changes: 1 addition & 1 deletion sdk/search/search-documents/src/serviceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ export function generatedVectorSearchVectorizerToPublicVectorizer(
return vectorizer;
},
};
const defaultDeserializer = () => {
const defaultDeserializer = (): any => {
logger.warning(`Unsupported vectorizer kind: ${(generatedVectorizer as any).kind}`);
return generatedVectorizer as any;
};
Expand Down
2 changes: 0 additions & 2 deletions sdk/search/search-documents/test/narrowedTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
// Licensed under the MIT License.

/* eslint-disable no-unused-expressions */
/* eslint-disable no-constant-condition */
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable @typescript-eslint/no-unused-vars */

import type { SelectFields } from "../src/index.js";
import { SearchClient } from "../src/index.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ describe("SearchClient", { timeout: 20_000 }, () => {
assert.deepEqual(["1"], resultIds);
});

it("search with vector", async () => {
it("search with vector", async (ctx) => {
// This live test is disabled due to temporary limitations with the new OpenAI service
if (isLiveMode()) {
ctx.skip();
Expand Down Expand Up @@ -563,7 +563,7 @@ describe("SearchClient", { timeout: 20_000 }, () => {
assert.deepEqual(resultIds, ["1", "3", "4"]);
});

it("multi-vector search", async () => {
it("multi-vector search", async (ctx) => {
// This live test is disabled due to temporary limitations with the new OpenAI service
if (isLiveMode()) {
ctx.skip();
Expand Down Expand Up @@ -603,7 +603,7 @@ describe("SearchClient", { timeout: 20_000 }, () => {
assert.deepEqual(resultIds, ["1", "3", "4"]);
});

it("oversampling compressed vectors", async () => {
it("oversampling compressed vectors", async (ctx) => {
// This live test is disabled due to temporary limitations with the new OpenAI service
if (isLiveMode()) {
ctx.skip();
Expand Down
2 changes: 0 additions & 2 deletions sdk/search/search-documents/test/public/typeDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/* eslint-disable @typescript-eslint/no-unused-vars */

import type {
KnownSemanticErrorMode,
KnownSemanticErrorReason,
Expand Down
6 changes: 0 additions & 6 deletions sdk/search/search-documents/test/public/utils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { assert } from "vitest";

export const WAIT_TIME = isPlaybackMode() ? 0 : 4000;

// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters
export async function createIndex(
client: SearchIndexClient,
name: string,
Expand Down Expand Up @@ -344,7 +343,6 @@ export async function createIndex(
return client.createIndex(hotelIndex);
}

// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters
export async function populateIndex(
client: SearchClient<Hotel>,
openAIClient: OpenAIClient,
Expand Down Expand Up @@ -585,14 +583,12 @@ async function addVectorDescriptions(
});
}

// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters
export async function deleteDataSourceConnections(client: SearchIndexerClient): Promise<void> {
for (let i = 1; i <= 2; i++) {
await client.deleteDataSourceConnection(`my-data-source-${i}`);
}
}

// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters
export async function createSkillsets(client: SearchIndexerClient): Promise<void> {
const testCaseNames: string[] = ["my-azureblob-skillset-1", "my-azureblob-skillset-2"];
const skillSetNames: string[] = await client.listSkillsetsNames();
Expand Down Expand Up @@ -644,14 +640,12 @@ export async function createSkillsets(client: SearchIndexerClient): Promise<void
}
}

// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters
export async function deleteSkillsets(client: SearchIndexerClient): Promise<void> {
for (let i = 1; i <= 2; i++) {
await client.deleteSkillset(`my-azureblob-skillset-${i}`);
}
}

// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters
export async function createIndexers(
client: SearchIndexerClient,
targetIndexName: string,
Expand Down
8 changes: 3 additions & 5 deletions sdk/search/search-documents/tsconfig.browser.config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"extends": "./.tshy/build.json",
"include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"],
"exclude": ["./test/**/node/**/*.ts"],
"extends": ["./tsconfig.test.json"],
"exclude": ["./test/**/node", "./test/stress", "./test/snippets.spec.ts"],
"compilerOptions": {
"outDir": "./dist-test/browser",
"rootDir": ".",
"skipLibCheck": true
"noEmit": false
}
}
24 changes: 6 additions & 18 deletions sdk/search/search-documents/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"paths": {
"@azure/search-documents": ["./src/index"]
},
"skipLibCheck": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "."
},
"include": [
"src/**/*.ts",
"src/**/*.mts",
"src/**/*.cts",
"samples-dev/**/*.ts",
"test/**/*.ts",
"test/**/*.mts",
"test/**/*.cts"
]
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
],
"files": []
}
14 changes: 14 additions & 0 deletions sdk/search/search-documents/tsconfig.samples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"paths": {
"@azure/openai": ["./dist/esm"]
},
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noEmit": true,
"composite": true
},
"include": ["./samples-dev"]
}
3 changes: 3 additions & 0 deletions sdk/search/search-documents/tsconfig.src.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.lib.json"
}
9 changes: 9 additions & 0 deletions sdk/search/search-documents/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": ["./tsconfig.src.json"],
"compilerOptions": {
"skipLibCheck": true,
"target": "ES2022",
"noEmit": true
},
"include": ["./test", "./src"]
}
5 changes: 5 additions & 0 deletions sdk/search/search-documents/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default mergeConfig(
include: ["test/**/*.spec.ts"],
hookTimeout: 5000000,
testTimeout: 5000000,
typecheck: {
enabled: true,
tsconfig: "tsconfig.test.json",
include: ["test/**/*.ts", "test/**/*.mts", "test/**/*.cts"],
},
},
}),
);
11 changes: 11 additions & 0 deletions sdk/search/search-documents/vitest.esm.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { mergeConfig } from "vitest/config";
import vitestConfig from "./vitest.config.ts";
import vitestEsmConfig from "../../../vitest.esm.shared.config.ts";

export default mergeConfig(
vitestConfig,
vitestEsmConfig
);

0 comments on commit 2e4f955

Please sign in to comment.