@strapi/typescript-utils 0.0.0-experimental.6340da17068c3bed7fb006e7bcc554c71129e282 → 0.0.0-experimental.63624e21eb5b0713345a0cf2f68f1c40eab427bc

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 (225) hide show
  1. package/dist/compile.d.ts +5 -0
  2. package/dist/compile.d.ts.map +1 -0
  3. package/dist/compile.js +12 -0
  4. package/dist/compile.js.map +1 -0
  5. package/dist/compile.mjs +10 -0
  6. package/dist/compile.mjs.map +1 -0
  7. package/dist/compilers/basic.d.ts +11 -0
  8. package/dist/compilers/basic.d.ts.map +1 -0
  9. package/dist/compilers/basic.js +58 -0
  10. package/dist/compilers/basic.js.map +1 -0
  11. package/dist/compilers/basic.mjs +36 -0
  12. package/dist/compilers/basic.mjs.map +1 -0
  13. package/dist/compilers/index.d.ts +3 -0
  14. package/dist/compilers/index.d.ts.map +1 -0
  15. package/dist/compilers/index.js +8 -0
  16. package/dist/compilers/index.js.map +1 -0
  17. package/dist/compilers/index.mjs +3 -0
  18. package/dist/compilers/index.mjs.map +1 -0
  19. package/dist/generators/common/compare.d.ts +14 -0
  20. package/dist/generators/common/compare.d.ts.map +1 -0
  21. package/dist/generators/common/compare.js +25 -0
  22. package/dist/generators/common/compare.js.map +1 -0
  23. package/dist/generators/common/compare.mjs +22 -0
  24. package/dist/generators/common/compare.mjs.map +1 -0
  25. package/dist/generators/common/imports.d.ts +5 -0
  26. package/dist/generators/common/imports.d.ts.map +1 -0
  27. package/dist/generators/common/imports.js +42 -0
  28. package/dist/generators/common/imports.js.map +1 -0
  29. package/dist/generators/common/imports.mjs +19 -0
  30. package/dist/generators/common/imports.mjs.map +1 -0
  31. package/dist/generators/common/index.d.ts +4 -0
  32. package/dist/generators/common/index.d.ts.map +1 -0
  33. package/dist/generators/common/interface-names.d.ts +16 -0
  34. package/dist/generators/common/interface-names.d.ts.map +1 -0
  35. package/dist/generators/common/interface-names.js +54 -0
  36. package/dist/generators/common/interface-names.js.map +1 -0
  37. package/dist/generators/common/interface-names.mjs +52 -0
  38. package/dist/generators/common/interface-names.mjs.map +1 -0
  39. package/dist/generators/common/models/attributes.d.ts +38 -0
  40. package/dist/generators/common/models/attributes.d.ts.map +1 -0
  41. package/dist/generators/common/models/attributes.js +205 -0
  42. package/dist/generators/common/models/attributes.js.map +1 -0
  43. package/dist/generators/common/models/attributes.mjs +176 -0
  44. package/dist/generators/common/models/attributes.mjs.map +1 -0
  45. package/dist/generators/common/models/index.d.ts +7 -0
  46. package/dist/generators/common/models/index.d.ts.map +1 -0
  47. package/dist/generators/common/models/mappers.d.ts +9 -0
  48. package/dist/generators/common/models/mappers.d.ts.map +1 -0
  49. package/dist/generators/common/models/mappers.js +227 -0
  50. package/dist/generators/common/models/mappers.js.map +1 -0
  51. package/dist/generators/common/models/mappers.mjs +202 -0
  52. package/dist/generators/common/models/mappers.mjs.map +1 -0
  53. package/dist/generators/common/models/schema.d.ts +8 -0
  54. package/dist/generators/common/models/schema.d.ts.map +1 -0
  55. package/dist/generators/common/models/schema.js +78 -0
  56. package/dist/generators/common/models/schema.js.map +1 -0
  57. package/dist/generators/common/models/schema.mjs +56 -0
  58. package/dist/generators/common/models/schema.mjs.map +1 -0
  59. package/dist/generators/common/models/utils.d.ts +57 -0
  60. package/dist/generators/common/models/utils.d.ts.map +1 -0
  61. package/dist/generators/common/models/utils.js +110 -0
  62. package/dist/generators/common/models/utils.js.map +1 -0
  63. package/dist/generators/common/models/utils.mjs +82 -0
  64. package/dist/generators/common/models/utils.mjs.map +1 -0
  65. package/dist/generators/common/sources.d.ts +133 -0
  66. package/dist/generators/common/sources.d.ts.map +1 -0
  67. package/dist/generators/common/sources.js +354 -0
  68. package/dist/generators/common/sources.js.map +1 -0
  69. package/dist/generators/common/sources.mjs +318 -0
  70. package/dist/generators/common/sources.mjs.map +1 -0
  71. package/dist/generators/components/index.d.ts +9 -0
  72. package/dist/generators/components/index.d.ts.map +1 -0
  73. package/dist/generators/components/index.js +84 -0
  74. package/dist/generators/components/index.js.map +1 -0
  75. package/dist/generators/components/index.mjs +62 -0
  76. package/dist/generators/components/index.mjs.map +1 -0
  77. package/dist/generators/constants.d.ts +3 -0
  78. package/dist/generators/constants.d.ts.map +1 -0
  79. package/dist/generators/constants.js +8 -0
  80. package/dist/generators/constants.js.map +1 -0
  81. package/dist/generators/constants.mjs +5 -0
  82. package/dist/generators/constants.mjs.map +1 -0
  83. package/dist/generators/content-types/index.d.ts +9 -0
  84. package/dist/generators/content-types/index.d.ts.map +1 -0
  85. package/dist/generators/content-types/index.js +84 -0
  86. package/dist/generators/content-types/index.js.map +1 -0
  87. package/dist/generators/content-types/index.mjs +62 -0
  88. package/dist/generators/content-types/index.mjs.map +1 -0
  89. package/dist/generators/controllers/index.d.ts +35 -0
  90. package/dist/generators/controllers/index.d.ts.map +1 -0
  91. package/dist/generators/controllers/index.js +88 -0
  92. package/dist/generators/controllers/index.js.map +1 -0
  93. package/dist/generators/controllers/index.mjs +86 -0
  94. package/dist/generators/controllers/index.mjs.map +1 -0
  95. package/dist/generators/index.d.ts +31 -0
  96. package/dist/generators/index.d.ts.map +1 -0
  97. package/dist/generators/index.js +150 -0
  98. package/dist/generators/index.js.map +1 -0
  99. package/dist/generators/index.mjs +142 -0
  100. package/dist/generators/index.mjs.map +1 -0
  101. package/dist/generators/middlewares/index.d.ts +30 -0
  102. package/dist/generators/middlewares/index.d.ts.map +1 -0
  103. package/dist/generators/middlewares/index.js +163 -0
  104. package/dist/generators/middlewares/index.js.map +1 -0
  105. package/dist/generators/middlewares/index.mjs +141 -0
  106. package/dist/generators/middlewares/index.mjs.map +1 -0
  107. package/dist/generators/plugins/index.d.ts +9 -0
  108. package/dist/generators/plugins/index.d.ts.map +1 -0
  109. package/dist/generators/plugins/index.js +225 -0
  110. package/dist/generators/plugins/index.js.map +1 -0
  111. package/dist/generators/plugins/index.mjs +200 -0
  112. package/dist/generators/plugins/index.mjs.map +1 -0
  113. package/dist/generators/policies/index.d.ts +29 -0
  114. package/dist/generators/policies/index.d.ts.map +1 -0
  115. package/dist/generators/policies/index.js +135 -0
  116. package/dist/generators/policies/index.js.map +1 -0
  117. package/dist/generators/policies/index.mjs +113 -0
  118. package/dist/generators/policies/index.mjs.map +1 -0
  119. package/dist/generators/services/index.d.ts +35 -0
  120. package/dist/generators/services/index.d.ts.map +1 -0
  121. package/dist/generators/services/index.js +87 -0
  122. package/dist/generators/services/index.js.map +1 -0
  123. package/dist/generators/services/index.mjs +85 -0
  124. package/dist/generators/services/index.mjs.map +1 -0
  125. package/dist/generators/strict/index.d.ts +13 -0
  126. package/dist/generators/strict/index.d.ts.map +1 -0
  127. package/dist/generators/strict/index.js +24 -0
  128. package/dist/generators/strict/index.js.map +1 -0
  129. package/dist/generators/strict/index.mjs +22 -0
  130. package/dist/generators/strict/index.mjs.map +1 -0
  131. package/dist/generators/utils.d.ts +68 -0
  132. package/dist/generators/utils.d.ts.map +1 -0
  133. package/dist/generators/utils.js +201 -0
  134. package/dist/generators/utils.js.map +1 -0
  135. package/dist/generators/utils.mjs +166 -0
  136. package/dist/generators/utils.mjs.map +1 -0
  137. package/dist/index.d.ts +5 -0
  138. package/dist/index.d.ts.map +1 -0
  139. package/dist/index.js +28 -0
  140. package/dist/index.js.map +1 -0
  141. package/dist/index.mjs +14 -0
  142. package/dist/index.mjs.map +1 -0
  143. package/dist/utils/format-host.d.ts +3 -0
  144. package/dist/utils/format-host.d.ts.map +1 -0
  145. package/dist/utils/format-host.js +33 -0
  146. package/dist/utils/format-host.js.map +1 -0
  147. package/dist/utils/format-host.mjs +11 -0
  148. package/dist/utils/format-host.mjs.map +1 -0
  149. package/dist/utils/get-config-path.d.ts +10 -0
  150. package/dist/utils/get-config-path.d.ts.map +1 -0
  151. package/dist/utils/get-config-path.js +43 -0
  152. package/dist/utils/get-config-path.js.map +1 -0
  153. package/dist/utils/get-config-path.mjs +18 -0
  154. package/dist/utils/get-config-path.mjs.map +1 -0
  155. package/dist/utils/index.d.ts +9 -0
  156. package/dist/utils/index.d.ts.map +1 -0
  157. package/dist/utils/is-using-typescript-sync.d.ts +5 -0
  158. package/dist/utils/is-using-typescript-sync.d.ts.map +1 -0
  159. package/dist/utils/is-using-typescript-sync.js +20 -0
  160. package/dist/utils/is-using-typescript-sync.js.map +1 -0
  161. package/dist/utils/is-using-typescript-sync.mjs +14 -0
  162. package/dist/utils/is-using-typescript-sync.mjs.map +1 -0
  163. package/dist/utils/is-using-typescript.d.ts +5 -0
  164. package/dist/utils/is-using-typescript.d.ts.map +1 -0
  165. package/dist/utils/is-using-typescript.js +20 -0
  166. package/dist/utils/is-using-typescript.js.map +1 -0
  167. package/dist/utils/is-using-typescript.mjs +14 -0
  168. package/dist/utils/is-using-typescript.mjs.map +1 -0
  169. package/dist/utils/report-diagnostics.d.ts +6 -0
  170. package/dist/utils/report-diagnostics.d.ts.map +1 -0
  171. package/dist/utils/report-diagnostics.js +37 -0
  172. package/dist/utils/report-diagnostics.js.map +1 -0
  173. package/dist/utils/report-diagnostics.mjs +15 -0
  174. package/dist/utils/report-diagnostics.mjs.map +1 -0
  175. package/dist/utils/resolve-config-options.d.ts +12 -0
  176. package/dist/utils/resolve-config-options.d.ts.map +1 -0
  177. package/dist/utils/resolve-config-options.js +39 -0
  178. package/dist/utils/resolve-config-options.js.map +1 -0
  179. package/dist/utils/resolve-config-options.mjs +17 -0
  180. package/dist/utils/resolve-config-options.mjs.map +1 -0
  181. package/dist/utils/resolve-outdir-sync.d.ts +5 -0
  182. package/dist/utils/resolve-outdir-sync.d.ts.map +1 -0
  183. package/dist/utils/resolve-outdir-sync.js +19 -0
  184. package/dist/utils/resolve-outdir-sync.js.map +1 -0
  185. package/dist/utils/resolve-outdir-sync.mjs +13 -0
  186. package/dist/utils/resolve-outdir-sync.mjs.map +1 -0
  187. package/dist/utils/resolve-outdir.d.ts +5 -0
  188. package/dist/utils/resolve-outdir.d.ts.map +1 -0
  189. package/dist/utils/resolve-outdir.js +19 -0
  190. package/dist/utils/resolve-outdir.js.map +1 -0
  191. package/dist/utils/resolve-outdir.mjs +13 -0
  192. package/dist/utils/resolve-outdir.mjs.map +1 -0
  193. package/package.json +27 -12
  194. package/.eslintrc.cjs +0 -16
  195. package/index.d.ts +0 -5
  196. package/jest.config.js +0 -6
  197. package/lib/__tests__/generators/schemas/attributes.test.js +0 -903
  198. package/lib/__tests__/generators/schemas/imports.test.js +0 -56
  199. package/lib/__tests__/generators/schemas/utils.test.js +0 -314
  200. package/lib/compile.js +0 -10
  201. package/lib/compilers/basic.js +0 -50
  202. package/lib/compilers/index.js +0 -7
  203. package/lib/generators/common/imports.js +0 -34
  204. package/lib/generators/common/index.js +0 -9
  205. package/lib/generators/common/models/attributes.js +0 -198
  206. package/lib/generators/common/models/index.js +0 -15
  207. package/lib/generators/common/models/mappers.js +0 -144
  208. package/lib/generators/common/models/schema.js +0 -93
  209. package/lib/generators/common/models/utils.js +0 -178
  210. package/lib/generators/components/index.js +0 -74
  211. package/lib/generators/constants.js +0 -6
  212. package/lib/generators/content-types/index.js +0 -74
  213. package/lib/generators/index.js +0 -122
  214. package/lib/generators/utils.js +0 -216
  215. package/lib/index.js +0 -13
  216. package/lib/utils/format-host.js +0 -15
  217. package/lib/utils/get-config-path.js +0 -29
  218. package/lib/utils/index.js +0 -21
  219. package/lib/utils/is-using-typescript-sync.js +0 -19
  220. package/lib/utils/is-using-typescript.js +0 -17
  221. package/lib/utils/report-diagnostics.js +0 -19
  222. package/lib/utils/resolve-config-options.js +0 -23
  223. package/lib/utils/resolve-outdir-sync.js +0 -18
  224. package/lib/utils/resolve-outdir.js +0 -18
  225. package/lint-staged.config.mjs +0 -1
