@simitgroup/simpleapp-generator 1.6.6-l-alpha → 1.6.6-n-alpha

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 (50) hide show
  1. package/ReleaseNote.md +8 -1
  2. package/dist/buildinschemas/customfield.d.ts +3 -0
  3. package/dist/buildinschemas/customfield.d.ts.map +1 -0
  4. package/dist/buildinschemas/customfield.js +50 -0
  5. package/dist/buildinschemas/customfield.js.map +1 -0
  6. package/dist/buildinschemas/index.d.ts +1 -0
  7. package/dist/buildinschemas/index.d.ts.map +1 -1
  8. package/dist/buildinschemas/index.js +3 -2
  9. package/dist/buildinschemas/index.js.map +1 -1
  10. package/dist/framework.d.ts.map +1 -1
  11. package/dist/framework.js +1 -0
  12. package/dist/framework.js.map +1 -1
  13. package/dist/processors/jsonschemabuilder.d.ts.map +1 -1
  14. package/dist/processors/jsonschemabuilder.js +75 -35
  15. package/dist/processors/jsonschemabuilder.js.map +1 -1
  16. package/dist/type.d.ts +1 -0
  17. package/dist/type.d.ts.map +1 -1
  18. package/dist/type.js.map +1 -1
  19. package/package.json +1 -1
  20. package/reset-install.sh +2 -1
  21. package/src/buildinschemas/customfield.ts +47 -0
  22. package/src/buildinschemas/index.ts +11 -11
  23. package/src/framework.ts +2 -0
  24. package/src/processors/jsonschemabuilder.ts +268 -192
  25. package/src/type.ts +3 -2
  26. package/templates/basic/nest/apischema.ts.eta +33 -22
  27. package/templates/basic/nest/default.ts.eta +6 -1
  28. package/templates/basic/nest/type.ts.eta +9 -5
  29. package/templates/basic/nuxt/default.ts.eta +7 -1
  30. package/templates/basic/nuxt/pages.form.vue.eta +5 -3
  31. package/templates/basic/nuxt/simpleapp.generate.client.ts.eta +70 -32
  32. package/templates/nest/src/enums/enums.generate.ts.eta +23 -0
  33. package/templates/nest/src/simpleapp/generate/apischemas/simpleapp.apischema.ts.eta +7 -1
  34. package/templates/nest/src/simpleapp/generate/processors/simpleapp.processor.ts.eta +8 -0
  35. package/templates/nest/src/simpleapp/generate/types/simpleapp.type.ts.eta +7 -1
  36. package/templates/nuxt/.gitignore.eta +6 -5
  37. package/templates/nuxt/components/simpleApp/SimpleAppForm.vue.eta +8 -0
  38. package/templates/nuxt/components/simpleApp/SimpleAppInput.vue.eta +15 -2
  39. package/templates/nuxt/components/simpleApp/SimpleAppInputTable.vue.eta +6 -1
  40. package/templates/nuxt/composables/getUserStore.generate.ts.eta +4 -0
  41. package/templates/nuxt/enums/enums.generate.ts.eta +23 -0
  42. package/templates/nuxt/i18n/lang/cn.ts._eta +15 -0
  43. package/templates/nuxt/i18n/lang/en.ts.eta +19 -0
  44. package/templates/nuxt/lang/en.ts.eta +1 -1
  45. package/templates/nuxt/plugins/18.simpleapp-custom-field-store.ts.eta +38 -0
  46. package/templates/nuxt/plugins/19.app-plugins.ts.eta +422 -0
  47. package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +8 -1
  48. package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +249 -213
  49. package/templates/nuxt/simpleapp/generate/clients/SimpleAppCustomFieldClient.ts.eta +191 -0
  50. package/templates/nuxt/types/schema.ts.eta +19 -2
