@holoscript/core 6.0.3 → 7.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 (244) hide show
  1. package/README.md +40 -40
  2. package/dist/codebase/index.d.ts +25 -0
  3. package/dist/compiler/index.d.ts +82 -0
  4. package/dist/constants.d.ts +4 -0
  5. package/dist/coordinators/index.d.ts +189 -0
  6. package/dist/entries/interop.d.ts +9 -0
  7. package/dist/entries/scripting.d.ts +7 -0
  8. package/dist/index.d.ts +520 -19
  9. package/dist/paper-0c-spike/index.d.ts +29 -0
  10. package/dist/reconstruction/index.d.ts +78 -0
  11. package/dist/self-improvement/index.d.ts +0 -48
  12. package/dist/storage/index.d.ts +24 -0
  13. package/dist/tools/index.d.ts +33 -0
  14. package/dist/traitDocs/traitDocs.d.ts +69 -0
  15. package/dist/traits/index.d.ts +61 -0
  16. package/package.json +102 -19
  17. package/dist/GLTFPipeline-3KLWWUQO.cjs +0 -34
  18. package/dist/GLTFPipeline-LYII2ZVQ.js +0 -13
  19. package/dist/HoloScriptPlusParser-BZR5DELQ.js +0 -692
  20. package/dist/HoloScriptPlusParser-SBMYDNXO.cjs +0 -697
  21. package/dist/USDZExporter-MHEHXZB4.cjs +0 -709
  22. package/dist/USDZExporter-YA55ZS35.js +0 -707
  23. package/dist/chunk-26TLYBFD.js +0 -309
  24. package/dist/chunk-27LWW5FU.cjs +0 -410
  25. package/dist/chunk-2UX5LRAP.cjs +0 -833
  26. package/dist/chunk-32TWR3HE.js +0 -70
  27. package/dist/chunk-3FXV5S25.cjs +0 -633
  28. package/dist/chunk-3FYZOR7S.cjs +0 -69
  29. package/dist/chunk-3KEU5QYY.cjs +0 -175
  30. package/dist/chunk-4FCZDTD5.js +0 -610
  31. package/dist/chunk-4KJ2R7VP.cjs +0 -507
  32. package/dist/chunk-4SMUJFHL.js +0 -1213
  33. package/dist/chunk-54FHG2MX.js +0 -655
  34. package/dist/chunk-56IF4NTA.js +0 -56
  35. package/dist/chunk-5GLCTO44.js +0 -161
  36. package/dist/chunk-5TOFIR6L.js +0 -407
  37. package/dist/chunk-65RFOWZI.js +0 -765
  38. package/dist/chunk-6OQBLABR.js +0 -5240
  39. package/dist/chunk-6WNCRE6F.js +0 -126
  40. package/dist/chunk-74YCHHTE.js +0 -1872
  41. package/dist/chunk-7H5UNJZD.cjs +0 -1973
  42. package/dist/chunk-7KPI4EKH.cjs +0 -701
  43. package/dist/chunk-7LCYLPW2.cjs +0 -663
  44. package/dist/chunk-7N3JIJMT.js +0 -1395
  45. package/dist/chunk-7X2IEJIE.cjs +0 -2526
  46. package/dist/chunk-A6GO3DPZ.cjs +0 -1002
  47. package/dist/chunk-AC4BSHFV.js +0 -765
  48. package/dist/chunk-AIUXRS74.cjs +0 -3681
  49. package/dist/chunk-ARNKA274.cjs +0 -130
  50. package/dist/chunk-AW7WAELW.js +0 -975
  51. package/dist/chunk-BKIGPPVM.js +0 -629
  52. package/dist/chunk-BO2OKHIY.js +0 -6055
  53. package/dist/chunk-BU5ZAFMC.js +0 -115
  54. package/dist/chunk-BY3B7ZYV.cjs +0 -457
  55. package/dist/chunk-C2QHVHZF.js +0 -4066
  56. package/dist/chunk-C7BNX4XJ.js +0 -1043
  57. package/dist/chunk-CLYEIWA5.cjs +0 -408
  58. package/dist/chunk-CMYAWUX3.js +0 -4455
  59. package/dist/chunk-CN4NOESF.cjs +0 -416
  60. package/dist/chunk-CNVM7J3M.js +0 -883
  61. package/dist/chunk-CO2VM2DK.js +0 -1965
  62. package/dist/chunk-CQDOF3G7.cjs +0 -1404
  63. package/dist/chunk-DH5G2JUA.cjs +0 -614
  64. package/dist/chunk-DIEDKX5B.cjs +0 -660
  65. package/dist/chunk-DN7UFU63.cjs +0 -172
  66. package/dist/chunk-DXVCEFZB.js +0 -2027
  67. package/dist/chunk-EGIZHYJP.cjs +0 -85
  68. package/dist/chunk-EJA7G2C4.cjs +0 -428
  69. package/dist/chunk-ELLQPFAF.js +0 -830
  70. package/dist/chunk-EMO7HAKJ.cjs +0 -1875
  71. package/dist/chunk-ENV7K6XA.js +0 -282
  72. package/dist/chunk-EPWRXL6S.js +0 -2522
  73. package/dist/chunk-EUFLX2PI.js +0 -56956
  74. package/dist/chunk-F5LVGHNT.js +0 -449
  75. package/dist/chunk-FEFHPUEM.cjs +0 -6122
  76. package/dist/chunk-FF3Q7ADR.js +0 -380
  77. package/dist/chunk-GC3YU46J.js +0 -762
  78. package/dist/chunk-H6WMMLQK.cjs +0 -4492
  79. package/dist/chunk-H7XMORZI.js +0 -2731
  80. package/dist/chunk-HAN4V3PF.cjs +0 -2037
  81. package/dist/chunk-HBZYCASG.js +0 -4208
  82. package/dist/chunk-HF4OFY25.cjs +0 -4097
  83. package/dist/chunk-HHS6FMOU.cjs +0 -3813
  84. package/dist/chunk-HJJLD366.js +0 -1169
  85. package/dist/chunk-HKCVM6OK.cjs +0 -2237
  86. package/dist/chunk-HUFNKFA6.js +0 -698
  87. package/dist/chunk-I3XGTIHM.cjs +0 -1505
  88. package/dist/chunk-I6XZ5DZF.cjs +0 -488
  89. package/dist/chunk-IHOUYQIA.js +0 -406
  90. package/dist/chunk-ILRBGFVD.cjs +0 -72
  91. package/dist/chunk-KDB6BUMB.js +0 -3666
  92. package/dist/chunk-KUJRR4FJ.js +0 -657
  93. package/dist/chunk-KYM4XRFG.js +0 -421
  94. package/dist/chunk-L3Z2HIWJ.cjs +0 -793
  95. package/dist/chunk-LBPEZQAF.js +0 -2232
  96. package/dist/chunk-LER4WXW5.cjs +0 -286
  97. package/dist/chunk-LK5IAVH6.cjs +0 -1173
  98. package/dist/chunk-M6FU6S22.js +0 -2911
  99. package/dist/chunk-MWEFR6YQ.js +0 -1857
  100. package/dist/chunk-N5FTS757.cjs +0 -415
  101. package/dist/chunk-NCUHGRTZ.js +0 -752
  102. package/dist/chunk-NKRKT6V2.js +0 -69
  103. package/dist/chunk-NLPSZT4C.js +0 -630
  104. package/dist/chunk-NRUB55IT.cjs +0 -771
  105. package/dist/chunk-NTMZSDXM.cjs +0 -633
  106. package/dist/chunk-ODGMVILH.js +0 -9662
  107. package/dist/chunk-PBA6NXCT.cjs +0 -1216
  108. package/dist/chunk-PHENW4MQ.js +0 -65
  109. package/dist/chunk-PJMOXFPR.cjs +0 -1861
  110. package/dist/chunk-PLMYCCA4.js +0 -504
  111. package/dist/chunk-PPULB4GG.cjs +0 -9728
  112. package/dist/chunk-PQLGZKMC.cjs +0 -755
  113. package/dist/chunk-Q56TT7IL.js +0 -483
  114. package/dist/chunk-QHVVVN47.cjs +0 -2033
  115. package/dist/chunk-QWKUKVRE.js +0 -2026
  116. package/dist/chunk-RE3OKSYF.cjs +0 -424
  117. package/dist/chunk-RT7LJRSF.cjs +0 -57378
  118. package/dist/chunk-SPDELRRV.cjs +0 -319
  119. package/dist/chunk-SUCBB66F.js +0 -229
  120. package/dist/chunk-TSWTWZ42.cjs +0 -4214
  121. package/dist/chunk-UITWA6DV.cjs +0 -2829
  122. package/dist/chunk-UQW6SLM5.js +0 -172
  123. package/dist/chunk-V2ILLPHK.cjs +0 -237
  124. package/dist/chunk-V42NTCFH.js +0 -3645
  125. package/dist/chunk-VJ3L7CHT.cjs +0 -169
  126. package/dist/chunk-VJVCD5T5.cjs +0 -769
  127. package/dist/chunk-VK5AXKO3.js +0 -746
  128. package/dist/chunk-VSXOIUCF.cjs +0 -473
  129. package/dist/chunk-VZNKJZTT.cjs +0 -749
  130. package/dist/chunk-W76ETJTI.js +0 -678
  131. package/dist/chunk-WFJIDI2N.cjs +0 -424
  132. package/dist/chunk-WN3YF33G.cjs +0 -118
  133. package/dist/chunk-WUXIRGZP.cjs +0 -2915
  134. package/dist/chunk-WYH4GVZ5.js +0 -1488
  135. package/dist/chunk-X4YVN7H3.cjs +0 -888
  136. package/dist/chunk-X67XRI2T.js +0 -410
  137. package/dist/chunk-XDXZM3ZP.cjs +0 -1046
  138. package/dist/chunk-XH7SE4HH.cjs +0 -72
  139. package/dist/chunk-XNMEH2BI.js +0 -126
  140. package/dist/chunk-XSF76QRU.js +0 -468
  141. package/dist/chunk-XSUZMPVQ.cjs +0 -682
  142. package/dist/chunk-XUILI4KB.cjs +0 -430
  143. package/dist/chunk-Y5MUAYTO.js +0 -167
  144. package/dist/chunk-Y7VK5TH3.cjs +0 -129
  145. package/dist/chunk-YCMQQQ5U.cjs +0 -5244
  146. package/dist/chunk-YYXH45E2.js +0 -426
  147. package/dist/chunk-ZGTGVSTZ.js +0 -422
  148. package/dist/chunk-ZL6VJ6SN.js +0 -421
  149. package/dist/cli/holoscript-runner.cjs +0 -2258
  150. package/dist/cli/holoscript-runner.js +0 -2233
  151. package/dist/codebase/index.cjs +0 -336
  152. package/dist/codebase/index.js +0 -331
  153. package/dist/compiler/agent-inference.cjs +0 -29
  154. package/dist/compiler/agent-inference.js +0 -6
  155. package/dist/compiler/android-xr.cjs +0 -20
  156. package/dist/compiler/android-xr.js +0 -10
  157. package/dist/compiler/android.cjs +0 -21
  158. package/dist/compiler/android.js +0 -11
  159. package/dist/compiler/ar.cjs +0 -21
  160. package/dist/compiler/ar.js +0 -9
  161. package/dist/compiler/babylon.cjs +0 -18
  162. package/dist/compiler/babylon.js +0 -12
  163. package/dist/compiler/coco.cjs +0 -27
  164. package/dist/compiler/coco.js +0 -4
  165. package/dist/compiler/domain-block-utils.cjs +0 -595
  166. package/dist/compiler/domain-block-utils.js +0 -9
  167. package/dist/compiler/dtdl.cjs +0 -25
  168. package/dist/compiler/dtdl.js +0 -9
  169. package/dist/compiler/gltf-pipeline.cjs +0 -39
  170. package/dist/compiler/gltf-pipeline.js +0 -4
  171. package/dist/compiler/godot.cjs +0 -16
  172. package/dist/compiler/godot.js +0 -10
  173. package/dist/compiler/incremental.cjs +0 -30
  174. package/dist/compiler/incremental.js +0 -5
  175. package/dist/compiler/index.cjs +0 -1522
  176. package/dist/compiler/index.js +0 -1321
  177. package/dist/compiler/ios.cjs +0 -21
  178. package/dist/compiler/ios.js +0 -11
  179. package/dist/compiler/multi-layer.cjs +0 -27
  180. package/dist/compiler/multi-layer.js +0 -12
  181. package/dist/compiler/nodetoy.cjs +0 -23
  182. package/dist/compiler/nodetoy.js +0 -4
  183. package/dist/compiler/openxr.cjs +0 -16
  184. package/dist/compiler/openxr.js +0 -10
  185. package/dist/compiler/playcanvas.cjs +0 -17
  186. package/dist/compiler/playcanvas.js +0 -11
  187. package/dist/compiler/r3f.cjs +0 -35
  188. package/dist/compiler/r3f.js +0 -13
  189. package/dist/compiler/remotion.cjs +0 -23
  190. package/dist/compiler/remotion.js +0 -4
  191. package/dist/compiler/reproducibility.cjs +0 -39
  192. package/dist/compiler/reproducibility.js +0 -4
  193. package/dist/compiler/sdf.cjs +0 -22
  194. package/dist/compiler/sdf.js +0 -10
  195. package/dist/compiler/semantic-scene.cjs +0 -31
  196. package/dist/compiler/semantic-scene.js +0 -4
  197. package/dist/compiler/state.cjs +0 -18
  198. package/dist/compiler/state.js +0 -8
  199. package/dist/compiler/trait-composition.cjs +0 -27
  200. package/dist/compiler/trait-composition.js +0 -6
  201. package/dist/compiler/unity.cjs +0 -16
  202. package/dist/compiler/unity.js +0 -10
  203. package/dist/compiler/unreal.cjs +0 -20
  204. package/dist/compiler/unreal.js +0 -10
  205. package/dist/compiler/urdf.cjs +0 -46
  206. package/dist/compiler/urdf.js +0 -10
  207. package/dist/compiler/usd-physics.cjs +0 -24
  208. package/dist/compiler/usd-physics.js +0 -7
  209. package/dist/compiler/visionos.cjs +0 -16
  210. package/dist/compiler/visionos.js +0 -10
  211. package/dist/compiler/vrchat.cjs +0 -20
  212. package/dist/compiler/vrchat.js +0 -10
  213. package/dist/compiler/vrr.cjs +0 -22
  214. package/dist/compiler/vrr.js +0 -10
  215. package/dist/compiler/wasm.cjs +0 -34
  216. package/dist/compiler/wasm.js +0 -10
  217. package/dist/compiler/webgpu.cjs +0 -16
  218. package/dist/compiler/webgpu.js +0 -10
  219. package/dist/debugger.cjs +0 -21
  220. package/dist/debugger.js +0 -8
  221. package/dist/entries/interop.cjs +0 -62
  222. package/dist/entries/interop.js +0 -5
  223. package/dist/entries/scripting.cjs +0 -67
  224. package/dist/entries/scripting.js +0 -10
  225. package/dist/index.cjs +0 -61703
  226. package/dist/index.js +0 -58652
  227. package/dist/math/vec3.cjs +0 -57
  228. package/dist/math/vec3.js +0 -4
  229. package/dist/parser.cjs +0 -26
  230. package/dist/parser.js +0 -9
  231. package/dist/playwright-7DTEQCBD.cjs +0 -98673
  232. package/dist/playwright-BIZXMLD2.js +0 -98660
  233. package/dist/post-quantum-JTTAAGO3.cjs +0 -6
  234. package/dist/post-quantum-RVPVDEPI.js +0 -4
  235. package/dist/runtime.cjs +0 -16
  236. package/dist/runtime.js +0 -7
  237. package/dist/storage/index.cjs +0 -37
  238. package/dist/storage/index.js +0 -4
  239. package/dist/traits/index.cjs +0 -14331
  240. package/dist/traits/index.js +0 -12126
  241. package/dist/type-checker.cjs +0 -18
  242. package/dist/type-checker.js +0 -5
  243. package/dist/wot/index.cjs +0 -29
  244. package/dist/wot/index.js +0 -4
