@strapi/typescript-utils 5.50.0 → 5.50.2

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 (171) 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/imports.d.ts +5 -0
  20. package/dist/generators/common/imports.d.ts.map +1 -0
  21. package/dist/generators/common/imports.js +42 -0
  22. package/dist/generators/common/imports.js.map +1 -0
  23. package/dist/generators/common/imports.mjs +19 -0
  24. package/dist/generators/common/imports.mjs.map +1 -0
  25. package/dist/generators/common/index.d.ts +4 -0
  26. package/dist/generators/common/index.d.ts.map +1 -0
  27. package/dist/generators/common/models/attributes.d.ts +17 -0
  28. package/dist/generators/common/models/attributes.d.ts.map +1 -0
  29. package/dist/generators/common/models/attributes.js +152 -0
  30. package/dist/generators/common/models/attributes.js.map +1 -0
  31. package/dist/generators/common/models/attributes.mjs +124 -0
  32. package/dist/generators/common/models/attributes.mjs.map +1 -0
  33. package/dist/generators/common/models/index.d.ts +7 -0
  34. package/dist/generators/common/models/index.d.ts.map +1 -0
  35. package/dist/generators/common/models/mappers.d.ts +9 -0
  36. package/dist/generators/common/models/mappers.d.ts.map +1 -0
  37. package/dist/generators/common/models/mappers.js +227 -0
  38. package/dist/generators/common/models/mappers.js.map +1 -0
  39. package/dist/generators/common/models/mappers.mjs +202 -0
  40. package/dist/generators/common/models/mappers.mjs.map +1 -0
  41. package/dist/generators/common/models/schema.d.ts +7 -0
  42. package/dist/generators/common/models/schema.d.ts.map +1 -0
  43. package/dist/generators/common/models/schema.js +79 -0
  44. package/dist/generators/common/models/schema.js.map +1 -0
  45. package/dist/generators/common/models/schema.mjs +57 -0
  46. package/dist/generators/common/models/schema.mjs.map +1 -0
  47. package/dist/generators/common/models/utils.d.ts +54 -0
  48. package/dist/generators/common/models/utils.d.ts.map +1 -0
  49. package/dist/generators/common/models/utils.js +109 -0
  50. package/dist/generators/common/models/utils.js.map +1 -0
  51. package/dist/generators/common/models/utils.mjs +81 -0
  52. package/dist/generators/common/models/utils.mjs.map +1 -0
  53. package/dist/generators/components/index.d.ts +9 -0
  54. package/dist/generators/components/index.d.ts.map +1 -0
  55. package/dist/generators/components/index.js +76 -0
  56. package/dist/generators/components/index.js.map +1 -0
  57. package/dist/generators/components/index.mjs +54 -0
  58. package/dist/generators/components/index.mjs.map +1 -0
  59. package/dist/generators/constants.d.ts +3 -0
  60. package/dist/generators/constants.d.ts.map +1 -0
  61. package/dist/generators/constants.js +8 -0
  62. package/dist/generators/constants.js.map +1 -0
  63. package/dist/generators/constants.mjs +5 -0
  64. package/dist/generators/constants.mjs.map +1 -0
  65. package/dist/generators/content-types/index.d.ts +9 -0
  66. package/dist/generators/content-types/index.d.ts.map +1 -0
  67. package/dist/generators/content-types/index.js +76 -0
  68. package/dist/generators/content-types/index.js.map +1 -0
  69. package/dist/generators/content-types/index.mjs +54 -0
  70. package/dist/generators/content-types/index.mjs.map +1 -0
  71. package/dist/generators/index.d.ts +23 -0
  72. package/dist/generators/index.d.ts.map +1 -0
  73. package/dist/generators/index.js +81 -0
  74. package/dist/generators/index.js.map +1 -0
  75. package/dist/generators/index.mjs +74 -0
  76. package/dist/generators/index.mjs.map +1 -0
  77. package/dist/generators/utils.d.ts +52 -0
  78. package/dist/generators/utils.d.ts.map +1 -0
  79. package/dist/generators/utils.js +164 -0
  80. package/dist/generators/utils.js.map +1 -0
  81. package/dist/generators/utils.mjs +131 -0
  82. package/dist/generators/utils.mjs.map +1 -0
  83. package/dist/index.d.ts +5 -0
  84. package/dist/index.d.ts.map +1 -0
  85. package/dist/index.js +28 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/index.mjs +14 -0
  88. package/dist/index.mjs.map +1 -0
  89. package/dist/utils/format-host.d.ts +3 -0
  90. package/dist/utils/format-host.d.ts.map +1 -0
  91. package/dist/utils/format-host.js +33 -0
  92. package/dist/utils/format-host.js.map +1 -0
  93. package/dist/utils/format-host.mjs +11 -0
  94. package/dist/utils/format-host.mjs.map +1 -0
  95. package/dist/utils/get-config-path.d.ts +10 -0
  96. package/dist/utils/get-config-path.d.ts.map +1 -0
  97. package/dist/utils/get-config-path.js +43 -0
  98. package/dist/utils/get-config-path.js.map +1 -0
  99. package/dist/utils/get-config-path.mjs +18 -0
  100. package/dist/utils/get-config-path.mjs.map +1 -0
  101. package/dist/utils/index.d.ts +9 -0
  102. package/dist/utils/index.d.ts.map +1 -0
  103. package/dist/utils/is-using-typescript-sync.d.ts +5 -0
  104. package/dist/utils/is-using-typescript-sync.d.ts.map +1 -0
  105. package/dist/utils/is-using-typescript-sync.js +20 -0
  106. package/dist/utils/is-using-typescript-sync.js.map +1 -0
  107. package/dist/utils/is-using-typescript-sync.mjs +14 -0
  108. package/dist/utils/is-using-typescript-sync.mjs.map +1 -0
  109. package/dist/utils/is-using-typescript.d.ts +5 -0
  110. package/dist/utils/is-using-typescript.d.ts.map +1 -0
  111. package/dist/utils/is-using-typescript.js +20 -0
  112. package/dist/utils/is-using-typescript.js.map +1 -0
  113. package/dist/utils/is-using-typescript.mjs +14 -0
  114. package/dist/utils/is-using-typescript.mjs.map +1 -0
  115. package/dist/utils/report-diagnostics.d.ts +6 -0
  116. package/dist/utils/report-diagnostics.d.ts.map +1 -0
  117. package/dist/utils/report-diagnostics.js +37 -0
  118. package/dist/utils/report-diagnostics.js.map +1 -0
  119. package/dist/utils/report-diagnostics.mjs +15 -0
  120. package/dist/utils/report-diagnostics.mjs.map +1 -0
  121. package/dist/utils/resolve-config-options.d.ts +12 -0
  122. package/dist/utils/resolve-config-options.d.ts.map +1 -0
  123. package/dist/utils/resolve-config-options.js +39 -0
  124. package/dist/utils/resolve-config-options.js.map +1 -0
  125. package/dist/utils/resolve-config-options.mjs +17 -0
  126. package/dist/utils/resolve-config-options.mjs.map +1 -0
  127. package/dist/utils/resolve-outdir-sync.d.ts +5 -0
  128. package/dist/utils/resolve-outdir-sync.d.ts.map +1 -0
  129. package/dist/utils/resolve-outdir-sync.js +19 -0
  130. package/dist/utils/resolve-outdir-sync.js.map +1 -0
  131. package/dist/utils/resolve-outdir-sync.mjs +13 -0
  132. package/dist/utils/resolve-outdir-sync.mjs.map +1 -0
  133. package/dist/utils/resolve-outdir.d.ts +5 -0
  134. package/dist/utils/resolve-outdir.d.ts.map +1 -0
  135. package/dist/utils/resolve-outdir.js +19 -0
  136. package/dist/utils/resolve-outdir.js.map +1 -0
  137. package/dist/utils/resolve-outdir.mjs +13 -0
  138. package/dist/utils/resolve-outdir.mjs.map +1 -0
  139. package/package.json +25 -10
  140. package/.eslintrc.cjs +0 -16
  141. package/index.d.ts +0 -5
  142. package/jest.config.js +0 -6
  143. package/lib/__tests__/generators/schemas/attributes.test.js +0 -903
  144. package/lib/__tests__/generators/schemas/imports.test.js +0 -56
  145. package/lib/__tests__/generators/schemas/utils.test.js +0 -314
  146. package/lib/compile.js +0 -10
  147. package/lib/compilers/basic.js +0 -50
  148. package/lib/compilers/index.js +0 -7
  149. package/lib/generators/common/imports.js +0 -34
  150. package/lib/generators/common/index.js +0 -9
  151. package/lib/generators/common/models/attributes.js +0 -198
  152. package/lib/generators/common/models/index.js +0 -15
  153. package/lib/generators/common/models/mappers.js +0 -144
  154. package/lib/generators/common/models/schema.js +0 -93
  155. package/lib/generators/common/models/utils.js +0 -178
  156. package/lib/generators/components/index.js +0 -74
  157. package/lib/generators/constants.js +0 -6
  158. package/lib/generators/content-types/index.js +0 -74
  159. package/lib/generators/index.js +0 -122
  160. package/lib/generators/utils.js +0 -216
  161. package/lib/index.js +0 -13
  162. package/lib/utils/format-host.js +0 -15
  163. package/lib/utils/get-config-path.js +0 -29
  164. package/lib/utils/index.js +0 -21
  165. package/lib/utils/is-using-typescript-sync.js +0 -19
  166. package/lib/utils/is-using-typescript.js +0 -17
  167. package/lib/utils/report-diagnostics.js +0 -19
  168. package/lib/utils/resolve-config-options.js +0 -23
  169. package/lib/utils/resolve-outdir-sync.js +0 -18
  170. package/lib/utils/resolve-outdir.js +0 -18
  171. package/lint-staged.config.mjs +0 -1
