-
Notifications
You must be signed in to change notification settings - Fork 48
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
Bring in Language Changes #85
Merged
Merged
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0cae903
Removing packages that were moved to the tools repo
KetanReddy 9f93829
Add xlr export rule to build pipeline
KetanReddy b8b9122
Use feature branch for bazel rules
KetanReddy e620bc6
Initial docs for XLR
KetanReddy fe95abf
Fix bad dsl package link
KetanReddy 0f848c3
add @rollup/plugin-image dependency
KetanReddy d178c38
Use release version of rules_player
KetanReddy 95997bd
upgrade to latest tools version
KetanReddy 6468cc9
Update CODEWOWNERS to use root directories instead of paths
KetanReddy 65823b4
Update tools version
KetanReddy 62722e9
Merge branch 'main' of https://github.com/player-ui/player into refac…
KetanReddy 1fffdc3
generate XLRs for common-expressions and common-types
KetanReddy b10106d
fix old import
KetanReddy 3542f1e
Fix lint error
KetanReddy 497aa80
Merge branch 'main' of https://github.com/player-ui/player into refac…
KetanReddy f31e686
fix build
KetanReddy 82d619a
Merge branch 'main' of https://github.com/player-ui/player into refac…
KetanReddy 887330f
Bump tools version to 0.3.0 release.
KetanReddy 5f74b2c
Export reference asset XLRs from the react plugin
KetanReddy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
title: XLR Concepts | ||
--- | ||
|
||
# XLR Definitions | ||
|
||
When talking about anything its helpful to make sure everyone is on the same page, XLR is no exception. In this section we'll explore some concepts related to XLRs, how they work, and how they're used. | ||
|
||
## Capability | ||
|
||
When we talk about a Capability, we are essentially talking about what it provides to Player. Most, if not all, capabilities are provided by Plugins. Capabilities are described in the manifest file in the `xlr` folder of a distribution. The manifest file, provided as both a `.json` and a `.js` file for static or dynamic use, contains the mapping of capabilities to a list of the XLRs. | ||
|
||
## XLR Objects | ||
|
||
XLRs contain all of the information about a TypeScript type or interface. For an interface it will have the information on what parameters it has, the types of those parameters, and if those parameters are optional. For a type, it will similarly describe the properties/types that compose it. There is no distinction in XLR on whether the XLR came from a type or an interface as everything is just represented by a Node. | ||
|
||
### XLR Nodes | ||
XLR nodes are similar to TypeScripts internal AST nodes but a bit simpler. Almost every type/language feature you would use in TypeScript has an equivalent XLR node type. The definitions for these types are available in the `@player-tools/xlr` [package](https://github.com/player-ui/tools/tree/main/xlr/types). | ||
|
||
### Named Types | ||
|
||
Named Types represent a top level interface/type and can be _any_ XLR Node. Named types are generated from interfaces/types that are exported from a source file or plugin. It should be noted that when generating a Named Type, all referenced types are also serialized and included in place in the Named Type and *not* exported separately. That is unless The type is listed as a _Custom Primitive_. A reason to do this would be if that type definition changes based on use case or platform. For example, in the Player ecosystem `Asset` is considered a Custom Primitive because depending on the context, we might need to swap it out with a different type. | ||
|
||
# XLR SDK | ||
|
||
The XLR SDK is used to abstract away the more tedious interactions XLRs like loading them from their package, managing them when they're loaded, and validating content against them. The SDK does include an simple object store so that it can be used out of the box, however if your use case requires some different logic it can be extended quite easily. In fact, [we do that in the Player LSP](https://github.com/player-ui/tools/blob/main/language/service/src/xlr/registry.ts). | ||
|
||
## Transform Functions | ||
|
||
Transform functions can be used to modify XLRs when they're loaded and when they're exported. There is no real limit to what you can do in a transform function but typical use cases are things like adding new properties to object and substituting type references with different ones. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
title: Into to XLR | ||
--- | ||
|
||
# What is XLR | ||
|
||
XLR, short for cross(x) language representation, is a way to export a static and language agnostic description of a TypeScript type or interface packaged along with the original type or interface. XLR started as a fork of [core-types](https://github.com/grantila/core-types) to add support for some missing features (generics, supported types, inheritance) that are heavily used in Player but has evolved into a superset of its features with some opinionated functionality to support Player specific conventions. XLR now powers a majority of the Player language features such as content validation, editor suggestions, and in editor documentation. | ||
|
||
# Why Do We Need it | ||
|
||
XLR was developed to fill in one of the major gaps in the Player ecosystem: Because everything is dynamic, there is no way to statically/programmatically know what plugin provides what capabilities (assets, data types, validations, etc) to Player and what that capability looks like. This becomes a real issue in the tooling around Player when things like content authoring and validation. In both use-cases information on what assets are available for use, what parameters do those assets require, what types are those parameters, etc. is required but cannot be assumed. Historically we have seen this gap bridged by hardcoding the set of capabilities that are available but that has proven to be a never ending cycle of keeping those definitions updated when things change and knowing about the *entire* set of capabilities, even those that people develop silently. With XLR, a static description of all capabilities provided by a plugin can be compiled at build time, included in the package, and used at any point in the future for a multitude of capabilities. | ||
|
||
|
||
# How Do I Leverage XLR | ||
|
||
How much you use XLR is pretty dependant on your niche in the Player ecosystem. | ||
|
||
## As a TypeScript Plugin/Capability Author | ||
|
||
If you are developing Player capabilities for Core/React, all you need to do is have your Plugin fill in the `ExtendedPlayerPlugin` interface and run the Player CLI during build time and the CLI will take care of compiling and bundling the capabilities. You can see an example of this in the [Exporting Plugin Capabilities](./usage#exporting-plugin-capabilities) section. | ||
|
||
## As Someone Building Capabilities Around Player | ||
|
||
If you want to leverage XLRs to develop capabilities around Player, you'll want to start with the [SDK](./concepts#xlr-sdk) and use it to load the XLRs from published packages. Then, using the SDK, you can access all the loaded types and information about them for use in your application. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
--- | ||
title: Using XLR | ||
--- | ||
|
||
# Part 1 - Creating XLRs | ||
|
||
XLR creation is done through the Player CLI which can be added to your project like so: | ||
|
||
```bash | ||
yarn install @player-tools/cli | ||
``` | ||
|
||
## Exporting Base Type Definitions | ||
|
||
If you want to compile all exported interfaces/types to XLRs run the following command as part of your build | ||
|
||
```bash | ||
player xlr compile -m types <other options> | ||
``` | ||
|
||
## Exporting Plugin Capabilities | ||
|
||
If you are writing a Player Plugin, you'll first need to have your plugin extend the `ExtendedPlayerPlugin` interface and fill in the generics with an array of the interfaces/types for each Capability. For example, you can see how its done below in the [core reference assets plugin](https://github.com/player-ui/player/blob/main/plugins/reference-assets/core/src/plugin.ts) | ||
|
||
```typescript | ||
export class ReferenceAssetsPlugin | ||
implements | ||
PlayerPlugin, | ||
ExtendedPlayerPlugin< | ||
[InputAsset, TextAsset, ActionAsset, InfoAsset, CollectionAsset] | ||
> | ||
``` | ||
|
||
Then run the following command as part of your build | ||
|
||
```shell | ||
player xlr compile -m plugin <other options> | ||
``` | ||
|
||
# Part 2 - Using XLRs | ||
|
||
## SDK: Initialization | ||
|
||
To start using the XLR SDK you'll need to install the SDK package | ||
|
||
```bash | ||
yarn install @player-tools/xlr-sdk | ||
``` | ||
|
||
Next, import the SDK | ||
|
||
```typescript | ||
import { XLRSDK } from "@player-tools/xlr-sdk" | ||
``` | ||
|
||
_If you want to implement a custom object store, also import the `XLRRegistry` interface and have your custom registry implement it._ | ||
|
||
Lastly, just initialize an instance of it. | ||
|
||
```typescript | ||
import { XLRSDK } from "@player-tools/xlr-sdk" | ||
|
||
const sdk = new XLRSDK(); | ||
``` | ||
|
||
or if you want to use your custom registry, just pass it in to the initializer. | ||
|
||
```typescript | ||
import { XLRSDK } from "@player-tools/xlr-sdk" | ||
import { customRegistry } from "./customRegistry" | ||
|
||
const sdk = new XLRSDK(customRegistry); | ||
``` | ||
|
||
## SDK: Loading Types | ||
|
||
If you want to load XLR types from disk, you can use the `loadDefinitionsFromDisk` function and pass it the path to parent folder of the `xlr` directory. | ||
|
||
```typescript | ||
const sdk = new XLRSDK(); | ||
sdk.loadDefinitionsFromDisk('./common/static_xlrs/core'); | ||
``` | ||
|
||
If you want to load XLR types from a module, you can use the `loadDefinitionsFromModule` function and pass it the module to load from. | ||
|
||
```typescript | ||
const sdk = new XLRSDK(); | ||
sdk.loadDefinitionsFromModule(require("@player-ui/reference-assets-plugin").path); | ||
``` | ||
|
||
- If you want to filter any of the types that are being loaded, you can supply a `Filters` object as the *second* arguments | ||
- If you want to apply any transform functions to the modules that you load, you can supply a list of `TransformFunction` as the *third* argument | ||
|
||
## SDK: Usage | ||
|
||
After the types are loaded into the SDK there are a couple ways to interact with them. | ||
|
||
### Type Recall | ||
|
||
To get a type back you can use the `getType` function and pass the name of the type you want to retrieve. You can also use the `hasType` function to check to see if the type exists before you try and access it. | ||
|
||
```typescript | ||
const sdk = new XLRSDK(); | ||
if(sdk.hasType("InputAsset")){ | ||
return sdk.getType("InputAsset") | ||
} else { | ||
throw new Error("Oh no!") | ||
} | ||
``` | ||
|
||
### Type Validation | ||
|
||
To validate if some JSON content matches the expected type, you can use the `validateType` function. You will need to supply a `Node` from the `jsonc-parser` library. | ||
|
||
```typescript | ||
import { parseTree } from 'jsonc-parser'; | ||
import { XLRSDK } from '@player-tools/xlr-sdk' | ||
|
||
const sdk = new XLRSDK(); | ||
|
||
///... Loading XLRs | ||
|
||
const mockAsset = parseTree(` | ||
{ | ||
"id": 1, | ||
"type": "input", | ||
"binding": "some.data", | ||
"label": { | ||
"asset": { | ||
"value": "{{input.label}}" | ||
} | ||
} | ||
`); | ||
|
||
return sdk.validate('InputAsset', mockAsset) | ||
``` |
Oops, something went wrong.
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.
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.
Tangential to the main purpose of the PR but I noticed in #95 I was tagged as a code owner because there were changes in the
core
directory under the jvm folder. These paths should be from the root, not relative.