@ibgib/core-gib 0.1.54 → 0.1.57

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 (190) hide show
  1. package/CHANGELOG.md +11 -3
  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 +2 -87
  111. package/src/sync/docs/architecture.md +26 -5
  112. package/src/sync/docs/security.md +176 -0
  113. package/src/sync/graft-info/graft-info-helpers.respec.mts +7 -7
  114. package/src/sync/sync-conflict-adv-multitimelines.respec.mts +25 -29
  115. package/src/sync/sync-conflict-basic-divergence.respec.mts +6 -7
  116. package/src/sync/sync-conflict-basic-multitimelines.respec.mts +9 -10
  117. package/src/sync/sync-conflict-text-merge.respec.mts +29 -32
  118. package/src/sync/sync-constants.mts +2 -62
  119. package/src/sync/sync-helpers.mts +1 -8
  120. package/src/sync/sync-id-testlog.txt +421 -0
  121. package/src/sync/sync-innerspace-constants.respec.mts +4 -8
  122. package/src/sync/sync-innerspace-deep-updates.respec.mts +5 -6
  123. package/src/sync/sync-innerspace-dest-ahead-withid.respec.mts +23 -25
  124. package/src/sync/sync-innerspace-dest-ahead.respec.mts +7 -8
  125. package/src/sync/sync-innerspace-multiple-timelines.respec.mts +5 -6
  126. package/src/sync/sync-innerspace-partial-update.respec.mts +6 -7
  127. package/src/sync/sync-innerspace.respec.mts +7 -10
  128. package/src/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mts +5 -5
  129. package/src/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.mts +5 -1
  130. package/src/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mts +30 -9
  131. package/src/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.mts +3 -1
  132. package/src/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.mts +29 -2
  133. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.mts +7 -1
  134. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +51 -38
  135. package/src/sync/sync-peer/sync-peer-types.mts +23 -6
  136. package/src/sync/sync-peer/sync-peer-v1.mts +68 -28
  137. package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +6 -66
  138. package/src/sync/sync-saga-context/sync-saga-context-types.mts +1 -48
  139. package/src/sync/sync-saga-coordinator.mts +12 -552
  140. package/src/sync/sync-saga-message/sync-saga-message-types.mts +2 -3
  141. package/src/sync/sync-types.mts +2 -22
  142. package/src/sync/unused-identity-backup.mts.md +311 -0
  143. package/src/test/mock-space.mts +1 -1
  144. package/src/test-helpers.mts +1 -26
  145. package/test_output.log +0 -0
  146. package/test_output_utf8.txt +398 -0
  147. package/.vscode/core-gib-snippets.code-snippets +0 -293
  148. package/.vscode/launch.json +0 -40
  149. package/.vscode/settings.json +0 -58
  150. package/.vscode/tasks.json +0 -37
  151. package/dist/sync/sync-peer/sync-peer-http.respec.d.mts +0 -2
  152. package/dist/sync/sync-peer/sync-peer-http.respec.d.mts.map +0 -1
  153. package/dist/sync/sync-peer/sync-peer-http.respec.mjs +0 -340
  154. package/dist/sync/sync-peer/sync-peer-http.respec.mjs.map +0 -1
  155. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.d.mts +0 -42
  156. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.d.mts.map +0 -1
  157. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.mjs +0 -312
  158. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.mjs.map +0 -1
  159. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.d.mts +0 -84
  160. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.d.mts.map +0 -1
  161. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.mjs +0 -65
  162. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.mjs.map +0 -1
  163. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.d.mts +0 -73
  164. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.d.mts.map +0 -1
  165. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mjs +0 -667
  166. package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mjs.map +0 -1
  167. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.d.mts +0 -2
  168. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.d.mts.map +0 -1
  169. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.mjs +0 -67
  170. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.mjs.map +0 -1
  171. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.d.mts +0 -2
  172. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.d.mts.map +0 -1
  173. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.mjs +0 -67
  174. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.mjs.map +0 -1
  175. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.d.mts +0 -2
  176. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.d.mts.map +0 -1
  177. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.mjs +0 -68
  178. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.mjs.map +0 -1
  179. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.d.mts +0 -2
  180. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.d.mts.map +0 -1
  181. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.mjs +0 -69
  182. package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.mjs.map +0 -1
  183. package/src/sync/sync-peer/sync-peer-http.respec.mts +0 -396
  184. package/src/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.mts +0 -298
  185. package/src/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.mts +0 -150
  186. package/src/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mts +0 -666
  187. package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.mts +0 -87
  188. package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.mts +0 -88
  189. package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.mts +0 -88
  190. package/src/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.mts +0 -90
