@arcote.tech/arc-react 0.7.26 → 0.7.28

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.
package/dist/index.js CHANGED
@@ -318,6 +318,15 @@ import {
318
318
  useState as useState3
319
319
  } from "react";
320
320
  import { jsx as jsx5 } from "react/jsx-runtime";
321
+ function logMutationError(descriptor, err) {
322
+ const label = `${descriptor.element}.${descriptor.method}`;
323
+ const e = err;
324
+ if (e && e.arcCode === "VALIDATION" && Array.isArray(e.fields)) {
325
+ console.error(`[arc] mutacja ${label} — Invalid parameters, niepoprawne pola: ${e.fields.join(", ")}`, err);
326
+ } else {
327
+ console.error(`[arc] mutacja ${label} nie powiodła się:`, err);
328
+ }
329
+ }
321
330
  var modelProviderFactory = (context, options) => {
322
331
  const ModelContext = createContext4(null);
323
332
  const commandWire = options.remoteUrl ? new CommandWire(options.remoteUrl) : undefined;
@@ -623,7 +632,16 @@ Event payload:`, event.payload);
623
632
  const model = useModel();
624
633
  return useMemo3(() => {
625
634
  const scoped = syncPersistedToken(model, name);
626
- return buildContextAccessor(model.context, scoped.getAdapters(), "mutateContext", (_descriptor, execute) => execute());
635
+ return buildContextAccessor(model.context, scoped.getAdapters(), "mutateContext", (descriptor, execute) => {
636
+ const result = execute();
637
+ if (result && typeof result.then === "function") {
638
+ return result.then(undefined, (err) => {
639
+ logMutationError(descriptor, err);
640
+ throw err;
641
+ });
642
+ }
643
+ return result;
644
+ });
627
645
  }, [model]);
628
646
  }
629
647
  return {
@@ -682,4 +700,4 @@ export {
682
700
  Form
683
701
  };
684
702
 
685
- //# debugId=4CA84684BEAF949D64756E2164756E21
703
+ //# debugId=288F1FEFD48F54D564756E2164756E21
@@ -1,4 +1,4 @@
1
- import { CommandWire, EventWire, Model, type ArcContextAny } from "@arcote.tech/arc";
1
+ import { CommandWire, EventWire, Model, type ArcContextAny, type MutationExecutor } from "@arcote.tech/arc";
2
2
  import type { ReactModelOptions } from "../options";
3
3
  /**
4
4
  * Accessor type for useQuery() — maps element names to their query methods,
@@ -10,11 +10,10 @@ export type QueryAccessor<C extends ArcContextAny> = {
10
10
  } : never;
11
11
  };
12
12
  /**
13
- * Accessor type for useMutation() — maps element names to their mutation methods.
13
+ * Accessor type for useMutation() — the canonical mutation accessor lives in
14
+ * core (`MutationExecutor`); re-aliased here as the single source of truth.
14
15
  */
15
- export type MutationAccessor<C extends ArcContextAny> = {
16
- [E in C["elements"][number] as E["mutateContext"] extends (...args: any[]) => any ? E["name"] : never]: E["mutateContext"] extends (...args: any[]) => infer R ? R : never;
17
- };
16
+ export type MutationAccessor<C extends ArcContextAny> = MutationExecutor<C>;
18
17
  export interface ScopeAPI<C extends ArcContextAny = ArcContextAny> {
19
18
  Provider: React.FC<{
20
19
  children: React.ReactNode;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc-react",
3
3
  "type": "module",
4
- "version": "0.7.26",
4
+ "version": "0.7.28",
5
5
  "private": false,
6
6
  "author": "Przemysław Krasiński [arcote.tech]",
7
7
  "description": "React client for the Arc framework, providing utilities for querying data and executing commands, enhancing the development of reactive and efficient user interfaces.",
@@ -32,7 +32,7 @@
32
32
  "typescript": "^5.2.2"
33
33
  },
34
34
  "peerDependencies": {
35
- "@arcote.tech/arc": "^0.7.26",
35
+ "@arcote.tech/arc": "^0.7.28",
36
36
  "react": "^18.0.0 || ^19.0.0",
37
37
  "react-dom": "^18.0.0 || ^19.0.0",
38
38
  "typescript": "^5.0.0"