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
@@ -93398,7 +93398,7 @@ var package_default = {
93398
93398
  type: "module",
93399
93399
  homepage: "https://appwrite.io/support",
93400
93400
  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",
93401
- version: "13.2.1",
93401
+ version: "13.3.1",
93402
93402
  license: "BSD-3-Clause",
93403
93403
  main: "dist/index.js",
93404
93404
  types: "dist/index.d.ts",
@@ -107253,7 +107253,7 @@ var validateRequiredDefault = (data) => {
107253
107253
  return true;
107254
107254
  };
107255
107255
  var validateStringSize = (data) => {
107256
- if (data.type !== "string") {
107256
+ if (data.type !== "string" && data.type !== "varchar") {
107257
107257
  return true;
107258
107258
  }
107259
107259
  if (data.format && data.format !== "") {
@@ -107485,6 +107485,10 @@ var AttributeSchema = external_exports.object({
107485
107485
  key: external_exports.string(),
107486
107486
  type: external_exports.enum([
107487
107487
  "string",
107488
+ "text",
107489
+ "varchar",
107490
+ "mediumtext",
107491
+ "longtext",
107488
107492
  "integer",
107489
107493
  "double",
107490
107494
  "boolean",
@@ -107519,7 +107523,7 @@ var AttributeSchema = external_exports.object({
107519
107523
  message: "When 'required' is true, 'default' must be null",
107520
107524
  path: ["default"]
107521
107525
  }).refine(validateStringSize, {
107522
- message: "When 'type' is 'string', 'size' must be defined",
107526
+ message: "When 'type' is 'string' or 'varchar', 'size' must be defined",
107523
107527
  path: ["size"]
107524
107528
  });
107525
107529
  var IndexSchema = external_exports.object({
@@ -107543,6 +107547,10 @@ var ColumnSchema = external_exports.object({
107543
107547
  key: external_exports.string(),
107544
107548
  type: external_exports.enum([
107545
107549
  "string",
107550
+ "text",
107551
+ "varchar",
107552
+ "mediumtext",
107553
+ "longtext",
107546
107554
  "integer",
107547
107555
  "double",
107548
107556
  "boolean",
@@ -107578,7 +107586,7 @@ var ColumnSchema = external_exports.object({
107578
107586
  message: "When 'required' is true, 'default' must be null",
107579
107587
  path: ["default"]
107580
107588
  }).refine(validateStringSize, {
107581
- message: "When 'type' is 'string', 'size' must be defined",
107589
+ message: "When 'type' is 'string' or 'varchar', 'size' must be defined",
107582
107590
  path: ["size"]
107583
107591
  });
107584
107592
  var IndexTableSchema = external_exports.object({
@@ -107654,7 +107662,7 @@ import childProcess from "child_process";
107654
107662
  // lib/constants.ts
107655
107663
  var SDK_TITLE = "Appwrite";
107656
107664
  var SDK_TITLE_LOWER = "appwrite";
107657
- var SDK_VERSION = "13.2.1";
107665
+ var SDK_VERSION = "13.3.1";
107658
107666
  var SDK_NAME = "Command Line";
107659
107667
  var SDK_PLATFORM = "console";
107660
107668
  var SDK_LANGUAGE = "cli";
@@ -109727,14 +109735,14 @@ var Global = class _Global extends Config {
109727
109735
  const sessionMap = /* @__PURE__ */ new Map();
109728
109736
  sessions.forEach((sessionId) => {
109729
109737
  const sessionData = this.data[sessionId];
109730
- const email3 = sessionData[_Global.PREFERENCE_EMAIL];
109731
- const endpoint = sessionData[_Global.PREFERENCE_ENDPOINT];
109738
+ const email3 = sessionData[_Global.PREFERENCE_EMAIL] ?? "";
109739
+ const endpoint = sessionData[_Global.PREFERENCE_ENDPOINT] ?? "";
109732
109740
  const key = `${email3}|${endpoint}`;
109733
109741
  if (sessionId === current || !sessionMap.has(key)) {
109734
109742
  sessionMap.set(key, {
109735
109743
  id: sessionId,
109736
- endpoint: sessionData[_Global.PREFERENCE_ENDPOINT],
109737
- email: sessionData[_Global.PREFERENCE_EMAIL]
109744
+ endpoint,
109745
+ email: email3
109738
109746
  });
109739
109747
  }
109740
109748
  });
@@ -135294,7 +135302,7 @@ var questionsLogin = [
135294
135302
  when: (answers) => answers.method !== "select"
135295
135303
  },
135296
135304
  {
135297
- type: "search-list",
135305
+ type: "list",
135298
135306
  name: "accountId",
135299
135307
  message: "Select an account to use",
135300
135308
  choices() {
@@ -135309,6 +135317,7 @@ var questionsLogin = [
135309
135317
  data.push({
135310
135318
  current: current === session.id,
135311
135319
  value: session.id,
135320
+ short: `${session.email} (${session.endpoint})`,
135312
135321
  name: `${session.email.padEnd(longestEmail)} ${current === session.id ? import_chalk2.default.green.bold("current") : " ".repeat(6)} ${session.endpoint}`
135313
135322
  });
135314
135323
  }
@@ -135917,6 +135926,88 @@ var client_default = Client3;
135917
135926
 
135918
135927
  // lib/commands/generic.ts
135919
135928
  var DEFAULT_ENDPOINT2 = "https://cloud.appwrite.io/v1";
135929
+ var isMfaRequiredError = (err) => err?.type === "user_more_factors_required" || err?.response === "user_more_factors_required";
135930
+ var createLegacyConsoleClient = (endpoint) => {
135931
+ const legacyClient = new client_default();
135932
+ legacyClient.setEndpoint(endpoint);
135933
+ legacyClient.setProject("console");
135934
+ if (globalConfig2.getSelfSigned()) {
135935
+ legacyClient.setSelfSigned(true);
135936
+ }
135937
+ return legacyClient;
135938
+ };
135939
+ var completeMfaLogin = async ({
135940
+ client: client2,
135941
+ legacyClient,
135942
+ mfa,
135943
+ code
135944
+ }) => {
135945
+ let accountClient2 = new Account(client2);
135946
+ const savedCookie = globalConfig2.getCookie();
135947
+ if (savedCookie) {
135948
+ legacyClient.setCookie(savedCookie);
135949
+ client2.setCookie(savedCookie);
135950
+ }
135951
+ const { factor } = mfa ? { factor: mfa } : await import_inquirer.default.prompt(questionsListFactors);
135952
+ const challenge = await accountClient2.createMfaChallenge(factor);
135953
+ const { otp } = code ? { otp: code } : await import_inquirer.default.prompt(questionsMFAChallenge);
135954
+ await legacyClient.call(
135955
+ "PUT",
135956
+ "/account/mfa/challenges",
135957
+ {
135958
+ "content-type": "application/json"
135959
+ },
135960
+ {
135961
+ challengeId: challenge.$id,
135962
+ otp
135963
+ }
135964
+ );
135965
+ const updatedCookie = globalConfig2.getCookie();
135966
+ if (updatedCookie) {
135967
+ client2.setCookie(updatedCookie);
135968
+ }
135969
+ accountClient2 = new Account(client2);
135970
+ return accountClient2.get();
135971
+ };
135972
+ var deleteServerSession = async (sessionId) => {
135973
+ try {
135974
+ let client2 = await sdkForConsole();
135975
+ let accountClient2 = new Account(client2);
135976
+ await accountClient2.deleteSession(sessionId);
135977
+ return true;
135978
+ } catch (e) {
135979
+ return false;
135980
+ }
135981
+ };
135982
+ var deleteLocalSession = (accountId) => {
135983
+ globalConfig2.removeSession(accountId);
135984
+ };
135985
+ var getSessionAccountKey = (sessionId) => {
135986
+ const session = globalConfig2.get(sessionId);
135987
+ if (!session) return void 0;
135988
+ return `${session.email ?? ""}|${session.endpoint ?? ""}`;
135989
+ };
135990
+ var planSessionLogout = (selectedSessionIds) => {
135991
+ const sessionIdsByAccount = /* @__PURE__ */ new Map();
135992
+ for (const sessionId of globalConfig2.getSessionIds()) {
135993
+ const key = getSessionAccountKey(sessionId);
135994
+ if (!key) continue;
135995
+ const ids = sessionIdsByAccount.get(key) ?? [];
135996
+ ids.push(sessionId);
135997
+ sessionIdsByAccount.set(key, ids);
135998
+ }
135999
+ const selectedByAccount = /* @__PURE__ */ new Map();
136000
+ for (const selectedSessionId of selectedSessionIds) {
136001
+ const key = getSessionAccountKey(selectedSessionId);
136002
+ if (!key || selectedByAccount.has(key)) continue;
136003
+ selectedByAccount.set(key, selectedSessionId);
136004
+ }
136005
+ const serverTargets = Array.from(selectedByAccount.values());
136006
+ const localTargets = Array.from(selectedByAccount.keys()).flatMap(
136007
+ (accountKey) => sessionIdsByAccount.get(accountKey) ?? []
136008
+ );
136009
+ return { serverTargets, localTargets };
136010
+ };
135920
136011
  var loginCommand = async ({
135921
136012
  email: email3,
135922
136013
  password,
@@ -135942,7 +136033,25 @@ var loginCommand = async ({
135942
136033
  throw Error("Session ID not found");
135943
136034
  }
135944
136035
  globalConfig2.setCurrentSession(accountId);
135945
- success2(`Current account is ${accountId}`);
136036
+ const client3 = await sdkForConsole(false);
136037
+ const accountClient3 = new Account(client3);
136038
+ const legacyClient2 = createLegacyConsoleClient(
136039
+ globalConfig2.getEndpoint() || DEFAULT_ENDPOINT2
136040
+ );
136041
+ try {
136042
+ await accountClient3.get();
136043
+ } catch (err) {
136044
+ if (!isMfaRequiredError(err)) {
136045
+ throw err;
136046
+ }
136047
+ await completeMfaLogin({
136048
+ client: client3,
136049
+ legacyClient: legacyClient2,
136050
+ mfa,
136051
+ code
136052
+ });
136053
+ }
136054
+ success2(`Switched to ${globalConfig2.getEmail()}`);
135946
136055
  return;
135947
136056
  }
135948
136057
  const id = id_default2.unique();
@@ -135950,12 +136059,7 @@ var loginCommand = async ({
135950
136059
  globalConfig2.setCurrentSession(id);
135951
136060
  globalConfig2.setEndpoint(configEndpoint);
135952
136061
  globalConfig2.setEmail(answers.email);
135953
- const legacyClient = new client_default();
135954
- legacyClient.setEndpoint(configEndpoint);
135955
- legacyClient.setProject("console");
135956
- if (globalConfig2.getSelfSigned()) {
135957
- legacyClient.setSelfSigned(true);
135958
- }
136062
+ const legacyClient = createLegacyConsoleClient(configEndpoint);
135959
136063
  let client2 = await sdkForConsole(false);
135960
136064
  let accountClient2 = new Account(client2);
135961
136065
  let account2;
@@ -135979,27 +136083,13 @@ var loginCommand = async ({
135979
136083
  accountClient2 = new Account(client2);
135980
136084
  account2 = await accountClient2.get();
135981
136085
  } catch (err) {
135982
- if (err.type === "user_more_factors_required" || err.response === "user_more_factors_required") {
135983
- const { factor } = mfa ? { factor: mfa } : await import_inquirer.default.prompt(questionsListFactors);
135984
- const challenge = await accountClient2.createMfaChallenge(factor);
135985
- const { otp } = code ? { otp: code } : await import_inquirer.default.prompt(questionsMFAChallenge);
135986
- await legacyClient.call(
135987
- "PUT",
135988
- "/account/mfa/challenges",
135989
- {
135990
- "content-type": "application/json"
135991
- },
135992
- {
135993
- challengeId: challenge.$id,
135994
- otp
135995
- }
135996
- );
135997
- const savedCookie = globalConfig2.getCookie();
135998
- if (savedCookie) {
135999
- client2.setCookie(savedCookie);
136000
- }
136001
- accountClient2 = new Account(client2);
136002
- account2 = await accountClient2.get();
136086
+ if (isMfaRequiredError(err)) {
136087
+ account2 = await completeMfaLogin({
136088
+ client: client2,
136089
+ legacyClient,
136090
+ mfa,
136091
+ code
136092
+ });
136003
136093
  } else {
136004
136094
  globalConfig2.removeSession(id);
136005
136095
  globalConfig2.setCurrentSession(oldCurrent);
@@ -136059,49 +136149,59 @@ var login = new Command("login").description(commandDescriptions["login"]).optio
136059
136149
  ).option(`--code [code]`, `Multi-factor code`).configureHelp({
136060
136150
  helpWidth: process.stdout.columns || 80
136061
136151
  }).action(actionRunner(loginCommand));
136062
- var deleteSession = async (accountId) => {
136063
- try {
136064
- let client2 = await sdkForConsole();
136065
- let accountClient2 = new Account(client2);
136066
- await accountClient2.deleteSession("current");
136067
- } catch (e) {
136068
- error48("Unable to log out, removing locally saved session information");
136069
- } finally {
136070
- globalConfig2.removeSession(accountId);
136071
- }
136072
- };
136073
136152
  var logout = new Command("logout").description(commandDescriptions["logout"]).configureHelp({
136074
136153
  helpWidth: process.stdout.columns || 80
136075
136154
  }).action(
136076
136155
  actionRunner(async () => {
136077
136156
  const sessions = globalConfig2.getSessions();
136078
136157
  const current = globalConfig2.getCurrentSession();
136158
+ const originalCurrent = current;
136079
136159
  if (current === "" || !sessions.length) {
136080
136160
  log("No active sessions found.");
136081
136161
  return;
136082
136162
  }
136083
136163
  if (sessions.length === 1) {
136084
- await deleteSession(current);
136164
+ const serverDeleted = await deleteServerSession(current);
136165
+ const allSessionIds = globalConfig2.getSessionIds();
136166
+ for (const sessId of allSessionIds) {
136167
+ deleteLocalSession(sessId);
136168
+ }
136085
136169
  globalConfig2.setCurrentSession("");
136086
- success2("Logging out");
136170
+ if (!serverDeleted) {
136171
+ hint("Could not reach server, removed local session data");
136172
+ }
136173
+ success2("Logged out successfully");
136087
136174
  return;
136088
136175
  }
136089
136176
  const answers = await import_inquirer.default.prompt(questionsLogout);
136090
- if (answers.accounts) {
136091
- for (let accountId of answers.accounts) {
136092
- globalConfig2.setCurrentSession(accountId);
136093
- await deleteSession(accountId);
136177
+ if (answers.accounts?.length) {
136178
+ const { serverTargets, localTargets } = planSessionLogout(
136179
+ answers.accounts
136180
+ );
136181
+ for (const sessionId of serverTargets) {
136182
+ globalConfig2.setCurrentSession(sessionId);
136183
+ await deleteServerSession(sessionId);
136184
+ }
136185
+ for (const sessionId of localTargets) {
136186
+ deleteLocalSession(sessionId);
136094
136187
  }
136095
136188
  }
136096
136189
  const remainingSessions = globalConfig2.getSessions();
136097
- if (remainingSessions.length > 0 && remainingSessions.filter((session) => session.id === current).length !== 1) {
136098
- const accountId = remainingSessions[0].id;
136099
- globalConfig2.setCurrentSession(accountId);
136100
- success2(`Current account is ${accountId}`);
136190
+ const hasCurrent = remainingSessions.some(
136191
+ (session) => session.id === originalCurrent
136192
+ );
136193
+ if (remainingSessions.length > 0 && hasCurrent) {
136194
+ globalConfig2.setCurrentSession(originalCurrent);
136195
+ } else if (remainingSessions.length > 0) {
136196
+ const nextSession = remainingSessions.find((session) => session.email) ?? remainingSessions[0];
136197
+ globalConfig2.setCurrentSession(nextSession.id);
136198
+ success2(
136199
+ nextSession.email ? `Switched to ${nextSession.email}` : `Switched to session at ${nextSession.endpoint}`
136200
+ );
136101
136201
  } else if (remainingSessions.length === 0) {
136102
136202
  globalConfig2.setCurrentSession("");
136103
136203
  }
136104
- success2("Logging out");
136204
+ success2("Logged out successfully");
136105
136205
  })
136106
136206
  );
136107
136207
  var client = new Command("client").description(commandDescriptions["client"]).configureHelp({
@@ -136194,10 +136294,14 @@ var client = new Command("client").description(commandDescriptions["client"]).co
136194
136294
  }
136195
136295
  if (reset !== void 0) {
136196
136296
  const sessions = globalConfig2.getSessions();
136197
- for (let accountId of sessions.map((session) => session.id)) {
136198
- globalConfig2.setCurrentSession(accountId);
136199
- await deleteSession(accountId);
136297
+ for (const sessionId of sessions.map((session) => session.id)) {
136298
+ globalConfig2.setCurrentSession(sessionId);
136299
+ await deleteServerSession(sessionId);
136200
136300
  }
136301
+ for (const sessionId of globalConfig2.getSessionIds()) {
136302
+ deleteLocalSession(sessionId);
136303
+ }
136304
+ globalConfig2.setCurrentSession("");
136201
136305
  }
136202
136306
  if (!debug) {
136203
136307
  success2("Setting client");
@@ -137834,6 +137938,10 @@ function detectLanguage() {
137834
137938
  // lib/type-generation/attribute.ts
137835
137939
  var AttributeType = {
137836
137940
  STRING: "string",
137941
+ TEXT: "text",
137942
+ VARCHAR: "varchar",
137943
+ MEDIUMTEXT: "mediumtext",
137944
+ LONGTEXT: "longtext",
137837
137945
  INTEGER: "integer",
137838
137946
  FLOAT: "double",
137839
137947
  BOOLEAN: "boolean",
@@ -137857,6 +137965,10 @@ var PHP = class extends LanguageMeta {
137857
137965
  let type = "";
137858
137966
  switch (attribute.type) {
137859
137967
  case AttributeType.STRING:
137968
+ case AttributeType.TEXT:
137969
+ case AttributeType.VARCHAR:
137970
+ case AttributeType.MEDIUMTEXT:
137971
+ case AttributeType.LONGTEXT:
137860
137972
  case AttributeType.DATETIME:
137861
137973
  type = "string";
137862
137974
  if (attribute.format === AttributeType.ENUM) {
@@ -137964,6 +138076,10 @@ function getTypeScriptType(attribute, entities, entityName, forCreate = false) {
137964
138076
  let type = "";
137965
138077
  switch (attribute.type) {
137966
138078
  case "string":
138079
+ case "text":
138080
+ case "varchar":
138081
+ case "mediumtext":
138082
+ case "longtext":
137967
138083
  case "datetime":
137968
138084
  type = "string";
137969
138085
  if (attribute.format === "enum") {
@@ -138042,6 +138158,22 @@ function getAppwriteDependency() {
138042
138158
  }
138043
138159
  return "appwrite";
138044
138160
  }
138161
+ function detectImportExtension(cwd = process.cwd()) {
138162
+ try {
138163
+ const pkgPath = path6.resolve(cwd, "package.json");
138164
+ if (fs7.existsSync(pkgPath)) {
138165
+ const pkg = JSON.parse(fs7.readFileSync(pkgPath, "utf-8"));
138166
+ if (pkg.type === "module") {
138167
+ return ".js";
138168
+ }
138169
+ }
138170
+ if (fs7.existsSync(path6.resolve(cwd, "deno.json")) || fs7.existsSync(path6.resolve(cwd, "deno.jsonc"))) {
138171
+ return ".ts";
138172
+ }
138173
+ } catch {
138174
+ }
138175
+ return "";
138176
+ }
138045
138177
  function supportsServerSideMethods(appwriteDep, override = "auto") {
138046
138178
  if (override === "true") return true;
138047
138179
  if (override === "false") return false;
@@ -138136,6 +138268,10 @@ var Kotlin = class extends LanguageMeta {
138136
138268
  let type = "";
138137
138269
  switch (attribute.type) {
138138
138270
  case AttributeType.STRING:
138271
+ case AttributeType.TEXT:
138272
+ case AttributeType.VARCHAR:
138273
+ case AttributeType.MEDIUMTEXT:
138274
+ case AttributeType.LONGTEXT:
138139
138275
  case AttributeType.DATETIME:
138140
138276
  type = "String";
138141
138277
  if (attribute.format === AttributeType.ENUM) {
@@ -138224,6 +138360,10 @@ var Swift = class extends LanguageMeta {
138224
138360
  let type = "";
138225
138361
  switch (attribute.type) {
138226
138362
  case AttributeType.STRING:
138363
+ case AttributeType.TEXT:
138364
+ case AttributeType.VARCHAR:
138365
+ case AttributeType.MEDIUMTEXT:
138366
+ case AttributeType.LONGTEXT:
138227
138367
  case AttributeType.DATETIME:
138228
138368
  type = "String";
138229
138369
  if (attribute.format === AttributeType.ENUM) {
@@ -138334,7 +138474,7 @@ public class <%- toPascalCase(collection.name) %>: Codable {
138334
138474
  <% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
138335
138475
  <% if (attribute.type === 'relationship') { -%>
138336
138476
  "<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %> as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
138337
- <% } else if (attribute.array && attribute.type !== 'string' && attribute.type !== 'integer' && attribute.type !== 'float' && attribute.type !== 'boolean') { -%>
138477
+ <% } else if (attribute.array && !['string', 'text', 'varchar', 'mediumtext', 'longtext', 'integer', 'float', 'boolean'].includes(attribute.type)) { -%>
138338
138478
  "<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %>?.map { $0.toMap() } as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
138339
138479
  <% } else { -%>
138340
138480
  "<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %> as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
@@ -138350,7 +138490,7 @@ public class <%- toPascalCase(collection.name) %>: Codable {
138350
138490
  <% const relationshipType = getType(attribute, collections, collection.name).replace('?', ''); -%>
138351
138491
  <%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> <%- relationshipType %><% if (index < collection.attributes.length - 1) { %>,<% } %>
138352
138492
  <% } else if (attribute.array) { -%>
138353
- <% if (attribute.type === 'string') { -%>
138493
+ <% if (['string', 'text', 'varchar', 'mediumtext', 'longtext'].includes(attribute.type)) { -%>
138354
138494
  <%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [String]<% if (index < collection.attributes.length - 1) { %>,<% } %>
138355
138495
  <% } else if (attribute.type === 'integer') { -%>
138356
138496
  <%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Int]<% if (index < collection.attributes.length - 1) { %>,<% } %>
@@ -138362,9 +138502,9 @@ public class <%- toPascalCase(collection.name) %>: Codable {
138362
138502
  <%- 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) { %>,<% } %>
138363
138503
  <% } -%>
138364
138504
  <% } else { -%>
138365
- <% if ((attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime') && attribute.format !== 'enum') { -%>
138505
+ <% if (['string', 'text', 'varchar', 'mediumtext', 'longtext', 'email', 'datetime'].includes(attribute.type) && attribute.format !== 'enum') { -%>
138366
138506
  <%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> String<% if (index < collection.attributes.length - 1) { %>,<% } %>
138367
- <% } else if (attribute.type === 'string' && attribute.format === 'enum') { -%>
138507
+ <% } else if (['string', 'text', 'varchar', 'mediumtext', 'longtext'].includes(attribute.type) && attribute.format === 'enum') { -%>
138368
138508
  <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>(rawValue: map["<%- attribute.key %>"] as! String)!<% if (index < collection.attributes.length - 1) { %>,<% } %>
138369
138509
  <% } else if (attribute.type === 'integer') { -%>
138370
138510
  <%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Int<% if (index < collection.attributes.length - 1) { %>,<% } %>
@@ -138392,6 +138532,10 @@ var Java = class extends LanguageMeta {
138392
138532
  let type = "";
138393
138533
  switch (attribute.type) {
138394
138534
  case AttributeType.STRING:
138535
+ case AttributeType.TEXT:
138536
+ case AttributeType.VARCHAR:
138537
+ case AttributeType.MEDIUMTEXT:
138538
+ case AttributeType.LONGTEXT:
138395
138539
  case AttributeType.DATETIME:
138396
138540
  type = "String";
138397
138541
  if (attribute.format === AttributeType.ENUM) {
@@ -138572,6 +138716,10 @@ var Dart = class extends LanguageMeta {
138572
138716
  let type = "";
138573
138717
  switch (attribute.type) {
138574
138718
  case AttributeType.STRING:
138719
+ case AttributeType.TEXT:
138720
+ case AttributeType.VARCHAR:
138721
+ case AttributeType.MEDIUMTEXT:
138722
+ case AttributeType.LONGTEXT:
138575
138723
  case AttributeType.DATETIME:
138576
138724
  type = "String";
138577
138725
  if (attribute.format === AttributeType.ENUM) {
@@ -138676,7 +138824,7 @@ class <%= toPascalCase(collection.name) %> {
138676
138824
  factory <%= toPascalCase(collection.name) %>.fromMap(Map<String, dynamic> map) {
138677
138825
  return <%= toPascalCase(collection.name) %>(<% if (__attrs.length > 0) { %>
138678
138826
  <% for (const [index, attribute] of Object.entries(__attrs)) { -%>
138679
- <%= strict ? toCamelCase(attribute.key) : attribute.key %>: <% if (attribute.type === '${AttributeType.STRING}' || attribute.type === '${AttributeType.EMAIL}' || attribute.type === '${AttributeType.DATETIME}') { -%>
138827
+ <%= strict ? toCamelCase(attribute.key) : attribute.key %>: <% if (['${AttributeType.STRING}', '${AttributeType.TEXT}', '${AttributeType.VARCHAR}', '${AttributeType.MEDIUMTEXT}', '${AttributeType.LONGTEXT}', '${AttributeType.EMAIL}', '${AttributeType.DATETIME}'].includes(attribute.type)) { -%>
138680
138828
  <% if (attribute.format === '${AttributeType.ENUM}') { -%>
138681
138829
  <% if (attribute.array) { -%>
138682
138830
  (map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.value == e)).toList()<% } else { -%>
@@ -138747,6 +138895,10 @@ var JavaScript = class extends LanguageMeta {
138747
138895
  let type = "";
138748
138896
  switch (attribute.type) {
138749
138897
  case AttributeType.STRING:
138898
+ case AttributeType.TEXT:
138899
+ case AttributeType.VARCHAR:
138900
+ case AttributeType.MEDIUMTEXT:
138901
+ case AttributeType.LONGTEXT:
138750
138902
  case AttributeType.DATETIME:
138751
138903
  type = "string";
138752
138904
  if (attribute.format === AttributeType.ENUM) {
@@ -138845,6 +138997,10 @@ var CSharp = class extends LanguageMeta {
138845
138997
  let type = "";
138846
138998
  switch (attribute.type) {
138847
138999
  case AttributeType.STRING:
139000
+ case AttributeType.TEXT:
139001
+ case AttributeType.VARCHAR:
139002
+ case AttributeType.MEDIUMTEXT:
139003
+ case AttributeType.LONGTEXT:
138848
139004
  case AttributeType.DATETIME:
138849
139005
  type = "string";
138850
139006
  if (attribute.format === AttributeType.ENUM) {
@@ -138952,7 +139108,7 @@ public class <%= toPascalCase(collection.name) %>
138952
139108
  }
138953
139109
  // ARRAY TYPES
138954
139110
  } else if (attribute.array) {
138955
- if (attribute.type === 'string' || attribute.type === 'datetime' || attribute.type === 'email') {
139111
+ if (['string', 'text', 'varchar', 'mediumtext', 'longtext', 'datetime', 'email'].includes(attribute.type)) {
138956
139112
  -%>((IEnumerable<object>)map["<%- attribute.key %>"]).Select(x => x?.ToString())<%- attribute.required ? '.Where(x => x != null)' : '' %>.ToList()!<%
138957
139113
  } else if (attribute.type === 'integer') {
138958
139114
  -%>((IEnumerable<object>)map["<%- attribute.key %>"]).Select(x => <%- !attribute.required ? 'x == null ? (long?)null : ' : '' %>Convert.ToInt64(x)).ToList()<%
@@ -138968,7 +139124,7 @@ public class <%= toPascalCase(collection.name) %>
138968
139124
  -%><%- !attribute.required ? 'map["' + attribute.key + '"] == null ? null : ' : '' %>Convert.ToDouble(map["<%- attribute.key %>"])<%
138969
139125
  } else if (attribute.type === 'boolean') {
138970
139126
  -%>(<%- getType(attribute, collections, collection.name) %>)map["<%- attribute.key %>"]<%
138971
- } else if (attribute.type === 'string' || attribute.type === 'datetime' || attribute.type === 'email') {
139127
+ } else if (['string', 'text', 'varchar', 'mediumtext', 'longtext', 'datetime', 'email'].includes(attribute.type)) {
138972
139128
  -%>map["<%- attribute.key %>"]<%- !attribute.required ? '?' : '' %>.ToString()<%- attribute.required ? '!' : ''%><%
138973
139129
  } else {
138974
139130
  -%>default<%
@@ -140678,6 +140834,43 @@ var Attributes = class {
140678
140834
  encrypt: attribute.encrypt
140679
140835
  });
140680
140836
  }
140837
+ case "varchar":
140838
+ return databasesService.createVarcharAttribute({
140839
+ databaseId,
140840
+ collectionId,
140841
+ key: attribute.key,
140842
+ size: attribute.size,
140843
+ required: attribute.required,
140844
+ xdefault: attribute.default,
140845
+ array: attribute.array
140846
+ });
140847
+ case "text":
140848
+ return databasesService.createTextAttribute({
140849
+ databaseId,
140850
+ collectionId,
140851
+ key: attribute.key,
140852
+ required: attribute.required,
140853
+ xdefault: attribute.default,
140854
+ array: attribute.array
140855
+ });
140856
+ case "mediumtext":
140857
+ return databasesService.createMediumtextAttribute({
140858
+ databaseId,
140859
+ collectionId,
140860
+ key: attribute.key,
140861
+ required: attribute.required,
140862
+ xdefault: attribute.default,
140863
+ array: attribute.array
140864
+ });
140865
+ case "longtext":
140866
+ return databasesService.createLongtextAttribute({
140867
+ databaseId,
140868
+ collectionId,
140869
+ key: attribute.key,
140870
+ required: attribute.required,
140871
+ xdefault: attribute.default,
140872
+ array: attribute.array
140873
+ });
140681
140874
  case "integer":
140682
140875
  return databasesService.createIntegerAttribute({
140683
140876
  databaseId,
@@ -140804,6 +140997,39 @@ var Attributes = class {
140804
140997
  xdefault: attribute.default
140805
140998
  });
140806
140999
  }
141000
+ case "varchar":
141001
+ return databasesService.updateVarcharAttribute({
141002
+ databaseId,
141003
+ collectionId,
141004
+ key: attribute.key,
141005
+ required: attribute.required,
141006
+ xdefault: attribute.default,
141007
+ size: attribute.size
141008
+ });
141009
+ case "text":
141010
+ return databasesService.updateTextAttribute({
141011
+ databaseId,
141012
+ collectionId,
141013
+ key: attribute.key,
141014
+ required: attribute.required,
141015
+ xdefault: attribute.default
141016
+ });
141017
+ case "mediumtext":
141018
+ return databasesService.updateMediumtextAttribute({
141019
+ databaseId,
141020
+ collectionId,
141021
+ key: attribute.key,
141022
+ required: attribute.required,
141023
+ xdefault: attribute.default
141024
+ });
141025
+ case "longtext":
141026
+ return databasesService.updateLongtextAttribute({
141027
+ databaseId,
141028
+ collectionId,
141029
+ key: attribute.key,
141030
+ required: attribute.required,
141031
+ xdefault: attribute.default
141032
+ });
140807
141033
  case "integer":
140808
141034
  return databasesService.updateIntegerAttribute({
140809
141035
  databaseId,
@@ -143028,7 +143254,7 @@ var pushCollection = async () => {
143028
143254
  const result = await pushInstance.pushCollections(collections);
143029
143255
  const { successfullyPushed, errors } = result;
143030
143256
  if (successfullyPushed === 0) {
143031
- error48("No collections were pushed.");
143257
+ warn("No collections were pushed.");
143032
143258
  } else {
143033
143259
  success2(`Successfully pushed ${successfullyPushed} collections.`);
143034
143260
  }
@@ -143534,10 +143760,10 @@ var BaseDatabasesGenerator = class {
143534
143760
  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";
143535
143761
 
143536
143762
  // lib/commands/generators/typescript/templates/databases.ts.hbs
143537
- 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';
143763
+ 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';
143538
143764
 
143539
143765
  // lib/commands/generators/typescript/templates/index.ts.hbs
143540
- 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';
143766
+ 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';
143541
143767
 
143542
143768
  // lib/commands/generators/typescript/templates/constants.ts.hbs
143543
143769
  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";
@@ -143806,7 +144032,7 @@ ${supportsServerSide ? ` create: (databaseId: string, name: string, options?: {
143806
144032
  delete (api as any).deleteMany;
143807
144033
  }`;
143808
144034
  }
143809
- generateDatabasesFile(config2) {
144035
+ generateDatabasesFile(config2, importExt) {
143810
144036
  const entities = config2.tables?.length ? config2.tables : config2.collections;
143811
144037
  if (!entities || entities.length === 0) {
143812
144038
  return "// No tables or collections found in configuration\n";
@@ -143820,6 +144046,7 @@ ${supportsServerSide ? ` create: (databaseId: string, name: string, options?: {
143820
144046
  return databasesTemplate({
143821
144047
  appwriteDep,
143822
144048
  supportsServerSide,
144049
+ importExt,
143823
144050
  TABLE_ID_MAP: this.generateTableIdMap(entitiesByDb),
143824
144051
  TABLES_WITH_RELATIONSHIPS: this.generateTablesWithRelationships(entitiesByDb),
143825
144052
  BULK_METHODS: this.generateBulkMethods(supportsServerSide),
@@ -143827,10 +144054,11 @@ ${supportsServerSide ? ` create: (databaseId: string, name: string, options?: {
143827
144054
  BULK_REMOVAL: this.generateBulkRemoval(supportsServerSide)
143828
144055
  });
143829
144056
  }
143830
- generateIndexFile() {
144057
+ generateIndexFile(importExt) {
143831
144058
  return indexTemplate({
143832
144059
  sdkTitle: SDK_TITLE,
143833
- executableName: EXECUTABLE_NAME
144060
+ executableName: EXECUTABLE_NAME,
144061
+ importExt
143834
144062
  });
143835
144063
  }
143836
144064
  generateConstantsFile(config2) {
@@ -143850,6 +144078,7 @@ ${supportsServerSide ? ` create: (databaseId: string, name: string, options?: {
143850
144078
  if (!config2.projectId) {
143851
144079
  throw new Error("Project ID is required in configuration");
143852
144080
  }
144081
+ const importExt = detectImportExtension();
143853
144082
  const files = /* @__PURE__ */ new Map();
143854
144083
  const hasEntities = config2.tables && config2.tables.length > 0 || config2.collections && config2.collections.length > 0;
143855
144084
  if (!hasEntities) {
@@ -143864,13 +144093,13 @@ ${supportsServerSide ? ` create: (databaseId: string, name: string, options?: {
143864
144093
  "types.ts",
143865
144094
  "// No tables or collections found in configuration\n"
143866
144095
  );
143867
- files.set("index.ts", this.generateIndexFile());
144096
+ files.set("index.ts", this.generateIndexFile(importExt));
143868
144097
  files.set("constants.ts", this.generateConstantsFile(config2));
143869
144098
  return { files };
143870
144099
  }
143871
144100
  files.set("types.ts", this.generateTypesFile(config2));
143872
- files.set("databases.ts", this.generateDatabasesFile(config2));
143873
- files.set("index.ts", this.generateIndexFile());
144101
+ files.set("databases.ts", this.generateDatabasesFile(config2, importExt));
144102
+ files.set("index.ts", this.generateIndexFile(importExt));
143874
144103
  files.set("constants.ts", this.generateConstantsFile(config2));
143875
144104
  return { files };
143876
144105
  }
@@ -143989,10 +144218,11 @@ Use --language to specify the target language. Supported: ${supported}`
143989
144218
  const firstEntity = entities?.[0];
143990
144219
  const dbId = firstEntity?.databaseId ?? "databaseId";
143991
144220
  const tableName = firstEntity?.name ?? "tableName";
144221
+ const importExt = detectImportExtension();
143992
144222
  console.log("");
143993
144223
  log(`Import the generated SDK in your project:`);
143994
144224
  console.log(
143995
- ` import { databases } from "./${outputDir}/${SDK_TITLE_LOWER}/index.js";`
144225
+ ` import { databases } from "./${outputDir}/${SDK_TITLE_LOWER}/index${importExt}";`
143996
144226
  );
143997
144227
  console.log("");
143998
144228
  log(`Configure your SDK constants:`);
@@ -144029,7 +144259,7 @@ var generate = new Command("generate").description(
144029
144259
  `
144030
144260
  Example:
144031
144261
  Import the generated SDK in your project:
144032
- import { databases } from "./generated/${SDK_TITLE_LOWER}/index.js";
144262
+ import { databases } from "./generated/${SDK_TITLE_LOWER}/index${detectImportExtension()}";
144033
144263
 
144034
144264
  Configure your SDK constants:
144035
144265
  set values in ./generated/${SDK_TITLE_LOWER}/constants.ts