appwrite-cli 13.2.1 → 13.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +2 -2
  3. package/dist/bundle-win-arm64.mjs +311 -81
  4. package/dist/cli.cjs +311 -81
  5. package/dist/index.js +119 -18
  6. package/dist/lib/commands/config-validations.d.ts +1 -1
  7. package/dist/lib/commands/config.d.ts +24 -0
  8. package/dist/lib/commands/config.d.ts.map +1 -1
  9. package/dist/lib/commands/generate.d.ts.map +1 -1
  10. package/dist/lib/commands/generators/typescript/databases.d.ts.map +1 -1
  11. package/dist/lib/commands/generic.d.ts +2 -4
  12. package/dist/lib/commands/generic.d.ts.map +1 -1
  13. package/dist/lib/commands/utils/attributes.d.ts.map +1 -1
  14. package/dist/lib/constants.d.ts +1 -1
  15. package/dist/lib/questions.d.ts +1 -0
  16. package/dist/lib/questions.d.ts.map +1 -1
  17. package/dist/lib/shared/typescript-type-utils.d.ts +5 -0
  18. package/dist/lib/shared/typescript-type-utils.d.ts.map +1 -1
  19. package/dist/lib/type-generation/attribute.d.ts +4 -0
  20. package/dist/lib/type-generation/attribute.d.ts.map +1 -1
  21. package/dist/lib/type-generation/languages/csharp.d.ts.map +1 -1
  22. package/dist/lib/type-generation/languages/dart.d.ts.map +1 -1
  23. package/dist/lib/type-generation/languages/java.d.ts.map +1 -1
  24. package/dist/lib/type-generation/languages/javascript.d.ts.map +1 -1
  25. package/dist/lib/type-generation/languages/kotlin.d.ts.map +1 -1
  26. package/dist/lib/type-generation/languages/php.d.ts.map +1 -1
  27. package/dist/lib/type-generation/languages/swift.d.ts.map +1 -1
  28. package/install.ps1 +2 -2
  29. package/install.sh +1 -1
  30. package/lib/commands/config-validations.ts +3 -3
  31. package/lib/commands/config.ts +10 -2
  32. package/lib/commands/generate.ts +4 -2
  33. package/lib/commands/generators/typescript/databases.ts +9 -5
  34. package/lib/commands/generators/typescript/templates/databases.ts.hbs +3 -3
  35. package/lib/commands/generators/typescript/templates/index.ts.hbs +2 -2
  36. package/lib/commands/generic.ts +211 -76
  37. package/lib/commands/push.ts +1 -1
  38. package/lib/commands/utils/attributes.ts +70 -0
  39. package/lib/config.ts +4 -4
  40. package/lib/constants.ts +1 -1
  41. package/lib/questions.ts +3 -1
  42. package/lib/shared/typescript-type-utils.ts +30 -0
  43. package/lib/type-generation/attribute.ts +4 -0
  44. package/lib/type-generation/languages/csharp.ts +6 -2
  45. package/lib/type-generation/languages/dart.ts +5 -1
  46. package/lib/type-generation/languages/java.ts +4 -0
  47. package/lib/type-generation/languages/javascript.ts +4 -0
  48. package/lib/type-generation/languages/kotlin.ts +4 -0
  49. package/lib/type-generation/languages/php.ts +4 -0
  50. package/lib/type-generation/languages/swift.ts +8 -4
  51. package/package.json +1 -1
  52. package/scoop/appwrite.config.json +3 -3
