@heyputer/puter.js 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 (74) hide show
  1. package/APACHE_LICENSE.txt +201 -0
  2. package/README.md +88 -0
  3. package/doc/devlog.md +49 -0
  4. package/package.json +31 -0
  5. package/src/bg.png +0 -0
  6. package/src/bg.webp +0 -0
  7. package/src/index.js +745 -0
  8. package/src/lib/APICallLogger.js +110 -0
  9. package/src/lib/EventListener.js +51 -0
  10. package/src/lib/RequestError.js +6 -0
  11. package/src/lib/filesystem/APIFS.js +73 -0
  12. package/src/lib/filesystem/CacheFS.js +243 -0
  13. package/src/lib/filesystem/PostMessageFS.js +40 -0
  14. package/src/lib/filesystem/definitions.js +39 -0
  15. package/src/lib/path.js +509 -0
  16. package/src/lib/polyfills/localStorage.js +92 -0
  17. package/src/lib/polyfills/xhrshim.js +233 -0
  18. package/src/lib/socket.io/socket.io.esm.min.js +7 -0
  19. package/src/lib/socket.io/socket.io.esm.min.js.map +1 -0
  20. package/src/lib/socket.io/socket.io.js +4385 -0
  21. package/src/lib/socket.io/socket.io.js.map +1 -0
  22. package/src/lib/socket.io/socket.io.min.js +7 -0
  23. package/src/lib/socket.io/socket.io.min.js.map +1 -0
  24. package/src/lib/socket.io/socket.io.msgpack.min.js +7 -0
  25. package/src/lib/socket.io/socket.io.msgpack.min.js.map +1 -0
  26. package/src/lib/utils.js +620 -0
  27. package/src/lib/xdrpc.js +104 -0
  28. package/src/modules/AI.js +680 -0
  29. package/src/modules/Apps.js +215 -0
  30. package/src/modules/Auth.js +171 -0
  31. package/src/modules/Debug.js +39 -0
  32. package/src/modules/Drivers.js +278 -0
  33. package/src/modules/FSItem.js +139 -0
  34. package/src/modules/FileSystem/index.js +187 -0
  35. package/src/modules/FileSystem/operations/copy.js +64 -0
  36. package/src/modules/FileSystem/operations/deleteFSEntry.js +59 -0
  37. package/src/modules/FileSystem/operations/getReadUrl.js +42 -0
  38. package/src/modules/FileSystem/operations/mkdir.js +62 -0
  39. package/src/modules/FileSystem/operations/move.js +75 -0
  40. package/src/modules/FileSystem/operations/read.js +46 -0
  41. package/src/modules/FileSystem/operations/readdir.js +102 -0
  42. package/src/modules/FileSystem/operations/rename.js +58 -0
  43. package/src/modules/FileSystem/operations/sign.js +103 -0
  44. package/src/modules/FileSystem/operations/space.js +40 -0
  45. package/src/modules/FileSystem/operations/stat.js +95 -0
  46. package/src/modules/FileSystem/operations/symlink.js +55 -0
  47. package/src/modules/FileSystem/operations/upload.js +440 -0
  48. package/src/modules/FileSystem/operations/write.js +65 -0
  49. package/src/modules/FileSystem/utils/getAbsolutePathForApp.js +21 -0
  50. package/src/modules/Hosting.js +138 -0
  51. package/src/modules/KV.js +301 -0
  52. package/src/modules/OS.js +95 -0
  53. package/src/modules/Perms.js +109 -0
  54. package/src/modules/PuterDialog.js +481 -0
  55. package/src/modules/Threads.js +75 -0
  56. package/src/modules/UI.js +1555 -0
  57. package/src/modules/Util.js +38 -0
  58. package/src/modules/Workers.js +120 -0
  59. package/src/modules/networking/PSocket.js +87 -0
  60. package/src/modules/networking/PTLS.js +100 -0
  61. package/src/modules/networking/PWispHandler.js +89 -0
  62. package/src/modules/networking/parsers.js +157 -0
  63. package/src/modules/networking/requests.js +282 -0
  64. package/src/services/APIAccess.js +46 -0
  65. package/src/services/FSRelay.js +20 -0
  66. package/src/services/Filesystem.js +122 -0
  67. package/src/services/NoPuterYet.js +20 -0
  68. package/src/services/XDIncoming.js +44 -0
  69. package/test/ai.test.js +214 -0
  70. package/test/fs.test.js +798 -0
  71. package/test/index.html +1183 -0
  72. package/test/kv.test.js +548 -0
  73. package/test/txt2speech.test.js +178 -0
  74. package/webpack.config.js +25 -0
