@visulima/prisma-dmmf-transformer 2.0.34 → 2.0.36
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/CHANGELOG.md +21 -0
- package/LICENSE.md +3 -0
- package/dist/get-json-schema-model.d.cts +4 -0
- package/dist/get-json-schema-model.d.mts +4 -0
- package/dist/get-json-schema-model.d.ts +4 -0
- package/dist/get-json-schema-property.d.cts +4 -0
- package/dist/get-json-schema-property.d.mts +4 -0
- package/dist/get-json-schema-property.d.ts +4 -0
- package/dist/index.cjs +11 -1
- package/dist/index.d.cts +3 -193
- package/dist/index.d.mts +3 -193
- package/dist/index.d.ts +3 -193
- package/dist/index.mjs +2 -1
- package/dist/packem_shared/getJSONSchemaProperty-ChH8N6gd.mjs +167 -0
- package/dist/packem_shared/getJSONSchemaProperty-DyREsKli.cjs +154 -0
- package/dist/packem_shared/transformDMMF-D2pok2ta.mjs +56 -0
- package/dist/packem_shared/transformDMMF-e7c5Igd0.cjs +58 -0
- package/dist/transform-dmmf.d.cts +5 -0
- package/dist/transform-dmmf.d.mts +5 -0
- package/dist/transform-dmmf.d.ts +5 -0
- package/dist/types.d.cts +20 -0
- package/dist/types.d.mts +20 -0
- package/dist/types.d.ts +20 -0
- package/package.json +1 -1
- package/dist/packem_shared/getJSONSchemaProperty-BJUSxFNN.mjs +0 -1
- package/dist/packem_shared/getJSONSchemaProperty-DRt6R_Y4.cjs +0 -1
- package/dist/packem_shared/transformDMMF-B3i5bZr6.mjs +0 -1
- package/dist/packem_shared/transformDMMF-CNWOKGfH.cjs +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## @visulima/prisma-dmmf-transformer [2.0.36](https://github.com/visulima/visulima/compare/@visulima/prisma-dmmf-transformer@2.0.35...@visulima/prisma-dmmf-transformer@2.0.36) (2025-11-12)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* update package configurations and TypeScript definitions ([b59aa59](https://github.com/visulima/visulima/commit/b59aa59dac1508216b944f4b917fb4a7ab1f70a4))
|
|
6
|
+
|
|
7
|
+
### Miscellaneous Chores
|
|
8
|
+
|
|
9
|
+
* Add jsr file to all packages for release ([#565](https://github.com/visulima/visulima/issues/565)) ([ec91652](https://github.com/visulima/visulima/commit/ec91652b4e4112adf14ba152c1239a7703ba425a))
|
|
10
|
+
* update license files and clean up TypeScript definitions ([fe668cc](https://github.com/visulima/visulima/commit/fe668cc26de23591d4df54a0954455ebbe31b22d))
|
|
11
|
+
|
|
12
|
+
## @visulima/prisma-dmmf-transformer [2.0.35](https://github.com/visulima/visulima/compare/@visulima/prisma-dmmf-transformer@2.0.34...@visulima/prisma-dmmf-transformer@2.0.35) (2025-11-07)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* update TypeScript configurations and improve linting across multiple packages ([6f25ec7](https://github.com/visulima/visulima/commit/6f25ec7841da7246f8f9166efc5292a7089d37ee))
|
|
17
|
+
|
|
18
|
+
### Miscellaneous Chores
|
|
19
|
+
|
|
20
|
+
* update npm and pnpm configurations for monorepo optimization ([#564](https://github.com/visulima/visulima/issues/564)) ([5512b42](https://github.com/visulima/visulima/commit/5512b42f672c216b6a3c9e39035199a4ebd9a4b8))
|
|
21
|
+
|
|
1
22
|
## @visulima/prisma-dmmf-transformer [2.0.34](https://github.com/visulima/visulima/compare/@visulima/prisma-dmmf-transformer@2.0.33...@visulima/prisma-dmmf-transformer@2.0.34) (2025-11-05)
|
|
2
23
|
|
|
3
24
|
### Bug Fixes
|
package/LICENSE.md
CHANGED
|
@@ -26,11 +26,14 @@ SOFTWARE.
|
|
|
26
26
|
<!-- TYPE_DEPENDENCIES -->
|
|
27
27
|
|
|
28
28
|
# Licenses of bundled types
|
|
29
|
+
|
|
29
30
|
The published @visulima/prisma-dmmf-transformer artifact additionally contains code with the following licenses:
|
|
30
31
|
MIT
|
|
31
32
|
|
|
32
33
|
# Bundled types:
|
|
34
|
+
|
|
33
35
|
## @types/json-schema
|
|
36
|
+
|
|
34
37
|
License: MIT
|
|
35
38
|
By: Boris Cherny, Lucian Buzzo, Roland Groza, Jason Kwok
|
|
36
39
|
Repository: https://github.com/DefinitelyTyped/DefinitelyTyped.git
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
+
import type { DefinitionMap, ModelMetaData, TransformOptions } from "./types.d.cts";
|
|
3
|
+
declare const getJSONSchemaModel: (modelMetaData: ModelMetaData, transformOptions: TransformOptions) => (model: DMMF.Model) => DefinitionMap;
|
|
4
|
+
export = getJSONSchemaModel;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
+
import type { DefinitionMap, ModelMetaData, TransformOptions } from "./types.d.mts";
|
|
3
|
+
declare const getJSONSchemaModel: (modelMetaData: ModelMetaData, transformOptions: TransformOptions) => (model: DMMF.Model) => DefinitionMap;
|
|
4
|
+
export default getJSONSchemaModel;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
+
import type { DefinitionMap, ModelMetaData, TransformOptions } from "./types.d.ts";
|
|
3
|
+
declare const getJSONSchemaModel: (modelMetaData: ModelMetaData, transformOptions: TransformOptions) => (model: DMMF.Model) => DefinitionMap;
|
|
4
|
+
export = getJSONSchemaModel;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
+
import type { ModelMetaData, PropertyMap, TransformOptions } from "./types.d.cts";
|
|
3
|
+
declare const getJSONSchemaProperty: (modelMetaData: ModelMetaData, transformOptions: TransformOptions) => (field: DMMF.Field) => PropertyMap;
|
|
4
|
+
export = getJSONSchemaProperty;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
+
import type { ModelMetaData, PropertyMap, TransformOptions } from "./types.d.mts";
|
|
3
|
+
declare const getJSONSchemaProperty: (modelMetaData: ModelMetaData, transformOptions: TransformOptions) => (field: DMMF.Field) => PropertyMap;
|
|
4
|
+
export default getJSONSchemaProperty;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
+
import type { ModelMetaData, PropertyMap, TransformOptions } from "./types.d.ts";
|
|
3
|
+
declare const getJSONSchemaProperty: (modelMetaData: ModelMetaData, transformOptions: TransformOptions) => (field: DMMF.Field) => PropertyMap;
|
|
4
|
+
export = getJSONSchemaProperty;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const getJSONSchemaProperty = require('./packem_shared/getJSONSchemaProperty-DyREsKli.cjs');
|
|
6
|
+
const transformDMMF = require('./packem_shared/transformDMMF-e7c5Igd0.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.getJSONSchemaProperty = getJSONSchemaProperty;
|
|
11
|
+
exports.transformDMMF = transformDMMF;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,193 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// ==================================================================================================
|
|
5
|
-
// JSON Schema Draft 07
|
|
6
|
-
// ==================================================================================================
|
|
7
|
-
// https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
|
8
|
-
// --------------------------------------------------------------------------------------------------
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Primitive type
|
|
12
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
|
13
|
-
*/
|
|
14
|
-
type JSONSchema7TypeName =
|
|
15
|
-
| "string" //
|
|
16
|
-
| "number"
|
|
17
|
-
| "integer"
|
|
18
|
-
| "boolean"
|
|
19
|
-
| "object"
|
|
20
|
-
| "array"
|
|
21
|
-
| "null";
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Primitive type
|
|
25
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
|
26
|
-
*/
|
|
27
|
-
type JSONSchema7Type =
|
|
28
|
-
| string //
|
|
29
|
-
| number
|
|
30
|
-
| boolean
|
|
31
|
-
| JSONSchema7Object
|
|
32
|
-
| JSONSchema7Array
|
|
33
|
-
| null;
|
|
34
|
-
|
|
35
|
-
// Workaround for infinite type recursion
|
|
36
|
-
interface JSONSchema7Object {
|
|
37
|
-
[key: string]: JSONSchema7Type;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Workaround for infinite type recursion
|
|
41
|
-
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
|
42
|
-
interface JSONSchema7Array extends Array<JSONSchema7Type> {}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Meta schema
|
|
46
|
-
*
|
|
47
|
-
* Recommended values:
|
|
48
|
-
* - 'http://json-schema.org/schema#'
|
|
49
|
-
* - 'http://json-schema.org/hyper-schema#'
|
|
50
|
-
* - 'http://json-schema.org/draft-07/schema#'
|
|
51
|
-
* - 'http://json-schema.org/draft-07/hyper-schema#'
|
|
52
|
-
*
|
|
53
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
|
|
54
|
-
*/
|
|
55
|
-
type JSONSchema7Version = string;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* JSON Schema v7
|
|
59
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
|
60
|
-
*/
|
|
61
|
-
type JSONSchema7Definition = JSONSchema7 | boolean;
|
|
62
|
-
interface JSONSchema7 {
|
|
63
|
-
$id?: string | undefined;
|
|
64
|
-
$ref?: string | undefined;
|
|
65
|
-
$schema?: JSONSchema7Version | undefined;
|
|
66
|
-
$comment?: string | undefined;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
|
|
70
|
-
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
|
|
71
|
-
*/
|
|
72
|
-
$defs?: {
|
|
73
|
-
[key: string]: JSONSchema7Definition;
|
|
74
|
-
} | undefined;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
|
|
78
|
-
*/
|
|
79
|
-
type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
|
|
80
|
-
enum?: JSONSchema7Type[] | undefined;
|
|
81
|
-
const?: JSONSchema7Type | undefined;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
|
|
85
|
-
*/
|
|
86
|
-
multipleOf?: number | undefined;
|
|
87
|
-
maximum?: number | undefined;
|
|
88
|
-
exclusiveMaximum?: number | undefined;
|
|
89
|
-
minimum?: number | undefined;
|
|
90
|
-
exclusiveMinimum?: number | undefined;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
|
|
94
|
-
*/
|
|
95
|
-
maxLength?: number | undefined;
|
|
96
|
-
minLength?: number | undefined;
|
|
97
|
-
pattern?: string | undefined;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
|
|
101
|
-
*/
|
|
102
|
-
items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
|
|
103
|
-
additionalItems?: JSONSchema7Definition | undefined;
|
|
104
|
-
maxItems?: number | undefined;
|
|
105
|
-
minItems?: number | undefined;
|
|
106
|
-
uniqueItems?: boolean | undefined;
|
|
107
|
-
contains?: JSONSchema7Definition | undefined;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
|
|
111
|
-
*/
|
|
112
|
-
maxProperties?: number | undefined;
|
|
113
|
-
minProperties?: number | undefined;
|
|
114
|
-
required?: string[] | undefined;
|
|
115
|
-
properties?: {
|
|
116
|
-
[key: string]: JSONSchema7Definition;
|
|
117
|
-
} | undefined;
|
|
118
|
-
patternProperties?: {
|
|
119
|
-
[key: string]: JSONSchema7Definition;
|
|
120
|
-
} | undefined;
|
|
121
|
-
additionalProperties?: JSONSchema7Definition | undefined;
|
|
122
|
-
dependencies?: {
|
|
123
|
-
[key: string]: JSONSchema7Definition | string[];
|
|
124
|
-
} | undefined;
|
|
125
|
-
propertyNames?: JSONSchema7Definition | undefined;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
|
|
129
|
-
*/
|
|
130
|
-
if?: JSONSchema7Definition | undefined;
|
|
131
|
-
then?: JSONSchema7Definition | undefined;
|
|
132
|
-
else?: JSONSchema7Definition | undefined;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
|
|
136
|
-
*/
|
|
137
|
-
allOf?: JSONSchema7Definition[] | undefined;
|
|
138
|
-
anyOf?: JSONSchema7Definition[] | undefined;
|
|
139
|
-
oneOf?: JSONSchema7Definition[] | undefined;
|
|
140
|
-
not?: JSONSchema7Definition | undefined;
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
|
|
144
|
-
*/
|
|
145
|
-
format?: string | undefined;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
|
|
149
|
-
*/
|
|
150
|
-
contentMediaType?: string | undefined;
|
|
151
|
-
contentEncoding?: string | undefined;
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
|
|
155
|
-
*/
|
|
156
|
-
definitions?: {
|
|
157
|
-
[key: string]: JSONSchema7Definition;
|
|
158
|
-
} | undefined;
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
|
|
162
|
-
*/
|
|
163
|
-
title?: string | undefined;
|
|
164
|
-
description?: string | undefined;
|
|
165
|
-
default?: JSONSchema7Type | undefined;
|
|
166
|
-
readOnly?: boolean | undefined;
|
|
167
|
-
writeOnly?: boolean | undefined;
|
|
168
|
-
examples?: JSONSchema7Type | undefined;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
interface PropertyMetaData {
|
|
172
|
-
hasDefaultValue: boolean;
|
|
173
|
-
isScalar: boolean;
|
|
174
|
-
required: boolean;
|
|
175
|
-
}
|
|
176
|
-
interface ModelMetaData {
|
|
177
|
-
enums: ReadonlyDeep<DMMF.DatamodelEnum[]>;
|
|
178
|
-
}
|
|
179
|
-
type DefinitionMap = [name: string, definition: JSONSchema7Definition];
|
|
180
|
-
type PropertyMap = [...DefinitionMap, PropertyMetaData];
|
|
181
|
-
interface TransformOptions {
|
|
182
|
-
includeRequiredFields?: "false" | "true";
|
|
183
|
-
keepRelationScalarFields?: "false" | "true";
|
|
184
|
-
persistOriginalType?: "false" | "true";
|
|
185
|
-
schemaId?: string;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
declare const getJSONSchemaProperty: (modelMetaData: ModelMetaData, transformOptions: TransformOptions) => (field: DMMF.Field) => PropertyMap;
|
|
189
|
-
|
|
190
|
-
declare const transformDmmf: (dmmf: DMMF.Document, transformOptions?: TransformOptions) => JSONSchema7;
|
|
191
|
-
|
|
192
|
-
export { getJSONSchemaProperty, transformDmmf as transformDMMF };
|
|
193
|
-
export type { DefinitionMap, ModelMetaData, PropertyMap, PropertyMetaData, TransformOptions };
|
|
1
|
+
export { default as getJSONSchemaProperty } from "./get-json-schema-property.d.cts";
|
|
2
|
+
export { default as transformDMMF } from "./transform-dmmf.d.cts";
|
|
3
|
+
export type { DefinitionMap, ModelMetaData, PropertyMap, PropertyMetaData, TransformOptions } from "./types.d.cts";
|
package/dist/index.d.mts
CHANGED
|
@@ -1,193 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// ==================================================================================================
|
|
5
|
-
// JSON Schema Draft 07
|
|
6
|
-
// ==================================================================================================
|
|
7
|
-
// https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
|
8
|
-
// --------------------------------------------------------------------------------------------------
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Primitive type
|
|
12
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
|
13
|
-
*/
|
|
14
|
-
type JSONSchema7TypeName =
|
|
15
|
-
| "string" //
|
|
16
|
-
| "number"
|
|
17
|
-
| "integer"
|
|
18
|
-
| "boolean"
|
|
19
|
-
| "object"
|
|
20
|
-
| "array"
|
|
21
|
-
| "null";
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Primitive type
|
|
25
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
|
26
|
-
*/
|
|
27
|
-
type JSONSchema7Type =
|
|
28
|
-
| string //
|
|
29
|
-
| number
|
|
30
|
-
| boolean
|
|
31
|
-
| JSONSchema7Object
|
|
32
|
-
| JSONSchema7Array
|
|
33
|
-
| null;
|
|
34
|
-
|
|
35
|
-
// Workaround for infinite type recursion
|
|
36
|
-
interface JSONSchema7Object {
|
|
37
|
-
[key: string]: JSONSchema7Type;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Workaround for infinite type recursion
|
|
41
|
-
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
|
42
|
-
interface JSONSchema7Array extends Array<JSONSchema7Type> {}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Meta schema
|
|
46
|
-
*
|
|
47
|
-
* Recommended values:
|
|
48
|
-
* - 'http://json-schema.org/schema#'
|
|
49
|
-
* - 'http://json-schema.org/hyper-schema#'
|
|
50
|
-
* - 'http://json-schema.org/draft-07/schema#'
|
|
51
|
-
* - 'http://json-schema.org/draft-07/hyper-schema#'
|
|
52
|
-
*
|
|
53
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
|
|
54
|
-
*/
|
|
55
|
-
type JSONSchema7Version = string;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* JSON Schema v7
|
|
59
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
|
60
|
-
*/
|
|
61
|
-
type JSONSchema7Definition = JSONSchema7 | boolean;
|
|
62
|
-
interface JSONSchema7 {
|
|
63
|
-
$id?: string | undefined;
|
|
64
|
-
$ref?: string | undefined;
|
|
65
|
-
$schema?: JSONSchema7Version | undefined;
|
|
66
|
-
$comment?: string | undefined;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
|
|
70
|
-
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
|
|
71
|
-
*/
|
|
72
|
-
$defs?: {
|
|
73
|
-
[key: string]: JSONSchema7Definition;
|
|
74
|
-
} | undefined;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
|
|
78
|
-
*/
|
|
79
|
-
type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
|
|
80
|
-
enum?: JSONSchema7Type[] | undefined;
|
|
81
|
-
const?: JSONSchema7Type | undefined;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
|
|
85
|
-
*/
|
|
86
|
-
multipleOf?: number | undefined;
|
|
87
|
-
maximum?: number | undefined;
|
|
88
|
-
exclusiveMaximum?: number | undefined;
|
|
89
|
-
minimum?: number | undefined;
|
|
90
|
-
exclusiveMinimum?: number | undefined;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
|
|
94
|
-
*/
|
|
95
|
-
maxLength?: number | undefined;
|
|
96
|
-
minLength?: number | undefined;
|
|
97
|
-
pattern?: string | undefined;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
|
|
101
|
-
*/
|
|
102
|
-
items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
|
|
103
|
-
additionalItems?: JSONSchema7Definition | undefined;
|
|
104
|
-
maxItems?: number | undefined;
|
|
105
|
-
minItems?: number | undefined;
|
|
106
|
-
uniqueItems?: boolean | undefined;
|
|
107
|
-
contains?: JSONSchema7Definition | undefined;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
|
|
111
|
-
*/
|
|
112
|
-
maxProperties?: number | undefined;
|
|
113
|
-
minProperties?: number | undefined;
|
|
114
|
-
required?: string[] | undefined;
|
|
115
|
-
properties?: {
|
|
116
|
-
[key: string]: JSONSchema7Definition;
|
|
117
|
-
} | undefined;
|
|
118
|
-
patternProperties?: {
|
|
119
|
-
[key: string]: JSONSchema7Definition;
|
|
120
|
-
} | undefined;
|
|
121
|
-
additionalProperties?: JSONSchema7Definition | undefined;
|
|
122
|
-
dependencies?: {
|
|
123
|
-
[key: string]: JSONSchema7Definition | string[];
|
|
124
|
-
} | undefined;
|
|
125
|
-
propertyNames?: JSONSchema7Definition | undefined;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
|
|
129
|
-
*/
|
|
130
|
-
if?: JSONSchema7Definition | undefined;
|
|
131
|
-
then?: JSONSchema7Definition | undefined;
|
|
132
|
-
else?: JSONSchema7Definition | undefined;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
|
|
136
|
-
*/
|
|
137
|
-
allOf?: JSONSchema7Definition[] | undefined;
|
|
138
|
-
anyOf?: JSONSchema7Definition[] | undefined;
|
|
139
|
-
oneOf?: JSONSchema7Definition[] | undefined;
|
|
140
|
-
not?: JSONSchema7Definition | undefined;
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
|
|
144
|
-
*/
|
|
145
|
-
format?: string | undefined;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
|
|
149
|
-
*/
|
|
150
|
-
contentMediaType?: string | undefined;
|
|
151
|
-
contentEncoding?: string | undefined;
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
|
|
155
|
-
*/
|
|
156
|
-
definitions?: {
|
|
157
|
-
[key: string]: JSONSchema7Definition;
|
|
158
|
-
} | undefined;
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
|
|
162
|
-
*/
|
|
163
|
-
title?: string | undefined;
|
|
164
|
-
description?: string | undefined;
|
|
165
|
-
default?: JSONSchema7Type | undefined;
|
|
166
|
-
readOnly?: boolean | undefined;
|
|
167
|
-
writeOnly?: boolean | undefined;
|
|
168
|
-
examples?: JSONSchema7Type | undefined;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
interface PropertyMetaData {
|
|
172
|
-
hasDefaultValue: boolean;
|
|
173
|
-
isScalar: boolean;
|
|
174
|
-
required: boolean;
|
|
175
|
-
}
|
|
176
|
-
interface ModelMetaData {
|
|
177
|
-
enums: ReadonlyDeep<DMMF.DatamodelEnum[]>;
|
|
178
|
-
}
|
|
179
|
-
type DefinitionMap = [name: string, definition: JSONSchema7Definition];
|
|
180
|
-
type PropertyMap = [...DefinitionMap, PropertyMetaData];
|
|
181
|
-
interface TransformOptions {
|
|
182
|
-
includeRequiredFields?: "false" | "true";
|
|
183
|
-
keepRelationScalarFields?: "false" | "true";
|
|
184
|
-
persistOriginalType?: "false" | "true";
|
|
185
|
-
schemaId?: string;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
declare const getJSONSchemaProperty: (modelMetaData: ModelMetaData, transformOptions: TransformOptions) => (field: DMMF.Field) => PropertyMap;
|
|
189
|
-
|
|
190
|
-
declare const transformDmmf: (dmmf: DMMF.Document, transformOptions?: TransformOptions) => JSONSchema7;
|
|
191
|
-
|
|
192
|
-
export { getJSONSchemaProperty, transformDmmf as transformDMMF };
|
|
193
|
-
export type { DefinitionMap, ModelMetaData, PropertyMap, PropertyMetaData, TransformOptions };
|
|
1
|
+
export { default as getJSONSchemaProperty } from "./get-json-schema-property.d.mts";
|
|
2
|
+
export { default as transformDMMF } from "./transform-dmmf.d.mts";
|
|
3
|
+
export type { DefinitionMap, ModelMetaData, PropertyMap, PropertyMetaData, TransformOptions } from "./types.d.mts";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,193 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// ==================================================================================================
|
|
5
|
-
// JSON Schema Draft 07
|
|
6
|
-
// ==================================================================================================
|
|
7
|
-
// https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
|
8
|
-
// --------------------------------------------------------------------------------------------------
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Primitive type
|
|
12
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
|
13
|
-
*/
|
|
14
|
-
type JSONSchema7TypeName =
|
|
15
|
-
| "string" //
|
|
16
|
-
| "number"
|
|
17
|
-
| "integer"
|
|
18
|
-
| "boolean"
|
|
19
|
-
| "object"
|
|
20
|
-
| "array"
|
|
21
|
-
| "null";
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Primitive type
|
|
25
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
|
26
|
-
*/
|
|
27
|
-
type JSONSchema7Type =
|
|
28
|
-
| string //
|
|
29
|
-
| number
|
|
30
|
-
| boolean
|
|
31
|
-
| JSONSchema7Object
|
|
32
|
-
| JSONSchema7Array
|
|
33
|
-
| null;
|
|
34
|
-
|
|
35
|
-
// Workaround for infinite type recursion
|
|
36
|
-
interface JSONSchema7Object {
|
|
37
|
-
[key: string]: JSONSchema7Type;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Workaround for infinite type recursion
|
|
41
|
-
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
|
42
|
-
interface JSONSchema7Array extends Array<JSONSchema7Type> {}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Meta schema
|
|
46
|
-
*
|
|
47
|
-
* Recommended values:
|
|
48
|
-
* - 'http://json-schema.org/schema#'
|
|
49
|
-
* - 'http://json-schema.org/hyper-schema#'
|
|
50
|
-
* - 'http://json-schema.org/draft-07/schema#'
|
|
51
|
-
* - 'http://json-schema.org/draft-07/hyper-schema#'
|
|
52
|
-
*
|
|
53
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
|
|
54
|
-
*/
|
|
55
|
-
type JSONSchema7Version = string;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* JSON Schema v7
|
|
59
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
|
60
|
-
*/
|
|
61
|
-
type JSONSchema7Definition = JSONSchema7 | boolean;
|
|
62
|
-
interface JSONSchema7 {
|
|
63
|
-
$id?: string | undefined;
|
|
64
|
-
$ref?: string | undefined;
|
|
65
|
-
$schema?: JSONSchema7Version | undefined;
|
|
66
|
-
$comment?: string | undefined;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
|
|
70
|
-
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
|
|
71
|
-
*/
|
|
72
|
-
$defs?: {
|
|
73
|
-
[key: string]: JSONSchema7Definition;
|
|
74
|
-
} | undefined;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
|
|
78
|
-
*/
|
|
79
|
-
type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
|
|
80
|
-
enum?: JSONSchema7Type[] | undefined;
|
|
81
|
-
const?: JSONSchema7Type | undefined;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
|
|
85
|
-
*/
|
|
86
|
-
multipleOf?: number | undefined;
|
|
87
|
-
maximum?: number | undefined;
|
|
88
|
-
exclusiveMaximum?: number | undefined;
|
|
89
|
-
minimum?: number | undefined;
|
|
90
|
-
exclusiveMinimum?: number | undefined;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
|
|
94
|
-
*/
|
|
95
|
-
maxLength?: number | undefined;
|
|
96
|
-
minLength?: number | undefined;
|
|
97
|
-
pattern?: string | undefined;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
|
|
101
|
-
*/
|
|
102
|
-
items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
|
|
103
|
-
additionalItems?: JSONSchema7Definition | undefined;
|
|
104
|
-
maxItems?: number | undefined;
|
|
105
|
-
minItems?: number | undefined;
|
|
106
|
-
uniqueItems?: boolean | undefined;
|
|
107
|
-
contains?: JSONSchema7Definition | undefined;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
|
|
111
|
-
*/
|
|
112
|
-
maxProperties?: number | undefined;
|
|
113
|
-
minProperties?: number | undefined;
|
|
114
|
-
required?: string[] | undefined;
|
|
115
|
-
properties?: {
|
|
116
|
-
[key: string]: JSONSchema7Definition;
|
|
117
|
-
} | undefined;
|
|
118
|
-
patternProperties?: {
|
|
119
|
-
[key: string]: JSONSchema7Definition;
|
|
120
|
-
} | undefined;
|
|
121
|
-
additionalProperties?: JSONSchema7Definition | undefined;
|
|
122
|
-
dependencies?: {
|
|
123
|
-
[key: string]: JSONSchema7Definition | string[];
|
|
124
|
-
} | undefined;
|
|
125
|
-
propertyNames?: JSONSchema7Definition | undefined;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
|
|
129
|
-
*/
|
|
130
|
-
if?: JSONSchema7Definition | undefined;
|
|
131
|
-
then?: JSONSchema7Definition | undefined;
|
|
132
|
-
else?: JSONSchema7Definition | undefined;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
|
|
136
|
-
*/
|
|
137
|
-
allOf?: JSONSchema7Definition[] | undefined;
|
|
138
|
-
anyOf?: JSONSchema7Definition[] | undefined;
|
|
139
|
-
oneOf?: JSONSchema7Definition[] | undefined;
|
|
140
|
-
not?: JSONSchema7Definition | undefined;
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
|
|
144
|
-
*/
|
|
145
|
-
format?: string | undefined;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
|
|
149
|
-
*/
|
|
150
|
-
contentMediaType?: string | undefined;
|
|
151
|
-
contentEncoding?: string | undefined;
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
|
|
155
|
-
*/
|
|
156
|
-
definitions?: {
|
|
157
|
-
[key: string]: JSONSchema7Definition;
|
|
158
|
-
} | undefined;
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
|
|
162
|
-
*/
|
|
163
|
-
title?: string | undefined;
|
|
164
|
-
description?: string | undefined;
|
|
165
|
-
default?: JSONSchema7Type | undefined;
|
|
166
|
-
readOnly?: boolean | undefined;
|
|
167
|
-
writeOnly?: boolean | undefined;
|
|
168
|
-
examples?: JSONSchema7Type | undefined;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
interface PropertyMetaData {
|
|
172
|
-
hasDefaultValue: boolean;
|
|
173
|
-
isScalar: boolean;
|
|
174
|
-
required: boolean;
|
|
175
|
-
}
|
|
176
|
-
interface ModelMetaData {
|
|
177
|
-
enums: ReadonlyDeep<DMMF.DatamodelEnum[]>;
|
|
178
|
-
}
|
|
179
|
-
type DefinitionMap = [name: string, definition: JSONSchema7Definition];
|
|
180
|
-
type PropertyMap = [...DefinitionMap, PropertyMetaData];
|
|
181
|
-
interface TransformOptions {
|
|
182
|
-
includeRequiredFields?: "false" | "true";
|
|
183
|
-
keepRelationScalarFields?: "false" | "true";
|
|
184
|
-
persistOriginalType?: "false" | "true";
|
|
185
|
-
schemaId?: string;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
declare const getJSONSchemaProperty: (modelMetaData: ModelMetaData, transformOptions: TransformOptions) => (field: DMMF.Field) => PropertyMap;
|
|
189
|
-
|
|
190
|
-
declare const transformDmmf: (dmmf: DMMF.Document, transformOptions?: TransformOptions) => JSONSchema7;
|
|
191
|
-
|
|
192
|
-
export { getJSONSchemaProperty, transformDmmf as transformDMMF };
|
|
193
|
-
export type { DefinitionMap, ModelMetaData, PropertyMap, PropertyMetaData, TransformOptions };
|
|
1
|
+
export { default as getJSONSchemaProperty } from "./get-json-schema-property.d.ts";
|
|
2
|
+
export { default as transformDMMF } from "./transform-dmmf.d.ts";
|
|
3
|
+
export type { DefinitionMap, ModelMetaData, PropertyMap, PropertyMetaData, TransformOptions } from "./types.d.ts";
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export { default as getJSONSchemaProperty } from './packem_shared/getJSONSchemaProperty-ChH8N6gd.mjs';
|
|
2
|
+
export { default as transformDMMF } from './packem_shared/transformDMMF-D2pok2ta.mjs';
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const assert = __cjs_getBuiltinModule("node:assert");
|
|
21
|
+
|
|
22
|
+
const isDefined = (value) => value !== void 0 && value !== null;
|
|
23
|
+
const getJSONSchemaScalar = (fieldType) => {
|
|
24
|
+
switch (fieldType) {
|
|
25
|
+
case "BigInt":
|
|
26
|
+
case "Int": {
|
|
27
|
+
return "integer";
|
|
28
|
+
}
|
|
29
|
+
case "Boolean": {
|
|
30
|
+
return "boolean";
|
|
31
|
+
}
|
|
32
|
+
case "Bytes":
|
|
33
|
+
case "DateTime":
|
|
34
|
+
case "String": {
|
|
35
|
+
return "string";
|
|
36
|
+
}
|
|
37
|
+
case "Decimal":
|
|
38
|
+
case "Float": {
|
|
39
|
+
return "number";
|
|
40
|
+
}
|
|
41
|
+
case "Json": {
|
|
42
|
+
return ["number", "string", "boolean", "object", "array", "null"];
|
|
43
|
+
}
|
|
44
|
+
default: {
|
|
45
|
+
throw new Error(`Unhandled discriminated union member: ${JSON.stringify(fieldType)}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const getJSONSchemaType = (field) => {
|
|
50
|
+
const { isList, isRequired, kind, type } = field;
|
|
51
|
+
let scalarFieldType = "object";
|
|
52
|
+
if (kind === "scalar" && !isList) {
|
|
53
|
+
scalarFieldType = getJSONSchemaScalar(type);
|
|
54
|
+
} else if (isList) {
|
|
55
|
+
scalarFieldType = "array";
|
|
56
|
+
} else if (kind === "enum") {
|
|
57
|
+
scalarFieldType = "string";
|
|
58
|
+
}
|
|
59
|
+
if (isRequired || isList) {
|
|
60
|
+
return scalarFieldType;
|
|
61
|
+
}
|
|
62
|
+
const isFieldUnion = Array.isArray(scalarFieldType);
|
|
63
|
+
if (isFieldUnion) {
|
|
64
|
+
return [.../* @__PURE__ */ new Set(["null", ...scalarFieldType])];
|
|
65
|
+
}
|
|
66
|
+
return [scalarFieldType, "null"];
|
|
67
|
+
};
|
|
68
|
+
const getDefaultValue = (field) => {
|
|
69
|
+
const fieldDefault = field.default;
|
|
70
|
+
if (!field.hasDefaultValue) {
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
if (field.kind === "enum") {
|
|
74
|
+
return typeof fieldDefault === "string" ? fieldDefault : void 0;
|
|
75
|
+
}
|
|
76
|
+
if (field.kind !== "scalar") {
|
|
77
|
+
return void 0;
|
|
78
|
+
}
|
|
79
|
+
switch (field.type) {
|
|
80
|
+
case "BigInt":
|
|
81
|
+
case "DateTime":
|
|
82
|
+
case "String": {
|
|
83
|
+
return typeof fieldDefault === "string" ? fieldDefault : void 0;
|
|
84
|
+
}
|
|
85
|
+
case "Boolean": {
|
|
86
|
+
return typeof fieldDefault === "boolean" ? fieldDefault : void 0;
|
|
87
|
+
}
|
|
88
|
+
case "Bytes":
|
|
89
|
+
case "Json": {
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
92
|
+
case "Decimal":
|
|
93
|
+
case "Float":
|
|
94
|
+
case "Int": {
|
|
95
|
+
return typeof fieldDefault === "number" ? fieldDefault : void 0;
|
|
96
|
+
}
|
|
97
|
+
default: {
|
|
98
|
+
throw new Error(`Unhandled discriminated union member: ${JSON.stringify(field.type)}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const getFormatByDMMFType = (fieldType) => {
|
|
103
|
+
if (fieldType === "DateTime") {
|
|
104
|
+
return "date-time";
|
|
105
|
+
}
|
|
106
|
+
return void 0;
|
|
107
|
+
};
|
|
108
|
+
const getJSONSchemaForPropertyReference = (field, { persistOriginalType, schemaId }) => {
|
|
109
|
+
const notNullable = field.isRequired || field.isList;
|
|
110
|
+
assert.equal(typeof field.type, "string");
|
|
111
|
+
const typeReference = `#/definitions/${field.type}`;
|
|
112
|
+
const reference = { $ref: schemaId ? `${schemaId}${typeReference}` : typeReference };
|
|
113
|
+
return notNullable ? reference : {
|
|
114
|
+
anyOf: [reference, { type: "null" }],
|
|
115
|
+
...persistOriginalType && {
|
|
116
|
+
originalType: field.type
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
const getItemsByDMMFType = (field, transformOptions) => {
|
|
121
|
+
if (field.kind === "scalar" && !field.isList || field.kind === "enum") {
|
|
122
|
+
return void 0;
|
|
123
|
+
}
|
|
124
|
+
if (field.kind === "scalar" && field.isList) {
|
|
125
|
+
return { type: getJSONSchemaScalar(field.type) };
|
|
126
|
+
}
|
|
127
|
+
return getJSONSchemaForPropertyReference(field, transformOptions);
|
|
128
|
+
};
|
|
129
|
+
const isSingleReference = (field) => field.kind !== "scalar" && !field.isList && field.kind !== "enum";
|
|
130
|
+
const getEnumListByDMMFType = (modelMetaData) => (field) => {
|
|
131
|
+
const enumItem = modelMetaData.enums.find(({ name }) => name === field.type);
|
|
132
|
+
if (!enumItem) {
|
|
133
|
+
return void 0;
|
|
134
|
+
}
|
|
135
|
+
return enumItem.values.map((item) => item.name);
|
|
136
|
+
};
|
|
137
|
+
const getDescription = (field) => field.documentation;
|
|
138
|
+
const getPropertyDefinition = (modelMetaData, transformOptions, field) => {
|
|
139
|
+
const type = getJSONSchemaType(field);
|
|
140
|
+
const format = getFormatByDMMFType(field.type);
|
|
141
|
+
const items = getItemsByDMMFType(field, transformOptions);
|
|
142
|
+
const enumList = getEnumListByDMMFType(modelMetaData)(field);
|
|
143
|
+
const defaultValue = getDefaultValue(field);
|
|
144
|
+
const description = getDescription(field);
|
|
145
|
+
return {
|
|
146
|
+
type,
|
|
147
|
+
...transformOptions.persistOriginalType && {
|
|
148
|
+
originalType: field.type
|
|
149
|
+
},
|
|
150
|
+
...isDefined(defaultValue) && { default: defaultValue },
|
|
151
|
+
...isDefined(format) && { format },
|
|
152
|
+
...isDefined(items) && { items },
|
|
153
|
+
...isDefined(enumList) && { enum: enumList },
|
|
154
|
+
...isDefined(description) && { description }
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
const getJSONSchemaProperty = (modelMetaData, transformOptions) => (field) => {
|
|
158
|
+
const propertyMetaData = {
|
|
159
|
+
hasDefaultValue: field.hasDefaultValue,
|
|
160
|
+
isScalar: field.kind === "scalar" || field.kind === "enum",
|
|
161
|
+
required: field.isRequired
|
|
162
|
+
};
|
|
163
|
+
const property = isSingleReference(field) ? getJSONSchemaForPropertyReference(field, transformOptions) : getPropertyDefinition(modelMetaData, transformOptions, field);
|
|
164
|
+
return [field.name, property, propertyMetaData];
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export { getJSONSchemaProperty as default };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert');
|
|
4
|
+
|
|
5
|
+
const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
|
|
6
|
+
|
|
7
|
+
const assert__default = /*#__PURE__*/_interopDefaultCompat(assert);
|
|
8
|
+
|
|
9
|
+
const isDefined = (value) => value !== void 0 && value !== null;
|
|
10
|
+
const getJSONSchemaScalar = (fieldType) => {
|
|
11
|
+
switch (fieldType) {
|
|
12
|
+
case "BigInt":
|
|
13
|
+
case "Int": {
|
|
14
|
+
return "integer";
|
|
15
|
+
}
|
|
16
|
+
case "Boolean": {
|
|
17
|
+
return "boolean";
|
|
18
|
+
}
|
|
19
|
+
case "Bytes":
|
|
20
|
+
case "DateTime":
|
|
21
|
+
case "String": {
|
|
22
|
+
return "string";
|
|
23
|
+
}
|
|
24
|
+
case "Decimal":
|
|
25
|
+
case "Float": {
|
|
26
|
+
return "number";
|
|
27
|
+
}
|
|
28
|
+
case "Json": {
|
|
29
|
+
return ["number", "string", "boolean", "object", "array", "null"];
|
|
30
|
+
}
|
|
31
|
+
default: {
|
|
32
|
+
throw new Error(`Unhandled discriminated union member: ${JSON.stringify(fieldType)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const getJSONSchemaType = (field) => {
|
|
37
|
+
const { isList, isRequired, kind, type } = field;
|
|
38
|
+
let scalarFieldType = "object";
|
|
39
|
+
if (kind === "scalar" && !isList) {
|
|
40
|
+
scalarFieldType = getJSONSchemaScalar(type);
|
|
41
|
+
} else if (isList) {
|
|
42
|
+
scalarFieldType = "array";
|
|
43
|
+
} else if (kind === "enum") {
|
|
44
|
+
scalarFieldType = "string";
|
|
45
|
+
}
|
|
46
|
+
if (isRequired || isList) {
|
|
47
|
+
return scalarFieldType;
|
|
48
|
+
}
|
|
49
|
+
const isFieldUnion = Array.isArray(scalarFieldType);
|
|
50
|
+
if (isFieldUnion) {
|
|
51
|
+
return [.../* @__PURE__ */ new Set(["null", ...scalarFieldType])];
|
|
52
|
+
}
|
|
53
|
+
return [scalarFieldType, "null"];
|
|
54
|
+
};
|
|
55
|
+
const getDefaultValue = (field) => {
|
|
56
|
+
const fieldDefault = field.default;
|
|
57
|
+
if (!field.hasDefaultValue) {
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
if (field.kind === "enum") {
|
|
61
|
+
return typeof fieldDefault === "string" ? fieldDefault : void 0;
|
|
62
|
+
}
|
|
63
|
+
if (field.kind !== "scalar") {
|
|
64
|
+
return void 0;
|
|
65
|
+
}
|
|
66
|
+
switch (field.type) {
|
|
67
|
+
case "BigInt":
|
|
68
|
+
case "DateTime":
|
|
69
|
+
case "String": {
|
|
70
|
+
return typeof fieldDefault === "string" ? fieldDefault : void 0;
|
|
71
|
+
}
|
|
72
|
+
case "Boolean": {
|
|
73
|
+
return typeof fieldDefault === "boolean" ? fieldDefault : void 0;
|
|
74
|
+
}
|
|
75
|
+
case "Bytes":
|
|
76
|
+
case "Json": {
|
|
77
|
+
return void 0;
|
|
78
|
+
}
|
|
79
|
+
case "Decimal":
|
|
80
|
+
case "Float":
|
|
81
|
+
case "Int": {
|
|
82
|
+
return typeof fieldDefault === "number" ? fieldDefault : void 0;
|
|
83
|
+
}
|
|
84
|
+
default: {
|
|
85
|
+
throw new Error(`Unhandled discriminated union member: ${JSON.stringify(field.type)}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const getFormatByDMMFType = (fieldType) => {
|
|
90
|
+
if (fieldType === "DateTime") {
|
|
91
|
+
return "date-time";
|
|
92
|
+
}
|
|
93
|
+
return void 0;
|
|
94
|
+
};
|
|
95
|
+
const getJSONSchemaForPropertyReference = (field, { persistOriginalType, schemaId }) => {
|
|
96
|
+
const notNullable = field.isRequired || field.isList;
|
|
97
|
+
assert__default.equal(typeof field.type, "string");
|
|
98
|
+
const typeReference = `#/definitions/${field.type}`;
|
|
99
|
+
const reference = { $ref: schemaId ? `${schemaId}${typeReference}` : typeReference };
|
|
100
|
+
return notNullable ? reference : {
|
|
101
|
+
anyOf: [reference, { type: "null" }],
|
|
102
|
+
...persistOriginalType && {
|
|
103
|
+
originalType: field.type
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
const getItemsByDMMFType = (field, transformOptions) => {
|
|
108
|
+
if (field.kind === "scalar" && !field.isList || field.kind === "enum") {
|
|
109
|
+
return void 0;
|
|
110
|
+
}
|
|
111
|
+
if (field.kind === "scalar" && field.isList) {
|
|
112
|
+
return { type: getJSONSchemaScalar(field.type) };
|
|
113
|
+
}
|
|
114
|
+
return getJSONSchemaForPropertyReference(field, transformOptions);
|
|
115
|
+
};
|
|
116
|
+
const isSingleReference = (field) => field.kind !== "scalar" && !field.isList && field.kind !== "enum";
|
|
117
|
+
const getEnumListByDMMFType = (modelMetaData) => (field) => {
|
|
118
|
+
const enumItem = modelMetaData.enums.find(({ name }) => name === field.type);
|
|
119
|
+
if (!enumItem) {
|
|
120
|
+
return void 0;
|
|
121
|
+
}
|
|
122
|
+
return enumItem.values.map((item) => item.name);
|
|
123
|
+
};
|
|
124
|
+
const getDescription = (field) => field.documentation;
|
|
125
|
+
const getPropertyDefinition = (modelMetaData, transformOptions, field) => {
|
|
126
|
+
const type = getJSONSchemaType(field);
|
|
127
|
+
const format = getFormatByDMMFType(field.type);
|
|
128
|
+
const items = getItemsByDMMFType(field, transformOptions);
|
|
129
|
+
const enumList = getEnumListByDMMFType(modelMetaData)(field);
|
|
130
|
+
const defaultValue = getDefaultValue(field);
|
|
131
|
+
const description = getDescription(field);
|
|
132
|
+
return {
|
|
133
|
+
type,
|
|
134
|
+
...transformOptions.persistOriginalType && {
|
|
135
|
+
originalType: field.type
|
|
136
|
+
},
|
|
137
|
+
...isDefined(defaultValue) && { default: defaultValue },
|
|
138
|
+
...isDefined(format) && { format },
|
|
139
|
+
...isDefined(items) && { items },
|
|
140
|
+
...isDefined(enumList) && { enum: enumList },
|
|
141
|
+
...isDefined(description) && { description }
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
const getJSONSchemaProperty = (modelMetaData, transformOptions) => (field) => {
|
|
145
|
+
const propertyMetaData = {
|
|
146
|
+
hasDefaultValue: field.hasDefaultValue,
|
|
147
|
+
isScalar: field.kind === "scalar" || field.kind === "enum",
|
|
148
|
+
required: field.isRequired
|
|
149
|
+
};
|
|
150
|
+
const property = isSingleReference(field) ? getJSONSchemaForPropertyReference(field, transformOptions) : getPropertyDefinition(modelMetaData, transformOptions, field);
|
|
151
|
+
return [field.name, property, propertyMetaData];
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
module.exports = getJSONSchemaProperty;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import getJSONSchemaProperty from './getJSONSchemaProperty-ChH8N6gd.mjs';
|
|
2
|
+
|
|
3
|
+
const getRelationScalarFields = (model) => model.fields.flatMap((field) => field.relationFromFields ?? []);
|
|
4
|
+
const getJSONSchemaModel = (modelMetaData, transformOptions) => (model) => {
|
|
5
|
+
const definitionPropertiesMap = model.fields.map(getJSONSchemaProperty(modelMetaData, transformOptions));
|
|
6
|
+
const propertiesMap = definitionPropertiesMap.map(([name, definition2]) => [name, definition2]);
|
|
7
|
+
const relationScalarFields = getRelationScalarFields(model);
|
|
8
|
+
const propertiesWithoutRelationScalars = propertiesMap.filter((property) => !relationScalarFields.includes(property[0]));
|
|
9
|
+
const properties = Object.fromEntries(transformOptions.keepRelationScalarFields === "true" ? propertiesMap : propertiesWithoutRelationScalars);
|
|
10
|
+
const definition = {
|
|
11
|
+
properties,
|
|
12
|
+
type: "object"
|
|
13
|
+
};
|
|
14
|
+
if (transformOptions.includeRequiredFields) {
|
|
15
|
+
definition.required = definitionPropertiesMap.reduce((filtered, [name, , fieldMetaData]) => {
|
|
16
|
+
if (fieldMetaData.required && fieldMetaData.isScalar && !fieldMetaData.hasDefaultValue) {
|
|
17
|
+
filtered.push(name);
|
|
18
|
+
}
|
|
19
|
+
return filtered;
|
|
20
|
+
}, []);
|
|
21
|
+
}
|
|
22
|
+
return [model.name, definition];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const toCamelCase = (name) => name.slice(0, 1).toLowerCase() + name.slice(1);
|
|
26
|
+
const getPropertyDefinition = ({ schemaId }) => (model) => {
|
|
27
|
+
const reference = `#/definitions/${model.name}`;
|
|
28
|
+
return [
|
|
29
|
+
toCamelCase(model.name),
|
|
30
|
+
{
|
|
31
|
+
$ref: schemaId ? `${schemaId}${reference}` : reference
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
};
|
|
35
|
+
const transformDmmf = (dmmf, transformOptions = {}) => {
|
|
36
|
+
const { enums = [], models = [], types = [] } = dmmf.datamodel;
|
|
37
|
+
const initialJSON = {
|
|
38
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
39
|
+
definitions: {},
|
|
40
|
+
type: "object"
|
|
41
|
+
};
|
|
42
|
+
const { schemaId } = transformOptions;
|
|
43
|
+
const modelDefinitionsMap = models.map(getJSONSchemaModel({ enums }, transformOptions));
|
|
44
|
+
const typeDefinitionsMap = types.map(getJSONSchemaModel({ enums }, transformOptions));
|
|
45
|
+
const modelPropertyDefinitionsMap = models.map(getPropertyDefinition(transformOptions));
|
|
46
|
+
const definitions = Object.fromEntries([...modelDefinitionsMap, ...typeDefinitionsMap]);
|
|
47
|
+
const properties = Object.fromEntries(modelPropertyDefinitionsMap);
|
|
48
|
+
return {
|
|
49
|
+
...schemaId ? { $id: schemaId } : void 0,
|
|
50
|
+
...initialJSON,
|
|
51
|
+
definitions,
|
|
52
|
+
properties
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { transformDmmf as default };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const getJSONSchemaProperty = require('./getJSONSchemaProperty-DyREsKli.cjs');
|
|
4
|
+
|
|
5
|
+
const getRelationScalarFields = (model) => model.fields.flatMap((field) => field.relationFromFields ?? []);
|
|
6
|
+
const getJSONSchemaModel = (modelMetaData, transformOptions) => (model) => {
|
|
7
|
+
const definitionPropertiesMap = model.fields.map(getJSONSchemaProperty(modelMetaData, transformOptions));
|
|
8
|
+
const propertiesMap = definitionPropertiesMap.map(([name, definition2]) => [name, definition2]);
|
|
9
|
+
const relationScalarFields = getRelationScalarFields(model);
|
|
10
|
+
const propertiesWithoutRelationScalars = propertiesMap.filter((property) => !relationScalarFields.includes(property[0]));
|
|
11
|
+
const properties = Object.fromEntries(transformOptions.keepRelationScalarFields === "true" ? propertiesMap : propertiesWithoutRelationScalars);
|
|
12
|
+
const definition = {
|
|
13
|
+
properties,
|
|
14
|
+
type: "object"
|
|
15
|
+
};
|
|
16
|
+
if (transformOptions.includeRequiredFields) {
|
|
17
|
+
definition.required = definitionPropertiesMap.reduce((filtered, [name, , fieldMetaData]) => {
|
|
18
|
+
if (fieldMetaData.required && fieldMetaData.isScalar && !fieldMetaData.hasDefaultValue) {
|
|
19
|
+
filtered.push(name);
|
|
20
|
+
}
|
|
21
|
+
return filtered;
|
|
22
|
+
}, []);
|
|
23
|
+
}
|
|
24
|
+
return [model.name, definition];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const toCamelCase = (name) => name.slice(0, 1).toLowerCase() + name.slice(1);
|
|
28
|
+
const getPropertyDefinition = ({ schemaId }) => (model) => {
|
|
29
|
+
const reference = `#/definitions/${model.name}`;
|
|
30
|
+
return [
|
|
31
|
+
toCamelCase(model.name),
|
|
32
|
+
{
|
|
33
|
+
$ref: schemaId ? `${schemaId}${reference}` : reference
|
|
34
|
+
}
|
|
35
|
+
];
|
|
36
|
+
};
|
|
37
|
+
const transformDmmf = (dmmf, transformOptions = {}) => {
|
|
38
|
+
const { enums = [], models = [], types = [] } = dmmf.datamodel;
|
|
39
|
+
const initialJSON = {
|
|
40
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
41
|
+
definitions: {},
|
|
42
|
+
type: "object"
|
|
43
|
+
};
|
|
44
|
+
const { schemaId } = transformOptions;
|
|
45
|
+
const modelDefinitionsMap = models.map(getJSONSchemaModel({ enums }, transformOptions));
|
|
46
|
+
const typeDefinitionsMap = types.map(getJSONSchemaModel({ enums }, transformOptions));
|
|
47
|
+
const modelPropertyDefinitionsMap = models.map(getPropertyDefinition(transformOptions));
|
|
48
|
+
const definitions = Object.fromEntries([...modelDefinitionsMap, ...typeDefinitionsMap]);
|
|
49
|
+
const properties = Object.fromEntries(modelPropertyDefinitionsMap);
|
|
50
|
+
return {
|
|
51
|
+
...schemaId ? { $id: schemaId } : void 0,
|
|
52
|
+
...initialJSON,
|
|
53
|
+
definitions,
|
|
54
|
+
properties
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
module.exports = transformDmmf;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
+
import type { JSONSchema7 } from "json-schema";
|
|
3
|
+
import type { TransformOptions } from "./types.d.cts";
|
|
4
|
+
declare const transformDmmf: (dmmf: DMMF.Document, transformOptions?: TransformOptions) => JSONSchema7;
|
|
5
|
+
export = transformDmmf;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
+
import type { JSONSchema7 } from "json-schema";
|
|
3
|
+
import type { TransformOptions } from "./types.d.mts";
|
|
4
|
+
declare const transformDmmf: (dmmf: DMMF.Document, transformOptions?: TransformOptions) => JSONSchema7;
|
|
5
|
+
export default transformDmmf;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
+
import type { JSONSchema7 } from "json-schema";
|
|
3
|
+
import type { TransformOptions } from "./types.d.ts";
|
|
4
|
+
declare const transformDmmf: (dmmf: DMMF.Document, transformOptions?: TransformOptions) => JSONSchema7;
|
|
5
|
+
export = transformDmmf;
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
+
import type { JSONSchema7Definition } from "json-schema";
|
|
3
|
+
import type { ReadonlyDeep } from "type-fest";
|
|
4
|
+
export type PrismaPrimitive = "BigInt" | "Boolean" | "Bytes" | "DateTime" | "Decimal" | "Float" | "Int" | "Json" | "String";
|
|
5
|
+
export interface PropertyMetaData {
|
|
6
|
+
hasDefaultValue: boolean;
|
|
7
|
+
isScalar: boolean;
|
|
8
|
+
required: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ModelMetaData {
|
|
11
|
+
enums: ReadonlyDeep<DMMF.DatamodelEnum[]>;
|
|
12
|
+
}
|
|
13
|
+
export type DefinitionMap = [name: string, definition: JSONSchema7Definition];
|
|
14
|
+
export type PropertyMap = [...DefinitionMap, PropertyMetaData];
|
|
15
|
+
export interface TransformOptions {
|
|
16
|
+
includeRequiredFields?: "false" | "true";
|
|
17
|
+
keepRelationScalarFields?: "false" | "true";
|
|
18
|
+
persistOriginalType?: "false" | "true";
|
|
19
|
+
schemaId?: string;
|
|
20
|
+
}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
+
import type { JSONSchema7Definition } from "json-schema";
|
|
3
|
+
import type { ReadonlyDeep } from "type-fest";
|
|
4
|
+
export type PrismaPrimitive = "BigInt" | "Boolean" | "Bytes" | "DateTime" | "Decimal" | "Float" | "Int" | "Json" | "String";
|
|
5
|
+
export interface PropertyMetaData {
|
|
6
|
+
hasDefaultValue: boolean;
|
|
7
|
+
isScalar: boolean;
|
|
8
|
+
required: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ModelMetaData {
|
|
11
|
+
enums: ReadonlyDeep<DMMF.DatamodelEnum[]>;
|
|
12
|
+
}
|
|
13
|
+
export type DefinitionMap = [name: string, definition: JSONSchema7Definition];
|
|
14
|
+
export type PropertyMap = [...DefinitionMap, PropertyMetaData];
|
|
15
|
+
export interface TransformOptions {
|
|
16
|
+
includeRequiredFields?: "false" | "true";
|
|
17
|
+
keepRelationScalarFields?: "false" | "true";
|
|
18
|
+
persistOriginalType?: "false" | "true";
|
|
19
|
+
schemaId?: string;
|
|
20
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
+
import type { JSONSchema7Definition } from "json-schema";
|
|
3
|
+
import type { ReadonlyDeep } from "type-fest";
|
|
4
|
+
export type PrismaPrimitive = "BigInt" | "Boolean" | "Bytes" | "DateTime" | "Decimal" | "Float" | "Int" | "Json" | "String";
|
|
5
|
+
export interface PropertyMetaData {
|
|
6
|
+
hasDefaultValue: boolean;
|
|
7
|
+
isScalar: boolean;
|
|
8
|
+
required: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ModelMetaData {
|
|
11
|
+
enums: ReadonlyDeep<DMMF.DatamodelEnum[]>;
|
|
12
|
+
}
|
|
13
|
+
export type DefinitionMap = [name: string, definition: JSONSchema7Definition];
|
|
14
|
+
export type PropertyMap = [...DefinitionMap, PropertyMetaData];
|
|
15
|
+
export interface TransformOptions {
|
|
16
|
+
includeRequiredFields?: "false" | "true";
|
|
17
|
+
keepRelationScalarFields?: "false" | "true";
|
|
18
|
+
persistOriginalType?: "false" | "true";
|
|
19
|
+
schemaId?: string;
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var f=Object.defineProperty;var c=(e,t)=>f(e,"name",{value:t,configurable:!0});import{createRequire as g}from"node:module";const h=g(import.meta.url),o=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,S=c(e=>{if(typeof o<"u"&&o.versions&&o.versions.node){const[t,r]=o.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return o.getBuiltinModule(e)}return h(e)},"__cjs_getBuiltinModule"),b=S("node:assert");var D=Object.defineProperty,s=c((e,t)=>D(e,"name",{value:t,configurable:!0}),"a");const u=s(e=>e!=null,"isDefined"),m=s(e=>{switch(e){case"BigInt":case"Int":return"integer";case"Boolean":return"boolean";case"Bytes":case"DateTime":case"String":return"string";case"Decimal":case"Float":return"number";case"Json":return["number","string","boolean","object","array","null"];default:throw new Error(`Unhandled discriminated union member: ${JSON.stringify(e)}`)}},"getJSONSchemaScalar"),T=s(e=>{const{isList:t,isRequired:r,kind:n,type:a}=e;let i="object";return n==="scalar"&&!t?i=m(a):t?i="array":n==="enum"&&(i="string"),r||t?i:Array.isArray(i)?[...new Set(["null",...i])]:[i,"null"]},"getJSONSchemaType"),_=s(e=>{const t=e.default;if(e.hasDefaultValue){if(e.kind==="enum")return typeof t=="string"?t:void 0;if(e.kind==="scalar")switch(e.type){case"BigInt":case"DateTime":case"String":return typeof t=="string"?t:void 0;case"Boolean":return typeof t=="boolean"?t:void 0;case"Bytes":case"Json":return;case"Decimal":case"Float":case"Int":return typeof t=="number"?t:void 0;default:throw new Error(`Unhandled discriminated union member: ${JSON.stringify(e.type)}`)}}},"getDefaultValue"),v=s(e=>{if(e==="DateTime")return"date-time"},"getFormatByDMMFType"),y=s((e,{persistOriginalType:t,schemaId:r})=>{const n=e.isRequired||e.isList;b.equal(typeof e.type,"string");const a=`#/definitions/${e.type}`,i={$ref:r?`${r}${a}`:a};return n?i:{anyOf:[i,{type:"null"}],...t&&{originalType:e.type}}},"getJSONSchemaForPropertyReference"),B=s((e,t)=>{if(!(e.kind==="scalar"&&!e.isList||e.kind==="enum"))return e.kind==="scalar"&&e.isList?{type:m(e.type)}:y(e,t)},"getItemsByDMMFType"),O=s(e=>e.kind!=="scalar"&&!e.isList&&e.kind!=="enum","isSingleReference"),k=s(e=>t=>{const r=e.enums.find(({name:n})=>n===t.type);if(r)return r.values.map(n=>n.name)},"getEnumListByDMMFType"),M=s(e=>e.documentation,"getDescription"),j=s((e,t,r)=>{const n=T(r),a=v(r.type),i=B(r,t),l=k(e)(r),d=_(r),p=M(r);return{type:n,...t.persistOriginalType&&{originalType:r.type},...u(d)&&{default:d},...u(a)&&{format:a},...u(i)&&{items:i},...u(l)&&{enum:l},...u(p)&&{description:p}}},"getPropertyDefinition"),J=s((e,t)=>r=>{const n={hasDefaultValue:r.hasDefaultValue,isScalar:r.kind==="scalar"||r.kind==="enum",required:r.isRequired},a=O(r)?y(r,t):j(e,t,r);return[r.name,a,n]},"getJSONSchemaProperty");export{J as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var u=(e,t)=>p(e,"name",{value:t,configurable:!0});const f=require("node:assert"),g=u(e=>e&&typeof e=="object"&&"default"in e?e.default:e,"_interopDefaultCompat"),D=g(f);var S=Object.defineProperty,a=u((e,t)=>S(e,"name",{value:t,configurable:!0}),"a");const o=a(e=>e!=null,"isDefined"),d=a(e=>{switch(e){case"BigInt":case"Int":return"integer";case"Boolean":return"boolean";case"Bytes":case"DateTime":case"String":return"string";case"Decimal":case"Float":return"number";case"Json":return["number","string","boolean","object","array","null"];default:throw new Error(`Unhandled discriminated union member: ${JSON.stringify(e)}`)}},"getJSONSchemaScalar"),h=a(e=>{const{isList:t,isRequired:r,kind:n,type:s}=e;let i="object";return n==="scalar"&&!t?i=d(s):t?i="array":n==="enum"&&(i="string"),r||t?i:Array.isArray(i)?[...new Set(["null",...i])]:[i,"null"]},"getJSONSchemaType"),b=a(e=>{const t=e.default;if(e.hasDefaultValue){if(e.kind==="enum")return typeof t=="string"?t:void 0;if(e.kind==="scalar")switch(e.type){case"BigInt":case"DateTime":case"String":return typeof t=="string"?t:void 0;case"Boolean":return typeof t=="boolean"?t:void 0;case"Bytes":case"Json":return;case"Decimal":case"Float":case"Int":return typeof t=="number"?t:void 0;default:throw new Error(`Unhandled discriminated union member: ${JSON.stringify(e.type)}`)}}},"getDefaultValue"),O=a(e=>{if(e==="DateTime")return"date-time"},"getFormatByDMMFType"),m=a((e,{persistOriginalType:t,schemaId:r})=>{const n=e.isRequired||e.isList;D.equal(typeof e.type,"string");const s=`#/definitions/${e.type}`,i={$ref:r?`${r}${s}`:s};return n?i:{anyOf:[i,{type:"null"}],...t&&{originalType:e.type}}},"getJSONSchemaForPropertyReference"),T=a((e,t)=>{if(!(e.kind==="scalar"&&!e.isList||e.kind==="enum"))return e.kind==="scalar"&&e.isList?{type:d(e.type)}:m(e,t)},"getItemsByDMMFType"),k=a(e=>e.kind!=="scalar"&&!e.isList&&e.kind!=="enum","isSingleReference"),B=a(e=>t=>{const r=e.enums.find(({name:n})=>n===t.type);if(r)return r.values.map(n=>n.name)},"getEnumListByDMMFType"),v=a(e=>e.documentation,"getDescription"),F=a((e,t,r)=>{const n=h(r),s=O(r.type),i=T(r,t),c=B(e)(r),l=b(r),y=v(r);return{type:n,...t.persistOriginalType&&{originalType:r.type},...o(l)&&{default:l},...o(s)&&{format:s},...o(i)&&{items:i},...o(c)&&{enum:c},...o(y)&&{description:y}}},"getPropertyDefinition"),J=a((e,t)=>r=>{const n={hasDefaultValue:r.hasDefaultValue,isScalar:r.kind==="scalar"||r.kind==="enum",required:r.isRequired},s=k(r)?m(r,t):F(e,t,r);return[r.name,s,n]},"getJSONSchemaProperty");module.exports=J;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var b=Object.defineProperty;var d=(r,e)=>b(r,"name",{value:e,configurable:!0});import j from"./getJSONSchemaProperty-BJUSxFNN.mjs";var v=Object.defineProperty,p=d((r,e)=>v(r,"name",{value:e,configurable:!0}),"n");const O=p(r=>r.fields.flatMap(e=>e.relationFromFields??[]),"getRelationScalarFields"),u=p((r,e)=>t=>{const i=t.fields.map(j(r,e)),o=i.map(([a,s])=>[a,s]),c=O(t),m=o.filter(a=>!c.includes(a[0])),l={properties:Object.fromEntries(e.keepRelationScalarFields==="true"?o:m),type:"object"};return e.includeRequiredFields&&(l.required=i.reduce((a,[s,,n])=>(n.required&&n.isScalar&&!n.hasDefaultValue&&a.push(s),a),[])),[t.name,l]},"getJSONSchemaModel");var g=Object.defineProperty,f=d((r,e)=>g(r,"name",{value:e,configurable:!0}),"o");const y=f(r=>r.slice(0,1).toLowerCase()+r.slice(1),"toCamelCase"),S=f(({schemaId:r})=>e=>{const t=`#/definitions/${e.name}`;return[y(e.name),{$ref:r?`${r}${t}`:t}]},"getPropertyDefinition"),D=f((r,e={})=>{const{enums:t=[],models:i=[],types:o=[]}=r.datamodel,c={$schema:"http://json-schema.org/draft-07/schema#",definitions:{},type:"object"},{schemaId:m}=e,l=i.map(u({enums:t},e)),a=o.map(u({enums:t},e)),s=i.map(S(e)),n=Object.fromEntries([...l,...a]),h=Object.fromEntries(s);return{...m?{$id:m}:void 0,...c,definitions:n,properties:h}},"transformDmmf");export{D as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var b=Object.defineProperty;var d=(r,e)=>b(r,"name",{value:e,configurable:!0});const j=require("./getJSONSchemaProperty-DRt6R_Y4.cjs");var S=Object.defineProperty,f=d((r,e)=>S(r,"name",{value:e,configurable:!0}),"n");const g=f(r=>r.fields.flatMap(e=>e.relationFromFields??[]),"getRelationScalarFields"),p=f((r,e)=>t=>{const s=t.fields.map(j(r,e)),o=s.map(([a,i])=>[a,i]),l=g(t),c=o.filter(a=>!l.includes(a[0])),m={properties:Object.fromEntries(e.keepRelationScalarFields==="true"?o:c),type:"object"};return e.includeRequiredFields&&(m.required=s.reduce((a,[i,,n])=>(n.required&&n.isScalar&&!n.hasDefaultValue&&a.push(i),a),[])),[t.name,m]},"getJSONSchemaModel");var v=Object.defineProperty,u=d((r,e)=>v(r,"name",{value:e,configurable:!0}),"o");const y=u(r=>r.slice(0,1).toLowerCase()+r.slice(1),"toCamelCase"),O=u(({schemaId:r})=>e=>{const t=`#/definitions/${e.name}`;return[y(e.name),{$ref:r?`${r}${t}`:t}]},"getPropertyDefinition"),$=u((r,e={})=>{const{enums:t=[],models:s=[],types:o=[]}=r.datamodel,l={$schema:"http://json-schema.org/draft-07/schema#",definitions:{},type:"object"},{schemaId:c}=e,m=s.map(p({enums:t},e)),a=o.map(p({enums:t},e)),i=s.map(O(e)),n=Object.fromEntries([...m,...a]),h=Object.fromEntries(i);return{...c?{$id:c}:void 0,...l,definitions:n,properties:h}},"transformDmmf");module.exports=$;
|