@banou/ponyfill 0.0.1 → 0.0.3

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Banou
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/build/storage.cjs CHANGED
@@ -21,31 +21,52 @@ var QUOTA_CEILING = {
21
21
  };
22
22
  var isDirectory = (handle) => typeof handle.values === "function";
23
23
  /**
24
- * Every byte under a directory, measured rather than asked for.
24
+ * Never walk forever: a cycle is impossible in OPFS, but a pathological tree is not worth the tick.
25
25
  *
26
- * Recursive, and it counts a file's REPORTED SIZE, which for OPFS is the file's extent rather than
27
- * how much of it has been written. That is the same accounting the quota system uses, which is the
28
- * whole point: a one byte write a gigabyte into a file is charged a gigabyte, and a measurement that
29
- * disagreed with the charge would be no more useful than the figure it replaces.
26
+ * These are bounds, not correctness: hitting either returns what was counted so far rather than
27
+ * failing, which keeps the answer a floor in the same direction as everything else here.
28
+ */
29
+ var MAX_DEPTH = 8;
30
+ var MAX_ENTRIES = 2e4;
31
+ /**
32
+ * Every byte under a directory, measured rather than asked for, or `null` when the walk could not
33
+ * be done at all.
34
+ *
35
+ * The null is a distinct third answer and callers depend on it: "the origin holds nothing" and "the
36
+ * file system was unreachable" lead to opposite decisions, and collapsing them to 0 would have
37
+ * {@link correctedUsage} report an empty origin for one that simply could not be read.
38
+ *
39
+ * Counts a file's REPORTED SIZE, which for OPFS is its extent rather than how much of it has been
40
+ * written. That is the same accounting the quota system uses, which is the point: a one byte write a
41
+ * gigabyte into a file is charged a gigabyte, and a measurement disagreeing with the charge would be
42
+ * no more useful than the figure it replaces.
30
43
  *
31
- * An unreadable entry is SKIPPED rather than fatal. A file the engine currently holds an exclusive
32
- * sync access handle for cannot be opened by anyone else, and a walk that threw on the first of
33
- * those would return nothing for exactly the origins that hold the most.
44
+ * An unreadable ENTRY is skipped rather than fatal. A file the engine currently holds an exclusive
45
+ * sync access handle for cannot be opened by anyone else, and `getFile()` on it throws rather than
46
+ * waiting, so a walk that gave up on the first of those would return nothing for exactly the origins
47
+ * holding the most. The answer is therefore a floor: short by the files open right now, never long.
34
48
  */
