Skip to content

Add a library for parsing Drupal-managed menus #6

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

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0da423c
Initial commit.
gabesullice Mar 2, 2021
3cb99cd
Reformat example JSON.
gabesullice Mar 2, 2021
ef8b427
Add (de)normalizer functions.
gabesullice Mar 2, 2021
218bd40
Better type definition.
gabesullice Mar 2, 2021
21f87bb
Add tests.
gabesullice Mar 3, 2021
a3992c3
Implement a hasLinkWithRel method.
gabesullice Mar 3, 2021
4c49f16
Run prettier.
gabesullice Mar 3, 2021
8adf238
Further define target attribute types.
gabesullice Mar 3, 2021
69f436c
Add registered target attribute denormalization test.
gabesullice Mar 3, 2021
2f251ce
Properly configure eslint.
gabesullice Mar 3, 2021
f786329
Fix eslints
gabesullice Mar 3, 2021
3885dd1
Rename hasLinkWithRel to linksTo
gabesullice Mar 3, 2021
e82c03a
Start working on a more usefule public interface for a linkset object
gabesullice Mar 3, 2021
7c99643
Clean up.
gabesullice Mar 3, 2021
21b288b
Add a method to get the first instance of a link with a given link re…
gabesullice Mar 3, 2021
6746bbd
Reorder methods and rename hasLinksTo to hasLinkTo (singular)
gabesullice Mar 3, 2021
3727ac0
Add test for internationalized target attributes.
gabesullice Mar 4, 2021
9e5707d
Consolidate example data into an examples object.
gabesullice Mar 4, 2021
7e794b0
Reorder tests.
gabesullice Mar 4, 2021
2c19cd1
Begin refactoring into smaller files.
gabesullice Mar 4, 2021
852066e
Reorganize file structure to encapsulate internal code.
gabesullice Mar 4, 2021
3026362
Add TSDoc comments.
gabesullice Mar 4, 2021
3538f97
Move the linkset normalization types out of the internal dir.
gabesullice Mar 4, 2021
3d91f76
Rename all instances of "LinkSet" to "Linkset".
gabesullice Mar 4, 2021
f66156a
Rename internal directory to "core"
gabesullice Mar 4, 2021
1f1f298
Fix example.
gabesullice Mar 4, 2021
e02ec2c
Re-run yarn install.
gabesullice Mar 4, 2021
f4fe1d6
Change iteration implementation to elimate a private property and mak…
gabesullice Mar 4, 2021
7d5773f
Add a parse() function to composes denormalize() with JSON.parse().
gabesullice Mar 4, 2021
3cc48c6
Remove unnecessary example file.
gabesullice Mar 10, 2021
f6b293d
Clean up type imports and fix rollup warning about using accessors.
gabesullice Mar 11, 2021
c916948
Output an ES module, not a CommonJS module, per the policy doc.
gabesullice Mar 11, 2021
0c2f0d2
Revert "Output an ES module, not a CommonJS module, per the policy doc."
gabesullice Mar 11, 2021
a3d819e
Add the ability to filter a linkset by an arbitrary attribute value.
gabesullice Mar 11, 2021
ef109e7
Add a menu abstraction over linksets.
gabesullice Mar 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
- uses: actions/setup-node@v1
- run: yarn
- run: yarn ci
- run: jq -s '[.[][]]' reports/eslint/*.json > reports/eslint/eslint-combined.json
- run: jq -s '[.[][]]' reports/eslint/*.json > reports/eslint/eslint-combined-menu.json
if: ${{ failure() }}
- name: Annotate Code Linting Results
uses: ataylorme/[email protected]
if: ${{ failure() }}
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
report-json: reports/eslint/eslint-combined.json
report-json: reports/eslint/eslint-combined-menu.json
- name: Upload test artifacts
if: ${{ failure() }}
uses: actions/upload-artifact@v2
Expand Down
7,690 changes: 5,451 additions & 2,239 deletions .pnp.js

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions linkset/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index.js
2 changes: 2 additions & 0 deletions linkset/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src
rollup.config.js
4 changes: 4 additions & 0 deletions linkset/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
41 changes: 41 additions & 0 deletions linkset/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@jsdrupal/linkset",
"version": "0.0.0",
"main": "index.js",
"repository": "git://github.com/jsdrupal/js-client.git",
"scripts": {
"build": "rimraf dist && rollup -c && mv dist/index.js index.js && rimraf dist",
"eslint": "eslint . --ext .ts --max-warnings=0 --ignore-path=.gitignore",
"eslintci": "eslint -o ../reports/eslint/linkset.json -f json",
"test": "jest"
},
"devDependencies": {
"@rollup/plugin-typescript": "^8.2.0",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.31",
"@types/node-fetch": "^2.5.8",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"eslint": "^7.21.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"rollup": "^2.40.0",
"ts-jest": "^26.5.2",
"tslib": "^2.1.0",
"typescript": "^4.1.2"
},
"eslintConfig": {
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
]
}
}
12 changes: 12 additions & 0 deletions linkset/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// rollup.config.js
import typescript from '@rollup/plugin-typescript';

export default {
input: 'src/index.ts',
output: {
exports: 'named',
dir: 'dist',
format: 'cjs',
},
plugins: [typescript()],
};
113 changes: 113 additions & 0 deletions linkset/src/core/link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* A value object that represents a single, internationalized target attribute.
* @see {@link https://tools.ietf.org/html/draft-ietf-httpapi-linkset-00#section-4.2.4.2|draft-ietf-httpapi-linkset-00: Linkset §4.2.4.2}
*/
export type InternationalizedValue = {
value: string;
language?: string;
}

