@ibgib/ts-gib 0.4.9

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 (87) hide show
  1. package/.vscode/launch.json +24 -0
  2. package/.vscode/settings.json +34 -0
  3. package/.vscode/tasks.json +37 -0
  4. package/CHANGELOG.md +159 -0
  5. package/README.md +502 -0
  6. package/dist/V1/constants.d.mts +22 -0
  7. package/dist/V1/constants.d.mts.map +1 -0
  8. package/dist/V1/constants.mjs +21 -0
  9. package/dist/V1/constants.mjs.map +1 -0
  10. package/dist/V1/factory.d.mts +23 -0
  11. package/dist/V1/factory.d.mts.map +1 -0
  12. package/dist/V1/factory.mjs +78 -0
  13. package/dist/V1/factory.mjs.map +1 -0
  14. package/dist/V1/index.d.mts +6 -0
  15. package/dist/V1/index.d.mts.map +1 -0
  16. package/dist/V1/index.mjs +6 -0
  17. package/dist/V1/index.mjs.map +1 -0
  18. package/dist/V1/sha256v1.d.mts +19 -0
  19. package/dist/V1/sha256v1.d.mts.map +1 -0
  20. package/dist/V1/sha256v1.mjs +86 -0
  21. package/dist/V1/sha256v1.mjs.map +1 -0
  22. package/dist/V1/transforms/fork.d.mts +16 -0
  23. package/dist/V1/transforms/fork.d.mts.map +1 -0
  24. package/dist/V1/transforms/fork.mjs +111 -0
  25. package/dist/V1/transforms/fork.mjs.map +1 -0
  26. package/dist/V1/transforms/index.d.mts +5 -0
  27. package/dist/V1/transforms/index.d.mts.map +1 -0
  28. package/dist/V1/transforms/index.mjs +5 -0
  29. package/dist/V1/transforms/index.mjs.map +1 -0
  30. package/dist/V1/transforms/mut8.d.mts +50 -0
  31. package/dist/V1/transforms/mut8.d.mts.map +1 -0
  32. package/dist/V1/transforms/mut8.mjs +246 -0
  33. package/dist/V1/transforms/mut8.mjs.map +1 -0
  34. package/dist/V1/transforms/rel8.d.mts +14 -0
  35. package/dist/V1/transforms/rel8.d.mts.map +1 -0
  36. package/dist/V1/transforms/rel8.mjs +176 -0
  37. package/dist/V1/transforms/rel8.mjs.map +1 -0
  38. package/dist/V1/transforms/transform-helper.d.mts +92 -0
  39. package/dist/V1/transforms/transform-helper.d.mts.map +1 -0
  40. package/dist/V1/transforms/transform-helper.mjs +189 -0
  41. package/dist/V1/transforms/transform-helper.mjs.map +1 -0
  42. package/dist/V1/types.d.mts +79 -0
  43. package/dist/V1/types.d.mts.map +1 -0
  44. package/dist/V1/types.mjs +12 -0
  45. package/dist/V1/types.mjs.map +1 -0
  46. package/dist/helper.d.mts +77 -0
  47. package/dist/helper.d.mts.map +1 -0
  48. package/dist/helper.mjs +179 -0
  49. package/dist/helper.mjs.map +1 -0
  50. package/dist/index.cjs +4 -0
  51. package/dist/index.cjs.map +1 -0
  52. package/dist/index.d.cts +4 -0
  53. package/dist/index.d.cts.map +1 -0
  54. package/dist/index.d.mts +4 -0
  55. package/dist/index.d.mts.map +1 -0
  56. package/dist/index.mjs +4 -0
  57. package/dist/index.mjs.map +1 -0
  58. package/dist/types.d.mts +242 -0
  59. package/dist/types.d.mts.map +1 -0
  60. package/dist/types.mjs +2 -0
  61. package/dist/types.mjs.map +1 -0
  62. package/jasmine-browser.json +18 -0
  63. package/jasmine.json +6 -0
  64. package/package.json +61 -0
  65. package/src/V1/constants.mts +23 -0
  66. package/src/V1/factory.mts +110 -0
  67. package/src/V1/factory.spec.mts +162 -0
  68. package/src/V1/index.mts +5 -0
  69. package/src/V1/sha256v1.mts +85 -0
  70. package/src/V1/sha256v1.spec.mts +221 -0
  71. package/src/V1/transforms/fork.mts +100 -0
  72. package/src/V1/transforms/fork.spec.mts +410 -0
  73. package/src/V1/transforms/index.mts +4 -0
  74. package/src/V1/transforms/mut8.mts +239 -0
  75. package/src/V1/transforms/mut8.spec.mts +656 -0
  76. package/src/V1/transforms/rel8.mts +173 -0
  77. package/src/V1/transforms/rel8.spec.mts +556 -0
  78. package/src/V1/transforms/transform-helper.mts +263 -0
  79. package/src/V1/transforms/transform-helper.spec.mts +45 -0
  80. package/src/V1/types.mts +84 -0
  81. package/src/helper.mts +192 -0
  82. package/src/helper.spec.mts +127 -0
  83. package/src/index.cts +3 -0
  84. package/src/index.mts +3 -0
  85. package/src/types.mts +242 -0
  86. package/tsconfig.json +15 -0
  87. package/tsconfig.test.json +10 -0
