@ibgib/core-gib 0.0.90 → 0.0.92
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/dist/common/alias/alias-constants.d.mts +19 -0
- package/dist/common/alias/alias-constants.d.mts.map +1 -0
- package/dist/common/alias/alias-constants.mjs +24 -0
- package/dist/common/alias/alias-constants.mjs.map +1 -0
- package/dist/common/alias/alias-helper.d.mts +69 -0
- package/dist/common/alias/alias-helper.d.mts.map +1 -0
- package/dist/common/alias/alias-helper.mjs +207 -0
- package/dist/common/alias/alias-helper.mjs.map +1 -0
- package/dist/common/alias/alias-types.d.mts +30 -0
- package/dist/common/alias/alias-types.d.mts.map +1 -0
- package/dist/common/alias/alias-types.mjs +2 -0
- package/dist/common/alias/alias-types.mjs.map +1 -0
- package/dist/common/other/other-constants.mjs +2 -2
- package/dist/common/other/other-constants.mjs.map +1 -1
- package/dist/common/other/other-types.d.mts +3 -1
- package/dist/common/other/other-types.d.mts.map +1 -1
- package/dist/common/other/other-types.mjs +2 -5
- package/dist/common/other/other-types.mjs.map +1 -1
- package/dist/common/tag/tag-constants.d.mts +1 -1
- package/dist/common/tag/tag-constants.d.mts.map +1 -1
- package/dist/common/tag/tag-constants.mjs +1 -1
- package/dist/common/tag/tag-constants.mjs.map +1 -1
- package/dist/common/tag/tag-helper.d.mts +3 -2
- package/dist/common/tag/tag-helper.d.mts.map +1 -1
- package/dist/common/tag/tag-helper.mjs +7 -7
- package/dist/common/tag/tag-helper.mjs.map +1 -1
- package/dist/witness/space/metaspace/metaspace-base.d.mts +1 -1
- package/dist/witness/space/metaspace/metaspace-base.d.mts.map +1 -1
- package/dist/witness/space/metaspace/metaspace-base.mjs +6 -1
- package/dist/witness/space/metaspace/metaspace-base.mjs.map +1 -1
- package/dist/witness/space/metaspace/metaspace-types.d.mts +1 -1
- package/dist/witness/space/space-helper.d.mts.map +1 -1
- package/dist/witness/space/space-helper.mjs +0 -1
- package/dist/witness/space/space-helper.mjs.map +1 -1
- package/package.json +1 -1
- package/src/common/alias/alias-constants.mts +28 -0
- package/src/common/alias/alias-helper.mts +259 -0
- package/src/common/alias/alias-types.mts +36 -0
- package/src/common/other/other-constants.mts +2 -2
- package/src/common/other/other-types.mts +3 -7
- package/src/common/tag/tag-constants.mts +1 -1
- package/src/common/tag/tag-helper.mts +7 -6
- package/src/witness/space/metaspace/metaspace-base.mts +4 -1
- package/src/witness/space/metaspace/metaspace-types.mts +1 -1
- package/src/witness/space/space-helper.mts +0 -1
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { extractErrorMsg, getSaferSubstring } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
|
|
2
|
+
import { IbGibAddr } from "@ibgib/ts-gib/dist/types.mjs";
|
|
3
|
+
import { IbGib_V1, Rel8n } from "@ibgib/ts-gib/dist/V1/types.mjs";
|
|
4
|
+
import { getIbAndGib, getIbGibAddr } from "@ibgib/ts-gib/dist/helper.mjs";
|
|
5
|
+
import { rel8 } from "@ibgib/ts-gib/dist/V1/transforms/rel8.mjs";
|
|
6
|
+
import { Factory_V1 } from "@ibgib/ts-gib/dist/V1/factory.mjs";
|
|
7
|
+
|
|
8
|
+
import { GLOBAL_LOG_A_LOT } from "../../core-constants.mjs";
|
|
9
|
+
import { AliasIbGib_V1, AliasInfo } from "./alias-types.mjs";
|
|
10
|
+
import { ALIAS_ATOM, ALIAS_MAX_LENGTH, ALIAS_REL8N_NAME, ALIAS_TARGET_REL8N_NAME, DEFAULT_ALIAS_DESCRIPTION } from "./alias-constants.mjs";
|
|
11
|
+
import { MetaspaceService } from "../../witness/space/metaspace/metaspace-types.mjs";
|
|
12
|
+
import { IbGibSpaceAny } from "../../witness/space/space-base-v1.mjs";
|
|
13
|
+
import { SpecialIbGibType } from "../other/other-types.mjs";
|
|
14
|
+
import { rel8ToSpecialIbGib } from "../../witness/space/space-helper.mjs";
|
|
15
|
+
|
|
16
|
+
const logalot = GLOBAL_LOG_A_LOT;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* relates an ibgib provided by {@link ibGib} or {@link addr} to the latest
|
|
20
|
+
* version of the given {@link aliasIbGib}.
|
|
21
|
+
*
|
|
22
|
+
* If the alias already exists, this will replace the target ibgib with the ibgib passed in.
|
|
23
|
+
* if the alias does not exist, this will create the new alias first.
|
|
24
|
+
*
|
|
25
|
+
* persists this result in the same {@link space} and registers the newly
|
|
26
|
+
* created alias ibgib via the {@link metaspace}.
|
|
27
|
+
*
|
|
28
|
+
* @returns the new/latest alias ibgib
|
|
29
|
+
*
|
|
30
|
+
* @throws an error if the aliases special ibgib index does not exist in the
|
|
31
|
+
* given {@link space}
|
|
32
|
+
*
|
|
33
|
+
* @see {@link ALIAS_TARGET_REL8N_NAME}
|
|
34
|
+
*/
|
|
35
|
+
export async function setAlias({
|
|
36
|
+
ibGib,
|
|
37
|
+
addr,
|
|
38
|
+
aliasIbGib,
|
|
39
|
+
aliasName,
|
|
40
|
+
metaspace,
|
|
41
|
+
space,
|
|
42
|
+
lock,
|
|
43
|
+
}: {
|
|
44
|
+
/**
|
|
45
|
+
* the ibgib that we're relating to the alias. can also provide just the
|
|
46
|
+
* {@link addr}.
|
|
47
|
+
*/
|
|
48
|
+
ibGib?: IbGib_V1,
|
|
49
|
+
/**
|
|
50
|
+
* the ibgib addr that we're relating to the alias.
|
|
51
|
+
*/
|
|
52
|
+
addr?: IbGibAddr,
|
|
53
|
+
/**
|
|
54
|
+
* the alias that we're relating to
|
|
55
|
+
*/
|
|
56
|
+
aliasIbGib?: AliasIbGib_V1,
|
|
57
|
+
aliasName?: string,
|
|
58
|
+
/**
|
|
59
|
+
* it's meta
|
|
60
|
+
*/
|
|
61
|
+
metaspace: MetaspaceService,
|
|
62
|
+
/**
|
|
63
|
+
* space in which the alias exists on the aliases special ibgib index
|
|
64
|
+
*/
|
|
65
|
+
space: IbGibSpaceAny,
|
|
66
|
+
/**
|
|
67
|
+
* lock on operations
|
|
68
|
+
*/
|
|
69
|
+
lock?: boolean,
|
|
70
|
+
}): Promise<AliasIbGib_V1> {
|
|
71
|
+
const lc = `[${setAlias.name}]`;
|
|
72
|
+
try {
|
|
73
|
+
if (logalot) { console.log(`${lc} starting... (I: f6a2969d2948482cac073467a010fe1b)`); }
|
|
74
|
+
|
|
75
|
+
if (addr && ibGib && addr !== getIbGibAddr({ ibGib })) { throw new Error(`both addr (${addr}) and ibGib (${getIbGibAddr({ ibGib })}) are provided but addr does not match addr of ibGib. (E: a0bfe5acf9c643cbbd20cc3936580ce9)`); }
|
|
76
|
+
|
|
77
|
+
if (!addr && !ibGib) { throw new Error(`either addr or ibGib required (E: 8f02309770504046960c64fae00c0fcc)`); }
|
|
78
|
+
addr ??= getIbGibAddr({ ibGib });
|
|
79
|
+
|
|
80
|
+
let aliasAddr: IbGibAddr | undefined = aliasIbGib ?
|
|
81
|
+
getIbGibAddr({ ibGib: aliasIbGib }) :
|
|
82
|
+
undefined;
|
|
83
|
+
|
|
84
|
+
if (!aliasIbGib) {
|
|
85
|
+
// get the alias ibgib if exists. if doesn't exist, will create
|
|
86
|
+
// later in code
|
|
87
|
+
if (!aliasName) { throw new Error(`(UNEXPECTED) !aliasIbGib && !aliasName? either aliasIbGib or aliasName required (E: 7dda32d1803ac02b4c80f415fd726f24)`); }
|
|
88
|
+
|
|
89
|
+
let info = await getAliasInfo({ aliasName, metaspace, space, lock });
|
|
90
|
+
if (info) {
|
|
91
|
+
aliasIbGib = info.ibGib;
|
|
92
|
+
aliasAddr = getIbGibAddr({ ibGib: aliasIbGib });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let newAliasIbGib: AliasIbGib_V1;
|
|
97
|
+
|
|
98
|
+
let latestAliasAddr: IbGibAddr | undefined = aliasAddr ?
|
|
99
|
+
await metaspace.getLatestAddr({ addr: aliasAddr, space }) :
|
|
100
|
+
undefined;
|
|
101
|
+
|
|
102
|
+
if (latestAliasAddr) {
|
|
103
|
+
// alias exists, so update
|
|
104
|
+
|
|
105
|
+
if (!aliasIbGib || latestAliasAddr !== getIbGibAddr({ ibGib: aliasIbGib })) {
|
|
106
|
+
let resGetLatestAlias = await metaspace.get({ addr: latestAliasAddr, space });
|
|
107
|
+
if (!resGetLatestAlias.success || resGetLatestAlias.ibGibs?.length !== 1) {
|
|
108
|
+
throw new Error(`could not get latest alias (${latestAliasAddr}) from space (${space.ib}). error: ${resGetLatestAlias.errorMsg ?? '[unknown error (E: faae3a4b5f6b4e28b99d089f1a8be13a)]'} (E: c5fc6dc7326242e48618b240266e63b7)`);
|
|
109
|
+
}
|
|
110
|
+
aliasIbGib = resGetLatestAlias.ibGibs!.at(0)! as AliasIbGib_V1;
|
|
111
|
+
aliasAddr = getIbGibAddr({ ibGib: aliasIbGib });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// at this point, the aliasIbGib and its addr are guaranteed to be
|
|
115
|
+
// truthy and latest
|
|
116
|
+
|
|
117
|
+
const rel8nsToAddByAddr = { [ALIAS_TARGET_REL8N_NAME]: [addr] };
|
|
118
|
+
const resRel8ToAlias =
|
|
119
|
+
await rel8({
|
|
120
|
+
src: aliasIbGib,
|
|
121
|
+
rel8nsToAddByAddr,
|
|
122
|
+
// linked because an alias only points to a single target
|
|
123
|
+
linkedRel8ns: [ALIAS_TARGET_REL8N_NAME],
|
|
124
|
+
dna: true, nCounter: true,
|
|
125
|
+
});
|
|
126
|
+
newAliasIbGib = resRel8ToAlias.newIbGib as AliasIbGib_V1;
|
|
127
|
+
|
|
128
|
+
await metaspace.persistTransformResult({ resTransform: resRel8ToAlias, space });
|
|
129
|
+
|
|
130
|
+
// update the special ibgib index to point to the new alias
|
|
131
|
+
const _newAliasesIndexIbGib = await metaspace.rel8ToSpecialIbGib({
|
|
132
|
+
type: SpecialIbGibType.aliases,
|
|
133
|
+
rel8nName: ALIAS_REL8N_NAME,
|
|
134
|
+
space,
|
|
135
|
+
ibGibsToRel8: [newAliasIbGib],
|
|
136
|
+
ibGibsToUnRel8: [aliasIbGib],
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
// alias does not yet exist, so create new
|
|
140
|
+
|
|
141
|
+
if (!aliasName) { throw new Error(`(UNEXPECTED) !latestAliasAddr and !aliasName? alias should either exist in space (${space.ib}) and have a latest addr or aliasName should be provided. (E: ab1cc9d24f356b888f877131d5dff824)`); }
|
|
142
|
+
|
|
143
|
+
const saferizedAliasName = getSaferSubstring({ text: aliasName });
|
|
144
|
+
|
|
145
|
+
const resNewAlias = await Factory_V1.firstGen({
|
|
146
|
+
parentIbGib: Factory_V1.primitive({ ib: ALIAS_ATOM }),
|
|
147
|
+
ib: `${ALIAS_ATOM} ${saferizedAliasName}`,
|
|
148
|
+
data: {
|
|
149
|
+
name: saferizedAliasName,
|
|
150
|
+
rawName: aliasName, // just in case probably yagni yada yada
|
|
151
|
+
description: DEFAULT_ALIAS_DESCRIPTION,
|
|
152
|
+
},
|
|
153
|
+
// linked because an alias only points to a single target
|
|
154
|
+
linkedRel8ns: [ALIAS_TARGET_REL8N_NAME],
|
|
155
|
+
tjp: { uuid: true, timestamp: true },
|
|
156
|
+
dna: true,
|
|
157
|
+
nCounter: true,
|
|
158
|
+
});
|
|
159
|
+
newAliasIbGib = resNewAlias.newIbGib as AliasIbGib_V1;
|
|
160
|
+
await metaspace.persistTransformResult({ resTransform: resNewAlias, space });
|
|
161
|
+
|
|
162
|
+
const _newAliasesIndexIbGib = await metaspace.rel8ToSpecialIbGib({
|
|
163
|
+
type: SpecialIbGibType.aliases,
|
|
164
|
+
rel8nName: ALIAS_REL8N_NAME,
|
|
165
|
+
space,
|
|
166
|
+
ibGibsToRel8: [newAliasIbGib],
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
await metaspace.registerNewIbGib({ ibGib: newAliasIbGib, space });
|
|
171
|
+
return newAliasIbGib;
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
174
|
+
throw error;
|
|
175
|
+
} finally {
|
|
176
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* gets the alias ibgib and sundry based on given `aliasName`.
|
|
182
|
+
*
|
|
183
|
+
* @returns info about the alias registered or undefined if no matching alias
|
|
184
|
+
* exists
|
|
185
|
+
*/
|
|
186
|
+
export async function getAliasInfo({
|
|
187
|
+
aliasName,
|
|
188
|
+
metaspace,
|
|
189
|
+
lock,
|
|
190
|
+
space,
|
|
191
|
+
}: {
|
|
192
|
+
aliasName: string,
|
|
193
|
+
/**
|
|
194
|
+
* space in which the alias exists on the aliases special ibgib index
|
|
195
|
+
*/
|
|
196
|
+
space: IbGibSpaceAny,
|
|
197
|
+
metaspace: MetaspaceService,
|
|
198
|
+
/**
|
|
199
|
+
* lock on operations
|
|
200
|
+
*/
|
|
201
|
+
lock?: boolean,
|
|
202
|
+
}): Promise<AliasInfo | undefined> {
|
|
203
|
+
const lc = `[${getAliasInfo.name}]`;
|
|
204
|
+
try {
|
|
205
|
+
if (logalot) { console.log(`${lc} starting... (I: 40bc11ee4d0e182047ffa28d046a0324)`); }
|
|
206
|
+
|
|
207
|
+
if (aliasName.length > ALIAS_MAX_LENGTH) { throw new Error(`invalid aliasName. cannot be greater than ALIAS_MAX_LENGTH (${ALIAS_MAX_LENGTH}). (E: b1a03c3893519b8bdbaef52ee1d4ab24)`); }
|
|
208
|
+
|
|
209
|
+
// get the alias via aliasName from the special ibgib index
|
|
210
|
+
let aliasesIbGib = await metaspace.getSpecialIbGib({
|
|
211
|
+
type: SpecialIbGibType.aliases,
|
|
212
|
+
initialize: false,
|
|
213
|
+
lock,
|
|
214
|
+
space,
|
|
215
|
+
});
|
|
216
|
+
if (!aliasesIbGib) { throw new Error(`no aliases special ibgib (index) exists in given space (${space.ib}). This index must be initialized first. (E: 7f4cb726cafb93534e2d893945867b24)`); }
|
|
217
|
+
|
|
218
|
+
// find the alias
|
|
219
|
+
const saferizedAliasName = getSaferSubstring({ text: aliasName! });
|
|
220
|
+
let rel8dTargets = (aliasesIbGib.rel8ns ?? {})[ALIAS_TARGET_REL8N_NAME] ?? [];
|
|
221
|
+
|
|
222
|
+
// alias ibs atow (04/2024) are just `alias_atom saferizedAliasName`
|
|
223
|
+
let aliasAddr = rel8dTargets.find(aliasAddr => {
|
|
224
|
+
let { ib: targetAliasIb } = getIbAndGib({ ibGibAddr: aliasAddr });
|
|
225
|
+
let saferizedAliasName_target = targetAliasIb.substring(`${ALIAS_ATOM} `.length);
|
|
226
|
+
return saferizedAliasName_target === saferizedAliasName;
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
if (aliasAddr) {
|
|
230
|
+
let latestAliasAddr = await metaspace.getLatestAddr({ addr: aliasAddr, space });
|
|
231
|
+
if (!latestAliasAddr) { throw new Error(`(UNEXPECTED) alias addr exists on special ibgib in space but getLatestAddr returns falsy? (E: 854b7209fe851ee4ea4034d5db229924)`); }
|
|
232
|
+
|
|
233
|
+
let resGetLatestAlias = await metaspace.get({ addr: latestAliasAddr, space });
|
|
234
|
+
if (!resGetLatestAlias.success || resGetLatestAlias.ibGibs?.length !== 1) {
|
|
235
|
+
throw new Error(`could not get latest alias (${latestAliasAddr}) from space (${space.ib}). error: ${resGetLatestAlias.errorMsg ?? '[unknown error (E: 3f4a79a1603c40e285816a81d693a488)]'} (E: b2e8fe50fbbc44a5ac973c23d3a40fef)`);
|
|
236
|
+
}
|
|
237
|
+
let aliasIbGib = resGetLatestAlias.ibGibs!.at(0)! as AliasIbGib_V1;
|
|
238
|
+
if (!aliasIbGib.rel8ns) { throw new Error(`(UNEXPECTED) !aliasIbGib.rel8ns? (E: 1d78faaf1c73c27d5cee2edbd1a14a24)`); }
|
|
239
|
+
if (!aliasIbGib.rel8ns[ALIAS_TARGET_REL8N_NAME]) { throw new Error(`(UNEXPECTED) !aliasIbGib.rel8ns[ALIAS_TARGET_REL8N_NAME]? (E: b7b2d8ac1c3d6e910b56891e56c9ab24)`); }
|
|
240
|
+
if (aliasIbGib.rel8ns[ALIAS_TARGET_REL8N_NAME].length !== 1) { throw new Error(`(UNEXPECTED) aliasIbGib.rel8ns[ALIAS_TARGET_REL8N_NAME].length !== 1? (E: 8da0d9566ca9c6b8519f46157404eb24)`); }
|
|
241
|
+
return {
|
|
242
|
+
ibGib: aliasIbGib,
|
|
243
|
+
targetAddr: aliasIbGib.rel8ns[ALIAS_TARGET_REL8N_NAME].at(0)!,
|
|
244
|
+
rawName: aliasName,
|
|
245
|
+
saferizedName: saferizedAliasName,
|
|
246
|
+
};
|
|
247
|
+
} else {
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
} catch (error) {
|
|
251
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
252
|
+
throw error;
|
|
253
|
+
} finally {
|
|
254
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// todo: removeAlias function
|
|
259
|
+
// todo: updateAlias function
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs';
|
|
2
|
+
import { IbGibData_V1, IbGibRel8ns_V1, IbGib_V1 } from '@ibgib/ts-gib/dist/V1/index.mjs';
|
|
3
|
+
|
|
4
|
+
import { ALIAS_TARGET_REL8N_NAME } from './alias-constants.mjs';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export interface AliasData_V1 extends IbGibData_V1 {
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface AliasRel8ns_V1 extends IbGibRel8ns_V1 {
|
|
11
|
+
[ALIAS_TARGET_REL8N_NAME]?: IbGibAddr[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface AliasIbGib_V1 extends IbGib_V1<AliasData_V1, AliasRel8ns_V1> {
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface AliasInfo {
|
|
19
|
+
/**
|
|
20
|
+
* reference to the actual ibgib
|
|
21
|
+
*/
|
|
22
|
+
ibGib: AliasIbGib_V1;
|
|
23
|
+
/**
|
|
24
|
+
* addr that the alias ibgib points to
|
|
25
|
+
*/
|
|
26
|
+
targetAddr: IbGibAddr;
|
|
27
|
+
/**
|
|
28
|
+
* this is what we actually go by
|
|
29
|
+
*/
|
|
30
|
+
saferizedName: string;
|
|
31
|
+
/**
|
|
32
|
+
* vague thoughts on storing the raw name in case there are issues or in
|
|
33
|
+
* case we want to load full records....yada hrmm
|
|
34
|
+
*/
|
|
35
|
+
rawName: string;
|
|
36
|
+
}
|
|
@@ -14,7 +14,7 @@ export const DEFAULT_UUID = undefined;
|
|
|
14
14
|
import { ROBBOT_REL8N_NAME } from '../../witness/robbot/robbot-constants.mjs';
|
|
15
15
|
import { SYNC_SPACE_REL8N_NAME } from '../../witness/space/space-constants.mjs';
|
|
16
16
|
import { DEFAULT_ROOT_REL8N_NAME, ROOT_REL8N_NAME } from '../root/root-constants.mjs';
|
|
17
|
-
import {
|
|
17
|
+
import { TAG_TARGET_REL8N_NAME, TAG_REL8N_NAME } from '../tag/tag-constants.mjs';
|
|
18
18
|
|
|
19
19
|
export const AUTOSYNC_ALWAYS_REL8N_NAME = 'always';
|
|
20
20
|
export const ARCHIVE_REL8N_NAME = 'archive';
|
|
@@ -29,7 +29,7 @@ export const DEFAULT_LIST_REL8N_NAMES: string[] = [
|
|
|
29
29
|
'pic', 'comment', 'link',
|
|
30
30
|
'result', 'import',
|
|
31
31
|
'tagged',
|
|
32
|
-
|
|
32
|
+
TAG_TARGET_REL8N_NAME,
|
|
33
33
|
TAG_REL8N_NAME,
|
|
34
34
|
ROOT_REL8N_NAME, // hack for now to get all to show
|
|
35
35
|
DEFAULT_ROOT_REL8N_NAME,
|
|
@@ -144,8 +144,7 @@ export interface DeleteIbGibResult extends FileResult { }
|
|
|
144
144
|
* should be extensible per use case in consuming apps.
|
|
145
145
|
*/
|
|
146
146
|
export type SpecialIbGibType =
|
|
147
|
-
"tags" | "roots" |
|
|
148
|
-
// "latest" |
|
|
147
|
+
"tags" | "aliases" | "roots" |
|
|
149
148
|
"outerspaces" | "secrets" |
|
|
150
149
|
"encryptions" | "autosyncs" | "robbots" | "apps" | "history" |
|
|
151
150
|
string;
|
|
@@ -159,13 +158,10 @@ export type SpecialIbGibType =
|
|
|
159
158
|
export const SpecialIbGibType = {
|
|
160
159
|
/** indexes all tag ibgibs within a space */
|
|
161
160
|
tags: "tags" as SpecialIbGibType,
|
|
161
|
+
/** indexes all aliases within a space */
|
|
162
|
+
aliases: "aliases" as SpecialIbGibType,
|
|
162
163
|
/** indexes all root ibgibs within a space */
|
|
163
164
|
roots: "roots" as SpecialIbGibType,
|
|
164
|
-
// /**
|
|
165
|
-
// * Ephemeral index ibgib that maps a tjp address -> latest local address in
|
|
166
|
-
// * a space.
|
|
167
|
-
// */
|
|
168
|
-
// latest: "latest" as SpecialIbGibType,
|
|
169
165
|
/** indexes all outerspace ibgibs, including sync spaces, within a space */
|
|
170
166
|
outerspaces: "outerspaces" as SpecialIbGibType,
|
|
171
167
|
/** indexes all secret ibgibs within a space */
|
|
@@ -10,7 +10,7 @@ export const TAG_REL8N_NAME = 'tag';
|
|
|
10
10
|
/**
|
|
11
11
|
* A tag ibGib uses this rel8n name for the ibgibs that it targets.
|
|
12
12
|
*/
|
|
13
|
-
export const
|
|
13
|
+
export const TAG_TARGET_REL8N_NAME = 'target';
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
export const ILLEGAL_TAG_TEXT_CHARS = [
|
|
@@ -6,7 +6,7 @@ import { rel8 } from "@ibgib/ts-gib/dist/V1/transforms/rel8.mjs";
|
|
|
6
6
|
|
|
7
7
|
import { GLOBAL_LOG_A_LOT } from "../../core-constants.mjs";
|
|
8
8
|
import { TagIbGib_V1 } from "./tag-types.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import { TAG_TARGET_REL8N_NAME } from "./tag-constants.mjs";
|
|
10
10
|
import { MetaspaceService } from "../../witness/space/metaspace/metaspace-types.mjs";
|
|
11
11
|
import { IbGibSpaceAny } from "../../witness/space/space-base-v1.mjs";
|
|
12
12
|
|
|
@@ -20,7 +20,7 @@ const logalot = GLOBAL_LOG_A_LOT;
|
|
|
20
20
|
* created tag ibgib via the {@link metaspace}.
|
|
21
21
|
*
|
|
22
22
|
* @returns new tag ibgib that has the ibgib related to it
|
|
23
|
-
* @see {@link
|
|
23
|
+
* @see {@link TAG_TARGET_REL8N_NAME}
|
|
24
24
|
*/
|
|
25
25
|
export async function rel8ToTag({
|
|
26
26
|
ibGib,
|
|
@@ -39,7 +39,8 @@ export async function rel8ToTag({
|
|
|
39
39
|
*/
|
|
40
40
|
addr?: IbGibAddr,
|
|
41
41
|
/**
|
|
42
|
-
* the tag that we're relating to
|
|
42
|
+
* the tag that we're relating to. Note that this gets the latest of this
|
|
43
|
+
* tag in the given {@link space}.
|
|
43
44
|
*/
|
|
44
45
|
tagIbGib: TagIbGib_V1,
|
|
45
46
|
/**
|
|
@@ -55,12 +56,12 @@ export async function rel8ToTag({
|
|
|
55
56
|
try {
|
|
56
57
|
if (logalot) { console.log(`${lc} starting... (I: b1fd25ec28bce8f1916b4ab55f48a724)`); }
|
|
57
58
|
|
|
58
|
-
if (addr && ibGib && addr !== getIbGibAddr({ ibGib })) { throw new Error(`both addr (${addr}) and ibGib (${getIbGibAddr({ ibGib })}) are provided but addr does not match addr of ibGib. (E: f2c14234a78c917fb9f587beaee89324)`); }
|
|
59
59
|
|
|
60
60
|
if (!addr && !ibGib) { throw new Error(`either addr or ibGib required (E: 3d580f8ecc251a0c81c7ea8bc3d38524)`); }
|
|
61
61
|
addr ??= getIbGibAddr({ ibGib });
|
|
62
|
+
if (addr !== getIbGibAddr({ ibGib })) { throw new Error(`addr (${addr}) differs from incoming ibGib's addr (${getIbGibAddr({ ibGib })}). (E: f2c14234a78c917fb9f587beaee89324)`); }
|
|
62
63
|
|
|
63
|
-
const latestTagAddr = await metaspace.getLatestAddr({
|
|
64
|
+
const latestTagAddr = await metaspace.getLatestAddr({ ibGib: tagIbGib, space });
|
|
64
65
|
if (latestTagAddr !== getIbGibAddr({ ibGib: tagIbGib })) {
|
|
65
66
|
let resGetLatestTag = await metaspace.get({ addr: latestTagAddr, space });
|
|
66
67
|
if (!resGetLatestTag.success || resGetLatestTag.ibGibs?.length !== 1) {
|
|
@@ -69,7 +70,7 @@ export async function rel8ToTag({
|
|
|
69
70
|
tagIbGib = resGetLatestTag.ibGibs!.at(0)! as TagIbGib_V1;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
const rel8nsToAddByAddr = { [
|
|
73
|
+
const rel8nsToAddByAddr = { [TAG_TARGET_REL8N_NAME]: [addr] };
|
|
73
74
|
const resRel8ToTag =
|
|
74
75
|
await rel8({ src: tagIbGib, rel8nsToAddByAddr, dna: true, nCounter: true });
|
|
75
76
|
const newTagIbGib = resRel8ToTag.newIbGib as TagIbGib_V1;
|
|
@@ -548,6 +548,9 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
548
548
|
await this.getSpecialIbGib({ type: "tags", initialize: true });
|
|
549
549
|
if (logalot) { console.timeLog(timerName); }
|
|
550
550
|
|
|
551
|
+
await this.getSpecialIbGib({ type: SpecialIbGibType.aliases, initialize: true });
|
|
552
|
+
if (logalot) { console.timeLog(timerName); }
|
|
553
|
+
|
|
551
554
|
await this.getSpecialIbGib({ type: "robbots", initialize: true });
|
|
552
555
|
if (logalot) { console.timeLog(timerName); }
|
|
553
556
|
|
|
@@ -1478,7 +1481,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
1478
1481
|
* * This was written early and makes many assumptions.
|
|
1479
1482
|
* * Meant to work with Ionic space atow.
|
|
1480
1483
|
*
|
|
1481
|
-
* @returns latest addr in a given space (or localUserSpace)
|
|
1484
|
+
* @returns latest addr in a given space (or localUserSpace) or undefined if does not exist
|
|
1482
1485
|
*/
|
|
1483
1486
|
async getLatestAddr({
|
|
1484
1487
|
ibGib,
|
|
@@ -447,7 +447,7 @@ export interface MetaspaceService {
|
|
|
447
447
|
* * This was written early and makes many assumptions.
|
|
448
448
|
* * Meant to work with Ionic space atow.
|
|
449
449
|
*
|
|
450
|
-
* @returns latest addr in a given space (or localUserSpace)
|
|
450
|
+
* @returns latest addr in a given space (or localUserSpace) or undefined if does not exist
|
|
451
451
|
*/
|
|
452
452
|
getLatestAddr(arg: {
|
|
453
453
|
ibGib?: IbGib_V1<any>,
|
|
@@ -1621,7 +1621,6 @@ export async function createTagIbGibAndSundry({
|
|
|
1621
1621
|
parentIbGib: tagPrimitive,
|
|
1622
1622
|
ib: tagIb,
|
|
1623
1623
|
data: { text, icon, description },
|
|
1624
|
-
linkedRel8ns: [Rel8n.past, Rel8n.ancestor],
|
|
1625
1624
|
tjp: { uuid: true, timestamp: true },
|
|
1626
1625
|
dna: true,
|
|
1627
1626
|
nCounter: true,
|