Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 8 additions & 8 deletions templates/cli/lib/type-generation/languages/csharp.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const { AttributeType } = require('../attribute');
const { LanguageMeta } = require("./language");

class CSharp extends LanguageMeta {
getType(attribute, collections) {
getType(attribute, collections, collectionName) {
let type = "";
switch (attribute.type) {
case AttributeType.STRING:
case AttributeType.EMAIL:
case AttributeType.DATETIME:
type = "string";
if (attribute.format === AttributeType.ENUM) {
type = LanguageMeta.toPascalCase(attribute.key);
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
}
break;
case AttributeType.INTEGER:
Expand Down Expand Up @@ -60,7 +60,7 @@ namespace Appwrite.Models
<% for (const attribute of collection.attributes) { -%>
<% if (attribute.format === 'enum') { -%>

public enum <%- toPascalCase(attribute.key) %> {
public enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %> {
<% for (const [index, element] of Object.entries(attribute.elements) ) { -%>
[JsonPropertyName("<%- element %>")]
<%- toPascalCase(element) %><% if (index < attribute.elements.length - 1) { %>,<% } %>
Expand All @@ -72,13 +72,13 @@ public class <%= toPascalCase(collection.name) %>
{
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
[JsonPropertyName("<%- attribute.key %>")]
public <%- getType(attribute, collections) %> <%= toPascalCase(attribute.key) %> { get; private set; }
public <%- getType(attribute, collections, collection.name) %> <%= toPascalCase(attribute.key) %> { get; private set; }

<% } -%>

public <%= toPascalCase(collection.name) %>(
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
<%- getType(attribute, collections) %> <%= toCamelCase(attribute.key) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
<%- getType(attribute, collections, collection.name) %> <%= toCamelCase(attribute.key) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
<% } -%>
)
{
Expand All @@ -93,9 +93,9 @@ public class <%= toPascalCase(collection.name) %>
// ENUM
if (attribute.format === 'enum') {
if (attribute.array) {
-%>((IEnumerable<object>)map["<%- attribute.key %>"]).Select(e => Enum.Parse<Models.<%- toPascalCase(attribute.key) %>>(e.ToString()!, true)).ToList()<%
-%>((IEnumerable<object>)map["<%- attribute.key %>"]).Select(e => Enum.Parse<Models.<%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>>(e.ToString()!, true)).ToList()<%
} else {
-%>Enum.Parse<Models.<%- toPascalCase(attribute.key) %>>(map["<%- attribute.key %>"].ToString()!, true)<%
-%>Enum.Parse<Models.<%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>>(map["<%- attribute.key %>"].ToString()!, true)<%
}
// RELATIONSHIP
} else if (attribute.type === 'relationship') {
Expand All @@ -122,7 +122,7 @@ public class <%= toPascalCase(collection.name) %>
} else if (attribute.type === 'double') {
-%><%- !attribute.required ? 'map["' + attribute.key + '"] == null ? null : ' : '' %>Convert.ToDouble(map["<%- attribute.key %>"])<%
} else if (attribute.type === 'boolean') {
-%>(<%- getType(attribute, collections) %>)map["<%- attribute.key %>"]<%
-%>(<%- getType(attribute, collections, collection.name) %>)map["<%- attribute.key %>"]<%
} else if (attribute.type === 'string' || attribute.type === 'datetime' || attribute.type === 'email') {
-%>map["<%- attribute.key %>"]<%- !attribute.required ? '?' : '' %>.ToString()<%- attribute.required ? '!' : ''%><%
} else {
Expand Down
14 changes: 7 additions & 7 deletions templates/cli/lib/type-generation/languages/dart.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ class Dart extends LanguageMeta {
return 'appwrite';
}

getType(attribute, collections) {
getType(attribute, collections, collectionName) {
let type = "";
switch (attribute.type) {
case AttributeType.STRING:
case AttributeType.EMAIL:
case AttributeType.DATETIME:
type = "String";
if (attribute.format === AttributeType.ENUM) {
type = LanguageMeta.toPascalCase(attribute.key);
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
}
break;
case AttributeType.INTEGER:
Expand Down Expand Up @@ -103,7 +103,7 @@ import '<%- toSnakeCase(related.name) %>.dart';

<% for (const attribute of __attrs) { -%>
<% if (attribute.format === '${AttributeType.ENUM}') { -%>
enum <%- toPascalCase(attribute.key) %> {
enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %> {
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
<%- strict ? toCamelCase(element) : element %><% if (index < attribute.elements.length - 1) { -%>,<% } %>
<% } -%>
Expand All @@ -113,7 +113,7 @@ enum <%- toPascalCase(attribute.key) %> {
<% } -%>
class <%= toPascalCase(collection.name) %> {
<% for (const [index, attribute] of Object.entries(__attrs)) { -%>
<%- getType(attribute, collections) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
<%- getType(attribute, collections, collection.name) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
<% } -%>

<%= toPascalCase(collection.name) %>({
Expand All @@ -128,10 +128,10 @@ class <%= toPascalCase(collection.name) %> {
<%= strict ? toCamelCase(attribute.key) : attribute.key %>: <% if (attribute.type === '${AttributeType.STRING}' || attribute.type === '${AttributeType.EMAIL}' || attribute.type === '${AttributeType.DATETIME}') { -%>
<% if (attribute.format === '${AttributeType.ENUM}') { -%>
<% if (attribute.array) { -%>
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.name == e)).toList()<% } else { -%>
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.name == e)).toList()<% } else { -%>
<% if (!attribute.required) { -%>
map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.key) %>.values.where((e) => e.name == map['<%= attribute.key %>']).firstOrNull : null<% } else { -%>
<%- toPascalCase(attribute.key) %>.values.firstWhere((e) => e.name == map['<%= attribute.key %>'])<% } -%>
map['<%= attribute.key %>'] != null ? <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>.values.where((e) => e.name == map['<%= attribute.key %>']).firstOrNull : null<% } else { -%>
<%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>.values.firstWhere((e) => e.name == map['<%= attribute.key %>'])<% } -%>
<% } -%>
<% } else { -%>
<% if (attribute.array) { -%>
Expand Down
14 changes: 7 additions & 7 deletions templates/cli/lib/type-generation/languages/java.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const { AttributeType } = require('../attribute');
const { LanguageMeta } = require("./language");

class Java extends LanguageMeta {
getType(attribute, collections) {
getType(attribute, collections, collectionName) {
let type = "";
switch (attribute.type) {
case AttributeType.STRING:
case AttributeType.EMAIL:
case AttributeType.DATETIME:
type = "String";
if (attribute.format === AttributeType.ENUM) {
type = LanguageMeta.toPascalCase(attribute.key);
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
}
break;
case AttributeType.INTEGER:
Expand Down Expand Up @@ -61,7 +61,7 @@ public class <%- toPascalCase(collection.name) %> {
<% for (const attribute of collection.attributes) { -%>
<% if (attribute.format === 'enum') { -%>

public enum <%- toPascalCase(attribute.key) %> {
public enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %> {
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
<%- strict ? toUpperSnakeCase(element) : element %><%- index < attribute.elements.length - 1 ? ',' : ';' %>
<% } -%>
Expand All @@ -70,15 +70,15 @@ public class <%- toPascalCase(collection.name) %> {
<% } -%>
<% } -%>
<% for (const attribute of collection.attributes) { -%>
private <%- getType(attribute, collections) %> <%- strict ? toCamelCase(attribute.key) : attribute.key %>;
private <%- getType(attribute, collections, collection.name) %> <%- strict ? toCamelCase(attribute.key) : attribute.key %>;
<% } -%>

public <%- toPascalCase(collection.name) %>() {
}

public <%- toPascalCase(collection.name) %>(
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
<%- getType(attribute, collections) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %><%- index < collection.attributes.length - 1 ? ',' : '' %>
<%- getType(attribute, collections, collection.name) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %><%- index < collection.attributes.length - 1 ? ',' : '' %>
<% } -%>
) {
<% for (const attribute of collection.attributes) { -%>
Expand All @@ -87,11 +87,11 @@ public class <%- toPascalCase(collection.name) %> {
}

<% for (const attribute of collection.attributes) { -%>
public <%- getType(attribute, collections) %> get<%- toPascalCase(attribute.key) %>() {
public <%- getType(attribute, collections, collection.name) %> get<%- toPascalCase(attribute.key) %>() {
return <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
}

public void set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>) {
public void set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections, collection.name) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>) {
this.<%= strict ? toCamelCase(attribute.key) : attribute.key %> = <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
}

Expand Down
8 changes: 4 additions & 4 deletions templates/cli/lib/type-generation/languages/kotlin.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const { AttributeType } = require('../attribute');
const { LanguageMeta } = require("./language");

class Kotlin extends LanguageMeta {
getType(attribute, collections) {
getType(attribute, collections, collectionName) {
let type = "";
switch (attribute.type) {
case AttributeType.STRING:
case AttributeType.EMAIL:
case AttributeType.DATETIME:
type = "String";
if (attribute.format === AttributeType.ENUM) {
type = LanguageMeta.toPascalCase(attribute.key);
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
}
break;
case AttributeType.INTEGER:
Expand Down Expand Up @@ -61,7 +61,7 @@ import <%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollect

<% for (const attribute of collection.attributes) { -%>
<% if (attribute.format === 'enum') { -%>
enum class <%- toPascalCase(attribute.key) %> {
enum class <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %> {
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
<%- strict ? toUpperSnakeCase(element) : element %><%- index < attribute.elements.length - 1 ? ',' : '' %>
<% } -%>
Expand All @@ -71,7 +71,7 @@ enum class <%- toPascalCase(attribute.key) %> {
<% } -%>
data class <%- toPascalCase(collection.name) %>(
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
val <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
val <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections, collection.name) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
<% } -%>
)
`;
Expand Down
18 changes: 9 additions & 9 deletions templates/cli/lib/type-generation/languages/php.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { AttributeType } = require('../attribute');
const { LanguageMeta } = require("./language");

class PHP extends LanguageMeta {
getType(attribute, collections) {
getType(attribute, collections, collectionName) {
if (attribute.array) {
return "array";
}
Expand All @@ -14,7 +14,7 @@ class PHP extends LanguageMeta {
case AttributeType.DATETIME:
type = "string";
if (attribute.format === AttributeType.ENUM) {
type = LanguageMeta.toPascalCase(attribute.key);
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
}
break;
case AttributeType.INTEGER:
Expand Down Expand Up @@ -60,25 +60,25 @@ use Appwrite\\Models\\<%- toPascalCase(collections.find(c => c.$id === attribute
<% } -%>
<% for (const attribute of collection.attributes) { -%>
<% if (attribute.format === 'enum') { -%>
enum <%- toPascalCase(attribute.key) %>: string {
enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>: string {
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
case <%- strict ? toUpperSnakeCase(element) : element %> = '<%- element %>';
case <%- toUpperSnakeCase(element) %> = '<%- element %>';
<% } -%>
}

<% } -%>
<% } -%>
class <%- toPascalCase(collection.name) %> {
<% for (const attribute of collection.attributes ){ -%>
private <%- getType(attribute, collections) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>;
private <%- getType(attribute, collections, collection.name) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>;
<% } -%>

public function __construct(
<% for (const attribute of collection.attributes ){ -%>
<% if (attribute.required) { -%>
<%- getType(attribute, collections).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
<%- getType(attribute, collections, collection.name).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
<% } else { -%>
?<%- getType(attribute, collections).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
?<%- getType(attribute, collections, collection.name).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
<% } -%>
<% } -%>
) {
Expand All @@ -88,11 +88,11 @@ class <%- toPascalCase(collection.name) %> {
}

<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
public function get<%- toPascalCase(attribute.key) %>(): <%- getType(attribute, collections) %> {
public function get<%- toPascalCase(attribute.key) %>(): <%- getType(attribute, collections, collection.name) %> {
return $this-><%- strict ? toCamelCase(attribute.key) : attribute.key %>;
}

public function set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>): void {
public function set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections, collection.name) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>): void {
$this-><%- strict ? toCamelCase(attribute.key) : attribute.key %> = $<%- strict ? toCamelCase(attribute.key) : attribute.key %>;
}
<% if (index < collection.attributes.length - 1) { %>
Expand Down
Loading
Loading