fatoority 0.5.0 → 0.6.0
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 +9 -9
- package/errors.d.mts +67 -0
- package/errors.mjs +94 -0
- package/fatoora_ffi.wasm +0 -0
- package/generated/Adjustment.d.mts +9 -3
- package/generated/Adjustment.mjs +12 -6
- package/generated/AdjustmentKind.d.mts +24 -0
- package/generated/AdjustmentKind.mjs +72 -0
- package/generated/AllowanceCharge.d.mts +6 -4
- package/generated/AllowanceCharge.mjs +10 -8
- package/generated/ClearanceMode.d.mts +30 -0
- package/generated/ClearanceMode.mjs +78 -0
- package/generated/ClearanceStatus.d.mts +34 -0
- package/generated/ClearanceStatus.mjs +84 -0
- package/generated/{CsidCompliance.d.mts → ComplianceCsid.d.mts} +4 -3
- package/generated/{CsidCompliance.mjs → ComplianceCsid.mjs} +21 -13
- package/generated/ComplianceRequest.d.mts +2 -2
- package/generated/ComplianceRequest.mjs +2 -2
- package/generated/Config.d.mts +3 -2
- package/generated/Config.mjs +11 -3
- package/generated/CsrProperties.d.mts +6 -2
- package/generated/CsrProperties.mjs +7 -3
- package/generated/Environment.d.mts +28 -0
- package/generated/Environment.mjs +78 -0
- package/generated/FinalizedInvoice.d.mts +1 -1
- package/generated/FinalizedInvoice.mjs +2 -2
- package/generated/InvoiceBuilder.d.mts +18 -21
- package/generated/InvoiceBuilder.mjs +31 -168
- package/generated/InvoiceData.d.mts +7 -4
- package/generated/InvoiceData.mjs +8 -5
- package/generated/InvoiceFlag.d.mts +36 -0
- package/generated/InvoiceFlag.mjs +105 -0
- package/generated/InvoiceLineItem.d.mts +5 -3
- package/generated/InvoiceLineItem.mjs +8 -6
- package/generated/{Signer.d.mts → InvoiceSigner.d.mts} +3 -3
- package/generated/{Signer.mjs → InvoiceSigner.mjs} +13 -13
- package/generated/InvoiceSubType.d.mts +26 -0
- package/generated/InvoiceSubType.mjs +74 -0
- package/generated/InvoiceTypeKind.d.mts +40 -0
- package/generated/InvoiceTypeKind.mjs +92 -0
- package/generated/LineItemBuilder.d.mts +2 -1
- package/generated/LineItemBuilder.mjs +2 -1
- package/generated/MessageType.d.mts +38 -0
- package/generated/MessageType.mjs +90 -0
- package/generated/{CsidProduction.d.mts → ProductionCsid.d.mts} +4 -3
- package/generated/{CsidProduction.mjs → ProductionCsid.mjs} +21 -13
- package/generated/ProductionRequest.d.mts +2 -2
- package/generated/ProductionRequest.mjs +2 -2
- package/generated/ReportingStatus.d.mts +34 -0
- package/generated/ReportingStatus.mjs +84 -0
- package/generated/Severity.d.mts +30 -0
- package/generated/Severity.mjs +78 -0
- package/generated/SignedInvoice.d.mts +1 -1
- package/generated/SignedInvoice.mjs +2 -2
- package/generated/ValidationLayer.d.mts +49 -0
- package/generated/ValidationLayer.mjs +107 -0
- package/generated/ValidationLocationKind.d.mts +37 -0
- package/generated/ValidationLocationKind.mjs +89 -0
- package/generated/ValidationMessage.d.mts +20 -2
- package/generated/ValidationMessage.mjs +52 -0
- package/generated/ValidationResponse.d.mts +21 -3
- package/generated/ValidationResponse.mjs +52 -0
- package/generated/ValidationResults.d.mts +10 -1
- package/generated/ValidationResults.mjs +26 -0
- package/generated/ValidationStatus.d.mts +38 -0
- package/generated/ValidationStatus.mjs +90 -0
- package/generated/VatBreakdown.d.mts +4 -3
- package/generated/VatBreakdown.mjs +5 -4
- package/generated/VatCategory.d.mts +40 -0
- package/generated/VatCategory.mjs +92 -0
- package/generated/Xml.d.mts +12 -5
- package/generated/Xml.mjs +15 -11
- package/generated/ZatcaClient.d.mts +10 -9
- package/generated/ZatcaClient.mjs +15 -14
- package/generated/ZatcaFinding.d.mts +59 -0
- package/generated/ZatcaFinding.mjs +239 -0
- package/generated/ZatcaRuleSource.d.mts +26 -0
- package/generated/ZatcaRuleSource.mjs +97 -0
- package/generated/ZatcaStage.d.mts +49 -0
- package/generated/ZatcaStage.mjs +107 -0
- package/generated/ZatcaStageReport.d.mts +41 -0
- package/generated/ZatcaStageReport.mjs +168 -0
- package/generated/ZatcaStageStatus.d.mts +45 -0
- package/generated/ZatcaStageStatus.mjs +101 -0
- package/generated/ZatcaValidationReport.d.mts +63 -0
- package/generated/ZatcaValidationReport.mjs +228 -0
- package/generated/index.d.mts +45 -5
- package/generated/index.mjs +45 -5
- package/index.d.mts +131 -15
- package/index.mjs +111 -33
- package/members.mjs +67 -0
- package/package.json +11 -5
- package/patch.mjs +121 -0
- package/raw.d.mts +731 -0
- package/raw.mjs +4 -0
package/patch.mjs
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Internal: adapts the generated classes in place: typed errors, `create`,
|
|
2
|
+
// value getters as properties and `Text` results as strings (see members.mjs).
|
|
3
|
+
// Both `fatoority` and `fatoority/raw` import this module, so the classes
|
|
4
|
+
// behave the same through either entry point and instances returned anywhere
|
|
5
|
+
// share one prototype.
|
|
6
|
+
import * as generated from './generated/index.mjs';
|
|
7
|
+
import { FatooraError, fromBindingError } from './errors.mjs';
|
|
8
|
+
import { properties, renamedMembers, textResults } from './members.mjs';
|
|
9
|
+
|
|
10
|
+
const { BindingError } = generated;
|
|
11
|
+
const wrapped = Symbol('fatoority.wrapped');
|
|
12
|
+
|
|
13
|
+
function translate(error) {
|
|
14
|
+
// Generated code throws `Error('BindingError: ...', { cause: BindingError })`.
|
|
15
|
+
if (error instanceof Error && !(error instanceof FatooraError) && error.cause instanceof BindingError) {
|
|
16
|
+
return fromBindingError(error.cause);
|
|
17
|
+
}
|
|
18
|
+
return error;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const text = (value) => value === null ? null : value.value();
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Return `fn` under `name`, converting its result and throwing the typed errors
|
|
25
|
+
* of errors.mjs with a stack that starts at the caller.
|
|
26
|
+
*/
|
|
27
|
+
function adapt(name, fn, convert) {
|
|
28
|
+
const adapter = {
|
|
29
|
+
// A method shorthand keeps `this` and the name, without a prototype.
|
|
30
|
+
[name](...args) {
|
|
31
|
+
try { return convert(fn.apply(this, args)); }
|
|
32
|
+
catch (error) {
|
|
33
|
+
const typed = translate(error);
|
|
34
|
+
if (typed !== error) Error.captureStackTrace?.(typed, adapter); // V8 only
|
|
35
|
+
throw typed;
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
}[name];
|
|
39
|
+
adapter[wrapped] = true;
|
|
40
|
+
return adapter;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const same = (value) => value;
|
|
44
|
+
|
|
45
|
+
function adaptMembers(target, skip, shape = {}) {
|
|
46
|
+
const { properties = [], texts = [], booleans = [] } = shape;
|
|
47
|
+
for (const name of Object.getOwnPropertyNames(target)) {
|
|
48
|
+
if (skip.has(name)) continue;
|
|
49
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, name);
|
|
50
|
+
if (typeof descriptor.value !== 'function' || descriptor.value[wrapped]) continue; // getters, enum singletons
|
|
51
|
+
const original = descriptor.value;
|
|
52
|
+
const convert = texts.includes(name) ? text : booleans.includes(name) ? Boolean : same;
|
|
53
|
+
const adapted = adapt(name, original, convert);
|
|
54
|
+
if (properties.includes(name)) {
|
|
55
|
+
// A getter needs no arguments, so the adapter serves as one directly.
|
|
56
|
+
Object.defineProperty(target, name, { get: adapted, enumerable: false, configurable: true });
|
|
57
|
+
// Keep the generated result for the deprecated 0.5 aliases below.
|
|
58
|
+
if (!unconverted.has(target)) unconverted.set(target, new Map());
|
|
59
|
+
unconverted.get(target).set(name, adapt(name, original, booleans.includes(name) ? Boolean : same));
|
|
60
|
+
} else {
|
|
61
|
+
Object.defineProperty(target, name, { ...descriptor, value: adapted });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Diplomat 0.16's JS backend returns plain `bool` results as the WASM integer
|
|
67
|
+
// 0/1 although the declarations say `boolean`. tests/runtime.test.mjs checks
|
|
68
|
+
// this list against every `(): boolean` instance method in the declarations.
|
|
69
|
+
export const integerBooleanMethods = {
|
|
70
|
+
AllowanceCharge: ['hasVatRate'],
|
|
71
|
+
BytesList: ['isEmpty'],
|
|
72
|
+
InvoiceLineItem: ['hasVatRate', 'hasTaxTotal', 'hasGrossAmount'],
|
|
73
|
+
PaymentMeans: ['hasAccount'],
|
|
74
|
+
VatBreakdown: ['hasVatRate'],
|
|
75
|
+
ZatcaValidationReport: ['isComplete', 'hasErrors', 'isValid'],
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const staticSkip = new Set(['length', 'name', 'prototype']);
|
|
79
|
+
const prototypeSkip = new Set(['constructor']);
|
|
80
|
+
const unconverted = new Map(); // prototype -> property name -> method with the generated result
|
|
81
|
+
|
|
82
|
+
for (const [className, value] of Object.entries(generated)) {
|
|
83
|
+
if (typeof value !== 'function' || value === BindingError) continue;
|
|
84
|
+
if (typeof value.getAllEntries === 'function') { // an enum class, such as `InvoiceFlag.bit`
|
|
85
|
+
adaptMembers(value.prototype, prototypeSkip, { properties: properties[className] ?? [] });
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
// Diplomat names a Rust `new` constructor `new_`; the public name is `create`.
|
|
89
|
+
// Define it before adapting so both names report errors at the caller.
|
|
90
|
+
const generatedNew = value.new_;
|
|
91
|
+
if (typeof generatedNew === 'function' && !Object.hasOwn(value, 'create')) {
|
|
92
|
+
const create = { create(...args) { return generatedNew.apply(this, args); } }.create;
|
|
93
|
+
Object.defineProperty(value, 'create', { value: create, writable: true, configurable: true });
|
|
94
|
+
}
|
|
95
|
+
adaptMembers(value, staticSkip);
|
|
96
|
+
// Value getters become read-only properties and `Text` results plain strings
|
|
97
|
+
// (members.mjs, generated by scripts/generate_js_facade.py).
|
|
98
|
+
adaptMembers(value.prototype, prototypeSkip, {
|
|
99
|
+
properties: properties[className], texts: textResults[className],
|
|
100
|
+
booleans: integerBooleanMethods[className],
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 0.5 names of members renamed in 0.6 to match the Rust core. Each forwards
|
|
105
|
+
// to its new name and is removed in 0.7. `Adjustment.percentage(base, percent)`
|
|
106
|
+
// is static, so it does not clash with the `percentage` property of instances.
|
|
107
|
+
// An alias of a property stays a method with its 0.5 result (`Text`).
|
|
108
|
+
export { renamedMembers };
|
|
109
|
+
for (const [name, members] of Object.entries(renamedMembers)) {
|
|
110
|
+
for (const [side, aliases] of Object.entries(members)) {
|
|
111
|
+
const target = side === 'static' ? generated[name] : generated[name].prototype;
|
|
112
|
+
for (const [old, current] of Object.entries(aliases)) {
|
|
113
|
+
const getter = unconverted.get(target)?.get(current);
|
|
114
|
+
if (!getter && typeof target[current] !== 'function') throw new Error(`${name}.${current} is missing`);
|
|
115
|
+
const alias = getter
|
|
116
|
+
? { [old]() { return getter.call(this); } }[old]
|
|
117
|
+
: { [old](...args) { return this[current](...args); } }[old];
|
|
118
|
+
Object.defineProperty(target, old, { value: alias, writable: true, configurable: true });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|