json-log-line 0.0.3 → 1.0.1
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 +28 -0
- package/dist/{src/index.d.ts → index.d.ts} +1 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/{src/index.js → index.js} +18 -15
- package/dist/{src/utils → utils}/is-empty.d.ts +1 -0
- package/dist/utils/is-empty.d.ts.map +1 -0
- package/dist/{src/utils → utils}/is-empty.js +1 -2
- package/dist/{src/utils → utils}/is-object.d.ts +1 -0
- package/dist/utils/is-object.d.ts.map +1 -0
- package/dist/{src/utils → utils}/is-object.js +1 -2
- package/package.json +29 -30
- package/dist/src/index.js.map +0 -1
- package/dist/src/utils/is-empty.js.map +0 -1
- package/dist/src/utils/is-object.js.map +0 -1
- package/dist/test/create-log-line.d.ts +0 -1
- package/dist/test/create-log-line.js +0 -71
- package/dist/test/create-log-line.js.map +0 -1
package/README.md
CHANGED
|
@@ -105,6 +105,34 @@ Format is an object the represents how you want to parse the log object. It will
|
|
|
105
105
|
|
|
106
106
|
A special key that contains the rest of the log object fields which were both included and not formatted by a format function.
|
|
107
107
|
|
|
108
|
+
#### Multi keys
|
|
109
|
+
|
|
110
|
+
You can map a single formatter to multiple keys by separating them with a pipe (`|`). Each key is resolved independently (dot notation is supported) and rendered in order. Every matched value is passed through the same formatter, and each consumed key is removed from the remaining `extraFields` payload.
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
const lineFormatter = logLineFactory({
|
|
114
|
+
format: {
|
|
115
|
+
// Applies to both top-level keys
|
|
116
|
+
'foo|baz': (value) => `!${value}`,
|
|
117
|
+
// Works with nested keys, too
|
|
118
|
+
'nested.a|other.a': (value) => `:${value}:`,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
console.log(
|
|
123
|
+
lineFormatter(
|
|
124
|
+
JSON.stringify({
|
|
125
|
+
foo: 'bar',
|
|
126
|
+
baz: 'buz',
|
|
127
|
+
nested: {a: 'x', b: 'y'},
|
|
128
|
+
other: {a: 'z'},
|
|
129
|
+
}),
|
|
130
|
+
),
|
|
131
|
+
);
|
|
132
|
+
// => !bar !buz :x: :z:
|
|
133
|
+
// {"nested":{"b":"y"},"other":{}}
|
|
134
|
+
```
|
|
135
|
+
|
|
108
136
|
### include
|
|
109
137
|
|
|
110
138
|
`string[]`
|
|
@@ -2,7 +2,6 @@ export type Options = {
|
|
|
2
2
|
exclude?: string | string[];
|
|
3
3
|
include?: string | string[];
|
|
4
4
|
format?: Record<string, (value: any, parsedLogObject?: any, ...arguments_: any[]) => string>;
|
|
5
|
-
logLineKeys?: string | string[];
|
|
6
5
|
};
|
|
7
6
|
export declare function logLineFactory({
|
|
8
7
|
/**
|
|
@@ -17,3 +16,4 @@ include,
|
|
|
17
16
|
* Format functions for any given key, keys of the object are automatically included and cannot be excluded
|
|
18
17
|
*/
|
|
19
18
|
format, }?: Options): (inputData: string | Record<string, unknown>) => string;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,OAAO,GAAG;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CACb,MAAM,EACN,CAAC,KAAK,EAAE,GAAG,EAAE,eAAe,CAAC,EAAE,GAAG,EAAE,GAAG,UAAU,EAAE,GAAG,EAAE,KAAK,MAAM,CACpE,CAAC;CACH,CAAC;AAMF,wBAAgB,cAAc,CAAC;AAC7B;;GAEG;AACH,OAAY;AACZ;;GAEG;AACH,OAAY;AACZ;;GAEG;AACH,MAAW,GACZ,GAAE,OAAY,IASI,WAAW,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAAM,CA0FtE"}
|
|
@@ -3,8 +3,8 @@ import unset from 'unset-value';
|
|
|
3
3
|
import get from 'get-value';
|
|
4
4
|
import set from 'set-value';
|
|
5
5
|
import deepMerge from '@fastify/deepmerge';
|
|
6
|
-
import isObject from
|
|
7
|
-
import isEmpty from
|
|
6
|
+
import isObject from "./utils/is-object.js";
|
|
7
|
+
import isEmpty from "./utils/is-empty.js";
|
|
8
8
|
const nl = '\n';
|
|
9
9
|
export function logLineFactory({
|
|
10
10
|
/**
|
|
@@ -20,6 +20,7 @@ include = [],
|
|
|
20
20
|
*/
|
|
21
21
|
format = {}, } = {}) {
|
|
22
22
|
const logLineKeys = Object.keys(format);
|
|
23
|
+
const splitLogLineKeys = logLineKeys.flatMap((key) => key.split('|'));
|
|
23
24
|
format.extraFields ||= (object) => JSON.stringify(object) + nl;
|
|
24
25
|
/**
|
|
25
26
|
* @param inputData - The input data to be formatted can be a JSON stringified object or a plain object
|
|
@@ -42,7 +43,7 @@ format = {}, } = {}) {
|
|
|
42
43
|
}
|
|
43
44
|
// cache the whitelist
|
|
44
45
|
const whiteListObject = {};
|
|
45
|
-
for (const key of [...
|
|
46
|
+
for (const key of [...splitLogLineKeys, ...include]) {
|
|
46
47
|
const value = get(object, key);
|
|
47
48
|
if (value) {
|
|
48
49
|
set(whiteListObject, key, value);
|
|
@@ -55,19 +56,22 @@ format = {}, } = {}) {
|
|
|
55
56
|
// add back in the whitelist
|
|
56
57
|
object = deepMerge()(object, whiteListObject);
|
|
57
58
|
const output = [];
|
|
58
|
-
for (const
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
for (const _key of logLineKeys) {
|
|
60
|
+
const keys = _key.split('|');
|
|
61
|
+
for (const key of keys) {
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
63
|
+
const value = get(object, key);
|
|
64
|
+
if (!value) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const formatter = format[_key];
|
|
68
|
+
if (formatter) {
|
|
69
|
+
output.push(formatter(value, object));
|
|
70
|
+
}
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
73
|
// remove the properties that were used to create the log-line
|
|
70
|
-
for (const key of
|
|
74
|
+
for (const key of splitLogLineKeys) {
|
|
71
75
|
unset(object, key);
|
|
72
76
|
}
|
|
73
77
|
// remove empty blacklist that may have had whitelisted properties
|
|
@@ -81,7 +85,7 @@ format = {}, } = {}) {
|
|
|
81
85
|
// extra fields that were not in the logLine nor in the log line nor blacklisted
|
|
82
86
|
// so these are the ones we want to prettify and highlight
|
|
83
87
|
if (isObject(object) && !isEmpty(object) && format.extraFields) {
|
|
84
|
-
outputString = outputString.concat(format.extraFields(object));
|
|
88
|
+
outputString = outputString.concat(format.extraFields(object)); // eslint-disable-line unicorn/prefer-spread
|
|
85
89
|
}
|
|
86
90
|
if (!outputString.endsWith(nl)) {
|
|
87
91
|
outputString += nl;
|
|
@@ -97,4 +101,3 @@ format = {}, } = {}) {
|
|
|
97
101
|
}
|
|
98
102
|
};
|
|
99
103
|
}
|
|
100
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-empty.d.ts","sourceRoot":"","sources":["../../src/utils/is-empty.ts"],"names":[],"mappings":"AAEA,iBAAS,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAOjE;AAED,eAAe,OAAO,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import isObject from
|
|
1
|
+
import isObject from "./is-object.js";
|
|
2
2
|
function isEmpty(object) {
|
|
3
3
|
return Boolean(isObject(object) &&
|
|
4
4
|
(object === undefined ||
|
|
@@ -6,4 +6,3 @@ function isEmpty(object) {
|
|
|
6
6
|
Object.keys(object).length === 0));
|
|
7
7
|
}
|
|
8
8
|
export default isEmpty;
|
|
9
|
-
//# sourceMappingURL=is-empty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-object.d.ts","sourceRoot":"","sources":["../../src/utils/is-object.ts"],"names":[],"mappings":"AACA,iBAAS,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAIjD;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-restricted-types
|
|
2
2
|
function isObject(input) {
|
|
3
3
|
return Boolean(input && Object.prototype.toString.apply(input) === '[object Object]');
|
|
4
4
|
}
|
|
5
5
|
export default isObject;
|
|
6
|
-
//# sourceMappingURL=is-object.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-log-line",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A utility for building awesome log lines from JSON",
|
|
5
5
|
"homepage": "https://github.com/spence-s/json-log-line",
|
|
6
6
|
"bugs": {
|
|
@@ -32,18 +32,13 @@
|
|
|
32
32
|
],
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "npm run clean && tsc --project tsconfig.build.json",
|
|
35
|
-
"build:test": "npm run clean && tsc --project tsconfig.json",
|
|
36
|
-
"build:watch": "npm run clean && tsc --project tsconfig.json --watch",
|
|
37
35
|
"check": "tsc --project ./tsconfig.json",
|
|
38
36
|
"clean": "rimraf dist",
|
|
39
|
-
"
|
|
40
|
-
"dev:watch": "NODE_NO_WARNINGS=1 node --watch --loader ts-node/esm/transpile-only ./src/index.ts",
|
|
41
|
-
"lint": "xo",
|
|
42
|
-
"lint:fix": "xo --fix",
|
|
37
|
+
"lint": "npm run check && xo",
|
|
43
38
|
"prepare": "husky",
|
|
39
|
+
"prepublish": "npm run build",
|
|
44
40
|
"release": "np",
|
|
45
|
-
"test": "
|
|
46
|
-
"test:watch": "ava --watch",
|
|
41
|
+
"test": "c8 ava",
|
|
47
42
|
"update": "ncu -i"
|
|
48
43
|
},
|
|
49
44
|
"prettier": {
|
|
@@ -52,41 +47,45 @@
|
|
|
52
47
|
]
|
|
53
48
|
},
|
|
54
49
|
"ava": {
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"!dist/test/fixtures/**",
|
|
58
|
-
"!dist/test/helpers/**"
|
|
50
|
+
"extensions": [
|
|
51
|
+
"ts"
|
|
59
52
|
],
|
|
60
|
-
"
|
|
61
|
-
"
|
|
53
|
+
"files": [
|
|
54
|
+
"test/**",
|
|
55
|
+
"!test/fixtures/**",
|
|
56
|
+
"!test/helpers/**"
|
|
62
57
|
],
|
|
63
58
|
"verbose": true
|
|
64
59
|
},
|
|
65
60
|
"dependencies": {
|
|
66
61
|
"@fastify/deepmerge": "^3.1.0",
|
|
67
62
|
"fast-json-parse": "^1.0.3",
|
|
68
|
-
"get-value": "^
|
|
63
|
+
"get-value": "^4.0.1",
|
|
69
64
|
"set-value": "^4.1.0",
|
|
70
65
|
"unset-value": "^2.0.1"
|
|
71
66
|
},
|
|
72
67
|
"devDependencies": {
|
|
73
|
-
"@commitlint/cli": "^
|
|
74
|
-
"@commitlint/config-conventional": "^
|
|
68
|
+
"@commitlint/cli": "^20.2.0",
|
|
69
|
+
"@commitlint/config-conventional": "^20.2.0",
|
|
75
70
|
"@types/get-value": "^3.0.5",
|
|
76
|
-
"@types/node": "^
|
|
71
|
+
"@types/node": "^25.0.3",
|
|
77
72
|
"@types/set-value": "^4.0.3",
|
|
78
|
-
"ava": "^6.1
|
|
79
|
-
"c8": "^10.1.
|
|
80
|
-
"husky": "^9.1.
|
|
81
|
-
"lint-staged": "^
|
|
82
|
-
"np": "^10.0
|
|
73
|
+
"ava": "^6.4.1",
|
|
74
|
+
"c8": "^10.1.3",
|
|
75
|
+
"husky": "^9.1.7",
|
|
76
|
+
"lint-staged": "^16.2.7",
|
|
77
|
+
"np": "^10.2.0",
|
|
83
78
|
"npm-check-updates": "latest",
|
|
84
|
-
"npm-package-json-lint": "^
|
|
85
|
-
"npm-package-json-lint-config-default": "^
|
|
86
|
-
"prettier": "^3.
|
|
87
|
-
"prettier-plugin-packagejson": "^2.5.
|
|
88
|
-
"rimraf": "^6.
|
|
79
|
+
"npm-package-json-lint": "^9.0.0",
|
|
80
|
+
"npm-package-json-lint-config-default": "^8.0.1",
|
|
81
|
+
"prettier": "^3.7.4",
|
|
82
|
+
"prettier-plugin-packagejson": "^2.5.20",
|
|
83
|
+
"rimraf": "^6.1.2",
|
|
89
84
|
"ts-node": "^10.9.2",
|
|
90
|
-
"
|
|
85
|
+
"typescript": "^5.9.3",
|
|
86
|
+
"xo": "^1.2.3"
|
|
87
|
+
},
|
|
88
|
+
"engines": {
|
|
89
|
+
"node": ">=22"
|
|
91
90
|
}
|
|
92
91
|
}
|
package/dist/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAC5C,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAc1C,MAAM,EAAE,GAAG,IAAI,CAAC;AAEhB,MAAM,UAAU,cAAc,CAAC;AAC7B;;GAEG;AACH,OAAO,GAAG,EAAE;AACZ;;GAEG;AACH,OAAO,GAAG,EAAE;AACZ;;GAEG;AACH,MAAM,GAAG,EAAE,MACA,EAAE;IACb,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAA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S,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;YACrC,CAAC;YAED,OAAO,YAAY,CAAC;QACtB,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACnB,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-empty.js","sourceRoot":"","sources":["../../../src/utils/is-empty.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC,SAAS,OAAO,CAAC,MAAe;IAC9B,OAAO,OAAO,CACZ,QAAQ,CAAC,MAAM,CAAC;QACd,CAAC,MAAM,KAAK,SAAS;YACnB,MAAM,KAAK,IAAI;YACf,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CACtC,CAAC;AACJ,CAAC;AAED,eAAe,OAAO,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-object.js","sourceRoot":"","sources":["../../../src/utils/is-object.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,CACZ,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,iBAAiB,CACtE,CAAC;AACJ,CAAC;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import { logLineFactory } from '../src/index.js';
|
|
3
|
-
test('named export is a function', (t) => {
|
|
4
|
-
t.is(typeof logLineFactory, 'function');
|
|
5
|
-
});
|
|
6
|
-
test('returns the original JSON stringified string if no formatters are provided', (t) => {
|
|
7
|
-
const logLine = logLineFactory();
|
|
8
|
-
const input = JSON.stringify({ foo: 'bar' });
|
|
9
|
-
const result = logLine(input);
|
|
10
|
-
t.is(result, input + '\n');
|
|
11
|
-
});
|
|
12
|
-
test('returns the JSON stringified object if an object is the input', (t) => {
|
|
13
|
-
const logLine = logLineFactory();
|
|
14
|
-
const input = { foo: 'bar' };
|
|
15
|
-
const stringified = JSON.stringify(input);
|
|
16
|
-
t.is(logLine(input), stringified + '\n');
|
|
17
|
-
});
|
|
18
|
-
test('creates a simple log line', (t) => {
|
|
19
|
-
const input = JSON.stringify({ foo: 'bar' });
|
|
20
|
-
const format = {
|
|
21
|
-
foo: (value) => value,
|
|
22
|
-
};
|
|
23
|
-
const logLine = logLineFactory({ format });
|
|
24
|
-
t.is(logLine(input), 'bar\n');
|
|
25
|
-
});
|
|
26
|
-
test('creates a simple log line with default extra fields', (t) => {
|
|
27
|
-
const input = JSON.stringify({ foo: 'bar', extra: 'baz' });
|
|
28
|
-
const format = {
|
|
29
|
-
foo: (value) => value + '\n',
|
|
30
|
-
};
|
|
31
|
-
const logLine = logLineFactory({ format });
|
|
32
|
-
t.is(logLine(input), 'bar\n{"extra":"baz"}\n');
|
|
33
|
-
});
|
|
34
|
-
test('creates a simple log line with formatted extra fields', (t) => {
|
|
35
|
-
const input = JSON.stringify({ foo: 'bar', extra: 'baz' });
|
|
36
|
-
const format = {
|
|
37
|
-
foo: (value) => value + '\n',
|
|
38
|
-
extraFields: (value) => JSON.stringify(value, null, 2),
|
|
39
|
-
};
|
|
40
|
-
const logLine = logLineFactory({ format });
|
|
41
|
-
t.is(logLine(input), 'bar\n' + JSON.stringify({ extra: 'baz' }, null, 2) + '\n');
|
|
42
|
-
});
|
|
43
|
-
test('nested fields can be added to log line and removed from extra fields', (t) => {
|
|
44
|
-
const input = JSON.stringify({ foo: { bar: 'baz' } });
|
|
45
|
-
const format = {
|
|
46
|
-
'foo.bar': (value) => value + '\n',
|
|
47
|
-
};
|
|
48
|
-
const logLine = logLineFactory({ format });
|
|
49
|
-
t.is(logLine(input), 'baz\n{"foo":{}}\n');
|
|
50
|
-
});
|
|
51
|
-
test('nested respect exlude and include', (t) => {
|
|
52
|
-
const input = JSON.stringify({ foo: { bar: 'baz', biz: 'buz', no: 'output' } });
|
|
53
|
-
const format = {
|
|
54
|
-
'foo.bar': (value) => value + '\n',
|
|
55
|
-
};
|
|
56
|
-
const logLine = logLineFactory({
|
|
57
|
-
format,
|
|
58
|
-
exclude: ['foo'],
|
|
59
|
-
include: ['foo.biz'],
|
|
60
|
-
});
|
|
61
|
-
t.is(logLine(input), 'baz\n{"foo":{"biz":"buz"}}\n');
|
|
62
|
-
});
|
|
63
|
-
test('deep nested fields can be added to log line and removed from extra fields', (t) => {
|
|
64
|
-
const input = JSON.stringify({ foo: { bar: { baz: 'buz', qux: 'quux' } } });
|
|
65
|
-
const format = {
|
|
66
|
-
'foo.bar.baz': (value) => value + '\n',
|
|
67
|
-
};
|
|
68
|
-
const logLine = logLineFactory({ format });
|
|
69
|
-
t.is(logLine(input), 'buz\n{"foo":{"bar":{"qux":"quux"}}}\n');
|
|
70
|
-
});
|
|
71
|
-
//# sourceMappingURL=create-log-line.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-log-line.js","sourceRoot":"","sources":["../../test/create-log-line.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,KAAK,CAAC;AACvB,OAAO,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAE/C,IAAI,CAAC,4BAA4B,EAAE,CAAC,CAAC,EAAE,EAAE;IACvC,CAAC,CAAC,EAAE,CAAC,OAAO,cAAc,EAAE,UAAU,CAAC,CAAC;AAC1C,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4EAA4E,EAAE,CAAC,CAAC,EAAE,EAAE;IACvF,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;IACjC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,KAAK,EAAC,CAAC,CAA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