Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/observable_fix-esm-import-extensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@equinor/fusion-observable": patch
---

Fix relative import/export specifiers in the published ESM output missing file extensions (e.g. `./operators` instead of `./operators/index.js`). This broke strict Node.js ESM resolution for consumers not using a bundler (e.g. `vitest` running against `node_modules` directly), producing errors like `Cannot find module '.../operators'`.
8 changes: 4 additions & 4 deletions packages/utils/observable/src/FlowSubject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import {
observeOn,
scan,
} from 'rxjs/operators';
import { filterAction } from './operators';
import { filterAction } from './operators/index.js';

import type { Action, ActionType, ExtractAction } from './actions/types';
import type { Flow, Effect } from './types/flow';
import type { ReducerWithInitialState } from './types/reducers';
import type { Action, ActionType, ExtractAction } from './actions/types.js';
import type { Flow, Effect } from './types/flow.js';
import type { ReducerWithInitialState } from './types/reducers.js';

/**
* A specialized Observable that maintains internal state mutated by dispatching actions.
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/observable/src/actions/ActionError.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Action } from './types';
import type { Action } from './types.js';

/**
* An error class that wraps a causal error together with the action that triggered it.
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/observable/src/actions/action-mapper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ActionCreator, ActionDefinitions, ActionTypes } from './types';
import type { ActionCreator, ActionDefinitions, ActionTypes } from './types.js';

/**
* A mapped type that converts {@link ActionDefinitions} into an object of
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/observable/src/actions/create-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* taken from https://github.com/reduxjs/redux-toolkit/tree/master/packages/toolkit/src
*/

import type { Action, PayloadAction } from './types';
import type { Action, PayloadAction } from './types.js';
import type {
IfMaybeUndefined,
IfVoid,
IsAny,
IsUnknownOrNonInferrable,
} from '../types/ts-helpers';
} from '../types/ts-helpers.js';

/**
* A "prepare" method to be used as the second parameter of `createAction`.
Expand Down Expand Up @@ -269,7 +269,7 @@ export function createAction(type: string, prepareAction?: PrepareAction<any>):
return actionCreator;
}

export { actionSuffixDivider, matchActionSuffix, getBaseType, getType } from './utils';
export { actionSuffixDivider, matchActionSuffix, getBaseType, getType } from './utils.js';

// helper types for more readable typings

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// biome-ignore-all lint/suspicious/noExplicitAny: generic constraints mirror create-action.ts's ported redux-toolkit PrepareAction<any> dispatch pattern

import { actionSuffixDivider, createAction } from './create-action';
import { actionSuffixDivider, createAction } from './create-action.js';
import {
isActionWithSuffix,
isCompleteAction,
isFailureAction,
isRequestAction,
isSuccessAction,
} from './predicates';
import type { PayloadActionCreator } from './create-action';
} from './predicates.js';
import type { PayloadActionCreator } from './create-action.js';

import type { PrepareAction } from './create-action';
import type { PrepareAction } from './create-action.js';

/**
* Creates an async action creator that produces request, success, and optionally failure sub-actions.
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/observable/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @module actions
*/
export * from './ActionError';
export * from './ActionError.js';
export * from './types.js';

export { actionMapper, type ActionCalls } from './action-mapper.js';
Expand All @@ -19,7 +19,7 @@ export {
type ActionCreatorWithOptionalPayload,
type ActionCreatorWithPreparedPayload,
type PayloadActionCreator,
} from './create-action';
} from './create-action.js';

export { getBaseType } from './utils.js';

Expand All @@ -29,4 +29,4 @@ export {
isCompleteAction,
isFailureAction,
isSuccessAction,
} from './create-async-action';
} from './create-async-action.js';
4 changes: 2 additions & 2 deletions packages/utils/observable/src/actions/predicates.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Action, ActionWithSuffix, AnyAction } from './types';
import { matchActionSuffix } from './utils';
import type { Action, ActionWithSuffix, AnyAction } from './types.js';
import { matchActionSuffix } from './utils.js';

