@heyputer/puter.js 2.0.0 → 2.0.1

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/README.md +3 -1
  2. package/index.d.ts +479 -0
  3. package/package.json +15 -4
  4. package/APACHE_LICENSE.txt +0 -201
  5. package/doc/devlog.md +0 -49
  6. package/src/bg.png +0 -0
  7. package/src/bg.webp +0 -0
  8. package/src/lib/APICallLogger.js +0 -110
  9. package/src/lib/EventListener.js +0 -51
  10. package/src/lib/RequestError.js +0 -6
  11. package/src/lib/filesystem/APIFS.js +0 -73
  12. package/src/lib/filesystem/CacheFS.js +0 -243
  13. package/src/lib/filesystem/PostMessageFS.js +0 -40
  14. package/src/lib/filesystem/definitions.js +0 -39
  15. package/src/lib/path.js +0 -509
  16. package/src/lib/polyfills/localStorage.js +0 -92
  17. package/src/lib/polyfills/xhrshim.js +0 -233
  18. package/src/lib/socket.io/socket.io.esm.min.js +0 -7
  19. package/src/lib/socket.io/socket.io.esm.min.js.map +0 -1
  20. package/src/lib/socket.io/socket.io.js +0 -4385
  21. package/src/lib/socket.io/socket.io.js.map +0 -1
  22. package/src/lib/socket.io/socket.io.min.js +0 -7
  23. package/src/lib/socket.io/socket.io.min.js.map +0 -1
  24. package/src/lib/socket.io/socket.io.msgpack.min.js +0 -7
  25. package/src/lib/socket.io/socket.io.msgpack.min.js.map +0 -1
  26. package/src/lib/utils.js +0 -620
  27. package/src/lib/xdrpc.js +0 -104
  28. package/src/modules/AI.js +0 -680
  29. package/src/modules/Apps.js +0 -215
  30. package/src/modules/Auth.js +0 -171
  31. package/src/modules/Debug.js +0 -39
  32. package/src/modules/Drivers.js +0 -278
  33. package/src/modules/FSItem.js +0 -139
  34. package/src/modules/FileSystem/index.js +0 -187
  35. package/src/modules/FileSystem/operations/copy.js +0 -64
  36. package/src/modules/FileSystem/operations/deleteFSEntry.js +0 -59
  37. package/src/modules/FileSystem/operations/getReadUrl.js +0 -42
  38. package/src/modules/FileSystem/operations/mkdir.js +0 -62
  39. package/src/modules/FileSystem/operations/move.js +0 -75
  40. package/src/modules/FileSystem/operations/read.js +0 -46
  41. package/src/modules/FileSystem/operations/readdir.js +0 -102
  42. package/src/modules/FileSystem/operations/rename.js +0 -58
  43. package/src/modules/FileSystem/operations/sign.js +0 -103
  44. package/src/modules/FileSystem/operations/space.js +0 -40
  45. package/src/modules/FileSystem/operations/stat.js +0 -95
  46. package/src/modules/FileSystem/operations/symlink.js +0 -55
  47. package/src/modules/FileSystem/operations/upload.js +0 -440
  48. package/src/modules/FileSystem/operations/write.js +0 -65
  49. package/src/modules/FileSystem/utils/getAbsolutePathForApp.js +0 -21
  50. package/src/modules/Hosting.js +0 -138
  51. package/src/modules/KV.js +0 -301
  52. package/src/modules/OS.js +0 -95
  53. package/src/modules/Perms.js +0 -109
  54. package/src/modules/PuterDialog.js +0 -481
  55. package/src/modules/Threads.js +0 -75
  56. package/src/modules/UI.js +0 -1555
  57. package/src/modules/Util.js +0 -38
  58. package/src/modules/Workers.js +0 -120
  59. package/src/modules/networking/PSocket.js +0 -87
  60. package/src/modules/networking/PTLS.js +0 -100
  61. package/src/modules/networking/PWispHandler.js +0 -89
  62. package/src/modules/networking/parsers.js +0 -157
  63. package/src/modules/networking/requests.js +0 -282
  64. package/src/services/APIAccess.js +0 -46
  65. package/src/services/FSRelay.js +0 -20
  66. package/src/services/Filesystem.js +0 -122
  67. package/src/services/NoPuterYet.js +0 -20
  68. package/src/services/XDIncoming.js +0 -44
  69. package/test/ai.test.js +0 -214
  70. package/test/fs.test.js +0 -798
  71. package/test/index.html +0 -1183
  72. package/test/kv.test.js +0 -548
  73. package/test/txt2speech.test.js +0 -178
  74. package/webpack.config.js +0 -25
