@delma/fylo 2.1.0 → 2.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 +27 -0
- package/dist/adapters/cipher.js +155 -0
- package/dist/adapters/cipher.js.map +1 -0
- package/dist/core/collection.js +6 -0
- package/dist/core/collection.js.map +1 -0
- package/{src/core/directory.ts → dist/core/directory.js} +28 -35
- package/dist/core/directory.js.map +1 -0
- package/dist/core/doc-id.js +15 -0
- package/dist/core/doc-id.js.map +1 -0
- package/dist/core/extensions.js +16 -0
- package/dist/core/extensions.js.map +1 -0
- package/dist/core/format.js +355 -0
- package/dist/core/format.js.map +1 -0
- package/dist/core/parser.js +764 -0
- package/dist/core/parser.js.map +1 -0
- package/dist/core/query.js +47 -0
- package/dist/core/query.js.map +1 -0
- package/dist/engines/s3-files/documents.js +62 -0
- package/dist/engines/s3-files/documents.js.map +1 -0
- package/dist/engines/s3-files/filesystem.js +165 -0
- package/dist/engines/s3-files/filesystem.js.map +1 -0
- package/dist/engines/s3-files/query.js +235 -0
- package/dist/engines/s3-files/query.js.map +1 -0
- package/dist/engines/s3-files/types.js +2 -0
- package/dist/engines/s3-files/types.js.map +1 -0
- package/dist/engines/s3-files.js +629 -0
- package/dist/engines/s3-files.js.map +1 -0
- package/dist/engines/types.js +2 -0
- package/dist/engines/types.js.map +1 -0
- package/dist/index.js +562 -0
- package/dist/index.js.map +1 -0
- package/dist/sync.js +18 -0
- package/dist/sync.js.map +1 -0
- package/{src → dist}/types/fylo.d.ts +14 -1
- package/package.json +2 -2
- package/.env.example +0 -16
- package/.github/copilot-instructions.md +0 -3
- package/.github/prompts/release.prompt.md +0 -10
- package/.github/workflows/ci.yml +0 -37
- package/.github/workflows/publish.yml +0 -91
- package/.prettierrc +0 -7
- package/AGENTS.md +0 -3
- package/CLAUDE.md +0 -3
- package/eslint.config.js +0 -32
- package/src/CLI +0 -39
- package/src/adapters/cipher.ts +0 -180
- package/src/core/collection.ts +0 -5
- package/src/core/extensions.ts +0 -21
- package/src/core/format.ts +0 -457
- package/src/core/parser.ts +0 -901
- package/src/core/query.ts +0 -53
- package/src/engines/s3-files/documents.ts +0 -65
- package/src/engines/s3-files/filesystem.ts +0 -172
- package/src/engines/s3-files/query.ts +0 -291
- package/src/engines/s3-files/types.ts +0 -42
- package/src/engines/s3-files.ts +0 -769
- package/src/engines/types.ts +0 -21
- package/src/index.ts +0 -632
- package/src/sync.ts +0 -58
- package/tests/collection/truncate.test.js +0 -36
- package/tests/data.js +0 -97
- package/tests/helpers/root.js +0 -7
- package/tests/integration/aws-s3-files.canary.test.js +0 -22
- package/tests/integration/create.test.js +0 -39
- package/tests/integration/delete.test.js +0 -97
- package/tests/integration/edge-cases.test.js +0 -162
- package/tests/integration/encryption.test.js +0 -148
- package/tests/integration/export.test.js +0 -46
- package/tests/integration/join-modes.test.js +0 -154
- package/tests/integration/nested.test.js +0 -144
- package/tests/integration/operators.test.js +0 -136
- package/tests/integration/read.test.js +0 -123
- package/tests/integration/rollback.test.js +0 -30
- package/tests/integration/s3-files.performance.test.js +0 -75
- package/tests/integration/s3-files.test.js +0 -205
- package/tests/integration/sync.test.js +0 -154
- package/tests/integration/update.test.js +0 -105
- package/tests/mocks/cipher.js +0 -40
- package/tests/schemas/album.d.ts +0 -5
- package/tests/schemas/album.json +0 -5
- package/tests/schemas/comment.d.ts +0 -7
- package/tests/schemas/comment.json +0 -7
- package/tests/schemas/photo.d.ts +0 -7
- package/tests/schemas/photo.json +0 -7
- package/tests/schemas/post.d.ts +0 -6
- package/tests/schemas/post.json +0 -6
- package/tests/schemas/tip.d.ts +0 -7
- package/tests/schemas/tip.json +0 -7
- package/tests/schemas/todo.d.ts +0 -6
- package/tests/schemas/todo.json +0 -6
- package/tests/schemas/user.d.ts +0 -23
- package/tests/schemas/user.json +0 -23
- package/tsconfig.json +0 -21
- package/tsconfig.typecheck.json +0 -31
- /package/{src → dist}/types/bun-runtime.d.ts +0 -0
- /package/{src → dist}/types/index.d.ts +0 -0
- /package/{src → dist}/types/node-runtime.d.ts +0 -0
- /package/{src → dist}/types/query.d.ts +0 -0
- /package/{src → dist}/types/vendor-modules.d.ts +0 -0
package/src/core/format.ts
DELETED
|
@@ -1,457 +0,0 @@
|
|
|
1
|
-
import TTID from '@delma/ttid'
|
|
2
|
-
|
|
3
|
-
class Format {
|
|
4
|
-
static table(docs: Record<string, any>) {
|
|
5
|
-
// Calculate the _id column width (considering both the column name and the actual keys)
|
|
6
|
-
const idColumnWidth = Math.max(...Object.keys(docs).map((key) => key.length)) + 2 // Add padding
|
|
7
|
-
|
|
8
|
-
const { maxWidths, maxHeight } = this.getHeaderDim(Object.values(docs))
|
|
9
|
-
|
|
10
|
-
let key = Object.keys(docs).shift()!
|
|
11
|
-
|
|
12
|
-
const keys = key.split(',')
|
|
13
|
-
|
|
14
|
-
if (TTID.isTTID(key) || keys.some((key) => TTID.isTTID(key ?? ''))) {
|
|
15
|
-
key = '_id'
|
|
16
|
-
} else key = '_key'
|
|
17
|
-
|
|
18
|
-
// Add the _id column to the front of maxWidths
|
|
19
|
-
const fullWidths = {
|
|
20
|
-
[key]: idColumnWidth,
|
|
21
|
-
...maxWidths
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Render the header
|
|
25
|
-
const header = this.renderHeader(fullWidths, maxHeight, key)
|
|
26
|
-
console.log('\n' + header)
|
|
27
|
-
|
|
28
|
-
// Render the data rows
|
|
29
|
-
const dataRows = this.renderDataRows(docs, fullWidths, key)
|
|
30
|
-
console.log(dataRows)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private static getHeaderDim(docs: Record<string, any>[]) {
|
|
34
|
-
let maxWidths: Record<string, any> = {}
|
|
35
|
-
let maxHeight = 1
|
|
36
|
-
|
|
37
|
-
// Create a copy to avoid mutating the original array
|
|
38
|
-
const docsCopy = [...docs]
|
|
39
|
-
|
|
40
|
-
while (docsCopy.length > 0) {
|
|
41
|
-
const doc = docsCopy.shift()!
|
|
42
|
-
const widths = this.getValueWidth(doc)
|
|
43
|
-
const height = this.getHeaderHeight(doc) // Fix: get height for this doc
|
|
44
|
-
maxHeight = Math.max(maxHeight, height) // Fix: take maximum height
|
|
45
|
-
maxWidths = this.increaseWidths(maxWidths, widths)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return { maxWidths, maxHeight }
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private static getValueWidth(doc: Record<string, any>) {
|
|
52
|
-
const keyWidths: Record<string, any> = {}
|
|
53
|
-
|
|
54
|
-
for (const key in doc) {
|
|
55
|
-
if (typeof doc[key] === 'object' && doc[key] !== null && !Array.isArray(doc[key])) {
|
|
56
|
-
keyWidths[key] = this.getValueWidth(doc[key])
|
|
57
|
-
} else {
|
|
58
|
-
// Consider both the key name length and the value length
|
|
59
|
-
const valueWidth = JSON.stringify(doc[key]).length
|
|
60
|
-
const keyWidth = key.length
|
|
61
|
-
// Add padding: 1 space before + content + 1 space after
|
|
62
|
-
keyWidths[key] = Math.max(valueWidth, keyWidth) + 2
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return keyWidths
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private static increaseWidths(oldWidths: Record<string, any>, newWidths: Record<string, any>) {
|
|
70
|
-
const increasedWidths: Record<string, any> = { ...oldWidths }
|
|
71
|
-
|
|
72
|
-
for (const key in newWidths) {
|
|
73
|
-
if (
|
|
74
|
-
oldWidths[key] &&
|
|
75
|
-
typeof newWidths[key] === 'object' &&
|
|
76
|
-
typeof oldWidths[key] === 'object'
|
|
77
|
-
) {
|
|
78
|
-
increasedWidths[key] = this.increaseWidths(oldWidths[key], newWidths[key])
|
|
79
|
-
} else if (
|
|
80
|
-
oldWidths[key] &&
|
|
81
|
-
typeof newWidths[key] === 'number' &&
|
|
82
|
-
typeof oldWidths[key] === 'number'
|
|
83
|
-
) {
|
|
84
|
-
increasedWidths[key] = Math.max(newWidths[key], oldWidths[key])
|
|
85
|
-
} else {
|
|
86
|
-
increasedWidths[key] = newWidths[key]
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Handle keys that exist in newWidths but not in oldWidths
|
|
91
|
-
for (const key in newWidths) {
|
|
92
|
-
if (!(key in increasedWidths)) {
|
|
93
|
-
increasedWidths[key] = newWidths[key]
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Also ensure column family names fit within their total width
|
|
98
|
-
for (const key in increasedWidths) {
|
|
99
|
-
if (typeof increasedWidths[key] === 'object' && increasedWidths[key] !== null) {
|
|
100
|
-
const totalChildWidth = this.calculateTotalWidth(increasedWidths[key])
|
|
101
|
-
const keyWidth = key.length
|
|
102
|
-
|
|
103
|
-
// If the column family name (with padding) is longer than the total child width,
|
|
104
|
-
// we need to adjust the child column widths proportionally
|
|
105
|
-
const keyWidthWithPadding = keyWidth + 2 // Add padding for family name too
|
|
106
|
-
if (keyWidthWithPadding > totalChildWidth) {
|
|
107
|
-
const childKeys = Object.keys(increasedWidths[key])
|
|
108
|
-
const extraWidth = keyWidthWithPadding - totalChildWidth
|
|
109
|
-
const widthPerChild = Math.ceil(extraWidth / childKeys.length)
|
|
110
|
-
|
|
111
|
-
for (const childKey of childKeys) {
|
|
112
|
-
if (typeof increasedWidths[key][childKey] === 'number') {
|
|
113
|
-
increasedWidths[key][childKey] += widthPerChild
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return increasedWidths
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
private static getHeaderHeight(doc: Record<string, any>): number {
|
|
124
|
-
let maxDepth = 1 // Fix: start with 1 for current level
|
|
125
|
-
|
|
126
|
-
for (const key in doc) {
|
|
127
|
-
if (typeof doc[key] === 'object' && doc[key] !== null && !Array.isArray(doc[key])) {
|
|
128
|
-
const nestedDepth = 1 + this.getHeaderHeight(doc[key]) // Fix: add 1 for current level
|
|
129
|
-
maxDepth = Math.max(maxDepth, nestedDepth) // Fix: track maximum depth
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return maxDepth
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
private static renderHeader(
|
|
137
|
-
widths: Record<string, any>,
|
|
138
|
-
height: number,
|
|
139
|
-
idColumnKey: string
|
|
140
|
-
): string {
|
|
141
|
-
const lines: string[] = []
|
|
142
|
-
|
|
143
|
-
// Flatten the structure to get all columns
|
|
144
|
-
const columns = this.flattenColumns(widths)
|
|
145
|
-
|
|
146
|
-
// Add top border
|
|
147
|
-
lines.push(this.renderTopBorder(columns))
|
|
148
|
-
|
|
149
|
-
// Add header content rows
|
|
150
|
-
for (let level = 0; level < height; level++) {
|
|
151
|
-
lines.push(this.renderHeaderRow(widths, level, height, idColumnKey))
|
|
152
|
-
|
|
153
|
-
// Add middle border between levels (except after last level)
|
|
154
|
-
if (level < height - 1) {
|
|
155
|
-
lines.push(this.renderMiddleBorder(columns))
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Add bottom border
|
|
160
|
-
lines.push(this.renderBottomBorder(columns))
|
|
161
|
-
|
|
162
|
-
return lines.join('\n')
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
private static renderDataRows<T extends Record<string, any>>(
|
|
166
|
-
docs: Record<string, T>,
|
|
167
|
-
widths: Record<string, any>,
|
|
168
|
-
idColumnKey: string
|
|
169
|
-
): string {
|
|
170
|
-
const lines: string[] = []
|
|
171
|
-
const columns = this.flattenColumns(widths)
|
|
172
|
-
const entries = Object.entries(docs)
|
|
173
|
-
|
|
174
|
-
for (let i = 0; i < entries.length; i++) {
|
|
175
|
-
const [docId, doc] = entries[i]
|
|
176
|
-
// Render data row
|
|
177
|
-
lines.push(this.renderDataRow(docId, doc, widths, columns, idColumnKey))
|
|
178
|
-
|
|
179
|
-
// Add separator between rows (except for last row)
|
|
180
|
-
if (i < entries.length - 1) {
|
|
181
|
-
lines.push(this.renderRowSeparator(columns))
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Add final bottom border
|
|
186
|
-
lines.push(this.renderBottomBorder(columns))
|
|
187
|
-
|
|
188
|
-
return lines.join('\n')
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private static renderDataRow(
|
|
192
|
-
docId: string,
|
|
193
|
-
doc: Record<string, any>,
|
|
194
|
-
widths: Record<string, any>,
|
|
195
|
-
columns: Array<{ name: string; width: number; path: string[] }>,
|
|
196
|
-
idColumnKey: string
|
|
197
|
-
): string {
|
|
198
|
-
let line = '│'
|
|
199
|
-
|
|
200
|
-
// Handle the ID column (could be _id or another key)
|
|
201
|
-
if (idColumnKey in widths && typeof widths[idColumnKey] === 'number') {
|
|
202
|
-
const contentWidth = widths[idColumnKey] - 2
|
|
203
|
-
const content = docId
|
|
204
|
-
const padding = Math.max(0, contentWidth - content.length)
|
|
205
|
-
const leftPad = Math.floor(padding / 2)
|
|
206
|
-
const rightPad = padding - leftPad
|
|
207
|
-
|
|
208
|
-
line += ' ' + ' '.repeat(leftPad) + content + ' '.repeat(rightPad) + ' │'
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// Handle data columns
|
|
212
|
-
for (const column of columns) {
|
|
213
|
-
// Skip the ID column as it's handled separately
|
|
214
|
-
if (column.name === idColumnKey) continue
|
|
215
|
-
|
|
216
|
-
const value = this.getNestedValue(doc, column.path)
|
|
217
|
-
const stringValue = this.formatValue(value)
|
|
218
|
-
const contentWidth = column.width - 2 // Subtract padding
|
|
219
|
-
|
|
220
|
-
// Truncate if value is too long
|
|
221
|
-
const truncatedValue =
|
|
222
|
-
stringValue.length > contentWidth
|
|
223
|
-
? stringValue.substring(0, contentWidth - 3) + '...'
|
|
224
|
-
: stringValue
|
|
225
|
-
|
|
226
|
-
const padding = Math.max(0, contentWidth - truncatedValue.length)
|
|
227
|
-
const leftPad = Math.floor(padding / 2)
|
|
228
|
-
const rightPad = padding - leftPad
|
|
229
|
-
|
|
230
|
-
line += ' ' + ' '.repeat(leftPad) + truncatedValue + ' '.repeat(rightPad) + ' │'
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return line
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
private static getNestedValue(obj: Record<string, any>, path: string[]): any {
|
|
237
|
-
let current = obj
|
|
238
|
-
|
|
239
|
-
for (const key of path) {
|
|
240
|
-
if (current === null || current === undefined || typeof current !== 'object') {
|
|
241
|
-
return undefined
|
|
242
|
-
}
|
|
243
|
-
current = current[key]
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return current
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
private static formatValue(value: any): string {
|
|
250
|
-
if (value === null) return 'null'
|
|
251
|
-
if (value === undefined) return ''
|
|
252
|
-
if (Array.isArray(value)) return JSON.stringify(value)
|
|
253
|
-
if (typeof value === 'object') return JSON.stringify(value)
|
|
254
|
-
if (typeof value === 'string') return value
|
|
255
|
-
return String(value)
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
private static renderRowSeparator(
|
|
259
|
-
columns: Array<{ name: string; width: number; path: string[] }>
|
|
260
|
-
): string {
|
|
261
|
-
let line = '├'
|
|
262
|
-
|
|
263
|
-
for (let i = 0; i < columns.length; i++) {
|
|
264
|
-
line += '─'.repeat(columns[i].width)
|
|
265
|
-
if (i < columns.length - 1) {
|
|
266
|
-
line += '┼'
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
line += '┤'
|
|
271
|
-
return line
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
private static flattenColumns(
|
|
275
|
-
widths: Record<string, any>,
|
|
276
|
-
path: string[] = []
|
|
277
|
-
): Array<{ name: string; width: number; path: string[] }> {
|
|
278
|
-
const columns: Array<{ name: string; width: number; path: string[] }> = []
|
|
279
|
-
|
|
280
|
-
for (const key in widths) {
|
|
281
|
-
const currentPath = [...path, key]
|
|
282
|
-
|
|
283
|
-
if (typeof widths[key] === 'object' && widths[key] !== null) {
|
|
284
|
-
// Recursively flatten nested objects
|
|
285
|
-
columns.push(...this.flattenColumns(widths[key], currentPath))
|
|
286
|
-
} else {
|
|
287
|
-
// This is a leaf column
|
|
288
|
-
columns.push({
|
|
289
|
-
name: key,
|
|
290
|
-
width: widths[key],
|
|
291
|
-
path: currentPath
|
|
292
|
-
})
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return columns
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
private static renderHeaderRow(
|
|
300
|
-
widths: Record<string, any>,
|
|
301
|
-
currentLevel: number,
|
|
302
|
-
totalHeight: number,
|
|
303
|
-
idColumnKey: string
|
|
304
|
-
): string {
|
|
305
|
-
let line = '│'
|
|
306
|
-
|
|
307
|
-
// Handle the ID column specially (could be _id or another key)
|
|
308
|
-
if (idColumnKey in widths && typeof widths[idColumnKey] === 'number') {
|
|
309
|
-
if (currentLevel === 0) {
|
|
310
|
-
// Show the ID column header at the top level
|
|
311
|
-
const contentWidth = widths[idColumnKey] - 2
|
|
312
|
-
const headerText = idColumnKey === '_id' ? '_id' : idColumnKey
|
|
313
|
-
const padding = Math.max(0, contentWidth - headerText.length)
|
|
314
|
-
const leftPad = Math.floor(padding / 2)
|
|
315
|
-
const rightPad = padding - leftPad
|
|
316
|
-
|
|
317
|
-
line += ' ' + ' '.repeat(leftPad) + headerText + ' '.repeat(rightPad) + ' │'
|
|
318
|
-
} else {
|
|
319
|
-
// Empty cell for other levels
|
|
320
|
-
line += ' '.repeat(widths[idColumnKey]) + '│'
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
const processLevel = (
|
|
325
|
-
obj: Record<string, any>,
|
|
326
|
-
level: number,
|
|
327
|
-
targetLevel: number
|
|
328
|
-
): string => {
|
|
329
|
-
let result = ''
|
|
330
|
-
|
|
331
|
-
for (const key in obj) {
|
|
332
|
-
// Skip the ID column as it's handled separately
|
|
333
|
-
if (key === idColumnKey) continue
|
|
334
|
-
|
|
335
|
-
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
336
|
-
if (level === targetLevel) {
|
|
337
|
-
// This is a column family at the target level
|
|
338
|
-
const totalWidth = this.calculateTotalWidth(obj[key])
|
|
339
|
-
const contentWidth = totalWidth - 2 // Subtract padding
|
|
340
|
-
const padding = Math.max(0, contentWidth - key.length)
|
|
341
|
-
const leftPad = Math.floor(padding / 2)
|
|
342
|
-
const rightPad = padding - leftPad
|
|
343
|
-
|
|
344
|
-
// Add 1 space padding + centered content + 1 space padding
|
|
345
|
-
result += ' ' + ' '.repeat(leftPad) + key + ' '.repeat(rightPad) + ' │'
|
|
346
|
-
} else if (level < targetLevel) {
|
|
347
|
-
// Recurse deeper
|
|
348
|
-
result += processLevel(obj[key], level + 1, targetLevel)
|
|
349
|
-
}
|
|
350
|
-
} else {
|
|
351
|
-
if (level === targetLevel) {
|
|
352
|
-
// This is a leaf column at the target level
|
|
353
|
-
const contentWidth = obj[key] - 2 // Subtract padding
|
|
354
|
-
const padding = Math.max(0, contentWidth - key.length)
|
|
355
|
-
const leftPad = Math.floor(padding / 2)
|
|
356
|
-
const rightPad = padding - leftPad
|
|
357
|
-
|
|
358
|
-
// Add 1 space padding + centered content + 1 space padding
|
|
359
|
-
result += ' ' + ' '.repeat(leftPad) + key + ' '.repeat(rightPad) + ' │'
|
|
360
|
-
} else if (level < targetLevel) {
|
|
361
|
-
// Empty cell - span the full width
|
|
362
|
-
result += ' '.repeat(obj[key]) + '│'
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
return result
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
line += processLevel(widths, 0, currentLevel)
|
|
371
|
-
return line
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
private static calculateTotalWidth(obj: Record<string, any>): number {
|
|
375
|
-
let total = 0
|
|
376
|
-
let columnCount = 0
|
|
377
|
-
|
|
378
|
-
for (const key in obj) {
|
|
379
|
-
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
380
|
-
total += this.calculateTotalWidth(obj[key])
|
|
381
|
-
columnCount += this.countLeafColumns(obj[key])
|
|
382
|
-
} else {
|
|
383
|
-
total += obj[key]
|
|
384
|
-
columnCount++
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
// Add space for separators between columns (one less than column count)
|
|
389
|
-
return total + Math.max(0, columnCount - 1)
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
private static countLeafColumns(obj: Record<string, any>): number {
|
|
393
|
-
let count = 0
|
|
394
|
-
|
|
395
|
-
for (const key in obj) {
|
|
396
|
-
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
397
|
-
count += this.countLeafColumns(obj[key])
|
|
398
|
-
} else {
|
|
399
|
-
count++
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
return count
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
private static renderTopBorder(
|
|
407
|
-
columns: Array<{ name: string; width: number; path: string[] }>
|
|
408
|
-
): string {
|
|
409
|
-
let line = '┌'
|
|
410
|
-
|
|
411
|
-
for (let i = 0; i < columns.length; i++) {
|
|
412
|
-
line += '─'.repeat(columns[i].width)
|
|
413
|
-
if (i < columns.length - 1) {
|
|
414
|
-
line += '┬'
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
line += '┐'
|
|
419
|
-
return line
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
private static renderMiddleBorder(
|
|
423
|
-
columns: Array<{ name: string; width: number; path: string[] }>
|
|
424
|
-
): string {
|
|
425
|
-
let line = '├'
|
|
426
|
-
|
|
427
|
-
for (let i = 0; i < columns.length; i++) {
|
|
428
|
-
line += '─'.repeat(columns[i].width)
|
|
429
|
-
if (i < columns.length - 1) {
|
|
430
|
-
line += '┼'
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
line += '┤'
|
|
435
|
-
return line
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
private static renderBottomBorder(
|
|
439
|
-
columns: Array<{ name: string; width: number; path: string[] }>
|
|
440
|
-
): string {
|
|
441
|
-
let line = '└'
|
|
442
|
-
|
|
443
|
-
for (let i = 0; i < columns.length; i++) {
|
|
444
|
-
line += '─'.repeat(columns[i].width)
|
|
445
|
-
if (i < columns.length - 1) {
|
|
446
|
-
line += '┴'
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
line += '┘'
|
|
451
|
-
return line
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
console.format = function (docs: Record<string, any>) {
|
|
456
|
-
Format.table(docs)
|
|
457
|
-
}
|