Skip to content

Conversation

@bruchanik
Copy link
Collaborator

@bruchanik bruchanik commented Aug 21, 2025

TL;DR

Resolves #71

This PR introduces a system for built-in and user-defined functions to TeaPie, allowing dynamic value generation in scripts and .http files.

Highlights

  • 🔧 Function system

    • New infrastructure for defining, registering, validating, and executing functions

    • Built-in functions:

      • $now → current timestamp
      • $guid → new GUID
      • $rand → random double
      • $randomInt → random integer
    • Resolver for parsing/executing functions in .http files (with argument parsing via System.CommandLine)

    • Functions are injectable across the application

  • 📖 Documentation

    • New page with function usage, naming rules, argument handling, and examples
  • 🧪 Demo & Tests

    • Updated demo scripts and tests with custom functions (e.g. $carReturnDate)
    • Function resolution tested in HTTP requests/responses
    • Minor corrections in server & CRUD configs to align with function workflows

Files of interest

  • Core: src/TeaPie/Functions/*
  • Resolver: src/TeaPie/Functions/FunctionsResolver.cs
  • Docs: docs/docs/functions.md
  • Demo/tests: demo/Tests/003-Car-Rentals/*, demo/.teapie/Definitions/CarRent.csx, demo/server/CarRentalServer.json

Add custom functions, similiary to variables.
Add predefined Add new feature - Functions
Add predefined system functions.
Add missing test scenarios.
Add functions to demo.
Edit documentation.
@bruchanik bruchanik requested a review from Copilot August 21, 2025 11:45
Suppress warning for nuget and change version for nuget package
Addressing comments from PR.
@bruchanik bruchanik marked this pull request as ready for review August 21, 2025 13:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@matejicko matejicko self-requested a review September 2, 2025 11:02
}

return _func((T1)Convert.ChangeType(args[0], typeof(T1)), (T2)Convert.ChangeType(args[1], typeof(T2)));
return _func((TParameter1)Convert.ChangeType(args[0], typeof(TParameter1)), (TParameter2)Convert.ChangeType(args[1], typeof(TParameter2)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too long line.

}

internal class Function<T1, T2, T>(string name, Func<T1, T2, T> func) : Function(name)
internal class Function<TParameter1, TParameter2, TResult>(string name, Func<TParameter1, TParameter2, TResult> func) : Function(name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too long line.

@bruchanik bruchanik merged commit ee77717 into master Sep 2, 2025
4 checks passed
@bruchanik bruchanik deleted the feature/function-variables branch September 2, 2025 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🚀 [NEW] Function Variables

4 participants