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

Entity templates #193

Merged
merged 10 commits into from
Jan 15, 2025
Merged

Entity templates #193

merged 10 commits into from
Jan 15, 2025

Conversation

theoephraim
Copy link
Member

This is a big update, driven by the goal of making entity templates work - which will be very important for deployment functionality.

Templates can now be created and entities can extend them. Templates can create/update/remove multiple entities from the graph. IDs are all relative to the template while inside of it, and while this was difficult to implement, for end users it should just feel intuitive. We wont see any user-facing DMNO changes just yet, but these will come next.

In the process, we also changed how "pick" works, to be more unified with the rest of the schema. Now it is reimplimented as a special kind of data type, and uses the existing data type chain for its settings. Rather than being defined in a separate section we now use pick via extends - for example: SOME_ITEM: { extends: pick('someEntityId', 'someNode') and because of the shorthand format already available (ie SOME_ITEM: 'string'), this means SOME_ITEM: pick() will also work.

The pick args work like this:

  • ITEM: pick() - defaults to picking from graph/template root, use same node path
  • ITEM: pick('entityId') - specify entity by id, use same node path
  • ITEM: pick('entityId', 'somePath') - specify both entity id and node path

While we lose the ability to pick multiple keys at once, these changes were driven by user feedback and are worthwhile.

Additionally this removed some existing constraints around what is considered a cycle, and the system is now more permissive.

Copy link

changeset-bot bot commented Jan 13, 2025

🦋 Changeset detected

Latest commit: 692e6db

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@dmno/encrypted-vault-plugin Patch
@dmno/remix-integration Patch
@dmno/vite-integration Patch
@dmno/1password-plugin Patch
@dmno/configraph Patch
dmno Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the maintainer Created by an official project maintainer label Jan 13, 2025
Copy link

pkg-pr-new bot commented Jan 13, 2025

Open in Stackblitz

dmno

npm i https://pkg.pr.new/dmno@193

@dmno/configraph

npm i https://pkg.pr.new/@dmno/configraph@193

@dmno/remix-integration

npm i https://pkg.pr.new/@dmno/remix-integration@193

@dmno/vite-integration

npm i https://pkg.pr.new/@dmno/vite-integration@193

@dmno/cloudflare-platform

npm i https://pkg.pr.new/@dmno/cloudflare-platform@193

@dmno/1password-plugin

npm i https://pkg.pr.new/@dmno/1password-plugin@193

@dmno/encrypted-vault-plugin

npm i https://pkg.pr.new/@dmno/encrypted-vault-plugin@193

commit: 692e6db


readonly graphRoot: Configraph;
readonly templateRootEntity?: ConfigraphEntity<EntityMetadata, NodeMetadata>;

constructor(
Copy link
Member Author

Choose a reason for hiding this comment

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

This is where the significant changes are.

we now follow up a chain of templates, applying the changes to config nodes from each, and adding/deleting/removing additional entities to the graph if applicable


// add graph edges based on "pick"
// we will not process individual items yet, but this will give us a DAG of entity dependencies
for (const entity of entitiesArray) {
Copy link
Member Author

Choose a reason for hiding this comment

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

no longer doing all these shenanigans with pick up front. instead we create the nodes normally, and then do a pass to re-connect picked nodes to their sources

import { templateContextAls } from './entity-template';

// special new data type that will delegate calls back to the original "picked" data type
export class PickedDataType extends ConfigraphDataType {
Copy link
Member Author

Choose a reason for hiding this comment

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

pick is a little different than something like inject - which is just a resolver. Pick needs to set all of the data type properties, not just how it is resolved, so we need to be able to link to the source node.

While the line here between data types / config nodes / resolvers all gets a bit blurrier than I would like, I think the end result for users is fairly clean and intuitive.

Copy link

cloudflare-workers-and-pages bot commented Jan 14, 2025

Deploying dmno with  Cloudflare Pages  Cloudflare Pages

Latest commit: 692e6db
Status: ✅  Deploy successful!
Preview URL: https://6d5e89db.dmno.pages.dev
Branch Preview URL: https://entity-templates.dmno.pages.dev

View logs

Making entity templates actually work invovled some larger changes, many of which were nice simplicications of other moving parts.

Templates can now be created and entities can extend them. Templates can create/update/remove multiple entities from the graph. IDs are all relative to the template while inside of it, and while this was difficult to implement, for end users it should just feel intuitive.

The big non-template change is that now pick is more unified with the rest of the system - reimplimented as a special kind of data type. Rather than being defined in a separate section we now use pick via extends - for example: `SOME_ITEM: { extends: pick('someEntityId', 'someNode')` and because of the shorthand format already available (ie `SOME_ITEM: 'string'`), this means `SOME_ITEM: pick()` will also work.

The pick args work like this:
- `ITEM: pick()` - defaults to picking from graph/template root, use same node path
- `ITEM: pick('entityId')` - specify entity by id, use same node path
- `ITEM: pick('entityId', 'somePath')` - specify both entity id and node path

While we lose the ability to pick multiple keys at once, these changes were driven by user feedback and are worthwhile.
Copy link
Contributor

@philmillman philmillman left a comment

Choose a reason for hiding this comment

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

added a few nits, but docs look good. That stable id plugin will help a lot!

@theoephraim theoephraim merged commit 4489744 into main Jan 15, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-site maintainer Created by an official project maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants