@visulima/prisma-dmmf-transformer 2.0.30 → 2.0.32

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.
@@ -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 };
@@ -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;
@@ -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;
@@ -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;
@@ -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
- }