Skip to content

Commit dfab055

Browse files
authored
Merge pull request #174 from appwrite/dev
chore: regenerate sdk
2 parents 52bc7d0 + 65150b3 commit dfab055

File tree

17 files changed

+118
-35
lines changed

17 files changed

+118
-35
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Change Log
22

3+
## 8.1.1
4+
5+
* Fix circular dependency issue due to usage of `success` method in `utils.js` file from `parser.js` file
6+
* Type generation fixes:
7+
* Add ability to generate types directly to a specific file by passing a file path to `appwrite types output_path`, instead of just a directory
8+
* Fix non-required attributes to not be null if default value is provided
9+
* Fix `Models` import error
10+
* Improve formatting and add auto-generated comments
11+
312
## 8.1.0
413

514
* Add multi-region support to `init` command
@@ -15,7 +24,7 @@
1524

1625
* Add Type generation fixes:
1726
* Properly handle enum attributes in dart, java and kotlin
18-
* Fix initialisation of null attributes in dart's fromMap method
27+
* Fix initialisation of null attributes in dart's fromMap method
1928
* Fix relationships and enums in swift
2029

2130
## 8.0.1

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using
2929

3030
```sh
3131
$ appwrite -v
32-
8.1.0
32+
8.1.1
3333
```
3434

3535
### Install using prebuilt binaries
@@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc
6060
Once the installation completes, you can verify your install using
6161
```
6262
$ appwrite -v
63-
8.1.0
63+
8.1.1
6464
```
6565

6666
## Getting Started

install.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# You can use "View source" of this page to see the full script.
1414

1515
# REPO
16-
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.1.0/appwrite-cli-win-x64.exe"
17-
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.1.0/appwrite-cli-win-arm64.exe"
16+
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.1.1/appwrite-cli-win-x64.exe"
17+
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.1.1/appwrite-cli-win-arm64.exe"
1818

1919
$APPWRITE_BINARY_NAME = "appwrite.exe"
2020

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ printSuccess() {
9797
downloadBinary() {
9898
echo "[2/4] Downloading executable for $OS ($ARCH) ..."
9999

100-
GITHUB_LATEST_VERSION="8.1.0"
100+
GITHUB_LATEST_VERSION="8.1.1"
101101
GITHUB_FILE="appwrite-cli-${OS}-${ARCH}"
102102
GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE"
103103

lib/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class Client {
1616
'x-sdk-name': 'Command Line',
1717
'x-sdk-platform': 'console',
1818
'x-sdk-language': 'cli',
19-
'x-sdk-version': '8.1.0',
20-
'user-agent' : `AppwriteCLI/8.1.0 (${os.type()} ${os.version()}; ${os.arch()})`,
19+
'x-sdk-version': '8.1.1',
20+
'user-agent' : `AppwriteCLI/8.1.1 (${os.type()} ${os.version()}; ${os.arch()})`,
2121
'X-Appwrite-Response-Format' : '1.7.0',
2222
};
2323
}

lib/commands/types.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,22 @@ const typesCommand = actionRunner(async (rawOutputDirectory, {language}) => {
6666

6767
const meta = createLanguageMeta(language);
6868

69-
const outputDirectory = path.resolve(rawOutputDirectory);
69+
const rawOutputPath = rawOutputDirectory;
70+
const outputExt = path.extname(rawOutputPath);
71+
const isFileOutput = !!outputExt;
72+
let outputDirectory = rawOutputPath;
73+
let singleFileDestination = null;
74+
75+
if (isFileOutput) {
76+
if (meta.isSingleFile()) {
77+
// Use the file path directly for single file languages
78+
outputDirectory = path.dirname(rawOutputPath);
79+
singleFileDestination = rawOutputPath;
80+
} else {
81+
throw new Error(`Invalid output path: ${rawOutputPath}. Output path must be a directory for languages that generate multiple files.`);
82+
}
83+
}
84+
7085
if (!fs.existsSync(outputDirectory)) {
7186
log(`Directory: ${outputDirectory} does not exist, creating...`);
7287
fs.mkdirSync(outputDirectory, { recursive: true });
@@ -95,7 +110,7 @@ const typesCommand = actionRunner(async (rawOutputDirectory, {language}) => {
95110
getType: meta.getType
96111
});
97112

98-
const destination = path.join(outputDirectory, meta.getFileName());
113+
const destination = singleFileDestination || path.join(outputDirectory, meta.getFileName());
99114

100115
fs.writeFileSync(destination, content);
101116
log(`Added types to ${destination}`);

lib/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const parseError = (err) => {
120120
} catch {
121121
}
122122

123-
const version = '8.1.0';
123+
const version = '8.1.1';
124124
const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``;
125125
const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud()}`;
126126

lib/type-generation/languages/dart.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,27 @@ class Dart extends LanguageMeta {
4141
return type;
4242
}
4343

44+
getCurrentDirectory() {
45+
return process.cwd();
46+
}
47+
4448
getTemplate() {
4549
return `<% for (const attribute of collection.attributes) { -%>
4650
<% if (attribute.type === 'relationship') { -%>
4751
import '<%- attribute.relatedCollection.toLowerCase() %>.dart';
4852
4953
<% } -%>
5054
<% } -%>
55+
/**
56+
* This file is auto-generated by the Appwrite CLI.
57+
* You can regenerate it by running \`appwrite types -l dart ${this.getCurrentDirectory()}\`.
58+
*/
59+
5160
<% for (const attribute of collection.attributes) { -%>
5261
<% if (attribute.format === 'enum') { -%>
5362
enum <%- toPascalCase(attribute.key) %> {
54-
<% for (const element of attribute.elements) { -%>
55-
<%- toSnakeCase(element) %>,
63+
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
64+
<%- toSnakeCase(element) %><% if (index < attribute.elements.length - 1) { %>,<% } %>
5665
<% } -%>
5766
}
5867
@@ -65,7 +74,7 @@ class <%= toPascalCase(collection.name) %> {
6574
6675
<%= toPascalCase(collection.name) %>({
6776
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
68-
<% if (attribute.required) { %>required <% } %>this.<%= toCamelCase(attribute.key) %>,
77+
<% if (attribute.required) { %>required <% } %>this.<%= toCamelCase(attribute.key) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
6978
<% } -%>
7079
});
7180
@@ -114,7 +123,7 @@ map['<%= attribute.key %>']<% if (!attribute.required) { %> ?? null<% } -%>
114123
map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.relatedCollection) %>.fromMap(map['<%= attribute.key %>']) : null<% } else { -%>
115124
<%- toPascalCase(attribute.relatedCollection) %>.fromMap(map['<%= attribute.key %>'])<% } -%>
116125
<% } -%>
117-
<% } -%>,
126+
<% } -%><% if (index < collection.attributes.length - 1) { %>,<% } %>
118127
<% } -%>
119128
);
120129
}
@@ -136,7 +145,7 @@ map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.relatedCollecti
136145
<% } -%>
137146
<% } else { -%>
138147
<%= toCamelCase(attribute.key) -%>
139-
<% } -%>,
148+
<% } -%><% if (index < collection.attributes.length - 1) { %>,<% } %>
140149
<% } -%>
141150
};
142151
}

