shelving 1.142.0 → 1.143.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 (57) hide show
  1. package/error/BaseError.d.ts +3 -6
  2. package/error/BaseError.js +6 -13
  3. package/error/NetworkError.js +0 -1
  4. package/error/RequestError.d.ts +7 -12
  5. package/error/RequestError.js +10 -18
  6. package/error/RequiredError.js +0 -1
  7. package/error/ResponseError.js +0 -1
  8. package/error/UnexpectedError.js +0 -1
  9. package/error/UnimplementedError.js +0 -1
  10. package/error/ValueError.js +0 -1
  11. package/markup/util/internal.js +1 -1
  12. package/package.json +13 -13
  13. package/react/createCacheContext.js +8 -7
  14. package/react/index.d.ts +2 -1
  15. package/react/index.js +2 -1
  16. package/react/useInstance.js +3 -4
  17. package/react/useLazy.js +3 -4
  18. package/react/useMap.d.ts +2 -0
  19. package/react/useMap.js +8 -0
  20. package/react/useProps.d.ts +6 -0
  21. package/react/useProps.js +5 -0
  22. package/react/useStore.js +3 -4
  23. package/util/array.d.ts +1 -1
  24. package/util/async.d.ts +3 -4
  25. package/util/boolean.d.ts +1 -1
  26. package/util/bytes.d.ts +1 -1
  27. package/util/callback.d.ts +2 -0
  28. package/util/color.d.ts +1 -1
  29. package/util/data.d.ts +1 -1
  30. package/util/date.d.ts +1 -1
  31. package/util/dictionary.d.ts +1 -1
  32. package/util/entity.d.ts +1 -1
  33. package/util/equal.d.ts +1 -1
  34. package/util/error.d.ts +0 -2
  35. package/util/error.js +1 -1
  36. package/util/file.d.ts +1 -1
  37. package/util/function.d.ts +3 -0
  38. package/util/http.d.ts +1 -1
  39. package/util/jwt.d.ts +1 -1
  40. package/util/link.d.ts +1 -1
  41. package/util/map.d.ts +1 -1
  42. package/util/null.d.ts +1 -1
  43. package/util/number.d.ts +1 -1
  44. package/util/optional.d.ts +1 -1
  45. package/util/path.d.ts +1 -1
  46. package/util/sequence.d.ts +2 -2
  47. package/util/set.d.ts +1 -1
  48. package/util/source.d.ts +2 -1
  49. package/util/source.js +2 -2
  50. package/util/string.d.ts +1 -1
  51. package/util/template.d.ts +1 -1
  52. package/util/time.d.ts +1 -1
  53. package/util/undefined.d.ts +1 -1
  54. package/util/url.d.ts +1 -1
  55. package/util/validate.d.ts +2 -1
  56. package/react/useInternals.d.ts +0 -5
  57. package/react/useInternals.js +0 -3
@@ -1,7 +1,4 @@
1
- import type { AnyConstructor } from "../util/class.js";
2
- import type { AnyFunction } from "../util/function.js";
3
- /** Any calling function or constructor that can appear in a stack tracer. */
4
- export type AnyCaller = AnyFunction | AnyConstructor;
1
+ import type { AnyCaller } from "../util/function.js";
5
2
  /** Options for `BaseError` that provide additional helpful error functionality. */
