Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add u8 field type support #433

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/scaffold/entry_type/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub enum FieldType {
#[serde(rename = "bool")]
Bool,
String,
#[serde(rename = "u8")]
U8,
#[serde(rename = "u32")]
U32,
#[serde(rename = "i32")]
Expand Down Expand Up @@ -61,6 +63,7 @@ impl std::fmt::Display for FieldType {
let str = match self {
FieldType::Bool => "bool",
FieldType::String => "String",
FieldType::U8 => "u8",
FieldType::U32 => "u32",
FieldType::I32 => "i32",
FieldType::F32 => "f32",
Expand All @@ -81,6 +84,7 @@ impl FieldType {
vec![
FieldType::String,
FieldType::Bool,
FieldType::U8,
FieldType::U32,
FieldType::I32,
FieldType::F32,
Expand Down Expand Up @@ -121,6 +125,7 @@ impl FieldType {
match self {
Bool => quote!(bool),
String => quote!(String),
U8 => quote!(u8),
U32 => quote!(u32),
I32 => quote!(i32),
F32 => quote!(f32),
Expand All @@ -143,6 +148,7 @@ impl FieldType {
match self {
Bool => "boolean",
String => "string",
U8 => "number",
U32 => "number",
I32 => "number",
F32 => "number",
Expand Down Expand Up @@ -515,11 +521,15 @@ impl EntryDefinition {
ts_type
),
Cardinality::Vector => {
format!(
" {}: Array<{}>;",
&field.field_name.to_case(Case::Snake),
ts_type
)
if matches!(field.field_type, FieldType::U8) {
format!(" {}: Uint8Array;", &field.field_name.to_case(Case::Snake),)
} else {
format!(
" {}: Array<{}>;",
&field.field_name.to_case(Case::Snake),
ts_type
)
}
}
};
ts_interface.push_str(&ts_field);
Expand Down
2 changes: 1 addition & 1 deletion templates/generic/field-types/Vec/type.hbs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Array<{{field_type.type}}>
{{#if (eq field_type.type "u8")}}Uint8Array{{else}}Array<{{field_type.type}}>{{/if}}
1 change: 1 addition & 0 deletions templates/generic/field-types/u8/default.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#if (eq cardinality "vector")}}[]{{else}}0{{/if}}
1 change: 1 addition & 0 deletions templates/generic/field-types/u8/sample.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
1 change: 1 addition & 0 deletions templates/generic/field-types/u8/type.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
number
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ export class Create{{pascal_case entry_type.name}} extends LitElement {
{{#if (eq cardinality "option")}}
@property()
{{camel_case field_name}}: {{> (concat field_type.type "/type") }} | undefined;
{{else}}
@property()
{{else}}
{{#if (eq field_type.type "u8")}}
{{camel_case field_name}}!: Uint8Array;
{{else}}
{{camel_case field_name}}!: Array<{{> (concat field_type.type "/type") }}>;

{{/if}}
{{/if}}
{{/if}}
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ interface Create{{pascal_case entry_type.name}}Props {
{{#each entry_type.fields}}
{{#if (not widget) }}
{{#if (eq cardinality "vector")}}
{{#if (eq field_type.type "u8")}}
{{camel_case field_name}}: Uint8Array,
{{else}}
{{camel_case field_name}}: {{> (concat field_type.type "/type") }}[],
{{/if}}
{{else}}
{{camel_case field_name}}{{#if (eq cardinality "single")}}{{/if}}: {{> (concat field_type.type "/type") }}{{#if (eq cardinality "option")}} | undefined{{/if}},
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ let {{camel_case field_name}}: Array<{{> (concat field_type.type "/type")}}> = [
{{#each entry_type.fields}}
{{#if (not widget) }}
{{#if (eq cardinality "vector")}}
{{#if (eq field_type.type "u8")}}
export let {{camel_case field_name}}!: Uint8Array;
{{else}}
export let {{camel_case field_name}}!: Array<{{> (concat field_type.type "/type") }}>;
{{/if}}
{{else}}
export let {{camel_case field_name}}{{#if (eq cardinality "single")}}!{{/if}}: {{> (concat field_type.type "/type") }}{{#if (eq cardinality "option")}} | undefined{{/if}};
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default defineComponent({
{{#if (eq cardinality "single") }}
{{snake_case field_name}}: this.{{camel_case field_name}}!,
{{else}}
{{snake_case field_name}}: this.{{camel_case field_name}}{{#if (eq cardinality "vector") }} as Array<{{> (concat field_type.type "/type") }}>{{/if}},
{{snake_case field_name}}: this.{{camel_case field_name}}{{#if (eq cardinality "vector") }}{{#if field_type.type "u8"}} as Uint8Array{{else}}as Array<{{> (concat field_type.type "/type") }}>{{/if}}{{/if}},
{{/if}}
{{/each}}
};
Expand Down
Loading