@@ -0,0 +1,205 @@
1
+ 'use strict';
2
+
3
+ var ts = require('typescript');
4
+ var _ = require('lodash');
5
+ var imports = require('../imports.js');
6
+ var utils = require('./utils.js');
7
+ var mappers = require('./mappers.js');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ function _interopNamespace(e) {
12
+ if (e && e.__esModule) return e;
13
+ var n = Object.create(null);
14
+ if (e) {
15
+ Object.keys(e).forEach(function (k) {
16
+ if (k !== 'default') {
17
+ var d = Object.getOwnPropertyDescriptor(e, k);
18
+ Object.defineProperty(n, k, d.get ? d : {
19
+ enumerable: true,
20
+ get: function () { return e[k]; }
21
+ });
22
+ }
23
+ });
24
+ }
25
+ n.default = e;
26
+ return Object.freeze(n);
27
+ }
28
+
29
+ var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
30
+ var ___default = /*#__PURE__*/_interopDefault(_);
31
+
32
+ const { factory } = ts__namespace;
33
+ /**
34
+ * Create the base type node for a given attribute
35
+ */ const getAttributeType = (attributeName, attribute, uid)=>{
36
+ if (!Object.keys(mappers.mappers).includes(attribute.type)) {
37
+ console.warn(`"${attributeName}" attribute from "${uid}" has an invalid type: "${attribute.type}"`);
38
+ return null;
39
+ }
40
+ const [attributeType, typeParams] = mappers.mappers[attribute.type]({
41
+ uid,
42
+ attribute,
43
+ attributeName
44
+ });
45
+ // Make sure the schema namespace is imported
46
+ imports.addImport(utils.NAMESPACES.Schema);
47
+ return utils.getTypeNode(attributeType, typeParams);
48
+ };
49
+ /**
50
+ * Collect every modifier node from an attribute
51
+ */ const getAttributeModifiers = (attribute, { strict = false } = {})=>{
52
+ const modifiers = [];
53
+ // Required
54
+ if (attribute.required) {
55
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(utils.withAttributeNamespace('Required'))));
56
+ }
57
+ // Private
58
+ if (attribute.private) {
59
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(utils.withAttributeNamespace('Private'))));
60
+ }
61
+ // Unique
62
+ if (attribute.unique) {
63
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(utils.withAttributeNamespace('Unique'))));
64
+ }
65
+ // Configurable
66
+ if (attribute.configurable) {
67
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(utils.withAttributeNamespace('Configurable'))));
68
+ }
69
+ // Custom field
70
+ if (attribute.customField) {
71
+ const customFieldUid = factory.createStringLiteral(attribute.customField);
72
+ const typeArguments = [
73
+ customFieldUid
74
+ ];
75
+ if (attribute.options) {
76
+ typeArguments.push(utils.toTypeLiteral(attribute.options));
77
+ }
78
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(utils.withAttributeNamespace('CustomField')), typeArguments));
79
+ }
80
+ // Plugin Options
81
+ if (!___default.default.isEmpty(attribute.pluginOptions)) {
82
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(utils.withAttributeNamespace('SetPluginOptions')), // Transform the pluginOptions object into an object literal expression
83
+ [
84
+ utils.toTypeLiteral(attribute.pluginOptions)
85
+ ]));
86
+ }
87
+ // Min / Max
88
+ if (attribute.min != null || attribute.max != null) {
89
+ const minMaxProperties = ___default.default.pick(attribute, [
90
+ 'min',
91
+ 'max'
92
+ ]);
93
+ const { min, max } = minMaxProperties;
94
+ const typeofMin = typeof min;
95
+ const typeofMax = typeof max;
96
+ // Throws error if min/max exist but have different types to prevent unexpected behavior
97
+ if (min !== undefined && max !== undefined && typeofMin !== typeofMax) {
98
+ throw new Error('typeof min/max values mismatch');
99
+ }
100
+ let typeKeyword;
101
+ // use 'string'
102
+ if (typeofMin === 'string' || typeofMax === 'string') {
103
+ typeKeyword = ts__namespace.SyntaxKind.StringKeyword;
104
+ } else if (typeofMin === 'number' || typeofMax === 'number') {
105
+ typeKeyword = ts__namespace.SyntaxKind.NumberKeyword;
106
+ } else {
107
+ throw new Error(`Invalid data type for min/max options. Must be string, number or undefined, but found { min: ${min} (${typeofMin}), max: ${max} (${typeofMax}) }`);
108
+ }
109
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(utils.withAttributeNamespace('SetMinMax')), [
110
+ utils.toTypeLiteral(minMaxProperties),
111
+ factory.createKeywordTypeNode(typeKeyword)
112
+ ]));
113
+ }
114
+ // Min length / Max length
115
+ if (attribute.minLength != null || attribute.maxLength != null) {
116
+ const minMaxProperties = ___default.default.pick(attribute, [
117
+ 'minLength',
118
+ 'maxLength'
119
+ ]);
120
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(utils.withAttributeNamespace('SetMinMaxLength')), [
121
+ utils.toTypeLiteral(minMaxProperties)
122
+ ]));
123
+ }
124
+ // Conditional (strict types only): a field hidden by its `conditions.visible` rule skips
125
+ // validation, so the strict write inputs make it optional and nullable
126
+ if (strict === true && attribute.conditions?.visible !== undefined) {
127
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(utils.withAttributeNamespace('Conditional'))));
128
+ }
129
+ // Default (ignore if default is a function)
130
+ if (attribute.default != null && typeof attribute.default !== 'function') {
131
+ const defaultLiteral = utils.toTypeLiteral(attribute.default);
132
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(utils.withAttributeNamespace('DefaultTo')), [
133
+ defaultLiteral
134
+ ]));
135
+ }
136
+ return modifiers;
137
+ };
138
+ /**
139
+ * Whether the attribute is a list of components: a repeatable component or a dynamic zone.
140
+ */ const isComponentList = (attribute)=>attribute.type === 'dynamiczone' || attribute.type === 'component' && attribute.repeatable === true;
141
+ /**
142
+ * The write rule of an attribute, as one sentence for its JSDoc, or `undefined` when the attribute
143
+ * has none to tell. It mirrors the strict write inputs of `@strapi/types`
144
+ * (`modules/documents/params/write.ts`), which follow the entity validator of `@strapi/core`.
145
+ *
146
+ * `draftAndPublish` is `undefined` for a component: its fields follow the mode of the parent entry.
147
+ */ const getAttributeWriteRule = (attribute, { draftAndPublish } = {})=>{
148
+ // The validator skips attributes that are not writable
149
+ if (attribute.writable === false) {
150
+ return undefined;
151
+ }
152
+ const hasDefault = attribute.default !== undefined && attribute.default !== null && typeof attribute.default !== 'function';
153
+ // `*/` in a default value would end the comment
154
+ const defaultRule = hasDefault === true ? `Default: ${JSON.stringify(attribute.default).replaceAll('*/', '*\\/')}.` : '';
155
+ if (attribute.required !== true) {
156
+ if (isComponentList(attribute) === true) {
157
+ return 'Never `null`.';
158
+ }
159
+ return hasDefault === true ? defaultRule : undefined;
160
+ }
161
+ if (attribute.conditions?.visible !== undefined) {
162
+ return 'Required only when its condition shows it.';
163
+ }
164
+ if (isComponentList(attribute) === true) {
165
+ return 'Required on every create, drafts included (`[]` is enough). Never `null`.';
166
+ }
167
+ if (attribute.type === 'relation' || attribute.type === 'media') {
168
+ return 'Required when published, only with `api.documents.strictRelations`.';
169
+ }
170
+ if (draftAndPublish === false) {
171
+ return hasDefault === true ? `${defaultRule} Never \`null\`.` : 'Required. Never `null`.';
172
+ }
173
+ return hasDefault === true ? `${defaultRule} \`null\` only in drafts.` : 'Required when published. `null` only in drafts.';
174
+ };
175
+ /**
176
+ * Generate a property signature node for a given attribute
177
+ */ const attributeToPropertySignature = (schema, attributeName, attribute, options = {})=>{
178
+ const baseType = getAttributeType(attributeName, attribute, schema.uid);
179
+ if (baseType === null) {
180
+ return null;
181
+ }
182
+ const modifiers = getAttributeModifiers(attribute, options);
183
+ const nodes = [
184
+ baseType,
185
+ ...modifiers
186
+ ];
187
+ const signature = factory.createPropertySignature(undefined, factory.createIdentifier(attributeName), undefined, factory.createIntersectionTypeNode(nodes));
188
+ // Strict types only: editors show the write rule on the attribute and on the input keys
189
+ if (options.strict === true) {
190
+ const rule = getAttributeWriteRule(attribute, {
191
+ draftAndPublish: schema.modelType === 'contentType' ? schema.options?.draftAndPublish === true : undefined
192
+ });
193
+ if (rule !== undefined) {
194
+ ts__namespace.addSyntheticLeadingComment(signature, ts__namespace.SyntaxKind.MultiLineCommentTrivia, `* ${rule} `, true);
195
+ }
196
+ }
197
+ return signature;
198
+ };
199
+
200
+ exports.mappers = mappers.mappers;
201
+ exports.attributeToPropertySignature = attributeToPropertySignature;
202
+ exports.getAttributeModifiers = getAttributeModifiers;
203
+ exports.getAttributeType = getAttributeType;
204
+ exports.getAttributeWriteRule = getAttributeWriteRule;
205
+ //# sourceMappingURL=attributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.js","sources":["../../../../src/generators/common/models/attributes.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport _ from 'lodash';\n\nimport { addImport } from '../imports';\nimport { getTypeNode, toTypeLiteral, withAttributeNamespace, NAMESPACES } from './utils';\nimport type { Attribute, Schema } from './utils';\nimport { mappers } from './mappers';\n\nconst { factory } = ts;\n\n/**\n * Create the base type node for a given attribute\n */\nexport const getAttributeType = (\n attributeName: string,\n attribute: Attribute,\n uid?: string\n): ts.TypeReferenceNode | null => {\n if (!Object.keys(mappers).includes(attribute.type)) {\n console.warn(\n `\"${attributeName}\" attribute from \"${uid}\" has an invalid type: \"${attribute.type}\"`\n );\n\n return null;\n }\n\n const [attributeType, typeParams] = mappers[attribute.type]({ uid, attribute, attributeName });\n\n // Make sure the schema namespace is imported\n addImport(NAMESPACES.Schema);\n\n return getTypeNode(attributeType, typeParams);\n};\n\n/**\n * Options of the attribute generators.\n */\nexport type AttributeOptions = {\n /**\n * Whether the application enables `typescript.strictTypes`. Strict-only modifiers, such as\n * `Schema.Attribute.Conditional`, are emitted only then, so generated files without strict types\n * stay as in previous releases.\n */\n strict?: boolean;\n};\n\n/**\n * Collect every modifier node from an attribute\n */\nexport const getAttributeModifiers = (\n attribute: Attribute,\n { strict = false }: AttributeOptions = {}\n): ts.TypeNode[] => {\n const modifiers: ts.TypeNode[] = [];\n\n // Required\n if (attribute.required) {\n modifiers.push(\n factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('Required')))\n );\n }\n\n // Private\n if (attribute.private) {\n modifiers.push(\n factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('Private')))\n );\n }\n\n // Unique\n if (attribute.unique) {\n modifiers.push(\n factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('Unique')))\n );\n }\n\n // Configurable\n if (attribute.configurable) {\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('Configurable'))\n )\n );\n }\n\n // Custom field\n if (attribute.customField) {\n const customFieldUid = factory.createStringLiteral(attribute.customField);\n const typeArguments: any[] = [customFieldUid];\n\n if (attribute.options) {\n typeArguments.push(toTypeLiteral(attribute.options));\n }\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('CustomField')),\n typeArguments\n )\n );\n }\n\n // Plugin Options\n if (!_.isEmpty(attribute.pluginOptions)) {\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('SetPluginOptions')),\n // Transform the pluginOptions object into an object literal expression\n [toTypeLiteral(attribute.pluginOptions)]\n )\n );\n }\n\n // Min / Max\n if (attribute.min != null || attribute.max != null) {\n const minMaxProperties = _.pick(attribute, ['min', 'max']);\n const { min, max } = minMaxProperties;\n\n const typeofMin = typeof min;\n const typeofMax = typeof max;\n\n // Throws error if min/max exist but have different types to prevent unexpected behavior\n if (min !== undefined && max !== undefined && typeofMin !== typeofMax) {\n throw new Error('typeof min/max values mismatch');\n }\n\n let typeKeyword: any;\n\n // use 'string'\n if (typeofMin === 'string' || typeofMax === 'string') {\n typeKeyword = ts.SyntaxKind.StringKeyword;\n }\n // use 'number'\n else if (typeofMin === 'number' || typeofMax === 'number') {\n typeKeyword = ts.SyntaxKind.NumberKeyword;\n }\n // invalid type\n else {\n throw new Error(\n `Invalid data type for min/max options. Must be string, number or undefined, but found { min: ${min} (${typeofMin}), max: ${max} (${typeofMax}) }`\n );\n }\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('SetMinMax')),\n [toTypeLiteral(minMaxProperties), factory.createKeywordTypeNode(typeKeyword)]\n )\n );\n }\n\n // Min length / Max length\n if (attribute.minLength != null || attribute.maxLength != null) {\n const minMaxProperties = _.pick(attribute, ['minLength', 'maxLength']);\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('SetMinMaxLength')),\n [toTypeLiteral(minMaxProperties)]\n )\n );\n }\n\n // Conditional (strict types only): a field hidden by its `conditions.visible` rule skips\n // validation, so the strict write inputs make it optional and nullable\n if (strict === true && attribute.conditions?.visible !== undefined) {\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('Conditional'))\n )\n );\n }\n\n // Default (ignore if default is a function)\n if (attribute.default != null && typeof attribute.default !== 'function') {\n const defaultLiteral = toTypeLiteral(attribute.default);\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('DefaultTo')),\n [defaultLiteral]\n )\n );\n }\n\n return modifiers;\n};\n\n/**\n * Whether the attribute is a list of components: a repeatable component or a dynamic zone.\n */\nconst isComponentList = (attribute: Attribute) =>\n attribute.type === 'dynamiczone' ||\n (attribute.type === 'component' && attribute.repeatable === true);\n\n/**\n * The write rule of an attribute, as one sentence for its JSDoc, or `undefined` when the attribute\n * has none to tell. It mirrors the strict write inputs of `@strapi/types`\n * (`modules/documents/params/write.ts`), which follow the entity validator of `@strapi/core`.\n *\n * `draftAndPublish` is `undefined` for a component: its fields follow the mode of the parent entry.\n */\nexport const getAttributeWriteRule = (\n attribute: Attribute,\n { draftAndPublish }: { draftAndPublish?: boolean } = {}\n): string | undefined => {\n // The validator skips attributes that are not writable\n if (attribute.writable === false) {\n return undefined;\n }\n\n const hasDefault =\n attribute.default !== undefined &&\n attribute.default !== null &&\n typeof attribute.default !== 'function';\n // `*/` in a default value would end the comment\n const defaultRule =\n hasDefault === true\n ? `Default: ${JSON.stringify(attribute.default).replaceAll('*/', '*\\\\/')}.`\n : '';\n\n if (attribute.required !== true) {\n if (isComponentList(attribute) === true) {\n return 'Never `null`.';\n }\n\n return hasDefault === true ? defaultRule : undefined;\n }\n\n if (attribute.conditions?.visible !== undefined) {\n return 'Required only when its condition shows it.';\n }\n\n if (isComponentList(attribute) === true) {\n return 'Required on every create, drafts included (`[]` is enough). Never `null`.';\n }\n\n if (attribute.type === 'relation' || attribute.type === 'media') {\n return 'Required when published, only with `api.documents.strictRelations`.';\n }\n\n if (draftAndPublish === false) {\n return hasDefault === true ? `${defaultRule} Never \\`null\\`.` : 'Required. Never `null`.';\n }\n\n return hasDefault === true\n ? `${defaultRule} \\`null\\` only in drafts.`\n : 'Required when published. `null` only in drafts.';\n};\n\n/**\n * Generate a property signature node for a given attribute\n */\nexport const attributeToPropertySignature = (\n schema: Schema,\n attributeName: string,\n attribute: Attribute,\n options: AttributeOptions = {}\n): ts.PropertySignature | null => {\n const baseType = getAttributeType(attributeName, attribute, schema.uid);\n\n if (baseType === null) {\n return null;\n }\n\n const modifiers = getAttributeModifiers(attribute, options);\n\n const nodes = [baseType, ...modifiers];\n\n const signature = factory.createPropertySignature(\n undefined,\n factory.createIdentifier(attributeName),\n undefined,\n factory.createIntersectionTypeNode(nodes)\n );\n\n // Strict types only: editors show the write rule on the attribute and on the input keys\n if (options.strict === true) {\n const rule = getAttributeWriteRule(attribute, {\n draftAndPublish:\n schema.modelType === 'contentType' ? schema.options?.draftAndPublish === true : undefined,\n });\n\n if (rule !== undefined) {\n ts.addSyntheticLeadingComment(\n signature,\n ts.SyntaxKind.MultiLineCommentTrivia,\n `* ${rule} `,\n true\n );\n }\n }\n\n return signature;\n};\n\nexport { mappers };\n"],"names":["factory","ts","getAttributeType","attributeName","attribute","uid","Object","keys","mappers","includes","type","console","warn","attributeType","typeParams","addImport","NAMESPACES","Schema","getTypeNode","getAttributeModifiers","strict","modifiers","required","push","createTypeReferenceNode","createIdentifier","withAttributeNamespace","private","unique","configurable","customField","customFieldUid","createStringLiteral","typeArguments","options","toTypeLiteral","_","isEmpty","pluginOptions","min","max","minMaxProperties","pick","typeofMin","typeofMax","undefined","Error","typeKeyword","SyntaxKind","StringKeyword","NumberKeyword","createKeywordTypeNode","minLength","maxLength","conditions","visible","default","defaultLiteral","isComponentList","repeatable","getAttributeWriteRule","draftAndPublish","writable","hasDefault","defaultRule","JSON","stringify","replaceAll","attributeToPropertySignature","schema","baseType","nodes","signature","createPropertySignature","createIntersectionTypeNode","rule","modelType","addSyntheticLeadingComment","MultiLineCommentTriv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A,CAAA;AAEJ,QAAA;AACF,IAAA;IAEA,OAAOH,SAAAA;AACT;;;;;;;;"}
@@ -0,0 +1,176 @@
1
+ import * as ts from 'typescript';
2
+ import _ from 'lodash';
3
+ import { addImport } from '../imports.mjs';
4
+ import { getTypeNode, withAttributeNamespace, toTypeLiteral, NAMESPACES } from './utils.mjs';
5
+ import { mappers } from './mappers.mjs';
6
+
7
+ const { factory } = ts;
8
+ /**
9
+ * Create the base type node for a given attribute
10
+ */ const getAttributeType = (attributeName, attribute, uid)=>{
11
+ if (!Object.keys(mappers).includes(attribute.type)) {
12
+ console.warn(`"${attributeName}" attribute from "${uid}" has an invalid type: "${attribute.type}"`);
13
+ return null;
14
+ }
15
+ const [attributeType, typeParams] = mappers[attribute.type]({
16
+ uid,
17
+ attribute,
18
+ attributeName
19
+ });
20
+ // Make sure the schema namespace is imported
21
+ addImport(NAMESPACES.Schema);
22
+ return getTypeNode(attributeType, typeParams);
23
+ };
24
+ /**
25
+ * Collect every modifier node from an attribute
26
+ */ const getAttributeModifiers = (attribute, { strict = false } = {})=>{
27
+ const modifiers = [];
28
+ // Required
29
+ if (attribute.required) {
30
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('Required'))));
31
+ }
32
+ // Private
33
+ if (attribute.private) {
34
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('Private'))));
35
+ }
36
+ // Unique
37
+ if (attribute.unique) {
38
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('Unique'))));
39
+ }
40
+ // Configurable
41
+ if (attribute.configurable) {
42
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('Configurable'))));
43
+ }
44
+ // Custom field
45
+ if (attribute.customField) {
46
+ const customFieldUid = factory.createStringLiteral(attribute.customField);
47
+ const typeArguments = [
48
+ customFieldUid
49
+ ];
50
+ if (attribute.options) {
51
+ typeArguments.push(toTypeLiteral(attribute.options));
52
+ }
53
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('CustomField')), typeArguments));
54
+ }
55
+ // Plugin Options
56
+ if (!_.isEmpty(attribute.pluginOptions)) {
57
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('SetPluginOptions')), // Transform the pluginOptions object into an object literal expression
58
+ [
59
+ toTypeLiteral(attribute.pluginOptions)
60
+ ]));
61
+ }
62
+ // Min / Max
63
+ if (attribute.min != null || attribute.max != null) {
64
+ const minMaxProperties = _.pick(attribute, [
65
+ 'min',
66
+ 'max'
67
+ ]);
68
+ const { min, max } = minMaxProperties;
69
+ const typeofMin = typeof min;
70
+ const typeofMax = typeof max;
71
+ // Throws error if min/max exist but have different types to prevent unexpected behavior
72
+ if (min !== undefined && max !== undefined && typeofMin !== typeofMax) {
73
+ throw new Error('typeof min/max values mismatch');
74
+ }
75
+ let typeKeyword;
76
+ // use 'string'
77
+ if (typeofMin === 'string' || typeofMax === 'string') {
78
+ typeKeyword = ts.SyntaxKind.StringKeyword;
79
+ } else if (typeofMin === 'number' || typeofMax === 'number') {
80
+ typeKeyword = ts.SyntaxKind.NumberKeyword;
81
+ } else {
82
+ throw new Error(`Invalid data type for min/max options. Must be string, number or undefined, but found { min: ${min} (${typeofMin}), max: ${max} (${typeofMax}) }`);
83
+ }
84
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('SetMinMax')), [
85
+ toTypeLiteral(minMaxProperties),
86
+ factory.createKeywordTypeNode(typeKeyword)
87
+ ]));
88
+ }
89
+ // Min length / Max length
90
+ if (attribute.minLength != null || attribute.maxLength != null) {
91
+ const minMaxProperties = _.pick(attribute, [
92
+ 'minLength',
93
+ 'maxLength'
94
+ ]);
95
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('SetMinMaxLength')), [
96
+ toTypeLiteral(minMaxProperties)
97
+ ]));
98
+ }
99
+ // Conditional (strict types only): a field hidden by its `conditions.visible` rule skips
100
+ // validation, so the strict write inputs make it optional and nullable
101
+ if (strict === true && attribute.conditions?.visible !== undefined) {
102
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('Conditional'))));
103
+ }
104
+ // Default (ignore if default is a function)
105
+ if (attribute.default != null && typeof attribute.default !== 'function') {
106
+ const defaultLiteral = toTypeLiteral(attribute.default);
107
+ modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('DefaultTo')), [
108
+ defaultLiteral
109
+ ]));
110
+ }
111
+ return modifiers;
112
+ };
113
+ /**
114
+ * Whether the attribute is a list of components: a repeatable component or a dynamic zone.
115
+ */ const isComponentList = (attribute)=>attribute.type === 'dynamiczone' || attribute.type === 'component' && attribute.repeatable === true;
116
+ /**
117
+ * The write rule of an attribute, as one sentence for its JSDoc, or `undefined` when the attribute
118
+ * has none to tell. It mirrors the strict write inputs of `@strapi/types`
119
+ * (`modules/documents/params/write.ts`), which follow the entity validator of `@strapi/core`.
120
+ *
121
+ * `draftAndPublish` is `undefined` for a component: its fields follow the mode of the parent entry.
122
+ */ const getAttributeWriteRule = (attribute, { draftAndPublish } = {})=>{
123
+ // The validator skips attributes that are not writable
124
+ if (attribute.writable === false) {
125
+ return undefined;
126
+ }
127
+ const hasDefault = attribute.default !== undefined && attribute.default !== null && typeof attribute.default !== 'function';
128
+ // `*/` in a default value would end the comment
129
+ const defaultRule = hasDefault === true ? `Default: ${JSON.stringify(attribute.default).replaceAll('*/', '*\\/')}.` : '';
130
+ if (attribute.required !== true) {
131
+ if (isComponentList(attribute) === true) {
132
+ return 'Never `null`.';
133
+ }
134
+ return hasDefault === true ? defaultRule : undefined;
135
+ }
136
+ if (attribute.conditions?.visible !== undefined) {
137
+ return 'Required only when its condition shows it.';
138
+ }
139
+ if (isComponentList(attribute) === true) {
140
+ return 'Required on every create, drafts included (`[]` is enough). Never `null`.';
141
+ }
142
+ if (attribute.type === 'relation' || attribute.type === 'media') {
143
+ return 'Required when published, only with `api.documents.strictRelations`.';
144
+ }
145
+ if (draftAndPublish === false) {
146
+ return hasDefault === true ? `${defaultRule} Never \`null\`.` : 'Required. Never `null`.';
147
+ }
148
+ return hasDefault === true ? `${defaultRule} \`null\` only in drafts.` : 'Required when published. `null` only in drafts.';
149
+ };
150
+ /**
151
+ * Generate a property signature node for a given attribute
152
+ */ const attributeToPropertySignature = (schema, attributeName, attribute, options = {})=>{
153
+ const baseType = getAttributeType(attributeName, attribute, schema.uid);
154
+ if (baseType === null) {
155
+ return null;
156
+ }
157
+ const modifiers = getAttributeModifiers(attribute, options);
158
+ const nodes = [
159
+ baseType,
160
+ ...modifiers
161
+ ];
162
+ const signature = factory.createPropertySignature(undefined, factory.createIdentifier(attributeName), undefined, factory.createIntersectionTypeNode(nodes));
163
+ // Strict types only: editors show the write rule on the attribute and on the input keys
164
+ if (options.strict === true) {
165
+ const rule = getAttributeWriteRule(attribute, {
166
+ draftAndPublish: schema.modelType === 'contentType' ? schema.options?.draftAndPublish === true : undefined
167
+ });
168
+ if (rule !== undefined) {
169
+ ts.addSyntheticLeadingComment(signature, ts.SyntaxKind.MultiLineCommentTrivia, `* ${rule} `, true);
170
+ }
171
+ }
172
+ return signature;
173
+ };
174
+
175
+ export { attributeToPropertySignature, getAttributeModifiers, getAttributeType, getAttributeWriteRule, mappers };
176
+ //# sourceMappingURL=attributes.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.mjs","sources":["../../../../src/generators/common/models/attributes.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport _ from 'lodash';\n\nimport { addImport } from '../imports';\nimport { getTypeNode, toTypeLiteral, withAttributeNamespace, NAMESPACES } from './utils';\nimport type { Attribute, Schema } from './utils';\nimport { mappers } from './mappers';\n\nconst { factory } = ts;\n\n/**\n * Create the base type node for a given attribute\n */\nexport const getAttributeType = (\n attributeName: string,\n attribute: Attribute,\n uid?: string\n): ts.TypeReferenceNode | null => {\n if (!Object.keys(mappers).includes(attribute.type)) {\n console.warn(\n `\"${attributeName}\" attribute from \"${uid}\" has an invalid type: \"${attribute.type}\"`\n );\n\n return null;\n }\n\n const [attributeType, typeParams] = mappers[attribute.type]({ uid, attribute, attributeName });\n\n // Make sure the schema namespace is imported\n addImport(NAMESPACES.Schema);\n\n return getTypeNode(attributeType, typeParams);\n};\n\n/**\n * Options of the attribute generators.\n */\nexport type AttributeOptions = {\n /**\n * Whether the application enables `typescript.strictTypes`. Strict-only modifiers, such as\n * `Schema.Attribute.Conditional`, are emitted only then, so generated files without strict types\n * stay as in previous releases.\n */\n strict?: boolean;\n};\n\n/**\n * Collect every modifier node from an attribute\n */\nexport const getAttributeModifiers = (\n attribute: Attribute,\n { strict = false }: AttributeOptions = {}\n): ts.TypeNode[] => {\n const modifiers: ts.TypeNode[] = [];\n\n // Required\n if (attribute.required) {\n modifiers.push(\n factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('Required')))\n );\n }\n\n // Private\n if (attribute.private) {\n modifiers.push(\n factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('Private')))\n );\n }\n\n // Unique\n if (attribute.unique) {\n modifiers.push(\n factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('Unique')))\n );\n }\n\n // Configurable\n if (attribute.configurable) {\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('Configurable'))\n )\n );\n }\n\n // Custom field\n if (attribute.customField) {\n const customFieldUid = factory.createStringLiteral(attribute.customField);\n const typeArguments: any[] = [customFieldUid];\n\n if (attribute.options) {\n typeArguments.push(toTypeLiteral(attribute.options));\n }\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('CustomField')),\n typeArguments\n )\n );\n }\n\n // Plugin Options\n if (!_.isEmpty(attribute.pluginOptions)) {\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('SetPluginOptions')),\n // Transform the pluginOptions object into an object literal expression\n [toTypeLiteral(attribute.pluginOptions)]\n )\n );\n }\n\n // Min / Max\n if (attribute.min != null || attribute.max != null) {\n const minMaxProperties = _.pick(attribute, ['min', 'max']);\n const { min, max } = minMaxProperties;\n\n const typeofMin = typeof min;\n const typeofMax = typeof max;\n\n // Throws error if min/max exist but have different types to prevent unexpected behavior\n if (min !== undefined && max !== undefined && typeofMin !== typeofMax) {\n throw new Error('typeof min/max values mismatch');\n }\n\n let typeKeyword: any;\n\n // use 'string'\n if (typeofMin === 'string' || typeofMax === 'string') {\n typeKeyword = ts.SyntaxKind.StringKeyword;\n }\n // use 'number'\n else if (typeofMin === 'number' || typeofMax === 'number') {\n typeKeyword = ts.SyntaxKind.NumberKeyword;\n }\n // invalid type\n else {\n throw new Error(\n `Invalid data type for min/max options. Must be string, number or undefined, but found { min: ${min} (${typeofMin}), max: ${max} (${typeofMax}) }`\n );\n }\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('SetMinMax')),\n [toTypeLiteral(minMaxProperties), factory.createKeywordTypeNode(typeKeyword)]\n )\n );\n }\n\n // Min length / Max length\n if (attribute.minLength != null || attribute.maxLength != null) {\n const minMaxProperties = _.pick(attribute, ['minLength', 'maxLength']);\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('SetMinMaxLength')),\n [toTypeLiteral(minMaxProperties)]\n )\n );\n }\n\n // Conditional (strict types only): a field hidden by its `conditions.visible` rule skips\n // validation, so the strict write inputs make it optional and nullable\n if (strict === true && attribute.conditions?.visible !== undefined) {\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('Conditional'))\n )\n );\n }\n\n // Default (ignore if default is a function)\n if (attribute.default != null && typeof attribute.default !== 'function') {\n const defaultLiteral = toTypeLiteral(attribute.default);\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('DefaultTo')),\n [defaultLiteral]\n )\n );\n }\n\n return modifiers;\n};\n\n/**\n * Whether the attribute is a list of components: a repeatable component or a dynamic zone.\n */\nconst isComponentList = (attribute: Attribute) =>\n attribute.type === 'dynamiczone' ||\n (attribute.type === 'component' && attribute.repeatable === true);\n\n/**\n * The write rule of an attribute, as one sentence for its JSDoc, or `undefined` when the attribute\n * has none to tell. It mirrors the strict write inputs of `@strapi/types`\n * (`modules/documents/params/write.ts`), which follow the entity validator of `@strapi/core`.\n *\n * `draftAndPublish` is `undefined` for a component: its fields follow the mode of the parent entry.\n */\nexport const getAttributeWriteRule = (\n attribute: Attribute,\n { draftAndPublish }: { draftAndPublish?: boolean } = {}\n): string | undefined => {\n // The validator skips attributes that are not writable\n if (attribute.writable === false) {\n return undefined;\n }\n\n const hasDefault =\n attribute.default !== undefined &&\n attribute.default !== null &&\n typeof attribute.default !== 'function';\n // `*/` in a default value would end the comment\n const defaultRule =\n hasDefault === true\n ? `Default: ${JSON.stringify(attribute.default).replaceAll('*/', '*\\\\/')}.`\n : '';\n\n if (attribute.required !== true) {\n if (isComponentList(attribute) === true) {\n return 'Never `null`.';\n }\n\n return hasDefault === true ? defaultRule : undefined;\n }\n\n if (attribute.conditions?.visible !== undefined) {\n return 'Required only when its condition shows it.';\n }\n\n if (isComponentList(attribute) === true) {\n return 'Required on every create, drafts included (`[]` is enough). Never `null`.';\n }\n\n if (attribute.type === 'relation' || attribute.type === 'media') {\n return 'Required when published, only with `api.documents.strictRelations`.';\n }\n\n if (draftAndPublish === false) {\n return hasDefault === true ? `${defaultRule} Never \\`null\\`.` : 'Required. Never `null`.';\n }\n\n return hasDefault === true\n ? `${defaultRule} \\`null\\` only in drafts.`\n : 'Required when published. `null` only in drafts.';\n};\n\n/**\n * Generate a property signature node for a given attribute\n */\nexport const attributeToPropertySignature = (\n schema: Schema,\n attributeName: string,\n attribute: Attribute,\n options: AttributeOptions = {}\n): ts.PropertySignature | null => {\n const baseType = getAttributeType(attributeName, attribute, schema.uid);\n\n if (baseType === null) {\n return null;\n }\n\n const modifiers = getAttributeModifiers(attribute, options);\n\n const nodes = [baseType, ...modifiers];\n\n const signature = factory.createPropertySignature(\n undefined,\n factory.createIdentifier(attributeName),\n undefined,\n factory.createIntersectionTypeNode(nodes)\n );\n\n // Strict types only: editors show the write rule on the attribute and on the input keys\n if (options.strict === true) {\n const rule = getAttributeWriteRule(attribute, {\n draftAndPublish:\n schema.modelType === 'contentType' ? schema.options?.draftAndPublish === true : undefined,\n });\n\n if (rule !== undefined) {\n ts.addSyntheticLeadingComment(\n signature,\n ts.SyntaxKind.MultiLineCommentTrivia,\n `* ${rule} `,\n true\n );\n }\n }\n\n return signature;\n};\n\nexport { mappers };\n"],"names":["factory","ts","getAttributeType","attributeName","attribute","uid","Object","keys","mappers","includes","type","console","warn","attributeType","typeParams","addImport","NAMESPACES","Schema","getTypeNode","getAttributeModifiers","strict","modifiers","required","push","createTypeReferenceNode","createIdentifier","withAttributeNamespace","private","unique","configurable","customField","customFieldUid","createStringLiteral","typeArguments","options","toTypeLiteral","_","isEmpty","pluginOptions","min","max","minMaxProperties","pick","typeofMin","typeofMax","undefined","Error","typeKeyword","SyntaxKind","StringKeyword","NumberKeyword","createKeywordTypeNode","minLength","maxLength","conditions","visible","default","defaultLiteral","isComponentList","repeatable","getAttributeWriteRule","draftAndPublish","writable","hasDefault","defaultRule","JSON","stringify","replaceAll","attributeToPropertySignature","schema","baseType","nodes","signature","createPropertySignature","createIntersectionTypeNode","rule","modelType","addSyntheticLeadingComment","MultiLineCommentTrivia"],"mappings":";;;;;;AAQA,MAAM,EAAEA,OAAO,EAAE,GAAGC,EAAAA;AAEpB;;AAEC,IACM,MAAMC,gBAAAA,GAAmB,CAC9BC,eACAC,SAAAA,EACAC,GAAAA,GAAAA;IAEA,IAAI,CAACC,OAAOC,IAAI,CAACC,SAASC,QAAQ,CAACL,SAAAA,CAAUM,IAAI,CAAA,EAAG;AAClDC,QAAAA,OAAAA,CAAQC,IAAI,CACV,CAAC,CAAC,EAAET,aAAAA,CAAc,kBAAkB,EAAEE,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A,IAAIiE,aAAa,IAAA,EAAM;QACrB,OAAO,IAAA;AACT,IAAA;IAEA,MAAMjD,SAAAA,GAAYF,sBAAsBf,SAAAA,EAAW8B,OAAAA,CAAAA;AAEnD,IAAA,MAAMqC,KAAAA,GAAQ;AAACD,QAAAA,QAAAA;AAAajD,QAAAA,GAAAA;AAAU,KAAA;AAEtC,IAAA,MAAMmD,SAAAA,GAAYxE,OAAAA,CAAQyE,uBAAuB,CAC/C5B,SAAAA,EACA7C,OAAAA,CAAQyB,gBAAgB,CAACtB,aAAAA,CAAAA,EACzB0C,SAAAA,EACA7C,OAAAA,CAAQ0E,0BAA0B,CAACH,KAAAA,CAAAA,CAAAA;;IAIrC,IAAIrC,OAAAA,CAAQd,MAAM,KAAK,IAAA,EAAM;QAC3B,MAAMuD,IAAAA,GAAOf,sBAAsBxD,SAAAA,EAAW;YAC5CyD,eAAAA,EACEQ,MAAAA,CAAOO,SAAS,KAAK,aAAA,GAAgBP,OAAOnC,OAAO,EAAE2B,oBAAoB,IAAA,GAAOhB;AACpF,SAAA,CAAA;AAEA,QAAA,IAAI8B,SAAS9B,SAAAA,EAAW;AACtB5C,YAAAA,EAAAA,CAAG4E,0BAA0B,CAC3BL,SAAAA,EACAvE,EAAAA,CAAG+C,UAAU,CAAC8B,sBAAsB,EACpC,CAAC,EAAE,EAAEH,IAAAA,CAAK,CAAC,CAAC,EACZ,IAAA,CAAA;AAEJ,QAAA;AACF,IAAA;IAEA,OAAOH,SAAAA;AACT;;;;"}
@@ -0,0 +1,7 @@
1
+ import * as schema from './schema';
2
+ import * as attributes from './attributes';
3
+ import { mappers } from './mappers';
4
+ import * as utils from './utils';
5
+ import * as imports from '../imports';
6
+ export { schema, attributes, mappers, utils, imports };
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/generators/common/models/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { Attribute } from './utils';
2
+ export interface MapperContext {
3
+ uid?: string;
4
+ attribute: Attribute;
5
+ attributeName?: string;
6
+ }
7
+ export type Mapper = (context: MapperContext) => [string] | [string, any[]];
8
+ export declare const mappers: Record<string, Mapper>;
9
+ //# sourceMappingURL=mappers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../../../../src/generators/common/models/mappers.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIzC,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,aAAa,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;AA8J5E,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAuB1C,CAAC"}