@fragment-dev/cli 2026.10.30-1 → 2026.10.30-13
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/README.md +69 -0
- package/bin/dev.js +1 -1
- package/bin/run.js +3 -1
- package/dist/chunk-2QGAXOCF.js +38 -0
- package/dist/{chunk-RWQZFXSF.js → chunk-3SE5DFKP.js} +1 -205
- package/dist/{chunk-DXYJ2C6A.js → chunk-4CPAGLCS.js} +5 -5
- package/dist/chunk-4E5LH6UM.js +46 -0
- package/dist/{chunk-XOKV3CLM.js → chunk-6CHMI6QB.js} +1149 -103
- package/dist/{chunk-NOFQF7LO.js → chunk-AXYDDQ64.js} +1 -1
- package/dist/{chunk-XKJQ557J.js → chunk-C3IGD3FR.js} +4 -2
- package/dist/{chunk-HZNM6VFG.js → chunk-ERS7TGXY.js} +4 -4
- package/dist/chunk-EXTVHTGU.js +88 -0
- package/dist/{chunk-FP3RI3B7.js → chunk-FTALVA4K.js} +20 -12
- package/dist/{chunk-2AWFI2YX.js → chunk-G7IGOKUP.js} +1 -1
- package/dist/{chunk-743236RA.js → chunk-GKWT6QEB.js} +5 -5
- package/dist/{chunk-GV36M6WY.js → chunk-HOYPQHWF.js} +7 -7
- package/dist/chunk-HYJ6MTD2.js +41 -0
- package/dist/chunk-JSWKMWBO.js +175 -0
- package/dist/{chunk-GCPPWOLT.js → chunk-LID4G5RM.js} +1 -1
- package/dist/chunk-MI5NFPWE.js +211 -0
- package/dist/{chunk-WNHRPKY6.js → chunk-MXOS5EPJ.js} +1 -1
- package/dist/chunk-N2SKO3MO.js +97 -0
- package/dist/chunk-NSEYKDYC.js +398 -0
- package/dist/chunk-OCE3DJ2V.js +76 -0
- package/dist/chunk-POIPF2YW.js +609 -0
- package/dist/chunk-PW3XYURG.js +4917 -0
- package/dist/chunk-T3RKAA7V.js +30 -0
- package/dist/{chunk-QJZAZHCO.js → chunk-WRHRJO7G.js} +16 -38
- package/dist/{chunk-YKGESMWT.js → chunk-WSFEOM2D.js} +1 -217
- package/dist/chunk-XKVEOJUH.js +85 -0
- package/dist/chunk-ZRPKEOB3.js +20 -0
- package/dist/commands/api-client/create.js +4 -3
- package/dist/commands/gen-graphql.js +11 -7
- package/dist/commands/login.js +4 -3
- package/dist/commands/print-schema.js +31 -0
- package/dist/commands/simulate-scenario.js +31 -0
- package/dist/commands/verify-schema.js +12 -8
- package/dist/commands.js +31 -17
- package/dist/graphql.js +8 -4
- package/dist/index.js +31 -17
- package/dist/lib/browserLogin.js +3 -2
- package/dist/utils/formatAccountHierarchy.js +11 -0
- package/dist/utils/formatAccountReference.js +12 -0
- package/dist/utils/formatBalance.js +11 -0
- package/dist/utils/formatChartOfAccounts.js +18 -0
- package/dist/utils/formatEntries.js +17 -0
- package/dist/utils/formatScenarioAccountBalances.js +18 -0
- package/dist/utils/formatScenarioBalances.js +19 -0
- package/dist/utils/formatTable.js +9 -0
- package/dist/utils/formatValidationErrors.js +6 -3
- package/dist/utils/schemaBackCompat.js +11 -7
- package/dist/utils/schemaValidation.js +10 -6
- package/oclif.manifest.json +92 -1
- package/package.json +8 -2
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CurrencyCodeSchema,
|
|
3
|
+
currencyPrecision
|
|
4
|
+
} from "./chunk-NSEYKDYC.js";
|
|
5
|
+
import {
|
|
6
|
+
init_cjs_shims
|
|
7
|
+
} from "./chunk-7GH3YGSC.js";
|
|
8
|
+
|
|
9
|
+
// src/utils/formatBalance.ts
|
|
10
|
+
init_cjs_shims();
|
|
11
|
+
|
|
12
|
+
// ../../fragment-ui/src/utils/formatAmount.ts
|
|
13
|
+
init_cjs_shims();
|
|
14
|
+
var MAX_FRACTIONAL_PARTS = 2;
|
|
15
|
+
var formatZero = (precision) => {
|
|
16
|
+
if (precision === 0) {
|
|
17
|
+
return "0";
|
|
18
|
+
}
|
|
19
|
+
if (precision === 1) {
|
|
20
|
+
return "0.0";
|
|
21
|
+
}
|
|
22
|
+
return "0.00";
|
|
23
|
+
};
|
|
24
|
+
var formatAmount = ({
|
|
25
|
+
amount,
|
|
26
|
+
precision,
|
|
27
|
+
isTruncated = false
|
|
28
|
+
}) => {
|
|
29
|
+
if (amount === "0" && isTruncated) {
|
|
30
|
+
return formatZero(precision);
|
|
31
|
+
}
|
|
32
|
+
let preformattedAmount = amount;
|
|
33
|
+
const isNegative = preformattedAmount.charAt(0) === "-";
|
|
34
|
+
if (isNegative) {
|
|
35
|
+
preformattedAmount = preformattedAmount.slice(1);
|
|
36
|
+
}
|
|
37
|
+
if (preformattedAmount.length < precision) {
|
|
38
|
+
preformattedAmount = preformattedAmount.padStart(precision, "0");
|
|
39
|
+
}
|
|
40
|
+
const integerPart = preformattedAmount.slice(0, preformattedAmount.length - precision) || "0";
|
|
41
|
+
const formattedIntegerPart = `${isNegative ? "-" : ""}${Intl.NumberFormat(
|
|
42
|
+
"en-US"
|
|
43
|
+
).format(BigInt(integerPart))}`;
|
|
44
|
+
if (precision === 0) {
|
|
45
|
+
return formattedIntegerPart;
|
|
46
|
+
}
|
|
47
|
+
let fractionalPart = preformattedAmount.slice(
|
|
48
|
+
preformattedAmount.length - precision
|
|
49
|
+
);
|
|
50
|
+
if (isTruncated && fractionalPart) {
|
|
51
|
+
if (fractionalPart.length > MAX_FRACTIONAL_PARTS + 1) {
|
|
52
|
+
fractionalPart = `${fractionalPart.slice(
|
|
53
|
+
0,
|
|
54
|
+
MAX_FRACTIONAL_PARTS
|
|
55
|
+
)}…`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return `${formattedIntegerPart}.${fractionalPart}`;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/utils/formatBalance.ts
|
|
62
|
+
var getBalancePrecision = (code) => currencyPrecision[CurrencyCodeSchema.parse(code)];
|
|
63
|
+
var formatBalance = ({
|
|
64
|
+
amount,
|
|
65
|
+
currency,
|
|
66
|
+
precision
|
|
67
|
+
}) => `${formatAmount({
|
|
68
|
+
amount: amount.toString(),
|
|
69
|
+
precision,
|
|
70
|
+
isTruncated: false
|
|
71
|
+
})} ${currency}`;
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
getBalancePrecision,
|
|
75
|
+
formatBalance
|
|
76
|
+
};
|
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatBalance
|
|
3
|
+
} from "./chunk-OCE3DJ2V.js";
|
|
4
|
+
import {
|
|
5
|
+
formatAccountHierarchy
|
|
6
|
+
} from "./chunk-4E5LH6UM.js";
|
|
7
|
+
import {
|
|
8
|
+
keyBy_default,
|
|
9
|
+
omit_default,
|
|
10
|
+
parameterizeSchemaLedgerEntryConditionInput,
|
|
11
|
+
parameterizeSchemaLedgerLineInput,
|
|
12
|
+
reparameterizeSchemaLedgerAccountInput
|
|
13
|
+
} from "./chunk-6CHMI6QB.js";
|
|
14
|
+
import {
|
|
15
|
+
getStructuralPath
|
|
16
|
+
} from "./chunk-2QGAXOCF.js";
|
|
17
|
+
import {
|
|
18
|
+
getStringParameters
|
|
19
|
+
} from "./chunk-MI5NFPWE.js";
|
|
20
|
+
import {
|
|
21
|
+
z
|
|
22
|
+
} from "./chunk-3SE5DFKP.js";
|
|
23
|
+
import {
|
|
24
|
+
init_cjs_shims
|
|
25
|
+
} from "./chunk-7GH3YGSC.js";
|
|
26
|
+
|
|
27
|
+
// src/utils/formatScenarioAccountBalances.ts
|
|
28
|
+
init_cjs_shims();
|
|
29
|
+
|
|
30
|
+
// ../../fragment-compositions/visualizer/src/utils/index.ts
|
|
31
|
+
init_cjs_shims();
|
|
32
|
+
|
|
33
|
+
// ../../fragment-compositions/visualizer/src/types/index.ts
|
|
34
|
+
init_cjs_shims();
|
|
35
|
+
|
|
36
|
+
// ../../libs/lil-id/index.ts
|
|
37
|
+
init_cjs_shims();
|
|
38
|
+
|
|
39
|
+
// ../../node_modules/nanoid/index.js
|
|
40
|
+
init_cjs_shims();
|
|
41
|
+
import crypto from "crypto";
|
|
42
|
+
|
|
43
|
+
// ../../node_modules/nanoid/url-alphabet/index.js
|
|
44
|
+
init_cjs_shims();
|
|
45
|
+
|
|
46
|
+
// ../../node_modules/nanoid/index.js
|
|
47
|
+
var POOL_SIZE_MULTIPLIER = 128;
|
|
48
|
+
var pool;
|
|
49
|
+
var poolOffset;
|
|
50
|
+
var fillPool = (bytes) => {
|
|
51
|
+
if (bytes < 0)
|
|
52
|
+
throw new RangeError("Wrong ID size");
|
|
53
|
+
try {
|
|
54
|
+
if (!pool || pool.length < bytes) {
|
|
55
|
+
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
56
|
+
crypto.randomFillSync(pool);
|
|
57
|
+
poolOffset = 0;
|
|
58
|
+
} else if (poolOffset + bytes > pool.length) {
|
|
59
|
+
crypto.randomFillSync(pool);
|
|
60
|
+
poolOffset = 0;
|
|
61
|
+
}
|
|
62
|
+
} catch (e) {
|
|
63
|
+
pool = void 0;
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
poolOffset += bytes;
|
|
67
|
+
};
|
|
68
|
+
var random = (bytes) => {
|
|
69
|
+
fillPool(bytes |= 0);
|
|
70
|
+
return pool.subarray(poolOffset - bytes, poolOffset);
|
|
71
|
+
};
|
|
72
|
+
var customRandom = (alphabet2, defaultSize, getRandom) => {
|
|
73
|
+
let mask = (2 << 31 - Math.clz32(alphabet2.length - 1 | 1)) - 1;
|
|
74
|
+
let step = Math.ceil(1.6 * mask * defaultSize / alphabet2.length);
|
|
75
|
+
return (size = defaultSize) => {
|
|
76
|
+
if (size <= 0)
|
|
77
|
+
return "";
|
|
78
|
+
let id = "";
|
|
79
|
+
while (true) {
|
|
80
|
+
let bytes = getRandom(step);
|
|
81
|
+
let i = step;
|
|
82
|
+
while (i--) {
|
|
83
|
+
id += alphabet2[bytes[i] & mask] || "";
|
|
84
|
+
if (id.length === size)
|
|
85
|
+
return id;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
var customAlphabet = (alphabet2, size = 21) => customRandom(alphabet2, size, random);
|
|
91
|
+
|
|
92
|
+
// ../../libs/lil-id/index.ts
|
|
93
|
+
var alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
94
|
+
var lilId = customAlphabet(alphabet, 21);
|
|
95
|
+
var lil_id_default = () => lilId();
|
|
96
|
+
|
|
97
|
+
// ../../fragment-compositions/visualizer/src/libs/recomputeAccountCaches.ts
|
|
98
|
+
init_cjs_shims();
|
|
99
|
+
|
|
100
|
+
// ../../libs/shared-utils/walk.ts
|
|
101
|
+
init_cjs_shims();
|
|
102
|
+
var walk = (collection, func, childKey, parent = null, level = 0, deriveArgs) => {
|
|
103
|
+
const results = collection.map(
|
|
104
|
+
(account) => {
|
|
105
|
+
const walked = func(
|
|
106
|
+
account,
|
|
107
|
+
parent,
|
|
108
|
+
level,
|
|
109
|
+
deriveArgs?.derivedParentState
|
|
110
|
+
);
|
|
111
|
+
const derivedState = deriveArgs ? deriveArgs.deriveState(account, deriveArgs.derivedParentState) : void 0;
|
|
112
|
+
const children = account[childKey];
|
|
113
|
+
let walkedChildren;
|
|
114
|
+
if (children) {
|
|
115
|
+
walkedChildren = walk(
|
|
116
|
+
children,
|
|
117
|
+
func,
|
|
118
|
+
childKey,
|
|
119
|
+
account,
|
|
120
|
+
level + 1,
|
|
121
|
+
deriveArgs && derivedState ? {
|
|
122
|
+
deriveState: deriveArgs.deriveState,
|
|
123
|
+
derivedParentState: derivedState
|
|
124
|
+
} : void 0
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
...walked,
|
|
129
|
+
[childKey]: walkedChildren
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
return results;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// ../../fragment-compositions/visualizer/src/libs/recomputeAccountCaches.ts
|
|
137
|
+
var recomputeAccountCache = (accounts) => {
|
|
138
|
+
const accountIdToAccount = {};
|
|
139
|
+
walk(
|
|
140
|
+
accounts,
|
|
141
|
+
(account) => {
|
|
142
|
+
accountIdToAccount[account.id] = account;
|
|
143
|
+
return account;
|
|
144
|
+
},
|
|
145
|
+
"children"
|
|
146
|
+
);
|
|
147
|
+
return {
|
|
148
|
+
accountIdToAccount
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// ../../fragment-compositions/visualizer/src/types/index.ts
|
|
153
|
+
var DEFAULT_SCENE = "default";
|
|
154
|
+
var defaultScene = {
|
|
155
|
+
id: DEFAULT_SCENE,
|
|
156
|
+
name: "First Scenario",
|
|
157
|
+
events: []
|
|
158
|
+
};
|
|
159
|
+
var defaultScenes = [defaultScene];
|
|
160
|
+
var generateAccountKey = (key, idMode, version) => {
|
|
161
|
+
const prelimSanitizedAccountKey = key.replace(/\s+/g, "");
|
|
162
|
+
const sanitizedAccountKey = version === "v2" ? prelimSanitizedAccountKey.replace(/[\W]+/g, "_") : prelimSanitizedAccountKey;
|
|
163
|
+
return `${idMode === "prefix" ? "id_" : ""}${sanitizedAccountKey}${idMode === "suffix" ? "_id" : ""}`;
|
|
164
|
+
};
|
|
165
|
+
var makeAccountTemplatePath = (account, accountPath, accountTemplatePathVersion) => {
|
|
166
|
+
if (!account.template || !account.key) {
|
|
167
|
+
return accountPath;
|
|
168
|
+
}
|
|
169
|
+
const templateVars = new Set(
|
|
170
|
+
accountPath.split("/").flatMap((components) => {
|
|
171
|
+
const [, literalTemplateKey] = components.split(":");
|
|
172
|
+
if (!literalTemplateKey) {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
return getStringParameters(literalTemplateKey);
|
|
176
|
+
}) ?? []
|
|
177
|
+
);
|
|
178
|
+
let i = 0;
|
|
179
|
+
const startsWithAlphabet = /^[A-Za-z]/.test(account.key[0]);
|
|
180
|
+
let id = generateAccountKey(
|
|
181
|
+
account.key,
|
|
182
|
+
startsWithAlphabet ? "suffix" : "prefix",
|
|
183
|
+
accountTemplatePathVersion
|
|
184
|
+
);
|
|
185
|
+
while (templateVars.has(id)) {
|
|
186
|
+
i += 1;
|
|
187
|
+
id = `${generateAccountKey(
|
|
188
|
+
account.key,
|
|
189
|
+
startsWithAlphabet ? "suffix" : "prefix",
|
|
190
|
+
accountTemplatePathVersion
|
|
191
|
+
)}_${i}`;
|
|
192
|
+
}
|
|
193
|
+
return `${accountPath}:{{${id}}}`;
|
|
194
|
+
};
|
|
195
|
+
var enhanceAccount = ({
|
|
196
|
+
account,
|
|
197
|
+
depth,
|
|
198
|
+
parentStructuralPath,
|
|
199
|
+
templatePath,
|
|
200
|
+
accountTemplatePathVersion,
|
|
201
|
+
accountIds
|
|
202
|
+
}) => {
|
|
203
|
+
if (account.id) {
|
|
204
|
+
return account;
|
|
205
|
+
}
|
|
206
|
+
const structuralPathForAccount = parentStructuralPath === "" ? account.key : `${parentStructuralPath}/${account.key}`;
|
|
207
|
+
const idForAccount = accountIds?.[structuralPathForAccount] ?? lil_id_default();
|
|
208
|
+
const newAccount = {
|
|
209
|
+
...account,
|
|
210
|
+
type: account.type,
|
|
211
|
+
templatePath,
|
|
212
|
+
depth,
|
|
213
|
+
structuralPath: structuralPathForAccount,
|
|
214
|
+
children: account.children?.map((acc) => {
|
|
215
|
+
const idForChild = accountIds?.[`${structuralPathForAccount}/${acc.key}`] ?? lil_id_default();
|
|
216
|
+
return enhanceAccount({
|
|
217
|
+
account: acc,
|
|
218
|
+
parentStructuralPath: structuralPathForAccount,
|
|
219
|
+
templatePath: makeAccountTemplatePath(
|
|
220
|
+
acc,
|
|
221
|
+
`${templatePath}/${acc.key}`,
|
|
222
|
+
accountTemplatePathVersion
|
|
223
|
+
),
|
|
224
|
+
depth: depth + 1,
|
|
225
|
+
id: idForChild,
|
|
226
|
+
accountTemplatePathVersion,
|
|
227
|
+
accountIds
|
|
228
|
+
});
|
|
229
|
+
}) ?? [],
|
|
230
|
+
id: idForAccount
|
|
231
|
+
};
|
|
232
|
+
return newAccount;
|
|
233
|
+
};
|
|
234
|
+
var enhanceCoA = (chartOfAccounts, opts) => {
|
|
235
|
+
const accountTemplatePathVersion = opts?.accountTemplatePathVersion ?? "v2";
|
|
236
|
+
const accountIds = opts?.accountIds;
|
|
237
|
+
const accounts = chartOfAccounts.accounts.map(
|
|
238
|
+
(acc) => enhanceAccount({
|
|
239
|
+
account: acc,
|
|
240
|
+
depth: 1,
|
|
241
|
+
parentStructuralPath: "",
|
|
242
|
+
templatePath: makeAccountTemplatePath(
|
|
243
|
+
acc,
|
|
244
|
+
acc.key,
|
|
245
|
+
accountTemplatePathVersion
|
|
246
|
+
),
|
|
247
|
+
// these are root nodes so structural path is the same as the key
|
|
248
|
+
id: accountIds?.[acc.key] ?? lil_id_default(),
|
|
249
|
+
accountTemplatePathVersion,
|
|
250
|
+
accountIds
|
|
251
|
+
})
|
|
252
|
+
);
|
|
253
|
+
const { accountIdToAccount } = recomputeAccountCache(accounts);
|
|
254
|
+
return {
|
|
255
|
+
...chartOfAccounts,
|
|
256
|
+
accounts,
|
|
257
|
+
accountIdToAccount
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
var enhanceLedgerEntry = (ledgerEntry, accountIdToAccount, entryId) => {
|
|
261
|
+
if (ledgerEntry.id) {
|
|
262
|
+
return ledgerEntry;
|
|
263
|
+
}
|
|
264
|
+
const structuralPathToAccount = keyBy_default(
|
|
265
|
+
Object.values(accountIdToAccount),
|
|
266
|
+
"structuralPath"
|
|
267
|
+
);
|
|
268
|
+
const enhancedLines = (ledgerEntry.lines ?? []).map(
|
|
269
|
+
(line) => {
|
|
270
|
+
let account;
|
|
271
|
+
if (line.account) {
|
|
272
|
+
account = line.account;
|
|
273
|
+
const structuralPath = getStructuralPath(line.account.path);
|
|
274
|
+
if (structuralPathToAccount[structuralPath]) {
|
|
275
|
+
account.id = structuralPathToAccount[structuralPath].id;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
...line,
|
|
280
|
+
account,
|
|
281
|
+
id: lil_id_default(),
|
|
282
|
+
tags: line.tags?.map((t) => ({
|
|
283
|
+
id: lil_id_default(),
|
|
284
|
+
key: t.key,
|
|
285
|
+
value: t.value
|
|
286
|
+
}))
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
);
|
|
290
|
+
const enhancedConditions = (ledgerEntry.conditions ?? []).map((condition) => {
|
|
291
|
+
let account;
|
|
292
|
+
if (condition.account) {
|
|
293
|
+
account = condition.account;
|
|
294
|
+
const structuralPath = getStructuralPath(condition.account.path);
|
|
295
|
+
if (structuralPathToAccount[structuralPath]) {
|
|
296
|
+
account.id = structuralPathToAccount[structuralPath].id;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
...condition,
|
|
301
|
+
account,
|
|
302
|
+
id: lil_id_default()
|
|
303
|
+
};
|
|
304
|
+
});
|
|
305
|
+
const enhancedTags = (ledgerEntry.tags ?? []).map((tag) => ({
|
|
306
|
+
id: lil_id_default(),
|
|
307
|
+
key: tag.key,
|
|
308
|
+
value: tag.value
|
|
309
|
+
}));
|
|
310
|
+
const enhancedGroups = (ledgerEntry.groups ?? []).map((group) => ({
|
|
311
|
+
id: lil_id_default(),
|
|
312
|
+
key: group.key,
|
|
313
|
+
value: group.value
|
|
314
|
+
}));
|
|
315
|
+
return {
|
|
316
|
+
...ledgerEntry,
|
|
317
|
+
typeVersion: ledgerEntry.typeVersion ?? 1,
|
|
318
|
+
parameters: ledgerEntry.parameters ?? {},
|
|
319
|
+
lines: enhancedLines,
|
|
320
|
+
conditions: enhancedConditions,
|
|
321
|
+
tags: enhancedTags,
|
|
322
|
+
groups: enhancedGroups,
|
|
323
|
+
id: entryId ?? lil_id_default()
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
var enhanceLedgerEntries = (params) => {
|
|
327
|
+
const { ledgerEntries, accountIdToAccount } = params;
|
|
328
|
+
return ledgerEntries.types.map(
|
|
329
|
+
(entry) => enhanceLedgerEntry(entry, accountIdToAccount)
|
|
330
|
+
);
|
|
331
|
+
};
|
|
332
|
+
var enhanceScene = (scene) => {
|
|
333
|
+
const internalSceneId = ("id" in scene ? scene.id : void 0) ?? lil_id_default();
|
|
334
|
+
return {
|
|
335
|
+
id: internalSceneId,
|
|
336
|
+
name: scene.name,
|
|
337
|
+
// Omitted like the deployable scene, never `payments: undefined`.
|
|
338
|
+
...scene.payments && { payments: scene.payments },
|
|
339
|
+
events: scene.events.map((event) => ({
|
|
340
|
+
...event,
|
|
341
|
+
id: ("id" in event ? event.id : void 0) ?? lil_id_default()
|
|
342
|
+
}))
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
var determineAccountTemplatePathVersion = (schema) => {
|
|
346
|
+
const re = /^[a-zA-Z_]+[a-zA-Z0-9_]*$/;
|
|
347
|
+
const doesSchemaUseValidGraphQlVars = schema.ledgerEntries.types.every(
|
|
348
|
+
(entry) => entry.lines.filter((line) => line.account !== void 0).every((line) => {
|
|
349
|
+
const params = getStringParameters(line.account?.path);
|
|
350
|
+
return params.length === 0 || params.every((param) => re.exec(param) !== null);
|
|
351
|
+
})
|
|
352
|
+
);
|
|
353
|
+
return doesSchemaUseValidGraphQlVars ? "v2" : "v1";
|
|
354
|
+
};
|
|
355
|
+
var enhanceSchema = (schema) => {
|
|
356
|
+
const { chartOfAccounts } = schema;
|
|
357
|
+
const enhancedChartOfAccounts = enhanceCoA(chartOfAccounts, {
|
|
358
|
+
accountTemplatePathVersion: determineAccountTemplatePathVersion(schema)
|
|
359
|
+
});
|
|
360
|
+
const enhancedLedgerEntries = {
|
|
361
|
+
types: enhanceLedgerEntries({
|
|
362
|
+
ledgerEntries: schema.ledgerEntries,
|
|
363
|
+
accountIdToAccount: enhancedChartOfAccounts.accountIdToAccount
|
|
364
|
+
})
|
|
365
|
+
};
|
|
366
|
+
return {
|
|
367
|
+
...schema,
|
|
368
|
+
chartOfAccounts: enhancedChartOfAccounts,
|
|
369
|
+
ledgerEntries: enhancedLedgerEntries,
|
|
370
|
+
scenes: schema.scenes && schema.scenes.length > 0 ? schema.scenes.map((scene) => enhanceScene(scene)) : defaultScenes,
|
|
371
|
+
groups: schema.groups ?? void 0
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
var SchemaCurrencyMatchInput = z.object({
|
|
375
|
+
customCurrencyId: z.string().optional(),
|
|
376
|
+
code: z.string()
|
|
377
|
+
});
|
|
378
|
+
var ExternalAccountMatchInput = z.object({
|
|
379
|
+
id: z.string().optional(),
|
|
380
|
+
externalId: z.string().optional(),
|
|
381
|
+
linkId: z.string().optional(),
|
|
382
|
+
linkIk: z.string().optional()
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
// ../../fragment-compositions/visualizer/src/utils/computeStructuralPath.ts
|
|
386
|
+
init_cjs_shims();
|
|
387
|
+
function computeStructuralPath(accountId, accounts, parentId, visited = /* @__PURE__ */ new Set()) {
|
|
388
|
+
const account = accounts.get(accountId);
|
|
389
|
+
if (!account) {
|
|
390
|
+
return "";
|
|
391
|
+
}
|
|
392
|
+
const accountKey = account.key;
|
|
393
|
+
if (visited.has(accountId)) {
|
|
394
|
+
return accountKey;
|
|
395
|
+
}
|
|
396
|
+
visited.add(accountId);
|
|
397
|
+
if (!parentId) {
|
|
398
|
+
return accountKey;
|
|
399
|
+
}
|
|
400
|
+
if (parentId === accountId) {
|
|
401
|
+
return accountKey;
|
|
402
|
+
}
|
|
403
|
+
const parentAccount = accounts.get(parentId);
|
|
404
|
+
if (!parentAccount) {
|
|
405
|
+
return accountKey;
|
|
406
|
+
}
|
|
407
|
+
const parentPath = computeStructuralPath(
|
|
408
|
+
parentId,
|
|
409
|
+
accounts,
|
|
410
|
+
parentAccount.parentId,
|
|
411
|
+
visited
|
|
412
|
+
);
|
|
413
|
+
return parentPath ? `${parentPath}/${accountKey}` : accountKey;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// ../../fragment-compositions/visualizer/src/utils/index.ts
|
|
417
|
+
var makeLineKey = (line, lineNumber) => `${line.account.path}:${lineNumber}:${line.currency.code}`;
|
|
418
|
+
var allChildrenForAccount = (account) => {
|
|
419
|
+
if (account.children.length === 0) {
|
|
420
|
+
return [account.path ?? account.structuralPath];
|
|
421
|
+
}
|
|
422
|
+
const allChildPaths = [account.path ?? account.structuralPath];
|
|
423
|
+
account.children.forEach((child) => {
|
|
424
|
+
allChildPaths.push(child.path ?? child.structuralPath);
|
|
425
|
+
const grandChildren = allChildrenForAccount(child);
|
|
426
|
+
allChildPaths.push(...grandChildren);
|
|
427
|
+
});
|
|
428
|
+
return allChildPaths;
|
|
429
|
+
};
|
|
430
|
+
var accountHasChild = (params) => {
|
|
431
|
+
const { account, maybeChild } = params;
|
|
432
|
+
const childPath = maybeChild?.path;
|
|
433
|
+
if (!childPath) {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
return allChildrenForAccount(account).some(
|
|
437
|
+
(path) => childPath === path || childPath.startsWith(`${path}/`)
|
|
438
|
+
);
|
|
439
|
+
};
|
|
440
|
+
function hasAccountAndCurrency(obj) {
|
|
441
|
+
return !!obj.account?.id && !!obj.currency?.code;
|
|
442
|
+
}
|
|
443
|
+
var filterValidLinesAndConditions = (params) => {
|
|
444
|
+
const { entry } = params;
|
|
445
|
+
const narrowedLines = entry.lines.filter(hasAccountAndCurrency);
|
|
446
|
+
const narrowedConditions = entry.conditions.filter(hasAccountAndCurrency);
|
|
447
|
+
return {
|
|
448
|
+
...entry,
|
|
449
|
+
lines: narrowedLines,
|
|
450
|
+
conditions: narrowedConditions
|
|
451
|
+
};
|
|
452
|
+
};
|
|
453
|
+
var generateSimulatingEntry = (params) => {
|
|
454
|
+
const { entry: unvalidatedEntry, accountIdToAccount, onError } = params;
|
|
455
|
+
const entry = filterValidLinesAndConditions({ entry: unvalidatedEntry });
|
|
456
|
+
const entryParameters = entry.parameters;
|
|
457
|
+
try {
|
|
458
|
+
const newLines = entry.lines.map(
|
|
459
|
+
(line) => parameterizeSchemaLedgerLineInput({
|
|
460
|
+
// At this point, let's just assume the line is valid.
|
|
461
|
+
// Ideally, this would be validated before this point.
|
|
462
|
+
line,
|
|
463
|
+
entryParameters
|
|
464
|
+
})
|
|
465
|
+
).map((line) => {
|
|
466
|
+
const account = accountIdToAccount[line.account.id];
|
|
467
|
+
const parameterizedAccount = reparameterizeSchemaLedgerAccountInput({
|
|
468
|
+
// We want to ignore the constructed templatePath here, which contains vars0, vars1, etc.
|
|
469
|
+
account: {
|
|
470
|
+
...line.account,
|
|
471
|
+
...omit_default(account, ["templatePath"])
|
|
472
|
+
},
|
|
473
|
+
entryParameters,
|
|
474
|
+
fillParamOptions: {
|
|
475
|
+
allowMissingInChildren: true
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
return {
|
|
479
|
+
...line,
|
|
480
|
+
parameters: line.parameters.concat(parameterizedAccount.parameters),
|
|
481
|
+
account: {
|
|
482
|
+
...parameterizedAccount,
|
|
483
|
+
path: line.account.path
|
|
484
|
+
},
|
|
485
|
+
accountPath: parameterizedAccount.path
|
|
486
|
+
};
|
|
487
|
+
});
|
|
488
|
+
const conditions = entry.conditions.map(
|
|
489
|
+
(condition) => parameterizeSchemaLedgerEntryConditionInput({
|
|
490
|
+
condition,
|
|
491
|
+
entryParameters,
|
|
492
|
+
fillParamOptions: {
|
|
493
|
+
allowMissing: true,
|
|
494
|
+
allowMissingInChildren: true
|
|
495
|
+
}
|
|
496
|
+
})
|
|
497
|
+
).map((condition) => {
|
|
498
|
+
const account = accountIdToAccount[condition.account.id];
|
|
499
|
+
const parameterizedAccount = reparameterizeSchemaLedgerAccountInput({
|
|
500
|
+
account: {
|
|
501
|
+
...condition.account,
|
|
502
|
+
...omit_default(account, ["templatePath"])
|
|
503
|
+
},
|
|
504
|
+
entryParameters,
|
|
505
|
+
fillParamOptions: {
|
|
506
|
+
allowMissingInChildren: true
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
return {
|
|
510
|
+
...condition,
|
|
511
|
+
account: {
|
|
512
|
+
...parameterizedAccount,
|
|
513
|
+
path: condition.account.path
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
});
|
|
517
|
+
return {
|
|
518
|
+
...entry,
|
|
519
|
+
conditions,
|
|
520
|
+
lines: newLines
|
|
521
|
+
};
|
|
522
|
+
} catch (e) {
|
|
523
|
+
onError(e);
|
|
524
|
+
}
|
|
525
|
+
return void 0;
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
// src/utils/formatScenarioAccountBalances.ts
|
|
529
|
+
var formatScenarioAccountBalances = ({
|
|
530
|
+
accounts,
|
|
531
|
+
balances,
|
|
532
|
+
usedAccounts
|
|
533
|
+
}) => {
|
|
534
|
+
const buildNodes = (definitions, parentPath) => definitions.flatMap((account) => {
|
|
535
|
+
const prefix = parentPath ? `${parentPath}/` : "";
|
|
536
|
+
const instances = account.template ? [
|
|
537
|
+
...new Set(
|
|
538
|
+
usedAccounts.flatMap((balance) => {
|
|
539
|
+
if (!balance.accountPath.startsWith(prefix))
|
|
540
|
+
return [];
|
|
541
|
+
const segment = balance.accountPath.slice(prefix.length).split("/")[0];
|
|
542
|
+
return segment.startsWith(`${account.key}:`) ? [segment] : [];
|
|
543
|
+
})
|
|
544
|
+
)
|
|
545
|
+
].sort() : [];
|
|
546
|
+
const keys = instances.length > 0 ? instances : [
|
|
547
|
+
account.template ? `${account.key}:{{${account.key}_id}}` : account.key
|
|
548
|
+
];
|
|
549
|
+
return keys.flatMap((key) => {
|
|
550
|
+
const path = prefix + key;
|
|
551
|
+
const accountScope = { key, path, structuralPath: path, children: [] };
|
|
552
|
+
const isUnderAccount = (reference) => accountHasChild({
|
|
553
|
+
account: accountScope,
|
|
554
|
+
maybeChild: { path: reference.accountPath }
|
|
555
|
+
});
|
|
556
|
+
const totals = /* @__PURE__ */ new Map();
|
|
557
|
+
usedAccounts.filter(isUnderAccount).forEach(
|
|
558
|
+
(reference) => totals.set(
|
|
559
|
+
JSON.stringify([reference.currencyCode, reference.currency]),
|
|
560
|
+
{
|
|
561
|
+
currency: reference.currency,
|
|
562
|
+
amount: 0n,
|
|
563
|
+
precision: reference.precision
|
|
564
|
+
}
|
|
565
|
+
)
|
|
566
|
+
);
|
|
567
|
+
if (totals.size === 0)
|
|
568
|
+
return [];
|
|
569
|
+
balances.forEach((balance) => {
|
|
570
|
+
if (isUnderAccount(balance)) {
|
|
571
|
+
const currencyKey = JSON.stringify([
|
|
572
|
+
balance.currencyCode,
|
|
573
|
+
balance.currency
|
|
574
|
+
]);
|
|
575
|
+
totals.set(currencyKey, {
|
|
576
|
+
currency: balance.currency,
|
|
577
|
+
amount: (totals.get(currencyKey)?.amount ?? 0n) + balance.amount,
|
|
578
|
+
precision: balance.precision
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
const balanceLabel = [...totals.values()].map(
|
|
583
|
+
({ currency, amount, precision }) => formatBalance({ amount, currency, precision })
|
|
584
|
+
).join(", ");
|
|
585
|
+
return [
|
|
586
|
+
{
|
|
587
|
+
label: `${key} [${balanceLabel}]`,
|
|
588
|
+
type: account.type,
|
|
589
|
+
children: buildNodes(account.children ?? [], path)
|
|
590
|
+
}
|
|
591
|
+
];
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
return formatAccountHierarchy({
|
|
595
|
+
accounts: buildNodes(accounts, ""),
|
|
596
|
+
formatLabel: (account) => account.label
|
|
597
|
+
}).join("\n");
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
export {
|
|
601
|
+
lil_id_default,
|
|
602
|
+
enhanceCoA,
|
|
603
|
+
enhanceLedgerEntry,
|
|
604
|
+
enhanceSchema,
|
|
605
|
+
computeStructuralPath,
|
|
606
|
+
makeLineKey,
|
|
607
|
+
generateSimulatingEntry,
|
|
608
|
+
formatScenarioAccountBalances
|
|
609
|
+
};
|