@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.
Files changed (96) hide show
  1. package/dist/EnumType.d.ts +29 -31
  2. package/dist/EnumType.d.ts.map +1 -1
  3. package/dist/EnumType.js +38 -54
  4. package/dist/EnumType.test.d.ts +2 -0
  5. package/dist/EnumType.test.d.ts.map +1 -0
  6. package/dist/FieldType.d.ts +19 -23
  7. package/dist/FieldType.d.ts.map +1 -1
  8. package/dist/FieldType.js +41 -47
  9. package/dist/FieldType.test.d.ts +2 -0
  10. package/dist/FieldType.test.d.ts.map +1 -0
  11. package/dist/GraphQLSchemaType.d.ts +8 -12
  12. package/dist/GraphQLSchemaType.d.ts.map +1 -1
  13. package/dist/GraphQLSchemaType.js +16 -18
  14. package/dist/GraphQLSchemaType.test.d.ts +2 -0
  15. package/dist/GraphQLSchemaType.test.d.ts.map +1 -0
  16. package/dist/JsonSchemaType.d.ts +67 -63
  17. package/dist/JsonSchemaType.d.ts.map +1 -1
  18. package/dist/JsonSchemaType.js +73 -123
  19. package/dist/JsonSchemaType.test.d.ts +2 -0
  20. package/dist/JsonSchemaType.test.d.ts.map +1 -0
  21. package/dist/ScalarTypeEnum.d.ts +23 -27
  22. package/dist/ScalarTypeEnum.d.ts.map +1 -1
  23. package/dist/ScalarTypeEnum.js +235 -235
  24. package/dist/ScalarTypeEnum.test.d.ts +2 -0
  25. package/dist/ScalarTypeEnum.test.d.ts.map +1 -0
  26. package/dist/SchemaModel.d.ts +38 -39
  27. package/dist/SchemaModel.d.ts.map +1 -1
  28. package/dist/SchemaModel.js +28 -55
  29. package/dist/SchemaModel.test.d.ts +2 -0
  30. package/dist/SchemaModel.test.d.ts.map +1 -0
  31. package/dist/SchemaModelType.d.ts +28 -24
  32. package/dist/SchemaModelType.d.ts.map +1 -1
  33. package/dist/SchemaModelType.js +6 -19
  34. package/dist/SchemaModelType.test.d.ts +2 -0
  35. package/dist/SchemaModelType.test.d.ts.map +1 -0
  36. package/dist/ZodSchemaType.d.ts +44 -40
  37. package/dist/ZodSchemaType.d.ts.map +1 -1
  38. package/dist/ZodSchemaType.js +30 -101
  39. package/dist/ZodSchemaType.test.d.ts +2 -0
  40. package/dist/ZodSchemaType.test.d.ts.map +1 -0
  41. package/dist/browser/EnumType.js +40 -0
  42. package/dist/browser/FieldType.js +43 -0
  43. package/dist/browser/GraphQLSchemaType.js +18 -0
  44. package/dist/browser/JsonSchemaType.js +74 -0
  45. package/dist/browser/ScalarTypeEnum.js +236 -0
  46. package/dist/browser/SchemaModel.js +30 -0
  47. package/dist/browser/SchemaModelType.js +7 -0
  48. package/dist/browser/ZodSchemaType.js +31 -0
  49. package/dist/browser/entity/defineEntity.js +128 -0
  50. package/dist/browser/entity/generator.js +283 -0
  51. package/dist/browser/entity/index.js +410 -0
  52. package/dist/browser/entity/types.js +0 -0
  53. package/dist/browser/index.js +840 -0
  54. package/dist/entity/defineEntity.d.ts +55 -34
  55. package/dist/entity/defineEntity.d.ts.map +1 -1
  56. package/dist/entity/defineEntity.js +123 -231
  57. package/dist/entity/defineEntity.test.d.ts +2 -0
  58. package/dist/entity/defineEntity.test.d.ts.map +1 -0
  59. package/dist/entity/generator.d.ts +16 -20
  60. package/dist/entity/generator.d.ts.map +1 -1
  61. package/dist/entity/generator.js +262 -196
  62. package/dist/entity/generator.test.d.ts +2 -0
  63. package/dist/entity/generator.test.d.ts.map +1 -0
  64. package/dist/entity/index.d.ts +4 -4
  65. package/dist/entity/index.d.ts.map +1 -0
  66. package/dist/entity/index.js +410 -4
  67. package/dist/entity/types.d.ts +99 -103
  68. package/dist/entity/types.d.ts.map +1 -1
  69. package/dist/entity/types.js +1 -1
  70. package/dist/index.d.ts +10 -13
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +841 -13
  73. package/dist/node/EnumType.js +40 -0
  74. package/dist/node/FieldType.js +43 -0
  75. package/dist/node/GraphQLSchemaType.js +18 -0
  76. package/dist/node/JsonSchemaType.js +74 -0
  77. package/dist/node/ScalarTypeEnum.js +236 -0
  78. package/dist/node/SchemaModel.js +30 -0
  79. package/dist/node/SchemaModelType.js +7 -0
  80. package/dist/node/ZodSchemaType.js +31 -0
  81. package/dist/node/entity/defineEntity.js +128 -0
  82. package/dist/node/entity/generator.js +283 -0
  83. package/dist/node/entity/index.js +410 -0
  84. package/dist/node/entity/types.js +0 -0
  85. package/dist/node/index.js +840 -0
  86. package/package.json +123 -25
  87. package/dist/EnumType.js.map +0 -1
  88. package/dist/FieldType.js.map +0 -1
  89. package/dist/GraphQLSchemaType.js.map +0 -1
  90. package/dist/JsonSchemaType.js.map +0 -1
  91. package/dist/ScalarTypeEnum.js.map +0 -1
  92. package/dist/SchemaModel.js.map +0 -1
  93. package/dist/SchemaModelType.js.map +0 -1
  94. package/dist/ZodSchemaType.js.map +0 -1
  95. package/dist/entity/defineEntity.js.map +0 -1
  96. package/dist/entity/generator.js.map +0 -1
