@ldsg/forms 0.3.9 → 0.3.11

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.
Files changed (68) hide show
  1. package/README.md +51 -1
  2. package/dist/constants.d.ts +3 -3
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +11 -10
  5. package/dist/handler.d.ts +5 -7
  6. package/dist/handler.d.ts.map +1 -1
  7. package/dist/index.d.ts +5 -5
  8. package/dist/instantiate-resource.d.ts +4 -4
  9. package/dist/instantiate-resource.js +1 -1
  10. package/dist/resource.d.ts +4 -4
  11. package/dist/resource.d.ts.map +1 -1
  12. package/dist/resource.js +4 -8
  13. package/dist/test/__tests__/unit.js +199 -131
  14. package/dist/types/get-form-info.d.ts +3 -3
  15. package/dist/types/index.d.ts +3 -2
  16. package/dist/types/index.d.ts.map +1 -1
  17. package/dist/types/index.js +1 -0
  18. package/dist/types/query-types.d.ts +50 -0
  19. package/dist/types/query-types.d.ts.map +1 -0
  20. package/dist/types/query-types.js +2 -0
  21. package/dist/types/specific-resource-settings.d.ts +1 -1
  22. package/dist/types/specific-resource-settings.d.ts.map +1 -1
  23. package/dist/utils/add-query-fields/index.d.ts +10 -0
  24. package/dist/utils/add-query-fields/index.d.ts.map +1 -0
  25. package/dist/utils/add-query-fields/index.js +26 -0
  26. package/dist/utils/add-query-fields/utils/create-resolvers.d.ts +21 -0
  27. package/dist/utils/add-query-fields/utils/create-resolvers.d.ts.map +1 -0
  28. package/dist/utils/add-query-fields/utils/create-resolvers.js +37 -0
  29. package/dist/utils/add-query-fields/utils/create-types.d.ts +10 -0
  30. package/dist/utils/add-query-fields/utils/create-types.d.ts.map +1 -0
  31. package/dist/utils/add-query-fields/utils/create-types.js +100 -0
  32. package/dist/utils/add-query-fields/utils/get-json-schema.d.ts +11 -0
  33. package/dist/utils/add-query-fields/utils/get-json-schema.d.ts.map +1 -0
  34. package/dist/utils/add-query-fields/utils/get-json-schema.js +90 -0
  35. package/dist/utils/add-query-fields/utils/get-schema-for-formily/constants.d.ts +3 -0
  36. package/dist/utils/add-query-fields/utils/get-schema-for-formily/constants.d.ts.map +1 -0
  37. package/dist/utils/add-query-fields/utils/get-schema-for-formily/constants.js +29 -0
  38. package/dist/utils/add-query-fields/utils/get-schema-for-formily/index.d.ts +11 -0
  39. package/dist/utils/add-query-fields/utils/get-schema-for-formily/index.d.ts.map +1 -0
  40. package/dist/utils/add-query-fields/utils/get-schema-for-formily/index.js +15 -0
  41. package/dist/utils/add-query-fields/utils/get-schema-for-formily/utils/process-object-schema.d.ts +8 -0
  42. package/dist/utils/add-query-fields/utils/get-schema-for-formily/utils/process-object-schema.d.ts.map +1 -0
  43. package/dist/utils/add-query-fields/utils/get-schema-for-formily/utils/process-object-schema.js +44 -0
  44. package/dist/utils/add-query-fields/utils/map-form-info.d.ts +11 -0
  45. package/dist/utils/add-query-fields/utils/map-form-info.d.ts.map +1 -0
  46. package/dist/utils/add-query-fields/utils/map-form-info.js +42 -0
  47. package/dist/utils/get-new-fields/index.d.ts +3 -3
  48. package/dist/utils/get-new-fields/index.d.ts.map +1 -1
  49. package/dist/utils/get-new-fields/index.js +3 -3
  50. package/dist/utils/get-new-fields/utils/get-field-config-map-definition.d.ts +1 -1
  51. package/dist/utils/get-new-fields/utils/get-field-config-map-definition.d.ts.map +1 -1
  52. package/dist/utils/get-new-fields/utils/get-field-config-map-definition.js +3 -3
  53. package/dist/utils/get-new-fields/utils/get-graphql-type-by-common-type.d.ts.map +1 -1
  54. package/dist/utils/get-new-fields/utils/get-graphql-type-by-common-type.js +3 -3
  55. package/dist/utils/get-new-fields/utils/get-graphql-type-by-type-info.d.ts +1 -1
  56. package/dist/utils/get-new-fields/utils/get-graphql-type-by-type-info.d.ts.map +1 -1
  57. package/dist/utils/get-new-fields/utils/get-graphql-type-by-type-info.js +2 -2
  58. package/dist/utils/get-new-fields/utils/get-input-itc.d.ts +3 -3
  59. package/dist/utils/get-new-fields/utils/get-input-itc.d.ts.map +1 -1
  60. package/dist/utils/get-new-fields/utils/get-input-itc.js +4 -4
  61. package/dist/utils/get-new-fields/utils/get-output-otc.d.ts +3 -3
  62. package/dist/utils/get-new-fields/utils/get-output-otc.d.ts.map +1 -1
  63. package/dist/utils/get-new-fields/utils/get-output-otc.js +10 -4
  64. package/dist/utils/get-new-fields/utils/index.d.ts +2 -2
  65. package/dist/utils/index.d.ts +2 -1
  66. package/dist/utils/index.d.ts.map +1 -1
  67. package/dist/utils/index.js +1 -0
  68. package/package.json +27 -19
