@istar-ts/actions 0.15.0-beta.1 → 0.15.0-beta.3
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.cjs +78 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -4
- package/dist/index.d.ts +51 -4
- package/dist/index.js +79 -23
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyIstarModel, AnyPaletteDescription, CustomProperties, DiagnosticSeverity, ElementKind, FileMetamodel, GoalDiagnostic, IstarModel, LinkKind, Metamodel, ModelChange, ModelStore, PistarFile, PropertySchema, PropertyShape } from "@istar-ts/core";
|
|
1
|
+
import { AnyIstarModel, AnyMetamodel, AnyPaletteDescription, CustomProperties, DiagnosticSeverity, ElementKind, FileMetamodel, GoalDiagnostic, IstarModel, LinkKind, Metamodel, ModelChange, ModelStore, PistarFile, PropertySchema, PropertyShape } from "@istar-ts/core";
|
|
2
2
|
//#region src/actions.d.ts
|
|
3
3
|
/** GLSP's custom arguments: a flat map of primitives. */
|
|
4
4
|
export type Args = Readonly<Record<string, string | number | boolean>>;
|
|
@@ -281,6 +281,11 @@ export interface ModelSourceChangedAction extends Action {
|
|
|
281
281
|
* created with `sendModel`). An iStar extra; a mirror uses this to know the exact state.
|
|
282
282
|
*/
|
|
283
283
|
readonly canRedo?: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* The `origin` the causing `dispatch` was given, echoed back; absent for a change with none
|
|
286
|
+
* (a host's direct `store.load`, for instance). See `ActionDispatcher.dispatch`.
|
|
287
|
+
*/
|
|
288
|
+
readonly origin?: string;
|
|
284
289
|
}
|
|
285
290
|
/** Saves the model through the host's `save` callback. */
|
|
286
291
|
export interface SaveModelAction extends Action {
|
|
@@ -293,6 +298,8 @@ export interface SetDirtyStateAction extends Action {
|
|
|
293
298
|
readonly kind: "setDirtyState";
|
|
294
299
|
readonly isDirty: boolean;
|
|
295
300
|
readonly reason?: DirtyStateChangeReason;
|
|
301
|
+
/** The `origin` of the dispatch that caused this dirty-state change, echoed back; see `ModelSourceChangedAction.origin`. */
|
|
302
|
+
readonly origin?: string;
|
|
296
303
|
}
|
|
297
304
|
export interface UndoAction extends Action {
|
|
298
305
|
readonly kind: "glspUndo";
|
|
@@ -489,8 +496,31 @@ export type ActionListener<EK extends string = ElementKind, LK extends string =
|
|
|
489
496
|
* Sends actions and hears what the other side sends back. Implemented in-process by
|
|
490
497
|
* `createActionDispatcher`; a transport implements it over a message port.
|
|
491
498
|
*/
|
|
499
|
+
/** `dispatch`'s second argument. */
|
|
500
|
+
export interface DispatchOptions {
|
|
501
|
+
/**
|
|
502
|
+
* Echoed back as `origin` on every `ModelSourceChangedAction` and `SetDirtyStateAction` this
|
|
503
|
+
* dispatch causes (each change of a compound, both events of an undo or redo), so a listener
|
|
504
|
+
* can tell which surface or client made a change without tracking it itself. Carried through
|
|
505
|
+
* `createRemoteDispatcher`/`connectDispatcher` and by `createMirrorStore`'s dispatcher, so it
|
|
506
|
+
* survives a round trip to a remote host. Optional: a change with no origin (a host's direct
|
|
507
|
+
* `store.load`, for instance) has none.
|
|
508
|
+
*/
|
|
509
|
+
readonly origin?: string;
|
|
510
|
+
}
|
|
492
511
|
export interface ActionDispatcher<EK extends string = ElementKind, LK extends string = LinkKind> {
|
|
493
|
-
|
|
512
|
+
/**
|
|
513
|
+
* For a **local** dispatcher (`createActionDispatcher`), an operation, `glspUndo`/`glspRedo`,
|
|
514
|
+
* and the guards and postGuards around them, are applied to the store and every listener
|
|
515
|
+
* (`subscribe`, the store's own) is notified synchronously, before this call's promise is
|
|
516
|
+
* created to resolve — only `saveModel` awaits. Code that needs to see the result of an action
|
|
517
|
+
* before its own next statement (not just before `await dispatch(...)` resolves) can rely on
|
|
518
|
+
* this for a local dispatcher; it does **not** hold across a `createRemoteDispatcher`/
|
|
519
|
+
* `connectDispatcher` transport or a `createMirrorStore` mirror, where a change always arrives
|
|
520
|
+
* after a message round trip. Use `origin` ({@link DispatchOptions}) instead where that
|
|
521
|
+
* portability matters — it is carried through both.
|
|
522
|
+
*/
|
|
523
|
+
dispatch<A extends IstarAction<EK, LK>>(action: A, options?: DispatchOptions): Promise<ActionResult<ResponseFor<A>>>;
|
|
494
524
|
/**
|
|
495
525
|
* Hears the actions the dispatcher sends: `ModelSourceChangedAction` after every model change,
|
|
496
526
|
* `SetDirtyStateAction` when the dirty state flips, and the notifications dispatched to it.
|
|
@@ -518,8 +548,14 @@ export interface ActionDispatcherOptions<EK extends string = ElementKind, LK ext
|
|
|
518
548
|
readonly guards?: readonly ActionGuard<EK, LK>[];
|
|
519
549
|
/** Run after each operation is applied; see `ActionPostGuard`. */
|
|
520
550
|
readonly postGuards?: readonly ActionPostGuard<EK, LK>[];
|
|
521
|
-
/**
|
|
522
|
-
|
|
551
|
+
/**
|
|
552
|
+
* What `RequestContextActions` offers: a fixed description, or a function evaluated on each
|
|
553
|
+
* request (so a host can track a registry or extensions that change after this dispatcher was
|
|
554
|
+
* created — a plain `AnyPaletteDescription` is read once, at creation). Default: derived from
|
|
555
|
+
* the model's current metamodel (`paletteFromMetamodel`), the same fallback `contributionFor`
|
|
556
|
+
* (`@istar-ts/glsp`) uses — not iStar 2.0's palette regardless of dialect.
|
|
557
|
+
*/
|
|
558
|
+
readonly palette?: AnyPaletteDescription | (() => AnyPaletteDescription);
|
|
523
559
|
/**
|
|
524
560
|
* Property schemas an operation must not break: an operation that adds an issue
|
|
525
561
|
* (`validateModelProperties`) is rejected. Their issues are also markers.
|
|
@@ -566,6 +602,15 @@ export declare function typeHintsFor<EK extends string, LK extends string>(metam
|
|
|
566
602
|
* lacks are left out.
|
|
567
603
|
*/
|
|
568
604
|
export declare function contextActionsFor<EK extends string, LK extends string>(palette: AnyPaletteDescription, metamodel: Metamodel<EK, LK>): Pick<SetContextActions, "actions" | "groups">;
|
|
605
|
+
/**
|
|
606
|
+
* A minimal palette for a metamodel with none of its own: one toolbar entry per visible kind
|
|
607
|
+
* (declaration order, actors first), labelled from the kind's own `label`. Kinds generated for
|
|
608
|
+
* an n-ary link (a hub, leg or end — `role` set) are hidden, as a hand-written palette would
|
|
609
|
+
* hide them (`KAOS_PALETTE`'s `RefinementLinkHub: false`, for instance). The fallback
|
|
610
|
+
* `createActionDispatcher` and `contributionFor` (`@istar-ts/glsp`) both use when no palette
|
|
611
|
+
* was given.
|
|
612
|
+
*/
|
|
613
|
+
export declare function paletteFromMetamodel(metamodel: AnyMetamodel): AnyPaletteDescription;
|
|
569
614
|
//#endregion
|
|
570
615
|
//#region src/host.d.ts
|
|
571
616
|
/** A host's knowledge for the model: a system-prompt section and/or an MCP resource. */
|
|
@@ -709,6 +754,8 @@ export interface JsonRpcRequest {
|
|
|
709
754
|
readonly id: JsonRpcId;
|
|
710
755
|
readonly method: string;
|
|
711
756
|
readonly params?: unknown;
|
|
757
|
+
/** The dispatch's `origin` (`DispatchOptions.origin`), carried to the server's `dispatch`. */
|
|
758
|
+
readonly origin?: string;
|
|
712
759
|
}
|
|
713
760
|
/** A subscriber event, sent with no `id`: it expects no response. */
|
|
714
761
|
export interface JsonRpcNotification {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyIstarModel, AnyPaletteDescription, CustomProperties, DiagnosticSeverity, ElementKind, FileMetamodel, GoalDiagnostic, IstarModel, LinkKind, Metamodel, ModelChange, ModelStore, PistarFile, PropertySchema, PropertyShape } from "@istar-ts/core";
|
|
1
|
+
import { AnyIstarModel, AnyMetamodel, AnyPaletteDescription, CustomProperties, DiagnosticSeverity, ElementKind, FileMetamodel, GoalDiagnostic, IstarModel, LinkKind, Metamodel, ModelChange, ModelStore, PistarFile, PropertySchema, PropertyShape } from "@istar-ts/core";
|
|
2
2
|
//#region src/actions.d.ts
|
|
3
3
|
/** GLSP's custom arguments: a flat map of primitives. */
|
|
4
4
|
export type Args = Readonly<Record<string, string | number | boolean>>;
|
|
@@ -281,6 +281,11 @@ export interface ModelSourceChangedAction extends Action {
|
|
|
281
281
|
* created with `sendModel`). An iStar extra; a mirror uses this to know the exact state.
|
|
282
282
|
*/
|
|
283
283
|
readonly canRedo?: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* The `origin` the causing `dispatch` was given, echoed back; absent for a change with none
|
|
286
|
+
* (a host's direct `store.load`, for instance). See `ActionDispatcher.dispatch`.
|
|
287
|
+
*/
|
|
288
|
+
readonly origin?: string;
|
|
284
289
|
}
|
|
285
290
|
/** Saves the model through the host's `save` callback. */
|
|
286
291
|
export interface SaveModelAction extends Action {
|
|
@@ -293,6 +298,8 @@ export interface SetDirtyStateAction extends Action {
|
|
|
293
298
|
readonly kind: "setDirtyState";
|
|
294
299
|
readonly isDirty: boolean;
|
|
295
300
|
readonly reason?: DirtyStateChangeReason;
|
|
301
|
+
/** The `origin` of the dispatch that caused this dirty-state change, echoed back; see `ModelSourceChangedAction.origin`. */
|
|
302
|
+
readonly origin?: string;
|
|
296
303
|
}
|
|
297
304
|
export interface UndoAction extends Action {
|
|
298
305
|
readonly kind: "glspUndo";
|
|
@@ -489,8 +496,31 @@ export type ActionListener<EK extends string = ElementKind, LK extends string =
|
|
|
489
496
|
* Sends actions and hears what the other side sends back. Implemented in-process by
|
|
490
497
|
* `createActionDispatcher`; a transport implements it over a message port.
|
|
491
498
|
*/
|
|
499
|
+
/** `dispatch`'s second argument. */
|
|
500
|
+
export interface DispatchOptions {
|
|
501
|
+
/**
|
|
502
|
+
* Echoed back as `origin` on every `ModelSourceChangedAction` and `SetDirtyStateAction` this
|
|
503
|
+
* dispatch causes (each change of a compound, both events of an undo or redo), so a listener
|
|
504
|
+
* can tell which surface or client made a change without tracking it itself. Carried through
|
|
505
|
+
* `createRemoteDispatcher`/`connectDispatcher` and by `createMirrorStore`'s dispatcher, so it
|
|
506
|
+
* survives a round trip to a remote host. Optional: a change with no origin (a host's direct
|
|
507
|
+
* `store.load`, for instance) has none.
|
|
508
|
+
*/
|
|
509
|
+
readonly origin?: string;
|
|
510
|
+
}
|
|
492
511
|
export interface ActionDispatcher<EK extends string = ElementKind, LK extends string = LinkKind> {
|
|
493
|
-
|
|
512
|
+
/**
|
|
513
|
+
* For a **local** dispatcher (`createActionDispatcher`), an operation, `glspUndo`/`glspRedo`,
|
|
514
|
+
* and the guards and postGuards around them, are applied to the store and every listener
|
|
515
|
+
* (`subscribe`, the store's own) is notified synchronously, before this call's promise is
|
|
516
|
+
* created to resolve — only `saveModel` awaits. Code that needs to see the result of an action
|
|
517
|
+
* before its own next statement (not just before `await dispatch(...)` resolves) can rely on
|
|
518
|
+
* this for a local dispatcher; it does **not** hold across a `createRemoteDispatcher`/
|
|
519
|
+
* `connectDispatcher` transport or a `createMirrorStore` mirror, where a change always arrives
|
|
520
|
+
* after a message round trip. Use `origin` ({@link DispatchOptions}) instead where that
|
|
521
|
+
* portability matters — it is carried through both.
|
|
522
|
+
*/
|
|
523
|
+
dispatch<A extends IstarAction<EK, LK>>(action: A, options?: DispatchOptions): Promise<ActionResult<ResponseFor<A>>>;
|
|
494
524
|
/**
|
|
495
525
|
* Hears the actions the dispatcher sends: `ModelSourceChangedAction` after every model change,
|
|
496
526
|
* `SetDirtyStateAction` when the dirty state flips, and the notifications dispatched to it.
|
|
@@ -518,8 +548,14 @@ export interface ActionDispatcherOptions<EK extends string = ElementKind, LK ext
|
|
|
518
548
|
readonly guards?: readonly ActionGuard<EK, LK>[];
|
|
519
549
|
/** Run after each operation is applied; see `ActionPostGuard`. */
|
|
520
550
|
readonly postGuards?: readonly ActionPostGuard<EK, LK>[];
|
|
521
|
-
/**
|
|
522
|
-
|
|
551
|
+
/**
|
|
552
|
+
* What `RequestContextActions` offers: a fixed description, or a function evaluated on each
|
|
553
|
+
* request (so a host can track a registry or extensions that change after this dispatcher was
|
|
554
|
+
* created — a plain `AnyPaletteDescription` is read once, at creation). Default: derived from
|
|
555
|
+
* the model's current metamodel (`paletteFromMetamodel`), the same fallback `contributionFor`
|
|
556
|
+
* (`@istar-ts/glsp`) uses — not iStar 2.0's palette regardless of dialect.
|
|
557
|
+
*/
|
|
558
|
+
readonly palette?: AnyPaletteDescription | (() => AnyPaletteDescription);
|
|
523
559
|
/**
|
|
524
560
|
* Property schemas an operation must not break: an operation that adds an issue
|
|
525
561
|
* (`validateModelProperties`) is rejected. Their issues are also markers.
|
|
@@ -566,6 +602,15 @@ export declare function typeHintsFor<EK extends string, LK extends string>(metam
|
|
|
566
602
|
* lacks are left out.
|
|
567
603
|
*/
|
|
568
604
|
export declare function contextActionsFor<EK extends string, LK extends string>(palette: AnyPaletteDescription, metamodel: Metamodel<EK, LK>): Pick<SetContextActions, "actions" | "groups">;
|
|
605
|
+
/**
|
|
606
|
+
* A minimal palette for a metamodel with none of its own: one toolbar entry per visible kind
|
|
607
|
+
* (declaration order, actors first), labelled from the kind's own `label`. Kinds generated for
|
|
608
|
+
* an n-ary link (a hub, leg or end — `role` set) are hidden, as a hand-written palette would
|
|
609
|
+
* hide them (`KAOS_PALETTE`'s `RefinementLinkHub: false`, for instance). The fallback
|
|
610
|
+
* `createActionDispatcher` and `contributionFor` (`@istar-ts/glsp`) both use when no palette
|
|
611
|
+
* was given.
|
|
612
|
+
*/
|
|
613
|
+
export declare function paletteFromMetamodel(metamodel: AnyMetamodel): AnyPaletteDescription;
|
|
569
614
|
//#endregion
|
|
570
615
|
//#region src/host.d.ts
|
|
571
616
|
/** A host's knowledge for the model: a system-prompt section and/or an MCP resource. */
|
|
@@ -709,6 +754,8 @@ export interface JsonRpcRequest {
|
|
|
709
754
|
readonly id: JsonRpcId;
|
|
710
755
|
readonly method: string;
|
|
711
756
|
readonly params?: unknown;
|
|
757
|
+
/** The dispatch's `origin` (`DispatchOptions.origin`), carried to the server's `dispatch`. */
|
|
758
|
+
readonly origin?: string;
|
|
712
759
|
}
|
|
713
760
|
/** A subscriber event, sent with no `id`: it expects no response. */
|
|
714
761
|
export interface JsonRpcNotification {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DIAGNOSTIC_SEVERITIES, FILE_METAMODEL_KEY, LINK_SELECTOR, MetamodelError, ModelOperationError, canLink, connectResultToDiagnostic, createEmptyModel, dependencyEnds, effectiveLinkKind, elementBehavesLike, inheritMetamodel, inheritSourceLayout, linkBehavesLike, metamodelOf, parsePistar, toPistarObject, validateModel, validateModelProperties, withFileMetamodel } from "@istar-ts/core";
|
|
2
2
|
//#region src/actions.ts
|
|
3
3
|
const OPERATION_KIND_LIST = [
|
|
4
4
|
"createNode",
|
|
@@ -185,6 +185,36 @@ function contextActionsFor(palette, metamodel) {
|
|
|
185
185
|
groups: palette.groups
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* A minimal palette for a metamodel with none of its own: one toolbar entry per visible kind
|
|
190
|
+
* (declaration order, actors first), labelled from the kind's own `label`. Kinds generated for
|
|
191
|
+
* an n-ary link (a hub, leg or end — `role` set) are hidden, as a hand-written palette would
|
|
192
|
+
* hide them (`KAOS_PALETTE`'s `RefinementLinkHub: false`, for instance). The fallback
|
|
193
|
+
* `createActionDispatcher` and `contributionFor` (`@istar-ts/glsp`) both use when no palette
|
|
194
|
+
* was given.
|
|
195
|
+
*/
|
|
196
|
+
function paletteFromMetamodel(metamodel) {
|
|
197
|
+
const elements = {};
|
|
198
|
+
let order = 0;
|
|
199
|
+
for (const definition of metamodel.elements.values()) elements[definition.kind] = definition.role !== void 0 ? false : {
|
|
200
|
+
label: definition.label,
|
|
201
|
+
order: order++,
|
|
202
|
+
section: definition.category === "actor" ? "actors" : "elements",
|
|
203
|
+
...definition.category === "actor" ? { group: "actors" } : {}
|
|
204
|
+
};
|
|
205
|
+
const links = {};
|
|
206
|
+
order = 0;
|
|
207
|
+
for (const definition of metamodel.links.values()) links[definition.kind] = definition.role !== void 0 ? false : [{
|
|
208
|
+
label: definition.label,
|
|
209
|
+
order: order++,
|
|
210
|
+
section: "elements"
|
|
211
|
+
}];
|
|
212
|
+
return {
|
|
213
|
+
elements,
|
|
214
|
+
links,
|
|
215
|
+
groups: { actors: { label: "Actor" } }
|
|
216
|
+
};
|
|
217
|
+
}
|
|
188
218
|
//#endregion
|
|
189
219
|
//#region src/markers.ts
|
|
190
220
|
/** A `GoalDiagnostic` as a GLSP marker: `kind` is its severity, `label` its message. */
|
|
@@ -276,22 +306,34 @@ function createActionDispatcher(store, options = {}) {
|
|
|
276
306
|
const s = store;
|
|
277
307
|
const guards = options.guards ?? [];
|
|
278
308
|
const postGuards = options.postGuards ?? [];
|
|
279
|
-
const
|
|
309
|
+
const resolvePalette = (meta) => {
|
|
310
|
+
const option = options.palette;
|
|
311
|
+
if (typeof option === "function") return option();
|
|
312
|
+
return option ?? paletteFromMetamodel(meta);
|
|
313
|
+
};
|
|
280
314
|
const sourceModelName = options.sourceModelName ?? "";
|
|
281
315
|
const listeners = /* @__PURE__ */ new Set();
|
|
282
316
|
let saved = s.getModel();
|
|
283
317
|
let dirty = false;
|
|
318
|
+
/**
|
|
319
|
+
* The origin of the dispatch currently applying synchronously (set by `dispatch`, around the
|
|
320
|
+
* synchronous part of `run`): what the store's subscription below echoes on
|
|
321
|
+
* `sourceModelChanged`/`setDirtyState`. `undefined` for a change not caused by a dispatch (a
|
|
322
|
+
* host's direct `store.load`) or once `run`'s synchronous part has returned.
|
|
323
|
+
*/
|
|
324
|
+
let currentOrigin;
|
|
284
325
|
const emit = (action) => {
|
|
285
326
|
for (const listener of listeners) listener(action);
|
|
286
327
|
};
|
|
287
|
-
const updateDirty = (reason) => {
|
|
328
|
+
const updateDirty = (reason, origin) => {
|
|
288
329
|
const next = s.getModel() !== saved;
|
|
289
330
|
if (next === dirty) return;
|
|
290
331
|
dirty = next;
|
|
291
332
|
emit({
|
|
292
333
|
kind: "setDirtyState",
|
|
293
334
|
isDirty: next,
|
|
294
|
-
reason
|
|
335
|
+
reason,
|
|
336
|
+
...origin === void 0 ? {} : { origin }
|
|
295
337
|
});
|
|
296
338
|
};
|
|
297
339
|
const REASONS = {
|
|
@@ -311,9 +353,10 @@ function createActionDispatcher(store, options = {}) {
|
|
|
311
353
|
...options.sendModel ? {
|
|
312
354
|
canUndo: s.canUndo(),
|
|
313
355
|
canRedo: s.canRedo()
|
|
314
|
-
} : {}
|
|
356
|
+
} : {},
|
|
357
|
+
...currentOrigin === void 0 ? {} : { origin: currentOrigin }
|
|
315
358
|
});
|
|
316
|
-
updateDirty(REASONS[event.source]);
|
|
359
|
+
updateDirty(REASONS[event.source], currentOrigin);
|
|
317
360
|
});
|
|
318
361
|
const requireElement = (id) => s.getModel().elements.get(id) ?? reject(`unknown element "${id}"`, id, "unknown-element");
|
|
319
362
|
const runGuards = (operation, warnings) => {
|
|
@@ -698,16 +741,19 @@ function createActionDispatcher(store, options = {}) {
|
|
|
698
741
|
...typeHintsFor(metaOf(model))
|
|
699
742
|
};
|
|
700
743
|
case "requestCheckEdge": return checkEdge(action);
|
|
701
|
-
case "requestContextActions":
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
744
|
+
case "requestContextActions": {
|
|
745
|
+
const meta = metaOf(model);
|
|
746
|
+
return {
|
|
747
|
+
kind: "setContextActions",
|
|
748
|
+
responseId: action.requestId,
|
|
749
|
+
...contextActionsFor(resolvePalette(meta), meta)
|
|
750
|
+
};
|
|
751
|
+
}
|
|
706
752
|
case "requestMarkers": return markers(action);
|
|
707
753
|
default: return;
|
|
708
754
|
}
|
|
709
755
|
};
|
|
710
|
-
const run = async (action) => {
|
|
756
|
+
const run = async (action, origin) => {
|
|
711
757
|
if (isOperation(action)) return runOperation(action);
|
|
712
758
|
if (isRequestAction(action)) return {
|
|
713
759
|
ok: true,
|
|
@@ -732,7 +778,7 @@ function createActionDispatcher(store, options = {}) {
|
|
|
732
778
|
const model = s.getModel();
|
|
733
779
|
await options.save(toPistarObject(model, { saveDate: /* @__PURE__ */ new Date() }), action);
|
|
734
780
|
saved = model;
|
|
735
|
-
updateDirty("save");
|
|
781
|
+
updateDirty("save", origin);
|
|
736
782
|
return {
|
|
737
783
|
ok: true,
|
|
738
784
|
createdIds: []
|
|
@@ -752,9 +798,17 @@ function createActionDispatcher(store, options = {}) {
|
|
|
752
798
|
}
|
|
753
799
|
};
|
|
754
800
|
return {
|
|
755
|
-
async dispatch(action) {
|
|
801
|
+
async dispatch(action, dispatchOptions) {
|
|
802
|
+
const origin = dispatchOptions?.origin;
|
|
803
|
+
currentOrigin = origin;
|
|
804
|
+
let pending;
|
|
805
|
+
try {
|
|
806
|
+
pending = run(action, origin);
|
|
807
|
+
} finally {
|
|
808
|
+
currentOrigin = void 0;
|
|
809
|
+
}
|
|
756
810
|
try {
|
|
757
|
-
return await
|
|
811
|
+
return await pending;
|
|
758
812
|
} catch (error) {
|
|
759
813
|
if (error instanceof Rejection) return {
|
|
760
814
|
ok: false,
|
|
@@ -978,8 +1032,8 @@ function createMirrorStore(remote, options = {}) {
|
|
|
978
1032
|
return {
|
|
979
1033
|
ready,
|
|
980
1034
|
dispatcher: {
|
|
981
|
-
async dispatch(action) {
|
|
982
|
-
const result = await r.dispatch(action);
|
|
1035
|
+
async dispatch(action, options) {
|
|
1036
|
+
const result = await r.dispatch(action, options);
|
|
983
1037
|
await tail;
|
|
984
1038
|
return result;
|
|
985
1039
|
},
|
|
@@ -1065,8 +1119,9 @@ function connectDispatcher(port, dispatcher) {
|
|
|
1065
1119
|
port.onmessage = (ev) => {
|
|
1066
1120
|
const message = ev.data;
|
|
1067
1121
|
if (!isRecord(message) || message.jsonrpc !== JSONRPC_VERSION) return;
|
|
1068
|
-
const { id, method, params } = message;
|
|
1122
|
+
const { id, method, params, origin } = message;
|
|
1069
1123
|
const hasId = isJsonRpcId(id);
|
|
1124
|
+
const dispatchOptions = typeof origin === "string" ? { origin } : void 0;
|
|
1070
1125
|
if (typeof method !== "string" || method.length === 0) {
|
|
1071
1126
|
if (hasId) port.postMessage(errorMessage(id, -32601, "method not found"));
|
|
1072
1127
|
return;
|
|
@@ -1077,10 +1132,10 @@ function connectDispatcher(port, dispatcher) {
|
|
|
1077
1132
|
}
|
|
1078
1133
|
const action = params;
|
|
1079
1134
|
if (!hasId) {
|
|
1080
|
-
dispatcher.dispatch(action);
|
|
1135
|
+
dispatcher.dispatch(action, dispatchOptions);
|
|
1081
1136
|
return;
|
|
1082
1137
|
}
|
|
1083
|
-
dispatcher.dispatch(action).then((result) => {
|
|
1138
|
+
dispatcher.dispatch(action, dispatchOptions).then((result) => {
|
|
1084
1139
|
port.postMessage({
|
|
1085
1140
|
jsonrpc: JSONRPC_VERSION,
|
|
1086
1141
|
id,
|
|
@@ -1124,7 +1179,7 @@ function createRemoteDispatcher(port) {
|
|
|
1124
1179
|
}
|
|
1125
1180
|
};
|
|
1126
1181
|
return {
|
|
1127
|
-
dispatch(action) {
|
|
1182
|
+
dispatch(action, dispatchOptions) {
|
|
1128
1183
|
const id = nextId++;
|
|
1129
1184
|
return new Promise((resolve, reject) => {
|
|
1130
1185
|
pending.set(id, {
|
|
@@ -1135,7 +1190,8 @@ function createRemoteDispatcher(port) {
|
|
|
1135
1190
|
jsonrpc: JSONRPC_VERSION,
|
|
1136
1191
|
id,
|
|
1137
1192
|
method: action.kind,
|
|
1138
|
-
params: action
|
|
1193
|
+
params: action,
|
|
1194
|
+
...dispatchOptions?.origin === void 0 ? {} : { origin: dispatchOptions.origin }
|
|
1139
1195
|
});
|
|
1140
1196
|
});
|
|
1141
1197
|
},
|
|
@@ -1150,6 +1206,6 @@ function createRemoteDispatcher(port) {
|
|
|
1150
1206
|
/** Version of the action protocol this package speaks. */
|
|
1151
1207
|
const ACTIONS_PROTOCOL_VERSION = "0.0.0";
|
|
1152
1208
|
//#endregion
|
|
1153
|
-
export { ACTIONS_PROTOCOL_VERSION, HANDLED_ACTION_KINDS, connectDispatcher, contextActionsFor, contextText, createActionDispatcher, createMirrorStore, createRemoteDispatcher, diagnosticToMarker, hostToolContext, isOperation, isRequestAction, markerToDiagnostic, readOnlyDispatcher, typeHintsFor };
|
|
1209
|
+
export { ACTIONS_PROTOCOL_VERSION, HANDLED_ACTION_KINDS, connectDispatcher, contextActionsFor, contextText, createActionDispatcher, createMirrorStore, createRemoteDispatcher, diagnosticToMarker, hostToolContext, isOperation, isRequestAction, markerToDiagnostic, paletteFromMetamodel, readOnlyDispatcher, typeHintsFor };
|
|
1154
1210
|
|
|
1155
1211
|
//# sourceMappingURL=index.js.map
|