@strapi/typescript-utils 5.56.0 → 5.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compilers/basic.js +2 -2
- package/dist/compilers/basic.js.map +1 -1
- package/dist/generators/common/models/attributes.js +8 -8
- package/dist/generators/common/models/attributes.js.map +1 -1
- package/dist/generators/common/models/attributes.mjs +8 -8
- package/dist/generators/common/models/attributes.mjs.map +1 -1
- package/dist/generators/common/models/mappers.d.ts.map +1 -1
- package/dist/generators/common/models/mappers.js +2 -2
- package/dist/generators/common/models/mappers.js.map +1 -1
- package/dist/generators/common/models/mappers.mjs +2 -2
- package/dist/generators/common/models/mappers.mjs.map +1 -1
- package/dist/generators/common/models/schema.js +1 -1
- package/dist/generators/common/models/schema.js.map +1 -1
- package/dist/generators/common/models/schema.mjs +1 -1
- package/dist/generators/common/models/schema.mjs.map +1 -1
- package/dist/generators/common/models/utils.d.ts.map +1 -1
- package/dist/generators/common/models/utils.js +5 -5
- package/dist/generators/common/models/utils.js.map +1 -1
- package/dist/generators/common/models/utils.mjs +5 -5
- package/dist/generators/common/models/utils.mjs.map +1 -1
- package/dist/generators/components/index.d.ts.map +1 -1
- package/dist/generators/components/index.js +3 -4
- package/dist/generators/components/index.js.map +1 -1
- package/dist/generators/components/index.mjs +3 -4
- package/dist/generators/components/index.mjs.map +1 -1
- package/dist/generators/content-types/index.d.ts.map +1 -1
- package/dist/generators/content-types/index.js +3 -4
- package/dist/generators/content-types/index.js.map +1 -1
- package/dist/generators/content-types/index.mjs +3 -4
- package/dist/generators/content-types/index.mjs.map +1 -1
- package/dist/utils/format-host.js +1 -1
- package/dist/utils/format-host.js.map +1 -1
- package/dist/utils/format-host.mjs +1 -1
- package/dist/utils/format-host.mjs.map +1 -1
- package/package.json +3 -3
package/dist/compilers/basic.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ts = require('typescript');
|
|
4
|
-
var
|
|
4
|
+
var _ = require('lodash');
|
|
5
5
|
var reportDiagnostics = require('../utils/report-diagnostics.js');
|
|
6
6
|
var resolveConfigOptions = require('../utils/resolve-config-options.js');
|
|
7
7
|
|
|
@@ -31,7 +31,7 @@ var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
|
|
|
31
31
|
const { ignoreDiagnostics = false } = configOptions;
|
|
32
32
|
// Parse the tsconfig.json file & resolve the configuration options
|
|
33
33
|
const { fileNames, options, projectReferences } = resolveConfigOptions.resolveConfigOptions(tsConfigPath);
|
|
34
|
-
const compilerOptions =
|
|
34
|
+
const compilerOptions = _.merge(options, configOptions.options);
|
|
35
35
|
if (ignoreDiagnostics) {
|
|
36
36
|
Object.assign(compilerOptions, {
|
|
37
37
|
noEmit: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basic.js","sources":["../../src/compilers/basic.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { merge } from 'lodash';\n\nimport { reportDiagnostics } from '../utils/report-diagnostics';\nimport { resolveConfigOptions } from '../utils/resolve-config-options';\n\nexport interface ConfigOptions {\n fileNames?: string[];\n options?: ts.CompilerOptions;\n ignoreDiagnostics?: boolean;\n}\n\n/**\n * Default TS -> JS Compilation for Strapi\n */\nexport function run(tsConfigPath: string, configOptions: ConfigOptions = {}) {\n const { ignoreDiagnostics = false } = configOptions;\n // Parse the tsconfig.json file & resolve the configuration options\n const { fileNames, options, projectReferences } = resolveConfigOptions(tsConfigPath);\n\n const compilerOptions = merge(options, configOptions.options);\n\n if (ignoreDiagnostics) {\n Object.assign(compilerOptions, { noEmit: false, noEmitOnError: false });\n }\n\n const program = ts.createProgram({\n rootNames: configOptions.fileNames ? configOptions.fileNames : fileNames,\n projectReferences,\n options: compilerOptions,\n });\n\n const emitResults = program.emit();\n\n const diagnostics = ts.sortAndDeduplicateDiagnostics(\n ts.getPreEmitDiagnostics(program).concat(emitResults.diagnostics)\n );\n\n if (!ignoreDiagnostics && diagnostics.length > 0) {\n reportDiagnostics(diagnostics);\n }\n\n // If the compilation failed and diagnostics are not ignored, exit early\n if (!ignoreDiagnostics && emitResults.emitSkipped) {\n throw new Error('TypeScript compilation failed');\n }\n}\n"],"names":["run","tsConfigPath","configOptions","ignoreDiagnostics","fileNames","options","projectReferences","resolveConfigOptions","compilerOptions","merge","Object","assign","noEmit","noEmitOnError","program","ts","createProgram","rootNames","emitResults","emit","diagnostics","sortAndDeduplicateDiagnostics","getPreEmitDiagnostics","concat","length","reportDiagnostics","emitSkipped","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA;;AAEC,IACM,SAASA,GAAAA,CAAIC,YAAoB,EAAEC,aAAAA,GAA+B,EAAE,EAAA;AACzE,IAAA,MAAM,EAAEC,iBAAAA,GAAoB,KAAK,EAAE,GAAGD,aAAAA;;IAEtC,MAAM,EAAEE,SAAS,EAAEC,OAAO,EAAEC,iBAAiB,EAAE,GAAGC,yCAAAA,CAAqBN,YAAAA,CAAAA;AAEvE,IAAA,MAAMO,eAAAA,GAAkBC,
|
|
1
|
+
{"version":3,"file":"basic.js","sources":["../../src/compilers/basic.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { merge } from 'lodash';\n\nimport { reportDiagnostics } from '../utils/report-diagnostics';\nimport { resolveConfigOptions } from '../utils/resolve-config-options';\n\nexport interface ConfigOptions {\n fileNames?: string[];\n options?: ts.CompilerOptions;\n ignoreDiagnostics?: boolean;\n}\n\n/**\n * Default TS -> JS Compilation for Strapi\n */\nexport function run(tsConfigPath: string, configOptions: ConfigOptions = {}) {\n const { ignoreDiagnostics = false } = configOptions;\n // Parse the tsconfig.json file & resolve the configuration options\n const { fileNames, options, projectReferences } = resolveConfigOptions(tsConfigPath);\n\n const compilerOptions = merge(options, configOptions.options);\n\n if (ignoreDiagnostics) {\n Object.assign(compilerOptions, { noEmit: false, noEmitOnError: false });\n }\n\n const program = ts.createProgram({\n rootNames: configOptions.fileNames ? configOptions.fileNames : fileNames,\n projectReferences,\n options: compilerOptions,\n });\n\n const emitResults = program.emit();\n\n const diagnostics = ts.sortAndDeduplicateDiagnostics(\n ts.getPreEmitDiagnostics(program).concat(emitResults.diagnostics)\n );\n\n if (!ignoreDiagnostics && diagnostics.length > 0) {\n reportDiagnostics(diagnostics);\n }\n\n // If the compilation failed and diagnostics are not ignored, exit early\n if (!ignoreDiagnostics && emitResults.emitSkipped) {\n throw new Error('TypeScript compilation failed');\n }\n}\n"],"names":["run","tsConfigPath","configOptions","ignoreDiagnostics","fileNames","options","projectReferences","resolveConfigOptions","compilerOptions","merge","Object","assign","noEmit","noEmitOnError","program","ts","createProgram","rootNames","emitResults","emit","diagnostics","sortAndDeduplicateDiagnostics","getPreEmitDiagnostics","concat","length","reportDiagnostics","emitSkipped","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA;;AAEC,IACM,SAASA,GAAAA,CAAIC,YAAoB,EAAEC,aAAAA,GAA+B,EAAE,EAAA;AACzE,IAAA,MAAM,EAAEC,iBAAAA,GAAoB,KAAK,EAAE,GAAGD,aAAAA;;IAEtC,MAAM,EAAEE,SAAS,EAAEC,OAAO,EAAEC,iBAAiB,EAAE,GAAGC,yCAAAA,CAAqBN,YAAAA,CAAAA;AAEvE,IAAA,MAAMO,eAAAA,GAAkBC,OAAAA,CAAMJ,OAAAA,EAASH,aAAAA,CAAcG,OAAO,CAAA;AAE5D,IAAA,IAAIF,iBAAAA,EAAmB;QACrBO,MAAAA,CAAOC,MAAM,CAACH,eAAAA,EAAiB;YAAEI,MAAAA,EAAQ,KAAA;YAAOC,aAAAA,EAAe;AAAM,SAAA,CAAA;AACvE,IAAA;IAEA,MAAMC,OAAAA,GAAUC,aAAAA,CAAGC,aAAa,CAAC;AAC/BC,QAAAA,SAAAA,EAAWf,aAAAA,CAAcE,SAAS,GAAGF,aAAAA,CAAcE,SAAS,GAAGA,SAAAA;AAC/DE,QAAAA,iBAAAA;QACAD,OAAAA,EAASG;AACX,KAAA,CAAA;IAEA,MAAMU,WAAAA,GAAcJ,QAAQK,IAAI,EAAA;IAEhC,MAAMC,WAAAA,GAAcL,aAAAA,CAAGM,6BAA6B,CAClDN,aAAAA,CAAGO,qBAAqB,CAACR,OAAAA,CAAAA,CAASS,MAAM,CAACL,WAAAA,CAAYE,WAAW,CAAA,CAAA;AAGlE,IAAA,IAAI,CAACjB,iBAAAA,IAAqBiB,WAAAA,CAAYI,MAAM,GAAG,CAAA,EAAG;QAChDC,mCAAAA,CAAkBL,WAAAA,CAAAA;AACpB,IAAA;;AAGA,IAAA,IAAI,CAACjB,iBAAAA,IAAqBe,WAAAA,CAAYQ,WAAW,EAAE;AACjD,QAAA,MAAM,IAAIC,KAAAA,CAAM,+BAAA,CAAA;AAClB,IAAA;AACF;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ts = require('typescript');
|
|
4
|
-
var _ = require('lodash
|
|
4
|
+
var _ = require('lodash');
|
|
5
5
|
var imports = require('../imports.js');
|
|
6
6
|
var utils = require('./utils.js');
|
|
7
7
|
var mappers = require('./mappers.js');
|
|
@@ -85,11 +85,11 @@ const { factory } = ts__namespace;
|
|
|
85
85
|
]));
|
|
86
86
|
}
|
|
87
87
|
// Min / Max
|
|
88
|
-
if (
|
|
89
|
-
const minMaxProperties = ___default.default.pick([
|
|
88
|
+
if (attribute.min != null || attribute.max != null) {
|
|
89
|
+
const minMaxProperties = ___default.default.pick(attribute, [
|
|
90
90
|
'min',
|
|
91
91
|
'max'
|
|
92
|
-
]
|
|
92
|
+
]);
|
|
93
93
|
const { min, max } = minMaxProperties;
|
|
94
94
|
const typeofMin = typeof min;
|
|
95
95
|
const typeofMax = typeof max;
|
|
@@ -112,17 +112,17 @@ const { factory } = ts__namespace;
|
|
|
112
112
|
]));
|
|
113
113
|
}
|
|
114
114
|
// Min length / Max length
|
|
115
|
-
if (
|
|
116
|
-
const minMaxProperties = ___default.default.pick([
|
|
115
|
+
if (attribute.minLength != null || attribute.maxLength != null) {
|
|
116
|
+
const minMaxProperties = ___default.default.pick(attribute, [
|
|
117
117
|
'minLength',
|
|
118
118
|
'maxLength'
|
|
119
|
-
]
|
|
119
|
+
]);
|
|
120
120
|
modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(utils.withAttributeNamespace('SetMinMaxLength')), [
|
|
121
121
|
utils.toTypeLiteral(minMaxProperties)
|
|
122
122
|
]));
|
|
123
123
|
}
|
|
124
124
|
// Default (ignore if default is a function)
|
|
125
|
-
if (
|
|
125
|
+
if (attribute.default != null && typeof attribute.default !== 'function') {
|
|
126
126
|
const defaultLiteral = utils.toTypeLiteral(attribute.default);
|
|
127
127
|
modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(utils.withAttributeNamespace('DefaultTo')), [
|
|
128
128
|
defaultLiteral
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.js","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","createPropertySignature","createIntersectionTypeNode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,EAAEA,OAAO,EAAE,GAAGC,aAAAA;AAEpB;;AAEC,IACM,MAAMC,gBAAAA,GAAmB,CAC9BC,eACAC,SAAAA,EACAC,GAAAA,GAAAA;IAEA,IAAI,CAACC,OAAOC,IAAI,CAACC,iBAASC,QAAQ,CAACL,SAAAA,CAAUM,IAAI,CAAA,EAAG;AAClDC,QAAAA,OAAAA,CAAQC,IAAI,CACV,CAAC,CAAC,EAAET,aAAAA,CAAc,kBAAkB,EAAEE,GAAAA,CAAI,wBAAwB,EAAED,SAAAA,CAAUM,IAAI,CAAC,CAAC,CAAC,CAAA;QAGvF,OAAO,IAAA;AACT,IAAA;IAEA,MAAM,CAACG,eAAeC,UAAAA,CAAW,GAAGN,eAAO,CAACJ,SAAAA,CAAUM,IAAI,CAAC,CAAC;AAAEL,QAAAA,GAAAA;AAAKD,QAAAA,SAAAA;AAAWD,QAAAA;AAAc,KAAA,CAAA;;AAG5FY,IAAAA,iBAAAA,CAAUC,iBAAWC,MAAM,CAAA;AAE3B,IAAA,OAAOC,kBAAYL,aAAAA,EAAeC,UAAAA,CAAAA;AACpC;AAEA;;IAGO,MAAMK,qBAAAA,GAAwB,CAACf,SAAAA,GAAAA;AACpC,IAAA,MAAMgB,YAA2B,EAAE;;IAGnC,IAAIhB,SAAAA,CAAUiB,QAAQ,EAAE;QACtBD,SAAAA,CAAUE,IAAI,CACZtB,OAAAA,CAAQuB,uBAAuB,CAACvB,OAAAA,CAAQwB,gBAAgB,CAACC,4BAAAA,CAAuB,UAAA,CAAA,CAAA,CAAA,CAAA;AAEpF,IAAA;;IAGA,IAAIrB,SAAAA,CAAUsB,OAAO,EAAE;QACrBN,SAAAA,CAAUE,IAAI,CACZtB,OAAAA,CAAQuB,uBAAuB,CAACvB,OAAAA,CAAQwB,gB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AAAA,CAAiBC,aAAAA,EAAeC,SAAAA,EAAWsD,OAAOrD,GAAG,CAAA;AAEtE,IAAA,IAAIsD,aAAa,IAAA,EAAM;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;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"attributes.js","sources":["../../../../src/generators/common/models/attributes.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport _ from 'lodash';\n\nimport { addImport } from '../imports';\nimport { getTypeNode, toTypeLiteral, withAttributeNamespace, NAMESPACES } from './utils';\nimport type { Attribute, Schema } from './utils';\nimport { mappers } from './mappers';\n\nconst { factory } = ts;\n\n/**\n * Create the base type node for a given attribute\n */\nexport const getAttributeType = (\n attributeName: string,\n attribute: Attribute,\n uid?: string\n): ts.TypeReferenceNode | null => {\n if (!Object.keys(mappers).includes(attribute.type)) {\n console.warn(\n `\"${attributeName}\" attribute from \"${uid}\" has an invalid type: \"${attribute.type}\"`\n );\n\n return null;\n }\n\n const [attributeType, typeParams] = mappers[attribute.type]({ uid, attribute, attributeName });\n\n // Make sure the schema namespace is imported\n addImport(NAMESPACES.Schema);\n\n return getTypeNode(attributeType, typeParams);\n};\n\n/**\n * 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 (attribute.min != null || attribute.max != null) {\n const minMaxProperties = _.pick(attribute, ['min', 'max']);\n const { min, max } = minMaxProperties;\n\n const typeofMin = typeof min;\n const typeofMax = typeof max;\n\n // Throws error if min/max exist but have different types to prevent unexpected behavior\n if (min !== undefined && max !== undefined && typeofMin !== typeofMax) {\n throw new Error('typeof min/max values mismatch');\n }\n\n let typeKeyword: any;\n\n // use 'string'\n if (typeofMin === 'string' || typeofMax === 'string') {\n typeKeyword = ts.SyntaxKind.StringKeyword;\n }\n // use 'number'\n else if (typeofMin === 'number' || typeofMax === 'number') {\n typeKeyword = ts.SyntaxKind.NumberKeyword;\n }\n // invalid type\n else {\n throw new Error(\n `Invalid data type for min/max options. Must be string, number or undefined, but found { min: ${min} (${typeofMin}), max: ${max} (${typeofMax}) }`\n );\n }\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('SetMinMax')),\n [toTypeLiteral(minMaxProperties), factory.createKeywordTypeNode(typeKeyword)]\n )\n );\n }\n\n // Min length / Max length\n if (attribute.minLength != null || attribute.maxLength != null) {\n const minMaxProperties = _.pick(attribute, ['minLength', 'maxLength']);\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('SetMinMaxLength')),\n [toTypeLiteral(minMaxProperties)]\n )\n );\n }\n\n // Default (ignore if default is a function)\n if (attribute.default != null && typeof attribute.default !== 'function') {\n const defaultLiteral = toTypeLiteral(attribute.default);\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('DefaultTo')),\n [defaultLiteral]\n )\n );\n }\n\n return modifiers;\n};\n\n/**\n * 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","min","max","minMaxProperties","pick","typeofMin","typeofMax","undefined","Error","typeKeyword","SyntaxKind","StringKeyword","NumberKeyword","createKeywordTypeNode","minLength","maxLength","default","defaultLiteral","attributeToPropertySignature","schema","baseType","nodes","createPropertySignature","createIntersectionTypeNode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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C,OAAOpB,OAAAA,CAAQ2D,uBAAuB,CACpCf,SAAAA,EACA5C,OAAAA,CAAQwB,gBAAgB,CAACrB,aAAAA,CAAAA,EACzByC,SAAAA,EACA5C,OAAAA,CAAQ4D,0BAA0B,CAACF,KAAAA,CAAAA,CAAAA;AAEvC;;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
|
-
import _ from 'lodash
|
|
2
|
+
import _ from 'lodash';
|
|
3
3
|
import { addImport } from '../imports.mjs';
|
|
4
4
|
import { getTypeNode, withAttributeNamespace, toTypeLiteral, NAMESPACES } from './utils.mjs';
|
|
5
5
|
import { mappers } from './mappers.mjs';
|
|
@@ -60,11 +60,11 @@ const { factory } = ts;
|
|
|
60
60
|
]));
|
|
61
61
|
}
|
|
62
62
|
// Min / Max
|
|
63
|
-
if (
|
|
64
|
-
const minMaxProperties = _.pick([
|
|
63
|
+
if (attribute.min != null || attribute.max != null) {
|
|
64
|
+
const minMaxProperties = _.pick(attribute, [
|
|
65
65
|
'min',
|
|
66
66
|
'max'
|
|
67
|
-
]
|
|
67
|
+
]);
|
|
68
68
|
const { min, max } = minMaxProperties;
|
|
69
69
|
const typeofMin = typeof min;
|
|
70
70
|
const typeofMax = typeof max;
|
|
@@ -87,17 +87,17 @@ const { factory } = ts;
|
|
|
87
87
|
]));
|
|
88
88
|
}
|
|
89
89
|
// Min length / Max length
|
|
90
|
-
if (
|
|
91
|
-
const minMaxProperties = _.pick([
|
|
90
|
+
if (attribute.minLength != null || attribute.maxLength != null) {
|
|
91
|
+
const minMaxProperties = _.pick(attribute, [
|
|
92
92
|
'minLength',
|
|
93
93
|
'maxLength'
|
|
94
|
-
]
|
|
94
|
+
]);
|
|
95
95
|
modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('SetMinMaxLength')), [
|
|
96
96
|
toTypeLiteral(minMaxProperties)
|
|
97
97
|
]));
|
|
98
98
|
}
|
|
99
99
|
// Default (ignore if default is a function)
|
|
100
|
-
if (
|
|
100
|
+
if (attribute.default != null && typeof attribute.default !== 'function') {
|
|
101
101
|
const defaultLiteral = toTypeLiteral(attribute.default);
|
|
102
102
|
modifiers.push(factory.createTypeReferenceNode(factory.createIdentifier(withAttributeNamespace('DefaultTo')), [
|
|
103
103
|
defaultLiteral
|
|
@@ -1 +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","createPropertySignature","createIntersectionTypeNode"],"mappings":";;;;;;AAQA,MAAM,EAAEA,OAAO,EAAE,GAAGC,EAAAA;AAEpB;;AAEC,IACM,MAAMC,gBAAAA,GAAmB,CAC9BC,eACAC,SAAAA,EACAC,GAAAA,GAAAA;IAEA,IAAI,CAACC,OAAOC,IAAI,CAACC,SAASC,QAAQ,CAACL,SAAAA,CAAUM,IAAI,CAAA,EAAG;AAClDC,QA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ACrB,aAAAA,CAAAA,EACzB0C,SAAAA,EACA7C,OAAAA,CAAQ8D,0BAA0B,CAACF,KAAAA,CAAAA,CAAAA;AAEvC;;;;"}
|
|
1
|
+
{"version":3,"file":"attributes.mjs","sources":["../../../../src/generators/common/models/attributes.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport _ from 'lodash';\n\nimport { addImport } from '../imports';\nimport { getTypeNode, toTypeLiteral, withAttributeNamespace, NAMESPACES } from './utils';\nimport type { Attribute, Schema } from './utils';\nimport { mappers } from './mappers';\n\nconst { factory } = ts;\n\n/**\n * Create the base type node for a given attribute\n */\nexport const getAttributeType = (\n attributeName: string,\n attribute: Attribute,\n uid?: string\n): ts.TypeReferenceNode | null => {\n if (!Object.keys(mappers).includes(attribute.type)) {\n console.warn(\n `\"${attributeName}\" attribute from \"${uid}\" has an invalid type: \"${attribute.type}\"`\n );\n\n return null;\n }\n\n const [attributeType, typeParams] = mappers[attribute.type]({ uid, attribute, attributeName });\n\n // Make sure the schema namespace is imported\n addImport(NAMESPACES.Schema);\n\n return getTypeNode(attributeType, typeParams);\n};\n\n/**\n * 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 (attribute.min != null || attribute.max != null) {\n const minMaxProperties = _.pick(attribute, ['min', 'max']);\n const { min, max } = minMaxProperties;\n\n const typeofMin = typeof min;\n const typeofMax = typeof max;\n\n // Throws error if min/max exist but have different types to prevent unexpected behavior\n if (min !== undefined && max !== undefined && typeofMin !== typeofMax) {\n throw new Error('typeof min/max values mismatch');\n }\n\n let typeKeyword: any;\n\n // use 'string'\n if (typeofMin === 'string' || typeofMax === 'string') {\n typeKeyword = ts.SyntaxKind.StringKeyword;\n }\n // use 'number'\n else if (typeofMin === 'number' || typeofMax === 'number') {\n typeKeyword = ts.SyntaxKind.NumberKeyword;\n }\n // invalid type\n else {\n throw new Error(\n `Invalid data type for min/max options. Must be string, number or undefined, but found { min: ${min} (${typeofMin}), max: ${max} (${typeofMax}) }`\n );\n }\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('SetMinMax')),\n [toTypeLiteral(minMaxProperties), factory.createKeywordTypeNode(typeKeyword)]\n )\n );\n }\n\n // Min length / Max length\n if (attribute.minLength != null || attribute.maxLength != null) {\n const minMaxProperties = _.pick(attribute, ['minLength', 'maxLength']);\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('SetMinMaxLength')),\n [toTypeLiteral(minMaxProperties)]\n )\n );\n }\n\n // Default (ignore if default is a function)\n if (attribute.default != null && typeof attribute.default !== 'function') {\n const defaultLiteral = toTypeLiteral(attribute.default);\n\n modifiers.push(\n factory.createTypeReferenceNode(\n factory.createIdentifier(withAttributeNamespace('DefaultTo')),\n [defaultLiteral]\n )\n );\n }\n\n return modifiers;\n};\n\n/**\n * 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","min","max","minMaxProperties","pick","typeofMin","typeofMax","undefined","Error","typeKeyword","SyntaxKind","StringKeyword","NumberKeyword","createKeywordTypeNode","minLength","maxLength","default","defaultLiteral","attributeToPropertySignature","schema","baseType","nodes","createPropertySignature","createIntersectionTypeNode"],"mappings":";;;;;;AAQA,MAAM,EAAEA,OAAO,EAAE,GAAGC,EAAAA;AAEpB;;AAEC,IACM,MAAMC,gBAAAA,GAAmB,CAC9BC,eACAC,SAAAA,EACAC,GAAAA,GAAAA;IAEA,IAAI,CAACC,OAAOC,IAAI,CAACC,SAASC,QAAQ,CAACL,SAAAA,CAAUM,IAAI,CAAA,EAAG;AAClDC,QAAAA,OAAAA,CAAQC,IAAI,CACV,CAAC,CAAC,EAAET,aAAAA,CAAc,kBAAkB,EAAEE,GAAAA,CAAI,wBAAwB,EAAED,SAAAA,CAAUM,IAAI,CAAC,CAAC,CAAC,CAAA;QAGvF,OAAO,IAAA;A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AC;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;
|
|
1
|
+
{"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../../../../src/generators/common/models/mappers.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIzC,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,aAAa,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;AA8J5E,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAuB1C,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ts = require('typescript');
|
|
4
|
-
var _ = require('lodash
|
|
4
|
+
var _ = require('lodash');
|
|
5
5
|
var utils = require('./utils.js');
|
|
6
6
|
|
|
7
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -104,7 +104,7 @@ function uid({ attribute }) {
|
|
|
104
104
|
const params = [];
|
|
105
105
|
// If the targetField property is defined, then reference it,
|
|
106
106
|
// otherwise, put `undefined` keyword type node as placeholder
|
|
107
|
-
const targetFieldParam =
|
|
107
|
+
const targetFieldParam = targetField === undefined ? factory.createKeywordTypeNode(ts__namespace.SyntaxKind.UndefinedKeyword) : factory.createStringLiteral(targetField);
|
|
108
108
|
params.push(targetFieldParam);
|
|
109
109
|
// If the options property is defined, transform it to
|
|
110
110
|
// a type literal node and add it to the params list
|
|
@@ -1 +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;QAACL,4BAAAA,CAAuB,MAAA;AAAQ,KAAA;AACzC;AAEA,SAASM,IAAAA,GAAAA;IACP,OAAO;QAACN,4BAAAA,CAAuB,MAAA;AAAQ,KAAA;AACzC;AAEA,SAASO,QAAAA,GAAAA;IACP,OAAO;QAACP,4BAAAA,CAAuB,UAAA;AAAY,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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;;;;"}
|
|
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","dynamiczone","componentsParam","createTupleTypeNode","components","c","mappers"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,EAAEA,OAAO,EAAE,GAAGC,aAAAA;AAUpB,SAASC,MAAAA,GAAAA;IACP,OAAO;Q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AM,IAAAA,SAAAA;AACAG,IAAAA;AACF;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
|
-
import _ from 'lodash
|
|
2
|
+
import _ from 'lodash';
|
|
3
3
|
import { withAttributeNamespace, toTypeLiteral } from './utils.mjs';
|
|
4
4
|
|
|
5
5
|
const { factory } = ts;
|
|
@@ -79,7 +79,7 @@ function uid({ attribute }) {
|
|
|
79
79
|
const params = [];
|
|
80
80
|
// If the targetField property is defined, then reference it,
|
|
81
81
|
// otherwise, put `undefined` keyword type node as placeholder
|
|
82
|
-
const targetFieldParam =
|
|
82
|
+
const targetFieldParam = targetField === undefined ? factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword) : factory.createStringLiteral(targetField);
|
|
83
83
|
params.push(targetFieldParam);
|
|
84
84
|
// If the options property is defined, transform it to
|
|
85
85
|
// a type literal node and add it to the params list
|
|
@@ -1 +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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ources":["../../../../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,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;AAAQ,KAAA;AACzC;AAEA,SAASO,QAAAA,GAAAA;IACP,OAAO;QAACP,sBAAAA,CAAuB,UAAA;AAAY,KAAA;AAC7C;AAEA,SAASQ,SAAAA,GAAAA;IACP,OAAO;QAACR,sBAAAA,CAAuB,WAAA;AAAa,KAAA;AAC9C;AAEA,SAASS,OAA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AAAgB,QAAA;AAACoD,YAAAA;AAAgB;AAAC,KAAA;AACnE;MAEaI,OAAAA,GAAkC;AAC7CzD,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;AACAe,IAAAA,WAAAA;AACAG,IAAAA,OAAAA;AACAC,IAAAA,IAAAA;AACAC,IAAAA,MAAAA;AACAC,IAAAA,KAAAA;AACAQ,IAAAA,QAAAA;AACAM,IAAAA,SAAAA;AACAG,IAAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sources":["../../../../src/generators/common/models/schema.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { isEmpty } from 'lodash
|
|
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 { 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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C,MAAM,CAAA;;AAG3B,IAAA,MAAMC,4BAAAA,GAA+B;AAAC,QAAA,gBAAA;AAAkB,QAAA,MAAA;AAAQ,QAAA,SAAA;AAAW,QAAA;AAAgB,KACzF;KACCC,MAAM,CAAC,CAACZ,GAAAA,GAAQ,CAACa,UAAQ/B,MAAM,CAACkB,GAAAA,CAAI,CAAA,CACrC;AACCT,KAAAA,GAAG,CAACQ,wCAAAA,CAAyCjB,MAAAA,CAAAA,CAAAA;;AAGhD,IAAA,MAAMgC,iBAAiBjC,kCAAAA,CAAmCC,MAAAA,CAAAA;;AAG1D,IAAA,MAAMiC,gBAAAA,GAAmB;AAAIJ,QAAAA,GAAAA,4BAAAA;AAA8BG,QAAAA;AAAe,KAAA;;IAG1E,MAAME,UAAAA,GAAarC,OAAAA,CAAQsC,0BAA0B,CACnD;AAACtC,QAAAA,OAAAA,CAAQuC,cAAc,CAACtC,aAAAA,CAAGuC,UAAU,CAACC,aAAa;AAAE,KAAA,EACrDzC,OAAAA,CAAQkB,gBAAgB,CAACO,aAAAA,CAAAA,EACzBR,SAAAA,EACA;AACEjB,QAAAA,OAAAA,CAAQ0C,oBAAoB,CAACzC,aAAAA,CAAGuC,UAAU,CAACG,cAAc,EAAE;AACzD3C,YAAAA,OAAAA,CAAQkB,gBAAgB,CAACS,UAAAA;AAC1B,SAAA;KACF,EACDS,gBAAAA,CAAAA;IAGF,OAAOC,UAAAA;AACT;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
|
-
import { isEmpty } from 'lodash
|
|
2
|
+
import { isEmpty } from 'lodash';
|
|
3
3
|
import { getSchemaInterfaceName, getSchemaExtendsTypeName, toTypeLiteral, NAMESPACES } from './utils.mjs';
|
|
4
4
|
import { attributeToPropertySignature } from './attributes.mjs';
|
|
5
5
|
import { addImport } from '../imports.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.mjs","sources":["../../../../src/generators/common/models/schema.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { isEmpty } from 'lodash
|
|
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 { 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,EAAAA;AAEpB;;IAGA,MAAMC,qCAAqC,CAACC,MAAAA,GAAAA;IAC1C,MAAM,EAAEC,UAAU,EAAE,GAAGD,MAAAA;IAEvB,MAAME,UAAAA,GAAaC,MAAAA,CAAOC,OAAO,CAACH,UAAAA,CAAAA,CAC/BI,IAAI,CAAC,CAACC,CAAAA,EAAGC,CAAAA,GAAMD,CAAC,CAAC,EAAE,CAACE,aAAa,CAACD,CAAC,CAAC,CAAA,CAAE,CAAA,CAAA,CACtCE,GAAG,CAAC,CAAC,CAACC,aAAAA,EAAeC,SAAAA,CAAU,GAAA;QAC9B,OAAOC,4BAAAA,CAA6BZ,QAAQU,aAAAA,EAAeC,SAAAA,CAAAA;AAC7D,IAAA,CAAA,CAAA;IAEF,OAAOd,OAAAA,CAAQgB,uBAAuB,CACpCC,SAAAA,EACAjB,OAAAA,CAAQkB,gBAAgB,CAAC,YAAA,CAAA,EACzBD,SAAAA,EACAjB,OAAAA,CAA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B,CAACO,aAAAA,CAAAA,EACzBR,SAAAA,EACA;AACEjB,QAAAA,OAAAA,CAAQ0C,oBAAoB,CAACzC,EAAAA,CAAGuC,UAAU,CAACG,cAAc,EAAE;AACzD3C,YAAAA,OAAAA,CAAQkB,gBAAgB,CAACS,UAAAA;AAC1B,SAAA;KACF,EACDS,gBAAAA,CAAAA;IAGF,OAAOC,UAAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/generators/common/models/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/generators/common/models/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAajC,eAAO,MAAM,UAAU;;;CAGtB,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACtC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAI,KAAK,MAAM,KAAG,MACJ,CAAC;AAElD,eAAO,MAAM,kBAAkB,GAAI,QAAQ,MAAM,KAAG,MAAM,GAAG,IAAI,GAAG,SAcnE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,QAAQ,MAAM,KAAG,MAAM,GAAG,IAQlE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,MAAM,EAAE,SAAQ,EAAE,CAAC,QAAQ,EAAO,KAAG,EAAE,CAAC,iBAE7E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,GAAG,KAAG,GA2DzC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,4BAA4B,GACvC,YAAY,EAAE,CAAC,oBAAoB,KAClC,MAAM,GAAG,IAUX,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAI,UAAU,MAAM,KAAG,MACZ,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,UAAU,MAAM,KAAG,MACV,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ts = require('typescript');
|
|
4
|
-
var _ = require('lodash
|
|
4
|
+
var _ = require('lodash');
|
|
5
5
|
|
|
6
6
|
function _interopNamespace(e) {
|
|
7
7
|
if (e && e.__esModule) return e;
|
|
@@ -30,7 +30,7 @@ const NAMESPACES = {
|
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
32
|
* Extract a valid interface name from a schema uid
|
|
33
|
-
*/ const getSchemaInterfaceName = _.
|
|
33
|
+
*/ const getSchemaInterfaceName = (uid)=>_.upperFirst(_.camelCase(uid.replace(/(:.)/, ' ')));
|
|
34
34
|
const getSchemaModelType = (schema)=>{
|
|
35
35
|
const { modelType, kind } = schema;
|
|
36
36
|
// Components
|
|
@@ -60,10 +60,10 @@ const getSchemaModelType = (schema)=>{
|
|
|
60
60
|
/**
|
|
61
61
|
* Transform a regular JavaScript object or scalar value into a literal expression
|
|
62
62
|
*/ const toTypeLiteral = (data)=>{
|
|
63
|
-
if (
|
|
63
|
+
if (data === undefined) {
|
|
64
64
|
return factory.createLiteralTypeNode(ts__namespace.SyntaxKind.UndefinedKeyword);
|
|
65
65
|
}
|
|
66
|
-
if (
|
|
66
|
+
if (data === null) {
|
|
67
67
|
return factory.createLiteralTypeNode(ts__namespace.SyntaxKind.NullKeyword);
|
|
68
68
|
}
|
|
69
69
|
if (_.isString(data)) {
|
|
@@ -75,7 +75,7 @@ const getSchemaModelType = (schema)=>{
|
|
|
75
75
|
if (_.isBoolean(data)) {
|
|
76
76
|
return data ? factory.createTrue() : factory.createFalse();
|
|
77
77
|
}
|
|
78
|
-
if (
|
|
78
|
+
if (Array.isArray(data)) {
|
|
79
79
|
return factory.createTupleTypeNode(data.map((item)=>toTypeLiteral(item)));
|
|
80
80
|
}
|
|
81
81
|
if (_.isDate(data)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../src/generators/common/models/utils.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport {\n
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/generators/common/models/utils.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport {\n camelCase,\n isBoolean,\n isDate,\n isNumber,\n isString,\n matchesProperty,\n upperFirst,\n} from 'lodash';\n\nconst { factory } = ts;\n\nexport const NAMESPACES = {\n Struct: 'Struct',\n Schema: 'Schema',\n};\n\n/**\n * Shallow representation of a content-type/component attribute definition.\n * Only the fields read by the generators are typed; the rest is left open.\n */\nexport interface Attribute {\n type: string;\n [key: string]: any;\n}\n\n/**\n * Shallow representation of a content-type/component schema definition.\n * Only the fields read by the generators are typed; the rest is left open.\n */\nexport interface Schema {\n uid: string;\n modelType?: string;\n kind?: string;\n attributes: Record<string, Attribute>;\n [key: string]: any;\n}\n\n/**\n * Extract a valid interface name from a schema uid\n */\nexport const getSchemaInterfaceName = (uid: string): string =>\n upperFirst(camelCase(uid.replace(/(:.)/, ' ')));\n\nexport const getSchemaModelType = (schema: Schema): string | null | undefined => {\n const { modelType, kind } = schema;\n\n // Components\n if (modelType === 'component') {\n return 'component';\n }\n\n // Content-Types\n if (modelType === 'contentType') {\n return kind;\n }\n\n return null;\n};\n\n/**\n * Get the parent type name to extend based on the schema's nature\n */\nexport const getSchemaExtendsTypeName = (schema: Schema): string | null => {\n const base = getSchemaModelType(schema);\n\n if (base === null) {\n return null;\n }\n\n return `${NAMESPACES.Struct}.${upperFirst(base as string)}Schema`;\n};\n\n/**\n * Get a type node based on a type and its params\n */\nexport const getTypeNode = (typeName: string, params: ts.TypeNode[] = []): ts.TypeReferenceNode => {\n return factory.createTypeReferenceNode(factory.createIdentifier(typeName), params);\n};\n\n/**\n * Transform a regular JavaScript object or scalar value into a literal expression\n */\nexport const toTypeLiteral = (data: any): any => {\n if (data === undefined) {\n return factory.createLiteralTypeNode(ts.SyntaxKind.UndefinedKeyword as any);\n }\n\n if (data === null) {\n return factory.createLiteralTypeNode(ts.SyntaxKind.NullKeyword as any);\n }\n\n if (isString(data)) {\n return factory.createStringLiteral(data, true);\n }\n\n if (isNumber(data)) {\n return data < 0\n ? factory.createPrefixUnaryExpression(\n ts.SyntaxKind.MinusToken,\n factory.createNumericLiteral(-data)\n )\n : factory.createNumericLiteral(data);\n }\n\n if (isBoolean(data)) {\n return data ? factory.createTrue() : factory.createFalse();\n }\n\n if (Array.isArray(data)) {\n return factory.createTupleTypeNode(data.map((item) => toTypeLiteral(item)));\n }\n\n if (isDate(data)) {\n return factory.createStringLiteral(data.toISOString());\n }\n\n if (typeof data !== 'object') {\n throw new Error(`Cannot convert to object literal. Unknown type \"${typeof data}\"`);\n }\n\n const entries = Object.entries(data).sort((a, b) => a[0].localeCompare(b[0]));\n\n const props = entries.reduce<any[]>((acc, [key, value]) => {\n // Handle keys such as content-type-builder & co.\n const identifier = key.includes('-')\n ? factory.createStringLiteral(key, true)\n : factory.createIdentifier(key);\n\n return [\n ...acc,\n factory.createPropertyDeclaration(\n undefined,\n identifier,\n undefined,\n toTypeLiteral(value),\n undefined\n ),\n ];\n }, []);\n\n return factory.createTypeLiteralNode(props);\n};\n\n/**\n * Get the number of attributes generated for a given schema definition\n */\nexport const getDefinitionAttributesCount = (\n definition: ts.InterfaceDeclaration\n): number | null => {\n const attributesNode = definition.members.find(\n matchesProperty('name.escapedText', 'attributes')\n ) as any;\n\n if (!attributesNode) {\n return null;\n }\n\n return attributesNode.type.members.length;\n};\n\n/**\n * Add the Schema.Attribute namespace before the typename\n */\nexport const withAttributeNamespace = (typeName: string): string =>\n `${NAMESPACES.Schema}.Attribute.${typeName}`;\n\n/**\n * Add the schema namespace before the typename\n */\nexport const withSchemaNamespace = (typeName: string): string =>\n `${(NAMESPACES as any).schema}.${typeName}`;\n"],"names":["factory","ts","NAMESPACES","Struct","Schema","getSchemaInterfaceName","uid","upperFirst","camelCase","replace","getSchemaModelType","schema","modelType","kind","getSchemaExtendsTypeName","base","getTypeNode","typeName","params","createTypeReferenceNode","createIdentifier","toTypeLiteral","data","undefined","createLiteralTypeNode","SyntaxKind","UndefinedKeyword","NullKeyword","isString","createStringLiteral","isNumber","createPrefixUnaryExpression","MinusToken","createNumericLiteral","isBoolean","createTrue","createFalse","Array","isArray","createTupleTypeNode","map","item","isDate","toISOString","Error","entries","Object","sort","a","b","localeCompare","props","reduce","acc","key","value","identifier","includes","createPropertyDeclaration","createTypeLiteralNode","withAttributeNamespace"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAWA,MAAM,EAAEA,OAAO,EAAE,GAAGC,aAAAA;MAEPC,UAAAA,GAAa;IACxBC,MAAAA,EAAQ,QAAA;IACRC,MAAAA,EAAQ;AACV;AAuBA;;IAGO,MAAMC,sBAAAA,GAAyB,CAACC,GAAAA,GACrCC,YAAAA,CAAWC,WAAAA,CAAUF,GAAAA,CAAIG,OAAO,CAAC,MAAA,EAAQ,GAAA,CAAA,CAAA;AAEpC,MAAMC,qBAAqB,CAACC,MAAAA,GAAAA;AACjC,IAAA,MAAM,EAAEC,SAAS,EAAEC,IAAI,EAAE,GAAGF,MAAAA;;AAG5B,IAAA,IAAIC,cAAc,WAAA,EAAa;QAC7B,OAAO,WAAA;AACT,IAAA;;AAGA,IAAA,IAAIA,cAAc,aAAA,EAAe;QAC/B,OAAOC,IAAAA;AACT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yBAAyB,CAC/BnC,SAAAA,EACAiC,UAAAA,EACAjC,SAAAA,EACAF,cAAckC,KAAAA,CAAAA,EACdhC,SAAAA;AAEH,SAAA;AACH,IAAA,CAAA,EAAG,EAAE,CAAA;IAEL,OAAOvB,OAAAA,CAAQ2D,qBAAqB,CAACR,KAAAA,CAAAA;AACvC;AAmBA;;AAEC,IACM,MAAMS,sBAAAA,GAAyB,CAAC3C,QAAAA,GACrC,CAAA,EAAGf,UAAAA,CAAWE,MAAM,CAAC,WAAW,EAAEa,QAAAA,CAAAA;;;;;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { upperFirst, camelCase, isString, isNumber, isBoolean, isDate } from 'lodash';
|
|
3
3
|
|
|
4
4
|
const { factory } = ts;
|
|
5
5
|
const NAMESPACES = {
|
|
@@ -8,7 +8,7 @@ const NAMESPACES = {
|
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Extract a valid interface name from a schema uid
|
|
11
|
-
*/ const getSchemaInterfaceName =
|
|
11
|
+
*/ const getSchemaInterfaceName = (uid)=>upperFirst(camelCase(uid.replace(/(:.)/, ' ')));
|
|
12
12
|
const getSchemaModelType = (schema)=>{
|
|
13
13
|
const { modelType, kind } = schema;
|
|
14
14
|
// Components
|
|
@@ -38,10 +38,10 @@ const getSchemaModelType = (schema)=>{
|
|
|
38
38
|
/**
|
|
39
39
|
* Transform a regular JavaScript object or scalar value into a literal expression
|
|
40
40
|
*/ const toTypeLiteral = (data)=>{
|
|
41
|
-
if (
|
|
41
|
+
if (data === undefined) {
|
|
42
42
|
return factory.createLiteralTypeNode(ts.SyntaxKind.UndefinedKeyword);
|
|
43
43
|
}
|
|
44
|
-
if (
|
|
44
|
+
if (data === null) {
|
|
45
45
|
return factory.createLiteralTypeNode(ts.SyntaxKind.NullKeyword);
|
|
46
46
|
}
|
|
47
47
|
if (isString(data)) {
|
|
@@ -53,7 +53,7 @@ const getSchemaModelType = (schema)=>{
|
|
|
53
53
|
if (isBoolean(data)) {
|
|
54
54
|
return data ? factory.createTrue() : factory.createFalse();
|
|
55
55
|
}
|
|
56
|
-
if (isArray(data)) {
|
|
56
|
+
if (Array.isArray(data)) {
|
|
57
57
|
return factory.createTupleTypeNode(data.map((item)=>toTypeLiteral(item)));
|
|
58
58
|
}
|
|
59
59
|
if (isDate(data)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../../../src/generators/common/models/utils.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport {\n
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../../../src/generators/common/models/utils.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport {\n camelCase,\n isBoolean,\n isDate,\n isNumber,\n isString,\n matchesProperty,\n upperFirst,\n} from 'lodash';\n\nconst { factory } = ts;\n\nexport const NAMESPACES = {\n Struct: 'Struct',\n Schema: 'Schema',\n};\n\n/**\n * Shallow representation of a content-type/component attribute definition.\n * Only the fields read by the generators are typed; the rest is left open.\n */\nexport interface Attribute {\n type: string;\n [key: string]: any;\n}\n\n/**\n * Shallow representation of a content-type/component schema definition.\n * Only the fields read by the generators are typed; the rest is left open.\n */\nexport interface Schema {\n uid: string;\n modelType?: string;\n kind?: string;\n attributes: Record<string, Attribute>;\n [key: string]: any;\n}\n\n/**\n * Extract a valid interface name from a schema uid\n */\nexport const getSchemaInterfaceName = (uid: string): string =>\n upperFirst(camelCase(uid.replace(/(:.)/, ' ')));\n\nexport const getSchemaModelType = (schema: Schema): string | null | undefined => {\n const { modelType, kind } = schema;\n\n // Components\n if (modelType === 'component') {\n return 'component';\n }\n\n // Content-Types\n if (modelType === 'contentType') {\n return kind;\n }\n\n return null;\n};\n\n/**\n * Get the parent type name to extend based on the schema's nature\n */\nexport const getSchemaExtendsTypeName = (schema: Schema): string | null => {\n const base = getSchemaModelType(schema);\n\n if (base === null) {\n return null;\n }\n\n return `${NAMESPACES.Struct}.${upperFirst(base as string)}Schema`;\n};\n\n/**\n * Get a type node based on a type and its params\n */\nexport const getTypeNode = (typeName: string, params: ts.TypeNode[] = []): ts.TypeReferenceNode => {\n return factory.createTypeReferenceNode(factory.createIdentifier(typeName), params);\n};\n\n/**\n * Transform a regular JavaScript object or scalar value into a literal expression\n */\nexport const toTypeLiteral = (data: any): any => {\n if (data === undefined) {\n return factory.createLiteralTypeNode(ts.SyntaxKind.UndefinedKeyword as any);\n }\n\n if (data === null) {\n return factory.createLiteralTypeNode(ts.SyntaxKind.NullKeyword as any);\n }\n\n if (isString(data)) {\n return factory.createStringLiteral(data, true);\n }\n\n if (isNumber(data)) {\n return data < 0\n ? factory.createPrefixUnaryExpression(\n ts.SyntaxKind.MinusToken,\n factory.createNumericLiteral(-data)\n )\n : factory.createNumericLiteral(data);\n }\n\n if (isBoolean(data)) {\n return data ? factory.createTrue() : factory.createFalse();\n }\n\n if (Array.isArray(data)) {\n return factory.createTupleTypeNode(data.map((item) => toTypeLiteral(item)));\n }\n\n if (isDate(data)) {\n return factory.createStringLiteral(data.toISOString());\n }\n\n if (typeof data !== 'object') {\n throw new Error(`Cannot convert to object literal. Unknown type \"${typeof data}\"`);\n }\n\n const entries = Object.entries(data).sort((a, b) => a[0].localeCompare(b[0]));\n\n const props = entries.reduce<any[]>((acc, [key, value]) => {\n // Handle keys such as content-type-builder & co.\n const identifier = key.includes('-')\n ? factory.createStringLiteral(key, true)\n : factory.createIdentifier(key);\n\n return [\n ...acc,\n factory.createPropertyDeclaration(\n undefined,\n identifier,\n undefined,\n toTypeLiteral(value),\n undefined\n ),\n ];\n }, []);\n\n return factory.createTypeLiteralNode(props);\n};\n\n/**\n * Get the number of attributes generated for a given schema definition\n */\nexport const getDefinitionAttributesCount = (\n definition: ts.InterfaceDeclaration\n): number | null => {\n const attributesNode = definition.members.find(\n matchesProperty('name.escapedText', 'attributes')\n ) as any;\n\n if (!attributesNode) {\n return null;\n }\n\n return attributesNode.type.members.length;\n};\n\n/**\n * Add the Schema.Attribute namespace before the typename\n */\nexport const withAttributeNamespace = (typeName: string): string =>\n `${NAMESPACES.Schema}.Attribute.${typeName}`;\n\n/**\n * Add the schema namespace before the typename\n */\nexport const withSchemaNamespace = (typeName: string): string =>\n `${(NAMESPACES as any).schema}.${typeName}`;\n"],"names":["factory","ts","NAMESPACES","Struct","Schema","getSchemaInterfaceName","uid","upperFirst","camelCase","replace","getSchemaModelType","schema","modelType","kind","getSchemaExtendsTypeName","base","getTypeNode","typeName","params","createTypeReferenceNode","createIdentifier","toTypeLiteral","data","undefined","createLiteralTypeNode","SyntaxKind","UndefinedKeyword","NullKeyword","isString","createStringLiteral","isNumber","createPrefixUnaryExpression","MinusToken","createNumericLiteral","isBoolean","createTrue","createFalse","Array","isArray","createTupleTypeNode","map","item","isDate","toISOString","Error","entries","Object","sort","a","b","localeCompare","props","reduce","acc","key","value","identifier","includes","createPropertyDeclaration","createTypeLiteralNode","withAttributeNamespace"],"mappings":";;;AAWA,MAAM,EAAEA,OAAO,EAAE,GAAGC,EAAAA;MAEPC,UAAAA,GAAa;IACxBC,MAAAA,EAAQ,QAAA;IACRC,MAAAA,EAAQ;AACV;AAuBA;;IAGO,MAAMC,sBAAAA,GAAyB,CAACC,GAAAA,GACrCC,UAAAA,CAAWC,SAAAA,CAAUF,GAAAA,CAAIG,OAAO,CAAC,MAAA,EAAQ,GAAA,CAAA,CAAA;AAEpC,MAAMC,qBAAqB,CAACC,MAAAA,GAAAA;AACjC,IAAA,MAAM,EAAEC,SAAS,EAAEC,IAAI,EAAE,GAAGF,MAAAA;;AAG5B,IAAA,IAAIC,cAAc,WAAA,EAAa;QAC7B,OAAO,WAAA;AACT,IAAA;;AAGA,IAAA,IAAIA,cAAc,aAAA,EAAe;QAC/B,OAAOC,IAAAA;AACT,IAAA;IAEA,OAAO,IAAA;AACT;AAEA;;IAGO,MAAMC,wBAAAA,GAA2B,CAACH,MAAAA,GAAAA;AACvC,IAAA,MAAMI,OAAO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H,IAAA,CAAA,EAAG,EAAE,CAAA;IAEL,OAAOvB,OAAAA,CAAQ2D,qBAAqB,CAACR,KAAAA,CAAAA;AACvC;AAmBA;;AAEC,IACM,MAAMS,sBAAAA,GAAyB,CAAC3C,QAAAA,GACrC,CAAA,EAAGf,UAAAA,CAAWE,MAAM,CAAC,WAAW,EAAEa,QAAAA,CAAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generators/components/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AASjD;;GAEG;AACH,eAAO,MAAM,6BAA6B,GACxC,UAAS,gBAAyC;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generators/components/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AASjD;;GAEG;AACH,eAAO,MAAM,6BAA6B,GACxC,UAAS,gBAAyC;;;EAkDnD,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ts = require('typescript');
|
|
4
|
-
var _ = require('lodash
|
|
4
|
+
var _ = require('lodash');
|
|
5
5
|
var schema = require('../common/models/schema.js');
|
|
6
6
|
var imports = require('../common/imports.js');
|
|
7
|
-
require('../common/models/utils.js');
|
|
8
7
|
var utils = require('../utils.js');
|
|
9
8
|
|
|
10
9
|
function _interopNamespace(e) {
|
|
@@ -37,10 +36,10 @@ const NO_COMPONENT_PLACEHOLDER_COMMENT = `/*
|
|
|
37
36
|
*/ const generateComponentsDefinitions = async (options = {})=>{
|
|
38
37
|
const { strapi } = options;
|
|
39
38
|
const { components } = strapi;
|
|
40
|
-
const componentsDefinitions = _.
|
|
39
|
+
const componentsDefinitions = _.sortBy(Object.values(components ?? {}), 'uid').map((component)=>({
|
|
41
40
|
uid: component.uid,
|
|
42
41
|
definition: schema.generateSchemaDefinition(component)
|
|
43
|
-
}))
|
|
42
|
+
}));
|
|
44
43
|
options.logger.debug(`Found ${componentsDefinitions.length} components.`);
|
|
45
44
|
if (componentsDefinitions.length === 0) {
|
|
46
45
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/generators/components/index.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/generators/components/index.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { sortBy } from 'lodash';\n\nimport { models } from '../common';\nimport { emitDefinitions, format, generateSharedExtensionDefinition } from '../utils';\nimport type { GeneratorOptions } from '../utils';\n\nconst { factory } = ts;\n\nconst NO_COMPONENT_PLACEHOLDER_COMMENT = `/*\n * The app doesn't have any components yet.\n */\n`;\n\n/**\n * Generate type definitions for Strapi Components\n */\nexport const generateComponentsDefinitions = async (\n options: GeneratorOptions = {} as GeneratorOptions\n) => {\n const { strapi } = options;\n\n const { components } = strapi;\n\n const componentsDefinitions = sortBy(\n Object.values<models.utils.Schema>(components ?? {}),\n 'uid'\n ).map((component) => ({\n uid: component.uid,\n definition: models.schema.generateSchemaDefinition(component),\n }));\n\n options.logger.debug(`Found ${componentsDefinitions.length} components.`);\n\n if (componentsDefinitions.length === 0) {\n return { output: NO_COMPONENT_PLACEHOLDER_COMMENT, stats: {} };\n }\n\n const formattedSchemasDefinitions = componentsDefinitions.reduce<any[]>((acc, def) => {\n acc.push(\n // Definition\n def.definition,\n\n // Add a newline between each interface declaration\n factory.createIdentifier('\\n')\n );\n\n return acc;\n }, []);\n\n const allDefinitions = [\n // Imports\n ...models.imports.generateImportDefinition(),\n\n // Add a newline after the import statement\n factory.createIdentifier('\\n'),\n\n // Schemas\n ...formattedSchemasDefinitions,\n\n // Global\n generateSharedExtensionDefinition('ComponentSchemas', componentsDefinitions),\n ];\n\n const output = emitDefinitions(allDefinitions);\n const formattedOutput = await format(output);\n\n return { output: formattedOutput, stats: {} };\n};\n"],"names":["factory","ts","NO_COMPONENT_PLACEHOLDER_COMMENT","generateComponentsDefinitions","options","strapi","components","componentsDefinitions","sortBy","Object","values","map","component","uid","definition","models","logger","debug","length","output","stats","formattedSchemasDefinitions","reduce","acc","def","push","createIdentifier","allDefinitions","generateSharedExtensionDefinition","emitDefinitions","formattedOutput","format"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAM,EAAEA,OAAO,EAAE,GAAGC,aAAAA;AAEpB,MAAMC,mCAAmC,CAAC;;;AAG1C,CAAC;AAED;;AAEC,IACM,MAAMC,6BAAAA,GAAgC,OAC3CC,OAAAA,GAA4B,EAAsB,GAAA;IAElD,MAAM,EAAEC,MAAM,EAAE,GAAGD,OAAAA;IAEnB,MAAM,EAAEE,UAAU,EAAE,GAAGD,MAAAA;AAEvB,IAAA,MAAME,qBAAAA,GAAwBC,QAAAA,CAC5BC,MAAAA,CAAOC,MAAM,CAAsBJ,UAAAA,IAAc,EAAC,CAAA,EAClD,KAAA,CAAA,CACAK,GAAG,CAAC,CAACC,aAAe;AACpBC,YAAAA,GAAAA,EAAKD,UAAUC,GAAG;AAClBC,YAAAA,UAAAA,EAAYC,+BAAsC,CAACH,SAAAA;SACrD,CAAA,CAAA;IAEAR,OAAAA,CAAQY,MAAM,CAACC,KAAK,CAAC,CAAC,MAAM,EAAEV,qBAAAA,CAAsBW,MAAM,CAAC,YAAY,CAAC,CAAA;IAExE,IAAIX,qBAAAA,CAAsBW,MAAM,KAAK,CAAA,EAAG;QACtC,OAAO;YAAEC,MAAAA,EAAQjB,gCAAAA;AAAkCkB,YAAAA,KAAAA,EAAO;AAAG,SAAA;AAC/D,IAAA;AAEA,IAAA,MAAMC,2BAAAA,GAA8Bd,qBAAAA,CAAsBe,MAAM,CAAQ,CAACC,GAAAA,EAAKC,GAAAA,GAAAA;QAC5ED,GAAAA,CAAIE,IAAI;QAEND,GAAAA,CAAIV,UAAU;AAGdd,QAAAA,OAAAA,CAAQ0B,gBAAgB,CAAC,IAAA,CAAA,CAAA;QAG3B,OAAOH,GAAAA;AACT,IAAA,CAAA,EAAG,EAAE,CAAA;AAEL,IAAA,MAAMI,cAAAA,GAAiB;;WAElBZ,gCAAuC,EAAA;;AAG1Cf,QAAAA,OAAAA,CAAQ0B,gBAAgB,CAAC,IAAA,CAAA;;AAGtBL,QAAAA,GAAAA,2BAAAA;;AAGHO,QAAAA,uCAAAA,CAAkC,kBAAA,EAAoBrB,qBAAAA;AACvD,KAAA;AAED,IAAA,MAAMY,SAASU,qBAAAA,CAAgBF,cAAAA,CAAAA;IAC/B,MAAMG,eAAAA,GAAkB,MAAMC,YAAAA,CAAOZ,MAAAA,CAAAA;IAErC,OAAO;QAAEA,MAAAA,EAAQW,eAAAA;AAAiBV,QAAAA,KAAAA,EAAO;AAAG,KAAA;AAC9C;;;;"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { sortBy } from 'lodash';
|
|
3
3
|
import { generateSchemaDefinition } from '../common/models/schema.mjs';
|
|
4
4
|
import { generateImportDefinition } from '../common/imports.mjs';
|
|
5
|
-
import '../common/models/utils.mjs';
|
|
6
5
|
import { generateSharedExtensionDefinition, emitDefinitions, format } from '../utils.mjs';
|
|
7
6
|
|
|
8
7
|
const { factory } = ts;
|
|
@@ -15,10 +14,10 @@ const NO_COMPONENT_PLACEHOLDER_COMMENT = `/*
|
|
|
15
14
|
*/ const generateComponentsDefinitions = async (options = {})=>{
|
|
16
15
|
const { strapi } = options;
|
|
17
16
|
const { components } = strapi;
|
|
18
|
-
const componentsDefinitions =
|
|
17
|
+
const componentsDefinitions = sortBy(Object.values(components ?? {}), 'uid').map((component)=>({
|
|
19
18
|
uid: component.uid,
|
|
20
19
|
definition: generateSchemaDefinition(component)
|
|
21
|
-
}))
|
|
20
|
+
}));
|
|
22
21
|
options.logger.debug(`Found ${componentsDefinitions.length} components.`);
|
|
23
22
|
if (componentsDefinitions.length === 0) {
|
|
24
23
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/generators/components/index.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport {
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/generators/components/index.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { sortBy } from 'lodash';\n\nimport { models } from '../common';\nimport { emitDefinitions, format, generateSharedExtensionDefinition } from '../utils';\nimport type { GeneratorOptions } from '../utils';\n\nconst { factory } = ts;\n\nconst NO_COMPONENT_PLACEHOLDER_COMMENT = `/*\n * The app doesn't have any components yet.\n */\n`;\n\n/**\n * Generate type definitions for Strapi Components\n */\nexport const generateComponentsDefinitions = async (\n options: GeneratorOptions = {} as GeneratorOptions\n) => {\n const { strapi } = options;\n\n const { components } = strapi;\n\n const componentsDefinitions = sortBy(\n Object.values<models.utils.Schema>(components ?? {}),\n 'uid'\n ).map((component) => ({\n uid: component.uid,\n definition: models.schema.generateSchemaDefinition(component),\n }));\n\n options.logger.debug(`Found ${componentsDefinitions.length} components.`);\n\n if (componentsDefinitions.length === 0) {\n return { output: NO_COMPONENT_PLACEHOLDER_COMMENT, stats: {} };\n }\n\n const formattedSchemasDefinitions = componentsDefinitions.reduce<any[]>((acc, def) => {\n acc.push(\n // Definition\n def.definition,\n\n // Add a newline between each interface declaration\n factory.createIdentifier('\\n')\n );\n\n return acc;\n }, []);\n\n const allDefinitions = [\n // Imports\n ...models.imports.generateImportDefinition(),\n\n // Add a newline after the import statement\n factory.createIdentifier('\\n'),\n\n // Schemas\n ...formattedSchemasDefinitions,\n\n // Global\n generateSharedExtensionDefinition('ComponentSchemas', componentsDefinitions),\n ];\n\n const output = emitDefinitions(allDefinitions);\n const formattedOutput = await format(output);\n\n return { output: formattedOutput, stats: {} };\n};\n"],"names":["factory","ts","NO_COMPONENT_PLACEHOLDER_COMMENT","generateComponentsDefinitions","options","strapi","components","componentsDefinitions","sortBy","Object","values","map","component","uid","definition","models","logger","debug","length","output","stats","formattedSchemasDefinitions","reduce","acc","def","push","createIdentifier","allDefinitions","generateSharedExtensionDefinition","emitDefinitions","formattedOutput","format"],"mappings":";;;;;;AAOA,MAAM,EAAEA,OAAO,EAAE,GAAGC,EAAAA;AAEpB,MAAMC,mCAAmC,CAAC;;;AAG1C,CAAC;AAED;;AAEC,IACM,MAAMC,6BAAAA,GAAgC,OAC3CC,OAAAA,GAA4B,EAAsB,GAAA;IAElD,MAAM,EAAEC,MAAM,EAAE,GAAGD,OAAAA;IAEnB,MAAM,EAAEE,UAAU,EAAE,GAAGD,MAAAA;AAEvB,IAAA,MAAME,qBAAAA,GAAwBC,MAAAA,CAC5BC,MAAAA,CAAOC,MAAM,CAAsBJ,UAAAA,IAAc,EAAC,CAAA,EAClD,KAAA,CAAA,CACAK,GAAG,CAAC,CAACC,aAAe;AACpBC,YAAAA,GAAAA,EAAKD,UAAUC,GAAG;AAClBC,YAAAA,UAAAA,EAAYC,wBAAsC,CAACH,SAAAA;SACrD,CAAA,CAAA;IAEAR,OAAAA,CAAQY,MAAM,CAACC,KAAK,CAAC,CAAC,MAAM,EAAEV,qBAAAA,CAAsBW,MAAM,CAAC,YAAY,CAAC,CAAA;IAExE,IAAIX,qBAAAA,CAAsBW,MAAM,KAAK,CAAA,EAAG;QACtC,OAAO;YAAEC,MAAAA,EAAQjB,gCAAAA;AAAkCkB,YAAAA,KAAAA,EAAO;AAAG,SAAA;AAC/D,IAAA;AAEA,IAAA,MAAMC,2BAAAA,GAA8Bd,qBAAAA,CAAsBe,MAAM,CAAQ,CAACC,GAAAA,EAAKC,GAAAA,GAAAA;QAC5ED,GAAAA,CAAIE,IAAI;QAEND,GAAAA,CAAIV,UAAU;AAGdd,QAAAA,OAAAA,CAAQ0B,gBAAgB,CAAC,IAAA,CAAA,CAAA;QAG3B,OAAOH,GAAAA;AACT,IAAA,CAAA,EAAG,EAAE,CAAA;AAEL,IAAA,MAAMI,cAAAA,GAAiB;;WAElBZ,wBAAuC,EAAA;;AAG1Cf,QAAAA,OAAAA,CAAQ0B,gBAAgB,CAAC,IAAA,CAAA;;AAGtBL,QAAAA,GAAAA,2BAAAA;;AAGHO,QAAAA,iCAAAA,CAAkC,kBAAA,EAAoBrB,qBAAAA;AACvD,KAAA;AAED,IAAA,MAAMY,SAASU,eAAAA,CAAgBF,cAAAA,CAAAA;IAC/B,MAAMG,eAAAA,GAAkB,MAAMC,MAAAA,CAAOZ,MAAAA,CAAAA;IAErC,OAAO;QAAEA,MAAAA,EAAQW,eAAAA;AAAiBV,QAAAA,KAAAA,EAAO;AAAG,KAAA;AAC9C;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generators/content-types/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AASjD;;GAEG;AACH,eAAO,MAAM,+BAA+B,GAC1C,UAAS,gBAAyC;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generators/content-types/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AASjD;;GAEG;AACH,eAAO,MAAM,+BAA+B,GAC1C,UAAS,gBAAyC;;;EAkDnD,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ts = require('typescript');
|
|
4
|
-
var _ = require('lodash
|
|
4
|
+
var _ = require('lodash');
|
|
5
5
|
var schema = require('../common/models/schema.js');
|
|
6
6
|
var imports = require('../common/imports.js');
|
|
7
|
-
require('../common/models/utils.js');
|
|
8
7
|
var utils = require('../utils.js');
|
|
9
8
|
|
|
10
9
|
function _interopNamespace(e) {
|
|
@@ -37,10 +36,10 @@ const NO_CONTENT_TYPE_PLACEHOLDER_COMMENT = `/*
|
|
|
37
36
|
*/ const generateContentTypesDefinitions = async (options = {})=>{
|
|
38
37
|
const { strapi } = options;
|
|
39
38
|
const { contentTypes } = strapi;
|
|
40
|
-
const contentTypesDefinitions = _.
|
|
39
|
+
const contentTypesDefinitions = _.sortBy(Object.values(contentTypes ?? {}), 'uid').map((contentType)=>({
|
|
41
40
|
uid: contentType.uid,
|
|
42
41
|
definition: schema.generateSchemaDefinition(contentType)
|
|
43
|
-
}))
|
|
42
|
+
}));
|
|
44
43
|
options.logger.debug(`Found ${contentTypesDefinitions.length} content-types.`);
|
|
45
44
|
if (contentTypesDefinitions.length === 0) {
|
|
46
45
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/generators/content-types/index.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/generators/content-types/index.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { sortBy } from 'lodash';\n\nimport { models } from '../common';\nimport { emitDefinitions, format, generateSharedExtensionDefinition } from '../utils';\nimport type { GeneratorOptions } from '../utils';\n\nconst { factory } = ts;\n\nconst NO_CONTENT_TYPE_PLACEHOLDER_COMMENT = `/*\n * The app doesn't have any content-types yet.\n */\n`;\n\n/**\n * Generate type definitions for Strapi Content-Types\n */\nexport const generateContentTypesDefinitions = async (\n options: GeneratorOptions = {} as GeneratorOptions\n) => {\n const { strapi } = options;\n\n const { contentTypes } = strapi;\n\n const contentTypesDefinitions = sortBy(\n Object.values<models.utils.Schema>(contentTypes ?? {}),\n 'uid'\n ).map((contentType) => ({\n uid: contentType.uid,\n definition: models.schema.generateSchemaDefinition(contentType),\n }));\n\n options.logger.debug(`Found ${contentTypesDefinitions.length} content-types.`);\n\n if (contentTypesDefinitions.length === 0) {\n return { output: NO_CONTENT_TYPE_PLACEHOLDER_COMMENT, stats: {} };\n }\n\n const formattedSchemasDefinitions = contentTypesDefinitions.reduce<any[]>((acc, def) => {\n acc.push(\n // Definition\n def.definition,\n\n // Add a newline between each interface declaration\n factory.createIdentifier('\\n')\n );\n\n return acc;\n }, []);\n\n const allDefinitions = [\n // Imports\n ...models.imports.generateImportDefinition(),\n\n // Add a newline after the import statement\n factory.createIdentifier('\\n'),\n\n // Schemas\n ...formattedSchemasDefinitions,\n\n // Global\n generateSharedExtensionDefinition('ContentTypeSchemas', contentTypesDefinitions),\n ];\n\n const output = emitDefinitions(allDefinitions);\n const formattedOutput = await format(output);\n\n return { output: formattedOutput, stats: {} };\n};\n"],"names":["factory","ts","NO_CONTENT_TYPE_PLACEHOLDER_COMMENT","generateContentTypesDefinitions","options","strapi","contentTypes","contentTypesDefinitions","sortBy","Object","values","map","contentType","uid","definition","models","logger","debug","length","output","stats","formattedSchemasDefinitions","reduce","acc","def","push","createIdentifier","allDefinitions","generateSharedExtensionDefinition","emitDefinitions","formattedOutput","format"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAM,EAAEA,OAAO,EAAE,GAAGC,aAAAA;AAEpB,MAAMC,sCAAsC,CAAC;;;AAG7C,CAAC;AAED;;AAEC,IACM,MAAMC,+BAAAA,GAAkC,OAC7CC,OAAAA,GAA4B,EAAsB,GAAA;IAElD,MAAM,EAAEC,MAAM,EAAE,GAAGD,OAAAA;IAEnB,MAAM,EAAEE,YAAY,EAAE,GAAGD,MAAAA;AAEzB,IAAA,MAAME,uBAAAA,GAA0BC,QAAAA,CAC9BC,MAAAA,CAAOC,MAAM,CAAsBJ,YAAAA,IAAgB,EAAC,CAAA,EACpD,KAAA,CAAA,CACAK,GAAG,CAAC,CAACC,eAAiB;AACtBC,YAAAA,GAAAA,EAAKD,YAAYC,GAAG;AACpBC,YAAAA,UAAAA,EAAYC,+BAAsC,CAACH,WAAAA;SACrD,CAAA,CAAA;IAEAR,OAAAA,CAAQY,MAAM,CAACC,KAAK,CAAC,CAAC,MAAM,EAAEV,uBAAAA,CAAwBW,MAAM,CAAC,eAAe,CAAC,CAAA;IAE7E,IAAIX,uBAAAA,CAAwBW,MAAM,KAAK,CAAA,EAAG;QACxC,OAAO;YAAEC,MAAAA,EAAQjB,mCAAAA;AAAqCkB,YAAAA,KAAAA,EAAO;AAAG,SAAA;AAClE,IAAA;AAEA,IAAA,MAAMC,2BAAAA,GAA8Bd,uBAAAA,CAAwBe,MAAM,CAAQ,CAACC,GAAAA,EAAKC,GAAAA,GAAAA;QAC9ED,GAAAA,CAAIE,IAAI;QAEND,GAAAA,CAAIV,UAAU;AAGdd,QAAAA,OAAAA,CAAQ0B,gBAAgB,CAAC,IAAA,CAAA,CAAA;QAG3B,OAAOH,GAAAA;AACT,IAAA,CAAA,EAAG,EAAE,CAAA;AAEL,IAAA,MAAMI,cAAAA,GAAiB;;WAElBZ,gCAAuC,EAAA;;AAG1Cf,QAAAA,OAAAA,CAAQ0B,gBAAgB,CAAC,IAAA,CAAA;;AAGtBL,QAAAA,GAAAA,2BAAAA;;AAGHO,QAAAA,uCAAAA,CAAkC,oBAAA,EAAsBrB,uBAAAA;AACzD,KAAA;AAED,IAAA,MAAMY,SAASU,qBAAAA,CAAgBF,cAAAA,CAAAA;IAC/B,MAAMG,eAAAA,GAAkB,MAAMC,YAAAA,CAAOZ,MAAAA,CAAAA;IAErC,OAAO;QAAEA,MAAAA,EAAQW,eAAAA;AAAiBV,QAAAA,KAAAA,EAAO;AAAG,KAAA;AAC9C;;;;"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { sortBy } from 'lodash';
|
|
3
3
|
import { generateSchemaDefinition } from '../common/models/schema.mjs';
|
|
4
4
|
import { generateImportDefinition } from '../common/imports.mjs';
|
|
5
|
-
import '../common/models/utils.mjs';
|
|
6
5
|
import { generateSharedExtensionDefinition, emitDefinitions, format } from '../utils.mjs';
|
|
7
6
|
|
|
8
7
|
const { factory } = ts;
|
|
@@ -15,10 +14,10 @@ const NO_CONTENT_TYPE_PLACEHOLDER_COMMENT = `/*
|
|
|
15
14
|
*/ const generateContentTypesDefinitions = async (options = {})=>{
|
|
16
15
|
const { strapi } = options;
|
|
17
16
|
const { contentTypes } = strapi;
|
|
18
|
-
const contentTypesDefinitions =
|
|
17
|
+
const contentTypesDefinitions = sortBy(Object.values(contentTypes ?? {}), 'uid').map((contentType)=>({
|
|
19
18
|
uid: contentType.uid,
|
|
20
19
|
definition: generateSchemaDefinition(contentType)
|
|
21
|
-
}))
|
|
20
|
+
}));
|
|
22
21
|
options.logger.debug(`Found ${contentTypesDefinitions.length} content-types.`);
|
|
23
22
|
if (contentTypesDefinitions.length === 0) {
|
|
24
23
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/generators/content-types/index.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport {
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/generators/content-types/index.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { sortBy } from 'lodash';\n\nimport { models } from '../common';\nimport { emitDefinitions, format, generateSharedExtensionDefinition } from '../utils';\nimport type { GeneratorOptions } from '../utils';\n\nconst { factory } = ts;\n\nconst NO_CONTENT_TYPE_PLACEHOLDER_COMMENT = `/*\n * The app doesn't have any content-types yet.\n */\n`;\n\n/**\n * Generate type definitions for Strapi Content-Types\n */\nexport const generateContentTypesDefinitions = async (\n options: GeneratorOptions = {} as GeneratorOptions\n) => {\n const { strapi } = options;\n\n const { contentTypes } = strapi;\n\n const contentTypesDefinitions = sortBy(\n Object.values<models.utils.Schema>(contentTypes ?? {}),\n 'uid'\n ).map((contentType) => ({\n uid: contentType.uid,\n definition: models.schema.generateSchemaDefinition(contentType),\n }));\n\n options.logger.debug(`Found ${contentTypesDefinitions.length} content-types.`);\n\n if (contentTypesDefinitions.length === 0) {\n return { output: NO_CONTENT_TYPE_PLACEHOLDER_COMMENT, stats: {} };\n }\n\n const formattedSchemasDefinitions = contentTypesDefinitions.reduce<any[]>((acc, def) => {\n acc.push(\n // Definition\n def.definition,\n\n // Add a newline between each interface declaration\n factory.createIdentifier('\\n')\n );\n\n return acc;\n }, []);\n\n const allDefinitions = [\n // Imports\n ...models.imports.generateImportDefinition(),\n\n // Add a newline after the import statement\n factory.createIdentifier('\\n'),\n\n // Schemas\n ...formattedSchemasDefinitions,\n\n // Global\n generateSharedExtensionDefinition('ContentTypeSchemas', contentTypesDefinitions),\n ];\n\n const output = emitDefinitions(allDefinitions);\n const formattedOutput = await format(output);\n\n return { output: formattedOutput, stats: {} };\n};\n"],"names":["factory","ts","NO_CONTENT_TYPE_PLACEHOLDER_COMMENT","generateContentTypesDefinitions","options","strapi","contentTypes","contentTypesDefinitions","sortBy","Object","values","map","contentType","uid","definition","models","logger","debug","length","output","stats","formattedSchemasDefinitions","reduce","acc","def","push","createIdentifier","allDefinitions","generateSharedExtensionDefinition","emitDefinitions","formattedOutput","format"],"mappings":";;;;;;AAOA,MAAM,EAAEA,OAAO,EAAE,GAAGC,EAAAA;AAEpB,MAAMC,sCAAsC,CAAC;;;AAG7C,CAAC;AAED;;AAEC,IACM,MAAMC,+BAAAA,GAAkC,OAC7CC,OAAAA,GAA4B,EAAsB,GAAA;IAElD,MAAM,EAAEC,MAAM,EAAE,GAAGD,OAAAA;IAEnB,MAAM,EAAEE,YAAY,EAAE,GAAGD,MAAAA;AAEzB,IAAA,MAAME,uBAAAA,GAA0BC,MAAAA,CAC9BC,MAAAA,CAAOC,MAAM,CAAsBJ,YAAAA,IAAgB,EAAC,CAAA,EACpD,KAAA,CAAA,CACAK,GAAG,CAAC,CAACC,eAAiB;AACtBC,YAAAA,GAAAA,EAAKD,YAAYC,GAAG;AACpBC,YAAAA,UAAAA,EAAYC,wBAAsC,CAACH,WAAAA;SACrD,CAAA,CAAA;IAEAR,OAAAA,CAAQY,MAAM,CAACC,KAAK,CAAC,CAAC,MAAM,EAAEV,uBAAAA,CAAwBW,MAAM,CAAC,eAAe,CAAC,CAAA;IAE7E,IAAIX,uBAAAA,CAAwBW,MAAM,KAAK,CAAA,EAAG;QACxC,OAAO;YAAEC,MAAAA,EAAQjB,mCAAAA;AAAqCkB,YAAAA,KAAAA,EAAO;AAAG,SAAA;AAClE,IAAA;AAEA,IAAA,MAAMC,2BAAAA,GAA8Bd,uBAAAA,CAAwBe,MAAM,CAAQ,CAACC,GAAAA,EAAKC,GAAAA,GAAAA;QAC9ED,GAAAA,CAAIE,IAAI;QAEND,GAAAA,CAAIV,UAAU;AAGdd,QAAAA,OAAAA,CAAQ0B,gBAAgB,CAAC,IAAA,CAAA,CAAA;QAG3B,OAAOH,GAAAA;AACT,IAAA,CAAA,EAAG,EAAE,CAAA;AAEL,IAAA,MAAMI,cAAAA,GAAiB;;WAElBZ,wBAAuC,EAAA;;AAG1Cf,QAAAA,OAAAA,CAAQ0B,gBAAgB,CAAC,IAAA,CAAA;;AAGtBL,QAAAA,GAAAA,2BAAAA;;AAGHO,QAAAA,iCAAAA,CAAkC,oBAAA,EAAsBrB,uBAAAA;AACzD,KAAA;AAED,IAAA,MAAMY,SAASU,eAAAA,CAAgBF,cAAAA,CAAAA;IAC/B,MAAMG,eAAAA,GAAkB,MAAMC,MAAAA,CAAOZ,MAAAA,CAAAA;IAErC,OAAO;QAAEA,MAAAA,EAAQW,eAAAA;AAAiBV,QAAAA,KAAAA,EAAO;AAAG,KAAA;AAC9C;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-host.js","sources":["../../src/utils/format-host.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { identity } from 'lodash
|
|
1
|
+
{"version":3,"file":"format-host.js","sources":["../../src/utils/format-host.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { identity } from 'lodash';\n\nexport const formatHost: ts.FormatDiagnosticsHost = {\n getCanonicalFileName: identity,\n getCurrentDirectory: ts.sys.getCurrentDirectory,\n getNewLine: () => ts.sys.newLine,\n};\n"],"names":["formatHost","getCanonicalFileName","identity","getCurrentDirectory","ts","sys","getNewLine","newLine"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;MAGaA,UAAAA,GAAuC;IAClDC,oBAAAA,EAAsBC,UAAAA;IACtBC,mBAAAA,EAAqBC,aAAAA,CAAGC,GAAG,CAACF,mBAAmB;AAC/CG,IAAAA,UAAAA,EAAY,IAAMF,aAAAA,CAAGC,GAAG,CAACE;AAC3B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-host.mjs","sources":["../../src/utils/format-host.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { identity } from 'lodash
|
|
1
|
+
{"version":3,"file":"format-host.mjs","sources":["../../src/utils/format-host.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport { identity } from 'lodash';\n\nexport const formatHost: ts.FormatDiagnosticsHost = {\n getCanonicalFileName: identity,\n getCurrentDirectory: ts.sys.getCurrentDirectory,\n getNewLine: () => ts.sys.newLine,\n};\n"],"names":["formatHost","getCanonicalFileName","identity","getCurrentDirectory","ts","sys","getNewLine","newLine"],"mappings":";;;MAGaA,UAAAA,GAAuC;IAClDC,oBAAAA,EAAsBC,QAAAA;IACtBC,mBAAAA,EAAqBC,EAAAA,CAAGC,GAAG,CAACF,mBAAmB;AAC/CG,IAAAA,UAAAA,EAAY,IAAMF,EAAAA,CAAGC,GAAG,CAACE;AAC3B;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/typescript-utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.57.0",
|
|
4
4
|
"description": "Typescript support for Strapi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -60,9 +60,9 @@
|
|
|
60
60
|
"@types/jest": "29.5.2",
|
|
61
61
|
"@types/lodash": "^4.14.191",
|
|
62
62
|
"@types/node": "20.19.41",
|
|
63
|
-
"eslint-config-custom": "5.
|
|
63
|
+
"eslint-config-custom": "5.57.0",
|
|
64
64
|
"jest": "29.6.0",
|
|
65
|
-
"tsconfig": "5.
|
|
65
|
+
"tsconfig": "5.57.0"
|
|
66
66
|
},
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=20.0.0 <=26.x.x",
|