@mastra/schema-compat 0.0.0-ai-v5-20250729012312 → 0.0.0-ai-v5-20250801192614

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,281 @@
1
+ import type { Schema, LanguageModel } from 'ai';
2
+ import type { JSONSchema7 } from 'json-schema';
3
+ import { z, ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodDate, ZodDefault, ZodNull } from 'zod';
4
+ import type { ZodTypeAny } from 'zod';
5
+ import type { Targets } from 'zod-to-json-schema';
6
+ export type SchemaCompatModel = Exclude<LanguageModel, string>;
7
+ /**
8
+ * All supported string validation check types that can be processed or converted to descriptions.
9
+ * @constant
10
+ */
11
+ export declare const ALL_STRING_CHECKS: readonly ["regex", "emoji", "email", "url", "uuid", "cuid", "min", "max"];
12
+ /**
13
+ * All supported number validation check types that can be processed or converted to descriptions.
14
+ * @constant
15
+ */
16
+ export declare const ALL_NUMBER_CHECKS: readonly ["min", "max", "multipleOf"];
17
+ /**
18
+ * All supported array validation check types that can be processed or converted to descriptions.
19
+ * @constant
20
+ */
21
+ export declare const ALL_ARRAY_CHECKS: readonly ["min", "max", "length"];
22
+ export declare const isOptional: (v: ZodTypeAny) => v is ZodOptional<any>;
23
+ export declare const isObj: (v: ZodTypeAny) => v is ZodObject<any, any, any>;
24
+ export declare const isNull: (v: ZodTypeAny) => v is ZodNull;
25
+ export declare const isArr: (v: ZodTypeAny) => v is ZodArray<any, any>;
26
+ export declare const isUnion: (v: ZodTypeAny) => v is ZodUnion<[ZodTypeAny, ...ZodTypeAny[]]>;
27
+ export declare const isString: (v: ZodTypeAny) => v is ZodString;
28
+ export declare const isNumber: (v: ZodTypeAny) => v is ZodNumber;
29
+ export declare const isDate: (v: ZodTypeAny) => v is ZodDate;
30
+ export declare const isDefault: (v: ZodTypeAny) => v is ZodDefault<any>;
31
+ /**
32
+ * Zod types that are not supported by most AI model providers and should be avoided.
33
+ * @constant
34
+ */
35
+ export declare const UNSUPPORTED_ZOD_TYPES: readonly ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
36
+ /**
37
+ * Zod types that are generally supported by AI model providers.
38
+ * @constant
39
+ */
40
+ export declare const SUPPORTED_ZOD_TYPES: readonly ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber", "ZodDate", "ZodAny", "ZodDefault"];
41
+ /**
42
+ * All Zod types (both supported and unsupported).
43
+ * @constant
44
+ */
45
+ export declare const ALL_ZOD_TYPES: readonly ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber", "ZodDate", "ZodAny", "ZodDefault", "ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
46
+ /**
47
+ * Type representing string validation checks.
48
+ */
49
+ export type StringCheckType = (typeof ALL_STRING_CHECKS)[number];
50
+ /**
51
+ * Type representing number validation checks.
52
+ */
53
+ export type NumberCheckType = (typeof ALL_NUMBER_CHECKS)[number];
54
+ /**
55
+ * Type representing array validation checks.
56
+ */
57
+ export type ArrayCheckType = (typeof ALL_ARRAY_CHECKS)[number];
58
+ /**
59
+ * Type representing unsupported Zod schema types.
60
+ */
61
+ export type UnsupportedZodType = (typeof UNSUPPORTED_ZOD_TYPES)[number];
62
+ /**
63
+ * Type representing supported Zod schema types.
64
+ */
65
+ export type SupportedZodType = (typeof SUPPORTED_ZOD_TYPES)[number];
66
+ /**
67
+ * Type representing all Zod schema types (supported and unsupported).
68
+ */
69
+ export type AllZodType = (typeof ALL_ZOD_TYPES)[number];
70
+ /**
71
+ * Utility type to extract the shape of a Zod object schema.
72
+ */
73
+ export type ZodShape<T extends z.AnyZodObject> = T['shape'];
74
+ /**
75
+ * Utility type to extract the keys from a Zod object shape.
76
+ */
77
+ export type ShapeKey<T extends z.AnyZodObject> = keyof ZodShape<T>;
78
+ /**
79
+ * Utility type to extract the value types from a Zod object shape.
80
+ */
81
+ export type ShapeValue<T extends z.AnyZodObject> = ZodShape<T>[ShapeKey<T>];
82
+ type StringConstraints = {
83
+ minLength?: number;
84
+ maxLength?: number;
85
+ email?: boolean;
86
+ url?: boolean;
87
+ uuid?: boolean;
88
+ cuid?: boolean;
89
+ emoji?: boolean;
90
+ regex?: {
91
+ pattern: string;
92
+ flags?: string;
93
+ };
94
+ };
95
+ type NumberConstraints = {
96
+ gt?: number;
97
+ gte?: number;
98
+ lt?: number;
99
+ lte?: number;
100
+ multipleOf?: number;
101
+ };
102
+ type ArrayConstraints = {
103
+ minLength?: number;
104
+ maxLength?: number;
105
+ exactLength?: number;
106
+ };
107
+ type DateConstraints = {
108
+ minDate?: string;
109
+ maxDate?: string;
110
+ dateFormat?: string;
111
+ };
112
+ /**
113
+ * Abstract base class for creating schema compatibility layers for different AI model providers.
114
+ *
115
+ * This class provides a framework for transforming Zod schemas to work with specific AI model
116
+ * provider requirements and limitations. Each provider may have different support levels for
117
+ * JSON Schema features, validation constraints, and data types.
118
+ *
119
+ * @abstract
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * import { SchemaCompatLayer } from '@mastra/schema-compat';
124
+ * import type { LanguageModelV1 } from 'ai';
125
+ *
126
+ * class CustomProviderCompat extends SchemaCompatLayer {
127
+ * constructor(model: LanguageModelV1) {
128
+ * super(model);
129
+ * }
130
+ *
131
+ * shouldApply(): boolean {
132
+ * return this.getModel().provider === 'custom-provider';
133
+ * }
134
+ *
135
+ * getSchemaTarget() {
136
+ * return 'jsonSchema7';
137
+ * }
138
+ *
139
+ * processZodType<T extends z.AnyZodObject>(value: z.ZodTypeAny): ShapeValue<T> {
140
+ * // Custom processing logic for this provider
141
+ * switch (value._def.typeName) {
142
+ * case 'ZodString':
143
+ * return this.defaultZodStringHandler(value, ['email', 'url']);
144
+ * default:
145
+ * return this.defaultUnsupportedZodTypeHandler(value);
146
+ * }
147
+ * }
148
+ * }
149
+ * ```
150
+ */
151
+ export declare abstract class SchemaCompatLayer {
152
+ private model;
153
+ /**
154
+ * Creates a new schema compatibility instance.
155
+ *
156
+ * @param model - The language model this compatibility layer applies to
157
+ */
158
+ constructor(model: SchemaCompatModel);
159
+ /**
160
+ * Gets the language model associated with this compatibility layer.
161
+ *
162
+ * @returns The language model instance
163
+ */
164
+ getModel(): SchemaCompatModel;
165
+ /**
166
+ * Determines whether this compatibility layer should be applied for the current model.
167
+ *
168
+ * @returns True if this compatibility layer should be used, false otherwise
169
+ * @abstract
170
+ */
171
+ abstract shouldApply(): boolean;
172
+ /**
173
+ * Returns the JSON Schema target format for this provider.
174
+ *
175
+ * @returns The schema target format, or undefined to use the default 'jsonSchema7'
176
+ * @abstract
177
+ */
178
+ abstract getSchemaTarget(): Targets | undefined;
179
+ /**
180
+ * Processes a specific Zod type according to the provider's requirements.
181
+ *
182
+ * @param value - The Zod type to process
183
+ * @returns The processed Zod type
184
+ * @abstract
185
+ */
186
+ abstract processZodType(value: ZodTypeAny): ZodTypeAny;
187
+ /**
188
+ * Default handler for Zod object types. Recursively processes all properties in the object.
189
+ *
190
+ * @param value - The Zod object to process
191
+ * @returns The processed Zod object
192
+ */
193
+ defaultZodObjectHandler(value: ZodObject<any, any, any>, options?: {
194
+ passthrough?: boolean;
195
+ }): ZodObject<any, any, any>;
196
+ /**
197
+ * Merges validation constraints into a parameter description.
198
+ *
199
+ * This helper method converts validation constraints that may not be supported
200
+ * by a provider into human-readable descriptions.
201
+ *
202
+ * @param description - The existing parameter description
203
+ * @param constraints - The validation constraints to merge
204
+ * @returns The updated description with constraints, or undefined if no constraints
205
+ */
206
+ mergeParameterDescription(description: string | undefined, constraints: NumberConstraints | StringConstraints | ArrayConstraints | DateConstraints | {
207
+ defaultValue?: unknown;
208
+ }): string | undefined;
209
+ /**
210
+ * Default handler for unsupported Zod types. Throws an error for specified unsupported types.
211
+ *
212
+ * @param value - The Zod type to check
213
+ * @param throwOnTypes - Array of type names to throw errors for
214
+ * @returns The original value if not in the throw list
215
+ * @throws Error if the type is in the unsupported list
216
+ */
217
+ defaultUnsupportedZodTypeHandler<T extends z.AnyZodObject>(value: z.ZodTypeAny, throwOnTypes?: readonly UnsupportedZodType[]): ShapeValue<T>;
218
+ /**
219
+ * Default handler for Zod array types. Processes array constraints according to provider support.
220
+ *
221
+ * @param value - The Zod array to process
222
+ * @param handleChecks - Array constraints to convert to descriptions vs keep as validation
223
+ * @returns The processed Zod array
224
+ */
225
+ defaultZodArrayHandler(value: ZodArray<any, any>, handleChecks?: readonly ArrayCheckType[]): ZodArray<any, any>;
226
+ /**
227
+ * Default handler for Zod union types. Processes all union options.
228
+ *
229
+ * @param value - The Zod union to process
230
+ * @returns The processed Zod union
231
+ * @throws Error if union has fewer than 2 options
232
+ */
233
+ defaultZodUnionHandler(value: ZodUnion<[ZodTypeAny, ...ZodTypeAny[]]>): ZodTypeAny;
234
+ /**
235
+ * Default handler for Zod string types. Processes string validation constraints.
236
+ *
237
+ * @param value - The Zod string to process
238
+ * @param handleChecks - String constraints to convert to descriptions vs keep as validation
239
+ * @returns The processed Zod string
240
+ */
241
+ defaultZodStringHandler(value: ZodString, handleChecks?: readonly StringCheckType[]): ZodString;
242
+ /**
243
+ * Default handler for Zod number types. Processes number validation constraints.
244
+ *
245
+ * @param value - The Zod number to process
246
+ * @param handleChecks - Number constraints to convert to descriptions vs keep as validation
247
+ * @returns The processed Zod number
248
+ */
249
+ defaultZodNumberHandler(value: ZodNumber, handleChecks?: readonly NumberCheckType[]): ZodNumber;
250
+ /**
251
+ * Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
252
+ *
253
+ * @param value - The Zod date to process
254
+ * @returns A Zod string schema representing the date in ISO format
255
+ */
256
+ defaultZodDateHandler(value: ZodDate): ZodString;
257
+ /**
258
+ * Default handler for Zod optional types. Processes the inner type and maintains optionality.
259
+ *
260
+ * @param value - The Zod optional to process
261
+ * @param handleTypes - Types that should be processed vs passed through
262
+ * @returns The processed Zod optional
263
+ */
264
+ defaultZodOptionalHandler(value: ZodOptional<any>, handleTypes?: readonly AllZodType[]): ZodTypeAny;
265
+ /**
266
+ * Processes a Zod object schema and converts it to an AI SDK Schema.
267
+ *
268
+ * @param zodSchema - The Zod object schema to process
269
+ * @returns An AI SDK Schema with provider-specific compatibility applied
270
+ */
271
+ processToAISDKSchema(zodSchema: z.ZodSchema): Schema;
272
+ /**
273
+ * Processes a Zod object schema and converts it to a JSON Schema.
274
+ *
275
+ * @param zodSchema - The Zod object schema to process
276
+ * @returns A JSONSchema7 object with provider-specific compatibility applied
277
+ */
278
+ processToJSONSchema(zodSchema: z.ZodSchema): JSONSchema7;
279
+ }
280
+ export {};
281
+ //# sourceMappingURL=schema-compatibility.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-compatibility.d.ts","sourceRoot":"","sources":["../src/schema-compatibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACxH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,iBAAiB,2EAA4E,CAAC;AAE3G;;;GAGG;AACH,eAAO,MAAM,iBAAiB,uCAIpB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,gBAAgB,mCAAoC,CAAC;AAElE,eAAO,MAAM,UAAU,GAAI,GAAG,UAAU,KAAG,CAAC,IAAI,WAAW,CAAC,GAAG,CAA6B,CAAC;AAC7F,eAAO,MAAM,KAAK,GAAI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CAAC,CAAC,CAAC;IAOhB;;;;;;OAMG;IACI,sBAAsB,CAC3B,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,EACzB,YAAY,GAAE,SAAS,cAAc,EAAqB,GACzD,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAuCrB;;;;;;OAMG;IACI,sBAAsB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,UAAU,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC,GAAG,UAAU;IAUzF;;;;;;OAMG;IACI,uBAAuB,CAC5B,KAAK,EAAE,SAAS,EAChB,YAAY,GAAE,SAAS,eAAe,EAAsB,GAC3D,SAAS;IA6DZ;;;;;;OAMG;IACI,uBAAuB,CAC5B,KAAK,EAAE,SAAS,EAChB,YAAY,GAAE,SAAS,eAAe,EAAsB,GAC3D,SAAS;IAqDZ;;;;;OAKG;IACI,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS;IAkCvD;;;;;;OAMG;IACI,yBAAyB,CAC9B,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,EACvB,WAAW,GAAE,SAAS,UAAU,EAAwB,GACvD,UAAU;IAQb;;;;;OAKG;IACI,oBAAoB,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,MAAM;IAM3D;;;;;OAKG;IACI,mBAAmB,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,WAAW;CAGhE"}
@@ -0,0 +1,84 @@
1
+ import type { Schema } from 'ai';
2
+ import type { JSONSchema7 } from 'json-schema';
3
+ import type { z, ZodSchema } from 'zod';
4
+ import type { Targets } from 'zod-to-json-schema';
5
+ import type { SchemaCompatLayer } from './schema-compatibility';
6
+ /**
7
+ * Converts a Zod schema to an AI SDK Schema with validation support.
8
+ *
9
+ * This function mirrors the behavior of Vercel's AI SDK zod-schema utility but allows
10
+ * customization of the JSON Schema target format.
11
+ *
12
+ * @param zodSchema - The Zod schema to convert
13
+ * @param target - The JSON Schema target format (defaults to 'jsonSchema7')
14
+ * @returns An AI SDK Schema object with built-in validation
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { z } from 'zod';
19
+ * import { convertZodSchemaToAISDKSchema } from '@mastra/schema-compat';
20
+ *
21
+ * const userSchema = z.object({
22
+ * name: z.string(),
23
+ * age: z.number().min(0)
24
+ * });
25
+ *
26
+ * const aiSchema = convertZodSchemaToAISDKSchema(userSchema);
27
+ * ```
28
+ */
29
+ export declare function convertZodSchemaToAISDKSchema(zodSchema: ZodSchema, target?: Targets): Schema<any>;
30
+ /**
31
+ * Converts an AI SDK Schema or Zod schema to a Zod schema.
32
+ *
33
+ * If the input is already a Zod schema, it returns it unchanged.
34
+ * If the input is an AI SDK Schema, it extracts the JSON schema and converts it to Zod.
35
+ *
36
+ * @param schema - The schema to convert (AI SDK Schema or Zod schema)
37
+ * @returns A Zod schema equivalent of the input
38
+ * @throws Error if the conversion fails
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * import { jsonSchema } from 'ai';
43
+ * import { convertSchemaToZod } from '@mastra/schema-compat';
44
+ *
45
+ * const aiSchema = jsonSchema({
46
+ * type: 'object',
47
+ * properties: {
48
+ * name: { type: 'string' }
49
+ * }
50
+ * });
51
+ *
52
+ * const zodSchema = convertSchemaToZod(aiSchema);
53
+ * ```
54
+ */
55
+ export declare function convertSchemaToZod(schema: Schema | z.ZodSchema): z.ZodType;
56
+ /**
57
+ * Processes a schema using provider compatibility layers and converts it to an AI SDK Schema.
58
+ *
59
+ * @param options - Configuration object for schema processing
60
+ * @param options.schema - The schema to process (AI SDK Schema or Zod object schema)
61
+ * @param options.compatLayers - Array of compatibility layers to try
62
+ * @param options.mode - Must be 'aiSdkSchema'
63
+ * @returns Processed schema as an AI SDK Schema
64
+ */
65
+ export declare function applyCompatLayer(options: {
66
+ schema: Schema | z.ZodSchema;
67
+ compatLayers: SchemaCompatLayer[];
68
+ mode: 'aiSdkSchema';
69
+ }): Schema;
70
+ /**
71
+ * Processes a schema using provider compatibility layers and converts it to a JSON Schema.
72
+ *
73
+ * @param options - Configuration object for schema processing
74
+ * @param options.schema - The schema to process (AI SDK Schema or Zod object schema)
75
+ * @param options.compatLayers - Array of compatibility layers to try
76
+ * @param options.mode - Must be 'jsonSchema'
77
+ * @returns Processed schema as a JSONSchema7
78
+ */
79
+ export declare function applyCompatLayer(options: {
80
+ schema: Schema | z.ZodSchema;
81
+ compatLayers: SchemaCompatLayer[];
82
+ mode: 'jsonSchema';
83
+ }): JSONSchema7;
84
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAGxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,wBAAgB,6BAA6B,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,GAAE,OAAuB,eAalG;AAsBD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,OAAO,CAa1E;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC;IAC7B,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAClC,IAAI,EAAE,aAAa,CAAC;CACrB,GAAG,MAAM,CAAC;AAEX;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC;IAC7B,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAClC,IAAI,EAAE,YAAY,CAAC;CACpB,GAAG,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/schema-compat",
3
- "version": "0.0.0-ai-v5-20250729012312",
3
+ "version": "0.0.0-ai-v5-20250801192614",
4
4
  "description": "Tool schema compatibility layer for Mastra.ai",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -33,23 +33,23 @@
