@hamak/ui-remote-resource 0.21.1 → 0.22.0

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.
@@ -16,9 +16,8 @@ export interface RemoteResourceAttributes {
16
16
  endpointId?: string;
17
17
  /**
18
18
  * High-level params that produced this node (the "query binding").
19
- * Persisted so the node can be re-fetched/refreshed with changed criteria —
20
- * the endpoint's payloadMapper deterministically re-derives the wire query
21
- * from these. See `ResourceActionFactory.refresh`.
19
+ * Persisted for `ResourceActionFactory.refresh` unless the endpoint sets
20
+ * `persistParams: false`.
22
21
  */
23
22
  params?: Record<string, any>;
24
23
  /** Resource-specific metadata */
@@ -1 +1 @@
1
- {"version":3,"file":"resource-attributes.d.ts","sourceRoot":"","sources":["../../../src/api/types/resource-attributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAErE;;;;;;;GAOG;AACH,MAAM,WAAW,wBAAwB;IACvC,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE7B,iCAAiC;IACjC,QAAQ,CAAC,EAAE;QACT,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IAEF,+BAA+B;IAC/B,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAElC,6BAA6B;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,yEAAyE;IACzE,MAAM,CAAC,EAAE,gBAAgB,CA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AS,EAAE,MAAM,EAAE,CAAC;IAEpB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3B"}
@@ -1,18 +1,15 @@
1
- /**
2
- * Per-path monotonic request sequencer.
3
- *
4
- * Guards against out-of-order responses when a node is re-fetched rapidly
5
- * (e.g. a user flipping filters): each request to a path gets an increasing
6
- * token, and a response is only applied if its token is still the latest one
7
- * issued for that path. A slow earlier response therefore can't clobber a
8
- * newer filter's result.
9
- */
1
+ /** Tracks the latest in-flight request per path until it settles or is invalidated. */
10
2
  export declare class RequestSequencer {
11
3
  private readonly latest;
4
+ private lastToken;
5
+ get checkpoint(): number;
12
6
  /** Issue the next token for a path key. */
13
7
  next(key: string): number;
14
8
  /** True if `token` is the most recent one issued for the path key. */
15
9
  isCurrent(key: string, token: number): boolean;
10
+ finish(key: string, token: number): void;
11
+ /** Keep requests dispatched by subscribers after the removal took effect. */
12
+ invalidate(path: string | string[], through: number, includeDescendants: boolean): void;
16
13
  }
17
14
  /** Normalize a path (string or segments) to a stable map key. */
18
15
  export declare function pathKey(path: string | string[]): string;
@@ -1 +1 @@
1
- {"version":3,"file":"request-sequencer.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/request-sequencer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6B;IAEpD,2CAA2C;IAC3C,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAMzB,sEAAsE;IACtE,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;CAG/C;AAED,iEAAiE;AACjE,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAEvD"}
1
+ {"version":3,"file":"request-sequencer.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/request-sequencer.ts"],"names":[],"mappings":"AAEA,uFAAuF;AACvF,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6B;IACpD,OAAO,CAAC,SAAS,CAAK;IAEtB,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,2CAA2C;IAC3C,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAMzB,sEAAsE;IACtE,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAI9C,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAMxC,6EAA6E;IAC7E,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,GAAG,IAAI;CASxF;AAED,iEAAiE;AACjE,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAEvD"}
@@ -1,12 +1,5 @@
1
- /**
2
- * Per-path monotonic request sequencer.
3
- *
4
- * Guards against out-of-order responses when a node is re-fetched rapidly
5
- * (e.g. a user flipping filters): each request to a path gets an increasing
6
- * token, and a response is only applied if its token is still the latest one
7
- * issued for that path. A slow earlier response therefore can't clobber a
8
- * newer filter's result.
9
- */
1
+ import { Pathway } from '@hamak/navigation-utils';
2
+ /** Tracks the latest in-flight request per path until it settles or is invalidated. */
10
3
  export class RequestSequencer {
11
4
  constructor() {
12
5
  Object.defineProperty(this, "latest", {
@@ -15,19 +8,43 @@ export class RequestSequencer {
15
8
  writable: true,
16
9
  value: new Map()
17
10
  });
11
+ Object.defineProperty(this, "lastToken", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: 0
16
+ });
17
+ }
18
+ get checkpoint() {
19
+ return this.lastToken;
18
20
  }
19
21
  /** Issue the next token for a path key. */
20
22
  next(key) {
21
- const token = (this.latest.get(key) ?? 0) + 1;
23
+ const token = ++this.lastToken;
22
24
  this.latest.set(key, token);
23
25
  return token;
24
26
  }
25
27
  /** True if `token` is the most recent one issued for the path key. */
26
28
  isCurrent(key, token) {
27
- return (this.latest.get(key) ?? 0) === token;
29
+ return this.latest.get(key) === token;
30
+ }
31
+ finish(key, token) {
32
+ if (this.isCurrent(key, token)) {
33
+ this.latest.delete(key);
34
+ }
35
+ }
36
+ /** Keep requests dispatched by subscribers after the removal took effect. */
37
+ invalidate(path, through, includeDescendants) {
38
+ const removed = Pathway.of(path);
39
+ const key = pathKey(path);
40
+ for (const [pendingPath, token] of this.latest) {
41
+ if (token <= through && (pendingPath === key || (includeDescendants && removed.isDescendant(pendingPath)))) {
42
+ this.latest.delete(pendingPath);
43
+ }
44
+ }
28
45
  }
29
46
  }
30
47
  /** Normalize a path (string or segments) to a stable map key. */
31
48
  export function pathKey(path) {
32
- return Array.isArray(path) ? path.join('/') : path;
49
+ return Pathway.of(path).getSegments().join('/');
33
50
  }
@@ -0,0 +1,3 @@
1
+ /** Keep short machine-readable codes and replace arbitrary provider text. */
2
+ export declare function resourceErrorCode(code: unknown): string;
3
+ //# sourceMappingURL=resource-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-error.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/resource-error.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAIvD"}
@@ -0,0 +1,6 @@
1
+ /** Keep short machine-readable codes and replace arbitrary provider text. */
2
+ export function resourceErrorCode(code) {
3
+ return typeof code === 'string' && /^[A-Za-z0-9_-]{1,64}$/.test(code)
4
+ ? code
5
+ : 'RESOURCE_CALL_FAILED';
6
+ }
@@ -6,8 +6,8 @@ export interface ResourceMiddlewareConfig {
6
6
  onError?: (error: any, action: ResourceAction) => void;
7
7
  onSuccess?: (result: any, action: ResourceAction) => void;
8
8
  /**
9
- * Optional out-of-order guard. When provided, a response is dropped if a newer
10
- * request to the same storage path was issued while it was in flight.
9
+ * Optional guard against newer requests. Share it with sync middleware
10
+ * to also drop replies for nodes removed while a request was in flight.
11
11
  */
12
12
  sequencer?: RequestSequencer;
13
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resource-middleware.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/resource-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,gBAAgB,EAAW,MAAM,qBAAqB,CAAC;AAGhE,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IACvD,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1D;;;OAGG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,GAAG,GAAG,EAC9C,MAAM,EAAE,wBAAwB,GAC/B,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAwFnB"}
1
+ {"version":3,"file":"resource-middleware.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/resource-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,gBAAgB,EAAW,MAAM,qBAAqB,CAAC;AAKhE,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IACvD,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1D;;;OAGG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,GAAG,GAAG,EAC9C,MAAM,EAAE,wBAAwB,GAC/B,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAmGnB"}
@@ -1,5 +1,7 @@
1
1
  import { ResourceActionTypes, ResourceActionFactory } from '../../api/index.js';
2
2
  import { pathKey } from './request-sequencer.js';
3
+ import { resourceErrorCode } from './resource-error.js';
4
+ import { Pathway } from '@hamak/navigation-utils';
3
5
  /**
4
6
  * Resource middleware
5
7
  * Intercepts RESOURCE_CALL_REQUEST actions and executes API calls via providers
@@ -12,26 +14,29 @@ export function createResourceMiddleware(config) {
12
14
  if (action.type !== ResourceActionTypes.RESOURCE_CALL_REQUEST) {
13
15
  return next(action);
14
16
  }
15
- // Continue action flow (for sync middleware to set loading state)
16
- next(action);
17
17
  const requestAction = action;
18
18
  const { endpointId, operation, params, path } = requestAction.payload;
19
19
  // Resolve the storage path and claim an ordering token up front, so a
20
20
  // response that loses the race to a newer request to the same node is
21
- // dropped instead of overwriting fresher content.
21
+ // dropped instead of overwriting fresher content. Claim the token before
22
+ // loading state is dispatched, since subscribers can dispatch a removal.
22
23
  const endpointDef = registry.getEndpoint(endpointId);
23
24
  const storagePath = determinePath(path, endpointDef, params, operation);
24
25
  const key = pathKey(storagePath);
25
26
  const token = sequencer?.next(key);
26
27
  const isStale = () => sequencer !== undefined && token !== undefined && !sequencer.isCurrent(key, token);
27
28
  try {
29
+ next(action);
30
+ if (isStale()) {
31
+ return;
32
+ }
28
33
  if (!endpointDef) {
29
- throw new Error(`Endpoint not found: ${endpointId}`);
34
+ throw Object.assign(new Error(`Endpoint not found: ${endpointId}`), { code: 'ENDPOINT_NOT_FOUND' });
30
35
  }
31
36
  // Get provider
32
37
  const provider = registry.getProvider(endpointDef.providerType);
33
38
  if (!provider) {
34
- throw new Error(`Provider not found: ${endpointDef.providerType}`);
39
+ throw Object.assign(new Error(`Provider not found: ${endpointDef.providerType}`), { code: 'PROVIDER_NOT_FOUND' });
35
40
  }
36
41
  // Map action to call params (mapper receives entire action)
37
42
  const callParams = endpointDef.payloadMapper
@@ -47,6 +52,9 @@ export function createResourceMiddleware(config) {
47
52
  const transformedData = endpointDef.responseTransformer
48
53
  ? endpointDef.responseTransformer(result.data, result.metadata, requestAction)
49
54
  : result.data;
55
+ if (isStale()) {
56
+ return;
57
+ }
50
58
  // Dispatch success action
51
59
  const successAction = actionFactory.callSuccess(endpointId, storagePath, transformedData, result.metadata, requestAction);
52
60
  store.dispatch(successAction);
@@ -62,6 +70,11 @@ export function createResourceMiddleware(config) {
62
70
  store.dispatch(failureAction);
63
71
  onError?.(error, requestAction);
64
72
  }
73
+ finally {
74
+ if (token !== undefined) {
75
+ sequencer?.finish(key, token);
76
+ }
77
+ }
65
78
  };
66
79
  }
67
80
  /**
@@ -74,9 +87,7 @@ function determinePath(explicitPath, endpointDef, params, operation) {
74
87
  }
75
88
  // 2. Use endpoint's default folder + generate filename
76
89
  if (endpointDef?.defaultFolder) {
77
- const folder = Array.isArray(endpointDef.defaultFolder)
78
- ? endpointDef.defaultFolder
79
- : [endpointDef.defaultFolder];
90
+ const folder = Pathway.of(endpointDef.defaultFolder).getSegments();
80
91
  // Generate filename from params or operation
81
92
  const filename = generateFilename(params, operation);
82
93
  return [...folder, filename];
@@ -96,17 +107,14 @@ function generateFilename(params, operation) {
96
107
  return `${operation}-${Date.now()}`;
97
108
  }
98
109
  /**
99
- * Normalize error to consistent format.
100
- *
101
- * Handles both axios-shaped errors (`error.response.status` / `.data`) and
102
- * plain-HTTP-shaped errors thrown by PlainHttpResourceProvider
103
- * (`error.status` / `.body`), so `code` carries the HTTP status either way.
110
+ * Keep diagnostic provider errors in onError and dispatch a generic message
111
+ * with the HTTP status (Axios or fetch) or a machine-readable provider code.
104
112
  */
105
113
  function normalizeError(error) {
106
- const status = error.response?.status ?? error.status;
114
+ const status = error?.response?.status ?? error?.status;
115
+ const isHttpStatus = Number.isInteger(status) && status >= 100 && status <= 599;
107
116
  return {
108
- message: error.message || 'Unknown error',
109
- code: error.code ?? (status != null ? String(status) : undefined),
110
- details: error.response?.data ?? error.body ?? error
117
+ message: 'Resource call failed',
118
+ code: isHttpStatus ? String(status) : resourceErrorCode(error?.code),
111
119
  };
112
120
  }
@@ -1,8 +1,13 @@
1
1
  import type { Middleware } from 'redux';
2
- import type { FileSystemNodeActions } from '@hamak/ui-store';
2
+ import { type FileSystemNodeActions } from '@hamak/ui-store';
3
+ import type { RequestSequencer } from './request-sequencer.js';
3
4
  export interface SyncMiddlewareConfig {
4
5
  /** FileSystem actions from FileSystemAdapter */
5
6
  fsActions: FileSystemNodeActions;
7
+ /** Share with resource middleware to invalidate requests when nodes are removed. */
8
+ sequencer?: RequestSequencer;
9
+ /** Resolve the endpoint's preference for keeping request params for refresh. */
10
+ shouldPersistParams?: (endpointId: string) => boolean;
6
11
  }
7
12
  /**
8
13
  * Sync middleware
@@ -1 +1 @@
1
- {"version":3,"file":"sync-middleware.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/sync-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAQxC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAG7D,MAAM,WAAW,oBAAoB;IACnC,gDAAgD;IAChD,SAAS,EAAE,qBAAqB,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,GAAG,EAC1C,MAAM,EAAE,oBAAoB,GAC3B,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAwBnB"}
1
+ {"version":3,"file":"sync-middleware.d.ts","sourceRoot":"","sources":["../../../src/impl/middleware/sync-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAQxC,OAAO,EAAqB,KAAK,qBAAqB,EAAwB,MAAM,iBAAiB,CAAC;AAEtG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,MAAM,WAAW,oBAAoB;IACnC,gDAAgD;IAChD,SAAS,EAAE,qBAAqB,CAAC;IACjC,oFAAoF;IACpF,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,gFAAgF;IAChF,mBAAmB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;CACvD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,GAAG,EAC1C,MAAM,EAAE,oBAAoB,GAC3B,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAyCnB"}
@@ -1,12 +1,29 @@
1
1
  import { ResourceActionTypes, REMOTE_RESOURCE_EXTENSION_KEY } from '../../api/index.js';
2
+ import { getFileSystemNode } from '@hamak/ui-store';
2
3
  import { Pathway } from '@hamak/navigation-utils';
4
+ import { resourceErrorCode } from './resource-error.js';
3
5
  /**
4
6
  * Sync middleware
5
7
  * Updates file system state when resource actions complete
6
8
  */
7
9
  export function createSyncMiddleware(config) {
8
- const { fsActions } = config;
10
+ const { fsActions, sequencer, shouldPersistParams } = config;
9
11
  return (store) => (next) => (action) => {
12
+ if (sequencer && action.type === fsActions.removeType && action.command?.name === 'remove') {
13
+ const { path } = action.command;
14
+ const readNode = () => {
15
+ const fs = store.getState()[fsActions.sliceName];
16
+ return fs && getFileSystemNode(fs.root, path);
17
+ };
18
+ const previous = readNode();
19
+ const checkpoint = sequencer.checkpoint;
20
+ const result = next(action);
21
+ // Check the reducer's result so a denied removal leaves its request active.
22
+ if (previous !== readNode()) {
23
+ sequencer.invalidate(path, checkpoint, previous?.type === 'directory');
24
+ }
25
+ return result;
26
+ }
10
27
  // Pass through all actions first
11
28
  const result = next(action);
12
29
  // Handle request action (set loading state)
@@ -15,7 +32,8 @@ export function createSyncMiddleware(config) {
15
32
  }
16
33
  // Handle success action (update content)
17
34
  if (action.type === ResourceActionTypes.RESOURCE_CALL_SUCCESS) {
18
- handleSuccessAction(store, action, fsActions);
35
+ const persistParams = shouldPersistParams?.(action.payload.endpointId) ?? true;
36
+ handleSuccessAction(store, action, fsActions, persistParams);
19
37
  }
20
38
  // Handle failure action (set error state)
21
39
  if (action.type === ResourceActionTypes.RESOURCE_CALL_FAILURE) {
@@ -43,8 +61,8 @@ function handleRequestAction(store, action, fsActions) {
43
61
  store.dispatch(fsActions.setFile(path, null, 'xs:any', { override: false, contentIsPresent: false }));
44
62
  store.dispatch(fsActions.setContentLoading(path, true));
45
63
  }
46
- function handleSuccessAction(store, action, fsActions) {
47
- const { path, data, endpointId, metadata } = action.payload;
64
+ function handleSuccessAction(store, action, fsActions, persistParams) {
65
+ const { path, data, endpointId } = action.payload;
48
66
  const { request } = action;
49
67
  // Normalize path using Pathway utility
50
68
  const pathway = Pathway.of(path);
@@ -67,10 +85,9 @@ function handleSuccessAction(store, action, fsActions) {
67
85
  // extension state, so this write must follow it.
68
86
  store.dispatch(fsActions.setExtensionState(path, REMOTE_RESOURCE_EXTENSION_KEY, {
69
87
  endpointId,
70
- params: request?.payload?.params,
88
+ ...(persistParams && { params: request?.payload?.params }),
71
89
  lastFetched: Date.now(),
72
90
  lastOperation: request?.payload?.operation,
73
- metadata
74
91
  }));
75
92
  }
76
93
  function handleFailureAction(store, action, fsActions) {
@@ -86,8 +103,6 @@ function handleFailureAction(store, action, fsActions) {
86
103
  if (parentSegments.length > 0) {
87
104
  store.dispatch(fsActions.mkdir(parentSegments, true));
88
105
  }
89
- // For now, just ensure the file exists and set content to null/error placeholder
90
- // TODO: FileSystemAdapter doesn't currently support setting error state directly
91
- // We might need to extend it or handle errors differently
92
- store.dispatch(fsActions.setFile(path, { error }, 'xs:any', { override: true, contentIsPresent: true }));
106
+ const content = { error: { code: resourceErrorCode(error?.code) } };
107
+ store.dispatch(fsActions.setFile(path, content, 'xs:any', { override: true, contentIsPresent: true }));
93
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resource-plugin-factory.d.ts","sourceRoot":"","sources":["../../../src/impl/plugin/resource-plugin-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAiBtD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,QAAQ,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED,UAAU,qBAAqB;IAC7B,OAAO,CAAC,QAAQ,EAAE,GAAG,GAAG,IAAI,CAAC;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,UAAU,eAAe;IACvB,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,CAAC;IACzB,KAAK,EAAE;QACL,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;KACvC,CAAC;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAGD,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAC3D,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAEvD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,GAAE,oBAAyB,GAChC,YAAY,CAgKd"}
1
+ {"version":3,"file":"resource-plugin-factory.d.ts","sourceRoot":"","sources":["../../../src/impl/plugin/resource-plugin-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAgBtD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,QAAQ,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED,UAAU,qBAAqB;IAC7B,OAAO,CAAC,QAAQ,EAAE,GAAG,GAAG,IAAI,CAAC;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,UAAU,eAAe;IACvB,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,CAAC;IACzB,KAAK,EAAE;QACL,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;KACvC,CAAC;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAGD,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAC3D,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAEvD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,GAAE,oBAAyB,GAChC,YAAY,CAwJd"}
@@ -1,5 +1,5 @@
1
1
  import { MIDDLEWARE_REGISTRY_TOKEN } from '@hamak/ui-store/api';
2
- import { FILESYSTEM_ADAPTER_TOKEN } from '@hamak/ui-store';
2
+ import { FILESYSTEM_ADAPTER_TOKEN, getFileSystemNode } from '@hamak/ui-store';
3
3
  import { ResourceRegistry } from '../registry/resource-registry.js';
4
4
  import { EntityRegistry } from '../registry/entity-registry.js';
5
5
  import { RestResourceProvider } from '../providers/rest-resource-provider.js';
@@ -10,7 +10,6 @@ import { createEntityMiddleware } from '../middleware/entity-middleware.js';
10
10
  import { createEntitySyncMiddleware } from '../middleware/entity-sync-middleware.js';
11
11
  import { createRefreshMiddleware } from '../middleware/refresh-middleware.js';
12
12
  import { RequestSequencer } from '../middleware/request-sequencer.js';
13
- import { Pathway } from '@hamak/navigation-utils';
14
13
  // Dependency injection tokens (for local use)
15
14
  export const RESOURCE_REGISTRY_TOKEN = 'RESOURCE_REGISTRY';
16
15
  export const ENTITY_REGISTRY_TOKEN = 'ENTITY_REGISTRY';
@@ -75,17 +74,7 @@ export function createResourcePlugin(config = {}) {
75
74
  // Read a node from the fs slice by path (for refresh binding lookup)
76
75
  const readNode = (state, path) => {
77
76
  const root = state?.[fsSliceName]?.root;
78
- if (!root) {
79
- return undefined;
80
- }
81
- return Pathway.of(path)
82
- .getSegments()
83
- .reduce((acc, step) => {
84
- if (!acc || acc.type === 'file') {
85
- return acc;
86
- }
87
- return acc.children?.[step];
88
- }, root);
77
+ return root && getFileSystemNode(root, path);
89
78
  };
90
79
  // Create middleware with FileSystemAdapter actions
91
80
  const entityMiddleware = createEntityMiddleware({
@@ -105,7 +94,9 @@ export function createResourcePlugin(config = {}) {
105
94
  });
106
95
  const entitySyncMiddleware = createEntitySyncMiddleware();
107
96
  const resourceSyncMiddleware = createSyncMiddleware({
108
- fsActions
97
+ fsActions,
98
+ sequencer,
99
+ shouldPersistParams: (endpointId) => resourceRegistry.getEndpoint(endpointId)?.persistParams !== false,
109
100
  });
110
101
  const middlewareRegistry = resolve(MIDDLEWARE_REGISTRY_TOKEN);
111
102
  middlewareRegistry.register({
@@ -29,6 +29,11 @@ export interface ResourceEndpointDefinition {
29
29
  payloadMapper?: PayloadMapper;
30
30
  /** Transforms response data before storing */
31
31
  responseTransformer?: ResponseTransformer;
32
+ /**
33
+ * Keep request params on the file for refresh (default: true). Set to false
34
+ * for sensitive criteria and pass any required params on each refresh.
35
+ */
36
+ persistParams?: boolean;
32
37
  /** Additional endpoint configuration */
33
38
  config?: {
34
39
  /** Auto-fetch on registration */
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint-definition.d.ts","sourceRoot":"","sources":["../../../src/spi/config/endpoint-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC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module",
6
6
  "description": "Remote resource management for microkernel-based applications",
@@ -52,9 +52,10 @@
52
52
  }
53
53
  },
54
54
  "dependencies": {
55
- "@hamak/shared-utils": "^0.21.1",
56
- "@hamak/ui-store": "^0.21.1",
57
- "@hamak/microkernel-api": "^0.21.1",
55
+ "@hamak/shared-utils": "^0.22.0",
56
+ "@hamak/ui-store": "^0.22.0",
57
+ "@hamak/microkernel-api": "^0.22.0",
58
+ "@hamak/navigation-utils": "^0.22.0",
58
59
  "axios": "^1.6.0",
59
60
  "redux": "^5.0.1",
60
61
  "uuid": "^9.0.0"