@teambit/schema 1.0.108 → 1.0.109
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/__bit_junit.xml +8 -0
- package/artifacts/preview/teambit_semantics_schema-preview.js +2 -0
- package/dist/{preview-1703647408454.js → preview-1703698405864.js} +3 -3
- package/package.json +13 -13
- package/index.ts +0 -16
- package/parser.ts +0 -13
- package/schema-env.ts +0 -10
- package/schema-extractor.ts +0 -23
- package/schema.aspect.ts +0 -5
- package/schema.cmd.ts +0 -40
- package/schema.graphql.ts +0 -58
- package/schema.main.runtime.ts +0 -221
- package/schema.service.ts +0 -22
- package/schema.spec.ts +0 -83
- package/schema.task.ts +0 -79
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<testsuites>
|
|
3
|
+
<testsuite name="teambit.semantics/schema@1.0.109" timestamp="2023-12-27T17:56:28.158Z" tests="3" failures="0" errors="0" skipped="0">
|
|
4
|
+
<testcase classname="schema.spec.js" name="should be able to generate JSON object with all schemas" time="0.02"/>
|
|
5
|
+
<testcase classname="schema.spec.js" name="should be able to deserialize an JSON object to SchemaNode instances" time="0.014"/>
|
|
6
|
+
<testcase classname="schema.spec.js" name="should not throw when it does not recognize the schema" time="0.002"/>
|
|
7
|
+
</testsuite>
|
|
8
|
+
</testsuites>
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see teambit_semantics_schema-preview.js.LICENSE.txt */
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["teambit.semantics/schema-preview"]=t():e["teambit.semantics/schema-preview"]=t()}(self,(()=>(()=>{var e={93183:(e,t)=>{"use strict";var n=Object.prototype.hasOwnProperty;function r(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(e){return null}}function o(e){try{return encodeURIComponent(e)}catch(e){return null}}t.stringify=function(e,t){t=t||"";var r,i,a=[];for(i in"string"!=typeof t&&(t="?"),e)if(n.call(e,i)){if((r=e[i])||null!=r&&!isNaN(r)||(r=""),i=o(i),r=o(r),null===i||null===r)continue;a.push(i+"="+r)}return a.length?t+a.join("&"):""},t.parse=function(e){for(var t,n=/([^=?#&]+)=?([^&]*)/g,o={};t=n.exec(e);){var i=r(t[1]),a=r(t[2]);null===i||null===a||i in o||(o[i]=a)}return o}},49010:e=>{"use strict";e.exports=function(e,t){if(t=t.split(":")[0],!(e=+e))return!1;switch(t){case"http":case"ws":return 80!==e;case"https":case"wss":return 443!==e;case"ftp":return 21!==e;case"gopher":return 70!==e;case"file":return!1}return 0!==e}},74842:(e,t)=>{var n;!function(){"use strict";var r={}.hasOwnProperty;function o(){for(var e=[],t=0;t<arguments.length;t++){var n=arguments[t];if(n){var i=typeof n;if("string"===i||"number"===i)e.push(n);else if(Array.isArray(n)){if(n.length){var a=o.apply(null,n);a&&e.push(a)}}else if("object"===i)if(n.toString===Object.prototype.toString)for(var s in n)r.call(n,s)&&n[s]&&e.push(s);else e.push(n.toString())}}return e.join(" ")}e.exports?(o.default=o,e.exports=o):void 0===(n=function(){return o}.apply(t,[]))||(e.exports=n)}()},83371:(e,t,n)=>{"use strict";var r=n(49010),o=n(93183),i=/^[A-Za-z][A-Za-z0-9+-.]*:[\\/]+/,a=/^([a-z][a-z0-9.+-]*:)?([\\/]{1,})?([\S\s]*)/i,s=new RegExp("^[\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\xA0\\u1680\\u180E\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u3000\\u2028\\u2029\\uFEFF]+");function c(e){return(e||"").toString().replace(s,"")}var u=[["#","hash"],["?","query"],function(e){return e.replace("\\","/")},["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d+)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],l={hash:1,query:1};function p(e){var t,r=("undefined"!=typeof window?window:void 0!==n.g?n.g:"undefined"!=typeof self?self:{}).location||{},o={},a=typeof(e=e||r);if("blob:"===e.protocol)o=new d(unescape(e.pathname),{});else if("string"===a)for(t in o=new d(e,{}),l)delete o[t];else if("object"===a){for(t in e)t in l||(o[t]=e[t]);void 0===o.slashes&&(o.slashes=i.test(e.href))}return o}function f(e){e=c(e);var t=a.exec(e);return{protocol:t[1]?t[1].toLowerCase():"",slashes:!!(t[2]&&t[2].length>=2),rest:t[2]&&1===t[2].length?"/"+t[3]:t[3]}}function d(e,t,n){if(e=c(e),!(this instanceof d))return new d(e,t,n);var i,a,s,l,m,h,b=u.slice(),v=typeof t,_=this,y=0;for("object"!==v&&"string"!==v&&(n=t,t=null),n&&"function"!=typeof n&&(n=o.parse),t=p(t),i=!(a=f(e||"")).protocol&&!a.slashes,_.slashes=a.slashes||i&&t.slashes,_.protocol=a.protocol||t.protocol||"",e=a.rest,a.slashes||(b[3]=[/(.*)/,"pathname"]);y<b.length;y++)"function"!=typeof(l=b[y])?(s=l[0],h=l[1],s!=s?_[h]=e:"string"==typeof s?~(m=e.indexOf(s))&&("number"==typeof l[2]?(_[h]=e.slice(0,m),e=e.slice(m+l[2])):(_[h]=e.slice(m),e=e.slice(0,m))):(m=s.exec(e))&&(_[h]=m[1],e=e.slice(0,m.index)),_[h]=_[h]||i&&l[3]&&t[h]||"",l[4]&&(_[h]=_[h].toLowerCase())):e=l(e);n&&(_.query=n(_.query)),i&&t.slashes&&"/"!==_.pathname.charAt(0)&&(""!==_.pathname||""!==t.pathname)&&(_.pathname=function(e,t){if(""===e)return t;for(var n=(t||"/").split("/").slice(0,-1).concat(e.split("/")),r=n.length,o=n[r-1],i=!1,a=0;r--;)"."===n[r]?n.splice(r,1):".."===n[r]?(n.splice(r,1),a++):a&&(0===r&&(i=!0),n.splice(r,1),a--);return i&&n.unshift(""),"."!==o&&".."!==o||n.push(""),n.join("/")}(_.pathname,t.pathname)),"/"!==_.pathname.charAt(0)&&_.hostname&&(_.pathname="/"+_.pathname),r(_.port,_.protocol)||(_.host=_.hostname,_.port=""),_.username=_.password="",_.auth&&(l=_.auth.split(":"),_.username=l[0]||"",_.password=l[1]||""),_.origin=_.protocol&&_.host&&"file:"!==_.protocol?_.protocol+"//"+_.host:"null",_.href=_.toString()}d.prototype={set:function(e,t,n){var i=this;switch(e){case"query":"string"==typeof t&&t.length&&(t=(n||o.parse)(t)),i[e]=t;break;case"port":i[e]=t,r(t,i.protocol)?t&&(i.host=i.hostname+":"+t):(i.host=i.hostname,i[e]="");break;case"hostname":i[e]=t,i.port&&(t+=":"+i.port),i.host=t;break;case"host":i[e]=t,/:\d+$/.test(t)?(t=t.split(":"),i.port=t.pop(),i.hostname=t.join(":")):(i.hostname=t,i.port="");break;case"protocol":i.protocol=t.toLowerCase(),i.slashes=!n;break;case"pathname":case"hash":if(t){var a="pathname"===e?"/":"#";i[e]=t.charAt(0)!==a?a+t:t}else i[e]=t;break;default:i[e]=t}for(var s=0;s<u.length;s++){var c=u[s];c[4]&&(i[c[1]]=i[c[1]].toLowerCase())}return i.origin=i.protocol&&i.host&&"file:"!==i.protocol?i.protocol+"//"+i.host:"null",i.href=i.toString(),i},toString:function(e){e&&"function"==typeof e||(e=o.stringify);var t,n=this,r=n.protocol;r&&":"!==r.charAt(r.length-1)&&(r+=":");var i=r+(n.slashes?"//":"");return n.username&&(i+=n.username,n.password&&(i+=":"+n.password),i+="@"),i+=n.host+n.pathname,(t="object"==typeof n.query?e(n.query):n.query)&&(i+="?"!==t.charAt(0)?"?"+t:t),n.hash&&(i+=n.hash),i}},d.extractProtocol=f,d.location=p,d.trimLeft=c,d.qs=o,e.exports=d},87264:(e,t,n)=>{"use strict";var r={id:"teambit.semantics/schema@1.0.109",homepage:"https://bit.cloud/teambit/semantics/schema",exported:!0};function o(){const e=a(n(87363));return o=function(){return e},e}function i(){const e=n(81774);return i=function(){return e},e}function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.ButtonWithIcon=t.ButtonWithCustomStyles=t.ButtonAsALink=t.BasicButton=void 0,t.Footer=c,o.__bit_component=r,i.__bit_component=r,a.__bit_component=r;const s=()=>o().default.createElement(i().Button,null,"click me");function c({children:e=o().default.createElement(s,null)}){return o().default.createElement(i().Button,null,e)}s.__bit_component=r,t.BasicButton=s,c.__bit_component=r;const u=()=>o().default.createElement(i().Button,{style:{background:"red"}},"click me");u.__bit_component=r,t.ButtonWithCustomStyles=u;const l=()=>o().default.createElement(i().Button,null,"click me");l.__bit_component=r,t.ButtonWithIcon=l;const p=()=>o().default.createElement(i().Button,{href:"https://bit.dev"},"Bit");p.__bit_component=r,t.ButtonAsALink=p},81774:(e,t,n)=>{"use strict";var r={id:"teambit.semantics/schema@1.0.109",homepage:"https://bit.cloud/teambit/semantics/schema",exported:!0};function o(){const e=s(n(87363));return o=function(){return e},e}function i(){const e=n(50430);return i=function(){return e},e}function a(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(a=function(e){return e?n:t})(e)}function s(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var n=a(t);if(n&&n.has(e))return n.get(e);var r={__proto__:null},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if("default"!==i&&Object.prototype.hasOwnProperty.call(e,i)){var s=o?Object.getOwnPropertyDescriptor(e,i):null;s&&(s.get||s.set)?Object.defineProperty(r,i,s):r[i]=e[i]}return r.default=e,n&&n.set(e,r),r}function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},c.apply(this,arguments)}function u(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function l(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?u(Object(n),!0).forEach((function(t){p(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):u(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function p(e,t,n){return(t=f(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e){var t=d(e,"string");return"symbol"==typeof t?t:String(t)}function d(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function m(e){const t=(0,o().useRef)(),n=l({},e),r=e.href?.startsWith("http:")||e.href?.startsWith("https:");return o().default.createElement(o().default.Fragment,null,e.href?o().default.createElement(i().Link,c({external:r,ref:t,className:e.className},n),e.children):o().default.createElement("button",c({className:e.className,ref:t},n),e.children))}Object.defineProperty(t,"__esModule",{value:!0}),t.Bar=void 0,t.Button=m,o.__bit_component=r,i.__bit_component=r,a.__bit_component=r,s.__bit_component=r,c.__bit_component=r,u.__bit_component=r,l.__bit_component=r,p.__bit_component=r,f.__bit_component=r,d.__bit_component=r,m.__bit_component=r,t.Bar=class{foo(){}}},29531:(e,t,n)=>{"use strict";var r={id:"teambit.semantics/schema@1.0.109",homepage:"https://bit.cloud/teambit/semantics/schema",exported:!0};function o(){const e=i(n(87363));return o=function(){return e},e}function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Logo=void 0,o.__bit_component=r,i.__bit_component=r;const a=()=>o().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},o().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/extensions-icons/code.svg"}));a.__bit_component=r,t.Logo=a},50430:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.NavigationProvider=t.useNavigation=t.useNavigate=t.useLocation=t.Link=void 0;var r=n(48174);Object.defineProperty(t,"Link",{enumerable:!0,get:function(){return r.Link}});var o=n(49319);Object.defineProperty(t,"useLocation",{enumerable:!0,get:function(){return o.useLocation}});var i=n(14863);Object.defineProperty(t,"useNavigate",{enumerable:!0,get:function(){return i.useNavigate}});var a=n(64328);Object.defineProperty(t,"useNavigation",{enumerable:!0,get:function(){return a.useNavigation}}),Object.defineProperty(t,"NavigationProvider",{enumerable:!0,get:function(){return a.NavigationProvider}})},48174:function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.Link=void 0;const a=i(n(87363)),s=n(64328),c=n(65494);t.Link=(0,a.forwardRef)((function(e,t){const n=(0,s.useNavigation)().Link||c.NativeLink;return e.native||e.external?a.default.createElement(c.NativeLink,Object.assign({},e,{ref:t})):a.default.createElement(n,Object.assign({},e,{ref:t}))}))},65494:function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t},a=this&&this.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.NativeLink=void 0;const c=i(n(87363)),u=s(n(74842)),l=n(34451),p=n(49319),f={rel:"noopener",target:"_blank"};t.NativeLink=(0,c.forwardRef)((function(e,t){var{className:n,style:r,activeClassName:o,activeStyle:i,active:s,strict:d,exact:m,href:h,external:b,native:v,state:_}=e,y=a(e,["className","style","activeClassName","activeStyle","active","strict","exact","href","external","native","state"]);const g=(0,p.useLocation)(),O=!!o||!!i,j=(0,c.useMemo)((()=>!!O&&("boolean"==typeof s?s:!(!g||!h)&&(0,l.compareUrl)(g.pathname,h,{exact:m,strict:d}))),[s,h,g,O]),w=b?f:{},x=(0,c.useMemo)((()=>j&&i?Object.assign(Object.assign({},r),i):r),[j,r]);return c.default.createElement("a",Object.assign({},w,y,{ref:t,href:h,className:(0,u.default)(n,j&&o),style:x}))}))},64328:function(e,t,n){"use strict";var r={id:"teambit.base-react/navigation/link@2.0.27",homepage:"https://bit.dev/teambit/base-react/navigation/link",exported:!0},o=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&o(t,e,n);return i(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.NavigationProvider=t.useNavigation=t.NavigationContext=void 0;const s=a(n(87363));function c(){return(0,s.useContext)(t.NavigationContext)}function u({children:e,implementation:n}){return s.default.createElement(t.NavigationContext.Provider,{value:n},e)}t.NavigationContext=s.default.createContext({}),c.__bit_component=r,t.useNavigation=c,u.__bit_component=r,t.NavigationProvider=u},49319:(e,t,n)=>{"use strict";var r={id:"teambit.base-react/navigation/link@2.0.27",homepage:"https://bit.dev/teambit/base-react/navigation/link",exported:!0};Object.defineProperty(t,"__esModule",{value:!0}),t.useLocation=void 0;const o=n(64328);function i(){return((0,o.useNavigation)().useLocation||a)()}function a(){if("undefined"!=typeof window)return window.location}i.__bit_component=r,t.useLocation=i,a.__bit_component=r},14863:(e,t,n)=>{"use strict";var r={id:"teambit.base-react/navigation/link@2.0.27",homepage:"https://bit.dev/teambit/base-react/navigation/link",exported:!0};Object.defineProperty(t,"__esModule",{value:!0}),t.useNavigate=void 0;const o=n(64328);function i(){var e;const t=(0,o.useNavigation)();return(null===(e=t.useNavigate)||void 0===e?void 0:e.call(t))||a}function a(e,{replace:t}={}){if("undefined"==typeof window)throw new Error("base-react.navigation.use-location - cannot use native navigator outside of browser. Inject a custom useNavigate, or use navigation after mount");const{location:n,history:r}=window;"number"==typeof e?r.go(e):t?n.replace(e):n.assign(e)}i.__bit_component=r,t.useNavigate=i,a.__bit_component=r},56140:function(e,t,n){"use strict";var r={id:"teambit.base-ui/routing/compare-url@1.0.0",homepage:"https://bit.dev/teambit/base-ui/routing/compare-url",exported:!0},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.compareUrl=void 0;const i=o(n(83371));function a(e,t,{exact:n,strict:r}={}){if(e===t)return!0;r||(e=e.replace(/\/(?=[?#]|$)/,""),t=t.replace(/\/(?=[?#]|$)/,""));const o=i.default(e),a=i.default(t),l=s(o,a),p=!n||c(o,a),f=!r||u(o,a);return l&&p&&f}function s(e,t){return(!t.protocol||t.protocol===e.protocol)&&(!t.hostname||t.hostname===e.hostname)&&(!t.port||t.port===e.port)&&(!t.pathname||e.pathname.startsWith(t.pathname))&&(!t.query||l(t.query,e.query))&&(!t.hash||t.hash===e.hash)&&(!t.password||t.password===e.password)&&(!t.username||t.username===e.username)}function c(e,t){return(!t.pathname||e.pathname===t.pathname)&&(!t.query||l(e.query,t.query))}function u(e,t){return!t.pathname||e.pathname.endsWith("/")===t.pathname.endsWith("/")}function l(e,t){return Object.keys(e).every((n=>e[n]===t[n]))}a.__bit_component=r,t.compareUrl=a,s.__bit_component=r,c.__bit_component=r,u.__bit_component=r,l.__bit_component=r},34451:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.compareUrl=void 0;var r=n(56140);Object.defineProperty(t,"compareUrl",{enumerable:!0,get:function(){return r.compareUrl}})},87363:e=>{"use strict";e.exports=React}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.r(r),n.d(r,{compositions:()=>f,compositions_metadata:()=>m,overview:()=>d});var e={};n.r(e),n.d(e,{default:()=>p});var t=n(29531),o=n(87264);n(87363);const i=MdxJsReact,a=TeambitMdxUiMdxScopeContext;var s=["components"];function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},c.apply(this,arguments)}var u={},l="wrapper";function p(e){var t=e.components,n=function(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(e,s);return(0,i.mdx)(l,c({},u,n,{components:t,mdxType:"MDXLayout"}),(0,i.mdx)(a.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"}))}p.isMDXComponent=!0;const f=[t,o],d=[e],m={compositions:[{displayName:"Logo",identifier:"Logo"},{displayName:"Basic button",identifier:"BasicButton"},{displayName:"Footer",identifier:"Footer"},{displayName:"Button with custom styles",identifier:"ButtonWithCustomStyles"},{displayName:"Button with icon",identifier:"ButtonWithIcon"},{displayName:"Button as a link",identifier:"ButtonAsALink"}]}})(),r})()));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@1.0.
|
|
2
|
-
import * as compositions_1 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@1.0.
|
|
3
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@1.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@1.0.109/dist/schema.composition.js';
|
|
2
|
+
import * as compositions_1 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@1.0.109/dist/mock/button/button.composition.js';
|
|
3
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@1.0.109/dist/schema.docs.mdx';
|
|
4
4
|
|
|
5
5
|
export const compositions = [compositions_0, compositions_1];
|
|
6
6
|
export const overview = [overview_0];
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/schema",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.109",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/semantics/schema",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.semantics",
|
|
8
8
|
"name": "schema",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.109"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"p-map-series": "2.1.0",
|
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
"@teambit/semantics.entities.semantic-schema": "0.0.59",
|
|
17
17
|
"@teambit/harmony": "0.4.6",
|
|
18
18
|
"@teambit/base-react.navigation.link": "2.0.27",
|
|
19
|
-
"@teambit/envs": "1.0.
|
|
20
|
-
"@teambit/component": "1.0.
|
|
21
|
-
"@teambit/formatter": "1.0.
|
|
22
|
-
"@teambit/cli": "0.0.
|
|
23
|
-
"@teambit/logger": "0.0.
|
|
24
|
-
"@teambit/graphql": "1.0.
|
|
25
|
-
"@teambit/builder": "1.0.
|
|
19
|
+
"@teambit/envs": "1.0.109",
|
|
20
|
+
"@teambit/component": "1.0.109",
|
|
21
|
+
"@teambit/formatter": "1.0.109",
|
|
22
|
+
"@teambit/cli": "0.0.841",
|
|
23
|
+
"@teambit/logger": "0.0.934",
|
|
24
|
+
"@teambit/graphql": "1.0.109",
|
|
25
|
+
"@teambit/builder": "1.0.109",
|
|
26
26
|
"@teambit/defender.prettier.config-mutator": "0.0.94",
|
|
27
|
-
"@teambit/workspace": "1.0.
|
|
27
|
+
"@teambit/workspace": "1.0.109"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/fs-extra": "9.0.7",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"@types/jest": "^29.2.2",
|
|
33
33
|
"@types/testing-library__jest-dom": "^5.9.5",
|
|
34
34
|
"@teambit/component-id": "1.2.0",
|
|
35
|
-
"@teambit/harmony.envs.core-aspect-env": "0.0.
|
|
36
|
-
"@teambit/harmony.testing.load-aspect": "0.0.
|
|
37
|
-
"@teambit/tracker": "1.0.
|
|
35
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.14",
|
|
36
|
+
"@teambit/harmony.testing.load-aspect": "0.0.180",
|
|
37
|
+
"@teambit/tracker": "1.0.109",
|
|
38
38
|
"@teambit/workspace.testing.mock-workspace": "0.0.18"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
package/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { SchemaAspect } from './schema.aspect';
|
|
2
|
-
|
|
3
|
-
export type { Parser } from './parser';
|
|
4
|
-
export type { SchemaExtractor } from './schema-extractor';
|
|
5
|
-
export type { SchemaExtractorOptions } from './schema-extractor';
|
|
6
|
-
export {
|
|
7
|
-
SchemaTask,
|
|
8
|
-
SCHEMA_ARTIFACT_NAME,
|
|
9
|
-
SCHEMA_TASK_NAME,
|
|
10
|
-
getSchemaArtifactDef,
|
|
11
|
-
getSchemaArtifactPath,
|
|
12
|
-
} from './schema.task';
|
|
13
|
-
export type { SchemaEnv } from './schema-env';
|
|
14
|
-
export type { SchemaMain } from './schema.main.runtime';
|
|
15
|
-
export default SchemaAspect;
|
|
16
|
-
export { SchemaAspect };
|
package/parser.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Export } from '@teambit/semantics.entities.semantic-schema';
|
|
2
|
-
|
|
3
|
-
export interface Parser {
|
|
4
|
-
/**
|
|
5
|
-
* regex to apply on which components compiler applies.
|
|
6
|
-
*/
|
|
7
|
-
extension: RegExp;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* parse a module.
|
|
11
|
-
*/
|
|
12
|
-
parseModule(modulePath: string, content?: string): Export[];
|
|
13
|
-
}
|
package/schema-env.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { EnvHandler } from '@teambit/envs';
|
|
2
|
-
import { SchemaExtractor } from './schema-extractor';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* define a schema extractor to extract type information
|
|
6
|
-
* and docs for your components.
|
|
7
|
-
*/
|
|
8
|
-
export interface SchemaEnv {
|
|
9
|
-
schemaExtractor(): EnvHandler<SchemaExtractor>;
|
|
10
|
-
}
|
package/schema-extractor.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Component } from '@teambit/component';
|
|
2
|
-
import { APISchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
-
import { Formatter } from '@teambit/formatter';
|
|
4
|
-
|
|
5
|
-
export interface SchemaExtractor {
|
|
6
|
-
/**
|
|
7
|
-
* extract a semantic schema from a component.
|
|
8
|
-
*/
|
|
9
|
-
extract(component: Component, options?: SchemaExtractorOptions): Promise<APISchema>;
|
|
10
|
-
/**
|
|
11
|
-
* release resources if no schemas are needed for this process.
|
|
12
|
-
* for typescript, this will kill the tsserver process.
|
|
13
|
-
* for performance reasons, this is not automatically run after "extract". otherwise, running extract on multiple
|
|
14
|
-
* components will be very slow.
|
|
15
|
-
*/
|
|
16
|
-
dispose(): void;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type SchemaExtractorOptions = {
|
|
20
|
-
formatter?: Formatter;
|
|
21
|
-
tsserverPath?: string;
|
|
22
|
-
contextPath?: string;
|
|
23
|
-
};
|
package/schema.aspect.ts
DELETED
package/schema.cmd.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
2
|
-
import { ComponentMain } from '@teambit/component';
|
|
3
|
-
import pMapSeries from 'p-map-series';
|
|
4
|
-
import { Logger } from '@teambit/logger';
|
|
5
|
-
import { APISchema } from '@teambit/semantics.entities.semantic-schema';
|
|
6
|
-
import { PATTERN_HELP } from '@teambit/legacy/dist/constants';
|
|
7
|
-
import type { SchemaMain } from './schema.main.runtime';
|
|
8
|
-
|
|
9
|
-
export class SchemaCommand implements Command {
|
|
10
|
-
name = 'schema <pattern>';
|
|
11
|
-
description = 'shows the API schema of the specified component/s.';
|
|
12
|
-
extendedDescription = `${PATTERN_HELP('schema')}`;
|
|
13
|
-
group = 'development';
|
|
14
|
-
options = [['j', 'json', 'return the component schema in json format']] as CommandOptions;
|
|
15
|
-
|
|
16
|
-
constructor(private schema: SchemaMain, private component: ComponentMain, private logger: Logger) {}
|
|
17
|
-
|
|
18
|
-
async report([pattern]: [string]) {
|
|
19
|
-
const schemas = await this.getSchemas([pattern]);
|
|
20
|
-
return schemas.map((schema) => schema.toStringPerType()).join('\n\n\n');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async json([pattern]: [string]): Promise<Record<string, any>> {
|
|
24
|
-
const schemas = await this.getSchemas([pattern]);
|
|
25
|
-
return schemas.map((schema) => schema.toObject());
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
private async getSchemas([pattern]: [string]): Promise<APISchema[]> {
|
|
29
|
-
const host = this.component.getHost();
|
|
30
|
-
const ids = await host.idsByPattern(pattern, true);
|
|
31
|
-
const components = await host.getMany(ids);
|
|
32
|
-
const longRunningLog = this.logger.createLongProcessLogger('generating schema', ids.length);
|
|
33
|
-
const results = await pMapSeries(components, (component) => {
|
|
34
|
-
longRunningLog.logProgress(component.id.toString());
|
|
35
|
-
return this.schema.getSchema(component, undefined, true);
|
|
36
|
-
});
|
|
37
|
-
longRunningLog.end();
|
|
38
|
-
return results;
|
|
39
|
-
}
|
|
40
|
-
}
|
package/schema.graphql.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { ComponentFactory } from '@teambit/component';
|
|
2
|
-
import { GraphQLJSONObject } from 'graphql-type-json';
|
|
3
|
-
import gql from 'graphql-tag';
|
|
4
|
-
import { APISchema, UnImplementedSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
5
|
-
import { Schema } from '@teambit/graphql';
|
|
6
|
-
import { SchemaMain } from './schema.main.runtime';
|
|
7
|
-
|
|
8
|
-
export function schemaSchema(schema: SchemaMain): Schema {
|
|
9
|
-
return {
|
|
10
|
-
typeDefs: gql`
|
|
11
|
-
scalar JSONObject
|
|
12
|
-
extend type ComponentHost {
|
|
13
|
-
getSchema(id: String!): JSONObject
|
|
14
|
-
}
|
|
15
|
-
`,
|
|
16
|
-
resolvers: {
|
|
17
|
-
JSONObject: GraphQLJSONObject,
|
|
18
|
-
ComponentHost: {
|
|
19
|
-
getSchema: async (host: ComponentFactory, { id }: { id: string }) => {
|
|
20
|
-
const componentId = await host.resolveComponentId(id);
|
|
21
|
-
const component = await host.get(componentId);
|
|
22
|
-
const empty = {
|
|
23
|
-
exports: [],
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
if (!component) return empty;
|
|
27
|
-
const api = await schema.getSchema(component);
|
|
28
|
-
if (!api) return empty;
|
|
29
|
-
|
|
30
|
-
return filterUnimplementedSchemaNodes(api);
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function filterUnimplementedSchemaNodes(api: APISchema) {
|
|
38
|
-
const apiObject = api.toObject();
|
|
39
|
-
const filteredExports = apiObject.module.exports.filter((exp) => exp.__schema !== UnImplementedSchema.name);
|
|
40
|
-
const filteredInternals = apiObject.internals.map((internalObject) => {
|
|
41
|
-
const filteredInternalExports = internalObject.exports.filter((exp) => exp.__schema !== UnImplementedSchema.name);
|
|
42
|
-
const filteredInternalNodes = internalObject.internals.filter((exp) => exp.__schema !== UnImplementedSchema.name);
|
|
43
|
-
return {
|
|
44
|
-
...internalObject,
|
|
45
|
-
exports: filteredInternalExports,
|
|
46
|
-
internals: filteredInternalNodes,
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
const filteredTaggedExports = apiObject.taggedModuleExports.filter(
|
|
50
|
-
(exp) => exp.__schema !== UnImplementedSchema.name
|
|
51
|
-
);
|
|
52
|
-
return {
|
|
53
|
-
...apiObject,
|
|
54
|
-
exports: filteredExports,
|
|
55
|
-
internals: filteredInternals,
|
|
56
|
-
taggedModuleExports: filteredTaggedExports,
|
|
57
|
-
};
|
|
58
|
-
}
|
package/schema.main.runtime.ts
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { MainRuntime, CLIMain, CLIAspect } from '@teambit/cli';
|
|
2
|
-
import ComponentAspect, { Component, ComponentMain } from '@teambit/component';
|
|
3
|
-
import { Slot, SlotRegistry } from '@teambit/harmony';
|
|
4
|
-
import GraphqlAspect, { GraphqlMain } from '@teambit/graphql';
|
|
5
|
-
import { EnvsAspect, EnvsMain } from '@teambit/envs';
|
|
6
|
-
import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
|
|
7
|
-
import { PrettierConfigMutator } from '@teambit/defender.prettier.config-mutator';
|
|
8
|
-
import {
|
|
9
|
-
APISchema,
|
|
10
|
-
Export,
|
|
11
|
-
Schemas,
|
|
12
|
-
SchemaNodeConstructor,
|
|
13
|
-
SchemaRegistry,
|
|
14
|
-
} from '@teambit/semantics.entities.semantic-schema';
|
|
15
|
-
import { BuilderMain, BuilderAspect } from '@teambit/builder';
|
|
16
|
-
import { Workspace, WorkspaceAspect } from '@teambit/workspace';
|
|
17
|
-
import { Formatter } from '@teambit/formatter';
|
|
18
|
-
import { Parser } from './parser';
|
|
19
|
-
import { SchemaAspect } from './schema.aspect';
|
|
20
|
-
import { SchemaExtractor } from './schema-extractor';
|
|
21
|
-
import { SchemaCommand } from './schema.cmd';
|
|
22
|
-
import { schemaSchema } from './schema.graphql';
|
|
23
|
-
import { SchemaTask, SCHEMA_TASK_NAME } from './schema.task';
|
|
24
|
-
import { SchemaService } from './schema.service';
|
|
25
|
-
|
|
26
|
-
export type ParserSlot = SlotRegistry<Parser>;
|
|
27
|
-
|
|
28
|
-
export type SchemaConfig = {
|
|
29
|
-
/**
|
|
30
|
-
* default parser
|
|
31
|
-
*/
|
|
32
|
-
defaultParser: string;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* extension for extracting component schemas.
|
|
37
|
-
*/
|
|
38
|
-
export class SchemaMain {
|
|
39
|
-
constructor(
|
|
40
|
-
/**
|
|
41
|
-
* parsers slot.
|
|
42
|
-
*/
|
|
43
|
-
private parserSlot: ParserSlot,
|
|
44
|
-
|
|
45
|
-
private envs: EnvsMain,
|
|
46
|
-
|
|
47
|
-
private config: SchemaConfig,
|
|
48
|
-
|
|
49
|
-
private builder: BuilderMain,
|
|
50
|
-
|
|
51
|
-
private workspace: Workspace,
|
|
52
|
-
|
|
53
|
-
private logger: Logger
|
|
54
|
-
) {}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* get the default parser.
|
|
58
|
-
*/
|
|
59
|
-
getDefaultParser(): Parser {
|
|
60
|
-
return this.parserSlot.get(this.config.defaultParser) as Parser;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
registerSchemaClass(schema: SchemaNodeConstructor) {
|
|
64
|
-
SchemaRegistry.register(schema);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* parse a module into a component schema.
|
|
69
|
-
*/
|
|
70
|
-
parseModule(path: string, content?: string): Export[] {
|
|
71
|
-
const parsers = this.parserSlot.toArray();
|
|
72
|
-
let maybeParser = parsers.find(([, parser]) => {
|
|
73
|
-
const match = path.match(parser.extension);
|
|
74
|
-
return match;
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
if (!maybeParser) {
|
|
78
|
-
maybeParser = [this.config.defaultParser, this.getDefaultParser()];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const [, parser] = maybeParser;
|
|
82
|
-
return parser.parseModule(path, content);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
getSchemaExtractor(component: Component, tsserverPath?: string, contextPath?: string): SchemaExtractor {
|
|
86
|
-
const env = this.envs.getEnv(component).env;
|
|
87
|
-
if (typeof env.getSchemaExtractor === 'undefined') {
|
|
88
|
-
throw new Error(`No SchemaExtractor defined for ${env.name}`);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return env.getSchemaExtractor(undefined, tsserverPath, contextPath);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* get a schema of a component.
|
|
96
|
-
* @param component target component.
|
|
97
|
-
* @param shouldDisposeResourcesOnceDone for long-running processes, such as bit-start/bit-watch, this is not
|
|
98
|
-
* relevant. for calling the API only to get a schema for one component, this is needed to ensure the ts-server is
|
|
99
|
-
* not kept alive. otherwise, the process will never end.
|
|
100
|
-
*
|
|
101
|
-
*/
|
|
102
|
-
async getSchema(
|
|
103
|
-
component: Component,
|
|
104
|
-
shouldDisposeResourcesOnceDone = false,
|
|
105
|
-
alwaysRunExtractor = false,
|
|
106
|
-
tsserverPath?: string,
|
|
107
|
-
contextPath?: string
|
|
108
|
-
): Promise<APISchema> {
|
|
109
|
-
if (alwaysRunExtractor || this.workspace) {
|
|
110
|
-
const env = this.envs.getEnv(component).env;
|
|
111
|
-
// types need to be fixed
|
|
112
|
-
const formatter: Formatter | undefined = env.getFormatter?.(null, [
|
|
113
|
-
(config: PrettierConfigMutator) => {
|
|
114
|
-
config.setKey('parser', 'typescript');
|
|
115
|
-
return config;
|
|
116
|
-
},
|
|
117
|
-
]);
|
|
118
|
-
if (typeof env.getSchemaExtractor === 'undefined') {
|
|
119
|
-
throw new Error(`No SchemaExtractor defined for ${env.name}`);
|
|
120
|
-
}
|
|
121
|
-
const schemaExtractor: SchemaExtractor = env.getSchemaExtractor(undefined, tsserverPath, contextPath);
|
|
122
|
-
|
|
123
|
-
const result = await schemaExtractor.extract(component, { formatter, tsserverPath, contextPath });
|
|
124
|
-
if (shouldDisposeResourcesOnceDone) schemaExtractor.dispose();
|
|
125
|
-
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// on scope get schema from builder api
|
|
130
|
-
const schemaArtifact = await this.builder.getArtifactsVinylByAspectAndTaskName(
|
|
131
|
-
component,
|
|
132
|
-
SchemaAspect.id,
|
|
133
|
-
SCHEMA_TASK_NAME
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
if (schemaArtifact.length === 0) {
|
|
137
|
-
this.logger.debug(`no schema found for ${component.id.toString()}`);
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* return empty schema
|
|
141
|
-
* when tag/snap without build
|
|
142
|
-
* or backwards compatibility
|
|
143
|
-
*/
|
|
144
|
-
return APISchema.empty(component.id as any);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const schemaJsonStr = schemaArtifact[0].contents.toString('utf-8');
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
const schemaJson = JSON.parse(schemaJsonStr);
|
|
151
|
-
return this.getSchemaFromObject(schemaJson);
|
|
152
|
-
} catch (e) {
|
|
153
|
-
if (e instanceof SyntaxError) {
|
|
154
|
-
this.logger.error(e.message);
|
|
155
|
-
throw new Error(`Invalid schema.json for ${component.id}`);
|
|
156
|
-
}
|
|
157
|
-
throw e;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
getSchemaFromObject(obj: Record<string, any>): APISchema {
|
|
162
|
-
return APISchema.fromObject(obj);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* register a new parser.
|
|
167
|
-
*/
|
|
168
|
-
registerParser(parser: Parser): SchemaMain {
|
|
169
|
-
this.parserSlot.register(parser);
|
|
170
|
-
return this;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
static runtime = MainRuntime;
|
|
174
|
-
static dependencies = [
|
|
175
|
-
EnvsAspect,
|
|
176
|
-
CLIAspect,
|
|
177
|
-
ComponentAspect,
|
|
178
|
-
GraphqlAspect,
|
|
179
|
-
LoggerAspect,
|
|
180
|
-
BuilderAspect,
|
|
181
|
-
WorkspaceAspect,
|
|
182
|
-
];
|
|
183
|
-
static slots = [Slot.withType<Parser>()];
|
|
184
|
-
|
|
185
|
-
static defaultConfig = {
|
|
186
|
-
defaultParser: 'teambit.typescript/typescript',
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
static async provider(
|
|
190
|
-
[envs, cli, component, graphql, loggerMain, builder, workspace]: [
|
|
191
|
-
EnvsMain,
|
|
192
|
-
CLIMain,
|
|
193
|
-
ComponentMain,
|
|
194
|
-
GraphqlMain,
|
|
195
|
-
LoggerMain,
|
|
196
|
-
BuilderMain,
|
|
197
|
-
Workspace
|
|
198
|
-
],
|
|
199
|
-
config: SchemaConfig,
|
|
200
|
-
[parserSlot]: [ParserSlot]
|
|
201
|
-
) {
|
|
202
|
-
const logger = loggerMain.createLogger(SchemaAspect.id);
|
|
203
|
-
const schema = new SchemaMain(parserSlot, envs, config, builder, workspace, logger);
|
|
204
|
-
const schemaTask = new SchemaTask(SchemaAspect.id, schema, logger);
|
|
205
|
-
builder.registerBuildTasks([schemaTask]);
|
|
206
|
-
cli.register(new SchemaCommand(schema, component, logger));
|
|
207
|
-
graphql.register(schemaSchema(schema));
|
|
208
|
-
envs.registerService(new SchemaService());
|
|
209
|
-
|
|
210
|
-
// register all default schema classes
|
|
211
|
-
Object.values(Schemas).forEach((Schema) => {
|
|
212
|
-
schema.registerSchemaClass(Schema);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
return schema;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
SchemaAspect.addRuntime(SchemaMain);
|
|
220
|
-
|
|
221
|
-
export default SchemaMain;
|
package/schema.service.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { EnvService, ExecutionContext, Env, EnvContext, ServiceTransformationMap } from '@teambit/envs';
|
|
2
|
-
import { SchemaExtractor } from './schema-extractor';
|
|
3
|
-
// import { APISchema } from './schema';
|
|
4
|
-
|
|
5
|
-
type SchemaTransformationMap = ServiceTransformationMap & {
|
|
6
|
-
getSchemaExtractor: () => SchemaExtractor;
|
|
7
|
-
};
|
|
8
|
-
export class SchemaService implements EnvService<{}> {
|
|
9
|
-
name = 'schema';
|
|
10
|
-
|
|
11
|
-
async run(context: ExecutionContext) {
|
|
12
|
-
return { errors: [], context };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
transform(env: Env, context: EnvContext): SchemaTransformationMap | undefined {
|
|
16
|
-
// Old env
|
|
17
|
-
if (!env?.schemaExtractor) return undefined;
|
|
18
|
-
return {
|
|
19
|
-
getSchemaExtractor: () => env.schemaExtractor()(context),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}
|
package/schema.spec.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import { APISchema, UnknownSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
4
|
-
import TrackerAspect, { TrackerMain } from '@teambit/tracker';
|
|
5
|
-
import { loadAspect, loadManyAspects } from '@teambit/harmony.testing.load-aspect';
|
|
6
|
-
import { mockWorkspace, destroyWorkspace, WorkspaceData } from '@teambit/workspace.testing.mock-workspace';
|
|
7
|
-
import { ComponentID } from '@teambit/component-id';
|
|
8
|
-
import WorkspaceAspect, { Workspace } from '@teambit/workspace';
|
|
9
|
-
import { SchemaMain } from './schema.main.runtime';
|
|
10
|
-
import { SchemaAspect } from '.';
|
|
11
|
-
|
|
12
|
-
describe('SchemaAspect', function () {
|
|
13
|
-
let schema: SchemaMain;
|
|
14
|
-
let workspace: Workspace;
|
|
15
|
-
let workspaceData: WorkspaceData;
|
|
16
|
-
beforeAll(async () => {
|
|
17
|
-
workspaceData = mockWorkspace();
|
|
18
|
-
const { workspacePath } = workspaceData;
|
|
19
|
-
// eslint-disable-next-line no-console
|
|
20
|
-
console.log('workspace created at ', workspacePath);
|
|
21
|
-
schema = await loadAspect(SchemaAspect, workspacePath);
|
|
22
|
-
}, 30000);
|
|
23
|
-
afterAll(async () => {
|
|
24
|
-
await destroyWorkspace(workspaceData);
|
|
25
|
-
});
|
|
26
|
-
describe('getSchema()', () => {
|
|
27
|
-
let apiSchema: APISchema;
|
|
28
|
-
beforeAll(async () => {
|
|
29
|
-
const { workspacePath } = workspaceData;
|
|
30
|
-
const compDir = path.join(workspacePath, 'button');
|
|
31
|
-
const src = path.join(getMockDir(), 'button');
|
|
32
|
-
await fs.copy(src, compDir);
|
|
33
|
-
const harmony = await loadManyAspects([WorkspaceAspect, SchemaAspect, TrackerAspect], workspacePath);
|
|
34
|
-
workspace = harmony.get<Workspace>(WorkspaceAspect.id);
|
|
35
|
-
const tracker = harmony.get<TrackerMain>(TrackerAspect.id);
|
|
36
|
-
await tracker.track({ rootDir: compDir, defaultScope: 'org.scope' });
|
|
37
|
-
await workspace.bitMap.write();
|
|
38
|
-
schema = harmony.get<SchemaMain>(SchemaAspect.id);
|
|
39
|
-
const compId = await workspace.resolveComponentId('button');
|
|
40
|
-
const comp = await workspace.get(compId);
|
|
41
|
-
apiSchema = await schema.getSchema(comp, true);
|
|
42
|
-
}, 30000);
|
|
43
|
-
it('should be able to generate JSON object with all schemas', async () => {
|
|
44
|
-
const results = apiSchema.toObject();
|
|
45
|
-
const expectedJsonPath = path.join(getMockDir(), 'button-schemas.json');
|
|
46
|
-
// uncomment the next line temporarily to sync the expected json with new schema changes
|
|
47
|
-
// fs.outputFileSync(expectedJsonPath, JSON.stringify(results, undefined, 2));
|
|
48
|
-
const expectedJson = fs.readJsonSync(expectedJsonPath);
|
|
49
|
-
// @ts-ignore it exists on Jest. for some reason ts assumes this is Jasmine.
|
|
50
|
-
expect(results).toMatchObject(expectedJson);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
describe('getSchemaFromObject', () => {
|
|
54
|
-
it('should be able to deserialize an JSON object to SchemaNode instances', () => {
|
|
55
|
-
const jsonPath = path.join(getMockDir(), 'button-schemas.json');
|
|
56
|
-
const json = fs.readJsonSync(jsonPath);
|
|
57
|
-
const apiSchema = schema.getSchemaFromObject(json);
|
|
58
|
-
expect(apiSchema instanceof APISchema).toEqual(true);
|
|
59
|
-
expect(apiSchema.componentId.constructor.name).toEqual(ComponentID.name);
|
|
60
|
-
// @ts-ignore it exists on Jest. for some reason ts assumes this is Jasmine.
|
|
61
|
-
expect(apiSchema.toObject()).toMatchObject(json);
|
|
62
|
-
});
|
|
63
|
-
it('should not throw when it does not recognize the schema', () => {
|
|
64
|
-
const jsonPath = path.join(getMockDir(), 'button-old-schema.json');
|
|
65
|
-
const json = fs.readJsonSync(jsonPath);
|
|
66
|
-
const apiSchema = schema.getSchemaFromObject(json);
|
|
67
|
-
expect(apiSchema instanceof APISchema).toEqual(true);
|
|
68
|
-
expect(apiSchema.module.exports[0] instanceof UnknownSchema).toEqual(true);
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
expect(apiSchema.module.exports[0].location).toMatchObject({ file: 'index.ts', line: 21, character: 14 });
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
function getCurrentDir() {
|
|
76
|
-
const currentDir = __dirname;
|
|
77
|
-
if (currentDir.endsWith(`${path.sep}dist`)) return currentDir.slice(0, -5);
|
|
78
|
-
return currentDir;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function getMockDir() {
|
|
82
|
-
return path.join(getCurrentDir(), 'mock');
|
|
83
|
-
}
|
package/schema.task.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BuildContext,
|
|
3
|
-
BuiltTaskResult,
|
|
4
|
-
BuildTask,
|
|
5
|
-
TaskLocation,
|
|
6
|
-
CAPSULE_ARTIFACTS_DIR,
|
|
7
|
-
ComponentResult,
|
|
8
|
-
ArtifactDefinition,
|
|
9
|
-
} from '@teambit/builder';
|
|
10
|
-
import { Logger } from '@teambit/logger';
|
|
11
|
-
import fs from 'fs-extra';
|
|
12
|
-
import pMapSeries from 'p-map-series';
|
|
13
|
-
import { join } from 'path';
|
|
14
|
-
import { SchemaMain } from './schema.main.runtime';
|
|
15
|
-
|
|
16
|
-
export const SCHEMA_TASK_NAME = 'ExtractSchema';
|
|
17
|
-
export const SCHEMA_ARTIFACT_NAME = 'schema';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* extract and persist the component schema as a json file
|
|
21
|
-
*/
|
|
22
|
-
export class SchemaTask implements BuildTask {
|
|
23
|
-
readonly name = SCHEMA_TASK_NAME;
|
|
24
|
-
readonly location: TaskLocation = 'end';
|
|
25
|
-
readonly description = 'extract api schema for a set of components';
|
|
26
|
-
|
|
27
|
-
constructor(readonly aspectId: string, private schema: SchemaMain, private logger: Logger) {}
|
|
28
|
-
|
|
29
|
-
async execute(context: BuildContext): Promise<BuiltTaskResult> {
|
|
30
|
-
const startTime = Date.now();
|
|
31
|
-
const capsules = context.capsuleNetwork.seedersCapsules;
|
|
32
|
-
const schemaResult: ComponentResult[] = [];
|
|
33
|
-
const rootDir = context.capsuleNetwork.capsulesRootDir;
|
|
34
|
-
await pMapSeries(capsules, async (capsule) => {
|
|
35
|
-
const component = capsule.component;
|
|
36
|
-
try {
|
|
37
|
-
const schema = await this.schema.getSchema(component, false, true, rootDir, capsule.path);
|
|
38
|
-
const schemaObj = schema.toObject();
|
|
39
|
-
await fs.outputFile(join(capsule.path, getSchemaArtifactPath()), JSON.stringify(schemaObj, null, 2));
|
|
40
|
-
schemaResult.push({
|
|
41
|
-
component,
|
|
42
|
-
startTime,
|
|
43
|
-
endTime: Date.now(),
|
|
44
|
-
});
|
|
45
|
-
} catch (e) {
|
|
46
|
-
this.logger.warn(`failed extracting schema for ${component.id.toString()}`);
|
|
47
|
-
/**
|
|
48
|
-
* @todo once schema extractor is more stable change this to an error
|
|
49
|
-
*/
|
|
50
|
-
if (e instanceof Error) {
|
|
51
|
-
schemaResult.push({
|
|
52
|
-
component,
|
|
53
|
-
startTime,
|
|
54
|
-
endTime: Date.now(),
|
|
55
|
-
warnings: [e.message],
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
return {
|
|
61
|
-
artifacts: [getSchemaArtifactDef()],
|
|
62
|
-
componentsResults: schemaResult,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function getSchemaArtifactPath() {
|
|
68
|
-
return join(CAPSULE_ARTIFACTS_DIR, 'schema.json');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function getSchemaArtifactDef() {
|
|
72
|
-
const def: ArtifactDefinition = {
|
|
73
|
-
name: SCHEMA_ARTIFACT_NAME,
|
|
74
|
-
rootDir: CAPSULE_ARTIFACTS_DIR,
|
|
75
|
-
globPatterns: ['schema.json'],
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
return def;
|
|
79
|
-
}
|