From 690662953fb9081404a5d67c803d99d7fa7fec35 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 14 Sep 2023 20:40:08 +0000 Subject: [PATCH 01/11] feat: add docs for bun runtime --- app/views/docs/functions-develop.phtml | 207 ++++++++++++++++++++++++- 1 file changed, 206 insertions(+), 1 deletion(-) diff --git a/app/views/docs/functions-develop.phtml b/app/views/docs/functions-develop.phtml index b1d11293..f88bb464 100644 --- a/app/views/docs/functions-develop.phtml +++ b/app/views/docs/functions-develop.phtml @@ -206,6 +206,43 @@ export default ({ req, res, log, error }: any) => { return res.send("Hello, World!"); } + // `res.json()` is a handy helper for sending JSON + return res.json({ + motto: "Build Fast. Scale Big. All in One Place.", + learn: "https://appwrite.io/docs", + connect: "https://appwrite.io/discord", + getInspired: "https://builtwith.appwrite.io", + }); +}; + + +
  • +

    Bun

    +
    +
    import { Client } from 'node-appwrite';
    +
    +// This is your Appwrite function
    +// It's executed each time we get a request
    +export default async ({ req, res, log, error }: any) => {
    +  // Why not try the Appwrite SDK?
    +  // const client = new Client()
    +  //    .setEndpoint('https://cloud.appwrite.io/v1')
    +  //    .setProject(Bun.env["APPWRITE_FUNCTION_PROJECT_ID"])
    +  //    .setKey(Bun.env["APPWRITE_API_KEY"]);
    +
    +  // You can log messages to the console
    +  log("Hello, Logs!");
    +
    +  // If something goes wrong, log an error
    +  error("Hello, Errors!");
    +
    +  // The `req` object contains the request data
    +  if (req.method === "GET") {
    +    // Send a response with the res object helpers
    +    // `res.send()` dispatches a string back to the client
    +    return res.send("Hello, World!");
    +  }
    +
       // `res.json()` is a handy helper for sending JSON
       return res.json({
         motto: "Build Fast. Scale Big. All in One Place.",
    @@ -503,6 +540,22 @@ export default async function (context: any) {
         return context.res.send("This is a response!");
     }
        
    +// after destructuring
    +export default async function ({ req, res, log, error }: any) {
    +    log("This is a log!");
    +    return res.send("This is a response!");
    +}
    +
    +
  • +
  • +

    Bun

    +
    +
    // before destructuring
    +export default async function (context: any) {
    +    context.log("This is a log!");
    +    return context.res.send("This is a response!");
    +}
    +   
     // after destructuring
     export default async function ({ req, res, log, error }: any) {
         log("This is a log!");
    @@ -620,6 +673,25 @@ end
    log(req.queryString); // Raw query params string. For example "limit=12&offset=50" log(JSON.stringify(req.query)); // Parsed query params. For example, req.query.limit + return res.send("All the request parameters are logged to the Appwrite Console."); +
    +
  • +
  • +

    Bun

    +
    +
    export default async ({ req, res, log }: any) => {
    +    log(req.bodyRaw);                 // Raw request body, contains request data
    +    log(JSON.stringify(req.body));    // Object from parsed JSON request body, otherwise string
    +    log(JSON.stringify(req.headers)); // String key-value pairs of all request headers, keys are lowercase
    +    log(req.scheme);                  // Value of the x-forwarded-proto header, usually http or https
    +    log(req.method);                  // Request method, such as GET, POST, PUT, DELETE, PATCH, etc.
    +    log(req.url);                     // Full URL, for example: http://awesome.appwrite.io:8000/v1/hooks?limit=12&offset=50
    +    log(req.host);                    // Hostname from the host header, such as awesome.appwrite.io
    +    log(req.port);                    // Port from the host header, for example 8000
    +    log(req.path);                    // Path part of URL, for example /v1/hooks
    +    log(req.queryString);             // Raw query params string. For example "limit=12&offset=50"
    +    log(JSON.stringify(req.query));   // Parsed query params. For example, req.query.limit
    +
         return res.send("All the request parameters are logged to the Appwrite Console.");
  • @@ -921,6 +993,29 @@ end
    export default async ({ req, res, log }) => {
     
    +    switch (req.query.type) {
    +        case 'empty':
    +            return res.empty();
    +        case 'json':
    +            return res.json({type": "This is a JSON response"});
    +        case 'redirect':
    +            return res.redirect("https://appwrite.io", 301);
    +        case 'html':
    +            return res.send(
    +                "<h1>This is an HTML response</h1>", 200, {
    +                    "content-type": "text/html"
    +                });
    +        default:
    +            return res.send("This is a text response");
    +    }
    +}
    +
    + +
  • +

    Bun

    +
    +
    export default async ({ req, res, log }) => {
    +
         switch (req.query.type) {
             case 'empty':
                 return res.empty();
    @@ -1203,6 +1298,18 @@ end
    log(`This function was called with ${context.req.method} method`); error("This is an error, use for logging errors to console"); + return res.send("Check the Appwrite Console to see logs and errors!"); +}; +
    +
  • +
  • +

    Bun

    +
    +
    export default async ({ res, log, error }: any) => {
    +    log("This is a log, use for logging information to console");
    +    log(`This function was called with ${context.req.method} method`);
    +    error("This is an error, use for logging errors to console");
    +
         return res.send("Check the Appwrite Console to see logs and errors!");
     };
    @@ -1454,6 +1561,14 @@ end
    export default async ({ req, res, log }) => {
         return res.send(Deno.env.get('MY_VAR'));
    +}
    +
    +
  • +
  • +

    Bun

    +
    +
    export default async ({ req, res, log }) => {
    +    return res.send(Bun.env.get('MY_VAR'));
     }
  • @@ -1593,7 +1708,15 @@ namespace runtime { Deno deno - deno cache <ENTRYPOINT_FILE> + deno install + + + + Bun icon + + Bun + bun + bun install @@ -1824,6 +1947,35 @@ export default function ({req, res, error}: any){ return res.send("Failed to create document"); } + return res.send("Document created"); +} + + +
  • +

    Bun

    +
    +
    import { Client, Databases, ID } from 'node-appwrite';
    +                
    +export default function ({req, res, error}: any){
    +    const client = new Client()
    +        .setEndpoint("https://cloud.appwrite.io/v1")
    +        .setProject(Bun.env.get("APPWRITE_FUNCTION_PROJECT_ID") || "")
    +        .setKey(Bun.env.get("APPWRITE_API_KEY") || "");
    +    
    +    const databases = new Databases(client);
    +    
    +    try {
    +        databases.createDocument(
    +            "[DATABASE_ID]",
    +            "[COLLECTION_ID]",
    +            ID.unique(),
    +            {}
    +        );
    +    } catch (e) {
    +        error("Failed to create document: " + e.message);
    +        return res.send("Failed to create document");
    +    }
    +    
         return res.send("Document created");
     }
    @@ -2188,6 +2340,40 @@ export default function ({req, res, error}: any){ return res.send("Failed to create document"); } + return res.send("Document created"); +} + +
  • +
  • +

    Bun

    +
    +
    import { Client, Databases, ID } from 'node-appwrite';
    +                
    +export default function ({req, res, error}: any){
    +    const client = new Client()
    +        .setEndpoint("https://cloud.appwrite.io/v1")
    +        .setProject(Bun.env.get("APPWRITE_FUNCTION_PROJECT_ID") || "")
    +    
    +    if (req.headers["x-appwrite-user-jwt"]) {
    +        client.setJWT(req.headers["x-appwrite-user-jwt"]);
    +    } else {
    +        return res.send("Please sign in, JWT not found");
    +    }
    +    
    +    const databases = new Databases(client);
    +    
    +    try {
    +        databases.createDocument(
    +            "[DATABASE_ID]",
    +            "[COLLECTION_ID]",
    +            ID.unique(),
    +            {}
    +        );
    +    } catch (e) {
    +        error("Failed to create document: " + e.message)
    +        return res.send("Failed to create document");
    +    }
    +    
         return res.send("Document created");
     }
    @@ -2492,6 +2678,25 @@ export function add(a: number, b: number): number { import { add } from './utils.ts'; +export default function ({res}: {res: any}) { + return res.send(add(1, 2)); +} + +
  • +
  • +

    Bun

    +
    +
    // src/utils.ts
    +
    +export function add(a: number, b: number): number {
    +    return a + b;
    +}
    +
    +
    +
    // src/main.ts
    +
    +import { add } from './utils.ts';
    +
     export default function ({res}: {res: any}) {
         return res.send(add(1, 2));
     }
    From b5e8b45bee1310ea2c0446a95eab6b7d951c0c24 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 14 Sep 2023 20:45:38 +0000 Subject: [PATCH 02/11] feat: add docs for bun runtime --- app/views/docs/functions-develop.phtml | 378 ++++++++++++------------- 1 file changed, 189 insertions(+), 189 deletions(-) diff --git a/app/views/docs/functions-develop.phtml b/app/views/docs/functions-develop.phtml index f88bb464..1cf0cf0b 100644 --- a/app/views/docs/functions-develop.phtml +++ b/app/views/docs/functions-develop.phtml @@ -206,43 +206,6 @@ export default ({ req, res, log, error }: any) => { return res.send("Hello, World!"); } - // `res.json()` is a handy helper for sending JSON - return res.json({ - motto: "Build Fast. Scale Big. All in One Place.", - learn: "https://appwrite.io/docs", - connect: "https://appwrite.io/discord", - getInspired: "https://builtwith.appwrite.io", - }); -}; -
    -
  • -
  • -

    Bun

    -
    -
    import { Client } from 'node-appwrite';
    -
    -// This is your Appwrite function
    -// It's executed each time we get a request
    -export default async ({ req, res, log, error }: any) => {
    -  // Why not try the Appwrite SDK?
    -  // const client = new Client()
    -  //    .setEndpoint('https://cloud.appwrite.io/v1')
    -  //    .setProject(Bun.env["APPWRITE_FUNCTION_PROJECT_ID"])
    -  //    .setKey(Bun.env["APPWRITE_API_KEY"]);
    -
    -  // You can log messages to the console
    -  log("Hello, Logs!");
    -
    -  // If something goes wrong, log an error
    -  error("Hello, Errors!");
    -
    -  // The `req` object contains the request data
    -  if (req.method === "GET") {
    -    // Send a response with the res object helpers
    -    // `res.send()` dispatches a string back to the client
    -    return res.send("Hello, World!");
    -  }
    -
       // `res.json()` is a handy helper for sending JSON
       return res.json({
         motto: "Build Fast. Scale Big. All in One Place.",
    @@ -470,6 +433,43 @@ public class Handler {
     }
  • +
  • +

    Bun

    +
    +
    import { Client } from 'node-appwrite';
    +
    +// This is your Appwrite function
    +// It's executed each time we get a request
    +export default async ({ req, res, log, error }: any) => {
    +  // Why not try the Appwrite SDK?
    +  // const client = new Client()
    +  //    .setEndpoint('https://cloud.appwrite.io/v1')
    +  //    .setProject(Bun.env["APPWRITE_FUNCTION_PROJECT_ID"])
    +  //    .setKey(Bun.env["APPWRITE_API_KEY"]);
    +
    +  // You can log messages to the console
    +  log("Hello, Logs!");
    +
    +  // If something goes wrong, log an error
    +  error("Hello, Errors!");
    +
    +  // The `req` object contains the request data
    +  if (req.method === "GET") {
    +    // Send a response with the res object helpers
    +    // `res.send()` dispatches a string back to the client
    +    return res.send("Hello, World!");
    +  }
    +
    +  // `res.json()` is a handy helper for sending JSON
    +  return res.json({
    +    motto: "Build Fast. Scale Big. All in One Place.",
    +    learn: "https://appwrite.io/docs",
    +    connect: "https://appwrite.io/discord",
    +    getInspired: "https://builtwith.appwrite.io",
    +  });
    +};
    +
    +
  • If you prefer to learn through more examples like this, explore the examples page.

    @@ -673,25 +673,6 @@ end log(req.queryString); // Raw query params string. For example "limit=12&offset=50" log(JSON.stringify(req.query)); // Parsed query params. For example, req.query.limit - return res.send("All the request parameters are logged to the Appwrite Console."); - - -
  • -

    Bun

    -
    -
    export default async ({ req, res, log }: any) => {
    -    log(req.bodyRaw);                 // Raw request body, contains request data
    -    log(JSON.stringify(req.body));    // Object from parsed JSON request body, otherwise string
    -    log(JSON.stringify(req.headers)); // String key-value pairs of all request headers, keys are lowercase
    -    log(req.scheme);                  // Value of the x-forwarded-proto header, usually http or https
    -    log(req.method);                  // Request method, such as GET, POST, PUT, DELETE, PATCH, etc.
    -    log(req.url);                     // Full URL, for example: http://awesome.appwrite.io:8000/v1/hooks?limit=12&offset=50
    -    log(req.host);                    // Hostname from the host header, such as awesome.appwrite.io
    -    log(req.port);                    // Port from the host header, for example 8000
    -    log(req.path);                    // Path part of URL, for example /v1/hooks
    -    log(req.queryString);             // Raw query params string. For example "limit=12&offset=50"
    -    log(JSON.stringify(req.query));   // Parsed query params. For example, req.query.limit
    -
         return res.send("All the request parameters are logged to the Appwrite Console.");
  • @@ -828,6 +809,25 @@ public class Main { } +
  • +

    Bun

    +
    +
    export default async ({ req, res, log }: any) => {
    +    log(req.bodyRaw);                 // Raw request body, contains request data
    +    log(JSON.stringify(req.body));    // Object from parsed JSON request body, otherwise string
    +    log(JSON.stringify(req.headers)); // String key-value pairs of all request headers, keys are lowercase
    +    log(req.scheme);                  // Value of the x-forwarded-proto header, usually http or https
    +    log(req.method);                  // Request method, such as GET, POST, PUT, DELETE, PATCH, etc.
    +    log(req.url);                     // Full URL, for example: http://awesome.appwrite.io:8000/v1/hooks?limit=12&offset=50
    +    log(req.host);                    // Hostname from the host header, such as awesome.appwrite.io
    +    log(req.port);                    // Port from the host header, for example 8000
    +    log(req.path);                    // Path part of URL, for example /v1/hooks
    +    log(req.queryString);             // Raw query params string. For example "limit=12&offset=50"
    +    log(JSON.stringify(req.query));   // Parsed query params. For example, req.query.limit
    +
    +    return res.send("All the request parameters are logged to the Appwrite Console.");
    +
    +
  • Headers

    @@ -993,29 +993,6 @@ end
    export default async ({ req, res, log }) => {
     
    -    switch (req.query.type) {
    -        case 'empty':
    -            return res.empty();
    -        case 'json':
    -            return res.json({type": "This is a JSON response"});
    -        case 'redirect':
    -            return res.redirect("https://appwrite.io", 301);
    -        case 'html':
    -            return res.send(
    -                "<h1>This is an HTML response</h1>", 200, {
    -                    "content-type": "text/html"
    -                });
    -        default:
    -            return res.send("This is a text response");
    -    }
    -}
    -
    - -
  • -

    Bun

    -
    -
    export default async ({ req, res, log }) => {
    -
         switch (req.query.type) {
             case 'empty':
                 return res.empty();
    @@ -1186,6 +1163,29 @@ namespace runtime {
             }
           }
       };
    +}
    +
    +
  • +
  • +

    Bun

    +
    +
    export default async ({ req, res, log }) => {
    +
    +    switch (req.query.type) {
    +        case 'empty':
    +            return res.empty();
    +        case 'json':
    +            return res.json({type": "This is a JSON response"});
    +        case 'redirect':
    +            return res.redirect("https://appwrite.io", 301);
    +        case 'html':
    +            return res.send(
    +                "<h1>This is an HTML response</h1>", 200, {
    +                    "content-type": "text/html"
    +                });
    +        default:
    +            return res.send("This is a text response");
    +    }
     }
  • @@ -1298,18 +1298,6 @@ end log(`This function was called with ${context.req.method} method`); error("This is an error, use for logging errors to console"); - return res.send("Check the Appwrite Console to see logs and errors!"); -}; - - -
  • -

    Bun

    -
    -
    export default async ({ res, log, error }: any) => {
    -    log("This is a log, use for logging information to console");
    -    log(`This function was called with ${context.req.method} method`);
    -    error("This is an error, use for logging errors to console");
    -
         return res.send("Check the Appwrite Console to see logs and errors!");
     };
    @@ -1419,6 +1407,18 @@ namespace runtime { }
  • +
  • +

    Bun

    +
    +
    export default async ({ res, log, error }: any) => {
    +    log("This is a log, use for logging information to console");
    +    log(`This function was called with ${context.req.method} method`);
    +    error("This is an error, use for logging errors to console");
    +
    +    return res.send("Check the Appwrite Console to see logs and errors!");
    +};
    +
    +
  • You can access these logs through the following steps.

      @@ -1561,14 +1561,6 @@ end
      export default async ({ req, res, log }) => {
           return res.send(Deno.env.get('MY_VAR'));
      -}
      -
      - -
    1. -

      Bun

      -
      -
      export default async ({ req, res, log }) => {
      -    return res.send(Bun.env.get('MY_VAR'));
       }
    2. @@ -1650,6 +1642,14 @@ namespace runtime { return context.res.send(std::getenv("MY_VAR")); }; +} + + +
    3. +

      Bun

      +
      +
      export default async ({ req, res, log }) => {
      +    return res.send(Bun.env.get('MY_VAR'));
       }
    4. @@ -1710,14 +1710,6 @@ namespace runtime { deno deno install - - - Bun icon - - Bun - bun - bun install - Dart icon @@ -1742,6 +1734,14 @@ namespace runtime { NuGet dotnet restore + + + Bun icon + + Bun + bun + bun install + Swift icon @@ -1947,35 +1947,6 @@ export default function ({req, res, error}: any){ return res.send("Failed to create document"); } - return res.send("Document created"); -} - - -
    5. -

      Bun

      -
      -
      import { Client, Databases, ID } from 'node-appwrite';
      -                
      -export default function ({req, res, error}: any){
      -    const client = new Client()
      -        .setEndpoint("https://cloud.appwrite.io/v1")
      -        .setProject(Bun.env.get("APPWRITE_FUNCTION_PROJECT_ID") || "")
      -        .setKey(Bun.env.get("APPWRITE_API_KEY") || "");
      -    
      -    const databases = new Databases(client);
      -    
      -    try {
      -        databases.createDocument(
      -            "[DATABASE_ID]",
      -            "[COLLECTION_ID]",
      -            ID.unique(),
      -            {}
      -        );
      -    } catch (e) {
      -        error("Failed to create document: " + e.message);
      -        return res.send("Failed to create document");
      -    }
      -    
           return res.send("Document created");
       }
      @@ -2149,6 +2120,35 @@ public class Main { return context.res.send("Document created"); } +} + +
    6. +
    7. +

      Bun

      +
      +
      import { Client, Databases, ID } from 'node-appwrite';
      +                
      +export default function ({req, res, error}: any){
      +    const client = new Client()
      +        .setEndpoint("https://cloud.appwrite.io/v1")
      +        .setProject(Bun.env.get("APPWRITE_FUNCTION_PROJECT_ID") || "")
      +        .setKey(Bun.env.get("APPWRITE_API_KEY") || "");
      +    
      +    const databases = new Databases(client);
      +    
      +    try {
      +        databases.createDocument(
      +            "[DATABASE_ID]",
      +            "[COLLECTION_ID]",
      +            ID.unique(),
      +            {}
      +        );
      +    } catch (e) {
      +        error("Failed to create document: " + e.message);
      +        return res.send("Failed to create document");
      +    }
      +    
      +    return res.send("Document created");
       }
    8. @@ -2340,40 +2340,6 @@ export default function ({req, res, error}: any){ return res.send("Failed to create document"); } - return res.send("Document created"); -} - - -
    9. -

      Bun

      -
      -
      import { Client, Databases, ID } from 'node-appwrite';
      -                
      -export default function ({req, res, error}: any){
      -    const client = new Client()
      -        .setEndpoint("https://cloud.appwrite.io/v1")
      -        .setProject(Bun.env.get("APPWRITE_FUNCTION_PROJECT_ID") || "")
      -    
      -    if (req.headers["x-appwrite-user-jwt"]) {
      -        client.setJWT(req.headers["x-appwrite-user-jwt"]);
      -    } else {
      -        return res.send("Please sign in, JWT not found");
      -    }
      -    
      -    const databases = new Databases(client);
      -    
      -    try {
      -        databases.createDocument(
      -            "[DATABASE_ID]",
      -            "[COLLECTION_ID]",
      -            ID.unique(),
      -            {}
      -        );
      -    } catch (e) {
      -        error("Failed to create document: " + e.message)
      -        return res.send("Failed to create document");
      -    }
      -    
           return res.send("Document created");
       }
      @@ -2573,6 +2539,40 @@ public class Main { return context.res.send("Document created"); } +} + +
    10. +
    11. +

      Bun

      +
      +
      import { Client, Databases, ID } from 'node-appwrite';
      +                
      +export default function ({req, res, error}: any){
      +    const client = new Client()
      +        .setEndpoint("https://cloud.appwrite.io/v1")
      +        .setProject(Bun.env.get("APPWRITE_FUNCTION_PROJECT_ID") || "")
      +    
      +    if (req.headers["x-appwrite-user-jwt"]) {
      +        client.setJWT(req.headers["x-appwrite-user-jwt"]);
      +    } else {
      +        return res.send("Please sign in, JWT not found");
      +    }
      +    
      +    const databases = new Databases(client);
      +    
      +    try {
      +        databases.createDocument(
      +            "[DATABASE_ID]",
      +            "[COLLECTION_ID]",
      +            ID.unique(),
      +            {}
      +        );
      +    } catch (e) {
      +        error("Failed to create document: " + e.message)
      +        return res.send("Failed to create document");
      +    }
      +    
      +    return res.send("Document created");
       }
    12. @@ -2678,25 +2678,6 @@ export function add(a: number, b: number): number { import { add } from './utils.ts'; -export default function ({res}: {res: any}) { - return res.send(add(1, 2)); -} - - -
    13. -

      Bun

      -
      -
      // src/utils.ts
      -
      -export function add(a: number, b: number): number {
      -    return a + b;
      -}
      -
      -
      -
      // src/main.ts
      -
      -import { add } from './utils.ts';
      -
       export default function ({res}: {res: any}) {
           return res.send(add(1, 2));
       }
      @@ -2825,6 +2806,25 @@ public class Main { public RuntimeOutput main(RuntimeContext context) throws Exception { return context.res.send(Utils.add(1, 2)); } +} +
      +
    14. +
    15. +

      Bun

      +
      +
      // src/utils.ts
      +
      +export function add(a: number, b: number): number {
      +    return a + b;
      +}
      +
      +
      +
      // src/main.ts
      +
      +import { add } from './utils.ts';
      +
      +export default function ({res}: {res: any}) {
      +    return res.send(add(1, 2));
       }
    16. From e6dab871ab674c0be7289de42c485d276674c844 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 14 Sep 2023 20:57:02 +0000 Subject: [PATCH 03/11] chore: adjust column width --- app/views/docs/functions-develop.phtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/docs/functions-develop.phtml b/app/views/docs/functions-develop.phtml index 1cf0cf0b..54f6e048 100644 --- a/app/views/docs/functions-develop.phtml +++ b/app/views/docs/functions-develop.phtml @@ -481,10 +481,10 @@ export default async ({ req, res, log, error }: any) => {

      You'll find these properties in the context object.

      - +
      - + From 3e486efdb3a7adc316af31fbafcf8faa70d73e76 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 14 Sep 2023 21:17:27 +0000 Subject: [PATCH 04/11] chore: adjust column width --- app/views/docs/functions-develop.phtml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/docs/functions-develop.phtml b/app/views/docs/functions-develop.phtml index 54f6e048..dba5d92d 100644 --- a/app/views/docs/functions-develop.phtml +++ b/app/views/docs/functions-develop.phtml @@ -481,7 +481,7 @@ export default async ({ req, res, log, error }: any) => {

      You'll find these properties in the context object.

      -
      PropertyProperty Description
      +
      @@ -504,7 +504,6 @@ export default async ({ req, res, log, error }: any) => { -
      Property
      error() Methoc to log errors to the Appwrite Console, end users will not be able to see these errors. See full examples here.
      From 1ac3ebf7200f49f63e53265ddb077fce1b96edd1 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 14 Sep 2023 17:17:51 -0400 Subject: [PATCH 05/11] Update app/views/docs/functions-develop.phtml Co-authored-by: Steven Nguyen <1477010+stnguyen90@users.noreply.github.com> --- app/views/docs/functions-develop.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/docs/functions-develop.phtml b/app/views/docs/functions-develop.phtml index dba5d92d..cf36bb39 100644 --- a/app/views/docs/functions-develop.phtml +++ b/app/views/docs/functions-develop.phtml @@ -1174,7 +1174,7 @@ namespace runtime { case 'empty': return res.empty(); case 'json': - return res.json({type": "This is a JSON response"}); + return res.json({type: "This is a JSON response"}); case 'redirect': return res.redirect("https://appwrite.io", 301); case 'html': From 1d48e95c971c373c8c7e2454cc1046d109c9bf99 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 14 Sep 2023 21:20:00 +0000 Subject: [PATCH 06/11] fix: missing quote --- app/views/docs/functions-develop.phtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/docs/functions-develop.phtml b/app/views/docs/functions-develop.phtml index dba5d92d..be14ecee 100644 --- a/app/views/docs/functions-develop.phtml +++ b/app/views/docs/functions-develop.phtml @@ -996,7 +996,7 @@ end case 'empty': return res.empty(); case 'json': - return res.json({type": "This is a JSON response"}); + return res.json({"type": "This is a JSON response"}); case 'redirect': return res.redirect("https://appwrite.io", 301); case 'html': @@ -1174,7 +1174,7 @@ namespace runtime { case 'empty': return res.empty(); case 'json': - return res.json({type": "This is a JSON response"}); + return res.json({"type": "This is a JSON response"}); case 'redirect': return res.redirect("https://appwrite.io", 301); case 'html': From 367628c1648eee988da5a20664c02073f72eff68 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 14 Sep 2023 21:25:11 +0000 Subject: [PATCH 07/11] chore: review comments --- app/views/docs/functions-develop.phtml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/docs/functions-develop.phtml b/app/views/docs/functions-develop.phtml index be14ecee..f55532ee 100644 --- a/app/views/docs/functions-develop.phtml +++ b/app/views/docs/functions-develop.phtml @@ -1292,9 +1292,9 @@ end
    17. Deno

      -
      export default async ({ res, log, error }: any) => {
      +                
      export default async ({ req, res, log, error }: any) => {
           log("This is a log, use for logging information to console");
      -    log(`This function was called with ${context.req.method} method`);
      +    log(`This function was called with ${req.method} method`);
           error("This is an error, use for logging errors to console");
       
           return res.send("Check the Appwrite Console to see logs and errors!");
      @@ -1409,9 +1409,9 @@ namespace runtime {
               
    18. Bun

      -
      export default async ({ res, log, error }: any) => {
      +                
      export default async ({ req, res, log, error }: any) => {
           log("This is a log, use for logging information to console");
      -    log(`This function was called with ${context.req.method} method`);
      +    log(`This function was called with ${req.method} method`);
           error("This is an error, use for logging errors to console");
       
           return res.send("Check the Appwrite Console to see logs and errors!");
      
      From e2996758cb5466a5ab5dffaeb5fdc188cc25d08f Mon Sep 17 00:00:00 2001
      From: Christy Jacob 
      Date: Thu, 14 Sep 2023 21:34:32 +0000
      Subject: [PATCH 08/11] chore: review comments
      
      ---
       app/views/docs/functions-develop.phtml | 2 +-
       1 file changed, 1 insertion(+), 1 deletion(-)
      
      diff --git a/app/views/docs/functions-develop.phtml b/app/views/docs/functions-develop.phtml
      index f55532ee..6cedea33 100644
      --- a/app/views/docs/functions-develop.phtml
      +++ b/app/views/docs/functions-develop.phtml
      @@ -1707,7 +1707,7 @@ namespace runtime {
                   
                   Deno
                   deno
      -            deno install
      +            deno cache <ENTRYPOINT_FILE>
               
               
                   
      
      From 0d3998ef3616ee100783e048a31a5819aae9f8db Mon Sep 17 00:00:00 2001
      From: "Vincent (Wen Yu) Ge" 
      Date: Thu, 14 Sep 2023 21:48:58 +0000
      Subject: [PATCH 09/11] fix the way we link to open runtimes
      
      ---
       app/views/docs/functions-runtimes.phtml | 12 ++++--------
       1 file changed, 4 insertions(+), 8 deletions(-)
      
      diff --git a/app/views/docs/functions-runtimes.phtml b/app/views/docs/functions-runtimes.phtml
      index 663d4eaf..08af0ab3 100644
      --- a/app/views/docs/functions-runtimes.phtml
      +++ b/app/views/docs/functions-runtimes.phtml
      @@ -43,7 +43,6 @@ foreach ($runtimes as $key => $item) {
                   Name
                   Version
                   
      -            Image
                   Architectures
               
           
      @@ -53,8 +52,10 @@ foreach ($runtimes as $key => $item) {
                   
                       Function Env.
                   
      -            
      -                escape($key); ?>
      +                            
      +            
      +                escape($key); ?>
      +            
                   
                   
                    $version): ?>
      @@ -68,11 +69,6 @@ foreach ($runtimes as $key => $item) {
                        
                    
                      
      -            
      -             $version): ?>
      -                escape($version['image'] ?? ''); ?> 
      -            
      -            
                   escape(implode(' / ', $runtime['versions'][0]['supports'] ?? [])); ?>
               
               
      
      From 35bb8b64677b5e70f7f8773864a238e1c1ff3453 Mon Sep 17 00:00:00 2001
      From: "Vincent (Wen Yu) Ge" 
      Date: Thu, 14 Sep 2023 22:16:09 +0000
      Subject: [PATCH 10/11] Clarify migration process
      
      ---
       app/views/docs/functions-develop.phtml | 7 ++++++-
       1 file changed, 6 insertions(+), 1 deletion(-)
      
      diff --git a/app/views/docs/functions-develop.phtml b/app/views/docs/functions-develop.phtml
      index 6cedea33..6ebb7d84 100644
      --- a/app/views/docs/functions-develop.phtml
      +++ b/app/views/docs/functions-develop.phtml
      @@ -2834,7 +2834,7 @@ export default function ({res}: {res: any}) {
           

      Appwrite Functions received major updates in Appwrite version 1.4. If you still have functions from previous versions, they will be read-only in Appwrite 1.4. - You will have to migrate your old functions to follow new runtime syntax. + You will have to recreate your old functions to follow new runtime syntax.

      @@ -2842,6 +2842,11 @@ export default function ({res}: {res: any}) {

        +
      1. + Your old function from 1.3 is marked read-only, but will continue to work. + You need to create a new function following 1.4 syntax. + After you've created your new function, point your application code to the new function and delete the old function. +
      2. The parameter passed into functions has changed. req and res has been replaced by context, which contains new logger methods. From e549657adad49c92c724de54f4d5d41bcb42b140 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 14 Sep 2023 19:06:10 -0400 Subject: [PATCH 11/11] Update app/views/docs/functions-develop.phtml Co-authored-by: Vincent (Wen Yu) Ge --- app/views/docs/functions-develop.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/docs/functions-develop.phtml b/app/views/docs/functions-develop.phtml index 6ebb7d84..ff92cc21 100644 --- a/app/views/docs/functions-develop.phtml +++ b/app/views/docs/functions-develop.phtml @@ -2843,7 +2843,7 @@ export default function ({res}: {res: any}) {
        1. - Your old function from 1.3 is marked read-only, but will continue to work. + Your old function from 1.3 will continue to work, but it can't be updated directly to a 1.4 function. You need to create a new function following 1.4 syntax. After you've created your new function, point your application code to the new function and delete the old function.