-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrapi-settings.ts
184 lines (178 loc) · 5.11 KB
/
strapi-settings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import './strapi.js';
// Models
// const models: { setting: ModelSetting, name: string, path: string }[] = [];
// for await (const entry of globIterate(`${process.argv[0]}/api/*/models/*.settings.json`)) {
// models.push({
// setting: JSON.parse(await fs.readFile(entry, 'utf8')),
// name: entry.split(path.sep).at(-3) ?? '',
// path: entry,
// });
// }
//
// Components
// interface Component { setting: ComponentSetting, group: string, name: string, path: string }
//
// const components: Component[] = [];
//
// for await (const entry of globIterate(`${process.argv[0]}/components/*/*.json`)) {
// const p = path.parse(entry);
// components.push({
// setting: JSON.parse(await fs.readFile(entry, 'utf8')),
// group: path.basename(p.dir),
// name: p.name,
// path: entry,
// });
// }
//
//
export interface AttributesSetting {
readonly [key: string]: ({
readonly type: 'datetime';
} | {
readonly type: 'string';
readonly regex?: string;
} | {
readonly type: 'component';
readonly repeatable: boolean;
readonly component: string;
} | {
readonly type: 'richtext';
} | {
readonly type: 'text';
} | {
readonly type: 'integer';
readonly min: number;
readonly max: number;
} | {
readonly type: 'float';
readonly min: number;
readonly max: number;
} | {
readonly type: 'boolean';
readonly default: boolean;
} | {
readonly type: 'enumeration';
readonly enum: readonly string[];
readonly default?: string;
} | {
readonly type: 'json';
} | {
readonly type: 'email';
} | {
readonly type: 'decimal';
} | {
readonly type: 'password';
} | {
readonly model: string;
readonly via?: string;
readonly allowedTypes?: readonly string[];
readonly plugin?: string;
} | {
readonly collection: string;
readonly via?: string;
readonly allowedTypes?: readonly string[];
readonly plugin?: string;
}) & {
readonly required?: boolean;
readonly pluginOptions?: {
readonly i18n: {
readonly localized: boolean;
};
};
readonly unique?: boolean;
readonly configurable?: boolean;
readonly writable?: boolean;
readonly visible?: boolean;
readonly private?: boolean;
}
}
export interface ModelSetting {
readonly kind: 'collectionType' | 'singleType';
readonly collectionName: string;
readonly info: {
readonly name: string;
readonly description?: string;
readonly mainField?: string;
};
options: {
readonly increments: boolean;
readonly timestamps: string[];
readonly draftAndPublish: boolean;
};
readonly pluginOptions?: {
readonly i18n?: {
readonly localized: boolean;
};
};
readonly plugin?: string;
readonly attributes: AttributesSetting;
readonly uid: string;
readonly apiName: string;
readonly globalId: string;
readonly modelType: string;
readonly modelName: string;
readonly connection: string;
readonly globalName: string;
readonly associations: {
readonly alias: string;
readonly type: 'collection' | 'model';
readonly targetUid: string;
readonly collection?: string;
readonly nature: 'manyWay' | 'oneWay' | 'manyToOne' | 'oneToMany' | 'oneToOne' | 'manyToManyMorph' | 'manyToMany' | 'oneToManyMorph' | 'manyMorphToMany';
readonly autoPopulate: boolean;
readonly dominant?: boolean;
readonly populate?: string[];
readonly tableCollectionName?: string;
readonly model?: string;
readonly plugin?: string;
readonly via?: string;
readonly filter?: string;
readonly related?: ModelSetting[];
}[];
readonly orm: string;
readonly databaseName: string;
readonly client: string;
readonly primaryKey: string;
readonly primaryKeyType: string;
readonly allAttributes: AttributesSetting;
// Below are only in strapi.model but not .setting.json file.
// associations: ({
// type: 'collection' | 'model';
// model?: 'user';
// related?: Array<any>; // Consider replacing `any` with the specific type
// nature: 'manyWay';
// autoPopulate: boolean;
// dominant?: boolean;
// plugin?: 'admin';
// via?: undefined;
// filter?: 'field' | undefined;
// populate?: undefined;
// } | {
// alias: string;
// targetUid: string;
// type: 'collection' | 'model';
// model?: 'user';
// related?: Array<any>; // Consider replacing `any` with the specific type
// nature: 'manyMorphToMany' | 'oneWay';
// autoPopulate: boolean;
// dominant?: boolean;
// plugin?: 'admin';
// via?: undefined;
// filter?: 'field' | undefined;
// populate?: undefined;
// })[];
}
export interface ComponentSetting {
readonly collectionName: string;
readonly info: {
readonly name: string;
readonly icon: string;
readonly description?: string;
};
readonly attributes: AttributesSetting;
}
export let models: { [name: string]: ModelSetting } = (strapi as any).models;
for (const pluginSetting of Object.values((strapi as any).plugins)) {
models = { ...models, ...(pluginSetting as any).models };
}
export const components: { [name: string]: ComponentSetting } = (strapi as any).components;