@powerhousedao/shared 6.1.0-dev.2 → 6.1.0-dev.21
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/analytics/index.d.ts +1 -1
- package/dist/clis/args/access-token.mjs +1 -1
- package/dist/clis/args/common-BQ2pvhCr.d.mts.map +1 -1
- package/dist/clis/args/{common-DPYlcz-d.mjs → common-fPNESurz.mjs} +4 -9
- package/dist/clis/args/common-fPNESurz.mjs.map +1 -0
- package/dist/clis/args/common.mjs +1 -1
- package/dist/clis/args/connect.d.mts +219 -13
- package/dist/clis/args/connect.d.mts.map +1 -1
- package/dist/clis/args/connect.mjs +138 -4
- package/dist/clis/args/connect.mjs.map +1 -1
- package/dist/clis/args/{generate-BJPBa0mK.mjs → generate-CTTdiwMD.mjs} +2 -2
- package/dist/clis/args/{generate-BJPBa0mK.mjs.map → generate-CTTdiwMD.mjs.map} +1 -1
- package/dist/clis/args/generate.mjs +1 -1
- package/dist/clis/args/{help-rztSuf9S.mjs → help-CfBzQJpL.mjs} +3 -3
- package/dist/clis/args/{help-rztSuf9S.mjs.map → help-CfBzQJpL.mjs.map} +1 -1
- package/dist/clis/args/help.mjs +1 -1
- package/dist/clis/args/index.d.mts +3 -3
- package/dist/clis/args/index.mjs +5 -5
- package/dist/clis/args/init.d.mts +3 -0
- package/dist/clis/args/init.d.mts.map +1 -1
- package/dist/clis/args/init.mjs +6 -1
- package/dist/clis/args/init.mjs.map +1 -1
- package/dist/clis/args/inspect.mjs +1 -1
- package/dist/clis/args/install.mjs +1 -1
- package/dist/clis/args/list.mjs +1 -1
- package/dist/clis/args/login.mjs +1 -1
- package/dist/clis/args/migrate.mjs +1 -1
- package/dist/clis/args/publish.mjs +1 -1
- package/dist/clis/args/registry.mjs +1 -1
- package/dist/clis/args/{service-LXIFUZ_8.d.mts → service-DbbCQSks.d.mts} +2 -2
- package/dist/clis/args/service-DbbCQSks.d.mts.map +1 -0
- package/dist/clis/args/service.d.mts +1 -1
- package/dist/clis/args/service.mjs +1 -1
- package/dist/clis/args/switchboard.mjs +1 -1
- package/dist/clis/args/uninstall.mjs +1 -1
- package/dist/clis/args/unpublish.mjs +1 -1
- package/dist/clis/args/vetra.mjs +1 -1
- package/dist/clis/build-config.d.mts.map +1 -1
- package/dist/clis/build-config.mjs +2 -1
- package/dist/clis/build-config.mjs.map +1 -1
- package/dist/clis/constants.d.mts +62 -4
- package/dist/clis/constants.d.mts.map +1 -1
- package/dist/clis/constants.mjs +8 -3
- package/dist/clis/constants.mjs.map +1 -1
- package/dist/clis/index.d.mts +696 -22
- package/dist/clis/index.d.mts.map +1 -1
- package/dist/clis/index.mjs +546 -12
- package/dist/clis/index.mjs.map +1 -1
- package/dist/config-loader-DORViRnN.js +144 -0
- package/dist/config-loader-DORViRnN.js.map +1 -0
- package/dist/connect/config-loader.d.ts +78 -0
- package/dist/connect/config-loader.d.ts.map +1 -0
- package/dist/connect/config-loader.js +2 -0
- package/dist/connect/index.d.ts +295 -245
- package/dist/connect/index.d.ts.map +1 -1
- package/dist/connect/index.js +264 -103
- package/dist/connect/index.js.map +1 -1
- package/dist/connect/json-adapter.d.ts +24 -0
- package/dist/connect/json-adapter.d.ts.map +1 -0
- package/dist/connect/json-adapter.js +28 -0
- package/dist/connect/json-adapter.js.map +1 -0
- package/dist/{constants-xNwF0jSl.d.ts → constants-C_EQX4DY.d.ts} +1 -1
- package/dist/constants-C_EQX4DY.d.ts.map +1 -0
- package/dist/constants.d.ts +1 -1
- package/dist/document-drive/index.d.ts +2 -2
- package/dist/document-drive/index.d.ts.map +1 -1
- package/dist/document-drive/index.js +6 -10
- package/dist/document-drive/index.js.map +1 -1
- package/dist/document-model/index.d.ts +5 -5
- package/dist/document-model/index.js +212 -64
- package/dist/document-model/index.js.map +1 -1
- package/dist/document-model/mock.d.ts +1 -1
- package/dist/document-model/utils.d.ts +2 -2
- package/dist/document-model/utils.js +1 -1
- package/dist/{index-C_iVZe7f.d.ts → index-CQDIrK1k.d.ts} +1 -1
- package/dist/index-CQDIrK1k.d.ts.map +1 -0
- package/dist/{index-DkRWfM_V.d.ts → index-DalC_-i7.d.ts} +46 -3
- package/dist/{index-DkRWfM_V.d.ts.map → index-DalC_-i7.d.ts.map} +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/{mock-Cgn-VBF_.d.ts → mock-CbrXTFOF.d.ts} +1 -1
- package/dist/{mock-Cgn-VBF_.d.ts.map → mock-CbrXTFOF.d.ts.map} +1 -1
- package/dist/processors/index.d.ts +1 -1
- package/dist/registry/index.d.ts +2 -1
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js.map +1 -1
- package/dist/{types-BFDlQkXZ.d.ts → types-C1in4fl3.d.ts} +1 -1
- package/dist/{types-BFDlQkXZ.d.ts.map → types-C1in4fl3.d.ts.map} +1 -1
- package/dist/{actions-UH5nIJcP.d.ts → types-CC6ib3_2.d.ts} +1330 -1330
- package/dist/types-CC6ib3_2.d.ts.map +1 -0
- package/dist/{types-WzwAClp2.d.ts → types-CVqmv94G.d.ts} +3 -109
- package/dist/types-CVqmv94G.d.ts.map +1 -0
- package/dist/types-Daq_zHP_.d.ts +160 -0
- package/dist/types-Daq_zHP_.d.ts.map +1 -0
- package/dist/{utils-CJF4w5Bp.d.ts → utils-BEByNOHo.d.ts} +1 -1
- package/dist/utils-BEByNOHo.d.ts.map +1 -0
- package/dist/{utils-bCWnsmtD.js → utils-DKOFCM0Q.js} +1 -1
- package/dist/{utils-bCWnsmtD.js.map → utils-DKOFCM0Q.js.map} +1 -1
- package/package.json +6 -3
- package/dist/actions-UH5nIJcP.d.ts.map +0 -1
- package/dist/clis/args/common-DPYlcz-d.mjs.map +0 -1
- package/dist/clis/args/service-LXIFUZ_8.d.mts.map +0 -1
- package/dist/constants-xNwF0jSl.d.ts.map +0 -1
- package/dist/index-C_iVZe7f.d.ts.map +0 -1
- package/dist/types-WzwAClp2.d.ts.map +0 -1
- package/dist/utils-CJF4w5Bp.d.ts.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { a as buildOperationSignatureParams, c as hex2ab, i as buildOperationSignatureMessage, n as generateId, o as getUnixTimestamp, r as ab2hex, s as hashBrowser, t as deriveOperationId } from "../utils-
|
|
1
|
+
import { a as buildOperationSignatureParams, c as hex2ab, i as buildOperationSignatureMessage, n as generateId, o as getUnixTimestamp, r as ab2hex, s as hashBrowser, t as deriveOperationId } from "../utils-DKOFCM0Q.js";
|
|
2
2
|
import { generateMock } from "./mock.js";
|
|
3
3
|
import { ZodError, z } from "zod";
|
|
4
4
|
import { stringify } from "safe-stable-stringify";
|
|
5
5
|
import { strFromU8, strToU8, unzip, zip } from "fflate";
|
|
6
6
|
import { castDraft, create, unsafe } from "mutative";
|
|
7
|
-
import { pascalCase } from "change-case";
|
|
7
|
+
import { constantCase, pascalCase } from "change-case";
|
|
8
8
|
//#region document-model/errors.ts
|
|
9
9
|
const FileSystemError = /* @__PURE__ */ new Error("File system not available.");
|
|
10
10
|
var InvalidActionInputError = class extends Error {
|
|
@@ -1648,16 +1648,72 @@ function isDocumentAction(action) {
|
|
|
1648
1648
|
].includes(action.type);
|
|
1649
1649
|
}
|
|
1650
1650
|
/**
|
|
1651
|
-
*
|
|
1652
|
-
*
|
|
1651
|
+
* The document-scope operations a reactor mints on `create`, so a standalone
|
|
1652
|
+
* document carries its initial state when exported outside a reactor.
|
|
1653
1653
|
*/
|
|
1654
|
-
function
|
|
1654
|
+
function createDocumentScopeOperations(header, state) {
|
|
1655
|
+
const createInput = {
|
|
1656
|
+
model: header.documentType,
|
|
1657
|
+
version: 0,
|
|
1658
|
+
documentId: header.id,
|
|
1659
|
+
signing: {
|
|
1660
|
+
signature: header.id,
|
|
1661
|
+
publicKey: header.sig.publicKey,
|
|
1662
|
+
nonce: header.sig.nonce,
|
|
1663
|
+
createdAtUtcIso: header.createdAtUtcIso,
|
|
1664
|
+
documentType: header.documentType
|
|
1665
|
+
},
|
|
1666
|
+
slug: header.slug,
|
|
1667
|
+
name: header.name,
|
|
1668
|
+
branch: header.branch,
|
|
1669
|
+
meta: header.meta,
|
|
1670
|
+
protocolVersions: header.protocolVersions ?? { "base-reducer": 2 }
|
|
1671
|
+
};
|
|
1672
|
+
const upgradeInput = {
|
|
1673
|
+
model: header.documentType,
|
|
1674
|
+
fromVersion: 0,
|
|
1675
|
+
toVersion: state.document.version,
|
|
1676
|
+
documentId: header.id,
|
|
1677
|
+
initialState: state
|
|
1678
|
+
};
|
|
1679
|
+
return [{
|
|
1680
|
+
id: generateId(),
|
|
1681
|
+
type: "CREATE_DOCUMENT",
|
|
1682
|
+
scope: "document",
|
|
1683
|
+
timestampUtcMs: header.createdAtUtcIso,
|
|
1684
|
+
input: createInput
|
|
1685
|
+
}, {
|
|
1686
|
+
id: generateId(),
|
|
1687
|
+
type: "UPGRADE_DOCUMENT",
|
|
1688
|
+
scope: "document",
|
|
1689
|
+
timestampUtcMs: header.createdAtUtcIso,
|
|
1690
|
+
input: upgradeInput
|
|
1691
|
+
}].map((action, index) => ({
|
|
1692
|
+
...action,
|
|
1693
|
+
action,
|
|
1694
|
+
id: deriveOperationId(header.id, "document", header.branch, action.id),
|
|
1695
|
+
hash: "",
|
|
1696
|
+
error: void 0,
|
|
1697
|
+
index,
|
|
1698
|
+
skip: 0
|
|
1699
|
+
}));
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Creates a new document. When `documentType` is given the header is stamped
|
|
1703
|
+
* with it and the document-scope operations are seeded.
|
|
1704
|
+
*/
|
|
1705
|
+
function baseCreateDocument(createState, initialState, documentType = "") {
|
|
1655
1706
|
const state = createState(initialState);
|
|
1707
|
+
const header = createPresignedHeader(generateId(), documentType);
|
|
1656
1708
|
return {
|
|
1657
|
-
header
|
|
1709
|
+
header,
|
|
1658
1710
|
state,
|
|
1659
1711
|
initialState: state,
|
|
1660
|
-
operations: {
|
|
1712
|
+
operations: documentType ? {
|
|
1713
|
+
global: [],
|
|
1714
|
+
local: [],
|
|
1715
|
+
document: createDocumentScopeOperations(header, state)
|
|
1716
|
+
} : {
|
|
1661
1717
|
global: [],
|
|
1662
1718
|
local: []
|
|
1663
1719
|
},
|
|
@@ -2676,6 +2732,15 @@ const RESERVED_OPERATION_NAMES = [
|
|
|
2676
2732
|
"NOOP"
|
|
2677
2733
|
];
|
|
2678
2734
|
/**
|
|
2735
|
+
* Operation names become the literal action `type` string at runtime and the
|
|
2736
|
+
* key for codegen's action union. They must be SCREAMING_SNAKE_CASE so the
|
|
2737
|
+
* generated TypeScript is valid.
|
|
2738
|
+
*/
|
|
2739
|
+
const OPERATION_NAME_PATTERN = /^[A-Z][A-Z0-9_]*$/;
|
|
2740
|
+
function isValidOperationNameFormat(name) {
|
|
2741
|
+
return OPERATION_NAME_PATTERN.test(name);
|
|
2742
|
+
}
|
|
2743
|
+
/**
|
|
2679
2744
|
* Check if name conflicts with base reducer actions (case-insensitive).
|
|
2680
2745
|
*/
|
|
2681
2746
|
function isReservedOperationName(name) {
|
|
@@ -2705,6 +2770,11 @@ function getAllOperationNames(state, excludeOperationId) {
|
|
|
2705
2770
|
*/
|
|
2706
2771
|
function validateOperationName(name, state, excludeOperationId) {
|
|
2707
2772
|
if (!name) return;
|
|
2773
|
+
if (!isValidOperationNameFormat(name)) {
|
|
2774
|
+
const suggestion = constantCase(name);
|
|
2775
|
+
const hint = suggestion && suggestion !== name && isValidOperationNameFormat(suggestion) ? ` Did you mean "${suggestion}"?` : "";
|
|
2776
|
+
throw new Error(`Operation name "${name}" is invalid. Names must be SCREAMING_SNAKE_CASE (matching ${OPERATION_NAME_PATTERN.source}).${hint}`);
|
|
2777
|
+
}
|
|
2708
2778
|
const upperName = name.toUpperCase();
|
|
2709
2779
|
if (isReservedOperationName(name)) throw new Error(`Operation name "${name}" is reserved. Please use a different name.`);
|
|
2710
2780
|
if (getAllOperationNames(state, excludeOperationId).includes(upperName)) throw new Error(`Operation name "${name}" is already used by another operation. Operation names must be unique across all modules.`);
|
|
@@ -2800,6 +2870,60 @@ function findOperationOrThrow(state, operationId) {
|
|
|
2800
2870
|
}
|
|
2801
2871
|
throw new Error(`Operation "${operationId}" not found in the latest specification`);
|
|
2802
2872
|
}
|
|
2873
|
+
/**
|
|
2874
|
+
* Find an operation error by id across all operations in the latest
|
|
2875
|
+
* specification, or throw. Throws on a duplicate id too: setters act on a
|
|
2876
|
+
* single error, so an ambiguous id must fail loudly rather than mutate an
|
|
2877
|
+
* arbitrary match.
|
|
2878
|
+
*/
|
|
2879
|
+
function findOperationErrorOrThrow(state, errorId) {
|
|
2880
|
+
const matches = state.specifications[state.specifications.length - 1]?.modules.flatMap((mod) => mod.operations.flatMap((op) => op.errors.filter((e) => e.id === errorId))) ?? [];
|
|
2881
|
+
if (matches.length === 0) throw new Error(`Operation error "${errorId}" not found in the latest specification`);
|
|
2882
|
+
if (matches.length > 1) throw new Error(`Operation error "${errorId}" is duplicated in the latest specification`);
|
|
2883
|
+
return matches[0];
|
|
2884
|
+
}
|
|
2885
|
+
/**
|
|
2886
|
+
* Find an operation example (code example) by id across all operations in the
|
|
2887
|
+
* latest specification, or throw. Throws on a duplicate id for the same reason
|
|
2888
|
+
* as findOperationErrorOrThrow.
|
|
2889
|
+
*/
|
|
2890
|
+
function findOperationExampleOrThrow(state, exampleId) {
|
|
2891
|
+
const matches = state.specifications[state.specifications.length - 1]?.modules.flatMap((mod) => mod.operations.flatMap((op) => op.examples.filter((e) => e.id === exampleId))) ?? [];
|
|
2892
|
+
if (matches.length === 0) throw new Error(`Operation example "${exampleId}" not found in the latest specification`);
|
|
2893
|
+
if (matches.length > 1) throw new Error(`Operation example "${exampleId}" is duplicated in the latest specification`);
|
|
2894
|
+
return matches[0];
|
|
2895
|
+
}
|
|
2896
|
+
/**
|
|
2897
|
+
* Assert no module in the latest specification already uses `id`. Modules are
|
|
2898
|
+
* targeted by id by the setter/delete/reorder reducers, so a duplicate id makes
|
|
2899
|
+
* those operations ambiguous.
|
|
2900
|
+
*/
|
|
2901
|
+
function assertModuleIdUnique(state, id) {
|
|
2902
|
+
if (state.specifications[state.specifications.length - 1]?.modules.some((m) => m.id === id)) throw new Error(`Module "${id}" already exists in the latest specification`);
|
|
2903
|
+
}
|
|
2904
|
+
/**
|
|
2905
|
+
* Assert no operation in the latest specification already uses `id`. Operations
|
|
2906
|
+
* are targeted by id across all modules, so the id must be unique document-wide.
|
|
2907
|
+
*/
|
|
2908
|
+
function assertOperationIdUnique(state, id) {
|
|
2909
|
+
if (state.specifications[state.specifications.length - 1]?.modules.some((m) => m.operations.some((o) => o.id === id))) throw new Error(`Operation "${id}" already exists in the latest specification`);
|
|
2910
|
+
}
|
|
2911
|
+
/**
|
|
2912
|
+
* Assert no operation error in the latest specification already uses `id`.
|
|
2913
|
+
* Error ids are targeted document-wide by the setter/delete reducers, so the id
|
|
2914
|
+
* must be unique to keep those operations unambiguous.
|
|
2915
|
+
*/
|
|
2916
|
+
function assertOperationErrorIdUnique(state, id) {
|
|
2917
|
+
if (state.specifications[state.specifications.length - 1]?.modules.some((m) => m.operations.some((o) => o.errors.some((e) => e.id === id)))) throw new Error(`Operation error "${id}" already exists in the latest specification`);
|
|
2918
|
+
}
|
|
2919
|
+
/**
|
|
2920
|
+
* Assert no operation example in the latest specification already uses `id`.
|
|
2921
|
+
* Example ids are targeted document-wide by the update/delete reducers, so the
|
|
2922
|
+
* id must be unique to keep those operations unambiguous.
|
|
2923
|
+
*/
|
|
2924
|
+
function assertOperationExampleIdUnique(state, id) {
|
|
2925
|
+
if (state.specifications[state.specifications.length - 1]?.modules.some((m) => m.operations.some((o) => o.examples.some((e) => e.id === id)))) throw new Error(`Operation example "${id}" already exists in the latest specification`);
|
|
2926
|
+
}
|
|
2803
2927
|
function validateOperations(operations) {
|
|
2804
2928
|
const errors = [];
|
|
2805
2929
|
const scopes = Object.keys(operations);
|
|
@@ -2824,10 +2948,22 @@ function validateOperations(operations) {
|
|
|
2824
2948
|
}
|
|
2825
2949
|
//#endregion
|
|
2826
2950
|
//#region document-model/reducers.ts
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2951
|
+
/**
|
|
2952
|
+
* Reorder `items` by the position of their id in `order`. Ids not listed in
|
|
2953
|
+
* `order` keep their relative position after the listed ones. Throws if `order`
|
|
2954
|
+
* references an id that isn't present, so a stale or mistyped id fails loudly
|
|
2955
|
+
* instead of silently producing an arbitrary order.
|
|
2956
|
+
*/
|
|
2957
|
+
function orderBy(items, order) {
|
|
2958
|
+
const ids = new Set(items.map((item) => item.id));
|
|
2959
|
+
for (const id of order) if (!ids.has(id)) throw new Error(`Cannot reorder: unknown id "${id}"`);
|
|
2960
|
+
const rank = new Map(order.map((id, index) => [id, index]));
|
|
2961
|
+
return items.map((item, index) => ({
|
|
2962
|
+
item,
|
|
2963
|
+
index
|
|
2964
|
+
})).sort((a, b) => {
|
|
2965
|
+
return (rank.get(a.item.id) ?? Number.MAX_SAFE_INTEGER) - (rank.get(b.item.id) ?? Number.MAX_SAFE_INTEGER) || a.index - b.index;
|
|
2966
|
+
}).map(({ item }) => item);
|
|
2831
2967
|
}
|
|
2832
2968
|
const documentModelHeaderReducer = {
|
|
2833
2969
|
setModelNameOperation(state, action) {
|
|
@@ -2859,6 +2995,7 @@ const documentModelHeaderReducer = {
|
|
|
2859
2995
|
};
|
|
2860
2996
|
const documentModelModuleReducer = {
|
|
2861
2997
|
addModuleOperation(state, action) {
|
|
2998
|
+
assertModuleIdUnique(state, action.input.id);
|
|
2862
2999
|
state.specifications[state.specifications.length - 1].modules.push({
|
|
2863
3000
|
id: action.input.id,
|
|
2864
3001
|
name: action.input.name,
|
|
@@ -2867,24 +3004,28 @@ const documentModelModuleReducer = {
|
|
|
2867
3004
|
});
|
|
2868
3005
|
},
|
|
2869
3006
|
setModuleNameOperation(state, action) {
|
|
2870
|
-
const
|
|
2871
|
-
|
|
3007
|
+
const targetModule = findModuleOrThrow(state, action.input.id);
|
|
3008
|
+
targetModule.name = action.input.name || "";
|
|
2872
3009
|
},
|
|
2873
3010
|
setModuleDescriptionOperation(state, action) {
|
|
2874
|
-
const
|
|
2875
|
-
|
|
3011
|
+
const targetModule = findModuleOrThrow(state, action.input.id);
|
|
3012
|
+
targetModule.description = action.input.description || "";
|
|
2876
3013
|
},
|
|
2877
3014
|
deleteModuleOperation(state, action) {
|
|
3015
|
+
findModuleOrThrow(state, action.input.id);
|
|
2878
3016
|
const latestSpec = state.specifications[state.specifications.length - 1];
|
|
2879
3017
|
latestSpec.modules = latestSpec.modules.filter((m) => m.id != action.input.id);
|
|
2880
3018
|
},
|
|
2881
3019
|
reorderModulesOperation(state, action) {
|
|
2882
|
-
state.specifications[state.specifications.length - 1]
|
|
3020
|
+
const latestSpec = state.specifications[state.specifications.length - 1];
|
|
3021
|
+
latestSpec.modules = orderBy(latestSpec.modules, action.input.order);
|
|
2883
3022
|
}
|
|
2884
3023
|
};
|
|
2885
3024
|
const documentModelOperationErrorReducer = {
|
|
2886
3025
|
addOperationErrorOperation(state, action) {
|
|
2887
|
-
findOperationOrThrow(state, action.input.operationId)
|
|
3026
|
+
const targetOp = findOperationOrThrow(state, action.input.operationId);
|
|
3027
|
+
assertOperationErrorIdUnique(state, action.input.id);
|
|
3028
|
+
targetOp.errors.push({
|
|
2888
3029
|
id: action.input.id,
|
|
2889
3030
|
name: action.input.errorName || "",
|
|
2890
3031
|
code: action.input.errorCode || "",
|
|
@@ -2893,54 +3034,58 @@ const documentModelOperationErrorReducer = {
|
|
|
2893
3034
|
});
|
|
2894
3035
|
},
|
|
2895
3036
|
setOperationErrorCodeOperation(state, action) {
|
|
2896
|
-
const
|
|
2897
|
-
|
|
3037
|
+
const error = findOperationErrorOrThrow(state, action.input.id);
|
|
3038
|
+
error.code = action.input.errorCode || "";
|
|
2898
3039
|
},
|
|
2899
3040
|
setOperationErrorNameOperation(state, action) {
|
|
2900
|
-
const
|
|
2901
|
-
|
|
3041
|
+
const error = findOperationErrorOrThrow(state, action.input.id);
|
|
3042
|
+
error.name = action.input.errorName || "";
|
|
2902
3043
|
},
|
|
2903
3044
|
setOperationErrorDescriptionOperation(state, action) {
|
|
2904
|
-
const
|
|
2905
|
-
|
|
3045
|
+
const error = findOperationErrorOrThrow(state, action.input.id);
|
|
3046
|
+
error.description = action.input.errorDescription || "";
|
|
2906
3047
|
},
|
|
2907
3048
|
setOperationErrorTemplateOperation(state, action) {
|
|
2908
|
-
const
|
|
2909
|
-
|
|
3049
|
+
const error = findOperationErrorOrThrow(state, action.input.id);
|
|
3050
|
+
error.template = action.input.errorTemplate || "";
|
|
2910
3051
|
},
|
|
2911
3052
|
deleteOperationErrorOperation(state, action) {
|
|
2912
3053
|
const latestSpec = state.specifications[state.specifications.length - 1];
|
|
2913
|
-
|
|
3054
|
+
if (!latestSpec.modules.some((mod) => mod.operations.some((op) => op.errors.some((e) => e.id === action.input.id)))) throw new Error(`Operation error "${action.input.id}" not found in the latest specification`);
|
|
3055
|
+
for (const mod of latestSpec.modules) for (const op of mod.operations) op.errors = op.errors.filter((e) => e.id != action.input.id);
|
|
2914
3056
|
},
|
|
2915
3057
|
reorderOperationErrorsOperation(state, action) {
|
|
2916
|
-
const
|
|
2917
|
-
|
|
3058
|
+
const targetOp = findOperationOrThrow(state, action.input.operationId);
|
|
3059
|
+
targetOp.errors = orderBy(targetOp.errors, action.input.order);
|
|
2918
3060
|
}
|
|
2919
3061
|
};
|
|
2920
3062
|
const documentModelOperationExampleReducer = {
|
|
2921
3063
|
addOperationExampleOperation(state, action) {
|
|
2922
|
-
const
|
|
2923
|
-
|
|
3064
|
+
const targetOp = findOperationOrThrow(state, action.input.operationId);
|
|
3065
|
+
assertOperationExampleIdUnique(state, action.input.id);
|
|
3066
|
+
targetOp.examples.push({
|
|
2924
3067
|
id: action.input.id,
|
|
2925
3068
|
value: action.input.example
|
|
2926
3069
|
});
|
|
2927
3070
|
},
|
|
2928
3071
|
updateOperationExampleOperation(state, action) {
|
|
2929
|
-
const
|
|
2930
|
-
|
|
3072
|
+
const example = findOperationExampleOrThrow(state, action.input.id);
|
|
3073
|
+
example.value = action.input.example;
|
|
2931
3074
|
},
|
|
2932
3075
|
deleteOperationExampleOperation(state, action) {
|
|
2933
3076
|
const latestSpec = state.specifications[state.specifications.length - 1];
|
|
2934
|
-
|
|
3077
|
+
if (!latestSpec.modules.some((mod) => mod.operations.some((op) => op.examples.some((e) => e.id === action.input.id)))) throw new Error(`Operation example "${action.input.id}" not found in the latest specification`);
|
|
3078
|
+
for (const mod of latestSpec.modules) for (const op of mod.operations) op.examples = op.examples.filter((e) => e.id != action.input.id);
|
|
2935
3079
|
},
|
|
2936
3080
|
reorderOperationExamplesOperation(state, action) {
|
|
2937
|
-
const
|
|
2938
|
-
|
|
3081
|
+
const targetOp = findOperationOrThrow(state, action.input.operationId);
|
|
3082
|
+
targetOp.examples = orderBy(targetOp.examples, action.input.order);
|
|
2939
3083
|
}
|
|
2940
3084
|
};
|
|
2941
3085
|
const documentModelOperationReducer = {
|
|
2942
3086
|
addOperationOperation(state, action) {
|
|
2943
3087
|
validateOperationName(action.input.name, state);
|
|
3088
|
+
assertOperationIdUnique(state, action.input.id);
|
|
2944
3089
|
findModuleOrThrow(state, action.input.moduleId).operations.push({
|
|
2945
3090
|
id: action.input.id,
|
|
2946
3091
|
name: action.input.name,
|
|
@@ -2955,8 +3100,8 @@ const documentModelOperationReducer = {
|
|
|
2955
3100
|
},
|
|
2956
3101
|
setOperationNameOperation(state, action) {
|
|
2957
3102
|
if (action.input.name) validateOperationName(action.input.name, state, action.input.id);
|
|
2958
|
-
const
|
|
2959
|
-
|
|
3103
|
+
const targetOp = findOperationOrThrow(state, action.input.id);
|
|
3104
|
+
targetOp.name = action.input.name || "";
|
|
2960
3105
|
},
|
|
2961
3106
|
setOperationScopeOperation(state, action) {
|
|
2962
3107
|
const targetOp = findOperationOrThrow(state, action.input.id);
|
|
@@ -2966,40 +3111,39 @@ const documentModelOperationReducer = {
|
|
|
2966
3111
|
targetOp.scope = action.input.scope || "global";
|
|
2967
3112
|
},
|
|
2968
3113
|
setOperationSchemaOperation(state, action) {
|
|
2969
|
-
const
|
|
2970
|
-
|
|
3114
|
+
const targetOp = findOperationOrThrow(state, action.input.id);
|
|
3115
|
+
targetOp.schema = action.input.schema || "";
|
|
2971
3116
|
},
|
|
2972
3117
|
setOperationDescriptionOperation(state, action) {
|
|
2973
|
-
const
|
|
2974
|
-
|
|
3118
|
+
const targetOp = findOperationOrThrow(state, action.input.id);
|
|
3119
|
+
targetOp.description = action.input.description || "";
|
|
2975
3120
|
},
|
|
2976
3121
|
setOperationTemplateOperation(state, action) {
|
|
2977
|
-
const
|
|
2978
|
-
|
|
3122
|
+
const targetOp = findOperationOrThrow(state, action.input.id);
|
|
3123
|
+
targetOp.template = action.input.template || "";
|
|
2979
3124
|
},
|
|
2980
3125
|
setOperationReducerOperation(state, action) {
|
|
2981
|
-
const
|
|
2982
|
-
|
|
3126
|
+
const targetOp = findOperationOrThrow(state, action.input.id);
|
|
3127
|
+
targetOp.reducer = action.input.reducer || "";
|
|
2983
3128
|
},
|
|
2984
3129
|
moveOperationOperation(state, action) {
|
|
2985
|
-
const
|
|
3130
|
+
const targetModule = findModuleOrThrow(state, action.input.newModuleId);
|
|
2986
3131
|
const latestSpec = state.specifications[state.specifications.length - 1];
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
});
|
|
2994
|
-
for (let i = 0; i < latestSpec.modules.length; i++) if (latestSpec.modules[i].id == action.input.newModuleId) latestSpec.modules[i].operations.push(...moveOperations);
|
|
3132
|
+
const matches = latestSpec.modules.flatMap((mod) => mod.operations.filter((op) => op.id === action.input.operationId));
|
|
3133
|
+
if (matches.length === 0) throw new Error(`Operation "${action.input.operationId}" not found in the latest specification`);
|
|
3134
|
+
if (matches.length > 1) throw new Error(`Operation "${action.input.operationId}" is duplicated in the latest specification`);
|
|
3135
|
+
const moved = matches[0];
|
|
3136
|
+
for (const mod of latestSpec.modules) mod.operations = mod.operations.filter((op) => op.id !== action.input.operationId);
|
|
3137
|
+
targetModule.operations.push(moved);
|
|
2995
3138
|
},
|
|
2996
3139
|
deleteOperationOperation(state, action) {
|
|
3140
|
+
findOperationOrThrow(state, action.input.id);
|
|
2997
3141
|
const latestSpec = state.specifications[state.specifications.length - 1];
|
|
2998
|
-
for (
|
|
3142
|
+
for (const mod of latestSpec.modules) mod.operations = mod.operations.filter((operation) => operation.id != action.input.id);
|
|
2999
3143
|
},
|
|
3000
3144
|
reorderModuleOperationsOperation(state, action) {
|
|
3001
|
-
const
|
|
3002
|
-
|
|
3145
|
+
const targetModule = findModuleOrThrow(state, action.input.moduleId);
|
|
3146
|
+
targetModule.operations = orderBy(targetModule.operations, action.input.order);
|
|
3003
3147
|
}
|
|
3004
3148
|
};
|
|
3005
3149
|
const documentModelStateSchemaReducer = {
|
|
@@ -3024,18 +3168,22 @@ const documentModelStateSchemaReducer = {
|
|
|
3024
3168
|
updateStateExampleOperation(state, action) {
|
|
3025
3169
|
const latestSpec = state.specifications[state.specifications.length - 1];
|
|
3026
3170
|
if (!Object.keys(latestSpec.state).includes(action.input.scope)) throw new Error(`Invalid scope: ${action.input.scope}`);
|
|
3027
|
-
const
|
|
3028
|
-
|
|
3171
|
+
const example = latestSpec.state[action.input.scope].examples.find((e) => e.id == action.input.id);
|
|
3172
|
+
if (!example) throw new Error(`State example "${action.input.id}" not found in scope "${action.input.scope}"`);
|
|
3173
|
+
example.value = action.input.newExample;
|
|
3029
3174
|
},
|
|
3030
3175
|
deleteStateExampleOperation(state, action) {
|
|
3031
3176
|
const latestSpec = state.specifications[state.specifications.length - 1];
|
|
3032
|
-
if (Object.keys(latestSpec.state).includes(action.input.scope))
|
|
3033
|
-
|
|
3177
|
+
if (!Object.keys(latestSpec.state).includes(action.input.scope)) throw new Error(`Invalid scope: ${action.input.scope}`);
|
|
3178
|
+
const scopeState = latestSpec.state[action.input.scope];
|
|
3179
|
+
if (!scopeState.examples.some((e) => e.id == action.input.id)) throw new Error(`State example "${action.input.id}" not found in scope "${action.input.scope}"`);
|
|
3180
|
+
scopeState.examples = scopeState.examples.filter((e) => e.id != action.input.id);
|
|
3034
3181
|
},
|
|
3035
3182
|
reorderStateExamplesOperation(state, action) {
|
|
3036
3183
|
const latestSpec = state.specifications[state.specifications.length - 1];
|
|
3037
|
-
if (Object.keys(latestSpec.state).includes(action.input.scope))
|
|
3038
|
-
|
|
3184
|
+
if (!Object.keys(latestSpec.state).includes(action.input.scope)) throw new Error(`Invalid scope: ${action.input.scope}`);
|
|
3185
|
+
const scopeState = latestSpec.state[action.input.scope];
|
|
3186
|
+
scopeState.examples = orderBy(scopeState.examples, action.input.order);
|
|
3039
3187
|
}
|
|
3040
3188
|
};
|
|
3041
3189
|
const documentModelVersioningReducer = {
|
|
@@ -3485,6 +3633,6 @@ function createState(baseState, globalState, localState) {
|
|
|
3485
3633
|
};
|
|
3486
3634
|
}
|
|
3487
3635
|
//#endregion
|
|
3488
|
-
export { AddChangeLogItemInputSchema, AddModuleInputSchema, AddOperationErrorInputSchema, AddOperationExampleInputSchema, AddOperationInputSchema, AddStateExampleInputSchema, AuthorSchema, BaseDocumentHeaderSchema, BaseDocumentStateSchema, CodeExampleSchema, ConfigEntrySchema, ConfigEntryTypeSchema, DeleteChangeLogItemInputSchema, DeleteModuleInputSchema, DeleteOperationErrorInputSchema, DeleteOperationExampleInputSchema, DeleteOperationInputSchema, DeleteStateExampleInputSchema, DocumentActionSchema, DocumentFileSchema, DocumentModelGlobalStateSchema, DocumentModelHeaderSchema, DocumentModelInputSchema, DocumentModelPHStateSchema, DocumentModelSchema, DocumentSpecificationSchema, FileSystemError, HASH_ALGORITHM_SHA1, HASH_ALGORITHM_SHA256, HASH_ALGORITHM_SHA512, HASH_ENCODING_BASE64, HASH_ENCODING_HEX, HashMismatchError, IntegrityIssueSubType, IntegrityIssueType, InvalidActionInputError, InvalidActionInputZodError, LoadStateActionInputSchema, LoadStateActionSchema, LoadStateActionStateInputSchema, Load_StateSchema, ManifestSchema, ModuleSchema, MoveOperationInputSchema, OperationErrorSchema, OperationScopeSchema, OperationSpecificationSchema, PowerhouseModuleSchema, PowerhouseModulesSchema, PruneActionInputSchema, PruneActionSchema, PruneSchema, PublisherSchema, RESERVED_OPERATION_NAMES, RedoActionInputSchema, RedoActionSchema, RedoSchema, ReorderChangeLogItemsInputSchema, ReorderModuleOperationsInputSchema, ReorderModulesInputSchema, ReorderOperationErrorsInputSchema, ReorderOperationExamplesInputSchema, ReorderStateExamplesInputSchema, ScopeStateSchema, SetAuthorNameInputSchema, SetAuthorWebsiteInputSchema, SetInitialStateInputSchema, SetModelDescriptionInputSchema, SetModelExtensionInputSchema, SetModelIdInputSchema, SetModelNameInputSchema, SetModuleDescriptionInputSchema, SetModuleNameInputSchema, SetNameActionInputSchema, SetNameActionSchema, SetOperationDescriptionInputSchema, SetOperationErrorCodeInputSchema, SetOperationErrorDescriptionInputSchema, SetOperationErrorNameInputSchema, SetOperationErrorTemplateInputSchema, SetOperationNameInputSchema, SetOperationReducerInputSchema, SetOperationSchemaInputSchema, SetOperationScopeInputSchema, SetOperationTemplateInputSchema, SetPreferredEditorActionInputSchema, SetPreferredEditorActionSchema, SetStateSchemaInputSchema, Set_NameSchema, Set_PreferredEditorSchema, StateSchema, UndoActionInputSchema, UndoActionSchema, UndoSchema, UpdateChangeLogItemInputSchema, UpdateOperationExampleInputSchema, UpdateStateExampleInputSchema, ab2hex, actionContext, actionFromAction, actionSigner, actions, addChangeLogItem, addModule, addOperation, addOperationError, addOperationExample, addStateExample, addUndo, assertIsDocumentModelDocument, assertIsDocumentModelState, attachBranch, baseActions, baseCreateDocument, baseLoadFromInput, baseReducer, baseSaveToFileHandle, buildOperationSignature, buildOperationSignatureMessage, buildOperationSignatureParams, buildSignedAction, checkCleanedOperationsIntegrity, checkOperationsIntegrity, createAction, createAuthState, createBaseState, createDocumentState, createGlobalState, createLocalState, createMinimalZip, createPresignedHeader, createReducer, createSignedHeader, createSignedHeaderForSigner, createState, createVerificationSigner, createZip, defaultAuthState, defaultBaseState, defaultDocumentState, defaultGlobalState, defaultLocalState, defaultPHState, definedNonNullAnySchema, deleteChangeLogItem, deleteModule, deleteOperation, deleteOperationError, deleteOperationExample, deleteStateExample, deriveOperationId, diffOperations, documentModelActions, documentModelDocumentType, documentModelFileExtension, documentModelGlobalState, documentModelHeaderReducer, documentModelInitialGlobalState, documentModelInitialLocalState, documentModelLoadFromInput, documentModelModuleReducer, documentModelOperationErrorReducer, documentModelOperationExampleReducer, documentModelOperationReducer, documentModelReducer, documentModelSaveToFileHandle, documentModelStateReducer, documentModelStateSchemaReducer, documentModelVersioningReducer, fetchFileBrowser, filterDocumentOperationsResultingState, filterDuplicatedOperations, findModuleOrThrow, findOperationOrThrow, garbageCollect, garbageCollectDocumentOperations, garbageCollectV2, generateId, generateMock, getAllOperationNames, getDocumentLastModified, getFileBrowser, getUnixTimestamp, groupOperationsByScope, hashBrowser, hashDocumentStateForScope, hex2ab, isDefinedNonNullAny, isDocumentAction, isDocumentModelDocument, isDocumentModelState, isNoopOperation, isReservedOperationName, isUndo, isUndoRedo, loadState, loadStateOperation, mapSkippedOperations, mapSkippedOperationsV2, merge, moveOperation, nextSkipNumber, noop, operationExampleCreators, operationFromAction, operationFromOperation, operationWithContext, operationsAreEqual, parseResultingState, precedes, prepareOperations, processUndoRedo, prune, pruneOperation, readFileBrowser, readOnly, redo, redoOperation, releaseNewVersion, removeExistingOperations, reorderChangeLogItems, reorderModuleOperations, reorderModules, reorderOperationErrors, reorderOperationExamples, reorderStateExamples, replayDocument, replayOperations, reshuffleByTimestamp, reshuffleByTimestampAndIndex, setAuthorName, setAuthorWebsite, setInitialState, setModelDescription, setModelExtension, setModelId, setModelName, setModuleDescription, setModuleName, setName, setNameOperation, setOperationDescription, setOperationErrorCode, setOperationErrorDescription, setOperationErrorName, setOperationErrorTemplate, setOperationName, setOperationReducer, setOperationSchema, setOperationScope, setOperationTemplate, setPreferredEditor, setPreferredEditorOperation, setStateSchema, sign, skipHeaderOperations, sortMappedOperations, sortOperations, split, undo, undoOperation, undoOperationV2, updateChangeLogItem, updateDocument, updateHeaderRevision, updateOperationExample, updateStateExample, validateHeader, validateInitialState, validateModule, validateModuleOperation, validateModules, validateOperationName, validateOperations, validateStateSchemaName, verify, verifyOperationSignature, writeFileBrowser };
|
|
3636
|
+
export { AddChangeLogItemInputSchema, AddModuleInputSchema, AddOperationErrorInputSchema, AddOperationExampleInputSchema, AddOperationInputSchema, AddStateExampleInputSchema, AuthorSchema, BaseDocumentHeaderSchema, BaseDocumentStateSchema, CodeExampleSchema, ConfigEntrySchema, ConfigEntryTypeSchema, DeleteChangeLogItemInputSchema, DeleteModuleInputSchema, DeleteOperationErrorInputSchema, DeleteOperationExampleInputSchema, DeleteOperationInputSchema, DeleteStateExampleInputSchema, DocumentActionSchema, DocumentFileSchema, DocumentModelGlobalStateSchema, DocumentModelHeaderSchema, DocumentModelInputSchema, DocumentModelPHStateSchema, DocumentModelSchema, DocumentSpecificationSchema, FileSystemError, HASH_ALGORITHM_SHA1, HASH_ALGORITHM_SHA256, HASH_ALGORITHM_SHA512, HASH_ENCODING_BASE64, HASH_ENCODING_HEX, HashMismatchError, IntegrityIssueSubType, IntegrityIssueType, InvalidActionInputError, InvalidActionInputZodError, LoadStateActionInputSchema, LoadStateActionSchema, LoadStateActionStateInputSchema, Load_StateSchema, ManifestSchema, ModuleSchema, MoveOperationInputSchema, OPERATION_NAME_PATTERN, OperationErrorSchema, OperationScopeSchema, OperationSpecificationSchema, PowerhouseModuleSchema, PowerhouseModulesSchema, PruneActionInputSchema, PruneActionSchema, PruneSchema, PublisherSchema, RESERVED_OPERATION_NAMES, RedoActionInputSchema, RedoActionSchema, RedoSchema, ReorderChangeLogItemsInputSchema, ReorderModuleOperationsInputSchema, ReorderModulesInputSchema, ReorderOperationErrorsInputSchema, ReorderOperationExamplesInputSchema, ReorderStateExamplesInputSchema, ScopeStateSchema, SetAuthorNameInputSchema, SetAuthorWebsiteInputSchema, SetInitialStateInputSchema, SetModelDescriptionInputSchema, SetModelExtensionInputSchema, SetModelIdInputSchema, SetModelNameInputSchema, SetModuleDescriptionInputSchema, SetModuleNameInputSchema, SetNameActionInputSchema, SetNameActionSchema, SetOperationDescriptionInputSchema, SetOperationErrorCodeInputSchema, SetOperationErrorDescriptionInputSchema, SetOperationErrorNameInputSchema, SetOperationErrorTemplateInputSchema, SetOperationNameInputSchema, SetOperationReducerInputSchema, SetOperationSchemaInputSchema, SetOperationScopeInputSchema, SetOperationTemplateInputSchema, SetPreferredEditorActionInputSchema, SetPreferredEditorActionSchema, SetStateSchemaInputSchema, Set_NameSchema, Set_PreferredEditorSchema, StateSchema, UndoActionInputSchema, UndoActionSchema, UndoSchema, UpdateChangeLogItemInputSchema, UpdateOperationExampleInputSchema, UpdateStateExampleInputSchema, ab2hex, actionContext, actionFromAction, actionSigner, actions, addChangeLogItem, addModule, addOperation, addOperationError, addOperationExample, addStateExample, addUndo, assertIsDocumentModelDocument, assertIsDocumentModelState, assertModuleIdUnique, assertOperationErrorIdUnique, assertOperationExampleIdUnique, assertOperationIdUnique, attachBranch, baseActions, baseCreateDocument, baseLoadFromInput, baseReducer, baseSaveToFileHandle, buildOperationSignature, buildOperationSignatureMessage, buildOperationSignatureParams, buildSignedAction, checkCleanedOperationsIntegrity, checkOperationsIntegrity, createAction, createAuthState, createBaseState, createDocumentState, createGlobalState, createLocalState, createMinimalZip, createPresignedHeader, createReducer, createSignedHeader, createSignedHeaderForSigner, createState, createVerificationSigner, createZip, defaultAuthState, defaultBaseState, defaultDocumentState, defaultGlobalState, defaultLocalState, defaultPHState, definedNonNullAnySchema, deleteChangeLogItem, deleteModule, deleteOperation, deleteOperationError, deleteOperationExample, deleteStateExample, deriveOperationId, diffOperations, documentModelActions, documentModelDocumentType, documentModelFileExtension, documentModelGlobalState, documentModelHeaderReducer, documentModelInitialGlobalState, documentModelInitialLocalState, documentModelLoadFromInput, documentModelModuleReducer, documentModelOperationErrorReducer, documentModelOperationExampleReducer, documentModelOperationReducer, documentModelReducer, documentModelSaveToFileHandle, documentModelStateReducer, documentModelStateSchemaReducer, documentModelVersioningReducer, fetchFileBrowser, filterDocumentOperationsResultingState, filterDuplicatedOperations, findModuleOrThrow, findOperationErrorOrThrow, findOperationExampleOrThrow, findOperationOrThrow, garbageCollect, garbageCollectDocumentOperations, garbageCollectV2, generateId, generateMock, getAllOperationNames, getDocumentLastModified, getFileBrowser, getUnixTimestamp, groupOperationsByScope, hashBrowser, hashDocumentStateForScope, hex2ab, isDefinedNonNullAny, isDocumentAction, isDocumentModelDocument, isDocumentModelState, isNoopOperation, isReservedOperationName, isUndo, isUndoRedo, isValidOperationNameFormat, loadState, loadStateOperation, mapSkippedOperations, mapSkippedOperationsV2, merge, moveOperation, nextSkipNumber, noop, operationExampleCreators, operationFromAction, operationFromOperation, operationWithContext, operationsAreEqual, parseResultingState, precedes, prepareOperations, processUndoRedo, prune, pruneOperation, readFileBrowser, readOnly, redo, redoOperation, releaseNewVersion, removeExistingOperations, reorderChangeLogItems, reorderModuleOperations, reorderModules, reorderOperationErrors, reorderOperationExamples, reorderStateExamples, replayDocument, replayOperations, reshuffleByTimestamp, reshuffleByTimestampAndIndex, setAuthorName, setAuthorWebsite, setInitialState, setModelDescription, setModelExtension, setModelId, setModelName, setModuleDescription, setModuleName, setName, setNameOperation, setOperationDescription, setOperationErrorCode, setOperationErrorDescription, setOperationErrorName, setOperationErrorTemplate, setOperationName, setOperationReducer, setOperationSchema, setOperationScope, setOperationTemplate, setPreferredEditor, setPreferredEditorOperation, setStateSchema, sign, skipHeaderOperations, sortMappedOperations, sortOperations, split, undo, undoOperation, undoOperationV2, updateChangeLogItem, updateDocument, updateHeaderRevision, updateOperationExample, updateStateExample, validateHeader, validateInitialState, validateModule, validateModuleOperation, validateModules, validateOperationName, validateOperations, validateStateSchemaName, verify, verifyOperationSignature, writeFileBrowser };
|
|
3489
3637
|
|
|
3490
3638
|
//# sourceMappingURL=index.js.map
|