Documentation
¶
Overview ¶
Package javascript provides a documentation source adapter that reads JavaScript source code from a local directory (downloaded from GitHub). It parses raw JS source via tree-sitter to extract classes, functions, module exports, and JSDoc without making any network calls during parsing.
The adapter is configurable for any JavaScript library (Node.js, React, Express, Lodash, etc.) via LibraryConfig.
Index ¶
- func NewAxiosFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewD3Factory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewExpressFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewFastifyFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewHapiFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewKoaFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewLodashFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewMeteorFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewMochaFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewMoleculerFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewNodeJSFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewReactFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewRemixFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewRestifyFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewSailsFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewSvelteKitFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewWSFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- func NewWebpackFactory(repoPath string, opts registry.FactoryOptions) (source.Source, error)
- type LibraryConfig
- type Option
- type Source
- func (s *Source) DetectWrapper(method *source.Method) (bool, string, string)
- func (s *Source) DiscoverEntities(ctx context.Context, fetch source.FetchFunc) ([]string, error)
- func (s *Source) ID() string
- func (s *Source) Meta() source.LibraryMeta
- func (s *Source) ParseEntity(ctx context.Context, entityID string, content []byte) (*source.Entity, []string, error)
- func (s *Source) ParseMethod(ctx context.Context, methodID string, content []byte) (*source.Method, error)
- func (s *Source) ParseSourceCode(entityID string, content []byte) (string, error)
- func (s *Source) ResolveWrapperURL(targetName, targetKind, entitySlug string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAxiosFactory ¶
NewAxiosFactory creates a Source for the Axios HTTP client.
func NewD3Factory ¶
NewD3Factory creates a Source for the D3.js visualization library. The d3/d3 umbrella repo only re-exports submodules, so this indexes the d3-selection core module, which carries the canonical DOM-selection API.
func NewExpressFactory ¶
NewExpressFactory creates a Source for the Express.js web framework.
func NewFastifyFactory ¶
NewFastifyFactory creates a Source for the Fastify web framework.
func NewHapiFactory ¶
NewHapiFactory creates a Source for the Hapi web framework.
func NewKoaFactory ¶
NewKoaFactory creates a Source for the Koa web framework.
func NewLodashFactory ¶
NewLodashFactory creates a Source for the Lodash utility library.
func NewMeteorFactory ¶
NewMeteorFactory creates a Source for the Meteor framework.
func NewMochaFactory ¶
NewMochaFactory creates a Source for the Mocha testing framework.
func NewMoleculerFactory ¶
NewMoleculerFactory creates a Source for the Moleculer microservices framework.
func NewNodeJSFactory ¶
NewNodeJSFactory creates a Source for the Node.js standard library.
func NewReactFactory ¶
NewReactFactory creates a Source for the React UI library.
func NewRemixFactory ¶
NewRemixFactory creates a Source for the Remix framework.
func NewRestifyFactory ¶
NewRestifyFactory creates a Source for the Restify framework.
func NewSailsFactory ¶
NewSailsFactory creates a Source for the Sails.js MVC framework.
func NewSvelteKitFactory ¶
NewSvelteKitFactory creates a Source for the SvelteKit framework.
func NewWSFactory ¶
NewWSFactory creates a Source for the ws WebSocket library. Replaces Polka, whose single-file source carries no JSDoc to index.
func NewWebpackFactory ¶
NewWebpackFactory creates a Source for the Webpack module bundler.
Types ¶
type LibraryConfig ¶
type LibraryConfig struct {
// ID is the canonical library ID (e.g., "/javascript/express").
ID string
// Name is the human-readable library name (e.g., "Express.js").
Name string
// Description is a short summary of what the library provides.
Description string
// SourceURL is the GitHub repository URL.
SourceURL string
// Version is the library version being indexed.
Version string
// SourceDirs are relative paths within the repo to scan for JS source.
// If empty, the root directory is scanned.
SourceDirs []string
// BlobRef is the git ref for source-code links (e.g., "v4.18.2").
// Defaults to "main" if empty.
BlobRef string
}
LibraryConfig describes a JavaScript library to index.
type Option ¶
type Option func(*Source)
Option customises a Source at construction time.
func WithConfig ¶
func WithConfig(cfg LibraryConfig) Option
WithConfig sets the library configuration.
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
Source is a documentation source adapter that reads JavaScript source code from a local directory. It implements the source.Source interface.
func New ¶
New constructs a new JavaScript Source pointing at a local directory. The index is initialised to an empty (non-nil) state so that DetectWrapper and ResolveWrapperURL are safe to call before DiscoverEntities.
func (*Source) DetectWrapper ¶
DetectWrapper analyzes a method's source code for wrapper patterns.
func (*Source) DiscoverEntities ¶
DiscoverEntities walks the local repository and returns a sorted list of entity identifiers. The fetch parameter is unused — all discovery reads files locally.
func (*Source) Meta ¶
func (s *Source) Meta() source.LibraryMeta
Meta returns metadata for the library record.
func (*Source) ParseEntity ¶
func (s *Source) ParseEntity(ctx context.Context, entityID string, content []byte) (*source.Entity, []string, error)
ParseEntity parses a single entity from file content, identified by entityID. Returns the entity data plus a list of method identifiers to crawl next.
func (*Source) ParseMethod ¶
func (s *Source) ParseMethod(ctx context.Context, methodID string, content []byte) (*source.Method, error)
ParseMethod parses a single method from file content.
func (*Source) ParseSourceCode ¶
ParseSourceCode extracts just the source code of a specific entity or method from file content.
func (*Source) ResolveWrapperURL ¶
ResolveWrapperURL constructs the identifier to fetch the wrapped target's source. Returns an empty string if the target cannot be resolved.