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