/**
* Checks whether an action type ends with a specific lifecycle suffix.
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/observable/src/actions/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PayloadActionCreator } from './create-action';
import type { PayloadActionCreator } from './create-action.js';

/**
* Internal helper utilities for constructing and inspecting Redux-style
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/observable/src/create-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { produce as createNextState, isDraft, isDraftable } from 'immer';

import type { Draft } from 'immer';

import type { TypeGuard } from './types/ts-helpers';
import type { Action, ActionType, AnyAction, ExtractAction } from './actions/types';
import type { ReducerWithInitialState } from './types/reducers';
import type { TypeGuard } from './types/ts-helpers.js';
import type { Action, ActionType, AnyAction, ExtractAction } from './actions/types.js';
import type { ReducerWithInitialState } from './types/reducers.js';

function freezeDraftable<T>(val: T) {
return isDraftable(val) ? createNextState(val, () => {}) : val;
Expand Down
10 changes: 5 additions & 5 deletions packages/utils/observable/src/create-state.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { actionMapper } from './actions/action-mapper';
import { type ActionReducerMapBuilder, createReducer } from './create-reducer';
import { FlowSubject } from './FlowSubject';
import type { ActionDefinitions, ActionTypes } from './actions/types';
import type { ReducerWithInitialState } from './types/reducers';
import { actionMapper } from './actions/action-mapper.js';
import { type ActionReducerMapBuilder, createReducer } from './create-reducer.js';
import { FlowSubject } from './FlowSubject.js';
import type { ActionDefinitions, ActionTypes } from './actions/types.js';
import type { ReducerWithInitialState } from './types/reducers.js';

/**
* Describes the output of {@link createState}: a `FlowSubject`, the original
Expand Down
24 changes: 12 additions & 12 deletions packages/utils/observable/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@

export { castDraft } from 'immer';

export * from './FlowSubject';
export * from './actions/ActionError';
export * from './types';
export * from './FlowSubject.js';
export * from './actions/ActionError.js';
export * from './types/index.js';

/** @deprecated use {@link FlowSubject} */
export { FlowSubject as ReactiveObservable } from './FlowSubject';
export { FlowSubject as ReactiveObservable } from './FlowSubject.js';

export { actionMapper, type ActionCalls } from './actions/action-mapper';
export { actionMapper, type ActionCalls } from './actions/action-mapper.js';

export { createAction, type ActionCreatorWithPreparedPayload } from './actions/create-action';
export { getBaseType } from './actions/utils';
export { createAction, type ActionCreatorWithPreparedPayload } from './actions/create-action.js';
export { getBaseType } from './actions/utils.js';

export {
createAsyncAction,
isRequestAction,
isCompleteAction,
isFailureAction,
isSuccessAction,
} from './actions/create-async-action';
} from './actions/create-async-action.js';

export { createReducer, ActionReducerMapBuilder } from './create-reducer';
export { createReducer, ActionReducerMapBuilder } from './create-reducer.js';

export { createState, type FlowState } from './create-state';
export { createState, type FlowState } from './create-state.js';

export { isObservableInput } from './is-observable-input';
export { isObservableInput } from './is-observable-input.js';

export { toObservable, type DynamicInputValue } from './to-observable';
export { toObservable, type DynamicInputValue } from './to-observable.js';
2 changes: 1 addition & 1 deletion packages/utils/observable/src/operators/filter-action.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { OperatorFunction } from 'rxjs';
import { filter } from 'rxjs/operators';

import type { Action, ActionType, ExtractAction, TypeConstant } from '../types';
import type { Action, ActionType, ExtractAction, TypeConstant } from '../types/index.js';

/**
* RxJS operator that filters an action stream to only emit actions matching
Expand Down
8 changes: 4 additions & 4 deletions packages/utils/observable/src/operators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*
* @module operators
*/
export * from './filter-action';
export * from './map-action';
export * from './switch-map-action';
export * from './filter-action.js';
export * from './map-action.js';
export * from './switch-map-action.js';

export { mapProp } from './map-prop';
export { mapProp } from './map-prop.js';
4 changes: 2 additions & 2 deletions packages/utils/observable/src/operators/map-action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Observable, map, type OperatorFunction } from 'rxjs';
import { filterAction } from './filter-action';
import type { Action, ActionType, ExtractAction } from '../types';
import { filterAction } from './filter-action.js';
import type { Action, ActionType, ExtractAction } from '../types/index.js';

/**
* RxJS operator that filters an action stream by type and maps matching
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/observable/src/operators/map-prop.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { OperatorFunction } from 'rxjs';
import { map } from 'rxjs/operators';

import type { NestedKeys, NestedPropType } from '../types';
import type { NestedKeys, NestedPropType } from '../types/index.js';

/**
* RxJS operator that extracts a nested property from emitted objects using
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type OperatorFunction, type ObservableInput, switchMap } from 'rxjs';
import { filterAction } from './filter-action';
import type { Action, ActionType, ExtractAction } from '../types';
import { filterAction } from './filter-action.js';
import type { Action, ActionType, ExtractAction } from '../types/index.js';

/**
* RxJS operator that filters an action stream by type and `switchMap`s
Expand Down
26 changes: 13 additions & 13 deletions packages/utils/observable/src/react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
*
* @module react
*/
export * from './useObservable';
export * from './useObservableEffect';
export * from './useObservableInput';
export * from './useObservableInputState';
export { useObservableFlow } from './useObservableFlow';
export { useObservableEpic } from './use-observable-epic';
export * from './useObservableRef';
export * from './useObservableState';
export * from './useObservableSelector';
export * from './useObservableSelectorState';
export * from './useObservableSubscription';
export * from './useObservableLayoutSubscription';
export * from './useDebounce';
export * from './useObservable.js';
export * from './useObservableEffect.js';
export * from './useObservableInput.js';
export * from './useObservableInputState.js';
export { useObservableFlow } from './useObservableFlow.js';
export { useObservableEpic } from './use-observable-epic.js';
export * from './useObservableRef.js';
export * from './useObservableState.js';
export * from './useObservableSelector.js';
export * from './useObservableSelectorState.js';
export * from './useObservableSubscription.js';
export * from './useObservableLayoutSubscription.js';
export * from './useDebounce.js';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useObservableFlow } from './useObservableFlow';
import { useObservableFlow } from './useObservableFlow.js';

