Skip to content

Conversation

@KernelDeimos
Copy link
Contributor

@KernelDeimos KernelDeimos commented Dec 24, 2025

Scope

This PR covers implementing the apps driver, which will replace the es:apps driver.

  • Later, es:subdomains and es:notifications will separately be moved away from the EntityStorage system.
  • This PR only covers es:apps.

Process/Convention Notes

  • This PR is regularly rebased on main.
  • Commits are intended to be well-formed, so this PR should be merged with the "Rebase and merge" option.

Method Implementations

  • apps.select()
  • apps.read()
  • apps.create()
  • apps.update()
  • apps.upsert()
  • apps.delete()

Regression Discovery

  • Write regression tests .select() to test es:app -> app
  • Write regression tests .read() to test es:app -> app
  • Write regression tests .create() to test es:app -> app
  • Write regression tests .update() to test es:app -> app
  • Write regression tests .upsert() to test es:app -> app
  • Write regression tests .delete() to test es:app -> app

Regression Fixes

this list will be populated later

Other Tasks

  • Test/implement protected apps support
  • Manual access policy testing

@KernelDeimos KernelDeimos marked this pull request as draft December 24, 2025 00:13
@KernelDeimos KernelDeimos changed the title Data access simplifications Data access simplifications (part 1: apps driver) Dec 24, 2025
@KernelDeimos KernelDeimos force-pushed the eric/25CN0-entity-refactor branch 3 times, most recently from bb96940 to 5bba01b Compare December 30, 2025 22:24
@KernelDeimos KernelDeimos force-pushed the eric/25CN0-entity-refactor branch from c39cac9 to 4f97755 Compare January 6, 2026 02:41
Adds `as_bool` utility function for boolean values from MySQL and
Sqlite, based on the previous implementatoin for ES/OM.
It turns out self-referencing tables add some nuances to what is and
what isn't ambiguous in SQL queries, so getting this right took a little
longer than expected. Following the entire chain doesn't seem to be
possible so a compromise is made by only traversing one level of depth.
(you can the uid of the owner of the app, but not the uid of the owner
app's own owner)
Adds the `icon_size` parameter to the `.select()` method on the new
non-ES/OM implementation.

When adding the necessary `params` parameter to the `.select()`
method, it was noticed that the `predicate` parameter did not have a
default value - potentially causing a regression; a default value was
set for both `params` and `predicate`.
Most of this implementation matched `.select()` which saved time. The
common behavior can be factored out, but since the purpose of this
refactor is to flatten everything as much as possible I'm going to leave
the duplicated code and make a note to do this later.

The challenging part was `#build_complex_id_where()`, which is the
equivalent to the `fetch_based_on_complex_id_()` method in
EntityStoreService. This allows `uid: app-UUID-OF-APP` and `id: { name:
'editor' }` to both work.
Fixes are also included for a couple issues that were found:
- `null` being included in extensions list
- property called `user_owner` instead of `owner`
DRY some redundant code and use guard clauses where applicable.
Primarily these tests were AI generated an then checked over for sanity.
These tests are good unit tests to avoid regressions as a result of
changes to this code but are not sufficient to test for regressions
introduced by this new implementation that will replace `es:app`.
This is a naive implementation of the `.upsert()` method that simply
calls `.create()` or `.update()` depending on whether or not the app
already exists.
This test was very difficult to get working because of issues
initializing the context under vitest. After a lot of effort and trying
to narrow down the issue in many ways that didn't work, I eventually
found that manually setting the storage and calling run on the
AsyncLocalStorage object got it working. I'm currently unsure if this is
specific to vitest or not. We don't seem to do this in Puter's kernel
but everything works fine in the typical runtime. Maybe this is
side-effect of otel's own use of AsyncLocalStorage.
The `helpers.js` file has two instances when testing with vitest.
Usually this can be solved by creating an "import bridge" file - another
CJS file that imports the desired CJS file and re-exports it so that the
`require` mechanism for caching modules is used instead of the `import`
mechanism for caching modules. Unfortunately in my most recent test
cases this does not work. I do not know why this does not work. However,
without doing a deep-dive into the internals of vitest I can at least
see that the only state in helpers is for providing `services` as a
pseudo-global, so a hack with `Symbol.for` solves everything.
The file `context.js` causes problems in unit tests because vitest does
not play nice with CJS, especially when both CJS and ESM are in use such
as in our repository.

Given that it is not feasible to solve the underlying interoperability
issue, I have elected to make `context.js` a singleton in `Symbol.for`.
This worked very well with `helpers.js`.
@KernelDeimos KernelDeimos force-pushed the eric/25CN0-entity-refactor branch from 4f97755 to 62ed715 Compare January 6, 2026 20:24
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.

2 participants