@cyberismo/data-handler 0.0.16 → 0.0.18
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/command-handler.js +5 -7
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.js +4 -4
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/create.js +1 -1
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/fetch.d.ts +8 -0
- package/dist/commands/fetch.js +101 -23
- package/dist/commands/fetch.js.map +1 -1
- package/dist/commands/import.d.ts +5 -2
- package/dist/commands/import.js +12 -3
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/remove.d.ts +3 -1
- package/dist/commands/remove.js +7 -1
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.js +5 -0
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +4 -2
- package/dist/commands/show.js +8 -2
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/validate.js +3 -5
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/card-container.d.ts +7 -5
- package/dist/containers/card-container.js +30 -5
- package/dist/containers/card-container.js.map +1 -1
- package/dist/containers/project/project-paths.d.ts +2 -0
- package/dist/containers/project/project-paths.js +6 -0
- package/dist/containers/project/project-paths.js.map +1 -1
- package/dist/containers/project/resource-cache.js +9 -7
- package/dist/containers/project/resource-cache.js.map +1 -1
- package/dist/containers/project.d.ts +11 -2
- package/dist/containers/project.js +54 -8
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.js +4 -4
- package/dist/containers/template.js.map +1 -1
- package/dist/interfaces/command-options.d.ts +3 -1
- package/dist/interfaces/project-interfaces.d.ts +5 -5
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/project-settings.d.ts +5 -0
- package/dist/project-settings.js +12 -0
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/card-type-resource.d.ts +6 -2
- package/dist/resources/card-type-resource.js +68 -86
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/field-type-resource.d.ts +5 -1
- package/dist/resources/field-type-resource.js +49 -54
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +14 -1
- package/dist/resources/file-resource.js +29 -0
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/link-type-resource.d.ts +5 -1
- package/dist/resources/link-type-resource.js +28 -30
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +1 -0
- package/dist/resources/resource-object.js +52 -1
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.js +5 -26
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +1 -1
- package/dist/resources/workflow-resource.js +79 -76
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/utils/configuration-logger.d.ts +91 -0
- package/dist/utils/configuration-logger.js +151 -0
- package/dist/utils/configuration-logger.js.map +1 -0
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/constants.js +5 -3
- package/dist/utils/constants.js.map +1 -1
- package/package.json +4 -4
- package/src/command-handler.ts +17 -9
- package/src/command-manager.ts +4 -4
- package/src/commands/create.ts +1 -1
- package/src/commands/fetch.ts +143 -34
- package/src/commands/import.ts +13 -1
- package/src/commands/remove.ts +10 -1
- package/src/commands/rename.ts +15 -0
- package/src/commands/show.ts +11 -3
- package/src/commands/validate.ts +3 -7
- package/src/containers/card-container.ts +37 -5
- package/src/containers/project/project-paths.ts +8 -0
- package/src/containers/project/resource-cache.ts +12 -9
- package/src/containers/project.ts +76 -9
- package/src/containers/template.ts +4 -4
- package/src/interfaces/command-options.ts +3 -1
- package/src/interfaces/project-interfaces.ts +5 -5
- package/src/project-settings.ts +13 -0
- package/src/resources/card-type-resource.ts +91 -109
- package/src/resources/field-type-resource.ts +60 -64
- package/src/resources/file-resource.ts +43 -1
- package/src/resources/link-type-resource.ts +32 -36
- package/src/resources/resource-object.ts +73 -1
- package/src/resources/template-resource.ts +6 -26
- package/src/resources/workflow-resource.ts +102 -93
- package/src/utils/configuration-logger.ts +206 -0
- package/src/utils/constants.ts +5 -3
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2025
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU Affero General Public License version 3 as published by
|
|
7
|
+
the Free Software Foundation. This program is distributed in the hope that it
|
|
8
|
+
will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
9
|
+
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
10
|
+
See the GNU Affero General Public License for more details.
|
|
11
|
+
You should have received a copy of the GNU Affero General Public
|
|
12
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { readFile, rename } from 'node:fs/promises';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
|
|
18
|
+
import { getChildLogger } from './log-utils.js';
|
|
19
|
+
import { ProjectPaths } from '../containers/project/project-paths.js';
|
|
20
|
+
import { writeFileSafe, pathExists } from './file-utils.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Enum for configuration change operation types.
|
|
24
|
+
*/
|
|
25
|
+
export enum ConfigurationOperation {
|
|
26
|
+
MODULE_ADD = 'module_add',
|
|
27
|
+
MODULE_REMOVE = 'module_remove',
|
|
28
|
+
PROJECT_RENAME = 'project_rename',
|
|
29
|
+
RESOURCE_CREATE = 'resource_create',
|
|
30
|
+
RESOURCE_DELETE = 'resource_delete',
|
|
31
|
+
RESOURCE_RENAME = 'resource_rename',
|
|
32
|
+
RESOURCE_UPDATE = 'resource_update',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Individual log entry representing a single configuration change.
|
|
37
|
+
* @param timestamp Timestamp when the operation occurred (ISO string)
|
|
38
|
+
* @param operation Type of operation performed
|
|
39
|
+
* @param target Target of the operation
|
|
40
|
+
* @param parameters Additional parameters specific to the operation
|
|
41
|
+
*/
|
|
42
|
+
export interface ConfigurationLogEntry {
|
|
43
|
+
timestamp: string;
|
|
44
|
+
operation: ConfigurationOperation;
|
|
45
|
+
target: string;
|
|
46
|
+
parameters?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Options for logging configuration changes.
|
|
51
|
+
* @param parameters Additional parameters to store with the operation
|
|
52
|
+
*/
|
|
53
|
+
export interface ConfigurationLogOptions {
|
|
54
|
+
parameters?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Logger for tracking configuration changes that affect project structure.
|
|
59
|
+
*/
|
|
60
|
+
export class ConfigurationLogger {
|
|
61
|
+
/**
|
|
62
|
+
* Path to the configuration log file.
|
|
63
|
+
* @param projectPath Path to the project root
|
|
64
|
+
* @returns Path to the log file
|
|
65
|
+
*/
|
|
66
|
+
public static logFile(projectPath: string): string {
|
|
67
|
+
const paths = new ProjectPaths(projectPath);
|
|
68
|
+
return paths.configurationChangesLog;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Clears all log entries.
|
|
73
|
+
* @param projectPath Path to the project root
|
|
74
|
+
* @note Use with caution.
|
|
75
|
+
*/
|
|
76
|
+
public static async clearLog(projectPath: string): Promise<void> {
|
|
77
|
+
const logFile = ConfigurationLogger.logFile(projectPath);
|
|
78
|
+
await writeFileSafe(logFile, '', 'utf-8');
|
|
79
|
+
const logger = getChildLogger({ module: 'ConfigurationLogger' });
|
|
80
|
+
logger.info('Configuration log cleared');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Create a versioned snapshot of the current migration log.
|
|
85
|
+
* Renames current migrationLog.jsonl to migrationLog_<version>.jsonl
|
|
86
|
+
* @param projectPath Path to the project root
|
|
87
|
+
* @param version Version identifier (e.g., "1.0.0", "v2")
|
|
88
|
+
* @returns Path to the versioned log file
|
|
89
|
+
*/
|
|
90
|
+
public static async createVersion(
|
|
91
|
+
projectPath: string,
|
|
92
|
+
version: string,
|
|
93
|
+
): Promise<string> {
|
|
94
|
+
const paths = new ProjectPaths(projectPath);
|
|
95
|
+
const currentLogPath = paths.configurationChangesLog;
|
|
96
|
+
const versionedLogPath = join(
|
|
97
|
+
paths.migrationLogFolder,
|
|
98
|
+
`migrationLog_${version}.jsonl`,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
// Only create version if current log exists and has content
|
|
102
|
+
if (!pathExists(currentLogPath)) {
|
|
103
|
+
throw new Error('No current migration log exists to version');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const content = await readFile(currentLogPath, 'utf-8');
|
|
107
|
+
if (!content.trim()) {
|
|
108
|
+
throw new Error('Current migration log is empty');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Rename current to versioned
|
|
112
|
+
await rename(currentLogPath, versionedLogPath);
|
|
113
|
+
|
|
114
|
+
const logger = getChildLogger({ module: 'ConfigurationLogger' });
|
|
115
|
+
logger.info(
|
|
116
|
+
`Created migration to version: ${version} at ${versionedLogPath}`,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
return versionedLogPath;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Reads all configuration log entries using JSON Lines format.
|
|
124
|
+
* @param projectPath Path to the project root
|
|
125
|
+
* @returns Array of log entries
|
|
126
|
+
*/
|
|
127
|
+
public static async entries(
|
|
128
|
+
projectPath: string,
|
|
129
|
+
): Promise<ConfigurationLogEntry[]> {
|
|
130
|
+
const logFile = ConfigurationLogger.logFile(projectPath);
|
|
131
|
+
const logger = getChildLogger({ module: 'ConfigurationLogger' });
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
const content = await readFile(logFile, 'utf-8');
|
|
135
|
+
const lines = content
|
|
136
|
+
.trim()
|
|
137
|
+
.split('\n')
|
|
138
|
+
.filter((line) => line.trim());
|
|
139
|
+
|
|
140
|
+
const entries: ConfigurationLogEntry[] = [];
|
|
141
|
+
for (const line of lines) {
|
|
142
|
+
try {
|
|
143
|
+
const entry = JSON.parse(line) as ConfigurationLogEntry;
|
|
144
|
+
if (entry.timestamp && entry.operation && entry.target) {
|
|
145
|
+
entries.push(entry);
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
logger.error(`Invalid configuration line: ${line}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return entries;
|
|
153
|
+
} catch (error) {
|
|
154
|
+
logger.error({ error }, `Failed to read configuration log`);
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Check if a configuration log exists for the given project path.
|
|
161
|
+
* @param projectPath Path to the project root
|
|
162
|
+
* @returns True if log file exists
|
|
163
|
+
*/
|
|
164
|
+
public static hasLog(projectPath: string): boolean {
|
|
165
|
+
const logPath = new ProjectPaths(projectPath).configurationChangesLog;
|
|
166
|
+
return pathExists(logPath);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Log a configuration change operation.
|
|
171
|
+
* @note This is designed to be called AFTER the operation succeeds.
|
|
172
|
+
* @param projectPath Path to the project root
|
|
173
|
+
* @param operation The type of operation
|
|
174
|
+
* @param target The target of the operation
|
|
175
|
+
* @param options Additional options for the log entry
|
|
176
|
+
*/
|
|
177
|
+
public static async log(
|
|
178
|
+
projectPath: string,
|
|
179
|
+
operation: ConfigurationOperation,
|
|
180
|
+
target: string,
|
|
181
|
+
options?: ConfigurationLogOptions,
|
|
182
|
+
): Promise<void> {
|
|
183
|
+
const logFile = ConfigurationLogger.logFile(projectPath);
|
|
184
|
+
const logger = getChildLogger({ module: 'ConfigurationLogger' });
|
|
185
|
+
|
|
186
|
+
try {
|
|
187
|
+
const entry: ConfigurationLogEntry = {
|
|
188
|
+
timestamp: new Date().toISOString(),
|
|
189
|
+
operation,
|
|
190
|
+
target,
|
|
191
|
+
parameters: options?.parameters,
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
await writeFileSafe(logFile, JSON.stringify(entry) + '\n', {
|
|
195
|
+
flag: 'a',
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
logger.debug(`Logged ${operation} operation for target: ${target}`);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
logger.error(
|
|
201
|
+
{ error, operation, target },
|
|
202
|
+
`Configuration logging failed`,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
package/src/utils/constants.ts
CHANGED
|
@@ -42,13 +42,15 @@ export const VALID_FOLDER_RESOURCE_FILES = [
|
|
|
42
42
|
* These are field names that are non-custom fields that present in metadata
|
|
43
43
|
*/
|
|
44
44
|
export const PREDEFINED_FIELDS = [
|
|
45
|
-
'rank',
|
|
46
45
|
'cardType',
|
|
47
|
-
'
|
|
48
|
-
'workflowState',
|
|
46
|
+
'labels',
|
|
49
47
|
'lastUpdated',
|
|
50
48
|
'lastTransitioned',
|
|
49
|
+
'links',
|
|
50
|
+
'rank',
|
|
51
51
|
'templateCardKey',
|
|
52
|
+
'title',
|
|
53
|
+
'workflowState',
|
|
52
54
|
] satisfies (keyof PredefinedCardMetadata)[];
|
|
53
55
|
|
|
54
56
|
/**
|