spasm.js 1.0.2 → 2.0.0-alpha

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 (123) hide show
  1. package/README.md +454 -113
  2. package/lib.commonjs/convert/convertToEventForSpasmid.d.ts +4 -0
  3. package/lib.commonjs/convert/convertToEventForSpasmid.d.ts.map +1 -0
  4. package/lib.commonjs/convert/convertToEventForSpasmid.js +171 -0
  5. package/lib.commonjs/convert/convertToEventForSpasmid.js.map +1 -0
  6. package/lib.commonjs/convert/convertToSpasm.d.ts +17 -15
  7. package/lib.commonjs/convert/convertToSpasm.d.ts.map +1 -1
  8. package/lib.commonjs/convert/convertToSpasm.js +772 -265
  9. package/lib.commonjs/convert/convertToSpasm.js.map +1 -1
  10. package/lib.commonjs/convert/convertToSpasmEventDatabase.d.ts +4 -0
  11. package/lib.commonjs/convert/convertToSpasmEventDatabase.d.ts.map +1 -0
  12. package/lib.commonjs/convert/convertToSpasmEventDatabase.js +130 -0
  13. package/lib.commonjs/convert/convertToSpasmEventDatabase.js.map +1 -0
  14. package/lib.commonjs/convert/index.d.ts +2 -0
  15. package/lib.commonjs/convert/index.d.ts.map +1 -1
  16. package/lib.commonjs/convert/index.js +5 -1
  17. package/lib.commonjs/convert/index.js.map +1 -1
  18. package/lib.commonjs/id/getSpasmId.d.ts +4 -0
  19. package/lib.commonjs/id/getSpasmId.d.ts.map +1 -0
  20. package/lib.commonjs/id/getSpasmId.js +31 -0
  21. package/lib.commonjs/id/getSpasmId.js.map +1 -0
  22. package/lib.commonjs/id/index.d.ts +2 -0
  23. package/lib.commonjs/id/index.d.ts.map +1 -0
  24. package/lib.commonjs/id/index.js +6 -0
  25. package/lib.commonjs/id/index.js.map +1 -0
  26. package/lib.commonjs/identify/identifyEvent.d.ts.map +1 -1
  27. package/lib.commonjs/identify/identifyEvent.js +13 -5
  28. package/lib.commonjs/identify/identifyEvent.js.map +1 -1
  29. package/lib.commonjs/sort/index.d.ts +2 -0
  30. package/lib.commonjs/sort/index.d.ts.map +1 -0
  31. package/lib.commonjs/sort/index.js +6 -0
  32. package/lib.commonjs/sort/index.js.map +1 -0
  33. package/lib.commonjs/sort/sortEventForSpasmid.d.ts +3 -0
  34. package/lib.commonjs/sort/sortEventForSpasmid.d.ts.map +1 -0
  35. package/lib.commonjs/sort/sortEventForSpasmid.js +15 -0
  36. package/lib.commonjs/sort/sortEventForSpasmid.js.map +1 -0
  37. package/lib.commonjs/spasm.d.ts +5 -3
  38. package/lib.commonjs/spasm.d.ts.map +1 -1
  39. package/lib.commonjs/spasm.js +4 -5
  40. package/lib.commonjs/spasm.js.map +1 -1
  41. package/lib.commonjs/types/index.d.ts +1 -1
  42. package/lib.commonjs/types/index.d.ts.map +1 -1
  43. package/lib.commonjs/types/interfaces.d.ts +468 -90
  44. package/lib.commonjs/types/interfaces.d.ts.map +1 -1
  45. package/lib.commonjs/types/interfaces.js +2 -0
  46. package/lib.commonjs/types/interfaces.js.map +1 -1
  47. package/lib.commonjs/utils/nostrUtils.d.ts +10 -2
  48. package/lib.commonjs/utils/nostrUtils.d.ts.map +1 -1
  49. package/lib.commonjs/utils/nostrUtils.js +122 -22
  50. package/lib.commonjs/utils/nostrUtils.js.map +1 -1
  51. package/lib.commonjs/utils/utils.d.ts +26 -1
  52. package/lib.commonjs/utils/utils.d.ts.map +1 -1
  53. package/lib.commonjs/utils/utils.js +723 -3
  54. package/lib.commonjs/utils/utils.js.map +1 -1
  55. package/lib.esm/convert/convertToEventForSpasmid.d.ts +4 -0
  56. package/lib.esm/convert/convertToEventForSpasmid.d.ts.map +1 -0
  57. package/lib.esm/convert/convertToEventForSpasmid.js +168 -0
  58. package/lib.esm/convert/convertToEventForSpasmid.js.map +1 -0
  59. package/lib.esm/convert/convertToSpasm.d.ts +17 -15
  60. package/lib.esm/convert/convertToSpasm.d.ts.map +1 -1
  61. package/lib.esm/convert/convertToSpasm.js +759 -251
  62. package/lib.esm/convert/convertToSpasm.js.map +1 -1
  63. package/lib.esm/convert/convertToSpasmEventDatabase.d.ts +4 -0
  64. package/lib.esm/convert/convertToSpasmEventDatabase.d.ts.map +1 -0
  65. package/lib.esm/convert/convertToSpasmEventDatabase.js +137 -0
  66. package/lib.esm/convert/convertToSpasmEventDatabase.js.map +1 -0
  67. package/lib.esm/convert/index.d.ts +2 -0
  68. package/lib.esm/convert/index.d.ts.map +1 -1
  69. package/lib.esm/convert/index.js +2 -0
  70. package/lib.esm/convert/index.js.map +1 -1
  71. package/lib.esm/id/getSpasmId.d.ts +4 -0
  72. package/lib.esm/id/getSpasmId.d.ts.map +1 -0
  73. package/lib.esm/id/getSpasmId.js +31 -0
  74. package/lib.esm/id/getSpasmId.js.map +1 -0
  75. package/lib.esm/id/index.d.ts +2 -0
  76. package/lib.esm/id/index.d.ts.map +1 -0
  77. package/lib.esm/id/index.js +2 -0
  78. package/lib.esm/id/index.js.map +1 -0
  79. package/lib.esm/identify/identifyEvent.d.ts.map +1 -1
  80. package/lib.esm/identify/identifyEvent.js +13 -5
  81. package/lib.esm/identify/identifyEvent.js.map +1 -1
  82. package/lib.esm/sort/index.d.ts +2 -0
  83. package/lib.esm/sort/index.d.ts.map +1 -0
  84. package/lib.esm/sort/index.js +2 -0
  85. package/lib.esm/sort/index.js.map +1 -0
  86. package/lib.esm/sort/sortEventForSpasmid.d.ts +3 -0
  87. package/lib.esm/sort/sortEventForSpasmid.d.ts.map +1 -0
  88. package/lib.esm/sort/sortEventForSpasmid.js +17 -0
  89. package/lib.esm/sort/sortEventForSpasmid.js.map +1 -0
  90. package/lib.esm/spasm.d.ts +5 -3
  91. package/lib.esm/spasm.d.ts.map +1 -1
  92. package/lib.esm/spasm.js +4 -2
  93. package/lib.esm/spasm.js.map +1 -1
  94. package/lib.esm/types/index.d.ts +1 -1
  95. package/lib.esm/types/index.d.ts.map +1 -1
  96. package/lib.esm/types/interfaces.d.ts +468 -90
  97. package/lib.esm/types/interfaces.d.ts.map +1 -1
  98. package/lib.esm/types/interfaces.js +2 -0
  99. package/lib.esm/types/interfaces.js.map +1 -1
  100. package/lib.esm/utils/nostrUtils.d.ts +10 -2
  101. package/lib.esm/utils/nostrUtils.d.ts.map +1 -1
  102. package/lib.esm/utils/nostrUtils.js +119 -21
  103. package/lib.esm/utils/nostrUtils.js.map +1 -1
  104. package/lib.esm/utils/utils.d.ts +26 -1
  105. package/lib.esm/utils/utils.d.ts.map +1 -1
  106. package/lib.esm/utils/utils.js +701 -2
  107. package/lib.esm/utils/utils.js.map +1 -1
  108. package/package.json +9 -2
  109. package/src.ts/convert/convertToEventForSpasmid.ts +289 -0
  110. package/src.ts/convert/convertToSpasm.ts +962 -292
  111. package/src.ts/convert/convertToSpasmEventDatabase.ts +204 -0
  112. package/src.ts/convert/index.ts +2 -0
  113. package/src.ts/docs/architecture.md +413 -0
  114. package/src.ts/id/getSpasmId.ts +56 -0
  115. package/src.ts/id/index.ts +1 -0
  116. package/src.ts/identify/identifyEvent.ts +12 -5
  117. package/src.ts/sort/index.ts +1 -0
  118. package/src.ts/sort/sortEventForSpasmid.ts +30 -0
  119. package/src.ts/spasm.ts +5 -3
  120. package/src.ts/types/index.ts +1 -1
  121. package/src.ts/types/interfaces.ts +729 -125
  122. package/src.ts/utils/nostrUtils.ts +150 -22
  123. package/src.ts/utils/utils.ts +1005 -4
