@nx-ddd/notion 5.8.0 → 5.9.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/_testing/entity.js +6 -6
- package/_testing/entity.js.map +1 -1
- package/converter/converter.js +6 -4
- package/converter/converter.js.map +1 -1
- package/decorators/decorators.d.ts +17 -40
- package/decorators/decorators.js +5 -5
- package/decorators/decorators.js.map +1 -1
- package/package.json +3 -3
- package/utils.d.ts +12 -5
- package/utils.js +25 -7
- package/utils.js.map +1 -1
package/_testing/entity.js
CHANGED
|
@@ -10,27 +10,27 @@ class Entity {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
tslib_1.__decorate([
|
|
13
|
-
(0, decorators_1.Title)(
|
|
13
|
+
(0, decorators_1.Title)('タイトル'),
|
|
14
14
|
tslib_1.__metadata("design:type", String)
|
|
15
15
|
], Entity.prototype, "title", void 0);
|
|
16
16
|
tslib_1.__decorate([
|
|
17
|
-
(0, decorators_1.Status)(
|
|
17
|
+
(0, decorators_1.Status)('ステータス'),
|
|
18
18
|
tslib_1.__metadata("design:type", String)
|
|
19
19
|
], Entity.prototype, "status", void 0);
|
|
20
20
|
tslib_1.__decorate([
|
|
21
|
-
(0, decorators_1.Relation)(
|
|
21
|
+
(0, decorators_1.Relation)('一次選考'),
|
|
22
22
|
tslib_1.__metadata("design:type", Array)
|
|
23
23
|
], Entity.prototype, "firstSelectionIds", void 0);
|
|
24
24
|
tslib_1.__decorate([
|
|
25
|
-
(0, decorators_1.Formula)(
|
|
25
|
+
(0, decorators_1.Formula)('一次選考開始文(Discord)'),
|
|
26
26
|
tslib_1.__metadata("design:type", String)
|
|
27
27
|
], Entity.prototype, "discordFirstSelectionMessage", void 0);
|
|
28
28
|
tslib_1.__decorate([
|
|
29
|
-
(0, decorators_1.Formula)(
|
|
29
|
+
(0, decorators_1.Formula)('二次選考開始文(Discord)'),
|
|
30
30
|
tslib_1.__metadata("design:type", String)
|
|
31
31
|
], Entity.prototype, "discordSecondSelectionMessage", void 0);
|
|
32
32
|
tslib_1.__decorate([
|
|
33
|
-
(0, decorators_1.RichText)(
|
|
33
|
+
(0, decorators_1.RichText)('discordChannelId'),
|
|
34
34
|
tslib_1.__metadata("design:type", String)
|
|
35
35
|
], Entity.prototype, "discordChannelId", void 0);
|
|
36
36
|
exports.Entity = Entity;
|
package/_testing/entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/_testing/entity.ts"],"names":[],"mappings":";;;;AAAA,4CAA+C;AAC/C,8CAA2E;AAE3E,MAAa,MAAM;IAmBjB,MAAM,CAAC,IAAI,CAAC,GAAoB;QAC9B,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,EAAE,oBAAM,GAAG,EAAE,CAAC;IAC/C,CAAC;CACF;AArBC;IAAC,IAAA,kBAAK,EAAC,
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/_testing/entity.ts"],"names":[],"mappings":";;;;AAAA,4CAA+C;AAC/C,8CAA2E;AAE3E,MAAa,MAAM;IAmBjB,MAAM,CAAC,IAAI,CAAC,GAAoB;QAC9B,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,EAAE,oBAAM,GAAG,EAAE,CAAC;IAC/C,CAAC;CACF;AArBC;IAAC,IAAA,kBAAK,EAAC,MAAM,CAAC;;qCACA;AAEd;IAAC,IAAA,mBAAM,EAAC,OAAO,CAAC;;sCACD;AAEf;IAAC,IAAA,qBAAQ,EAAC,MAAM,CAAC;;iDACW;AAE5B;IAAC,IAAA,oBAAO,EAAC,kBAAkB,CAAC;;4DACS;AAErC;IAAC,IAAA,oBAAO,EAAC,kBAAkB,CAAC;;6DACU;AAEtC;IAAC,IAAA,qBAAQ,EAAC,kBAAkB,CAAC;;gDACJ;AAjB3B,wBAsBC;AAED,MAAa,eAAgB,SAAQ,2BAAuB;IAA5D;;QACY,WAAM,GAAG,MAAM,CAAC;IAC5B,CAAC;CAAA;AAFD,0CAEC"}
|
package/converter/converter.js
CHANGED
|
@@ -8,15 +8,17 @@ const lodash_1 = require("lodash");
|
|
|
8
8
|
class NotionConverter extends converter_1.Converter {
|
|
9
9
|
fromRecord(page) {
|
|
10
10
|
const annotations = this.Entity[decorators_1.NOTION_ANNOTATIONS];
|
|
11
|
-
const obj = annotations.reduce((obj,
|
|
12
|
-
const value = page['properties'][
|
|
13
|
-
|
|
11
|
+
const obj = annotations.reduce((obj, annotation) => {
|
|
12
|
+
const value = page['properties'][annotation.fieldName]
|
|
13
|
+
? utils_1.NotionUtils.fromNotionValue(page['properties'][annotation.fieldName], annotation)
|
|
14
|
+
: undefined;
|
|
15
|
+
return Object.assign(Object.assign({}, obj), { [annotation.propName]: value });
|
|
14
16
|
}, { id: page.id });
|
|
15
17
|
return this.Entity.from(obj);
|
|
16
18
|
}
|
|
17
19
|
toRecord(entity) {
|
|
18
20
|
const annotations = this.Entity[decorators_1.NOTION_ANNOTATIONS];
|
|
19
|
-
const data = annotations.reduce((obj,
|
|
21
|
+
const data = annotations.reduce((obj, annotation) => (Object.assign(Object.assign({}, obj), { [annotation.fieldName]: utils_1.NotionUtils.toNotionValue(entity[annotation.propName], annotation) })), {});
|
|
20
22
|
return (0, lodash_1.omitBy)(data, (value) => typeof value === 'undefined');
|
|
21
23
|
}
|
|
22
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/converter/converter.ts"],"names":[],"mappings":";;;AACA,uEAAoE;AACpE,oCAAuC;AACvC,8CAAqE;AACrE,mCAAgC;AAEhC,MAAsB,eAAmB,SAAQ,qBAAY;IAG3D,UAAU,CAAC,IAAoD;QAC7D,MAAM,WAAW,GAAuB,IAAI,CAAC,MAAM,CAAC,+BAAkB,CAAC,CAAC;QACx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AAC,CAAC;QACR,OAAO,IAAA,eAAM,EAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,WAAW,CAAC,CAAC;IAC/D,CAAC;CACF;AArBD,0CAqBC;AAED,SAAgB,eAAe,CAAU,MAAW;IAClD,MAAM,SAAU,SAAQ,eAAkB;QAA1C;;YACY,WAAM,GAAG,MAAM,CAAC;QAC5B,CAAC;KAAA;IAED,OAAO,IAAI,SAAS,EAAE,CAAC;AACzB,CAAC;AAND,0CAMC"}
|
|
@@ -1,46 +1,23 @@
|
|
|
1
1
|
export declare const NOTION_ANNOTATIONS = "notion_annotations";
|
|
2
2
|
export type NotionFieldType = 'title' | 'url' | 'rich_text' | 'relation' | 'status' | 'formula' | 'rollup' | 'timestamp' | 'number' | 'created_time' | 'last_edited_time' | 'date' | 'select';
|
|
3
|
-
export interface NotionAnnotation {
|
|
3
|
+
export interface NotionAnnotation<T extends object = undefined> {
|
|
4
4
|
type: NotionFieldType;
|
|
5
5
|
fieldName: string;
|
|
6
6
|
propName: string;
|
|
7
|
+
options?: T;
|
|
7
8
|
}
|
|
8
|
-
export declare const Title: (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export declare const
|
|
12
|
-
|
|
13
|
-
}) => (target: any, propName: string) => void;
|
|
14
|
-
export declare const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export declare const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export declare const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export declare const Formula: (props?: {
|
|
24
|
-
name?: string;
|
|
25
|
-
}) => (target: any, propName: string) => void;
|
|
26
|
-
export declare const Rollup: (props?: {
|
|
27
|
-
name?: string;
|
|
28
|
-
}) => (target: any, propName: string) => void;
|
|
29
|
-
export declare const Timestamp: (props?: {
|
|
30
|
-
name?: string;
|
|
31
|
-
}) => (target: any, propName: string) => void;
|
|
32
|
-
export declare const Number: (props?: {
|
|
33
|
-
name?: string;
|
|
34
|
-
}) => (target: any, propName: string) => void;
|
|
35
|
-
export declare const CreatedTime: (props?: {
|
|
36
|
-
name?: string;
|
|
37
|
-
}) => (target: any, propName: string) => void;
|
|
38
|
-
export declare const LastEditedTime: (props?: {
|
|
39
|
-
name?: string;
|
|
40
|
-
}) => (target: any, propName: string) => void;
|
|
41
|
-
export declare const Date: (props?: {
|
|
42
|
-
name?: string;
|
|
43
|
-
}) => (target: any, propName: string) => void;
|
|
44
|
-
export declare const Select: (props?: {
|
|
45
|
-
name?: string;
|
|
46
|
-
}) => (target: any, propName: string) => void;
|
|
9
|
+
export declare const Title: (name?: string, options?: undefined) => (target: any, propName: string) => void;
|
|
10
|
+
export declare const Url: (name?: string, options?: undefined) => (target: any, propName: string) => void;
|
|
11
|
+
export declare const RichText: (name?: string, options?: undefined) => (target: any, propName: string) => void;
|
|
12
|
+
export declare const Relation: (name?: string, options?: Partial<{
|
|
13
|
+
multi: boolean;
|
|
14
|
+
}>) => (target: any, propName: string) => void;
|
|
15
|
+
export declare const Status: (name?: string, options?: undefined) => (target: any, propName: string) => void;
|
|
16
|
+
export declare const Formula: (name?: string, options?: undefined) => (target: any, propName: string) => void;
|
|
17
|
+
export declare const Rollup: (name?: string, options?: undefined) => (target: any, propName: string) => void;
|
|
18
|
+
export declare const Timestamp: (name?: string, options?: undefined) => (target: any, propName: string) => void;
|
|
19
|
+
export declare const Number: (name?: string, options?: undefined) => (target: any, propName: string) => void;
|
|
20
|
+
export declare const CreatedTime: (name?: string, options?: undefined) => (target: any, propName: string) => void;
|
|
21
|
+
export declare const LastEditedTime: (name?: string, options?: undefined) => (target: any, propName: string) => void;
|
|
22
|
+
export declare const Date: (name?: string, options?: undefined) => (target: any, propName: string) => void;
|
|
23
|
+
export declare const Select: (name?: string, options?: undefined) => (target: any, propName: string) => void;
|
package/decorators/decorators.js
CHANGED
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Select = exports.Date = exports.LastEditedTime = exports.CreatedTime = exports.Number = exports.Timestamp = exports.Rollup = exports.Formula = exports.Status = exports.Relation = exports.RichText = exports.Url = exports.Title = exports.NOTION_ANNOTATIONS = void 0;
|
|
4
4
|
exports.NOTION_ANNOTATIONS = 'notion_annotations';
|
|
5
5
|
;
|
|
6
|
-
function createDecorator(type) {
|
|
7
|
-
return (
|
|
6
|
+
function createDecorator(type, defaultOptions) {
|
|
7
|
+
return (name, options) => {
|
|
8
8
|
return (target, propName) => {
|
|
9
9
|
var _a;
|
|
10
10
|
var _b;
|
|
11
|
-
const fieldName =
|
|
12
|
-
const ANNOTATION = { type, fieldName, propName };
|
|
11
|
+
const fieldName = name || propName;
|
|
12
|
+
const ANNOTATION = { type, fieldName, propName, options: Object.assign(Object.assign({}, defaultOptions), options) };
|
|
13
13
|
(_a = (_b = target.constructor)[exports.NOTION_ANNOTATIONS]) !== null && _a !== void 0 ? _a : (_b[exports.NOTION_ANNOTATIONS] = []);
|
|
14
14
|
target.constructor[exports.NOTION_ANNOTATIONS].push(ANNOTATION);
|
|
15
15
|
};
|
|
@@ -18,7 +18,7 @@ function createDecorator(type) {
|
|
|
18
18
|
exports.Title = createDecorator('title');
|
|
19
19
|
exports.Url = createDecorator('url');
|
|
20
20
|
exports.RichText = createDecorator('rich_text');
|
|
21
|
-
exports.Relation = createDecorator('relation');
|
|
21
|
+
exports.Relation = createDecorator('relation', { multi: false });
|
|
22
22
|
exports.Status = createDecorator('status');
|
|
23
23
|
exports.Formula = createDecorator('formula');
|
|
24
24
|
exports.Rollup = createDecorator('rollup');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/decorators/decorators.ts"],"names":[],"mappings":";;;AAAa,QAAA,kBAAkB,GAAG,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/decorators/decorators.ts"],"names":[],"mappings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rD,QAAA,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;AAC/B,QAAA,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx-ddd/notion",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.9.0",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"reflect-metadata": "^0.1.13"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"@nx-ddd/common": "5.
|
|
15
|
-
"@nx-ddd/core": "5.
|
|
14
|
+
"@nx-ddd/common": "5.9.0",
|
|
15
|
+
"@nx-ddd/core": "5.9.0",
|
|
16
16
|
"tslib": "^2.3.0"
|
|
17
17
|
}
|
|
18
18
|
}
|
package/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
|
-
import {
|
|
2
|
+
import { NotionAnnotation } from "./decorators";
|
|
3
3
|
type NotionText = {
|
|
4
4
|
type: 'text';
|
|
5
5
|
text: {
|
|
@@ -94,7 +94,7 @@ export type NotionSelect = {
|
|
|
94
94
|
};
|
|
95
95
|
export type NotionValue = NotionTitle | NotionUrl | NotionRichText | NotionNumber | NotionRelation | NotionStatus | NotionFormula | NotionRollup | NotionCreatedTime | NotionLastEditedTime | NotionDate | NotionSelect;
|
|
96
96
|
export declare class NotionUtils {
|
|
97
|
-
static toNotionValue(value: any,
|
|
97
|
+
static toNotionValue(value: any, annotation: NotionAnnotation): void | {
|
|
98
98
|
type: string;
|
|
99
99
|
title: {
|
|
100
100
|
text: {
|
|
@@ -146,7 +146,13 @@ export declare class NotionUtils {
|
|
|
146
146
|
name: string;
|
|
147
147
|
};
|
|
148
148
|
};
|
|
149
|
-
static
|
|
149
|
+
static toRelationMulti(ids: string[]): {
|
|
150
|
+
type: string;
|
|
151
|
+
relation: {
|
|
152
|
+
id: string;
|
|
153
|
+
}[];
|
|
154
|
+
};
|
|
155
|
+
static toRelation(value: string): {
|
|
150
156
|
type: string;
|
|
151
157
|
relation: {
|
|
152
158
|
id: string;
|
|
@@ -178,11 +184,12 @@ export declare class NotionUtils {
|
|
|
178
184
|
name: string;
|
|
179
185
|
};
|
|
180
186
|
};
|
|
181
|
-
static fromNotionValue(value: NotionValue): string | number | string[] | dayjs.Dayjs | number[];
|
|
187
|
+
static fromNotionValue(value: NotionValue, annotation: NotionAnnotation): string | number | string[] | dayjs.Dayjs | number[];
|
|
182
188
|
static fromTitle(notionTitle: NotionTitle): string;
|
|
183
189
|
static fromUrl(notionUrl: NotionUrl): string | null;
|
|
184
190
|
static fromRichText(notionRichText: NotionRichText): string | null;
|
|
185
|
-
static fromRelation(notionRelation: NotionRelation): string
|
|
191
|
+
static fromRelation(notionRelation: NotionRelation): string | null;
|
|
192
|
+
static fromRelationMulti(notionRelation: NotionRelation): string[];
|
|
186
193
|
static fromStatus(notionStatus: NotionStatus): string;
|
|
187
194
|
static fromFormula(notionFormula: NotionFormula): string | number;
|
|
188
195
|
static fromRollup(notionRollup: NotionRollup): string[] | number[];
|
package/utils.js
CHANGED
|
@@ -4,11 +4,17 @@ exports.NotionUtils = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
6
6
|
class NotionUtils {
|
|
7
|
-
static toNotionValue(value,
|
|
8
|
-
switch (type) {
|
|
7
|
+
static toNotionValue(value, annotation) {
|
|
8
|
+
switch (annotation.type) {
|
|
9
9
|
case 'title': return NotionUtils.toNotionTitle(value);
|
|
10
10
|
case 'status': return NotionUtils.toNotionStatus(value);
|
|
11
|
-
case 'relation':
|
|
11
|
+
case 'relation':
|
|
12
|
+
if (annotation.options.multi) {
|
|
13
|
+
return NotionUtils.toRelationMulti(value);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return NotionUtils.toRelation(value);
|
|
17
|
+
}
|
|
12
18
|
case 'formula': return NotionUtils.toNotionFormula(value);
|
|
13
19
|
case 'rich_text': return NotionUtils.toRichText(value);
|
|
14
20
|
case 'rollup': return NotionUtils.toRollup(value);
|
|
@@ -24,10 +30,12 @@ class NotionUtils {
|
|
|
24
30
|
static toNotionStatus(value) {
|
|
25
31
|
return value ? { type: 'status', status: { name: value } } : undefined;
|
|
26
32
|
}
|
|
27
|
-
static
|
|
28
|
-
console.log('ids', ids);
|
|
33
|
+
static toRelationMulti(ids) {
|
|
29
34
|
return Array.isArray(ids) ? { type: 'relation', relation: (ids).map(id => ({ id })) } : undefined;
|
|
30
35
|
}
|
|
36
|
+
static toRelation(value) {
|
|
37
|
+
return value ? this.toRelationMulti([value]) : undefined;
|
|
38
|
+
}
|
|
31
39
|
static toRichText(text) {
|
|
32
40
|
return text ? { type: 'rich_text', rich_text: [{ text: { content: text } }] } : undefined;
|
|
33
41
|
}
|
|
@@ -47,11 +55,17 @@ class NotionUtils {
|
|
|
47
55
|
static toSelect(value) {
|
|
48
56
|
return value ? { type: 'select', select: { name: value } } : undefined;
|
|
49
57
|
}
|
|
50
|
-
static fromNotionValue(value) {
|
|
58
|
+
static fromNotionValue(value, annotation) {
|
|
51
59
|
switch (value.type) {
|
|
52
60
|
case 'title': return this.fromTitle(value);
|
|
53
61
|
case 'formula': return this.fromFormula(value);
|
|
54
|
-
case 'relation':
|
|
62
|
+
case 'relation':
|
|
63
|
+
if (annotation.options.multi) {
|
|
64
|
+
return this.fromRelationMulti(value);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return this.fromRelation(value);
|
|
68
|
+
}
|
|
55
69
|
case 'rich_text': return this.fromRichText(value);
|
|
56
70
|
case 'status': return this.fromStatus(value);
|
|
57
71
|
case 'url': return this.fromUrl(value);
|
|
@@ -74,6 +88,10 @@ class NotionUtils {
|
|
|
74
88
|
return notionRichText.rich_text.map(({ plain_text }) => plain_text).join('') || null;
|
|
75
89
|
}
|
|
76
90
|
static fromRelation(notionRelation) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
return (_b = (_a = this.fromRelationMulti(notionRelation)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : null;
|
|
93
|
+
}
|
|
94
|
+
static fromRelationMulti(notionRelation) {
|
|
77
95
|
return notionRelation.relation.map(r => r.id);
|
|
78
96
|
}
|
|
79
97
|
static fromStatus(notionStatus) {
|
package/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../packages/@nx-ddd/notion/src/lib/utils.ts"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAqC1B,MAAa,WAAW;IACtB,MAAM,CAAC,aAAa,CAAC,KAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../packages/@nx-ddd/notion/src/lib/utils.ts"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAqC1B,MAAa,WAAW;IACtB,MAAM,CAAC,aAAa,CAAC,KAAU,EAAE,UAA4B;QAC3D,QAAO,UAAU,CAAC,IAAI,EAAE;YACtB,KAAK,OAAO,CAAC,CAAC,OAAO,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YACtD,KAAK,QAAQ,CAAC,CAAC,OAAO,WAAW,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YACxD,KAAK,UAAU;gBACb,IAAK,UAAU,CAAC,OAAe,CAAC,KAAK,EAAE;oBACrC,OAAO,WAAW,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;iBAC3C;qBAAM;oBACL,OAAO,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;iBACtC;YACH,KAAK,SAAS,CAAC,CAAC,OAAO,WAAW,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;YAC1D,KAAK,WAAW,C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