@@ -0,0 +1,50 @@
1
+ import { ObjectInfo } from '@ldsg/object';
2
+ /**
3
+ * Extended ObjectInfo with JSON schemas for form queries
4
+ */
5
+ export interface FormObjectInfo extends Omit<ObjectInfo, 'fieldInfoList'> {
6
+ /**
7
+ * List of field information
8
+ */
9
+ fieldInfoList?: ObjectInfo['fieldInfoList'];
10
+ /**
11
+ * JSON Schema for the object
12
+ */
13
+ jsonSchema?: any;
14
+ /**
15
+ * Formily JSON Schema for the object
16
+ */
17
+ formilyJsonSchema?: any;
18
+ }
19
+ /**
20
+ * Form metadata returned by the forms query
21
+ */
22
+ export interface FormMetadata {
23
+ /**
24
+ * Form name (used to query the form)
25
+ */
26
+ name: string;
27
+ /**
28
+ * Human-readable form title
29
+ */
30
+ title?: string;
31
+ /**
32
+ * Optional form description
33
+ */
34
+ description?: string;
35
+ }
36
+ /**
37
+ * Detailed form information returned by the form query
38
+ * Includes input and output objects
39
+ */
40
+ export interface FormDetail extends FormMetadata {
41
+ /**
42
+ * Input object information
43
+ */
44
+ inputObjectInfo: FormObjectInfo;
45
+ /**
46
+ * Output object information
47
+ */
48
+ outputObjectInfo: FormObjectInfo;
49
+ }
50
+ //# sourceMappingURL=query-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-types.d.ts","sourceRoot":"","sources":["../../src/types/query-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC;IACvE;;OAEG;IACH,aAAa,CAAC,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;IAE5C;;OAEG;IACH,UAAU,CAAC,EAAE,GAAG,CAAC;IAEjB;;OAEG;IACH,iBAAiB,CAAC,EAAE,GAAG,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C;;OAEG;IACH,eAAe,EAAE,cAAc,CAAC;IAEhC;;OAEG;IACH,gBAAgB,EAAE,cAAc,CAAC;CAClC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,4 @@
1
- import { SpecificResourceSettings } from "@ldsg/types";
1
+ import { SpecificResourceSettings } from '@ldsg/types';
2
2
  export interface FormsSpecificResourceSettings extends SpecificResourceSettings {
3
3
  }
4
4
  //# sourceMappingURL=specific-resource-settings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"specific-resource-settings.d.ts","sourceRoot":"","sources":["../../src/types/specific-resource-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,WAAW,6BACf,SAAQ,wBAAwB;CAAG"}
