@paris-ias/trees 1.8.56
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/LICENSE +679 -0
- package/dist/form/action.js +83 -0
- package/dist/form/affiliation.js +178 -0
- package/dist/form/apps.js +132 -0
- package/dist/form/disciplines.js +30 -0
- package/dist/form/events.js +836 -0
- package/dist/form/fellowships.js +1307 -0
- package/dist/form/files.js +30 -0
- package/dist/form/mailing.js +43 -0
- package/dist/form/news.js +252 -0
- package/dist/form/people.js +658 -0
- package/dist/form/projects.js +338 -0
- package/dist/form/publications.js +364 -0
- package/dist/form/tags.js +38 -0
- package/dist/form/users.js +576 -0
- package/dist/graphql/client/action/query.get.action.gql +22 -0
- package/dist/graphql/client/action/query.list.action.gql +32 -0
- package/dist/graphql/client/affiliation/query.get.affiliations.gql +37 -0
- package/dist/graphql/client/affiliation/query.list.affiliations.gql +43 -0
- package/dist/graphql/client/apps/query.get.apps.gql +33 -0
- package/dist/graphql/client/apps/query.list.apps.gql +43 -0
- package/dist/graphql/client/events/query.get.events.gql +119 -0
- package/dist/graphql/client/events/query.list.events.gql +40 -0
- package/dist/graphql/client/fellowships/query.get.fellowships.gql +163 -0
- package/dist/graphql/client/fellowships/query.list.fellowships.gql +49 -0
- package/dist/graphql/client/files/query.get.files.gql +24 -0
- package/dist/graphql/client/files/query.list.files.gql +37 -0
- package/dist/graphql/client/mailing/query.get.mailing.gql +24 -0
- package/dist/graphql/client/mailing/query.list.mailing.gql +23 -0
- package/dist/graphql/client/misc/apex.mutations.delete.gql +0 -0
- package/dist/graphql/client/misc/apex.mutations.upsert.gql +0 -0
- package/dist/graphql/client/misc/apex.queries.login.gql +0 -0
- package/dist/graphql/client/misc/query.get.disciplines.gql +17 -0
- package/dist/graphql/client/misc/query.get.tags.gql +13 -0
- package/dist/graphql/client/misc/query.list.disciplines.gql +23 -0
- package/dist/graphql/client/misc/query.list.tags.gql +23 -0
- package/dist/graphql/client/news/query.get.news.gql +128 -0
- package/dist/graphql/client/news/query.list.news.gql +35 -0
- package/dist/graphql/client/people/query.get.people.gql +173 -0
- package/dist/graphql/client/people/query.get.users.gql +0 -0
- package/dist/graphql/client/people/query.list.people.gql +55 -0
- package/dist/graphql/client/people/query.list.users.gql +31 -0
- package/dist/graphql/client/projects/query.get.projects.gql +166 -0
- package/dist/graphql/client/projects/query.list.projects.gql +33 -0
- package/dist/graphql/client/publications/query.get.publications.gql +169 -0
- package/dist/graphql/client/publications/query.list.publications.gql +35 -0
- package/dist/graphql/schemas/apex-resolvers-list.json +45 -0
- package/dist/graphql/schemas/schema.apex.graphql +946 -0
- package/dist/graphql/schemas/schema.website.graphql +794 -0
- package/dist/graphql/schemas/website-resolvers-list.json +22 -0
- package/dist/list/action.js +133 -0
- package/dist/list/affiliation.js +133 -0
- package/dist/list/apps.js +133 -0
- package/dist/list/disciplines.js +132 -0
- package/dist/list/events.js +186 -0
- package/dist/list/fellowships.js +149 -0
- package/dist/list/files.js +132 -0
- package/dist/list/mailing.js +132 -0
- package/dist/list/news.js +135 -0
- package/dist/list/people.js +176 -0
- package/dist/list/projects.js +135 -0
- package/dist/list/publications.js +152 -0
- package/dist/list/tags.js +133 -0
- package/dist/list/users.js +176 -0
- package/index.ts +63 -0
- package/lib/README.md +206 -0
- package/lib/buildClientGraphQL.ts +342 -0
- package/lib/buildDefaults.ts +0 -0
- package/lib/buildSchemas.ts +109 -0
- package/lib/generate.ts +505 -0
- package/lib/generateAll.ts +231 -0
- package/lib/utils.ts +24 -0
- package/package.json +34 -0
- package/readme.md +116 -0
- package/src/LICENSE +661 -0
- package/src/action/graphql/client/query.get.action.gql +22 -0
- package/src/action/graphql/client/query.list.action.gql +32 -0
- package/src/action/graphql/server/apex.types.action.graphql +15 -0
- package/src/action/models/action.ts +147 -0
- package/src/affiliation/graphql/client/query.get.affiliations.gql +37 -0
- package/src/affiliation/graphql/client/query.list.affiliations.gql +43 -0
- package/src/affiliation/graphql/server/shared.types.affiliations.graphql +20 -0
- package/src/affiliation/models/affiliation.ts +130 -0
- package/src/affiliation/models/member.ts +11 -0
- package/src/affiliation/models/partner.ts +9 -0
- package/src/apps/graphql/client/query.get.apps.gql +33 -0
- package/src/apps/graphql/client/query.list.apps.gql +43 -0
- package/src/apps/models/apps.ts +195 -0
- package/src/events/graphql/client/query.get.events.gql +119 -0
- package/src/events/graphql/client/query.list.events.gql +40 -0
- package/src/events/graphql/server/shared.inputs.events.graphql +24 -0
- package/src/events/models/eventSlot.ts +73 -0
- package/src/events/models/events.ts +569 -0
- package/src/fellowships/graphql/client/query.get.fellowships.gql +163 -0
- package/src/fellowships/graphql/client/query.list.fellowships.gql +49 -0
- package/src/fellowships/graphql/server/apex.inputs.fellowshipDetails.graphql +13 -0
- package/src/fellowships/graphql/server/shared.types.fellowshipDetails.graphql +13 -0
- package/src/fellowships/graphql/server/shared.types.fellowships.graphql +38 -0
- package/src/fellowships/models/fellowshipDetails.ts +145 -0
- package/src/fellowships/models/fellowships.ts +341 -0
- package/src/files/graphql/client/query.get.files.gql +24 -0
- package/src/files/graphql/client/query.list.files.gql +37 -0
- package/src/files/graphql/server/apex.inputs.files.graphql +7 -0
- package/src/files/graphql/server/apex.inputs.video.graphql +9 -0
- package/src/files/graphql/server/apex.types.files.graphql +4 -0
- package/src/files/graphql/server/shared.inputs.image.graphql +9 -0
- package/src/files/graphql/server/shared.types.files.graphql +15 -0
- package/src/files/graphql/server/shared.types.image.graphql +9 -0
- package/src/files/graphql/server/shared.types.video.graphql +9 -0
- package/src/files/models/files.ts +113 -0
- package/src/files/models/gallery.ts +11 -0
- package/src/files/models/image.ts +159 -0
- package/src/files/models/video.ts +166 -0
- package/src/form.ts +52 -0
- package/src/index.ts +98 -0
- package/src/list.ts +34 -0
- package/src/mailing/graphql/client/query.get.mailing.gql +24 -0
- package/src/mailing/graphql/client/query.list.mailing.gql +23 -0
- package/src/mailing/graphql/server/apex.types.mailing.graphql +13 -0
- package/src/mailing/models/mailing.ts +123 -0
- package/src/misc/graphql/client/apex.mutations.delete.gql +0 -0
- package/src/misc/graphql/client/apex.mutations.upsert.gql +0 -0
- package/src/misc/graphql/client/apex.queries.login.gql +0 -0
- package/src/misc/graphql/client/query.get.disciplines.gql +17 -0
- package/src/misc/graphql/client/query.get.tags.gql +13 -0
- package/src/misc/graphql/client/query.list.disciplines.gql +23 -0
- package/src/misc/graphql/client/query.list.tags.gql +23 -0
- package/src/misc/graphql/server/apex.inputs.misc.graphql +13 -0
- package/src/misc/graphql/server/apex.inputs.socials.graphql +12 -0
- package/src/misc/graphql/server/apex.mutations.graphql +23 -0
- package/src/misc/graphql/server/apex.queries.graphql +36 -0
- package/src/misc/graphql/server/apex.types.disciplines.graphql +4 -0
- package/src/misc/graphql/server/apex.types.tags.graphql +4 -0
- package/src/misc/graphql/server/shared.enums.graphql +112 -0
- package/src/misc/graphql/server/shared.inputs.misc.graphql +101 -0
- package/src/misc/graphql/server/shared.queries.graphql +35 -0
- package/src/misc/graphql/server/shared.types.disciplines.graphql +8 -0
- package/src/misc/graphql/server/shared.types.events.graphql +39 -0
- package/src/misc/graphql/server/shared.types.location.graphql +17 -0
- package/src/misc/graphql/server/shared.types.misc.graphql +120 -0
- package/src/misc/graphql/server/shared.types.related.graphql +10 -0
- package/src/misc/graphql/server/shared.types.relatedAffiliation.graphql +7 -0
- package/src/misc/graphql/server/shared.types.relatedEvent.graphql +7 -0
- package/src/misc/graphql/server/shared.types.relatedFellowships.graphql +7 -0
- package/src/misc/graphql/server/shared.types.relatedNews.graphql +7 -0
- package/src/misc/graphql/server/shared.types.relatedPeople.graphql +6 -0
- package/src/misc/graphql/server/shared.types.relatedProject.graphql +7 -0
- package/src/misc/graphql/server/shared.types.relatedPublications.graphql +6 -0
- package/src/misc/graphql/server/shared.types.socials.graphql +22 -0
- package/src/misc/graphql/server/shared.types.tags.graphql +11 -0
- package/src/misc/graphql/server/website.mutations.graphql +4 -0
- package/src/misc/models/disciplines.ts +116 -0
- package/src/misc/models/location.ts +136 -0
- package/src/misc/models/organizers.ts +13 -0
- package/src/misc/models/related.ts +123 -0
- package/src/misc/models/relatedEvents.ts +16 -0
- package/src/misc/models/relatedFellowships.ts +7 -0
- package/src/misc/models/relatedNews.ts +13 -0
- package/src/misc/models/relatedPeople.ts +8 -0
- package/src/misc/models/relatedProject.ts +14 -0
- package/src/misc/models/relatedPublications.ts +14 -0
- package/src/misc/models/socials.ts +133 -0
- package/src/misc/models/sponsor.ts +13 -0
- package/src/misc/models/tags.ts +116 -0
- package/src/misc/models/taxonomy.ts +1 -0
- package/src/model.ts +7 -0
- package/src/news/graphql/client/query.get.news.gql +128 -0
- package/src/news/graphql/client/query.list.news.gql +35 -0
- package/src/news/graphql/server/share.types.news.graphql +27 -0
- package/src/news/models/news.ts +257 -0
- package/src/people/graphql/client/query.get.people.gql +173 -0
- package/src/people/graphql/client/query.get.users.gql +0 -0
- package/src/people/graphql/client/query.list.people.gql +55 -0
- package/src/people/graphql/client/query.list.users.gql +31 -0
- package/src/people/graphql/server/apex.inputs.consent.graphql +9 -0
- package/src/people/graphql/server/apex.inputs.groups.graphql +8 -0
- package/src/people/graphql/server/apex.inputs.vintage.graphql +6 -0
- package/src/people/graphql/server/shared.types.consent.graphql +9 -0
- package/src/people/graphql/server/shared.types.groups.graphql +8 -0
- package/src/people/graphql/server/shared.types.people.graphql +29 -0
- package/src/people/graphql/server/shared.types.position.graphql +6 -0
- package/src/people/graphql/server/shared.types.users.graphql +17 -0
- package/src/people/graphql/server/shared.types.vintage.graphql +6 -0
- package/src/people/models/consent.ts +82 -0
- package/src/people/models/discussants.ts +9 -0
- package/src/people/models/experiences.ts +38 -0
- package/src/people/models/fellows.ts +12 -0
- package/src/people/models/groups.ts +58 -0
- package/src/people/models/people.ts +244 -0
- package/src/people/models/position.ts +62 -0
- package/src/people/models/speakers.ts +9 -0
- package/src/people/models/users.ts +252 -0
- package/src/people/models/vintage.ts +124 -0
- package/src/projects/graphql/client/query.get.projects.gql +166 -0
- package/src/projects/graphql/client/query.list.projects.gql +33 -0
- package/src/projects/graphql/server/shared.types.projects.graphql +29 -0
- package/src/projects/models/projects.ts +249 -0
- package/src/publications/graphql/client/query.get.publications.gql +169 -0
- package/src/publications/graphql/client/query.list.publications.gql +35 -0
- package/src/publications/graphql/server/shared.types.publications.graphql +34 -0
- package/src/publications/models/article.ts +262 -0
- package/src/publications/models/publications.ts +306 -0
package/lib/generate.ts
ADDED
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import { templates, Form, Model, Sort, Views } from "../src/index.ts"
|
|
2
|
+
import { createJsonFile } from "./utils.ts"
|
|
3
|
+
import { formType } from "../src/form.ts"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* List configuration interface for generated modules
|
|
7
|
+
*/
|
|
8
|
+
interface List {
|
|
9
|
+
items: any[]
|
|
10
|
+
itemsPerPage?: number
|
|
11
|
+
itemsPerPageArray?: number[]
|
|
12
|
+
filtersCount: number
|
|
13
|
+
views?: Record<string, Views>
|
|
14
|
+
sort: Record<string, Sort>
|
|
15
|
+
view: Views | string | undefined
|
|
16
|
+
filters: Record<string, any>
|
|
17
|
+
limit?: number
|
|
18
|
+
sortBy: Sort | string[] | undefined
|
|
19
|
+
sortDesc?: Sort | number[] | string[] | string | undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Custom form interface for generated modules
|
|
24
|
+
*/
|
|
25
|
+
interface CustomForm {
|
|
26
|
+
_defaults: Record<string, Form> | string
|
|
27
|
+
schema: Record<string, Form>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Module type interface that combines form and list configurations
|
|
32
|
+
*/
|
|
33
|
+
export interface ModuleType {
|
|
34
|
+
source?: string
|
|
35
|
+
form: CustomForm
|
|
36
|
+
list: List
|
|
37
|
+
loading: boolean
|
|
38
|
+
current: any
|
|
39
|
+
resetFilters: boolean
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Generation error types for better error handling
|
|
44
|
+
*/
|
|
45
|
+
interface GenerationError {
|
|
46
|
+
type:
|
|
47
|
+
| "CIRCULAR_DEPENDENCY"
|
|
48
|
+
| "MISSING_TEMPLATE"
|
|
49
|
+
| "INVALID_SCHEMA"
|
|
50
|
+
| "BUILD_ERROR"
|
|
51
|
+
message: string
|
|
52
|
+
context: { key?: string; template?: string; error?: any }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const buildDefaults = (schema: Record<string, any>): Record<string, any> => {
|
|
56
|
+
const result: Record<string, any> = {}
|
|
57
|
+
for (const [key, field] of Object.entries(schema || {})) {
|
|
58
|
+
switch (field.type) {
|
|
59
|
+
case formType.Primitive: {
|
|
60
|
+
if (field.i18n) {
|
|
61
|
+
result[key] = { en: "", fr: "" } // default i18n structure
|
|
62
|
+
} else if (field.default) result[key] = field.default
|
|
63
|
+
else if (field.component === "Checkbox") result[key] = false
|
|
64
|
+
else result[key] = ""
|
|
65
|
+
break
|
|
66
|
+
}
|
|
67
|
+
case formType.Document: {
|
|
68
|
+
result[key] = field.default ?? ""
|
|
69
|
+
break
|
|
70
|
+
}
|
|
71
|
+
case formType.Object: {
|
|
72
|
+
result[key] = buildDefaults(field.items || {})
|
|
73
|
+
break
|
|
74
|
+
}
|
|
75
|
+
case formType.Array: {
|
|
76
|
+
result[key] = field && field.items && [buildDefaults(field.items)]
|
|
77
|
+
break
|
|
78
|
+
}
|
|
79
|
+
case formType.Template: {
|
|
80
|
+
result[key] = field && field.items && buildDefaults(field.items)
|
|
81
|
+
break
|
|
82
|
+
}
|
|
83
|
+
default: {
|
|
84
|
+
result[key] = field && field.items && buildDefaults(field.items)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return result
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Completes form schema by resolving templates and handling nested structures
|
|
93
|
+
* @param schema - The form schema to complete
|
|
94
|
+
* @param visitedTemplates - Set of visited templates to prevent circular dependencies
|
|
95
|
+
* @returns Completed schema with all templates resolved
|
|
96
|
+
*/
|
|
97
|
+
const completeSchema = (
|
|
98
|
+
schema: Record<string, Form>,
|
|
99
|
+
visitedTemplates: Set<string> = new Set()
|
|
100
|
+
): Record<string, Form> => {
|
|
101
|
+
const completedSchema: Record<string, Form> = {}
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
for (const key of Object.keys(schema)) {
|
|
105
|
+
try {
|
|
106
|
+
switch (schema[key]?.type) {
|
|
107
|
+
case formType.Primitive:
|
|
108
|
+
completedSchema[key] = schema[key]
|
|
109
|
+
break
|
|
110
|
+
|
|
111
|
+
case formType.Object:
|
|
112
|
+
completedSchema[key] = {
|
|
113
|
+
...schema[key],
|
|
114
|
+
items: completeSchema(
|
|
115
|
+
schema[key].items as Record<string, Form>,
|
|
116
|
+
visitedTemplates
|
|
117
|
+
),
|
|
118
|
+
}
|
|
119
|
+
break
|
|
120
|
+
|
|
121
|
+
case formType.Array:
|
|
122
|
+
completedSchema[key] = {
|
|
123
|
+
...schema[key],
|
|
124
|
+
items: completeSchema(
|
|
125
|
+
{ [key]: schema[key].items } as Record<string, Form>,
|
|
126
|
+
visitedTemplates
|
|
127
|
+
),
|
|
128
|
+
}
|
|
129
|
+
break
|
|
130
|
+
|
|
131
|
+
case formType.Document:
|
|
132
|
+
completedSchema[key] = {
|
|
133
|
+
...schema[key],
|
|
134
|
+
default: schema[key].default ?? "",
|
|
135
|
+
}
|
|
136
|
+
break
|
|
137
|
+
|
|
138
|
+
case formType.Template:
|
|
139
|
+
// Check for circular dependencies
|
|
140
|
+
if (visitedTemplates.has(key)) {
|
|
141
|
+
const error: GenerationError = {
|
|
142
|
+
type: "CIRCULAR_DEPENDENCY",
|
|
143
|
+
message: `Circular dependency detected for template: ${key}`,
|
|
144
|
+
context: { key, template: key },
|
|
145
|
+
}
|
|
146
|
+
console.warn(`ā ļø ${error.message}`)
|
|
147
|
+
completedSchema[key] = { ...schema[key], items: {} } // Break the cycle
|
|
148
|
+
continue
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
console.log(`š¦ Importing template: ${key}`)
|
|
152
|
+
|
|
153
|
+
visitedTemplates.add(key)
|
|
154
|
+
try {
|
|
155
|
+
if (!templates[key]) {
|
|
156
|
+
const error: GenerationError = {
|
|
157
|
+
type: "MISSING_TEMPLATE",
|
|
158
|
+
message: `Template '${key}' not found in templates`,
|
|
159
|
+
context: { key, template: key },
|
|
160
|
+
}
|
|
161
|
+
console.error(`ā ${error.message}`)
|
|
162
|
+
completedSchema[key] = { ...schema[key], items: {} }
|
|
163
|
+
continue
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
completedSchema[key] = {
|
|
167
|
+
...schema[key],
|
|
168
|
+
type: schema[key]?.component.toLowerCase().startsWith("object")
|
|
169
|
+
? formType.Object
|
|
170
|
+
: formType.Array,
|
|
171
|
+
items: completeSchema(
|
|
172
|
+
templates[key].form as Record<string, Form>,
|
|
173
|
+
visitedTemplates
|
|
174
|
+
),
|
|
175
|
+
}
|
|
176
|
+
} finally {
|
|
177
|
+
visitedTemplates.delete(key)
|
|
178
|
+
}
|
|
179
|
+
break
|
|
180
|
+
|
|
181
|
+
default:
|
|
182
|
+
console.warn(
|
|
183
|
+
`ā ļø Unknown form type for key '${key}': ${schema[key]?.type}`
|
|
184
|
+
)
|
|
185
|
+
break
|
|
186
|
+
}
|
|
187
|
+
} catch (fieldError) {
|
|
188
|
+
const error: GenerationError = {
|
|
189
|
+
type: "INVALID_SCHEMA",
|
|
190
|
+
message: `Error processing field '${key}'`,
|
|
191
|
+
context: { key, error: fieldError },
|
|
192
|
+
}
|
|
193
|
+
console.error(`ā ${error.message}:`, fieldError)
|
|
194
|
+
// Continue with other fields
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return completedSchema
|
|
199
|
+
} catch (error) {
|
|
200
|
+
const genError: GenerationError = {
|
|
201
|
+
type: "BUILD_ERROR",
|
|
202
|
+
message: "Error completing schema",
|
|
203
|
+
context: { error },
|
|
204
|
+
}
|
|
205
|
+
console.error(`š„ ${genError.message}:`, error)
|
|
206
|
+
return {}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Creates a complete module configuration for a given type
|
|
212
|
+
* @param type - The type name to create module for
|
|
213
|
+
*/
|
|
214
|
+
const createModule = (type: string): void => {
|
|
215
|
+
console.log(`\nšØ Creating module for: ${type.toUpperCase()}`)
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
const baseType = templates[type] as Model
|
|
219
|
+
|
|
220
|
+
if (!baseType) {
|
|
221
|
+
console.error(`ā No configuration found for type: ${type}`)
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const baseSchema: Record<string, Form> | undefined = baseType.form
|
|
226
|
+
if (!baseSchema) {
|
|
227
|
+
console.warn(`ā ļø No form schema found for type: ${type}`)
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
console.log(
|
|
232
|
+
` š Processing ${Object.keys(baseSchema).length} form fields...`
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
const defaultState: Record<string, Form> = completeSchema(baseSchema)
|
|
236
|
+
|
|
237
|
+
// Find default view
|
|
238
|
+
const defaultViewKey: string | undefined =
|
|
239
|
+
baseType?.list?.views &&
|
|
240
|
+
Object.keys(baseType.list.views).find((item) => {
|
|
241
|
+
return baseType.list.views[item]?.default === true
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
const defaultView =
|
|
245
|
+
defaultViewKey !== undefined
|
|
246
|
+
? { ...baseType?.list.views[defaultViewKey], name: defaultViewKey }
|
|
247
|
+
: undefined
|
|
248
|
+
|
|
249
|
+
// Find default sort
|
|
250
|
+
const defaultSortKey: string | undefined =
|
|
251
|
+
baseType?.list.sort &&
|
|
252
|
+
Object.keys(baseType.list.sort).find((item) => {
|
|
253
|
+
return baseType.list.sort[item].default === true
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
const defaultPerPage = defaultView?.perPage?.default
|
|
257
|
+
const perPageOptions = defaultView?.perPage?.options
|
|
258
|
+
|
|
259
|
+
const defaultSort: Sort | undefined =
|
|
260
|
+
defaultSortKey !== undefined
|
|
261
|
+
? baseType?.list.sort[defaultSortKey]
|
|
262
|
+
: undefined
|
|
263
|
+
|
|
264
|
+
console.log(
|
|
265
|
+
` š List config: ${
|
|
266
|
+
defaultView ? defaultView.name : "no default"
|
|
267
|
+
} view, ${defaultSort ? "sorted by " + defaultSortKey : "no sort"}`
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
// Create a Set to track visited templates and prevent circular dependencies
|
|
271
|
+
const visitedTemplates = new Set<string>()
|
|
272
|
+
|
|
273
|
+
// Helper function to handle aliases
|
|
274
|
+
const processAliases = (aliases: string[]): Record<string, Form> => {
|
|
275
|
+
console.log("aliases: ", aliases)
|
|
276
|
+
let aliasTemplatesForms: Record<string, Form> = {}
|
|
277
|
+
|
|
278
|
+
aliases.map((alias) => {
|
|
279
|
+
const aliasTemplate = templates[alias]
|
|
280
|
+
aliasTemplatesForms = {
|
|
281
|
+
...aliasTemplatesForms,
|
|
282
|
+
...aliasTemplate.form,
|
|
283
|
+
}
|
|
284
|
+
return aliasTemplatesForms
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
return aliasTemplatesForms
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Helper function to handle template types
|
|
291
|
+
const processTemplate = (key: string): Promise<any> => {
|
|
292
|
+
/* console.log("key2: ", key) */
|
|
293
|
+
// Check for circular dependencies
|
|
294
|
+
if (visitedTemplates.has(key)) {
|
|
295
|
+
console.warn(`Circular dependency detected for template: ${key}`)
|
|
296
|
+
return Promise.resolve({}) // Return empty object to break the cycle
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Add current template to visited set
|
|
300
|
+
visitedTemplates.add(key)
|
|
301
|
+
|
|
302
|
+
const template = templates[key] as Model
|
|
303
|
+
try {
|
|
304
|
+
// is it an implementation of another template?
|
|
305
|
+
if (template?.aliases?.length) {
|
|
306
|
+
const aliasTemplatesForms: Record<string, Form> = processAliases(
|
|
307
|
+
template.aliases
|
|
308
|
+
)
|
|
309
|
+
const result = buildForm(aliasTemplatesForms)
|
|
310
|
+
// build based on aliases
|
|
311
|
+
return result
|
|
312
|
+
} else {
|
|
313
|
+
return buildForm(template.form as Record<string, Form>)
|
|
314
|
+
}
|
|
315
|
+
} finally {
|
|
316
|
+
// Remove the template from visited set after processing
|
|
317
|
+
visitedTemplates.delete(key)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Helper function to process items within the schema
|
|
322
|
+
const processItems = (key: string, items: any[], form: any): any => {
|
|
323
|
+
/* console.log("processing items for key: ", key) */
|
|
324
|
+
|
|
325
|
+
// only collection have items with an array type
|
|
326
|
+
if (form[key] && form[key].type === formType.Array) {
|
|
327
|
+
// if (!form[key]) form[key] = [{}];
|
|
328
|
+
if (!form[key]) {
|
|
329
|
+
form[key] = [{}]
|
|
330
|
+
}
|
|
331
|
+
/* for (const item of items) {
|
|
332
|
+
form[key][0] = {
|
|
333
|
+
...form[key][0],
|
|
334
|
+
...( buildForm({ [item.key]: item })),
|
|
335
|
+
}
|
|
336
|
+
} */
|
|
337
|
+
// else it's an object
|
|
338
|
+
} else {
|
|
339
|
+
if (!form[key]) form[key] = {}
|
|
340
|
+
if (items && Object.keys(items).length) {
|
|
341
|
+
for (const subkey of Object.keys(items)) {
|
|
342
|
+
form[key] = {
|
|
343
|
+
...form[key],
|
|
344
|
+
...buildForm({ [subkey]: items[subkey] }),
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
} else {
|
|
348
|
+
console.log("no items found for key: ", key)
|
|
349
|
+
if (["location", "image"].includes(key)) {
|
|
350
|
+
console.log(form)
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Build the form
|
|
357
|
+
const buildForm = (schema: Record<string, Form>): any => {
|
|
358
|
+
try {
|
|
359
|
+
if (!schema) return {}
|
|
360
|
+
let form: { [key: string]: any } = {}
|
|
361
|
+
for (const key of Object.keys(schema)) {
|
|
362
|
+
switch (schema[key]?.type as formType) {
|
|
363
|
+
// document picker
|
|
364
|
+
case formType.Document:
|
|
365
|
+
/* console.log("document picker for key: ", key) */
|
|
366
|
+
form[key] = schema[key]?.default ?? []
|
|
367
|
+
break
|
|
368
|
+
|
|
369
|
+
// template import
|
|
370
|
+
case formType.Template:
|
|
371
|
+
/* console.log("template import for key: ", key) */
|
|
372
|
+
|
|
373
|
+
// Check if this is a template we're already processing (to avoid circular dependencies)
|
|
374
|
+
if (visitedTemplates.has(key)) {
|
|
375
|
+
console.warn(
|
|
376
|
+
`Avoiding circular dependency for template key: ${key}`
|
|
377
|
+
)
|
|
378
|
+
form[key] = {} // Use empty object to break the cycle
|
|
379
|
+
} else {
|
|
380
|
+
form[key] = processTemplate(key)
|
|
381
|
+
}
|
|
382
|
+
break
|
|
383
|
+
|
|
384
|
+
// object
|
|
385
|
+
case formType.Object:
|
|
386
|
+
/* console.log("object for key: ", key) */
|
|
387
|
+
processItems(key, schema[key].items, form)
|
|
388
|
+
break
|
|
389
|
+
|
|
390
|
+
// collection
|
|
391
|
+
case formType.Array:
|
|
392
|
+
/* console.log("collection for key: ", key) */
|
|
393
|
+
processItems(key, schema[key].items, form)
|
|
394
|
+
break
|
|
395
|
+
|
|
396
|
+
// primitive
|
|
397
|
+
case formType.Primitive:
|
|
398
|
+
/* console.log("primitive for key: ", key) */
|
|
399
|
+
form[key] = schema[key]?.default ?? ""
|
|
400
|
+
break
|
|
401
|
+
|
|
402
|
+
default:
|
|
403
|
+
console.log("missing type in form builder for key: ", key)
|
|
404
|
+
break
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return form
|
|
408
|
+
} catch (error) {
|
|
409
|
+
console.log("error building form: ", error)
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const formModule = {
|
|
414
|
+
_defaults: buildDefaults(defaultState),
|
|
415
|
+
schema: defaultState,
|
|
416
|
+
}
|
|
417
|
+
const listModule = {
|
|
418
|
+
items: Array(defaultPerPage || 9).fill({}),
|
|
419
|
+
...(defaultPerPage && {
|
|
420
|
+
itemsPerPage: defaultPerPage,
|
|
421
|
+
}),
|
|
422
|
+
...(perPageOptions && {
|
|
423
|
+
itemsPerPageArray: perPageOptions,
|
|
424
|
+
}),
|
|
425
|
+
filtersCount: 0,
|
|
426
|
+
...(baseType?.list?.views && {
|
|
427
|
+
views: baseType.list?.views,
|
|
428
|
+
}),
|
|
429
|
+
...(baseType?.list?.sort && {
|
|
430
|
+
sort: baseType.list?.sort,
|
|
431
|
+
}),
|
|
432
|
+
view: defaultView,
|
|
433
|
+
filters: baseType?.list?.filters,
|
|
434
|
+
...(defaultPerPage && {
|
|
435
|
+
limit: defaultPerPage,
|
|
436
|
+
}),
|
|
437
|
+
sortBy: defaultSort && [defaultSort.value[0]],
|
|
438
|
+
sortDesc: defaultSort && [defaultSort.value[1]],
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Create the output files
|
|
442
|
+
createJsonFile(type, listModule, "/list")
|
|
443
|
+
createJsonFile(type, formModule, "/form")
|
|
444
|
+
|
|
445
|
+
console.log(`ā
Module '${type}' generated successfully`)
|
|
446
|
+
} catch (error) {
|
|
447
|
+
const genError: GenerationError = {
|
|
448
|
+
type: "BUILD_ERROR",
|
|
449
|
+
message: `Failed to create module for type: ${type}`,
|
|
450
|
+
context: { error },
|
|
451
|
+
}
|
|
452
|
+
console.error(`š„ ${genError.message}:`, error)
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Array of type names to generate modules for
|
|
458
|
+
*/
|
|
459
|
+
const Modules = [
|
|
460
|
+
"apps",
|
|
461
|
+
"fellowships",
|
|
462
|
+
"projects",
|
|
463
|
+
"events",
|
|
464
|
+
"news",
|
|
465
|
+
"people",
|
|
466
|
+
"publications",
|
|
467
|
+
"affiliation",
|
|
468
|
+
"disciplines",
|
|
469
|
+
"mailing",
|
|
470
|
+
"files",
|
|
471
|
+
"tags",
|
|
472
|
+
"users",
|
|
473
|
+
"action",
|
|
474
|
+
// "taxonomy", //TODO: Ć definir
|
|
475
|
+
]
|
|
476
|
+
|
|
477
|
+
console.log("š Starting module generation...")
|
|
478
|
+
console.log(`š Generating ${Modules.length} modules: ${Modules.join(", ")}`)
|
|
479
|
+
|
|
480
|
+
const startTime = Date.now()
|
|
481
|
+
let successCount = 0
|
|
482
|
+
let errorCount = 0
|
|
483
|
+
|
|
484
|
+
Modules.forEach((type) => {
|
|
485
|
+
try {
|
|
486
|
+
createModule(type)
|
|
487
|
+
successCount++
|
|
488
|
+
} catch (error) {
|
|
489
|
+
errorCount++
|
|
490
|
+
console.error(`š„ Failed to generate module '${type}':`, error)
|
|
491
|
+
}
|
|
492
|
+
})
|
|
493
|
+
|
|
494
|
+
const endTime = Date.now()
|
|
495
|
+
const duration = endTime - startTime
|
|
496
|
+
|
|
497
|
+
console.log("\nš Generation Summary:")
|
|
498
|
+
console.log(
|
|
499
|
+
`ā
Successfully generated: ${successCount}/${Modules.length} modules`
|
|
500
|
+
)
|
|
501
|
+
if (errorCount > 0) {
|
|
502
|
+
console.log(`ā Failed: ${errorCount} modules`)
|
|
503
|
+
}
|
|
504
|
+
console.log(`ā±ļø Duration: ${duration}ms`)
|
|
505
|
+
console.log("š Module generation complete!")
|