bkper 4.2.0 → 4.3.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 +57 -56
- package/lib/commands/accounts/batch-create.d.ts +4 -6
- package/lib/commands/accounts/batch-create.d.ts.map +1 -1
- package/lib/commands/accounts/batch-create.js +6 -44
- package/lib/commands/accounts/batch-create.js.map +1 -1
- package/lib/commands/groups/batch-create.d.ts +4 -6
- package/lib/commands/groups/batch-create.d.ts.map +1 -1
- package/lib/commands/groups/batch-create.js +5 -25
- package/lib/commands/groups/batch-create.js.map +1 -1
- package/lib/commands/transactions/batch-create.d.ts +4 -6
- package/lib/commands/transactions/batch-create.d.ts.map +1 -1
- package/lib/commands/transactions/batch-create.js +5 -62
- package/lib/commands/transactions/batch-create.js.map +1 -1
- package/lib/input/index.d.ts +11 -8
- package/lib/input/index.d.ts.map +1 -1
- package/lib/input/index.js +17 -16
- package/lib/input/index.js.map +1 -1
- package/package.json +1 -1
- package/lib/input/csv-parser.d.ts +0 -9
- package/lib/input/csv-parser.d.ts.map +0 -1
- package/lib/input/csv-parser.js +0 -110
- package/lib/input/csv-parser.js.map +0 -1
- package/lib/input/format-detector.d.ts +0 -12
- package/lib/input/format-detector.d.ts.map +0 -1
- package/lib/input/format-detector.js +0 -14
- package/lib/input/format-detector.js.map +0 -1
package/README.md
CHANGED
|
@@ -475,77 +475,40 @@ When using the CLI from an AI agent, LLM, or automated script:
|
|
|
475
475
|
|
|
476
476
|
### Stdin input (batch operations)
|
|
477
477
|
|
|
478
|
-
Write commands (`account create`, `group create`, `transaction create`) accept data piped via stdin for batch operations. The format
|
|
478
|
+
Write commands (`account create`, `group create`, `transaction create`) accept JSON data piped via stdin for batch operations. The input format follows the [Bkper API Types](https://raw.githubusercontent.com/bkper/bkper-api-types/refs/heads/master/index.d.ts) exactly -- a single JSON object or an array of objects.
|
|
479
479
|
|
|
480
480
|
```bash
|
|
481
|
-
# Create
|
|
481
|
+
# Create transactions
|
|
482
|
+
echo '[{
|
|
483
|
+
"date": "2025-01-15",
|
|
484
|
+
"amount": "100.50",
|
|
485
|
+
"creditAccount": {"name": "Bank Account"},
|
|
486
|
+
"debitAccount": {"name": "Office Supplies"},
|
|
487
|
+
"description": "Printer paper",
|
|
488
|
+
"properties": {"invoice": "INV-001"}
|
|
489
|
+
}]' | bkper transaction create -b abc123
|
|
490
|
+
|
|
491
|
+
# Create accounts
|
|
482
492
|
echo '[{"name":"Cash","type":"ASSET"},{"name":"Revenue","type":"INCOMING"}]' | \
|
|
483
493
|
bkper account create -b abc123
|
|
484
494
|
|
|
485
|
-
# Create
|
|
486
|
-
|
|
495
|
+
# Create groups
|
|
496
|
+
echo '[{"name":"Fixed Costs","hidden":true}]' | \
|
|
497
|
+
bkper group create -b abc123
|
|
487
498
|
|
|
488
499
|
# Pipe from a script
|
|
489
500
|
python export_bank.py | bkper transaction create -b abc123
|
|
490
501
|
```
|
|
491
502
|
|
|
492
|
-
|
|
503
|
+
The input follows the exact `bkper.Transaction`, `bkper.Account`, or `bkper.Group` type from the [Bkper API Types](https://raw.githubusercontent.com/bkper/bkper-api-types/refs/heads/master/index.d.ts). Custom properties go inside the `properties` object.
|
|
493
504
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
| Field | Type | Required | Description |
|
|
497
|
-
| --------------- | -------- | -------- | --------------------------------------- |
|
|
498
|
-
| `date` | string | yes | ISO date (`YYYY-MM-DD`) |
|
|
499
|
-
| `amount` | string | yes | Numeric value |
|
|
500
|
-
| `description` | string | no | Transaction description |
|
|
501
|
-
| `creditAccount` | string | no | Source account (name or ID) |
|
|
502
|
-
| `debitAccount` | string | no | Destination account (name or ID) |
|
|
503
|
-
| `urls` | string[] | no | Array of URLs |
|
|
504
|
-
| `remoteIds` | string[] | no | Array of remote IDs (for deduplication) |
|
|
505
|
-
| _anything else_ | string | no | Stored as a custom property |
|
|
505
|
+
The `--property` CLI flag can override or delete properties from the stdin payload:
|
|
506
506
|
|
|
507
507
|
```bash
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
"date": "2025-01-15",
|
|
511
|
-
"amount": "100.50",
|
|
512
|
-
"creditAccount": "Bank Account",
|
|
513
|
-
"debitAccount": "Office Supplies",
|
|
514
|
-
"description": "Printer paper",
|
|
515
|
-
"urls": ["https://receipt.example.com/123"],
|
|
516
|
-
"remoteIds": ["BANK-TXN-456"],
|
|
517
|
-
"invoice": "INV-001"
|
|
518
|
-
}]' | bkper transaction create -b abc123
|
|
519
|
-
|
|
520
|
-
# CSV -- use comma-separated values for array fields
|
|
521
|
-
# date,amount,creditAccount,debitAccount,description,urls,remoteIds,invoice
|
|
522
|
-
# 2025-01-15,100.50,Bank Account,Office Supplies,Printer paper,https://receipt.example.com/123,BANK-TXN-456,INV-001
|
|
508
|
+
echo '[{"name":"Cash","type":"ASSET"}]' | \
|
|
509
|
+
bkper account create -b abc123 -p "region=LATAM"
|
|
523
510
|
```
|
|
524
511
|
|
|
525
|
-
#### Account fields
|
|
526
|
-
|
|
527
|
-
| Field | Type | Required | Description |
|
|
528
|
-
| --------------- | -------- | -------- | -------------------------------------------- |
|
|
529
|
-
| `name` | string | yes | Account name |
|
|
530
|
-
| `type` | string | no | `ASSET`, `LIABILITY`, `INCOMING`, `OUTGOING` |
|
|
531
|
-
| `groups` | string[] | no | Array of group names |
|
|
532
|
-
| _anything else_ | string | no | Stored as a custom property |
|
|
533
|
-
|
|
534
|
-
#### Group fields
|
|
535
|
-
|
|
536
|
-
| Field | Type | Required | Description |
|
|
537
|
-
| --------------- | ------- | -------- | --------------------------- |
|
|
538
|
-
| `name` | string | yes | Group name |
|
|
539
|
-
| `parent` | string | no | Parent group name or ID |
|
|
540
|
-
| `hidden` | boolean | no | Whether to hide the group |
|
|
541
|
-
| _anything else_ | string | no | Stored as a custom property |
|
|
542
|
-
|
|
543
|
-
#### JSON vs CSV
|
|
544
|
-
|
|
545
|
-
**JSON input** preserves native types -- use real arrays (`["a","b"]`) and booleans (`true`). A single object `{}` or an array `[{}, {}]`.
|
|
546
|
-
|
|
547
|
-
**CSV input** is flat strings -- use comma-separated values within a cell for array fields (e.g., `url1,url2` in a `urls` column). First row is headers.
|
|
548
|
-
|
|
549
512
|
**Batch output:** results are streamed as NDJSON (one JSON object per line), printed as each batch completes:
|
|
550
513
|
|
|
551
514
|
```
|
|
@@ -553,6 +516,44 @@ echo '[{
|
|
|
553
516
|
{"id":"tx-def","date":"2025-01-16","amount":"200.00","creditAccount":{...},...}
|
|
554
517
|
```
|
|
555
518
|
|
|
519
|
+
#### Writable fields reference
|
|
520
|
+
|
|
521
|
+
Only the fields below are meaningful when creating resources via stdin. Read-only fields (`id`, `createdAt`, `updatedAt`, etc.) are ignored.
|
|
522
|
+
|
|
523
|
+
**Transaction** (`bkper.Transaction`)
|
|
524
|
+
|
|
525
|
+
| Field | Type | Notes |
|
|
526
|
+
| --------------- | ---------------------------------- | --------------------------------------------- |
|
|
527
|
+
| `date` | `string` | ISO format `yyyy-MM-dd` |
|
|
528
|
+
| `amount` | `string` | Decimal format `####.##` (string, not number) |
|
|
529
|
+
| `creditAccount` | `{"name":"..."}` or `{"id":"..."}` | Reference to an existing account |
|
|
530
|
+
| `debitAccount` | `{"name":"..."}` or `{"id":"..."}` | Reference to an existing account |
|
|
531
|
+
| `description` | `string` | Free-text description |
|
|
532
|
+
| `urls` | `string[]` | Attached URLs (e.g. receipts) |
|
|
533
|
+
| `remoteIds` | `string[]` | External IDs to prevent duplicates |
|
|
534
|
+
| `properties` | `{"key": "value", ...}` | Custom key/value properties |
|
|
535
|
+
|
|
536
|
+
**Account** (`bkper.Account`)
|
|
537
|
+
|
|
538
|
+
| Field | Type | Notes |
|
|
539
|
+
| ------------ | ----------------------- | -------------------------------------------------- |
|
|
540
|
+
| `name` | `string` | Account name (required) |
|
|
541
|
+
| `type` | `string` | `ASSET`, `LIABILITY`, `INCOMING`, or `OUTGOING` |
|
|
542
|
+
| `credit` | `boolean` | Credit nature (`true`) or debit (`false`) |
|
|
543
|
+
| `archived` | `boolean` | Archive the account on creation |
|
|
544
|
+
| `permanent` | `boolean` | Permanent accounts (e.g. bank accounts, customers) |
|
|
545
|
+
| `groups` | `[{"name":"..."}, ...]` | Groups to assign by name or id |
|
|
546
|
+
| `properties` | `{"key": "value", ...}` | Custom key/value properties |
|
|
547
|
+
|
|
548
|
+
**Group** (`bkper.Group`)
|
|
549
|
+
|
|
550
|
+
| Field | Type | Notes |
|
|
551
|
+
| ------------ | ---------------------------------- | -------------------------------- |
|
|
552
|
+
| `name` | `string` | Group name (required) |
|
|
553
|
+
| `hidden` | `boolean` | Hide from transactions main menu |
|
|
554
|
+
| `parent` | `{"name":"..."}` or `{"id":"..."}` | Parent group for nesting |
|
|
555
|
+
| `properties` | `{"key": "value", ...}` | Custom key/value properties |
|
|
556
|
+
|
|
556
557
|
---
|
|
557
558
|
|
|
558
559
|
## Library
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import type { StdinValue } from '../../input/index.js';
|
|
2
1
|
/**
|
|
3
2
|
* Creates multiple accounts from stdin items using the batch API.
|
|
4
3
|
* Outputs NDJSON (one JSON object per line) as each chunk completes.
|
|
5
4
|
*
|
|
6
|
-
* Stdin
|
|
7
|
-
* name, type, groups
|
|
5
|
+
* Stdin items must follow the bkper.Account format exactly.
|
|
8
6
|
*
|
|
9
7
|
* @param bookId - Target book ID
|
|
10
|
-
* @param items - Parsed stdin items
|
|
11
|
-
* @param propertyOverrides - CLI --property flags that override stdin
|
|
8
|
+
* @param items - Parsed stdin items as bkper.Account payloads
|
|
9
|
+
* @param propertyOverrides - CLI --property flags that override stdin properties
|
|
12
10
|
*/
|
|
13
|
-
export declare function batchCreateAccounts(bookId: string, items: Record<string,
|
|
11
|
+
export declare function batchCreateAccounts(bookId: string, items: Record<string, unknown>[], propertyOverrides?: string[]): Promise<void>;
|
|
14
12
|
//# sourceMappingURL=batch-create.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-create.d.ts","sourceRoot":"","sources":["../../../src/commands/accounts/batch-create.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"batch-create.d.ts","sourceRoot":"","sources":["../../../src/commands/accounts/batch-create.ts"],"names":[],"mappings":"AAMA;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACrC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAChC,iBAAiB,CAAC,EAAE,MAAM,EAAE,GAC7B,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
|
|
@@ -8,34 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { getBkperInstance } from '../../bkper-factory.js';
|
|
11
|
-
import { Account
|
|
11
|
+
import { Account } from 'bkper-js';
|
|
12
12
|
import { parsePropertyFlag } from '../../utils/properties.js';
|
|
13
13
|
const CHUNK_SIZE = 100;
|
|
14
|
-
/**
|
|
15
|
-
* Resolves a StdinValue that may be a string[] or comma-separated string into a string array.
|
|
16
|
-
*/
|
|
17
|
-
function resolveArray(value) {
|
|
18
|
-
if (Array.isArray(value)) {
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
if (typeof value === 'string') {
|
|
22
|
-
return value
|
|
23
|
-
.split(',')
|
|
24
|
-
.map(s => s.trim())
|
|
25
|
-
.filter(Boolean);
|
|
26
|
-
}
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
29
14
|
/**
|
|
30
15
|
* Creates multiple accounts from stdin items using the batch API.
|
|
31
16
|
* Outputs NDJSON (one JSON object per line) as each chunk completes.
|
|
32
17
|
*
|
|
33
|
-
* Stdin
|
|
34
|
-
* name, type, groups
|
|
18
|
+
* Stdin items must follow the bkper.Account format exactly.
|
|
35
19
|
*
|
|
36
20
|
* @param bookId - Target book ID
|
|
37
|
-
* @param items - Parsed stdin items
|
|
38
|
-
* @param propertyOverrides - CLI --property flags that override stdin
|
|
21
|
+
* @param items - Parsed stdin items as bkper.Account payloads
|
|
22
|
+
* @param propertyOverrides - CLI --property flags that override stdin properties
|
|
39
23
|
*/
|
|
40
24
|
export function batchCreateAccounts(bookId, items, propertyOverrides) {
|
|
41
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -45,22 +29,8 @@ export function batchCreateAccounts(bookId, items, propertyOverrides) {
|
|
|
45
29
|
const chunk = items.slice(i, i + CHUNK_SIZE);
|
|
46
30
|
const accounts = [];
|
|
47
31
|
for (const item of chunk) {
|
|
48
|
-
const account = new Account(book);
|
|
49
|
-
|
|
50
|
-
account.setName(String(item.name));
|
|
51
|
-
if (item.type) {
|
|
52
|
-
const accountType = AccountType[String(item.type)];
|
|
53
|
-
if (accountType !== undefined)
|
|
54
|
-
account.setType(accountType);
|
|
55
|
-
}
|
|
56
|
-
// Set properties from stdin fields (excluding known fields)
|
|
57
|
-
const knownFields = new Set(['name', 'type', 'groups']);
|
|
58
|
-
for (const [key, value] of Object.entries(item)) {
|
|
59
|
-
if (!knownFields.has(key) && value !== '') {
|
|
60
|
-
account.setProperty(key, String(value));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// CLI --property flags override stdin
|
|
32
|
+
const account = new Account(book, item);
|
|
33
|
+
// CLI --property flags override stdin properties
|
|
64
34
|
if (propertyOverrides) {
|
|
65
35
|
for (const raw of propertyOverrides) {
|
|
66
36
|
const [key, value] = parsePropertyFlag(raw);
|
|
@@ -72,14 +42,6 @@ export function batchCreateAccounts(bookId, items, propertyOverrides) {
|
|
|
72
42
|
}
|
|
73
43
|
}
|
|
74
44
|
}
|
|
75
|
-
if (item.groups) {
|
|
76
|
-
for (const groupName of resolveArray(item.groups)) {
|
|
77
|
-
const group = yield book.getGroup(groupName);
|
|
78
|
-
if (group) {
|
|
79
|
-
account.addGroup(group);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
45
|
accounts.push(account);
|
|
84
46
|
}
|
|
85
47
|
const results = yield book.batchCreateAccounts(accounts);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-create.js","sourceRoot":"","sources":["../../../src/commands/accounts/batch-create.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"batch-create.js","sourceRoot":"","sources":["../../../src/commands/accounts/batch-create.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE9D,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB;;;;;;;;;GASG;AACH,MAAM,UAAgB,mBAAmB,CACrC,MAAc,EACd,KAAgC,EAChC,iBAA4B;;QAE5B,MAAM,KAAK,GAAG,gBAAgB,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC;YAChD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC;YAC7C,MAAM,QAAQ,GAAc,EAAE,CAAC;YAE/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACvB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,IAAqB,CAAC,CAAC;gBAEzD,iDAAiD;gBACjD,IAAI,iBAAiB,EAAE,CAAC;oBACpB,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;wBAClC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;wBAC5C,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;4BACf,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;wBAChC,CAAC;6BAAM,CAAC;4BACJ,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;wBACpC,CAAC;oBACL,CAAC;gBACL,CAAC;gBAED,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC3B,CAAC;YAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;YACzD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC3B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC;IACL,CAAC;CAAA"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import type { StdinValue } from '../../input/index.js';
|
|
2
1
|
/**
|
|
3
2
|
* Creates multiple groups from stdin items using the batch API.
|
|
4
3
|
* Outputs NDJSON (one JSON object per line) as each chunk completes.
|
|
5
4
|
*
|
|
6
|
-
* Stdin
|
|
7
|
-
* name, parent, hidden
|
|
5
|
+
* Stdin items must follow the bkper.Group format exactly.
|
|
8
6
|
*
|
|
9
7
|
* @param bookId - Target book ID
|
|
10
|
-
* @param items - Parsed stdin items
|
|
11
|
-
* @param propertyOverrides - CLI --property flags that override stdin
|
|
8
|
+
* @param items - Parsed stdin items as bkper.Group payloads
|
|
9
|
+
* @param propertyOverrides - CLI --property flags that override stdin properties
|
|
12
10
|
*/
|
|
13
|
-
export declare function batchCreateGroups(bookId: string, items: Record<string,
|
|
11
|
+
export declare function batchCreateGroups(bookId: string, items: Record<string, unknown>[], propertyOverrides?: string[]): Promise<void>;
|
|
14
12
|
//# sourceMappingURL=batch-create.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-create.d.ts","sourceRoot":"","sources":["../../../src/commands/groups/batch-create.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"batch-create.d.ts","sourceRoot":"","sources":["../../../src/commands/groups/batch-create.ts"],"names":[],"mappings":"AAMA;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CACnC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAChC,iBAAiB,CAAC,EAAE,MAAM,EAAE,GAC7B,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
|
|
@@ -15,12 +15,11 @@ const CHUNK_SIZE = 100;
|
|
|
15
15
|
* Creates multiple groups from stdin items using the batch API.
|
|
16
16
|
* Outputs NDJSON (one JSON object per line) as each chunk completes.
|
|
17
17
|
*
|
|
18
|
-
* Stdin
|
|
19
|
-
* name, parent, hidden
|
|
18
|
+
* Stdin items must follow the bkper.Group format exactly.
|
|
20
19
|
*
|
|
21
20
|
* @param bookId - Target book ID
|
|
22
|
-
* @param items - Parsed stdin items
|
|
23
|
-
* @param propertyOverrides - CLI --property flags that override stdin
|
|
21
|
+
* @param items - Parsed stdin items as bkper.Group payloads
|
|
22
|
+
* @param propertyOverrides - CLI --property flags that override stdin properties
|
|
24
23
|
*/
|
|
25
24
|
export function batchCreateGroups(bookId, items, propertyOverrides) {
|
|
26
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -30,21 +29,8 @@ export function batchCreateGroups(bookId, items, propertyOverrides) {
|
|
|
30
29
|
const chunk = items.slice(i, i + CHUNK_SIZE);
|
|
31
30
|
const groups = [];
|
|
32
31
|
for (const item of chunk) {
|
|
33
|
-
const group = new Group(book);
|
|
34
|
-
|
|
35
|
-
group.setName(String(item.name));
|
|
36
|
-
if (item.hidden !== undefined) {
|
|
37
|
-
const hidden = typeof item.hidden === 'boolean' ? item.hidden : item.hidden === 'true';
|
|
38
|
-
group.setHidden(hidden);
|
|
39
|
-
}
|
|
40
|
-
// Set properties from stdin fields (excluding known fields)
|
|
41
|
-
const knownFields = new Set(['name', 'parent', 'hidden']);
|
|
42
|
-
for (const [key, value] of Object.entries(item)) {
|
|
43
|
-
if (!knownFields.has(key) && value !== '') {
|
|
44
|
-
group.setProperty(key, String(value));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
// CLI --property flags override stdin
|
|
32
|
+
const group = new Group(book, item);
|
|
33
|
+
// CLI --property flags override stdin properties
|
|
48
34
|
if (propertyOverrides) {
|
|
49
35
|
for (const raw of propertyOverrides) {
|
|
50
36
|
const [key, value] = parsePropertyFlag(raw);
|
|
@@ -56,12 +42,6 @@ export function batchCreateGroups(bookId, items, propertyOverrides) {
|
|
|
56
42
|
}
|
|
57
43
|
}
|
|
58
44
|
}
|
|
59
|
-
if (item.parent) {
|
|
60
|
-
const parentGroup = yield book.getGroup(String(item.parent));
|
|
61
|
-
if (parentGroup) {
|
|
62
|
-
group.setParent(parentGroup);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
45
|
groups.push(group);
|
|
66
46
|
}
|
|
67
47
|
const results = yield book.batchCreateGroups(groups);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-create.js","sourceRoot":"","sources":["../../../src/commands/groups/batch-create.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"batch-create.js","sourceRoot":"","sources":["../../../src/commands/groups/batch-create.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,iBAA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,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC;IACL,CAAC;CAAA"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import type { StdinValue } from '../../input/index.js';
|
|
2
1
|
/**
|
|
3
2
|
* Creates multiple transactions from stdin items using the batch API.
|
|
4
3
|
* Outputs NDJSON (one JSON object per line) as each chunk completes.
|
|
5
4
|
*
|
|
6
|
-
* Stdin
|
|
7
|
-
* date, amount, description, creditAccount, debitAccount, urls, remoteIds
|
|
5
|
+
* Stdin items must follow the bkper.Transaction format exactly.
|
|
8
6
|
*
|
|
9
7
|
* @param bookId - Target book ID
|
|
10
|
-
* @param items - Parsed stdin items
|
|
11
|
-
* @param propertyOverrides - CLI --property flags that override stdin
|
|
8
|
+
* @param items - Parsed stdin items as bkper.Transaction payloads
|
|
9
|
+
* @param propertyOverrides - CLI --property flags that override stdin properties
|
|
12
10
|
*/
|
|
13
|
-
export declare function batchCreateTransactions(bookId: string, items: Record<string,
|
|
11
|
+
export declare function batchCreateTransactions(bookId: string, items: Record<string, unknown>[], propertyOverrides?: string[]): Promise<void>;
|
|
14
12
|
//# sourceMappingURL=batch-create.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-create.d.ts","sourceRoot":"","sources":["../../../src/commands/transactions/batch-create.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"batch-create.d.ts","sourceRoot":"","sources":["../../../src/commands/transactions/batch-create.ts"],"names":[],"mappings":"AAMA;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CACzC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAChC,iBAAiB,CAAC,EAAE,MAAM,EAAE,GAC7B,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
|
|
@@ -11,31 +11,15 @@ import { getBkperInstance } from '../../bkper-factory.js';
|
|
|
11
11
|
import { Transaction } from 'bkper-js';
|
|
12
12
|
import { parsePropertyFlag } from '../../utils/properties.js';
|
|
13
13
|
const CHUNK_SIZE = 100;
|
|
14
|
-
/**
|
|
15
|
-
* Resolves a StdinValue that may be a string[] or comma-separated string into a string array.
|
|
16
|
-
*/
|
|
17
|
-
function resolveArray(value) {
|
|
18
|
-
if (Array.isArray(value)) {
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
if (typeof value === 'string') {
|
|
22
|
-
return value
|
|
23
|
-
.split(',')
|
|
24
|
-
.map(s => s.trim())
|
|
25
|
-
.filter(Boolean);
|
|
26
|
-
}
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
29
14
|
/**
|
|
30
15
|
* Creates multiple transactions from stdin items using the batch API.
|
|
31
16
|
* Outputs NDJSON (one JSON object per line) as each chunk completes.
|
|
32
17
|
*
|
|
33
|
-
* Stdin
|
|
34
|
-
* date, amount, description, creditAccount, debitAccount, urls, remoteIds
|
|
18
|
+
* Stdin items must follow the bkper.Transaction format exactly.
|
|
35
19
|
*
|
|
36
20
|
* @param bookId - Target book ID
|
|
37
|
-
* @param items - Parsed stdin items
|
|
38
|
-
* @param propertyOverrides - CLI --property flags that override stdin
|
|
21
|
+
* @param items - Parsed stdin items as bkper.Transaction payloads
|
|
22
|
+
* @param propertyOverrides - CLI --property flags that override stdin properties
|
|
39
23
|
*/
|
|
40
24
|
export function batchCreateTransactions(bookId, items, propertyOverrides) {
|
|
41
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -45,49 +29,8 @@ export function batchCreateTransactions(bookId, items, propertyOverrides) {
|
|
|
45
29
|
const chunk = items.slice(i, i + CHUNK_SIZE);
|
|
46
30
|
const transactions = [];
|
|
47
31
|
for (const item of chunk) {
|
|
48
|
-
const tx = new Transaction(book);
|
|
49
|
-
|
|
50
|
-
tx.setDate(String(item.date));
|
|
51
|
-
if (item.amount)
|
|
52
|
-
tx.setAmount(String(item.amount));
|
|
53
|
-
if (item.description)
|
|
54
|
-
tx.setDescription(String(item.description));
|
|
55
|
-
if (item.creditAccount) {
|
|
56
|
-
const creditAccount = yield book.getAccount(String(item.creditAccount));
|
|
57
|
-
if (creditAccount)
|
|
58
|
-
tx.setCreditAccount(creditAccount);
|
|
59
|
-
}
|
|
60
|
-
if (item.debitAccount) {
|
|
61
|
-
const debitAccount = yield book.getAccount(String(item.debitAccount));
|
|
62
|
-
if (debitAccount)
|
|
63
|
-
tx.setDebitAccount(debitAccount);
|
|
64
|
-
}
|
|
65
|
-
if (item.urls) {
|
|
66
|
-
for (const u of resolveArray(item.urls)) {
|
|
67
|
-
tx.addUrl(u);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (item.remoteIds) {
|
|
71
|
-
for (const r of resolveArray(item.remoteIds)) {
|
|
72
|
-
tx.addRemoteId(r);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// Set properties from stdin fields (excluding known fields)
|
|
76
|
-
const knownFields = new Set([
|
|
77
|
-
'date',
|
|
78
|
-
'amount',
|
|
79
|
-
'description',
|
|
80
|
-
'creditAccount',
|
|
81
|
-
'debitAccount',
|
|
82
|
-
'urls',
|
|
83
|
-
'remoteIds',
|
|
84
|
-
]);
|
|
85
|
-
for (const [key, value] of Object.entries(item)) {
|
|
86
|
-
if (!knownFields.has(key) && value !== '') {
|
|
87
|
-
tx.setProperty(key, String(value));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// CLI --property flags override stdin
|
|
32
|
+
const tx = new Transaction(book, item);
|
|
33
|
+
// CLI --property flags override stdin properties
|
|
91
34
|
if (propertyOverrides) {
|
|
92
35
|
for (const raw of propertyOverrides) {
|
|
93
36
|
const [key, value] = parsePropertyFlag(raw);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-create.js","sourceRoot":"","sources":["../../../src/commands/transactions/batch-create.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAA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4BACf,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;wBAC3B,CAAC;6BAAM,CAAC;4BACJ,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;wBAC/B,CAAC;oBACL,CAAC;gBACL,CAAC;gBAED,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC1B,CAAC;YAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,YAAY,CAAC,CAAC;YACjE,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC3B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC;IACL,CAAC;CAAA"}
|
package/lib/input/index.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
export { readStdin } from './stdin-reader.js';
|
|
2
|
-
export { InputFormat } from './format-detector.js';
|
|
3
|
-
import { InputFormat } from './format-detector.js';
|
|
4
2
|
/**
|
|
5
|
-
*
|
|
6
|
-
* JSON input preserves native types (arrays, booleans, numbers as strings).
|
|
7
|
-
* CSV input produces string values only.
|
|
3
|
+
* Parsed stdin result containing an array of JSON objects.
|
|
8
4
|
*/
|
|
9
|
-
export type StdinValue = string | string[] | boolean;
|
|
10
5
|
export interface StdinItems {
|
|
11
|
-
items: Record<string,
|
|
12
|
-
format: InputFormat;
|
|
6
|
+
items: Record<string, unknown>[];
|
|
13
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Reads and parses JSON input from stdin.
|
|
10
|
+
*
|
|
11
|
+
* Accepts a single JSON object or a JSON array of objects.
|
|
12
|
+
* Returns null if no piped input is available.
|
|
13
|
+
*
|
|
14
|
+
* @returns Parsed items, or null if stdin is not piped
|
|
15
|
+
* @throws Error if input is not valid JSON or not an object/array
|
|
16
|
+
*/
|
|
14
17
|
export declare function parseStdinItems(): Promise<StdinItems | null>;
|
|
15
18
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/input/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/input/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/input/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAI9C;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;CACpC;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAkBlE"}
|
package/lib/input/index.js
CHANGED
|
@@ -9,32 +9,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
export { readStdin } from './stdin-reader.js';
|
|
11
11
|
import { readStdin } from './stdin-reader.js';
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Reads and parses JSON input from stdin.
|
|
14
|
+
*
|
|
15
|
+
* Accepts a single JSON object or a JSON array of objects.
|
|
16
|
+
* Returns null if no piped input is available.
|
|
17
|
+
*
|
|
18
|
+
* @returns Parsed items, or null if stdin is not piped
|
|
19
|
+
* @throws Error if input is not valid JSON or not an object/array
|
|
20
|
+
*/
|
|
14
21
|
export function parseStdinItems() {
|
|
15
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
23
|
const content = yield readStdin();
|
|
17
24
|
if (content === null) {
|
|
18
25
|
return null;
|
|
19
26
|
}
|
|
20
|
-
const
|
|
27
|
+
const parsed = JSON.parse(content);
|
|
21
28
|
let items;
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
else if (typeof parsed === 'object' && parsed !== null) {
|
|
28
|
-
items = [parsed];
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
throw new Error('JSON input must be an object or an array of objects');
|
|
32
|
-
}
|
|
29
|
+
if (Array.isArray(parsed)) {
|
|
30
|
+
items = parsed;
|
|
31
|
+
}
|
|
32
|
+
else if (typeof parsed === 'object' && parsed !== null) {
|
|
33
|
+
items = [parsed];
|
|
33
34
|
}
|
|
34
35
|
else {
|
|
35
|
-
|
|
36
|
+
throw new Error('JSON input must be an object or an array of objects');
|
|
36
37
|
}
|
|
37
|
-
return { items
|
|
38
|
+
return { items };
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
41
|
//# sourceMappingURL=index.js.map
|
package/lib/input/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/input/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/input/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAS9C;;;;;;;;GAQG;AACH,MAAM,UAAgB,eAAe;;QACjC,MAAM,OAAO,GAAG,MAAM,SAAS,EAAE,CAAC;QAClC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,KAAgC,CAAC;QAErC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACxB,KAAK,GAAG,MAAmC,CAAC;QAChD,CAAC;aAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACvD,KAAK,GAAG,CAAC,MAAiC,CAAC,CAAC;QAChD,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,CAAC;IACrB,CAAC;CAAA"}
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parses CSV content into an array of records using the first row as headers.
|
|
3
|
-
* Handles quoted fields, escaped quotes, and CRLF/LF line endings.
|
|
4
|
-
*
|
|
5
|
-
* @param content - Raw CSV string to parse
|
|
6
|
-
* @returns Array of records keyed by header names
|
|
7
|
-
*/
|
|
8
|
-
export declare function parseCsv(content: string): Record<string, string>[];
|
|
9
|
-
//# sourceMappingURL=csv-parser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"csv-parser.d.ts","sourceRoot":"","sources":["../../src/input/csv-parser.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAuBlE"}
|
package/lib/input/csv-parser.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parses CSV content into an array of records using the first row as headers.
|
|
3
|
-
* Handles quoted fields, escaped quotes, and CRLF/LF line endings.
|
|
4
|
-
*
|
|
5
|
-
* @param content - Raw CSV string to parse
|
|
6
|
-
* @returns Array of records keyed by header names
|
|
7
|
-
*/
|
|
8
|
-
export function parseCsv(content) {
|
|
9
|
-
const rows = parseRows(content);
|
|
10
|
-
if (rows.length === 0) {
|
|
11
|
-
return [];
|
|
12
|
-
}
|
|
13
|
-
const headers = rows[0].map(h => h.trim());
|
|
14
|
-
const results = [];
|
|
15
|
-
for (let i = 1; i < rows.length; i++) {
|
|
16
|
-
const row = rows[i];
|
|
17
|
-
if (row.length === 1 && row[0] === '') {
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
const record = {};
|
|
21
|
-
for (let j = 0; j < headers.length; j++) {
|
|
22
|
-
record[headers[j]] = j < row.length ? row[j] : '';
|
|
23
|
-
}
|
|
24
|
-
results.push(record);
|
|
25
|
-
}
|
|
26
|
-
return results;
|
|
27
|
-
}
|
|
28
|
-
function parseRows(content) {
|
|
29
|
-
const rows = [];
|
|
30
|
-
let current = 0;
|
|
31
|
-
while (current < content.length) {
|
|
32
|
-
const { fields, nextPosition } = parseRow(content, current);
|
|
33
|
-
rows.push(fields);
|
|
34
|
-
current = nextPosition;
|
|
35
|
-
}
|
|
36
|
-
return rows;
|
|
37
|
-
}
|
|
38
|
-
function parseRow(content, start) {
|
|
39
|
-
const fields = [];
|
|
40
|
-
let pos = start;
|
|
41
|
-
while (pos < content.length) {
|
|
42
|
-
if (content[pos] === '"') {
|
|
43
|
-
const { value, nextPosition } = parseQuotedField(content, pos);
|
|
44
|
-
fields.push(value);
|
|
45
|
-
pos = nextPosition;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
const { value, nextPosition } = parseUnquotedField(content, pos);
|
|
49
|
-
fields.push(value);
|
|
50
|
-
pos = nextPosition;
|
|
51
|
-
}
|
|
52
|
-
if (pos >= content.length) {
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
if (content[pos] === ',') {
|
|
56
|
-
pos++;
|
|
57
|
-
if (pos >= content.length ||
|
|
58
|
-
content[pos] === '\n' ||
|
|
59
|
-
(content[pos] === '\r' && content[pos + 1] === '\n')) {
|
|
60
|
-
fields.push('');
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
if (content[pos] === '\r' && pos + 1 < content.length && content[pos + 1] === '\n') {
|
|
66
|
-
pos += 2;
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
if (content[pos] === '\n') {
|
|
70
|
-
pos++;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return { fields, nextPosition: pos };
|
|
75
|
-
}
|
|
76
|
-
function parseQuotedField(content, start) {
|
|
77
|
-
let pos = start + 1;
|
|
78
|
-
const chars = [];
|
|
79
|
-
while (pos < content.length) {
|
|
80
|
-
if (content[pos] === '"') {
|
|
81
|
-
if (pos + 1 < content.length && content[pos + 1] === '"') {
|
|
82
|
-
chars.push('"');
|
|
83
|
-
pos += 2;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
pos++;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
chars.push(content[pos]);
|
|
92
|
-
pos++;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return { value: chars.join(''), nextPosition: pos };
|
|
96
|
-
}
|
|
97
|
-
function parseUnquotedField(content, start) {
|
|
98
|
-
let pos = start;
|
|
99
|
-
while (pos < content.length) {
|
|
100
|
-
const ch = content[pos];
|
|
101
|
-
if (ch === ',' ||
|
|
102
|
-
ch === '\n' ||
|
|
103
|
-
(ch === '\r' && pos + 1 < content.length && content[pos + 1] === '\n')) {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
pos++;
|
|
107
|
-
}
|
|
108
|
-
return { value: content.substring(start, pos), nextPosition: pos };
|
|
109
|
-
}
|
|
110
|
-
//# sourceMappingURL=csv-parser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"csv-parser.js","sourceRoot":"","sources":["../../src/input/csv-parser.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAe;IACpC,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAChC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,EAAE,CAAC;IACd,CAAC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;YACX,CAAC,EAAE,KAAK,IAAI,IAAI,GAAG,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,EACxE,CAAC;YACC,MAAM;QACV,CAAC;QACD,GAAG,EAAE,CAAC;IACV,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC;AACvE,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Supported input formats for piped data.
|
|
3
|
-
*/
|
|
4
|
-
export type InputFormat = 'json' | 'csv';
|
|
5
|
-
/**
|
|
6
|
-
* Detects whether the input content is JSON or CSV based on the first non-whitespace character.
|
|
7
|
-
*
|
|
8
|
-
* @param content - The raw input string to analyze
|
|
9
|
-
* @returns The detected input format
|
|
10
|
-
*/
|
|
11
|
-
export declare function detectInputFormat(content: string): InputFormat;
|
|
12
|
-
//# sourceMappingURL=format-detector.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format-detector.d.ts","sourceRoot":"","sources":["../../src/input/format-detector.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,KAAK,CAAC;AAEzC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAM9D"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Detects whether the input content is JSON or CSV based on the first non-whitespace character.
|
|
3
|
-
*
|
|
4
|
-
* @param content - The raw input string to analyze
|
|
5
|
-
* @returns The detected input format
|
|
6
|
-
*/
|
|
7
|
-
export function detectInputFormat(content) {
|
|
8
|
-
const trimmed = content.trim();
|
|
9
|
-
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
10
|
-
return 'json';
|
|
11
|
-
}
|
|
12
|
-
return 'csv';
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=format-detector.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format-detector.js","sourceRoot":"","sources":["../../src/input/format-detector.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC7C,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/B,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACrD,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
|