@nx-ddd/notion 19.0.0-preview.28 → 19.0.0-preview.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 +11 -0
- package/_testing/entity.d.ts +20 -0
- package/_testing/entity.js +44 -0
- package/_testing/entity.js.map +1 -0
- package/_testing/index.d.ts +1 -0
- package/_testing/index.js +5 -0
- package/_testing/index.js.map +1 -0
- package/converter/converter.js +37 -0
- package/converter/converter.js.map +1 -0
- package/converter/index.js +5 -0
- package/converter/index.js.map +1 -0
- package/decorators/decorators.js +58 -0
- package/decorators/decorators.js.map +1 -0
- package/decorators/index.js +5 -0
- package/decorators/index.js.map +1 -0
- package/index.d.ts +0 -1
- package/index.js +10 -0
- package/index.js.map +1 -0
- package/notion/index.js +5 -0
- package/notion/index.js.map +1 -0
- package/notion/notion.service.impl.d.ts +0 -5
- package/notion/notion.service.impl.js +142 -0
- package/notion/notion.service.impl.js.map +1 -0
- package/notion/notion.service.js +12 -0
- package/notion/notion.service.js.map +1 -0
- package/package.json +12 -18
- package/query/index.js +5 -0
- package/query/index.js.map +1 -0
- package/query/query.js +122 -0
- package/query/query.js.map +1 -0
- package/query-builder/index.js +5 -0
- package/query-builder/index.js.map +1 -0
- package/query-builder/query-builder.js +30 -0
- package/query-builder/query-builder.js.map +1 -0
- package/repository/index.js +5 -0
- package/repository/index.js.map +1 -0
- package/repository/repository.d.ts +5 -17
- package/repository/repository.js +112 -0
- package/repository/repository.js.map +1 -0
- package/utils.js +184 -0
- package/utils.js.map +1 -0
- package/fesm2022/nx-ddd-notion.mjs +0 -525
- package/fesm2022/nx-ddd-notion.mjs.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# notion
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Running unit tests
|
|
6
|
+
|
|
7
|
+
Run `nx test notion` to execute the unit tests via [Jest](https://jestjs.io).
|
|
8
|
+
|
|
9
|
+
## Running lint
|
|
10
|
+
|
|
11
|
+
Run `nx lint notion` to execute the lint via [ESLint](https://eslint.org/).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NotionConverter } from '../converter';
|
|
2
|
+
export declare class Entity {
|
|
3
|
+
title: string;
|
|
4
|
+
status: string;
|
|
5
|
+
firstSelectionIds: string[];
|
|
6
|
+
discordFirstSelectionMessage: string;
|
|
7
|
+
discordSecondSelectionMessage: string;
|
|
8
|
+
discordChannelId: string;
|
|
9
|
+
static from(obj: Partial<Entity>): Entity & {
|
|
10
|
+
title?: string;
|
|
11
|
+
status?: string;
|
|
12
|
+
firstSelectionIds?: string[];
|
|
13
|
+
discordFirstSelectionMessage?: string;
|
|
14
|
+
discordSecondSelectionMessage?: string;
|
|
15
|
+
discordChannelId?: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare class EntityConverter extends NotionConverter<Entity> {
|
|
19
|
+
protected Entity: typeof Entity;
|
|
20
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityConverter = exports.Entity = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const converter_1 = require("../converter");
|
|
6
|
+
const decorators_1 = require("../decorators");
|
|
7
|
+
class Entity {
|
|
8
|
+
static from(obj) {
|
|
9
|
+
return Object.assign(new Entity(), Object.assign({}, obj));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.Entity = Entity;
|
|
13
|
+
tslib_1.__decorate([
|
|
14
|
+
(0, decorators_1.Title)('タイトル'),
|
|
15
|
+
tslib_1.__metadata("design:type", String)
|
|
16
|
+
], Entity.prototype, "title", void 0);
|
|
17
|
+
tslib_1.__decorate([
|
|
18
|
+
(0, decorators_1.Status)('ステータス'),
|
|
19
|
+
tslib_1.__metadata("design:type", String)
|
|
20
|
+
], Entity.prototype, "status", void 0);
|
|
21
|
+
tslib_1.__decorate([
|
|
22
|
+
(0, decorators_1.Relation)('一次選考'),
|
|
23
|
+
tslib_1.__metadata("design:type", Array)
|
|
24
|
+
], Entity.prototype, "firstSelectionIds", void 0);
|
|
25
|
+
tslib_1.__decorate([
|
|
26
|
+
(0, decorators_1.Formula)('一次選考開始文(Discord)'),
|
|
27
|
+
tslib_1.__metadata("design:type", String)
|
|
28
|
+
], Entity.prototype, "discordFirstSelectionMessage", void 0);
|
|
29
|
+
tslib_1.__decorate([
|
|
30
|
+
(0, decorators_1.Formula)('二次選考開始文(Discord)'),
|
|
31
|
+
tslib_1.__metadata("design:type", String)
|
|
32
|
+
], Entity.prototype, "discordSecondSelectionMessage", void 0);
|
|
33
|
+
tslib_1.__decorate([
|
|
34
|
+
(0, decorators_1.RichText)('discordChannelId'),
|
|
35
|
+
tslib_1.__metadata("design:type", String)
|
|
36
|
+
], Entity.prototype, "discordChannelId", void 0);
|
|
37
|
+
class EntityConverter extends converter_1.NotionConverter {
|
|
38
|
+
constructor() {
|
|
39
|
+
super(...arguments);
|
|
40
|
+
this.Entity = Entity;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.EntityConverter = EntityConverter;
|
|
44
|
+
//# sourceMappingURL=entity.js.map
|
|
@@ -0,0 +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;AAtBD,wBAsBC;AApBC;IADC,IAAA,kBAAK,EAAC,MAAM,CAAC;;qCACA;AAGd;IADC,IAAA,mBAAM,EAAC,OAAO,CAAC;;sCACD;AAGf;IADC,IAAA,qBAAQ,EAAC,MAAM,CAAC;;iDACW;AAG5B;IADC,IAAA,oBAAO,EAAC,kBAAkB,CAAC;;4DACS;AAGrC;IADC,IAAA,oBAAO,EAAC,kBAAkB,CAAC;;6DACU;AAGtC;IADC,IAAA,qBAAQ,EAAC,kBAAkB,CAAC;;gDACJ;AAO3B,MAAa,eAAgB,SAAQ,2BAAuB;IAA5D;;QACY,WAAM,GAAG,MAAM,CAAC;IAC5B,CAAC;CAAA;AAFD,0CAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './entity';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/_testing/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotionConverter = void 0;
|
|
4
|
+
exports.createConverter = createConverter;
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const decorators_1 = require("../decorators");
|
|
7
|
+
const lodash_es_1 = require("lodash-es");
|
|
8
|
+
class NotionConverter {
|
|
9
|
+
fromNotion(page) {
|
|
10
|
+
var _a;
|
|
11
|
+
const annotations = (_a = this.Entity[decorators_1.NOTION_ANNOTATIONS]) !== null && _a !== void 0 ? _a : [];
|
|
12
|
+
const obj = annotations.reduce((obj, annotation) => {
|
|
13
|
+
const value = page['properties'][annotation.fieldName]
|
|
14
|
+
? utils_1.NotionUtils.fromNotionValue(page['properties'][annotation.fieldName], annotation)
|
|
15
|
+
: undefined;
|
|
16
|
+
return Object.assign(Object.assign({}, obj), { [annotation.propName]: value });
|
|
17
|
+
}, { id: page.id });
|
|
18
|
+
return this.Entity.from(obj);
|
|
19
|
+
}
|
|
20
|
+
toNotion(entity) {
|
|
21
|
+
var _a;
|
|
22
|
+
const annotations = (_a = this.Entity[decorators_1.NOTION_ANNOTATIONS]) !== null && _a !== void 0 ? _a : [];
|
|
23
|
+
const data = annotations.reduce((obj, annotation) => (Object.assign(Object.assign({}, obj), { [annotation.fieldName]: utils_1.NotionUtils.toNotionValue(entity[annotation.propName], annotation) })), {});
|
|
24
|
+
return (0, lodash_es_1.omitBy)(data, (value) => typeof value === 'undefined');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.NotionConverter = NotionConverter;
|
|
28
|
+
function createConverter(Entity) {
|
|
29
|
+
class Converter extends NotionConverter {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.Entity = Entity;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return new Converter();
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/converter/converter.ts"],"names":[],"mappings":";;;AA4BA,0CAMC;AAjCD,oCAAuC;AACvC,8CAAqE;AACrE,yCAAmC;AAEnC,MAAsB,eAAe;IAGnC,UAAU,CAAC,IAA6G;;QACtH,MAAM,WAAW,GAAuB,MAAA,IAAI,CAAC,MAAM,CAAC,+BAAkB,CAAC,mCAAI,EAAE,CAAC;QAC9E,MAAM,GAAG,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE;YACjD,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC;gBACpD,CAAC,CAAC,mBAAW,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC;gBACnF,CAAC,CAAC,SAAS,CAAC;YACd,uCAAW,GAAG,KAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,IAAE;QAChD,CAAC,EAAE,EAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAC,CAAC,CAAC;QAClB,OAAQ,IAAI,CAAC,MAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxC,CAAC;IAED,QAAQ,CAAC,MAAkB;;QACzB,MAAM,WAAW,GAAuB,MAAA,IAAI,CAAC,MAAM,CAAC,+BAAkB,CAAC,mCAAI,EAAE,CAAC;QAC9E,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE,CAAC,iCAChD,GAAG,KAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,mBAAW,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,IAClG,EAAE,EAAE,CAAC,CAAC;QACR,OAAO,IAAA,kBAAM,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/converter/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Notion = exports.UniqueID = exports.Email = exports.PhoneNumber = 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
|
+
exports.NOTION_ANNOTATIONS = 'notion_annotations';
|
|
5
|
+
function createDecorator(type, defaultOptions) {
|
|
6
|
+
return (name, options) => {
|
|
7
|
+
return (target, propName) => {
|
|
8
|
+
var _a;
|
|
9
|
+
var _b;
|
|
10
|
+
const fieldName = name || propName;
|
|
11
|
+
const ANNOTATION = { type, fieldName, propName, options: Object.assign(Object.assign({}, defaultOptions), options) };
|
|
12
|
+
(_a = (_b = target.constructor)[exports.NOTION_ANNOTATIONS]) !== null && _a !== void 0 ? _a : (_b[exports.NOTION_ANNOTATIONS] = []);
|
|
13
|
+
target.constructor[exports.NOTION_ANNOTATIONS].push(ANNOTATION);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.Title = createDecorator('title');
|
|
18
|
+
exports.Url = createDecorator('url');
|
|
19
|
+
exports.RichText = createDecorator('rich_text');
|
|
20
|
+
exports.Relation = createDecorator('relation', { multi: false });
|
|
21
|
+
exports.Status = createDecorator('status');
|
|
22
|
+
exports.Formula = createDecorator('formula');
|
|
23
|
+
exports.Rollup = createDecorator('rollup', { multi: false });
|
|
24
|
+
exports.Timestamp = createDecorator('timestamp');
|
|
25
|
+
exports.Number = createDecorator('number');
|
|
26
|
+
exports.CreatedTime = createDecorator('created_time');
|
|
27
|
+
exports.LastEditedTime = createDecorator('last_edited_time');
|
|
28
|
+
exports.Date = createDecorator('date');
|
|
29
|
+
exports.Select = createDecorator('select');
|
|
30
|
+
exports.PhoneNumber = createDecorator('phone_number');
|
|
31
|
+
exports.Email = createDecorator('email');
|
|
32
|
+
exports.UniqueID = createDecorator('unique_id');
|
|
33
|
+
// Not implemented below props!
|
|
34
|
+
// export const Checkbox = createDecorator('checkbox');
|
|
35
|
+
// export const CreatedBy = createDecorator('created_by');
|
|
36
|
+
// export const Files = createDecorator('files');
|
|
37
|
+
// export const LastEditedBy = createDecorator('last_edited_by');
|
|
38
|
+
// export const MultiSelect = createDecorator('multi_select');
|
|
39
|
+
// export const People = createDecorator('people');
|
|
40
|
+
exports.Notion = {
|
|
41
|
+
Title: exports.Title,
|
|
42
|
+
Url: exports.Url,
|
|
43
|
+
RichText: exports.RichText,
|
|
44
|
+
Relation: exports.Relation,
|
|
45
|
+
Status: exports.Status,
|
|
46
|
+
Formula: exports.Formula,
|
|
47
|
+
Rollup: exports.Rollup,
|
|
48
|
+
Timestamp: exports.Timestamp,
|
|
49
|
+
Number: exports.Number,
|
|
50
|
+
CreatedTime: exports.CreatedTime,
|
|
51
|
+
LastEditedTime: exports.LastEditedTime,
|
|
52
|
+
Date: exports.Date,
|
|
53
|
+
Select: exports.Select,
|
|
54
|
+
PhoneNumber: exports.PhoneNumber,
|
|
55
|
+
Email: exports.Email,
|
|
56
|
+
UniqueID: exports.UniqueID,
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +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;AAavD,SAAS,eAAe,CAA+B,IAAqB,EAAE,cAAkB;IAC9F,OAAO,CAAC,IAAa,EAAE,OAAoB,EAAE,EAAE;QAC7C,OAAO,CAAC,MAAW,EAAE,QAAgB,EAAE,EAAE;;;YACvC,MAAM,SAAS,GAAG,IAAI,IAAI,QAAQ,CAAC;YACnC,MAAM,UAAU,GAAwB,EAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,kCAAM,cAAc,GAAK,OAAO,CAAC,EAAC,CAAC;YAC9G,YAAA,MAAM,CAAC,WAAW,EAAC,0BAAkB,wCAAlB,0BAAkB,IAAM,EAAE,EAAC;YAC9C,MAAM,CAAC,WAAW,CAAC,0BAAkB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1D,CAAC,CAAC;IACJ,CAAC,CAAC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,EAAP,eAAO;IACP,MAAM,EAAN,cAAM;IACN,SAAS,EAAT,iBAAS;IACT,MAAM,EAAN,cAAM;IACN,WAAW,EAAX,mBAAW;IACX,cAAc,EAAd,sBAAc;IACd,IAAI,EAAJ,YAAI;IACJ,MAAM,EAAN,cAAM;IACN,WAAW,EAAX,mBAAW;IACX,KAAK,EAAL,aAAK;IACL,QAAQ,EAAR,gBAAQ;CACT,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/decorators/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B"}
|
package/index.d.ts
CHANGED
package/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./converter"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./decorators"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./query"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./query-builder"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./repository"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./utils"), exports);
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/@nx-ddd/notion/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,uDAA6B;AAC7B,kDAAwB;AACxB,0DAAgC;AAChC,uDAA6B;AAC7B,kDAAwB"}
|
package/notion/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/notion/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { InjectionToken, Provider } from '@angular/core';
|
|
2
2
|
import { LocalStorage } from "node-localstorage";
|
|
3
|
-
import * as i0 from "@angular/core";
|
|
4
3
|
export interface NotionConfig {
|
|
5
4
|
token: string;
|
|
6
5
|
}
|
|
@@ -15,8 +14,6 @@ export declare class CacheAdapter {
|
|
|
15
14
|
protected makeKey(keyOrObj: string | object): string;
|
|
16
15
|
protected makeJson(valueOrObj: any): string;
|
|
17
16
|
protected parseJson(value: string): any;
|
|
18
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<CacheAdapter, never>;
|
|
19
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<CacheAdapter>;
|
|
20
17
|
}
|
|
21
18
|
export declare class NotionService {
|
|
22
19
|
private config;
|
|
@@ -30,6 +27,4 @@ export declare class NotionService {
|
|
|
30
27
|
retrieveBlock(blockId: string): Promise<import("@notionhq/client/build/src/api-endpoints").GetBlockResponse>;
|
|
31
28
|
search(params: Parameters<typeof this.notionClient.search>[0]): Promise<import("@notionhq/client/build/src/api-endpoints").SearchResponse>;
|
|
32
29
|
queryDatabase(databaseId: string, filter?: any): Promise<(import("@notionhq/client/build/src/api-endpoints").PageObjectResponse | import("@notionhq/client/build/src/api-endpoints").PartialPageObjectResponse | import("@notionhq/client/build/src/api-endpoints").PartialDatabaseObjectResponse | import("@notionhq/client/build/src/api-endpoints").DatabaseObjectResponse)[]>;
|
|
33
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<NotionService, never>;
|
|
34
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<NotionService>;
|
|
35
30
|
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotionService = exports.CacheAdapter = exports.NOTION_CONFIG = void 0;
|
|
4
|
+
exports.provideNotionService = provideNotionService;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const core_1 = require("@angular/core");
|
|
7
|
+
const client_1 = require("@notionhq/client");
|
|
8
|
+
const notion_service_1 = require("./notion.service");
|
|
9
|
+
const node_localstorage_1 = require("node-localstorage");
|
|
10
|
+
const CryptoJS = tslib_1.__importStar(require("crypto-js"));
|
|
11
|
+
exports.NOTION_CONFIG = new core_1.InjectionToken('NOTION_CONFIG');
|
|
12
|
+
function provideNotionService(useFactory) {
|
|
13
|
+
return [
|
|
14
|
+
{ provide: exports.NOTION_CONFIG, useFactory },
|
|
15
|
+
{ provide: notion_service_1.NOTION_SERVICE, useClass: NotionService },
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
let CacheAdapter = class CacheAdapter {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.localStorage = global.localStorage || new node_localstorage_1.LocalStorage('node_modules/.cache/@nx-ddd/notion', 5 * 1024 * 1024 * 1024);
|
|
21
|
+
}
|
|
22
|
+
get(keyOrObj) {
|
|
23
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const key = this.makeKey(keyOrObj);
|
|
25
|
+
return this.parseJson(this.localStorage.getItem(key));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
set(keyOrObj, value) {
|
|
29
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const key = this.makeKey(keyOrObj);
|
|
31
|
+
this.localStorage.setItem(key, this.makeJson(value));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
remove(keyOrObj) {
|
|
35
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const key = this.makeKey(keyOrObj);
|
|
37
|
+
this.localStorage.removeItem(key);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
call(props, callback) {
|
|
41
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const key = this.makeKey(props);
|
|
43
|
+
let value = yield this.get(key);
|
|
44
|
+
if (value)
|
|
45
|
+
return value;
|
|
46
|
+
value = yield callback(props);
|
|
47
|
+
yield this.set(key, value);
|
|
48
|
+
return value;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
makeKey(keyOrObj) {
|
|
52
|
+
const value = typeof keyOrObj === 'string' ? keyOrObj : JSON.stringify(keyOrObj);
|
|
53
|
+
return CryptoJS.SHA256(value).toString();
|
|
54
|
+
}
|
|
55
|
+
makeJson(valueOrObj) {
|
|
56
|
+
return JSON.stringify(valueOrObj);
|
|
57
|
+
}
|
|
58
|
+
parseJson(value) {
|
|
59
|
+
return JSON.parse(value);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exports.CacheAdapter = CacheAdapter;
|
|
63
|
+
exports.CacheAdapter = CacheAdapter = tslib_1.__decorate([
|
|
64
|
+
(0, core_1.Injectable)({ providedIn: 'root' })
|
|
65
|
+
], CacheAdapter);
|
|
66
|
+
let NotionService = class NotionService {
|
|
67
|
+
constructor() {
|
|
68
|
+
this.config = (0, core_1.inject)(exports.NOTION_CONFIG);
|
|
69
|
+
this.notionClient = new client_1.Client({ auth: this.config.token });
|
|
70
|
+
this.cache = (0, core_1.inject)(CacheAdapter);
|
|
71
|
+
}
|
|
72
|
+
retrievePage(pageId) {
|
|
73
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
return this.cache.call(pageId, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
return this.notionClient.pages.retrieve({ page_id: pageId });
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
updatePage(pageId, properties) {
|
|
80
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const response = yield this.notionClient.pages.update({
|
|
82
|
+
page_id: pageId,
|
|
83
|
+
properties,
|
|
84
|
+
});
|
|
85
|
+
return response;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
deletePage(pageId) {
|
|
89
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
yield this.notionClient.pages.update({
|
|
91
|
+
page_id: pageId,
|
|
92
|
+
archived: true,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
retrieveDatabase(databaseId) {
|
|
97
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
// return this.cache.call(databaseId, async () => {
|
|
99
|
+
return this.notionClient.databases.retrieve({ database_id: databaseId });
|
|
100
|
+
// });
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
updateDatabase(databaseId, properties) {
|
|
104
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
console.debug('properties:', properties);
|
|
106
|
+
const response = yield this.notionClient.databases.update({
|
|
107
|
+
database_id: databaseId,
|
|
108
|
+
properties,
|
|
109
|
+
});
|
|
110
|
+
yield this.cache.remove(databaseId);
|
|
111
|
+
return response;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
retrieveBlock(blockId) {
|
|
115
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
return this.cache.call(blockId, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
return this.notionClient.blocks.retrieve({ block_id: blockId });
|
|
118
|
+
}));
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
search(params) {
|
|
122
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
return this.cache.call(params, () => {
|
|
124
|
+
return this.notionClient.search(params);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
queryDatabase(databaseId, filter) {
|
|
129
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
const response = yield this.notionClient.databases.query({
|
|
131
|
+
database_id: databaseId,
|
|
132
|
+
filter,
|
|
133
|
+
});
|
|
134
|
+
return response.results;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
exports.NotionService = NotionService;
|
|
139
|
+
exports.NotionService = NotionService = tslib_1.__decorate([
|
|
140
|
+
(0, core_1.Injectable)({ providedIn: 'root' })
|
|
141
|
+
], NotionService);
|
|
142
|
+
//# sourceMappingURL=notion.service.impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notion.service.impl.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/notion/notion.service.impl.ts"],"names":[],"mappings":";;;AAYA,oDAKC;;AAjBD,wCAA6E;AAC7E,6CAA0C;AAC1C,qDAAkD;AAClD,yDAAiD;AACjD,4DAAsC;AAMzB,QAAA,aAAa,GAAG,IAAI,qBAAc,CAAe,eAAe,CAAC,CAAC;AAE/E,SAAgB,oBAAoB,CAAC,UAA8B;IACjE,OAAO;QACL,EAAE,OAAO,EAAE,qBAAa,EAAE,UAAU,EAAE;QACtC,EAAE,OAAO,EAAE,+BAAc,EAAE,QAAQ,EAAE,aAAa,EAAE;KACrD,CAAC;AACJ,CAAC;AAEM,IAAM,YAAY,GAAlB,MAAM,YAAY;IAAlB;QACK,iBAAY,GAAiB,MAAM,CAAC,YAAY,IAAI,IAAI,gCAAY,CAAC,oCAAoC,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IAsC/I,CAAC;IApCO,GAAG,CAAI,QAAyB;;YACpC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACnC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAa,CAAC;QACpE,CAAC;KAAA;IAEK,GAAG,CAAC,QAAyB,EAAE,KAAU;;YAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACnC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QACvD,CAAC;K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,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YACpC,OAAO,QAAQ,CAAC;QAClB,CAAC;KAAA;IAEK,aAAa,CAAC,OAAe;;YACjC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAS,EAAE;gBACzC,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;YAClE,CAAC,CAAA,CAAC,CAAC;QACL,CAAC;KAAA;IAEK,MAAM,CAAC,MAAsD;;YACjE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE;gBAClC,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;IAEK,aAAa,CAAC,UAAkB,EAAE,MAAY;;YAClD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC;gBACvD,WAAW,EAAE,UAAU;gBACvB,MAAM;aACP,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC,OAAO,CAAC;QAC1B,CAAC;KAAA;CACF,CAAA;AA7DY,sCAAa;wBAAb,aAAa;IADzB,IAAA,iBAAU,EAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;GACtB,aAAa,CA6DzB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NOTION_CONFIG = exports.NOTION_SERVICE = void 0;
|
|
4
|
+
exports.injectNotion = injectNotion;
|
|
5
|
+
const core_1 = require("@angular/core");
|
|
6
|
+
exports.NOTION_SERVICE = new core_1.InjectionToken('NOTION_SERVICE');
|
|
7
|
+
exports.NOTION_CONFIG = new core_1.InjectionToken('NOTION_CONFIG');
|
|
8
|
+
function injectNotion() {
|
|
9
|
+
var _a;
|
|
10
|
+
return (_a = (0, core_1.inject)(exports.NOTION_SERVICE, { optional: true })) !== null && _a !== void 0 ? _a : null;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=notion.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notion.service.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/notion/notion.service.ts"],"names":[],"mappings":";;;AAUA,oCAEC;AAZD,wCAAuD;AAO1C,QAAA,cAAc,GAAG,IAAI,qBAAc,CAAgB,gBAAgB,CAAC,CAAC;AACrE,QAAA,aAAa,GAAG,IAAI,qBAAc,CAAe,eAAe,CAAC,CAAC;AAE/E,SAAgB,YAAY;;IAC1B,OAAO,MAAA,IAAA,aAAM,EAAC,sBAAc,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,mCAAI,IAAI,CAAC;AAC5D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,29 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx-ddd/notion",
|
|
3
|
-
"version": "19.0.0-preview.
|
|
4
|
-
"
|
|
3
|
+
"version": "19.0.0-preview.3",
|
|
4
|
+
"main": "./index.js",
|
|
5
|
+
"types": "./index.d.ts",
|
|
6
|
+
"homepage": "https://github.com/xx-machina/plaform/tree/main/packages/@nx-ddd/notion",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/xx-machina/plaform.git"
|
|
10
|
+
},
|
|
5
11
|
"peerDependencies": {
|
|
6
12
|
"@notionhq/client": "^2.2.2",
|
|
7
|
-
"@nx-ddd/common": "19.0.0-preview.
|
|
13
|
+
"@nx-ddd/common": "19.0.0-preview.3",
|
|
8
14
|
"dayjs": "1.11.13",
|
|
9
15
|
"lodash-es": "^4.17.15",
|
|
16
|
+
"tslib": "^2.3.0",
|
|
10
17
|
"@angular/core": "19.1.4",
|
|
11
18
|
"node-localstorage": "^3.0.5",
|
|
12
19
|
"crypto-js": "4.2.0"
|
|
13
20
|
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
"module": "fesm2022/nx-ddd-notion.mjs",
|
|
18
|
-
"typings": "index.d.ts",
|
|
19
|
-
"exports": {
|
|
20
|
-
"./package.json": {
|
|
21
|
-
"default": "./package.json"
|
|
22
|
-
},
|
|
23
|
-
".": {
|
|
24
|
-
"types": "./index.d.ts",
|
|
25
|
-
"default": "./fesm2022/nx-ddd-notion.mjs"
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
"sideEffects": false
|
|
21
|
+
"dependencies": {},
|
|
22
|
+
"type": "commonjs"
|
|
29
23
|
}
|
package/query/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/query/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB"}
|
package/query/query.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Query = exports.NotionOr = exports.NotionAnd = exports.NotionSort = exports.NotionFilter = exports.NotionBaseQuery = exports.N = void 0;
|
|
4
|
+
const decorators_1 = require("../decorators");
|
|
5
|
+
class N {
|
|
6
|
+
static RollupPropQuery(property, evaluation, value) {
|
|
7
|
+
return { property, rollup: { every: { rich_text: { equals: value } } } };
|
|
8
|
+
}
|
|
9
|
+
static FormulaQuery(property, evaluation, value) {
|
|
10
|
+
return { property, formula: {} };
|
|
11
|
+
}
|
|
12
|
+
static LastEditedTime(property, evaluation, value) {
|
|
13
|
+
const query = evaluation === '>' ? 'after'
|
|
14
|
+
: evaluation === '<' ? 'before'
|
|
15
|
+
: evaluation === '==' ? 'equals'
|
|
16
|
+
: evaluation === '<=' ? 'on_or_before'
|
|
17
|
+
: evaluation === '>=' ? 'on_or_after'
|
|
18
|
+
: evaluation === '!=' ? '' : '';
|
|
19
|
+
return { timestamp: 'last_edited_time', last_edited_time: { [query]: value } };
|
|
20
|
+
}
|
|
21
|
+
static Timestamp(property, evaluation, value) {
|
|
22
|
+
const query = evaluation === '>' ? 'after'
|
|
23
|
+
: evaluation === '<' ? 'before'
|
|
24
|
+
: evaluation === '==' ? 'equals'
|
|
25
|
+
: evaluation === '<=' ? 'on_or_before'
|
|
26
|
+
: evaluation === '>=' ? 'on_or_after'
|
|
27
|
+
: evaluation === '!=' ? '' : '';
|
|
28
|
+
return { property, timestamp: { [query]: value } };
|
|
29
|
+
}
|
|
30
|
+
static Status(property, evaluation, value) {
|
|
31
|
+
const query = evaluation === '==' ? 'equals' : '';
|
|
32
|
+
// TODO(nontangent): 'ステータス'を修正
|
|
33
|
+
return { property: 'ステータス', status: { [query]: value } };
|
|
34
|
+
}
|
|
35
|
+
static Relation(property, evaluation, value) {
|
|
36
|
+
const query = evaluation === 'in' ? 'contains' : '';
|
|
37
|
+
return { property, relation: { [query]: value } };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.N = N;
|
|
41
|
+
class NotionBaseQuery {
|
|
42
|
+
}
|
|
43
|
+
exports.NotionBaseQuery = NotionBaseQuery;
|
|
44
|
+
class NotionFilter extends NotionBaseQuery {
|
|
45
|
+
constructor(propertyType, propertyName, evaluation, value) {
|
|
46
|
+
super();
|
|
47
|
+
this.propertyType = propertyType;
|
|
48
|
+
this.propertyName = propertyName;
|
|
49
|
+
this.evaluation = evaluation;
|
|
50
|
+
this.value = value;
|
|
51
|
+
this.type = 'filter';
|
|
52
|
+
}
|
|
53
|
+
build() {
|
|
54
|
+
switch (this.propertyName) {
|
|
55
|
+
case 'last_edited_time': return N.LastEditedTime(this.propertyName, this.evaluation, this.value);
|
|
56
|
+
}
|
|
57
|
+
switch (this.propertyType) {
|
|
58
|
+
case 'rollup': return N.RollupPropQuery(this.propertyName, this.evaluation, this.value);
|
|
59
|
+
case 'formula': return N.FormulaQuery(this.propertyName, this.evaluation, this.value);
|
|
60
|
+
case 'status': return N.Status(this.propertyName, this.evaluation, this.value);
|
|
61
|
+
case 'relation': return N.Relation(this.propertyName, this.evaluation, this.value);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.NotionFilter = NotionFilter;
|
|
66
|
+
class NotionSort extends NotionBaseQuery {
|
|
67
|
+
constructor(property, direction = 'asc') {
|
|
68
|
+
super();
|
|
69
|
+
this.property = property;
|
|
70
|
+
this.direction = direction;
|
|
71
|
+
this.type = 'sort';
|
|
72
|
+
}
|
|
73
|
+
build() {
|
|
74
|
+
return {
|
|
75
|
+
property: this.property,
|
|
76
|
+
direction: this.direction === 'asc' ? 'ascending' : 'descending',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.NotionSort = NotionSort;
|
|
81
|
+
class NotionAnd extends NotionBaseQuery {
|
|
82
|
+
constructor(...filters) {
|
|
83
|
+
super();
|
|
84
|
+
this.type = 'and';
|
|
85
|
+
this.arr = filters;
|
|
86
|
+
}
|
|
87
|
+
build() {
|
|
88
|
+
return { and: this.arr.map(filter => filter.build()) };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.NotionAnd = NotionAnd;
|
|
92
|
+
class NotionOr extends NotionBaseQuery {
|
|
93
|
+
constructor(...filters) {
|
|
94
|
+
super();
|
|
95
|
+
this.type = 'or';
|
|
96
|
+
this.arr = filters;
|
|
97
|
+
}
|
|
98
|
+
build() {
|
|
99
|
+
return { or: this.arr.map(filter => filter.build()) };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.NotionOr = NotionOr;
|
|
103
|
+
const Query = (Entity) => {
|
|
104
|
+
const Filter = (_propName, evaluation, value) => {
|
|
105
|
+
var _a;
|
|
106
|
+
const annotation = Entity[decorators_1.NOTION_ANNOTATIONS].find(({ propName }) => propName === _propName);
|
|
107
|
+
// if(!annotation) {
|
|
108
|
+
// throw new Error(`NotionFilter: ${Entity} does not have ${_propName}.`);
|
|
109
|
+
// }
|
|
110
|
+
return new NotionFilter(annotation === null || annotation === void 0 ? void 0 : annotation.type, (_a = annotation === null || annotation === void 0 ? void 0 : annotation.fieldName) !== null && _a !== void 0 ? _a : _propName, evaluation, value);
|
|
111
|
+
};
|
|
112
|
+
const OrderBy = (_propName, direction) => {
|
|
113
|
+
var _a;
|
|
114
|
+
const annotation = Entity[decorators_1.NOTION_ANNOTATIONS].find(({ propName }) => propName === _propName);
|
|
115
|
+
return new NotionSort((_a = annotation === null || annotation === void 0 ? void 0 : annotation.fieldName) !== null && _a !== void 0 ? _a : _propName, direction);
|
|
116
|
+
};
|
|
117
|
+
const And = (...args) => new NotionAnd(...args);
|
|
118
|
+
const Or = (...args) => new NotionOr(...args);
|
|
119
|
+
return { Filter, OrderBy, And, Or };
|
|
120
|
+
};
|
|
121
|
+
exports.Query = Query;
|
|
122
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/notion/src/lib/query/query.ts"],"names":[],"mappings":";;;AAAA,8CAAqE;AAKrE,MAAa,CAAC;IACZ,MAAM,CAAC,eAAe,CAAC,QAAgB,EAAE,UAAsB,EAAE,KAAsB;QACrF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC;IAC3E,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,QAAgB,EAAE,UAAsB,EAAE,KAAsB;QAClF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAC,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,QAAgB,EAAE,UAAsB,EAAE,KAAsB;QACpF,MAAM,KAAK,GAAG,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,O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