-
Notifications
You must be signed in to change notification settings - Fork 1
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
#2 Relations and References #3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a relation example as well, wouldn't it make more sense to extend that instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for you input. There are some points that might be addressed:
- Relative fields are recognized on top level only (for the import).
- The imports required for the transformers should be defined by the transformers themselves. Thus, they should be called first, returning their dependencies in the result payload.
- Runtime types are unsupported, which might be okay. But consequently, this feature has to be removed entirely someday, as I'm not even using them for myself.
I don't want to bother you aligning this, I might add the changes myself, if it's okay for you.
@@ -56,9 +56,16 @@ export async function loadAndTransformCollections( | |||
const keys = { name: collection.name }; | |||
const name = naming.replace(/%%(\w+)%%/, (_, k: keyof typeof keys) => keys[k] ?? _); | |||
const path = resolve(to, name); | |||
const relational = collection.fields?.some(field => field.widget === 'relation'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would fail on nested fields. This should be a recursive lookup. Or what might be better, is some additional property in the result payload of the transformers, so the imports would be build after transformations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think about or test with nested relations, my bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. I changed the transform result to include a dependencies property, this should do the trick.
} | ||
|
||
// Normalises quotes in the cptime output for consistent comparison | ||
function normaliseCptime(cptime: string): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the test data is explicitly defined and the transformers are deterministic, this should not be necessary. Instead, we must trust the resulting output to have a specific kind of quote and expect them to have always the same shape.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was only added because of a battle between eslint and prettier, so it's there to satisfy the IDE only.
I couldn't get eslint and prettier rules to agree on quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. But badly configured tooling shouldn't force us to do such things. I'll align the configuration.
cptime: 'z.string()', | ||
}); | ||
) => { | ||
const runtime = multiple ? z.array(z.string()) : z.string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the reason I haven't thrown it together yet... 😅
Even though I like the idea using the generated reference
function, this is no option for the runtime version.
Tbh, I'm not sure if supporting the runtime types anyway, as I personally just generate the types in watch mode as static files. So it maybe makes sense to drop them entirely...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also not really using / interested in the runtime side of things. I include adc as part of my build process and watch the content dir to trigger a new build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll drop the runtime support, that reduces complexity for several aspects.
Maybe that can be implemented one day using the approach now available for tests using eval (or something less evil)...
This PR updates the relation transformer to include astro's reference helper function.
Closes #2