@@ -0,0 +1,104 @@
1
+ /**
2
+ * This module provides a simple RPC mechanism for cross-document
3
+ * (iframe / window.postMessage) communication.
4
+ */
5
+
6
+ // Since `Symbol` is not clonable, we use a UUID to identify RPCs.
7
+ export const $SCOPE = '9a9c83a4-7897-43a0-93b9-53217b84fde6';
8
+
9
+ /**
10
+ * The CallbackManager is used to manage callbacks for RPCs.
11
+ * It is used by the dehydrator and hydrator to store and retrieve
12
+ * the functions that are being called remotely.
13
+ */
14
+ export class CallbackManager {
15
+ #messageId = 1;
16
+
17
+ constructor () {
18
+ this.callbacks = new Map();
19
+ }
20
+
21
+ register_callback (callback) {
22
+ const id = this.#messageId++;
23
+ this.callbacks.set(id, callback);
24
+ return id;
25
+ }
26
+
27
+ attach_to_source (source) {
28
+ source.addEventListener('message', event => {
29
+ const { data } = event;
30
+ if (data && typeof data === 'object' && data.$SCOPE === $SCOPE) {
31
+ const { id, args } = data;
32
+ const callback = this.callbacks.get(id);
33
+ if (callback) {
34
+ callback(...args);
35
+ }
36
+ }
37
+ });
38
+ }
39
+ }
40
+
41
+ /**
42
+ * The dehydrator replaces functions in an object with identifiers,
43
+ * so that hydrate() can be called on the other side of the frame
44
+ * to bind RPC stubs. The original functions are stored in a map
45
+ * so that they can be called when the RPC is invoked.
46
+ */
47
+ export class Dehydrator {
48
+ constructor ({ callbackManager }) {
49
+ this.callbackManager = callbackManager;
50
+ }
51
+ dehydrate (value) {
52
+ return this.dehydrate_value_(value);
53
+ }
54
+ dehydrate_value_ (value) {
55
+ if (typeof value === 'function') {
56
+ const id = this.callbackManager.register_callback(value);
57
+ return { $SCOPE, id };
58
+ } else if (Array.isArray(value)) {
59
+ return value.map(this.dehydrate_value_.bind(this));
60
+ } else if (typeof value === 'object' && value !== null) {
61
+ const result = {};
62
+ for (const key in value) {
63
+ result[key] = this.dehydrate_value_(value[key]);
64
+ }
65
+ return result;
66
+ } else {
67
+ return value;
68
+ }
69
+ }
70
+ }
71
+
72
+ /**
73
+ * The hydrator binds RPC stubs to the functions that were
74
+ * previously dehydrated. This allows the RPC to be invoked
75
+ * on the other side of the frame.
76
+ */
77
+ export class Hydrator {
78
+ constructor ({ target }) {
79
+ this.target = target;
80
+ }
81
+ hydrate (value) {
82
+ return this.hydrate_value_(value);
83
+ }
84
+ hydrate_value_ (value) {
85
+ if (
86
+ value && typeof value === 'object' &&
87
+ value.$SCOPE === $SCOPE
88
+ ) {
89
+ const { id } = value;
90
+ return (...args) => {
91
+ this.target.postMessage({ $SCOPE, id, args }, '*');
92
+ };
93
+ } else if (Array.isArray(value)) {
94
+ return value.map(this.hydrate_value_.bind(this));
95
+ } else if (typeof value === 'object' && value !== null) {
96
+ const result = {};
97
+ for (const key in value) {
98
+ result[key] = this.hydrate_value_(value[key]);
99
+ }
100
+ return result;
101
+ }
102
+ return value;
103
+ }
104
+ }