openxiangda 1.0.45 → 1.0.46

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openxiangda",
3
- "version": "1.0.45",
3
+ "version": "1.0.46",
4
4
  "description": "OpenXiangda CLI, workspace build tools, runtime SDK, and form components.",
5
5
  "private": false,
6
6
  "bin": {
@@ -159,6 +159,7 @@ async function sendToApi(apiPayload, config, accessToken) {
159
159
  ? {
160
160
  schema: apiPayload.schema,
161
161
  packages: apiPayload.packages,
162
+ formType: apiPayload.formType,
162
163
  }
163
164
  : {
164
165
  userId: config.userId,
@@ -166,6 +167,7 @@ async function sendToApi(apiPayload, config, accessToken) {
166
167
  formUuid: apiPayload.formUuid,
167
168
  schema: apiPayload.schema,
168
169
  packages: apiPayload.packages,
170
+ formType: apiPayload.formType,
169
171
  },
170
172
  ),
171
173
  });
@@ -72,6 +72,9 @@ export function transformToApiFormat(schema, formName = "unknown") {
72
72
  validateFormSchema(schema, formName);
73
73
 
74
74
  const { formMeta, fields } = schema;
75
+ const formType = normalizeFormType(
76
+ formMeta.formType || schema.template?.formType,
77
+ );
75
78
  const componentNodes = fields.map(createFormComponentNode);
76
79
  const pageSchema = {
77
80
  version: "2.0",
@@ -88,12 +91,21 @@ export function transformToApiFormat(schema, formName = "unknown") {
88
91
  return {
89
92
  formUuid: formMeta.formUuid,
90
93
  appType: formMeta.appType,
94
+ formType,
91
95
  fieldCount: componentNodes.length,
92
96
  schema: JSON.stringify(pageSchema),
93
97
  packages: JSON.stringify({}),
94
98
  };
95
99
  }
96
100
 
101
+ export function normalizeFormType(formType) {
102
+ const normalized = String(formType || "").trim().toLowerCase();
103
+ if (["process", "workflow", "flow", "flowform", "processform"].includes(normalized)) {
104
+ return "process";
105
+ }
106
+ return "receipt";
107
+ }
108
+
97
109
  export function assertSchemaSyncResult(body, expectedFieldCount) {
98
110
  if (body?.code !== 200) {
99
111
  throw new Error(
@@ -35,6 +35,7 @@ describe("schema-transform", () => {
35
35
  const schema = JSON.parse(payload.schema);
36
36
  const nodes = schema.componentsTree[0].children;
37
37
 
38
+ expect(payload.formType).toBe("receipt");
38
39
  expect(payload.fieldCount).toBe(2);
39
40
  expect(nodes[0].props).toMatchObject({
40
41
  fieldId: "customer_name",
@@ -48,6 +49,36 @@ describe("schema-transform", () => {
48
49
  });
49
50
  });
50
51
 
52
+ it("normalizes process form type from form meta or template", () => {
53
+ const fromMeta = transformToApiFormat(
54
+ {
55
+ formMeta: {
56
+ formUuid: "FORM_PROCESS_META",
57
+ appType: "APP_1",
58
+ title: "审批表单",
59
+ formType: "process",
60
+ },
61
+ fields: [{ fieldId: "title", componentName: "TextField", label: "标题" }],
62
+ },
63
+ "process-meta",
64
+ );
65
+ const fromTemplate = transformToApiFormat(
66
+ {
67
+ formMeta: {
68
+ formUuid: "FORM_PROCESS_TEMPLATE",
69
+ appType: "APP_1",
70
+ title: "审批表单",
71
+ },
72
+ template: { formType: "workflow" },
73
+ fields: [{ fieldId: "title", componentName: "TextField", label: "标题" }],
74
+ },
75
+ "process-template",
76
+ );
77
+
78
+ expect(fromMeta.formType).toBe("process");
79
+ expect(fromTemplate.formType).toBe("process");
80
+ });
81
+
51
82
  it("rejects duplicate field ids and empty fields", () => {
52
83
  expect(() =>
53
84
  transformToApiFormat(
@@ -57,8 +57,10 @@ export type OpenXiangdaFormSchemaInput = {
57
57
  formUuid: string;
58
58
  appType: string;
59
59
  title: string;
60
+ formType?: "receipt" | "process";
60
61
  };
61
62
  fields: FieldDefinition[];
63
+ template?: Record<string, unknown>;
62
64
  };
63
65
 
64
66
  export function option(value: string, label = value): FormOption {
@@ -72,6 +74,10 @@ export function options(values: string[]): FormOption[] {
72
74
  export function createFormSchema(input: OpenXiangdaFormSchemaInput) {
73
75
  return defineFormSchema({
74
76
  formMeta: input.formMeta,
77
+ template: {
78
+ ...(input.template || {}),
79
+ ...(input.formMeta.formType === "process" ? { formType: "process" } : {}),
80
+ },
75
81
  fields: input.fields.map(normalizeField),
76
82
  layout: input.fields.map((field) => ({
77
83
  id: `layout_${field.fieldId}`,