6
3
  export interface BaseErrorOptions extends ErrorOptions {
7
4
  /**
@@ -15,7 +12,7 @@ export interface BaseErrorOptions extends ErrorOptions {
15
12
  }
16
13
  /** An error that provides additional helpful functionality. */
17
14
  export declare abstract class BaseError extends Error {
18
- /** Provide additional named contextual data that should be attached to the `Error` instance. */
19
- [key: string]: unknown;
15
+ /** Provide additional named contextual data that is relevant to the `Error` instance. */
16
+ readonly [key: string]: unknown;
20
17
  constructor(message?: string, options?: BaseErrorOptions);
21
18
  }
@@ -1,18 +1,11 @@
1
1
  /** An error that provides additional helpful functionality. */
2
2
  export class BaseError extends Error {
3
- constructor(message, options) {
4
- if (options) {
5
- super(message, options);
6
- const { cause, caller = BaseError, ...rest } = options;
7
- for (const [key, value] of Object.entries(rest))
8
- this[key] = value;
9
- Error.captureStackTrace(this, caller);
10
- }
11
- else {
12
- super(message);
13
- Error.captureStackTrace(this, BaseError);
14
- }
3
+ constructor(message, options = {}) {
4
+ super(message, options);
5
+ const { cause, caller = BaseError, ...rest } = options;
6
+ for (const [key, value] of Object.entries(rest))
7
+ this[key] = value;
8
+ Error.captureStackTrace(this, caller);
15
9
  }
16
10
  }
17
11
  BaseError.prototype.name = "BaseError";
18
- BaseError.prototype.message = "Unknown error";
@@ -6,4 +6,3 @@ export class NetworkError extends BaseError {
6
6
  }
7
7
  }
8
8
  NetworkError.prototype.name = "NetworkError";
9
- NetworkError.prototype.message = "Network error";
@@ -1,32 +1,27 @@
1
1
  import { BaseError, type BaseErrorOptions } from "./BaseError.js";
2
- /** Options for a `RequestError` */
3
- interface RequestErrorOptions extends BaseErrorOptions {
4
- code?: number;
5
- }
6
2
  /** Error thrown when a request isn't well-formed. */
7
3
  export declare class RequestError extends BaseError {
8
4
  /** The corresponding HTTP status code for this error, in the range `400-499` */
9
- code: number;
10
- constructor(message?: string, options?: RequestErrorOptions);
5
+ readonly code: number;
6
+ constructor(message?: string, options?: BaseErrorOptions);
11
7
  }
12
8
  /** Thrown if an operation failed because the user is not logged in, or the login information is not well-formed. */
13
9
  export declare class UnauthorizedError extends RequestError {
14
10
  readonly code: number;
15
- constructor(message?: string, options?: RequestErrorOptions);
11
+ constructor(message?: string, options?: BaseErrorOptions);
16
12
  }
17
13
  /** Thrown if the requested content is not found. */
18
14
  export declare class NotFoundError extends RequestError {
19
- readonly code = 404;
20
- constructor(message?: string, options?: RequestErrorOptions);
15
+ readonly code: number;
16
+ constructor(message?: string, options?: BaseErrorOptions);
21
17
  }
22
18
  /** Error thrown when a request is is valid and well-formed, but its actual data is not. */
23
19
  export declare class UnprocessableError extends RequestError {
24
20
  readonly code: number;
25
- constructor(message?: string, options?: RequestErrorOptions);
21
+ constructor(message?: string, options?: BaseErrorOptions);
26
22
  }
27
23
  /** Thrown if an operation failed because the user is logged in, but does not have sufficient privileges to access this content. */
28
24
  export declare class ForbiddenError extends RequestError {
29
25
  readonly code: number;
30
- constructor(message?: string, options?: RequestErrorOptions);
26
+ constructor(message?: string, options?: BaseErrorOptions);
31
27
  }
32
- export {};
@@ -2,49 +2,41 @@ import { BaseError } from "./BaseError.js";
2
2
  /** Error thrown when a request isn't well-formed. */
3
3
  export class RequestError extends BaseError {
4
4
  /** The corresponding HTTP status code for this error, in the range `400-499` */
5
- code;
6
- constructor(message = RequestError.prototype.message, options) {
5
+ code = 400;
6
+ constructor(message, options) {
7
7
  super(message, { caller: RequestError, ...options });
8
- this.code = options?.code || 400;
9
8
  }
10
9
  }
11
10
  RequestError.prototype.name = "RequestError";
12
- RequestError.prototype.message = "Invalid request";
13
11
  /** Thrown if an operation failed because the user is not logged in, or the login information is not well-formed. */
14
12
  export class UnauthorizedError extends RequestError {
15
13
  code = 401;
16
- constructor(message = UnauthorizedError.prototype.message, options) {
17
- super(message, { caller: UnauthorizedError, code: 401, ...options });
14
+ constructor(message, options) {
15
+ super(message, { caller: UnauthorizedError, ...options });
18
16
  }
19
17
  }
20
18
  UnauthorizedError.prototype.name = "UnauthorizedError";
21
- UnauthorizedError.prototype.message = "Authorization is required";
22
19
  /** Thrown if the requested content is not found. */
23
20
  export class NotFoundError extends RequestError {
24
21
  code = 404;
25
- constructor(message = NotFoundError.prototype.message, options) {
26
- super(message, { caller: NotFoundError, code: 404, ...options });
27
- Error.captureStackTrace(this, NotFoundError);
22
+ constructor(message, options) {
23
+ super(message, { caller: NotFoundError, ...options });
28
24
  }
29
25
  }
30
26
  NotFoundError.prototype.name = "NotFoundError";
31
- NotFoundError.prototype.message = "Cannot find requested content";
32
27
  /** Error thrown when a request is is valid and well-formed, but its actual data is not. */
33
28
  export class UnprocessableError extends RequestError {
34
29
  code = 422;
35
- constructor(message = UnprocessableError.prototype.message, options) {
36
- super(message, { caller: UnprocessableError, code: 422, ...options });
37
- Error.captureStackTrace(this, UnprocessableError);
30
+ constructor(message, options) {
31
+ super(message, { caller: UnprocessableError, ...options });
38
32
  }
39
33
  }
40
34
  UnprocessableError.prototype.name = "UnprocessableError";
41
- UnprocessableError.prototype.message = "Input data is invalid";
42
35
  /** Thrown if an operation failed because the user is logged in, but does not have sufficient privileges to access this content. */
43
36
  export class ForbiddenError extends RequestError {
44
37
  code = 403;
45
- constructor(message = ForbiddenError.prototype.message, options) {
46
- super(message, { caller: ForbiddenError, code: 403, ...options });
38
+ constructor(message, options) {
39
+ super(message, { caller: ForbiddenError, ...options });
47
40
  }
48
41
  }
49
42
  ForbiddenError.prototype.name = "ForbiddenError";
50
- ForbiddenError.prototype.message = "Insufficient privileges to access this content";
@@ -9,4 +9,3 @@ export class RequiredError extends BaseError {
9
9
  }
10
10
  }
11
11
  RequiredError.prototype.name = "RequiredError";
12
- RequiredError.prototype.message = "Value is required";
@@ -6,4 +6,3 @@ export class ResponseError extends BaseError {
6
6
  }
7
7
  }
8
8
  ResponseError.prototype.name = "ResponseError";
9
- ResponseError.prototype.message = "Invalid response";
@@ -6,4 +6,3 @@ export class UnexpectedError extends BaseError {
6
6
  }
7
7
  }
8
8
  UnexpectedError.prototype.name = "UnexpectedError";
9
- UnexpectedError.prototype.message = "Unexpected error";
@@ -6,4 +6,3 @@ export class UnimplementedError extends BaseError {
6
6
  }
7
7
  }
8
8
  UnimplementedError.prototype.name = "UnimplementedError";
9
- UnimplementedError.prototype.message = "Not implemented";
@@ -6,4 +6,3 @@ export class ValueError extends BaseError {
6
6
  }
7
7
  }
8
8
  ValueError.prototype.name = "ValueError";
9
- ValueError.prototype.message = "Invalid value";
@@ -1,2 +1,2 @@
1
1
  /** React security symbol — see https://github.com/facebook/react/pull/4832 */
2
- export const REACT_ELEMENT_TYPE = Symbol.for("react.element");
2
+ export const REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element");
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.142.0",
14
+ "version": "1.143.1",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -57,19 +57,19 @@
57
57
  "build:test:unit": "bun test ./dist/**/*.test.js --bail"
58
58
  },
