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

ftd.main-package (variable) and ftd.is_app_mounted (function) #2061

Merged
merged 10 commits into from
Feb 1, 2025

Conversation

siddhantk232
Copy link
Contributor

@siddhantk232 siddhantk232 commented Jan 31, 2025

Demo video: https://youtu.be/IrfsVCy7Y0Y

TODO

  • ftd.main-package variable
  • Add app param to ftd.app-path
  • ftd.is_app_mounted function
  • Update docs of ftd.app-path
  • Document ftd.main-package
  • Document ftd.is_app_mounted
  • Rename ftd.app-path -> ftd.app-url

@siddhantk232 siddhantk232 mentioned this pull request Jan 31, 2025
4 tasks
fastn-builtins/src/lib.rs Outdated Show resolved Hide resolved
@siddhantk232 siddhantk232 changed the title Feat/ftd app path ex ftd.main-package (variable) and ftd.is_app_mounted (function) Jan 31, 2025
WARN: the `ftd.main-package` does not work yet. It's stored in the
`global` map in js output and it's not getting resolved when used in an
ftd file. This should be key on `ftd` object itself.

- `ftd.main-package`: A string variable that stores the name of the
  packaeg. This is useful to determine if a package is mounted in
  another package or if it's running standalone.
- Refactor: Create `HostBuiltins` type and use it instead of Array of
  fixed sized type everywhere. This makes it easy to add new builtins
This allows to use the following in ftd code:

```ftd
-- ftd.text: $ftd.main-package
```
This variable is used to support the optional second parameter (app) in
`ftd.app-path` function.

The `ftd.app-path` function now takes a second optional arg. This arg is
used to construct app paths for any app that is mounted using
`fastn.app` in FASTN.ftd.
We don't need this definition here. This function is only invoked
internally through `ftd.app-path` function.
If a package has `lets-auth` app mounted. Then the following code will
show "Hello" as output:

```ftd
-- string app: lets-auth

-- ftd.text: Hello
if: { ftd.is_app_mounted(app) } ;; or ftd.is_app_mounted("lets-auth")
```
- Update the docs of `ftd.app-path` to mention the second `app`
  parameter.
- Document `ftd.main-package` string variable
- Document `ftd.is_app_mounted(app: string)` ftd function. This can be
  used to conditionally render things based on the mounting status of
  specific apps (using app package's system name)
`fastn` touches both the file system (through its fs routing) and the
urls (since it's a webserver, duh). This might create a situation where
people think `ftd.app-path` is something related to fs but it's really
constructing the path relative to your website url. For this reason,
this has been renamed to `ftd.app-url` instead.
@amitu amitu merged commit 4da95b6 into main Feb 1, 2025
1 check passed
@amitu amitu deleted the feat/ftd-app-path-ex branch February 1, 2025 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants