Skip to content

Commit

Permalink
Merge branch 'master' into do-sails-js
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit committed Dec 18, 2023
2 parents 3b6c04a + 5a92b78 commit 91bd777
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 82 deletions.
4 changes: 2 additions & 2 deletions idlgen/hbs/composite.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type {{{lookup @root/type_names id}}} = record {
type {{{lookup @root/type_names id}}} = struct {
{{#each fields}}
{{#if name}}{{name}}: {{/if}}{{{lookup @root/type_names type}}};
{{#if name}}{{name}}: {{/if}}{{{lookup @root/type_names type}}},
{{/each}}
};
4 changes: 2 additions & 2 deletions idlgen/hbs/idl_ex.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
{{/each}}
service {
{{#each commands.type.def.variant.variants}}
{{name}} : ({{#with (lookup @root/all_types fields.[0].type)}}{{#each type.def.composite.fields}}{{#if @index}}, {{/if}}{{name}}: {{{lookup @root/type_names type}}}{{/each}}{{/with}}) -> {{{lookup @root/type_names fields.[1].type}}}
{{name}} : ({{#with (lookup @root/all_types fields.[0].type)}}{{#each type.def.composite.fields}}{{#if @index}}, {{/if}}{{name}}: {{{lookup @root/type_names type}}}{{/each}}{{/with}}) -> {{{lookup @root/type_names fields.[1].type}}};
{{/each}}
{{#each queries.type.def.variant.variants}}
query {{name}} : ({{#with (lookup @root/all_types fields.[0].type)}}{{#each type.def.composite.fields}}{{#if @index}}, {{/if}}{{name}}: {{{lookup @root/type_names type}}}{{/each}}{{/with}}) -> {{{lookup @root/type_names fields.[1].type}}}
query {{name}} : ({{#with (lookup @root/all_types fields.[0].type)}}{{#each type.def.composite.fields}}{{#if @index}}, {{/if}}{{name}}: {{{lookup @root/type_names type}}}{{/each}}{{/with}}) -> {{{lookup @root/type_names fields.[1].type}}};
{{/each}}
}
6 changes: 3 additions & 3 deletions idlgen/hbs/variant.hbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
type {{{lookup @root/type_names id}}} = variant {
type {{{lookup @root/type_names id}}} = enum {
{{#each variants}}
{{name}}
{{~#if fields.[1]}}: record { {{#each fields~}} {{#if @index}}; {{/if}}{{#if name}}{{name}}: {{/if}}{{{lookup @root/type_names type}}}{{/each}} }
{{~#if fields.[1]}}: struct { {{#each fields~}} {{#if @index}}, {{/if}}{{#if name}}{{name}}: {{/if}}{{{lookup @root/type_names type}}}{{/each}} }
{{~else}}
{{~#if fields.[0]}}: {{{lookup @root/type_names fields.[0].type}}}
{{~/if}}
{{/if~}}
;
,
{{/each}}
};
146 changes: 73 additions & 73 deletions idlgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,42 +247,42 @@ mod tests {
generate_serivce_idl::<TestCommandProcessorMeta, ()>(None, &mut idl).unwrap();
let generated_idl = String::from_utf8(idl).unwrap();

const EXPECTED_IDL: &str = r"type SailsIdlgenTestsTupleStruct = record {
bool;
const EXPECTED_IDL: &str = r"type SailsIdlgenTestsTupleStruct = struct {
bool,
};
type SailsIdlgenTestsGenericStruct<u32> = record {
p1: u32;
type SailsIdlgenTestsGenericStruct<u32> = struct {
p1: u32,
};
type SailsIdlgenTestsGenericStruct<str> = record {
p1: str;
type SailsIdlgenTestsGenericStruct<str> = struct {
p1: str,
};
type SailsIdlgenTestsDoThatParam = record {
p1: u32;
p2: str;
p3: SailsIdlgenTestsManyVariants;
type SailsIdlgenTestsDoThatParam = struct {
p1: u32,
p2: str,
p3: SailsIdlgenTestsManyVariants,
};
type SailsIdlgenTestsManyVariants = variant {
One;
Two: u32;
Three: opt vec u32;
Four: record { a: u32; b: opt u16 };
Five: record { str; vec u8 };
Six: record { u32 };
Seven: SailsIdlgenTestsGenericEnum<u32, str>;
type SailsIdlgenTestsManyVariants = enum {
One,
Two: u32,
Three: opt vec u32,
Four: struct { a: u32, b: opt u16 },
Five: struct { str, vec u8 },
Six: struct { u32 },
Seven: SailsIdlgenTestsGenericEnum<u32, str>,
};
type SailsIdlgenTestsGenericEnum<u32, str> = variant {
Variant1: u32;
Variant2: str;
type SailsIdlgenTestsGenericEnum<u32, str> = enum {
Variant1: u32,
Variant2: str,
};
service {
async DoThis : (u32, str, record { opt str; u8 }, SailsIdlgenTestsTupleStruct, SailsIdlgenTestsGenericStruct<u32>, SailsIdlgenTestsGenericStruct<str>) -> result (record { str; u32 }, str);
async DoThat : (SailsIdlgenTestsDoThatParam) -> result (record { str; u32 }, record { str });
async DoThis : (u32, str, struct { opt str, u8 }, SailsIdlgenTestsTupleStruct, SailsIdlgenTestsGenericStruct<u32>, SailsIdlgenTestsGenericStruct<str>) -> result (struct { str, u32 }, str);
async DoThat : (SailsIdlgenTestsDoThatParam) -> result (struct { str, u32 }, struct { str });
async Fail : (str) -> result (null, str);
}
";
Expand All @@ -295,37 +295,37 @@ service {
generate_serivce_idl::<(), TestQueryProcessorMeta>(None, &mut idl).unwrap();
let generated_idl = String::from_utf8(idl).unwrap();

const EXPECTED_IDL: &str = r"type SailsIdlgenTestsTupleStruct = record {
bool;
const EXPECTED_IDL: &str = r"type SailsIdlgenTestsTupleStruct = struct {
bool,
};
type SailsIdlgenTestsGenericEnum<bool, u32> = variant {
Variant1: bool;
Variant2: u32;
type SailsIdlgenTestsGenericEnum<bool, u32> = enum {
Variant1: bool,
Variant2: u32,
};
type SailsIdlgenTestsThatParam = record {
p1: SailsIdlgenTestsManyVariants;
type SailsIdlgenTestsThatParam = struct {
p1: SailsIdlgenTestsManyVariants,
};
type SailsIdlgenTestsManyVariants = variant {
One;
Two: u32;
Three: opt vec u32;
Four: record { a: u32; b: opt u16 };
Five: record { str; vec u8 };
Six: record { u32 };
Seven: SailsIdlgenTestsGenericEnum<u32, str>;
type SailsIdlgenTestsManyVariants = enum {
One,
Two: u32,
Three: opt vec u32,
Four: struct { a: u32, b: opt u16 },
Five: struct { str, vec u8 },
Six: struct { u32 },
Seven: SailsIdlgenTestsGenericEnum<u32, str>,
};
type SailsIdlgenTestsGenericEnum<u32, str> = variant {
Variant1: u32;
Variant2: str;
type SailsIdlgenTestsGenericEnum<u32, str> = enum {
Variant1: u32,
Variant2: str,
};
service {
This : (u32, str, record { opt str; u8 }, SailsIdlgenTestsTupleStruct, SailsIdlgenTestsGenericEnum<bool, u32>) -> result (record { str; u32 }, str) query;
That : (SailsIdlgenTestsThatParam) -> result (record { str; u32 }, record { str }) query;
This : (u32, str, struct { opt str, u8 }, SailsIdlgenTestsTupleStruct, SailsIdlgenTestsGenericEnum<bool, u32>) -> result (struct { str, u32 }, str) query;
That : (SailsIdlgenTestsThatParam) -> result (struct { str, u32 }, struct { str }) query;
Fail : (str) -> result (null, str) query;
}
";
Expand All @@ -339,54 +339,54 @@ service {
.unwrap();
let generated_idl = String::from_utf8(idl).unwrap();

const EXPECTED_IDL: &str = r"type SailsIdlgenTestsTupleStruct = record {
bool;
const EXPECTED_IDL: &str = r"type SailsIdlgenTestsTupleStruct = struct {
bool,
};
type SailsIdlgenTestsGenericStruct<u32> = record {
p1: u32;
type SailsIdlgenTestsGenericStruct<u32> = struct {
p1: u32,
};
type SailsIdlgenTestsGenericStruct<str> = record {
p1: str;
type SailsIdlgenTestsGenericStruct<str> = struct {
p1: str,
};
type SailsIdlgenTestsDoThatParam = record {
p1: u32;
p2: str;
p3: SailsIdlgenTestsManyVariants;
type SailsIdlgenTestsDoThatParam = struct {
p1: u32,
p2: str,
p3: SailsIdlgenTestsManyVariants,
};
type SailsIdlgenTestsManyVariants = variant {
One;
Two: u32;
Three: opt vec u32;
Four: record { a: u32; b: opt u16 };
Five: record { str; vec u8 };
Six: record { u32 };
Seven: SailsIdlgenTestsGenericEnum<u32, str>;
type SailsIdlgenTestsManyVariants = enum {
One,
Two: u32,
Three: opt vec u32,
Four: struct { a: u32, b: opt u16 },
Five: struct { str, vec u8 },
Six: struct { u32 },
Seven: SailsIdlgenTestsGenericEnum<u32, str>,
};
type SailsIdlgenTestsGenericEnum<u32, str> = variant {
Variant1: u32;
Variant2: str;
type SailsIdlgenTestsGenericEnum<u32, str> = enum {
Variant1: u32,
Variant2: str,
};
type SailsIdlgenTestsGenericEnum<bool, u32> = variant {
Variant1: bool;
Variant2: u32;
type SailsIdlgenTestsGenericEnum<bool, u32> = enum {
Variant1: bool,
Variant2: u32,
};
type SailsIdlgenTestsThatParam = record {
p1: SailsIdlgenTestsManyVariants;
type SailsIdlgenTestsThatParam = struct {
p1: SailsIdlgenTestsManyVariants,
};
service {
async DoThis : (u32, str, record { opt str; u8 }, SailsIdlgenTestsTupleStruct, SailsIdlgenTestsGenericStruct<u32>, SailsIdlgenTestsGenericStruct<str>) -> result (record { str; u32 }, str);
async DoThat : (SailsIdlgenTestsDoThatParam) -> result (record { str; u32 }, record { str });
async DoThis : (u32, str, struct { opt str, u8 }, SailsIdlgenTestsTupleStruct, SailsIdlgenTestsGenericStruct<u32>, SailsIdlgenTestsGenericStruct<str>) -> result (struct { str, u32 }, str);
async DoThat : (SailsIdlgenTestsDoThatParam) -> result (struct { str, u32 }, struct { str });
async Fail : (str) -> result (null, str);
This : (u32, str, record { opt str; u8 }, SailsIdlgenTestsTupleStruct, SailsIdlgenTestsGenericEnum<bool, u32>) -> result (record { str; u32 }, str) query;
That : (SailsIdlgenTestsThatParam) -> result (record { str; u32 }, record { str }) query;
This : (u32, str, struct { opt str, u8 }, SailsIdlgenTestsTupleStruct, SailsIdlgenTestsGenericEnum<bool, u32>) -> result (struct { str, u32 }, str) query;
That : (SailsIdlgenTestsThatParam) -> result (struct { str, u32 }, struct { str }) query;
Fail : (str) -> result (null, str) query;
}
";
Expand Down
4 changes: 2 additions & 2 deletions idlgen/src/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ fn tuple_type_name(
.iter()
.map(|field| resolve_type_name(type_registry, field.id, resolved_type_names))
.collect::<Result<Vec<_>>>()?
.join("; ");
.join(", ");
if fields.is_empty() {
Ok("null".into()) // For the () type
} else {
Ok(format!("record {{ {} }}", fields))
Ok(format!("struct {{ {} }}", fields))
}
}

Expand Down

0 comments on commit 91bd777

Please sign in to comment.