@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,227 @@
1
+ 'use strict';
2
+
3
+ var ts = require('typescript');
4
+ var _ = require('lodash');
5
+ var utils = require('./utils.js');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
28
+ var ___default = /*#__PURE__*/_interopDefault(_);
29
+
30
+ const { factory } = ts__namespace;
31
+ function string() {
32
+ return [
33
+ utils.withAttributeNamespace('String')
34
+ ];
35
+ }
36
+ function text() {
37
+ return [
38
+ utils.withAttributeNamespace('Text')
39
+ ];
40
+ }
41
+ function richtext() {
42
+ return [
43
+ utils.withAttributeNamespace('RichText')
44
+ ];
45
+ }
46
+ function password() {
47
+ return [
48
+ utils.withAttributeNamespace('Password')
49
+ ];
50
+ }
51
+ function email() {
52
+ return [
53
+ utils.withAttributeNamespace('Email')
54
+ ];
55
+ }
56
+ function date() {
57
+ return [
58
+ utils.withAttributeNamespace('Date')
59
+ ];
60
+ }
61
+ function time() {
62
+ return [
63
+ utils.withAttributeNamespace('Time')
64
+ ];
65
+ }
66
+ function datetime() {
67
+ return [
68
+ utils.withAttributeNamespace('DateTime')
69
+ ];
70
+ }
71
+ function timestamp() {
72
+ return [
73
+ utils.withAttributeNamespace('Timestamp')
74
+ ];
75
+ }
76
+ function integer() {
77
+ return [
78
+ utils.withAttributeNamespace('Integer')
79
+ ];
80
+ }
81
+ function biginteger() {
82
+ return [
83
+ utils.withAttributeNamespace('BigInteger')
84
+ ];
85
+ }
86
+ function float() {
87
+ return [
88
+ utils.withAttributeNamespace('Float')
89
+ ];
90
+ }
91
+ function decimal() {
92
+ return [
93
+ utils.withAttributeNamespace('Decimal')
94
+ ];
95
+ }
96
+ function uid({ attribute }) {
97
+ const { targetField, options } = attribute;
98
+ // If there are no params to compute, then return the attribute type alone
99
+ if (targetField === undefined && options === undefined) {
100
+ return [
101
+ utils.withAttributeNamespace('UID')
102
+ ];
103
+ }
104
+ const params = [];
105
+ // If the targetField property is defined, then reference it,
106
+ // otherwise, put `undefined` keyword type node as placeholder
107
+ const targetFieldParam = targetField === undefined ? factory.createKeywordTypeNode(ts__namespace.SyntaxKind.UndefinedKeyword) : factory.createStringLiteral(targetField);
108
+ params.push(targetFieldParam);
109
+ // If the options property is defined, transform it to
110
+ // a type literal node and add it to the params list
111
+ if (___default.default.isObject(options)) {
112
+ params.push(utils.toTypeLiteral(options));
113
+ }
114
+ return [
115
+ utils.withAttributeNamespace('UID'),
116
+ params
117
+ ];
118
+ }
119
+ function enumeration({ attribute }) {
120
+ const { enum: enumValues } = attribute;
121
+ return [
122
+ utils.withAttributeNamespace('Enumeration'),
123
+ [
124
+ utils.toTypeLiteral(enumValues)
125
+ ]
126
+ ];
127
+ }
128
+ function boolean() {
129
+ return [
130
+ utils.withAttributeNamespace('Boolean')
131
+ ];
132
+ }
133
+ function json() {
134
+ return [
135
+ utils.withAttributeNamespace('JSON')
136
+ ];
137
+ }
138
+ function blocks() {
139
+ return [
140
+ utils.withAttributeNamespace('Blocks')
141
+ ];
142
+ }
143
+ function media({ attribute }) {
144
+ const { allowedTypes, multiple } = attribute;
145
+ const params = [];
146
+ const typesParam = allowedTypes ? factory.createUnionTypeNode(allowedTypes.map((allowedType)=>factory.createStringLiteral(allowedType))) : factory.createKeywordTypeNode(ts__namespace.SyntaxKind.UndefinedKeyword);
147
+ if (allowedTypes || multiple) {
148
+ params.push(typesParam);
149
+ }
150
+ if (multiple) {
151
+ params.push(factory.createTrue());
152
+ }
153
+ return [
154
+ utils.withAttributeNamespace('Media'),
155
+ params
156
+ ];
157
+ }
158
+ function relation({ attribute }) {
159
+ const { relation: relationType, target } = attribute;
160
+ const isMorphRelation = relationType.toLowerCase().includes('morph');
161
+ if (isMorphRelation) {
162
+ return [
163
+ utils.withAttributeNamespace('Relation'),
164
+ [
165
+ factory.createStringLiteral(relationType, true)
166
+ ]
167
+ ];
168
+ }
169
+ return [
170
+ utils.withAttributeNamespace('Relation'),
171
+ [
172
+ factory.createStringLiteral(relationType, true),
173
+ factory.createStringLiteral(target, true)
174
+ ]
175
+ ];
176
+ }
177
+ function component({ attribute }) {
178
+ const target = attribute.component;
179
+ const params = [
180
+ factory.createStringLiteral(target, true)
181
+ ];
182
+ if (attribute.repeatable) {
183
+ params.push(factory.createTrue());
184
+ } else {
185
+ params.push(factory.createFalse());
186
+ }
187
+ return [
188
+ utils.withAttributeNamespace('Component'),
189
+ params
190
+ ];
191
+ }
192
+ function dynamiczone({ attribute }) {
193
+ const componentsParam = factory.createTupleTypeNode(attribute.components.map((c)=>factory.createStringLiteral(c)));
194
+ return [
195
+ utils.withAttributeNamespace('DynamicZone'),
196
+ [
197
+ componentsParam
198
+ ]
199
+ ];
200
+ }
201
+ const mappers = {
202
+ string,
203
+ text,
204
+ richtext,
205
+ password,
206
+ email,
207
+ date,
208
+ time,
209
+ datetime,
210
+ timestamp,
211
+ integer,
212
+ biginteger,
213
+ float,
214
+ decimal,
215
+ uid,
216
+ enumeration,
217
+ boolean,
218
+ json,
219
+ blocks,
220
+ media,
221
+ relation,
222
+ component,
223
+ dynamiczone
224
+ };
225
+
226
+ exports.mappers = mappers;
227
+ //# sourceMappingURL=mappers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mappers.js","sources":["../../../../src/generators/common/models/mappers.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport _ from 'lodash';\n\nimport { toTypeLiteral, withAttributeNamespace } from './utils';\nimport type { Attribute } from './utils';\n\nconst { factory } = ts;\n\nexport interface MapperContext {\n uid?: string;\n attribute: Attribute;\n attributeName?: string;\n}\n\nexport type Mapper = (context: MapperContext) => [string] | [string, any[]];\n\nfunction string(): [string] {\n return [withAttributeNamespace('String')];\n}\n\nfunction text(): [string] {\n return [withAttributeNamespace('Text')];\n}\n\nfunction richtext(): [string] {\n return [withAttributeNamespace('RichText')];\n}\n\nfunction password(): [string] {\n return [withAttributeNamespace('Password')];\n}\n\nfunction email(): [string] {\n return [withAttributeNamespace('Email')];\n}\n\nfunction date(): [string] {\n return [withAttributeNamespace('Date')];\n}\n\nfunction time(): [string] {\n return [withAttributeNamespace('Time')];\n}\n\nfunction datetime(): [string] {\n return [withAttributeNamespace('DateTime')];\n}\n\nfunction timestamp(): [string] {\n return [withAttributeNamespace('Timestamp')];\n}\n\nfunction integer(): [string] {\n return [withAttributeNamespace('Integer')];\n}\n\nfunction biginteger(): [string] {\n return [withAttributeNamespace('BigInteger')];\n}\n\nfunction float(): [string] {\n return [withAttributeNamespace('Float')];\n}\n\nfunction decimal(): [string] {\n return [withAttributeNamespace('Decimal')];\n}\n\nfunction uid({ attribute }: MapperContext): [string] | [string, any[]] {\n const { targetField, options } = attribute;\n\n // If there are no params to compute, then return the attribute type alone\n if (targetField === undefined && options === undefined) {\n return [withAttributeNamespace('UID')];\n }\n\n const params: any[] = [];\n\n // If the targetField property is defined, then reference it,\n // otherwise, put `undefined` keyword type node as placeholder\n const targetFieldParam =\n targetField === undefined\n ? factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword)\n : factory.createStringLiteral(targetField);\n\n params.push(targetFieldParam);\n\n // If the options property is defined, transform it to\n // a type literal node and add it to the params list\n if (_.isObject(options)) {\n params.push(toTypeLiteral(options));\n }\n\n return [withAttributeNamespace('UID'), params];\n}\n\nfunction enumeration({ attribute }: MapperContext): [string, any[]] {\n const { enum: enumValues } = attribute;\n\n return [withAttributeNamespace('Enumeration'), [toTypeLiteral(enumValues)]];\n}\n\nfunction boolean(): [string] {\n return [withAttributeNamespace('Boolean')];\n}\n\nfunction json(): [string] {\n return [withAttributeNamespace('JSON')];\n}\n\nfunction blocks(): [string] {\n return [withAttributeNamespace('Blocks')];\n}\n\nfunction media({ attribute }: MapperContext): [string, any[]] {\n const { allowedTypes, multiple } = attribute;\n\n const params: any[] = [];\n\n const typesParam = allowedTypes\n ? factory.createUnionTypeNode(\n allowedTypes.map((allowedType: string) => factory.createStringLiteral(allowedType))\n )\n : factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword);\n\n if (allowedTypes || multiple) {\n params.push(typesParam);\n }\n\n if (multiple) {\n params.push(factory.createTrue());\n }\n\n return [withAttributeNamespace('Media'), params];\n}\n\nfunction relation({ attribute }: MapperContext): [string, any[]] {\n const { relation: relationType, target } = attribute;\n\n const isMorphRelation = relationType.toLowerCase().includes('morph');\n\n if (isMorphRelation) {\n return [withAttributeNamespace('Relation'), [factory.createStringLiteral(relationType, true)]];\n }\n\n return [\n withAttributeNamespace('Relation'),\n [factory.createStringLiteral(relationType, true), factory.createStringLiteral(target, true)],\n ];\n}\n\nfunction component({ attribute }: MapperContext): [string, any[]] {\n const target = attribute.component;\n const params = [factory.createStringLiteral(target, true)];\n\n if (attribute.repeatable) {\n params.push(factory.createTrue() as any);\n } else {\n params.push(factory.createFalse() as any);\n }\n\n return [withAttributeNamespace('Component'), params];\n}\n\nfunction dynamiczone({ attribute }: MapperContext): [string, any[]] {\n const componentsParam = factory.createTupleTypeNode(\n attribute.components.map((c: string) => factory.createStringLiteral(c))\n );\n\n return [withAttributeNamespace('DynamicZone'), [componentsParam]];\n}\n\nexport const mappers: Record<string, Mapper> = {\n string,\n text,\n richtext,\n password,\n email,\n date,\n time,\n datetime,\n timestamp,\n integer,\n biginteger,\n float,\n decimal,\n uid,\n enumeration,\n boolean,\n json,\n blocks,\n media,\n relation,\n component,\n dynamiczone,\n};\n"],"names":["factory","ts","string","withAttributeNamespace","text","richtext","password","email","date","time","datetime","timestamp","integer","biginteger","float","decimal","uid","attribute","targetField","options","undefined","params","targetFieldParam","createKeywordTypeNode","SyntaxKind","UndefinedKeyword","createStringLiteral","push","_","isObject","toTypeLiteral","enumeration","enum","enumValues","boolean","json","blocks","media","allowedTypes","multiple","typesParam","createUnionTypeNode","map","allowedType","createTrue","relation","relationType","target","isMorphRelation","toLowerCase","includes","component","repeatable","createFalse","dynami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AAAA,OAAAA;AACAC,IAAAA,GAAAA;AACAe,IAAAA,WAAAA;AACAG,IAAAA,OAAAA;AACAC,IAAAA,IAAAA;AACAC,IAAAA,MAAAA;AACAC,IAAAA,KAAAA;AACAQ,IAAAA,QAAAA;AACAM,IAAAA,SAAAA;AACAG,IAAAA;AACF;;;;"}
@@ -0,0 +1,202 @@
1
+ import * as ts from 'typescript';
2
+ import _ from 'lodash';
3
+ import { withAttributeNamespace, toTypeLiteral } from './utils.mjs';
4
+
5
+ const { factory } = ts;
6
+ function string() {
7
+ return [
8
+ withAttributeNamespace('String')
9
+ ];
10
+ }
11
+ function text() {
12
+ return [
13
+ withAttributeNamespace('Text')
14
+ ];
15
+ }
16
+ function richtext() {
17
+ return [
18
+ withAttributeNamespace('RichText')
19
+ ];
20
+ }
21
+ function password() {
22
+ return [
23
+ withAttributeNamespace('Password')
24
+ ];
25
+ }
26
+ function email() {
27
+ return [
28
+ withAttributeNamespace('Email')
29
+ ];
30
+ }
31
+ function date() {
32
+ return [
33
+ withAttributeNamespace('Date')
34
+ ];
35
+ }
36
+ function time() {
37
+ return [
38
+ withAttributeNamespace('Time')
39
+ ];
40
+ }
41
+ function datetime() {
42
+ return [
43
+ withAttributeNamespace('DateTime')
44
+ ];
45
+ }
46
+ function timestamp() {
47
+ return [
48
+ withAttributeNamespace('Timestamp')
49
+ ];
50
+ }
51
+ function integer() {
52
+ return [
53
+ withAttributeNamespace('Integer')
54
+ ];
55
+ }
56
+ function biginteger() {
57
+ return [
58
+ withAttributeNamespace('BigInteger')
59
+ ];
60
+ }
61
+ function float() {
62
+ return [
63
+ withAttributeNamespace('Float')
64
+ ];
65
+ }
66
+ function decimal() {
67
+ return [
68
+ withAttributeNamespace('Decimal')
69
+ ];
70
+ }
71
+ function uid({ attribute }) {
72
+ const { targetField, options } = attribute;
73
+ // If there are no params to compute, then return the attribute type alone
74
+ if (targetField === undefined && options === undefined) {
75
+ return [
76
+ withAttributeNamespace('UID')
77
+ ];
78
+ }
79
+ const params = [];
80
+ // If the targetField property is defined, then reference it,
81
+ // otherwise, put `undefined` keyword type node as placeholder
82
+ const targetFieldParam = targetField === undefined ? factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword) : factory.createStringLiteral(targetField);
83
+ params.push(targetFieldParam);
84
+ // If the options property is defined, transform it to
85
+ // a type literal node and add it to the params list
86
+ if (_.isObject(options)) {
87
+ params.push(toTypeLiteral(options));
88
+ }
89
+ return [
90
+ withAttributeNamespace('UID'),
91
+ params
92
+ ];
93
+ }
94
+ function enumeration({ attribute }) {
95
+ const { enum: enumValues } = attribute;
96
+ return [
97
+ withAttributeNamespace('Enumeration'),
98
+ [
99
+ toTypeLiteral(enumValues)
100
+ ]
101
+ ];
102
+ }
103
+ function boolean() {
104
+ return [
105
+ withAttributeNamespace('Boolean')
106
+ ];
107
+ }
108
+ function json() {
109
+ return [
110
+ withAttributeNamespace('JSON')
111
+ ];
112
+ }
113
+ function blocks() {
114
+ return [
115
+ withAttributeNamespace('Blocks')
116
+ ];
117
+ }
118
+ function media({ attribute }) {
119
+ const { allowedTypes, multiple } = attribute;
120
+ const params = [];
121
+ const typesParam = allowedTypes ? factory.createUnionTypeNode(allowedTypes.map((allowedType)=>factory.createStringLiteral(allowedType))) : factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword);
122
+ if (allowedTypes || multiple) {
123
+ params.push(typesParam);
124
+ }
125
+ if (multiple) {
126
+ params.push(factory.createTrue());
127
+ }
128
+ return [
129
+ withAttributeNamespace('Media'),
130
+ params
131
+ ];
132
+ }
133
+ function relation({ attribute }) {
134
+ const { relation: relationType, target } = attribute;
135
+ const isMorphRelation = relationType.toLowerCase().includes('morph');
136
+ if (isMorphRelation) {
137
+ return [
138
+ withAttributeNamespace('Relation'),
139
+ [
140
+ factory.createStringLiteral(relationType, true)
141
+ ]
142
+ ];
143
+ }
144
+ return [
145
+ withAttributeNamespace('Relation'),
146
+ [
147
+ factory.createStringLiteral(relationType, true),
148
+ factory.createStringLiteral(target, true)
149
+ ]
150
+ ];
151
+ }
152
+ function component({ attribute }) {
153
+ const target = attribute.component;
154
+ const params = [
155
+ factory.createStringLiteral(target, true)
156
+ ];
157
+ if (attribute.repeatable) {
158
+ params.push(factory.createTrue());
159
+ } else {
160
+ params.push(factory.createFalse());
161
+ }
162
+ return [
163
+ withAttributeNamespace('Component'),
164
+ params
165
+ ];
166
+ }
167
+ function dynamiczone({ attribute }) {
168
+ const componentsParam = factory.createTupleTypeNode(attribute.components.map((c)=>factory.createStringLiteral(c)));
169
+ return [
170
+ withAttributeNamespace('DynamicZone'),
171
+ [
172
+ componentsParam
173
+ ]
174
+ ];
175
+ }
176
+ const mappers = {
177
+ string,
178
+ text,
179
+ richtext,
180
+ password,
181
+ email,
182
+ date,
183
+ time,
184
+ datetime,
185
+ timestamp,
186
+ integer,
187
+ biginteger,
188
+ float,
189
+ decimal,
190
+ uid,
191
+ enumeration,
192
+ boolean,
193
+ json,
194
+ blocks,
195
+ media,
196
+ relation,
197
+ component,
198
+ dynamiczone
199
+ };
200
+
201
+ export { mappers };
202
+ //# sourceMappingURL=mappers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mappers.mjs","sources":["../../../../src/generators/common/models/mappers.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport _ from 'lodash';\n\nimport { toTypeLiteral, withAttributeNamespace } from './utils';\nimport type { Attribute } from './utils';\n\nconst { factory } = ts;\n\nexport interface MapperContext {\n uid?: string;\n attribute: Attribute;\n attributeName?: string;\n}\n\nexport type Mapper = (context: MapperContext) => [string] | [string, any[]];\n\nfunction string(): [string] {\n return [withAttributeNamespace('String')];\n}\n\nfunction text(): [string] {\n return [withAttributeNamespace('Text')];\n}\n\nfunction richtext(): [string] {\n return [withAttributeNamespace('RichText')];\n}\n\nfunction password(): [string] {\n return [withAttributeNamespace('Password')];\n}\n\nfunction email(): [string] {\n return [withAttributeNamespace('Email')];\n}\n\nfunction date(): [string] {\n return [withAttributeNamespace('Date')];\n}\n\nfunction time(): [string] {\n return [withAttributeNamespace('Time')];\n}\n\nfunction datetime(): [string] {\n return [withAttributeNamespace('DateTime')];\n}\n\nfunction timestamp(): [string] {\n return [withAttributeNamespace('Timestamp')];\n}\n\nfunction integer(): [string] {\n return [withAttributeNamespace('Integer')];\n}\n\nfunction biginteger(): [string] {\n return [withAttributeNamespace('BigInteger')];\n}\n\nfunction float(): [string] {\n return [withAttributeNamespace('Float')];\n}\n\nfunction decimal(): [string] {\n return [withAttributeNamespace('Decimal')];\n}\n\nfunction uid({ attribute }: MapperContext): [string] | [string, any[]] {\n const { targetField, options } = attribute;\n\n // If there are no params to compute, then return the attribute type alone\n if (targetField === undefined && options === undefined) {\n return [withAttributeNamespace('UID')];\n }\n\n const params: any[] = [];\n\n // If the targetField property is defined, then reference it,\n // otherwise, put `undefined` keyword type node as placeholder\n const targetFieldParam =\n targetField === undefined\n ? factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword)\n : factory.createStringLiteral(targetField);\n\n params.push(targetFieldParam);\n\n // If the options property is defined, transform it to\n // a type literal node and add it to the params list\n if (_.isObject(options)) {\n params.push(toTypeLiteral(options));\n }\n\n return [withAttributeNamespace('UID'), params];\n}\n\nfunction enumeration({ attribute }: MapperContext): [string, any[]] {\n const { enum: enumValues } = attribute;\n\n return [withAttributeNamespace('Enumeration'), [toTypeLiteral(enumValues)]];\n}\n\nfunction boolean(): [string] {\n return [withAttributeNamespace('Boolean')];\n}\n\nfunction json(): [string] {\n return [withAttributeNamespace('JSON')];\n}\n\nfunction blocks(): [string] {\n return [withAttributeNamespace('Blocks')];\n}\n\nfunction media({ attribute }: MapperContext): [string, any[]] {\n const { allowedTypes, multiple } = attribute;\n\n const params: any[] = [];\n\n const typesParam = allowedTypes\n ? factory.createUnionTypeNode(\n allowedTypes.map((allowedType: string) => factory.createStringLiteral(allowedType))\n )\n : factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword);\n\n if (allowedTypes || multiple) {\n params.push(typesParam);\n }\n\n if (multiple) {\n params.push(factory.createTrue());\n }\n\n return [withAttributeNamespace('Media'), params];\n}\n\nfunction relation({ attribute }: MapperContext): [string, any[]] {\n const { relation: relationType, target } = attribute;\n\n const isMorphRelation = relationType.toLowerCase().includes('morph');\n\n if (isMorphRelation) {\n return [withAttributeNamespace('Relation'), [factory.createStringLiteral(relationType, true)]];\n }\n\n return [\n withAttributeNamespace('Relation'),\n [factory.createStringLiteral(relationType, true), factory.createStringLiteral(target, true)],\n ];\n}\n\nfunction component({ attribute }: MapperContext): [string, any[]] {\n const target = attribute.component;\n const params = [factory.createStringLiteral(target, true)];\n\n if (attribute.repeatable) {\n params.push(factory.createTrue() as any);\n } else {\n params.push(factory.createFalse() as any);\n }\n\n return [withAttributeNamespace('Component'), params];\n}\n\nfunction dynamiczone({ attribute }: MapperContext): [string, any[]] {\n const componentsParam = factory.createTupleTypeNode(\n attribute.components.map((c: string) => factory.createStringLiteral(c))\n );\n\n return [withAttributeNamespace('DynamicZone'), [componentsParam]];\n}\n\nexport const mappers: Record<string, Mapper> = {\n string,\n text,\n richtext,\n password,\n email,\n date,\n time,\n datetime,\n timestamp,\n integer,\n biginteger,\n float,\n decimal,\n uid,\n enumeration,\n boolean,\n json,\n blocks,\n media,\n relation,\n component,\n dynamiczone,\n};\n"],"names":["factory","ts","string","withAttributeNamespace","text","richtext","password","email","date","time","datetime","timestamp","integer","biginteger","float","decimal","uid","attribute","targetField","options","undefined","params","targetFieldParam","createKeywordTypeNode","SyntaxKind","UndefinedKeyword","createStringLiteral","push","_","isObject","toTypeLiteral","enumeration","enum","enumValues","boolean","json","blocks","media","allowedTypes","multiple","typesParam","createUnionTypeNode","map","allowedType","createTrue","relation","relationType","target","isMorphRelation","toLowerCase","includes","component","repeatable","createFalse","dynamiczone","componentsParam","createTupleTypeNode","components","c","mappers"],"mappings":";;;;AAMA,MAAM,EAAEA,OAAO,EAAE,GAAGC,EAAAA;AAUpB,SAASC,MAAAA,GAAAA;IACP,O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AACAM,IAAAA,SAAAA;AACAG,IAAAA;AACF;;;;"}
@@ -0,0 +1,8 @@
1
+ import * as ts from 'typescript';
2
+ import type { Schema } from './utils';
3
+ import type { AttributeOptions } from './attributes';
4
+ /**
5
+ * Generate an interface declaration for a given schema
6
+ */
7
+ export declare const generateSchemaDefinition: (schema: Schema, interfaceName?: string, options?: AttributeOptions) => ts.InterfaceDeclaration;
8
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/generators/common/models/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AASjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAsCrD;;GAEG;AACH,eAAO,MAAM,wBAAwB,GACnC,QAAQ,MAAM,EACd,gBAAe,MAA2C,EAC1D,UAAS,gBAAqB,KAC7B,EAAE,CAAC,oBAkCL,CAAC"}
@@ -0,0 +1,78 @@
1
+ 'use strict';
2
+
3
+ var ts = require('typescript');
4
+ var _ = require('lodash');
5
+ var utils = require('./utils.js');
6
+ var attributes = require('./attributes.js');
7
+ var imports = require('../imports.js');
8
+ var compare = require('../compare.js');
9
+
10
+ function _interopNamespace(e) {
11
+ if (e && e.__esModule) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n.default = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
29
+
30
+ const { factory } = ts__namespace;
31
+ /**
32
+ * Generate a property signature for the schema's `attributes` field
33
+ */ const generateAttributePropertySignature = (schema, options)=>{
34
+ const { attributes: attributes$1 } = schema;
35
+ const properties = Object.entries(attributes$1).sort((a, b)=>compare.compareEnglish(a[0], b[0])).map(([attributeName, attribute])=>{
36
+ return attributes.attributeToPropertySignature(schema, attributeName, attribute, options);
37
+ });
38
+ return factory.createPropertySignature(undefined, factory.createIdentifier('attributes'), undefined, factory.createTypeLiteralNode(properties));
39
+ };
40
+ const generatePropertyLiteralDefinitionFactory = (schema)=>(key)=>{
41
+ return factory.createPropertySignature(undefined, factory.createIdentifier(key), undefined, utils.toTypeLiteral(schema[key]));
42
+ };
43
+ /**
44
+ * Generate an interface declaration for a given schema
45
+ */ const generateSchemaDefinition = (schema, interfaceName = utils.getSchemaInterfaceName(schema.uid), options = {})=>{
46
+ // Resolve the different interface names needed to declare the schema's interface
47
+ const parentType = utils.getSchemaExtendsTypeName(schema);
48
+ // Make sure the Struct namespace is imported
49
+ imports.addImport(utils.NAMESPACES.Struct);
50
+ // Properties whose values can be mapped to a literal type expression
51
+ const literalPropertiesDefinitions = [
52
+ 'collectionName',
53
+ 'info',
54
+ 'options',
55
+ 'pluginOptions'
56
+ ]// Ignore non-existent or empty declarations
57
+ .filter((key)=>!_.isEmpty(schema[key]))// Generate literal definition for each property
58
+ .map(generatePropertyLiteralDefinitionFactory(schema));
59
+ // Generate the `attributes` literal type definition
60
+ const attributesProp = generateAttributePropertySignature(schema, options);
61
+ // Merge every schema's definition in a single list
62
+ const schemaProperties = [
63
+ ...literalPropertiesDefinitions,
64
+ attributesProp
65
+ ];
66
+ // Generate the schema's interface declaration
67
+ const schemaType = factory.createInterfaceDeclaration([
68
+ factory.createModifier(ts__namespace.SyntaxKind.ExportKeyword)
69
+ ], factory.createIdentifier(interfaceName), undefined, [
70
+ factory.createHeritageClause(ts__namespace.SyntaxKind.ExtendsKeyword, [
71
+ factory.createIdentifier(parentType)
72
+ ])
73
+ ], schemaProperties);
74
+ return schemaType;
75
+ };
76
+
77
+ exports.generateSchemaDefinition = generateSchemaDefinition;
78
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sources":["../../../../src/generators/common/models/schema.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { isEmpty } from 'lodash';\n\nimport {\n getSchemaExtendsTypeName,\n getSchemaInterfaceName,\n toTypeLiteral,\n NAMESPACES,\n} from './utils';\nimport type { Schema } from './utils';\nimport { attributeToPropertySignature } from './attributes';\nimport type { AttributeOptions } from './attributes';\nimport { addImport } from '../imports';\nimport { compareEnglish } from '../compare';\n\nconst { factory } = ts;\n\n/**\n * Generate a property signature for the schema's `attributes` field\n */\nconst generateAttributePropertySignature = (\n schema: Schema,\n options: AttributeOptions\n): ts.PropertySignature => {\n const { attributes } = schema;\n\n const properties = Object.entries(attributes)\n .sort((a, b) => compareEnglish(a[0], b[0]))\n .map(([attributeName, attribute]) => {\n return attributeToPropertySignature(schema, attributeName, attribute, options);\n });\n\n return factory.createPropertySignature(\n undefined,\n factory.createIdentifier('attributes'),\n undefined,\n factory.createTypeLiteralNode(properties as any)\n );\n};\n\nconst generatePropertyLiteralDefinitionFactory = (schema: Schema) => (key: string) => {\n return factory.createPropertySignature(\n undefined,\n factory.createIdentifier(key),\n undefined,\n toTypeLiteral(schema[key])\n );\n};\n\n/**\n * Generate an interface declaration for a given schema\n */\nexport const generateSchemaDefinition = (\n schema: Schema,\n interfaceName: string = getSchemaInterfaceName(schema.uid),\n options: AttributeOptions = {}\n): ts.InterfaceDeclaration => {\n // Resolve the different interface names needed to declare the schema's interface\n const parentType = getSchemaExtendsTypeName(schema);\n\n // Make sure the Struct namespace is imported\n addImport(NAMESPACES.Struct);\n\n // Properties whose values can be mapped to a literal type expression\n const literalPropertiesDefinitions = ['collectionName', 'info', 'options', 'pluginOptions']\n // Ignore non-existent or empty declarations\n .filter((key) => !isEmpty(schema[key]))\n // Generate literal definition for each property\n .map(generatePropertyLiteralDefinitionFactory(schema));\n\n // Generate the `attributes` literal type definition\n const attributesProp = generateAttributePropertySignature(schema, options);\n\n // Merge every schema's definition in a single list\n const schemaProperties = [...literalPropertiesDefinitions, attributesProp];\n\n // Generate the schema's interface declaration\n const schemaType = factory.createInterfaceDeclaration(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(interfaceName),\n undefined,\n [\n factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [\n factory.createIdentifier(parentType as string) as any,\n ]),\n ],\n schemaProperties\n );\n\n return schemaType;\n};\n"],"names":["factory","ts","generateAttributePropertySignature","schema","options","attributes","properties","Object","entries","sort","a","b","compareEnglish","map","attributeName","attribute","attributeToPropertySignature","createPropertySignature","undefined","createIdentifier","createTypeLiteralNode","generatePropertyLiteralDefinitionFactory","key","toTypeLiteral","generateSchemaDefinition","interfaceName","getSchemaInterfaceName","uid","parentType","getSchemaExtendsTypeName","addImport","NAMESPACES","Struct","literalPropertiesDefinitions","filter","isEmpty","attributesProp","schemaProperties","schemaType","createInterfaceDeclaration","createModifier","SyntaxKind","ExportKeyword","createHeritageClause","ExtendsKeyword"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,EAAEA,OAAO,EAAE,GAAGC,aAAAA;AAEpB;;IAGA,MAAMC,kCAAAA,GAAqC,CACzCC,MAAAA,EACAC,OAAAA,GAAAA;IAEA,MAAM,cAAEC,YAAU,EAAE,GAAGF,MAAAA;IAEvB,MAAMG,UAAAA,GAAaC,MAAAA,CAAOC,OAAO,CAACH,YAAAA,CAAAA,CAC/BI,IAAI,CAAC,CAACC,CAAAA,EAAGC,CAAAA,GAAMC,sBAAAA,CAAeF,CAAC,CAAC,CAAA,CAAE,EAAEC,CAAC,CAAC,CAAA,CAAE,CAAA,CAAA,CACxCE,GAAG,CAAC,CAAC,CAACC,aAAAA,EAAeC,SAAAA,CAAU,GAAA;QAC9B,OAAOC,uCAAAA,CAA6Bb,MAAAA,EAAQW,aAAAA,EAAeC,SAAAA,EAAWX,OAAAA,CAA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,UAAAA,GAAatC,OAAAA,CAAQuC,0BAA0B,CACnD;AAACvC,QAAAA,OAAAA,CAAQwC,cAAc,CAACvC,aAAAA,CAAGwC,UAAU,CAACC,aAAa;AAAE,KAAA,EACrD1C,OAAAA,CAAQmB,gBAAgB,CAACM,aAAAA,CAAAA,EACzBP,SAAAA,EACA;AACElB,QAAAA,OAAAA,CAAQ2C,oBAAoB,CAAC1C,aAAAA,CAAGwC,UAAU,CAACG,cAAc,EAAE;AACzD5C,YAAAA,OAAAA,CAAQmB,gBAAgB,CAACS,UAAAA;AAC1B,SAAA;KACF,EACDS,gBAAAA,CAAAA;IAGF,OAAOC,UAAAA;AACT;;;;"}
@@ -0,0 +1,56 @@
1
+ import * as ts from 'typescript';
2
+ import { isEmpty } from 'lodash';
3
+ import { getSchemaExtendsTypeName, getSchemaInterfaceName, toTypeLiteral, NAMESPACES } from './utils.mjs';
4
+ import { attributeToPropertySignature } from './attributes.mjs';
5
+ import { addImport } from '../imports.mjs';
6
+ import { compareEnglish } from '../compare.mjs';
7
+
8
+ const { factory } = ts;
9
+ /**
10
+ * Generate a property signature for the schema's `attributes` field
11
+ */ const generateAttributePropertySignature = (schema, options)=>{
12
+ const { attributes } = schema;
13
+ const properties = Object.entries(attributes).sort((a, b)=>compareEnglish(a[0], b[0])).map(([attributeName, attribute])=>{
14
+ return attributeToPropertySignature(schema, attributeName, attribute, options);
15
+ });
16
+ return factory.createPropertySignature(undefined, factory.createIdentifier('attributes'), undefined, factory.createTypeLiteralNode(properties));
17
+ };
18
+ const generatePropertyLiteralDefinitionFactory = (schema)=>(key)=>{
19
+ return factory.createPropertySignature(undefined, factory.createIdentifier(key), undefined, toTypeLiteral(schema[key]));
20
+ };
21
+ /**
22
+ * Generate an interface declaration for a given schema
23
+ */ const generateSchemaDefinition = (schema, interfaceName = getSchemaInterfaceName(schema.uid), options = {})=>{
24
+ // Resolve the different interface names needed to declare the schema's interface
25
+ const parentType = getSchemaExtendsTypeName(schema);
26
+ // Make sure the Struct namespace is imported
27
+ addImport(NAMESPACES.Struct);
28
+ // Properties whose values can be mapped to a literal type expression
29
+ const literalPropertiesDefinitions = [
30
+ 'collectionName',
31
+ 'info',
32
+ 'options',
33
+ 'pluginOptions'
34
+ ]// Ignore non-existent or empty declarations
35
+ .filter((key)=>!isEmpty(schema[key]))// Generate literal definition for each property
36
+ .map(generatePropertyLiteralDefinitionFactory(schema));
37
+ // Generate the `attributes` literal type definition
38
+ const attributesProp = generateAttributePropertySignature(schema, options);
39
+ // Merge every schema's definition in a single list
40
+ const schemaProperties = [
41
+ ...literalPropertiesDefinitions,
42
+ attributesProp
43
+ ];
44
+ // Generate the schema's interface declaration
45
+ const schemaType = factory.createInterfaceDeclaration([
46
+ factory.createModifier(ts.SyntaxKind.ExportKeyword)
47
+ ], factory.createIdentifier(interfaceName), undefined, [
48
+ factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
49
+ factory.createIdentifier(parentType)
50
+ ])
51
+ ], schemaProperties);
52
+ return schemaType;
53
+ };
54
+
55
+ export { generateSchemaDefinition };
56
+ //# sourceMappingURL=schema.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.mjs","sources":["../../../../src/generators/common/models/schema.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { isEmpty } from 'lodash';\n\nimport {\n getSchemaExtendsTypeName,\n getSchemaInterfaceName,\n toTypeLiteral,\n NAMESPACES,\n} from './utils';\nimport type { Schema } from './utils';\nimport { attributeToPropertySignature } from './attributes';\nimport type { AttributeOptions } from './attributes';\nimport { addImport } from '../imports';\nimport { compareEnglish } from '../compare';\n\nconst { factory } = ts;\n\n/**\n * Generate a property signature for the schema's `attributes` field\n */\nconst generateAttributePropertySignature = (\n schema: Schema,\n options: AttributeOptions\n): ts.PropertySignature => {\n const { attributes } = schema;\n\n const properties = Object.entries(attributes)\n .sort((a, b) => compareEnglish(a[0], b[0]))\n .map(([attributeName, attribute]) => {\n return attributeToPropertySignature(schema, attributeName, attribute, options);\n });\n\n return factory.createPropertySignature(\n undefined,\n factory.createIdentifier('attributes'),\n undefined,\n factory.createTypeLiteralNode(properties as any)\n );\n};\n\nconst generatePropertyLiteralDefinitionFactory = (schema: Schema) => (key: string) => {\n return factory.createPropertySignature(\n undefined,\n factory.createIdentifier(key),\n undefined,\n toTypeLiteral(schema[key])\n );\n};\n\n/**\n * Generate an interface declaration for a given schema\n */\nexport const generateSchemaDefinition = (\n schema: Schema,\n interfaceName: string = getSchemaInterfaceName(schema.uid),\n options: AttributeOptions = {}\n): ts.InterfaceDeclaration => {\n // Resolve the different interface names needed to declare the schema's interface\n const parentType = getSchemaExtendsTypeName(schema);\n\n // Make sure the Struct namespace is imported\n addImport(NAMESPACES.Struct);\n\n // Properties whose values can be mapped to a literal type expression\n const literalPropertiesDefinitions = ['collectionName', 'info', 'options', 'pluginOptions']\n // Ignore non-existent or empty declarations\n .filter((key) => !isEmpty(schema[key]))\n // Generate literal definition for each property\n .map(generatePropertyLiteralDefinitionFactory(schema));\n\n // Generate the `attributes` literal type definition\n const attributesProp = generateAttributePropertySignature(schema, options);\n\n // Merge every schema's definition in a single list\n const schemaProperties = [...literalPropertiesDefinitions, attributesProp];\n\n // Generate the schema's interface declaration\n const schemaType = factory.createInterfaceDeclaration(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(interfaceName),\n undefined,\n [\n factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [\n factory.createIdentifier(parentType as string) as any,\n ]),\n ],\n schemaProperties\n );\n\n return schemaType;\n};\n"],"names":["factory","ts","generateAttributePropertySignature","schema","options","attributes","properties","Object","entries","sort","a","b","compareEnglish","map","attributeName","attribute","attributeToPropertySignature","createPropertySignature","undefined","createIdentifier","createTypeLiteralNode","generatePropertyLiteralDefinitionFactory","key","toTypeLiteral","generateSchemaDefinition","interfaceName","getSchemaInterfaceName","uid","parentType","getSchemaExtendsTypeName","addImport","NAMESPACES","Struct","literalPropertiesDefinitions","filter","isEmpty","attributesProp","schemaProperties","schemaType","createInterfaceDeclaration","createModifier","SyntaxKind","ExportKeyword","createHeritageClause","ExtendsKeyword"],"mappings":";;;;;;;AAeA,MAAM,EAAEA,OAAO,EAAE,GAAGC,EAAAA;AAEpB;;IAGA,MAAMC,kCAAAA,GAAqC,CACzCC,MAAAA,EACAC,OAAAA,GAAAA;IAEA,MAAM,EAAEC,UAAU,EAAE,GAAGF,MAAAA;IAEvB,MAAMG,UAAAA,GAAaC,MAAAA,CAAOC,OAAO,CAACH,UAAAA,CAAAA,CAC/BI,IAAI,CAAC,CAACC,CAAAA,EAAGC,CAAAA,GAAMC,cAAAA,CAAeF,CAAC,CAAC,CAAA,CAAE,EAAEC,CAAC,CAAC,CAAA,CAAE,CAAA,CAAA,CACxCE,GAAG,CAAC,CAAC,CAACC,aAAAA,EAAeC,SAAAA,CAAU,GAAA;QAC9B,OAAOC,4BAAAA,CAA6Bb,MAAAA,EAAQW,aAAAA,EAAeC,SAAAA,EAAWX,OAAAA,CAAAA;AACxE,IAAA,CAAA,CAAA;IAEF,OAAOJ,OAAAA,CAAQiB,uBAAuB,CACpCC,SAAAA,EACAlB,OAAAA,CAAQmB,gBAAgB,CAAC,YAAA,CAAA,EACzBD,SAAAA,EACAlB,OAAAA,CAAQoB,qBAAqB,CAACd,UAAAA,CAAAA,CAAAA;AAElC,CAAA;AAEA,MAAMe,wCAAAA,GAA2C,CAAClB,MAAAA,GAAmB,CAACmB,GAAAA,GAAAA;AACpE,QAAA,OAAOtB,OAAAA,CAAQiB,uBAAuB,CACpCC,SAAAA,EACAlB,OAAAA,CAAQmB,gBAAgB,CAACG,GAAAA,CAAAA,EACzBJ,SAAAA,EACAK,aAAAA,CAAcpB,MAAM,CAACmB,GAAAA,CAAI,CAAA,CAAA;AAE7B,IAAA,CAAA;AAEA;;AAEC,IACM,MAAME,wBAAAA,GAA2B,CACtCrB,MAAAA,EACAsB,aAAAA,GAAwBC,sBAAAA,CAAuBvB,MAAAA,CAAOwB,GAAG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