├── .gitattributes ├── .gitignore ├── .editorconfig ├── .github ├── workflows │ ├── security.yml │ ├── ci.yml │ └── release.yml ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md └── renovate.json ├── src ├── tsconfig.types.json ├── types.ts └── ComponentMapping.ts ├── DEV_GUIDELINES.md ├── tsconfig.json ├── test ├── LazyClass.ts ├── MapTo.test.ts └── ComponentMapping.test.ts ├── jest.config.js ├── .releaserc.js ├── webpack.config.js ├── CONTRIBUTING.md ├── README.md ├── package.json ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md └── LICENSE /.gitattributes: -------------------------------------------------------------------------------- 1 | package-lock.json binary 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ 3 | .scannerwork/ 4 | **/*.log 5 | *.tgz 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | trim_trailing_whitespace = true 7 | charset = utf-8 8 | indent_size = 2 9 | indent_style = space 10 | 11 | [*.{js,jsx,ts,tsx}] 12 | indent_size = 4 13 | 14 | [*.{json,xml}] 15 | insert_final_newline = false 16 | 17 | [package.json] 18 | insert_final_newline = true 19 | -------------------------------------------------------------------------------- /.github/workflows/security.yml: -------------------------------------------------------------------------------- 1 | name: Vulnerability check 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | 8 | jobs: 9 | security: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout source code 13 | uses: actions/checkout@master 14 | - name: Run Snyk to check for vulnerabilities 15 | uses: snyk/actions/node@master 16 | env: 17 | SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} 18 | with: 19 | command: monitor 20 | -------------------------------------------------------------------------------- /src/tsconfig.types.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "noEmit": false, 5 | "baseUrl": ".", 6 | "paths": { 7 | "@adobe/aem-spa-component-mapping": [ "./" ], 8 | "@adobe/aem-spa-component-mapping/*": [ "./*" ] 9 | }, 10 | "composite": true, 11 | "module": "es2015", 12 | "target": "esnext", 13 | "importHelpers": true, 14 | "removeComments": false, 15 | "declaration": true, 16 | "declarationMap": true, 17 | "declarationDir": "../dist", 18 | "emitDeclarationOnly": true 19 | } 20 | } -------------------------------------------------------------------------------- /DEV_GUIDELINES.md: -------------------------------------------------------------------------------- 1 | # Development 2 | 3 | Run npm install to get all node_modules that are necessary for development. 4 | 5 | ## Build 6 | 7 | ```sh 8 | $ npm run build 9 | ``` 10 | 11 | or 12 | 13 | ```sh 14 | $ npm run build:production 15 | ``` 16 | 17 | ## Test 18 | 19 | ```sh 20 | $ npm run test 21 | ``` 22 | 23 | ## Usage example 24 | 25 | The `MapTo` helper can be used to directly associate resource type(s) with a given SPA component. 26 | 27 | ``` 28 | import { MapTo } from '@adobe/spa-component-mapping'; 29 | 30 | class MyComponent { 31 | ... 32 | } 33 | 34 | export default MapTo('my/resource/type')(MyComponent); 35 | 36 | ``` 37 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowJs": true, 4 | "allowSyntheticDefaultImports": true, 5 | "esModuleInterop": true, 6 | "experimentalDecorators": true, 7 | "forceConsistentCasingInFileNames": true, 8 | "incremental": true, 9 | "isolatedModules": true, 10 | "lib": [ 11 | "dom", 12 | "dom.iterable", 13 | "esnext" 14 | ], 15 | "module": "esnext", 16 | "moduleResolution": "node", 17 | "outDir": "./dist", 18 | "resolveJsonModule": true, 19 | "skipLibCheck": true, 20 | "strict": true, 21 | "target": "es2018" 22 | }, 23 | "include": [ 24 | "src/**/*" 25 | ] 26 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[feature]" 5 | labels: feature-request 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Adobe. All rights reserved. 3 | * This file is licensed to you under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. You may obtain a copy 5 | * of the License at http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under 8 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific language 10 | * governing permissions and limitations under the License. 11 | */ 12 | 13 | export { ComponentMapping, MapTo } from './ComponentMapping'; 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[bug] " 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Package version** 14 | Provide a package version where the bug occurs. 15 | 16 | **To Reproduce** 17 | Steps to reproduce the behavior: 18 | 1. Go to '...' 19 | 2. Click on '....' 20 | 3. Scroll down to '....' 21 | 4. See error 22 | 23 | **Expected behavior** 24 | A clear and concise description of what you expected to happen. 25 | 26 | **Screenshots** 27 | If applicable, add screenshots to help explain your problem. 28 | 29 | **Additional context** 30 | Add any other context about the problem here. 31 | -------------------------------------------------------------------------------- /test/LazyClass.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Adobe. All rights reserved. 3 | * This file is licensed to you under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. You may obtain a copy 5 | * of the License at http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under 8 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific language 10 | * governing permissions and limitations under the License. 11 | */ 12 | export class LazyClass { 13 | static get hello():string { 14 | return 'world'; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "timezone": "Europe/Zurich", 3 | "packageRules": [ 4 | { 5 | "groupName": "@adobe fixes", 6 | "updateTypes": ["patch", "pin", "digest", "minor"], 7 | "automerge": true, 8 | "packagePatterns": ["^@adobe/"], 9 | "schedule": ["at any time"] 10 | }, 11 | { 12 | "groupName": "@adobe major", 13 | "updateTypes": ["major"], 14 | "packagePatterns": ["^@adobe/"], 15 | "automerge": false, 16 | "schedule": ["at any time"] 17 | }, 18 | { 19 | "groupName": "external fixes", 20 | "updateTypes": ["patch", "pin", "digest", "minor"], 21 | "automerge": true, 22 | "schedule": ["after 1pm on Monday"], 23 | "packagePatterns": ["^.+"], 24 | "excludePackagePatterns": ["^@adobe/"] 25 | }, 26 | { 27 | "groupName": "external major", 28 | "updateTypes": ["major"], 29 | "automerge": false, 30 | "packagePatterns": ["^.+"], 31 | "excludePackagePatterns": ["^@adobe/"], 32 | "schedule": ["after 1pm on Monday"] 33 | } 34 | ] 35 | } -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Adobe. All rights reserved. 3 | * This file is licensed to you under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. You may obtain a copy 5 | * of the License at http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under 8 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific language 10 | * governing permissions and limitations under the License. 11 | */ 12 | 13 | module.exports = { 14 | preset: 'ts-jest', 15 | setupFilesAfterEnv: [], 16 | testEnvironment: 'jsdom', 17 | transform: { 18 | '^.+\\.ts$': 'ts-jest' 19 | }, 20 | testMatch: [ 21 | '/**/test/*.test.ts' 22 | ], 23 | testPathIgnorePatterns: [ 24 | 'node_modules/', 25 | 'dist/' 26 | ], 27 | collectCoverageFrom: [ 28 | 'src/**/*.ts' 29 | ], 30 | coveragePathIgnorePatterns: [ 31 | 'src/types.ts' 32 | ], 33 | coverageDirectory: 'dist/coverage', 34 | moduleFileExtensions: [ 35 | 'ts', 36 | 'js' 37 | ] 38 | }; 39 | -------------------------------------------------------------------------------- /.releaserc.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Adobe. All rights reserved. 3 | * This file is licensed to you under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. You may obtain a copy 5 | * of the License at http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under 8 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific language 10 | * governing permissions and limitations under the License. 11 | */ 12 | 13 | module.exports = { 14 | plugins: [ 15 | '@semantic-release/commit-analyzer', 16 | '@semantic-release/release-notes-generator', 17 | [ 18 | '@semantic-release/changelog', { 19 | 'changelogFile': 'CHANGELOG.md' 20 | } 21 | ], 22 | '@semantic-release/npm', 23 | [ 24 | '@semantic-release/github', { 25 | 'assets': [ 26 | 'package.json', 27 | 'CHANGELOG.md' 28 | ], 29 | 'message': 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}' 30 | } 31 | ], 32 | [ 33 | '@semantic-release/git', { 34 | 'assets': [ 35 | 'package.json', 36 | 'CHANGELOG.md' 37 | ] 38 | } 39 | ] 40 | ], 41 | branch: 'master', 42 | branches: [ 'master' ] 43 | }; 44 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Adobe. All rights reserved. 3 | * This file is licensed to you under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. You may obtain a copy 5 | * of the License at http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under 8 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific language 10 | * governing permissions and limitations under the License. 11 | */ 12 | 13 | const path = require('path'); 14 | const { CleanWebpackPlugin } = require('clean-webpack-plugin'); 15 | 16 | const isProduction = process.env.NODE_ENV === 'production'; 17 | const mode = isProduction ? 'production' : 'development'; 18 | const devtool = isProduction ? false : 'source-map'; 19 | 20 | console.log('Building for:', mode); 21 | 22 | module.exports = { 23 | entry: './src/types.ts', 24 | mode, 25 | devtool, 26 | output: { 27 | globalObject: `(function(){ try{ return typeof self !== 'undefined';}catch(err){return false;}})() ? self : this`, 28 | path: path.resolve(__dirname, 'dist'), 29 | filename: 'aem-spa-component-mapping.js', 30 | library: 'aemSpaComponentMapping', 31 | libraryTarget: 'umd' 32 | }, 33 | module: { 34 | rules: [ 35 | { 36 | test: /.ts$/, 37 | exclude: /(node_modules|dist)/, 38 | use: { 39 | loader: 'ts-loader' 40 | }, 41 | enforce: 'post' 42 | } 43 | ] 44 | }, 45 | resolve: { 46 | extensions: [ '.ts' ] 47 | }, 48 | plugins: [ new CleanWebpackPlugin() ] 49 | }; 50 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Continuous Integration 2 | on: [ pull_request ] 3 | 4 | jobs: 5 | test: 6 | name: Build & Test 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout source code 10 | uses: actions/checkout@v2 11 | with: 12 | fetch-depth: 0 13 | - name: Setup Node.js 14 | uses: actions/setup-node@v2 15 | with: 16 | node-version: '12' 17 | - name: Install dependencies 18 | run: npm ci 19 | - name: Build the project 20 | run: npm run build:production 21 | - name: Run tests and do code coverage check 22 | run: npm run test:coverage 23 | - name: Run code linter 24 | uses: hallee/eslint-action@1.0.3 25 | if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }} 26 | with: 27 | repo-token: ${{ secrets.GITHUB_TOKEN }} 28 | - name: Upload code coverage report to workflow as an artifact 29 | uses: actions/upload-artifact@v2 30 | with: 31 | name: istanbul-code-coverage.zip 32 | path: coverage 33 | - name: Upload code coverage report to codecov.io and comment in pull request 34 | uses: codecov/codecov-action@v1 35 | - name: Upload Sonar report to sonarcloud.io and comment in pull request 36 | uses: sonarsource/sonarcloud-github-action@master 37 | env: 38 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 39 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 40 | with: 41 | args: > 42 | -Dsonar.organization=adobeinc 43 | -Dsonar.projectKey=adobe_aem-spa-component-mapping 44 | -Dsonar.sources=src 45 | -Dsonar.tests=test 46 | -Dsonar.javascript.lcov.reportPaths=dist/coverage/lcov.info 47 | -Dsonar.coverage.exclusions=src/types.ts 48 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | push: 4 | branches: 5 | - master 6 | 7 | jobs: 8 | release: 9 | name: Release and publish module 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout source code 13 | uses: actions/checkout@v2 14 | with: 15 | fetch-depth: 0 16 | - name: Setup Node.js 17 | uses: actions/setup-node@v2 18 | with: 19 | node-version: 12 20 | - name: Install dependencies 21 | run: npm ci 22 | - name: Build the project 23 | run: npm run build:production 24 | - name: Run tests and do code coverage check 25 | run: npm run test:coverage 26 | - name: Upload code coverage report to codecov.io 27 | uses: codecov/codecov-action@v1 28 | - name: Upload Sonar report to sonarcloud.io 29 | uses: sonarsource/sonarcloud-github-action@master 30 | env: 31 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 32 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 33 | with: 34 | args: > 35 | -Dsonar.organization=adobeinc 36 | -Dsonar.projectKey=adobe_aem-spa-component-mapping 37 | -Dsonar.sources=src 38 | -Dsonar.tests=test 39 | -Dsonar.javascript.lcov.reportPaths=dist/coverage/lcov.info 40 | -Dsonar.coverage.exclusions=src/types.ts 41 | - name: Release module and publish it in github.com and npmjs.com 42 | env: 43 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 44 | NPM_TOKEN: ${{ secrets.ADOBE_BOT_NPM_TOKEN }} 45 | run: npm run semantic-release 46 | - name: Build documentation 47 | run: npm run docs 48 | - name: Publish documentation to github pages 49 | uses: JamesIves/github-pages-deploy-action@3.7.1 50 | with: 51 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 52 | BRANCH: gh-pages-documentation 53 | FOLDER: dist/docs 54 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thanks for choosing to contribute! 4 | 5 | The following are a set of guidelines to follow when contributing to this project. 6 | 7 | ## Code Of Conduct 8 | 9 | This project adheres to the Adobe [code of conduct](../CODE_OF_CONDUCT.md). By participating, 10 | you are expected to uphold this code. Please report unacceptable behavior to 11 | [Grp-opensourceoffice@adobe.com](mailto:Grp-opensourceoffice@adobe.com). 12 | 13 | ## Have A Question? 14 | 15 | Start by filing an issue. The existing committers on this project work to reach 16 | consensus around project direction and issue solutions within issue threads 17 | (when appropriate). 18 | 19 | ## Contributor License Agreement 20 | 21 | All third-party contributions to this project must be accompanied by a signed contributor 22 | license agreement. This gives Adobe permission to redistribute your contributions 23 | as part of the project. [Sign our CLA](https://opensource.adobe.com/cla.html). You 24 | only need to submit an Adobe CLA one time, so if you have submitted one previously, 25 | you are good to go! 26 | 27 | ## Code Reviews 28 | 29 | All submissions should come in the form of pull requests and need to be reviewed 30 | by project committers. Read [GitHub's pull request documentation](https://help.github.com/articles/about-pull-requests/) 31 | for more information on sending pull requests. 32 | 33 | Lastly, please follow the [pull request template](PULL_REQUEST_TEMPLATE.md) when 34 | submitting a pull request! 35 | 36 | ## From Contributor To Committer 37 | 38 | We love contributions from our community! If you'd like to go a step beyond contributor 39 | and become a committer with full write access and a say in the project, you must 40 | be invited to the project. The existing committers employ an internal nomination 41 | process that must reach lazy consensus (silence is approval) before invitations 42 | are issued. If you feel you are qualified and want to get more deeply involved, 43 | feel free to reach out to existing committers to have a conversation about that. 44 | 45 | ## Security Issues 46 | 47 | Security issues shouldn't be reported on this issue tracker. Instead, [file an issue to our security experts](https://helpx.adobe.com/security/alertus.html). 48 | 49 | ## Developer Guidelines 50 | 51 | * [Developer Guidelines](DEV_GUIDELINES.md) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AEM Component Mapping package 2 | 3 | [![License](https://img.shields.io/badge/license-Apache%202-blue)](https://github.com/adobe/aem-spa-component-mapping/blob/master/LICENSE) 4 | [![NPM Version](https://img.shields.io/npm/v/@adobe/aem-spa-component-mapping.svg)](https://www.npmjs.com/package/@adobe/aem-spa-component-mapping) 5 | [![Documentation](https://img.shields.io/badge/docs-api-blue)](https://opensource.adobe.com/aem-spa-component-mapping/) 6 | 7 | [![codecov](https://codecov.io/gh/adobe/aem-spa-component-mapping/branch/master/graph/badge.svg)](https://codecov.io/gh/adobe/aem-spa-component-mapping) 8 | [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=adobe_aem-spa-component-mapping&metric=alert_status)](https://sonarcloud.io/dashboard?id=adobe_aem-spa-component-mapping) 9 | [![Known Vulnerabilities](https://snyk.io/test/github/adobe/aem-spa-component-mapping/badge.svg)](https://snyk.io/test/github/adobe/aem-spa-component-mapping) 10 | [![Dependencies](https://badges.renovateapi.com/github/adobe/aem-spa-component-mapping?)](https://app.renovatebot.com/dashboard#github/adobe/aem-spa-component-mapping) 11 | 12 | A storage library for front-end components. Provides a way for the Single Page Application to map front-end components to Adobe Experience Manager resource types (AEM Components). The SPA Editor is the recommended solution for projects that use a SPA framework (React or Angular). 13 | For more information please see the [documentation](https://docs.adobe.com/content/help/en/experience-manager-65/developing/headless/spas/spa-dynamic-model-to-component-mapping.html). 14 | 15 | 16 | ## Installation 17 | ``` 18 | npm install @adobe/aem-spa-component-mapping 19 | ``` 20 | 21 | ## Documentation 22 | 23 | * [SPA Editor Overview](https://www.adobe.com/go/aem6_5_docs_spa_en) 24 | * [SPA Architecture](https://docs.adobe.com/content/help/en/experience-manager-65/developing/headless/spas/spa-architecture.html) 25 | * [Getting Started with the AEM SPA Editor and Angular](https://docs.adobe.com/content/help/en/experience-manager-learn/spa-angular-tutorial/overview.html) 26 | * [Getting Started with the AEM SPA Editor and React](https://docs.adobe.com/content/help/en/experience-manager-learn/spa-react-tutorial/overview.html) 27 | 28 | ## Contributing 29 | 30 | Contributions are welcome! Read the [Contributing Guide](CONTRIBUTING.md) for more information. 31 | 32 | ## Licensing 33 | 34 | This project is licensed under the Apache V2 License. See [LICENSE](LICENSE) for more information. 35 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@adobe/aem-spa-component-mapping", 3 | "version": "1.1.1", 4 | "description": "Provides a mapping of SPA front-end components to AEM resource types.", 5 | "keywords": [ 6 | "spa", 7 | "aem", 8 | "component-mapping", 9 | "adobe" 10 | ], 11 | "author": "Adobe Systems Inc. ", 12 | "license": "Apache-2.0", 13 | "repository": "github:adobe/aem-spa-component-mapping", 14 | "homepage": "https://docs.adobe.com/content/help/en/experience-manager-65/developing/headless/spas/spa-reference-materials.html", 15 | "bugs": { 16 | "url": "https://github.com/adobe/aem-spa-component-mapping/issues" 17 | }, 18 | "engines": { 19 | "npm": "7.24.2", 20 | "node": ">=12.16.2" 21 | }, 22 | "main": "dist/aem-spa-component-mapping.js", 23 | "types": "dist/types.d.ts", 24 | "scripts": { 25 | "build:production": "NODE_ENV=production npm run build", 26 | "build:types": "tsc -p src/tsconfig.types.json", 27 | "build": "npm run clean && npm run linter && webpack && npm run build:types", 28 | "clean": "rm -rf dist/", 29 | "docs": "npm i && npx typedoc --excludePrivate ./src --out ./dist/docs", 30 | "linter": "eslint .", 31 | "semantic-release": "semantic-release", 32 | "test:coverage": "jest --clearCache && jest --coverage", 33 | "test:debug": "jest --coverage --watchAll", 34 | "test": "jest --clearCache && jest" 35 | }, 36 | "devDependencies": { 37 | "@adobe/eslint-config-editorxp": "^1.0.8", 38 | "@semantic-release/changelog": "^5.0.1", 39 | "@semantic-release/git": "^9.0.0", 40 | "@semantic-release/github": "^7.2.1", 41 | "@types/jest": "^26.0.22", 42 | "@typescript-eslint/eslint-plugin": "^4.22.0", 43 | "@typescript-eslint/parser": "^4.22.0", 44 | "clean-webpack-plugin": "^3.0.0", 45 | "commitizen": "^4.2.3", 46 | "cz-conventional-changelog": "^3.3.0", 47 | "eslint": "^7.24.0", 48 | "eslint-plugin-header": "^3.1.1", 49 | "eslint-plugin-json": "^2.1.2", 50 | "eslint-plugin-react": "^7.23.2", 51 | "jest": "^26.6.3", 52 | "semantic-release": "^17.4.2", 53 | "ts-jest": "^26.5.4", 54 | "ts-loader": "^8.1.0", 55 | "typedoc": "^0.22.0", 56 | "typescript": "^4.2.4", 57 | "webpack": "^5.34.0", 58 | "webpack-cli": "^4.6.0" 59 | }, 60 | "files": [ 61 | "dist/**/*.{js,ts,map}", 62 | "!**/{docs,coverage}/" 63 | ], 64 | "config": { 65 | "commitizen": { 66 | "path": "./node_modules/cz-conventional-changelog" 67 | } 68 | }, 69 | "eslintConfig": { 70 | "root": true, 71 | "extends": [ 72 | "@adobe/eslint-config-editorxp/typescript" 73 | ] 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [1.1.1](https://github.com/adobe/aem-spa-component-mapping/compare/v1.1.0...v1.1.1) (2021-04-15) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * return generic types in get/getLazy ([#39](https://github.com/adobe/aem-spa-component-mapping/issues/39)) ([f92ac1f](https://github.com/adobe/aem-spa-component-mapping/commit/f92ac1f9d20e992d782292d6e12e483edde5cce1)) 7 | 8 | # [1.1.0](https://github.com/adobe/aem-spa-component-mapping/compare/v1.0.8...v1.1.0) (2021-01-08) 9 | 10 | 11 | ### Features 12 | 13 | * Support for LazyLoading using promises ([228b65b](https://github.com/adobe/aem-spa-component-mapping/commit/228b65b1ef770c0fb8f19975a93f8f58a08be1ca)) 14 | 15 | ## [1.0.8](https://github.com/adobe/aem-spa-component-mapping/compare/v1.0.7...v1.0.8) (2021-01-05) 16 | 17 | 18 | ### Bug Fixes 19 | 20 | * **docs:** remove --mode from docs build after a typedoc breaking change ([087645d](https://github.com/adobe/aem-spa-component-mapping/commit/087645df9d8cf8bf2eba9fc44838bf17719662b3)) 21 | 22 | ## [1.0.7](https://github.com/adobe/aem-spa-component-mapping/compare/v1.0.6...v1.0.7) (2020-10-08) 23 | 24 | 25 | ### Bug Fixes 26 | 27 | * **package.json:** update engine targets ([#30](https://github.com/adobe/aem-spa-component-mapping/issues/30)) ([e5a44f8](https://github.com/adobe/aem-spa-component-mapping/commit/e5a44f8fa2cac09aef00c2bfbdfddd7ab335d5cf)) 28 | 29 | ## [1.0.6](https://github.com/adobe/aem-spa-component-mapping/compare/v1.0.5...v1.0.6) (2020-09-27) 30 | 31 | 32 | ### Bug Fixes 33 | 34 | * remove project and documentation clutter ([#27](https://github.com/adobe/aem-spa-component-mapping/issues/27)) ([19ece68](https://github.com/adobe/aem-spa-component-mapping/commit/19ece684cfaa835c0c045018f643297b4d70e974)) 35 | 36 | ## [1.0.5](https://github.com/adobe/aem-spa-component-mapping/compare/v1.0.4...v1.0.5) (2020-08-31) 37 | 38 | 39 | ### Bug Fixes 40 | 41 | * **semantic-release:** remove readme generation on release ([#14](https://github.com/adobe/aem-spa-component-mapping/issues/14)) ([7d0f5f5](https://github.com/adobe/aem-spa-component-mapping/commit/7d0f5f56bfeda1a5d7258bb4f51248d4b04a8c7c)) 42 | 43 | ## [1.0.4](https://github.com/adobe/aem-spa-component-mapping/compare/v1.0.3...v1.0.4) (2020-08-30) 44 | 45 | 46 | ### Bug Fixes 47 | 48 | * do not alias `this` ([#13](https://github.com/adobe/aem-spa-component-mapping/issues/13)) ([b5b2605](https://github.com/adobe/aem-spa-component-mapping/commit/b5b260545b8fbba8eed5be6c4a5b955669d30913)) 49 | 50 | ## [1.0.0](https://github.com/adobe/aem-spa-component-mapping/releases/tag/v1.0.0) (2020-08-24) 51 | 52 | 53 | ### Changes 54 | 55 | Initial public release of `aem-spa-component-mapping`. Renamed from cq-spa-component-mapping. 56 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Adobe Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language. 18 | * Being respectful of differing viewpoints and experiences. 19 | * Gracefully accepting constructive criticism. 20 | * Focusing on what is best for the community. 21 | * Showing empathy towards other community members. 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances. 27 | * Trolling, insulting/derogatory comments, and personal or political attacks. 28 | * Public or private harassment. 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission. 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting. 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at Grp-opensourceoffice@adobe.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [https://contributor-covenant.org/version/1/4][version]. 72 | 73 | [homepage]: https://contributor-covenant.org 74 | [version]: https://contributor-covenant.org/version/1/4/ -------------------------------------------------------------------------------- /test/MapTo.test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Adobe. All rights reserved. 3 | * This file is licensed to you under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. You may obtain a copy 5 | * of the License at http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under 8 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific language 10 | * governing permissions and limitations under the License. 11 | */ 12 | 13 | import { ComponentMapping, LazyMapTo, MapTo } from '../src/ComponentMapping'; 14 | import { LazyClass } from './LazyClass'; 15 | 16 | const resource = 'test/mapto'; 17 | const resourcesArray = [ 'resource/mapto/first', 'resource/mapto/second', 'resource/mapto/third' ]; 18 | const lazyResource = 'some/lazy/resource'; 19 | const lazyResourcesArray: string[] = [ 'lazyresource/first', 'lazyresource/second', 'lazyresource/third' ]; 20 | 21 | const lazyPromise:Promise = new Promise((resolve, reject) => { 22 | import('./LazyClass').then((Module) => { 23 | resolve(Module.LazyClass); 24 | }).catch(reject); 25 | }); 26 | 27 | class SampleClassOne { 28 | static get hello() { 29 | return 'world'; 30 | } 31 | } 32 | 33 | class SampleClassTwo { 34 | static get hello() { 35 | return 'world'; 36 | } 37 | } 38 | 39 | describe('MapTo', () => { 40 | let mapping: ComponentMapping; 41 | 42 | beforeEach(() => { 43 | mapping = new ComponentMapping(); 44 | }); 45 | 46 | it('should return `undefined` if given resource string is not mapped', () => { 47 | // then 48 | expect(mapping.get(resource)).toBeUndefined(); 49 | expect(mapping.getLazy(lazyResource)).rejects.toEqual(`resourceType ${lazyResource} not found in mappings!`); 50 | }); 51 | 52 | it('should not create mapping if class was not provided', () => { 53 | // when 54 | MapTo(resource); 55 | LazyMapTo(lazyResource); 56 | 57 | // then 58 | expect(mapping.get(resource)).toBeUndefined(); 59 | expect(mapping.getLazy(lazyResource)).rejects.toEqual(`resourceType ${lazyResource} not found in mappings!`); 60 | }); 61 | 62 | it('should create mapping for a single resource', () => { 63 | // when 64 | MapTo(resource)(SampleClassOne); 65 | LazyMapTo(lazyResource)(() => lazyPromise); 66 | 67 | // then 68 | expect(mapping.get(resource)).toEqual(SampleClassOne); 69 | expect(mapping.getLazy(lazyResource)).resolves.toBe(LazyClass); 70 | }); 71 | 72 | it('should override mapping for single resource', () => { 73 | // when 74 | MapTo(resource)(SampleClassTwo); 75 | 76 | // then 77 | expect(mapping.get(resource)).toEqual(SampleClassTwo); 78 | }); 79 | 80 | it('should create mapping for resource array', () => { 81 | // when 82 | MapTo(resourcesArray)(SampleClassOne); 83 | LazyMapTo(lazyResourcesArray)(() => lazyPromise); 84 | 85 | // then 86 | expect(mapping.get(resourcesArray[0])).toEqual(SampleClassOne); 87 | expect(mapping.getLazy(lazyResourcesArray[0])).resolves.toBe(LazyClass); 88 | 89 | expect(mapping.get(resourcesArray[1])).toEqual(SampleClassOne); 90 | expect(mapping.getLazy(lazyResourcesArray[1])).resolves.toBe(LazyClass); 91 | 92 | expect(mapping.get(resourcesArray[2])).toEqual(SampleClassOne); 93 | expect(mapping.getLazy(lazyResourcesArray[2])).resolves.toBe(LazyClass); 94 | 95 | }); 96 | 97 | it('should override mapping for resource array', () => { 98 | // when 99 | MapTo(resourcesArray)(SampleClassTwo); 100 | LazyMapTo(lazyResourcesArray)(() => lazyPromise); 101 | 102 | // then 103 | expect(mapping.get(resourcesArray[0])).toEqual(SampleClassTwo); 104 | expect(mapping.getLazy(lazyResourcesArray[0])).resolves.toBe(LazyClass); 105 | 106 | expect(mapping.get(resourcesArray[1])).toEqual(SampleClassTwo); 107 | expect(mapping.getLazy(lazyResourcesArray[1])).resolves.toBe(LazyClass); 108 | 109 | expect(mapping.get(resourcesArray[2])).toEqual(SampleClassTwo); 110 | expect(mapping.getLazy(lazyResourcesArray[2])).resolves.toBe(LazyClass); 111 | }); 112 | }); 113 | -------------------------------------------------------------------------------- /test/ComponentMapping.test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Adobe. All rights reserved. 3 | * This file is licensed to you under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. You may obtain a copy 5 | * of the License at http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under 8 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific language 10 | * governing permissions and limitations under the License. 11 | */ 12 | 13 | import { ComponentMapping } from '../src/ComponentMapping'; 14 | import { LazyClass } from './LazyClass'; 15 | 16 | class SampleClass { 17 | static get hello() { 18 | return 'world'; 19 | } 20 | } 21 | 22 | const lazyPromise: Promise = new Promise((resolve, reject) => { 23 | import('./LazyClass').then((Module) => { 24 | resolve(Module.LazyClass); 25 | }).catch(reject); 26 | }); 27 | 28 | describe('ComponentMapping', () => { 29 | let mapping: ComponentMapping; 30 | const resource = 'some/resource'; 31 | const lazyResource = 'some/lazy/resource'; 32 | const resourcesArray: string[] = [ 'resource/first', 'resource/second', 'resource/third' ]; 33 | const lazyResourcesArray: string[] = [ 'lazyresource/first', 'lazyresource/second', 'lazyresource/third' ]; 34 | 35 | beforeEach(() => { 36 | mapping = new ComponentMapping(); 37 | ComponentMapping.mapping = {}; 38 | ComponentMapping.lazyMapping = {}; 39 | }); 40 | 41 | it('should be a singleton', () => { 42 | // get ComponentMapping instance 43 | const instance1 = new ComponentMapping(); 44 | 45 | // creating mapping 46 | instance1.map('singleton-test', SampleClass); 47 | instance1.lazyMap('singleton-lazy-test', () => lazyPromise); 48 | 49 | // get ComponentMapping instance 50 | const instance2 = new ComponentMapping(); 51 | 52 | // checking if mapping created by first instance is present in second instance 53 | expect(instance2.get('singleton-test')).toBe(SampleClass); 54 | expect(instance2.getLazy('singleton-lazy-test')).resolves.toBe(LazyClass); 55 | expect(instance1).toBe(instance2); 56 | }); 57 | 58 | it('should not create any mapping if class is missing', () => { 59 | // mapping does not exist 60 | expect(mapping.get(resource)).toBeUndefined(); 61 | expect(mapping.getLazy(lazyResource)).rejects.toEqual(`resourceType ${lazyResource} not found in mappings!`); 62 | 63 | // attempt to create mapping 64 | mapping.map(resource, undefined); 65 | mapping.lazyMap(lazyResource, () => new Promise((resolve => resolve(undefined)))); 66 | 67 | // mapping does not exist 68 | expect(mapping.get(resource)).toBeUndefined(); 69 | expect(mapping.getLazy(resource)).rejects.toEqual(`resourceType ${resource} not found in mappings!`); 70 | }); 71 | 72 | it('should create mapping between resource type and component class', () => { 73 | // mapping does not exist 74 | expect(mapping.get(resource)).toBeUndefined(); 75 | expect(mapping.getLazy(lazyResource)).rejects.toEqual(`resourceType ${lazyResource} not found in mappings!`); 76 | 77 | // creating mapping 78 | mapping.map(resource, SampleClass); 79 | mapping.lazyMap(lazyResource, () => lazyPromise); 80 | 81 | // checking mapping 82 | expect(mapping.get(resource)).toBe(SampleClass); 83 | expect(mapping.getLazy(lazyResource)).resolves.toBe(LazyClass); 84 | }); 85 | 86 | it('should create mapping for several resource types', () => { 87 | // mapping does not exist 88 | expect(mapping.get(resourcesArray[0])).toBeUndefined(); 89 | expect(mapping.get(resourcesArray[1])).toBeUndefined(); 90 | expect(mapping.get(resourcesArray[2])).toBeUndefined(); 91 | 92 | expect(mapping.getLazy(lazyResourcesArray[0])).rejects.toEqual(`resourceType ${lazyResourcesArray[0]} not found in mappings!`); 93 | expect(mapping.getLazy(lazyResourcesArray[1])).rejects.toEqual(`resourceType ${lazyResourcesArray[1]} not found in mappings!`); 94 | expect(mapping.getLazy(lazyResourcesArray[2])).rejects.toEqual(`resourceType ${lazyResourcesArray[2]} not found in mappings!`); 95 | 96 | // creating mapping 97 | mapping.map(resourcesArray, SampleClass); 98 | mapping.lazyMap(lazyResourcesArray, () => lazyPromise); 99 | 100 | // checking mapping 101 | expect(mapping.get(resourcesArray[0])).toBe(SampleClass); 102 | expect(mapping.get(resourcesArray[1])).toBe(SampleClass); 103 | expect(mapping.get(resourcesArray[2])).toBe(SampleClass); 104 | 105 | const checkPromise = (promise: Promise) => { 106 | promise.then((clazz) => { 107 | expect(clazz).toBe(LazyClass); 108 | }); 109 | }; 110 | 111 | // checking mapping 112 | checkPromise(mapping.getLazy(lazyResourcesArray[0])); 113 | checkPromise(mapping.getLazy(lazyResourcesArray[1])); 114 | checkPromise(mapping.getLazy(lazyResourcesArray[2])); 115 | }); 116 | }); 117 | -------------------------------------------------------------------------------- /src/ComponentMapping.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Adobe. All rights reserved. 3 | * This file is licensed to you under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. You may obtain a copy 5 | * of the License at http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under 8 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific language 10 | * governing permissions and limitations under the License. 11 | */ 12 | 13 | /** 14 | * ComponentMapping interface. 15 | * @private 16 | */ 17 | interface ComponentMappingObject { 18 | [key: string]: unknown; 19 | } 20 | 21 | /** 22 | * LazyComponentMappingObject interface. 23 | * @private 24 | */ 25 | interface LazyComponentMappingObject { 26 | [key: string]: lazyMapFunction; 27 | } 28 | 29 | /** 30 | * ComponentMapping instance. 31 | * @private 32 | */ 33 | let instance: ComponentMappingImpl; 34 | 35 | export type lazyMapFunction = () => Promise; 36 | 37 | /** 38 | * ComponentMapping singleton. It manages the mapping between AEM component resource types and corresponding 39 | * JavaScript component class. 40 | * @private 41 | */ 42 | class ComponentMappingImpl { 43 | 44 | static mapping: ComponentMappingObject = {}; 45 | static lazyMapping: LazyComponentMappingObject = {}; 46 | 47 | static get instance(): ComponentMappingImpl { 48 | return new this(); 49 | } 50 | 51 | constructor() { 52 | if (!instance) { 53 | instance = this; 54 | } 55 | 56 | return instance; 57 | } 58 | 59 | /** 60 | * Creates mapping for given resource type(s) and a component class. 61 | * @param resourceTypes Resource type(s). 62 | * @param clazz Component class that will be associated with given resource type(s). 63 | * @protected 64 | */ 65 | public map(resourceTypes: string | string[], clazz: unknown): void { 66 | ComponentMappingImpl.map(resourceTypes, clazz); 67 | } 68 | 69 | /** 70 | * Creates mapping for given resource type(s) and a component class. 71 | * @param resourceTypes Resource type(s). 72 | * @param clazz Component class that will be associated with given resource type(s). 73 | * @protected 74 | */ 75 | public static map(resourceTypes: string | string[], clazz: unknown): void { 76 | if (resourceTypes && clazz) { 77 | const resourceList = (typeof resourceTypes === 'string') ? [ resourceTypes ] : resourceTypes; 78 | 79 | resourceList.forEach((entry) => { 80 | this.mapping[entry] = clazz; 81 | }); 82 | } 83 | } 84 | 85 | public lazyMap(resourceTypes: string | string[], clazz: lazyMapFunction): void { 86 | ComponentMappingImpl.lazyMap(resourceTypes, clazz); 87 | } 88 | 89 | public static lazyMap(resourceTypes: string | string[], clazz: lazyMapFunction): void { 90 | if (resourceTypes && clazz) { 91 | 92 | const resourceList = (typeof resourceTypes === 'string') ? [ resourceTypes ] : resourceTypes; 93 | 94 | resourceList.forEach((entry) => { 95 | this.lazyMapping[entry] = clazz; 96 | }); 97 | } 98 | } 99 | 100 | /** 101 | * Returns object (or `undefined`) matching with given resource type. 102 | * @param resourceType Resource type. 103 | * @returns Class associated with given resource type or `undefined`. 104 | */ 105 | public get(resourceType: string): T { 106 | return ComponentMappingImpl.get(resourceType); 107 | } 108 | 109 | /** 110 | * Returns object (or `undefined`) matching with given resource type. 111 | * @param resourceType Resource type. 112 | * @returns Class associated with given resource type or `undefined`. 113 | */ 114 | public static get(resourceType: string): T { 115 | return this.mapping[resourceType] as T; 116 | } 117 | 118 | /** 119 | * Returns object (or undefined) matching with given resource type. 120 | * 121 | * @param {string} resourceType - resource type 122 | * @returns {object|undefined} - class associated with given resource type 123 | */ 124 | public getLazy(resourceType: string): Promise { 125 | return ComponentMappingImpl.getLazy(resourceType); 126 | } 127 | 128 | public static getLazy(resourceType: string): Promise { 129 | 130 | if (this.lazyMapping[resourceType]) { 131 | return this.lazyMapping[resourceType]() as Promise; 132 | } 133 | 134 | return Promise.reject('resourceType ' + resourceType + ' not found in mappings!'); 135 | } 136 | 137 | } 138 | 139 | /** 140 | * Use to register resource types to Class mapping. 141 | * 142 | * Example: 143 | * ``` 144 | * import { MapTo } from '@adobe/aem-spa-component-mapping'; 145 | * 146 | * class MyComponent { 147 | * ... 148 | * } 149 | * 150 | * export default MapTo('my/resource/type')(MyComponent); 151 | * ``` 152 | * 153 | * @param resourceTypes AEM resource type(s). 154 | * @returns Function mapping a class with the given resource types. 155 | */ 156 | const MapTo = (resourceTypes: string | string[]): (clazz: unknown) => void => { 157 | return (clazz: unknown) => ComponentMappingImpl.instance.map(resourceTypes, clazz); 158 | }; 159 | 160 | /** 161 | * Use to register resource types to Class mapping in a lazyLoad fashion, with dynamic imports 162 | * 163 | * Example: 164 | * ``` 165 | * import { LazyMapTo } from '@adobe/aem-spa-component-mapping'; 166 | * 167 | * MyComponent.ts: 168 | * export class MyComponent { 169 | * ... 170 | * } 171 | * 172 | * LazyMapTo('my/resource/type')(MyComponent); 173 | * ``` 174 | * 175 | * @param resourceTypes AEM resource type(s). 176 | * @returns Function mapping a class with the given resource types. 177 | */ 178 | const LazyMapTo = (resourceTypes: string | string[]): (lazyPromise: lazyMapFunction) => void => { 179 | return (lazyPromise: lazyMapFunction) => ComponentMappingImpl.instance.lazyMap(resourceTypes, lazyPromise); 180 | }; 181 | 182 | export { ComponentMappingImpl as ComponentMapping, MapTo, LazyMapTo }; 183 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2020 Adobe 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. --------------------------------------------------------------------------------