lib/type-generation/languages/java.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,18 @@ class Java extends LanguageMeta {
3838
return type;
3939
}
4040

41+
getCurrentDirectory() {
42+
return process.cwd();
43+
}
44+
4145
getTemplate() {
4246
return `package io.appwrite.models;
4347
48+
/**
49+
* This file is auto-generated by the Appwrite CLI.
50+
* You can regenerate it by running \`appwrite types -l java ${this.getCurrentDirectory()}\`.
51+
*/
52+
4453
import java.util.*;
4554
<% for (const attribute of collection.attributes) { -%>
4655
<% if (attribute.type === 'relationship') { -%>

lib/type-generation/languages/javascript.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class JavaScript extends LanguageMeta {
4040
if (attribute.array) {
4141
type += "[]";
4242
}
43-
if (!attribute.required) {
44-
type += "|null|undefined";
43+
if (!attribute.required && attribute.default === null) {
44+
type += "|null";
4545
}
4646
return type;
4747
}
@@ -60,19 +60,26 @@ class JavaScript extends LanguageMeta {
6060
return "appwrite";
6161
}
6262

63+
getCurrentDirectory() {
64+
return process.cwd();
65+
}
66+
6367
getTemplate() {
6468
return `/**
6569
* @typedef {import('${this._getAppwriteDependency()}').Models.Document} Document
6670
*/
6771
72+
/**
73+
* This file is auto-generated by the Appwrite CLI.
74+
* You can regenerate it by running \`appwrite types -l js ${this.getCurrentDirectory()}\`.
75+
*/
6876
<% for (const collection of collections) { %>
6977
/**
7078
* @typedef {Object} <%- toPascalCase(collection.name) %>
7179
<% for (const attribute of collection.attributes) { -%>
7280
* @property {<%- getType(attribute) %>} <%- toCamelCase(attribute.key) %>
7381
<% } -%>
7482
*/
75-
7683
<% } %>`;
7784
}
7885

0 commit comments

Comments
 (0)