@@ -0,0 +1,191 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2025-06-09
5
+ */
6
+ import { isEmpty } from "lodash";
7
+ import {
8
+ CustomFieldItemJsonSchema,
9
+ CustomFieldJsonSchema,
10
+ SimpleAppJSONSchema7,
11
+ } from "~/types";
12
+
13
+ export type CustomFieldMoreDataGroup = {
14
+ [key: string]: CustomFieldMoreDataGroupItem;
15
+ };
16
+
17
+ export type CustomFieldMoreDataGroupItem = {
18
+ [key: string]: any;
19
+ };
20
+
21
+ export class SimpleAppCustomFieldClient {
22
+ private _defaultReturn = {
23
+ schema: {
24
+ type: "object",
25
+ properties: {},
26
+ },
27
+ };
28
+
29
+ constructor() {}
30
+
31
+ processCustomField(collectionName: string) {
32
+ // console.log(collectionName, "trigger processCustomField");
33
+ const { $customFieldStore } = useNuxtApp();
34
+ if (!$customFieldStore.data || isEmpty($customFieldStore.data)) {
35
+ // Not Found Any Custom Field
36
+ return this._defaultReturn;
37
+ }
38
+
39
+ const customField = $customFieldStore.findByCollectionName(collectionName);
40
+ if (!customField) {
41
+ // Not Found Custom Field In Current collectionName
42
+ return this._defaultReturn;
43
+ }
44
+
45
+ const schema = this._processCustomFieldMoreProperties(
46
+ collectionName,
47
+ customField.form.schema as CustomFieldItemJsonSchema,
48
+ );
49
+
50
+ return { schema };
51
+ }
52
+
53
+ private _processCustomFieldMoreProperties(
54
+ collectionName: string,
55
+ customFieldJsonSchemaString: CustomFieldItemJsonSchema | undefined,
56
+ ) {
57
+ const customFieldJsonSchema = this._processCustomFieldProperties(
58
+ customFieldJsonSchemaString,
59
+ );
60
+ const pluginJsonSchema =
61
+ this._processPluginCustomFieldProperties(collectionName);
62
+ return {
63
+ type: "object",
64
+ properties: {
65
+ ...customFieldJsonSchema,
66
+ ...pluginJsonSchema,
67
+ },
68
+ };
69
+ }
70
+
71
+ private _processPluginCustomFieldProperties(collectionName: string) {
72
+ const schema: CustomFieldJsonSchema["properties"] = {};
73
+ const { $appPluginsStore } = useNuxtApp();
74
+ const pluginForms = $appPluginsStore.getForm(collectionName);
75
+ if (!pluginForms || pluginForms.length <= 0) {
76
+ return schema;
77
+ }
78
+
79
+ for (let i = 0; i < pluginForms.length; i++) {
80
+ const pluginItem = pluginForms[i];
81
+ const { pluginCode, jsonSchema } = pluginItem;
82
+
83
+ schema[pluginCode] = jsonSchema as CustomFieldItemJsonSchema;
84
+ }
85
+
86
+ return schema;
87
+ }
88
+
89
+ private _processCustomFieldProperties(
90
+ customFieldJsonSchemaString: CustomFieldItemJsonSchema | undefined,
91
+ ) {
92
+ if (!customFieldJsonSchemaString) {
93
+ return this._defaultReturn;
94
+ }
95
+
96
+ return {
97
+ default: {
98
+ title: "Custom Field",
99
+ ...customFieldJsonSchemaString,
100
+ },
101
+ };
102
+ }
103
+
104
+ processCustomFieldData(
105
+ moreSchema: CustomFieldJsonSchema | undefined,
106
+ isNew: boolean,
107
+ resourceData: CustomFieldMoreDataGroup | undefined,
108
+ ) {
109
+ const data: Record<string, any> = {};
110
+ if (!moreSchema || !moreSchema?.properties) {
111
+ return data;
112
+ }
113
+
114
+ for (const [groupName, groupItem] of Object.entries(
115
+ moreSchema.properties,
116
+ )) {
117
+ let groupData: Record<string, any> = {};
118
+ if (groupItem.properties) {
119
+ groupData = this._processGroupItemData(
120
+ groupItem.properties,
121
+ isNew,
122
+ resourceData?.[groupName],
123
+ );
124
+ }
125
+
126
+ data[groupName] = groupData;
127
+ }
128
+
129
+ return data;
130
+ }
131
+
132
+ private _processGroupItemData(
133
+ groupItemProp: SimpleAppJSONSchema7 | SimpleAppJSONSchema7[] | undefined,
134
+ isNew: boolean,
135
+ resourceData: CustomFieldMoreDataGroupItem | undefined,
136
+ ) {
137
+ const data: Record<string, any> = {};
138
+
139
+ if (!groupItemProp) {
140
+ return data;
141
+ }
142
+
143
+ for (const [fieldName, fieldItem] of Object.entries(groupItemProp)) {
144
+ let value;
145
+ if (isNew) {
146
+ // New Record
147
+ value = this._getFieldDefaultValue(fieldItem);
148
+ } else {
149
+ // Fetch By Id
150
+ if (resourceData?.[fieldName]) {
151
+ // DB got this field
152
+ value = resourceData?.[fieldName];
153
+ } else {
154
+ // DB don't have this field
155
+ value = this._getDefaultValueByType(fieldItem);
156
+ console.log(fieldName, value);
157
+ }
158
+ }
159
+
160
+ data[fieldName] = value;
161
+ }
162
+
163
+ return data;
164
+ }
165
+
166
+ private _getFieldDefaultValue(fieldItem: SimpleAppJSONSchema7) {
167
+ return fieldItem.default !== undefined
168
+ ? fieldItem.default
169
+ : this._getDefaultValueByType(fieldItem);
170
+ }
171
+
172
+ private _getDefaultValueByType(fieldItem: SimpleAppJSONSchema7) {
173
+ if (fieldItem.type === "string") {
174
+ return "";
175
+ }
176
+
177
+ if (fieldItem.type === "number") {
178
+ return 0;
179
+ }
180
+
181
+ if (fieldItem.type === "object") {
182
+ return {};
183
+ }
184
+
185
+ if (fieldItem.type === "array") {
186
+ return [];
187
+ }
188
+
189
+ return "";
190
+ }
191
+ }
@@ -89,7 +89,7 @@ export type SchemaFields = {
89
89
  // modified from jsonschemas
90
90
  export type SimpleAppJSONSchema7Definition = SimpleAppJSONSchema7 | boolean;
91
91
  export interface SimpleAppJSONSchema7 {
92
-
92
+ inputType?: string;
93
93
  'x-foreignkey' ?:string
94
94
  $id?: string | undefined;
95
95
  $ref?: string | undefined;
@@ -197,4 +197,21 @@ export type SchemaFields = {
197
197
  readOnly?: boolean | undefined;
198
198
  writeOnly?: boolean | undefined;
199
199
  examples?: JSONSchema7Type[] | undefined;
200
- }
200
+ }
201
+
202
+
203
+ // ==================== Start Custom Field ====================
204
+
205
+ export type CustomFieldJsonSchema = {
206
+ type: string;
207
+ required?: string[];
208
+ properties: Record<string, CustomFieldItemJsonSchema>;
209
+ };
210
+
211
+ export type CustomFieldItemJsonSchema = {
212
+ type: string;
213
+ required?: string[];
214
+ properties?: SimpleAppJSONSchema7 | SimpleAppJSONSchema7[] | undefined;
215
+ };
216
+
217
+ // ===================== End Custom Field =====================