Skip to content

Commit

Permalink
Merge pull request #1102 from Genez-io/dev
Browse files Browse the repository at this point in the history
Release 2.0
  • Loading branch information
costinsin authored May 29, 2024
2 parents d4481ed + 5e81144 commit 6c7f8a0
Show file tree
Hide file tree
Showing 81 changed files with 3,075 additions and 1,568 deletions.
2 changes: 1 addition & 1 deletion examples
1,602 changes: 1,087 additions & 515 deletions package-lock.json

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genezio",
"version": "1.2.2",
"version": "2.0.0",
"description": "Command line utility to interact with Genezio infrastructure.",
"exports": "./index.js",
"type": "module",
Expand Down Expand Up @@ -42,17 +42,18 @@
"license": "GPL-3",
"dependencies": {
"@amplitude/analytics-node": "^1.3.5",
"@aws-sdk/client-cloudformation": "^3.535.0",
"@aws-sdk/client-cloudformation": "^3.569.0",
"@aws-sdk/client-s3": "^3.554.0",
"@babel/core": "^7.23.9",
"@babel/core": "^7.24.5",
"@babel/parser": "^7.24.4",
"@babel/plugin-proposal-decorators": "^7.23.9",
"@babel/preset-env": "^7.24.4",
"@babel/preset-typescript": "^7.23.3",
"@babel/preset-typescript": "^7.24.6",
"@babel/traverse": "^7.24.1",
"@genezio/test-interface-component": "^1.0.1",
"@genezio/test-interface-component": "^1.1.3",
"@sentry/node": "^7.110.1",
"@sentry/profiling-node": "~7.108.0",
"@webcontainer/env": "^1.1.1",
"archiver": "^7.0.1",
"async-mutex": "^0.5.0",
"await-exec": "^0.1.2",
Expand All @@ -66,11 +67,11 @@
"cli-spinner": "^0.2.10",
"cli-table": "^0.3.11",
"colors": "^1.4.0",
"commander": "^12.0.0",
"commander": "^12.1.0",
"cors": "^2.8.5",
"cron-validator": "^1.3.1",
"decompress": "^4.2.1",
"dir-compare": "^4.2.0",
"dir-compare": "^5.0.0",
"dotenv": "^16.4.5",
"esbuild": "^0.18.20",
"esbuild-node-externals": "^1.11.0",
Expand All @@ -79,32 +80,30 @@
"fs-extra": "^11.2.0",
"glob": "^8.0.3",
"hash-it": "^6.0.0",
"http-proxy": "^1.18.1",
"inquirer": "^9.2.15",
"isomorphic-git": "^1.25.6",
"isomorphic-git": "^1.25.10",
"latest-version": "^9.0.0",
"lodash": "^4.17.21",
"log-update": "^6.0.0",
"loglevel-plugin-prefix": "^0.8.4",
"memfs": "^4.6.0",
"memfs": "^4.9.2",
"mime-types": "^2.1.35",
"mustache": "^4.2.0",
"node-abort-controller": "^3.1.1",
"node-cron": "^3.0.3",
"open": "^10.1.0",
"ora": "^8.0.1",
"semver": "^7.5.4",
"tree-sitter": "0.20.6",
"tree-sitter-go": "0.20.0",
"tree-sitter-typescript": "^0.20.5",
"semver": "^7.6.2",
"tslog": "^4.9.2",
"typescript": "^5.4.4",
"unique-names-generator": "^4.7.1",
"uuid": "^9.0.1",
"whatwg-mimetype": "~3.0.0",
"which": "^4.0.0",
"yaml": "^2.4.0",
"yaml": "^2.4.2",
"yaml-transmute": "^0.0.7",
"zod": "^3.22.4"
"zod": "^3.23.8"
},
"repository": {
"type": "git",
Expand All @@ -114,7 +113,7 @@
"genezio": "./build/src/index.js"
},
"devDependencies": {
"@babel/types": "^7.23.6",
"@babel/types": "^7.24.5",
"@types/archiver": "^6.0.2",
"@types/babel__core": "^7.20.5",
"@types/babel__traverse": "^7.20.4",
Expand All @@ -128,16 +127,17 @@
"@types/express": "^4.17.21",
"@types/fs-extra": "^11.0.4",
"@types/glob": "^8.0.0",
"@types/http-proxy": "^1.17.14",
"@types/inquirer": "^9.0.7",
"@types/lodash": "^4.14.202",
"@types/lodash": "^4.17.4",
"@types/mime-types": "^2.1.3",
"@types/mustache": "^4.2.5",
"@types/node": "^20.11.25",
"@types/node-cron": "^3.0.11",
"@types/uuid": "^9.0.8",
"@types/whatwg-mimetype": "~3.0.0",
"@types/which": "^3.0.3",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^6.18.0",
"envify": "^4.1.0",
"eslint": "^8.55.0",
Expand All @@ -151,14 +151,14 @@
"optionalDependencies": {
"@rollup/rollup-android-arm-eabi": "4.9.4",
"@rollup/rollup-android-arm64": "4.14.1",
"@rollup/rollup-darwin-arm64": "4.14.1",
"@rollup/rollup-darwin-x64": "4.13.2",
"@rollup/rollup-linux-arm-gnueabihf": "4.13.0",
"@rollup/rollup-linux-arm64-gnu": "4.12.1",
"@rollup/rollup-linux-arm64-musl": "4.14.3",
"@rollup/rollup-darwin-arm64": "4.16.1",
"@rollup/rollup-darwin-x64": "4.17.1",
"@rollup/rollup-linux-arm-gnueabihf": "4.17.2",
"@rollup/rollup-linux-arm64-gnu": "4.17.2",
"@rollup/rollup-linux-arm64-musl": "4.17.2",
"@rollup/rollup-linux-riscv64-gnu": "4.9.6",
"@rollup/rollup-linux-x64-gnu": "4.14.3",
"@rollup/rollup-linux-x64-musl": "4.13.0",
"@rollup/rollup-linux-x64-musl": "4.18.0",
"@rollup/rollup-win32-arm64-msvc": "4.14.3",
"@rollup/rollup-win32-ia32-msvc": "4.14.3",
"@rollup/rollup-win32-x64-msvc": "4.9.2"
Expand Down
2 changes: 2 additions & 0 deletions src/bundlers/bundler.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export type BundlerInput = {
installDeps?: boolean;
allNonJsFilesPaths?: FileDetails[];
disableOptimization?: boolean;
type?: "class" | "function";
entryFile?: string;
};
};

Expand Down
26 changes: 14 additions & 12 deletions src/bundlers/go/genezioRuntimeGoBundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@ export class GenezioRuntimeGoBundler extends GoBundler {

generateErrorReturn(): string {
return `
sendError(w, err, JsonRpcMethod)
sendError(ctx, w, err, JsonRpcMethod)
return
`;
}

async compile(folderPath: string, _: BundlerInput) {
// Compile the Go code locally
const getDependencyResult = $({ cwd: folderPath })
.sync`go get github.com/Genez-io/genezio_types`;
if (getDependencyResult.exitCode == null) {
log.info(
"There was an error while running the go script, make sure you have the correct permissions.",
);
throw new UserError("Compilation error! Please check your code and try again.");
} else if (getDependencyResult.exitCode != 0) {
log.info(getDependencyResult.stderr.toString());
log.info(getDependencyResult.stdout.toString());
throw new UserError("Compilation error! Please check your code and try again.");
const dependencies = ["github.com/Genez-io/genezio_types", "github.com/Genez-io/auth"];
for (const dependency of dependencies) {
const getDependencyResult = $({ cwd: folderPath }).sync`go get ${dependency}`;
if (getDependencyResult.exitCode == null) {
log.info(
"There was an error while running the go script, make sure you have the correct permissions.",
);
throw new UserError("Compilation error! Please check your code and try again.");
} else if (getDependencyResult.exitCode != 0) {
log.info(getDependencyResult.stderr.toString());
log.info(getDependencyResult.stdout.toString());
throw new UserError("Compilation error! Please check your code and try again.");
}
}
process.env["GOOS"] = "linux";
process.env["GOARCH"] = "amd64";
Expand Down
43 changes: 34 additions & 9 deletions src/bundlers/go/genezioRuntimeGoMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ import (
"strconv"
"strings"
"time"
"context"
"github.com/Genez-io/genezio_types"
{{#usesAuth}}
"github.com/Genez-io/auth"
{{/usesAuth}}
{{#imports}}
{{#named}}{{name}} {{/named}}"{{{path}}}"
{{/imports}}
Expand Down Expand Up @@ -74,7 +79,7 @@ const (
JsonRpcMethod MethodType = "jsonrpc"
)
func sendError(w http.ResponseWriter, err error, methodType MethodType) {
func sendError(ctx context.Context, w http.ResponseWriter, err error, methodType MethodType) {
genezioError := make(map[string]interface{})
byteError, error := json.Marshal(err)
if error != nil {
Expand Down Expand Up @@ -122,6 +127,8 @@ func (g requestHandler) HandleRequest(w http.ResponseWriter, r *http.Request) {
var responseBody ResponseBody
var err error
ctx := r.Context()
defer r.Body.Close()
class := {{class.packageName}}.New()
Expand Down Expand Up @@ -181,20 +188,20 @@ func (g requestHandler) HandleRequest(w http.ResponseWriter, r *http.Request) {
case "{{name}}":
result, err = class.{{name}}(genezioRequest)
if err != nil {
sendError(w, err, HttpMethod)
sendError(ctx, w, err, HttpMethod)
return
}
{{/httpMethods}}
default:
sendError(w, errors.New("http method not found"), HttpMethod)
sendError(ctx, w, errors.New("http method not found"), HttpMethod)
return
}
strBody, ok := result.Body.(string)
if !ok {
resultBody, err := json.Marshal(result.Body)
if err != nil {
sendError(w, err, HttpMethod)
sendError(ctx, w, err, HttpMethod)
return
}
strBody = string(resultBody)
Expand All @@ -219,9 +226,27 @@ func (g requestHandler) HandleRequest(w http.ResponseWriter, r *http.Request) {
{{#parameters}}
{{{cast}}}
{{/parameters}}
{{#auth}}
gnzContext, ok := body.Params[0].(map[string]interface{})
if !ok {
sendError(ctx, w, errors.New("invalid context"), JsonRpcMethod)
return
}
token, ok := gnzContext["token"].(string)
if !ok {
sendError(ctx, w, errors.New("invalid token"), JsonRpcMethod)
return
}
user, err := auth.GetUserByToken(token)
if err != nil {
sendError(ctx, w, err, JsonRpcMethod)
return
}
param0 = context.WithValue(ctx, "user", user)
{{/auth}}
{{^isVoid}}result, {{/isVoid}}err {{^isVoid}}:{{/isVoid}}= class.{{name}}({{#parameters}}param{{index}}{{^last}}, {{/last}}{{/parameters}})
if err != nil {
sendError(w, err, JsonRpcMethod)
sendError(ctx, w, err, JsonRpcMethod)
return
}
{{^isVoid}}
Expand All @@ -232,12 +257,12 @@ func (g requestHandler) HandleRequest(w http.ResponseWriter, r *http.Request) {
case "{{class.name}}.{{name}}":
err := class.{{name}}()
if err != nil {
sendError(w, err, JsonRpcMethod)
sendError(ctx, w, err, JsonRpcMethod)
return
}
{{/cronMethods}}
default:
sendError(w, errors.New("method not found"), JsonRpcMethod)
sendError(ctx, w, errors.New("method not found"), JsonRpcMethod)
return
}
responseBody.Id = body.Id
Expand All @@ -246,7 +271,7 @@ func (g requestHandler) HandleRequest(w http.ResponseWriter, r *http.Request) {
bodyString, err := json.Marshal(responseBody)
if err != nil {
sendError(w, err, JsonRpcMethod)
sendError(ctx, w, err, JsonRpcMethod)
return
}
Expand All @@ -261,7 +286,7 @@ func (g requestHandler) HandleRequest(w http.ResponseWriter, r *http.Request) {
// Encode the struct into JSON and check for errors
responseByte, err := json.Marshal(response)
if err != nil {
sendError(w, err, JsonRpcMethod)
sendError(ctx, w, err, JsonRpcMethod)
return
}
w.Header().Set("Content-Type", "application/json")
Expand Down
4 changes: 2 additions & 2 deletions src/bundlers/go/goBundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { BundlerInterface } from "../bundler.interface.js";

export function NewGoBundler(projectConfiguration: ProjectConfiguration): BundlerInterface {
if (
projectConfiguration.cloudProvider == CloudProviderIdentifier.CAPYBARA ||
projectConfiguration.cloudProvider == CloudProviderIdentifier.CAPYBARA_LINUX
projectConfiguration.cloudProvider == CloudProviderIdentifier.GENEZIO_UNIKERNEL ||
projectConfiguration.cloudProvider == CloudProviderIdentifier.GENEZIO_CLOUD
) {
return new GenezioRuntimeGoBundler();
}
Expand Down
15 changes: 14 additions & 1 deletion src/bundlers/go/goBundlerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type ImportView = {

type MoustanceViewForMain = {
imports: ImportView[];
usesAuth: boolean;
class: {
name: string;
packageName: string | undefined;
Expand All @@ -46,6 +47,7 @@ type MoustanceViewForMain = {
}[];
jsonRpcMethods: {
name: string;
auth: boolean;
parameters: {
index: number;
cast: string;
Expand Down Expand Up @@ -150,8 +152,13 @@ export abstract class GoBundler implements BundlerInterface {
}
return `paramFloat${index} := body.Params[${index}].(float64)
param${index} := int(paramFloat${index})`;
case AstNodeType.MapType:
case AstNodeType.CustomNodeLiteral:
if ((parameter.type as CustomAstNodeType).rawValue === "GnzContext") {
return `param${index} := ctx`;
}
// intentional fallthrough
// eslint-disable-next-line no-fallthrough
case AstNodeType.MapType:
case AstNodeType.ArrayType:
return `var param${index} ${parameter.optional ? "*" : ""}${this.#mapTypeToGoType(
parameter.type,
Expand Down Expand Up @@ -196,6 +203,7 @@ export abstract class GoBundler implements BundlerInterface {

const moustacheViewForMain: MoustanceViewForMain = {
imports: [],
usesAuth: classConfiguration.methods.some((m) => m.auth),
class: {
name: mainClass.name,
packageName: mainClass.path?.substring(mainClass.path.lastIndexOf("/") + 1),
Expand All @@ -214,6 +222,7 @@ export abstract class GoBundler implements BundlerInterface {
.filter((m) => m.type === TriggerType.jsonrpc)
.map((m: MethodConfiguration) => ({
name: m.name,
auth: m.auth ?? false,
isVoid: m.returnType.type === AstNodeType.VoidLiteral,
parameters: m.parameters.map((p, index) => ({
index,
Expand Down Expand Up @@ -258,6 +267,10 @@ export abstract class GoBundler implements BundlerInterface {
return {
...input,
path: inputTemporaryFolder,
extra: {
...input.extra,
entryFile: "bootstrap",
},
};
}

Expand Down
1 change: 1 addition & 0 deletions src/bundlers/go/lambdaGoBundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class LambdaGoBundler extends GoBundler {
const dependencies = [
"github.com/aws/aws-lambda-go/lambda",
"github.com/Genez-io/genezio_types",
"github.com/Genez-io/auth",
];
for (const dependency of dependencies) {
const getDependencyResult = $({ cwd: folderPath }).sync`go get ${dependency}`;
Expand Down
Loading

0 comments on commit 6c7f8a0

Please sign in to comment.