@@ -0,0 +1,179 @@
1
+ let crypto = globalThis.crypto;
2
+ let { subtle } = crypto;
3
+ export const HashAlgorithm = {
4
+ 'sha_256': 'SHA-256',
5
+ 'sha_512': 'SHA-512',
6
+ };
7
+ export function clone(obj) {
8
+ return JSON.parse(JSON.stringify(obj));
9
+ }
10
+ export function getTimestamp() {
11
+ return (new Date()).toUTCString();
12
+ }
13
+ /**
14
+ * Gets the ib^gib address from the given ib and gib or
15
+ * from the ibGib object.
16
+ *
17
+ * Need to refactor to getIbGibAddr
18
+ */
19
+ export function getIbGibAddr({ ib, gib, ibGib, delimiter = '^' }) {
20
+ ib = ib || ibGib?.ib || '';
21
+ gib = gib || ibGib?.gib || '';
22
+ return ib + delimiter + gib;
23
+ }
24
+ /**
25
+ * Get the ib and gib fields from an ibGib object or ibGibAddr
26
+ * with the given `delimiter`.
27
+ */
28
+ export function getIbAndGib({ ibGib, ibGibAddr, delimiter = '^' }) {
29
+ const lc = '[getIbAndGib]';
30
+ if (!ibGibAddr) {
31
+ if (ibGib) {
32
+ ibGibAddr = getIbGibAddr({ ibGib });
33
+ }
34
+ else {
35
+ throw new Error(`${lc} We need either an address or an ibGib object`);
36
+ }
37
+ }
38
+ if (!ibGibAddr) {
39
+ throw new Error(`${lc} Couldn't get ibGibAddr. ibGib invalid?`);
40
+ }
41
+ if (!delimiter) {
42
+ delimiter = '^';
43
+ }
44
+ const pieces = ibGibAddr.split(delimiter);
45
+ if (pieces.length === 2) {
46
+ // normal v1 case, e.g. 'ib^gib' or 'tag home^ABC123'
47
+ return { ib: pieces[0], gib: pieces[1] };
48
+ }
49
+ else if (pieces.length === 1 && ibGibAddr.endsWith(delimiter)) {
50
+ // normal v1 primitive, e.g. '7^' or 'name^'
51
+ return { ib: pieces[0], gib: '' };
52
+ }
53
+ else if (pieces.length === 1 && ibGibAddr.startsWith(delimiter)) {
54
+ // only gib/hash is provided like maybe a binary file
55
+ // e.g. ^ABC123 or ^XYZ456 or ^some_gib_that_isnt_a_hash
56
+ return { ib: '', gib: pieces[0] };
57
+ }
58
+ else if (pieces.length === 2 && pieces[0] === '' && pieces[1] === '') {
59
+ // edge case of address is only the delimiter.
60
+ // So it's the primitive for that delimiter
61
+ return { ib: delimiter, gib: '' };
62
+ // } else if (pieces.length === 0 ) {
63
+ // ibGibAddr is falsy, so would have thrown earlier in this function
64
+ // I'm just noting this case for intent ATOW
65
+ }
66
+ else {
67
+ console.warn(`${lc} multiple delimiters found in ibGibAddr. Considering last delimiter as the demarcation of gib hash`);
68
+ // e.g. 'ib^ABC123^gib'
69
+ // ib: 'ib^ABC123'
70
+ // gib: 'gib'
71
+ return {
72
+ ib: pieces.slice(0, pieces.length - 1).join(delimiter),
73
+ gib: pieces.slice(pieces.length - 1)[0],
74
+ };
75
+ }
76
+ }
77
+ /**
78
+ * Simple hash function.
79
+ *
80
+ * NOTE:
81
+ * This is not used for ibGib.gib values (ATOW)
82
+ * but rather as a helper function for generating random UUIDs.
83
+ *
84
+ * @param s string to hash
85
+ * @param algorithm to use, currently only 'SHA-256'
86
+ */
87
+ export async function hash({ s, algorithm = 'SHA-256', }) {
88
+ if (!s) {
89
+ return '';
90
+ }
91
+ const validAlgorithms = Object.values(HashAlgorithm);
92
+ if (!validAlgorithms.includes(algorithm)) {
93
+ console.error(`Only ${validAlgorithms} implemented`);
94
+ return '';
95
+ }
96
+ try {
97
+ const msgUint8 = new TextEncoder().encode(s);
98
+ const buffer = await subtle.digest(algorithm, msgUint8);
99
+ const asArray = Array.from(new Uint8Array(buffer));
100
+ return asArray.map(b => b.toString(16).padStart(2, '0')).join('');
101
+ }
102
+ catch (e) {
103
+ console.error(extractErrorMsg(e.message));
104
+ return '';
105
+ }
106
+ }
107
+ /**
108
+ * Simple func to generate UUID (sha-256 hash basically).
109
+ *
110
+ * @param seedSize size of seed for UUID generation
111
+ */
112
+ export async function getUUID(seedSize = 64) {
113
+ let uuid = '';
114
+ if (seedSize < 32) {
115
+ throw new Error(`Seed size must be at least 32`);
116
+ }
117
+ if (!globalThis.crypto) {
118
+ throw new Error(`Cannot create UUID, as unknown crypto library version. If using node.js, v19+ is required. (E: c02cee3fd8a94f678d3f4ebe9dc49797)`);
119
+ }
120
+ const values = crypto.getRandomValues(new Uint8Array(16));
121
+ uuid = await hash({ s: values.join('') });
122
+ if (!uuid) {
123
+ throw new Error(`Did not create UUID...hmm...`);
124
+ }
125
+ return uuid;
126
+ }
127
+ /**
128
+ * Syntactic sugar for JSON.stringify(obj, null, 2);
129
+ *
130
+ * @param obj to pretty stringify
131
+ */
132
+ export function pretty(obj) {
133
+ return JSON.stringify(obj, null, 2);
134
+ }
135
+ /**
136
+ * Just delays given number of ms.
137
+ *
138
+ * @param ms milliseconds to delay
139
+ */
140
+ export async function delay(ms) {
141
+ return new Promise(resolve => {
142
+ setTimeout(() => {
143
+ resolve();
144
+ }, ms);
145
+ });
146
+ }
147
+ /**
148
+ * extracts the error message from an error object/string/falsy arg.
149
+ *
150
+ * ## notes
151
+ *
152
+ * * some libs throw errors, some throw just strings.
153
+ * * who knows what else it could be.
154
+ *
155
+ * ## todo
156
+ *
157
+ * * extract inner errors/causes if we ever use this function extensively.
158
+ *
159
+ * @param error the error object in the catch area of the try..catch block.
160
+ * @returns error.message if it's a string, error itself if it's a string, or canned error messages if it's falsy or none of the above.
161
+ */
162
+ export function extractErrorMsg(error) {
163
+ if (!error && error !== 0) {
164
+ return '[error is falsy]';
165
+ }
166
+ else if (typeof error === 'string') {
167
+ return error;
168
+ }
169
+ else if (typeof error.message === 'string') {
170
+ return error.message;
171
+ }
172
+ else if (typeof error === 'number') {
173
+ return JSON.stringify(error);
174
+ }
175
+ else {
176
+ return `[error is not a string and error.message is not a string. typeof error: ${typeof error}]`;
177
+ }
178
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E;QAC1C,OAAO,KAAK,CAAC,OAAO,CAAC;KACxB;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAClC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;KAChC;SAAM;QACH,OAAO,2EAA2E,OAAO,KAAK,GAAG,CAAC;KACrG;AACL,CAAC"}
package/dist/index.cjs ADDED
@@ -0,0 +1,4 @@
1
+ export * as V1 from './V1/index.mjs';
2
+ export * from './types.mjs';
3
+ export * from './helper.mjs';
4
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.cts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * as V1 from './V1/index.mjs';
2
+ export * from './types.mjs';
3
+ export * from './helper.mjs';
4
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.cts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * as V1 from './V1/index.mjs';
2
+ export * from './types.mjs';
3
+ export * from './helper.mjs';
4
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
package/dist/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ export * as V1 from './V1/index.mjs';
2
+ export * from './types.mjs';
3
+ export * from './helper.mjs';
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,242 @@
1
+ /**
2
+ * The core of the simplicity of the ibGib protocol is that
3
+ * fundamentally you are taking two ibGibs and producing a third.
4
+ *
5
+ * There are three primary functions: mut8, rel8, fork
6
+ *
7
+ * These are actually different aspects of the single function of
8
+ * relationship and time, either extending or creating a timeline.
9
+ *
10
+ * Mut8 is intrinsic, rel8 is extrinsic, fork is a new timeline.
11
+ * Mut8 changes a timeline, rel8 changes a timeline's link(s),
12
+ * fork creates a new timeline.
13
+ */
14
+ export declare type Ib = '' | string;
15
+ export declare type Gib = '' | 'gib' | string;
16
+ /**
17
+ * Convenient for when destructuring an IbGibAddr
18
+ */
19
+ export interface IbAndGib {
20
+ ib: Ib;
21
+ gib: Gib;
22
+ }
23
+ /**
24
+ * Mostly a marker type of address.
25
+ *
26
+ * Not sure how to enforce schema on demand in TypeScript, but
27
+ * that's to decide for future.
28
+ */
29
+ export declare type IbGibAddr = string;
30
+ export declare type IbGibRel8ns = {
31
+ /**
32
+ * The key is the rel8nName.
33
+ *
34
+ * TS doesnt allow for the indexer to have a non-number/string value
35
+ * even if it's an alias for one of these types to be more readable.
36
+ * Otherwise I would type the `key` here as a `Rel8nName` alias of
37
+ * `string.`
38
+ */
39
+ [key: string]: IbGibAddr[] | null | undefined;
40
+ };
41
+ /**
42
+ * At the base ibGib, the bare minimum is that an ib (data) is required,
43
+ * with an optional gib (metadata).
44
+ */
45
+ export interface IbGib {
46
+ ib: Ib;
47
+ gib?: Gib;
48
+ }
49
+ /**
50
+ * When adding additional structure to an ibGib, the first representation
51
+ * mechanism (from V1) was having explicit Data and Rel8ns keys.
52
+ *
53
+ * This is, however, not the only way to represent this. As just one example,
54
+ * you could also have a prefix for keys that are meant to be the relationships
55
+ * to other ibGibs.
56
+ *
57
+ * I'm including this shape at the core here and not just in V1 because it could
58
+ * be reused for other versions that are different tweaks with different default
59
+ * relationships and data structures but still adhere to this data/rel8ns split
60
+ * (and naming convention).
61
+ */
62
+ export interface IbGibWithDataAndRel8ns<TData = any, TRel8ns extends IbGibRel8ns = IbGibRel8ns> extends IbGib {
63
+ /**
64
+ * Intrinsic data to this ibGib, most likely with primitives e.g. strings or numbers,
65
+ * that will be statically copied from mutation to mutation.
66
+ */
67
+ data?: TData | undefined;
68
+ /**
69
+ * Extrinsic data WRT this ibGib, which can track their own timelines of changes.
70
+ *
71
+ * Note that even if the relationships here point to the same address, i.e. do
72
+ * not change, the other ibGibs can be seen as changing or not. It all depends
73
+ * on how you want to interpret the relationship.
74
+ *
75
+ * For example, if you want to pause/freeze a relationship, then this would be
76
+ * handled by the viewer of the relationship. It just wouldn't check anywhere for
77
+ * the more up-to-date version.
78
+ */
79
+ rel8ns?: TRel8ns | undefined;
80
+ }
81
+ export declare type TransformType = 'fork' | 'mut8' | 'rel8';
82
+ export interface TransformOpts<TSrc extends IbGib = IbGib> {
83
+ /**
84
+ * Fork, mut8, rel8
85
+ */
86
+ type?: TransformType;
87
+ /**
88
+ * If truthy, does NOT add a timestamp to the new ibGib.
89
+ */
90
+ noTimestamp?: boolean;
91
+ /**
92
+ * If truthy, creates dna ibGibs like V1.
93
+ * If falsy, skips the dna and only creates the resultant ibGib.
94
+ */
95
+ dna?: boolean;
96
+ /**
97
+ * Src to apply the transform to.
98
+ *
99
+ * Used at runtime, NOT persisted in space.
100
+ */
101
+ src?: TSrc;
102
+ /**
103
+ * Address of Src. Used in the space persistence.
104
+ */
105
+ srcAddr?: IbGibAddr;
106
+ /**
107
+ * There are two ways of creating rel8ns to other ibgibs:
108
+ *
109
+ * 1) Concat previous ones with new one
110
+ * * e.g. past: ['a^gib'] --> past: ['a^gib', 'b^gib'] --> past: ['a^gib', 'b^gib', 'c^gib']
111
+ * 2) Only have most recent one, linked list style:
112
+ * * e.g. past: ['a^gib'] --> past: ['b^gib'] --> past: ['c^gib']
113
+ *
114
+ * If you choose #1, then you have the advantage of not needing to load up all of the previous
115
+ * records to evaluate. So this will give you minimal runtime requirements, but take up more space.
116
+ * If you choose #2, like in a blockchain e.g., then you will have a smaller space footprint but
117
+ * it takes longer to build the entire list.
118
+ *
119
+ * This gives flexibility for having rel8ns that only wish to have a single value at most.
120
+ *
121
+ */
122
+ linkedRel8ns?: string[];
123
+ /**
124
+ * If truthy, this will include a data['n'] value that acts as an incremented
125
+ * counter for a naive versioning tracker.
126
+ *
127
+ * So A0^123.data.n = 0, A1^456.data.n = 1, etc.
128
+ */
129
+ nCounter?: boolean;
130
+ }
131
+ export interface TemporalJunctionPointOptions {
132
+ timestamp?: boolean;
133
+ uuid?: boolean;
134
+ }
135
+ export interface TransformOpts_Fork<TSrc extends IbGib = IbGib> extends TransformOpts<TSrc> {
136
+ type?: 'fork';
137
+ /**
138
+ * Destination ib for the transform.
139
+ */
140
+ destIb?: string;
141
+ /**
142
+ * If truthy, creates a UUID to encourage local uniqueness of the fork.
143
+ */
144
+ uuid?: boolean;
145
+ /**
146
+ * If truthy, the forked ibGib will be a temporal junction point using
147
+ * the specified
148
+ * This will provide a UUID to encourage local uniqueness of the fork.
149
+ *
150
+ * For what a temporal junction point is, refer to
151
+ * Back to the Future II (or ask me).
152
+ */
153
+ tjp?: TemporalJunctionPointOptions;
154
+ /**
155
+ * If true, retains parent/source's extrinsic rel8ns.
156
+ */
157
+ cloneRel8ns?: boolean;
158
+ /**
159
+ * If true, retains parent/source's intrinsic data.
160
+ */
161
+ cloneData?: boolean;
162
+ }
163
+ export interface TransformOpts_Mut8<TSrc extends IbGib = IbGib, TNewData = any> extends TransformOpts<TSrc> {
164
+ type?: 'mut8';
165
+ /**
166
+ * Info to rename keys. Should be an object where each value should either be
167
+ * a string or an object. If it's a string, then the corresponding key will
168
+ * be renamed to that value. If it's an object, then it will recurse at that
169
+ * key.
170
+ *
171
+ * @example
172
+ * data = { a: 'aaa', b: { rename: 'me', ignore: 'me' }}
173
+ * dataToRemove = { a: 'aRenamed', b: { rename: 'renamed' } }
174
+ * data = { aRenamed: 'aaa', b: { renamed: 'me', ignore: 'me' }}
175
+ */
176
+ dataToRename?: {
177
+ [key: string]: any;
178
+ };
179
+ /**
180
+ * Info to remove keys. Should be an object where each value should either be
181
+ * a string or an object. If it's a string, then the corresponding key will
182
+ * be removed (the value is ignored). If it's an object, then it will recurse at that
183
+ * key.
184
+ *
185
+ * @example
186
+ * data = { a: 'aaa', b: { remove: 'me', ignore: 'me' }}
187
+ * dataToRemove = { b: { remove: '' } }
188
+ * data = { a: 'aaa', b: { ignore: 'me' }}
189
+ */
190
+ dataToRemove?: {
191
+ [key: string]: any;
192
+ };
193
+ /**
194
+ * Data object that contains only additive information for ibGib's intrinsic data.
195
+ */
196
+ dataToAddOrPatch?: TNewData;
197
+ /**
198
+ * If given, will mut8 the ib (without forking the entire ibGib).
199
+ *
200
+ * Often this will act as a 'rename', e.g. (if the ib is acting as the 'name')
201
+ */
202
+ mut8Ib?: string;
203
+ }
204
+ export interface TransformOpts_Rel8<TSrc extends IbGib = IbGib> extends TransformOpts<TSrc> {
205
+ type?: 'rel8';
206
+ /**
207
+ * Relationships to add to an ibGib, either by creating new relationships or by
208
+ * concatenating the arrays to existing ones.
209
+ *
210
+ * NOTES:
211
+ * - Moving relationships can be performed by combining add/remove rel8ns.
212
+ * - How the relations are actually represented in the ibGib record is
213
+ * left to the compiler. The same goes for how this information is
214
+ * recorded in the dna, if generating dna.
215
+ */
216
+ rel8nsToAddByAddr?: IbGibRel8ns;
217
+ /**
218
+ * Relationships to remove from an ibGib.
219
+ *
220
+ * NOTES:
221
+ * - Moving relationships can be performed by combining add/remove rel8ns.
222
+ * - Attempting to remove a non-existing relationship may or may not cause
223
+ * an error, depending on the compiler.
224
+ */
225
+ rel8nsToRemoveByAddr?: IbGibRel8ns;
226
+ }
227
+ export interface TransformResult<TOut extends IbGib> {
228
+ /**
229
+ * The final result of the transformation
230
+ */
231
+ newIbGib: TOut;
232
+ /**
233
+ * DNA side effects created in the transformation.
234
+ */
235
+ dnas?: TOut[];
236
+ /**
237
+ * If you're performing a transform with multiple steps,
238
+ * then there will be intermediate ibGibs created.
239
+ */
240
+ intermediateIbGibs?: TOut[];
241
+ }
242
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;AACrC,MAAM,CAAC,OAAO,MAAM,GAAG,GAAG,EAAE,GAAG,KAAK,GAAG,MAAM,CAAC;AAC9C;;GAEG;AACH,MAAM,WAAW,QAAQ;IACrB,EAAE,EAAE,EAAE,CAAC;IACP,GAAG,EAAE,GAAG,CAAC;CACZ;AACD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,MAAM,SAAS,GAAG,MAAM,CAAC;AACvC,MAAM,CAAC,OAAO,MAAM,WAAW,GAAG;IAC9B;;;;;;;OAOG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;CACjD,CAAC;AACF;;;GAGG;AACH,MAAM,WAAW,KAAK;IAClB,EAAE,EAAE,EAAE,CAAC;IACP,GAAG,CAAC,EAAE,GAAG,CAAC;CACb;AACD;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,sBAAsB,CAAC,KAAK,GAAG,GAAG,EAAE,OAAO,SAAS,WAAW,GAAG,WAAW,CAAE,SAAQ,KAAK;IACzG;;;OAGG;IACH,IAAI,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IACzB;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC;AACD,MAAM,CAAC,OAAO,MAAM,aAAa,GAAG,MAAM,GA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UG;IACH,YAAY,CAAC,EAAE;QACX,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACtB,CAAC;IACF;;OAEG;IACH,gBAAgB,CAAC,EAAE,QAAQ,CAAC;IAC5B;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AACD,MAAM,WAAW,kBAAkB,CAAC,IAAI,SAAS,KAAK,GAAG,KAAK,CAAE,SAAQ,aAAa,CAAC,IAAI,CAAC;IACvF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;;OASG;IACH,iBAAiB,CAAC,EAAE,WAAW,CAAC;IAChC;;;;;;;OAOG;IACH,oBAAoB,CAAC,EAAE,WAAW,CAAC;CACtC;AAED,MAAM,WAAW,eAAe,CAAC,IAAI,SAAS,KAAK;IAC/C;;OAEG;IACH,QAAQ,EAAE,IAAI,CAAC;IACf;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;IACd;;;OAGG;IACH,kBAAkB,CAAC,EAAE,IAAI,EAAE,CAAC;CAC/B"}
package/dist/types.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.mts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ {
2
+ "srcDir": "dist",
3
+ "srcFiles": [
4
+ "**/*[!spec].mjs"
5
+ ],
6
+ "specDir": "dist",
7
+ "specFiles": [
8
+ "**/*.spec.mjs"
9
+ ],
10
+ "env": {
11
+ "stopSpecOnExpectationFailure": false,
12
+ "stopOnSpecFailure": false,
13
+ "random": true
14
+ },
15
+ "browser": {
16
+ "name": "firefox"
17
+ }
18
+ }
package/jasmine.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "spec_dir": "dist",
3
+ "spec_files": [
4
+ "**/*.spec.mjs"
5
+ ]
6
+ }
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@ibgib/ts-gib",
3
+ "version": "0.4.9",
4
+ "description": "ibgib library with low-level graphing-related substrate functionality, e.g. creating raw ibgibs and transformations. node19+ needed for heavily-used webcrypto hashing isomorphically consumed in node and browsers (apps).",
5
+ "repository": {
6
+ "url": "https://gitlab.com/ibgib/ts-gib",
7
+ "type": "git"
8
+ },
9
+ "funding": {
10
+ "type": "individual",
11
+ "url": "https://paypal.me/ibGib"
12
+ },
13
+ "main": "dist/index.mjs",
14
+ "scripts": {
15
+ "build": "npm run clean && tsc -b tsconfig.json --force",
16
+ "build:test": "npm run clean && tsc -b tsconfig.test.json --force",
17
+ "build:test:noclean": "tsc -b tsconfig.test.json --force",
18
+ "clean": "rm -rf ./dist",
19
+ "test": "npm run test:both",
20
+ "test:both": "npm run build:test && npm run test:node:nobuild && npm run test:browser:nobuild",
21
+ "man:test:both": "use this if you want to test in both node and browser contexts",
22
+ "test:node": "npm run build:test && npx jasmine --config=jasmine.json",
23
+ "man:test:node": "use this if you want to build+test in node",
24
+ "test:node:nobuild": "npx jasmine --config=jasmine.json",
25
+ "man:test:node:nobuild": "use this if you want to test in node but its already built",
26
+ "test:browser": "npm run build:test && npx jasmine-browser-runner runSpecs --config=jasmine-browser.json ",
27
+ "man:test:browser": "use this if you want to build+test only the browser context",
28
+ "test:browser:nobuild": "npx jasmine-browser-runner runSpecs --config=jasmine-browser.json ",
29
+ "man:test:browser:nobuild": "use this if you want to test only the browser context but its already built",
30
+ "test:browser:serve": "npm run build:test && npx jasmine-browser-runner serve --config=jasmine-browser.json ",
31
+ "man:test:browser:serve": "use this if you want to build+test in the browser and don't want the browser to close when your done. (i.e. you're debugging)",
32
+ "test:browser:serve:nobuild": "npx jasmine-browser-runner serve --config=jasmine-browser.json ",
33
+ "man:test:browser:serve:nobuild": "use this if you are troubleshooting existing dist output and don't want to overwrite those files. (and you're debugging in the browser)",
34
+ "pack": "npm pack --pack-destination=\"./published\"",
35
+ "prepare:publish": "npm run clean && npm version patch && npm run build && npm run pack",
36
+ "man:prepare:publish": "use this to patch > build > pack for publishing to npm repo"
37
+ },
38
+ "type": "module",
39
+ "keywords": [
40
+ "ibgib",
41
+ "dlt",
42
+ "blockchain",
43
+ "graph-database"
44
+ ],
45
+ "author": "William Raiford",
46
+ "license": "ISC",
47
+ "devDependencies": {
48
+ "@types/jasmine": "^4.3.1",
49
+ "@types/node": "^16.11.6",
50
+ "jasmine": "^4.5.0",
51
+ "jasmine-browser-runner": "^1.3.0",
52
+ "jasmine-core": "^4.5.0",
53
+ "typescript": "^4.9.5"
54
+ },
55
+ "engines": {
56
+ "node": ">=19.0.0"
57
+ },
58
+ "publishConfig": {
59
+ "access": "public"
60
+ }
61
+ }
@@ -0,0 +1,23 @@
1
+ import { IbGib_V1 } from './types.mjs';
2
+
3
+ export const IB = 'ib';
4
+ export const GIB = 'gib';
5
+ export const ROOT: IbGib_V1 = { ib: IB, gib: GIB, }
6
+ export const IBGIB_DELIMITER = '^';
7
+ /**
8
+ * Gib is often just a single hash for a single ib^gib record.
9
+ * But if the ibgib has a tjp, which implies a timeline ("stream"
10
+ * in some senses), then we will include the tjp gib hash alongside the
11
+ * individual punctilear ibgib frame.
12
+ *
13
+ * ATOW this has the default schema of
14
+ *
15
+ * @example "comment abc^TJPHASH123", "comment abc^TJPHASH123.THISRECORDHASH456"
16
+ */
17
+ export const GIB_DELIMITER = '.';
18
+ export const ROOT_ADDR = 'ib^gib'; // `${IB}${IBGIB_DELIMITER}${GIB}`;
19
+
20
+ /**
21
+ * Some rel8ns should not be able to be renamed or removed.
22
+ */
23
+ export const FORBIDDEN_ADD_RENAME_REMOVE_REL8N_NAMES = ['past', 'ancestor', 'dna', 'tjp'];