Skip to content

docs: document static loadAsInstance in the v5 Resource API reference - #619

Open
kriszyp wants to merge 4 commits into
mainfrom
kris/deprecate-loadasinstance
Open

docs: document static loadAsInstance in the v5 Resource API reference#619
kriszyp wants to merge 4 commits into
mainfrom
kris/deprecate-loadasinstance

Conversation

@kriszyp

@kriszyp kriszyp commented Aug 4, 2026

Copy link
Copy Markdown
Member

Summary

loadAsInstance isn't mentioned anywhere in the v5 Resource API reference. With nothing in the reference to guide them, AI coding agents copying older example code (e.g. engineering-metrics/DevLogin.ts) reintroduce static loadAsInstance = false; into fresh v5 resources and then argue it's required — see the Slack thread that prompted this.

This adds a short static loadAsInstance?: boolean subsection at the top of "Resource Static Methods", plus a cross-reference from the back-compat instance-method list. It deliberately does not restate the mode internals — the v4 reference's API Versions section already documents both modes in full, so the v5 page links there and stays focused on what a v5 author needs to decide.

The two things worth documenting

Verified against resources/Resource.ts and resources/Table.ts on main:

  1. Overridden static methods are unaffected by the flag. It is only read inside Harper's built-in dispatch, at the point that dispatch instantiates the resource and calls the corresponding instance method. Defining static get/static post replaces that dispatch — including the code reading the flag — so a custom static always receives (target, data) regardless. This is a large part of why static methods are the recommended shape for custom endpoints, and it's the direct answer to the confusion in the thread.

  2. The flag is still live in v5, so the line is not safe to delete on its own. It still selects the argument order for REST-mirroring instance verbs. Removing static loadAsInstance = false; from a resource that still defines those instance methods reverses their argument order and breaks them. It can only come out as part of converting them to statics.

Notes for reviewers

  • Dropped the applied VersionBadge. 641db8a (gemini-code-assist suggestion) added <VersionBadge type="changed" version="v5.0.0" />. That was premised on an earlier draft of mine which wrongly claimed v5 made the flag's behavior unconditional for static methods. The corrected text says the opposite — the instance-method behavior is unchanged and still live — so a "changed in v5.0.0" badge would be inaccurate. Happy to add a plain (non-changed) badge instead if we want one here.
  • Dropped a behavior-comparison table that an earlier revision included. One row claimed records are mutable in default mode and frozen with the flag; that conflated the record (frozen either way) with the Resource instance the instance verbs are called on (mutable). Deferring to the v4 doc avoids re-deriving these details in two places.

Test plan

  • Mechanism verified against resources/Resource.ts (the loadAsInstance branches inside each verb's transactional dispatch) and resources/Table.ts (getResource preload, get(string) semantics, permission placement)
  • npx prettier --write reference/resources/resource-api.md — clean
  • Anchors confirmed against github-slugger output (#api-versions, #resource-instance-methods, #static-loadasinstance-boolean); repo uses generated slugs, not explicit heading ids
  • Relative path to reference_versioned_docs/version-v4/... matches the existing cross-version link already in this file
  • Docs site preview / review

🤖 Generated with Claude Code

The flag was dropped from the v5 docs without explanation, so AI coding
agents copying older example code (e.g. engineering-metrics/DevLogin.ts)
reintroduce it as if still required. Document that the v4 loadAsInstance=false
behavior is unconditional in v5 and the flag is now a no-op.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@kriszyp
kriszyp requested a review from a team as a code owner August 4, 2026 15:32

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds documentation to reference/resources/resource-api.md regarding the deprecation of the static loadAsInstance property in v5. The reviewer suggested adding a VersionBadge component to properly document this behavior change in accordance with the repository's guidelines.

Comment thread reference/resources/resource-api.md Outdated
@github-actions
github-actions Bot temporarily deployed to pr-619 August 4, 2026 15:34 Inactive
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

🚀 Preview Deployment

Your preview deployment is ready!

🔗 Preview URL: https://preview.harper-documentation.harperfabric.com/pr-619

This preview will update automatically when you push new commits.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@kriszyp
kriszyp requested review from Ethan-Arrowood and removed request for a team August 4, 2026 15:38
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

🚀 Preview Deployment

Your preview deployment is ready!

🔗 Preview URL: https://preview.harper-documentation.harperfabric.com/pr-619

This preview will update automatically when you push new commits.

@github-actions
github-actions Bot temporarily deployed to pr-619 August 4, 2026 15:41 Inactive
…tic, methods

Previous revision wrongly claimed the flag affected overridden static methods
and was a v5 no-op that was safe to delete. Verified against
resources/Resource.ts and resources/Table.ts: the flag is only read by
Harper's built-in static dispatch when it calls a resource's *instance*
methods, controlling arg order ((data, target) vs (target, data)), record
pre-loading, get(string) semantics, and record freezing. An overridden static
replaces that dispatch, so the flag never applies to it — which is why static
methods are the recommended shape. The behavior is still live in v5, so the
line cannot be removed unless the instance methods are converted too.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@kriszyp kriszyp changed the title docs: mark static loadAsInstance as deprecated in Resource API reference docs: document static loadAsInstance in the v5 Resource API reference Aug 4, 2026
@github-actions
github-actions Bot temporarily deployed to pr-619 August 4, 2026 16:56 Inactive
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

🚀 Preview Deployment

Your preview deployment is ready!

🔗 Preview URL: https://preview.harper-documentation.harperfabric.com/pr-619

This preview will update automatically when you push new commits.

Drop the per-behavior comparison table. The "records mutable vs frozen" row
conflated two things: records are frozen regardless of the flag; what is
mutable is the Resource instance the instance verbs are called on. Rather than
restate mode internals in the v5 reference, link to the v4 doc's API Versions
section, which already documents both modes in full. Keeps the v5 page focused
on the actionable guidance: statics don't need the flag, and the line can't be
deleted while REST-mirroring instance verbs remain.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

🚀 Preview Deployment

Your preview deployment is ready!

🔗 Preview URL: https://preview.harper-documentation.harperfabric.com/pr-619

This preview will update automatically when you push new commits.

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