type-crafter 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +43 -34
- package/dist/types/index.d.ts +4 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21417,21 +21417,23 @@ function getPrimitiveType(typeName, typeInfo) {
|
|
|
21417
21417
|
return result;
|
|
21418
21418
|
}
|
|
21419
21419
|
async function generateAdditionalPropertiesType(typeName, typeInfo, parentTypes) {
|
|
21420
|
-
let result = null;
|
|
21421
21420
|
const stringKeyType = getPrimitiveType(typeName, {
|
|
21422
21421
|
...placeholderTypeInfo,
|
|
21423
21422
|
type: 'string'
|
|
21424
21423
|
}).templateInput.type;
|
|
21425
21424
|
if (typeof typeInfo.additionalProperties === 'boolean') {
|
|
21426
|
-
|
|
21427
|
-
|
|
21428
|
-
|
|
21429
|
-
|
|
21430
|
-
|
|
21431
|
-
|
|
21432
|
-
|
|
21433
|
-
|
|
21434
|
-
|
|
21425
|
+
return {
|
|
21426
|
+
templateInput: {
|
|
21427
|
+
keyType: stringKeyType,
|
|
21428
|
+
valueType: getPrimitiveType(typeName, {
|
|
21429
|
+
...placeholderTypeInfo,
|
|
21430
|
+
type: 'unknown'
|
|
21431
|
+
}).templateInput.type,
|
|
21432
|
+
valueTypeReferenced: false,
|
|
21433
|
+
valuePrimitiveType: 'unknown',
|
|
21434
|
+
valueComposerType: null
|
|
21435
|
+
},
|
|
21436
|
+
primitives: new Set()
|
|
21435
21437
|
};
|
|
21436
21438
|
}
|
|
21437
21439
|
else if (valueIsKeyedAdditionalProperties(typeInfo.additionalProperties)) {
|
|
@@ -21439,17 +21441,20 @@ async function generateAdditionalPropertiesType(typeName, typeInfo, parentTypes)
|
|
|
21439
21441
|
const generatedValueType = await generateType(typeName + 'ValueType', valueTypeInfo, parentTypes);
|
|
21440
21442
|
const isReferenced = valueTypeInfo.$ref !== null;
|
|
21441
21443
|
const isArray = valueTypeInfo.type === 'array';
|
|
21442
|
-
|
|
21443
|
-
|
|
21444
|
-
|
|
21445
|
-
|
|
21446
|
-
|
|
21447
|
-
|
|
21448
|
-
|
|
21449
|
-
|
|
21450
|
-
|
|
21451
|
-
|
|
21452
|
-
|
|
21444
|
+
return {
|
|
21445
|
+
templateInput: {
|
|
21446
|
+
keyType: getPrimitiveType(typeName, {
|
|
21447
|
+
...placeholderTypeInfo,
|
|
21448
|
+
type: typeInfo.additionalProperties.keyType
|
|
21449
|
+
}).templateInput.type,
|
|
21450
|
+
valueType: generatedValueType.templateInput.type,
|
|
21451
|
+
valueTypeReferenced: isReferenced,
|
|
21452
|
+
valuePrimitiveType: isArray ? 'array' : (valueTypeInfo.type ?? 'object'),
|
|
21453
|
+
valueComposerType: 'composerType' in generatedValueType.templateInput
|
|
21454
|
+
? (generatedValueType.templateInput.composerType ?? null)
|
|
21455
|
+
: null
|
|
21456
|
+
},
|
|
21457
|
+
primitives: generatedValueType.primitives
|
|
21453
21458
|
};
|
|
21454
21459
|
}
|
|
21455
21460
|
else if (valueIsTypeInfo(typeInfo.additionalProperties)) {
|
|
@@ -21457,17 +21462,20 @@ async function generateAdditionalPropertiesType(typeName, typeInfo, parentTypes)
|
|
|
21457
21462
|
const generatedValueType = await generateType(typeName + 'ValueType', valueTypeInfo, parentTypes);
|
|
21458
21463
|
const isReferenced = valueTypeInfo.$ref !== null;
|
|
21459
21464
|
const isArray = valueTypeInfo.type === 'array';
|
|
21460
|
-
|
|
21461
|
-
|
|
21462
|
-
|
|
21463
|
-
|
|
21464
|
-
|
|
21465
|
-
|
|
21466
|
-
|
|
21467
|
-
|
|
21465
|
+
return {
|
|
21466
|
+
templateInput: {
|
|
21467
|
+
keyType: stringKeyType,
|
|
21468
|
+
valueType: generatedValueType.templateInput.type,
|
|
21469
|
+
valueTypeReferenced: isReferenced,
|
|
21470
|
+
valuePrimitiveType: isArray ? 'array' : (valueTypeInfo.type ?? 'object'),
|
|
21471
|
+
valueComposerType: 'composerType' in generatedValueType.templateInput
|
|
21472
|
+
? (generatedValueType.templateInput.composerType ?? null)
|
|
21473
|
+
: null
|
|
21474
|
+
},
|
|
21475
|
+
primitives: generatedValueType.primitives
|
|
21468
21476
|
};
|
|
21469
21477
|
}
|
|
21470
|
-
return
|
|
21478
|
+
return null;
|
|
21471
21479
|
}
|
|
21472
21480
|
async function generateObjectType(typeName, typeInfo, parentTypes) {
|
|
21473
21481
|
const templateInput = {
|
|
@@ -21556,9 +21564,10 @@ async function generateObjectType(typeName, typeInfo, parentTypes) {
|
|
|
21556
21564
|
};
|
|
21557
21565
|
}
|
|
21558
21566
|
// Generating additional property types
|
|
21559
|
-
const
|
|
21560
|
-
if (
|
|
21561
|
-
templateInput.additionalProperties =
|
|
21567
|
+
const additionalPropertiesResult = await generateAdditionalPropertiesType(typeName + 'AdditionalProperty', typeInfo, parentTypes);
|
|
21568
|
+
if (additionalPropertiesResult !== null) {
|
|
21569
|
+
templateInput.additionalProperties = additionalPropertiesResult.templateInput;
|
|
21570
|
+
primitives.push(...additionalPropertiesResult.primitives);
|
|
21562
21571
|
}
|
|
21563
21572
|
const result = {
|
|
21564
21573
|
content: Runtime.getObjectTemplate()(templateInput) +
|
|
@@ -22215,7 +22224,7 @@ async function runner(language, inputFilePath, outputDirectory, _typesWriterMode
|
|
|
22215
22224
|
}
|
|
22216
22225
|
}
|
|
22217
22226
|
greeting();
|
|
22218
|
-
const program = new Command().version('0.12.
|
|
22227
|
+
const program = new Command().version('0.12.2');
|
|
22219
22228
|
program
|
|
22220
22229
|
.command('generate')
|
|
22221
22230
|
.description('Generate types for your language from a type spec file')
|
package/dist/types/index.d.ts
CHANGED
|
@@ -122,6 +122,10 @@ export type AdditionalPropertiesTemplateInput = {
|
|
|
122
122
|
valuePrimitiveType: string;
|
|
123
123
|
valueComposerType: string | null;
|
|
124
124
|
};
|
|
125
|
+
export type AdditionalPropertiesGenerationResult = {
|
|
126
|
+
templateInput: AdditionalPropertiesTemplateInput;
|
|
127
|
+
primitives: Set<string>;
|
|
128
|
+
};
|
|
125
129
|
export type ExporterModuleTemplateInput = {
|
|
126
130
|
modules: string[];
|
|
127
131
|
};
|