@@ -40,9 +40,6 @@ class TypeScript extends LanguageMeta {
40
40
if (attribute.array) {
41
41
type += "[]";
42
42
}
43
- if (!attribute.required) {
44
- type += " | null";
45
- }
46
43
return type;
47
44
}
48
45
@@ -64,15 +61,23 @@ class TypeScript extends LanguageMeta {
64
61
return "appwrite";
65
62
}
66
63
64
+ getCurrentDirectory() {
65
+ return process.cwd();
66
+ }
67
+
67
68
getTemplate() {
68
- return `import { Models } from '${this._getAppwriteDependency()}';
69
+ return `import { type Models } from '${this._getAppwriteDependency()}';
70
+
71
+ // This file is auto-generated by the Appwrite CLI.
72
+ // You can regenerate it by running \`appwrite types -l ts ${this.getCurrentDirectory()}\`.
69
73
70
74
<% for (const collection of collections) { -%>
71
75
<% for (const attribute of collection.attributes) { -%>
72
76
<% if (attribute.format === ' enum' ) { -%>
73
77
export enum <% - toPascalCase(attribute.key) %> {
74
- <% for (const [index, element] of Object .entries(attribute.elements)) { -%>
75
- <% - toUpperSnakeCase(element) %> = "<% - element %> ",
78
+ <% const entries = Object .entries(attribute.elements); -%>
79
+ <% for (let i = 0 ; i < entries.length; i++ ) { -%>
80
+ <% - toUpperSnakeCase(entries[i][1 ]) %> = "<% - entries[i][1 ] %> "<% if (i != = entries.length - 1 ) { %> ,<% } %>
76
81
<% } -%>
77
82
}
78
83
@@ -82,7 +87,7 @@ export enum <%- toPascalCase(attribute.key) %> {
82
87
<% for (const collection of collections) { -%>
83
88
export type <% - toPascalCase(collection.name) %> = Models.Document & {
84
89
<% for (const attribute of collection.attributes) { -%>
85
- <% - toCamelCase(attribute.key) %> : <% - getType(attribute) %> ;
90
+ <% - toCamelCase(attribute.key) %><% if (!attribute.required) { %> ? <% } %> : <% - getType(attribute) %> ;
86
91
<% } -%>
87
92
}
88
93
0 commit comments