ag-common 0.0.867 → 0.0.869
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.
- package/dist/api/helpers/zod.d.ts +1 -1
- package/dist/api/helpers/zod.js +43 -55
- package/package.json +29 -29
|
@@ -3,7 +3,7 @@ import type { z } from 'zod';
|
|
|
3
3
|
* Convert a Zod object schema to its code representation for use in LLM prompts.
|
|
4
4
|
* Outputs actual Zod code like: z.object({ field: z.string().nullable().describe("...") })
|
|
5
5
|
*
|
|
6
|
-
* Uses
|
|
6
|
+
* Uses Zod 4 internals: _def.type (lowercase string like 'string', 'number', etc.)
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* const schema = z.object({
|
package/dist/api/helpers/zod.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.zodSchemaToString = zodSchemaToString;
|
|
|
5
5
|
* Convert a Zod object schema to its code representation for use in LLM prompts.
|
|
6
6
|
* Outputs actual Zod code like: z.object({ field: z.string().nullable().describe("...") })
|
|
7
7
|
*
|
|
8
|
-
* Uses
|
|
8
|
+
* Uses Zod 4 internals: _def.type (lowercase string like 'string', 'number', etc.)
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* const schema = z.object({
|
|
@@ -32,86 +32,74 @@ function zodSchemaToString(schema) {
|
|
|
32
32
|
}
|
|
33
33
|
return `z.object({\n${fields.join(',\n')}\n})`;
|
|
34
34
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Get the type name from a Zod type's internal definition.
|
|
37
|
-
* This works across different Zod module instances unlike instanceof.
|
|
38
|
-
*/
|
|
35
|
+
/** Get the Zod 4 type name from _def.type (e.g. 'string', 'number', 'optional') */
|
|
39
36
|
function getTypeName(zodType) {
|
|
40
|
-
|
|
41
|
-
return
|
|
37
|
+
const type = zodType._def.type;
|
|
38
|
+
return typeof type === 'string' ? type : undefined;
|
|
42
39
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Recursively convert a Zod type to its code representation
|
|
45
|
-
*/
|
|
40
|
+
/** Recursively convert a Zod type to its code representation. */
|
|
46
41
|
function zodTypeToCode(zodType) {
|
|
42
|
+
var _a;
|
|
47
43
|
const description = zodType.description;
|
|
48
44
|
const describeChain = description
|
|
49
45
|
? `.describe(${JSON.stringify(description)})`
|
|
50
46
|
: '';
|
|
47
|
+
const def = zodType._def;
|
|
51
48
|
const typeName = getTypeName(zodType);
|
|
52
|
-
//
|
|
53
|
-
if (typeName === '
|
|
54
|
-
|
|
55
|
-
const innerType = zodType._def.innerType;
|
|
56
|
-
const inner = zodTypeToCode(innerType).replace(/\.describe\([^)]+\)$/, '');
|
|
49
|
+
// Wrapper types (unwrap inner type)
|
|
50
|
+
if (typeName === 'optional') {
|
|
51
|
+
const inner = zodTypeToCode(def.innerType).replace(/\.describe\([^)]+\)$/, '');
|
|
57
52
|
return `${inner}.optional()${describeChain}`;
|
|
58
53
|
}
|
|
59
|
-
if (typeName === '
|
|
60
|
-
|
|
61
|
-
const innerType = zodType._def.innerType;
|
|
62
|
-
const inner = zodTypeToCode(innerType).replace(/\.describe\([^)]+\)$/, '');
|
|
54
|
+
if (typeName === 'nullable') {
|
|
55
|
+
const inner = zodTypeToCode(def.innerType).replace(/\.describe\([^)]+\)$/, '');
|
|
63
56
|
return `${inner}.nullable()${describeChain}`;
|
|
64
57
|
}
|
|
65
|
-
//
|
|
66
|
-
if (typeName === '
|
|
58
|
+
// Primitives
|
|
59
|
+
if (typeName === 'string')
|
|
67
60
|
return `z.string()${describeChain}`;
|
|
68
|
-
|
|
69
|
-
if (typeName === 'ZodNumber') {
|
|
61
|
+
if (typeName === 'number')
|
|
70
62
|
return `z.number()${describeChain}`;
|
|
71
|
-
|
|
72
|
-
if (typeName === 'ZodBoolean') {
|
|
63
|
+
if (typeName === 'boolean')
|
|
73
64
|
return `z.boolean()${describeChain}`;
|
|
74
|
-
}
|
|
75
|
-
if (typeName === '
|
|
76
|
-
|
|
77
|
-
const values = zodType._def.values;
|
|
65
|
+
// Enum: _def.entries is { [k]: k }
|
|
66
|
+
if (typeName === 'enum') {
|
|
67
|
+
const values = Object.keys(def.entries);
|
|
78
68
|
const enumStr = values.map((v) => JSON.stringify(v)).join(', ');
|
|
79
69
|
return `z.enum([${enumStr}])${describeChain}`;
|
|
80
70
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
return `z.array(${innerType})${describeChain}`;
|
|
71
|
+
// Array: _def.element is the element type
|
|
72
|
+
if (typeName === 'array') {
|
|
73
|
+
const inner = zodTypeToCode(def.element);
|
|
74
|
+
return `z.array(${inner})${describeChain}`;
|
|
86
75
|
}
|
|
87
|
-
|
|
88
|
-
|
|
76
|
+
// Object: recurse into shape
|
|
77
|
+
if (typeName === 'object') {
|
|
89
78
|
return zodSchemaToString(zodType);
|
|
90
79
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const value =
|
|
80
|
+
// Literal: _def.values is an array (e.g. ['foo'])
|
|
81
|
+
if (typeName === 'literal') {
|
|
82
|
+
const value = def.values[0];
|
|
94
83
|
return `z.literal(${JSON.stringify(value)})${describeChain}`;
|
|
95
84
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
85
|
+
// Union: _def.options is array of Zod types
|
|
86
|
+
if (typeName === 'union') {
|
|
87
|
+
const optionsStr = def.options
|
|
88
|
+
.map((opt) => zodTypeToCode(opt))
|
|
89
|
+
.join(', ');
|
|
100
90
|
return `z.union([${optionsStr}])${describeChain}`;
|
|
101
91
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
-
const valueType = zodType._def.valueType;
|
|
108
|
-
return `z.record(${zodTypeToCode(valueType)})${describeChain}`;
|
|
92
|
+
// Record: _def.keyType + _def.valueType (valueType may be undefined for single-arg z.record(keyType))
|
|
93
|
+
if (typeName === 'record') {
|
|
94
|
+
const innerType = ((_a = def.valueType) !== null && _a !== void 0 ? _a : def.keyType);
|
|
95
|
+
return `z.record(${zodTypeToCode(innerType)})${describeChain}`;
|
|
109
96
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
97
|
+
// Tuple: _def.items is array of Zod types
|
|
98
|
+
if (typeName === 'tuple') {
|
|
99
|
+
const itemsStr = def.items
|
|
100
|
+
.map((item) => zodTypeToCode(item))
|
|
101
|
+
.join(', ');
|
|
114
102
|
return `z.tuple([${itemsStr}])${describeChain}`;
|
|
115
103
|
}
|
|
116
|
-
throw new Error(`Unsupported Zod type: ${typeName} (keys: ${Object.keys(
|
|
104
|
+
throw new Error(`Unsupported Zod type: ${typeName} (keys: ${Object.keys(def).join(', ')})`);
|
|
117
105
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.869",
|
|
3
3
|
"name": "ag-common",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@tailwindcss/postcss": "^4.1.18",
|
|
14
|
-
"autoprefixer": "^10.4.
|
|
14
|
+
"autoprefixer": "^10.4.24",
|
|
15
15
|
"class-variance-authority": "^0.7.1",
|
|
16
16
|
"clsx": "^2.1.1",
|
|
17
17
|
"cross-env": "^10.1.0",
|
|
18
18
|
"eslint": "^9.39.2",
|
|
19
19
|
"eslint-config-e7npm": "^0.1.31",
|
|
20
20
|
"lucide-react": "^0.563.0",
|
|
21
|
-
"react": "^19.2.
|
|
22
|
-
"react-dom": "^19.2.
|
|
21
|
+
"react": "^19.2.4",
|
|
22
|
+
"react-dom": "^19.2.4",
|
|
23
23
|
"tailwind-merge": "^3.4.0",
|
|
24
24
|
"tailwindcss": "^4.1.18",
|
|
25
25
|
"tailwindcss-animate": "^1.0.7",
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
"typescript": "^5.9.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@aws-sdk/client-acm": "^3.
|
|
31
|
-
"@aws-sdk/client-apigatewaymanagementapi": "^3.
|
|
32
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
33
|
-
"@aws-sdk/client-s3": "^3.
|
|
34
|
-
"@aws-sdk/client-ses": "^3.
|
|
35
|
-
"@aws-sdk/client-sqs": "^3.
|
|
36
|
-
"@aws-sdk/client-sts": "^3.
|
|
37
|
-
"@aws-sdk/lib-dynamodb": "^3.
|
|
38
|
-
"@aws-sdk/s3-presigned-post": "^3.
|
|
39
|
-
"@azure/cosmos": "^4.9.
|
|
40
|
-
"@google/genai": "^1.
|
|
30
|
+
"@aws-sdk/client-acm": "^3.983.0",
|
|
31
|
+
"@aws-sdk/client-apigatewaymanagementapi": "^3.983.0",
|
|
32
|
+
"@aws-sdk/client-dynamodb": "^3.983.0",
|
|
33
|
+
"@aws-sdk/client-s3": "^3.983.0",
|
|
34
|
+
"@aws-sdk/client-ses": "^3.983.0",
|
|
35
|
+
"@aws-sdk/client-sqs": "^3.983.0",
|
|
36
|
+
"@aws-sdk/client-sts": "^3.983.0",
|
|
37
|
+
"@aws-sdk/lib-dynamodb": "^3.983.0",
|
|
38
|
+
"@aws-sdk/s3-presigned-post": "^3.983.0",
|
|
39
|
+
"@azure/cosmos": "^4.9.1",
|
|
40
|
+
"@google/genai": "^1.40.0",
|
|
41
41
|
"@radix-ui/react-accordion": "^1.2.12",
|
|
42
42
|
"@radix-ui/react-avatar": "^1.1.11",
|
|
43
43
|
"@radix-ui/react-checkbox": "^1.3.3",
|
|
@@ -52,29 +52,29 @@
|
|
|
52
52
|
"@radix-ui/react-slot": "^1.2.4",
|
|
53
53
|
"@radix-ui/react-switch": "^1.2.6",
|
|
54
54
|
"@radix-ui/react-toast": "^1.2.15",
|
|
55
|
-
"@smithy/types": "^4.
|
|
56
|
-
"@storybook/addon-docs": "^10.
|
|
57
|
-
"@storybook/addon-links": "^10.
|
|
55
|
+
"@smithy/types": "^4.12.0",
|
|
56
|
+
"@storybook/addon-docs": "^10.2.6",
|
|
57
|
+
"@storybook/addon-links": "^10.2.6",
|
|
58
58
|
"@storybook/addon-styling-webpack": "^3.0.0",
|
|
59
59
|
"@storybook/addons": "^7.6.17",
|
|
60
|
-
"@storybook/react-vite": "^10.
|
|
61
|
-
"@storybook/react-webpack5": "^10.
|
|
60
|
+
"@storybook/react-vite": "^10.2.6",
|
|
61
|
+
"@storybook/react-webpack5": "^10.2.6",
|
|
62
62
|
"@types/jsonwebtoken": "^9.0.10",
|
|
63
|
-
"@types/node": "^25.0
|
|
64
|
-
"@types/react": "^19.2.
|
|
63
|
+
"@types/node": "^25.2.0",
|
|
64
|
+
"@types/react": "^19.2.11",
|
|
65
65
|
"@types/react-dom": "^19.2.3",
|
|
66
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
67
|
-
"@typescript-eslint/parser": "^8.
|
|
68
|
-
"aws-cdk-lib": "^2.
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
67
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
68
|
+
"aws-cdk-lib": "^2.237.1",
|
|
69
69
|
"buffer": "^6.0.3",
|
|
70
|
-
"eslint-plugin-storybook": "^10.
|
|
70
|
+
"eslint-plugin-storybook": "^10.2.6",
|
|
71
71
|
"globstar": "^1.0.0",
|
|
72
72
|
"jsonwebtoken": "^9.0.3",
|
|
73
|
-
"jwks-rsa": "^3.2.
|
|
73
|
+
"jwks-rsa": "^3.2.2",
|
|
74
74
|
"node-cache": "^5.1.2",
|
|
75
75
|
"rimraf": "^6.1.2",
|
|
76
|
-
"storybook": "^10.
|
|
77
|
-
"zod": "^3.
|
|
76
|
+
"storybook": "^10.2.6",
|
|
77
|
+
"zod": "^4.3.6"
|
|
78
78
|
},
|
|
79
79
|
"files": [
|
|
80
80
|
"dist/**/*",
|