From e148c372918e8bddce50676460dc95c20f793eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillem=20C=C3=B3rdoba?= Date: Fri, 27 Jan 2023 21:29:55 +0100 Subject: [PATCH] Improved signal type --- src/templates.rs | 8 ++++++++ .../{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs | 4 +--- .../{{coordinator_zome_manifest.name}}/types.ts.hbs | 6 +++++- .../{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs | 4 +--- .../{{coordinator_zome_manifest.name}}/types.ts.hbs | 7 ++++++- .../{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs | 4 +--- .../{{coordinator_zome_manifest.name}}/types.ts.hbs | 7 ++++++- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/templates.rs b/src/templates.rs index 5ec7b5788..92d700352 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -56,6 +56,7 @@ pub fn register_helpers<'a>(h: Handlebars<'a>) -> Handlebars<'a> { let h = register_contains_helper(h); let h = register_includes_helper(h); let h = register_case_helpers(h); + let h = register_replace_helper(h); let h = register_pluralize_helpers(h); let h = register_merge_scope(h); let h = register_uniq_lines(h); @@ -228,6 +229,13 @@ pub fn register_includes_helper<'a>(mut h: Handlebars<'a>) -> Handlebars<'a> { h } +pub fn register_replace_helper<'a>(mut h: Handlebars<'a>) -> Handlebars<'a> { + handlebars_helper!(replace: |s: String, pattern: String, replaced_by: String| s.replace(&pattern, replaced_by.as_str())); + h.register_helper("replace", Box::new(replace)); + + h +} + pub fn register_pluralize_helpers<'a>(mut h: Handlebars<'a>) -> Handlebars<'a> { handlebars_helper!(singular: |s: String| pluralizer::pluralize(s.as_str(), 1, false)); h.register_helper("singular", Box::new(singular)); diff --git a/templates/lit/coordinator-zome/ui/src/{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs b/templates/lit/coordinator-zome/ui/src/{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs index 25cd51121..042422bd9 100644 --- a/templates/lit/coordinator-zome/ui/src/{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs +++ b/templates/lit/coordinator-zome/ui/src/{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs @@ -34,6 +34,4 @@ export type {{pascal_case zome_manifest.name}}Signal = { link_type: string; }; -export type EntryTypes = { - type: string; -} & any; +export type EntryTypes = {}; diff --git a/templates/lit/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/types.ts.hbs b/templates/lit/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/types.ts.hbs index 6831ab2ca..86db79735 100644 --- a/templates/lit/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/types.ts.hbs +++ b/templates/lit/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/types.ts.hbs @@ -1,4 +1,8 @@ -{{previous_file_content}} +{{#if (includes previous_file_content "export type EntryTypes = {};")}} +{{replace previous_file_content "export type EntryTypes = {};" (concat "export type EntryTypes =\n | ({ type: '" (pascal_case entry_type.name) "'; } & " (pascal_case entry_type.name) ");")}} +{{else}} +{{replace previous_file_content "export type EntryTypes =" (concat "export type EntryTypes =\n | ({ type: '" (pascal_case entry_type.name) "'; } & " (pascal_case entry_type.name) ")")}} +{{/if}} export interface {{pascal_case entry_type.name}} { {{#each entry_type.fields}} {{#if (not (eq cardinality "vector" ) )}} diff --git a/templates/svelte/coordinator-zome/ui/src/{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs b/templates/svelte/coordinator-zome/ui/src/{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs index 25cd51121..042422bd9 100644 --- a/templates/svelte/coordinator-zome/ui/src/{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs +++ b/templates/svelte/coordinator-zome/ui/src/{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs @@ -34,6 +34,4 @@ export type {{pascal_case zome_manifest.name}}Signal = { link_type: string; }; -export type EntryTypes = { - type: string; -} & any; +export type EntryTypes = {}; diff --git a/templates/svelte/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/types.ts.hbs b/templates/svelte/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/types.ts.hbs index 9a1f79616..86db79735 100644 --- a/templates/svelte/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/types.ts.hbs +++ b/templates/svelte/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/types.ts.hbs @@ -1,4 +1,8 @@ -{{previous_file_content}} +{{#if (includes previous_file_content "export type EntryTypes = {};")}} +{{replace previous_file_content "export type EntryTypes = {};" (concat "export type EntryTypes =\n | ({ type: '" (pascal_case entry_type.name) "'; } & " (pascal_case entry_type.name) ");")}} +{{else}} +{{replace previous_file_content "export type EntryTypes =" (concat "export type EntryTypes =\n | ({ type: '" (pascal_case entry_type.name) "'; } & " (pascal_case entry_type.name) ")")}} +{{/if}} export interface {{pascal_case entry_type.name}} { {{#each entry_type.fields}} {{#if (not (eq cardinality "vector" ) )}} @@ -9,3 +13,4 @@ export interface {{pascal_case entry_type.name}} { {{#each entry_type.fields}} {{/each}} } + diff --git a/templates/vue/coordinator-zome/ui/src/{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs b/templates/vue/coordinator-zome/ui/src/{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs index 25cd51121..042422bd9 100644 --- a/templates/vue/coordinator-zome/ui/src/{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs +++ b/templates/vue/coordinator-zome/ui/src/{{dna_role_name}}/{{zome_manifest.name}}/types.ts.hbs @@ -34,6 +34,4 @@ export type {{pascal_case zome_manifest.name}}Signal = { link_type: string; }; -export type EntryTypes = { - type: string; -} & any; +export type EntryTypes = {}; diff --git a/templates/vue/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/types.ts.hbs b/templates/vue/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/types.ts.hbs index 9a1f79616..86db79735 100644 --- a/templates/vue/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/types.ts.hbs +++ b/templates/vue/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/types.ts.hbs @@ -1,4 +1,8 @@ -{{previous_file_content}} +{{#if (includes previous_file_content "export type EntryTypes = {};")}} +{{replace previous_file_content "export type EntryTypes = {};" (concat "export type EntryTypes =\n | ({ type: '" (pascal_case entry_type.name) "'; } & " (pascal_case entry_type.name) ");")}} +{{else}} +{{replace previous_file_content "export type EntryTypes =" (concat "export type EntryTypes =\n | ({ type: '" (pascal_case entry_type.name) "'; } & " (pascal_case entry_type.name) ")")}} +{{/if}} export interface {{pascal_case entry_type.name}} { {{#each entry_type.fields}} {{#if (not (eq cardinality "vector" ) )}} @@ -9,3 +13,4 @@ export interface {{pascal_case entry_type.name}} { {{#each entry_type.fields}} {{/each}} } +