feat(typespec): Adding typespec library - #427
Merged
Merged
Conversation
This pull request introduces the initial setup for the new `@alloy-js/typespec` package, including its configuration, dependencies, and build/test scripts. The changes ensure the package is ready for development, testing, and documentation generation, and integrate it into the project’s monorepo structure. **New package setup and configuration:** * Added `packages/typespec/package.json` to define the package name, exports/imports, scripts, dependencies, and devDependencies for `@alloy-js/typespec`. * Added `packages/typespec/tsconfig.json` to configure TypeScript compilation settings, declaration output, project references, and file inclusions/exclusions. * Added `packages/typespec/api-extractor.json` to configure API Extractor for documentation generation. * Added `packages/typespec/vitest.config.ts` to set up Vitest testing configuration and integrate the Alloy rollup plugin. **Monorepo integration:** * Updated `pnpm-lock.yaml` to register `@alloy-js/typespec` and its dependencies in the workspace, ensuring proper package management and linking.
This PR adds a dev container definition (with added dependabot configuration for the devcontainer ecosystem), and it also merges main into the feature branch. --------- Co-authored-by: Rodge Fu <fwj_ac@msn.com> Co-authored-by: Brian Terlson <brian.terlson@microsoft.com> Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Auto Chronus Bot <chronus@github.com> Co-authored-by: Maurício Gardini <mauriciogardini@users.noreply.github.com> Co-authored-by: Steve Rice <srice@pinterest.com> Co-authored-by: Jimmy Ding <jimmyguding@gmail.com> Co-authored-by: Steve Rice <steve@steverice.org> Co-authored-by: Chenjie Shi <tadelesh.shi@live.cn> Co-authored-by: tadelesh <chenjieshi@microsoft.com> Co-authored-by: Frank Shaw <frshaw1@gmail.com> Co-authored-by: Derek Perez <derek@perez.earth>
…352) This pull request introduces the initial implementation of the TypeSpec built-in library for Alloy, providing core TypeSpec types, decorators, and supporting infrastructure for symbol creation, scoping, and global namespace management. The changes establish a system for describing TypeSpec libraries and their members, enable dynamic symbol creation, and add comprehensive tests for library creation and symbol resolution. The most important changes are: **TypeSpec Built-in Library Implementation** * Added the `TypeSpec` built-in library, including core TypeSpec data types and decorators, with descriptors for models, enums, scalars, and decorators in `data-types.ts` and `decorators.ts`. The library is exported via `index.ts` for consumption. [[1]](diffhunk://#diff-97feba7bb89f8ac6b5f9c4947c88663cbe01da9df8363fedb5fc00fc0830e47bR1-R136) [[2]](diffhunk://#diff-56e5ddc34aee11d7a24b5b2e496e385aa4995b7fd5511714887cfc8c0e2b993cR1-R173) [[3]](diffhunk://#diff-1011d00cbc481e924a414262cb9f7b0de0928aea90c703ff85e3928bb43b3eecR1-R15) [[4]](diffhunk://#diff-1ee37f63c4ce289d94e005f25784ec6e3a728758767d0cd34b59474d4fd4b20aR1) **Library Creation and Symbol Management** * Implemented the `createLibrary` function and supporting types in `create-library.ts` to allow dynamic creation of TypeSpec libraries and their symbols, with support for nested namespaces, lazy member initialization, and reference resolution. **Global Namespace and Context Management** * Added global namespace management utilities in `contexts/global-namespace.ts`, including functions to get, use, and reset the global namespace, and exported these via `contexts/index.ts`. [[1]](diffhunk://#diff-f9bcb0976673e96b76ce0bd5bf6ac3c78387b3e0c74a8b00ba67e43f197b7436R1-R36) [[2]](diffhunk://#diff-e71837cafbe6774fba835c15b1efa465ab63b0e3b4cf3f248e8b539a36042369R1) **Scoping Infrastructure** * Introduced scope classes for organizing symbols and output: `DirectoryScope`, `NamespaceScope`, `NamedTypeScope`, and `SourceFileScope`, supporting hierarchical organization and tracking of used namespaces. [[1]](diffhunk://#diff-6fb3f0a95a7eed68b14ae0fa4ab7fbd7b415eaa81af14a077bf7712314e1b3daR1-R13) [[2]](diffhunk://#diff-4066cbacf6b0bb138009eac5bf6e346a8ac16085aa931d3c0f51052e92f5fd66R1-R15) [[3]](diffhunk://#diff-f94305226136fee74ad050d97f70ea2dcd3eae04c7bf18f02a14bf1b2026c7ddR1-R18) [[4]](diffhunk://#diff-49691d916239ba89993a5b456692293c8d14d879c5b296d8b47ec552fe9fd4bbR1-R33) [[5]](diffhunk://#diff-1a7774470eea330af702163815f518e6e5f77711161130fea337bc1dd79610f2R1-R4) **Testing and Exports** * Added comprehensive tests for library creation, symbol resolution, nested namespaces, and reference handling in `create-library.test.ts`. Updated exports to expose new modules and symbols. [[1]](diffhunk://#diff-4c922989ef97f53a602c7d17891e88ef1727c87dab72ebed2a7a0dd2c263d2d3R1-R103) [[2]](diffhunk://#diff-e36adb89d5bcbe2fa3812b3d77417e39c514c32200352d815896036e41ba0b8eR1-R3) [[3]](diffhunk://#diff-7e39c32a5a5f10160055115b72a7f33d5a3636e8639b00d0bd649a11b92c5350R1-R3) These changes lay the foundation for Alloy's TypeSpec support, enabling extensible type libraries, symbol referencing, and organized output generation.
…s. (#371) This pull request introduces a suite of new TypeSpec component implementations and comprehensive tests for namespace, operation, name, and reference handling. It also improves developer tooling and workflow with formatting and devcontainer enhancements. The most important changes are grouped below: ### New Component Implementations * Added core TypeSpec components for namespace, operation declarations, source files, and template parameters in `src/components/`. These enable structured rendering and context propagation for TypeSpec constructs. [[1]](diffhunk://#diff-6939d367ce1ef200d22a7145f536f215347832c5f5f001aa007227515ebc517eR1-R4) [[2]](diffhunk://#diff-cebfa5d8493e99533fdc6142dd6440e9e8a64c45855dc062b4b5c409d18784f2R1-R29) [[3]](diffhunk://#diff-e008af06b8a63300e5d0a3f12fc50547fb030bab77aa63ebe62ac2c83f062adfR1-R21) [[4]](diffhunk://#diff-5f7fc22f7ffa16b8ff619a6054b2a64904d1245a3e100e4e44a9f747274ffe2fR1-R50) [[5]](diffhunk://#diff-6b3e933d445860d7ccb99855f262d66b2470fe677c3c289f0634d8b07148d308R1-R90) * Implemented a `Name` component for rendering declaration names with context validation. * Implemented a `Reference` component for resolving and rendering type references, including proper symbol emission and fallback for unresolved references. ### Comprehensive Test Coverage * Added extensive test suites for `Namespace`, `OperationDeclaration`, `Name`, and `Reference` components to verify correct rendering, context handling, error cases, and reference resolution across files and directories. [[1]](diffhunk://#diff-da55632d514074a90edc519d32a08118493109b046a34e6863998c6b5d056933R1-R39) [[2]](diffhunk://#diff-3ce29f3acfca19883cf39527d0fbd3390c36eb50732127e3b862c54046912671R1-R268) [[3]](diffhunk://#diff-d5ed82ffa6ac0b37a3b24fe7900b73fc75b37f17085f396e13599db8323a2f8eR1-R73) [[4]](diffhunk://#diff-45a8ea4ff3c074098463d93eb892d2ace062697edf302f60460950d5c8ea3c9bR1-R121) ### Developer Tooling & Workflow * Added a `format` script using Prettier to `package.json` for consistent code formatting. * Enhanced devcontainer configuration to include the Copilot CLI feature for improved developer experience. --------- Co-authored-by: Jose Alvarez <jpalvarezl@users.noreply.github.com>
This pull request introduces new components and comprehensive tests for handling TypeSpec enum, model, and union declarations and expressions in the codebase. The changes add JSX-based components for TypeSpec constructs, along with tests to verify their rendering and name resolution, and update the component exports for broader usage. **New TypeSpec Components:** * Added `EnumDeclaration` and `EnumMember` components to represent and render TypeSpec enums, including symbol creation, scoping, and name policy support. [[1]](diffhunk://#diff-671f6ff75026a5fd9b089ce049f9d68ecf9f60d1b1f691d72b1dde045b26f775R1-R38) [[2]](diffhunk://#diff-fcc22ee46c2d9d3422f989a4cd03d94d865b75b6d4272d32c58b438b412b92c9R1-R21) * Introduced `ModelDeclaration`, `ModelExpression`, and `ModelProperty` components for TypeSpec models, supporting template parameters, inheritance, and error handling for invalid combinations. [[1]](diffhunk://#diff-338644523af808384bfff3fcc10214c3b9a1e71ef455cb09d3c02d7c311dcc25R1-R61) [[2]](diffhunk://#diff-d707faeca50b0421ee462cea426b62e63bf5526bcd83b3d57210421d97f42f8dR1-R9) [[3]](diffhunk://#diff-aa3a7e64edf4f266caac45ce7d0562b82c842e5060ffadfc1d592b8a6cf3612dR1-R22) * Added `UnionDeclaration`, `UnionVariant`, and `UnionExpression` components to represent TypeSpec unions, supporting template parameters, named/anonymous variants, and union type expressions. [[1]](diffhunk://#diff-c478fb10d00beb785cbee9f401c3ba2a21ea94bbde14096f044f2dbd8d05d235R1-R47) [[2]](diffhunk://#diff-3e796b4e66c7137319c576b524609eebb5af513504739d0710496d501d318d17R1-R24) [[3]](diffhunk://#diff-6e6b0772938b38d113db5083cbc17d044564086fde1639903c8e1398ea0a9306R1-R9) **Component Exports:** * Updated `index.ts` to export the new enum, model, and union components for use elsewhere in the codebase. **Comprehensive Testing:** * Added test suites for enums (`enum-declaration.test.tsx`), unions (`union-declaration.test.tsx`, `union-expression.test.tsx`), covering rendering, name policy, namespace handling, template parameters, references, and deconfliction logic. [[1]](diffhunk://#diff-a5d65beef82afcaec495350dd0b6c5c4e7fc34a587f09e602943d408d27f4fe3R1-R206) [[2]](diffhunk://#diff-ed1a37f232dd6eb05af014dcb58fb61356d62f43bf267f906352053fa5f4bc37R1-R259) [[3]](diffhunk://#diff-60d15406575964ca0a81f8aa4b69f8bbf23c7321e827e665aa148eedbd07a065R1-R76)
Co-authored-by: Rodge Fu <fwj_ac@msn.com> Co-authored-by: Brian Terlson <brian.terlson@microsoft.com> Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Auto Chronus Bot <chronus@github.com> Co-authored-by: Maurício Gardini <mauriciogardini@users.noreply.github.com> Co-authored-by: Steve Rice <srice@pinterest.com> Co-authored-by: Jimmy Ding <jimmyguding@gmail.com> Co-authored-by: Steve Rice <steve@steverice.org> Co-authored-by: Chenjie Shi <tadelesh.shi@live.cn> Co-authored-by: tadelesh <chenjieshi@microsoft.com> Co-authored-by: Frank Shaw <frshaw1@gmail.com> Co-authored-by: Derek Perez <derek@perez.earth> Co-authored-by: Rodge Fu <wenjiefu@microsoft.com> Co-authored-by: Timothee Guerin <tiguerin@microsoft.com> Co-authored-by: Paul Bakker <p-bakker@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add InterfaceDeclaration and InterfaceOperationDeclaration components to the TypeSpec package with support for: - Template parameters (simple and constrained) - Interface extends clauses - Operation parameters, return types, and 'is' syntax - Name policy and deconfliction - Refkey-based cross-declaration references Extract shared Parameters component from operation-declaration to avoid duplication between OperationDeclaration and InterfaceOperationDeclaration. Clean up test files: remove unused imports and fix nested afterEach anti-pattern. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
#408) …nents - Add DecoratorApplication component for @decorator(args) syntax - Add AugmentDecorator component for @@decorator(target, args) syntax - Add decorators prop to all decoratable types: ModelDeclaration, ModelProperty, EnumDeclaration, EnumMember, UnionDeclaration, UnionVariant, OperationDeclaration, ScalarDeclaration - Add tests for decorator rendering on each declaration type --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add AliasDeclaration component for rendering TypeSpec alias declarations: alias Name<T> = Type Features: - Template parameters with constraints and defaults - Name policy support (quotes reserved words) - Symbol deconfliction within namespaces - Cross-namespace reference resolution with automatic using generation --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add ConstDeclaration, ObjectValue, ObjectValueProperty, and ArrayValue
components for TypeSpec const declarations and value expressions.
- ConstDeclaration: renders const with optional type annotation
- ObjectValue/ObjectValueProperty: renders #{ key: value } syntax
- ArrayValue: renders #[item1, item2] syntax
- Added 'const' to NamedTypeKind and name policy
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
Add standalone components for explicit import and using statements in TypeSpec source files. - ImportStatement: registers an import path with the SourceFileScope - UsingStatement: registers a using namespace with the SourceFileScope - Both integrate with existing auto-generated imports/usings for deduplication - Updated SourceFileScope to store usings as strings instead of NamespaceSymbol objects, supporting both explicit string names and NamespaceSymbol references via addUsing() --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolved all conflicts taking main's version for everything outside packages/typespec. Removed stale .chronus/changes entries that no longer exist in main. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ns (#411) Add DocComment, DocParam, DocReturns, DocTemplate, and DocWhen components for rendering TypeSpec documentation comments (`/** ... */`). Add a `doc?: Children` prop to all 10 declaration components (ModelDeclaration, ModelProperty, EnumDeclaration, EnumMember, UnionDeclaration, UnionVariant, InterfaceDeclaration, OperationDeclaration, ScalarDeclaration, AliasDeclaration), rendered via `<DocWhen>` following the same pattern used in the C# package. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…417) - StringLiteral renders single-line (`"..."`) or multi-line (`"""..."""'`) string literals via the multiline prop - StringTemplateExpr wraps children in ${} for interpolation - Multi-line strings use raw <indent> intrinsic to keep closing triple quotes at the same indentation level as content - Export both components from package entry point --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
#416) …clarations - Add TypeOfExpression component for typeof expressions - Add SuppressDirective and DeprecatedDirective components - Add directives prop to all declaration components (model, enum, union, interface, operation, scalar, alias, const, and their members) - Render order: doc → directives → decorators → keyword - Export new components and add missing exports (components, contexts, name-policy) to package entry point - Inline ValueOrArray/Optional to fix API Extractor forgotten-export errors Note: Namespace doc/decorators/directives support deferred to follow-up PR. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ace (#422) Add doc, directives, and decorators props to the Namespace component, matching the pattern used by ModelDeclaration and OperationDeclaration. - Added DocWhen rendering for doc comments - Added directives and decorators pass-through rendering - Added JSDoc for all NamespaceProps fields - Added tests for doc, decorators, directives, and nested namespace cases Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…#410) New components: - ArrayExpression: renders Type[] array syntax - IntersectionExpression: renders A & B intersection syntax - SpreadExpression: renders ...Type spread syntax for models and enums Enhanced: - ModelProperty: add optional 'default' prop for default values --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add TemplateArguments component for named template arguments at usage sites (e.g. `Pair<int32, B = boolean>`). Supports positional, named, and mixed argument styles. Add STC (structured type components) directory with programmatic API wrappers for all public components via core.stc(). Also export Reference, ScalarDeclaration, and Parameters from the components index (previously missing). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
#415) …ing components - Add ScalarInitializer component with doc/decorators support - Update ScalarDeclaration to accept children for body content - Replace incomplete keyword list with full TypeSpec keywords from compiler - Fix name policy to properly detect invalid identifiers (not just 5 words) - Export Reference, Parameters, and ScalarDeclaration from components index - Export components, contexts, and name-policy from package index --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add SpreadParameterDescriptor and ParameterEntry types to support spread parameters in operation declarations (e.g. `op foo(...CommonParams, name: string)`). Also update GAPS.md to reflect current state: remove completed items from missing/partial lists, add newly implemented features. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
#425) …t resolution - Add repeatable audit script to verify builtins match TypeSpec stdlib - Add all builtin namespaces: TypeSpec, Http, OpenAPI, Rest, Versioning, Reflection - Add packageImport/implicitlyUsed to TypeSpecSymbol for automatic import/using generation when referencing library builtins - Implement three-mode resolution: implicitlyUsed, packageImport, using-only - Add namespace-shifting in ref() for correct member path rendering (e.g. Lifecycle.Read, DiscriminatedOptions.envelope) - Add typeArgs prop to Reference component for template types - Handle inline descriptors gracefully in createLibrary (anonymous types) - Fix copy() to preserve library metadata - Add OpenAPI3 separate library entry for split-namespace support --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
#426) …e references - Add DecoratorDeclaration component for extern dec syntax with symbol creation, refkey support, doc comments, directives, and parameter descriptors - Fix 'using global;' bug: skip isGlobal namespaces in ref() when adding using statements and in findContainingNamespace() - Fix cross-file import generation for symbols without explicit namespaces by registering the global namespace symbol in SourceFileScope's members space, giving it a proper scope chain for resolution Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
All changed packages have been documented.
Show changes
|
Align with other packages (typescript, csharp) by excluding dist/ from test discovery and adding resolve conditions for source imports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
- Add TypeSpec.Events library (@typespec/events): events, contentType, data decorators - Add TypeSpec.SSE library (@typespec/sse): terminalEvent decorator, SSEStream model - Add tests for both libraries Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
#435) …on parameters Add doc, directives, and decorators fields to ParameterDescriptor, matching the existing pattern used by ModelProperty. Update the Parameters component to render them before each parameter name. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…436) Update exports to use dist/dev/ paths for development condition and add source condition, matching the pattern used by other language packages (typescript, csharp, etc.). Switch build to use --with-dev so the dev build with source info is produced in dist/dev/. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
#437) …erences When two files share the same namespace, a reference from one to the other should emit an import but not a using statement, since the namespace members are already in scope. Add isOriginInNamespace check to suppress the redundant using. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
#438) …confliction ModelExpression was not creating its own scope, so ModelProperty symbols from sibling expressions shared the parent NamedTypeScope and were incorrectly deconflicted (e.g. statusCode_2, body_2). Create an anonymous NamedTypeScope in ModelExpression so each expression isolates its own property symbols. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.