0.1.3 • Published 9 months ago

prisma-schema-form v0.1.3

Weekly downloads
-
License
ISC
Repository
github
Last release
9 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

9 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.0

9 months ago

0.0.17

10 months ago

0.0.16

10 months ago

0.0.15

10 months ago

0.0.14

10 months ago

0.0.13

10 months ago

0.0.12

10 months ago

0.0.11

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago

0.0.1-bate

10 months ago