@theunwalked/cardigantime 0.0.1 → 0.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.
- package/README.md +699 -0
- package/dist/cardigantime.cjs +907 -15
- package/dist/cardigantime.cjs.map +1 -1
- package/dist/cardigantime.d.ts +42 -0
- package/dist/cardigantime.js +49 -345
- package/dist/cardigantime.js.map +1 -1
- package/dist/configure.d.ts +50 -1
- package/dist/configure.js +102 -3
- package/dist/configure.js.map +1 -1
- package/dist/constants.d.ts +17 -0
- package/dist/constants.js +17 -9
- package/dist/constants.js.map +1 -1
- package/dist/error/ArgumentError.d.ts +26 -0
- package/dist/error/ArgumentError.js +48 -0
- package/dist/error/ArgumentError.js.map +1 -0
- package/dist/error/ConfigurationError.d.ts +21 -0
- package/dist/error/ConfigurationError.js +46 -0
- package/dist/error/ConfigurationError.js.map +1 -0
- package/dist/error/FileSystemError.d.ts +30 -0
- package/dist/error/FileSystemError.js +58 -0
- package/dist/error/FileSystemError.js.map +1 -0
- package/dist/error/index.d.ts +3 -0
- package/dist/read.d.ts +30 -0
- package/dist/read.js +105 -12
- package/dist/read.js.map +1 -1
- package/dist/types.d.ts +63 -0
- package/dist/types.js +5 -3
- package/dist/types.js.map +1 -1
- package/dist/util/storage.js +33 -4
- package/dist/util/storage.js.map +1 -1
- package/dist/validate.d.ts +96 -1
- package/dist/validate.js +164 -20
- package/dist/validate.js.map +1 -1
- package/package.json +30 -23
- package/.gitcarve/config.yaml +0 -10
- package/.gitcarve/context/content.md +0 -1
- package/dist/configure.cjs +0 -12
- package/dist/configure.cjs.map +0 -1
- package/dist/constants.cjs +0 -35
- package/dist/constants.cjs.map +0 -1
- package/dist/read.cjs +0 -69
- package/dist/read.cjs.map +0 -1
- package/dist/types.cjs +0 -13
- package/dist/types.cjs.map +0 -1
- package/dist/util/storage.cjs +0 -149
- package/dist/util/storage.cjs.map +0 -1
- package/dist/validate.cjs +0 -130
- package/dist/validate.cjs.map +0 -1
- package/eslint.config.mjs +0 -82
- package/nodemon.json +0 -14
- package/vite.config.ts +0 -98
- package/vitest.config.ts +0 -17
package/dist/util/storage.cjs
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const glob = require('glob');
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const crypto = require('crypto');
|
|
9
|
-
|
|
10
|
-
function _interopNamespaceDefault(e) {
|
|
11
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
12
|
-
if (e) {
|
|
13
|
-
for (const k in e) {
|
|
14
|
-
if (k !== 'default') {
|
|
15
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: () => e[k]
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
n.default = e;
|
|
24
|
-
return Object.freeze(n);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line no-restricted-imports
|
|
30
|
-
const create = (params)=>{
|
|
31
|
-
// eslint-disable-next-line no-console
|
|
32
|
-
const log = params.log || console.log;
|
|
33
|
-
const exists = async (path)=>{
|
|
34
|
-
try {
|
|
35
|
-
await fs__namespace.promises.stat(path);
|
|
36
|
-
return true;
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
38
|
-
} catch (error) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const isDirectory = async (path)=>{
|
|
43
|
-
const stats = await fs__namespace.promises.stat(path);
|
|
44
|
-
if (!stats.isDirectory()) {
|
|
45
|
-
log(`${path} is not a directory`);
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
};
|
|
50
|
-
const isFile = async (path)=>{
|
|
51
|
-
const stats = await fs__namespace.promises.stat(path);
|
|
52
|
-
if (!stats.isFile()) {
|
|
53
|
-
log(`${path} is not a file`);
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
};
|
|
58
|
-
const isReadable = async (path)=>{
|
|
59
|
-
try {
|
|
60
|
-
await fs__namespace.promises.access(path, fs__namespace.constants.R_OK);
|
|
61
|
-
} catch (error) {
|
|
62
|
-
log(`${path} is not readable: %s %s`, error.message, error.stack);
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
return true;
|
|
66
|
-
};
|
|
67
|
-
const isWritable = async (path)=>{
|
|
68
|
-
try {
|
|
69
|
-
await fs__namespace.promises.access(path, fs__namespace.constants.W_OK);
|
|
70
|
-
} catch (error) {
|
|
71
|
-
log(`${path} is not writable: %s %s`, error.message, error.stack);
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
return true;
|
|
75
|
-
};
|
|
76
|
-
const isFileReadable = async (path)=>{
|
|
77
|
-
return await exists(path) && await isFile(path) && await isReadable(path);
|
|
78
|
-
};
|
|
79
|
-
const isDirectoryWritable = async (path)=>{
|
|
80
|
-
return await exists(path) && await isDirectory(path) && await isWritable(path);
|
|
81
|
-
};
|
|
82
|
-
const isDirectoryReadable = async (path)=>{
|
|
83
|
-
return await exists(path) && await isDirectory(path) && await isReadable(path);
|
|
84
|
-
};
|
|
85
|
-
const createDirectory = async (path)=>{
|
|
86
|
-
try {
|
|
87
|
-
await fs__namespace.promises.mkdir(path, {
|
|
88
|
-
recursive: true
|
|
89
|
-
});
|
|
90
|
-
} catch (mkdirError) {
|
|
91
|
-
throw new Error(`Failed to create output directory ${path}: ${mkdirError.message} ${mkdirError.stack}`);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
const readFile = async (path, encoding)=>{
|
|
95
|
-
return await fs__namespace.promises.readFile(path, {
|
|
96
|
-
encoding: encoding
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
const writeFile = async (path, data, encoding)=>{
|
|
100
|
-
await fs__namespace.promises.writeFile(path, data, {
|
|
101
|
-
encoding: encoding
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
const forEachFileIn = async (directory, callback, options = {
|
|
105
|
-
pattern: '*.*'
|
|
106
|
-
})=>{
|
|
107
|
-
try {
|
|
108
|
-
const files = await glob.glob(options.pattern, {
|
|
109
|
-
cwd: directory,
|
|
110
|
-
nodir: true
|
|
111
|
-
});
|
|
112
|
-
for (const file of files){
|
|
113
|
-
await callback(path.join(directory, file));
|
|
114
|
-
}
|
|
115
|
-
} catch (err) {
|
|
116
|
-
throw new Error(`Failed to glob pattern ${options.pattern} in ${directory}: ${err.message}`);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
const readStream = async (path)=>{
|
|
120
|
-
return fs__namespace.createReadStream(path);
|
|
121
|
-
};
|
|
122
|
-
const hashFile = async (path, length)=>{
|
|
123
|
-
const file = await readFile(path, 'utf8');
|
|
124
|
-
return crypto.createHash('sha256').update(file).digest('hex').slice(0, length);
|
|
125
|
-
};
|
|
126
|
-
const listFiles = async (directory)=>{
|
|
127
|
-
return await fs__namespace.promises.readdir(directory);
|
|
128
|
-
};
|
|
129
|
-
return {
|
|
130
|
-
exists,
|
|
131
|
-
isDirectory,
|
|
132
|
-
isFile,
|
|
133
|
-
isReadable,
|
|
134
|
-
isWritable,
|
|
135
|
-
isFileReadable,
|
|
136
|
-
isDirectoryWritable,
|
|
137
|
-
isDirectoryReadable,
|
|
138
|
-
createDirectory,
|
|
139
|
-
readFile,
|
|
140
|
-
readStream,
|
|
141
|
-
writeFile,
|
|
142
|
-
forEachFileIn,
|
|
143
|
-
hashFile,
|
|
144
|
-
listFiles
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
exports.create = create;
|
|
149
|
-
//# sourceMappingURL=storage.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storage.cjs","sources":["../../src/util/storage.ts"],"sourcesContent":["// eslint-disable-next-line no-restricted-imports\nimport * as fs from 'fs';\nimport { glob } from 'glob';\nimport path from 'path';\nimport crypto from 'crypto';\n/**\n * This module exists to isolate filesystem operations from the rest of the codebase.\n * This makes testing easier by avoiding direct fs mocking in jest configuration.\n * \n * Additionally, abstracting storage operations allows for future flexibility - \n * this export utility may need to work with storage systems other than the local filesystem\n * (e.g. S3, Google Cloud Storage, etc).\n */\n\nexport interface Utility {\n exists: (path: string) => Promise<boolean>;\n isDirectory: (path: string) => Promise<boolean>;\n isFile: (path: string) => Promise<boolean>;\n isReadable: (path: string) => Promise<boolean>;\n isWritable: (path: string) => Promise<boolean>;\n isFileReadable: (path: string) => Promise<boolean>;\n isDirectoryWritable: (path: string) => Promise<boolean>;\n isDirectoryReadable: (path: string) => Promise<boolean>;\n createDirectory: (path: string) => Promise<void>;\n readFile: (path: string, encoding: string) => Promise<string>;\n readStream: (path: string) => Promise<fs.ReadStream>;\n writeFile: (path: string, data: string | Buffer, encoding: string) => Promise<void>;\n forEachFileIn: (directory: string, callback: (path: string) => Promise<void>, options?: { pattern: string }) => Promise<void>;\n hashFile: (path: string, length: number) => Promise<string>;\n listFiles: (directory: string) => Promise<string[]>;\n}\n\nexport const create = (params: { log?: (message: string, ...args: any[]) => void }): Utility => {\n\n // eslint-disable-next-line no-console\n const log = params.log || console.log;\n\n const exists = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.stat(path);\n return true;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error: any) {\n return false;\n }\n }\n\n const isDirectory = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isDirectory()) {\n log(`${path} is not a directory`);\n return false;\n }\n return true;\n }\n\n const isFile = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isFile()) {\n log(`${path} is not a file`);\n return false;\n }\n return true;\n }\n\n const isReadable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.R_OK);\n } catch (error: any) {\n log(`${path} is not readable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isWritable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.W_OK);\n } catch (error: any) {\n log(`${path} is not writable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isFileReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isFile(path) && await isReadable(path);\n }\n\n const isDirectoryWritable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isWritable(path);\n }\n\n const isDirectoryReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isReadable(path);\n }\n\n const createDirectory = async (path: string): Promise<void> => {\n try {\n await fs.promises.mkdir(path, { recursive: true });\n } catch (mkdirError: any) {\n throw new Error(`Failed to create output directory ${path}: ${mkdirError.message} ${mkdirError.stack}`);\n }\n }\n\n const readFile = async (path: string, encoding: string): Promise<string> => {\n return await fs.promises.readFile(path, { encoding: encoding as BufferEncoding });\n }\n\n const writeFile = async (path: string, data: string | Buffer, encoding: string): Promise<void> => {\n await fs.promises.writeFile(path, data, { encoding: encoding as BufferEncoding });\n }\n\n const forEachFileIn = async (directory: string, callback: (file: string) => Promise<void>, options: { pattern: string | string[] } = { pattern: '*.*' }): Promise<void> => {\n try {\n const files = await glob(options.pattern, { cwd: directory, nodir: true });\n for (const file of files) {\n await callback(path.join(directory, file));\n }\n } catch (err: any) {\n throw new Error(`Failed to glob pattern ${options.pattern} in ${directory}: ${err.message}`);\n }\n }\n\n const readStream = async (path: string): Promise<fs.ReadStream> => {\n return fs.createReadStream(path);\n }\n\n const hashFile = async (path: string, length: number): Promise<string> => {\n const file = await readFile(path, 'utf8');\n return crypto.createHash('sha256').update(file).digest('hex').slice(0, length);\n }\n\n const listFiles = async (directory: string): Promise<string[]> => {\n return await fs.promises.readdir(directory);\n }\n\n return {\n exists,\n isDirectory,\n isFile,\n isReadable,\n isWritable,\n isFileReadable,\n isDirectoryWritable,\n isDirectoryReadable,\n createDirectory,\n readFile,\n readStream,\n writeFile,\n forEachFileIn,\n hashFile,\n listFiles,\n };\n}"],"names":["create","params","log","console","exists","path","fs","promises","stat","error","isDirectory","stats","isFile","isReadable","access","constants","R_OK","message","stack","isWritable","W_OK","isFileReadable","isDirectoryWritable","isDirectoryReadable","createDirectory","mkdir","recursive","mkdirError","Error","readFile","encoding","writeFile","data","forEachFileIn","directory","callback","options","pattern","files","glob","cwd","nodir","file","join","err","readStream","createReadStream","hashFile","length","crypto","createHash","update","digest","slice","listFiles","readdir"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAgCO,MAAMA,SAAS,CAACC,MAAAA,GAAAA;;AAGnB,IAAA,MAAMC,GAAMD,GAAAA,MAAAA,CAAOC,GAAG,IAAIC,QAAQD,GAAG;AAErC,IAAA,MAAME,SAAS,OAAOC,IAAAA,GAAAA;QAClB,IAAI;AACA,YAAA,MAAMC,aAAGC,CAAAA,QAAQ,CAACC,IAAI,CAACH,IAAAA,CAAAA;YACvB,OAAO,IAAA;;AAEX,SAAA,CAAE,OAAOI,KAAY,EAAA;YACjB,OAAO,KAAA;AACX;AACJ,KAAA;AAEA,IAAA,MAAMC,cAAc,OAAOL,IAAAA,GAAAA;AACvB,QAAA,MAAMM,QAAQ,MAAML,aAAAA,CAAGC,QAAQ,CAACC,IAAI,CAACH,IAAAA,CAAAA;QACrC,IAAI,CAACM,KAAMD,CAAAA,WAAW,EAAI,EAAA;YACtBR,GAAI,CAAA,CAAA,EAAGG,IAAK,CAAA,mBAAmB,CAAC,CAAA;YAChC,OAAO,KAAA;AACX;QACA,OAAO,IAAA;AACX,KAAA;AAEA,IAAA,MAAMO,SAAS,OAAOP,IAAAA,GAAAA;A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A;AACAE,QAAAA,MAAAA;AACAC,QAAAA,UAAAA;AACAM,QAAAA,UAAAA;AACAE,QAAAA,cAAAA;AACAC,QAAAA,mBAAAA;AACAC,QAAAA,mBAAAA;AACAC,QAAAA,eAAAA;AACAK,QAAAA,QAAAA;AACAgB,QAAAA,UAAAA;AACAd,QAAAA,SAAAA;AACAE,QAAAA,aAAAA;AACAc,QAAAA,QAAAA;AACAO,QAAAA;AACJ,KAAA;AACJ;;;;"}
|
package/dist/validate.cjs
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const zod = require('zod');
|
|
6
|
-
const types = require('./types.cjs');
|
|
7
|
-
const storage = require('./util/storage.cjs');
|
|
8
|
-
|
|
9
|
-
const listZodKeys = (schema, prefix = '')=>{
|
|
10
|
-
// Check if schema has unwrap method (which both ZodOptional and ZodNullable have)
|
|
11
|
-
if (schema._def && (schema._def.typeName === 'ZodOptional' || schema._def.typeName === 'ZodNullable')) {
|
|
12
|
-
// Use type assertion to handle the unwrap method
|
|
13
|
-
const unwrappable = schema;
|
|
14
|
-
return listZodKeys(unwrappable.unwrap(), prefix);
|
|
15
|
-
}
|
|
16
|
-
if (schema._def && schema._def.typeName === 'ZodArray') {
|
|
17
|
-
// Use type assertion to handle the element property
|
|
18
|
-
const arraySchema = schema;
|
|
19
|
-
return listZodKeys(arraySchema.element, prefix);
|
|
20
|
-
}
|
|
21
|
-
if (schema._def && schema._def.typeName === 'ZodObject') {
|
|
22
|
-
// Use type assertion to handle the shape property
|
|
23
|
-
const objectSchema = schema;
|
|
24
|
-
return Object.entries(objectSchema.shape).flatMap(([key, subschema])=>{
|
|
25
|
-
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
26
|
-
const nested = listZodKeys(subschema, fullKey);
|
|
27
|
-
return nested.length ? nested : fullKey;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
return [];
|
|
31
|
-
};
|
|
32
|
-
const isPlainObject = (value)=>{
|
|
33
|
-
// Check if it's an object, not null, and not an array.
|
|
34
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Generates a list of all keys within a JavaScript object, using dot notation for nested keys.
|
|
38
|
-
* Mimics the behavior of listZodKeys but operates on plain objects.
|
|
39
|
-
* For arrays, it inspects the first element that is a plain object to determine nested keys.
|
|
40
|
-
* If an array contains no plain objects, or is empty, the key for the array itself is listed.
|
|
41
|
-
*
|
|
42
|
-
* @param obj The object to introspect.
|
|
43
|
-
* @param prefix Internal use for recursion: the prefix for the current nesting level.
|
|
44
|
-
* @returns An array of strings representing all keys in dot notation.
|
|
45
|
-
*/ const listObjectKeys = (obj, prefix = '')=>{
|
|
46
|
-
const keys = new Set(); // Use Set to automatically handle duplicates from array recursion
|
|
47
|
-
for(const key in obj){
|
|
48
|
-
// Ensure it's an own property, not from the prototype chain
|
|
49
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
50
|
-
const value = obj[key];
|
|
51
|
-
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
52
|
-
if (Array.isArray(value)) {
|
|
53
|
-
// Find the first element that is a plain object to determine structure
|
|
54
|
-
const firstObjectElement = value.find(isPlainObject);
|
|
55
|
-
if (firstObjectElement) {
|
|
56
|
-
// Recurse into the structure of the first object element found
|
|
57
|
-
const nestedKeys = listObjectKeys(firstObjectElement, fullKey);
|
|
58
|
-
nestedKeys.forEach((k)=>keys.add(k));
|
|
59
|
-
} else {
|
|
60
|
-
// Array is empty or contains no plain objects, list the array key itself
|
|
61
|
-
keys.add(fullKey);
|
|
62
|
-
}
|
|
63
|
-
} else if (isPlainObject(value)) {
|
|
64
|
-
// Recurse into nested plain objects
|
|
65
|
-
const nestedKeys = listObjectKeys(value, fullKey);
|
|
66
|
-
nestedKeys.forEach((k)=>keys.add(k));
|
|
67
|
-
} else {
|
|
68
|
-
// It's a primitive, null, or other non-plain object/array type
|
|
69
|
-
keys.add(fullKey);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return Array.from(keys); // Convert Set back to Array
|
|
74
|
-
};
|
|
75
|
-
const checkForExtraKeys = (mergedSources, fullSchema, logger)=>{
|
|
76
|
-
const allowedKeys = new Set(listZodKeys(fullSchema));
|
|
77
|
-
const actualKeys = listObjectKeys(mergedSources);
|
|
78
|
-
const extraKeys = actualKeys.filter((key)=>!allowedKeys.has(key));
|
|
79
|
-
if (extraKeys.length > 0) {
|
|
80
|
-
const allowedKeysString = Array.from(allowedKeys).join(', ');
|
|
81
|
-
const extraKeysString = extraKeys.join(', ');
|
|
82
|
-
const errorMessage = `Unknown configuration keys found: ${extraKeysString}. Allowed keys are: ${allowedKeysString}`;
|
|
83
|
-
logger.error(errorMessage);
|
|
84
|
-
throw new Error(`Configuration validation failed: Unknown keys found (${extraKeysString}). Check logs for details.`);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
const validateConfigDirectory = async (configDirectory, isRequired)=>{
|
|
88
|
-
// eslint-disable-next-line no-console
|
|
89
|
-
const storage$1 = storage.create({
|
|
90
|
-
log: console.log
|
|
91
|
-
});
|
|
92
|
-
const exists = await storage$1.exists(configDirectory);
|
|
93
|
-
if (!exists) {
|
|
94
|
-
if (isRequired) {
|
|
95
|
-
throw new Error(`Config directory does not exist and is required: ${configDirectory}`);
|
|
96
|
-
}
|
|
97
|
-
} else if (exists) {
|
|
98
|
-
const isReadable = await storage$1.isDirectoryReadable(configDirectory);
|
|
99
|
-
if (!isReadable) {
|
|
100
|
-
throw new Error(`Config directory exists but is not readable: ${configDirectory}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const validate = async (config, options)=>{
|
|
105
|
-
const logger = options.logger;
|
|
106
|
-
if (options.features.includes('config') && config.configDirectory) {
|
|
107
|
-
await validateConfigDirectory(config.configDirectory, options.defaults.isRequired);
|
|
108
|
-
}
|
|
109
|
-
// Combine the base schema with the user-provided shape
|
|
110
|
-
const fullSchema = zod.z.object({
|
|
111
|
-
...types.ConfigSchema.shape,
|
|
112
|
-
...options.configShape
|
|
113
|
-
});
|
|
114
|
-
logger.debug('Full Schema: \n\n%s\n\n', JSON.stringify(listZodKeys(fullSchema), null, 2));
|
|
115
|
-
// Validate the merged sources against the full schema
|
|
116
|
-
const validationResult = fullSchema.safeParse(config);
|
|
117
|
-
// Check for extraneous keys
|
|
118
|
-
checkForExtraKeys(config, fullSchema, logger);
|
|
119
|
-
if (!validationResult.success) {
|
|
120
|
-
logger.error('Configuration validation failed: %s', JSON.stringify(validationResult.error.format(), null, 2));
|
|
121
|
-
throw new Error(`Configuration validation failed. Check logs for details.`);
|
|
122
|
-
}
|
|
123
|
-
return;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
exports.checkForExtraKeys = checkForExtraKeys;
|
|
127
|
-
exports.listObjectKeys = listObjectKeys;
|
|
128
|
-
exports.listZodKeys = listZodKeys;
|
|
129
|
-
exports.validate = validate;
|
|
130
|
-
//# sourceMappingURL=validate.cjs.map
|
package/dist/validate.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate.cjs","sources":["../src/validate.ts"],"sourcesContent":["import { z, ZodObject } from \"zod\";\nimport { ArgumentError } from \"./error/ArgumentError\";\nimport { ConfigSchema, Logger, Options } from \"./types\";\nimport * as Storage from \"./util/storage\";\nexport { ArgumentError };\n\nexport const listZodKeys = (schema: z.ZodTypeAny, prefix = ''): string[] => {\n // Check if schema has unwrap method (which both ZodOptional and ZodNullable have)\n if (schema._def && (schema._def.typeName === 'ZodOptional' || schema._def.typeName === 'ZodNullable')) {\n // Use type assertion to handle the unwrap method\n const unwrappable = schema as z.ZodOptional<any> | z.ZodNullable<any>;\n return listZodKeys(unwrappable.unwrap(), prefix);\n }\n if (schema._def && schema._def.typeName === 'ZodArray') {\n // Use type assertion to handle the element property\n const arraySchema = schema as z.ZodArray<any>;\n return listZodKeys(arraySchema.element, prefix);\n }\n if (schema._def && schema._def.typeName === 'ZodObject') {\n // Use type assertion to handle the shape property\n const objectSchema = schema as z.ZodObject<any>;\n return Object.entries(objectSchema.shape).flatMap(([key, subschema]) => {\n const fullKey = prefix ? `${prefix}.${key}` : key;\n const nested = listZodKeys(subschema as z.ZodTypeAny, fullKey);\n return nested.length ? nested : fullKey;\n });\n }\n return [];\n}\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => {\n // Check if it's an object, not null, and not an array.\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n};\n\n/**\n * Generates a list of all keys within a JavaScript object, using dot notation for nested keys.\n * Mimics the behavior of listZodKeys but operates on plain objects.\n * For arrays, it inspects the first element that is a plain object to determine nested keys.\n * If an array contains no plain objects, or is empty, the key for the array itself is listed.\n *\n * @param obj The object to introspect.\n * @param prefix Internal use for recursion: the prefix for the current nesting level.\n * @returns An array of strings representing all keys in dot notation.\n */\nexport const listObjectKeys = (obj: Record<string, unknown>, prefix = ''): string[] => {\n const keys = new Set<string>(); // Use Set to automatically handle duplicates from array recursion\n\n for (const key in obj) {\n // Ensure it's an own property, not from the prototype chain\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n const value = obj[key];\n const fullKey = prefix ? `${prefix}.${key}` : key;\n\n if (Array.isArray(value)) {\n // Find the first element that is a plain object to determine structure\n const firstObjectElement = value.find(isPlainObject);\n if (firstObjectElement) {\n // Recurse into the structure of the first object element found\n const nestedKeys = listObjectKeys(firstObjectElement, fullKey);\n nestedKeys.forEach(k => keys.add(k));\n } else {\n // Array is empty or contains no plain objects, list the array key itself\n keys.add(fullKey);\n }\n } else if (isPlainObject(value)) {\n // Recurse into nested plain objects\n const nestedKeys = listObjectKeys(value, fullKey);\n nestedKeys.forEach(k => keys.add(k));\n } else {\n // It's a primitive, null, or other non-plain object/array type\n keys.add(fullKey);\n }\n }\n }\n return Array.from(keys); // Convert Set back to Array\n};\n\n\n\nexport const checkForExtraKeys = (mergedSources: object, fullSchema: ZodObject<any>, logger: Logger | typeof console): void => {\n const allowedKeys = new Set(listZodKeys(fullSchema));\n const actualKeys = listObjectKeys(mergedSources as Record<string, unknown>);\n const extraKeys = actualKeys.filter(key => !allowedKeys.has(key));\n\n if (extraKeys.length > 0) {\n const allowedKeysString = Array.from(allowedKeys).join(', ');\n const extraKeysString = extraKeys.join(', ');\n const errorMessage = `Unknown configuration keys found: ${extraKeysString}. Allowed keys are: ${allowedKeysString}`;\n logger.error(errorMessage);\n throw new Error(`Configuration validation failed: Unknown keys found (${extraKeysString}). Check logs for details.`);\n }\n}\n\nconst validateConfigDirectory = async (configDirectory: string, isRequired: boolean): Promise<void> => {\n // eslint-disable-next-line no-console\n const storage = Storage.create({ log: console.log });\n const exists = await storage.exists(configDirectory);\n if (!exists) {\n if (isRequired) {\n throw new Error(`Config directory does not exist and is required: ${configDirectory}`);\n }\n } else if (exists) {\n const isReadable = await storage.isDirectoryReadable(configDirectory);\n if (!isReadable) {\n throw new Error(`Config directory exists but is not readable: ${configDirectory}`);\n }\n }\n}\n\nexport const validate = async <T extends z.ZodRawShape>(config: z.infer<ZodObject<T & typeof ConfigSchema.shape>>, options: Options<T>): Promise<void> => {\n const logger = options.logger;\n\n if (options.features.includes('config') && config.configDirectory) {\n await validateConfigDirectory(config.configDirectory, options.defaults.isRequired);\n }\n\n // Combine the base schema with the user-provided shape\n const fullSchema = z.object({\n ...ConfigSchema.shape,\n ...options.configShape,\n });\n\n logger.debug('Full Schema: \\n\\n%s\\n\\n', JSON.stringify(listZodKeys(fullSchema), null, 2));\n\n // Validate the merged sources against the full schema\n const validationResult = fullSchema.safeParse(config);\n\n // Check for extraneous keys\n checkForExtraKeys(config, fullSchema, logger);\n\n if (!validationResult.success) {\n logger.error('Configuration validation failed: %s', JSON.stringify(validationResult.error.format(), null, 2));\n throw new Error(`Configuration validation failed. Check logs for details.`);\n }\n\n return;\n}\n\n"],"names":["listZodKeys","schema","prefix","_def","typeName","unwrappable","unwrap","arraySchema","element","objectSchema","Object","entries","shape","flatMap","key","subschema","fullKey","nested","length","isPlainObject","value","Array","isArray","listObjectKeys","obj","keys","Set","prototype","hasOwnProperty","call","firstObjectElement","find","nestedKeys","forEach","k","add","from","checkForExtraKeys","mergedSources","fullSchema","logger","allowedKeys","actualKeys","extraKeys","filter","has","allowedKeysString","join","extraKeysString","errorMessage","error","Error","validateConfigDirectory","configDirectory","isRequired","storage","Storage","log","console","exists","isReadable","isDirectoryReadable","validate","config","options","features","includes","defaults","z","object","ConfigSchema","configShape","debug","JSON","stringify","validationResult","safeParse","success","format"],"mappings":";;;;;;;;AAMaA,MAAAA,WAAAA,GAAc,CAACC,MAAAA,EAAsBC,SAAS,EAAE,GAAA;;AAEzD,IAAA,IAAID,OAAOE,IAAI,KAAKF,MAAAA,CAAOE,IAAI,CAACC,QAAQ,KAAK,aAAA,IAAiBH,OAAOE,IAAI,CAACC,QAAQ,KAAK,aAAY,CAAI,EAAA;;AAEnG,QAAA,MAAMC,WAAcJ,GAAAA,MAAAA;QACpB,OAAOD,WAAAA,CAAYK,WAAYC,CAAAA,MAAM,EAAIJ,EAAAA,MAAAA,CAAAA;AAC7C;IACA,IAAID,MAAAA,CAAOE,IAAI,IAAIF,MAAAA,CAAOE,IAAI,CAACC,QAAQ,KAAK,UAAY,EAAA;;AAEpD,QAAA,MAAMG,WAAcN,GAAAA,MAAAA;QACpB,OAAOD,WAAAA,CAAYO,WAAYC,CAAAA,OAAO,EAAEN,MAAAA,CAAAA;AAC5C;IACA,IAAID,MAAAA,CAAOE,IAAI,IAAIF,MAAAA,CAAOE,IAAI,CAACC,QAAQ,KAAK,WAAa,EAAA;;AAErD,QAAA,MAAMK,YAAeR,GAAAA,MAAAA;QACrB,OAAOS,MAAAA,CAAOC,OAAO,CAACF,YAAaG,CAAAA,KAAK,CAAEC,CAAAA,OAAO,CAAC,CAAC,CAACC,GAAAA,EAAK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AA,CAAKC,SAAS,CAAC1E,WAAAA,CAAYuC,aAAa,IAAM,EAAA,CAAA,CAAA,CAAA;;IAGtF,MAAMoC,gBAAAA,GAAmBpC,UAAWqC,CAAAA,SAAS,CAACb,MAAAA,CAAAA;;AAG9C1B,IAAAA,iBAAAA,CAAkB0B,QAAQxB,UAAYC,EAAAA,MAAAA,CAAAA;IAEtC,IAAI,CAACmC,gBAAiBE,CAAAA,OAAO,EAAE;QAC3BrC,MAAOU,CAAAA,KAAK,CAAC,qCAAA,EAAuCuB,IAAKC,CAAAA,SAAS,CAACC,gBAAAA,CAAiBzB,KAAK,CAAC4B,MAAM,EAAA,EAAI,IAAM,EAAA,CAAA,CAAA,CAAA;AAC1G,QAAA,MAAM,IAAI3B,KAAAA,CAAM,CAAC,wDAAwD,CAAC,CAAA;AAC9E;AAEA,IAAA;AACJ;;;;;;;"}
|
package/eslint.config.mjs
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { defineConfig, globalIgnores } from "eslint/config";
|
|
2
|
-
import typescriptEslint from "@typescript-eslint/eslint-plugin";
|
|
3
|
-
import importPlugin from "eslint-plugin-import";
|
|
4
|
-
import globals from "globals";
|
|
5
|
-
import tsParser from "@typescript-eslint/parser";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
import { fileURLToPath } from "node:url";
|
|
8
|
-
import js from "@eslint/js";
|
|
9
|
-
import { FlatCompat } from "@eslint/eslintrc";
|
|
10
|
-
|
|
11
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
-
const __dirname = path.dirname(__filename);
|
|
13
|
-
const compat = new FlatCompat({
|
|
14
|
-
baseDirectory: __dirname,
|
|
15
|
-
recommendedConfig: js.configs.recommended,
|
|
16
|
-
allConfig: js.configs.all
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export default defineConfig([
|
|
20
|
-
globalIgnores([
|
|
21
|
-
"dist/**",
|
|
22
|
-
"node_modules/**",
|
|
23
|
-
"**/*.test.ts",
|
|
24
|
-
]),
|
|
25
|
-
{
|
|
26
|
-
extends: compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended"),
|
|
27
|
-
|
|
28
|
-
plugins: {
|
|
29
|
-
"@typescript-eslint": typescriptEslint,
|
|
30
|
-
"import": importPlugin,
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
languageOptions: {
|
|
34
|
-
globals: {
|
|
35
|
-
...globals.node,
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
parser: tsParser,
|
|
39
|
-
ecmaVersion: "latest",
|
|
40
|
-
sourceType: "module",
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
rules: {
|
|
44
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
45
|
-
"@typescript-eslint/explicit-function-return-type": "off",
|
|
46
|
-
|
|
47
|
-
"@typescript-eslint/no-unused-vars": ["warn", {
|
|
48
|
-
argsIgnorePattern: "^_",
|
|
49
|
-
}],
|
|
50
|
-
|
|
51
|
-
indent: ["error", 4, {
|
|
52
|
-
SwitchCase: 1,
|
|
53
|
-
}],
|
|
54
|
-
|
|
55
|
-
"import/extensions": ["error", "never", {
|
|
56
|
-
ignorePackages: true,
|
|
57
|
-
pattern: {
|
|
58
|
-
"js": "never",
|
|
59
|
-
"ts": "never",
|
|
60
|
-
"d": "always"
|
|
61
|
-
}
|
|
62
|
-
}],
|
|
63
|
-
|
|
64
|
-
"import/no-extraneous-dependencies": ["error", {
|
|
65
|
-
devDependencies: true,
|
|
66
|
-
optionalDependencies: false,
|
|
67
|
-
peerDependencies: false,
|
|
68
|
-
}],
|
|
69
|
-
|
|
70
|
-
"no-console": ["error"],
|
|
71
|
-
|
|
72
|
-
"no-restricted-imports": ["error", {
|
|
73
|
-
paths: ["dayjs", "fs", "moment-timezone"],
|
|
74
|
-
patterns: [
|
|
75
|
-
{
|
|
76
|
-
group: ["src/**"],
|
|
77
|
-
message: "Use absolute imports instead of relative imports"
|
|
78
|
-
}
|
|
79
|
-
]
|
|
80
|
-
}]
|
|
81
|
-
},
|
|
82
|
-
}]);
|
package/nodemon.json
DELETED
package/vite.config.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
|
-
import { VitePluginNode } from 'vite-plugin-node';
|
|
3
|
-
import replace from '@rollup/plugin-replace';
|
|
4
|
-
// import { visualizer } from 'rollup-plugin-visualizer';
|
|
5
|
-
import { execSync } from 'child_process';
|
|
6
|
-
import dts from 'vite-plugin-dts';
|
|
7
|
-
|
|
8
|
-
let gitInfo = {
|
|
9
|
-
branch: '',
|
|
10
|
-
commit: '',
|
|
11
|
-
tags: '',
|
|
12
|
-
commitDate: '',
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
gitInfo = {
|
|
17
|
-
branch: execSync('git rev-parse --abbrev-ref HEAD').toString().trim(),
|
|
18
|
-
commit: execSync('git rev-parse --short HEAD').toString().trim(),
|
|
19
|
-
tags: '',
|
|
20
|
-
commitDate: execSync('git log -1 --format=%cd --date=iso').toString().trim(),
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
gitInfo.tags = execSync('git tag --points-at HEAD | paste -sd "," -').toString().trim();
|
|
25
|
-
} catch {
|
|
26
|
-
gitInfo.tags = '';
|
|
27
|
-
}
|
|
28
|
-
} catch {
|
|
29
|
-
// eslint-disable-next-line no-console
|
|
30
|
-
console.log('Directory does not have a Git repository, skipping git info');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export default defineConfig({
|
|
35
|
-
server: {
|
|
36
|
-
port: 3000
|
|
37
|
-
},
|
|
38
|
-
plugins: [
|
|
39
|
-
...VitePluginNode({
|
|
40
|
-
adapter: 'express',
|
|
41
|
-
appPath: './src/cardigantime.ts',
|
|
42
|
-
exportName: 'viteNodeApp',
|
|
43
|
-
tsCompiler: 'swc',
|
|
44
|
-
swcOptions: {
|
|
45
|
-
sourceMaps: true,
|
|
46
|
-
},
|
|
47
|
-
}),
|
|
48
|
-
// visualizer({
|
|
49
|
-
// template: 'network',
|
|
50
|
-
// filename: 'network.html',
|
|
51
|
-
// projectRoot: process.cwd(),
|
|
52
|
-
// }),
|
|
53
|
-
replace({
|
|
54
|
-
'__VERSION__': process.env.npm_package_version,
|
|
55
|
-
'__GIT_BRANCH__': gitInfo.branch,
|
|
56
|
-
'__GIT_COMMIT__': gitInfo.commit,
|
|
57
|
-
'__GIT_TAGS__': gitInfo.tags === '' ? '' : `T:${gitInfo.tags}`,
|
|
58
|
-
'__GIT_COMMIT_DATE__': gitInfo.commitDate,
|
|
59
|
-
'__SYSTEM_INFO__': `${process.platform} ${process.arch} ${process.version}`,
|
|
60
|
-
preventAssignment: true,
|
|
61
|
-
}),
|
|
62
|
-
dts({
|
|
63
|
-
entryRoot: 'src',
|
|
64
|
-
outDir: 'dist',
|
|
65
|
-
exclude: ['**/*.test.ts'],
|
|
66
|
-
include: ['**/*.ts'],
|
|
67
|
-
}),
|
|
68
|
-
],
|
|
69
|
-
build: {
|
|
70
|
-
target: 'esnext',
|
|
71
|
-
outDir: 'dist',
|
|
72
|
-
lib: {
|
|
73
|
-
entry: './src/cardigantime.ts',
|
|
74
|
-
formats: ['es', 'cjs'],
|
|
75
|
-
},
|
|
76
|
-
rollupOptions: {
|
|
77
|
-
input: 'src/cardigantime.ts',
|
|
78
|
-
output: [
|
|
79
|
-
{
|
|
80
|
-
format: 'esm',
|
|
81
|
-
entryFileNames: '[name].js',
|
|
82
|
-
preserveModules: true,
|
|
83
|
-
exports: 'named',
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
format: 'cjs',
|
|
87
|
-
entryFileNames: '[name].cjs',
|
|
88
|
-
preserveModules: true,
|
|
89
|
-
exports: 'named',
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
},
|
|
93
|
-
// Make sure Vite generates ESM-compatible code
|
|
94
|
-
modulePreload: false,
|
|
95
|
-
minify: false,
|
|
96
|
-
sourcemap: true
|
|
97
|
-
},
|
|
98
|
-
});
|
package/vitest.config.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vitest/config';
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
test: {
|
|
5
|
-
globals: false,
|
|
6
|
-
environment: 'node',
|
|
7
|
-
setupFiles: ['tests/setup.ts'],
|
|
8
|
-
coverage: {
|
|
9
|
-
provider: 'v8',
|
|
10
|
-
reporter: ['text', 'html', 'lcov'],
|
|
11
|
-
lines: 75,
|
|
12
|
-
branches: 56,
|
|
13
|
-
functions: 82,
|
|
14
|
-
statements: 75,
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
});
|