@@ -1,243 +0,0 @@
1
- import putility from "@heyputer/putility";
2
- import { RWLock } from "@heyputer/putility/src/libs/promise.js";
3
- import { ProxyFilesystem, TFilesystem } from "./definitions.js";
4
- import { uuidv4 } from "../utils.js";
5
-
6
- export const ROOT_UUID = '00000000-0000-0000-0000-000000000000';
7
- const TTL = 5 * 1000;
8
-
9
- export class CacheFS extends putility.AdvancedBase {
10
- static PROPERTIES = {
11
- assocs_path_: () => ({}),
12
- assocs_uuid_: () => ({}),
13
- entries: () => ({}),
14
- };
15
-
16
- get_entry_ei (external_identifier) {
17
- if ( Array.isArray(external_identifier) ) {
18
- for ( const ei of external_identifier ) {
19
- const entry = this.get_entry_ei(ei);
20
- if ( entry ) return entry;
21
- }
22
- return;
23
- }
24
-
25
- console.log('GET ENTRY EI', external_identifier);
26
-
27
- const internal_identifier =
28
- this.assocs_path_[external_identifier] ||
29
- this.assocs_uuid_[external_identifier] ||
30
- external_identifier;
31
-
32
- if ( ! internal_identifier ) {
33
- return;
34
- }
35
- return this.entries[internal_identifier];
36
- }
37
-
38
- add_entry ({ id } = {}) {
39
- const internal_identifier = id ?? uuidv4();
40
- const entry = {
41
- id: internal_identifier,
42
- stat_has: {},
43
- stat_exp: 0,
44
- locks: {
45
- stat: new RWLock(),
46
- members: new RWLock(),
47
- },
48
- };
49
- this.entries[internal_identifier] = entry;
50
- return entry;
51
- }
52
-
53
- assoc_path (path, internal_identifier) {
54
- console.log('ASSOC PATH', path, internal_identifier);
55
- this.assocs_path_[path] = internal_identifier;
56
- }
57
-
58
- assoc_uuid (uuid, internal_identifier) {
59
- if ( uuid === internal_identifier ) return;
60
- this.assocs_uuid_[uuid] = internal_identifier;
61
- }
62
-
63
- }
64
-
65
- export class CachedFilesystem extends ProxyFilesystem {
66
- constructor (o) {
67
- super(o);
68
- // this.cacheFS = cacheFS;
69
- this.cacheFS = new CacheFS();
70
- }
71
- static IMPLEMENTS = {
72
- [TFilesystem]: {
73
- stat: async function (o) {
74
- let cent = this.cacheFS.get_entry_ei(o.path ?? o.uid);
75
-
76
- const modifiers = [
77
- 'subdomains',
78
- 'permissions',
79
- 'versions',
80
- 'size',
81
- ];
82
-
83
- let values_requested = {};
84
- for ( const mod of modifiers ) {
85
- const optionsKey = 'return' +
86
- mod.charAt(0).toUpperCase() +
87
- mod.slice(1);
88
- if ( ! o[optionsKey] ) continue;
89
- values_requested[mod] = true;
90
- }
91
-
92
- const satisfactory_cache = cent => {
93
- for ( const mod of modifiers ) {
94
- if ( ! values_requested[mod] ) continue;
95
- if ( ! cent.stat_has[mod] ) {
96
- return false;
97
- }
98
- }
99
- return true;
100
- }
101
-
102
- let cached_stat;
103
- if ( cent && cent.stat && cent.stat_exp > Date.now() ) {
104
- const l = await cent.locks.stat.rlock();
105
- if ( satisfactory_cache(cent) ) {
106
- cached_stat = cent.stat;
107
- }
108
- l.unlock();
109
- }
110
-
111
- if ( cached_stat ) {
112
- console.log('CACHE HIT');
113
- return cached_stat;
114
- }
115
- console.log('CACHE MISS');
116
-
117
- let l;
118
- if ( cent ) {
119
- l = await cent.locks.stat.wlock();
120
- }
121
-
122
- console.log('DOING THE STAT', o);
123
- const entry = await this.delegate.stat(o);
124
-
125
- // We might have new information to identify a relevant cache entry
126
- let cent_replaced = !! cent;
127
- cent = this.cacheFS.get_entry_ei([entry.uid, entry.path]);
128
- if ( cent ) {
129
- if ( cent_replaced ) l.unlock();
130
- l = await cent.locks.stat.wlock();
131
- }
132
-
133
- if ( ! cent ) {
134
- cent = this.cacheFS.add_entry({ id: entry.uid });
135
- this.cacheFS.assoc_path(entry.path, cent.id);
136
- this.cacheFS.assoc_uuid(entry.uid, cent.id);
137
-
138
- l = await cent.locks.stat.wlock();
139
- }
140
-
141
- cent.stat = entry;
142
- cent.stat_has = { ...values_requested };
143
- // TODO: increase cache TTL once invalidation works
144
- cent.stat_exp = Date.now() + TTL;
145
-
146
- l.unlock();
147
-
148
- console.log('RETRUNING THE ENTRY', entry);
149
- return entry;
150
- },
151
- readdir: async function (o) {
152
- let cent = this.cacheFS.get_entry_ei([o.path, o.uid]);
153
-
154
- console.log('CENT', cent, o);
155
- let stats = null;
156
- if ( cent && cent.members && cent.members_exp > Date.now() ) {
157
- console.log('MEMBERS', cent.members);
158
- stats = [];
159
- const l = await cent.locks.stat.rlock();
160
-
161
- for ( const id of cent.members ) {
162
- const member = this.cacheFS.get_entry_ei(id);
163
- if ( ! member || ! member.stat || member.stat_exp <= Date.now() ) {
164
- console.log('NO MEMBER OR STAT', member);
165
- stats = null;
166
- break;
167
- }
168
- console.log('member', member);
169
- if ( ! o.no_assocs && ! member.stat_has.subdomains ) {
170
- stats = null;
171
- break;
172
- }
173
- if ( ! o.no_assocs && ! member.stat_has.apps ) {
174
- stats = null;
175
- break;
176
- }
177
- if ( ! o.no_thumbs && ! member.stat_has.thumbnail ) {
178
- stats = null;
179
- break;
180
- }
181
- console.log('PUSHING', member.stat);
182
-
183
- stats.push(member.stat);
184
- }
185
-
186
- l.unlock();
187
- }
188
-
189
- console.log('STATS????', stats);
190
- if ( stats ) {
191
- return stats;
192
- }
193
-
194
- let l;
195
- if ( cent ) {
196
- l = await cent.locks.members.wlock();
197
- }
198
-
199
- const entries = await this.delegate.readdir(o);
200
- if ( ! cent ) {
201
- cent = this.cacheFS.add_entry(o.uid ? { id: o.uid } : {});
202
- if ( o.path ) this.cacheFS.assoc_path(o.path, cent.id);
203
- l = await cent.locks.members.wlock();
204
- }
205
-
206
- let cent_ids = [];
207
- for ( const entry of entries ) {
208
- let entry_cent = this.cacheFS.get_entry_ei([entry.path, entry.uid]);
209
- if ( ! entry_cent ) {
210
- entry_cent = this.cacheFS.add_entry({ id: entry.uid });
211
- this.cacheFS.assoc_path(entry.path, entry.uid);
212
- }
213
- cent_ids.push(entry_cent.id);
214
- // TODO: update_stat_ is not implemented
215
- // this.cacheFS.update_stat_(entry_cent, entry, {
216
- // subdomains: ! o.no_assocs,
217
- // apps: ! o.no_assocs,
218
- // thumbnail: ! o.no_thumbs,
219
- // });
220
- entry_cent.stat = entry;
221
- entry_cent.stat_has = {
222
- subdomains: ! o.no_assocs,
223
- apps: ! o.no_assocs,
224
- thumbnail: ! o.no_thumbs,
225
- }
226
- entry_cent.stat_exp = Date.now() + 1000*3;
227
- }
228
-
229
- cent.members = []
230
- for ( const id of cent_ids ) {
231
- cent.members.push(id);
232
- }
233
- cent.members_exp = Date.now() + TTL;
234
-
235
- l.unlock();
236
-
237
- console.log('CACHE ENTRY?', cent);
238
-
239
- return entries;
240
- }
241
- }
242
- }
243
- }
@@ -1,40 +0,0 @@
1
- import putility from "@heyputer/putility";
2
- import { TFilesystem } from "./definitions.js";
3
-
4
- const example = {
5
- "id": "f485f1ba-de07-422c-8c4b-c2da057d4a44",
6
- "uid": "f485f1ba-de07-422c-8c4b-c2da057d4a44",
7
- "is_dir": true,
8
- "immutable": true,
9
- "name": "Test",
10
- };
11
-
12
- export class PostMessageFilesystem extends putility.AdvancedBase {
13
- constructor ({ rpc, messageTarget }) {
14
- super();
15
- this.rpc = rpc;
16
- this.messageTarget = messageTarget;
17
- }
18
- static IMPLEMENTS = {
19
- [TFilesystem]: {
20
- stat: async function (o) {
21
- return example;
22
- },
23
- readdir: async function (o) {
24
- const tp = new putility.libs.promise.TeePromise();
25
- const $callback = this.rpc.registerCallback((result) => {
26
- tp.resolve(result);
27
- });
28
- // return [example];
29
- this.messageTarget.postMessage({
30
- $: 'puter-fs',
31
- $callback,
32
- op: 'readdir',
33
- args: o,
34
- }, '*');
35
-
36
- return await tp;
37
- }
38
- }
39
- }
40
- }
@@ -1,39 +0,0 @@
1
- import putility from "@heyputer/putility";
2
-
3
- export const TFilesystem = 'TFilesystem';
4
-
5
- // TODO: UNUSED (eventually putility will support these definitions)
6
- // This is here so that the idea is not forgotten.
7
- export const IFilesystem = {
8
- methods: {
9
- stat: {
10
- parameters: {
11
- path: {
12
- alias: 'uid',
13
- }
14
- }
15
- }
16
- }
17
-
18
- };
19
-
20
- export class ProxyFilesystem extends putility.AdvancedBase {
21
- static PROPERTIES = {
22
- delegate: () => {},
23
- }
24
- // TODO: constructor implied by properties
25
- constructor ({ delegate }) {
26
- super();
27
- this.delegate = delegate;
28
- }
29
- static IMPLEMENTS = {
30
- [TFilesystem]: {
31
- stat: async function (o) {
32
- return this.delegate.stat(o);
33
- },
34
- readdir: async function (o) {
35
- return this.delegate.readdir(o);
36
- }
37
- }
38
- }
39
- }