0.1.3 • Published 6 months ago

prisma-schema-form v0.1.3

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

Screenshot

prisma-schema-form

Live Playground

A live playground is hosted on GitHub Pages.

How to install

npm install prisma-schema-form
yarn add prisma-schema-form

How to use

Step1 (cli generate code)

npx psf
yarn psf

Step2 (import schema)

import schema from "prisma-schema-form/schema";
import RJSFForm from "@rjsf/mui";

const App: React.FC<{}> = () => {
  return <RJSFForm formData={yourFormData} schema={schema.YourModel} />;
};

Advanced usage

import React, { useMemo } from "react";
import { merge } from "es-toolkit";

const Advanced: React.FC<{}> = () => {
  const appSchema = useMemo(() => {
    const android = !!formData?.platforms?.includes("ANDROID");
    const ios = !!formData?.platforms?.includes("IOS");
    const required = [
      ...(android ? ["androidBundleId"] : []),
      ...(ios ? ["iosBundleId"] : []),
    ];
    return (
      schemaBuilder(schema.YourModel)
        .assign(true, {
          // modify a property
          properties: {
            name: {
              title: "名字",
            },
          },
        })
        .assignDeep(true, "items", (envSchema) => ({
          ...envSchema,
          // modify required property
          required: [...envSchema.required, ...required],
          // modify a deep property
          properties: merge(envSchema.properties, {
            type: {
              title: "类型",
            },
          }),
        }))
        // omit a property
        .omit(true, "icon")
        // omit a deep property
        .omitDeep(true, ["items", "type"])
        .build()
    );
  }, [formData]);
  return <RJSFForm formData={yourFormData} schema={appSchema} />;
};

Advanced usage method

methoddescriptionparams
omitomit a propertycondition: boolean, keys: string[]
omitDeepomit a deep propertycondition: boolean, paths: string[]
assignmodify a propertycondition: boolean, value: Partial\<JSONSchemaValue> | (model: T) => Partial\<JSONSchemaValue>
assignDeepmodify a deep propertycondition: boolean, key: string, value: Partial\<JSONSchemaValue> | (model: T) => Partial\<JSONSchemaValue>
appendBeforeappend some property before specified propertycondition: boolean, key: string, value: Record\<string, JSONSchemaValue>
appendAfterappend some property after specified propertycondition: boolean, key: string, value: Record\<string, JSONSchemaValue>
buildreturns the final schema
0.1.3

6 months ago

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago

0.0.17

6 months ago

0.0.16

6 months ago

0.0.15

6 months ago

0.0.14

6 months ago

0.0.13

6 months ago

0.0.12

6 months ago

0.0.11

6 months ago

0.0.10

6 months ago

0.0.9

7 months ago

0.0.8

7 months ago

0.0.7

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago

0.0.1-bate

7 months ago