33
33
  "zod-to-json-schema": "^3.24.5"
34
34
  },
35
35
  "peerDependencies": {
36
- "ai": "5.0.0-beta.14",
36
+ "ai": "^5.0.0",
37
37
  "zod": "^3.0.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/json-schema": "^7.0.15",
41
- "ai": "5.0.0-beta.14",
41
+ "ai": "latest",
42
42
  "@types/node": "^20.19.0",
43
43
  "eslint": "^9.30.1",
44
44
  "tsup": "^8.5.0",
45
45
  "typescript": "^5.8.3",
46
46
  "vitest": "^3.2.4",
47
47
  "zod": "^3.25.67",
48
- "@internal/lint": "0.0.0-ai-v5-20250729012312"
48
+ "@internal/lint": "0.0.0-ai-v5-20250801192614"
49
49
  },
50
50
  "scripts": {
51
- "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
52
- "build:watch": "pnpm build --watch",
51
+ "build": "tsup --silent --config tsup.config.ts",
52
+ "build:watch": "tsup --watch --silent --config tsup.config.ts",
53
53
  "test": "vitest run",
54
54
  "lint": "eslint ."
55
55
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": ["./tsconfig.json", "../../tsconfig.build.json"],
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*"],
8
+ "exclude": ["node_modules", "**/*.test.ts", "src/**/*.mock.ts"]
9
+ }
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "extends": "../../tsconfig.node.json",
3
- "include": ["src/**/*"],
3
+ "include": ["src/**/*", "tsup.config.ts"],
4
4
  "exclude": ["node_modules", "**/*.test.ts"]
5
5
  }
package/tsup.config.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { spawn } from 'child_process';
2
+ import { promisify } from 'util';
3
+ import { defineConfig } from 'tsup';
4
+
5
+ const exec = promisify(spawn);
6
+
7
+ export default defineConfig({
8
+ entry: ['src/index.ts'],
9
+ format: ['esm', 'cjs'],
10
+ clean: true,
11
+ dts: false,
12
+ splitting: true,
13
+ treeshake: {
14
+ preset: 'smallest',
15
+ },
16
+ sourcemap: true,
17
+ onSuccess: async () => {
18
+ await exec('pnpm', ['tsc', '-p', 'tsconfig.build.json'], {
19
+ stdio: 'inherit',
20
+ });
21
+ },
22
+ });