@@ -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/fp';\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 * Collect every modifier node from an attribute\n */\nexport const getAttributeModifiers = (attribute: Attribute): 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 (!_.isNil(attribute.min) || !_.isNil(attribute.max)) {\n const minMaxProperties = _.pick(['min', 'max'], attribute);\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 (!_.isNil(attribute.minLength) || !_.isNil(attribute.maxLength)) {\n const minMaxProperties = _.pick(['minLength', 'maxLength'], attribute);\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('SetMinMaxLength')),\n [toTypeLiteral(minMaxProperties)]\n )\n );\n }\n\n // Default (ignore if default is a function)\n if (!_.isNil(attribute.default) && !_.isFunction(attribute.default)) {\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 * Generate a property signature node for a given attribute\n */\nexport const attributeToPropertySignature = (\n schema: Schema,\n attributeName: string,\n attribute: Attribute\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);\n\n const nodes = [baseType, ...modifiers];\n\n return factory.createPropertySignature(\n undefined,\n factory.createIdentifier(attributeName),\n undefined,\n factory.createIntersectionTypeNode(nodes)\n );\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","modifiers","required","push","createTypeReferenceNode","createIdentifier","withAttributeNamespace","private","unique","configurable","customField","customFieldUid","createStringLiteral","typeArguments","options","toTypeLiteral","_","isEmpty","pluginOptions","isNil","min","max","minMaxProperties","pick","typeofMin","typeofMax","undefined","Error","typeKeyword","SyntaxKind","StringKeyword","NumberKeyword","createKeywordTypeNode","minLength","maxLength","default","isFunction","defaultLiteral","attributeToPropertySignature","schema","baseType","nodes","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;QACrB,OAAO,IAAA;AACT,IAAA;AAEA,IAAA,MAAMvC,YAAYD,qBAAAA,CAAsBf,SAAAA,CAAAA;AAExC,IAAA,MAAMwD,KAAAA,GAAQ;AAACD,QAAAA,QAAAA;AAAavC,QAAAA,GAAAA;AAAU,KAAA;IAEtC,OAAOpB,OAAAA,CAAQ6D,uBAAuB,CACpChB,SAAAA,EACA7C,OAAAA,CAAQwB,gBAAgB,CAACrB,aAAAA,CAAAA,EACzB0C,SAAAA,EACA7C,OAAAA,CAAQ8D,0BAA0B,CAACF,KAAAA,CAAAA,CAAAA;AAEvC;;;;"}
@@ -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;AA6J5E,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAuB1C,CAAC"}
@@ -0,0 +1,227 @@
1
+ 'use strict';
2
+
3
+ var ts = require('typescript');
4
+ var _ = require('lodash/fp');
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 = ___default.default.isUndefined(targetField) ? 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/fp';\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 = _.isUndefined(targetField)\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","_","isUndefined","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,aAAAA;AAUpB,SAASC,MAAAA,GAAAA;IACP,OAAO;QAACC,4BAAAA,CAAuB,QAAA;AAAU,KAAA;AAC3C;AAEA,SAASC,IAAAA,GAAAA;IACP,OAAO;QAACD,4BAAAA,CAAuB,MAAA;AAAQ,KAAA;AACzC;AAEA,SAASE,QAAAA,GAAAA;IACP,OAAO;QAACF,4BAAAA,CAAuB,UAAA;AAAY,KAAA;AAC7C;AAEA,SAASG,QAAAA,GAAAA;IACP,OAAO;QAACH,4BAAAA,CAAuB,UAAA;AAAY,KAAA;AAC7C;AAEA,SAASI,KAAAA,GAAAA;IACP,OAAO;QAACJ,4BAAAA,CAAuB,OAAA;AAAS,KAAA;AAC1C;AAEA,SAASK,IAAAA,GAAAA;IACP,OAAO;QAAC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,CAAA;AAAckB,QAAAA;AAAO,KAAA;AACtD;AAEA,SAASkC,WAAAA,CAAY,EAAEtC,SAAS,EAAiB,EAAA;AAC/C,IAAA,MAAMuC,eAAAA,GAAkBxD,OAAAA,CAAQyD,mBAAmB,CACjDxC,SAAAA,CAAUyC,UAAU,CAACf,GAAG,CAAC,CAACgB,CAAAA,GAAc3D,OAAAA,CAAQ4B,mBAAmB,CAAC+B,CAAAA,CAAAA,CAAAA,CAAAA;IAGtE,OAAO;QAACxD,4BAAAA,CAAuB,aAAA,CAAA;AAAgB,QAAA;AAACqD,YAAAA;AAAgB;AAAC,KAAA;AACnE;MAEaI,OAAAA,GAAkC;AAC7C1D,IAAAA,MAAAA;AACAE,IAAAA,IAAAA;AACAC,IAAAA,QAAAA;AACAC,IAAAA,QAAAA;AACAC,IAAAA,KAAAA;AACAC,IAAAA,IAAAA;AACAC,IAAAA,IAAAA;AACAC,IAAAA,QAAAA;AACAC,IAAAA,SAAAA;AACAC,IAAAA,OAAAA;AACAC,IAAAA,UAAAA;AACAC,IAAAA,KAAAA;AACAC,IAAAA,OAAAA;AACAC,IAAAA,GAAAA;AACAgB,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/fp';
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 = _.isUndefined(targetField) ? 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/fp';\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 = _.isUndefined(targetField)\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","_","isUndefined","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,OAAO;QAACC,sBAAAA,CAAuB,QAAA;AAAU,KAAA;AAC3C;AAEA,SAASC,IAAAA,GAAAA;IACP,OAAO;QAACD,sBAAAA,CAAuB,MAAA;AAAQ,KAAA;AACzC;AAEA,SAASE,QAAAA,GAAAA;IACP,OAAO;QAACF,sBAAAA,CAAuB,UAAA;AAAY,KAAA;AAC7C;AAEA,SAASG,QAAAA,GAAAA;IACP,OAAO;QAACH,sBAAAA,CAAuB,UAAA;AAAY,KAAA;AAC7C;AAEA,SAASI,KAAAA,GAAAA;IACP,OAAO;QAACJ,sBAAAA,CAAuB,OAAA;AAAS,KAAA;AAC1C;AAEA,SAASK,IAAAA,GAAAA;IACP,OAAO;QAACL,sBAAAA,CAAuB,MAAA;AAAQ,KAAA;AACzC;AAEA,SAASM,IAAAA,GAAAA;IACP,OAAO;QAACN,sBAAAA,CAAuB,MAAA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uC,eAAAA,GAAkBxD,OAAAA,CAAQyD,mBAAmB,CACjDxC,SAAAA,CAAUyC,UAAU,CAACf,GAAG,CAAC,CAACgB,CAAAA,GAAc3D,OAAAA,CAAQ4B,mBAAmB,CAAC+B,CAAAA,CAAAA,CAAAA,CAAAA;IAGtE,OAAO;QAACxD,sBAAAA,CAAuB,aAAA,CAAA;AAAgB,QAAA;AAACqD,YAAAA;AAAgB;AAAC,KAAA;AACnE;MAEaI,OAAAA,GAAkC;AAC7C1D,IAAAA,MAAAA;AACAE,IAAAA,IAAAA;AACAC,IAAAA,QAAAA;AACAC,IAAAA,QAAAA;AACAC,IAAAA,KAAAA;AACAC,IAAAA,IAAAA;AACAC,IAAAA,IAAAA;AACAC,IAAAA,QAAAA;AACAC,IAAAA,SAAAA;AACAC,IAAAA,OAAAA;AACAC,IAAAA,UAAAA;AACAC,IAAAA,KAAAA;AACAC,IAAAA,OAAAA;AACAC,IAAAA,GAAAA;AACAgB,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,7 @@
1
+ import * as ts from 'typescript';
2
+ import type { Schema } from './utils';
3
+ /**
4
+ * Generate an interface declaration for a given schema
5
+ */
6
+ export declare const generateSchemaDefinition: (schema: Schema) => ts.InterfaceDeclaration;
7
+ //# 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;AAmCtC;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,QAAQ,MAAM,KAAG,EAAE,CAAC,oBAqC5D,CAAC"}
@@ -0,0 +1,79 @@
1
+ 'use strict';
2
+
3
+ var ts = require('typescript');
4
+ var _ = require('lodash/fp');
5
+ var utils = require('./utils.js');
6
+ var attributes = require('./attributes.js');
7
+ var imports = require('../imports.js');
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
+
29
+ const { factory } = ts__namespace;
30
+ /**
31
+ * Generate a property signature for the schema's `attributes` field
32
+ */ const generateAttributePropertySignature = (schema)=>{
33
+ const { attributes: attributes$1 } = schema;
34
+ const properties = Object.entries(attributes$1).sort((a, b)=>a[0].localeCompare(b[0])).map(([attributeName, attribute])=>{
35
+ return attributes.attributeToPropertySignature(schema, attributeName, attribute);
36
+ });
37
+ return factory.createPropertySignature(undefined, factory.createIdentifier('attributes'), undefined, factory.createTypeLiteralNode(properties));
38
+ };
39
+ const generatePropertyLiteralDefinitionFactory = (schema)=>(key)=>{
40
+ return factory.createPropertySignature(undefined, factory.createIdentifier(key), undefined, utils.toTypeLiteral(schema[key]));
41
+ };
42
+ /**
43
+ * Generate an interface declaration for a given schema
44
+ */ const generateSchemaDefinition = (schema)=>{
45
+ const { uid } = schema;
46
+ // Resolve the different interface names needed to declare the schema's interface
47
+ const interfaceName = utils.getSchemaInterfaceName(uid);
48
+ const parentType = utils.getSchemaExtendsTypeName(schema);
49
+ // Make sure the Struct namespace is imported
50
+ imports.addImport(utils.NAMESPACES.Struct);
51
+ // Properties whose values can be mapped to a literal type expression
52
+ const literalPropertiesDefinitions = [
53
+ 'collectionName',
54
+ 'info',
55
+ 'options',
56
+ 'pluginOptions'
57
+ ]// Ignore non-existent or empty declarations
58
+ .filter((key)=>!_.isEmpty(schema[key]))// Generate literal definition for each property
59
+ .map(generatePropertyLiteralDefinitionFactory(schema));
60
+ // Generate the `attributes` literal type definition
61
+ const attributesProp = generateAttributePropertySignature(schema);
62
+ // Merge every schema's definition in a single list
63
+ const schemaProperties = [
64
+ ...literalPropertiesDefinitions,
65
+ attributesProp
66
+ ];
67
+ // Generate the schema's interface declaration
68
+ const schemaType = factory.createInterfaceDeclaration([
69
+ factory.createModifier(ts__namespace.SyntaxKind.ExportKeyword)
70
+ ], factory.createIdentifier(interfaceName), undefined, [
71
+ factory.createHeritageClause(ts__namespace.SyntaxKind.ExtendsKeyword, [
72
+ factory.createIdentifier(parentType)
73
+ ])
74
+ ], schemaProperties);
75
+ return schemaType;
76
+ };
77
+
78
+ exports.generateSchemaDefinition = generateSchemaDefinition;
79
+ //# 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/fp';\n\nimport {\n getSchemaExtendsTypeName,\n getSchemaInterfaceName,\n toTypeLiteral,\n NAMESPACES,\n} from './utils';\nimport type { Schema } from './utils';\nimport { attributeToPropertySignature } from './attributes';\nimport { addImport } from '../imports';\n\nconst { factory } = ts;\n\n/**\n * Generate a property signature for the schema's `attributes` field\n */\nconst generateAttributePropertySignature = (schema: Schema): ts.PropertySignature => {\n const { attributes } = schema;\n\n const properties = Object.entries(attributes)\n .sort((a, b) => a[0].localeCompare(b[0]))\n .map(([attributeName, attribute]) => {\n return attributeToPropertySignature(schema, attributeName, attribute);\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 = (schema: Schema): ts.InterfaceDeclaration => {\n const { uid } = schema;\n\n // Resolve the different interface names needed to declare the schema's interface\n const interfaceName = getSchemaInterfaceName(uid);\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);\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","attributes","properties","Object","entries","sort","a","b","localeCompare","map","attributeName","attribute","attributeToPropertySignature","createPropertySignature","undefined","createIdentifier","createTypeLiteralNode","generatePropertyLiteralDefinitionFactory","key","toTypeLiteral","generateSchemaDefinition","uid","interfaceName","getSchemaInterfaceName","parentType","getSchemaExtendsTypeName","addImport","NAMESPACES","Struct","literalPropertiesDefinitions","filter","isEmpty","attributesProp","schemaProperties","schemaType","createInterfaceDeclaration","createModifier","SyntaxKind","ExportKeyword","createHeritageClause","ExtendsKeyword"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,MAAM,EAAEA,OAAO,EAAE,GAAGC,aAAAA;AAEpB;;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