@crustjs/store 0.4.4 → 0.5.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/dist/index.d.ts +4 -10
- package/dist/index.js +7 -12
- package/package.json +5 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { JsonCompatible } from "@crustjs/utils/json";
|
|
2
2
|
import { BaseValueType, ResolvePrimitive } from "@crustjs/utils/primitive";
|
|
3
3
|
import { InferOutput, StandardSchema } from "@crustjs/utils/schema";
|
|
4
|
-
//#region src/types.d.ts
|
|
5
4
|
/** Supported type literals for store fields. */
|
|
6
5
|
type ValueType = BaseValueType;
|
|
7
6
|
/** Shared fields present on every store field definition. */
|
|
@@ -109,8 +108,10 @@ type FieldDef = StringFieldDef | NumberFieldDef | BooleanFieldDef | StringArrayF
|
|
|
109
108
|
/** Record mapping field names to their definitions. */
|
|
110
109
|
type FieldsDef = Record<string, FieldDef>;
|
|
111
110
|
type JsonCompatibleFields<F extends FieldsDef> = { [K in keyof F]: F[K] extends {
|
|
112
|
-
schema:
|
|
113
|
-
} ? Exclude<
|
|
111
|
+
schema: infer S extends StandardSchema;
|
|
112
|
+
} ? Exclude<InferOutput<S>, undefined> extends JsonCompatible<Exclude<InferOutput<S>, undefined>> ? F[K] : F[K] & {
|
|
113
|
+
readonly FIX_JSON_OUTPUT: "store schema output must be JSON-compatible data (no Date, Map, bigint, or functions)";
|
|
114
|
+
} : F[K]; };
|
|
114
115
|
/**
|
|
115
116
|
* Infer the resolved type for a single field definition.
|
|
116
117
|
*
|
|
@@ -350,8 +351,6 @@ interface Store<TConfig> {
|
|
|
350
351
|
*/
|
|
351
352
|
reset(): Promise<void>;
|
|
352
353
|
}
|
|
353
|
-
//#endregion
|
|
354
|
-
//#region src/errors.d.ts
|
|
355
354
|
/**
|
|
356
355
|
* Contextual details attached to an `IO` error.
|
|
357
356
|
*
|
|
@@ -464,8 +463,6 @@ export declare class CrustStoreError<C extends StoreErrorCode = StoreErrorCode>
|
|
|
464
463
|
*/
|
|
465
464
|
is<T extends StoreErrorCode>(code: T): this is CrustStoreError<T>;
|
|
466
465
|
}
|
|
467
|
-
//#endregion
|
|
468
|
-
//#region src/path.d.ts
|
|
469
466
|
/**
|
|
470
467
|
* Encapsulates runtime environment values needed for path resolution.
|
|
471
468
|
*
|
|
@@ -584,8 +581,6 @@ export declare function stateDir(appName: string, env?: PlatformEnv): string;
|
|
|
584
581
|
* ```
|
|
585
582
|
*/
|
|
586
583
|
export declare function cacheDir(appName: string, env?: PlatformEnv): string;
|
|
587
|
-
//#endregion
|
|
588
|
-
//#region src/store.d.ts
|
|
589
584
|
/**
|
|
590
585
|
* Creates a typed async config store backed by a local JSON file.
|
|
591
586
|
*
|
|
@@ -623,5 +618,4 @@ export declare function cacheDir(appName: string, env?: PlatformEnv): string;
|
|
|
623
618
|
* ```
|
|
624
619
|
*/
|
|
625
620
|
export declare function createStore<const F extends FieldsDef>(options: CreateStoreOptions<F>): Store<InferStoreConfig<F>>;
|
|
626
|
-
//#endregion
|
|
627
621
|
export type { CreateStoreOptions, FieldDef, FieldsDef, InferStoreConfig, PlatformEnv, Store, StoreAccess, StoreErrorCode, StorePermissionBits, StoreUpdater, StoreValidatorIssue, ValidationErrorDetails, ValueType };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
|
-
import { dirname, join, win32 } from "node:path";
|
|
2
|
+
import { dirname, join, posix, win32 } from "node:path";
|
|
3
3
|
import { isDeepStrictEqual } from "node:util";
|
|
4
4
|
import { isJsonObject } from "@crustjs/utils/json";
|
|
5
5
|
import { coerceBooleanString, tryCoerceNumber } from "@crustjs/utils/primitive";
|
|
6
6
|
import { normalizeStandardIssues } from "@crustjs/utils/schema";
|
|
7
7
|
import { chmod, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
8
8
|
import { isErrnoException } from "@crustjs/utils/error";
|
|
9
|
-
|
|
9
|
+
// src/errors.ts
|
|
10
10
|
/**
|
|
11
11
|
* A typed error thrown by `@crustjs/store` for path, parse, IO, and validation failures.
|
|
12
12
|
*
|
|
@@ -56,8 +56,7 @@ var CrustStoreError = class extends Error {
|
|
|
56
56
|
return Object.is(this.code, code);
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
|
-
|
|
60
|
-
//#region src/path.ts
|
|
59
|
+
// src/path.ts
|
|
61
60
|
/**
|
|
62
61
|
* Returns the current runtime environment for path resolution.
|
|
63
62
|
*
|
|
@@ -119,7 +118,7 @@ function resolvePlatformDir(kind, appName, env = getRuntimeEnv()) {
|
|
|
119
118
|
const config = DIRECTORY_CONFIG[kind];
|
|
120
119
|
if (env.platform === "linux" || env.platform === "darwin") {
|
|
121
120
|
const configured = env.env[config.xdg];
|
|
122
|
-
const base = configured
|
|
121
|
+
const base = configured && posix.isAbsolute(configured) ? configured : join(env.homedir, ...config.unixFallback);
|
|
123
122
|
return join(base, appName);
|
|
124
123
|
}
|
|
125
124
|
if (env.platform === "win32") {
|
|
@@ -258,8 +257,7 @@ function resolveStorePath(dirPath, name) {
|
|
|
258
257
|
validateSegment(name, "name");
|
|
259
258
|
return join(dirPath, `${name}.json`);
|
|
260
259
|
}
|
|
261
|
-
|
|
262
|
-
//#region src/merge.ts
|
|
260
|
+
// src/merge.ts
|
|
263
261
|
/**
|
|
264
262
|
* Sets an own enumerable data property. Plain assignment would invoke the
|
|
265
263
|
* inherited `__proto__` setter instead of storing a `__proto__` field.
|
|
@@ -299,8 +297,7 @@ function applyFieldDefaults(persisted, fields, pruneUnknown = true) {
|
|
|
299
297
|
}
|
|
300
298
|
return result;
|
|
301
299
|
}
|
|
302
|
-
|
|
303
|
-
//#region src/persistence.ts
|
|
300
|
+
// src/persistence.ts
|
|
304
301
|
/**
|
|
305
302
|
* Reads and parses a JSON config file from disk.
|
|
306
303
|
*
|
|
@@ -415,8 +412,7 @@ async function deleteJson(filePath) {
|
|
|
415
412
|
}, err);
|
|
416
413
|
}
|
|
417
414
|
}
|
|
418
|
-
|
|
419
|
-
//#region src/store.ts
|
|
415
|
+
// src/store.ts
|
|
420
416
|
function makeSchemaValidator(schema) {
|
|
421
417
|
return async (value) => {
|
|
422
418
|
const result = await schema["~standard"].validate(value);
|
|
@@ -653,5 +649,4 @@ function createStore(options) {
|
|
|
653
649
|
reset
|
|
654
650
|
};
|
|
655
651
|
}
|
|
656
|
-
//#endregion
|
|
657
652
|
export { CrustStoreError, cacheDir, configDir, createStore, dataDir, stateDir };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crustjs/store",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Typed JSON persistence for CLI config, data, state, and cache files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@crustjs/utils": "^0.
|
|
43
|
+
"@crustjs/utils": "^0.3.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@crustjs/config": "0.0.0",
|
|
47
|
-
"zod": "^4.6.
|
|
48
|
-
"vite-plus": "1.
|
|
47
|
+
"zod": "^4.6.7",
|
|
48
|
+
"vite-plus": "1.4.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"typescript": "^7.0.0"
|
|
@@ -57,8 +57,7 @@
|
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"bun": ">=1.4.0",
|
|
60
|
-
"node": ">=24"
|
|
61
|
-
"deno": ">=2.8"
|
|
60
|
+
"node": ">=24"
|
|
62
61
|
},
|
|
63
62
|
"scripts": {
|
|
64
63
|
"build": "vp run build:task",
|