@veztraa/report-core 0.1.0 → 0.1.1
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 +94 -0
- package/package.json +7 -3
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @veztraa/report-core
|
|
2
|
+
|
|
3
|
+
Core types, Zod schema, and expression engine for ReportForge. Used internally by `@veztraa/report-renderer` and `@veztraa/report-designer` — you only need this directly if you're building your own renderer or tooling on top of the ReportForge template format.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @veztraa/report-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Template Schema
|
|
12
|
+
|
|
13
|
+
Every ReportForge report is a plain JSON object that matches the `Template` type:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import type { Template } from "@veztraa/report-core";
|
|
17
|
+
|
|
18
|
+
const template: Template = {
|
|
19
|
+
version: "1.0",
|
|
20
|
+
name: "Invoice",
|
|
21
|
+
page: {
|
|
22
|
+
size: "A4", // A4 | A3 | A5 | Letter | Legal
|
|
23
|
+
orientation: "portrait", // portrait | landscape
|
|
24
|
+
margin: { top: 30, right: 30, bottom: 30, left: 30 },
|
|
25
|
+
},
|
|
26
|
+
header: { height: 60, elements: [] },
|
|
27
|
+
footer: { height: 40, elements: [] },
|
|
28
|
+
body: {
|
|
29
|
+
elements: [
|
|
30
|
+
{
|
|
31
|
+
id: "el_001",
|
|
32
|
+
type: "text",
|
|
33
|
+
x: 0, y: 0, width: 400, height: 30,
|
|
34
|
+
content: "Invoice #{{invoice.number}}",
|
|
35
|
+
style: { fontSize: 18, fontWeight: "bold", color: "#1a1a2e" },
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: "el_002",
|
|
39
|
+
type: "table",
|
|
40
|
+
x: 0, y: 50, width: 535, height: 200,
|
|
41
|
+
dataSource: "items",
|
|
42
|
+
columns: [
|
|
43
|
+
{ key: "name", label: "Item", width: 300 },
|
|
44
|
+
{ key: "qty", label: "Qty", width: 80 },
|
|
45
|
+
{ key: "price", label: "Price", width: 100 },
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Element Types
|
|
54
|
+
|
|
55
|
+
| Type | Description |
|
|
56
|
+
|---|---|
|
|
57
|
+
| `text` | Plain text with `{{field}}` bindings |
|
|
58
|
+
| `richtext` | HTML rich text |
|
|
59
|
+
| `table` | Data-bound table with repeating rows |
|
|
60
|
+
| `image` | Image from URL or base64 |
|
|
61
|
+
| `chart` | Bar, line, or pie chart |
|
|
62
|
+
| `barcode` | 1D barcode (Code128, EAN, etc.) |
|
|
63
|
+
| `qrcode` | QR code |
|
|
64
|
+
| `rectangle` | Filled or stroked rectangle |
|
|
65
|
+
| `line` | Horizontal or vertical line |
|
|
66
|
+
| `pagebreak` | Forces a new page |
|
|
67
|
+
|
|
68
|
+
## Expression Engine
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { evaluate, evaluateCondition, resolveArray } from "@veztraa/report-core";
|
|
72
|
+
|
|
73
|
+
const data = { user: { name: "Alice" }, items: [{ price: 10 }, { price: 20 }] };
|
|
74
|
+
|
|
75
|
+
evaluate("Hello {{user.name}}!", data); // "Hello Alice!"
|
|
76
|
+
evaluate("Total: {{items.1.price}}", data); // "Total: 20"
|
|
77
|
+
evaluateCondition("{{user.name}} === 'Alice'", data); // true
|
|
78
|
+
resolveArray("items", data); // [{ price: 10 }, { price: 20 }]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Schema Validation
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { TemplateSchema } from "@veztraa/report-core";
|
|
85
|
+
|
|
86
|
+
const result = TemplateSchema.safeParse(untrustedInput);
|
|
87
|
+
if (!result.success) {
|
|
88
|
+
console.error(result.error.issues);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT © [Veztraa Innovations](https://veztraa.com)
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veztraa/report-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Core types, schema, and expression engine for ReportForge",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
|
-
"files": [
|
|
10
|
-
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
11
15
|
"exports": {
|
|
12
16
|
".": {
|
|
13
17
|
"import": "./dist/index.js",
|