@delma/fylo 2.0.1 → 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.
Files changed (107) hide show
  1. package/README.md +206 -261
  2. package/dist/adapters/cipher.js +155 -0
  3. package/dist/adapters/cipher.js.map +1 -0
  4. package/dist/core/collection.js +6 -0
  5. package/dist/core/collection.js.map +1 -0
  6. package/dist/core/directory.js +48 -0
  7. package/dist/core/directory.js.map +1 -0
  8. package/dist/core/doc-id.js +15 -0
  9. package/dist/core/doc-id.js.map +1 -0
  10. package/dist/core/extensions.js +16 -0
  11. package/dist/core/extensions.js.map +1 -0
  12. package/dist/core/format.js +355 -0
  13. package/dist/core/format.js.map +1 -0
  14. package/dist/core/parser.js +764 -0
  15. package/dist/core/parser.js.map +1 -0
  16. package/dist/core/query.js +47 -0
  17. package/dist/core/query.js.map +1 -0
  18. package/dist/engines/s3-files/documents.js +62 -0
  19. package/dist/engines/s3-files/documents.js.map +1 -0
  20. package/dist/engines/s3-files/filesystem.js +165 -0
  21. package/dist/engines/s3-files/filesystem.js.map +1 -0
  22. package/dist/engines/s3-files/query.js +235 -0
  23. package/dist/engines/s3-files/query.js.map +1 -0
  24. package/dist/engines/s3-files/types.js +2 -0
  25. package/dist/engines/s3-files/types.js.map +1 -0
  26. package/dist/engines/s3-files.js +629 -0
  27. package/dist/engines/s3-files.js.map +1 -0
  28. package/dist/engines/types.js +2 -0
  29. package/dist/engines/types.js.map +1 -0
  30. package/dist/index.js +562 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/sync.js +18 -0
  33. package/dist/sync.js.map +1 -0
  34. package/dist/types/fylo.d.ts +179 -0
  35. package/{src → dist}/types/node-runtime.d.ts +1 -0
  36. package/package.json +3 -6
  37. package/.env.example +0 -16
  38. package/.github/copilot-instructions.md +0 -3
  39. package/.github/prompts/release.prompt.md +0 -10
  40. package/.github/workflows/ci.yml +0 -37
  41. package/.github/workflows/publish.yml +0 -91
  42. package/.prettierrc +0 -7
  43. package/AGENTS.md +0 -3
  44. package/CLAUDE.md +0 -3
  45. package/eslint.config.js +0 -32
  46. package/src/CLI +0 -39
  47. package/src/adapters/cipher.ts +0 -180
  48. package/src/adapters/redis.ts +0 -487
  49. package/src/adapters/s3.ts +0 -61
  50. package/src/core/collection.ts +0 -5
  51. package/src/core/directory.ts +0 -387
  52. package/src/core/extensions.ts +0 -21
  53. package/src/core/format.ts +0 -457
  54. package/src/core/parser.ts +0 -901
  55. package/src/core/query.ts +0 -53
  56. package/src/core/walker.ts +0 -174
  57. package/src/core/write-queue.ts +0 -59
  58. package/src/engines/s3-files.ts +0 -1068
  59. package/src/engines/types.ts +0 -21
  60. package/src/index.ts +0 -1727
  61. package/src/migrate-cli.ts +0 -22
  62. package/src/migrate.ts +0 -74
  63. package/src/types/fylo.d.ts +0 -261
  64. package/src/types/write-queue.ts +0 -42
  65. package/src/worker.ts +0 -18
  66. package/src/workers/write-worker.ts +0 -120
  67. package/tests/collection/truncate.test.js +0 -35
  68. package/tests/data.js +0 -97
  69. package/tests/index.js +0 -14
  70. package/tests/integration/aws-s3-files.canary.test.js +0 -22
  71. package/tests/integration/create.test.js +0 -39
  72. package/tests/integration/delete.test.js +0 -95
  73. package/tests/integration/edge-cases.test.js +0 -158
  74. package/tests/integration/encryption.test.js +0 -131
  75. package/tests/integration/export.test.js +0 -46
  76. package/tests/integration/join-modes.test.js +0 -154
  77. package/tests/integration/migration.test.js +0 -38
  78. package/tests/integration/nested.test.js +0 -142
  79. package/tests/integration/operators.test.js +0 -122
  80. package/tests/integration/queue.test.js +0 -83
  81. package/tests/integration/read.test.js +0 -119
  82. package/tests/integration/rollback.test.js +0 -60
  83. package/tests/integration/s3-files.test.js +0 -192
  84. package/tests/integration/update.test.js +0 -99
  85. package/tests/mocks/cipher.js +0 -40
  86. package/tests/mocks/redis.js +0 -123
  87. package/tests/mocks/s3.js +0 -80
  88. package/tests/schemas/album.d.ts +0 -5
  89. package/tests/schemas/album.json +0 -5
  90. package/tests/schemas/comment.d.ts +0 -7
  91. package/tests/schemas/comment.json +0 -7
  92. package/tests/schemas/photo.d.ts +0 -7
  93. package/tests/schemas/photo.json +0 -7
  94. package/tests/schemas/post.d.ts +0 -6
  95. package/tests/schemas/post.json +0 -6
  96. package/tests/schemas/tip.d.ts +0 -7
  97. package/tests/schemas/tip.json +0 -7
  98. package/tests/schemas/todo.d.ts +0 -6
  99. package/tests/schemas/todo.json +0 -6
  100. package/tests/schemas/user.d.ts +0 -23
  101. package/tests/schemas/user.json +0 -23
  102. package/tsconfig.json +0 -21
  103. package/tsconfig.typecheck.json +0 -31
  104. /package/{src → dist}/types/bun-runtime.d.ts +0 -0
  105. /package/{src → dist}/types/index.d.ts +0 -0
  106. /package/{src → dist}/types/query.d.ts +0 -0
  107. /package/{src → dist}/types/vendor-modules.d.ts +0 -0
@@ -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
- }