@comapeo/core 1.0.0

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 (186) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +31 -0
  3. package/dist/blob-api.d.ts +92 -0
  4. package/dist/blob-api.d.ts.map +1 -0
  5. package/dist/blob-store/index.d.ts +163 -0
  6. package/dist/blob-store/index.d.ts.map +1 -0
  7. package/dist/blob-store/live-download.d.ts +107 -0
  8. package/dist/blob-store/live-download.d.ts.map +1 -0
  9. package/dist/config-import.d.ts +74 -0
  10. package/dist/config-import.d.ts.map +1 -0
  11. package/dist/constants.d.ts +14 -0
  12. package/dist/constants.d.ts.map +1 -0
  13. package/dist/core-manager/bitfield-rle.d.ts +25 -0
  14. package/dist/core-manager/bitfield-rle.d.ts.map +1 -0
  15. package/dist/core-manager/core-index.d.ts +56 -0
  16. package/dist/core-manager/core-index.d.ts.map +1 -0
  17. package/dist/core-manager/index.d.ts +125 -0
  18. package/dist/core-manager/index.d.ts.map +1 -0
  19. package/dist/core-manager/random-access-file-pool.d.ts +17 -0
  20. package/dist/core-manager/random-access-file-pool.d.ts.map +1 -0
  21. package/dist/core-manager/remote-bitfield.d.ts +146 -0
  22. package/dist/core-manager/remote-bitfield.d.ts.map +1 -0
  23. package/dist/core-ownership.d.ts +112 -0
  24. package/dist/core-ownership.d.ts.map +1 -0
  25. package/dist/datastore/index.d.ts +91 -0
  26. package/dist/datastore/index.d.ts.map +1 -0
  27. package/dist/datatype/index.d.ts +108 -0
  28. package/dist/discovery/local-discovery.d.ts +64 -0
  29. package/dist/discovery/local-discovery.d.ts.map +1 -0
  30. package/dist/errors.d.ts +4 -0
  31. package/dist/errors.d.ts.map +1 -0
  32. package/dist/fastify-controller.d.ts +27 -0
  33. package/dist/fastify-controller.d.ts.map +1 -0
  34. package/dist/fastify-plugins/blobs.d.ts +6 -0
  35. package/dist/fastify-plugins/blobs.d.ts.map +1 -0
  36. package/dist/fastify-plugins/constants.d.ts +3 -0
  37. package/dist/fastify-plugins/constants.d.ts.map +1 -0
  38. package/dist/fastify-plugins/icons.d.ts +6 -0
  39. package/dist/fastify-plugins/icons.d.ts.map +1 -0
  40. package/dist/fastify-plugins/maps/index.d.ts +11 -0
  41. package/dist/fastify-plugins/maps/index.d.ts.map +1 -0
  42. package/dist/fastify-plugins/maps/offline-fallback-map.d.ts +12 -0
  43. package/dist/fastify-plugins/maps/offline-fallback-map.d.ts.map +1 -0
  44. package/dist/fastify-plugins/maps/static-maps.d.ts +11 -0
  45. package/dist/fastify-plugins/maps/static-maps.d.ts.map +1 -0
  46. package/dist/fastify-plugins/utils.d.ts +23 -0
  47. package/dist/fastify-plugins/utils.d.ts.map +1 -0
  48. package/dist/generated/extensions.d.ts +44 -0
  49. package/dist/generated/extensions.d.ts.map +1 -0
  50. package/dist/generated/keys.d.ts +36 -0
  51. package/dist/generated/keys.d.ts.map +1 -0
  52. package/dist/generated/rpc.d.ts +87 -0
  53. package/dist/generated/rpc.d.ts.map +1 -0
  54. package/dist/icon-api.d.ts +109 -0
  55. package/dist/icon-api.d.ts.map +1 -0
  56. package/dist/index-writer/index.d.ts +51 -0
  57. package/dist/index-writer/index.d.ts.map +1 -0
  58. package/dist/index.d.ts +14 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/invite-api.d.ts +70 -0
  61. package/dist/invite-api.d.ts.map +1 -0
  62. package/dist/lib/hashmap.d.ts +62 -0
  63. package/dist/lib/hashmap.d.ts.map +1 -0
  64. package/dist/lib/hypercore-helpers.d.ts +6 -0
  65. package/dist/lib/hypercore-helpers.d.ts.map +1 -0
  66. package/dist/lib/noise-secret-stream-helpers.d.ts +45 -0
  67. package/dist/lib/noise-secret-stream-helpers.d.ts.map +1 -0
  68. package/dist/lib/ponyfills.d.ts +10 -0
  69. package/dist/lib/ponyfills.d.ts.map +1 -0
  70. package/dist/lib/string.d.ts +2 -0
  71. package/dist/lib/string.d.ts.map +1 -0
  72. package/dist/lib/timing-safe-equal.d.ts +15 -0
  73. package/dist/lib/timing-safe-equal.d.ts.map +1 -0
  74. package/dist/local-peers.d.ts +151 -0
  75. package/dist/local-peers.d.ts.map +1 -0
  76. package/dist/logger.d.ts +32 -0
  77. package/dist/logger.d.ts.map +1 -0
  78. package/dist/mapeo-manager.d.ts +178 -0
  79. package/dist/mapeo-manager.d.ts.map +1 -0
  80. package/dist/mapeo-project.d.ts +3233 -0
  81. package/dist/mapeo-project.d.ts.map +1 -0
  82. package/dist/member-api.d.ts +114 -0
  83. package/dist/member-api.d.ts.map +1 -0
  84. package/dist/roles.d.ts +157 -0
  85. package/dist/roles.d.ts.map +1 -0
  86. package/dist/schema/client.d.ts +284 -0
  87. package/dist/schema/client.d.ts.map +1 -0
  88. package/dist/schema/project.d.ts +1812 -0
  89. package/dist/schema/project.d.ts.map +1 -0
  90. package/dist/schema/schema-to-drizzle.d.ts +20 -0
  91. package/dist/schema/schema-to-drizzle.d.ts.map +1 -0
  92. package/dist/schema/types.d.ts +98 -0
  93. package/dist/schema/types.d.ts.map +1 -0
  94. package/dist/schema/utils.d.ts +55 -0
  95. package/dist/schema/utils.d.ts.map +1 -0
  96. package/dist/sync/core-sync-state.d.ts +252 -0
  97. package/dist/sync/core-sync-state.d.ts.map +1 -0
  98. package/dist/sync/namespace-sync-state.d.ts +47 -0
  99. package/dist/sync/namespace-sync-state.d.ts.map +1 -0
  100. package/dist/sync/peer-sync-controller.d.ts +44 -0
  101. package/dist/sync/peer-sync-controller.d.ts.map +1 -0
  102. package/dist/sync/sync-api.d.ts +158 -0
  103. package/dist/sync/sync-api.d.ts.map +1 -0
  104. package/dist/sync/sync-state.d.ts +40 -0
  105. package/dist/sync/sync-state.d.ts.map +1 -0
  106. package/dist/translation-api.d.ts +288 -0
  107. package/dist/translation-api.d.ts.map +1 -0
  108. package/dist/types.d.ts +115 -0
  109. package/dist/types.d.ts.map +1 -0
  110. package/dist/utils.d.ts +115 -0
  111. package/dist/utils.d.ts.map +1 -0
  112. package/dist/utils_types.d.ts +14 -0
  113. package/drizzle/client/0000_bumpy_carnage.sql +33 -0
  114. package/drizzle/client/meta/0000_snapshot.json +199 -0
  115. package/drizzle/client/meta/_journal.json +13 -0
  116. package/drizzle/project/0000_spooky_lady_ursula.sql +192 -0
  117. package/drizzle/project/meta/0000_snapshot.json +1137 -0
  118. package/drizzle/project/meta/_journal.json +13 -0
  119. package/package.json +202 -0
  120. package/src/blob-api.js +139 -0
  121. package/src/blob-store/index.js +325 -0
  122. package/src/blob-store/live-download.js +373 -0
  123. package/src/config-import.js +604 -0
  124. package/src/constants.js +34 -0
  125. package/src/core-manager/bitfield-rle.js +235 -0
  126. package/src/core-manager/core-index.js +87 -0
  127. package/src/core-manager/index.js +504 -0
  128. package/src/core-manager/random-access-file-pool.js +30 -0
  129. package/src/core-manager/remote-bitfield.js +416 -0
  130. package/src/core-ownership.js +235 -0
  131. package/src/datastore/README.md +46 -0
  132. package/src/datastore/index.js +234 -0
  133. package/src/datatype/README.md +33 -0
  134. package/src/datatype/index.d.ts +108 -0
  135. package/src/datatype/index.js +358 -0
  136. package/src/discovery/local-discovery.js +303 -0
  137. package/src/errors.js +5 -0
  138. package/src/fastify-controller.js +84 -0
  139. package/src/fastify-plugins/blobs.js +139 -0
  140. package/src/fastify-plugins/constants.js +5 -0
  141. package/src/fastify-plugins/icons.js +158 -0
  142. package/src/fastify-plugins/maps/index.js +173 -0
  143. package/src/fastify-plugins/maps/offline-fallback-map.js +114 -0
  144. package/src/fastify-plugins/maps/static-maps.js +271 -0
  145. package/src/fastify-plugins/utils.js +52 -0
  146. package/src/generated/README.md +3 -0
  147. package/src/generated/extensions.d.ts +44 -0
  148. package/src/generated/extensions.js +196 -0
  149. package/src/generated/extensions.ts +237 -0
  150. package/src/generated/keys.d.ts +36 -0
  151. package/src/generated/keys.js +148 -0
  152. package/src/generated/keys.ts +185 -0
  153. package/src/generated/rpc.d.ts +87 -0
  154. package/src/generated/rpc.js +389 -0
  155. package/src/generated/rpc.ts +463 -0
  156. package/src/icon-api.js +282 -0
  157. package/src/index-writer/README.md +38 -0
  158. package/src/index-writer/index.js +124 -0
  159. package/src/index.js +16 -0
  160. package/src/invite-api.js +450 -0
  161. package/src/lib/hashmap.js +91 -0
  162. package/src/lib/hypercore-helpers.js +18 -0
  163. package/src/lib/noise-secret-stream-helpers.js +37 -0
  164. package/src/lib/ponyfills.js +25 -0
  165. package/src/lib/string.js +7 -0
  166. package/src/lib/timing-safe-equal.js +34 -0
  167. package/src/local-peers.js +737 -0
  168. package/src/logger.js +99 -0
  169. package/src/mapeo-manager.js +914 -0
  170. package/src/mapeo-project.js +980 -0
  171. package/src/member-api.js +319 -0
  172. package/src/roles.js +412 -0
  173. package/src/schema/client.js +55 -0
  174. package/src/schema/project.js +44 -0
  175. package/src/schema/schema-to-drizzle.js +118 -0
  176. package/src/schema/types.ts +153 -0
  177. package/src/schema/utils.js +51 -0
  178. package/src/sync/core-sync-state.js +440 -0
  179. package/src/sync/namespace-sync-state.js +193 -0
  180. package/src/sync/peer-sync-controller.js +332 -0
  181. package/src/sync/sync-api.js +588 -0
  182. package/src/sync/sync-state.js +63 -0
  183. package/src/translation-api.js +141 -0
  184. package/src/types.ts +149 -0
  185. package/src/utils.js +210 -0
  186. package/src/utils_types.d.ts +14 -0
