Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improved scaffolding for custom functions #1343

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions node/scaffold.go
Original file line number Diff line number Diff line change
@@ -104,17 +104,18 @@ func writeFunctionWrapper(function *proto.Action) string {

if proto.ActionIsArbitraryFunction(function) {
return fmt.Sprintf(`import { %s } from '@teamkeel/sdk';

// To learn more about what you can do with custom functions, visit https://docs.keel.so/functions
export default %s(async (ctx, inputs) => {

})`, functionName, functionName)
});`, functionName, functionName)
}

hookType := fmt.Sprintf("%sHooks", casing.ToCamel(function.Name))

return fmt.Sprintf(`import { %s, %s } from '@teamkeel/sdk';

// To learn more about what you can do with hooks,
// visit https://docs.keel.so/functions
// To learn more about what you can do with hooks, visit https://docs.keel.so/functions
const hooks : %s = {};

export default %s(hooks);
70 changes: 56 additions & 14 deletions node/scaffold_test.go
Original file line number Diff line number Diff line change
@@ -73,32 +73,74 @@ func TestScaffold(t *testing.T) {

expectedFiles := codegen.GeneratedFiles{
&codegen.GeneratedFile{
Contents: "import { CreatePost, CreatePostHooks } from '@teamkeel/sdk';\n\n// To learn more about what you can do with hooks,\n// visit https://docs.keel.so/functions\nconst hooks : CreatePostHooks = {};\n\nexport default CreatePost(hooks);\n\t",
Path: "functions/createPost.ts",
Contents: `
import { CreatePost, CreatePostHooks } from '@teamkeel/sdk';

// To learn more about what you can do with hooks, visit https://docs.keel.so/functions
const hooks : CreatePostHooks = {};

export default CreatePost(hooks);`,
Path: "functions/createPost.ts",
},
&codegen.GeneratedFile{
Contents: "import { ListPosts, ListPostsHooks } from '@teamkeel/sdk';\n\n// To learn more about what you can do with hooks,\n// visit https://docs.keel.so/functions\nconst hooks : ListPostsHooks = {};\n\nexport default ListPosts(hooks);\n\t",
Path: "functions/listPosts.ts",
Contents: `
import { ListPosts, ListPostsHooks } from '@teamkeel/sdk';

// To learn more about what you can do with hooks, visit https://docs.keel.so/functions
const hooks : ListPostsHooks = {};

export default ListPosts(hooks);`,
Path: "functions/listPosts.ts",
},
&codegen.GeneratedFile{
Contents: "import { UpdatePost, UpdatePostHooks } from '@teamkeel/sdk';\n\n// To learn more about what you can do with hooks,\n// visit https://docs.keel.so/functions\nconst hooks : UpdatePostHooks = {};\n\nexport default UpdatePost(hooks);\n\t",
Path: "functions/updatePost.ts",
Contents: `
import { UpdatePost, UpdatePostHooks } from '@teamkeel/sdk';

// To learn more about what you can do with hooks, visit https://docs.keel.so/functions
const hooks : UpdatePostHooks = {};

export default UpdatePost(hooks);`,
Path: "functions/updatePost.ts",
},
&codegen.GeneratedFile{
Contents: "import { GetPost, GetPostHooks } from '@teamkeel/sdk';\n\n// To learn more about what you can do with hooks,\n// visit https://docs.keel.so/functions\nconst hooks : GetPostHooks = {};\n\nexport default GetPost(hooks);\n\t",
Path: "functions/getPost.ts",
Contents: `
import { GetPost, GetPostHooks } from '@teamkeel/sdk';

// To learn more about what you can do with hooks, visit https://docs.keel.so/functions
const hooks : GetPostHooks = {};

export default GetPost(hooks);`,
Path: "functions/getPost.ts",
},
&codegen.GeneratedFile{
Contents: "import { DeletePost, DeletePostHooks } from '@teamkeel/sdk';\n\n// To learn more about what you can do with hooks,\n// visit https://docs.keel.so/functions\nconst hooks : DeletePostHooks = {};\n\nexport default DeletePost(hooks);\n\t",
Path: "functions/deletePost.ts",
Contents: `
import { DeletePost, DeletePostHooks } from '@teamkeel/sdk';

// To learn more about what you can do with hooks, visit https://docs.keel.so/functions
const hooks : DeletePostHooks = {};

export default DeletePost(hooks);`,
Path: "functions/deletePost.ts",
},
&codegen.GeneratedFile{
Contents: "import { CustomFunctionWrite } from '@teamkeel/sdk';\nexport default CustomFunctionWrite(async (ctx, inputs) => {\n\n})",
Path: "functions/customFunctionWrite.ts",
Contents: `
import { CustomFunctionWrite } from '@teamkeel/sdk';

// To learn more about what you can do with custom functions, visit https://docs.keel.so/functions
export default CustomFunctionWrite(async (ctx, inputs) => {

});`,
Path: "functions/customFunctionWrite.ts",
},
&codegen.GeneratedFile{
Contents: "import { CustomFunctionRead } from '@teamkeel/sdk';\nexport default CustomFunctionRead(async (ctx, inputs) => {\n\n})",
Path: "functions/customFunctionRead.ts",
Contents: `
import { CustomFunctionRead } from '@teamkeel/sdk';

// To learn more about what you can do with custom functions, visit https://docs.keel.so/functions
export default CustomFunctionRead(async (ctx, inputs) => {

});`,
Path: "functions/customFunctionRead.ts",
},
&codegen.GeneratedFile{
Contents: `