1
+ {"version":3,"file":"specific-resource-settings.d.ts","sourceRoot":"","sources":["../../src/types/specific-resource-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,WAAW,6BAA8B,SAAQ,wBAAwB;CAAG"}
@@ -0,0 +1,10 @@
1
+ import { SchemaComposerParams } from '@ldsg/graphql';
2
+ import { FormInfo } from '../../types';
3
+ export interface AddQueryFieldsParams extends SchemaComposerParams {
4
+ formInfoList: FormInfo[];
5
+ }
6
+ /**
7
+ * Adds `form` and `forms` query fields to the GraphQL schema
8
+ */
9
+ export declare function addQueryFields(params: AddQueryFieldsParams): void;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/add-query-fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIvC,MAAM,WAAW,oBAAqB,SAAQ,oBAAoB;IAChE,YAAY,EAAE,QAAQ,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAqBjE"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addQueryFields = addQueryFields;
4
+ const create_types_1 = require("./utils/create-types");
5
+ const create_resolvers_1 = require("./utils/create-resolvers");
6
+ /**
7
+ * Adds `form` and `forms` query fields to the GraphQL schema
8
+ */
9
+ function addQueryFields(params) {
10
+ const { schemaComposer, formInfoList } = params;
11
+ const { Query } = schemaComposer;
12
+ // Create GraphQL types
13
+ const formDetailTC = (0, create_types_1.createFormDetailTC)(schemaComposer);
14
+ const formMetadataTC = (0, create_types_1.createFormMetadataTC)(schemaComposer);
15
+ // Add the types to the schema
16
+ schemaComposer.addSchemaMustHaveType(formDetailTC);
17
+ schemaComposer.addSchemaMustHaveType(formMetadataTC);
18
+ // Create resolvers
19
+ const formResolver = (0, create_resolvers_1.createFormResolver)(formInfoList);
20
+ const formsResolver = (0, create_resolvers_1.createFormsResolver)(formInfoList);
21
+ // Add fields to Query type
22
+ Query.addFields({
23
+ form: formResolver,
24
+ forms: formsResolver
25
+ });
26
+ }
@@ -0,0 +1,21 @@
1
+ import { FormInfo } from '../../../types';
2
+ /**
3
+ * Creates a resolver definition for querying a single form by name
4
+ */
5
+ export declare function createFormResolver(formInfoList: FormInfo[]): {
6
+ name: string;
7
+ type: string;
8
+ args: {
9
+ name: string;
10
+ };
11
+ resolve: (_root: any, args: any) => Promise<import("../../../types").FormDetail>;
12
+ };
13
+ /**
14
+ * Creates a resolver definition for querying all forms
15
+ */
16
+ export declare function createFormsResolver(formInfoList: FormInfo[]): {
17
+ name: string;
18
+ type: string;
19
+ resolve: () => Promise<import("../../../types").FormMetadata[]>;
20
+ };
21
+ //# sourceMappingURL=create-resolvers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-resolvers.d.ts","sourceRoot":"","sources":["../../../../src/utils/add-query-fields/utils/create-resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,QAAQ,EAAE;;;;;;qBAOhC,GAAG,QAAQ,GAAG;EAWxC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,QAAQ,EAAE;;;;EAQ3D"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFormResolver = createFormResolver;
4
+ exports.createFormsResolver = createFormsResolver;
5
+ const map_form_info_1 = require("./map-form-info");
6
+ /**
7
+ * Creates a resolver definition for querying a single form by name
8
+ */
9
+ function createFormResolver(formInfoList) {
10
+ return {
11
+ name: 'form',
12
+ type: 'FormDetail',
13
+ args: {
14
+ name: 'String!'
15
+ },
16
+ resolve: async (_root, args) => {
17
+ const { name } = args;
18
+ const formInfo = formInfoList.find((f) => f.name === name);
19
+ if (!formInfo) {
20
+ throw new Error(`Form not found: ${name}`);
21
+ }
22
+ return (0, map_form_info_1.mapFormInfoToDetail)(formInfo);
23
+ }
24
+ };
25
+ }
26
+ /**
27
+ * Creates a resolver definition for querying all forms
28
+ */
29
+ function createFormsResolver(formInfoList) {
30
+ return {
31
+ name: 'forms',
32
+ type: '[FormMetadata!]!',
33
+ resolve: async () => {
34
+ return formInfoList.map((f) => (0, map_form_info_1.mapFormInfoToMetadata)(f));
35
+ }
36
+ };
37
+ }
@@ -0,0 +1,10 @@
1
+ import { ObjectTypeComposer, SchemaComposer } from 'graphql-compose';
2
+ /**
3
+ * Creates GraphQL type for FormMetadata
4
+ */
5
+ export declare function createFormMetadataTC(schemaComposer: SchemaComposer): ObjectTypeComposer<any, any>;
6
+ /**
7
+ * Creates GraphQL type for FormDetail
8
+ */
9
+ export declare function createFormDetailTC(schemaComposer: SchemaComposer): ObjectTypeComposer<any, any>;
10
+ //# sourceMappingURL=create-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-types.d.ts","sourceRoot":"","sources":["../../../../src/utils/add-query-fields/utils/create-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAyCrE;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,cAAc,EAAE,cAAc,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAsBjG;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,cAAc,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAgC/F"}
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFormMetadataTC = createFormMetadataTC;
4
+ exports.createFormDetailTC = createFormDetailTC;
5
+ /**
6
+ * Creates GraphQL type for ObjectInfo (used in inputObject and outputObject)
7
+ */
8
+ function createObjectInfoTC(schemaComposer) {
9
+ if (schemaComposer.has('FormObjectInfo')) {
10
+ return schemaComposer.getOTC('FormObjectInfo');
11
+ }
12
+ return schemaComposer.createObjectTC({
13
+ name: 'FormObjectInfo',
14
+ fields: {
15
+ name: {
16
+ type: 'String',
17
+ description: 'Object name'
18
+ },
19
+ title: {
20
+ type: 'String',
21
+ description: 'Object title'
22
+ },
23
+ description: {
24
+ type: 'String',
25
+ description: 'Object description'
26
+ },
27
+ fieldInfoList: {
28
+ type: 'JSON',
29
+ description: 'List of field information'
30
+ },
31
+ jsonSchema: {
32
+ type: 'JSON',
33
+ description: 'JSON Schema for the object'
34
+ },
35
+ formilyJsonSchema: {
36
+ type: 'JSON',
37
+ description: 'Formily JSON Schema for the object'
38
+ }
39
+ }
40
+ });
41
+ }
42
+ /**
43
+ * Creates GraphQL type for FormMetadata
44
+ */
45
+ function createFormMetadataTC(schemaComposer) {
46
+ if (schemaComposer.has('FormMetadata')) {
47
+ return schemaComposer.getOTC('FormMetadata');
48
+ }
49
+ return schemaComposer.createObjectTC({
50
+ name: 'FormMetadata',
51
+ fields: {
52
+ name: {
53
+ type: 'String!',
54
+ description: 'Form name'
55
+ },
56
+ title: {
57
+ type: 'String',
58
+ description: 'Human-readable form title'
59
+ },
60
+ description: {
61
+ type: 'String',
62
+ description: 'Optional form description'
63
+ }
64
+ }
65
+ });
66
+ }
67
+ /**
68
+ * Creates GraphQL type for FormDetail
69
+ */
70
+ function createFormDetailTC(schemaComposer) {
71
+ if (schemaComposer.has('FormDetail')) {
72
+ return schemaComposer.getOTC('FormDetail');
73
+ }
74
+ const objectInfoTC = createObjectInfoTC(schemaComposer);
75
+ return schemaComposer.createObjectTC({
76
+ name: 'FormDetail',
77
+ fields: {
78
+ name: {
79
+ type: 'String!',
80
+ description: 'Form name'
81
+ },
82
+ title: {
83
+ type: 'String',
84
+ description: 'Human-readable form title'
85
+ },
86
+ description: {
87
+ type: 'String',
88
+ description: 'Optional form description'
89
+ },
90
+ inputObjectInfo: {
91
+ type: objectInfoTC,
92
+ description: 'Input object information'
93
+ },
94
+ outputObjectInfo: {
95
+ type: objectInfoTC,
96
+ description: 'Output object information'
97
+ }
98
+ }
99
+ });
100
+ }
@@ -0,0 +1,11 @@
1
+ import { FieldInfo } from '@ldsg/object';
2
+ /**
3
+ * Generates JSON Schema for an object from its field info list
4
+ */
5
+ export declare function getJsonSchemaByFieldInfoList(fieldInfoList: FieldInfo[]): any;
6
+ /**
7
+ * Generates Formily JSON Schema for an object from its field info list
8
+ * Falls back to JSON Schema for individual fields if Formily schema is not available
9
+ */
10
+ export declare function getFormilyJsonSchemaByFieldInfoList(fieldInfoList: FieldInfo[]): any;
11
+ //# sourceMappingURL=get-json-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-json-schema.d.ts","sourceRoot":"","sources":["../../../../src/utils/add-query-fields/utils/get-json-schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AA0DzC;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,aAAa,EAAE,SAAS,EAAE,GAAG,GAAG,CAmB5E;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,CAAC,aAAa,EAAE,SAAS,EAAE,GAAG,GAAG,CAqBnF"}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getJsonSchemaByFieldInfoList = getJsonSchemaByFieldInfoList;
4
+ exports.getFormilyJsonSchemaByFieldInfoList = getFormilyJsonSchemaByFieldInfoList;
5
+ const json_schema_1 = require("@formily/json-schema");
6
+ const field_type_1 = require("@ldsg/field-type");
7
+ const get_schema_for_formily_1 = require("./get-schema-for-formily");
8
+ /**
9
+ * Generates JSON Schema for a field based on its type info
10
+ */
11
+ function getJsonSchemaForField(fieldInfo) {
12
+ const { typeInfo } = fieldInfo;
13
+ const { platformToTypeMap } = typeInfo;
14
+ // Try to get JSON schema from platform-specific type map
15
+ const jsonSchema = platformToTypeMap[field_type_1.FieldTypeBasePlatform.JSON_SCHEMA];
16
+ if (jsonSchema) {
17
+ return jsonSchema;
18
+ }
19
+ // Fallback: generate basic schema based on common type
20
+ const commonType = platformToTypeMap[field_type_1.FieldTypeBasePlatform.COMMON];
21
+ if (!commonType) {
22
+ return {
23
+ type: 'string',
24
+ title: fieldInfo.title || fieldInfo.name
25
+ };
26
+ }
27
+ // Basic type mapping
28
+ const typeMap = {
29
+ string: { type: 'string', title: fieldInfo.title || fieldInfo.name },
30
+ number: { type: 'number', title: fieldInfo.title || fieldInfo.name },
31
+ boolean: { type: 'boolean', title: fieldInfo.title || fieldInfo.name },
32
+ array: { type: 'array', title: fieldInfo.title || fieldInfo.name },
33
+ object: { type: 'object', title: fieldInfo.title || fieldInfo.name }
34
+ };
35
+ return typeMap[commonType] || { type: 'string', title: fieldInfo.title || fieldInfo.name };
36
+ }
37
+ /**
38
+ * Generates Formily JSON Schema for a field based on its type info
39
+ * Falls back to JSON Schema if Formily schema is not available
40
+ */
41
+ function getFormilyJsonSchemaForField(fieldInfo) {
42
+ const { title, description, typeInfo } = fieldInfo;
43
+ const { platformToTypeMap } = typeInfo;
44
+ let res = platformToTypeMap[field_type_1.FieldTypeBasePlatform.FORMILY_JSON_SCHEMA];
45
+ if (!res) {
46
+ const commonType = platformToTypeMap[field_type_1.FieldTypeBasePlatform.COMMON];
47
+ res = { ...commonType, title, description };
48
+ }
49
+ return res;
50
+ }
51
+ /**
52
+ * Generates JSON Schema for an object from its field info list
53
+ */
54
+ function getJsonSchemaByFieldInfoList(fieldInfoList) {
55
+ const properties = {};
56
+ const required = [];
57
+ fieldInfoList.forEach((fieldInfo) => {
58
+ const schema = getJsonSchemaForField(fieldInfo);
59
+ properties[fieldInfo.name] = schema;
60
+ // Add to required if field is mandatory (check if there's a required flag)
61
+ // This assumes there might be a 'required' property in fieldInfo or typeInfo
62
+ if (fieldInfo.required) {
63
+ required.push(fieldInfo.name);
64
+ }
65
+ });
66
+ return {
67
+ type: 'object',
68
+ properties
69
+ };
70
+ }
71
+ /**
72
+ * Generates Formily JSON Schema for an object from its field info list
73
+ * Falls back to JSON Schema for individual fields if Formily schema is not available
74
+ */
75
+ function getFormilyJsonSchemaByFieldInfoList(fieldInfoList) {
76
+ const properties = {};
77
+ fieldInfoList.forEach((fieldInfo) => {
78
+ const formilySchema = getFormilyJsonSchemaForField(fieldInfo);
79
+ properties[fieldInfo.name] = formilySchema;
80
+ });
81
+ const schema = new json_schema_1.Schema({
82
+ type: 'object',
83
+ properties
84
+ });
85
+ const { schemaForFormily } = (0, get_schema_for_formily_1.getSchemaForFormily)({
86
+ schema
87
+ });
88
+ const res = schemaForFormily;
89
+ return res;
90
+ }
@@ -0,0 +1,3 @@
1
+ import { ISchema, SchemaTypes } from '@formily/json-schema';
2
+ export declare const SchemaTypeMap: Partial<Record<SchemaTypes, ISchema>>;
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/utils/add-query-fields/utils/get-schema-for-formily/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAE5D,eAAO,MAAM,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAyB/D,CAAC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaTypeMap = void 0;
4
+ exports.SchemaTypeMap = {
5
+ boolean: {
6
+ 'x-decorator': 'FormItem',
7
+ 'x-component': 'Checkbox'
8
+ },
9
+ integer: {
10
+ 'x-decorator': 'FormItem',
11
+ 'x-component': 'NumberPicker'
12
+ },
13
+ number: {
14
+ 'x-decorator': 'FormItem',
15
+ 'x-component': 'NumberPicker'
16
+ },
17
+ object: {},
18
+ objectWithoutProperties: {
19
+ 'x-decorator': 'FormItem',
20
+ 'x-component': 'JsonInput'
21
+ },
22
+ string: {
23
+ 'x-decorator': 'FormItem',
24
+ 'x-component': 'Input'
25
+ },
26
+ array: {
27
+ 'x-decorator': 'FormItem'
28
+ }
29
+ };
@@ -0,0 +1,11 @@
1
+ import { Schema } from '@formily/json-schema';
2
+ interface GetSchemaForFormilyParams {
3
+ schema: Schema;
4
+ }
5
+ interface GetSchemaForFormilyRes {
6
+ schemaForFormily: Schema;
7
+ }
8
+ type GetSchemaForFormily = (params: GetSchemaForFormilyParams) => GetSchemaForFormilyRes;
9
+ export declare const getSchemaForFormily: GetSchemaForFormily;
10
+ export {};
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/utils/add-query-fields/utils/get-schema-for-formily/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAG9C,UAAU,yBAAyB;IACjC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,sBAAsB;IAC9B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,KAAK,mBAAmB,GAAG,CAAC,MAAM,EAAE,yBAAyB,KAAK,sBAAsB,CAAC;AAEzF,eAAO,MAAM,mBAAmB,EAAE,mBAYjC,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSchemaForFormily = void 0;
4
+ const process_object_schema_1 = require("./utils/process-object-schema");
5
+ const getSchemaForFormily = (params) => {
6
+ const { schema } = params;
7
+ (0, process_object_schema_1.processObjectSchema)({
8
+ schema
9
+ });
10
+ const res = {
11
+ schemaForFormily: schema
12
+ };
13
+ return res;
14
+ };
15
+ exports.getSchemaForFormily = getSchemaForFormily;
@@ -0,0 +1,8 @@
1
+ import { Schema } from '@formily/json-schema';
2
+ interface ProcessObjectSchemaParams {
3
+ schema: Schema;
4
+ }
5
+ type ProcessObjectSchema = (params: ProcessObjectSchemaParams) => void;
6
+ export declare const processObjectSchema: ProcessObjectSchema;
7
+ export {};
8
+ //# sourceMappingURL=process-object-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-object-schema.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/add-query-fields/utils/get-schema-for-formily/utils/process-object-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAI9C,UAAU,yBAAyB;IACjC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,KAAK,mBAAmB,GAAG,CAAC,MAAM,EAAE,yBAAyB,KAAK,IAAI,CAAC;AAEvE,eAAO,MAAM,mBAAmB,EAAE,mBA2CjC,CAAC"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.processObjectSchema = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const constants_1 = require("../constants");
9
+ const processObjectSchema = (params) => {
10
+ const { schema } = params;
11
+ const { type, properties } = schema;
12
+ switch (type) {
13
+ case 'object': {
14
+ if (properties && lodash_1.default.keys(properties).length) {
15
+ const schemaTypeMapValue = constants_1.SchemaTypeMap['object'];
16
+ lodash_1.default.defaults(schema, schemaTypeMapValue);
17
+ schema.mapProperties((property) => {
18
+ (0, exports.processObjectSchema)({
19
+ schema: property
20
+ });
21
+ });
22
+ }
23
+ else {
24
+ const schemaTypeMapValue = constants_1.SchemaTypeMap['objectWithoutProperties'];
25
+ lodash_1.default.defaults(schema, schemaTypeMapValue);
26
+ }
27
+ break;
28
+ }
29
+ default: {
30
+ if (schema.enum && schema.enum.length && !schema['x-component']) {
31
+ /**
32
+ * TODO:应改成 Select,但在此 react 版本中 Select 功能异常
33
+ */
34
+ schema['x-component'] = 'Radio.Group';
35
+ }
36
+ const schemaTypeMapValue = constants_1.SchemaTypeMap[type];
37
+ if (schemaTypeMapValue) {
38
+ lodash_1.default.defaults(schema, schemaTypeMapValue);
39
+ }
40
+ break;
41
+ }
42
+ }
43
+ };
44
+ exports.processObjectSchema = processObjectSchema;
@@ -0,0 +1,11 @@
1
+ import { FormInfo } from '../../../types';
2
+ import { FormDetail, FormMetadata } from '../../../types/query-types';
3
+ /**
4
+ * Maps FormInfo to FormMetadata (lightweight version without schemas)
5
+ */
6
+ export declare function mapFormInfoToMetadata(formInfo: FormInfo): FormMetadata;
7
+ /**
8
+ * Maps FormInfo to FormDetail (includes schemas)
9
+ */
10
+ export declare function mapFormInfoToDetail(formInfo: FormInfo): FormDetail;
11
+ //# sourceMappingURL=map-form-info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-form-info.d.ts","sourceRoot":"","sources":["../../../../src/utils/add-query-fields/utils/map-form-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAGtE;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,GAAG,YAAY,CAMtE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,CA0BlE"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapFormInfoToMetadata = mapFormInfoToMetadata;
4
+ exports.mapFormInfoToDetail = mapFormInfoToDetail;
5
+ const get_json_schema_1 = require("./get-json-schema");
6
+ /**
7
+ * Maps FormInfo to FormMetadata (lightweight version without schemas)
8
+ */
9
+ function mapFormInfoToMetadata(formInfo) {
10
+ return {
11
+ name: formInfo.name,
12
+ title: formInfo.title,
13
+ description: formInfo.description
14
+ };
15
+ }
16
+ /**
17
+ * Maps FormInfo to FormDetail (includes schemas)
18
+ */
19
+ function mapFormInfoToDetail(formInfo) {
20
+ const { inputObjectInfo, outputObjectInfo } = formInfo;
21
+ // Generate JSON schemas for input object
22
+ const inputJsonSchema = (0, get_json_schema_1.getJsonSchemaByFieldInfoList)(inputObjectInfo.fieldInfoList);
23
+ const inputFormilyJsonSchema = (0, get_json_schema_1.getFormilyJsonSchemaByFieldInfoList)(inputObjectInfo.fieldInfoList);
24
+ // Generate JSON schemas for output object
25
+ const outputJsonSchema = (0, get_json_schema_1.getJsonSchemaByFieldInfoList)(outputObjectInfo.fieldInfoList);
26
+ const outputFormilyJsonSchema = (0, get_json_schema_1.getFormilyJsonSchemaByFieldInfoList)(outputObjectInfo.fieldInfoList);
27
+ return {
28
+ name: formInfo.name,
29
+ title: formInfo.title,
30
+ description: formInfo.description,
31
+ inputObjectInfo: {
32
+ ...inputObjectInfo,
33
+ jsonSchema: inputJsonSchema,
34
+ formilyJsonSchema: inputFormilyJsonSchema
35
+ },
36
+ outputObjectInfo: {
37
+ ...outputObjectInfo,
38
+ jsonSchema: outputJsonSchema,
39
+ formilyJsonSchema: outputFormilyJsonSchema
40
+ }
41
+ };
42
+ }
@@ -1,6 +1,6 @@
1
- import { SchemaComposerParams } from "@ldsg/graphql";
2
- import { ObjectTypeComposerFieldConfigMapDefinition } from "graphql-compose";
3
- import { FormInfo } from "../../types";
1
+ import { SchemaComposerParams } from '@ldsg/graphql';
2
+ import { ObjectTypeComposerFieldConfigMapDefinition } from 'graphql-compose';
3
+ import { FormInfo } from '../../types';
4
4
  interface GetNewFieldsParams extends SchemaComposerParams {
5
5
  formInfoList: FormInfo[];
6
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/get-new-fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EACL,0CAA0C,EAE3C,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,UAAU,kBAAmB,SAAQ,oBAAoB;IACvD,YAAY,EAAE,QAAQ,EAAE,CAAC;CAC1B;AAED,UAAU,eAAe;IACvB,SAAS,EAAE,0CAA0C,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;CACjE;AAED,KAAK,YAAY,GAAG,CAAC,MAAM,EAAE,kBAAkB,KAAK,eAAe,CAAC;AAEpE,eAAO,MAAM,YAAY,EAAE,YAgC1B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/get-new-fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,0CAA0C,EAAsB,MAAM,iBAAiB,CAAC;AAEjG,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,UAAU,kBAAmB,SAAQ,oBAAoB;IACvD,YAAY,EAAE,QAAQ,EAAE,CAAC;CAC1B;AAED,UAAU,eAAe;IACvB,SAAS,EAAE,0CAA0C,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;CACjE;AAED,KAAK,YAAY,GAAG,CAAC,MAAM,EAAE,kBAAkB,KAAK,eAAe,CAAC;AAEpE,eAAO,MAAM,YAAY,EAAE,YA+B1B,CAAC"}
@@ -16,15 +16,15 @@ const getNewFields = (params) => {
16
16
  const { inputITC } = (0, utils_1.getInputITC)({ schemaComposer, inputObjectInfo });
17
17
  const resolverDefinition = {
18
18
  name: graphqlFieldName,
19
- description: `${title}${description ? `:${description}` : ""}`,
19
+ description: `${title}${description ? `:${description}` : ''}`,
20
20
  type: outputOTC,
21
- args: inputITC.getFields(),
21
+ args: inputITC.getFields()
22
22
  };
23
23
  const fieldResolver = schemaComposer.createResolver(resolverDefinition);
24
24
  newFields[graphqlFieldName] = fieldResolver;
25
25
  });
26
26
  const res = {
27
- newFields,
27
+ newFields
28
28
  };
29
29
  return res;
30
30
  };
