{"id":302153,"date":"2020-04-19T21:00:30","date_gmt":"2020-04-19T21:00:30","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=302153"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=302153","title":{"rendered":"OData babel \u043f\u043b\u0430\u0433\u0438\u043d"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/497928\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/5h\/8q\/ue\/5h8quezts1sv-yo9wy9ptuva-l0.png\"><br \/>  \u0421\u0442\u0430\u0442\u044c\u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u044e \u043a\u043e\u0434\u0430 TypeScript \u0432 OData \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<br \/>  \u041f\u043b\u0430\u0433\u0438\u043d <a href=\"https:\/\/github.com\/voronov-maxim\/TsToOdata\/tree\/master\/babel-plugin-ts2odata\" rel=\"nofollow\">babel-plugin-ts2odata<\/a> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0430\u0437\u0431\u043e\u0440 JavaScript AST \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/github.com\/voronov-maxim\/TsToOdata\" rel=\"nofollow\">TsToOdata<\/a> \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432 \u043c\u043e\u0435\u0439 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/489122\/\">\u0422\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b OData \u0432 TypeScript<\/a>.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u043c \u043f\u0435\u0440\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 TsToOdata \u044f\u0432\u043b\u044f\u043b\u043e\u0441\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043d\u0430 \u043f\u0430\u043a\u0435\u0442\u044b <a href=\"https:\/\/habr.com\/ru\/users\/babel\/\" class=\"user_link\">babel<\/a>\/parser, <a href=\"https:\/\/habr.com\/ru\/users\/babel\/\" class=\"user_link\">babel<\/a>\/traverse, \u0440\u0430\u0437\u0431\u043e\u0440 JavaScript \u043a\u043e\u0434\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u0436\u0435 \u0431\u044b\u043b\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u0430\u0442\u0440\u0430\u0442\u043d\u044b\u043c. \u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u0440\u0430\u0437\u0431\u043e\u0440 \u043a\u043e\u0434\u0430 \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u044b \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/github.com\/voronov-maxim\/TsToOdata\/tree\/master\/ts2odata-babel\" rel=\"nofollow\">ts2odata-babel<\/a>. \u0414\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442 ts2odata \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 devDependencies \u043d\u0430 ts2odata-babel \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0430 \u0434\u043b\u044f \u0440\u0435\u043b\u0438\u0437\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0431\u043e\u0440\u043a\u0443 \u0441 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043b\u0430\u0433\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u0432 \u0432\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043e\u0441\u0442\u0430\u043d\u0443\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430 \u043f\u0430\u043a\u0435\u0442\u044b ts2odata \u0438 <a href=\"https:\/\/github.com\/lquixada\/cross-fetch\" rel=\"nofollow\">cross-fetch<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">npm install --save-dev @babel\/core @babel\/cli npm install ts2odata npm install --save-dev babel-plugin-ts2odata<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u043e\u0440\u0435\u043d\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0444\u0430\u0439\u043b babel.config.js:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">module.exports = {     plugins: [         [             'babel-plugin-ts2odata',             {                 odataNamespace: 'OdataToEntity.Test.Model'             }         ]     ] };<\/code><\/pre>\n<p>  <\/p>\n<p>\u043a\u043b\u044e\u0447 odataNamespace \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0435\u0441\u043b\u0438 \u0432\u0430\u0448 OData \u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d (Namespace).<\/p>\n<p>  <\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0441\u0435\u043a\u0446\u0438\u044e scripts \u0444\u0430\u0439\u043b\u0430 package.json:<\/p>\n<p>  <\/p>\n<pre><code class=\"json\">&quot;build&quot;: &quot;tsc --build &amp;&amp; npx babel .\/source --out-dir .\/lib&quot;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0433\u0434\u0435 source \u043f\u0430\u043f\u043a\u0430 \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c TypeScript, lib \u043f\u0430\u043f\u043a\u0430 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u043c \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u043c JavaScript \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434 \u043d\u0430 TypeScript:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">let price = 2.1; let orders = context.Orders.filter(o =&gt; o.Items.every(i =&gt; i.Price &gt;= price), { price })     .select(i =&gt; { return { orderYear: i.Date.getFullYear() } }).toArrayAsync();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">let price = 2.1; let orders = context.Orders.filter(&quot;Items\/all(d:d\/Price ge {price})&quot;, {   price }).select(&quot;[{\\&quot;expression\\&quot;:\\&quot;year(Date)\\&quot;,\\&quot;alias\\&quot;:\\&quot;orderYear\\&quot;,\\&quot;kind\\&quot;:1}]&quot;).toArrayAsync();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0432\u044b\u0448\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f OData \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">http:\/\/localhost:5000\/Orders?$filter=Items\/all(d:d\/Price+ge+2.1)&amp;$compute=year(Date)+as+orderYear<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/voronov-maxim\/TsToOdata\/tree\/master\/babel-plugin-ts2odata\/test\/fixtures\/test1\" rel=\"nofollow\">\u043f\u0430\u043f\u043a\u0435 \u0441 \u0442\u0435\u0441\u0442\u0430\u043c\u0438<\/a>, \u0433\u0434\u0435 \u0444\u0430\u0439\u043b <a href=\"https:\/\/github.com\/voronov-maxim\/TsToOdata\/blob\/master\/babel-plugin-ts2odata\/test\/fixtures\/test1\/code.js\" rel=\"nofollow\">code.js<\/a> \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0444\u0430\u0439\u043b\u0430 <a href=\"https:\/\/github.com\/voronov-maxim\/TsToOdata\/blob\/master\/ts2odata\/test\/QueryTests.ts\" rel=\"nofollow\">QueryTests.ts<\/a>, \u0430 \u0444\u0430\u0439\u043b <a href=\"https:\/\/github.com\/voronov-maxim\/TsToOdata\/blob\/master\/babel-plugin-ts2odata\/test\/fixtures\/test1\/output.js\" rel=\"nofollow\">output.js<\/a> \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043b\u0430\u0433\u0438\u043d\u0430.<br \/>  \u0420\u0430\u0431\u043e\u0442\u0430 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u0431\u044b\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u0430 \u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 vue.js.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 TypeScript, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u0435\u043b\u0435\u043d \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f\u043c \u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c \u043a \u043a\u043e\u0434\u0443, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0447\u0442\u043e-\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0449\u0435 \u0438\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/497928\/\"> https:\/\/habr.com\/ru\/post\/497928\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/497928\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/5h\/8q\/ue\/5h8quezts1sv-yo9wy9ptuva-l0.png\"><br \/>  \u0421\u0442\u0430\u0442\u044c\u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u044e \u043a\u043e\u0434\u0430 TypeScript \u0432 OData \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<br \/>  \u041f\u043b\u0430\u0433\u0438\u043d <a href=\"https:\/\/github.com\/voronov-maxim\/TsToOdata\/tree\/master\/babel-plugin-ts2odata\" rel=\"nofollow\">babel-plugin-ts2odata<\/a> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0430\u0437\u0431\u043e\u0440 JavaScript AST \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/github.com\/voronov-maxim\/TsToOdata\" rel=\"nofollow\">TsToOdata<\/a> \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432 \u043c\u043e\u0435\u0439 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/489122\/\">\u0422\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b OData \u0432 TypeScript<\/a>.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-302153","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/302153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=302153"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/302153\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=302153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=302153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=302153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}