/** @deprecated Renamed to {@link useObservableFlow} since 8.0.3. */
export const useObservableEpic = useObservableFlow;
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/observable/src/react/useDebounce.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useMemo, useState } from 'react';
import { from, type Observable, type ObservableInput, Subject } from 'rxjs';
import { debounce, debounceTime, switchMap, tap } from 'rxjs/operators';
import type { ObservableType } from '../types';
import type { ObservableType } from '../types/index.js';

/**
* Options for the {@link useDebounce} hook.
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/observable/src/react/useObservable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import { FlowSubject } from '../FlowSubject';
import { FlowSubject } from '../FlowSubject.js';

import type { Action, Reducer, ReducerWithInitialState } from '../types';
import type { Action, Reducer, ReducerWithInitialState } from '../types/index.js';

/**
* React hook that creates and memoises a {@link FlowSubject} from a reducer and
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/observable/src/react/useObservableEffect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useLayoutEffect, useState } from 'react';
import type { FlowSubject } from '../FlowSubject';
import type { Action, Effect, ActionType, ExtractAction } from '../types';
import type { FlowSubject } from '../FlowSubject.js';
import type { Action, Effect, ActionType, ExtractAction } from '../types/index.js';

/**
* React hook that attaches a side-effect to a {@link FlowSubject}, filtered
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/observable/src/react/useObservableFlow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useLayoutEffect } from 'react';
import type { FlowSubject } from '../FlowSubject';
import type { Action, Flow } from '../types';
import type { FlowSubject } from '../FlowSubject.js';
import type { Action, Flow } from '../types/index.js';
/**
* React hook that attaches a flow (epic-style function) to a {@link FlowSubject}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ObservableInput } from 'rxjs';
import { useObservableState, type ObservableStateReturnType } from './useObservableState';
import { useObservableInput } from './useObservableInput';
import { useObservableState, type ObservableStateReturnType } from './useObservableState.js';
import { useObservableInput } from './useObservableInput.js';

/**
* React hook that subscribes to an `ObservableInput` and tracks its latest
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/observable/src/react/useObservableRef.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useRef } from 'react';
import type { BehaviorSubject } from 'rxjs';
import { useObservableLayoutSubscription } from './useObservableLayoutSubscription';
import type { Observable } from '../types';
import { useObservableLayoutSubscription } from './useObservableLayoutSubscription.js';
import type { Observable } from '../types/index.js';

/**
* React hook that keeps a `ref` synchronised with the latest value from an
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useMemo } from 'react';
import type { Observable } from '../types';
import type { Observable } from '../types/index.js';
import { distinctUntilChanged, map } from 'rxjs/operators';
import type { OperatorFunction } from 'rxjs';

import type { NestedKeys, NestedPropType } from '../types';
import { mapProp } from '../operators';
import type { NestedKeys, NestedPropType } from '../types/index.js';
import { mapProp } from '../operators/index.js';

const selectorFn = <
TType extends Record<string, unknown>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useObservableSelector } from './useObservableSelector';
import { useObservableState } from './useObservableState';
import type { Observable } from '../types';
import { useObservableSelector } from './useObservableSelector.js';
import { useObservableState } from './useObservableState.js';
import type { Observable } from '../types/index.js';

/**
* @deprecated Use `useObservableState(useObservableSelector(...))` instead (since ^8.1).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'react';
import { BehaviorSubject, type Subscription } from 'rxjs';
import { distinctUntilChanged } from 'rxjs/operators';
import type { Observable, StatefulObservable } from '../types';
import type { Observable, StatefulObservable } from '../types/index.js';

/**
* Options for {@link useObservableState}.
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/observable/src/to-observable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { from, of } from 'rxjs';
import type { ObservableInput, Observable } from 'rxjs';

import { isObservableInput } from './is-observable-input';
import { isObservableInput } from './is-observable-input.js';

/**
* Represents a value that can be:
Expand Down
10 changes: 5 additions & 5 deletions packages/utils/observable/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Observable } from 'rxjs';

export * from '../actions/types.js';
export * from './flow';
export * from './observable';
export * from './reducers';
export * from './flow.js';
export * from './observable.js';
export * from './reducers.js';

export type { NestedKeys, NestedPropType } from './ts-helpers';
export type { NestedKeys, NestedPropType } from './ts-helpers.js';

/** @deprecated Use {@link Flow} instead. */
export { Flow as Epic } from './flow';
export { Flow as Epic } from './flow.js';

/**
* Extracts the value type `U` from `Observable<U>`.
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/observable/src/types/reducers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Action, AnyAction } from '../actions/types.js';
import type { NotFunction } from './ts-helpers';
import type { NotFunction } from './ts-helpers.js';

/**
* A pure function that takes a previous state and an action, and returns
Expand Down
Loading
Loading