@nice-code/action 0.2.3 → 0.2.4

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.
Files changed (24) hide show
  1. package/build/index.js +65 -55
  2. package/build/react-query/index.js +5 -5
  3. package/build/types/ActionDefinition/Action/Context/ActionContext.d.ts +3 -3
  4. package/build/types/ActionDefinition/Action/Context/ActionContext.types.d.ts +5 -5
  5. package/build/types/ActionDefinition/Action/Core/ActionCore.d.ts +1 -1
  6. package/build/types/ActionDefinition/Domain/ActionDomain.types.d.ts +1 -1
  7. package/build/types/ActionDefinition/Domain/ActionRootDomain.d.ts +2 -2
  8. package/build/types/ActionRuntime/ActionRuntime.d.ts +6 -4
  9. package/build/types/ActionRuntime/ActionRuntime.types.d.ts +2 -2
  10. package/build/types/ActionRuntime/ActionRuntimeManager.d.ts +4 -4
  11. package/build/types/ActionRuntime/Handler/ActionHandler.types.d.ts +4 -4
  12. package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.d.ts +2 -2
  13. package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.types.d.ts +2 -2
  14. package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Transport.types.d.ts +3 -3
  15. package/build/types/ActionRuntime/RuntimeCoordinate.d.ts +55 -0
  16. package/build/types/ActionRuntime/utils/runtimeCoordinateToStringIds.d.ts +2 -0
  17. package/build/types/errors/err_nice_action.d.ts +4 -4
  18. package/build/types/index.d.ts +1 -1
  19. package/build/types/nice_action.static.d.ts +2 -2
  20. package/build/types/react-query/hooks/useActionMutation.d.ts +7 -3
  21. package/build/types/react-query/hooks/useActionQuery.d.ts +4 -4
  22. package/package.json +1 -1
  23. package/build/types/ActionRuntime/Client/ActionClientSpecifier.d.ts +0 -47
  24. package/build/types/ActionRuntime/Client/utils/clientSpecifierToStringIds.d.ts +0 -2