/**
* An object that represent a single target attribute value.
* @see {@link https://tools.ietf.org/html/draft-ietf-httpapi-linkset-00#section-4.2.4|draft-ietf-httpapi-linkset-00: Linkset §4.2.4}
*/
export type TargetAttributeValue = string | InternationalizedValue;

/**
* An object that represents a subset of a link's target attributes.
* The subset's contents are the target attributes defined by Web Linking.
* @see {@link https://tools.ietf.org/html/draft-ietf-httpapi-linkset-00#section-4.2.4.1|draft-ietf-httpapi-linkset-00: Linkset §4.2.4.1}
*/
interface RegisteredTargetAttributes {
readonly hreflang?: string[];
readonly media?: string;
readonly type?: string;
readonly title?: string;
readonly 'title*'?: InternationalizedValue[];
};

/**
* An object that represents a link's target attributes.
* @see {@link https://tools.ietf.org/html/draft-ietf-httpapi-linkset-00#section-4.2.4|draft-ietf-httpapi-linkset-00: Linkset §4.2.4}
*/
export interface TargetAttributes extends RegisteredTargetAttributes {
readonly [name: string]: TargetAttributeValue | TargetAttributeValue[];
}

/**
* An object representing a link's parameters.
* @internal
*/
interface LinkParameters extends TargetAttributes {
/**
* The link context.
*/
readonly anchor: string;
/**
* The link relation type.
*/
readonly rel: string;
/**
* The link target.
*/
readonly href: string;
}

/**
* An interface for a web link.
* @see {@link https://tools.ietf.org/html/rfc8288#section-2|RFC 8288: Web Linking §2}
*/
export interface LinkInterface {
/**
* The link context.
*/
readonly anchor: string;
/**
* The link relation type.
* @see {@link https://tools.ietf.org/html/rfc8288#section-2.1|RFC 8288: Web Linking §2.1 Link Relation Types}
*/
readonly rel: string;
/**
* The link target.
*/
readonly href: string;
/**
* The link target attributes.
*/
readonly attributes: TargetAttributes;
}

/**
* A web link.
* @internal
*/
export class Link implements LinkInterface {
/**
* {@inheritDoc LinkInterface.anchor}
*/
public anchor: string;
/**
* {@inheritDoc LinkInterface.rel}
*/
public rel: string;
/**
* {@inheritDoc LinkInterface.href}
*/
public href: string;
/**
* {@inheritDoc LinkInterface.attributes}
*/
public attributes: TargetAttributes;
/**
* Constructs a new link.
* @param parameters - the link's parameters.
* @see {@link LinkParameters}
*/
constructor(parameters: LinkParameters) {
const { anchor, rel, href, ...attributes } = parameters;
this.anchor = anchor;
this.rel = rel;
this.href = href;
this.attributes = attributes;
}
}
Loading