@@ -0,0 +1,204 @@
1
+ import {
2
+ UnknownEventV2,
3
+ // EventForSpasmid01,
4
+ SpasmEventV2,
5
+ // SpasmEventBodyAuthorV2,
6
+ // SpasmEventBodyHostV2,
7
+ // SpasmEventBodyLinkV2,
8
+ // SpasmEventMentionV2,
9
+ SpasmEventBodyReferenceV2,
10
+ SpasmEventBodyParentV2,
11
+ SpasmEventDatabaseV2,
12
+ // SpasmEventIdV2,
13
+ } from "./../types/interfaces.js";
14
+
15
+ import { convertToSpasm } from "./convertToSpasm.js"
16
+
17
+ import {
18
+ isObjectWithValues,
19
+ // sortArrayOfStringsAndNumbers,
20
+ // sortArrayOfObjects,
21
+ keepTheseKeysInObject,
22
+ keepTheseKeysInObjectsInArray,
23
+ // sortAuthorsForSpasmid01,
24
+ // sortHostsForSpasmid01,
25
+ // sortLinksForSpasmid01,
26
+ // sortArrayOfObjectsByKeyValue,
27
+ // sortMediasForSpasmid01,
28
+ // sortParentForSpasmid01,
29
+ // sortReferencesForSpasmid01,
30
+ // sortTagsForSpasmid01
31
+ } from "./../utils/utils.js";
32
+
33
+ // Spasm V2
34
+ export const convertToSpasmEventDatabase = (
35
+ unknownEvent: UnknownEventV2,
36
+ dbVersion = "2.0.0"
37
+ ): SpasmEventDatabaseV2 | null => {
38
+
39
+ let spasmEventV2: SpasmEventV2 | null = null
40
+
41
+ // SpasmEventV2
42
+ if (
43
+ 'type' in unknownEvent &&
44
+ unknownEvent.type === "SpasmEventV2"
45
+ ) {
46
+ spasmEventV2 = unknownEvent
47
+ } else {
48
+ spasmEventV2 = convertToSpasm(unknownEvent, "2.0.0")
49
+ }
50
+
51
+ if (!spasmEventV2) return null
52
+
53
+ if (dbVersion === "2.0.0") {
54
+ const spasmEventDatabaseV2 =
55
+ convertSpasmEventV2ToSpasmEventDatabaseV2(
56
+ spasmEventV2
57
+ )
58
+ return spasmEventDatabaseV2
59
+ }
60
+
61
+ return null
62
+ }
63
+
64
+ export const convertSpasmEventV2ToSpasmEventDatabaseV2 = (
65
+ spasmEvent: SpasmEventV2
66
+ ): SpasmEventDatabaseV2 | null => {
67
+
68
+ if (!isObjectWithValues(spasmEvent)) return null
69
+
70
+ if (spasmEvent.type !== "SpasmEventV2") return null
71
+
72
+ const spasmEventDatabase: SpasmEventDatabaseV2 = {
73
+ type: "SpasmEventDatabaseV2"
74
+ }
75
+
76
+ // if (spasmEvent.root) {
77
+ // spasmEventDatabase.root = spasmEvent.root
78
+ // }
79
+
80
+ if (spasmEvent.parent) {
81
+ // Only 'ids' and 'marker' of a parent are used for Spasm ID
82
+ const cleanParent: SpasmEventBodyParentV2 =
83
+ keepTheseKeysInObject(
84
+ spasmEvent.parent, ["ids", "marker"]
85
+ ) as SpasmEventBodyParentV2
86
+
87
+ spasmEventDatabase.parent = cleanParent
88
+ }
89
+
90
+ if (spasmEvent.action) {
91
+ spasmEventDatabase.action = spasmEvent.action
92
+ }
93
+
94
+ if (spasmEvent.title) {
95
+ spasmEventDatabase.title = spasmEvent.title
96
+ }
97
+
98
+ if (spasmEvent.content) {
99
+ spasmEventDatabase.content = spasmEvent.content
100
+ }
101
+
102
+ if (spasmEvent.timestamp) {
103
+ spasmEventDatabase.timestamp = spasmEvent.timestamp
104
+ }
105
+
106
+ if (spasmEvent.authors) {
107
+ spasmEventDatabase.authors = spasmEvent.authors
108
+ }
109
+
110
+ if (spasmEvent.categories) {
111
+ spasmEventDatabase.categories = spasmEvent.categories
112
+ }
113
+
114
+ if (spasmEvent.tips) {
115
+ spasmEventDatabase.tips = spasmEvent.tips
116
+ }
117
+
118
+ if (spasmEvent.hosts) {
119
+ spasmEventDatabase.hosts = spasmEvent.hosts
120
+ }
121
+
122
+ if (spasmEvent.links) {
123
+ spasmEventDatabase.links = spasmEvent.links
124
+ }
125
+
126
+ if (spasmEvent.keywords) {
127
+ spasmEventDatabase.keywords = spasmEvent.keywords
128
+ }
129
+
130
+ if (spasmEvent.tags) {
131
+ spasmEventDatabase.tags = spasmEvent.tags
132
+ }
133
+
134
+ if (spasmEvent.medias) {
135
+ spasmEventDatabase.medias = spasmEvent.medias
136
+ }
137
+
138
+ if (spasmEvent.references) {
139
+ const cleanReferences = keepTheseKeysInObjectsInArray(
140
+ spasmEvent.references, ["ids", "marker"]
141
+ ) as SpasmEventBodyReferenceV2[]
142
+
143
+ spasmEventDatabase.references = cleanReferences
144
+ }
145
+
146
+ if (spasmEvent.mentions) {
147
+ spasmEventDatabase.mentions = spasmEvent.mentions
148
+ }
149
+
150
+ if (spasmEvent.proofs) {
151
+ spasmEventDatabase.proofs = spasmEvent.proofs
152
+ }
153
+
154
+ if (spasmEvent.license) {
155
+ spasmEventDatabase.license = spasmEvent.license
156
+ }
157
+
158
+ if (spasmEvent.language) {
159
+ spasmEventDatabase.language = spasmEvent.language
160
+ }
161
+
162
+ if (spasmEvent.extra) {
163
+ spasmEventDatabase.extra = spasmEvent.extra
164
+ }
165
+
166
+ if (spasmEvent.pows) {
167
+ spasmEventDatabase.pows = spasmEvent.pows
168
+ }
169
+
170
+ if (spasmEvent.ids) {
171
+ spasmEventDatabase.ids = spasmEvent.ids
172
+ }
173
+
174
+ if (spasmEvent.signatures) {
175
+ spasmEventDatabase.signatures = spasmEvent.signatures
176
+ }
177
+
178
+ if (spasmEvent.siblings) {
179
+ spasmEventDatabase.siblings = spasmEvent.siblings
180
+ }
181
+
182
+ if (spasmEvent.source) {
183
+ spasmEventDatabase.source = spasmEvent.source
184
+ }
185
+
186
+ if (spasmEvent.sharedBy) {
187
+ spasmEventDatabase.sharedBy = spasmEvent.sharedBy
188
+ }
189
+
190
+ /**
191
+ * SpasmEventDatabaseV2 is used for saving an event into the
192
+ * database, so 'stats' should not be included because they
193
+ * should be calculated separately on each instance even if
194
+ * the instance syncs reactions with other instances (not
195
+ * recommended).
196
+ * Database-related data should not be included either, e.g.,
197
+ * db.key, db.addedTimestamp, updatedTimestamp, db.table.
198
+ */
199
+ // if (spasmEvent.stats) {
200
+ // spasmEventDatabase.stats = spasmEvent.stats
201
+ // }
202
+
203
+ return spasmEventDatabase
204
+ }
@@ -1 +1,3 @@
1
1
  export { convertToSpasm } from "./convertToSpasm.js"
