@grunnverk/shared 0.1.11

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.
@@ -0,0 +1,39 @@
1
+ import { ValidationResult } from './types';
2
+ /**
3
+ * Generic validation function that validates data against a schema
4
+ * @param data Data to validate
5
+ * @param schema Validation schema (can be a Zod schema or custom validator)
6
+ * @returns ValidationResult with success status and either data or error
7
+ */
8
+ export declare const validate: <T>(data: unknown, schema: {
9
+ parse: (data: unknown) => T;
10
+ }) => ValidationResult<T>;
11
+ /**
12
+ * Validates that a value is a string
13
+ */
14
+ export declare const validateString: (value: unknown, fieldName?: string) => string;
15
+ /**
16
+ * Validates that a value is a number
17
+ */
18
+ export declare const validateNumber: (value: unknown, fieldName?: string) => number;
19
+ /**
20
+ * Validates that a value is a boolean
21
+ */
22
+ export declare const validateBoolean: (value: unknown, fieldName?: string) => boolean;
23
+ /**
24
+ * Validates that a value is an array
25
+ */
26
+ export declare const validateArray: <T>(value: unknown, fieldName?: string) => T[];
27
+ /**
28
+ * Validates that a value is an object (and not null or array)
29
+ */
30
+ export declare const validateObject: (value: unknown, fieldName?: string) => Record<string, any>;
31
+ /**
32
+ * Validates that a string is not empty
33
+ */
34
+ export declare const validateNonEmptyString: (value: unknown, fieldName?: string) => string;
35
+ /**
36
+ * Validates that a value is one of the allowed values
37
+ */
38
+ export declare const validateEnum: <T>(value: unknown, allowedValues: readonly T[], fieldName?: string) => T;
39
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EACtB,MAAM,OAAO,EACb,QAAQ;IAAE,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,CAAC,CAAA;CAAE,KACxC,gBAAgB,CAAC,CAAC,CAOpB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,EAAE,YAAW,MAAgB,KAAG,MAK5E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,EAAE,YAAW,MAAgB,KAAG,MAK5E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,EAAE,YAAW,MAAgB,KAAG,OAK7E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,OAAO,OAAO,EAAE,YAAW,MAAgB,KAAG,CAAC,EAK/E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,EAAE,YAAW,MAAgB,KAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAK9F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAI,OAAO,OAAO,EAAE,YAAW,MAAgB,KAAG,MAMpF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,EAC1B,OAAO,OAAO,EACd,eAAe,SAAS,CAAC,EAAE,EAC3B,YAAW,MAAgB,KAC5B,CAOF,CAAC"}
package/guide/index.md ADDED
@@ -0,0 +1,84 @@
1
+ # @grunnverk/shared - Agentic Guide
2
+
3
+ ## Purpose
4
+
5
+ Shared utilities for grunnverk tools. Provides storage, validation, error handling, date utilities, and common helpers.
6
+
7
+ ## Key Features
8
+
9
+ - **Storage** - File-based storage with JSON/YAML support
10
+ - **Validation** - Input validation and sanitization
11
+ - **Error Handling** - Custom error types (ArgumentError, CommandErrors, etc.)
12
+ - **Date Utilities** - Date parsing and formatting
13
+ - **Safety** - Safe file operations and input handling
14
+ - **Standard Input** - Interactive input reading
15
+
16
+ ## Usage
17
+
18
+ ```typescript
19
+ import {
20
+ Storage,
21
+ validateInput,
22
+ ArgumentError,
23
+ formatDate,
24
+ safeReadFile
25
+ } from '@grunnverk/shared';
26
+
27
+ // Storage
28
+ const storage = new Storage('config.json');
29
+ await storage.save({ key: 'value' });
30
+ const data = await storage.load();
31
+
32
+ // Validation
33
+ const valid = validateInput(userInput, schema);
34
+
35
+ // Error handling
36
+ if (!valid) {
37
+ throw new ArgumentError('Invalid input', { input: userInput });
38
+ }
39
+
40
+ // Date utilities
41
+ const formatted = formatDate(new Date(), 'YYYY-MM-DD');
42
+ ```
43
+
44
+ ## Dependencies
45
+
46
+ - dayjs - Date manipulation
47
+ - js-yaml - YAML parsing
48
+ - glob - File pattern matching
49
+ - moment-timezone - Timezone support
50
+ - semver - Version parsing
51
+ - zod - Schema validation
52
+
53
+ ## Package Structure
54
+
55
+ ```
56
+ src/
57
+ ├── errors/ # Error types
58
+ │ ├── ArgumentError.ts
59
+ │ ├── CancellationError.ts
60
+ │ ├── CommandErrors.ts
61
+ │ ├── ExitError.ts
62
+ │ └── index.ts
63
+ ├── storage.ts # File storage
64
+ ├── validation.ts # Input validation
65
+ ├── dates.ts # Date utilities
66
+ ├── general.ts # General utilities
67
+ ├── safety.ts # Safe operations
68
+ ├── stdin.ts # Standard input
69
+ ├── types.ts # Type definitions
70
+ └── index.ts
71
+ ```
72
+
73
+ ## Key Exports
74
+
75
+ - `Storage` - File-based storage
76
+ - `validateInput()` - Input validation
77
+ - `ArgumentError` - Argument validation error
78
+ - `CommandError` - Command execution error
79
+ - `CancellationError` - Operation cancelled
80
+ - `ExitError` - Process exit error
81
+ - `formatDate()` - Date formatting
82
+ - `safeReadFile()` - Safe file reading
83
+ - `sanitizeInput()` - Input sanitization
84
+
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "@grunnverk/shared",
3
+ "version": "0.1.11",
4
+ "description": "Shared utilities for grunnverk tools - storage, validation, errors, and more",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "guide"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/grunnverk/shared-utils.git"
20
+ },
21
+ "scripts": {
22
+ "build": "npm run lint && tsc --noEmit && vite build",
23
+ "dev": "vite",
24
+ "watch": "vite build --watch",
25
+ "test": "vitest run --coverage",
26
+ "lint": "eslint . --ext .ts",
27
+ "lint:fix": "eslint . --ext .ts --fix",
28
+ "clean": "rm -rf dist",
29
+ "precommit": "npm run clean && npm run build && npm run lint && npm run test",
30
+ "prepublishOnly": "npm run clean && npm run lint && npm run build && npm run test"
31
+ },
32
+ "keywords": [
33
+ "utilities",
34
+ "storage",
35
+ "validation",
36
+ "errors",
37
+ "helpers",
38
+ "typescript"
39
+ ],
40
+ "author": "Tim O'Brien <tobrien@discursive.com>",
41
+ "license": "Apache-2.0",
42
+ "engines": {
43
+ "node": ">=24.0.0"
44
+ },
45
+ "dependencies": {
46
+ "dayjs": "^1.11.13",
47
+ "glob": "^13.0.0",
48
+ "js-yaml": "^4.1.0",
49
+ "moment-timezone": "^0.6.0",
50
+ "semver": "^7.7.2",
51
+ "zod": "^4.1.12"
52
+ },
53
+ "peerDependencies": {
54
+ "@grunnverk/git-tools": "^1.0.1",
55
+ "winston": "^3.17.0"
56
+ },
57
+ "peerDependenciesMeta": {
58
+ "@grunnverk/git-tools": {
59
+ "optional": true
60
+ },
61
+ "winston": {
62
+ "optional": true
63
+ }
64
+ },
65
+ "devDependencies": {
66
+ "@grunnverk/git-tools": "^1.0.1",
67
+ "@eslint/eslintrc": "^3.3.1",
68
+ "@eslint/js": "^9.33.0",
69
+ "@swc/core": "^1.13.3",
70
+ "@types/js-yaml": "^4.0.9",
71
+ "@types/node": "^24.10.1",
72
+ "@types/semver": "^7.7.0",
73
+ "@types/winston": "^2.4.4",
74
+ "@typescript-eslint/eslint-plugin": "^8.39.1",
75
+ "@typescript-eslint/parser": "^8.47.0",
76
+ "@vitest/coverage-v8": "^4.0.13",
77
+ "esbuild": "0.27.0",
78
+ "eslint": "^9.33.0",
79
+ "eslint-plugin-import": "^2.32.0",
80
+ "globals": "^16.3.0",
81
+ "mockdate": "^3.0.5",
82
+ "typescript": "^5.9.2",
83
+ "vite": "^7.2.4",
84
+ "vite-plugin-dts": "^4.3.0",
85
+ "vite-plugin-node": "^7.0.0",
86
+ "vitest": "^4.0.13",
87
+ "winston": "^3.17.0"
88
+ }
89
+ }