incur 0.3.15 → 0.3.16

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/Schema.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import { z } from 'zod';
2
- /** Converts a Zod schema to a JSON Schema object. Strips the `$schema` meta-property. */
2
+ /**
3
+ * Converts a Zod schema to a JSON Schema object. Strips the `$schema`
4
+ * meta-property. Represents bigints and dates as `{ type: "string" }`
5
+ * since JSON lacks native types for them.
6
+ */
3
7
  export declare function toJsonSchema(schema: z.ZodType): Record<string, unknown>;
4
8
  //# sourceMappingURL=Schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,yFAAyF;AACzF,wBAAgB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIvE"}
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAUvE"}
package/dist/Schema.js CHANGED
@@ -1,7 +1,18 @@
1
1
  import { z } from 'zod';
2
- /** Converts a Zod schema to a JSON Schema object. Strips the `$schema` meta-property. */
2
+ /**
3
+ * Converts a Zod schema to a JSON Schema object. Strips the `$schema`
4
+ * meta-property. Represents bigints and dates as `{ type: "string" }`
5
+ * since JSON lacks native types for them.
6
+ */
3
7
  export function toJsonSchema(schema) {
4
- const result = z.toJSONSchema(schema);
8
+ const result = z.toJSONSchema(schema, {
9
+ unrepresentable: 'any',
10
+ override: (ctx) => {
11
+ const type = ctx.zodSchema._zod?.def?.type;
12
+ if (type === 'bigint' || type === 'date')
13
+ ctx.jsonSchema.type = 'string';
14
+ },
15
+ });
5
16
  delete result.$schema;
6
17
  return result;
7
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Schema.js","sourceRoot":"","sources":["../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,yFAAyF;AACzF,MAAM,UAAU,YAAY,CAAC,MAAiB;IAC5C,MAAM,MAAM,GAAG,CAAC,CAAC,YAAY,CAAC,MAAM,CAA4B,CAAA;IAChE,OAAO,MAAM,CAAC,OAAO,CAAA;IACrB,OAAO,MAAM,CAAA;AACf,CAAC"}
1
+ {"version":3,"file":"Schema.js","sourceRoot":"","sources":["../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAiB;IAC5C,MAAM,MAAM,GAAG,CAAC,CAAC,YAAY,CAAC,MAAM,EAAE;QACpC,eAAe,EAAE,KAAK;QACtB,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE;YAChB,MAAM,IAAI,GAAG,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAA;YAC1C,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,MAAM;gBAAE,GAAG,CAAC,UAAU,CAAC,IAAI,GAAG,QAAQ,CAAA;QAC1E,CAAC;KACF,CAA4B,CAAA;IAC7B,OAAO,MAAM,CAAC,OAAO,CAAA;IACrB,OAAO,MAAM,CAAA;AACf,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "incur",
3
3
  "type": "module",
4
- "version": "0.3.15",
4
+ "version": "0.3.16",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -21,6 +21,9 @@
21
21
  "yaml": "^2.8.2",
22
22
  "zod": "^4.3.6"
23
23
  },
24
+ "engines": {
25
+ "node": ">=22"
26
+ },
24
27
  "sideEffects": false,
25
28
  "bin": {
26
29
  "incur": "./dist/bin.js",
@@ -97,6 +97,35 @@ describe('toJsonSchema', () => {
97
97
  })
98
98
  })
99
99
 
100
+ test('converts z.bigint() as string', () => {
101
+ expect(Schema.toJsonSchema(z.bigint())).toEqual({ type: 'string' })
102
+ })
103
+
104
+ test('converts z.coerce.bigint() as string', () => {
105
+ expect(Schema.toJsonSchema(z.coerce.bigint())).toEqual({ type: 'string' })
106
+ })
107
+
108
+ test('converts z.object() with bigint field', () => {
109
+ expect(
110
+ Schema.toJsonSchema(z.object({ amount: z.coerce.bigint().describe('Token amount') })),
111
+ ).toEqual({
112
+ type: 'object',
113
+ properties: {
114
+ amount: { type: 'string', description: 'Token amount' },
115
+ },
116
+ required: ['amount'],
117
+ additionalProperties: false,
118
+ })
119
+ })
120
+
121
+ test('converts z.date() as string', () => {
122
+ expect(Schema.toJsonSchema(z.date())).toEqual({ type: 'string' })
123
+ })
124
+
125
+ test('converts z.coerce.date() as string', () => {
126
+ expect(Schema.toJsonSchema(z.coerce.date())).toEqual({ type: 'string' })
127
+ })
128
+
100
129
  test('full object with optional, default, and describe', () => {
101
130
  const result = Schema.toJsonSchema(
102
131
  z.object({
package/src/Schema.ts CHANGED
@@ -1,8 +1,18 @@
1
1
  import { z } from 'zod'
2
2
 
3
- /** Converts a Zod schema to a JSON Schema object. Strips the `$schema` meta-property. */
3
+ /**
4
+ * Converts a Zod schema to a JSON Schema object. Strips the `$schema`
5
+ * meta-property. Represents bigints and dates as `{ type: "string" }`
6
+ * since JSON lacks native types for them.
7
+ */
4
8
  export function toJsonSchema(schema: z.ZodType): Record<string, unknown> {
5
- const result = z.toJSONSchema(schema) as Record<string, unknown>
9
+ const result = z.toJSONSchema(schema, {
10
+ unrepresentable: 'any',
11
+ override: (ctx) => {
12
+ const type = ctx.zodSchema._zod?.def?.type
13
+ if (type === 'bigint' || type === 'date') ctx.jsonSchema.type = 'string'
14
+ },
15
+ }) as Record<string, unknown>
6
16
  delete result.$schema
7
17
  return result
8
18
  }