2
+ export { convertToEventForSpasmid } from "./convertToEventForSpasmid.js"
3
+ export { convertToSpasmEventDatabase } from "./convertToSpasmEventDatabase.js"
@@ -0,0 +1,413 @@
1
+ See the full list of properties of `SpasmEvent` at `./src.ts/types/interfaces.ts`.
2
+
3
+ Here is a schema of the SpasmEventV2 interface:
4
+
5
+ ```
6
+ #01 = EventForSpasmid01
7
+ SE = SpasmEvent
8
+ Body = SpasmEventBody
9
+ Env = SpasmEventEnvelope
10
+ Tree = SpasmEventEnvelopeWithTree
11
+ DB = SpasmEventDatabase
12
+
13
+ event*
14
+
15
+ ├── type --- SE Body Env Tree DB
16
+ ├── protocol (+ sibling) --- -- Body --- ---- --
17
+ │ ├── name --- -- Body --- ---- --
18
+ │ └── version --- -- Body --- ---- --
19
+ ├── root --- SE ---- --- Tree --
20
+ │ ├── ids[] --- SE ---- --- Tree --
21
+ │ ├── marker --- SE ---- --- Tree --
22
+ │ ├── depth --- SE ---- --- Tree --
23
+ │ └── event* --- SE ---- --- Tree --
24
+ ├── parent #01 SE Body --- Tree DB
25
+ │ ├── ids[] #01 SE Body --- Tree DB
26
+ │ ├── marker #01 SE Body --- Tree DB
27
+ │ ├── depth --- SE ---- --- Tree --
28
+ │ └── event* --- SE ---- --- Tree --
29
+ ├── action #01 SE Body --- ---- DB
30
+ ├── title #01 SE Body --- ---- DB
31
+ ├── content #01 SE Body --- ---- DB
32
+ ├── timestamp #01 SE Body --- ---- DB
33
+ ├── authors[] #01 SE Body --- ---- DB
34
+ │ ├── addresses[] #01 SE Body --- ---- DB
35
+ │ │ ├── value #01 SE Body --- ---- DB
36
+ │ │ ├── format #01 SE Body --- ---- DB
37
+ │ │ │ ├── name #01 SE Body --- ---- DB
38
+ │ │ │ └── version #01 SE Body --- ---- DB
39
+ │ │ ├── hosts[] --- SE Body --- ---- DB
40
+ │ │ └── verified --- SE ---- --- ---- DB
41
+ │ ├── usernames[] (eg RSS posts) #01 SE Body --- ---- DB
42
+ │ │ ├── value #01 SE Body --- ---- DB
43
+ │ │ ├── protocol #01 SE Body --- ---- DB
44
+ │ │ ├── proof #01 SE Body --- ---- DB
45
+ │ │ └── provider #01 SE Body --- ---- DB
46
+ │ └── marker #01 SE Body --- ---- DB
47
+ ├── categories[] #01 SE Body --- ---- DB
48
+ │ ├── name #01 SE Body --- ---- DB
49
+ │ └── sub (recursive category) #01 SE Body --- ---- DB
50
+ ├── tips[] #01 SE Body --- ---- DB
51
+ │ ├── address #01 SE Body --- ---- DB
52
+ │ ├── text #01 SE Body --- ---- DB
53
+ │ ├── expiration #01 SE Body --- ---- DB
54
+ │ │ └── timestamp #01 SE Body --- ---- DB
55
+ │ ├── currency #01 SE Body --- ---- DB
56
+ │ │ ├── name #01 SE Body --- ---- DB
57
+ │ │ └── ticker #01 SE Body --- ---- DB
58
+ │ └── network #01 SE Body --- ---- DB
59
+ │ ├── name #01 SE Body --- ---- DB
60
+ │ └── id #01 SE Body --- ---- DB
61
+ ├── hosts[] (see hosts below) #01 SE Body --- ---- DB
62
+ ├── links[] (see link below) #01 SE Body --- ---- DB
63
+ ├── keywords[] #01 SE Body --- ---- DB
64
+ ├── tags[] #01 SE Body --- ---- DB
65
+ ├── medias[] #01 SE Body --- ---- DB
66
+ │ ├── hashes[] (see hash below) #01 SE Body --- ---- DB
67
+ │ ├── links[] (see link below) #01 SE Body --- ---- DB
68
+ │ └── type #01 SE Body --- ---- DB
69
+ ├── references[] #01 SE Body --- Tree DB
70
+ │ ├── ids[] #01 SE Body --- Tree DB
71
+ │ ├── marker #01 SE Body --- Tree DB
72
+ │ └── event* --- SE ---- --- Tree --
73
+ ├── mentions[] #01 SE Body --- ---- DB
74
+ │ ├── addresses[] #01 SE Body --- ---- DB
75
+ │ │ ├── value #01 SE Body --- ---- DB
76
+ │ │ ├── format #01 SE Body --- ---- DB
77
+ │ │ │ ├── name #01 SE Body --- ---- DB
78
+ │ │ │ └── version #01 SE Body --- ---- DB
79
+ │ │ └── hosts[] --- SE Body --- ---- DB
80
+ │ ├── usernames[] #01 SE Body --- ---- DB
81
+ │ │ ├── value #01 SE Body --- ---- DB
82
+ │ │ ├── protocol #01 SE Body --- ---- DB
83
+ │ │ ├── proof #01 SE Body --- ---- DB
84
+ │ │ └── provider #01 SE Body --- ---- DB
85
+ │ └── marker #01 SE Body --- ---- DB
86
+ ├── proofs[] #01 SE Body --- ---- DB
87
+ │ ├── value #01 SE Body --- ---- DB
88
+ │ ├── links[] #01 SE Body --- ---- DB
89
+ │ └── protocol #01 SE Body --- ---- DB
90
+ │ ├── name #01 SE Body --- ---- DB
91
+ │ └── version #01 SE Body --- ---- DB
92
+ ├── previousEvent (+ sibling) --- -- Body --- ---- --
93
+ │ ├── ids[] --- -- Body --- ---- --
94
+ │ ├── marker --- -- Body --- ---- --
95
+ │ ├── depth --- -- Body --- ---- --
96
+ │ └── event* --- -- ---- --- ---- --
97
+ ├── sequence (+ sibling) --- -- Body --- ---- --
98
+ ├── license #01 SE Body --- ---- DB
99
+ ├── language #01 SE Body --- ---- DB
100
+ ├── extra #01 SE Body --- ---- DB
101
+ ├── pows (only 1 in body) --- SE Body --- ---- DB
102
+ │ ├── marker --- SE Body --- ---- DB
103
+ │ ├── nonce --- SE Body --- ---- DB
104
+ │ ├── difficulty --- SE Body --- ---- DB
105
+ │ ├── words[] --- SE Body --- ---- DB
106
+ │ └── network --- SE Body --- ---- DB
107
+ │ ├── name --- SE Body --- ---- DB
108
+ │ └── id --- SE Body --- ---- DB
109
+
110
+ ├── ids[] --- SE ---- Env Tree DB
111
+ ├── signatures[] --- SE ---- Env Tree DB
112
+ │ ├── value --- SE ---- Env Tree DB
113
+ │ ├── pubkey --- SE ---- Env Tree DB
114
+ │ └── format --- SE ---- Env Tree DB
115
+ │ ├── name --- SE ---- Env Tree DB
116
+ │ └── version --- SE ---- Env Tree DB
117
+
118
+ ├── siblings[] --- SE ---- Env Tree DB
119
+ │ ├── type --- SE ---- Env Tree DB
120
+ │ ├── signedString --- SE ---- Env Tree DB
121
+ │ ├── originalObject --- SE ---- Env Tree DB
122
+ │ ├── signatures[] --- SE ---- Env Tree DB
123
+ │ │ ├── value --- SE ---- Env Tree DB
124
+ │ │ ├── pubkey --- SE ---- Env Tree DB
125
+ │ │ └── format --- SE ---- Env Tree DB
126
+ │ │ ├── name --- SE ---- Env Tree DB
127
+ │ │ └── version --- SE ---- Env Tree DB
128
+ │ ├── sequence --- SE ---- Env Tree DB
129
+ │ ├── previousEvent --- SE ---- Env Tree DB
130
+ │ │ ├── ids[] --- SE ---- Env Tree DB
131
+ │ │ ├── marker --- SE ---- Env Tree DB
132
+ │ │ ├── depth --- SE ---- Env Tree DB
133
+ │ │ └── event* --- SE ---- --- Tree DB
134
+ │ └── protocol --- SE ---- Env Tree DB
135
+ │ ├── name --- SE ---- Env Tree DB
136
+ │ ├── version --- SE ---- Env Tree DB
137
+ │ ├── hasExtraSpasmFields --- SE ---- Env Tree DB
138
+ │ └── extraSpasmFieldsVersion --- SE ---- Env Tree DB
139
+
140
+ ├── db* --- SE ---- Env Tree DB
141
+ │ ├── key* --- SE ---- Env Tree DB
142
+ │ ├── addedTimestamp* --- SE ---- Env Tree DB
143
+ │ ├── updatedTimestamp* --- SE ---- Env Tree DB
144
+ │ └── table* --- SE ---- Env Tree DB
145
+ ├── source --- SE ---- Env Tree DB
146
+ │ ├── name --- SE ---- Env Tree DB
147
+ │ ├── uiUrl --- SE ---- Env Tree DB
148
+ │ ├── apiUrl --- SE ---- Env Tree DB
149
+ │ ├── query --- SE ---- Env Tree DB
150
+ │ └── showSource --- SE ---- Env Tree DB
151
+ ├── stats[] --- SE ---- Env Tree DB
152
+ │ ├── action --- SE ---- Env Tree DB
153
+ │ ├── total --- SE ---- Env Tree DB
154
+ │ ├── latestTimestamp --- SE ---- Env Tree DB
155
+ │ ├── latestDbTimestamp --- SE ---- Env Tree DB
156
+ │ └── ...(upvote, downvote, etc.) --- SE ---- Env Tree DB
157
+ ├── sharedBy[] --- SE ---- Env Tree DB
158
+ │ └── ids[] --- SE ---- Env Tree DB
159
+
160
+ │ (Envelope with tree)
161
+ ├── root --- SE ---- Env Tree --
162
+ │ └── event --- SE ---- Env Tree --
163
+ ├── parent --- SE ---- Env Tree --
164
+ │ └── event --- SE ---- Env Tree --
165
+ ├── references[] --- SE ---- Env Tree --
166
+ │ └── event --- SE ---- Env Tree --
167
+ └── children[] --- SE ---- Env Tree --
168
+ └── SE | Env | Tree --- SE ---- Env Tree --
169
+
170
+ id
171
+ ├── value #.
172
+ ├── format #.
173
+ │ ├── name
174
+ │ └── version
175
+ └── hosts[]
176
+
177
+ hash
178
+ ├── value
179
+ ├── name
180
+ ├── length
181
+ ├── type
182
+ ├── pieceLength
183
+ └── pieces[]
184
+
185
+ link
186
+ ├── value
187
+ ├── protocol
188
+ ├── origin
189
+ ├── host
190
+ ├── pathname
191
+ ├── search
192
+ ├── port
193
+ └── originalProtocolKey
194
+
195
+ ```
196
+
197
+
198
+
199
+ ```
200
+ event.type
201
+ event.ids
202
+ id.value
203
+ id.format.name
204
+ id.format.version
205
+ id.hosts
206
+ host.value
207
+ host.marker
208
+ event.db.key
209
+ event.db.addedTimestamp
210
+ event.db.updatedTimestamp
211
+ event.db.table
212
+ event.root.ids
213
+ event.root.hosts
214
+ event.root.depth
215
+ event.root.event
216
+ event.parent.ids
217
+ event.parent.hosts
218
+ event.parent.depth
219
+ event.parent.event
220
+ event.action
221
+ event.title
222
+ event.content
223
+ event.source
224
+ event.timestamp
225
+ event.authors
226
+ author.addresses
227
+ address.value
228
+ address.format.name
229
+ address.format.version
230
+ author.usernames
231
+ username.value
232
+ username.protocol
233
+ username.proof
234
+ username.provider
235
+ event.categories
236
+ category.name
237
+ category.sub.name
238
+ category.sub.sub.name
239
+ event.tips
240
+ tip.address
241
+ tip.text
242
+ tip.expiration.timestamp
243
+ tip.currency.name
244
+ tip.currency.ticker
245
+ tip.network.name
246
+ tip.network.id
247
+ event.hosts
248
+ host.value
249
+ host.marker
250
+ event.links
251
+ link.value
252
+ link.marker
253
+ event.keywords
254
+ event.tags
255
+ event.medias
256
+ media.ids
257
+ media.hashes
258
+ media.links
259
+ media.type
260
+ event.references
261
+ reference.ids
262
+ reference.hosts
263
+ reference.depth
264
+ reference.event
265
+ event.mentions
266
+ mention.addresses
267
+ address.value
268
+ address.format.name
269
+ address.format.version
270
+ mention.usernames
271
+ username.value
272
+ username.protocol
273
+ username.proof
274
+ username.provider
275
+ event.proofs
276
+ proof.value
277
+ proof.links
278
+ proof.protocol.name
279
+ proof.protocol.version
280
+ event.previousEvent.ids
281
+ event.previousEvent.hosts
282
+ event.previousEvent.depth
283
+ event.previousEvent.event
284
+ event.sequence
285
+ event.license
286
+ event.language
287
+ event.extra
288
+ event.pows
289
+ pow.nonce
290
+ pow.difficulty
291
+ pow.words
292
+ pow.network.name
293
+ pow.network.id
294
+
295
+ event.source.name
296
+ event.source.uiUrl
297
+ event.source.apiUrl
298
+ event.source.query
299
+ event.source.showSource
300
+ event.siblings
301
+ sibling.type
302
+ sibling.ids
303
+ sibling.signedString
304
+ sibling.signatures
305
+ sibling.protocol.name
306
+ sibling.protocol.version
307
+ sibling.protocol.hasExtraSpasmFields
308
+ sibling.protocol.extraSpasmFieldsVersion
309
+ sibling.previousEvent
310
+ sibling.sequence
311
+
312
+ event.stats
313
+ stat.action
314
+ stat.total
315
+ stat.latestTimestamp
316
+ stat.latestDbTimestamp
317
+ stat.contents
318
+ content.value
319
+ content.total
320
+
321
+ event.sharedBy.ids
322
+ ```
323
+
324
+
325
+ ```
326
+ EventBodyForSpasmid01
327
+ - all standardized signed key-value pairs to calculate spasmid01
328
+ - similar to SpasmEventBodyV2, but without type, protocol, pows
329
+
330
+ SpasmEventBodyV2
331
+ - all standardized signed key-value pairs
332
+
333
+ SpasmEventEnvelopeV2
334
+ - ids
335
+ - signatures
336
+ - siblings with signed strings and objects
337
+ - database info
338
+ - source
339
+ - stats
340
+ - sharedBy
341
+
342
+ SpasmEventEnvelopeWithTreeV2
343
+ - ...SpasmEventEnvelopeV2
344
+ - children, parent.event, root.event, reference.event
345
+
346
+ ---
347
+
348
+ SpasmEventEnvelopeExpandedV2
349
+ - SpasmEnvelope
350
+ - extra meta data for each sibling
351
+ - extra data for all key-value pairs
352
+
353
+ SpasmEventDatabaseV2
354
+ - ...SpasmBodyV2
355
+ - ...SpasmEnvelopeV2 (without tree)
356
+
357
+ SpasmEventV2
358
+ - ...spasm body expanded
359
+ - ...spasm envelope expanded
360
+ - ...spasm tree expanded
361
+
362
+ SpasmEvent
363
+ SpasmEventBody
364
+ SpasmEventEnvelope
365
+ SpasmEventEnvelopeWithTree
366
+
367
+ SpasmEventTree
368
+ SpasmEventDatabase
369
+
370
+ SpasmEvent
371
+ Body (+expansion)
372
+ Envelope (+expansion)
373
+ Tree (+expansion)
374
+
375
+ === submit event ===
376
+ Client:
377
+ ---
378
+ + SpasmEventBody
379
+ + Ethereum & Nostr addresses
380
+ ! SpasmEventBody > SpasmEventEnvelope (sign)
381
+ ---
382
+ + NostrEvent
383
+ + Ethereum address (tags)
384
+ + SpasmId (tags) - optional for search in Nostr network
385
+ > NostrEvent > EventBodyForSpasmid01
386
+ ! NostrEvent > NostrEventSignedOpened (sign)
387
+ > NostrEventSignedOpened > SpasmEventEnvelope
388
+ ---
389
+ = SpasmEventEnvelope[] (Dmp + Nostr) = SpasmEventEnvelope (merge)
390
+ > SpasmEventEnvelope > server
391
+ ---
392
+ Server:
393
+ > SpasmEventEnvelope > SpasmEventDatabase (expand)
394
+ > SpasmEventDatabase > database (insert)
395
+ ----------------
396
+ === get feed ===
397
+ Server:
398
+ > database > SpasmEventDatabase[] (get)
399
+ > SpasmEventDatabase[] > SpasmEventEnvelope[] (compress)
400
+ > SpasmEventEnvelope[] > client
401
+ ---
402
+ Client:
403
+ > SpasmEventEnvelope[] > SpasmEvent[]
404
+ > SpasmEvent[] > feed
405
+ ----------------
406
+ === get comments/parent/root ===
407
+ Server:
408
+ > database > SpasmEventEnvelopeWithTree (get)
409
+ > SpasmEventEnvelopeWithTree > client
410
+ ---
411
+ Client:
412
+ > SpasmEventEnvelopeWithTree > comments/parent/root
413
+ ```
@@ -0,0 +1,56 @@
1
+ import {
2
+ EventForSpasmid01,
3
+ // SpasmEventBodyAuthorV2,
4
+ SpasmEventV2,
5
+ } from "./../types/interfaces.js";
6
+
7
+ import {
8
+ isObjectWithValues,
9
+ getHashOfString,
10
+ // sortArrayOfStringsAndNumbers,
11
+ // sortArrayOfObjects,
12
+ // sortAuthorsForSpasmid01,
13
+ // keepTheseKeysInObjectsInArray
14
+ } from "./../utils/utils.js";
15
+
16
+ import {
17
+ convertToEventForSpasmid
18
+ } from "./../convert/convertToEventForSpasmid.js";
19
+
20
+ // import {
21
+ // sortEventForSpasmid
22
+ // } from "./../sort/sortEventForSpasmid.js";
23
+
24
+ export const getSpasmId = (
25
+ spasmEvent: SpasmEventV2,
26
+ idVersion = "01"
27
+ ): string | null => {
28
+ if (idVersion === "01") {
29
+ return getSpasmId01(spasmEvent)
30
+ }
31
+ return null
32
+ }
33
+
34
+ export const getSpasmId01 = (
35
+ spasmEvent: SpasmEventV2
36
+ ): string | null => {
37
+
38
+ if (!isObjectWithValues(spasmEvent)) return null
39
+
40
+ if (spasmEvent.type !== "SpasmEventV2") return null
41
+
42
+ const eventForSpasmid: EventForSpasmid01 | null =
43
+ convertToEventForSpasmid(spasmEvent, "01")
44
+
45
+ if (!eventForSpasmid) return null
46
+
47
+ const stringForId = JSON.stringify(eventForSpasmid)
48
+
49
+ const hash = getHashOfString(stringForId)
50
+
51
+ const spasmId = "spasmid01" + hash
52
+
53
+ // TODO write test for double-signed events
54
+
55
+ return spasmId
56
+ }
@@ -0,0 +1 @@
1
+ export { getSpasmId } from "./getSpasmId.js"