@sv443-network/coreutils 2.0.1 → 2.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.
@@ -2,8 +2,8 @@
2
2
  * @module DataStore
3
3
  * This module contains the DataStore class, which is a general purpose, sync and async persistent database for JSON-serializable data - [see the documentation for more info](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#class-datastore)
4
4
  */
5
- import type { DataStoreEngine } from "./DataStoreEngine.js";
6
- import type { LooseUnion, Prettify, SerializableVal } from "./types.js";
5
+ import type { DataStoreEngine } from "./DataStoreEngine.ts";
6
+ import type { LooseUnion, Prettify, SerializableVal } from "./types.ts";
7
7
  /** Function that takes the data in the old format and returns the data in the new format. Also supports an asynchronous migration. */
8
8
  type MigrationFunc = (oldData: any) => any | Promise<any>;
9
9
  /** Dictionary of format version numbers and the function that migrates to them from the previous whole integer */
@@ -3,8 +3,8 @@
3
3
  * This module contains the `DataStoreEngine` class and some of its subclasses like `FileStorageEngine` and `BrowserStorageEngine`.
4
4
  * [See the documentation for more info.](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#class-datastoreengine)
5
5
  */
6
- import type { DataStoreData, DataStoreOptions } from "./DataStore.js";
7
- import type { Prettify, SerializableVal } from "./types.js";
6
+ import type { DataStoreData, DataStoreOptions } from "./DataStore.ts";
7
+ import type { Prettify, SerializableVal } from "./types.ts";
8
8
  /** Contains the only properties of {@linkcode DataStoreOptions} that are relevant to the {@linkcode DataStoreEngine} class. */
9
9
  export type DataStoreEngineDSOptions<TData extends DataStoreData> = Prettify<Pick<DataStoreOptions<TData>, "decodeData" | "encodeData" | "id">>;
10
10
  export interface DataStoreEngine<TData extends DataStoreData> {
@@ -20,7 +20,7 @@ export declare abstract class DataStoreEngine<TData extends DataStoreData> {
20
20
  constructor(options?: DataStoreEngineDSOptions<TData>);
21
21
  /** Called by DataStore on creation, to pass its options. Only call this if you are using this instance standalone! */
22
22
  setDataStoreOptions(dataStoreOptions: DataStoreEngineDSOptions<TData>): void;
23
- /** Fetches a value from persistent storage */
23
+ /** Fetches a value from persistent storage. Defaults to `defaultValue` if the value does not exist. `null` is considered a valid value. */
24
24
  abstract getValue<TValue extends SerializableVal = string>(name: string, defaultValue: TValue): Promise<string | TValue>;
25
25
  /** Sets a value in persistent storage */
26
26
  abstract setValue(name: string, value: SerializableVal): Promise<void>;
@@ -88,6 +88,7 @@ export type FileStorageEngineOptions = {
88
88
  */
89
89
  export declare class FileStorageEngine<TData extends DataStoreData> extends DataStoreEngine<TData> {
90
90
  protected options: FileStorageEngineOptions & Required<Pick<FileStorageEngineOptions, "filePath">>;
91
+ private fileAccessQueue;
91
92
  /**
92
93
  * Creates an instance of `FileStorageEngine`.
93
94
  *
@@ -2,7 +2,7 @@
2
2
  * @module DataStoreSerializer
3
3
  * This module contains the DataStoreSerializer class, which allows you to import and export serialized DataStore data - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#datastoreserializer)
4
4
  */
5
- import type { DataStore, DataStoreData } from "./DataStore.js";
5
+ import type { DataStore, DataStoreData } from "./DataStore.ts";
6
6
  /** Options for the DataStoreSerializer class */
7
7
  export type DataStoreSerializerOptions = {
8
8
  /** Whether to add a checksum to the exported data. Defaults to `true` */
@@ -2,7 +2,7 @@
2
2
  * @module Debouncer
3
3
  * This module contains the Debouncer class and debounce function that allow you to reduce the amount of calls in rapidly firing event listeners and such - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#debouncer)
4
4
  */
5
- import { NanoEmitter } from "./NanoEmitter.js";
5
+ import { NanoEmitter } from "./NanoEmitter.ts";
6
6
  /**
7
7
  * The type of edge to use for the debouncer - [see the docs for a diagram and explanation.](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#debouncer)
8
8
  * - `immediate` - (default & recommended) - calls the listeners at the very first call ("rising" edge) and queues the latest call until the timeout expires
@@ -3,7 +3,7 @@
3
3
  * This module contains the NanoEmitter class, which is a tiny event emitter powered by [nanoevents](https://www.npmjs.com/package/nanoevents) - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#nanoemitter)
4
4
  */
5
5
  import { type DefaultEvents, type Emitter, type EventsMap, type Unsubscribe } from "nanoevents";
6
- import type { Prettify } from "./types.js";
6
+ import type { Prettify } from "./types.ts";
7
7
  export interface NanoEmitterOptions {
8
8
  /** If set to true, allows emitting events through the public method emit() */
9
9
  publicEmit: boolean;
@@ -0,0 +1,12 @@
1
+ import { DataStore, type DataStoreData } from "./DataStore.ts";
2
+ import type { SerializableVal } from "./types.ts";
3
+ /**
4
+ * A DataStore wrapper subclass that exposes internal methods for testing via the `direct_` prefixed methods.
5
+ */
6
+ export declare class TestDataStore<TData extends DataStoreData> extends DataStore<TData> {
7
+ direct_getValue<TValue extends SerializableVal = string>(name: string, defaultValue: TValue): Promise<string | TValue>;
8
+ direct_setValue(name: string, value: SerializableVal): Promise<void>;
9
+ direct_renameKey(oldName: string, newName: string): Promise<void>;
10
+ direct_deleteValue(name: string): Promise<void>;
11
+ direct_setFirstInit(value: boolean): void;
12
+ }
@@ -2,10 +2,10 @@
2
2
  * @module TieredCache
3
3
  * This module contains the TieredCache class, which is a cache that can have multiple tiers with different max TTLs, with data being moved between tiers based on what is fetched the most.
4
4
  */
5
- import { DataStore, type DataStoreData } from "./DataStore.js";
6
- import { NanoEmitter, type NanoEmitterOptions } from "./NanoEmitter.js";
7
- import type { DataStoreEngine } from "./DataStoreEngine.js";
8
- import type { Prettify } from "./types.js";
5
+ import { DataStore, type DataStoreData } from "./DataStore.ts";
6
+ import { NanoEmitter, type NanoEmitterOptions } from "./NanoEmitter.ts";
7
+ import type { DataStoreEngine } from "./DataStoreEngine.ts";
8
+ import type { Prettify } from "./types.ts";
9
9
  /** Options for the {@linkcode TieredCache} class. */
10
10
  export type TieredCacheOptions<TData extends DataStoreData> = Prettify<{
11
11
  /** Unique identifier for this cache. */
@@ -2,7 +2,7 @@
2
2
  * @module Translate
3
3
  * This module contains a sophisticated but still lightweight, JSON-based translation system - [see the documentation for more info](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#class-translate)
4
4
  */
5
- import type { Stringifiable } from "./types.js";
5
+ import type { Stringifiable } from "./types.ts";
6
6
  /**
7
7
  * Translation object to pass to {@linkcode tr.addTranslations()}
8
8
  * Can be a flat object of identifier keys and the translation text as the value, or an infinitely nestable object containing the same.
@@ -2,7 +2,7 @@
2
2
  * @module crypto
3
3
  * This module contains various cryptographic functions, like compression and Uint8Array encoding - [see the documentation for more info](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#crypto)
4
4
  */
5
- import type { Stringifiable } from "./types.js";
5
+ import type { Stringifiable } from "./types.ts";
6
6
  /** Converts an Uint8Array to a base64-encoded (ASCII) string */
7
7
  export declare function abtoa(buf: Uint8Array): string;
8
8
  /** Converts a base64-encoded (ASCII) string to an Uint8Array representation of its bytes */
@@ -2,16 +2,16 @@
2
2
  * @module @sv443-network/coreutils
3
3
  * @description Cross-platform, general-purpose, JavaScript core library for Node, Deno and the browser. Intended to be used in conjunction with [`@sv443-network/userutils`](https://github.com/Sv443-Network/UserUtils) and [`@sv443-network/djsutils`](https://github.com/Sv443-Network/DJSUtils), but can be used independently as well.
4
4
  */
5
- export * from "./array.js";
6
- export * from "./colors.js";
7
- export * from "./crypto.js";
8
- export * from "./math.js";
9
- export * from "./misc.js";
10
- export * from "./text.js";
11
- export * from "./types.js";
12
- export * from "./DataStore.js";
13
- export * from "./DataStoreEngine.js";
14
- export * from "./DataStoreSerializer.js";
15
- export * from "./Debouncer.js";
16
- export * from "./Errors.js";
17
- export * from "./NanoEmitter.js";
5
+ export * from "./array.ts";
6
+ export * from "./colors.ts";
7
+ export * from "./crypto.ts";
8
+ export * from "./math.ts";
9
+ export * from "./misc.ts";
10
+ export * from "./text.ts";
11
+ export * from "./types.ts";
12
+ export * from "./DataStore.ts";
13
+ export * from "./DataStoreEngine.ts";
14
+ export * from "./DataStoreSerializer.ts";
15
+ export * from "./Debouncer.ts";
16
+ export * from "./Errors.ts";
17
+ export * from "./NanoEmitter.ts";
@@ -2,7 +2,7 @@
2
2
  * @module math
3
3
  * This module contains general-purpose math functions like clamping, mapping and random number generation - [see the documentation for more info](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#math)
4
4
  */
5
- import type { NumberFormat, Stringifiable } from "./types.js";
5
+ import type { NumberFormat, Stringifiable } from "./types.ts";
6
6
  /** Checks if the given {@linkcode bitSet} contains the given {@linkcode checkVal} */
7
7
  export declare function bitSetHas<TType extends number | bigint>(bitSet: TType, checkVal: TType): boolean;
8
8
  /** Ensures the passed {@linkcode value} always stays between {@linkcode min} and {@linkcode max} */
@@ -2,7 +2,7 @@
2
2
  * @module misc
3
3
  * This module contains miscellaneous functions that don't fit in another category - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#misc)
4
4
  */
5
- import type { ListLike, Prettify, Stringifiable } from "./types.js";
5
+ import type { ListLike, Prettify, Stringifiable } from "./types.ts";
6
6
  /**
7
7
  * A ValueGen value is either its type, a promise that resolves to its type, or a function that returns its type, either synchronous or asynchronous.
8
8
  * ValueGen allows for the utmost flexibility when applied to any type, as long as {@linkcode consumeGen()} is used to get the final value.
@@ -1,4 +1,4 @@
1
- import type { ListLike, Prettify, Stringifiable } from "./types.js";
1
+ import type { ListLike, Prettify, Stringifiable } from "./types.ts";
2
2
  /**
3
3
  * Automatically pluralizes the given string an `-s` or `-ies` to the passed {@linkcode term}, if {@linkcode num} is not equal to 1.
4
4
  * By default, words ending in `-y` will have it replaced with `-ies`, and all other words will simply have `-s` appended.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sv443-network/coreutils",
3
3
  "libName": "@sv443-network/coreutils",
4
- "version": "2.0.1",
4
+ "version": "2.0.3",
5
5
  "description": "Cross-platform, general-purpose, JavaScript core library for Node, Deno and the browser. Intended to be used in conjunction with `@sv443-network/userutils` and `@sv443-network/djsutils`, but can be used independently as well.",
6
6
  "main": "dist/CoreUtils.cjs",
7
7
  "module": "dist/CoreUtils.mjs",
@@ -41,27 +41,27 @@
41
41
  "nanoevents": "^9.1.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@changesets/cli": "^2.29.4",
45
- "@eslint/eslintrc": "^3.3.1",
46
- "@eslint/js": "^9.28.0",
47
- "@swc/core": "^1.11.29",
48
- "@testing-library/dom": "^10.4.0",
49
- "@types/deno": "^2.3.0",
50
- "@types/node": "^22.15.29",
44
+ "@changesets/cli": "^2.29.8",
45
+ "@eslint/eslintrc": "^3.3.3",
46
+ "@eslint/js": "^9.39.2",
47
+ "@swc/core": "^1.15.11",
48
+ "@testing-library/dom": "^10.4.1",
49
+ "@types/deno": "^2.5.0",
50
+ "@types/node": "^22.19.7",
51
51
  "@types/tx2": "^1.0.3",
52
- "@typescript-eslint/eslint-plugin": "^8.33.0",
53
- "@typescript-eslint/parser": "^8.33.0",
54
- "@typescript-eslint/utils": "^8.33.0",
55
- "@vitest/coverage-v8": "^3.1.4",
52
+ "@typescript-eslint/eslint-plugin": "^8.54.0",
53
+ "@typescript-eslint/parser": "^8.54.0",
54
+ "@typescript-eslint/utils": "^8.54.0",
55
+ "@vitest/coverage-v8": "^3.2.4",
56
56
  "esbuild-plugin-umd-wrapper": "^3.0.0",
57
- "eslint": "^9.28.0",
58
- "globals": "^16.2.0",
57
+ "eslint": "^9.39.2",
58
+ "globals": "^16.5.0",
59
59
  "jsdom": "^26.1.0",
60
60
  "tslib": "^2.8.1",
61
- "tsup": "^8.5.0",
62
- "tsx": "^4.19.4",
63
- "typescript": "^5.8.3",
64
- "vitest": "^3.1.4"
61
+ "tsup": "^8.5.1",
62
+ "tsx": "^4.21.0",
63
+ "typescript": "^5.9.3",
64
+ "vitest": "^3.2.4"
65
65
  },
66
66
  "files": [
67
67
  "/dist/CoreUtils.cjs",