@openlimiter/core 0.1.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.
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +9 -0
- package/dist/cache.d.ts +76 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +326 -0
- package/dist/cache.js.map +1 -0
- package/dist/forecast.d.ts +3 -0
- package/dist/forecast.d.ts.map +1 -0
- package/dist/forecast.js +25 -0
- package/dist/forecast.js.map +1 -0
- package/dist/format.d.ts +15 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +22 -0
- package/dist/format.js.map +1 -0
- package/dist/freshness.d.ts +3 -0
- package/dist/freshness.d.ts.map +1 -0
- package/dist/freshness.js +15 -0
- package/dist/freshness.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/merge.d.ts +12 -0
- package/dist/merge.d.ts.map +1 -0
- package/dist/merge.js +40 -0
- package/dist/merge.js.map +1 -0
- package/dist/normalizer.d.ts +5 -0
- package/dist/normalizer.d.ts.map +1 -0
- package/dist/normalizer.js +127 -0
- package/dist/normalizer.js.map +1 -0
- package/dist/policy.d.ts +3 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +83 -0
- package/dist/policy.js.map +1 -0
- package/dist/types.d.ts +89 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# `@openlimiter/core`
|
|
2
|
+
|
|
3
|
+
Shared types, quota models, cache handling, and forecasts for OpenLimiter.
|
|
4
|
+
|
|
5
|
+
The advice policy recommends only a bounded provider enum. It selects the fresh healthy provider with the lowest usage, uses configured provider order for ties, and returns `NONE` when no provider is usable.
|
|
6
|
+
|
|
7
|
+
Most users should install the [`openlimiter`](https://www.npmjs.com/package/openlimiter) CLI.
|
|
8
|
+
|
|
9
|
+
See the [repository](https://github.com/lucaswebsystems/openlimiter) and [OpenLimiter site](https://openlimiter.com).
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Snapshot } from "./types.js";
|
|
2
|
+
export declare const CACHE_FILE_NAME = "openlimiter-cache.json";
|
|
3
|
+
export declare const CACHE_LOCK_NAME = "openlimiter.lock";
|
|
4
|
+
/** Largest JSON document this package will read into memory. */
|
|
5
|
+
export declare const MAX_JSON_FILE_BYTES = 1048576;
|
|
6
|
+
/** A lock older than this is treated as abandoned and reclaimed. */
|
|
7
|
+
export declare const LOCK_STALE_MILLISECONDS = 5000;
|
|
8
|
+
export interface StateDirectoryOptions {
|
|
9
|
+
platform?: NodeJS.Platform;
|
|
10
|
+
environment?: Readonly<Record<string, string | undefined>>;
|
|
11
|
+
homeDirectory?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function resolveStateDirectory(options?: StateDirectoryOptions): string;
|
|
14
|
+
export type JsonFileResult = {
|
|
15
|
+
ok: true;
|
|
16
|
+
value: unknown;
|
|
17
|
+
} | {
|
|
18
|
+
ok: false;
|
|
19
|
+
reason: "missing" | "corrupt" | "unsafe";
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Read and parse a JSON document without a window between the safety check and
|
|
23
|
+
* the read.
|
|
24
|
+
*
|
|
25
|
+
* The descriptor is opened first and every check runs against that descriptor,
|
|
26
|
+
* so a path swapped after the open cannot redirect the bytes that come back.
|
|
27
|
+
* The path is compared with the open object by device and inode, which rejects
|
|
28
|
+
* a symbolic link, a junction, and a file replaced mid read.
|
|
29
|
+
*/
|
|
30
|
+
export declare function readJsonFileSafely(file: string, maximumBytes?: number): Promise<JsonFileResult>;
|
|
31
|
+
export type CacheReadResult = {
|
|
32
|
+
ok: true;
|
|
33
|
+
snapshots: Snapshot[];
|
|
34
|
+
dropped: number;
|
|
35
|
+
} | {
|
|
36
|
+
ok: false;
|
|
37
|
+
reason: "missing" | "corrupt" | "unsafe";
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Read the snapshot cache.
|
|
41
|
+
*
|
|
42
|
+
* A row that fails validation is dropped and counted. The surviving rows are
|
|
43
|
+
* still returned, because one bad row is not a reason to forget every other
|
|
44
|
+
* provider. No value is ever repaired or invented.
|
|
45
|
+
*/
|
|
46
|
+
export declare function readSnapshotCache(directory?: string): Promise<CacheReadResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Write a file so that a reader sees either the previous content or the new
|
|
49
|
+
* content, never a partial write.
|
|
50
|
+
*
|
|
51
|
+
* The payload is flushed to stable storage before the rename, so a crash right
|
|
52
|
+
* after the rename cannot leave an empty file behind.
|
|
53
|
+
*/
|
|
54
|
+
export declare function writeFileAtomically(target: string, contents: string): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Replace the snapshot cache.
|
|
57
|
+
*
|
|
58
|
+
* Every snapshot is revalidated before anything touches the disk, the payload
|
|
59
|
+
* is flushed to stable storage before the rename, and the lock carries an owner
|
|
60
|
+
* stamp so a writer that died cannot freeze the cache forever.
|
|
61
|
+
*/
|
|
62
|
+
export declare function writeSnapshotCache(snapshots: readonly Snapshot[], directory?: string): Promise<void>;
|
|
63
|
+
export interface CacheMergeResult {
|
|
64
|
+
merged: Snapshot[];
|
|
65
|
+
written: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Fold fresh snapshots into the cache under the lock.
|
|
69
|
+
*
|
|
70
|
+
* Reading, merging, and writing all happen inside one lock, so two writers that
|
|
71
|
+
* observe different providers cannot silently drop each other's rows. An
|
|
72
|
+
* unchanged result skips the write entirely, which keeps a statusline that
|
|
73
|
+
* renders on every keystroke from churning the disk.
|
|
74
|
+
*/
|
|
75
|
+
export declare function mergeSnapshotCache(incoming: readonly Snapshot[], directory?: string): Promise<CacheMergeResult>;
|
|
76
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAY,QAAQ,EAAE,MAAM,YAAY,CAAC;AAErD,eAAO,MAAM,eAAe,2BAA2B,CAAC;AACxD,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAElD,gEAAgE;AAChE,eAAO,MAAM,mBAAmB,UAAY,CAAC;AAE7C,oEAAoE;AACpE,eAAO,MAAM,uBAAuB,OAAQ,CAAC;AAK7C,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC3B,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAC3D,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAgBjF;AA0BD,MAAM,MAAM,cAAc,GACtB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC5B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAA;CAAE,CAAC;AAU5D;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,YAAY,SAAsB,GACjC,OAAO,CAAC,cAAc,CAAC,CA6BzB;AAED,MAAM,MAAM,eAAe,GACvB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,QAAQ,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAA;CAAE,CAAC;AAE5D;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,SAA0B,GAClC,OAAO,CAAC,eAAe,CAAC,CAc1B;AAyCD;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAgBf;AAsGD;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,SAAS,QAAQ,EAAE,EAC9B,SAAS,SAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CAKf;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,SAAS,QAAQ,EAAE,EAC7B,SAAS,SAA0B,GAClC,OAAO,CAAC,gBAAgB,CAAC,CAa3B"}
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { chmod, lstat, mkdir, open, readFile, rename, unlink } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { MAX_CACHE_ENTRIES, mergeSnapshots } from "./merge.js";
|
|
7
|
+
import { canonicalJson, normalizeMeter, normalizeMeters } from "./normalizer.js";
|
|
8
|
+
export const CACHE_FILE_NAME = "openlimiter-cache.json";
|
|
9
|
+
export const CACHE_LOCK_NAME = "openlimiter.lock";
|
|
10
|
+
/** Largest JSON document this package will read into memory. */
|
|
11
|
+
export const MAX_JSON_FILE_BYTES = 1_048_576;
|
|
12
|
+
/** A lock older than this is treated as abandoned and reclaimed. */
|
|
13
|
+
export const LOCK_STALE_MILLISECONDS = 5_000;
|
|
14
|
+
const LOCK_ATTEMPT_LIMIT = 40;
|
|
15
|
+
const LOCK_BACKOFF_CEILING_MILLISECONDS = 25;
|
|
16
|
+
export function resolveStateDirectory(options = {}) {
|
|
17
|
+
const platform = options.platform ?? process.platform;
|
|
18
|
+
const environment = options.environment ?? process.env;
|
|
19
|
+
const home = options.homeDirectory ?? homedir();
|
|
20
|
+
if (platform === "win32") {
|
|
21
|
+
const local = environment["LOCALAPPDATA"];
|
|
22
|
+
return path.join(local === undefined || local === "" ? home : local, "openlimiter");
|
|
23
|
+
}
|
|
24
|
+
if (platform === "darwin") {
|
|
25
|
+
return path.join(home, "Library", "Application Support", "openlimiter");
|
|
26
|
+
}
|
|
27
|
+
const xdg = environment["XDG_STATE_HOME"];
|
|
28
|
+
return path.join(xdg === undefined || xdg === "" ? path.join(home, ".local", "state") : xdg, "openlimiter");
|
|
29
|
+
}
|
|
30
|
+
function isRecord(value) {
|
|
31
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32
|
+
}
|
|
33
|
+
function errorCode(error) {
|
|
34
|
+
return error.code;
|
|
35
|
+
}
|
|
36
|
+
async function rejectSymlink(target) {
|
|
37
|
+
try {
|
|
38
|
+
const stat = await lstat(target);
|
|
39
|
+
if (stat.isSymbolicLink())
|
|
40
|
+
throw new Error("State path is a symbolic link");
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (errorCode(error) !== "ENOENT")
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async function prepareStateDirectory(directory) {
|
|
48
|
+
await rejectSymlink(directory);
|
|
49
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
50
|
+
await rejectSymlink(directory);
|
|
51
|
+
if (process.platform !== "win32")
|
|
52
|
+
await chmod(directory, 0o700);
|
|
53
|
+
}
|
|
54
|
+
/*
|
|
55
|
+
* O_NOFOLLOW makes the kernel refuse a final path component that is a symbolic
|
|
56
|
+
* link. Windows does not define it, so the constant collapses to zero there and
|
|
57
|
+
* the identity comparison below carries the check on its own.
|
|
58
|
+
*/
|
|
59
|
+
const openFlags = constants.O_RDONLY |
|
|
60
|
+
(typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0);
|
|
61
|
+
/**
|
|
62
|
+
* Read and parse a JSON document without a window between the safety check and
|
|
63
|
+
* the read.
|
|
64
|
+
*
|
|
65
|
+
* The descriptor is opened first and every check runs against that descriptor,
|
|
66
|
+
* so a path swapped after the open cannot redirect the bytes that come back.
|
|
67
|
+
* The path is compared with the open object by device and inode, which rejects
|
|
68
|
+
* a symbolic link, a junction, and a file replaced mid read.
|
|
69
|
+
*/
|
|
70
|
+
export async function readJsonFileSafely(file, maximumBytes = MAX_JSON_FILE_BYTES) {
|
|
71
|
+
let handle;
|
|
72
|
+
try {
|
|
73
|
+
handle = await open(file, openFlags);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
const code = errorCode(error);
|
|
77
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
78
|
+
return { ok: false, reason: "missing" };
|
|
79
|
+
return { ok: false, reason: "unsafe" };
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const opened = await handle.stat();
|
|
83
|
+
if (!opened.isFile())
|
|
84
|
+
return { ok: false, reason: "unsafe" };
|
|
85
|
+
if (opened.size > maximumBytes)
|
|
86
|
+
return { ok: false, reason: "corrupt" };
|
|
87
|
+
const linked = await lstat(file);
|
|
88
|
+
if (linked.isSymbolicLink())
|
|
89
|
+
return { ok: false, reason: "unsafe" };
|
|
90
|
+
if (linked.dev !== opened.dev || linked.ino !== opened.ino) {
|
|
91
|
+
return { ok: false, reason: "unsafe" };
|
|
92
|
+
}
|
|
93
|
+
const text = await handle.readFile("utf8");
|
|
94
|
+
try {
|
|
95
|
+
return { ok: true, value: JSON.parse(text) };
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return { ok: false, reason: "corrupt" };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return { ok: false, reason: "unsafe" };
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
await handle.close().catch(() => undefined);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Read the snapshot cache.
|
|
110
|
+
*
|
|
111
|
+
* A row that fails validation is dropped and counted. The surviving rows are
|
|
112
|
+
* still returned, because one bad row is not a reason to forget every other
|
|
113
|
+
* provider. No value is ever repaired or invented.
|
|
114
|
+
*/
|
|
115
|
+
export async function readSnapshotCache(directory = resolveStateDirectory()) {
|
|
116
|
+
try {
|
|
117
|
+
await rejectSymlink(directory);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return { ok: false, reason: "unsafe" };
|
|
121
|
+
}
|
|
122
|
+
const document = await readJsonFileSafely(path.join(directory, CACHE_FILE_NAME));
|
|
123
|
+
if (!document.ok)
|
|
124
|
+
return document;
|
|
125
|
+
if (!isRecord(document.value))
|
|
126
|
+
return { ok: false, reason: "corrupt" };
|
|
127
|
+
const rawSnapshots = document.value["snapshots"];
|
|
128
|
+
if (!Array.isArray(rawSnapshots))
|
|
129
|
+
return { ok: false, reason: "corrupt" };
|
|
130
|
+
if (rawSnapshots.length > MAX_CACHE_ENTRIES)
|
|
131
|
+
return { ok: false, reason: "corrupt" };
|
|
132
|
+
const snapshots = normalizeMeters(rawSnapshots);
|
|
133
|
+
return { ok: true, snapshots, dropped: rawSnapshots.length - snapshots.length };
|
|
134
|
+
}
|
|
135
|
+
function delay(milliseconds) {
|
|
136
|
+
return new Promise((resolve) => {
|
|
137
|
+
setTimeout(resolve, milliseconds);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function backoffMilliseconds(attempt) {
|
|
141
|
+
const growth = Math.min(4 + attempt * 2, LOCK_BACKOFF_CEILING_MILLISECONDS);
|
|
142
|
+
return growth + Math.floor(Math.random() * 5);
|
|
143
|
+
}
|
|
144
|
+
const RENAME_ATTEMPT_LIMIT = 12;
|
|
145
|
+
const transientRenameCodes = new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
146
|
+
/**
|
|
147
|
+
* Replace a file, retrying the transient failures Windows reports.
|
|
148
|
+
*
|
|
149
|
+
* Windows refuses to replace a destination that another process has open for a
|
|
150
|
+
* moment, which a reader or a virus scanner can cause at any time. The failure
|
|
151
|
+
* clears on its own, so a bounded retry is the difference between a durable
|
|
152
|
+
* write and a lost one. Every other failure is raised immediately.
|
|
153
|
+
*/
|
|
154
|
+
async function renameWithRetry(from, to) {
|
|
155
|
+
for (let attempt = 0;; attempt += 1) {
|
|
156
|
+
try {
|
|
157
|
+
await rename(from, to);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
const code = errorCode(error);
|
|
162
|
+
if (attempt >= RENAME_ATTEMPT_LIMIT ||
|
|
163
|
+
code === undefined ||
|
|
164
|
+
!transientRenameCodes.has(code))
|
|
165
|
+
throw error;
|
|
166
|
+
await delay(backoffMilliseconds(attempt));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Write a file so that a reader sees either the previous content or the new
|
|
172
|
+
* content, never a partial write.
|
|
173
|
+
*
|
|
174
|
+
* The payload is flushed to stable storage before the rename, so a crash right
|
|
175
|
+
* after the rename cannot leave an empty file behind.
|
|
176
|
+
*/
|
|
177
|
+
export async function writeFileAtomically(target, contents) {
|
|
178
|
+
const tempPath = target + "." + process.pid + "." + randomUUID() + ".tmp";
|
|
179
|
+
try {
|
|
180
|
+
const temporary = await open(tempPath, "wx", 0o600);
|
|
181
|
+
try {
|
|
182
|
+
await temporary.writeFile(contents, "utf8");
|
|
183
|
+
await temporary.sync();
|
|
184
|
+
}
|
|
185
|
+
finally {
|
|
186
|
+
await temporary.close();
|
|
187
|
+
}
|
|
188
|
+
if (process.platform !== "win32")
|
|
189
|
+
await chmod(tempPath, 0o600);
|
|
190
|
+
await renameWithRetry(tempPath, target);
|
|
191
|
+
if (process.platform !== "win32")
|
|
192
|
+
await chmod(target, 0o600);
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
await unlink(tempPath).catch(() => undefined);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Decide whether an existing lock has been abandoned and remove it if so.
|
|
200
|
+
*
|
|
201
|
+
* The owner stamp inside the lock is the primary signal. An empty or unreadable
|
|
202
|
+
* lock falls back to the file modification time, which covers the short window
|
|
203
|
+
* between creating the lock and writing the stamp into it.
|
|
204
|
+
*/
|
|
205
|
+
async function reclaimStaleLock(lockPath) {
|
|
206
|
+
const now = Date.now();
|
|
207
|
+
let heldSince = null;
|
|
208
|
+
try {
|
|
209
|
+
const parsed = JSON.parse(await readFile(lockPath, "utf8"));
|
|
210
|
+
const stamp = isRecord(parsed) ? parsed["at"] : undefined;
|
|
211
|
+
if (typeof stamp === "number" && Number.isFinite(stamp) && stamp <= now) {
|
|
212
|
+
heldSince = stamp;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
heldSince = null;
|
|
217
|
+
}
|
|
218
|
+
if (heldSince === null) {
|
|
219
|
+
try {
|
|
220
|
+
heldSince = (await lstat(lockPath)).mtimeMs;
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
if (!Number.isFinite(heldSince) || heldSince > now)
|
|
226
|
+
heldSince = now;
|
|
227
|
+
}
|
|
228
|
+
if (now - heldSince < LOCK_STALE_MILLISECONDS)
|
|
229
|
+
return false;
|
|
230
|
+
await unlink(lockPath).catch(() => undefined);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
async function acquireLock(lockPath) {
|
|
234
|
+
const token = JSON.stringify({ at: Date.now(), pid: process.pid });
|
|
235
|
+
for (let attempt = 0; attempt < LOCK_ATTEMPT_LIMIT; attempt += 1) {
|
|
236
|
+
try {
|
|
237
|
+
const handle = await open(lockPath, "wx", 0o600);
|
|
238
|
+
await handle.writeFile(token, "utf8").catch(() => undefined);
|
|
239
|
+
return { handle, token };
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
if (errorCode(error) !== "EEXIST")
|
|
243
|
+
throw error;
|
|
244
|
+
if (!(await reclaimStaleLock(lockPath))) {
|
|
245
|
+
await delay(backoffMilliseconds(attempt));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
throw new Error("Cache lock is busy");
|
|
250
|
+
}
|
|
251
|
+
async function releaseLock(lockPath, token) {
|
|
252
|
+
try {
|
|
253
|
+
if ((await readFile(lockPath, "utf8")) !== token)
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
await unlink(lockPath).catch(() => undefined);
|
|
260
|
+
}
|
|
261
|
+
function rejectOutOfBounds(snapshots) {
|
|
262
|
+
if (snapshots.length > MAX_CACHE_ENTRIES)
|
|
263
|
+
throw new Error("Snapshot bounds rejected");
|
|
264
|
+
if (snapshots.some((snapshot) => normalizeMeter(snapshot) === null))
|
|
265
|
+
throw new Error("Snapshot bounds rejected");
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Run one cache mutation while holding the single cache lock.
|
|
269
|
+
*
|
|
270
|
+
* Readers never take this lock. They rely on the atomic replacement below, so
|
|
271
|
+
* the lock exists only to keep two writers from interleaving.
|
|
272
|
+
*/
|
|
273
|
+
async function withCacheLock(directory, action) {
|
|
274
|
+
await prepareStateDirectory(directory);
|
|
275
|
+
const lockPath = path.join(directory, CACHE_LOCK_NAME);
|
|
276
|
+
await rejectSymlink(lockPath);
|
|
277
|
+
const { handle, token } = await acquireLock(lockPath);
|
|
278
|
+
try {
|
|
279
|
+
return await action();
|
|
280
|
+
}
|
|
281
|
+
finally {
|
|
282
|
+
await handle.close().catch(() => undefined);
|
|
283
|
+
await releaseLock(lockPath, token);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async function replaceCache(directory, snapshots) {
|
|
287
|
+
const file = path.join(directory, CACHE_FILE_NAME);
|
|
288
|
+
await rejectSymlink(file);
|
|
289
|
+
await writeFileAtomically(file, canonicalJson({ snapshots, version: 1 }));
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Replace the snapshot cache.
|
|
293
|
+
*
|
|
294
|
+
* Every snapshot is revalidated before anything touches the disk, the payload
|
|
295
|
+
* is flushed to stable storage before the rename, and the lock carries an owner
|
|
296
|
+
* stamp so a writer that died cannot freeze the cache forever.
|
|
297
|
+
*/
|
|
298
|
+
export async function writeSnapshotCache(snapshots, directory = resolveStateDirectory()) {
|
|
299
|
+
rejectOutOfBounds(snapshots);
|
|
300
|
+
await withCacheLock(directory, async () => {
|
|
301
|
+
await replaceCache(directory, snapshots);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Fold fresh snapshots into the cache under the lock.
|
|
306
|
+
*
|
|
307
|
+
* Reading, merging, and writing all happen inside one lock, so two writers that
|
|
308
|
+
* observe different providers cannot silently drop each other's rows. An
|
|
309
|
+
* unchanged result skips the write entirely, which keeps a statusline that
|
|
310
|
+
* renders on every keystroke from churning the disk.
|
|
311
|
+
*/
|
|
312
|
+
export async function mergeSnapshotCache(incoming, directory = resolveStateDirectory()) {
|
|
313
|
+
rejectOutOfBounds(incoming);
|
|
314
|
+
return await withCacheLock(directory, async () => {
|
|
315
|
+
const cached = await readSnapshotCache(directory);
|
|
316
|
+
const existing = cached.ok ? cached.snapshots : [];
|
|
317
|
+
const merged = mergeSnapshots(existing, incoming);
|
|
318
|
+
if (canonicalJson(merged) === canonicalJson(existing)) {
|
|
319
|
+
return { merged, written: false };
|
|
320
|
+
}
|
|
321
|
+
rejectOutOfBounds(merged);
|
|
322
|
+
await replaceCache(directory, merged);
|
|
323
|
+
return { merged, written: true };
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,MAAM,EAEP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGjF,MAAM,CAAC,MAAM,eAAe,GAAG,wBAAwB,CAAC;AACxD,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAElD,gEAAgE;AAChE,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAE7C,oEAAoE;AACpE,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,CAAC;AAE7C,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,iCAAiC,GAAG,EAAE,CAAC;AAQ7C,MAAM,UAAU,qBAAqB,CAAC,UAAiC,EAAE;IACvE,MAAM,QAAQ,GAAG,OAAO,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