@@ -1,125 +1,75 @@
1
- import * as z$1 from "zod";
1
+ // @bun
2
+ // src/JsonSchemaType.ts
3
+ import * as z from "zod";
2
4
 
3
- //#region src/JsonSchemaType.ts
4
- /**
5
- * JSON Schema wrapper for ContractSpec compatibility.
6
- *
7
- * Wraps JSON Schema definitions to implement the SchemaType interface,
8
- * enabling direct JSON Schema usage in ContractSpec definitions.
9
- *
10
- * @module JsonSchemaType
11
- */
12
- /**
13
- * Wrapper to use JSON Schema as a SchemaType.
14
- * Converts to Zod at runtime for validation.
15
- *
16
- * @example
17
- * ```typescript
18
- * const CustomFieldsSchema = fromJsonSchema({
19
- * type: 'object',
20
- * additionalProperties: {
21
- * oneOf: [
22
- * { type: 'string' },
23
- * { type: 'number' },
24
- * { type: 'boolean' },
25
- * ],
26
- * },
27
- * }, { name: 'CustomFields' });
28
- * ```
29
- */
30
- var JsonSchemaType = class JsonSchemaType {
31
- jsonSchema;
32
- options;
33
- constructor(jsonSchema, options = {}) {
34
- this.jsonSchema = jsonSchema;
35
- this.options = options;
36
- }
37
- /**
38
- * Convert JSON Schema to Zod schema for runtime validation.
39
- *
40
- * Note: This is a simplified conversion. For complex schemas,
41
- * consider using a dedicated json-schema-to-zod library.
42
- */
43
- getZod() {
44
- if (this.jsonSchema.additionalProperties !== void 0) {
45
- if (this.jsonSchema.additionalProperties === true) return z$1.record(z$1.string(), z$1.unknown());
46
- if (typeof this.jsonSchema.additionalProperties === "object") return z$1.record(z$1.string(), z$1.unknown());
47
- if (this.jsonSchema.additionalProperties === false) return z$1.object({}).strict();
48
- }
49
- if (this.jsonSchema.properties) {
50
- const shape = {};
51
- const required = new Set(this.jsonSchema.required ?? []);
52
- for (const [key, propSchema] of Object.entries(this.jsonSchema.properties)) {
53
- const fieldType = this.convertPropertyToZod(propSchema);
54
- shape[key] = required.has(key) ? fieldType : fieldType.optional();
55
- }
56
- return z$1.object(shape).passthrough();
57
- }
58
- return z$1.object({}).passthrough();
59
- }
60
- /**
61
- * Return the original JSON Schema.
62
- */
63
- getJsonSchema() {
64
- return this.jsonSchema;
65
- }
66
- /**
67
- * Return GraphQL type info.
68
- * JSON Schema types map to JSON scalar in GraphQL.
69
- */
70
- getPothos() {
71
- return {
72
- type: "JSON",
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=JsonSchemaType.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonSchemaType.test.d.ts","sourceRoot":"","sources":["../src/JsonSchemaType.test.ts"],"names":[],"mappings":""}
@@ -1,32 +1,28 @@
1
- import { FieldType } from "./FieldType.js";
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
- readonly String_unsecure: () => FieldType<string>;
9
- readonly Int_unsecure: () => FieldType<number>;
10
- readonly Float_unsecure: () => FieldType<number>;
11
- readonly Boolean: () => FieldType<boolean>;
12
- readonly ID: () => FieldType<string>;
13
- readonly JSON: () => FieldType<unknown>;
14
- readonly JSONObject: () => FieldType<Record<string, unknown>>;
15
- readonly Date: () => FieldType<Date, string>;
16
- readonly DateTime: () => FieldType<Date, string>;
17
- readonly Time: () => FieldType<string>;
18
- readonly EmailAddress: () => FieldType<string>;
19
- readonly URL: () => FieldType<string>;
20
- readonly PhoneNumber: () => FieldType<string>;
21
- readonly NonEmptyString: () => FieldType<string>;
22
- readonly Locale: () => FieldType<string>;
23
- readonly TimeZone: () => FieldType<string>;
24
- readonly Latitude: () => FieldType<number>;
25
- readonly Longitude: () => FieldType<number>;
26
- readonly Currency: () => FieldType<string>;
27
- readonly CountryCode: () => FieldType<string>;
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","names":[],"sources":["../src/ScalarTypeEnum.ts"],"mappings":";;;;;AAkBA;cAAa,cAAA;EAAA,gCAEU,SAAA;EAAA,6BAaH,SAAA;EAAA,+BAgBE,SAAA;EAAA,wBAiBP,SAAA;EAAA,mBAaL,SAAA;EAAA,qBAeE,SAAA;EAAA,2BAQM,SAAA,CAAU,MAAA;EAAA,qBAQhB,SAAA,CAAU,IAAA;EAAA,yBAUN,SAAA,CAAU,IAAA;EAAA,qBA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