@adviser/cement 0.3.12 → 0.3.14
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/cf/index.cjs +101 -83
- package/cf/index.cjs.map +1 -1
- package/cf/index.js +2 -2
- package/{chunk-YXJKUIKD.js → chunk-22GI5ETU.js} +23 -4
- package/chunk-22GI5ETU.js.map +1 -0
- package/{chunk-LAE3VSNM.js → chunk-GLUGMVET.js} +2 -2
- package/{chunk-K7DKFBLZ.js → chunk-KY47QBK3.js} +22 -3
- package/{chunk-K7DKFBLZ.js.map → chunk-KY47QBK3.js.map} +1 -1
- package/deno/index.cjs +101 -83
- package/deno/index.cjs.map +1 -1
- package/deno/index.js +1 -1
- package/{index-CbOCsgzP.d.ts → index-D2WPDt4R.d.ts} +2 -1
- package/{index-EnKo_jNv.d.cts → index-DixRvifF.d.cts} +2 -1
- package/index.cjs +132 -94
- package/index.cjs.map +1 -1
- package/index.d.cts +7 -4
- package/index.d.ts +7 -4
- package/index.js +5 -3
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/node/index.cjs +21 -3
- package/node/index.cjs.map +1 -1
- package/node/index.js +1 -1
- package/package.json +2 -2
- package/src/jsr.json +1 -1
- package/src/resolve-once.ts +29 -5
- package/src/uri.ts +20 -0
- package/test/index.cjs +21 -3
- package/test/index.cjs.map +1 -1
- package/test/index.d.cts +1 -1
- package/test/index.d.ts +1 -1
- package/test/index.js +3 -3
- package/ts/src/resolve-once.d.ts +6 -2
- package/ts/src/resolve-once.d.ts.map +1 -1
- package/ts/src/resolve-once.js +20 -3
- package/ts/src/resolve-once.js.map +1 -1
- package/ts/src/resolve-once.test.js +30 -1
- package/ts/src/resolve-once.test.js.map +1 -1
- package/ts/src/uri.d.ts +1 -0
- package/ts/src/uri.d.ts.map +1 -1
- package/ts/src/uri.js +18 -0
- package/ts/src/uri.js.map +1 -1
- package/ts/src/uri.test.js +11 -1
- package/ts/src/uri.test.js.map +1 -1
- package/web/index.cjs +101 -83
- package/web/index.cjs.map +1 -1
- package/web/index.js +2 -2
- package/chunk-YXJKUIKD.js.map +0 -1
- /package/{chunk-LAE3VSNM.js.map → chunk-GLUGMVET.js.map} +0 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@adviser/cement",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.14",
|
4
4
|
"description": "better try/catch/finally handling",
|
5
5
|
"main": "index.js",
|
6
6
|
"type": "module",
|
@@ -55,7 +55,7 @@
|
|
55
55
|
"@vitest/browser": "^2.1.8",
|
56
56
|
"esbuild-plugin-replace": "^1.4.0",
|
57
57
|
"esbuild-plugin-resolve": "^2.0.0",
|
58
|
-
"eslint": "9.
|
58
|
+
"eslint": "9.20.0",
|
59
59
|
"prettier": "^3.3.3",
|
60
60
|
"tsup": "^8.3.0",
|
61
61
|
"tsx": "^4.19.1",
|
package/src/jsr.json
CHANGED
package/src/resolve-once.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { Future } from "./future.js";
|
2
|
+
import { Result } from "./result.js";
|
2
3
|
|
3
4
|
interface ResolveSeqItem<T, C> {
|
4
5
|
readonly future: Future<T>;
|
@@ -164,7 +165,7 @@ export class ResolveOnce<T, CTX = void> {
|
|
164
165
|
}
|
165
166
|
|
166
167
|
export class Keyed<T extends { reset: () => void }, K = string> {
|
167
|
-
|
168
|
+
protected readonly _map: Map<K, T> = new Map<K, T>();
|
168
169
|
|
169
170
|
readonly factory: (key: K) => T;
|
170
171
|
constructor(factory: (key: K) => T) {
|
@@ -175,10 +176,6 @@ export class Keyed<T extends { reset: () => void }, K = string> {
|
|
175
176
|
return this.get(await key());
|
176
177
|
}
|
177
178
|
|
178
|
-
entries(): IterableIterator<[K, T]> {
|
179
|
-
return this._map.entries();
|
180
|
-
}
|
181
|
-
|
182
179
|
get(key: K | (() => K)): T {
|
183
180
|
if (typeof key === "function") {
|
184
181
|
key = (key as () => K)();
|
@@ -207,6 +204,33 @@ export class KeyedResolvOnce<T, K = string> extends Keyed<ResolveOnce<T, K>, K>
|
|
207
204
|
constructor() {
|
208
205
|
super((key) => new ResolveOnce<T, K>(key));
|
209
206
|
}
|
207
|
+
|
208
|
+
/**
|
209
|
+
*
|
210
|
+
* @returns The values of the resolved keys
|
211
|
+
*/
|
212
|
+
values(): { key: K; value: Result<T> }[] {
|
213
|
+
return (
|
214
|
+
Array.from(this._map.entries())
|
215
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
216
|
+
.filter(([_, v]) => v._onceDone)
|
217
|
+
.map(([k, v]) => {
|
218
|
+
if (v._onceDone) {
|
219
|
+
if (v._onceError) {
|
220
|
+
return {
|
221
|
+
key: k,
|
222
|
+
value: Result.Err(v._onceError),
|
223
|
+
};
|
224
|
+
}
|
225
|
+
return {
|
226
|
+
key: k,
|
227
|
+
value: Result.Ok(v._onceValue as T),
|
228
|
+
};
|
229
|
+
}
|
230
|
+
throw new Error("KeyedResolvOnce.values impossible");
|
231
|
+
})
|
232
|
+
);
|
233
|
+
}
|
210
234
|
}
|
211
235
|
|
212
236
|
export class KeyedResolvSeq<T, K = string> extends Keyed<ResolveSeq<T, K>, K> {
|
package/src/uri.ts
CHANGED
@@ -421,6 +421,26 @@ export class BuildURI implements URIInterface<BuildURI> {
|
|
421
421
|
|
422
422
|
export type CoerceURI = string | URI | MutableURL | URL | BuildURI | NullOrUndef;
|
423
423
|
|
424
|
+
export function isCoerceURI(value: unknown): value is CoerceURI {
|
425
|
+
if (!value) {
|
426
|
+
return false;
|
427
|
+
}
|
428
|
+
if (isURL(value)) {
|
429
|
+
// includes MutableURL
|
430
|
+
return true;
|
431
|
+
}
|
432
|
+
if (URI.is(value)) {
|
433
|
+
return true;
|
434
|
+
}
|
435
|
+
if (BuildURI.is(value)) {
|
436
|
+
return true;
|
437
|
+
}
|
438
|
+
if (typeof value === "string") {
|
439
|
+
return true;
|
440
|
+
}
|
441
|
+
return false;
|
442
|
+
}
|
443
|
+
|
424
444
|
export const hasHostPartProtocols: Set<string> = new Set<string>(["http", "https", "ws", "wss"]);
|
425
445
|
|
426
446
|
// non mutable URL Implementation
|
package/test/index.cjs
CHANGED
@@ -933,9 +933,6 @@ var Keyed = class {
|
|
933
933
|
async asyncGet(key) {
|
934
934
|
return this.get(await key());
|
935
935
|
}
|
936
|
-
entries() {
|
937
|
-
return this._map.entries();
|
938
|
-
}
|
939
936
|
get(key) {
|
940
937
|
if (typeof key === "function") {
|
941
938
|
key = key();
|
@@ -961,6 +958,27 @@ var KeyedResolvOnce = class extends Keyed {
|
|
961
958
|
constructor() {
|
962
959
|
super((key) => new ResolveOnce(key));
|
963
960
|
}
|
961
|
+
/**
|
962
|
+
*
|
963
|
+
* @returns The values of the resolved keys
|
964
|
+
*/
|
965
|
+
values() {
|
966
|
+
return Array.from(this._map.entries()).filter(([_, v]) => v._onceDone).map(([k, v]) => {
|
967
|
+
if (v._onceDone) {
|
968
|
+
if (v._onceError) {
|
969
|
+
return {
|
970
|
+
key: k,
|
971
|
+
value: Result.Err(v._onceError)
|
972
|
+
};
|
973
|
+
}
|
974
|
+
return {
|
975
|
+
key: k,
|
976
|
+
value: Result.Ok(v._onceValue)
|
977
|
+
};
|
978
|
+
}
|
979
|
+
throw new Error("KeyedResolvOnce.values impossible");
|
980
|
+
});
|
981
|
+
}
|
964
982
|
};
|
965
983
|
|
966
984
|
// src/runtime.ts
|