@@ -1,667 +0,0 @@
1
- import { existsSync, mkdirSync } from 'node:fs';
2
- import { writeFile, rm, readdir } from 'node:fs/promises';
3
- import { default as pathUtils } from 'path';
4
- import { clone, extractErrorMsg, } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
5
- import { getIbAndGib, getIbGibAddr, } from '@ibgib/ts-gib/dist/helper.mjs';
6
- import { getGib, getGibInfo, } from '@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs';
7
- import { validateIbGibAddr } from '@ibgib/ts-gib/dist/V1/validate-helper.mjs';
8
- import { IBGIB_DELIMITER } from '@ibgib/ts-gib/dist/V1/constants.mjs';
9
- import { GLOBAL_LOG_A_LOT } from '../../../../core-constants.mjs';
10
- import { isBinary, parseBinIb, toDto, } from '../../../../common/other/ibgib-helper.mjs';
11
- import { getSpaceIb, } from '../../space-helper.mjs';
12
- import { IBGIB_BASE_SUBPATH, IBGIB_SPACE_SUBPATH_DEFAULT, IBGIB_BASE_DIR, IBGIB_ENCODING, IBGIB_IBGIBS_SUBPATH, IBGIB_META_SUBPATH, IBGIB_BIN_SUBPATH, IBGIB_DNA_SUBPATH, DEFAULT_LONG_PATH_LENGTH, IBGIB_LONG_SUBPATH, } from '../filesystem-constants.mjs';
13
- import { FilesystemSpace_V1, } from '../filesystem-space-v1.mjs';
14
- import { tryRead, tryRead_bin } from './node-filesystem-space-helper.mjs';
15
- import { DEFAULT_NODE_FILESYSTEM_SPACE_DATA_V1, } from './node-filesystem-space-types.mjs';
16
- import { META_STONE_ATOM } from '../../../../common/meta-stone/meta-stone-constants.mjs';
17
- import { isMetaStone, validateCommonMetaStoneIb } from '../../../../common/meta-stone/meta-stone-helper.mjs';
18
- const logalot = GLOBAL_LOG_A_LOT;
19
- /**
20
- * Base class convenience for a local space with V1 ibgibs working with the node
21
- * filesystem.
22
- *
23
- * Unfortunately, file systems have short file name requirements, where 255 is
24
- * often the max length of a filename. So this cannot store ibgibs directly by
25
- * their address.
26
- *
27
- * This naively caches ibGibs in memory. When not found there, will looks in
28
- * files using Ionic `FileSystem`.
29
- */
30
- export class NodeFilesystemSpace_V1 extends FilesystemSpace_V1 {
31
- /**
32
- * Log context for convenience with logging. (Ignore if you don't want to use this.)
33
- */
34
- lc = `[${NodeFilesystemSpace_V1.name}]`;
35
- constructor(
36
- // /**
37
- // * Default predicate value when putting an unknown ibGib.
38
- // *
39
- // * ## notes
40
- // *
41
- // * So when a repo witnesses another ibGib, it either defaults to
42
- // * storing that ibGib or not storing that ibGib. This is what that
43
- // * is referring to. If it's optimistic, then it stores any ibGib by
44
- // * default and it passes its put predicate.
45
- // */
46
- // public optimisticPut: boolean = true,
47
- initialData, initialRel8ns) {
48
- super(initialData ?? clone(DEFAULT_NODE_FILESYSTEM_SPACE_DATA_V1), initialRel8ns);
49
- const lc = `${this.lc}[ctor]`;
50
- // try {
51
- // if (logalot) { console.log(`${lc} starting...`); }
52
- // this.initialize();
53
- // } catch (error) {
54
- // console.error(`${lc} ${extractErrorMsg(error)}`);
55
- // throw error;
56
- // } finally {
57
- // if (logalot) { console.log(`${lc} complete.`); }
58
- // }
59
- }
60
- /**
61
- * Factory static method to create the space with the given
62
- * `dto` param's ibGib properties.
63
- *
64
- * We do this because when we persist this space (and its settings
65
- * located in `data`), we do not save the actual class instantiation
66
- * but just the ibgib properties. Use this factory method to
67
- * create a new space instance and rehydrate from that saved dto.
68
- *
69
- * ## notes
70
- *
71
- * * DTO stands for data transfer object.
72
- *
73
- * @param dto space ibGib dto that we're going to load from
74
- * @returns newly created space built upon `dto`
75
- */
76
- static async createFromDto(dto) {
77
- const lc = `[${FilesystemSpace_V1.name}][${this.createFromDto.name}]`;
78
- if (logalot) {
79
- console.log(`${lc}`);
80
- }
81
- const space = new NodeFilesystemSpace_V1();
82
- await space.initialized;
83
- await space.loadIbGibDto(dto);
84
- return space;
85
- }
86
- async validateWitnessArg(arg) {
87
- const lc = `${this.lc}[${this.validateWitnessArg.name}]`;
88
- let errors = [];
89
- try {
90
- errors = (await super.validateWitnessArg(arg)) || [];
91
- if (arg.data?.cmd === 'put' && (arg.ibGibs || []).length === 0) {
92
- errors.push(`when "put" cmd is called, ibGibs required.`);
93
- }
94
- if (arg.data?.cmd === 'get' && (arg.data?.ibGibAddrs || []).length === 0) {
95
- errors.push(`when "get" cmd is called, ibGibAddrs required.`);
96
- }
97
- }
98
- catch (error) {
99
- console.error(`${lc} ${extractErrorMsg(error)}`);
100
- throw error;
101
- }
102
- finally {
103
- if (errors?.length > 0) {
104
- console.error(`${lc} errors: ${errors}`);
105
- }
106
- }
107
- return errors;
108
- }
109
- /**
110
- * Initializes to default space values.
111
- */
112
- async initialize() {
113
- const lc = `${this.lc}[${this.initialize.name}]`;
114
- try {
115
- if (logalot) {
116
- console.log(`${lc} starting...`);
117
- }
118
- if (!this.data) {
119
- this.data = clone(DEFAULT_NODE_FILESYSTEM_SPACE_DATA_V1);
120
- this.data = this.data; // why does ts compiler need this?
121
- }
122
- // if (!this.data?.classname) { this.data!.classname = NodeFilesystemSpace_V1.name }
123
- if (this.data.classname !== NodeFilesystemSpace_V1.name) {
124
- if (this.data.classname) {
125
- // only warn if the consumer has explicitly set a different classname
126
- console.warn(`${lc} this.data.classname (${this.data.classname}) !== ${NodeFilesystemSpace_V1.name}. overriding this. (W: 0f53162c43a440c2a790c19dd223c6b6)`);
127
- }
128
- this.data.classname = NodeFilesystemSpace_V1.name; // always set?
129
- }
130
- if (!this.data.baseDir) {
131
- this.data.baseDir = IBGIB_BASE_DIR;
132
- }
133
- if (!this.data.encoding) {
134
- this.data.encoding = IBGIB_ENCODING;
135
- }
136
- if (!this.data.baseSubPath) {
137
- this.data.baseSubPath = IBGIB_BASE_SUBPATH;
138
- }
139
- if (!this.data.spaceSubPath) {
140
- this.data.spaceSubPath = IBGIB_SPACE_SUBPATH_DEFAULT;
141
- }
142
- if (!this.data.ibgibsSubPath) {
143
- this.data.ibgibsSubPath = IBGIB_IBGIBS_SUBPATH;
144
- }
145
- if (!this.data.metaSubPath) {
146
- this.data.metaSubPath = IBGIB_META_SUBPATH;
147
- }
148
- if (!this.data.binSubPath) {
149
- this.data.binSubPath = IBGIB_BIN_SUBPATH;
150
- }
151
- if (!this.data.dnaSubPath) {
152
- this.data.dnaSubPath = IBGIB_DNA_SUBPATH;
153
- }
154
- // do nothing, allow falsy
155
- if (this.data.longSubPath === undefined) {
156
- this.data.longSubPath = IBGIB_LONG_SUBPATH;
157
- }
158
- if (this.data.longPathLength === undefined) {
159
- this.data.longPathLength = DEFAULT_LONG_PATH_LENGTH;
160
- }
161
- if (this.data.mitigateLongPaths === undefined) {
162
- this.data.mitigateLongPaths = true;
163
- }
164
- this.ib = getSpaceIb({ space: this, classname: this.data.classname });
165
- this.gib = await getGib({ ibGib: this });
166
- }
167
- catch (error) {
168
- console.error(`${lc} ${extractErrorMsg(error)}`);
169
- }
170
- finally {
171
- if (logalot) {
172
- console.log(`${lc} complete.`);
173
- }
174
- }
175
- }
176
- async putFile({ ibGib, isDna, }) {
177
- const lc = `${this.lc}[${this.putFile.name}]`;
178
- let result = {};
179
- try {
180
- if (!ibGib) {
181
- throw new Error(`ibGib required. (E: b019eedc22094687a83dca8f7a98ba35)`);
182
- }
183
- ;
184
- const thisData = this.data;
185
- // await this.ensureAllDirsExist();
186
- let path = "";
187
- let data = "";
188
- const addr = getIbGibAddr({ ibGib });
189
- const isBin = isBinary({ addr });
190
- path = await this.buildPath({
191
- addr, isDna: isDna ?? false, isBin, ensureMetaStonePaths: true,
192
- });
193
- await this.ensureDirsImpl([pathUtils.dirname(path)]);
194
- let fullPath = pathUtils.join(thisData.baseDir, path);
195
- if (logalot) {
196
- console.log(`${lc} fullPath: ${fullPath} (I: 2441a896f7e6418db57c0341d5c65ef2)`);
197
- }
198
- if (logalot) {
199
- console.log(`${lc} path: ${path}, directory: ${thisData.baseDir}, thisData.encoding: ${thisData.encoding} (I: d4440ececbe6c859f8fcf6d7ece12522)`);
200
- }
201
- let encoding;
202
- if (!isBin) {
203
- // not binary - most ibgibs will not be bins.
204
- // we only want to persist the ibGib protocol properties (not
205
- // any functions or other properties that might exist on the
206
- // incoming ibGib arg)
207
- const bareIbGib = toDto({ ibGib });
208
- data = JSON.stringify(bareIbGib);
209
- encoding = thisData.encoding || 'utf8';
210
- await writeFile(fullPath, data, encoding);
211
- }
212
- else {
213
- // binary
214
- const binIbGib = ibGib;
215
- data = binIbGib.data;
216
- if (!data) {
217
- throw new Error(`(UNEXPECTED) binIbGib.data falsy? I'm trying to have data always populated for bin ibgibs even if it is an empty Uint8Array. (E: 8c9c3650ec97792b1913754ed0877824)`);
218
- }
219
- // if (!Buffer.isBuffer(data)) {
220
- // debugger; // checking to see if !Buffer.isBuffer(data) fails for Uint8Array
221
- // throw new Error(`(UNEXPECTED) !Buffer.isBuffer(data)? I'm trying to have binIbGib.data always populated and it should be a Buffer. (E: 179c97da10ac082b77376c0db9077d24)`);
222
- // }
223
- // encoding = parseBinIb({ addr }).binEncoding ?? undefined
224
- // write bins directly as buffers
225
- // const dataBuffer = Buffer.from(data);
226
- await writeFile(fullPath, data);
227
- }
228
- result.success = true;
229
- }
230
- catch (error) {
231
- const errorMsg = `${lc} ${extractErrorMsg(error)}`;
232
- console.error(errorMsg);
233
- result.errorMsg = errorMsg;
234
- }
235
- return result;
236
- }
237
- async deleteFile({ addr, isDna, }) {
238
- const lc = `${this.lc}[${this.deleteFile.name}]`;
239
- const result = {};
240
- try {
241
- if (!addr) {
242
- throw new Error(`addr required. (E: 98ff4fb4067a4a8281e21756aca4bf82)`);
243
- }
244
- ;
245
- if (!this.data) {
246
- throw new Error(`this.data required (E: 27e1f5206d96d635e617f5ba69141423)`);
247
- }
248
- const data = this.data;
249
- let path = "";
250
- if (!isBinary({ addr })) {
251
- // regular ibGib
252
- path = await this.buildPath({
253
- addr, isDna: isDna ?? false, ensureMetaStonePaths: true,
254
- });
255
- }
256
- else {
257
- path = await this.buildPath({
258
- addr, isDna: false, isBin: true, ensureMetaStonePaths: false,
259
- });
260
- }
261
- if (logalot) {
262
- console.log(`${lc} path: ${path}, directory: ${data.baseDir}`);
263
- }
264
- const fullPath = pathUtils.join(this.data.baseDir, path);
265
- await rm(fullPath, { force: true });
266
- if (logalot) {
267
- console.log(`${lc} deleted. path: ${path}`);
268
- }
269
- result.success = true;
270
- }
271
- catch (error) {
272
- const errorMsg = `${lc} ${extractErrorMsg(error)}`;
273
- if (!errorMsg.includes('File does not exist')) {
274
- console.error(errorMsg);
275
- }
276
- else {
277
- if (logalot) {
278
- console.log(`${lc} attempted to delete non-existent file. ${errorMsg} (I: 8953b51a5f14960e5ea2e86f6c6a7622)`);
279
- }
280
- }
281
- result.errorMsg = errorMsg;
282
- }
283
- return result;
284
- }
285
- async getFile({ addr, isDna, }) {
286
- let lc = `${this.lc}[${this.getFile.name}(${addr})]`;
287
- const result = {};
288
- try {
289
- if (logalot) {
290
- console.log(`${lc} starting... (I: f69b58063ff7cafaaab341e633002a23)`);
291
- }
292
- if (!addr) {
293
- throw new Error(`addr required`);
294
- }
295
- ;
296
- const data = this.data;
297
- const { ib } = getIbAndGib({ ibGibAddr: addr });
298
- const addrIsBin = isBinary({ addr });
299
- const knownTransformIbs = ['fork', 'mut8', 'rel8', 'plan']; // hack/kluge here
300
- const addrMightBeDna = knownTransformIbs.some(x => x === ib || x.startsWith(ib + ' '));
301
- const pathsToLook = [];
302
- if (isDna || addrMightBeDna) {
303
- pathsToLook.push(await this.buildPath({
304
- addr, isDna: true, ensureMetaStonePaths: false
305
- }));
306
- }
307
- else if (addrIsBin) {
308
- pathsToLook.push(await this.buildPath({
309
- addr, isDna: false, isBin: true, ensureMetaStonePaths: false
310
- }));
311
- }
312
- // always look in the main location as a last resort
313
- pathsToLook.push(await this.buildPath({
314
- addr, isDna: false, ensureMetaStonePaths: false
315
- }));
316
- // ...(pretend shortened as well as an absolute last last resort)
317
- if (!isMetaStone({ addr })) {
318
- pathsToLook.push(await this.buildPath({
319
- addr, isDna: false, ensureMetaStonePaths: false,
320
- pretendItsALongPath: true,
321
- }));
322
- }
323
- // this is ugly atow (02/2024) because i'm struggling a bit of
324
- // changing bin ibgibs to actually support binaries. i apologize.
325
- if (!addrIsBin) {
326
- // non-bin ibGib(s) retrieved (most ibgibs are non-bin)
327
- let resRead = null;
328
- for (const tryPath of pathsToLook) {
329
- const x = await tryRead({ path: tryPath, directory: data.baseDir, encoding: data.encoding });
330
- if (x) {
331
- resRead = x;
332
- break;
333
- }
334
- }
335
- if (resRead) {
336
- result.ibGib = JSON.parse(resRead);
337
- }
338
- else {
339
- if (logalot) {
340
- console.log(`${lc} paths not found: ${JSON.stringify(pathsToLook)} (I: 7fc6c550b1a047d8a14392185de1b06e)`);
341
- }
342
- // will return success since it's not really an error, but ibgib
343
- // will not be populated, indicating the addr was not found.
344
- }
345
- }
346
- else {
347
- // bin
348
- let resRead = null;
349
- let { binEncoding, binHash } = parseBinIb({ addr });
350
- if (binHash === '0') {
351
- // special case: if the binHash is 0, then it is an empty file.
352
- const { ib, gib } = getIbAndGib({ ibGibAddr: addr });
353
- result.ibGib = {
354
- ib,
355
- gib,
356
- data: new Uint8Array(0),
357
- // data: '',
358
- // rawData: Buffer.from([]),
359
- };
360
- }
361
- else {
362
- for (const tryPath of pathsToLook) {
363
- const x = await tryRead_bin({
364
- path: tryPath, directory: data.baseDir, encoding: binEncoding ?? data.encoding,
365
- });
366
- if (x) {
367
- resRead = x;
368
- break;
369
- }
370
- }
371
- if (resRead) {
372
- // all bins are buffers
373
- const { ib, gib } = getIbAndGib({ ibGibAddr: addr });
374
- const binIbGib = {
375
- ib, gib, data: resRead.dataBuffer,
376
- // rawData: resRead.dataBuffer,
377
- };
378
- result.ibGib = binIbGib;
379
- }
380
- else {
381
- if (logalot) {
382
- console.log(`${lc} paths not found: ${JSON.stringify(pathsToLook)} (I: 6a3bd3b125619da7a944200b14e7e922)`);
383
- }
384
- // will return success since it's not really an error, but ibgib
385
- // will not be populated, indicating the addr was not found.
386
- }
387
- }
388
- }
389
- result.success = true;
390
- }
391
- catch (error) {
392
- const errorMsg = `${lc} ${extractErrorMsg(error)}`;
393
- console.error(errorMsg);
394
- result.errorMsg = errorMsg;
395
- }
396
- finally {
397
- if (logalot) {
398
- console.log(`${lc} complete. (I: 413374e48f0a3cb8fd25de0d82134123)`);
399
- }
400
- }
401
- return result;
402
- }
403
- async ensurePermissions() {
404
- const lc = `${this.lc}[${this.ensurePermissions.name}]`;
405
- if (logalot) {
406
- console.log(`${lc} always returns true in base class (I: 0a036a097093c622167e40f81e03d923)`);
407
- }
408
- return true;
409
- }
410
- async ensureAllDirsExist() {
411
- const lc = `${this.lc}[${this.ensureAllDirsExist.name}]`;
412
- try {
413
- if (logalot) {
414
- console.log(`${lc} starting... (I: f9f1bc18215fd591cf9dcaea4deaa323)`);
415
- }
416
- if (!this.data) {
417
- throw new Error(`this.data required (E: ccf51541c1d5714ddafb67a8c3289823)`);
418
- }
419
- if (!this.data.uuid) {
420
- throw new Error(`this.data.uuid required (E: 33691c4c97e2033bf13d2c2d26a8f823)`);
421
- }
422
- const data = this.data;
423
- /** these are the paths we're ensuring exist. all ibgibs are stored here. */
424
- const paths = [
425
- data.baseSubPath, // = 'ibgib';
426
- data.baseSubPath + '/' + data.spaceSubPath,
427
- data.baseSubPath + '/' + data.spaceSubPath + '/' + data.ibgibsSubPath,
428
- data.baseSubPath + '/' + data.spaceSubPath + '/' + data.metaSubPath,
429
- data.baseSubPath + '/' + data.spaceSubPath + '/' + data.binSubPath,
430
- data.baseSubPath + '/' + data.spaceSubPath + '/' + data.dnaSubPath,
431
- ];
432
- if (data.mitigateLongPaths) {
433
- paths.push(data.baseSubPath + '/' + data.spaceSubPath + '/' + data.longSubPath);
434
- }
435
- await this.ensureDirsImpl(paths);
436
- }
437
- catch (error) {
438
- console.error(`${lc} ${extractErrorMsg(error)}`);
439
- throw error;
440
- }
441
- finally {
442
- if (logalot) {
443
- console.log(`${lc} complete.`);
444
- }
445
- }
446
- }
447
- /**
448
- * actually executes the ensure functionality for given `paths`. If they
449
- * don't exist, then this tries to make the dirs.
450
- * @param paths to ensure exist.
451
- */
452
- async ensureDirsImpl(paths) {
453
- const lc = `${this.lc}[${this.ensureDirsImpl.name}]`;
454
- try {
455
- if (logalot) {
456
- console.log(`${lc} starting... (I: ad355a80dafa5873ac8ef31bf1f27923)`);
457
- }
458
- if (paths.length === 0) {
459
- console.warn(`${lc} paths empty? returning early. (W: a089ab1c9c0a4275a49341fb9f4c01c1)`);
460
- return; /* <<<< returns early */
461
- }
462
- const directory = this.data.baseDir;
463
- const getPathKey = (p) => { return directory.toString() + '/' + p; };
464
- let allExist = paths.every(p => this.pathExistsMap[getPathKey(p)]);
465
- if (allExist) {
466
- if (logalot) {
467
- console.log(`${lc} allExist (I: f14ad6db1d29e368c37c3117fee1cb22)`);
468
- }
469
- return; /* <<<< returns early */
470
- }
471
- const permitted = await this.ensurePermissions();
472
- if (!permitted) {
473
- console.error(`${lc} permission not granted.`);
474
- return; /* <<<< returns early */
475
- }
476
- for (let i = 0; i < paths.length; i++) {
477
- const path = paths[i];
478
- const lc2 = `${lc}[(path: ${path}, directory: ${directory})]`;
479
- const fullPath = pathUtils.join(directory, path);
480
- // check if we've already ensured for this path
481
- const pathExistsKey = getPathKey(path);
482
- let exists = this.pathExistsMap[pathExistsKey] || false;
483
- if (!exists) {
484
- // we've not checked this path (or it didn't exist)
485
- try {
486
- exists = existsSync(fullPath);
487
- this.pathExistsMap[pathExistsKey] = exists;
488
- }
489
- catch (error) {
490
- if (logalot) {
491
- console.log(`${lc2} Did not exist`);
492
- }
493
- }
494
- }
495
- if (!exists) {
496
- // try full path
497
- if (logalot) {
498
- console.log(`${lc2} creating...`);
499
- }
500
- try {
501
- mkdirSync(fullPath, { recursive: true });
502
- exists = existsSync(fullPath);
503
- if (logalot) {
504
- console.log(`${lc} exists: ${exists}`);
505
- }
506
- this.pathExistsMap[pathExistsKey] = exists;
507
- }
508
- catch (error) {
509
- if (logalot) {
510
- console.log(`${lc2} Error creating. Trying next`);
511
- }
512
- }
513
- finally {
514
- if (logalot) {
515
- console.log(`${lc2} complete.`);
516
- }
517
- }
518
- }
519
- }
520
- }
521
- catch (error) {
522
- console.error(`${lc} ${extractErrorMsg(error)}`);
523
- throw error;
524
- }
525
- finally {
526
- if (logalot) {
527
- console.log(`${lc} complete.`);
528
- }
529
- }
530
- }
531
- /** */
532
- async getMetaStoneAddrs({ ibGibAddr, tjpGib, fnFilterIb, }) {
533
- const lc = `${this.lc}[${this.getMetaStoneAddrs.name}]`;
534
- try {
535
- if (logalot) {
536
- console.log(`${lc} starting... (I: 510ba658195aa0aed9b8836f616d7823)`);
537
- }
538
- // first build the path with the given tjpGib
539
- // debugger;
540
- let pathSansBaseDir = await this.buildPath({
541
- addr: ibGibAddr, ensureMetaStonePaths: false, isDna: false,
542
- addrIsForAMetaStone: true,
543
- });
544
- let fullPath = pathUtils.join(this.data.baseDir, pathSansBaseDir);
545
- if (logalot) {
546
- console.log(`${lc} fullPath: ${fullPath} (I: 9fc7113d6c9649f9b25f227ddad57f69)`);
547
- }
548
- // the given ibgib's containing dir is the one that should contain
549
- // the metastones.
550
- let gibInfo = getGibInfo({ ibGibAddr });
551
- let containingDir = !!gibInfo.tjpGib ?
552
- pathUtils.dirname(pathUtils.join(fullPath, '..')) :
553
- pathUtils.dirname(fullPath);
554
- if (logalot) {
555
- console.log(`${lc} containingDir: ${containingDir} (I: 2780437a6778a4633f49d81ac26ab723)`);
556
- }
557
- // iterate through the files for metastones.
558
- const fnFilter = fnFilterIb ?
559
- (s) => s.startsWith(META_STONE_ATOM) && fnFilterIb(s) :
560
- (s) => s.startsWith(META_STONE_ATOM);
561
- let filenames = [];
562
- try {
563
- if (logalot) {
564
- console.log(`${lc} calling readdir(containingDir) (I: 682d129a44d1101a0a7c2be999921923)`);
565
- }
566
- filenames = await readdir(containingDir, {
567
- recursive: false,
568
- withFileTypes: false,
569
- });
570
- }
571
- catch (error) {
572
- let emsg = extractErrorMsg(error);
573
- if (!emsg.includes('ENOENT')) { // no such file or directory
574
- console.warn(`${lc} readdir error did not contain ENOENT...not sure what this is...maybe a different OS no dir exists emsg? Treating this as if dir does not exist. (W: cde1cab3f64c47559782da8da55ed48a)`);
575
- }
576
- else {
577
- if (logalot) {
578
- console.log(`${lc} readdir errors: ${extractErrorMsg(error)} (I: 62bd4ec398b86ca84f7b3866dd83c123)`);
579
- }
580
- }
581
- filenames = [];
582
- }
583
- if (filenames.length === 0) {
584
- if (logalot) {
585
- console.log(`${lc} filenames: [empty]. no metastones found. (I: da9fef3f2edde037ca1c340bc38b7723)`);
586
- }
587
- return []; /* <<<< returns early */
588
- }
589
- if (logalot) {
590
- console.log(`${lc} filenames: ${filenames} (I: cb2948540a031522d184b1611f914323)`);
591
- }
592
- /**
593
- * atow (11/2023) extensions are hard-coded to ".json",
594
- */
595
- const dotExt = '.json';
596
- const dotExtLength = 5;
597
- const metaStoneAddrs = filenames
598
- .filter(x => {
599
- // some filenames may be adjusted and not the full ibs.
600
- // however, the metastones are never shortened (atow
601
- // 11/2023), so those that don't have the delimiter will be
602
- // stored in ibIsh but they should get filtered out.
603
- const [ibIsh, gibPlusExt] = x.split(IBGIB_DELIMITER);
604
- return !!gibPlusExt?.endsWith(dotExt) && fnFilter(ibIsh);
605
- }).map(addrPlusExt => {
606
- // strip the extension
607
- return addrPlusExt.substring(0, addrPlusExt.length - dotExtLength);
608
- }).filter(metaStoneAddr => {
609
- // atow (11/2023) I'm not sure what other metastones are
610
- // going to be in this dir, so I'm saying it has to
611
- // explicitly contain the tjpGib.
612
- return isMetaStone({ addr: metaStoneAddr }) && metaStoneAddr.includes(tjpGib);
613
- });
614
- if (logalot) {
615
- console.log(`${lc} filtered/mapped filenames -> metaStoneAddrs: ${metaStoneAddrs} (I: ed062833a65730c04c7f9523e31a5a23)`);
616
- }
617
- // do some basic validation
618
- // throw (which could cripple in the future...), or silent fail
619
- // (which could lead to corrupt data)... hmm...going to throw for
620
- // now.
621
- for (let i = 0; i < metaStoneAddrs.length; i++) {
622
- const metaStoneAddr = metaStoneAddrs[i];
623
- let basicErrors = validateIbGibAddr({ addr: metaStoneAddr });
624
- if ((basicErrors ?? []).length > 0) {
625
- throw new Error(`(UNEXPECTED) invalid metastone found? metaStoneAddr (${metaStoneAddr}) had basic validation errors: ${basicErrors.join('|')} (E: 318c164fc2014c036c91b179c8d7f623)`);
626
- }
627
- const { ib } = getIbAndGib({ ibGibAddr: metaStoneAddr });
628
- let metaStoneErrors = validateCommonMetaStoneIb({ ib });
629
- if (metaStoneErrors.length > 0) {
630
- throw new Error(`(UNEXPECTED) metaStoneIb had validation errors? metaStoneErrors: ${metaStoneErrors.join('|')} (E: 5a07b4dcd817f72a1a70e4b2d18f7323)`);
631
- }
632
- }
633
- // all good, return 'em!
634
- if (logalot) {
635
- console.log(`${lc} returning metaStoneAddrs: ${metaStoneAddrs} (I: c235e1005d02a53219e032f8818e8223)`);
636
- }
637
- return metaStoneAddrs;
638
- }
639
- catch (error) {
640
- console.error(`${lc} ${extractErrorMsg(error)}`);
641
- throw error;
642
- }
643
- finally {
644
- if (logalot) {
645
- console.log(`${lc} complete.`);
646
- }
647
- }
648
- }
649
- }
650
- export async function convertData({ data, encoding, }) {
651
- const lc = `[${convertData.name}]`;
652
- try {
653
- if (logalot) {
654
- console.log(`${lc} starting... (I: 77ef782249fdc9588c5b5b810126cc24)`);
655
- }
656
- }
657
- catch (error) {
658
- console.error(`${lc} ${extractErrorMsg(error)}`);
659
- throw error;
660
- }
661
- finally {
662
- if (logalot) {
663
- console.log(`${lc} complete.`);
664
- }
665
- }
666
- }
667
- //# sourceMappingURL=node-filesystem-space-v1.mjs.map