@ibgib/core-gib 0.1.53 → 0.1.55

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 (189) hide show
  1. package/CHANGELOG.md +16 -2
  2. package/README.md +12 -15
  3. package/dist/keystone/aggregate-details.respec.d.mts +2 -0
  4. package/dist/keystone/aggregate-details.respec.d.mts.map +1 -0
  5. package/dist/keystone/aggregate-details.respec.mjs +118 -0
  6. package/dist/keystone/aggregate-details.respec.mjs.map +1 -0
  7. package/dist/keystone/keystone-constants.d.mts +5 -0
  8. package/dist/keystone/keystone-constants.d.mts.map +1 -1
  9. package/dist/keystone/keystone-constants.mjs +6 -1
  10. package/dist/keystone/keystone-constants.mjs.map +1 -1
  11. package/dist/keystone/keystone-helpers.d.mts +7 -1
  12. package/dist/keystone/keystone-helpers.d.mts.map +1 -1
  13. package/dist/keystone/keystone-helpers.mjs +5 -2
  14. package/dist/keystone/keystone-helpers.mjs.map +1 -1
  15. package/dist/keystone/keystone-service-v1.d.mts +51 -0
  16. package/dist/keystone/keystone-service-v1.d.mts.map +1 -1
  17. package/dist/keystone/keystone-service-v1.mjs +176 -9
  18. package/dist/keystone/keystone-service-v1.mjs.map +1 -1
  19. package/dist/keystone/keystone-service-v1.respec.mjs +40 -98
  20. package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -1
  21. package/dist/keystone/keystone-types.d.mts +5 -0
  22. package/dist/keystone/keystone-types.d.mts.map +1 -1
  23. package/dist/sync/graft-info/graft-info-helpers.respec.mjs +8 -8
  24. package/dist/sync/graft-info/graft-info-helpers.respec.mjs.map +1 -1
  25. package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs +26 -30
  26. package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs.map +1 -1
  27. package/dist/sync/sync-conflict-basic-divergence.respec.mjs +7 -8
  28. package/dist/sync/sync-conflict-basic-divergence.respec.mjs.map +1 -1
  29. package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs +10 -11
  30. package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs.map +1 -1
  31. package/dist/sync/sync-conflict-text-merge.respec.mjs +30 -33
  32. package/dist/sync/sync-conflict-text-merge.respec.mjs.map +1 -1
  33. package/dist/sync/sync-constants.d.mts +1 -56
  34. package/dist/sync/sync-constants.d.mts.map +1 -1
  35. package/dist/sync/sync-constants.mjs +2 -59
  36. package/dist/sync/sync-constants.mjs.map +1 -1
  37. package/dist/sync/sync-helpers.d.mts +0 -1
  38. package/dist/sync/sync-helpers.d.mts.map +1 -1
  39. package/dist/sync/sync-helpers.mjs +1 -6
  40. package/dist/sync/sync-helpers.mjs.map +1 -1
  41. package/dist/sync/sync-innerspace-constants.respec.mjs +5 -9
  42. package/dist/sync/sync-innerspace-constants.respec.mjs.map +1 -1
  43. package/dist/sync/sync-innerspace-deep-updates.respec.mjs +6 -7
  44. package/dist/sync/sync-innerspace-deep-updates.respec.mjs.map +1 -1
  45. package/dist/sync/sync-innerspace-dest-ahead-withid.respec.mjs +22 -22
  46. package/dist/sync/sync-innerspace-dest-ahead-withid.respec.mjs.map +1 -1
  47. package/dist/sync/sync-innerspace-dest-ahead.respec.mjs +8 -9
  48. package/dist/sync/sync-innerspace-dest-ahead.respec.mjs.map +1 -1
  49. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs +6 -7
  50. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs.map +1 -1
  51. package/dist/sync/sync-innerspace-partial-update.respec.mjs +7 -8
  52. package/dist/sync/sync-innerspace-partial-update.respec.mjs.map +1 -1
  53. package/dist/sync/sync-innerspace.respec.mjs +8 -11
  54. package/dist/sync/sync-innerspace.respec.mjs.map +1 -1
  55. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mjs +10 -5
  56. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mjs.map +1 -1
  57. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.d.mts +3 -1
  58. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.d.mts.map +1 -1
  59. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.d.mts +4 -2
  60. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.d.mts.map +1 -1
  61. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mjs +37 -6
  62. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mjs.map +1 -1
  63. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.d.mts +3 -1
  64. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.d.mts.map +1 -1
  65. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.d.mts +4 -2
  66. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.d.mts.map +1 -1
  67. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.mjs +37 -0
  68. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.mjs.map +1 -1
  69. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.d.mts +7 -1
  70. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.d.mts.map +1 -1
  71. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts +10 -2
  72. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts.map +1 -1
  73. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs +50 -38
  74. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -1
  75. package/dist/sync/sync-peer/sync-peer-types.d.mts +21 -5
  76. package/dist/sync/sync-peer/sync-peer-types.d.mts.map +1 -1
  77. package/dist/sync/sync-peer/sync-peer-v1.d.mts +30 -5
  78. package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
  79. package/dist/sync/sync-peer/sync-peer-v1.mjs +41 -25
  80. package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
  81. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts +2 -11
  82. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts.map +1 -1
  83. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs +7 -51
  84. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs.map +1 -1
  85. package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts +1 -47
  86. package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts.map +1 -1
  87. package/dist/sync/sync-saga-coordinator.d.mts +6 -58
  88. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
  89. package/dist/sync/sync-saga-coordinator.mjs +23 -425
  90. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  91. package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts +2 -2
  92. package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts.map +1 -1
  93. package/dist/sync/sync-types.d.mts +2 -19
  94. package/dist/sync/sync-types.d.mts.map +1 -1
  95. package/dist/sync/sync-types.mjs.map +1 -1
  96. package/dist/test/mock-space.mjs +1 -1
  97. package/dist/test/mock-space.mjs.map +1 -1
  98. package/dist/test-helpers.d.mts +0 -6
  99. package/dist/test-helpers.d.mts.map +1 -1
  100. package/dist/test-helpers.mjs +2 -25
  101. package/dist/test-helpers.mjs.map +1 -1
  102. package/package.json +10 -34
  103. package/src/keystone/aggregate-details.respec.mts +137 -0
  104. package/src/keystone/docs/architecture.md +16 -0
  105. package/src/keystone/keystone-constants.mts +6 -1
  106. package/src/keystone/keystone-helpers.mts +9 -1
  107. package/src/keystone/keystone-service-v1.mts +216 -8
  108. package/src/keystone/keystone-service-v1.respec.mts +39 -103
  109. package/src/keystone/keystone-types.mts +6 -0
  110. package/src/sync/README.md +18 -0
  111. package/src/sync/docs/architecture.md +21 -0
  112. package/src/sync/graft-info/graft-info-helpers.respec.mts +7 -7
  113. package/src/sync/sync-conflict-adv-multitimelines.respec.mts +25 -29
  114. package/src/sync/sync-conflict-basic-divergence.respec.mts +6 -7
  115. package/src/sync/sync-conflict-basic-multitimelines.respec.mts +9 -10
  116. package/src/sync/sync-conflict-text-merge.respec.mts +29 -32
  117. package/src/sync/sync-constants.mts +2 -62
  118. package/src/sync/sync-helpers.mts +1 -8
  119. package/src/sync/sync-id-testlog.txt +421 -0
  120. package/src/sync/sync-innerspace-constants.respec.mts +4 -8
  121. package/src/sync/sync-innerspace-deep-updates.respec.mts +5 -6
  122. package/src/sync/sync-innerspace-dest-ahead-withid.respec.mts +23 -25
  123. package/src/sync/sync-innerspace-dest-ahead.respec.mts +7 -8
  124. package/src/sync/sync-innerspace-multiple-timelines.respec.mts +5 -6
  125. package/src/sync/sync-innerspace-partial-update.respec.mts +6 -7
  126. package/src/sync/sync-innerspace.respec.mts +7 -10
  127. package/src/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mts +5 -5
  128. package/src/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.mts +5 -1
  129. package/src/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mts +30 -9
  130. package/src/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.mts +3 -1
  131. package/src/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.mts +29 -2
  132. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.mts +7 -1
  133. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +51 -38
  134. package/src/sync/sync-peer/sync-peer-types.mts +23 -6
  135. package/src/sync/sync-peer/sync-peer-v1.mts +68 -28
  136. package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +6 -66
  137. package/src/sync/sync-saga-context/sync-saga-context-types.mts +1 -48
  138. package/src/sync/sync-saga-coordinator.mts +12 -552
  139. package/src/sync/sync-saga-message/sync-saga-message-types.mts +2 -3
  140. package/src/sync/sync-types.mts +2 -22
  141. package/src/sync/unused-identity-backup.mts.md +311 -0
  142. package/src/test/mock-space.mts +1 -1
  143. package/src/test-helpers.mts +1 -26
  144. package/test_output.log +0 -0
  145. package/test_output_utf8.txt +398 -0
  146. package/.vscode/core-gib-snippets.code-snippets +0 -293
  147. package/.vscode/launch.json +0 -40
  148. package/.vscode/settings.json +0 -58
  149. package/.vscode/tasks.json +0 -37
  150. package/dist/sync/sync-peer/sync-peer-http.respec.d.mts +0 -2
  151. package/dist/sync/sync-peer/sync-peer-http.respec.d.mts.map +0 -1
  152. package/dist/sync/sync-peer/sync-peer-http.respec.mjs +0 -340
  153. package/dist/sync/sync-peer/sync-peer-http.respec.mjs.map +0 -1
  154. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.d.mts +0 -42
  155. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.d.mts.map +0 -1
  156. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.mjs +0 -312
  157. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.mjs.map +0 -1
  158. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.d.mts +0 -84
  159. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.d.mts.map +0 -1
  160. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.mjs +0 -65
  161. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.mjs.map +0 -1
  162. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.d.mts +0 -73
  163. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.d.mts.map +0 -1
  164. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mjs +0 -667
  165. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mjs.map +0 -1
  166. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.d.mts +0 -2
  167. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.d.mts.map +0 -1
  168. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.mjs +0 -67
  169. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.mjs.map +0 -1
  170. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.d.mts +0 -2
  171. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.d.mts.map +0 -1
  172. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.mjs +0 -67
  173. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.mjs.map +0 -1
  174. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.d.mts +0 -2
  175. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.d.mts.map +0 -1
  176. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.mjs +0 -68
  177. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.mjs.map +0 -1
  178. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.d.mts +0 -2
  179. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.d.mts.map +0 -1
  180. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.mjs +0 -69
  181. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.mjs.map +0 -1
  182. package/src/sync/sync-peer/sync-peer-http.respec.mts +0 -396
  183. package/src/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.mts +0 -298
  184. package/src/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.mts +0 -150
  185. package/src/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mts +0 -666
  186. package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.mts +0 -87
  187. package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.mts +0 -88
  188. package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.mts +0 -88
  189. package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.mts +0 -90