59
59
  "devDependencies": {
60
- "@biomejs/biome": "^1.8.3",
61
- "@google-cloud/firestore": "^7.9.0",
62
- "@types/bun": "^1.1.6",
63
- "@types/react": "^18.3.3",
64
- "@types/react-dom": "^18.3.0",
65
- "firebase": "^10.12.5",
66
- "react": "^18.3.1",
67
- "react-dom": "^18.3.1",
68
- "typescript": "^5.8.2"
60
+ "@biomejs/biome": "^1.9.4",
61
+ "@google-cloud/firestore": "^7.11.3",
62
+ "@types/bun": "^1.2.18",
63
+ "@types/react": "^19.1.8",
64
+ "@types/react-dom": "^19.1.6",
65
+ "firebase": "^11.10.0",
66
+ "react": "^19.1.0",
67
+ "react-dom": "^19.1.0",
68
+ "typescript": "^5.8.3"
69
69
  },
70
70
  "peerDependencies": {
71
- "@google-cloud/firestore": ">=4.0.0",
72
- "firebase": ">=9.0.0",
73
- "react": ">=17.0.0"
71
+ "@google-cloud/firestore": ">=7.0.0",
72
+ "firebase": ">=11.0.0",
73
+ "react": ">=19.0.0"
74
74
  }