package/build/index.js CHANGED
@@ -45,70 +45,70 @@ var nanoid = (size = 21) => {
45
45
 
46
46
  // src/nice_action.static.ts
47
47
  var DEFAULT_TRANSPORT_TIMEOUT = 1e4;
48
- var UNSET_CLIENT_ID = "_unset_";
48
+ var UNSET_RUNTIME_ENV_ID = "_unset_";
49
49
 
50
- // src/ActionRuntime/Client/utils/clientSpecifierToStringIds.ts
51
- function clientSpecifierToStringIds(specifier) {
50
+ // src/ActionRuntime/utils/runtimeCoordinateToStringIds.ts
51
+ function runtimeCoordinateToStringIds(coordinate) {
52
52
  return [
53
- `id[${specifier.id}]perId[${specifier.perId ?? "_"}]:insId[${specifier.insId ?? "_"}]`,
54
- `id[${specifier.id}]perId[${specifier.perId ?? "_"}]:insId[_]`,
55
- `id[${specifier.id}]perId[_]:insId[_]`
53
+ `envId[${coordinate.envId}]perId[${coordinate.perId ?? "_"}]:insId[${coordinate.insId ?? "_"}]`,
54
+ `envId[${coordinate.envId}]perId[${coordinate.perId ?? "_"}]:insId[_]`,
55
+ `envId[${coordinate.envId}]perId[_]:insId[_]`
56
56
  ];
57
57
  }
58
58
 
59
- // src/ActionRuntime/Client/ActionClientSpecifier.ts
60
- class ActionClientSpecifier {
61
- id;
59
+ // src/ActionRuntime/RuntimeCoordinate.ts
60
+ class RuntimeCoordinate {
61
+ envId;
62
62
  perId;
63
63
  insId;
64
64
  static get unknown() {
65
- return new ActionClientSpecifier({
66
- id: UNSET_CLIENT_ID
65
+ return new RuntimeCoordinate({
66
+ envId: UNSET_RUNTIME_ENV_ID
67
67
  });
68
68
  }
69
- static root(id) {
70
- return new ActionClientSpecifier({
71
- id
69
+ static env(envId) {
70
+ return new RuntimeCoordinate({
71
+ envId
72
72
  });
73
73
  }
74
74
  withPersistentId(perId) {
75
75
  return this.specify({ perId });
76
76
  }
77
- constructor({ id, perId, insId }) {
78
- this.id = id;
77
+ constructor({ envId, perId, insId }) {
78
+ this.envId = envId;
79
79
  this.perId = perId;
80
80
  this.insId = insId;
81
81
  }
82
82
  specify(newInputs) {
83
- return new ActionClientSpecifier({
84
- id: this.id,
83
+ return new RuntimeCoordinate({
84
+ envId: this.envId,
85
85
  perId: this.perId,
86
86
  insId: this.insId,
87
87
  ...newInputs
88
88
  });
89
89
  }
90
90
  specifyIfUnset(newInputs) {
91
- return new ActionClientSpecifier({
92
- id: this.id,
91
+ return new RuntimeCoordinate({
92
+ envId: this.envId,
93
93
  perId: this.perId ?? newInputs.perId,
94
94
  insId: this.insId ?? newInputs.insId
95
95
  });
96
96
  }
97
97
  toJsonObject() {
98
98
  return {
99
- id: this.id,
99
+ envId: this.envId,
100
100
  perId: this.perId,
101
101
  insId: this.insId
102
102
  };
103
103
  }
104
104
  isExactlySame(other) {
105
- return this.id === other.id && this.perId === other.perId && this.insId === other.insId;
105
+ return this.envId === other.envId && this.perId === other.perId && this.insId === other.insId;
106
106
  }
107
107
  isSameFor(other) {
108
108
  return {
109
- id: this.id === other.id,
110
- perId: this.id === other.id && this.perId === other.perId,
111
- insId: this.id === other.id && this.perId === other.perId && this.insId === other.insId
109
+ id: this.envId === other.envId,
110
+ perId: this.envId === other.envId && this.perId === other.perId,
111
+ insId: this.envId === other.envId && this.perId === other.perId && this.insId === other.insId
112
112
  };
113
113
  }
114
114
  similarityLevel(other) {
@@ -122,10 +122,10 @@ class ActionClientSpecifier {
122
122
  return 0;
123
123
  }
124
124
  get stringId() {
125
- return `id[${this.id}]perId[${this.perId ?? "_"}]:insId[${this.insId ?? "_"}]`;
125
+ return `envId[${this.envId}]perId[${this.perId ?? "_"}]:insId[${this.insId ?? "_"}]`;
126
126
  }
127
127
  toStringIds() {
128
- return clientSpecifierToStringIds(this);
128
+ return runtimeCoordinateToStringIds(this);
129
129
  }
130
130
  }
131
131
 
@@ -375,7 +375,8 @@ class ActionCore extends ActionBase {
375
375
  allDomains: this.allDomains
376
376
  };
377
377
  }
378
- request(input) {
378
+ request(...args) {
379
+ const input = args[0];
379
380
  const validatedInput = this.schema.validateInput(input, {
380
381
  actionId: this.id,
381
382
  domain: this.domain
@@ -384,7 +385,7 @@ class ActionCore extends ActionBase {
384
385
  cuid: nanoid(),
385
386
  timeCreated: Date.now(),
386
387
  routing: [],
387
- originClient: ActionClientSpecifier.unknown
388
+ originClient: RuntimeCoordinate.unknown
388
389
  });
389
390
  return new ActionPayload_Request({ context }, validatedInput, {
390
391
  time: Date.now()
@@ -3503,14 +3504,14 @@ class ActionRouter {
3503
3504
  throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
3504
3505
  domain: action.domain,
3505
3506
  actionId: action.id,
3506
- specifiedClient: context.targetLocalRuntime?.clientSpecifier
3507
+ specifiedClient: context.targetLocalRuntime?.coordinate
3507
3508
  });
3508
3509
  }
3509
3510
  if (this._context.contextType === "runtime_to_handler" /* runtime_to_handler */) {
3510
3511
  throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
3511
3512
  domain: action.domain,
3512
3513
  actionId: action.id,
3513
- specifiedClient: this._context.runtime.clientSpecifier
3514
+ specifiedClient: this._context.runtime.coordinate
3514
3515
  });
3515
3516
  }
3516
3517
  throw new Error(`No route function found for action with domain "${action.domain}" and id "${action.id}".`);
@@ -3611,7 +3612,7 @@ class ActionRouter {
3611
3612
 
3612
3613
  // src/ActionRuntime/ActionRuntime.ts
3613
3614
  class ActionRuntime {
3614
- clientSpecifier;
3615
+ _coordinate;
3615
3616
  timeCreated;
3616
3617
  runtimeInfo = getAssumedRuntimeInfo();
3617
3618
  actionRouter;
@@ -3620,8 +3621,8 @@ class ActionRuntime {
3620
3621
  static getDefault() {
3621
3622
  return getDefaultActionRuntime();
3622
3623
  }
3623
- constructor(client) {
3624
- this.clientSpecifier = client.specifyIfUnset({
3624
+ constructor(coordinate) {
3625
+ this._coordinate = coordinate.specifyIfUnset({
3625
3626
  insId: nanoid(14)
3626
3627
  });
3627
3628
  this.timeCreated = Date.now();
@@ -3630,6 +3631,15 @@ class ActionRuntime {
3630
3631
  runtime: this
3631
3632
  });
3632
3633
  }
3634
+ get coordinate() {
3635
+ return this._coordinate;
3636
+ }
3637
+ updateRuntimeCoordinate(newCoordinate) {
3638
+ if (this._coordinate.envId !== newCoordinate.envId) {
3639
+ throw new Error(`Can't update Runtime Coordinate with different "envId" properties (static environment id). "${this.coordinate.envId}" (current) !== ${newCoordinate.envId}`);
3640
+ }
3641
+ this._coordinate = newCoordinate;
3642
+ }
3633
3643
  registerRunningAction(ra) {
3634
3644
  this._pendingRunningActions.set(ra.cuid, ra);
3635
3645
  ra.addUpdateListeners([
@@ -3695,7 +3705,7 @@ class ActionRuntime {
3695
3705
  if (possibleHandlers.length === 0) {
3696
3706
  return;
3697
3707
  }
3698
- const scoringExternalClient = targetExternalClient ?? ActionClientSpecifier.unknown;
3708
+ const scoringExternalClient = targetExternalClient ?? RuntimeCoordinate.unknown;
3699
3709
  let handlerScore = -1;
3700
3710
  let handler;
3701
3711
  for (const possibleHandler of possibleHandlers) {
@@ -3741,7 +3751,7 @@ class ActionRuntime {
3741
3751
  return this;
3742
3752
  }
3743
3753
  getReturnHandlerForOrigin(originClient) {
3744
- if (originClient.id === UNSET_CLIENT_ID)
3754
+ if (originClient.envId === UNSET_RUNTIME_ENV_ID)
3745
3755
  return;
3746
3756
  let bestScore = -1;
3747
3757
  let bestHandler;
@@ -3756,7 +3766,7 @@ class ActionRuntime {
3756
3766
  }
3757
3767
  _trySetupReturnDispatch(runningAction) {
3758
3768
  const originClient = runningAction.context.originClient;
3759
- if (originClient.id === UNSET_CLIENT_ID || originClient.isSameFor(this.clientSpecifier).id) {
3769
+ if (originClient.envId === UNSET_RUNTIME_ENV_ID || originClient.isSameFor(this._coordinate).id) {
3760
3770
  return;
3761
3771
  }
3762
3772
  runningAction.addUpdateListeners([
@@ -3778,7 +3788,7 @@ function getDefaultActionRuntime() {
3778
3788
  runtimeState.assumedRuntimeInfo = getAssumedRuntimeInfo();
3779
3789
  }
3780
3790
  if (runtimeState.defaultLocalRuntime == null) {
3781
- runtimeState.defaultLocalRuntime = new ActionRuntime(ActionClientSpecifier.unknown.specify({
3791
+ runtimeState.defaultLocalRuntime = new ActionRuntime(RuntimeCoordinate.unknown.specify({
3782
3792
  perId: `${runtimeState.assumedRuntimeInfo?.runtimeName ?? "unknown"}-runtime`
3783
3793
  }));
3784
3794
  }
@@ -3828,7 +3838,7 @@ class ActionLocalHandler extends ActionHandler {
3828
3838
  targetLocalRuntime
3829
3839
  });
3830
3840
  action.context.addRouteItem({
3831
- runtime: targetLocalRuntime.clientSpecifier,
3841
+ runtime: targetLocalRuntime.coordinate,
3832
3842
  handler: this.toHandlerRouteItem(),
3833
3843
  time: Date.now()
3834
3844
  });
@@ -3980,12 +3990,12 @@ class ActionDomain extends ActionDomainBase {
3980
3990
  cuid: contextData.cuid,
3981
3991
  routing: contextData.routing.map((item) => {
3982
3992
  return {
3983
- runtime: new ActionClientSpecifier(item.runtime),
3993
+ runtime: new RuntimeCoordinate(item.runtime),
3984
3994
  handler: item.handler,
3985
3995
  time: item.time
3986
3996
  };
3987
3997
  }),
3988
- originClient: contextData.originClient ? new ActionClientSpecifier(contextData.originClient) : ActionClientSpecifier.unknown
3998
+ originClient: contextData.originClient ? new RuntimeCoordinate(contextData.originClient) : RuntimeCoordinate.unknown
3989
3999
  });
3990
4000
  }
3991
4001
  isDomainAction(action) {
@@ -4080,14 +4090,14 @@ class ActionRuntimeManager {
4080
4090
  this._context = context ?? {};
4081
4091
  }
4082
4092
  registerRuntime(runtime2) {
4083
- const runtimeId = runtime2.clientSpecifier.stringId;
4093
+ const runtimeId = runtime2.coordinate.stringId;
4084
4094
  if (this._runtimes.has(runtimeId)) {
4085
4095
  throw err_nice_action.fromId("client_runtime_already_registered" /* client_runtime_already_registered */, {
4086
4096
  context: this._context,
4087
- client: runtime2.clientSpecifier
4097
+ client: runtime2.coordinate
4088
4098
  });
4089
4099
  }
4090
- for (const id of runtime2.clientSpecifier.toStringIds()) {
4100
+ for (const id of runtime2.coordinate.toStringIds()) {
4091
4101
  if (this._runtimes.has(id)) {
4092
4102
  continue;
4093
4103
  }
@@ -4097,7 +4107,7 @@ class ActionRuntimeManager {
4097
4107
  getRuntimeAndHandlerForAction(action, options, throwOnIssue) {
4098
4108
  const localRuntime = options?.targetLocalRuntime;
4099
4109
  if (localRuntime != null) {
4100
- const runtime2 = throwOnIssue ? this.getBestRuntimeOrThrow(options?.targetLocalRuntime?.clientSpecifier) : this.getBestRuntime(options?.targetLocalRuntime?.clientSpecifier);
4110
+ const runtime2 = throwOnIssue ? this.getBestRuntimeOrThrow(options?.targetLocalRuntime?.coordinate) : this.getBestRuntime(options?.targetLocalRuntime?.coordinate);
4101
4111
  if (runtime2 == null) {
4102
4112
  return;
4103
4113
  }
@@ -4109,7 +4119,7 @@ class ActionRuntimeManager {
4109
4119
  throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
4110
4120
  domain: action.domain,
4111
4121
  actionId: action.id,
4112
- specifiedClient: localRuntime.clientSpecifier
4122
+ specifiedClient: localRuntime.coordinate
4113
4123
  });
4114
4124
  }
4115
4125
  }
@@ -4123,7 +4133,7 @@ class ActionRuntimeManager {
4123
4133
  throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
4124
4134
  domain: action.domain,
4125
4135
  actionId: action.id,
4126
- specifiedClient: options?.targetLocalRuntime?.clientSpecifier
4136
+ specifiedClient: options?.targetLocalRuntime?.coordinate
4127
4137
  });
4128
4138
  }
4129
4139
  }
@@ -4131,7 +4141,7 @@ class ActionRuntimeManager {
4131
4141
  return this.getRuntimeAndHandlerForAction(action, options, true);
4132
4142
  }
4133
4143
  setPreferredRuntime(runtime2) {
4134
- const runtimeId = runtime2.clientSpecifier.stringId;
4144
+ const runtimeId = runtime2.coordinate.stringId;
4135
4145
  this._preferredRuntimeClientId = runtimeId;
4136
4146
  }
4137
4147
  getPreferredRuntime() {
@@ -4144,7 +4154,7 @@ class ActionRuntimeManager {
4144
4154
  return this._runtimes.values().next().value;
4145
4155
  }
4146
4156
  getBestRuntimeForSpecifier(clientSpecifier) {
4147
- const actionClient = new ActionClientSpecifier(clientSpecifier);
4157
+ const actionClient = new RuntimeCoordinate(clientSpecifier);
4148
4158
  const ids = actionClient.toStringIds();
4149
4159
  for (const id of ids) {
4150
4160
  const runtime2 = this._runtimes.get(id);
@@ -4166,7 +4176,7 @@ class ActionRuntimeManager {
4166
4176
  }
4167
4177
  throw err_nice_action.fromId("client_runtime_not_registered" /* client_runtime_not_registered */, {
4168
4178
  context: this._context,
4169
- clientStringId: clientSpecifierToStringIds(specifier)[0]
4179
+ clientStringId: runtimeCoordinateToStringIds(specifier)[0]
4170
4180
  });
4171
4181
  }
4172
4182
  return runtime2;
@@ -4210,7 +4220,7 @@ class ActionRootDomain extends ActionDomainBase {
4210
4220
  }
4211
4221
  async _runAction(actionPayload, options) {
4212
4222
  const { handler, runtime: runtime2 } = this._actionRuntimeManager.getRuntimeAndHandlerForActionOrThrow(actionPayload, options);
4213
- actionPayload.context._setOriginClient(runtime2.clientSpecifier);
4223
+ actionPayload.context._setOriginClient(runtime2.coordinate);
4214
4224
  const allListeners = [...this._listeners, ...options?.listeners ?? []];
4215
4225
  const runningAction = await handler.handleActionRequest(actionPayload, {
4216
4226
  targetLocalRuntime: runtime2
@@ -7398,7 +7408,7 @@ class ActionExternalClientHandler extends ActionHandler {
7398
7408
  }
7399
7409
  async handleActionRequest(action, config) {
7400
7410
  const localRuntime = config?.targetLocalRuntime ?? ActionRuntime.getDefault();
7401
- const localClient = localRuntime.clientSpecifier;
7411
+ const localClient = localRuntime.coordinate;
7402
7412
  const incomingTimeout = config?.timeout ?? this._defaultTimeout;
7403
7413
  const { methods, transport } = await this.transportManager.getReadyTransport({
7404
7414
  action,
@@ -7431,7 +7441,7 @@ class ActionExternalClientHandler extends ActionHandler {
7431
7441
  return runningAction;
7432
7442
  }
7433
7443
  async sendReturnPayload(payload, config) {
7434
- const localClient = config.targetLocalRuntime.clientSpecifier;
7444
+ const localClient = config.targetLocalRuntime.coordinate;
7435
7445
  try {
7436
7446
  const { methods } = await this.transportManager.getReadyTransport({
7437
7447
  action: payload,
@@ -7479,6 +7489,7 @@ export {
7479
7489
  TransportWebSocket,
7480
7490
  TransportHttp,
7481
7491
  Transport,
7492
+ RuntimeCoordinate,
7482
7493
  RunningAction,
7483
7494
  ETransportType,
7484
7495
  ETransportStatus,
@@ -7496,6 +7507,5 @@ export {
7496
7507
  ActionLocalHandler,
7497
7508
  ActionExternalClientHandler,
7498
7509
  ActionDomain,
7499
- ActionCore,
7500
- ActionClientSpecifier
7510
+ ActionCore
7501
7511
  };
@@ -3108,23 +3108,23 @@ function useActionMutation(action, options) {
3108
3108
  });
3109
3109
  }
3110
3110
  // src/react-query/hooks/useActionQuery.ts
3111
- function niceActionQueryKey(action, input) {
3111
+ function actionQueryKey(action, input) {
3112
3112
  if (input === undefined) {
3113
3113
  return ["nice-action", action.domain, action.allDomains, action.id];
3114
3114
  }
3115
3115
  return ["nice-action", action.domain, action.allDomains, action.id, input];
3116
3116
  }
3117
- function useNiceQuery(action, input, options) {
3117
+ function useActionQuery(action, input, options) {
3118
3118
  const { enabled, ...queryOptions2 } = options ?? {};
3119
3119
  return useQuery({
3120
- queryKey: input != null ? niceActionQueryKey(action, input) : niceActionQueryKey(action),
3120
+ queryKey: input != null ? actionQueryKey(action, input) : actionQueryKey(action),
3121
3121
  queryFn: () => action.request(input).runToOutput(),
3122
3122
  enabled: input != null && (enabled ?? true),
3123
3123
  ...queryOptions2
3124
3124
  });
3125
3125
  }
3126
3126
  export {
3127
- useNiceQuery,
3127
+ useActionQuery,
3128
3128
  useActionMutation,
3129
- niceActionQueryKey
3129
+ actionQueryKey
3130
3130
  };
@@ -1,4 +1,4 @@
1
- import { ActionClientSpecifier } from "../../../ActionRuntime/Client/ActionClientSpecifier";
1
+ import { RuntimeCoordinate } from "../../../ActionRuntime/RuntimeCoordinate";
2
2
  import type { ActionDomain } from "../../Domain/ActionDomain";
3
3
  import type { IActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../../Domain/ActionDomain.types";
4
4
  import { ActionBase } from "../ActionBase";
@@ -10,9 +10,9 @@ export declare class ActionContext<DOM extends IActionDomain, ID extends keyof D
10
10
  readonly _routing: IActionRouteItem[];
11
11
  readonly timeCreated: number;
12
12
  readonly cuid: string;
13
- originClient: ActionClientSpecifier;
13
+ originClient: RuntimeCoordinate;
14
14
  constructor(_domain: ActionDomain<DOM>, id: ID, hydrationData: IActionContext_Data);
15
- _setOriginClient(client: ActionClientSpecifier): void;
15
+ _setOriginClient(client: RuntimeCoordinate): void;
16
16
  toJsonString(): string;
17
17
  toContextDataJsonObject(): IActionContext_Data_JsonObject;
18
18
  toJsonObject(): IActionContext_JsonObject<DOM, ID>;
@@ -1,9 +1,9 @@
1
- import type { ActionClientSpecifier, IActionClientSpecifier } from "../../../ActionRuntime/Client/ActionClientSpecifier";
1
+ import type { IRuntimeCoordinate, RuntimeCoordinate } from "../../../ActionRuntime/RuntimeCoordinate";
2
2
  import type { IActionDomain } from "../../Domain/ActionDomain.types";
3
3
  import type { EActionForm, IActionBase, IActionBase_JsonObject } from "../ActionBase.types";
4
4
  import type { IActionRouteItemHandler } from "../Payload/ActionPayload.types";
5
5
  export interface IActionRouteItem {
6
- runtime: ActionClientSpecifier;
6
+ runtime: RuntimeCoordinate;
7
7
  handler: IActionRouteItemHandler;
8
8
  time: number;
9
9
  }
@@ -11,7 +11,7 @@ export interface IActionContext_Data {
11
11
  cuid: string;
12
12
  timeCreated: number;
13
13
  routing: IActionRouteItem[];
14
- originClient: ActionClientSpecifier;
14
+ originClient: RuntimeCoordinate;
15
15
  }
16
16
  export interface IActionContext<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IActionBase<EActionForm.context, DOM, ID>, IActionContext_Data {
17
17
  }
@@ -21,7 +21,7 @@ export interface IActionContext<DOM extends IActionDomain, ID extends keyof DOM[
21
21
  *
22
22
  */
23
23
  export interface IActionRouteItem_JsonObject {
24
- runtime: IActionClientSpecifier;
24
+ runtime: IRuntimeCoordinate;
25
25
  handler: IActionRouteItemHandler;
26
26
  time: number;
27
27
  }
@@ -29,7 +29,7 @@ export interface IActionContext_Data_JsonObject {
29
29
  cuid: string;
30
30
  timeCreated: number;
31
31
  routing: IActionRouteItem_JsonObject[];
32
- originClient: IActionClientSpecifier;
32
+ originClient: IRuntimeCoordinate;
33
33
  }
34
34
  export interface IActionContext_JsonObject<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IActionBase_JsonObject<EActionForm.context, DOM, ID>, IActionContext_Data_JsonObject {
35
35
  }
@@ -11,7 +11,7 @@ export declare class ActionCore<DOM extends IActionDomain, ID extends keyof DOM[
11
11
  constructor(_domain: ActionDomain<DOM>, id: ID);
12
12
  is<ACT extends IActionBase<any, any, any>>(action: ACT | unknown | null | undefined): action is TNarrowActionType<DOM, ACT, ID>;
13
13
  toJsonObject(): IActionBase_JsonObject<EActionForm.core, DOM, ID>;
14
- request(input: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]): ActionPayload_Request<DOM, ID>;
14
+ request(...args: [TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]] extends [never] ? [input?: never] : [input: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]]): ActionPayload_Request<DOM, ID>;
15
15
  deserializeInput(serialized: TInferInputFromSchema<DOM["actionSchema"][ID]>["SerdeInput"]): TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"];
16
16
  serializeInput(raw: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]): TInferInputFromSchema<DOM["actionSchema"][ID]>["SerdeInput"];
17
17
  validateInput(input: unknown): TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"];
@@ -39,5 +39,5 @@ export type TInferOutputFromSchema<SCH extends ActionSchema<any, any, any>> = SC
39
39
  SerdeOutput: OUT[1];
40
40
  } : never;
41
41
  export type TWrappableDomainActionHandler<DOM extends IActionDomain> = {
42
- [K in TDomainActionId<DOM>]: (input: TInferInputFromSchema<DOM["actionSchema"][K]>["Input"]) => Promise<TInferOutputFromSchema<DOM["actionSchema"][K]>["Output"]>;
42
+ [K in TDomainActionId<DOM>]: (...args: [TInferInputFromSchema<DOM["actionSchema"][K]>["Input"]] extends [never] ? [] : [input: TInferInputFromSchema<DOM["actionSchema"][K]>["Input"]]) => [TInferOutputFromSchema<DOM["actionSchema"][K]>["Output"]] extends [never] ? Promise<void> | void : Promise<TInferOutputFromSchema<DOM["actionSchema"][K]>["Output"]>;
43
43
  };
@@ -1,6 +1,6 @@
1
1
  import type { ActionRuntime } from "../../ActionRuntime/ActionRuntime";
2
- import type { IActionClientSpecifier } from "../../ActionRuntime/Client/ActionClientSpecifier";
3
2
  import type { IExecuteActionOptions } from "../../ActionRuntime/Handler/ActionHandler.types";
3
+ import type { IRuntimeCoordinate } from "../../ActionRuntime/RuntimeCoordinate";
4
4
  import type { ActionPayload_Request } from "../Action/Payload/ActionPayload_Request";
5
5
  import type { RunningAction } from "../Action/RunningAction";
6
6
  import { ActionDomain } from "./ActionDomain";
@@ -18,6 +18,6 @@ export declare class ActionRootDomain<ROOT_DOM extends IActionRootDomain = IActi
18
18
  [K in Exclude<keyof SUB_DOM, keyof IActionDomainChildOptions>]: never;
19
19
  }): ActionDomain<TActionDomainChildDef<ROOT_DOM, SUB_DOM>>;
20
20
  addActionRuntime(runtime: ActionRuntime): this;
21
- getRuntime(clientSpecifier: IActionClientSpecifier): ActionRuntime | undefined;
21
+ getRuntime(clientSpecifier: IRuntimeCoordinate): ActionRuntime | undefined;
22
22
  _runAction<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string, ACT extends ActionPayload_Request<DOM, ID> = ActionPayload_Request<DOM, ID>>(actionPayload: ACT, options?: IExecuteActionOptions<DOM, ID>): Promise<RunningAction<DOM, ID>>;
23
23
  }
@@ -3,18 +3,20 @@ import { type TActionPayload_Any_JsonObject } from "../ActionDefinition/Action/P
3
3
  import { RunningAction } from "../ActionDefinition/Action/RunningAction";
4
4
  import type { IActionDomain } from "../ActionDefinition/Domain/ActionDomain.types";
5
5
  import type { IRuntimeMeta, TActionRuntimeHandler } from "./ActionRuntime.types";
6
- import { ActionClientSpecifier } from "./Client/ActionClientSpecifier";
7
6
  import { type IHandleActionOptions, type TActionHandler } from "./Handler/ActionHandler.types";
8
7
  import type { ActionExternalClientHandler } from "./Handler/ExternalClient/ActionExternalClientHandler";
8
+ import { RuntimeCoordinate } from "./RuntimeCoordinate";
9
9
  export declare class ActionRuntime {
10
- readonly clientSpecifier: ActionClientSpecifier;
10
+ private _coordinate;
11
11
  readonly timeCreated: number;
12
12
  readonly runtimeInfo: IRuntimeMeta;
13
13
  private readonly actionRouter;
14
14
  private readonly _pendingRunningActions;
15
15
  private readonly _registeredExternalHandlers;
16
16
  static getDefault(): ActionRuntime;
17
- constructor(client: ActionClientSpecifier);
17
+ constructor(coordinate: RuntimeCoordinate);
18
+ get coordinate(): RuntimeCoordinate;
19
+ updateRuntimeCoordinate(newCoordinate: RuntimeCoordinate): void;
18
20
  registerRunningAction(ra: RunningAction<any, any>): void;
19
21
  resolveIncomingActionPayload(json: TActionPayload_Any_JsonObject<any, any>): void;
20
22
  /**
@@ -38,6 +40,6 @@ export declare class ActionRuntime {
38
40
  * Used to locate the return-path channel for dispatching results back to the action origin.
39
41
  * Returns `undefined` if no handler matches (score > 0 required, i.e. at least id must match).
40
42
  */
41
- getReturnHandlerForOrigin(originClient: ActionClientSpecifier): ActionExternalClientHandler | undefined;
43
+ getReturnHandlerForOrigin(originClient: RuntimeCoordinate): ActionExternalClientHandler | undefined;
42
44
  private _trySetupReturnDispatch;
43
45
  }
@@ -1,15 +1,15 @@
1
1
  import type { RuntimeName } from "std-env";
2
2
  import type { ActionRuntime } from "./ActionRuntime";
3
- import type { ActionClientSpecifier } from "./Client/ActionClientSpecifier";
4
3
  import type { TActionHandler } from "./Handler/ActionHandler.types";
5
4
  import type { ActionExternalClientHandler } from "./Handler/ExternalClient/ActionExternalClientHandler";
6
5
  import type { ActionLocalHandler } from "./Handler/Local/ActionLocalHandler";
6
+ import type { RuntimeCoordinate } from "./RuntimeCoordinate";
7
7
  export interface IRuntimeMeta {
8
8
  assumed: boolean;
9
9
  runtimeName: RuntimeName;
10
10
  }
11
11
  export interface IRuntimeEnvironmentMeta {
12
- client: ActionClientSpecifier;
12
+ client: RuntimeCoordinate;
13
13
  runtimeInfo: IRuntimeMeta;
14
14
  }
15
15
  export interface IActionRuntimeManagerContext {
@@ -1,8 +1,8 @@
1
1
  import type { TActionPayload_Any_Instance } from "../ActionDefinition/Action/Payload/ActionPayload.types";
2
2
  import type { ActionRuntime } from "./ActionRuntime";
3
3
  import type { IActionHandlerAndRuntime, IActionRuntimeManagerContext } from "./ActionRuntime.types";
4
- import { type IActionClientSpecifier } from "./Client/ActionClientSpecifier";
5
4
  import type { IHandleActionOptions } from "./Handler/ActionHandler.types";
5
+ import { type IRuntimeCoordinate } from "./RuntimeCoordinate";
6
6
  export declare class ActionRuntimeManager {
7
7
  private _runtimes;
8
8
  private _preferredRuntimeClientId;
@@ -13,7 +13,7 @@ export declare class ActionRuntimeManager {
13
13
  getRuntimeAndHandlerForActionOrThrow(action: TActionPayload_Any_Instance<any, any>, options?: IHandleActionOptions): IActionHandlerAndRuntime;
14
14
  setPreferredRuntime(runtime: ActionRuntime): void;
15
15
  getPreferredRuntime(): ActionRuntime | undefined;
16
- getBestRuntimeForSpecifier(clientSpecifier: IActionClientSpecifier): ActionRuntime | undefined;
17
- getBestRuntime(clientSpecifier?: IActionClientSpecifier): ActionRuntime | undefined;
18
- getBestRuntimeOrThrow(specifier?: IActionClientSpecifier): ActionRuntime;
16
+ getBestRuntimeForSpecifier(clientSpecifier: IRuntimeCoordinate): ActionRuntime | undefined;
17
+ getBestRuntime(clientSpecifier?: IRuntimeCoordinate): ActionRuntime | undefined;
18
+ getBestRuntimeOrThrow(specifier?: IRuntimeCoordinate): ActionRuntime;
19
19
  }
@@ -4,8 +4,8 @@ import type { RunningAction } from "../../ActionDefinition/Action/RunningAction"
4
4
  import type { TRunningActionUpdateListener } from "../../ActionDefinition/Action/RunningAction.types";
5
5
  import type { IActionDomain } from "../../ActionDefinition/Domain/ActionDomain.types";
6
6
  import type { ActionRuntime } from "../ActionRuntime";
7
- import type { ActionClientSpecifier, IActionClientSpecifier } from "../Client/ActionClientSpecifier";
8
7
  import type { ActionRouter } from "../Routing/ActionRouter";
8
+ import type { IRuntimeCoordinate, RuntimeCoordinate } from "../RuntimeCoordinate";
9
9
  export declare enum EActionHandlerType {
10
10
  external = "external",
11
11
  local = "local"
@@ -14,14 +14,14 @@ export interface IActionHandler_Json<T extends EActionHandlerType> {
14
14
  type: T;
15
15
  }
16
16
  export interface IActionHandler_ExternalClient_Json extends IActionHandler_Json<EActionHandlerType.external> {
17
- client: IActionClientSpecifier;
17
+ client: IRuntimeCoordinate;
18
18
  }
19
19
  export interface IActionHandler_Local_Json extends IActionHandler_Json<EActionHandlerType.local> {
20
20
  }
21
21
  export type TActionHandler_Json = IActionHandler_Local_Json | IActionHandler_ExternalClient_Json;
22
22
  export interface IHandleActionOptions {
23
23
  timeout?: number;
24
- targetExternalClient?: ActionClientSpecifier;
24
+ targetExternalClient?: RuntimeCoordinate;
25
25
  targetLocalRuntime?: ActionRuntime;
26
26
  }
27
27
  export interface IExecuteActionOptions<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IHandleActionOptions {
@@ -53,7 +53,7 @@ export interface IActionHandler_Local extends IActionHandler_Base<EActionHandler
53
53
  export interface IHandleActionOptions_External extends IHandleActionOptions {
54
54
  }
55
55
  export interface IActionHandler_ExternalClient extends IActionHandler_Base<EActionHandlerType.external> {
56
- externalClient: ActionClientSpecifier;
56
+ externalClient: RuntimeCoordinate;
57
57
  handleActionRequest: <DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionPayload_Request<DOM, ID>, config?: IHandleActionOptions_External) => Promise<RunningAction<DOM, ID>>;
58
58
  _setIncomingActionDataListener(listener: (json: TActionPayload_Any_JsonObject<any>) => void): void;
59
59
  }
@@ -5,14 +5,14 @@ import { RunningAction } from "../../../ActionDefinition/Action/RunningAction";
5
5
  import type { ActionDomain } from "../../../ActionDefinition/Domain/ActionDomain";
6
6
  import type { IActionDomain } from "../../../ActionDefinition/Domain/ActionDomain.types";
7
7
  import { ActionRuntime } from "../../ActionRuntime";
8
- import { ActionClientSpecifier } from "../../Client/ActionClientSpecifier";
9
8
  import { ActionRouter } from "../../Routing/ActionRouter";
9
+ import { RuntimeCoordinate } from "../../RuntimeCoordinate";
10
10
  import { ActionHandler } from "../ActionHandler";
11
11
  import { EActionHandlerType, type IActionHandler_ExternalClient, type IActionHandler_ExternalClient_Json, type IHandleActionOptions } from "../ActionHandler.types";
12
12
  import type { IActionExternalClientRequestHandlerConfig } from "./ActionExternalClientHandler.types";
13
13
  import type { Transport } from "./Transport/Transport";
14
14
  export declare class ActionExternalClientHandler extends ActionHandler<EActionHandlerType.external> implements IActionHandler_ExternalClient {
15
- readonly externalClient: ActionClientSpecifier;
15
+ readonly externalClient: RuntimeCoordinate;
16
16
  readonly handlerType = EActionHandlerType.external;
17
17
  readonly cuid: string;
18
18
  private _defaultTimeout;
@@ -1,7 +1,7 @@
1
- import type { ActionClientSpecifier } from "../../Client/ActionClientSpecifier";
1
+ import type { RuntimeCoordinate } from "../../RuntimeCoordinate";
2
2
  import type { TActionTransportDef } from "./Transport/Transport.combined.types";
3
3
  export interface IActionExternalClientRequestHandlerConfig {
4
4
  defaultTimeout?: number;
5
- externalClientSpecifier: ActionClientSpecifier;
5
+ externalClientSpecifier: RuntimeCoordinate;
6
6
  transports: TActionTransportDef[];
7
7
  }
@@ -3,7 +3,7 @@ import type { IActionPayload_Request_JsonObject, IActionPayload_Result_JsonObjec
3
3
  import type { ActionPayload_Request } from "../../../../ActionDefinition/Action/Payload/ActionPayload_Request";
4
4
  import type { ActionPayload_Result } from "../../../../ActionDefinition/Action/Payload/ActionPayload_Result";
5
5
  import type { RunningAction } from "../../../../ActionDefinition/Action/RunningAction";
6
- import type { ActionClientSpecifier } from "../../../Client/ActionClientSpecifier";
6
+ import type { RuntimeCoordinate } from "../../../RuntimeCoordinate";
7
7
  import type { Transport } from "./Transport";
8
8
  export declare enum ETransportType {
9
9
  ws = "ws",
@@ -56,8 +56,8 @@ export type TTransportStatusInfo_GetTransport_Output<READY extends IActionTransp
56
56
  *
57
57
  */
58
58
  export interface ITransportRouteClientParams {
59
- localClient: ActionClientSpecifier;
60
- externalClient: ActionClientSpecifier;
59
+ localClient: RuntimeCoordinate;
60
+ externalClient: RuntimeCoordinate;
61
61
  }
62
62
  export interface ITransportRouteActionParams extends ITransportRouteClientParams {
63
63
  action: TActionPayload_Any_Instance<any, any>;
@@ -0,0 +1,55 @@
1
+ export interface IRuntimeCoordinate {
2
+ /**
3
+ * A static runtime environment identifier (e.g. "web_app_v1", "backend_analytics")
4
+ */
5
+ envId: string;
6
+ /**
7
+ * A unique and persistent client ID (should stay the same between runtime instance reloads)
8
+ */
9
+ perId?: string;
10
+ /**
11
+ * A unique instance (or "memory-only") ID (unique for each instance of an action runtime, which should generally
12
+ * not persist between reloads, depending on the architecture)
13
+ */
14
+ insId?: string;
15
+ }
16
+ export type TRuntimeCoordinateStringId = `envId[${string}]perId[${string | "_"}]:insId[${string | "_"}]`;
17
+ export interface IRuntimeFullCoordinates extends Required<IRuntimeCoordinate> {
18
+ }
19
+ export declare class RuntimeCoordinate implements IRuntimeCoordinate {
20
+ readonly envId: string;
21
+ readonly perId?: string;
22
+ readonly insId?: string;
23
+ static get unknown(): RuntimeCoordinate;
24
+ static env(envId: string): RuntimeCoordinate;
25
+ withPersistentId(perId: string): RuntimeCoordinate;
26
+ constructor({ envId, perId, insId }: IRuntimeCoordinate);
27
+ specify(newInputs: Omit<IRuntimeCoordinate, "envId">): RuntimeCoordinate;
28
+ specifyIfUnset(newInputs: Omit<IRuntimeCoordinate, "envId">): RuntimeCoordinate;
29
+ toJsonObject(): IRuntimeCoordinate;
30
+ isExactlySame(other: IRuntimeCoordinate): boolean;
31
+ isSameFor(other: IRuntimeCoordinate): {
32
+ id: boolean;
33
+ perId: boolean;
34
+ insId: boolean;
35
+ };
36
+ similarityLevel(other: IRuntimeCoordinate): number;
37
+ get stringId(): TRuntimeCoordinateStringId;
38
+ /**
39
+ * Takes the "Runtime Coordinate" and generates a list of full coordinate IDs representing the runtime
40
+ * with decreasing levels of specificity.
41
+ *
42
+ * The first full coordinate ID is the most specific (including instance ID), while the last ID is
43
+ * the least specific (only environment ID).
44
+ *
45
+ * Example output for a RuntimeCoordinate with envId "web_app", perId "user123", and insId "instance456":
46
+ * [
47
+ * "envId[web_app]perId[user123]:insId[instance456]",
48
+ * "envId[web_app]perId[user123]:insId[_]",
49
+ * "envId[web_app]perId[_]:insId[_]"
50
+ * ]
51
+ *
52
+ * @returns a list of "full" runtime coordinate IDs with decreasing accuracy for targeting a runtime.
53
+ */
54
+ toStringIds(): TRuntimeCoordinateStringId[];
55
+ }
@@ -0,0 +1,2 @@
1
+ import type { IRuntimeCoordinate, TRuntimeCoordinateStringId } from "../RuntimeCoordinate";
2
+ export declare function runtimeCoordinateToStringIds(coordinate: IRuntimeCoordinate): TRuntimeCoordinateStringId[];
@@ -1,5 +1,5 @@
1
1
  import type { IActionRuntimeManagerContext } from "../ActionRuntime/ActionRuntime.types";
2
- import type { ActionClientSpecifier, TClientSpecifierStringId } from "../ActionRuntime/Client/ActionClientSpecifier";
2
+ import type { RuntimeCoordinate, TRuntimeCoordinateStringId } from "../ActionRuntime/RuntimeCoordinate";
3
3
  export declare enum EErrId_NiceAction {
4
4
  not_implemented = "not_implemented",
5
5
  action_id_not_in_domain = "action_id_not_in_domain",
@@ -53,7 +53,7 @@ export declare const err_nice_action: import("@nice-code/error").NiceErrorDomain
53
53
  no_action_execution_handler: import("@nice-code/error").INiceErrorIdMetadata<{
54
54
  domain: string;
55
55
  actionId: string;
56
- specifiedClient?: ActionClientSpecifier;
56
+ specifiedClient?: RuntimeCoordinate;
57
57
  }, import("@nice-code/error").JSONSerializableValue>;
58
58
  wire_action_not_payload: import("@nice-code/error").INiceErrorIdMetadata<{
59
59
  domain: string;
@@ -63,11 +63,11 @@ export declare const err_nice_action: import("@nice-code/error").NiceErrorDomain
63
63
  wire_not_action_data: import("@nice-code/error").INiceErrorIdMetadata<any, import("@nice-code/error").JSONSerializableValue>;
64
64
  client_runtime_already_registered: import("@nice-code/error").INiceErrorIdMetadata<{
65
65
  context?: IActionRuntimeManagerContext;
66
- client: ActionClientSpecifier;
66
+ client: RuntimeCoordinate;
67
67
  }, import("@nice-code/error").JSONSerializableValue>;
68
68
  client_runtime_not_registered: import("@nice-code/error").INiceErrorIdMetadata<{
69
69
  context?: IActionRuntimeManagerContext;
70
- clientStringId: TClientSpecifierStringId;
70
+ clientStringId: TRuntimeCoordinateStringId;
71
71
  }, import("@nice-code/error").JSONSerializableValue>;
72
72
  no_client_runtimes_registered: import("@nice-code/error").INiceErrorIdMetadata<{
73
73
  context?: IActionRuntimeManagerContext;
@@ -14,7 +14,6 @@ export { createActionRootDomain } from "./ActionDefinition/Domain/helpers/create
14
14
  export { ActionSchema, actionSchema, type TInferActionError, } from "./ActionDefinition/Schema/ActionSchema";
15
15
  export type { TActionSchemaOptions, TActionSerializationDefinition, TTransportedValue, } from "./ActionDefinition/Schema/ActionSchema.types";
16
16
  export { ActionRuntime } from "./ActionRuntime/ActionRuntime";
17
- export { ActionClientSpecifier, type IActionClientSpecifier, } from "./ActionRuntime/Client/ActionClientSpecifier";
18
17
  export { ActionExternalClientHandler, createExternalClientHandler, } from "./ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler";
19
18
  export * from "./ActionRuntime/Handler/ExternalClient/err_nice_external_client";
20
19
  export * from "./ActionRuntime/Handler/ExternalClient/Transport/err_nice_transport";
@@ -25,6 +24,7 @@ export type { TActionTransportDef } from "./ActionRuntime/Handler/ExternalClient
25
24
  export * from "./ActionRuntime/Handler/ExternalClient/Transport/Transport.types";
26
25
  export * from "./ActionRuntime/Handler/ExternalClient/Transport/WebSocket/TransportWebSocket";
27
26
  export { ActionLocalHandler, createLocalHandler, } from "./ActionRuntime/Handler/Local/ActionLocalHandler";
27
+ export { type IRuntimeCoordinate, RuntimeCoordinate, } from "./ActionRuntime/RuntimeCoordinate";
28
28
  export { EErrId_NiceAction, err_nice_action } from "./errors/err_nice_action";
29
29
  export { isActionPayload_Any_JsonObject } from "./utils/isActionPayload_Any_JsonObject";
30
30
  export * from "./utils/isActionPayload_Request_JsonObject";
@@ -1,3 +1,3 @@
1
1
  export declare const DEFAULT_TRANSPORT_TIMEOUT = 10000;
2
- export declare const UNSET_CLIENT_ID = "_unset_";
3
- export declare const UNSET_PERSISTENT_ID = "_0_0_";
2
+ export declare const UNSET_RUNTIME_ENV_ID = "_unset_";
3
+ export declare const UNSET_RUNTIME_PER_ID = "_0_0_";
@@ -1,6 +1,10 @@
1
1
  import { type UseMutationOptions, type UseMutationResult } from "@tanstack/react-query";
2
2
  import type { ActionCore } from "../../ActionDefinition/Action/Core/ActionCore";
3
3
  import type { IActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../../ActionDefinition/Domain/ActionDomain.types";
4
- import type { TInferActionError } from "../../ActionDefinition/Schema/ActionSchema";
5
- export type TUseNiceMutationOptions<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string, SCH extends DOM["actionSchema"][ID] = DOM["actionSchema"][ID], TContext = unknown> = Omit<UseMutationOptions<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>, TInferInputFromSchema<SCH>["Input"], TContext>, "mutationFn">;
6
- export declare function useActionMutation<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string, SCH extends DOM["actionSchema"][ID], TContext = unknown>(action: ActionCore<DOM, ID>, options?: TUseNiceMutationOptions<DOM, ID, SCH, TContext>): UseMutationResult<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>, TInferInputFromSchema<SCH>["Input"], TContext>;
4
+ import type { ActionSchema, TInferActionError } from "../../ActionDefinition/Schema/ActionSchema";
5
+ /** When an action has no input schema (Input = never), use void so mutate() needs no arguments. */
6
+ export type TActionMutationVars<SCH extends ActionSchema<any, any, any>> = [
7
+ TInferInputFromSchema<SCH>["Input"]
8
+ ] extends [never] ? void : TInferInputFromSchema<SCH>["Input"];
9
+ export type TUseNiceMutationOptions<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string, SCH extends DOM["actionSchema"][ID] = DOM["actionSchema"][ID], TContext = unknown> = Omit<UseMutationOptions<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>, TActionMutationVars<SCH>, TContext>, "mutationFn">;
10
+ export declare function useActionMutation<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string, SCH extends DOM["actionSchema"][ID], TContext = unknown>(action: ActionCore<DOM, ID>, options?: TUseNiceMutationOptions<DOM, ID, SCH, TContext>): UseMutationResult<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>, TActionMutationVars<SCH>, TContext>;
@@ -2,8 +2,8 @@ import { type QueryKey, type UseQueryOptions, type UseQueryResult } from "@tanst
2
2
  import type { ActionCore } from "../../ActionDefinition/Action/Core/ActionCore";
3
3
  import type { IActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../../ActionDefinition/Domain/ActionDomain.types";
4
4
  import type { TInferActionError } from "../../ActionDefinition/Schema/ActionSchema";
5
- export declare function niceActionQueryKey<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionCore<DOM, ID>): readonly ["nice-action", DOM["domain"], DOM["allDomains"], ID];
6
- export declare function niceActionQueryKey<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionCore<DOM, ID>, input: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]): readonly [
5
+ export declare function actionQueryKey<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionCore<DOM, ID>): readonly ["nice-action", DOM["domain"], DOM["allDomains"], ID];
6
+ export declare function actionQueryKey<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionCore<DOM, ID>, input: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]): readonly [
7
7
  "nice-action",
8
8
  DOM["domain"],
9
9
  DOM["allDomains"],
@@ -11,5 +11,5 @@ export declare function niceActionQueryKey<DOM extends IActionDomain, ID extends
11
11
  TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"],
12
12
  string | undefined
13
13
  ];
14
- export type TUseNiceQueryOptions<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string, SCH extends DOM["actionSchema"][ID] = DOM["actionSchema"][ID], TSelect = TInferOutputFromSchema<SCH>["Output"]> = Omit<UseQueryOptions<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>, TSelect, QueryKey>, "queryKey" | "queryFn">;
15
- export declare function useNiceQuery<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string, SCH extends DOM["actionSchema"][ID], TSelect = TInferOutputFromSchema<SCH>["Output"]>(action: ActionCore<DOM, ID>, input: TInferInputFromSchema<SCH>["Input"] | null | undefined, options?: TUseNiceQueryOptions<DOM, ID, SCH, TSelect>): UseQueryResult<TSelect, TInferActionError<SCH>>;
14
+ export type TUseActionQueryOptions<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string, SCH extends DOM["actionSchema"][ID] = DOM["actionSchema"][ID], TSelect = TInferOutputFromSchema<SCH>["Output"]> = Omit<UseQueryOptions<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>, TSelect, QueryKey>, "queryKey" | "queryFn">;
15
+ export declare function useActionQuery<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string, SCH extends DOM["actionSchema"][ID], TSelect = TInferOutputFromSchema<SCH>["Output"]>(action: ActionCore<DOM, ID>, input: TInferInputFromSchema<SCH>["Input"] | null | undefined, options?: TUseActionQueryOptions<DOM, ID, SCH, TSelect>): UseQueryResult<TSelect, TInferActionError<SCH>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nice-code/action",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,47 +0,0 @@
1
- export interface IActionClientSpecifier {
2
- /**
3
- * A static client identifier (e.g. "web_app_v1", "backend_analytics")
4
- */
5
- id: string;
6
- /**
7
- * A unique and persistant ID (between client instance reloads)
8
- */
9
- perId?: string;
10
- /**
11
- * A unique instance ID (unique for each instance of a client, does not persist between reloads)
12
- */
13
- insId?: string;
14
- }
15
- export type TClientSpecifierStringId = `id[${string}]perId[${string | "_"}]:insId[${string | "_"}]`;
16
- export interface IActionClientFullSpecifier extends Required<IActionClientSpecifier> {
17
- }
18
- export declare class ActionClientSpecifier implements IActionClientSpecifier {
19
- readonly id: string;
20
- readonly perId?: string;
21
- readonly insId?: string;
22
- static get unknown(): ActionClientSpecifier;
23
- static root(id: string): ActionClientSpecifier;
24
- withPersistentId(perId: string): ActionClientSpecifier;
25
- constructor({ id, perId, insId }: IActionClientSpecifier);
26
- specify(newInputs: Omit<IActionClientSpecifier, "id">): ActionClientSpecifier;
27
- specifyIfUnset(newInputs: Omit<IActionClientSpecifier, "id">): ActionClientSpecifier;
28
- toJsonObject(): IActionClientSpecifier;
29
- isExactlySame(other: IActionClientSpecifier): boolean;
30
- isSameFor(other: IActionClientSpecifier): {
31
- id: boolean;
32
- perId: boolean;
33
- insId: boolean;
34
- };
35
- similarityLevel(other: IActionClientSpecifier): number;
36
- get stringId(): TClientSpecifierStringId;
37
- /**
38
- * Generates a list of string IDs representing the client with decreasing levels of specificity.
39
- * The first ID is the most specific (including instance ID), while the last ID is the least specific (only client ID).
40
- *
41
- * Example output for a client with id "web_app", perId "user123", and insId "instance456":
42
- * ["id[web_app]perId[user123]:insId[instance456]", "id[web_app]perId[user123]:insId[_]", "id[web_app]perId[_]:insId[_]"]
43
- *
44
- * @returns a list of "string IDs" with decreasing target accuracy for the client
45
- */
46
- toStringIds(): TClientSpecifierStringId[];
47
- }
@@ -1,2 +0,0 @@
1
- import type { IActionClientSpecifier, TClientSpecifierStringId } from "../ActionClientSpecifier";
2
- export declare function clientSpecifierToStringIds(specifier: IActionClientSpecifier): TClientSpecifierStringId[];