@@ -1,298 +0,0 @@
1
- /**
2
- * @module node-filesystem-space-helper
3
- *
4
- */
5
-
6
-
7
- import { readFile, } from 'node:fs/promises';
8
- import { default as pathUtils } from 'path';
9
- import { cwd } from 'node:process';
10
-
11
- import { extractErrorMsg, unique, } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
12
- import { IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs';
13
- import { getIbAndGib, } from '@ibgib/ts-gib/dist/helper.mjs';
14
- import { GIB, } from '@ibgib/ts-gib/dist/V1/index.mjs';
15
- import { validateIbGibIntrinsically } from '@ibgib/ts-gib/dist/V1/validate-helper.mjs';
16
-
17
- import { GLOBAL_LOG_A_LOT } from '../../../../core-constants.mjs';
18
- import { parseSpaceIb, } from '../../space-helper.mjs';
19
- import { NodeFilesystemSpace_V1 } from './node-filesystem-space-v1.mjs';
20
- import { B2TFS_DEFAULT_ENCODINGS_TO_TRY, FILE_ENCODINGS, FileDataInfo, FileEncoding } from './node-filesystem-space-types.mjs';
21
-
22
-
23
- const logalot = GLOBAL_LOG_A_LOT;
24
-
25
- /**
26
- * tries to read the given path. if fails **FOR ANY REASON**, @returns `null`.
27
- *
28
- * does not throw
29
- *
30
- * @returns file contents as string or `null`
31
- */
32
- export async function tryRead({
33
- path,
34
- directory,
35
- encoding,
36
- }: {
37
- path: string,
38
- directory: string,
39
- encoding: string,
40
- }): Promise<string | Uint8Array | null> {
41
- const lc = `[${tryRead.name}]`;
42
- try {
43
- if (logalot) {
44
- console.log(`${lc} starting...`);
45
- console.log(`${lc} cwd: ${cwd()}`);
46
- if (path.includes('bootstrap^gib')) { console.log(`${lc} trying bootstrap^gib... (I: dacfdbe5a2d640ab947a7c17e3c56f78)`); }
47
- }
48
- const fullPath = pathUtils.join(directory, path);
49
- if (logalot) { console.log(`${lc} fullPath: ${fullPath} (I: 459b416ac32c711bfbab54177839b323)`); }
50
- encoding ||= 'utf8';
51
- let resRead: string | undefined = undefined;
52
- resRead = await readFile(fullPath, { encoding: encoding as BufferEncoding });
53
-
54
- if (logalot) {
55
- console.log(`${lc} record found. data length: ${resRead?.length ?? 0}. fullPath: ${fullPath}. console.dir(resRead)... (I: 82e3ad9821bd4bf8a54c8facc61dbad0)`);
56
- console.dir(resRead)
57
- }
58
- return resRead;
59
- } catch (error) {
60
- if (logalot) {
61
- console.log(`${lc} fullPath not found from directory (${directory}) and path (${path})\nerror:\n${extractErrorMsg(error)} (I: 1fde689d29aa47fcb589b3e7dac8929b)`);
62
- }
63
- return null;
64
- } finally {
65
- if (logalot) { console.log(`${lc} complete. (I: e2615c944a464cd48a5635fe401562d9)`); }
66
- }
67
- }
68
-
69
- export async function tryRead_bin({
70
- path,
71
- directory,
72
- encoding,
73
- }: {
74
- path: string,
75
- directory: string,
76
- encoding: string,
77
- }): Promise<FileDataInfo | null> {
78
- const lc = `[${tryRead_bin.name}]`;
79
- try {
80
- if (logalot) {
81
- console.log(`${lc} starting...`);
82
- console.log(`${lc} cwd: ${cwd()}`);
83
- if (path.includes('bootstrap^gib')) { console.log(`${lc} trying bootstrap^gib... (I: 5eb010444b814addb1a6bbe18ca3dbfa)`); }
84
- }
85
- const fullPath = pathUtils.join(directory, path);
86
- if (logalot) { console.log(`${lc} fullPath: ${fullPath} (I: c342bf56df354e9ab2653855a458b99d)`); }
87
- encoding ||= 'utf8';
88
- let resRead: string | Uint8Array | undefined = undefined;
89
- let encodingsToTry: FileEncoding[] = unique<FileEncoding>([
90
- encoding as FileEncoding,
91
- ...FILE_ENCODINGS,
92
- ]);
93
- let { dataBuffer, dataString, inputPath, detectedEncoding } = await getFileDataAndEncoding({
94
- inputPath: path,
95
- encodingsToTry,
96
- });
97
- if (!dataBuffer) { throw new Error(`getFileDataAndEncoding yielded falsy dataBuffer (E: f7aac299212a1ae41d5bbef6079c4d24)`); }
98
- resRead = dataBuffer;
99
-
100
- if (logalot) {
101
- console.log(`${lc} record found. data length: ${resRead?.length ?? 0}. fullPath: ${fullPath}. console.dir(resRead)... (I: 438189ba2fd345d782f928ecc7dc6e58)`);
102
- console.dir(resRead)
103
- }
104
-
105
- return {
106
- dataBuffer, dataString, inputPath, detectedEncoding
107
- };
108
- } catch (error) {
109
- if (logalot) {
110
- console.log(`${lc} fullPath not found from directory (${directory}) and path (${path})\nerror:\n${extractErrorMsg(error)} (I: 882e54f079024c94864bdaa74979b397)`);
111
- }
112
- return null;
113
- } finally {
114
- if (logalot) { console.log(`${lc} complete. (I: 500e391835aa4d959adf4720fdc38c4b)`); }
115
- }
116
- }
117
-
118
- /**
119
- * basic validation for a node fs space ibgib
120
- */
121
- export async function validateNodeFilesystemSpace_V1Intrinsically({ space }: { space: NodeFilesystemSpace_V1<any, any> }): Promise<string[] | null> {
122
- const lc = `[${validateNodeFilesystemSpace_V1Intrinsically.name}]`;
123
- try {
124
- if (logalot) { console.log(`${lc} starting... (I: fcfe57145426ab4a5a0e961e87001922)`); }
125
- const errors: string[] = (await validateIbGibIntrinsically({ ibGib: space })) ?? [];
126
-
127
- const { ib, gib, data, rel8ns } = space;
128
-
129
- if (!ib) { errors.push('ib required. (E: e69ddadd947d4534ae60af9eda1bda47)'); }
130
- if (!gib) { errors.push('gib required. (E: 9794fb92dd79473b9139c001f0634ec2)'); }
131
- if (gib === GIB) { errors.push('gib cannot be primitive. (E: 651c12f1303d45aba54aa228eca1e575)'); }
132
-
133
- if (!data) {
134
- errors.push('data required. (E: 264d13ce6b47400e8943bf046c57e8bc)');
135
- return errors;
136
- }
137
-
138
- if (!data.name) { errors.push('space name required. (E: 4845041c9f2e44098e1e7bb30fe3c13d)') }
139
- // if (!data.classname) { errors.push('classname required. (E: cb645bebf8fc4baabfbf74be39563008)') }
140
- if (data.classname && data.classname !== NodeFilesystemSpace_V1.name) {
141
- errors.push(`unknown classname (${data.classname}). data.classname !== FilesystemSpace_V1.name (E: e159eb46ca5e4c2b850998af88cb5840)`);
142
- }
143
- if (!data.baseDir) { errors.push(`data.baseDir required (E: 373544741a974ab9bc0001d3d63c2601).`) }
144
- if (!data.baseSubPath) { errors.push(`data.baseSubPath required. (E: 7336f8eb7c7846d48993e0db893fb7cb)`) }
145
- if (!data.binSubPath) { errors.push(`data.binSubPath required. (E: 3544a80a3cec4fdfb35d3e6ccb36dbd6)`) }
146
- if (!data.dnaSubPath) { errors.push(`data.dnaSubPath required. (E: 4d6e529cdd0f47a492545c31e1dda865)`) }
147
- if (!data.ibgibsSubPath) { errors.push(`data.ibgibsSubPath required. (E: 11b90fdc1b1c41b492c26a61da3409b8)`) }
148
- if (!data.metaSubPath) { errors.push(`data.metaSubPath required. (E: 259113f4f0bc488785f9019160c8a226)`) }
149
- if (data.n && typeof data.n !== 'number') { errors.push(`data.n must be a number. (E: e7c76f44b1114dba949d06146a8c169b)`) }
150
- if (data.n === undefined) {
151
- // the very first space record (tjp) has an undefined n and no rel8ns
152
- if (rel8ns) { errors.push(`rel8ns not expected when data.n is falsy (custom temporal junction point indicator I suppose...) (E: 08604c8b33524009886ac2c63eb34c50)`); }
153
- }
154
- if (!data.spaceSubPath) { errors.push(`data.spaceSubPath required. (E: 1688a59dfc6447b3bccb7690b233e4fa)`) }
155
- if (!data.uuid) { errors.push(`data.uuid required. (E: dd984a04d0d14d16a4faa300ec125960)`) }
156
- if (!data.encoding) { errors.push(`data.encoding required. (E: e75958932f614364a1765a875acad2ce)`) }
157
- /** should probably get this from Capacitor... */
158
- const validEncodings = ["utf8", "ascii", "utf16"];
159
- if (!validEncodings.includes(data.encoding)) {
160
- errors.push(`invalid encoding: ${data.encoding}. validEncodings: ${validEncodings.join(', ')} (E: b88b909521db42cbae684c2937c77079)`);
161
- }
162
-
163
- // ensure ib matches up with internal data
164
- const { spaceClassname, spaceId, spaceName } = parseSpaceIb({ spaceIb: ib });
165
- if (data.classname && (spaceClassname !== data.classname)) {
166
- errors.push(`ib's spaceClassname (${spaceClassname}) must match data.classname (${data.classname}) (E: 913b8b98717647fea832e4cca80d8ee6)`);
167
- }
168
- if (spaceId !== data.uuid) {
169
- errors.push(`ib's spaceId (${spaceId}) must match data.uuid (${data.uuid}) (E: b20f36f32bc244008b4df856f892a62a)`);
170
- }
171
- if (spaceName !== data.name) {
172
- errors.push(`ib's spaceName (${spaceName}) must match data.name (${data.name}) (E: cf599a9bf875464d9ec99c79cdee0452)`);
173
- }
174
-
175
- // ensure rel8ns make sense
176
- if (data.n === undefined && (rel8ns?.past ?? []).length > 0) {
177
- errors.push(`"past" rel8n not expected when data.n is falsy (E: 77bb7a90b40a4d989a9e53053776be86)`);
178
- }
179
- if (data.n && (rel8ns?.past ?? []).length === 0) {
180
- errors.push(`"past" rel8n required when data.n is truthy (E: 735e07bac58b44deb2523e3d349d5479)`);
181
- }
182
- if (data.n === 0 && (rel8ns?.past ?? []).length !== 1) {
183
- errors.push(`"past" rel8n expected to have a single record when data.n === 0 (E: 8915bb8084414d3b810cff9bccfc3ec6)`);
184
- }
185
- if (rel8ns && (rel8ns.past?.length ?? -1) > 0) {
186
- const pastAddrs = rel8ns.past as IbGibAddr[];
187
- pastAddrs.forEach(x => {
188
- const { ib: pastIb } = getIbAndGib({ ibGibAddr: x });
189
- const pastIbInfo = parseSpaceIb({ spaceIb: pastIb });
190
- if (pastIbInfo.spaceClassname && (pastIbInfo.spaceClassname !== spaceClassname)) {
191
- errors.push(`rel8ns.past address classname (${pastIbInfo.spaceClassname}) must match current spaceClassname (${spaceClassname}) (E: 10b2f05597574558ad2f20db8e471a44)`);
192
- }
193
- if (pastIbInfo.spaceId !== spaceId) {
194
- errors.push(`rel8ns.past address spaceId (${pastIbInfo.spaceId}) must match current spaceId (${spaceId}) (E: 78b665a31fc34c68be3884d4cd4da35a)`);
195
- }
196
- // i want to allow this, but for now we're going to require not changing the name...
197
- if (pastIbInfo.spaceName !== spaceName) {
198
- errors.push(`rel8ns.past address spaceName (${pastIbInfo.spaceName}) must match current spaceName (${spaceName}) (E: 8a6621cbec9e48e7b6d880375c444bfe)`);
199
- }
200
- });
201
- }
202
-
203
- return errors;
204
- } catch (error) {
205
- console.error(`${lc} ${error.message}`);
206
- throw error;
207
- } finally {
208
- if (logalot) { console.log(`${lc} complete.`); }
209
- }
210
- }
211
-
212
- /**
213
- * gets the data and encoding of a given {@link inputPath} if that file exists.
214
- * if it doesn't exist, this will throw an ENOENT error, but this is not logged
215
- * as an error.
216
- *
217
- * this is because atow (03/2024) this is only used in a tryRead_bin function
218
- * where the file often does not exist.
219
- */
220
- export async function getFileDataAndEncoding({
221
- inputPath,
222
- encodingsToTry = B2TFS_DEFAULT_ENCODINGS_TO_TRY,
223
- }: {
224
- inputPath: string,
225
- encodingsToTry?: (FileEncoding | undefined)[],
226
- }): Promise<FileDataInfo> {
227
- const lc = `[${getFileDataAndEncoding.name}]`;
228
- try {
229
- if (logalot) { console.log(`${lc} starting... (I: b4688e6e5f28efa9ed95729f10a6df24)`); }
230
-
231
- let resDataAndEncoding: FileDataInfo | undefined = undefined;
232
- const dataBuffer = await readFile(inputPath);
233
-
234
- if (dataBuffer.length === 0) {
235
- console.warn(`${lc} file at inputPath (${inputPath}) has dataBuffer.length === 0, i.e., no data content. we are treating this as utf8. (W: 2ea55367538146d695482cfb6ec1b79a)`)
236
- return {
237
- inputPath,
238
- dataBuffer,
239
- detectedEncoding: 'utf8',
240
- dataString: '',
241
- }; /* <<<< returns early */
242
- }
243
-
244
- encodingsToTry ??= B2TFS_DEFAULT_ENCODINGS_TO_TRY;
245
-
246
- const tryEncoding = async (encoding: FileEncoding | undefined) => {
247
- let res: [boolean, string | undefined];
248
- try {
249
- const str = dataBuffer.toString(encoding ?? undefined);
250
- /**
251
- * doesn't include the node.js replacement unicode char
252
- */
253
- const isProbablyCorrect = !str.includes('\ufffd');
254
- res = [isProbablyCorrect, str];
255
- return res;
256
- } catch (error) {
257
- debugger;
258
- res = [false, undefined];
259
- }
260
- return res;
261
- }
262
-
263
- for (let i = 0; i < encodingsToTry.length; i++) {
264
- const maybeEncoding = encodingsToTry[i];
265
- const [isProbablyCorrectEncoding, dataString] = await tryEncoding(maybeEncoding);
266
- if (isProbablyCorrectEncoding) {
267
- resDataAndEncoding = {
268
- inputPath,
269
- dataString,
270
- detectedEncoding: maybeEncoding,
271
- dataBuffer,
272
- };
273
- break;
274
- }
275
- }
276
-
277
- if (!resDataAndEncoding) {
278
- debugger; // !resDataAndEncoding -> want to see why resDataAndEncoding is still undefined
279
- throw new Error(`couldn't turn dataBuffer (length: ${dataBuffer.length}) into dataString with encodingsToTry: (${encodingsToTry}). no idea why. (E: 557c7722f2df7703429778662d3ea224)`);
280
- // resDataAndEncoding = {
281
- // inputPath,
282
- // detectedEncoding: undefined,
283
- // dataString: undefined,
284
- // dataBuffer,
285
- // }
286
- }
287
-
288
- return resDataAndEncoding;
289
- } catch (error) {
290
- // i'm just suppressing ENOENT at this time because in context, this is
291
- // often the case. we do, however, rethrow the error for proper flow.
292
- const emsg = extractErrorMsg(error);
293
- if (!emsg.startsWith('ENOENT:')) { console.error(`${lc} ${emsg}`); }
294
- throw error;
295
- } finally {
296
- if (logalot) { console.log(`${lc} complete.`); }
297
- }
298
- }
@@ -1,150 +0,0 @@
1
- /**
2
- * @module node-filesystem-space-types
3
- *
4
- * mostly interfaces, some constants
5
- */
6
-
7
- import { IbGibRel8ns_V1, } from '@ibgib/ts-gib/dist/V1/index.mjs';
8
-
9
- import { DEFAULT_LOCAL_SPACE_POLLING_INTERVAL_MS, IBGIB_SPACE_NAME_DEFAULT, ZERO_SPACE_ID } from '../../space-constants.mjs';
10
- import {
11
- IBGIB_BASE_SUBPATH, IBGIB_SPACE_SUBPATH_DEFAULT, IBGIB_BASE_DIR,
12
- IBGIB_ENCODING, IBGIB_IBGIBS_SUBPATH, IBGIB_META_SUBPATH,
13
- IBGIB_BIN_SUBPATH, IBGIB_DNA_SUBPATH,
14
- IBGIB_LONG_SUBPATH,
15
- DEFAULT_LONG_PATH_LENGTH,
16
- DEFAULT_FILESYSTEM_SPACE_DESCRIPTION,
17
- } from '../filesystem-constants.mjs';
18
- import {
19
- FilesystemSpaceData_V1,
20
- FilesystemSpaceOptionsData, FilesystemSpaceOptionsRel8ns, FilesystemSpaceOptionsIbGib,
21
- FilesystemSpaceResultData, FilesystemSpaceResultRel8ns, FilesystemSpaceResultIbGib,
22
- } from '../filesystem-space-v1.mjs';
23
-
24
-
25
- /**
26
- * This is the shape of data about this space itself (not the contained ibgibs' spaces).
27
- */
28
- export interface NodeFilesystemSpaceData_V1 extends FilesystemSpaceData_V1 {
29
- }
30
-
31
- /**
32
- * Used in bootstrapping.
33
- *
34
- * If you change this, please bump the version
35
- *
36
- * (but of course won't be the end of the world when this doesn't happen).
37
- */
38
- export const DEFAULT_NODE_FILESYSTEM_SPACE_DATA_V1: NodeFilesystemSpaceData_V1 = {
39
- version: '2',
40
- uuid: ZERO_SPACE_ID,
41
- name: IBGIB_SPACE_NAME_DEFAULT,
42
- classname: 'NodeFilesystemSpace_V1',
43
- baseDir: IBGIB_BASE_DIR,
44
- encoding: IBGIB_ENCODING,
45
- baseSubPath: IBGIB_BASE_SUBPATH,
46
- spaceSubPath: IBGIB_SPACE_SUBPATH_DEFAULT,
47
- ibgibsSubPath: IBGIB_IBGIBS_SUBPATH,
48
- metaSubPath: IBGIB_META_SUBPATH,
49
- binSubPath: IBGIB_BIN_SUBPATH,
50
- dnaSubPath: IBGIB_DNA_SUBPATH,
51
- longSubPath: IBGIB_LONG_SUBPATH,
52
- mitigateLongPaths: true,
53
- longPathLength: DEFAULT_LONG_PATH_LENGTH,
54
- persistOptsAndResultIbGibs: false,
55
- validateIbGibAddrsMatchIbGibs: false,
56
- longPollingIntervalMs: DEFAULT_LOCAL_SPACE_POLLING_INTERVAL_MS,
57
- allowPrimitiveArgs: false,
58
- catchAllErrors: true,
59
- description: DEFAULT_FILESYSTEM_SPACE_DESCRIPTION,
60
- trace: false,
61
- }
62
-
63
- /** Marker interface atm */
64
- export interface NodeFilesystemSpaceRel8ns_V1 extends IbGibRel8ns_V1 { }
65
-
66
- /**
67
- * Space options involve whether we're getting/putting ibgibs categorized as
68
- * meta, bin, dna.
69
- *
70
- * We'll leverage the fact that we don't need to get dna very often, and that
71
- * meta ibgibs act differently and are recorded differently.
72
- *
73
- * For example, we don't necessarily want to keep the past of certain meta
74
- * objects, because it may change (and thus grow) too quickly.
75
- */
76
- export interface NodeFilesystemSpaceOptionsData extends FilesystemSpaceOptionsData {
77
- }
78
-
79
- export interface NodeFilesystemSpaceOptionsRel8ns extends FilesystemSpaceOptionsRel8ns {
80
- }
81
-
82
- /** Marker interface atm */
83
- export interface NodeFilesystemSpaceOptionsIbGib
84
- extends FilesystemSpaceOptionsIbGib<NodeFilesystemSpaceOptionsData, NodeFilesystemSpaceOptionsRel8ns> {
85
- }
86
-
87
- /** Marker interface atm */
88
- export interface NodeFilesystemSpaceResultData extends FilesystemSpaceResultData {
89
- }
90
-
91
- export interface NodeFilesystemSpaceResultRel8ns extends FilesystemSpaceResultRel8ns {
92
- }
93
-
94
- export interface NodeFilesystemSpaceResultIbGib
95
- extends FilesystemSpaceResultIbGib<NodeFilesystemSpaceResultData, NodeFilesystemSpaceResultRel8ns> {
96
- }
97
- /**
98
- * currently i'm just taking this from the definition of node's `Buffer` type.
99
- *
100
- * ## notes
101
- *
102
- * * using this with handle-reify-file.mts when reading the file.
103
- * * 'binary' may resolve to 'latin1' per SO
104
- * * https://stackoverflow.com/questions/46441667/reading-binary-data-in-node-js
105
- */
106
- export type FileEncoding =
107
- | 'ascii'
108
- | 'utf8'
109
- | 'utf-8'
110
- | 'utf16le'
111
- | 'ucs2'
112
- | 'ucs-2'
113
- | 'base64'
114
- | 'base64url'
115
- | 'latin1'
116
- | 'binary'
117
- | 'hex';
118
- export const FileEncoding = {
119
- ascii: 'ascii' as FileEncoding,
120
- utf8: 'utf8' as FileEncoding,
121
- utf_8: 'utf-8' as FileEncoding,
122
- ['utf-8']: 'utf-8' as FileEncoding,
123
- utf16le: 'utf16le' as FileEncoding,
124
- ucs2: 'ucs2' as FileEncoding,
125
- ucs_2: 'ucs-2' as FileEncoding,
126
- ['ucs-2']: 'ucs-2' as FileEncoding,
127
- base64: 'base64' as FileEncoding,
128
- base64url: 'base64url' as FileEncoding,
129
- latin1: 'latin1' as FileEncoding,
130
- binary: 'binary' as FileEncoding,
131
- hex: 'hex' as FileEncoding,
132
- };
133
- /**
134
- * valid file encoding values per {@link FileEncoding}
135
- */
136
- export const FILE_ENCODINGS = Object.values(FileEncoding);
137
-
138
- export interface FileDataInfo {
139
- inputPath: string;
140
- detectedEncoding?: FileEncoding | undefined;
141
- dataString?: string | undefined;
142
- dataBuffer?: Uint8Array | undefined;
143
- }
144
- export const B2TFS_DEFAULT_ENCODINGS_TO_TRY: (FileEncoding | undefined)[] = [
145
- FileEncoding.utf8,
146
- FileEncoding.utf16le,
147
- FileEncoding.base64,
148
- FileEncoding.binary,
149
- undefined,
150
- ];