@visulima/prisma-dmmf-transformer 2.0.30 → 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 +15 -0
- package/LICENSE.md +1 -130
- package/dist/index.cjs +1 -11
- package/dist/index.d.cts +193 -3
- package/dist/index.d.mts +193 -3
- package/dist/index.d.ts +193 -3
- 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 +3 -2
- package/dist/model.d.cts +0 -4
- package/dist/model.d.mts +0 -4
- package/dist/model.d.ts +0 -4
- package/dist/packem_shared/getJSONSchemaProperty-DulgsLKr.mjs +0 -150
- package/dist/packem_shared/getJSONSchemaProperty-E2OXsCgc.cjs +0 -156
- package/dist/packem_shared/transformDMMF-CAcG255G.cjs +0 -62
- package/dist/packem_shared/transformDMMF-DvU3tZ1x.mjs +0 -60
- package/dist/properties.d.cts +0 -4
- package/dist/properties.d.mts +0 -4
- package/dist/properties.d.ts +0 -4
- package/dist/transform-dmmf.d.cts +0 -5
- package/dist/transform-dmmf.d.mts +0 -5
- package/dist/transform-dmmf.d.ts +0 -5
- package/dist/types.d.cts +0 -20
- package/dist/types.d.mts +0 -20
- package/dist/types.d.ts +0 -20
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import getJSONSchemaProperty from './getJSONSchemaProperty-DulgsLKr.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 };
|
package/dist/properties.d.cts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
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;
|
package/dist/properties.d.mts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
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;
|
package/dist/properties.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
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;
|
|
@@ -1,5 +0,0 @@
|
|
|
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;
|
|
@@ -1,5 +0,0 @@
|
|
|
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;
|
package/dist/transform-dmmf.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
-
import type { JSONSchema7Definition } from "json-schema";
|
|
3
|
-
import type { ReadonlyDeep } from ".//index.d.d.cts";
|
|
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
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
-
import type { JSONSchema7Definition } from "json-schema";
|
|
3
|
-
import type { ReadonlyDeep } from ".//index.d.d.mts";
|
|
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
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { DMMF } from "@prisma/generator-helper";
|
|
2
|
-
import type { JSONSchema7Definition } from "json-schema";
|
|
3
|
-
import type { ReadonlyDeep } from ".//index.d.d.ts";
|
|
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
|
-
}
|