Skip to content

Commit

Permalink
[cascading] from release/10.2 to release/10.3.0-rc (#1795)
Browse files Browse the repository at this point in the history
<!--
{"currentBranch":"release/10.2","targetBranch":"release/10.3.0-rc","bypassReviewers":true,"isConflicting":false}
-->

## Cascading from release/10.2 to release/10.3.0-rc


The configuration requests the cascading to bypass reviewer in case of
CI success.
To not bypass the reviewing process, please check the following
checkbox:

- [ ] <!-- !cancel bypass! --> 🚫 stop reviewing process
bypass for this Pull Request




---

<small>This Pull Request has been generated with ❤️ by the
[Otter](https://github.com/AmadeusITGroup/otter) cascading tool.</small>
  • Loading branch information
matthieu-crouzet committed May 17, 2024
2 parents 813293f + 397dcbd commit 4f0022e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
16 changes: 10 additions & 6 deletions packages/@o3r/core/schematics/service/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { strings } from '@angular-devkit/core';
import { apply, chain, MergeStrategy, mergeWith, move, noop, renameTemplateFiles, Rule, SchematicContext, template, Tree, url } from '@angular-devkit/schematics';
import { applyEsLintFix, createSchematicWithMetricsIfInstalled, getDestinationPath, getTestFramework, getWorkspaceConfig, moduleHasSubEntryPoints, writeSubEntryPointPackageJson } from '@o3r/schematics';
import { applyEsLintFix, createSchematicWithMetricsIfInstalled, getDestinationPath, getTestFramework, getWorkspaceConfig, moduleHasSubEntryPoints, O3rCliError, writeSubEntryPointPackageJson } from '@o3r/schematics';
import * as path from 'node:path';
import { NgGenerateServiceSchematicsSchema } from './schema';

Expand All @@ -9,7 +9,6 @@ import { NgGenerateServiceSchematicsSchema } from './schema';
* @param options
*/
function ngGenerateServiceFn(options: NgGenerateServiceSchematicsSchema): Rule {

const generateFiles: Rule = (tree: Tree, context: SchematicContext) => {
const destination = getDestinationPath('@o3r/core:service', options.path, tree, options.projectName);

Expand Down Expand Up @@ -45,11 +44,16 @@ function ngGenerateServiceFn(options: NgGenerateServiceSchematicsSchema): Rule {
const workspaceConfig = getWorkspaceConfig(tree);
let packageName = destination;
if (workspaceProject?.projectType !== 'application') {
let rec = '..';
while (!tree.exists(path.resolve(destination, rec, 'package.json')) && path.resolve(destination, rec) !== '/') {
rec = path.join('..', rec);
let currentDirectory = path.normalize(destination);
const parent = '..';
// Find the package.json file in the project directory
while (!currentDirectory.includes(parent) && !tree.exists(path.join(currentDirectory, 'package.json'))) {
currentDirectory = path.join(currentDirectory, parent);
}
if (currentDirectory.includes(parent)) {
throw new O3rCliError('Could not find package.json in the project directory.');
}
packageName = JSON.parse(tree.read(path.resolve(destination, rec, 'package.json'))!.toString()).name?.split('/')[0] || destination;
packageName = JSON.parse(tree.read(path.join(currentDirectory, 'package.json'))!.toString()).name?.split('/')[0] || destination;
}

const templateData = {
Expand Down
15 changes: 9 additions & 6 deletions packages/@o3r/core/src/store/async/async.operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { catchError, delay, filter, finalize, pairwise, startWith, switchMap, ta
import { isIdentifiedCallAction } from './async.helpers';
import { AsyncRequest, ExtractFromApiActionPayloadType, FromApiActionPayload } from './async.interfaces';

/**
* Determine if the given parameter is a Promise
* @param object
*/
const isPromise = <U>(object: U | Promise<U>): object is Promise<U> => object && typeof object === 'object' && typeof (object as any).then !== 'undefined';

/**
* Custom operator to use instead of SwitchMap with effects based on FromApi actions.
Expand All @@ -14,7 +19,7 @@ import { AsyncRequest, ExtractFromApiActionPayloadType, FromApiActionPayload } f
*/
// eslint-disable-next-line @typescript-eslint/ban-types
export function fromApiEffectSwitchMap<T extends FromApiActionPayload<any>, S extends ExtractFromApiActionPayloadType<T>, U extends Action, V extends Action, W extends Action>(
successHandler: (result: S, action: T) => U | Observable<U> | Promise<Observable<U> | U>,
successHandler: (result: S, action: T) => U | Observable<U> | Promise<U>,
errorHandler?: (error: any, action: T) => Observable<V>,
cancelRequestActionFactory?: (props: AsyncRequest, action: T) => W): OperatorFunction<T, U | V | W> {

Expand All @@ -41,10 +46,8 @@ export function fromApiEffectSwitchMap<T extends FromApiActionPayload<any>, S ex
return from(action.call).pipe(
tap(cleanStack),
switchMap((result) => {
const sucessPromise = Promise.resolve(successHandler(result, action));
return from(sucessPromise).pipe(
switchMap((success) => isObservable(success) ? success : of(success))
);
const success = successHandler(result, action);
return isObservable(success) ? success : (isPromise(success) ? success : of(success));
}),
catchError((error) => {
cleanStack();
Expand All @@ -67,7 +70,7 @@ export function fromApiEffectSwitchMapById<T extends FromApiActionPayload<any> &
U extends Action,
V extends Action,
W extends Action>(
successHandler: (result: S, action: T) => U | Observable<U> | Promise<Observable<U> | U>,
successHandler: (result: S, action: T) => U | Observable<U> | Promise<U>,
errorHandler?: (error: any, action: T) => Observable<V>,
cancelRequestActionFactory?: (props: AsyncRequest, action: T) => W,
cleanUpTimer?: number
Expand Down

0 comments on commit 4f0022e

Please sign in to comment.