35
- var measureDirectoryBytes = async (directory) => {
49
+ var measureDirectoryBytes = async (directory, { maxDepth = 8, maxEntries = MAX_ENTRIES } = {}) => {
36
50
  let total = 0;
37
- const visit = async (handle) => {
51
+ let seen = 0;
52
+ const visit = async (handle, depth) => {
53
+ if (depth > maxDepth) return;
38
54
  for await (const child of handle.values()) {
55
+ if (++seen > maxEntries) return;
39
56
  if (isDirectory(child)) {
40
- await visit(child);
57
+ await visit(child, depth + 1);
41
58
  continue;
42
59
  }
43
60
  const file = await child.getFile().catch(() => null);
44
61
  if (file) total += file.size;
45
62
  }
46
63
  };
47
- await visit(directory);
48
- return total;
64
+ try {
65
+ await visit(directory, 0);
66
+ return total;
67
+ } catch {
68
+ return null;
69
+ }
49
70
  };
50
71
  /**
51
72
  * The usage figure to believe, given what the browser said and what a walk found.
@@ -156,6 +177,8 @@ var measureQuotaCeiling = async ({ probeBytes = 536870912, name = ".ponyfill-quo
156
177
  }
157
178
  };
158
179
  //#endregion
180
+ exports.MAX_DEPTH = MAX_DEPTH;
181
+ exports.MAX_ENTRIES = MAX_ENTRIES;
159
182
  exports.QUOTA_CEILING = QUOTA_CEILING;
160
183
  exports.correctedUsage = correctedUsage;
161
184
  exports.isUsageUnderReported = isUsageUnderReported;
@@ -90,18 +90,35 @@ type WalkableFile = {
90
90
  }>;
91
91
  };
92
92
  /**
93
- * Every byte under a directory, measured rather than asked for.
93
+ * Never walk forever: a cycle is impossible in OPFS, but a pathological tree is not worth the tick.
94
94
  *
95
- * Recursive, and it counts a file's REPORTED SIZE, which for OPFS is the file's extent rather than
96
- * how much of it has been written. That is the same accounting the quota system uses, which is the
97
- * whole point: a one byte write a gigabyte into a file is charged a gigabyte, and a measurement that
98
- * disagreed with the charge would be no more useful than the figure it replaces.
99
- *
100
- * An unreadable entry is SKIPPED rather than fatal. A file the engine currently holds an exclusive
101
- * sync access handle for cannot be opened by anyone else, and a walk that threw on the first of
102
- * those would return nothing for exactly the origins that hold the most.
95
+ * These are bounds, not correctness: hitting either returns what was counted so far rather than
96
+ * failing, which keeps the answer a floor in the same direction as everything else here.
97
+ */
98
+ export declare const MAX_DEPTH = 8;
99
+ export declare const MAX_ENTRIES = 20000;
100
+ /**
101
+ * Every byte under a directory, measured rather than asked for, or `null` when the walk could not
102
+ * be done at all.
103
+ *
104
+ * The null is a distinct third answer and callers depend on it: "the origin holds nothing" and "the
105
+ * file system was unreachable" lead to opposite decisions, and collapsing them to 0 would have
106
+ * {@link correctedUsage} report an empty origin for one that simply could not be read.
107
+ *
108
+ * Counts a file's REPORTED SIZE, which for OPFS is its extent rather than how much of it has been
109
+ * written. That is the same accounting the quota system uses, which is the point: a one byte write a
110
+ * gigabyte into a file is charged a gigabyte, and a measurement disagreeing with the charge would be
111
+ * no more useful than the figure it replaces.
112
+ *
113
+ * An unreadable ENTRY is skipped rather than fatal. A file the engine currently holds an exclusive
114
+ * sync access handle for cannot be opened by anyone else, and `getFile()` on it throws rather than
115
+ * waiting, so a walk that gave up on the first of those would return nothing for exactly the origins
116
+ * holding the most. The answer is therefore a floor: short by the files open right now, never long.
103
117
  */
104
- export declare const measureDirectoryBytes: (directory: WalkableDirectory) => Promise<number>;
118
+ export declare const measureDirectoryBytes: (directory: WalkableDirectory, { maxDepth, maxEntries }?: {
119
+ maxDepth?: number;
120
+ maxEntries?: number;
121
+ }) => Promise<number | null>;
105
122
  /**
106
123
  * The usage figure to believe, given what the browser said and what a walk found.
107
124
  *
package/build/storage.js CHANGED
@@ -20,31 +20,52 @@ var QUOTA_CEILING = {
20
20
  };
21
21
  var isDirectory = (handle) => typeof handle.values === "function";
22
22
  /**
23
- * Every byte under a directory, measured rather than asked for.
23
+ * Never walk forever: a cycle is impossible in OPFS, but a pathological tree is not worth the tick.
24
24
  *
25
- * Recursive, and it counts a file's REPORTED SIZE, which for OPFS is the file's extent rather than
26
- * how much of it has been written. That is the same accounting the quota system uses, which is the
27
- * whole point: a one byte write a gigabyte into a file is charged a gigabyte, and a measurement that
28
- * disagreed with the charge would be no more useful than the figure it replaces.
25
+ * These are bounds, not correctness: hitting either returns what was counted so far rather than
26
+ * failing, which keeps the answer a floor in the same direction as everything else here.
27
+ */
28
+ var MAX_DEPTH = 8;
29
+ var MAX_ENTRIES = 2e4;
30
+ /**
31
+ * Every byte under a directory, measured rather than asked for, or `null` when the walk could not
32
+ * be done at all.
33
+ *
34
+ * The null is a distinct third answer and callers depend on it: "the origin holds nothing" and "the
35
+ * file system was unreachable" lead to opposite decisions, and collapsing them to 0 would have
36
+ * {@link correctedUsage} report an empty origin for one that simply could not be read.
37
+ *
38
+ * Counts a file's REPORTED SIZE, which for OPFS is its extent rather than how much of it has been
39
+ * written. That is the same accounting the quota system uses, which is the point: a one byte write a
40
+ * gigabyte into a file is charged a gigabyte, and a measurement disagreeing with the charge would be
41
+ * no more useful than the figure it replaces.
29
42
  *
30
- * An unreadable entry is SKIPPED rather than fatal. A file the engine currently holds an exclusive
31
- * sync access handle for cannot be opened by anyone else, and a walk that threw on the first of
32
- * those would return nothing for exactly the origins that hold the most.
43
+ * An unreadable ENTRY is skipped rather than fatal. A file the engine currently holds an exclusive
44
+ * sync access handle for cannot be opened by anyone else, and `getFile()` on it throws rather than
45
+ * waiting, so a walk that gave up on the first of those would return nothing for exactly the origins
46
+ * holding the most. The answer is therefore a floor: short by the files open right now, never long.
33
47
  */
34
- var measureDirectoryBytes = async (directory) => {
48
+ var measureDirectoryBytes = async (directory, { maxDepth = 8, maxEntries = MAX_ENTRIES } = {}) => {
35
49
  let total = 0;
36
- const visit = async (handle) => {
50
+ let seen = 0;
51
+ const visit = async (handle, depth) => {
52
+ if (depth > maxDepth) return;
37
53
  for await (const child of handle.values()) {
54
+ if (++seen > maxEntries) return;
38
55
  if (isDirectory(child)) {
39
- await visit(child);
56
+ await visit(child, depth + 1);
40
57
  continue;
41
58
  }
42
59
  const file = await child.getFile().catch(() => null);
43
60
  if (file) total += file.size;
44
61
  }
45
62
  };
46
- await visit(directory);
47
- return total;
63
+ try {
64
+ await visit(directory, 0);
65
+ return total;
66
+ } catch {
67
+ return null;
68
+ }
48
69
  };
49
70
  /**
50
71
  * The usage figure to believe, given what the browser said and what a walk found.
@@ -155,4 +176,4 @@ var measureQuotaCeiling = async ({ probeBytes = 536870912, name = ".ponyfill-quo
155
176
  }
156
177
  };
157
178
  //#endregion
158
- export { QUOTA_CEILING, correctedUsage, isUsageUnderReported, measureDirectoryBytes, measureQuotaCeiling, storage };
179
+ export { MAX_DEPTH, MAX_ENTRIES, QUOTA_CEILING, correctedUsage, isUsageUnderReported, measureDirectoryBytes, measureQuotaCeiling, storage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@banou/ponyfill",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "main": "build/index.cjs",
6
6
  "module": "build/index.js",
@@ -25,6 +25,7 @@
25
25
  "test": "vp test run"
26
26
  },
27
27
  "description": "Ponyfills for the places browsers disagree, with the measurement behind each one. Imports only, never a global.",
28
+ "license": "MIT",
28
29
  "devDependencies": {
29
30
  "@types/node": "^25.9.5",
30
31
  "typescript": "^5.9.2",
@@ -38,7 +39,8 @@
38
39
  },
39
40
  "files": [
40
41
  "build",
41
- "README.md"
42
+ "README.md",
43
+ "LICENSE"
42
44
  ],
43
45
  "publishConfig": {
44
46
  "access": "public"