@@ -1,663 +0,0 @@
1
- 'use strict';
2
-
3
- // src/storage/IPFSTypes.ts
4
- var IPFSUploadError = class extends Error {
5
- constructor(message, provider, originalError) {
6
- super(message);
7
- this.provider = provider;
8
- this.originalError = originalError;
9
- this.name = "IPFSUploadError";
10
- }
11
- };
12
- var IPFSPinError = class extends Error {
13
- constructor(message, cid, originalError) {
14
- super(message);
15
- this.cid = cid;
16
- this.originalError = originalError;
17
- this.name = "IPFSPinError";
18
- }
19
- };
20
- var FileSizeExceededError = class extends Error {
21
- constructor(fileSize, maxSize) {
22
- super(`File size ${fileSize} bytes exceeds maximum ${maxSize} bytes`);
23
- this.fileSize = fileSize;
24
- this.maxSize = maxSize;
25
- this.name = "FileSizeExceededError";
26
- }
27
- };
28
-
29
- // src/storage/IPFSProviders.ts
30
- var PinataProvider = class {
31
- constructor(apiKey, apiSecret) {
32
- this.baseUrl = "https://api.pinata.cloud";
33
- this.apiKey = apiKey;
34
- this.apiSecret = apiSecret || "";
35
- }
36
- async upload(files, options) {
37
- const formData = new FormData();
38
- for (const file of files) {
39
- const blob = new Blob([file.content]);
40
- formData.append("file", blob, file.path);
41
- }
42
- const metadata = {
43
- name: options.metadata?.name || options.name,
44
- keyvalues: options.metadata?.keyvalues || {}
45
- };
46
- formData.append("pinataMetadata", JSON.stringify(metadata));
47
- const pinataOptions = {
48
- cidVersion: 1
49
- };
50
- formData.append("pinataOptions", JSON.stringify(pinataOptions));
51
- const response = await fetch(`${this.baseUrl}/pinning/pinFileToIPFS`, {
52
- method: "POST",
53
- headers: {
54
- pinata_api_key: this.apiKey,
55
- pinata_secret_api_key: this.apiSecret
56
- },
57
- body: formData
58
- });
59
- if (!response.ok) {
60
- const error = await response.text();
61
- throw new Error(`Pinata upload failed: ${error}`);
62
- }
63
- const data = await response.json();
64
- return {
65
- cid: data.IpfsHash,
66
- size: data.PinSize
67
- };
68
- }
69
- async pin(cid, name) {
70
- const response = await fetch(`${this.baseUrl}/pinning/pinByHash`, {
71
- method: "POST",
72
- headers: {
73
- "Content-Type": "application/json",
74
- pinata_api_key: this.apiKey,
75
- pinata_secret_api_key: this.apiSecret
76
- },
77
- body: JSON.stringify({
78
- hashToPin: cid,
79
- pinataMetadata: {
80
- name: name || cid
81
- }
82
- })
83
- });
84
- if (!response.ok) {
85
- const error = await response.text();
86
- throw new Error(`Pinata pin failed: ${error}`);
87
- }
88
- }
89
- async unpin(cid) {
90
- const response = await fetch(`${this.baseUrl}/pinning/unpin/${cid}`, {
91
- method: "DELETE",
92
- headers: {
93
- pinata_api_key: this.apiKey,
94
- pinata_secret_api_key: this.apiSecret
95
- }
96
- });
97
- if (!response.ok) {
98
- const error = await response.text();
99
- throw new Error(`Pinata unpin failed: ${error}`);
100
- }
101
- }
102
- async getPinStatus(cid) {
103
- const response = await fetch(
104
- `${this.baseUrl}/data/pinList?hashContains=${cid}&status=pinned,pinning`,
105
- {
106
- headers: {
107
- pinata_api_key: this.apiKey,
108
- pinata_secret_api_key: this.apiSecret
109
- }
110
- }
111
- );
112
- if (!response.ok) {
113
- return "unpinned";
114
- }
115
- const data = await response.json();
116
- if (data.count === 0) {
117
- return "unpinned";
118
- }
119
- const pin = data.rows[0];
120
- return pin.status === "pinned" ? "pinned" : "pinning";
121
- }
122
- async listPins() {
123
- const response = await fetch(`${this.baseUrl}/data/pinList?status=pinned`, {
124
- headers: {
125
- pinata_api_key: this.apiKey,
126
- pinata_secret_api_key: this.apiSecret
127
- }
128
- });
129
- if (!response.ok) {
130
- throw new Error("Failed to list pins");
131
- }
132
- const data = await response.json();
133
- return data.rows.map((pin) => ({
134
- // @ts-expect-error
135
- cid: pin.ipfs_pin_hash,
136
- // @ts-expect-error
137
- name: pin.metadata?.name || pin.ipfs_pin_hash,
138
- // @ts-expect-error
139
- size: pin.size,
140
- // @ts-expect-error
141
- status: pin.status,
142
- // @ts-expect-error
143
- created: new Date(pin.date_pinned)
144
- }));
145
- }
146
- async verifyCID(cid) {
147
- try {
148
- const status = await this.getPinStatus(cid);
149
- return status === "pinned" || status === "pinning";
150
- } catch {
151
- return false;
152
- }
153
- }
154
- };
155
- var NFTStorageProvider = class {
156
- constructor(apiKey) {
157
- this.baseUrl = "https://api.nft.storage";
158
- this.apiKey = apiKey;
159
- }
160
- async upload(files, options) {
161
- const formData = new FormData();
162
- for (const file of files) {
163
- const blob = new Blob([file.content]);
164
- formData.append("file", blob, file.path);
165
- }
166
- const response = await fetch(`${this.baseUrl}/upload`, {
167
- method: "POST",
168
- headers: {
169
- Authorization: `Bearer ${this.apiKey}`
170
- },
171
- body: formData
172
- });
173
- if (!response.ok) {
174
- const error = await response.text();
175
- throw new Error(`NFT.Storage upload failed: ${error}`);
176
- }
177
- const data = await response.json();
178
- return {
179
- cid: data.value.cid,
180
- size: data.value.size
181
- };
182
- }
183
- async pin(cid, name) {
184
- }
185
- async unpin(cid) {
186
- const response = await fetch(`${this.baseUrl}/${cid}`, {
187
- method: "DELETE",
188
- headers: {
189
- Authorization: `Bearer ${this.apiKey}`
190
- }
191
- });
192
- if (!response.ok) {
193
- const error = await response.text();
194
- throw new Error(`NFT.Storage unpin failed: ${error}`);
195
- }
196
- }
197
- async getPinStatus(cid) {
198
- const response = await fetch(`${this.baseUrl}/${cid}`, {
199
- headers: {
200
- Authorization: `Bearer ${this.apiKey}`
201
- }
202
- });
203
- if (!response.ok) {
204
- return "unpinned";
205
- }
206
- const data = await response.json();
207
- return data.pin?.status === "pinned" ? "pinned" : "pinning";
208
- }
209
- async listPins() {
210
- const response = await fetch(`${this.baseUrl}`, {
211
- headers: {
212
- Authorization: `Bearer ${this.apiKey}`
213
- }
214
- });
215
- if (!response.ok) {
216
- throw new Error("Failed to list pins");
217
- }
218
- const data = await response.json();
219
- return data.value.map((item) => ({
220
- // @ts-expect-error
221
- cid: item.cid,
222
- // @ts-expect-error
223
- name: item.name || item.cid,
224
- // @ts-expect-error
225
- size: item.size,
226
- // @ts-expect-error
227
- status: item.pin?.status || "pinned",
228
- // @ts-expect-error
229
- created: new Date(item.created)
230
- }));
231
- }
232
- async verifyCID(cid) {
233
- try {
234
- const status = await this.getPinStatus(cid);
235
- return status === "pinned" || status === "pinning";
236
- } catch {
237
- return false;
238
- }
239
- }
240
- };
241
- var InfuraProvider = class {
242
- constructor(projectId, projectSecret) {
243
- this.baseUrl = "https://ipfs.infura.io:5001/api/v0";
244
- this.projectId = projectId;
245
- this.projectSecret = projectSecret || "";
246
- }
247
- getAuthHeader() {
248
- const auth = Buffer.from(`${this.projectId}:${this.projectSecret}`).toString("base64");
249
- return `Basic ${auth}`;
250
- }
251
- async upload(files, options) {
252
- const formData = new FormData();
253
- for (const file of files) {
254
- const blob = new Blob([file.content]);
255
- formData.append("file", blob, file.path);
256
- }
257
- const response = await fetch(`${this.baseUrl}/add?wrap-with-directory=true`, {
258
- method: "POST",
259
- headers: {
260
- Authorization: this.getAuthHeader()
261
- },
262
- body: formData
263
- });
264
- if (!response.ok) {
265
- const error = await response.text();
266
- throw new Error(`Infura upload failed: ${error}`);
267
- }
268
- const text = await response.text();
269
- const lines = text.trim().split("\n");
270
- const lastLine = JSON.parse(lines[lines.length - 1]);
271
- let totalSize = 0;
272
- for (const line of lines) {
273
- const data = JSON.parse(line);
274
- totalSize += data.Size || 0;
275
- }
276
- return {
277
- cid: lastLine.Hash,
278
- size: totalSize
279
- };
280
- }
281
- async pin(cid, name) {
282
- const response = await fetch(`${this.baseUrl}/pin/add?arg=${cid}`, {
283
- method: "POST",
284
- headers: {
285
- Authorization: this.getAuthHeader()
286
- }
287
- });
288
- if (!response.ok) {
289
- const error = await response.text();
290
- throw new Error(`Infura pin failed: ${error}`);
291
- }
292
- }
293
- async unpin(cid) {
294
- const response = await fetch(`${this.baseUrl}/pin/rm?arg=${cid}`, {
295
- method: "POST",
296
- headers: {
297
- Authorization: this.getAuthHeader()
298
- }
299
- });
300
- if (!response.ok) {
301
- const error = await response.text();
302
- throw new Error(`Infura unpin failed: ${error}`);
303
- }
304
- }
305
- async getPinStatus(cid) {
306
- const response = await fetch(`${this.baseUrl}/pin/ls?arg=${cid}`, {
307
- headers: {
308
- Authorization: this.getAuthHeader()
309
- }
310
- });
311
- if (!response.ok) {
312
- return "unpinned";
313
- }
314
- const data = await response.json();
315
- return data.Keys && data.Keys[cid] ? "pinned" : "unpinned";
316
- }
317
- async listPins() {
318
- const response = await fetch(`${this.baseUrl}/pin/ls`, {
319
- headers: {
320
- Authorization: this.getAuthHeader()
321
- }
322
- });
323
- if (!response.ok) {
324
- throw new Error("Failed to list pins");
325
- }
326
- const data = await response.json();
327
- return Object.entries(data.Keys || {}).map(([cid, info]) => ({
328
- cid,
329
- name: cid,
330
- size: 0,
331
- // Infura doesn't provide size in pin list
332
- status: "pinned"
333
- }));
334
- }
335
- async verifyCID(cid) {
336
- try {
337
- const response = await fetch(`${this.baseUrl}/cat?arg=${cid}`, {
338
- method: "POST",
339
- headers: {
340
- Authorization: this.getAuthHeader()
341
- }
342
- });
343
- return response.ok;
344
- } catch {
345
- return false;
346
- }
347
- }
348
- };
349
-
350
- // src/storage/IPFSService.ts
351
- var IPFSService = class {
352
- constructor(options) {
353
- this.fallbackProviders = [];
354
- this.defaultGateway = "https://ipfs.io/ipfs";
355
- this.cdnGateway = "https://cloudflare-ipfs.com/ipfs";
356
- this.options = {
357
- ...options,
358
- fallbackProviders: options.fallbackProviders || [],
359
- enableCDN: options.enableCDN ?? true,
360
- maxFileSize: options.maxFileSize || 100 * 1024 * 1024,
361
- // 100MB
362
- chunkSize: options.chunkSize || 5 * 1024 * 1024,
363
- // 5MB
364
- maxRetries: options.maxRetries || 3,
365
- retryDelay: options.retryDelay || 1e3,
366
- gatewayUrl: options.gatewayUrl || this.defaultGateway,
367
- apiSecret: options.apiSecret
368
- };
369
- this.primaryProvider = this.createProvider(
370
- this.options.provider,
371
- this.options.apiKey,
372
- this.options.apiSecret
373
- );
374
- for (const fallback of this.options.fallbackProviders) {
375
- const provider = this.createProvider(fallback.provider, fallback.apiKey, fallback.apiSecret);
376
- this.fallbackProviders.push(provider);
377
- }
378
- }
379
- /**
380
- * Create provider instance
381
- */
382
- createProvider(type, apiKey, apiSecret) {
383
- switch (type) {
384
- case "pinata":
385
- return new PinataProvider(apiKey, apiSecret);
386
- case "nft.storage":
387
- return new NFTStorageProvider(apiKey);
388
- case "infura":
389
- return new InfuraProvider(apiKey, apiSecret);
390
- default:
391
- throw new Error(`Unknown IPFS provider: ${type}`);
392
- }
393
- }
394
- /**
395
- * Upload files to IPFS
396
- *
397
- * Returns CID and gateway URLs. Automatically retries on failure and falls back
398
- * to backup providers if primary fails.
399
- *
400
- * @param options Upload options
401
- * @returns Upload result with CID and URLs
402
- * @throws {FileSizeExceededError} If file size exceeds maximum
403
- * @throws {IPFSUploadError} If upload fails on all providers
404
- */
405
- async upload(options) {
406
- const startTime = Date.now();
407
- const totalSize = options.files.reduce((sum, file) => {
408
- const size = file.content instanceof Buffer || file.content instanceof Uint8Array ? file.content.length : Buffer.from(file.content).length;
409
- return sum + size;
410
- }, 0);
411
- if (totalSize > this.options.maxFileSize) {
412
- throw new FileSizeExceededError(totalSize, this.options.maxFileSize);
413
- }
414
- const needsChunking = totalSize > this.options.chunkSize;
415
- try {
416
- const result = await this.uploadWithRetry(
417
- this.primaryProvider,
418
- this.options.provider,
419
- options,
420
- needsChunking
421
- );
422
- return this.buildUploadResult(result.cid, result.size, startTime, options.pin ?? true);
423
- } catch (primaryError) {
424
- console.warn(`Primary provider ${this.options.provider} failed:`, primaryError);
425
- for (let i = 0; i < this.fallbackProviders.length; i++) {
426
- const provider = this.fallbackProviders[i];
427
- const providerType = this.options.fallbackProviders[i].provider;
428
- try {
429
- const result = await this.uploadWithRetry(provider, providerType, options, needsChunking);
430
- return this.buildUploadResult(result.cid, result.size, startTime, options.pin ?? true);
431
- } catch (error) {
432
- console.warn(`Fallback provider ${providerType} failed:`, error);
433
- continue;
434
- }
435
- }
436
- throw new IPFSUploadError(
437
- "Upload failed on all providers",
438
- this.options.provider,
439
- primaryError
440
- );
441
- }
442
- }
443
- /**
444
- * Upload with retry logic
445
- */
446
- async uploadWithRetry(provider, providerType, options, needsChunking) {
447
- let lastError;
448
- for (let attempt = 0; attempt < this.options.maxRetries; attempt++) {
449
- try {
450
- if (needsChunking) {
451
- return await this.uploadChunked(provider, options);
452
- } else {
453
- if (options.onProgress) {
454
- const totalSize = options.files.reduce((sum, file) => {
455
- const size = file.content instanceof Buffer || file.content instanceof Uint8Array ? file.content.length : Buffer.from(file.content).length;
456
- return sum + size;
457
- }, 0);
458
- let uploadedBytes = 0;
459
- for (const file of options.files) {
460
- const size = file.content instanceof Buffer || file.content instanceof Uint8Array ? file.content.length : Buffer.from(file.content).length;
461
- uploadedBytes += size;
462
- options.onProgress({
463
- uploadedBytes,
464
- totalBytes: totalSize,
465
- percentage: uploadedBytes / totalSize * 100,
466
- currentFile: file.path
467
- });
468
- }
469
- }
470
- return await provider.upload(options.files, options);
471
- }
472
- } catch (error) {
473
- lastError = error;
474
- if (attempt < this.options.maxRetries - 1) {
475
- const delay = this.options.retryDelay * Math.pow(2, attempt);
476
- await this.delay(delay);
477
- }
478
- }
479
- }
480
- throw new IPFSUploadError(
481
- `Upload failed after ${this.options.maxRetries} attempts`,
482
- providerType,
483
- lastError
484
- );
485
- }
486
- /**
487
- * Upload large files in chunks
488
- *
489
- * Breaks large files into smaller chunks, uploads them separately,
490
- * and combines them into a single IPFS directory.
491
- */
492
- async uploadChunked(provider, options) {
493
- const chunks = [];
494
- let totalSize = 0;
495
- let uploadedBytes = 0;
496
- for (const file of options.files) {
497
- const content = file.content instanceof Buffer || file.content instanceof Uint8Array ? file.content : Buffer.from(file.content);
498
- const fileSize = content.length;
499
- totalSize += fileSize;
500
- if (fileSize > this.options.chunkSize) {
501
- const numChunks = Math.ceil(fileSize / this.options.chunkSize);
502
- for (let i = 0; i < numChunks; i++) {
503
- const start = i * this.options.chunkSize;
504
- const end = Math.min(start + this.options.chunkSize, fileSize);
505
- const chunk = content.slice(start, end);
506
- chunks.push({
507
- path: `${file.path}.chunk${i}`,
508
- content: chunk
509
- });
510
- uploadedBytes += chunk.length;
511
- if (options.onProgress) {
512
- options.onProgress({
513
- uploadedBytes,
514
- totalBytes: totalSize,
515
- percentage: uploadedBytes / totalSize * 100,
516
- currentFile: file.path
517
- });
518
- }
519
- }
520
- } else {
521
- chunks.push(file);
522
- uploadedBytes += fileSize;
523
- if (options.onProgress) {
524
- options.onProgress({
525
- uploadedBytes,
526
- totalBytes: totalSize,
527
- percentage: uploadedBytes / totalSize * 100,
528
- currentFile: file.path
529
- });
530
- }
531
- }
532
- }
533
- return await provider.upload(chunks, options);
534
- }
535
- /**
536
- * Build upload result
537
- */
538
- buildUploadResult(cid, size, startTime, pinned) {
539
- const gatewayUrl = `${this.options.gatewayUrl}/${cid}`;
540
- const cdnUrl = this.options.enableCDN ? `${this.cdnGateway}/${cid}` : void 0;
541
- return {
542
- cid,
543
- uri: `ipfs://${cid}`,
544
- gatewayUrl,
545
- cdnUrl,
546
- pinned,
547
- size,
548
- duration: Date.now() - startTime
549
- };
550
- }
551
- /**
552
- * Pin existing CID to IPFS
553
- *
554
- * @param cid IPFS CID to pin
555
- * @param name Optional name for the pin
556
- * @throws {IPFSPinError} If pin operation fails
557
- */
558
- async pin(cid, name) {
559
- try {
560
- await this.primaryProvider.pin(cid, name);
561
- } catch (error) {
562
- throw new IPFSPinError(`Failed to pin CID ${cid}`, cid, error);
563
- }
564
- }
565
- /**
566
- * Unpin CID from IPFS
567
- *
568
- * @param cid IPFS CID to unpin
569
- * @throws {IPFSPinError} If unpin operation fails
570
- */
571
- async unpin(cid) {
572
- try {
573
- await this.primaryProvider.unpin(cid);
574
- } catch (error) {
575
- throw new IPFSPinError(`Failed to unpin CID ${cid}`, cid, error);
576
- }
577
- }
578
- /**
579
- * Get pin status for CID
580
- *
581
- * @param cid IPFS CID to check
582
- * @returns Pin status ('pinned', 'pinning', or 'unpinned')
583
- */
584
- async getPinStatus(cid) {
585
- return await this.primaryProvider.getPinStatus(cid);
586
- }
587
- /**
588
- * Verify CID exists and is accessible
589
- *
590
- * @param cid IPFS CID to verify
591
- * @returns True if CID is accessible
592
- */
593
- async verifyCID(cid) {
594
- return await this.primaryProvider.verifyCID(cid);
595
- }
596
- /**
597
- * Get file from IPFS
598
- *
599
- * @param cid IPFS CID
600
- * @param path Optional path within directory
601
- * @returns File content as Uint8Array
602
- */
603
- async get(cid, path) {
604
- const url = path ? `${this.options.gatewayUrl}/${cid}/${path}` : `${this.options.gatewayUrl}/${cid}`;
605
- const response = await fetch(url);
606
- if (!response.ok) {
607
- throw new Error(`Failed to fetch CID ${cid}: ${response.statusText}`);
608
- }
609
- const buffer = await response.arrayBuffer();
610
- return new Uint8Array(buffer);
611
- }
612
- /**
613
- * List all pins for account
614
- *
615
- * @returns Array of pin information
616
- */
617
- async listPins() {
618
- return await this.primaryProvider.listPins();
619
- }
620
- /**
621
- * Delay helper for retry logic
622
- */
623
- delay(ms) {
624
- return new Promise((resolve) => setTimeout(resolve, ms));
625
- }
626
- /**
627
- * Get CDN URL for CID
628
- *
629
- * @param cid IPFS CID
630
- * @returns CDN URL if enabled, otherwise gateway URL
631
- */
632
- getCDNUrl(cid) {
633
- return this.options.enableCDN ? `${this.cdnGateway}/${cid}` : `${this.options.gatewayUrl}/${cid}`;
634
- }
635
- /**
636
- * Get gateway URL for CID
637
- *
638
- * @param cid IPFS CID
639
- * @returns Gateway URL
640
- */
641
- getGatewayUrl(cid) {
642
- return `${this.options.gatewayUrl}/${cid}`;
643
- }
644
- /**
645
- * Get IPFS URI for CID
646
- *
647
- * @param cid IPFS CID
648
- * @returns IPFS URI (ipfs://...)
649
- */
650
- getIPFSUri(cid) {
651
- return `ipfs://${cid}`;
652
- }
653
- };
654
-
655
- exports.FileSizeExceededError = FileSizeExceededError;
656
- exports.IPFSPinError = IPFSPinError;
657
- exports.IPFSService = IPFSService;
658
- exports.IPFSUploadError = IPFSUploadError;
659
- exports.InfuraProvider = InfuraProvider;
660
- exports.NFTStorageProvider = NFTStorageProvider;
661
- exports.PinataProvider = PinataProvider;
662
- //# sourceMappingURL=chunk-7LCYLPW2.cjs.map
663
- //# sourceMappingURL=chunk-7LCYLPW2.cjs.map