75
75
  }
@@ -1,21 +1,22 @@
1
- import { createContext, createElement, useContext, useRef } from "react";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
2
3
  import { UnexpectedError } from "../error/UnexpectedError.js";
4
+ import { useMap } from "./useMap.js";
3
5
  /**
4
6
  * Create a cache context that can be provided to React elements and allows them to call `useCache()`
5
7
  * - Cache is a `Map` indexed by strings that can be used to store any value.
6
8
  */
7
9
  export function createCacheContext() {
8
- const context = createContext(undefined);
10
+ const Context = createContext(undefined);
9
11
  const useCache = () => {
10
- const cache = useContext(context);
12
+ const cache = useContext(Context);
11
13
  if (!cache)
12
- throw new UnexpectedError("useCache() must be used inside <Cache>", { caller: useCache });
14
+ throw new UnexpectedError("useCache() must be used inside <CacheContext>", { caller: useCache });
13
15
  return cache;
14
16
  };
15
17
  const CacheContext = ({ children }) => {
16
- // biome-ignore lint/suspicious/noAssignInExpressions: This is the most efficient way to do this.
17
- const cache = (useRef().current ||= new Map());
18
- return createElement(context.Provider, { children, value: cache });
18
+ const cache = useMap();
19
+ return _jsx(Context, { value: cache, children: children });
19
20
  };
20
21
  return { useCache, CacheContext };
21
22
  }
package/react/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./createCacheContext.js";
2
2
  export * from "./createDataContext.js";
3
- export * from "./useInstance.js";
3
+ export * from "./useProps.js";
4
+ export * from "./useMap.js";
4
5
  export * from "./useLazy.js";
5
6
  export * from "./useReduce.js";
6
7
  export * from "./useSequence.js";
package/react/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./createCacheContext.js";
2
2
  export * from "./createDataContext.js";
3
- export * from "./useInstance.js";
3
+ export * from "./useProps.js";
4
+ export * from "./useMap.js";
4
5
  export * from "./useLazy.js";
5
6
  export * from "./useReduce.js";
6
7
  export * from "./useSequence.js";
@@ -1,17 +1,16 @@
1
1
  import { isArrayEqual } from "../util/equal.js";
2
- import { useInternals } from "./useInternals.js";
2
+ import { useProps } from "./useProps.js";
3
3
  /**
4
4
  * Use a memoised class instance.
5
5
  * - Creates a new instance of `Constructor` using `args`
6
6
  * - Returns same instance for as long as `args` is equal to previous `args`.
7
7
  */
