type-crafter 0.16.1 → 0.17.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/index.js
CHANGED
|
@@ -21281,6 +21281,31 @@ function escapeReservedWord(input) {
|
|
|
21281
21281
|
}
|
|
21282
21282
|
return input;
|
|
21283
21283
|
}
|
|
21284
|
+
function appendUnique(base, additions) {
|
|
21285
|
+
const seen = new Set();
|
|
21286
|
+
const result = [];
|
|
21287
|
+
const add = (item) => {
|
|
21288
|
+
if (typeof item !== 'string') {
|
|
21289
|
+
return;
|
|
21290
|
+
}
|
|
21291
|
+
const trimmed = item.trim();
|
|
21292
|
+
if (trimmed.length === 0 || seen.has(trimmed)) {
|
|
21293
|
+
return;
|
|
21294
|
+
}
|
|
21295
|
+
seen.add(trimmed);
|
|
21296
|
+
result.push(trimmed);
|
|
21297
|
+
};
|
|
21298
|
+
if (typeof base === 'string') {
|
|
21299
|
+
base.split(',').forEach(add);
|
|
21300
|
+
}
|
|
21301
|
+
if (Array.isArray(additions)) {
|
|
21302
|
+
additions.forEach(add);
|
|
21303
|
+
}
|
|
21304
|
+
else {
|
|
21305
|
+
add(additions);
|
|
21306
|
+
}
|
|
21307
|
+
return result.join(', ');
|
|
21308
|
+
}
|
|
21284
21309
|
function registerTemplateHelpers() {
|
|
21285
21310
|
Handlebars.registerHelper('getOptionalKeys', getOptionalKeys);
|
|
21286
21311
|
Handlebars.registerHelper('getRequiredKeys', getRequiredKeys);
|
|
@@ -21297,6 +21322,7 @@ function registerTemplateHelpers() {
|
|
|
21297
21322
|
Handlebars.registerHelper('variableName', refineVariableName);
|
|
21298
21323
|
Handlebars.registerHelper('indexKey', refineIndexKey);
|
|
21299
21324
|
Handlebars.registerHelper('escapeReservedWord', escapeReservedWord);
|
|
21325
|
+
Handlebars.registerHelper('appendUnique', appendUnique);
|
|
21300
21326
|
Handlebars.registerHelper('stringify', (value) => JSON.stringify(value));
|
|
21301
21327
|
Handlebars.registerHelper('not', (value) => {
|
|
21302
21328
|
if (typeof value === 'boolean') {
|
|
@@ -22547,7 +22573,7 @@ async function runner(language, inputFilePath, outputDirectory, _typesWriterMode
|
|
|
22547
22573
|
}
|
|
22548
22574
|
}
|
|
22549
22575
|
greeting();
|
|
22550
|
-
const program = new Command().version('0.
|
|
22576
|
+
const program = new Command().version('0.17.0');
|
|
22551
22577
|
program
|
|
22552
22578
|
.command('generate')
|
|
22553
22579
|
.description('Generate types for your language from a type spec file')
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{{#if description}}
|
|
2
2
|
/// {{{description}}}
|
|
3
3
|
{{/if}}
|
|
4
|
-
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
4
|
+
#[derive({{{appendUnique "Debug, Clone, Serialize, Deserialize" customAttributes.[x-derive]}}})]
|
|
5
5
|
pub struct {{typeName}} {
|
|
6
6
|
{{#each compositions}}
|
|
7
7
|
{{#if (eq this.source 'referenced')}}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
{{#if example}}
|
|
5
5
|
/// Example: {{{example}}}
|
|
6
6
|
{{/if}}
|
|
7
|
-
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
7
|
+
#[derive({{{appendUnique "Debug, Clone, Serialize, Deserialize" customAttributes.[x-derive]}}})]
|
|
8
8
|
pub enum {{typeName}} {
|
|
9
9
|
{{#each values}}
|
|
10
10
|
{{#if (eq ../type 'string')}}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
{{#if example}}
|
|
5
5
|
/// Example: {{{example}}}
|
|
6
6
|
{{/if}}
|
|
7
|
-
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
7
|
+
#[derive({{{appendUnique "Debug, Clone, Serialize, Deserialize" customAttributes.[x-derive]}}})]
|
|
8
8
|
{{#if customAttributes.renameAll}}
|
|
9
9
|
#[serde(rename_all = "{{{customAttributes.renameAll}}}")]
|
|
10
10
|
{{/if}}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{{#if description}}
|
|
2
2
|
/// {{{description}}}
|
|
3
3
|
{{/if}}
|
|
4
|
-
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
4
|
+
#[derive({{{appendUnique "Debug, Clone, Serialize, Deserialize" customAttributes.[x-derive]}}})]
|
|
5
5
|
#[serde(untagged)]
|
|
6
6
|
pub enum {{typeName}} {
|
|
7
7
|
{{#each compositions}}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare function refineJSONKey(input: unknown): unknown;
|
|
|
17
17
|
export declare function refineVariableName(input: unknown): unknown;
|
|
18
18
|
export declare function refineIndexKey(input: unknown): unknown;
|
|
19
19
|
export declare function escapeReservedWord(input: unknown): unknown;
|
|
20
|
+
export declare function appendUnique(base: unknown, additions: unknown): string;
|
|
20
21
|
export declare function registerTemplateHelpers(): void;
|
|
21
22
|
export declare function readNestedValue(json: unknown, keyPath: string[]): JSONObject;
|
|
22
23
|
export declare function generateRelativePath(fromPath: string, toPath: string): string;
|