@signaltree/ng-forms 4.2.1 → 5.0.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/audit/audit.js +70 -0
- package/dist/audit/index.js +1 -0
- package/dist/get-changes.js +11 -0
- package/package.json +7 -2
- package/src/audit/audit.d.ts +17 -7
- package/src/audit/index.d.ts +1 -1
- package/dist/constants.js +0 -6
- package/dist/core/async-validators.js +0 -24
- package/dist/core/ng-forms.js +0 -880
- package/dist/core/validators.js +0 -56
- package/dist/deep-clone.js +0 -80
- package/dist/history/history.js +0 -113
- package/dist/index.js +0 -4
- package/dist/lru-cache.js +0 -64
- package/dist/match-path.js +0 -13
- package/dist/merge-deep.js +0 -26
- package/dist/parse-path.js +0 -13
- package/dist/snapshots-equal.js +0 -5
- package/dist/tslib.es6.js +0 -34
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { getChanges } from '../get-changes.js';
|
|
2
|
+
|
|
3
|
+
function createAuditTracker(tree, auditLog, config = {}) {
|
|
4
|
+
const {
|
|
5
|
+
getMetadata,
|
|
6
|
+
includePreviousValues = false,
|
|
7
|
+
filter,
|
|
8
|
+
maxEntries = 0
|
|
9
|
+
} = config;
|
|
10
|
+
let previousState = structuredClone(tree());
|
|
11
|
+
let isTracking = true;
|
|
12
|
+
const handleChange = () => {
|
|
13
|
+
if (!isTracking) return;
|
|
14
|
+
const currentState = tree();
|
|
15
|
+
const changes = getChanges(previousState, currentState);
|
|
16
|
+
if (Object.keys(changes).length > 0) {
|
|
17
|
+
if (filter && !filter(changes)) {
|
|
18
|
+
previousState = structuredClone(currentState);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const entry = {
|
|
22
|
+
timestamp: Date.now(),
|
|
23
|
+
changes,
|
|
24
|
+
metadata: getMetadata?.()
|
|
25
|
+
};
|
|
26
|
+
if (includePreviousValues) {
|
|
27
|
+
const prevValues = {};
|
|
28
|
+
for (const key of Object.keys(changes)) {
|
|
29
|
+
prevValues[key] = previousState[key];
|
|
30
|
+
}
|
|
31
|
+
entry.previousValues = prevValues;
|
|
32
|
+
}
|
|
33
|
+
auditLog.push(entry);
|
|
34
|
+
if (maxEntries > 0 && auditLog.length > maxEntries) {
|
|
35
|
+
auditLog.splice(0, auditLog.length - maxEntries);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
previousState = structuredClone(currentState);
|
|
39
|
+
};
|
|
40
|
+
let unsubscribe;
|
|
41
|
+
let pollingId;
|
|
42
|
+
try {
|
|
43
|
+
unsubscribe = tree.subscribe(handleChange);
|
|
44
|
+
} catch {
|
|
45
|
+
pollingId = setInterval(handleChange, 100);
|
|
46
|
+
}
|
|
47
|
+
return () => {
|
|
48
|
+
isTracking = false;
|
|
49
|
+
if (unsubscribe) {
|
|
50
|
+
unsubscribe();
|
|
51
|
+
}
|
|
52
|
+
if (pollingId) {
|
|
53
|
+
clearInterval(pollingId);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function createAuditCallback(auditLog, getMetadata) {
|
|
58
|
+
return (previousState, currentState) => {
|
|
59
|
+
const changes = getChanges(previousState, currentState);
|
|
60
|
+
if (Object.keys(changes).length > 0) {
|
|
61
|
+
auditLog.push({
|
|
62
|
+
timestamp: Date.now(),
|
|
63
|
+
changes,
|
|
64
|
+
metadata: getMetadata?.()
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { createAuditCallback, createAuditTracker };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createAuditCallback, createAuditTracker } from './audit.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signaltree/ng-forms",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Complete Angular forms integration for SignalTree. FormTree creation, custom directives, validators, form state tracking, and RxJS bridge.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -12,12 +12,17 @@
|
|
|
12
12
|
"types": "./src/index.d.ts",
|
|
13
13
|
"import": "./dist/index.js",
|
|
14
14
|
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./audit": {
|
|
17
|
+
"types": "./src/audit/index.d.ts",
|
|
18
|
+
"import": "./dist/audit/index.js",
|
|
19
|
+
"default": "./dist/audit/index.js"
|
|
15
20
|
}
|
|
16
21
|
},
|
|
17
22
|
"peerDependencies": {
|
|
18
23
|
"@angular/core": "^20.3.0",
|
|
19
24
|
"@angular/forms": "^20.3.0",
|
|
20
|
-
"@signaltree/core": "^
|
|
25
|
+
"@signaltree/core": "^5.0.0",
|
|
21
26
|
"rxjs": "^7.0.0"
|
|
22
27
|
},
|
|
23
28
|
"devDependencies": {
|
package/src/audit/audit.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SignalTree } from '@signaltree/core';
|
|
2
2
|
export interface AuditEntry<T = unknown> {
|
|
3
3
|
timestamp: number;
|
|
4
4
|
changes: Partial<T>;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
source?: string;
|
|
8
|
-
description?: string;
|
|
9
|
-
};
|
|
5
|
+
previousValues?: Partial<T>;
|
|
6
|
+
metadata?: AuditMetadata;
|
|
10
7
|
}
|
|
11
|
-
export
|
|
8
|
+
export interface AuditMetadata {
|
|
9
|
+
userId?: string;
|
|
10
|
+
source?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface AuditTrackerConfig<T> {
|
|
15
|
+
getMetadata?: () => AuditMetadata;
|
|
16
|
+
includePreviousValues?: boolean;
|
|
17
|
+
filter?: (changes: Partial<T>) => boolean;
|
|
18
|
+
maxEntries?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function createAuditTracker<T extends Record<string, unknown>>(tree: SignalTree<T>, auditLog: AuditEntry<T>[], config?: AuditTrackerConfig<T>): () => void;
|
|
21
|
+
export declare function createAuditCallback<T extends Record<string, unknown>>(auditLog: AuditEntry<T>[], getMetadata?: () => AuditMetadata): (previousState: T, currentState: T) => void;
|
package/src/audit/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createAuditTracker, createAuditCallback, type AuditEntry, type AuditMetadata, type AuditTrackerConfig, } from './audit.js';
|
package/dist/constants.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { isObservable, firstValueFrom } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
function unique(checkFn, message = 'Already exists') {
|
|
4
|
-
return async value => {
|
|
5
|
-
if (!value) return null;
|
|
6
|
-
const exists = await checkFn(value);
|
|
7
|
-
return exists ? message : null;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
function debounce(validator, delayMs) {
|
|
11
|
-
let timeoutId;
|
|
12
|
-
return async value => {
|
|
13
|
-
return new Promise(resolve => {
|
|
14
|
-
clearTimeout(timeoutId);
|
|
15
|
-
timeoutId = setTimeout(async () => {
|
|
16
|
-
const maybeAsync = validator(value);
|
|
17
|
-
const result = isObservable(maybeAsync) ? await firstValueFrom(maybeAsync) : await maybeAsync;
|
|
18
|
-
resolve(result);
|
|
19
|
-
}, delayMs);
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { debounce, unique };
|