@contractspec/lib.schema 1.57.0 → 1.59.0
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/EnumType.d.ts +29 -31
- package/dist/EnumType.d.ts.map +1 -1
- package/dist/EnumType.js +38 -54
- package/dist/EnumType.test.d.ts +2 -0
- package/dist/EnumType.test.d.ts.map +1 -0
- package/dist/FieldType.d.ts +19 -23
- package/dist/FieldType.d.ts.map +1 -1
- package/dist/FieldType.js +41 -47
- package/dist/FieldType.test.d.ts +2 -0
- package/dist/FieldType.test.d.ts.map +1 -0
- package/dist/GraphQLSchemaType.d.ts +8 -12
- package/dist/GraphQLSchemaType.d.ts.map +1 -1
- package/dist/GraphQLSchemaType.js +16 -18
- package/dist/GraphQLSchemaType.test.d.ts +2 -0
- package/dist/GraphQLSchemaType.test.d.ts.map +1 -0
- package/dist/JsonSchemaType.d.ts +67 -63
- package/dist/JsonSchemaType.d.ts.map +1 -1
- package/dist/JsonSchemaType.js +73 -123
- package/dist/JsonSchemaType.test.d.ts +2 -0
- package/dist/JsonSchemaType.test.d.ts.map +1 -0
- package/dist/ScalarTypeEnum.d.ts +23 -27
- package/dist/ScalarTypeEnum.d.ts.map +1 -1
- package/dist/ScalarTypeEnum.js +235 -235
- package/dist/ScalarTypeEnum.test.d.ts +2 -0
- package/dist/ScalarTypeEnum.test.d.ts.map +1 -0
- package/dist/SchemaModel.d.ts +38 -39
- package/dist/SchemaModel.d.ts.map +1 -1
- package/dist/SchemaModel.js +28 -55
- package/dist/SchemaModel.test.d.ts +2 -0
- package/dist/SchemaModel.test.d.ts.map +1 -0
- package/dist/SchemaModelType.d.ts +28 -24
- package/dist/SchemaModelType.d.ts.map +1 -1
- package/dist/SchemaModelType.js +6 -19
- package/dist/SchemaModelType.test.d.ts +2 -0
- package/dist/SchemaModelType.test.d.ts.map +1 -0
- package/dist/ZodSchemaType.d.ts +44 -40
- package/dist/ZodSchemaType.d.ts.map +1 -1
- package/dist/ZodSchemaType.js +30 -101
- package/dist/ZodSchemaType.test.d.ts +2 -0
- package/dist/ZodSchemaType.test.d.ts.map +1 -0
- package/dist/browser/EnumType.js +40 -0
- package/dist/browser/FieldType.js +43 -0
- package/dist/browser/GraphQLSchemaType.js +18 -0
- package/dist/browser/JsonSchemaType.js +74 -0
- package/dist/browser/ScalarTypeEnum.js +236 -0
- package/dist/browser/SchemaModel.js +30 -0
- package/dist/browser/SchemaModelType.js +7 -0
- package/dist/browser/ZodSchemaType.js +31 -0
- package/dist/browser/entity/defineEntity.js +128 -0
- package/dist/browser/entity/generator.js +283 -0
- package/dist/browser/entity/index.js +410 -0
- package/dist/browser/entity/types.js +0 -0
- package/dist/browser/index.js +840 -0
- package/dist/entity/defineEntity.d.ts +55 -34
- package/dist/entity/defineEntity.d.ts.map +1 -1
- package/dist/entity/defineEntity.js +123 -231
- package/dist/entity/defineEntity.test.d.ts +2 -0
- package/dist/entity/defineEntity.test.d.ts.map +1 -0
- package/dist/entity/generator.d.ts +16 -20
- package/dist/entity/generator.d.ts.map +1 -1
- package/dist/entity/generator.js +262 -196
- package/dist/entity/generator.test.d.ts +2 -0
- package/dist/entity/generator.test.d.ts.map +1 -0
- package/dist/entity/index.d.ts +4 -4
- package/dist/entity/index.d.ts.map +1 -0
- package/dist/entity/index.js +410 -4
- package/dist/entity/types.d.ts +99 -103
- package/dist/entity/types.d.ts.map +1 -1
- package/dist/entity/types.js +1 -1
- package/dist/index.d.ts +10 -13
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +841 -13
- package/dist/node/EnumType.js +40 -0
- package/dist/node/FieldType.js +43 -0
- package/dist/node/GraphQLSchemaType.js +18 -0
- package/dist/node/JsonSchemaType.js +74 -0
- package/dist/node/ScalarTypeEnum.js +236 -0
- package/dist/node/SchemaModel.js +30 -0
- package/dist/node/SchemaModelType.js +7 -0
- package/dist/node/ZodSchemaType.js +31 -0
- package/dist/node/entity/defineEntity.js +128 -0
- package/dist/node/entity/generator.js +283 -0
- package/dist/node/entity/index.js +410 -0
- package/dist/node/entity/types.js +0 -0
- package/dist/node/index.js +840 -0
- package/package.json +123 -25
- package/dist/EnumType.js.map +0 -1
- package/dist/FieldType.js.map +0 -1
- package/dist/GraphQLSchemaType.js.map +0 -1
- package/dist/JsonSchemaType.js.map +0 -1
- package/dist/ScalarTypeEnum.js.map +0 -1
- package/dist/SchemaModel.js.map +0 -1
- package/dist/SchemaModelType.js.map +0 -1
- package/dist/ZodSchemaType.js.map +0 -1
- package/dist/entity/defineEntity.js.map +0 -1
- package/dist/entity/generator.js.map +0 -1
package/dist/JsonSchemaType.js
CHANGED
|
@@ -1,125 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
// src/JsonSchemaType.ts
|
|
3
|
+
import * as z from "zod";
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
name: this.options.name
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Get the configured name for this schema.
|
|
78
|
-
*/
|
|
79
|
-
getName() {
|
|
80
|
-
return this.options.name;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Convert a single JSON Schema property to Zod.
|
|
84
|
-
*/
|
|
85
|
-
convertPropertyToZod(schema) {
|
|
86
|
-
switch (Array.isArray(schema.type) ? schema.type[0] : schema.type) {
|
|
87
|
-
case "string": return z$1.string();
|
|
88
|
-
case "number":
|
|
89
|
-
case "integer": return z$1.number();
|
|
90
|
-
case "boolean": return z$1.boolean();
|
|
91
|
-
case "array":
|
|
92
|
-
if (schema.items && !Array.isArray(schema.items)) return z$1.array(this.convertPropertyToZod(schema.items));
|
|
93
|
-
return z$1.array(z$1.unknown());
|
|
94
|
-
case "object":
|
|
95
|
-
if (schema.properties) return new JsonSchemaType(schema).getZod();
|
|
96
|
-
return z$1.record(z$1.string(), z$1.unknown());
|
|
97
|
-
case "null": return z$1.null();
|
|
98
|
-
default: return z$1.unknown();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
5
|
+
class JsonSchemaType {
|
|
6
|
+
jsonSchema;
|
|
7
|
+
options;
|
|
8
|
+
constructor(jsonSchema, options = {}) {
|
|
9
|
+
this.jsonSchema = jsonSchema;
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
getZod() {
|
|
13
|
+
if (this.jsonSchema.additionalProperties !== undefined) {
|
|
14
|
+
if (this.jsonSchema.additionalProperties === true) {
|
|
15
|
+
return z.record(z.string(), z.unknown());
|
|
16
|
+
}
|
|
17
|
+
if (typeof this.jsonSchema.additionalProperties === "object") {
|
|
18
|
+
return z.record(z.string(), z.unknown());
|
|
19
|
+
}
|
|
20
|
+
if (this.jsonSchema.additionalProperties === false) {
|
|
21
|
+
return z.object({}).strict();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (this.jsonSchema.properties) {
|
|
25
|
+
const shape = {};
|
|
26
|
+
const required = new Set(this.jsonSchema.required ?? []);
|
|
27
|
+
for (const [key, propSchema] of Object.entries(this.jsonSchema.properties)) {
|
|
28
|
+
const fieldType = this.convertPropertyToZod(propSchema);
|
|
29
|
+
shape[key] = required.has(key) ? fieldType : fieldType.optional();
|
|
30
|
+
}
|
|
31
|
+
return z.object(shape).passthrough();
|
|
32
|
+
}
|
|
33
|
+
return z.object({}).passthrough();
|
|
34
|
+
}
|
|
35
|
+
getJsonSchema() {
|
|
36
|
+
return this.jsonSchema;
|
|
37
|
+
}
|
|
38
|
+
getPothos() {
|
|
39
|
+
return { type: "JSON", name: this.options.name };
|
|
40
|
+
}
|
|
41
|
+
getName() {
|
|
42
|
+
return this.options.name;
|
|
43
|
+
}
|
|
44
|
+
convertPropertyToZod(schema) {
|
|
45
|
+
const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;
|
|
46
|
+
switch (type) {
|
|
47
|
+
case "string":
|
|
48
|
+
return z.string();
|
|
49
|
+
case "number":
|
|
50
|
+
case "integer":
|
|
51
|
+
return z.number();
|
|
52
|
+
case "boolean":
|
|
53
|
+
return z.boolean();
|
|
54
|
+
case "array":
|
|
55
|
+
if (schema.items && !Array.isArray(schema.items)) {
|
|
56
|
+
return z.array(this.convertPropertyToZod(schema.items));
|
|
57
|
+
}
|
|
58
|
+
return z.array(z.unknown());
|
|
59
|
+
case "object":
|
|
60
|
+
if (schema.properties) {
|
|
61
|
+
return new JsonSchemaType(schema).getZod();
|
|
62
|
+
}
|
|
63
|
+
return z.record(z.string(), z.unknown());
|
|
64
|
+
case "null":
|
|
65
|
+
return z.null();
|
|
66
|
+
default:
|
|
67
|
+
return z.unknown();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
var fromJsonSchema = (schema, options) => new JsonSchemaType(schema, options);
|
|
72
|
+
export {
|
|
73
|
+
fromJsonSchema,
|
|
74
|
+
JsonSchemaType
|
|
101
75
|
};
|
|
102
|
-
/**
|
|
103
|
-
* Helper to create a SchemaType from JSON Schema.
|
|
104
|
-
*
|
|
105
|
-
* @param schema - The JSON Schema definition
|
|
106
|
-
* @param options - Optional configuration
|
|
107
|
-
* @returns A SchemaType-compatible wrapper
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```typescript
|
|
111
|
-
* const MetadataSchema = fromJsonSchema({
|
|
112
|
-
* type: 'object',
|
|
113
|
-
* properties: {
|
|
114
|
-
* createdAt: { type: 'string', format: 'date-time' },
|
|
115
|
-
* updatedAt: { type: 'string', format: 'date-time' },
|
|
116
|
-
* },
|
|
117
|
-
* required: ['createdAt'],
|
|
118
|
-
* });
|
|
119
|
-
* ```
|
|
120
|
-
*/
|
|
121
|
-
const fromJsonSchema = (schema, options) => new JsonSchemaType(schema, options);
|
|
122
|
-
|
|
123
|
-
//#endregion
|
|
124
|
-
export { JsonSchemaType, fromJsonSchema };
|
|
125
|
-
//# sourceMappingURL=JsonSchemaType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonSchemaType.test.d.ts","sourceRoot":"","sources":["../src/JsonSchemaType.test.ts"],"names":[],"mappings":""}
|
package/dist/ScalarTypeEnum.d.ts
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
import { FieldType } from
|
|
2
|
-
|
|
3
|
-
//#region src/ScalarTypeEnum.d.ts
|
|
1
|
+
import { FieldType } from './FieldType';
|
|
4
2
|
/**
|
|
5
3
|
* Factory functions for common scalar FieldTypes with zod/GraphQL/JSON Schema.
|
|
6
4
|
*/
|
|
7
|
-
declare const ScalarTypeEnum: {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
export declare const ScalarTypeEnum: {
|
|
6
|
+
readonly String_unsecure: () => FieldType<string>;
|
|
7
|
+
readonly Int_unsecure: () => FieldType<number>;
|
|
8
|
+
readonly Float_unsecure: () => FieldType<number>;
|
|
9
|
+
readonly Boolean: () => FieldType<boolean>;
|
|
10
|
+
readonly ID: () => FieldType<string>;
|
|
11
|
+
readonly JSON: () => FieldType<unknown>;
|
|
12
|
+
readonly JSONObject: () => FieldType<Record<string, unknown>>;
|
|
13
|
+
readonly Date: () => FieldType<Date, string>;
|
|
14
|
+
readonly DateTime: () => FieldType<Date, string>;
|
|
15
|
+
readonly Time: () => FieldType<string>;
|
|
16
|
+
readonly EmailAddress: () => FieldType<string>;
|
|
17
|
+
readonly URL: () => FieldType<string>;
|
|
18
|
+
readonly PhoneNumber: () => FieldType<string>;
|
|
19
|
+
readonly NonEmptyString: () => FieldType<string>;
|
|
20
|
+
readonly Locale: () => FieldType<string>;
|
|
21
|
+
readonly TimeZone: () => FieldType<string>;
|
|
22
|
+
readonly Latitude: () => FieldType<number>;
|
|
23
|
+
readonly Longitude: () => FieldType<number>;
|
|
24
|
+
readonly Currency: () => FieldType<string>;
|
|
25
|
+
readonly CountryCode: () => FieldType<string>;
|
|
28
26
|
};
|
|
29
|
-
type ScalarTypeEnum = [keyof typeof ScalarTypeEnum];
|
|
30
|
-
//#endregion
|
|
31
|
-
export { ScalarTypeEnum };
|
|
27
|
+
export type ScalarTypeEnum = [keyof typeof ScalarTypeEnum];
|
|
32
28
|
//# sourceMappingURL=ScalarTypeEnum.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScalarTypeEnum.d.ts","
|
|
1
|
+
{"version":3,"file":"ScalarTypeEnum.d.ts","sourceRoot":"","sources":["../src/ScalarTypeEnum.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAaxC;;GAEG;AACH,eAAO,MAAM,cAAc;oCAEJ,SAAS,CAAC,MAAM,CAAC;iCAapB,SAAS,CAAC,MAAM,CAAC;mCAgBf,SAAS,CAAC,MAAM,CAAC;4BAiBxB,SAAS,CAAC,OAAO,CAAC;uBAavB,SAAS,CAAC,MAAM,CAAC;yBAef,SAAS,CAAC,OAAO,CAAC;+BAQZ,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;yBAQxC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;6BAUnB,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;yBAU3B,SAAS,CAAC,MAAM,CAAC;iCAYT,SAAS,CAAC,MAAM,CAAC;wBAQ1B,SAAS,CAAC,MAAM,CAAC;gCAQT,SAAS,CAAC,MAAM,CAAC;mCAQd,SAAS,CAAC,MAAM,CAAC;2BAQzB,SAAS,CAAC,MAAM,CAAC;6BAQf,SAAS,CAAC,MAAM,CAAC;6BAQjB,SAAS,CAAC,MAAM,CAAC;8BAQhB,SAAS,CAAC,MAAM,CAAC;6BAQlB,SAAS,CAAC,MAAM,CAAC;gCAQd,SAAS,CAAC,MAAM,CAAC;CAoB1B,CAAC;AACX,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC"}
|