package/dist/cli.cjs CHANGED
@@ -93392,7 +93392,7 @@ var package_default = {
93392
93392
  type: "module",
93393
93393
  homepage: "https://appwrite.io/support",
93394
93394
  description: "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API",
93395
- version: "13.2.1",
93395
+ version: "13.3.1",
93396
93396
  license: "BSD-3-Clause",
93397
93397
  main: "dist/index.js",
93398
93398
  types: "dist/index.d.ts",
@@ -107247,7 +107247,7 @@ var validateRequiredDefault = (data) => {
107247
107247
  return true;
107248
107248
  };
107249
107249
  var validateStringSize = (data) => {
107250
- if (data.type !== "string") {
107250
+ if (data.type !== "string" && data.type !== "varchar") {
107251
107251
  return true;
107252
107252
  }
107253
107253
  if (data.format && data.format !== "") {
@@ -107479,6 +107479,10 @@ var AttributeSchema = external_exports.object({
107479
107479
  key: external_exports.string(),
107480
107480
  type: external_exports.enum([
107481
107481
  "string",
107482
+ "text",
107483
+ "varchar",
107484
+ "mediumtext",
107485
+ "longtext",
107482
107486
  "integer",
107483
107487
  "double",
107484
107488
  "boolean",
@@ -107513,7 +107517,7 @@ var AttributeSchema = external_exports.object({
107513
107517
  message: "When 'required' is true, 'default' must be null",
107514
107518
  path: ["default"]
107515
107519
  }).refine(validateStringSize, {
107516
- message: "When 'type' is 'string', 'size' must be defined",
107520
+ message: "When 'type' is 'string' or 'varchar', 'size' must be defined",
107517
107521
  path: ["size"]
107518
107522
  });
107519
107523
  var IndexSchema = external_exports.object({
@@ -107537,6 +107541,10 @@ var ColumnSchema = external_exports.object({
107537
107541
  key: external_exports.string(),
107538
107542
  type: external_exports.enum([
107539
107543
  "string",
107544
+ "text",
107545
+ "varchar",
107546
+ "mediumtext",
107547
+ "longtext",
107540
107548
  "integer",
107541
107549
  "double",
107542
107550
  "boolean",
@@ -107572,7 +107580,7 @@ var ColumnSchema = external_exports.object({
107572
107580
  message: "When 'required' is true, 'default' must be null",
107573
107581
  path: ["default"]
107574
107582
  }).refine(validateStringSize, {
107575
- message: "When 'type' is 'string', 'size' must be defined",
107583
+ message: "When 'type' is 'string' or 'varchar', 'size' must be defined",
107576
107584
  path: ["size"]
107577
107585
  });
107578
107586
  var IndexTableSchema = external_exports.object({
@@ -107648,7 +107656,7 @@ var import_undici = __toESM(require_undici(), 1);
107648
107656
  // lib/constants.ts
107649
107657
  var SDK_TITLE = "Appwrite";
107650
107658
  var SDK_TITLE_LOWER = "appwrite";
107651
- var SDK_VERSION = "13.2.1";
107659
+ var SDK_VERSION = "13.3.1";
107652
107660
  var SDK_NAME = "Command Line";
107653
107661
  var SDK_PLATFORM = "console";
107654
107662
  var SDK_LANGUAGE = "cli";
@@ -109721,14 +109729,14 @@ var Global = class _Global extends Config {
109721
109729
  const sessionMap = /* @__PURE__ */ new Map();
109722
109730
  sessions.forEach((sessionId) => {
109723
109731
  const sessionData = this.data[sessionId];
109724
- const email3 = sessionData[_Global.PREFERENCE_EMAIL];
109725
- const endpoint = sessionData[_Global.PREFERENCE_ENDPOINT];
109732
+ const email3 = sessionData[_Global.PREFERENCE_EMAIL] ?? "";
109733
+ const endpoint = sessionData[_Global.PREFERENCE_ENDPOINT] ?? "";
109726
109734
  const key = `${email3}|${endpoint}`;
109727
109735
  if (sessionId === current || !sessionMap.has(key)) {
109728
109736
  sessionMap.set(key, {
109729
109737
  id: sessionId,
109730
- endpoint: sessionData[_Global.PREFERENCE_ENDPOINT],
109731
- email: sessionData[_Global.PREFERENCE_EMAIL]
109738
+ endpoint,
109739
+ email: email3
109732
109740
  });
109733
109741
  }
109734
109742
  });
@@ -135288,7 +135296,7 @@ var questionsLogin = [
135288
135296
  when: (answers) => answers.method !== "select"
135289
135297
  },
135290
135298
  {
135291
- type: "search-list",
135299
+ type: "list",
135292
135300
  name: "accountId",
135293
135301
  message: "Select an account to use",
135294
135302
  choices() {
@@ -135303,6 +135311,7 @@ var questionsLogin = [
135303
135311
  data.push({
135304
135312
  current: current === session.id,
135305
135313
  value: session.id,
135314
+ short: `${session.email} (${session.endpoint})`,
135306
135315
  name: `${session.email.padEnd(longestEmail)} ${current === session.id ? import_chalk2.default.green.bold("current") : " ".repeat(6)} ${session.endpoint}`
135307
135316
  });
135308
135317
  }
@@ -135911,6 +135920,88 @@ var client_default = Client3;
135911
135920
 
135912
135921
  // lib/commands/generic.ts
135913
135922
  var DEFAULT_ENDPOINT2 = "https://cloud.appwrite.io/v1";
135923
+ var isMfaRequiredError = (err) => err?.type === "user_more_factors_required" || err?.response === "user_more_factors_required";
135924
+ var createLegacyConsoleClient = (endpoint) => {
135925
+ const legacyClient = new client_default();
135926
+ legacyClient.setEndpoint(endpoint);
135927
+ legacyClient.setProject("console");
135928
+ if (globalConfig2.getSelfSigned()) {
135929
+ legacyClient.setSelfSigned(true);
135930
+ }
135931
+ return legacyClient;
135932
+ };
135933
+ var completeMfaLogin = async ({
135934
+ client: client2,
135935
+ legacyClient,
135936
+ mfa,
135937
+ code
135938
+ }) => {
135939
+ let accountClient2 = new Account(client2);
135940
+ const savedCookie = globalConfig2.getCookie();
135941
+ if (savedCookie) {
135942
+ legacyClient.setCookie(savedCookie);
135943
+ client2.setCookie(savedCookie);
135944
+ }
135945
+ const { factor } = mfa ? { factor: mfa } : await import_inquirer.default.prompt(questionsListFactors);
135946
+ const challenge = await accountClient2.createMfaChallenge(factor);
135947
+ const { otp } = code ? { otp: code } : await import_inquirer.default.prompt(questionsMFAChallenge);
135948
+ await legacyClient.call(
135949
+ "PUT",
135950
+ "/account/mfa/challenges",
135951
+ {
135952
+ "content-type": "application/json"
135953
+ },
135954
+ {
135955
+ challengeId: challenge.$id,
135956
+ otp
135957
+ }
135958
+ );
135959
+ const updatedCookie = globalConfig2.getCookie();
135960
+ if (updatedCookie) {
135961
+ client2.setCookie(updatedCookie);
135962
+ }
135963
+ accountClient2 = new Account(client2);
135964
+ return accountClient2.get();
135965
+ };
135966
+ var deleteServerSession = async (sessionId) => {
135967
+ try {
135968
+ let client2 = await sdkForConsole();
135969
+ let accountClient2 = new Account(client2);
135970
+ await accountClient2.deleteSession(sessionId);
135971
+ return true;
135972
+ } catch (e) {
135973
+ return false;
135974
+ }
135975
+ };
135976
+ var deleteLocalSession = (accountId) => {
135977
+ globalConfig2.removeSession(accountId);
135978
+ };
135979
+ var getSessionAccountKey = (sessionId) => {
135980
+ const session = globalConfig2.get(sessionId);
135981
+ if (!session) return void 0;
135982
+ return `${session.email ?? ""}|${session.endpoint ?? ""}`;
135983
+ };
135984
+ var planSessionLogout = (selectedSessionIds) => {
135985
+ const sessionIdsByAccount = /* @__PURE__ */ new Map();
135986
+ for (const sessionId of globalConfig2.getSessionIds()) {
135987
+ const key = getSessionAccountKey(sessionId);
135988
+ if (!key) continue;
135989
+ const ids = sessionIdsByAccount.get(key) ?? [];
135990
+ ids.push(sessionId);
135991
+ sessionIdsByAccount.set(key, ids);
135992
+ }
135993
+ const selectedByAccount = /* @__PURE__ */ new Map();
135994
+ for (const selectedSessionId of selectedSessionIds) {
135995
+ const key = getSessionAccountKey(selectedSessionId);
135996
+ if (!key || selectedByAccount.has(key)) continue;
135997
+ selectedByAccount.set(key, selectedSessionId);
135998
+ }
135999
+ const serverTargets = Array.from(selectedByAccount.values());
136000
+ const localTargets = Array.from(selectedByAccount.keys()).flatMap(
136001
+ (accountKey) => sessionIdsByAccount.get(accountKey) ?? []
136002
+ );
136003
+ return { serverTargets, localTargets };
136004
+ };
135914
136005
  var loginCommand = async ({
135915
136006
  email: email3,
135916
136007
  password,
@@ -135936,7 +136027,25 @@ var loginCommand = async ({
135936
136027
  throw Error("Session ID not found");
135937
136028
  }
135938
136029
  globalConfig2.setCurrentSession(accountId);
135939
- success2(`Current account is ${accountId}`);
136030
+ const client3 = await sdkForConsole(false);
136031
+ const accountClient3 = new Account(client3);
136032
+ const legacyClient2 = createLegacyConsoleClient(
136033
+ globalConfig2.getEndpoint() || DEFAULT_ENDPOINT2
136034
+ );
136035
+ try {
136036
+ await accountClient3.get();
136037
+ } catch (err) {
136038
+ if (!isMfaRequiredError(err)) {
136039
+ throw err;
136040
+ }
136041
+ await completeMfaLogin({
136042
+ client: client3,
136043
+ legacyClient: legacyClient2,
136044
+ mfa,
136045
+ code
136046
+ });
136047
+ }
136048
+ success2(`Switched to ${globalConfig2.getEmail()}`);
135940
136049
  return;
135941
136050
  }
135942
136051
  const id = id_default2.unique();
@@ -135944,12 +136053,7 @@ var loginCommand = async ({
135944
136053
  globalConfig2.setCurrentSession(id);
135945
136054
  globalConfig2.setEndpoint(configEndpoint);
135946
136055
  globalConfig2.setEmail(answers.email);
135947
- const legacyClient = new client_default();
135948
- legacyClient.setEndpoint(configEndpoint);
135949
- legacyClient.setProject("console");
135950
- if (globalConfig2.getSelfSigned()) {
135951
- legacyClient.setSelfSigned(true);
135952
- }
136056
+ const legacyClient = createLegacyConsoleClient(configEndpoint);
135953
136057
  let client2 = await sdkForConsole(false);
135954
136058
  let accountClient2 = new Account(client2);
135955
136059
  let account2;
@@ -135973,27 +136077,13 @@ var loginCommand = async ({
135973
136077
  accountClient2 = new Account(client2);
135974
136078
  account2 = await accountClient2.get();
135975
136079
  } catch (err) {
135976
- if (err.type === "user_more_factors_required" || err.response === "user_more_factors_required") {
135977
- const { factor } = mfa ? { factor: mfa } : await import_inquirer.default.prompt(questionsListFactors);
135978
- const challenge = await accountClient2.createMfaChallenge(factor);
135979
- const { otp } = code ? { otp: code } : await import_inquirer.default.prompt(questionsMFAChallenge);
135980
- await legacyClient.call(
135981
- "PUT",
135982
- "/account/mfa/challenges",
135983
- {
135984
- "content-type": "application/json"
135985
- },
135986
- {
135987
- challengeId: challenge.$id,
135988
- otp
135989
- }
135990
- );
135991
- const savedCookie = globalConfig2.getCookie();
135992
- if (savedCookie) {
135993
- client2.setCookie(savedCookie);
135994
- }
135995
- accountClient2 = new Account(client2);
135996
- account2 = await accountClient2.get();
136080
+ if (isMfaRequiredError(err)) {
136081
+ account2 = await completeMfaLogin({
136082
+ client: client2,
136083
+ legacyClient,
136084
+ mfa,
136085
+ code
136086
+ });
135997
136087
  } else {
135998
136088
  globalConfig2.removeSession(id);
135999
136089
  globalConfig2.setCurrentSession(oldCurrent);
@@ -136053,49 +136143,59 @@ var login = new Command("login").description(commandDescriptions["login"]).optio
136053
136143
  ).option(`--code [code]`, `Multi-factor code`).configureHelp({
136054
136144
  helpWidth: process.stdout.columns || 80
136055
136145
  }).action(actionRunner(loginCommand));
136056
- var deleteSession = async (accountId) => {
136057
- try {
136058
- let client2 = await sdkForConsole();
136059
- let accountClient2 = new Account(client2);
136060
- await accountClient2.deleteSession("current");
136061
- } catch (e) {
136062
- error48("Unable to log out, removing locally saved session information");
136063
- } finally {
136064
- globalConfig2.removeSession(accountId);
136065
- }
136066
- };
136067
136146
  var logout = new Command("logout").description(commandDescriptions["logout"]).configureHelp({
136068
136147
  helpWidth: process.stdout.columns || 80
136069
136148
  }).action(
136070
136149
  actionRunner(async () => {
136071
136150
  const sessions = globalConfig2.getSessions();
136072
136151
  const current = globalConfig2.getCurrentSession();
136152
+ const originalCurrent = current;
136073
136153
  if (current === "" || !sessions.length) {
136074
136154
  log("No active sessions found.");
136075
136155
  return;
136076
136156
  }
136077
136157
  if (sessions.length === 1) {
136078
- await deleteSession(current);
136158
+ const serverDeleted = await deleteServerSession(current);
136159
+ const allSessionIds = globalConfig2.getSessionIds();
136160
+ for (const sessId of allSessionIds) {
136161
+ deleteLocalSession(sessId);
136162
+ }
136079
136163
  globalConfig2.setCurrentSession("");
136080
- success2("Logging out");
136164
+ if (!serverDeleted) {
136165
+ hint("Could not reach server, removed local session data");
136166
+ }
136167
+ success2("Logged out successfully");
136081
136168
  return;
136082
136169
  }
136083
136170
  const answers = await import_inquirer.default.prompt(questionsLogout);
136084
- if (answers.accounts) {
136085
- for (let accountId of answers.accounts) {
136086
- globalConfig2.setCurrentSession(accountId);
136087
- await deleteSession(accountId);
136171
+ if (answers.accounts?.length) {
136172
+ const { serverTargets, localTargets } = planSessionLogout(
136173
+ answers.accounts
136174
+ );
136175
+ for (const sessionId of serverTargets) {
136176
+ globalConfig2.setCurrentSession(sessionId);
136177
+ await deleteServerSession(sessionId);
136178
+ }
136179
+ for (const sessionId of localTargets) {
136180
+ deleteLocalSession(sessionId);
136088
136181
  }
136089
136182
  }
136090
136183
  const remainingSessions = globalConfig2.getSessions();
136091
- if (remainingSessions.length > 0 && remainingSessions.filter((session) => session.id === current).length !== 1) {
136092
- const accountId = remainingSessions[0].id;
136093
- globalConfig2.setCurrentSession(accountId);
136094
- success2(`Current account is ${accountId}`);
136184
+ const hasCurrent = remainingSessions.some(
136185
+ (session) => session.id === originalCurrent
136186
+ );
136187
+ if (remainingSessions.length > 0 && hasCurrent) {
136188
+ globalConfig2.setCurrentSession(originalCurrent);
136189
+ } else if (remainingSessions.length > 0) {
136190
+ const nextSession = remainingSessions.find((session) => session.email) ?? remainingSessions[0];
136191
+ globalConfig2.setCurrentSession(nextSession.id);
136192
+ success2(
136193
+ nextSession.email ? `Switched to ${nextSession.email}` : `Switched to session at ${nextSession.endpoint}`
136194
+ );
136095
136195
  } else if (remainingSessions.length === 0) {
136096
136196
  globalConfig2.setCurrentSession("");
136097
136197
  }
136098
- success2("Logging out");
136198
+ success2("Logged out successfully");
136099
136199
  })
136100
136200
  );
136101
136201
  var client = new Command("client").description(commandDescriptions["client"]).configureHelp({
@@ -136188,10 +136288,14 @@ var client = new Command("client").description(commandDescriptions["client"]).co
136188
136288
  }
136189
136289
  if (reset !== void 0) {
136190
136290
  const sessions = globalConfig2.getSessions();
136191
- for (let accountId of sessions.map((session) => session.id)) {
136192
- globalConfig2.setCurrentSession(accountId);
136193
- await deleteSession(accountId);
136291
+ for (const sessionId of sessions.map((session) => session.id)) {
136292
+ globalConfig2.setCurrentSession(sessionId);
136293
+ await deleteServerSession(sessionId);
136194
136294
  }
136295
+ for (const sessionId of globalConfig2.getSessionIds()) {
136296
+ deleteLocalSession(sessionId);
136297
+ }
136298
+ globalConfig2.setCurrentSession("");
136195
136299
  }
136196
136300
  if (!debug) {
136197
136301
  success2("Setting client");
@@ -137828,6 +137932,10 @@ function detectLanguage() {
137828
137932
  // lib/type-generation/attribute.ts
137829
137933
  var AttributeType = {
137830
137934
  STRING: "string",
137935
+ TEXT: "text",
137936
+ VARCHAR: "varchar",
137937
+ MEDIUMTEXT: "mediumtext",
137938
+ LONGTEXT: "longtext",
137831
137939
  INTEGER: "integer",
137832
137940
  FLOAT: "double",
137833
137941
  BOOLEAN: "boolean",
@@ -137851,6 +137959,10 @@ var PHP = class extends LanguageMeta {
137851
137959
  let type = "";
137852
137960
  switch (attribute.type) {
137853
137961
  case AttributeType.STRING:
137962
+ case AttributeType.TEXT:
137963
+ case AttributeType.VARCHAR:
137964
+ case AttributeType.MEDIUMTEXT:
137965
+ case AttributeType.LONGTEXT:
137854
137966
  case AttributeType.DATETIME:
137855
137967
  type = "string";
137856
137968
  if (attribute.format === AttributeType.ENUM) {
@@ -137958,6 +138070,10 @@ function getTypeScriptType(attribute, entities, entityName, forCreate = false) {
137958
138070
  let type = "";
137959
138071
  switch (attribute.type) {
137960
138072
  case "string":
138073
+ case "text":
138074
+ case "varchar":
138075
+ case "mediumtext":
138076
+ case "longtext":
137961
138077
  case "datetime":
137962
138078
  type = "string";
137963
138079
  if (attribute.format === "enum") {
@@ -138036,6 +138152,22 @@ function getAppwriteDependency() {
138036
138152
  }
138037
138153
  return "appwrite";
138038
138154
  }
138155
+ function detectImportExtension(cwd = process.cwd()) {
138156
+ try {
138157
+ const pkgPath = path6.resolve(cwd, "package.json");
138158
+ if (fs7.existsSync(pkgPath)) {
138159
+ const pkg = JSON.parse(fs7.readFileSync(pkgPath, "utf-8"));
138160
+ if (pkg.type === "module") {
138161
+ return ".js";
138162
+ }
138163
+ }
138164
+ if (fs7.existsSync(path6.resolve(cwd, "deno.json")) || fs7.existsSync(path6.resolve(cwd, "deno.jsonc"))) {
138165
+ return ".ts";
138166
+ }
138167
+ } catch {
138168
+ }
138169
+ return "";
138170
+ }
138039
138171
  function supportsServerSideMethods(appwriteDep, override = "auto") {
138040
138172
  if (override === "true") return true;
138041
138173
  if (override === "false") return false;
@@ -138130,6 +138262,10 @@ var Kotlin = class extends LanguageMeta {
138130
138262
  let type = "";
138131
138263
  switch (attribute.type) {
138132
138264
  case AttributeType.STRING:
138265
+ case AttributeType.TEXT:
138266
+ case AttributeType.VARCHAR:
138267
+ case AttributeType.MEDIUMTEXT:
138268
+ case AttributeType.LONGTEXT:
138133
138269
  case AttributeType.DATETIME:
138134
138270
  type = "String";
138135
138271
  if (attribute.format === AttributeType.ENUM) {
@@ -138218,6 +138354,10 @@ var Swift = class extends LanguageMeta {
138218
138354
  let type = "";
138219
138355
  switch (attribute.type) {
138220
138356
  case AttributeType.STRING:
138357
+ case AttributeType.TEXT:
138358
+ case AttributeType.VARCHAR:
138359
+ case AttributeType.MEDIUMTEXT:
138360
+ case AttributeType.LONGTEXT:
138221
138361
  case AttributeType.DATETIME:
138222
138362
  type = "String";
138223
138363
  if (attribute.format === AttributeType.ENUM) {
@@ -138328,7 +138468,7 @@ public class <%- toPascalCase(collection.name) %>: Codable {
138328
138468
  <% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
138329
138469
  <% if (attribute.type === 'relationship') { -%>
138330
138470
  "<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %> as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
138331
- <% } else if (attribute.array && attribute.type !== 'string' && attribute.type !== 'integer' && attribute.type !== 'float' && attribute.type !== 'boolean') { -%>
138471
+ <% } else if (attribute.array && !['string', 'text', 'varchar', 'mediumtext', 'longtext', 'integer', 'float', 'boolean'].includes(attribute.type)) { -%>
138332
138472
  "<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %>?.map { $0.toMap() } as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
138333
138473
  <% } else { -%>
138334
138474
  "<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %> as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
@@ -138344,7 +138484,7 @@ public class <%- toPascalCase(collection.name) %>: Codable {
138344
138484
  <% const relationshipType = getType(attribute, collections, collection.name).replace('?', ''); -%>
138345
138485
  <%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> <%- relationshipType %><% if (index < collection.attributes.length - 1) { %>,<% } %>
138346
138486
  <% } else if (attribute.array) { -%>
138347
- <% if (attribute.type === 'string') { -%>
138487
+ <% if (['string', 'text', 'varchar', 'mediumtext', 'longtext'].includes(attribute.type)) { -%>
138348
138488
  <%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [String]<% if (index < collection.attributes.length - 1) { %>,<% } %>
138349
138489
  <% } else if (attribute.type === 'integer') { -%>
138350
138490
  <%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Int]<% if (index < collection.attributes.length - 1) { %>,<% } %>
@@ -138356,9 +138496,9 @@ public class <%- toPascalCase(collection.name) %>: Codable {
138356
138496
  <%- strict ? toCamelCase(attribute.key) : attribute.key %>: (map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [[String: Any]])<% if (!attribute.required) { %>?<% } %>.map { <%- toPascalCase(attribute.type) %>.from(map: $0) }<% if (index < collection.attributes.length - 1) { %>,<% } %>
138357
138497
  <% } -%>
138358
138498
  <% } else { -%>
138359
- <% if ((attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime') && attribute.format !== 'enum') { -%>
138499
+ <% if (['string', 'text', 'varchar', 'mediumtext', 'longtext', 'email', 'datetime'].includes(attribute.type) && attribute.format !== 'enum') { -%>
138360
138500
  <%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> String<% if (index < collection.attributes.length - 1) { %>,<% } %>
138361
- <% } else if (attribute.type === 'string' && attribute.format === 'enum') { -%>
138501
+ <% } else if (['string', 'text', 'varchar', 'mediumtext', 'longtext'].includes(attribute.type) && attribute.format === 'enum') { -%>
138362
138502
  <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>(rawValue: map["<%- attribute.key %>"] as! String)!<% if (index < collection.attributes.length - 1) { %>,<% } %>
138363
138503
  <% } else if (attribute.type === 'integer') { -%>
138364
138504
  <%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Int<% if (index < collection.attributes.length - 1) { %>,<% } %>
@@ -138386,6 +138526,10 @@ var Java = class extends LanguageMeta {
138386
138526
  let type = "";
138387
138527
  switch (attribute.type) {
138388
138528
  case AttributeType.STRING:
138529
+ case AttributeType.TEXT:
138530
+ case AttributeType.VARCHAR:
138531
+ case AttributeType.MEDIUMTEXT:
138532
+ case AttributeType.LONGTEXT:
138389
138533
  case AttributeType.DATETIME:
138390
138534
  type = "String";
138391
138535
  if (attribute.format === AttributeType.ENUM) {
@@ -138566,6 +138710,10 @@ var Dart = class extends LanguageMeta {
138566
138710
  let type = "";
138567
138711
  switch (attribute.type) {
138568
138712
  case AttributeType.STRING:
138713
+ case AttributeType.TEXT:
138714
+ case AttributeType.VARCHAR:
138715
+ case AttributeType.MEDIUMTEXT:
138716
+ case AttributeType.LONGTEXT:
138569
138717
  case AttributeType.DATETIME:
138570
138718
  type = "String";
138571
138719
  if (attribute.format === AttributeType.ENUM) {
@@ -138670,7 +138818,7 @@ class <%= toPascalCase(collection.name) %> {
138670
138818
  factory <%= toPascalCase(collection.name) %>.fromMap(Map<String, dynamic> map) {
138671
138819
  return <%= toPascalCase(collection.name) %>(<% if (__attrs.length > 0) { %>
138672
138820
  <% for (const [index, attribute] of Object.entries(__attrs)) { -%>
138673
- <%= strict ? toCamelCase(attribute.key) : attribute.key %>: <% if (attribute.type === '${AttributeType.STRING}' || attribute.type === '${AttributeType.EMAIL}' || attribute.type === '${AttributeType.DATETIME}') { -%>
138821
+ <%= strict ? toCamelCase(attribute.key) : attribute.key %>: <% if (['${AttributeType.STRING}', '${AttributeType.TEXT}', '${AttributeType.VARCHAR}', '${AttributeType.MEDIUMTEXT}', '${AttributeType.LONGTEXT}', '${AttributeType.EMAIL}', '${AttributeType.DATETIME}'].includes(attribute.type)) { -%>
138674
138822
  <% if (attribute.format === '${AttributeType.ENUM}') { -%>
138675
138823
  <% if (attribute.array) { -%>
138676
138824
  (map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.value == e)).toList()<% } else { -%>
@@ -138741,6 +138889,10 @@ var JavaScript = class extends LanguageMeta {
138741
138889
  let type = "";
138742
138890
  switch (attribute.type) {
138743
138891
  case AttributeType.STRING:
138892
+ case AttributeType.TEXT:
138893
+ case AttributeType.VARCHAR:
138894
+ case AttributeType.MEDIUMTEXT:
138895
+ case AttributeType.LONGTEXT:
138744
138896
  case AttributeType.DATETIME:
138745
138897
  type = "string";
138746
138898
  if (attribute.format === AttributeType.ENUM) {
@@ -138839,6 +138991,10 @@ var CSharp = class extends LanguageMeta {
138839
138991
  let type = "";
138840
138992
  switch (attribute.type) {
138841
138993
  case AttributeType.STRING:
138994
+ case AttributeType.TEXT:
138995
+ case AttributeType.VARCHAR:
138996
+ case AttributeType.MEDIUMTEXT:
138997
+ case AttributeType.LONGTEXT:
138842
138998
  case AttributeType.DATETIME:
138843
138999
  type = "string";
138844
139000
  if (attribute.format === AttributeType.ENUM) {
@@ -138946,7 +139102,7 @@ public class <%= toPascalCase(collection.name) %>
138946
139102
  }
138947
139103
  // ARRAY TYPES
138948
139104
  } else if (attribute.array) {
138949
- if (attribute.type === 'string' || attribute.type === 'datetime' || attribute.type === 'email') {
139105
+ if (['string', 'text', 'varchar', 'mediumtext', 'longtext', 'datetime', 'email'].includes(attribute.type)) {
138950
139106
  -%>((IEnumerable<object>)map["<%- attribute.key %>"]).Select(x => x?.ToString())<%- attribute.required ? '.Where(x => x != null)' : '' %>.ToList()!<%
138951
139107
  } else if (attribute.type === 'integer') {
138952
139108
  -%>((IEnumerable<object>)map["<%- attribute.key %>"]).Select(x => <%- !attribute.required ? 'x == null ? (long?)null : ' : '' %>Convert.ToInt64(x)).ToList()<%
@@ -138962,7 +139118,7 @@ public class <%= toPascalCase(collection.name) %>
138962
139118
  -%><%- !attribute.required ? 'map["' + attribute.key + '"] == null ? null : ' : '' %>Convert.ToDouble(map["<%- attribute.key %>"])<%
138963
139119
  } else if (attribute.type === 'boolean') {
138964
139120
  -%>(<%- getType(attribute, collections, collection.name) %>)map["<%- attribute.key %>"]<%
138965
- } else if (attribute.type === 'string' || attribute.type === 'datetime' || attribute.type === 'email') {
139121
+ } else if (['string', 'text', 'varchar', 'mediumtext', 'longtext', 'datetime', 'email'].includes(attribute.type)) {
138966
139122
  -%>map["<%- attribute.key %>"]<%- !attribute.required ? '?' : '' %>.ToString()<%- attribute.required ? '!' : ''%><%
138967
139123
  } else {
138968
139124
  -%>default<%
@@ -140672,6 +140828,43 @@ var Attributes = class {
140672
140828
  encrypt: attribute.encrypt
140673
140829
  });
140674
140830
  }
140831
+ case "varchar":
140832
+ return databasesService.createVarcharAttribute({
140833
+ databaseId,
140834
+ collectionId,
140835
+ key: attribute.key,
140836
+ size: attribute.size,
140837
+ required: attribute.required,
140838
+ xdefault: attribute.default,
140839
+ array: attribute.array
140840
+ });
140841
+ case "text":
140842
+ return databasesService.createTextAttribute({
140843
+ databaseId,
140844
+ collectionId,
140845
+ key: attribute.key,
140846
+ required: attribute.required,
140847
+ xdefault: attribute.default,
140848
+ array: attribute.array
140849
+ });
140850
+ case "mediumtext":
140851
+ return databasesService.createMediumtextAttribute({
140852
+ databaseId,
140853
+ collectionId,
140854
+ key: attribute.key,
140855
+ required: attribute.required,
140856
+ xdefault: attribute.default,
140857
+ array: attribute.array
140858
+ });
140859
+ case "longtext":
140860
+ return databasesService.createLongtextAttribute({
140861
+ databaseId,
140862
+ collectionId,
140863
+ key: attribute.key,
140864
+ required: attribute.required,
140865
+ xdefault: attribute.default,
140866
+ array: attribute.array
140867
+ });
140675
140868
  case "integer":
140676
140869
  return databasesService.createIntegerAttribute({
140677
140870
  databaseId,
@@ -140798,6 +140991,39 @@ var Attributes = class {
140798
140991
  xdefault: attribute.default
140799
140992
  });
140800
140993
  }
140994
+ case "varchar":
140995
+ return databasesService.updateVarcharAttribute({
140996
+ databaseId,
140997
+ collectionId,
140998
+ key: attribute.key,
140999
+ required: attribute.required,
141000
+ xdefault: attribute.default,
141001
+ size: attribute.size
141002
+ });
141003
+ case "text":
141004
+ return databasesService.updateTextAttribute({
141005
+ databaseId,
141006
+ collectionId,
141007
+ key: attribute.key,
141008
+ required: attribute.required,
141009
+ xdefault: attribute.default
141010
+ });
141011
+ case "mediumtext":
141012
+ return databasesService.updateMediumtextAttribute({
141013
+ databaseId,
141014
+ collectionId,
141015
+ key: attribute.key,
141016
+ required: attribute.required,
141017
+ xdefault: attribute.default
141018
+ });
141019
+ case "longtext":
141020
+ return databasesService.updateLongtextAttribute({
141021
+ databaseId,
141022
+ collectionId,
141023
+ key: attribute.key,
141024
+ required: attribute.required,
141025
+ xdefault: attribute.default
141026
+ });
140801
141027
  case "integer":
140802
141028
  return databasesService.updateIntegerAttribute({
140803
141029
  databaseId,
@@ -143022,7 +143248,7 @@ var pushCollection = async () => {
143022
143248
  const result = await pushInstance.pushCollections(collections);
143023
143249
  const { successfullyPushed, errors } = result;
143024
143250
  if (successfullyPushed === 0) {
143025
- error48("No collections were pushed.");
143251
+ warn("No collections were pushed.");
143026
143252
  } else {
143027
143253
  success2(`Successfully pushed ${successfullyPushed} collections.`);
143028
143254
  }
@@ -143528,10 +143754,10 @@ var BaseDatabasesGenerator = class {
143528
143754
  var types_ts_default = "import { type Models } from '{{appwriteDep}}';\n\n{{{ENUMS}}}{{{TYPES}}}\ndeclare const __roleStringBrand: unique symbol;\nexport type RoleString = string & { readonly [__roleStringBrand]: never };\n\nexport type RoleBuilder = {\n any: () => RoleString;\n user: (userId: string, status?: string) => RoleString;\n users: (status?: string) => RoleString;\n guests: () => RoleString;\n team: (teamId: string, role?: string) => RoleString;\n member: (memberId: string) => RoleString;\n label: (label: string) => RoleString;\n}\n\nexport type PermissionBuilder = {\n read: (role: RoleString) => string;\n write: (role: RoleString) => string;\n create: (role: RoleString) => string;\n update: (role: RoleString) => string;\n delete: (role: RoleString) => string;\n}\n\nexport type PermissionCallback = (permission: PermissionBuilder, role: RoleBuilder) => string[];\n\nexport type QueryValue = string | number | boolean;\n\nexport type ExtractQueryValue<T> = T extends (infer U)[]\n ? U extends QueryValue ? U : never\n : T extends QueryValue | null ? NonNullable<T> : never;\n\nexport type QueryableKeys<T> = {\n [K in keyof T]: ExtractQueryValue<T[K]> extends never ? never : K;\n}[keyof T];\n\nexport type QueryBuilder<T> = {\n equal: <K extends QueryableKeys<T>>(field: K, value: ExtractQueryValue<T[K]>) => string;\n notEqual: <K extends QueryableKeys<T>>(field: K, value: ExtractQueryValue<T[K]>) => string;\n lessThan: <K extends QueryableKeys<T>>(field: K, value: ExtractQueryValue<T[K]>) => string;\n lessThanEqual: <K extends QueryableKeys<T>>(field: K, value: ExtractQueryValue<T[K]>) => string;\n greaterThan: <K extends QueryableKeys<T>>(field: K, value: ExtractQueryValue<T[K]>) => string;\n greaterThanEqual: <K extends QueryableKeys<T>>(field: K, value: ExtractQueryValue<T[K]>) => string;\n contains: <K extends QueryableKeys<T>>(field: K, value: ExtractQueryValue<T[K]>) => string;\n search: <K extends QueryableKeys<T>>(field: K, value: string) => string;\n isNull: <K extends QueryableKeys<T>>(field: K) => string;\n isNotNull: <K extends QueryableKeys<T>>(field: K) => string;\n startsWith: <K extends QueryableKeys<T>>(field: K, value: string) => string;\n endsWith: <K extends QueryableKeys<T>>(field: K, value: string) => string;\n between: <K extends QueryableKeys<T>>(field: K, start: ExtractQueryValue<T[K]>, end: ExtractQueryValue<T[K]>) => string;\n select: <K extends keyof T>(fields: K[]) => string;\n orderAsc: <K extends keyof T>(field: K) => string;\n orderDesc: <K extends keyof T>(field: K) => string;\n limit: (value: number) => string;\n offset: (value: number) => string;\n cursorAfter: (documentId: string) => string;\n cursorBefore: (documentId: string) => string;\n or: (...queries: string[]) => string;\n and: (...queries: string[]) => string;\n}\n\nexport type DatabaseId = {{{databaseIdType}}};\n\n{{{DATABASE_TABLES_TYPE}}}\n";
143529
143755
 
143530
143756
  // lib/commands/generators/typescript/templates/databases.ts.hbs
143531
- var databases_ts_default = 'import { Client, TablesDB, ID, Query, type Models, Permission, Role } from \'{{appwriteDep}}\';\nimport type { DatabaseHandle, DatabaseId, DatabaseTableMap, DatabaseTables, QueryBuilder, PermissionBuilder, RoleBuilder, RoleString } from \'./types.js\';\n{{#if supportsServerSide}}\nimport { PROJECT_ID, ENDPOINT, API_KEY } from \'./constants.js\';\n{{else}}\nimport { PROJECT_ID, ENDPOINT } from \'./constants.js\';\n{{/if}}\n\nconst createQueryBuilder = <T>(): QueryBuilder<T> => ({\n equal: (field, value) => Query.equal(String(field), value as any),\n notEqual: (field, value) => Query.notEqual(String(field), value as any),\n lessThan: (field, value) => Query.lessThan(String(field), value as any),\n lessThanEqual: (field, value) => Query.lessThanEqual(String(field), value as any),\n greaterThan: (field, value) => Query.greaterThan(String(field), value as any),\n greaterThanEqual: (field, value) => Query.greaterThanEqual(String(field), value as any),\n contains: (field, value) => Query.contains(String(field), value as any),\n search: (field, value) => Query.search(String(field), value),\n isNull: (field) => Query.isNull(String(field)),\n isNotNull: (field) => Query.isNotNull(String(field)),\n startsWith: (field, value) => Query.startsWith(String(field), value),\n endsWith: (field, value) => Query.endsWith(String(field), value),\n between: (field, start, end) => Query.between(String(field), start as any, end as any),\n select: (fields) => Query.select(fields.map(String)),\n orderAsc: (field) => Query.orderAsc(String(field)),\n orderDesc: (field) => Query.orderDesc(String(field)),\n limit: (value) => Query.limit(value),\n offset: (value) => Query.offset(value),\n cursorAfter: (documentId) => Query.cursorAfter(documentId),\n cursorBefore: (documentId) => Query.cursorBefore(documentId),\n or: (...queries) => Query.or(queries),\n and: (...queries) => Query.and(queries),\n});\n\n{{{TABLE_ID_MAP}}}\n\n{{{TABLES_WITH_RELATIONSHIPS}}}\n\nconst roleBuilder: RoleBuilder = {\n any: () => Role.any() as RoleString,\n user: (userId, status?) => Role.user(userId, status) as RoleString,\n users: (status?) => Role.users(status) as RoleString,\n guests: () => Role.guests() as RoleString,\n team: (teamId, role?) => Role.team(teamId, role) as RoleString,\n member: (memberId) => Role.member(memberId) as RoleString,\n label: (label) => Role.label(label) as RoleString,\n};\n\nconst permissionBuilder: PermissionBuilder = {\n read: (role) => Permission.read(role),\n write: (role) => Permission.write(role),\n create: (role) => Permission.create(role),\n update: (role) => Permission.update(role),\n delete: (role) => Permission.delete(role),\n};\n\nconst resolvePermissions = (callback?: (permission: { read: (role: RoleString) => string; write: (role: RoleString) => string; create: (role: RoleString) => string; update: (role: RoleString) => string; delete: (role: RoleString) => string }, role: { any: () => RoleString; user: (userId: string, status?: string) => RoleString; users: (status?: string) => RoleString; guests: () => RoleString; team: (teamId: string, role?: string) => RoleString; member: (memberId: string) => RoleString; label: (label: string) => RoleString }) => string[]): string[] | undefined =>\n callback?.(permissionBuilder, roleBuilder);\n\nfunction createTableApi<T extends Models.Row>(\n tablesDB: TablesDB,\n databaseId: string,\n tableId: string,\n) {\n return {\n create: (data: any, options?: { rowId?: string; permissions?: (permission: { read: (role: RoleString) => string; write: (role: RoleString) => string; create: (role: RoleString) => string; update: (role: RoleString) => string; delete: (role: RoleString) => string }, role: { any: () => RoleString; user: (userId: string, status?: string) => RoleString; users: (status?: string) => RoleString; guests: () => RoleString; team: (teamId: string, role?: string) => RoleString; member: (memberId: string) => RoleString; label: (label: string) => RoleString }) => string[]; transactionId?: string }) =>\n tablesDB.createRow<T>({\n databaseId,\n tableId,\n rowId: options?.rowId ?? ID.unique(),\n data,\n permissions: resolvePermissions(options?.permissions),\n transactionId: options?.transactionId,\n }),\n get: (id: string) =>\n tablesDB.getRow<T>({\n databaseId,\n tableId,\n rowId: id,\n }),\n update: (id: string, data: any, options?: { permissions?: (permission: { read: (role: RoleString) => string; write: (role: RoleString) => string; create: (role: RoleString) => string; update: (role: RoleString) => string; delete: (role: RoleString) => string }, role: { any: () => RoleString; user: (userId: string, status?: string) => RoleString; users: (status?: string) => RoleString; guests: () => RoleString; team: (teamId: string, role?: string) => RoleString; member: (memberId: string) => RoleString; label: (label: string) => RoleString }) => string[]; transactionId?: string }) =>\n tablesDB.updateRow<T>({\n databaseId,\n tableId,\n rowId: id,\n data,\n ...(options?.permissions ? { permissions: resolvePermissions(options.permissions) } : {}),\n transactionId: options?.transactionId,\n }),\n delete: async (id: string, options?: { transactionId?: string }) => {\n await tablesDB.deleteRow({\n databaseId,\n tableId,\n rowId: id,\n transactionId: options?.transactionId,\n });\n },\n list: (options?: { queries?: (q: any) => string[] }) =>\n tablesDB.listRows<T>({\n databaseId,\n tableId,\n queries: options?.queries?.(createQueryBuilder<T>()),\n }),{{{BULK_METHODS}}}\n };\n}\n\n{{{BULK_CHECK}}}\nconst hasOwn = (obj: unknown, key: string): boolean =>\n obj != null && Object.prototype.hasOwnProperty.call(obj, key);\n\nfunction createDatabaseHandle<D extends DatabaseId>(\n tablesDB: TablesDB,\n databaseId: D,\n): DatabaseHandle<D> {\n const tableApiCache = new Map<string, unknown>();\n const dbMap = tableIdMap[databaseId];\n\n return {\n use: <T extends keyof DatabaseTableMap[D] & string>(tableId: T): DatabaseTableMap[D][T] => {\n if (!hasOwn(dbMap, tableId)) {\n throw new Error(`Unknown table "${tableId}" in database "${databaseId}"`);\n }\n\n if (!tableApiCache.has(tableId)) {\n const resolvedTableId = dbMap[tableId];\n const api = createTableApi(tablesDB, databaseId, resolvedTableId);\n {{{BULK_REMOVAL}}}\n tableApiCache.set(tableId, api);\n }\n return tableApiCache.get(tableId) as DatabaseTableMap[D][T];\n },\n{{#if supportsServerSide}}\n create: (tableId: string, name: string, options?: { permissions?: (permission: { read: (role: RoleString) => string; write: (role: RoleString) => string; create: (role: RoleString) => string; update: (role: RoleString) => string; delete: (role: RoleString) => string }, role: { any: () => RoleString; user: (userId: string, status?: string) => RoleString; users: (status?: string) => RoleString; guests: () => RoleString; team: (teamId: string, role?: string) => RoleString; member: (memberId: string) => RoleString; label: (label: string) => RoleString }) => string[]; rowSecurity?: boolean; enabled?: boolean; columns?: any[]; indexes?: any[] }) =>\n tablesDB.createTable({\n databaseId,\n tableId,\n name,\n permissions: resolvePermissions(options?.permissions),\n rowSecurity: options?.rowSecurity,\n enabled: options?.enabled,\n columns: options?.columns,\n indexes: options?.indexes,\n }),\n update: (tableId: string, options?: { name?: string; permissions?: (permission: { read: (role: RoleString) => string; write: (role: RoleString) => string; create: (role: RoleString) => string; update: (role: RoleString) => string; delete: (role: RoleString) => string }, role: { any: () => RoleString; user: (userId: string, status?: string) => RoleString; users: (status?: string) => RoleString; guests: () => RoleString; team: (teamId: string, role?: string) => RoleString; member: (memberId: string) => RoleString; label: (label: string) => RoleString }) => string[]; rowSecurity?: boolean; enabled?: boolean }) => {\n if (!hasOwn(dbMap, tableId)) {\n throw new Error(`Unknown table "${tableId}" in database "${databaseId}"`);\n }\n const resolvedTableId = dbMap[tableId];\n return tablesDB.updateTable({\n databaseId,\n tableId: resolvedTableId,\n name: options?.name ?? tableId, // TODO: remove this fallback once fixed in other SDKs\n permissions: resolvePermissions(options?.permissions),\n rowSecurity: options?.rowSecurity,\n enabled: options?.enabled,\n });\n },\n delete: async (tableId: string) => {\n if (!hasOwn(dbMap, tableId)) {\n throw new Error(`Unknown table "${tableId}" in database "${databaseId}"`);\n }\n const resolvedTableId = dbMap[tableId];\n await tablesDB.deleteTable({\n databaseId,\n tableId: resolvedTableId,\n });\n },\n{{/if}}\n };\n}\n\nfunction createDatabasesApi(tablesDB: TablesDB): DatabaseTables {\n const dbCache = new Map<DatabaseId, ReturnType<typeof createDatabaseHandle>>();\n\n return {\n use: (databaseId: DatabaseId) => {\n if (!hasOwn(tableIdMap, databaseId)) {\n throw new Error(`Unknown database "${databaseId}"`);\n }\n\n if (!dbCache.has(databaseId)) {\n dbCache.set(databaseId, createDatabaseHandle(tablesDB, databaseId));\n }\n return dbCache.get(databaseId);\n },\n{{#if supportsServerSide}}\n create: (databaseId: string, name: string, options?: { enabled?: boolean }) =>\n tablesDB.create({\n databaseId,\n name,\n enabled: options?.enabled,\n }),\n update: (databaseId: DatabaseId, options?: { name?: string; enabled?: boolean }) => {\n return tablesDB.update({\n databaseId,\n name: options?.name ?? databaseId,\n enabled: options?.enabled,\n });\n },\n delete: async (databaseId: DatabaseId) => {\n await tablesDB.delete({\n databaseId,\n });\n },\n{{/if}}\n } as DatabaseTables;\n}\n\n// Initialize client\nconst client = new Client()\n .setEndpoint(ENDPOINT)\n .setProject(PROJECT_ID){{#if supportsServerSide}}\n .setKey(API_KEY){{/if}};\n\nconst tablesDB = new TablesDB(client);\n\nexport const databases: DatabaseTables = createDatabasesApi(tablesDB);\n';
143757
+ var databases_ts_default = 'import { Client, TablesDB, ID, Query, type Models, Permission, Role } from \'{{appwriteDep}}\';\nimport type { DatabaseHandle, DatabaseId, DatabaseTableMap, DatabaseTables, QueryBuilder, PermissionBuilder, RoleBuilder, RoleString } from \'./types{{importExt}}\';\n{{#if supportsServerSide}}\nimport { PROJECT_ID, ENDPOINT, API_KEY } from \'./constants{{importExt}}\';\n{{else}}\nimport { PROJECT_ID, ENDPOINT } from \'./constants{{importExt}}\';\n{{/if}}\n\nconst createQueryBuilder = <T>(): QueryBuilder<T> => ({\n equal: (field, value) => Query.equal(String(field), value as any),\n notEqual: (field, value) => Query.notEqual(String(field), value as any),\n lessThan: (field, value) => Query.lessThan(String(field), value as any),\n lessThanEqual: (field, value) => Query.lessThanEqual(String(field), value as any),\n greaterThan: (field, value) => Query.greaterThan(String(field), value as any),\n greaterThanEqual: (field, value) => Query.greaterThanEqual(String(field), value as any),\n contains: (field, value) => Query.contains(String(field), value as any),\n search: (field, value) => Query.search(String(field), value),\n isNull: (field) => Query.isNull(String(field)),\n isNotNull: (field) => Query.isNotNull(String(field)),\n startsWith: (field, value) => Query.startsWith(String(field), value),\n endsWith: (field, value) => Query.endsWith(String(field), value),\n between: (field, start, end) => Query.between(String(field), start as any, end as any),\n select: (fields) => Query.select(fields.map(String)),\n orderAsc: (field) => Query.orderAsc(String(field)),\n orderDesc: (field) => Query.orderDesc(String(field)),\n limit: (value) => Query.limit(value),\n offset: (value) => Query.offset(value),\n cursorAfter: (documentId) => Query.cursorAfter(documentId),\n cursorBefore: (documentId) => Query.cursorBefore(documentId),\n or: (...queries) => Query.or(queries),\n and: (...queries) => Query.and(queries),\n});\n\n{{{TABLE_ID_MAP}}}\n\n{{{TABLES_WITH_RELATIONSHIPS}}}\n\nconst roleBuilder: RoleBuilder = {\n any: () => Role.any() as RoleString,\n user: (userId, status?) => Role.user(userId, status) as RoleString,\n users: (status?) => Role.users(status) as RoleString,\n guests: () => Role.guests() as RoleString,\n team: (teamId, role?) => Role.team(teamId, role) as RoleString,\n member: (memberId) => Role.member(memberId) as RoleString,\n label: (label) => Role.label(label) as RoleString,\n};\n\nconst permissionBuilder: PermissionBuilder = {\n read: (role) => Permission.read(role),\n write: (role) => Permission.write(role),\n create: (role) => Permission.create(role),\n update: (role) => Permission.update(role),\n delete: (role) => Permission.delete(role),\n};\n\nconst resolvePermissions = (callback?: (permission: { read: (role: RoleString) => string; write: (role: RoleString) => string; create: (role: RoleString) => string; update: (role: RoleString) => string; delete: (role: RoleString) => string }, role: { any: () => RoleString; user: (userId: string, status?: string) => RoleString; users: (status?: string) => RoleString; guests: () => RoleString; team: (teamId: string, role?: string) => RoleString; member: (memberId: string) => RoleString; label: (label: string) => RoleString }) => string[]): string[] | undefined =>\n callback?.(permissionBuilder, roleBuilder);\n\nfunction createTableApi<T extends Models.Row>(\n tablesDB: TablesDB,\n databaseId: string,\n tableId: string,\n) {\n return {\n create: (data: any, options?: { rowId?: string; permissions?: (permission: { read: (role: RoleString) => string; write: (role: RoleString) => string; create: (role: RoleString) => string; update: (role: RoleString) => string; delete: (role: RoleString) => string }, role: { any: () => RoleString; user: (userId: string, status?: string) => RoleString; users: (status?: string) => RoleString; guests: () => RoleString; team: (teamId: string, role?: string) => RoleString; member: (memberId: string) => RoleString; label: (label: string) => RoleString }) => string[]; transactionId?: string }) =>\n tablesDB.createRow<T>({\n databaseId,\n tableId,\n rowId: options?.rowId ?? ID.unique(),\n data,\n permissions: resolvePermissions(options?.permissions),\n transactionId: options?.transactionId,\n }),\n get: (id: string) =>\n tablesDB.getRow<T>({\n databaseId,\n tableId,\n rowId: id,\n }),\n update: (id: string, data: any, options?: { permissions?: (permission: { read: (role: RoleString) => string; write: (role: RoleString) => string; create: (role: RoleString) => string; update: (role: RoleString) => string; delete: (role: RoleString) => string }, role: { any: () => RoleString; user: (userId: string, status?: string) => RoleString; users: (status?: string) => RoleString; guests: () => RoleString; team: (teamId: string, role?: string) => RoleString; member: (memberId: string) => RoleString; label: (label: string) => RoleString }) => string[]; transactionId?: string }) =>\n tablesDB.updateRow<T>({\n databaseId,\n tableId,\n rowId: id,\n data,\n ...(options?.permissions ? { permissions: resolvePermissions(options.permissions) } : {}),\n transactionId: options?.transactionId,\n }),\n delete: async (id: string, options?: { transactionId?: string }) => {\n await tablesDB.deleteRow({\n databaseId,\n tableId,\n rowId: id,\n transactionId: options?.transactionId,\n });\n },\n list: (options?: { queries?: (q: any) => string[] }) =>\n tablesDB.listRows<T>({\n databaseId,\n tableId,\n queries: options?.queries?.(createQueryBuilder<T>()),\n }),{{{BULK_METHODS}}}\n };\n}\n\n{{{BULK_CHECK}}}\nconst hasOwn = (obj: unknown, key: string): boolean =>\n obj != null && Object.prototype.hasOwnProperty.call(obj, key);\n\nfunction createDatabaseHandle<D extends DatabaseId>(\n tablesDB: TablesDB,\n databaseId: D,\n): DatabaseHandle<D> {\n const tableApiCache = new Map<string, unknown>();\n const dbMap = tableIdMap[databaseId];\n\n return {\n use: <T extends keyof DatabaseTableMap[D] & string>(tableId: T): DatabaseTableMap[D][T] => {\n if (!hasOwn(dbMap, tableId)) {\n throw new Error(`Unknown table "${tableId}" in database "${databaseId}"`);\n }\n\n if (!tableApiCache.has(tableId)) {\n const resolvedTableId = dbMap[tableId];\n const api = createTableApi(tablesDB, databaseId, resolvedTableId);\n {{{BULK_REMOVAL}}}\n tableApiCache.set(tableId, api);\n }\n return tableApiCache.get(tableId) as DatabaseTableMap[D][T];\n },\n{{#if supportsServerSide}}\n create: (tableId: string, name: string, options?: { permissions?: (permission: { read: (role: RoleString) => string; write: (role: RoleString) => string; create: (role: RoleString) => string; update: (role: RoleString) => string; delete: (role: RoleString) => string }, role: { any: () => RoleString; user: (userId: string, status?: string) => RoleString; users: (status?: string) => RoleString; guests: () => RoleString; team: (teamId: string, role?: string) => RoleString; member: (memberId: string) => RoleString; label: (label: string) => RoleString }) => string[]; rowSecurity?: boolean; enabled?: boolean; columns?: any[]; indexes?: any[] }) =>\n tablesDB.createTable({\n databaseId,\n tableId,\n name,\n permissions: resolvePermissions(options?.permissions),\n rowSecurity: options?.rowSecurity,\n enabled: options?.enabled,\n columns: options?.columns,\n indexes: options?.indexes,\n }),\n update: (tableId: string, options?: { name?: string; permissions?: (permission: { read: (role: RoleString) => string; write: (role: RoleString) => string; create: (role: RoleString) => string; update: (role: RoleString) => string; delete: (role: RoleString) => string }, role: { any: () => RoleString; user: (userId: string, status?: string) => RoleString; users: (status?: string) => RoleString; guests: () => RoleString; team: (teamId: string, role?: string) => RoleString; member: (memberId: string) => RoleString; label: (label: string) => RoleString }) => string[]; rowSecurity?: boolean; enabled?: boolean }) => {\n if (!hasOwn(dbMap, tableId)) {\n throw new Error(`Unknown table "${tableId}" in database "${databaseId}"`);\n }\n const resolvedTableId = dbMap[tableId];\n return tablesDB.updateTable({\n databaseId,\n tableId: resolvedTableId,\n name: options?.name ?? tableId, // TODO: remove this fallback once fixed in other SDKs\n permissions: resolvePermissions(options?.permissions),\n rowSecurity: options?.rowSecurity,\n enabled: options?.enabled,\n });\n },\n delete: async (tableId: string) => {\n if (!hasOwn(dbMap, tableId)) {\n throw new Error(`Unknown table "${tableId}" in database "${databaseId}"`);\n }\n const resolvedTableId = dbMap[tableId];\n await tablesDB.deleteTable({\n databaseId,\n tableId: resolvedTableId,\n });\n },\n{{/if}}\n };\n}\n\nfunction createDatabasesApi(tablesDB: TablesDB): DatabaseTables {\n const dbCache = new Map<DatabaseId, ReturnType<typeof createDatabaseHandle>>();\n\n return {\n use: (databaseId: DatabaseId) => {\n if (!hasOwn(tableIdMap, databaseId)) {\n throw new Error(`Unknown database "${databaseId}"`);\n }\n\n if (!dbCache.has(databaseId)) {\n dbCache.set(databaseId, createDatabaseHandle(tablesDB, databaseId));\n }\n return dbCache.get(databaseId);\n },\n{{#if supportsServerSide}}\n create: (databaseId: string, name: string, options?: { enabled?: boolean }) =>\n tablesDB.create({\n databaseId,\n name,\n enabled: options?.enabled,\n }),\n update: (databaseId: DatabaseId, options?: { name?: string; enabled?: boolean }) => {\n return tablesDB.update({\n databaseId,\n name: options?.name ?? databaseId,\n enabled: options?.enabled,\n });\n },\n delete: async (databaseId: DatabaseId) => {\n await tablesDB.delete({\n databaseId,\n });\n },\n{{/if}}\n } as DatabaseTables;\n}\n\n// Initialize client\nconst client = new Client()\n .setEndpoint(ENDPOINT)\n .setProject(PROJECT_ID){{#if supportsServerSide}}\n .setKey(API_KEY){{/if}};\n\nconst tablesDB = new TablesDB(client);\n\nexport const databases: DatabaseTables = createDatabasesApi(tablesDB);\n';
143532
143758
 
143533
143759
  // lib/commands/generators/typescript/templates/index.ts.hbs
143534
- var index_ts_default = '/**\n * {{sdkTitle}} Generated SDK\n *\n * This file is auto-generated. Do not edit manually.\n * Re-run `{{executableName}} generate` to regenerate.\n */\n\nexport { databases } from "./databases.js";\nexport * from "./types.js";\n';
143760
+ var index_ts_default = '/**\n * {{sdkTitle}} Generated SDK\n *\n * This file is auto-generated. Do not edit manually.\n * Re-run `{{executableName}} generate` to regenerate.\n */\n\nexport { databases } from "./databases{{importExt}}";\nexport * from "./types{{importExt}}";\n';
143535
143761
 
143536
143762
  // lib/commands/generators/typescript/templates/constants.ts.hbs
143537
143763
  var constants_ts_default = "/**\n * {{sdkTitle}} Configuration Constants\n *\n * This file contains configuration for the generated SDK.\n * You may modify these values as needed.\n */\n\nexport const PROJECT_ID = '{{projectId}}';\nexport const ENDPOINT = '{{endpoint}}';\n{{#if requiresApiKey}}\n\n/**\n * API Key is required for server-side operations\n * Set the APPWRITE_API_KEY environment variable or replace this value directly.\n */\nexport const API_KEY = process.env.APPWRITE_API_KEY ?? '';\n{{/if}}\n";
@@ -143800,7 +144026,7 @@ ${supportsServerSide ? ` create: (databaseId: string, name: string, options?: {
143800
144026
  delete (api as any).deleteMany;
143801
144027
  }`;
143802
144028
  }
143803
- generateDatabasesFile(config2) {
144029
+ generateDatabasesFile(config2, importExt) {
143804
144030
  const entities = config2.tables?.length ? config2.tables : config2.collections;
143805
144031
  if (!entities || entities.length === 0) {
143806
144032
  return "// No tables or collections found in configuration\n";
@@ -143814,6 +144040,7 @@ ${supportsServerSide ? ` create: (databaseId: string, name: string, options?: {
143814
144040
  return databasesTemplate({
143815
144041
  appwriteDep,
143816
144042
  supportsServerSide,
144043
+ importExt,
143817
144044
  TABLE_ID_MAP: this.generateTableIdMap(entitiesByDb),
143818
144045
  TABLES_WITH_RELATIONSHIPS: this.generateTablesWithRelationships(entitiesByDb),
143819
144046
  BULK_METHODS: this.generateBulkMethods(supportsServerSide),
@@ -143821,10 +144048,11 @@ ${supportsServerSide ? ` create: (databaseId: string, name: string, options?: {
143821
144048
  BULK_REMOVAL: this.generateBulkRemoval(supportsServerSide)
143822
144049
  });
143823
144050
  }
143824
- generateIndexFile() {
144051
+ generateIndexFile(importExt) {
143825
144052
  return indexTemplate({
143826
144053
  sdkTitle: SDK_TITLE,
143827
- executableName: EXECUTABLE_NAME
144054
+ executableName: EXECUTABLE_NAME,
144055
+ importExt
143828
144056
  });
143829
144057
  }
143830
144058
  generateConstantsFile(config2) {
@@ -143844,6 +144072,7 @@ ${supportsServerSide ? ` create: (databaseId: string, name: string, options?: {
143844
144072
  if (!config2.projectId) {
143845
144073
  throw new Error("Project ID is required in configuration");
143846
144074
  }
144075
+ const importExt = detectImportExtension();
143847
144076
  const files = /* @__PURE__ */ new Map();
143848
144077
  const hasEntities = config2.tables && config2.tables.length > 0 || config2.collections && config2.collections.length > 0;
143849
144078
  if (!hasEntities) {
@@ -143858,13 +144087,13 @@ ${supportsServerSide ? ` create: (databaseId: string, name: string, options?: {
143858
144087
  "types.ts",
143859
144088
  "// No tables or collections found in configuration\n"
143860
144089
  );
143861
- files.set("index.ts", this.generateIndexFile());
144090
+ files.set("index.ts", this.generateIndexFile(importExt));
143862
144091
  files.set("constants.ts", this.generateConstantsFile(config2));
143863
144092
  return { files };
143864
144093
  }
143865
144094
  files.set("types.ts", this.generateTypesFile(config2));
143866
- files.set("databases.ts", this.generateDatabasesFile(config2));
143867
- files.set("index.ts", this.generateIndexFile());
144095
+ files.set("databases.ts", this.generateDatabasesFile(config2, importExt));
144096
+ files.set("index.ts", this.generateIndexFile(importExt));
143868
144097
  files.set("constants.ts", this.generateConstantsFile(config2));
143869
144098
  return { files };
143870
144099
  }
@@ -143983,10 +144212,11 @@ Use --language to specify the target language. Supported: ${supported}`
143983
144212
  const firstEntity = entities?.[0];
143984
144213
  const dbId = firstEntity?.databaseId ?? "databaseId";
143985
144214
  const tableName = firstEntity?.name ?? "tableName";
144215
+ const importExt = detectImportExtension();
143986
144216
  console.log("");
143987
144217
  log(`Import the generated SDK in your project:`);
143988
144218
  console.log(
143989
- ` import { databases } from "./${outputDir}/${SDK_TITLE_LOWER}/index.js";`
144219
+ ` import { databases } from "./${outputDir}/${SDK_TITLE_LOWER}/index${importExt}";`
143990
144220
  );
143991
144221
  console.log("");
143992
144222
  log(`Configure your SDK constants:`);
@@ -144023,7 +144253,7 @@ var generate = new Command("generate").description(
144023
144253
  `
144024
144254
  Example:
144025
144255
  Import the generated SDK in your project:
144026
- import { databases } from "./generated/${SDK_TITLE_LOWER}/index.js";
144256
+ import { databases } from "./generated/${SDK_TITLE_LOWER}/index${detectImportExtension()}";
144027
144257
 
144028
144258
  Configure your SDK constants:
144029
144259
  set values in ./generated/${SDK_TITLE_LOWER}/constants.ts