@@ -0,0 +1,271 @@
1
+ import path from 'path'
2
+ import fs from 'fs/promises'
3
+ import FastifyStatic from '@fastify/static'
4
+ import fp from 'fastify-plugin'
5
+ import { Type as T } from '@sinclair/typebox'
6
+ import asar from '@electron/asar'
7
+ import { Mime } from 'mime/lite'
8
+ import standardTypes from 'mime/types/standard.js'
9
+
10
+ import {
11
+ NotFoundError,
12
+ createStyleJsonResponseHeaders,
13
+ getFastifyServerAddress,
14
+ } from '../utils.js'
15
+
16
+ export const PLUGIN_NAME = 'mapeo-static-maps'
17
+
18
+ export const plugin = fp(staticMapsPlugin, {
19
+ fastify: '4.x',
20
+ name: PLUGIN_NAME,
21
+ })
22
+
23
+ /**
24
+ * @typedef {object} StaticMapsPluginOpts
25
+ * @property {string} [prefix]
26
+ * @property {string} staticRootDir
27
+ */
28
+
29
+ /**
30
+ * @typedef {object} StaticMapsPluginDecorator
31
+ * @property {(styleId: string, serverAddress: string) => Promise<string>} getResolvedStyleJson
32
+ * @property {(styleId: string) => Promise<import('node:fs').Stats>} getStyleJsonStats
33
+ */
34
+
35
+ /** @type {import('fastify').FastifyPluginAsync<StaticMapsPluginOpts>} */
36
+ async function staticMapsPlugin(fastify, opts) {
37
+ fastify.decorate('mapeoStaticMaps', {
38
+ async getResolvedStyleJson(styleId, serverAddress) {
39
+ const filePath = path.join(opts.staticRootDir, styleId, 'style.json')
40
+
41
+ const data = await fs.readFile(filePath, 'utf-8')
42
+
43
+ return data.replace(
44
+ /\{host\}/gm,
45
+ new URL(`${opts.prefix || ''}/${styleId}`, serverAddress).href
46
+ )
47
+ },
48
+ async getStyleJsonStats(styleId) {
49
+ const filePath = path.join(opts.staticRootDir, styleId, 'style.json')
50
+ const stats = await fs.stat(filePath)
51
+ return stats
52
+ },
53
+ })
54
+
55
+ fastify.register(routes, {
56
+ prefix: opts.prefix,
57
+ staticRootDir: opts.staticRootDir,
58
+ })
59
+ }
60
+
61
+ const GetStaticMapTileParamsSchema = T.Object({
62
+ styleId: T.String(),
63
+ tileId: T.String(),
64
+ z: T.Number(),
65
+ y: T.Number(),
66
+ x: T.Number(),
67
+ ext: T.Optional(T.String()),
68
+ })
69
+
70
+ const ListStaticMapsReplySchema = T.Array(
71
+ T.Object({
72
+ id: T.String(),
73
+ name: T.Union([T.String(), T.Null()]),
74
+ styleUrl: T.String(),
75
+ })
76
+ )
77
+
78
+ const GetStyleJsonParamsSchema = T.Object({
79
+ styleId: T.String(),
80
+ })
81
+
82
+ /** @type {import('fastify').FastifyPluginAsync<StaticMapsPluginOpts, import('fastify').RawServerDefault, import('@fastify/type-provider-typebox').TypeBoxTypeProvider>} */
83
+ async function routes(fastify, opts) {
84
+ const { staticRootDir } = opts
85
+
86
+ /**
87
+ * @param {import('fastify').FastifyRequest<{Params: import('@sinclair/typebox').Static<typeof GetStaticMapTileParamsSchema>}>} req
88
+ * @param {import('fastify').FastifyReply} rep
89
+ */
90
+ async function handleStyleTileGet(req, rep) {
91
+ const result = getStyleTileInfo(staticRootDir, req.params)
92
+
93
+ if (!result) {
94
+ const { tileId, z, x, y, ext } = req.params
95
+ throw new NotFoundError(
96
+ `Tileset id = ${tileId}, ext=${ext}, [${z}, ${x}, ${y}]`
97
+ )
98
+ }
99
+
100
+ const { data, mimeType } = result
101
+
102
+ if (mimeType) {
103
+ rep.header('Content-Type', mimeType)
104
+ }
105
+
106
+ rep.send(data)
107
+ }
108
+
109
+ // Serve static files
110
+ fastify.register(FastifyStatic, {
111
+ root: staticRootDir,
112
+ setHeaders: (res, path) => {
113
+ if (path.toLowerCase().endsWith('.pbf')) {
114
+ res.setHeader('Content-Type', 'application/x-protobuf')
115
+ }
116
+ },
117
+ })
118
+
119
+ /// List static maps
120
+ fastify.get(
121
+ '/',
122
+ { schema: { response: { 200: ListStaticMapsReplySchema } } },
123
+ async (req) => {
124
+ const styleDirFiles = await fs.readdir(staticRootDir)
125
+
126
+ const serverAddress = await getFastifyServerAddress(req.server.server)
127
+
128
+ const result = (
129
+ await Promise.all(
130
+ styleDirFiles.map(async (filename) => {
131
+ const stat = await fs.stat(path.join(staticRootDir, filename))
132
+ if (!stat.isDirectory()) return null
133
+
134
+ let styleJson
135
+
136
+ try {
137
+ const styleJsonContent = await fs.readFile(
138
+ path.join(staticRootDir, filename, 'style.json'),
139
+ 'utf-8'
140
+ )
141
+
142
+ styleJson = JSON.parse(styleJsonContent)
143
+ } catch (err) {
144
+ return null
145
+ }
146
+
147
+ return {
148
+ id: filename,
149
+ name: typeof styleJson.name === 'string' ? styleJson.name : null,
150
+ styleUrl: new URL(
151
+ `${req.server.prefix || ''}/${filename}/style.json`,
152
+ serverAddress
153
+ ).href,
154
+ }
155
+ })
156
+ )
157
+ ).filter(
158
+ /**
159
+ * @template {import('@sinclair/typebox').Static<typeof ListStaticMapsReplySchema>[number] | null} V
160
+ * @param {V} v
161
+ * @returns {v is NonNullable<V>}
162
+ */
163
+ (v) => v !== null
164
+ )
165
+
166
+ return result
167
+ }
168
+ )
169
+
170
+ /// Get a map's style.json
171
+ fastify.get(
172
+ `/:styleId/style.json`,
173
+ { schema: { params: GetStyleJsonParamsSchema } },
174
+ async (req, rep) => {
175
+ const { styleId } = req.params
176
+
177
+ const serverAddress = await getFastifyServerAddress(req.server.server)
178
+
179
+ let stats, styleJson
180
+
181
+ try {
182
+ const results = await Promise.all([
183
+ fastify.mapeoStaticMaps.getStyleJsonStats(styleId),
184
+ fastify.mapeoStaticMaps.getResolvedStyleJson(styleId, serverAddress),
185
+ ])
186
+
187
+ stats = results[0]
188
+ styleJson = results[1]
189
+ } catch (err) {
190
+ throw new NotFoundError(`id = ${styleId}, style.json`)
191
+ }
192
+
193
+ rep.headers(createStyleJsonResponseHeaders(stats.mtime))
194
+
195
+ return styleJson
196
+ }
197
+ )
198
+
199
+ // Get a tile (extension specified)
200
+ fastify.get(
201
+ `/:styleId/tiles/:tileId/:z/:x/:y.:ext`,
202
+ { schema: { params: GetStaticMapTileParamsSchema } },
203
+ handleStyleTileGet
204
+ )
205
+ // Get a tile (extension not specified)
206
+ fastify.get(
207
+ `/:styleId/tiles/:tileId/:z/:x/:y`,
208
+ { schema: { params: GetStaticMapTileParamsSchema } },
209
+ handleStyleTileGet
210
+ )
211
+ }
212
+
213
+ /**
214
+ * @param {string} archive
215
+ * @param {string} filename
216
+ */
217
+ function extractAsarFile(archive, filename) {
218
+ try {
219
+ return asar.extractFile(archive, filename)
220
+ } catch (err) {
221
+ return undefined
222
+ }
223
+ }
224
+
225
+ const mime = new Mime(standardTypes, { 'application/x-protobuf': ['pbf'] })
226
+
227
+ /**
228
+ * @param {string} baseDirectory
229
+ * @param {import('@sinclair/typebox').Static<typeof GetStaticMapTileParamsSchema>} params
230
+ * @returns {null | { data: Buffer, mimeType: string | null }}
231
+ */
232
+ function getStyleTileInfo(baseDirectory, params) {
233
+ const { styleId, tileId, z, x, y } = params
234
+ let { ext } = params
235
+
236
+ // TODO: If necessary, need to flip the y value first if the TileJSON source is TMS scheme
237
+ // Doing this will depend on if we decide that the asar directory structure should only follow XYZ or if it should align with corresponding tilejson spec
238
+
239
+ const fileBasename = path.join(z.toString(), x.toString(), y.toString())
240
+ const asarPath = path.join(baseDirectory, styleId, 'tiles', tileId + '.asar')
241
+
242
+ /** @type {Buffer | undefined} */
243
+ let data
244
+
245
+ if (ext) {
246
+ data = extractAsarFile(asarPath, fileBasename + '.' + ext)
247
+ } else {
248
+ // Try common extensions
249
+ const extensions = ['png', 'jpg', 'jpeg']
250
+
251
+ for (const e of extensions) {
252
+ data = extractAsarFile(asarPath, fileBasename + '.' + e)
253
+
254
+ // Match found, use the corresponding extension moving forward
255
+ if (data) {
256
+ ext = e
257
+ break
258
+ }
259
+ }
260
+ }
261
+
262
+ // extension check isn't fully necessary since the buffer will only exist if the extension exists
263
+ // but useful to check for types reasons
264
+ if (!data || !ext) {
265
+ return null
266
+ }
267
+
268
+ const mimeType = mime.getType(ext)
269
+
270
+ return { data, mimeType }
271
+ }
@@ -0,0 +1,52 @@
1
+ import { once } from 'node:events'
2
+ import createError from '@fastify/error'
3
+
4
+ export const NotFoundError = createError(
5
+ 'FST_RESOURCE_NOT_FOUND',
6
+ 'Resource `%s` not found',
7
+ 404
8
+ )
9
+
10
+ /**
11
+ * @param {import('node:http').Server} server
12
+ * @param {{ timeout?: number }} [options]
13
+ * @returns {Promise<string>}
14
+ */
15
+ export async function getFastifyServerAddress(server, { timeout } = {}) {
16
+ const address = server.address()
17
+
18
+ if (!address) {
19
+ await once(server, 'listening', {
20
+ signal: timeout ? AbortSignal.timeout(timeout) : undefined,
21
+ })
22
+ return getFastifyServerAddress(server)
23
+ }
24
+
25
+ if (typeof address === 'string') {
26
+ return address
27
+ }
28
+
29
+ // Full address construction for non unix-socket address
30
+ // https://github.com/fastify/fastify/blob/7aa802ed224b91ca559edec469a6b903e89a7f88/lib/server.js#L413
31
+ let addr = ''
32
+ if (address.address.indexOf(':') === -1) {
33
+ addr += address.address + ':' + address.port
34
+ } else {
35
+ addr += '[' + address.address + ']:' + address.port
36
+ }
37
+
38
+ return 'http://' + addr
39
+ }
40
+
41
+ /**
42
+ * @param {Readonly<Date>} lastModified
43
+ */
44
+ export function createStyleJsonResponseHeaders(lastModified) {
45
+ return {
46
+ 'Cache-Control': 'max-age=' + 5 * 60, // 5 minutes
47
+ 'Access-Control-Allow-Headers':
48
+ 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since',
49
+ 'Access-Control-Allow-Origin': '*',
50
+ 'Last-Modified': lastModified.toUTCString(),
51
+ }
52
+ }
@@ -0,0 +1,3 @@
1
+ ## Generated from Protobuf schema
2
+
3
+ These files are generated by the protobuf schema in [`../proto`](../proto) using the script in [`../scripts/build-messages.js`](../scripts/build-messages.js)
@@ -0,0 +1,44 @@
1
+ import _m0 from "protobufjs/minimal.js";
2
+ export interface ProjectExtension {
3
+ authCoreKeys: Buffer[];
4
+ }
5
+ export interface HaveExtension {
6
+ discoveryKey: Buffer;
7
+ start: number;
8
+ encodedBitfield: Buffer;
9
+ namespace: HaveExtension_Namespace;
10
+ }
11
+ export declare const HaveExtension_Namespace: {
12
+ readonly auth: "auth";
13
+ readonly config: "config";
14
+ readonly data: "data";
15
+ readonly blobIndex: "blobIndex";
16
+ readonly blob: "blob";
17
+ readonly UNRECOGNIZED: "UNRECOGNIZED";
18
+ };
19
+ export type HaveExtension_Namespace = typeof HaveExtension_Namespace[keyof typeof HaveExtension_Namespace];
20
+ export declare function haveExtension_NamespaceFromJSON(object: any): HaveExtension_Namespace;
21
+ export declare function haveExtension_NamespaceToNumber(object: HaveExtension_Namespace): number;
22
+ export declare const ProjectExtension: {
23
+ encode(message: ProjectExtension, writer?: _m0.Writer): _m0.Writer;
24
+ decode(input: _m0.Reader | Uint8Array, length?: number): ProjectExtension;
25
+ create<I extends Exact<DeepPartial<ProjectExtension>, I>>(base?: I): ProjectExtension;
26
+ fromPartial<I extends Exact<DeepPartial<ProjectExtension>, I>>(object: I): ProjectExtension;
27
+ };
28
+ export declare const HaveExtension: {
29
+ encode(message: HaveExtension, writer?: _m0.Writer): _m0.Writer;
30
+ decode(input: _m0.Reader | Uint8Array, length?: number): HaveExtension;
31
+ create<I extends Exact<DeepPartial<HaveExtension>, I>>(base?: I): HaveExtension;
32
+ fromPartial<I extends Exact<DeepPartial<HaveExtension>, I>>(object: I): HaveExtension;
33
+ };
34
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
35
+ type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
36
+ [K in keyof T]?: DeepPartial<T[K]>;
37
+ } : Partial<T>;
38
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
39
+ type Exact<P, I extends P> = P extends Builtin ? P : P & {
40
+ [K in keyof P]: Exact<P[K], I[K]>;
41
+ } & {
42
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
43
+ };
44
+ export {};
@@ -0,0 +1,196 @@
1
+ /* eslint-disable */
2
+ import Long from "long";
3
+ import _m0 from "protobufjs/minimal.js";
4
+ export var HaveExtension_Namespace = {
5
+ auth: "auth",
6
+ config: "config",
7
+ data: "data",
8
+ blobIndex: "blobIndex",
9
+ blob: "blob",
10
+ UNRECOGNIZED: "UNRECOGNIZED",
11
+ };
12
+ export function haveExtension_NamespaceFromJSON(object) {
13
+ switch (object) {
14
+ case 0:
15
+ case "auth":
16
+ return HaveExtension_Namespace.auth;
17
+ case 1:
18
+ case "config":
19
+ return HaveExtension_Namespace.config;
20
+ case 2:
21
+ case "data":
22
+ return HaveExtension_Namespace.data;
23
+ case 3:
24
+ case "blobIndex":
25
+ return HaveExtension_Namespace.blobIndex;
26
+ case 4:
27
+ case "blob":
28
+ return HaveExtension_Namespace.blob;
29
+ case -1:
30
+ case "UNRECOGNIZED":
31
+ default:
32
+ return HaveExtension_Namespace.UNRECOGNIZED;
33
+ }
34
+ }
35
+ export function haveExtension_NamespaceToNumber(object) {
36
+ switch (object) {
37
+ case HaveExtension_Namespace.auth:
38
+ return 0;
39
+ case HaveExtension_Namespace.config:
40
+ return 1;
41
+ case HaveExtension_Namespace.data:
42
+ return 2;
43
+ case HaveExtension_Namespace.blobIndex:
44
+ return 3;
45
+ case HaveExtension_Namespace.blob:
46
+ return 4;
47
+ case HaveExtension_Namespace.UNRECOGNIZED:
48
+ default:
49
+ return -1;
50
+ }
51
+ }
52
+ function createBaseProjectExtension() {
53
+ return { authCoreKeys: [] };
54
+ }
55
+ export var ProjectExtension = {
56
+ encode: function (message, writer) {
57
+ if (writer === void 0) { writer = _m0.Writer.create(); }
58
+ for (var _i = 0, _a = message.authCoreKeys; _i < _a.length; _i++) {
59
+ var v = _a[_i];
60
+ writer.uint32(10).bytes(v);
61
+ }
62
+ return writer;
63
+ },
64
+ decode: function (input, length) {
65
+ var reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
66
+ var end = length === undefined ? reader.len : reader.pos + length;
67
+ var message = createBaseProjectExtension();
68
+ while (reader.pos < end) {
69
+ var tag = reader.uint32();
70
+ switch (tag >>> 3) {
71
+ case 1:
72
+ if (tag !== 10) {
73
+ break;
74
+ }
75
+ message.authCoreKeys.push(reader.bytes());
76
+ continue;
77
+ }
78
+ if ((tag & 7) === 4 || tag === 0) {
79
+ break;
80
+ }
81
+ reader.skipType(tag & 7);
82
+ }
83
+ return message;
84
+ },
85
+ create: function (base) {
86
+ return ProjectExtension.fromPartial(base !== null && base !== void 0 ? base : {});
87
+ },
88
+ fromPartial: function (object) {
89
+ var _a;
90
+ var message = createBaseProjectExtension();
91
+ message.authCoreKeys = ((_a = object.authCoreKeys) === null || _a === void 0 ? void 0 : _a.map(function (e) { return e; })) || [];
92
+ return message;
93
+ },
94
+ };
95
+ function createBaseHaveExtension() {
96
+ return {
97
+ discoveryKey: Buffer.alloc(0),
98
+ start: 0,
99
+ encodedBitfield: Buffer.alloc(0),
100
+ namespace: HaveExtension_Namespace.auth,
101
+ };
102
+ }
103
+ export var HaveExtension = {
104
+ encode: function (message, writer) {
105
+ if (writer === void 0) { writer = _m0.Writer.create(); }
106
+ if (message.discoveryKey.length !== 0) {
107
+ writer.uint32(10).bytes(message.discoveryKey);
108
+ }
109
+ if (message.start !== 0) {
110
+ writer.uint32(16).uint64(message.start);
111
+ }
112
+ if (message.encodedBitfield.length !== 0) {
113
+ writer.uint32(26).bytes(message.encodedBitfield);
114
+ }
115
+ if (message.namespace !== HaveExtension_Namespace.auth) {
116
+ writer.uint32(32).int32(haveExtension_NamespaceToNumber(message.namespace));
117
+ }
118
+ return writer;
119
+ },
120
+ decode: function (input, length) {
121
+ var reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
122
+ var end = length === undefined ? reader.len : reader.pos + length;
123
+ var message = createBaseHaveExtension();
124
+ while (reader.pos < end) {
125
+ var tag = reader.uint32();
126
+ switch (tag >>> 3) {
127
+ case 1:
128
+ if (tag !== 10) {
129
+ break;
130
+ }
131
+ message.discoveryKey = reader.bytes();
132
+ continue;
133
+ case 2:
134
+ if (tag !== 16) {
135
+ break;
136
+ }
137
+ message.start = longToNumber(reader.uint64());
138
+ continue;
139
+ case 3:
140
+ if (tag !== 26) {
141
+ break;
142
+ }
143
+ message.encodedBitfield = reader.bytes();
144
+ continue;
145
+ case 4:
146
+ if (tag !== 32) {
147
+ break;
148
+ }
149
+ message.namespace = haveExtension_NamespaceFromJSON(reader.int32());
150
+ continue;
151
+ }
152
+ if ((tag & 7) === 4 || tag === 0) {
153
+ break;
154
+ }
155
+ reader.skipType(tag & 7);
156
+ }
157
+ return message;
158
+ },
159
+ create: function (base) {
160
+ return HaveExtension.fromPartial(base !== null && base !== void 0 ? base : {});
161
+ },
162
+ fromPartial: function (object) {
163
+ var _a, _b, _c, _d;
164
+ var message = createBaseHaveExtension();
165
+ message.discoveryKey = (_a = object.discoveryKey) !== null && _a !== void 0 ? _a : Buffer.alloc(0);
166
+ message.start = (_b = object.start) !== null && _b !== void 0 ? _b : 0;
167
+ message.encodedBitfield = (_c = object.encodedBitfield) !== null && _c !== void 0 ? _c : Buffer.alloc(0);
168
+ message.namespace = (_d = object.namespace) !== null && _d !== void 0 ? _d : HaveExtension_Namespace.auth;
169
+ return message;
170
+ },
171
+ };
172
+ var tsProtoGlobalThis = (function () {
173
+ if (typeof globalThis !== "undefined") {
174
+ return globalThis;
175
+ }
176
+ if (typeof self !== "undefined") {
177
+ return self;
178
+ }
179
+ if (typeof window !== "undefined") {
180
+ return window;
181
+ }
182
+ if (typeof global !== "undefined") {
183
+ return global;
184
+ }
185
+ throw "Unable to locate global object";
186
+ })();
187
+ function longToNumber(long) {
188
+ if (long.gt(Number.MAX_SAFE_INTEGER)) {
189
+ throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
190
+ }
191
+ return long.toNumber();
192
+ }
193
+ if (_m0.util.Long !== Long) {
194
+ _m0.util.Long = Long;
195
+ _m0.configure();
196
+ }