@@ -1,4 +1,4 @@
1
- import { FieldInfo } from "@ldsg/object";
1
+ import { FieldInfo } from '@ldsg/object';
2
2
  interface GetFieldConfigMapDefinitionParams {
3
3
  fieldInfoList: FieldInfo[];
4
4
  }
@@ -1 +1 @@
1
- {"version":3,"file":"get-field-config-map-definition.d.ts","sourceRoot":"","sources":["../../../../src/utils/get-new-fields/utils/get-field-config-map-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC,UAAU,iCAAiC;IACzC,aAAa,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED,UAAU,8BAA8B;IACtC,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/C;AAED,KAAK,2BAA2B,GAAG,CACjC,MAAM,EAAE,iCAAiC,KACtC,8BAA8B,CAAC;AAEpC,eAAO,MAAM,2BAA2B,EAAE,2BA2BzC,CAAC"}
1
+ {"version":3,"file":"get-field-config-map-definition.d.ts","sourceRoot":"","sources":["../../../../src/utils/get-new-fields/utils/get-field-config-map-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC,UAAU,iCAAiC;IACzC,aAAa,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED,UAAU,8BAA8B;IACtC,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/C;AAED,KAAK,2BAA2B,GAAG,CACjC,MAAM,EAAE,iCAAiC,KACtC,8BAA8B,CAAC;AAEpC,eAAO,MAAM,2BAA2B,EAAE,2BAyBzC,CAAC"}