8
8
  export function useInstance(Constructor, ...args) {
9
- const internals = useInternals();
9
+ const internals = useProps();
10
10
  // Update `internals` if `args` changes or `instance` is not set.
11
- if (!internals.args || !isArrayEqual(args, internals.args)) {
11
+ if (!internals.args || !internals.instance || !isArrayEqual(args, internals.args)) {
12
12
  internals.instance = new Constructor(...args);
13
13
  internals.args = args;
14
14
  }
15
- // biome-ignore lint/style/noNonNullAssertion: We know this is set.
16
15
  return internals.instance;
17
16
  }
package/react/useLazy.js CHANGED
@@ -1,13 +1,12 @@
1
1
  import { isArrayEqual } from "../util/equal.js";
2
2
  import { getLazy } from "../util/lazy.js";
3
- import { useInternals } from "./useInternals.js";
3
+ import { useProps } from "./useProps.js";
4
4
  export function useLazy(value, ...args) {
5
- const internals = useInternals();
5
+ const internals = useProps();
6
6
  // Update `internals` if `args` changes.
7
- if (internals.args === undefined || !isArrayEqual(args, internals.args)) {
7
+ if (!internals.args || !isArrayEqual(args, internals.args)) {
8
8
  internals.value = getLazy(value, ...args);
9
9
  internals.args = args;
10
10
  }
11
- // biome-ignore lint/style/noNonNullAssertion: We know this is set.
12
11
  return internals.value;
13
12
  }
@@ -0,0 +1,2 @@
1
+ /** Create a mutable Map that persist for the lifetime of the component. */
2
+ export declare function useMap<K, V>(): Map<K, V>;
@@ -0,0 +1,8 @@
1
+ import { useRef } from "react";
2
+ /** Create a mutable Map that persist for the lifetime of the component. */
3
+ export function useMap() {
4
+ const ref = useRef(undefined);
5
+ if (!ref.current)
6
+ ref.current = new Map();
7
+ return ref.current;
8
+ }
@@ -0,0 +1,6 @@
1
+ type Mutable<T> = {
2
+ -readonly [K in keyof T]: T[K];
3
+ };
4
+ /** Create an object that persist for the lifetime of the component. */
5
+ export declare function useProps<T>(): Partial<Mutable<T>>;
6
+ export {};
@@ -0,0 +1,5 @@
1
+ import { useRef } from "react";
2
+ /** Create an object that persist for the lifetime of the component. */
3
+ export function useProps() {
4
+ return useRef(undefined);
5
+ }
package/react/useStore.js CHANGED
@@ -2,17 +2,16 @@ import { useSyncExternalStore } from "react";
2
2
  import { NONE } from "../util/constants.js";
3
3
  import { BLACKHOLE } from "../util/function.js";
4
4
  import { runSequence } from "../util/sequence.js";
5
- import { useInternals } from "./useInternals.js";
5
+ import { useProps } from "./useProps.js";
6
6
  export function useStore(store) {
7
7
  // Store memoized versions of `subscribe()` and `getSnapshot()` so `useSyncExternalStore()` doesn't re-subscribe on every render.
8
- const internals = useInternals();
8
+ const internals = useProps();
9
9
  // Update `internals` if `store` changes.
10
- if (store !== internals.store) {
10
+ if (store !== internals.store || !internals.subscribe || !internals.getSnapshot) {
11
11
  internals.subscribe = onStoreChange => (store ? runSequence(store, onStoreChange, onStoreChange) : BLACKHOLE);
12
12
  internals.getSnapshot = () => (!store ? undefined : store.loading ? NONE : store.value);
13
13
  internals.store = store;
14
14
  }
15
- // biome-ignore lint/style/noNonNullAssertion: We know these are set.
16
15
  useSyncExternalStore(internals.subscribe, internals.getSnapshot);
17
16
  return store;
18
17
  }
package/util/array.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  /**
3
3
  * Mutable array: an array that can be changed.
4
4
  * - Consistency with `MutableObject<T>` and `ImmutableArray<T>`
package/util/async.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { ImmutableArray } from "./array.js";
2
- import type { ValueCallback } from "./callback.js";
3
- import type { Report } from "./error.js";
2
+ import type { ErrorCallback, ValueCallback } from "./callback.js";
4
3
  /** Is a value an asynchronous value implementing a `then()` function. */
5
4
  export declare function isAsync<T>(value: PromiseLike<T> | T): value is PromiseLike<T>;
6
5
  /** Is a value a synchronous value. */
@@ -39,14 +38,14 @@ export declare abstract class AbstractPromise<T> extends Promise<T> {
39
38
  /** Resolve this promise with a value. */
40
39
  protected readonly _resolve: ValueCallback<T>;
41
40
  /** Reject this promise with a reason. */
42
- protected readonly _reject: Report;
41
+ protected readonly _reject: ErrorCallback;
43
42
  constructor();
44
43
  }
45
44
  /** Deferred allows you to access the internal resolve/reject callbacks of a `Promise` */
46
45
  export type Deferred<T> = {
47
46
  promise: Promise<T>;
48
47
  resolve: ValueCallback<T>;
49
- reject: Report;
48
+ reject: ErrorCallback;
50
49
  };
51
50
  /**
52
51
  * Get a deferred to access the `resolve()` and `reject()` functions of a promise.
package/util/boolean.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  /** Is a value a boolean? */
3
3
  export declare function isBoolean(value: unknown): value is boolean;
4
4
  /** Is a value true? */
package/util/bytes.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  /** Types that can be converted to a `Uint8Array` byte sequence. */
3
3
  export type PossibleBytes = Uint8Array | ArrayBuffer | string;
4
4
  /** Assert that an unknown value is a `Uint8Array` byte sequence. */
@@ -11,6 +11,8 @@ export type AsyncValueCallback<T = void> = (value: T) => void | PromiseLike<void
11
11
  export type ValuesCallback<T extends Arguments = []> = (...values: T) => void;
12
12
  /** Callback function that receives multiple values and possibly returns a promise that must be handled. */
13
13
  export type AsyncValuesCallback<T extends Arguments = []> = (...values: T) => void | PromiseLike<void>;
14
+ /** Callback function that receives an error. */
15
+ export type ErrorCallback = (reason: unknown) => void;
14
16
  /** Safely call a callback function (possibly with a value). */
15
17
  export declare function call<A extends Arguments = []>(callback: (...v: A) => unknown, ...values: A): void;
16
18
  /** Return a callback function that safely calls a callback function (possibly with a value). */
package/util/color.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  export declare const HEX3_REGEXP: RegExp;
3
3
  export declare const HEX6_REGEXP: RegExp;
4
4
  /** Things that can be converted to a `Color` instance. */
package/util/data.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
2
1
  import type { ImmutableArray } from "./array.js";
3
2
  import type { EntryObject } from "./entry.js";
3
+ import type { AnyCaller } from "./function.js";
4
4
  import type { DeepPartial } from "./object.js";
5
5
  /** Data object. */
6
6
  export type Data = {
package/util/date.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  /** Values that can be converted to dates. */
3
3
  export type PossibleDate = "now" | "today" | "tomorrow" | "yesterday" | Date | number | string;
4
4
  /**
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  /** Readonly dictionary object. */
3
3
  export type ImmutableDictionary<T = unknown> = {
4
4
  readonly [K in string]: T;
package/util/entity.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  import type { Optional } from "./optional.js";
3
3
  /** Entity strings combine a type and ID, e.g. `challenge:a1b2c3` */
4
4
  export type Entity<T extends string = string> = `${T}:${string}`;
package/util/equal.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
2
1
  import type { ImmutableArray } from "./array.js";
3
2
  import type { Match } from "./filter.js";
3
+ import type { AnyCaller } from "./function.js";
4
4
  import type { ImmutableMap } from "./map.js";
5
5
  import type { ImmutableObject } from "./object.js";
6
6
  /** Assert two values are equal. */
package/util/error.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /** Callback function that reports an error. */
2
- export type Report = (reason: unknown) => void;
3
1
  /** Log an error to the console. */
4
2
  export declare function logError(reason: unknown): void;
5
3
  /** Is an unknown value an `Error` instance? */
package/util/error.js CHANGED
@@ -4,5 +4,5 @@ export function logError(reason) {
4
4
  }
5
5
  /** Is an unknown value an `Error` instance? */
6
6
  export function isError(v) {
7
- return v instanceof Error;
7
+ return typeof Error.isError === "function" ? Error.isError(v) : v instanceof Error;
8
8
  }
package/util/file.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  /** List of file types in `extension: mime` format. */
3
3
  export type FileTypes = {
4
4
  [extension: string]: string;
@@ -1,7 +1,10 @@
1
+ import type { AnyConstructor } from "./class.js";
1
2
  /** Unknown function. */
2
3
  export type UnknownFunction = (...args: unknown[]) => unknown;
3
4
  /** Any function (purposefully as wide as possible for use with `extends X` or `is X` statements). */
4
5
  export type AnyFunction = (...args: any) => any;
6
+ /** Any calling function or constructor, usually referring to something that can call in the current scope that can appear in a stack trace. */
7
+ export type AnyCaller = AnyFunction | AnyConstructor;
5
8
  /** Is a value a function? */
6
9
  export declare function isFunction(value: unknown): value is AnyFunction;
7
10
  /** Assert that a value is a function. */
package/util/http.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
2
1
  import { RequestError } from "../error/RequestError.js";
3
2
  import { ResponseError } from "../error/ResponseError.js";
3
+ import type { AnyCaller } from "./function.js";
4
4
  /** A handler function takes a `Request` and returns a `Response` (possibly asynchronously). */
5
5
  export type RequestHandler = (request: Request) => Response | Promise<Response>;
6
6
  export declare function _getMessageJSON(message: Request | Response, MessageError: typeof RequestError | typeof ResponseError, caller: AnyCaller): Promise<unknown>;
package/util/jwt.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
2
1
  import { type PossibleBytes } from "./bytes.js";
3
2
  import type { Data } from "./data.js";
3
+ import type { AnyCaller } from "./function.js";
4
4
  /**
5
5
  * Encode a JWT and return the string token.
6
6
  * - Currently only supports HMAC SHA-512 signing.
package/util/link.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
2
1
  import type { ImmutableArray } from "./array.js";
2
+ import type { AnyCaller } from "./function.js";
3
3
  import type { Optional } from "./optional.js";
4
4
  import type { Path } from "./path.js";
5
5
  import { type PossibleURL } from "./url.js";
package/util/map.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
2
1
  import type { Entry } from "./entry.js";
2
+ import type { AnyCaller } from "./function.js";
3
3
  /** `Map` that cannot be changed. */
4
4
  export type ImmutableMap<K = unknown, T = unknown> = ReadonlyMap<K, T>;
5
5
  /** Class for a `Map` that cannot be changed (so you can extend `Map` while implementing `ImmutableMap`). */
package/util/null.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  /** Function that always returns null. */
3
3
  export declare function getNull(): null;
4
4
  /** Nullable is the value or `null` */
package/util/number.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  /** Values that can be converted to a number. */
3
3
  export type PossibleNumber = number | string | Date;
4
4
  /** Is a value a finite number? */
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  /** Optional is the value or `null` or `undefined` (synonym for `Nullish`). */
3
3
  export type Optional<T> = T | null | undefined;
4
4
  /** Get a required value. */
package/util/path.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  import { type Optional } from "./optional.js";
3
3
  /** Absolute path string starts with `/` slash. */
4
4
  export type AbsolutePath = `/` | `/${string}`;
@@ -1,6 +1,6 @@
1
1
  import type { AsyncValueCallback, ValueCallback } from "./callback.js";
2
+ import type { ErrorCallback } from "./callback.js";
2
3
  import { STOP } from "./constants.js";
3
- import type { Report } from "./error.js";
4
4
  import type { Stop } from "./start.js";
5
5
  /**
6
6
  * Is a value an async iterable object?
@@ -15,4 +15,4 @@ export declare function repeatDelay(ms: number): AsyncIterable<number>;
15
15
  /** Dispatch items in a sequence to a (possibly async) callback. */
16
16
  export declare function callSequence<T>(sequence: AsyncIterable<T>, callback: AsyncValueCallback<T>): AsyncIterable<T>;
17
17
  /** Pull values from a sequence until the returned function is called. */
18
- export declare function runSequence<T>(sequence: AsyncIterable<T>, onNext?: ValueCallback<T>, onError?: Report): Stop;
18
+ export declare function runSequence<T>(sequence: AsyncIterable<T>, onNext?: ValueCallback<T>, onError?: ErrorCallback): Stop;
package/util/set.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  /** `Set` that cannot be changed. */
3
3
  export type ImmutableSet<T = unknown> = ReadonlySet<T>;
4
4
  /** `Set` that can be changed. */
package/util/source.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Class } from "./class.js";
2
+ import type { AnyCaller } from "./function.js";
2
3
  /** Something that has a source of a specified type. */
3
4
  export interface Sourceable<T> {
4
5
  readonly source: T;
@@ -6,4 +7,4 @@ export interface Sourceable<T> {
6
7
  /** Recurse through `Sourceable` objects and return the first one that is an instance of `type`, or `undefined` if no source object matches. */
7
8
  export declare function getSource<T>(type: Class<T>, value: unknown): T | undefined;
8
9
  /** Recurse through `Sourceable` objects and return the first one that is an instance of `type`, or throw `RequiredError` if no source object matches. */
9
- export declare function requireSource<T>(type: Class<T>, data: unknown): T;
10
+ export declare function requireSource<T>(type: Class<T>, data: unknown, caller?: AnyCaller): T;
package/util/source.js CHANGED
@@ -10,9 +10,9 @@ export function getSource(type, value) {
10
10
  }
11
11
  }
12
12
  /** Recurse through `Sourceable` objects and return the first one that is an instance of `type`, or throw `RequiredError` if no source object matches. */
13
- export function requireSource(type, data) {
13
+ export function requireSource(type, data, caller = requireSource) {
14
14
  const source = getSource(type, data);
15
15
  if (!source)
16
- throw new RequiredError(`Source "${type.name}" not found`, { received: data, expected: type, caller: requireSource });
16
+ throw new RequiredError(`Source "${type.name}" not found`, { received: data, expected: type, caller });
17
17
  return source;
18
18
  }
package/util/string.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
2
1
  import type { ImmutableArray } from "./array.js";
2
+ import type { AnyCaller } from "./function.js";
3
3
  /**
4
4
  * Type that never matches the `string` type.
5
5
  * - `string` itself is iterable (iterating over its individual characters) and implements `Iterable<string>`
@@ -1,6 +1,6 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
2
1
  import type { ImmutableArray } from "./array.js";
3
2
  import { type ImmutableDictionary } from "./dictionary.js";
3
+ import type { AnyCaller } from "./function.js";
4
4
  import type { NotString } from "./string.js";
5
5
  /** Dictionary of named template values in `{ myPlaceholder: "value" }` format. */
6
6
  export type TemplateDictionary = ImmutableDictionary<string>;
package/util/time.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  /** Class representing a time in the day in 24 hour format in the user's current locale. */
3
3
  export declare class Time {
4
4
  /** Make a new `Time` instance from a time string. */
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  /** Function that always returns undefined. */
3
3
  export declare function getUndefined(): undefined;
4
4
  /** Is a value undefined? */
package/util/url.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyCaller } from "../error/BaseError.js";
1
+ import type { AnyCaller } from "./function.js";
2
2
  import { type Optional } from "./optional.js";
3
3
  /** Values that can be converted to a URL instance. */
4
4
  export type PossibleURL = string | URL;
@@ -1,8 +1,9 @@
1
- import type { AnyCaller, BaseError, BaseErrorOptions } from "../error/BaseError.js";
1
+ import type { BaseError, BaseErrorOptions } from "../error/BaseError.js";
2
2
  import type { ImmutableArray, PossibleArray } from "./array.js";
3
3
  import type { Constructor } from "./class.js";
4
4
  import type { Data } from "./data.js";
5
5
  import type { ImmutableDictionary } from "./dictionary.js";
6
+ import type { AnyCaller } from "./function.js";
6
7
  import type { DeepPartial } from "./object.js";
7
8
  /** Object that can validate an unknown value with its `validate()` method. */
8
9
  export interface Validator<T> {
@@ -1,5 +0,0 @@
1
- import type { Data } from "../util/data.js";
2
- /** Store internal implementation details for a hook that persist for the lifetime of the component. */
3
- export declare const useInternals: <T extends Data>() => T | {
4
- [K in keyof T]: undefined;
5
- };
@@ -1,3 +0,0 @@
1
- import { useRef } from "react";
2
- /** Store internal implementation details for a hook that persist for the lifetime of the component. */
3
- export const useInternals = useRef;