From 265af782a35547f62e9a42dd138e81180d4b69e5 Mon Sep 17 00:00:00 2001 From: Like Zhu Date: Thu, 29 Jul 2021 11:54:36 -0700 Subject: [PATCH] Add parentKeySelector --- .../src/templates/calls/action-spec.ejs | 4 +--- .../src/templates/calls/func-spec.ejs | 1 + .../src/templates/coll/add-spec.ejs | 1 + .../src/templates/coll/destroy-spec.ejs | 1 + .../src/templates/coll/fetch-spec.ejs | 1 + .../src/templates/coll/mutation-spec.ejs | 1 + .../src/templates/entity/destroy-spec.ejs | 1 + .../src/templates/entity/fetch-spec.ejs | 1 + .../src/templates/entity/mutation-spec.ejs | 1 + packages/generator-overreact-odata/src/writers/calls.js | 5 +++++ packages/generator-overreact-odata/src/writers/coll.js | 5 +++++ packages/generator-overreact-odata/src/writers/entity.js | 5 +++++ 12 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/generator-overreact-odata/src/templates/calls/action-spec.ejs b/packages/generator-overreact-odata/src/templates/calls/action-spec.ejs index 645f370..710c809 100644 --- a/packages/generator-overreact-odata/src/templates/calls/action-spec.ejs +++ b/packages/generator-overreact-odata/src/templates/calls/action-spec.ejs @@ -61,9 +61,7 @@ const requestContract = createRequestContract({ uriFactoryFn: urlDecorator(odataUrlFactory), headerFactoryFn: headerDecorator(odataHeaderFactory), payloadFactoryFn: payloadDecorator(odataPayloadFactory), - - // TODO: figure out how to do parentKey - parentKeySelector: variables => variables.locator.descriptor.<%- parentKey %> + parentKeySelector: variables => variables.locator.descriptor.<%- parentKey %>, }); const responseContract = createResponseContract({ diff --git a/packages/generator-overreact-odata/src/templates/calls/func-spec.ejs b/packages/generator-overreact-odata/src/templates/calls/func-spec.ejs index 2ef65a8..7921857 100644 --- a/packages/generator-overreact-odata/src/templates/calls/func-spec.ejs +++ b/packages/generator-overreact-odata/src/templates/calls/func-spec.ejs @@ -54,6 +54,7 @@ const requestContract = createRequestContract({ fetchPolicy: networkPolicy, uriFactoryFn: urlDecorator(odataUrlFactory), headerFactoryFn: headerDecorator(odataHeaderFactory), + parentKeySelector: variables => variables.locator.descriptor.<%- parentKey %>, }); const responseContract = createResponseContract({ diff --git a/packages/generator-overreact-odata/src/templates/coll/add-spec.ejs b/packages/generator-overreact-odata/src/templates/coll/add-spec.ejs index 4f4a1fa..60d73aa 100644 --- a/packages/generator-overreact-odata/src/templates/coll/add-spec.ejs +++ b/packages/generator-overreact-odata/src/templates/coll/add-spec.ejs @@ -61,6 +61,7 @@ const requestContract = createRequestContract({ uriFactoryFn: urlDecorator(odataUrlFactory), headerFactoryFn: headerDecorator(odataHeaderFactory), payloadFactoryFn: payloadDecorator(odataPayloadFactory), + parentKeySelector: variables => variables.locator.descriptor.<%- parentKey %>, }); const responseContract = createResponseContract({ diff --git a/packages/generator-overreact-odata/src/templates/coll/destroy-spec.ejs b/packages/generator-overreact-odata/src/templates/coll/destroy-spec.ejs index d206f49..7aeb419 100644 --- a/packages/generator-overreact-odata/src/templates/coll/destroy-spec.ejs +++ b/packages/generator-overreact-odata/src/templates/coll/destroy-spec.ejs @@ -54,6 +54,7 @@ const requestContract = createRequestContract({ fetchPolicy: networkPolicy, uriFactoryFn: urlDecorator(odataUrlFactory), headerFactoryFn: headerDecorator(odataHeaderFactory), + parentKeySelector: variables => variables.locator.descriptor.<%- parentKey %>, }); const responseContract = createResponseContract({ diff --git a/packages/generator-overreact-odata/src/templates/coll/fetch-spec.ejs b/packages/generator-overreact-odata/src/templates/coll/fetch-spec.ejs index cf8cd80..e5d2fe8 100644 --- a/packages/generator-overreact-odata/src/templates/coll/fetch-spec.ejs +++ b/packages/generator-overreact-odata/src/templates/coll/fetch-spec.ejs @@ -54,6 +54,7 @@ const requestContract = createRequestContract({ fetchPolicy: networkPolicy, uriFactoryFn: urlDecorator(odataUrlFactory), headerFactoryFn: headerDecorator(odataHeaderFactory), + parentKeySelector: variables => variables.locator.descriptor.<%- parentKey %>, }); const responseContract = createResponseContract({ diff --git a/packages/generator-overreact-odata/src/templates/coll/mutation-spec.ejs b/packages/generator-overreact-odata/src/templates/coll/mutation-spec.ejs index 47428ad..8d2a880 100644 --- a/packages/generator-overreact-odata/src/templates/coll/mutation-spec.ejs +++ b/packages/generator-overreact-odata/src/templates/coll/mutation-spec.ejs @@ -61,6 +61,7 @@ const requestContract = createRequestContract({ uriFactoryFn: urlDecorator(odataUrlFactory), headerFactoryFn: headerDecorator(odataHeaderFactory), payloadFactoryFn: payloadDecorator(odataPayloadFactory), + parentKeySelector: variables => variables.locator.descriptor.<%- parentKey %>, }); const responseContract = createResponseContract({ diff --git a/packages/generator-overreact-odata/src/templates/entity/destroy-spec.ejs b/packages/generator-overreact-odata/src/templates/entity/destroy-spec.ejs index 37dcca1..6441408 100644 --- a/packages/generator-overreact-odata/src/templates/entity/destroy-spec.ejs +++ b/packages/generator-overreact-odata/src/templates/entity/destroy-spec.ejs @@ -54,6 +54,7 @@ const requestContract = createRequestContract({ fetchPolicy: networkPolicy, uriFactoryFn: urlDecorator(odataUrlFactory), headerFactoryFn: headerDecorator(odataHeaderFactory), + parentKeySelector: variables => variables.locator.descriptor.<%- parentKey %>, }); const responseContract = createResponseContract({ diff --git a/packages/generator-overreact-odata/src/templates/entity/fetch-spec.ejs b/packages/generator-overreact-odata/src/templates/entity/fetch-spec.ejs index fd450cd..d617e56 100644 --- a/packages/generator-overreact-odata/src/templates/entity/fetch-spec.ejs +++ b/packages/generator-overreact-odata/src/templates/entity/fetch-spec.ejs @@ -61,6 +61,7 @@ const responseContract = createResponseContract({ responseType: responseTypes.ENTITY, keySelector: keySelectorDecorator(r => r.<%= key %>), processorFn: processorDecorator(r => r), + parentKeySelector: variables => variables.locator.descriptor.<%- parentKey %>, }); export const fetchSpec = createSpec( diff --git a/packages/generator-overreact-odata/src/templates/entity/mutation-spec.ejs b/packages/generator-overreact-odata/src/templates/entity/mutation-spec.ejs index 8f705cc..b91be32 100644 --- a/packages/generator-overreact-odata/src/templates/entity/mutation-spec.ejs +++ b/packages/generator-overreact-odata/src/templates/entity/mutation-spec.ejs @@ -61,6 +61,7 @@ const requestContract = createRequestContract({ uriFactoryFn: urlDecorator(odataUrlFactory), headerFactoryFn: headerDecorator(odataHeaderFactory), payloadFactoryFn: payloadDecorator(odataPayloadFactory), + parentKeySelector: variables => variables.locator.descriptor.<%- parentKey %>, }); const responseContract = createResponseContract({ diff --git a/packages/generator-overreact-odata/src/writers/calls.js b/packages/generator-overreact-odata/src/writers/calls.js index 7adc37c..6b3eb57 100644 --- a/packages/generator-overreact-odata/src/writers/calls.js +++ b/packages/generator-overreact-odata/src/writers/calls.js @@ -26,6 +26,10 @@ function composeSharedContext(metadata, scope, aliasHashMap) { const odataUriSegments = odataCallUriFactory(visitedSchemas, rootSchema, aliasHashMap, isColl); const descriptorList = generateDescriptorList(visitedSchemas, aliasHashMap, isColl); + // note that for action/function, the "parent" is the _last_ + // element of the descriptor list + const parentKey = descriptorList[descriptorList.length - 1]; + const { ReturnType } = rootSchema.schema; let responseType = 'responseTypes.ENTITY'; let key = 'r => r'; @@ -62,6 +66,7 @@ function composeSharedContext(metadata, scope, aliasHashMap) { key, responseType, processor, + parentKey, }; } diff --git a/packages/generator-overreact-odata/src/writers/coll.js b/packages/generator-overreact-odata/src/writers/coll.js index e40e2b2..62752d7 100644 --- a/packages/generator-overreact-odata/src/writers/coll.js +++ b/packages/generator-overreact-odata/src/writers/coll.js @@ -23,6 +23,10 @@ function composeSharedContext(metadata, scope, aliasHashMap) { const descriptorList = generateDescriptorList(visitedSchemas, aliasHashMap, true); const { $$ODataExtension } = rootSchema.schema; + const parentKey = descriptorList.length > 1 + ? descriptorList[descriptorList.length - 2] + : descriptorList[0]; + return { edmLocation, envLocation, @@ -30,6 +34,7 @@ function composeSharedContext(metadata, scope, aliasHashMap) { descriptorList, odataUriSegments, key: $$ODataExtension.Key[0], + parentKey, }; } diff --git a/packages/generator-overreact-odata/src/writers/entity.js b/packages/generator-overreact-odata/src/writers/entity.js index 7948772..2681b29 100644 --- a/packages/generator-overreact-odata/src/writers/entity.js +++ b/packages/generator-overreact-odata/src/writers/entity.js @@ -23,6 +23,10 @@ function composeSharedContext(metadata, scope, aliasHashMap) { const descriptorList = generateDescriptorList(visitedSchemas, aliasHashMap, false); const { $$ODataExtension } = rootSchema.schema; + const parentKey = descriptorList.length > 1 + ? descriptorList[descriptorList.length - 2] + : descriptorList[0]; + return { edmLocation, envLocation, @@ -30,6 +34,7 @@ function composeSharedContext(metadata, scope, aliasHashMap) { descriptorList, odataUriSegments, key: $$ODataExtension.Key[0], + parentKey, }; }