···11-import { fileURLToPath } from 'node:url';
22-33-import { createVitestConfig } from '@config/vite-base';
44-55-export default createVitestConfig(fileURLToPath(new URL('./', import.meta.url)), {
66- // Add specific configuration here if needed
77-});
-43
packages/config-vite-base/README.md
···11-# @config/vite-base
22-33-Base configuration for Vite and Vitest.
44-55-## Installation
66-77-```bash
88-pnpm add -D @config/vite-base
99-```
1010-1111-## Usage
1212-1313-To use the base configuration in your vitest.config.ts:
1414-1515-```ts
1616-// vitest.config.ts
1717-import { createVitestConfig } from '@config/vite-base';
1818-1919-export default createVitestConfig({
2020- // Your specific configuration
2121-});
2222-```
2323-2424-## Implementation
2525-2626-To complete the implementation of this package in the workspace:
2727-2828-1. Build the package:
2929-3030- ```bash
3131- cd packages/configs/vite-base
3232- pnpm install
3333- pnpm build
3434- ```
3535-3636-2. Add it as a dependency to your packages:
3737-3838- ```bash
3939- cd <your-package>
4040- pnpm add -D @config/vite-base@workspace:*
4141- ```
4242-4343-3. Update your vitest.config.ts and vite.config.ts files to use the base configurations.
···5959} from './ir/parameter';
6060export { deduplicateSchema } from './ir/schema';
6161export type { IR } from './ir/types';
6262+export type { SchemaExtractor, SchemaExtractorContext } from './ir/utils';
6363+export { addItemsToSchema, createSchemaExtractor, inlineSchema } from './ir/utils';
6264export { parseOpenApiSpec } from './openApi';
6365export type { OpenApiV2_0_X, OpenApiV2_0_XTypes } from './openApi/2.0.x';
6466export { parseV2_0_X } from './openApi/2.0.x';
+35
packages/shared/src/ir/utils.ts
···11+import { pathToJsonPointer } from '../utils/ref';
12import type { IR } from './types';
2334/**
···4243 schema.items = items;
4344 return schema;
4445}
4646+4747+export type SchemaExtractorContext = {
4848+ path: ReadonlyArray<string | number>;
4949+ schema: IR.SchemaObject;
5050+};
5151+5252+export type SchemaExtractor = (ctx: SchemaExtractorContext) => IR.SchemaObject;
5353+5454+export const inlineSchema: SchemaExtractor = (ctx) => ctx.schema;
5555+5656+export function createSchemaExtractor({
5757+ callback,
5858+ shouldExtract,
5959+}: {
6060+ /** Called when a schema should be extracted. Should call irSchemaToAst with the provided path to extract the schema and register the symbol. */
6161+ callback: (ctx: SchemaExtractorContext) => void;
6262+ /** Determines whether a schema at a given path should be extracted. */
6363+ shouldExtract: (ctx: SchemaExtractorContext) => boolean;
6464+}): SchemaExtractor {
6565+ // track pointers to prevent infinite recursion
6666+ const extractedPointers = new Set<string>();
6767+6868+ const extractor: SchemaExtractor = (ctx) => {
6969+ const pointer = pathToJsonPointer(ctx.path);
7070+ if (extractedPointers.has(pointer) || !shouldExtract(ctx)) {
7171+ return ctx.schema;
7272+ }
7373+ extractedPointers.add(pointer);
7474+ callback(ctx);
7575+ return { $ref: pointer };
7676+ };
7777+7878+ return extractor;
7979+}
···2525 type: Extract<IrTopLevelKind, 'operation'>;
2626 }
2727 | {
2828+ /** Name of the parameter (e.g., "id" for a parameter defined as "#/components/parameters/id"). */
2829 name: string;
2930 parameter: IR.ParameterObject;
3031 type: Extract<IrTopLevelKind, 'parameter'>;
3132 }
3233 | {
3434+ /** Name of the request body (e.g., "CreateUserRequest" for a request body defined as "#/components/requestBodies/CreateUserRequest"). */
3335 name: string;
3436 requestBody: IR.RequestBodyObject;
3537 type: Extract<IrTopLevelKind, 'requestBody'>;
3638 }
3739 | {
4040+ /** Name of the schema (e.g., "User" for a schema defined as "#/components/schemas/User"). */
3841 name: string;
3942 schema: IR.SchemaObject;
4043 type: Extract<IrTopLevelKind, 'schema'>;
-7
packages/shared/vitest.config.ts
···11-import { fileURLToPath } from 'node:url';
22-33-import { createVitestConfig } from '@config/vite-base';
44-55-export default createVitestConfig(fileURLToPath(new URL('./', import.meta.url)), {
66- // Add specific configuration here if needed
77-});