@visulima/prisma-dmmf-transformer 2.0.29 → 2.0.31
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 +22 -0
- package/LICENSE.md +1 -130
- package/dist/index.cjs +1 -11
- package/dist/index.d.cts +3 -124
- package/dist/index.d.mts +3 -124
- package/dist/index.d.ts +3 -124
- package/dist/index.mjs +1 -2
- package/dist/packem_shared/getJSONSchemaProperty-BJUSxFNN.mjs +1 -0
- package/dist/packem_shared/getJSONSchemaProperty-DRt6R_Y4.cjs +1 -0
- package/dist/packem_shared/transformDMMF-B3i5bZr6.mjs +1 -0
- package/dist/packem_shared/transformDMMF-CNWOKGfH.cjs +1 -0
- package/package.json +10 -9
- package/dist/packem_shared/getJSONSchemaProperty-CCMlB6rF.mjs +0 -150
- package/dist/packem_shared/getJSONSchemaProperty-Ul9ZXvbT.cjs +0 -156
- package/dist/packem_shared/transformDMMF-BlrIBvPS.cjs +0 -62
- package/dist/packem_shared/transformDMMF-BtZz70Wg.mjs +0 -60
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## @visulima/prisma-dmmf-transformer [2.0.31](https://github.com/visulima/visulima/compare/@visulima/prisma-dmmf-transformer@2.0.30...@visulima/prisma-dmmf-transformer@2.0.31) (2025-10-15)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* update @visulima/packem to 2.0.0-alpha.30 across multiple packages for improved compatibility ([27b346e](https://github.com/visulima/visulima/commit/27b346eaa1c0fb0e420d9a9824482028307f4249))
|
|
6
|
+
* update dependencies and improve code structure for JSON schema transformation ([88947c4](https://github.com/visulima/visulima/commit/88947c47b1bb7d55a7b2650a9e6c1ac99882b66e))
|
|
7
|
+
|
|
8
|
+
### Miscellaneous Chores
|
|
9
|
+
|
|
10
|
+
* **deps:** update build scripts and remove cross-env dependency ([7510e82](https://github.com/visulima/visulima/commit/7510e826b9235a0013fe61c82a7eb333bc4cbb78))
|
|
11
|
+
* update dependencies and fix linting issues ([0e802fe](https://github.com/visulima/visulima/commit/0e802fe02bb9ed791659cb5f3c77605ae5b42ec8))
|
|
12
|
+
* update package dependencies across multiple packages for improved compatibility and performance ([9567591](https://github.com/visulima/visulima/commit/9567591c415da3002f3a4fe08f8caf7ce01ca5f7))
|
|
13
|
+
* update package.json and pnpm-lock.yaml to include publint@0.3.12 and adjust build/test commands to exclude shared-utils ([1f7b3c0](https://github.com/visulima/visulima/commit/1f7b3c0381d77edfeec80ea1bf57b3469e929414))
|
|
14
|
+
* update package.json scripts and vitest configuration ([6006ddf](https://github.com/visulima/visulima/commit/6006ddf468a500abb3f13223ea6e3a9876c0c31b))
|
|
15
|
+
|
|
16
|
+
## @visulima/prisma-dmmf-transformer [2.0.30](https://github.com/visulima/visulima/compare/@visulima/prisma-dmmf-transformer@2.0.29...@visulima/prisma-dmmf-transformer@2.0.30) (2025-09-10)
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **prisma-dmmf-transformer:** update dependencies and ESLint configuration ([73aa16c](https://github.com/visulima/visulima/commit/73aa16c2d856a390ff72bf1f2159dffb6c8eb424))
|
|
21
|
+
* **prisma-dmmf-transformer:** update package.json and pnpm-lock.yaml for compatibility ([c12a482](https://github.com/visulima/visulima/commit/c12a4828f7b934a2faa532c380210addefc13428))
|
|
22
|
+
|
|
1
23
|
## @visulima/prisma-dmmf-transformer [2.0.29](https://github.com/visulima/visulima/compare/@visulima/prisma-dmmf-transformer@2.0.28...@visulima/prisma-dmmf-transformer@2.0.29) (2025-05-30)
|
|
2
24
|
|
|
3
25
|
### Bug Fixes
|
package/LICENSE.md
CHANGED
|
@@ -27,7 +27,7 @@ SOFTWARE.
|
|
|
27
27
|
|
|
28
28
|
# Licenses of bundled types
|
|
29
29
|
The published @visulima/prisma-dmmf-transformer artifact additionally contains code with the following licenses:
|
|
30
|
-
MIT
|
|
30
|
+
MIT
|
|
31
31
|
|
|
32
32
|
# Bundled types:
|
|
33
33
|
## @types/json-schema
|
|
@@ -57,133 +57,4 @@ Repository: https://github.com/DefinitelyTyped/DefinitelyTyped.git
|
|
|
57
57
|
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
58
58
|
> SOFTWARE
|
|
59
59
|
|
|
60
|
-
---------------------------------------
|
|
61
|
-
|
|
62
|
-
## type-fest
|
|
63
|
-
License: (MIT OR CC0-1.0)
|
|
64
|
-
By: Sindre Sorhus
|
|
65
|
-
Repository: sindresorhus/type-fest
|
|
66
|
-
|
|
67
|
-
> Creative Commons Legal Code
|
|
68
|
-
>
|
|
69
|
-
> CC0 1.0 Universal
|
|
70
|
-
>
|
|
71
|
-
> CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
72
|
-
> LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
73
|
-
> ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
74
|
-
> INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
75
|
-
> REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
76
|
-
> PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
77
|
-
> THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
78
|
-
> HEREUNDER.
|
|
79
|
-
>
|
|
80
|
-
> Statement of Purpose
|
|
81
|
-
>
|
|
82
|
-
> The laws of most jurisdictions throughout the world automatically confer
|
|
83
|
-
> exclusive Copyright and Related Rights (defined below) upon the creator
|
|
84
|
-
> and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
85
|
-
> authorship and/or a database (each, a "Work").
|
|
86
|
-
>
|
|
87
|
-
> Certain owners wish to permanently relinquish those rights to a Work for
|
|
88
|
-
> the purpose of contributing to a commons of creative, cultural and
|
|
89
|
-
> scientific works ("Commons") that the public can reliably and without fear
|
|
90
|
-
> of later claims of infringement build upon, modify, incorporate in other
|
|
91
|
-
> works, reuse and redistribute as freely as possible in any form whatsoever
|
|
92
|
-
> and for any purposes, including without limitation commercial purposes.
|
|
93
|
-
> These owners may contribute to the Commons to promote the ideal of a free
|
|
94
|
-
> culture and the further production of creative, cultural and scientific
|
|
95
|
-
> works, or to gain reputation or greater distribution for their Work in
|
|
96
|
-
> part through the use and efforts of others.
|
|
97
|
-
>
|
|
98
|
-
> For these and/or other purposes and motivations, and without any
|
|
99
|
-
> expectation of additional consideration or compensation, the person
|
|
100
|
-
> associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
101
|
-
> is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
102
|
-
> elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
103
|
-
> terms, with knowledge of his or her Copyright and Related Rights in the
|
|
104
|
-
> Work and the meaning and intended legal effect of CC0 on those rights.
|
|
105
|
-
>
|
|
106
|
-
> 1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
107
|
-
> protected by copyright and related or neighboring rights ("Copyright and
|
|
108
|
-
> Related Rights"). Copyright and Related Rights include, but are not
|
|
109
|
-
> limited to, the following:
|
|
110
|
-
>
|
|
111
|
-
> i. the right to reproduce, adapt, distribute, perform, display,
|
|
112
|
-
> communicate, and translate a Work;
|
|
113
|
-
> ii. moral rights retained by the original author(s) and/or performer(s);
|
|
114
|
-
> iii. publicity and privacy rights pertaining to a person's image or
|
|
115
|
-
> likeness depicted in a Work;
|
|
116
|
-
> iv. rights protecting against unfair competition in regards to a Work,
|
|
117
|
-
> subject to the limitations in paragraph 4(a), below;
|
|
118
|
-
> v. rights protecting the extraction, dissemination, use and reuse of data
|
|
119
|
-
> in a Work;
|
|
120
|
-
> vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
121
|
-
> European Parliament and of the Council of 11 March 1996 on the legal
|
|
122
|
-
> protection of databases, and under any national implementation
|
|
123
|
-
> thereof, including any amended or successor version of such
|
|
124
|
-
> directive); and
|
|
125
|
-
> vii. other similar, equivalent or corresponding rights throughout the
|
|
126
|
-
> world based on applicable law or treaty, and any national
|
|
127
|
-
> implementations thereof.
|
|
128
|
-
>
|
|
129
|
-
> 2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
130
|
-
> of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
131
|
-
> irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
132
|
-
> Affirmer's Copyright and Related Rights and associated claims and causes
|
|
133
|
-
> of action, whether now known or unknown (including existing as well as
|
|
134
|
-
> future claims and causes of action), in the Work (i) in all territories
|
|
135
|
-
> worldwide, (ii) for the maximum duration provided by applicable law or
|
|
136
|
-
> treaty (including future time extensions), (iii) in any current or future
|
|
137
|
-
> medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
138
|
-
> including without limitation commercial, advertising or promotional
|
|
139
|
-
> purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
140
|
-
> member of the public at large and to the detriment of Affirmer's heirs and
|
|
141
|
-
> successors, fully intending that such Waiver shall not be subject to
|
|
142
|
-
> revocation, rescission, cancellation, termination, or any other legal or
|
|
143
|
-
> equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
144
|
-
> as contemplated by Affirmer's express Statement of Purpose.
|
|
145
|
-
>
|
|
146
|
-
> 3. Public License Fallback. Should any part of the Waiver for any reason
|
|
147
|
-
> be judged legally invalid or ineffective under applicable law, then the
|
|
148
|
-
> Waiver shall be preserved to the maximum extent permitted taking into
|
|
149
|
-
> account Affirmer's express Statement of Purpose. In addition, to the
|
|
150
|
-
> extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
151
|
-
> person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
152
|
-
> irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
153
|
-
> Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
154
|
-
> maximum duration provided by applicable law or treaty (including future
|
|
155
|
-
> time extensions), (iii) in any current or future medium and for any number
|
|
156
|
-
> of copies, and (iv) for any purpose whatsoever, including without
|
|
157
|
-
> limitation commercial, advertising or promotional purposes (the
|
|
158
|
-
> "License"). The License shall be deemed effective as of the date CC0 was
|
|
159
|
-
> applied by Affirmer to the Work. Should any part of the License for any
|
|
160
|
-
> reason be judged legally invalid or ineffective under applicable law, such
|
|
161
|
-
> partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
162
|
-
> of the License, and in such case Affirmer hereby affirms that he or she
|
|
163
|
-
> will not (i) exercise any of his or her remaining Copyright and Related
|
|
164
|
-
> Rights in the Work or (ii) assert any associated claims and causes of
|
|
165
|
-
> action with respect to the Work, in either case contrary to Affirmer's
|
|
166
|
-
> express Statement of Purpose.
|
|
167
|
-
>
|
|
168
|
-
> 4. Limitations and Disclaimers.
|
|
169
|
-
>
|
|
170
|
-
> a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
171
|
-
> surrendered, licensed or otherwise affected by this document.
|
|
172
|
-
> b. Affirmer offers the Work as-is and makes no representations or
|
|
173
|
-
> warranties of any kind concerning the Work, express, implied,
|
|
174
|
-
> statutory or otherwise, including without limitation warranties of
|
|
175
|
-
> title, merchantability, fitness for a particular purpose, non
|
|
176
|
-
> infringement, or the absence of latent or other defects, accuracy, or
|
|
177
|
-
> the present or absence of errors, whether or not discoverable, all to
|
|
178
|
-
> the greatest extent permissible under applicable law.
|
|
179
|
-
> c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
180
|
-
> that may apply to the Work or any use thereof, including without
|
|
181
|
-
> limitation any person's Copyright and Related Rights in the Work.
|
|
182
|
-
> Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
183
|
-
> consents, permissions or other rights required for any use of the
|
|
184
|
-
> Work.
|
|
185
|
-
> d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
186
|
-
> party to this document and has no duty or obligation with respect to
|
|
187
|
-
> this CC0 or use of the Work.
|
|
188
|
-
|
|
189
60
|
<!-- /TYPE_DEPENDENCIES -->
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
-
|
|
5
|
-
const getJSONSchemaProperty = require('./packem_shared/getJSONSchemaProperty-Ul9ZXvbT.cjs');
|
|
6
|
-
const transformDMMF = require('./packem_shared/transformDMMF-BlrIBvPS.cjs');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.getJSONSchemaProperty = getJSONSchemaProperty;
|
|
11
|
-
exports.transformDMMF = transformDMMF;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./packem_shared/getJSONSchemaProperty-DRt6R_Y4.cjs"),r=require("./packem_shared/transformDMMF-CNWOKGfH.cjs");exports.getJSONSchemaProperty=e;exports.transformDMMF=r;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper';
|
|
2
|
+
import { ReadonlyDeep } from 'type-fest';
|
|
2
3
|
|
|
3
4
|
// ==================================================================================================
|
|
4
5
|
// JSON Schema Draft 07
|
|
@@ -167,129 +168,6 @@ interface JSONSchema7 {
|
|
|
167
168
|
examples?: JSONSchema7Type | undefined;
|
|
168
169
|
}
|
|
169
170
|
|
|
170
|
-
/**
|
|
171
|
-
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
172
|
-
|
|
173
|
-
@category Type
|
|
174
|
-
*/
|
|
175
|
-
type Primitive =
|
|
176
|
-
| null
|
|
177
|
-
| undefined
|
|
178
|
-
| string
|
|
179
|
-
| number
|
|
180
|
-
| boolean
|
|
181
|
-
| symbol
|
|
182
|
-
| bigint;
|
|
183
|
-
|
|
184
|
-
declare global {
|
|
185
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
186
|
-
interface SymbolConstructor {
|
|
187
|
-
readonly observable: symbol;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
193
|
-
*/
|
|
194
|
-
type BuiltIns = Primitive | void | Date | RegExp;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
Test if the given function has multiple call signatures.
|
|
198
|
-
|
|
199
|
-
Needed to handle the case of a single call signature with properties.
|
|
200
|
-
|
|
201
|
-
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
202
|
-
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
203
|
-
*/
|
|
204
|
-
type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
|
|
205
|
-
T extends {(...arguments_: infer A): unknown; (...arguments_: infer B): unknown}
|
|
206
|
-
? B extends A
|
|
207
|
-
? A extends B
|
|
208
|
-
? false
|
|
209
|
-
: true
|
|
210
|
-
: true
|
|
211
|
-
: false;
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
Convert `object`s, `Map`s, `Set`s, and `Array`s and all of their keys/elements into immutable structures recursively.
|
|
215
|
-
|
|
216
|
-
This is useful when a deeply nested structure needs to be exposed as completely immutable, for example, an imported JSON module or when receiving an API response that is passed around.
|
|
217
|
-
|
|
218
|
-
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/13923) if you want to have this type as a built-in in TypeScript.
|
|
219
|
-
|
|
220
|
-
@example
|
|
221
|
-
```
|
|
222
|
-
// data.json
|
|
223
|
-
{
|
|
224
|
-
"foo": ["bar"]
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// main.ts
|
|
228
|
-
import type {ReadonlyDeep} from 'type-fest';
|
|
229
|
-
import dataJson = require('./data.json');
|
|
230
|
-
|
|
231
|
-
const data: ReadonlyDeep<typeof dataJson> = dataJson;
|
|
232
|
-
|
|
233
|
-
export default data;
|
|
234
|
-
|
|
235
|
-
// test.ts
|
|
236
|
-
import data from './main';
|
|
237
|
-
|
|
238
|
-
data.foo.push('bar');
|
|
239
|
-
//=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
Note that types containing overloaded functions are not made deeply readonly due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
|
|
243
|
-
|
|
244
|
-
@category Object
|
|
245
|
-
@category Array
|
|
246
|
-
@category Set
|
|
247
|
-
@category Map
|
|
248
|
-
*/
|
|
249
|
-
type ReadonlyDeep<T> = T extends BuiltIns
|
|
250
|
-
? T
|
|
251
|
-
: T extends new (...arguments_: any[]) => unknown
|
|
252
|
-
? T // Skip class constructors
|
|
253
|
-
: T extends (...arguments_: any[]) => unknown
|
|
254
|
-
? {} extends ReadonlyObjectDeep<T>
|
|
255
|
-
? T
|
|
256
|
-
: HasMultipleCallSignatures<T> extends true
|
|
257
|
-
? T
|
|
258
|
-
: ((...arguments_: Parameters<T>) => ReturnType<T>) & ReadonlyObjectDeep<T>
|
|
259
|
-
: T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>>
|
|
260
|
-
? ReadonlyMapDeep<KeyType, ValueType>
|
|
261
|
-
: T extends Readonly<ReadonlySet<infer ItemType>>
|
|
262
|
-
? ReadonlySetDeep<ItemType>
|
|
263
|
-
: // Identify tuples to avoid converting them to arrays inadvertently; special case `readonly [...never[]]`, as it emerges undesirably from recursive invocations of ReadonlyDeep below.
|
|
264
|
-
T extends readonly [] | readonly [...never[]]
|
|
265
|
-
? readonly []
|
|
266
|
-
: T extends readonly [infer U, ...infer V]
|
|
267
|
-
? readonly [ReadonlyDeep<U>, ...ReadonlyDeep<V>]
|
|
268
|
-
: T extends readonly [...infer U, infer V]
|
|
269
|
-
? readonly [...ReadonlyDeep<U>, ReadonlyDeep<V>]
|
|
270
|
-
: T extends ReadonlyArray<infer ItemType>
|
|
271
|
-
? ReadonlyArray<ReadonlyDeep<ItemType>>
|
|
272
|
-
: T extends object
|
|
273
|
-
? ReadonlyObjectDeep<T>
|
|
274
|
-
: unknown;
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
Same as `ReadonlyDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
278
|
-
*/
|
|
279
|
-
type ReadonlyMapDeep<KeyType, ValueType> = {} & Readonly<ReadonlyMap<ReadonlyDeep<KeyType>, ReadonlyDeep<ValueType>>>;
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
Same as `ReadonlyDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
283
|
-
*/
|
|
284
|
-
type ReadonlySetDeep<ItemType> = {} & Readonly<ReadonlySet<ReadonlyDeep<ItemType>>>;
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
Same as `ReadonlyDeep`, but accepts only `object`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
288
|
-
*/
|
|
289
|
-
type ReadonlyObjectDeep<ObjectType extends object> = {
|
|
290
|
-
readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]>
|
|
291
|
-
};
|
|
292
|
-
|
|
293
171
|
interface PropertyMetaData {
|
|
294
172
|
hasDefaultValue: boolean;
|
|
295
173
|
isScalar: boolean;
|
|
@@ -311,4 +189,5 @@ declare const getJSONSchemaProperty: (modelMetaData: ModelMetaData, transformOpt
|
|
|
311
189
|
|
|
312
190
|
declare const transformDmmf: (dmmf: DMMF.Document, transformOptions?: TransformOptions) => JSONSchema7;
|
|
313
191
|
|
|
314
|
-
export {
|
|
192
|
+
export { getJSONSchemaProperty, transformDmmf as transformDMMF };
|
|
193
|
+
export type { DefinitionMap, ModelMetaData, PropertyMap, PropertyMetaData, TransformOptions };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper';
|
|
2
|
+
import { ReadonlyDeep } from 'type-fest';
|
|
2
3
|
|
|
3
4
|
// ==================================================================================================
|
|
4
5
|
// JSON Schema Draft 07
|
|
@@ -167,129 +168,6 @@ interface JSONSchema7 {
|
|
|
167
168
|
examples?: JSONSchema7Type | undefined;
|
|
168
169
|
}
|
|
169
170
|
|
|
170
|
-
/**
|
|
171
|
-
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
172
|
-
|
|
173
|
-
@category Type
|
|
174
|
-
*/
|
|
175
|
-
type Primitive =
|
|
176
|
-
| null
|
|
177
|
-
| undefined
|
|
178
|
-
| string
|
|
179
|
-
| number
|
|
180
|
-
| boolean
|
|
181
|
-
| symbol
|
|
182
|
-
| bigint;
|
|
183
|
-
|
|
184
|
-
declare global {
|
|
185
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
186
|
-
interface SymbolConstructor {
|
|
187
|
-
readonly observable: symbol;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
193
|
-
*/
|
|
194
|
-
type BuiltIns = Primitive | void | Date | RegExp;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
Test if the given function has multiple call signatures.
|
|
198
|
-
|
|
199
|
-
Needed to handle the case of a single call signature with properties.
|
|
200
|
-
|
|
201
|
-
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
202
|
-
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
203
|
-
*/
|
|
204
|
-
type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
|
|
205
|
-
T extends {(...arguments_: infer A): unknown; (...arguments_: infer B): unknown}
|
|
206
|
-
? B extends A
|
|
207
|
-
? A extends B
|
|
208
|
-
? false
|
|
209
|
-
: true
|
|
210
|
-
: true
|
|
211
|
-
: false;
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
Convert `object`s, `Map`s, `Set`s, and `Array`s and all of their keys/elements into immutable structures recursively.
|
|
215
|
-
|
|
216
|
-
This is useful when a deeply nested structure needs to be exposed as completely immutable, for example, an imported JSON module or when receiving an API response that is passed around.
|
|
217
|
-
|
|
218
|
-
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/13923) if you want to have this type as a built-in in TypeScript.
|
|
219
|
-
|
|
220
|
-
@example
|
|
221
|
-
```
|
|
222
|
-
// data.json
|
|
223
|
-
{
|
|
224
|
-
"foo": ["bar"]
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// main.ts
|
|
228
|
-
import type {ReadonlyDeep} from 'type-fest';
|
|
229
|
-
import dataJson = require('./data.json');
|
|
230
|
-
|
|
231
|
-
const data: ReadonlyDeep<typeof dataJson> = dataJson;
|
|
232
|
-
|
|
233
|
-
export default data;
|
|
234
|
-
|
|
235
|
-
// test.ts
|
|
236
|
-
import data from './main';
|
|
237
|
-
|
|
238
|
-
data.foo.push('bar');
|
|
239
|
-
//=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
Note that types containing overloaded functions are not made deeply readonly due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
|
|
243
|
-
|
|
244
|
-
@category Object
|
|
245
|
-
@category Array
|
|
246
|
-
@category Set
|
|
247
|
-
@category Map
|
|
248
|
-
*/
|
|
249
|
-
type ReadonlyDeep<T> = T extends BuiltIns
|
|
250
|
-
? T
|
|
251
|
-
: T extends new (...arguments_: any[]) => unknown
|
|
252
|
-
? T // Skip class constructors
|
|
253
|
-
: T extends (...arguments_: any[]) => unknown
|
|
254
|
-
? {} extends ReadonlyObjectDeep<T>
|
|
255
|
-
? T
|
|
256
|
-
: HasMultipleCallSignatures<T> extends true
|
|
257
|
-
? T
|
|
258
|
-
: ((...arguments_: Parameters<T>) => ReturnType<T>) & ReadonlyObjectDeep<T>
|
|
259
|
-
: T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>>
|
|
260
|
-
? ReadonlyMapDeep<KeyType, ValueType>
|
|
261
|
-
: T extends Readonly<ReadonlySet<infer ItemType>>
|
|
262
|
-
? ReadonlySetDeep<ItemType>
|
|
263
|
-
: // Identify tuples to avoid converting them to arrays inadvertently; special case `readonly [...never[]]`, as it emerges undesirably from recursive invocations of ReadonlyDeep below.
|
|
264
|
-
T extends readonly [] | readonly [...never[]]
|
|
265
|
-
? readonly []
|
|
266
|
-
: T extends readonly [infer U, ...infer V]
|
|
267
|
-
? readonly [ReadonlyDeep<U>, ...ReadonlyDeep<V>]
|
|
268
|
-
: T extends readonly [...infer U, infer V]
|
|
269
|
-
? readonly [...ReadonlyDeep<U>, ReadonlyDeep<V>]
|
|
270
|
-
: T extends ReadonlyArray<infer ItemType>
|
|
271
|
-
? ReadonlyArray<ReadonlyDeep<ItemType>>
|
|
272
|
-
: T extends object
|
|
273
|
-
? ReadonlyObjectDeep<T>
|
|
274
|
-
: unknown;
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
Same as `ReadonlyDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
278
|
-
*/
|
|
279
|
-
type ReadonlyMapDeep<KeyType, ValueType> = {} & Readonly<ReadonlyMap<ReadonlyDeep<KeyType>, ReadonlyDeep<ValueType>>>;
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
Same as `ReadonlyDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
283
|
-
*/
|
|
284
|
-
type ReadonlySetDeep<ItemType> = {} & Readonly<ReadonlySet<ReadonlyDeep<ItemType>>>;
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
Same as `ReadonlyDeep`, but accepts only `object`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
288
|
-
*/
|
|
289
|
-
type ReadonlyObjectDeep<ObjectType extends object> = {
|
|
290
|
-
readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]>
|
|
291
|
-
};
|
|
292
|
-
|
|
293
171
|
interface PropertyMetaData {
|
|
294
172
|
hasDefaultValue: boolean;
|
|
295
173
|
isScalar: boolean;
|
|
@@ -311,4 +189,5 @@ declare const getJSONSchemaProperty: (modelMetaData: ModelMetaData, transformOpt
|
|
|
311
189
|
|
|
312
190
|
declare const transformDmmf: (dmmf: DMMF.Document, transformOptions?: TransformOptions) => JSONSchema7;
|
|
313
191
|
|
|
314
|
-
export {
|
|
192
|
+
export { getJSONSchemaProperty, transformDmmf as transformDMMF };
|
|
193
|
+
export type { DefinitionMap, ModelMetaData, PropertyMap, PropertyMetaData, TransformOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper';
|
|
2
|
+
import { ReadonlyDeep } from 'type-fest';
|
|
2
3
|
|
|
3
4
|
// ==================================================================================================
|
|
4
5
|
// JSON Schema Draft 07
|
|
@@ -167,129 +168,6 @@ interface JSONSchema7 {
|
|
|
167
168
|
examples?: JSONSchema7Type | undefined;
|
|
168
169
|
}
|
|
169
170
|
|
|
170
|
-
/**
|
|
171
|
-
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
172
|
-
|
|
173
|
-
@category Type
|
|
174
|
-
*/
|
|
175
|
-
type Primitive =
|
|
176
|
-
| null
|
|
177
|
-
| undefined
|
|
178
|
-
| string
|
|
179
|
-
| number
|
|
180
|
-
| boolean
|
|
181
|
-
| symbol
|
|
182
|
-
| bigint;
|
|
183
|
-
|
|
184
|
-
declare global {
|
|
185
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
186
|
-
interface SymbolConstructor {
|
|
187
|
-
readonly observable: symbol;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
193
|
-
*/
|
|
194
|
-
type BuiltIns = Primitive | void | Date | RegExp;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
Test if the given function has multiple call signatures.
|
|
198
|
-
|
|
199
|
-
Needed to handle the case of a single call signature with properties.
|
|
200
|
-
|
|
201
|
-
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
202
|
-
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
203
|
-
*/
|
|
204
|
-
type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
|
|
205
|
-
T extends {(...arguments_: infer A): unknown; (...arguments_: infer B): unknown}
|
|
206
|
-
? B extends A
|
|
207
|
-
? A extends B
|
|
208
|
-
? false
|
|
209
|
-
: true
|
|
210
|
-
: true
|
|
211
|
-
: false;
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
Convert `object`s, `Map`s, `Set`s, and `Array`s and all of their keys/elements into immutable structures recursively.
|
|
215
|
-
|
|
216
|
-
This is useful when a deeply nested structure needs to be exposed as completely immutable, for example, an imported JSON module or when receiving an API response that is passed around.
|
|
217
|
-
|
|
218
|
-
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/13923) if you want to have this type as a built-in in TypeScript.
|
|
219
|
-
|
|
220
|
-
@example
|
|
221
|
-
```
|
|
222
|
-
// data.json
|
|
223
|
-
{
|
|
224
|
-
"foo": ["bar"]
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// main.ts
|
|
228
|
-
import type {ReadonlyDeep} from 'type-fest';
|
|
229
|
-
import dataJson = require('./data.json');
|
|
230
|
-
|
|
231
|
-
const data: ReadonlyDeep<typeof dataJson> = dataJson;
|
|
232
|
-
|
|
233
|
-
export default data;
|
|
234
|
-
|
|
235
|
-
// test.ts
|
|
236
|
-
import data from './main';
|
|
237
|
-
|
|
238
|
-
data.foo.push('bar');
|
|
239
|
-
//=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
Note that types containing overloaded functions are not made deeply readonly due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
|
|
243
|
-
|
|
244
|
-
@category Object
|
|
245
|
-
@category Array
|
|
246
|
-
@category Set
|
|
247
|
-
@category Map
|
|
248
|
-
*/
|
|
249
|
-
type ReadonlyDeep<T> = T extends BuiltIns
|
|
250
|
-
? T
|
|
251
|
-
: T extends new (...arguments_: any[]) => unknown
|
|
252
|
-
? T // Skip class constructors
|
|
253
|
-
: T extends (...arguments_: any[]) => unknown
|
|
254
|
-
? {} extends ReadonlyObjectDeep<T>
|
|
255
|
-
? T
|
|
256
|
-
: HasMultipleCallSignatures<T> extends true
|
|
257
|
-
? T
|
|
258
|
-
: ((...arguments_: Parameters<T>) => ReturnType<T>) & ReadonlyObjectDeep<T>
|
|
259
|
-
: T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>>
|
|
260
|
-
? ReadonlyMapDeep<KeyType, ValueType>
|
|
261
|
-
: T extends Readonly<ReadonlySet<infer ItemType>>
|
|
262
|
-
? ReadonlySetDeep<ItemType>
|
|
263
|
-
: // Identify tuples to avoid converting them to arrays inadvertently; special case `readonly [...never[]]`, as it emerges undesirably from recursive invocations of ReadonlyDeep below.
|
|
264
|
-
T extends readonly [] | readonly [...never[]]
|
|
265
|
-
? readonly []
|
|
266
|
-
: T extends readonly [infer U, ...infer V]
|
|
267
|
-
? readonly [ReadonlyDeep<U>, ...ReadonlyDeep<V>]
|
|
268
|
-
: T extends readonly [...infer U, infer V]
|
|
269
|
-
? readonly [...ReadonlyDeep<U>, ReadonlyDeep<V>]
|
|
270
|
-
: T extends ReadonlyArray<infer ItemType>
|
|
271
|
-
? ReadonlyArray<ReadonlyDeep<ItemType>>
|
|
272
|
-
: T extends object
|
|
273
|
-
? ReadonlyObjectDeep<T>
|
|
274
|
-
: unknown;
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
Same as `ReadonlyDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
278
|
-
*/
|
|
279
|
-
type ReadonlyMapDeep<KeyType, ValueType> = {} & Readonly<ReadonlyMap<ReadonlyDeep<KeyType>, ReadonlyDeep<ValueType>>>;
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
Same as `ReadonlyDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
283
|
-
*/
|
|
284
|
-
type ReadonlySetDeep<ItemType> = {} & Readonly<ReadonlySet<ReadonlyDeep<ItemType>>>;
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
Same as `ReadonlyDeep`, but accepts only `object`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
288
|
-
*/
|
|
289
|
-
type ReadonlyObjectDeep<ObjectType extends object> = {
|
|
290
|
-
readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]>
|
|
291
|
-
};
|
|
292
|
-
|
|
293
171
|
interface PropertyMetaData {
|
|
294
172
|
hasDefaultValue: boolean;
|
|
295
173
|
isScalar: boolean;
|
|
@@ -311,4 +189,5 @@ declare const getJSONSchemaProperty: (modelMetaData: ModelMetaData, transformOpt
|
|
|
311
189
|
|
|
312
190
|
declare const transformDmmf: (dmmf: DMMF.Document, transformOptions?: TransformOptions) => JSONSchema7;
|
|
313
191
|
|
|
314
|
-
export {
|
|
192
|
+
export { getJSONSchemaProperty, transformDmmf as transformDMMF };
|
|
193
|
+
export type { DefinitionMap, ModelMetaData, PropertyMap, PropertyMetaData, TransformOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { default as transformDMMF } from './packem_shared/transformDMMF-BtZz70Wg.mjs';
|
|
1
|
+
import{default as t}from"./packem_shared/getJSONSchemaProperty-BJUSxFNN.mjs";import{default as o}from"./packem_shared/transformDMMF-B3i5bZr6.mjs";export{t as getJSONSchemaProperty,o as transformDMMF};
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
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=$;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/prisma-dmmf-transformer",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.31",
|
|
4
4
|
"description": "A generator for Prisma to generate a valid JSON Schema v7.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anolilab",
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"sideEffects": false,
|
|
39
39
|
"exports": {
|
|
40
40
|
".": {
|
|
41
|
-
"require": {
|
|
42
|
-
"types": "./dist/index.d.cts",
|
|
43
|
-
"default": "./dist/index.cjs"
|
|
44
|
-
},
|
|
45
41
|
"import": {
|
|
46
42
|
"types": "./dist/index.d.mts",
|
|
47
43
|
"default": "./dist/index.mjs"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/index.d.cts",
|
|
47
|
+
"default": "./dist/index.cjs"
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
"./package.json": "./package.json"
|
|
@@ -66,14 +66,15 @@
|
|
|
66
66
|
"LICENSE.md"
|
|
67
67
|
],
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@prisma/generator-helper": "6.
|
|
69
|
+
"@prisma/generator-helper": "6.17.1",
|
|
70
|
+
"type-fest": "5.0.1"
|
|
70
71
|
},
|
|
71
72
|
"peerDependencies": {
|
|
72
|
-
"@prisma/client": "3.* || 4.*",
|
|
73
|
-
"prisma": "3.* || 4.*"
|
|
73
|
+
"@prisma/client": "3.* || 4.* || 5.* || 6.*",
|
|
74
|
+
"prisma": "3.* || 4.* || 5.* || 6.*"
|
|
74
75
|
},
|
|
75
76
|
"engines": {
|
|
76
|
-
"node": ">=18.0.0 <=
|
|
77
|
+
"node": ">=18.0.0 <=24.x"
|
|
77
78
|
},
|
|
78
79
|
"os": [
|
|
79
80
|
"darwin",
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
-
const isDefined = /* @__PURE__ */ __name((value) => value !== void 0 && value !== null, "isDefined");
|
|
6
|
-
const getJSONSchemaScalar = /* @__PURE__ */ __name((fieldType) => {
|
|
7
|
-
switch (fieldType) {
|
|
8
|
-
case "Int":
|
|
9
|
-
case "BigInt": {
|
|
10
|
-
return "integer";
|
|
11
|
-
}
|
|
12
|
-
case "DateTime":
|
|
13
|
-
case "Bytes":
|
|
14
|
-
case "String": {
|
|
15
|
-
return "string";
|
|
16
|
-
}
|
|
17
|
-
case "Float":
|
|
18
|
-
case "Decimal": {
|
|
19
|
-
return "number";
|
|
20
|
-
}
|
|
21
|
-
case "Json": {
|
|
22
|
-
return ["number", "string", "boolean", "object", "array", "null"];
|
|
23
|
-
}
|
|
24
|
-
case "Boolean": {
|
|
25
|
-
return "boolean";
|
|
26
|
-
}
|
|
27
|
-
default: {
|
|
28
|
-
throw new Error(`Unhandled discriminated union member: ${JSON.stringify(fieldType)}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}, "getJSONSchemaScalar");
|
|
32
|
-
const getJSONSchemaType = /* @__PURE__ */ __name((field) => {
|
|
33
|
-
const { isList, isRequired, kind, type } = field;
|
|
34
|
-
let scalarFieldType = "object";
|
|
35
|
-
if (kind === "scalar" && !isList) {
|
|
36
|
-
scalarFieldType = getJSONSchemaScalar(type);
|
|
37
|
-
} else if (isList) {
|
|
38
|
-
scalarFieldType = "array";
|
|
39
|
-
} else if (kind === "enum") {
|
|
40
|
-
scalarFieldType = "string";
|
|
41
|
-
}
|
|
42
|
-
if (isRequired || isList) {
|
|
43
|
-
return scalarFieldType;
|
|
44
|
-
}
|
|
45
|
-
const isFieldUnion = Array.isArray(scalarFieldType);
|
|
46
|
-
if (isFieldUnion) {
|
|
47
|
-
return [.../* @__PURE__ */ new Set([...scalarFieldType, "null"])];
|
|
48
|
-
}
|
|
49
|
-
return [scalarFieldType, "null"];
|
|
50
|
-
}, "getJSONSchemaType");
|
|
51
|
-
const getDefaultValue = /* @__PURE__ */ __name((field) => {
|
|
52
|
-
const fieldDefault = field.default;
|
|
53
|
-
if (!field.hasDefaultValue) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
if (field.kind === "enum") {
|
|
57
|
-
return typeof fieldDefault === "string" ? fieldDefault : null;
|
|
58
|
-
}
|
|
59
|
-
if (field.kind !== "scalar") {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
switch (field.type) {
|
|
63
|
-
case "String":
|
|
64
|
-
case "BigInt":
|
|
65
|
-
case "DateTime": {
|
|
66
|
-
return typeof fieldDefault === "string" ? fieldDefault : null;
|
|
67
|
-
}
|
|
68
|
-
case "Int":
|
|
69
|
-
case "Float":
|
|
70
|
-
case "Decimal": {
|
|
71
|
-
return typeof fieldDefault === "number" ? fieldDefault : null;
|
|
72
|
-
}
|
|
73
|
-
case "Boolean": {
|
|
74
|
-
return typeof fieldDefault === "boolean" ? fieldDefault : null;
|
|
75
|
-
}
|
|
76
|
-
case "Json":
|
|
77
|
-
case "Bytes": {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
default: {
|
|
81
|
-
throw new Error(`Unhandled discriminated union member: ${JSON.stringify(field.type)}`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}, "getDefaultValue");
|
|
85
|
-
const getFormatByDMMFType = /* @__PURE__ */ __name((fieldType) => {
|
|
86
|
-
if (fieldType === "DateTime") {
|
|
87
|
-
return "date-time";
|
|
88
|
-
}
|
|
89
|
-
return void 0;
|
|
90
|
-
}, "getFormatByDMMFType");
|
|
91
|
-
const getJSONSchemaForPropertyReference = /* @__PURE__ */ __name((field, { persistOriginalType, schemaId }) => {
|
|
92
|
-
const notNullable = field.isRequired || field.isList;
|
|
93
|
-
assert.equal(typeof field.type, "string");
|
|
94
|
-
const typeReference = `#/definitions/${field.type}`;
|
|
95
|
-
const reference = { $ref: schemaId ? `${schemaId}${typeReference}` : typeReference };
|
|
96
|
-
return notNullable ? reference : {
|
|
97
|
-
anyOf: [reference, { type: "null" }],
|
|
98
|
-
...persistOriginalType && {
|
|
99
|
-
originalType: field.type
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
}, "getJSONSchemaForPropertyReference");
|
|
103
|
-
const getItemsByDMMFType = /* @__PURE__ */ __name((field, transformOptions) => {
|
|
104
|
-
if (field.kind === "scalar" && !field.isList || field.kind === "enum") {
|
|
105
|
-
return void 0;
|
|
106
|
-
}
|
|
107
|
-
if (field.kind === "scalar" && field.isList) {
|
|
108
|
-
return { type: getJSONSchemaScalar(field.type) };
|
|
109
|
-
}
|
|
110
|
-
return getJSONSchemaForPropertyReference(field, transformOptions);
|
|
111
|
-
}, "getItemsByDMMFType");
|
|
112
|
-
const isSingleReference = /* @__PURE__ */ __name((field) => field.kind !== "scalar" && !field.isList && field.kind !== "enum", "isSingleReference");
|
|
113
|
-
const getEnumListByDMMFType = /* @__PURE__ */ __name((modelMetaData) => (field) => {
|
|
114
|
-
const enumItem = modelMetaData.enums.find(({ name }) => name === field.type);
|
|
115
|
-
if (!enumItem) {
|
|
116
|
-
return void 0;
|
|
117
|
-
}
|
|
118
|
-
return enumItem.values.map((item) => item.name);
|
|
119
|
-
}, "getEnumListByDMMFType");
|
|
120
|
-
const getDescription = /* @__PURE__ */ __name((field) => field.documentation, "getDescription");
|
|
121
|
-
const getPropertyDefinition = /* @__PURE__ */ __name((modelMetaData, transformOptions, field) => {
|
|
122
|
-
const type = getJSONSchemaType(field);
|
|
123
|
-
const format = getFormatByDMMFType(field.type);
|
|
124
|
-
const items = getItemsByDMMFType(field, transformOptions);
|
|
125
|
-
const enumList = getEnumListByDMMFType(modelMetaData)(field);
|
|
126
|
-
const defaultValue = getDefaultValue(field);
|
|
127
|
-
const description = getDescription(field);
|
|
128
|
-
return {
|
|
129
|
-
type,
|
|
130
|
-
...transformOptions.persistOriginalType && {
|
|
131
|
-
originalType: field.type
|
|
132
|
-
},
|
|
133
|
-
...isDefined(defaultValue) && { default: defaultValue },
|
|
134
|
-
...isDefined(format) && { format },
|
|
135
|
-
...isDefined(items) && { items },
|
|
136
|
-
...isDefined(enumList) && { enum: enumList },
|
|
137
|
-
...isDefined(description) && { description }
|
|
138
|
-
};
|
|
139
|
-
}, "getPropertyDefinition");
|
|
140
|
-
const getJSONSchemaProperty = /* @__PURE__ */ __name((modelMetaData, transformOptions) => (field) => {
|
|
141
|
-
const propertyMetaData = {
|
|
142
|
-
hasDefaultValue: field.hasDefaultValue,
|
|
143
|
-
isScalar: field.kind === "scalar" || field.kind === "enum",
|
|
144
|
-
required: field.isRequired
|
|
145
|
-
};
|
|
146
|
-
const property = isSingleReference(field) ? getJSONSchemaForPropertyReference(field, transformOptions) : getPropertyDefinition(modelMetaData, transformOptions, field);
|
|
147
|
-
return [field.name, property, propertyMetaData];
|
|
148
|
-
}, "getJSONSchemaProperty");
|
|
149
|
-
|
|
150
|
-
export { getJSONSchemaProperty as default };
|
|
@@ -1,156 +0,0 @@
|
|
|
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
|
-
var __defProp = Object.defineProperty;
|
|
10
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
-
const isDefined = /* @__PURE__ */ __name((value) => value !== void 0 && value !== null, "isDefined");
|
|
12
|
-
const getJSONSchemaScalar = /* @__PURE__ */ __name((fieldType) => {
|
|
13
|
-
switch (fieldType) {
|
|
14
|
-
case "Int":
|
|
15
|
-
case "BigInt": {
|
|
16
|
-
return "integer";
|
|
17
|
-
}
|
|
18
|
-
case "DateTime":
|
|
19
|
-
case "Bytes":
|
|
20
|
-
case "String": {
|
|
21
|
-
return "string";
|
|
22
|
-
}
|
|
23
|
-
case "Float":
|
|
24
|
-
case "Decimal": {
|
|
25
|
-
return "number";
|
|
26
|
-
}
|
|
27
|
-
case "Json": {
|
|
28
|
-
return ["number", "string", "boolean", "object", "array", "null"];
|
|
29
|
-
}
|
|
30
|
-
case "Boolean": {
|
|
31
|
-
return "boolean";
|
|
32
|
-
}
|
|
33
|
-
default: {
|
|
34
|
-
throw new Error(`Unhandled discriminated union member: ${JSON.stringify(fieldType)}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}, "getJSONSchemaScalar");
|
|
38
|
-
const getJSONSchemaType = /* @__PURE__ */ __name((field) => {
|
|
39
|
-
const { isList, isRequired, kind, type } = field;
|
|
40
|
-
let scalarFieldType = "object";
|
|
41
|
-
if (kind === "scalar" && !isList) {
|
|
42
|
-
scalarFieldType = getJSONSchemaScalar(type);
|
|
43
|
-
} else if (isList) {
|
|
44
|
-
scalarFieldType = "array";
|
|
45
|
-
} else if (kind === "enum") {
|
|
46
|
-
scalarFieldType = "string";
|
|
47
|
-
}
|
|
48
|
-
if (isRequired || isList) {
|
|
49
|
-
return scalarFieldType;
|
|
50
|
-
}
|
|
51
|
-
const isFieldUnion = Array.isArray(scalarFieldType);
|
|
52
|
-
if (isFieldUnion) {
|
|
53
|
-
return [.../* @__PURE__ */ new Set([...scalarFieldType, "null"])];
|
|
54
|
-
}
|
|
55
|
-
return [scalarFieldType, "null"];
|
|
56
|
-
}, "getJSONSchemaType");
|
|
57
|
-
const getDefaultValue = /* @__PURE__ */ __name((field) => {
|
|
58
|
-
const fieldDefault = field.default;
|
|
59
|
-
if (!field.hasDefaultValue) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
if (field.kind === "enum") {
|
|
63
|
-
return typeof fieldDefault === "string" ? fieldDefault : null;
|
|
64
|
-
}
|
|
65
|
-
if (field.kind !== "scalar") {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
switch (field.type) {
|
|
69
|
-
case "String":
|
|
70
|
-
case "BigInt":
|
|
71
|
-
case "DateTime": {
|
|
72
|
-
return typeof fieldDefault === "string" ? fieldDefault : null;
|
|
73
|
-
}
|
|
74
|
-
case "Int":
|
|
75
|
-
case "Float":
|
|
76
|
-
case "Decimal": {
|
|
77
|
-
return typeof fieldDefault === "number" ? fieldDefault : null;
|
|
78
|
-
}
|
|
79
|
-
case "Boolean": {
|
|
80
|
-
return typeof fieldDefault === "boolean" ? fieldDefault : null;
|
|
81
|
-
}
|
|
82
|
-
case "Json":
|
|
83
|
-
case "Bytes": {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
default: {
|
|
87
|
-
throw new Error(`Unhandled discriminated union member: ${JSON.stringify(field.type)}`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}, "getDefaultValue");
|
|
91
|
-
const getFormatByDMMFType = /* @__PURE__ */ __name((fieldType) => {
|
|
92
|
-
if (fieldType === "DateTime") {
|
|
93
|
-
return "date-time";
|
|
94
|
-
}
|
|
95
|
-
return void 0;
|
|
96
|
-
}, "getFormatByDMMFType");
|
|
97
|
-
const getJSONSchemaForPropertyReference = /* @__PURE__ */ __name((field, { persistOriginalType, schemaId }) => {
|
|
98
|
-
const notNullable = field.isRequired || field.isList;
|
|
99
|
-
assert__default.equal(typeof field.type, "string");
|
|
100
|
-
const typeReference = `#/definitions/${field.type}`;
|
|
101
|
-
const reference = { $ref: schemaId ? `${schemaId}${typeReference}` : typeReference };
|
|
102
|
-
return notNullable ? reference : {
|
|
103
|
-
anyOf: [reference, { type: "null" }],
|
|
104
|
-
...persistOriginalType && {
|
|
105
|
-
originalType: field.type
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
}, "getJSONSchemaForPropertyReference");
|
|
109
|
-
const getItemsByDMMFType = /* @__PURE__ */ __name((field, transformOptions) => {
|
|
110
|
-
if (field.kind === "scalar" && !field.isList || field.kind === "enum") {
|
|
111
|
-
return void 0;
|
|
112
|
-
}
|
|
113
|
-
if (field.kind === "scalar" && field.isList) {
|
|
114
|
-
return { type: getJSONSchemaScalar(field.type) };
|
|
115
|
-
}
|
|
116
|
-
return getJSONSchemaForPropertyReference(field, transformOptions);
|
|
117
|
-
}, "getItemsByDMMFType");
|
|
118
|
-
const isSingleReference = /* @__PURE__ */ __name((field) => field.kind !== "scalar" && !field.isList && field.kind !== "enum", "isSingleReference");
|
|
119
|
-
const getEnumListByDMMFType = /* @__PURE__ */ __name((modelMetaData) => (field) => {
|
|
120
|
-
const enumItem = modelMetaData.enums.find(({ name }) => name === field.type);
|
|
121
|
-
if (!enumItem) {
|
|
122
|
-
return void 0;
|
|
123
|
-
}
|
|
124
|
-
return enumItem.values.map((item) => item.name);
|
|
125
|
-
}, "getEnumListByDMMFType");
|
|
126
|
-
const getDescription = /* @__PURE__ */ __name((field) => field.documentation, "getDescription");
|
|
127
|
-
const getPropertyDefinition = /* @__PURE__ */ __name((modelMetaData, transformOptions, field) => {
|
|
128
|
-
const type = getJSONSchemaType(field);
|
|
129
|
-
const format = getFormatByDMMFType(field.type);
|
|
130
|
-
const items = getItemsByDMMFType(field, transformOptions);
|
|
131
|
-
const enumList = getEnumListByDMMFType(modelMetaData)(field);
|
|
132
|
-
const defaultValue = getDefaultValue(field);
|
|
133
|
-
const description = getDescription(field);
|
|
134
|
-
return {
|
|
135
|
-
type,
|
|
136
|
-
...transformOptions.persistOriginalType && {
|
|
137
|
-
originalType: field.type
|
|
138
|
-
},
|
|
139
|
-
...isDefined(defaultValue) && { default: defaultValue },
|
|
140
|
-
...isDefined(format) && { format },
|
|
141
|
-
...isDefined(items) && { items },
|
|
142
|
-
...isDefined(enumList) && { enum: enumList },
|
|
143
|
-
...isDefined(description) && { description }
|
|
144
|
-
};
|
|
145
|
-
}, "getPropertyDefinition");
|
|
146
|
-
const getJSONSchemaProperty = /* @__PURE__ */ __name((modelMetaData, transformOptions) => (field) => {
|
|
147
|
-
const propertyMetaData = {
|
|
148
|
-
hasDefaultValue: field.hasDefaultValue,
|
|
149
|
-
isScalar: field.kind === "scalar" || field.kind === "enum",
|
|
150
|
-
required: field.isRequired
|
|
151
|
-
};
|
|
152
|
-
const property = isSingleReference(field) ? getJSONSchemaForPropertyReference(field, transformOptions) : getPropertyDefinition(modelMetaData, transformOptions, field);
|
|
153
|
-
return [field.name, property, propertyMetaData];
|
|
154
|
-
}, "getJSONSchemaProperty");
|
|
155
|
-
|
|
156
|
-
module.exports = getJSONSchemaProperty;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const getJSONSchemaProperty = require('./getJSONSchemaProperty-Ul9ZXvbT.cjs');
|
|
4
|
-
|
|
5
|
-
var __defProp$1 = Object.defineProperty;
|
|
6
|
-
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
7
|
-
const getRelationScalarFields = /* @__PURE__ */ __name$1((model) => model.fields.flatMap((field) => field.relationFromFields ?? []), "getRelationScalarFields");
|
|
8
|
-
const getJSONSchemaModel = /* @__PURE__ */ __name$1((modelMetaData, transformOptions) => (model) => {
|
|
9
|
-
const definitionPropertiesMap = model.fields.map(getJSONSchemaProperty(modelMetaData, transformOptions));
|
|
10
|
-
const propertiesMap = definitionPropertiesMap.map(([name, definition2]) => [name, definition2]);
|
|
11
|
-
const relationScalarFields = getRelationScalarFields(model);
|
|
12
|
-
const propertiesWithoutRelationScalars = propertiesMap.filter((property) => !relationScalarFields.includes(property[0]));
|
|
13
|
-
const properties = Object.fromEntries(transformOptions.keepRelationScalarFields === "true" ? propertiesMap : propertiesWithoutRelationScalars);
|
|
14
|
-
const definition = {
|
|
15
|
-
properties,
|
|
16
|
-
type: "object"
|
|
17
|
-
};
|
|
18
|
-
if (transformOptions.includeRequiredFields) {
|
|
19
|
-
definition.required = definitionPropertiesMap.reduce((filtered, [name, , fieldMetaData]) => {
|
|
20
|
-
if (fieldMetaData.required && fieldMetaData.isScalar && !fieldMetaData.hasDefaultValue) {
|
|
21
|
-
filtered.push(name);
|
|
22
|
-
}
|
|
23
|
-
return filtered;
|
|
24
|
-
}, []);
|
|
25
|
-
}
|
|
26
|
-
return [model.name, definition];
|
|
27
|
-
}, "getJSONSchemaModel");
|
|
28
|
-
|
|
29
|
-
var __defProp = Object.defineProperty;
|
|
30
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
31
|
-
const toCamelCase = /* @__PURE__ */ __name((name) => name.slice(0, 1).toLowerCase() + name.slice(1), "toCamelCase");
|
|
32
|
-
const getPropertyDefinition = /* @__PURE__ */ __name(({ schemaId }) => (model) => {
|
|
33
|
-
const reference = `#/definitions/${model.name}`;
|
|
34
|
-
return [
|
|
35
|
-
toCamelCase(model.name),
|
|
36
|
-
{
|
|
37
|
-
$ref: schemaId ? `${schemaId}${reference}` : reference
|
|
38
|
-
}
|
|
39
|
-
];
|
|
40
|
-
}, "getPropertyDefinition");
|
|
41
|
-
const transformDmmf = /* @__PURE__ */ __name((dmmf, transformOptions = {}) => {
|
|
42
|
-
const { enums = [], models = [], types = [] } = dmmf.datamodel;
|
|
43
|
-
const initialJSON = {
|
|
44
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
45
|
-
definitions: {},
|
|
46
|
-
type: "object"
|
|
47
|
-
};
|
|
48
|
-
const { schemaId } = transformOptions;
|
|
49
|
-
const modelDefinitionsMap = models.map(getJSONSchemaModel({ enums }, transformOptions));
|
|
50
|
-
const typeDefinitionsMap = types.map(getJSONSchemaModel({ enums }, transformOptions));
|
|
51
|
-
const modelPropertyDefinitionsMap = models.map(getPropertyDefinition(transformOptions));
|
|
52
|
-
const definitions = Object.fromEntries([...modelDefinitionsMap, ...typeDefinitionsMap]);
|
|
53
|
-
const properties = Object.fromEntries(modelPropertyDefinitionsMap);
|
|
54
|
-
return {
|
|
55
|
-
...schemaId ? { $id: schemaId } : null,
|
|
56
|
-
...initialJSON,
|
|
57
|
-
definitions,
|
|
58
|
-
properties
|
|
59
|
-
};
|
|
60
|
-
}, "transformDmmf");
|
|
61
|
-
|
|
62
|
-
module.exports = transformDmmf;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import getJSONSchemaProperty from './getJSONSchemaProperty-CCMlB6rF.mjs';
|
|
2
|
-
|
|
3
|
-
var __defProp$1 = Object.defineProperty;
|
|
4
|
-
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
5
|
-
const getRelationScalarFields = /* @__PURE__ */ __name$1((model) => model.fields.flatMap((field) => field.relationFromFields ?? []), "getRelationScalarFields");
|
|
6
|
-
const getJSONSchemaModel = /* @__PURE__ */ __name$1((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
|
-
}, "getJSONSchemaModel");
|
|
26
|
-
|
|
27
|
-
var __defProp = Object.defineProperty;
|
|
28
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
29
|
-
const toCamelCase = /* @__PURE__ */ __name((name) => name.slice(0, 1).toLowerCase() + name.slice(1), "toCamelCase");
|
|
30
|
-
const getPropertyDefinition = /* @__PURE__ */ __name(({ schemaId }) => (model) => {
|
|
31
|
-
const reference = `#/definitions/${model.name}`;
|
|
32
|
-
return [
|
|
33
|
-
toCamelCase(model.name),
|
|
34
|
-
{
|
|
35
|
-
$ref: schemaId ? `${schemaId}${reference}` : reference
|
|
36
|
-
}
|
|
37
|
-
];
|
|
38
|
-
}, "getPropertyDefinition");
|
|
39
|
-
const transformDmmf = /* @__PURE__ */ __name((dmmf, transformOptions = {}) => {
|
|
40
|
-
const { enums = [], models = [], types = [] } = dmmf.datamodel;
|
|
41
|
-
const initialJSON = {
|
|
42
|
-
$schema: "http://json-schema.org/draft-07/schema#",
|
|
43
|
-
definitions: {},
|
|
44
|
-
type: "object"
|
|
45
|
-
};
|
|
46
|
-
const { schemaId } = transformOptions;
|
|
47
|
-
const modelDefinitionsMap = models.map(getJSONSchemaModel({ enums }, transformOptions));
|
|
48
|
-
const typeDefinitionsMap = types.map(getJSONSchemaModel({ enums }, transformOptions));
|
|
49
|
-
const modelPropertyDefinitionsMap = models.map(getPropertyDefinition(transformOptions));
|
|
50
|
-
const definitions = Object.fromEntries([...modelDefinitionsMap, ...typeDefinitionsMap]);
|
|
51
|
-
const properties = Object.fromEntries(modelPropertyDefinitionsMap);
|
|
52
|
-
return {
|
|
53
|
-
...schemaId ? { $id: schemaId } : null,
|
|
54
|
-
...initialJSON,
|
|
55
|
-
definitions,
|
|
56
|
-
properties
|
|
57
|
-
};
|
|
58
|
-
}, "transformDmmf");
|
|
59
|
-
|
|
60
|
-
export { transformDmmf as default };
|