@noy-db/as-xlsx 0.1.0-pre.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/LICENSE +21 -0
- package/README.md +138 -0
- package/dist/index.cjs +624 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +274 -0
- package/dist/index.d.ts +274 -0
- package/dist/index.js +579 -0
- package/dist/index.js.map +1 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 vLannaAi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# @noy-db/as-xlsx
|
|
2
|
+
|
|
3
|
+
Excel spreadsheet plaintext export for noy-db. Produces a real
|
|
4
|
+
`.xlsx` (Office Open XML) that opens natively in Excel, Numbers,
|
|
5
|
+
LibreOffice Calc, and Google Sheets.
|
|
6
|
+
|
|
7
|
+
Zero runtime dependencies — the XLSX encoder ships SpreadsheetML
|
|
8
|
+
parts and reuses `@noy-db/as-zip`'s zip writer. No SheetJS, no
|
|
9
|
+
ExcelJS, no xlsx-populate — ~230 LOC across the two-file encoder.
|
|
10
|
+
|
|
11
|
+
Part of the `@noy-db/as-*` portable-artefact family, plaintext
|
|
12
|
+
tier. See [`docs/packages-exports.md#authorization-model`](https://github.com/vLannaAi/noy-db/blob/main/docs/packages-exports.md#authorization-model).
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add @noy-db/as-xlsx @noy-db/as-zip @noy-db/hub
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`@noy-db/as-zip` + `@noy-db/hub` are peer deps.
|
|
21
|
+
|
|
22
|
+
## Authorisation (RFC #249)
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
await db.grant('firm', {
|
|
26
|
+
userId: 'accountant',
|
|
27
|
+
role: 'viewer',
|
|
28
|
+
passphrase: '…',
|
|
29
|
+
exportCapability: { plaintext: ['xlsx'] }, // or ['*']
|
|
30
|
+
})
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Every entry point calls `assertCanExport('plaintext', 'xlsx')`.
|
|
34
|
+
Absent the grant → `ExportCapabilityError`.
|
|
35
|
+
|
|
36
|
+
## API
|
|
37
|
+
|
|
38
|
+
### `toBytes(vault, options)` — raw xlsx bytes
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { toBytes } from '@noy-db/as-xlsx'
|
|
42
|
+
|
|
43
|
+
const bytes = await toBytes(vault, {
|
|
44
|
+
sheets: [
|
|
45
|
+
{
|
|
46
|
+
name: 'Invoices',
|
|
47
|
+
collection: 'invoices',
|
|
48
|
+
columns: ['id', 'client', 'amount', 'status', 'issueDate'],
|
|
49
|
+
filter: (r) => r.status !== 'draft',
|
|
50
|
+
},
|
|
51
|
+
{ name: 'Payments', collection: 'payments' },
|
|
52
|
+
],
|
|
53
|
+
})
|
|
54
|
+
// Uint8Array → fs.writeFile, Blob upload, S3 PutObject, …
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### `download(vault, options)` — browser
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { download } from '@noy-db/as-xlsx'
|
|
61
|
+
|
|
62
|
+
await download(vault, {
|
|
63
|
+
sheets: [{ name: 'Invoices', collection: 'invoices' }],
|
|
64
|
+
filename: 'invoices-2026-03.xlsx',
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### `write(vault, path, options)` — Node file
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { write } from '@noy-db/as-xlsx'
|
|
72
|
+
|
|
73
|
+
await write(vault, '/tmp/invoices.xlsx', {
|
|
74
|
+
sheets: [{ name: 'Invoices', collection: 'invoices' }],
|
|
75
|
+
acknowledgeRisks: true,
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Shorthand — one collection, one sheet
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { toBytesFromCollection } from '@noy-db/as-xlsx'
|
|
83
|
+
|
|
84
|
+
const bytes = await toBytesFromCollection(vault, 'invoices')
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Type coercion
|
|
88
|
+
|
|
89
|
+
| JS type | Cell type in xlsx |
|
|
90
|
+
|---------|-------------------|
|
|
91
|
+
| `number` (finite) | numeric |
|
|
92
|
+
| `boolean` | boolean (`t="b"`) |
|
|
93
|
+
| `string` | shared-string (`t="s"`, Unicode-safe) |
|
|
94
|
+
| `Date` | ISO-8601 string |
|
|
95
|
+
| `null` / `undefined` / `''` | empty cell |
|
|
96
|
+
| `object` / `Array` | `JSON.stringify` via shared-string |
|
|
97
|
+
|
|
98
|
+
Dates are stored as ISO strings rather than Excel's serial-day
|
|
99
|
+
encoding — the receiving spreadsheet sees text. Cell-format styles
|
|
100
|
+
are out of scope for this minimal writer; format via Excel's
|
|
101
|
+
built-in date detection or paste-special at open time.
|
|
102
|
+
|
|
103
|
+
## Unicode
|
|
104
|
+
|
|
105
|
+
Strings route through the shared-strings table (`xl/sharedStrings.xml`)
|
|
106
|
+
rather than being inlined on cells. Required for Excel to correctly
|
|
107
|
+
handle non-ASCII text (Thai, Arabic, Chinese, emoji). Tested with
|
|
108
|
+
Thai + Arabic + English round-trip.
|
|
109
|
+
|
|
110
|
+
## Low-level encoder
|
|
111
|
+
|
|
112
|
+
Exposed for consumers who want to build workbooks from non-noy-db
|
|
113
|
+
sources:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { writeXlsx, type XlsxSheet } from '@noy-db/as-xlsx'
|
|
117
|
+
|
|
118
|
+
const bytes = writeXlsx([
|
|
119
|
+
{
|
|
120
|
+
name: 'Results',
|
|
121
|
+
header: ['Name', 'Score'],
|
|
122
|
+
rows: [['Alice', 42], ['Bob', 37]],
|
|
123
|
+
},
|
|
124
|
+
])
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Not supported
|
|
128
|
+
|
|
129
|
+
Pure data export — styles, formulas, merged cells, frozen panes,
|
|
130
|
+
auto-filter, charts, images, drawings are all out of scope. Need
|
|
131
|
+
rich formatting? Use SheetJS / ExcelJS for authoring, and let
|
|
132
|
+
consumers of the exported xlsx apply their own formatting.
|
|
133
|
+
|
|
134
|
+
## Related
|
|
135
|
+
|
|
136
|
+
- `@noy-db/as-csv` — flat CSV (simpler format, no multi-sheet)
|
|
137
|
+
- `@noy-db/as-zip` — composite archive (records + blobs)
|
|
138
|
+
- `@noy-db/as-blob` — single attachment
|